@native-sdk/cli 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +41 -1
- package/build.zig +264 -3
- package/native-sdk.d.ts +17 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +138 -3
- package/packages/core/sdk/core.ts +225 -3
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +2625 -262
- 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 +4 -2
- package/skill-data/ts-core/SKILL.md +9 -1
- package/src/app_runner/root.zig +106 -1
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +187 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/linux/gtk_host.c +112 -3
- package/src/platform/linux/root.zig +71 -0
- package/src/platform/macos/appkit_host.h +59 -2
- package/src/platform/macos/appkit_host.m +663 -34
- package/src/platform/macos/cef_host.mm +262 -10
- package/src/platform/macos/root.zig +126 -4
- package/src/platform/null_platform.zig +298 -5
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +36 -0
- package/src/platform/types.zig +247 -8
- package/src/platform/windows/root.zig +134 -0
- package/src/platform/windows/webview2_host.cpp +152 -40
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- 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 +25 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/ui.zig +46 -9
- package/src/primitives/canvas/ui_markup.zig +82 -34
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
- package/src/primitives/canvas/ui_markup_contract.zig +10 -1
- package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_tests.zig +55 -9
- package/src/primitives/canvas/ui_markup_view.zig +81 -14
- package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
- package/src/primitives/canvas/ui_schema.zig +29 -0
- 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 +129 -0
- package/src/primitives/canvas/widget_layout.zig +9 -4
- 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/widgets.zig +16 -0
- package/src/root.zig +12 -0
- package/src/runtime/api.zig +15 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +64 -0
- package/src/runtime/bridge_payload.zig +7 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +711 -5
- package/src/runtime/canvas_fonts.zig +120 -25
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +221 -0
- package/src/runtime/canvas_images.zig +78 -19
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +24 -4
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +148 -9
- package/src/runtime/effects.zig +1664 -43
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_tests.zig +153 -0
- package/src/runtime/flow.zig +44 -0
- package/src/runtime/gpu_surface_events.zig +7 -0
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +20 -0
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +111 -20
- package/src/runtime/session_record.zig +27 -2
- package/src/runtime/session_replay.zig +168 -16
- package/src/runtime/session_tests.zig +2118 -4
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +3 -0
- package/src/runtime/ts_core_host.zig +439 -4
- package/src/runtime/ts_core_host_tests.zig +41 -0
- package/src/runtime/ts_ui_app.zig +63 -0
- package/src/runtime/ui_app.zig +169 -6
- package/src/runtime/ui_app_tests.zig +334 -0
- package/src/runtime/ui_app_window_tests.zig +468 -0
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +32 -0
- package/src/runtime/window_views.zig +61 -1
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +219 -1
|
@@ -398,6 +398,23 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
398
398
|
}
|
|
399
399
|
if (pane_count != 2) return self.failNode(node, markup.split_children_message);
|
|
400
400
|
}
|
|
401
|
+
// The image leaf's static shape, mirroring the validator and
|
|
402
|
+
// the compiled engine's compile error. Without its id binding
|
|
403
|
+
// the leaf can never draw - statically dead markup, refused
|
|
404
|
+
// here too so markup that skipped validation (hot reload)
|
|
405
|
+
// fails the build instead of silently rendering nothing. And
|
|
406
|
+
// it takes no children at all (icon's leaf policy): checked
|
|
407
|
+
// on the ORIGINAL node, so an extracted context-menu still
|
|
408
|
+
// counts as a child exactly like the validator's raw-node
|
|
409
|
+
// check.
|
|
410
|
+
if (kind == .image) {
|
|
411
|
+
if (node.attr("image") == null) {
|
|
412
|
+
return self.failNode(node, markup.image_missing_image_message);
|
|
413
|
+
}
|
|
414
|
+
if (node.children.len > 0) {
|
|
415
|
+
return self.failNode(node, markup.image_children_message);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
401
418
|
// The a11y lint's error half: an unnamed interactive control
|
|
402
419
|
// or a misused role ships a view a screen reader user cannot
|
|
403
420
|
// operate, so it fails the build like any other markup
|
|
@@ -1449,7 +1466,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1449
1466
|
return self.failKey(node, "key does not name a field on the item");
|
|
1450
1467
|
};
|
|
1451
1468
|
return switch (value) {
|
|
1452
|
-
|
|
1469
|
+
// Keys are identity, not quantities: a negative integer
|
|
1470
|
+
// id (an i64 database id, a -1 sentinel) is a distinct,
|
|
1471
|
+
// legitimate identity, so it maps bijectively into the
|
|
1472
|
+
// u64 key space instead of trapping in a signed cast.
|
|
1473
|
+
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
1453
1474
|
.string => |text| canvas.uiKey(text),
|
|
1454
1475
|
else => self.failKey(node, "key fields must be integers or strings"),
|
|
1455
1476
|
};
|
|
@@ -1495,6 +1516,10 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1495
1516
|
try self.applyImageAttr(scope, node, options, attribute);
|
|
1496
1517
|
continue;
|
|
1497
1518
|
}
|
|
1519
|
+
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
1520
|
+
try self.applySurfaceAttr(scope, node, options, attribute);
|
|
1521
|
+
continue;
|
|
1522
|
+
}
|
|
1498
1523
|
if (std.mem.eql(u8, attribute.name, "name")) {
|
|
1499
1524
|
// Consumed by the icon branch in buildElement.
|
|
1500
1525
|
if (!std.mem.eql(u8, node.name, "icon")) {
|
|
@@ -1559,22 +1584,53 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1559
1584
|
};
|
|
1560
1585
|
}
|
|
1561
1586
|
|
|
1562
|
-
/// `image="{binding}"` on avatar: one binding
|
|
1563
|
-
/// `canvas.ImageId` the app registered at
|
|
1564
|
-
/// (`fx.
|
|
1565
|
-
///
|
|
1566
|
-
///
|
|
1567
|
-
///
|
|
1587
|
+
/// `image="{binding}"` on avatar and image: one binding
|
|
1588
|
+
/// producing a `u64` `canvas.ImageId` the app registered at
|
|
1589
|
+
/// runtime (`Cmd.imageLoad`, `fx.loadImage`,
|
|
1590
|
+
/// `fx.registerImageBytes`) — the id is model data, never a
|
|
1591
|
+
/// markup literal, and 0 draws nothing (an avatar keeps its
|
|
1592
|
+
/// initials fallback). The remaining image-bearing widget
|
|
1593
|
+
/// (icon-button) stays a Zig view.
|
|
1568
1594
|
fn applyImageAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
1569
|
-
if (!std.mem.eql(u8, node.name, "avatar")) {
|
|
1570
|
-
return self.failVoid(node, markup.
|
|
1595
|
+
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) {
|
|
1596
|
+
return self.failVoid(node, markup.image_binding_element_message);
|
|
1571
1597
|
}
|
|
1572
1598
|
const typed = markup.attrTyped(attribute);
|
|
1573
|
-
if (typed != .binding) return self.failVoid(node, markup.
|
|
1599
|
+
if (typed != .binding) return self.failVoid(node, markup.image_binding_message);
|
|
1574
1600
|
const value = try self.evalBinding(scope, node, typed.binding, true);
|
|
1601
|
+
// Range-checked before the u64 cast: expression values are
|
|
1602
|
+
// i64, so a signed model field (`image: i64 = -1`) can
|
|
1603
|
+
// deliver a negative — the teaching failure, never a trap.
|
|
1575
1604
|
options.image = switch (value) {
|
|
1576
|
-
.integer => |int|
|
|
1577
|
-
|
|
1605
|
+
.integer => |int| if (int < 0)
|
|
1606
|
+
return self.failVoid(node, markup.image_binding_message)
|
|
1607
|
+
else
|
|
1608
|
+
@intCast(int),
|
|
1609
|
+
else => return self.failVoid(node, markup.image_binding_message),
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
/// `surface="{binding}"` on media-surface: the model-owned u64
|
|
1614
|
+
/// surface id a producer targets — media-surface-only,
|
|
1615
|
+
/// binding-only, integer-valued (the runtime-image-id grammar
|
|
1616
|
+
/// exactly). The id rides `options.image` into
|
|
1617
|
+
/// `Widget.image_id`, the media surface's surface-id channel.
|
|
1618
|
+
fn applySurfaceAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
1619
|
+
if (!std.mem.eql(u8, node.name, "media-surface")) {
|
|
1620
|
+
return self.failVoid(node, markup.media_surface_surface_element_message);
|
|
1621
|
+
}
|
|
1622
|
+
const typed = markup.attrTyped(attribute);
|
|
1623
|
+
if (typed != .binding) return self.failVoid(node, markup.media_surface_surface_message);
|
|
1624
|
+
const value = try self.evalBinding(scope, node, typed.binding, true);
|
|
1625
|
+
// Range-checked before the u64 cast: expression values are
|
|
1626
|
+
// i64, so a signed model field (`surface: i64 = -1`) can
|
|
1627
|
+
// deliver a negative — the teaching failure, never a trap.
|
|
1628
|
+
options.image = switch (value) {
|
|
1629
|
+
.integer => |int| if (int < 0)
|
|
1630
|
+
return self.failVoid(node, markup.media_surface_surface_message)
|
|
1631
|
+
else
|
|
1632
|
+
@intCast(int),
|
|
1633
|
+
else => return self.failVoid(node, markup.media_surface_surface_message),
|
|
1578
1634
|
};
|
|
1579
1635
|
}
|
|
1580
1636
|
|
|
@@ -1702,7 +1758,9 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1702
1758
|
fn attrKey(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!canvas.UiKey {
|
|
1703
1759
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1704
1760
|
return switch (value) {
|
|
1705
|
-
|
|
1761
|
+
// Bijective like itemKey: a negative integer key is a
|
|
1762
|
+
// distinct identity, never a trap.
|
|
1763
|
+
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
1706
1764
|
.string => |text| canvas.uiKey(text),
|
|
1707
1765
|
else => self.failKey(node, "keys must be integers or strings"),
|
|
1708
1766
|
};
|
|
@@ -1806,8 +1864,17 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1806
1864
|
|
|
1807
1865
|
fn coerce(self: *Self, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
|
|
1808
1866
|
return switch (@typeInfo(T)) {
|
|
1867
|
+
// Range-checked against the payload's own integer type
|
|
1868
|
+
// before the cast (the option-attribute pattern): a
|
|
1869
|
+
// binding's i64 can deliver a negative to an unsigned
|
|
1870
|
+
// payload or overflow a small one — the teaching
|
|
1871
|
+
// failure, never a trap. Signed payloads keep their
|
|
1872
|
+
// negative range (minInt is the honest lower bound).
|
|
1809
1873
|
.int => switch (value) {
|
|
1810
|
-
.integer => |int|
|
|
1874
|
+
.integer => |int| if (int < std.math.minInt(T) or int > std.math.maxInt(T))
|
|
1875
|
+
self.failCoerce(T, node)
|
|
1876
|
+
else
|
|
1877
|
+
@intCast(int),
|
|
1811
1878
|
else => self.failCoerce(T, node),
|
|
1812
1879
|
},
|
|
1813
1880
|
.float => switch (value) {
|
|
@@ -1321,9 +1321,11 @@ test "the registry's a11y name classes match the engine's control predicates" {
|
|
|
1321
1321
|
try testing.expect(canvas.widgetKindHitTarget(kind));
|
|
1322
1322
|
try testing.expect(canvas.widgetKindClaimsPress(kind));
|
|
1323
1323
|
}
|
|
1324
|
-
// Image-class elements are announced under the image role
|
|
1324
|
+
// Image-class elements are announced under the image role:
|
|
1325
|
+
// avatar, the media surface, and the image leaf (pictorial
|
|
1326
|
+
// content whose missing label degrades but never blocks).
|
|
1325
1327
|
if (entry.a11y_name == .image) {
|
|
1326
|
-
try testing.
|
|
1328
|
+
try testing.expect(kind == .avatar or kind == .media_surface or kind == .image);
|
|
1327
1329
|
}
|
|
1328
1330
|
}
|
|
1329
1331
|
}
|
|
@@ -1406,7 +1408,7 @@ test "the registry's takes-children predicate matches the interpreter's takes-ch
|
|
|
1406
1408
|
/// lowered through `Ui.inputGroup`), so no plain element maps to the
|
|
1407
1409
|
/// kind here — like chart, the bespoke builder is the channel.
|
|
1408
1410
|
const markup_excluded_widget_kinds = [_]canvas.WidgetKind{
|
|
1409
|
-
.
|
|
1411
|
+
.icon_button, .data_grid, .popover, .menu_surface, .segmented_control, .chart, .split_divider, .input_group,
|
|
1410
1412
|
};
|
|
1411
1413
|
|
|
1412
1414
|
fn kindExpressible(kind: canvas.WidgetKind) bool {
|
|
@@ -2367,6 +2369,9 @@ pub const AvatarModel = struct {
|
|
|
2367
2369
|
/// `fx.registerImageBytes`.
|
|
2368
2370
|
user_image: canvas.ImageId = 0,
|
|
2369
2371
|
user_name: []const u8 = "Casey Torres",
|
|
2372
|
+
/// A signed id field: bindings evaluate as i64, so a negative must
|
|
2373
|
+
/// reach the image seam as a value, never trap in the u64 cast.
|
|
2374
|
+
stale_image: i64 = -1,
|
|
2370
2375
|
|
|
2371
2376
|
/// A pub fn producing an ImageId binds like a field.
|
|
2372
2377
|
pub fn teammateImage(model: *const AvatarModel) canvas.ImageId {
|
|
@@ -2381,6 +2386,14 @@ pub const avatar_markup_source =
|
|
|
2381
2386
|
\\</row>
|
|
2382
2387
|
;
|
|
2383
2388
|
|
|
2389
|
+
/// A negative model value into avatar's u64 image seam: both engines
|
|
2390
|
+
/// must fail the build with the avatar teaching, never trap.
|
|
2391
|
+
pub const avatar_negative_markup_source =
|
|
2392
|
+
\\<row>
|
|
2393
|
+
\\ <avatar image="{stale_image}">CT</avatar>
|
|
2394
|
+
\\</row>
|
|
2395
|
+
;
|
|
2396
|
+
|
|
2384
2397
|
pub const AvatarUi = canvas.Ui(AvatarMsg);
|
|
2385
2398
|
|
|
2386
2399
|
/// The hand-written equivalent of the avatar markup: `ui.avatar` with
|
|
@@ -2444,17 +2457,23 @@ test "avatar image misuse fails the build with the teaching messages" {
|
|
|
2444
2457
|
.{
|
|
2445
2458
|
// A literal id is not model data.
|
|
2446
2459
|
.source = "<row>\n <avatar image=\"7\">CT</avatar>\n</row>",
|
|
2447
|
-
.message = canvas.ui_markup.
|
|
2460
|
+
.message = canvas.ui_markup.image_binding_message,
|
|
2448
2461
|
},
|
|
2449
2462
|
.{
|
|
2450
2463
|
// The binding must produce an integer ImageId (user_name is text).
|
|
2451
2464
|
.source = "<row>\n <avatar image=\"{user_name}\">CT</avatar>\n</row>",
|
|
2452
|
-
.message = canvas.ui_markup.
|
|
2465
|
+
.message = canvas.ui_markup.image_binding_message,
|
|
2466
|
+
},
|
|
2467
|
+
.{
|
|
2468
|
+
// A negative integer can never be a u64 ImageId: the
|
|
2469
|
+
// teaching failure, not an @intCast trap.
|
|
2470
|
+
.source = avatar_negative_markup_source,
|
|
2471
|
+
.message = canvas.ui_markup.image_binding_message,
|
|
2453
2472
|
},
|
|
2454
2473
|
.{
|
|
2455
2474
|
// Scoped to avatar: the other image elements stay Zig views.
|
|
2456
2475
|
.source = "<row>\n <badge image=\"{user_image}\">3</badge>\n</row>",
|
|
2457
|
-
.message = canvas.ui_markup.
|
|
2476
|
+
.message = canvas.ui_markup.image_binding_element_message,
|
|
2458
2477
|
},
|
|
2459
2478
|
};
|
|
2460
2479
|
for (cases) |case| {
|
|
@@ -2466,6 +2485,198 @@ test "avatar image misuse fails the build with the teaching messages" {
|
|
|
2466
2485
|
}
|
|
2467
2486
|
}
|
|
2468
2487
|
|
|
2488
|
+
// -------------------------------------------- media-surface id binding
|
|
2489
|
+
|
|
2490
|
+
pub const SurfaceMsg = union(enum) { refresh };
|
|
2491
|
+
|
|
2492
|
+
pub const SurfaceModel = struct {
|
|
2493
|
+
preview: u64 = 5,
|
|
2494
|
+
/// A signed id field: bindings evaluate as i64, so a negative must
|
|
2495
|
+
/// reach the surface seam as a value, never trap in the u64 cast.
|
|
2496
|
+
stale_surface: i64 = -3,
|
|
2497
|
+
};
|
|
2498
|
+
|
|
2499
|
+
pub const surface_markup_source =
|
|
2500
|
+
\\<column>
|
|
2501
|
+
\\ <media-surface surface="{preview}" label="Preview" />
|
|
2502
|
+
\\</column>
|
|
2503
|
+
;
|
|
2504
|
+
|
|
2505
|
+
/// A negative model value into media-surface's u64 surface seam: both
|
|
2506
|
+
/// engines must fail the build with the surface teaching, never trap.
|
|
2507
|
+
pub const surface_negative_markup_source =
|
|
2508
|
+
\\<column>
|
|
2509
|
+
\\ <media-surface surface="{stale_surface}" label="Preview" />
|
|
2510
|
+
\\</column>
|
|
2511
|
+
;
|
|
2512
|
+
|
|
2513
|
+
pub const SurfaceUi = canvas.Ui(SurfaceMsg);
|
|
2514
|
+
|
|
2515
|
+
test "the media-surface surface binding resolves the model id; negatives fail the build" {
|
|
2516
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
2517
|
+
defer arena_state.deinit();
|
|
2518
|
+
const arena = arena_state.allocator();
|
|
2519
|
+
const SurfaceMarkup = markup_view.MarkupView(SurfaceModel, SurfaceMsg);
|
|
2520
|
+
const model = SurfaceModel{};
|
|
2521
|
+
|
|
2522
|
+
// The u64 model id rides options.image into the widget's image_id
|
|
2523
|
+
// (the media surface's surface-id channel).
|
|
2524
|
+
var view = try SurfaceMarkup.init(arena, surface_markup_source);
|
|
2525
|
+
var ui = SurfaceUi.init(arena);
|
|
2526
|
+
const tree = try ui.finalize(try view.build(&ui, &model));
|
|
2527
|
+
const surface = tree.root.children[0];
|
|
2528
|
+
try testing.expectEqual(canvas.WidgetKind.media_surface, surface.kind);
|
|
2529
|
+
try testing.expectEqual(@as(canvas.ImageId, 5), surface.image_id);
|
|
2530
|
+
|
|
2531
|
+
// A negative integer can never be a u64 surface id: the teaching
|
|
2532
|
+
// failure, not an @intCast trap.
|
|
2533
|
+
var negative_view = try SurfaceMarkup.init(arena, surface_negative_markup_source);
|
|
2534
|
+
var negative_ui = SurfaceUi.init(arena);
|
|
2535
|
+
try testing.expectError(error.MarkupBuild, negative_view.build(&negative_ui, &model));
|
|
2536
|
+
try testing.expectEqualStrings(canvas.ui_markup.media_surface_surface_message, negative_view.diagnostic.message);
|
|
2537
|
+
try testing.expect(negative_view.diagnostic.line > 0);
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
// ------------------------------------------------ image leaf id binding
|
|
2541
|
+
|
|
2542
|
+
pub const ImageLeafMsg = union(enum) { refresh };
|
|
2543
|
+
|
|
2544
|
+
pub const ImageLeafModel = struct {
|
|
2545
|
+
/// Runtime-registered ImageId kept in the model (0 = no image, the
|
|
2546
|
+
/// leaf draws nothing) — the id lands here from `Cmd.imageLoad`'s
|
|
2547
|
+
/// loaded result (or `fx.registerImageBytes` on the Zig tier).
|
|
2548
|
+
cover: canvas.ImageId = 0,
|
|
2549
|
+
/// A signed id field: bindings evaluate as i64, so a negative must
|
|
2550
|
+
/// reach the image seam as a value, never trap in the u64 cast.
|
|
2551
|
+
stale_image: i64 = -2,
|
|
2552
|
+
|
|
2553
|
+
/// A pub fn producing an ImageId binds like a field.
|
|
2554
|
+
pub fn thumbnail(model: *const ImageLeafModel) canvas.ImageId {
|
|
2555
|
+
return model.cover + 1;
|
|
2556
|
+
}
|
|
2557
|
+
};
|
|
2558
|
+
|
|
2559
|
+
pub const image_markup_source =
|
|
2560
|
+
\\<row gap="8">
|
|
2561
|
+
\\ <image image="{cover}" width="120" height="80" label="Cover art" />
|
|
2562
|
+
\\ <image image="{thumbnail}" width="48" height="48" label="" />
|
|
2563
|
+
\\</row>
|
|
2564
|
+
;
|
|
2565
|
+
|
|
2566
|
+
/// A negative model value into the image leaf's u64 id seam: both
|
|
2567
|
+
/// engines must fail the build with the image teaching, never trap.
|
|
2568
|
+
pub const image_negative_markup_source =
|
|
2569
|
+
\\<row>
|
|
2570
|
+
\\ <image image="{stale_image}" label="Cover art" />
|
|
2571
|
+
\\</row>
|
|
2572
|
+
;
|
|
2573
|
+
|
|
2574
|
+
pub const ImageLeafUi = canvas.Ui(ImageLeafMsg);
|
|
2575
|
+
|
|
2576
|
+
/// The hand-written equivalent of the image markup: `ui.image` with
|
|
2577
|
+
/// `ElementOptions.image`, the parity baseline the compiled suite
|
|
2578
|
+
/// shares.
|
|
2579
|
+
pub fn handImageLeafView(ui: *ImageLeafUi, model: *const ImageLeafModel) ImageLeafUi.Node {
|
|
2580
|
+
return ui.row(.{ .gap = 8 }, .{
|
|
2581
|
+
ui.image(.{ .image = model.cover, .width = 120, .height = 80, .semantics = .{ .label = "Cover art" } }),
|
|
2582
|
+
ui.image(.{ .image = model.thumbnail(), .width = 48, .height = 48, .semantics = .{ .label = "" } }),
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
test "the image leaf binds a dynamic ImageId from model fields and fns" {
|
|
2587
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
2588
|
+
defer arena_state.deinit();
|
|
2589
|
+
const arena = arena_state.allocator();
|
|
2590
|
+
const ImageMarkup = markup_view.MarkupView(ImageLeafModel, ImageLeafMsg);
|
|
2591
|
+
const model = ImageLeafModel{ .cover = 42 };
|
|
2592
|
+
|
|
2593
|
+
var view = try ImageMarkup.init(arena, image_markup_source);
|
|
2594
|
+
var markup_ui = ImageLeafUi.init(arena);
|
|
2595
|
+
const markup_tree = try markup_ui.finalize(try view.build(&markup_ui, &model));
|
|
2596
|
+
|
|
2597
|
+
var hand_ui = ImageLeafUi.init(arena);
|
|
2598
|
+
const hand_tree = try hand_ui.finalize(handImageLeafView(&hand_ui, &model));
|
|
2599
|
+
|
|
2600
|
+
var markup_ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
|
|
2601
|
+
defer markup_ids.deinit(testing.allocator);
|
|
2602
|
+
var hand_ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
|
|
2603
|
+
defer hand_ids.deinit(testing.allocator);
|
|
2604
|
+
try collectIds(markup_tree.root, &markup_ids, testing.allocator);
|
|
2605
|
+
try collectIds(hand_tree.root, &hand_ids, testing.allocator);
|
|
2606
|
+
try testing.expectEqualSlices(canvas.ObjectId, hand_ids.items, markup_ids.items);
|
|
2607
|
+
|
|
2608
|
+
// The field binding and the fn binding both land in image_id.
|
|
2609
|
+
const cover = markup_tree.root.children[0];
|
|
2610
|
+
try testing.expectEqual(canvas.WidgetKind.image, cover.kind);
|
|
2611
|
+
try testing.expectEqual(@as(canvas.ImageId, 42), cover.image_id);
|
|
2612
|
+
try testing.expectEqualStrings("Cover art", cover.semantics.label);
|
|
2613
|
+
const thumbnail = markup_tree.root.children[1];
|
|
2614
|
+
try testing.expectEqual(@as(canvas.ImageId, 43), thumbnail.image_id);
|
|
2615
|
+
|
|
2616
|
+
// 0 is the "no image" sentinel: the leaf renders nothing (the
|
|
2617
|
+
// model simply has not loaded the image yet).
|
|
2618
|
+
const empty_model = ImageLeafModel{};
|
|
2619
|
+
var empty_ui = ImageLeafUi.init(arena);
|
|
2620
|
+
const empty_tree = try empty_ui.finalize(try view.build(&empty_ui, &empty_model));
|
|
2621
|
+
try testing.expectEqual(@as(canvas.ImageId, 0), empty_tree.root.children[0].image_id);
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
test "image leaf misuse fails the build with the teaching messages" {
|
|
2625
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
2626
|
+
defer arena_state.deinit();
|
|
2627
|
+
const arena = arena_state.allocator();
|
|
2628
|
+
const model = ImageLeafModel{};
|
|
2629
|
+
const ImageMarkup = markup_view.MarkupView(ImageLeafModel, ImageLeafMsg);
|
|
2630
|
+
|
|
2631
|
+
const cases = [_]struct { source: []const u8, message: []const u8 }{
|
|
2632
|
+
.{
|
|
2633
|
+
// A literal id is not model data.
|
|
2634
|
+
.source = "<row>\n <image image=\"7\" label=\"Art\" />\n</row>",
|
|
2635
|
+
.message = canvas.ui_markup.image_binding_message,
|
|
2636
|
+
},
|
|
2637
|
+
.{
|
|
2638
|
+
// A negative integer can never be a u64 ImageId: the
|
|
2639
|
+
// teaching failure, not an @intCast trap.
|
|
2640
|
+
.source = image_negative_markup_source,
|
|
2641
|
+
.message = canvas.ui_markup.image_binding_message,
|
|
2642
|
+
},
|
|
2643
|
+
.{
|
|
2644
|
+
// A leaf like icon: widget layout gives an image no child
|
|
2645
|
+
// slots, so a nested caption would silently vanish - the
|
|
2646
|
+
// build refuses it instead (the compiled engine rejects
|
|
2647
|
+
// the same construct as a compile error).
|
|
2648
|
+
.source = "<row>\n <image image=\"{cover}\" label=\"Art\"><text>Caption</text></image>\n</row>",
|
|
2649
|
+
.message = canvas.ui_markup.image_children_message,
|
|
2650
|
+
},
|
|
2651
|
+
.{
|
|
2652
|
+
// Markup that skipped validation (hot reload) can reach the
|
|
2653
|
+
// engine without the binding: the leaf could only ever
|
|
2654
|
+
// render nothing, so the build refuses it exactly like the
|
|
2655
|
+
// validator (the compiled engine rejects the same construct
|
|
2656
|
+
// as a compile error).
|
|
2657
|
+
.source = "<row>\n <image label=\"Art\" />\n</row>",
|
|
2658
|
+
.message = canvas.ui_markup.image_missing_image_message,
|
|
2659
|
+
},
|
|
2660
|
+
.{
|
|
2661
|
+
// The children check reads the ORIGINAL node: a context-menu
|
|
2662
|
+
// child is extracted as host metadata before the content
|
|
2663
|
+
// rules, but the validator rejects it on the raw node - the
|
|
2664
|
+
// build agrees instead of quietly accepting a menu-bearing
|
|
2665
|
+
// leaf the validator refuses (the compiled engine rejects
|
|
2666
|
+
// the same construct as a compile error).
|
|
2667
|
+
.source = "<row>\n <image image=\"{cover}\" label=\"Art\" on-press=\"refresh\"><context-menu><menu-item on-press=\"refresh\">Reload</menu-item></context-menu></image>\n</row>",
|
|
2668
|
+
.message = canvas.ui_markup.image_children_message,
|
|
2669
|
+
},
|
|
2670
|
+
};
|
|
2671
|
+
for (cases) |case| {
|
|
2672
|
+
var view = try ImageMarkup.init(arena, case.source);
|
|
2673
|
+
var ui = ImageLeafUi.init(arena);
|
|
2674
|
+
try testing.expectError(error.MarkupBuild, view.build(&ui, &model));
|
|
2675
|
+
try testing.expectEqualStrings(case.message, view.diagnostic.message);
|
|
2676
|
+
try testing.expect(view.diagnostic.line > 0);
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2469
2680
|
// ------------------------------------- text alignment and grid columns
|
|
2470
2681
|
|
|
2471
2682
|
pub const AlignMsg = union(enum) { refresh };
|
|
@@ -3836,7 +4047,8 @@ test "reactions misuse fails the build with the pinned teaching messages" {
|
|
|
3836
4047
|
|
|
3837
4048
|
// The pill's literal run rides the tofu guard: a codepoint outside
|
|
3838
4049
|
// the bundled face renders as a tofu box on the reference path, so
|
|
3839
|
-
// the validator teaches
|
|
4050
|
+
// the validator teaches the real paths — a registered covering
|
|
4051
|
+
// font behind a binding, a vector icon, or plain words.
|
|
3840
4052
|
const emoji = "<column>\n <bubble><text>hi</text><reactions>\u{1F44D}</reactions></bubble>\n</column>";
|
|
3841
4053
|
var parser = canvas.ui_markup.Parser.init(arena, emoji);
|
|
3842
4054
|
const document = try parser.parse();
|
|
@@ -312,6 +312,23 @@ pub const elements = [_]ElementInfo{
|
|
|
312
312
|
// end, the reference's trailing dock), so the element mints ONE
|
|
313
313
|
// code and no attribute codes at all.
|
|
314
314
|
.{ .code = 65, .name = "reactions", .rule_hook = "reactions" },
|
|
315
|
+
// The media surface: a leaf compositing a texture PRODUCED OUTSIDE
|
|
316
|
+
// the widget tree (video decoder, camera preview, an external
|
|
317
|
+
// renderer like mpv) into the layout like any widget. Its `surface`
|
|
318
|
+
// attribute binds the model-owned u64 surface id a producer targets
|
|
319
|
+
// (`Runtime.acquireMediaSurfaceProducer`) — the runtime-image-id
|
|
320
|
+
// binding shape, never a markup literal. Display-only like image
|
|
321
|
+
// and chart (presses fall through); pictorial for the a11y lint.
|
|
322
|
+
.{ .code = 66, .name = "media-surface", .widget_kind = "media_surface", .hit_target = false, .a11y_name = .image },
|
|
323
|
+
// The image leaf: draws a RUNTIME-REGISTERED image by its
|
|
324
|
+
// model-owned u64 ImageId — the id `Cmd.imageLoad` /
|
|
325
|
+
// `fx.loadImage` / `fx.registerImageBytes` registered pixels
|
|
326
|
+
// under. Its `image` attribute is the avatar binding shape exactly
|
|
327
|
+
// (attr 38, scope broadened): one {binding}, never a markup
|
|
328
|
+
// literal; 0 draws nothing (the image-leaf convention — an avatar
|
|
329
|
+
// falls back to initials instead). Display-only like media-surface
|
|
330
|
+
// and chart (presses fall through); pictorial for the a11y lint.
|
|
331
|
+
.{ .code = 67, .name = "image", .widget_kind = "image", .hit_target = false, .a11y_name = .image },
|
|
315
332
|
};
|
|
316
333
|
|
|
317
334
|
// ------------------------------------------------------------- attributes
|
|
@@ -363,6 +380,10 @@ pub const attrs = [_]AttrInfo{
|
|
|
363
380
|
// Element-scoped specials.
|
|
364
381
|
.{ .code = 36, .name = "name", .class = .icon, .group = .element },
|
|
365
382
|
.{ .code = 37, .name = "icon", .class = .icon, .group = .element },
|
|
383
|
+
// The runtime-image binding (avatar and image; the validator
|
|
384
|
+
// scopes it): one {binding} to the model-owned u64 ImageId the app
|
|
385
|
+
// registered at runtime — ids are model data, never markup
|
|
386
|
+
// literals; 0 is the no-image sentinel.
|
|
366
387
|
.{ .code = 38, .name = "image", .class = .binding_only, .group = .element },
|
|
367
388
|
.{ .code = 39, .name = "anchor", .class = .option, .group = .element },
|
|
368
389
|
.{ .code = 40, .name = "anchor-alignment", .class = .option, .group = .element },
|
|
@@ -464,6 +485,14 @@ pub const attrs = [_]AttrInfo{
|
|
|
464
485
|
// unreachable from markup; absent keeps the token default
|
|
465
486
|
// (`ControlMetricTokens.tooltip_show_delay_ms`).
|
|
466
487
|
.{ .code = 80, .name = "tooltip-delay", .class = .whole, .group = .option, .field = "tooltip_delay" },
|
|
488
|
+
// The media-surface producer rendezvous (media-surface only; the
|
|
489
|
+
// validator scopes it): one {binding} to the model-owned u64 surface
|
|
490
|
+
// id a producer targets (`Runtime.acquireMediaSurfaceProducer`) —
|
|
491
|
+
// ids are model data in the runtime-image-id spirit, never markup
|
|
492
|
+
// literals; 0 is the unbound sentinel (the surface draws nothing,
|
|
493
|
+
// like an image leaf with id 0), and usable ids stay below the
|
|
494
|
+
// reserved namespace bit (bit 63), which acquire refuses.
|
|
495
|
+
.{ .code = 81, .name = "surface", .class = .binding_only, .group = .element },
|
|
467
496
|
};
|
|
468
497
|
|
|
469
498
|
// ----------------------------------------------------------------- events
|
|
@@ -21,15 +21,14 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
|
|
|
21
21
|
// (append or slot them anywhere — order carries no meaning) and pin
|
|
22
22
|
// the new fingerprint ONLY for additions; renames/renumbers are
|
|
23
23
|
// schema-version-bump events, not silent edits.
|
|
24
|
-
try testing.expectEqual(@as(usize,
|
|
25
|
-
try testing.expectEqual(@as(usize,
|
|
24
|
+
try testing.expectEqual(@as(usize, 67), schema.elements.len);
|
|
25
|
+
try testing.expectEqual(@as(usize, 81), schema.attrs.len);
|
|
26
26
|
try testing.expectEqual(@as(usize, 10), schema.events.len);
|
|
27
|
-
// The element table runs through the span composite (64)
|
|
28
|
-
// bubble-reactions composite (65)
|
|
29
|
-
//
|
|
30
|
-
// leave the attr table untouched.
|
|
27
|
+
// The element table runs through the span composite (64), the
|
|
28
|
+
// bubble-reactions composite (65), the media surface (66), and the
|
|
29
|
+
// runtime-image leaf (67).
|
|
31
30
|
try testing.expectEqual(
|
|
32
|
-
@as(u64,
|
|
31
|
+
@as(u64, 0x2a68661a562f0565),
|
|
33
32
|
tableFingerprint(schema.ElementInfo, &schema.elements),
|
|
34
33
|
);
|
|
35
34
|
// The attr table runs through the split layout-tween attributes
|
|
@@ -37,10 +36,11 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
|
|
|
37
36
|
// attributes x-labels (73), y-labels (74), and hover-details (75),
|
|
38
37
|
// the later span additions scale (76) and underline (77), the
|
|
39
38
|
// split enter-from attribute resize-origin (78), the quiet-surface
|
|
40
|
-
// hover knob quiet-hover (79),
|
|
41
|
-
// delay tooltip-delay (80)
|
|
39
|
+
// hover knob quiet-hover (79), the anchored-tooltip hover-intent
|
|
40
|
+
// delay tooltip-delay (80), and the media-surface producer
|
|
41
|
+
// rendezvous surface (81).
|
|
42
42
|
try testing.expectEqual(
|
|
43
|
-
@as(u64,
|
|
43
|
+
@as(u64, 0x046479d29c4f0c5e),
|
|
44
44
|
tableFingerprint(schema.AttrInfo, &schema.attrs),
|
|
45
45
|
);
|
|
46
46
|
try testing.expectEqual(
|
|
@@ -91,7 +91,7 @@ test "registry event scoping names registry elements" {
|
|
|
91
91
|
test "derived name lists mirror the registry" {
|
|
92
92
|
// The derivations are the vocabulary every consumer reads; hold them
|
|
93
93
|
// to the registry's own predicates.
|
|
94
|
-
try testing.expectEqual(@as(usize,
|
|
94
|
+
try testing.expectEqual(@as(usize, 55), schema.element_names.len);
|
|
95
95
|
for (schema.element_names) |name| {
|
|
96
96
|
try testing.expect(schema.elementByName(name).?.rule_hook == null);
|
|
97
97
|
}
|
|
@@ -354,6 +354,36 @@ test "textarea keyboard: enter edits a newline, submit rides the primary chord"
|
|
|
354
354
|
try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(textarea.id, alt_enter));
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
test "single-line keyboard fallback derivation sanitizes line breaks like the runtime seam" {
|
|
358
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
359
|
+
defer arena_state.deinit();
|
|
360
|
+
|
|
361
|
+
var ui = InboxUi.init(arena_state.allocator());
|
|
362
|
+
const tree = try ui.finalize(ui.column(.{ .gap = 8 }, .{
|
|
363
|
+
ui.el(.text_field, .{ .on_input = InboxUi.inputMsg(.draft) }, .{}),
|
|
364
|
+
ui.el(.textarea, .{ .on_input = InboxUi.inputMsg(.draft) }, .{}),
|
|
365
|
+
}));
|
|
366
|
+
const field = findByKind(tree.root, .text_field).?;
|
|
367
|
+
const textarea = findByKind(tree.root, .textarea).?;
|
|
368
|
+
|
|
369
|
+
// An un-stamped text_input event (a direct Tree consumer — nothing
|
|
370
|
+
// crossed the runtime) derives its insert locally, and the local
|
|
371
|
+
// derivation applies the SAME single-line sanitize rule the runtime
|
|
372
|
+
// seam stamps with: line breaks strip, so a model mirror can never
|
|
373
|
+
// hear bytes the retained editor would refuse.
|
|
374
|
+
const multi_line = canvas.WidgetKeyboardEvent{ .phase = .text_input, .text = "a\nb\r\nc" };
|
|
375
|
+
try testing.expectEqualStrings("abc", tree.msgForKeyboard(field.id, multi_line).?.draft.insert_text);
|
|
376
|
+
try testing.expectEqualStrings("a\nb\r\nc", tree.msgForKeyboard(textarea.id, multi_line).?.draft.insert_text);
|
|
377
|
+
|
|
378
|
+
// An insert that is ONLY breaks suppresses outright.
|
|
379
|
+
const bare_breaks = canvas.WidgetKeyboardEvent{ .phase = .text_input, .text = "\r\n" };
|
|
380
|
+
try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(field.id, bare_breaks));
|
|
381
|
+
|
|
382
|
+
// A STAMPED edit (the runtime already sanitized it) passes through.
|
|
383
|
+
const stamped = canvas.WidgetKeyboardEvent{ .phase = .key_down, .edit = .{ .insert_text = "clean" } };
|
|
384
|
+
try testing.expectEqualStrings("clean", tree.msgForKeyboard(field.id, stamped).?.draft.insert_text);
|
|
385
|
+
}
|
|
386
|
+
|
|
357
387
|
test "typed handlers imply accessibility actions" {
|
|
358
388
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
359
389
|
defer arena_state.deinit();
|
|
@@ -1402,6 +1432,7 @@ test "widget kind codes are pinned: assigned at birth, declaration-order-indepen
|
|
|
1402
1432
|
.{ .kind = .split_divider, .code = 58 },
|
|
1403
1433
|
.{ .kind = .tree, .code = 59 },
|
|
1404
1434
|
.{ .kind = .input_group, .code = 60 },
|
|
1435
|
+
.{ .kind = .media_surface, .code = 61 },
|
|
1405
1436
|
};
|
|
1406
1437
|
try testing.expectEqual(std.enums.values(canvas.WidgetKind).len, expected.len);
|
|
1407
1438
|
for (expected) |entry| {
|