@labpics/colors 0.9.1 → 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.
Binary file
@@ -1,15 +1,65 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
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;
6
- export const labcolors_loadConfig: (a: number, b: number, c: number, d: number) => void;
7
- export const labcolors_muddiness: (a: number, b: number, c: number, d: number) => void;
8
- export const labcolors_new: () => number;
9
- export const labcolors_recheckContrast: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
10
- export const labcolors_resolveTheme: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
11
- export const __wbindgen_export: (a: number, b: number) => number;
12
- export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
13
- export const __wbindgen_export3: (a: number) => void;
4
+ export const __wbg_attachedmaterializationauthority_free: (a: number, b: number) => void;
5
+ export const __wbg_programattachedrender_free: (a: number, b: number) => void;
6
+ export const __wbg_programattachedsnapshot_free: (a: number, b: number) => void;
7
+ export const __wbg_programattachment_free: (a: number, b: number) => void;
8
+ export const __wbg_programruntime_free: (a: number, b: number) => void;
9
+ export const __wbg_programsnapshot_free: (a: number, b: number) => void;
10
+ export const attachProgramWire: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
11
+ export const attachedmaterializationauthority_bindingEpoch: (a: number) => bigint;
12
+ export const attachedmaterializationauthority_contentIdentity: (a: number, b: number) => void;
13
+ export const attachedmaterializationauthority_contextIdentity: (a: number, b: number) => void;
14
+ export const attachedmaterializationauthority_occurrence: (a: number) => number;
15
+ export const attachedmaterializationauthority_outputOpacity: (a: number) => number;
16
+ export const attachedmaterializationauthority_outputRgb: (a: number, b: number) => void;
17
+ export const attachedmaterializationauthority_outputSlot: (a: number) => number;
18
+ export const attachedmaterializationauthority_physicalIdentity: (a: number, b: number) => void;
19
+ export const attachedmaterializationauthority_presentationRoot: (a: number) => number;
20
+ export const attachedmaterializationauthority_rendererProvenance: (a: number, b: number) => void;
21
+ export const attachedmaterializationauthority_revision: (a: number) => bigint;
22
+ export const attachedmaterializationauthority_sinkSequence: (a: number) => bigint;
23
+ export const attachedmaterializationauthority_terminalCompositeRgb: (a: number, b: number) => void;
24
+ export const compileProgramWire: (a: number, b: number, c: number, d: number) => void;
25
+ export const decodeCertificateEnvelope: (a: number, b: number, c: number) => void;
26
+ export const evaluateWcag22: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
27
+ export const issueSourceCertificateEnvelope: (a: number) => void;
28
+ export const numericalCapabilityManifest: (a: number) => void;
29
+ export const programattachedrender_bindingEpoch: (a: number) => bigint;
30
+ export const programattachedrender_contentIdentity: (a: number, b: number) => void;
31
+ export const programattachedrender_contextIdentity: (a: number, b: number) => void;
32
+ export const programattachedrender_occurrence: (a: number) => number;
33
+ export const programattachedrender_outputOpacity: (a: number) => number;
34
+ export const programattachedrender_outputRgb: (a: number, b: number) => void;
35
+ export const programattachedrender_outputSlot: (a: number) => number;
36
+ export const programattachedrender_physicalIdentity: (a: number, b: number) => void;
37
+ export const programattachedrender_presentationRoot: (a: number) => number;
38
+ export const programattachedrender_revision: (a: number) => bigint;
39
+ export const programattachedrender_sinkOutput: (a: number) => number;
40
+ export const programattachedrender_sinkSequence: (a: number) => bigint;
41
+ export const programattachedrender_terminalCompositeRgb: (a: number, b: number) => void;
42
+ export const programattachedsnapshot_hasRender: (a: number) => number;
43
+ export const programattachedsnapshot_outputCount: (a: number) => number;
44
+ export const programattachedsnapshot_outputOpacity: (a: number, b: number, c: number) => void;
45
+ export const programattachedsnapshot_outputRgb: (a: number, b: number, c: number) => void;
46
+ export const programattachedsnapshot_outputSlot: (a: number, b: number, c: number) => void;
47
+ export const programattachedsnapshot_render: (a: number) => number;
48
+ export const programattachedsnapshot_state: (a: number, b: number) => void;
49
+ export const programattachment_dispose: (a: number, b: number, c: number) => void;
50
+ export const programattachment_materializationAuthority: (a: number, b: number) => void;
51
+ export const programattachment_materializationAuthorityFor: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
52
+ export const programattachment_updateObserved: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
53
+ export const programattachment_updateUnknown: (a: number, b: number, c: number, d: number) => void;
54
+ export const programruntime_updateObserved: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
55
+ export const programruntime_updateUnknown: (a: number, b: number, c: number, d: number) => void;
56
+ export const programsnapshot_outputCount: (a: number) => number;
57
+ export const programsnapshot_outputOpacity: (a: number, b: number, c: number) => void;
58
+ export const programsnapshot_outputRgb: (a: number, b: number, c: number) => void;
59
+ export const programsnapshot_outputSlot: (a: number, b: number, c: number) => void;
60
+ export const programsnapshot_state: (a: number, b: number) => void;
61
+ export const __wbindgen_export: (a: number) => void;
14
62
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
15
- export const __wbindgen_export4: (a: number, b: number, c: number) => void;
63
+ export const __wbindgen_export2: (a: number, b: number) => number;
64
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;
65
+ export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
@@ -0,0 +1,98 @@
1
+
2
+ export function programError(message, code, operation) {
3
+ try {
4
+ const error = new Error(message);
5
+ error.code = code;
6
+ error.operation = operation;
7
+ return error;
8
+ } catch {
9
+ return new Error("Program error projection failed");
10
+ }
11
+ }
12
+
13
+ const programFailureCodes = [
14
+ "program_wire",
15
+ "program_compile",
16
+ "program_family_artifacts_required",
17
+ "program_instantiate",
18
+ "program_update",
19
+ "program_resource_exhausted",
20
+ "program_internal_invariant",
21
+ "program_runtime",
22
+ "program_attachment_binding",
23
+ "program_attachment_instantiate",
24
+ "program_attachment_sink_admission",
25
+ "program_attachment_resource_exhausted",
26
+ "program_attachment_internal_invariant",
27
+ "program_attachment_non_terminal_target",
28
+ "program_attachment",
29
+ ];
30
+
31
+ export function programFailure(kind, operation) {
32
+ return programError(
33
+ kind < 8 ? "Program runtime operation failed" : "Program attachment admission failed",
34
+ programFailureCodes[kind],
35
+ operation,
36
+ );
37
+ }
38
+
39
+ const bindingFailures = [
40
+ ["invalid_color", "evaluateWcag22"],
41
+ ["unknown_wcag22_criterion", "evaluateWcag22"],
42
+ ["internal_error", "evaluateWcag22"],
43
+ ["internal_error", "numericalCapabilityManifest"],
44
+ ["invalid_output_index", "readProgramOutput"],
45
+ ];
46
+
47
+ export function bindingFailure(kind, reason) {
48
+ const [code, operation] = bindingFailures[kind];
49
+ return programError(code + ": " + reason, code, operation);
50
+ }
51
+
52
+ export function certificateError(code, operation) {
53
+ return programError(
54
+ "Certificate envelope operation failed",
55
+ `certificate_${code}`,
56
+ operation,
57
+ );
58
+ }
59
+
60
+ export function unsupportedPhysicalIdentityError() {
61
+ return programError(
62
+ "Unsupported program physical identity",
63
+ "program_physical_identity",
64
+ "physicalIdentity",
65
+ );
66
+ }
67
+
68
+ export function certificateProjection(
69
+ schemaVersion,
70
+ operation,
71
+ authorityKind,
72
+ authorityVersion,
73
+ runtimeArtifactId,
74
+ producerRevision,
75
+ producerContentIdentity,
76
+ contextId,
77
+ payloadType,
78
+ payloadVersion,
79
+ payloadLength,
80
+ payloadSha256,
81
+ bindingSha256,
82
+ ) {
83
+ return Object.freeze({
84
+ schemaVersion,
85
+ operation,
86
+ authorityKind,
87
+ authorityVersion,
88
+ runtimeArtifactId,
89
+ producerRevision,
90
+ producerContentIdentity: Uint8Array.from(producerContentIdentity),
91
+ contextId,
92
+ payloadType,
93
+ payloadVersion,
94
+ payloadLength,
95
+ payloadSha256: Uint8Array.from(payloadSha256),
96
+ bindingSha256: Uint8Array.from(bindingSha256),
97
+ });
98
+ }
@@ -0,0 +1,84 @@
1
+ export const SURROUND_AVERAGE_V1: 1;
2
+ export const SURROUND_DIM_V1: 2;
3
+ export const SURROUND_DARK_V1: 3;
4
+ export type ProgramWireSurroundV1 =
5
+ | typeof SURROUND_AVERAGE_V1
6
+ | typeof SURROUND_DIM_V1
7
+ | typeof SURROUND_DARK_V1;
8
+
9
+ export const WCAG22_SC143_TEXT_DEFAULT_V1: 1;
10
+ export const WCAG22_SC143_TEXT_LARGE_SCALE_V1: 2;
11
+ export const WCAG22_SC1411_UI_COMPONENT_OR_STATE_V1: 3;
12
+ export const WCAG22_SC1411_GRAPHICAL_OBJECT_V1: 4;
13
+ export type ProgramWireWcag22CriterionV1 =
14
+ | typeof WCAG22_SC143_TEXT_DEFAULT_V1
15
+ | typeof WCAG22_SC143_TEXT_LARGE_SCALE_V1
16
+ | typeof WCAG22_SC1411_UI_COMPONENT_OR_STATE_V1
17
+ | typeof WCAG22_SC1411_GRAPHICAL_OBJECT_V1;
18
+
19
+ export const PROGRAM_WIRE_TOO_MANY_ENTRIES: "PROGRAM_WIRE_TOO_MANY_ENTRIES";
20
+ export const PROGRAM_WIRE_INVALID_DECLARATION: "PROGRAM_WIRE_INVALID_DECLARATION";
21
+ export type ProgramWireErrorCode =
22
+ | typeof PROGRAM_WIRE_TOO_MANY_ENTRIES
23
+ | typeof PROGRAM_WIRE_INVALID_DECLARATION;
24
+
25
+ export class ProgramWireError extends Error {
26
+ readonly code: ProgramWireErrorCode;
27
+ constructor(code: ProgramWireErrorCode, message: string);
28
+ }
29
+
30
+ export type ProgramWireRgbV1 = readonly [number, number, number];
31
+ export type ProgramWireCandidateV1 = Readonly<{
32
+ id: number;
33
+ rgb: ProgramWireRgbV1;
34
+ opacity: number;
35
+ }>;
36
+
37
+ export class ProgramWireBuilderV1 {
38
+ source(id: number, rgb: ProgramWireRgbV1): this;
39
+ fixedTarget(id: number, source: number): this;
40
+ finiteTarget(id: number, candidates: readonly ProgramWireCandidateV1[]): this;
41
+ family(id: number, releaseBytes: readonly number[]): this;
42
+ surfaceInputPort(id: number): this;
43
+ opacityInput(id: number, value: number): this;
44
+ solidPaint(id: number, target: number): this;
45
+ opacityPaint(id: number, source: number, opacity: number): this;
46
+ inputSurface(id: number, input: number): this;
47
+ occurrenceSurface(id: number, occurrence: number): this;
48
+ sourceOverOccurrence(
49
+ id: number,
50
+ subject: number,
51
+ against: number,
52
+ adaptingLuminance: number,
53
+ backgroundRatio: number,
54
+ surround: ProgramWireSurroundV1,
55
+ ): this;
56
+ presentationRoot(id: number, terminal: number): this;
57
+ presentationTarget(root: number, occurrence: number): this;
58
+ exactVisibleUnary(
59
+ hard: boolean,
60
+ id: number,
61
+ occurrence: number,
62
+ expectedRgb: ProgramWireRgbV1,
63
+ ): this;
64
+ wcag22VisibleUnary(
65
+ hard: boolean,
66
+ id: number,
67
+ occurrence: number,
68
+ criterion: ProgramWireWcag22CriterionV1,
69
+ ): this;
70
+ /** Явная sRGB8-конвенция конечной point-композиции без гарантии восприятия или автоисправления. */
71
+ declaredSrgb8CleanSet(
72
+ hard: boolean,
73
+ id: number,
74
+ root: number,
75
+ occurrence: number,
76
+ ): this;
77
+ exactIntrinsicRelationHard(
78
+ id: number,
79
+ reference: number,
80
+ candidates: readonly number[],
81
+ ): this;
82
+ output(slot: number, paint: number): this;
83
+ finish(): Uint8Array;
84
+ }
@@ -0,0 +1,332 @@
1
+ import {
2
+ PROGRAM_WIRE_MAGIC_V1,
3
+ PROGRAM_WIRE_VERSION_V1,
4
+ MAX_SECTION_ENTRIES_V1,
5
+ SECTION_ORDER_V1,
6
+ KIND_EXACT_VISIBLE_UNARY,
7
+ KIND_EXACT_INTRINSIC_RELATION,
8
+ KIND_WCAG22_VISIBLE_UNARY,
9
+ KIND_CLEAN_SET,
10
+ ProgramWireError,
11
+ PROGRAM_WIRE_TOO_MANY_ENTRIES,
12
+ invalid,
13
+ u32Value,
14
+ byteValue,
15
+ opacityValue,
16
+ positiveF64Value,
17
+ positiveUnitRatioValue,
18
+ memberValue,
19
+ SURROUND_VALUES_V1,
20
+ WCAG22_CRITERIA_V1,
21
+ inputProperty,
22
+ inputArrayLength,
23
+ indexedValues,
24
+ candidateList,
25
+ rgbBytes,
26
+ ByteSink
27
+ } from "./encoding.js";
28
+ export {
29
+ SURROUND_AVERAGE_V1,
30
+ SURROUND_DIM_V1,
31
+ SURROUND_DARK_V1,
32
+ WCAG22_SC143_TEXT_DEFAULT_V1,
33
+ WCAG22_SC143_TEXT_LARGE_SCALE_V1,
34
+ WCAG22_SC1411_UI_COMPONENT_OR_STATE_V1,
35
+ WCAG22_SC1411_GRAPHICAL_OBJECT_V1,
36
+ ProgramWireError,
37
+ PROGRAM_WIRE_TOO_MANY_ENTRIES,
38
+ PROGRAM_WIRE_INVALID_DECLARATION
39
+ } from "./encoding.js";
40
+
41
+ /**
42
+ * Канонический builder байтов wire v1 — двойник Rust ProgramWireBuilderV1.
43
+ * Клиент объявляет граф; builder эмитирует единственное каноническое
44
+ * представление. Joint selection непредставим на wire v1 by design.
45
+ */
46
+ export class ProgramWireBuilderV1 {
47
+ constructor() {
48
+ /** @type {Map<string, {count: number, sink: ByteSink}>} */
49
+ this.sections = new Map(
50
+ SECTION_ORDER_V1.map((name) => [name, { count: 0, sink: new ByteSink() }]),
51
+ );
52
+ }
53
+
54
+ section(name) {
55
+ const section = this.sections.get(name);
56
+ if (section === undefined) invalid("unknown section");
57
+ return section;
58
+ }
59
+
60
+ entry(name) {
61
+ const section = this.section(name);
62
+ section.count += 1;
63
+ return section.sink;
64
+ }
65
+
66
+ source(id, rgb) {
67
+ const checkedId = u32Value(id, "source id");
68
+ const checkedRgb = rgbBytes(rgb, "source rgb");
69
+ const sink = this.entry("sources");
70
+ sink.u32(checkedId);
71
+ sink.rgb(checkedRgb);
72
+ return this;
73
+ }
74
+
75
+ fixedTarget(id, source) {
76
+ const checkedId = u32Value(id, "target id");
77
+ const checkedSource = u32Value(source, "target source");
78
+ const sink = this.entry("targets");
79
+ sink.u32(checkedId);
80
+ sink.u8(1);
81
+ sink.u32(checkedSource);
82
+ return this;
83
+ }
84
+
85
+ finiteTarget(id, candidates) {
86
+ const checkedId = u32Value(id, "target id");
87
+ const checked = candidateList(candidates, "finite target candidates").map(
88
+ (candidate, index) => {
89
+ if (candidate === null || typeof candidate !== "object") {
90
+ invalid(`candidate[${index}] must be an object`);
91
+ }
92
+ return {
93
+ id: u32Value(inputProperty(candidate, "id", "candidate id"), "candidate[" + index + "] id"),
94
+ rgb: rgbBytes(inputProperty(candidate, "rgb", "candidate rgb"), "candidate[" + index + "] rgb"),
95
+ opacity: opacityValue(inputProperty(candidate, "opacity", "candidate opacity"), "candidate[" + index + "] opacity"),
96
+ };
97
+ },
98
+ );
99
+ const sink = this.entry("targets");
100
+ sink.u32(checkedId);
101
+ sink.u8(2);
102
+ sink.u32(checked.length);
103
+ for (const candidate of checked) {
104
+ sink.u32(candidate.id);
105
+ sink.rgb(candidate.rgb);
106
+ sink.f64Bits(candidate.opacity);
107
+ }
108
+ return this;
109
+ }
110
+
111
+ family(id, releaseBytes) {
112
+ const checkedId = u32Value(id, "family id");
113
+ if (inputArrayLength(releaseBytes, "family release") !== 32) {
114
+ invalid("family release must be 32 bytes");
115
+ }
116
+ const checkedRelease = indexedValues(releaseBytes, 32, "family release").map((byte) => byteValue(byte, "family release byte"));
117
+ const sink = this.entry("families");
118
+ sink.u32(checkedId);
119
+ for (const byte of checkedRelease) sink.u8(byte);
120
+ return this;
121
+ }
122
+
123
+ surfaceInputPort(id) {
124
+ const checkedId = u32Value(id, "surface input port id");
125
+ this.entry("surfaceInputPorts").u32(checkedId);
126
+ return this;
127
+ }
128
+
129
+ opacityInput(id, value) {
130
+ const checkedId = u32Value(id, "opacity input id");
131
+ const checkedValue = opacityValue(value, "opacity input value");
132
+ const sink = this.entry("opacityInputs");
133
+ sink.u32(checkedId);
134
+ sink.f64Bits(checkedValue);
135
+ return this;
136
+ }
137
+
138
+ solidPaint(id, target) {
139
+ const checkedId = u32Value(id, "paint id");
140
+ const checkedTarget = u32Value(target, "paint target");
141
+ const sink = this.entry("paints");
142
+ sink.u32(checkedId);
143
+ sink.u8(1);
144
+ sink.u32(checkedTarget);
145
+ return this;
146
+ }
147
+
148
+ opacityPaint(id, source, opacity) {
149
+ const checkedId = u32Value(id, "paint id");
150
+ const checkedSource = u32Value(source, "paint source");
151
+ const checkedOpacity = u32Value(opacity, "paint opacity input");
152
+ const sink = this.entry("paints");
153
+ sink.u32(checkedId);
154
+ sink.u8(2);
155
+ sink.u32(checkedSource);
156
+ sink.u32(checkedOpacity);
157
+ return this;
158
+ }
159
+
160
+ inputSurface(id, input) {
161
+ const checkedId = u32Value(id, "surface id");
162
+ const checkedInput = u32Value(input, "surface input port");
163
+ const sink = this.entry("surfaces");
164
+ sink.u32(checkedId);
165
+ sink.u8(1);
166
+ sink.u32(checkedInput);
167
+ return this;
168
+ }
169
+
170
+ occurrenceSurface(id, occurrence) {
171
+ const checkedId = u32Value(id, "surface id");
172
+ const checkedOccurrence = u32Value(occurrence, "surface occurrence");
173
+ const sink = this.entry("surfaces");
174
+ sink.u32(checkedId);
175
+ sink.u8(2);
176
+ sink.u32(checkedOccurrence);
177
+ return this;
178
+ }
179
+
180
+ sourceOverOccurrence(id, subject, against, adaptingLuminance, backgroundRatio, surround) {
181
+ const checkedId = u32Value(id, "occurrence id");
182
+ const checkedSubject = u32Value(subject, "occurrence subject");
183
+ const checkedAgainst = u32Value(against, "occurrence surface");
184
+ const checkedLuminance = positiveF64Value(adaptingLuminance, "occurrence adapting luminance");
185
+ const checkedRatio = positiveUnitRatioValue(backgroundRatio, "occurrence background ratio");
186
+ const checkedSurround = memberValue(surround, SURROUND_VALUES_V1, "occurrence surround");
187
+ const sink = this.entry("occurrences");
188
+ sink.u32(checkedId);
189
+ sink.u32(checkedSubject);
190
+ sink.u32(checkedAgainst);
191
+ sink.f64Bits(checkedLuminance);
192
+ sink.f64Bits(checkedRatio);
193
+ sink.u8(checkedSurround);
194
+ return this;
195
+ }
196
+
197
+ presentationRoot(id, terminal) {
198
+ const checkedId = u32Value(id, "presentation root id");
199
+ const checkedTerminal = u32Value(terminal, "presentation terminal");
200
+ const sink = this.entry("presentationRoots");
201
+ sink.u32(checkedId);
202
+ sink.u32(checkedTerminal);
203
+ return this;
204
+ }
205
+
206
+ presentationTarget(root, occurrence) {
207
+ const checkedRoot = u32Value(root, "presentation root");
208
+ const checkedOccurrence = u32Value(occurrence, "presentation occurrence");
209
+ const sink = this.entry("presentationTargets");
210
+ sink.u32(checkedRoot);
211
+ sink.u32(checkedOccurrence);
212
+ return this;
213
+ }
214
+
215
+ constraintEntry(hard) {
216
+ if (typeof hard !== "boolean") invalid("constraint hard flag must be a boolean");
217
+ return this.entry(hard ? "hardConstraints" : "reportConstraints");
218
+ }
219
+
220
+ exactVisibleUnary(hard, id, occurrence, expectedRgb) {
221
+ const checkedId = u32Value(id, "constraint id");
222
+ const checkedOccurrence = u32Value(occurrence, "constraint occurrence");
223
+ const checkedRgb = rgbBytes(expectedRgb, "expected rgb");
224
+ const sink = this.constraintEntry(hard);
225
+ sink.u32(checkedId);
226
+ sink.u8(KIND_EXACT_VISIBLE_UNARY);
227
+ sink.u32(checkedOccurrence);
228
+ sink.rgb(checkedRgb);
229
+ return this;
230
+ }
231
+
232
+ wcag22VisibleUnary(hard, id, occurrence, criterion) {
233
+ const checkedId = u32Value(id, "constraint id");
234
+ const checkedOccurrence = u32Value(occurrence, "constraint occurrence");
235
+ const checkedCriterion = memberValue(criterion, WCAG22_CRITERIA_V1, "wcag22 criterion");
236
+ const sink = this.constraintEntry(hard);
237
+ sink.u32(checkedId);
238
+ sink.u8(KIND_WCAG22_VISIBLE_UNARY);
239
+ sink.u32(checkedOccurrence);
240
+ sink.u8(checkedCriterion);
241
+ return this;
242
+ }
243
+
244
+ declaredSrgb8CleanSet(hard, id, root, occurrence) {
245
+ const checkedId = u32Value(id, "constraint id");
246
+ const checkedRoot = u32Value(root, "constraint presentation root");
247
+ const checkedOccurrence = u32Value(occurrence, "constraint occurrence");
248
+ const sink = this.constraintEntry(hard);
249
+ sink.u32(checkedId);
250
+ sink.u8(KIND_CLEAN_SET);
251
+ sink.u32(checkedRoot);
252
+ sink.u32(checkedOccurrence);
253
+ return this;
254
+ }
255
+
256
+ exactIntrinsicRelationHard(id, reference, candidates) {
257
+ const checkedId = u32Value(id, "constraint id");
258
+ const checkedReference = u32Value(reference, "relation reference");
259
+ const checked = candidateList(candidates, "relation candidates").map(
260
+ (candidate, index) => u32Value(candidate, "relation candidate[" + index + "]"),
261
+ );
262
+ const sink = this.constraintEntry(true);
263
+ sink.u32(checkedId);
264
+ sink.u8(KIND_EXACT_INTRINSIC_RELATION);
265
+ sink.u32(checkedReference);
266
+ sink.u32(checked.length);
267
+ for (const candidate of checked) {
268
+ sink.u32(candidate);
269
+ }
270
+ return this;
271
+ }
272
+
273
+ output(slot, paint) {
274
+ const checkedSlot = u32Value(slot, "output slot");
275
+ const checkedPaint = u32Value(paint, "output paint");
276
+ const sink = this.entry("outputs");
277
+ sink.u32(checkedSlot);
278
+ sink.u32(checkedPaint);
279
+ return this;
280
+ }
281
+
282
+ /** Эмитирует единственные канонические байты объявленного графа. */
283
+ finish() {
284
+ const header = new ByteSink();
285
+ for (const byte of PROGRAM_WIRE_MAGIC_V1) header.u8(byte);
286
+ header.u16(PROGRAM_WIRE_VERSION_V1);
287
+ header.u32(0); // patched below
288
+
289
+ // Check the u32 envelope before copying section payloads. New nested
290
+ // declarations cannot silently truncate the header length.
291
+ let declaredLength = header.bytes.length + SECTION_ORDER_V1.length * 4;
292
+ for (const name of SECTION_ORDER_V1) {
293
+ const { count, sink } = this.section(name);
294
+ if (!Number.isSafeInteger(count) || count < 0) {
295
+ invalid("section " + name + " has an invalid entry count");
296
+ }
297
+ const payloadLength = sink.bytes.length;
298
+ if (!Number.isSafeInteger(payloadLength) || payloadLength < 0) {
299
+ invalid("section " + name + " has an invalid payload length");
300
+ }
301
+ if (count > MAX_SECTION_ENTRIES_V1 || payloadLength > 0xffff_ffff - declaredLength) {
302
+ throw new ProgramWireError(
303
+ PROGRAM_WIRE_TOO_MANY_ENTRIES,
304
+ "section " + name + " exceeds the wire length or count limit",
305
+ );
306
+ }
307
+ declaredLength += payloadLength;
308
+ }
309
+
310
+ const body = new ByteSink();
311
+ for (const name of SECTION_ORDER_V1) {
312
+ const { count, sink } = this.section(name);
313
+ body.u32(count);
314
+ // Поэлементно: spread разворачивает массив в аргументы вызова и падает
315
+ // на больших секциях (лимит аргументов V8), а не по нашему typed-отказу.
316
+ for (const byte of sink.bytes) {
317
+ body.bytes.push(byte);
318
+ }
319
+ }
320
+
321
+ const total = header.bytes.length + body.bytes.length;
322
+ if (total !== declaredLength) {
323
+ invalid("wire sections changed during emission");
324
+ }
325
+ const bytes = new Uint8Array(total);
326
+ bytes.set(header.bytes, 0);
327
+ bytes.set(body.bytes, header.bytes.length);
328
+ const view = new DataView(bytes.buffer);
329
+ view.setUint32(6, total, true);
330
+ return bytes;
331
+ }
332
+ }
@@ -0,0 +1,17 @@
1
+ import { ProgramWireBuilderV1 } from "./abi-v1.js";
2
+ export { ProgramWireError, PROGRAM_WIRE_INVALID_DECLARATION, PROGRAM_WIRE_TOO_MANY_ENTRIES,
3
+ SURROUND_AVERAGE_V1, SURROUND_DIM_V1, SURROUND_DARK_V1,
4
+ WCAG22_SC143_TEXT_DEFAULT_V1, WCAG22_SC143_TEXT_LARGE_SCALE_V1,
5
+ WCAG22_SC1411_UI_COMPONENT_OR_STATE_V1, WCAG22_SC1411_GRAPHICAL_OBJECT_V1 } from "./abi-v1.js";
6
+
7
+ export type ProgramSelectionChoiceV2 = Readonly<{ target: number; candidate: number }>;
8
+ export type ProgramSelectionStateV2 = Readonly<{
9
+ id: number;
10
+ choices: readonly ProgramSelectionChoiceV2[];
11
+ }>;
12
+
13
+ export class ProgramWireBuilderV2 extends ProgramWireBuilderV1 {
14
+ /** Rank groups in preference order; Core validates and canonically orders ties. */
15
+ selectionRelease(revision: bigint, rankGroups: readonly (readonly ProgramSelectionStateV2[])[]): this;
16
+ finish(): Uint8Array;
17
+ }
@@ -0,0 +1,61 @@
1
+ import { ProgramWireBuilderV1 } from "./abi-v1.js";
2
+ import { ByteSink, candidateList, inputProperty, invalid, MAX_SECTION_ENTRIES_V1,
3
+ PROGRAM_WIRE_TOO_MANY_ENTRIES, ProgramWireError, u32Value } from "./encoding.js";
4
+
5
+ export { ProgramWireError, PROGRAM_WIRE_INVALID_DECLARATION, PROGRAM_WIRE_TOO_MANY_ENTRIES,
6
+ SURROUND_AVERAGE_V1, SURROUND_DIM_V1, SURROUND_DARK_V1,
7
+ WCAG22_SC143_TEXT_DEFAULT_V1, WCAG22_SC143_TEXT_LARGE_SCALE_V1,
8
+ WCAG22_SC1411_UI_COMPONENT_OR_STATE_V1, WCAG22_SC1411_GRAPHICAL_OBJECT_V1 } from "./abi-v1.js";
9
+
10
+ const MAX_U64 = (1n << 64n) - 1n;
11
+
12
+ /** Explicit authored preferences over complete finite states; the Core selects. */
13
+ export class ProgramWireBuilderV2 extends ProgramWireBuilderV1 {
14
+ selectionRelease(revision, rankGroups) {
15
+ if (typeof revision !== "bigint" || revision < 0n || revision > MAX_U64) {
16
+ invalid("selection revision must be a u64 bigint");
17
+ }
18
+ if (this.section("jointSelection").count !== 0) invalid("selection release is already declared");
19
+ const groups = candidateList(rankGroups, "selection rank groups");
20
+ const sink = new ByteSink();
21
+ sink.u64(revision);
22
+ sink.u32(groups.length);
23
+ let states = 0, choices = 0;
24
+ for (const group of groups) {
25
+ const members = candidateList(group, "selection rank group");
26
+ states += members.length;
27
+ if (states > MAX_SECTION_ENTRIES_V1) {
28
+ throw new ProgramWireError(PROGRAM_WIRE_TOO_MANY_ENTRIES, "selection state budget exceeded");
29
+ }
30
+ sink.u32(members.length);
31
+ for (const member of members) {
32
+ const id = u32Value(inputProperty(member, "id", "selection state"), "selection state id");
33
+ const entries = candidateList(inputProperty(member, "choices", "selection state"), "selection choices");
34
+ choices += entries.length;
35
+ if (choices > MAX_SECTION_ENTRIES_V1) {
36
+ throw new ProgramWireError(PROGRAM_WIRE_TOO_MANY_ENTRIES, "selection choice budget exceeded");
37
+ }
38
+ sink.u32(id);
39
+ sink.u32(entries.length);
40
+ for (const entry of entries) {
41
+ const target = u32Value(inputProperty(entry, "target", "selection choice"), "selection target");
42
+ const candidate = u32Value(inputProperty(entry, "candidate", "selection choice"), "selection candidate");
43
+ sink.u32(target);
44
+ sink.u32(candidate);
45
+ }
46
+ }
47
+ }
48
+ // Callers may execute getters while the declaration is copied. Commit only
49
+ // after all nested values have passed admission, without replacing a release.
50
+ if (this.section("jointSelection").count !== 0) invalid("selection release is already declared");
51
+ const output = this.entry("jointSelection");
52
+ for (const byte of sink.bytes) output.u8(byte);
53
+ return this;
54
+ }
55
+
56
+ finish() {
57
+ const bytes = super.finish();
58
+ new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).setUint16(4, 2, true);
59
+ return bytes;
60
+ }
61
+ }