@wordpress/theme 0.3.1-next.8b30e05b0.0 → 0.4.1-next.738bb1424.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 +114 -40
- 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} +66 -66
- package/build/color-ramps/lib/{default-ramps.js.map → default-ramps.cjs.map} +1 -1
- package/build/color-ramps/lib/{find-color-with-constraints.js → find-color-with-constraints.cjs} +6 -6
- package/build/color-ramps/lib/find-color-with-constraints.cjs.map +7 -0
- package/build/color-ramps/lib/{index.js → index.cjs} +6 -6
- package/build/color-ramps/lib/index.cjs.map +7 -0
- 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} +20 -46
- package/build/color-ramps/lib/taper-chroma.cjs.map +7 -0
- 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} +33 -7
- package/build/prebuilt/js/design-tokens.cjs.map +7 -0
- package/build/prebuilt/ts/{color-tokens.js → color-tokens.cjs} +36 -14
- package/build/prebuilt/ts/color-tokens.cjs.map +7 -0
- package/build/{token-id.js → prebuilt/ts/token-types.cjs} +4 -16
- 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/default-ramps.js +65 -65
- package/build-module/color-ramps/lib/default-ramps.js.map +1 -1
- package/build-module/color-ramps/lib/find-color-with-constraints.js +5 -5
- package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build-module/color-ramps/lib/index.js +5 -5
- package/build-module/color-ramps/lib/index.js.map +2 -2
- package/build-module/color-ramps/lib/taper-chroma.js +20 -47
- package/build-module/color-ramps/lib/taper-chroma.js.map +2 -2
- 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/js/design-tokens.js +32 -6
- package/build-module/prebuilt/js/design-tokens.js.map +2 -2
- package/build-module/prebuilt/ts/color-tokens.js +35 -13
- package/build-module/prebuilt/ts/color-tokens.js.map +2 -2
- package/build-module/prebuilt/ts/token-types.js +1 -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/color-ramps/lib/find-color-with-constraints.d.ts +3 -4
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
- package/build-types/color-ramps/lib/taper-chroma.d.ts +4 -4
- package/build-types/color-ramps/lib/taper-chroma.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/prebuilt/ts/color-tokens.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 +15 -7
- package/src/color-ramps/lib/default-ramps.ts +65 -65
- package/src/color-ramps/lib/find-color-with-constraints.ts +11 -7
- package/src/color-ramps/lib/index.ts +4 -4
- package/src/color-ramps/lib/taper-chroma.ts +32 -63
- package/src/index.ts +2 -1
- package/src/prebuilt/css/design-tokens.css +72 -28
- package/src/prebuilt/js/design-tokens.js +32 -6
- package/src/prebuilt/ts/color-tokens.ts +31 -9
- 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 -120
- package/bin/terrazzo-plugin-ds-tokens-docs/index.ts +0 -84
- package/bin/terrazzo-plugin-figma-ds-token-manager/index.ts +0 -217
- package/bin/terrazzo-plugin-figma-ds-token-manager/lib.ts +0 -1
- package/bin/terrazzo-plugin-inline-alias-values/index.ts +0 -113
- package/bin/terrazzo-plugin-known-wpds-css-variables/index.ts +0 -52
- package/build/color-ramps/lib/find-color-with-constraints.js.map +0 -7
- package/build/color-ramps/lib/index.js.map +0 -7
- package/build/color-ramps/lib/taper-chroma.js.map +0 -7
- package/build/index.js.map +0 -7
- package/build/prebuilt/js/design-tokens.js.map +0 -7
- package/build/prebuilt/json/figma.json +0 -715
- package/build/prebuilt/ts/color-tokens.js.map +0 -7
- package/build/token-id.js.map +0 -7
- package/build/types/css-modules.d.js +0 -1
- package/build/types/css-modules.d.js.map +0 -7
- package/build-module/prebuilt/json/figma.json +0 -715
- package/build-module/token-id.js +0 -6
- package/build-module/token-id.js.map +0 -7
- package/build-module/types/css-modules.d.js +0 -1
- package/build-types/token-id.d.ts +0 -9
- package/build-types/token-id.d.ts.map +0 -1
- package/docs/ds-tokens.md +0 -150
- package/src/prebuilt/json/figma.json +0 -715
- package/src/test/token-id.test.ts +0 -12
- package/src/token-id.ts +0 -9
- package/src/types/css-modules.d.ts +0 -4
- package/terrazzo.config.ts +0 -126
- package/tokens/border.json +0 -34
- package/tokens/color.json +0 -1029
- package/tokens/dimension.json +0 -109
- package/tokens/elevation.json +0 -201
- 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/{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/{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/{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
- /package/build-module/{types/css-modules.d.js.map → prebuilt/ts/token-types.js.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/theme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1-next.738bb1424.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.36.1-next.
|
|
47
|
-
"@wordpress/private-apis": "^1.36.1-next.
|
|
54
|
+
"@wordpress/element": "^6.36.1-next.738bb1424.0",
|
|
55
|
+
"@wordpress/private-apis": "^1.36.1-next.738bb1424.0",
|
|
48
56
|
"colorjs.io": "^0.5.2",
|
|
49
57
|
"memize": "^2.1.0"
|
|
50
58
|
},
|
|
@@ -62,7 +70,7 @@
|
|
|
62
70
|
"build:default-ramps": "node --import=esbuild-esm-loader/register bin/generate-default-ramps/index.ts",
|
|
63
71
|
"build:tokens": "node --import=esbuild-esm-loader/register bin/generate-primitive-tokens/index.ts && cross-env NODE_OPTIONS=--import=esbuild-esm-loader/register tz build --config terrazzo.config.ts",
|
|
64
72
|
"build": "npm run build:tokens && npm run build:default-ramps",
|
|
65
|
-
"postbuild": "prettier --write tokens/color.json src/prebuilt src/color-ramps/lib/default-ramps.ts docs"
|
|
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": "ab1b004c0d61c295aa34bc86ea07f979343983ce"
|
|
68
76
|
}
|
|
@@ -40,10 +40,10 @@ export const DEFAULT_RAMPS: Record<
|
|
|
40
40
|
bgFill1: '#3858e9',
|
|
41
41
|
fgFill: '#eff0f2',
|
|
42
42
|
bgFill2: '#2e49d9',
|
|
43
|
-
surface2: '#
|
|
44
|
-
surface6: '#
|
|
43
|
+
surface2: '#f6f8fd',
|
|
44
|
+
surface6: '#c7d2ed',
|
|
45
45
|
surface5: '#dbe2f4',
|
|
46
|
-
surface4: '#
|
|
46
|
+
surface4: '#e6eaf4',
|
|
47
47
|
surface3: '#fff',
|
|
48
48
|
fgSurface4: '#0b0070',
|
|
49
49
|
fgSurface3: '#3858e9',
|
|
@@ -51,11 +51,11 @@ export const DEFAULT_RAMPS: Record<
|
|
|
51
51
|
fgSurface1: '#85a9ff',
|
|
52
52
|
stroke3: '#3858e9',
|
|
53
53
|
stroke4: '#2337c8',
|
|
54
|
-
stroke2: '#
|
|
55
|
-
stroke1: '#
|
|
56
|
-
bgFillDark: '#
|
|
54
|
+
stroke2: '#9caacc',
|
|
55
|
+
stroke1: '#a3b1d4',
|
|
56
|
+
bgFillDark: '#1a1e27',
|
|
57
57
|
fgFillDark: '#eff0f2',
|
|
58
|
-
bgFillInverted2: '#
|
|
58
|
+
bgFillInverted2: '#1a1e27',
|
|
59
59
|
bgFillInverted1: '#13009f',
|
|
60
60
|
fgFillInverted: '#eff0f2',
|
|
61
61
|
surface1: '#ecf0f9',
|
|
@@ -65,27 +65,27 @@ export const DEFAULT_RAMPS: Record<
|
|
|
65
65
|
info: {
|
|
66
66
|
ramp: {
|
|
67
67
|
bgFill1: '#0090ff',
|
|
68
|
-
fgFill: '#
|
|
68
|
+
fgFill: '#1a1f24',
|
|
69
69
|
bgFill2: '#007fed',
|
|
70
|
-
surface2: '#
|
|
71
|
-
surface6: '#
|
|
72
|
-
surface5: '#
|
|
73
|
-
surface4: '#
|
|
70
|
+
surface2: '#f3f9ff',
|
|
71
|
+
surface6: '#bcd5f1',
|
|
72
|
+
surface5: '#d3e4f7',
|
|
73
|
+
surface4: '#deebfa',
|
|
74
74
|
surface3: '#fff',
|
|
75
75
|
fgSurface4: '#001b4f',
|
|
76
76
|
fgSurface3: '#006bd7',
|
|
77
77
|
fgSurface2: '#008bfa',
|
|
78
|
-
fgSurface1: '#
|
|
78
|
+
fgSurface1: '#58b0ff',
|
|
79
79
|
stroke3: '#006bd7',
|
|
80
80
|
stroke4: '#004fa9',
|
|
81
|
-
stroke2: '#
|
|
82
|
-
stroke1: '#
|
|
83
|
-
bgFillDark: '#
|
|
84
|
-
fgFillDark: '#
|
|
85
|
-
bgFillInverted2: '#
|
|
81
|
+
stroke2: '#95b5d9',
|
|
82
|
+
stroke1: '#9fbcdc',
|
|
83
|
+
bgFillDark: '#1a1f24',
|
|
84
|
+
fgFillDark: '#eef0f3',
|
|
85
|
+
bgFillInverted2: '#1a1f24',
|
|
86
86
|
bgFillInverted1: '#002a69',
|
|
87
|
-
fgFillInverted: '#
|
|
88
|
-
surface1: '#
|
|
87
|
+
fgFillInverted: '#eef0f3',
|
|
88
|
+
surface1: '#e4f1ff',
|
|
89
89
|
},
|
|
90
90
|
direction: 'darker',
|
|
91
91
|
},
|
|
@@ -94,25 +94,25 @@ export const DEFAULT_RAMPS: Record<
|
|
|
94
94
|
bgFill1: '#4ab866',
|
|
95
95
|
fgFill: '#1b1f1c',
|
|
96
96
|
bgFill2: '#37a756',
|
|
97
|
-
surface2: '#
|
|
98
|
-
surface6: '#
|
|
99
|
-
surface5: '#
|
|
100
|
-
surface4: '#
|
|
97
|
+
surface2: '#eaffed',
|
|
98
|
+
surface6: '#88e89b',
|
|
99
|
+
surface5: '#aff3bb',
|
|
100
|
+
surface4: '#c5f7cc',
|
|
101
101
|
surface3: '#fff',
|
|
102
102
|
fgSurface4: '#002900',
|
|
103
103
|
fgSurface3: '#007f30',
|
|
104
104
|
fgSurface2: '#2b9e4e',
|
|
105
|
-
fgSurface1: '#
|
|
105
|
+
fgSurface1: '#53c16e',
|
|
106
106
|
stroke3: '#007f30',
|
|
107
107
|
stroke4: '#006013',
|
|
108
|
-
stroke2: '#
|
|
109
|
-
stroke1: '#
|
|
108
|
+
stroke2: '#84c08e',
|
|
109
|
+
stroke1: '#8ac894',
|
|
110
110
|
bgFillDark: '#1b1f1c',
|
|
111
|
-
fgFillDark: '#
|
|
111
|
+
fgFillDark: '#eaf3eb',
|
|
112
112
|
bgFillInverted2: '#1b1f1c',
|
|
113
113
|
bgFillInverted1: '#003701',
|
|
114
|
-
fgFillInverted: '#
|
|
115
|
-
surface1: '#
|
|
114
|
+
fgFillInverted: '#eaf3eb',
|
|
115
|
+
surface1: '#cbfdd2',
|
|
116
116
|
},
|
|
117
117
|
direction: 'darker',
|
|
118
118
|
},
|
|
@@ -121,25 +121,25 @@ export const DEFAULT_RAMPS: Record<
|
|
|
121
121
|
bgFill1: '#f0d149',
|
|
122
122
|
fgFill: '#1f1e1b',
|
|
123
123
|
bgFill2: '#dcbe2f',
|
|
124
|
-
surface2: '#
|
|
125
|
-
surface6: '#
|
|
126
|
-
surface5: '#
|
|
127
|
-
surface4: '#
|
|
124
|
+
surface2: '#fff9c9',
|
|
125
|
+
surface6: '#e8d172',
|
|
126
|
+
surface5: '#f7e18a',
|
|
127
|
+
surface4: '#fee994',
|
|
128
128
|
surface3: '#fff',
|
|
129
129
|
fgSurface4: '#281d00',
|
|
130
|
-
fgSurface3: '#
|
|
131
|
-
fgSurface2: '#
|
|
132
|
-
fgSurface1: '#
|
|
133
|
-
stroke3: '#
|
|
134
|
-
stroke4: '#
|
|
135
|
-
stroke2: '#
|
|
136
|
-
stroke1: '#
|
|
130
|
+
fgSurface3: '#826a00',
|
|
131
|
+
fgSurface2: '#a48600',
|
|
132
|
+
fgSurface1: '#c6a800',
|
|
133
|
+
stroke3: '#826a00',
|
|
134
|
+
stroke4: '#624f00',
|
|
135
|
+
stroke2: '#bdb17e',
|
|
136
|
+
stroke1: '#c5b883',
|
|
137
137
|
bgFillDark: '#1f1e1b',
|
|
138
|
-
fgFillDark: '#
|
|
138
|
+
fgFillDark: '#fdf1bf',
|
|
139
139
|
bgFillInverted2: '#1f1e1b',
|
|
140
140
|
bgFillInverted1: '#392c00',
|
|
141
|
-
fgFillInverted: '#
|
|
142
|
-
surface1: '#
|
|
141
|
+
fgFillInverted: '#fdf1bf',
|
|
142
|
+
surface1: '#ffef9b',
|
|
143
143
|
},
|
|
144
144
|
direction: 'darker',
|
|
145
145
|
},
|
|
@@ -148,25 +148,25 @@ export const DEFAULT_RAMPS: Record<
|
|
|
148
148
|
bgFill1: '#f0b849',
|
|
149
149
|
fgFill: '#1f1e1b',
|
|
150
150
|
bgFill2: '#dda633',
|
|
151
|
-
surface2: '#
|
|
152
|
-
surface6: '#
|
|
153
|
-
surface5: '#
|
|
154
|
-
surface4: '#
|
|
151
|
+
surface2: '#fff7e0',
|
|
152
|
+
surface6: '#f4cc84',
|
|
153
|
+
surface5: '#faddac',
|
|
154
|
+
surface4: '#fde6bd',
|
|
155
155
|
surface3: '#fff',
|
|
156
156
|
fgSurface4: '#2e1900',
|
|
157
|
-
fgSurface3: '#
|
|
158
|
-
fgSurface2: '#
|
|
159
|
-
fgSurface1: '#
|
|
160
|
-
stroke3: '#
|
|
161
|
-
stroke4: '#
|
|
162
|
-
stroke2: '#
|
|
163
|
-
stroke1: '#
|
|
157
|
+
fgSurface3: '#926300',
|
|
158
|
+
fgSurface2: '#b47f00',
|
|
159
|
+
fgSurface1: '#d7a02a',
|
|
160
|
+
stroke3: '#926300',
|
|
161
|
+
stroke4: '#6f4900',
|
|
162
|
+
stroke2: '#c7ad7e',
|
|
163
|
+
stroke1: '#d0b381',
|
|
164
164
|
bgFillDark: '#1f1e1b',
|
|
165
|
-
fgFillDark: '#
|
|
165
|
+
fgFillDark: '#f7efe2',
|
|
166
166
|
bgFillInverted2: '#1f1e1b',
|
|
167
167
|
bgFillInverted1: '#422800',
|
|
168
|
-
fgFillInverted: '#
|
|
169
|
-
surface1: '#
|
|
168
|
+
fgFillInverted: '#f7efe2',
|
|
169
|
+
surface1: '#ffecc4',
|
|
170
170
|
},
|
|
171
171
|
direction: 'darker',
|
|
172
172
|
},
|
|
@@ -175,10 +175,10 @@ export const DEFAULT_RAMPS: Record<
|
|
|
175
175
|
bgFill1: '#cc1818',
|
|
176
176
|
fgFill: '#f2efef',
|
|
177
177
|
bgFill2: '#b90000',
|
|
178
|
-
surface2: '#
|
|
179
|
-
surface6: '#
|
|
180
|
-
surface5: '#
|
|
181
|
-
surface4: '#
|
|
178
|
+
surface2: '#fff6f4',
|
|
179
|
+
surface6: '#f3c8c2',
|
|
180
|
+
surface5: '#f8dcd7',
|
|
181
|
+
surface4: '#f6e6e3',
|
|
182
182
|
surface3: '#fff',
|
|
183
183
|
fgSurface4: '#470000',
|
|
184
184
|
fgSurface3: '#cc1818',
|
|
@@ -186,14 +186,14 @@ export const DEFAULT_RAMPS: Record<
|
|
|
186
186
|
fgSurface1: '#ff8879',
|
|
187
187
|
stroke3: '#cc1818',
|
|
188
188
|
stroke4: '#9d0000',
|
|
189
|
-
stroke2: '#
|
|
190
|
-
stroke1: '#
|
|
189
|
+
stroke2: '#d39c95',
|
|
190
|
+
stroke1: '#daa39b',
|
|
191
191
|
bgFillDark: '#231c1b',
|
|
192
192
|
fgFillDark: '#f2efef',
|
|
193
193
|
bgFillInverted2: '#231c1b',
|
|
194
194
|
bgFillInverted1: '#640000',
|
|
195
195
|
fgFillInverted: '#f2efef',
|
|
196
|
-
surface1: '#
|
|
196
|
+
surface1: '#fcece9',
|
|
197
197
|
},
|
|
198
198
|
direction: 'darker',
|
|
199
199
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { get, OKLCH, type
|
|
4
|
+
import { get, OKLCH, type PlainColorObject } from 'colorjs.io/fn';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -28,7 +28,6 @@ function cdiff( c1: number, c2: number ) {
|
|
|
28
28
|
* - the L applied to the seed meets the contrast target against the reference
|
|
29
29
|
* - the search is performed in one direction (ie lighter / darker)
|
|
30
30
|
* - more constraints can be applied around lightness
|
|
31
|
-
* - chroma could be tapered
|
|
32
31
|
* @param reference
|
|
33
32
|
* @param seed
|
|
34
33
|
* @param target
|
|
@@ -40,8 +39,8 @@ function cdiff( c1: number, c2: number ) {
|
|
|
40
39
|
* @param options.taperChromaOptions
|
|
41
40
|
*/
|
|
42
41
|
export function findColorMeetingRequirements(
|
|
43
|
-
reference:
|
|
44
|
-
seed:
|
|
42
|
+
reference: PlainColorObject,
|
|
43
|
+
seed: PlainColorObject,
|
|
45
44
|
target: number,
|
|
46
45
|
direction: 'lighter' | 'darker',
|
|
47
46
|
{
|
|
@@ -54,7 +53,12 @@ export function findColorMeetingRequirements(
|
|
|
54
53
|
};
|
|
55
54
|
taperChromaOptions?: TaperChromaOptions;
|
|
56
55
|
} = {}
|
|
57
|
-
): {
|
|
56
|
+
): {
|
|
57
|
+
color: PlainColorObject;
|
|
58
|
+
reached: boolean;
|
|
59
|
+
achieved: number;
|
|
60
|
+
deficit?: number;
|
|
61
|
+
} {
|
|
58
62
|
// A target of 1 means same color.
|
|
59
63
|
// A target lower than 1 doesn't make sense.
|
|
60
64
|
if ( target <= 1 ) {
|
|
@@ -65,7 +69,7 @@ export function findColorMeetingRequirements(
|
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
function getColorForL( l: number ):
|
|
72
|
+
function getColorForL( l: number ): PlainColorObject {
|
|
69
73
|
let newL = l;
|
|
70
74
|
let newC = get( seed, [ OKLCH, 'c' ] );
|
|
71
75
|
|
|
@@ -140,7 +144,7 @@ export function findColorMeetingRequirements(
|
|
|
140
144
|
|
|
141
145
|
const bestColor = solveWithBisect(
|
|
142
146
|
getColorForL,
|
|
143
|
-
( c
|
|
147
|
+
( c ) => cdiff( getContrast( reference, c ), target ),
|
|
144
148
|
lowerL,
|
|
145
149
|
lowerContrast,
|
|
146
150
|
upperL,
|
|
@@ -56,7 +56,7 @@ function calculateRamp( {
|
|
|
56
56
|
oppDir,
|
|
57
57
|
pinLightness,
|
|
58
58
|
}: {
|
|
59
|
-
seed:
|
|
59
|
+
seed: PlainColorObject;
|
|
60
60
|
sortedSteps: ( keyof Ramp )[];
|
|
61
61
|
config: RampConfig;
|
|
62
62
|
mainDir: RampDirection;
|
|
@@ -74,7 +74,7 @@ function calculateRamp( {
|
|
|
74
74
|
|
|
75
75
|
// Keep track of the calculated colors, as they are going to be useful
|
|
76
76
|
// when other colors reference them.
|
|
77
|
-
const calculatedColors = new Map< keyof Ramp | 'seed',
|
|
77
|
+
const calculatedColors = new Map< keyof Ramp | 'seed', PlainColorObject >();
|
|
78
78
|
calculatedColors.set( 'seed', seed );
|
|
79
79
|
|
|
80
80
|
for ( const stepName of sortedSteps ) {
|
|
@@ -267,11 +267,11 @@ export function buildRamp(
|
|
|
267
267
|
if ( maxDeficit > CONTRAST_EPSILON && rescaleToFitContrastTargets ) {
|
|
268
268
|
const iterSteps = stepsForStep( maxDeficitStep!, config );
|
|
269
269
|
|
|
270
|
-
function getSeedForL( l: number ):
|
|
270
|
+
function getSeedForL( l: number ): PlainColorObject {
|
|
271
271
|
return clampToGamut( set( clone( seed ), [ OKLCH, 'l' ], l ) );
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
function getDeficitForSeed( s:
|
|
274
|
+
function getDeficitForSeed( s: PlainColorObject ): number {
|
|
275
275
|
const iterationResults = calculateRamp( {
|
|
276
276
|
seed: s,
|
|
277
277
|
sortedSteps: iterSteps,
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import {
|
|
5
5
|
get,
|
|
6
|
-
|
|
6
|
+
toGamut,
|
|
7
7
|
OKLCH,
|
|
8
|
-
P3,
|
|
9
8
|
sRGB,
|
|
10
|
-
type
|
|
11
|
-
type
|
|
9
|
+
type PlainColorObject,
|
|
10
|
+
type ColorSpace,
|
|
12
11
|
} from 'colorjs.io/fn';
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -17,7 +16,7 @@ import {
|
|
|
17
16
|
import './register-color-spaces';
|
|
18
17
|
|
|
19
18
|
export interface TaperChromaOptions {
|
|
20
|
-
gamut?:
|
|
19
|
+
gamut?: ColorSpace; // target gamut (default `sRGB`)
|
|
21
20
|
alpha?: number; // base fraction of Cmax at target (default 0.62)
|
|
22
21
|
carry?: number; // seed vividness carry exponent β in [0..1] (default 0.5)
|
|
23
22
|
cUpperBound?: number; // hard search cap for C (default 0.45)
|
|
@@ -41,12 +40,11 @@ export interface TaperChromaOptions {
|
|
|
41
40
|
* @param options
|
|
42
41
|
*/
|
|
43
42
|
export function taperChroma(
|
|
44
|
-
seed:
|
|
43
|
+
seed: PlainColorObject, // already OKLCH
|
|
45
44
|
lTarget: number, // [0..1]
|
|
46
45
|
options: TaperChromaOptions = {}
|
|
47
|
-
): { l: number; c: number } |
|
|
48
|
-
const gamut = options.gamut ??
|
|
49
|
-
const gamutSpace = gamut === 'p3' ? P3 : sRGB;
|
|
46
|
+
): { l: number; c: number } | PlainColorObject {
|
|
47
|
+
const gamut = options.gamut ?? sRGB;
|
|
50
48
|
const alpha = options.alpha ?? 0.65; // 0.7-0.8 works well for accent surface
|
|
51
49
|
const carry = options.carry ?? 0.5;
|
|
52
50
|
const cUpperBound = options.cUpperBound ?? 0.45;
|
|
@@ -68,24 +66,20 @@ export function taperChroma(
|
|
|
68
66
|
} else {
|
|
69
67
|
// Respect achromatic intent: grayscale at target L
|
|
70
68
|
return {
|
|
71
|
-
|
|
69
|
+
space: OKLCH,
|
|
72
70
|
coords: [ clamp01( lTarget ), 0, 0 ],
|
|
71
|
+
alpha: 1,
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
// Capacity at seed and target
|
|
78
77
|
const lSeed = clamp01( get( seed, [ OKLCH, 'l' ] ) );
|
|
79
|
-
const cmaxSeed = getCachedMaxChromaAtLH(
|
|
80
|
-
lSeed,
|
|
81
|
-
hSeed,
|
|
82
|
-
gamutSpace,
|
|
83
|
-
cUpperBound
|
|
84
|
-
);
|
|
78
|
+
const cmaxSeed = getCachedMaxChromaAtLH( lSeed, hSeed, gamut, cUpperBound );
|
|
85
79
|
const cmaxTarget = getCachedMaxChromaAtLH(
|
|
86
80
|
clamp01( lTarget ),
|
|
87
81
|
hSeed,
|
|
88
|
-
|
|
82
|
+
gamut,
|
|
89
83
|
cUpperBound
|
|
90
84
|
);
|
|
91
85
|
|
|
@@ -106,20 +100,10 @@ export function taperChroma(
|
|
|
106
100
|
kLight,
|
|
107
101
|
kDark,
|
|
108
102
|
} );
|
|
109
|
-
|
|
103
|
+
const cPlanned = cWithCarry * t;
|
|
110
104
|
|
|
111
105
|
// Downward-only clamp (preserve L & H)
|
|
112
106
|
const lOut = clamp01( lTarget );
|
|
113
|
-
const candidate: ColorTypes = {
|
|
114
|
-
spaceId: 'oklch',
|
|
115
|
-
coords: [ lOut, cPlanned, hSeed ],
|
|
116
|
-
};
|
|
117
|
-
if ( ! inGamut( candidate, gamutSpace ) ) {
|
|
118
|
-
const cap = Math.min( cPlanned, cUpperBound );
|
|
119
|
-
cPlanned = getCachedMaxChromaAtLH( lOut, hSeed, gamutSpace, cap );
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
cPlanned = Math.min( cPlanned, cSeed );
|
|
123
107
|
|
|
124
108
|
return { l: lOut, c: cPlanned };
|
|
125
109
|
}
|
|
@@ -181,19 +165,14 @@ function continuousTaper(
|
|
|
181
165
|
/* ---- chroma-capacity queries with small caches ---- */
|
|
182
166
|
|
|
183
167
|
const maxChromaCache = new Map< string, number >();
|
|
184
|
-
|
|
185
|
-
function keyMax(
|
|
186
|
-
l: number,
|
|
187
|
-
h: number,
|
|
188
|
-
gamut: 'p3' | 'srgb',
|
|
189
|
-
cap: number
|
|
190
|
-
): string {
|
|
168
|
+
function keyMax( l: number, h: number, gamut: string, cap: number ): string {
|
|
191
169
|
// Quantize to keep cache compact
|
|
192
|
-
const lq = quantize( l,
|
|
193
|
-
const hq = quantize( normalizeHue( h ),
|
|
194
|
-
const cq = quantize( cap,
|
|
170
|
+
const lq = quantize( l, 0.05 );
|
|
171
|
+
const hq = quantize( normalizeHue( h ), 10 );
|
|
172
|
+
const cq = quantize( cap, 0.05 );
|
|
195
173
|
return `${ gamut }|L:${ lq }|H:${ hq }|cap:${ cq }`;
|
|
196
174
|
}
|
|
175
|
+
|
|
197
176
|
function quantize( x: number, step: number ): number {
|
|
198
177
|
const k = Math.round( x / step );
|
|
199
178
|
return k * step;
|
|
@@ -202,10 +181,10 @@ function quantize( x: number, step: number ): number {
|
|
|
202
181
|
function getCachedMaxChromaAtLH(
|
|
203
182
|
l: number,
|
|
204
183
|
h: number,
|
|
205
|
-
gamutSpace:
|
|
184
|
+
gamutSpace: ColorSpace,
|
|
206
185
|
cap: number
|
|
207
186
|
): number {
|
|
208
|
-
const gamut = gamutSpace
|
|
187
|
+
const gamut = gamutSpace.id;
|
|
209
188
|
const key = keyMax( l, h, gamut, cap );
|
|
210
189
|
const hit = maxChromaCache.get( key );
|
|
211
190
|
if ( typeof hit === 'number' ) {
|
|
@@ -218,7 +197,7 @@ function getCachedMaxChromaAtLH(
|
|
|
218
197
|
}
|
|
219
198
|
|
|
220
199
|
/**
|
|
221
|
-
*
|
|
200
|
+
* Find the max in-gamut chroma at fixed (L,H) in the target gamut
|
|
222
201
|
* @param l
|
|
223
202
|
* @param h
|
|
224
203
|
* @param gamutSpace
|
|
@@ -227,28 +206,18 @@ function getCachedMaxChromaAtLH(
|
|
|
227
206
|
function maxInGamutChromaAtLH(
|
|
228
207
|
l: number,
|
|
229
208
|
h: number,
|
|
230
|
-
gamutSpace:
|
|
209
|
+
gamutSpace: ColorSpace,
|
|
231
210
|
cap: number
|
|
232
211
|
): number {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
coords: [ lFixed, mid, hFixed ],
|
|
245
|
-
};
|
|
246
|
-
if ( inGamut( probe, gamutSpace ) ) {
|
|
247
|
-
ok = mid;
|
|
248
|
-
lo = mid;
|
|
249
|
-
} else {
|
|
250
|
-
hi = mid;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return ok;
|
|
212
|
+
// Construct a color with maximum chroma.
|
|
213
|
+
const probe: PlainColorObject = {
|
|
214
|
+
space: OKLCH,
|
|
215
|
+
coords: [ l, cap, h ],
|
|
216
|
+
alpha: 1,
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// Let `toGamut` reduce the chroma to the gamut maximum.
|
|
220
|
+
const clamped = toGamut( probe, { space: gamutSpace, method: 'css' } );
|
|
221
|
+
|
|
222
|
+
return get( clamped, [ OKLCH, 'c' ] );
|
|
254
223
|
}
|
package/src/index.ts
CHANGED