@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,86 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const platform = @import("../platform/root.zig");
|
|
3
|
+
const global_shortcuts = @import("global_shortcuts.zig");
|
|
4
|
+
|
|
5
|
+
pub const send_chord_name = "native-sdk.keyboard.sendChord";
|
|
6
|
+
pub const access_status_name = "native-sdk.keyboard.accessStatus";
|
|
7
|
+
|
|
8
|
+
pub const Binding = struct {
|
|
9
|
+
context: *anyopaque,
|
|
10
|
+
send_key_chord_fn: *const fn (context: *anyopaque, chord: platform.KeyChord) anyerror!void,
|
|
11
|
+
access_fn: *const fn (context: *anyopaque, prompt: bool) anyerror!platform.KeyboardInputAccess,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
pub const Result = struct {
|
|
15
|
+
ok: bool,
|
|
16
|
+
bytes: []const u8,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
pub const max_chord_payload_bytes: usize = 4 + platform.max_shortcut_key_bytes + 8;
|
|
20
|
+
|
|
21
|
+
const modifier_count = std.meta.fields(platform.ShortcutModifiers).len;
|
|
22
|
+
|
|
23
|
+
pub fn isRequestName(name: []const u8) bool {
|
|
24
|
+
return std.mem.eql(u8, name, send_chord_name) or
|
|
25
|
+
std.mem.eql(u8, name, access_status_name);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pub fn encodeChord(buffer: *[max_chord_payload_bytes]u8, chord: platform.KeyChord) []const u8 {
|
|
29
|
+
const name = chord.key();
|
|
30
|
+
std.mem.writeInt(u32, buffer[0..4], @intCast(name.len), .little);
|
|
31
|
+
@memcpy(buffer[4..][0..name.len], name);
|
|
32
|
+
const bits: f64 = @floatFromInt(global_shortcuts.modifierMask(chord.modifiers));
|
|
33
|
+
std.mem.writeInt(u64, buffer[4 + name.len ..][0..8], @bitCast(bits), .little);
|
|
34
|
+
return buffer[0 .. 4 + name.len + 8];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
pub fn decodeChord(payload: []const u8) ?platform.KeyChord {
|
|
38
|
+
if (payload.len < 4) return null;
|
|
39
|
+
const name_len: usize = std.mem.readInt(u32, payload[0..4], .little);
|
|
40
|
+
if (name_len > payload.len - 4 or payload.len - 4 - name_len != 8) return null;
|
|
41
|
+
const bits: f64 = @bitCast(std.mem.readInt(u64, payload[4 + name_len ..][0..8], .little));
|
|
42
|
+
if (!(bits >= 0 and bits < 1 << modifier_count) or bits != @floor(bits)) return null;
|
|
43
|
+
return platform.KeyChord.init(payload[4..][0..name_len], global_shortcuts.modifiersFromMask(@intFromFloat(bits)));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub fn execute(binding: Binding, name: []const u8, payload: []const u8) Result {
|
|
47
|
+
if (std.mem.eql(u8, name, send_chord_name)) {
|
|
48
|
+
const chord = decodeChord(payload) orelse return .{ .ok = false, .bytes = "invalid_request" };
|
|
49
|
+
binding.send_key_chord_fn(binding.context, chord) catch |err| return .{ .ok = false, .bytes = reasonName(err) };
|
|
50
|
+
return .{ .ok = true, .bytes = "" };
|
|
51
|
+
}
|
|
52
|
+
if (payload.len != 1 or payload[0] > 1) return .{ .ok = false, .bytes = "invalid_request" };
|
|
53
|
+
const access = binding.access_fn(binding.context, payload[0] == 1) catch |err| return .{ .ok = false, .bytes = reasonName(err) };
|
|
54
|
+
return .{ .ok = true, .bytes = @tagName(access) };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fn reasonName(err: anyerror) []const u8 {
|
|
58
|
+
return switch (err) {
|
|
59
|
+
error.PermissionDenied => "rejected",
|
|
60
|
+
error.UnsupportedService => "unsupported",
|
|
61
|
+
error.KeyboardInputAccessDenied => "denied",
|
|
62
|
+
error.KeyboardInputBlocked => "blocked",
|
|
63
|
+
else => "failed",
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
test "chord payloads round-trip every modifier and reject malformed bytes" {
|
|
68
|
+
var buffer: [max_chord_payload_bytes]u8 = undefined;
|
|
69
|
+
for (0..1 << modifier_count) |mask| {
|
|
70
|
+
const chord = platform.KeyChord.init("enter", global_shortcuts.modifiersFromMask(@intCast(mask))).?;
|
|
71
|
+
try std.testing.expectEqual(chord, decodeChord(encodeChord(&buffer, chord)).?);
|
|
72
|
+
}
|
|
73
|
+
const valid = encodeChord(&buffer, platform.KeyChord.init("v", .{}).?);
|
|
74
|
+
var bad: [max_chord_payload_bytes + 1]u8 = undefined;
|
|
75
|
+
@memcpy(bad[0..valid.len], valid);
|
|
76
|
+
bad[valid.len] = 0;
|
|
77
|
+
try std.testing.expectEqual(@as(?platform.KeyChord, null), decodeChord(valid[0..3]));
|
|
78
|
+
try std.testing.expectEqual(@as(?platform.KeyChord, null), decodeChord(bad[0 .. valid.len + 1]));
|
|
79
|
+
for ([_]f64{ 32, 0.5, -1, std.math.nan(f64), std.math.inf(f64) }) |bits| {
|
|
80
|
+
std.mem.writeInt(u64, bad[5..13], @bitCast(bits), .little);
|
|
81
|
+
try std.testing.expectEqual(@as(?platform.KeyChord, null), decodeChord(bad[0..valid.len]));
|
|
82
|
+
}
|
|
83
|
+
std.mem.writeInt(u64, bad[5..13], 0, .little);
|
|
84
|
+
bad[4] = '!';
|
|
85
|
+
try std.testing.expectEqual(@as(?platform.KeyChord, null), decodeChord(bad[0..valid.len]));
|
|
86
|
+
}
|
package/src/runtime/root.zig
CHANGED
|
@@ -150,6 +150,8 @@ pub const EffectChannelEventKind = runtime_effects.EffectChannelEventKind;
|
|
|
150
150
|
pub const EffectAudioCaptureEvent = runtime_effects.EffectAudioCaptureEvent;
|
|
151
151
|
pub const EffectAudioCaptureEventKind = runtime_effects.EffectAudioCaptureEventKind;
|
|
152
152
|
pub const decodeAudioCaptureChannelEvent = runtime_effects.decodeAudioCaptureChannelEvent;
|
|
153
|
+
pub const EffectGlobalShortcutEvent = runtime_effects.EffectGlobalShortcutEvent;
|
|
154
|
+
pub const EffectGlobalShortcutEventKind = runtime_effects.EffectGlobalShortcutEventKind;
|
|
153
155
|
pub const HostChannelSourceBinding = runtime_effects.HostChannelSourceBinding;
|
|
154
156
|
pub const EffectChannelSourceState = runtime_effects.EffectChannelSourceState;
|
|
155
157
|
pub const EffectChannelSourceResult = runtime_effects.EffectChannelSourceResult;
|
|
@@ -198,6 +200,7 @@ pub const ts_core_db_key_base = runtime_ts_core_host.db_key_base;
|
|
|
198
200
|
pub const ts_core_file_stream_key_base = runtime_ts_core_host.file_stream_key_base;
|
|
199
201
|
|
|
200
202
|
const runtime_ts_ui_app = @import("ts_ui_app.zig");
|
|
203
|
+
pub const view_reload = @import("view_reload.zig");
|
|
201
204
|
pub const TsUiApp = runtime_ts_ui_app.TsUiApp;
|
|
202
205
|
pub const TsUiAppWithFeatures = runtime_ts_ui_app.TsUiAppWithFeatures;
|
|
203
206
|
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//! Copied scroll capability programs. All state, identities, f32 numeric
|
|
2
|
+
//! operations and geometry remain native-owned; compiled code orders them.
|
|
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 Mode = enum(u8) { axis, textarea, driver, keyboard, kinetic, finish };
|
|
8
|
+
pub const Kind = enum(u8) {
|
|
9
|
+
viewport,
|
|
10
|
+
textarea_viewport,
|
|
11
|
+
region_state,
|
|
12
|
+
textarea_state,
|
|
13
|
+
delegate_textarea,
|
|
14
|
+
wheel,
|
|
15
|
+
wheel_clamped,
|
|
16
|
+
discrete,
|
|
17
|
+
zero_velocity,
|
|
18
|
+
store_axis,
|
|
19
|
+
compare_axis,
|
|
20
|
+
write_axis,
|
|
21
|
+
translate_axis,
|
|
22
|
+
event,
|
|
23
|
+
semantics,
|
|
24
|
+
revision,
|
|
25
|
+
dirty,
|
|
26
|
+
driver_y,
|
|
27
|
+
driver_x,
|
|
28
|
+
target_y,
|
|
29
|
+
target_x,
|
|
30
|
+
store_state,
|
|
31
|
+
write_both,
|
|
32
|
+
translate_both,
|
|
33
|
+
clear_velocities,
|
|
34
|
+
probe_y,
|
|
35
|
+
probe_x,
|
|
36
|
+
kinetic_y,
|
|
37
|
+
kinetic_x,
|
|
38
|
+
zero_y,
|
|
39
|
+
zero_x,
|
|
40
|
+
accumulate_dirty,
|
|
41
|
+
};
|
|
42
|
+
pub fn nodeFacts(node: canvas.WidgetLayoutNode) u8 {
|
|
43
|
+
var facts: u8 = 1;
|
|
44
|
+
if (node.widget.kind == .scroll_view) facts |= 2;
|
|
45
|
+
if (node.widget.kind == .textarea) facts |= 4;
|
|
46
|
+
if (node.widget.layout.virtualized and !canvas.widgetVirtualRuntimeScrolled(node.widget)) facts |= 8;
|
|
47
|
+
if (canvas.widgetScrollsAxis(node.widget, .vertical)) facts |= 16;
|
|
48
|
+
if (canvas.widgetScrollsAxis(node.widget, .horizontal)) facts |= 32;
|
|
49
|
+
if (node.widget.runtime_flags.native_scroll) facts |= 64;
|
|
50
|
+
return facts;
|
|
51
|
+
}
|
|
52
|
+
pub const Selection = struct {
|
|
53
|
+
include: [limits.max_canvas_widget_nodes_per_view]bool = undefined,
|
|
54
|
+
};
|
|
55
|
+
pub fn kineticSelection(policy: Policy, nodes: []const canvas.WidgetLayoutNode) Selection {
|
|
56
|
+
comptime {
|
|
57
|
+
if (limits.max_canvas_widget_nodes_per_view != 1024) @compileError("update kinetic selection wire budget");
|
|
58
|
+
}
|
|
59
|
+
if (nodes.len > limits.max_canvas_widget_nodes_per_view) @panic("kinetic selection exceeds node budget");
|
|
60
|
+
var input: [16 + limits.max_canvas_widget_nodes_per_view]u8 = @splat(0);
|
|
61
|
+
input[0] = 101;
|
|
62
|
+
input[1] = 6;
|
|
63
|
+
std.mem.writeInt(u32, input[8..12], @intCast(nodes.len), .little);
|
|
64
|
+
for (nodes, 0..) |node, i| input[16 + i] = nodeFacts(node);
|
|
65
|
+
var output: [8 + limits.max_canvas_widget_nodes_per_view]u8 = undefined;
|
|
66
|
+
if (policy(input[0 .. 16 + nodes.len], &output) != 8 + nodes.len or output[0] != 101 or output[1] != 6 or
|
|
67
|
+
output[2] != 0 or output[3] != 0 or std.mem.readInt(u32, output[4..8], .little) != nodes.len)
|
|
68
|
+
@panic("invalid kinetic selection header");
|
|
69
|
+
var result: Selection = undefined;
|
|
70
|
+
for (result.include[0..nodes.len], 0..) |*include, i| {
|
|
71
|
+
if (output[8 + i] > 1) @panic("invalid kinetic selection capability");
|
|
72
|
+
include.* = output[8 + i] == 1;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
pub const Program = struct {
|
|
77
|
+
bytes: [24]u8,
|
|
78
|
+
count: usize,
|
|
79
|
+
next: u8,
|
|
80
|
+
pub fn instruction(self: *const Program, index: usize) Kind {
|
|
81
|
+
std.debug.assert(index < self.count);
|
|
82
|
+
return @enumFromInt(self.bytes[8 + index]);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
pub fn plan(policy: Policy, mode: Mode, phase: u8, source: u8, vertical: bool, facts: u32) Program {
|
|
86
|
+
var input: [16]u8 = @splat(0);
|
|
87
|
+
input[0..5].* = .{ 101, @intFromEnum(mode), phase, source, @intFromBool(vertical) };
|
|
88
|
+
std.mem.writeInt(u32, input[8..12], facts, .little);
|
|
89
|
+
var result: Program = undefined;
|
|
90
|
+
const size = policy(&input, &result.bytes);
|
|
91
|
+
if (size < 8 or size > result.bytes.len or result.bytes[0] != 101 or result.bytes[1] != @intFromEnum(mode) or
|
|
92
|
+
std.mem.readInt(u32, result.bytes[4..8], .little) != 0)
|
|
93
|
+
@panic("invalid scroll mutation program header");
|
|
94
|
+
result.count = result.bytes[3];
|
|
95
|
+
result.next = result.bytes[2];
|
|
96
|
+
if (size != 8 + result.count or (result.next != 255 and (result.next != phase + 1 or result.next > (if (mode == .kinetic) @as(u8, 4) else 2))) or
|
|
97
|
+
(mode == .finish and result.next != 255)) @panic("invalid scroll mutation program progress");
|
|
98
|
+
if (mode != .finish and ((facts & 1 == 0 and result.count != 0) or
|
|
99
|
+
(phase > 1 and facts & 256 == 0 and result.count != 0))) @panic("invalid scroll mutation storage admission");
|
|
100
|
+
for (result.bytes[8..size]) |kind| {
|
|
101
|
+
if (kind > @intFromEnum(Kind.accumulate_dirty)) @panic("invalid scroll mutation capability");
|
|
102
|
+
const capability: Kind = @enumFromInt(kind);
|
|
103
|
+
// Capability admission, independent of the program's semantic choices.
|
|
104
|
+
const allowed = switch (capability) {
|
|
105
|
+
.viewport => phase == 0 and mode != .textarea and mode != .finish,
|
|
106
|
+
.textarea_viewport => phase == 0 and mode == .textarea,
|
|
107
|
+
.delegate_textarea => phase == 0 and mode == .axis,
|
|
108
|
+
.region_state => phase == 1 and mode != .textarea and mode != .finish,
|
|
109
|
+
.textarea_state, .compare_axis => phase == 1 and mode == .textarea,
|
|
110
|
+
.wheel, .wheel_clamped, .discrete => phase == 1 and (mode == .axis or mode == .textarea),
|
|
111
|
+
.zero_velocity, .store_axis => phase == 1 and mode == .axis,
|
|
112
|
+
.driver_y, .driver_x => phase == 1 and mode == .driver,
|
|
113
|
+
.target_y, .target_x => phase == 1 and mode == .keyboard,
|
|
114
|
+
.store_state => (phase == 1 and (mode == .driver or mode == .keyboard)) or (phase == 3 and mode == .kinetic),
|
|
115
|
+
.clear_velocities => phase == 1 and mode == .kinetic,
|
|
116
|
+
.probe_y => phase == 1 and mode == .kinetic,
|
|
117
|
+
.probe_x, .kinetic_y, .zero_y => phase == 2 and mode == .kinetic,
|
|
118
|
+
.kinetic_x, .zero_x => phase == 3 and mode == .kinetic,
|
|
119
|
+
.semantics, .revision => (phase == 2 and mode != .kinetic and mode != .finish) or (phase == 0 and mode == .finish),
|
|
120
|
+
.write_axis => phase == 2 and (mode == .axis or mode == .textarea),
|
|
121
|
+
.translate_axis => phase == 2 and mode == .axis,
|
|
122
|
+
.dirty => phase == 2 and mode != .kinetic and mode != .finish,
|
|
123
|
+
.event => (phase == 2 and (mode == .axis or mode == .driver or mode == .keyboard)) or (phase == 4 and mode == .kinetic),
|
|
124
|
+
.write_both, .translate_both => (phase == 2 and (mode == .driver or mode == .keyboard)) or (phase == 4 and mode == .kinetic),
|
|
125
|
+
.accumulate_dirty => phase == 4 and mode == .kinetic,
|
|
126
|
+
};
|
|
127
|
+
if (!allowed) @panic("invalid scroll mutation capability admission");
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
//! Storage, numeric and geometry capabilities for compiled scroll programs.
|
|
2
|
+
const canvas = @import("canvas");
|
|
3
|
+
const geometry = @import("geometry");
|
|
4
|
+
const programs = @import("scroll_mutation_policy.zig");
|
|
5
|
+
|
|
6
|
+
pub const Outcome = struct { dirty: ?geometry.RectF = null, changed: bool = false };
|
|
7
|
+
|
|
8
|
+
pub fn run(self: anytype, policy: programs.Policy, comptime mode: programs.Mode, index: usize, comptime axis: canvas.ScrollAxis, source: u8, delta: f32, offset_x: f32, offset_y: f32, allow_rubberband: bool) anyerror!Outcome {
|
|
9
|
+
var facts: u32 = if (allow_rubberband) 128 else 0;
|
|
10
|
+
var node: canvas.WidgetLayoutNode = undefined;
|
|
11
|
+
if (index < self.widget_layout_node_count) {
|
|
12
|
+
node = self.widget_layout_nodes[index];
|
|
13
|
+
facts |= programs.nodeFacts(node);
|
|
14
|
+
}
|
|
15
|
+
var viewport: geometry.RectF = undefined;
|
|
16
|
+
var current: canvas.ScrollState = undefined;
|
|
17
|
+
var next: canvas.ScrollState = undefined;
|
|
18
|
+
var current_axis: canvas.ScrollAxisState = undefined;
|
|
19
|
+
var next_axis: canvas.ScrollAxisState = undefined;
|
|
20
|
+
var physics: canvas.ScrollPhysics = undefined;
|
|
21
|
+
var moved = geometry.OffsetF{};
|
|
22
|
+
var dirty: ?geometry.RectF = null;
|
|
23
|
+
var phase: u8 = 0;
|
|
24
|
+
while (true) {
|
|
25
|
+
const program = programs.plan(policy, mode, phase, source, axis == .vertical, facts);
|
|
26
|
+
for (0..program.count) |i| switch (program.instruction(i)) {
|
|
27
|
+
.viewport => {
|
|
28
|
+
viewport = node.frame.inset(node.widget.layout.padding).normalized();
|
|
29
|
+
if (!viewport.isEmpty()) facts |= 256;
|
|
30
|
+
},
|
|
31
|
+
.textarea_viewport => {
|
|
32
|
+
if (canvas.textInputViewportForWidget(node.widget, self.widget_tokens)) |value| {
|
|
33
|
+
viewport = value;
|
|
34
|
+
facts |= 256;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
.region_state => {
|
|
38
|
+
if (mode == .kinetic) physics = canvas.widgetScrollPhysics(node.widget, self.widget_tokens.scroll);
|
|
39
|
+
current = self.canvasWidgetScrollState(index, node, viewport);
|
|
40
|
+
if (mode == .axis) physics = canvas.widgetScrollPhysics(node.widget, self.widget_tokens.scroll);
|
|
41
|
+
next = current;
|
|
42
|
+
current_axis = current.axis(axis);
|
|
43
|
+
},
|
|
44
|
+
.textarea_state => {
|
|
45
|
+
const vertical = axis == .vertical;
|
|
46
|
+
current_axis = .{
|
|
47
|
+
.offset = if (vertical) canvas.clampedTextInputScrollOffsetForWidget(node.widget, self.widget_tokens, node.widget.value) else canvas.clampedTextInputHorizontalScrollOffsetForWidget(node.widget, self.widget_tokens, node.widget.value_x),
|
|
48
|
+
.viewport_extent = if (vertical) viewport.height else viewport.width,
|
|
49
|
+
.content_extent = if (vertical) canvas.textInputContentExtentForWidget(node.widget, self.widget_tokens) else canvas.textInputContentWidthForWidget(node.widget, self.widget_tokens),
|
|
50
|
+
};
|
|
51
|
+
physics = self.widget_tokens.scroll;
|
|
52
|
+
},
|
|
53
|
+
.delegate_textarea => return run(self, policy, .textarea, index, axis, source, delta, 0, 0, false),
|
|
54
|
+
.wheel => next_axis = current_axis.applyWheel(delta, physics),
|
|
55
|
+
.wheel_clamped => next_axis = current_axis.applyWheelClamped(delta, physics),
|
|
56
|
+
.discrete => {
|
|
57
|
+
next_axis = current_axis;
|
|
58
|
+
if (mode == .axis) {
|
|
59
|
+
if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 1, .current = current_axis.offset, .viewport = current_axis.viewport_extent, .content = current_axis.content_extent, .delta = delta })) |result| {
|
|
60
|
+
next_axis.offset = result.dx;
|
|
61
|
+
next_axis.velocity = 0;
|
|
62
|
+
} else {
|
|
63
|
+
next_axis.offset += delta;
|
|
64
|
+
next_axis.velocity = 0;
|
|
65
|
+
next_axis = next_axis.clamped();
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
next_axis.offset += delta;
|
|
69
|
+
next_axis.velocity = 0;
|
|
70
|
+
next_axis = next_axis.clamped();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
.zero_velocity => next_axis.velocity = 0,
|
|
74
|
+
.store_axis => {
|
|
75
|
+
self.widget_scroll_states[index] = current.withAxis(axis, next_axis);
|
|
76
|
+
if (next_axis.offset != current_axis.offset) facts |= 512;
|
|
77
|
+
},
|
|
78
|
+
.compare_axis => if (next_axis.offset != current_axis.offset) {
|
|
79
|
+
facts |= 512;
|
|
80
|
+
},
|
|
81
|
+
.write_axis => switch (axis) {
|
|
82
|
+
.vertical => self.widget_layout_nodes[index].widget.value = next_axis.offset,
|
|
83
|
+
.horizontal => self.widget_layout_nodes[index].widget.value_x = next_axis.offset,
|
|
84
|
+
},
|
|
85
|
+
.translate_axis => self.translateCanvasWidgetScrollDescendants(index, if (axis == .vertical) .{ .dy = -(next_axis.offset - current_axis.offset) } else .{ .dx = -(next_axis.offset - current_axis.offset) }),
|
|
86
|
+
.event => self.noteCanvasWidgetScrollEvent(node.widget.id),
|
|
87
|
+
.semantics => try self.refreshCanvasWidgetSemantics(),
|
|
88
|
+
.revision => self.widget_revision += 1,
|
|
89
|
+
.dirty, .accumulate_dirty => dirty = self.canvasWidgetDirtyBounds(index, if (mode == .textarea) node.widget.frame else node.frame),
|
|
90
|
+
.driver_y => {
|
|
91
|
+
next.offset_y = offset_y;
|
|
92
|
+
next.velocity_y = 0;
|
|
93
|
+
},
|
|
94
|
+
.driver_x => {
|
|
95
|
+
next.offset_x = offset_x;
|
|
96
|
+
next.velocity_x = 0;
|
|
97
|
+
},
|
|
98
|
+
.target_y => next = next.withAxis(.vertical, target(node.widget, current.axis(.vertical), source)),
|
|
99
|
+
.target_x => next = next.withAxis(.horizontal, target(node.widget, current.axis(.horizontal), source)),
|
|
100
|
+
.store_state => {
|
|
101
|
+
self.widget_scroll_states[index] = next;
|
|
102
|
+
if (mode == .kinetic) {
|
|
103
|
+
if (moved.dx != 0 or moved.dy != 0) facts |= 512;
|
|
104
|
+
} else if (next.offset_y != current.offset_y or next.offset_x != current.offset_x) facts |= 512;
|
|
105
|
+
},
|
|
106
|
+
.write_both => {
|
|
107
|
+
self.widget_layout_nodes[index].widget.value = next.offset_y;
|
|
108
|
+
self.widget_layout_nodes[index].widget.value_x = next.offset_x;
|
|
109
|
+
},
|
|
110
|
+
.translate_both => {
|
|
111
|
+
const offset = if (mode == .kinetic) moved else geometry.OffsetF.init(next.offset_x - current.offset_x, next.offset_y - current.offset_y);
|
|
112
|
+
self.translateCanvasWidgetScrollDescendants(index, .{ .dx = -offset.dx, .dy = -offset.dy });
|
|
113
|
+
},
|
|
114
|
+
.clear_velocities => {
|
|
115
|
+
self.widget_scroll_states[index].velocity_y = 0;
|
|
116
|
+
self.widget_scroll_states[index].velocity_x = 0;
|
|
117
|
+
},
|
|
118
|
+
.probe_y => {
|
|
119
|
+
facts &= ~@as(u32, 1024);
|
|
120
|
+
if (current.axis(.vertical).needsKineticStep(physics)) facts |= 1024;
|
|
121
|
+
},
|
|
122
|
+
.probe_x => {
|
|
123
|
+
facts &= ~@as(u32, 1024);
|
|
124
|
+
if (current.axis(.horizontal).needsKineticStep(physics)) facts |= 1024;
|
|
125
|
+
},
|
|
126
|
+
.kinetic_y => {
|
|
127
|
+
const value = current.axis(.vertical).stepKinetic(delta, physics);
|
|
128
|
+
next = next.withAxis(.vertical, value);
|
|
129
|
+
moved.dy = value.offset - current.offset_y;
|
|
130
|
+
},
|
|
131
|
+
.kinetic_x => {
|
|
132
|
+
const value = current.axis(.horizontal).stepKinetic(delta, physics);
|
|
133
|
+
next = next.withAxis(.horizontal, value);
|
|
134
|
+
moved.dx = value.offset - current.offset_x;
|
|
135
|
+
},
|
|
136
|
+
.zero_y => next.velocity_y = 0,
|
|
137
|
+
.zero_x => next.velocity_x = 0,
|
|
138
|
+
};
|
|
139
|
+
if (program.next == 255) return .{ .dirty = dirty, .changed = facts & 512 != 0 };
|
|
140
|
+
phase = program.next;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
pub fn finish(self: anytype, policy: programs.Policy, changed: bool) anyerror!void {
|
|
145
|
+
const program = programs.plan(policy, .finish, 0, 0, false, if (changed) 512 else 0);
|
|
146
|
+
for (0..program.count) |i| switch (program.instruction(i)) {
|
|
147
|
+
.semantics => try self.refreshCanvasWidgetSemantics(),
|
|
148
|
+
.revision => self.widget_revision += 1,
|
|
149
|
+
else => unreachable,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fn target(widget: canvas.Widget, current: canvas.ScrollAxisState, source: u8) canvas.ScrollAxisState {
|
|
154
|
+
var next = current;
|
|
155
|
+
next.offset = if (canvas.widgetCompiledScrollResult(widget, .{ .operation = if (source == 0) 12 else 13, .viewport = current.viewport_extent, .content = current.content_extent })) |result| result.dx else if (source == 0) 0 else current.maxOffset();
|
|
156
|
+
next.velocity = 0;
|
|
157
|
+
return next.clamped();
|
|
158
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
//! Copied retained-tree plans. Native owns the geometry buffers and virtual
|
|
2
|
+
//! measurement; the planner chooses traversal, moving nodes and tab reveals.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const canvas = @import("canvas");
|
|
5
|
+
const geometry = @import("geometry");
|
|
6
|
+
const limits = @import("canvas_limits.zig");
|
|
7
|
+
pub const Policy = ?*const fn ([]const u8, []u8) usize;
|
|
8
|
+
pub const Request = struct {
|
|
9
|
+
operation: u8,
|
|
10
|
+
target: usize,
|
|
11
|
+
viewport: geometry.RectF = .{},
|
|
12
|
+
previous: canvas.WidgetLayoutTree = .{ .nodes = &.{} },
|
|
13
|
+
anchored_depth: ?usize = null,
|
|
14
|
+
strata: ?canvas.layout_coordination_policy.RetainedPlan = null,
|
|
15
|
+
};
|
|
16
|
+
pub const Plan = struct {
|
|
17
|
+
target: ?usize,
|
|
18
|
+
x: f32,
|
|
19
|
+
y: f32,
|
|
20
|
+
cursor: usize,
|
|
21
|
+
moving: [limits.max_canvas_widget_nodes_per_view]bool = undefined,
|
|
22
|
+
|
|
23
|
+
pub fn translate(self: *const Plan, nodes: []canvas.WidgetLayoutNode, offset: geometry.OffsetF) void {
|
|
24
|
+
for (nodes, 0..) |*node, i| if (self.moving[i]) {
|
|
25
|
+
node.frame = node.frame.translate(offset);
|
|
26
|
+
node.widget.frame = node.frame;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
pub fn build(policy: Policy, nodes: []const canvas.WidgetLayoutNode, request: Request) ?Plan {
|
|
31
|
+
const callback = policy orelse return null;
|
|
32
|
+
if (nodes.len > limits.max_canvas_widget_nodes_per_view or request.target > nodes.len or (request.operation != 2 and request.target == nodes.len)) @panic("scroll tree exceeds view budget");
|
|
33
|
+
var input: [48 + limits.max_canvas_widget_nodes_per_view * 56]u8 = undefined;
|
|
34
|
+
const bytes = input[0 .. 48 + nodes.len * 56];
|
|
35
|
+
@memset(bytes, 0);
|
|
36
|
+
bytes[0] = 94;
|
|
37
|
+
bytes[1] = request.operation;
|
|
38
|
+
word(bytes[4..8], nodes.len);
|
|
39
|
+
word(bytes[8..12], request.target);
|
|
40
|
+
word(bytes[12..16], request.anchored_depth orelse std.math.maxInt(u32));
|
|
41
|
+
rect(bytes[16..32], request.viewport);
|
|
42
|
+
if (request.operation == 0 and nodes[request.target].widget.layout.virtualized) float(bytes[32..36], canvas.virtualWidgetScrollContentExtent(nodes[request.target].widget, request.viewport.height));
|
|
43
|
+
const tree = canvas.WidgetLayoutTree{ .nodes = nodes };
|
|
44
|
+
for (nodes, 0..) |node, i| {
|
|
45
|
+
const w = node.widget;
|
|
46
|
+
const fact = bytes[48 + i * 56 ..][0..56];
|
|
47
|
+
word(fact[0..4], node.depth);
|
|
48
|
+
word(fact[4..8], node.parent_index orelse std.math.maxInt(u32));
|
|
49
|
+
var bits: u32 = 0;
|
|
50
|
+
if (canvas.widgetIsRootRelativeModal(w)) bits |= 1;
|
|
51
|
+
if (w.layout.anchor != null) bits |= 2;
|
|
52
|
+
if (canvas.widgetEscapesAncestorClips(w)) bits |= 4;
|
|
53
|
+
if (w.kind == .scroll_view or w.layout.clip_content) bits |= 8;
|
|
54
|
+
if (w.layout.virtualized) bits |= 16;
|
|
55
|
+
if (request.operation == 0 and canvas.widgetKindDisclosureAnimated(w.kind) and !canvas.disclosureSettledOpen(tree, i)) bits |= 32;
|
|
56
|
+
if (w.kind == .scroll_view and canvas.widgetScrollsAxis(w, .horizontal)) bits |= 64;
|
|
57
|
+
if (w.semantics.role == .tab and w.state.selected) {
|
|
58
|
+
bits |= 128;
|
|
59
|
+
if (request.operation == 2 and w.id != 0) for (request.previous.nodes) |previous| {
|
|
60
|
+
if (previous.widget.id != w.id) continue;
|
|
61
|
+
if (previous.widget.semantics.role == .tab and previous.widget.state.selected) bits |= 256;
|
|
62
|
+
break;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
word(fact[8..12], bits);
|
|
66
|
+
float(fact[12..16], w.value);
|
|
67
|
+
float(fact[16..20], w.value_x);
|
|
68
|
+
rect(fact[20..36], node.frame);
|
|
69
|
+
if (request.operation == 2) {
|
|
70
|
+
// Only eligible scroll ancestors consume a viewport. Other nodes
|
|
71
|
+
// may have negative extents that the tab planner normalizes itself.
|
|
72
|
+
if (bits & (64 | 16) == 64) rect(fact[36..52], node.frame.inset(w.layout.padding).normalized());
|
|
73
|
+
word(fact[52..56], if (request.strata) |plan| plan.nesting(i) else canvas.anchoredNestingDepth(nodes, i));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var output: [24 + limits.max_canvas_widget_nodes_per_view]u8 = undefined;
|
|
77
|
+
const size = callback(bytes, &output);
|
|
78
|
+
if (size != 24 + nodes.len or output[0] != 94 or output[1] != request.operation or output[2] != 0 or output[3] != 0 or std.mem.readInt(u32, output[4..8], .little) != nodes.len) @panic("invalid compiled scroll tree header");
|
|
79
|
+
const target = std.mem.readInt(u32, output[8..12], .little);
|
|
80
|
+
const cursor = std.mem.readInt(u32, output[20..24], .little);
|
|
81
|
+
if ((target != std.math.maxInt(u32) and (request.operation != 2 or target >= nodes.len or nodes[target].widget.kind != .scroll_view)) or
|
|
82
|
+
(request.operation == 2 and (cursor <= request.target and request.target < nodes.len or cursor > nodes.len)) or
|
|
83
|
+
(request.operation != 2 and cursor != 0)) @panic("invalid compiled scroll tree target");
|
|
84
|
+
var plan = Plan{ .target = if (target == std.math.maxInt(u32)) null else target, .cursor = cursor, .x = @bitCast(std.mem.readInt(u32, output[12..16], .little)), .y = @bitCast(std.mem.readInt(u32, output[16..20], .little)) };
|
|
85
|
+
for (plan.moving[0..nodes.len], 0..) |*moving, i| {
|
|
86
|
+
if (output[24 + i] > 1 or (request.operation == 0 and output[24 + i] != 0)) @panic("invalid compiled scroll tree translation");
|
|
87
|
+
moving.* = output[24 + i] != 0;
|
|
88
|
+
}
|
|
89
|
+
return plan;
|
|
90
|
+
}
|
|
91
|
+
fn word(bytes: *[4]u8, value: usize) void {
|
|
92
|
+
std.mem.writeInt(u32, bytes, @intCast(value), .little);
|
|
93
|
+
}
|
|
94
|
+
fn float(bytes: *[4]u8, value: f32) void {
|
|
95
|
+
std.mem.writeInt(u32, bytes, @bitCast(value), .little);
|
|
96
|
+
}
|
|
97
|
+
fn rect(bytes: *[16]u8, value: geometry.RectF) void {
|
|
98
|
+
inline for (.{ value.x, value.y, value.width, value.height }, 0..) |v, i| float(bytes[i * 4 ..][0..4], v);
|
|
99
|
+
}
|
|
@@ -482,6 +482,13 @@ pub const SessionRecorder = struct {
|
|
|
482
482
|
return if (self.failed) count else count + 1;
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
+
/// Stop recording because the session can no longer replay
|
|
486
|
+
/// faithfully (for example, its view changed mid-session). Same
|
|
487
|
+
/// loud, once-only failure as an internal recording failure.
|
|
488
|
+
pub fn abandon(self: *SessionRecorder, reason: []const u8) void {
|
|
489
|
+
self.fail(reason);
|
|
490
|
+
}
|
|
491
|
+
|
|
485
492
|
/// Flip into the failed state, loudly, once. Recording failures
|
|
486
493
|
/// degrade — the app keeps running; only the journal dies.
|
|
487
494
|
fn fail(self: *SessionRecorder, reason: []const u8) void {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//! Copied staged-rebuild programs. Native owns source/retained records and
|
|
2
|
+
//! geometry mutations; compiler results are copied before any further call.
|
|
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 Kind = enum(u8) { done, split, restore_scroll, clamp_scroll, reveal_tabs, anchors };
|
|
8
|
+
pub const Step = struct { kind: Kind, index: usize, depth: usize };
|
|
9
|
+
pub const Program = struct {
|
|
10
|
+
input: [32 + limits.max_canvas_widget_nodes_per_view * 8]u8 = @splat(0),
|
|
11
|
+
count: usize,
|
|
12
|
+
policy: Policy,
|
|
13
|
+
pub fn init(policy: Policy, count: usize, maximum: usize) Program {
|
|
14
|
+
if (count > limits.max_canvas_widget_nodes_per_view or maximum > 1024) @panic("staged rebuild exceeds budget");
|
|
15
|
+
var self = Program{ .count = count, .policy = policy };
|
|
16
|
+
self.input[0] = 96;
|
|
17
|
+
word(&self.input, 4, count);
|
|
18
|
+
word(&self.input, 16, maximum);
|
|
19
|
+
return self;
|
|
20
|
+
}
|
|
21
|
+
pub fn setNode(self: *Program, index: usize, node: canvas.WidgetLayoutNode, depth: usize) void {
|
|
22
|
+
word(&self.input, 32 + index * 8, @intFromBool(node.widget.kind == .split and node.widget.id != 0));
|
|
23
|
+
word(&self.input, 36 + index * 8, depth);
|
|
24
|
+
}
|
|
25
|
+
pub fn refreshAdmission(self: *Program, nodes: []const canvas.WidgetLayoutNode) void {
|
|
26
|
+
for (nodes, 0..) |node, i| word(&self.input, 32 + i * 8, @intFromBool(node.widget.kind == .split and node.widget.id != 0));
|
|
27
|
+
}
|
|
28
|
+
pub fn next(self: *Program) Step {
|
|
29
|
+
var output: [24]u8 = undefined;
|
|
30
|
+
if (self.policy(self.input[0 .. 32 + self.count * 8], &output) != output.len or
|
|
31
|
+
output[0] != 96 or output[1] != 0 or output[2] > 5 or output[3] != 0 or read(&output, 20) != 0)
|
|
32
|
+
@panic("invalid staged rebuild result");
|
|
33
|
+
const kind: Kind = @enumFromInt(output[2]);
|
|
34
|
+
const index = read(&output, 4);
|
|
35
|
+
const cursor = read(&output, 8);
|
|
36
|
+
const phase = read(&output, 12);
|
|
37
|
+
const depth = read(&output, 16);
|
|
38
|
+
const old_depth = read(&self.input, 12);
|
|
39
|
+
const old_phase = read(&self.input, 20);
|
|
40
|
+
const old_cursor = read(&self.input, 8);
|
|
41
|
+
if (cursor > self.count or phase > 3 or depth > read(&self.input, 16) or
|
|
42
|
+
(kind == .split and (index >= self.count or index < old_cursor or cursor <= index or read(&self.input, 32 + index * 8) != 1 or read(&self.input, 36 + index * 8) != old_depth)) or
|
|
43
|
+
(kind != .split and index != 0) or
|
|
44
|
+
(kind != .done and !(depth > old_depth or (depth == old_depth and (phase > old_phase or (phase == old_phase and cursor > old_cursor))))))
|
|
45
|
+
@panic("invalid staged rebuild progress");
|
|
46
|
+
word(&self.input, 8, cursor);
|
|
47
|
+
word(&self.input, 12, depth);
|
|
48
|
+
word(&self.input, 20, phase);
|
|
49
|
+
return .{ .kind = kind, .index = index, .depth = old_depth };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
pub const SplitKind = enum(u8) { keep, enter_slide, value_only, slide, relayout };
|
|
53
|
+
pub const Split = struct { kind: SplitKind, value: f32 };
|
|
54
|
+
pub fn split(policy: Policy, node: canvas.WidgetLayoutNode, previous: ?f32, source: ?f32, armed: bool, dragging: bool) Split {
|
|
55
|
+
var input: [32]u8 = @splat(0);
|
|
56
|
+
input[0..3].* = .{ 96, 1, bit(previous != null, 0) | bit(source != null, 1) | bit(node.widget.children.len != 0, 2) |
|
|
57
|
+
bit(node.widget.resize_duration_ms != 0, 3) | bit(node.widget.resize_origin >= 0, 4) | bit(armed, 5) | bit(dragging, 6) };
|
|
58
|
+
float(&input, 4, node.widget.value);
|
|
59
|
+
float(&input, 8, node.widget.resize_origin);
|
|
60
|
+
float(&input, 12, source orelse 0);
|
|
61
|
+
float(&input, 16, previous orelse 0);
|
|
62
|
+
var output: [12]u8 = undefined;
|
|
63
|
+
if (policy(&input, &output) != output.len or output[0] != 96 or output[1] != 1 or output[2] > 4 or output[3] != 0 or read(&output, 8) != 0)
|
|
64
|
+
@panic("invalid staged split result");
|
|
65
|
+
const kind: SplitKind = @enumFromInt(output[2]);
|
|
66
|
+
if ((kind == .enter_slide and (previous != null or node.widget.children.len == 0)) or
|
|
67
|
+
(kind != .keep and kind != .enter_slide and previous == null) or
|
|
68
|
+
((kind == .slide or kind == .relayout) and node.widget.children.len == 0))
|
|
69
|
+
@panic("invalid staged split capability");
|
|
70
|
+
return .{ .kind = kind, .value = @bitCast(read(&output, 4)) };
|
|
71
|
+
}
|
|
72
|
+
fn bit(value: bool, shift: u3) u8 {
|
|
73
|
+
return @as(u8, @intFromBool(value)) << shift;
|
|
74
|
+
}
|
|
75
|
+
fn word(bytes: []u8, at: usize, value: usize) void {
|
|
76
|
+
std.mem.writeInt(u32, bytes[at..][0..4], @intCast(value), .little);
|
|
77
|
+
}
|
|
78
|
+
fn read(bytes: []const u8, at: usize) u32 {
|
|
79
|
+
return std.mem.readInt(u32, bytes[at..][0..4], .little);
|
|
80
|
+
}
|
|
81
|
+
fn float(bytes: []u8, at: usize, value: f32) void {
|
|
82
|
+
word(bytes, at, @as(u32, @bitCast(value)));
|
|
83
|
+
}
|
|
@@ -139,6 +139,25 @@ pub fn RuntimeSystemServices(comptime Runtime: type) type {
|
|
|
139
139
|
return self.options.platform.services.formatLocalTime(timestamp_ms, style, buffer);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
/// Post a key chord to the focused app; requires the `keyboard_input` manifest permission.
|
|
143
|
+
pub fn sendKeyChord(self: *Runtime, chord: platform.KeyChord) anyerror!void {
|
|
144
|
+
try requireKeyboardInput(self);
|
|
145
|
+
try self.options.platform.services.sendKeyChord(chord);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// Report the OS grant for synthesized input; `prompt` asks the OS to show its grant prompt.
|
|
149
|
+
pub fn keyboardInputAccess(self: *Runtime, prompt: bool) anyerror!platform.KeyboardInputAccess {
|
|
150
|
+
try requireKeyboardInput(self);
|
|
151
|
+
return self.options.platform.services.keyboardInputAccess(prompt);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fn requireKeyboardInput(self: *Runtime) error{ UnsupportedService, PermissionDenied }!void {
|
|
155
|
+
if (self.options.platform.services.send_key_chord_fn == null) return error.UnsupportedService;
|
|
156
|
+
if (!authorization.hasPermission(self.authorization_policy, self.options.security.permissions, security.permission_keyboard_input)) {
|
|
157
|
+
return error.PermissionDenied;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
142
161
|
pub fn createStatusItem(self: *Runtime, status_item_id: platform.StatusItemId, options: platform.TrayOptions) anyerror!void {
|
|
143
162
|
if (self.command_policy) |policy| try status_validation.identity(policy, status_item_id) else try validation.validateStatusItemId(status_item_id);
|
|
144
163
|
if (self.command_policy) |policy| try status_validation.options(policy, options) else try validateTrayOptions(options);
|
package/src/runtime/tests.zig
CHANGED
|
@@ -28,6 +28,7 @@ test {
|
|
|
28
28
|
_ = @import("effects_image_tests.zig");
|
|
29
29
|
_ = @import("effects_channel_tests.zig");
|
|
30
30
|
_ = @import("effects_host_tests.zig");
|
|
31
|
+
_ = @import("keyboard_input.zig");
|
|
31
32
|
_ = @import("effects_credentials_tests.zig");
|
|
32
33
|
_ = @import("effects_store_tests.zig");
|
|
33
34
|
_ = @import("effects_relational_tests.zig");
|