@wordpress/theme 0.1.1-next.2f1c7c01b.0 → 0.2.1-next.16d95556a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/bin/generate-primitive-tokens/index.ts +1 -1
- package/bin/terrazzo-plugin-ds-tokens-docs/index.ts +5 -24
- package/bin/terrazzo-plugin-inline-alias-values/index.ts +84 -0
- package/bin/terrazzo-plugin-known-wpds-css-variables/index.ts +19 -39
- package/build/color-ramps/index.js +5 -5
- package/build/color-ramps/index.js.map +2 -2
- package/build/color-ramps/lib/constants.js +4 -4
- package/build/color-ramps/lib/constants.js.map +2 -2
- package/build/color-ramps/lib/default-ramps.js +154 -154
- package/build/color-ramps/lib/default-ramps.js.map +2 -2
- package/build/color-ramps/lib/find-color-with-constraints.js +36 -53
- package/build/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build/color-ramps/lib/index.js +72 -64
- package/build/color-ramps/lib/index.js.map +2 -2
- package/build/color-ramps/lib/ramp-configs.js +3 -3
- package/build/color-ramps/lib/ramp-configs.js.map +1 -1
- package/build/color-ramps/lib/types.js.map +1 -1
- package/build/color-ramps/lib/utils.js +63 -2
- package/build/color-ramps/lib/utils.js.map +2 -2
- package/build/prebuilt/js/design-tokens.js +5 -10
- package/build/prebuilt/js/design-tokens.js.map +2 -2
- package/build/prebuilt/json/figma.json +105 -905
- package/build/prebuilt/ts/color-tokens.js +137 -0
- package/build/prebuilt/ts/color-tokens.js.map +7 -0
- package/build/token-id.js +30 -0
- package/build/token-id.js.map +7 -0
- package/build/use-theme-provider-styles.js +15 -27
- package/build/use-theme-provider-styles.js.map +3 -3
- package/build-module/color-ramps/index.js +5 -5
- package/build-module/color-ramps/index.js.map +2 -2
- package/build-module/color-ramps/lib/constants.js +3 -3
- package/build-module/color-ramps/lib/constants.js.map +2 -2
- package/build-module/color-ramps/lib/default-ramps.js +154 -154
- package/build-module/color-ramps/lib/default-ramps.js.map +2 -2
- package/build-module/color-ramps/lib/find-color-with-constraints.js +38 -60
- package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build-module/color-ramps/lib/index.js +76 -66
- package/build-module/color-ramps/lib/index.js.map +2 -2
- package/build-module/color-ramps/lib/ramp-configs.js +3 -3
- package/build-module/color-ramps/lib/ramp-configs.js.map +1 -1
- package/build-module/color-ramps/lib/utils.js +63 -2
- package/build-module/color-ramps/lib/utils.js.map +2 -2
- package/build-module/prebuilt/js/design-tokens.js +5 -10
- package/build-module/prebuilt/js/design-tokens.js.map +2 -2
- package/build-module/prebuilt/json/figma.json +105 -905
- package/build-module/prebuilt/ts/color-tokens.js +117 -0
- package/build-module/prebuilt/ts/color-tokens.js.map +7 -0
- package/build-module/token-id.js +6 -0
- package/build-module/token-id.js.map +7 -0
- package/build-module/use-theme-provider-styles.js +15 -27
- package/build-module/use-theme-provider-styles.js.map +2 -2
- package/build-types/color-ramps/lib/constants.d.ts +2 -2
- package/build-types/color-ramps/lib/constants.d.ts.map +1 -1
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +2 -3
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
- package/build-types/color-ramps/lib/index.d.ts.map +1 -1
- package/build-types/color-ramps/lib/types.d.ts +2 -4
- package/build-types/color-ramps/lib/types.d.ts.map +1 -1
- package/build-types/color-ramps/lib/utils.d.ts +21 -2
- package/build-types/color-ramps/lib/utils.d.ts.map +1 -1
- package/build-types/color-ramps/stories/index.story.d.ts.map +1 -1
- package/build-types/color-ramps/stories/ramp-table.d.ts +2 -4
- package/build-types/color-ramps/stories/ramp-table.d.ts.map +1 -1
- package/build-types/prebuilt/ts/color-tokens.d.ts +7 -0
- package/build-types/prebuilt/ts/color-tokens.d.ts.map +1 -0
- package/build-types/stories/index.story.d.ts.map +1 -1
- package/build-types/theme-provider.d.ts.map +1 -1
- package/build-types/token-id.d.ts +9 -0
- package/build-types/token-id.d.ts.map +1 -0
- package/build-types/use-theme-provider-styles.d.ts.map +1 -1
- package/docs/ds-tokens.md +10 -178
- package/package.json +4 -4
- package/src/color-ramps/index.ts +5 -5
- package/src/color-ramps/lib/constants.ts +7 -5
- package/src/color-ramps/lib/default-ramps.ts +154 -154
- package/src/color-ramps/lib/find-color-with-constraints.ts +53 -77
- package/src/color-ramps/lib/index.ts +100 -100
- package/src/color-ramps/lib/ramp-configs.ts +3 -3
- package/src/color-ramps/lib/types.ts +2 -7
- package/src/color-ramps/lib/utils.ts +109 -5
- package/src/color-ramps/stories/index.story.tsx +4 -1
- package/src/color-ramps/stories/ramp-table.tsx +15 -26
- package/src/color-ramps/test/__snapshots__/index.test.ts.snap +16891 -1059
- package/src/color-ramps/test/index.test.ts +43 -16
- package/src/prebuilt/css/design-tokens.css +88 -413
- package/src/prebuilt/js/design-tokens.js +5 -10
- package/src/prebuilt/json/figma.json +105 -905
- package/src/prebuilt/ts/color-tokens.ts +117 -0
- package/src/stories/index.story.tsx +4 -18
- package/src/test/token-id.test.ts +12 -0
- package/src/token-id.ts +9 -0
- package/src/use-theme-provider-styles.ts +17 -35
- package/terrazzo.config.ts +15 -12
- package/tokens/color.json +82 -82
- package/tokens/dimension.json +75 -0
- package/tsconfig.bin.tsbuildinfo +1 -1
- package/tsconfig.src.tsbuildinfo +1 -1
- package/build/prebuilt/ts/design-tokens.js +0 -391
- package/build/prebuilt/ts/design-tokens.js.map +0 -7
- package/build-module/prebuilt/ts/design-tokens.js +0 -371
- package/build-module/prebuilt/ts/design-tokens.js.map +0 -7
- package/build-types/prebuilt/ts/design-tokens.d.ts +0 -7
- package/build-types/prebuilt/ts/design-tokens.d.ts.map +0 -1
- package/src/prebuilt/ts/design-tokens.ts +0 -371
- package/tokens/spacing.json +0 -45
|
@@ -2,190 +2,190 @@
|
|
|
2
2
|
var DEFAULT_RAMPS = {
|
|
3
3
|
bg: {
|
|
4
4
|
ramp: {
|
|
5
|
-
surface2:
|
|
6
|
-
bgFill1:
|
|
7
|
-
fgFill:
|
|
8
|
-
bgFill2:
|
|
9
|
-
surface6:
|
|
10
|
-
surface5:
|
|
11
|
-
surface4:
|
|
12
|
-
surface3:
|
|
13
|
-
fgSurface4:
|
|
14
|
-
fgSurface3:
|
|
15
|
-
fgSurface2:
|
|
16
|
-
fgSurface1:
|
|
17
|
-
stroke3:
|
|
18
|
-
stroke4:
|
|
19
|
-
stroke2:
|
|
20
|
-
stroke1:
|
|
21
|
-
bgFillDark:
|
|
22
|
-
fgFillDark:
|
|
23
|
-
bgFillInverted2:
|
|
24
|
-
bgFillInverted1:
|
|
25
|
-
fgFillInverted:
|
|
26
|
-
surface1:
|
|
5
|
+
surface2: "#f8f8f8",
|
|
6
|
+
bgFill1: "#555",
|
|
7
|
+
fgFill: "#f0f0f0",
|
|
8
|
+
bgFill2: "#494949",
|
|
9
|
+
surface6: "#d3d3d3",
|
|
10
|
+
surface5: "#e3e3e3",
|
|
11
|
+
surface4: "#eaeaea",
|
|
12
|
+
surface3: "#fff",
|
|
13
|
+
fgSurface4: "#1e1e1e",
|
|
14
|
+
fgSurface3: "#6e6e6e",
|
|
15
|
+
fgSurface2: "#8b8b8b",
|
|
16
|
+
fgSurface1: "#ababab",
|
|
17
|
+
stroke3: "#8b8b8b",
|
|
18
|
+
stroke4: "#6d6d6d",
|
|
19
|
+
stroke2: "#adadad",
|
|
20
|
+
stroke1: "#cfcfcf",
|
|
21
|
+
bgFillDark: "#1e1e1e",
|
|
22
|
+
fgFillDark: "#f0f0f0",
|
|
23
|
+
bgFillInverted2: "#1e1e1e",
|
|
24
|
+
bgFillInverted1: "#2d2d2d",
|
|
25
|
+
fgFillInverted: "#f0f0f0",
|
|
26
|
+
surface1: "#f0f0f0"
|
|
27
27
|
},
|
|
28
28
|
direction: "darker"
|
|
29
29
|
},
|
|
30
30
|
primary: {
|
|
31
31
|
ramp: {
|
|
32
|
-
bgFill1:
|
|
33
|
-
fgFill:
|
|
34
|
-
bgFill2:
|
|
35
|
-
surface2:
|
|
36
|
-
surface6:
|
|
37
|
-
surface5:
|
|
38
|
-
surface4:
|
|
39
|
-
surface3:
|
|
40
|
-
fgSurface4:
|
|
41
|
-
fgSurface3:
|
|
42
|
-
fgSurface2:
|
|
43
|
-
fgSurface1:
|
|
44
|
-
stroke3:
|
|
45
|
-
stroke4:
|
|
46
|
-
stroke2:
|
|
47
|
-
stroke1:
|
|
48
|
-
bgFillDark:
|
|
49
|
-
fgFillDark:
|
|
50
|
-
bgFillInverted2:
|
|
51
|
-
bgFillInverted1:
|
|
52
|
-
fgFillInverted:
|
|
53
|
-
surface1:
|
|
32
|
+
bgFill1: "#3858e9",
|
|
33
|
+
fgFill: "#eff0f2",
|
|
34
|
+
bgFill2: "#2e49da",
|
|
35
|
+
surface2: "#f6f8fc",
|
|
36
|
+
surface6: "#c7d3ef",
|
|
37
|
+
surface5: "#dce3f5",
|
|
38
|
+
surface4: "#e5ebf7",
|
|
39
|
+
surface3: "#fff",
|
|
40
|
+
fgSurface4: "#080071",
|
|
41
|
+
fgSurface3: "#3858e9",
|
|
42
|
+
fgSurface2: "#5881ff",
|
|
43
|
+
fgSurface1: "#84a9ff",
|
|
44
|
+
stroke3: "#3858e9",
|
|
45
|
+
stroke4: "#2337c8",
|
|
46
|
+
stroke2: "#6d83bf",
|
|
47
|
+
stroke1: "#91a2cf",
|
|
48
|
+
bgFillDark: "#1b1e26",
|
|
49
|
+
fgFillDark: "#eff0f2",
|
|
50
|
+
bgFillInverted2: "#1b1e26",
|
|
51
|
+
bgFillInverted1: "#12009f",
|
|
52
|
+
fgFillInverted: "#eff0f2",
|
|
53
|
+
surface1: "#edf0fa"
|
|
54
54
|
},
|
|
55
55
|
direction: "darker"
|
|
56
56
|
},
|
|
57
57
|
info: {
|
|
58
58
|
ramp: {
|
|
59
|
-
bgFill1:
|
|
60
|
-
fgFill:
|
|
61
|
-
bgFill2:
|
|
62
|
-
surface2:
|
|
63
|
-
surface6:
|
|
64
|
-
surface5:
|
|
65
|
-
surface4:
|
|
66
|
-
surface3:
|
|
67
|
-
fgSurface4:
|
|
68
|
-
fgSurface3:
|
|
69
|
-
fgSurface2:
|
|
70
|
-
fgSurface1:
|
|
71
|
-
stroke3:
|
|
72
|
-
stroke4:
|
|
73
|
-
stroke2:
|
|
74
|
-
stroke1:
|
|
75
|
-
bgFillDark:
|
|
76
|
-
fgFillDark:
|
|
77
|
-
bgFillInverted2:
|
|
78
|
-
bgFillInverted1:
|
|
79
|
-
fgFillInverted:
|
|
80
|
-
surface1:
|
|
59
|
+
bgFill1: "#0090ff",
|
|
60
|
+
fgFill: "#1b1e23",
|
|
61
|
+
bgFill2: "#0081ef",
|
|
62
|
+
surface2: "#f5f9fd",
|
|
63
|
+
surface6: "#bed6f1",
|
|
64
|
+
surface5: "#d5e5f6",
|
|
65
|
+
surface4: "#e0ebf8",
|
|
66
|
+
surface3: "#fff",
|
|
67
|
+
fgSurface4: "#001758",
|
|
68
|
+
fgSurface3: "#006dd9",
|
|
69
|
+
fgSurface2: "#008cfb",
|
|
70
|
+
fgSurface1: "#53b1ff",
|
|
71
|
+
stroke3: "#006dd9",
|
|
72
|
+
stroke4: "#004eb8",
|
|
73
|
+
stroke2: "#5d8fc6",
|
|
74
|
+
stroke1: "#8aaed6",
|
|
75
|
+
bgFillDark: "#1b1e23",
|
|
76
|
+
fgFillDark: "#eff0f2",
|
|
77
|
+
bgFillInverted2: "#1b1e23",
|
|
78
|
+
bgFillInverted1: "#002675",
|
|
79
|
+
fgFillInverted: "#eff0f2",
|
|
80
|
+
surface1: "#eaf1fa"
|
|
81
81
|
},
|
|
82
82
|
direction: "darker"
|
|
83
83
|
},
|
|
84
84
|
success: {
|
|
85
85
|
ramp: {
|
|
86
|
-
bgFill1:
|
|
87
|
-
fgFill:
|
|
88
|
-
bgFill2:
|
|
89
|
-
surface2:
|
|
90
|
-
surface6:
|
|
91
|
-
surface5:
|
|
92
|
-
surface4:
|
|
93
|
-
surface3:
|
|
94
|
-
fgSurface4:
|
|
95
|
-
fgSurface3:
|
|
96
|
-
fgSurface2:
|
|
97
|
-
fgSurface1:
|
|
98
|
-
stroke3:
|
|
99
|
-
stroke4:
|
|
100
|
-
stroke2:
|
|
101
|
-
stroke1:
|
|
102
|
-
bgFillDark:
|
|
103
|
-
fgFillDark:
|
|
104
|
-
bgFillInverted2:
|
|
105
|
-
bgFillInverted1:
|
|
106
|
-
fgFillInverted:
|
|
107
|
-
surface1:
|
|
86
|
+
bgFill1: "#4ab866",
|
|
87
|
+
fgFill: "#1b1f1c",
|
|
88
|
+
bgFill2: "#37a857",
|
|
89
|
+
surface2: "#f0fcf2",
|
|
90
|
+
surface6: "#7eea95",
|
|
91
|
+
surface5: "#b7f2c1",
|
|
92
|
+
surface4: "#cdf5d3",
|
|
93
|
+
surface3: "#fff",
|
|
94
|
+
fgSurface4: "#002b00",
|
|
95
|
+
fgSurface3: "#008031",
|
|
96
|
+
fgSurface2: "#2c9f4e",
|
|
97
|
+
fgSurface1: "#54c16f",
|
|
98
|
+
stroke3: "#008031",
|
|
99
|
+
stroke4: "#006314",
|
|
100
|
+
stroke2: "#61986b",
|
|
101
|
+
stroke1: "#77ba84",
|
|
102
|
+
bgFillDark: "#1b1f1c",
|
|
103
|
+
fgFillDark: "#edf2ed",
|
|
104
|
+
bgFillInverted2: "#1b1f1c",
|
|
105
|
+
bgFillInverted1: "#003800",
|
|
106
|
+
fgFillInverted: "#edf2ed",
|
|
107
|
+
surface1: "#ddf8e1"
|
|
108
108
|
},
|
|
109
109
|
direction: "darker"
|
|
110
110
|
},
|
|
111
111
|
caution: {
|
|
112
112
|
ramp: {
|
|
113
|
-
bgFill1:
|
|
114
|
-
fgFill:
|
|
115
|
-
bgFill2:
|
|
116
|
-
surface2:
|
|
117
|
-
surface6:
|
|
118
|
-
surface5:
|
|
119
|
-
surface4:
|
|
120
|
-
surface3:
|
|
121
|
-
fgSurface4:
|
|
122
|
-
fgSurface3:
|
|
123
|
-
fgSurface2:
|
|
124
|
-
fgSurface1:
|
|
125
|
-
stroke3:
|
|
126
|
-
stroke4:
|
|
127
|
-
stroke2:
|
|
128
|
-
stroke1:
|
|
129
|
-
bgFillDark:
|
|
130
|
-
fgFillDark:
|
|
131
|
-
bgFillInverted2:
|
|
132
|
-
bgFillInverted1:
|
|
133
|
-
fgFillInverted:
|
|
134
|
-
surface1:
|
|
113
|
+
bgFill1: "#f0d149",
|
|
114
|
+
fgFill: "#1f1e1b",
|
|
115
|
+
bgFill2: "#ddbe30",
|
|
116
|
+
surface2: "#fdf9e7",
|
|
117
|
+
surface6: "#ecd367",
|
|
118
|
+
surface5: "#f5e399",
|
|
119
|
+
surface4: "#f8ebb5",
|
|
120
|
+
surface3: "#fff",
|
|
121
|
+
fgSurface4: "#291d00",
|
|
122
|
+
fgSurface3: "#876b00",
|
|
123
|
+
fgSurface2: "#a78900",
|
|
124
|
+
fgSurface1: "#c9aa00",
|
|
125
|
+
stroke3: "#876b00",
|
|
126
|
+
stroke4: "#675000",
|
|
127
|
+
stroke2: "#978c60",
|
|
128
|
+
stroke1: "#b8ab75",
|
|
129
|
+
bgFillDark: "#1f1e1b",
|
|
130
|
+
fgFillDark: "#f6f1da",
|
|
131
|
+
bgFillInverted2: "#1f1e1b",
|
|
132
|
+
bgFillInverted1: "#3a2b00",
|
|
133
|
+
fgFillInverted: "#f6f1da",
|
|
134
|
+
surface1: "#faf1cd"
|
|
135
135
|
},
|
|
136
136
|
direction: "darker"
|
|
137
137
|
},
|
|
138
138
|
warning: {
|
|
139
139
|
ramp: {
|
|
140
|
-
bgFill1:
|
|
141
|
-
fgFill:
|
|
142
|
-
bgFill2:
|
|
143
|
-
surface2:
|
|
144
|
-
surface6:
|
|
145
|
-
surface5:
|
|
146
|
-
surface4:
|
|
147
|
-
surface3:
|
|
148
|
-
fgSurface4:
|
|
149
|
-
fgSurface3:
|
|
150
|
-
fgSurface2:
|
|
151
|
-
fgSurface1:
|
|
152
|
-
stroke3:
|
|
153
|
-
stroke4:
|
|
154
|
-
stroke2:
|
|
155
|
-
stroke1:
|
|
156
|
-
bgFillDark:
|
|
157
|
-
fgFillDark:
|
|
158
|
-
bgFillInverted2:
|
|
159
|
-
bgFillInverted1:
|
|
160
|
-
fgFillInverted:
|
|
161
|
-
surface1:
|
|
140
|
+
bgFill1: "#f0b849",
|
|
141
|
+
fgFill: "#1f1e1b",
|
|
142
|
+
bgFill2: "#dea633",
|
|
143
|
+
surface2: "#fdf7ee",
|
|
144
|
+
surface6: "#f1ce90",
|
|
145
|
+
surface5: "#f6e0bb",
|
|
146
|
+
surface4: "#f8e9cd",
|
|
147
|
+
surface3: "#fff",
|
|
148
|
+
fgSurface4: "#2f1800",
|
|
149
|
+
fgSurface3: "#976300",
|
|
150
|
+
fgSurface2: "#b78100",
|
|
151
|
+
fgSurface1: "#d9a22e",
|
|
152
|
+
stroke3: "#976300",
|
|
153
|
+
stroke4: "#754900",
|
|
154
|
+
stroke2: "#9f8860",
|
|
155
|
+
stroke1: "#c2a776",
|
|
156
|
+
bgFillDark: "#1f1e1b",
|
|
157
|
+
fgFillDark: "#f3f0e9",
|
|
158
|
+
bgFillInverted2: "#1f1e1b",
|
|
159
|
+
bgFillInverted1: "#432600",
|
|
160
|
+
fgFillInverted: "#f3f0e9",
|
|
161
|
+
surface1: "#faefdc"
|
|
162
162
|
},
|
|
163
163
|
direction: "darker"
|
|
164
164
|
},
|
|
165
165
|
error: {
|
|
166
166
|
ramp: {
|
|
167
|
-
bgFill1:
|
|
168
|
-
fgFill:
|
|
169
|
-
bgFill2:
|
|
170
|
-
surface2:
|
|
171
|
-
surface6:
|
|
172
|
-
surface5:
|
|
173
|
-
surface4:
|
|
174
|
-
surface3:
|
|
175
|
-
fgSurface4:
|
|
176
|
-
fgSurface3:
|
|
177
|
-
fgSurface2:
|
|
178
|
-
fgSurface1:
|
|
179
|
-
stroke3:
|
|
180
|
-
stroke4:
|
|
181
|
-
stroke2:
|
|
182
|
-
stroke1:
|
|
183
|
-
bgFillDark:
|
|
184
|
-
fgFillDark:
|
|
185
|
-
bgFillInverted2:
|
|
186
|
-
bgFillInverted1:
|
|
187
|
-
fgFillInverted:
|
|
188
|
-
surface1:
|
|
167
|
+
bgFill1: "#cc1818",
|
|
168
|
+
fgFill: "#f2efef",
|
|
169
|
+
bgFill2: "#bc0001",
|
|
170
|
+
surface2: "#fdf6f5",
|
|
171
|
+
surface6: "#f5c9c2",
|
|
172
|
+
surface5: "#f9dcd8",
|
|
173
|
+
surface4: "#fae5e2",
|
|
174
|
+
surface3: "#fff",
|
|
175
|
+
fgSurface4: "#4a0000",
|
|
176
|
+
fgSurface3: "#cc1818",
|
|
177
|
+
fgSurface2: "#f84d41",
|
|
178
|
+
fgSurface1: "#ff8373",
|
|
179
|
+
stroke3: "#cc1818",
|
|
180
|
+
stroke4: "#a70000",
|
|
181
|
+
stroke2: "#ca675c",
|
|
182
|
+
stroke1: "#dc8e83",
|
|
183
|
+
bgFillDark: "#231c1b",
|
|
184
|
+
fgFillDark: "#f2efef",
|
|
185
|
+
bgFillInverted2: "#231c1b",
|
|
186
|
+
bgFillInverted1: "#680000",
|
|
187
|
+
fgFillInverted: "#f2efef",
|
|
188
|
+
surface1: "#fcedea"
|
|
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:
|
|
5
|
-
"mappings": ";AAMO,IAAM,gBAGT;AAAA,EACH,IAAI;AAAA,IACH,MAAM;AAAA,MACL,UAAU
|
|
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: '#494949',\n\t\t\tsurface6: '#d3d3d3',\n\t\t\tsurface5: '#e3e3e3',\n\t\t\tsurface4: '#eaeaea',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#1e1e1e',\n\t\t\tfgSurface3: '#6e6e6e',\n\t\t\tfgSurface2: '#8b8b8b',\n\t\t\tfgSurface1: '#ababab',\n\t\t\tstroke3: '#8b8b8b',\n\t\t\tstroke4: '#6d6d6d',\n\t\t\tstroke2: '#adadad',\n\t\t\tstroke1: '#cfcfcf',\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: '#2e49da',\n\t\t\tsurface2: '#f6f8fc',\n\t\t\tsurface6: '#c7d3ef',\n\t\t\tsurface5: '#dce3f5',\n\t\t\tsurface4: '#e5ebf7',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#080071',\n\t\t\tfgSurface3: '#3858e9',\n\t\t\tfgSurface2: '#5881ff',\n\t\t\tfgSurface1: '#84a9ff',\n\t\t\tstroke3: '#3858e9',\n\t\t\tstroke4: '#2337c8',\n\t\t\tstroke2: '#6d83bf',\n\t\t\tstroke1: '#91a2cf',\n\t\t\tbgFillDark: '#1b1e26',\n\t\t\tfgFillDark: '#eff0f2',\n\t\t\tbgFillInverted2: '#1b1e26',\n\t\t\tbgFillInverted1: '#12009f',\n\t\t\tfgFillInverted: '#eff0f2',\n\t\t\tsurface1: '#edf0fa',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n\tinfo: {\n\t\tramp: {\n\t\t\tbgFill1: '#0090ff',\n\t\t\tfgFill: '#1b1e23',\n\t\t\tbgFill2: '#0081ef',\n\t\t\tsurface2: '#f5f9fd',\n\t\t\tsurface6: '#bed6f1',\n\t\t\tsurface5: '#d5e5f6',\n\t\t\tsurface4: '#e0ebf8',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#001758',\n\t\t\tfgSurface3: '#006dd9',\n\t\t\tfgSurface2: '#008cfb',\n\t\t\tfgSurface1: '#53b1ff',\n\t\t\tstroke3: '#006dd9',\n\t\t\tstroke4: '#004eb8',\n\t\t\tstroke2: '#5d8fc6',\n\t\t\tstroke1: '#8aaed6',\n\t\t\tbgFillDark: '#1b1e23',\n\t\t\tfgFillDark: '#eff0f2',\n\t\t\tbgFillInverted2: '#1b1e23',\n\t\t\tbgFillInverted1: '#002675',\n\t\t\tfgFillInverted: '#eff0f2',\n\t\t\tsurface1: '#eaf1fa',\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: '#37a857',\n\t\t\tsurface2: '#f0fcf2',\n\t\t\tsurface6: '#7eea95',\n\t\t\tsurface5: '#b7f2c1',\n\t\t\tsurface4: '#cdf5d3',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#002b00',\n\t\t\tfgSurface3: '#008031',\n\t\t\tfgSurface2: '#2c9f4e',\n\t\t\tfgSurface1: '#54c16f',\n\t\t\tstroke3: '#008031',\n\t\t\tstroke4: '#006314',\n\t\t\tstroke2: '#61986b',\n\t\t\tstroke1: '#77ba84',\n\t\t\tbgFillDark: '#1b1f1c',\n\t\t\tfgFillDark: '#edf2ed',\n\t\t\tbgFillInverted2: '#1b1f1c',\n\t\t\tbgFillInverted1: '#003800',\n\t\t\tfgFillInverted: '#edf2ed',\n\t\t\tsurface1: '#ddf8e1',\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: '#ddbe30',\n\t\t\tsurface2: '#fdf9e7',\n\t\t\tsurface6: '#ecd367',\n\t\t\tsurface5: '#f5e399',\n\t\t\tsurface4: '#f8ebb5',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#291d00',\n\t\t\tfgSurface3: '#876b00',\n\t\t\tfgSurface2: '#a78900',\n\t\t\tfgSurface1: '#c9aa00',\n\t\t\tstroke3: '#876b00',\n\t\t\tstroke4: '#675000',\n\t\t\tstroke2: '#978c60',\n\t\t\tstroke1: '#b8ab75',\n\t\t\tbgFillDark: '#1f1e1b',\n\t\t\tfgFillDark: '#f6f1da',\n\t\t\tbgFillInverted2: '#1f1e1b',\n\t\t\tbgFillInverted1: '#3a2b00',\n\t\t\tfgFillInverted: '#f6f1da',\n\t\t\tsurface1: '#faf1cd',\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: '#dea633',\n\t\t\tsurface2: '#fdf7ee',\n\t\t\tsurface6: '#f1ce90',\n\t\t\tsurface5: '#f6e0bb',\n\t\t\tsurface4: '#f8e9cd',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#2f1800',\n\t\t\tfgSurface3: '#976300',\n\t\t\tfgSurface2: '#b78100',\n\t\t\tfgSurface1: '#d9a22e',\n\t\t\tstroke3: '#976300',\n\t\t\tstroke4: '#754900',\n\t\t\tstroke2: '#9f8860',\n\t\t\tstroke1: '#c2a776',\n\t\t\tbgFillDark: '#1f1e1b',\n\t\t\tfgFillDark: '#f3f0e9',\n\t\t\tbgFillInverted2: '#1f1e1b',\n\t\t\tbgFillInverted1: '#432600',\n\t\t\tfgFillInverted: '#f3f0e9',\n\t\t\tsurface1: '#faefdc',\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: '#bc0001',\n\t\t\tsurface2: '#fdf6f5',\n\t\t\tsurface6: '#f5c9c2',\n\t\t\tsurface5: '#f9dcd8',\n\t\t\tsurface4: '#fae5e2',\n\t\t\tsurface3: '#fff',\n\t\t\tfgSurface4: '#4a0000',\n\t\t\tfgSurface3: '#cc1818',\n\t\t\tfgSurface2: '#f84d41',\n\t\t\tfgSurface1: '#ff8373',\n\t\t\tstroke3: '#cc1818',\n\t\t\tstroke4: '#a70000',\n\t\t\tstroke2: '#ca675c',\n\t\t\tstroke1: '#dc8e83',\n\t\t\tbgFillDark: '#231c1b',\n\t\t\tfgFillDark: '#f2efef',\n\t\t\tbgFillInverted2: '#231c1b',\n\t\t\tbgFillInverted1: '#680000',\n\t\t\tfgFillInverted: '#f2efef',\n\t\t\tsurface1: '#fcedea',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";AAMO,IAAM,gBAGT;AAAA,EACH,IAAI;AAAA,IACH,MAAM;AAAA,MACL,UAAU;AAAA,MACV,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,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,gBA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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,22 +1,23 @@
|
|
|
1
1
|
// packages/theme/src/color-ramps/lib/find-color-with-constraints.ts
|
|
2
2
|
import { get, OKLCH } from "colorjs.io/fn";
|
|
3
3
|
import "./register-color-spaces";
|
|
4
|
-
import { clampToGamut } from "./utils";
|
|
5
|
-
import {
|
|
6
|
-
WHITE,
|
|
7
|
-
BLACK,
|
|
8
|
-
LIGHTNESS_EPSILON,
|
|
9
|
-
MAX_BISECTION_ITERATIONS
|
|
10
|
-
} from "./constants";
|
|
4
|
+
import { clampToGamut, solveWithBisect } from "./utils";
|
|
5
|
+
import { WHITE, BLACK, CONTRAST_EPSILON } from "./constants";
|
|
11
6
|
import { getContrast } from "./color-utils";
|
|
12
7
|
import { taperChroma } from "./taper-chroma";
|
|
8
|
+
function cdiff(c1, c2) {
|
|
9
|
+
return Math.log(c1 / c2);
|
|
10
|
+
}
|
|
13
11
|
function findColorMeetingRequirements(reference, seed, target, direction, {
|
|
14
12
|
lightnessConstraint,
|
|
15
|
-
taperChromaOptions
|
|
16
|
-
strict = true
|
|
13
|
+
taperChromaOptions
|
|
17
14
|
} = {}) {
|
|
18
15
|
if (target <= 1) {
|
|
19
|
-
return {
|
|
16
|
+
return {
|
|
17
|
+
color: reference,
|
|
18
|
+
reached: true,
|
|
19
|
+
achieved: 1
|
|
20
|
+
};
|
|
20
21
|
}
|
|
21
22
|
function getColorForL(l) {
|
|
22
23
|
let newL = l;
|
|
@@ -35,71 +36,48 @@ function findColorMeetingRequirements(reference, seed, target, direction, {
|
|
|
35
36
|
coords: [newL, newC, get(seed, [OKLCH, "h"])]
|
|
36
37
|
});
|
|
37
38
|
}
|
|
39
|
+
const mostContrastingL = direction === "lighter" ? 1 : 0;
|
|
40
|
+
const mostContrastingColor = direction === "lighter" ? WHITE : BLACK;
|
|
41
|
+
const highestContrast = getContrast(reference, mostContrastingColor);
|
|
38
42
|
if (lightnessConstraint) {
|
|
39
43
|
const colorWithExactL = getColorForL(lightnessConstraint.value);
|
|
40
44
|
const exactLContrast = getContrast(reference, colorWithExactL);
|
|
41
|
-
|
|
45
|
+
const exactLContrastMeetsTarget = cdiff(exactLContrast, target) >= -CONTRAST_EPSILON;
|
|
46
|
+
if (exactLContrastMeetsTarget || lightnessConstraint.type === "force") {
|
|
42
47
|
return {
|
|
43
48
|
color: colorWithExactL,
|
|
44
|
-
reached:
|
|
45
|
-
achieved: exactLContrast
|
|
49
|
+
reached: exactLContrastMeetsTarget,
|
|
50
|
+
achieved: exactLContrast,
|
|
51
|
+
deficit: exactLContrastMeetsTarget ? cdiff(exactLContrast, highestContrast) : cdiff(target, exactLContrast)
|
|
46
52
|
};
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
const mostContrastingColor = direction === "lighter" ? WHITE : BLACK;
|
|
51
|
-
const highestContrast = getContrast(reference, mostContrastingColor);
|
|
52
|
-
if (highestContrast < target) {
|
|
53
|
-
if (strict) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Contrast target ${target.toFixed(
|
|
56
|
-
2
|
|
57
|
-
)}:1 unreachable in ${direction} direction(boundary achieves ${highestContrast.toFixed(3)}:1).`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
55
|
+
if (cdiff(highestContrast, target) <= CONTRAST_EPSILON) {
|
|
60
56
|
return {
|
|
61
57
|
color: mostContrastingColor,
|
|
62
|
-
reached:
|
|
63
|
-
achieved: highestContrast
|
|
58
|
+
reached: cdiff(highestContrast, target) >= -CONTRAST_EPSILON,
|
|
59
|
+
achieved: highestContrast,
|
|
60
|
+
deficit: cdiff(target, highestContrast)
|
|
64
61
|
};
|
|
65
62
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (Math.abs(bestContrast - target) <= LIGHTNESS_EPSILON) {
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
if (bestContrast >= target) {
|
|
82
|
-
betterL = newL;
|
|
83
|
-
betterContrast = bestContrast;
|
|
84
|
-
if (replacedBetter) {
|
|
85
|
-
worseContrast = (worseContrast + target) / 2;
|
|
86
|
-
}
|
|
87
|
-
replacedBetter = true;
|
|
88
|
-
replacedWorse = false;
|
|
89
|
-
} else {
|
|
90
|
-
worseL = newL;
|
|
91
|
-
worseContrast = bestContrast;
|
|
92
|
-
if (replacedWorse) {
|
|
93
|
-
betterContrast = (betterContrast + target) / 2;
|
|
94
|
-
}
|
|
95
|
-
replacedWorse = true;
|
|
96
|
-
replacedBetter = false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
63
|
+
const lowerL = get(reference, [OKLCH, "l"]);
|
|
64
|
+
const lowerContrast = cdiff(1, target);
|
|
65
|
+
const upperL = mostContrastingL;
|
|
66
|
+
const upperContrast = cdiff(highestContrast, target);
|
|
67
|
+
const bestColor = solveWithBisect(
|
|
68
|
+
getColorForL,
|
|
69
|
+
(c) => cdiff(getContrast(reference, c), target),
|
|
70
|
+
lowerL,
|
|
71
|
+
lowerContrast,
|
|
72
|
+
upperL,
|
|
73
|
+
upperContrast
|
|
74
|
+
);
|
|
99
75
|
return {
|
|
100
76
|
color: bestColor,
|
|
101
77
|
reached: true,
|
|
102
|
-
achieved:
|
|
78
|
+
achieved: target,
|
|
79
|
+
// Negative number that specifies how much room we have.
|
|
80
|
+
deficit: cdiff(target, highestContrast)
|
|
103
81
|
};
|
|
104
82
|
}
|
|
105
83
|
export {
|
|
@@ -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 ColorTypes } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport { clampToGamut } from './utils';\nimport {
|
|
5
|
-
"mappings": ";AAGA,SAAS,KAAK,aAA8B;AAK5C,OAAO;AACP,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { get, OKLCH, type ColorTypes } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport { clampToGamut, solveWithBisect } from './utils';\nimport { WHITE, BLACK, CONTRAST_EPSILON } from './constants';\nimport { 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 * - chroma could be tapered\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: ColorTypes,\n\tseed: ColorTypes,\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): { color: ColorTypes; reached: boolean; achieved: number; deficit?: number } {\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 ): ColorTypes {\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: ColorTypes ) => 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,aAA8B;AAK5C,OAAO;AACP,SAAS,cAAc,uBAAuB;AAC9C,SAAS,OAAO,OAAO,wBAAwB;AAC/C,SAAS,mBAAmB;AAC5B,SAA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