@native-sdk/cli 0.5.2 → 0.5.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 +41 -0
- 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.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +39 -3
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +1 -0
- package/src/app_runner/root.zig +25 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +69 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/macos/appkit_host.h +11 -0
- package/src/platform/macos/appkit_host.m +130 -0
- package/src/platform/macos/root.zig +34 -0
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +109 -4
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +25 -0
- package/src/primitives/canvas/ui.zig +35 -2
- package/src/primitives/canvas/ui_markup.zig +24 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +40 -3
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +33 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
- package/src/primitives/canvas/ui_markup_tests.zig +26 -0
- package/src/primitives/canvas/ui_markup_view.zig +53 -4
- package/src/primitives/canvas/ui_markup_view_tests.zig +73 -2
- package/src/primitives/canvas/ui_schema.zig +16 -0
- package/src/primitives/canvas/ui_schema_tests.zig +10 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
- package/src/primitives/canvas/widget_layout.zig +9 -4
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widgets.zig +16 -0
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +13 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +64 -0
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +26 -0
- package/src/runtime/canvas_images.zig +33 -7
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +24 -4
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +98 -6
- package/src/runtime/flow.zig +27 -0
- package/src/runtime/gpu_surface_events.zig +7 -0
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +9 -0
- package/src/runtime/session_journal.zig +30 -3
- package/src/runtime/session_tests.zig +126 -4
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +58 -0
- package/src/runtime/ui_app_tests.zig +334 -0
package/src/runtime/root.zig
CHANGED
|
@@ -154,6 +154,15 @@ pub const RegisteredCanvasImage = runtime_canvas_images.RegisteredCanvasImage;
|
|
|
154
154
|
pub const max_registered_canvas_images = runtime_canvas_images.max_registered_canvas_images;
|
|
155
155
|
pub const max_registered_canvas_image_pixel_bytes = runtime_canvas_images.max_registered_canvas_image_pixel_bytes;
|
|
156
156
|
|
|
157
|
+
// The media-surface producer channel (media_surface.zig): the handle
|
|
158
|
+
// type `Runtime.acquireMediaSurfaceProducer` returns rides the public
|
|
159
|
+
// root so producer callbacks can be TYPED (the docs' mpv recipe takes a
|
|
160
|
+
// `MediaSurfaceProducer` parameter), alongside the channel budgets.
|
|
161
|
+
const runtime_media_surface = @import("media_surface.zig");
|
|
162
|
+
pub const MediaSurfaceProducer = runtime_media_surface.MediaSurfaceProducer;
|
|
163
|
+
pub const max_media_surface_channels = runtime_media_surface.max_media_surface_channels;
|
|
164
|
+
pub const max_media_surface_pixel_bytes = runtime_media_surface.max_media_surface_pixel_bytes;
|
|
165
|
+
|
|
157
166
|
const runtime_canvas_fonts = @import("canvas_fonts.zig");
|
|
158
167
|
pub const max_registered_canvas_fonts = runtime_canvas_fonts.max_registered_canvas_fonts;
|
|
159
168
|
pub const max_registered_canvas_font_bytes = runtime_canvas_fonts.max_registered_canvas_font_bytes;
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
//!
|
|
47
47
|
//! Coverage note: automation driving is fully journaled. Verbs that
|
|
48
48
|
//! synthesize PLATFORM events (widget-click/hold/context-press/drag/
|
|
49
|
-
//! wheel/key, resize, menu-command, shortcut, tray-action) journal
|
|
49
|
+
//! wheel/key/pinch, resize, menu-command, shortcut, tray-action) journal
|
|
50
50
|
//! those events; every widget-action verb — including the direct-
|
|
51
51
|
//! surface ones (focus, select, set_selection, set_text, and the
|
|
52
52
|
//! composition edits) — journals as the outer-wins
|
|
@@ -75,8 +75,11 @@ pub const magic = "NSDKSJNL";
|
|
|
75
75
|
/// composition verbs (`set_composition`/`commit_composition`/
|
|
76
76
|
/// `cancel_composition`, codes 11-13) to the accessibility-action
|
|
77
77
|
/// record's verb enum — a v3 reader hitting one of those codes would
|
|
78
|
-
/// have reported the file corrupt instead of refusing the skew
|
|
79
|
-
|
|
78
|
+
/// have reported the file corrupt instead of refusing the skew; v5
|
|
79
|
+
/// added the pinch magnification `scale` field to gpu-surface input
|
|
80
|
+
/// records (a layout change every v4 reader would misparse) plus the
|
|
81
|
+
/// `pinch_begin`/`pinch_change`/`pinch_end` input kinds (codes 12-14).
|
|
82
|
+
pub const format_version: u32 = 5;
|
|
80
83
|
|
|
81
84
|
// ------------------------------------------------------------- budgets
|
|
82
85
|
//
|
|
@@ -530,6 +533,8 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
|
|
|
530
533
|
try cursor.writeInt(u64, @intCast(composition_cursor));
|
|
531
534
|
}
|
|
532
535
|
try writeModifiers(&cursor, input.modifiers);
|
|
536
|
+
// v5: the pinch magnification delta (0 on non-pinch kinds).
|
|
537
|
+
try cursor.writeF32(input.scale);
|
|
533
538
|
},
|
|
534
539
|
.gpu_surface_scroll_driver => |driver| {
|
|
535
540
|
try cursor.writeEnum(EventTag.gpu_surface_scroll_driver);
|
|
@@ -756,6 +761,8 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
|
|
|
756
761
|
.text = text,
|
|
757
762
|
.composition_cursor = composition_cursor,
|
|
758
763
|
.modifiers = try readModifiers(&cursor),
|
|
764
|
+
// v5: the pinch magnification delta (0 on non-pinch kinds).
|
|
765
|
+
.scale = try cursor.readF32(),
|
|
759
766
|
} };
|
|
760
767
|
},
|
|
761
768
|
.gpu_surface_scroll_driver => blk: {
|
|
@@ -1230,6 +1237,26 @@ test "event codec round-trips every payload variant" {
|
|
|
1230
1237
|
try testing.expectEqualStrings("7", decoded.gpu_surface_input.text);
|
|
1231
1238
|
try testing.expectEqual(@as(?usize, 3), decoded.gpu_surface_input.composition_cursor);
|
|
1232
1239
|
try testing.expect(decoded.gpu_surface_input.modifiers.control);
|
|
1240
|
+
try testing.expectEqual(@as(f32, 0), decoded.gpu_surface_input.scale);
|
|
1241
|
+
}
|
|
1242
|
+
{
|
|
1243
|
+
// v5: pinch records carry the magnification delta and the
|
|
1244
|
+
// gesture kinds appended at codes 12-14.
|
|
1245
|
+
const decoded = try roundTripEvent(.{ .gpu_surface_input = .{
|
|
1246
|
+
.label = "timeline-canvas",
|
|
1247
|
+
.kind = .pinch_change,
|
|
1248
|
+
.timestamp_ns = 6,
|
|
1249
|
+
.x = 160,
|
|
1250
|
+
.y = 120,
|
|
1251
|
+
.scale = 0.25,
|
|
1252
|
+
} });
|
|
1253
|
+
try testing.expectEqual(platform.GpuSurfaceInputKind.pinch_change, decoded.gpu_surface_input.kind);
|
|
1254
|
+
try testing.expectEqual(@as(f32, 0.25), decoded.gpu_surface_input.scale);
|
|
1255
|
+
try testing.expectEqual(@as(f32, 160), decoded.gpu_surface_input.x);
|
|
1256
|
+
const begin = try roundTripEvent(.{ .gpu_surface_input = .{ .label = "timeline-canvas", .kind = .pinch_begin } });
|
|
1257
|
+
try testing.expectEqual(platform.GpuSurfaceInputKind.pinch_begin, begin.gpu_surface_input.kind);
|
|
1258
|
+
const end = try roundTripEvent(.{ .gpu_surface_input = .{ .label = "timeline-canvas", .kind = .pinch_end } });
|
|
1259
|
+
try testing.expectEqual(platform.GpuSurfaceInputKind.pinch_end, end.gpu_surface_input.kind);
|
|
1233
1260
|
}
|
|
1234
1261
|
{
|
|
1235
1262
|
const decoded = try roundTripEvent(.{ .widget_accessibility_action = .{
|
|
@@ -51,6 +51,13 @@ const SessionModel = struct {
|
|
|
51
51
|
name_anchor: usize = 0,
|
|
52
52
|
name_focus: usize = 0,
|
|
53
53
|
name_edits: u32 = 0,
|
|
54
|
+
/// The pinch channel's cumulative zoom (the product of 1 + delta
|
|
55
|
+
/// across change events) plus phase counters: the reference session
|
|
56
|
+
/// pinches once raw and once through the automation verb, so replay
|
|
57
|
+
/// re-deriving the identical product pins the journaled scale field.
|
|
58
|
+
zoom: f32 = 1,
|
|
59
|
+
pinch_begins: u32 = 0,
|
|
60
|
+
pinch_ends: u32 = 0,
|
|
54
61
|
|
|
55
62
|
fn bodyText(self: *const SessionModel) []const u8 {
|
|
56
63
|
return self.body[0..self.body_len];
|
|
@@ -73,6 +80,7 @@ const SessionMsg = union(enum) {
|
|
|
73
80
|
start_audio,
|
|
74
81
|
query_edit: canvas.TextInputEvent,
|
|
75
82
|
name_edit: canvas.TextInputEvent,
|
|
83
|
+
pinch: platform.PinchEvent,
|
|
76
84
|
fetched: effects_mod.EffectResponse,
|
|
77
85
|
line: effects_mod.EffectLine,
|
|
78
86
|
exited: effects_mod.EffectExit,
|
|
@@ -123,6 +131,11 @@ fn sessionUpdate(model: *SessionModel, msg: SessionMsg, fx: *SessionApp.Effects)
|
|
|
123
131
|
},
|
|
124
132
|
.query_edit => |edit| applyMirrorEdit(&model.query, &model.query_len, &model.query_anchor, &model.query_focus, &model.query_edits, edit),
|
|
125
133
|
.name_edit => |edit| applyMirrorEdit(&model.name, &model.name_len, &model.name_anchor, &model.name_focus, &model.name_edits, edit),
|
|
134
|
+
.pinch => |pinch| switch (pinch.phase) {
|
|
135
|
+
.begin => model.pinch_begins += 1,
|
|
136
|
+
.change => model.zoom *= (1 + pinch.scale),
|
|
137
|
+
.end => model.pinch_ends += 1,
|
|
138
|
+
},
|
|
126
139
|
.line => model.line_count += 1,
|
|
127
140
|
.exited => |exit| model.exit_code = exit.code,
|
|
128
141
|
.tick => |timer| model.tick_timestamp_ns = timer.timestamp_ns,
|
|
@@ -162,7 +175,13 @@ fn sessionView(ui: *SessionApp.Ui, model: *const SessionModel) SessionApp.Ui.Nod
|
|
|
162
175
|
.placeholder = "Name",
|
|
163
176
|
.on_input = SessionApp.Ui.inputMsg(.name_edit),
|
|
164
177
|
}, .{}),
|
|
178
|
+
// A static multi-line source the paste replay pin copies from:
|
|
179
|
+
// the journal records only the raw select-all/copy/paste
|
|
180
|
+
// platform events, so the multi-line clipboard bytes and the
|
|
181
|
+
// sanitized single-line insert both re-derive on replay.
|
|
182
|
+
ui.el(.textarea, .{ .text = "line one\nline two" }, .{}),
|
|
165
183
|
ui.text(.{}, ui.fmt("Query {s} ({d}) Name {s} ({d})", .{ model.queryText(), model.query_edits, model.nameText(), model.name_edits })),
|
|
184
|
+
ui.text(.{}, ui.fmt("Zoom {d:.4} ({d}/{d})", .{ model.zoom, model.pinch_begins, model.pinch_ends })),
|
|
166
185
|
ui.button(.{ .on_press = .increment }, "Increment"),
|
|
167
186
|
});
|
|
168
187
|
}
|
|
@@ -188,6 +207,10 @@ const session_windows = [_]app_manifest.ShellWindow{.{
|
|
|
188
207
|
}};
|
|
189
208
|
const session_scene: app_manifest.ShellConfig = .{ .windows = &session_windows };
|
|
190
209
|
|
|
210
|
+
fn sessionPinch(pinch: platform.PinchEvent) ?SessionMsg {
|
|
211
|
+
return .{ .pinch = pinch };
|
|
212
|
+
}
|
|
213
|
+
|
|
191
214
|
fn sessionOptions() SessionApp.Options {
|
|
192
215
|
return .{
|
|
193
216
|
.name = "session-demo",
|
|
@@ -196,6 +219,7 @@ fn sessionOptions() SessionApp.Options {
|
|
|
196
219
|
.update_fx = sessionUpdate,
|
|
197
220
|
.view = sessionView,
|
|
198
221
|
.on_command = sessionCommand,
|
|
222
|
+
.on_pinch = sessionPinch,
|
|
199
223
|
};
|
|
200
224
|
}
|
|
201
225
|
|
|
@@ -337,6 +361,98 @@ fn recordReferenceSession(gpa: std.mem.Allocator, buffer: *JournalBuffer, web_la
|
|
|
337
361
|
try std.testing.expectEqualStrings("", app_state.model.queryText());
|
|
338
362
|
try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
|
|
339
363
|
|
|
364
|
+
// A recorded MULTI-LINE PASTE replays to the identical sanitized
|
|
365
|
+
// value: copy the textarea's two lines (select-all + copy — raw
|
|
366
|
+
// journaled inputs that rebuild the clipboard on replay), then paste
|
|
367
|
+
// into the single-line search field. Sanitization is deterministic
|
|
368
|
+
// derivation at the apply seam, so the replayed editor, the model
|
|
369
|
+
// mirror, and the fingerprint all land on the same stripped bytes.
|
|
370
|
+
var textarea_frame: ?geometry.RectF = null;
|
|
371
|
+
for ((try harness.runtime.canvasWidgetLayout(1, canvas_label)).nodes) |node| {
|
|
372
|
+
if (node.widget.kind == .textarea) textarea_frame = node.frame;
|
|
373
|
+
}
|
|
374
|
+
const source_frame = textarea_frame.?;
|
|
375
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
376
|
+
.window_id = 1,
|
|
377
|
+
.label = canvas_label,
|
|
378
|
+
.kind = .pointer_down,
|
|
379
|
+
.x = source_frame.x + source_frame.width * 0.5,
|
|
380
|
+
.y = source_frame.y + source_frame.height * 0.5,
|
|
381
|
+
} });
|
|
382
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
383
|
+
.window_id = 1,
|
|
384
|
+
.label = canvas_label,
|
|
385
|
+
.kind = .key_down,
|
|
386
|
+
.key = "a",
|
|
387
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
388
|
+
} });
|
|
389
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
390
|
+
.window_id = 1,
|
|
391
|
+
.label = canvas_label,
|
|
392
|
+
.kind = .key_down,
|
|
393
|
+
.key = "c",
|
|
394
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
395
|
+
} });
|
|
396
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
397
|
+
.window_id = 1,
|
|
398
|
+
.label = canvas_label,
|
|
399
|
+
.kind = .pointer_down,
|
|
400
|
+
.x = field_frame.x + field_frame.width * 0.5,
|
|
401
|
+
.y = field_frame.y + field_frame.height * 0.5,
|
|
402
|
+
} });
|
|
403
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
404
|
+
.window_id = 1,
|
|
405
|
+
.label = canvas_label,
|
|
406
|
+
.kind = .key_down,
|
|
407
|
+
.key = "v",
|
|
408
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
409
|
+
} });
|
|
410
|
+
try std.testing.expectEqualStrings("line oneline two", app_state.model.queryText());
|
|
411
|
+
|
|
412
|
+
// A trackpad pinch, twice over: the raw journaled phase stream (the
|
|
413
|
+
// macOS host shape — begin, two deltas, end; the +25% then -25%
|
|
414
|
+
// deltas compound as a PRODUCT, 1.25 * 0.75 = 0.9375, never a sum's
|
|
415
|
+
// 1.0), then the automation verb's synthesized gesture, which
|
|
416
|
+
// journals the same leaf gpu_surface_input events. Replay must
|
|
417
|
+
// re-derive the identical cumulative zoom from the journaled scale
|
|
418
|
+
// fields alone. Every value here is binary-exact in f32, so the
|
|
419
|
+
// model equality below is exact, not approximate.
|
|
420
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
421
|
+
.window_id = 1,
|
|
422
|
+
.label = canvas_label,
|
|
423
|
+
.kind = .pinch_begin,
|
|
424
|
+
.x = 200,
|
|
425
|
+
.y = 150,
|
|
426
|
+
} });
|
|
427
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
428
|
+
.window_id = 1,
|
|
429
|
+
.label = canvas_label,
|
|
430
|
+
.kind = .pinch_change,
|
|
431
|
+
.x = 200,
|
|
432
|
+
.y = 150,
|
|
433
|
+
.scale = 0.25,
|
|
434
|
+
} });
|
|
435
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
436
|
+
.window_id = 1,
|
|
437
|
+
.label = canvas_label,
|
|
438
|
+
.kind = .pinch_change,
|
|
439
|
+
.x = 200,
|
|
440
|
+
.y = 150,
|
|
441
|
+
.scale = -0.25,
|
|
442
|
+
} });
|
|
443
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
444
|
+
.window_id = 1,
|
|
445
|
+
.label = canvas_label,
|
|
446
|
+
.kind = .pinch_end,
|
|
447
|
+
.x = 200,
|
|
448
|
+
.y = 150,
|
|
449
|
+
} });
|
|
450
|
+
try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
|
|
451
|
+
var pinch_buffer: [64]u8 = undefined;
|
|
452
|
+
const pinch_command = try std.fmt.bufPrint(&pinch_buffer, "widget-pinch {s} 1.5 120 80", .{canvas_label});
|
|
453
|
+
try harness.runtime.dispatchAutomationCommand(app, pinch_command);
|
|
454
|
+
try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
|
|
455
|
+
|
|
340
456
|
recorder.finish();
|
|
341
457
|
try std.testing.expect(!recorder.failed);
|
|
342
458
|
|
|
@@ -389,10 +505,16 @@ test "a recorded session replays to identical model state and fingerprints" {
|
|
|
389
505
|
try std.testing.expect(recorded.model.stamp_ms != 0);
|
|
390
506
|
try std.testing.expectEqual(@as(u32, 1), recorded.model.spectrum_count);
|
|
391
507
|
try std.testing.expect(recorded.model.band_checksum != 0);
|
|
392
|
-
// The typed insert
|
|
393
|
-
// model's `on_input` mirror
|
|
394
|
-
|
|
395
|
-
try std.testing.
|
|
508
|
+
// The typed insert, the DERIVED Escape-clear, and the sanitized
|
|
509
|
+
// multi-line paste all reached the model's `on_input` mirror — the
|
|
510
|
+
// paste landing STRIPPED of its line breaks (single-line rule).
|
|
511
|
+
try std.testing.expectEqual(@as(u32, 3), recorded.model.query_edits);
|
|
512
|
+
try std.testing.expectEqualStrings("line oneline two", recorded.model.queryText());
|
|
513
|
+
// Both pinch gestures reached the model: the raw stream's product
|
|
514
|
+
// (1.25 * 0.75 = 0.9375) times the verb's exact 1.5.
|
|
515
|
+
try std.testing.expectEqual(@as(u32, 2), recorded.model.pinch_begins);
|
|
516
|
+
try std.testing.expectEqual(@as(u32, 2), recorded.model.pinch_ends);
|
|
517
|
+
try std.testing.expectEqual(@as(f32, 1.40625), recorded.model.zoom);
|
|
396
518
|
|
|
397
519
|
const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
|
|
398
520
|
try std.testing.expect(replayed.report.ok());
|
package/src/runtime/tests.zig
CHANGED
|
@@ -14,6 +14,7 @@ test {
|
|
|
14
14
|
_ = @import("ui_app_huge_model_tests.zig");
|
|
15
15
|
_ = @import("ui_app_window_tests.zig");
|
|
16
16
|
_ = @import("canvas_image_tests.zig");
|
|
17
|
+
_ = @import("media_surface_tests.zig");
|
|
17
18
|
_ = @import("canvas_font_tests.zig");
|
|
18
19
|
_ = @import("effects_tests.zig");
|
|
19
20
|
_ = @import("effects_fetch_tests.zig");
|
|
@@ -193,6 +193,12 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
193
193
|
}
|
|
194
194
|
stamped.on_key = keyMsgAdapter;
|
|
195
195
|
}
|
|
196
|
+
if (comptime @hasDecl(core, "pinchMsg")) {
|
|
197
|
+
if (options.on_pinch != null) {
|
|
198
|
+
@panic("TsUiApp wires on_pinch from the core's pinchMsg export - remove the wiring's on_pinch");
|
|
199
|
+
}
|
|
200
|
+
stamped.on_pinch = pinchMsgAdapter;
|
|
201
|
+
}
|
|
196
202
|
if (comptime @hasDecl(core, "appearanceMsg")) {
|
|
197
203
|
if (options.on_appearance != null) {
|
|
198
204
|
@panic("TsUiApp wires on_appearance from the core's appearanceMsg export - remove the wiring's on_appearance");
|
|
@@ -360,6 +366,56 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
360
366
|
return core.keyMsg(arg);
|
|
361
367
|
}
|
|
362
368
|
|
|
369
|
+
/// `Options.on_pinch` over the core's `pinchMsg(pinch)` export:
|
|
370
|
+
/// the emitted PinchEvent record — `windowId`/`label` (the
|
|
371
|
+
/// source identity: `x`/`y` are view-local, so a coordinate
|
|
372
|
+
/// without its view is not a position; multi-window cores tell
|
|
373
|
+
/// pinches apart by these), `phase` (the declared
|
|
374
|
+
/// begin/change/end alias, matched by member name), `scale` (the
|
|
375
|
+
/// magnification DELTA on "change" — multiplicative, so the
|
|
376
|
+
/// cumulative gesture scale is the product of `1 + scale`,
|
|
377
|
+
/// applied memorylessly), and the `x`/`y` pointer anchor
|
|
378
|
+
/// in view-local canvas points. The core's return gates the channel
|
|
379
|
+
/// exactly like a Zig `on_pinch` (null drops the event).
|
|
380
|
+
fn pinchMsgAdapter(pinch: platform.PinchEvent) ?Msg {
|
|
381
|
+
const params = @typeInfo(@TypeOf(core.pinchMsg)).@"fn".params;
|
|
382
|
+
if (comptime params.len != 1) {
|
|
383
|
+
@compileError("TsUiApp: pinchMsg must take one PinchEvent parameter - regenerate the core");
|
|
384
|
+
}
|
|
385
|
+
const PinchArg = params[0].type.?;
|
|
386
|
+
comptime {
|
|
387
|
+
const fields = @typeInfo(PinchArg).@"struct".fields;
|
|
388
|
+
if (fields.len != 6 or !@hasField(PinchArg, "windowId") or !@hasField(PinchArg, "label") or
|
|
389
|
+
!@hasField(PinchArg, "phase") or !@hasField(PinchArg, "scale") or
|
|
390
|
+
!@hasField(PinchArg, "x") or !@hasField(PinchArg, "y"))
|
|
391
|
+
{
|
|
392
|
+
@compileError("TsUiApp: pinchMsg's PinchEvent must be exactly { windowId: number; label: string; phase: \"begin\" | \"change\" | \"end\"; scale: number; x: number; y: number }");
|
|
393
|
+
}
|
|
394
|
+
const Phase = @FieldType(PinchArg, "phase");
|
|
395
|
+
const phase_info = @typeInfo(Phase);
|
|
396
|
+
if (phase_info != .@"enum" or phase_info.@"enum".fields.len != 3 or
|
|
397
|
+
!@hasField(Phase, "begin") or !@hasField(Phase, "change") or !@hasField(Phase, "end"))
|
|
398
|
+
{
|
|
399
|
+
@compileError("TsUiApp: pinchMsg's PinchEvent.phase must be the named \"begin\" | \"change\" | \"end\" alias");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
var arg: PinchArg = undefined;
|
|
403
|
+
const Phase = @FieldType(PinchArg, "phase");
|
|
404
|
+
arg.phase = switch (pinch.phase) {
|
|
405
|
+
inline else => |phase| @field(Phase, @tagName(phase)),
|
|
406
|
+
};
|
|
407
|
+
// The label slice stays borrowed exactly through the core
|
|
408
|
+
// call, like the Zig channel's contract: a Msg built from it
|
|
409
|
+
// commits (copies) on dispatch like every routed bytes
|
|
410
|
+
// payload.
|
|
411
|
+
arg.windowId = channelNum(@FieldType(PinchArg, "windowId"), @floatFromInt(pinch.window_id));
|
|
412
|
+
arg.label = pinch.label;
|
|
413
|
+
arg.scale = channelNum(@FieldType(PinchArg, "scale"), pinch.scale);
|
|
414
|
+
arg.x = channelNum(@FieldType(PinchArg, "x"), pinch.x);
|
|
415
|
+
arg.y = channelNum(@FieldType(PinchArg, "y"), pinch.y);
|
|
416
|
+
return core.pinchMsg(arg);
|
|
417
|
+
}
|
|
418
|
+
|
|
363
419
|
/// `Options.on_appearance` over the core's `appearanceMsg` arm
|
|
364
420
|
/// export: the appearance record — `colorScheme` (a declared
|
|
365
421
|
/// light/dark enum, matched by member name), `reduceMotion`,
|
package/src/runtime/ui_app.zig
CHANGED
|
@@ -537,6 +537,26 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
537
537
|
/// can never steal typing — a fallback that yields to every
|
|
538
538
|
/// consuming widget can carry them safely.
|
|
539
539
|
on_key: ?*const fn (keyboard: canvas.WidgetKeyboardEvent) ?MsgT = null,
|
|
540
|
+
/// Optional mapping from trackpad pinch gestures into
|
|
541
|
+
/// messages — the app-level gesture channel (the `on_key`
|
|
542
|
+
/// shape). Pinch deliberately bypasses the widget pipeline:
|
|
543
|
+
/// it is a view-global gesture (timeline/canvas zoom is an
|
|
544
|
+
/// app-level concern), delivered phase-explicit (`begin`,
|
|
545
|
+
/// `change`, `end`) with the per-event magnification DELTA
|
|
546
|
+
/// on `change` — a MULTIPLICATIVE delta: the cumulative
|
|
547
|
+
/// gesture scale is the running product of `(1 + scale)`,
|
|
548
|
+
/// applied memorylessly (`zoom *= 1 + scale`); on macOS the
|
|
549
|
+
/// host forwards AppKit's raw `NSEvent.magnification`,
|
|
550
|
+
/// which IS that delta per the browser-engine convention
|
|
551
|
+
/// — and the pointer anchor in
|
|
552
|
+
/// view-local canvas points (`x`/`y`, the zoom-at-cursor
|
|
553
|
+
/// anchor). Every event names its source window and view
|
|
554
|
+
/// (`window_id`/`label`, the `on_frame` identity shape) —
|
|
555
|
+
/// view-local coordinates mean nothing without their view,
|
|
556
|
+
/// so multi-window apps tell pinches apart. Only hosts with
|
|
557
|
+
/// a pinch source emit these (macOS today); everywhere else
|
|
558
|
+
/// the channel simply never fires.
|
|
559
|
+
on_pinch: ?*const fn (pinch: platform.PinchEvent) ?MsgT = null,
|
|
540
560
|
/// Optional mapping from runtime timer events (started via
|
|
541
561
|
/// `runtime.startTimer`) into messages. Framework-reserved timer
|
|
542
562
|
/// ids (>= `platform.reserved_timer_id_base`) are handled
|
|
@@ -2770,6 +2790,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2770
2790
|
.canvas_widget_change => |change_event| try self.handleWidgetChange(runtime, change_event),
|
|
2771
2791
|
.window_closed => |closed| try self.handleWindowClosed(runtime, closed),
|
|
2772
2792
|
.automation_provenance => |query| try self.handleProvenanceQuery(runtime, query),
|
|
2793
|
+
// Raw gpu-surface input stays runtime-internal EXCEPT the
|
|
2794
|
+
// pinch kinds, which surface through the app-level pinch
|
|
2795
|
+
// channel (widget routing never claims a pinch).
|
|
2796
|
+
.gpu_surface_input => |input_event| try self.handlePinch(runtime, input_event),
|
|
2773
2797
|
else => {},
|
|
2774
2798
|
}
|
|
2775
2799
|
}
|
|
@@ -2835,6 +2859,13 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2835
2859
|
"font \"{s}\" (id {d}) failed to register: {s}",
|
|
2836
2860
|
.{ font.name, font.id, canvas.font_ttf.parseFailureReason(font.ttf) orelse "not a parseable TrueType face" },
|
|
2837
2861
|
),
|
|
2862
|
+
error.FontExceedsGlyphBudgets => if (canvas.font_ttf.declaredGlyphMaxima(font.ttf)) |maxima| ui_app_log.warn(
|
|
2863
|
+
"font \"{s}\" (id {d}) failed to register: its 'maxp' declares glyphs up to {d} points / {d} contours, flattened composites up to {d} points / {d} contours, with composites {d} deep of {d} components, beyond the outline budgets ({d} points, {d} contours, {d} composite points, {d} composite contours, {d} deep, {d} components — canvas.font_ttf); past-budget glyphs would render as block fallbacks, so registration refuses the face whole",
|
|
2864
|
+
.{ font.name, font.id, maxima.points, maxima.contours, maxima.composite_points, maxima.composite_contours, maxima.component_depth, maxima.component_elements, canvas.font_ttf.max_glyph_points, canvas.font_ttf.max_glyph_contours, canvas.font_ttf.max_composite_points, canvas.font_ttf.max_composite_contours, canvas.font_ttf.max_composite_depth, canvas.font_ttf.max_composite_components },
|
|
2865
|
+
) else ui_app_log.warn(
|
|
2866
|
+
"font \"{s}\" (id {d}) failed to register: it declares glyph outlines denser than the renderer's budgets ({d} points / {d} contours per glyph — canvas.font_ttf), so its densest glyphs could not render as outlines",
|
|
2867
|
+
.{ font.name, font.id, canvas.font_ttf.max_glyph_points, canvas.font_ttf.max_glyph_contours },
|
|
2868
|
+
),
|
|
2838
2869
|
error.FontTooLarge => ui_app_log.warn(
|
|
2839
2870
|
"font \"{s}\" (id {d}) failed to register: the file is {d} bytes but the per-font budget is {d} bytes (canvas_limits.max_registered_canvas_font_bytes)",
|
|
2840
2871
|
.{ font.name, font.id, font.ttf.len, canvas_limits.max_registered_canvas_font_bytes },
|
|
@@ -3343,6 +3374,33 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
3343
3374
|
}
|
|
3344
3375
|
}
|
|
3345
3376
|
|
|
3377
|
+
/// Trackpad pinch reaches the app as the view-global gesture
|
|
3378
|
+
/// channel (`Options.on_pinch`): only the pinch kinds of the raw
|
|
3379
|
+
/// gpu-surface input surface here — every other raw input kind
|
|
3380
|
+
/// stays runtime-internal (widgets and the semantic Msg surface
|
|
3381
|
+
/// already carry it). The Msg dispatch rides the same journaled
|
|
3382
|
+
/// input event, so a recorded pinch replays to the identical
|
|
3383
|
+
/// model.
|
|
3384
|
+
fn handlePinch(self: *Self, runtime: *Runtime, input_event: platform.GpuSurfaceInputEvent) anyerror!void {
|
|
3385
|
+
const map = self.options.on_pinch orelse return;
|
|
3386
|
+
const phase: platform.PinchPhase = switch (input_event.kind) {
|
|
3387
|
+
.pinch_begin => .begin,
|
|
3388
|
+
.pinch_change => .change,
|
|
3389
|
+
.pinch_end => .end,
|
|
3390
|
+
else => return,
|
|
3391
|
+
};
|
|
3392
|
+
if (map(.{
|
|
3393
|
+
.window_id = input_event.window_id,
|
|
3394
|
+
.label = input_event.label,
|
|
3395
|
+
.phase = phase,
|
|
3396
|
+
.scale = input_event.scale,
|
|
3397
|
+
.x = input_event.x,
|
|
3398
|
+
.y = input_event.y,
|
|
3399
|
+
})) |msg| {
|
|
3400
|
+
try self.dispatch(runtime, input_event.window_id, msg);
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3346
3404
|
/// Split-fraction changes route through the split's `on_resize`
|
|
3347
3405
|
/// constructor. The payload is the fraction the runtime already
|
|
3348
3406
|
/// applied, so a model that stores it and echoes it back into
|