@native-sdk/cli 0.11.0 → 0.11.1
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 +73 -37
- package/build.zig +239 -5
- package/native-sdk.d.ts +5 -1
- package/package.json +13 -12
- package/packages/core/compile-surface/core.ts +30 -0
- package/packages/core/package-lock.json +6 -6
- package/packages/core/package.json +3 -3
- package/packages/core/scripts/scriptc-toolchain.json +44 -44
- package/packages/core/scripts/stage_external_core.mjs +27 -16
- package/packages/core/sdk/core.d.ts +24 -1
- package/packages/core/sdk/core.ts +51 -1
- package/packages/core/sdk/events.d.ts +5 -0
- package/packages/core/sdk/events.ts +10 -0
- package/packages/core/src/bridge_descriptors.ts +3 -3
- package/packages/core/src/checker.ts +20 -0
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/portable_sources.json +24 -0
- package/packages/core/src/registered_font.ts +2 -3
- package/packages/core/src/runtime_policy.ts +24 -0
- package/packages/core/src/scalar_text.ts +1 -3
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +53 -2
- package/packages/core/src/sqlite_cli.ts +3 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +340 -218
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/skill-data/native-ui/SKILL.md +2 -2
- package/skill-data/ts-core/SKILL.md +5 -3
- package/skill-data/ts-services/references/service-surface.md +29 -5
- package/src/app_runner/root.zig +14 -0
- package/src/app_runner/ts_compiled_view.zig +88 -17
- package/src/app_runner/ts_core_main.zig +43 -5
- package/src/app_runner/ts_core_mobile.zig +1 -1
- package/src/automation/server.zig +56 -3
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +31 -9
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/null_platform.zig +104 -0
- package/src/platform/root.zig +14 -0
- package/src/platform/types.zig +102 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +15 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/reference.zig +3 -5
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +1 -1
- package/src/primitives/canvas/root.zig +7 -4
- package/src/primitives/canvas/text_metrics.zig +32 -39
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +142 -3
- package/src/primitives/canvas/text_scalar_policy.zig +80 -2
- package/src/primitives/canvas/tokens.zig +9 -0
- package/src/primitives/canvas/ui.zig +1 -0
- package/src/primitives/canvas/ui_markup.zig +69 -14
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +2817 -74
- package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
- package/src/primitives/canvas/virtual_extents.zig +47 -33
- package/src/primitives/canvas/widget_metric_policy.zig +4 -1
- package/src/primitives/canvas/widget_runtime.zig +2 -1
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +1 -0
- package/src/runtime/bridge_descriptor_policy.zig +1 -1
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/canvas_widget_context_menu.zig +179 -0
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_runtime.zig +306 -92
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +14 -0
- package/src/runtime/effects.zig +172 -4
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/flow.zig +1 -0
- package/src/runtime/flow_reference.zig +1 -0
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/root.zig +3 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_record.zig +7 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/system_services.zig +19 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +126 -0
- package/src/runtime/ts_ui_app.zig +24 -0
- package/src/runtime/ui_app.zig +274 -31
- package/src/runtime/ui_app_tests.zig +48 -179
- package/src/runtime/ui_app_window_tests.zig +133 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_scroll.zig +30 -21
- package/src/runtime/view_widget_tree.zig +43 -13
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_views.zig +19 -4
- package/src/security/root.zig +1 -0
- package/src/tooling/templates.zig +8 -0
- package/src/tooling/ts_core.zig +84 -1
- package/src/tooling/verbs.zig +79 -15
- package/tools/corewire/core.test.ts +25 -3
- package/tools/corewire/core_abi.zig +4 -0
- package/tools/corewire/core_contract.ts +1 -1
- package/tools/corewire/core_goldens.json +75 -75
- package/tools/corewire/core_projection.ts +3 -2
- package/tools/corewire/emit_mirror.ts +19 -9
- package/tools/corewire/facade_templates.ts +1 -1
- package/tools/corewire/intake.test.ts +4 -0
- package/tools/corewire/intake_goldens.json +50 -50
- package/tools/corewire/invocation.test.ts +4 -0
- package/tools/corewire/invocation_goldens.json +3 -3
- package/tools/corewire/mirror_templates.ts +4 -0
- package/tools/corewire/profile_emission.ts +2 -0
- package/tools/corewire/sidecar.zig +2 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
3
|
+
const canvas = @import("canvas");
|
|
4
|
+
const app_manifest = @import("app_manifest");
|
|
5
|
+
const core = @import("core.zig");
|
|
6
|
+
const ui_app_model = @import("ui_app.zig");
|
|
7
|
+
const effects_mod = @import("effects.zig");
|
|
8
|
+
const automation = @import("../automation/root.zig");
|
|
9
|
+
const zero_platform = @import("../platform/root.zig");
|
|
10
|
+
const null_platform_mod = @import("../platform/null_platform.zig");
|
|
11
|
+
const canvas_frame_helpers = @import("canvas_frame_helpers.zig");
|
|
12
|
+
|
|
13
|
+
pub fn Cases(comptime policy: ?*const fn ([]const u8, []u8) usize) type {
|
|
14
|
+
return struct {
|
|
15
|
+
const preview_canvas_label = "preview-canvas";
|
|
16
|
+
const preview_pane_anchor = "preview-pane";
|
|
17
|
+
const example_url = "https://example.com/";
|
|
18
|
+
const docs_url = "https://native-sdk.dev/";
|
|
19
|
+
|
|
20
|
+
const PreviewModel = struct {
|
|
21
|
+
show_docs: bool = false,
|
|
22
|
+
reload_token: u64 = 0,
|
|
23
|
+
|
|
24
|
+
fn url(model: *const PreviewModel) []const u8 {
|
|
25
|
+
return if (model.show_docs) docs_url else example_url;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const PreviewMsg = union(enum) {
|
|
30
|
+
show_docs,
|
|
31
|
+
show_example,
|
|
32
|
+
reload,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const PreviewApp = ui_app_model.UiApp(PreviewModel, PreviewMsg);
|
|
36
|
+
|
|
37
|
+
fn previewUpdate(model: *PreviewModel, msg: PreviewMsg) void {
|
|
38
|
+
switch (msg) {
|
|
39
|
+
.show_docs => model.show_docs = true,
|
|
40
|
+
.show_example => model.show_docs = false,
|
|
41
|
+
.reload => model.reload_token += 1,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fn previewView(ui: *PreviewApp.Ui, model: *const PreviewModel) PreviewApp.Ui.Node {
|
|
46
|
+
_ = model;
|
|
47
|
+
return ui.row(.{ .gap = 0 }, .{
|
|
48
|
+
ui.column(.{ .width = 200, .padding = 12, .gap = 8 }, .{
|
|
49
|
+
ui.button(.{ .on_press = .show_docs }, "Docs"),
|
|
50
|
+
ui.button(.{ .on_press = .show_example }, "Example"),
|
|
51
|
+
ui.button(.{ .on_press = .reload }, "Reload"),
|
|
52
|
+
}),
|
|
53
|
+
// The empty panel that reserves the webview region: the pane
|
|
54
|
+
// anchor resolves to this widget's layout frame.
|
|
55
|
+
ui.panel(.{ .grow = 1, .semantics = .{ .label = preview_pane_anchor } }, .{}),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fn previewPanes(model: *const PreviewModel, out: []PreviewApp.WebViewPane) usize {
|
|
60
|
+
out[0] = .{
|
|
61
|
+
.label = "preview",
|
|
62
|
+
.anchor = preview_pane_anchor,
|
|
63
|
+
.url = model.url(),
|
|
64
|
+
.reload_token = model.reload_token,
|
|
65
|
+
};
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const preview_views = [_]app_manifest.ShellView{
|
|
70
|
+
.{ .label = preview_canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
|
|
71
|
+
.{ .label = "preview", .kind = .webview, .parent = preview_canvas_label, .url = example_url, .x = 200, .y = 0, .width = 440, .height = 480 },
|
|
72
|
+
};
|
|
73
|
+
const preview_windows = [_]app_manifest.ShellWindow{.{
|
|
74
|
+
.label = "main",
|
|
75
|
+
.title = "Preview",
|
|
76
|
+
.width = 640,
|
|
77
|
+
.height = 480,
|
|
78
|
+
.views = &preview_views,
|
|
79
|
+
}};
|
|
80
|
+
const preview_scene: app_manifest.ShellConfig = .{ .windows = &preview_windows };
|
|
81
|
+
const preview_origins = [_][]const u8{ "https://example.com", "https://native-sdk.dev", "zero://app", "zero://inline" };
|
|
82
|
+
|
|
83
|
+
fn previewOptions() PreviewApp.Options {
|
|
84
|
+
return .{
|
|
85
|
+
.name = "ui-app-preview",
|
|
86
|
+
.scene = preview_scene,
|
|
87
|
+
.canvas_label = preview_canvas_label,
|
|
88
|
+
.update = previewUpdate,
|
|
89
|
+
.view = previewView,
|
|
90
|
+
.web_panes = previewPanes,
|
|
91
|
+
.web_pane_policy = policy,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fn previewHarnessAndApp(app_state: *PreviewApp) !*core.TestHarness() {
|
|
96
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(640, 480) });
|
|
97
|
+
errdefer harness.destroy(std.testing.allocator);
|
|
98
|
+
harness.null_platform.gpu_surfaces = true;
|
|
99
|
+
harness.runtime.options.security.navigation.allowed_origins = &preview_origins;
|
|
100
|
+
|
|
101
|
+
app_state.* = PreviewApp.init(std.heap.page_allocator, .{}, previewOptions());
|
|
102
|
+
const app = app_state.app();
|
|
103
|
+
try harness.start(app);
|
|
104
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
105
|
+
.label = preview_canvas_label,
|
|
106
|
+
.size = geometry.SizeF.init(640, 480),
|
|
107
|
+
.scale_factor = 1,
|
|
108
|
+
.frame_index = 1,
|
|
109
|
+
.timestamp_ns = 1_000_000,
|
|
110
|
+
.nonblank = true,
|
|
111
|
+
} });
|
|
112
|
+
return harness;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fn previewNullWebView(harness: *core.TestHarness()) !null_platform_mod.NullWebView {
|
|
116
|
+
for (harness.null_platform.webviews[0..harness.null_platform.webview_count]) |webview| {
|
|
117
|
+
if (std.mem.eql(u8, webview.label, "preview")) return webview;
|
|
118
|
+
}
|
|
119
|
+
return error.TestUnexpectedResult;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
pub fn case0() !void {
|
|
123
|
+
const app_state = try std.testing.allocator.create(PreviewApp);
|
|
124
|
+
defer std.testing.allocator.destroy(app_state);
|
|
125
|
+
const harness = try previewHarnessAndApp(app_state);
|
|
126
|
+
defer harness.destroy(std.testing.allocator);
|
|
127
|
+
defer app_state.deinit();
|
|
128
|
+
|
|
129
|
+
// The canvas-first scene never grows an implicit main webview: the
|
|
130
|
+
// loaded source stays null and only the declared views exist.
|
|
131
|
+
try std.testing.expect(harness.runtime.loaded_source == null);
|
|
132
|
+
var views_buffer: [8]zero_platform.ViewInfo = undefined;
|
|
133
|
+
const views = harness.runtime.listViews(1, &views_buffer);
|
|
134
|
+
try std.testing.expectEqual(@as(usize, 2), views.len);
|
|
135
|
+
for (views) |view| {
|
|
136
|
+
try std.testing.expect(!std.mem.eql(u8, view.label, "main"));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
pub fn case1() !void {
|
|
141
|
+
const app_state = try std.testing.allocator.create(PreviewApp);
|
|
142
|
+
defer std.testing.allocator.destroy(app_state);
|
|
143
|
+
const harness = try previewHarnessAndApp(app_state);
|
|
144
|
+
defer harness.destroy(std.testing.allocator);
|
|
145
|
+
defer app_state.deinit();
|
|
146
|
+
|
|
147
|
+
try std.testing.expect(app_state.installed);
|
|
148
|
+
const webview = try previewNullWebView(harness);
|
|
149
|
+
try std.testing.expect(webview.open);
|
|
150
|
+
try std.testing.expectEqualStrings(example_url, webview.url);
|
|
151
|
+
|
|
152
|
+
// The pane frame is the anchor widget's layout frame: the row's
|
|
153
|
+
// remaining width after the 200pt sidebar column.
|
|
154
|
+
const layout = try harness.runtime.canvasWidgetLayout(1, preview_canvas_label);
|
|
155
|
+
var anchor_frame: ?geometry.RectF = null;
|
|
156
|
+
for (layout.nodes) |node| {
|
|
157
|
+
if (std.mem.eql(u8, node.widget.semantics.label, preview_pane_anchor)) anchor_frame = node.frame;
|
|
158
|
+
}
|
|
159
|
+
try std.testing.expect(anchor_frame != null);
|
|
160
|
+
try std.testing.expect(anchor_frame.?.width > 0);
|
|
161
|
+
try std.testing.expectApproxEqAbs(anchor_frame.?.x, webview.frame.x, 0.5);
|
|
162
|
+
try std.testing.expectApproxEqAbs(anchor_frame.?.y, webview.frame.y, 0.5);
|
|
163
|
+
try std.testing.expectApproxEqAbs(anchor_frame.?.width, webview.frame.width, 0.5);
|
|
164
|
+
try std.testing.expectApproxEqAbs(anchor_frame.?.height, webview.frame.height, 0.5);
|
|
165
|
+
|
|
166
|
+
// A resize rebuild follows the anchor to its new frame.
|
|
167
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .gpu_surface_resized = .{
|
|
168
|
+
.label = preview_canvas_label,
|
|
169
|
+
.window_id = 1,
|
|
170
|
+
.frame = geometry.RectF.init(0, 0, 900, 600),
|
|
171
|
+
.scale_factor = 1,
|
|
172
|
+
} });
|
|
173
|
+
const resized = try previewNullWebView(harness);
|
|
174
|
+
try std.testing.expectApproxEqAbs(@as(f32, 900 - 200), resized.frame.width, 0.5);
|
|
175
|
+
try std.testing.expectApproxEqAbs(@as(f32, 600), resized.frame.height, 0.5);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
pub fn case2() !void {
|
|
179
|
+
const app_state = try std.testing.allocator.create(PreviewApp);
|
|
180
|
+
defer std.testing.allocator.destroy(app_state);
|
|
181
|
+
const harness = try previewHarnessAndApp(app_state);
|
|
182
|
+
defer harness.destroy(std.testing.allocator);
|
|
183
|
+
defer app_state.deinit();
|
|
184
|
+
|
|
185
|
+
const navigations_after_install = harness.null_platform.webview_navigate_count;
|
|
186
|
+
|
|
187
|
+
// A model-driven URL change navigates the webview.
|
|
188
|
+
try app_state.dispatch(&harness.runtime, 1, .show_docs);
|
|
189
|
+
var webview = try previewNullWebView(harness);
|
|
190
|
+
try std.testing.expectEqualStrings(docs_url, webview.url);
|
|
191
|
+
try std.testing.expectEqual(navigations_after_install + 1, harness.null_platform.webview_navigate_count);
|
|
192
|
+
|
|
193
|
+
// A rebuild without a URL change does not renavigate.
|
|
194
|
+
try app_state.dispatch(&harness.runtime, 1, .show_docs);
|
|
195
|
+
try std.testing.expectEqual(navigations_after_install + 1, harness.null_platform.webview_navigate_count);
|
|
196
|
+
|
|
197
|
+
// Bumping the reload token renavigates the same URL.
|
|
198
|
+
try app_state.dispatch(&harness.runtime, 1, .reload);
|
|
199
|
+
webview = try previewNullWebView(harness);
|
|
200
|
+
try std.testing.expectEqualStrings(docs_url, webview.url);
|
|
201
|
+
try std.testing.expectEqual(navigations_after_install + 2, harness.null_platform.webview_navigate_count);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//! Rebuild continuity decisions. Exact identities and complete source/physics
|
|
2
|
+
//! records stay native; compiled code sees copied facts and returns action bits.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const canvas = @import("canvas");
|
|
5
|
+
const limits = @import("canvas_limits.zig");
|
|
6
|
+
pub const Policy = ?*const fn ([]const u8, []u8) usize;
|
|
7
|
+
pub const Plan = struct { actions: [limits.max_canvas_widget_nodes_per_view]u8 = undefined };
|
|
8
|
+
|
|
9
|
+
pub fn layout(policy: Policy, nodes: []const canvas.WidgetLayoutNode, previous: anytype, semantics: anytype) ?Plan {
|
|
10
|
+
const callback = policy orelse return null;
|
|
11
|
+
var input: [8 + limits.max_canvas_widget_nodes_per_view * 24]u8 = undefined;
|
|
12
|
+
const bytes = header(&input, nodes.len, 0);
|
|
13
|
+
for (nodes, 0..) |node, i| {
|
|
14
|
+
const w = node.widget;
|
|
15
|
+
const fact = bytes[8 + i * 24 ..][0..24];
|
|
16
|
+
fact[0] = bit(w.id != 0, 0) | bit(w.kind == .scroll_view, 1) |
|
|
17
|
+
bit(canvas.widgetScrollsAxis(w, .vertical), 2) | bit(canvas.widgetScrollsAxis(w, .horizontal), 3);
|
|
18
|
+
float(fact[4..8], w.value);
|
|
19
|
+
float(fact[8..12], w.value_x);
|
|
20
|
+
if (w.kind == .scroll_view and w.id != 0) for (previous) |entry| {
|
|
21
|
+
if (entry.id != w.id) continue;
|
|
22
|
+
fact[0] |= 16;
|
|
23
|
+
float(fact[12..16], entry.state.offset_y);
|
|
24
|
+
float(fact[16..20], entry.state.offset_x);
|
|
25
|
+
break;
|
|
26
|
+
};
|
|
27
|
+
if (semantics.first(w.id)) |source| fact[0] |= 32 | bit(source.list.present, 6) | bit(source.scroll.present, 7);
|
|
28
|
+
}
|
|
29
|
+
return finish(callback, bytes, nodes.len, 0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub fn semanticsPlan(policy: Policy, nodes: []const canvas.WidgetSemanticsNode, sources: anytype) ?Plan {
|
|
33
|
+
const callback = policy orelse return null;
|
|
34
|
+
var input: [8 + limits.max_canvas_widget_nodes_per_view * 24]u8 = undefined;
|
|
35
|
+
const bytes = header(&input, nodes.len, 1);
|
|
36
|
+
for (nodes, 0..) |node, i| {
|
|
37
|
+
if (sources.first(node.id)) |source| bytes[8 + i * 24] = 32 | bit(source.list.present, 6) | bit(source.scroll.present, 7);
|
|
38
|
+
}
|
|
39
|
+
return finish(callback, bytes, nodes.len, 1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn header(input: []u8, count: usize, mode: u8) []u8 {
|
|
43
|
+
if (count > limits.max_canvas_widget_nodes_per_view) @panic("widget continuity exceeds view budget");
|
|
44
|
+
const bytes = input[0 .. 8 + count * 24];
|
|
45
|
+
@memset(bytes, 0);
|
|
46
|
+
bytes[0] = 95;
|
|
47
|
+
bytes[1] = mode;
|
|
48
|
+
std.mem.writeInt(u32, bytes[4..8], @intCast(count), .little);
|
|
49
|
+
return bytes;
|
|
50
|
+
}
|
|
51
|
+
fn finish(callback: *const fn ([]const u8, []u8) usize, bytes: []const u8, count: usize, mode: u8) Plan {
|
|
52
|
+
var output: [8 + limits.max_canvas_widget_nodes_per_view]u8 = undefined;
|
|
53
|
+
const size = callback(bytes, &output);
|
|
54
|
+
if (size != 8 + count or output[0] != 95 or output[1] != mode or output[2] != 0 or output[3] != 0 or
|
|
55
|
+
std.mem.readInt(u32, output[4..8], .little) != count) @panic("invalid compiled widget continuity header");
|
|
56
|
+
var plan = Plan{};
|
|
57
|
+
for (plan.actions[0..count], 0..) |*action, i| {
|
|
58
|
+
const flags = output[8 + i];
|
|
59
|
+
const facts = bytes[8 + i * 24];
|
|
60
|
+
if ((flags & (if (mode == 0) @as(u8, 242) else @as(u8, 253))) != 0 or
|
|
61
|
+
(flags & 1 != 0 and facts & 96 != 96) or (flags & 2 != 0 and facts & 160 != 160) or
|
|
62
|
+
(flags & 4 != 0 and facts & 23 != 23) or (flags & 8 != 0 and facts & 27 != 27))
|
|
63
|
+
@panic("invalid compiled widget continuity action");
|
|
64
|
+
action.* = flags;
|
|
65
|
+
}
|
|
66
|
+
return plan;
|
|
67
|
+
}
|
|
68
|
+
fn bit(value: bool, shift: u3) u8 {
|
|
69
|
+
return @as(u8, @intFromBool(value)) << shift;
|
|
70
|
+
}
|
|
71
|
+
fn float(bytes: *[4]u8, value: f32) void {
|
|
72
|
+
std.mem.writeInt(u32, bytes, @bitCast(value), .little);
|
|
73
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//! Rebuild decisions over copied facts. Exact keyed storage lookups, byte
|
|
2
|
+
//! equality and fingerprinting stay native; the compiled planner owns admission
|
|
3
|
+
//! and restoration. Every result is copied before another callback can run.
|
|
4
|
+
const std = @import("std");
|
|
5
|
+
const canvas = @import("canvas");
|
|
6
|
+
const limits = @import("canvas_limits.zig");
|
|
7
|
+
pub const Policy = ?*const fn ([]const u8, []u8) usize;
|
|
8
|
+
pub const Action = struct { flags: u32, value: f32 };
|
|
9
|
+
pub const Plan = struct { entries: [limits.max_canvas_widget_nodes_per_view]Action = undefined };
|
|
10
|
+
|
|
11
|
+
pub fn build(policy: Policy, layout: canvas.WidgetLayoutTree, controls: anytype, sources: anytype, texts: anytype, comptime hidden: anytype, comptime fingerprint: anytype, comptime minimumWidth: anytype) ?Plan {
|
|
12
|
+
const callback = policy orelse return null;
|
|
13
|
+
if (layout.nodes.len > limits.max_canvas_widget_nodes_per_view) @panic("widget reconcile exceeds view budget");
|
|
14
|
+
var input: [8 + limits.max_canvas_widget_nodes_per_view * 64]u8 = undefined;
|
|
15
|
+
const bytes = input[0 .. 8 + layout.nodes.len * 64];
|
|
16
|
+
@memset(bytes, 0);
|
|
17
|
+
bytes[0] = 93;
|
|
18
|
+
std.mem.writeInt(u32, bytes[4..8], @intCast(layout.nodes.len), .little);
|
|
19
|
+
for (layout.nodes, 0..) |node, i| {
|
|
20
|
+
const w = node.widget;
|
|
21
|
+
const fact = bytes[8 + i * 64 ..][0..64];
|
|
22
|
+
const control = controls.firstWithKind(w.id, w.kind);
|
|
23
|
+
const source = sources.firstWithKind(w.id, w.kind);
|
|
24
|
+
const text = texts.firstWithKind(w.id, w.kind);
|
|
25
|
+
fact[0] = @intCast(canvas.widgetKindCode(w.kind));
|
|
26
|
+
fact[1] = bit(w.id != 0, 0) | bit(w.state.disabled, 1) | bit(hidden(layout, i), 2) |
|
|
27
|
+
bit(control != null, 3) | bit(source != null, 4) | bit(text != null, 5) |
|
|
28
|
+
bit(w.runtime_flags.code_editor, 6) | bit(w.hasCodeDiff(), 7);
|
|
29
|
+
fact[2] = bit(w.state.selected or w.value >= 0.5, 0) |
|
|
30
|
+
bit(if (source) |entry| entry.selected else false, 1) |
|
|
31
|
+
bit(if (control) |entry| entry.state.selected or entry.value >= 0.5 else false, 2) |
|
|
32
|
+
bit(if (control) |entry| entry.state.pressed else false, 3);
|
|
33
|
+
float(fact[4..8], w.value);
|
|
34
|
+
float(fact[8..12], if (source) |entry| entry.value else 0);
|
|
35
|
+
float(fact[12..16], if (control) |entry| entry.value else 0);
|
|
36
|
+
float(fact[16..20], minimumWidth(w));
|
|
37
|
+
fact[20] = bit(w.text_selection != null, 0) | bit(w.text_composition != null, 1) |
|
|
38
|
+
bit(if (w.text_selection) |selection| selection.affinity == .downstream else false, 2);
|
|
39
|
+
if (w.text_selection) |selection| {
|
|
40
|
+
wide(fact[24..32], selection.anchor);
|
|
41
|
+
wide(fact[32..40], selection.focus);
|
|
42
|
+
}
|
|
43
|
+
if (text) |entry| {
|
|
44
|
+
const source_text = fingerprint(w.text);
|
|
45
|
+
fact[2] |= bit(std.mem.eql(u8, w.text, entry.text), 4) | bit(w.static_text_group_id == entry.static_text_group_id, 5) |
|
|
46
|
+
bit(source_text.len == entry.source_text_len and source_text.hash == entry.source_text_hash, 6);
|
|
47
|
+
fact[20] |= bit(entry.text_selection != null, 3) |
|
|
48
|
+
bit(if (entry.text_selection) |selection| selection.affinity == .downstream else false, 4) |
|
|
49
|
+
bit(entry.source_text_selection != null, 5) |
|
|
50
|
+
bit(if (entry.source_text_selection) |selection| selection.affinity == .downstream else false, 6);
|
|
51
|
+
if (entry.text_selection) |selection| {
|
|
52
|
+
wide(fact[40..48], selection.anchor);
|
|
53
|
+
wide(fact[48..56], selection.focus);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
var output: [8 + limits.max_canvas_widget_nodes_per_view * 8]u8 = undefined;
|
|
58
|
+
const size = callback(bytes, &output);
|
|
59
|
+
if (size != 8 + layout.nodes.len * 8 or output[0] != 93 or output[1] != 0 or output[2] != 0 or output[3] != 0 or
|
|
60
|
+
std.mem.readInt(u32, output[4..8], .little) != layout.nodes.len) @panic("invalid compiled widget reconcile header");
|
|
61
|
+
var plan = Plan{};
|
|
62
|
+
for (plan.entries[0..layout.nodes.len], 0..) |*action, i| {
|
|
63
|
+
const at = 8 + i * 8;
|
|
64
|
+
const flags = std.mem.readInt(u32, output[at..][0..4], .little);
|
|
65
|
+
if (flags > 2047 or (flags & 2 != 0 and flags & 1 == 0) or (flags & (16 | 128 | 256 | 512) != 0 and flags & 32 == 0) or
|
|
66
|
+
(flags & 512 != 0 and flags & 256 == 0) or (flags & (1 | 4 | 8) != 0 and controls.firstWithKind(layout.nodes[i].widget.id, layout.nodes[i].widget.kind) == null) or
|
|
67
|
+
(flags & (16 | 32 | 64 | 128 | 256 | 512) != 0 and texts.firstWithKind(layout.nodes[i].widget.id, layout.nodes[i].widget.kind) == null))
|
|
68
|
+
@panic("invalid compiled widget reconcile action");
|
|
69
|
+
action.* = .{ .flags = flags, .value = @bitCast(std.mem.readInt(u32, output[at + 4 ..][0..4], .little)) };
|
|
70
|
+
}
|
|
71
|
+
return plan;
|
|
72
|
+
}
|
|
73
|
+
fn bit(value: bool, shift: u3) u8 {
|
|
74
|
+
return @as(u8, @intFromBool(value)) << shift;
|
|
75
|
+
}
|
|
76
|
+
fn float(bytes: *[4]u8, value: f32) void {
|
|
77
|
+
std.mem.writeInt(u32, bytes, @bitCast(value), .little);
|
|
78
|
+
}
|
|
79
|
+
fn wide(bytes: *[8]u8, value: usize) void {
|
|
80
|
+
std.mem.writeInt(u64, bytes, @intCast(value), .little);
|
|
81
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//! Rebuild collection plans over copied facts. Returned ordinals select native
|
|
2
|
+
//! records; text, hashes, selections and code-cache identities never transfer
|
|
3
|
+
//! ownership. Native reference collectors remain independent when absent.
|
|
4
|
+
const std = @import("std");
|
|
5
|
+
const canvas = @import("canvas");
|
|
6
|
+
const limits = @import("canvas_limits.zig");
|
|
7
|
+
pub const Policy = ?*const fn ([]const u8, []u8) usize;
|
|
8
|
+
pub const Operation = enum(u8) { source_scroll, source_control, control, scroll, source_text, text, autofocus };
|
|
9
|
+
pub const Selection = struct { node: usize, source: ?usize, selected: bool, resizable: bool, code_diff: bool };
|
|
10
|
+
pub const Plan = struct {
|
|
11
|
+
entries: [limits.max_canvas_widget_nodes_per_view]Selection = undefined,
|
|
12
|
+
count: usize = 0,
|
|
13
|
+
target: ?usize = null,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
pub fn collect(policy: Policy, operation: Operation, nodes: []const canvas.WidgetLayoutNode, sources: anytype, capacity: usize, states: usize) ?Plan {
|
|
17
|
+
const callback = policy orelse return null;
|
|
18
|
+
if (nodes.len > limits.max_canvas_widget_nodes_per_view or sources.len > limits.max_canvas_widget_nodes_per_view or capacity > limits.max_canvas_widget_nodes_per_view or states > limits.max_canvas_widget_nodes_per_view)
|
|
19
|
+
@panic("widget retention table exceeds view budget");
|
|
20
|
+
var input: [24 + limits.max_canvas_widget_nodes_per_view * 32]u8 = undefined;
|
|
21
|
+
const bytes = input[0 .. 24 + (nodes.len + sources.len) * 16];
|
|
22
|
+
@memset(bytes, 0);
|
|
23
|
+
bytes[0] = 92;
|
|
24
|
+
bytes[1] = @intFromEnum(operation);
|
|
25
|
+
word(bytes[4..8], nodes.len);
|
|
26
|
+
word(bytes[8..12], sources.len);
|
|
27
|
+
word(bytes[12..16], capacity);
|
|
28
|
+
word(bytes[16..20], states);
|
|
29
|
+
for (nodes, 0..) |node, i| {
|
|
30
|
+
const fact = bytes[24 + i * 16 ..][0..16];
|
|
31
|
+
wide(fact[0..8], node.widget.id);
|
|
32
|
+
fact[8] = @intCast(canvas.widgetKindCode(node.widget.kind));
|
|
33
|
+
const selection = node.widget.text_selection;
|
|
34
|
+
fact[9] = @as(u8, @intFromBool(node.widget.autofocus)) |
|
|
35
|
+
(@as(u8, @intFromBool(selection != null)) << 1) |
|
|
36
|
+
(@as(u8, @intFromBool(if (selection) |value| !value.isCollapsed(node.widget.text.len) else false)) << 2) |
|
|
37
|
+
(@as(u8, @intFromBool(node.widget.hasCodeDiff())) << 3) |
|
|
38
|
+
(@as(u8, @intFromBool(node.widget.state.selected)) << 4);
|
|
39
|
+
std.mem.writeInt(u32, fact[12..16], @bitCast(node.widget.value), .little);
|
|
40
|
+
}
|
|
41
|
+
for (sources, 0..) |source, i| {
|
|
42
|
+
const fact = bytes[24 + (nodes.len + i) * 16 ..][0..16];
|
|
43
|
+
wide(fact[0..8], source.id);
|
|
44
|
+
fact[8] = if (comptime @hasField(@TypeOf(source), "kind")) @intCast(canvas.widgetKindCode(source.kind)) else 0;
|
|
45
|
+
}
|
|
46
|
+
var output: [16 + limits.max_canvas_widget_nodes_per_view * 12]u8 = undefined;
|
|
47
|
+
const size = callback(bytes, &output);
|
|
48
|
+
if (size < 16 or size > output.len or output[0] != 92 or output[1] != @intFromEnum(operation) or output[2] != 0 or output[3] != 0 or read(output[12..16]) != 0)
|
|
49
|
+
@panic("invalid compiled widget retention header");
|
|
50
|
+
var plan = Plan{};
|
|
51
|
+
plan.count = read(output[4..8]);
|
|
52
|
+
const target = read(output[8..12]);
|
|
53
|
+
if (plan.count > capacity or size != 16 + plan.count * 12 or (target != std.math.maxInt(u32) and (operation != .autofocus or target >= nodes.len)))
|
|
54
|
+
@panic("invalid compiled widget retention counts");
|
|
55
|
+
plan.target = if (target == std.math.maxInt(u32)) null else target;
|
|
56
|
+
for (plan.entries[0..plan.count], 0..) |*entry, i| {
|
|
57
|
+
const at = 16 + i * 12;
|
|
58
|
+
const index = read(output[at..][0..4]);
|
|
59
|
+
const source = read(output[at + 4 ..][0..4]);
|
|
60
|
+
const flags = read(output[at + 8 ..][0..4]);
|
|
61
|
+
if (index >= nodes.len or (i > 0 and index <= plan.entries[i - 1].node) or (source != std.math.maxInt(u32) and source >= sources.len) or flags > 7)
|
|
62
|
+
@panic("invalid compiled widget retention entry");
|
|
63
|
+
entry.* = .{ .node = index, .source = if (source == std.math.maxInt(u32)) null else source, .selected = flags & 1 != 0, .resizable = flags & 2 != 0, .code_diff = flags & 4 != 0 };
|
|
64
|
+
}
|
|
65
|
+
return plan;
|
|
66
|
+
}
|
|
67
|
+
fn word(bytes: *[4]u8, value: usize) void {
|
|
68
|
+
std.mem.writeInt(u32, bytes, @intCast(value), .little);
|
|
69
|
+
}
|
|
70
|
+
fn wide(bytes: *[8]u8, value: u64) void {
|
|
71
|
+
std.mem.writeInt(u64, bytes, value, .little);
|
|
72
|
+
}
|
|
73
|
+
fn read(bytes: *const [4]u8) usize {
|
|
74
|
+
return std.mem.readInt(u32, bytes, .little);
|
|
75
|
+
}
|
|
@@ -208,7 +208,18 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
|
|
|
208
208
|
/// back on platform failure. A window that was never hidden
|
|
209
209
|
/// just comes to the front.
|
|
210
210
|
pub fn showWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
|
|
211
|
-
|
|
211
|
+
return Self.showWindowWithNative(self, window_id, true);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// Apply the same immediate show transition during replay. Native
|
|
215
|
+
/// window notifications still arrive from the journal afterward.
|
|
216
|
+
pub fn restoreWindowShow(self: *Runtime, label: []const u8) void {
|
|
217
|
+
const index = Self.findWindowIndexByLabel(self, label) orelse return;
|
|
218
|
+
Self.showWindowWithNative(self, self.windows[index].info.id, false) catch return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
fn showWindowWithNative(self: *Runtime, window_id: platform.WindowId, execute_native: bool) anyerror!void {
|
|
222
|
+
if (self.window_lifecycle_policy) |policy| return Self.executeWindowCapabilityWithNative(self, policy, .show, window_id, execute_native);
|
|
212
223
|
const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
|
|
213
224
|
// A closed window keeps its table slot (the id and label
|
|
214
225
|
// release lazily, at the next create), so resolving the id
|
|
@@ -221,7 +232,7 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
|
|
|
221
232
|
if (!self.windows[index].info.open) return error.WindowNotFound;
|
|
222
233
|
const was_hidden = self.windows[index].info.hidden;
|
|
223
234
|
self.windows[index].info.hidden = false;
|
|
224
|
-
self.options.platform.services.showWindow(window_id) catch |err| {
|
|
235
|
+
if (execute_native) self.options.platform.services.showWindow(window_id) catch |err| {
|
|
225
236
|
self.windows[index].info.hidden = was_hidden;
|
|
226
237
|
return err;
|
|
227
238
|
};
|
|
@@ -239,6 +250,10 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
|
|
|
239
250
|
/// Outcome classification crosses the policy boundary; rollback fields,
|
|
240
251
|
/// replay exceptions and follow-up focus stay in the compiled program.
|
|
241
252
|
pub fn executeWindowCapability(self: *Runtime, policy: lifecycle.Policy, verb: lifecycle.Verb, window_id: platform.WindowId) anyerror!void {
|
|
253
|
+
return Self.executeWindowCapabilityWithNative(self, policy, verb, window_id, true);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
fn executeWindowCapabilityWithNative(self: *Runtime, policy: lifecycle.Policy, verb: lifecycle.Verb, window_id: platform.WindowId, execute_native: bool) anyerror!void {
|
|
242
257
|
const begin = lifecycle.plan(policy, self, .begin, .{ .id = window_id, .variant = @intFromEnum(verb) });
|
|
243
258
|
try begin.admitted();
|
|
244
259
|
const index = begin.selected.?;
|
|
@@ -246,7 +261,7 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
|
|
|
246
261
|
begin.apply(&self.windows[index].info);
|
|
247
262
|
if (begin.has(16)) try Self.showWindow(self, window_id);
|
|
248
263
|
var failure: ?anyerror = null;
|
|
249
|
-
switch (verb) {
|
|
264
|
+
if (execute_native) switch (verb) {
|
|
250
265
|
.close => self.options.platform.services.closeWindow(window_id) catch |err| {
|
|
251
266
|
failure = err;
|
|
252
267
|
},
|
|
@@ -260,7 +275,7 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
|
|
|
260
275
|
failure = err;
|
|
261
276
|
},
|
|
262
277
|
.minimize => return self.options.platform.services.minimizeWindow(window_id),
|
|
263
|
-
}
|
|
278
|
+
};
|
|
264
279
|
const finish = lifecycle.plan(policy, self, .finish, .{ .cursor = index, .variant = @intFromEnum(verb), .saved = saved, .value = self.replay_window_chrome_active, .outcome = if (failure) |err| (if (err == error.WindowNotFound) .window_not_found else .failed) else .success });
|
|
265
280
|
finish.apply(&self.windows[index].info);
|
|
266
281
|
if (finish.has(8)) return failure.?;
|
package/src/security/root.zig
CHANGED
|
@@ -9,6 +9,7 @@ pub const permission_clipboard = "clipboard";
|
|
|
9
9
|
pub const permission_network = "network";
|
|
10
10
|
pub const permission_notifications = "notifications";
|
|
11
11
|
pub const permission_credentials = "credentials";
|
|
12
|
+
pub const permission_keyboard_input = "keyboard_input";
|
|
12
13
|
|
|
13
14
|
pub const ExternalLinkAction = enum(c_int) {
|
|
14
15
|
deny = 0,
|
|
@@ -1410,6 +1410,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1410
1410
|
\\ const trace_option = b.option(TraceOption, "trace", "Trace output: off, events, runtime, all") orelse .events;
|
|
1411
1411
|
\\ const debug_overlay = b.option(bool, "debug-overlay", "Enable debug overlay output") orelse false;
|
|
1412
1412
|
\\ const automation_enabled = b.option(bool, "automation", "Enable Native SDK automation artifacts") orelse false;
|
|
1413
|
+
\\ const webview_inspection = b.option(bool, "webview-inspect", "Enable macOS system WebView inspection (default: Debug builds only)");
|
|
1413
1414
|
\\ const js_bridge_enabled = b.option(bool, "js-bridge", "Enable optional JavaScript bridge stubs") orelse false;
|
|
1414
1415
|
\\ const web_engine_override = b.option(WebEngineOption, "web-engine", "Override app.zon web engine: system, chromium");
|
|
1415
1416
|
\\ const web_layer_override = b.option(WebLayerOption, "web-layer", "Override app.zon webview_layer: auto, include, exclude");
|
|
@@ -1460,6 +1461,9 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1460
1461
|
\\ options.addOption([]const u8, "web_engine", @tagName(web_engine));
|
|
1461
1462
|
\\ options.addOption(bool, "debug_overlay", debug_overlay);
|
|
1462
1463
|
\\ options.addOption(bool, "automation", automation_enabled);
|
|
1464
|
+
\\ // Resolve the default inside each runner so the separate packaged
|
|
1465
|
+
\\ // release binary never inherits the development binary's setting.
|
|
1466
|
+
\\ options.addOption(?bool, "webview_inspection", webview_inspection);
|
|
1463
1467
|
\\ options.addOption(bool, "js_bridge", js_bridge_enabled);
|
|
1464
1468
|
\\ options.addOption(bool, "web_layer", web_layer);
|
|
1465
1469
|
\\ const options_mod = options.createModule();
|
|
@@ -2410,6 +2414,10 @@ fn runnerZig() []const u8 {
|
|
|
2410
2414
|
\\ .version = manifestStringField("version"),
|
|
2411
2415
|
\\ .description = manifestStringField("description"),
|
|
2412
2416
|
\\ .has_web_content = manifestHasWebContent(),
|
|
2417
|
+
\\ .webview_inspection = if (@hasDecl(build_options, "webview_inspection"))
|
|
2418
|
+
\\ build_options.webview_inspection orelse (@import("builtin").mode == .Debug)
|
|
2419
|
+
\\ else
|
|
2420
|
+
\\ @import("builtin").mode == .Debug,
|
|
2413
2421
|
\\ .declares_tray = manifestDeclaresTrayCapability(),
|
|
2414
2422
|
\\ .dock_visible = manifestDockVisible(),
|
|
2415
2423
|
\\ .window_title = self.window_title,
|
package/src/tooling/ts_core.zig
CHANGED
|
@@ -519,10 +519,15 @@ pub const ServicePackage = struct {
|
|
|
519
519
|
content_hash: []const u8,
|
|
520
520
|
};
|
|
521
521
|
|
|
522
|
+
/// Where `native check` keeps the core contract it checks markup against.
|
|
523
|
+
pub const check_contract_path = ".native/cache/check/core.contract.json";
|
|
524
|
+
|
|
522
525
|
/// Run the TypeScript frontend in check-only mode on src/core.ts — and,
|
|
523
526
|
/// through it, the core's whole import graph under src/ — and surface its NS
|
|
524
527
|
/// diagnostics verbatim. Manifest-owned routes ride into the same typed Msg
|
|
525
|
-
/// contract the watched dev host invokes on each of its own restarts.
|
|
528
|
+
/// contract the watched dev host invokes on each of its own restarts. The
|
|
529
|
+
/// core contract lands at `check_contract_path`, the same document the
|
|
530
|
+
/// build compiles the views against.
|
|
526
531
|
pub fn checkCore(
|
|
527
532
|
allocator: std.mem.Allocator,
|
|
528
533
|
io: std.Io,
|
|
@@ -547,6 +552,8 @@ pub fn checkCore(
|
|
|
547
552
|
var persist_version_arg: ?[]u8 = null;
|
|
548
553
|
defer if (persist_version_arg) |value| allocator.free(value);
|
|
549
554
|
try argv.appendSlice(allocator, &.{ "node", runner_path, cli_path, "src/core.ts" });
|
|
555
|
+
try std.Io.Dir.cwd().createDirPath(io, std.fs.path.dirname(check_contract_path).?);
|
|
556
|
+
try argv.appendSlice(allocator, &.{ "--contract", check_contract_path, "--contract-entry", "src/core.ts" });
|
|
550
557
|
for (capabilities) |capability| try argv.appendSlice(allocator, &.{ "--capability", capability });
|
|
551
558
|
for (permissions) |permission| try argv.appendSlice(allocator, &.{ "--permission", permission });
|
|
552
559
|
var service_package_args: std.ArrayList([]u8) = .empty;
|
|
@@ -604,6 +611,75 @@ pub fn checkCore(
|
|
|
604
611
|
return error.CoreCheckFailed;
|
|
605
612
|
}
|
|
606
613
|
|
|
614
|
+
/// Where `native dev` and the running app exchange markup reloads: the
|
|
615
|
+
/// app's session announcement and the watcher's view updates. Local to one
|
|
616
|
+
/// dev session; never staged, built from, or packaged.
|
|
617
|
+
pub const view_reload_dir = ".native/dev";
|
|
618
|
+
|
|
619
|
+
/// Start the markup watcher for a `native dev` run of a view-reload build
|
|
620
|
+
/// (packages/core/src/view_reload_watch.ts). It snapshots the markup now,
|
|
621
|
+
/// before the build reads it, and exits when its stdin closes. Clears any
|
|
622
|
+
/// exchange left by an earlier session first.
|
|
623
|
+
pub fn startViewReloadWatch(allocator: std.mem.Allocator, io: std.Io, base_env: *std.process.Environ.Map, framework_root: []const u8) !std.process.Child {
|
|
624
|
+
const watch_path = try transpilerPath(allocator, io, framework_root, "src/view_reload_watch.ts");
|
|
625
|
+
defer allocator.free(watch_path);
|
|
626
|
+
const runner_path = try tsRunnerPath(allocator, io, framework_root);
|
|
627
|
+
defer allocator.free(runner_path);
|
|
628
|
+
std.Io.Dir.cwd().deleteTree(io, view_reload_dir) catch {};
|
|
629
|
+
try std.Io.Dir.cwd().createDirPath(io, view_reload_dir);
|
|
630
|
+
return std.process.spawn(io, .{
|
|
631
|
+
.argv = &.{ "node", runner_path, watch_path, "--src", "src", "--dir", view_reload_dir },
|
|
632
|
+
.stdin = .pipe,
|
|
633
|
+
.stdout = .inherit,
|
|
634
|
+
.stderr = .inherit,
|
|
635
|
+
.environ_map = base_env,
|
|
636
|
+
}) catch return nodeMissing();
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
pub const ViewCheck = struct {
|
|
640
|
+
errors: usize = 0,
|
|
641
|
+
warnings: usize = 0,
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
/// Compile the app's markup against the contract `checkCore` wrote, with
|
|
645
|
+
/// the same TypeScript view compiler and source closure the build uses,
|
|
646
|
+
/// and report model state and Msg kinds no view uses. The checker prints
|
|
647
|
+
/// its own diagnostics; the returned counts feed the summary and
|
|
648
|
+
/// `--strict`.
|
|
649
|
+
pub fn checkViews(allocator: std.mem.Allocator, io: std.Io, base_env: *std.process.Environ.Map, framework_root: []const u8) !ViewCheck {
|
|
650
|
+
const check_path = try transpilerPath(allocator, io, framework_root, "src/view_check.ts");
|
|
651
|
+
defer allocator.free(check_path);
|
|
652
|
+
const runner_path = try tsRunnerPath(allocator, io, framework_root);
|
|
653
|
+
defer allocator.free(runner_path);
|
|
654
|
+
const result = std.process.run(allocator, io, .{
|
|
655
|
+
.argv = &.{ "node", runner_path, check_path, "--contract", check_contract_path, "--src", "src" },
|
|
656
|
+
.stdout_limit = .limited(4096),
|
|
657
|
+
.environ_map = base_env,
|
|
658
|
+
}) catch |err| switch (err) {
|
|
659
|
+
error.FileNotFound => return nodeMissing(),
|
|
660
|
+
else => return err,
|
|
661
|
+
};
|
|
662
|
+
defer allocator.free(result.stdout);
|
|
663
|
+
defer allocator.free(result.stderr);
|
|
664
|
+
std.debug.print("{s}", .{result.stderr});
|
|
665
|
+
const exited_cleanly = switch (result.term) {
|
|
666
|
+
.exited => |code| code == 0,
|
|
667
|
+
else => false,
|
|
668
|
+
};
|
|
669
|
+
if (exited_cleanly) {
|
|
670
|
+
if (parseViewCheck(allocator, result.stdout)) |counts| return counts else |_| {}
|
|
671
|
+
}
|
|
672
|
+
std.debug.print("native check: the TypeScript view checker did not report a verdict (output above)\n", .{});
|
|
673
|
+
return error.ViewCheckFailed;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
fn parseViewCheck(allocator: std.mem.Allocator, stdout: []const u8) !ViewCheck {
|
|
677
|
+
const line = std.mem.trim(u8, stdout, " \r\n");
|
|
678
|
+
const parsed = try std.json.parseFromSlice(ViewCheck, allocator, line, .{});
|
|
679
|
+
defer parsed.deinit();
|
|
680
|
+
return parsed.value;
|
|
681
|
+
}
|
|
682
|
+
|
|
607
683
|
/// The compiler-truth pass `checkCore` chains after the frontend: the
|
|
608
684
|
/// pinned external core compiler's analyzer over the same entry, with
|
|
609
685
|
/// the shipped SDK declarations mapped — the check verdict and the
|
|
@@ -964,6 +1040,13 @@ pub fn selfHealEditorPackage(allocator: std.mem.Allocator, io: std.Io, framework
|
|
|
964
1040
|
}
|
|
965
1041
|
}
|
|
966
1042
|
|
|
1043
|
+
test "the view checker verdict parses from its one stdout line" {
|
|
1044
|
+
const counts = try parseViewCheck(std.testing.allocator, "{\"errors\":0,\"warnings\":3}\n");
|
|
1045
|
+
try std.testing.expectEqual(@as(usize, 0), counts.errors);
|
|
1046
|
+
try std.testing.expectEqual(@as(usize, 3), counts.warnings);
|
|
1047
|
+
try std.testing.expectError(error.UnexpectedEndOfInput, parseViewCheck(std.testing.allocator, ""));
|
|
1048
|
+
}
|
|
1049
|
+
|
|
967
1050
|
test "core tree detection reads the tree, not config" {
|
|
968
1051
|
const io = std.testing.io;
|
|
969
1052
|
var cwd = std.Io.Dir.cwd();
|