@labpics/colors 1.0.2 → 1.1.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/README.md +52 -12
- package/build-metadata.json +8 -8
- package/evidence/point-support-reference-surplus-q55-bps-proof-v1.json +1 -1
- package/evidence/wcag22-srgb8-q55-proof-v1.json +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +9 -8
- package/pkg/labcolors.d.ts +20 -8
- package/pkg/labcolors.js +66 -7
- package/pkg/labcolors_bg.wasm +0 -0
- package/pkg/labcolors_bg.wasm.d.ts +10 -8
- package/pkg/snippets/labcolors-wasm-9fb8b927594c3d6f/inline0.js +15 -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, чтобы закрепить версию.
|
|
12
20
|
|
|
13
|
-
[
|
|
21
|
+
[Пример подбора цвета под фон](https://github.com/Labpics-Team/lab-colors/blob/main/docs/how-to/adapt-contrast.md)
|
|
22
|
+
выбирает чёрный или белый текст по требованию контраста WCAG 2.2
|
|
23
|
+
и показывает отказ, когда ни один вариант не подходит.
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
<a id="первый-маршрут"></a>
|
|
26
|
+
|
|
27
|
+
## Первый запуск
|
|
16
28
|
|
|
17
29
|
Инициализируйте WASM один раз выбранным способом, затем выполните общий пример
|
|
18
30
|
ниже в том же модуле.
|
|
@@ -81,11 +93,12 @@ try {
|
|
|
81
93
|
);
|
|
82
94
|
try {
|
|
83
95
|
if (snapshot.state === "ready") {
|
|
84
|
-
|
|
96
|
+
const outputs = snapshot.copyOutputTable();
|
|
97
|
+
for (let row = 0; row < outputs.length; row += 5) {
|
|
85
98
|
console.log(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
outputs[row],
|
|
100
|
+
outputs[row + 1], outputs[row + 2], outputs[row + 3],
|
|
101
|
+
outputs[row + 4],
|
|
89
102
|
);
|
|
90
103
|
}
|
|
91
104
|
}
|
|
@@ -99,6 +112,33 @@ try {
|
|
|
99
112
|
|
|
100
113
|
Канонические `LCPW` v1 bytes создаются `ProgramWireBuilderV1` или другим реализационно-независимым энкодером того же контракта.
|
|
101
114
|
|
|
115
|
+
## Чтение outputs
|
|
116
|
+
|
|
117
|
+
Для чтения всех цветов используйте `snapshot.copyOutputTable()` у
|
|
118
|
+
`ProgramSnapshot` и `ProgramAttachedSnapshot`. Один вызов возвращает
|
|
119
|
+
`Float64Array` длиной `outputCount() * 5`; каждая строка содержит:
|
|
120
|
+
|
|
121
|
+
| Смещение в строке | Значение |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| 0 | Непрозрачный клиентский `slot`, целое u32 |
|
|
124
|
+
| 1, 2, 3 | Красный, зелёный и синий канал sRGB8, целые `0..255` |
|
|
125
|
+
| 4 | Straight opacity, исходное f64 в `0..1` |
|
|
126
|
+
|
|
127
|
+
Строка `i` совпадает с `outputSlot(i)`, `outputRgb(i)` и `outputOpacity(i)`.
|
|
128
|
+
Слоты и каналы точно представимы в f64, opacity копируется без округления.
|
|
129
|
+
Каждый вызов создаёт независимый JS-буфер: его изменение не меняет snapshot,
|
|
130
|
+
другую таблицу или runtime. Таблица остаётся доступна после следующего update
|
|
131
|
+
и `free()` снимка или владельца. Поштучные геттеры доступны, когда нужен один
|
|
132
|
+
output.
|
|
133
|
+
|
|
134
|
+
Перед применением цветов проверяйте `snapshot.state === "ready"`.
|
|
135
|
+
`failed` и `stale` могут содержать последние проверенные значения, которые
|
|
136
|
+
не удостоверены для текущего контекста; таблица сохраняет эту же семантику.
|
|
137
|
+
Снимок без outputs возвращает пустой `Float64Array`.
|
|
138
|
+
Если не удаётся выделить Rust-таблицу или создать её JS-копию, метод бросает ошибку
|
|
139
|
+
`{ code: "program_resource_exhausted", operation: "copyOutputTable" }`,
|
|
140
|
+
распознаваемую `isProgramError`. Снимок при отказе не меняется.
|
|
141
|
+
|
|
102
142
|
## Явная конвенция cleanliness
|
|
103
143
|
|
|
104
144
|
Чтобы выбранный результат удовлетворял встроенной конвенции sRGB8, добавьте
|
package/build-metadata.json
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": {
|
|
4
4
|
"name": "@labpics/colors",
|
|
5
|
-
"version": "1.0
|
|
5
|
+
"version": "1.1.0"
|
|
6
6
|
},
|
|
7
|
-
"sourceSha": "
|
|
7
|
+
"sourceSha": "a00f1215ad151366c84d818e8d2fb92bf1b1f8e5",
|
|
8
8
|
"coreVersion": "0.3.0",
|
|
9
9
|
"conformance": {
|
|
10
|
-
"packVersion": "
|
|
11
|
-
"packDigest": "
|
|
12
|
-
"manifestSha256": "
|
|
13
|
-
"familySetSha256": "
|
|
10
|
+
"packVersion": "13.0.0",
|
|
11
|
+
"packDigest": "ab63bf70",
|
|
12
|
+
"manifestSha256": "845265aa61cc067978c5604585127d88601cb1a196ab6c21c4f29f80db170622",
|
|
13
|
+
"familySetSha256": "b04a5894861ba7d11295fb7e944cc257add26c02c81a4aa55d5967baa143b82b"
|
|
14
14
|
},
|
|
15
15
|
"wasm": [
|
|
16
16
|
{
|
|
17
17
|
"role": "runtime",
|
|
18
18
|
"path": "pkg/labcolors_bg.wasm",
|
|
19
|
-
"bytes":
|
|
20
|
-
"sha256": "
|
|
19
|
+
"bytes": 627400,
|
|
20
|
+
"sha256": "e95ad4856901300e11717fd1231f0401ac81618b99f861460005a69e6892ea3e"
|
|
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":"c52e2721dbca4902ae9d40870f97d0c8d1f373d26ff134fc2d0fdbd6bb420ec5","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":"659ec379cb71d6ac4e20272610626957c79e4531b53127257d9a19ffe6f3ae59","proof_sha256":"fce4e75c036274ede4ee20adfbdd8112512f8385244f852b71a8020afd87ef84","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":"a03c96a1d708abc7b69ca70f525e43be8eb4a6d4cb6bfaa396510fa07fe29949","source_files":[{"kind":"compile-time-input","path":"crates/labcolors-core/contracts/wcag22-srgb8-q55-proof-v1.json","sha256":"fce4e75c036274ede4ee20adfbdd8112512f8385244f852b71a8020afd87ef84"},{"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":"2a953a62d62a01884fc10a2f27fe5ebabae8e60805de9ff291f3ba8b32b16ef6"},{"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":"8d4f57faf6953d8717ee9f1b21fbc059a0226c270130c0fe8de356771defa369"},{"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":"973397e06e344ca0fd17ec3c2dfd563daeea42915712df1589ac16c2a0294be1"},{"kind":"rust-source","path":"crates/labcolors-core/src/wcag22/kernel.rs","sha256":"f82a1bf356141a1cd79605c889bc0f67b7b861a35de4fe18745d71eee4f36a53"},{"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":"d02b40a44cc24e813d7a00a20f198692b47215f28d6c942f2608836617794a71"}],"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":"95f1608872c3a6edfbd9412aa2a5efddb0e30c86cef321877a0202a8e62275b8"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"artifact_id":"wcag22-srgb8-luminance-q55-v1","artifact_rust_source_sha256":"af4d23d6b70c45ce6efa839e7dda4bb0a61f6aae43cb805af6fa9b29e6c3bae2","artifact_sha256":"7ff239d9052b346f3c50da01ca65ca2330892ed1a3ff30e190797fcef6f03604","artifact_words":1536,"bound_id":"wcag22-srgb8-outward-q55-v1","colors":16777216,"declared_operation_law":"final-srgb8-outward-q55-two-orientation-integer-threshold-v1","facade_id":"wcag22-srgb8-public-facade-v1","facade_normalized_sha256":"c2f252829577f1a5455b91afdccc1669ff0c964e10d8935db9e79b0c8ce251d6","full_domain_algorithm":"unique-q55-interval-monotone-boundary-v1","generator_sha256":"7ad72f53e26ebb74ebfc2d8945f833613fa1317bb441d821f518d012c8c09687","integer_replay_envelope":{"carrier":"signed-64","carrier_maximum":9223372036854775807,"headroom":2485986994308513251,"maximum_luminance_upper":36028797018963971,"maximum_threshold_term":6737385042546262556,"next_scale_maximum_threshold_term":13474770085092524572,"next_scale_power":56,"observed_interval_width":3,"outward_interval_width_bound":3},"kernel_id":"wcag22-srgb8-evaluation-kernel-v1","kernel_source_sha256":"
|
|
1
|
+
{"artifact_id":"wcag22-srgb8-luminance-q55-v1","artifact_rust_source_sha256":"af4d23d6b70c45ce6efa839e7dda4bb0a61f6aae43cb805af6fa9b29e6c3bae2","artifact_sha256":"7ff239d9052b346f3c50da01ca65ca2330892ed1a3ff30e190797fcef6f03604","artifact_words":1536,"bound_id":"wcag22-srgb8-outward-q55-v1","colors":16777216,"declared_operation_law":"final-srgb8-outward-q55-two-orientation-integer-threshold-v1","facade_id":"wcag22-srgb8-public-facade-v1","facade_normalized_sha256":"c2f252829577f1a5455b91afdccc1669ff0c964e10d8935db9e79b0c8ce251d6","full_domain_algorithm":"unique-q55-interval-monotone-boundary-v1","generator_sha256":"7ad72f53e26ebb74ebfc2d8945f833613fa1317bb441d821f518d012c8c09687","integer_replay_envelope":{"carrier":"signed-64","carrier_maximum":9223372036854775807,"headroom":2485986994308513251,"maximum_luminance_upper":36028797018963971,"maximum_threshold_term":6737385042546262556,"next_scale_maximum_threshold_term":13474770085092524572,"next_scale_power":56,"observed_interval_width":3,"outward_interval_width_bound":3},"kernel_id":"wcag22-srgb8-evaluation-kernel-v1","kernel_source_sha256":"f82a1bf356141a1cd79605c889bc0f67b7b861a35de4fe18745d71eee4f36a53","max_color_interval_width":3,"negative_controls":15,"parser_id":"encoded-srgb8-hex-parser-v1","parser_source_sha256":"70fc992594762b97c3191a721156161b7f188b29cd05ee555c1656fb3840aed0","profile_checksum":"152813fe","profile_id":"wcag22-srgb8-contrast-v1","profile_source_sha256":"b4bb7e5f17a99f2c911fdbe3da23a48b049277b796291094950f14680cc3cc7b","proof_id":"wcag22-srgb8-full-domain-q55-v1","proof_payload_sha256":"659ec379cb71d6ac4e20272610626957c79e4531b53127257d9a19ffe6f3ae59","q55_scale":36028797018963968,"recommendation":"https://www.w3.org/TR/2024/REC-WCAG22-20241212/","registry_row_id":"wcag22-srgb8-contrast-v1","registry_row_negative_controls":10,"registry_row_sha256":"c91c5e185c432ae4a9fb9ea03e9838bf2565f2aabff56019e190aae97bfaa0f1","row_oracle":{"integer_tightness_cross_checks":768,"maximum_precision_used":72,"precision_schedule":[48,72,108,162],"rows_stable":768},"rows":768,"schema_version":2,"source_binding_law":"wcag22-rust-semantic-dependency-cone-v1","source_binding_schema_version":1,"source_route_sha256":"3b8dfe6f0a538e2e026484ff361dce97b1cee852e4e3029453b05915d49eef8c","terminal_evidence_id":"wcag22-srgb8-terminal-evidence-v1","terminal_evidence_source_sha256":"d02b40a44cc24e813d7a00a20f198692b47215f28d6c942f2608836617794a71","thresholds":[{"candidate_checks":0,"integer_law":{"dark_factor":30,"light_factor":10,"offset_factor":1},"minimum_fail_intervals":[{"bounds":[14728116861854887,14728116861854890],"rgb":"#89BB09"},{"bounds":[3708412386652940,3708412386652943],"rgb":"#8212DB"}],"minimum_fail_margin":3268,"minimum_pass_intervals":[{"bounds":[22947817375997342,22947817375997345],"rgb":"#32F120"},{"bounds":[6448312558033241,6448312558033244],"rgb":"#BF39C2"}],"minimum_pass_margin":12132,"threshold":"3.0","unresolved":0},{"candidate_checks":0,"integer_law":{"dark_factor":180,"light_factor":40,"offset_factor":7},"minimum_fail_intervals":[{"bounds":[9920609921116460,9920609921116463],"rgb":"#898CB8"},{"bounds":[803460098399708,803460098399711],"rgb":"#3E2217"}],"minimum_fail_margin":36696,"minimum_pass_intervals":[{"bounds":[9070597544121535,9070597544121538],"rgb":"#BE64DB"},{"bounds":[614568459067254,614568459067257],"rgb":"#480B1D"}],"minimum_pass_margin":7364,"threshold":"4.5","unresolved":0}],"unique_intervals":16777216,"verifier_sha256":"0e5cac77e57fdfa57a914093e28e7ed43bf2e9eb23b39dabc1e2c67d8ac25d83"}
|
package/index.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export type ProgramUpdateOperation = "updateObserved" | "updateUnknown";
|
|
|
82
82
|
export type ProgramError = Error & (
|
|
83
83
|
| Readonly<{ code: ProgramCompileErrorCode; operation: "compileProgramWire" }>
|
|
84
84
|
| Readonly<{ code: ProgramUpdateErrorCode; operation: ProgramUpdateOperation }>
|
|
85
|
+
| Readonly<{ code: "program_resource_exhausted"; operation: "copyOutputTable" }>
|
|
85
86
|
| Readonly<{ code: ProgramAttachmentErrorCode; operation: "attachProgramWire" }>
|
|
86
87
|
| Readonly<{
|
|
87
88
|
code: ProgramAttachmentUpdateErrorCode;
|
package/index.js
CHANGED
|
@@ -402,6 +402,7 @@ export function isProgramError(error) {
|
|
|
402
402
|
if (operation === "updateObserved" || operation === "updateUnknown") {
|
|
403
403
|
return UPDATE_PROGRAM_ERROR_CODES.has(code);
|
|
404
404
|
}
|
|
405
|
+
if (operation === "copyOutputTable") return code === "program_resource_exhausted";
|
|
405
406
|
if (operation === "attachProgramWire") return ATTACHMENT_ERROR_CODES.has(code);
|
|
406
407
|
if (operation === "attachmentUpdateObserved" || operation === "attachmentUpdateUnknown") {
|
|
407
408
|
return ATTACHMENT_UPDATE_ERROR_CODES.has(code);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labpics/colors",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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.d.ts
CHANGED
|
@@ -101,6 +101,11 @@ export class ProgramAttachedSnapshot {
|
|
|
101
101
|
private constructor();
|
|
102
102
|
free(): void;
|
|
103
103
|
[Symbol.dispose](): void;
|
|
104
|
+
/**
|
|
105
|
+
* Независимая JS-копия outputs: строки `[slot, red, green, blue, opacity]`
|
|
106
|
+
* в порядке поштучных геттеров. Состояние snapshot не меняется.
|
|
107
|
+
*/
|
|
108
|
+
copyOutputTable(): Float64Array;
|
|
104
109
|
hasRender(): boolean;
|
|
105
110
|
outputCount(): number;
|
|
106
111
|
outputOpacity(index: number): number;
|
|
@@ -158,6 +163,11 @@ export class ProgramSnapshot {
|
|
|
158
163
|
private constructor();
|
|
159
164
|
free(): void;
|
|
160
165
|
[Symbol.dispose](): void;
|
|
166
|
+
/**
|
|
167
|
+
* Независимая JS-копия outputs: строки `[slot, red, green, blue, opacity]`
|
|
168
|
+
* в порядке поштучных геттеров. Состояние snapshot не меняется.
|
|
169
|
+
*/
|
|
170
|
+
copyOutputTable(): Float64Array;
|
|
161
171
|
outputCount(): number;
|
|
162
172
|
outputOpacity(index: number): number;
|
|
163
173
|
outputRgb(index: number): Uint8Array;
|
|
@@ -230,19 +240,13 @@ export interface InitOutput {
|
|
|
230
240
|
readonly evaluateWcag22: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
231
241
|
readonly issueSourceCertificateEnvelope: (a: number) => void;
|
|
232
242
|
readonly numericalCapabilityManifest: (a: number) => void;
|
|
233
|
-
readonly programattachedrender_bindingEpoch: (a: number) => bigint;
|
|
234
243
|
readonly programattachedrender_contentIdentity: (a: number, b: number) => void;
|
|
235
244
|
readonly programattachedrender_contextIdentity: (a: number, b: number) => void;
|
|
236
245
|
readonly programattachedrender_occurrence: (a: number) => number;
|
|
237
|
-
readonly programattachedrender_outputOpacity: (a: number) => number;
|
|
238
246
|
readonly programattachedrender_outputRgb: (a: number, b: number) => void;
|
|
239
|
-
readonly programattachedrender_outputSlot: (a: number) => number;
|
|
240
247
|
readonly programattachedrender_physicalIdentity: (a: number, b: number) => void;
|
|
241
|
-
readonly programattachedrender_presentationRoot: (a: number) => number;
|
|
242
|
-
readonly programattachedrender_revision: (a: number) => bigint;
|
|
243
|
-
readonly programattachedrender_sinkOutput: (a: number) => number;
|
|
244
|
-
readonly programattachedrender_sinkSequence: (a: number) => bigint;
|
|
245
248
|
readonly programattachedrender_terminalCompositeRgb: (a: number, b: number) => void;
|
|
249
|
+
readonly programattachedsnapshot_copyOutputTable: (a: number, b: number) => void;
|
|
246
250
|
readonly programattachedsnapshot_hasRender: (a: number) => number;
|
|
247
251
|
readonly programattachedsnapshot_outputCount: (a: number) => number;
|
|
248
252
|
readonly programattachedsnapshot_outputOpacity: (a: number, b: number, c: number) => void;
|
|
@@ -257,11 +261,19 @@ export interface InitOutput {
|
|
|
257
261
|
readonly programattachment_updateUnknown: (a: number, b: number, c: number, d: number) => void;
|
|
258
262
|
readonly programruntime_updateObserved: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
259
263
|
readonly programruntime_updateUnknown: (a: number, b: number, c: number, d: number) => void;
|
|
260
|
-
readonly
|
|
264
|
+
readonly programsnapshot_copyOutputTable: (a: number, b: number) => void;
|
|
261
265
|
readonly programsnapshot_outputOpacity: (a: number, b: number, c: number) => void;
|
|
262
266
|
readonly programsnapshot_outputRgb: (a: number, b: number, c: number) => void;
|
|
263
267
|
readonly programsnapshot_outputSlot: (a: number, b: number, c: number) => void;
|
|
264
268
|
readonly programsnapshot_state: (a: number, b: number) => void;
|
|
269
|
+
readonly programsnapshot_outputCount: (a: number) => number;
|
|
270
|
+
readonly programattachedrender_bindingEpoch: (a: number) => bigint;
|
|
271
|
+
readonly programattachedrender_outputOpacity: (a: number) => number;
|
|
272
|
+
readonly programattachedrender_outputSlot: (a: number) => number;
|
|
273
|
+
readonly programattachedrender_presentationRoot: (a: number) => number;
|
|
274
|
+
readonly programattachedrender_revision: (a: number) => bigint;
|
|
275
|
+
readonly programattachedrender_sinkOutput: (a: number) => number;
|
|
276
|
+
readonly programattachedrender_sinkSequence: (a: number) => bigint;
|
|
265
277
|
readonly __wbindgen_export: (a: number) => void;
|
|
266
278
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
267
279
|
readonly __wbindgen_export2: (a: number, b: number) => number;
|
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, copyOutputTable, programError, programFailure } from './snippets/labcolors-wasm-9fb8b927594c3d6f/inline0.js';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export class AttachedMaterializationAuthority {
|
|
@@ -352,6 +352,26 @@ export class ProgramAttachedSnapshot {
|
|
|
352
352
|
const ptr = this.__destroy_into_raw();
|
|
353
353
|
wasm.__wbg_programattachedsnapshot_free(ptr, 0);
|
|
354
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Независимая JS-копия outputs: строки `[slot, red, green, blue, opacity]`
|
|
357
|
+
* в порядке поштучных геттеров. Состояние snapshot не меняется.
|
|
358
|
+
* @returns {Float64Array}
|
|
359
|
+
*/
|
|
360
|
+
copyOutputTable() {
|
|
361
|
+
try {
|
|
362
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
363
|
+
wasm.programattachedsnapshot_copyOutputTable(retptr, this.__wbg_ptr);
|
|
364
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
365
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
366
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
367
|
+
if (r2) {
|
|
368
|
+
throw takeObject(r1);
|
|
369
|
+
}
|
|
370
|
+
return takeObject(r0);
|
|
371
|
+
} finally {
|
|
372
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
355
375
|
/**
|
|
356
376
|
* @returns {boolean}
|
|
357
377
|
*/
|
|
@@ -674,6 +694,26 @@ export class ProgramSnapshot {
|
|
|
674
694
|
const ptr = this.__destroy_into_raw();
|
|
675
695
|
wasm.__wbg_programsnapshot_free(ptr, 0);
|
|
676
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* Независимая JS-копия outputs: строки `[slot, red, green, blue, opacity]`
|
|
699
|
+
* в порядке поштучных геттеров. Состояние snapshot не меняется.
|
|
700
|
+
* @returns {Float64Array}
|
|
701
|
+
*/
|
|
702
|
+
copyOutputTable() {
|
|
703
|
+
try {
|
|
704
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
705
|
+
wasm.programsnapshot_copyOutputTable(retptr, this.__wbg_ptr);
|
|
706
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
707
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
708
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
709
|
+
if (r2) {
|
|
710
|
+
throw takeObject(r1);
|
|
711
|
+
}
|
|
712
|
+
return takeObject(r0);
|
|
713
|
+
} finally {
|
|
714
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
677
717
|
/**
|
|
678
718
|
* @returns {number}
|
|
679
719
|
*/
|
|
@@ -711,13 +751,10 @@ export class ProgramSnapshot {
|
|
|
711
751
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
712
752
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
713
753
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
throw takeObject(r2);
|
|
754
|
+
if (r2) {
|
|
755
|
+
throw takeObject(r1);
|
|
717
756
|
}
|
|
718
|
-
|
|
719
|
-
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
720
|
-
return v1;
|
|
757
|
+
return takeObject(r0);
|
|
721
758
|
} finally {
|
|
722
759
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
723
760
|
}
|
|
@@ -958,6 +995,14 @@ function __wbg_get_imports() {
|
|
|
958
995
|
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
996
|
return addHeapObject(ret);
|
|
960
997
|
},
|
|
998
|
+
__wbg_copyOutputRgb_9c1248136397e8f7: function() { return handleError(function (arg0, arg1, arg2) {
|
|
999
|
+
const ret = copyOutputRgb(arg0, arg1, arg2);
|
|
1000
|
+
return addHeapObject(ret);
|
|
1001
|
+
}, arguments); },
|
|
1002
|
+
__wbg_copyOutputTable_00ec0bd65e911c91: function() { return handleError(function (arg0, arg1) {
|
|
1003
|
+
const ret = copyOutputTable(getArrayF64FromWasm0(arg0, arg1));
|
|
1004
|
+
return addHeapObject(ret);
|
|
1005
|
+
}, arguments); },
|
|
961
1006
|
__wbg_new_da52cf8fe3429cb2: function() {
|
|
962
1007
|
const ret = new Object();
|
|
963
1008
|
return addHeapObject(ret);
|
|
@@ -1051,6 +1096,11 @@ function dropObject(idx) {
|
|
|
1051
1096
|
heap_next = idx;
|
|
1052
1097
|
}
|
|
1053
1098
|
|
|
1099
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
1100
|
+
ptr = ptr >>> 0;
|
|
1101
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1054
1104
|
function getArrayU8FromWasm0(ptr, len) {
|
|
1055
1105
|
ptr = ptr >>> 0;
|
|
1056
1106
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
@@ -1064,6 +1114,14 @@ function getDataViewMemory0() {
|
|
|
1064
1114
|
return cachedDataViewMemory0;
|
|
1065
1115
|
}
|
|
1066
1116
|
|
|
1117
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
1118
|
+
function getFloat64ArrayMemory0() {
|
|
1119
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
1120
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
1121
|
+
}
|
|
1122
|
+
return cachedFloat64ArrayMemory0;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1067
1125
|
function getStringFromWasm0(ptr, len) {
|
|
1068
1126
|
return decodeText(ptr >>> 0, len);
|
|
1069
1127
|
}
|
|
@@ -1197,6 +1255,7 @@ function __wbg_finalize_init(instance, module) {
|
|
|
1197
1255
|
wasm = instance.exports;
|
|
1198
1256
|
wasmModule = module;
|
|
1199
1257
|
cachedDataViewMemory0 = null;
|
|
1258
|
+
cachedFloat64ArrayMemory0 = null;
|
|
1200
1259
|
cachedUint32ArrayMemory0 = null;
|
|
1201
1260
|
cachedUint8ArrayMemory0 = null;
|
|
1202
1261
|
return wasm;
|
package/pkg/labcolors_bg.wasm
CHANGED
|
Binary file
|
|
@@ -26,19 +26,13 @@ export const decodeCertificateEnvelope: (a: number, b: number, c: number) => voi
|
|
|
26
26
|
export const evaluateWcag22: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
27
27
|
export const issueSourceCertificateEnvelope: (a: number) => void;
|
|
28
28
|
export const numericalCapabilityManifest: (a: number) => void;
|
|
29
|
-
export const programattachedrender_bindingEpoch: (a: number) => bigint;
|
|
30
29
|
export const programattachedrender_contentIdentity: (a: number, b: number) => void;
|
|
31
30
|
export const programattachedrender_contextIdentity: (a: number, b: number) => void;
|
|
32
31
|
export const programattachedrender_occurrence: (a: number) => number;
|
|
33
|
-
export const programattachedrender_outputOpacity: (a: number) => number;
|
|
34
32
|
export const programattachedrender_outputRgb: (a: number, b: number) => void;
|
|
35
|
-
export const programattachedrender_outputSlot: (a: number) => number;
|
|
36
33
|
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
34
|
export const programattachedrender_terminalCompositeRgb: (a: number, b: number) => void;
|
|
35
|
+
export const programattachedsnapshot_copyOutputTable: (a: number, b: number) => void;
|
|
42
36
|
export const programattachedsnapshot_hasRender: (a: number) => number;
|
|
43
37
|
export const programattachedsnapshot_outputCount: (a: number) => number;
|
|
44
38
|
export const programattachedsnapshot_outputOpacity: (a: number, b: number, c: number) => void;
|
|
@@ -53,11 +47,19 @@ export const programattachment_updateObserved: (a: number, b: number, c: number,
|
|
|
53
47
|
export const programattachment_updateUnknown: (a: number, b: number, c: number, d: number) => void;
|
|
54
48
|
export const programruntime_updateObserved: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
55
49
|
export const programruntime_updateUnknown: (a: number, b: number, c: number, d: number) => void;
|
|
56
|
-
export const
|
|
50
|
+
export const programsnapshot_copyOutputTable: (a: number, b: number) => void;
|
|
57
51
|
export const programsnapshot_outputOpacity: (a: number, b: number, c: number) => void;
|
|
58
52
|
export const programsnapshot_outputRgb: (a: number, b: number, c: number) => void;
|
|
59
53
|
export const programsnapshot_outputSlot: (a: number, b: number, c: number) => void;
|
|
60
54
|
export const programsnapshot_state: (a: number, b: number) => void;
|
|
55
|
+
export const programsnapshot_outputCount: (a: number) => number;
|
|
56
|
+
export const programattachedrender_bindingEpoch: (a: number) => bigint;
|
|
57
|
+
export const programattachedrender_outputOpacity: (a: number) => number;
|
|
58
|
+
export const programattachedrender_outputSlot: (a: number) => number;
|
|
59
|
+
export const programattachedrender_presentationRoot: (a: number) => number;
|
|
60
|
+
export const programattachedrender_revision: (a: number) => bigint;
|
|
61
|
+
export const programattachedrender_sinkOutput: (a: number) => number;
|
|
62
|
+
export const programattachedrender_sinkSequence: (a: number) => bigint;
|
|
61
63
|
export const __wbindgen_export: (a: number) => void;
|
|
62
64
|
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
63
65
|
export const __wbindgen_export2: (a: number, b: number) => number;
|
|
@@ -49,6 +49,21 @@ export function bindingFailure(kind, reason) {
|
|
|
49
49
|
return programError(code + ": " + reason, code, operation);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const OutputRgbArray = Uint8Array;
|
|
53
|
+
const OutputTableArray = Float64Array;
|
|
54
|
+
|
|
55
|
+
export function copyOutputRgb(red, green, blue) {
|
|
56
|
+
const bytes = new OutputRgbArray(3);
|
|
57
|
+
bytes[0] = red;
|
|
58
|
+
bytes[1] = green;
|
|
59
|
+
bytes[2] = blue;
|
|
60
|
+
return bytes;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function copyOutputTable(values) {
|
|
64
|
+
return new OutputTableArray(values);
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
export function certificateError(code, operation) {
|
|
53
68
|
return programError(
|
|
54
69
|
"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
|
-
|