@native-sdk/cli 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +73 -37
- package/build.zig +239 -5
- package/native-sdk.d.ts +5 -1
- package/package.json +13 -12
- package/packages/core/compile-surface/core.ts +30 -0
- package/packages/core/package-lock.json +6 -6
- package/packages/core/package.json +3 -3
- package/packages/core/scripts/scriptc-toolchain.json +44 -44
- package/packages/core/scripts/stage_external_core.mjs +27 -16
- package/packages/core/sdk/core.d.ts +24 -1
- package/packages/core/sdk/core.ts +51 -1
- package/packages/core/sdk/events.d.ts +5 -0
- package/packages/core/sdk/events.ts +10 -0
- package/packages/core/src/bridge_descriptors.ts +3 -3
- package/packages/core/src/checker.ts +20 -0
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/portable_sources.json +24 -0
- package/packages/core/src/registered_font.ts +2 -3
- package/packages/core/src/runtime_policy.ts +24 -0
- package/packages/core/src/scalar_text.ts +1 -3
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +53 -2
- package/packages/core/src/sqlite_cli.ts +3 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +340 -218
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/skill-data/native-ui/SKILL.md +2 -2
- package/skill-data/ts-core/SKILL.md +5 -3
- package/skill-data/ts-services/references/service-surface.md +29 -5
- package/src/app_runner/root.zig +14 -0
- package/src/app_runner/ts_compiled_view.zig +88 -17
- package/src/app_runner/ts_core_main.zig +43 -5
- package/src/app_runner/ts_core_mobile.zig +1 -1
- package/src/automation/server.zig +56 -3
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +31 -9
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/null_platform.zig +104 -0
- package/src/platform/root.zig +14 -0
- package/src/platform/types.zig +102 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +15 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/reference.zig +3 -5
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +1 -1
- package/src/primitives/canvas/root.zig +7 -4
- package/src/primitives/canvas/text_metrics.zig +32 -39
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +142 -3
- package/src/primitives/canvas/text_scalar_policy.zig +80 -2
- package/src/primitives/canvas/tokens.zig +9 -0
- package/src/primitives/canvas/ui.zig +1 -0
- package/src/primitives/canvas/ui_markup.zig +69 -14
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +2817 -74
- package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
- package/src/primitives/canvas/virtual_extents.zig +47 -33
- package/src/primitives/canvas/widget_metric_policy.zig +4 -1
- package/src/primitives/canvas/widget_runtime.zig +2 -1
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +1 -0
- package/src/runtime/bridge_descriptor_policy.zig +1 -1
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/canvas_widget_context_menu.zig +179 -0
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_runtime.zig +306 -92
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +14 -0
- package/src/runtime/effects.zig +172 -4
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/flow.zig +1 -0
- package/src/runtime/flow_reference.zig +1 -0
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/root.zig +3 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_record.zig +7 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/system_services.zig +19 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +126 -0
- package/src/runtime/ts_ui_app.zig +24 -0
- package/src/runtime/ui_app.zig +274 -31
- package/src/runtime/ui_app_tests.zig +48 -179
- package/src/runtime/ui_app_window_tests.zig +133 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_scroll.zig +30 -21
- package/src/runtime/view_widget_tree.zig +43 -13
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_views.zig +19 -4
- package/src/security/root.zig +1 -0
- package/src/tooling/templates.zig +8 -0
- package/src/tooling/ts_core.zig +84 -1
- package/src/tooling/verbs.zig +79 -15
- package/tools/corewire/core.test.ts +25 -3
- package/tools/corewire/core_abi.zig +4 -0
- package/tools/corewire/core_contract.ts +1 -1
- package/tools/corewire/core_goldens.json +75 -75
- package/tools/corewire/core_projection.ts +3 -2
- package/tools/corewire/emit_mirror.ts +19 -9
- package/tools/corewire/facade_templates.ts +1 -1
- package/tools/corewire/intake.test.ts +4 -0
- package/tools/corewire/intake_goldens.json +50 -50
- package/tools/corewire/invocation.test.ts +4 -0
- package/tools/corewire/invocation_goldens.json +3 -3
- package/tools/corewire/mirror_templates.ts +4 -0
- package/tools/corewire/profile_emission.ts +2 -0
- package/tools/corewire/sidecar.zig +2 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/** Runtime value, typed-message and binding programs (113). Native capabilities
|
|
2
|
+
* expose reflected types and exact numeric/storage facts; no pointer or i64 is
|
|
3
|
+
* transported through the numeric program fields. All names remain raw bytes.
|
|
4
|
+
*/
|
|
5
|
+
function nscmDot(path: Uint8Array): number {
|
|
6
|
+
for (let i = 0; i < path.length; i++) if (path[i] === 46) return i;
|
|
7
|
+
return -1;
|
|
8
|
+
}
|
|
9
|
+
function nscmIcon(r: NscElementReader, out: number[]): void {
|
|
10
|
+
const raw = r.blob(), names = r.names(), classification: number[] = [];
|
|
11
|
+
// Icons deliberately use raw expression grammar, even with a typed cache.
|
|
12
|
+
nsccAttribute(classification, 0, new Uint8Array(0), raw);
|
|
13
|
+
const kind = classification[1]!;
|
|
14
|
+
if (kind === 2) { nsceEmit(out, 73); return; }
|
|
15
|
+
if (kind !== 1) { nsceFail(out, 42); return; }
|
|
16
|
+
if (raw.length >= 4 && nsceNamed(raw.subarray(0, 4), "app:")) {
|
|
17
|
+
let dash = true;
|
|
18
|
+
for (let i = 4; i < raw.length; i++) {
|
|
19
|
+
const byte = raw[i]!;
|
|
20
|
+
if (byte >= 97 && byte <= 122 || byte >= 48 && byte <= 57) dash = false;
|
|
21
|
+
else if (byte === 45 && !dash) dash = true;
|
|
22
|
+
else { nsceFail(out, 43); return; }
|
|
23
|
+
}
|
|
24
|
+
if (dash) nsceFail(out, 43);
|
|
25
|
+
else nsceEmit(out, 72, 1);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
for (const byte of raw) if (byte === 58) { nsceFail(out, 44); return; }
|
|
29
|
+
if (nsceIn(raw, names)) nsceEmit(out, 72);
|
|
30
|
+
else nsceFail(out, 42);
|
|
31
|
+
}
|
|
32
|
+
function nscmTrim(bytes: Uint8Array, start: number, end: number, newlines: boolean): number[] {
|
|
33
|
+
while (start < end && (bytes[start] === 32 || bytes[start] === 9 || newlines && (bytes[start] === 13 || bytes[start] === 10))) start++;
|
|
34
|
+
while (end > start && (bytes[end - 1] === 32 || bytes[end - 1] === 9 || newlines && (bytes[end - 1] === 13 || bytes[end - 1] === 10))) end--;
|
|
35
|
+
return [start, end];
|
|
36
|
+
}
|
|
37
|
+
function nscmLanguage(r: NscElementReader, out: number[]): void {
|
|
38
|
+
const raw = r.blob(), names = r.names(), span = nscmTrim(raw, 0, raw.length, true), folded = raw.slice(span[0]!, span[1]!);
|
|
39
|
+
for (let i = 0; i < folded.length; i++) if (folded[i]! >= 65 && folded[i]! <= 90) folded[i] = folded[i]! + 32;
|
|
40
|
+
const groups = ["plain text", "zig", "js mjs javascript", "ts typescript", "json jsonc", "yaml yml", "sh bash zsh shell", "py python", "rs rust", "c h cc cpp c++ cs csharp java kotlin swift", "go golang", "html xml svg", "css scss less", "sql", "jsx", "tsx", "md markdown"];
|
|
41
|
+
const canonical = ["plain", "zig", "javascript", "typescript", "json", "yaml", "shell", "python", "rust", "c_like", "go", "html", "css", "sql", "jsx", "tsx", "markdown"];
|
|
42
|
+
for (let i = 0; i < groups.length; i++) for (const alias of groups[i]!.split(" ")) if (nsceNamed(folded, alias)) {
|
|
43
|
+
for (let j = 0; j < names.length; j++) if (nsceNamed(names[j]!, canonical[i]!)) { nsceEmit(out, 76, 0, j); return; }
|
|
44
|
+
throw new Error("missing native code language capability");
|
|
45
|
+
}
|
|
46
|
+
nsceFail(out, 45);
|
|
47
|
+
}
|
|
48
|
+
function nscmLinePieces(r: NscElementReader, out: number[]): void {
|
|
49
|
+
const spec = r.blob(), span = nscmTrim(spec, 0, spec.length, true), end = span[1]!;
|
|
50
|
+
let start = span[0]!;
|
|
51
|
+
if (start === end) { nsceEmit(out, 200); return; }
|
|
52
|
+
while (start <= end) {
|
|
53
|
+
let stop = start; while (stop < end && spec[stop] !== 44) stop++;
|
|
54
|
+
const piece = nscmTrim(spec, start, stop, true), first = piece[0]!, last = piece[1]!;
|
|
55
|
+
if (first === last) { nsceFail(out, 46); return; }
|
|
56
|
+
let dash = -1;
|
|
57
|
+
for (let i = first; i < last; i++) if (spec[i] === 45) {
|
|
58
|
+
if (dash >= 0) { nsceFail(out, 46); return; }
|
|
59
|
+
dash = i;
|
|
60
|
+
}
|
|
61
|
+
const a = nscmTrim(spec, first, dash < 0 ? last : dash, false);
|
|
62
|
+
const b = dash < 0 ? a : nscmTrim(spec, dash + 1, last, false);
|
|
63
|
+
if (a[0] === a[1] || b[0] === b[1]) { nsceFail(out, 46); return; }
|
|
64
|
+
// Exact usize conversion runs natively, in order, before the next piece.
|
|
65
|
+
out.push(77, 0, a[0]!, a[1]!, b[0]!, b[1]!, 0);
|
|
66
|
+
if (stop === end) break;
|
|
67
|
+
start = stop + 1;
|
|
68
|
+
}
|
|
69
|
+
nsceEmit(out, 200);
|
|
70
|
+
}
|
|
71
|
+
function nscmLineRange(r: NscElementReader, out: number[]): void {
|
|
72
|
+
const firstValid = r.flag(), firstWithin = r.flag(), first = r.word();
|
|
73
|
+
const lastValid = r.flag(), lastWithin = r.flag(), last = r.word(), capacity = r.word(), count = r.word(), lines: number[] = [];
|
|
74
|
+
if (count > capacity) throw new Error("invalid native line storage");
|
|
75
|
+
for (let i = 0; i < count; i++) { const line = r.word(); if (line === 0 || line > capacity) throw new Error("invalid stored line"); lines.push(line); }
|
|
76
|
+
if (!firstValid || !lastValid || !firstWithin || !lastWithin || first === 0 || last < first || last > capacity) { nsceFail(out, 46); return; }
|
|
77
|
+
for (let line = first; line <= last; line++) {
|
|
78
|
+
let duplicate = false; for (const stored of lines) if (stored === line) duplicate = true;
|
|
79
|
+
if (duplicate) continue;
|
|
80
|
+
if (lines.length === capacity) { nsceFail(out, 46); return; }
|
|
81
|
+
nsceEmit(out, 78, 0, lines.length, line); lines.push(line);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function nscmValues(r: NscElementReader, out: number[], mode: number): void {
|
|
85
|
+
if (mode === 0) {
|
|
86
|
+
const channel = r.word(), name = r.blob(), binding = r.flag();
|
|
87
|
+
if (channel > 2) throw new Error("invalid resource channel");
|
|
88
|
+
const element = channel === 0 ? nsceOne(name, ["avatar", "image"]) : nsceNamed(name, channel === 1 ? "media-surface" : "terminal");
|
|
89
|
+
if (!element) nsceFail(out, channel * 2 + 1);
|
|
90
|
+
else if (!binding) nsceFail(out, channel * 2 + 2);
|
|
91
|
+
else nsceEmit(out, 1);
|
|
92
|
+
} else if (mode === 1) {
|
|
93
|
+
const channel = r.word(), kind = r.word(), nonnegative = r.flag();
|
|
94
|
+
if (channel > 2 || kind > 3) throw new Error("invalid resource value");
|
|
95
|
+
if (kind === 0 && nonnegative) nsceEmit(out, 2);
|
|
96
|
+
else if (channel === 2 && kind === 3) nsceEmit(out, 3);
|
|
97
|
+
else nsceFail(out, channel * 2 + 2);
|
|
98
|
+
} else if (mode === 2) {
|
|
99
|
+
const family = r.word(), name = r.blob(), eligible = r.names();
|
|
100
|
+
if (family > 2) throw new Error("invalid element family");
|
|
101
|
+
if (nsceIn(name, eligible)) nsceEmit(out, 1);
|
|
102
|
+
else nsceFail(out, family === 0 ? 7 : family === 1 ? 8 : 9);
|
|
103
|
+
} else if (mode === 3) {
|
|
104
|
+
const kind = r.word(), phase = r.word(), anchor = r.flag(), valid = r.flag();
|
|
105
|
+
if (kind > 2 || phase > 1) throw new Error("invalid anchor phase");
|
|
106
|
+
if (phase === 0 && kind !== 0 && !anchor) nsceFail(out, 10);
|
|
107
|
+
else if (phase === 1 && !valid) nsceFail(out, 11 + kind);
|
|
108
|
+
else nsceEmit(out, 1);
|
|
109
|
+
} else if (mode === 4 || mode === 5) {
|
|
110
|
+
const type = r.word(), kind = r.word(), withinRange = r.flag();
|
|
111
|
+
if (type > 5 || kind > 3) throw new Error("invalid typed value fact");
|
|
112
|
+
const admitted = type === 1 ? kind === 0 || kind === 1 : type === 2 ? true : type === 3 || type === 5 ? kind === 3 : type === 4 ? kind === 0 && withinRange : false;
|
|
113
|
+
if (admitted) nsceEmit(out, type);
|
|
114
|
+
else if (mode === 5) nsceFail(out, 27);
|
|
115
|
+
else nsceFail(out, type === 1 ? 20 : type === 3 ? 21 : type === 4 ? kind === 0 ? 23 : 24 : type === 5 ? 26 : 25);
|
|
116
|
+
} else if (mode === 6) {
|
|
117
|
+
const drag = r.flag(), tag = r.blob(), payload = r.flag(), names = r.names(), classes: number[] = [];
|
|
118
|
+
for (let i = 0; i < names.length; i++) { const kind = r.word(); if (kind > 2) throw new Error("invalid message type"); classes.push(kind); }
|
|
119
|
+
if (drag && !payload) { nsceFail(out, 31); return; }
|
|
120
|
+
for (let i = 0; i < names.length; i++) if (nsceEqual(tag, names[i]!)) {
|
|
121
|
+
const kind = classes[i]!;
|
|
122
|
+
if (drag) { if (kind !== 2) nsceFail(out, 31); else nsceEmit(out, 42, 0, i); }
|
|
123
|
+
else if (kind === 0) { if (payload) nsceFail(out, 28); else nsceEmit(out, 40, 0, i); }
|
|
124
|
+
else if (!payload) nsceFail(out, 29);
|
|
125
|
+
else nsceEmit(out, 41, 0, i);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
nsceFail(out, drag ? 31 : 30);
|
|
129
|
+
} else if (mode === 7) {
|
|
130
|
+
const tag = r.blob(), names = r.names(), classes: number[] = [];
|
|
131
|
+
for (let i = 0; i < names.length; i++) { const kind = r.word(); if (kind > 2) throw new Error("invalid callback class"); classes.push(kind); }
|
|
132
|
+
for (let i = 0; i < names.length; i++) if (classes[i] !== 0 && nsceEqual(tag, names[i]!)) { nsceEmit(out, 43, 0, i, classes[i]!); return; }
|
|
133
|
+
nsceEmit(out, 0);
|
|
134
|
+
} else if (mode === 8) {
|
|
135
|
+
const kind = r.word(), aware = r.flag();
|
|
136
|
+
if (kind > 5) throw new Error("invalid attribute kind");
|
|
137
|
+
if (kind === 0) nsceEmit(out, aware ? 50 : 51);
|
|
138
|
+
else if (kind === 1) nsceEmit(out, 52);
|
|
139
|
+
else if (kind === 2) { nsceEmit(out, 53); nsceEmit(out, 54); nsceEmit(out, 55); }
|
|
140
|
+
else if (kind === 3) nsceEmit(out, 56);
|
|
141
|
+
else nsceFail(out, 32);
|
|
142
|
+
} else if (mode === 9) {
|
|
143
|
+
nsceEmit(out, r.flag() ? 57 : 58);
|
|
144
|
+
} else if (mode === 10) {
|
|
145
|
+
const count = r.word();
|
|
146
|
+
for (let i = 0; i < count; i++) {
|
|
147
|
+
const binding = r.flag(), comparison = r.flag();
|
|
148
|
+
if (binding) nsceEmit(out, 59, 0, i, comparison ? 0 : 1);
|
|
149
|
+
}
|
|
150
|
+
nsceEmit(out, 60);
|
|
151
|
+
} else if (mode === 11) {
|
|
152
|
+
const path = r.blob(), floor = r.word(), names = r.names(), classes: number[] = [];
|
|
153
|
+
if (floor > names.length) throw new Error("invalid binding floor");
|
|
154
|
+
for (let i = 0; i < names.length; i++) { const kind = r.word(); if (kind > 4) throw new Error("invalid scope payload"); classes.push(kind); }
|
|
155
|
+
const dot = nscmDot(path), head = path.subarray(0, dot < 0 ? path.length : dot), tail = dot + 1;
|
|
156
|
+
for (let i = names.length - 1; i >= floor; i--) if (nsceEqual(head, names[i]!)) {
|
|
157
|
+
const kind = classes[i]!;
|
|
158
|
+
if (kind === 0) nsceEmit(out, dot < 0 ? 62 : 61, 0, i, tail);
|
|
159
|
+
else if (kind === 1) nsceFail(out, 36);
|
|
160
|
+
else if (kind === 2) { if (dot >= 0) nsceFail(out, 37); else nsceEmit(out, 63, 0, i); }
|
|
161
|
+
else if (kind === 3) { if (dot < 0) nsceFail(out, 41); else nsceEmit(out, 64, 0, i, tail); }
|
|
162
|
+
else throw new Error("named slot capture is unreachable");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
nsceEmit(out, 65, 0, head.length);
|
|
166
|
+
} else if (mode === 12) {
|
|
167
|
+
const domain = r.word(), phase = r.word(), present = r.flag(), allowArena = r.flag();
|
|
168
|
+
if (domain > 3 || phase > 2) throw new Error("invalid binding resolution phase");
|
|
169
|
+
if (phase === 2) { nsceFail(out, present ? 38 : 39); return; }
|
|
170
|
+
if (phase === 1 && present) { nsceFail(out, 33); return; }
|
|
171
|
+
if (present) { nsceEmit(out, 66); return; }
|
|
172
|
+
if (phase === 0 && domain < 2 && !allowArena) nsceEmit(out, 67);
|
|
173
|
+
else if (domain === 1) nsceEmit(out, 75);
|
|
174
|
+
else nsceFail(out, domain === 0 ? 34 : domain === 2 ? 40 : 35);
|
|
175
|
+
} else if (mode === 13) {
|
|
176
|
+
const type = r.word(), path = r.blob(), arena = r.flag(), fields = r.names(), declarations = r.names(), classes: number[] = [];
|
|
177
|
+
if (type > 2) throw new Error("invalid reflected binding type");
|
|
178
|
+
for (let i = 0; i < declarations.length; i++) { const kind = r.word(); if (kind > 2) throw new Error("invalid declaration class"); classes.push(kind); }
|
|
179
|
+
if (type === 2) { nsceEmit(out, 70); return; }
|
|
180
|
+
if (type === 0) { nsceEmit(out, 0); return; }
|
|
181
|
+
const dot = nscmDot(path), head = path.subarray(0, dot < 0 ? path.length : dot);
|
|
182
|
+
for (let i = 0; i < fields.length; i++) if (nsceEqual(head, fields[i]!)) { nsceEmit(out, 68, 0, i, dot + 1); return; }
|
|
183
|
+
if (dot < 0) for (let i = 0; i < declarations.length; i++) if (classes[i] !== 0 && nsceEqual(head, declarations[i]!)) {
|
|
184
|
+
if (classes[i] === 2 && !arena) nsceEmit(out, 0);
|
|
185
|
+
else nsceEmit(out, 69, 0, i, classes[i]!);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
nsceEmit(out, 0);
|
|
189
|
+
} else if (mode === 14) {
|
|
190
|
+
nscmIcon(r, out);
|
|
191
|
+
} else if (mode === 15) {
|
|
192
|
+
const text = r.blob(), names = r.names();
|
|
193
|
+
for (let i = 0; i < names.length; i++) if (nsceEqual(text, names[i]!)) { nsceEmit(out, 74, 0, i); return; }
|
|
194
|
+
nsceEmit(out, 0);
|
|
195
|
+
} else if (mode === 16) nscmLanguage(r, out);
|
|
196
|
+
else if (mode === 17) nscmLinePieces(r, out);
|
|
197
|
+
else if (mode === 18) nscmLineRange(r, out);
|
|
198
|
+
else if (mode === 19) {
|
|
199
|
+
const raw = r.blob(), names = r.names();
|
|
200
|
+
const area = nsceNamed(raw, "area");
|
|
201
|
+
const canonical = area || nsceNamed(raw, "line") ? "line" : nsceNamed(raw, "bar") ? "bar" : "";
|
|
202
|
+
if (canonical === "") { nsceFail(out, 47); return; }
|
|
203
|
+
for (let i = 0; i < names.length; i++) if (nsceNamed(names[i]!, canonical)) { nsceEmit(out, 79, area ? 1 : 0, i); return; }
|
|
204
|
+
throw new Error("missing native chart kind capability");
|
|
205
|
+
} else if (mode === 20) {
|
|
206
|
+
// Native conversion precedes admission; these are the exact IEEE f32 bits.
|
|
207
|
+
const bits = r.word();
|
|
208
|
+
if (bits > 0xffffffff) throw new Error("invalid native f32 representation");
|
|
209
|
+
if (bits > 0 && bits < 0x7f800000) nsceEmit(out, 1);
|
|
210
|
+
else nsceFail(out, 48);
|
|
211
|
+
} else if (mode === 21) {
|
|
212
|
+
const channel = r.word(), kind = r.word(), low = r.word(), high = r.word(), capacity = r.word();
|
|
213
|
+
if (channel > 2 || kind > 3 || low > 0xffffffff || high > 0xffffffff || capacity > 255) throw new Error("invalid numeric option channel");
|
|
214
|
+
if (kind !== 0) { nsceFail(out, channel === 0 ? 50 : channel === 1 ? 52 : 53); return; }
|
|
215
|
+
// Exact two's-complement i64 words never pass through a floating conversion.
|
|
216
|
+
if (channel === 0) {
|
|
217
|
+
if (high <= 0x1fffff) nsceEmit(out, 1);
|
|
218
|
+
else nsceFail(out, 49);
|
|
219
|
+
} else if (channel === 1) nsceEmit(out, high >= 0x80000000 ? 2 : 1);
|
|
220
|
+
else if (high === 0 && low <= capacity) nsceEmit(out, 1);
|
|
221
|
+
else nsceFail(out, 54);
|
|
222
|
+
} else if (mode === 22) {
|
|
223
|
+
const bits = r.word();
|
|
224
|
+
if (bits > 0xffffffff) throw new Error("invalid native f32 representation");
|
|
225
|
+
if (bits < 0x7f800000 || bits === 0x80000000) nsceEmit(out, 1);
|
|
226
|
+
else nsceFail(out, 51);
|
|
227
|
+
} else if (mode === 23) {
|
|
228
|
+
const raw = r.blob(), names = r.names(), selected = nsceNamed(raw, "trailing") ? "trailing" : "leading";
|
|
229
|
+
for (let i = 0; i < names.length; i++) if (nsceNamed(names[i]!, selected)) { nsceEmit(out, 80, 0, i); return; }
|
|
230
|
+
throw new Error("missing native virtual anchor capability");
|
|
231
|
+
} else if (mode === 24) {
|
|
232
|
+
const base = r.word(), count = r.word();
|
|
233
|
+
if (base <= 9007199254740991 - count) nsceEmit(out, 0);
|
|
234
|
+
else nsceFail(out, 55);
|
|
235
|
+
} else if (mode === 25) {
|
|
236
|
+
const bits = r.word(), estimator = r.flag();
|
|
237
|
+
if (bits > 0xffffffff) throw new Error("invalid native f32 representation");
|
|
238
|
+
if (estimator || bits !== 0 && bits !== 0x80000000) nsceEmit(out, 0);
|
|
239
|
+
else nsceFail(out, 56);
|
|
240
|
+
} else if (mode === 26) {
|
|
241
|
+
const channel = r.word(), name = r.blob(), present = r.flag();
|
|
242
|
+
if (channel > 1 || !nsceOne(name, channel === 0 ? ["item-count", "overscan", "index-base"] : ["item-extent", "gap", "viewport-fallback"])) throw new Error("invalid virtual option name");
|
|
243
|
+
if (present) nsceEmit(out, 1);
|
|
244
|
+
else nsceEmit(out, 0, 0, nsceNamed(name, "overscan") ? 4 : 0);
|
|
245
|
+
}
|
|
246
|
+
else if (mode === 27) {
|
|
247
|
+
const channel = r.word(), form = r.word(), payloadLength = r.word();
|
|
248
|
+
if (channel > 13 || form > 5) throw new Error("invalid specialized attribute form");
|
|
249
|
+
const diagnostics = [57, 58, 59, 60, 61, 62, 63, 45, 64, 65, 47, 66, 67, 46];
|
|
250
|
+
const admitted = channel === 1 || channel === 2 ? form === 4 && payloadLength === 0
|
|
251
|
+
: channel === 5 ? form !== 2 && form !== 5
|
|
252
|
+
: channel === 7 || channel === 10 || channel === 12 ? form === 0
|
|
253
|
+
: channel === 8 ? form === 4
|
|
254
|
+
: channel === 13 ? form !== 5
|
|
255
|
+
: form === 1;
|
|
256
|
+
if (!admitted) nsceFail(out, diagnostics[channel]!);
|
|
257
|
+
else nsceEmit(out, channel === 13 && form !== 0 ? 2 : 1);
|
|
258
|
+
} else if (mode === 28) {
|
|
259
|
+
const channel = r.word(), kind = r.word(), length = r.word();
|
|
260
|
+
if (channel > 4 || kind > 3) throw new Error("invalid specialized value kind");
|
|
261
|
+
const diagnostics = [57, 63, 62, 46, 48];
|
|
262
|
+
if (channel === 4) {
|
|
263
|
+
if (kind < 2) nsceEmit(out, kind === 0 ? 2 : 1);
|
|
264
|
+
else nsceFail(out, 48);
|
|
265
|
+
} else if (kind !== 3) nsceFail(out, diagnostics[channel]!);
|
|
266
|
+
else nsceEmit(out, channel === 2 && length === 0 ? 0 : 1);
|
|
267
|
+
} else if (mode === 29) {
|
|
268
|
+
// Raw empty presence wins even when a typed cache says otherwise.
|
|
269
|
+
nsceEmit(out, r.word() === 0 ? 1 : 2);
|
|
270
|
+
} else if (mode === 30) {
|
|
271
|
+
const phase = r.word();
|
|
272
|
+
if (phase === 0) {
|
|
273
|
+
const count = r.word(), firstKind = r.blob();
|
|
274
|
+
nsceEmit(out, count === 1 && nsceNamed(firstKind, "slot_block") ? 2 : 1);
|
|
275
|
+
} else if (phase === 1) {
|
|
276
|
+
if (r.flag()) nsceEmit(out, 1);
|
|
277
|
+
else nsceFail(out, 68);
|
|
278
|
+
} else throw new Error("invalid stepper capture phase");
|
|
279
|
+
} else if (mode === 31) {
|
|
280
|
+
const phase = r.word();
|
|
281
|
+
if (phase === 0) {
|
|
282
|
+
const raw = r.blob(), aware = r.flag(), name = r.blob(), textNames = r.names();
|
|
283
|
+
// Schema text takes precedence even over exact boolean and numeric text.
|
|
284
|
+
// Conversion is requested in order; exact native values stay native.
|
|
285
|
+
if (aware && nsceIn(name, textNames)) nsceEmit(out, 81);
|
|
286
|
+
else if (nsceNamed(raw, "true")) nsceEmit(out, 82, 1);
|
|
287
|
+
else if (nsceNamed(raw, "false")) nsceEmit(out, 82);
|
|
288
|
+
else nsceEmit(out, 83);
|
|
289
|
+
} else if (phase === 1) nsceEmit(out, r.flag() ? 84 : 85);
|
|
290
|
+
else if (phase === 2) nsceEmit(out, r.flag() ? 86 : 81);
|
|
291
|
+
else throw new Error("invalid literal inference phase");
|
|
292
|
+
} else if (mode === 32) {
|
|
293
|
+
const length = r.word(), floor = r.word();
|
|
294
|
+
if (floor > length) throw new Error("invalid capture floor");
|
|
295
|
+
let selected = 0;
|
|
296
|
+
for (let i = 0; i < length; i++) {
|
|
297
|
+
const slot = r.flag();
|
|
298
|
+
// An empty capture still shadows every outer capture.
|
|
299
|
+
if (i >= floor && slot) selected = i + 1;
|
|
300
|
+
}
|
|
301
|
+
nsceEmit(out, 87, 0, selected);
|
|
302
|
+
} else if (mode === 33) {
|
|
303
|
+
const press = r.flag(), provenance = r.flag();
|
|
304
|
+
// Root construction can fail before either postprocessing capability runs.
|
|
305
|
+
nsceEmit(out, 88);
|
|
306
|
+
if (press) nsceEmit(out, 89);
|
|
307
|
+
if (provenance) nsceEmit(out, 90);
|
|
308
|
+
nsceEmit(out, 91);
|
|
309
|
+
} else if (mode === 34) {
|
|
310
|
+
const count = r.word();
|
|
311
|
+
for (let i = 0; i < count; i++) {
|
|
312
|
+
// Toggle buttons retain their distinct on-toggle contract.
|
|
313
|
+
if (nsceNamed(r.blob(), "button")) nsceEmit(out, 92, 0, i);
|
|
314
|
+
}
|
|
315
|
+
} else if (mode === 35) {
|
|
316
|
+
const path = r.blob(), dot = nscmDot(path);
|
|
317
|
+
// Return borrowed byte offsets; a trailing dot has a present empty tail.
|
|
318
|
+
nsceEmit(out, 93, 0, dot < 0 ? path.length : dot, dot < 0 ? 0 : dot + 1);
|
|
319
|
+
} else if (mode === 36) {
|
|
320
|
+
// A use-site handler replaces the local timeline handler before construction.
|
|
321
|
+
nsceEmit(out, r.flag() ? 1 : 0);
|
|
322
|
+
} else throw new Error("invalid markup value mode");
|
|
323
|
+
}
|
|
324
|
+
function nscvMarkupValues(input: Uint8Array): Uint8Array {
|
|
325
|
+
if (input.length < 4 || input[0] !== 113 || input[1] !== 1 || input[2]! > 36 || input[3]! > 1) throw new Error("invalid markup value header");
|
|
326
|
+
const r = new NscElementReader(input), out: number[] = [];
|
|
327
|
+
nscmValues(r, out, input[2]!);
|
|
328
|
+
if (r.at !== input.length) throw new Error("trailing markup value facts");
|
|
329
|
+
const count = out.length / 7, bytes = new Uint8Array(input[3] === 0 ? 16 : 16 + count * 48), wire = new DataView(bytes.buffer);
|
|
330
|
+
bytes[0] = 113; bytes[1] = 1; bytes[2] = input[3]!; wire.setFloat64(8, count, true);
|
|
331
|
+
if (input[3] === 1) for (let i = 0; i < count; i++) {
|
|
332
|
+
const at = 16 + i * 48, from = i * 7; bytes[at] = out[from]!; bytes[at + 1] = out[from + 1]!;
|
|
333
|
+
for (let j = 0; j < 5; j++) wire.setFloat64(at + 8 + j * 8, out[from + j + 2]!, true);
|
|
334
|
+
}
|
|
335
|
+
return bytes;
|
|
336
|
+
}
|
|
@@ -51,6 +51,30 @@
|
|
|
51
51
|
"src/widget_audits.ts",
|
|
52
52
|
"src/widget_routing.ts",
|
|
53
53
|
"src/widget_changes.ts",
|
|
54
|
+
"src/widget_retention.ts",
|
|
55
|
+
"src/widget_reconcile.ts",
|
|
56
|
+
"src/scroll_tree.ts",
|
|
57
|
+
"src/widget_continuity.ts",
|
|
58
|
+
"src/staged_rebuild.ts",
|
|
59
|
+
"src/virtual_windows.ts",
|
|
60
|
+
"src/context_menus.ts",
|
|
61
|
+
"src/web_panes.ts",
|
|
62
|
+
"src/extent_program.ts",
|
|
63
|
+
"src/scroll_mutation.ts",
|
|
64
|
+
"src/markup_expressions.ts",
|
|
65
|
+
"src/markup_text.ts",
|
|
66
|
+
"src/markup_display.ts",
|
|
67
|
+
"src/markup_scalars.ts",
|
|
68
|
+
"src/markup_parser.ts",
|
|
69
|
+
"src/markup_document.ts",
|
|
70
|
+
"src/markup_imports.ts",
|
|
71
|
+
"src/markup_canonical.ts",
|
|
72
|
+
"src/markup_construction.ts",
|
|
73
|
+
"src/markup_elements.ts",
|
|
74
|
+
"src/markup_specialized.ts",
|
|
75
|
+
"src/markup_values.ts",
|
|
76
|
+
"src/markup_runtime.ts",
|
|
77
|
+
"src/markup_shapes.ts",
|
|
54
78
|
"src/widget_paint.ts",
|
|
55
79
|
"src/widget_presentation.ts",
|
|
56
80
|
"src/widget_paint_walk.ts",
|
|
@@ -29,9 +29,8 @@ class NscRegisteredFont {
|
|
|
29
29
|
float(at: number, value: number): void { this.wire.setFloat32(at, value, true); }
|
|
30
30
|
action(value: number): Uint8Array { this.put(72, value); this.bytes[3] = value === 0 ? 2 : 1; return this.bytes; }
|
|
31
31
|
cell(em: number): Uint8Array {
|
|
32
|
-
const registered = this.bytes[4] === 1
|
|
33
|
-
const
|
|
34
|
-
const value = Math.fround(Math.fround(this.f(20) * em) * factor);
|
|
32
|
+
const registered = this.bytes[4] === 1;
|
|
33
|
+
const value = Math.fround(this.f(20) * em);
|
|
35
34
|
// A registered cluster is itself a one-cluster width sum starting at
|
|
36
35
|
// +0. Built-in advance estimators return their product directly.
|
|
37
36
|
this.float(76, registered ? Math.fround(0 + value) : value);
|
|
@@ -203,6 +203,30 @@ export function native_window_policy(request: Uint8Array): Uint8Array {
|
|
|
203
203
|
if (request[0] === 88) return nscvAuthorization(request);
|
|
204
204
|
if (request[0] === 90) return nscvAutomationCommands(request);
|
|
205
205
|
if (request[0] === 91) return nscvAutomationInteractions(request);
|
|
206
|
+
if (request[0] === 92) return nscvWidgetRetention(request);
|
|
207
|
+
if (request[0] === 93) return nscvWidgetReconcile(request);
|
|
208
|
+
if (request[0] === 94) return nscvScrollTree(request);
|
|
209
|
+
if (request[0] === 95) return nscvWidgetContinuity(request);
|
|
210
|
+
if (request[0] === 96) return nscvStagedRebuild(request);
|
|
211
|
+
if (request[0] === 97) return nscvVirtualWindows(request);
|
|
212
|
+
if (request[0] === 98) return nscvContextMenus(request);
|
|
213
|
+
if (request[0] === 99) return nscvWebPanes(request);
|
|
214
|
+
if (request[0] === 100) return nscvExtentProgram(request);
|
|
215
|
+
if (request[0] === 101) return nscvScrollMutation(request);
|
|
216
|
+
if (request[0] === 102) return nscvMarkupExpressions(request);
|
|
217
|
+
if (request[0] === 103) return nscvMarkupText(request);
|
|
218
|
+
if (request[0] === 104) return nscvMarkupDisplay(request);
|
|
219
|
+
if (request[0] === 105) return nscvMarkupScalars(request);
|
|
220
|
+
if (request[0] === 107) return nscvMarkupDocument(request);
|
|
221
|
+
if (request[0] === 108) return nscvMarkupImports(request);
|
|
222
|
+
if (request[0] === 109) return nscvMarkupCanonical(request);
|
|
223
|
+
if (request[0] === 110) return nscvMarkupConstruction(request);
|
|
224
|
+
if (request[0] === 111) return nscvMarkupElements(request);
|
|
225
|
+
if (request[0] === 112) return nscvMarkupSpecialized(request);
|
|
226
|
+
if (request[0] === 113) return nscvMarkupValues(request);
|
|
227
|
+
if (request[0] === 114) return nscvMarkupRuntime(request);
|
|
228
|
+
if (request[0] === 115) return nscvMarkupShapes(request);
|
|
229
|
+
if (request[0] === 106) return nscvMarkupParser(request);
|
|
206
230
|
if (request[0] === 89) return nscvBuiltinCoordination(request);
|
|
207
231
|
if (request[0] === 81) return nscvWindowLifecycle(request);
|
|
208
232
|
if (request[0] === 80) return nscvViewCoordination(request);
|
|
@@ -60,8 +60,6 @@ function nscvScalarText(request: Uint8Array): Uint8Array {
|
|
|
60
60
|
w.setFloat32(32, nscvScalarTextMonoWidth(text, 0, length, size, mode === 2), true);
|
|
61
61
|
return out;
|
|
62
62
|
}
|
|
63
|
-
const font = w.getUint32(20, true) === 0 ? w.getUint32(16, true) : 0;
|
|
64
|
-
const factor = Math.fround(font === 3 ? 1.02 : font === 4 || font === 6 ? 1.04 : 1);
|
|
65
63
|
let count = w.getUint32(36, true);
|
|
66
64
|
if (phase === 0) {
|
|
67
65
|
count = 0; let first = 0;
|
|
@@ -77,7 +75,7 @@ function nscvScalarText(request: Uint8Array): Uint8Array {
|
|
|
77
75
|
}
|
|
78
76
|
let width = 0;
|
|
79
77
|
for (let i = 0; i < count; i++) {
|
|
80
|
-
const advance = Math.fround(
|
|
78
|
+
const advance = Math.fround(size * w.getFloat32(64 + i * 8 + 4, true));
|
|
81
79
|
width = mode === 2 ? advance : Math.fround(width + advance);
|
|
82
80
|
}
|
|
83
81
|
out[3] = 2; w.setUint32(56, 0, true); w.setFloat32(32, width, true); return out;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Scroll mutation capability programs (101). Native retains the complete
|
|
2
|
+
* states, f32 physics/geometry and callbacks. This owner sequences admission,
|
|
3
|
+
* numeric capabilities, retained writes, events, accessibility and damage.
|
|
4
|
+
* Facts are refreshed after each stage; no pointer or identity crosses here.
|
|
5
|
+
* Modes: axis, textarea, driver, keyboard, kinetic region, kinetic finish,
|
|
6
|
+
* and a batched kinetic-region selection over at most 1024 copied node facts.
|
|
7
|
+
* Facts: valid=1, scroll=2, textarea=4, model-owned=8, y=16, x=32,
|
|
8
|
+
* native=64, rubberband=128, viewport=256, moved=512, needs-step=1024.
|
|
9
|
+
* Capabilities (see native Kind): 0–4 observations/delegation, 5–10 axis
|
|
10
|
+
* arithmetic/store/compare, 11–16 geometry/event/semantics/revision/damage,
|
|
11
|
+
* 17–23 driver/target/state/both-axis writes, 24–31 kinetic probes/steps/damage.
|
|
12
|
+
*/
|
|
13
|
+
function nscvScrollMutation(request: Uint8Array): Uint8Array {
|
|
14
|
+
if (request[1] === 6) {
|
|
15
|
+
if (request.length < 16 || request[0] !== 101 || request[2] !== 0 || request[3] !== 0 ||
|
|
16
|
+
request[4] !== 0 || request[5] !== 0 || request[6] !== 0 || request[7] !== 0)
|
|
17
|
+
throw new Error("invalid kinetic selection header");
|
|
18
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength), count = w.getUint32(8, true);
|
|
19
|
+
if (count > 1024 || request.length !== 16 + count || w.getUint32(12, true) !== 0)
|
|
20
|
+
throw new Error("invalid kinetic selection facts");
|
|
21
|
+
const result = new Uint8Array(8 + count); result[0] = 101; result[1] = 6;
|
|
22
|
+
new DataView(result.buffer).setUint32(4, count, true);
|
|
23
|
+
for (let i = 0; i < count; i++) result[8 + i] = (request[16 + i]! & (2 | 8 | 64)) === 2 ? 1 : 0;
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
if (request.length !== 16 || request[0] !== 101 || request[1]! > 5 || request[2]! > 4 ||
|
|
27
|
+
request[3]! > 2 || request[4]! > 1 || request[5] !== 0 || request[6] !== 0 || request[7] !== 0)
|
|
28
|
+
throw new Error("invalid scroll mutation header");
|
|
29
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
30
|
+
const mode = request[1]!, phase = request[2]!, source = request[3]!, facts = w.getUint32(8, true);
|
|
31
|
+
if (facts > 2047 || w.getUint32(12, true) !== 0 || (mode === 3 && source > 1) ||
|
|
32
|
+
(mode === 5 ? phase !== 0 : mode === 4 ? phase > 4 : phase > 2))
|
|
33
|
+
throw new Error("invalid scroll mutation facts");
|
|
34
|
+
const actions: number[] = [];
|
|
35
|
+
let next = 255;
|
|
36
|
+
const granted = (facts & (request[4] === 1 ? 16 : 32)) !== 0;
|
|
37
|
+
if (mode === 5) {
|
|
38
|
+
if ((facts & 512) !== 0) actions.push(14, 15);
|
|
39
|
+
} else if (phase === 0) {
|
|
40
|
+
if ((facts & 1) !== 0) {
|
|
41
|
+
if (mode === 0) {
|
|
42
|
+
if ((facts & 4) !== 0) { if (granted) actions.push(4); }
|
|
43
|
+
else if ((facts & 2) !== 0 && (facts & 8) === 0 && granted) { actions.push(0); next = 1; }
|
|
44
|
+
} else if (mode === 1) {
|
|
45
|
+
if ((facts & 4) !== 0) { actions.push(1); next = 1; }
|
|
46
|
+
} else if ((facts & 2) !== 0 && (facts & 8) === 0 && (mode !== 4 || (facts & 64) === 0)) {
|
|
47
|
+
actions.push(0); next = 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else if (phase === 1) {
|
|
51
|
+
if ((facts & 256) === 0) { if (mode === 4) actions.push(24); }
|
|
52
|
+
else if (mode === 0 || mode === 1) {
|
|
53
|
+
actions.push(mode === 0 ? 2 : 3);
|
|
54
|
+
actions.push(source === 0 ? 7 : mode === 0 && (facts & 128) !== 0 && (facts & 64) === 0 ? 5 : 6);
|
|
55
|
+
// Detented engine input cancels momentum even at an unchanged offset.
|
|
56
|
+
// Textareas never retain this temporary velocity in the first place.
|
|
57
|
+
if (mode === 0 && source === 2) actions.push(8);
|
|
58
|
+
actions.push(mode === 0 ? 9 : 10); next = 2;
|
|
59
|
+
} else {
|
|
60
|
+
actions.push(2);
|
|
61
|
+
if (mode === 4) { if ((facts & 16) !== 0) actions.push(25); next = 2; }
|
|
62
|
+
else {
|
|
63
|
+
if ((facts & 16) !== 0) actions.push(mode === 2 ? 17 : 19);
|
|
64
|
+
if ((facts & 32) !== 0) actions.push(mode === 2 ? 18 : 20);
|
|
65
|
+
actions.push(21); next = 2;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else if (mode === 4 && phase === 2) {
|
|
69
|
+
actions.push((facts & (16 | 1024)) === (16 | 1024) ? 27 : 29);
|
|
70
|
+
if ((facts & 32) !== 0) actions.push(26);
|
|
71
|
+
next = 3;
|
|
72
|
+
} else if (mode === 4 && phase === 3) {
|
|
73
|
+
actions.push((facts & (32 | 1024)) === (32 | 1024) ? 28 : 30);
|
|
74
|
+
actions.push(21); next = 4;
|
|
75
|
+
} else if ((facts & 512) !== 0) {
|
|
76
|
+
if (mode <= 1) actions.push(11);
|
|
77
|
+
else actions.push(22);
|
|
78
|
+
if (mode !== 1) actions.push(mode === 0 ? 12 : 23, 13);
|
|
79
|
+
if (mode === 4) actions.push(31);
|
|
80
|
+
else actions.push(14, 15, 16);
|
|
81
|
+
}
|
|
82
|
+
const result = new Uint8Array(8 + actions.length);
|
|
83
|
+
result[0] = 101; result[1] = mode; result[2] = next; result[3] = actions.length;
|
|
84
|
+
for (let i = 0; i < actions.length; i++) result[8 + i] = actions[i]!;
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Retained scroll geometry over copied preorder facts. Tag 94 uses a
|
|
2
|
+
* 48-byte header and 56 bytes per node; results contain a 24-byte header
|
|
3
|
+
* followed by one translation bit per node. Native owns frames, exact IDs,
|
|
4
|
+
* virtual-content measurements and the buffers on both sides of the ABI.
|
|
5
|
+
* Operations: 0 = both content extents, 1 = moving descendants, 2 = the
|
|
6
|
+
* next newly selected tab. Tab plans are refreshed after every mutation.
|
|
7
|
+
* Node fields: depth/parent/flags u32, offsets y/x f32, frame and inset
|
|
8
|
+
* viewport (four f32 each), anchored stratum u32. Flag bits describe a
|
|
9
|
+
* root modal, anchor, escaping clip, clip scope, virtual region, concealed
|
|
10
|
+
* disclosure, horizontal scroll grant, selected tab and prior selection.
|
|
11
|
+
*/
|
|
12
|
+
function nscvScrollTree(request: Uint8Array): Uint8Array {
|
|
13
|
+
if (request.length < 48 || request[0] !== 94 || request[1]! > 2 || request[2] !== 0 || request[3] !== 0)
|
|
14
|
+
throw new Error("invalid scroll tree header");
|
|
15
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
16
|
+
const count = w.getUint32(4, true), target = w.getUint32(8, true), mode = request[1]!;
|
|
17
|
+
if (count > 1024 || request.length !== 48 + count * 56 || target > count || mode !== 2 && target === count)
|
|
18
|
+
throw new Error("invalid scroll tree shape");
|
|
19
|
+
for (let i = 36; i < 48; i++) if (request[i] !== 0) throw new Error("invalid scroll tree reserved bytes");
|
|
20
|
+
const at = (i: number): number => 48 + i * 56;
|
|
21
|
+
const flags = (i: number): number => w.getUint32(at(i) + 8, true);
|
|
22
|
+
const depth = (i: number): number => w.getUint32(at(i), true);
|
|
23
|
+
const parent = (i: number): number => w.getUint32(at(i) + 4, true);
|
|
24
|
+
for (let i = 0; i < count; i++) {
|
|
25
|
+
const p = parent(i);
|
|
26
|
+
if (flags(i) > 511 || p !== 0xffffffff && p >= i) throw new Error("invalid scroll tree node");
|
|
27
|
+
}
|
|
28
|
+
const result = new Uint8Array(24 + count), out = new DataView(result.buffer);
|
|
29
|
+
result[0] = 94; result[1] = mode; out.setUint32(4, count, true); out.setUint32(8, 0xffffffff, true);
|
|
30
|
+
const f = Math.fround;
|
|
31
|
+
const maximum = (a: number, b: number): number => Number.isNaN(a) ? b : Number.isNaN(b) ? a : Math.max(a, b);
|
|
32
|
+
const skip = (i: number): number => { let next = i + 1; while (next < count && depth(next) > depth(i)) next++; return next; };
|
|
33
|
+
const stationary = (i: number, root: number): boolean => (flags(i) & 1) !== 0 || (flags(i) & 2) !== 0 && parent(i) === root;
|
|
34
|
+
const moves = (root: number): void => {
|
|
35
|
+
let i = root + 1;
|
|
36
|
+
while (i < count && depth(i) > depth(root)) {
|
|
37
|
+
if (stationary(i, root)) i = skip(i);
|
|
38
|
+
else { result[24 + i] = 1; i++; }
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
if (mode === 1) { moves(target); return result; }
|
|
42
|
+
if (mode === 0) {
|
|
43
|
+
const x = w.getFloat32(16, true), y = w.getFloat32(20, true), width = w.getFloat32(24, true), height = w.getFloat32(28, true);
|
|
44
|
+
let right = f(x + width), bottom = f(y + height);
|
|
45
|
+
if ((flags(target) & 16) !== 0) {
|
|
46
|
+
out.setFloat32(12, width, true); out.setFloat32(16, maximum(height, w.getFloat32(32, true)), true); return result;
|
|
47
|
+
}
|
|
48
|
+
const offsetY = w.getFloat32(at(target) + 12, true), offsetX = w.getFloat32(at(target) + 16, true);
|
|
49
|
+
let i = target + 1;
|
|
50
|
+
while (i < count && depth(i) > depth(target)) {
|
|
51
|
+
if (stationary(i, target)) { i = skip(i); continue; }
|
|
52
|
+
bottom = maximum(bottom, f(f(w.getFloat32(at(i) + 24, true) + w.getFloat32(at(i) + 32, true)) + offsetY)); i++;
|
|
53
|
+
}
|
|
54
|
+
i = target + 1;
|
|
55
|
+
while (i < count && depth(i) > depth(target)) {
|
|
56
|
+
const bits = flags(i);
|
|
57
|
+
if ((bits & 4) !== 0) { i = skip(i); continue; }
|
|
58
|
+
right = maximum(right, f(f(w.getFloat32(at(i) + 20, true) + w.getFloat32(at(i) + 28, true)) + offsetX));
|
|
59
|
+
i = (bits & (8 | 16 | 32)) !== 0 ? skip(i) : i + 1;
|
|
60
|
+
}
|
|
61
|
+
out.setFloat32(12, maximum(0, f(right - x)), true); out.setFloat32(16, maximum(0, f(bottom - y)), true); return result;
|
|
62
|
+
}
|
|
63
|
+
const stratum = w.getUint32(12, true);
|
|
64
|
+
let tab = target;
|
|
65
|
+
while (tab < count && ((flags(tab) & (128 | 256)) !== 128 || stratum !== 0xffffffff && w.getUint32(at(tab) + 52, true) !== stratum)) tab++;
|
|
66
|
+
out.setUint32(20, tab < count ? tab + 1 : count, true);
|
|
67
|
+
if (tab === count) return result;
|
|
68
|
+
let ancestor = parent(tab);
|
|
69
|
+
while (ancestor !== 0xffffffff) {
|
|
70
|
+
if ((flags(ancestor) & (64 | 16)) === 64) {
|
|
71
|
+
const a = at(ancestor), t = at(tab);
|
|
72
|
+
const vx = w.getFloat32(a + 36, true), vy = w.getFloat32(a + 40, true), vw = w.getFloat32(a + 44, true), vh = w.getFloat32(a + 48, true);
|
|
73
|
+
let tx = w.getFloat32(t + 20, true), tw = w.getFloat32(t + 28, true), th = w.getFloat32(t + 32, true);
|
|
74
|
+
if (tw < 0) { tx = f(tx + tw); tw = -tw; }
|
|
75
|
+
if (th < 0) th = -th;
|
|
76
|
+
if (vw <= 0 || vh <= 0 || tw <= 0 || th <= 0) break;
|
|
77
|
+
const delta = tx < vx ? f(tx - vx) : f(tx + tw) > f(vx + vw) ? f(f(tx + tw) - f(vx + vw)) : 0;
|
|
78
|
+
if (delta === 0) break;
|
|
79
|
+
const current = w.getFloat32(a + 16, true), next = maximum(0, f(current + delta));
|
|
80
|
+
if (next === current) break;
|
|
81
|
+
out.setUint32(8, ancestor, true); out.setFloat32(12, -f(next - current), true); out.setFloat32(16, next, true); moves(ancestor); break;
|
|
82
|
+
}
|
|
83
|
+
ancestor = parent(ancestor);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|