@labpics/colors 1.0.2 → 1.0.3
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 +20 -8
- package/build-metadata.json +4 -4
- package/evidence/point-support-reference-surplus-q55-bps-proof-v1.json +1 -1
- package/package.json +9 -8
- package/pkg/labcolors.js +8 -7
- package/pkg/labcolors_bg.wasm +0 -0
- package/pkg/snippets/labcolors-wasm-9fb8b927594c3d6f/inline0.js +10 -0
- package/program-wire/abi-v1.js +29 -38
- package/program-wire/abi-v2.js +4 -3
- package/program-wire/encoding.js +37 -45
package/README.md
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lab Colors
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Библиотека адаптивных цветов для интерфейсов и дизайн-систем.
|
|
4
|
+
Вы задаёте цвета, фоны и ограничения, например контраст текста.
|
|
5
|
+
Lab Colors выбирает подходящие значения с учётом наложения слоёв
|
|
6
|
+
и пересчитывает результат, когда приложение передаёт изменения фона.
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
[](https://www.npmjs.com/package/@labpics/colors)
|
|
9
|
+
[](https://github.com/Labpics-Team/lab-colors/actions/workflows/ci.yml)
|
|
10
|
+
[](https://github.com/Labpics-Team/lab-colors/blob/main/LICENSE)
|
|
6
11
|
|
|
7
12
|
## Установка
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
```sh
|
|
15
|
+
npm install @labpics/colors@^1
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
JavaScript и TypeScript, ESM. Ядро на Rust/WASM включено в пакет.
|
|
19
|
+
Сохраните lockfile, чтобы закрепить версию.
|
|
20
|
+
|
|
21
|
+
[Пример подбора цвета под фон](https://github.com/Labpics-Team/lab-colors/blob/main/docs/how-to/adapt-contrast.md)
|
|
22
|
+
выбирает чёрный или белый текст по требованию контраста WCAG 2.2
|
|
23
|
+
и показывает отказ, когда ни один вариант не подходит.
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
<a id="первый-маршрут"></a>
|
|
14
26
|
|
|
15
|
-
## Первый
|
|
27
|
+
## Первый запуск
|
|
16
28
|
|
|
17
29
|
Инициализируйте WASM один раз выбранным способом, затем выполните общий пример
|
|
18
30
|
ниже в том же модуле.
|
package/build-metadata.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": {
|
|
4
4
|
"name": "@labpics/colors",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.3"
|
|
6
6
|
},
|
|
7
|
-
"sourceSha": "
|
|
7
|
+
"sourceSha": "3f45c7e522f9a609b4cac69745c860d51f27b3fb",
|
|
8
8
|
"coreVersion": "0.3.0",
|
|
9
9
|
"conformance": {
|
|
10
10
|
"packVersion": "12.0.0",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
{
|
|
17
17
|
"role": "runtime",
|
|
18
18
|
"path": "pkg/labcolors_bg.wasm",
|
|
19
|
-
"bytes":
|
|
20
|
-
"sha256": "
|
|
19
|
+
"bytes": 442027,
|
|
20
|
+
"sha256": "a39d1b53f9f0e5253eb2768a7d6402cdedba497415564c1ce8ba3d2e99763684"
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"artifact_id":"wcag22-srgb8-luminance-q55-v1","basis_point_proof":{"checks":30,"drop_all_semantics":"zero required surplus; current must still meet the anchor","drop_domain_inclusive":[0,10000],"nonpositive_baseline_semantics":"zero required surplus; current must meet the anchor"},"bound_id":"point-support-reference-surplus-q55-bps-v1","certified_claim":"for every successfully evaluated enabled stability cell, decision is Retained iff current_lower_surplus >= (10000-drop_bps)/10000 * max(baseline_lower_surplus,0); the declared anchor remains a separate hard floor","comparator_proof":{"algorithm":"euclidean-continued-fraction-ordering-v1","dense_denominator_inclusive":[1,31],"dense_numerator_inclusive":[0,31],"dense_small_cases":984064,"invariant":"equal integer parts; reciprocal proper fractions reverse order","largest_fibonacci_index":186,"oracle":"unbounded-integer-cross-product","random_cases":250000,"random_corpus_sha256":"97c4af7b452b31a4ab92645f70c17acb38bf57ca55484e32ad9d7d79d97a333d","random_seed":210583930,"termination":"each nonterminal denominator becomes a strictly smaller remainder","u128_adversarial_cases":190},"declared_operation_law":"q55-lower-reference-distance-explicit-anchor-bps-retention-v1","excluded_claim":"does not certify retention against the unknown exact baseline surplus, renderer equivalence outside encoded-sRGB8 source-over, or a successful result when evaluation fails","integer_replay_envelope":{"assumption":"every Q55 luminance upper <= scale + 3","i128_max":170141183460469231731687303715884105727,"offset_cleared_denominator_max":756604737398243388,"positive_baseline_numerator_max":1188950301625811064,"rational_denominator_max":1513209474796486776,"required_denominator_max":15132094747964867760000,"required_numerator_max":11889503016258110640000,"signed_anchor_abs_coarse_max":5296233161787703716,"u128_max":340282366920938463463374607431768211455,"u64_max":18446744073709551615},"profile_id":"srgb8-q55-retained-reference-surplus-bps-v1","proof_id":"point-support-reference-surplus-integer-v1","proof_payload_sha256":"
|
|
1
|
+
{"artifact_id":"wcag22-srgb8-luminance-q55-v1","basis_point_proof":{"checks":30,"drop_all_semantics":"zero required surplus; current must still meet the anchor","drop_domain_inclusive":[0,10000],"nonpositive_baseline_semantics":"zero required surplus; current must meet the anchor"},"bound_id":"point-support-reference-surplus-q55-bps-v1","certified_claim":"for every successfully evaluated enabled stability cell, decision is Retained iff current_lower_surplus >= (10000-drop_bps)/10000 * max(baseline_lower_surplus,0); the declared anchor remains a separate hard floor","comparator_proof":{"algorithm":"euclidean-continued-fraction-ordering-v1","dense_denominator_inclusive":[1,31],"dense_numerator_inclusive":[0,31],"dense_small_cases":984064,"invariant":"equal integer parts; reciprocal proper fractions reverse order","largest_fibonacci_index":186,"oracle":"unbounded-integer-cross-product","random_cases":250000,"random_corpus_sha256":"97c4af7b452b31a4ab92645f70c17acb38bf57ca55484e32ad9d7d79d97a333d","random_seed":210583930,"termination":"each nonterminal denominator becomes a strictly smaller remainder","u128_adversarial_cases":190},"declared_operation_law":"q55-lower-reference-distance-explicit-anchor-bps-retention-v1","excluded_claim":"does not certify retention against the unknown exact baseline surplus, renderer equivalence outside encoded-sRGB8 source-over, or a successful result when evaluation fails","integer_replay_envelope":{"assumption":"every Q55 luminance upper <= scale + 3","i128_max":170141183460469231731687303715884105727,"offset_cleared_denominator_max":756604737398243388,"positive_baseline_numerator_max":1188950301625811064,"rational_denominator_max":1513209474796486776,"required_denominator_max":15132094747964867760000,"required_numerator_max":11889503016258110640000,"signed_anchor_abs_coarse_max":5296233161787703716,"u128_max":340282366920938463463374607431768211455,"u64_max":18446744073709551615},"profile_id":"srgb8-q55-retained-reference-surplus-bps-v1","proof_id":"point-support-reference-surplus-integer-v1","proof_payload_sha256":"62208d41239f9c7cfe645d2ba10bc28a779a0d6b0b6066c4570a501d9e9c7c5d","q55_dependency":{"artifact_id":"wcag22-srgb8-luminance-q55-v1","artifact_sha256":"7ff239d9052b346f3c50da01ca65ca2330892ed1a3ff30e190797fcef6f03604","maximum_luminance_upper":36028797018963971,"outward_interval_width_bound":3,"proof_id":"wcag22-srgb8-full-domain-q55-v1","proof_payload_sha256":"a4e02b4dce47c58310fb3ea9e34af1538ae5813b31b15ddee71a9a1be7bb76f8","proof_sha256":"2b2170e20bd24c059a0bbaf8d92603470ec941402f3a08185f54a5e1e41c69ca","q55_scale":36028797018963968},"reference_and_anchor_proof":{"anchor_identity_checks":75,"orientation_law":"distance-magnitude-symmetric-orientation-reported-separately","overlap_lower_distance":"0/1","separated_endpoint_checks":504},"schema_version":2,"site_id":"point-support-retained-reference-surplus-v1","source_binding_exclusions":["whole-crate compilation or compiler/toolchain attestation","binary, package, FFI, renderer, or browser transport attestation","unrelated Lab Colors modules outside the declared point-support semantic cone"],"source_binding_law":"point-support-rust-whole-file-semantic-cone-v2","source_binding_schema_version":2,"source_binding_scope":"exact bytes of the private point-support Rust semantic cone and its two WCAG include_str inputs; comments and cfg(test) text are intentionally significant","source_closure_sha256":"5fa4305e060086a3e5df3f0da33fcb297c3c7527f7daed4d941a5b090a6e08b8","source_files":[{"kind":"compile-time-input","path":"crates/labcolors-core/contracts/wcag22-srgb8-q55-proof-v1.json","sha256":"2b2170e20bd24c059a0bbaf8d92603470ec941402f3a08185f54a5e1e41c69ca"},{"kind":"compile-time-input","path":"crates/labcolors-core/contracts/wcag22-srgb8-v1.json","sha256":"b4bb7e5f17a99f2c911fdbe3da23a48b049277b796291094950f14680cc3cc7b"},{"kind":"rust-source","path":"crates/labcolors-core/src/appearance.rs","sha256":"9e6fa6fc6efac242d118e92bf416c8547d043e965d7b681610fa6a5baa447dc3"},{"kind":"rust-source","path":"crates/labcolors-core/src/composition.rs","sha256":"66506ab70fbe9223486ebfd480dd114542c6acab81115880871db56fe923e134"},{"kind":"rust-source","path":"crates/labcolors-core/src/constraints/exact.rs","sha256":"ae9d95c3aa08142192ff422cd7a5bd514855d47f58c8e54aaffb69bfd7481afc"},{"kind":"rust-source","path":"crates/labcolors-core/src/constraints/mod.rs","sha256":"93f914875c0a0780e612bfedad1b52f75aa63429e53a2242346db13031e4a0cd"},{"kind":"rust-source","path":"crates/labcolors-core/src/constraints/wcag22.rs","sha256":"63b78e4a4669d2b237812ffd62b4b9b5cb3761d9a6856f508ad50da68ab611fb"},{"kind":"rust-source","path":"crates/labcolors-core/src/hash.rs","sha256":"f97a0fd7d6ad3162f0f1dfb326fccfb7ed40da9a8fa67a5b8a239a1ae2ae49c3"},{"kind":"rust-source","path":"crates/labcolors-core/src/lcs_occurrence.rs","sha256":"78d37406e9bdc37f126b72987c9c92b452c13b3233c0aeb0a75ed25dadb83a68"},{"kind":"rust-source","path":"crates/labcolors-core/src/lib.rs","sha256":"bae7d0c4fd0fd554c3c23dddac33c45e60c987300e67558d205d12336b2498a0"},{"kind":"rust-source","path":"crates/labcolors-core/src/numerics.rs","sha256":"94ab17694b86e724e149570dfda8fafa71619f1c1015dcb7af421bc72d44ff22"},{"kind":"rust-source","path":"crates/labcolors-core/src/observation.rs","sha256":"b9ea44b2b0a471ba86e791abacaab17cb3475744676575d1520de9629346199b"},{"kind":"rust-source","path":"crates/labcolors-core/src/point_support.rs","sha256":"f8c12113a1487cc33dc289621d16e54ef84ba99a65bc370dead1da185228f17e"},{"kind":"rust-source","path":"crates/labcolors-core/src/session.rs","sha256":"b21c6a41e24349ec37e6311a3a51d8bc29b81cdbaea9f36bb04b3ce838b044bc"},{"kind":"rust-source","path":"crates/labcolors-core/src/srgb8.rs","sha256":"c8d600491f92c86c79b33ae2643787c52bb616028a48cd66bd711ba27d0b19d7"},{"kind":"rust-source","path":"crates/labcolors-core/src/wcag22.rs","sha256":"15de885a352794944993d00f61ccdab9ec78d12777efd247bfbff0004be89a4f"},{"kind":"rust-source","path":"crates/labcolors-core/src/wcag22/kernel.rs","sha256":"8ab231b0a7fac8ebf78e04c3a2e70c1a7e477fdd3324ffa9d0eb100e89df1059"},{"kind":"rust-source","path":"crates/labcolors-core/src/wcag22/q55_data.rs","sha256":"af4d23d6b70c45ce6efa839e7dda4bb0a61f6aae43cb805af6fa9b29e6c3bae2"},{"kind":"rust-source","path":"crates/labcolors-core/src/wcag22_evidence.rs","sha256":"19dea4c88a75414c6869bedc0a36058a884d73f36ed9cb5c2f243764f10ac5dc"}],"source_negative_controls":43,"universal_algebraic_certificate":{"basis_point_scale_instantiation":10000,"domain":"integers; Q55 scale Q>0; anchor L>=D>=0; lighter monotonicity L2>=L1>D>=0; darker monotonicity L>D2>=D1>=0; current/baseline denominators b,q>0; basis-point scale B>0 instantiated as 10000; p>0; a>=0; 0<=drop_bps<=B","identities":["three explicit anchor-surplus formulas after denominator clearing","reference distance is monotone increasing in lighter L","reference distance is monotone decreasing in darker D","positive-baseline retained threshold is p*(B-drop)/(q*B)","a/b >= p*(B-drop)/(q*B) iff a*q*B >= p*(B-drop)*b"],"method":"exact-sparse-integer-polynomial-identities-plus-positive-denominator-order-lemma-v1","nonpositive_baseline_case":"max(baseline,0)=0; retained threshold is exactly zero","symbolic_mutation_controls":{"anchor_coefficients_and_denominator":6,"retained_cross_product":5},"wolfram_language_cross_check":{"query":"FullSimplify[{20 g/d - 0 == 20 g/d, 20 g/d - 2 == (20 g - 2 d)/d, 20 g/d - 7/2 == (40 g - 7 d)/(2 d), Equivalent[a/b >= p (s-x)/(q s), a q s >= p (s-x) b], Max[p/q, 0] (s-x)/s == Piecewise[{{0, p <= 0}}, p (s-x)/(q s)]}, Assumptions -> Element[{a,b,p,q,s,x,g,d}, Integers] && a >= 0 && b > 0 && q > 0 && s > 0 && 0 <= x <= s && d > 0 && g >= 0]","query_sha256":"8cdbb9964583030c8b92498961896cb2a98613f1cb31eb7c54acdf8e16beff10","result":"{True, True, True, True, True}","result_sha256":"13a8f2ee8d0fde335a638e46d7cc8a8427b9a1437c77d22cfcf925bb87fa6303"}},"verifier_sha256":"1a338442048e022df09a27608e3a9934da1bd0964fab2d050ede560f118b29d2"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labpics/colors",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"packageManager": "npm@11.9.0",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Библиотека адаптивных цветов для интерфейсов и дизайн-систем.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT AND CC-BY-4.0 AND CC-BY-SA-4.0",
|
|
8
8
|
"publishConfig": {
|
|
@@ -64,20 +64,21 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"es-module-lexer": "1.7.0",
|
|
66
66
|
"typescript": "^5.5.0",
|
|
67
|
-
"typescript-floor": "npm:typescript@5.2.2"
|
|
67
|
+
"typescript-floor": "npm:typescript@5.2.2",
|
|
68
|
+
"yaml": "2.9.1"
|
|
68
69
|
},
|
|
69
70
|
"types": "./index.d.ts",
|
|
70
71
|
"sideEffects": false,
|
|
71
72
|
"keywords": [
|
|
72
73
|
"color",
|
|
73
|
-
"oklch",
|
|
74
74
|
"contrast",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"theme",
|
|
75
|
+
"accessibility",
|
|
76
|
+
"design-system",
|
|
78
77
|
"design-tokens",
|
|
78
|
+
"rust",
|
|
79
|
+
"typescript",
|
|
79
80
|
"wasm",
|
|
80
|
-
"
|
|
81
|
+
"wcag"
|
|
81
82
|
],
|
|
82
83
|
"engines": {
|
|
83
84
|
"node": ">=22.11.0"
|
package/pkg/labcolors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @ts-self-types="./labcolors.d.ts" */
|
|
2
|
-
import { bindingFailure, certificateError, certificateProjection, programError, programFailure } from './snippets/labcolors-wasm-9fb8b927594c3d6f/inline0.js';
|
|
2
|
+
import { bindingFailure, certificateError, certificateProjection, copyOutputRgb, programError, programFailure } from './snippets/labcolors-wasm-9fb8b927594c3d6f/inline0.js';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export class AttachedMaterializationAuthority {
|
|
@@ -711,13 +711,10 @@ export class ProgramSnapshot {
|
|
|
711
711
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
712
712
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
713
713
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
throw takeObject(r2);
|
|
714
|
+
if (r2) {
|
|
715
|
+
throw takeObject(r1);
|
|
717
716
|
}
|
|
718
|
-
|
|
719
|
-
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
720
|
-
return v1;
|
|
717
|
+
return takeObject(r0);
|
|
721
718
|
} finally {
|
|
722
719
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
723
720
|
}
|
|
@@ -958,6 +955,10 @@ function __wbg_get_imports() {
|
|
|
958
955
|
const ret = certificateProjection(arg0, getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), arg5, getStringFromWasm0(arg6, arg7), getStringFromWasm0(arg8, arg9), getArrayU8FromWasm0(arg10, arg11), getStringFromWasm0(arg12, arg13), getStringFromWasm0(arg14, arg15), arg16, arg17 >>> 0, getArrayU8FromWasm0(arg18, arg19), getArrayU8FromWasm0(arg20, arg21));
|
|
959
956
|
return addHeapObject(ret);
|
|
960
957
|
},
|
|
958
|
+
__wbg_copyOutputRgb_9c1248136397e8f7: function() { return handleError(function (arg0, arg1, arg2) {
|
|
959
|
+
const ret = copyOutputRgb(arg0, arg1, arg2);
|
|
960
|
+
return addHeapObject(ret);
|
|
961
|
+
}, arguments); },
|
|
961
962
|
__wbg_new_da52cf8fe3429cb2: function() {
|
|
962
963
|
const ret = new Object();
|
|
963
964
|
return addHeapObject(ret);
|
package/pkg/labcolors_bg.wasm
CHANGED
|
Binary file
|
|
@@ -49,6 +49,16 @@ export function bindingFailure(kind, reason) {
|
|
|
49
49
|
return programError(code + ": " + reason, code, operation);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const OutputRgbArray = Uint8Array;
|
|
53
|
+
|
|
54
|
+
export function copyOutputRgb(red, green, blue) {
|
|
55
|
+
const bytes = new OutputRgbArray(3);
|
|
56
|
+
bytes[0] = red;
|
|
57
|
+
bytes[1] = green;
|
|
58
|
+
bytes[2] = blue;
|
|
59
|
+
return bytes;
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
export function certificateError(code, operation) {
|
|
53
63
|
return programError(
|
|
54
64
|
"Certificate envelope operation failed",
|
package/program-wire/abi-v1.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
inputArrayLength,
|
|
23
23
|
indexedValues,
|
|
24
24
|
candidateList,
|
|
25
|
-
|
|
25
|
+
rgb24,
|
|
26
26
|
ByteSink
|
|
27
27
|
} from "./encoding.js";
|
|
28
28
|
export {
|
|
@@ -65,10 +65,10 @@ export class ProgramWireBuilderV1 {
|
|
|
65
65
|
|
|
66
66
|
source(id, rgb) {
|
|
67
67
|
const checkedId = u32Value(id, "source id");
|
|
68
|
-
const checkedRgb =
|
|
68
|
+
const checkedRgb = rgb24(rgb, "source rgb");
|
|
69
69
|
const sink = this.entry("sources");
|
|
70
70
|
sink.u32(checkedId);
|
|
71
|
-
sink.
|
|
71
|
+
sink.rgb24(checkedRgb);
|
|
72
72
|
return this;
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -91,7 +91,7 @@ export class ProgramWireBuilderV1 {
|
|
|
91
91
|
}
|
|
92
92
|
return {
|
|
93
93
|
id: u32Value(inputProperty(candidate, "id", "candidate id"), "candidate[" + index + "] id"),
|
|
94
|
-
rgb:
|
|
94
|
+
rgb: rgb24(inputProperty(candidate, "rgb", "candidate rgb"), "candidate[" + index + "] rgb"),
|
|
95
95
|
opacity: opacityValue(inputProperty(candidate, "opacity", "candidate opacity"), "candidate[" + index + "] opacity"),
|
|
96
96
|
};
|
|
97
97
|
},
|
|
@@ -102,7 +102,7 @@ export class ProgramWireBuilderV1 {
|
|
|
102
102
|
sink.u32(checked.length);
|
|
103
103
|
for (const candidate of checked) {
|
|
104
104
|
sink.u32(candidate.id);
|
|
105
|
-
sink.
|
|
105
|
+
sink.rgb24(candidate.rgb);
|
|
106
106
|
sink.f64Bits(candidate.opacity);
|
|
107
107
|
}
|
|
108
108
|
return this;
|
|
@@ -220,12 +220,12 @@ export class ProgramWireBuilderV1 {
|
|
|
220
220
|
exactVisibleUnary(hard, id, occurrence, expectedRgb) {
|
|
221
221
|
const checkedId = u32Value(id, "constraint id");
|
|
222
222
|
const checkedOccurrence = u32Value(occurrence, "constraint occurrence");
|
|
223
|
-
const checkedRgb =
|
|
223
|
+
const checkedRgb = rgb24(expectedRgb, "expected rgb");
|
|
224
224
|
const sink = this.constraintEntry(hard);
|
|
225
225
|
sink.u32(checkedId);
|
|
226
226
|
sink.u8(KIND_EXACT_VISIBLE_UNARY);
|
|
227
227
|
sink.u32(checkedOccurrence);
|
|
228
|
-
sink.
|
|
228
|
+
sink.rgb24(checkedRgb);
|
|
229
229
|
return this;
|
|
230
230
|
}
|
|
231
231
|
|
|
@@ -256,9 +256,10 @@ export class ProgramWireBuilderV1 {
|
|
|
256
256
|
exactIntrinsicRelationHard(id, reference, candidates) {
|
|
257
257
|
const checkedId = u32Value(id, "constraint id");
|
|
258
258
|
const checkedReference = u32Value(reference, "relation reference");
|
|
259
|
-
const checked = candidateList(candidates, "relation candidates")
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
const checked = candidateList(candidates, "relation candidates");
|
|
260
|
+
for (let i = 0; i < checked.length; i++) {
|
|
261
|
+
checked[i] = u32Value(checked[i], "relation candidate", i);
|
|
262
|
+
}
|
|
262
263
|
const sink = this.constraintEntry(true);
|
|
263
264
|
sink.u32(checkedId);
|
|
264
265
|
sink.u8(KIND_EXACT_INTRINSIC_RELATION);
|
|
@@ -281,20 +282,17 @@ export class ProgramWireBuilderV1 {
|
|
|
281
282
|
|
|
282
283
|
/** Эмитирует единственные канонические байты объявленного графа. */
|
|
283
284
|
finish() {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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;
|
|
285
|
+
// magic + u16 version + u32 total, followed by a u32 count per section.
|
|
286
|
+
const headerLength = PROGRAM_WIRE_MAGIC_V1.length + 2 + 4;
|
|
287
|
+
let declaredLength = headerLength + SECTION_ORDER_V1.length * 4;
|
|
288
|
+
const sections = [];
|
|
292
289
|
for (const name of SECTION_ORDER_V1) {
|
|
293
290
|
const { count, sink } = this.section(name);
|
|
291
|
+
const payload = sink.bytes;
|
|
294
292
|
if (!Number.isSafeInteger(count) || count < 0) {
|
|
295
293
|
invalid("section " + name + " has an invalid entry count");
|
|
296
294
|
}
|
|
297
|
-
const payloadLength =
|
|
295
|
+
const payloadLength = payload.length;
|
|
298
296
|
if (!Number.isSafeInteger(payloadLength) || payloadLength < 0) {
|
|
299
297
|
invalid("section " + name + " has an invalid payload length");
|
|
300
298
|
}
|
|
@@ -305,28 +303,21 @@ export class ProgramWireBuilderV1 {
|
|
|
305
303
|
);
|
|
306
304
|
}
|
|
307
305
|
declaredLength += payloadLength;
|
|
306
|
+
sections.push({ count, payload });
|
|
308
307
|
}
|
|
309
308
|
|
|
310
|
-
const
|
|
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);
|
|
309
|
+
const bytes = new Uint8Array(declaredLength);
|
|
328
310
|
const view = new DataView(bytes.buffer);
|
|
329
|
-
|
|
311
|
+
bytes.set(PROGRAM_WIRE_MAGIC_V1);
|
|
312
|
+
view.setUint16(PROGRAM_WIRE_MAGIC_V1.length, PROGRAM_WIRE_VERSION_V1, true);
|
|
313
|
+
view.setUint32(headerLength - 4, declaredLength, true);
|
|
314
|
+
let at = headerLength;
|
|
315
|
+
for (const { count, payload } of sections) {
|
|
316
|
+
view.setUint32(at, count, true);
|
|
317
|
+
at += 4;
|
|
318
|
+
bytes.set(payload, at);
|
|
319
|
+
at += payload.length;
|
|
320
|
+
}
|
|
330
321
|
return bytes;
|
|
331
322
|
}
|
|
332
323
|
}
|
package/program-wire/abi-v2.js
CHANGED
|
@@ -47,9 +47,10 @@ export class ProgramWireBuilderV2 extends ProgramWireBuilderV1 {
|
|
|
47
47
|
}
|
|
48
48
|
// Callers may execute getters while the declaration is copied. Commit only
|
|
49
49
|
// after all nested values have passed admission, without replacing a release.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const section = this.section("jointSelection");
|
|
51
|
+
if (section.count !== 0) invalid("selection release is already declared");
|
|
52
|
+
section.sink = sink;
|
|
53
|
+
section.count = 1;
|
|
53
54
|
return this;
|
|
54
55
|
}
|
|
55
56
|
|
package/program-wire/encoding.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
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.
|
|
1
|
+
// Wire V1/V2: LCPW header, little-endian sections in Core draft order.
|
|
2
|
+
// This module admits scalar inputs; Rust checks graph semantics in program/wire.rs.
|
|
10
3
|
|
|
11
4
|
export const PROGRAM_WIRE_MAGIC_V1 = Object.freeze([0x4c, 0x43, 0x50, 0x57]); // LCPW
|
|
12
5
|
export const PROGRAM_WIRE_VERSION_V1 = 1;
|
|
@@ -64,16 +57,20 @@ export function invalid(message) {
|
|
|
64
57
|
}
|
|
65
58
|
|
|
66
59
|
// Диагностика не преобразует отклонённое значение и не вызывает его hooks.
|
|
67
|
-
|
|
60
|
+
function indexedPath(what, index) {
|
|
61
|
+
return index === undefined ? what : what + "[" + index + "]";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function u32Value(value, what, index) {
|
|
68
65
|
if (!Number.isInteger(value) || value < 0 || value > 0xffff_ffff) {
|
|
69
|
-
invalid(
|
|
66
|
+
invalid(indexedPath(what, index) + " must be a u32 (received type " + typeof value + ")");
|
|
70
67
|
}
|
|
71
68
|
return value >>> 0;
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
export function byteValue(value, what) {
|
|
71
|
+
export function byteValue(value, what, index) {
|
|
75
72
|
if (!Number.isInteger(value) || value < 0 || value > 0xff) {
|
|
76
|
-
invalid(
|
|
73
|
+
invalid(indexedPath(what, index) + " must be a byte (received type " + typeof value + ")");
|
|
77
74
|
}
|
|
78
75
|
return value;
|
|
79
76
|
}
|
|
@@ -167,52 +164,47 @@ export function candidateList(candidates, what) {
|
|
|
167
164
|
return indexedValues(candidates, length, what);
|
|
168
165
|
}
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
// Keep the three caller-owned reads ordered and complete before validation.
|
|
168
|
+
// The packed number is internal; the wire still carries R, G, B in that order.
|
|
169
|
+
export function rgb24(rgb, what) {
|
|
170
|
+
if (inputArrayLength(rgb, what) !== 3) invalid(what + " must be an [r, g, b] triple");
|
|
171
|
+
const r = inputProperty(rgb, 0, what);
|
|
172
|
+
const g = inputProperty(rgb, 1, what);
|
|
173
|
+
const b = inputProperty(rgb, 2, what);
|
|
174
|
+
return byteValue(r, what, 0) | (byteValue(g, what, 1) << 8) | (byteValue(b, what, 2) << 16);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
/**
|
|
177
|
+
/** Stage admitted bytes; only finish() materializes the contiguous wire. */
|
|
178
178
|
export class ByteSink {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.bytes = [];
|
|
182
|
-
}
|
|
179
|
+
bytes = [];
|
|
180
|
+
#float;
|
|
183
181
|
|
|
184
|
-
|
|
185
|
-
this.bytes.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
u16(value) {
|
|
189
|
-
this.bytes.push(value & 0xff, (value >>> 8) & 0xff);
|
|
182
|
+
#room(width) {
|
|
183
|
+
if (this.bytes.length > 0xffff_ffff - width) {
|
|
184
|
+
throw new ProgramWireError(PROGRAM_WIRE_TOO_MANY_ENTRIES, "section exceeds the u32 wire length");
|
|
185
|
+
}
|
|
190
186
|
}
|
|
191
187
|
|
|
188
|
+
u8(value) { this.#room(1); this.bytes.push(value & 255); }
|
|
192
189
|
u32(value) {
|
|
193
|
-
this
|
|
194
|
-
|
|
195
|
-
(value >>> 8) & 0xff,
|
|
196
|
-
(value >>> 16) & 0xff,
|
|
197
|
-
(value >>> 24) & 0xff,
|
|
198
|
-
);
|
|
190
|
+
this.#room(4);
|
|
191
|
+
this.bytes.push(value & 255, (value >>> 8) & 255, (value >>> 16) & 255, value >>> 24);
|
|
199
192
|
}
|
|
200
|
-
|
|
201
193
|
u64(value) {
|
|
194
|
+
this.#room(8);
|
|
202
195
|
this.u32(Number(value & 0xffff_ffffn));
|
|
203
196
|
this.u32(Number(value >> 32n));
|
|
204
197
|
}
|
|
205
|
-
|
|
206
198
|
f64Bits(value) {
|
|
207
|
-
|
|
199
|
+
this.#room(8);
|
|
200
|
+
// Only sections that actually encode floating-point values need a view.
|
|
201
|
+
const view = this.#float ??= new DataView(new ArrayBuffer(Float64Array.BYTES_PER_ELEMENT));
|
|
208
202
|
view.setFloat64(0, value, true);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
203
|
+
this.u32(view.getUint32(0, true));
|
|
204
|
+
this.u32(view.getUint32(4, true));
|
|
212
205
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
this.bytes.push(
|
|
206
|
+
rgb24(value) {
|
|
207
|
+
this.#room(3);
|
|
208
|
+
this.bytes.push(value & 255, (value >>> 8) & 255, value >>> 16);
|
|
216
209
|
}
|
|
217
210
|
}
|
|
218
|
-
|