@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
|
@@ -44,9 +44,37 @@ const render_fingerprints = @import("render_fingerprints.zig");
|
|
|
44
44
|
const vector = @import("vector.zig");
|
|
45
45
|
const font_ttf = @import("font_ttf.zig");
|
|
46
46
|
|
|
47
|
-
/// Element budget for one glyph outline
|
|
48
|
-
///
|
|
49
|
-
|
|
47
|
+
/// Element budget for one glyph outline, derived from the parser's
|
|
48
|
+
/// glyph budgets so every glyph a parsed face maps fits: a contour
|
|
49
|
+
/// emits at most one element per point plus a move, a closing quad, and
|
|
50
|
+
/// a close (points + 3*contours), taken over BOTH glyph forms the gate
|
|
51
|
+
/// admits — a simple glyph's maxima and a composite's flattened maxima
|
|
52
|
+
/// (`maxp.maxCompositePoints`/`maxCompositeContours`, which is what
|
|
53
|
+
/// this builder actually receives when a composite renders). The
|
|
54
|
+
/// budgets are currently equal, so the max is 1408 either way; the
|
|
55
|
+
/// derivation keeps capacity honest if they ever diverge. Stack shape:
|
|
56
|
+
/// at 28 B per element this is ~39 KiB in `drawGlyphOutline`; the edge
|
|
57
|
+
/// accumulator below it is the per-thread heap-resident
|
|
58
|
+
/// `vector.GlyphRasterizer` (see `reference_glyph_raster_scratch`), so
|
|
59
|
+
/// the builder is the only glyph raster state on the stack.
|
|
60
|
+
const reference_glyph_path_capacity: usize = @max(
|
|
61
|
+
font_ttf.max_glyph_points + 3 * font_ttf.max_glyph_contours,
|
|
62
|
+
font_ttf.max_composite_points + 3 * font_ttf.max_composite_contours,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/// Per-thread rasterizer for glyph fills: `vector.GlyphRasterizer`'s
|
|
66
|
+
/// derived budgets guarantee every outline the font registration gate
|
|
67
|
+
/// admits rasterizes (never a block fallback), which sizes it at
|
|
68
|
+
/// ~508 KiB — a per-thread heap slot behind one TLS pointer (the
|
|
69
|
+
/// lazy_tls pattern), not a stack temporary and not static TLS. Only
|
|
70
|
+
/// threads that ink a glyph through the reference renderer allocate it.
|
|
71
|
+
/// The array carries no default and stays uninitialized, exactly like
|
|
72
|
+
/// the stack `Rasterizer` it replaces; `vector.fillGlyphPath` resets it
|
|
73
|
+
/// per glyph.
|
|
74
|
+
const ReferenceGlyphRasterScratch = struct {
|
|
75
|
+
raster: vector.GlyphRasterizer,
|
|
76
|
+
};
|
|
77
|
+
const reference_glyph_raster_scratch = @import("lazy_tls.zig").LazyTls(ReferenceGlyphRasterScratch);
|
|
50
78
|
|
|
51
79
|
const referenceBlurKernel = reference_blur.referenceBlurKernel;
|
|
52
80
|
const referenceBlurSampleWithKernel = reference_blur.referenceBlurSampleWithKernel;
|
|
@@ -62,6 +90,19 @@ pub const ReferenceImage = struct {
|
|
|
62
90
|
width: usize,
|
|
63
91
|
height: usize,
|
|
64
92
|
pixels: []const u8,
|
|
93
|
+
/// Precomputed content fingerprint for the GPU cache planner
|
|
94
|
+
/// (`renderImageFingerprintForResource` uses it when nonzero instead
|
|
95
|
+
/// of hashing `pixels` at plan time). Media-surface textures set it
|
|
96
|
+
/// at adoption so a 60 fps producer never pays a full-buffer hash
|
|
97
|
+
/// per planned frame; 0 — every registered canvas image — keeps the
|
|
98
|
+
/// classic hash-the-bytes keying byte-identically.
|
|
99
|
+
content_fingerprint: u64 = 0,
|
|
100
|
+
/// PRESENTATION-ONLY resource: composited by live GPU/packet hosts,
|
|
101
|
+
/// invisible to the deterministic reference renderer (see the
|
|
102
|
+
/// policy comment in `findReferenceImage`). Media-surface textures
|
|
103
|
+
/// ride the image pipeline with this set, so producer output can
|
|
104
|
+
/// never leak into goldens, screenshots, or replay pixel marks.
|
|
105
|
+
presentation_only: bool = false,
|
|
65
106
|
};
|
|
66
107
|
|
|
67
108
|
/// One runtime-registered font face the reference renderer resolves text
|
|
@@ -772,9 +813,12 @@ pub const ReferenceRenderSurface = struct {
|
|
|
772
813
|
|
|
773
814
|
/// Paint one glyph: the real Geist outline through the vector core
|
|
774
815
|
/// when the codepoint resolves, the historical block rect otherwise
|
|
775
|
-
/// (unmapped codepoints, glyphs
|
|
776
|
-
///
|
|
777
|
-
///
|
|
816
|
+
/// (unmapped codepoints, glyphs of hostile faces whose `maxp`
|
|
817
|
+
/// under-declares — the per-glyph parse backstops — or draws
|
|
818
|
+
/// carrying no text bytes; never a gate-admitted glyph, whose raster
|
|
819
|
+
/// budgets are derived from the registration gate). Layout is
|
|
820
|
+
/// untouched — the pen position and advance still come from the
|
|
821
|
+
/// deterministic estimator.
|
|
778
822
|
fn drawGlyphBox(
|
|
779
823
|
self: ReferenceRenderSurface,
|
|
780
824
|
command: RenderCommand,
|
|
@@ -839,8 +883,14 @@ pub const ReferenceRenderSurface = struct {
|
|
|
839
883
|
.coverage_blend = .srgb,
|
|
840
884
|
};
|
|
841
885
|
// The outline is already in device space; TrueType interiorness
|
|
842
|
-
// is the nonzero rule.
|
|
843
|
-
|
|
886
|
+
// is the nonzero rule. The glyph raster budgets are derived from
|
|
887
|
+
// the registration gate's outline budgets, so a gate-admitted
|
|
888
|
+
// face never trips `VectorPathTooComplex` here — the remaining
|
|
889
|
+
// fallback triggers are a clip band wider than
|
|
890
|
+
// `max_raster_width` (surface-shaped, not font-shaped) and
|
|
891
|
+
// nothing else.
|
|
892
|
+
vector.fillGlyphPath(
|
|
893
|
+
&reference_glyph_raster_scratch.get().raster,
|
|
844
894
|
builder.slice(),
|
|
845
895
|
Affine.identity(),
|
|
846
896
|
.nonzero,
|
|
@@ -1255,6 +1305,15 @@ fn referenceImagePixelLen(width: usize, height: usize) ?usize {
|
|
|
1255
1305
|
|
|
1256
1306
|
fn findReferenceImage(images: []const ReferenceImage, id: ImageId) ?ReferenceImage {
|
|
1257
1307
|
for (images) |image| {
|
|
1308
|
+
// THE REFERENCE-RENDERER MEDIA POLICY: presentation-only
|
|
1309
|
+
// resources (media-surface textures pushed by external
|
|
1310
|
+
// producers) do not exist for the deterministic CPU path. The
|
|
1311
|
+
// draw referencing one skips — exactly like an unregistered id —
|
|
1312
|
+
// so the surface's id-derived placeholder beneath it is what
|
|
1313
|
+
// reference renders, screenshots, replay pixel marks, and
|
|
1314
|
+
// GOLDENS show. Goldens can therefore never depend on producer
|
|
1315
|
+
// output; only live GPU/packet hosts composite the real texture.
|
|
1316
|
+
if (image.presentation_only) continue;
|
|
1258
1317
|
if (image.id == id) return image;
|
|
1259
1318
|
}
|
|
1260
1319
|
return null;
|
|
@@ -53,6 +53,14 @@ pub fn renderImageFingerprintForResource(image_id: ImageId, image: ?ReferenceIma
|
|
|
53
53
|
var hash = renderImageFingerprint(image_id);
|
|
54
54
|
hash = resourceHashUsize(hash, value.width);
|
|
55
55
|
hash = resourceHashUsize(hash, value.height);
|
|
56
|
+
// A precomputed content fingerprint stands in for the pixel bytes:
|
|
57
|
+
// media-surface textures stamp one at adoption so the planner never
|
|
58
|
+
// re-hashes a full video frame per plan. Any content change changes
|
|
59
|
+
// the stamp, so upload/retain/evict keying is untouched; resources
|
|
60
|
+
// without one (every registered canvas image) hash bytes as always.
|
|
61
|
+
if (value.content_fingerprint != 0) {
|
|
62
|
+
return resourceHashU64(hash, value.content_fingerprint);
|
|
63
|
+
}
|
|
56
64
|
hash = resourceHashBytes(hash, value.pixels);
|
|
57
65
|
return hash;
|
|
58
66
|
}
|
|
@@ -58,6 +58,28 @@ pub const ObjectId = u64;
|
|
|
58
58
|
pub const ImageId = u64;
|
|
59
59
|
pub const FontId = u64;
|
|
60
60
|
|
|
61
|
+
/// Reserved namespace bit for MEDIA-SURFACE textures inside the ImageId
|
|
62
|
+
/// value space: a media surface bound to `surface_id` composites the
|
|
63
|
+
/// texture registered under `surface_id | media_surface_image_id_bit`,
|
|
64
|
+
/// so producer-pushed textures and app-registered canvas images can
|
|
65
|
+
/// never collide in the one flat id space draw commands reference.
|
|
66
|
+
/// Surface ids and registered canvas image ids must both stay BELOW the
|
|
67
|
+
/// bit — `Runtime.acquireMediaSurfaceProducer` and
|
|
68
|
+
/// `Runtime.registerCanvasImage` reject ids with it set, loudly.
|
|
69
|
+
pub const media_surface_image_id_bit: ImageId = 1 << 63;
|
|
70
|
+
|
|
71
|
+
/// The texture image id a media surface's draw command references for a
|
|
72
|
+
/// bound surface id (see `media_surface_image_id_bit`).
|
|
73
|
+
pub fn mediaSurfaceTextureImageId(surface_id: u64) ImageId {
|
|
74
|
+
return surface_id | media_surface_image_id_bit;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// The media surface's deterministic id-derived placeholder color
|
|
78
|
+
/// (widget_render.zig): what the reference renderer — goldens,
|
|
79
|
+
/// screenshots, replay pixel marks — shows for a bound surface, live
|
|
80
|
+
/// texture or not. Exported so tests pin the placeholder policy.
|
|
81
|
+
pub const mediaSurfacePlaceholderColor = @import("widget_render.zig").mediaSurfacePlaceholderColor;
|
|
82
|
+
|
|
61
83
|
pub const default_sans_font_id: FontId = 1;
|
|
62
84
|
pub const default_mono_font_id: FontId = 2;
|
|
63
85
|
// Reserved sans variant ids for inline span styling. The deterministic
|
|
@@ -172,6 +194,7 @@ pub const CommandRef = command_model.CommandRef;
|
|
|
172
194
|
pub const DiffKind = command_model.DiffKind;
|
|
173
195
|
pub const DiffChange = command_model.DiffChange;
|
|
174
196
|
pub const Builder = command_model.Builder;
|
|
197
|
+
pub const max_display_list_text_bytes = command_model.max_display_list_text_bytes;
|
|
175
198
|
|
|
176
199
|
// Canvas render data and cache plans live in `render.zig`; root keeps the public API stable.
|
|
177
200
|
pub const max_render_state_stack = render_model.max_render_state_stack;
|
|
@@ -566,6 +589,8 @@ pub const WidgetInvalidation = event_model.WidgetInvalidation;
|
|
|
566
589
|
pub const WidgetClipboardAction = event_model.WidgetClipboardAction;
|
|
567
590
|
pub const widgetKeyboardClipboardAction = event_model.widgetKeyboardClipboardAction;
|
|
568
591
|
pub const widgetKeyboardNewlineTextEditEvent = event_model.widgetKeyboardNewlineTextEditEvent;
|
|
592
|
+
pub const widgetKindSingleLineTextEntry = event_model.widgetKindSingleLineTextEntry;
|
|
593
|
+
pub const sanitizedSingleLineTextInputEvent = event_model.sanitizedSingleLineTextInputEvent;
|
|
569
594
|
pub const widgetKeyboardControlIntent = event_model.widgetKeyboardControlIntent;
|
|
570
595
|
pub const semanticActions = event_model.semanticActions;
|
|
571
596
|
pub const widgetSemanticControlIntent = event_model.widgetSemanticControlIntent;
|
|
@@ -11,6 +11,7 @@ test {
|
|
|
11
11
|
_ = @import("ui_markup_compiled_tests.zig");
|
|
12
12
|
_ = @import("ui_markup_contract_tests.zig");
|
|
13
13
|
_ = @import("ui_markup_huge_model_tests.zig");
|
|
14
|
+
_ = @import("ui_markup_huge_document_tests.zig");
|
|
14
15
|
_ = @import("chart_tests.zig");
|
|
15
16
|
_ = @import("render_tests.zig");
|
|
16
17
|
_ = @import("reference_tests.zig");
|
|
@@ -96,12 +96,16 @@ fn warnTextSizeKind(kind: WidgetKind, size: canvas.WidgetSize) void {
|
|
|
96
96
|
/// (`automate screenshot`), mobile embeds, provider-less measurement.
|
|
97
97
|
/// Markup literals get the same lesson as a validation error; this
|
|
98
98
|
/// diagnostic is the net for DYNAMIC strings (model-derived text
|
|
99
|
-
/// reaches no static check) and Zig-authored literals.
|
|
100
|
-
///
|
|
101
|
-
///
|
|
102
|
-
///
|
|
103
|
-
///
|
|
104
|
-
///
|
|
99
|
+
/// reaches no static check) and Zig-authored literals. The check
|
|
100
|
+
/// knows only bundled coverage — a builder has no view of the
|
|
101
|
+
/// runtime's font registry — so a run whose tokens point at a
|
|
102
|
+
/// registered face covering the codepoint renders real glyphs and
|
|
103
|
+
/// still logs here; that imprecision is one reason this logs at
|
|
104
|
+
/// .debug. Logs the first uncovered codepoint per text run and keeps
|
|
105
|
+
/// building — live macOS rendering falls back through CoreText, so
|
|
106
|
+
/// this must never fail an app, and .debug (the
|
|
107
|
+
/// `logAxisChildrenOverflow` precedent) because a .warn inside a
|
|
108
|
+
/// test-built view would fail the whole suite for a rendering nit.
|
|
105
109
|
fn warnUncoveredText(kind: WidgetKind, text: []const u8) void {
|
|
106
110
|
if (builtin.mode != .Debug) return;
|
|
107
111
|
var index: usize = 0;
|
|
@@ -111,7 +115,7 @@ fn warnUncoveredText(kind: WidgetKind, text: []const u8) void {
|
|
|
111
115
|
const codepoint = std.unicode.utf8Decode(text[index .. index + len]) catch return;
|
|
112
116
|
if (codepoint >= 0x20 and codepoint != 0x7F and !font_coverage.covers(codepoint)) {
|
|
113
117
|
ui_log.debug(
|
|
114
|
-
"{s} text contains \"{s}\" (U+{X:0>4}), outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths; use a vector icon (icon option, <icon name>) or plain words",
|
|
118
|
+
"{s} text contains \"{s}\" (U+{X:0>4}), outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths unless a registered font covers it; register a font (UiApp Options.fonts), use a vector icon (icon option, <icon name>), or plain words",
|
|
115
119
|
.{ @tagName(kind), text[index .. index + len], codepoint },
|
|
116
120
|
);
|
|
117
121
|
return;
|
|
@@ -455,7 +459,12 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
455
459
|
/// app registered at runtime (`Runtime.registerCanvasImage`,
|
|
456
460
|
/// `fx.registerImageBytes`). 0 — the "no image" sentinel —
|
|
457
461
|
/// keeps the widget on its non-image rendering (an avatar
|
|
458
|
-
/// falls back to initials).
|
|
462
|
+
/// falls back to initials). For `media_surface` this same
|
|
463
|
+
/// channel carries the SURFACE id its producer targets
|
|
464
|
+
/// (`Runtime.acquireMediaSurfaceProducer`, markup
|
|
465
|
+
/// `surface={binding}`) — the identical model-owned-u64
|
|
466
|
+
/// shape, one bit of the id space apart (see
|
|
467
|
+
/// `canvas.media_surface_image_id_bit`).
|
|
459
468
|
image: canvas.ImageId = 0,
|
|
460
469
|
/// Vector icon name drawn inside icon-bearing controls
|
|
461
470
|
/// (`button`, `toggle_button`, `icon_button`, `list_item`,
|
|
@@ -1170,7 +1179,18 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1170
1179
|
else
|
|
1171
1180
|
canvas.widgetKeyboardNewlineTextEditEvent(widget.kind, keyboard) orelse keyboard.textEditEvent();
|
|
1172
1181
|
if (edit) |text_edit| {
|
|
1173
|
-
|
|
1182
|
+
// Single-line kinds sanitize the edit with the
|
|
1183
|
+
// SAME rule the runtime seam applies before
|
|
1184
|
+
// stamping (strip line breaks; suppress inserts
|
|
1185
|
+
// that strip to nothing), so the fallback
|
|
1186
|
+
// derivation for events that never crossed the
|
|
1187
|
+
// runtime can never feed a model mirror bytes
|
|
1188
|
+
// the retained editor would refuse. Stamped
|
|
1189
|
+
// edits are already sanitized and pass through
|
|
1190
|
+
// untouched.
|
|
1191
|
+
if (canvas.sanitizedSingleLineTextInputEvent(widget.kind, text_edit)) |sanitized| {
|
|
1192
|
+
if (self.msgForTextEdit(target_id, sanitized)) |msg| return msg;
|
|
1193
|
+
}
|
|
1174
1194
|
}
|
|
1175
1195
|
}
|
|
1176
1196
|
return null;
|
|
@@ -1726,6 +1746,23 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1726
1746
|
return self.el(.image, options, .{});
|
|
1727
1747
|
}
|
|
1728
1748
|
|
|
1749
|
+
/// The media surface leaf (markup `<media-surface surface={id}>`):
|
|
1750
|
+
/// composites a texture PRODUCED OUTSIDE the widget tree — a
|
|
1751
|
+
/// video decoder, a camera pipeline, an external renderer —
|
|
1752
|
+
/// into the layout like any widget. `options.image` carries the
|
|
1753
|
+
/// SURFACE id the producer targets
|
|
1754
|
+
/// (`Runtime.acquireMediaSurfaceProducer`), a model-owned u64 in
|
|
1755
|
+
/// the ImageId value space; 0 draws nothing (the image-leaf
|
|
1756
|
+
/// convention). Until the first producer frame arrives, live
|
|
1757
|
+
/// hosts show the surface's deterministic id-derived placeholder
|
|
1758
|
+
/// — which is also ALL the reference renderer (goldens,
|
|
1759
|
+
/// screenshots, replay pixel marks) ever shows, because texture
|
|
1760
|
+
/// contents are presentation chrome by policy. Size it like an
|
|
1761
|
+
/// image: definite width/height or flex grow (no intrinsic size).
|
|
1762
|
+
pub fn mediaSurface(self: *Self, options: ElementOptions) Node {
|
|
1763
|
+
return self.el(.media_surface, options, .{});
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1729
1766
|
/// A built-in vector icon leaf: `name` is one of
|
|
1730
1767
|
/// `canvas.icons.known_icon_names` (compile error otherwise), so
|
|
1731
1768
|
/// icon references never rot. Size comes from `options.size` /
|
|
@@ -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,14 @@ 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";
|
|
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";
|
|
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";
|
|
1256
|
+
pub const media_surface_missing_surface_message = "media-surface requires surface={binding} naming the u64 surface id its producer targets - without one the surface can never show anything (dead markup, same policy as icon without name)";
|
|
1252
1257
|
|
|
1253
1258
|
/// The built-in vector icon vocabulary behind `<icon name="..."/>`.
|
|
1254
1259
|
/// Registry section mirroring `canvas.icons.known_icon_names` (the
|
|
@@ -1672,7 +1677,7 @@ fn trimBlank(text: []const u8) []const u8 {
|
|
|
1672
1677
|
return std.mem.trim(u8, text, " \t\r\n");
|
|
1673
1678
|
}
|
|
1674
1679
|
|
|
1675
|
-
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";
|
|
1676
1681
|
|
|
1677
1682
|
pub const UncoveredCodepoint = struct {
|
|
1678
1683
|
/// Byte offset of the codepoint within the scanned literal.
|
|
@@ -2928,6 +2933,21 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
2928
2933
|
if (node.attr("name") == null) return errorAt(node, icon_missing_name_message);
|
|
2929
2934
|
if (node.children.len > 0) return errorAt(node.children[0], icon_children_message);
|
|
2930
2935
|
}
|
|
2936
|
+
if (std.mem.eql(u8, node.name, "media-surface")) {
|
|
2937
|
+
// A media surface without a producer rendezvous can never
|
|
2938
|
+
// show anything: statically dead markup, refused with a
|
|
2939
|
+
// teaching (the icon-without-name policy).
|
|
2940
|
+
if (node.attr("surface") == null) return errorAt(node, media_surface_missing_surface_message);
|
|
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
|
+
}
|
|
2931
2951
|
if (std.mem.eql(u8, node.name, "split")) {
|
|
2932
2952
|
// Exactly two pane children, statically: the divider sits
|
|
2933
2953
|
// between fixed panes, so conditional/repeated content
|
|
@@ -3052,14 +3072,30 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
3052
3072
|
continue;
|
|
3053
3073
|
}
|
|
3054
3074
|
if (std.mem.eql(u8, attribute.name, "image")) {
|
|
3055
|
-
// Runtime image binding,
|
|
3056
|
-
//
|
|
3057
|
-
|
|
3058
|
-
|
|
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);
|
|
3081
|
+
}
|
|
3082
|
+
const expression = parseAttrExpression(attribute.value);
|
|
3083
|
+
if (expression == null or expression.? != .binding) {
|
|
3084
|
+
return attrError(node, attribute, image_binding_message);
|
|
3085
|
+
}
|
|
3086
|
+
continue;
|
|
3087
|
+
}
|
|
3088
|
+
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
3089
|
+
// The media-surface producer rendezvous, media-surface
|
|
3090
|
+
// scoped: surface ids are model data a producer
|
|
3091
|
+
// targets, never markup literals (the runtime-image-id
|
|
3092
|
+
// grammar exactly).
|
|
3093
|
+
if (!std.mem.eql(u8, node.name, "media-surface")) {
|
|
3094
|
+
return attrError(node, attribute, media_surface_surface_element_message);
|
|
3059
3095
|
}
|
|
3060
3096
|
const expression = parseAttrExpression(attribute.value);
|
|
3061
3097
|
if (expression == null or expression.? != .binding) {
|
|
3062
|
-
return attrError(node, attribute,
|
|
3098
|
+
return attrError(node, attribute, media_surface_surface_message);
|
|
3063
3099
|
}
|
|
3064
3100
|
continue;
|
|
3065
3101
|
}
|
|
@@ -3490,7 +3526,7 @@ pub fn resolveImports(
|
|
|
3490
3526
|
.diagnostic = diagnostic,
|
|
3491
3527
|
};
|
|
3492
3528
|
const root = try resolver.visit(root_name, root_source, 0);
|
|
3493
|
-
return .{ .imports = &.{}, .templates = resolver.templates.items, .root = root };
|
|
3529
|
+
return .{ .imports = &.{}, .templates = resolver.templates.items, .root = root, .source_bytes = resolver.source_bytes };
|
|
3494
3530
|
}
|
|
3495
3531
|
|
|
3496
3532
|
const ImportResolver = struct {
|
|
@@ -3505,12 +3541,17 @@ const ImportResolver = struct {
|
|
|
3505
3541
|
/// The in-progress import chain, for cycle reporting.
|
|
3506
3542
|
chain: [max_import_depth][]const u8 = undefined,
|
|
3507
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,
|
|
3508
3548
|
|
|
3509
3549
|
/// Parse one file, resolve its imports depth-first, splice its
|
|
3510
3550
|
/// templates, and return its stamped view root (null for a component
|
|
3511
3551
|
/// file). Only the root file (depth 0) may have a view root.
|
|
3512
3552
|
fn visit(self: *ImportResolver, path: []const u8, source: []const u8, depth: usize) ResolveError!?MarkupNode {
|
|
3513
3553
|
self.chain[depth] = path;
|
|
3554
|
+
self.source_bytes += source.len;
|
|
3514
3555
|
var parser = Parser.init(self.arena, source);
|
|
3515
3556
|
const document = parser.parse() catch |err| {
|
|
3516
3557
|
if (err == error.MarkupSyntax) {
|
|
@@ -3705,6 +3746,10 @@ fn dirnamePath(path: []const u8) []const u8 {
|
|
|
3705
3746
|
/// would report, prefixed with the offending file.
|
|
3706
3747
|
pub fn resolveImportsComptime(comptime root_name: []const u8, comptime sources: []const SourceFile) MarkupDocument {
|
|
3707
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);
|
|
3708
3753
|
var total_len: usize = 0;
|
|
3709
3754
|
for (sources) |file| total_len += file.source.len;
|
|
3710
3755
|
@setEvalBranchQuota(comptime_parse_quota_base + total_len * comptime_parse_quota_per_byte + (sources.len + 1) * 50_000);
|
|
@@ -3714,7 +3759,10 @@ pub fn resolveImportsComptime(comptime root_name: []const u8, comptime sources:
|
|
|
3714
3759
|
var templates: []const MarkupNode = &.{};
|
|
3715
3760
|
var visited: []const []const u8 = &.{};
|
|
3716
3761
|
const root = visitComptime(root_name, root_source, sources, dirnamePath(root_name), &templates, &visited, &.{});
|
|
3717
|
-
|
|
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 };
|
|
3718
3766
|
}
|
|
3719
3767
|
}
|
|
3720
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
|
}
|
|
@@ -152,6 +152,31 @@ test "NSUI round-trips the input-group vocabulary under its fresh codes" {
|
|
|
152
152
|
try testing.expectEqual(@as(u16, 63), schema.elementByName("input-group-actions").?.code);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
test "NSUI round-trips the media surface under its fresh codes" {
|
|
156
|
+
// media-surface and its surface binding serialize like any element —
|
|
157
|
+
// fresh registry codes ride the wire automatically, no schema bump —
|
|
158
|
+
// so a media document survives encode/decode node-for-node.
|
|
159
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
160
|
+
defer arena_state.deinit();
|
|
161
|
+
const arena = arena_state.allocator();
|
|
162
|
+
const source =
|
|
163
|
+
\\<column gap="8">
|
|
164
|
+
\\ <media-surface surface="{preview}" width="320" height="180" label="Camera preview" />
|
|
165
|
+
\\</column>
|
|
166
|
+
;
|
|
167
|
+
const document = try parseSource(arena, source);
|
|
168
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(document));
|
|
169
|
+
|
|
170
|
+
var diagnostic = nsui.CodecDiagnostic{};
|
|
171
|
+
const bytes = try nsui.encode(arena, document, .{}, &diagnostic);
|
|
172
|
+
const decoded = try nsui.decode(arena, bytes, &diagnostic);
|
|
173
|
+
try expectNodesEqual(document.root.?, decoded.root.?);
|
|
174
|
+
|
|
175
|
+
// The wire carries the registry codes, never the names.
|
|
176
|
+
try testing.expectEqual(@as(u16, 66), schema.elementByName("media-surface").?.code);
|
|
177
|
+
try testing.expectEqual(@as(u16, 81), schema.attrByName("surface").?.code);
|
|
178
|
+
}
|
|
179
|
+
|
|
155
180
|
test "NSUI round-trips the split layout-tween pair under its fresh codes" {
|
|
156
181
|
// resize-duration/resize-easing serialize like any attribute — fresh
|
|
157
182
|
// registry codes ride the wire automatically, no schema bump — so a
|