@native-sdk/cli 0.5.3 → 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 +223 -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/src/emitter.ts +2586 -259
- package/skill-data/native-ui/SKILL.md +3 -2
- package/skill-data/ts-core/SKILL.md +9 -1
- package/src/app_runner/root.zig +81 -1
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/embed/tests.zig +119 -1
- package/src/platform/linux/gtk_host.c +112 -3
- package/src/platform/linux/root.zig +71 -0
- package/src/platform/macos/appkit_host.h +48 -2
- package/src/platform/macos/appkit_host.m +533 -34
- package/src/platform/macos/cef_host.mm +262 -10
- package/src/platform/macos/root.zig +92 -4
- package/src/platform/null_platform.zig +298 -5
- package/src/platform/root.zig +33 -0
- package/src/platform/types.zig +138 -4
- 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/tests.zig +1 -0
- package/src/primitives/canvas/ui.zig +11 -7
- package/src/primitives/canvas/ui_markup.zig +58 -34
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +23 -8
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1 -1
- package/src/primitives/canvas/ui_markup_contract_tests.zig +26 -0
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_tests.zig +29 -9
- package/src/primitives/canvas/ui_markup_view.zig +29 -11
- package/src/primitives/canvas/ui_markup_view_tests.zig +150 -9
- package/src/primitives/canvas/ui_schema.zig +13 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +6 -4
- 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 +439 -2
- package/src/runtime/canvas_fonts.zig +61 -6
- package/src/runtime/canvas_image_tests.zig +195 -0
- package/src/runtime/canvas_images.zig +45 -12
- package/src/runtime/core.zig +58 -11
- 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 +17 -0
- package/src/runtime/root.zig +11 -0
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +85 -21
- package/src/runtime/session_record.zig +27 -2
- package/src/runtime/session_replay.zig +168 -16
- package/src/runtime/session_tests.zig +1992 -0
- 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 +2 -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 +7 -0
- package/src/runtime/ui_app.zig +111 -6
- 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
|
@@ -149,6 +149,13 @@ pub const MarkupDocument = struct {
|
|
|
149
149
|
/// all templates is valid as an import target, but an app view needs
|
|
150
150
|
/// a root, which the engines enforce with a teaching error.
|
|
151
151
|
root: ?MarkupNode = null,
|
|
152
|
+
/// Total bytes of markup source this document was built from — the
|
|
153
|
+
/// parsed file, or every resolved file after import resolution. Both
|
|
154
|
+
/// parsers and both resolvers stamp it, so comptime branch-quota
|
|
155
|
+
/// scaling (`canonicalizeComptime`) can size its walk in O(1) instead
|
|
156
|
+
/// of recursing over the tree, which would itself exhaust the caller's
|
|
157
|
+
/// default quota on large documents.
|
|
158
|
+
source_bytes: usize = 0,
|
|
152
159
|
|
|
153
160
|
pub fn templateIndex(self: MarkupDocument, name: []const u8) ?usize {
|
|
154
161
|
for (self.templates, 0..) |template_node, index| {
|
|
@@ -235,7 +242,7 @@ pub const Parser = struct {
|
|
|
235
242
|
if (imports.items.len == 0 and templates.items.len == 0) {
|
|
236
243
|
return self.fail(empty_document_message);
|
|
237
244
|
}
|
|
238
|
-
return .{ .imports = imports.items, .templates = templates.items, .root = null };
|
|
245
|
+
return .{ .imports = imports.items, .templates = templates.items, .root = null, .source_bytes = self.source.len };
|
|
239
246
|
}
|
|
240
247
|
const node = try self.parseElement();
|
|
241
248
|
if (node.kind == .import_block) {
|
|
@@ -256,7 +263,7 @@ pub const Parser = struct {
|
|
|
256
263
|
if (self.index < self.source.len) {
|
|
257
264
|
return self.fail("expected end of file after the root element");
|
|
258
265
|
}
|
|
259
|
-
return .{ .imports = imports.items, .templates = templates.items, .root = node };
|
|
266
|
+
return .{ .imports = imports.items, .templates = templates.items, .root = node, .source_bytes = self.source.len };
|
|
260
267
|
}
|
|
261
268
|
}
|
|
262
269
|
|
|
@@ -561,7 +568,7 @@ pub fn parseComptime(comptime source: []const u8) MarkupDocument {
|
|
|
561
568
|
if (imports.len == 0 and templates.len == 0) {
|
|
562
569
|
failComptime(&parser, parser.fail(empty_document_message));
|
|
563
570
|
}
|
|
564
|
-
return .{ .imports = imports, .templates = templates, .root = null };
|
|
571
|
+
return .{ .imports = imports, .templates = templates, .root = null, .source_bytes = source.len };
|
|
565
572
|
}
|
|
566
573
|
const node = parseElementComptime(&parser);
|
|
567
574
|
if (node.kind == .import_block) {
|
|
@@ -582,7 +589,7 @@ pub fn parseComptime(comptime source: []const u8) MarkupDocument {
|
|
|
582
589
|
if (parser.index < parser.source.len) {
|
|
583
590
|
failComptime(&parser, parser.fail("expected end of file after the root element"));
|
|
584
591
|
}
|
|
585
|
-
return .{ .imports = imports, .templates = templates, .root = node };
|
|
592
|
+
return .{ .imports = imports, .templates = templates, .root = node, .source_bytes = source.len };
|
|
586
593
|
}
|
|
587
594
|
}
|
|
588
595
|
}
|
|
@@ -980,11 +987,16 @@ fn typedTextSegments(arena: std.mem.Allocator, text: []const u8) error{OutOfMemo
|
|
|
980
987
|
|
|
981
988
|
/// Comptime mirror of `canonicalize` for the compiled engine's documents:
|
|
982
989
|
/// same classification, same segment scan, with comptime consts in place
|
|
983
|
-
/// of arena allocations. The branch quota scales with the
|
|
990
|
+
/// of arena allocations. The branch quota scales with the source the
|
|
991
|
+
/// document was parsed from.
|
|
984
992
|
pub fn canonicalizeComptime(comptime document: MarkupDocument) MarkupDocument {
|
|
985
993
|
comptime {
|
|
994
|
+
// Invariant: a quota argument must never recurse over the tree it
|
|
995
|
+
// is budgeting — it evaluates under the CALLER's quota, so the
|
|
996
|
+
// measurement itself would exhaust the default 1000 branches on a
|
|
997
|
+
// large document. `source_bytes` is stamped at parse time (O(1)).
|
|
986
998
|
@setEvalBranchQuota(comptime_parse_quota_base +
|
|
987
|
-
(
|
|
999
|
+
(document.source_bytes + 1) * comptime_canonicalize_quota_per_byte);
|
|
988
1000
|
var out = document;
|
|
989
1001
|
var templates: []const MarkupNode = &.{};
|
|
990
1002
|
for (document.templates) |template_node| {
|
|
@@ -996,26 +1008,13 @@ pub fn canonicalizeComptime(comptime document: MarkupDocument) MarkupDocument {
|
|
|
996
1008
|
}
|
|
997
1009
|
}
|
|
998
1010
|
|
|
1011
|
+
/// Tuned against the canonicalize walk's comptime slice concatenation
|
|
1012
|
+
/// (`children ++`/`attrs ++` re-copy per element) with wide safety margin.
|
|
1013
|
+
/// The scale, `source_bytes`, only grew when it replaced the old measured
|
|
1014
|
+
/// tree size (node text/names/attrs): the source carries every one of
|
|
1015
|
+
/// those bytes plus all markup syntax, so the constant keeps its headroom.
|
|
999
1016
|
const comptime_canonicalize_quota_per_byte = 400;
|
|
1000
1017
|
|
|
1001
|
-
fn documentByteSize(comptime document: MarkupDocument) usize {
|
|
1002
|
-
comptime {
|
|
1003
|
-
var total: usize = 0;
|
|
1004
|
-
for (document.templates) |template_node| total += nodeByteSize(template_node);
|
|
1005
|
-
if (document.root) |root| total += nodeByteSize(root);
|
|
1006
|
-
return total;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
fn nodeByteSize(comptime node: MarkupNode) usize {
|
|
1011
|
-
comptime {
|
|
1012
|
-
var total: usize = node.text.len + node.name.len;
|
|
1013
|
-
for (node.attrs) |attribute| total += attribute.name.len + attribute.value.len;
|
|
1014
|
-
for (node.children) |child| total += nodeByteSize(child);
|
|
1015
|
-
return total;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
1018
|
fn canonicalizeNodeComptime(comptime node: MarkupNode) MarkupNode {
|
|
1020
1019
|
comptime {
|
|
1021
1020
|
var out = node;
|
|
@@ -1247,8 +1246,10 @@ pub const tooltip_delay_element_message = "tooltip-delay is only supported on to
|
|
|
1247
1246
|
|
|
1248
1247
|
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
1248
|
|
|
1250
|
-
pub const
|
|
1251
|
-
pub const
|
|
1249
|
+
pub const image_binding_message = "image takes one {binding} to a u64 ImageId the app registered at runtime (Cmd.imageLoad, fx.loadImage, fx.registerImageBytes) - runtime image ids are model data, not markup literals; 0 renders nothing (an avatar falls back to its initials)";
|
|
1250
|
+
pub const image_binding_element_message = "image is only supported on avatar and image - the remaining image-bearing widget (icon-button) stays a Zig view (ElementOptions.image)";
|
|
1251
|
+
pub const image_missing_image_message = "image requires image={binding} naming the u64 ImageId the app registered at runtime - without one the leaf can never draw anything (dead markup, same policy as icon without name)";
|
|
1252
|
+
pub const image_children_message = "image is a leaf - it takes no children";
|
|
1252
1253
|
|
|
1253
1254
|
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
1255
|
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";
|
|
@@ -1676,7 +1677,7 @@ fn trimBlank(text: []const u8) []const u8 {
|
|
|
1676
1677
|
return std.mem.trim(u8, text, " \t\r\n");
|
|
1677
1678
|
}
|
|
1678
1679
|
|
|
1679
|
-
pub const font_coverage_message = "this text contains a character outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths; use a vector icon (<icon name=\"...\"/> or the icon attribute) or plain words";
|
|
1680
|
+
pub const font_coverage_message = "this text contains a character outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths; register a font that covers it (UiApp Options.fonts) and bind the text from the model, use a vector icon (<icon name=\"...\"/> or the icon attribute), or plain words";
|
|
1680
1681
|
|
|
1681
1682
|
pub const UncoveredCodepoint = struct {
|
|
1682
1683
|
/// Byte offset of the codepoint within the scanned literal.
|
|
@@ -2938,6 +2939,15 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
2938
2939
|
// teaching (the icon-without-name policy).
|
|
2939
2940
|
if (node.attr("surface") == null) return errorAt(node, media_surface_missing_surface_message);
|
|
2940
2941
|
}
|
|
2942
|
+
if (std.mem.eql(u8, node.name, "image")) {
|
|
2943
|
+
// An image leaf without its id binding can never draw:
|
|
2944
|
+
// the same dead-markup policy as media-surface.
|
|
2945
|
+
if (node.attr("image") == null) return errorAt(node, image_missing_image_message);
|
|
2946
|
+
// A leaf like icon: widget layout gives an image no
|
|
2947
|
+
// child slots, so any nested content would silently
|
|
2948
|
+
// vanish - rejected instead (icon's policy exactly).
|
|
2949
|
+
if (node.children.len > 0) return errorAt(node.children[0], image_children_message);
|
|
2950
|
+
}
|
|
2941
2951
|
if (std.mem.eql(u8, node.name, "split")) {
|
|
2942
2952
|
// Exactly two pane children, statically: the divider sits
|
|
2943
2953
|
// between fixed panes, so conditional/repeated content
|
|
@@ -3062,14 +3072,16 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
3062
3072
|
continue;
|
|
3063
3073
|
}
|
|
3064
3074
|
if (std.mem.eql(u8, attribute.name, "image")) {
|
|
3065
|
-
// Runtime image binding,
|
|
3066
|
-
//
|
|
3067
|
-
|
|
3068
|
-
|
|
3075
|
+
// Runtime image binding, scoped to the two widgets
|
|
3076
|
+
// drawing a registered ImageId (avatar's fallback
|
|
3077
|
+
// circle and the image leaf): ids are model data
|
|
3078
|
+
// the app registered, never markup literals.
|
|
3079
|
+
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) {
|
|
3080
|
+
return attrError(node, attribute, image_binding_element_message);
|
|
3069
3081
|
}
|
|
3070
3082
|
const expression = parseAttrExpression(attribute.value);
|
|
3071
3083
|
if (expression == null or expression.? != .binding) {
|
|
3072
|
-
return attrError(node, attribute,
|
|
3084
|
+
return attrError(node, attribute, image_binding_message);
|
|
3073
3085
|
}
|
|
3074
3086
|
continue;
|
|
3075
3087
|
}
|
|
@@ -3514,7 +3526,7 @@ pub fn resolveImports(
|
|
|
3514
3526
|
.diagnostic = diagnostic,
|
|
3515
3527
|
};
|
|
3516
3528
|
const root = try resolver.visit(root_name, root_source, 0);
|
|
3517
|
-
return .{ .imports = &.{}, .templates = resolver.templates.items, .root = root };
|
|
3529
|
+
return .{ .imports = &.{}, .templates = resolver.templates.items, .root = root, .source_bytes = resolver.source_bytes };
|
|
3518
3530
|
}
|
|
3519
3531
|
|
|
3520
3532
|
const ImportResolver = struct {
|
|
@@ -3529,12 +3541,17 @@ const ImportResolver = struct {
|
|
|
3529
3541
|
/// The in-progress import chain, for cycle reporting.
|
|
3530
3542
|
chain: [max_import_depth][]const u8 = undefined,
|
|
3531
3543
|
file_count: usize = 0,
|
|
3544
|
+
/// Sum of every resolved file's source length — stamped onto the
|
|
3545
|
+
/// merged document as `source_bytes`, so it covers the whole tree the
|
|
3546
|
+
/// canonicalize walk will visit, imported templates included.
|
|
3547
|
+
source_bytes: usize = 0,
|
|
3532
3548
|
|
|
3533
3549
|
/// Parse one file, resolve its imports depth-first, splice its
|
|
3534
3550
|
/// templates, and return its stamped view root (null for a component
|
|
3535
3551
|
/// file). Only the root file (depth 0) may have a view root.
|
|
3536
3552
|
fn visit(self: *ImportResolver, path: []const u8, source: []const u8, depth: usize) ResolveError!?MarkupNode {
|
|
3537
3553
|
self.chain[depth] = path;
|
|
3554
|
+
self.source_bytes += source.len;
|
|
3538
3555
|
var parser = Parser.init(self.arena, source);
|
|
3539
3556
|
const document = parser.parse() catch |err| {
|
|
3540
3557
|
if (err == error.MarkupSyntax) {
|
|
@@ -3729,6 +3746,10 @@ fn dirnamePath(path: []const u8) []const u8 {
|
|
|
3729
3746
|
/// would report, prefixed with the offending file.
|
|
3730
3747
|
pub fn resolveImportsComptime(comptime root_name: []const u8, comptime sources: []const SourceFile) MarkupDocument {
|
|
3731
3748
|
comptime {
|
|
3749
|
+
// The summing loop runs under the CALLER's quota (a quota argument
|
|
3750
|
+
// must never walk anything unbounded first), so budget it from the
|
|
3751
|
+
// O(1) set length before deriving the byte-scaled quota from it.
|
|
3752
|
+
@setEvalBranchQuota(comptime_parse_quota_base + sources.len * 100);
|
|
3732
3753
|
var total_len: usize = 0;
|
|
3733
3754
|
for (sources) |file| total_len += file.source.len;
|
|
3734
3755
|
@setEvalBranchQuota(comptime_parse_quota_base + total_len * comptime_parse_quota_per_byte + (sources.len + 1) * 50_000);
|
|
@@ -3738,7 +3759,10 @@ pub fn resolveImportsComptime(comptime root_name: []const u8, comptime sources:
|
|
|
3738
3759
|
var templates: []const MarkupNode = &.{};
|
|
3739
3760
|
var visited: []const []const u8 = &.{};
|
|
3740
3761
|
const root = visitComptime(root_name, root_source, sources, dirnamePath(root_name), &templates, &visited, &.{});
|
|
3741
|
-
|
|
3762
|
+
// `total_len` covers the whole embedded set — a superset of the
|
|
3763
|
+
// files resolution actually visited — so the canonicalize walk
|
|
3764
|
+
// over the merged tree (imported templates included) is budgeted.
|
|
3765
|
+
return .{ .imports = &.{}, .templates = templates, .root = root, .source_bytes = total_len };
|
|
3742
3766
|
}
|
|
3743
3767
|
}
|
|
3744
3768
|
|
|
@@ -419,7 +419,10 @@ pub fn decode(arena: std.mem.Allocator, bytes: []const u8, diagnostic: *CodecDia
|
|
|
419
419
|
for (templates) |*template_node| {
|
|
420
420
|
template_node.* = try decoder.node(0);
|
|
421
421
|
}
|
|
422
|
-
|
|
422
|
+
// `source_bytes` sizes the tree for quota scaling; the artifact
|
|
423
|
+
// carries every node's text/names/attrs, so its length is the honest
|
|
424
|
+
// stand-in for the source this document no longer has.
|
|
425
|
+
var document = markup.MarkupDocument{ .templates = templates, .source_bytes = bytes.len };
|
|
423
426
|
if (try decoder.byte() != 0) {
|
|
424
427
|
document.root = try decoder.node(0);
|
|
425
428
|
}
|
|
@@ -405,6 +405,21 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
405
405
|
}
|
|
406
406
|
if (pane_count != 2) fail(node, markup.split_children_message);
|
|
407
407
|
}
|
|
408
|
+
// Interpreter parity: the image leaf's static shape.
|
|
409
|
+
// Without its id binding the leaf can never draw —
|
|
410
|
+
// statically dead markup, a compile error here too. And
|
|
411
|
+
// it takes no children at all (icon's leaf policy): the
|
|
412
|
+
// check reads the ORIGINAL node, so an extracted
|
|
413
|
+
// context-menu still counts as a child exactly like the
|
|
414
|
+
// validator's raw-node check.
|
|
415
|
+
if (kind == .image) {
|
|
416
|
+
if (node.attr("image") == null) {
|
|
417
|
+
fail(node, markup.image_missing_image_message);
|
|
418
|
+
}
|
|
419
|
+
if (node.children.len > 0) {
|
|
420
|
+
fail(node, markup.image_children_message);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
408
423
|
// Interpreter parity: the a11y lint's error half — an
|
|
409
424
|
// unnamed interactive control or a misused role ships a
|
|
410
425
|
// view a screen reader user cannot operate, so it is a
|
|
@@ -1656,18 +1671,18 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1656
1671
|
}
|
|
1657
1672
|
|
|
1658
1673
|
/// Comptime mirror of the interpreter's `applyImageAttr`:
|
|
1659
|
-
/// `image="{binding}"` on avatar resolves to a `u64`
|
|
1660
|
-
/// app registered at runtime —
|
|
1661
|
-
/// binding must produce an integer, all checked at comptime
|
|
1662
|
-
/// the interpreter's messages.
|
|
1674
|
+
/// `image="{binding}"` on avatar and image resolves to a `u64`
|
|
1675
|
+
/// ImageId the app registered at runtime — binding-only, and
|
|
1676
|
+
/// the binding must produce an integer, all checked at comptime
|
|
1677
|
+
/// with the interpreter's messages.
|
|
1663
1678
|
fn applyImageAttr(comptime node: markup.MarkupNode, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
1664
1679
|
comptime {
|
|
1665
|
-
if (!std.mem.eql(u8, node.name, "avatar")) fail(node, markup.
|
|
1666
|
-
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.
|
|
1667
|
-
if (expression != .binding) fail(node, markup.
|
|
1680
|
+
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) fail(node, markup.image_binding_element_message);
|
|
1681
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.image_binding_message);
|
|
1682
|
+
if (expression != .binding) fail(node, markup.image_binding_message);
|
|
1668
1683
|
}
|
|
1669
1684
|
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
1670
|
-
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.
|
|
1685
|
+
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.image_binding_message);
|
|
1671
1686
|
// Range-checked before the u64 cast (the interpreter fails
|
|
1672
1687
|
// the same way): a signed model field (`image: i64 = -1`)
|
|
1673
1688
|
// can deliver a negative — fail the build, never trap.
|
|
@@ -1251,6 +1251,61 @@ test "compiled avatar and media-surface id bindings refuse negative model values
|
|
|
1251
1251
|
try testing.expectError(error.OutOfMemory, surface_ui.finalize(surface_node));
|
|
1252
1252
|
}
|
|
1253
1253
|
|
|
1254
|
+
// ------------------------------------------------ image leaf id binding
|
|
1255
|
+
|
|
1256
|
+
const ImageLeafUi = fixture.ImageLeafUi;
|
|
1257
|
+
const ImageLeafInterpreter = markup_view.MarkupView(fixture.ImageLeafModel, fixture.ImageLeafMsg);
|
|
1258
|
+
const ImageLeafCompiled = canvas.CompiledMarkupView(fixture.ImageLeafModel, fixture.ImageLeafMsg, fixture.image_markup_source);
|
|
1259
|
+
const ImageLeafNegativeCompiled = canvas.CompiledMarkupView(fixture.ImageLeafModel, fixture.ImageLeafMsg, fixture.image_negative_markup_source);
|
|
1260
|
+
|
|
1261
|
+
test "compiled image leaf binding matches the interpreter and the hand-written view" {
|
|
1262
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1263
|
+
defer arena_state.deinit();
|
|
1264
|
+
const arena = arena_state.allocator();
|
|
1265
|
+
|
|
1266
|
+
const model = fixture.ImageLeafModel{ .cover = 42 };
|
|
1267
|
+
|
|
1268
|
+
var view = try ImageLeafInterpreter.init(arena, fixture.image_markup_source);
|
|
1269
|
+
var interpreted_ui = ImageLeafUi.init(arena);
|
|
1270
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1271
|
+
|
|
1272
|
+
var compiled_ui = ImageLeafUi.init(arena);
|
|
1273
|
+
const compiled = try compiled_ui.finalize(ImageLeafCompiled.build(&compiled_ui, &model));
|
|
1274
|
+
|
|
1275
|
+
var hand_ui = ImageLeafUi.init(arena);
|
|
1276
|
+
const hand = try hand_ui.finalize(fixture.handImageLeafView(&hand_ui, &model));
|
|
1277
|
+
|
|
1278
|
+
try expectSameTree(fixture.ImageLeafMsg, hand, interpreted);
|
|
1279
|
+
try expectSameTree(fixture.ImageLeafMsg, hand, compiled);
|
|
1280
|
+
|
|
1281
|
+
// The field binding and the fn binding both resolve to the
|
|
1282
|
+
// widget's image id at comptime-unrolled access.
|
|
1283
|
+
const cover = compiled.root.children[0];
|
|
1284
|
+
try testing.expectEqual(canvas.WidgetKind.image, cover.kind);
|
|
1285
|
+
try testing.expectEqual(@as(canvas.ImageId, 42), cover.image_id);
|
|
1286
|
+
try testing.expectEqual(@as(canvas.ImageId, 43), compiled.root.children[1].image_id);
|
|
1287
|
+
|
|
1288
|
+
// 0 draws nothing in both engines — the not-loaded-yet state.
|
|
1289
|
+
const empty_model = fixture.ImageLeafModel{};
|
|
1290
|
+
var empty_ui = ImageLeafUi.init(arena);
|
|
1291
|
+
const empty = try empty_ui.finalize(ImageLeafCompiled.build(&empty_ui, &empty_model));
|
|
1292
|
+
try testing.expectEqual(@as(canvas.ImageId, 0), empty.root.children[0].image_id);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
test "compiled image leaf binding refuses negative model values instead of trapping" {
|
|
1296
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1297
|
+
defer arena_state.deinit();
|
|
1298
|
+
const arena = arena_state.allocator();
|
|
1299
|
+
|
|
1300
|
+
// A negative i64 binding into the u64 id seam latches the failed
|
|
1301
|
+
// build (the interpreter's teaching error mirrors it), and
|
|
1302
|
+
// finalize surfaces the failure — never an @intCast trap.
|
|
1303
|
+
var image_ui = ImageLeafUi.init(arena);
|
|
1304
|
+
const image_node = ImageLeafNegativeCompiled.build(&image_ui, &fixture.ImageLeafModel{});
|
|
1305
|
+
try testing.expect(image_ui.failed);
|
|
1306
|
+
try testing.expectError(error.OutOfMemory, image_ui.finalize(image_node));
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1254
1309
|
// ------------------------------------------------------ text wrap parity
|
|
1255
1310
|
|
|
1256
1311
|
const WrapUi = fixture.WrapUi;
|
|
@@ -1193,7 +1193,7 @@ const Checker = struct {
|
|
|
1193
1193
|
const expression = markup.parseAttrExpression(attribute.value) orelse continue;
|
|
1194
1194
|
if (expression != .binding) continue;
|
|
1195
1195
|
const resolved = try self.resolveBinding(node, expression.binding, true);
|
|
1196
|
-
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.
|
|
1196
|
+
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.image_binding_message);
|
|
1197
1197
|
continue;
|
|
1198
1198
|
}
|
|
1199
1199
|
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
@@ -743,6 +743,32 @@ test "the media-surface surface binding checks as a model integer" {
|
|
|
743
743
|
try testing.expectEqualStrings(markup.media_surface_surface_message, message);
|
|
744
744
|
}
|
|
745
745
|
|
|
746
|
+
test "the image leaf's image binding checks as a model integer" {
|
|
747
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
748
|
+
defer arena_state.deinit();
|
|
749
|
+
const arena = arena_state.allocator();
|
|
750
|
+
|
|
751
|
+
// An integer-producing binding passes on avatar and the image leaf
|
|
752
|
+
// alike — the exact grammar `native check`'s model-aware pass
|
|
753
|
+
// applies to TS and Zig cores.
|
|
754
|
+
const good = try parseFixture(arena,
|
|
755
|
+
\\<column>
|
|
756
|
+
\\ <image image="{count}" label="Cover art" />
|
|
757
|
+
\\ <avatar image="{count}">CT</avatar>
|
|
758
|
+
\\</column>
|
|
759
|
+
);
|
|
760
|
+
try testing.expectEqual(null, try contractMessage(arena, good, null));
|
|
761
|
+
|
|
762
|
+
// A non-integer binding is refused with the image teaching.
|
|
763
|
+
const wrong = try parseFixture(arena,
|
|
764
|
+
\\<column>
|
|
765
|
+
\\ <image image="{name}" label="Cover art" />
|
|
766
|
+
\\</column>
|
|
767
|
+
);
|
|
768
|
+
const message = (try contractMessage(arena, wrong, null)).?;
|
|
769
|
+
try testing.expectEqualStrings(markup.image_binding_message, message);
|
|
770
|
+
}
|
|
771
|
+
|
|
746
772
|
test "app: icon references check against the contract's registered icon list" {
|
|
747
773
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
748
774
|
defer arena_state.deinit();
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//! Compile-cost guard: a deliberately huge `.native` document — well past
|
|
2
|
+
//! 16KB of realistically nested markup — must build through the compiled
|
|
3
|
+
//! engine without the test (or any app) raising `@setEvalBranchQuota`.
|
|
4
|
+
//! Before the fix, `canonicalizeComptime` sized its quota by recursively
|
|
5
|
+
//! measuring the tree INSIDE the quota argument, which evaluates under the
|
|
6
|
+
//! caller's default 1000-backwards-branch budget — so any document past
|
|
7
|
+
//! ~10KB failed to compile with "evaluation exceeded 1000 backwards
|
|
8
|
+
//! branches" while the runtime interpreter handled it fine. The document
|
|
9
|
+
//! now carries `source_bytes` from parse/resolve time (O(1) to read);
|
|
10
|
+
//! this fixture is the regression tripwire for the single-file path, and
|
|
11
|
+
//! the import fixture below pins the resolver's size accounting (the
|
|
12
|
+
//! merged document's `source_bytes` must cover imported template trees,
|
|
13
|
+
//! not just the root file).
|
|
14
|
+
|
|
15
|
+
const std = @import("std");
|
|
16
|
+
const canvas = @import("root.zig");
|
|
17
|
+
const compiled_view = @import("ui_markup_compiled.zig");
|
|
18
|
+
|
|
19
|
+
const Item = struct {
|
|
20
|
+
id: u32,
|
|
21
|
+
name: []const u8,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const Model = struct {
|
|
25
|
+
title: []const u8 = "ops console",
|
|
26
|
+
count: u32 = 3,
|
|
27
|
+
items: []const Item = &.{},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const Msg = union(enum) {
|
|
31
|
+
refresh,
|
|
32
|
+
press: u32,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/// One realistic dashboard section, ~560 bytes of markup: a header row
|
|
36
|
+
/// with an interpolated title, a conditional status line, and a keyed-off
|
|
37
|
+
/// item list with per-item dispatch. Repeated enough times to put the
|
|
38
|
+
/// whole source safely past the old ~10KB comptime cliff.
|
|
39
|
+
fn sectionSource(comptime index: usize) []const u8 {
|
|
40
|
+
return std.fmt.comptimePrint(
|
|
41
|
+
\\ <panel padding="12">
|
|
42
|
+
\\ <row gap="8" cross="center">
|
|
43
|
+
\\ <badge radius="md">Section {d}</badge>
|
|
44
|
+
\\ <text grow="1">{{title}} - block {d} of the oversized regression document, padded with realistic prose so the source passes the old comptime measurement cliff.</text>
|
|
45
|
+
\\ <button size="sm" on-press="refresh">Reload</button>
|
|
46
|
+
\\ </row>
|
|
47
|
+
\\ <if test="{{count}}">
|
|
48
|
+
\\ <text>block {d} has {{count}} pending updates</text>
|
|
49
|
+
\\ </if>
|
|
50
|
+
\\ <for each="items" as="it">
|
|
51
|
+
\\ <row gap="6" cross="center">
|
|
52
|
+
\\ <text grow="1">{{it.name}}</text>
|
|
53
|
+
\\ <button size="sm" on-press="press:{{it.id}}">Open</button>
|
|
54
|
+
\\ </row>
|
|
55
|
+
\\ </for>
|
|
56
|
+
\\ </panel>
|
|
57
|
+
\\
|
|
58
|
+
, .{ index, index, index });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fn hugeSource(comptime sections: usize) []const u8 {
|
|
62
|
+
comptime {
|
|
63
|
+
// Quota for the fixture GENERATOR only (comptime string
|
|
64
|
+
// concatenation over ~20KB); the engine under test must get by on
|
|
65
|
+
// its own derived quotas.
|
|
66
|
+
@setEvalBranchQuota(1_000_000);
|
|
67
|
+
var source: []const u8 = "<column gap=\"8\">\n <text>{title}</text>\n";
|
|
68
|
+
for (0..sections) |index| {
|
|
69
|
+
source = source ++ sectionSource(index);
|
|
70
|
+
}
|
|
71
|
+
return source ++ "</column>\n";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const huge_source = hugeSource(36);
|
|
76
|
+
|
|
77
|
+
fn testItems() []const Item {
|
|
78
|
+
return &.{ .{ .id = 1, .name = "alpha" }, .{ .id = 2, .name = "beta" } };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
test "a 16KB+ document compiles through the compiled engine without raising the eval-branch quota" {
|
|
82
|
+
try std.testing.expect(huge_source.len >= 16_000);
|
|
83
|
+
|
|
84
|
+
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
85
|
+
defer arena_state.deinit();
|
|
86
|
+
const arena = arena_state.allocator();
|
|
87
|
+
|
|
88
|
+
var ui = canvas.Ui(Msg).init(arena);
|
|
89
|
+
const model: Model = .{ .items = testItems() };
|
|
90
|
+
const tree = try ui.finalize(compiled_view.CompiledMarkupView(Model, Msg, huge_source).build(&ui, &model));
|
|
91
|
+
|
|
92
|
+
// The whole document rendered: every section's badge, per-item
|
|
93
|
+
// dispatch from the last section's list, and the conditional branch.
|
|
94
|
+
var badges: usize = 0;
|
|
95
|
+
countKind(tree.root, .badge, &badges);
|
|
96
|
+
try std.testing.expectEqual(@as(usize, 36), badges);
|
|
97
|
+
var buttons: usize = 0;
|
|
98
|
+
countKind(tree.root, .button, &buttons);
|
|
99
|
+
try std.testing.expectEqual(@as(usize, 36 + 36 * 2), buttons);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// A component file carrying one huge template body. The root view is
|
|
103
|
+
/// tiny, so if import resolution failed to count imported sources into
|
|
104
|
+
/// the merged document's `source_bytes`, the canonicalize walk over the
|
|
105
|
+
/// spliced template tree would outrun its quota and this file would not
|
|
106
|
+
/// compile.
|
|
107
|
+
fn hugeTemplateSource(comptime rows: usize) []const u8 {
|
|
108
|
+
comptime {
|
|
109
|
+
@setEvalBranchQuota(1_000_000);
|
|
110
|
+
var source: []const u8 = "<template name=\"big-panel\" args=\"heading\">\n <column gap=\"4\">\n";
|
|
111
|
+
for (0..rows) |index| {
|
|
112
|
+
source = source ++ std.fmt.comptimePrint(
|
|
113
|
+
\\ <row gap="6" cross="center">
|
|
114
|
+
\\ <badge radius="md">{{heading}} {d}</badge>
|
|
115
|
+
\\ <text grow="1">imported row {d}, padded with enough literal prose that the imported file alone crosses the old comptime measurement cliff.</text>
|
|
116
|
+
\\ </row>
|
|
117
|
+
\\
|
|
118
|
+
, .{ index, index });
|
|
119
|
+
}
|
|
120
|
+
return source ++ " </column>\n</template>\n";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const huge_import_sources = [_]canvas.ui_markup.SourceFile{
|
|
125
|
+
.{ .path = "view.native", .source =
|
|
126
|
+
\\<import src="components/big.native"/>
|
|
127
|
+
\\<column gap="8">
|
|
128
|
+
\\ <use template="big-panel" heading="Imported" />
|
|
129
|
+
\\</column>
|
|
130
|
+
},
|
|
131
|
+
.{ .path = "components/big.native", .source = hugeTemplateSource(72) },
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
test "a large imported template compiles through the compiled engine's import resolution" {
|
|
135
|
+
try std.testing.expect(huge_import_sources[1].source.len >= 16_000);
|
|
136
|
+
|
|
137
|
+
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
138
|
+
defer arena_state.deinit();
|
|
139
|
+
const arena = arena_state.allocator();
|
|
140
|
+
|
|
141
|
+
const Compiled = canvas.CompiledMarkupImports(Model, Msg, "view.native", &huge_import_sources);
|
|
142
|
+
var ui = canvas.Ui(Msg).init(arena);
|
|
143
|
+
const model: Model = .{};
|
|
144
|
+
const tree = try ui.finalize(Compiled.build(&ui, &model));
|
|
145
|
+
|
|
146
|
+
var badges: usize = 0;
|
|
147
|
+
countKind(tree.root, .badge, &badges);
|
|
148
|
+
try std.testing.expectEqual(@as(usize, 72), badges);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fn countKind(widget: canvas.Widget, kind: canvas.WidgetKind, total: *usize) void {
|
|
152
|
+
if (widget.kind == kind) total.* += 1;
|
|
153
|
+
for (widget.children) |child| countKind(child, kind, total);
|
|
154
|
+
}
|
|
@@ -673,22 +673,42 @@ test "gap on stacking containers is rejected with the teaching error" {
|
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
|
|
676
|
-
test "the
|
|
676
|
+
test "the image attribute validates as one binding on avatar and image" {
|
|
677
677
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
678
678
|
defer arena_state.deinit();
|
|
679
679
|
const arena = arena_state.allocator();
|
|
680
680
|
|
|
681
|
-
// One {binding} on avatar is the whole grammar.
|
|
682
|
-
|
|
683
|
-
|
|
681
|
+
// One {binding} on avatar or the image leaf is the whole grammar.
|
|
682
|
+
const valid = [_][]const u8{
|
|
683
|
+
"<row>\n <avatar image=\"{user_image}\">CT</avatar>\n</row>",
|
|
684
|
+
"<row>\n <image image=\"{cover}\" width=\"120\" height=\"80\" label=\"Cover art\" />\n</row>",
|
|
685
|
+
};
|
|
686
|
+
for (valid) |source| {
|
|
687
|
+
var parser = markup.Parser.init(arena, source);
|
|
688
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
|
|
689
|
+
}
|
|
684
690
|
|
|
685
691
|
const cases = [_]struct { source: []const u8, message: []const u8 }{
|
|
686
692
|
// Runtime image ids are model data, never markup literals.
|
|
687
|
-
.{ .source = "<row>\n <avatar image=\"7\">CT</avatar>\n</row>", .message = markup.
|
|
688
|
-
.{ .source = "<row>\n <avatar image=\"{a == b}\">CT</avatar>\n</row>", .message = markup.
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
693
|
+
.{ .source = "<row>\n <avatar image=\"7\">CT</avatar>\n</row>", .message = markup.image_binding_message },
|
|
694
|
+
.{ .source = "<row>\n <avatar image=\"{a == b}\">CT</avatar>\n</row>", .message = markup.image_binding_message },
|
|
695
|
+
.{ .source = "<row>\n <image image=\"7\" label=\"Art\" />\n</row>", .message = markup.image_binding_message },
|
|
696
|
+
// Scoped to the two ImageId-drawing widgets: anywhere else the
|
|
697
|
+
// attribute would be silently inert.
|
|
698
|
+
.{ .source = "<row>\n <badge image=\"{user_image}\">3</badge>\n</row>", .message = markup.image_binding_element_message },
|
|
699
|
+
.{ .source = "<column>\n <panel image=\"{user_image}\" />\n</column>", .message = markup.image_binding_element_message },
|
|
700
|
+
// ...and required on the leaf: an unbound image is statically
|
|
701
|
+
// dead markup (avatar keeps its initials fallback instead).
|
|
702
|
+
.{ .source = "<row>\n <image label=\"Art\" />\n</row>", .message = markup.image_missing_image_message },
|
|
703
|
+
// The leaf takes no children (icon's policy): widget layout
|
|
704
|
+
// gives an image no child slots, so a nested caption would
|
|
705
|
+
// silently vanish instead of rendering.
|
|
706
|
+
.{ .source = "<row>\n <image image=\"{cover}\" label=\"Art\"><text>Caption</text></image>\n</row>", .message = markup.image_children_message },
|
|
707
|
+
// ...and the rejection reads the RAW node: an extracted
|
|
708
|
+
// context-menu (host metadata on a pressable host) still counts
|
|
709
|
+
// as a child - the leaf takes no children at all, and both
|
|
710
|
+
// engines check the original node the same way.
|
|
711
|
+
.{ .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>", .message = markup.image_children_message },
|
|
692
712
|
};
|
|
693
713
|
for (cases) |case| {
|
|
694
714
|
var case_parser = markup.Parser.init(arena, case.source);
|