@native-sdk/cli 0.9.2 → 0.9.3
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.zig +69 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/events.d.ts +7 -0
- package/packages/core/sdk/events.ts +26 -5
- package/packages/core/sdk/text.d.ts +4 -0
- package/packages/core/sdk/text.ts +51 -0
- package/packages/core/src/checker.ts +58 -1
- package/packages/core/src/contract.ts +5 -4
- package/packages/core/src/devhost_journal.mjs +2 -2
- package/packages/core/src/diagnostics.ts +2 -2
- package/packages/core/src/service_contract.ts +10 -0
- package/packages/core/src/typed_ast.ts +9 -7
- package/packages/core/src/types.ts +28 -8
- package/skill-data/automation/SKILL.md +4 -3
- package/skill-data/native-ui/SKILL.md +3 -1
- package/skill-data/ts-core/SKILL.md +7 -4
- package/src/app_runner/root.zig +208 -6
- package/src/app_runner/ts_core_main.zig +2 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +119 -0
- package/src/platform/macos/appkit_host.m +79 -12
- package/src/platform/macos/root.zig +68 -5
- package/src/primitives/canvas/events.zig +79 -1
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/text_interaction.zig +23 -0
- package/src/primitives/canvas/text_tests.zig +45 -0
- package/src/primitives/canvas/ui.zig +11 -8
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +3 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +18 -2
- package/src/primitives/canvas/ui_tests.zig +37 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +13 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/canvas_widget_control_tests.zig +2 -0
- package/src/runtime/canvas_widget_text_tests.zig +124 -0
- package/src/runtime/native_command_event_tests.zig +29 -0
- package/src/runtime/session_journal.zig +21 -2
- package/src/runtime/ts_ui_app.zig +164 -1
- package/src/runtime/ui_app.zig +91 -18
- package/src/runtime/ui_app_tests.zig +232 -13
- package/src/runtime/view_widget_text.zig +1 -1
- package/src/tooling/verbs.zig +1 -0
- package/tools/corewire/emit.zig +31 -12
- package/tools/corewire/emit_facade.zig +57 -2
- package/tools/corewire/shim_rt.zig +20 -0
package/src/runtime/ui_app.zig
CHANGED
|
@@ -281,6 +281,23 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
281
281
|
items: []const platform.TrayMenuItem = &.{},
|
|
282
282
|
};
|
|
283
283
|
|
|
284
|
+
/// The stock-theme axes a model may own without replacing the full
|
|
285
|
+
/// DesignTokens register. `system` follows the platform's live color
|
|
286
|
+
/// scheme; null pack/accent values inherit the manifest-backed
|
|
287
|
+
/// Options fields. Native chrome and WebViews remain OS-themed — this
|
|
288
|
+
/// state controls canvas tokens only.
|
|
289
|
+
pub const ThemeColorScheme = enum { system, light, dark };
|
|
290
|
+
|
|
291
|
+
pub const ThemeState = struct {
|
|
292
|
+
pack: ?canvas.ThemePack = null,
|
|
293
|
+
color_scheme: ThemeColorScheme = .system,
|
|
294
|
+
accent: ?canvas.Color = null,
|
|
295
|
+
/// Adapter-only invalid declaration marker. Zig cores already
|
|
296
|
+
/// pass a typed Color; the TS adapter retains malformed source
|
|
297
|
+
/// text here so rebuild rejects it instead of silently inheriting.
|
|
298
|
+
invalid_accent: ?[]const u8 = null,
|
|
299
|
+
};
|
|
300
|
+
|
|
284
301
|
/// One entry in the model-declared status-item collection.
|
|
285
302
|
/// `id` is stable identity; dropping the entry removes that
|
|
286
303
|
/// native status item, while every other field patches in place.
|
|
@@ -485,6 +502,11 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
485
502
|
/// `tokens_fn` still take precedence because those paths own
|
|
486
503
|
/// the complete token register.
|
|
487
504
|
theme_fn: ?*const fn (model: *const ModelT) canvas.ThemePack = null,
|
|
505
|
+
/// Cohesive model-derived stock-theme state: built-in pack,
|
|
506
|
+
/// canvas color scheme, and accent. This subsumes `theme_fn` and
|
|
507
|
+
/// is mutually exclusive with it. Explicit `tokens_fn`/`tokens`
|
|
508
|
+
/// still own the complete register and take precedence.
|
|
509
|
+
theme_state_fn: ?*const fn (model: *const ModelT) ThemeState = null,
|
|
488
510
|
/// The app's ONE-accent brand statement over the stock
|
|
489
511
|
/// tokens: when set (and the app claims neither `tokens`
|
|
490
512
|
/// nor `tokens_fn` — apps that own their tokens own their
|
|
@@ -962,6 +984,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
962
984
|
/// light/dark setting live. Test/null platforms never emit it,
|
|
963
985
|
/// so deterministic runs stay on the default light theme.
|
|
964
986
|
system_appearance: platform.Appearance = .{},
|
|
987
|
+
/// Last valid model-derived state. Re-derived before each rebuild;
|
|
988
|
+
/// equality is a handful of scalar/optional fields.
|
|
989
|
+
theme_state: ThemeState = .{},
|
|
990
|
+
theme_state_known: bool = false,
|
|
965
991
|
pixel_snap_scale: f32 = 1,
|
|
966
992
|
frame_timestamp_ns: u64 = 0,
|
|
967
993
|
markup_arenas: [2]std.heap.ArenaAllocator,
|
|
@@ -1397,6 +1423,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1397
1423
|
std.debug.assert((options.update != null) != (options.update_fx != null));
|
|
1398
1424
|
// Declared windows need the per-window view to build them.
|
|
1399
1425
|
std.debug.assert(options.windows_fn == null or options.window_view != null);
|
|
1426
|
+
std.debug.assert(options.theme_fn == null or options.theme_state_fn == null);
|
|
1400
1427
|
if (comptime !features.runtime_markup) std.debug.assert(options.markup == null);
|
|
1401
1428
|
}
|
|
1402
1429
|
|
|
@@ -1883,32 +1910,66 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1883
1910
|
tokens.pixel_snap.scale = self.pixel_snap_scale;
|
|
1884
1911
|
return tokens;
|
|
1885
1912
|
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1913
|
+
const state = self.currentThemeState();
|
|
1914
|
+
const color_scheme: canvas.ColorScheme = switch (state.color_scheme) {
|
|
1915
|
+
.system => switch (self.system_appearance.color_scheme) {
|
|
1888
1916
|
.light => .light,
|
|
1889
1917
|
.dark => .dark,
|
|
1890
1918
|
},
|
|
1919
|
+
.light => .light,
|
|
1920
|
+
.dark => .dark,
|
|
1921
|
+
};
|
|
1922
|
+
var tokens = canvas.DesignTokens.theme(.{
|
|
1923
|
+
.color_scheme = color_scheme,
|
|
1891
1924
|
.contrast = if (self.system_appearance.high_contrast) .high else .standard,
|
|
1892
1925
|
.reduce_motion = self.system_appearance.reduce_motion,
|
|
1893
|
-
.pack = if (self.options.theme_fn) |theme_fn| theme_fn(&self.model) else self.options.theme,
|
|
1926
|
+
.pack = state.pack orelse if (self.options.theme_fn) |theme_fn| theme_fn(&self.model) else self.options.theme,
|
|
1894
1927
|
});
|
|
1895
|
-
if (self.options.theme_accent) |accent| {
|
|
1928
|
+
if (state.accent orelse self.options.theme_accent) |accent| {
|
|
1896
1929
|
// The manifest accent layers over the resolved pack —
|
|
1897
1930
|
// except under high contrast, where the pack's own loud
|
|
1898
1931
|
// register wins untouched (accessibility beats brand).
|
|
1899
1932
|
// The bundle takes the resolved scheme: the dark ring
|
|
1900
1933
|
// derives desaturated (canvas.accentFocusRing).
|
|
1901
1934
|
if (!self.system_appearance.high_contrast) {
|
|
1902
|
-
tokens = tokens.withOverrides(canvas.accentOverrides(accent,
|
|
1903
|
-
.light => .light,
|
|
1904
|
-
.dark => .dark,
|
|
1905
|
-
}));
|
|
1935
|
+
tokens = tokens.withOverrides(canvas.accentOverrides(accent, color_scheme));
|
|
1906
1936
|
}
|
|
1907
1937
|
}
|
|
1908
1938
|
tokens.pixel_snap.scale = self.pixel_snap_scale;
|
|
1909
1939
|
return tokens;
|
|
1910
1940
|
}
|
|
1911
1941
|
|
|
1942
|
+
fn currentThemeState(self: *const Self) ThemeState {
|
|
1943
|
+
if (self.theme_state_known) return self.theme_state;
|
|
1944
|
+
return if (self.options.theme_state_fn) |theme_state_fn| theme_state_fn(&self.model) else .{};
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
/// Re-derive once per rebuild and reject malformed adapter input at
|
|
1948
|
+
/// the declaration boundary. A valid retained state contains no
|
|
1949
|
+
/// borrowed accent text, so it remains safe between dispatches.
|
|
1950
|
+
fn refreshThemeState(self: *Self) error{InvalidThemeAccent}!void {
|
|
1951
|
+
// Complete-token paths outrank the stock-theme helper entirely.
|
|
1952
|
+
// Do not even validate an unused model accent: the app has
|
|
1953
|
+
// explicitly claimed the whole DesignTokens register.
|
|
1954
|
+
if (self.options.tokens_fn != null or self.options.tokens != null) {
|
|
1955
|
+
self.theme_state = .{};
|
|
1956
|
+
self.theme_state_known = true;
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
const next = if (self.options.theme_state_fn) |theme_state_fn| theme_state_fn(&self.model) else ThemeState{};
|
|
1960
|
+
if (next.invalid_accent) |accent| {
|
|
1961
|
+
ui_app_log.warn(
|
|
1962
|
+
"themeState(model) returned accent '{s}'; expected exactly #rrggbb (six hexadecimal digits)",
|
|
1963
|
+
.{accent},
|
|
1964
|
+
);
|
|
1965
|
+
return error.InvalidThemeAccent;
|
|
1966
|
+
}
|
|
1967
|
+
if (!self.theme_state_known or !std.meta.eql(self.theme_state, next)) {
|
|
1968
|
+
self.theme_state = next;
|
|
1969
|
+
self.theme_state_known = true;
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1912
1973
|
/// The design tokens for a secondary window's rebuild: the same
|
|
1913
1974
|
/// app-owned appearance as `effectiveTokens`, restamped with the
|
|
1914
1975
|
/// SLOT's device scale. Each window snaps hairlines against its
|
|
@@ -1924,13 +1985,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1924
1985
|
/// true only when the app claims neither token override, so an
|
|
1925
1986
|
/// appearance flip must re-derive and re-render.
|
|
1926
1987
|
fn followsSystemAppearance(self: *const Self) bool {
|
|
1927
|
-
|
|
1988
|
+
if (self.options.tokens_fn != null or self.options.tokens != null) return false;
|
|
1989
|
+
if (self.options.theme_state_fn == null) return true;
|
|
1990
|
+
return self.currentThemeState().color_scheme == .system;
|
|
1928
1991
|
}
|
|
1929
1992
|
|
|
1930
1993
|
/// Whether tokens are derived per rebuild (model-owned or
|
|
1931
1994
|
/// system-followed) rather than a fixed set.
|
|
1932
1995
|
fn derivesTokens(self: *const Self) bool {
|
|
1933
|
-
return self.options.tokens_fn != null or self.followsSystemAppearance();
|
|
1996
|
+
return self.options.tokens_fn != null or self.options.theme_state_fn != null or self.followsSystemAppearance();
|
|
1934
1997
|
}
|
|
1935
1998
|
|
|
1936
1999
|
/// Whether a rebuild must push its tokens into the runtime's
|
|
@@ -1947,8 +2010,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1947
2010
|
/// pre-registration metrics). Ordinary rebuilds keep skipping
|
|
1948
2011
|
/// the redundant emission.
|
|
1949
2012
|
fn rebuildEmitsTokens(self: *const Self, runtime: *Runtime, window_id: platform.WindowId, canvas_label: []const u8, tokens: canvas.DesignTokens) bool {
|
|
1950
|
-
if (self.derivesTokens()) return true;
|
|
1951
2013
|
const stored = runtime.canvasWidgetDesignTokens(window_id, canvas_label) catch return true;
|
|
2014
|
+
if (self.derivesTokens()) return !std.meta.eql(stored, tokens);
|
|
1952
2015
|
if (!std.meta.eql(stored.text_measure, tokens.text_measure)) return true;
|
|
1953
2016
|
return stored.pixel_snap.scale != tokens.pixel_snap.scale;
|
|
1954
2017
|
}
|
|
@@ -1981,6 +2044,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1981
2044
|
/// for the next Msg.
|
|
1982
2045
|
pub fn rebuild(self: *Self, runtime: *Runtime, window_id: platform.WindowId) anyerror!void {
|
|
1983
2046
|
self.syncModel(runtime, window_id);
|
|
2047
|
+
try self.refreshThemeState();
|
|
1984
2048
|
if (comptime features.runtime_markup) {
|
|
1985
2049
|
// Under automation, drive the interpreter from the first
|
|
1986
2050
|
// frame even when a compiled view is present: provenance
|
|
@@ -2953,6 +3017,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2953
3017
|
|
|
2954
3018
|
fn rebuildWindowSlot(self: *Self, runtime: *Runtime, slot: *WindowSlot) anyerror!void {
|
|
2955
3019
|
if (self.options.window_view == null) return;
|
|
3020
|
+
try self.refreshThemeState();
|
|
2956
3021
|
var tokens = runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot));
|
|
2957
3022
|
const next_index = self.contextMenuRebuildIndex(slot.window_id, slot.arena_index);
|
|
2958
3023
|
const bounds = geometry.RectF.fromSize(slot.canvas_size).deflate(runtime.viewportInsetsForWindow(slot.window_id));
|
|
@@ -4249,7 +4314,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4249
4314
|
}
|
|
4250
4315
|
},
|
|
4251
4316
|
.appearance_changed => |appearance| {
|
|
4252
|
-
const
|
|
4317
|
+
const previous = self.system_appearance;
|
|
4253
4318
|
self.system_appearance = appearance;
|
|
4254
4319
|
if (self.options.on_appearance) |map| {
|
|
4255
4320
|
if (map(appearance)) |msg| {
|
|
@@ -4257,14 +4322,22 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4257
4322
|
return;
|
|
4258
4323
|
}
|
|
4259
4324
|
}
|
|
4260
|
-
// No app mapping consumed the change
|
|
4261
|
-
//
|
|
4262
|
-
//
|
|
4263
|
-
//
|
|
4264
|
-
// stored appearance alone is enough: the first build
|
|
4325
|
+
// No app mapping consumed the change. High contrast and
|
|
4326
|
+
// reduced motion remain live system axes even when the
|
|
4327
|
+
// model forces light/dark; only a scheme-only flip may
|
|
4328
|
+
// skip repaint while themeState is forced. Before install
|
|
4329
|
+
// the stored appearance alone is enough: the first build
|
|
4265
4330
|
// reads it.
|
|
4266
|
-
|
|
4331
|
+
const accessibility_changed =
|
|
4332
|
+
previous.high_contrast != appearance.high_contrast or
|
|
4333
|
+
previous.reduce_motion != appearance.reduce_motion;
|
|
4334
|
+
const followed_scheme_changed =
|
|
4335
|
+
previous.color_scheme != appearance.color_scheme and self.followsSystemAppearance();
|
|
4336
|
+
if (self.installed and self.options.tokens_fn == null and self.options.tokens == null and
|
|
4337
|
+
(accessibility_changed or followed_scheme_changed))
|
|
4338
|
+
{
|
|
4267
4339
|
try self.rebuild(runtime, self.canvas_window_id);
|
|
4340
|
+
try self.rebuildWindowSlots(runtime);
|
|
4268
4341
|
if (self.options.chrome == null) {
|
|
4269
4342
|
_ = try runtime.emitCanvasWidgetDisplayList(self.canvas_window_id, self.options.canvas_label, runtime.tokensWithTextMeasure(self.effectiveTokens()));
|
|
4270
4343
|
}
|
|
@@ -47,6 +47,18 @@ fn counterThemePack(model: *const CounterModel) canvas.ThemePack {
|
|
|
47
47
|
return if (model.count == 0) .house else .geist;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
fn counterThemeState(model: *const CounterModel) CounterApp.ThemeState {
|
|
51
|
+
return switch (model.count) {
|
|
52
|
+
0 => .{ .color_scheme = .dark },
|
|
53
|
+
1 => .{ .pack = .geist, .color_scheme = .system, .accent = canvas.Color.rgb8(0, 0x78, 0x6f) },
|
|
54
|
+
else => .{ .pack = .house, .color_scheme = .light, .accent = canvas.Color.rgb8(0xdf, 0x26, 0x70) },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fn invalidCounterThemeState(_: *const CounterModel) CounterApp.ThemeState {
|
|
59
|
+
return .{ .invalid_accent = "pink" };
|
|
60
|
+
}
|
|
61
|
+
|
|
50
62
|
const counter_views = [_]app_manifest.ShellView{
|
|
51
63
|
.{ .label = canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
|
|
52
64
|
};
|
|
@@ -1920,6 +1932,117 @@ test "model-derived theme packs retain live appearance, accent, and surface scal
|
|
|
1920
1932
|
try std.testing.expectEqual(@as(f32, 2), actual.pixel_snap.scale);
|
|
1921
1933
|
}
|
|
1922
1934
|
|
|
1935
|
+
test "model-derived theme state composes forced/system schemes and model accent over manifest defaults" {
|
|
1936
|
+
var options = counterOptions();
|
|
1937
|
+
options.theme = .house;
|
|
1938
|
+
options.theme_accent = canvas.Color.rgb8(0x12, 0x34, 0x56);
|
|
1939
|
+
options.theme_state_fn = counterThemeState;
|
|
1940
|
+
|
|
1941
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
1942
|
+
defer std.testing.allocator.destroy(app_state);
|
|
1943
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
|
|
1944
|
+
defer app_state.deinit();
|
|
1945
|
+
app_state.system_appearance = .{ .color_scheme = .light };
|
|
1946
|
+
app_state.pixel_snap_scale = 2;
|
|
1947
|
+
|
|
1948
|
+
// Model-forced dark wins over an OS-light appearance; omitted pack and
|
|
1949
|
+
// accent inherit the manifest-backed options.
|
|
1950
|
+
var expected = canvas.DesignTokens.theme(.{ .color_scheme = .dark, .pack = .house });
|
|
1951
|
+
expected = expected.withOverrides(canvas.accentOverrides(options.theme_accent.?, .dark));
|
|
1952
|
+
var actual = app_state.effectiveTokens();
|
|
1953
|
+
try std.testing.expectEqualDeep(expected.colors.background, actual.colors.background);
|
|
1954
|
+
try std.testing.expectEqualDeep(expected.colors.accent, actual.colors.accent);
|
|
1955
|
+
try std.testing.expectEqual(@as(f32, 2), actual.pixel_snap.scale);
|
|
1956
|
+
|
|
1957
|
+
// `system` resumes live OS following while model pack/accent override the
|
|
1958
|
+
// manifest values.
|
|
1959
|
+
app_state.model.count = 1;
|
|
1960
|
+
app_state.theme_state_known = false;
|
|
1961
|
+
app_state.system_appearance = .{ .color_scheme = .dark };
|
|
1962
|
+
const teal = canvas.Color.rgb8(0, 0x78, 0x6f);
|
|
1963
|
+
expected = canvas.DesignTokens.theme(.{ .color_scheme = .dark, .pack = .geist });
|
|
1964
|
+
expected = expected.withOverrides(canvas.accentOverrides(teal, .dark));
|
|
1965
|
+
actual = app_state.effectiveTokens();
|
|
1966
|
+
try std.testing.expectEqualDeep(expected.colors.background, actual.colors.background);
|
|
1967
|
+
try std.testing.expectEqualDeep(teal, actual.colors.accent);
|
|
1968
|
+
try std.testing.expectEqualDeep(canvas.accentFocusRing(teal, .dark), actual.colors.focus_ring);
|
|
1969
|
+
|
|
1970
|
+
// High contrast keeps the existing accessibility rule: neither the
|
|
1971
|
+
// model nor manifest accent layers over the pack's loud register.
|
|
1972
|
+
app_state.system_appearance.high_contrast = true;
|
|
1973
|
+
actual = app_state.effectiveTokens();
|
|
1974
|
+
const loud = canvas.DesignTokens.theme(.{ .color_scheme = .dark, .contrast = .high, .pack = .geist });
|
|
1975
|
+
try std.testing.expectEqualDeep(loud.colors.accent, actual.colors.accent);
|
|
1976
|
+
try std.testing.expect(!std.meta.eql(teal, actual.colors.accent));
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
test "malformed adapter theme accents reject the rebuild instead of inheriting silently" {
|
|
1980
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1981
|
+
defer harness.destroy(std.testing.allocator);
|
|
1982
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1983
|
+
var options = counterOptions();
|
|
1984
|
+
options.theme_state_fn = invalidCounterThemeState;
|
|
1985
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
1986
|
+
defer std.testing.allocator.destroy(app_state);
|
|
1987
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
|
|
1988
|
+
defer app_state.deinit();
|
|
1989
|
+
const app = app_state.app();
|
|
1990
|
+
try harness.start(app);
|
|
1991
|
+
try std.testing.expectError(error.InvalidThemeAccent, harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
1992
|
+
.label = canvas_label,
|
|
1993
|
+
.size = geometry.SizeF.init(400, 300),
|
|
1994
|
+
.scale_factor = 1,
|
|
1995
|
+
.frame_index = 1,
|
|
1996
|
+
.timestamp_ns = 1_000_000,
|
|
1997
|
+
.nonblank = true,
|
|
1998
|
+
} }));
|
|
1999
|
+
try std.testing.expect(!app_state.installed);
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
test "forced theme state still follows accessibility axes while scheme-only OS flips do not restyle" {
|
|
2003
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
2004
|
+
defer harness.destroy(std.testing.allocator);
|
|
2005
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2006
|
+
|
|
2007
|
+
var options = counterOptions();
|
|
2008
|
+
options.theme_state_fn = counterThemeState; // count 0 forces dark.
|
|
2009
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
2010
|
+
defer std.testing.allocator.destroy(app_state);
|
|
2011
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
|
|
2012
|
+
defer app_state.deinit();
|
|
2013
|
+
const app = app_state.app();
|
|
2014
|
+
try harness.start(app);
|
|
2015
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .appearance_changed = .{ .color_scheme = .light } });
|
|
2016
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
2017
|
+
.label = canvas_label,
|
|
2018
|
+
.size = geometry.SizeF.init(400, 300),
|
|
2019
|
+
.scale_factor = 1,
|
|
2020
|
+
.frame_index = 1,
|
|
2021
|
+
.timestamp_ns = 1_000_000,
|
|
2022
|
+
.nonblank = true,
|
|
2023
|
+
} });
|
|
2024
|
+
var stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
2025
|
+
const dark = canvas.DesignTokens.theme(.{ .color_scheme = .dark });
|
|
2026
|
+
try std.testing.expectEqualDeep(dark.colors.background, stored.colors.background);
|
|
2027
|
+
|
|
2028
|
+
// A scheme-only flip cannot override the forced state.
|
|
2029
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .appearance_changed = .{ .color_scheme = .dark } });
|
|
2030
|
+
stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
2031
|
+
try std.testing.expectEqualDeep(dark.colors.background, stored.colors.background);
|
|
2032
|
+
|
|
2033
|
+
// Accessibility axes remain live even under a forced color scheme.
|
|
2034
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .appearance_changed = .{
|
|
2035
|
+
.color_scheme = .light,
|
|
2036
|
+
.high_contrast = true,
|
|
2037
|
+
.reduce_motion = true,
|
|
2038
|
+
} });
|
|
2039
|
+
stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
2040
|
+
const dark_loud = canvas.DesignTokens.theme(.{ .color_scheme = .dark, .contrast = .high, .reduce_motion = true });
|
|
2041
|
+
try std.testing.expectEqualDeep(dark_loud.colors.background, stored.colors.background);
|
|
2042
|
+
try std.testing.expectEqualDeep(dark_loud.colors.focus_ring, stored.colors.focus_ring);
|
|
2043
|
+
try std.testing.expectEqual(@as(u32, 0), stored.motion.normal_ms);
|
|
2044
|
+
}
|
|
2045
|
+
|
|
1923
2046
|
test "static tokens carry the surface scale and re-snap on a scale change" {
|
|
1924
2047
|
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1925
2048
|
defer harness.destroy(std.testing.allocator);
|
|
@@ -3142,6 +3265,73 @@ test "automation composition and selection verbs keep the model mirror consisten
|
|
|
3142
3265
|
try std.testing.expectEqualStrings("", canceled_layout.findById(field_id).?.widget.text);
|
|
3143
3266
|
}
|
|
3144
3267
|
|
|
3268
|
+
test "macOS Command Backspace keeps the controlled TextBuffer mirror and history in lockstep" {
|
|
3269
|
+
if (comptime @import("builtin").os.tag != .macos) return error.SkipZigTest;
|
|
3270
|
+
|
|
3271
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
3272
|
+
defer harness.destroy(std.testing.allocator);
|
|
3273
|
+
harness.null_platform.gpu_surfaces = true;
|
|
3274
|
+
|
|
3275
|
+
const app_state = try std.testing.allocator.create(SearchMirrorApp);
|
|
3276
|
+
defer std.testing.allocator.destroy(app_state);
|
|
3277
|
+
try startSearchMirror(harness, app_state);
|
|
3278
|
+
defer app_state.deinit();
|
|
3279
|
+
const app = app_state.app();
|
|
3280
|
+
const field_id = findWidgetIdByKind(app_state.tree.?.root, .search_field).?;
|
|
3281
|
+
|
|
3282
|
+
try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
|
|
3283
|
+
.view_label = search_mirror_canvas_label,
|
|
3284
|
+
.id = field_id,
|
|
3285
|
+
.action = .set_text,
|
|
3286
|
+
.value = "second line",
|
|
3287
|
+
});
|
|
3288
|
+
for (0..5) |_| {
|
|
3289
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3290
|
+
.window_id = 1,
|
|
3291
|
+
.label = search_mirror_canvas_label,
|
|
3292
|
+
.kind = .key_down,
|
|
3293
|
+
.key = "arrowleft",
|
|
3294
|
+
} });
|
|
3295
|
+
}
|
|
3296
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(6), app_state.model.query.selection);
|
|
3297
|
+
|
|
3298
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3299
|
+
.window_id = 1,
|
|
3300
|
+
.label = search_mirror_canvas_label,
|
|
3301
|
+
.kind = .key_down,
|
|
3302
|
+
.key = "backspace",
|
|
3303
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
3304
|
+
} });
|
|
3305
|
+
try std.testing.expectEqualStrings(" line", app_state.model.query.text());
|
|
3306
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), app_state.model.query.selection);
|
|
3307
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
|
|
3308
|
+
try std.testing.expectEqualStrings(app_state.model.query.text(), retained.findById(field_id).?.widget.text);
|
|
3309
|
+
try std.testing.expectEqualDeep(app_state.model.query.selection, retained.findById(field_id).?.widget.text_selection.?);
|
|
3310
|
+
|
|
3311
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3312
|
+
.window_id = 1,
|
|
3313
|
+
.label = search_mirror_canvas_label,
|
|
3314
|
+
.kind = .key_down,
|
|
3315
|
+
.key = "z",
|
|
3316
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
3317
|
+
} });
|
|
3318
|
+
try std.testing.expectEqualStrings("second line", app_state.model.query.text());
|
|
3319
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(6), app_state.model.query.selection);
|
|
3320
|
+
|
|
3321
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3322
|
+
.window_id = 1,
|
|
3323
|
+
.label = search_mirror_canvas_label,
|
|
3324
|
+
.kind = .key_down,
|
|
3325
|
+
.key = "z",
|
|
3326
|
+
.modifiers = .{ .primary = true, .command = true, .shift = true },
|
|
3327
|
+
} });
|
|
3328
|
+
try std.testing.expectEqualStrings(" line", app_state.model.query.text());
|
|
3329
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), app_state.model.query.selection);
|
|
3330
|
+
retained = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
|
|
3331
|
+
try std.testing.expectEqualStrings(app_state.model.query.text(), retained.findById(field_id).?.widget.text);
|
|
3332
|
+
try std.testing.expectEqualDeep(app_state.model.query.selection, retained.findById(field_id).?.widget.text_selection.?);
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3145
3335
|
// --------------------------------- combobox open-arrow (mirror invariant)
|
|
3146
3336
|
|
|
3147
3337
|
const combo_mirror_canvas_label = "combo-mirror-canvas";
|
|
@@ -3151,12 +3341,16 @@ const ComboMirrorModel = struct {
|
|
|
3151
3341
|
note: canvas.TextBuffer(64) = .{},
|
|
3152
3342
|
open: bool = false,
|
|
3153
3343
|
opens: u32 = 0,
|
|
3344
|
+
submits: u32 = 0,
|
|
3345
|
+
picks: u32 = 0,
|
|
3154
3346
|
query_edits: u32 = 0,
|
|
3155
3347
|
};
|
|
3156
3348
|
|
|
3157
3349
|
const ComboMirrorMsg = union(enum) {
|
|
3158
3350
|
open_picker,
|
|
3159
3351
|
close_picker,
|
|
3352
|
+
submit_query,
|
|
3353
|
+
pick_query: []const u8,
|
|
3160
3354
|
query_edit: canvas.TextInputEvent,
|
|
3161
3355
|
note_edit: canvas.TextInputEvent,
|
|
3162
3356
|
};
|
|
@@ -3170,6 +3364,16 @@ fn comboMirrorUpdate(model: *ComboMirrorModel, msg: ComboMirrorMsg) void {
|
|
|
3170
3364
|
model.opens += 1;
|
|
3171
3365
|
},
|
|
3172
3366
|
.close_picker => model.open = false,
|
|
3367
|
+
.submit_query => {
|
|
3368
|
+
model.open = false;
|
|
3369
|
+
model.submits += 1;
|
|
3370
|
+
},
|
|
3371
|
+
.pick_query => |query| {
|
|
3372
|
+
model.query.clear();
|
|
3373
|
+
model.query.apply(.{ .insert_text = query });
|
|
3374
|
+
model.open = false;
|
|
3375
|
+
model.picks += 1;
|
|
3376
|
+
},
|
|
3173
3377
|
.query_edit => |edit| {
|
|
3174
3378
|
model.query.apply(edit);
|
|
3175
3379
|
model.query_edits += 1;
|
|
@@ -3185,6 +3389,7 @@ fn comboMirrorView(ui: *ComboMirrorApp.Ui, model: *const ComboMirrorModel) Combo
|
|
|
3185
3389
|
.width = 200,
|
|
3186
3390
|
.expanded = model.open,
|
|
3187
3391
|
.on_press = .open_picker,
|
|
3392
|
+
.on_submit = .submit_query,
|
|
3188
3393
|
.on_input = ComboMirrorApp.Ui.inputMsg(.query_edit),
|
|
3189
3394
|
}, .{});
|
|
3190
3395
|
const picker = if (model.open) ui.stack(.{ .height = 28 }, .{
|
|
@@ -3196,8 +3401,8 @@ fn comboMirrorView(ui: *ComboMirrorApp.Ui, model: *const ComboMirrorModel) Combo
|
|
|
3196
3401
|
.height = 60,
|
|
3197
3402
|
.on_dismiss = .close_picker,
|
|
3198
3403
|
}, .{
|
|
3199
|
-
ui.el(.menu_item, .{ .key = .{ .int = 0 }, .text = "glass bead", .height = 26, .on_press = .
|
|
3200
|
-
ui.el(.menu_item, .{ .key = .{ .int = 1 }, .text = "glass jar", .height = 26, .on_press = .
|
|
3404
|
+
ui.el(.menu_item, .{ .key = .{ .int = 0 }, .text = "glass bead", .height = 26, .on_press = ComboMirrorMsg{ .pick_query = "glass bead" } }, .{}),
|
|
3405
|
+
ui.el(.menu_item, .{ .key = .{ .int = 1 }, .text = "glass jar", .height = 26, .on_press = ComboMirrorMsg{ .pick_query = "glass jar" } }, .{}),
|
|
3201
3406
|
}),
|
|
3202
3407
|
}) else ui.stack(.{ .height = 28 }, .{trigger});
|
|
3203
3408
|
return ui.column(.{ .gap = 8, .padding = 12 }, .{
|
|
@@ -3237,7 +3442,7 @@ fn comboMirrorRetainedSelection(harness: *core.TestHarness(), id: canvas.ObjectI
|
|
|
3237
3442
|
return layout.findById(id).?.widget.text_selection;
|
|
3238
3443
|
}
|
|
3239
3444
|
|
|
3240
|
-
test "
|
|
3445
|
+
test "combobox submit precedence and open-menu selection keep the text mirror consistent" {
|
|
3241
3446
|
// The split-brain escapee: a CLOSED combobox maps ArrowUp/Down to
|
|
3242
3447
|
// BOTH its open press (`widgetKeyboardControlIntent`'s menu-open
|
|
3243
3448
|
// keys) and — through the single-line caret derivation — a stamped
|
|
@@ -3292,6 +3497,19 @@ test "a closed combobox's open arrows move neither the retained caret nor the mo
|
|
|
3292
3497
|
try std.testing.expectEqualStrings("glass", app_state.model.query.text());
|
|
3293
3498
|
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
3294
3499
|
|
|
3500
|
+
// Enter resolves through on_submit BEFORE the trigger's open press.
|
|
3501
|
+
// The closed picker stays closed and neither side of the text mirror
|
|
3502
|
+
// changes while the submit message commits.
|
|
3503
|
+
const edits_before_submit = app_state.model.query_edits;
|
|
3504
|
+
try comboMirrorKey(harness, app, "enter");
|
|
3505
|
+
try std.testing.expect(!app_state.model.open);
|
|
3506
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.model.opens);
|
|
3507
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.model.submits);
|
|
3508
|
+
try std.testing.expectEqual(edits_before_submit, app_state.model.query_edits);
|
|
3509
|
+
try std.testing.expectEqualStrings("glass", app_state.model.query.text());
|
|
3510
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
3511
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
|
|
3512
|
+
|
|
3295
3513
|
// THE pin: ArrowDown on the closed trigger opens the picker and
|
|
3296
3514
|
// both carets stay at 3 — no query edit is heard or applied.
|
|
3297
3515
|
const edits_before_open = app_state.model.query_edits;
|
|
@@ -3302,9 +3520,10 @@ test "a closed combobox's open arrows move neither the retained caret nor the mo
|
|
|
3302
3520
|
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
3303
3521
|
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
|
|
3304
3522
|
|
|
3305
|
-
// The OPEN-picker truth
|
|
3306
|
-
//
|
|
3307
|
-
//
|
|
3523
|
+
// The OPEN-picker truth: the next arrow walks the keyboard INTO the
|
|
3524
|
+
// mounted menu (the focus step consumes it before routing reaches
|
|
3525
|
+
// the trigger), so Enter selects that menu item instead of reaching
|
|
3526
|
+
// the combobox submit handler again.
|
|
3308
3527
|
const first_item_id = findWidgetIdByText(app_state.tree.?, .menu_item, "glass bead").?;
|
|
3309
3528
|
try comboMirrorKey(harness, app, "arrowdown");
|
|
3310
3529
|
try std.testing.expectEqual(first_item_id, harness.runtime.views[0].canvas_widget_focused_id);
|
|
@@ -3312,12 +3531,12 @@ test "a closed combobox's open arrows move neither the retained caret nor the mo
|
|
|
3312
3531
|
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
3313
3532
|
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
|
|
3314
3533
|
|
|
3315
|
-
|
|
3316
|
-
// the picker closes through `on_dismiss` and the combobox's
|
|
3317
|
-
// Escape-clear never runs — the query survives.
|
|
3318
|
-
try comboMirrorKey(harness, app, "escape");
|
|
3534
|
+
try comboMirrorKey(harness, app, "enter");
|
|
3319
3535
|
try std.testing.expect(!app_state.model.open);
|
|
3320
|
-
try std.testing.
|
|
3536
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.model.submits);
|
|
3537
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.model.picks);
|
|
3538
|
+
try std.testing.expectEqualStrings("glass bead", app_state.model.query.text());
|
|
3539
|
+
try std.testing.expectEqualStrings("glass bead", (try harness.runtime.canvasWidgetLayout(1, combo_mirror_canvas_label)).findById(combo_id).?.widget.text);
|
|
3321
3540
|
try std.testing.expectEqual(combo_id, harness.runtime.views[0].canvas_widget_focused_id);
|
|
3322
3541
|
|
|
3323
3542
|
// ArrowUp on the closed trigger is the same open key: opens, and
|
|
@@ -3326,8 +3545,8 @@ test "a closed combobox's open arrows move neither the retained caret nor the mo
|
|
|
3326
3545
|
try std.testing.expect(app_state.model.open);
|
|
3327
3546
|
try std.testing.expectEqual(@as(u32, 2), app_state.model.opens);
|
|
3328
3547
|
try std.testing.expectEqual(edits_before_open, app_state.model.query_edits);
|
|
3329
|
-
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(
|
|
3330
|
-
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(
|
|
3548
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed("glass bead".len), app_state.model.query.selection);
|
|
3549
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed("glass bead".len)), try comboMirrorRetainedSelection(harness, combo_id));
|
|
3331
3550
|
try comboMirrorKey(harness, app, "escape");
|
|
3332
3551
|
try std.testing.expect(!app_state.model.open);
|
|
3333
3552
|
|
|
@@ -412,7 +412,7 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
|
|
|
412
412
|
if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown")) return .{ .move_caret = .{ .direction = .end, .extend = keyboard.modifiers.shift } };
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
-
return
|
|
415
|
+
return canvas.widgetKeyboardTextEditEventForWidget(widget, keyboard);
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
/// Resolve Command/Ctrl+Z against the focused editor's delta
|
package/src/tooling/verbs.zig
CHANGED
|
@@ -254,6 +254,7 @@ fn runZig(io: std.Io, verb: Verb, argv: []const []const u8) !void {
|
|
|
254
254
|
// SDK builds with Zig 0.16, where std APIs moved, and those failures
|
|
255
255
|
// read "no member named 'cwd'/'init'/'io'" on std types.
|
|
256
256
|
std.debug.print("if the errors above name missing std members, the code may use pre-0.16 Zig idioms - run `native skills get zig` or see https://native-sdk.dev/zig\n", .{});
|
|
257
|
+
std.debug.print("if generated core wiring exceeds Zig's eval branch quota, do not regenerate the TypeScript contract or add an app-side quota - update or report the SDK-generated scan\n", .{});
|
|
257
258
|
return error.ZigBuildFailed;
|
|
258
259
|
}
|
|
259
260
|
|