@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.
Files changed (182) hide show
  1. package/build/app.zig +73 -37
  2. package/build.zig +239 -5
  3. package/native-sdk.d.ts +5 -1
  4. package/package.json +13 -12
  5. package/packages/core/compile-surface/core.ts +30 -0
  6. package/packages/core/package-lock.json +6 -6
  7. package/packages/core/package.json +3 -3
  8. package/packages/core/scripts/scriptc-toolchain.json +44 -44
  9. package/packages/core/scripts/stage_external_core.mjs +27 -16
  10. package/packages/core/sdk/core.d.ts +24 -1
  11. package/packages/core/sdk/core.ts +51 -1
  12. package/packages/core/sdk/events.d.ts +5 -0
  13. package/packages/core/sdk/events.ts +10 -0
  14. package/packages/core/src/bridge_descriptors.ts +3 -3
  15. package/packages/core/src/checker.ts +20 -0
  16. package/packages/core/src/cli.ts +2 -11
  17. package/packages/core/src/context_menus.ts +76 -0
  18. package/packages/core/src/diagnostics.ts +7 -0
  19. package/packages/core/src/extent_program.ts +53 -0
  20. package/packages/core/src/frontend.ts +12 -10
  21. package/packages/core/src/markup_canonical.ts +140 -0
  22. package/packages/core/src/markup_construction.ts +189 -0
  23. package/packages/core/src/markup_display.ts +43 -0
  24. package/packages/core/src/markup_document.ts +226 -0
  25. package/packages/core/src/markup_elements.ts +225 -0
  26. package/packages/core/src/markup_expressions.ts +79 -0
  27. package/packages/core/src/markup_imports.ts +146 -0
  28. package/packages/core/src/markup_parser.ts +228 -0
  29. package/packages/core/src/markup_runtime.ts +93 -0
  30. package/packages/core/src/markup_scalars.ts +143 -0
  31. package/packages/core/src/markup_shapes.ts +243 -0
  32. package/packages/core/src/markup_specialized.ts +242 -0
  33. package/packages/core/src/markup_text.ts +86 -0
  34. package/packages/core/src/markup_values.ts +336 -0
  35. package/packages/core/src/portable_sources.json +24 -0
  36. package/packages/core/src/registered_font.ts +2 -3
  37. package/packages/core/src/runtime_policy.ts +24 -0
  38. package/packages/core/src/scalar_text.ts +1 -3
  39. package/packages/core/src/scroll_mutation.ts +86 -0
  40. package/packages/core/src/scroll_tree.ts +86 -0
  41. package/packages/core/src/service_contract.ts +53 -2
  42. package/packages/core/src/sqlite_cli.ts +3 -46
  43. package/packages/core/src/sqlite_codegen.ts +84 -0
  44. package/packages/core/src/staged_rebuild.ts +60 -0
  45. package/packages/core/src/view_bridge.ts +161 -0
  46. package/packages/core/src/view_check.ts +145 -0
  47. package/packages/core/src/view_evaluator.ts +823 -0
  48. package/packages/core/src/view_frontend.ts +340 -218
  49. package/packages/core/src/view_program.ts +221 -0
  50. package/packages/core/src/view_reload.ts +166 -0
  51. package/packages/core/src/view_reload_watch.ts +98 -0
  52. package/packages/core/src/view_sources.ts +34 -0
  53. package/packages/core/src/virtual_windows.ts +88 -0
  54. package/packages/core/src/web_panes.ts +67 -0
  55. package/packages/core/src/widget_continuity.ts +37 -0
  56. package/packages/core/src/widget_reconcile.ts +63 -0
  57. package/packages/core/src/widget_retention.ts +62 -0
  58. package/skill-data/native-ui/SKILL.md +2 -2
  59. package/skill-data/ts-core/SKILL.md +5 -3
  60. package/skill-data/ts-services/references/service-surface.md +29 -5
  61. package/src/app_runner/root.zig +14 -0
  62. package/src/app_runner/ts_compiled_view.zig +88 -17
  63. package/src/app_runner/ts_core_main.zig +43 -5
  64. package/src/app_runner/ts_core_mobile.zig +1 -1
  65. package/src/automation/server.zig +56 -3
  66. package/src/embed/host.zig +2 -0
  67. package/src/embed/tests.zig +2 -0
  68. package/src/embed/ui_host.zig +2 -0
  69. package/src/platform/keyboard_input.zig +32 -0
  70. package/src/platform/linux/root.zig +2 -0
  71. package/src/platform/macos/appkit_host.h +7 -2
  72. package/src/platform/macos/appkit_host.m +31 -9
  73. package/src/platform/macos/cef_host.mm +15 -1
  74. package/src/platform/macos/global_shortcuts.zig +138 -0
  75. package/src/platform/macos/key_codes.zig +102 -0
  76. package/src/platform/macos/keyboard_input.zig +81 -0
  77. package/src/platform/macos/root.zig +25 -3
  78. package/src/platform/macos/webview_inspection_test.m +106 -0
  79. package/src/platform/null_platform.zig +104 -0
  80. package/src/platform/root.zig +14 -0
  81. package/src/platform/types.zig +102 -0
  82. package/src/platform/windows/global_shortcuts.zig +157 -0
  83. package/src/platform/windows/key_codes.zig +63 -0
  84. package/src/platform/windows/keyboard_input.zig +136 -0
  85. package/src/platform/windows/root.zig +15 -0
  86. package/src/primitives/canvas/decision_reuse.zig +133 -0
  87. package/src/primitives/canvas/font_ttf.zig +27 -3
  88. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  89. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  90. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  91. package/src/primitives/canvas/fonts/README.md +15 -0
  92. package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
  93. package/src/primitives/canvas/markdown_tests.zig +3 -3
  94. package/src/primitives/canvas/reference.zig +3 -5
  95. package/src/primitives/canvas/reference_tests.zig +58 -0
  96. package/src/primitives/canvas/registered_font_policy.zig +1 -1
  97. package/src/primitives/canvas/root.zig +7 -4
  98. package/src/primitives/canvas/text_metrics.zig +32 -39
  99. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  100. package/src/primitives/canvas/text_query_policy.zig +142 -3
  101. package/src/primitives/canvas/text_scalar_policy.zig +80 -2
  102. package/src/primitives/canvas/tokens.zig +9 -0
  103. package/src/primitives/canvas/ui.zig +1 -0
  104. package/src/primitives/canvas/ui_markup.zig +69 -14
  105. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  106. package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
  107. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  108. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  109. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  110. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  111. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  112. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  113. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  114. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  115. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  116. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  117. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  118. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  119. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  120. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  121. package/src/primitives/canvas/ui_markup_view.zig +2817 -74
  122. package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
  123. package/src/primitives/canvas/virtual_extents.zig +47 -33
  124. package/src/primitives/canvas/widget_metric_policy.zig +4 -1
  125. package/src/primitives/canvas/widget_runtime.zig +2 -1
  126. package/src/root.zig +5 -0
  127. package/src/runtime/api.zig +1 -0
  128. package/src/runtime/bridge_descriptor_policy.zig +1 -1
  129. package/src/runtime/bridge_payload.zig +2 -0
  130. package/src/runtime/canvas_widget_context_menu.zig +179 -0
  131. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  132. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  133. package/src/runtime/canvas_widget_runtime.zig +306 -92
  134. package/src/runtime/context_menu_policy.zig +112 -0
  135. package/src/runtime/core.zig +14 -0
  136. package/src/runtime/effects.zig +172 -4
  137. package/src/runtime/effects_host_tests.zig +25 -0
  138. package/src/runtime/flow.zig +1 -0
  139. package/src/runtime/flow_reference.zig +1 -0
  140. package/src/runtime/global_shortcuts.zig +75 -0
  141. package/src/runtime/keyboard_input.zig +86 -0
  142. package/src/runtime/root.zig +3 -0
  143. package/src/runtime/scroll_mutation_policy.zig +130 -0
  144. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  145. package/src/runtime/scroll_tree_policy.zig +99 -0
  146. package/src/runtime/session_record.zig +7 -0
  147. package/src/runtime/staged_rebuild_policy.zig +83 -0
  148. package/src/runtime/system_services.zig +19 -0
  149. package/src/runtime/tests.zig +1 -0
  150. package/src/runtime/ts_core_host.zig +126 -0
  151. package/src/runtime/ts_ui_app.zig +24 -0
  152. package/src/runtime/ui_app.zig +274 -31
  153. package/src/runtime/ui_app_tests.zig +48 -179
  154. package/src/runtime/ui_app_window_tests.zig +133 -0
  155. package/src/runtime/view_reload.zig +226 -0
  156. package/src/runtime/view_widget_scroll.zig +30 -21
  157. package/src/runtime/view_widget_tree.zig +43 -13
  158. package/src/runtime/virtual_window_policy.zig +128 -0
  159. package/src/runtime/web_pane_policy.zig +111 -0
  160. package/src/runtime/web_pane_test_cases.zig +204 -0
  161. package/src/runtime/widget_continuity_policy.zig +73 -0
  162. package/src/runtime/widget_reconcile_policy.zig +81 -0
  163. package/src/runtime/widget_retention_policy.zig +75 -0
  164. package/src/runtime/window_views.zig +19 -4
  165. package/src/security/root.zig +1 -0
  166. package/src/tooling/templates.zig +8 -0
  167. package/src/tooling/ts_core.zig +84 -1
  168. package/src/tooling/verbs.zig +79 -15
  169. package/tools/corewire/core.test.ts +25 -3
  170. package/tools/corewire/core_abi.zig +4 -0
  171. package/tools/corewire/core_contract.ts +1 -1
  172. package/tools/corewire/core_goldens.json +75 -75
  173. package/tools/corewire/core_projection.ts +3 -2
  174. package/tools/corewire/emit_mirror.ts +19 -9
  175. package/tools/corewire/facade_templates.ts +1 -1
  176. package/tools/corewire/intake.test.ts +4 -0
  177. package/tools/corewire/intake_goldens.json +50 -50
  178. package/tools/corewire/invocation.test.ts +4 -0
  179. package/tools/corewire/invocation_goldens.json +3 -3
  180. package/tools/corewire/mirror_templates.ts +4 -0
  181. package/tools/corewire/profile_emission.ts +2 -0
  182. package/tools/corewire/sidecar.zig +2 -0
@@ -1,6 +1,10 @@
1
1
  const std = @import("std");
2
2
  const surface = @import("surface_layout_policy.zig");
3
3
  pub const Policy = surface.Policy;
4
+ /// Host f32 clamp zero-sign capability shared by virtual range consumers.
5
+ pub fn numericFlags() u8 {
6
+ return surface.anchorFlags(0, false) >> 3;
7
+ }
4
8
  pub const Measurement = struct { physical: usize, extent: f32 };
5
9
  pub const SyncPlan = struct { mode: u8, flags: u8, gap: f32, old_total: f32, first_chunk: usize, shift: usize };
6
10
 
@@ -24,6 +28,60 @@ pub fn sync(policy: Policy, table: anytype, args: anytype, old_total: f32) SyncP
24
28
  return .{ .mode = result[0], .flags = result[1], .gap = getFloat(&result, 4), .old_total = getFloat(&result, 8), .first_chunk = getInt(&result, 16), .shift = getInt(&result, 24) };
25
29
  }
26
30
 
31
+ /// Owned copy of a bounded program. Each instruction names a storage or
32
+ /// existing compiled-arithmetic capability; native code never chooses order.
33
+ pub const Program = struct {
34
+ bytes: [224]u8,
35
+ count: usize,
36
+ flags: u8,
37
+ gap: f32,
38
+ pub const Instruction = struct { kind: u32, argument: usize };
39
+ pub fn instruction(self: *const Program, index: usize) Instruction {
40
+ std.debug.assert(index < self.count);
41
+ const at = 16 + index * 16;
42
+ return .{ .kind = getWord(&self.bytes, at), .argument = getInt(&self.bytes, at + 8) };
43
+ }
44
+ };
45
+ fn program(policy: Policy, request: []const u8) Program {
46
+ var out: Program = undefined;
47
+ const length = policy(request, &out.bytes);
48
+ if (length < 16 or length > out.bytes.len or getWord(&out.bytes, 0) > 7 or getWord(&out.bytes, 12) != 0)
49
+ @panic("invalid extent capability program");
50
+ out.count = getWord(&out.bytes, 8);
51
+ out.flags = @intCast(getWord(&out.bytes, 0));
52
+ out.gap = getFloat(&out.bytes, 4);
53
+ if (out.count > 13 or length != 16 + out.count * 16) @panic("invalid extent program length");
54
+ for (0..out.count) |i| {
55
+ const at = 16 + i * 16;
56
+ const action = out.instruction(i);
57
+ if (getWord(&out.bytes, at + 4) != 0 or action.kind > 13 or
58
+ (request[1] == 0 and action.kind > 11) or
59
+ (request[1] == 1 and action.kind < 12) or
60
+ (action.kind != 5 and action.kind != 8 and action.kind != 13 and action.argument != 0) or
61
+ (action.kind == 13 and action.argument > 3)) @panic("invalid extent program capability");
62
+ }
63
+ return out;
64
+ }
65
+ pub fn syncProgram(policy: Policy, table: anytype, args: anytype) Program {
66
+ var request = header(72, 0);
67
+ request[0] = 100;
68
+ request[2] = @intFromBool(table.measured_prefix_dirty);
69
+ putInt(&request, 8, table.id);
70
+ putInt(&request, 16, args.id);
71
+ putInt(&request, 24, table.item_count);
72
+ putInt(&request, 32, args.item_count);
73
+ putInt(&request, 40, table.index_base);
74
+ putInt(&request, 48, args.index_base);
75
+ putFloat(&request, 56, args.gap);
76
+ return program(policy, &request);
77
+ }
78
+ pub fn correctionProgram(policy: Policy, mode: u8) Program {
79
+ var request = header(16, 1);
80
+ request[0] = 100;
81
+ request[2] = mode;
82
+ return program(policy, &request);
83
+ }
84
+
27
85
  pub fn corrections(policy: Policy, table: anytype, mode: u8, anchor: usize, rendered_offset: ?f32, rows: []const Measurement, estimate_prefix: f32, gap_extent: f32) void {
28
86
  const allocator = std.heap.page_allocator;
29
87
  const request = allocator.alloc(u8, 64 + table.measured_count * 16 + rows.len * 16) catch @panic("extent request allocation failed");
@@ -369,42 +369,58 @@ pub const VirtualExtentTable = struct {
369
369
  }
370
370
 
371
371
  fn syncCompiled(self: *VirtualExtentTable, policy: compiled.Policy, args: VirtualExtentSyncArgs) VirtualExtentSyncInfo {
372
- // Refresh estimate capabilities before reading the previous total,
373
- // matching the native reference's cached/full-partial-chunk behavior.
374
- self.estimate_context = args.estimate_context;
375
- self.estimate_fn = args.estimate_fn;
376
- self.uniform_estimate = args.uniform_estimate;
377
- const old_total = if (self.id == args.id and self.id != 0) self.totalExtent() else 0;
378
- const plan = compiled.sync(policy, self, args, old_total);
379
- if (plan.mode == 1) {
380
- self.reset();
381
- self.estimate_context = args.estimate_context;
382
- self.estimate_fn = args.estimate_fn;
383
- self.uniform_estimate = args.uniform_estimate;
384
- self.id = args.id;
385
- self.chunk_prefix[0] = 0;
372
+ const program = compiled.syncProgram(policy, self, args);
373
+ var old_total: f32 = 0;
374
+ var shift: f32 = 0;
375
+ for (0..program.count) |i| {
376
+ const action = program.instruction(i);
377
+ switch (action.kind) {
378
+ 0 => self.reset(),
379
+ 1 => {
380
+ self.estimate_context = args.estimate_context;
381
+ self.estimate_fn = args.estimate_fn;
382
+ self.uniform_estimate = args.uniform_estimate;
383
+ },
384
+ 2 => old_total = self.totalExtent(),
385
+ 3 => {
386
+ self.id = args.id;
387
+ self.chunk_prefix[0] = 0;
388
+ },
389
+ 4 => self.gap = program.gap,
390
+ 5 => shift = self.offsetAtPhysical(action.argument),
391
+ 6 => {
392
+ self.index_base = args.index_base;
393
+ self.item_count = args.item_count;
394
+ },
395
+ 7 => compiled.corrections(policy, self, 4, self.anchor_physical, null, &.{}, 0, 0),
396
+ 8 => self.rebuildChunkPrefixFrom(action.argument),
397
+ 9 => compiled.corrections(policy, self, 5, self.anchor_physical, null, &.{}, 0, 0),
398
+ 10 => self.pending_offset_delta = compiled.shift(policy, self.pending_offset_delta, shift, false),
399
+ 11 => self.pending_offset_delta = compiled.shift(policy, self.pending_offset_delta, shift, true),
400
+ else => unreachable,
401
+ }
386
402
  }
387
- self.gap = plan.gap;
388
- // Head truncation uses the refreshed callback and NEW sanitized gap
389
- // with the OLD count/base/cache, exactly as the reference does.
390
- const removed_with_gap = if (plan.mode == 3) self.offsetAtPhysical(plan.shift) else 0;
391
- if (plan.mode != 0) {
392
- self.index_base = args.index_base;
393
- self.item_count = args.item_count;
394
- if (plan.mode == 2 or plan.mode == 3 or plan.mode == 5) compiled.corrections(policy, self, 4, self.anchor_physical, null, &.{}, 0, 0);
395
- self.rebuildChunkPrefixFrom(plan.first_chunk);
403
+ return .{ .fresh = program.flags & 1 != 0, .appended = program.flags & 2 != 0, .prepended = program.flags & 4 != 0, .old_total_extent = old_total };
404
+ }
405
+
406
+ fn correctCompiled(self: *VirtualExtentTable, policy: compiled.Policy, mode: u8, anchor: usize, rendered_offset: ?f32, rows: []const VirtualExtentMeasurement) void {
407
+ const program = compiled.correctionProgram(policy, mode);
408
+ var facts = compiled.Query{ .prefix = 0, .gap = 0, .offset = 0 };
409
+ for (0..program.count) |i| {
410
+ const action = program.instruction(i);
411
+ switch (action.kind) {
412
+ 12 => facts = compiled.query(policy, self, anchor, 0),
413
+ 13 => compiled.corrections(policy, self, @intCast(action.argument), anchor, rendered_offset, rows, facts.prefix, facts.gap),
414
+ else => unreachable,
415
+ }
396
416
  }
397
- if (self.measured_prefix_dirty) compiled.corrections(policy, self, 5, self.anchor_physical, null, &.{}, 0, 0);
398
- if (plan.mode == 2 or plan.mode == 3) self.pending_offset_delta = compiled.shift(policy, self.pending_offset_delta, if (plan.mode == 2) self.offsetAtPhysical(plan.shift) else removed_with_gap, plan.mode == 3);
399
- return .{ .fresh = plan.flags & 1 != 0, .appended = plan.flags & 2 != 0, .prepended = plan.flags & 4 != 0, .old_total_extent = plan.old_total };
400
417
  }
401
418
 
402
419
  /// One ordered measurement transfer per mounted window. Single-record
403
420
  /// methods remain available with the same native/compiled ownership.
404
421
  pub fn applyMeasurements(self: *VirtualExtentTable, anchor: usize, rendered_offset: ?f32, rows: []const VirtualExtentMeasurement) void {
405
422
  if (self.policy) |policy| {
406
- const facts = compiled.query(policy, self, anchor, 0);
407
- compiled.corrections(policy, self, 3, anchor, rendered_offset, rows, facts.prefix, facts.gap);
423
+ self.correctCompiled(policy, 3, anchor, rendered_offset, rows);
408
424
  return;
409
425
  }
410
426
  self.beginCorrections(anchor, rendered_offset);
@@ -442,8 +458,7 @@ pub const VirtualExtentTable = struct {
442
458
  pub fn beginCorrections(self: *VirtualExtentTable, anchor_physical: usize, rendered_offset: ?f32) void {
443
459
  std.debug.assert(!self.measured_prefix_dirty);
444
460
  if (self.policy) |policy| {
445
- const facts = compiled.query(policy, self, anchor_physical, 0);
446
- compiled.corrections(policy, self, 0, anchor_physical, rendered_offset, &.{}, facts.prefix, facts.gap);
461
+ self.correctCompiled(policy, 0, anchor_physical, rendered_offset, &.{});
447
462
  return;
448
463
  }
449
464
  self.anchor_physical = @min(anchor_physical, self.item_count);
@@ -458,7 +473,7 @@ pub const VirtualExtentTable = struct {
458
473
  pub fn recordMeasured(self: *VirtualExtentTable, physical: usize, extent: f32) void {
459
474
  if (physical >= self.item_count) return;
460
475
  if (self.policy) |policy| {
461
- compiled.corrections(policy, self, 1, self.anchor_physical, null, &.{.{ .physical = physical, .extent = extent }}, 0, 0);
476
+ self.correctCompiled(policy, 1, self.anchor_physical, null, &.{.{ .physical = physical, .extent = extent }});
462
477
  return;
463
478
  }
464
479
  const logical = self.index_base + @as(u64, physical);
@@ -510,8 +525,7 @@ pub const VirtualExtentTable = struct {
510
525
  /// where the user sees it.
511
526
  pub fn endCorrections(self: *VirtualExtentTable) void {
512
527
  if (self.policy) |policy| {
513
- const facts = compiled.query(policy, self, self.anchor_physical, 0);
514
- compiled.corrections(policy, self, 2, self.anchor_physical, null, &.{}, facts.prefix, facts.gap);
528
+ self.correctCompiled(policy, 2, self.anchor_physical, null, &.{});
515
529
  return;
516
530
  }
517
531
  if (self.measured_prefix_dirty) self.rebuildMeasuredPrefix();
@@ -28,6 +28,9 @@ pub const Result = struct {
28
28
  return .init(float(&self.bytes, 8), float(&self.bytes, 12), float(&self.bytes, 16), float(&self.bytes, 20));
29
29
  }
30
30
  };
31
+ /// Each continuation step is a pure function of the request bytes, and every
32
+ /// step's measurement is computed again before the next request is formed.
33
+ const metric_decisions = @import("decision_reuse.zig").Table(512, 224, @sizeOf(Result));
31
34
  pub const Request = struct {
32
35
  bytes: [224]u8 = @splat(0),
33
36
  pub fn init(op: Operation, widget: widgets.Widget, tokens: tokens_model.DesignTokens, base: f32) Request {
@@ -60,7 +63,7 @@ pub const Request = struct {
60
63
  const policy = tokens.control_geometry_policy orelse @panic("missing widget metric owner");
61
64
  for (0..3) |_| {
62
65
  var copied: Result = .{ .bytes = @splat(0xa5) };
63
- if (policy(&self.bytes, &copied.bytes) != copied.bytes.len or read(&copied.bytes, 0) != 1) @panic("invalid compiled widget metric length");
66
+ if (metric_decisions.decide(policy, &self.bytes, &copied.bytes) != copied.bytes.len or read(&copied.bytes, 0) != 1) @panic("invalid compiled widget metric length");
64
67
  const mode = read(&copied.bytes, 4);
65
68
  const ranges: []const [2]usize = switch (mode) {
66
69
  1 => &.{.{ 12, 32 }},
@@ -73,6 +73,7 @@ pub const WidgetLayoutTree = struct {
73
73
  routing_policy: ?@import("widget_routing_policy.zig").Policy = null,
74
74
  /// Explicit retained-change owner, independent of input routing.
75
75
  change_policy: ?@import("widget_change_policy.zig").Policy = null,
76
+ retention_policy: ?*const fn ([]const u8, []u8) usize = null,
76
77
  /// Text decisions must reach reconciliation before display tokens arrive.
77
78
  text_run_policy: ?@import("text_document_policy.zig").Policy = null,
78
79
  paint_policy: ?@import("widget_paint_policy.zig").Policy = null,
@@ -231,7 +232,7 @@ pub fn layoutWidgetTreeWithTokens(widget: Widget, bounds: geometry.RectF, tokens
231
232
  const root_bounds = bounds.normalized();
232
233
  var len: usize = 0;
233
234
  _ = try widget_layout.layoutWidgetDepth(widget, root_bounds, null, 0, output, &len, tokens);
234
- return .{ .nodes = output[0..len], .root_bounds = root_bounds, .semantic_policy = tokens.intrinsic_layout_policy, .audit_policy = tokens.widget_audit_policy, .routing_policy = tokens.widget_routing_policy, .change_policy = tokens.widget_change_policy, .text_run_policy = tokens.text_run_policy, .paint_policy = tokens.widget_paint_policy, .presentation_policy = tokens.widget_presentation_policy, .paint_walk_policy = tokens.widget_paint_walk_policy };
235
+ return .{ .nodes = output[0..len], .root_bounds = root_bounds, .semantic_policy = tokens.intrinsic_layout_policy, .audit_policy = tokens.widget_audit_policy, .routing_policy = tokens.widget_routing_policy, .change_policy = tokens.widget_change_policy, .retention_policy = tokens.widget_retention_policy, .text_run_policy = tokens.text_run_policy, .paint_policy = tokens.widget_paint_policy, .presentation_policy = tokens.widget_presentation_policy, .paint_walk_policy = tokens.widget_paint_walk_policy };
235
236
  }
236
237
 
237
238
  pub fn intrinsicWidgetSize(widget: Widget, tokens: DesignTokens) geometry.SizeF {
package/src/root.zig CHANGED
@@ -136,6 +136,8 @@ pub const EffectAudioEventKind = runtime.EffectAudioEventKind;
136
136
  pub const EffectAudioCaptureEvent = runtime.EffectAudioCaptureEvent;
137
137
  pub const EffectAudioCaptureEventKind = runtime.EffectAudioCaptureEventKind;
138
138
  pub const decodeAudioCaptureChannelEvent = runtime.decodeAudioCaptureChannelEvent;
139
+ pub const EffectGlobalShortcutEvent = runtime.EffectGlobalShortcutEvent;
140
+ pub const EffectGlobalShortcutEventKind = runtime.EffectGlobalShortcutEventKind;
139
141
  pub const EffectAudioSource = runtime.EffectAudioSource;
140
142
  pub const audioCachePath = runtime.audioCachePath;
141
143
  pub const max_effect_audio_path_bytes = runtime.max_effect_audio_path_bytes;
@@ -180,6 +182,7 @@ pub const TsCoreHost = runtime.TsCoreHost;
180
182
  pub const TsCoreHostWithRuntimeModel = runtime.TsCoreHostWithRuntimeModel;
181
183
  pub const TsUiApp = runtime.TsUiApp;
182
184
  pub const TsUiAppWithFeatures = runtime.TsUiAppWithFeatures;
185
+ pub const view_reload = runtime.view_reload;
183
186
  pub const Clock = runtime.Clock;
184
187
  pub const TestClock = runtime.TestClock;
185
188
  pub const nowMs = runtime.nowMs;
@@ -252,6 +255,8 @@ pub const MenuItem = platform.MenuItem;
252
255
  pub const Shortcut = platform.Shortcut;
253
256
  pub const ShortcutModifiers = platform.ShortcutModifiers;
254
257
  pub const ShortcutEvent = platform.ShortcutEvent;
258
+ pub const KeyChord = platform.KeyChord;
259
+ pub const KeyboardInputAccess = platform.KeyboardInputAccess;
255
260
  pub const TimerEvent = platform.TimerEvent;
256
261
  pub const reserved_timer_id_base = platform.reserved_timer_id_base;
257
262
  pub const ColorScheme = platform.ColorScheme;
@@ -445,6 +445,7 @@ pub fn App(comptime Runtime: type) type {
445
445
  /// Portable command routing and status-item selection. Native retains
446
446
  /// registry bytes, exact handles and OS capability execution.
447
447
  command_policy: ?*const fn ([]const u8, []u8) usize = null,
448
+ context_menu_policy: ?*const fn ([]const u8, []u8) usize = null,
448
449
  text_cache_policy: ?*const fn ([]const u8, []u8) usize = null,
449
450
  render_cache_policy: ?*const fn ([]const u8, []u8) usize = null,
450
451
  render_plan_policy: ?*const fn ([]const u8, []u8) usize = null,
@@ -66,7 +66,7 @@ fn enumType(comptime family: Family) type {
66
66
  }
67
67
  comptime {
68
68
  // Keep ordinal transport tied to the independently tested native vocabulary.
69
- for (.{ .view, .titlebar, .backend, .pixel_format, .present_mode, .alpha_mode, .color_space, .feature }, .{ 19, 4, 4, 2, 2, 3, 3, 28 }) |family, count| {
69
+ for (.{ .view, .titlebar, .backend, .pixel_format, .present_mode, .alpha_mode, .color_space, .feature }, .{ 19, 4, 4, 2, 2, 3, 3, 30 }) |family, count| {
70
70
  if (@typeInfo(enumType(family)).@"enum".fields.len != count) @compileError("update bridge descriptor vocabulary");
71
71
  }
72
72
  }
@@ -129,6 +129,8 @@ pub fn platformFeatureFromString(value: []const u8) ?platform.PlatformFeature {
129
129
  if (std.mem.eql(u8, value, "systemAudioCapture")) return .system_audio_capture;
130
130
  if (std.mem.eql(u8, value, "windowHideOnClose")) return .window_hide_on_close;
131
131
  if (std.mem.eql(u8, value, "videoPlayback")) return .video_playback;
132
+ if (std.mem.eql(u8, value, "globalShortcuts")) return .global_shortcuts;
133
+ if (std.mem.eql(u8, value, "keyboardInput")) return .keyboard_input;
132
134
  return null;
133
135
  }
134
136
 
@@ -34,6 +34,8 @@ const canvas_limits = @import("canvas_limits.zig");
34
34
  const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
35
35
  const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
36
36
 
37
+ const menu_policy = @import("context_menu_policy.zig");
38
+
37
39
  const context_menu_log = std.log.scoped(.zero_context_menu);
38
40
 
39
41
  const CanvasWidgetContextMenuTextScratch = struct {
@@ -190,6 +192,50 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
190
192
  return;
191
193
  }
192
194
 
195
+ if (self.context_menu_policy) |policy| {
196
+ var facts = menu_policy.Facts{ .flags = if (has_presenter) 16 else 0 };
197
+ facts.selected = self.views[index].canvas_widget_selected_text_id;
198
+ if (pointer_event.target) |target| {
199
+ const node_index = self.views[index].canvasWidgetNodeIndexById(target.id) orelse return;
200
+ const widget = self.views[index].widget_layout_nodes[node_index].widget;
201
+ facts.target = target.id;
202
+ facts.flags |= 1 | (if (canvas_widget_runtime.canvasWidgetEditableTextKind(widget.kind)) @as(u32, 2) else 0) |
203
+ (if (widget.state.disabled) @as(u32, 4) else 0) | (if (widget.kind == .terminal) @as(u32, 8) else 0);
204
+ const clipboard = canvas.widgetTextClipboardState(widget);
205
+ facts.flags |= (if (clipboard.selection != null) @as(u32, 32) else 0) | (if (clipboard.select_all) @as(u32, 64) else 0);
206
+ if (widget.terminal.grid) |grid| facts.flags |= (if (grid.selection_active) @as(u32, 128) else 0) |
207
+ (if (widget.terminal.pty != 0 and grid.running) @as(u32, 256) else 0);
208
+ if (self.views[index].canvasWidgetNodeIndexById(facts.selected)) |selected| {
209
+ facts.flags |= 1024;
210
+ facts.selected_group = self.views[index].widget_layout_nodes[selected].widget.static_text_group_id;
211
+ facts.target_group = widget.static_text_group_id;
212
+ }
213
+ }
214
+ const plan = menu_policy.presentation(policy, facts);
215
+ switch (plan.kind) {
216
+ .none => return,
217
+ .hold => try self.dispatchEvent(app, .{ .canvas_widget_context_press = .{
218
+ .window_id = input_event.window_id,
219
+ .view_label = self.views[index].label,
220
+ .press_target = pointer_event.press_target,
221
+ } }),
222
+ .edit_text, .terminal, .static_copy => {
223
+ if (plan.kind != .static_copy) try CanvasWidgetEventMethods().updateCanvasWidgetFocusFromPointer(self, pointer_event);
224
+ _ = try showMenu(self, app, index, .{
225
+ .window_id = input_event.window_id,
226
+ .target_id = facts.target,
227
+ .kind = switch (plan.kind) {
228
+ .edit_text => .edit_text,
229
+ .terminal => .terminal,
230
+ .static_copy => .static_copy,
231
+ else => unreachable,
232
+ },
233
+ }, point, plan.items[0..plan.count]);
234
+ },
235
+ }
236
+ return;
237
+ }
238
+
193
239
  // 2/3. Editable text and terminal targets: standard menus
194
240
  // wired to the existing clipboard and committed-input
195
241
  // paths. Focus the target first so paste lands where the
@@ -275,6 +321,17 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
275
321
  /// dispatch is fallible, and the runtime's bookkeeping must
276
322
  /// already match the menu the platform accepted.
277
323
  pub fn notifySupersededPending(self: *Runtime, app: runtime_api.App(Runtime), superseded: ?PendingCanvasWidgetContextMenu) anyerror!void {
324
+ if (self.context_menu_policy) |policy| {
325
+ if (menu_policy.notice(policy, if (superseded) |old| policyKind(old.kind) else null)) {
326
+ const pending = superseded.?;
327
+ try self.dispatchEvent(app, .{ .canvas_widget_context_menu_dismissed = .{
328
+ .window_id = pending.window_id,
329
+ .view_label = pending.viewLabel(),
330
+ .token = pending.token,
331
+ } });
332
+ }
333
+ return;
334
+ }
278
335
  const pending = superseded orelse return;
279
336
  if (pending.kind != .app) return;
280
337
  try self.dispatchEvent(app, .{ .canvas_widget_context_menu_dismissed = .{
@@ -342,6 +399,20 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
342
399
  const superseded = self.canvas_widget_context_menu_pending;
343
400
  self.canvas_widget_context_menu_pending = pending;
344
401
  try notifySupersededPending(self, app, superseded);
402
+ if (self.context_menu_policy) |policy| {
403
+ const current = if (self.canvas_widget_context_menu_pending) |value| value.token else null;
404
+ // A successor must be admitted before asking about the view:
405
+ // dismissal callbacks may replace requests and compact views.
406
+ if (menu_policy.continuation(policy, pending.token, current, true) == .superseded) return .superseded;
407
+ switch (menu_policy.continuation(policy, pending.token, current, runtimeFindViewIndex(self, pending.window_id, pending.viewLabel()) != null)) {
408
+ .superseded => return .superseded,
409
+ .view_closed => {
410
+ self.canvas_widget_context_menu_pending = null;
411
+ return .view_closed;
412
+ },
413
+ .shown => return .{ .shown = pending },
414
+ }
415
+ }
345
416
  const still_armed = if (self.canvas_widget_context_menu_pending) |current| current.token == pending.token else false;
346
417
  if (!still_armed) return .superseded;
347
418
  // Still armed, but the notice may have closed the view the
@@ -359,6 +430,29 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
359
430
  /// table); the default menus perform the clipboard action
360
431
  /// directly through the same paths the keyboard shortcuts use.
361
432
  pub fn dispatchContextMenuAction(self: *Runtime, app: runtime_api.App(Runtime), event: platform.ContextMenuActionEvent) anyerror!void {
433
+ if (self.context_menu_policy) |policy| {
434
+ const maybe = self.canvas_widget_context_menu_pending;
435
+ const admission = menu_policy.admission(policy, if (maybe) |v| policyKind(v.kind) else null, if (maybe) |v| v.window_id else 0, if (maybe) |v| v.token else 0, event);
436
+ if (admission == .ignore) return;
437
+ const pending = maybe.?;
438
+ self.canvas_widget_context_menu_pending = null;
439
+ switch (admission) {
440
+ .ignore => unreachable,
441
+ .clear => return,
442
+ .dismiss => {
443
+ try self.dispatchEvent(app, .{ .canvas_widget_context_menu_dismissed = .{
444
+ .window_id = event.window_id,
445
+ .view_label = event.view_label,
446
+ .token = pending.token,
447
+ } });
448
+ return;
449
+ },
450
+ .lookup => {},
451
+ }
452
+ const index = runtimeFindViewIndex(self, event.window_id, event.view_label) orelse return;
453
+ try executeAction(self, app, index, pending, event, menu_policy.action(policy, policyKind(pending.kind), event.item_id));
454
+ return;
455
+ }
362
456
  const pending = self.canvas_widget_context_menu_pending orelse return;
363
457
  // Token gate BEFORE the clear: an event carrying a stale
364
458
  // token belongs to a superseded request (its deferred
@@ -414,6 +508,10 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
414
508
  /// Mint the next per-request correlation token. Never zero, so a
415
509
  /// zero-token event can never match an armed request.
416
510
  pub fn nextContextMenuToken(self: *Runtime) u64 {
511
+ if (self.context_menu_policy) |policy| {
512
+ self.canvas_widget_context_menu_token = menu_policy.nextToken(policy, self.canvas_widget_context_menu_token);
513
+ return self.canvas_widget_context_menu_token;
514
+ }
417
515
  self.canvas_widget_context_menu_token +%= 1;
418
516
  if (self.canvas_widget_context_menu_token == 0) self.canvas_widget_context_menu_token = 1;
419
517
  return self.canvas_widget_context_menu_token;
@@ -507,6 +605,86 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
507
605
  }
508
606
  }
509
607
 
608
+ fn policyKind(kind: PendingCanvasWidgetContextMenu.Kind) menu_policy.Kind {
609
+ return switch (kind) {
610
+ .app => .app,
611
+ .edit_text => .edit_text,
612
+ .terminal => .terminal,
613
+ .static_copy => .static_copy,
614
+ };
615
+ }
616
+
617
+ fn executeAction(self: *Runtime, app: runtime_api.App(Runtime), index: usize, pending: PendingCanvasWidgetContextMenu, event: platform.ContextMenuActionEvent, action: menu_policy.Action) anyerror!void {
618
+ switch (action) {
619
+ .none => {},
620
+ .app => try self.dispatchEvent(app, .{ .canvas_widget_context_menu = .{
621
+ .window_id = event.window_id,
622
+ .view_label = self.views[index].label,
623
+ .target_id = pending.target_id,
624
+ .item_index = event.item_id - 1,
625
+ .token = pending.token,
626
+ } }),
627
+ .copy => {
628
+ const text = editableSelectionText(self, index, pending.target_id) orelse return;
629
+ self.writeClipboard(text) catch return;
630
+ },
631
+ .cut => {
632
+ var keyboard = editKeyboardEvent(self, index, pending.target_id) orelse return;
633
+ const text = editableSelectionText(self, index, pending.target_id) orelse return;
634
+ self.writeClipboard(text) catch return;
635
+ keyboard.keyboard.edit = .{ .insert_text = "" };
636
+ try applyEditKeyboardEvent(self, app, keyboard);
637
+ },
638
+ .paste => {
639
+ var keyboard = editKeyboardEvent(self, index, pending.target_id) orelse return;
640
+ const node = self.views[index].canvasWidgetNodeIndexById(pending.target_id) orelse return;
641
+ const widget = self.views[index].widget_layout_nodes[node].widget;
642
+ if (!canvas_widget_runtime.canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return;
643
+ var buffer: [platform.max_clipboard_data_bytes]u8 = undefined;
644
+ const text = self.readClipboard(&buffer) catch return;
645
+ if (text.len == 0) return;
646
+ const clamp = canvas_widget_runtime.clampCanvasWidgetPasteText(widget, self.views[index].widget_text_len, text);
647
+ keyboard.keyboard.edit_truncated = clamp.truncated;
648
+ if (clamp.text.len == 0) return;
649
+ keyboard.keyboard.edit = .{ .insert_text = clamp.text };
650
+ try applyEditKeyboardEvent(self, app, keyboard);
651
+ },
652
+ .select_all => {
653
+ var keyboard = editKeyboardEvent(self, index, pending.target_id) orelse return;
654
+ keyboard.keyboard.key = "a";
655
+ keyboard.keyboard.modifiers = .{ .super = true };
656
+ try applyEditKeyboardEvent(self, app, keyboard);
657
+ },
658
+ .terminal_copy, .terminal_paste => {
659
+ const node = self.views[index].canvasWidgetNodeIndexById(pending.target_id) orelse return;
660
+ const widget = self.views[index].widget_layout_nodes[node].widget;
661
+ if (widget.kind != .terminal or widget.state.disabled) return;
662
+ const grid = widget.terminal.grid orelse return;
663
+ if (action == .terminal_copy) {
664
+ if (!grid.selection_active) return;
665
+ self.writeClipboard(grid.selection_text) catch return;
666
+ } else {
667
+ if (widget.terminal.pty == 0 or !grid.running) return;
668
+ var buffer: [platform.max_clipboard_data_bytes]u8 = undefined;
669
+ const text = self.readClipboard(&buffer) catch return;
670
+ if (text.len == 0) return;
671
+ try self.dispatchEvent(app, .{ .canvas_widget_keyboard = .{
672
+ .window_id = self.views[index].window_id,
673
+ .view_label = self.views[index].label,
674
+ .keyboard = .{ .phase = .text_input, .focused_id = pending.target_id, .text = text, .edit = .{ .insert_text = text } },
675
+ .terminal_paste = true,
676
+ .standalone = true,
677
+ } });
678
+ }
679
+ },
680
+ .static_copy => {
681
+ const buffer = &canvas_widget_context_menu_text_scratch.get().group_buffer;
682
+ const text = self.views[index].canvasWidgetCopyText(buffer) orelse return;
683
+ self.writeClipboard(text) catch return;
684
+ },
685
+ }
686
+ }
687
+
510
688
  /// A synthesized key-down keyboard event addressed at the editable
511
689
  /// widget, shaped like the routed events the clipboard shortcuts
512
690
  /// stamp their edits onto.
@@ -543,6 +721,7 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
543
721
  /// The deepest node on the pointer route carrying an app-declared
544
722
  /// context menu.
545
723
  fn deepestContextMenuRouteNode(self: *const Runtime, view_index: usize, route: []const canvas.WidgetEventRouteEntry) ?usize {
724
+ if (self.context_menu_policy) |policy| return menu_policy.route(policy, self.views[view_index].widget_layout_nodes[0..self.views[view_index].widget_layout_node_count], route);
546
725
  var result: ?usize = null;
547
726
  var result_depth: usize = 0;
548
727
  for (route) |entry| {