@fusion.dev/helix-theme 0.111.1 → 0.112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DerivedTheme, Oklch, ThemeIntent } from './types.js';
|
|
2
|
-
export type { Color, DerivedTheme, DerivedToken, Oklch, Pairing, PairingRequest, Relation, Seed, StatusSeed, ThemeIntent, } from './types.js';
|
|
1
|
+
import type { DerivedModes, DerivedTheme, Oklch, ThemeIntent } from './types.js';
|
|
2
|
+
export type { Color, DerivedModes, DerivedTheme, DerivedToken, Oklch, Pairing, PairingRequest, Relation, Seed, StatusSeed, ThemeIntent, } from './types.js';
|
|
3
3
|
/** A loaded engine. */
|
|
4
4
|
export interface ThemeEngine {
|
|
5
5
|
/**
|
|
@@ -11,6 +11,18 @@ export interface ThemeEngine {
|
|
|
11
11
|
* outside the range it is meaningful in.
|
|
12
12
|
*/
|
|
13
13
|
derive(intent: ThemeIntent, selectors?: readonly string[]): DerivedTheme;
|
|
14
|
+
/**
|
|
15
|
+
* Derives a theme in both modes, and renders them as one block under each
|
|
16
|
+
* selector asked for, every color a `light-dark()` pair, which is how the
|
|
17
|
+
* shipped stylesheet writes its tokens. The intent's `scheme` is set aside.
|
|
18
|
+
*
|
|
19
|
+
* For a site with both modes, which otherwise derived twice and merged the
|
|
20
|
+
* blocks by hand. Each mode's theme comes back too, so a finding in either is
|
|
21
|
+
* still read.
|
|
22
|
+
*
|
|
23
|
+
* @throws when the engine refuses the intent in either mode.
|
|
24
|
+
*/
|
|
25
|
+
deriveModes(intent: ThemeIntent, selectors?: readonly string[]): DerivedModes;
|
|
14
26
|
/**
|
|
15
27
|
* Reads a hex color into its OKLCH components.
|
|
16
28
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import initWasm, { derive, hexToOklch as readHex } from '../wasm/fusion_helix_theme.js';
|
|
1
|
+
import initWasm, { derive, deriveModes, hexToOklch as readHex } from '../wasm/fusion_helix_theme.js';
|
|
2
2
|
let loading;
|
|
3
3
|
export function initTheme(source) {
|
|
4
4
|
loading ??= initWasm({ module_or_path: source }).then(() => ({
|
|
5
5
|
derive: (intent, selectors = []) => JSON.parse(derive(JSON.stringify(intent), JSON.stringify(selectors))),
|
|
6
|
+
deriveModes: (intent, selectors = []) => JSON.parse(deriveModes(JSON.stringify(intent), JSON.stringify(selectors))),
|
|
6
7
|
hexToOklch: (hex) => JSON.parse(readHex(hex)),
|
|
7
8
|
}));
|
|
8
9
|
return loading;
|
package/dist/types.d.ts
CHANGED
|
@@ -108,9 +108,14 @@ export interface ThemeIntent {
|
|
|
108
108
|
scale?: number;
|
|
109
109
|
};
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
112
|
-
* Accessibility Act points at WCAG 2.1 AA, so 4.5 is the figure with
|
|
113
|
-
* weight and is the default.
|
|
111
|
+
* The least contrast any text may have. 4.5 is WCAG AA, 7 is AAA. The
|
|
112
|
+
* European Accessibility Act points at WCAG 2.1 AA, so 4.5 is the figure with
|
|
113
|
+
* legal weight and is the default.
|
|
114
|
+
*
|
|
115
|
+
* A floor, which the muted ink is solved to and every other text ink is
|
|
116
|
+
* measured against. Body text, `color-foreground`, is the strongest ink the
|
|
117
|
+
* neutral has whatever the target: black on a light page and white on a dark
|
|
118
|
+
* one, as the shipped stylesheet writes it.
|
|
114
119
|
*/
|
|
115
120
|
contrastTarget?: number;
|
|
116
121
|
/**
|
|
@@ -299,6 +304,20 @@ export interface ThemeIntent {
|
|
|
299
304
|
*/
|
|
300
305
|
tokens?: Record<string, Color>;
|
|
301
306
|
}
|
|
307
|
+
/** One intent derived in both modes, from `deriveModes`. */
|
|
308
|
+
export interface DerivedModes {
|
|
309
|
+
/**
|
|
310
|
+
* One block per selector asked for, each color a `light-dark()` pair. A
|
|
311
|
+
* value that is not a color and differs by mode, such as a floating
|
|
312
|
+
* surface's edge, is set by the rules after the block, for the operating
|
|
313
|
+
* system's dark mode and for `[data-color-mode]` on or inside the selector.
|
|
314
|
+
*/
|
|
315
|
+
css: Record<string, string>;
|
|
316
|
+
/** The dark theme, with its own findings. Its `css` is empty. */
|
|
317
|
+
dark: DerivedTheme;
|
|
318
|
+
/** The light theme, with its own findings. Its `css` is empty. */
|
|
319
|
+
light: DerivedTheme;
|
|
320
|
+
}
|
|
302
321
|
/** A derived token, carrying the check that produced it. */
|
|
303
322
|
export interface DerivedToken {
|
|
304
323
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion.dev/helix-theme",
|
|
3
3
|
"description": "Theme derivation engine. Computes a complete, contrast-guaranteed token set from intent inputs.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.112.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ross Sheppard <ross.sheppard@fusion.dev>",
|
|
7
7
|
"repository": {
|
|
@@ -21,6 +21,21 @@
|
|
|
21
21
|
*/
|
|
22
22
|
export function derive(intent: string, selectors: string): string;
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Derives a theme in both modes, and renders them as one block under every
|
|
26
|
+
* selector asked for, each color a `light-dark()` pair.
|
|
27
|
+
*
|
|
28
|
+
* The intent's own `scheme` is set aside, since both are derived. The result
|
|
29
|
+
* carries each mode's report, `light` and `dark`, so a finding in either is
|
|
30
|
+
* still read, and `css` keyed by selector.
|
|
31
|
+
*
|
|
32
|
+
* # Errors
|
|
33
|
+
*
|
|
34
|
+
* When either argument is not the JSON it should be, or when the engine refuses
|
|
35
|
+
* the intent in either mode.
|
|
36
|
+
*/
|
|
37
|
+
export function deriveModes(intent: string, selectors: string): string;
|
|
38
|
+
|
|
24
39
|
/**
|
|
25
40
|
* Reads a hex color into its OKLCH components, as JSON.
|
|
26
41
|
*
|
|
@@ -40,6 +55,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
40
55
|
export interface InitOutput {
|
|
41
56
|
readonly memory: WebAssembly.Memory;
|
|
42
57
|
readonly derive: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
58
|
+
readonly deriveModes: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
43
59
|
readonly hexToOklch: (a: number, b: number) => [number, number, number, number];
|
|
44
60
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
45
61
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
@@ -44,6 +44,45 @@ export function derive(intent, selectors) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Derives a theme in both modes, and renders them as one block under every
|
|
49
|
+
* selector asked for, each color a `light-dark()` pair.
|
|
50
|
+
*
|
|
51
|
+
* The intent's own `scheme` is set aside, since both are derived. The result
|
|
52
|
+
* carries each mode's report, `light` and `dark`, so a finding in either is
|
|
53
|
+
* still read, and `css` keyed by selector.
|
|
54
|
+
*
|
|
55
|
+
* # Errors
|
|
56
|
+
*
|
|
57
|
+
* When either argument is not the JSON it should be, or when the engine refuses
|
|
58
|
+
* the intent in either mode.
|
|
59
|
+
* @param {string} intent
|
|
60
|
+
* @param {string} selectors
|
|
61
|
+
* @returns {string}
|
|
62
|
+
*/
|
|
63
|
+
export function deriveModes(intent, selectors) {
|
|
64
|
+
let deferred4_0;
|
|
65
|
+
let deferred4_1;
|
|
66
|
+
try {
|
|
67
|
+
const ptr0 = passStringToWasm0(intent, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
68
|
+
const len0 = WASM_VECTOR_LEN;
|
|
69
|
+
const ptr1 = passStringToWasm0(selectors, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
70
|
+
const len1 = WASM_VECTOR_LEN;
|
|
71
|
+
const ret = wasm.deriveModes(ptr0, len0, ptr1, len1);
|
|
72
|
+
var ptr3 = ret[0];
|
|
73
|
+
var len3 = ret[1];
|
|
74
|
+
if (ret[3]) {
|
|
75
|
+
ptr3 = 0; len3 = 0;
|
|
76
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
77
|
+
}
|
|
78
|
+
deferred4_0 = ptr3;
|
|
79
|
+
deferred4_1 = len3;
|
|
80
|
+
return getStringFromWasm0(ptr3, len3);
|
|
81
|
+
} finally {
|
|
82
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
47
86
|
/**
|
|
48
87
|
* Reads a hex color into its OKLCH components, as JSON.
|
|
49
88
|
*
|
|
Binary file
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const derive: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
5
|
+
export const deriveModes: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
5
6
|
export const hexToOklch: (a: number, b: number) => [number, number, number, number];
|
|
6
7
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
8
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|