@wordpress/theme 0.3.1-next.8b30e05b0.0 → 0.4.1-next.8fd3f8831.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +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
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// packages/theme/src/color-ramps/index.ts
|
|
2
2
|
import { get, OKLCH, parse } from "colorjs.io/fn";
|
|
3
|
-
import "./lib/register-color-spaces";
|
|
4
|
-
import { buildRamp } from "./lib/index";
|
|
5
|
-
import { clampAccentScaleReferenceLightness } from "./lib/utils";
|
|
6
|
-
import { BG_RAMP_CONFIG, ACCENT_RAMP_CONFIG } from "./lib/ramp-configs";
|
|
7
|
-
import { getContrast } from "./lib/color-utils";
|
|
8
|
-
import { CONTRAST_COMBINATIONS } from "./lib/constants";
|
|
9
|
-
import { DEFAULT_SEED_COLORS } from "./lib/constants";
|
|
3
|
+
import "./lib/register-color-spaces.js";
|
|
4
|
+
import { buildRamp } from "./lib/index.js";
|
|
5
|
+
import { clampAccentScaleReferenceLightness } from "./lib/utils.js";
|
|
6
|
+
import { BG_RAMP_CONFIG, ACCENT_RAMP_CONFIG } from "./lib/ramp-configs.js";
|
|
7
|
+
import { getContrast } from "./lib/color-utils.js";
|
|
8
|
+
import { CONTRAST_COMBINATIONS } from "./lib/constants.js";
|
|
9
|
+
import { DEFAULT_SEED_COLORS } from "./lib/constants.js";
|
|
10
10
|
function buildBgRamp(seed) {
|
|
11
11
|
if (typeof seed !== "string" || seed.trim() === "") {
|
|
12
12
|
throw new Error("Seed color must be a non-empty string");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/theme/src/color-ramps/lib/constants.ts
|
|
2
2
|
import { to, OKLCH } from "colorjs.io/fn";
|
|
3
|
-
import "./register-color-spaces";
|
|
3
|
+
import "./register-color-spaces.js";
|
|
4
4
|
var WHITE = to("white", OKLCH);
|
|
5
5
|
var BLACK = to("black", OKLCH);
|
|
6
6
|
var UNIVERSAL_CONTRAST_TOPUP = 0.02;
|
|
@@ -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: '#231c1b',\n\t\t\tbgFillInverted1: '#640000',\n\t\t\tfgFillInverted: '#f2efef',\n\t\t\tsurface1: '#fcece9',\n\t\t},\n\t\tdirection: 'darker',\n\t},\n};\n"],
|
|
5
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;A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,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,10 +1,10 @@
|
|
|
1
1
|
// packages/theme/src/color-ramps/lib/find-color-with-constraints.ts
|
|
2
2
|
import { get, OKLCH } from "colorjs.io/fn";
|
|
3
|
-
import "./register-color-spaces";
|
|
4
|
-
import { solveWithBisect } from "./utils";
|
|
5
|
-
import { WHITE, BLACK, CONTRAST_EPSILON } from "./constants";
|
|
6
|
-
import { clampToGamut, getContrast } from "./color-utils";
|
|
7
|
-
import { taperChroma } from "./taper-chroma";
|
|
3
|
+
import "./register-color-spaces.js";
|
|
4
|
+
import { solveWithBisect } from "./utils.js";
|
|
5
|
+
import { WHITE, BLACK, CONTRAST_EPSILON } from "./constants.js";
|
|
6
|
+
import { clampToGamut, getContrast } from "./color-utils.js";
|
|
7
|
+
import { taperChroma } from "./taper-chroma.js";
|
|
8
8
|
function cdiff(c1, c2) {
|
|
9
9
|
return Math.log(c1 / c2);
|
|
10
10
|
}
|
|
@@ -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;AAC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,MAAO;AAErD,QAAM,YAAY;AAAA,IACjB;AAAA,IACA,CAAE,MAAO,MAAO,YAAa,WAAW,CAAE,GAAG,MAAO;AAAA,IACpD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,SAAO;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,UAAU;AAAA;AAAA,IAEV,SAAS,MAAO,QAAQ,eAAgB;AAAA,EACzC;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,17 +6,17 @@ import {
|
|
|
6
6
|
parse,
|
|
7
7
|
set
|
|
8
8
|
} from "colorjs.io/fn";
|
|
9
|
-
import "./register-color-spaces";
|
|
10
|
-
import { clampToGamut, getContrast, getColorString } from "./color-utils";
|
|
11
|
-
import { findColorMeetingRequirements } from "./find-color-with-constraints";
|
|
9
|
+
import "./register-color-spaces.js";
|
|
10
|
+
import { clampToGamut, getContrast, getColorString } from "./color-utils.js";
|
|
11
|
+
import { findColorMeetingRequirements } from "./find-color-with-constraints.js";
|
|
12
12
|
import {
|
|
13
13
|
sortByDependency,
|
|
14
14
|
computeBetterFgColorDirection,
|
|
15
15
|
adjustContrastTarget,
|
|
16
16
|
stepsForStep,
|
|
17
17
|
solveWithBisect
|
|
18
|
-
} from "./utils";
|
|
19
|
-
import { CONTRAST_EPSILON } from "./constants";
|
|
18
|
+
} from "./utils.js";
|
|
19
|
+
import { CONTRAST_EPSILON } from "./constants.js";
|
|
20
20
|
function calculateRamp({
|
|
21
21
|
seed,
|
|
22
22
|
sortedSteps,
|
|
@@ -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,sBA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,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
|
-
import "./register-color-spaces";
|
|
8
|
+
import "./register-color-spaces.js";
|
|
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
|