@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,3 +1,7 @@
1
+ pub const staged_rebuild_policy = @import("staged_rebuild_policy.zig");
2
+ pub const continuity_policy = @import("widget_continuity_policy.zig");
3
+ pub const scroll_tree_policy = @import("scroll_tree_policy.zig");
4
+ const retention = @import("widget_retention_policy.zig");
1
5
  const keyboard_focus = @import("canvas_keyboard_focus_policy.zig");
2
6
  const std = @import("std");
3
7
  const geometry = @import("geometry");
@@ -225,7 +229,7 @@ pub fn restoreCanvasWidgetLayoutScrollOffsets(
225
229
  previous_runtime_offsets: []const CanvasWidgetSourceScrollEntry,
226
230
  previous_source_offsets: []const CanvasWidgetSourceScrollEntry,
227
231
  ) void {
228
- restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(nodes, previous_runtime_offsets, previous_source_offsets, null, null);
232
+ restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(nodes, previous_runtime_offsets, previous_source_offsets, null, null, null);
229
233
  }
230
234
 
231
235
  fn restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
@@ -234,6 +238,7 @@ fn restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
234
238
  previous_source_offsets: []const CanvasWidgetSourceScrollEntry,
235
239
  anchored_depth: ?usize,
236
240
  strata: ?canvas.layout_coordination_policy.RetainedPlan,
241
+ policy: scroll_tree_policy.Policy,
237
242
  ) void {
238
243
  for (nodes, 0..) |node, index| {
239
244
  if (node.widget.kind != .scroll_view or node.widget.id == 0) continue;
@@ -261,7 +266,7 @@ fn restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
261
266
  nodes[index].widget.value_x = next_x;
262
267
  }
263
268
  if (restore.dx == 0 and restore.dy == 0) continue;
264
- translateCanvasWidgetLayoutScrollDescendants(nodes, index, .{ .dx = -restore.dx, .dy = -restore.dy });
269
+ translateCanvasWidgetLayoutScrollDescendantsWithPolicy(policy, nodes, index, .{ .dx = -restore.dx, .dy = -restore.dy });
265
270
  }
266
271
  }
267
272
 
@@ -282,6 +287,7 @@ fn clampCanvasWidgetLayoutProgrammaticScrollOffsets(
282
287
  previous_source_offsets: []const CanvasWidgetSourceScrollEntry,
283
288
  anchored_depth: ?usize,
284
289
  strata: ?canvas.layout_coordination_policy.RetainedPlan,
290
+ policy: scroll_tree_policy.Policy,
285
291
  ) void {
286
292
  for (nodes, 0..) |node, index| {
287
293
  if (node.widget.kind != .scroll_view or node.widget.id == 0) continue;
@@ -305,18 +311,19 @@ fn clampCanvasWidgetLayoutProgrammaticScrollOffsets(
305
311
  const viewport = node.frame.inset(node.widget.layout.padding).normalized();
306
312
  if (viewport.isEmpty()) continue;
307
313
 
314
+ const extents = canvasWidgetLayoutScrollExtentsWithPolicy(policy, nodes, index, viewport);
308
315
  const current_y = node.widget.value;
309
316
  const current_x = node.widget.value_x;
310
- const next_y = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 3, .current = current_y, .viewport = viewport.height, .content = canvasWidgetLayoutScrollContentExtent(nodes, index, viewport), .delta = source_node.widget.value, .previous_source = if (previous_source) |entry| entry.value else null, .retained = if (previous_runtime) |entry| entry.value else null, .granted = canvas.widgetScrollsAxis(node.widget, .vertical) })) |result| result.dx else if (clamp_y)
317
+ const next_y = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 3, .current = current_y, .viewport = viewport.height, .content = extents.dy, .delta = source_node.widget.value, .previous_source = if (previous_source) |entry| entry.value else null, .retained = if (previous_runtime) |entry| entry.value else null, .granted = canvas.widgetScrollsAxis(node.widget, .vertical) })) |result| result.dx else if (clamp_y)
311
318
  if (canvas.widgetScrollsAxis(node.widget, .vertical))
312
- std.math.clamp(@max(0, current_y), 0, @max(0, canvasWidgetLayoutScrollContentExtent(nodes, index, viewport) - viewport.height))
319
+ std.math.clamp(@max(0, current_y), 0, @max(0, extents.dy - viewport.height))
313
320
  else
314
321
  0
315
322
  else
316
323
  current_y;
317
- const next_x = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 3, .current = current_x, .viewport = viewport.width, .content = canvasWidgetLayoutScrollContentExtentX(nodes, index, viewport), .delta = source_node.widget.value_x, .previous_source = if (previous_source) |entry| entry.value_x else null, .retained = if (previous_runtime) |entry| entry.value_x else null, .granted = canvas.widgetScrollsAxis(node.widget, .horizontal) })) |result| result.dx else if (clamp_x)
324
+ const next_x = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 3, .current = current_x, .viewport = viewport.width, .content = extents.dx, .delta = source_node.widget.value_x, .previous_source = if (previous_source) |entry| entry.value_x else null, .retained = if (previous_runtime) |entry| entry.value_x else null, .granted = canvas.widgetScrollsAxis(node.widget, .horizontal) })) |result| result.dx else if (clamp_x)
318
325
  if (canvas.widgetScrollsAxis(node.widget, .horizontal))
319
- std.math.clamp(@max(0, current_x), 0, @max(0, canvasWidgetLayoutScrollContentExtentX(nodes, index, viewport) - viewport.width))
326
+ std.math.clamp(@max(0, current_x), 0, @max(0, extents.dx - viewport.width))
320
327
  else
321
328
  0
322
329
  else
@@ -325,7 +332,7 @@ fn clampCanvasWidgetLayoutProgrammaticScrollOffsets(
325
332
 
326
333
  nodes[index].widget.value = next_y;
327
334
  nodes[index].widget.value_x = next_x;
328
- translateCanvasWidgetLayoutScrollDescendants(nodes, index, .{
335
+ translateCanvasWidgetLayoutScrollDescendantsWithPolicy(policy, nodes, index, .{
329
336
  .dx = if (canvas.widgetScrollsAxis(node.widget, .horizontal)) -(next_x - current_x) else 0,
330
337
  .dy = if (canvas.widgetScrollsAxis(node.widget, .vertical)) -(next_y - current_y) else 0,
331
338
  });
@@ -343,7 +350,7 @@ fn previousLayoutHasSelectedTab(previous: canvas.WidgetLayoutTree, id: canvas.Ob
343
350
  /// viewport. This runs after retained scroll restoration, against final layout
344
351
  /// frames, so an already-visible tab preserves the exact offset and a newly
345
352
  /// mounted native scroll driver never paints a speculative leading-edge jump.
346
- fn revealNewlySelectedTabs(previous: canvas.WidgetLayoutTree, nodes: []canvas.WidgetLayoutNode, anchored_depth: ?usize, strata: ?canvas.layout_coordination_policy.RetainedPlan) void {
353
+ pub fn revealNewlySelectedTabs(previous: canvas.WidgetLayoutTree, nodes: []canvas.WidgetLayoutNode, anchored_depth: ?usize, strata: ?canvas.layout_coordination_policy.RetainedPlan) void {
347
354
  for (nodes, 0..) |tab_node, tab_index| {
348
355
  const tab = tab_node.widget;
349
356
  if (tab.semantics.role != .tab or !tab.state.selected) continue;
@@ -809,6 +816,45 @@ fn canvasWidgetSourceTextEntryByIdKind(
809
816
  return null;
810
817
  }
811
818
 
819
+ pub const reconcile_policy = @import("widget_reconcile_policy.zig");
820
+ pub fn canvasWidgetReconcilePlan(policy: reconcile_policy.Policy, layout: canvas.WidgetLayoutTree, controls: *const CanvasWidgetControlEntryIndex, sources: *const CanvasWidgetSourceControlEntryIndex, texts: *const CanvasWidgetTextEntryIndex) ?reconcile_policy.Plan {
821
+ return reconcile_policy.build(policy, layout, controls, sources, texts, canvasWidgetLayoutNodeHidden, canvasWidgetSourceTextFingerprint, canvasWidgetResizableMinWidth);
822
+ }
823
+ pub fn canvasWidgetLayoutNodeWithPlannedText(node: canvas.WidgetLayoutNode, action: reconcile_policy.Action, previous: *const CanvasWidgetTextEntryIndex) canvas.WidgetLayoutNode {
824
+ var copy = node;
825
+ if (action.flags & (16 | 32 | 64 | 128 | 256 | 512) != 0) {
826
+ const entry = previous.firstWithKind(node.widget.id, node.widget.kind) orelse @panic("missing planned text record");
827
+ if (action.flags & 16 != 0) copy.widget.text = entry.text;
828
+ if (action.flags & 32 != 0) copy.widget.value = entry.value;
829
+ if (action.flags & 64 != 0) {
830
+ copy.widget.text_selection = entry.text_selection;
831
+ // Static text restores only selection, never composition.
832
+ if (copy.widget.kind != .text) copy.widget.text_composition = entry.text_composition;
833
+ } else if (action.flags & 128 != 0) copy.widget.text_selection.?.affinity = entry.text_selection.?.affinity;
834
+ if (action.flags & 256 != 0) copy.widget.value_x = entry.value_x;
835
+ if (action.flags & 512 != 0) {
836
+ copy.widget.code_content_width = entry.code_content_width;
837
+ copy.widget.code_content_width_generation = entry.code_content_width_generation;
838
+ copy.widget.code_content_width_font_id = entry.code_content_width_font_id;
839
+ copy.widget.code_content_width_size_bits = entry.code_content_width_size_bits;
840
+ }
841
+ }
842
+ return if (action.flags & 1024 != 0) canvasWidgetLayoutNodeWithCaretSafeSelection(copy) else copy;
843
+ }
844
+ pub fn canvasWidgetLayoutNodeWithPlannedControl(node: canvas.WidgetLayoutNode, action: reconcile_policy.Action) canvas.WidgetLayoutNode {
845
+ var copy = node;
846
+ if (action.flags & 1 != 0) {
847
+ copy.widget.state.selected = action.flags & 2 != 0;
848
+ copy.widget.value = if (copy.widget.state.selected) 1 else 0;
849
+ }
850
+ if (action.flags & 4 != 0) copy.widget.value = action.value;
851
+ if (action.flags & 8 != 0) {
852
+ copy.frame.width = action.value;
853
+ copy.widget.frame.width = action.value;
854
+ }
855
+ return copy;
856
+ }
857
+
812
858
  pub fn canvasWidgetLayoutNodeWithControlReconcileState(
813
859
  node: canvas.WidgetLayoutNode,
814
860
  layout: canvas.WidgetLayoutTree,
@@ -1038,16 +1084,19 @@ pub fn canvasWidgetLayoutTreeWithRuntimeReconcileState(
1038
1084
  ) anyerror!canvas.WidgetLayoutTree {
1039
1085
  if (next.nodes.len > node_buffer.len) return error.WidgetNodeLimitReached;
1040
1086
 
1041
- const previous_control_states = collectCanvasWidgetControlReconcileEntries(
1087
+ const previous_control_states = collectCanvasWidgetControlReconcileEntriesWithPolicy(
1088
+ tokens.widget_retention_policy,
1042
1089
  previous.nodes,
1043
1090
  control_entries,
1044
1091
  );
1045
- const previous_runtime_offsets = collectCanvasWidgetScrollOffsetEntries(
1092
+ const previous_runtime_offsets = collectCanvasWidgetScrollOffsetEntriesWithPolicy(
1093
+ tokens.widget_retention_policy,
1046
1094
  previous.nodes,
1047
1095
  scroll_offset_entries,
1048
1096
  );
1049
1097
  var text_len: usize = 0;
1050
- const previous_text_states = try collectCanvasWidgetTextReconcileEntries(
1098
+ const previous_text_states = try collectCanvasWidgetTextReconcileEntriesWithPolicy(
1099
+ tokens.widget_retention_policy,
1051
1100
  previous.nodes,
1052
1101
  previous_source_text_entries,
1053
1102
  text_entries,
@@ -1088,84 +1137,125 @@ pub fn canvasWidgetLayoutTreeWithRuntimeReconcileState(
1088
1137
  null;
1089
1138
  defer if (strata) |plan| plan.deinit();
1090
1139
  const max_anchored_depth = if (strata) |plan| plan.maximum() else canvas.maxAnchoredNestingDepth(staged_nodes);
1091
- var anchored_depth: usize = 0;
1092
- while (anchored_depth <= max_anchored_depth) : (anchored_depth += 1) {
1093
- for (staged_nodes, 0..) |node, index| {
1094
- if (node.widget.kind != .split or node.widget.id == 0) continue;
1095
- if ((if (strata) |plan| plan.nesting(index) else canvas.anchoredNestingDepth(staged_nodes, index)) != anchored_depth) continue;
1096
- const tween_armed = objectIdInList(armed_split_tween_ids, node.widget.id);
1097
- const previous_runtime = canvasWidgetSourceScrollById(previous_runtime_offsets, node.widget.id) orelse {
1098
- // A FRESH split (no retained fraction): a declared enter
1099
- // origin slides the first layout's boundary to the origin
1100
- // pose — children keep the declared value's (target) wrap —
1101
- // so the tween armed right after this reconcile eases it in
1102
- // instead of the mount popping to its value.
1103
- if (node.widget.resize_duration_ms != 0 and node.widget.resize_origin >= 0 and node.widget.children.len != 0) {
1104
- canvas.slideSplitChildrenWithTokens(node.frame, node.widget.resize_origin, index, staged_nodes, tokens);
1105
- }
1106
- continue;
1107
- };
1108
- const previous_source = canvasWidgetSourceScrollById(previous_source_scroll_entries, node.widget.id);
1109
- // Source-wins: the runtime-owned fraction survives rebuilds only
1110
- // while the SOURCE fraction is unchanged; a source-side change
1111
- // (the model echoing or driving the fraction) wins — UNLESS the
1112
- // split declares a layout tween (`resize_duration_ms` nonzero)
1113
- // or one is already in flight: then the moved source value is a
1114
- // TARGET, the rendered fraction stays where it is, and the
1115
- // runtime's tween lowering (armed right after this reconcile
1116
- // lands, in setCanvasWidgetLayout) eases it there one presented
1117
- // frame at a time. Reduced motion still snaps: the tween
1118
- // lowering's snap path applies the target through this same
1119
- // mutation family in the same rebuild.
1120
- const source_moved = if (previous_source) |source| node.widget.value != source else false;
1121
- const retained_fraction = canvas.widgetCompiledSplitValue(node.widget, .{
1122
- .operation = 2,
1123
- .value = node.widget.value,
1124
- .previous_source = previous_source,
1125
- .retained = previous_runtime,
1126
- .declared_tween = node.widget.resize_duration_ms != 0,
1127
- .armed_tween = tween_armed,
1128
- }) orelse if (previous_source == null or (source_moved and node.widget.resize_duration_ms == 0 and !tween_armed)) node.widget.value else previous_runtime;
1129
- if (node.widget.value == retained_fraction) continue;
1130
- staged_nodes[index].widget.value = retained_fraction;
1131
- // Retained trees clear children; a split without them keeps the
1132
- // value restore only (frames follow on the next full layout).
1133
- if (node.widget.children.len == 0) continue;
1134
- // A pressed divider is a live drag: its echo rebuilds must keep
1135
- // re-wrapping at the dragged width (the pinned drag behavior),
1136
- // so the slide shape only applies to tween-owned motion.
1137
- const dragging = pressed_split_id != 0 and node.widget.id == pressed_split_id;
1138
- if (!dragging and (tween_armed or (source_moved and node.widget.resize_duration_ms != 0))) {
1139
- canvas.slideSplitChildrenWithTokens(node.frame, retained_fraction, index, staged_nodes, tokens);
1140
- } else {
1141
- try canvas.relayoutSplitChildren(staged_nodes[index].widget, node.frame, index, node.depth, node_buffer, staged_root_bounds, tokens);
1140
+ if (tokens.staged_rebuild_policy) |policy| {
1141
+ var program = staged_rebuild_policy.Program.init(policy, staged_nodes.len, max_anchored_depth);
1142
+ for (staged_nodes, 0..) |node, i| program.setNode(i, node, if (strata) |plan| plan.nesting(i) else canvas.anchoredNestingDepth(staged_nodes, i));
1143
+ while (true) {
1144
+ const step = program.next();
1145
+ switch (step.kind) {
1146
+ .done => break,
1147
+ .split => {
1148
+ // Read the node AFTER prior mutations: an outer split
1149
+ // or anchored replay may have rebuilt this source value.
1150
+ const node = staged_nodes[step.index];
1151
+ const result = staged_rebuild_policy.split(policy, node, canvasWidgetSourceScrollById(previous_runtime_offsets, node.widget.id), canvasWidgetSourceScrollById(previous_source_scroll_entries, node.widget.id), objectIdInList(armed_split_tween_ids, node.widget.id), pressed_split_id != 0 and node.widget.id == pressed_split_id);
1152
+ switch (result.kind) {
1153
+ .keep => {},
1154
+ .enter_slide => canvas.slideSplitChildrenWithTokens(node.frame, result.value, step.index, staged_nodes, tokens),
1155
+ .value_only => staged_nodes[step.index].widget.value = result.value,
1156
+ .slide => {
1157
+ staged_nodes[step.index].widget.value = result.value;
1158
+ canvas.slideSplitChildrenWithTokens(node.frame, result.value, step.index, staged_nodes, tokens);
1159
+ },
1160
+ .relayout => {
1161
+ staged_nodes[step.index].widget.value = result.value;
1162
+ try canvas.relayoutSplitChildren(staged_nodes[step.index].widget, node.frame, step.index, node.depth, node_buffer, staged_root_bounds, tokens);
1163
+ },
1164
+ }
1165
+ program.refreshAdmission(staged_nodes);
1166
+ },
1167
+ .restore_scroll => restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(staged_nodes, previous_runtime_offsets, previous_source_scroll_entries, step.depth, strata, tokens.scroll_tree_policy),
1168
+ .clamp_scroll => clampCanvasWidgetLayoutProgrammaticScrollOffsets(staged_nodes, next, previous_runtime_offsets, previous_source_scroll_entries, step.depth, strata, tokens.scroll_tree_policy),
1169
+ .reveal_tabs => revealNewlySelectedTabsWithPolicy(tokens.scroll_tree_policy, previous, staged_nodes, step.depth, strata),
1170
+ .anchors => {
1171
+ try canvas.relayoutAnchoredChildrenAtDepth(staged_nodes, staged_root_bounds, tokens, step.depth);
1172
+ if (strata) |plan| for (staged_nodes, 0..) |node, i| plan.setNode(i, node);
1173
+ for (staged_nodes, 0..) |node, i| program.setNode(i, node, if (strata) |plan| plan.nesting(i) else canvas.anchoredNestingDepth(staged_nodes, i));
1174
+ },
1142
1175
  }
1143
1176
  }
1177
+ } else {
1178
+ var anchored_depth: usize = 0;
1179
+ while (anchored_depth <= max_anchored_depth) : (anchored_depth += 1) {
1180
+ for (staged_nodes, 0..) |node, index| {
1181
+ if (node.widget.kind != .split or node.widget.id == 0) continue;
1182
+ if ((if (strata) |plan| plan.nesting(index) else canvas.anchoredNestingDepth(staged_nodes, index)) != anchored_depth) continue;
1183
+ const tween_armed = objectIdInList(armed_split_tween_ids, node.widget.id);
1184
+ const previous_runtime = canvasWidgetSourceScrollById(previous_runtime_offsets, node.widget.id) orelse {
1185
+ // A FRESH split (no retained fraction): a declared enter
1186
+ // origin slides the first layout's boundary to the origin
1187
+ // pose — children keep the declared value's (target) wrap —
1188
+ // so the tween armed right after this reconcile eases it in
1189
+ // instead of the mount popping to its value.
1190
+ if (node.widget.resize_duration_ms != 0 and node.widget.resize_origin >= 0 and node.widget.children.len != 0) {
1191
+ canvas.slideSplitChildrenWithTokens(node.frame, node.widget.resize_origin, index, staged_nodes, tokens);
1192
+ }
1193
+ continue;
1194
+ };
1195
+ const previous_source = canvasWidgetSourceScrollById(previous_source_scroll_entries, node.widget.id);
1196
+ // Source-wins: the runtime-owned fraction survives rebuilds only
1197
+ // while the SOURCE fraction is unchanged; a source-side change
1198
+ // (the model echoing or driving the fraction) wins — UNLESS the
1199
+ // split declares a layout tween (`resize_duration_ms` nonzero)
1200
+ // or one is already in flight: then the moved source value is a
1201
+ // TARGET, the rendered fraction stays where it is, and the
1202
+ // runtime's tween lowering (armed right after this reconcile
1203
+ // lands, in setCanvasWidgetLayout) eases it there one presented
1204
+ // frame at a time. Reduced motion still snaps: the tween
1205
+ // lowering's snap path applies the target through this same
1206
+ // mutation family in the same rebuild.
1207
+ const source_moved = if (previous_source) |source| node.widget.value != source else false;
1208
+ const retained_fraction = canvas.widgetCompiledSplitValue(node.widget, .{
1209
+ .operation = 2,
1210
+ .value = node.widget.value,
1211
+ .previous_source = previous_source,
1212
+ .retained = previous_runtime,
1213
+ .declared_tween = node.widget.resize_duration_ms != 0,
1214
+ .armed_tween = tween_armed,
1215
+ }) orelse if (previous_source == null or (source_moved and node.widget.resize_duration_ms == 0 and !tween_armed)) node.widget.value else previous_runtime;
1216
+ if (node.widget.value == retained_fraction) continue;
1217
+ staged_nodes[index].widget.value = retained_fraction;
1218
+ // Retained trees clear children; a split without them keeps the
1219
+ // value restore only (frames follow on the next full layout).
1220
+ if (node.widget.children.len == 0) continue;
1221
+ // A pressed divider is a live drag: its echo rebuilds must keep
1222
+ // re-wrapping at the dragged width (the pinned drag behavior),
1223
+ // so the slide shape only applies to tween-owned motion.
1224
+ const dragging = pressed_split_id != 0 and node.widget.id == pressed_split_id;
1225
+ if (!dragging and (tween_armed or (source_moved and node.widget.resize_duration_ms != 0))) {
1226
+ canvas.slideSplitChildrenWithTokens(node.frame, retained_fraction, index, staged_nodes, tokens);
1227
+ } else {
1228
+ try canvas.relayoutSplitChildren(staged_nodes[index].widget, node.frame, index, node.depth, node_buffer, staged_root_bounds, tokens);
1229
+ }
1230
+ }
1144
1231
 
1145
- // Scroll restore is staged too (after splits, so translated frames
1146
- // are final geometry): the retained offset comes back WITH its
1147
- // descendants translated to match. Engine-side clamping happens at
1148
- // the caller AFTER native scroll drivers are stamped — a rebuild
1149
- // mid-rubber-band must not clamp an offset the OS scroller owns.
1150
- restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
1151
- staged_nodes,
1152
- previous_runtime_offsets,
1153
- previous_source_scroll_entries,
1154
- anchored_depth,
1155
- strata,
1156
- );
1157
- clampCanvasWidgetLayoutProgrammaticScrollOffsets(
1158
- staged_nodes,
1159
- next,
1160
- previous_runtime_offsets,
1161
- previous_source_scroll_entries,
1162
- anchored_depth,
1163
- strata,
1164
- );
1165
- revealNewlySelectedTabs(previous, staged_nodes, anchored_depth, strata);
1166
- if (anchored_depth < max_anchored_depth) {
1167
- try canvas.relayoutAnchoredChildrenAtDepth(staged_nodes, staged_root_bounds, tokens, anchored_depth);
1168
- if (strata) |plan| for (staged_nodes, 0..) |node, i| plan.setNode(i, node);
1232
+ // Scroll restore is staged too (after splits, so translated frames
1233
+ // are final geometry): the retained offset comes back WITH its
1234
+ // descendants translated to match. Engine-side clamping happens at
1235
+ // the caller AFTER native scroll drivers are stamped — a rebuild
1236
+ // mid-rubber-band must not clamp an offset the OS scroller owns.
1237
+ restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
1238
+ staged_nodes,
1239
+ previous_runtime_offsets,
1240
+ previous_source_scroll_entries,
1241
+ anchored_depth,
1242
+ strata,
1243
+ tokens.scroll_tree_policy,
1244
+ );
1245
+ clampCanvasWidgetLayoutProgrammaticScrollOffsets(
1246
+ staged_nodes,
1247
+ next,
1248
+ previous_runtime_offsets,
1249
+ previous_source_scroll_entries,
1250
+ anchored_depth,
1251
+ strata,
1252
+ tokens.scroll_tree_policy,
1253
+ );
1254
+ revealNewlySelectedTabsWithPolicy(tokens.scroll_tree_policy, previous, staged_nodes, anchored_depth, strata);
1255
+ if (anchored_depth < max_anchored_depth) {
1256
+ try canvas.relayoutAnchoredChildrenAtDepth(staged_nodes, staged_root_bounds, tokens, anchored_depth);
1257
+ if (strata) |plan| for (staged_nodes, 0..) |node, i| plan.setNode(i, node);
1258
+ }
1169
1259
  }
1170
1260
  }
1171
1261
 
@@ -1176,16 +1266,52 @@ pub fn canvasWidgetLayoutTreeWithRuntimeReconcileState(
1176
1266
  index_scratch.semantics.build(source_semantics);
1177
1267
 
1178
1268
  const staged = canvas.WidgetLayoutTree{ .nodes = staged_nodes, .root_bounds = next.root_bounds };
1269
+ const reconcile_plan = canvasWidgetReconcilePlan(tokens.widget_reconcile_policy, staged, &index_scratch.controls, &index_scratch.source_controls, &index_scratch.texts);
1270
+ const continuity_plan = continuity_policy.layout(tokens.widget_continuity_policy, staged_nodes, @as([]const CanvasWidgetScrollReconcileEntry, &.{}), &index_scratch.semantics);
1179
1271
  for (staged_nodes, 0..) |node, index| {
1180
- const text_copy = canvasWidgetLayoutNodeWithTextReconcileState(node, staged, index, &index_scratch.texts);
1181
- const control_copy = canvasWidgetLayoutNodeWithControlReconcileState(text_copy, staged, index, &index_scratch.controls, &index_scratch.source_controls);
1182
- node_buffer[index] = canvasWidgetLayoutNodeWithSourceSemantics(control_copy, &index_scratch.semantics);
1272
+ const text_copy = if (reconcile_plan) |*plan| canvasWidgetLayoutNodeWithPlannedText(node, plan.entries[index], &index_scratch.texts) else canvasWidgetLayoutNodeWithTextReconcileState(node, staged, index, &index_scratch.texts);
1273
+ const control_copy = if (reconcile_plan) |*plan| canvasWidgetLayoutNodeWithPlannedControl(text_copy, plan.entries[index]) else canvasWidgetLayoutNodeWithControlReconcileState(text_copy, staged, index, &index_scratch.controls, &index_scratch.source_controls);
1274
+ node_buffer[index] = canvasWidgetLayoutNodeWithPlannedSourceSemantics(control_copy, &index_scratch.semantics, if (continuity_plan) |plan| plan.actions[index] else null);
1183
1275
  }
1184
1276
  const reconciled = node_buffer[0..next.nodes.len];
1185
1277
  clampCanvasWidgetLayoutTextOffsets(reconciled, tokens);
1186
1278
  return .{ .nodes = reconciled, .root_bounds = next.root_bounds, .change_policy = next.change_policy, .text_run_policy = next.text_run_policy };
1187
1279
  }
1188
1280
 
1281
+ /// Apply only the compiled selection; complete records and physics remain in
1282
+ /// native-owned storage. Null plans preserve the independent native reference.
1283
+ pub fn canvasWidgetLayoutNodeWithPlannedSourceSemantics(node: canvas.WidgetLayoutNode, sources: *const CanvasWidgetSemanticsIndex, action: ?u8) canvas.WidgetLayoutNode {
1284
+ const flags = action orelse return canvasWidgetLayoutNodeWithSourceSemantics(node, sources);
1285
+ var copy = node;
1286
+ if (flags & 1 != 0) {
1287
+ const source = sources.first(node.widget.id) orelse @panic("missing planned source semantics");
1288
+ copy.widget.semantics.list_item_index = source.list.item_index;
1289
+ copy.widget.semantics.list_item_count = source.list.item_count;
1290
+ }
1291
+ return copy;
1292
+ }
1293
+ pub fn canvasWidgetScrollStateWithPlan(node: canvas.WidgetLayoutNode, previous: []const CanvasWidgetScrollReconcileEntry, action: ?u8) canvas.ScrollState {
1294
+ const flags = action orelse return canvasWidgetScrollStateForLayoutNode(node, previous);
1295
+ var state = canvas.ScrollState{ .offset_y = node.widget.value, .offset_x = node.widget.value_x };
1296
+ if (flags & 12 != 0) for (previous) |entry| {
1297
+ if (entry.id != node.widget.id) continue;
1298
+ if (flags & 4 != 0) state.velocity_y = entry.state.velocity_y;
1299
+ if (flags & 8 != 0) state.velocity_x = entry.state.velocity_x;
1300
+ break;
1301
+ };
1302
+ return state;
1303
+ }
1304
+ pub fn applyCanvasWidgetSourceScrollSemanticsWithPolicy(policy: continuity_policy.Policy, nodes: []canvas.WidgetSemanticsNode, sources: *const CanvasWidgetSemanticsIndex) void {
1305
+ const plan = continuity_policy.semanticsPlan(policy, nodes, sources) orelse return applyCanvasWidgetSourceScrollSemantics(nodes, sources);
1306
+ for (nodes, 0..) |*node, i| if (plan.actions[i] & 2 != 0) {
1307
+ const source = sources.first(node.id) orelse @panic("missing planned scroll semantics");
1308
+ node.value = source.value;
1309
+ node.scroll = source.scroll;
1310
+ node.actions = source.actions;
1311
+ node.focusable = source.focusable;
1312
+ };
1313
+ }
1314
+
1189
1315
  pub fn canvasWidgetLayoutNodeWithSourceSemantics(
1190
1316
  node: canvas.WidgetLayoutNode,
1191
1317
  source_semantics: *const CanvasWidgetSemanticsIndex,
@@ -1272,7 +1398,8 @@ fn clampCanvasWidgetLayoutScrollOffsetsImpl(
1272
1398
  const viewport = node.frame.inset(node.widget.layout.padding).normalized();
1273
1399
  if (viewport.isEmpty()) continue;
1274
1400
 
1275
- const content_extent = canvasWidgetLayoutScrollContentExtent(nodes, index, viewport);
1401
+ const extents = canvasWidgetLayoutScrollExtentsWithPolicy(tokens.scroll_tree_policy, nodes, index, viewport);
1402
+ const content_extent = extents.dy;
1276
1403
  const max_offset = @max(0, content_extent - viewport.height);
1277
1404
  const current_offset = node.widget.value;
1278
1405
  // An offset on an axis the region does not grant pins home: a
@@ -1283,7 +1410,7 @@ fn clampCanvasWidgetLayoutScrollOffsetsImpl(
1283
1410
  else
1284
1411
  0;
1285
1412
 
1286
- const content_extent_x = canvasWidgetLayoutScrollContentExtentX(nodes, index, viewport);
1413
+ const content_extent_x = extents.dx;
1287
1414
  const max_offset_x = @max(0, content_extent_x - viewport.width);
1288
1415
  const current_offset_x = node.widget.value_x;
1289
1416
  const next_offset_x = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 0, .current = current_offset_x, .viewport = viewport.width, .content = content_extent_x, .granted = canvas.widgetScrollsAxis(node.widget, .horizontal) })) |result| result.dx else if (canvas.widgetScrollsAxis(node.widget, .horizontal))
@@ -1297,7 +1424,7 @@ fn clampCanvasWidgetLayoutScrollOffsetsImpl(
1297
1424
  // Only granted axes translate: the layout pass never displaced
1298
1425
  // children along an ungranted axis (`scrollLayoutOffset` gates
1299
1426
  // it), so pinning that value home is bookkeeping, not motion.
1300
- translateCanvasWidgetLayoutScrollDescendants(nodes, index, .{
1427
+ translateCanvasWidgetLayoutScrollDescendantsWithPolicy(tokens.scroll_tree_policy, nodes, index, .{
1301
1428
  .dx = if (canvas.widgetScrollsAxis(node.widget, .horizontal)) -(next_offset_x - current_offset_x) else 0,
1302
1429
  .dy = if (canvas.widgetScrollsAxis(node.widget, .vertical)) -(next_offset - current_offset) else 0,
1303
1430
  });
@@ -1345,6 +1472,34 @@ pub fn clampCanvasWidgetLayoutTextOffsets(nodes: []canvas.WidgetLayoutNode, toke
1345
1472
  }
1346
1473
  }
1347
1474
 
1475
+ /// A fresh copied plan observes every earlier split/scroll mutation. Never
1476
+ /// cache geometry plans across relayout or across two selected-tab reveals.
1477
+ pub fn canvasWidgetLayoutScrollExtentsWithPolicy(policy: scroll_tree_policy.Policy, nodes: []const canvas.WidgetLayoutNode, index: usize, viewport: geometry.RectF) geometry.OffsetF {
1478
+ if (index >= nodes.len) return .{};
1479
+ if (scroll_tree_policy.build(policy, nodes, .{ .operation = 0, .target = index, .viewport = viewport })) |plan| return .{ .dx = plan.x, .dy = plan.y };
1480
+ return .{ .dx = canvasWidgetLayoutScrollContentExtentX(nodes, index, viewport), .dy = canvasWidgetLayoutScrollContentExtent(nodes, index, viewport) };
1481
+ }
1482
+
1483
+ pub fn translateCanvasWidgetLayoutScrollDescendantsWithPolicy(policy: scroll_tree_policy.Policy, nodes: []canvas.WidgetLayoutNode, index: usize, offset: geometry.OffsetF) void {
1484
+ if (index >= nodes.len) return;
1485
+ if (scroll_tree_policy.build(policy, nodes, .{ .operation = 1, .target = index })) |plan| {
1486
+ plan.translate(nodes, offset);
1487
+ } else translateCanvasWidgetLayoutScrollDescendants(nodes, index, offset);
1488
+ }
1489
+
1490
+ pub fn revealNewlySelectedTabsWithPolicy(policy: scroll_tree_policy.Policy, previous: canvas.WidgetLayoutTree, nodes: []canvas.WidgetLayoutNode, anchored_depth: ?usize, strata: ?canvas.layout_coordination_policy.RetainedPlan) void {
1491
+ if (policy == null) return revealNewlySelectedTabs(previous, nodes, anchored_depth, strata);
1492
+ var cursor: usize = 0;
1493
+ while (cursor < nodes.len) {
1494
+ const plan = scroll_tree_policy.build(policy, nodes, .{ .operation = 2, .target = cursor, .previous = previous, .anchored_depth = anchored_depth, .strata = strata }).?;
1495
+ if (plan.target) |index| {
1496
+ nodes[index].widget.value_x = plan.y;
1497
+ plan.translate(nodes, .{ .dx = plan.x });
1498
+ }
1499
+ cursor = plan.cursor;
1500
+ }
1501
+ }
1502
+
1348
1503
  pub fn canvasWidgetLayoutScrollContentExtent(nodes: []const canvas.WidgetLayoutNode, scroll_index: usize, viewport: geometry.RectF) f32 {
1349
1504
  if (scroll_index >= nodes.len) return 0;
1350
1505
  const scroll_node = nodes[scroll_index];
@@ -2394,3 +2549,62 @@ fn canvasWidgetCompiledGroupFocus(layout: canvas.WidgetLayoutTree, focused: canv
2394
2549
  else
2395
2550
  layout.focusTargetById(layout.nodes[index].widget.id);
2396
2551
  }
2552
+
2553
+ /// Compiled plans select complete native records, without lending their storage
2554
+ /// to the policy. Absent policies use the independent reference collectors.
2555
+ pub fn collectCanvasWidgetScrollOffsetEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, output: []CanvasWidgetSourceScrollEntry) []const CanvasWidgetSourceScrollEntry {
2556
+ const plan = retention.collect(policy, .source_scroll, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, 0) orelse return collectCanvasWidgetScrollOffsetEntries(nodes, output);
2557
+ for (plan.entries[0..plan.count], 0..) |entry, i| {
2558
+ const widget = nodes[entry.node].widget;
2559
+ output[i] = .{ .id = widget.id, .value = widget.value, .value_x = widget.value_x };
2560
+ }
2561
+ return output[0..plan.count];
2562
+ }
2563
+ pub fn collectCanvasWidgetSourceControlEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, output: []CanvasWidgetSourceControlEntry) []const CanvasWidgetSourceControlEntry {
2564
+ const plan = retention.collect(policy, .source_control, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, 0) orelse return collectCanvasWidgetSourceControlEntries(nodes, output);
2565
+ for (plan.entries[0..plan.count], 0..) |entry, i| {
2566
+ const widget = nodes[entry.node].widget;
2567
+ output[i] = .{ .id = widget.id, .kind = widget.kind, .selected = entry.selected, .value = widget.value };
2568
+ }
2569
+ return output[0..plan.count];
2570
+ }
2571
+ pub fn collectCanvasWidgetControlReconcileEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, output: []CanvasWidgetControlReconcileEntry) []const CanvasWidgetControlReconcileEntry {
2572
+ const plan = retention.collect(policy, .control, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, 0) orelse return collectCanvasWidgetControlReconcileEntries(nodes, output);
2573
+ for (plan.entries[0..plan.count], 0..) |entry, i| {
2574
+ const node = nodes[entry.node];
2575
+ output[i] = .{ .id = node.widget.id, .kind = node.widget.kind, .state = node.widget.state, .value = if (entry.resizable) node.frame.width else node.widget.value };
2576
+ }
2577
+ return output[0..plan.count];
2578
+ }
2579
+ pub fn collectCanvasWidgetScrollReconcileEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, states: []const canvas.ScrollState, output: []CanvasWidgetScrollReconcileEntry) []const CanvasWidgetScrollReconcileEntry {
2580
+ const plan = retention.collect(policy, .scroll, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, @min(nodes.len, states.len)) orelse return collectCanvasWidgetScrollReconcileEntries(nodes, states, output);
2581
+ for (plan.entries[0..plan.count], 0..) |entry, i| output[i] = .{ .id = nodes[entry.node].widget.id, .state = states[entry.node] };
2582
+ return output[0..plan.count];
2583
+ }
2584
+ pub fn collectCanvasWidgetTextReconcileEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, source_entries: []const CanvasWidgetSourceTextEntry, output: []CanvasWidgetTextReconcileEntry, text_storage: []u8, text_len: *usize) anyerror![]const CanvasWidgetTextReconcileEntry {
2585
+ const plan = retention.collect(policy, .text, nodes, source_entries, output.len, 0) orelse return collectCanvasWidgetTextReconcileEntries(nodes, source_entries, output, text_storage, text_len);
2586
+ for (plan.entries[0..plan.count], 0..) |entry, i| {
2587
+ const widget = nodes[entry.node].widget;
2588
+ const text_range = try appendWidgetTextStorageRange(text_storage, text_len, widget.text);
2589
+ const source_entry: ?CanvasWidgetSourceTextEntry = if (entry.source) |index| source_entries[index] else null;
2590
+ const source_text = if (source_entry) |source| CanvasWidgetSourceTextFingerprint{ .len = source.text_len, .hash = source.text_hash } else canvasWidgetSourceTextFingerprint(widget.text);
2591
+ output[i] = .{
2592
+ .id = widget.id,
2593
+ .kind = widget.kind,
2594
+ .text = text_storage[text_range.start..text_range.end],
2595
+ .static_text_group_id = widget.static_text_group_id,
2596
+ .source_text_len = source_text.len,
2597
+ .source_text_hash = source_text.hash,
2598
+ .source_text_selection = if (source_entry) |source| source.text_selection else null,
2599
+ .text_selection = widget.text_selection,
2600
+ .text_composition = widget.text_composition,
2601
+ .value = widget.value,
2602
+ .value_x = widget.value_x,
2603
+ .code_content_width = if (!entry.code_diff) widget.code_content_width else 0,
2604
+ .code_content_width_generation = if (!entry.code_diff) widget.code_content_width_generation else 0,
2605
+ .code_content_width_font_id = if (!entry.code_diff) widget.code_content_width_font_id else 0,
2606
+ .code_content_width_size_bits = if (!entry.code_diff) widget.code_content_width_size_bits else 0,
2607
+ };
2608
+ }
2609
+ return output[0..plan.count];
2610
+ }