@labpics/colors 0.9.0 → 0.9.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 +282 -282
- package/adapt-theme.d.ts +74 -74
- package/adapt-theme.js +542 -542
- package/apply-theme.d.ts +16 -16
- package/apply-theme.js +44 -44
- package/effective-bg.d.ts +50 -50
- package/effective-bg.js +492 -492
- package/index.d.ts +37 -37
- package/index.js +21 -21
- package/package.json +16 -2
- package/pkg/labcolors.d.ts +17 -15
- package/pkg/labcolors.js +43 -41
- package/pkg/labcolors_bg.wasm +0 -0
- package/pkg/labcolors_bg.wasm.d.ts +1 -1
- package/watch-theme.d.ts +57 -57
- package/watch-theme.js +144 -144
package/index.d.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
// Public types for @labpics/colors.
|
|
2
|
-
//
|
|
3
|
-
// Re-exports the wasm-bindgen-generated types (the rich `ResolvedTheme` /
|
|
4
|
-
// `RoleResult` union and the `LabColors` engine) and the vanilla `applyTheme`
|
|
5
|
-
// helper, so a consumer gets full typing from the package root.
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
default,
|
|
9
|
-
default as init,
|
|
10
|
-
initSync,
|
|
11
|
-
LabColors,
|
|
12
|
-
} from "./pkg/labcolors.js";
|
|
13
|
-
|
|
14
|
-
export type {
|
|
15
|
-
ThemeName,
|
|
16
|
-
SolvedColor,
|
|
17
|
-
TranslucentRole,
|
|
18
|
-
NoneRole,
|
|
19
|
-
UnreachableRole,
|
|
20
|
-
RoleResult,
|
|
21
|
-
ResolvedTheme,
|
|
22
|
-
} from "./pkg/labcolors.js";
|
|
23
|
-
|
|
24
|
-
export { applyTheme } from "./apply-theme.js";
|
|
25
|
-
export { watchTheme } from "./watch-theme.js";
|
|
26
|
-
export type { WatchThemeOptions, WatchController } from "./watch-theme.js";
|
|
27
|
-
export { adaptTheme } from "./adapt-theme.js";
|
|
28
|
-
export type { AdaptThemeOptions, AdaptController } from "./adapt-theme.js";
|
|
29
|
-
export {
|
|
30
|
-
effectiveBackground,
|
|
31
|
-
parseCssColor,
|
|
32
|
-
compositeOver,
|
|
33
|
-
compositeStackToHex,
|
|
34
|
-
toHex,
|
|
35
|
-
oklabLerp,
|
|
36
|
-
} from "./effective-bg.js";
|
|
37
|
-
export type { Rgba, EffectiveBackgroundOptions, StyleLike } from "./effective-bg.js";
|
|
1
|
+
// Public types for @labpics/colors.
|
|
2
|
+
//
|
|
3
|
+
// Re-exports the wasm-bindgen-generated types (the rich `ResolvedTheme` /
|
|
4
|
+
// `RoleResult` union and the `LabColors` engine) and the vanilla `applyTheme`
|
|
5
|
+
// helper, so a consumer gets full typing from the package root.
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
default,
|
|
9
|
+
default as init,
|
|
10
|
+
initSync,
|
|
11
|
+
LabColors,
|
|
12
|
+
} from "./pkg/labcolors.js";
|
|
13
|
+
|
|
14
|
+
export type {
|
|
15
|
+
ThemeName,
|
|
16
|
+
SolvedColor,
|
|
17
|
+
TranslucentRole,
|
|
18
|
+
NoneRole,
|
|
19
|
+
UnreachableRole,
|
|
20
|
+
RoleResult,
|
|
21
|
+
ResolvedTheme,
|
|
22
|
+
} from "./pkg/labcolors.js";
|
|
23
|
+
|
|
24
|
+
export { applyTheme } from "./apply-theme.js";
|
|
25
|
+
export { watchTheme } from "./watch-theme.js";
|
|
26
|
+
export type { WatchThemeOptions, WatchController } from "./watch-theme.js";
|
|
27
|
+
export { adaptTheme } from "./adapt-theme.js";
|
|
28
|
+
export type { AdaptThemeOptions, AdaptController } from "./adapt-theme.js";
|
|
29
|
+
export {
|
|
30
|
+
effectiveBackground,
|
|
31
|
+
parseCssColor,
|
|
32
|
+
compositeOver,
|
|
33
|
+
compositeStackToHex,
|
|
34
|
+
toHex,
|
|
35
|
+
oklabLerp,
|
|
36
|
+
} from "./effective-bg.js";
|
|
37
|
+
export type { Rgba, EffectiveBackgroundOptions, StyleLike } from "./effective-bg.js";
|
package/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// Public entry for @labpics/colors.
|
|
2
|
-
//
|
|
3
|
-
// Re-exports the wasm-bindgen surface (the default `init` loader, `initSync`,
|
|
4
|
-
// and the `LabColors` engine class) plus the vanilla DOM runtime helpers:
|
|
5
|
-
// `applyTheme` (one-shot apply), `watchTheme` (reactive sync), and the
|
|
6
|
-
// effective-background resolver. The wasm glue is the generated `pkg/` artifact
|
|
7
|
-
// (built by `npm run build`).
|
|
8
|
-
|
|
9
|
-
export { default, default as init, initSync, LabColors } from "./pkg/labcolors.js";
|
|
10
|
-
|
|
11
|
-
export { applyTheme } from "./apply-theme.js";
|
|
12
|
-
export { watchTheme } from "./watch-theme.js";
|
|
13
|
-
export { adaptTheme } from "./adapt-theme.js";
|
|
14
|
-
export {
|
|
15
|
-
effectiveBackground,
|
|
16
|
-
parseCssColor,
|
|
17
|
-
compositeOver,
|
|
18
|
-
compositeStackToHex,
|
|
19
|
-
toHex,
|
|
20
|
-
oklabLerp,
|
|
21
|
-
} from "./effective-bg.js";
|
|
1
|
+
// Public entry for @labpics/colors.
|
|
2
|
+
//
|
|
3
|
+
// Re-exports the wasm-bindgen surface (the default `init` loader, `initSync`,
|
|
4
|
+
// and the `LabColors` engine class) plus the vanilla DOM runtime helpers:
|
|
5
|
+
// `applyTheme` (one-shot apply), `watchTheme` (reactive sync), and the
|
|
6
|
+
// effective-background resolver. The wasm glue is the generated `pkg/` artifact
|
|
7
|
+
// (built by `npm run build`).
|
|
8
|
+
|
|
9
|
+
export { default, default as init, initSync, LabColors } from "./pkg/labcolors.js";
|
|
10
|
+
|
|
11
|
+
export { applyTheme } from "./apply-theme.js";
|
|
12
|
+
export { watchTheme } from "./watch-theme.js";
|
|
13
|
+
export { adaptTheme } from "./adapt-theme.js";
|
|
14
|
+
export {
|
|
15
|
+
effectiveBackground,
|
|
16
|
+
parseCssColor,
|
|
17
|
+
compositeOver,
|
|
18
|
+
compositeStackToHex,
|
|
19
|
+
toHex,
|
|
20
|
+
oklabLerp,
|
|
21
|
+
} from "./effective-bg.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labpics/colors",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Framework-agnostic contrast engine: resolve accessible, perceptually-anchored colour roles for any background. WASM core, zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,5 +63,19 @@
|
|
|
63
63
|
"typescript": "^5.5.0"
|
|
64
64
|
},
|
|
65
65
|
"types": "./index.d.ts",
|
|
66
|
-
"sideEffects": false
|
|
66
|
+
"sideEffects": false,
|
|
67
|
+
"keywords": [
|
|
68
|
+
"color",
|
|
69
|
+
"oklch",
|
|
70
|
+
"contrast",
|
|
71
|
+
"apca",
|
|
72
|
+
"wcag",
|
|
73
|
+
"theme",
|
|
74
|
+
"design-tokens",
|
|
75
|
+
"wasm",
|
|
76
|
+
"labpics"
|
|
77
|
+
],
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">=18"
|
|
80
|
+
}
|
|
67
81
|
}
|
package/pkg/labcolors.d.ts
CHANGED
|
@@ -204,6 +204,22 @@ export interface ResolvedTheme {
|
|
|
204
204
|
export class LabColors {
|
|
205
205
|
free(): void;
|
|
206
206
|
[Symbol.dispose](): void;
|
|
207
|
+
/**
|
|
208
|
+
* PROTOTYPE — NOT part of the public API (unlisted, `_`-prefixed; may change
|
|
209
|
+
* or be removed without notice). Recheck one foreground set against MANY
|
|
210
|
+
* background samples in a single call. The reactive controller's worst-case
|
|
211
|
+
* loop rechecks the same foregrounds against every sample of a varying
|
|
212
|
+
* backdrop; the dominant per-foreground CAM16 forward is background-
|
|
213
|
+
* independent, so this shares it across all samples instead of recomputing it
|
|
214
|
+
* per `recheckContrast` call.
|
|
215
|
+
*
|
|
216
|
+
* Returns a flat, background-major `Float64Array`: sample `s`, foreground `i`
|
|
217
|
+
* is at `(s * fgHexes.length + i) * 2` (`lc`) and `+1` (`wcagRatio`). The
|
|
218
|
+
* values are byte-identical to calling `recheckContrast(bgHexes[s], fgHexes,
|
|
219
|
+
* theme)` for each `s`. Wiring the runtime to it is an OWNER decision (it
|
|
220
|
+
* changes the controller↔engine call shape); it is measured, not adopted.
|
|
221
|
+
*/
|
|
222
|
+
_recheckContrastMulti(bg_hexes: string[], fg_hexes: string[], theme: string): Float64Array;
|
|
207
223
|
/**
|
|
208
224
|
* Загрузить конфиг дизайн-системы (JSON по типу `ThemeConfig` из `.d.ts`).
|
|
209
225
|
*
|
|
@@ -240,20 +256,6 @@ export class LabColors {
|
|
|
240
256
|
* an unknown theme.
|
|
241
257
|
*/
|
|
242
258
|
recheckContrast(bg_hex: string, fg_hexes: string[], theme: string): Float64Array;
|
|
243
|
-
/**
|
|
244
|
-
* Recheck one foreground set against MANY background samples in a single
|
|
245
|
-
* call. The reactive controller's worst-case loop rechecks the same
|
|
246
|
-
* foregrounds against every sample of a varying backdrop (gradient / image /
|
|
247
|
-
* bg-blur / glass); the dominant per-foreground CAM16 forward is background-
|
|
248
|
-
* independent, so this shares it across all samples instead of recomputing it
|
|
249
|
-
* per `recheckContrast` call — a measured ~2.6x on the multi-sample recheck.
|
|
250
|
-
*
|
|
251
|
-
* Returns a flat, background-major `Float64Array`: sample `s`, foreground `i`
|
|
252
|
-
* is at `(s * fgHexes.length + i) * 2` (`lc`) and `+1` (`wcagRatio`). The
|
|
253
|
-
* values are byte-identical to calling `recheckContrast(bgHexes[s], fgHexes,
|
|
254
|
-
* theme)` for each `s`.
|
|
255
|
-
*/
|
|
256
|
-
recheckContrastMulti(bg_hexes: string[], fg_hexes: string[], theme: string): Float64Array;
|
|
257
259
|
/**
|
|
258
260
|
* Resolve every role for `bgHex` under `theme` (`"light" | "dark" |
|
|
259
261
|
* "light-ic" | "dark-ic"`).
|
|
@@ -273,11 +275,11 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
273
275
|
export interface InitOutput {
|
|
274
276
|
readonly memory: WebAssembly.Memory;
|
|
275
277
|
readonly __wbg_labcolors_free: (a: number, b: number) => void;
|
|
278
|
+
readonly labcolors__recheckContrastMulti: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
276
279
|
readonly labcolors_loadConfig: (a: number, b: number, c: number, d: number) => void;
|
|
277
280
|
readonly labcolors_muddiness: (a: number, b: number, c: number, d: number) => void;
|
|
278
281
|
readonly labcolors_new: () => number;
|
|
279
282
|
readonly labcolors_recheckContrast: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
280
|
-
readonly labcolors_recheckContrastMulti: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
281
283
|
readonly labcolors_resolveTheme: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
282
284
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
283
285
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
package/pkg/labcolors.js
CHANGED
|
@@ -17,6 +17,49 @@ export class LabColors {
|
|
|
17
17
|
const ptr = this.__destroy_into_raw();
|
|
18
18
|
wasm.__wbg_labcolors_free(ptr, 0);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* PROTOTYPE — NOT part of the public API (unlisted, `_`-prefixed; may change
|
|
22
|
+
* or be removed without notice). Recheck one foreground set against MANY
|
|
23
|
+
* background samples in a single call. The reactive controller's worst-case
|
|
24
|
+
* loop rechecks the same foregrounds against every sample of a varying
|
|
25
|
+
* backdrop; the dominant per-foreground CAM16 forward is background-
|
|
26
|
+
* independent, so this shares it across all samples instead of recomputing it
|
|
27
|
+
* per `recheckContrast` call.
|
|
28
|
+
*
|
|
29
|
+
* Returns a flat, background-major `Float64Array`: sample `s`, foreground `i`
|
|
30
|
+
* is at `(s * fgHexes.length + i) * 2` (`lc`) and `+1` (`wcagRatio`). The
|
|
31
|
+
* values are byte-identical to calling `recheckContrast(bgHexes[s], fgHexes,
|
|
32
|
+
* theme)` for each `s`. Wiring the runtime to it is an OWNER decision (it
|
|
33
|
+
* changes the controller↔engine call shape); it is measured, not adopted.
|
|
34
|
+
* @param {string[]} bg_hexes
|
|
35
|
+
* @param {string[]} fg_hexes
|
|
36
|
+
* @param {string} theme
|
|
37
|
+
* @returns {Float64Array}
|
|
38
|
+
*/
|
|
39
|
+
_recheckContrastMulti(bg_hexes, fg_hexes, theme) {
|
|
40
|
+
try {
|
|
41
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
42
|
+
const ptr0 = passArrayJsValueToWasm0(bg_hexes, wasm.__wbindgen_export);
|
|
43
|
+
const len0 = WASM_VECTOR_LEN;
|
|
44
|
+
const ptr1 = passArrayJsValueToWasm0(fg_hexes, wasm.__wbindgen_export);
|
|
45
|
+
const len1 = WASM_VECTOR_LEN;
|
|
46
|
+
const ptr2 = passStringToWasm0(theme, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
47
|
+
const len2 = WASM_VECTOR_LEN;
|
|
48
|
+
wasm.labcolors__recheckContrastMulti(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
49
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
50
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
51
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
52
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
53
|
+
if (r3) {
|
|
54
|
+
throw takeObject(r2);
|
|
55
|
+
}
|
|
56
|
+
var v4 = getArrayF64FromWasm0(r0, r1).slice();
|
|
57
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
58
|
+
return v4;
|
|
59
|
+
} finally {
|
|
60
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
20
63
|
/**
|
|
21
64
|
* Загрузить конфиг дизайн-системы (JSON по типу `ThemeConfig` из `.d.ts`).
|
|
22
65
|
*
|
|
@@ -130,47 +173,6 @@ export class LabColors {
|
|
|
130
173
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
131
174
|
}
|
|
132
175
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Recheck one foreground set against MANY background samples in a single
|
|
135
|
-
* call. The reactive controller's worst-case loop rechecks the same
|
|
136
|
-
* foregrounds against every sample of a varying backdrop (gradient / image /
|
|
137
|
-
* bg-blur / glass); the dominant per-foreground CAM16 forward is background-
|
|
138
|
-
* independent, so this shares it across all samples instead of recomputing it
|
|
139
|
-
* per `recheckContrast` call — a measured ~2.6x on the multi-sample recheck.
|
|
140
|
-
*
|
|
141
|
-
* Returns a flat, background-major `Float64Array`: sample `s`, foreground `i`
|
|
142
|
-
* is at `(s * fgHexes.length + i) * 2` (`lc`) and `+1` (`wcagRatio`). The
|
|
143
|
-
* values are byte-identical to calling `recheckContrast(bgHexes[s], fgHexes,
|
|
144
|
-
* theme)` for each `s`.
|
|
145
|
-
* @param {string[]} bg_hexes
|
|
146
|
-
* @param {string[]} fg_hexes
|
|
147
|
-
* @param {string} theme
|
|
148
|
-
* @returns {Float64Array}
|
|
149
|
-
*/
|
|
150
|
-
recheckContrastMulti(bg_hexes, fg_hexes, theme) {
|
|
151
|
-
try {
|
|
152
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
153
|
-
const ptr0 = passArrayJsValueToWasm0(bg_hexes, wasm.__wbindgen_export);
|
|
154
|
-
const len0 = WASM_VECTOR_LEN;
|
|
155
|
-
const ptr1 = passArrayJsValueToWasm0(fg_hexes, wasm.__wbindgen_export);
|
|
156
|
-
const len1 = WASM_VECTOR_LEN;
|
|
157
|
-
const ptr2 = passStringToWasm0(theme, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
158
|
-
const len2 = WASM_VECTOR_LEN;
|
|
159
|
-
wasm.labcolors_recheckContrastMulti(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
160
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
161
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
162
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
163
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
164
|
-
if (r3) {
|
|
165
|
-
throw takeObject(r2);
|
|
166
|
-
}
|
|
167
|
-
var v4 = getArrayF64FromWasm0(r0, r1).slice();
|
|
168
|
-
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
169
|
-
return v4;
|
|
170
|
-
} finally {
|
|
171
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
176
|
/**
|
|
175
177
|
* Resolve every role for `bgHex` under `theme` (`"light" | "dark" |
|
|
176
178
|
* "light-ic" | "dark-ic"`).
|
package/pkg/labcolors_bg.wasm
CHANGED
|
Binary file
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_labcolors_free: (a: number, b: number) => void;
|
|
5
|
+
export const labcolors__recheckContrastMulti: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
5
6
|
export const labcolors_loadConfig: (a: number, b: number, c: number, d: number) => void;
|
|
6
7
|
export const labcolors_muddiness: (a: number, b: number, c: number, d: number) => void;
|
|
7
8
|
export const labcolors_new: () => number;
|
|
8
9
|
export const labcolors_recheckContrast: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
9
|
-
export const labcolors_recheckContrastMulti: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
10
10
|
export const labcolors_resolveTheme: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
11
11
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
12
12
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
package/watch-theme.d.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
// Public types for the reactive theme runtime.
|
|
2
|
-
|
|
3
|
-
import type { LabColors, ResolvedTheme, ThemeName } from "./pkg/labcolors.js";
|
|
4
|
-
|
|
5
|
-
export interface WatchThemeOptions {
|
|
6
|
-
/** An initialised `LabColors` engine (after `await init()`). */
|
|
7
|
-
colors: Pick<LabColors, "resolveTheme">;
|
|
8
|
-
/** Theme name. */
|
|
9
|
-
theme: ThemeName;
|
|
10
|
-
/**
|
|
11
|
-
* Explicit effective background, overriding the ancestor-composite. Use a hex
|
|
12
|
-
* string or a `() => hex` you sample yourself for image/gradient/blur surfaces
|
|
13
|
-
* that have no single readable `background-color`.
|
|
14
|
-
*/
|
|
15
|
-
background?: string | (() => string);
|
|
16
|
-
/** Element to write the `--lab-*` variables onto. Defaults to the watched element. */
|
|
17
|
-
target?: HTMLElement;
|
|
18
|
-
/** Base colour when the ancestor chain is fully translucent. Default `"#FFFFFF"`. */
|
|
19
|
-
fallback?: string;
|
|
20
|
-
/** Auto-refresh on DOM attribute mutations. Default `true`. */
|
|
21
|
-
observe?: boolean;
|
|
22
|
-
/** Mutation-observer root. Defaults to the document element. */
|
|
23
|
-
root?: Node;
|
|
24
|
-
/** Window-like host (for `MutationObserver`). Defaults to `globalThis`. */
|
|
25
|
-
win?: Window;
|
|
26
|
-
/** Injection seam for the computed style of an element (testing). */
|
|
27
|
-
getStyle?: (element: unknown) => { getPropertyValue(property: string): string };
|
|
28
|
-
/** Injection seam for an element's parent (testing). */
|
|
29
|
-
parentOf?: (element: unknown) => unknown;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface WatchController {
|
|
33
|
-
/**
|
|
34
|
-
* Re-resolve and re-apply if the effective background (or theme) changed;
|
|
35
|
-
* `force` re-applies unconditionally. Returns the now-applied result, or the
|
|
36
|
-
* cached one when nothing changed.
|
|
37
|
-
*/
|
|
38
|
-
refresh(force?: boolean): ResolvedTheme | null;
|
|
39
|
-
/** Switch theme and re-apply. */
|
|
40
|
-
setTheme(theme: ThemeName): void;
|
|
41
|
-
/** The effective background hex last resolved. */
|
|
42
|
-
background(): string;
|
|
43
|
-
/** Disconnect observers and stop watching. */
|
|
44
|
-
stop(): void;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Keep an element's `--lab-*` variables in sync with its (effective) background.
|
|
49
|
-
*
|
|
50
|
-
* Discrete background/theme changes are caught by a `MutationObserver`;
|
|
51
|
-
* continuous (animated) backgrounds are driven by calling `refresh()` from a
|
|
52
|
-
* `requestAnimationFrame` loop (cheap — re-resolves only on real change).
|
|
53
|
-
*/
|
|
54
|
-
export declare function watchTheme(
|
|
55
|
-
element: HTMLElement,
|
|
56
|
-
options: WatchThemeOptions,
|
|
57
|
-
): WatchController;
|
|
1
|
+
// Public types for the reactive theme runtime.
|
|
2
|
+
|
|
3
|
+
import type { LabColors, ResolvedTheme, ThemeName } from "./pkg/labcolors.js";
|
|
4
|
+
|
|
5
|
+
export interface WatchThemeOptions {
|
|
6
|
+
/** An initialised `LabColors` engine (after `await init()`). */
|
|
7
|
+
colors: Pick<LabColors, "resolveTheme">;
|
|
8
|
+
/** Theme name. */
|
|
9
|
+
theme: ThemeName;
|
|
10
|
+
/**
|
|
11
|
+
* Explicit effective background, overriding the ancestor-composite. Use a hex
|
|
12
|
+
* string or a `() => hex` you sample yourself for image/gradient/blur surfaces
|
|
13
|
+
* that have no single readable `background-color`.
|
|
14
|
+
*/
|
|
15
|
+
background?: string | (() => string);
|
|
16
|
+
/** Element to write the `--lab-*` variables onto. Defaults to the watched element. */
|
|
17
|
+
target?: HTMLElement;
|
|
18
|
+
/** Base colour when the ancestor chain is fully translucent. Default `"#FFFFFF"`. */
|
|
19
|
+
fallback?: string;
|
|
20
|
+
/** Auto-refresh on DOM attribute mutations. Default `true`. */
|
|
21
|
+
observe?: boolean;
|
|
22
|
+
/** Mutation-observer root. Defaults to the document element. */
|
|
23
|
+
root?: Node;
|
|
24
|
+
/** Window-like host (for `MutationObserver`). Defaults to `globalThis`. */
|
|
25
|
+
win?: Window;
|
|
26
|
+
/** Injection seam for the computed style of an element (testing). */
|
|
27
|
+
getStyle?: (element: unknown) => { getPropertyValue(property: string): string };
|
|
28
|
+
/** Injection seam for an element's parent (testing). */
|
|
29
|
+
parentOf?: (element: unknown) => unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface WatchController {
|
|
33
|
+
/**
|
|
34
|
+
* Re-resolve and re-apply if the effective background (or theme) changed;
|
|
35
|
+
* `force` re-applies unconditionally. Returns the now-applied result, or the
|
|
36
|
+
* cached one when nothing changed.
|
|
37
|
+
*/
|
|
38
|
+
refresh(force?: boolean): ResolvedTheme | null;
|
|
39
|
+
/** Switch theme and re-apply. */
|
|
40
|
+
setTheme(theme: ThemeName): void;
|
|
41
|
+
/** The effective background hex last resolved. */
|
|
42
|
+
background(): string;
|
|
43
|
+
/** Disconnect observers and stop watching. */
|
|
44
|
+
stop(): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Keep an element's `--lab-*` variables in sync with its (effective) background.
|
|
49
|
+
*
|
|
50
|
+
* Discrete background/theme changes are caught by a `MutationObserver`;
|
|
51
|
+
* continuous (animated) backgrounds are driven by calling `refresh()` from a
|
|
52
|
+
* `requestAnimationFrame` loop (cheap — re-resolves only on real change).
|
|
53
|
+
*/
|
|
54
|
+
export declare function watchTheme(
|
|
55
|
+
element: HTMLElement,
|
|
56
|
+
options: WatchThemeOptions,
|
|
57
|
+
): WatchController;
|