@litfamily/litclaude 1.0.52 → 1.0.53
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 +17 -0
- package/README.md +8 -8
- package/README_ko-KR.md +8 -8
- package/docs/assets/readme/badge-version.svg +1 -1
- package/docs/hooks.md +76 -9
- package/package.json +1 -1
- package/plugins/litclaude/.claude-plugin/plugin.json +7 -1
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/hooks/lit-mod.mjs +81 -6
- package/plugins/litclaude/hooks/make-colors.d.ts +35 -0
- package/plugins/litclaude/hooks/make-colors.js +1016 -0
- package/plugins/litclaude/lib/mod/backdrop.mjs +675 -0
- package/plugins/litclaude/lib/mod/settings.mjs +5 -2
- package/plugins/litclaude/lib/mod/skills.mjs +10 -0
- package/plugins/litclaude/lib/mod/svg-card.mjs +34 -13
|
@@ -0,0 +1,1016 @@
|
|
|
1
|
+
// make-colors.js: copy this file into your mod's hooks folder, and leave it as it is.
|
|
2
|
+
// Generated from the design system's theme code. Don't edit it.
|
|
3
|
+
// sources-sha256: c44e83e0e09808d3442f475a8b2ff715181338f4973f7b860009f0fe4b4093a8
|
|
4
|
+
// body-sha256: 9d71ea3fbc24f3fef16ac58e386315002d2e4763c27138821dcd756d38510d65
|
|
5
|
+
var THEME_GRAPH = {
|
|
6
|
+
border: "alpha-2",
|
|
7
|
+
"alpha-2": "@neutral-900/10",
|
|
8
|
+
"neutral-900": ["gray-900", "gray-0"],
|
|
9
|
+
"border-accent": ["role-accent-250", "role-accent-700"],
|
|
10
|
+
"border-danger": ["role-danger-250", "role-danger-700"],
|
|
11
|
+
"border-success": ["role-success-250", "role-success-700"],
|
|
12
|
+
"border-warning": ["role-warning-250", "role-warning-700"],
|
|
13
|
+
"border-pro": ["role-pro-250", "role-pro-700"],
|
|
14
|
+
"border-git-added": "color-mix(in srgb, {text-git-added} 40%, transparent)",
|
|
15
|
+
"border-git-removed": "color-mix(in srgb, {text-git-removed} 40%, transparent)",
|
|
16
|
+
"border-git-modified": "color-mix(in srgb, {text-git-modified} 40%, transparent)",
|
|
17
|
+
"border-git-merged": "color-mix(in srgb, {text-git-merged} 40%, transparent)",
|
|
18
|
+
"border-git-closed": "color-mix(in srgb, {text-git-closed} 40%, transparent)",
|
|
19
|
+
"border-git-conflicting": "color-mix(in srgb, {text-git-conflicting} 40%, transparent)",
|
|
20
|
+
"border-git-draft": "color-mix(in srgb, {text-git-draft} 40%, transparent)",
|
|
21
|
+
"border-strong": "alpha-3",
|
|
22
|
+
"alpha-3": "@neutral-900/20",
|
|
23
|
+
"border-stronger": "@neutral-900/40",
|
|
24
|
+
"shadow-sm": "0 1px 2px 0 {@gray-900/6}, 0 2px 8px 0 {shadow-color}",
|
|
25
|
+
"shadow-color": ["@gray-900/8", "'rgba(0, 0, 0, 0.24)"],
|
|
26
|
+
"shadow-md": "0 2px 4px 0 {@gray-900/7}, 0 6px 16px 0 {shadow-color}",
|
|
27
|
+
"shadow-lg": "0 4px 8px 0 {@gray-900/8}, 0 12px 28px -2px {shadow-color}",
|
|
28
|
+
"shadow-drop-ring": "inset 0 0 0 2px {fill-accent}",
|
|
29
|
+
"fill-accent": "role-accent-fill",
|
|
30
|
+
"shadow-drop-ring-danger": "inset 0 0 0 2px {fill-danger}",
|
|
31
|
+
"fill-danger": "role-danger-fill",
|
|
32
|
+
"shadow-drop-glow": "inset 0 0 24px -2px {@fill-accent/20}",
|
|
33
|
+
"shadow-drop-glow-danger": "inset 0 0 24px -2px {@fill-danger/20}",
|
|
34
|
+
"ring-color": ["border", "alpha-2"],
|
|
35
|
+
"focus-shadow": ["inset 0 0 0 1px {page-bg}, 0 0 0 1px {fill-accent}, 0 0 6px 1px {bg-accent}", "inset 0 0 0 1px {page-bg}, 0 0 0 1px {fill-accent}, 0 0 6px 1px {@role-accent-600/60}"],
|
|
36
|
+
"page-bg": "surface-0",
|
|
37
|
+
"surface-0": ["gray-20", "gray-900"],
|
|
38
|
+
"bg-accent": ["role-accent-100", "role-accent-800"],
|
|
39
|
+
"focus-shadow-danger": ["inset 0 0 0 1px {page-bg}, 0 0 0 1px {fill-danger}, 0 0 6px 1px {bg-danger}", "inset 0 0 0 1px {page-bg}, 0 0 0 1px {fill-danger}, 0 0 6px 1px {@role-danger-600/60}"],
|
|
40
|
+
"bg-danger": ["role-danger-100", "role-danger-800"],
|
|
41
|
+
"pictogram-highlight-default": ["gray-80", "gray-650"],
|
|
42
|
+
"neutral-0": ["gray-0", "gray-900"],
|
|
43
|
+
"neutral-10": ["gray-10", "gray-890"],
|
|
44
|
+
"neutral-20": ["gray-20", "gray-880"],
|
|
45
|
+
"neutral-30": ["gray-30", "gray-870"],
|
|
46
|
+
"neutral-40": ["gray-40", "gray-860"],
|
|
47
|
+
"neutral-50": ["gray-50", "gray-850"],
|
|
48
|
+
"neutral-60": ["gray-60", "gray-840"],
|
|
49
|
+
"neutral-70": ["gray-70", "gray-830"],
|
|
50
|
+
"neutral-80": ["gray-80", "gray-820"],
|
|
51
|
+
"neutral-90": ["gray-90", "gray-810"],
|
|
52
|
+
"neutral-100": ["gray-100", "gray-800"],
|
|
53
|
+
"neutral-150": ["gray-150", "gray-750"],
|
|
54
|
+
"neutral-200": ["gray-200", "gray-700"],
|
|
55
|
+
"neutral-250": ["gray-250", "gray-650"],
|
|
56
|
+
"neutral-300": ["gray-300", "gray-600"],
|
|
57
|
+
"neutral-350": ["gray-350", "gray-550"],
|
|
58
|
+
"neutral-400": ["gray-400", "gray-500"],
|
|
59
|
+
"neutral-450": "gray-450",
|
|
60
|
+
"neutral-500": ["gray-500", "gray-400"],
|
|
61
|
+
"neutral-550": ["gray-550", "gray-350"],
|
|
62
|
+
"neutral-600": ["gray-600", "gray-300"],
|
|
63
|
+
"neutral-650": ["gray-650", "gray-250"],
|
|
64
|
+
"neutral-700": ["gray-700", "gray-200"],
|
|
65
|
+
"neutral-750": ["gray-750", "gray-150"],
|
|
66
|
+
"neutral-800": ["gray-800", "gray-100"],
|
|
67
|
+
"neutral-810": ["gray-810", "gray-90"],
|
|
68
|
+
"neutral-820": ["gray-820", "gray-80"],
|
|
69
|
+
"neutral-830": ["gray-830", "gray-70"],
|
|
70
|
+
"neutral-840": ["gray-840", "gray-60"],
|
|
71
|
+
"neutral-850": ["gray-850", "gray-50"],
|
|
72
|
+
"neutral-860": ["gray-860", "gray-40"],
|
|
73
|
+
"neutral-870": ["gray-870", "gray-30"],
|
|
74
|
+
"neutral-880": ["gray-880", "gray-20"],
|
|
75
|
+
"neutral-890": ["gray-890", "gray-10"],
|
|
76
|
+
"alpha-0": "@neutral-900/0",
|
|
77
|
+
"alpha-1": "@neutral-900/5",
|
|
78
|
+
"alpha-4": "@neutral-900/35",
|
|
79
|
+
"alpha-5": "@neutral-900/50",
|
|
80
|
+
"alpha-6": "@neutral-900/60",
|
|
81
|
+
"alpha-7": "@neutral-900/70",
|
|
82
|
+
"alpha-8": "@neutral-900/85",
|
|
83
|
+
"alpha-9": "@neutral-900/95",
|
|
84
|
+
"surface-1": ["gray-10", "gray-850"],
|
|
85
|
+
"surface-2": ["gray-0", "gray-830"],
|
|
86
|
+
"surface-3": ["gray-0", "gray-800"],
|
|
87
|
+
"surface-popover": "surface-3",
|
|
88
|
+
"surface-panel": "surface-2",
|
|
89
|
+
"fill-accent-hover": "role-accent-fill-hover",
|
|
90
|
+
"fill-danger-hover": "role-danger-fill-hover",
|
|
91
|
+
"fill-success": "role-success-fill",
|
|
92
|
+
"fill-success-hover": "role-success-fill-hover",
|
|
93
|
+
"fill-warning": "role-warning-fill",
|
|
94
|
+
"fill-warning-hover": "role-warning-fill-hover",
|
|
95
|
+
"fill-pro": "role-pro-fill",
|
|
96
|
+
"fill-pro-hover": "role-pro-fill-hover",
|
|
97
|
+
"fill-git-removed": "text-git-removed",
|
|
98
|
+
"fill-primary": "neutral-900",
|
|
99
|
+
"fill-primary-hover": ["neutral-750", "gray-100"],
|
|
100
|
+
"fill-secondary": ["'hsl(0 0% 100% / 0.1)", "alpha-2"],
|
|
101
|
+
"fill-secondary-hover": ["alpha-1", "@neutral-900/14"],
|
|
102
|
+
"fill-secondary-ring": ["border", "'transparent"],
|
|
103
|
+
"fill-secondary-pressed-ring": "border",
|
|
104
|
+
"fill-field": ["'hsl(0 0% 100% / 0.5)", "alpha-1"],
|
|
105
|
+
"fill-field-ring": "border",
|
|
106
|
+
"fill-ghost-hover": ["alpha-1", "@neutral-900/7.5"],
|
|
107
|
+
"fill-ghost-selected": ["alpha-2", "@neutral-900/15"],
|
|
108
|
+
"fill-disabled": "alpha-1",
|
|
109
|
+
"fill-control": "alpha-2",
|
|
110
|
+
"fill-control-hover": "alpha-3",
|
|
111
|
+
"bg-accent-muted": "color-mix(in srgb, {fill-accent} 10%, transparent)",
|
|
112
|
+
"bg-success": ["role-success-100", "role-success-800"],
|
|
113
|
+
"bg-warning": ["role-warning-100", "role-warning-800"],
|
|
114
|
+
"bg-pro": ["role-pro-100", "role-pro-800"],
|
|
115
|
+
"bg-git-added": "color-mix(in srgb, {text-git-added} 20%, transparent)",
|
|
116
|
+
"bg-git-removed": "color-mix(in srgb, {text-git-removed} 20%, transparent)",
|
|
117
|
+
"bg-git-modified": "color-mix(in srgb, {text-git-modified} 20%, transparent)",
|
|
118
|
+
"bg-git-merged": "color-mix(in srgb, {text-git-merged} 20%, transparent)",
|
|
119
|
+
"bg-git-closed": "color-mix(in srgb, {text-git-closed} 20%, transparent)",
|
|
120
|
+
"bg-git-conflicting": "color-mix(in srgb, {text-git-conflicting} 20%, transparent)",
|
|
121
|
+
"bg-git-draft": "color-mix(in srgb, {text-git-draft} 20%, transparent)",
|
|
122
|
+
"bg-highlight": "color-mix(in srgb, {fill-warning} 33%, transparent)",
|
|
123
|
+
"bg-editor-canvas": "neutral-60",
|
|
124
|
+
"bg-editor-highlight-yellow": "bg-highlight",
|
|
125
|
+
"bg-editor-highlight-gray": "color-mix(in srgb, {gray-300} 33%, transparent)",
|
|
126
|
+
"bg-editor-collaborator-6": "color-mix(in srgb, {editor-collaborator-6} 22%, transparent)",
|
|
127
|
+
"editor-collaborator-6": "gray-500",
|
|
128
|
+
"bg-editor-comment": "color-mix(in srgb, {fill-warning} 20%, transparent)",
|
|
129
|
+
"bg-editor-comment-active": "color-mix(in srgb, {fill-warning} 45%, transparent)",
|
|
130
|
+
"bg-neutral": "alpha-1",
|
|
131
|
+
"bg-neutral-hover": "alpha-2",
|
|
132
|
+
"bg-user-message": "bg-neutral",
|
|
133
|
+
"text-accent": ["role-accent-600", "role-accent-300"],
|
|
134
|
+
"text-danger": ["role-danger-600", "role-danger-300"],
|
|
135
|
+
"text-success": ["role-success-600", "role-success-400"],
|
|
136
|
+
"text-warning": ["role-warning-600", "role-warning-300"],
|
|
137
|
+
"text-pro": ["role-pro-600", "role-pro-300"],
|
|
138
|
+
"text-primary": ["neutral-900", "gray-50"],
|
|
139
|
+
"text-secondary": ["neutral-600", "gray-200"],
|
|
140
|
+
"text-muted": ["neutral-400", "gray-400"],
|
|
141
|
+
"text-disabled": "alpha-4",
|
|
142
|
+
"on-primary": "neutral-0",
|
|
143
|
+
"on-accent": "role-accent-on",
|
|
144
|
+
"on-danger": "role-danger-on",
|
|
145
|
+
"on-success": "role-success-on",
|
|
146
|
+
"on-warning": "role-warning-on",
|
|
147
|
+
"on-pro": "role-pro-on",
|
|
148
|
+
"chart-diverging-4": ["gray-50", "gray-700"],
|
|
149
|
+
"chart-muted": ["gray-200", "gray-550"],
|
|
150
|
+
"chart-reference": ["gray-400", "gray-350"],
|
|
151
|
+
"chart-reference-tint": ["@gray-400/15", "@gray-350/15"],
|
|
152
|
+
"chart-grid": "alpha-2",
|
|
153
|
+
"chart-axis": ["gray-200", "gray-700"],
|
|
154
|
+
"chart-baseline": ["gray-200", "gray-700"]
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
var THEME_PAIRS = [
|
|
158
|
+
["border", "surface-0", "UI"],
|
|
159
|
+
["border", "surface-1", "UI"],
|
|
160
|
+
["border", "surface-2", "UI"],
|
|
161
|
+
["border", "surface-3", "UI"],
|
|
162
|
+
["border-accent", "bg-accent", "UI"],
|
|
163
|
+
["border-danger", "bg-danger", "UI"],
|
|
164
|
+
["border-success", "bg-success", "UI"],
|
|
165
|
+
["border-warning", "bg-warning", "UI"],
|
|
166
|
+
["border-pro", "bg-pro", "UI"],
|
|
167
|
+
["border-strong", "surface-0", "UI"],
|
|
168
|
+
["border-strong", "surface-1", "UI"],
|
|
169
|
+
["border-strong", "surface-2", "UI"],
|
|
170
|
+
["border-strong", "surface-3", "UI"],
|
|
171
|
+
["border-stronger", "surface-0", "UI"],
|
|
172
|
+
["border-stronger", "surface-1", "UI"],
|
|
173
|
+
["border-stronger", "surface-2", "UI"],
|
|
174
|
+
["border-stronger", "surface-3", "UI"],
|
|
175
|
+
["ring-color", "surface-0", "UI"],
|
|
176
|
+
["ring-color", "surface-1", "UI"],
|
|
177
|
+
["ring-color", "surface-2", "UI"],
|
|
178
|
+
["ring-color", "surface-3", "UI"],
|
|
179
|
+
["fill-accent", "surface-0", "UI"],
|
|
180
|
+
["fill-accent", "surface-1", "UI"],
|
|
181
|
+
["fill-accent", "surface-2", "UI"],
|
|
182
|
+
["fill-accent", "surface-3", "UI"],
|
|
183
|
+
["fill-danger", "surface-0", "UI"],
|
|
184
|
+
["fill-danger", "surface-1", "UI"],
|
|
185
|
+
["fill-danger", "surface-2", "UI"],
|
|
186
|
+
["fill-danger", "surface-3", "UI"],
|
|
187
|
+
["fill-success", "surface-0", "UI"],
|
|
188
|
+
["fill-success", "surface-1", "UI"],
|
|
189
|
+
["fill-success", "surface-2", "UI"],
|
|
190
|
+
["fill-success", "surface-3", "UI"],
|
|
191
|
+
["fill-warning", "surface-0", "UI"],
|
|
192
|
+
["fill-warning", "surface-1", "UI"],
|
|
193
|
+
["fill-warning", "surface-2", "UI"],
|
|
194
|
+
["fill-warning", "surface-3", "UI"],
|
|
195
|
+
["fill-pro", "surface-0", "UI"],
|
|
196
|
+
["fill-pro", "surface-1", "UI"],
|
|
197
|
+
["fill-pro", "surface-2", "UI"],
|
|
198
|
+
["fill-pro", "surface-3", "UI"],
|
|
199
|
+
["fill-primary", "surface-0", "UI"],
|
|
200
|
+
["fill-primary", "surface-1", "UI"],
|
|
201
|
+
["fill-primary", "surface-2", "UI"],
|
|
202
|
+
["fill-primary", "surface-3", "UI"],
|
|
203
|
+
["fill-secondary-ring", "surface-0", "UI"],
|
|
204
|
+
["fill-secondary-ring", "surface-1", "UI"],
|
|
205
|
+
["fill-secondary-ring", "surface-2", "UI"],
|
|
206
|
+
["fill-secondary-ring", "surface-3", "UI"],
|
|
207
|
+
["fill-secondary-pressed-ring", "surface-0", "UI"],
|
|
208
|
+
["fill-secondary-pressed-ring", "surface-1", "UI"],
|
|
209
|
+
["fill-secondary-pressed-ring", "surface-2", "UI"],
|
|
210
|
+
["fill-secondary-pressed-ring", "surface-3", "UI"],
|
|
211
|
+
["fill-field-ring", "surface-0", "UI"],
|
|
212
|
+
["fill-field-ring", "surface-1", "UI"],
|
|
213
|
+
["fill-field-ring", "surface-2", "UI"],
|
|
214
|
+
["fill-field-ring", "surface-3", "UI"],
|
|
215
|
+
["text-accent", "surface-0", "AA"],
|
|
216
|
+
["text-accent", "surface-1", "AA"],
|
|
217
|
+
["text-accent", "surface-2", "AA"],
|
|
218
|
+
["text-accent", "surface-3", "AA"],
|
|
219
|
+
["text-accent", "bg-accent", "AA"],
|
|
220
|
+
["text-accent", "bg-tint-blue=rgba(118, 178, 251, 0.35)|rgba(0, 36, 81, 0.75)", "AA"],
|
|
221
|
+
["text-accent", "tooltip-bg", "AA", 0, 1],
|
|
222
|
+
["text-danger", "surface-0", "AA"],
|
|
223
|
+
["text-danger", "surface-1", "AA"],
|
|
224
|
+
["text-danger", "surface-2", "AA"],
|
|
225
|
+
["text-danger", "surface-3", "AA"],
|
|
226
|
+
["text-danger", "bg-danger", "AA"],
|
|
227
|
+
["text-danger", "bg-tint-red=rgba(246, 143, 145, 0.35)|rgba(73, 12, 12, 0.75)", "AA"],
|
|
228
|
+
["text-danger", "bg-user-message-personal=rgba(118, 178, 251, 0.35)|rgba(0, 36, 81, 0.75)", "AA"],
|
|
229
|
+
["text-success", "surface-0", "AA"],
|
|
230
|
+
["text-success", "surface-1", "AA"],
|
|
231
|
+
["text-success", "surface-2", "AA"],
|
|
232
|
+
["text-success", "surface-3", "AA"],
|
|
233
|
+
["text-success", "bg-success", "AA"],
|
|
234
|
+
["text-warning", "surface-0", "AA"],
|
|
235
|
+
["text-warning", "surface-1", "AA"],
|
|
236
|
+
["text-warning", "surface-2", "AA"],
|
|
237
|
+
["text-warning", "surface-3", "AA"],
|
|
238
|
+
["text-warning", "bg-warning", "AA"],
|
|
239
|
+
["text-warning", "bg-tint-yellow=rgba(243, 161, 2, 0.35)|rgba(58, 28, 0, 0.75)", "AA"],
|
|
240
|
+
["text-pro", "surface-0", "AA"],
|
|
241
|
+
["text-pro", "surface-1", "AA"],
|
|
242
|
+
["text-pro", "surface-2", "AA"],
|
|
243
|
+
["text-pro", "surface-3", "AA"],
|
|
244
|
+
["text-pro", "bg-pro", "AA"],
|
|
245
|
+
["text-pro", "bg-tint-violet=rgba(169, 158, 255, 0.35)|rgba(32, 22, 90, 0.75)", "AA"],
|
|
246
|
+
["text-tint-red=#8e2626|#ec7e7e", "bg-tint-red=rgba(246, 143, 145, 0.35)|rgba(73, 12, 12, 0.75)", "AA"],
|
|
247
|
+
["text-tint-orange=#863311|#ec835a", "bg-tint-orange=rgba(238, 149, 114, 0.35)|rgba(66, 20, 2, 0.75)", "AA"],
|
|
248
|
+
["text-tint-yellow=#734500|#db9300", "bg-tint-yellow=rgba(243, 161, 2, 0.35)|rgba(58, 28, 0, 0.75)", "AA"],
|
|
249
|
+
["text-tint-green=#006300|#55bf50", "bg-tint-green=rgba(109, 201, 102, 0.35)|rgba(16, 44, 13, 0.75)", "AA"],
|
|
250
|
+
["text-tint-aqua=#065f49|#3bbd8c", "bg-tint-aqua=rgba(78, 203, 160, 0.35)|rgba(0, 45, 36, 0.75)", "AA"],
|
|
251
|
+
["text-tint-blue=#184f95|#6da7ec", "bg-tint-blue=rgba(118, 178, 251, 0.35)|rgba(0, 36, 81, 0.75)", "AA"],
|
|
252
|
+
["text-tint-violet=#4a3aa7|#a096eb", "bg-tint-violet=rgba(169, 158, 255, 0.35)|rgba(32, 22, 90, 0.75)", "AA"],
|
|
253
|
+
["text-tint-magenta=#862a4c|#e87ba4", "bg-tint-magenta=rgba(243, 138, 180, 0.35)|rgba(69, 13, 34, 0.75)", "AA"],
|
|
254
|
+
["text-user-message-personal=#184f95|#6da7ec", "bg-user-message-personal=rgba(118, 178, 251, 0.35)|rgba(0, 36, 81, 0.75)", "AA"],
|
|
255
|
+
["text-git-added", "surface-1", "AA"],
|
|
256
|
+
["text-git-added", "bg-git-added", "AA"],
|
|
257
|
+
["text-git-removed", "surface-1", "AA"],
|
|
258
|
+
["text-git-removed", "bg-git-removed", "AA"],
|
|
259
|
+
["text-git-modified", "surface-1", "AA"],
|
|
260
|
+
["text-git-modified", "bg-git-modified", "AA"],
|
|
261
|
+
["text-git-merged", "surface-1", "AA"],
|
|
262
|
+
["text-git-merged", "bg-git-merged", "AA"],
|
|
263
|
+
["text-git-closed", "surface-1", "AA"],
|
|
264
|
+
["text-git-closed", "bg-git-closed", "AA"],
|
|
265
|
+
["text-git-conflicting", "surface-1", "AA"],
|
|
266
|
+
["text-git-conflicting", "bg-git-conflicting", "AA"],
|
|
267
|
+
["text-git-draft", "surface-1", "AA"],
|
|
268
|
+
["text-git-draft", "bg-git-draft", "AA"],
|
|
269
|
+
["text-primary", "surface-0", "AA"],
|
|
270
|
+
["text-primary", "surface-1", "AA"],
|
|
271
|
+
["text-primary", "surface-2", "AA"],
|
|
272
|
+
["text-primary", "surface-3", "AA"],
|
|
273
|
+
["text-primary", "fill-secondary", "AA"],
|
|
274
|
+
["text-primary", "fill-secondary-hover", "AA"],
|
|
275
|
+
["text-primary", "fill-ghost-hover", "AA"],
|
|
276
|
+
["text-primary", "fill-ghost-selected", "AA"],
|
|
277
|
+
["text-primary", "fill-control", "AA"],
|
|
278
|
+
["text-primary", "fill-field", "AA"],
|
|
279
|
+
["text-primary", "bg-neutral", "AA"],
|
|
280
|
+
["text-primary", "bg-neutral-hover", "AA"],
|
|
281
|
+
["text-primary", "bg-user-message", "AA"],
|
|
282
|
+
["text-primary", "bg-user-message-personal=rgba(118, 178, 251, 0.35)|rgba(0, 36, 81, 0.75)", "AA"],
|
|
283
|
+
["text-primary", "bg-highlight", "AA"],
|
|
284
|
+
["text-primary", "bg-editor-comment", "AA"],
|
|
285
|
+
["text-primary", "bg-editor-comment-active", "AA"],
|
|
286
|
+
["text-primary", "bg-accent-muted", "AA"],
|
|
287
|
+
["text-primary", "bg-editor-claude-pending=color-mix(in srgb, #d97757 22%, transparent)", "AA"],
|
|
288
|
+
["text-primary", "bg-editor-highlight-yellow", "AA"],
|
|
289
|
+
["text-primary", "bg-editor-highlight-green=color-mix(in srgb, #55bf50 33%, transparent)", "AA"],
|
|
290
|
+
["text-primary", "bg-editor-highlight-blue=color-mix(in srgb, #6da7ec 33%, transparent)", "AA"],
|
|
291
|
+
["text-primary", "bg-editor-highlight-magenta=color-mix(in srgb, #e87ba4 33%, transparent)", "AA"],
|
|
292
|
+
["text-primary", "bg-editor-highlight-violet=color-mix(in srgb, #a096eb 33%, transparent)", "AA"],
|
|
293
|
+
["text-primary", "bg-editor-highlight-gray", "AA"],
|
|
294
|
+
["text-primary", "segmented-control-track", "AA"],
|
|
295
|
+
["text-primary", "segmented-control-thumb", "AA"],
|
|
296
|
+
["text-primary", "radio-group-card-selected", "AA"],
|
|
297
|
+
["text-primary", "tooltip-bg", "AA", 0, 1],
|
|
298
|
+
["text-secondary", "surface-0", "AA"],
|
|
299
|
+
["text-secondary", "surface-1", "AA"],
|
|
300
|
+
["text-secondary", "surface-2", "AA"],
|
|
301
|
+
["text-secondary", "surface-3", "AA"],
|
|
302
|
+
["text-secondary", "fill-secondary", "AA"],
|
|
303
|
+
["text-secondary", "fill-ghost-hover", "AA"],
|
|
304
|
+
["text-secondary", "fill-control", "AA"],
|
|
305
|
+
["text-secondary", "bg-neutral", "AA"],
|
|
306
|
+
["text-secondary", "bg-danger", "AA"],
|
|
307
|
+
["text-secondary", "bg-warning", "AA"],
|
|
308
|
+
["text-secondary", "segmented-control-track", "AA"],
|
|
309
|
+
["text-secondary", "radio-group-card-selected", "AA"],
|
|
310
|
+
["text-secondary", "tooltip-bg", "AA", 0, 1],
|
|
311
|
+
["text-muted", "surface-0", "AA"],
|
|
312
|
+
["text-muted", "surface-1", "AA"],
|
|
313
|
+
["text-muted", "surface-2", "AA"],
|
|
314
|
+
["text-muted", "surface-3", "AA"],
|
|
315
|
+
["text-muted", "fill-field", "AA"],
|
|
316
|
+
["text-muted", "fill-ghost-hover", "AA"],
|
|
317
|
+
["text-muted", "fill-secondary", "AA"],
|
|
318
|
+
["text-muted", "bg-neutral", "AA"],
|
|
319
|
+
["text-muted", "segmented-control-track", "AA"],
|
|
320
|
+
["text-muted", "tooltip-bg", "AA", 0, 1],
|
|
321
|
+
["on-primary", "fill-primary", "AA"],
|
|
322
|
+
["on-primary", "fill-primary-hover", "AA"],
|
|
323
|
+
["on-accent", "fill-accent", "AA"],
|
|
324
|
+
["on-accent", "fill-accent-hover", "AA"],
|
|
325
|
+
["on-danger", "fill-danger", "AA"],
|
|
326
|
+
["on-danger", "fill-danger-hover", "AA"],
|
|
327
|
+
["on-success", "fill-success", "AA"],
|
|
328
|
+
["on-success", "fill-success-hover", "AA"],
|
|
329
|
+
["on-warning", "fill-warning", "AA"],
|
|
330
|
+
["on-warning", "fill-warning-hover", "AA"],
|
|
331
|
+
["on-pro", "fill-pro", "AA"],
|
|
332
|
+
["on-pro", "fill-pro-hover", "AA"],
|
|
333
|
+
["shortcut-cap-ink", "surface-0", "AA"],
|
|
334
|
+
["shortcut-cap-ink", "surface-1", "AA"],
|
|
335
|
+
["shortcut-cap-ink", "surface-2", "AA"],
|
|
336
|
+
["shortcut-cap-ink", "surface-3", "AA"],
|
|
337
|
+
["shortcut-cap-ink", "fill-secondary", "AA"],
|
|
338
|
+
["shortcut-cap-ink", "fill-ghost-hover", "AA"],
|
|
339
|
+
["slider-track", "surface-0", "UI"],
|
|
340
|
+
["slider-track", "surface-1", "UI"],
|
|
341
|
+
["slider-track", "surface-2", "UI"],
|
|
342
|
+
["slider-track", "surface-3", "UI"],
|
|
343
|
+
["slider-handle", "slider-fill", "UI"],
|
|
344
|
+
["switch-knob", "fill-accent", "UI"],
|
|
345
|
+
["switch-knob", "fill-accent-hover", "UI"],
|
|
346
|
+
["switch-knob", "switch-track", "UI"],
|
|
347
|
+
["switch-knob", "switch-track-hover", "UI"],
|
|
348
|
+
["switch-track", "surface-0", "UI"],
|
|
349
|
+
["switch-track", "surface-1", "UI"],
|
|
350
|
+
["switch-track", "surface-2", "UI"],
|
|
351
|
+
["switch-track", "surface-3", "UI"],
|
|
352
|
+
["switch-track-hover", "surface-0", "UI"],
|
|
353
|
+
["switch-track-hover", "surface-1", "UI"],
|
|
354
|
+
["switch-track-hover", "surface-2", "UI"],
|
|
355
|
+
["switch-track-hover", "surface-3", "UI"],
|
|
356
|
+
["tooltip-fg", "tooltip-bg", "AA"]
|
|
357
|
+
], THEME_PAIR_FORMS = {
|
|
358
|
+
"tooltip-bg": ["role-tooltip-bg", "surface-3"],
|
|
359
|
+
"segmented-control-track": "alpha-1",
|
|
360
|
+
"segmented-control-thumb": ["surface-popover", "alpha-2"],
|
|
361
|
+
"radio-group-card-selected": ["role-accent-50", "role-accent-850"],
|
|
362
|
+
"shortcut-cap-ink": ["gray-500", "gray-300"],
|
|
363
|
+
"slider-track": "alpha-2",
|
|
364
|
+
"slider-handle": "gray-0",
|
|
365
|
+
"slider-fill": ["alpha-3", "alpha-4"],
|
|
366
|
+
"switch-knob": "gray-0",
|
|
367
|
+
"switch-track": ["alpha-3", "alpha-2"],
|
|
368
|
+
"switch-track-hover": ["alpha-4", "alpha-3"],
|
|
369
|
+
"tooltip-fg": ["role-tooltip-fg", "text-primary"]
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
var toLinear = (c) => c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4, toGamma = (c) => c <= 0.0031308 ? 12.92 * c : 1.055 * c ** 0.4166666666666667 - 0.055;
|
|
373
|
+
function hexToRgb(hex) {
|
|
374
|
+
let n = parseInt(hex.slice(1), 16);
|
|
375
|
+
return [(n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255];
|
|
376
|
+
}
|
|
377
|
+
function rgbToHex(rgb) {
|
|
378
|
+
return "#" + rgb.map((c) => Math.round(Math.min(1, Math.max(0, c)) * 255).toString(16).padStart(2, "0")).join("");
|
|
379
|
+
}
|
|
380
|
+
function hexToLab(hex) {
|
|
381
|
+
let [r, g, b] = hexToRgb(hex), [R, G, B] = [toLinear(r), toLinear(g), toLinear(b)], l = Math.cbrt(0.4122214708 * R + 0.5363325363 * G + 0.0514459929 * B), m = Math.cbrt(0.2119034982 * R + 0.6806995451 * G + 0.1073969566 * B), s = Math.cbrt(0.0883024619 * R + 0.2817188376 * G + 0.6299787005 * B);
|
|
382
|
+
return [
|
|
383
|
+
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
384
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
385
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
|
|
386
|
+
];
|
|
387
|
+
}
|
|
388
|
+
function labToLinear([L, a, b]) {
|
|
389
|
+
let l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3, m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3, s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
390
|
+
return [
|
|
391
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
392
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
393
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
|
|
394
|
+
];
|
|
395
|
+
}
|
|
396
|
+
function hexToLch(hex) {
|
|
397
|
+
let [L, a, b] = hexToLab(hex);
|
|
398
|
+
return [L, Math.hypot(a, b), Math.atan2(b, a)];
|
|
399
|
+
}
|
|
400
|
+
var inGamut = (rgb) => rgb.every((c) => c >= -0.0001 && c <= 1.0001);
|
|
401
|
+
function lchToHex(lightness, chroma, hue) {
|
|
402
|
+
let L = Math.min(1, Math.max(0, lightness)), at = (c) => labToLinear([L, c * Math.cos(hue), c * Math.sin(hue)]), c = chroma;
|
|
403
|
+
if (!inGamut(at(c))) {
|
|
404
|
+
let lo = 0, hi = c;
|
|
405
|
+
for (let i = 0;i < 24; i++) {
|
|
406
|
+
let mid = (lo + hi) / 2;
|
|
407
|
+
if (inGamut(at(mid)))
|
|
408
|
+
lo = mid;
|
|
409
|
+
else
|
|
410
|
+
hi = mid;
|
|
411
|
+
}
|
|
412
|
+
c = lo;
|
|
413
|
+
}
|
|
414
|
+
let [r, g, b] = at(c);
|
|
415
|
+
return rgbToHex([toGamma(r), toGamma(g), toGamma(b)]);
|
|
416
|
+
}
|
|
417
|
+
function labToHex([L, a, b]) {
|
|
418
|
+
return lchToHex(L, Math.hypot(a, b), Math.atan2(b, a));
|
|
419
|
+
}
|
|
420
|
+
function mixLab(x, y, t) {
|
|
421
|
+
return [
|
|
422
|
+
x[0] + (y[0] - x[0]) * t,
|
|
423
|
+
x[1] + (y[1] - x[1]) * t,
|
|
424
|
+
x[2] + (y[2] - x[2]) * t
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
function relativeLuminance(r, g, b) {
|
|
428
|
+
let channel = (s) => s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
429
|
+
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
|
|
430
|
+
}
|
|
431
|
+
function contrastRatio(a, b) {
|
|
432
|
+
let la = relativeLuminance(...hexToRgb(a)), lb = relativeLuminance(...hexToRgb(b));
|
|
433
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
var TARGET_RATIO = {
|
|
437
|
+
AA: 4.5,
|
|
438
|
+
UI: 3,
|
|
439
|
+
AAA: 7
|
|
440
|
+
}, PLANES = [
|
|
441
|
+
"surface-0",
|
|
442
|
+
"surface-1",
|
|
443
|
+
"surface-2",
|
|
444
|
+
"surface-3"
|
|
445
|
+
], alphaOf = (s) => s === void 0 ? 1 : s.endsWith("%") ? parseFloat(s) / 100 : Number(s);
|
|
446
|
+
function readColor(literal) {
|
|
447
|
+
let v = literal.trim(), m;
|
|
448
|
+
if (m = v.match(/^#([0-9a-f]{6})$/i)) {
|
|
449
|
+
let n = parseInt(m[1] ?? "", 16);
|
|
450
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255, 1];
|
|
451
|
+
}
|
|
452
|
+
if (v === "transparent")
|
|
453
|
+
return [0, 0, 0, 0];
|
|
454
|
+
if (m = v.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/))
|
|
455
|
+
return [Number(m[1]), Number(m[2]), Number(m[3]), alphaOf(m[4])];
|
|
456
|
+
if (m = v.match(/^hsl\(\s*0\s+0%\s+([\d.]+)%\s*\/\s*([\d.]+%?)\s*\)$/)) {
|
|
457
|
+
let c = Math.round(Number(m[1]) * 2.55);
|
|
458
|
+
return [c, c, c, alphaOf(m[2])];
|
|
459
|
+
}
|
|
460
|
+
if (m = v.match(/^color-mix\(in srgb,\s*(#[0-9a-f]{6})\s+([\d.]+)%,\s*transparent\)$/i)) {
|
|
461
|
+
let c = readColor(m[1] ?? "");
|
|
462
|
+
return c && [c[0], c[1], c[2], Number(m[2]) / 100];
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
var over = (top, under) => [
|
|
467
|
+
top[0] * top[3] + under[0] * (1 - top[3]),
|
|
468
|
+
top[1] * top[3] + under[1] * (1 - top[3]),
|
|
469
|
+
top[2] * top[3] + under[2] * (1 - top[3]),
|
|
470
|
+
1
|
|
471
|
+
];
|
|
472
|
+
function contrastRatio2(a, b) {
|
|
473
|
+
let la = relativeLuminance(a[0] / 255, a[1] / 255, a[2] / 255), lb = relativeLuminance(b[0] / 255, b[1] / 255, b[2] / 255);
|
|
474
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
475
|
+
}
|
|
476
|
+
var hex = (c) => "#" + [c[0], c[1], c[2]].map((x) => Math.round(x).toString(16).padStart(2, "0")).join(""), planesOf = (pairing, againstIsOpaque) => pairing.over !== void 0 ? [pairing.over] : againstIsOpaque ? [pairing.against] : PLANES;
|
|
477
|
+
function evaluatePairing(colorOf, pairing, mode) {
|
|
478
|
+
let { token, against } = pairing, ink = colorOf(token, pairing.darkScope ? "dark" : mode), ground = colorOf(against, mode), results = planesOf(pairing, ground[3] === 1).map((plane) => {
|
|
479
|
+
let under = colorOf(plane, mode);
|
|
480
|
+
if (under[3] !== 1)
|
|
481
|
+
throw Error(plane === pairing.over ? `${token}, pair against "${against}": "${plane}" is see-through in ${mode} mode, so the check does not know what is under it. Name an opaque token in \`over\`.` : `${plane} is see-through in ${mode} mode, so a see-through color laid over it (${token} on ${against}) cannot be checked. Make ${plane} opaque, or name an opaque token in the pair's \`over\`.`);
|
|
482
|
+
let background = over(ground, under), foreground = over(ink, background);
|
|
483
|
+
return {
|
|
484
|
+
ratio: contrastRatio2(foreground, background),
|
|
485
|
+
over: plane,
|
|
486
|
+
painted: { token: hex(foreground), against: hex(background) }
|
|
487
|
+
};
|
|
488
|
+
});
|
|
489
|
+
if (results.some((r) => !Number.isFinite(r.ratio)))
|
|
490
|
+
throw Error(`${token} on ${against} (${mode} mode): the ratio is not a number. One of the colors involved, or the plane under them, has a number the contrast check could not read; check how each is written.`);
|
|
491
|
+
return results.reduce((low, r) => r.ratio < low.ratio ? r : low);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
var oneDecimalDown = (x) => Math.floor(x * 10) / 10;
|
|
495
|
+
function checkThemeWith(rows, themed, unthemed) {
|
|
496
|
+
let nameOf = (written) => written.split("=")[0] ?? written, reader = (literals) => (written, mode) => {
|
|
497
|
+
let [name = written, fixed] = written.split("="), [light = "", dark] = (fixed ?? "").split("|"), value = fixed === void 0 ? literals(name, mode) : mode === "dark" ? dark ?? light : light, color = value === void 0 ? void 0 : readColor(value);
|
|
498
|
+
if (color === void 0)
|
|
499
|
+
throw Error(value === void 0 ? `The contrast table names "${name}", which is neither a token a theme moves nor a fixed color. This is a bug in make-colors.js.` : `${name} resolves to ${JSON.stringify(value)} in ${mode} mode, which the contrast check cannot read as a color.`);
|
|
500
|
+
return color;
|
|
501
|
+
}, issues = [];
|
|
502
|
+
for (let [token, against, target, over, darkScope] of rows) {
|
|
503
|
+
let pairing = {
|
|
504
|
+
token,
|
|
505
|
+
against,
|
|
506
|
+
target,
|
|
507
|
+
...typeof over === "string" ? { over } : {},
|
|
508
|
+
...darkScope === 1 ? { darkScope: !0 } : {}
|
|
509
|
+
};
|
|
510
|
+
for (let mode of ["light", "dark"]) {
|
|
511
|
+
let stock = evaluatePairing(reader(unthemed), pairing, mode).ratio, got = evaluatePairing(reader(themed), pairing, mode), floor = Math.min(TARGET_RATIO[target], oneDecimalDown(stock));
|
|
512
|
+
if (Math.round(got.ratio * 100) / 100 >= floor)
|
|
513
|
+
continue;
|
|
514
|
+
let ground = got.over === against ? nameOf(against) : `${nameOf(against)} over ${nameOf(got.over)}`;
|
|
515
|
+
issues.push({
|
|
516
|
+
level: target === "AAA" ? "warning" : "error",
|
|
517
|
+
mode,
|
|
518
|
+
token: nameOf(token),
|
|
519
|
+
against: nameOf(against),
|
|
520
|
+
darkScope: darkScope === 1,
|
|
521
|
+
target: TARGET_RATIO[target],
|
|
522
|
+
over: nameOf(got.over),
|
|
523
|
+
ratio: got.ratio,
|
|
524
|
+
floor,
|
|
525
|
+
stock,
|
|
526
|
+
message: `${nameOf(token)} on ${ground} is ${got.ratio.toFixed(2)}:1 in ${mode} mode; it needs ${floor}:1` + (floor < TARGET_RATIO[target] ? ` (the design system's own pair is ${stock.toFixed(2)}:1, itself under ${TARGET_RATIO[target]}:1).` : ` (the design system's own pair: ${stock.toFixed(2)}:1).`) + (darkScope === 1 ? " The tooltip uses the dark half's colors in both modes, so change them there." : "")
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return issues;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
var RGB = [0, 1, 2];
|
|
534
|
+
function channelsOf(fn, name, hex) {
|
|
535
|
+
let digits = /^#([0-9a-fA-F]{6})$/.exec(hex)?.[1];
|
|
536
|
+
if (digits === void 0)
|
|
537
|
+
throw Error(`${fn}: ref "${name}" resolved to ${JSON.stringify(hex)} — ` + "expected a 6-digit hex. Chain through a palette stop.");
|
|
538
|
+
let n = parseInt(digits, 16);
|
|
539
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
540
|
+
}
|
|
541
|
+
function evalExpr(expr, literalOf, nameOf) {
|
|
542
|
+
switch (expr.op) {
|
|
543
|
+
case "ref":
|
|
544
|
+
return literalOf(expr.ref);
|
|
545
|
+
case "alpha":
|
|
546
|
+
return `rgba(${channelsOf("atAlpha", nameOf(expr.ref), literalOf(expr.ref)).join(", ")}, ${expr.pct / 100})`;
|
|
547
|
+
case "unmix": {
|
|
548
|
+
let a = expr.pct / 100, c = channelsOf("unmix", nameOf(expr.ref), literalOf(expr.ref));
|
|
549
|
+
return `rgba(${RGB.map((i) => Math.round(Math.min(255, Math.max(0, (c[i] - expr.k[i]) / a)))).join(", ")}, ${a})`;
|
|
550
|
+
}
|
|
551
|
+
case "css": {
|
|
552
|
+
let out = expr.strings[0] ?? "";
|
|
553
|
+
for (let [i, part] of expr.parts.entries())
|
|
554
|
+
out += evalExpr(part, literalOf, nameOf) + (expr.strings[i + 1] ?? "");
|
|
555
|
+
return out;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
var NAME = /^[a-z][a-z0-9-]*$/;
|
|
561
|
+
function parseForm(text) {
|
|
562
|
+
let part = (s) => {
|
|
563
|
+
let [ref = "", a = "", b = ""] = s.slice(1).split("/");
|
|
564
|
+
if (s.startsWith("@"))
|
|
565
|
+
return { op: "alpha", ref, pct: Number(a) };
|
|
566
|
+
if (s.startsWith("~")) {
|
|
567
|
+
let [r = 0, g = 0, bl = 0] = a.split(",").map(Number);
|
|
568
|
+
return { op: "unmix", ref, k: [r, g, bl], pct: Number(b) };
|
|
569
|
+
}
|
|
570
|
+
return { op: "ref", ref: s };
|
|
571
|
+
};
|
|
572
|
+
if (text.startsWith("'"))
|
|
573
|
+
return { op: "css", strings: [text.slice(1)], parts: [] };
|
|
574
|
+
if (NAME.test(text) || /^[@~]/.test(text))
|
|
575
|
+
return part(text);
|
|
576
|
+
let pieces = text.split(/\{([^}]*)\}/);
|
|
577
|
+
return {
|
|
578
|
+
op: "css",
|
|
579
|
+
strings: pieces.filter((_, i) => i % 2 === 0),
|
|
580
|
+
parts: pieces.filter((_, i) => i % 2 === 1).map(part)
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function evaluator(graph, inputs, dark) {
|
|
584
|
+
let known = /* @__PURE__ */ new Map, literalOf = (name) => {
|
|
585
|
+
let seen = known.get(name);
|
|
586
|
+
if (seen !== void 0)
|
|
587
|
+
return seen;
|
|
588
|
+
let entry = Object.hasOwn(graph, name) ? graph[name] : void 0, form = typeof entry === "string" ? entry : entry?.[dark ? 1 : 0], value = form === void 0 ? Object.hasOwn(inputs, name) ? inputs[name] : void 0 : evalExpr(parseForm(form), literalOf, (r) => r);
|
|
589
|
+
if (value === void 0)
|
|
590
|
+
throw Error(`The theme graph reads ${name}, which is neither a theme input nor in the graph. This is a bug in make-colors.js.`);
|
|
591
|
+
return known.set(name, value), value;
|
|
592
|
+
};
|
|
593
|
+
return (name) => Object.hasOwn(graph, name) || Object.hasOwn(inputs, name) ? literalOf(name) : void 0;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
var THEME_INPUT_GROUPS = [
|
|
597
|
+
["gray-", "0 10 20 30 40 50 60 70 80 90 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 810 820 830 840 850 860 870 880 890 900"],
|
|
598
|
+
["role-accent-", "50 100 250 300 400 450 600 700 800 850 fill fill-hover on", 1],
|
|
599
|
+
["role-danger-", "100 250 300 400 450 600 700 800 fill fill-hover on", 1],
|
|
600
|
+
["role-success-", "100 250 400 450 600 700 800 fill fill-hover on", 1],
|
|
601
|
+
["role-warning-", "100 200 250 300 600 700 800 fill fill-hover on", 1],
|
|
602
|
+
["role-pro-", "100 250 300 400 450 600 700 800 fill fill-hover on", 1],
|
|
603
|
+
["role-tooltip-", "bg fg", 1],
|
|
604
|
+
["fill-git-", "added modified"],
|
|
605
|
+
["text-git-", "added removed modified merged closed conflicting draft"]
|
|
606
|
+
], STOCK_THEME_INPUTS = {
|
|
607
|
+
light: "fffffffcfcfbf9f9f7f6f6f4f3f3f0f0efecedece8eae9e4e7e6e1e4e3dde1e0d9d2d1c7c3c2b7b4b3a8a5a49a97958d8987817b79746d6b675f5e5a52514e4544423838352c2c2a20201f1e1e1d1c1c1b1a1a191818171515151313131111110f0f0f0d0d0d0b0b0be7f1fbcde2fb86b6ef6da7ec3987e52a78d6184f950d366b03204203162c2a78d63987e5fffffffad6d6f09595ec7e7ee34948d03b3b8e26266419193c0e0ed03b3be34948ffffffcaeac773cb6d0ca30c00930000630007450611260f0093000ca30c0b0b0bf9dca4fab219eda100db9300734500512e00311a00fab219eda1000b0b0bdfdbfdb0a7f2a096eb8173e37161e04a3aa73227771d16497161e08173e3ffffff0b0b0bffffff1a86338b751c1e9e3ccd205498801f8e6bd9ff3a30c5621b737373",
|
|
608
|
+
darkFrom: 92,
|
|
609
|
+
dark: "32d74bffd01432d74bff2c56ffd014b796ffff6159fa832ea6a6a6"
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
var INPUT_ALIASES = {}, RETIRED_INPUTS = [
|
|
613
|
+
"fill-git-modified-hover",
|
|
614
|
+
"fill-git-merged-hover",
|
|
615
|
+
"fill-git-closed-hover",
|
|
616
|
+
"fill-git-conflicting",
|
|
617
|
+
"fill-git-conflicting-hover",
|
|
618
|
+
"fill-git-draft-hover",
|
|
619
|
+
"fill-git-added-hover",
|
|
620
|
+
"fill-git-removed-hover",
|
|
621
|
+
"fill-git-merged",
|
|
622
|
+
"fill-git-closed"
|
|
623
|
+
];
|
|
624
|
+
function savedUnder(given, name, aliases = INPUT_ALIASES) {
|
|
625
|
+
if (Object.hasOwn(given, name))
|
|
626
|
+
return given[name];
|
|
627
|
+
for (let [old, now] of Object.entries(aliases))
|
|
628
|
+
if (now === name && Object.hasOwn(given, old))
|
|
629
|
+
return given[old];
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function inputNamesOf(data, publicOnly = !1) {
|
|
634
|
+
return data.groups.flatMap(([prefix, suffixes, internal]) => publicOnly && internal === 1 ? [] : suffixes.split(" ").map((s) => prefix + s));
|
|
635
|
+
}
|
|
636
|
+
function stockInputsOf(data, mode) {
|
|
637
|
+
let { light, darkFrom, dark } = data.stock, packed = mode === "light" ? light : light.slice(0, darkFrom * 6) + dark;
|
|
638
|
+
return Object.fromEntries(inputNamesOf(data).map((name, i) => [
|
|
639
|
+
name,
|
|
640
|
+
"#" + packed.slice(i * 6, i * 6 + 6)
|
|
641
|
+
]));
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
var THEME_ID = /^[a-z][a-z0-9-]{0,31}$/, HEX_COLOR = /^#[0-9a-f]{6}$/i, CODE_THEME_NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/i, isThemeId = (v) => typeof v === "string" && THEME_ID.test(v), isHexColor = (v) => typeof v === "string" && HEX_COLOR.test(v), isCodeThemeName = (v) => typeof v === "string" && CODE_THEME_NAME.test(v);
|
|
645
|
+
function shown(v) {
|
|
646
|
+
let text = "an object";
|
|
647
|
+
try {
|
|
648
|
+
text = typeof v === "string" || typeof v === "object" && v !== null ? JSON.stringify(v) ?? String(v) : String(v);
|
|
649
|
+
} catch {}
|
|
650
|
+
return text.length > 40 ? text.slice(0, 37) + "..." : text;
|
|
651
|
+
}
|
|
652
|
+
function assertThemeId(id) {
|
|
653
|
+
if (!isThemeId(id))
|
|
654
|
+
throw Error(`A theme id starts with a lowercase letter and uses only lowercase letters, digits and hyphens, 32 characters at most; got ${shown(id)}.`);
|
|
655
|
+
}
|
|
656
|
+
function assertHexColor(v, what) {
|
|
657
|
+
if (!isHexColor(v))
|
|
658
|
+
throw Error(`${what} is ${shown(v)}. Theme colors are six-digit hex, like #1e1e2e.`);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
var DATA = {
|
|
662
|
+
groups: THEME_INPUT_GROUPS,
|
|
663
|
+
stock: STOCK_THEME_INPUTS
|
|
664
|
+
};
|
|
665
|
+
function themeInputValues(theme, mode) {
|
|
666
|
+
let inputs = stockInputsOf(DATA, mode), given = theme?.inputs?.[mode] ?? {};
|
|
667
|
+
for (let name of Object.keys(inputs)) {
|
|
668
|
+
let value = savedUnder(given, name);
|
|
669
|
+
if (value !== void 0) {
|
|
670
|
+
if (!isHexColor(value))
|
|
671
|
+
assertHexColor(value, `${name} (${mode}) in the theme ${shown(theme?.id)}`);
|
|
672
|
+
inputs[name] = value;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
return inputs;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function literalsFor(theme) {
|
|
679
|
+
let graph = { ...THEME_GRAPH, ...THEME_PAIR_FORMS }, light = evaluator(graph, themeInputValues(theme, "light"), !1), dark = evaluator(graph, themeInputValues(theme, "dark"), !0);
|
|
680
|
+
return (name, mode) => (mode === "dark" ? dark : light)(name);
|
|
681
|
+
}
|
|
682
|
+
function checkTheme(theme) {
|
|
683
|
+
let inputs = Object(theme).inputs, isObject = (v) => typeof v === "object" && v !== null;
|
|
684
|
+
if (!isObject(theme) || !isObject(inputs) || !isObject(Object(inputs).light) || !isObject(Object(inputs).dark))
|
|
685
|
+
throw Error(`checkTheme takes the object defineTheme or parseTheme returns, with its light and dark inputs; got ${shown(theme)}.`);
|
|
686
|
+
return checkThemeWith(THEME_PAIRS, literalsFor(theme), literalsFor(null));
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
var RAMP_STOPS = "0 10 20 30 40 50 60 70 80 90 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 810 820 830 840 850 860 870 880 890 900", ROLE_DEFAULTS = {
|
|
690
|
+
accent: { ramp: "fffffffafcfff5f9fef0f7feebf4fce7f1fbe2eefaddebfad7e8fad2e5facde2fbb7d3f69ec5f486b6ef6da7ec5598e73987e52a78d6256abf1c5cab184f951042810d366b062b57032042031e3d021c39021a3602183103162c05142607121f0910180a0d110b0b0b", shade: 450, ink: 0, floor: 4.4 },
|
|
691
|
+
danger: { ramp: "fffffffffbfbfef7f7fef3f3fdefeffbebebfae7e7fae3e3fadfdffadadafad6d6f7c1c1f4ababf09595ec7e7ee66767e34948d03b3bb93535a32c2c8e2626791e1e6419195112123c0e0e380d0d340c0c310b0b2d0a0a280a0a230b0a1d0b0a170c0b110c0b0b0b0b", shade: 450, ink: 0, floor: 4.5 },
|
|
692
|
+
success: { ramp: "fffffffafdfaf5fbf4f0f9efebf7e9e5f4e4e0f2dedbf0d8d5eed3d0eccdcaeac7aee0a991d68b73cb6d55bf5035b2310ca30c0093000083000073000063000054000745060f350d11260f10230f10210f101e0f101b0f0f180e0e160e0e130d0d100d0c0e0c0b0b0b", shade: 450, ink: 900, floor: 4.5 },
|
|
693
|
+
warning: { ramp: "fffffffefcf8fcf8f1fbf5eaf9f2e4f9eedafaebcefae7c2fae3b8f9e0b0f9dca4f9c868fab219eda100db9300c98500b77700a66a00945d00835100734500623900512e00412400311a002e18002b17002715002314021f12041b1106171007130e090f0d0a0b0b0b", shade: 200, ink: 900, floor: 4.5 },
|
|
694
|
+
pro: { ramp: "fffffffcfbfff8f8fff5f4fff2f1ffefedffebeafee8e6fee5e2fde2dffddfdbfdcfcafbbfb9f5b0a7f2a096eb9085e98173e37161e06250d65645be4a3aa73e318e322777271e601d16491b154419133f17123b151036130f32110e2b0f0e230e0d1b0c0c130b0b0b", shade: 450, ink: 0, floor: 4.5 }
|
|
695
|
+
}, ANCHOR_STOPS = {
|
|
696
|
+
light: { "surface-0": 20, "surface-1": 10, "surface-2": 0, "surface-3": 0, "text-primary": 900, "text-secondary": 600, "text-muted": 400 },
|
|
697
|
+
dark: { "surface-0": 900, "surface-1": 850, "surface-2": 830, "surface-3": 800, "text-primary": 50, "text-secondary": 200, "text-muted": 400 }
|
|
698
|
+
}, DARK_GRAY_INPUTS = [
|
|
699
|
+
["role-tooltip-bg", 900],
|
|
700
|
+
["role-tooltip-fg", 0]
|
|
701
|
+
], GIT_FILLS = [
|
|
702
|
+
["fill-git-added", "text-git-added", [-0.0688, 0.8774, 0.0017], 0],
|
|
703
|
+
["fill-git-modified", "text-git-modified", [-0.0379, 0.935, 0.0009], 0]
|
|
704
|
+
];
|
|
705
|
+
|
|
706
|
+
var isFields = (v) => typeof v === "object" && v !== null && !Array.isArray(v), fieldsOf = (v) => isFields(v) ? v : {};
|
|
707
|
+
function part(v, where) {
|
|
708
|
+
return v === void 0 || isFields(v) ? fieldsOf(v) : fail(`${where} is ${shown(v)}; it has to be an object.`);
|
|
709
|
+
}
|
|
710
|
+
var LIGHTNESS_SLACK = 0.0001, NEUTRAL_CHROMA = 0.004, MATCH_CHROMA = 0.03, MAX_GAIN = 3;
|
|
711
|
+
function fail(message) {
|
|
712
|
+
throw Error(message);
|
|
713
|
+
}
|
|
714
|
+
function onlyKeys(from, known, where) {
|
|
715
|
+
for (let key of Object.keys(from))
|
|
716
|
+
if (!known.includes(key))
|
|
717
|
+
fail(`${where} has ${shown(key)}, which is not something it can set. It takes: ${known.join(", ")}.`);
|
|
718
|
+
}
|
|
719
|
+
function colorsAt(from, keys, where, why) {
|
|
720
|
+
return Object.fromEntries(keys.map((k) => {
|
|
721
|
+
let hex = from[k] ?? fail(`${where} has no ${k}. ${why}: ${keys.join(", ")}.`);
|
|
722
|
+
return assertHexColor(hex, `${where}[${k}]`), [k, hex];
|
|
723
|
+
}));
|
|
724
|
+
}
|
|
725
|
+
var pick = (ramp, stop) => ramp[stop] ?? fail(`defineTheme looked up stop ${stop} on a ramp that has none. This is a bug in make-colors.js.`);
|
|
726
|
+
function grayFromAnchors(stopOf, stops, stock, mode, anchors) {
|
|
727
|
+
let where = `${mode}.gray.anchors`, placed = /* @__PURE__ */ new Map;
|
|
728
|
+
for (let [anchor, hex] of Object.entries(anchors)) {
|
|
729
|
+
if (hex === void 0)
|
|
730
|
+
continue;
|
|
731
|
+
let stop = Object.hasOwn(stopOf, anchor) ? stopOf[anchor] ?? 0 : fail(`${where} names ${shown(anchor)}. A gray ramp can be anchored on: ${Object.keys(stopOf).join(", ")}.`);
|
|
732
|
+
assertHexColor(hex, `${where}[${shown(anchor)}]`);
|
|
733
|
+
let other = placed.get(stop);
|
|
734
|
+
if (other !== void 0 && other.hex.toLowerCase() !== hex.toLowerCase())
|
|
735
|
+
fail(`In ${mode} mode the design system paints ${other.anchor} and ${anchor} with the same gray (gray-${stop}), so they need the same color; got ${other.hex} and ${hex}. Give them one color, or leave one out.`);
|
|
736
|
+
placed.set(stop, { hex, anchor });
|
|
737
|
+
}
|
|
738
|
+
for (let required of ["surface-0", "text-primary"])
|
|
739
|
+
if (anchors[required] === void 0)
|
|
740
|
+
fail(`${where} needs "${required}": the ramp is laid out between the page and the text on it.`);
|
|
741
|
+
let order = [...placed].sort(([a], [b]) => a - b);
|
|
742
|
+
order.forEach(([stop, { hex, anchor }], i) => {
|
|
743
|
+
let [prevStop, prev] = order[i - 1] ?? [];
|
|
744
|
+
if (prev !== void 0 && hexToLab(hex)[0] > hexToLab(prev.hex)[0] + LIGHTNESS_SLACK)
|
|
745
|
+
fail(`In ${mode} mode ${anchor} (gray-${stop}, ${hex}) is lighter than ${prev.anchor} (gray-${prevStop}, ${prev.hex}). The gray ramp runs from lightest at gray-0 to darkest at gray-900, so ${anchor} has to be the darker of the two, or the same.`);
|
|
746
|
+
});
|
|
747
|
+
let ladder = (s) => hexToLab(pick(stock, s))[0], knots = order.map(([s, { hex }]) => ({
|
|
748
|
+
t: ladder(s),
|
|
749
|
+
lab: hexToLab(hex)
|
|
750
|
+
}));
|
|
751
|
+
return Object.fromEntries(stops.map((s) => {
|
|
752
|
+
let t = ladder(s), found = knots.findIndex((k, i) => t <= k.t && t >= (knots[i + 1]?.t ?? 1 / 0)), i = found >= 0 ? found : t > (knots[0]?.t ?? 0) ? 0 : knots.length - 2, a = knots[i], b = knots[i + 1];
|
|
753
|
+
return [
|
|
754
|
+
s,
|
|
755
|
+
placed.get(s)?.hex ?? (a === void 0 || b === void 0 ? pick(stock, s) : labToHex(mixLab(a.lab, b.lab, (t - a.t) / (b.t - a.t))))
|
|
756
|
+
];
|
|
757
|
+
}));
|
|
758
|
+
}
|
|
759
|
+
function roleSpec(v, where, grid) {
|
|
760
|
+
if (typeof v !== "string" && v !== void 0 && !isFields(v))
|
|
761
|
+
fail(`${where} is ${shown(v)}. Give a color like "#1e66f5", or an object with seed, stops or fillShade.`);
|
|
762
|
+
let spec = typeof v === "string" ? { seed: v } : fieldsOf(v);
|
|
763
|
+
if (onlyKeys(spec, ["seed", "stops", "fillShade"], where), spec.seed !== void 0)
|
|
764
|
+
assertHexColor(spec.seed, `${where}.seed`);
|
|
765
|
+
let byHand = part(spec.stops, `${where}.stops`);
|
|
766
|
+
onlyKeys(byHand, grid.map(String), `${where}.stops`);
|
|
767
|
+
for (let [stop, hex] of Object.entries(byHand))
|
|
768
|
+
if (hex !== void 0)
|
|
769
|
+
assertHexColor(hex, `${where}.stops[${stop}]`);
|
|
770
|
+
let { fillShade } = spec;
|
|
771
|
+
if (fillShade !== void 0 && (typeof fillShade !== "number" || !grid.includes(fillShade)))
|
|
772
|
+
fail(`${where}.fillShade is ${shown(fillShade)}. It names the stop filled controls use: ${grid.join(", ")}.`);
|
|
773
|
+
return Object.fromEntries(Object.entries({ ...spec, stops: byHand }).filter(([, value]) => value !== void 0));
|
|
774
|
+
}
|
|
775
|
+
function rampFromSeed(stops, stock, seed) {
|
|
776
|
+
let lch = stops.map((s) => hexToLch(pick(stock, s))), [seedL, seedC, seedH] = hexToLch(seed), match = lch.filter((c) => c[1] >= MATCH_CHROMA).reduce((best, c) => Math.abs(c[0] - seedL) < Math.abs(best[0] - seedL) ? c : best, [9, MATCH_CHROMA, 0]), gain = Math.min(MAX_GAIN, seedC / match[1]);
|
|
777
|
+
return Object.fromEntries(stops.map((s, i) => {
|
|
778
|
+
let [l, c, h] = lch[i] ?? match;
|
|
779
|
+
return [
|
|
780
|
+
s,
|
|
781
|
+
c < NEUTRAL_CHROMA ? pick(stock, s) : lchToHex(l, c * gain, seedH + h - match[2])
|
|
782
|
+
];
|
|
783
|
+
}));
|
|
784
|
+
}
|
|
785
|
+
function inkOn(fill, gray, stockEnd, floor) {
|
|
786
|
+
let [same, other] = stockEnd === 0 ? [0, 900] : [900, 0], pure = (end) => end === 0 ? "#ffffff" : "#000000", reaches = (ink, ratio) => contrastRatio(ink, fill) >= ratio;
|
|
787
|
+
return [pick(gray, same), pure(same)].find((ink) => reaches(ink, floor)) ?? (reaches(pick(gray, other), 7) ? pick(gray, other) : pure(other));
|
|
788
|
+
}
|
|
789
|
+
function deriveWith(data, def) {
|
|
790
|
+
if (!isFields(def))
|
|
791
|
+
return fail(`defineTheme takes an object like { id, label, roles, light, dark }; got ${shown(def)}.`);
|
|
792
|
+
onlyKeys(def, ["id", "label", "roles", "light", "dark", "codeTheme"], "The theme definition");
|
|
793
|
+
let { id, label } = def;
|
|
794
|
+
if (assertThemeId(id), typeof label !== "string" || label === "" || label.length > 64)
|
|
795
|
+
fail(`The theme "${id}" needs a label of 1 to 64 characters: the name people see in a picker.`);
|
|
796
|
+
if (!def.roles && !def.light && !def.dark)
|
|
797
|
+
fail(`The theme "${id}" sets nothing. Give it "roles", a "light" half or a "dark" half.`);
|
|
798
|
+
let stops = data.stops.split(" ").map(Number), names = inputNamesOf(data), roleNames = Object.keys(data.roles);
|
|
799
|
+
onlyKeys(part(def.roles, "roles"), roleNames, "roles");
|
|
800
|
+
let unpack = (packed) => Object.fromEntries(stops.map((s, i) => [s, "#" + packed.slice(i * 6, i * 6 + 6)])), gitKeys = names.flatMap((n) => n.startsWith("text-git-") ? [n.slice(9)] : []), build = (mode) => {
|
|
801
|
+
let stock = stockInputsOf(data, mode), half = def[mode] === void 0 ? void 0 : part(def[mode], mode), out = {};
|
|
802
|
+
if (half !== void 0)
|
|
803
|
+
onlyKeys(half, ["gray", "roles", "git"], mode), onlyKeys(part(half.roles, `${mode}.roles`), roleNames, `${mode}.roles`);
|
|
804
|
+
let stockGray = Object.fromEntries(stops.map((s) => [s, stock[`gray-${s}`] ?? ""])), g = part(half?.gray, `${mode}.gray`);
|
|
805
|
+
if (onlyKeys(g, ["anchors", "stops"], `${mode}.gray`), half?.gray !== void 0 && !g.stops && !g.anchors)
|
|
806
|
+
fail(`${mode}.gray needs "anchors" (a few colors named after what they paint, with "stops" for single stops set by hand) or "stops" alone (all ${stops.length} stops).`);
|
|
807
|
+
let byHand = g.anchors ? part(g.stops, `${mode}.gray.stops`) : {};
|
|
808
|
+
if (g.anchors) {
|
|
809
|
+
onlyKeys(byHand, stops.map(String), `${mode}.gray.stops`);
|
|
810
|
+
for (let [stop, hex] of Object.entries(byHand))
|
|
811
|
+
if (hex !== void 0)
|
|
812
|
+
assertHexColor(hex, `${mode}.gray.stops[${stop}]`);
|
|
813
|
+
}
|
|
814
|
+
let gray = {
|
|
815
|
+
...half?.gray === void 0 ? stockGray : g.anchors ? grayFromAnchors(data.anchorStops[mode], stops, stockGray, mode, part(g.anchors, `${mode}.gray.anchors`)) : colorsAt(part(g.stops, `${mode}.gray.stops`), stops, `${mode}.gray.stops`, "A full ramp sets every stop"),
|
|
816
|
+
...Object.fromEntries(Object.entries(byHand).flatMap(([stop, hex]) => typeof hex === "string" ? [[Number(stop), hex]] : []))
|
|
817
|
+
};
|
|
818
|
+
for (let s of stops)
|
|
819
|
+
out[`gray-${s}`] = pick(gray, s);
|
|
820
|
+
for (let [role, defaults] of Object.entries(data.roles)) {
|
|
821
|
+
let own = fieldsOf(half?.roles)[role], base = roleSpec(fieldsOf(def.roles)[role], `roles.${role}`, stops), over = roleSpec(own, `${mode}.roles.${role}`, stops), spec = over.seed !== void 0 ? over : {
|
|
822
|
+
...base,
|
|
823
|
+
...over,
|
|
824
|
+
stops: { ...fieldsOf(base.stops), ...fieldsOf(over.stops) }
|
|
825
|
+
}, prefix = `role-${role}-`, reads = names.flatMap((n) => {
|
|
826
|
+
let stop = n.startsWith(prefix) ? Number(n.slice(prefix.length)) : NaN;
|
|
827
|
+
return Number.isNaN(stop) ? [] : [stop];
|
|
828
|
+
}), ramp = {
|
|
829
|
+
...typeof spec.seed === "string" ? rampFromSeed(stops, unpack(defaults.ramp), spec.seed) : unpack(defaults.ramp)
|
|
830
|
+
};
|
|
831
|
+
for (let [stop, hex] of Object.entries(fieldsOf(spec.stops)))
|
|
832
|
+
if (typeof hex === "string")
|
|
833
|
+
ramp[Number(stop)] = hex;
|
|
834
|
+
let shade = Number(spec.fillShade ?? defaults.shade), i = stops.indexOf(shade);
|
|
835
|
+
for (let s of reads)
|
|
836
|
+
out[prefix + s] = pick(ramp, s);
|
|
837
|
+
let fill = pick(ramp, shade);
|
|
838
|
+
out[prefix + "fill"] = fill;
|
|
839
|
+
let beside = stops[shade >= 300 ? i - 1 : i + 1] ?? shade, handSet = fieldsOf(spec.stops), [, fillChroma, fillHue] = hexToLch(fill);
|
|
840
|
+
out[prefix + "fill-hover"] = spec.seed === void 0 && Object.hasOwn(handSet, String(shade)) && !Object.hasOwn(handSet, String(beside)) ? lchToHex(hexToLch(pick(ramp, beside))[0], fillChroma, fillHue) : pick(ramp, beside);
|
|
841
|
+
let floor = fill.toLowerCase() === stock[prefix + "fill"] ? defaults.floor : 4.5;
|
|
842
|
+
out[prefix + "on"] = inkOn(fill, gray, defaults.ink, floor);
|
|
843
|
+
}
|
|
844
|
+
let git = part(half?.git, `${mode}.git`);
|
|
845
|
+
for (let key of Object.keys(git))
|
|
846
|
+
if (!gitKeys.includes(key))
|
|
847
|
+
fail(`${mode}.git names ${shown(key)}. The git state colors are: ${gitKeys.join(", ")}.`);
|
|
848
|
+
for (let key of gitKeys) {
|
|
849
|
+
let hex = git[key];
|
|
850
|
+
if (hex !== void 0)
|
|
851
|
+
assertHexColor(hex, `${mode}.git.${key}`);
|
|
852
|
+
out[`text-git-${key}`] = hex ?? stock[`text-git-${key}`] ?? "";
|
|
853
|
+
}
|
|
854
|
+
for (let [fill, ink, light, dark] of data.gitFills) {
|
|
855
|
+
let shift = mode === "light" ? light : dark, inkHex = out[ink] ?? "", [l, c, h] = hexToLch(inkHex);
|
|
856
|
+
out[fill] = inkHex.toLowerCase() === stock[ink] ? stock[fill] ?? inkHex : shift === 0 ? inkHex : lchToHex(l + shift[0], c * shift[1], h + shift[2]);
|
|
857
|
+
}
|
|
858
|
+
return { gray, out };
|
|
859
|
+
}, light = build("light"), dark = build("dark");
|
|
860
|
+
for (let [name, stop] of data.darkGrayInputs)
|
|
861
|
+
light.out[name] = dark.out[name] = pick(dark.gray, stop);
|
|
862
|
+
let ordered = ({
|
|
863
|
+
out
|
|
864
|
+
}) => Object.fromEntries(names.map((name) => [
|
|
865
|
+
name,
|
|
866
|
+
out[name]?.toLowerCase() ?? fail(`defineTheme has no rule for the theme input ${name}. This is a gap in make-colors.js, not in the theme.`)
|
|
867
|
+
])), code = part(def.codeTheme, "codeTheme");
|
|
868
|
+
onlyKeys(code, ["light", "dark"], "codeTheme");
|
|
869
|
+
let codeTheme = {};
|
|
870
|
+
for (let mode of ["light", "dark"]) {
|
|
871
|
+
let name = code[mode];
|
|
872
|
+
if (name === void 0)
|
|
873
|
+
continue;
|
|
874
|
+
if (!isCodeThemeName(name))
|
|
875
|
+
fail(`codeTheme.${mode} is ${shown(name)}. A code theme's name is 1 to 64 letters, digits, dots, hyphens or underscores, starting with a letter or digit, like "github-dark".`);
|
|
876
|
+
codeTheme[mode] = String(name);
|
|
877
|
+
}
|
|
878
|
+
return {
|
|
879
|
+
v: 1,
|
|
880
|
+
id,
|
|
881
|
+
label: String(label),
|
|
882
|
+
inputs: { light: ordered(light), dark: ordered(dark) },
|
|
883
|
+
...Object.keys(codeTheme).length > 0 ? { codeTheme } : {}
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
var THEME_DERIVE_DATA = {
|
|
888
|
+
groups: THEME_INPUT_GROUPS,
|
|
889
|
+
stock: STOCK_THEME_INPUTS,
|
|
890
|
+
stops: RAMP_STOPS,
|
|
891
|
+
roles: ROLE_DEFAULTS,
|
|
892
|
+
anchorStops: ANCHOR_STOPS,
|
|
893
|
+
darkGrayInputs: DARK_GRAY_INPUTS,
|
|
894
|
+
gitFills: GIT_FILLS
|
|
895
|
+
}, freeze = (o) => (Object.values(o).forEach((v) => {
|
|
896
|
+
if (typeof v === "object" && v !== null)
|
|
897
|
+
freeze(v);
|
|
898
|
+
}), Object.freeze(o));
|
|
899
|
+
function defineTheme(def) {
|
|
900
|
+
return freeze(deriveWith(THEME_DERIVE_DATA, def));
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
var THEME_INPUT_DATA = {
|
|
904
|
+
groups: THEME_INPUT_GROUPS,
|
|
905
|
+
stock: STOCK_THEME_INPUTS
|
|
906
|
+
};
|
|
907
|
+
var themeInputNames = () => inputNamesOf(THEME_INPUT_DATA), stockThemeInputs = (mode) => stockInputsOf(THEME_INPUT_DATA, mode);
|
|
908
|
+
|
|
909
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v), isLabel = (v) => typeof v === "string" && v !== "" && v.length <= 64, MAX_UNKNOWN = 512, MAX_KEYS = 1024, INPUT_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/, keepable = (name) => name.length <= 64 && INPUT_NAME.test(name);
|
|
910
|
+
function inputsFrom(given, names, stock, aliases, retired = RETIRED_INPUTS) {
|
|
911
|
+
let taken = /* @__PURE__ */ new Set([...names, ...Object.keys(aliases), ...retired]), keys = Object.prototype.toString.call(given) === "[object Object]" ? Object.keys(given) : [], unknown = (keys.length > MAX_KEYS ? [] : keys).filter((k) => keepable(k) && !taken.has(k)).sort().flatMap((key) => {
|
|
912
|
+
let value = given[key];
|
|
913
|
+
return isHexColor(value) ? [[key, value]] : [];
|
|
914
|
+
}).slice(0, MAX_UNKNOWN);
|
|
915
|
+
return Object.fromEntries([
|
|
916
|
+
...names.map((name) => {
|
|
917
|
+
let saved = savedUnder(given, name, aliases);
|
|
918
|
+
return [name, isHexColor(saved) ? saved : stock[name] ?? ""];
|
|
919
|
+
}),
|
|
920
|
+
...unknown
|
|
921
|
+
]);
|
|
922
|
+
}
|
|
923
|
+
function parseTheme(raw) {
|
|
924
|
+
try {
|
|
925
|
+
return read(raw);
|
|
926
|
+
} catch {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
function read(raw) {
|
|
931
|
+
if (!isRecord(raw))
|
|
932
|
+
return;
|
|
933
|
+
let { v, id, label, inputs, codeTheme } = raw;
|
|
934
|
+
if (v !== 1 || !isThemeId(id) || !isLabel(label) || !isRecord(inputs))
|
|
935
|
+
return;
|
|
936
|
+
let half = (mode) => {
|
|
937
|
+
let given = isRecord(inputs[mode]) ? inputs[mode] : {};
|
|
938
|
+
return inputsFrom(given, themeInputNames(), stockThemeInputs(mode), INPUT_ALIASES);
|
|
939
|
+
}, code = isRecord(codeTheme) ? {
|
|
940
|
+
...isCodeThemeName(codeTheme.light) ? { light: codeTheme.light } : {},
|
|
941
|
+
...isCodeThemeName(codeTheme.dark) ? { dark: codeTheme.dark } : {}
|
|
942
|
+
} : void 0;
|
|
943
|
+
return Object.freeze({
|
|
944
|
+
v: 1,
|
|
945
|
+
id,
|
|
946
|
+
label,
|
|
947
|
+
inputs: Object.freeze({
|
|
948
|
+
light: Object.freeze(half("light")),
|
|
949
|
+
dark: Object.freeze(half("dark"))
|
|
950
|
+
}),
|
|
951
|
+
...code !== void 0 && Object.keys(code).length > 0 ? { codeTheme: Object.freeze(code) } : {}
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
var LEAST_TEXT_CONTRAST = 3, isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
956
|
+
function undefinedIn(value, path) {
|
|
957
|
+
if (value === void 0)
|
|
958
|
+
return [path];
|
|
959
|
+
return isRecord2(value) ? Object.entries(value).flatMap(([key, inner]) => undefinedIn(inner, `${path}.${key}`)) : [];
|
|
960
|
+
}
|
|
961
|
+
function halfProblems(mode, half, known) {
|
|
962
|
+
if (half === void 0)
|
|
963
|
+
return [];
|
|
964
|
+
if (mode !== "light" && mode !== "dark")
|
|
965
|
+
return [
|
|
966
|
+
`inputs.${mode} isn't a mode, so nothing paints there: use light or dark.`
|
|
967
|
+
];
|
|
968
|
+
if (!isRecord2(half))
|
|
969
|
+
return [`inputs.${mode} must be an object, so nothing paints there.`];
|
|
970
|
+
return Object.entries(half).filter(([, value]) => value !== void 0).flatMap(([name, value]) => [
|
|
971
|
+
...known.has(name) ? [] : [
|
|
972
|
+
`inputs.${mode}.${name} isn't a theme color name, so it paints nothing.`
|
|
973
|
+
],
|
|
974
|
+
...isHexColor(value) ? [] : [
|
|
975
|
+
`inputs.${mode}.${name} is not six-digit hex, so it paints nothing.`
|
|
976
|
+
]
|
|
977
|
+
]);
|
|
978
|
+
}
|
|
979
|
+
function shapeProblems(colors) {
|
|
980
|
+
if (!isRecord2(colors))
|
|
981
|
+
return ["colors must be an object, so nothing paints."];
|
|
982
|
+
let { v, label, inputs } = colors, known = new Set(themeInputNames());
|
|
983
|
+
return [
|
|
984
|
+
...undefinedIn(colors, "colors").map((path) => `${path} is undefined, and $.theme.set refuses that: leave the key out.`),
|
|
985
|
+
...v === 1 ? [] : ["v must be 1, so nothing paints."],
|
|
986
|
+
...typeof label === "string" && label !== "" && label.length <= 64 ? [] : ["label must be 1 to 64 characters, so nothing paints."],
|
|
987
|
+
...isRecord2(inputs) ? Object.entries(inputs).flatMap(([mode, half]) => halfProblems(mode, half, known)) : ["inputs must be an object, so nothing paints."]
|
|
988
|
+
];
|
|
989
|
+
}
|
|
990
|
+
function contrastProblems(colors) {
|
|
991
|
+
let theme = parseTheme({ ...colors, id: "mod-theme" });
|
|
992
|
+
if (theme === void 0)
|
|
993
|
+
return [];
|
|
994
|
+
let issues = checkTheme(theme), isRefused = (issue) => issue.target >= 4.5 && issue.ratio < LEAST_TEXT_CONTRAST && !issue.token.startsWith("text-git-");
|
|
995
|
+
return [
|
|
996
|
+
...issues.filter(isRefused).map((issue) => `Desktop won't paint this theme, because this text is under 3:1: ${issue.message}`),
|
|
997
|
+
...issues.filter((issue) => issue.level === "error" && !isRefused(issue)).map((issue) => issue.message)
|
|
998
|
+
];
|
|
999
|
+
}
|
|
1000
|
+
function checkColors(colors) {
|
|
1001
|
+
return [...shapeProblems(colors), ...isRecord2(colors) ? contrastProblems(colors) : []];
|
|
1002
|
+
}
|
|
1003
|
+
function makeColors({ only, contrast, ...definition }) {
|
|
1004
|
+
if (only !== void 0 && only !== "light" && only !== "dark")
|
|
1005
|
+
throw Error(`only is "${only}": use 'light' or 'dark', or leave it out.`);
|
|
1006
|
+
let asJson = JSON.parse(JSON.stringify(definition)), whole = JSON.parse(JSON.stringify(defineTheme({ id: "mod-theme", ...asJson }))), theme = {
|
|
1007
|
+
...whole,
|
|
1008
|
+
...only !== void 0 && { inputs: { [only]: whole.inputs[only] } },
|
|
1009
|
+
...contrast !== void 0 && { contrast }
|
|
1010
|
+
};
|
|
1011
|
+
return { theme, problems: checkColors(theme) };
|
|
1012
|
+
}
|
|
1013
|
+
export {
|
|
1014
|
+
checkColors,
|
|
1015
|
+
makeColors
|
|
1016
|
+
};
|