@wordpress/theme 0.3.1-next.8b30e05b0.0 → 0.4.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/README.md +82 -18
- package/bin/generate-primitive-tokens/index.ts +26 -33
- package/bin/terrazzo-plugin-mode-overrides/index.ts +208 -0
- package/build/color-ramps/lib/default-ramps.js +65 -65
- package/build/color-ramps/lib/default-ramps.js.map +1 -1
- package/build/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build/color-ramps/lib/index.js.map +2 -2
- package/build/color-ramps/lib/taper-chroma.js +18 -44
- package/build/color-ramps/lib/taper-chroma.js.map +2 -2
- package/build/prebuilt/js/design-tokens.js +32 -6
- package/build/prebuilt/js/design-tokens.js.map +2 -2
- package/build/prebuilt/ts/color-tokens.js +35 -13
- package/build/prebuilt/ts/color-tokens.js.map +2 -2
- 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.map +2 -2
- package/build-module/color-ramps/lib/index.js.map +2 -2
- package/build-module/color-ramps/lib/taper-chroma.js +19 -46
- package/build-module/color-ramps/lib/taper-chroma.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-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/prebuilt/ts/color-tokens.d.ts.map +1 -1
- package/docs/ds-tokens.md +35 -9
- package/package.json +5 -5
- 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/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/terrazzo.config.ts +11 -14
- package/tokens/border.json +44 -22
- package/tokens/color.json +1160 -630
- package/tokens/dimension.json +112 -52
- package/tokens/elevation.json +1 -1
- package/tokens/modes/border.high-dpi.json +15 -0
- package/tokens/modes/dimension.comfortable.json +54 -0
- package/tokens/modes/dimension.compact.json +54 -0
- package/tokens/typography.json +1 -1
- package/tsconfig.bin.tsbuildinfo +1 -1
- package/tsconfig.src.json +1 -1
- package/tsconfig.src.tsbuildinfo +1 -1
- 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/build/prebuilt/json/figma.json +0 -715
- package/build/token-id.js +0 -30
- 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-module/types/css-modules.d.js.map +0 -7
- package/build-types/token-id.d.ts +0 -9
- package/build-types/token-id.d.ts.map +0 -1
- 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
|
@@ -32,10 +32,10 @@ var DEFAULT_RAMPS = {
|
|
|
32
32
|
bgFill1: "#3858e9",
|
|
33
33
|
fgFill: "#eff0f2",
|
|
34
34
|
bgFill2: "#2e49d9",
|
|
35
|
-
surface2: "#
|
|
36
|
-
surface6: "#
|
|
35
|
+
surface2: "#f6f8fd",
|
|
36
|
+
surface6: "#c7d2ed",
|
|
37
37
|
surface5: "#dbe2f4",
|
|
38
|
-
surface4: "#
|
|
38
|
+
surface4: "#e6eaf4",
|
|
39
39
|
surface3: "#fff",
|
|
40
40
|
fgSurface4: "#0b0070",
|
|
41
41
|
fgSurface3: "#3858e9",
|
|
@@ -43,11 +43,11 @@ var DEFAULT_RAMPS = {
|
|
|
43
43
|
fgSurface1: "#85a9ff",
|
|
44
44
|
stroke3: "#3858e9",
|
|
45
45
|
stroke4: "#2337c8",
|
|
46
|
-
stroke2: "#
|
|
47
|
-
stroke1: "#
|
|
48
|
-
bgFillDark: "#
|
|
46
|
+
stroke2: "#9caacc",
|
|
47
|
+
stroke1: "#a3b1d4",
|
|
48
|
+
bgFillDark: "#1a1e27",
|
|
49
49
|
fgFillDark: "#eff0f2",
|
|
50
|
-
bgFillInverted2: "#
|
|
50
|
+
bgFillInverted2: "#1a1e27",
|
|
51
51
|
bgFillInverted1: "#13009f",
|
|
52
52
|
fgFillInverted: "#eff0f2",
|
|
53
53
|
surface1: "#ecf0f9"
|
|
@@ -57,27 +57,27 @@ var DEFAULT_RAMPS = {
|
|
|
57
57
|
info: {
|
|
58
58
|
ramp: {
|
|
59
59
|
bgFill1: "#0090ff",
|
|
60
|
-
fgFill: "#
|
|
60
|
+
fgFill: "#1a1f24",
|
|
61
61
|
bgFill2: "#007fed",
|
|
62
|
-
surface2: "#
|
|
63
|
-
surface6: "#
|
|
64
|
-
surface5: "#
|
|
65
|
-
surface4: "#
|
|
62
|
+
surface2: "#f3f9ff",
|
|
63
|
+
surface6: "#bcd5f1",
|
|
64
|
+
surface5: "#d3e4f7",
|
|
65
|
+
surface4: "#deebfa",
|
|
66
66
|
surface3: "#fff",
|
|
67
67
|
fgSurface4: "#001b4f",
|
|
68
68
|
fgSurface3: "#006bd7",
|
|
69
69
|
fgSurface2: "#008bfa",
|
|
70
|
-
fgSurface1: "#
|
|
70
|
+
fgSurface1: "#58b0ff",
|
|
71
71
|
stroke3: "#006bd7",
|
|
72
72
|
stroke4: "#004fa9",
|
|
73
|
-
stroke2: "#
|
|
74
|
-
stroke1: "#
|
|
75
|
-
bgFillDark: "#
|
|
76
|
-
fgFillDark: "#
|
|
77
|
-
bgFillInverted2: "#
|
|
73
|
+
stroke2: "#95b5d9",
|
|
74
|
+
stroke1: "#9fbcdc",
|
|
75
|
+
bgFillDark: "#1a1f24",
|
|
76
|
+
fgFillDark: "#eef0f3",
|
|
77
|
+
bgFillInverted2: "#1a1f24",
|
|
78
78
|
bgFillInverted1: "#002a69",
|
|
79
|
-
fgFillInverted: "#
|
|
80
|
-
surface1: "#
|
|
79
|
+
fgFillInverted: "#eef0f3",
|
|
80
|
+
surface1: "#e4f1ff"
|
|
81
81
|
},
|
|
82
82
|
direction: "darker"
|
|
83
83
|
},
|
|
@@ -86,25 +86,25 @@ var DEFAULT_RAMPS = {
|
|
|
86
86
|
bgFill1: "#4ab866",
|
|
87
87
|
fgFill: "#1b1f1c",
|
|
88
88
|
bgFill2: "#37a756",
|
|
89
|
-
surface2: "#
|
|
90
|
-
surface6: "#
|
|
91
|
-
surface5: "#
|
|
92
|
-
surface4: "#
|
|
89
|
+
surface2: "#eaffed",
|
|
90
|
+
surface6: "#88e89b",
|
|
91
|
+
surface5: "#aff3bb",
|
|
92
|
+
surface4: "#c5f7cc",
|
|
93
93
|
surface3: "#fff",
|
|
94
94
|
fgSurface4: "#002900",
|
|
95
95
|
fgSurface3: "#007f30",
|
|
96
96
|
fgSurface2: "#2b9e4e",
|
|
97
|
-
fgSurface1: "#
|
|
97
|
+
fgSurface1: "#53c16e",
|
|
98
98
|
stroke3: "#007f30",
|
|
99
99
|
stroke4: "#006013",
|
|
100
|
-
stroke2: "#
|
|
101
|
-
stroke1: "#
|
|
100
|
+
stroke2: "#84c08e",
|
|
101
|
+
stroke1: "#8ac894",
|
|
102
102
|
bgFillDark: "#1b1f1c",
|
|
103
|
-
fgFillDark: "#
|
|
103
|
+
fgFillDark: "#eaf3eb",
|
|
104
104
|
bgFillInverted2: "#1b1f1c",
|
|
105
105
|
bgFillInverted1: "#003701",
|
|
106
|
-
fgFillInverted: "#
|
|
107
|
-
surface1: "#
|
|
106
|
+
fgFillInverted: "#eaf3eb",
|
|
107
|
+
surface1: "#cbfdd2"
|
|
108
108
|
},
|
|
109
109
|
direction: "darker"
|
|
110
110
|
},
|
|
@@ -113,25 +113,25 @@ var DEFAULT_RAMPS = {
|
|
|
113
113
|
bgFill1: "#f0d149",
|
|
114
114
|
fgFill: "#1f1e1b",
|
|
115
115
|
bgFill2: "#dcbe2f",
|
|
116
|
-
surface2: "#
|
|
117
|
-
surface6: "#
|
|
118
|
-
surface5: "#
|
|
119
|
-
surface4: "#
|
|
116
|
+
surface2: "#fff9c9",
|
|
117
|
+
surface6: "#e8d172",
|
|
118
|
+
surface5: "#f7e18a",
|
|
119
|
+
surface4: "#fee994",
|
|
120
120
|
surface3: "#fff",
|
|
121
121
|
fgSurface4: "#281d00",
|
|
122
|
-
fgSurface3: "#
|
|
123
|
-
fgSurface2: "#
|
|
124
|
-
fgSurface1: "#
|
|
125
|
-
stroke3: "#
|
|
126
|
-
stroke4: "#
|
|
127
|
-
stroke2: "#
|
|
128
|
-
stroke1: "#
|
|
122
|
+
fgSurface3: "#826a00",
|
|
123
|
+
fgSurface2: "#a48600",
|
|
124
|
+
fgSurface1: "#c6a800",
|
|
125
|
+
stroke3: "#826a00",
|
|
126
|
+
stroke4: "#624f00",
|
|
127
|
+
stroke2: "#bdb17e",
|
|
128
|
+
stroke1: "#c5b883",
|
|
129
129
|
bgFillDark: "#1f1e1b",
|
|
130
|
-
fgFillDark: "#
|
|
130
|
+
fgFillDark: "#fdf1bf",
|
|
131
131
|
bgFillInverted2: "#1f1e1b",
|
|
132
132
|
bgFillInverted1: "#392c00",
|
|
133
|
-
fgFillInverted: "#
|
|
134
|
-
surface1: "#
|
|
133
|
+
fgFillInverted: "#fdf1bf",
|
|
134
|
+
surface1: "#ffef9b"
|
|
135
135
|
},
|
|
136
136
|
direction: "darker"
|
|
137
137
|
},
|
|
@@ -140,25 +140,25 @@ var DEFAULT_RAMPS = {
|
|
|
140
140
|
bgFill1: "#f0b849",
|
|
141
141
|
fgFill: "#1f1e1b",
|
|
142
142
|
bgFill2: "#dda633",
|
|
143
|
-
surface2: "#
|
|
144
|
-
surface6: "#
|
|
145
|
-
surface5: "#
|
|
146
|
-
surface4: "#
|
|
143
|
+
surface2: "#fff7e0",
|
|
144
|
+
surface6: "#f4cc84",
|
|
145
|
+
surface5: "#faddac",
|
|
146
|
+
surface4: "#fde6bd",
|
|
147
147
|
surface3: "#fff",
|
|
148
148
|
fgSurface4: "#2e1900",
|
|
149
|
-
fgSurface3: "#
|
|
150
|
-
fgSurface2: "#
|
|
151
|
-
fgSurface1: "#
|
|
152
|
-
stroke3: "#
|
|
153
|
-
stroke4: "#
|
|
154
|
-
stroke2: "#
|
|
155
|
-
stroke1: "#
|
|
149
|
+
fgSurface3: "#926300",
|
|
150
|
+
fgSurface2: "#b47f00",
|
|
151
|
+
fgSurface1: "#d7a02a",
|
|
152
|
+
stroke3: "#926300",
|
|
153
|
+
stroke4: "#6f4900",
|
|
154
|
+
stroke2: "#c7ad7e",
|
|
155
|
+
stroke1: "#d0b381",
|
|
156
156
|
bgFillDark: "#1f1e1b",
|
|
157
|
-
fgFillDark: "#
|
|
157
|
+
fgFillDark: "#f7efe2",
|
|
158
158
|
bgFillInverted2: "#1f1e1b",
|
|
159
159
|
bgFillInverted1: "#422800",
|
|
160
|
-
fgFillInverted: "#
|
|
161
|
-
surface1: "#
|
|
160
|
+
fgFillInverted: "#f7efe2",
|
|
161
|
+
surface1: "#ffecc4"
|
|
162
162
|
},
|
|
163
163
|
direction: "darker"
|
|
164
164
|
},
|
|
@@ -167,10 +167,10 @@ var DEFAULT_RAMPS = {
|
|
|
167
167
|
bgFill1: "#cc1818",
|
|
168
168
|
fgFill: "#f2efef",
|
|
169
169
|
bgFill2: "#b90000",
|
|
170
|
-
surface2: "#
|
|
171
|
-
surface6: "#
|
|
172
|
-
surface5: "#
|
|
173
|
-
surface4: "#
|
|
170
|
+
surface2: "#fff6f4",
|
|
171
|
+
surface6: "#f3c8c2",
|
|
172
|
+
surface5: "#f8dcd7",
|
|
173
|
+
surface4: "#f6e6e3",
|
|
174
174
|
surface3: "#fff",
|
|
175
175
|
fgSurface4: "#470000",
|
|
176
176
|
fgSurface3: "#cc1818",
|
|
@@ -178,14 +178,14 @@ var DEFAULT_RAMPS = {
|
|
|
178
178
|
fgSurface1: "#ff8879",
|
|
179
179
|
stroke3: "#cc1818",
|
|
180
180
|
stroke4: "#9d0000",
|
|
181
|
-
stroke2: "#
|
|
182
|
-
stroke1: "#
|
|
181
|
+
stroke2: "#d39c95",
|
|
182
|
+
stroke1: "#daa39b",
|
|
183
183
|
bgFillDark: "#231c1b",
|
|
184
184
|
fgFillDark: "#f2efef",
|
|
185
185
|
bgFillInverted2: "#231c1b",
|
|
186
186
|
bgFillInverted1: "#640000",
|
|
187
187
|
fgFillInverted: "#f2efef",
|
|
188
|
-
surface1: "#
|
|
188
|
+
surface1: "#fcece9"
|
|
189
189
|
},
|
|
190
190
|
direction: "darker"
|
|
191
191
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/default-ramps.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RampResult } from './types';\nimport type { DEFAULT_SEED_COLORS } from './constants';\n\nexport const DEFAULT_RAMPS: Record<\n\tkeyof typeof DEFAULT_SEED_COLORS,\n\tRampResult\n> = {\n\tbg: {\n\t\tramp: {\n\t\t\tsurface2: '#f8f8f8',\n\t\t\tbgFill1: '#555',\n\t\t\tfgFill: '#f0f0f0',\n\t\t\tbgFill2: '#484848',\n\t\t\tsurface6: '#d2d2d2',\n\t\t\tsurface5: '#e2e2e2',\n\t\t\tsurface4: '#eaeaea',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#1e1e1e',\n\t\t\tfgSurface3: '#6d6d6d',\n\t\t\tfgSurface2: '#8a8a8a',\n\t\t\tfgSurface1: '#aaa',\n\t\t\tstroke3: '#8a8a8a',\n\t\t\tstroke4: '#6c6c6c',\n\t\t\tstroke2: '#d8d8d8',\n\t\t\tstroke1: '#e0e0e0',\n\t\t\tbgFillDark: '#1e1e1e',\n\t\t\tfgFillDark: '#f0f0f0',\n\t\t\tbgFillInverted2: '#1e1e1e',\n\t\t\tbgFillInverted1: '#2d2d2d',\n\t\t\tfgFillInverted: '#f0f0f0',\n\t\t\tsurface1: '#f0f0f0',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\tprimary: {\n\t\tramp: {\n\t\t\tbgFill1: '#3858e9',\n\t\t\tfgFill: '#eff0f2',\n\t\t\tbgFill2: '#2e49d9',\n\t\t\tsurface2: '#
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RampResult } from './types';\nimport type { DEFAULT_SEED_COLORS } from './constants';\n\nexport const DEFAULT_RAMPS: Record<\n\tkeyof typeof DEFAULT_SEED_COLORS,\n\tRampResult\n> = {\n\tbg: {\n\t\tramp: {\n\t\t\tsurface2: '#f8f8f8',\n\t\t\tbgFill1: '#555',\n\t\t\tfgFill: '#f0f0f0',\n\t\t\tbgFill2: '#484848',\n\t\t\tsurface6: '#d2d2d2',\n\t\t\tsurface5: '#e2e2e2',\n\t\t\tsurface4: '#eaeaea',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#1e1e1e',\n\t\t\tfgSurface3: '#6d6d6d',\n\t\t\tfgSurface2: '#8a8a8a',\n\t\t\tfgSurface1: '#aaa',\n\t\t\tstroke3: '#8a8a8a',\n\t\t\tstroke4: '#6c6c6c',\n\t\t\tstroke2: '#d8d8d8',\n\t\t\tstroke1: '#e0e0e0',\n\t\t\tbgFillDark: '#1e1e1e',\n\t\t\tfgFillDark: '#f0f0f0',\n\t\t\tbgFillInverted2: '#1e1e1e',\n\t\t\tbgFillInverted1: '#2d2d2d',\n\t\t\tfgFillInverted: '#f0f0f0',\n\t\t\tsurface1: '#f0f0f0',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\tprimary: {\n\t\tramp: {\n\t\t\tbgFill1: '#3858e9',\n\t\t\tfgFill: '#eff0f2',\n\t\t\tbgFill2: '#2e49d9',\n\t\t\tsurface2: '#f6f8fd',\n\t\t\tsurface6: '#c7d2ed',\n\t\t\tsurface5: '#dbe2f4',\n\t\t\tsurface4: '#e6eaf4',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#0b0070',\n\t\t\tfgSurface3: '#3858e9',\n\t\t\tfgSurface2: '#5b82ff',\n\t\t\tfgSurface1: '#85a9ff',\n\t\t\tstroke3: '#3858e9',\n\t\t\tstroke4: '#2337c8',\n\t\t\tstroke2: '#9caacc',\n\t\t\tstroke1: '#a3b1d4',\n\t\t\tbgFillDark: '#1a1e27',\n\t\t\tfgFillDark: '#eff0f2',\n\t\t\tbgFillInverted2: '#1a1e27',\n\t\t\tbgFillInverted1: '#13009f',\n\t\t\tfgFillInverted: '#eff0f2',\n\t\t\tsurface1: '#ecf0f9',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\tinfo: {\n\t\tramp: {\n\t\t\tbgFill1: '#0090ff',\n\t\t\tfgFill: '#1a1f24',\n\t\t\tbgFill2: '#007fed',\n\t\t\tsurface2: '#f3f9ff',\n\t\t\tsurface6: '#bcd5f1',\n\t\t\tsurface5: '#d3e4f7',\n\t\t\tsurface4: '#deebfa',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#001b4f',\n\t\t\tfgSurface3: '#006bd7',\n\t\t\tfgSurface2: '#008bfa',\n\t\t\tfgSurface1: '#58b0ff',\n\t\t\tstroke3: '#006bd7',\n\t\t\tstroke4: '#004fa9',\n\t\t\tstroke2: '#95b5d9',\n\t\t\tstroke1: '#9fbcdc',\n\t\t\tbgFillDark: '#1a1f24',\n\t\t\tfgFillDark: '#eef0f3',\n\t\t\tbgFillInverted2: '#1a1f24',\n\t\t\tbgFillInverted1: '#002a69',\n\t\t\tfgFillInverted: '#eef0f3',\n\t\t\tsurface1: '#e4f1ff',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\tsuccess: {\n\t\tramp: {\n\t\t\tbgFill1: '#4ab866',\n\t\t\tfgFill: '#1b1f1c',\n\t\t\tbgFill2: '#37a756',\n\t\t\tsurface2: '#eaffed',\n\t\t\tsurface6: '#88e89b',\n\t\t\tsurface5: '#aff3bb',\n\t\t\tsurface4: '#c5f7cc',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#002900',\n\t\t\tfgSurface3: '#007f30',\n\t\t\tfgSurface2: '#2b9e4e',\n\t\t\tfgSurface1: '#53c16e',\n\t\t\tstroke3: '#007f30',\n\t\t\tstroke4: '#006013',\n\t\t\tstroke2: '#84c08e',\n\t\t\tstroke1: '#8ac894',\n\t\t\tbgFillDark: '#1b1f1c',\n\t\t\tfgFillDark: '#eaf3eb',\n\t\t\tbgFillInverted2: '#1b1f1c',\n\t\t\tbgFillInverted1: '#003701',\n\t\t\tfgFillInverted: '#eaf3eb',\n\t\t\tsurface1: '#cbfdd2',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\tcaution: {\n\t\tramp: {\n\t\t\tbgFill1: '#f0d149',\n\t\t\tfgFill: '#1f1e1b',\n\t\t\tbgFill2: '#dcbe2f',\n\t\t\tsurface2: '#fff9c9',\n\t\t\tsurface6: '#e8d172',\n\t\t\tsurface5: '#f7e18a',\n\t\t\tsurface4: '#fee994',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#281d00',\n\t\t\tfgSurface3: '#826a00',\n\t\t\tfgSurface2: '#a48600',\n\t\t\tfgSurface1: '#c6a800',\n\t\t\tstroke3: '#826a00',\n\t\t\tstroke4: '#624f00',\n\t\t\tstroke2: '#bdb17e',\n\t\t\tstroke1: '#c5b883',\n\t\t\tbgFillDark: '#1f1e1b',\n\t\t\tfgFillDark: '#fdf1bf',\n\t\t\tbgFillInverted2: '#1f1e1b',\n\t\t\tbgFillInverted1: '#392c00',\n\t\t\tfgFillInverted: '#fdf1bf',\n\t\t\tsurface1: '#ffef9b',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\twarning: {\n\t\tramp: {\n\t\t\tbgFill1: '#f0b849',\n\t\t\tfgFill: '#1f1e1b',\n\t\t\tbgFill2: '#dda633',\n\t\t\tsurface2: '#fff7e0',\n\t\t\tsurface6: '#f4cc84',\n\t\t\tsurface5: '#faddac',\n\t\t\tsurface4: '#fde6bd',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#2e1900',\n\t\t\tfgSurface3: '#926300',\n\t\t\tfgSurface2: '#b47f00',\n\t\t\tfgSurface1: '#d7a02a',\n\t\t\tstroke3: '#926300',\n\t\t\tstroke4: '#6f4900',\n\t\t\tstroke2: '#c7ad7e',\n\t\t\tstroke1: '#d0b381',\n\t\t\tbgFillDark: '#1f1e1b',\n\t\t\tfgFillDark: '#f7efe2',\n\t\t\tbgFillInverted2: '#1f1e1b',\n\t\t\tbgFillInverted1: '#422800',\n\t\t\tfgFillInverted: '#f7efe2',\n\t\t\tsurface1: '#ffecc4',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\terror: {\n\t\tramp: {\n\t\t\tbgFill1: '#cc1818',\n\t\t\tfgFill: '#f2efef',\n\t\t\tbgFill2: '#b90000',\n\t\t\tsurface2: '#fff6f4',\n\t\t\tsurface6: '#f3c8c2',\n\t\t\tsurface5: '#f8dcd7',\n\t\t\tsurface4: '#f6e6e3',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#470000',\n\t\t\tfgSurface3: '#cc1818',\n\t\t\tfgSurface2: '#f74c40',\n\t\t\tfgSurface1: '#ff8879',\n\t\t\tstroke3: '#cc1818',\n\t\t\tstroke4: '#9d0000',\n\t\t\tstroke2: '#d39c95',\n\t\t\tstroke1: '#daa39b',\n\t\t\tbgFillDark: '#231c1b',\n\t\t\tfgFillDark: '#f2efef',\n\t\t\tbgFillInverted2: '#231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AAW;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACR,MAAM;AAAA,MACL,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU;AAAA,IACX;AAAA,IACA,WAAW;AAAA,EACZ;AAAA,EACA,OAAO;AAAA,IACN,MAAM;AAAA,MACL,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU;AAAA,IACX;AAAA,IACA,WAAW;AAAA,EACZ;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/find-color-with-constraints.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { get, OKLCH, type
|
|
5
|
-
"mappings": ";AAGA,SAAS,KAAK,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { get, OKLCH, type PlainColorObject } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport { solveWithBisect } from './utils';\nimport { WHITE, BLACK, CONTRAST_EPSILON } from './constants';\nimport { clampToGamut, getContrast } from './color-utils';\nimport { type TaperChromaOptions, taperChroma } from './taper-chroma';\n\n/**\n * Difference of contrast values that grows linearly with the Y luminance.\n * We get more precise linear interpolations when we use this.\n * @param c1 First contrast.\n * @param c2 Second contrast.\n * @return Difference of logarithms.\n */\nfunction cdiff( c1: number, c2: number ) {\n\treturn Math.log( c1 / c2 );\n}\n\n/**\n * Solve for L such that:\n * - the L applied to the seed meets the contrast target against the reference\n * - the search is performed in one direction (ie lighter / darker)\n * - more constraints can be applied around lightness\n * @param reference\n * @param seed\n * @param target\n * @param direction\n * @param options\n * @param options.lightnessConstraint\n * @param options.lightnessConstraint.type\n * @param options.lightnessConstraint.value\n * @param options.taperChromaOptions\n */\nexport function findColorMeetingRequirements(\n\treference: PlainColorObject,\n\tseed: PlainColorObject,\n\ttarget: number,\n\tdirection: 'lighter' | 'darker',\n\t{\n\t\tlightnessConstraint,\n\t\ttaperChromaOptions,\n\t}: {\n\t\tlightnessConstraint?: {\n\t\t\ttype: 'force' | 'onlyIfSucceeds';\n\t\t\tvalue: number;\n\t\t};\n\t\ttaperChromaOptions?: TaperChromaOptions;\n\t} = {}\n): {\n\tcolor: PlainColorObject;\n\treached: boolean;\n\tachieved: number;\n\tdeficit?: number;\n} {\n\t// A target of 1 means same color.\n\t// A target lower than 1 doesn't make sense.\n\tif ( target <= 1 ) {\n\t\treturn {\n\t\t\tcolor: reference,\n\t\t\treached: true,\n\t\t\tachieved: 1,\n\t\t};\n\t}\n\n\tfunction getColorForL( l: number ): PlainColorObject {\n\t\tlet newL = l;\n\t\tlet newC = get( seed, [ OKLCH, 'c' ] );\n\n\t\tif ( taperChromaOptions ) {\n\t\t\tconst tapered = taperChroma( seed, newL, taperChromaOptions );\n\t\t\t// taperChroma returns either { l, c } or a ColorObject\n\t\t\tif ( 'l' in tapered && 'c' in tapered ) {\n\t\t\t\tnewL = tapered.l;\n\t\t\t\tnewC = tapered.c;\n\t\t\t} else {\n\t\t\t\t// It's already a ColorObject, return it directly\n\t\t\t\treturn tapered;\n\t\t\t}\n\t\t}\n\n\t\treturn clampToGamut( {\n\t\t\tspaceId: 'oklch',\n\t\t\tcoords: [ newL, newC, get( seed, [ OKLCH, 'h' ] ) ],\n\t\t} );\n\t}\n\n\t// Set the boundary based on the direction.\n\tconst mostContrastingL = direction === 'lighter' ? 1 : 0;\n\tconst mostContrastingColor = direction === 'lighter' ? WHITE : BLACK;\n\tconst highestContrast = getContrast( reference, mostContrastingColor );\n\n\tif ( lightnessConstraint ) {\n\t\t// Apply a specific L value.\n\t\t// Useful when pinning a step to a specific lightness, of to specify\n\t\t// min/max L values.\n\t\tconst colorWithExactL = getColorForL( lightnessConstraint.value );\n\t\tconst exactLContrast = getContrast( reference, colorWithExactL );\n\t\tconst exactLContrastMeetsTarget =\n\t\t\tcdiff( exactLContrast, target ) >= -CONTRAST_EPSILON;\n\n\t\t// If the L constraint is of \"force\" type, apply it even when it doesn't\n\t\t// meet the contrast target.\n\t\tif (\n\t\t\texactLContrastMeetsTarget ||\n\t\t\tlightnessConstraint.type === 'force'\n\t\t) {\n\t\t\treturn {\n\t\t\t\tcolor: colorWithExactL,\n\t\t\t\treached: exactLContrastMeetsTarget,\n\t\t\t\tachieved: exactLContrast,\n\t\t\t\tdeficit: exactLContrastMeetsTarget\n\t\t\t\t\t? cdiff( exactLContrast, highestContrast )\n\t\t\t\t\t: cdiff( target, exactLContrast ),\n\t\t\t};\n\t\t}\n\t}\n\n\t// If even the most contrasting color can't reach the target, the target is unreachable.\n\t// On the other hand, if the contrast is very close to the target, we consider it reached.\n\tif ( cdiff( highestContrast, target ) <= CONTRAST_EPSILON ) {\n\t\treturn {\n\t\t\tcolor: mostContrastingColor,\n\t\t\treached: cdiff( highestContrast, target ) >= -CONTRAST_EPSILON,\n\t\t\tachieved: highestContrast,\n\t\t\tdeficit: cdiff( target, highestContrast ),\n\t\t};\n\t}\n\n\t// Bracket: low fails, high meets.\n\t// Originally this was seed.oklch.l \u2014 although it's an assumption that works\n\t// only when we know for sure the direction of the search.\n\t// TODO: can we bring this back to seed.oklch.l ?\n\tconst lowerL = get( reference, [ OKLCH, 'l' ] );\n\tconst lowerContrast = cdiff( 1, target );\n\tconst upperL = mostContrastingL;\n\tconst upperContrast = cdiff( highestContrast, target );\n\n\tconst bestColor = solveWithBisect(\n\t\tgetColorForL,\n\t\t( c ) => cdiff( getContrast( reference, c ), target ),\n\t\tlowerL,\n\t\tlowerContrast,\n\t\tupperL,\n\t\tupperContrast\n\t);\n\n\treturn {\n\t\tcolor: bestColor,\n\t\treached: true,\n\t\tachieved: target,\n\t\t// Negative number that specifies how much room we have.\n\t\tdeficit: cdiff( target, highestContrast ),\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,KAAK,aAAoC;AAKlD,OAAO;AACP,SAAS,uBAAuB;AAChC,SAAS,OAAO,OAAO,wBAAwB;AAC/C,SAAS,cAAc,mBAAmB;AAC1C,SAAkC,mBAAmB;AASrD,SAAS,MAAO,IAAY,IAAa;AACxC,SAAO,KAAK,IAAK,KAAK,EAAG;AAC1B;AAiBO,SAAS,6BACf,WACA,MACA,QACA,WACA;AAAA,EACC;AAAA,EACA;AACD,IAMI,CAAC,GAMJ;AAGD,MAAK,UAAU,GAAI;AAClB,WAAO;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,MACT,UAAU;AAAA,IACX;AAAA,EACD;AAEA,WAAS,aAAc,GAA8B;AACpD,QAAI,OAAO;AACX,QAAI,OAAO,IAAK,MAAM,CAAE,OAAO,GAAI,CAAE;AAErC,QAAK,oBAAqB;AACzB,YAAM,UAAU,YAAa,MAAM,MAAM,kBAAmB;AAE5D,UAAK,OAAO,WAAW,OAAO,SAAU;AACvC,eAAO,QAAQ;AACf,eA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AAAA,IACT,UAAU;AAAA;AAAA,IAEV,SAAS,MAAO,QAAQ,eAAgB;AAAA,EACzC;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tclone,\n\tget,\n\tOKLCH,\n\tparse,\n\tset,\n\ttype ColorTypes,\n\ttype PlainColorObject,\n} from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport { clampToGamut, getContrast, getColorString } from './color-utils';\nimport { findColorMeetingRequirements } from './find-color-with-constraints';\nimport {\n\tsortByDependency,\n\tcomputeBetterFgColorDirection,\n\tadjustContrastTarget,\n\tstepsForStep,\n\tsolveWithBisect,\n} from './utils';\n\nimport type {\n\tFollowDirection,\n\tRamp,\n\tRampDirection,\n\tRampConfig,\n\tRampResult,\n} from './types';\nimport { CONTRAST_EPSILON } from './constants';\n\n/**\n * Calculate a complete color ramp based on the provided configuration.\n *\n * @param params - The calculation parameters\n * @param params.seed - The base color to build the ramp from\n * @param params.sortedSteps - Steps sorted in dependency order\n * @param params.config - Ramp configuration defining contrast requirements\n * @param params.mainDir - Primary direction for the ramp (lighter/darker)\n * @param params.oppDir - Opposite direction from mainDir\n * @param params.pinLightness - Optional lightness override for a given step\n * @param params.pinLightness.stepName\n * @param params.pinLightness.value\n * @return Object containing ramp results and satisfaction status\n */\nfunction calculateRamp( {\n\tseed,\n\tsortedSteps,\n\tconfig,\n\tmainDir,\n\toppDir,\n\tpinLightness,\n}: {\n\tseed:
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AAKP,OAAO;AACP,SAAS,cAAc,aAAa,sBAAsB;AAC1D,SAAS,oCAAoC;AAC7C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AASP,SAAS,wBAAwB;AAgBjC,SAAS,cAAe;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAUI;AACH,QAAM,cAAc,CAAC;AACrB,MAAI;AACJ,MAAI,aAAa;AACjB,MAAI,sBAAqC;AACzC,MAAI;AAIJ,QAAM,mBAAmB,oBAAI,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tclone,\n\tget,\n\tOKLCH,\n\tparse,\n\tset,\n\ttype ColorTypes,\n\ttype PlainColorObject,\n} from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport { clampToGamut, getContrast, getColorString } from './color-utils';\nimport { findColorMeetingRequirements } from './find-color-with-constraints';\nimport {\n\tsortByDependency,\n\tcomputeBetterFgColorDirection,\n\tadjustContrastTarget,\n\tstepsForStep,\n\tsolveWithBisect,\n} from './utils';\n\nimport type {\n\tFollowDirection,\n\tRamp,\n\tRampDirection,\n\tRampConfig,\n\tRampResult,\n} from './types';\nimport { CONTRAST_EPSILON } from './constants';\n\n/**\n * Calculate a complete color ramp based on the provided configuration.\n *\n * @param params - The calculation parameters\n * @param params.seed - The base color to build the ramp from\n * @param params.sortedSteps - Steps sorted in dependency order\n * @param params.config - Ramp configuration defining contrast requirements\n * @param params.mainDir - Primary direction for the ramp (lighter/darker)\n * @param params.oppDir - Opposite direction from mainDir\n * @param params.pinLightness - Optional lightness override for a given step\n * @param params.pinLightness.stepName\n * @param params.pinLightness.value\n * @return Object containing ramp results and satisfaction status\n */\nfunction calculateRamp( {\n\tseed,\n\tsortedSteps,\n\tconfig,\n\tmainDir,\n\toppDir,\n\tpinLightness,\n}: {\n\tseed: PlainColorObject;\n\tsortedSteps: ( keyof Ramp )[];\n\tconfig: RampConfig;\n\tmainDir: RampDirection;\n\toppDir: RampDirection;\n\tpinLightness?: {\n\t\tstepName: keyof Ramp;\n\t\tvalue: number;\n\t};\n} ) {\n\tconst rampResults = {} as Record< keyof Ramp, string >;\n\tlet warnings: string[] | undefined;\n\tlet maxDeficit = -Infinity;\n\tlet maxDeficitDirection: RampDirection = 'lighter';\n\tlet maxDeficitStep;\n\n\t// Keep track of the calculated colors, as they are going to be useful\n\t// when other colors reference them.\n\tconst calculatedColors = new Map< keyof Ramp | 'seed', PlainColorObject >();\n\tcalculatedColors.set( 'seed', seed );\n\n\tfor ( const stepName of sortedSteps ) {\n\t\tconst {\n\t\t\tcontrast,\n\t\t\tlightness: stepLightnessConstraint,\n\t\t\ttaperChromaOptions,\n\t\t\tsameAsIfPossible,\n\t\t} = config[ stepName ];\n\n\t\tconst referenceColor = calculatedColors.get( contrast.reference );\n\t\tif ( ! referenceColor ) {\n\t\t\tthrow new Error(\n\t\t\t\t`Reference color for step ${ stepName } not found: ${ contrast.reference }`\n\t\t\t);\n\t\t}\n\n\t\t// Check if we can reuse color from the `sameAsIfPossible` config option\n\t\tif ( sameAsIfPossible ) {\n\t\t\tconst candidateColor = calculatedColors.get( sameAsIfPossible );\n\t\t\tif ( ! candidateColor ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Same-as color for step ${ stepName } not found: ${ sameAsIfPossible }`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst candidateContrast = getContrast(\n\t\t\t\treferenceColor,\n\t\t\t\tcandidateColor\n\t\t\t);\n\t\t\tconst adjustedTarget = adjustContrastTarget( contrast.target );\n\t\t\t// If the candidate meets the contrast requirement, use it\n\t\t\tif ( candidateContrast >= adjustedTarget ) {\n\t\t\t\t// Store the reused color\n\t\t\t\tcalculatedColors.set( stepName, candidateColor );\n\t\t\t\trampResults[ stepName ] = getColorString( candidateColor );\n\n\t\t\t\tcontinue; // Skip to next step\n\t\t\t}\n\t\t}\n\n\t\tfunction computeDirection(\n\t\t\tcolor: ColorTypes,\n\t\t\tfollowDirection: FollowDirection\n\t\t): RampDirection {\n\t\t\tif ( followDirection === 'main' ) {\n\t\t\t\treturn mainDir;\n\t\t\t}\n\n\t\t\tif ( followDirection === 'opposite' ) {\n\t\t\t\treturn oppDir;\n\t\t\t}\n\n\t\t\tif ( followDirection === 'best' ) {\n\t\t\t\treturn computeBetterFgColorDirection(\n\t\t\t\t\tcolor,\n\t\t\t\t\tcontrast.preferLighter\n\t\t\t\t).better;\n\t\t\t}\n\n\t\t\treturn followDirection;\n\t\t}\n\n\t\tconst computedDir = computeDirection(\n\t\t\treferenceColor,\n\t\t\tcontrast.followDirection\n\t\t);\n\n\t\tconst adjustedTarget = adjustContrastTarget( contrast.target );\n\n\t\t// Define the lightness constraint, if needed.\n\t\tlet lightnessConstraint;\n\t\tif ( pinLightness?.stepName === stepName ) {\n\t\t\tlightnessConstraint = {\n\t\t\t\tvalue: pinLightness.value,\n\t\t\t\ttype: 'force',\n\t\t\t} as const;\n\t\t} else if ( stepLightnessConstraint ) {\n\t\t\tlightnessConstraint = {\n\t\t\t\tvalue: stepLightnessConstraint( computedDir ),\n\t\t\t\ttype: 'onlyIfSucceeds',\n\t\t\t} as const;\n\t\t}\n\n\t\t// Calculate the color meeting the requirements\n\t\tconst searchResults = findColorMeetingRequirements(\n\t\t\treferenceColor,\n\t\t\tseed,\n\t\t\tadjustedTarget,\n\t\t\tcomputedDir,\n\t\t\t{\n\t\t\t\tlightnessConstraint,\n\t\t\t\ttaperChromaOptions,\n\t\t\t}\n\t\t);\n\n\t\t// When the target contrast is not met, take note of it and use\n\t\t// that information to guide the ramp calculation bisection.\n\t\tif (\n\t\t\t! contrast.ignoreWhenAdjustingSeed &&\n\t\t\tsearchResults.deficit &&\n\t\t\tsearchResults.deficit > maxDeficit\n\t\t) {\n\t\t\tmaxDeficit = searchResults.deficit;\n\t\t\tmaxDeficitDirection = computedDir;\n\t\t\tmaxDeficitStep = stepName;\n\t\t}\n\n\t\t// Store calculated color for future dependencies\n\t\tcalculatedColors.set( stepName, searchResults.color );\n\n\t\t// Add to results\n\t\trampResults[ stepName ] = getColorString( searchResults.color );\n\n\t\tif ( ! searchResults.reached && ! contrast.ignoreWhenAdjustingSeed ) {\n\t\t\twarnings ??= [];\n\t\t\twarnings.push( stepName );\n\t\t}\n\t}\n\n\treturn {\n\t\trampResults,\n\t\twarnings,\n\t\tmaxDeficit,\n\t\tmaxDeficitDirection,\n\t\tmaxDeficitStep,\n\t};\n}\n\nexport function buildRamp(\n\tseedArg: string,\n\tconfig: RampConfig,\n\t{\n\t\tmainDirection,\n\t\tpinLightness,\n\t\trescaleToFitContrastTargets = true,\n\t}: {\n\t\tmainDirection?: RampDirection;\n\t\tpinLightness?: {\n\t\t\tstepName: keyof Ramp;\n\t\t\tvalue: number;\n\t\t};\n\t\trescaleToFitContrastTargets?: boolean;\n\t} = {}\n): RampResult {\n\tlet seed: PlainColorObject;\n\ttry {\n\t\tseed = clampToGamut( parse( seedArg ) );\n\t} catch ( error ) {\n\t\tthrow new Error(\n\t\t\t`Invalid seed color \"${ seedArg }\": ${\n\t\t\t\terror instanceof Error ? error.message : 'Unknown error'\n\t\t\t}`\n\t\t);\n\t}\n\n\tlet mainDir: RampDirection = 'lighter';\n\tlet oppDir: RampDirection = 'darker';\n\n\tif ( mainDirection ) {\n\t\tmainDir = mainDirection;\n\t\toppDir = mainDirection === 'darker' ? 'lighter' : 'darker';\n\t} else {\n\t\tconst { better, worse } = computeBetterFgColorDirection( seed );\n\t\tmainDir = better;\n\t\toppDir = worse;\n\t}\n\n\t// Get the correct calculation order based on dependencies\n\tconst sortedSteps = sortByDependency( config );\n\n\t// Calculate the ramp with the initial seed.\n\tconst {\n\t\trampResults,\n\t\twarnings,\n\t\tmaxDeficit,\n\t\tmaxDeficitDirection,\n\t\tmaxDeficitStep,\n\t} = calculateRamp( {\n\t\tseed,\n\t\tsortedSteps,\n\t\tconfig,\n\t\tmainDir,\n\t\toppDir,\n\t\tpinLightness,\n\t} );\n\n\tlet bestRamp = rampResults;\n\n\tif ( maxDeficit > CONTRAST_EPSILON && rescaleToFitContrastTargets ) {\n\t\tconst iterSteps = stepsForStep( maxDeficitStep!, config );\n\n\t\tfunction getSeedForL( l: number ): PlainColorObject {\n\t\t\treturn clampToGamut( set( clone( seed ), [ OKLCH, 'l' ], l ) );\n\t\t}\n\n\t\tfunction getDeficitForSeed( s: PlainColorObject ): number {\n\t\t\tconst iterationResults = calculateRamp( {\n\t\t\t\tseed: s,\n\t\t\t\tsortedSteps: iterSteps,\n\t\t\t\tconfig,\n\t\t\t\tmainDir,\n\t\t\t\toppDir,\n\t\t\t\tpinLightness,\n\t\t\t} );\n\n\t\t\t// If the constraints start failing in the opposite direction to the original\n\t\t\t// iteration's direction, that means we've moved too far away from the target.\n\t\t\t// Don't use the `maxDeficit` value because it's not related to our search,\n\t\t\t// and might even be positive, which would confuse the bisection algorithm.\n\t\t\treturn iterationResults.maxDeficitDirection === maxDeficitDirection\n\t\t\t\t? iterationResults.maxDeficit\n\t\t\t\t: -maxDeficit;\n\t\t}\n\n\t\t// For a scale with the \"lighter\" direction, the contrast can be improved\n\t\t// by darkening the seed. For \"darker\" direction, by lightening the seed.\n\t\tconst lowerSeedL = maxDeficitDirection === 'lighter' ? 0 : 1;\n\t\tconst lowerDeficit = -maxDeficit;\n\t\tconst upperSeedL = get( seed, [ OKLCH, 'l' ] );\n\t\tconst upperDeficit = maxDeficit;\n\n\t\tconst bestSeed = solveWithBisect(\n\t\t\tgetSeedForL,\n\t\t\tgetDeficitForSeed,\n\t\t\tlowerSeedL,\n\t\t\tlowerDeficit,\n\t\t\tupperSeedL,\n\t\t\tupperDeficit\n\t\t);\n\n\t\t// Calculate the final ramp with adjusted seed.\n\t\tbestRamp = calculateRamp( {\n\t\t\tseed: bestSeed,\n\t\t\tsortedSteps,\n\t\t\tconfig,\n\t\t\tmainDir,\n\t\t\toppDir,\n\t\t\tpinLightness,\n\t\t} ).rampResults;\n\t}\n\n\t// Swap surface1 and surface3 for darker ramps to maintain visual elevation hierarchy.\n\t// This ensures surface1 appears \"behind\" surface2, and surface3 appears \"in front\",\n\t// regardless of the ramp's main direction.\n\tif ( mainDir === 'darker' ) {\n\t\tconst tmpSurface1 = bestRamp.surface1;\n\t\tbestRamp.surface1 = bestRamp.surface3;\n\t\tbestRamp.surface3 = tmpSurface1;\n\t}\n\n\treturn {\n\t\tramp: bestRamp,\n\t\twarnings,\n\t\tdirection: mainDir,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AAKP,OAAO;AACP,SAAS,cAAc,aAAa,sBAAsB;AAC1D,SAAS,oCAAoC;AAC7C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AASP,SAAS,wBAAwB;AAgBjC,SAAS,cAAe;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAUI;AACH,QAAM,cAAc,CAAC;AACrB,MAAI;AACJ,MAAI,aAAa;AACjB,MAAI,sBAAqC;AACzC,MAAI;AAIJ,QAAM,mBAAmB,oBAAI,IAA6C;AAC1E,mBAAiB,IAAK,QAAQ,IAAK;AAEnC,aAAY,YAAY,aAAc;AAuCrC,QAAS,mBAAT,SACC,OACA,iBACgB;AAChB,UAAK,oBAAoB,QAAS;AACjC,eAAO;AAAA,MACR;AAEA,UAAK,oBAAoB,YAAa;AACrC,eAAO;AAAA,MACR;AAEA,UAAK,oBAAoB,QAAS;AACjC,eAAO;AAAA,UACN;AAAA,UACA,SAAS;AAAA,QACV,EAAE;AAAA,MACH;AAEA,aAAO;AAAA,IACR;AA1DA,UAAM;AAAA,MACL;AAAA,MACA,WAAW;AAAA,MACX;AAAA,MACA;AAAA,IACD,IAAI,OAAQ,QAAS;AAErB,UAAM,iBAAiB,iBAAiB,IAAK,SAAS,SAAU;AAChE,QAAK,CAAE,gBAAiB;AACvB,YAAM,IAAI;AAAA,QACT,4BAA6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,IAAI;AAC3D,UAAM,eAAe,CAAC;AACtB,UAAM,aAAa,IAAK,MAAM,CAAE,OAAO,GAAI,CAAE;AAC7C,UAAM,eAAe;AAErB,UAAM,WAAW;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAGA,eAAW,cAAe;AAAA,MACzB,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,CAAE,EAAE;AAAA,EACL;AAKA,MAAK,YAAY,UAAW;AAC3B,UAAM,cAAc,SAAS;AAC7B,aAAS,WAAW,SAAS;AAC7B,aAAS,WAAW;AAAA,EACrB;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,WAAW;AAAA,EACZ;AACD;",
|
|
6
6
|
"names": ["adjustedTarget"]
|
|
7
7
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
// packages/theme/src/color-ramps/lib/taper-chroma.ts
|
|
2
2
|
import {
|
|
3
3
|
get,
|
|
4
|
-
|
|
4
|
+
toGamut,
|
|
5
5
|
OKLCH,
|
|
6
|
-
P3,
|
|
7
6
|
sRGB
|
|
8
7
|
} from "colorjs.io/fn";
|
|
9
8
|
import "./register-color-spaces";
|
|
10
9
|
function taperChroma(seed, lTarget, options = {}) {
|
|
11
|
-
const gamut = options.gamut ??
|
|
12
|
-
const gamutSpace = gamut === "p3" ? P3 : sRGB;
|
|
10
|
+
const gamut = options.gamut ?? sRGB;
|
|
13
11
|
const alpha = options.alpha ?? 0.65;
|
|
14
12
|
const carry = options.carry ?? 0.5;
|
|
15
13
|
const cUpperBound = options.cUpperBound ?? 0.45;
|
|
@@ -27,22 +25,18 @@ function taperChroma(seed, lTarget, options = {}) {
|
|
|
27
25
|
hSeed = normalizeHue(options.hueFallback);
|
|
28
26
|
} else {
|
|
29
27
|
return {
|
|
30
|
-
|
|
31
|
-
coords: [clamp01(lTarget), 0, 0]
|
|
28
|
+
space: OKLCH,
|
|
29
|
+
coords: [clamp01(lTarget), 0, 0],
|
|
30
|
+
alpha: 1
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
const lSeed = clamp01(get(seed, [OKLCH, "l"]));
|
|
36
|
-
const cmaxSeed = getCachedMaxChromaAtLH(
|
|
37
|
-
lSeed,
|
|
38
|
-
hSeed,
|
|
39
|
-
gamutSpace,
|
|
40
|
-
cUpperBound
|
|
41
|
-
);
|
|
35
|
+
const cmaxSeed = getCachedMaxChromaAtLH(lSeed, hSeed, gamut, cUpperBound);
|
|
42
36
|
const cmaxTarget = getCachedMaxChromaAtLH(
|
|
43
37
|
clamp01(lTarget),
|
|
44
38
|
hSeed,
|
|
45
|
-
|
|
39
|
+
gamut,
|
|
46
40
|
cUpperBound
|
|
47
41
|
);
|
|
48
42
|
let seedRelative = 0;
|
|
@@ -56,17 +50,8 @@ function taperChroma(seed, lTarget, options = {}) {
|
|
|
56
50
|
kLight,
|
|
57
51
|
kDark
|
|
58
52
|
});
|
|
59
|
-
|
|
53
|
+
const cPlanned = cWithCarry * t;
|
|
60
54
|
const lOut = clamp01(lTarget);
|
|
61
|
-
const candidate = {
|
|
62
|
-
spaceId: "oklch",
|
|
63
|
-
coords: [lOut, cPlanned, hSeed]
|
|
64
|
-
};
|
|
65
|
-
if (!inGamut(candidate, gamutSpace)) {
|
|
66
|
-
const cap = Math.min(cPlanned, cUpperBound);
|
|
67
|
-
cPlanned = getCachedMaxChromaAtLH(lOut, hSeed, gamutSpace, cap);
|
|
68
|
-
}
|
|
69
|
-
cPlanned = Math.min(cPlanned, cSeed);
|
|
70
55
|
return { l: lOut, c: cPlanned };
|
|
71
56
|
}
|
|
72
57
|
function clamp01(x) {
|
|
@@ -102,9 +87,9 @@ function continuousTaper(seedL, targetL, opts) {
|
|
|
102
87
|
}
|
|
103
88
|
var maxChromaCache = /* @__PURE__ */ new Map();
|
|
104
89
|
function keyMax(l, h, gamut, cap) {
|
|
105
|
-
const lq = quantize(l,
|
|
106
|
-
const hq = quantize(normalizeHue(h),
|
|
107
|
-
const cq = quantize(cap,
|
|
90
|
+
const lq = quantize(l, 0.05);
|
|
91
|
+
const hq = quantize(normalizeHue(h), 10);
|
|
92
|
+
const cq = quantize(cap, 0.05);
|
|
108
93
|
return `${gamut}|L:${lq}|H:${hq}|cap:${cq}`;
|
|
109
94
|
}
|
|
110
95
|
function quantize(x, step) {
|
|
@@ -112,7 +97,7 @@ function quantize(x, step) {
|
|
|
112
97
|
return k * step;
|
|
113
98
|
}
|
|
114
99
|
function getCachedMaxChromaAtLH(l, h, gamutSpace, cap) {
|
|
115
|
-
const gamut = gamutSpace
|
|
100
|
+
const gamut = gamutSpace.id;
|
|
116
101
|
const key = keyMax(l, h, gamut, cap);
|
|
117
102
|
const hit = maxChromaCache.get(key);
|
|
118
103
|
if (typeof hit === "number") {
|
|
@@ -123,25 +108,13 @@ function getCachedMaxChromaAtLH(l, h, gamutSpace, cap) {
|
|
|
123
108
|
return computed;
|
|
124
109
|
}
|
|
125
110
|
function maxInGamutChromaAtLH(l, h, gamutSpace, cap) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const probe = {
|
|
134
|
-
spaceId: "oklch",
|
|
135
|
-
coords: [lFixed, mid, hFixed]
|
|
136
|
-
};
|
|
137
|
-
if (inGamut(probe, gamutSpace)) {
|
|
138
|
-
ok = mid;
|
|
139
|
-
lo = mid;
|
|
140
|
-
} else {
|
|
141
|
-
hi = mid;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return ok;
|
|
111
|
+
const probe = {
|
|
112
|
+
space: OKLCH,
|
|
113
|
+
coords: [l, cap, h],
|
|
114
|
+
alpha: 1
|
|
115
|
+
};
|
|
116
|
+
const clamped = toGamut(probe, { space: gamutSpace, method: "css" });
|
|
117
|
+
return get(clamped, [OKLCH, "c"]);
|
|
145
118
|
}
|
|
146
119
|
export {
|
|
147
120
|
taperChroma
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/taper-chroma.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tget,\n\
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tget,\n\ttoGamut,\n\tOKLCH,\n\tsRGB,\n\ttype PlainColorObject,\n\ttype ColorSpace,\n} from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\n\nexport interface TaperChromaOptions {\n\tgamut?: ColorSpace; // target gamut (default `sRGB`)\n\talpha?: number; // base fraction of Cmax at target (default 0.62)\n\tcarry?: number; // seed vividness carry exponent \u03B2 in [0..1] (default 0.5)\n\tcUpperBound?: number; // hard search cap for C (default 0.45)\n\t// Continuous taper around the seed (desaturate both sides slightly)\n\tradiusLight?: number; // distance in L where kLight is reached (default 0.20)\n\tradiusDark?: number; // distance in L where kDark is reached (default 0.20)\n\tkLight?: number; // floor multiplier near lighter side (default 0.85)\n\tkDark?: number; // floor multiplier near darker side (default 0.85)\n\t// Achromatic handling\n\thueFallback?: number; // degrees: if seed is achromatic and you still want color\n\tachromaEpsilon?: number; // \u2264 this chroma \u2192 treat as achromatic (default 0.005)\n}\n\n/**\n * Given the seed and the target lightness, tapers the chroma smoothly.\n * - C_intended = Cmax(Lt,H0) * alpha * (seedRelative^carry)\n * - Continuous taper vs |Lt - Ls| to softly reduce chroma for neighbors\n * - Downward-only clamp on C (preserve L & H)\n * @param seed\n * @param lTarget\n * @param options\n */\nexport function taperChroma(\n\tseed: PlainColorObject, // already OKLCH\n\tlTarget: number, // [0..1]\n\toptions: TaperChromaOptions = {}\n): { l: number; c: number } | PlainColorObject {\n\tconst gamut = options.gamut ?? sRGB;\n\tconst alpha = options.alpha ?? 0.65; // 0.7-0.8 works well for accent surface\n\tconst carry = options.carry ?? 0.5;\n\tconst cUpperBound = options.cUpperBound ?? 0.45;\n\tconst radiusLight = options.radiusLight ?? 0.2;\n\tconst radiusDark = options.radiusDark ?? 0.2;\n\tconst kLight = options.kLight ?? 0.85;\n\tconst kDark = options.kDark ?? 0.85;\n\tconst achromaEpsilon = options.achromaEpsilon ?? 0.005;\n\n\tconst cSeed = Math.max( 0, get( seed, [ OKLCH, 'c' ] ) );\n\tlet hSeed = Number( get( seed, [ OKLCH, 'h' ] ) );\n\n\tconst chromaIsTiny = cSeed < achromaEpsilon;\n\tconst hueIsInvalid = ! Number.isFinite( hSeed );\n\n\tif ( chromaIsTiny || hueIsInvalid ) {\n\t\tif ( typeof options.hueFallback === 'number' ) {\n\t\t\thSeed = normalizeHue( options.hueFallback );\n\t\t} else {\n\t\t\t// Respect achromatic intent: grayscale at target L\n\t\t\treturn {\n\t\t\t\tspace: OKLCH,\n\t\t\t\tcoords: [ clamp01( lTarget ), 0, 0 ],\n\t\t\t\talpha: 1,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Capacity at seed and target\n\tconst lSeed = clamp01( get( seed, [ OKLCH, 'l' ] ) );\n\tconst cmaxSeed = getCachedMaxChromaAtLH( lSeed, hSeed, gamut, cUpperBound );\n\tconst cmaxTarget = getCachedMaxChromaAtLH(\n\t\tclamp01( lTarget ),\n\t\thSeed,\n\t\tgamut,\n\t\tcUpperBound\n\t);\n\n\t// Seed vividness ratio (hue-fair normalization)\n\tlet seedRelative = 0;\n\tconst denom = cmaxSeed > 0 ? cmaxSeed : 1e-6;\n\tseedRelative = clamp01( cSeed / denom );\n\n\t// Intended chroma from local capacity, tempered by seed vividness\n\tconst cIntendedBase = alpha * cmaxTarget;\n\tconst cWithCarry =\n\t\tcIntendedBase * Math.pow( seedRelative, clamp01( carry ) );\n\n\t// Gentle, symmetric desaturation vs distance in L\n\tconst t = continuousTaper( lSeed, lTarget, {\n\t\tradiusLight,\n\t\tradiusDark,\n\t\tkLight,\n\t\tkDark,\n\t} );\n\tconst cPlanned = cWithCarry * t;\n\n\t// Downward-only clamp (preserve L & H)\n\tconst lOut = clamp01( lTarget );\n\n\treturn { l: lOut, c: cPlanned };\n}\n\n/* ---------------- helpers & caches ---------------- */\n\nfunction clamp01( x: number ): number {\n\tif ( x < 0 ) {\n\t\treturn 0;\n\t}\n\tif ( x > 1 ) {\n\t\treturn 1;\n\t}\n\treturn x;\n}\nfunction normalizeHue( h: number ): number {\n\tlet hue = h % 360;\n\tif ( hue < 0 ) {\n\t\thue += 360;\n\t}\n\treturn hue;\n}\nfunction raisedCosine( u: number ): number {\n\tconst x = clamp01( u );\n\treturn 0.5 - 0.5 * Math.cos( Math.PI * x );\n}\n\n/**\n * smooth, distance-from-seed chroma taper (raised-cosine per side)\n * @param seedL\n * @param targetL\n * @param opts\n * @param opts.radiusLight\n * @param opts.radiusDark\n * @param opts.kLight\n * @param opts.kDark\n */\nfunction continuousTaper(\n\tseedL: number,\n\ttargetL: number,\n\topts: {\n\t\tradiusLight: number;\n\t\tradiusDark: number;\n\t\tkLight: number;\n\t\tkDark: number;\n\t}\n): number {\n\tconst d = targetL - seedL;\n\tif ( d >= 0 ) {\n\t\tconst u = opts.radiusLight > 0 ? Math.abs( d ) / opts.radiusLight : 1;\n\t\tconst w = raisedCosine( u > 1 ? 1 : u );\n\t\treturn 1 - ( 1 - opts.kLight ) * w;\n\t}\n\tconst u = opts.radiusDark > 0 ? Math.abs( d ) / opts.radiusDark : 1;\n\tconst w = raisedCosine( u > 1 ? 1 : u );\n\treturn 1 - ( 1 - opts.kDark ) * w;\n}\n\n/* ---- chroma-capacity queries with small caches ---- */\n\nconst maxChromaCache = new Map< string, number >();\nfunction keyMax( l: number, h: number, gamut: string, cap: number ): string {\n\t// Quantize to keep cache compact\n\tconst lq = quantize( l, 0.05 );\n\tconst hq = quantize( normalizeHue( h ), 10 );\n\tconst cq = quantize( cap, 0.05 );\n\treturn `${ gamut }|L:${ lq }|H:${ hq }|cap:${ cq }`;\n}\n\nfunction quantize( x: number, step: number ): number {\n\tconst k = Math.round( x / step );\n\treturn k * step;\n}\n\nfunction getCachedMaxChromaAtLH(\n\tl: number,\n\th: number,\n\tgamutSpace: ColorSpace,\n\tcap: number\n): number {\n\tconst gamut = gamutSpace.id;\n\tconst key = keyMax( l, h, gamut, cap );\n\tconst hit = maxChromaCache.get( key );\n\tif ( typeof hit === 'number' ) {\n\t\treturn hit;\n\t}\n\n\tconst computed = maxInGamutChromaAtLH( l, h, gamutSpace, cap );\n\tmaxChromaCache.set( key, computed );\n\treturn computed;\n}\n\n/**\n * Find the max in-gamut chroma at fixed (L,H) in the target gamut\n * @param l\n * @param h\n * @param gamutSpace\n * @param cap\n */\nfunction maxInGamutChromaAtLH(\n\tl: number,\n\th: number,\n\tgamutSpace: ColorSpace,\n\tcap: number\n): number {\n\t// Construct a color with maximum chroma.\n\tconst probe: PlainColorObject = {\n\t\tspace: OKLCH,\n\t\tcoords: [ l, cap, h ],\n\t\talpha: 1,\n\t};\n\n\t// Let `toGamut` reduce the chroma to the gamut maximum.\n\tconst clamped = toGamut( probe, { space: gamutSpace, method: 'css' } );\n\n\treturn get( clamped, [ OKLCH, 'c' ] );\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AAKP,OAAO;AA0BA,SAAS,YACf,MACA,SACA,UAA8B,CAAC,GACe;AAC9C,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,aAAa,QAAQ,cAAc;AACzC,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,iBAAiB,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AAG,YAAY,GAAI;AAC7D,iBAAe,IAAK,KAAK,QAAS;AAClC,SAAO;AACR;AASA,SAAS,qBACR,GACA,GACA,YACA,KACS;AAET,QAAM,QAA0B;AAAA,IAC/B,OAAO;AAAA,IACP,QAAQ,CAAE,GAAG,KAAK,CAAE;AAAA,IACpB,OAAO;AAAA,EACR;AAGA,QAAM,UAAU,QAAS,OAAO,EAAE,OAAO,YAAY,QAAQ,MAAM,CAAE;AAErE,SAAO,IAAK,SAAS,CAAE,OAAO,GAAI,CAAE;AACrC;",
|
|
6
6
|
"names": ["u", "w"]
|
|
7
7
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
// packages/theme/src/prebuilt/js/design-tokens.js
|
|
2
2
|
var design_tokens_default = [
|
|
3
|
-
"--wpds-border-radius-
|
|
4
|
-
"--wpds-border-radius-
|
|
5
|
-
"--wpds-border-radius-
|
|
6
|
-
"--wpds-border-radius-
|
|
7
|
-
"--wpds-border-width-
|
|
3
|
+
"--wpds-border-radius-surface-xs",
|
|
4
|
+
"--wpds-border-radius-surface-sm",
|
|
5
|
+
"--wpds-border-radius-surface-md",
|
|
6
|
+
"--wpds-border-radius-surface-lg",
|
|
7
|
+
"--wpds-border-width-surface-xs",
|
|
8
|
+
"--wpds-border-width-surface-sm",
|
|
9
|
+
"--wpds-border-width-surface-md",
|
|
10
|
+
"--wpds-border-width-surface-lg",
|
|
11
|
+
"--wpds-border-width-interactive-focus",
|
|
8
12
|
"--wpds-color-bg-surface-neutral",
|
|
9
13
|
"--wpds-color-bg-surface-neutral-strong",
|
|
10
14
|
"--wpds-color-bg-surface-neutral-weak",
|
|
@@ -37,6 +41,15 @@ var design_tokens_default = [
|
|
|
37
41
|
"--wpds-color-bg-interactive-brand-weak",
|
|
38
42
|
"--wpds-color-bg-interactive-brand-weak-active",
|
|
39
43
|
"--wpds-color-bg-interactive-brand-weak-disabled",
|
|
44
|
+
"--wpds-color-bg-interactive-error",
|
|
45
|
+
"--wpds-color-bg-interactive-error-active",
|
|
46
|
+
"--wpds-color-bg-interactive-error-disabled",
|
|
47
|
+
"--wpds-color-bg-interactive-error-strong",
|
|
48
|
+
"--wpds-color-bg-interactive-error-strong-active",
|
|
49
|
+
"--wpds-color-bg-interactive-error-strong-disabled",
|
|
50
|
+
"--wpds-color-bg-interactive-error-weak",
|
|
51
|
+
"--wpds-color-bg-interactive-error-weak-active",
|
|
52
|
+
"--wpds-color-bg-interactive-error-weak-disabled",
|
|
40
53
|
"--wpds-color-bg-track-neutral-weak",
|
|
41
54
|
"--wpds-color-bg-track-neutral",
|
|
42
55
|
"--wpds-color-bg-thumb-neutral-weak",
|
|
@@ -70,6 +83,12 @@ var design_tokens_default = [
|
|
|
70
83
|
"--wpds-color-fg-interactive-brand-strong",
|
|
71
84
|
"--wpds-color-fg-interactive-brand-strong-active",
|
|
72
85
|
"--wpds-color-fg-interactive-brand-strong-disabled",
|
|
86
|
+
"--wpds-color-fg-interactive-error",
|
|
87
|
+
"--wpds-color-fg-interactive-error-active",
|
|
88
|
+
"--wpds-color-fg-interactive-error-disabled",
|
|
89
|
+
"--wpds-color-fg-interactive-error-strong",
|
|
90
|
+
"--wpds-color-fg-interactive-error-strong-active",
|
|
91
|
+
"--wpds-color-fg-interactive-error-strong-disabled",
|
|
73
92
|
"--wpds-color-stroke-surface-neutral",
|
|
74
93
|
"--wpds-color-stroke-surface-neutral-weak",
|
|
75
94
|
"--wpds-color-stroke-surface-neutral-strong",
|
|
@@ -89,7 +108,8 @@ var design_tokens_default = [
|
|
|
89
108
|
"--wpds-color-stroke-interactive-neutral-strong",
|
|
90
109
|
"--wpds-color-stroke-interactive-brand",
|
|
91
110
|
"--wpds-color-stroke-interactive-brand-active",
|
|
92
|
-
"--wpds-color-stroke-interactive-
|
|
111
|
+
"--wpds-color-stroke-interactive-error",
|
|
112
|
+
"--wpds-color-stroke-interactive-error-active",
|
|
93
113
|
"--wpds-color-stroke-interactive-error-strong",
|
|
94
114
|
"--wpds-color-stroke-focus-brand",
|
|
95
115
|
"--wpds-dimension-base",
|
|
@@ -98,6 +118,12 @@ var design_tokens_default = [
|
|
|
98
118
|
"--wpds-dimension-padding-surface-sm",
|
|
99
119
|
"--wpds-dimension-padding-surface-md",
|
|
100
120
|
"--wpds-dimension-padding-surface-lg",
|
|
121
|
+
"--wpds-dimension-gap-2xs",
|
|
122
|
+
"--wpds-dimension-gap-xs",
|
|
123
|
+
"--wpds-dimension-gap-sm",
|
|
124
|
+
"--wpds-dimension-gap-md",
|
|
125
|
+
"--wpds-dimension-gap-lg",
|
|
126
|
+
"--wpds-dimension-gap-xl",
|
|
101
127
|
"--wpds-elevation-x-small",
|
|
102
128
|
"--wpds-elevation-small",
|
|
103
129
|
"--wpds-elevation-medium",
|