@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
|
@@ -1589,6 +1589,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1589
1589
|
};
|
|
1590
1590
|
} else if (comptime std.mem.eql(u8, attribute.name, "image")) {
|
|
1591
1591
|
applyImageAttr(node, attribute.value, entries, ui, model, scope, options);
|
|
1592
|
+
} else if (comptime std.mem.eql(u8, attribute.name, "surface")) {
|
|
1593
|
+
applySurfaceAttr(node, attribute.value, entries, ui, model, scope, options);
|
|
1592
1594
|
} else if (comptime std.mem.eql(u8, attribute.name, "name")) {
|
|
1593
1595
|
// Consumed by the icon branch in buildElement; a
|
|
1594
1596
|
// compile error on any other element (interpreter and
|
|
@@ -1666,8 +1668,35 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1666
1668
|
}
|
|
1667
1669
|
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
1668
1670
|
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.avatar_image_message);
|
|
1671
|
+
// Range-checked before the u64 cast (the interpreter fails
|
|
1672
|
+
// the same way): a signed model field (`image: i64 = -1`)
|
|
1673
|
+
// can deliver a negative — fail the build, never trap.
|
|
1669
1674
|
options.image = switch (bindingValue(node, entries, path, ui, model, scope, true)) {
|
|
1670
|
-
.integer => |int| @intCast(int),
|
|
1675
|
+
.integer => |int| if (int < 0) runtimeFail(canvas.ImageId, ui) else @intCast(int),
|
|
1676
|
+
else => runtimeFail(canvas.ImageId, ui),
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
/// Comptime mirror of the interpreter's `applySurfaceAttr`:
|
|
1681
|
+
/// `surface="{binding}"` on media-surface resolves to the
|
|
1682
|
+
/// model-owned u64 surface id a producer targets —
|
|
1683
|
+
/// media-surface-only, binding-only, integer-valued, all checked
|
|
1684
|
+
/// at comptime with the interpreter's messages. The id rides
|
|
1685
|
+
/// `options.image` into `Widget.image_id`, the media surface's
|
|
1686
|
+
/// surface-id channel.
|
|
1687
|
+
fn applySurfaceAttr(comptime node: markup.MarkupNode, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
1688
|
+
comptime {
|
|
1689
|
+
if (!std.mem.eql(u8, node.name, "media-surface")) fail(node, markup.media_surface_surface_element_message);
|
|
1690
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.media_surface_surface_message);
|
|
1691
|
+
if (expression != .binding) fail(node, markup.media_surface_surface_message);
|
|
1692
|
+
}
|
|
1693
|
+
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
1694
|
+
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.media_surface_surface_message);
|
|
1695
|
+
// Range-checked before the u64 cast (the interpreter fails
|
|
1696
|
+
// the same way): a signed model field (`surface: i64 = -1`)
|
|
1697
|
+
// can deliver a negative — fail the build, never trap.
|
|
1698
|
+
options.image = switch (bindingValue(node, entries, path, ui, model, scope, true)) {
|
|
1699
|
+
.integer => |int| if (int < 0) runtimeFail(canvas.ImageId, ui) else @intCast(int),
|
|
1671
1700
|
else => runtimeFail(canvas.ImageId, ui),
|
|
1672
1701
|
};
|
|
1673
1702
|
}
|
|
@@ -1732,8 +1761,16 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1732
1761
|
.optional => @field(options, zig_field) = evalExpr(node, entries, raw, ui, model, scope).truthy(),
|
|
1733
1762
|
.int => {
|
|
1734
1763
|
comptime requireVariant(variant, &.{.integer}, node, "expected a whole number");
|
|
1764
|
+
// Range-checked against the field's own integer type
|
|
1765
|
+
// before the cast (the grid-lines pattern; the
|
|
1766
|
+
// interpreter fails the same way): expression values
|
|
1767
|
+
// are i64, so a literal or model binding can deliver
|
|
1768
|
+
// 2147483648 to the i32 tooltip-delay — an unchecked
|
|
1769
|
+
// @intCast TRAPPED on it instead of failing the
|
|
1770
|
+
// build. The field type is the honest upper bound;
|
|
1771
|
+
// no semantic cap is invented on top of it.
|
|
1735
1772
|
@field(options, zig_field) = switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
1736
|
-
.integer => |int| if (int < 0) runtimeFail(FieldType, ui) else @intCast(int),
|
|
1773
|
+
.integer => |int| if (int < 0 or int > std.math.maxInt(FieldType)) runtimeFail(FieldType, ui) else @intCast(int),
|
|
1737
1774
|
else => runtimeFail(FieldType, ui),
|
|
1738
1775
|
};
|
|
1739
1776
|
},
|
|
@@ -1770,7 +1807,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1770
1807
|
|
|
1771
1808
|
fn uiKeyFromValue(value: Value, ui: *Ui) canvas.UiKey {
|
|
1772
1809
|
return switch (value) {
|
|
1773
|
-
|
|
1810
|
+
// Keys are identity, not quantities: a negative integer
|
|
1811
|
+
// id maps bijectively into the u64 key space (the
|
|
1812
|
+
// interpreter's itemKey/attrKey rule), never a trap.
|
|
1813
|
+
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
1774
1814
|
.string => |text| canvas.uiKey(text),
|
|
1775
1815
|
else => blk: {
|
|
1776
1816
|
ui.failed = true;
|
|
@@ -1969,8 +2009,13 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1969
2009
|
switch (comptime @typeInfo(T)) {
|
|
1970
2010
|
.int => {
|
|
1971
2011
|
comptime requireVariant(variant, &.{.integer}, node, "payload type does not match the message");
|
|
2012
|
+
// Range-checked against the payload's own integer
|
|
2013
|
+
// type before the cast (the interpreter fails the
|
|
2014
|
+
// same way): a binding's i64 can deliver a negative
|
|
2015
|
+
// to an unsigned payload or overflow a small one.
|
|
2016
|
+
// Signed payloads keep their negative range.
|
|
1972
2017
|
return switch (value) {
|
|
1973
|
-
.integer => |int| @intCast(int),
|
|
2018
|
+
.integer => |int| if (int < std.math.minInt(T) or int > std.math.maxInt(T)) runtimeFail(T, ui) else @intCast(int),
|
|
1974
2019
|
else => runtimeFail(T, ui),
|
|
1975
2020
|
};
|
|
1976
2021
|
},
|
|
@@ -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 =
|
|
@@ -1091,6 +1218,39 @@ test "compiled avatar image binding matches the interpreter and the hand-written
|
|
|
1091
1218
|
try testing.expectEqualStrings("CT", fixture.findByText(empty.root, .avatar, "CT").?.text);
|
|
1092
1219
|
}
|
|
1093
1220
|
|
|
1221
|
+
// ------------------------------- negative id bindings fail, never trap
|
|
1222
|
+
|
|
1223
|
+
const AvatarNegativeCompiled = canvas.CompiledMarkupView(fixture.AvatarModel, fixture.AvatarMsg, fixture.avatar_negative_markup_source);
|
|
1224
|
+
const SurfaceUi = fixture.SurfaceUi;
|
|
1225
|
+
const SurfaceCompiled = canvas.CompiledMarkupView(fixture.SurfaceModel, fixture.SurfaceMsg, fixture.surface_markup_source);
|
|
1226
|
+
const SurfaceNegativeCompiled = canvas.CompiledMarkupView(fixture.SurfaceModel, fixture.SurfaceMsg, fixture.surface_negative_markup_source);
|
|
1227
|
+
|
|
1228
|
+
test "compiled avatar and media-surface id bindings refuse negative model values instead of trapping" {
|
|
1229
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1230
|
+
defer arena_state.deinit();
|
|
1231
|
+
const arena = arena_state.allocator();
|
|
1232
|
+
|
|
1233
|
+
// The u64 surface id resolves like the interpreter's.
|
|
1234
|
+
var ok_ui = SurfaceUi.init(arena);
|
|
1235
|
+
const ok_tree = try ok_ui.finalize(SurfaceCompiled.build(&ok_ui, &fixture.SurfaceModel{}));
|
|
1236
|
+
const surface = ok_tree.root.children[0];
|
|
1237
|
+
try testing.expectEqual(canvas.WidgetKind.media_surface, surface.kind);
|
|
1238
|
+
try testing.expectEqual(@as(canvas.ImageId, 5), surface.image_id);
|
|
1239
|
+
|
|
1240
|
+
// A negative i64 binding into either u64 id seam latches the
|
|
1241
|
+
// failed build (the interpreter's teaching error mirrors it), and
|
|
1242
|
+
// finalize surfaces the failure — never an @intCast trap.
|
|
1243
|
+
var avatar_ui = AvatarUi.init(arena);
|
|
1244
|
+
const avatar_node = AvatarNegativeCompiled.build(&avatar_ui, &fixture.AvatarModel{});
|
|
1245
|
+
try testing.expect(avatar_ui.failed);
|
|
1246
|
+
try testing.expectError(error.OutOfMemory, avatar_ui.finalize(avatar_node));
|
|
1247
|
+
|
|
1248
|
+
var surface_ui = SurfaceUi.init(arena);
|
|
1249
|
+
const surface_node = SurfaceNegativeCompiled.build(&surface_ui, &fixture.SurfaceModel{});
|
|
1250
|
+
try testing.expect(surface_ui.failed);
|
|
1251
|
+
try testing.expectError(error.OutOfMemory, surface_ui.finalize(surface_node));
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1094
1254
|
// ------------------------------------------------------ text wrap parity
|
|
1095
1255
|
|
|
1096
1256
|
const WrapUi = fixture.WrapUi;
|
|
@@ -1196,6 +1196,15 @@ const Checker = struct {
|
|
|
1196
1196
|
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.avatar_image_message);
|
|
1197
1197
|
continue;
|
|
1198
1198
|
}
|
|
1199
|
+
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
1200
|
+
// Media-surface ids are model integers (engine parity —
|
|
1201
|
+
// the runtime-image-id shape exactly).
|
|
1202
|
+
const expression = markup.parseAttrExpression(attribute.value) orelse continue;
|
|
1203
|
+
if (expression != .binding) continue;
|
|
1204
|
+
const resolved = try self.resolveBinding(node, expression.binding, true);
|
|
1205
|
+
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.media_surface_surface_message);
|
|
1206
|
+
continue;
|
|
1207
|
+
}
|
|
1199
1208
|
if (std.mem.eql(u8, attribute.name, "icon") or
|
|
1200
1209
|
(std.mem.eql(u8, attribute.name, "name") and std.mem.eql(u8, node.name, "icon")))
|
|
1201
1210
|
{
|
|
@@ -719,6 +719,30 @@ test "expression type errors name the model field and its Zig type" {
|
|
|
719
719
|
try testing.expect(std.mem.indexOf(u8, message, "name: []const u8") != null);
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
+
test "the media-surface surface binding checks as a model integer" {
|
|
723
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
724
|
+
defer arena_state.deinit();
|
|
725
|
+
const arena = arena_state.allocator();
|
|
726
|
+
|
|
727
|
+
// An integer-producing binding passes — the exact grammar `native
|
|
728
|
+
// check`'s model-aware pass applies to TS and Zig cores alike.
|
|
729
|
+
const good = try parseFixture(arena,
|
|
730
|
+
\\<column>
|
|
731
|
+
\\ <media-surface surface="{count}" label="Preview" />
|
|
732
|
+
\\</column>
|
|
733
|
+
);
|
|
734
|
+
try testing.expectEqual(null, try contractMessage(arena, good, null));
|
|
735
|
+
|
|
736
|
+
// A non-integer binding is refused with the surface teaching.
|
|
737
|
+
const wrong = try parseFixture(arena,
|
|
738
|
+
\\<column>
|
|
739
|
+
\\ <media-surface surface="{name}" label="Preview" />
|
|
740
|
+
\\</column>
|
|
741
|
+
);
|
|
742
|
+
const message = (try contractMessage(arena, wrong, null)).?;
|
|
743
|
+
try testing.expectEqualStrings(markup.media_surface_surface_message, message);
|
|
744
|
+
}
|
|
745
|
+
|
|
722
746
|
test "app: icon references check against the contract's registered icon list" {
|
|
723
747
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
724
748
|
defer arena_state.deinit();
|
|
@@ -698,6 +698,32 @@ test "the avatar image attribute validates as one binding, avatar-only" {
|
|
|
698
698
|
}
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
+
test "the media-surface surface attribute validates as one binding, required, media-surface-only" {
|
|
702
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
703
|
+
defer arena_state.deinit();
|
|
704
|
+
const arena = arena_state.allocator();
|
|
705
|
+
|
|
706
|
+
// One {binding} on media-surface is the whole grammar.
|
|
707
|
+
var parser = markup.Parser.init(arena, "<row>\n <media-surface surface=\"{preview}\" label=\"Preview\" />\n</row>");
|
|
708
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
|
|
709
|
+
|
|
710
|
+
const cases = [_]struct { source: []const u8, message: []const u8 }{
|
|
711
|
+
// Surface ids are model data, never markup literals.
|
|
712
|
+
.{ .source = "<row>\n <media-surface surface=\"7\" label=\"Preview\" />\n</row>", .message = markup.media_surface_surface_message },
|
|
713
|
+
.{ .source = "<row>\n <media-surface surface=\"{a == b}\" label=\"Preview\" />\n</row>", .message = markup.media_surface_surface_message },
|
|
714
|
+
// Scoped to media-surface: anywhere else it would be inert.
|
|
715
|
+
.{ .source = "<row>\n <panel surface=\"{preview}\" />\n</row>", .message = markup.media_surface_surface_element_message },
|
|
716
|
+
// ...and required: an unbound surface is statically dead markup.
|
|
717
|
+
.{ .source = "<row>\n <media-surface label=\"Preview\" />\n</row>", .message = markup.media_surface_missing_surface_message },
|
|
718
|
+
};
|
|
719
|
+
for (cases) |case| {
|
|
720
|
+
var case_parser = markup.Parser.init(arena, case.source);
|
|
721
|
+
const info = markup.validate(try case_parser.parse()) orelse return error.TestUnexpectedResult;
|
|
722
|
+
try testing.expectEqualStrings(case.message, info.message);
|
|
723
|
+
try testing.expectEqual(@as(usize, 2), info.line);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
701
727
|
test "wrap and issue-link-base validate as vocabulary with teaching errors" {
|
|
702
728
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
703
729
|
defer arena_state.deinit();
|
|
@@ -795,6 +821,53 @@ test "overscroll validates as scroll-scoped with a closed value vocabulary" {
|
|
|
795
821
|
}
|
|
796
822
|
}
|
|
797
823
|
|
|
824
|
+
test "tooltip-delay validates as tooltip-scoped beside anchor, and anchor accepts tooltip" {
|
|
825
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
826
|
+
defer arena_state.deinit();
|
|
827
|
+
const arena = arena_state.allocator();
|
|
828
|
+
|
|
829
|
+
// Valid: an anchored tooltip with a literal delay, a zero delay
|
|
830
|
+
// (instant show), a binding (resolved by the engines at build), and
|
|
831
|
+
// an anchored tooltip with no delay at all (the token default).
|
|
832
|
+
const valid_sources = [_][]const u8{
|
|
833
|
+
"<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"above\" tooltip-delay=\"500\">Bold the selection</tooltip>\n</stack>",
|
|
834
|
+
"<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"above\" tooltip-delay=\"0\">Bold the selection</tooltip>\n</stack>",
|
|
835
|
+
"<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"below\" tooltip-delay=\"{delay}\">Bold the selection</tooltip>\n</stack>",
|
|
836
|
+
"<stack>\n <button on-press=\"pressed\">Bold</button>\n <tooltip anchor=\"above\">Bold the selection</tooltip>\n</stack>",
|
|
837
|
+
};
|
|
838
|
+
for (valid_sources) |source| {
|
|
839
|
+
var parser = markup.Parser.init(arena, source);
|
|
840
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
const cases = [_]struct { source: []const u8, message: []const u8 }{
|
|
844
|
+
// Hover intent exists only where the runtime owns visibility;
|
|
845
|
+
// anywhere else the delay is silently inert.
|
|
846
|
+
.{
|
|
847
|
+
.source = "<column>\n <button on-press=\"pressed\" tooltip-delay=\"500\">Bold</button>\n</column>",
|
|
848
|
+
.message = markup.tooltip_delay_element_message,
|
|
849
|
+
},
|
|
850
|
+
// A delay beside no anchor shapes a hover-show that never
|
|
851
|
+
// happens: a static tooltip paints whenever the view renders it.
|
|
852
|
+
.{
|
|
853
|
+
.source = "<column>\n <tooltip tooltip-delay=\"500\">Bold the selection</tooltip>\n</column>",
|
|
854
|
+
.message = markup.tooltip_delay_dependent_attr_message,
|
|
855
|
+
},
|
|
856
|
+
// Anchor stays scoped to its registry set; tooltip joining it
|
|
857
|
+
// must not open other elements.
|
|
858
|
+
.{
|
|
859
|
+
.source = "<column>\n <badge anchor=\"above\">3</badge>\n</column>",
|
|
860
|
+
.message = markup.anchor_element_message,
|
|
861
|
+
},
|
|
862
|
+
};
|
|
863
|
+
for (cases) |case| {
|
|
864
|
+
var parser = markup.Parser.init(arena, case.source);
|
|
865
|
+
const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
|
|
866
|
+
try testing.expectEqualStrings(case.message, info.message);
|
|
867
|
+
try testing.expect(info.line > 0);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
798
871
|
test "overflow validates as text-scoped with a closed value vocabulary" {
|
|
799
872
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
800
873
|
defer arena_state.deinit();
|
|
@@ -1449,7 +1449,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1449
1449
|
return self.failKey(node, "key does not name a field on the item");
|
|
1450
1450
|
};
|
|
1451
1451
|
return switch (value) {
|
|
1452
|
-
|
|
1452
|
+
// Keys are identity, not quantities: a negative integer
|
|
1453
|
+
// id (an i64 database id, a -1 sentinel) is a distinct,
|
|
1454
|
+
// legitimate identity, so it maps bijectively into the
|
|
1455
|
+
// u64 key space instead of trapping in a signed cast.
|
|
1456
|
+
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
1453
1457
|
.string => |text| canvas.uiKey(text),
|
|
1454
1458
|
else => self.failKey(node, "key fields must be integers or strings"),
|
|
1455
1459
|
};
|
|
@@ -1495,6 +1499,10 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1495
1499
|
try self.applyImageAttr(scope, node, options, attribute);
|
|
1496
1500
|
continue;
|
|
1497
1501
|
}
|
|
1502
|
+
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
1503
|
+
try self.applySurfaceAttr(scope, node, options, attribute);
|
|
1504
|
+
continue;
|
|
1505
|
+
}
|
|
1498
1506
|
if (std.mem.eql(u8, attribute.name, "name")) {
|
|
1499
1507
|
// Consumed by the icon branch in buildElement.
|
|
1500
1508
|
if (!std.mem.eql(u8, node.name, "icon")) {
|
|
@@ -1572,12 +1580,42 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1572
1580
|
const typed = markup.attrTyped(attribute);
|
|
1573
1581
|
if (typed != .binding) return self.failVoid(node, markup.avatar_image_message);
|
|
1574
1582
|
const value = try self.evalBinding(scope, node, typed.binding, true);
|
|
1583
|
+
// Range-checked before the u64 cast: expression values are
|
|
1584
|
+
// i64, so a signed model field (`image: i64 = -1`) can
|
|
1585
|
+
// deliver a negative — the teaching failure, never a trap.
|
|
1575
1586
|
options.image = switch (value) {
|
|
1576
|
-
.integer => |int|
|
|
1587
|
+
.integer => |int| if (int < 0)
|
|
1588
|
+
return self.failVoid(node, markup.avatar_image_message)
|
|
1589
|
+
else
|
|
1590
|
+
@intCast(int),
|
|
1577
1591
|
else => return self.failVoid(node, markup.avatar_image_message),
|
|
1578
1592
|
};
|
|
1579
1593
|
}
|
|
1580
1594
|
|
|
1595
|
+
/// `surface="{binding}"` on media-surface: the model-owned u64
|
|
1596
|
+
/// surface id a producer targets — media-surface-only,
|
|
1597
|
+
/// binding-only, integer-valued (the runtime-image-id grammar
|
|
1598
|
+
/// exactly). The id rides `options.image` into
|
|
1599
|
+
/// `Widget.image_id`, the media surface's surface-id channel.
|
|
1600
|
+
fn applySurfaceAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
1601
|
+
if (!std.mem.eql(u8, node.name, "media-surface")) {
|
|
1602
|
+
return self.failVoid(node, markup.media_surface_surface_element_message);
|
|
1603
|
+
}
|
|
1604
|
+
const typed = markup.attrTyped(attribute);
|
|
1605
|
+
if (typed != .binding) return self.failVoid(node, markup.media_surface_surface_message);
|
|
1606
|
+
const value = try self.evalBinding(scope, node, typed.binding, true);
|
|
1607
|
+
// Range-checked before the u64 cast: expression values are
|
|
1608
|
+
// i64, so a signed model field (`surface: i64 = -1`) can
|
|
1609
|
+
// deliver a negative — the teaching failure, never a trap.
|
|
1610
|
+
options.image = switch (value) {
|
|
1611
|
+
.integer => |int| if (int < 0)
|
|
1612
|
+
return self.failVoid(node, markup.media_surface_surface_message)
|
|
1613
|
+
else
|
|
1614
|
+
@intCast(int),
|
|
1615
|
+
else => return self.failVoid(node, markup.media_surface_surface_message),
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1581
1619
|
/// `icon="save"` on button, toggle-button, list-item, or
|
|
1582
1620
|
/// menu-item: the same icon value grammar as `<icon name>` — a
|
|
1583
1621
|
/// built-in literal can never rot silently, app:<name> and one
|
|
@@ -1666,8 +1704,17 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1666
1704
|
// Optional bools (`expanded`): the attribute's PRESENCE
|
|
1667
1705
|
// makes the state non-null; the value sets it.
|
|
1668
1706
|
.optional => @field(options, field) = value.truthy(),
|
|
1707
|
+
// Range-checked against the FIELD's own integer type
|
|
1708
|
+
// before the cast (the grid-lines teaching, generalized):
|
|
1709
|
+
// expression values are i64, so a literal or model
|
|
1710
|
+
// binding can deliver 2147483648 to the i32
|
|
1711
|
+
// tooltip-delay — an unchecked @intCast TRAPPED on it
|
|
1712
|
+
// instead of failing the build. The field type is the
|
|
1713
|
+
// honest upper bound: no semantic millisecond cap is
|
|
1714
|
+
// invented on top of it, matching resize-duration, whose
|
|
1715
|
+
// only bound is likewise its u32.
|
|
1669
1716
|
.int => @field(options, field) = switch (value) {
|
|
1670
|
-
.integer => |int| if (int < 0)
|
|
1717
|
+
.integer => |int| if (int < 0 or int > std.math.maxInt(FieldType))
|
|
1671
1718
|
return self.failVoid(node, "expected a non-negative whole number")
|
|
1672
1719
|
else
|
|
1673
1720
|
@intCast(int),
|
|
@@ -1693,7 +1740,9 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1693
1740
|
fn attrKey(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!canvas.UiKey {
|
|
1694
1741
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1695
1742
|
return switch (value) {
|
|
1696
|
-
|
|
1743
|
+
// Bijective like itemKey: a negative integer key is a
|
|
1744
|
+
// distinct identity, never a trap.
|
|
1745
|
+
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
1697
1746
|
.string => |text| canvas.uiKey(text),
|
|
1698
1747
|
else => self.failKey(node, "keys must be integers or strings"),
|
|
1699
1748
|
};
|
|
@@ -1797,8 +1846,17 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1797
1846
|
|
|
1798
1847
|
fn coerce(self: *Self, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
|
|
1799
1848
|
return switch (@typeInfo(T)) {
|
|
1849
|
+
// Range-checked against the payload's own integer type
|
|
1850
|
+
// before the cast (the option-attribute pattern): a
|
|
1851
|
+
// binding's i64 can deliver a negative to an unsigned
|
|
1852
|
+
// payload or overflow a small one — the teaching
|
|
1853
|
+
// failure, never a trap. Signed payloads keep their
|
|
1854
|
+
// negative range (minInt is the honest lower bound).
|
|
1800
1855
|
.int => switch (value) {
|
|
1801
|
-
.integer => |int|
|
|
1856
|
+
.integer => |int| if (int < std.math.minInt(T) or int > std.math.maxInt(T))
|
|
1857
|
+
self.failCoerce(T, node)
|
|
1858
|
+
else
|
|
1859
|
+
@intCast(int),
|
|
1802
1860
|
else => self.failCoerce(T, node),
|
|
1803
1861
|
},
|
|
1804
1862
|
.float => switch (value) {
|