@native-sdk/cli 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/build/app.zig +26 -9
  2. package/build.zig +124 -1
  3. package/package.json +9 -9
  4. package/packages/core/package-lock.json +2 -2
  5. package/packages/core/package.json +1 -1
  6. package/packages/core/sdk/core.ts +3 -1
  7. package/packages/core/sdk/events.d.ts +7 -0
  8. package/packages/core/sdk/events.ts +26 -5
  9. package/packages/core/sdk/text.d.ts +4 -0
  10. package/packages/core/sdk/text.ts +51 -0
  11. package/packages/core/src/checker.ts +58 -1
  12. package/packages/core/src/contract.ts +5 -4
  13. package/packages/core/src/devhost_journal.mjs +2 -2
  14. package/packages/core/src/diagnostics.ts +2 -2
  15. package/packages/core/src/service_contract.ts +10 -0
  16. package/packages/core/src/typed_ast.ts +9 -7
  17. package/packages/core/src/types.ts +28 -8
  18. package/skill-data/automation/SKILL.md +4 -3
  19. package/skill-data/native-ui/SKILL.md +10 -8
  20. package/skill-data/ts-core/SKILL.md +8 -5
  21. package/src/app_runner/root.zig +301 -12
  22. package/src/app_runner/ts_core_main.zig +6 -4
  23. package/src/app_runner/window_placement.zig +63 -0
  24. package/src/automation/protocol.zig +5 -1
  25. package/src/automation/snapshot.zig +119 -0
  26. package/src/embed/app_exports.zig +2 -1
  27. package/src/embed/conversions.zig +1 -0
  28. package/src/embed/host.zig +10 -3
  29. package/src/embed/root.zig +1 -0
  30. package/src/embed/tests.zig +13 -1
  31. package/src/embed/types.zig +2 -0
  32. package/src/embed/ui_host.zig +26 -2
  33. package/src/platform/android/NativeSdkActivity.java +49 -4
  34. package/src/platform/android/android_host.c +3 -3
  35. package/src/platform/android/native_sdk_app.h +1 -1
  36. package/src/platform/ios/apple_image_fit.h +38 -0
  37. package/src/platform/ios/files.zig +1 -0
  38. package/src/platform/ios/native_sdk_app.h +1 -1
  39. package/src/platform/ios/uikit_host.m +28 -5
  40. package/src/platform/linux/cef_host.cpp +10 -2
  41. package/src/platform/linux/gtk_host.c +43 -10
  42. package/src/platform/linux/gtk_host.h +3 -3
  43. package/src/platform/linux/root.zig +22 -7
  44. package/src/platform/macos/appkit_host.h +7 -4
  45. package/src/platform/macos/appkit_host.m +271 -52
  46. package/src/platform/macos/cef_host.mm +132 -34
  47. package/src/platform/macos/image_fit_test.m +44 -0
  48. package/src/platform/macos/root.zig +222 -14
  49. package/src/platform/null_platform.zig +17 -3
  50. package/src/platform/null_platform_tests.zig +58 -4
  51. package/src/platform/root.zig +2 -0
  52. package/src/platform/types.zig +69 -19
  53. package/src/platform/windows/root.zig +22 -7
  54. package/src/platform/windows/webview2_host.cpp +31 -6
  55. package/src/primitives/app_manifest/root.zig +3 -0
  56. package/src/primitives/app_manifest/tests.zig +24 -0
  57. package/src/primitives/app_manifest/types.zig +13 -0
  58. package/src/primitives/app_manifest/validation.zig +24 -0
  59. package/src/primitives/canvas/a11y_audit.zig +9 -7
  60. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  61. package/src/primitives/canvas/events.zig +129 -1
  62. package/src/primitives/canvas/layout_audit.zig +6 -6
  63. package/src/primitives/canvas/markdown.zig +4 -0
  64. package/src/primitives/canvas/markdown_tests.zig +1 -0
  65. package/src/primitives/canvas/png.zig +138 -0
  66. package/src/primitives/canvas/root.zig +14 -2
  67. package/src/primitives/canvas/text_interaction.zig +23 -0
  68. package/src/primitives/canvas/text_span_tests.zig +5 -3
  69. package/src/primitives/canvas/text_spans.zig +2 -0
  70. package/src/primitives/canvas/text_tests.zig +65 -0
  71. package/src/primitives/canvas/ui.zig +66 -10
  72. package/src/primitives/canvas/ui_markup.zig +40 -13
  73. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  74. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  75. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  76. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  77. package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
  78. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  79. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  80. package/src/primitives/canvas/ui_markup_view_tests.zig +67 -6
  81. package/src/primitives/canvas/ui_schema.zig +17 -13
  82. package/src/primitives/canvas/ui_tests.zig +84 -0
  83. package/src/primitives/canvas/widget_access.zig +3 -3
  84. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  85. package/src/primitives/canvas/widget_builtin_tests.zig +593 -32
  86. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  87. package/src/primitives/canvas/widget_layout.zig +333 -126
  88. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  89. package/src/primitives/canvas/widget_metrics.zig +7 -8
  90. package/src/primitives/canvas/widget_render.zig +76 -44
  91. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  92. package/src/primitives/canvas/widget_render_style.zig +58 -18
  93. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  94. package/src/primitives/canvas/widget_routing.zig +40 -34
  95. package/src/primitives/canvas/widget_runtime.zig +11 -2
  96. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  97. package/src/primitives/canvas/widget_semantics.zig +8 -3
  98. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  99. package/src/primitives/canvas/widget_tree.zig +99 -5
  100. package/src/primitives/canvas/widgets.zig +20 -7
  101. package/src/root.zig +3 -0
  102. package/src/runtime/api.zig +6 -0
  103. package/src/runtime/automation_snapshot.zig +4 -0
  104. package/src/runtime/automation_widget_dispatch.zig +48 -6
  105. package/src/runtime/builtin_bridge.zig +5 -2
  106. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  107. package/src/runtime/canvas_image_tests.zig +146 -2
  108. package/src/runtime/canvas_images.zig +35 -16
  109. package/src/runtime/canvas_limits.zig +13 -3
  110. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  111. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  112. package/src/runtime/canvas_widget_control_tests.zig +33 -1
  113. package/src/runtime/canvas_widget_events.zig +151 -26
  114. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  115. package/src/runtime/canvas_widget_runtime.zig +322 -102
  116. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  117. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  118. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  119. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  120. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  121. package/src/runtime/canvas_widget_state.zig +33 -7
  122. package/src/runtime/canvas_widget_text_tests.zig +124 -0
  123. package/src/runtime/core.zig +16 -0
  124. package/src/runtime/effects.zig +14 -14
  125. package/src/runtime/effects_image_tests.zig +91 -0
  126. package/src/runtime/gpu_surface_events.zig +25 -2
  127. package/src/runtime/native_command_event_tests.zig +29 -0
  128. package/src/runtime/root.zig +2 -0
  129. package/src/runtime/session_journal.zig +21 -2
  130. package/src/runtime/session_replay.zig +13 -8
  131. package/src/runtime/session_tests.zig +111 -4
  132. package/src/runtime/shell_layout_tests.zig +12 -0
  133. package/src/runtime/ts_core_host_tests.zig +47 -0
  134. package/src/runtime/ts_ui_app.zig +164 -1
  135. package/src/runtime/ui_app.zig +100 -21
  136. package/src/runtime/ui_app_tests.zig +351 -32
  137. package/src/runtime/ui_app_window_tests.zig +13 -1
  138. package/src/runtime/view.zig +3 -0
  139. package/src/runtime/view_widget_control.zig +18 -0
  140. package/src/runtime/view_widget_scroll.zig +112 -18
  141. package/src/runtime/view_widget_text.zig +1 -1
  142. package/src/runtime/view_widget_tree.zig +110 -13
  143. package/src/runtime/widget_bridge.zig +2 -0
  144. package/src/runtime/window_command_bridge_tests.zig +86 -0
  145. package/src/runtime/window_storage.zig +16 -1
  146. package/src/runtime/window_views.zig +1 -0
  147. package/src/tooling/ios.zig +3 -0
  148. package/src/tooling/manifest.zig +90 -2
  149. package/src/tooling/package.zig +67 -2
  150. package/src/tooling/raw_manifest.zig +10 -0
  151. package/src/tooling/templates.zig +128 -18
  152. package/src/tooling/verbs.zig +1 -0
  153. package/src/tooling/web_engine.zig +1 -1
  154. package/tools/corewire/emit.zig +31 -12
  155. package/tools/corewire/emit_facade.zig +57 -2
  156. package/tools/corewire/shim_rt.zig +20 -0
@@ -1044,6 +1044,8 @@ pub fn Ui(comptime Msg: type) type {
1044
1044
  .delete_forward => @unionInit(Payload, "delete_forward", {}),
1045
1045
  .delete_word_backward => @unionInit(Payload, "delete_word_backward", {}),
1046
1046
  .delete_word_forward => @unionInit(Payload, "delete_word_forward", {}),
1047
+ .delete_to_start => @unionInit(Payload, "delete_to_start", {}),
1048
+ .delete_to_line_start => @unionInit(Payload, "delete_to_line_start", {}),
1047
1049
  .clear => @unionInit(Payload, "clear", {}),
1048
1050
  .move_caret => |move| blk: {
1049
1051
  const Move = @FieldType(Payload, "move_caret");
@@ -1409,8 +1411,22 @@ pub fn Ui(comptime Msg: type) type {
1409
1411
  /// widget resolves through the engine's semantic intent model
1410
1412
  /// (press, then toggle, then select) to the matching handler.
1411
1413
  pub fn msgForPointer(self: Tree, target_id: ObjectId, phase: canvas.WidgetPointerPhase) ?Msg {
1414
+ return self.msgForPointerSelection(target_id, phase, null);
1415
+ }
1416
+
1417
+ fn msgForPointerSelection(self: Tree, target_id: ObjectId, phase: canvas.WidgetPointerPhase, radio_selection_changed: ?bool) ?Msg {
1412
1418
  if (phase != .up) return null;
1413
1419
  const widget = self.findWidget(target_id) orelse return null;
1420
+ // A radio press is selection, regardless of which legacy
1421
+ // handlers are also bound. Resolve it through the same
1422
+ // canonical order as keyboard and a11y selection before
1423
+ // the generic press/toggle/select action walk can choose
1424
+ // an explicitly stamped on_toggle action first.
1425
+ if (widget.kind == .radio) {
1426
+ const intent = canvas.widgetSemanticControlIntent(widget, .select) orelse return null;
1427
+ _ = intent;
1428
+ return self.msgForRadioSelection(target_id, radio_selection_changed);
1429
+ }
1414
1430
  const semantic_actions = [_]canvas.WidgetSemanticAction{ .press, .toggle, .select };
1415
1431
  for (semantic_actions) |action| {
1416
1432
  const intent = canvas.widgetSemanticControlIntent(widget, action) orelse continue;
@@ -1430,7 +1446,18 @@ pub fn Ui(comptime Msg: type) type {
1430
1446
  if (phase == .up and click_count == 2) {
1431
1447
  if (self.msgFor(target_id, .double_press)) |msg| return msg;
1432
1448
  }
1433
- return self.msgForPointer(target_id, phase);
1449
+ return self.msgForPointerSelection(target_id, phase, null);
1450
+ }
1451
+
1452
+ /// Runtime pointer dispatch with the retained radio-selection
1453
+ /// outcome preserved. Direct tests and consumers can keep using
1454
+ /// `msgForPointerClick`; the runtime uses this form so reselecting
1455
+ /// an already-checked radio does not synthesize `on_change`.
1456
+ pub fn msgForPointerEvent(self: Tree, target_id: ObjectId, pointer: canvas.WidgetPointerEvent) ?Msg {
1457
+ if (pointer.phase == .up and pointer.click_count == 2) {
1458
+ if (self.msgFor(target_id, .double_press)) |msg| return msg;
1459
+ }
1460
+ return self.msgForPointerSelection(target_id, pointer.phase, pointer.radio_selection_changed);
1434
1461
  }
1435
1462
 
1436
1463
  /// Typed dispatch for keyboard events: engine control intents
@@ -1446,16 +1473,21 @@ pub fn Ui(comptime Msg: type) type {
1446
1473
  if (widget.semantics.role == .treeitem and keyboard.focus_moved) {
1447
1474
  if (self.msgFor(target_id, .change)) |msg| return msg;
1448
1475
  }
1449
- // A list row prefers a bound submit handler on plain
1450
- // Enter: Enter is the row's PRIMARY action (open the
1451
- // record, play the track — the desktop list convention),
1452
- // while Space keeps the select activation below. Only
1453
- // rows that bind `on_submit` take this branch; everything
1454
- // else resolves exactly as before.
1455
- if (widget.kind == .list_item and isSubmitKeyboard(widget, keyboard)) {
1476
+ // List rows and comboboxes prefer a bound submit handler
1477
+ // on plain Enter before their activation intent: Enter is
1478
+ // the row's PRIMARY action or commits the combobox text,
1479
+ // while Space and the combobox open arrows keep the
1480
+ // activation below. Only widgets that bind `on_submit`
1481
+ // return from this branch; everything else resolves
1482
+ // exactly as before.
1483
+ if ((widget.kind == .list_item or widget.kind == .combobox) and isSubmitKeyboard(widget, keyboard)) {
1456
1484
  if (self.msgFor(target_id, .submit)) |msg| return msg;
1457
1485
  }
1458
1486
  if (canvas.widgetKeyboardControlIntent(widget, keyboard)) |intent| {
1487
+ if (widget.kind == .radio and intent.kind == .select) {
1488
+ if (self.msgForRadioSelection(target_id, keyboard.radio_selection_changed)) |msg| return msg;
1489
+ return null;
1490
+ }
1459
1491
  if (self.msgForIntent(target_id, intent)) |msg| return msg;
1460
1492
  }
1461
1493
  if (isSubmitKeyboard(widget, keyboard)) {
@@ -1481,7 +1513,7 @@ pub fn Ui(comptime Msg: type) type {
1481
1513
  } else {
1482
1514
  const locally_derived = canvas.widgetCodeTabTextEditEvent(widget, keyboard) orelse
1483
1515
  canvas.widgetKeyboardNewlineTextEditEvent(widget, keyboard) orelse
1484
- keyboard.textEditEvent();
1516
+ canvas.widgetKeyboardTextEditEventForWidget(widget, keyboard);
1485
1517
  if (locally_derived) |text_edit| {
1486
1518
  // Direct Tree consumers still sanitize locally:
1487
1519
  // these bytes have not crossed the runtime seam.
@@ -1498,7 +1530,18 @@ pub fn Ui(comptime Msg: type) type {
1498
1530
  return switch (intent.kind) {
1499
1531
  .press => self.msgFor(id, .press),
1500
1532
  .toggle => self.msgFor(id, .toggle),
1501
- .select => self.msgFor(id, .press),
1533
+ // Radio selection has one canonical handler order on
1534
+ // every input path: on_change, then the historical
1535
+ // on_toggle markup convention, then on_press for
1536
+ // backwards compatibility. Pointer, Space/Enter, and
1537
+ // radio-group focus arrivals all resolve here.
1538
+ .select => if (self.findWidget(id)) |widget|
1539
+ if (widget.kind == .radio)
1540
+ self.msgForRadioSelection(id, null)
1541
+ else
1542
+ self.msgFor(id, .press)
1543
+ else
1544
+ null,
1502
1545
  .set_value => blk: {
1503
1546
  if (intent.value) |value| {
1504
1547
  if (self.msgForValue(id, value)) |msg| break :blk msg;
@@ -1508,6 +1551,19 @@ pub fn Ui(comptime Msg: type) type {
1508
1551
  .scroll_by, .scroll_to_start, .scroll_to_end => null,
1509
1552
  };
1510
1553
  }
1554
+
1555
+ fn msgForRadioSelection(self: Tree, id: ObjectId, stamped_changed: ?bool) ?Msg {
1556
+ const widget = self.findWidget(id) orelse return null;
1557
+ if (widget.kind != .radio) return null;
1558
+ // Runtime input carries the exact retained mutation. A
1559
+ // direct Tree consumer has no retained mirror, so derive
1560
+ // the same ordinary case from the source snapshot.
1561
+ const changed = stamped_changed orelse !(widget.state.selected or widget.value >= 0.5);
1562
+ if (changed) {
1563
+ if (self.msgFor(id, .change)) |msg| return msg;
1564
+ }
1565
+ return self.msgFor(id, .toggle) orelse self.msgFor(id, .press);
1566
+ }
1511
1567
  };
1512
1568
 
1513
1569
  pub fn init(arena: std.mem.Allocator) Self {
@@ -1149,11 +1149,11 @@ pub const anchor_offset_value_message = "anchor-offset takes a literal number: t
1149
1149
  pub const anchor_dependent_attr_message = "anchor-alignment and anchor-offset only apply together with anchor - add anchor=\"below\" (or \"above\") to float this surface";
1150
1150
 
1151
1151
  /// Elements whose widget KIND the engine never hit-tests: layout and
1152
- /// decoration only. A bound `on-press`/`on-double-press`/`on-toggle`
1153
- /// makes any element a hit target (widget-level: the handler stamps the
1154
- /// press/toggle action, and presses on non-interactive content inside it
1155
- /// fall through to it), so those three are legal everywhere; the
1156
- /// remaining value/text handlers
1152
+ /// decoration only. A bound `on-press`/`on-double-press`/`on-toggle`/
1153
+ /// `on-hold`/`on-drag` makes any element a hit target (widget-level: the
1154
+ /// handler stamps a press/toggle/drag action, and presses on
1155
+ /// non-interactive content inside it fall through to it), so those are
1156
+ /// legal everywhere; the remaining value/text handlers
1157
1157
  /// (`on-change`/`on-submit`/`on-input`) have no behavior to bind to on
1158
1158
  /// these elements and stay validation errors. Registry-derived from the
1159
1159
  /// `hit_target` element predicate, which mirrors the engine's kind
@@ -1177,7 +1177,7 @@ pub const autofocus_element_message = "autofocus is only supported on focusable
1177
1177
 
1178
1178
  pub const submit_on_enter_element_message = "submit-on-enter is only supported on textarea - it makes plain Enter dispatch on-submit while Shift+Enter inserts a newline; single-line fields already submit on Enter, and other elements have no multiline Enter policy";
1179
1179
 
1180
- pub const non_hit_target_handler_message = "on-change/on-submit/on-input never fire here: this element has no control or text behavior - put them on a control (input, checkbox, slider) inside it (on-press/on-double-press/on-toggle are fine anywhere: a bound press handler makes any element pressable, and clicks on plain text or icons inside it fall through to it)";
1180
+ pub const non_hit_target_handler_message = "on-change/on-submit/on-input never fire here: this element has no control or text behavior - put them on a control (input, checkbox, slider) inside it (on-press/on-double-press/on-toggle/on-hold/on-drag are fine anywhere: they make any element interactive, and presses on plain text or icons inside it fall through to it)";
1181
1181
 
1182
1182
  /// Elements whose widget kind layers its children on top of each other
1183
1183
  /// (every child gets the full content box), so `gap` can never space
@@ -1419,7 +1419,7 @@ pub fn dismissEventElement(name: []const u8) bool {
1419
1419
  // operated blind; a role that cannot mean what it says lies to the
1420
1420
  // bridge), and a WARNING when the experience degrades but remains
1421
1421
  // navigable (an unnamed image, a label duplicating the text it shadows).
1422
- // Which elements are controls/editables/images is registry data
1422
+ // Which elements are controls/editables/radiogroups/images is registry data
1423
1423
  // (`schema.ElementInfo.a11y_name`); the judgment about name sources and
1424
1424
  // severities lives here. Both engines and the validator call the same
1425
1425
  // predicates, so the lint cannot drift between check time and build time.
@@ -1430,6 +1430,8 @@ pub const a11y_icon_only_message = "icon-only control: the icon name is a drawin
1430
1430
 
1431
1431
  pub const a11y_unlabeled_editable_message = "this text control has no accessible name - a screen reader user cannot tell what to type; add label=\"...\" (or placeholder=\"...\", which the accessibility bridges announce as the fallback name)";
1432
1432
 
1433
+ pub const a11y_unlabeled_radiogroup_message = "this radiogroup has no accessible name - a screen reader announces the choices without their shared question; add label=\"...\" naming the shared choice";
1434
+
1433
1435
  pub const a11y_unknown_role_message = "unknown role: role takes a canvas.WidgetRole name (button, link, tree, treeitem, list, listitem, tab, checkbox, ...)";
1434
1436
 
1435
1437
  pub const a11y_container_role_message = "this role promises child structure (rows, items, cells) that this element can never hold - put the role on the container element around it, or drop it";
@@ -1445,6 +1447,13 @@ pub const a11y_redundant_label_message = "this label duplicates the element's te
1445
1447
  /// the validator and both engines; comptime-callable.
1446
1448
  pub fn a11yNameError(node: MarkupNode) ?[]const u8 {
1447
1449
  const entry = schema.elementByName(node.name) orelse return null;
1450
+ // A literal role override can create a radiogroup on any container;
1451
+ // enforce the role's name contract in addition to the element-kind
1452
+ // registry. Dynamic roles resolve at runtime, where the tree audit
1453
+ // applies the same requirement to the effective semantic role.
1454
+ if (nodeHasLiteralRole(node, "radiogroup") and !attrNonBlank(node, "label")) {
1455
+ return a11y_unlabeled_radiogroup_message;
1456
+ }
1448
1457
  switch (entry.a11y_name) {
1449
1458
  .none, .image => return null,
1450
1459
  .control => {
@@ -1462,9 +1471,22 @@ pub fn a11yNameError(node: MarkupNode) ?[]const u8 {
1462
1471
  if (entry.takes_text and a11yNodeHasName(node)) return null;
1463
1472
  return a11y_unlabeled_editable_message;
1464
1473
  },
1474
+ .radiogroup => {
1475
+ if (attrNonBlank(node, "label")) return null;
1476
+ return a11y_unlabeled_radiogroup_message;
1477
+ },
1465
1478
  }
1466
1479
  }
1467
1480
 
1481
+ fn nodeHasLiteralRole(node: MarkupNode, role: []const u8) bool {
1482
+ const value = node.attr("role") orelse return false;
1483
+ const expression = parseAttrExpression(value) orelse return false;
1484
+ return switch (expression) {
1485
+ .literal => |literal| std.mem.eql(u8, literal, role),
1486
+ else => false,
1487
+ };
1488
+ }
1489
+
1468
1490
  /// The role-misuse ERROR for an element node: an unknown literal role, or
1469
1491
  /// a container role on an element that provably cannot hold the children
1470
1492
  /// the role promises. Dynamic role values (`role="{binding}"`) resolve at
@@ -1572,12 +1594,17 @@ fn inlineSeparatorNode(source: []const u8, start: usize, end: usize) MarkupNode
1572
1594
  }
1573
1595
 
1574
1596
  /// Whether an element can HOST a context-menu: right-click resolution
1575
- /// walks the hit route, so the host must be a hit target — or carry a
1576
- /// bound on-press/on-hold, which makes any element pressable. Shared by
1577
- /// the validator and both engines; comptime-callable.
1597
+ /// walks the hit route, so the host must be a hit target — or carry any
1598
+ /// handler that stamps a press/toggle/drag action and therefore makes an
1599
+ /// otherwise structural element a hit target. Shared by the validator
1600
+ /// and both engines; comptime-callable.
1578
1601
  pub fn contextMenuHostEligible(node: MarkupNode) bool {
1579
1602
  if (!nameInList(node.name, &known_non_hit_target_element_names)) return true;
1580
- return node.attr("on-press") != null or node.attr("on-hold") != null;
1603
+ return node.attr("on-press") != null or
1604
+ node.attr("on-double-press") != null or
1605
+ node.attr("on-toggle") != null or
1606
+ node.attr("on-hold") != null or
1607
+ node.attr("on-drag") != null;
1581
1608
  }
1582
1609
 
1583
1610
  fn a11yNodeHasName(node: MarkupNode) bool {
@@ -1645,7 +1672,7 @@ fn collectNodeA11yWarnings(node: MarkupNode, storage: []MarkupErrorInfo, len: *u
1645
1672
 
1646
1673
  /// The a11y ERRORS for a document, all of them: the same findings
1647
1674
  /// `validate` fails on one at a time (unnamed controls, icon-only
1648
- /// controls, unnamed text entry, and role misuse), collected per node so
1675
+ /// controls, unnamed text entry/radiogroups, and role misuse), collected per node so
1649
1676
  /// a checker can report every offender in one pass instead of one per
1650
1677
  /// re-run. Positions match `validate`'s emission exactly: the element
1651
1678
  /// for name errors, the role attribute for role errors.
@@ -1900,7 +1927,7 @@ pub const series_color_message = "series color takes a literal color token name
1900
1927
  pub const series_label_message = "series label expects text (a literal or one {binding}) - it names the series in the chart's semantics summary";
1901
1928
  pub const series_children_message = "series is a leaf - it takes no children; the values binding carries its data";
1902
1929
  pub const context_menu_parent_message = "context-menu must be a DIRECT child of the element whose right-click it answers - a conditional menu goes inside: wrap the menu-items in if/else, not the context-menu itself";
1903
- pub const context_menu_host_message = "context-menu attaches to the element that takes the right-click, and this element is never a hit target - put the menu on the pressable element (list-item, button, panel, ...) or bind on-press on this one";
1930
+ pub const context_menu_host_message = "context-menu attaches to the element that takes the right-click, and this element is never a hit target - put the menu on an interactive element (list-item, button, panel, ...) or bind on-press/on-double-press/on-toggle/on-hold/on-drag on this one";
1904
1931
  pub const context_menu_single_message = "an element takes at most one context-menu - one right-click, one menu; swap its items with if/else INSIDE the menu";
1905
1932
  pub const context_menu_attrs_message = "context-menu takes no attributes - presentation belongs to the platform (the OS menu where the host has one, the anchored fallback surface elsewhere)";
1906
1933
  pub const context_menu_children_message = "context-menu takes menu-item and separator children (if/else/for around them are fine) - the items present through the platform's menu, so other elements cannot render there";
@@ -391,17 +391,19 @@ const Decoder = struct {
391
391
  }
392
392
  };
393
393
 
394
- /// Decode an NSUI document. Refuses unknown versions and codes loudly
395
- /// (never a silent skip) and hostile depth/length input safely. The
396
- /// result is CANONICALIZED (typed values stamped), ready for either
397
- /// engine or further tooling; line/column positions are derived from the
398
- /// carried spans when present.
394
+ /// Decode an NSUI document. Schema v1 migrates structurally to v2: the
395
+ /// wire layout is unchanged, and every v1-valid checkbox/radio remains
396
+ /// valid after those elements gain optional text content. Other unknown
397
+ /// versions and codes refuse loudly (never a silent skip), and hostile
398
+ /// depth/length input stays bounded. The result is CANONICALIZED (typed
399
+ /// values stamped), ready for either engine or further tooling;
400
+ /// line/column positions are derived from the carried spans when present.
399
401
  pub fn decode(arena: std.mem.Allocator, bytes: []const u8, diagnostic: *CodecDiagnostic) DecodeError!markup.MarkupDocument {
400
402
  var decoder = Decoder{ .arena = arena, .bytes = bytes, .diagnostic = diagnostic };
401
403
  const header = try decoder.take(magic.len);
402
404
  if (!std.mem.eql(u8, header, magic)) return decoder.fail(bad_magic_message);
403
405
  const version = try decoder.int(u16);
404
- if (version != schema.schema_version) return decoder.fail(bad_version_message);
406
+ if (version != 1 and version != schema.schema_version) return decoder.fail(bad_version_message);
405
407
  const flags = try decoder.int(u16);
406
408
  decoder.spans = flags & flag_spans != 0;
407
409
  decoder.provenance = flags & flag_provenance != 0;
@@ -225,7 +225,7 @@ test "NSUI golden bytes for a minimal document" {
225
225
  const bytes = try nsui.encode(arena, document, .{ .spans = false, .provenance = false }, &diagnostic);
226
226
  const expected = [_]u8{
227
227
  'N', 'S', 'U', 'I', // magic
228
- 1, 0, // schema_version = 1
228
+ 2, 0, // schema_version = 2
229
229
  0, 0, // flags: no spans, no provenance
230
230
  0, 0, // template count = 0
231
231
  1, // root present
@@ -319,6 +319,16 @@ test "NSUI refuses what it does not know, loudly" {
319
319
  var diagnostic = nsui.CodecDiagnostic{};
320
320
  const bytes = try nsui.encode(arena, document, .{}, &diagnostic);
321
321
 
322
+ // V1 migrates structurally to v2. Its wire layout is unchanged, and
323
+ // every document valid under the old checkbox/radio content rules is
324
+ // also valid under the new optional-text rules.
325
+ {
326
+ const migrated = try arena.dupe(u8, bytes);
327
+ std.mem.writeInt(u16, migrated[4..6], 1, .little);
328
+ const decoded = try nsui.decode(arena, migrated, &diagnostic);
329
+ try testing.expectEqualStrings("row", decoded.root.?.name);
330
+ }
331
+
322
332
  // Unknown schema version.
323
333
  {
324
334
  const mutated = try arena.dupe(u8, bytes);
@@ -375,7 +385,7 @@ test "NSUI JSON dump derives from the decoded document" {
375
385
  defer out.deinit();
376
386
  try nsui.writeJson(decoded, hash, &out.writer);
377
387
  const json = out.written();
378
- try testing.expect(std.mem.indexOf(u8, json, "\"schemaVersion\":1") != null);
388
+ try testing.expect(std.mem.indexOf(u8, json, "\"schemaVersion\":2") != null);
379
389
  try testing.expect(std.mem.indexOf(u8, json, "\"node\":\"row\"") != null);
380
390
  try testing.expect(std.mem.indexOf(u8, json, "\"code\":1") != null);
381
391
  try testing.expect(std.mem.indexOf(u8, json, "\"name\":\"gap\"") != null);
@@ -402,8 +412,8 @@ test "NSUI refuses hostile nesting depth" {
402
412
  try testing.expectEqualStrings(nsui.depth_message, diagnostic.message);
403
413
  }
404
414
 
405
- test "the schema version constant is 1 and the registry backs the wire" {
406
- try testing.expectEqual(@as(u16, 1), schema.schema_version);
415
+ test "the schema version constant is 2 and the registry backs the wire" {
416
+ try testing.expectEqual(@as(u16, 2), schema.schema_version);
407
417
  // Every registry element/attr the encoder can meet has a nonzero code
408
418
  // (0 is the wire's "no entry" marker).
409
419
  for (schema.elements) |entry| try testing.expect(entry.code != 0);
@@ -514,7 +514,11 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
514
514
  }
515
515
  if (comptime (interpreter.elementTakesText(kind) and !composite_children)) {
516
516
  var built = ui.el(kind, options, .{});
517
- built.widget.text = interpolatedText(inner, entries, ui, model, scope);
517
+ // Interpreter parity: content wins when present; an empty
518
+ // element keeps its already-resolved text= attribute.
519
+ if (comptime inner.children.len > 0) {
520
+ built.widget.text = interpolatedText(inner, entries, ui, model, scope);
521
+ }
518
522
  // Avatars clip their runtime image to the avatar circle,
519
523
  // exactly like `Ui.avatar` and the interpreter (a no-op
520
524
  // while the id is 0 and the initials fallback renders).
@@ -99,6 +99,38 @@ const zero_card_padding_markup =
99
99
  ;
100
100
  const ZeroCardPaddingCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, zero_card_padding_markup);
101
101
 
102
+ const selection_label_content_markup =
103
+ \\<column gap="8">
104
+ \\ <checkbox checked="true" on-toggle="add">Done</checkbox>
105
+ \\ <checkbox on-toggle="add" text="Later" />
106
+ \\ <radio-group label="Density">
107
+ \\ <radio checked="true" on-change="add">Default</radio>
108
+ \\ <radio on-change="add" text="Compact" />
109
+ \\ </radio-group>
110
+ \\</column>
111
+ ;
112
+ const SelectionLabelContentCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, selection_label_content_markup);
113
+
114
+ test "checkbox and radio element content builds identically in both markup engines" {
115
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
116
+ defer arena_state.deinit();
117
+ const arena = arena_state.allocator();
118
+ const model = fixture.testModel();
119
+
120
+ var interpreter = try InboxInterpreter.init(arena, selection_label_content_markup);
121
+ var interpreter_ui = InboxUi.init(arena);
122
+ const interpreted = try interpreter_ui.finalize(try interpreter.build(&interpreter_ui, &model));
123
+ var compiled_ui = InboxUi.init(arena);
124
+ const compiled = try compiled_ui.finalize(SelectionLabelContentCompiled.build(&compiled_ui, &model));
125
+
126
+ try expectSameTree(fixture.Msg, interpreted, compiled);
127
+ try expectSameTexts(interpreted.root, compiled.root);
128
+ try testing.expect(fixture.findByText(compiled.root, .checkbox, "Done") != null);
129
+ try testing.expect(fixture.findByText(compiled.root, .checkbox, "Later") != null);
130
+ try testing.expect(fixture.findByText(compiled.root, .radio, "Default") != null);
131
+ try testing.expect(fixture.findByText(compiled.root, .radio, "Compact") != null);
132
+ }
133
+
102
134
  test "explicit zero card padding survives interpreted and compiled markup" {
103
135
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
104
136
  defer arena_state.deinit();
@@ -130,6 +162,26 @@ fn compileInbox(arena: std.mem.Allocator, model: *const fixture.Model) !InboxUi.
130
162
  }
131
163
 
132
164
  const ContextMenuCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, fixture.context_menu_markup_source);
165
+ const DragContextMenuCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, fixture.drag_context_menu_markup_source);
166
+
167
+ test "compiled drag-only context-menu host matches the interpreter" {
168
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
169
+ defer arena_state.deinit();
170
+ const arena = arena_state.allocator();
171
+ const model = fixture.testModel();
172
+
173
+ var interpreter_view = try InboxInterpreter.init(arena, fixture.drag_context_menu_markup_source);
174
+ var interpreter_ui = InboxUi.init(arena);
175
+ const interpreted = try interpreter_ui.finalize(try interpreter_view.build(&interpreter_ui, &model));
176
+ var compiled_ui = InboxUi.init(arena);
177
+ const compiled = try compiled_ui.finalize(DragContextMenuCompiled.build(&compiled_ui, &model));
178
+
179
+ try expectSameTree(fixture.Msg, interpreted, compiled);
180
+ try expectSameTexts(interpreted.root, compiled.root);
181
+ try testing.expect(compiled.root.semantics.actions.drag);
182
+ try testing.expect(canvas.widgetClaimsPress(compiled.root));
183
+ try testing.expectEqual(fixture.Msg.add, compiled.msgForContextMenu(compiled.root.id, 0).?);
184
+ }
133
185
 
134
186
  test "compiled context-menus build the interpreter's declared items and handler entries exactly" {
135
187
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
@@ -941,6 +993,9 @@ test "compiled catalog elements match the interpreter and the hand-written view"
941
993
  interpreted.msgForKeyboard(input.id, submit).?,
942
994
  compiled.msgForKeyboard(input.id, submit).?,
943
995
  );
996
+ const combobox = fixture.findByKind(compiled.root, .combobox).?;
997
+ try testing.expectEqual(fixture.CatalogMsg.submit_query, compiled.msgForKeyboard(combobox.id, submit).?);
998
+ try testing.expectEqual(fixture.CatalogMsg.open_picker, compiled.msgForKeyboard(combobox.id, .{ .phase = .key_down, .key = "space" }).?);
944
999
  }
945
1000
 
946
1001
  test "compiled catalog stays in parity when conditional surfaces flip" {
@@ -106,9 +106,10 @@ pub fn isZeroArgFn(comptime T: type, comptime DeclType: type) bool {
106
106
  /// declared-shape predicate below stays std-only. A drift test in
107
107
  /// `ui_markup_contract_tests.zig` holds this list equal to the real union.
108
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",
109
+ "insert_text", "delete_backward", "delete_forward", "delete_word_backward",
110
+ "delete_word_forward", "delete_to_start", "delete_to_line_start", "clear",
111
+ "move_caret", "set_selection", "set_composition", "commit_composition",
112
+ "cancel_composition",
112
113
  };
113
114
 
114
115
  /// The caret-direction member vocabulary (`canvas.TextCaretDirection`).
@@ -125,8 +126,8 @@ pub const text_caret_affinity_members = [_][]const u8{
125
126
  /// where the emitted module declares its own mirror union (type identity
126
127
  /// cannot cross the emission boundary). Matched structurally, by the same
127
128
  /// contract everywhere markup resolves `on-input`:
128
- /// - a tagged union carrying exactly the eleven canvas event tags;
129
- /// - `insert_text` a bytes payload; the seven verb arms void;
129
+ /// - a tagged union carrying exactly the thirteen canvas event tags;
130
+ /// - `insert_text` a bytes payload; the nine verb arms void;
130
131
  /// - `move_caret` a record of `direction` (an enum with exactly the six
131
132
  /// caret-direction member names) and `extend: bool`;
132
133
  /// - `set_selection` a record of numeric `anchor`/`focus`, optionally
@@ -474,7 +474,7 @@ test "a dead handler on a non-hit-target element reports the attribute position"
474
474
  try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try fixed_parser.parse()));
475
475
  }
476
476
 
477
- test "the a11y lint: unnamed controls, icon-only controls, and unnamed text entry are errors" {
477
+ test "the a11y lint: unnamed controls, radiogroups, and text entry are errors" {
478
478
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
479
479
  defer arena_state.deinit();
480
480
  const arena = arena_state.allocator();
@@ -490,6 +490,11 @@ test "the a11y lint: unnamed controls, icon-only controls, and unnamed text entr
490
490
  // not a name (hearing the content does not say what to type).
491
491
  .{ .source = "<row>\n <text-field on-input=\"draft\" />\n</row>", .message = markup.a11y_unlabeled_editable_message },
492
492
  .{ .source = "<row>\n <input text=\"{query}\" on-input=\"draft\" />\n</row>", .message = markup.a11y_unlabeled_editable_message },
493
+ // A radio group's individually named choices do not name their
494
+ // shared question. The built-in element and a literal role
495
+ // override both require their own label.
496
+ .{ .source = "<radio-group>\n <radio label=\"Default\" />\n</radio-group>", .message = markup.a11y_unlabeled_radiogroup_message },
497
+ .{ .source = "<row role=\"radiogroup\">\n <radio label=\"Default\" />\n</row>", .message = markup.a11y_unlabeled_radiogroup_message },
493
498
  // A blank label is not a name on a control (unlike an image,
494
499
  // where the empty label is the decorative opt-out).
495
500
  .{ .source = "<row>\n <checkbox label=\" \" on-toggle=\"select\" />\n</row>", .message = markup.a11y_unlabeled_control_message },
@@ -505,6 +510,7 @@ test "the a11y lint: unnamed controls, icon-only controls, and unnamed text entr
505
510
  // select's face content.
506
511
  const clean = [_][]const u8{
507
512
  "<row>\n <checkbox on-toggle=\"select\">Done</checkbox>\n</row>",
513
+ "<radio-group label=\"Density\">\n <radio checked=\"true\">Default</radio>\n</radio-group>",
508
514
  "<row>\n <checkbox text=\"Done\" on-toggle=\"select\" />\n</row>",
509
515
  "<row>\n <checkbox label=\"Done\" on-toggle=\"select\" />\n</row>",
510
516
  "<row>\n <button icon=\"trash\" label=\"Delete\" on-press=\"remove\"></button>\n</row>",
@@ -514,6 +520,8 @@ test "the a11y lint: unnamed controls, icon-only controls, and unnamed text entr
514
520
  "<row>\n <textarea label=\"Body\" on-input=\"draft\" />\n</row>",
515
521
  "<row>\n <select on-press=\"open\">Newest first</select>\n</row>",
516
522
  "<row>\n <select text=\"{choice}\" on-press=\"open\"/>\n</row>",
523
+ "<radio-group label=\"Density\">\n <radio label=\"Default\" />\n</radio-group>",
524
+ "<row role=\"radiogroup\" label=\"{question}\">\n <radio label=\"Default\" />\n</row>",
517
525
  };
518
526
  for (clean) |source| {
519
527
  var parser = markup.Parser.init(arena, source);
@@ -632,7 +640,7 @@ test "collectA11yErrors reports every a11y error in one pass with validate's pos
632
640
  try testing.expectEqual(@as(usize, 0), markup.collectA11yErrors(try clean_parser.parse(), &storage).len);
633
641
  }
634
642
 
635
- test "press and toggle handlers are legal on layout elements (press fall-through makes them pressable)" {
643
+ test "press toggle and drag handlers are legal on layout elements (press fall-through makes them interactive)" {
636
644
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
637
645
  defer arena_state.deinit();
638
646
 
@@ -644,6 +652,7 @@ test "press and toggle handlers are legal on layout elements (press fall-through
644
652
  "<column>\n <row on-press=\"select\" gap=\"8\">\n <text>press me</text>\n </row>\n</column>",
645
653
  "<column on-press=\"add\">\n <text>x</text>\n</column>",
646
654
  "<column>\n <stack on-toggle=\"flip\">\n <text>x</text>\n </stack>\n</column>",
655
+ "<column>\n <row on-drag=\"drag:{open_count}\" label=\"Draggable\">\n <text>x</text>\n </row>\n</column>",
647
656
  "<row>\n <icon name=\"search\" on-press=\"go\" />\n</row>",
648
657
  "<row>\n <badge on-press=\"open\">3</badge>\n</row>",
649
658
  };
@@ -512,9 +512,15 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
512
512
  }
513
513
  }
514
514
  if (elementTakesText(kind) and !composite_children) {
515
- const text = try self.interpolatedText(ui, scope, inner);
516
515
  var built = ui.el(kind, options, .{});
517
- built.widget.text = text;
516
+ // Element content wins when present; an empty element
517
+ // keeps the already-resolved text= attribute in options.
518
+ // Checkbox/radio joined this path when they became text
519
+ // leaves, so replacing unconditionally would regress the
520
+ // binding-friendly attribute that already worked.
521
+ if (inner.children.len > 0) {
522
+ built.widget.text = try self.interpolatedText(ui, scope, inner);
523
+ }
518
524
  // Avatars clip their runtime image to the avatar circle,
519
525
  // exactly like `Ui.avatar` (a no-op while the id is 0 and
520
526
  // the initials fallback renders).