@labpics/colors 0.3.0 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labpics/colors",
3
- "version": "0.3.0",
3
+ "version": "0.4.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",
@@ -33,7 +33,9 @@
33
33
  "./effective-bg": {
34
34
  "types": "./effective-bg.d.ts",
35
35
  "default": "./effective-bg.js"
36
- }
36
+ },
37
+ "./pkg/labcolors_bg.wasm": "./pkg/labcolors_bg.wasm",
38
+ "./package.json": "./package.json"
37
39
  },
38
40
  "files": [
39
41
  "index.js",
@@ -9,8 +9,10 @@ export interface SolvedColor {
9
9
  readonly kind: "color";
10
10
  /** The CSS custom-property name for this role, e.g. "--lab-label-primary". */
11
11
  readonly cssVar: string;
12
- /** The resolved colour as #RRGGBB. */
12
+ /** The resolved colour as #RRGGBB (data; `css`/`vars` carry oklch). */
13
13
  readonly hex: string;
14
+ /** Ready-to-serve CSS value: "oklch(L% C H)". `vars` carries the same string. */
15
+ readonly css: string;
14
16
  /** Signed perceptual contrast (Lc) against the background. */
15
17
  readonly lc: number;
16
18
  /** WCAG 2.1 ratio (1–21) against the background. */
@@ -44,11 +46,11 @@ export interface UnreachableRole {
44
46
  readonly message: string;
45
47
  }
46
48
 
47
- /** A semi-transparent ladder / alpha-analog emission: the CSS carries rgba(), the browser composites it. */
48
- export interface RgbaRole {
49
- readonly kind: "rgba";
49
+ /** A semi-transparent ladder / alpha-analog emission: the CSS carries oklch(L% C H / A), the browser composites it. */
50
+ export interface TranslucentRole {
51
+ readonly kind: "translucent";
50
52
  readonly cssVar: string;
51
- /** The tint as #RRGGBB — the colour the rgba() carries. */
53
+ /** The tint as #RRGGBB (data) — the colour the oklch(… / A) carries. */
52
54
  readonly tintHex: string;
53
55
  /** The alpha of the emission, (0, 1]. */
54
56
  readonly alpha: number;
@@ -58,11 +60,11 @@ export interface RgbaRole {
58
60
  readonly compositeLc: number;
59
61
  /** WCAG 2.1 ratio of the composite. */
60
62
  readonly compositeWcag: number;
61
- /** Ready-to-serve CSS value: "rgb(R G B / A)". `vars` carries the same string. */
63
+ /** Ready-to-serve CSS value: "oklch(L% C H / A)". `vars` carries the same string. */
62
64
  readonly css: string;
63
65
  }
64
66
 
65
- export type RoleResult = SolvedColor | RgbaRole | NoneRole | UnreachableRole;
67
+ export type RoleResult = SolvedColor | TranslucentRole | NoneRole | UnreachableRole;
66
68
 
67
69
  /** Пер-темная четвёрка якорных hex (light / dark / light-ic / dark-ic). */
68
70
  export interface ThemeAnchors {
@@ -123,9 +125,15 @@ export interface ResolvedTheme {
123
125
  readonly theme: ThemeName;
124
126
  readonly background: string;
125
127
  /**
126
- * Reachable roles only. Values are ready-to-serve CSS: "#RRGGBB" for solid
127
- * roles, "rgb(R G B / A)" for semi-transparent ladder/alpha-analog roles —
128
- * do not validate them as hex.
128
+ * Reachable roles only. Values are ready-to-serve CSS in ONE form:
129
+ * "oklch(L% C H)" for solid roles, "oklch(L% C H / A)" for semi-transparent
130
+ * ladder/alpha-analog roles. Solved in the sRGB gamut (oklch is the
131
+ * notation, not a gamut extension); byte-exact vs `SolvedColor.hex` and
132
+ * `TranslucentRole.tintHex` (`compositeHex` is the background-specific
133
+ * composite, not the emitted token).
134
+ * Scope: this is resolveTheme's contract (applyTheme/watchTheme inject it
135
+ * verbatim); adaptTheme's per-frame easing writes concrete interpolated
136
+ * colours and is not bound by the emission form.
129
137
  */
130
138
  readonly vars: Record<string, string>;
131
139
  /** Every role, keyed by its stable role key (without the --lab- prefix). */
@@ -192,8 +200,10 @@ export class LabColors {
192
200
  *
193
201
  * Returns a [`ResolvedTheme`] object. Per-role unreachability is part of a
194
202
  * successful result (each role carries its own `kind`); only whole-call
195
- * failures (invalid hex, unknown theme) reject — as a
196
- * structured `{ code, message }` error, never an unwound panic.
203
+ * failures reject (invalid hex, unknown theme, and the
204
+ * by-construction-unreachable oklch serialisation failure as
205
+ * `internal_error`) — as a structured `"<code>: <message>"` error,
206
+ * never an unwound panic.
197
207
  */
198
208
  resolveTheme(bg_hex: string, theme: string): ResolvedTheme;
199
209
  }
package/pkg/labcolors.js CHANGED
@@ -161,8 +161,10 @@ export class LabColors {
161
161
  *
162
162
  * Returns a [`ResolvedTheme`] object. Per-role unreachability is part of a
163
163
  * successful result (each role carries its own `kind`); only whole-call
164
- * failures (invalid hex, unknown theme) reject — as a
165
- * structured `{ code, message }` error, never an unwound panic.
164
+ * failures reject (invalid hex, unknown theme, and the
165
+ * by-construction-unreachable oklch serialisation failure as
166
+ * `internal_error`) — as a structured `"<code>: <message>"` error,
167
+ * never an unwound panic.
166
168
  * @param {string} bg_hex
167
169
  * @param {string} theme
168
170
  * @returns {ResolvedTheme}
Binary file