@native-sdk/cli 0.5.2 → 0.5.4

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.
Files changed (123) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +264 -3
  3. package/native-sdk.d.ts +17 -1
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/rt/rt.zig +138 -3
  8. package/packages/core/sdk/core.ts +225 -3
  9. package/packages/core/sdk/events.ts +39 -2
  10. package/packages/core/src/checker.ts +1 -1
  11. package/packages/core/src/emitter.ts +2625 -262
  12. package/packages/core/src/infer.ts +53 -7
  13. package/skill-data/automation/SKILL.md +7 -4
  14. package/skill-data/core/references/app-model-runtime.md +3 -0
  15. package/skill-data/native-ui/SKILL.md +4 -2
  16. package/skill-data/ts-core/SKILL.md +9 -1
  17. package/src/app_runner/root.zig +106 -1
  18. package/src/app_runner/ts_core_main.zig +4 -0
  19. package/src/automation/protocol.zig +20 -1
  20. package/src/embed/host.zig +27 -0
  21. package/src/embed/tests.zig +187 -0
  22. package/src/embed/ui_host.zig +4 -0
  23. package/src/platform/linux/gtk_host.c +112 -3
  24. package/src/platform/linux/root.zig +71 -0
  25. package/src/platform/macos/appkit_host.h +59 -2
  26. package/src/platform/macos/appkit_host.m +663 -34
  27. package/src/platform/macos/cef_host.mm +262 -10
  28. package/src/platform/macos/root.zig +126 -4
  29. package/src/platform/null_platform.zig +298 -5
  30. package/src/platform/null_platform_tests.zig +39 -0
  31. package/src/platform/root.zig +36 -0
  32. package/src/platform/types.zig +247 -8
  33. package/src/platform/windows/root.zig +134 -0
  34. package/src/platform/windows/webview2_host.cpp +152 -40
  35. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  36. package/src/primitives/app_manifest/root.zig +1 -0
  37. package/src/primitives/app_manifest/types.zig +32 -0
  38. package/src/primitives/canvas/chart.zig +7 -7
  39. package/src/primitives/canvas/chart_tests.zig +66 -0
  40. package/src/primitives/canvas/commands.zig +48 -0
  41. package/src/primitives/canvas/events.zig +161 -0
  42. package/src/primitives/canvas/font_ttf.zig +155 -8
  43. package/src/primitives/canvas/font_ttf_tests.zig +686 -0
  44. package/src/primitives/canvas/reference.zig +67 -8
  45. package/src/primitives/canvas/render_fingerprints.zig +8 -0
  46. package/src/primitives/canvas/root.zig +25 -0
  47. package/src/primitives/canvas/tests.zig +1 -0
  48. package/src/primitives/canvas/ui.zig +46 -9
  49. package/src/primitives/canvas/ui_markup.zig +82 -34
  50. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  51. package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
  52. package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
  53. package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
  54. package/src/primitives/canvas/ui_markup_contract.zig +10 -1
  55. package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
  56. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  57. package/src/primitives/canvas/ui_markup_tests.zig +55 -9
  58. package/src/primitives/canvas/ui_markup_view.zig +81 -14
  59. package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
  60. package/src/primitives/canvas/ui_schema.zig +29 -0
  61. package/src/primitives/canvas/ui_schema_tests.zig +11 -11
  62. package/src/primitives/canvas/ui_tests.zig +31 -0
  63. package/src/primitives/canvas/vector.zig +258 -141
  64. package/src/primitives/canvas/widget_access.zig +1 -1
  65. package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
  66. package/src/primitives/canvas/widget_layout.zig +9 -4
  67. package/src/primitives/canvas/widget_render.zig +78 -40
  68. package/src/primitives/canvas/widget_render_controls.zig +15 -4
  69. package/src/primitives/canvas/widget_semantics.zig +6 -1
  70. package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
  71. package/src/primitives/canvas/widget_text_input.zig +118 -10
  72. package/src/primitives/canvas/widgets.zig +16 -0
  73. package/src/root.zig +12 -0
  74. package/src/runtime/api.zig +15 -0
  75. package/src/runtime/automation_commands.zig +33 -0
  76. package/src/runtime/automation_widget_dispatch.zig +64 -0
  77. package/src/runtime/bridge_payload.zig +7 -0
  78. package/src/runtime/bridge_responses.zig +5 -0
  79. package/src/runtime/builtin_bridge.zig +9 -4
  80. package/src/runtime/canvas_font_tests.zig +711 -5
  81. package/src/runtime/canvas_fonts.zig +120 -25
  82. package/src/runtime/canvas_frame_helpers.zig +15 -0
  83. package/src/runtime/canvas_image_tests.zig +221 -0
  84. package/src/runtime/canvas_images.zig +78 -19
  85. package/src/runtime/canvas_limits.zig +44 -8
  86. package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
  87. package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
  88. package/src/runtime/canvas_widget_events.zig +24 -4
  89. package/src/runtime/canvas_widget_runtime.zig +24 -7
  90. package/src/runtime/canvas_widget_state.zig +6 -1
  91. package/src/runtime/canvas_widget_text_tests.zig +277 -0
  92. package/src/runtime/core.zig +148 -9
  93. package/src/runtime/effects.zig +1664 -43
  94. package/src/runtime/effects_fetch_tests.zig +89 -1
  95. package/src/runtime/effects_file_tests.zig +41 -1
  96. package/src/runtime/effects_image_tests.zig +1304 -0
  97. package/src/runtime/effects_tests.zig +153 -0
  98. package/src/runtime/flow.zig +44 -0
  99. package/src/runtime/gpu_surface_events.zig +7 -0
  100. package/src/runtime/media_surface.zig +726 -0
  101. package/src/runtime/media_surface_tests.zig +1476 -0
  102. package/src/runtime/root.zig +20 -0
  103. package/src/runtime/session_blobs.zig +689 -0
  104. package/src/runtime/session_journal.zig +111 -20
  105. package/src/runtime/session_record.zig +27 -2
  106. package/src/runtime/session_replay.zig +168 -16
  107. package/src/runtime/session_tests.zig +2118 -4
  108. package/src/runtime/shell_layout.zig +7 -0
  109. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  110. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  111. package/src/runtime/tests.zig +3 -0
  112. package/src/runtime/ts_core_host.zig +439 -4
  113. package/src/runtime/ts_core_host_tests.zig +41 -0
  114. package/src/runtime/ts_ui_app.zig +63 -0
  115. package/src/runtime/ui_app.zig +169 -6
  116. package/src/runtime/ui_app_tests.zig +334 -0
  117. package/src/runtime/ui_app_window_tests.zig +468 -0
  118. package/src/runtime/window_command_bridge_tests.zig +117 -0
  119. package/src/runtime/window_storage.zig +32 -0
  120. package/src/runtime/window_views.zig +61 -1
  121. package/src/tooling/manifest.zig +75 -0
  122. package/src/tooling/raw_manifest.zig +2 -0
  123. package/src/tooling/templates.zig +219 -1
@@ -133,6 +133,21 @@ pub const WidgetKind = enum {
133
133
  /// never double-draw. Not a hit target itself: the textarea fills the
134
134
  /// group's body, so a click "in the field" IS a click in the textarea.
135
135
  input_group,
136
+ /// The media surface leaf: composites a texture PRODUCED OUTSIDE the
137
+ /// widget tree (a video decoder, a camera pipeline, an external
138
+ /// renderer) into the layout like any widget — clipped, z-ordered,
139
+ /// transformed. `image_id` carries the SURFACE id the producer
140
+ /// targets (`Runtime.acquireMediaSurfaceProducer`), a model-owned
141
+ /// u64 in the ImageId value space; 0 is the unbound sentinel, and
142
+ /// usable ids are nonzero values below the reserved namespace bit
143
+ /// (`media_surface_image_id_bit`, refused at acquire).
144
+ /// Display-only like `image` and `chart`: not a hit target, presses
145
+ /// fall through to the nearest pressable ancestor. Texture CONTENTS
146
+ /// are presentation chrome — the deterministic reference renderer
147
+ /// draws the surface's id-derived placeholder instead (see
148
+ /// `ReferenceImage.presentation_only`), so goldens and session
149
+ /// fingerprints never depend on producer output.
150
+ media_surface,
136
151
  };
137
152
 
138
153
  /// STABLE code for a widget kind: assigned at birth, never reused or
@@ -210,6 +225,7 @@ pub fn widgetKindCode(kind: WidgetKind) u16 {
210
225
  .split_divider => 58,
211
226
  .tree => 59,
212
227
  .input_group => 60,
228
+ .media_surface => 61,
213
229
  };
214
230
  }
215
231
 
package/src/root.zig CHANGED
@@ -76,6 +76,12 @@ pub const EffectAudioEventKind = runtime.EffectAudioEventKind;
76
76
  pub const EffectAudioSource = runtime.EffectAudioSource;
77
77
  pub const audioCachePath = runtime.audioCachePath;
78
78
  pub const max_effect_audio_path_bytes = runtime.max_effect_audio_path_bytes;
79
+ pub const EffectImageResult = runtime.EffectImageResult;
80
+ pub const EffectImageOutcome = runtime.EffectImageOutcome;
81
+ pub const imageCachePath = runtime.imageCachePath;
82
+ pub const max_effect_image_path_bytes = runtime.max_effect_image_path_bytes;
83
+ pub const max_effect_image_bytes = runtime.max_effect_image_bytes;
84
+ pub const effect_image_blob_hash_len = runtime.effect_image_blob_hash_len;
79
85
  pub const EffectHostResult = runtime.EffectHostResult;
80
86
  pub const HostCallBinding = runtime.HostCallBinding;
81
87
  pub const max_effect_host_name_bytes = runtime.max_effect_host_name_bytes;
@@ -93,6 +99,9 @@ pub const setFreestandingMonotonicNanoseconds = runtime.setFreestandingMonotonic
93
99
  pub const RegisteredImage = runtime.RegisteredImage;
94
100
  pub const max_registered_canvas_images = runtime.max_registered_canvas_images;
95
101
  pub const max_registered_canvas_image_pixel_bytes = runtime.max_registered_canvas_image_pixel_bytes;
102
+ pub const MediaSurfaceProducer = runtime.MediaSurfaceProducer;
103
+ pub const max_media_surface_channels = runtime.max_media_surface_channels;
104
+ pub const max_media_surface_pixel_bytes = runtime.max_media_surface_pixel_bytes;
96
105
  pub const ShellConfig = app_manifest.ShellConfig;
97
106
  pub const ShellWindow = app_manifest.ShellWindow;
98
107
  pub const ShellView = app_manifest.ShellView;
@@ -134,6 +143,7 @@ pub const WindowChrome = platform.WindowChrome;
134
143
  pub const FormFactor = platform.FormFactor;
135
144
  pub const WindowDragRegion = platform.WindowDragRegion;
136
145
  pub const WindowShowMode = platform.WindowShowMode;
146
+ pub const WindowClosePolicy = platform.WindowClosePolicy;
137
147
  pub const Menu = platform.Menu;
138
148
  pub const MenuItem = platform.MenuItem;
139
149
  pub const Shortcut = platform.Shortcut;
@@ -147,6 +157,8 @@ pub const GpuSurfaceFrameEvent = platform.GpuSurfaceFrameEvent;
147
157
  pub const GpuSurfaceResizeEvent = platform.GpuSurfaceResizeEvent;
148
158
  pub const GpuSurfaceInputKind = platform.GpuSurfaceInputKind;
149
159
  pub const GpuSurfaceInputEvent = platform.GpuSurfaceInputEvent;
160
+ pub const PinchPhase = platform.PinchPhase;
161
+ pub const PinchEvent = platform.PinchEvent;
150
162
  pub const FileFilter = platform.FileFilter;
151
163
  pub const OpenDialogOptions = platform.OpenDialogOptions;
152
164
  pub const OpenDialogResult = platform.OpenDialogResult;
@@ -384,6 +384,21 @@ pub fn App(comptime Runtime: type) type {
384
384
 
385
385
  pub const Options = struct {
386
386
  platform: platform.Platform,
387
+ /// Allocator for the runtime's on-demand storage (registered
388
+ /// canvas font bytes, sized per file at registration; registered
389
+ /// canvas image slot buffers, one slot-budget buffer per used slot
390
+ /// allocated at the slot's first registration; and adopted
391
+ /// media-surface texture buffers, one frame-budget buffer per
392
+ /// texture entry allocated at first adoption — a runtime with no
393
+ /// registered fonts, no registered images, and no media producers
394
+ /// allocates nothing; the fixed-capacity per-view storage stays
395
+ /// embedded in the Runtime struct). The default suits process-lifetime runtimes; embedders
396
+ /// that create and destroy runtimes in one process (tests, the docs
397
+ /// wasm preview host) pass their own and call `Runtime.deinit`. The
398
+ /// runtime captures this into its `owned_allocator` at init:
399
+ /// mutating `options.allocator` on a live runtime retargets
400
+ /// nothing — pick the owning allocator here, before init.
401
+ allocator: std.mem.Allocator = std.heap.page_allocator,
387
402
  trace_sink: ?trace.Sink = null,
388
403
  log_path: ?[]const u8 = null,
389
404
  extensions: ?extensions.ModuleRegistry = null,
@@ -58,6 +58,21 @@ pub const AutomationWidgetKey = struct {
58
58
  modifiers: AutomationKeyModifiers = .{},
59
59
  };
60
60
 
61
+ /// `widget-pinch <view-label> <scale> [<x> <y>]`: a trackpad pinch
62
+ /// gesture against a gpu-surface view. `scale` is the FINAL
63
+ /// multiplicative zoom for the gesture (1.5 zooms in 50%, 0.5 zooms out
64
+ /// to half) — the dispatch synthesizes begin, one change carrying
65
+ /// `scale - 1`, and end, so the product of `(1 + delta)` lands exactly
66
+ /// on `scale`. The optional
67
+ /// anchor point is view-local canvas points (where the zoom anchors,
68
+ /// like the pointer position under a real pinch); omitted, it defaults
69
+ /// to the view center.
70
+ pub const AutomationWidgetPinch = struct {
71
+ view_label: []const u8,
72
+ scale: f32,
73
+ point: ?geometry.PointF = null,
74
+ };
75
+
61
76
  /// Modifier chord for automation key dispatch, mirroring
62
77
  /// `platform.ShortcutModifiers` field-for-field (automation stays
63
78
  /// platform-agnostic; the dispatch layer copies these across).
@@ -261,6 +276,24 @@ pub fn parseAutomationWidgetKey(value: []const u8) !AutomationWidgetKey {
261
276
  return .{ .view_label = view.token, .key = chord.key, .text = text, .modifiers = chord.modifiers };
262
277
  }
263
278
 
279
+ pub fn parseAutomationWidgetPinch(value: []const u8) !AutomationWidgetPinch {
280
+ const view = takeAutomationToken(value) orelse return error.InvalidCommand;
281
+ const scale_part = takeAutomationToken(view.rest) orelse return error.InvalidCommand;
282
+ const scale = std.fmt.parseFloat(f32, scale_part.token) catch return error.InvalidCommand;
283
+ // A non-positive cumulative scale is not a gesture two fingers can
284
+ // perform (the product of 1 + delta stays positive); refuse loudly.
285
+ if (!std.math.isFinite(scale) or scale <= 0) return error.InvalidCommand;
286
+ const x_part = takeAutomationToken(scale_part.rest) orelse {
287
+ return .{ .view_label = view.token, .scale = scale };
288
+ };
289
+ const y_part = takeAutomationToken(x_part.rest) orelse return error.InvalidCommand;
290
+ if (takeAutomationToken(y_part.rest) != null) return error.InvalidCommand;
291
+ const x = std.fmt.parseFloat(f32, x_part.token) catch return error.InvalidCommand;
292
+ const y = std.fmt.parseFloat(f32, y_part.token) catch return error.InvalidCommand;
293
+ if (!std.math.isFinite(x) or !std.math.isFinite(y)) return error.InvalidCommand;
294
+ return .{ .view_label = view.token, .scale = scale, .point = geometry.PointF.init(x, y) };
295
+ }
296
+
264
297
  pub fn parseAutomationWidgetPointerDrag(value: []const u8) !AutomationWidgetPointerDrag {
265
298
  const view = takeAutomationToken(value) orelse return error.InvalidCommand;
266
299
  const id_part = takeAutomationToken(view.rest) orelse return error.InvalidCommand;
@@ -284,6 +284,70 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
284
284
  } });
285
285
  }
286
286
 
287
+ /// Drive a trackpad pinch through the real platform-event path:
288
+ /// `pinch_begin`, one `pinch_change` carrying `scale - 1` (so
289
+ /// the cumulative product of `1 + delta` lands exactly on the
290
+ /// commanded scale — the gesture's FINAL multiplicative zoom),
291
+ /// and `pinch_end`, all at the same anchor point. A scale so
292
+ /// small its f32 delta rounds to -1 (factor 0 on the wire) is
293
+ /// refused as `PinchScaleBelowWireMinimum` — see the guard
294
+ /// below for the named minimum.
295
+ /// Plain input synthesis, the `widget-key` discipline: every
296
+ /// event journals as itself and replays through the same
297
+ /// dispatch — no accessibility-action record, because pinch is
298
+ /// not a widget verb (it never routes into the widget tree; the
299
+ /// app hears it through the pinch channel).
300
+ pub fn dispatchAutomationWidgetPinch(self: *Runtime, app: runtime_api.App(Runtime), pinch: automation_commands.AutomationWidgetPinch) anyerror!void {
301
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, pinch.view_label);
302
+ const window_id = self.views[view_index].window_id;
303
+ const label = self.views[view_index].label;
304
+ const point = pinch.point orelse geometry.PointF.init(
305
+ self.views[view_index].gpu_size.width / 2,
306
+ self.views[view_index].gpu_size.height / 2,
307
+ );
308
+ // The wire delta is `scale - 1` in f32, and f32 rounding can
309
+ // betray the parser's `scale > 0` guard: any scale at or
310
+ // below 2^-25 rounds the difference to exactly -1
311
+ // (ties-to-even at the halfway point), which would put the
312
+ // factor `1 + delta = 0` on the wire — a zoom through zero
313
+ // scale, which no gesture can perform and no downstream
314
+ // product can recover from. The invariant is the WIRE's
315
+ // (every emitted factor stays > 0), so validate the computed
316
+ // delta, not the input; the minimum accepted scale is the
317
+ // smallest f32 above 2^-25 (~2.9802326e-8), whose delta
318
+ // rounds to -1 + 2^-24 — the smallest positive factor the
319
+ // wire can carry. Refused before anything dispatches, so no
320
+ // partial gesture reaches the journal.
321
+ const delta = pinch.scale - 1;
322
+ if (1 + delta <= 0) return error.PinchScaleBelowWireMinimum;
323
+ const timestamp_ns = automationInputTimestampNs();
324
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
325
+ .window_id = window_id,
326
+ .label = label,
327
+ .kind = .pinch_begin,
328
+ .timestamp_ns = timestamp_ns,
329
+ .x = point.x,
330
+ .y = point.y,
331
+ } });
332
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
333
+ .window_id = window_id,
334
+ .label = label,
335
+ .kind = .pinch_change,
336
+ .timestamp_ns = timestamp_ns,
337
+ .x = point.x,
338
+ .y = point.y,
339
+ .scale = delta,
340
+ } });
341
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
342
+ .window_id = window_id,
343
+ .label = label,
344
+ .kind = .pinch_end,
345
+ .timestamp_ns = timestamp_ns,
346
+ .x = point.x,
347
+ .y = point.y,
348
+ } });
349
+ }
350
+
287
351
  pub fn dispatchAutomationWidgetPointerDrag(self: *Runtime, app: runtime_api.App(Runtime), drag: AutomationWidgetPointerDrag) anyerror!void {
288
352
  const view_index = try automationWidgetTargetViewIndex(self, drag.target);
289
353
  const layout = self.views[view_index].widgetLayoutTree();
@@ -110,6 +110,13 @@ pub fn platformFeatureFromString(value: []const u8) ?platform.PlatformFeature {
110
110
  if (std.mem.eql(u8, value, "fileDrops")) return .file_drops;
111
111
  if (std.mem.eql(u8, value, "appActivationEvents")) return .app_activation_events;
112
112
  if (std.mem.eql(u8, value, "gpuSurfaces")) return .gpu_surfaces;
113
+ if (std.mem.eql(u8, value, "gpuSurfaceScrollDrivers")) return .gpu_surface_scroll_drivers;
114
+ if (std.mem.eql(u8, value, "contextMenus")) return .context_menus;
115
+ if (std.mem.eql(u8, value, "viewSurfaceAdoption")) return .view_surface_adoption;
116
+ if (std.mem.eql(u8, value, "audioPlayback")) return .audio_playback;
117
+ if (std.mem.eql(u8, value, "audioStreaming")) return .audio_streaming;
118
+ if (std.mem.eql(u8, value, "audioSpectrum")) return .audio_spectrum;
119
+ if (std.mem.eql(u8, value, "windowHideOnClose")) return .window_hide_on_close;
113
120
  return null;
114
121
  }
115
122
 
@@ -275,6 +275,11 @@ pub fn writeWindowJsonToWriter(window: platform.WindowInfo, writer: anytype) !vo
275
275
  try writer.writeAll(if (window.open) "true" else "false");
276
276
  try writer.writeAll(",\"focused\":");
277
277
  try writer.writeAll(if (window.focused) "true" else "false");
278
+ // Alive-but-policy-hidden rides beside open/focused: without it a JS
279
+ // consumer cannot tell a close_policy = "hide" window (open:true,
280
+ // focused:false) from a visible unfocused one.
281
+ try writer.writeAll(",\"hidden\":");
282
+ try writer.writeAll(if (window.hidden) "true" else "false");
278
283
  try writer.print(",\"x\":{d},\"y\":{d},\"width\":{d},\"height\":{d},\"scale\":{d}", .{
279
284
  window.frame.x,
280
285
  window.frame.y,
@@ -530,11 +530,16 @@ pub fn RuntimeBuiltinBridge(comptime Runtime: type) type {
530
530
  var storage = json.StringStorage.init(output);
531
531
  const window_id = try Self.resolveWindowSelector(self, payload, &storage);
532
532
  const index = WindowViewMethods.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
533
- var info = self.windows[index].info;
534
- info.open = false;
535
- info.focused = false;
536
533
  try self.closeWindow(window_id);
537
- return writeWindowJson(info, output);
534
+ // The response serializes the TABLE state after the close,
535
+ // never a hand-cleared copy: closeWindow owns which flags a
536
+ // close clears (open, focused, AND hidden — a closed
537
+ // policy-hidden window is gone, not "hidden"), and a copy
538
+ // maintained here field-by-field silently drifts every time
539
+ // that set grows. The index stays valid: a closed window
540
+ // keeps its table slot — slots only compact inside window
541
+ // create, when a dead slot's id or label is re-used.
542
+ return writeWindowJson(self.windows[index].info, output);
538
543
  }
539
544
 
540
545
  pub fn resolveWindowSelector(self: *Runtime, payload: []const u8, storage: *json.StringStorage) !platform.WindowId {