@native-sdk/cli 0.4.3 → 0.5.0
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 +308 -72
- package/build/ts_run.mjs +63 -0
- package/build.zig +336 -7
- package/build.zig.zon +1 -0
- package/package.json +15 -10
- package/packages/core/package-lock.json +43 -0
- package/packages/core/package.json +37 -0
- package/packages/core/rt/rt.zig +1579 -0
- package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
- package/packages/core/sdk/core.ts +694 -0
- package/packages/core/sdk/events.ts +137 -0
- package/packages/core/sdk/text.ts +519 -0
- package/packages/core/src/checker.ts +1869 -0
- package/packages/core/src/cli.ts +68 -0
- package/packages/core/src/devhost.ts +291 -0
- package/packages/core/src/devhost_resolver.mjs +22 -0
- package/packages/core/src/diagnostics.ts +417 -0
- package/packages/core/src/emitter.ts +8815 -0
- package/packages/core/src/infer.ts +1515 -0
- package/packages/core/src/modules.ts +173 -0
- package/packages/core/src/ownership.ts +740 -0
- package/packages/core/src/text_polyfill.ts +337 -0
- package/packages/core/src/text_tables.ts +408 -0
- package/packages/core/src/transpile.ts +146 -0
- package/packages/core/src/typed_ast.ts +536 -0
- package/packages/core/src/types.ts +815 -0
- package/skill-data/core/SKILL.md +3 -0
- package/skill-data/native-ui/SKILL.md +30 -0
- package/skill-data/ts-core/SKILL.md +493 -0
- package/skill-data/zig/SKILL.md +208 -0
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/root.zig +75 -9
- package/src/app_runner/ts_core_main.zig +231 -0
- package/src/platform/linux/gtk_host.c +226 -21
- package/src/platform/windows/webview2_host.cpp +16 -10
- package/src/primitives/app_manifest/comptime_scene.zig +341 -0
- package/src/primitives/app_manifest/root.zig +13 -0
- package/src/primitives/app_manifest/types.zig +14 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/app_manifest/web_layer.zig +366 -0
- package/src/primitives/canvas/commands.zig +14 -7
- package/src/primitives/canvas/lazy_tls.zig +73 -0
- package/src/primitives/canvas/render_generic_resources.zig +22 -15
- package/src/primitives/canvas/root.zig +6 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +40 -32
- package/src/primitives/canvas/text_layout_cache.zig +29 -22
- package/src/primitives/canvas/text_measure_cache.zig +56 -41
- package/src/primitives/canvas/text_spans.zig +39 -26
- package/src/primitives/canvas/tokens.zig +54 -0
- package/src/primitives/canvas/ui.zig +125 -0
- package/src/primitives/canvas/ui_markup.zig +22 -3
- package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
- package/src/primitives/canvas/ui_markup_contract.zig +68 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
- package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
- package/src/primitives/canvas/ui_markup_view.zig +105 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
- package/src/primitives/canvas/ui_schema.zig +8 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_invalidation.zig +14 -7
- package/src/primitives/canvas/widget_render.zig +25 -15
- package/src/primitives/canvas/widget_render_controls.zig +15 -9
- package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +7 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +6 -0
- package/src/runtime/canvas_frame.zig +57 -36
- package/src/runtime/canvas_images.zig +9 -3
- package/src/runtime/canvas_widget_control_tests.zig +5 -6
- package/src/runtime/canvas_widget_runtime.zig +7 -4
- package/src/runtime/effects.zig +490 -2
- package/src/runtime/effects_host_tests.zig +594 -0
- package/src/runtime/flow.zig +8 -0
- package/src/runtime/platform_bridge_tests.zig +1 -0
- package/src/runtime/root.zig +18 -0
- package/src/runtime/session_replay.zig +7 -1
- package/src/runtime/session_tests.zig +35 -8
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_core_host.zig +1505 -0
- package/src/runtime/ts_core_host_tests.zig +1408 -0
- package/src/runtime/ts_ui_app.zig +469 -0
- package/src/runtime/ui_app.zig +58 -0
- package/src/runtime/view_canvas.zig +24 -17
- package/src/runtime/view_widget_tree.zig +2 -2
- package/src/runtime/web_layer_gate_tests.zig +242 -0
- package/src/runtime/window_storage.zig +5 -0
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/buildgraph.zig +7 -1
- package/src/tooling/codesign.zig +212 -105
- package/src/tooling/doctor.zig +78 -0
- package/src/tooling/manifest.zig +314 -1
- package/src/tooling/package.zig +722 -18
- package/src/tooling/raw_manifest.zig +16 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +911 -88
- package/src/tooling/ts_core.zig +486 -0
- package/src/tooling/verbs.zig +22 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
//! Comptime app.zon -> scene conversion: turn the manifest module's
|
|
2
|
+
//! `.shell` declaration (the anonymous ZON tuple a build imports as
|
|
3
|
+
//! `app_manifest_zon`) into a typed `ShellConfig`, so a generated wiring
|
|
4
|
+
//! module can run an app whose ONLY window/scene declaration is app.zon —
|
|
5
|
+
//! nothing repeated in Zig. The Zig app template keeps declaring its scene
|
|
6
|
+
//! in main.zig (both declarations there are user-owned); this converter is
|
|
7
|
+
//! for build-generated wiring where app.zon must be the single source of
|
|
8
|
+
//! truth. Unknown enum spellings are teaching @compileErrors naming the
|
|
9
|
+
//! field — the manifest validator accepts the same vocabularies at
|
|
10
|
+
//! `native check` time (validation.zig), so the two surfaces agree.
|
|
11
|
+
|
|
12
|
+
const std = @import("std");
|
|
13
|
+
const types = @import("types.zig");
|
|
14
|
+
|
|
15
|
+
/// The `.shell` scene from an imported app.zon module, as a comptime
|
|
16
|
+
/// `ShellConfig`. Absent shell (or absent windows) yields the empty
|
|
17
|
+
/// config — the runtime then keeps the host's default startup window.
|
|
18
|
+
pub fn shellConfigFrom(comptime manifest: anytype) types.ShellConfig {
|
|
19
|
+
comptime {
|
|
20
|
+
if (!@hasField(@TypeOf(manifest), "shell")) return .{};
|
|
21
|
+
const shell = manifest.shell;
|
|
22
|
+
// The whole conversion is ONE comptime evaluation sharing one
|
|
23
|
+
// backwards-branch budget, and the default (1000) does not survive
|
|
24
|
+
// a real manifest: every window and view costs field probes, slice
|
|
25
|
+
// concatenation, and enum-name scans, so a scene one field richer
|
|
26
|
+
// than the smallest demo dies mid-sort deep in std. Budget
|
|
27
|
+
// proportional to the declared scene instead — see
|
|
28
|
+
// sceneEvalBranchQuota for the per-node ceiling.
|
|
29
|
+
@setEvalBranchQuota(sceneEvalBranchQuota(shell));
|
|
30
|
+
var windows: []const types.ShellWindow = &.{};
|
|
31
|
+
if (@hasField(@TypeOf(shell), "windows")) {
|
|
32
|
+
for (shell.windows) |window| {
|
|
33
|
+
windows = windows ++ &[_]types.ShellWindow{shellWindowFrom(window)};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
var chrome: types.ShellChrome = .{};
|
|
37
|
+
if (@hasField(@TypeOf(shell), "chrome")) {
|
|
38
|
+
chrome = shellChromeFrom(shell.chrome);
|
|
39
|
+
}
|
|
40
|
+
return .{ .windows = windows, .chrome = chrome };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// The first `gpu_surface` view label in the scene — the canvas a
|
|
45
|
+
/// markup-viewed app renders into. A teaching @compileError when the
|
|
46
|
+
/// manifest declares none: a canvas app cannot render without one.
|
|
47
|
+
pub fn firstGpuSurfaceLabel(comptime scene: types.ShellConfig) []const u8 {
|
|
48
|
+
comptime {
|
|
49
|
+
// A separate top-level evaluation with its own default branch
|
|
50
|
+
// budget: walking a large converted scene must not die at 1000
|
|
51
|
+
// either. The walk is a compare per view, so a small per-view
|
|
52
|
+
// grant is plenty.
|
|
53
|
+
var views: comptime_int = 1;
|
|
54
|
+
for (scene.windows) |window| views += 1 + window.views.len;
|
|
55
|
+
@setEvalBranchQuota(1_000 + 16 * views);
|
|
56
|
+
for (scene.windows) |window| {
|
|
57
|
+
for (window.views) |view| {
|
|
58
|
+
if (view.kind == .gpu_surface) return view.label;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
@compileError("app.zon declares no gpu_surface view - a canvas app needs one: add" ++
|
|
62
|
+
" .views = .{ .{ .label = \"main-canvas\", .kind = \"gpu_surface\", .fill = true } } to the shell window");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn shellWindowFrom(comptime window: anytype) types.ShellWindow {
|
|
67
|
+
var out: types.ShellWindow = .{};
|
|
68
|
+
if (@hasField(@TypeOf(window), "label")) out.label = window.label;
|
|
69
|
+
if (@hasField(@TypeOf(window), "title")) {
|
|
70
|
+
if (@TypeOf(window.title) != @TypeOf(null)) out.title = window.title;
|
|
71
|
+
}
|
|
72
|
+
if (@hasField(@TypeOf(window), "width")) out.width = window.width;
|
|
73
|
+
if (@hasField(@TypeOf(window), "height")) out.height = window.height;
|
|
74
|
+
if (@hasField(@TypeOf(window), "x")) out.x = window.x;
|
|
75
|
+
if (@hasField(@TypeOf(window), "y")) out.y = window.y;
|
|
76
|
+
if (@hasField(@TypeOf(window), "resizable")) out.resizable = window.resizable;
|
|
77
|
+
if (@hasField(@TypeOf(window), "restore_state")) out.restore_state = window.restore_state;
|
|
78
|
+
if (@hasField(@TypeOf(window), "restore_policy")) {
|
|
79
|
+
out.restore_policy = enumField(types.WindowRestorePolicy, window.restore_policy, "restore_policy");
|
|
80
|
+
}
|
|
81
|
+
if (@hasField(@TypeOf(window), "titlebar")) {
|
|
82
|
+
out.titlebar = enumField(types.WindowTitlebarStyle, window.titlebar, "titlebar");
|
|
83
|
+
}
|
|
84
|
+
if (@hasField(@TypeOf(window), "min_width")) out.min_width = window.min_width;
|
|
85
|
+
if (@hasField(@TypeOf(window), "min_height")) out.min_height = window.min_height;
|
|
86
|
+
if (@hasField(@TypeOf(window), "views")) {
|
|
87
|
+
var views: []const types.ShellView = &.{};
|
|
88
|
+
for (window.views) |view| {
|
|
89
|
+
views = views ++ &[_]types.ShellView{shellViewFrom(view)};
|
|
90
|
+
}
|
|
91
|
+
out.views = views;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fn shellViewFrom(comptime view: anytype) types.ShellView {
|
|
97
|
+
if (!@hasField(@TypeOf(view), "label")) @compileError("app.zon shell view needs a .label");
|
|
98
|
+
if (!@hasField(@TypeOf(view), "kind")) @compileError("app.zon shell view needs a .kind");
|
|
99
|
+
var out: types.ShellView = .{
|
|
100
|
+
.label = view.label,
|
|
101
|
+
.kind = enumField(types.ViewKind, view.kind, "view kind"),
|
|
102
|
+
};
|
|
103
|
+
if (@hasField(@TypeOf(view), "parent")) out.parent = view.parent;
|
|
104
|
+
if (@hasField(@TypeOf(view), "edge")) out.edge = enumField(types.ShellEdge, view.edge, "edge");
|
|
105
|
+
if (@hasField(@TypeOf(view), "axis")) out.axis = enumField(types.ShellAxis, view.axis, "axis");
|
|
106
|
+
if (@hasField(@TypeOf(view), "x")) out.x = view.x;
|
|
107
|
+
if (@hasField(@TypeOf(view), "y")) out.y = view.y;
|
|
108
|
+
if (@hasField(@TypeOf(view), "width")) out.width = view.width;
|
|
109
|
+
if (@hasField(@TypeOf(view), "height")) out.height = view.height;
|
|
110
|
+
if (@hasField(@TypeOf(view), "min_width")) out.min_width = view.min_width;
|
|
111
|
+
if (@hasField(@TypeOf(view), "min_height")) out.min_height = view.min_height;
|
|
112
|
+
if (@hasField(@TypeOf(view), "max_width")) out.max_width = view.max_width;
|
|
113
|
+
if (@hasField(@TypeOf(view), "max_height")) out.max_height = view.max_height;
|
|
114
|
+
if (@hasField(@TypeOf(view), "fill")) out.fill = view.fill;
|
|
115
|
+
if (@hasField(@TypeOf(view), "layer")) out.layer = view.layer;
|
|
116
|
+
if (@hasField(@TypeOf(view), "visible")) out.visible = view.visible;
|
|
117
|
+
if (@hasField(@TypeOf(view), "enabled")) out.enabled = view.enabled;
|
|
118
|
+
if (@hasField(@TypeOf(view), "role")) out.role = view.role;
|
|
119
|
+
if (@hasField(@TypeOf(view), "accessibility_label")) out.accessibility_label = view.accessibility_label;
|
|
120
|
+
if (@hasField(@TypeOf(view), "url")) out.url = view.url;
|
|
121
|
+
if (@hasField(@TypeOf(view), "text")) out.text = view.text;
|
|
122
|
+
if (@hasField(@TypeOf(view), "command")) out.command = view.command;
|
|
123
|
+
if (@hasField(@TypeOf(view), "gpu_backend")) out.gpu_backend = enumField(types.GpuSurfaceBackend, view.gpu_backend, "gpu_backend");
|
|
124
|
+
if (@hasField(@TypeOf(view), "gpu_pixel_format")) out.gpu_pixel_format = enumField(types.GpuSurfacePixelFormat, view.gpu_pixel_format, "gpu_pixel_format");
|
|
125
|
+
if (@hasField(@TypeOf(view), "gpu_present_mode")) out.gpu_present_mode = enumField(types.GpuSurfacePresentMode, view.gpu_present_mode, "gpu_present_mode");
|
|
126
|
+
if (@hasField(@TypeOf(view), "gpu_alpha_mode")) out.gpu_alpha_mode = enumField(types.GpuSurfaceAlphaMode, view.gpu_alpha_mode, "gpu_alpha_mode");
|
|
127
|
+
if (@hasField(@TypeOf(view), "gpu_color_space")) out.gpu_color_space = enumField(types.GpuSurfaceColorSpace, view.gpu_color_space, "gpu_color_space");
|
|
128
|
+
if (@hasField(@TypeOf(view), "gpu_vsync")) out.gpu_vsync = view.gpu_vsync;
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fn shellChromeFrom(comptime chrome: anytype) types.ShellChrome {
|
|
133
|
+
var out: types.ShellChrome = .{};
|
|
134
|
+
if (@hasField(@TypeOf(chrome), "tabs")) {
|
|
135
|
+
var tabs: []const types.ShellTab = &.{};
|
|
136
|
+
for (chrome.tabs) |tab| {
|
|
137
|
+
var entry: types.ShellTab = .{ .id = tab.id, .label = tab.label };
|
|
138
|
+
if (@hasField(@TypeOf(tab), "icon")) entry.icon = tab.icon;
|
|
139
|
+
tabs = tabs ++ &[_]types.ShellTab{entry};
|
|
140
|
+
}
|
|
141
|
+
out.tabs = tabs;
|
|
142
|
+
}
|
|
143
|
+
if (@hasField(@TypeOf(chrome), "primary_action")) {
|
|
144
|
+
const action = chrome.primary_action;
|
|
145
|
+
var entry: types.ShellPrimaryAction = .{ .id = action.id, .label = action.label };
|
|
146
|
+
if (@hasField(@TypeOf(action), "icon")) entry.icon = action.icon;
|
|
147
|
+
out.primary_action = entry;
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// The branch budget for converting `shell`, proportional to its size.
|
|
153
|
+
/// Counting first is safe: windows.len is comptime-known (no branches),
|
|
154
|
+
/// so an interim grant covers the counting walk itself, and the walk is
|
|
155
|
+
/// one pass over the windows. The 2000-per-node ceiling is deliberately
|
|
156
|
+
/// fat — a view costs ~25 field probes, a slice concatenation, and up to
|
|
157
|
+
/// six linear enum-name scans (see enumField), each of which
|
|
158
|
+
/// short-circuits on length, so real cost sits far below it.
|
|
159
|
+
fn sceneEvalBranchQuota(comptime shell: anytype) comptime_int {
|
|
160
|
+
comptime {
|
|
161
|
+
var nodes: comptime_int = 4; // the shell itself, chrome, slack
|
|
162
|
+
if (@hasField(@TypeOf(shell), "windows")) {
|
|
163
|
+
@setEvalBranchQuota(1_000 + 16 * shell.windows.len);
|
|
164
|
+
for (shell.windows) |window| {
|
|
165
|
+
nodes += 1;
|
|
166
|
+
if (@hasField(@TypeOf(window), "views")) nodes += window.views.len;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (@hasField(@TypeOf(shell), "chrome")) {
|
|
170
|
+
if (@hasField(@TypeOf(shell.chrome), "tabs")) nodes += shell.chrome.tabs.len;
|
|
171
|
+
}
|
|
172
|
+
return 2_000 * nodes;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fn enumField(comptime E: type, comptime value: []const u8, comptime what: []const u8) E {
|
|
177
|
+
comptime {
|
|
178
|
+
// NOT std.meta.stringToEnum: that builds a sorted StaticStringMap
|
|
179
|
+
// at comptime on EVERY call, and its own quota grant is a @max
|
|
180
|
+
// that never rises above the default for small enums — so each
|
|
181
|
+
// enum-mapped manifest field pays a full comptime pdq sort out of
|
|
182
|
+
// the shared budget. A linear name scan is a handful of branches
|
|
183
|
+
// per member (length short-circuit first) and needs no map.
|
|
184
|
+
for (@typeInfo(E).@"enum".fields) |field| {
|
|
185
|
+
if (std.mem.eql(u8, field.name, value)) return @field(E, field.name);
|
|
186
|
+
}
|
|
187
|
+
@compileError("unknown app.zon " ++ what ++ " \"" ++ value ++ "\" - expected one of: " ++ memberList(E));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
fn memberList(comptime E: type) []const u8 {
|
|
192
|
+
comptime {
|
|
193
|
+
var out: []const u8 = "";
|
|
194
|
+
for (@typeInfo(E).@"enum".fields, 0..) |field, index| {
|
|
195
|
+
out = out ++ (if (index == 0) "" else ", ") ++ field.name;
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
test "shellConfigFrom converts a zon-shaped scene" {
|
|
202
|
+
const manifest = .{
|
|
203
|
+
.name = "demo",
|
|
204
|
+
.shell = .{
|
|
205
|
+
.windows = .{
|
|
206
|
+
.{
|
|
207
|
+
.label = "main",
|
|
208
|
+
.title = "Demo",
|
|
209
|
+
.width = 480,
|
|
210
|
+
.height = 320,
|
|
211
|
+
.restore_state = false,
|
|
212
|
+
.restore_policy = "center_on_primary",
|
|
213
|
+
.views = .{
|
|
214
|
+
.{ .label = "main-canvas", .kind = "gpu_surface", .fill = true, .gpu_backend = "metal", .gpu_vsync = true },
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
const scene = comptime shellConfigFrom(manifest);
|
|
221
|
+
try std.testing.expectEqual(@as(usize, 1), scene.windows.len);
|
|
222
|
+
try std.testing.expectEqualStrings("main", scene.windows[0].label);
|
|
223
|
+
try std.testing.expectEqualStrings("Demo", scene.windows[0].title.?);
|
|
224
|
+
try std.testing.expectEqual(@as(f32, 480), scene.windows[0].width);
|
|
225
|
+
try std.testing.expectEqual(types.WindowRestorePolicy.center_on_primary, scene.windows[0].restore_policy);
|
|
226
|
+
try std.testing.expectEqual(@as(usize, 1), scene.windows[0].views.len);
|
|
227
|
+
try std.testing.expectEqual(types.ViewKind.gpu_surface, scene.windows[0].views[0].kind);
|
|
228
|
+
try std.testing.expectEqual(types.GpuSurfaceBackend.metal, scene.windows[0].views[0].gpu_backend.?);
|
|
229
|
+
try std.testing.expect(scene.windows[0].views[0].fill);
|
|
230
|
+
try std.testing.expectEqualStrings("main-canvas", comptime firstGpuSurfaceLabel(scene));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
test "shellConfigFrom yields the empty scene when app.zon declares none" {
|
|
234
|
+
const scene = comptime shellConfigFrom(.{ .name = "bare" });
|
|
235
|
+
try std.testing.expectEqual(@as(usize, 0), scene.windows.len);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Branch-budget regression guard: a scene substantially richer than any
|
|
239
|
+
// shipped example — several windows, every enum-mapped shell field spelled
|
|
240
|
+
// as a string, chrome — must CONVERT, not die on "evaluation exceeded N
|
|
241
|
+
// backwards branches" in a comptime sort deep in std (the system-monitor-ts
|
|
242
|
+
// macOS build regression: one field richer than the smallest demo was
|
|
243
|
+
// already over the default quota).
|
|
244
|
+
test "shellConfigFrom converts a rich scene without exhausting the branch quota" {
|
|
245
|
+
const rich_view = .{
|
|
246
|
+
.label = "surface",
|
|
247
|
+
.kind = "gpu_surface",
|
|
248
|
+
.parent = "root",
|
|
249
|
+
.edge = "left",
|
|
250
|
+
.axis = "column",
|
|
251
|
+
.x = 0,
|
|
252
|
+
.y = 0,
|
|
253
|
+
.width = 400,
|
|
254
|
+
.height = 300,
|
|
255
|
+
.min_width = 200,
|
|
256
|
+
.min_height = 150,
|
|
257
|
+
.max_width = 800,
|
|
258
|
+
.max_height = 600,
|
|
259
|
+
.fill = true,
|
|
260
|
+
.layer = 1,
|
|
261
|
+
.visible = true,
|
|
262
|
+
.enabled = true,
|
|
263
|
+
.role = "Canvas",
|
|
264
|
+
.accessibility_label = "Main canvas",
|
|
265
|
+
.gpu_backend = "metal",
|
|
266
|
+
.gpu_pixel_format = "bgra8_unorm",
|
|
267
|
+
.gpu_present_mode = "timer",
|
|
268
|
+
.gpu_alpha_mode = "opaque",
|
|
269
|
+
.gpu_color_space = "display_p3",
|
|
270
|
+
.gpu_vsync = true,
|
|
271
|
+
};
|
|
272
|
+
const rich_window = .{
|
|
273
|
+
.label = "main",
|
|
274
|
+
.title = "Rich",
|
|
275
|
+
.width = 1144,
|
|
276
|
+
.height = 720,
|
|
277
|
+
.x = 10,
|
|
278
|
+
.y = 20,
|
|
279
|
+
.resizable = true,
|
|
280
|
+
.restore_state = false,
|
|
281
|
+
.restore_policy = "center_on_primary",
|
|
282
|
+
.titlebar = "hidden_inset_tall",
|
|
283
|
+
.min_width = 1144,
|
|
284
|
+
.min_height = 720,
|
|
285
|
+
.views = .{
|
|
286
|
+
rich_view,
|
|
287
|
+
.{ .label = "side", .kind = "sidebar", .edge = "right", .axis = "row", .width = 240 },
|
|
288
|
+
.{ .label = "status", .kind = "statusbar", .edge = "bottom", .visible = true },
|
|
289
|
+
.{ .label = "tools", .kind = "toolbar", .edge = "top", .enabled = true },
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
const manifest = .{
|
|
293
|
+
.name = "rich",
|
|
294
|
+
.shell = .{
|
|
295
|
+
.windows = .{
|
|
296
|
+
rich_window,
|
|
297
|
+
.{
|
|
298
|
+
.label = "aux",
|
|
299
|
+
.titlebar = "hidden_inset",
|
|
300
|
+
.restore_policy = "clamp_to_visible_screen",
|
|
301
|
+
.views = .{
|
|
302
|
+
.{ .label = "aux-canvas", .kind = "gpu_surface", .fill = true, .gpu_backend = "software", .gpu_alpha_mode = "premultiplied", .gpu_color_space = "srgb" },
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
.{
|
|
306
|
+
.label = "chromeless",
|
|
307
|
+
.titlebar = "chromeless",
|
|
308
|
+
.views = .{
|
|
309
|
+
.{ .label = "web", .kind = "webview", .url = "zero://app" },
|
|
310
|
+
.{ .label = "split", .kind = "split", .axis = "row" },
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
.chrome = .{
|
|
315
|
+
.tabs = .{
|
|
316
|
+
.{ .id = "one", .label = "One", .icon = "gauge" },
|
|
317
|
+
.{ .id = "two", .label = "Two" },
|
|
318
|
+
.{ .id = "three", .label = "Three" },
|
|
319
|
+
},
|
|
320
|
+
.primary_action = .{ .id = "go", .label = "Go", .icon = "play" },
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
const scene = comptime shellConfigFrom(manifest);
|
|
325
|
+
try std.testing.expectEqual(@as(usize, 3), scene.windows.len);
|
|
326
|
+
try std.testing.expectEqual(types.WindowTitlebarStyle.hidden_inset_tall, scene.windows[0].titlebar);
|
|
327
|
+
try std.testing.expectEqual(types.WindowRestorePolicy.center_on_primary, scene.windows[0].restore_policy);
|
|
328
|
+
try std.testing.expectEqual(@as(usize, 4), scene.windows[0].views.len);
|
|
329
|
+
try std.testing.expectEqual(types.ShellEdge.left, scene.windows[0].views[0].edge.?);
|
|
330
|
+
try std.testing.expectEqual(types.ShellAxis.column, scene.windows[0].views[0].axis.?);
|
|
331
|
+
try std.testing.expectEqual(types.GpuSurfacePixelFormat.bgra8_unorm, scene.windows[0].views[0].gpu_pixel_format.?);
|
|
332
|
+
try std.testing.expectEqual(types.GpuSurfacePresentMode.timer, scene.windows[0].views[0].gpu_present_mode.?);
|
|
333
|
+
try std.testing.expectEqual(types.GpuSurfaceAlphaMode.@"opaque", scene.windows[0].views[0].gpu_alpha_mode.?);
|
|
334
|
+
try std.testing.expectEqual(types.GpuSurfaceColorSpace.display_p3, scene.windows[0].views[0].gpu_color_space.?);
|
|
335
|
+
try std.testing.expectEqual(types.GpuSurfaceBackend.software, scene.windows[1].views[0].gpu_backend.?);
|
|
336
|
+
try std.testing.expectEqual(types.GpuSurfaceAlphaMode.premultiplied, scene.windows[1].views[0].gpu_alpha_mode.?);
|
|
337
|
+
try std.testing.expectEqual(types.WindowTitlebarStyle.chromeless, scene.windows[2].titlebar);
|
|
338
|
+
try std.testing.expectEqual(@as(usize, 3), scene.chrome.tabs.len);
|
|
339
|
+
try std.testing.expectEqualStrings("go", scene.chrome.primary_action.?.id);
|
|
340
|
+
try std.testing.expectEqualStrings("surface", comptime firstGpuSurfaceLabel(scene));
|
|
341
|
+
}
|
|
@@ -2,6 +2,10 @@ const std = @import("std");
|
|
|
2
2
|
const types = @import("types.zig");
|
|
3
3
|
const validation = @import("validation.zig");
|
|
4
4
|
|
|
5
|
+
/// The web-layer inference contract: the one declare-to-use definition
|
|
6
|
+
/// every boundary (build graph, CLI tooling, app runner) consumes.
|
|
7
|
+
pub const web_layer = @import("web_layer.zig");
|
|
8
|
+
|
|
5
9
|
pub const ValidationError = types.ValidationError;
|
|
6
10
|
pub const max_shortcuts = types.max_shortcuts;
|
|
7
11
|
pub const max_shortcut_id_bytes = types.max_shortcut_id_bytes;
|
|
@@ -27,6 +31,7 @@ pub const max_url_schemes = types.max_url_schemes;
|
|
|
27
31
|
pub const Platform = types.Platform;
|
|
28
32
|
pub const PackageKind = types.PackageKind;
|
|
29
33
|
pub const WebEngine = types.WebEngine;
|
|
34
|
+
pub const WebViewLayer = types.WebViewLayer;
|
|
30
35
|
pub const CefConfig = types.CefConfig;
|
|
31
36
|
pub const IconPurpose = types.IconPurpose;
|
|
32
37
|
pub const PermissionKind = types.PermissionKind;
|
|
@@ -87,6 +92,8 @@ pub const validateFileAssociations = validation.validateFileAssociations;
|
|
|
87
92
|
pub const validateUrlSchemes = validation.validateUrlSchemes;
|
|
88
93
|
pub const validateShortcutsForPlatforms = validation.validateShortcutsForPlatforms;
|
|
89
94
|
pub const validateCefConfig = validation.validateCefConfig;
|
|
95
|
+
pub const validateWebViewLayer = validation.validateWebViewLayer;
|
|
96
|
+
pub const manifestDeclaresWebContent = validation.manifestDeclaresWebContent;
|
|
90
97
|
pub const AppIdMode = validation.AppIdMode;
|
|
91
98
|
pub const validateAppId = validation.validateAppId;
|
|
92
99
|
pub const validateName = validation.validateName;
|
|
@@ -102,8 +109,14 @@ pub const validateUpdates = validation.validateUpdates;
|
|
|
102
109
|
pub const validatePlatforms = validation.validatePlatforms;
|
|
103
110
|
pub const validatePackageMetadata = validation.validatePackageMetadata;
|
|
104
111
|
pub const versionString = validation.versionString;
|
|
112
|
+
pub const shellConfigFrom = comptime_scene.shellConfigFrom;
|
|
113
|
+
pub const firstGpuSurfaceLabel = comptime_scene.firstGpuSurfaceLabel;
|
|
114
|
+
|
|
115
|
+
const comptime_scene = @import("comptime_scene.zig");
|
|
105
116
|
|
|
106
117
|
test {
|
|
107
118
|
std.testing.refAllDecls(@This());
|
|
108
119
|
_ = @import("tests.zig");
|
|
120
|
+
_ = comptime_scene;
|
|
121
|
+
_ = @import("web_layer.zig");
|
|
109
122
|
}
|
|
@@ -26,6 +26,7 @@ pub const ValidationError = error{
|
|
|
26
26
|
InvalidTimeout,
|
|
27
27
|
InvalidKeyword,
|
|
28
28
|
MissingRequiredField,
|
|
29
|
+
WebViewLayerConflict,
|
|
29
30
|
NoSpaceLeft,
|
|
30
31
|
};
|
|
31
32
|
|
|
@@ -84,6 +85,18 @@ pub const WebEngine = enum {
|
|
|
84
85
|
chromium,
|
|
85
86
|
};
|
|
86
87
|
|
|
88
|
+
/// Whether the app ships the embedded web layer. `auto` (the default)
|
|
89
|
+
/// infers it from the manifest's declarations — a `.frontend` block, the
|
|
90
|
+
/// `webview` capability, a `.shell` webview view, or the Chromium engine
|
|
91
|
+
/// all mean web; none of them means native-only. `include`/`exclude`
|
|
92
|
+
/// override the inference, and an `exclude` that contradicts a web
|
|
93
|
+
/// declaration is a validation error, never a silently broken build.
|
|
94
|
+
pub const WebViewLayer = enum {
|
|
95
|
+
auto,
|
|
96
|
+
include,
|
|
97
|
+
exclude,
|
|
98
|
+
};
|
|
99
|
+
|
|
87
100
|
pub const CefConfig = struct {
|
|
88
101
|
dir: []const u8 = "third_party/cef/macos",
|
|
89
102
|
auto_install: bool = false,
|
|
@@ -582,6 +595,7 @@ pub const Manifest = struct {
|
|
|
582
595
|
file_associations: []const FileAssociation = &.{},
|
|
583
596
|
url_schemes: []const UrlScheme = &.{},
|
|
584
597
|
cef: CefConfig = .{},
|
|
598
|
+
webview_layer: WebViewLayer = .auto,
|
|
585
599
|
package: PackageMetadata = .{},
|
|
586
600
|
updates: UpdateConfig = .{},
|
|
587
601
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const types = @import("types.zig");
|
|
3
|
+
const web_layer = @import("web_layer.zig");
|
|
3
4
|
|
|
4
5
|
const ValidationError = types.ValidationError;
|
|
5
6
|
const max_shortcuts = types.max_shortcuts;
|
|
@@ -85,10 +86,27 @@ pub fn validateManifest(manifest: Manifest) ValidationError!void {
|
|
|
85
86
|
try validateFileAssociations(manifest.file_associations);
|
|
86
87
|
try validateUrlSchemes(manifest.url_schemes);
|
|
87
88
|
try validateCefConfig(manifest.package.web_engine, manifest.cef);
|
|
89
|
+
try validateWebViewLayer(manifest);
|
|
88
90
|
try validatePackageMetadata(manifest.package);
|
|
89
91
|
try validateUpdates(manifest.updates);
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
/// Whether the manifest declares web content — the shared declare-to-use
|
|
95
|
+
/// contract (web_layer.zig) over the typed manifest. Validation has no
|
|
96
|
+
/// engine flag, so the manifest's own engine is the resolved engine here;
|
|
97
|
+
/// flag-resolved engines are the build graph's and the CLI's inputs.
|
|
98
|
+
pub fn manifestDeclaresWebContent(manifest: Manifest) bool {
|
|
99
|
+
return web_layer.webDeclaration(manifest, manifest.package.web_engine) != null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// `.webview_layer = "exclude"` promises a native-only app; a manifest
|
|
103
|
+
/// that simultaneously declares web content contradicts itself, and the
|
|
104
|
+
/// contradiction is refused here — never resolved silently in either
|
|
105
|
+
/// direction.
|
|
106
|
+
pub fn validateWebViewLayer(manifest: Manifest) ValidationError!void {
|
|
107
|
+
_ = web_layer.decide(manifest.webview_layer, web_layer.webDeclaration(manifest, manifest.package.web_engine)) catch return error.WebViewLayerConflict;
|
|
108
|
+
}
|
|
109
|
+
|
|
92
110
|
pub fn validateIdentity(identity: AppIdentity) ValidationError!void {
|
|
93
111
|
try validateAppId(identity.id, .reverse_dns);
|
|
94
112
|
try validateName(identity.name);
|