@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,14 +32,14 @@
32
32
  "@typescript/typescript6": "6.0.2"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@native-sdk/cli-darwin-arm64": "0.5.1",
36
- "@native-sdk/cli-darwin-x64": "0.5.1",
37
- "@native-sdk/cli-linux-arm64-gnu": "0.5.1",
38
- "@native-sdk/cli-linux-arm64-musl": "0.5.1",
39
- "@native-sdk/cli-linux-x64-gnu": "0.5.1",
40
- "@native-sdk/cli-linux-x64-musl": "0.5.1",
41
- "@native-sdk/cli-win32-arm64": "0.5.1",
42
- "@native-sdk/cli-win32-x64": "0.5.1"
35
+ "@native-sdk/cli-darwin-arm64": "0.5.2",
36
+ "@native-sdk/cli-darwin-x64": "0.5.2",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.5.2",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.5.2",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.5.2",
40
+ "@native-sdk/cli-linux-x64-musl": "0.5.2",
41
+ "@native-sdk/cli-win32-arm64": "0.5.2",
42
+ "@native-sdk/cli-win32-x64": "0.5.2"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.5.1",
9
+ "version": "0.5.2",
10
10
  "devDependencies": {
11
11
  "@typescript/old": "npm:typescript@6.0.3",
12
12
  "@typescript/typescript6": "6.0.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -171,7 +171,7 @@ Automation drives the native path honestly: snapshots list every widget's declar
171
171
  | `resizable` | resizable | engine-managed drag handle; `width` sets the initial width |
172
172
  | `split` | split | two-pane horizontal splitter: exactly two element children (nest splits for more panes), the engine synthesizes the draggable divider between them. `value` binds the model-owned first-pane fraction (0 lays out at 0.5), `on-resize` names an f32 Msg variant dispatched with every applied fraction (echo it back through `value` — see Splitters), `min-width` on the panes bounds the drag, `gap` sets the divider band thickness. The divider is focusable: Left/Right (Shift for bigger steps) adjust, Home/End jump to the clamp edges |
173
173
  | `tree` | tree | disclosure-tree container (vertical flow): descendant rows carrying `role="treeitem"` — at ANY nesting depth — form one roving keyboard focus set with the ARIA tree keymap. Up/Down walk visible rows (selection follows focus through each row's `on-press`), Left collapses an expanded row or moves to the parent row, Right expands a collapsed row or moves to the first child row, Home/End jump to the edges, Enter/Space activate. Expandable rows bind `expanded` and `on-toggle`; the model owns selection and expansion (collapsed children are simply not rendered) |
174
- | `text`, `badge`, `tooltip` | text leaves | text content, `{}` interpolation allowed; `text` line policy via `wrap` (`"true"` word-wraps; `"false"`/unset paint one honest line, overflow eliding by default — `overflow="clip"` opts out), and `text` alone takes the typography rungs `size="heading"`/`size="display"` (themable token steps above title — section headings, hero stats, timer numerals) |
174
+ | `text`, `badge`, `tooltip` | text leaves | text content, `{}` interpolation allowed; `text` line policy via `wrap` (`"true"` word-wraps; `"false"`/unset paint one honest line, overflow eliding by default — `overflow="clip"` opts out), and `text` alone takes the typography rungs `size="heading"`/`size="display"` (themable token steps above title — section headings, hero stats, timer numerals). `tooltip` with `anchor="above\|below"` floats against its parent (the stack wrapping trigger + tooltip, the dropdown pattern) and the RUNTIME owns its visibility — hover intent on the trigger: shows after `tooltip-delay` ms (default 600; `"0"` = instant) and immediately on keyboard focus; hides on leave, focus departure, Escape, or a press of the trigger (a press also closes the warm window), and a shared 400ms warm window after a pointer-hovered tooltip hides on leave (the only hide that warms) shows the next trigger's tooltip instantly; the model never hears hover. These are shadcn/ui's defaults (Base UI). Without `anchor` it stays a static leaf that paints whenever the view renders it |
175
175
  | `text` > `span` | inline styled runs | mixed-style text in ONE wrapped paragraph: span children style runs with `weight="regular\|medium\|bold"`, `mono`, `italic`, `scale` (a positive multiplier on the paragraph's base size — inline headings, hero stats), `underline`, `foreground` (token name); `{bindings}` interpolate inside spans; whitespace between runs collapses to a single space (none = the runs abut); spans do not nest, take no events, and the paragraph announces as one text run — see "Rich text" |
176
176
  | `button`, `toggle-button`, `list-item`, `menu-item`, `toggle`, `switch`, `select`, `avatar` | text-bearing controls | label is the text content; `button`, `toggle-button`, `list-item`, and `menu-item` also take `icon="save"` — a vector icon drawn inline (buttons/toggle-buttons before the label, icon-only when the content is empty: add a `label`; list/menu items as a leading slot), ONE hit target whose icon follows the element's enabled/disabled tint (no overlay stacking, no duplicated `on-press`); tab strips are `toggle-button` children, so tabs get icons this way; `select` shows `placeholder` while empty and dispatches `on-press`; `avatar` renders initials, or a runtime image via `image="{binding}"` (see the Images section) |
177
177
  | `checkbox`, `radio`, `slider`, `progress` | value controls | `checked`, `value` (a 0..1 fraction on slider and progress; progress clamps out-of-range values at render, never an error); the checkbox/radio label rides `text="..."` — these are not text-bearing elements, so text content is a teaching error (`label=` alone names one for accessibility without a visible label); a slider's `value` follows the source when it MOVES (model-driven progress renders every rebuild) and keeps the user's drag while the source replays the same value — use `slider` for seek bars, `progress` for display-only; a markup slider's `on-change` dispatches a PLAIN Msg with no value payload — mirror the applied value into the model with `Options.sync` (the Zig builder's `on_value = Ui.valueMsg(.tag)` does deliver the applied f32) |
@@ -191,7 +191,7 @@ Not markup-expressible (deliberately — write these as Zig view functions with
191
191
 
192
192
  ## Attributes
193
193
 
194
- Layout: `gap` (flow containers only — stacking containers `stack`/`panel`/`card`/`alert`/`bubble`/`dialog`/`drawer`/`sheet`/`resizable` layer their children, so `gap` there is a validation error, not silence: wrap the children in a `column`/`row` inside; on `split` it sets the divider band thickness), `padding` (uniform), `grow`, `width`, `height` (definite: the element is exactly that size — intrinsic content neither shrinks nor silently overflows it; `resizable` treats `width` as the initial width), `min-width` (a floor WITHOUT `width`'s definite max — the element may grow past it but never shrink below; on split panes it bounds the divider drag), `wrap` (`text` only: `wrap="true"` word-wraps at the width the element receives and reserves the wrapped height in columns; `wrap="false"` and unset are honest single-line — one line whose overflow follows `overflow`), `overflow` (`text` only, a teaching error elsewhere: what a single line does with content that does not fit — `ellipsis`, the default, elides behind a trailing … measured with the same metrics paint uses, right for width-constrained list-row titles; `clip` hard-cuts at the frame for fixed-format content like a duration column where "1…" beats nothing; there is deliberately no overflow-visible), `text-alignment` (start|center|end — text leaves, status bars, surface titles; controls that own their label placement ignore it), `columns` (`grid` only: fixed column count, omit for the derived near-square grid; a teaching error elsewhere), `main` (start|center|end|space_between), `cross` (stretch|start|center|end), `virtualized`, `virtual-item-extent`, `anchor` (`dropdown-menu` only, literal `below`/`above`: floats the surface against its parent instead of the flow — auto-flips when the preferred side does not fit, height clamps to the chosen side, x clamps into the window), `anchor-alignment` (with `anchor`: `start`/`end`/`stretch` — stretch also widens the surface to at least the anchor's width, the select-menu look), `anchor-offset` (with `anchor`: literal gap in points, default 4), `overscroll` (`scroll` only, a teaching error elsewhere: `none` pins the region at its content edges — the shipped default via the `ScrollPhysics.overscroll` token — `rubber_band` lets it bounce past them on both the engine and native paths, `default` follows the token).
194
+ Layout: `gap` (flow containers only — stacking containers `stack`/`panel`/`card`/`alert`/`bubble`/`dialog`/`drawer`/`sheet`/`resizable` layer their children, so `gap` there is a validation error, not silence: wrap the children in a `column`/`row` inside; on `split` it sets the divider band thickness), `padding` (uniform), `grow`, `width`, `height` (definite: the element is exactly that size — intrinsic content neither shrinks nor silently overflows it; `resizable` treats `width` as the initial width), `min-width` (a floor WITHOUT `width`'s definite max — the element may grow past it but never shrink below; on split panes it bounds the divider drag), `wrap` (`text` only: `wrap="true"` word-wraps at the width the element receives and reserves the wrapped height in columns; `wrap="false"` and unset are honest single-line — one line whose overflow follows `overflow`), `overflow` (`text` only, a teaching error elsewhere: what a single line does with content that does not fit — `ellipsis`, the default, elides behind a trailing … measured with the same metrics paint uses, right for width-constrained list-row titles; `clip` hard-cuts at the frame for fixed-format content like a duration column where "1…" beats nothing; there is deliberately no overflow-visible), `text-alignment` (start|center|end — text leaves, status bars, surface titles; controls that own their label placement ignore it), `columns` (`grid` only: fixed column count, omit for the derived near-square grid; a teaching error elsewhere), `main` (start|center|end|space_between), `cross` (stretch|start|center|end), `virtualized`, `virtual-item-extent`, `anchor` (`dropdown-menu` and `tooltip`, literal `below`/`above`: floats the surface against its parent instead of the flow — auto-flips when the preferred side does not fit, height clamps to the chosen side, x clamps into the window; an anchored tooltip's visibility is runtime-owned hover intent, unlike the model-owned dropdown), `anchor-alignment` (with `anchor`: `start`/`end`/`stretch` — stretch also widens the surface to at least the anchor's width, the select-menu look), `anchor-offset` (with `anchor`: literal gap in points, default 4), `tooltip-delay` (`tooltip` only, beside `anchor` — a teaching error elsewhere or without it: hover-intent show delay in ms, default 600, `"0"` = instant; keyboard-focus reveals are always immediate), `overscroll` (`scroll` only, a teaching error elsewhere: `none` pins the region at its content edges — the shipped default via the `ScrollPhysics.overscroll` token — `rubber_band` lets it bounce past them on both the engine and native paths, `default` follows the token).
195
195
  Appearance/state: `variant` (default|primary|secondary|outline|ghost|destructive), `size` (the control scale default|sm|lg|icon on every sized element; on `text` also the typography rungs heading|display — named typography token steps (`heading_size` 28, `display_size` 48, themable like every token) for section headings and hero stats/timer numerals. The two axes stay apart: heading/display on a control is a teaching error naming text as their home, unknown values list the vocabulary, and numeric sizes are refused by design — retheme the typography tokens to move the whole scale), `disabled`, `checked`, `selected`, `value`, `placeholder`, `icon` (`button`, `toggle-button`, `list-item`, `menu-item`: vector icon drawn inline — buttons/toggle-buttons before the label, list/menu items as a leading slot; a teaching error anywhere else. A built-in name, `app:<name>`, or one `{binding}` resolving to such a name). **One size register per row**: every control class shares the control height at a given register (default 36, sm 31.5, lg 40.5 before density), so a toolbar/filter row reads as one height exactly when every control in it carries the SAME `size` — mixing `size="sm"` buttons with a default field renders two heights in one row, and hand-sized pressable panels (`height="30"`) never land on the scale; compose rows from real controls at one register.
196
196
  Focus: `autofocus` (focusable controls only — a teaching error elsewhere): moves keyboard focus to the element when it MOUNTS or when the bound value turns on, edge-triggered so holding it true never re-steals focus from the user. The TEA way to focus an editor on note-create (`<text-field autofocus="{editing}" ...>` or mount the field under an `<if>` with `autofocus="true"`; Zig views use `ElementOptions.autofocus`) and to give keyboard-first apps their first focus without a click.
197
197
  Semantics: `role` (listitem, treeitem, button, ...; `treeitem` also makes the row part of its tree's roving keyboard focus set), `label` (accessible name — it REPLACES the element's text content as the announced name, so snapshot greps and screen readers see the label, never the text; don't `label` an element whose visible text you grep for), `expanded` (tree rows: disclosure state, model-owned — omit on leaves). Accessible names are ENFORCED: an interactive control with no text content, no `text=`, and no `label=` is a validation error (icon-only controls need `label`; text-entry controls need `label` or `placeholder`), unknown/misused literal roles are errors (`role="tree"` on a text leaf can never hold rows), unnamed avatars and labels duplicating the text content are warnings (`label=""` marks an image decorative). Zig-built trees get the same discipline from `canvas.expectA11yAuditSweepClean` (missing names as the bridges would announce them, focusables clipped out of keyboard reach, identically labeled siblings) — adopt it next to the layout sweep.
@@ -1817,6 +1817,15 @@ pub const WidgetAccessibilityActionKind = enum(c_int) {
1817
1817
  drag = 8,
1818
1818
  drop_files = 9,
1819
1819
  dismiss = 10,
1820
+ // The composition verbs never arrive from desktop assistive-tech
1821
+ // bridges (AppKit has no AX composition action); they exist so the
1822
+ // DIRECT verb surfaces (embed hosts, automation commands) and the
1823
+ // session journal can carry every accessibility verb as one
1824
+ // `widget_accessibility_action` — replay re-runs the verb, focus
1825
+ // included, instead of replaying its untargeted ime children.
1826
+ set_composition = 11,
1827
+ commit_composition = 12,
1828
+ cancel_composition = 13,
1820
1829
  };
1821
1830
 
1822
1831
  pub const WidgetAccessibilityActionEvent = struct {
@@ -371,6 +371,7 @@ pub const ControlVisualTokenOverrides = token_model.ControlVisualTokenOverrides;
371
371
  pub const ControlTokenOverrides = token_model.ControlTokenOverrides;
372
372
  pub const DesignTokenOverrides = token_model.DesignTokenOverrides;
373
373
  pub const accentOverrides = token_model.accentOverrides;
374
+ pub const accentFocusRing = token_model.accentFocusRing;
374
375
  pub const DesignTokens = token_model.DesignTokens;
375
376
 
376
377
  // Canvas widget model and built-in factories live in `widgets.zig`; root keeps the public API stable.
@@ -549,6 +549,26 @@ pub const ControlMetricTokens = struct {
549
549
  /// cycle is part of the register's identity, and reduced motion
550
550
  /// already gates the loop through `MotionTokens` upstream.
551
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,
552
572
  };
553
573
 
554
574
  pub const ShadowToken = struct {
@@ -1197,6 +1217,8 @@ pub const ControlMetricTokenOverrides = struct {
1197
1217
  spinner_segment_radius_ratio: ?f32 = null,
1198
1218
  spinner_tail_opacity: ?f32 = null,
1199
1219
  spinner_period_ms: ?u32 = null,
1220
+ tooltip_show_delay_ms: ?u32 = null,
1221
+ tooltip_warm_window_ms: ?u32 = null,
1200
1222
 
1201
1223
  pub fn apply(self: ControlMetricTokenOverrides, base: ControlMetricTokens) ControlMetricTokens {
1202
1224
  return applyFlatTokenOverrides(ControlMetricTokens, base, self);
@@ -1437,7 +1459,11 @@ pub const ControlTokenOverrides = struct {
1437
1459
  /// both schemes without a second manifest knob.
1438
1460
  /// - `colors.focus_ring`: packs spend their identity hue on focus; with
1439
1461
  /// the identity moved, the ring follows so focus and accent chrome
1440
- /// 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.
1441
1467
  /// - `controls.slider.active_background`: the slider table states its
1442
1468
  /// own hue for the filled range rather than deriving from the accent
1443
1469
  /// channel, so the same move is stated once more or a seek scrubber
@@ -1446,12 +1472,12 @@ pub const ControlTokenOverrides = struct {
1446
1472
  /// High-contrast composition is the CALLER's rule (accessibility beats
1447
1473
  /// brand): the runtime skips this bundle when the system asks for high
1448
1474
  /// contrast, taking the pack's own loud register untouched.
1449
- pub fn accentOverrides(accent: Color) DesignTokenOverrides {
1475
+ pub fn accentOverrides(accent: Color, color_scheme: ColorScheme) DesignTokenOverrides {
1450
1476
  return .{
1451
1477
  .colors = .{
1452
1478
  .accent = accent,
1453
1479
  .accent_text = accentKnockoutInk(accent),
1454
- .focus_ring = accent,
1480
+ .focus_ring = accentFocusRing(accent, color_scheme),
1455
1481
  },
1456
1482
  .controls = .{
1457
1483
  .slider = .{ .active_background = accent },
@@ -1459,17 +1485,154 @@ pub fn accentOverrides(accent: Color) DesignTokenOverrides {
1459
1485
  };
1460
1486
  }
1461
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
+
1462
1628
  /// The readable knockout ink over one accent fill: WHITE whenever it
1463
1629
  /// clears the 4.5:1 text bar over the accent (the ink packs pair with
1464
1630
  /// every solid identity fill — the convention brands expect), and the
1465
1631
  /// near-black text ink only when the accent is light enough that white
1466
1632
  /// honestly cannot (1.05 / (L + 0.05) < 4.5).
1467
1633
  fn accentKnockoutInk(accent: Color) Color {
1468
- const luminance = 0.2126 * srgbToLinear(accent.r) +
1469
- 0.7152 * srgbToLinear(accent.g) +
1470
- 0.0722 * srgbToLinear(accent.b);
1471
1634
  // White clears 4.5:1 up to L = 1.05/4.5 - 0.05 ≈ 0.18333.
1472
- if (luminance <= 0.18333) return Color.rgb8(255, 255, 255);
1635
+ if (relativeLuminance(accent) <= 0.18333) return Color.rgb8(255, 255, 255);
1473
1636
  return Color.rgb8(10, 10, 10);
1474
1637
  }
1475
1638
 
@@ -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
- // The textarea newline mapping resolves BEFORE the
1147
- // generic key mapping (which has no Enter case), so
1148
- // the model's `on_input` hears the same newline the
1149
- // runtime applied to the retained text.
1150
- const edit = canvas.widgetKeyboardNewlineTextEditEvent(widget.kind, keyboard) orelse keyboard.textEditEvent();
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 is the
1137
- /// markup channel; popover/menu-surface stay Zig views (documented
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 =