@kabmo-labs/kabmo 0.19.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -5
- package/dist/client/index.html +3 -3
- package/dist/client/index.js +340 -340
- package/dist/client/static/js/{index-sxdw908m.css → index-0721wrkf.css} +1 -1
- package/dist/client/static/js/{index-fcee4c13.js → index-thwqf24c.js} +685 -685
- package/dist/client/static/{manifest-42r8wcmg.webmanifest → manifest-q6h8k9e0.webmanifest} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/public/manifest.webmanifest +1 -1
- package/src/client/components/common/checkbox/style.test.ts +11 -8
- package/src/client/components/common/panel-mark/index.test.tsx +124 -0
- package/src/client/components/common/panel-mark/index.tsx +9 -1
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +46 -0
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +7 -9
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +33 -6
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +15 -0
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +6 -2
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +7 -1
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +35 -2
- package/src/client/glass-sticky.test.ts +46 -0
- package/src/client/glass.css +27 -17
- package/src/client/glass.test.ts +21 -61
- package/src/client/hooks/ui/stuck-header.test.ts +28 -3
- package/src/client/hooks/ui/stuck-header.ts +36 -5
- package/src/client/hooks/workspace/panel-registry.ts +8 -4
- package/src/server/lib/lifecycle/tls.test.ts +6 -1
- package/src/server/lib/panels/git-update.server.test.ts +20 -0
- package/src/server/lib/panels/git-update.server.ts +20 -4
- package/src/server/lib/panels/sync.server.ts +9 -1
- package/src/server/lib/panels/update.server.test.ts +193 -0
- package/src/server/lib/panels/update.server.ts +210 -0
- package/src/server/lib/plugins/server-half.server.ts +42 -0
- package/src/server/lib/terminal/attach-replay.test.ts +26 -8
- package/src/server/routes/panels/install-route.test.ts +238 -0
- package/src/server/routes/panels/install.ts +36 -64
- package/src/server/routes/panels/panel-routes.test-util.ts +6 -1
- package/src/server/routes/panels/routes.test.ts +1 -118
- package/src/shared/lib/icons/icon-paint-css.test.ts +104 -25
- package/src/shared/lib/icons/icon-paint-css.ts +60 -50
- package/src/shared/lib/icons/icon-paint-panel.ts +16 -7
- package/src/shared/lib/icons/icon-paint-weight.ts +123 -0
- package/src/shared/lib/icons/icon-tone.ts +166 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +50 -3
- package/src/shared/lib/icons/tint.test.ts +75 -15
- package/src/shared/lib/icons/tint.ts +40 -11
- package/src/shared/lib/panels/update.test.ts +107 -0
- package/src/shared/lib/panels/update.ts +73 -0
- package/src/shared/lib/theme/color.ts +50 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The LIGHT tone of a generated hue — solved, not stated as one pair.
|
|
8
|
+
*
|
|
9
|
+
* ## The bug this answers
|
|
10
|
+
*
|
|
11
|
+
* `color` mode painted every light icon with one `hsl(H 60% 30%)`, and the
|
|
12
|
+
* report was that icons look muddy in light mode while the same icons look
|
|
13
|
+
* bright in dark ("warna icon di mode full color ketika light mode kelihatan
|
|
14
|
+
* kusem"). Measured, the cause is not rendering. That pair is pinned to the 3:1
|
|
15
|
+
* non-text floor, so its saturation is whatever the WORST hue tolerates — and
|
|
16
|
+
* chroma is not evenly distributed on the wheel. Over the 36 generated hues the
|
|
17
|
+
* pair spans OKLCH chroma **0.075** (hue 190) to **0.164** (hue 120), mean
|
|
18
|
+
* **0.121**, while dark's `hsl(H 65% 70%)` reaches **0.126** with 4.07:1 of
|
|
19
|
+
* headroom left over. Light spent its entire legibility budget and still had
|
|
20
|
+
* less colour than dark, which never had to spend anything.
|
|
21
|
+
*
|
|
22
|
+
* One pair cannot fix that. Raising it to `85%` drops the worst hue to 2.66:1
|
|
23
|
+
* and `100%` to 2.32:1 — under the floor. Gamut, not taste, is the binding
|
|
24
|
+
* constraint, and it binds differently at every hue, so the tone is solved per
|
|
25
|
+
* hue.
|
|
26
|
+
*
|
|
27
|
+
* ## The rule
|
|
28
|
+
*
|
|
29
|
+
* Keep the hue; take the most chroma sRGB can show at that lightness, capped at
|
|
30
|
+
* {@link ICON_TONE_CHROMA_CAP}; keep only lightnesses where the painted byte
|
|
31
|
+
* clears {@link ICON_TONE_CONTRAST} on EVERY light palette this build ships.
|
|
32
|
+
* Prefer the most chroma, then the lighter candidate (a lighter tone of equal
|
|
33
|
+
* chroma reads less heavy beside ink text).
|
|
34
|
+
*
|
|
35
|
+
* Over the same 36 hues: mean chroma **0.121 → 0.162 (×1.34)**, the muddiest
|
|
36
|
+
* row (hue 190) **0.075 → 0.102** and hue 200 **0.078 → 0.121**, every hue
|
|
37
|
+
* improves, and the worst painted contrast stays at 3.15.
|
|
38
|
+
*
|
|
39
|
+
* ## Why the answer is a generated table, not a call
|
|
40
|
+
*
|
|
41
|
+
* The solve needs `THEMES`, and the client must not pay 11k contrast checks on
|
|
42
|
+
* load — nor carry the palette table just to colour a plugin's initials. So
|
|
43
|
+
* `scripts/icon-tints.mjs` runs this module at build time and emits `ICON_TONES`
|
|
44
|
+
* into `tint-hues.generated.ts`; runtime is a lookup shipped in that file. The
|
|
45
|
+
* suite compares the table against this solver, so a palette added later cannot
|
|
46
|
+
* leave a stale, sub-floor tone behind.
|
|
47
|
+
*
|
|
48
|
+
* ## What it deliberately does not do
|
|
49
|
+
*
|
|
50
|
+
* - **Dark is untouched.** It reads bright already; raising its chroma would
|
|
51
|
+
* only invert the complaint.
|
|
52
|
+
* - **The hue is the OKLCH hue of the old paint**, not the raw wheel number.
|
|
53
|
+
* HSL's `210` and OKLCH's `210` are different colours; deriving one from the
|
|
54
|
+
* other keeps "hue 210 is that blue" true across the change.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
import { THEMES } from '@/shared/lib/theme/catalog';
|
|
58
|
+
import { BRAND_CONTRAST_FLOOR, contrastRatio } from '@/shared/lib/theme/legibility';
|
|
59
|
+
import { maxChromaInGamut, oklchToRgb, parseHexColor, rgbaToHex } from '@/shared/lib/theme/color';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The contrast a tone must clear on every light palette, with headroom ON TOP of
|
|
63
|
+
* the WCAG floor.
|
|
64
|
+
*
|
|
65
|
+
* Quantizing to 8-bit hex moves the achieved ratio by up to ~0.15, so a tone
|
|
66
|
+
* solved at exactly 3.0 can paint at 2.87. 3.15 is the measured value at which
|
|
67
|
+
* the painted byte is still clear of {@link BRAND_CONTRAST_FLOOR}.
|
|
68
|
+
*/
|
|
69
|
+
export const ICON_TONE_CONTRAST = 3.15;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The most chroma a generated tone may carry.
|
|
73
|
+
*
|
|
74
|
+
* Uncapped, the solver hands magenta `C 0.25` (`#f00580`) — all the chroma sRGB
|
|
75
|
+
* can show at that lightness. Measured, that reads as a neon sign beside a
|
|
76
|
+
* toolbar glyph, not as a hue. 0.19 keeps every capped hue vivid and leaves the
|
|
77
|
+
* ones that cannot reach it (yellow, teal) at their gamut maximum.
|
|
78
|
+
*/
|
|
79
|
+
export const ICON_TONE_CHROMA_CAP = 0.19;
|
|
80
|
+
|
|
81
|
+
/** Lightnesses the solver may use, lightest first — ties prefer the lighter. */
|
|
82
|
+
const LIGHTNESS_LADDER = [0.62, 0.6, 0.58, 0.56, 0.54, 0.52, 0.5, 0.48, 0.46, 0.44, 0.4];
|
|
83
|
+
|
|
84
|
+
/** The wheel the generated hues land on: 36 steps of 10°. */
|
|
85
|
+
export const ICON_TONE_WHEEL = Array.from({ length: 36 }, (_, index) => index * 10);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* OKLCH of a painted hex — what "the same colour, brighter" is measured in.
|
|
89
|
+
*
|
|
90
|
+
* Used by the solver (to keep the hue) and by the suite (to prove the light tone
|
|
91
|
+
* carries more chroma than the pair it replaced, which is the whole report).
|
|
92
|
+
*/
|
|
93
|
+
export function oklchOf(hex: string): { lightness: number; chroma: number; hue: number } {
|
|
94
|
+
const color = parseHexColor(hex);
|
|
95
|
+
if (!color) return { lightness: 0, chroma: 0, hue: 0 };
|
|
96
|
+
const lin = (raw: number) => {
|
|
97
|
+
const c = raw / 255;
|
|
98
|
+
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
99
|
+
};
|
|
100
|
+
const r = lin(color.r);
|
|
101
|
+
const g = lin(color.g);
|
|
102
|
+
const b = lin(color.b);
|
|
103
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
104
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
105
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
106
|
+
const lightness = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
107
|
+
const a = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
108
|
+
const bb = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
109
|
+
return {
|
|
110
|
+
lightness,
|
|
111
|
+
chroma: Math.hypot(a, bb),
|
|
112
|
+
hue: ((Math.atan2(bb, a) * 180) / Math.PI + 360) % 360,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The lowest contrast `hex` reaches on any light palette's surface. */
|
|
117
|
+
function worstLightContrast(hex: string): number {
|
|
118
|
+
let worst = Number.POSITIVE_INFINITY;
|
|
119
|
+
for (const theme of THEMES) {
|
|
120
|
+
if (theme.variant !== 'light') continue;
|
|
121
|
+
worst = Math.min(worst, contrastRatio(hex, theme.paper));
|
|
122
|
+
}
|
|
123
|
+
return worst === Number.POSITIVE_INFINITY ? BRAND_CONTRAST_FLOOR : worst;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The tone for ONE wheel hue, given the pair the mode used to paint with.
|
|
128
|
+
*
|
|
129
|
+
* `saturation`/`lightness` are the OLD constants, and they are only used to name
|
|
130
|
+
* the colour: `hsl(H 60% 30%)` is hue `H` as this app already means it, and its
|
|
131
|
+
* OKLCH hue angle is what gets kept.
|
|
132
|
+
*/
|
|
133
|
+
export function solveIconTone(wheelHue: number, saturation = 60, lightness = 30): string {
|
|
134
|
+
const colorHue = oklchOf(hslToHex(wheelHue, saturation, lightness)).hue;
|
|
135
|
+
let best: { hex: string; chroma: number; lightness: number } | null = null;
|
|
136
|
+
let darkest = '';
|
|
137
|
+
for (const candidate of LIGHTNESS_LADDER) {
|
|
138
|
+
const chroma = Math.min(ICON_TONE_CHROMA_CAP, maxChromaInGamut(candidate, colorHue));
|
|
139
|
+
const paint = oklchToRgb(candidate, Math.max(chroma, 0.02), colorHue);
|
|
140
|
+
const hex = rgbaToHex(paint);
|
|
141
|
+
darkest = hex;
|
|
142
|
+
if (!paint.inGamut) continue;
|
|
143
|
+
if (worstLightContrast(hex) < ICON_TONE_CONTRAST) continue;
|
|
144
|
+
const better = !best || chroma > best.chroma + 1e-6 || (Math.abs(chroma - best.chroma) <= 1e-6 && candidate > best.lightness);
|
|
145
|
+
if (better) best = { hex, chroma, lightness: candidate };
|
|
146
|
+
}
|
|
147
|
+
return best?.hex ?? darkest;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Every wheel hue's light tone: what the generator writes to disk. */
|
|
151
|
+
export function solveIconTones(): Record<number, string> {
|
|
152
|
+
return Object.fromEntries(ICON_TONE_WHEEL.map((hue) => [hue, solveIconTone(hue)]));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** `hsl(h <saturation>% <lightness>%)` as `#rrggbb` — the paint this module replaces. */
|
|
156
|
+
export function hslToHex(hue: number, saturation: number, lightness: number): string {
|
|
157
|
+
const s = saturation / 100;
|
|
158
|
+
const l = lightness / 100;
|
|
159
|
+
const k = (n: number) => (n + hue / 30) % 12;
|
|
160
|
+
const a = s * Math.min(l, 1 - l);
|
|
161
|
+
const channel = (n: number) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
|
162
|
+
const byte = (value: number) => Math.round(Math.min(1, Math.max(0, value)) * 255);
|
|
163
|
+
return `#${[channel(0), channel(8), channel(4)]
|
|
164
|
+
.map((value) => byte(value).toString(16).padStart(2, '0'))
|
|
165
|
+
.join('')}`;
|
|
166
|
+
}
|
|
@@ -11,9 +11,16 @@
|
|
|
11
11
|
* paint a palette token, because a trash can has to be the theme's error colour
|
|
12
12
|
* and not whatever the hash said.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* table
|
|
14
|
+
* `ICON_TONES` is the LIGHT paint for each wheel hue, solved by
|
|
15
|
+
* `shared/lib/icons/icon-tone.ts` against every light palette this build ships.
|
|
16
|
+
* It is a table rather than a call because the solve needs the palette catalog,
|
|
17
|
+
* which the client would otherwise carry — and 11k contrast checks — only to
|
|
18
|
+
* colour a toolbar glyph. Dark keeps its single `hsl()` pair: it already reads
|
|
19
|
+
* bright, and one pair is enough when the budget is not spent.
|
|
20
|
+
*
|
|
21
|
+
* Regenerate with `bun run icons:tints` after adding an icon OR a palette. The
|
|
22
|
+
* suite fails when this table and the imports disagree (`icons:tints:check`),
|
|
23
|
+
* so a stale table cannot ship.
|
|
17
24
|
*/
|
|
18
25
|
|
|
19
26
|
export const ICON_HUES: Readonly<Record<string, number>> = {
|
|
@@ -228,3 +235,43 @@ export const ICON_HUES: Readonly<Record<string, number>> = {
|
|
|
228
235
|
ZoomIn: 250,
|
|
229
236
|
ZoomOut: 340,
|
|
230
237
|
};
|
|
238
|
+
|
|
239
|
+
/** The light paint for each wheel hue, darkest-legible-but-most-chromatic. */
|
|
240
|
+
export const ICON_TONES: Readonly<Record<number, string>> = {
|
|
241
|
+
0: '#db4241',
|
|
242
|
+
10: '#da4528',
|
|
243
|
+
20: '#cf5500',
|
|
244
|
+
30: '#b06600',
|
|
245
|
+
40: '#9e7200',
|
|
246
|
+
50: '#8e7a00',
|
|
247
|
+
60: '#808000',
|
|
248
|
+
70: '#738400',
|
|
249
|
+
80: '#5f8200',
|
|
250
|
+
90: '#4f8600',
|
|
251
|
+
100: '#3a8a00',
|
|
252
|
+
110: '#218c00',
|
|
253
|
+
120: '#008e0a',
|
|
254
|
+
130: '#008d29',
|
|
255
|
+
140: '#008c3e',
|
|
256
|
+
150: '#008b53',
|
|
257
|
+
160: '#008965',
|
|
258
|
+
170: '#008876',
|
|
259
|
+
180: '#008686',
|
|
260
|
+
190: '#00899f',
|
|
261
|
+
200: '#0085b7',
|
|
262
|
+
210: '#007cd8',
|
|
263
|
+
220: '#3972e9',
|
|
264
|
+
230: '#4f6de9',
|
|
265
|
+
240: '#6070ef',
|
|
266
|
+
250: '#736aec',
|
|
267
|
+
260: '#8663e6',
|
|
268
|
+
270: '#985cdc',
|
|
269
|
+
280: '#a556d0',
|
|
270
|
+
290: '#b051c4',
|
|
271
|
+
300: '#b94db8',
|
|
272
|
+
310: '#c149ab',
|
|
273
|
+
320: '#c9459b',
|
|
274
|
+
330: '#d04188',
|
|
275
|
+
340: '#d63f70',
|
|
276
|
+
350: '#da3f58',
|
|
277
|
+
};
|
|
@@ -40,10 +40,12 @@ import {
|
|
|
40
40
|
iconHueColor,
|
|
41
41
|
iconHuePaint,
|
|
42
42
|
iconTintRole,
|
|
43
|
+
iconTone,
|
|
43
44
|
kebabIconName,
|
|
44
45
|
lucideClassName,
|
|
45
46
|
} from '@/shared/lib/icons/tint';
|
|
46
|
-
import { ICON_HUES } from '@/shared/lib/icons/tint-hues.generated';
|
|
47
|
+
import { ICON_HUES, ICON_TONES } from '@/shared/lib/icons/tint-hues.generated';
|
|
48
|
+
import { oklchOf } from '@/shared/lib/icons/icon-tone';
|
|
47
49
|
import { THEMES } from '@/shared/lib/theme/catalog';
|
|
48
50
|
import { BRAND_CONTRAST_FLOOR, contrastRatio } from '@/shared/lib/theme/legibility';
|
|
49
51
|
|
|
@@ -196,26 +198,84 @@ describe('the generated hues', () => {
|
|
|
196
198
|
expect(check.exitCode, check.stderr.toString()).toBe(0);
|
|
197
199
|
});
|
|
198
200
|
|
|
199
|
-
test('every
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
201
|
+
test('every light tone clears the non-text floor on every light palette', () => {
|
|
202
|
+
// The tone is SOLVED per hue (see `icon-tone.ts`); this is the property that
|
|
203
|
+
// let the mode carry 39% more chroma without losing a single row, so it is
|
|
204
|
+
// pinned per palette rather than against one hex.
|
|
205
|
+
const papers = THEMES.filter((theme) => theme.variant === 'light').map((theme) => theme.paper);
|
|
206
|
+
for (const [hue, tone] of Object.entries(ICON_TONES)) {
|
|
207
|
+
expect(tone, hue).toMatch(/^#[0-9a-f]{6}$/);
|
|
208
|
+
const worst = Math.min(...papers.map((paper) => contrastRatio(tone, paper)));
|
|
209
|
+
expect(worst, `hue ${hue} (${tone})`).toBeGreaterThanOrEqual(BRAND_CONTRAST_FLOOR);
|
|
208
210
|
}
|
|
209
211
|
});
|
|
210
212
|
|
|
213
|
+
test('the dark hue still clears the floor at its one stated pair', () => {
|
|
214
|
+
// Dark is deliberately untouched: it reads bright already, and raising its
|
|
215
|
+
// chroma would only invert the complaint.
|
|
216
|
+
const { saturation, lightness } = ICON_HUE_PAINT.dark;
|
|
217
|
+
const papers = THEMES.filter((theme) => theme.variant === 'dark').map((theme) => theme.paper);
|
|
218
|
+
for (const hue of new Set(Object.values(ICON_HUES))) {
|
|
219
|
+
const color = hslHex(hue, saturation, lightness);
|
|
220
|
+
const worst = Math.min(...papers.map((paper) => contrastRatio(color, paper)));
|
|
221
|
+
expect(worst, `hue ${hue} (${color})`).toBeGreaterThanOrEqual(BRAND_CONTRAST_FLOOR);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('a light tone carries MORE chroma than the pair it replaced', () => {
|
|
226
|
+
// The report — "warna icon di mode full color ketika light mode kelihatan
|
|
227
|
+
// kusem" — is this measurement, and nothing else: the old pair maxed out at
|
|
228
|
+
// OKLCH chroma 0.075 on the muddiest hue because one saturation had to suit
|
|
229
|
+
// every hue on the wheel. Solving per hue is what buys the colour back, and
|
|
230
|
+
// this is the assertion that would fail if a future edit quietly put a
|
|
231
|
+
// uniform pair back.
|
|
232
|
+
const hues = Object.keys(ICON_TONES).map(Number);
|
|
233
|
+
const mean = (values: number[]) => values.reduce((a, b) => a + b, 0) / values.length;
|
|
234
|
+
const before = hues.map((hue) => oklchOf(hslHex(hue, ICON_HUE_PAINT.light.saturation, ICON_HUE_PAINT.light.lightness)).chroma);
|
|
235
|
+
const after = hues.map((hue) => oklchOf(ICON_TONES[hue]!).chroma);
|
|
236
|
+
expect(mean(after)).toBeGreaterThan(mean(before) * 1.3);
|
|
237
|
+
// Every single hue must improve — a table that traded one muddy row for
|
|
238
|
+
// another would still pass the mean.
|
|
239
|
+
for (const hue of hues) {
|
|
240
|
+
expect(oklchOf(ICON_TONES[hue]!).chroma, `hue ${hue}`).toBeGreaterThan(
|
|
241
|
+
oklchOf(hslHex(hue, ICON_HUE_PAINT.light.saturation, ICON_HUE_PAINT.light.lightness)).chroma,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('a light tone keeps its hue, so a row does not change colour', () => {
|
|
247
|
+
// Solved in OKLCH, but the hue is the OKLCH angle of the OLD paint: a tone
|
|
248
|
+
// that drifted would recolour every icon in the app, which is not what
|
|
249
|
+
// "more colour" means.
|
|
250
|
+
for (const [hue, tone] of Object.entries(ICON_TONES)) {
|
|
251
|
+
const before = oklchOf(hslHex(Number(hue), ICON_HUE_PAINT.light.saturation, ICON_HUE_PAINT.light.lightness)).hue;
|
|
252
|
+
const after = oklchOf(tone).hue;
|
|
253
|
+
const circular = Math.min(Math.abs(before - after), 360 - Math.abs(before - after));
|
|
254
|
+
expect(circular, `hue ${hue} (${tone})`).toBeLessThan(12);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('the light tone is a table lookup, not a solve, and it snaps to the wheel', () => {
|
|
259
|
+
expect(iconTone(120)).toBe(ICON_TONES[120]!);
|
|
260
|
+
// `hashHue` only produces wheel steps, but a stored or plugin name could
|
|
261
|
+
// still reach here with something else; the nearest step keeps it a colour.
|
|
262
|
+
expect(iconTone(124)).toBe(ICON_TONES[120]!);
|
|
263
|
+
expect(iconTone(356)).toBe(ICON_TONES[0]!);
|
|
264
|
+
expect(iconTone(-10)).toBe(ICON_TONES[350]!);
|
|
265
|
+
});
|
|
266
|
+
|
|
211
267
|
test('the paint rule and the concrete colour share one formula', () => {
|
|
212
268
|
// The stylesheet leaves the hue to `--icon-hue`; the settings preview needs a
|
|
213
269
|
// real colour. Both must come from the same numbers, or the preview lies.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
270
|
+
// LIGHT reads the solved `--icon-tone` (falling back to the old pair), which
|
|
271
|
+
// is why it is not a bare `hsl()` any more.
|
|
272
|
+
const { saturation, lightness } = ICON_HUE_PAINT.dark;
|
|
273
|
+
expect(iconHuePaint('light')).toBe(
|
|
274
|
+
`var(--icon-tone, hsl(var(--icon-hue, ${DEFAULT_ICON_HUE}) ${ICON_HUE_PAINT.light.saturation}% ${ICON_HUE_PAINT.light.lightness}%))`,
|
|
275
|
+
);
|
|
276
|
+
expect(iconHuePaint('dark')).toBe(`hsl(var(--icon-hue, ${DEFAULT_ICON_HUE}) ${saturation}% ${lightness}%)`);
|
|
277
|
+
expect(iconHueColor(120, 'light')).toBe(ICON_TONES[120]!);
|
|
278
|
+
expect(iconHueColor(120, 'dark')).toBe(`hsl(120 ${saturation}% ${lightness}%)`);
|
|
219
279
|
});
|
|
220
280
|
|
|
221
281
|
test('the table is exactly what the runtime hash produces', () => {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* is the single translation to `lucide-trash-2`.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import { ICON_HUES } from '@/shared/lib/icons/tint-hues.generated';
|
|
34
|
+
import { ICON_HUES, ICON_TONES } from '@/shared/lib/icons/tint-hues.generated';
|
|
35
35
|
|
|
36
36
|
export type IconTintRole = 'error' | 'success' | 'warning' | 'info';
|
|
37
37
|
|
|
@@ -44,13 +44,12 @@ export const ICON_TINT_TOKENS: Readonly<Record<IconTintRole, string>> = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* How the DARK hue is painted. Light has no pair any more — see below.
|
|
48
48
|
*
|
|
49
|
-
*
|
|
50
|
-
* palette,
|
|
51
|
-
* graphic)
|
|
52
|
-
*
|
|
53
|
-
* value (34%) drops two hues below the floor, which is why it is not "prettier".
|
|
49
|
+
* `65% 70%` is the whole legibility budget on that side: measured against every
|
|
50
|
+
* dark palette, its worst hue is 4.07:1 on `jetbrains-dark`'s `#2B2D30` (the
|
|
51
|
+
* floor is 3:1 for a graphic). It is also the side nobody complained about, so
|
|
52
|
+
* it is left exactly as it was.
|
|
54
53
|
*/
|
|
55
54
|
export const ICON_HUE_PAINT = {
|
|
56
55
|
light: { saturation: 60, lightness: 30 },
|
|
@@ -60,16 +59,46 @@ export const ICON_HUE_PAINT = {
|
|
|
60
59
|
/** The hue an icon with no row keeps — a neutral blue, never a sixth signal. */
|
|
61
60
|
export const DEFAULT_ICON_HUE = 210;
|
|
62
61
|
|
|
63
|
-
/**
|
|
62
|
+
/** The wheel step nearest `hue` — every producer today is already on it. */
|
|
63
|
+
function wheelStep(hue: number): number {
|
|
64
|
+
return ((Math.round(hue / 10) * 10) % 360 + 360) % 360;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The LIGHT tone for a hue: a hex solved per hue, not one pair for all of them.
|
|
69
|
+
*
|
|
70
|
+
* Measured, this is the difference the report named — the muddiest row (hue 190)
|
|
71
|
+
* goes from OKLCH chroma 0.075 to 0.102, hue 200 from 0.078 to 0.121, and the
|
|
72
|
+
* mean from 0.121 to 0.162 (×1.34), with every tone still at 3.15:1 or better on
|
|
73
|
+
* all 32 light palettes. `icon-tone.ts` states the rule and the numbers.
|
|
74
|
+
*
|
|
75
|
+
* A hue off the wheel snaps to the nearest step: every producer here is a
|
|
76
|
+
* `hashHue` result (36 steps of 10°) or a table row, so the nearest step IS that
|
|
77
|
+
* hue; snapping is what keeps this a table lookup rather than a solve on load.
|
|
78
|
+
*/
|
|
79
|
+
export function iconTone(hue: number): string {
|
|
80
|
+
return ICON_TONES[wheelStep(hue)] ?? ICON_TONES[0]!;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** One hue as a paintable colour. Light is a solved hex; dark is still an `hsl()`. */
|
|
64
84
|
export function iconHueColor(hue: number, variant: 'light' | 'dark'): string {
|
|
65
|
-
|
|
85
|
+
if (variant === 'light') return iconTone(hue);
|
|
86
|
+
const { saturation, lightness } = ICON_HUE_PAINT.dark;
|
|
66
87
|
return `hsl(${hue} ${saturation}% ${lightness}%)`;
|
|
67
88
|
}
|
|
68
89
|
|
|
69
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* The paint rule's value: the hue left to the custom property the class sets.
|
|
92
|
+
*
|
|
93
|
+
* `--icon-tone` wins where it is stamped (every generated row, every plugin and
|
|
94
|
+
* panel mark). The `hsl()` behind it is the old light paint, kept as the last
|
|
95
|
+
* resort for an icon that declares a hue no table row covers — a shade that is
|
|
96
|
+
* merely dated, never absent.
|
|
97
|
+
*/
|
|
70
98
|
export function iconHuePaint(variant: 'light' | 'dark'): string {
|
|
71
99
|
const { saturation, lightness } = ICON_HUE_PAINT[variant];
|
|
72
|
-
|
|
100
|
+
const fallback = `hsl(var(--icon-hue, ${DEFAULT_ICON_HUE}) ${saturation}% ${lightness}%)`;
|
|
101
|
+
return variant === 'light' ? `var(--icon-tone, ${fallback})` : fallback;
|
|
73
102
|
}
|
|
74
103
|
|
|
75
104
|
/** Glyph name → the signal it stands for. Everything else gets a generated hue. */
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one answer three surfaces ask: is there an update, and to what.
|
|
8
|
+
*
|
|
9
|
+
* The states that matter are the ones a naive comparison gets wrong, and each is
|
|
10
|
+
* pinned here because the surfaces disagreeing is invisible until a header counts
|
|
11
|
+
* a button that will not render:
|
|
12
|
+
*
|
|
13
|
+
* - a GIT clone is behind when its remote's COMMIT differs, even at the same
|
|
14
|
+
* version — a fix shipped without a bump;
|
|
15
|
+
* - a BUNDLED install is behind only on a strictly newer version, because the
|
|
16
|
+
* store's copy is what it would install;
|
|
17
|
+
* - a LOCAL directory has no source at all and never has an update.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { describe, expect, test } from 'bun:test';
|
|
21
|
+
import { countPluginUpdates, pluginUpdate } from '@/shared/lib/panels/update';
|
|
22
|
+
import type { PanelGitStatus, PanelPluginStatus } from '@/shared/types';
|
|
23
|
+
|
|
24
|
+
const clone = (overrides: Partial<PanelPluginStatus> = {}): PanelPluginStatus => ({
|
|
25
|
+
pluginId: 'git-plugin',
|
|
26
|
+
name: 'Git Plugin',
|
|
27
|
+
version: '1.0.0',
|
|
28
|
+
built: true,
|
|
29
|
+
isPackage: true,
|
|
30
|
+
enabled: true,
|
|
31
|
+
bundled: false,
|
|
32
|
+
origin: 'git',
|
|
33
|
+
gitOrigin: 'https://example.test/plugin.git',
|
|
34
|
+
...overrides,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const status = (overrides: Partial<PanelGitStatus> = {}): PanelGitStatus => ({
|
|
38
|
+
current: 'aaaaaaa',
|
|
39
|
+
latest: 'bbbbbbb',
|
|
40
|
+
updateAvailable: true,
|
|
41
|
+
checkedAt: Date.now(),
|
|
42
|
+
...overrides,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('a git clone', () => {
|
|
46
|
+
test('is behind when the probe says its commit moved', () => {
|
|
47
|
+
expect(pluginUpdate(clone(), status())).toEqual({});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('names the version the remote declares, so the button can say what it installs', () => {
|
|
51
|
+
expect(pluginUpdate(clone(), status({ latestVersion: '1.1.0' }))).toEqual({ version: '1.1.0' });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('is current when the probe found nothing, whatever the versions say', () => {
|
|
55
|
+
// The probe is the authority: a remote at the same commit cannot install
|
|
56
|
+
// anything, so a stale `latestVersion` must not resurrect the button.
|
|
57
|
+
expect(pluginUpdate(clone({ latestVersion: '9.9.9' }), status({ updateAvailable: false }))).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('is unknown, not current, when it was never probed', () => {
|
|
61
|
+
// A `latestVersion` with no probe behind it describes a status the probe
|
|
62
|
+
// never wrote, so the button stays off until the remote is actually asked.
|
|
63
|
+
expect(pluginUpdate(clone({ latestVersion: '1.2.0' }), undefined)).toBeNull();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('is unknown, not current, when the probe errored', () => {
|
|
67
|
+
expect(pluginUpdate(clone(), status({ updateAvailable: false, error: 'unreachable' }))).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('a bundled install', () => {
|
|
72
|
+
const bundled = (overrides: Partial<PanelPluginStatus> = {}) =>
|
|
73
|
+
clone({ pluginId: 'store-plugin', origin: 'bundled', bundled: true, gitOrigin: null, ...overrides });
|
|
74
|
+
|
|
75
|
+
test('is behind when the store ships a newer version', () => {
|
|
76
|
+
expect(pluginUpdate(bundled({ latestVersion: '2.0.0' }), undefined)).toEqual({ version: '2.0.0' });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('is current at the same version', () => {
|
|
80
|
+
expect(pluginUpdate(bundled({ latestVersion: '1.0.0' }), undefined)).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('is current when the store version is unknown', () => {
|
|
84
|
+
expect(pluginUpdate(bundled(), undefined)).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('a local directory', () => {
|
|
89
|
+
test('never has an update, even when a version looks newer', () => {
|
|
90
|
+
expect(
|
|
91
|
+
pluginUpdate(clone({ origin: 'local', gitOrigin: null, latestVersion: '2.0.0' }), status()),
|
|
92
|
+
).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('the count', () => {
|
|
97
|
+
test('counts exactly the cards that would render an Update', () => {
|
|
98
|
+
const plugins = [
|
|
99
|
+
clone({ pluginId: 'a' }),
|
|
100
|
+
clone({ pluginId: 'b', origin: 'bundled', bundled: true, gitOrigin: null, latestVersion: '2.0.0' }),
|
|
101
|
+
clone({ pluginId: 'c', origin: 'local', gitOrigin: null }),
|
|
102
|
+
clone({ pluginId: 'd', origin: 'bundled', bundled: true, gitOrigin: null, latestVersion: '1.0.0' }),
|
|
103
|
+
];
|
|
104
|
+
// `a` is behind by commit, `b` by version; `c` and `d` are current.
|
|
105
|
+
expect(countPluginUpdates(plugins, { a: status() })).toBe(2);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Is an installed plugin behind whatever publishes it?
|
|
8
|
+
*
|
|
9
|
+
* ONE answer, asked by three surfaces — the card's Update button, the Installed
|
|
10
|
+
* header's count and the Update-all button — because they answer the same
|
|
11
|
+
* question and disagreeing once is the whole bug: a header saying "2 updates
|
|
12
|
+
* available" over a single button is a count of nothing.
|
|
13
|
+
*
|
|
14
|
+
* Two sources, and the two are probed differently:
|
|
15
|
+
*
|
|
16
|
+
* - a BUNDLED install's source is the store, whose manifest sits on disk, so the
|
|
17
|
+
* comparison is a version against a version;
|
|
18
|
+
* - a GIT clone's source is its remote, whose HEAD only a probe knows. A commit
|
|
19
|
+
* difference therefore counts even when the versions are equal (a fix shipped
|
|
20
|
+
* without a bump), which is why the probe's own `updateAvailable` is read
|
|
21
|
+
* rather than a version pair alone.
|
|
22
|
+
*
|
|
23
|
+
* A local directory has no source and never updates; `false` is its honest
|
|
24
|
+
* answer, and its card offers no button at all.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import type { PanelGitStatus, PanelPluginStatus } from '@/shared/types';
|
|
28
|
+
import { isNewer } from '@/shared/lib/updates/semver';
|
|
29
|
+
|
|
30
|
+
/** Where the update would come from, when one is pending. */
|
|
31
|
+
export interface PluginUpdate {
|
|
32
|
+
/** The version the update would install, when the source declares one. */
|
|
33
|
+
version?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The pending update for one plugin, or null when there is nothing to apply.
|
|
38
|
+
*
|
|
39
|
+
* Returns the target version rather than a bare boolean so a button can name
|
|
40
|
+
* what it would install — `Update to v0.3.0` — instead of leaving the reader to
|
|
41
|
+
* compare two numbers themselves.
|
|
42
|
+
*/
|
|
43
|
+
export function pluginUpdate(
|
|
44
|
+
plugin: Pick<PanelPluginStatus, 'version' | 'latestVersion' | 'origin'>,
|
|
45
|
+
gitStatus: PanelGitStatus | undefined,
|
|
46
|
+
): PluginUpdate | null {
|
|
47
|
+
if (plugin.origin === 'local') return null;
|
|
48
|
+
|
|
49
|
+
// A clone: the PROBE is the verdict, not a version pair. Its `latestVersion`
|
|
50
|
+
// is written only on the branch where the commits differ, so it doubles as the
|
|
51
|
+
// target — and a clone that was never probed is unknown rather than current,
|
|
52
|
+
// which is what the card's own freshness row says too.
|
|
53
|
+
if (plugin.origin === 'git') {
|
|
54
|
+
if (gitStatus?.updateAvailable !== true) return null;
|
|
55
|
+
const target = plugin.latestVersion ?? gitStatus.latestVersion;
|
|
56
|
+
return target ? { version: target } : {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// A store install: the store's version is the answer, and "same" means there
|
|
60
|
+
// is nothing to fetch — except for a shipped fix that forgot its bump, which
|
|
61
|
+
// only the server can see and which the boot sync applies without asking.
|
|
62
|
+
const target = plugin.latestVersion;
|
|
63
|
+
if (!target || !isNewer(target, plugin.version)) return null;
|
|
64
|
+
return { version: target };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** How many installed plugins have an update waiting. */
|
|
68
|
+
export function countPluginUpdates(
|
|
69
|
+
plugins: readonly Pick<PanelPluginStatus, 'pluginId' | 'version' | 'latestVersion' | 'origin'>[],
|
|
70
|
+
gitStatus: Readonly<Record<string, PanelGitStatus>>,
|
|
71
|
+
): number {
|
|
72
|
+
return plugins.filter((plugin) => pluginUpdate(plugin, gitStatus[plugin.pluginId]) !== null).length;
|
|
73
|
+
}
|
|
@@ -76,6 +76,56 @@ export function mixHex(base: string, blend: string, ratio: number): string {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* OKLCH, for the one place sRGB arithmetic is measurably wrong: shading a hue
|
|
81
|
+
* toward another tone.
|
|
82
|
+
*
|
|
83
|
+
* The icon tones are the reason. Mixing `#FFD21E` toward black in sRGB keeps
|
|
84
|
+
* 63% of its chroma where the same move in OKLCH keeps it whole, because sRGB
|
|
85
|
+
* channels are not perceptually spaced — a dark yellow drifts to olive. So the
|
|
86
|
+
* light icon tone is *solved* here: hold the hue, take the most chroma sRGB can
|
|
87
|
+
* actually show at that lightness, and then check the result with WCAG contrast.
|
|
88
|
+
*
|
|
89
|
+
* Values are the standard Björn Ottosson transform: OKLab is the linear part,
|
|
90
|
+
* OKLCH is that in polar form.
|
|
91
|
+
*/
|
|
92
|
+
export function oklchToRgb(lightness: number, chroma: number, hue: number): Rgba & { inGamut: boolean } {
|
|
93
|
+
const radians = (hue * Math.PI) / 180;
|
|
94
|
+
const a = chroma * Math.cos(radians);
|
|
95
|
+
const b = chroma * Math.sin(radians);
|
|
96
|
+
|
|
97
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
98
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
99
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
100
|
+
|
|
101
|
+
// Linear-light sRGB, then the transfer function.
|
|
102
|
+
const linear = [
|
|
103
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
104
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
105
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
|
|
106
|
+
] as const;
|
|
107
|
+
const channel = (value: number) => {
|
|
108
|
+
const encoded = value <= 0.0031308 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - 0.055;
|
|
109
|
+
return encoded * 255;
|
|
110
|
+
};
|
|
111
|
+
// A hair of slack: at the gamut surface the transform lands on `-1e-8`, and
|
|
112
|
+
// an exact test would reject colours that round to a perfectly valid byte.
|
|
113
|
+
const inGamut = linear.every((value) => value >= -0.0005 && value <= 1.0005);
|
|
114
|
+
return { r: channel(linear[0]), g: channel(linear[1]), b: channel(linear[2]), a: 1, inGamut };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The most chroma sRGB can show at this lightness and hue. */
|
|
118
|
+
export function maxChromaInGamut(lightness: number, hue: number): number {
|
|
119
|
+
let low = 0;
|
|
120
|
+
let high = 0.4;
|
|
121
|
+
for (let step = 0; step < 16; step += 1) {
|
|
122
|
+
const mid = (low + high) / 2;
|
|
123
|
+
if (oklchToRgb(lightness, mid, hue).inGamut) low = mid;
|
|
124
|
+
else high = mid;
|
|
125
|
+
}
|
|
126
|
+
return low;
|
|
127
|
+
}
|
|
128
|
+
|
|
79
129
|
/** WCAG relative luminance, used to order two palette colors light-to-dark. */
|
|
80
130
|
export function relativeLuminance(value: string): number {
|
|
81
131
|
const color = parseHexColor(value);
|