@native-sdk/cli 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/build/app.zig +308 -72
  2. package/build/ts_run.mjs +63 -0
  3. package/build.zig +336 -7
  4. package/build.zig.zon +1 -0
  5. package/package.json +15 -10
  6. package/packages/core/package-lock.json +43 -0
  7. package/packages/core/package.json +37 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +536 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/core/SKILL.md +3 -0
  28. package/skill-data/native-ui/SKILL.md +30 -0
  29. package/skill-data/ts-core/SKILL.md +493 -0
  30. package/skill-data/zig/SKILL.md +208 -0
  31. package/skills/native-sdk/SKILL.md +1 -1
  32. package/src/app_runner/root.zig +75 -9
  33. package/src/app_runner/ts_core_main.zig +231 -0
  34. package/src/platform/linux/gtk_host.c +226 -21
  35. package/src/platform/windows/webview2_host.cpp +16 -10
  36. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  37. package/src/primitives/app_manifest/root.zig +13 -0
  38. package/src/primitives/app_manifest/types.zig +14 -0
  39. package/src/primitives/app_manifest/validation.zig +18 -0
  40. package/src/primitives/app_manifest/web_layer.zig +366 -0
  41. package/src/primitives/canvas/commands.zig +14 -7
  42. package/src/primitives/canvas/lazy_tls.zig +73 -0
  43. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  44. package/src/primitives/canvas/root.zig +6 -0
  45. package/src/primitives/canvas/tests.zig +1 -0
  46. package/src/primitives/canvas/text_atlas.zig +40 -32
  47. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  48. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  49. package/src/primitives/canvas/text_spans.zig +39 -26
  50. package/src/primitives/canvas/tokens.zig +54 -0
  51. package/src/primitives/canvas/ui.zig +125 -0
  52. package/src/primitives/canvas/ui_markup.zig +22 -3
  53. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  54. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  55. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  56. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  57. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  58. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  59. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  60. package/src/primitives/canvas/ui_schema.zig +8 -0
  61. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  62. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  63. package/src/primitives/canvas/widget_render.zig +25 -15
  64. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  65. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  66. package/src/root.zig +7 -0
  67. package/src/runtime/api.zig +7 -0
  68. package/src/runtime/bridge_responses.zig +2 -0
  69. package/src/runtime/builtin_bridge.zig +6 -0
  70. package/src/runtime/canvas_frame.zig +57 -36
  71. package/src/runtime/canvas_images.zig +9 -3
  72. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  73. package/src/runtime/canvas_widget_runtime.zig +7 -4
  74. package/src/runtime/effects.zig +490 -2
  75. package/src/runtime/effects_host_tests.zig +594 -0
  76. package/src/runtime/flow.zig +8 -0
  77. package/src/runtime/platform_bridge_tests.zig +1 -0
  78. package/src/runtime/root.zig +18 -0
  79. package/src/runtime/session_replay.zig +7 -1
  80. package/src/runtime/session_tests.zig +35 -8
  81. package/src/runtime/tests.zig +2 -0
  82. package/src/runtime/ts_core_host.zig +1505 -0
  83. package/src/runtime/ts_core_host_tests.zig +1408 -0
  84. package/src/runtime/ts_ui_app.zig +469 -0
  85. package/src/runtime/ui_app.zig +58 -0
  86. package/src/runtime/view_canvas.zig +24 -17
  87. package/src/runtime/view_widget_tree.zig +2 -2
  88. package/src/runtime/web_layer_gate_tests.zig +242 -0
  89. package/src/runtime/window_storage.zig +5 -0
  90. package/src/runtime/window_view_runtime.zig +1 -0
  91. package/src/tooling/buildgraph.zig +7 -1
  92. package/src/tooling/codesign.zig +212 -105
  93. package/src/tooling/doctor.zig +78 -0
  94. package/src/tooling/manifest.zig +314 -1
  95. package/src/tooling/package.zig +722 -18
  96. package/src/tooling/raw_manifest.zig +16 -0
  97. package/src/tooling/root.zig +1 -0
  98. package/src/tooling/templates.zig +911 -88
  99. package/src/tooling/ts_core.zig +486 -0
  100. package/src/tooling/verbs.zig +22 -0
@@ -46,6 +46,15 @@ const Profile = struct {
46
46
  age: u32 = 30,
47
47
  };
48
48
 
49
+ /// The transpiled-core mirror of `canvas.ScrollState` (field names pinned
50
+ /// by the reflect drift test below; classes per field).
51
+ const MirrorScroll = struct {
52
+ offset: f64,
53
+ velocity: f64,
54
+ viewport_extent: f64,
55
+ content_extent: f64,
56
+ };
57
+
49
58
  const Msg = union(enum) {
50
59
  add,
51
60
  remove: u32,
@@ -54,7 +63,9 @@ const Msg = union(enum) {
54
63
  scale: f32,
55
64
  draft: canvas.TextInputEvent,
56
65
  scrolled: canvas.ScrollState,
66
+ mirror_scrolled: MirrorScroll,
57
67
  pane: f32,
68
+ pane_wide: f64,
58
69
  tick,
59
70
  };
60
71
 
@@ -68,6 +79,7 @@ const Model = struct {
68
79
  cards: [2]Card = .{ .{ .id = 1 }, .{ .id = 2 } },
69
80
  hidden: u8 = 0,
70
81
  history: [4]f32 = .{ 0.1, 0.4, 0.2, 0.8 },
82
+ samples: [3]f64 = .{ 0.25, 0.5, 1 },
71
83
  stages: [4][]const u8 = .{ "one", "two", "three", "four" },
72
84
  draft_buffer: canvas.TextBuffer(16) = .{},
73
85
 
@@ -340,6 +352,64 @@ const fixtures = [_]Fixture{
340
352
  ,
341
353
  .expect = "expected a number",
342
354
  },
355
+ .{
356
+ // The value-payload change event: a slider's bare on-change tag
357
+ // naming an f32 arm dispatches the applied fraction.
358
+ .name = "a slider on-change value arm (f32) accepts",
359
+ .source =
360
+ \\<slider value="{ratio}" on-change="scale" label="Weight" />
361
+ ,
362
+ .expect = null,
363
+ },
364
+ .{
365
+ // The transpiled one-number float arm matches structurally.
366
+ .name = "a slider on-change value arm (f64) accepts",
367
+ .source =
368
+ \\<slider value="{ratio}" on-change="pane_wide" label="Weight" />
369
+ ,
370
+ .expect = null,
371
+ },
372
+ .{
373
+ // A non-value payload arm keeps the static-form contract: a bare
374
+ // tag with a payload the value event cannot fill is the ordinary
375
+ // missing-payload teaching.
376
+ .name = "a slider on-change naming a non-value payload arm rejects",
377
+ .source =
378
+ \\<slider value="{ratio}" on-change="remove" label="Weight" />
379
+ ,
380
+ .expect = "message requires a payload",
381
+ },
382
+ .{
383
+ // The declared scroll-state mirror binds on-scroll like the canvas
384
+ // type (transpiled cores).
385
+ .name = "a declared scroll-state mirror arm accepts on-scroll",
386
+ .source =
387
+ \\<scroll on-scroll="mirror_scrolled">
388
+ \\ <column><text>body</text></column>
389
+ \\</scroll>
390
+ ,
391
+ .expect = null,
392
+ },
393
+ .{
394
+ .name = "an on-scroll tag without a scroll-state payload rejects",
395
+ .source =
396
+ \\<scroll on-scroll="pane">
397
+ \\ <column><text>body</text></column>
398
+ \\</scroll>
399
+ ,
400
+ .expect = markup.on_scroll_payload_message,
401
+ },
402
+ .{
403
+ // The transpiled one-number float arm carries the split fraction.
404
+ .name = "a split on-resize f64 arm accepts",
405
+ .source =
406
+ \\<split value="{ratio}" on-resize="pane_wide">
407
+ \\ <panel><text>a</text></panel>
408
+ \\ <panel><text>b</text></panel>
409
+ \\</split>
410
+ ,
411
+ .expect = null,
412
+ },
343
413
  .{
344
414
  .name = "a whole-number binding in resize-duration accepts",
345
415
  .source =
@@ -469,6 +539,19 @@ const fixtures = [_]Fixture{
469
539
  ,
470
540
  .expect = null,
471
541
  },
542
+ .{
543
+ // f64 is the transpiled-core float class: TS number arrays emit
544
+ // as []const f64 and both engines narrow them per sample.
545
+ .name = "a chart with f64 series bindings (the transpiled-core float class) accepts",
546
+ .source =
547
+ \\<column>
548
+ \\ <chart y-min="0" y-max="1" label="Window">
549
+ \\ <series kind="bar" values="{samples}" />
550
+ \\ </chart>
551
+ \\</column>
552
+ ,
553
+ .expect = null,
554
+ },
472
555
  .{
473
556
  .name = "a series values binding to a non-f32 iterable rejects",
474
557
  .source =
@@ -909,7 +992,7 @@ fn findMsg(c: contract.Contract, name: []const u8) ?contract.MsgTag {
909
992
 
910
993
  // ------------------------------------------------------------- staleness
911
994
 
912
- test "hashSourceDir changes when a source file changes and ignores non-Zig files" {
995
+ test "hashSourceDir changes when a source file changes and ignores non-core files" {
913
996
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
914
997
  defer arena_state.deinit();
915
998
  const arena = arena_state.allocator();
@@ -923,7 +1006,7 @@ test "hashSourceDir changes when a source file changes and ignores non-Zig files
923
1006
  const first = try contract.hashSourceDirAt(arena, io, tmp.dir, ".");
924
1007
 
925
1008
  // A markup edit must not invalidate the contract (it is derived from
926
- // the Zig side only)...
1009
+ // the core side only)...
927
1010
  try tmp.dir.writeFile(io, .{ .sub_path = "view.native", .data = "<row/>" });
928
1011
  try testing.expectEqual(first, try contract.hashSourceDirAt(arena, io, tmp.dir, "."));
929
1012
 
@@ -932,6 +1015,35 @@ test "hashSourceDir changes when a source file changes and ignores non-Zig files
932
1015
  try testing.expect(first != try contract.hashSourceDirAt(arena, io, tmp.dir, "."));
933
1016
  }
934
1017
 
1018
+ test "hashSourceDir: a core.ts edit invalidates the contract on the TS track" {
1019
+ // The wave-2 trap: `src/core.ts` is the Model/Msg truth on the TS
1020
+ // track, but it is not a `.zig` file — a hash over Zig sources only
1021
+ // kept a scaffold-era contract "fresh" through every core edit, and
1022
+ // `native check` reported phantom unknown-tag/unknown-field errors
1023
+ // naming the user's NEW state. TypeScript sources must invalidate.
1024
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1025
+ defer arena_state.deinit();
1026
+ const arena = arena_state.allocator();
1027
+ const io = testing.io;
1028
+
1029
+ var tmp = std.testing.tmpDir(.{ .iterate = true });
1030
+ defer tmp.cleanup();
1031
+ try tmp.dir.writeFile(io, .{ .sub_path = "core.ts", .data = "export const model = { count: 0 };\n" });
1032
+ try tmp.dir.writeFile(io, .{ .sub_path = "app.native", .data = "<column/>" });
1033
+
1034
+ const first = try contract.hashSourceDirAt(arena, io, tmp.dir, ".");
1035
+
1036
+ // Editing the TypeScript core must change the hash...
1037
+ try tmp.dir.writeFile(io, .{ .sub_path = "core.ts", .data = "export const model = { count: 0, phase: \"rest\" };\n" });
1038
+ const second = try contract.hashSourceDirAt(arena, io, tmp.dir, ".");
1039
+ try testing.expect(first != second);
1040
+
1041
+ // ...and a new imported .ts module under src/ must too (the checker
1042
+ // runs the core's whole import graph).
1043
+ try tmp.dir.writeFile(io, .{ .sub_path = "timers.ts", .data = "export const tick = 1;\n" });
1044
+ try testing.expect(second != try contract.hashSourceDirAt(arena, io, tmp.dir, "."));
1045
+ }
1046
+
935
1047
  test "a wrong-typed series values binding names the model item type" {
936
1048
  // The teaching error carries the fix: the binding named, and what it
937
1049
  // actually iterates.
@@ -951,3 +1063,146 @@ test "a wrong-typed series values binding names the model item type" {
951
1063
  try testing.expect(std.mem.indexOf(u8, message, "\"cards\" iterates") != null);
952
1064
  try testing.expect(std.mem.indexOf(u8, message, "Card") != null);
953
1065
  }
1066
+
1067
+ // -------------------------------------------- committed-model (pointer) shape
1068
+
1069
+ const PointerMeta = struct {
1070
+ title: []const u8 = "lib",
1071
+ total: i64 = 0,
1072
+ };
1073
+
1074
+ /// A self-referential pointer node: legal in committed models (shared
1075
+ /// nodes may link), and the describe walk must stop at the cycle instead
1076
+ /// of recursing forever.
1077
+ const PointerNode = struct {
1078
+ id: i64 = 0,
1079
+ next: ?*const PointerNode = null,
1080
+ parent: *const PointerMeta = &.{},
1081
+ };
1082
+
1083
+ const PointerModel = struct {
1084
+ meta: *const PointerMeta = &.{},
1085
+ rows: []const *const PointerNode = &.{},
1086
+ head: *const PointerNode = &.{},
1087
+ };
1088
+
1089
+ const PointerMsg = union(enum) { open: i64 };
1090
+
1091
+ test "describe traverses *const record fields and pointer-item lists like the engines" {
1092
+ const c = comptime contract.describe(PointerModel, PointerMsg, specials);
1093
+
1094
+ // The `*const` record field is a traversable group named for the
1095
+ // struct it shares.
1096
+ var found_meta = false;
1097
+ for (c.model.groups) |group| {
1098
+ if (std.mem.eql(u8, group.name, "meta")) {
1099
+ found_meta = true;
1100
+ try testing.expect(findScalar(group.group, "title").?.kind == .string);
1101
+ try testing.expect(findScalar(group.group, "total").?.kind == .integer);
1102
+ }
1103
+ }
1104
+ try testing.expect(found_meta);
1105
+
1106
+ // A `[]const *const T` iterable binds item fields like `[]const T`.
1107
+ var found_rows = false;
1108
+ for (c.iterables) |iterable| {
1109
+ if (std.mem.eql(u8, iterable.name, "rows")) {
1110
+ found_rows = true;
1111
+ try testing.expect(!iterable.item_scalar);
1112
+ try testing.expect(findScalar(iterable.item, "id").?.kind == .integer);
1113
+ }
1114
+ }
1115
+ try testing.expect(found_rows);
1116
+
1117
+ // The cyclic `next` pointer stopped the walk (the group exists via
1118
+ // `head`, but no infinite nesting), and the optional pointer stayed
1119
+ // unbindable — optionals of records gate through scalar flags.
1120
+ var found_head = false;
1121
+ for (c.model.groups) |group| {
1122
+ if (std.mem.eql(u8, group.name, "head")) {
1123
+ found_head = true;
1124
+ var nested_next = false;
1125
+ for (group.group.groups) |nested| {
1126
+ if (std.mem.eql(u8, nested.name, "next")) nested_next = true;
1127
+ }
1128
+ try testing.expect(!nested_next);
1129
+ }
1130
+ }
1131
+ try testing.expect(found_head);
1132
+ }
1133
+
1134
+ // ----------------------------------------------- declared text-input unions
1135
+
1136
+ test "the reflect tag vocabulary never drifts from canvas.TextInputEvent" {
1137
+ const reflect = @import("ui_markup_reflect.zig");
1138
+ const event_fields = @typeInfo(canvas.TextInputEvent).@"union".fields;
1139
+ try testing.expectEqual(reflect.text_input_event_tags.len, event_fields.len);
1140
+ inline for (event_fields) |field| {
1141
+ var found = false;
1142
+ for (reflect.text_input_event_tags) |tag| {
1143
+ if (std.mem.eql(u8, tag, field.name)) found = true;
1144
+ }
1145
+ try testing.expect(found);
1146
+ }
1147
+ const direction_fields = @typeInfo(canvas.TextCaretDirection).@"enum".fields;
1148
+ try testing.expectEqual(reflect.text_caret_direction_members.len, direction_fields.len);
1149
+ inline for (direction_fields) |field| {
1150
+ var found = false;
1151
+ for (reflect.text_caret_direction_members) |member| {
1152
+ if (std.mem.eql(u8, member, field.name)) found = true;
1153
+ }
1154
+ try testing.expect(found);
1155
+ }
1156
+ }
1157
+
1158
+ test "the reflect field vocabulary never drifts from canvas.ScrollState" {
1159
+ const reflect = @import("ui_markup_reflect.zig");
1160
+ const state_fields = @typeInfo(canvas.ScrollState).@"struct".fields;
1161
+ try testing.expectEqual(reflect.scroll_state_field_names.len, state_fields.len);
1162
+ inline for (state_fields) |field| {
1163
+ // Every real field appears in the pinned vocabulary, and every
1164
+ // real field is the f32 the translation widens from — a canvas
1165
+ // field changing type (or gaining a sibling) fails here first.
1166
+ try testing.expectEqual(f32, field.type);
1167
+ var found = false;
1168
+ for (reflect.scroll_state_field_names) |name| {
1169
+ if (std.mem.eql(u8, name, field.name)) found = true;
1170
+ }
1171
+ try testing.expect(found);
1172
+ }
1173
+ }
1174
+
1175
+ test "a declared scroll-state mirror classifies as a scroll_state payload" {
1176
+ var saw_mirror = false;
1177
+ var saw_wide_pane = false;
1178
+ for (model_contract.msgs) |tag| {
1179
+ if (std.mem.eql(u8, tag.name, "mirror_scrolled")) {
1180
+ saw_mirror = true;
1181
+ try testing.expectEqual(contract.PayloadClass.scroll_state, tag.payload);
1182
+ }
1183
+ if (std.mem.eql(u8, tag.name, "pane_wide")) {
1184
+ saw_wide_pane = true;
1185
+ try testing.expectEqual(contract.PayloadClass.float, tag.payload);
1186
+ try testing.expectEqualStrings("f64", tag.payload_type);
1187
+ }
1188
+ }
1189
+ try testing.expect(saw_mirror);
1190
+ try testing.expect(saw_wide_pane);
1191
+ }
1192
+
1193
+ test "a declared mirror union classifies as a text_input payload" {
1194
+ const mirror_fixture = @import("ui_markup_view_tests.zig");
1195
+ const mirror_contract = comptime contract.describe(
1196
+ mirror_fixture.MirrorModel,
1197
+ mirror_fixture.MirrorMsg,
1198
+ specials,
1199
+ );
1200
+ var saw_edit = false;
1201
+ for (mirror_contract.msgs) |tag| {
1202
+ if (std.mem.eql(u8, tag.name, "edit")) {
1203
+ saw_edit = true;
1204
+ try testing.expectEqual(contract.PayloadClass.text_input, tag.payload);
1205
+ }
1206
+ }
1207
+ try testing.expect(saw_edit);
1208
+ }
@@ -33,6 +33,21 @@ pub fn typeScanQuota(comptime T: type) u32 {
33
33
  return 2000 + entries * 64 + entries * entries;
34
34
  }
35
35
 
36
+ /// Single-item const pointers are transparent in binding traversal: a
37
+ /// `*const Row` nested-record field or list element binds exactly like
38
+ /// the struct it points at. This is the committed-model idiom — shared
39
+ /// nodes referenced by pointer, the shape transpiled cores emit for
40
+ /// records and record arrays — and it mirrors `sliceElement`'s existing
41
+ /// pointer transparency for iterables. Mutable single-item pointers stay
42
+ /// opaque: markup reads models, so a bindable path must not smuggle a
43
+ /// mutation channel.
44
+ pub fn Pointee(comptime T: type) type {
45
+ return switch (@typeInfo(T)) {
46
+ .pointer => |info| if (info.size == .one and info.is_const) Pointee(info.child) else T,
47
+ else => T,
48
+ };
49
+ }
50
+
36
51
  /// The element type a `for each` can iterate from this declaration:
37
52
  /// slices, arrays, and single-item pointers to either.
38
53
  pub fn sliceElement(comptime T: type) ?type {
@@ -87,6 +102,205 @@ pub fn isZeroArgFn(comptime T: type, comptime DeclType: type) bool {
87
102
  return info.params.len == 1 and info.return_type != null and info.params[0].type == *const T;
88
103
  }
89
104
 
105
+ /// The canvas `TextInputEvent` union's tag vocabulary, pinned here so the
106
+ /// declared-shape predicate below stays std-only. A drift test in
107
+ /// `ui_markup_contract_tests.zig` holds this list equal to the real union.
108
+ pub const text_input_event_tags = [_][]const u8{
109
+ "insert_text", "delete_backward", "delete_forward", "delete_word_backward",
110
+ "delete_word_forward", "clear", "move_caret", "set_selection",
111
+ "set_composition", "commit_composition", "cancel_composition",
112
+ };
113
+
114
+ /// The caret-direction member vocabulary (`canvas.TextCaretDirection`).
115
+ pub const text_caret_direction_members = [_][]const u8{
116
+ "previous", "next", "previous_word", "next_word", "start", "end",
117
+ };
118
+
119
+ /// A Msg arm payload union DECLARING the text-input event shape rather than
120
+ /// being `canvas.TextInputEvent` by identity — the transpiled-core case,
121
+ /// where the emitted module declares its own mirror union (type identity
122
+ /// cannot cross the emission boundary). Matched structurally, by the same
123
+ /// contract everywhere markup resolves `on-input`:
124
+ /// - a tagged union carrying exactly the eleven canvas event tags;
125
+ /// - `insert_text` a bytes payload; the seven verb arms void;
126
+ /// - `move_caret` a record of `direction` (an enum with exactly the six
127
+ /// caret-direction member names) and `extend: bool`;
128
+ /// - `set_selection` a record of numeric `anchor`/`focus`;
129
+ /// - `set_composition` a record of bytes `text` and optional numeric
130
+ /// `cursor`.
131
+ /// Numeric fields accept integer or float (the transpiler's number model
132
+ /// classes each slot); the dispatch translation widens accordingly.
133
+ pub fn declaredTextInputUnion(comptime T: type) bool {
134
+ const info = switch (@typeInfo(T)) {
135
+ .@"union" => |u| u,
136
+ else => return false,
137
+ };
138
+ if (info.tag_type == null) return false;
139
+ if (info.fields.len != text_input_event_tags.len) return false;
140
+ inline for (text_input_event_tags) |tag| {
141
+ if (!@hasField(T, tag)) return false;
142
+ }
143
+ inline for (info.fields) |field| {
144
+ if (comptime std.mem.eql(u8, field.name, "insert_text")) {
145
+ if (!isBytes(field.type)) return false;
146
+ } else if (comptime std.mem.eql(u8, field.name, "move_caret")) {
147
+ if (!isCaretMoveRecord(field.type)) return false;
148
+ } else if (comptime std.mem.eql(u8, field.name, "set_selection")) {
149
+ if (!isSelectionRecord(field.type)) return false;
150
+ } else if (comptime std.mem.eql(u8, field.name, "set_composition")) {
151
+ if (!isCompositionRecord(field.type)) return false;
152
+ } else if (field.type != void) {
153
+ return false;
154
+ }
155
+ }
156
+ return true;
157
+ }
158
+
159
+ /// The canvas `ScrollState` field vocabulary, pinned here so the
160
+ /// declared-shape predicate below stays std-only. A drift test in
161
+ /// `ui_markup_contract_tests.zig` holds this list equal to the real
162
+ /// struct's fields (names and f32 types alike).
163
+ pub const scroll_state_field_names = [_][]const u8{
164
+ "offset", "velocity", "viewport_extent", "content_extent",
165
+ };
166
+
167
+ /// The same vocabulary in the TS SDK's spelling (`@native-sdk/core/events`
168
+ /// `ScrollState`): transpiled cores emit their mirror record with the
169
+ /// field names the TS source wrote — your names are your names — so the
170
+ /// structural match accepts either spelling, never a mix.
171
+ pub const scroll_state_field_names_ts = [_][]const u8{
172
+ "offset", "velocity", "viewportExtent", "contentExtent",
173
+ };
174
+
175
+ /// A Msg arm payload record DECLARING the scroll-state shape rather than
176
+ /// being `canvas.ScrollState` by identity — the transpiled-core case,
177
+ /// where the emitted module declares its own mirror record (type identity
178
+ /// cannot cross the emission boundary). Matched structurally, the
179
+ /// `declaredTextInputUnion` contract applied to `on-scroll`: a struct of
180
+ /// exactly the four field names in either the canvas spelling
181
+ /// (`viewport_extent`, Zig-declared mirrors and `canvas.ScrollState`
182
+ /// itself) or the TS SDK spelling (`viewportExtent`, the emitted-core
183
+ /// mirror — transpiled fields keep their TS names), each numeric. Integer
184
+ /// or float per field (the transpiler's number model classes each slot);
185
+ /// the dispatch translation widens floats exactly and rounds
186
+ /// integer-classed fields to the nearest whole number.
187
+ pub fn declaredScrollStateRecord(comptime T: type) bool {
188
+ const info = switch (@typeInfo(T)) {
189
+ .@"struct" => |s| s,
190
+ else => return false,
191
+ };
192
+ if (info.fields.len != scroll_state_field_names.len) return false;
193
+ const canvas_spelling = comptime blk: {
194
+ for (scroll_state_field_names) |name| {
195
+ if (!@hasField(T, name)) break :blk false;
196
+ }
197
+ break :blk true;
198
+ };
199
+ const ts_spelling = comptime blk: {
200
+ for (scroll_state_field_names_ts) |name| {
201
+ if (!@hasField(T, name)) break :blk false;
202
+ }
203
+ break :blk true;
204
+ };
205
+ if (!canvas_spelling and !ts_spelling) return false;
206
+ inline for (info.fields) |field| {
207
+ if (!isNumeric(field.type)) return false;
208
+ }
209
+ return true;
210
+ }
211
+
212
+ /// The machine classes a value-carrying Msg arm may declare for the
213
+ /// markup value events (slider `on-change`, split `on-resize`): `f32` is
214
+ /// the canvas-native payload Zig cores declare; `f64` is the one-number
215
+ /// float arm transpiled cores emit (the timestamp-arm shape, float side),
216
+ /// matched structurally because type identity cannot cross the emission
217
+ /// boundary — the dispatch translation widens the runtime's applied f32
218
+ /// exactly. Integer arms are deliberately excluded: both value events
219
+ /// deliver a clamped 0..1 fraction (the slider and split contracts), so
220
+ /// an integer arm could only ever receive 0 or 1 — silently useless data
221
+ /// the teaching message refuses instead.
222
+ pub const ValueArmClass = enum { identity, float };
223
+
224
+ /// Classify a Msg arm payload as a value arm, or null when the arm
225
+ /// cannot carry the control's applied value.
226
+ pub fn valueArmClass(comptime T: type) ?ValueArmClass {
227
+ if (T == f32) return .identity;
228
+ if (T == f64) return .float;
229
+ return null;
230
+ }
231
+
232
+ fn isBytes(comptime T: type) bool {
233
+ return switch (@typeInfo(T)) {
234
+ .pointer => |info| info.size == .slice and info.child == u8 and info.is_const,
235
+ else => false,
236
+ };
237
+ }
238
+
239
+ fn isNumeric(comptime T: type) bool {
240
+ return switch (@typeInfo(T)) {
241
+ .int, .float => true,
242
+ else => false,
243
+ };
244
+ }
245
+
246
+ fn isCaretMoveRecord(comptime T: type) bool {
247
+ const info = switch (@typeInfo(T)) {
248
+ .@"struct" => |s| s,
249
+ else => return false,
250
+ };
251
+ if (info.fields.len != 2) return false;
252
+ if (!@hasField(T, "direction") or !@hasField(T, "extend")) return false;
253
+ inline for (info.fields) |field| {
254
+ if (comptime std.mem.eql(u8, field.name, "extend")) {
255
+ if (field.type != bool) return false;
256
+ } else {
257
+ const members = switch (@typeInfo(field.type)) {
258
+ .@"enum" => |e| e.fields,
259
+ else => return false,
260
+ };
261
+ if (members.len != text_caret_direction_members.len) return false;
262
+ inline for (text_caret_direction_members) |name| {
263
+ if (!@hasField(field.type, name)) return false;
264
+ }
265
+ }
266
+ }
267
+ return true;
268
+ }
269
+
270
+ fn isSelectionRecord(comptime T: type) bool {
271
+ const info = switch (@typeInfo(T)) {
272
+ .@"struct" => |s| s,
273
+ else => return false,
274
+ };
275
+ if (info.fields.len != 2) return false;
276
+ if (!@hasField(T, "anchor") or !@hasField(T, "focus")) return false;
277
+ inline for (info.fields) |field| {
278
+ if (!isNumeric(field.type)) return false;
279
+ }
280
+ return true;
281
+ }
282
+
283
+ fn isCompositionRecord(comptime T: type) bool {
284
+ const info = switch (@typeInfo(T)) {
285
+ .@"struct" => |s| s,
286
+ else => return false,
287
+ };
288
+ if (info.fields.len != 2) return false;
289
+ if (!@hasField(T, "text") or !@hasField(T, "cursor")) return false;
290
+ inline for (info.fields) |field| {
291
+ if (comptime std.mem.eql(u8, field.name, "text")) {
292
+ if (!isBytes(field.type)) return false;
293
+ } else {
294
+ const inner = switch (@typeInfo(field.type)) {
295
+ .optional => |o| o.child,
296
+ else => return false,
297
+ };
298
+ if (!isNumeric(inner)) return false;
299
+ }
300
+ }
301
+ return true;
302
+ }
303
+
90
304
  /// Types a binding leaf can produce a `Value` from, mirroring the
91
305
  /// interpreter's runtime acceptance (`valueOf` returning null is exactly
92
306
  /// when the interpreter reports an unresolvable binding).