@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
@@ -1171,7 +1171,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1171
1171
 
1172
1172
  /// Resolve a series `values` binding to an f32 slice through the
1173
1173
  /// same sources `for each` accepts (scope slice args shadow model
1174
- /// fields, pub decls, and fns).
1174
+ /// fields, pub decls, and fns). f64 iterables resolve too, copied
1175
+ /// down into the build arena per sample: the chart pipeline is
1176
+ /// f32, but transpiled TS cores carry every number array as f64
1177
+ /// (the subset's one float class), and refusing them would leave
1178
+ /// markup charts unreachable from a TS model.
1175
1179
  fn f32Items(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const f32 {
1176
1180
  @setEvalBranchQuota(scan_quota);
1177
1181
  inline for (item_types, 0..) |Item, type_index| {
@@ -1180,6 +1184,15 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1180
1184
  return items;
1181
1185
  }
1182
1186
  }
1187
+ if (comptime (Item == f64)) {
1188
+ if (try self.iterateItems(ui, f64, type_index, scope, path)) |items| {
1189
+ const narrowed = ui.arena.alloc(f32, items.len) catch {
1190
+ return self.failText(node, markup.series_values_message);
1191
+ };
1192
+ for (narrowed, items) |*slot, value| slot.* = @floatCast(value);
1193
+ return narrowed;
1194
+ }
1195
+ }
1183
1196
  }
1184
1197
  return self.failText(node, markup.series_values_message);
1185
1198
  }
@@ -1505,6 +1518,10 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1505
1518
  try self.applyAnchorOffsetAttr(node, options, attribute.value);
1506
1519
  continue;
1507
1520
  }
1521
+ if (std.mem.eql(u8, attribute.name, "quiet-hover")) {
1522
+ try self.applyQuietHoverAttr(scope, node, options, attribute);
1523
+ continue;
1524
+ }
1508
1525
  if (try self.applyStyleTokenAttr(node, options, attribute)) continue;
1509
1526
  if (!try self.applyOptionAttr(scope, node, options, attribute)) {
1510
1527
  return self.failVoid(node, "unknown attribute for this element");
@@ -1612,6 +1629,20 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1612
1629
  };
1613
1630
  }
1614
1631
 
1632
+ /// `quiet-hover="true"` on a hit-target element: the quiet-surface
1633
+ /// knob (`WidgetStyle.quiet_hover`) for image-forward content
1634
+ /// tiles — silences ONLY the hover wash; press/selection fills,
1635
+ /// the focus ring, cursor intent, and hit testing keep their own
1636
+ /// channels. Applied to `options.style`, so no flat option field
1637
+ /// backs it (mirrors the validator and the compiled engine).
1638
+ fn applyQuietHoverAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
1639
+ if (!markup.hitTargetElement(node.name)) {
1640
+ return self.failVoid(node, markup.quiet_hover_element_message);
1641
+ }
1642
+ const value = try self.evalAttrExpression(scope, node, attribute);
1643
+ options.style.quiet_hover = value.truthy();
1644
+ }
1645
+
1615
1646
  fn applyOptionAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!bool {
1616
1647
  inline for (attr_names) |name| {
1617
1648
  if (std.mem.eql(u8, attribute.name, name.markup)) {
@@ -1699,6 +1730,19 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1699
1730
  };
1700
1731
  return;
1701
1732
  }
1733
+ // The value-payload change event: a slider's `on-change` with a
1734
+ // bare tag naming a value-carrying arm dispatches the APPLIED
1735
+ // value through the `on_value` constructor (the `on-resize`
1736
+ // fraction mechanism) instead of a static Msg. Void arms keep
1737
+ // the static form below, so `on-change="volume_changed"` on a
1738
+ // slider still means "something changed" when the arm carries
1739
+ // nothing.
1740
+ if (std.mem.eql(u8, event, "change") and std.mem.eql(u8, node.name, "slider") and expression.payload.len == 0) {
1741
+ if (valueConstructor(expression.tag)) |make| {
1742
+ options.on_value = make;
1743
+ return;
1744
+ }
1745
+ }
1702
1746
  const msg = try self.constructMessage(scope, node, expression);
1703
1747
  if (std.mem.eql(u8, event, "press")) {
1704
1748
  options.on_press = msg;
@@ -1787,6 +1831,12 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1787
1831
  if (std.mem.eql(u8, field.name, tag)) {
1788
1832
  return Ui.inputMsg(@field(std.meta.Tag(MsgT), field.name));
1789
1833
  }
1834
+ } else if (comptime reflect.declaredTextInputUnion(field.type)) {
1835
+ // A declared mirror of the event union (transpiled
1836
+ // cores): translated at dispatch, same handler shape.
1837
+ if (std.mem.eql(u8, field.name, tag)) {
1838
+ return Ui.translatedInputMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
1839
+ }
1790
1840
  }
1791
1841
  }
1792
1842
  return null;
@@ -1799,6 +1849,13 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1799
1849
  if (std.mem.eql(u8, field.name, tag)) {
1800
1850
  return Ui.scrollMsg(@field(std.meta.Tag(MsgT), field.name));
1801
1851
  }
1852
+ } else if (comptime reflect.declaredScrollStateRecord(field.type)) {
1853
+ // A declared mirror of the scroll-state record
1854
+ // (transpiled cores): translated at dispatch, same
1855
+ // handler shape.
1856
+ if (std.mem.eql(u8, field.name, tag)) {
1857
+ return Ui.translatedScrollMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
1858
+ }
1802
1859
  }
1803
1860
  }
1804
1861
  return null;
@@ -1811,6 +1868,34 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1811
1868
  if (std.mem.eql(u8, field.name, tag)) {
1812
1869
  return Ui.valueMsg(@field(std.meta.Tag(MsgT), field.name));
1813
1870
  }
1871
+ } else if (field.type == f64) {
1872
+ // A declared one-number float arm (transpiled cores,
1873
+ // where f32 cannot be spelled): the fraction widens
1874
+ // exactly at dispatch. Integer arms stay excluded —
1875
+ // a 0..1 fraction rounded into an integer would be
1876
+ // silently useless data.
1877
+ if (std.mem.eql(u8, field.name, tag)) {
1878
+ return Ui.translatedValueMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
1879
+ }
1880
+ }
1881
+ }
1882
+ return null;
1883
+ }
1884
+
1885
+ /// The slider `on-change` value form: an arm carrying the applied
1886
+ /// 0..1 fraction as `f32` (the canvas-native shape) or the
1887
+ /// transpiled one-number float arm (`f64`, widened exactly).
1888
+ fn valueConstructor(tag: []const u8) ?Ui.ValueMsgFn {
1889
+ @setEvalBranchQuota(scan_quota);
1890
+ inline for (@typeInfo(MsgT).@"union".fields) |field| {
1891
+ const class = comptime reflect.valueArmClass(field.type);
1892
+ if (comptime class != null) {
1893
+ if (std.mem.eql(u8, field.name, tag)) {
1894
+ return switch (comptime class.?) {
1895
+ .identity => Ui.valueMsg(@field(std.meta.Tag(MsgT), field.name)),
1896
+ .float => Ui.translatedValueMsg(@field(std.meta.Tag(MsgT), field.name), field.type),
1897
+ };
1898
+ }
1814
1899
  }
1815
1900
  }
1816
1901
  return null;
@@ -2120,6 +2205,10 @@ pub const color_style_attr_fields: []const AttrName = &markup.schema.color_style
2120
2205
  /// definition of what markup can bind, three consumers).
2121
2206
  const reflect = @import("ui_markup_reflect.zig");
2122
2207
  pub const typeScanQuota = reflect.typeScanQuota;
2208
+ pub const Pointee = reflect.Pointee;
2209
+ pub const declaredTextInputUnion = reflect.declaredTextInputUnion;
2210
+ pub const declaredScrollStateRecord = reflect.declaredScrollStateRecord;
2211
+ pub const valueArmClass = reflect.valueArmClass;
2123
2212
  pub const sliceElement = reflect.sliceElement;
2124
2213
  pub const isItemFn = reflect.isItemFn;
2125
2214
  pub const isArenaScalarFn = reflect.isArenaScalarFn;
@@ -2209,6 +2298,15 @@ fn resolveOn(comptime T: type, value: *const T, path: []const u8, arena: ?std.me
2209
2298
  }
2210
2299
  return null;
2211
2300
  },
2301
+ // Single-item const pointers are transparent (`reflect.Pointee`):
2302
+ // a `*const Row` loop item or shared model node binds like the
2303
+ // struct it points at.
2304
+ .pointer => |info| {
2305
+ if (info.size == .one and info.is_const) {
2306
+ return resolveOn(info.child, value.*, path, arena);
2307
+ }
2308
+ return null;
2309
+ },
2212
2310
  else => return null,
2213
2311
  }
2214
2312
  }
@@ -2231,6 +2329,12 @@ pub fn fieldIsTextBuffer(comptime T: type, head: []const u8) bool {
2231
2329
  fn resolveNested(comptime T: type, ptr: anytype, path: []const u8, arena: ?std.mem.Allocator) ?Value {
2232
2330
  return switch (@typeInfo(T)) {
2233
2331
  .@"struct" => resolveOn(T, ptr, path, arena),
2332
+ // The `reflect.Pointee` transparency: traverse through a
2333
+ // single-item const pointer field into the struct it shares.
2334
+ .pointer => |info| if (info.size == .one and info.is_const)
2335
+ resolveNested(info.child, ptr.*, path, arena)
2336
+ else
2337
+ null,
2234
2338
  else => null,
2235
2339
  };
2236
2340
  }
@@ -3036,6 +3036,64 @@ test "the chart element builds the hand-written Ui.chart tree with series bindin
3036
3036
  try testing.expectEqual(@as(?f32, 2), latency_chart.style.stroke_width);
3037
3037
  }
3038
3038
 
3039
+ // ------------------------------------------------------ f64 chart fixture
3040
+
3041
+ /// A model shaped the way TRANSPILED TS cores emit theirs: every number
3042
+ /// array is `[]const f64` (the subset's one float class). Series bindings
3043
+ /// must narrow these into arena f32 copies — without that rule markup
3044
+ /// charts would be unreachable from a TS model.
3045
+ pub const ChartF64Model = struct {
3046
+ samples: []const f64 = &.{ 0.25, std.math.nan(f64), 0.5, 1 },
3047
+
3048
+ /// Arena-computed f64 series: the emitted shape of an exported TS
3049
+ /// model helper returning `readonly number[]`.
3050
+ pub fn halved(model: *const ChartF64Model, arena: std.mem.Allocator) []const f64 {
3051
+ const out = arena.alloc(f64, model.samples.len) catch return &.{};
3052
+ for (model.samples, out) |sample, *slot| slot.* = sample / 2;
3053
+ return out;
3054
+ }
3055
+ };
3056
+
3057
+ pub const chart_f64_markup_source =
3058
+ \\<column>
3059
+ \\ <chart width="120" height="32" y-min="0" y-max="1" label="F64 history">
3060
+ \\ <series kind="bar" values="{samples}" />
3061
+ \\ <series kind="area" values="{halved}" />
3062
+ \\ </chart>
3063
+ \\</column>
3064
+ ;
3065
+
3066
+ test "chart series bind f64 iterables (the transpiled-core float class) by narrowing into the arena" {
3067
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
3068
+ defer arena_state.deinit();
3069
+ const arena = arena_state.allocator();
3070
+
3071
+ const model = ChartF64Model{};
3072
+ const ChartMarkup = markup_view.MarkupView(ChartF64Model, ChartMsg);
3073
+ var view = try ChartMarkup.init(arena, chart_f64_markup_source);
3074
+ var markup_ui = ChartUi.init(arena);
3075
+ const tree = try markup_ui.finalize(try view.build(&markup_ui, &model));
3076
+
3077
+ const chart = findByKind(tree.root, .chart).?;
3078
+ try testing.expectEqual(@as(usize, 2), chart.chart.series.len);
3079
+
3080
+ // The field-bound series: exact f32 casts of the f64 samples, NaN
3081
+ // gaps passed through as gaps.
3082
+ const bars = chart.chart.series[0];
3083
+ try testing.expectEqual(@as(usize, 4), bars.values.len);
3084
+ try testing.expectEqual(@as(f32, 0.25), bars.values[0]);
3085
+ try testing.expect(std.math.isNan(bars.values[1]));
3086
+ try testing.expectEqual(@as(f32, 1), bars.values[3]);
3087
+
3088
+ // The arena-fn-bound series narrows the same way.
3089
+ const area = chart.chart.series[1];
3090
+ try testing.expectEqual(canvas.ChartSeriesKind.line, area.kind);
3091
+ try testing.expect(area.fill);
3092
+ try testing.expectEqual(@as(f32, 0.125), area.values[0]);
3093
+ try testing.expect(std.math.isNan(area.values[1]));
3094
+ try testing.expectEqual(@as(f32, 0.5), area.values[3]);
3095
+ }
3096
+
3039
3097
  test "chart misuse fails the build with teaching messages" {
3040
3098
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
3041
3099
  defer arena_state.deinit();
@@ -3707,3 +3765,281 @@ test "reactions misuse fails the build with the pinned teaching messages" {
3707
3765
  const info = canvas.ui_markup.validate(document) orelse return error.TestUnexpectedResult;
3708
3766
  try testing.expectEqualStrings(canvas.ui_markup.font_coverage_message, info.message);
3709
3767
  }
3768
+
3769
+ // ----------------------------------------------- declared text-input unions
3770
+
3771
+ /// The transpiled-core mirror of `canvas.TextInputEvent`: the shape the
3772
+ /// @native-sdk/core emitter produces for a core-declared event union. Matched
3773
+ /// structurally by `declaredTextInputUnion` — type identity cannot cross
3774
+ /// the emission boundary.
3775
+ pub const MirrorCaretDirection = enum(u8) { previous = 0, next = 1, previous_word = 2, next_word = 3, start = 4, end = 5 };
3776
+ pub const MirrorCaretMove = struct { direction: MirrorCaretDirection, extend: bool };
3777
+ pub const MirrorSelection = struct { anchor: i64, focus: i64 };
3778
+ pub const MirrorTextInputEvent = union(enum) {
3779
+ insert_text: []const u8,
3780
+ delete_backward,
3781
+ delete_forward,
3782
+ delete_word_backward,
3783
+ delete_word_forward,
3784
+ clear,
3785
+ move_caret: MirrorCaretMove,
3786
+ set_selection: MirrorSelection,
3787
+ set_composition: struct { text: []const u8, cursor: ?i64 },
3788
+ commit_composition,
3789
+ cancel_composition,
3790
+ };
3791
+
3792
+ pub const MirrorModel = struct {
3793
+ draft: []const u8 = "",
3794
+ };
3795
+
3796
+ pub const MirrorMsg = union(enum) {
3797
+ submit,
3798
+ edit: MirrorTextInputEvent,
3799
+ };
3800
+
3801
+ test "declaredTextInputUnion accepts the emitted mirror shape and rejects near-misses" {
3802
+ try testing.expect(markup_view.declaredTextInputUnion(MirrorTextInputEvent));
3803
+ // The canvas union itself matches structurally too (usize numerics).
3804
+ try testing.expect(markup_view.declaredTextInputUnion(canvas.TextInputEvent));
3805
+ // Near-misses stay out: a missing arm, a non-bytes insert payload, a
3806
+ // wrong caret vocabulary.
3807
+ const MissingArm = union(enum) {
3808
+ insert_text: []const u8,
3809
+ delete_backward,
3810
+ delete_forward,
3811
+ delete_word_backward,
3812
+ delete_word_forward,
3813
+ clear,
3814
+ move_caret: MirrorCaretMove,
3815
+ set_selection: MirrorSelection,
3816
+ set_composition: struct { text: []const u8, cursor: ?i64 },
3817
+ commit_composition,
3818
+ };
3819
+ try testing.expect(!markup_view.declaredTextInputUnion(MissingArm));
3820
+ const WrongInsert = union(enum) {
3821
+ insert_text: i64,
3822
+ delete_backward,
3823
+ delete_forward,
3824
+ delete_word_backward,
3825
+ delete_word_forward,
3826
+ clear,
3827
+ move_caret: MirrorCaretMove,
3828
+ set_selection: MirrorSelection,
3829
+ set_composition: struct { text: []const u8, cursor: ?i64 },
3830
+ commit_composition,
3831
+ cancel_composition,
3832
+ };
3833
+ try testing.expect(!markup_view.declaredTextInputUnion(WrongInsert));
3834
+ const WrongDirection = enum { up, down, left, right, home, end_key };
3835
+ const WrongMove = union(enum) {
3836
+ insert_text: []const u8,
3837
+ delete_backward,
3838
+ delete_forward,
3839
+ delete_word_backward,
3840
+ delete_word_forward,
3841
+ clear,
3842
+ move_caret: struct { direction: WrongDirection, extend: bool },
3843
+ set_selection: MirrorSelection,
3844
+ set_composition: struct { text: []const u8, cursor: ?i64 },
3845
+ commit_composition,
3846
+ cancel_composition,
3847
+ };
3848
+ try testing.expect(!markup_view.declaredTextInputUnion(WrongMove));
3849
+ try testing.expect(!markup_view.declaredTextInputUnion(i64));
3850
+ }
3851
+
3852
+ // ------------------------------------- declared scroll-state + value arms
3853
+
3854
+ /// The transpiled-core mirror of `canvas.ScrollState`: the record shape the
3855
+ /// @native-sdk/core emitter produces for a core-declared scroll payload —
3856
+ /// fields keep their TS names (`viewportExtent`), so the mirror carries the
3857
+ /// TS SDK spelling. Matched structurally by `declaredScrollStateRecord` —
3858
+ /// type identity cannot cross the emission boundary. Fields class
3859
+ /// independently (the number tier): float fields widen exactly, integer
3860
+ /// fields round.
3861
+ pub const MirrorScrollState = struct {
3862
+ offset: f64,
3863
+ velocity: f64,
3864
+ viewportExtent: i64,
3865
+ contentExtent: i64,
3866
+ };
3867
+
3868
+ pub const MirrorControlsModel = struct {
3869
+ scroll_top: f64 = 0,
3870
+ seek_fraction: f64 = 0,
3871
+ volume: f64 = 0.5,
3872
+ };
3873
+
3874
+ pub const MirrorControlsMsg = union(enum) {
3875
+ library_scrolled: MirrorScrollState,
3876
+ scrubbed: f64,
3877
+ set_volume: f32,
3878
+ stepped: i64,
3879
+ nudged,
3880
+ };
3881
+
3882
+ test "declaredScrollStateRecord accepts the emitted mirror shape and rejects near-misses" {
3883
+ try testing.expect(markup_view.declaredScrollStateRecord(MirrorScrollState));
3884
+ // The canvas struct itself matches structurally too (four f32 fields).
3885
+ try testing.expect(markup_view.declaredScrollStateRecord(canvas.ScrollState));
3886
+ // A Zig-declared mirror in the canvas spelling stays accepted.
3887
+ try testing.expect(markup_view.declaredScrollStateRecord(struct { offset: f64, velocity: f64, viewport_extent: f64, content_extent: f64 }));
3888
+ // Near-misses stay out: a missing field, a renamed field, a non-numeric
3889
+ // field, an extra field, a spelling mix.
3890
+ try testing.expect(!markup_view.declaredScrollStateRecord(struct { offset: f64, velocity: f64, viewport_extent: f64 }));
3891
+ try testing.expect(!markup_view.declaredScrollStateRecord(struct { offset: f64, velocity: f64, viewport_extent: f64, content_size: f64 }));
3892
+ try testing.expect(!markup_view.declaredScrollStateRecord(struct { offset: []const u8, velocity: f64, viewport_extent: f64, content_extent: f64 }));
3893
+ try testing.expect(!markup_view.declaredScrollStateRecord(struct { offset: f64, velocity: f64, viewport_extent: f64, content_extent: f64, extra: f64 }));
3894
+ try testing.expect(!markup_view.declaredScrollStateRecord(struct { offset: f64, velocity: f64, viewport_extent: f64, contentExtent: f64 }));
3895
+ try testing.expect(!markup_view.declaredScrollStateRecord(i64));
3896
+ }
3897
+
3898
+ test "valueArmClass classifies exactly the value-carrying arm shapes" {
3899
+ try testing.expect(markup_view.valueArmClass(f32) == .identity);
3900
+ try testing.expect(markup_view.valueArmClass(f64) == .float);
3901
+ // Integer arms stay out: the value events deliver a clamped 0..1
3902
+ // fraction, so an integer arm could only ever carry 0 or 1.
3903
+ try testing.expect(markup_view.valueArmClass(i64) == null);
3904
+ try testing.expect(markup_view.valueArmClass(u32) == null);
3905
+ try testing.expect(markup_view.valueArmClass(bool) == null);
3906
+ try testing.expect(markup_view.valueArmClass([]const u8) == null);
3907
+ }
3908
+
3909
+ test "the interpreter binds on-scroll to a declared mirror record and translates the state" {
3910
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
3911
+ defer arena_state.deinit();
3912
+ const arena = arena_state.allocator();
3913
+
3914
+ const model = MirrorControlsModel{};
3915
+ var view = try markup_view.MarkupView(MirrorControlsModel, MirrorControlsMsg).init(arena,
3916
+ \\<scroll value="{scroll_top}" on-scroll="library_scrolled">
3917
+ \\ <text>rows</text>
3918
+ \\</scroll>
3919
+ );
3920
+ var ui = canvas.Ui(MirrorControlsMsg).init(arena);
3921
+ const tree = try ui.finalize(try view.build(&ui, &model));
3922
+ const region = findByKind(tree.root, .scroll_view).?;
3923
+ const msg = tree.msgForScroll(region.id, .{
3924
+ .offset = 41.5,
3925
+ .velocity = -3.25,
3926
+ .viewport_extent = 480.4,
3927
+ .content_extent = 2000.6,
3928
+ }).?;
3929
+ // Float fields widen exactly; integer-classed fields round to the
3930
+ // nearest whole number.
3931
+ try testing.expectEqual(@as(f64, 41.5), msg.library_scrolled.offset);
3932
+ try testing.expectEqual(@as(f64, -3.25), msg.library_scrolled.velocity);
3933
+ try testing.expectEqual(@as(i64, 480), msg.library_scrolled.viewportExtent);
3934
+ try testing.expectEqual(@as(i64, 2001), msg.library_scrolled.contentExtent);
3935
+ }
3936
+
3937
+ test "the interpreter binds slider on-change value arms and keeps the void static form" {
3938
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
3939
+ defer arena_state.deinit();
3940
+ const arena = arena_state.allocator();
3941
+
3942
+ const model = MirrorControlsModel{};
3943
+ var view = try markup_view.MarkupView(MirrorControlsModel, MirrorControlsMsg).init(arena,
3944
+ \\<column>
3945
+ \\ <slider value="{seek_fraction}" label="Seek" on-change="scrubbed" />
3946
+ \\ <slider value="{volume}" label="Volume" on-change="set_volume" />
3947
+ \\ <slider value="{volume}" label="Nudge" on-change="nudged" />
3948
+ \\</column>
3949
+ );
3950
+ var ui = canvas.Ui(MirrorControlsMsg).init(arena);
3951
+ const tree = try ui.finalize(try view.build(&ui, &model));
3952
+ var sliders: [3]canvas.Widget = undefined;
3953
+ var count: usize = 0;
3954
+ collectByKind(tree.root, .slider, &sliders, &count);
3955
+ try testing.expectEqual(@as(usize, 3), count);
3956
+ // The f64 arm receives the applied fraction widened exactly.
3957
+ try testing.expectEqual(@as(f64, 0.25), tree.msgForChange(sliders[0].id, 0.25).?.scrubbed);
3958
+ // The f32 arm keeps the identity path.
3959
+ try testing.expectEqual(@as(f32, 0.5), tree.msgForChange(sliders[1].id, 0.5).?.set_volume);
3960
+ // A void arm keeps the static "something changed" form.
3961
+ try testing.expectEqual(MirrorControlsMsg.nudged, tree.msgForChange(sliders[2].id, 0.9).?);
3962
+ // An integer arm is not a value target: the bare form stays the
3963
+ // static-message error path ("message requires a payload").
3964
+ var bad_view = try markup_view.MarkupView(MirrorControlsModel, MirrorControlsMsg).init(arena,
3965
+ \\<slider value="{volume}" label="Step" on-change="stepped" />
3966
+ );
3967
+ var bad_ui = canvas.Ui(MirrorControlsMsg).init(arena);
3968
+ try testing.expectError(error.MarkupBuild, bad_view.build(&bad_ui, &model));
3969
+ try testing.expectEqualStrings("message requires a payload", bad_view.diagnostic.message);
3970
+ }
3971
+
3972
+ fn collectByKind(widget: canvas.Widget, kind: canvas.WidgetKind, out: []canvas.Widget, count: *usize) void {
3973
+ if (widget.kind == kind and count.* < out.len) {
3974
+ out[count.*] = widget;
3975
+ count.* += 1;
3976
+ }
3977
+ for (widget.children) |child| collectByKind(child, kind, out, count);
3978
+ }
3979
+
3980
+ test "the interpreter binds split on-resize to a declared one-number float arm" {
3981
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
3982
+ defer arena_state.deinit();
3983
+ const arena = arena_state.allocator();
3984
+
3985
+ const model = MirrorControlsModel{};
3986
+ var view = try markup_view.MarkupView(MirrorControlsModel, MirrorControlsMsg).init(arena,
3987
+ \\<split value="{seek_fraction}" on-resize="scrubbed">
3988
+ \\ <column><text>left</text></column>
3989
+ \\ <column><text>right</text></column>
3990
+ \\</split>
3991
+ );
3992
+ var ui = canvas.Ui(MirrorControlsMsg).init(arena);
3993
+ const tree = try ui.finalize(try view.build(&ui, &model));
3994
+ const fraction = tree.msgForResize(tree.root.id, 0.25).?.scrubbed;
3995
+ try testing.expectApproxEqAbs(@as(f64, 0.25), fraction, 0.0000001);
3996
+ }
3997
+
3998
+ test "on-resize with an integer arm keeps the payload teaching message" {
3999
+ // on-resize stays float-only: an i64 arm is not a fraction target.
4000
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
4001
+ defer arena_state.deinit();
4002
+ const arena = arena_state.allocator();
4003
+ const source = "<split value=\"0.5\" on-resize=\"stepped\"><column></column><column></column></split>";
4004
+ const model = MirrorControlsModel{};
4005
+ var view = try markup_view.MarkupView(MirrorControlsModel, MirrorControlsMsg).init(arena, source);
4006
+ var ui = canvas.Ui(MirrorControlsMsg).init(arena);
4007
+ try testing.expectError(error.MarkupBuild, view.build(&ui, &model));
4008
+ try testing.expectEqualStrings(canvas.ui_markup.on_resize_payload_message, view.diagnostic.message);
4009
+ }
4010
+
4011
+ test "the interpreter binds on-input to a declared mirror union and translates every event" {
4012
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
4013
+ defer arena_state.deinit();
4014
+ const arena = arena_state.allocator();
4015
+
4016
+ const model = MirrorModel{ .draft = "hi" };
4017
+ var view = try markup_view.MarkupView(MirrorModel, MirrorMsg).init(arena,
4018
+ \\<column>
4019
+ \\ <text-field text="{draft}" label="Draft" on-input="edit" on-submit="submit" />
4020
+ \\</column>
4021
+ );
4022
+ var ui = canvas.Ui(MirrorMsg).init(arena);
4023
+ const tree = try ui.finalize(try view.build(&ui, &model));
4024
+ const field = findByKind(tree.root, .text_field).?;
4025
+
4026
+ // Bytes ride through unchanged.
4027
+ const inserted = tree.msgForTextEdit(field.id, .{ .insert_text = "abc" }).?;
4028
+ try testing.expectEqualStrings("abc", inserted.edit.insert_text);
4029
+ // Void verbs map by tag.
4030
+ try testing.expectEqual(MirrorTextInputEvent.delete_backward, tree.msgForTextEdit(field.id, .delete_backward).?.edit);
4031
+ // Caret moves translate the direction enum by member name.
4032
+ const moved = tree.msgForTextEdit(field.id, .{ .move_caret = .{ .direction = .previous_word, .extend = true } }).?;
4033
+ try testing.expectEqual(MirrorCaretDirection.previous_word, moved.edit.move_caret.direction);
4034
+ try testing.expect(moved.edit.move_caret.extend);
4035
+ // Selections widen into the declared integer fields.
4036
+ const selected = tree.msgForTextEdit(field.id, .{ .set_selection = .{ .anchor = 1, .focus = 4 } }).?;
4037
+ try testing.expectEqual(@as(i64, 1), selected.edit.set_selection.anchor);
4038
+ try testing.expectEqual(@as(i64, 4), selected.edit.set_selection.focus);
4039
+ // Compositions carry text and the optional cursor.
4040
+ const composed = tree.msgForTextEdit(field.id, .{ .set_composition = .{ .text = "é", .cursor = 2 } }).?;
4041
+ try testing.expectEqualStrings("é", composed.edit.set_composition.text);
4042
+ try testing.expectEqual(@as(?i64, 2), composed.edit.set_composition.cursor);
4043
+ const cleared = tree.msgForTextEdit(field.id, .{ .set_composition = .{ .text = "", .cursor = null } }).?;
4044
+ try testing.expectEqual(@as(?i64, null), cleared.edit.set_composition.cursor);
4045
+ }
@@ -442,6 +442,14 @@ pub const attrs = [_]AttrInfo{
442
442
  // (absent) declares no origin, so every existing document keeps
443
443
  // its mount-never-animates behavior.
444
444
  .{ .code = 78, .name = "resize-origin", .class = .number, .group = .option, .field = "resize_origin" },
445
+ // The quiet-surface knob (`WidgetStyle.quiet_hover`) for
446
+ // image-forward content tiles: opts a pressable element out of the
447
+ // HOVER wash only — press/selection fills, the focus ring, cursor
448
+ // intent, and hit testing keep their own channels. Hit-target
449
+ // elements only (the validator scopes it; anywhere else it would be
450
+ // silently inert). No `field`: the engines apply it to
451
+ // `ElementOptions.style`, not a flat option field.
452
+ .{ .code = 79, .name = "quiet-hover", .class = .flag, .group = .option },
445
453
  };
446
454
 
447
455
  // ----------------------------------------------------------------- events
@@ -22,7 +22,7 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
22
22
  // the new fingerprint ONLY for additions; renames/renumbers are
23
23
  // schema-version-bump events, not silent edits.
24
24
  try testing.expectEqual(@as(usize, 65), schema.elements.len);
25
- try testing.expectEqual(@as(usize, 78), schema.attrs.len);
25
+ try testing.expectEqual(@as(usize, 79), schema.attrs.len);
26
26
  try testing.expectEqual(@as(usize, 10), schema.events.len);
27
27
  // The element table runs through the span composite (64) and the
28
28
  // bubble-reactions composite (65); the reaction pill's dock rides
@@ -35,10 +35,11 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
35
35
  // The attr table runs through the split layout-tween attributes
36
36
  // resize-duration (71) and resize-easing (72), the chart axis/hover
37
37
  // attributes x-labels (73), y-labels (74), and hover-details (75),
38
- // the later span additions scale (76) and underline (77), and the
39
- // split enter-from attribute resize-origin (78).
38
+ // the later span additions scale (76) and underline (77), the
39
+ // split enter-from attribute resize-origin (78), and the
40
+ // quiet-surface hover knob quiet-hover (79).
40
41
  try testing.expectEqual(
41
- @as(u64, 0x13fddf21980756c0),
42
+ @as(u64, 0x3b439a78a91600b6),
42
43
  tableFingerprint(schema.AttrInfo, &schema.attrs),
43
44
  );
44
45
  try testing.expectEqual(
@@ -94,9 +94,10 @@ pub fn diffWidgetLayoutTrees(previous: anytype, next: anytype, tokens: DesignTok
94
94
  next.nodes.len >= plan_key_index.min_entries_for_index) and
95
95
  plan_key_index.fitsHashSlots(diff_widget_id_index_slots, previous.nodes.len) and
96
96
  plan_key_index.fitsHashSlots(diff_widget_id_index_slots, next.nodes.len);
97
- if (use_index) {
98
- try buildDiffWidgetIdIndex(previous, &diff_previous_widget_id_index);
99
- try buildDiffWidgetIdIndex(next, &diff_next_widget_id_index);
97
+ const id_scratch: ?*DiffWidgetIdScratch = if (use_index) diff_widget_id_scratch.get() else null;
98
+ if (id_scratch) |scratch| {
99
+ try buildDiffWidgetIdIndex(previous, &scratch.previous);
100
+ try buildDiffWidgetIdIndex(next, &scratch.next);
100
101
  } else {
101
102
  try validateUniqueWidgetIds(previous);
102
103
  try validateUniqueWidgetIds(next);
@@ -106,7 +107,7 @@ pub fn diffWidgetLayoutTrees(previous: anytype, next: anytype, tokens: DesignTok
106
107
  for (previous.nodes, 0..) |previous_node, previous_index| {
107
108
  const id = previous_node.widget.id;
108
109
  if (id == 0) continue;
109
- const next_lookup = if (use_index) findWidgetNodeByIdIndexed(next, &diff_next_widget_id_index, id) else findWidgetNodeById(next, id);
110
+ const next_lookup = if (id_scratch) |scratch| findWidgetNodeByIdIndexed(next, &scratch.next, id) else findWidgetNodeById(next, id);
110
111
  const next_ref = next_lookup orelse {
111
112
  try appendWidgetInvalidation(output, &len, .{
112
113
  .kind = .removed,
@@ -157,7 +158,7 @@ pub fn diffWidgetLayoutTrees(previous: anytype, next: anytype, tokens: DesignTok
157
158
  for (next.nodes, 0..) |next_node, next_index| {
158
159
  const id = next_node.widget.id;
159
160
  if (id == 0) continue;
160
- const previous_lookup = if (use_index) findWidgetNodeByIdIndexed(previous, &diff_previous_widget_id_index, id) else findWidgetNodeById(previous, id);
161
+ const previous_lookup = if (id_scratch) |scratch| findWidgetNodeByIdIndexed(previous, &scratch.previous, id) else findWidgetNodeById(previous, id);
161
162
  if (previous_lookup == null) {
162
163
  try appendWidgetInvalidation(output, &len, .{
163
164
  .kind = .added,
@@ -201,8 +202,14 @@ fn findWidgetNodeById(layout: anytype, id: ObjectId) ?WidgetNodeRef {
201
202
  /// bound; small or oversized trees keep the linear scans.
202
203
  const diff_widget_id_index_slots = 2048;
203
204
  const DiffWidgetIdIndex = plan_key_index.HashSlots(diff_widget_id_index_slots);
204
- threadlocal var diff_previous_widget_id_index: DiffWidgetIdIndex = .{};
205
- threadlocal var diff_next_widget_id_index: DiffWidgetIdIndex = .{};
205
+ // Lazily heap-allocated per thread (16 KiB of probe tables): reset per
206
+ // diff, so first-use init on the diffing thread is the only contract —
207
+ // threads that never diff widget trees never allocate it.
208
+ const DiffWidgetIdScratch = struct {
209
+ previous: DiffWidgetIdIndex = .{},
210
+ next: DiffWidgetIdIndex = .{},
211
+ };
212
+ const diff_widget_id_scratch = @import("lazy_tls.zig").LazyTls(DiffWidgetIdScratch);
206
213
 
207
214
  /// Fill `table` with the keyed nodes' id->index mapping, erroring on the
208
215
  /// duplicate ids `validateUniqueWidgetIds` rejects — one pass does both