@tooee/themes 0.16.1 → 0.16.3
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/dist/color-mix.d.ts +9 -0
- package/dist/color-mix.d.ts.map +1 -1
- package/dist/color-mix.js +3 -2
- package/dist/color-mix.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/separation.d.ts +38 -0
- package/dist/separation.d.ts.map +1 -0
- package/dist/separation.js +146 -0
- package/dist/separation.js.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +17 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/src/color-mix.ts +4 -3
- package/src/index.ts +1 -1
- package/src/separation.ts +217 -0
- package/src/types.ts +26 -1
- package/themes/lucent-orng.json +12 -4
package/dist/color-mix.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
export interface Rgba {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
}
|
|
7
|
+
/** Parse 3, 4, 6, or 8 digit hex into 0-255 channels, or `null` when it is not hex. */
|
|
8
|
+
export declare const parseHex: (hex: string) => Rgba | null;
|
|
9
|
+
export declare const toRgbHex: (source: Rgba) => string;
|
|
1
10
|
/**
|
|
2
11
|
* Blend `amount` (0 to 1) of `tint` over `base`.
|
|
3
12
|
*
|
package/dist/color-mix.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-mix.d.ts","sourceRoot":"","sources":["../src/color-mix.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"color-mix.d.ts","sourceRoot":"","sources":["../src/color-mix.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAMD,uFAAuF;AACvF,eAAO,MAAM,QAAQ,QAA0B,MAAM,KAAG,IAAI,GAAG,IAgB9D,CAAC;AAMF,eAAO,MAAM,QAAQ,WAA6B,IAAI,KAAG,MAExD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,SAA4B,MAAM,QAAQ,MAAM,UAAU,MAAM,KAAG,MAkBxF,CAAC"}
|
package/dist/color-mix.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Hex colour blending for derived theme tokens.
|
|
2
2
|
const SHORT_HEX = /^#(?<digits>[0-9a-f]{3,4})$/iu;
|
|
3
3
|
const LONG_HEX = /^#(?<digits>[0-9a-f]{6}|[0-9a-f]{8})$/iu;
|
|
4
|
-
|
|
4
|
+
/** Parse 3, 4, 6, or 8 digit hex into 0-255 channels, or `null` when it is not hex. */
|
|
5
|
+
export const parseHex = function parseHex(hex) {
|
|
5
6
|
const short = SHORT_HEX.exec(hex)?.groups?.digits;
|
|
6
7
|
const digits = short === undefined
|
|
7
8
|
? LONG_HEX.exec(hex)?.groups?.digits
|
|
@@ -15,7 +16,7 @@ const parseHex = function parseHex(hex) {
|
|
|
15
16
|
const toHex = function toHex(value) {
|
|
16
17
|
return Math.round(value).toString(16).padStart(2, "0");
|
|
17
18
|
};
|
|
18
|
-
const toRgbHex = function toRgbHex(source) {
|
|
19
|
+
export const toRgbHex = function toRgbHex(source) {
|
|
19
20
|
return `#${toHex(source.r)}${toHex(source.g)}${toHex(source.b)}`;
|
|
20
21
|
};
|
|
21
22
|
/**
|
package/dist/color-mix.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-mix.js","sourceRoot":"","sources":["../src/color-mix.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAShD,MAAM,SAAS,GAAG,+BAA+B,CAAC;AAElD,MAAM,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AACL,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { FALLBACKS, RESOLVED_KEYS, resolveTheme } from "./types.js";
|
|
1
|
+
export { FALLBACKS, MIN_SURFACE_SEPARATION, RESOLVED_KEYS, resolveTheme } from "./types.js";
|
|
2
2
|
export type { ThemeJSON, ResolvedTheme } from "./types.js";
|
|
3
3
|
export { buildSyntaxStyle } from "./syntax-rules.js";
|
|
4
4
|
export { loadThemes, getThemeNames, defaultTheme } from "./loader.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5F,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEtE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhG,YAAY,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { FALLBACKS, RESOLVED_KEYS, resolveTheme } from "./types.js";
|
|
1
|
+
export { FALLBACKS, MIN_SURFACE_SEPARATION, RESOLVED_KEYS, resolveTheme } from "./types.js";
|
|
2
2
|
export { buildSyntaxStyle } from "./syntax-rules.js";
|
|
3
3
|
export { loadThemes, getThemeNames, defaultTheme } from "./loader.js";
|
|
4
4
|
export { ThemeProvider, ThemeSwitcherProvider, useTheme, useThemeSwitcher } from "./context.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAItE,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ΔEOK between two opaque hex colours, or `null` when either is translucent or
|
|
3
|
+
* cannot be parsed.
|
|
4
|
+
*/
|
|
5
|
+
export declare const deltaEOK: (x: string, y: string) => number | null;
|
|
6
|
+
export type Side = 1 | -1;
|
|
7
|
+
/**
|
|
8
|
+
* The side of `base` that `highlight` is on: 1 for lighter, -1 for darker, or
|
|
9
|
+
* `null` when they share a lightness or either is translucent.
|
|
10
|
+
*/
|
|
11
|
+
export declare const lightnessSide: (highlight: string, base: string) => Side | null;
|
|
12
|
+
/**
|
|
13
|
+
* Return `highlight`, moved in Oklab lightness only as far as needed to sit at
|
|
14
|
+
* least `minDelta` ΔEOK from `base`.
|
|
15
|
+
*
|
|
16
|
+
* A highlight that is already far enough away is returned unchanged. Otherwise
|
|
17
|
+
* it moves to the `prefer` side of the base. Without `prefer`, a highlight that
|
|
18
|
+
* is lighter or darker than its base keeps that side, and one at the base's
|
|
19
|
+
* lightness becomes lighter on a dark base and darker on a light base. When
|
|
20
|
+
* that side runs out of gamut the other side is tried. Translucent or
|
|
21
|
+
* unparsable colours are returned unchanged.
|
|
22
|
+
*/
|
|
23
|
+
export declare const separateFrom: (highlight: string, base: string, minDelta: number, prefer?: Side | null) => string;
|
|
24
|
+
export interface SurfaceStack {
|
|
25
|
+
background: string;
|
|
26
|
+
backgroundPanel: string;
|
|
27
|
+
backgroundElement: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Keep panels apart from the page and elements apart from panels.
|
|
31
|
+
*
|
|
32
|
+
* The element keeps the side of the panel the theme put it on. An element that
|
|
33
|
+
* equals the panel starts from the moved panel. When the theme gives it no side, it follows the panel's final step away from the page, so an
|
|
34
|
+
* active row stays lighter than its panel on a theme whose panels are lighter
|
|
35
|
+
* than the page.
|
|
36
|
+
*/
|
|
37
|
+
export declare const separateSurfaces: (surfaces: SurfaceStack, minDelta: number) => SurfaceStack;
|
|
38
|
+
//# sourceMappingURL=separation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"separation.d.ts","sourceRoot":"","sources":["../src/separation.ts"],"names":[],"mappings":"AA6EA;;;GAGG;AACH,eAAO,MAAM,QAAQ,MAAwB,MAAM,KAAK,MAAM,KAAG,MAAM,GAAG,IAKzE,CAAC;AAkCF,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1B;;;GAGG;AACH,eAAO,MAAM,aAAa,cAAqC,MAAM,QAAQ,MAAM,KAAG,IAAI,GAAG,IAe5F,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,cACZ,MAAM,QACX,MAAM,YACF,MAAM,WACP,IAAI,GAAG,IAAI,KACnB,MAsBF,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,aACjB,YAAY,YACZ,MAAM,KACf,YAgBF,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Keep highlight surfaces visibly apart from the surface they sit on.
|
|
2
|
+
//
|
|
3
|
+
// Distances are ΔEOK: Euclidean distance in Oklab (Björn Ottosson, 2020,
|
|
4
|
+
// https://bottosson.github.io/posts/oklab/). About 0.02 is one just-noticeable
|
|
5
|
+
// difference.
|
|
6
|
+
import { parseHex, toRgbHex } from "./color-mix.js";
|
|
7
|
+
/** Extra lightness added per retry when gamut clipping eats into the target distance. */
|
|
8
|
+
const LIGHTNESS_STEP = 0.004;
|
|
9
|
+
/** Retries per direction before trying the other direction. */
|
|
10
|
+
const MAX_STEPS = 40;
|
|
11
|
+
/** Below this lightness gap the highlight has no direction of its own. */
|
|
12
|
+
const SAME_LIGHTNESS = 0.005;
|
|
13
|
+
const toLinear = function toLinear(channel) {
|
|
14
|
+
const c = channel / 255;
|
|
15
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
16
|
+
};
|
|
17
|
+
const fromLinear = function fromLinear(value) {
|
|
18
|
+
const c = Math.min(1, Math.max(0, value));
|
|
19
|
+
return 255 * (c <= 0.0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
20
|
+
};
|
|
21
|
+
const toOklab = function toOklab(color) {
|
|
22
|
+
const r = toLinear(color.r);
|
|
23
|
+
const g = toLinear(color.g);
|
|
24
|
+
const b = toLinear(color.b);
|
|
25
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
26
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
27
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
28
|
+
return {
|
|
29
|
+
L: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
30
|
+
a: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
31
|
+
b: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/** Convert Oklab to opaque 8-bit sRGB, clipping each channel to the sRGB gamut. */
|
|
35
|
+
const fromOklab = function fromOklab(color) {
|
|
36
|
+
const l = (color.L + 0.3963377774 * color.a + 0.2158037573 * color.b) ** 3;
|
|
37
|
+
const m = (color.L - 0.1055613458 * color.a - 0.0638541728 * color.b) ** 3;
|
|
38
|
+
const s = (color.L - 0.0894841775 * color.a - 1.291485548 * color.b) ** 3;
|
|
39
|
+
return {
|
|
40
|
+
a: 255,
|
|
41
|
+
b: fromLinear(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),
|
|
42
|
+
g: fromLinear(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
43
|
+
r: fromLinear(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const distance = function distance(x, y) {
|
|
47
|
+
return Math.hypot(x.L - y.L, x.a - y.a, x.b - y.b);
|
|
48
|
+
};
|
|
49
|
+
/** Opaque colours only: alpha blending makes the rendered distance unknown here. */
|
|
50
|
+
const parseOpaque = function parseOpaque(hex) {
|
|
51
|
+
const color = parseHex(hex);
|
|
52
|
+
return color !== null && color.a === 255 ? color : null;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* ΔEOK between two opaque hex colours, or `null` when either is translucent or
|
|
56
|
+
* cannot be parsed.
|
|
57
|
+
*/
|
|
58
|
+
export const deltaEOK = function deltaEOK(x, y) {
|
|
59
|
+
const from = parseOpaque(x);
|
|
60
|
+
const to = parseOpaque(y);
|
|
61
|
+
return from === null || to === null ? null : distance(toOklab(from), toOklab(to));
|
|
62
|
+
};
|
|
63
|
+
/** Move `highlight` to lightness `lightness`, keeping its Oklab a and b (hue and chroma). */
|
|
64
|
+
const withLightness = function withLightness(highlight, lightness) {
|
|
65
|
+
return toRgbHex(fromOklab({ ...highlight, L: lightness }));
|
|
66
|
+
};
|
|
67
|
+
const searchDirection = function searchDirection(highlight, base, minDelta, direction) {
|
|
68
|
+
const hueGap = Math.hypot(highlight.a - base.a, highlight.b - base.b);
|
|
69
|
+
const lightnessGap = Math.sqrt(Math.max(0, minDelta ** 2 - hueGap ** 2));
|
|
70
|
+
for (let step = 0; step <= MAX_STEPS; step += 1) {
|
|
71
|
+
const lightness = base.L + direction * (lightnessGap + step * LIGHTNESS_STEP);
|
|
72
|
+
if (lightness < 0 || lightness > 1) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const candidate = withLightness(highlight, lightness);
|
|
76
|
+
const rendered = parseOpaque(candidate);
|
|
77
|
+
if (rendered !== null && distance(toOklab(rendered), base) >= minDelta) {
|
|
78
|
+
return candidate;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* The side of `base` that `highlight` is on: 1 for lighter, -1 for darker, or
|
|
85
|
+
* `null` when they share a lightness or either is translucent.
|
|
86
|
+
*/
|
|
87
|
+
export const lightnessSide = function lightnessSide(highlight, base) {
|
|
88
|
+
const from = parseOpaque(highlight);
|
|
89
|
+
const to = parseOpaque(base);
|
|
90
|
+
if (from === null || to === null) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const gap = toOklab(from).L - toOklab(to).L;
|
|
94
|
+
if (Math.abs(gap) < SAME_LIGHTNESS) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return gap > 0 ? 1 : -1;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Return `highlight`, moved in Oklab lightness only as far as needed to sit at
|
|
101
|
+
* least `minDelta` ΔEOK from `base`.
|
|
102
|
+
*
|
|
103
|
+
* A highlight that is already far enough away is returned unchanged. Otherwise
|
|
104
|
+
* it moves to the `prefer` side of the base. Without `prefer`, a highlight that
|
|
105
|
+
* is lighter or darker than its base keeps that side, and one at the base's
|
|
106
|
+
* lightness becomes lighter on a dark base and darker on a light base. When
|
|
107
|
+
* that side runs out of gamut the other side is tried. Translucent or
|
|
108
|
+
* unparsable colours are returned unchanged.
|
|
109
|
+
*/
|
|
110
|
+
export const separateFrom = function separateFrom(highlight, base, minDelta, prefer) {
|
|
111
|
+
const highlightRgb = parseOpaque(highlight);
|
|
112
|
+
const baseRgb = parseOpaque(base);
|
|
113
|
+
if (highlightRgb === null || baseRgb === null) {
|
|
114
|
+
return highlight;
|
|
115
|
+
}
|
|
116
|
+
const from = toOklab(highlightRgb);
|
|
117
|
+
const to = toOklab(baseRgb);
|
|
118
|
+
if (distance(from, to) >= minDelta) {
|
|
119
|
+
return highlight;
|
|
120
|
+
}
|
|
121
|
+
const side = prefer ?? lightnessSide(highlight, base) ?? (to.L < 0.5 ? 1 : -1);
|
|
122
|
+
return (searchDirection(from, to, minDelta, side) ??
|
|
123
|
+
searchDirection(from, to, minDelta, side === 1 ? -1 : 1) ??
|
|
124
|
+
highlight);
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Keep panels apart from the page and elements apart from panels.
|
|
128
|
+
*
|
|
129
|
+
* The element keeps the side of the panel the theme put it on. An element that
|
|
130
|
+
* equals the panel starts from the moved panel. When the theme gives it no side, it follows the panel's final step away from the page, so an
|
|
131
|
+
* active row stays lighter than its panel on a theme whose panels are lighter
|
|
132
|
+
* than the page.
|
|
133
|
+
*/
|
|
134
|
+
export const separateSurfaces = function separateSurfaces(surfaces, minDelta) {
|
|
135
|
+
const { background, backgroundElement, backgroundPanel } = surfaces;
|
|
136
|
+
const panel = separateFrom(backgroundPanel, background, minDelta);
|
|
137
|
+
const elementSide = lightnessSide(backgroundElement, backgroundPanel) ?? lightnessSide(panel, background);
|
|
138
|
+
// A theme that reuses the panel colour for elements means "the panel, one step on".
|
|
139
|
+
const element = backgroundElement.toLowerCase() === backgroundPanel.toLowerCase() ? panel : backgroundElement;
|
|
140
|
+
return {
|
|
141
|
+
background,
|
|
142
|
+
backgroundElement: separateFrom(element, panel, minDelta, elementSide),
|
|
143
|
+
backgroundPanel: panel,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=separation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"separation.js","sourceRoot":"","sources":["../src/separation.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,yEAAyE;AACzE,+EAA+E;AAC/E,cAAc;AAEd,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AASpD,yFAAyF;AACzF,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,+DAA+D;AAC/D,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,0EAA0E;AAC1E,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,QAAQ,GAAG,SAAS,QAAQ,CAAC,OAAe;IAChD,MAAM,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC;IAExB,OAAO,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,SAAS,UAAU,CAAC,KAAa;IAClD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAE1C,OAAO,GAAG,GAAG,CAAC,CAAC,I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,eAAe,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC;IAEhG,OAAO;QACL,UAAU;QACV,iBAAiB,EAAE,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC;QACtE,eAAe,EAAE,KAAK;KACvB,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -130,6 +130,11 @@ export declare const FALLBACKS: {
|
|
|
130
130
|
warning: string;
|
|
131
131
|
};
|
|
132
132
|
export declare const RESOLVED_KEYS: (keyof ResolvedTheme)[];
|
|
133
|
+
/**
|
|
134
|
+
* Minimum ΔEOK between a highlight surface and the surface it sits on. About
|
|
135
|
+
* 0.02 is one just-noticeable difference.
|
|
136
|
+
*/
|
|
137
|
+
export declare const MIN_SURFACE_SEPARATION = 0.05;
|
|
133
138
|
export declare const resolveTheme: (json: ThemeJSON, mode: ColorMode) => ResolvedTheme;
|
|
134
139
|
export {};
|
|
135
140
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAS/C,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,KAAK,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnC,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,KAAK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EAAE,MAAM,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAE1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAElB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iDAAiD;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,oBAAoB,EAAE,MAAM,CAAC;IAE7B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAGD,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDyB,CAAC;AAEhD,eAAO,MAAM,aAAa,EAGE,CAAC,MAAM,aAAa,CAAC,EAAE,CAAC;AAepD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAO3C,eAAO,MAAM,YAAY,SAA+B,SAAS,QAAQ,SAAS,KAAG,aAwFpF,CAAC"}
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mixColors } from "./color-mix.js";
|
|
2
|
+
import { lightnessSide, separateFrom, separateSurfaces } from "./separation.js";
|
|
2
3
|
// Fallbacks used when a theme key is missing: a complete theme in its own right.
|
|
3
4
|
export const FALLBACKS = {
|
|
4
5
|
accent: "#808080",
|
|
@@ -69,6 +70,13 @@ Object.keys(FALLBACKS);
|
|
|
69
70
|
const SEARCH_MATCH_TINT = 0.22;
|
|
70
71
|
/** Share of `primary` blended over `background` for a derived `searchCurrentMatchBg`. */
|
|
71
72
|
const SEARCH_CURRENT_MATCH_TINT = 0.35;
|
|
73
|
+
/** Share of `primary` blended over `background` for a derived `selection`. */
|
|
74
|
+
const SELECTION_TINT = 0.2;
|
|
75
|
+
/**
|
|
76
|
+
* Minimum ΔEOK between a highlight surface and the surface it sits on. About
|
|
77
|
+
* 0.02 is one just-noticeable difference.
|
|
78
|
+
*/
|
|
79
|
+
export const MIN_SURFACE_SEPARATION = 0.05;
|
|
72
80
|
/** A mode-specific colour pair is an object; a single colour is a string. */
|
|
73
81
|
const isVariant = function isVariant(value) {
|
|
74
82
|
return value instanceof Object;
|
|
@@ -104,13 +112,21 @@ export const resolveTheme = function resolveTheme(json, mode) {
|
|
|
104
112
|
result[key] = resolveColor(val);
|
|
105
113
|
}
|
|
106
114
|
}
|
|
115
|
+
// Panels sit on the page and active rows sit on panels: keep each step visible.
|
|
116
|
+
Object.assign(result, separateSurfaces(result, MIN_SURFACE_SEPARATION));
|
|
107
117
|
// Dynamic fallbacks that reference other resolved keys
|
|
108
118
|
if (json.theme.cursorLine === undefined) {
|
|
109
119
|
result.cursorLine = result.backgroundElement;
|
|
110
120
|
}
|
|
121
|
+
// A tinted selection stays apart from panels and toggled rows, which use backgroundPanel.
|
|
111
122
|
if (json.theme.selection === undefined) {
|
|
112
|
-
result.selection = result.
|
|
123
|
+
result.selection = mixColors(result.background, result.primary, SELECTION_TINT);
|
|
113
124
|
}
|
|
125
|
+
// Selection and cursor rows sit on the page. A selection also stays apart from
|
|
126
|
+
// toggled rows, moving further from the page when it must move.
|
|
127
|
+
result.selection = separateFrom(result.selection, result.background, MIN_SURFACE_SEPARATION);
|
|
128
|
+
result.selection = separateFrom(result.selection, result.backgroundPanel, MIN_SURFACE_SEPARATION, lightnessSide(result.selection, result.background));
|
|
129
|
+
result.cursorLine = separateFrom(result.cursorLine, result.background, MIN_SURFACE_SEPARATION);
|
|
114
130
|
// Search highlights tint the background, so matched text stays readable.
|
|
115
131
|
if (json.theme.searchMatchBg === undefined) {
|
|
116
132
|
result.searchMatchBg = mixColors(result.background, result.warning, SEARCH_MATCH_TINT);
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA4FhF,iFAAiF;AACjF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,SAAS;IACrB,iBAAiB,EAAE,SAAS;IAC5B,eAAe,EAAE,SAAS;IAC1B,MAAM,EAAE,SAAS;IACjB,YAAY,EAAE,SAAS;IACvB,YAAY,EAAE,SAAS;IACvB,UAAU,EAAE,SAAS;IACrB,SAAS,EAAE,SAAS;IACpB,WAAW,EAAE,SAAS;IACtB,qBAAqB,EAAE,SAAS;IAChC,WAAW,EAAE,SAAS;IACtB,aAAa,EAAE,SAAS;IACxB,kBAAkB,EAAE,SAAS;IAC7B,oBAAoB,EAAE,SAAS;IAC/B,cAAc,EAAE,SAAS;IACzB,cAAc,EAAE,SAAS;IACzB,WAAW,EAAE,SAAS;IACtB,aAAa,EAAE,SAAS;IACxB,uBAAuB,EAAE,SAAS;IAClC,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,kBAAkB,EAAE,SAAS;IAC7B,YAAY,EAAE,SAAS;IACvB,iBAAiB,EAAE,SAAS;IAC5B,YAAY,EAAE,SAAS;IACvB,eAAe,EAAE,SAAS;IAC1B,sBAAsB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MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACzF,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,oBAAoB,KAAK,SAAS,EAAE,CAAC;QAClD,MAAM,CAAC,oBAAoB,GAAG,SAAS,CACrC,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,OAAO,EACd,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC;IACxC,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,oBAAoB,KAAK,SAAS,EAAE,CAAC;QAClD,MAAM,CAAC,oBAAoB,GAAG,MAAM,CAAC,OAAO,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tooee/themes",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"description": "Theme management with 34 bundled themes for Tooee",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"typecheck": "tsc --noEmit"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tooee/config": "0.16.
|
|
43
|
+
"@tooee/config": "0.16.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@opentui/core": "^0.6.6",
|
package/src/color-mix.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Hex colour blending for derived theme tokens.
|
|
2
2
|
|
|
3
|
-
interface Rgba {
|
|
3
|
+
export interface Rgba {
|
|
4
4
|
r: number;
|
|
5
5
|
g: number;
|
|
6
6
|
b: number;
|
|
@@ -11,7 +11,8 @@ const SHORT_HEX = /^#(?<digits>[0-9a-f]{3,4})$/iu;
|
|
|
11
11
|
|
|
12
12
|
const LONG_HEX = /^#(?<digits>[0-9a-f]{6}|[0-9a-f]{8})$/iu;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/** Parse 3, 4, 6, or 8 digit hex into 0-255 channels, or `null` when it is not hex. */
|
|
15
|
+
export const parseHex = function parseHex(hex: string): Rgba | null {
|
|
15
16
|
const short = SHORT_HEX.exec(hex)?.groups?.digits;
|
|
16
17
|
|
|
17
18
|
const digits =
|
|
@@ -33,7 +34,7 @@ const toHex = function toHex(value: number): string {
|
|
|
33
34
|
return Math.round(value).toString(16).padStart(2, "0");
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
const toRgbHex = function toRgbHex(source: Rgba): string {
|
|
37
|
+
export const toRgbHex = function toRgbHex(source: Rgba): string {
|
|
37
38
|
return `#${toHex(source.r)}${toHex(source.g)}${toHex(source.b)}`;
|
|
38
39
|
};
|
|
39
40
|
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// Keep highlight surfaces visibly apart from the surface they sit on.
|
|
2
|
+
//
|
|
3
|
+
// Distances are ΔEOK: Euclidean distance in Oklab (Björn Ottosson, 2020,
|
|
4
|
+
// https://bottosson.github.io/posts/oklab/). About 0.02 is one just-noticeable
|
|
5
|
+
// difference.
|
|
6
|
+
|
|
7
|
+
import { parseHex, toRgbHex } from "./color-mix.js";
|
|
8
|
+
import type { Rgba } from "./color-mix.js";
|
|
9
|
+
|
|
10
|
+
interface Oklab {
|
|
11
|
+
L: number;
|
|
12
|
+
a: number;
|
|
13
|
+
b: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Extra lightness added per retry when gamut clipping eats into the target distance. */
|
|
17
|
+
const LIGHTNESS_STEP = 0.004;
|
|
18
|
+
|
|
19
|
+
/** Retries per direction before trying the other direction. */
|
|
20
|
+
const MAX_STEPS = 40;
|
|
21
|
+
|
|
22
|
+
/** Below this lightness gap the highlight has no direction of its own. */
|
|
23
|
+
const SAME_LIGHTNESS = 0.005;
|
|
24
|
+
|
|
25
|
+
const toLinear = function toLinear(channel: number): number {
|
|
26
|
+
const c = channel / 255;
|
|
27
|
+
|
|
28
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const fromLinear = function fromLinear(value: number): number {
|
|
32
|
+
const c = Math.min(1, Math.max(0, value));
|
|
33
|
+
|
|
34
|
+
return 255 * (c <= 0.0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const toOklab = function toOklab(color: Rgba): Oklab {
|
|
38
|
+
const r = toLinear(color.r);
|
|
39
|
+
const g = toLinear(color.g);
|
|
40
|
+
const b = toLinear(color.b);
|
|
41
|
+
|
|
42
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
43
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
44
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
L: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
48
|
+
a: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
49
|
+
b: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Convert Oklab to opaque 8-bit sRGB, clipping each channel to the sRGB gamut. */
|
|
54
|
+
const fromOklab = function fromOklab(color: Oklab): Rgba {
|
|
55
|
+
const l = (color.L + 0.3963377774 * color.a + 0.2158037573 * color.b) ** 3;
|
|
56
|
+
const m = (color.L - 0.1055613458 * color.a - 0.0638541728 * color.b) ** 3;
|
|
57
|
+
const s = (color.L - 0.0894841775 * color.a - 1.291485548 * color.b) ** 3;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
a: 255,
|
|
61
|
+
b: fromLinear(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),
|
|
62
|
+
g: fromLinear(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
63
|
+
r: fromLinear(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const distance = function distance(x: Oklab, y: Oklab): number {
|
|
68
|
+
return Math.hypot(x.L - y.L, x.a - y.a, x.b - y.b);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** Opaque colours only: alpha blending makes the rendered distance unknown here. */
|
|
72
|
+
const parseOpaque = function parseOpaque(hex: string): Rgba | null {
|
|
73
|
+
const color = parseHex(hex);
|
|
74
|
+
|
|
75
|
+
return color !== null && color.a === 255 ? color : null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* ΔEOK between two opaque hex colours, or `null` when either is translucent or
|
|
80
|
+
* cannot be parsed.
|
|
81
|
+
*/
|
|
82
|
+
export const deltaEOK = function deltaEOK(x: string, y: string): number | null {
|
|
83
|
+
const from = parseOpaque(x);
|
|
84
|
+
const to = parseOpaque(y);
|
|
85
|
+
|
|
86
|
+
return from === null || to === null ? null : distance(toOklab(from), toOklab(to));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Move `highlight` to lightness `lightness`, keeping its Oklab a and b (hue and chroma). */
|
|
90
|
+
const withLightness = function withLightness(highlight: Oklab, lightness: number): string {
|
|
91
|
+
return toRgbHex(fromOklab({ ...highlight, L: lightness }));
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const searchDirection = function searchDirection(
|
|
95
|
+
highlight: Oklab,
|
|
96
|
+
base: Oklab,
|
|
97
|
+
minDelta: number,
|
|
98
|
+
direction: 1 | -1
|
|
99
|
+
): string | null {
|
|
100
|
+
const hueGap = Math.hypot(highlight.a - base.a, highlight.b - base.b);
|
|
101
|
+
const lightnessGap = Math.sqrt(Math.max(0, minDelta ** 2 - hueGap ** 2));
|
|
102
|
+
|
|
103
|
+
for (let step = 0; step <= MAX_STEPS; step += 1) {
|
|
104
|
+
const lightness = base.L + direction * (lightnessGap + step * LIGHTNESS_STEP);
|
|
105
|
+
|
|
106
|
+
if (lightness < 0 || lightness > 1) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const candidate = withLightness(highlight, lightness);
|
|
111
|
+
const rendered = parseOpaque(candidate);
|
|
112
|
+
|
|
113
|
+
if (rendered !== null && distance(toOklab(rendered), base) >= minDelta) {
|
|
114
|
+
return candidate;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return null;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type Side = 1 | -1;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The side of `base` that `highlight` is on: 1 for lighter, -1 for darker, or
|
|
125
|
+
* `null` when they share a lightness or either is translucent.
|
|
126
|
+
*/
|
|
127
|
+
export const lightnessSide = function lightnessSide(highlight: string, base: string): Side | null {
|
|
128
|
+
const from = parseOpaque(highlight);
|
|
129
|
+
const to = parseOpaque(base);
|
|
130
|
+
|
|
131
|
+
if (from === null || to === null) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const gap = toOklab(from).L - toOklab(to).L;
|
|
136
|
+
|
|
137
|
+
if (Math.abs(gap) < SAME_LIGHTNESS) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return gap > 0 ? 1 : -1;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Return `highlight`, moved in Oklab lightness only as far as needed to sit at
|
|
146
|
+
* least `minDelta` ΔEOK from `base`.
|
|
147
|
+
*
|
|
148
|
+
* A highlight that is already far enough away is returned unchanged. Otherwise
|
|
149
|
+
* it moves to the `prefer` side of the base. Without `prefer`, a highlight that
|
|
150
|
+
* is lighter or darker than its base keeps that side, and one at the base's
|
|
151
|
+
* lightness becomes lighter on a dark base and darker on a light base. When
|
|
152
|
+
* that side runs out of gamut the other side is tried. Translucent or
|
|
153
|
+
* unparsable colours are returned unchanged.
|
|
154
|
+
*/
|
|
155
|
+
export const separateFrom = function separateFrom(
|
|
156
|
+
highlight: string,
|
|
157
|
+
base: string,
|
|
158
|
+
minDelta: number,
|
|
159
|
+
prefer?: Side | null
|
|
160
|
+
): string {
|
|
161
|
+
const highlightRgb = parseOpaque(highlight);
|
|
162
|
+
const baseRgb = parseOpaque(base);
|
|
163
|
+
|
|
164
|
+
if (highlightRgb === null || baseRgb === null) {
|
|
165
|
+
return highlight;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const from = toOklab(highlightRgb);
|
|
169
|
+
const to = toOklab(baseRgb);
|
|
170
|
+
|
|
171
|
+
if (distance(from, to) >= minDelta) {
|
|
172
|
+
return highlight;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const side: Side = prefer ?? lightnessSide(highlight, base) ?? (to.L < 0.5 ? 1 : -1);
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
searchDirection(from, to, minDelta, side) ??
|
|
179
|
+
searchDirection(from, to, minDelta, side === 1 ? -1 : 1) ??
|
|
180
|
+
highlight
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export interface SurfaceStack {
|
|
185
|
+
background: string;
|
|
186
|
+
backgroundPanel: string;
|
|
187
|
+
backgroundElement: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Keep panels apart from the page and elements apart from panels.
|
|
192
|
+
*
|
|
193
|
+
* The element keeps the side of the panel the theme put it on. An element that
|
|
194
|
+
* equals the panel starts from the moved panel. When the theme gives it no side, it follows the panel's final step away from the page, so an
|
|
195
|
+
* active row stays lighter than its panel on a theme whose panels are lighter
|
|
196
|
+
* than the page.
|
|
197
|
+
*/
|
|
198
|
+
export const separateSurfaces = function separateSurfaces(
|
|
199
|
+
surfaces: SurfaceStack,
|
|
200
|
+
minDelta: number
|
|
201
|
+
): SurfaceStack {
|
|
202
|
+
const { background, backgroundElement, backgroundPanel } = surfaces;
|
|
203
|
+
const panel = separateFrom(backgroundPanel, background, minDelta);
|
|
204
|
+
|
|
205
|
+
const elementSide =
|
|
206
|
+
lightnessSide(backgroundElement, backgroundPanel) ?? lightnessSide(panel, background);
|
|
207
|
+
|
|
208
|
+
// A theme that reuses the panel colour for elements means "the panel, one step on".
|
|
209
|
+
const element =
|
|
210
|
+
backgroundElement.toLowerCase() === backgroundPanel.toLowerCase() ? panel : backgroundElement;
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
background,
|
|
214
|
+
backgroundElement: separateFrom(element, panel, minDelta, elementSide),
|
|
215
|
+
backgroundPanel: panel,
|
|
216
|
+
};
|
|
217
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ColorMode } from "@tooee/config";
|
|
2
2
|
|
|
3
3
|
import { mixColors } from "./color-mix.js";
|
|
4
|
+
import { lightnessSide, separateFrom, separateSurfaces } from "./separation.js";
|
|
4
5
|
|
|
5
6
|
// ---------------------------------------------------------------------------
|
|
6
7
|
// Theme JSON format (OpenCode-compatible)
|
|
@@ -167,6 +168,15 @@ const SEARCH_MATCH_TINT = 0.22;
|
|
|
167
168
|
/** Share of `primary` blended over `background` for a derived `searchCurrentMatchBg`. */
|
|
168
169
|
const SEARCH_CURRENT_MATCH_TINT = 0.35;
|
|
169
170
|
|
|
171
|
+
/** Share of `primary` blended over `background` for a derived `selection`. */
|
|
172
|
+
const SELECTION_TINT = 0.2;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Minimum ΔEOK between a highlight surface and the surface it sits on. About
|
|
176
|
+
* 0.02 is one just-noticeable difference.
|
|
177
|
+
*/
|
|
178
|
+
export const MIN_SURFACE_SEPARATION = 0.05;
|
|
179
|
+
|
|
170
180
|
/** A mode-specific colour pair is an object; a single colour is a string. */
|
|
171
181
|
const isVariant = function isVariant(value: ColorValue): value is Variant {
|
|
172
182
|
return value instanceof Object;
|
|
@@ -214,15 +224,30 @@ export const resolveTheme = function resolveTheme(json: ThemeJSON, mode: ColorMo
|
|
|
214
224
|
}
|
|
215
225
|
}
|
|
216
226
|
|
|
227
|
+
// Panels sit on the page and active rows sit on panels: keep each step visible.
|
|
228
|
+
Object.assign(result, separateSurfaces(result, MIN_SURFACE_SEPARATION));
|
|
229
|
+
|
|
217
230
|
// Dynamic fallbacks that reference other resolved keys
|
|
218
231
|
if (json.theme.cursorLine === undefined) {
|
|
219
232
|
result.cursorLine = result.backgroundElement;
|
|
220
233
|
}
|
|
221
234
|
|
|
235
|
+
// A tinted selection stays apart from panels and toggled rows, which use backgroundPanel.
|
|
222
236
|
if (json.theme.selection === undefined) {
|
|
223
|
-
result.selection = result.
|
|
237
|
+
result.selection = mixColors(result.background, result.primary, SELECTION_TINT);
|
|
224
238
|
}
|
|
225
239
|
|
|
240
|
+
// Selection and cursor rows sit on the page. A selection also stays apart from
|
|
241
|
+
// toggled rows, moving further from the page when it must move.
|
|
242
|
+
result.selection = separateFrom(result.selection, result.background, MIN_SURFACE_SEPARATION);
|
|
243
|
+
result.selection = separateFrom(
|
|
244
|
+
result.selection,
|
|
245
|
+
result.backgroundPanel,
|
|
246
|
+
MIN_SURFACE_SEPARATION,
|
|
247
|
+
lightnessSide(result.selection, result.background)
|
|
248
|
+
);
|
|
249
|
+
result.cursorLine = separateFrom(result.cursorLine, result.background, MIN_SURFACE_SEPARATION);
|
|
250
|
+
|
|
226
251
|
// Search highlights tint the background, so matched text stays readable.
|
|
227
252
|
if (json.theme.searchMatchBg === undefined) {
|
|
228
253
|
result.searchMatchBg = mixColors(result.background, result.warning, SEARCH_MATCH_TINT);
|
package/themes/lucent-orng.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://opencode.ai/theme.json",
|
|
3
3
|
"defs": {
|
|
4
|
+
"darkStep2": "#141414",
|
|
5
|
+
"darkStep3": "#1e1e1e",
|
|
4
6
|
"darkStep6": "#3c3c3c",
|
|
5
7
|
"darkStep11": "#808080",
|
|
6
8
|
"darkStep12": "#eeeeee",
|
|
@@ -11,6 +13,8 @@
|
|
|
11
13
|
"darkBlue": "#6ba1e6",
|
|
12
14
|
"darkCyan": "#56b6c2",
|
|
13
15
|
"darkYellow": "#e5c07b",
|
|
16
|
+
"lightStep2": "#FFF7F1",
|
|
17
|
+
"lightStep3": "#f5f0eb",
|
|
14
18
|
"lightStep6": "#d4d4d4",
|
|
15
19
|
"lightStep11": "#8a8a8a",
|
|
16
20
|
"lightStep12": "#1a1a1a",
|
|
@@ -64,12 +68,12 @@
|
|
|
64
68
|
"light": "transparent"
|
|
65
69
|
},
|
|
66
70
|
"backgroundPanel": {
|
|
67
|
-
"dark": "
|
|
68
|
-
"light": "
|
|
71
|
+
"dark": "darkStep2",
|
|
72
|
+
"light": "lightStep2"
|
|
69
73
|
},
|
|
70
74
|
"backgroundElement": {
|
|
71
|
-
"dark": "
|
|
72
|
-
"light": "
|
|
75
|
+
"dark": "darkStep3",
|
|
76
|
+
"light": "lightStep3"
|
|
73
77
|
},
|
|
74
78
|
"border": {
|
|
75
79
|
"dark": "darkOrange",
|
|
@@ -223,6 +227,10 @@
|
|
|
223
227
|
"dark": "darkStep12",
|
|
224
228
|
"light": "lightStep12"
|
|
225
229
|
},
|
|
230
|
+
"cursorLine": {
|
|
231
|
+
"dark": "#eeeeee1f",
|
|
232
|
+
"light": "#1a1a1a1a"
|
|
233
|
+
},
|
|
226
234
|
"searchMatchBg": "#ec5b2b38",
|
|
227
235
|
"searchCurrentMatchBg": "#ec5b2b59",
|
|
228
236
|
"searchMatchFg": "warning",
|