@labpics/colors 0.10.0 → 1.0.2
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/LICENSE +1 -1
- package/LICENSES/CC-BY-4.0.txt +396 -0
- package/LICENSES/CC-BY-SA-4.0.txt +428 -0
- package/NOTICE.md +65 -0
- package/README.md +303 -333
- package/build-metadata.json +16 -12
- package/evidence/point-support-reference-surplus-q55-bps-proof-v1.json +1 -0
- package/evidence/wcag22-srgb8-q55-proof-v1.json +1 -0
- package/evidence/wcag22-srgb8-q55-v1.bin +0 -0
- package/evidence/wcag22-srgb8-v1.json +1 -0
- package/index.d.ts +204 -63
- package/index.js +495 -17
- package/package.json +32 -34
- package/pkg/labcolors.d.ts +227 -491
- package/pkg/labcolors.js +943 -177
- package/pkg/labcolors_bg.wasm +0 -0
- package/pkg/labcolors_bg.wasm.d.ts +61 -12
- package/pkg/snippets/labcolors-wasm-9fb8b927594c3d6f/inline0.js +98 -0
- package/program-wire/abi-v1.d.ts +84 -0
- package/program-wire/abi-v1.js +332 -0
- package/program-wire/abi-v2.d.ts +17 -0
- package/program-wire/abi-v2.js +61 -0
- package/program-wire/encoding.js +218 -0
- package/wcag22.d.ts +6 -0
- package/adapt-theme.d.ts +0 -76
- package/adapt-theme.js +0 -738
- package/apply-theme.d.ts +0 -16
- package/apply-theme.js +0 -45
- package/effective-bg.d.ts +0 -51
- package/effective-bg.js +0 -501
- package/watch-theme.d.ts +0 -57
- package/watch-theme.js +0 -144
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Shared canonical scalar encoding for the two supported Program envelopes.
|
|
2
|
+
// Каноническая wire-грамматика авторского Draft-графа Program (v1) — JS-зеркало
|
|
3
|
+
// Rust-модуля crates/labcolors-core/src/program/wire.rs. Одни байты — одна
|
|
4
|
+
// декларация: заголовок LCPW + u16 version + u32 total_len, секции строго в
|
|
5
|
+
// порядке полей CoreProgramDraftV1, LE-скаляры, opacity как f64-bits.
|
|
6
|
+
//
|
|
7
|
+
// Слой 1 двухслойного контракта: байты <-> декларации. Семантику графа
|
|
8
|
+
// проверяет Rust-компилятор Program; этот модуль не выражает семантических
|
|
9
|
+
// отказов и не изобретает fallback.
|
|
10
|
+
|
|
11
|
+
export const PROGRAM_WIRE_MAGIC_V1 = Object.freeze([0x4c, 0x43, 0x50, 0x57]); // LCPW
|
|
12
|
+
export const PROGRAM_WIRE_VERSION_V1 = 1;
|
|
13
|
+
export const MAX_SECTION_ENTRIES_V1 = 4096;
|
|
14
|
+
|
|
15
|
+
export const SECTION_ORDER_V1 = Object.freeze([
|
|
16
|
+
"sources",
|
|
17
|
+
"targets",
|
|
18
|
+
"families",
|
|
19
|
+
"jointSelection",
|
|
20
|
+
"surfaceInputPorts",
|
|
21
|
+
"opacityInputs",
|
|
22
|
+
"paints",
|
|
23
|
+
"surfaces",
|
|
24
|
+
"occurrences",
|
|
25
|
+
"presentationRoots",
|
|
26
|
+
"presentationTargets",
|
|
27
|
+
"hardConstraints",
|
|
28
|
+
"reportConstraints",
|
|
29
|
+
"outputs",
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
export const KIND_EXACT_VISIBLE_UNARY = 1;
|
|
33
|
+
export const KIND_EXACT_INTRINSIC_RELATION = 4;
|
|
34
|
+
export const KIND_WCAG22_VISIBLE_UNARY = 9;
|
|
35
|
+
export const KIND_CLEAN_SET = 10;
|
|
36
|
+
|
|
37
|
+
export const SURROUND_AVERAGE_V1 = 1;
|
|
38
|
+
export const SURROUND_DIM_V1 = 2;
|
|
39
|
+
export const SURROUND_DARK_V1 = 3;
|
|
40
|
+
|
|
41
|
+
export const WCAG22_SC143_TEXT_DEFAULT_V1 = 1;
|
|
42
|
+
export const WCAG22_SC143_TEXT_LARGE_SCALE_V1 = 2;
|
|
43
|
+
export const WCAG22_SC1411_UI_COMPONENT_OR_STATE_V1 = 3;
|
|
44
|
+
export const WCAG22_SC1411_GRAPHICAL_OBJECT_V1 = 4;
|
|
45
|
+
|
|
46
|
+
/** Typed-отказ канонического builder-а — зеркало Rust ProgramWireEncodeErrorV1. */
|
|
47
|
+
export class ProgramWireError extends Error {
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} code машинный код класса отказа
|
|
50
|
+
* @param {string} message человекочитаемая причина
|
|
51
|
+
*/
|
|
52
|
+
constructor(code, message) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.name = "ProgramWireError";
|
|
55
|
+
this.code = code;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const PROGRAM_WIRE_TOO_MANY_ENTRIES = "PROGRAM_WIRE_TOO_MANY_ENTRIES";
|
|
60
|
+
export const PROGRAM_WIRE_INVALID_DECLARATION = "PROGRAM_WIRE_INVALID_DECLARATION";
|
|
61
|
+
|
|
62
|
+
export function invalid(message) {
|
|
63
|
+
throw new ProgramWireError(PROGRAM_WIRE_INVALID_DECLARATION, message);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Диагностика не преобразует отклонённое значение и не вызывает его hooks.
|
|
67
|
+
export function u32Value(value, what) {
|
|
68
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xffff_ffff) {
|
|
69
|
+
invalid(`${what} must be a u32 (received type ${typeof value})`);
|
|
70
|
+
}
|
|
71
|
+
return value >>> 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function byteValue(value, what) {
|
|
75
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xff) {
|
|
76
|
+
invalid(`${what} must be a byte (received type ${typeof value})`);
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function f64Value(value, what) {
|
|
82
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
83
|
+
invalid(`${what} must be a finite binary64 number (received type ${typeof value})`);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Wire producers admit the same physical domains as Core, before emitting bytes.
|
|
89
|
+
export function opacityValue(value, what) {
|
|
90
|
+
const admitted = f64Value(value, what);
|
|
91
|
+
if (admitted < 0 || admitted > 1) invalid(`${what} must be in [0, 1]`);
|
|
92
|
+
return admitted === 0 ? 0 : admitted;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function positiveF64Value(value, what) {
|
|
96
|
+
const admitted = f64Value(value, what);
|
|
97
|
+
if (admitted <= 0) invalid(`${what} must be positive`);
|
|
98
|
+
return admitted;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function positiveUnitRatioValue(value, what) {
|
|
102
|
+
const admitted = positiveF64Value(value, what);
|
|
103
|
+
if (admitted > 1) invalid(`${what} must be in (0, 1]`);
|
|
104
|
+
return admitted;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function memberValue(value, allowed, what) {
|
|
108
|
+
if (!allowed.includes(value)) {
|
|
109
|
+
invalid(`${what} must be one of ${allowed.join(", ")} (received type ${typeof value})`);
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const SURROUND_VALUES_V1 = Object.freeze([
|
|
115
|
+
SURROUND_AVERAGE_V1,
|
|
116
|
+
SURROUND_DIM_V1,
|
|
117
|
+
SURROUND_DARK_V1,
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
export const WCAG22_CRITERIA_V1 = Object.freeze([
|
|
121
|
+
WCAG22_SC143_TEXT_DEFAULT_V1,
|
|
122
|
+
WCAG22_SC143_TEXT_LARGE_SCALE_V1,
|
|
123
|
+
WCAG22_SC1411_UI_COMPONENT_OR_STATE_V1,
|
|
124
|
+
WCAG22_SC1411_GRAPHICAL_OBJECT_V1,
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
// Объявление задаёт индексные элементы массива, а не его переопределяемый
|
|
128
|
+
// iterator. Длина фиксируется до чтения элементов, чтобы snapshot и wire-count
|
|
129
|
+
// описывали один ограниченный набор даже при пользовательском iterator.
|
|
130
|
+
export function inputProperty(value, key, what) {
|
|
131
|
+
try {
|
|
132
|
+
return value[key];
|
|
133
|
+
} catch {
|
|
134
|
+
invalid(`${what} could not be read`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function inputArrayLength(values, what) {
|
|
139
|
+
// Array.isArray тоже бросает TypeError на отозванном Proxy: это отказ входа.
|
|
140
|
+
let isArray;
|
|
141
|
+
try {
|
|
142
|
+
isArray = Array.isArray(values);
|
|
143
|
+
} catch {
|
|
144
|
+
invalid(`${what} must be a readable array`);
|
|
145
|
+
}
|
|
146
|
+
if (!isArray) invalid(`${what} must be an array`);
|
|
147
|
+
return inputProperty(values, "length", what);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function indexedValues(values, length, what) {
|
|
151
|
+
return Array.from({ length }, (_, index) => inputProperty(values, index, what));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function candidateList(candidates, what) {
|
|
155
|
+
const length = inputArrayLength(candidates, what);
|
|
156
|
+
if (!Number.isInteger(length) || length <= 0) {
|
|
157
|
+
invalid(`${what} must be a non-empty array`);
|
|
158
|
+
}
|
|
159
|
+
// Вложенный счётчик имеет тот же wire-limit, что и секция. Проверка до
|
|
160
|
+
// копирования и чтения элементов сохраняет builder при отказе.
|
|
161
|
+
if (length > MAX_SECTION_ENTRIES_V1) {
|
|
162
|
+
throw new ProgramWireError(
|
|
163
|
+
PROGRAM_WIRE_TOO_MANY_ENTRIES,
|
|
164
|
+
`${what} exceeds the wire v1 count limit ${MAX_SECTION_ENTRIES_V1}`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return indexedValues(candidates, length, what);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function rgbBytes(rgb, what) {
|
|
171
|
+
if (inputArrayLength(rgb, what) !== 3) {
|
|
172
|
+
invalid(`${what} must be an [r, g, b] triple`);
|
|
173
|
+
}
|
|
174
|
+
return indexedValues(rgb, 3, what).map((channel, index) => byteValue(channel, `${what}[${index}]`));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Растущий LE-байтовый буфер: те же представления, что у Rust-стороны. */
|
|
178
|
+
export class ByteSink {
|
|
179
|
+
constructor() {
|
|
180
|
+
/** @type {number[]} */
|
|
181
|
+
this.bytes = [];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
u8(value) {
|
|
185
|
+
this.bytes.push(value & 0xff);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
u16(value) {
|
|
189
|
+
this.bytes.push(value & 0xff, (value >>> 8) & 0xff);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
u32(value) {
|
|
193
|
+
this.bytes.push(
|
|
194
|
+
value & 0xff,
|
|
195
|
+
(value >>> 8) & 0xff,
|
|
196
|
+
(value >>> 16) & 0xff,
|
|
197
|
+
(value >>> 24) & 0xff,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
u64(value) {
|
|
202
|
+
this.u32(Number(value & 0xffff_ffffn));
|
|
203
|
+
this.u32(Number(value >> 32n));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
f64Bits(value) {
|
|
207
|
+
const view = new DataView(new ArrayBuffer(8));
|
|
208
|
+
view.setFloat64(0, value, true);
|
|
209
|
+
for (let index = 0; index < 8; index += 1) {
|
|
210
|
+
this.bytes.push(view.getUint8(index));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
rgb(rgb) {
|
|
215
|
+
this.bytes.push(rgb[0], rgb[1], rgb[2]);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
package/wcag22.d.ts
ADDED
package/adapt-theme.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// Public types for the adaptive hysteresis controller.
|
|
2
|
-
|
|
3
|
-
import type { LabColors, ThemeName } from "./pkg/labcolors.js";
|
|
4
|
-
|
|
5
|
-
export interface AdaptThemeOptions {
|
|
6
|
-
/**
|
|
7
|
-
* An initialised engine — needs resolve + contrast recheck. The exact
|
|
8
|
-
* `isStableGlowPointNoop` capability is conditionally required when a result
|
|
9
|
-
* contains a stable Glow role; its absence then fails explicitly.
|
|
10
|
-
* `recheckContrastMulti` is optional: when present, a multi-sample backdrop
|
|
11
|
-
* is rechecked in ONE batched call per frame (byte-identical to the
|
|
12
|
-
* per-sample loop, locked by the wasm boundary parity test); when absent,
|
|
13
|
-
* the controller falls back to N `recheckContrast` calls.
|
|
14
|
-
*/
|
|
15
|
-
colors: Pick<LabColors, "resolveTheme" | "recheckContrast"> &
|
|
16
|
-
Partial<Pick<LabColors, "recheckContrastMulti" | "isStableGlowPointNoop">>;
|
|
17
|
-
theme: ThemeName;
|
|
18
|
-
/**
|
|
19
|
-
* Explicit effective background, overriding the ancestor-composite. A single
|
|
20
|
-
* hex is one solid surface; an array (or a function returning one) is a set of
|
|
21
|
-
* worst-case samples of a varying backdrop (gradient / image / video the
|
|
22
|
-
* caller sampled), and the colours are held legible against the hardest
|
|
23
|
-
* sample. With one sample this is identical to plain single-background mode.
|
|
24
|
-
*/
|
|
25
|
-
background?: string | string[] | (() => string | string[]);
|
|
26
|
-
/** Element to write the `--lab-*` variables onto. Defaults to the watched element. */
|
|
27
|
-
target?: HTMLElement;
|
|
28
|
-
/** Base colour when the ancestor chain is fully translucent. Default `"#FFFFFF"`. */
|
|
29
|
-
fallback?: string;
|
|
30
|
-
/** Fraction of a role's contrast surplus that may be lost before a re-solve. Default `0.2`. */
|
|
31
|
-
dropFraction?: number;
|
|
32
|
-
/** A breach must persist this many ms before re-solving (debounce). Default `120`. */
|
|
33
|
-
sustainMs?: number;
|
|
34
|
-
/** Minimum ms between re-solves (dwell / rate cap). Default `250`. */
|
|
35
|
-
dwellMs?: number;
|
|
36
|
-
/** Crossfade duration in ms. Default `280` (capped to a short fade under reduced motion). */
|
|
37
|
-
easeMs?: number;
|
|
38
|
-
/**
|
|
39
|
-
* Enable the legacy characterized per-frame clamp. The current
|
|
40
|
-
* Oklab→clip→sRGB8 path is not globally monotone, so this option is not a
|
|
41
|
-
* universal floor/least-blend certificate; #287 owns the finite replacement.
|
|
42
|
-
* Default `false`.
|
|
43
|
-
*/
|
|
44
|
-
strict?: boolean;
|
|
45
|
-
/** Override reduced-motion detection (default reads `matchMedia`). */
|
|
46
|
-
reducedMotion?: boolean;
|
|
47
|
-
/** Clock injection (default `performance.now`/`Date.now`). */
|
|
48
|
-
now?: () => number;
|
|
49
|
-
/** Window-like host (rAF, matchMedia). Defaults to `globalThis`. */
|
|
50
|
-
win?: Window;
|
|
51
|
-
/** Injection seam for the computed style of an element (testing). */
|
|
52
|
-
getStyle?: (element: unknown) => { getPropertyValue(property: string): string };
|
|
53
|
-
/** Injection seam for an element's parent (testing). */
|
|
54
|
-
parentOf?: (element: unknown) => unknown;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface AdaptController {
|
|
58
|
-
/** Drive one step. Cheap (a re-check); re-solves only on a sustained breach. */
|
|
59
|
-
tick(now?: number): void;
|
|
60
|
-
/** Switch theme INSTANTLY (intent, not drift) — bypasses the hysteresis. */
|
|
61
|
-
setTheme(theme: ThemeName): void;
|
|
62
|
-
/** Begin an internal `requestAnimationFrame` loop. */
|
|
63
|
-
start(): void;
|
|
64
|
-
/** Stop the loop. */
|
|
65
|
-
stop(): void;
|
|
66
|
-
/** The currently-applied `--lab-*` variables. */
|
|
67
|
-
current(): Record<string, string>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Keep an element's `--lab-*` variables adapting to its (changing) background
|
|
72
|
-
* **lazily and smoothly**: re-check each frame, hold while colours still pass,
|
|
73
|
-
* and re-solve + ease only when contrast stably degrades. The calm, cheap
|
|
74
|
-
* alternative to re-solving every frame.
|
|
75
|
-
*/
|
|
76
|
-
export declare function adaptTheme(element: HTMLElement, options: AdaptThemeOptions): AdaptController;
|