@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,243 @@
|
|
|
1
|
+
/** Shared runtime markup shape and diagnostic programs (115). Source bytes,
|
|
2
|
+
* tree indices and type classes are copied; native retains borrowed records,
|
|
3
|
+
* exact literal conversion and the bundled font's glyph coverage capability.
|
|
4
|
+
*/
|
|
5
|
+
interface NscShapeNode {
|
|
6
|
+
readonly kind: number; readonly name: Uint8Array; readonly text: Uint8Array;
|
|
7
|
+
readonly attrs: readonly { name: Uint8Array; value: Uint8Array }[];
|
|
8
|
+
readonly children: readonly number[];
|
|
9
|
+
}
|
|
10
|
+
function nschEmit(out: number[], action: number, code: number, a: number = 0, b: number = 0,
|
|
11
|
+
c: number = 0, d: number = 0, e: number = 0): void { out.push(action, code, a, b, c, d, e); }
|
|
12
|
+
function nschFail(out: number[], code: number, node: number, attr: number = 0,
|
|
13
|
+
offset: number = 0, text: boolean = false): void { nschEmit(out, 255, code, node, attr, offset, text ? 1 : 0); }
|
|
14
|
+
function nschAttr(node: NscShapeNode, name: string): number {
|
|
15
|
+
for (let i = 0; i < node.attrs.length; i++) if (nsceNamed(node.attrs[i]!.name, name)) return i;
|
|
16
|
+
return -1;
|
|
17
|
+
}
|
|
18
|
+
// 0=literal, 1=path/equality, 2=expression, 3=malformed. Attribute braces
|
|
19
|
+
// trim only ASCII space, exactly like the original attribute classifier.
|
|
20
|
+
function nschExpression(value: Uint8Array): number[] {
|
|
21
|
+
if (value.length === 0 || value[0] !== 123) return [0, 0, value.length];
|
|
22
|
+
if (value[value.length - 1] !== 125) return [3, 0, 0];
|
|
23
|
+
const span = nsccTrim(value, 1, value.length - 1), start = span[0]!, end = span[1]!;
|
|
24
|
+
if (start === end) return [3, 0, 0];
|
|
25
|
+
for (let i = start; i + 1 < end; i++) if (value[i] === 61 && value[i + 1] === 61) {
|
|
26
|
+
const left = nsccTrim(value, start, i), right = nsccTrim(value, i + 2, end);
|
|
27
|
+
if (nsccPath(value, left[0]!, left[1]!) && nsccPath(value, right[0]!, right[1]!)) return [1, start, end];
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
return [nsccPath(value, start, end) ? 1 : 2, start, end];
|
|
31
|
+
}
|
|
32
|
+
function nschAttrExpression(out: number[], node: number, attr: number, value: Uint8Array,
|
|
33
|
+
fallback: number, atNode: boolean = false): boolean {
|
|
34
|
+
const form = nschExpression(value);
|
|
35
|
+
if (form[0] === 3) { nschFail(out, fallback, node, atNode ? 0 : attr + 1); return false; }
|
|
36
|
+
if (form[0] === 2) nschEmit(out, 1, 0, node, attr + 1, form[1]!, form[2]! - form[1]!, atNode ? 1 : 0);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function nschMessage(value: Uint8Array): boolean {
|
|
40
|
+
const colon = nsccFind(value, 0, 58);
|
|
41
|
+
if (colon < 0) return nsccPath(value, 0, value.length);
|
|
42
|
+
return nsccPath(value, 0, colon) && value.length - colon - 1 >= 3 && value[colon + 1] === 123 &&
|
|
43
|
+
value[value.length - 1] === 125 && nsccPath(value, colon + 2, value.length - 1);
|
|
44
|
+
}
|
|
45
|
+
function nschText(out: number[], index: number, text: Uint8Array): boolean {
|
|
46
|
+
let cursor = 0;
|
|
47
|
+
while (true) {
|
|
48
|
+
const open = nsccFind(text, cursor, 123);
|
|
49
|
+
if (open < 0) break;
|
|
50
|
+
const close = nsccFind(text, open, 125);
|
|
51
|
+
if (close < 0) { nschFail(out, 22, index, 0, open, true); return false; }
|
|
52
|
+
const span = nsccTrim(text, open + 1, close);
|
|
53
|
+
if (!nsccPath(text, span[0]!, span[1]!)) nschEmit(out, 4, 0, index, 0, span[0]!, span[1]! - span[0]!, open);
|
|
54
|
+
cursor = close + 1;
|
|
55
|
+
}
|
|
56
|
+
nschEmit(out, 5, 0, index); // literal coverage follows every interpolation
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
function nschMenuItem(nodes: readonly NscShapeNode[], index: number, out: number[]): boolean {
|
|
60
|
+
const node = nodes[index]!; let press = false;
|
|
61
|
+
for (let i = 0; i < node.attrs.length; i++) {
|
|
62
|
+
const attr = node.attrs[i]!;
|
|
63
|
+
if (nsceNamed(attr.name, "on-press")) {
|
|
64
|
+
press = true;
|
|
65
|
+
if (!nschMessage(attr.value)) { nschFail(out, 19, index, i + 1); return false; }
|
|
66
|
+
} else if (nsceNamed(attr.name, "disabled")) {
|
|
67
|
+
if (!nschAttrExpression(out, index, i, attr.value, 20)) return false;
|
|
68
|
+
} else { nschFail(out, 16, index, i + 1); return false; }
|
|
69
|
+
}
|
|
70
|
+
if (!press) { nschFail(out, 17, index); return false; }
|
|
71
|
+
let runs = 0;
|
|
72
|
+
for (const child of node.children) {
|
|
73
|
+
const run = nodes[child]!;
|
|
74
|
+
if (run.kind !== 1) { nschFail(out, 18, child); return false; }
|
|
75
|
+
if (++runs > 1) { nschFail(out, 7, child); return false; }
|
|
76
|
+
if (!nschText(out, child, run.text)) return false;
|
|
77
|
+
}
|
|
78
|
+
if (runs === 0) { nschFail(out, 18, index); return false; }
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
function nschMenuChildren(nodes: readonly NscShapeNode[], index: number, out: number[]): number {
|
|
82
|
+
let previous = -1, count = 0;
|
|
83
|
+
for (const childIndex of nodes[index]!.children) {
|
|
84
|
+
const child = nodes[childIndex]!;
|
|
85
|
+
if (child.kind === 0) {
|
|
86
|
+
if (nsceNamed(child.name, "menu-item")) {
|
|
87
|
+
count++;
|
|
88
|
+
if (!nschMenuItem(nodes, childIndex, out)) return -1;
|
|
89
|
+
} else if (nsceNamed(child.name, "separator")) {
|
|
90
|
+
if (child.attrs.length !== 0 || child.children.length !== 0) { nschFail(out, 12, childIndex); return -1; }
|
|
91
|
+
count++;
|
|
92
|
+
} else { nschFail(out, 11, childIndex); return -1; }
|
|
93
|
+
} else if (child.kind === 2) {
|
|
94
|
+
if (nschAttr(child, "each") < 0) { nschFail(out, 13, childIndex); return -1; }
|
|
95
|
+
if (nschAttr(child, "as") < 0) { nschFail(out, 14, childIndex); return -1; }
|
|
96
|
+
if (child.children.length === 0) { nschFail(out, 15, childIndex); return -1; }
|
|
97
|
+
const repeated = nschMenuChildren(nodes, childIndex, out);
|
|
98
|
+
if (repeated < 0) return -1;
|
|
99
|
+
if (repeated === 0) { nschFail(out, 11, childIndex); return -1; }
|
|
100
|
+
count += repeated;
|
|
101
|
+
} else if (child.kind === 3) {
|
|
102
|
+
const test = nschAttr(child, "test");
|
|
103
|
+
if (test < 0) { nschFail(out, 23, childIndex); return -1; }
|
|
104
|
+
if (!nschAttrExpression(out, childIndex, test, child.attrs[test]!.value, 24, true)) return -1;
|
|
105
|
+
const nested = nschMenuChildren(nodes, childIndex, out); if (nested < 0) return -1; count += nested;
|
|
106
|
+
} else if (child.kind === 4) {
|
|
107
|
+
if (previous !== 2 && previous !== 3) { nschFail(out, 21, childIndex); return -1; }
|
|
108
|
+
const nested = nschMenuChildren(nodes, childIndex, out); if (nested < 0) return -1; count += nested;
|
|
109
|
+
} else { nschFail(out, 11, childIndex); return -1; }
|
|
110
|
+
previous = child.kind;
|
|
111
|
+
}
|
|
112
|
+
return count;
|
|
113
|
+
}
|
|
114
|
+
function nschShape(r: NscElementReader, mode: number, out: number[]): void {
|
|
115
|
+
const count = r.word(), nodes: NscShapeNode[] = [], parents = new Uint8Array(count);
|
|
116
|
+
if (count === 0 || count > r.bytes.length - r.at) throw new Error("invalid shape node count");
|
|
117
|
+
for (let i = 0; i < count; i++) {
|
|
118
|
+
const kind = r.word(), name = r.blob(), text = r.blob(), attrs: { name: Uint8Array; value: Uint8Array }[] = [];
|
|
119
|
+
if (kind > 8) throw new Error("invalid shape node kind");
|
|
120
|
+
const ac = r.word(); for (let a = 0; a < ac; a++) attrs.push({ name: r.blob(), value: r.blob() });
|
|
121
|
+
const cc = r.word(), children: number[] = [];
|
|
122
|
+
for (let c = 0; c < cc; c++) {
|
|
123
|
+
const child = r.word();
|
|
124
|
+
if (child <= i || child >= count || parents[child] !== 0) throw new Error("invalid shape tree edge");
|
|
125
|
+
parents[child] = 1; children.push(child);
|
|
126
|
+
}
|
|
127
|
+
nodes.push({ kind, name, text, attrs, children });
|
|
128
|
+
}
|
|
129
|
+
for (let i = 1; i < count; i++) if (parents[i] !== 1) throw new Error("unreachable shape node");
|
|
130
|
+
const weights = r.names(), colors = r.names(), alignments = r.names(), node = nodes[0]!;
|
|
131
|
+
if (mode === 0) {
|
|
132
|
+
if (node.attrs.length !== 0) { nschFail(out, 9, 0, 1); return; }
|
|
133
|
+
const items = nschMenuChildren(nodes, 0, out);
|
|
134
|
+
if (items === 0) nschFail(out, 10, 0);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
for (let i = 0; i < node.attrs.length; i++) {
|
|
138
|
+
const attr = node.attrs[i]!;
|
|
139
|
+
if (mode === 2) {
|
|
140
|
+
if (!nsceNamed(attr.name, "text-alignment")) { nschFail(out, 25, 0, i + 1); return; }
|
|
141
|
+
if (!nsceIn(attr.value, alignments)) { nschFail(out, 26, 0, i + 1); return; }
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const form = nschExpression(attr.value);
|
|
145
|
+
if (nsceNamed(attr.name, "weight")) {
|
|
146
|
+
if (form[0] === 0 && !nsceIn(attr.value, weights)) { nschFail(out, 1, 0, i + 1); return; }
|
|
147
|
+
} else if (nsceNamed(attr.name, "scale")) {
|
|
148
|
+
if (form[0] === 0) nschEmit(out, 2, 0, 0, i + 1);
|
|
149
|
+
} else if (nsceOne(attr.name, ["mono", "italic", "underline"])) {
|
|
150
|
+
// These channels use the same structural expression check.
|
|
151
|
+
} else if (nsceNamed(attr.name, "foreground")) {
|
|
152
|
+
if (!nsceIn(attr.value, colors)) { nschFail(out, form[0] === 0 ? 3 : 4, 0, i + 1); return; }
|
|
153
|
+
continue;
|
|
154
|
+
} else { nschFail(out, 5, 0, i + 1); return; }
|
|
155
|
+
if (!nschAttrExpression(out, 0, i, attr.value, 20)) return;
|
|
156
|
+
}
|
|
157
|
+
let runs = 0;
|
|
158
|
+
for (const child of node.children) {
|
|
159
|
+
if (nodes[child]!.kind !== 1) { nschFail(out, mode === 1 ? 6 : 27, child); return; }
|
|
160
|
+
if (++runs > 1) { nschFail(out, 7, child); return; }
|
|
161
|
+
}
|
|
162
|
+
if (runs === 0) nschFail(out, mode === 1 ? 6 : 27, 0);
|
|
163
|
+
}
|
|
164
|
+
function nschCoverage(r: NscElementReader, out: number[]): void {
|
|
165
|
+
const text = r.blob(); let at = 0;
|
|
166
|
+
while (at < text.length) {
|
|
167
|
+
const first = text[at]!;
|
|
168
|
+
if (first === 123) { const close = nsccFind(text, at + 1, 125); at = close < 0 ? text.length : close + 1; continue; }
|
|
169
|
+
const size = first < 128 ? 1 : first >= 192 && first < 224 ? 2 : first < 240 && first >= 224 ? 3 : first >= 240 && first < 248 ? 4 : 0;
|
|
170
|
+
if (size === 0) { nschEmit(out, 255, 8, at, 1, 65533); return; }
|
|
171
|
+
if (size > text.length - at) { nschEmit(out, 255, 8, at, text.length - at, 65533); return; }
|
|
172
|
+
let point = first & (size === 1 ? 127 : size === 2 ? 31 : size === 3 ? 15 : 7), valid = true;
|
|
173
|
+
for (let i = 1; i < size; i++) { const b = text[at + i]!; if (b < 128 || b > 191) valid = false; point = point * 64 + (b & 63); }
|
|
174
|
+
if (!valid || size === 2 && point < 128 || size === 3 && point < 2048 || size === 4 && point < 65536 || point > 1114111 || point >= 55296 && point <= 57343) {
|
|
175
|
+
nschEmit(out, 255, 8, at, size, 65533); return;
|
|
176
|
+
}
|
|
177
|
+
if (point >= 32 && point !== 127) nschEmit(out, 3, 0, at, size, point);
|
|
178
|
+
at += size;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function nschTypes(r: NscElementReader, out: number[]): void {
|
|
182
|
+
const count = r.word(), root = r.word(), nodes: number[][] = [], kinds: number[] = [];
|
|
183
|
+
if (count === 0 || count > 64 || root >= count) throw new Error("invalid structural expression tree");
|
|
184
|
+
for (let i = 0; i < count; i++) {
|
|
185
|
+
const row: number[] = []; for (let j = 0; j < 11; j++) row.push(r.word());
|
|
186
|
+
const kind = row[0]!, fn = row[1]!, argc = row[2]!;
|
|
187
|
+
if (kind > 20 || fn > 16 || argc > 4 || row[10]! > 4 || row[9]! > 65535) throw new Error("invalid structural expression node");
|
|
188
|
+
if ((kind === 5 || kind === 6) && row[3]! >= i || kind >= 7 && kind <= 19 && (row[3]! >= i || row[4]! >= i)) throw new Error("invalid structural operand");
|
|
189
|
+
if (kind === 20) {
|
|
190
|
+
const min = fn === 0 || fn === 9 || fn === 10 || fn === 16 ? 2 : fn === 15 ? 3 : 1, max = fn === 2 ? 2 : min;
|
|
191
|
+
if (argc < min || argc > max) throw new Error("invalid structural arity");
|
|
192
|
+
for (let j = 0; j < argc; j++) if (row[5 + j]! >= i) throw new Error("invalid structural argument");
|
|
193
|
+
}
|
|
194
|
+
nodes.push(row);
|
|
195
|
+
}
|
|
196
|
+
for (let i = 0; i < count; i++) {
|
|
197
|
+
const n = nodes[i]!, kind = n[0]!, fn = n[1]!, left = kinds[n[3]!] ?? 0, right = kinds[n[4]!] ?? 0;
|
|
198
|
+
let result = 0, error = 0;
|
|
199
|
+
const badNumber = (k: number): boolean => k !== 0 && k !== 2 && k !== 3;
|
|
200
|
+
if (kind < 4) result = kind === 0 ? 2 : kind === 1 ? 3 : kind === 2 ? 1 : 4;
|
|
201
|
+
else if (kind === 4) result = n[10]!;
|
|
202
|
+
else if (kind === 5) { result = left; if (badNumber(left)) error = 1; }
|
|
203
|
+
else if (kind === 6) { result = 4; if (left !== 0 && left !== 4) error = 2; }
|
|
204
|
+
else if (kind >= 7 && kind <= 10) {
|
|
205
|
+
result = kind === 10 ? 3 : left === 0 || right === 0 ? 0 : left === 2 && right === 2 ? 2 : 3;
|
|
206
|
+
if (badNumber(left) || badNumber(right)) error = 3;
|
|
207
|
+
} else if (kind === 11) result = 1;
|
|
208
|
+
else if (kind === 12 || kind === 13) result = 4;
|
|
209
|
+
else if (kind >= 14 && kind <= 17) { result = 4; if (badNumber(left) || badNumber(right)) error = 4; }
|
|
210
|
+
else if (kind === 18 || kind === 19) { result = 4; if (left !== 0 && left !== 4 || right !== 0 && right !== 4) error = 2; }
|
|
211
|
+
else {
|
|
212
|
+
const a = kinds[n[5]!] ?? 0, b = kinds[n[6]!] ?? 0, c = kinds[n[7]!] ?? 0;
|
|
213
|
+
const bad = (k: number, expected: number): boolean => k !== 0 && k !== expected;
|
|
214
|
+
result = fn === 9 || fn === 10 ? a === 0 || b === 0 ? 0 : a === 2 && b === 2 ? 2 : 3 : fn === 11 ? a : fn >= 12 && fn <= 14 ? 2 : 1;
|
|
215
|
+
if (fn === 0) { if (badNumber(a) || bad(b, 2)) error = 32 + fn; }
|
|
216
|
+
else if (fn === 2) { if (badNumber(a) || n[2]! > 1 && bad(b, 2)) error = 32 + fn; }
|
|
217
|
+
else if (fn === 1 || fn >= 3 && fn <= 5) { if (bad(a, 2)) error = 32 + fn; }
|
|
218
|
+
else if (fn >= 6 && fn <= 8) { if (bad(a, 1)) error = 32 + fn; }
|
|
219
|
+
else if (fn === 9 || fn === 10) { if (badNumber(a) || badNumber(b)) error = 32 + fn; }
|
|
220
|
+
else if (fn >= 11 && fn <= 14) { if (badNumber(a)) error = 32 + fn; }
|
|
221
|
+
else if (fn === 15) { if (bad(a, 2) || bad(b, 1) || bad(c, 1)) error = 32 + fn; }
|
|
222
|
+
else if (bad(a, 2) || bad(b, 2)) error = 32 + fn;
|
|
223
|
+
}
|
|
224
|
+
if (error !== 0) { nschEmit(out, 255, error, i, n[9]!); return; }
|
|
225
|
+
kinds.push(result);
|
|
226
|
+
}
|
|
227
|
+
nschEmit(out, 0, 0, kinds[root]!);
|
|
228
|
+
}
|
|
229
|
+
function nscvMarkupShapes(input: Uint8Array): Uint8Array {
|
|
230
|
+
if (input.length < 4 || input[0] !== 115 || input[1] !== 1 || input[2]! > 4 || input[3]! > 1) throw new Error("invalid markup shape header");
|
|
231
|
+
const r = new NscElementReader(input), out: number[] = [], mode = input[2]!;
|
|
232
|
+
if (mode < 3) nschShape(r, mode, out);
|
|
233
|
+
else if (mode === 3) nschTypes(r, out);
|
|
234
|
+
else nschCoverage(r, out);
|
|
235
|
+
if (r.at !== input.length) throw new Error("trailing markup shape facts");
|
|
236
|
+
const count = out.length / 7, bytes = new Uint8Array(input[3] === 0 ? 16 : 16 + count * 48), wire = new DataView(bytes.buffer);
|
|
237
|
+
bytes[0] = 115; bytes[1] = 1; bytes[2] = input[3]!; wire.setFloat64(8, count, true);
|
|
238
|
+
if (input[3] === 1) for (let i = 0; i < count; i++) {
|
|
239
|
+
const at = 16 + i * 48, from = i * 7; bytes[at] = out[from]!; bytes[at + 1] = out[from + 1]!;
|
|
240
|
+
for (let j = 0; j < 5; j++) wire.setFloat64(at + 8 + j * 8, out[from + j + 2]!, true);
|
|
241
|
+
}
|
|
242
|
+
return bytes;
|
|
243
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/** Specialized runtime markup programs (112). The policy sequences admission,
|
|
2
|
+
* evaluation, scope changes, child construction and publication; native supplies
|
|
3
|
+
* typed reflection, exact conversion, borrowed storage and builder capabilities.
|
|
4
|
+
*/
|
|
5
|
+
function nscsAttrs(node: NscElementNode, out: number[], names: readonly string[], error: number, skipKind: boolean): boolean {
|
|
6
|
+
for (let i = 0; i < node.attrs.length; i++) {
|
|
7
|
+
const name = node.attrs[i]!.name;
|
|
8
|
+
if (skipKind && nsceNamed(name, "kind")) continue;
|
|
9
|
+
let selected = -1;
|
|
10
|
+
for (let j = 0; j < names.length; j++) if (names[j] === "on-*" ? nsceStartsEvent(name) : nsceNamed(name, names[j]!)) { selected = j; break; }
|
|
11
|
+
if (selected < 0) { nsceFail(out, error); return false; }
|
|
12
|
+
nsceEmit(out, selected + 1, 0, i);
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
// Source-known shapes are admitted by static lowering. These programs retain
|
|
17
|
+
// first-occurrence channels in the static engine's fixed evaluation order.
|
|
18
|
+
function nscsStaticAttrs(node: NscElementNode, out: number[], names: readonly string[]): void {
|
|
19
|
+
for (let i = 0; i < names.length; i++) {
|
|
20
|
+
const index = nsceAttr(node, names[i]!);
|
|
21
|
+
if (index >= 0) nsceEmit(out, i + 1, 0, index);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function nscsNode(r: NscElementReader, out: number[], mode: number): void {
|
|
25
|
+
const node = nsceNode(r);
|
|
26
|
+
const kind = mode === 14 ? r.word() : 0;
|
|
27
|
+
const windowFacts = mode === 0 ? [r.flag(), r.flag(), r.flag(), r.flag()] : [];
|
|
28
|
+
const full = mode === 1 ? r.flag() : false;
|
|
29
|
+
if (mode === 22) {
|
|
30
|
+
nscsStaticAttrs(node, out, ["label", "width", "height", "min-width", "grow", "key", "global-key"]);
|
|
31
|
+
nsceEmit(out, 100);
|
|
32
|
+
if (node.children.length > 1) nsceEmit(out, 101, 0, 1);
|
|
33
|
+
nsceEmit(out, 200); return;
|
|
34
|
+
}
|
|
35
|
+
if (mode === 23) {
|
|
36
|
+
nscsStaticAttrs(node, out, ["gap", "key", "global-key"]);
|
|
37
|
+
nsceEmit(out, 100);
|
|
38
|
+
nsceEmit(out, 200); return;
|
|
39
|
+
}
|
|
40
|
+
if (mode === 24) {
|
|
41
|
+
nscsStaticAttrs(node, out, ["gap", "grow", "key", "global-key", "label"]);
|
|
42
|
+
nsceEmit(out, 100);
|
|
43
|
+
nsceEmit(out, 200); return;
|
|
44
|
+
}
|
|
45
|
+
if (mode === 25) {
|
|
46
|
+
nscsStaticAttrs(node, out, ["title", "description", "meta", "indicator", "icon", "variant", "connector", "selected", "on-press", "key", "global-key"]);
|
|
47
|
+
nsceEmit(out, 200); return;
|
|
48
|
+
}
|
|
49
|
+
if (mode === 26) {
|
|
50
|
+
nscsStaticAttrs(node, out, ["y-min", "y-max", "grid-lines", "baseline", "x-labels", "y-labels", "hover-details", "stroke-width", "width", "height", "grow", "padding", "key", "global-key", "label"]);
|
|
51
|
+
nsceEmit(out, 100);
|
|
52
|
+
for (let i = 0; i < node.children.length; i++) nsceEmit(out, 101, 0, i);
|
|
53
|
+
nsceEmit(out, 200); return;
|
|
54
|
+
}
|
|
55
|
+
if (mode === 27) {
|
|
56
|
+
nscsStaticAttrs(node, out, ["kind", "values", "color", "label"]);
|
|
57
|
+
nsceEmit(out, 200); return;
|
|
58
|
+
}
|
|
59
|
+
if (mode === 28) {
|
|
60
|
+
nscsStaticAttrs(node, out, ["src", "controls", "autoplay", "loop", "muted", "width", "height", "grow", "label", "key", "global-key"]);
|
|
61
|
+
nsceEmit(out, 200); return;
|
|
62
|
+
}
|
|
63
|
+
if (mode === 29) {
|
|
64
|
+
nscsStaticAttrs(node, out, ["source", "on-link", "on-details", "details-expanded", "images", "issue-link-base"]);
|
|
65
|
+
nsceEmit(out, 200); return;
|
|
66
|
+
}
|
|
67
|
+
if (mode === 30) {
|
|
68
|
+
nscsStaticAttrs(node, out, ["source", "language", "line-numbers", "added-lines", "removed-lines", "editable", "on-input", "wrap", "width", "height", "min-width", "grow", "label", "key", "global-key"]);
|
|
69
|
+
nsceEmit(out, 200); return;
|
|
70
|
+
}
|
|
71
|
+
if (mode === 31) {
|
|
72
|
+
// Inherited slot steps interpolate in their lexical site scope; ordinary
|
|
73
|
+
// steps use the stepper's scope. The step array precedes every label.
|
|
74
|
+
const steps = r.word(), slot = r.flag();
|
|
75
|
+
if (slot ? node.children.length !== 1 : steps !== node.children.length) throw new Error("invalid static stepper facts");
|
|
76
|
+
nscsStaticAttrs(node, out, ["active", "key", "global-key", "label"]);
|
|
77
|
+
nsceEmit(out, 100);
|
|
78
|
+
for (let i = 0; i < steps; i++) nsceEmit(out, slot ? 102 : 101, 0, i);
|
|
79
|
+
nsceEmit(out, 200); return;
|
|
80
|
+
}
|
|
81
|
+
if (mode === 2) {
|
|
82
|
+
if (node.children.length !== 0) { nsceFail(out, 1, 1); return; }
|
|
83
|
+
if (!nscsAttrs(node, out, ["source", "on-link", "on-details", "details-expanded", "images", "issue-link-base"], 2, true)) return;
|
|
84
|
+
if (nsceAttr(node, "source") < 0) { nsceFail(out, 3, 0); return; }
|
|
85
|
+
nsceEmit(out, 200); return;
|
|
86
|
+
}
|
|
87
|
+
if (mode === 3) {
|
|
88
|
+
if (node.children.length !== 0) { nsceFail(out, 4, 1); return; }
|
|
89
|
+
if (!nscsAttrs(node, out, ["source", "language", "line-numbers", "added-lines", "removed-lines", "editable", "on-input", "wrap", "width", "height", "min-width", "grow", "key", "global-key", "label"], 5, true)) return;
|
|
90
|
+
if (nsceAttr(node, "source") < 0) { nsceFail(out, 6, 0); return; }
|
|
91
|
+
nsceEmit(out, 200); return;
|
|
92
|
+
}
|
|
93
|
+
if (mode === 4) {
|
|
94
|
+
if (!nscsAttrs(node, out, ["active", "key", "global-key", "label"], 7, true)) return;
|
|
95
|
+
if (nsceAttr(node, "active") < 0) { nsceFail(out, 8, 0); return; }
|
|
96
|
+
nsceEmit(out, 100); return;
|
|
97
|
+
}
|
|
98
|
+
if (mode === 5) {
|
|
99
|
+
if (!nscsAttrs(node, out, ["label", "width", "height", "min-width", "grow", "key", "global-key"], 9, true)) return;
|
|
100
|
+
let entry = false, actions = false;
|
|
101
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
102
|
+
const child = node.children[i]!;
|
|
103
|
+
if (child.kind !== 0) { nsceFail(out, 10, i + 1); return; }
|
|
104
|
+
if (nsceNamed(child.name, "textarea")) {
|
|
105
|
+
if (entry || actions) { nsceFail(out, 10, i + 1); return; }
|
|
106
|
+
nsceEmit(out, 100, 0, i); entry = true;
|
|
107
|
+
} else if (nsceNamed(child.name, "input-group-actions")) {
|
|
108
|
+
if (!entry) { nsceFail(out, 11, i + 1); return; }
|
|
109
|
+
if (actions) { nsceFail(out, 10, i + 1); return; }
|
|
110
|
+
nsceEmit(out, 101, 0, i); actions = true;
|
|
111
|
+
} else { nsceFail(out, 10, i + 1); return; }
|
|
112
|
+
}
|
|
113
|
+
if (!entry) { nsceFail(out, 11, 0); return; }
|
|
114
|
+
nsceEmit(out, 200); return;
|
|
115
|
+
}
|
|
116
|
+
if (mode === 6) {
|
|
117
|
+
if (!nscsAttrs(node, out, ["gap", "key", "global-key"], 12, true)) return;
|
|
118
|
+
for (let i = 0; i < node.children.length; i++) if (node.children[i]!.kind === 1) { nsceFail(out, 13, i + 1); return; }
|
|
119
|
+
nsceEmit(out, 100); nsceEmit(out, 200); return;
|
|
120
|
+
}
|
|
121
|
+
if (mode === 7) {
|
|
122
|
+
if (!nscsAttrs(node, out, ["gap", "grow", "key", "global-key", "label"], 14, true)) return;
|
|
123
|
+
nsceEmit(out, 100); nsceEmit(out, 200); return;
|
|
124
|
+
}
|
|
125
|
+
if (mode === 8) {
|
|
126
|
+
if (node.children.length !== 0) { nsceFail(out, 15, 1); return; }
|
|
127
|
+
if (!nscsAttrs(node, out, ["title", "description", "meta", "indicator", "icon", "variant", "connector", "selected", "on-press", "on-*", "key", "global-key"], 16, true)) return;
|
|
128
|
+
if (nsceAttr(node, "title") < 0) { nsceFail(out, 17, 0); return; }
|
|
129
|
+
nsceEmit(out, 200); return;
|
|
130
|
+
}
|
|
131
|
+
if (mode === 9) {
|
|
132
|
+
if (!nscsAttrs(node, out, ["on-*", "y-min", "y-max", "grid-lines", "baseline", "x-labels", "y-labels", "hover-details", "stroke-width", "width", "height", "grow", "padding", "key", "global-key", "label"], 18, true)) return;
|
|
133
|
+
if (node.children.length === 0) { nsceFail(out, 19, 0); return; }
|
|
134
|
+
nsceEmit(out, 100);
|
|
135
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
136
|
+
if (!nsceMetadata(node.children[i]!, "series")) { nsceFail(out, 20, i + 1); return; }
|
|
137
|
+
nsceEmit(out, 101, 0, i);
|
|
138
|
+
}
|
|
139
|
+
nsceEmit(out, 200); return;
|
|
140
|
+
}
|
|
141
|
+
if (mode === 10) {
|
|
142
|
+
if (node.children.length !== 0) { nsceFail(out, 21, 1); return; }
|
|
143
|
+
if (!nscsAttrs(node, out, ["src", "controls", "autoplay", "loop", "muted", "width", "height", "grow", "label", "key", "global-key"], 22, true)) return;
|
|
144
|
+
nsceEmit(out, 200); return;
|
|
145
|
+
}
|
|
146
|
+
if (mode === 11) {
|
|
147
|
+
if (node.children.length !== 0) { nsceFail(out, 23, 1); return; }
|
|
148
|
+
if (!nscsAttrs(node, out, ["kind", "values", "color", "label"], 24, false)) return;
|
|
149
|
+
if (nsceAttr(node, "values") < 0) { nsceFail(out, 25, 0); return; }
|
|
150
|
+
nsceEmit(out, 200); return;
|
|
151
|
+
}
|
|
152
|
+
if (mode === 12) {
|
|
153
|
+
for (const attr of node.attrs) if (nsceOne(attr.name, ["wrap", "overflow"])) { nsceFail(out, 26, 0); return; }
|
|
154
|
+
nsceEmit(out, 100);
|
|
155
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
156
|
+
const child = node.children[i]!;
|
|
157
|
+
if (child.kind === 1) nsceEmit(out, 101, 0, i);
|
|
158
|
+
else if (nsceMetadata(child, "span")) nsceEmit(out, 102, 0, i);
|
|
159
|
+
else { nsceFail(out, 27, i + 1); return; }
|
|
160
|
+
}
|
|
161
|
+
nsceEmit(out, 200); return;
|
|
162
|
+
}
|
|
163
|
+
if (mode === 13 || mode === 21) {
|
|
164
|
+
nsceEmit(out, 100); // shared span-shape capability precedes every evaluation
|
|
165
|
+
const names = ["weight", "scale", "mono", "italic", "underline", "foreground"];
|
|
166
|
+
if (mode === 21) {
|
|
167
|
+
// Static views evaluate the first occurrence of each channel in this
|
|
168
|
+
// order, independently of the source attribute order.
|
|
169
|
+
for (let j = 0; j < names.length; j++) {
|
|
170
|
+
const index = nsceAttr(node, names[j]!);
|
|
171
|
+
if (index >= 0) nsceEmit(out, j + 1, 0, index);
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
for (let i = 0; i < node.attrs.length; i++) {
|
|
175
|
+
for (let j = 0; j < names.length; j++) if (nsceNamed(node.attrs[i]!.name, names[j]!)) nsceEmit(out, j + 1, 0, i);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
nsceEmit(out, 101); nsceEmit(out, 200); return;
|
|
179
|
+
}
|
|
180
|
+
if (mode === 14) {
|
|
181
|
+
if (!nsceNamed(node.name, "step") || kind !== 0) { nsceFail(out, 28, 0); return; }
|
|
182
|
+
for (const attr of node.attrs) if (!nsceNamed(attr.name, "kind")) { nsceFail(out, 29, 0); return; }
|
|
183
|
+
nsceEmit(out, 101); return;
|
|
184
|
+
}
|
|
185
|
+
if (mode === 16) {
|
|
186
|
+
for (let i = 0; i < node.attrs.length; i++) if (!nsceOne(node.attrs[i]!.name, ["window", "each", "as"])) nsceEmit(out, 1, 0, i);
|
|
187
|
+
nsceEmit(out, 100); nsceEmit(out, 200); return;
|
|
188
|
+
}
|
|
189
|
+
if (mode === 0) {
|
|
190
|
+
const nested = windowFacts[0]!, full = windowFacts[1]!, windowsFull = windowFacts[2]!, duplicate = windowFacts[3]!;
|
|
191
|
+
if (nested) { nsceFail(out, 30, 0); return; }
|
|
192
|
+
if (full || node.children.length !== 1 || (node.children[0]!.kind !== 0 && node.children[0]!.kind !== 6)) { nsceFail(out, 31, 0); return; }
|
|
193
|
+
if (nsceAttr(node, "id") < 0) { nsceFail(out, 32, 0); return; }
|
|
194
|
+
if (nsceAttr(node, "as") < 0) { nsceFail(out, 33, 0); return; }
|
|
195
|
+
if (windowsFull) { nsceFail(out, 34, 0); return; }
|
|
196
|
+
if (duplicate) { nsceFail(out, 35, 0); return; }
|
|
197
|
+
for (let i = 1; i <= 6; i++) nsceEmit(out, i);
|
|
198
|
+
nsceEmit(out, 100); // exact logical range fact, before estimator lookup
|
|
199
|
+
if (nsceAttr(node, "extent-estimate") >= 0) nsceEmit(out, 7);
|
|
200
|
+
nsceEmit(out, 101); nsceEmit(out, 102); nsceEmit(out, 103); nsceEmit(out, 200); return;
|
|
201
|
+
}
|
|
202
|
+
if (mode === 1) {
|
|
203
|
+
if (nsceAttr(node, "window") < 0) { nsceFail(out, 36, 0); return; }
|
|
204
|
+
nsceEmit(out, 100); // lookup, admission, then consumed publication
|
|
205
|
+
if (nsceAttr(node, "each") < 0) { nsceFail(out, 37, 0); return; }
|
|
206
|
+
if (nsceAttr(node, "as") < 0) { nsceFail(out, 38, 0); return; }
|
|
207
|
+
if (full || node.children.length !== 1) { nsceFail(out, 39, 0); return; }
|
|
208
|
+
nsceEmit(out, 101); return;
|
|
209
|
+
}
|
|
210
|
+
throw new Error("invalid specialized node mode");
|
|
211
|
+
}
|
|
212
|
+
function nscvMarkupSpecialized(input: Uint8Array): Uint8Array {
|
|
213
|
+
if (input.length < 4 || input[0] !== 112 || input[1] !== 1 || input[2]! > 31 || input[3]! > 1) throw new Error("invalid specialized header");
|
|
214
|
+
const r = new NscElementReader(input), out: number[] = [], mode = input[2]!;
|
|
215
|
+
if (mode === 15) {
|
|
216
|
+
const count = r.word(), expected = r.word();
|
|
217
|
+
if (count !== expected) { nsceFail(out, 40); }
|
|
218
|
+
else { for (let i = 0; i < count; i++) nsceEmit(out, 1, 0, i); nsceEmit(out, 100); nsceEmit(out, 200); }
|
|
219
|
+
} else if (mode === 17) {
|
|
220
|
+
const phase = r.word(), admitted = r.flag();
|
|
221
|
+
if (phase > 2) throw new Error("invalid virtual window phase");
|
|
222
|
+
if (!admitted) nsceFail(out, phase === 0 ? 41 : phase === 1 ? 42 : 43); else nsceEmit(out, 0);
|
|
223
|
+
} else if (mode === 18) {
|
|
224
|
+
const virtual = r.flag(), consumed = r.flag();
|
|
225
|
+
if (!virtual) nsceFail(out, 44); else if (consumed) nsceFail(out, 45); else nsceEmit(out, 0);
|
|
226
|
+
} else if (mode === 19) {
|
|
227
|
+
if (!r.flag()) nsceFail(out, 39); else nsceEmit(out, 0);
|
|
228
|
+
} else if (mode === 20) {
|
|
229
|
+
const count = r.word(), capacity = r.word(), duplicate = r.flag();
|
|
230
|
+
if (count >= capacity) nsceFail(out, 34);
|
|
231
|
+
else if (duplicate) nsceFail(out, 35);
|
|
232
|
+
else nsceEmit(out, 0);
|
|
233
|
+
} else nscsNode(r, out, mode);
|
|
234
|
+
if (r.at !== input.length) throw new Error("trailing specialized facts");
|
|
235
|
+
const count = out.length / 7, bytes = new Uint8Array(input[3] === 0 ? 16 : 16 + count * 48), wire = new DataView(bytes.buffer);
|
|
236
|
+
bytes[0] = 112; bytes[1] = 1; bytes[2] = input[3]!; wire.setFloat64(8, count, true);
|
|
237
|
+
if (input[3] === 1) for (let i = 0; i < count; i++) {
|
|
238
|
+
const at = 16 + i * 48, from = i * 7; bytes[at] = out[from]!; bytes[at + 1] = out[from + 1]!;
|
|
239
|
+
for (let j = 0; j < 5; j++) wire.setFloat64(at + 8 + j * 8, out[from + j + 2]!, true);
|
|
240
|
+
}
|
|
241
|
+
return bytes;
|
|
242
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Markup text/calendar capabilities (103). Byte chunks carry no pointers;
|
|
2
|
+
* exact integer decimal conversion and timestamp division remain native.
|
|
3
|
+
* Results describe either owned bytes or cuts/choices into caller storage.
|
|
4
|
+
* Modes: upper, lower, trim, thousands, pad, date, time, datetime, plural.
|
|
5
|
+
*/
|
|
6
|
+
function nscvMarkupTextSpace(byte: number): boolean {
|
|
7
|
+
return byte === 32 || byte === 9 || byte === 13 || byte === 10;
|
|
8
|
+
}
|
|
9
|
+
function nscvMarkupTextDigits(out: Uint8Array, at: number, value: number, width: number): void {
|
|
10
|
+
for (let i = width - 1; i >= 0; i--) {
|
|
11
|
+
out[at + i] = 48 + value % 10;
|
|
12
|
+
value = Math.floor(value / 10);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function nscvMarkupText(request: Uint8Array): Uint8Array {
|
|
16
|
+
if (request.length < 32 || request[0] !== 103 || request[1] !== 1 || request[2]! > 8)
|
|
17
|
+
throw new Error("invalid markup text header");
|
|
18
|
+
const mode = request[2]!, width = request[3]!, r = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
19
|
+
const length = r.getUint16(4, true);
|
|
20
|
+
if (length > 256 || request.length !== 32 + length || width > (mode === 4 ? 6 : 0) ||
|
|
21
|
+
r.getUint16(6, true) !== 0 || r.getUint32(8, true) !== 0 || r.getUint32(12, true) !== 0 ||
|
|
22
|
+
(mode >= 5 && length !== 0) || r.getUint32(28, true) !== 0)
|
|
23
|
+
throw new Error("invalid markup text storage");
|
|
24
|
+
if (mode < 5 && (r.getUint32(16, true) !== 0 || r.getUint32(20, true) !== 0 || r.getUint32(24, true) !== 0) ||
|
|
25
|
+
mode === 8 && r.getUint32(24, true) !== 0) throw new Error("invalid markup text facts");
|
|
26
|
+
const bytes = request.subarray(32);
|
|
27
|
+
let resultLength = 0, sign = 0, zeros = 0, first = 0, last = length;
|
|
28
|
+
if (mode === 0 || mode === 1) resultLength = length;
|
|
29
|
+
else if (mode === 2) {
|
|
30
|
+
while (first < length && nscvMarkupTextSpace(bytes[first]!)) first++;
|
|
31
|
+
while (last > first && nscvMarkupTextSpace(bytes[last - 1]!)) last--;
|
|
32
|
+
} else if (mode === 3 || mode === 4) {
|
|
33
|
+
if (length === 0 || length > 20) throw new Error("invalid markup decimal length");
|
|
34
|
+
sign = bytes[0] === 45 ? 1 : 0;
|
|
35
|
+
if (length === sign) throw new Error("invalid markup decimal sign");
|
|
36
|
+
for (let i = sign; i < length; i++) if (bytes[i]! < 48 || bytes[i]! > 57)
|
|
37
|
+
throw new Error("invalid markup decimal byte");
|
|
38
|
+
zeros = Math.max(0, width - (length - sign));
|
|
39
|
+
resultLength = length + (mode === 3 ? Math.floor((length - sign - 1) / 3) : 0);
|
|
40
|
+
} else if (mode < 8) {
|
|
41
|
+
const days = r.getFloat64(16, true), seconds = r.getUint32(24, true);
|
|
42
|
+
if (!Number.isSafeInteger(days) || Math.abs(days) > 106751991167301 || seconds >= 86400)
|
|
43
|
+
throw new Error("invalid markup timestamp facts");
|
|
44
|
+
resultLength = days < -719162 || days > 2932896 ? 0 : mode === 5 ? 10 : mode === 6 ? 5 : 16;
|
|
45
|
+
}
|
|
46
|
+
const out = new Uint8Array(16 + resultLength), w = new DataView(out.buffer);
|
|
47
|
+
out[0] = 103; out[1] = 1; out[2] = mode; w.setUint16(8, resultLength, true);
|
|
48
|
+
if (mode === 0 || mode === 1) {
|
|
49
|
+
for (let i = 0; i < length; i++) {
|
|
50
|
+
const b = bytes[i]!;
|
|
51
|
+
out[16 + i] = mode === 0 && b >= 97 && b <= 122 ? b - 32 : mode === 1 && b >= 65 && b <= 90 ? b + 32 : b;
|
|
52
|
+
}
|
|
53
|
+
} else if (mode === 2) {
|
|
54
|
+
w.setUint16(4, first, true); w.setUint16(6, last, true);
|
|
55
|
+
} else if (mode === 3) {
|
|
56
|
+
let at = 16;
|
|
57
|
+
if (sign === 1) out[at++] = 45;
|
|
58
|
+
for (let i = sign; i < length; i++) {
|
|
59
|
+
if (i > sign && (length - i) % 3 === 0) out[at++] = 44;
|
|
60
|
+
out[at++] = bytes[i]!;
|
|
61
|
+
}
|
|
62
|
+
} else if (mode === 4) {
|
|
63
|
+
out[4] = sign; out[5] = zeros; out[6] = length - sign;
|
|
64
|
+
for (let i = 0; i < length; i++) out[16 + i] = bytes[i]!;
|
|
65
|
+
} else if (mode < 8) {
|
|
66
|
+
if (resultLength === 0) { out[3] = 1; return out; }
|
|
67
|
+
// Gregorian eras use exact small integers after the admitted year range.
|
|
68
|
+
const shifted = r.getFloat64(16, true) + 719468, era = Math.floor(shifted / 146097);
|
|
69
|
+
const dayOfEra = shifted - era * 146097;
|
|
70
|
+
const yearOfEra = Math.floor((dayOfEra - Math.floor(dayOfEra / 1460) + Math.floor(dayOfEra / 36524) - Math.floor(dayOfEra / 146096)) / 365);
|
|
71
|
+
const dayOfYear = dayOfEra - (365 * yearOfEra + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100));
|
|
72
|
+
const monthIndex = Math.floor((5 * dayOfYear + 2) / 153), month = monthIndex < 10 ? monthIndex + 3 : monthIndex - 9;
|
|
73
|
+
const year = yearOfEra + era * 400 + (month <= 2 ? 1 : 0), day = dayOfYear - Math.floor((153 * monthIndex + 2) / 5) + 1;
|
|
74
|
+
if (mode !== 6) {
|
|
75
|
+
nscvMarkupTextDigits(out, 16, year, 4); out[20] = 45;
|
|
76
|
+
nscvMarkupTextDigits(out, 21, month, 2); out[23] = 45; nscvMarkupTextDigits(out, 24, day, 2);
|
|
77
|
+
}
|
|
78
|
+
if (mode !== 5) {
|
|
79
|
+
const at = mode === 6 ? 16 : 27, seconds = r.getUint32(24, true);
|
|
80
|
+
if (mode === 7) out[26] = 32;
|
|
81
|
+
nscvMarkupTextDigits(out, at, Math.floor(seconds / 3600), 2); out[at + 2] = 58;
|
|
82
|
+
nscvMarkupTextDigits(out, at + 3, Math.floor(seconds % 3600 / 60), 2);
|
|
83
|
+
}
|
|
84
|
+
} else out[4] = r.getUint32(16, true) === 1 && r.getUint32(20, true) === 0 ? 1 : 2;
|
|
85
|
+
return out;
|
|
86
|
+
}
|