@native-sdk/cli 0.5.1 → 0.5.2

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 (44) hide show
  1. package/package.json +9 -9
  2. package/packages/core/package-lock.json +2 -2
  3. package/packages/core/package.json +1 -1
  4. package/skill-data/native-ui/SKILL.md +2 -2
  5. package/src/platform/types.zig +9 -0
  6. package/src/primitives/canvas/root.zig +1 -0
  7. package/src/primitives/canvas/tokens.zig +170 -7
  8. package/src/primitives/canvas/ui.zig +27 -5
  9. package/src/primitives/canvas/ui_markup.zig +27 -4
  10. package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
  11. package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
  12. package/src/primitives/canvas/ui_markup_tests.zig +47 -0
  13. package/src/primitives/canvas/ui_markup_view.zig +10 -1
  14. package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
  15. package/src/primitives/canvas/ui_schema.zig +15 -1
  16. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  17. package/src/primitives/canvas/widget_builtin_tests.zig +130 -0
  18. package/src/primitives/canvas/widget_layout.zig +4 -1
  19. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  20. package/src/primitives/canvas/widget_tree.zig +14 -2
  21. package/src/primitives/canvas/widgets.zig +12 -0
  22. package/src/runtime/automation_widget_dispatch.zig +95 -28
  23. package/src/runtime/canvas_frame.zig +15 -0
  24. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  25. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  26. package/src/runtime/canvas_widget_events.zig +1271 -3
  27. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  28. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  29. package/src/runtime/canvas_widget_state.zig +82 -5
  30. package/src/runtime/core.zig +14 -0
  31. package/src/runtime/flow.zig +24 -1
  32. package/src/runtime/gpu_surface_events.zig +44 -5
  33. package/src/runtime/session_journal.zig +25 -13
  34. package/src/runtime/session_record.zig +166 -0
  35. package/src/runtime/session_tests.zig +453 -0
  36. package/src/runtime/ui_app.zig +6 -1
  37. package/src/runtime/ui_app_tests.zig +460 -0
  38. package/src/runtime/view.zig +86 -0
  39. package/src/runtime/view_widget_text.zig +18 -1
  40. package/src/runtime/view_widget_tree.zig +339 -20
  41. package/src/runtime/widget_bridge.zig +26 -0
  42. package/src/runtime/window_storage.zig +61 -15
  43. package/src/runtime/window_view_runtime.zig +13 -0
  44. package/src/runtime/window_views.zig +6 -0
@@ -795,6 +795,53 @@ test "overscroll validates as scroll-scoped with a closed value vocabulary" {
795
795
  }
796
796
  }
797
797
 
798
+ test "tooltip-delay validates as tooltip-scoped beside anchor, and anchor accepts tooltip" {
799
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
800
+ defer arena_state.deinit();
801
+ const arena = arena_state.allocator();
802
+
803
+ // Valid: an anchored tooltip with a literal delay, a zero delay
804
+ // (instant show), a binding (resolved by the engines at build), and
805
+ // an anchored tooltip with no delay at all (the token default).
806
+ const valid_sources = [_][]const u8{
807
+ "<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"above\" tooltip-delay=\"500\">Bold the selection</tooltip>\n</stack>",
808
+ "<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"above\" tooltip-delay=\"0\">Bold the selection</tooltip>\n</stack>",
809
+ "<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"below\" tooltip-delay=\"{delay}\">Bold the selection</tooltip>\n</stack>",
810
+ "<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"above\">Bold the selection</tooltip>\n</stack>",
811
+ };
812
+ for (valid_sources) |source| {
813
+ var parser = markup.Parser.init(arena, source);
814
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
815
+ }
816
+
817
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
818
+ // Hover intent exists only where the runtime owns visibility;
819
+ // anywhere else the delay is silently inert.
820
+ .{
821
+ .source = "<column>\n <button on-press=\"pressed\" tooltip-delay=\"500\">Bold</button>\n</column>",
822
+ .message = markup.tooltip_delay_element_message,
823
+ },
824
+ // A delay beside no anchor shapes a hover-show that never
825
+ // happens: a static tooltip paints whenever the view renders it.
826
+ .{
827
+ .source = "<column>\n <tooltip tooltip-delay=\"500\">Bold the selection</tooltip>\n</column>",
828
+ .message = markup.tooltip_delay_dependent_attr_message,
829
+ },
830
+ // Anchor stays scoped to its registry set; tooltip joining it
831
+ // must not open other elements.
832
+ .{
833
+ .source = "<column>\n <badge anchor=\"above\">3</badge>\n</column>",
834
+ .message = markup.anchor_element_message,
835
+ },
836
+ };
837
+ for (cases) |case| {
838
+ var parser = markup.Parser.init(arena, case.source);
839
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
840
+ try testing.expectEqualStrings(case.message, info.message);
841
+ try testing.expect(info.line > 0);
842
+ }
843
+ }
844
+
798
845
  test "overflow validates as text-scoped with a closed value vocabulary" {
799
846
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
800
847
  defer arena_state.deinit();
@@ -1666,8 +1666,17 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1666
1666
  // Optional bools (`expanded`): the attribute's PRESENCE
1667
1667
  // makes the state non-null; the value sets it.
1668
1668
  .optional => @field(options, field) = value.truthy(),
1669
+ // Range-checked against the FIELD's own integer type
1670
+ // before the cast (the grid-lines teaching, generalized):
1671
+ // expression values are i64, so a literal or model
1672
+ // binding can deliver 2147483648 to the i32
1673
+ // tooltip-delay — an unchecked @intCast TRAPPED on it
1674
+ // instead of failing the build. The field type is the
1675
+ // honest upper bound: no semantic millisecond cap is
1676
+ // invented on top of it, matching resize-duration, whose
1677
+ // only bound is likewise its u32.
1669
1678
  .int => @field(options, field) = switch (value) {
1670
- .integer => |int| if (int < 0)
1679
+ .integer => |int| if (int < 0 or int > std.math.maxInt(FieldType))
1671
1680
  return self.failVoid(node, "expected a non-negative whole number")
1672
1681
  else
1673
1682
  @intCast(int),
@@ -716,6 +716,84 @@ test "resize-duration and resize-easing on split stamp the layout-tween declarat
716
716
  try testing.expectEqual(canvas.Easing.standard, plain.resize_easing);
717
717
  }
718
718
 
719
+ test "anchor and tooltip-delay on tooltip stamp the hover-intent declaration" {
720
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
721
+ defer arena_state.deinit();
722
+ const arena = arena_state.allocator();
723
+ const model = Model{};
724
+
725
+ // An anchored tooltip declaring its own delay, an anchored tooltip
726
+ // on the token default, and a bare static tooltip that keeps the
727
+ // classic paints-when-rendered leaf — so existing documents lower
728
+ // byte-identically.
729
+ var view = try InboxMarkup.init(arena, "<column>\n <stack>\n <text>Bold</text>\n <tooltip anchor=\"above\" tooltip-delay=\"250\">Bold the selection</tooltip>\n </stack>\n <stack>\n <text>Link</text>\n <tooltip anchor=\"below\">Insert a link</tooltip>\n </stack>\n <tooltip>Copied!</tooltip>\n</column>");
730
+ var ui = InboxUi.init(arena);
731
+ const tree = try ui.finalize(try view.build(&ui, &model));
732
+
733
+ const declared = findByText(tree.root, .tooltip, "Bold the selection").?;
734
+ try testing.expectEqual(@as(i32, 250), declared.tooltip_delay_ms);
735
+ try testing.expectEqual(canvas.WidgetAnchorPlacement.above, declared.layout.anchor.?.placement);
736
+
737
+ const defaulted = findByText(tree.root, .tooltip, "Insert a link").?;
738
+ try testing.expectEqual(@as(i32, -1), defaulted.tooltip_delay_ms);
739
+ try testing.expectEqual(canvas.WidgetAnchorPlacement.below, defaulted.layout.anchor.?.placement);
740
+
741
+ const static = findByText(tree.root, .tooltip, "Copied!").?;
742
+ try testing.expectEqual(@as(i32, -1), static.tooltip_delay_ms);
743
+ try testing.expectEqual(@as(?canvas.WidgetAnchor, null), static.layout.anchor);
744
+ }
745
+
746
+ test "tooltip-delay past i32 max fails the build instead of trapping" {
747
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
748
+ defer arena_state.deinit();
749
+ const arena = arena_state.allocator();
750
+ const model = Model{};
751
+
752
+ // One past maxInt(i32): the option field's own type is the bound,
753
+ // so the cast that used to trap is now the grid-lines teaching
754
+ // error. The value parses fine as a 64-bit literal — the failure
755
+ // must come from the attribute seam, not the expression parser.
756
+ var overflow_view = try InboxMarkup.init(arena, "<column>\n <stack>\n <text>Bold</text>\n <tooltip anchor=\"above\" tooltip-delay=\"2147483648\">Bold the selection</tooltip>\n </stack>\n</column>");
757
+ var overflow_ui = InboxUi.init(arena);
758
+ try testing.expectError(error.MarkupBuild, overflow_view.build(&overflow_ui, &model));
759
+ try testing.expectEqualStrings("expected a non-negative whole number", overflow_view.diagnostic.message);
760
+
761
+ // Boundary values pass: 0 (the instant-show escape hatch) and the
762
+ // type's exact max.
763
+ var boundary_view = try InboxMarkup.init(arena, "<column>\n <stack>\n <text>Bold</text>\n <tooltip anchor=\"above\" tooltip-delay=\"0\">Bold the selection</tooltip>\n </stack>\n <stack>\n <text>Link</text>\n <tooltip anchor=\"below\" tooltip-delay=\"2147483647\">Insert a link</tooltip>\n </stack>\n</column>");
764
+ var boundary_ui = InboxUi.init(arena);
765
+ const tree = try boundary_ui.finalize(try boundary_view.build(&boundary_ui, &model));
766
+ try testing.expectEqual(@as(i32, 0), findByText(tree.root, .tooltip, "Bold the selection").?.tooltip_delay_ms);
767
+ try testing.expectEqual(@as(i32, std.math.maxInt(i32)), findByText(tree.root, .tooltip, "Insert a link").?.tooltip_delay_ms);
768
+ }
769
+
770
+ test "tooltip-delay model binding past i32 max fails the build instead of trapping" {
771
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
772
+ defer arena_state.deinit();
773
+ const arena = arena_state.allocator();
774
+
775
+ // Bindings deliver i64 model values straight into the same cast
776
+ // seam the literal path uses, so an out-of-range model value must
777
+ // produce the same teaching error — per-build, since only the
778
+ // value (not the document) is wrong.
779
+ const DelayModel = struct { delay: i64 = 0 };
780
+ const DelayMarkup = markup_view.MarkupView(DelayModel, Msg);
781
+ const source = "<column>\n <stack>\n <text>Bold</text>\n <tooltip anchor=\"above\" tooltip-delay=\"{delay}\">Bold the selection</tooltip>\n </stack>\n</column>";
782
+
783
+ var overflow_view = try DelayMarkup.init(arena, source);
784
+ var overflow_ui = InboxUi.init(arena);
785
+ const overflow_model = DelayModel{ .delay = @as(i64, std.math.maxInt(i32)) + 1 };
786
+ try testing.expectError(error.MarkupBuild, overflow_view.build(&overflow_ui, &overflow_model));
787
+ try testing.expectEqualStrings("expected a non-negative whole number", overflow_view.diagnostic.message);
788
+
789
+ // The same document lowers when the model holds an in-range value.
790
+ var ok_view = try DelayMarkup.init(arena, source);
791
+ var ok_ui = InboxUi.init(arena);
792
+ const ok_model = DelayModel{ .delay = 250 };
793
+ const tree = try ok_ui.finalize(try ok_view.build(&ok_ui, &ok_model));
794
+ try testing.expectEqual(@as(i32, 250), findByText(tree.root, .tooltip, "Bold the selection").?.tooltip_delay_ms);
795
+ }
796
+
719
797
  test "resize-easing value vocabulary mirrors the live Easing enum" {
720
798
  // The validator's std-only mirror of the enum's member names; a new
721
799
  // member cannot ship without its markup spelling.
@@ -249,7 +249,13 @@ pub const elements = [_]ElementInfo{
249
249
  .{ .code = 36, .name = "switch", .widget_kind = "switch_control", .takes_text = true, .a11y_name = .control },
250
250
  .{ .code = 37, .name = "table-cell", .widget_kind = "data_cell", .takes_text = true },
251
251
  .{ .code = 38, .name = "toggle-button", .widget_kind = "toggle_button", .takes_text = true, .icon_attr = true, .a11y_name = .control },
252
- .{ .code = 39, .name = "tooltip", .widget_kind = "tooltip", .takes_text = true, .hit_target = false },
252
+ // Tooltip is anchorable: `anchor="above|below"` floats it against
253
+ // its PARENT's frame (the trigger, or the stack wrapping trigger +
254
+ // tooltip), and the RUNTIME owns its visibility — hidden until the
255
+ // hover-intent delay on the trigger fires (see `tooltip-delay`).
256
+ // Without `anchor` it stays the classic static text leaf that
257
+ // paints whenever the view renders it.
258
+ .{ .code = 39, .name = "tooltip", .widget_kind = "tooltip", .takes_text = true, .hit_target = false, .anchorable = true },
253
259
  // Value controls and text entry.
254
260
  .{ .code = 40, .name = "checkbox", .widget_kind = "checkbox", .a11y_name = .control },
255
261
  .{ .code = 41, .name = "radio", .widget_kind = "radio", .a11y_name = .control },
@@ -450,6 +456,14 @@ pub const attrs = [_]AttrInfo{
450
456
  // silently inert). No `field`: the engines apply it to
451
457
  // `ElementOptions.style`, not a flat option field.
452
458
  .{ .code = 79, .name = "quiet-hover", .class = .flag, .group = .option },
459
+ // Hover-intent show delay for ANCHORED tooltips (tooltip only, and
460
+ // only beside `anchor`; the validator scopes both), in whole
461
+ // milliseconds. The runtime shows an anchored tooltip after its
462
+ // trigger has been hovered this long on the recorded frame clock —
463
+ // 0 shows the instant the trigger is hovered. Negative is
464
+ // unreachable from markup; absent keeps the token default
465
+ // (`ControlMetricTokens.tooltip_show_delay_ms`).
466
+ .{ .code = 80, .name = "tooltip-delay", .class = .whole, .group = .option, .field = "tooltip_delay" },
453
467
  };
454
468
 
455
469
  // ----------------------------------------------------------------- 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, 79), schema.attrs.len);
25
+ try testing.expectEqual(@as(usize, 80), 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
@@ -36,10 +36,11 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
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
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).
39
+ // split enter-from attribute resize-origin (78), the quiet-surface
40
+ // hover knob quiet-hover (79), and the anchored-tooltip hover-intent
41
+ // delay tooltip-delay (80).
41
42
  try testing.expectEqual(
42
- @as(u64, 0x3b439a78a91600b6),
43
+ @as(u64, 0x5348b0f92c314d2a),
43
44
  tableFingerprint(schema.AttrInfo, &schema.attrs),
44
45
  );
45
46
  try testing.expectEqual(
@@ -1415,6 +1415,136 @@ test "design tokens provide theme and contrast palettes" {
1415
1415
  try std.testing.expectEqual(Easing.linear, reduced_motion.motion.easing);
1416
1416
  }
1417
1417
 
1418
+ test "the accent override desaturates its dark-scheme focus ring" {
1419
+ const accent = Color.rgb8(223, 38, 112);
1420
+
1421
+ // Light keeps the raw accent on every identity slot, ring included.
1422
+ const light = canvas.accentOverrides(accent, .light);
1423
+ try std.testing.expectEqualDeep(accent, light.colors.accent.?);
1424
+ try std.testing.expectEqualDeep(accent, light.colors.focus_ring.?);
1425
+
1426
+ // Dark keeps the accent identity but derives the ring at half the
1427
+ // accent's HSL saturation — a quiet outline instead of a neon glare
1428
+ // — through the exported derivation, so hand-authored token sets
1429
+ // can state the same value.
1430
+ const dark = canvas.accentOverrides(accent, .dark);
1431
+ try std.testing.expectEqualDeep(accent, dark.colors.accent.?);
1432
+ const ring = dark.colors.focus_ring.?;
1433
+ try std.testing.expectEqualDeep(canvas.accentFocusRing(accent, .dark), ring);
1434
+ try std.testing.expect(!std.meta.eql(accent, ring));
1435
+ // Same lightness (HSL max+min preserved), lower chroma: the channel
1436
+ // spread shrinks to half while the hue's ordering holds.
1437
+ const accent_spread = @max(accent.r, @max(accent.g, accent.b)) - @min(accent.r, @min(accent.g, accent.b));
1438
+ const ring_spread = @max(ring.r, @max(ring.g, ring.b)) - @min(ring.r, @min(ring.g, ring.b));
1439
+ try std.testing.expect(ring_spread < accent_spread);
1440
+ try std.testing.expect(ring.r > ring.b and ring.b > ring.g);
1441
+
1442
+ // An achromatic accent has no saturation to halve: the ring passes
1443
+ // through untouched.
1444
+ const gray = Color.rgb8(115, 115, 115);
1445
+ try std.testing.expectEqualDeep(gray, canvas.accentFocusRing(gray, .dark));
1446
+ }
1447
+
1448
+ test "the dark accent focus ring holds the non-text contrast floor across hues" {
1449
+ // Rings draw OUTSIDE controls, so the tones that matter are the
1450
+ // dark containers controls commonly sit on, across BOTH shipped
1451
+ // packs: page background, card/popover surface, and the muted
1452
+ // surface (the tabs-list pill container focusable triggers sit
1453
+ // inside). accentFocusRing floors against the LIGHTEST of these
1454
+ // (house surface_subtle #262626) — a ring clearing 3:1 there
1455
+ // clears every darker tone in the set too; each is asserted below.
1456
+ const house_dark = DesignTokens.theme(.{ .color_scheme = .dark }).colors;
1457
+ const geist_dark = DesignTokens.theme(.{ .pack = .geist, .color_scheme = .dark }).colors;
1458
+ const adjacent_tones = [_]Color{
1459
+ house_dark.background, // #0a0a0a
1460
+ house_dark.surface, // #171717
1461
+ house_dark.surface_subtle, // #262626 — the floor's reference
1462
+ geist_dark.background, // #000000 (Geist surface is the same black)
1463
+ geist_dark.surface_subtle, // #1a1a1a
1464
+ };
1465
+ const reference_tone = house_dark.surface_subtle;
1466
+ const cases = [_]Color{
1467
+ // Green: the input clears 3:1 on the background AND the card
1468
+ // surface; desaturation alone dropped to ~2.6:1 on the
1469
+ // background (worse still on the surface) — the floor lifts it
1470
+ // back over the bar on both. Against the muted reference the
1471
+ // input itself sits just under 3:1 (~2.94), so the ring holds
1472
+ // exactly that there — restored, never invented.
1473
+ Color.rgb8(0, 128, 0),
1474
+ // Deep blue: below 3:1 on its own; the ring must not get worse.
1475
+ Color.rgb8(0, 0, 204),
1476
+ // Dark red: below 3:1 on its own AND desaturation costs more —
1477
+ // the floor restores the accent's own contrast, no further.
1478
+ Color.rgb8(139, 0, 0),
1479
+ // The soundboard pink: clears the bar before and after halving.
1480
+ Color.rgb8(223, 38, 112),
1481
+ // Achromatic gray: nothing to desaturate, passes through.
1482
+ Color.rgb8(115, 115, 115),
1483
+ };
1484
+ for (cases) |accent| {
1485
+ // Light passes the accent through untouched, every hue.
1486
+ try std.testing.expectEqualDeep(accent, canvas.accentFocusRing(accent, .light));
1487
+
1488
+ const ring = canvas.accentFocusRing(accent, .dark);
1489
+ // Dark never raises saturation; chromatic accents lose half.
1490
+ const accent_saturation = testHslSaturation(accent);
1491
+ const ring_saturation = testHslSaturation(ring);
1492
+ if (accent_saturation > 0) {
1493
+ try std.testing.expect(ring_saturation < accent_saturation);
1494
+ } else {
1495
+ try std.testing.expectEqualDeep(accent, ring);
1496
+ }
1497
+ // The floor, tone by tone: >= 3:1 (WCAG non-text) against EVERY
1498
+ // adjacent tone the accent itself cleared it on. Flooring
1499
+ // against the lightest tone guarantees the rest: where the
1500
+ // accent cleared 3:1 anywhere, the ring's luminance lands at or
1501
+ // above the accent's, so no darker tone can regress.
1502
+ for (adjacent_tones) |tone| {
1503
+ if (testContrastRatio(accent, tone) >= 3.0) {
1504
+ try std.testing.expect(testContrastRatio(ring, tone) >= 3.0);
1505
+ }
1506
+ }
1507
+ // The escape hatch, stated against the SAME reference the floor
1508
+ // measures on: when the accent never cleared 3:1 there, the
1509
+ // ring still never lands below the accent's own contrast.
1510
+ const accent_contrast = testContrastRatio(accent, reference_tone);
1511
+ const ring_contrast = testContrastRatio(ring, reference_tone);
1512
+ if (accent_contrast >= 3.0) {
1513
+ try std.testing.expect(ring_contrast >= 3.0);
1514
+ } else {
1515
+ try std.testing.expect(ring_contrast >= accent_contrast);
1516
+ }
1517
+ }
1518
+ }
1519
+
1520
+ /// HSL saturation of a color, for the desaturation assertions.
1521
+ fn testHslSaturation(color: Color) f32 {
1522
+ const max = @max(color.r, @max(color.g, color.b));
1523
+ const min = @min(color.r, @min(color.g, color.b));
1524
+ const delta = max - min;
1525
+ if (delta <= 0.0001) return 0;
1526
+ const lightness = (max + min) / 2;
1527
+ return delta / (1 - @abs(2 * lightness - 1));
1528
+ }
1529
+
1530
+ /// WCAG contrast ratio between two colors, for the floor assertions.
1531
+ fn testContrastRatio(a: Color, b: Color) f32 {
1532
+ const la = testRelativeLuminance(a);
1533
+ const lb = testRelativeLuminance(b);
1534
+ return (@max(la, lb) + 0.05) / (@min(la, lb) + 0.05);
1535
+ }
1536
+
1537
+ fn testRelativeLuminance(color: Color) f32 {
1538
+ return 0.2126 * testSrgbToLinear(color.r) +
1539
+ 0.7152 * testSrgbToLinear(color.g) +
1540
+ 0.0722 * testSrgbToLinear(color.b);
1541
+ }
1542
+
1543
+ fn testSrgbToLinear(channel: f32) f32 {
1544
+ if (channel <= 0.04045) return channel / 12.92;
1545
+ return std.math.pow(f32, (channel + 0.055) / 1.055, 2.4);
1546
+ }
1547
+
1418
1548
  test "built-in component catalog covers house component set" {
1419
1549
  const expected_names = [_][]const u8{
1420
1550
  "Accordion",
@@ -1681,7 +1681,10 @@ fn intrinsicGridChildrenSize(widget: Widget, tokens: DesignTokens, depth: usize)
1681
1681
  cell_height = @max(cell_height, size.height);
1682
1682
  }
1683
1683
  const columns = gridColumnCount(widget.children.len, widget.layout.columns);
1684
- const rows = (widget.children.len + columns - 1) / columns;
1684
+ // `gridRowCount`, not the additive ceil-div: declared columns are
1685
+ // engine input, and `children.len + columns` overflows in safe
1686
+ // builds when a parent intrinsically measures a maxInt-columns grid.
1687
+ const rows = gridRowCount(widget.children.len, columns);
1685
1688
  const gap = nonNegative(widget.layout.gap);
1686
1689
  return paddedIntrinsicSize(widget, geometry.SizeF.init(
1687
1690
  cell_width * @as(f32, @floatFromInt(columns)) + gap * @as(f32, @floatFromInt(columns - 1)),
@@ -935,6 +935,88 @@ test "widget grid layout places children in deterministic cells" {
935
935
  try std.testing.expectEqual(@as(usize, 8), builder.displayList().commandCount());
936
936
  }
937
937
 
938
+ test "widget grid keeps declared column slots when children run short" {
939
+ // Fewer children than the declared columns (a filtered grid): each
940
+ // child keeps the column-slot width the declared count derives —
941
+ // never stretching across the freed row — filling the leading slots
942
+ // and leaving the trailing slots empty.
943
+ const children = [_]Widget{
944
+ .{ .id = 2, .kind = .text, .text = "One" },
945
+ .{ .id = 3, .kind = .text, .text = "Two" },
946
+ };
947
+ const grid = Widget{
948
+ .id = 1,
949
+ .kind = .grid,
950
+ .layout = .{ .gap = 8, .columns = 4 },
951
+ .children = &children,
952
+ };
953
+
954
+ var nodes: [4]WidgetLayoutNode = undefined;
955
+ const layout = try layoutWidgetTree(grid, geometry.RectF.init(0, 0, 424, 40), &nodes);
956
+ try std.testing.expectEqual(@as(usize, 3), layout.nodeCount());
957
+ // Slot width = (424 - 3 gaps of 8) / 4 declared columns = 100.
958
+ try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 100, 40));
959
+ try expectLayoutFrame(layout, 3, geometry.RectF.init(108, 0, 100, 40));
960
+ }
961
+
962
+ test "widget grid row count survives a huge declared column count" {
963
+ const widget_tree = @import("widget_tree.zig");
964
+ // Declared columns are engine input (never validator-bounded): the
965
+ // additive ceil-div `(count + columns - 1) / columns` would overflow
966
+ // in safe builds for a huge but valid usize. A few children under
967
+ // maxInt columns is one row, not a panic.
968
+ const huge = std.math.maxInt(usize);
969
+ try std.testing.expectEqual(@as(usize, 1), widget_tree.gridRowCount(3, huge));
970
+ try std.testing.expectEqual(@as(usize, 1), widget_tree.gridRowCount(1, huge));
971
+ // Zero children (or zero columns) is zero rows in both paths.
972
+ try std.testing.expectEqual(@as(usize, 0), widget_tree.gridRowCount(0, huge));
973
+ try std.testing.expectEqual(@as(usize, 0), widget_tree.gridRowCount(0, 4));
974
+ try std.testing.expectEqual(@as(usize, 0), widget_tree.gridRowCount(5, 0));
975
+ // The ordinary shape still ceil-divides: 5 children over 2 columns
976
+ // is 3 rows.
977
+ try std.testing.expectEqual(@as(usize, 3), widget_tree.gridRowCount(5, 2));
978
+ try std.testing.expectEqual(@as(usize, 2), widget_tree.gridRowCount(4, 2));
979
+ }
980
+
981
+ test "nested widget grid with a huge declared column count measures intrinsically" {
982
+ // The root-grid case above never runs the INTRINSIC path: only a
983
+ // parent that measures its children (a column sizing an unframed
984
+ // child) reaches intrinsicGridChildrenSize, where the row math must
985
+ // be the same overflow-safe helper — the additive ceil-div panicked
986
+ // here while the placement path was already fixed.
987
+ const tiles = [_]Widget{
988
+ .{ .id = 3, .kind = .text, .text = "One" },
989
+ .{ .id = 4, .kind = .text, .text = "Two" },
990
+ .{ .id = 5, .kind = .text, .text = "Three" },
991
+ };
992
+ const grid = Widget{
993
+ .id = 2,
994
+ .kind = .grid,
995
+ .layout = .{ .gap = 8, .columns = std.math.maxInt(usize) },
996
+ .children = &tiles,
997
+ };
998
+ const column = Widget{
999
+ .id = 1,
1000
+ .kind = .column,
1001
+ .children = &[_]Widget{grid},
1002
+ };
1003
+
1004
+ // The direct measurement: three children under maxInt columns is
1005
+ // ONE row, so the grid's intrinsic height is one cell (no row gap).
1006
+ const cell = support.intrinsicWidgetSize(tiles[0], .{});
1007
+ const intrinsic = support.intrinsicWidgetSize(grid, .{});
1008
+ try std.testing.expectEqual(cell.height, intrinsic.height);
1009
+
1010
+ // And the full pass: the column measures the unframed grid child
1011
+ // intrinsically while laying out — no panic, one grid row.
1012
+ var nodes: [8]WidgetLayoutNode = undefined;
1013
+ const layout = try layoutWidgetTree(column, geometry.RectF.init(0, 0, 400, 120), &nodes);
1014
+ try std.testing.expectEqual(@as(usize, 5), layout.nodeCount());
1015
+ const first = layout.findById(3).?;
1016
+ const last = layout.findById(5).?;
1017
+ try std.testing.expectEqual(first.frame.y, last.frame.y);
1018
+ }
1019
+
938
1020
  test "widget virtualized grid lays out visible cells by row" {
939
1021
  const children = [_]Widget{
940
1022
  .{ .id = 2, .kind = .button, .text = "Zero" },
@@ -217,14 +217,26 @@ pub fn isWidgetConcealedByDisclosure(layout: anytype, node_index: usize) bool {
217
217
  return false;
218
218
  }
219
219
 
220
+ /// The column count a grid lays out, measures, and reports: the DECLARED
221
+ /// count when one is set — even when fewer children remain (a filtered
222
+ /// grid keeps its column-slot geometry; children fill the leading slots
223
+ /// and the trailing slots stay empty, they never stretch to fill missing
224
+ /// columns) — and one column per child when unset (the single-row grid).
220
225
  pub fn gridColumnCount(child_count: usize, requested_columns: usize) usize {
221
226
  if (child_count == 0) return 0;
222
- return if (requested_columns > 0) @min(requested_columns, child_count) else child_count;
227
+ return if (requested_columns > 0) requested_columns else child_count;
223
228
  }
224
229
 
230
+ /// The row count those columns yield: ceil-division stated as
231
+ /// `1 + (count - 1) / columns` rather than the additive
232
+ /// `(count + columns - 1) / columns` — a declared column count is
233
+ /// engine input (never validator-bounded), so `columns` may be any
234
+ /// usize, including values where the additive form's sum overflows in
235
+ /// safe builds. Both the layout and intrinsic-size paths share this
236
+ /// helper.
225
237
  pub fn gridRowCount(child_count: usize, columns: usize) usize {
226
238
  if (child_count == 0 or columns == 0) return 0;
227
- return (child_count + columns - 1) / columns;
239
+ return 1 + (child_count - 1) / columns;
228
240
  }
229
241
 
230
242
  pub fn saturatingU32(value: usize) u32 {
@@ -841,6 +841,18 @@ pub const Widget = struct {
841
841
  /// origin: mounts land at their value, exactly as before. Ignored
842
842
  /// on splits that already have a retained fraction.
843
843
  resize_origin: f32 = -1,
844
+ /// Hover-intent show delay for an ANCHORED `.tooltip` widget
845
+ /// (`tooltip_delay:` in the builder, `tooltip-delay=` in markup),
846
+ /// in milliseconds. An anchored tooltip is runtime-owned hover
847
+ /// chrome: it stays hidden until its trigger (the anchor parent's
848
+ /// subtree) has been hovered this long on the recorded frame
849
+ /// clock, shows while the hover holds, and hides when the pointer
850
+ /// leaves — the model never hears hover. 0 shows the instant the
851
+ /// trigger is hovered. Negative (the default) follows the token
852
+ /// default (`ControlMetricTokens.tooltip_show_delay_ms`). Ignored
853
+ /// on every other kind, and on tooltips without an anchor (those
854
+ /// stay static leaves that paint whenever the view renders them).
855
+ tooltip_delay_ms: i32 = -1,
844
856
  /// Window-drag surface (`window-drag="true"` / `.window_drag`): a
845
857
  /// pointer press that lands here — or falls through plain text /
846
858
  /// icons / decorations onto it — moves the WINDOW instead of