@native-sdk/cli 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.zig +41 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +39 -3
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +3 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +69 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/macos/appkit_host.h +11 -0
- package/src/platform/macos/appkit_host.m +130 -0
- package/src/platform/macos/root.zig +34 -0
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +118 -4
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +26 -0
- package/src/primitives/canvas/tokens.zig +170 -7
- package/src/primitives/canvas/ui.zig +62 -7
- package/src/primitives/canvas/ui_markup.zig +51 -4
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
- package/src/primitives/canvas/ui_markup_tests.zig +73 -0
- package/src/primitives/canvas/ui_markup_view.zig +63 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
- package/src/primitives/canvas/ui_schema.zig +31 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +259 -0
- package/src/primitives/canvas/widget_layout.zig +13 -5
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +28 -0
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +13 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +159 -28
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +26 -0
- package/src/runtime/canvas_images.zig +33 -7
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +1295 -7
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +88 -6
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +112 -6
- package/src/runtime/flow.zig +51 -1
- package/src/runtime/gpu_surface_events.zig +51 -5
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +9 -0
- package/src/runtime/session_journal.zig +52 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +575 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +64 -1
- package/src/runtime/ui_app_tests.zig +794 -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
|
@@ -44,9 +44,37 @@ const render_fingerprints = @import("render_fingerprints.zig");
|
|
|
44
44
|
const vector = @import("vector.zig");
|
|
45
45
|
const font_ttf = @import("font_ttf.zig");
|
|
46
46
|
|
|
47
|
-
/// Element budget for one glyph outline
|
|
48
|
-
///
|
|
49
|
-
|
|
47
|
+
/// Element budget for one glyph outline, derived from the parser's
|
|
48
|
+
/// glyph budgets so every glyph a parsed face maps fits: a contour
|
|
49
|
+
/// emits at most one element per point plus a move, a closing quad, and
|
|
50
|
+
/// a close (points + 3*contours), taken over BOTH glyph forms the gate
|
|
51
|
+
/// admits — a simple glyph's maxima and a composite's flattened maxima
|
|
52
|
+
/// (`maxp.maxCompositePoints`/`maxCompositeContours`, which is what
|
|
53
|
+
/// this builder actually receives when a composite renders). The
|
|
54
|
+
/// budgets are currently equal, so the max is 1408 either way; the
|
|
55
|
+
/// derivation keeps capacity honest if they ever diverge. Stack shape:
|
|
56
|
+
/// at 28 B per element this is ~39 KiB in `drawGlyphOutline`; the edge
|
|
57
|
+
/// accumulator below it is the per-thread heap-resident
|
|
58
|
+
/// `vector.GlyphRasterizer` (see `reference_glyph_raster_scratch`), so
|
|
59
|
+
/// the builder is the only glyph raster state on the stack.
|
|
60
|
+
const reference_glyph_path_capacity: usize = @max(
|
|
61
|
+
font_ttf.max_glyph_points + 3 * font_ttf.max_glyph_contours,
|
|
62
|
+
font_ttf.max_composite_points + 3 * font_ttf.max_composite_contours,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/// Per-thread rasterizer for glyph fills: `vector.GlyphRasterizer`'s
|
|
66
|
+
/// derived budgets guarantee every outline the font registration gate
|
|
67
|
+
/// admits rasterizes (never a block fallback), which sizes it at
|
|
68
|
+
/// ~508 KiB — a per-thread heap slot behind one TLS pointer (the
|
|
69
|
+
/// lazy_tls pattern), not a stack temporary and not static TLS. Only
|
|
70
|
+
/// threads that ink a glyph through the reference renderer allocate it.
|
|
71
|
+
/// The array carries no default and stays uninitialized, exactly like
|
|
72
|
+
/// the stack `Rasterizer` it replaces; `vector.fillGlyphPath` resets it
|
|
73
|
+
/// per glyph.
|
|
74
|
+
const ReferenceGlyphRasterScratch = struct {
|
|
75
|
+
raster: vector.GlyphRasterizer,
|
|
76
|
+
};
|
|
77
|
+
const reference_glyph_raster_scratch = @import("lazy_tls.zig").LazyTls(ReferenceGlyphRasterScratch);
|
|
50
78
|
|
|
51
79
|
const referenceBlurKernel = reference_blur.referenceBlurKernel;
|
|
52
80
|
const referenceBlurSampleWithKernel = reference_blur.referenceBlurSampleWithKernel;
|
|
@@ -62,6 +90,19 @@ pub const ReferenceImage = struct {
|
|
|
62
90
|
width: usize,
|
|
63
91
|
height: usize,
|
|
64
92
|
pixels: []const u8,
|
|
93
|
+
/// Precomputed content fingerprint for the GPU cache planner
|
|
94
|
+
/// (`renderImageFingerprintForResource` uses it when nonzero instead
|
|
95
|
+
/// of hashing `pixels` at plan time). Media-surface textures set it
|
|
96
|
+
/// at adoption so a 60 fps producer never pays a full-buffer hash
|
|
97
|
+
/// per planned frame; 0 — every registered canvas image — keeps the
|
|
98
|
+
/// classic hash-the-bytes keying byte-identically.
|
|
99
|
+
content_fingerprint: u64 = 0,
|
|
100
|
+
/// PRESENTATION-ONLY resource: composited by live GPU/packet hosts,
|
|
101
|
+
/// invisible to the deterministic reference renderer (see the
|
|
102
|
+
/// policy comment in `findReferenceImage`). Media-surface textures
|
|
103
|
+
/// ride the image pipeline with this set, so producer output can
|
|
104
|
+
/// never leak into goldens, screenshots, or replay pixel marks.
|
|
105
|
+
presentation_only: bool = false,
|
|
65
106
|
};
|
|
66
107
|
|
|
67
108
|
/// One runtime-registered font face the reference renderer resolves text
|
|
@@ -772,9 +813,12 @@ pub const ReferenceRenderSurface = struct {
|
|
|
772
813
|
|
|
773
814
|
/// Paint one glyph: the real Geist outline through the vector core
|
|
774
815
|
/// when the codepoint resolves, the historical block rect otherwise
|
|
775
|
-
/// (unmapped codepoints, glyphs
|
|
776
|
-
///
|
|
777
|
-
///
|
|
816
|
+
/// (unmapped codepoints, glyphs of hostile faces whose `maxp`
|
|
817
|
+
/// under-declares — the per-glyph parse backstops — or draws
|
|
818
|
+
/// carrying no text bytes; never a gate-admitted glyph, whose raster
|
|
819
|
+
/// budgets are derived from the registration gate). Layout is
|
|
820
|
+
/// untouched — the pen position and advance still come from the
|
|
821
|
+
/// deterministic estimator.
|
|
778
822
|
fn drawGlyphBox(
|
|
779
823
|
self: ReferenceRenderSurface,
|
|
780
824
|
command: RenderCommand,
|
|
@@ -839,8 +883,14 @@ pub const ReferenceRenderSurface = struct {
|
|
|
839
883
|
.coverage_blend = .srgb,
|
|
840
884
|
};
|
|
841
885
|
// The outline is already in device space; TrueType interiorness
|
|
842
|
-
// is the nonzero rule.
|
|
843
|
-
|
|
886
|
+
// is the nonzero rule. The glyph raster budgets are derived from
|
|
887
|
+
// the registration gate's outline budgets, so a gate-admitted
|
|
888
|
+
// face never trips `VectorPathTooComplex` here — the remaining
|
|
889
|
+
// fallback triggers are a clip band wider than
|
|
890
|
+
// `max_raster_width` (surface-shaped, not font-shaped) and
|
|
891
|
+
// nothing else.
|
|
892
|
+
vector.fillGlyphPath(
|
|
893
|
+
&reference_glyph_raster_scratch.get().raster,
|
|
844
894
|
builder.slice(),
|
|
845
895
|
Affine.identity(),
|
|
846
896
|
.nonzero,
|
|
@@ -1255,6 +1305,15 @@ fn referenceImagePixelLen(width: usize, height: usize) ?usize {
|
|
|
1255
1305
|
|
|
1256
1306
|
fn findReferenceImage(images: []const ReferenceImage, id: ImageId) ?ReferenceImage {
|
|
1257
1307
|
for (images) |image| {
|
|
1308
|
+
// THE REFERENCE-RENDERER MEDIA POLICY: presentation-only
|
|
1309
|
+
// resources (media-surface textures pushed by external
|
|
1310
|
+
// producers) do not exist for the deterministic CPU path. The
|
|
1311
|
+
// draw referencing one skips — exactly like an unregistered id —
|
|
1312
|
+
// so the surface's id-derived placeholder beneath it is what
|
|
1313
|
+
// reference renders, screenshots, replay pixel marks, and
|
|
1314
|
+
// GOLDENS show. Goldens can therefore never depend on producer
|
|
1315
|
+
// output; only live GPU/packet hosts composite the real texture.
|
|
1316
|
+
if (image.presentation_only) continue;
|
|
1258
1317
|
if (image.id == id) return image;
|
|
1259
1318
|
}
|
|
1260
1319
|
return null;
|
|
@@ -53,6 +53,14 @@ pub fn renderImageFingerprintForResource(image_id: ImageId, image: ?ReferenceIma
|
|
|
53
53
|
var hash = renderImageFingerprint(image_id);
|
|
54
54
|
hash = resourceHashUsize(hash, value.width);
|
|
55
55
|
hash = resourceHashUsize(hash, value.height);
|
|
56
|
+
// A precomputed content fingerprint stands in for the pixel bytes:
|
|
57
|
+
// media-surface textures stamp one at adoption so the planner never
|
|
58
|
+
// re-hashes a full video frame per plan. Any content change changes
|
|
59
|
+
// the stamp, so upload/retain/evict keying is untouched; resources
|
|
60
|
+
// without one (every registered canvas image) hash bytes as always.
|
|
61
|
+
if (value.content_fingerprint != 0) {
|
|
62
|
+
return resourceHashU64(hash, value.content_fingerprint);
|
|
63
|
+
}
|
|
56
64
|
hash = resourceHashBytes(hash, value.pixels);
|
|
57
65
|
return hash;
|
|
58
66
|
}
|
|
@@ -58,6 +58,28 @@ pub const ObjectId = u64;
|
|
|
58
58
|
pub const ImageId = u64;
|
|
59
59
|
pub const FontId = u64;
|
|
60
60
|
|
|
61
|
+
/// Reserved namespace bit for MEDIA-SURFACE textures inside the ImageId
|
|
62
|
+
/// value space: a media surface bound to `surface_id` composites the
|
|
63
|
+
/// texture registered under `surface_id | media_surface_image_id_bit`,
|
|
64
|
+
/// so producer-pushed textures and app-registered canvas images can
|
|
65
|
+
/// never collide in the one flat id space draw commands reference.
|
|
66
|
+
/// Surface ids and registered canvas image ids must both stay BELOW the
|
|
67
|
+
/// bit — `Runtime.acquireMediaSurfaceProducer` and
|
|
68
|
+
/// `Runtime.registerCanvasImage` reject ids with it set, loudly.
|
|
69
|
+
pub const media_surface_image_id_bit: ImageId = 1 << 63;
|
|
70
|
+
|
|
71
|
+
/// The texture image id a media surface's draw command references for a
|
|
72
|
+
/// bound surface id (see `media_surface_image_id_bit`).
|
|
73
|
+
pub fn mediaSurfaceTextureImageId(surface_id: u64) ImageId {
|
|
74
|
+
return surface_id | media_surface_image_id_bit;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// The media surface's deterministic id-derived placeholder color
|
|
78
|
+
/// (widget_render.zig): what the reference renderer — goldens,
|
|
79
|
+
/// screenshots, replay pixel marks — shows for a bound surface, live
|
|
80
|
+
/// texture or not. Exported so tests pin the placeholder policy.
|
|
81
|
+
pub const mediaSurfacePlaceholderColor = @import("widget_render.zig").mediaSurfacePlaceholderColor;
|
|
82
|
+
|
|
61
83
|
pub const default_sans_font_id: FontId = 1;
|
|
62
84
|
pub const default_mono_font_id: FontId = 2;
|
|
63
85
|
// Reserved sans variant ids for inline span styling. The deterministic
|
|
@@ -172,6 +194,7 @@ pub const CommandRef = command_model.CommandRef;
|
|
|
172
194
|
pub const DiffKind = command_model.DiffKind;
|
|
173
195
|
pub const DiffChange = command_model.DiffChange;
|
|
174
196
|
pub const Builder = command_model.Builder;
|
|
197
|
+
pub const max_display_list_text_bytes = command_model.max_display_list_text_bytes;
|
|
175
198
|
|
|
176
199
|
// Canvas render data and cache plans live in `render.zig`; root keeps the public API stable.
|
|
177
200
|
pub const max_render_state_stack = render_model.max_render_state_stack;
|
|
@@ -371,6 +394,7 @@ pub const ControlVisualTokenOverrides = token_model.ControlVisualTokenOverrides;
|
|
|
371
394
|
pub const ControlTokenOverrides = token_model.ControlTokenOverrides;
|
|
372
395
|
pub const DesignTokenOverrides = token_model.DesignTokenOverrides;
|
|
373
396
|
pub const accentOverrides = token_model.accentOverrides;
|
|
397
|
+
pub const accentFocusRing = token_model.accentFocusRing;
|
|
374
398
|
pub const DesignTokens = token_model.DesignTokens;
|
|
375
399
|
|
|
376
400
|
// Canvas widget model and built-in factories live in `widgets.zig`; root keeps the public API stable.
|
|
@@ -565,6 +589,8 @@ pub const WidgetInvalidation = event_model.WidgetInvalidation;
|
|
|
565
589
|
pub const WidgetClipboardAction = event_model.WidgetClipboardAction;
|
|
566
590
|
pub const widgetKeyboardClipboardAction = event_model.widgetKeyboardClipboardAction;
|
|
567
591
|
pub const widgetKeyboardNewlineTextEditEvent = event_model.widgetKeyboardNewlineTextEditEvent;
|
|
592
|
+
pub const widgetKindSingleLineTextEntry = event_model.widgetKindSingleLineTextEntry;
|
|
593
|
+
pub const sanitizedSingleLineTextInputEvent = event_model.sanitizedSingleLineTextInputEvent;
|
|
568
594
|
pub const widgetKeyboardControlIntent = event_model.widgetKeyboardControlIntent;
|
|
569
595
|
pub const semanticActions = event_model.semanticActions;
|
|
570
596
|
pub const widgetSemanticControlIntent = event_model.widgetSemanticControlIntent;
|
|
@@ -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 (
|
|
1635
|
+
if (relativeLuminance(accent) <= 0.18333) return Color.rgb8(255, 255, 255);
|
|
1473
1636
|
return Color.rgb8(10, 10, 10);
|
|
1474
1637
|
}
|
|
1475
1638
|
|
|
@@ -455,7 +455,12 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
455
455
|
/// app registered at runtime (`Runtime.registerCanvasImage`,
|
|
456
456
|
/// `fx.registerImageBytes`). 0 — the "no image" sentinel —
|
|
457
457
|
/// keeps the widget on its non-image rendering (an avatar
|
|
458
|
-
/// falls back to initials).
|
|
458
|
+
/// falls back to initials). For `media_surface` this same
|
|
459
|
+
/// channel carries the SURFACE id its producer targets
|
|
460
|
+
/// (`Runtime.acquireMediaSurfaceProducer`, markup
|
|
461
|
+
/// `surface={binding}`) — the identical model-owned-u64
|
|
462
|
+
/// shape, one bit of the id space apart (see
|
|
463
|
+
/// `canvas.media_surface_image_id_bit`).
|
|
459
464
|
image: canvas.ImageId = 0,
|
|
460
465
|
/// Vector icon name drawn inside icon-bearing controls
|
|
461
466
|
/// (`button`, `toggle_button`, `icon_button`, `list_item`,
|
|
@@ -598,6 +603,17 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
598
603
|
/// Negative (the default) declares no origin. Only
|
|
599
604
|
/// meaningful with a nonzero `resize_duration`.
|
|
600
605
|
resize_origin: f32 = -1,
|
|
606
|
+
/// Hover-intent show delay for an ANCHORED tooltip (markup
|
|
607
|
+
/// `tooltip-delay`), in milliseconds: the runtime shows the
|
|
608
|
+
/// tooltip only after its trigger has been hovered this
|
|
609
|
+
/// long on the recorded frame clock. 0 shows the instant
|
|
610
|
+
/// the trigger is hovered. Negative (the default) follows
|
|
611
|
+
/// the token default
|
|
612
|
+
/// (`ControlMetricTokens.tooltip_show_delay_ms`). Only
|
|
613
|
+
/// meaningful on a tooltip with `anchor` — the markup
|
|
614
|
+
/// validator rejects it anywhere else as silently-inert
|
|
615
|
+
/// data.
|
|
616
|
+
tooltip_delay: i32 = -1,
|
|
601
617
|
style: canvas.WidgetStyle = .{},
|
|
602
618
|
/// Named token references resolved against design tokens in
|
|
603
619
|
/// `finalizeWithTokens`; explicit `style` values win.
|
|
@@ -1143,13 +1159,34 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1143
1159
|
if (self.msgFor(target_id, .submit)) |msg| return msg;
|
|
1144
1160
|
}
|
|
1145
1161
|
if (isTextEntryWidget(widget) and !widget.state.disabled) {
|
|
1146
|
-
//
|
|
1147
|
-
//
|
|
1148
|
-
//
|
|
1149
|
-
//
|
|
1150
|
-
|
|
1162
|
+
// Events routed through the runtime arrive with the
|
|
1163
|
+
// edit the retained editor actually applied STAMPED
|
|
1164
|
+
// onto `keyboard.edit` (the runtime's one derivation
|
|
1165
|
+
// seam — Escape's search-field clear, composition
|
|
1166
|
+
// cancels, and clipboard edits all ride it), and
|
|
1167
|
+
// `textEditEvent()` returns the stamp first. The
|
|
1168
|
+
// local derivation below is the fallback for events
|
|
1169
|
+
// that never crossed the runtime (direct Tree
|
|
1170
|
+
// consumers, tests); the textarea newline mapping
|
|
1171
|
+
// resolves BEFORE it because the generic key mapping
|
|
1172
|
+
// has no Enter case.
|
|
1173
|
+
const edit = if (keyboard.edit != null)
|
|
1174
|
+
keyboard.edit
|
|
1175
|
+
else
|
|
1176
|
+
canvas.widgetKeyboardNewlineTextEditEvent(widget.kind, keyboard) orelse keyboard.textEditEvent();
|
|
1151
1177
|
if (edit) |text_edit| {
|
|
1152
|
-
|
|
1178
|
+
// Single-line kinds sanitize the edit with the
|
|
1179
|
+
// SAME rule the runtime seam applies before
|
|
1180
|
+
// stamping (strip line breaks; suppress inserts
|
|
1181
|
+
// that strip to nothing), so the fallback
|
|
1182
|
+
// derivation for events that never crossed the
|
|
1183
|
+
// runtime can never feed a model mirror bytes
|
|
1184
|
+
// the retained editor would refuse. Stamped
|
|
1185
|
+
// edits are already sanitized and pass through
|
|
1186
|
+
// untouched.
|
|
1187
|
+
if (canvas.sanitizedSingleLineTextInputEvent(widget.kind, text_edit)) |sanitized| {
|
|
1188
|
+
if (self.msgForTextEdit(target_id, sanitized)) |msg| return msg;
|
|
1189
|
+
}
|
|
1153
1190
|
}
|
|
1154
1191
|
}
|
|
1155
1192
|
return null;
|
|
@@ -1705,6 +1742,23 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1705
1742
|
return self.el(.image, options, .{});
|
|
1706
1743
|
}
|
|
1707
1744
|
|
|
1745
|
+
/// The media surface leaf (markup `<media-surface surface={id}>`):
|
|
1746
|
+
/// composites a texture PRODUCED OUTSIDE the widget tree — a
|
|
1747
|
+
/// video decoder, a camera pipeline, an external renderer —
|
|
1748
|
+
/// into the layout like any widget. `options.image` carries the
|
|
1749
|
+
/// SURFACE id the producer targets
|
|
1750
|
+
/// (`Runtime.acquireMediaSurfaceProducer`), a model-owned u64 in
|
|
1751
|
+
/// the ImageId value space; 0 draws nothing (the image-leaf
|
|
1752
|
+
/// convention). Until the first producer frame arrives, live
|
|
1753
|
+
/// hosts show the surface's deterministic id-derived placeholder
|
|
1754
|
+
/// — which is also ALL the reference renderer (goldens,
|
|
1755
|
+
/// screenshots, replay pixel marks) ever shows, because texture
|
|
1756
|
+
/// contents are presentation chrome by policy. Size it like an
|
|
1757
|
+
/// image: definite width/height or flex grow (no intrinsic size).
|
|
1758
|
+
pub fn mediaSurface(self: *Self, options: ElementOptions) Node {
|
|
1759
|
+
return self.el(.media_surface, options, .{});
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1708
1762
|
/// A built-in vector icon leaf: `name` is one of
|
|
1709
1763
|
/// `canvas.icons.known_icon_names` (compile error otherwise), so
|
|
1710
1764
|
/// icon references never rot. Size comes from `options.size` /
|
|
@@ -2687,6 +2741,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2687
2741
|
.resize_duration_ms = options.resize_duration,
|
|
2688
2742
|
.resize_easing = options.resize_easing,
|
|
2689
2743
|
.resize_origin = options.resize_origin,
|
|
2744
|
+
.tooltip_delay_ms = options.tooltip_delay,
|
|
2690
2745
|
};
|
|
2691
2746
|
applyKindDefaultLayout(kind, options, &widget.layout);
|
|
2692
2747
|
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,9 +1243,17 @@ 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
|
|
|
1253
|
+
pub const media_surface_surface_message = "surface takes one {binding} to the u64 surface id a producer targets (runtime.acquireMediaSurfaceProducer) - surface ids are model data, not markup literals; 0 leaves the surface unbound and it draws nothing";
|
|
1254
|
+
pub const media_surface_surface_element_message = "surface is only supported on media-surface - it names the producer rendezvous of the media surface's texture channel; anywhere else it would be silently inert";
|
|
1255
|
+
pub const media_surface_missing_surface_message = "media-surface requires surface={binding} naming the u64 surface id its producer targets - without one the surface can never show anything (dead markup, same policy as icon without name)";
|
|
1256
|
+
|
|
1247
1257
|
/// The built-in vector icon vocabulary behind `<icon name="..."/>`.
|
|
1248
1258
|
/// Registry section mirroring `canvas.icons.known_icon_names` (the
|
|
1249
1259
|
/// comptime-parsed registry; this layer stays std-only); a test in
|
|
@@ -2922,6 +2932,12 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
2922
2932
|
if (node.attr("name") == null) return errorAt(node, icon_missing_name_message);
|
|
2923
2933
|
if (node.children.len > 0) return errorAt(node.children[0], icon_children_message);
|
|
2924
2934
|
}
|
|
2935
|
+
if (std.mem.eql(u8, node.name, "media-surface")) {
|
|
2936
|
+
// A media surface without a producer rendezvous can never
|
|
2937
|
+
// show anything: statically dead markup, refused with a
|
|
2938
|
+
// teaching (the icon-without-name policy).
|
|
2939
|
+
if (node.attr("surface") == null) return errorAt(node, media_surface_missing_surface_message);
|
|
2940
|
+
}
|
|
2925
2941
|
if (std.mem.eql(u8, node.name, "split")) {
|
|
2926
2942
|
// Exactly two pane children, statically: the divider sits
|
|
2927
2943
|
// between fixed panes, so conditional/repeated content
|
|
@@ -3057,6 +3073,20 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
3057
3073
|
}
|
|
3058
3074
|
continue;
|
|
3059
3075
|
}
|
|
3076
|
+
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
3077
|
+
// The media-surface producer rendezvous, media-surface
|
|
3078
|
+
// scoped: surface ids are model data a producer
|
|
3079
|
+
// targets, never markup literals (the runtime-image-id
|
|
3080
|
+
// grammar exactly).
|
|
3081
|
+
if (!std.mem.eql(u8, node.name, "media-surface")) {
|
|
3082
|
+
return attrError(node, attribute, media_surface_surface_element_message);
|
|
3083
|
+
}
|
|
3084
|
+
const expression = parseAttrExpression(attribute.value);
|
|
3085
|
+
if (expression == null or expression.? != .binding) {
|
|
3086
|
+
return attrError(node, attribute, media_surface_surface_message);
|
|
3087
|
+
}
|
|
3088
|
+
continue;
|
|
3089
|
+
}
|
|
3060
3090
|
if (std.mem.eql(u8, attribute.name, "anchor")) {
|
|
3061
3091
|
// Anchored floating placement, dropdown-menu-scoped:
|
|
3062
3092
|
// a literal side so the compiled engine resolves it
|
|
@@ -3211,6 +3241,23 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
3211
3241
|
}
|
|
3212
3242
|
}
|
|
3213
3243
|
}
|
|
3244
|
+
if (std.mem.eql(u8, attribute.name, "tooltip-delay")) {
|
|
3245
|
+
// Hover intent exists only where the runtime owns
|
|
3246
|
+
// visibility: anywhere but a tooltip the delay is
|
|
3247
|
+
// silently inert (same policy as resize-duration
|
|
3248
|
+
// off split).
|
|
3249
|
+
if (!std.mem.eql(u8, node.name, "tooltip")) {
|
|
3250
|
+
return attrError(node, attribute, tooltip_delay_element_message);
|
|
3251
|
+
}
|
|
3252
|
+
// The delay shapes a hover-show that exists only on
|
|
3253
|
+
// an ANCHORED tooltip: a static tooltip paints
|
|
3254
|
+
// whenever the view renders it, so a delay beside
|
|
3255
|
+
// no anchor is silently inert — a teaching error
|
|
3256
|
+
// (the anchor-alignment-without-anchor policy).
|
|
3257
|
+
if (node.attr("anchor") == null) {
|
|
3258
|
+
return attrError(node, attribute, tooltip_delay_dependent_attr_message);
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3214
3261
|
if (std.mem.eql(u8, attribute.name, "size")) {
|
|
3215
3262
|
// The size register's closed literal vocabulary
|
|
3216
3263
|
// (bindings resolve at build): the control scale
|
|
@@ -152,6 +152,31 @@ test "NSUI round-trips the input-group vocabulary under its fresh codes" {
|
|
|
152
152
|
try testing.expectEqual(@as(u16, 63), schema.elementByName("input-group-actions").?.code);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
test "NSUI round-trips the media surface under its fresh codes" {
|
|
156
|
+
// media-surface and its surface binding serialize like any element —
|
|
157
|
+
// fresh registry codes ride the wire automatically, no schema bump —
|
|
158
|
+
// so a media document survives encode/decode node-for-node.
|
|
159
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
160
|
+
defer arena_state.deinit();
|
|
161
|
+
const arena = arena_state.allocator();
|
|
162
|
+
const source =
|
|
163
|
+
\\<column gap="8">
|
|
164
|
+
\\ <media-surface surface="{preview}" width="320" height="180" label="Camera preview" />
|
|
165
|
+
\\</column>
|
|
166
|
+
;
|
|
167
|
+
const document = try parseSource(arena, source);
|
|
168
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(document));
|
|
169
|
+
|
|
170
|
+
var diagnostic = nsui.CodecDiagnostic{};
|
|
171
|
+
const bytes = try nsui.encode(arena, document, .{}, &diagnostic);
|
|
172
|
+
const decoded = try nsui.decode(arena, bytes, &diagnostic);
|
|
173
|
+
try expectNodesEqual(document.root.?, decoded.root.?);
|
|
174
|
+
|
|
175
|
+
// The wire carries the registry codes, never the names.
|
|
176
|
+
try testing.expectEqual(@as(u16, 66), schema.elementByName("media-surface").?.code);
|
|
177
|
+
try testing.expectEqual(@as(u16, 81), schema.attrByName("surface").?.code);
|
|
178
|
+
}
|
|
179
|
+
|
|
155
180
|
test "NSUI round-trips the split layout-tween pair under its fresh codes" {
|
|
156
181
|
// resize-duration/resize-easing serialize like any attribute — fresh
|
|
157
182
|
// registry codes ride the wire automatically, no schema bump — so a
|