@native-sdk/cli 0.5.0 → 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.
- package/build/app.zig +198 -13
- package/build/ts_run.mjs +58 -19
- package/build.zig +42 -0
- package/package.json +13 -9
- package/packages/core/package-lock.json +4 -3
- package/packages/core/package.json +3 -2
- package/packages/core/src/typed_ast.ts +11 -1
- package/skill-data/native-ui/SKILL.md +2 -2
- package/src/platform/types.zig +9 -0
- package/src/platform/windows/webview2_host.cpp +24 -0
- package/src/primitives/canvas/layout_audit.zig +5 -5
- package/src/primitives/canvas/root.zig +6 -0
- package/src/primitives/canvas/tokens.zig +185 -7
- package/src/primitives/canvas/ui.zig +27 -5
- package/src/primitives/canvas/ui_markup.zig +27 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +47 -0
- package/src/primitives/canvas/ui_markup_view.zig +10 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
- package/src/primitives/canvas/ui_schema.zig +15 -1
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_builtin_tests.zig +439 -5
- package/src/primitives/canvas/widget_layout.zig +142 -3
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_metrics.zig +16 -8
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +12 -0
- package/src/runtime/automation_widget_dispatch.zig +95 -28
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_events.zig +1271 -3
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +82 -5
- package/src/runtime/core.zig +30 -0
- package/src/runtime/effects.zig +1037 -133
- package/src/runtime/effects_fetch_tests.zig +42 -0
- package/src/runtime/effects_file_tests.zig +220 -0
- package/src/runtime/effects_tests.zig +287 -0
- package/src/runtime/flow.zig +24 -1
- package/src/runtime/gpu_surface_events.zig +44 -5
- package/src/runtime/session_journal.zig +25 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +453 -0
- package/src/runtime/ui_app.zig +137 -39
- package/src/runtime/ui_app_tests.zig +681 -0
- package/src/runtime/ui_app_window_tests.zig +182 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
- package/src/tooling/package.zig +311 -8
- package/src/tooling/templates.zig +97 -9
- package/src/tooling/ts_core.zig +626 -13
- package/src/tooling/verbs.zig +88 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
2
3
|
const canvas = @import("root.zig");
|
|
3
4
|
const text_metrics = @import("text_metrics.zig");
|
|
4
5
|
const geist_theme = @import("themes/geist.zig");
|
|
@@ -548,6 +549,26 @@ pub const ControlMetricTokens = struct {
|
|
|
548
549
|
/// cycle is part of the register's identity, and reduced motion
|
|
549
550
|
/// already gates the loop through `MotionTokens` upstream.
|
|
550
551
|
spinner_period_ms: u32 = 1000,
|
|
552
|
+
/// Hover-intent show delay for ANCHORED tooltips, in milliseconds:
|
|
553
|
+
/// the runtime shows an anchored tooltip only after its trigger has
|
|
554
|
+
/// been hovered this long on the recorded frame clock, so sweeping
|
|
555
|
+
/// a dense toolbar never flashes every tooltip. Per-tooltip markup
|
|
556
|
+
/// (`tooltip-delay=`) and the builder (`tooltip_delay:`) override
|
|
557
|
+
/// it; 0 shows the instant the trigger is hovered. Kept with the
|
|
558
|
+
/// behavior metrics (like `spinner_period_ms`) because hover intent
|
|
559
|
+
/// is part of the tooltip register's identity, not the motion
|
|
560
|
+
/// ladder. 600ms is shadcn's Base UI-backed default trigger delay.
|
|
561
|
+
tooltip_show_delay_ms: u32 = 600,
|
|
562
|
+
/// The shared warm window after a pointer-hovered tooltip hides on
|
|
563
|
+
/// pointer leave (focus departure, Escape, presses, and view blur
|
|
564
|
+
/// deliberately do not warm): moving
|
|
565
|
+
/// to another tooltip trigger within this many milliseconds shows
|
|
566
|
+
/// its tooltip immediately (no delay) and re-warms on the next
|
|
567
|
+
/// hide — the skip-delay polish that makes sweeping a toolbar of
|
|
568
|
+
/// already-explained controls feel right. View-wide by design, not
|
|
569
|
+
/// per-tooltip: the warmth belongs to the pointer, not the widget.
|
|
570
|
+
/// 400ms is shadcn's Base UI-backed default provider timeout.
|
|
571
|
+
tooltip_warm_window_ms: u32 = 400,
|
|
551
572
|
};
|
|
552
573
|
|
|
553
574
|
pub const ShadowToken = struct {
|
|
@@ -1196,6 +1217,8 @@ pub const ControlMetricTokenOverrides = struct {
|
|
|
1196
1217
|
spinner_segment_radius_ratio: ?f32 = null,
|
|
1197
1218
|
spinner_tail_opacity: ?f32 = null,
|
|
1198
1219
|
spinner_period_ms: ?u32 = null,
|
|
1220
|
+
tooltip_show_delay_ms: ?u32 = null,
|
|
1221
|
+
tooltip_warm_window_ms: ?u32 = null,
|
|
1199
1222
|
|
|
1200
1223
|
pub fn apply(self: ControlMetricTokenOverrides, base: ControlMetricTokens) ControlMetricTokens {
|
|
1201
1224
|
return applyFlatTokenOverrides(ControlMetricTokens, base, self);
|
|
@@ -1436,7 +1459,11 @@ pub const ControlTokenOverrides = struct {
|
|
|
1436
1459
|
/// both schemes without a second manifest knob.
|
|
1437
1460
|
/// - `colors.focus_ring`: packs spend their identity hue on focus; with
|
|
1438
1461
|
/// the identity moved, the ring follows so focus and accent chrome
|
|
1439
|
-
/// read as one system.
|
|
1462
|
+
/// read as one system. The ring is stated PER SCHEME
|
|
1463
|
+
/// (`accentFocusRing`): the accent itself in light, a desaturated,
|
|
1464
|
+
/// contrast-floored step of it in dark — a full-chroma brand hue
|
|
1465
|
+
/// glares neon against a dark palette, so the bundle takes the scheme
|
|
1466
|
+
/// it layers over.
|
|
1440
1467
|
/// - `controls.slider.active_background`: the slider table states its
|
|
1441
1468
|
/// own hue for the filled range rather than deriving from the accent
|
|
1442
1469
|
/// channel, so the same move is stated once more or a seek scrubber
|
|
@@ -1445,12 +1472,12 @@ pub const ControlTokenOverrides = struct {
|
|
|
1445
1472
|
/// High-contrast composition is the CALLER's rule (accessibility beats
|
|
1446
1473
|
/// brand): the runtime skips this bundle when the system asks for high
|
|
1447
1474
|
/// contrast, taking the pack's own loud register untouched.
|
|
1448
|
-
pub fn accentOverrides(accent: Color) DesignTokenOverrides {
|
|
1475
|
+
pub fn accentOverrides(accent: Color, color_scheme: ColorScheme) DesignTokenOverrides {
|
|
1449
1476
|
return .{
|
|
1450
1477
|
.colors = .{
|
|
1451
1478
|
.accent = accent,
|
|
1452
1479
|
.accent_text = accentKnockoutInk(accent),
|
|
1453
|
-
.focus_ring = accent,
|
|
1480
|
+
.focus_ring = accentFocusRing(accent, color_scheme),
|
|
1454
1481
|
},
|
|
1455
1482
|
.controls = .{
|
|
1456
1483
|
.slider = .{ .active_background = accent },
|
|
@@ -1458,17 +1485,154 @@ pub fn accentOverrides(accent: Color) DesignTokenOverrides {
|
|
|
1458
1485
|
};
|
|
1459
1486
|
}
|
|
1460
1487
|
|
|
1488
|
+
/// The focus ring an accent identity carries, per scheme: the accent
|
|
1489
|
+
/// itself in light, and in dark a desaturated step of it that still
|
|
1490
|
+
/// CLEARS the ring's contrast bar. Dark surfaces amplify chroma, so the
|
|
1491
|
+
/// raw brand hue reads neon where the ring should stay a quiet outline;
|
|
1492
|
+
/// halving HSL saturation settles it — but desaturation does not
|
|
1493
|
+
/// preserve luminance (a deep green loses a third of its light to the
|
|
1494
|
+
/// halved chroma), so the settled ring is then contrast-floored: its
|
|
1495
|
+
/// HSL lightness rises until it holds 3:1 (WCAG 1.4.11 non-text)
|
|
1496
|
+
/// against the LIGHTEST dark tone controls commonly sit on
|
|
1497
|
+
/// (`lightest_dark_adjacent_tone`) whenever the accent itself cleared
|
|
1498
|
+
/// that bar there, and never lands below the accent's OWN contrast
|
|
1499
|
+
/// (against that same tone) when it did not — the floor restores what
|
|
1500
|
+
/// desaturation cost, it never invents contrast the brand hue never
|
|
1501
|
+
/// had. Contrast against a DARKER tone is always higher for a light
|
|
1502
|
+
/// ring, so clearing the lightest adjacent tone clears every darker
|
|
1503
|
+
/// one — background and card surface included — in both shipped packs.
|
|
1504
|
+
/// Exported so hand-authored token sets can state the identical
|
|
1505
|
+
/// derivation and stay in step with the manifest channel.
|
|
1506
|
+
pub fn accentFocusRing(accent: Color, color_scheme: ColorScheme) Color {
|
|
1507
|
+
return switch (color_scheme) {
|
|
1508
|
+
.light => accent,
|
|
1509
|
+
.dark => darkAccentFocusRing(accent),
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/// The tone `accentFocusRing`'s dark contrast floor measures against:
|
|
1514
|
+
/// the LIGHTEST of the dark tones controls commonly sit on across the
|
|
1515
|
+
/// shipped packs — rings draw OUTSIDE controls, so the tone that
|
|
1516
|
+
/// matters is the container behind the control, and lighter dark tones
|
|
1517
|
+
/// are the more demanding reference. The set, per pack:
|
|
1518
|
+
///
|
|
1519
|
+
/// - house dark: `background` #0a0a0a (the page), `surface` #171717
|
|
1520
|
+
/// (cards, popovers, menus), `surface_subtle` #262626 (muted chrome —
|
|
1521
|
+
/// the tabs-list pill container focusable triggers sit inside);
|
|
1522
|
+
/// - Geist dark: `background`/`surface` #000000, `surface_subtle`
|
|
1523
|
+
/// #1a1a1a.
|
|
1524
|
+
///
|
|
1525
|
+
/// The house `surface_subtle` is the lightest of the set, so a ring
|
|
1526
|
+
/// clearing 3:1 there clears it on every other tone controls sit on in
|
|
1527
|
+
/// both packs (contrast against a darker tone is strictly higher for a
|
|
1528
|
+
/// ring lighter than all of them).
|
|
1529
|
+
const lightest_dark_adjacent_tone: Color = ColorTokens.dark().surface_subtle;
|
|
1530
|
+
|
|
1531
|
+
fn darkAccentFocusRing(accent: Color) Color {
|
|
1532
|
+
// Apps resolve palettes as container-level consts (the soundboard's
|
|
1533
|
+
// `dark_colors`), so this runs at comptime too: the lightness
|
|
1534
|
+
// search's srgb pow calls need more than the default branch quota.
|
|
1535
|
+
if (@inComptime()) @setEvalBranchQuota(1_000_000);
|
|
1536
|
+
const desaturated = scaleSaturation(accent, 0.5);
|
|
1537
|
+
const surface_luminance = relativeLuminance(lightest_dark_adjacent_tone);
|
|
1538
|
+
const accent_contrast = contrastRatio(relativeLuminance(accent), surface_luminance);
|
|
1539
|
+
const floor = @min(3.0, accent_contrast);
|
|
1540
|
+
if (contrastRatio(relativeLuminance(desaturated), surface_luminance) >= floor) return desaturated;
|
|
1541
|
+
// Solve the floor for the luminance it demands — (L + 0.05) /
|
|
1542
|
+
// (Ls + 0.05) ≥ floor — and lift the desaturated ring's lightness
|
|
1543
|
+
// to reach it. The epsilon absorbs the HSL roundtrip's f32 error so
|
|
1544
|
+
// the returned ring measures at the floor, never a hair under it.
|
|
1545
|
+
const needed_luminance = floor * (surface_luminance + 0.05) - 0.05 + 0.0001;
|
|
1546
|
+
return lightenToLuminance(desaturated, needed_luminance);
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
const Hsl = struct { hue: f32, saturation: f32, lightness: f32 };
|
|
1550
|
+
|
|
1551
|
+
fn rgbToHsl(color: Color) Hsl {
|
|
1552
|
+
const max = @max(color.r, @max(color.g, color.b));
|
|
1553
|
+
const min = @min(color.r, @min(color.g, color.b));
|
|
1554
|
+
const lightness = (max + min) / 2;
|
|
1555
|
+
const delta = max - min;
|
|
1556
|
+
if (delta <= 0.0001) return .{ .hue = 0, .saturation = 0, .lightness = lightness };
|
|
1557
|
+
const saturation = delta / (1 - @abs(2 * lightness - 1));
|
|
1558
|
+
const hue: f32 = if (max == color.r)
|
|
1559
|
+
60 * @mod((color.g - color.b) / delta, 6)
|
|
1560
|
+
else if (max == color.g)
|
|
1561
|
+
60 * ((color.b - color.r) / delta + 2)
|
|
1562
|
+
else
|
|
1563
|
+
60 * ((color.r - color.g) / delta + 4);
|
|
1564
|
+
return .{ .hue = hue, .saturation = saturation, .lightness = lightness };
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
fn hslToRgb(hsl: Hsl, alpha: f32) Color {
|
|
1568
|
+
const chroma = (1 - @abs(2 * hsl.lightness - 1)) * hsl.saturation;
|
|
1569
|
+
const x = chroma * (1 - @abs(@mod(hsl.hue / 60, 2) - 1));
|
|
1570
|
+
const base = hsl.lightness - chroma / 2;
|
|
1571
|
+
const sector: u3 = @intFromFloat(@min(5, @floor(hsl.hue / 60)));
|
|
1572
|
+
const rgb: [3]f32 = switch (sector) {
|
|
1573
|
+
0 => .{ chroma, x, 0 },
|
|
1574
|
+
1 => .{ x, chroma, 0 },
|
|
1575
|
+
2 => .{ 0, chroma, x },
|
|
1576
|
+
3 => .{ 0, x, chroma },
|
|
1577
|
+
4 => .{ x, 0, chroma },
|
|
1578
|
+
else => .{ chroma, 0, x },
|
|
1579
|
+
};
|
|
1580
|
+
return .{ .r = rgb[0] + base, .g = rgb[1] + base, .b = rgb[2] + base, .a = alpha };
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
/// Scale a color's HSL saturation, keeping hue, lightness, and alpha.
|
|
1584
|
+
/// Achromatic colors pass through untouched (no hue to keep).
|
|
1585
|
+
fn scaleSaturation(color: Color, factor: f32) Color {
|
|
1586
|
+
const hsl = rgbToHsl(color);
|
|
1587
|
+
if (hsl.saturation == 0) return color;
|
|
1588
|
+
return hslToRgb(.{
|
|
1589
|
+
.hue = hsl.hue,
|
|
1590
|
+
.saturation = std.math.clamp(hsl.saturation * factor, 0, 1),
|
|
1591
|
+
.lightness = hsl.lightness,
|
|
1592
|
+
}, color.a);
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/// Raise a color's HSL lightness (hue and saturation held) until its
|
|
1596
|
+
/// relative luminance reaches `minimum_luminance`. Luminance rises
|
|
1597
|
+
/// monotonically with HSL lightness at fixed hue and saturation, so a
|
|
1598
|
+
/// binary search converges; white (lightness 1, luminance 1) bounds the
|
|
1599
|
+
/// search and clears any reachable floor.
|
|
1600
|
+
fn lightenToLuminance(color: Color, minimum_luminance: f32) Color {
|
|
1601
|
+
if (relativeLuminance(color) >= minimum_luminance) return color;
|
|
1602
|
+
var hsl = rgbToHsl(color);
|
|
1603
|
+
var low = hsl.lightness;
|
|
1604
|
+
var high: f32 = 1;
|
|
1605
|
+
for (0..24) |_| {
|
|
1606
|
+
const mid = (low + high) / 2;
|
|
1607
|
+
hsl.lightness = mid;
|
|
1608
|
+
if (relativeLuminance(hslToRgb(hsl, color.a)) < minimum_luminance) low = mid else high = mid;
|
|
1609
|
+
}
|
|
1610
|
+
hsl.lightness = high;
|
|
1611
|
+
return hslToRgb(hsl, color.a);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
/// WCAG relative luminance of a color's sRGB channels (alpha ignored).
|
|
1615
|
+
fn relativeLuminance(color: Color) f32 {
|
|
1616
|
+
return 0.2126 * srgbToLinear(color.r) +
|
|
1617
|
+
0.7152 * srgbToLinear(color.g) +
|
|
1618
|
+
0.0722 * srgbToLinear(color.b);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
/// WCAG contrast ratio between two relative luminances.
|
|
1622
|
+
fn contrastRatio(luminance_a: f32, luminance_b: f32) f32 {
|
|
1623
|
+
const lighter = @max(luminance_a, luminance_b);
|
|
1624
|
+
const darker = @min(luminance_a, luminance_b);
|
|
1625
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1461
1628
|
/// The readable knockout ink over one accent fill: WHITE whenever it
|
|
1462
1629
|
/// clears the 4.5:1 text bar over the accent (the ink packs pair with
|
|
1463
1630
|
/// every solid identity fill — the convention brands expect), and the
|
|
1464
1631
|
/// near-black text ink only when the accent is light enough that white
|
|
1465
1632
|
/// honestly cannot (1.05 / (L + 0.05) < 4.5).
|
|
1466
1633
|
fn accentKnockoutInk(accent: Color) Color {
|
|
1467
|
-
const luminance = 0.2126 * srgbToLinear(accent.r) +
|
|
1468
|
-
0.7152 * srgbToLinear(accent.g) +
|
|
1469
|
-
0.0722 * srgbToLinear(accent.b);
|
|
1470
1634
|
// White clears 4.5:1 up to L = 1.05/4.5 - 0.05 ≈ 0.18333.
|
|
1471
|
-
if (
|
|
1635
|
+
if (relativeLuminance(accent) <= 0.18333) return Color.rgb8(255, 255, 255);
|
|
1472
1636
|
return Color.rgb8(10, 10, 10);
|
|
1473
1637
|
}
|
|
1474
1638
|
|
|
@@ -1521,6 +1685,20 @@ pub const DesignTokens = struct {
|
|
|
1521
1685
|
/// actually draws. Not themed and not part of overrides: the runtime
|
|
1522
1686
|
/// stamps it after theme resolution.
|
|
1523
1687
|
text_measure: ?*const text_metrics.TextMeasureProvider = null,
|
|
1688
|
+
/// The OS window-control cluster's frame in the canvas's local
|
|
1689
|
+
/// coordinates (Windows: the DWM min/max/close buttons on the
|
|
1690
|
+
/// trailing edge; macOS: the traffic lights on the leading edge),
|
|
1691
|
+
/// for hidden-titlebar windows whose content extends under the
|
|
1692
|
+
/// band. Null (the default) lays out exactly as before. The runtime
|
|
1693
|
+
/// stamps it — like `text_measure`, never themed and not part of
|
|
1694
|
+
/// overrides — and only after a build proved the app's own drag
|
|
1695
|
+
/// header left content UNDER the cluster (an app that already pads
|
|
1696
|
+
/// via the chrome channel's insets keeps its byte-identical
|
|
1697
|
+
/// layout). `window_drag` widgets then lay their content out clear
|
|
1698
|
+
/// of the cluster (`widget_layout.windowControlsClearedContent`),
|
|
1699
|
+
/// so a header that never consumed the chrome insets still keeps
|
|
1700
|
+
/// its trailing status text out from under the caption buttons.
|
|
1701
|
+
window_controls: ?geometry.RectF = null,
|
|
1524
1702
|
|
|
1525
1703
|
pub fn theme(options: ThemeOptions) DesignTokens {
|
|
1526
1704
|
// The pack resolves the register (palette, control tables, and
|
|
@@ -598,6 +598,17 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
598
598
|
/// Negative (the default) declares no origin. Only
|
|
599
599
|
/// meaningful with a nonzero `resize_duration`.
|
|
600
600
|
resize_origin: f32 = -1,
|
|
601
|
+
/// Hover-intent show delay for an ANCHORED tooltip (markup
|
|
602
|
+
/// `tooltip-delay`), in milliseconds: the runtime shows the
|
|
603
|
+
/// tooltip only after its trigger has been hovered this
|
|
604
|
+
/// long on the recorded frame clock. 0 shows the instant
|
|
605
|
+
/// the trigger is hovered. Negative (the default) follows
|
|
606
|
+
/// the token default
|
|
607
|
+
/// (`ControlMetricTokens.tooltip_show_delay_ms`). Only
|
|
608
|
+
/// meaningful on a tooltip with `anchor` — the markup
|
|
609
|
+
/// validator rejects it anywhere else as silently-inert
|
|
610
|
+
/// data.
|
|
611
|
+
tooltip_delay: i32 = -1,
|
|
601
612
|
style: canvas.WidgetStyle = .{},
|
|
602
613
|
/// Named token references resolved against design tokens in
|
|
603
614
|
/// `finalizeWithTokens`; explicit `style` values win.
|
|
@@ -1143,11 +1154,21 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1143
1154
|
if (self.msgFor(target_id, .submit)) |msg| return msg;
|
|
1144
1155
|
}
|
|
1145
1156
|
if (isTextEntryWidget(widget) and !widget.state.disabled) {
|
|
1146
|
-
//
|
|
1147
|
-
//
|
|
1148
|
-
//
|
|
1149
|
-
//
|
|
1150
|
-
|
|
1157
|
+
// Events routed through the runtime arrive with the
|
|
1158
|
+
// edit the retained editor actually applied STAMPED
|
|
1159
|
+
// onto `keyboard.edit` (the runtime's one derivation
|
|
1160
|
+
// seam — Escape's search-field clear, composition
|
|
1161
|
+
// cancels, and clipboard edits all ride it), and
|
|
1162
|
+
// `textEditEvent()` returns the stamp first. The
|
|
1163
|
+
// local derivation below is the fallback for events
|
|
1164
|
+
// that never crossed the runtime (direct Tree
|
|
1165
|
+
// consumers, tests); the textarea newline mapping
|
|
1166
|
+
// resolves BEFORE it because the generic key mapping
|
|
1167
|
+
// has no Enter case.
|
|
1168
|
+
const edit = if (keyboard.edit != null)
|
|
1169
|
+
keyboard.edit
|
|
1170
|
+
else
|
|
1171
|
+
canvas.widgetKeyboardNewlineTextEditEvent(widget.kind, keyboard) orelse keyboard.textEditEvent();
|
|
1151
1172
|
if (edit) |text_edit| {
|
|
1152
1173
|
if (self.msgForTextEdit(target_id, text_edit)) |msg| return msg;
|
|
1153
1174
|
}
|
|
@@ -2687,6 +2708,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2687
2708
|
.resize_duration_ms = options.resize_duration,
|
|
2688
2709
|
.resize_easing = options.resize_easing,
|
|
2689
2710
|
.resize_origin = options.resize_origin,
|
|
2711
|
+
.tooltip_delay_ms = options.tooltip_delay,
|
|
2690
2712
|
};
|
|
2691
2713
|
applyKindDefaultLayout(kind, options, &widget.layout);
|
|
2692
2714
|
return widget;
|
|
@@ -1133,13 +1133,15 @@ pub const known_dismiss_element_names = schema.dismiss_element_names;
|
|
|
1133
1133
|
|
|
1134
1134
|
pub const on_dismiss_element_message = "on-dismiss is only supported on dismissible surfaces (dialog, drawer, sheet, dropdown-menu) - Escape and click-outside dismiss those, and the Msg lets the model own the close (clear the open flag in update)";
|
|
1135
1135
|
|
|
1136
|
-
/// Elements that may float as anchored surfaces. dropdown-menu
|
|
1137
|
-
/// markup
|
|
1138
|
-
/// exclusions) and dialogs/drawers/sheets place themselves.
|
|
1136
|
+
/// Elements that may float as anchored surfaces. dropdown-menu and
|
|
1137
|
+
/// tooltip are the markup channels; popover/menu-surface stay Zig views
|
|
1138
|
+
/// (documented exclusions) and dialogs/drawers/sheets place themselves.
|
|
1139
|
+
/// An anchored tooltip's visibility is RUNTIME-owned (hover intent on
|
|
1140
|
+
/// its trigger), unlike the model-owned dropdown.
|
|
1139
1141
|
/// Registry-derived from the `anchorable` element predicate.
|
|
1140
1142
|
pub const known_anchor_element_names = schema.anchor_element_names;
|
|
1141
1143
|
|
|
1142
|
-
pub const anchor_element_message = "anchor is only supported on dropdown-menu - it floats the surface against its PARENT's frame (put the dropdown beside its trigger inside a stack); dialogs, drawers, and sheets place themselves";
|
|
1144
|
+
pub const anchor_element_message = "anchor is only supported on dropdown-menu and tooltip - it floats the surface against its PARENT's frame (put the dropdown or tooltip beside its trigger inside a stack); dialogs, drawers, and sheets place themselves";
|
|
1143
1145
|
pub const anchor_value_message = "anchor takes a literal placement: below or above (either side flips automatically when the surface does not fit and the other side has more room)";
|
|
1144
1146
|
pub const anchor_alignment_value_message = "anchor-alignment takes a literal alignment: start, end, or stretch (stretch also widens the surface to at least the anchor's width)";
|
|
1145
1147
|
pub const anchor_offset_value_message = "anchor-offset takes a literal number: the gap in points between the anchor edge and the surface";
|
|
@@ -1241,6 +1243,10 @@ pub const resize_origin_element_message = "resize-origin is only supported on sp
|
|
|
1241
1243
|
|
|
1242
1244
|
pub const resize_origin_dependent_attr_message = "resize-origin needs a nonzero resize-duration on the same split - without a duration a mount lands on its value and the origin is silently inert";
|
|
1243
1245
|
|
|
1246
|
+
pub const tooltip_delay_element_message = "tooltip-delay is only supported on tooltip - it sets the hover-intent show delay (milliseconds; 0 shows the instant the trigger is hovered) the runtime waits before showing an ANCHORED tooltip; anywhere else it would be silently inert";
|
|
1247
|
+
|
|
1248
|
+
pub const tooltip_delay_dependent_attr_message = "tooltip-delay needs anchor on the same tooltip - only an anchored tooltip is hover-shown by the runtime (a static tooltip paints whenever the view renders it), so without anchor the delay is silently inert";
|
|
1249
|
+
|
|
1244
1250
|
pub const avatar_image_message = "image takes one {binding} to a u64 ImageId the app registered at runtime (fx.registerImageBytes) - runtime image ids are model data, not markup literals; 0 renders the initials fallback";
|
|
1245
1251
|
pub const avatar_image_element_message = "image is only supported on avatar - the other image-bearing widgets (image, icon-button) stay Zig views (ui.image with ElementOptions.image)";
|
|
1246
1252
|
|
|
@@ -3211,6 +3217,23 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
3211
3217
|
}
|
|
3212
3218
|
}
|
|
3213
3219
|
}
|
|
3220
|
+
if (std.mem.eql(u8, attribute.name, "tooltip-delay")) {
|
|
3221
|
+
// Hover intent exists only where the runtime owns
|
|
3222
|
+
// visibility: anywhere but a tooltip the delay is
|
|
3223
|
+
// silently inert (same policy as resize-duration
|
|
3224
|
+
// off split).
|
|
3225
|
+
if (!std.mem.eql(u8, node.name, "tooltip")) {
|
|
3226
|
+
return attrError(node, attribute, tooltip_delay_element_message);
|
|
3227
|
+
}
|
|
3228
|
+
// The delay shapes a hover-show that exists only on
|
|
3229
|
+
// an ANCHORED tooltip: a static tooltip paints
|
|
3230
|
+
// whenever the view renders it, so a delay beside
|
|
3231
|
+
// no anchor is silently inert — a teaching error
|
|
3232
|
+
// (the anchor-alignment-without-anchor policy).
|
|
3233
|
+
if (node.attr("anchor") == null) {
|
|
3234
|
+
return attrError(node, attribute, tooltip_delay_dependent_attr_message);
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3214
3237
|
if (std.mem.eql(u8, attribute.name, "size")) {
|
|
3215
3238
|
// The size register's closed literal vocabulary
|
|
3216
3239
|
// (bindings resolve at build): the control scale
|
|
@@ -1732,8 +1732,16 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1732
1732
|
.optional => @field(options, zig_field) = evalExpr(node, entries, raw, ui, model, scope).truthy(),
|
|
1733
1733
|
.int => {
|
|
1734
1734
|
comptime requireVariant(variant, &.{.integer}, node, "expected a whole number");
|
|
1735
|
+
// Range-checked against the field's own integer type
|
|
1736
|
+
// before the cast (the grid-lines pattern; the
|
|
1737
|
+
// interpreter fails the same way): expression values
|
|
1738
|
+
// are i64, so a literal or model binding can deliver
|
|
1739
|
+
// 2147483648 to the i32 tooltip-delay — an unchecked
|
|
1740
|
+
// @intCast TRAPPED on it instead of failing the
|
|
1741
|
+
// build. The field type is the honest upper bound;
|
|
1742
|
+
// no semantic cap is invented on top of it.
|
|
1735
1743
|
@field(options, zig_field) = switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
1736
|
-
.integer => |int| if (int < 0) runtimeFail(FieldType, ui) else @intCast(int),
|
|
1744
|
+
.integer => |int| if (int < 0 or int > std.math.maxInt(FieldType)) runtimeFail(FieldType, ui) else @intCast(int),
|
|
1737
1745
|
else => runtimeFail(FieldType, ui),
|
|
1738
1746
|
};
|
|
1739
1747
|
},
|
|
@@ -479,6 +479,133 @@ test "compiled split tween pair lowers into the layout-tween declaration identic
|
|
|
479
479
|
try testing.expectEqual(interpreted_split.value, compiled_split.value);
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
+
// ---------------------------------------- anchored-tooltip intent parity
|
|
483
|
+
|
|
484
|
+
const tooltip_intent_markup =
|
|
485
|
+
\\<column gap="12">
|
|
486
|
+
\\ <stack>
|
|
487
|
+
\\ <text>Bold</text>
|
|
488
|
+
\\ <tooltip anchor="above" tooltip-delay="250">Bold the selection</tooltip>
|
|
489
|
+
\\ </stack>
|
|
490
|
+
\\ <stack>
|
|
491
|
+
\\ <text>Link</text>
|
|
492
|
+
\\ <tooltip anchor="below" anchor-offset="8">Insert a link</tooltip>
|
|
493
|
+
\\ </stack>
|
|
494
|
+
\\ <tooltip>Copied!</tooltip>
|
|
495
|
+
\\</column>
|
|
496
|
+
;
|
|
497
|
+
|
|
498
|
+
const TooltipIntentCompiled = canvas.CompiledMarkupView(EntriesModel, EntriesMsg, tooltip_intent_markup);
|
|
499
|
+
|
|
500
|
+
test "compiled anchored tooltips stamp the hover-intent declaration identically to the interpreter" {
|
|
501
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
502
|
+
defer arena_state.deinit();
|
|
503
|
+
const arena = arena_state.allocator();
|
|
504
|
+
|
|
505
|
+
const entries = [_]Entry{.{ .id = 11, .label = "first" }};
|
|
506
|
+
const model = EntriesModel{ .entries = &entries };
|
|
507
|
+
|
|
508
|
+
var view = try markup_view.MarkupView(EntriesModel, EntriesMsg).init(arena, tooltip_intent_markup);
|
|
509
|
+
var interpreter_ui = EntriesUi.init(arena);
|
|
510
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
511
|
+
var compiled_ui = EntriesUi.init(arena);
|
|
512
|
+
const compiled = try compiled_ui.finalize(TooltipIntentCompiled.build(&compiled_ui, &model));
|
|
513
|
+
try expectSameTree(EntriesMsg, interpreted, compiled);
|
|
514
|
+
|
|
515
|
+
// Both engines stamp the declaration the runtime's hover-intent
|
|
516
|
+
// machine reads: the anchor floats the leaf against its parent, and
|
|
517
|
+
// tooltip-delay overrides the token default (-1 keeps it). The bare
|
|
518
|
+
// static tooltip keeps null anchor and the -1 default, so existing
|
|
519
|
+
// documents lower byte-identically.
|
|
520
|
+
inline for (.{ interpreted.root, compiled.root }) |root| {
|
|
521
|
+
const declared = fixture.findByText(root, .tooltip, "Bold the selection").?;
|
|
522
|
+
try testing.expectEqual(@as(i32, 250), declared.tooltip_delay_ms);
|
|
523
|
+
try testing.expectEqual(canvas.WidgetAnchorPlacement.above, declared.layout.anchor.?.placement);
|
|
524
|
+
|
|
525
|
+
const defaulted = fixture.findByText(root, .tooltip, "Insert a link").?;
|
|
526
|
+
try testing.expectEqual(@as(i32, -1), defaulted.tooltip_delay_ms);
|
|
527
|
+
try testing.expectEqual(canvas.WidgetAnchorPlacement.below, defaulted.layout.anchor.?.placement);
|
|
528
|
+
try testing.expectEqual(@as(f32, 8), defaulted.layout.anchor.?.offset);
|
|
529
|
+
|
|
530
|
+
const static = fixture.findByText(root, .tooltip, "Copied!").?;
|
|
531
|
+
try testing.expectEqual(@as(i32, -1), static.tooltip_delay_ms);
|
|
532
|
+
try testing.expectEqual(@as(?canvas.WidgetAnchor, null), static.layout.anchor);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// ------------------------------------------- tooltip-delay range guard
|
|
537
|
+
|
|
538
|
+
const TooltipDelayModel = struct { delay: i64 = 0 };
|
|
539
|
+
|
|
540
|
+
const tooltip_delay_binding_markup =
|
|
541
|
+
\\<stack>
|
|
542
|
+
\\ <text>Bold</text>
|
|
543
|
+
\\ <tooltip anchor="above" tooltip-delay="{delay}">Bold the selection</tooltip>
|
|
544
|
+
\\</stack>
|
|
545
|
+
;
|
|
546
|
+
|
|
547
|
+
const tooltip_delay_boundary_markup =
|
|
548
|
+
\\<column gap="12">
|
|
549
|
+
\\ <stack>
|
|
550
|
+
\\ <text>Bold</text>
|
|
551
|
+
\\ <tooltip anchor="above" tooltip-delay="0">Bold the selection</tooltip>
|
|
552
|
+
\\ </stack>
|
|
553
|
+
\\ <stack>
|
|
554
|
+
\\ <text>Link</text>
|
|
555
|
+
\\ <tooltip anchor="below" tooltip-delay="2147483647">Insert a link</tooltip>
|
|
556
|
+
\\ </stack>
|
|
557
|
+
\\</column>
|
|
558
|
+
;
|
|
559
|
+
|
|
560
|
+
const tooltip_delay_overflow_literal_markup =
|
|
561
|
+
\\<stack>
|
|
562
|
+
\\ <text>Bold</text>
|
|
563
|
+
\\ <tooltip anchor="above" tooltip-delay="2147483648">Bold the selection</tooltip>
|
|
564
|
+
\\</stack>
|
|
565
|
+
;
|
|
566
|
+
|
|
567
|
+
const TooltipDelayUi = canvas.Ui(EntriesMsg);
|
|
568
|
+
const TooltipDelayBindingCompiled = canvas.CompiledMarkupView(TooltipDelayModel, EntriesMsg, tooltip_delay_binding_markup);
|
|
569
|
+
const TooltipDelayBoundaryCompiled = canvas.CompiledMarkupView(TooltipDelayModel, EntriesMsg, tooltip_delay_boundary_markup);
|
|
570
|
+
const TooltipDelayOverflowLiteralCompiled = canvas.CompiledMarkupView(TooltipDelayModel, EntriesMsg, tooltip_delay_overflow_literal_markup);
|
|
571
|
+
|
|
572
|
+
test "compiled tooltip-delay past i32 max fails the build instead of trapping" {
|
|
573
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
574
|
+
defer arena_state.deinit();
|
|
575
|
+
const arena = arena_state.allocator();
|
|
576
|
+
|
|
577
|
+
// A literal one past maxInt(i32): the option field's own type is
|
|
578
|
+
// the bound (the grid-lines pattern), so the cast that used to
|
|
579
|
+
// trap latches the failed build the interpreter's teaching error
|
|
580
|
+
// mirrors, and finalize surfaces it.
|
|
581
|
+
var literal_ui = TooltipDelayUi.init(arena);
|
|
582
|
+
const literal_node = TooltipDelayOverflowLiteralCompiled.build(&literal_ui, &TooltipDelayModel{});
|
|
583
|
+
try testing.expect(literal_ui.failed);
|
|
584
|
+
try testing.expectError(error.OutOfMemory, literal_ui.finalize(literal_node));
|
|
585
|
+
|
|
586
|
+
// Bindings deliver i64 model values into the same cast seam, so an
|
|
587
|
+
// out-of-range model value fails the same way — per-build, since
|
|
588
|
+
// only the value (not the document) is wrong.
|
|
589
|
+
var overflow_ui = TooltipDelayUi.init(arena);
|
|
590
|
+
const overflow_model = TooltipDelayModel{ .delay = @as(i64, std.math.maxInt(i32)) + 1 };
|
|
591
|
+
const overflow_node = TooltipDelayBindingCompiled.build(&overflow_ui, &overflow_model);
|
|
592
|
+
try testing.expect(overflow_ui.failed);
|
|
593
|
+
try testing.expectError(error.OutOfMemory, overflow_ui.finalize(overflow_node));
|
|
594
|
+
|
|
595
|
+
// The same document lowers when the model holds an in-range value.
|
|
596
|
+
var ok_ui = TooltipDelayUi.init(arena);
|
|
597
|
+
const ok_model = TooltipDelayModel{ .delay = 250 };
|
|
598
|
+
const ok_tree = try ok_ui.finalize(TooltipDelayBindingCompiled.build(&ok_ui, &ok_model));
|
|
599
|
+
try testing.expectEqual(@as(i32, 250), fixture.findByText(ok_tree.root, .tooltip, "Bold the selection").?.tooltip_delay_ms);
|
|
600
|
+
|
|
601
|
+
// Boundary values pass: 0 (the instant-show escape hatch) and the
|
|
602
|
+
// type's exact max.
|
|
603
|
+
var boundary_ui = TooltipDelayUi.init(arena);
|
|
604
|
+
const boundary_tree = try boundary_ui.finalize(TooltipDelayBoundaryCompiled.build(&boundary_ui, &TooltipDelayModel{}));
|
|
605
|
+
try testing.expectEqual(@as(i32, 0), fixture.findByText(boundary_tree.root, .tooltip, "Bold the selection").?.tooltip_delay_ms);
|
|
606
|
+
try testing.expectEqual(@as(i32, std.math.maxInt(i32)), fixture.findByText(boundary_tree.root, .tooltip, "Insert a link").?.tooltip_delay_ms);
|
|
607
|
+
}
|
|
608
|
+
|
|
482
609
|
// --------------------- multi-child for bodies and the for-empty else
|
|
483
610
|
|
|
484
611
|
const multi_entries_markup =
|
|
@@ -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),
|