@native-sdk/cli 0.0.0 → 0.4.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 (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
@@ -0,0 +1,540 @@
1
+ //! Variable-extent windowed virtual lists: the offset table behind
2
+ //! `Ui.virtualWindow` when rows are NOT uniform (chat transcripts,
3
+ //! mixed-height feeds, markdown-bearing lists).
4
+ //!
5
+ //! The honest contract, in one paragraph: the APP provides a cheap
6
+ //! per-item extent ESTIMATE (a fn of the item index — line counts, byte
7
+ //! counts, anything O(1)); the ENGINE measures the rows it actually
8
+ //! mounts and keeps a bounded table of measured actuals. Scroll
9
+ //! geometry (item offsets, the total content extent, index-at-offset)
10
+ //! is prefix sums over the estimates PATCHED by the measured deltas, so
11
+ //! the scrollbar converges to truth as the user visits the list. The
12
+ //! scrollbar may therefore adjust as estimates correct — that is the
13
+ //! honest behavior every virtualized-list system has — but corrections
14
+ //! NEVER move content the user is looking at: every correction batch is
15
+ //! anchored on a caller-chosen row, and the table reports the offset
16
+ //! delta that keeps that row's position invariant
17
+ //! (`pending_offset_delta`, consumed together with the patched offsets
18
+ //! at the next window computation, so offset and geometry always shift
19
+ //! atomically).
20
+ //!
21
+ //! Bookkeeping is budgeted, canvas_limits-style (fixed, documented,
22
+ //! loud):
23
+ //! - Estimate prefix sums are cached per CHUNK of
24
+ //! `virtual_extent_chunk` items, so offset queries cost one partial
25
+ //! chunk scan and data changes recompute only the chunks they touch.
26
+ //! `max_virtual_extent_chunks` bounds the cache; items past the
27
+ //! covered range extrapolate at the covered average extent (at
28
+ //! 262k+ items the extrapolation error is far below one scrollbar
29
+ //! pixel, and it corrects itself as the tail is ever reached).
30
+ //! - Measured actuals are bounded by `max_virtual_measured_items` per
31
+ //! list. When the table is full, the entry FARTHEST from the current
32
+ //! anchor is evicted and that row drifts back to its estimate until
33
+ //! revisited — bounded memory, documented drift, no failure mode.
34
+ //!
35
+ //! Items are keyed by LOGICAL index: `index_base + physical_index`.
36
+ //! A tail-anchored transcript that loads older history PREPENDS items
37
+ //! by decreasing `index_base`, so logical identities (and their
38
+ //! measured extents) never shift; the table folds the prepended extent
39
+ //! into `pending_offset_delta` so the viewport stays glued to what it
40
+ //! was showing.
41
+
42
+ const std = @import("std");
43
+
44
+ /// Per-item extent estimate: cheap, pure, O(1) — derived from model
45
+ /// facts (line counts, attachment presence), never from layout. The
46
+ /// index is LOGICAL (`index_base + physical`), so estimates stay keyed
47
+ /// to item identity across prepends.
48
+ pub const VirtualExtentEstimateFn = *const fn (context: ?*const anyopaque, index: u64) f32;
49
+
50
+ /// Items per estimate-prefix chunk. 64 keeps the partial-scan cost of
51
+ /// an offset query trivial while one chunk recompute stays cheap.
52
+ pub const virtual_extent_chunk: usize = 64;
53
+
54
+ /// Estimate-prefix chunks cached per list: 4096 chunks x 64 items
55
+ /// covers 262,144 items exactly; larger lists extrapolate the tail at
56
+ /// the covered average (see the module doc). 4096 x 4 bytes = 16 KiB
57
+ /// per list.
58
+ pub const max_virtual_extent_chunks: usize = 4096;
59
+
60
+ /// Items whose estimates the table covers exactly.
61
+ pub const max_virtual_extent_items: usize = virtual_extent_chunk * max_virtual_extent_chunks;
62
+
63
+ /// Measured actuals retained per list. A mounted window is a few dozen
64
+ /// rows, so 2048 covers ~50+ visited windows before eviction starts;
65
+ /// 2048 x (8 + 4 + 4) bytes = 32 KiB per list.
66
+ pub const max_virtual_measured_items: usize = 2048;
67
+
68
+ /// Measured extents within this many points of the current belief are
69
+ /// not corrections (text metrics jitter, snap rounding).
70
+ pub const virtual_extent_epsilon: f32 = 0.25;
71
+
72
+ fn nonNegativeFinite(value: f32) f32 {
73
+ if (!std.math.isFinite(value) or value < 0) return 0;
74
+ return value;
75
+ }
76
+
77
+ /// What `sync` observed about the data change since the last build —
78
+ /// enough for the caller to implement tail anchoring (stick to the
79
+ /// bottom on append) without retaining its own copy of the counts.
80
+ pub const VirtualExtentSyncInfo = struct {
81
+ /// The table had no prior state for this list (first build, or the
82
+ /// slot was recycled): callers should treat retained offsets as
83
+ /// authoritative and skip anchoring heuristics.
84
+ fresh: bool = false,
85
+ /// Items appended at the tail (same base, count grew).
86
+ appended: bool = false,
87
+ /// Items prepended at the head (`index_base` decreased); their
88
+ /// estimated extent was already folded into `pending_offset_delta`.
89
+ prepended: bool = false,
90
+ /// Total content extent BEFORE this sync (estimates + corrections +
91
+ /// gaps), for was-at-bottom checks. 0 when `fresh`.
92
+ old_total_extent: f32 = 0,
93
+ };
94
+
95
+ pub const VirtualExtentSyncArgs = struct {
96
+ /// List identity (the virtual list's global widget id).
97
+ id: u64,
98
+ item_count: usize,
99
+ /// Logical index of physical item 0. Decrease it (by the prepended
100
+ /// count) when loading older history; increase it when the head is
101
+ /// truncated (bounded transcripts compacting old rows away).
102
+ index_base: u64 = 0,
103
+ /// Vertical gap between rows (part of the stride, not of extents).
104
+ gap: f32 = 0,
105
+ estimate_context: ?*const anyopaque = null,
106
+ /// Null falls back to `uniform_estimate` for every item — the seam
107
+ /// uniform lists use when they only need tail anchoring.
108
+ estimate_fn: ?VirtualExtentEstimateFn = null,
109
+ uniform_estimate: f32 = 0,
110
+ };
111
+
112
+ /// The offset table for ONE variable-extent virtual list. Retained by
113
+ /// the app loop across builds (it is ~50 KiB of fixed capacity — keep
114
+ /// it off the stack); all methods are single-threaded, called from the
115
+ /// view-build/measure path only.
116
+ pub const VirtualExtentTable = struct {
117
+ /// 0 = free slot.
118
+ id: u64 = 0,
119
+ item_count: usize = 0,
120
+ index_base: u64 = 0,
121
+ gap: f32 = 0,
122
+ estimate_context: ?*const anyopaque = null,
123
+ estimate_fn: ?VirtualExtentEstimateFn = null,
124
+ uniform_estimate: f32 = 0,
125
+
126
+ /// Number of items the chunk cache covers exactly
127
+ /// (`min(item_count, max_virtual_extent_items)`).
128
+ covered_count: usize = 0,
129
+ chunk_count: usize = 0,
130
+ /// chunk_prefix[k] = sum of estimates for physical items
131
+ /// [0, k * virtual_extent_chunk); chunk_prefix[chunk_count] covers
132
+ /// all `covered_count` items.
133
+ chunk_prefix: [max_virtual_extent_chunks + 1]f32 = undefined,
134
+
135
+ measured_count: usize = 0,
136
+ /// LOGICAL indices, sorted ascending.
137
+ measured_index: [max_virtual_measured_items]u64 = undefined,
138
+ /// measured extent - estimate at patch time.
139
+ measured_delta: [max_virtual_measured_items]f32 = undefined,
140
+ /// measured_prefix[i] = sum of measured_delta[0..i] (EXCLUSIVE of i).
141
+ measured_prefix: [max_virtual_measured_items]f32 = undefined,
142
+ measured_prefix_dirty: bool = false,
143
+ measured_total_delta: f32 = 0,
144
+
145
+ /// The offset shift that keeps the anchored row visually fixed
146
+ /// across the corrections applied since the last consume. The
147
+ /// window computation adds it to the retained scroll offset and
148
+ /// clears it — offsets and geometry move together, atomically.
149
+ pending_offset_delta: f32 = 0,
150
+
151
+ /// Geometry of the last window computation (total extent and the
152
+ /// viewport it was computed for): what the trailing anchor's
153
+ /// was-at-the-bottom check compares the retained offset against.
154
+ /// -1 total = no build yet.
155
+ last_build_total: f32 = -1,
156
+ last_build_viewport: f32 = 0,
157
+
158
+ /// Correction-batch state (between beginCorrections/endCorrections).
159
+ anchor_physical: usize = 0,
160
+ anchor_offset_before: f32 = 0,
161
+
162
+ pub fn reset(self: *VirtualExtentTable) void {
163
+ self.* = .{};
164
+ }
165
+
166
+ fn estimateAt(self: *const VirtualExtentTable, physical: usize) f32 {
167
+ if (self.estimate_fn) |estimate| {
168
+ return nonNegativeFinite(estimate(self.estimate_context, self.index_base + @as(u64, physical)));
169
+ }
170
+ return nonNegativeFinite(self.uniform_estimate);
171
+ }
172
+
173
+ /// Average covered estimate — the extrapolation extent for items
174
+ /// past the chunk-cache budget.
175
+ fn coveredAverage(self: *const VirtualExtentTable) f32 {
176
+ if (self.covered_count == 0) return 0;
177
+ return self.chunk_prefix[self.chunk_count] / @as(f32, @floatFromInt(self.covered_count));
178
+ }
179
+
180
+ fn rebuildChunkPrefixFrom(self: *VirtualExtentTable, first_chunk: usize) void {
181
+ self.covered_count = @min(self.item_count, max_virtual_extent_items);
182
+ self.chunk_count = (self.covered_count + virtual_extent_chunk - 1) / virtual_extent_chunk;
183
+ var chunk = first_chunk;
184
+ if (chunk > self.chunk_count) chunk = self.chunk_count;
185
+ while (chunk < self.chunk_count) : (chunk += 1) {
186
+ var sum: f32 = 0;
187
+ var index = chunk * virtual_extent_chunk;
188
+ const end = @min(self.covered_count, index + virtual_extent_chunk);
189
+ while (index < end) : (index += 1) sum += self.estimateAt(index);
190
+ self.chunk_prefix[chunk + 1] = self.chunk_prefix[chunk] + sum;
191
+ }
192
+ }
193
+
194
+ fn rebuildMeasuredPrefix(self: *VirtualExtentTable) void {
195
+ var sum: f32 = 0;
196
+ for (0..self.measured_count) |i| {
197
+ self.measured_prefix[i] = sum;
198
+ sum += self.measured_delta[i];
199
+ }
200
+ self.measured_total_delta = sum;
201
+ self.measured_prefix_dirty = false;
202
+ }
203
+
204
+ /// Sum of estimates for physical items [0, index).
205
+ fn estimatePrefix(self: *const VirtualExtentTable, index: usize) f32 {
206
+ const clamped = @min(index, self.item_count);
207
+ if (clamped > self.covered_count) {
208
+ const extra = @as(f32, @floatFromInt(clamped - self.covered_count));
209
+ return self.chunk_prefix[self.chunk_count] + extra * self.coveredAverage();
210
+ }
211
+ const chunk = clamped / virtual_extent_chunk;
212
+ var sum = self.chunk_prefix[chunk];
213
+ var i = chunk * virtual_extent_chunk;
214
+ while (i < clamped) : (i += 1) sum += self.estimateAt(i);
215
+ return sum;
216
+ }
217
+
218
+ /// Sum of measured deltas for logical indices < `logical`.
219
+ fn measuredDeltaBefore(self: *const VirtualExtentTable, logical: u64) f32 {
220
+ std.debug.assert(!self.measured_prefix_dirty);
221
+ // Lowest measured slot whose index is >= logical.
222
+ var low: usize = 0;
223
+ var high: usize = self.measured_count;
224
+ while (low < high) {
225
+ const mid = (low + high) / 2;
226
+ if (self.measured_index[mid] < logical) low = mid + 1 else high = mid;
227
+ }
228
+ if (low == self.measured_count) return self.measured_total_delta;
229
+ return self.measured_prefix[low];
230
+ }
231
+
232
+ fn measuredSlot(self: *const VirtualExtentTable, logical: u64) ?usize {
233
+ var low: usize = 0;
234
+ var high: usize = self.measured_count;
235
+ while (low < high) {
236
+ const mid = (low + high) / 2;
237
+ if (self.measured_index[mid] < logical) low = mid + 1 else high = mid;
238
+ }
239
+ if (low < self.measured_count and self.measured_index[low] == logical) return low;
240
+ return null;
241
+ }
242
+
243
+ /// Current belief about one item's extent: measured if visited,
244
+ /// estimate otherwise.
245
+ pub fn extentAtPhysical(self: *const VirtualExtentTable, physical: usize) f32 {
246
+ const base = self.estimateAt(physical);
247
+ if (self.measuredSlot(self.index_base + @as(u64, physical))) |slot| {
248
+ return @max(0, base + self.measured_delta[slot]);
249
+ }
250
+ return base;
251
+ }
252
+
253
+ /// Leading edge of item `physical` (gaps between prior rows
254
+ /// included).
255
+ pub fn offsetAtPhysical(self: *const VirtualExtentTable, physical: usize) f32 {
256
+ const clamped = @min(physical, self.item_count);
257
+ return self.estimatePrefix(clamped) +
258
+ self.measuredDeltaBefore(self.index_base + @as(u64, clamped)) +
259
+ self.gap * @as(f32, @floatFromInt(clamped));
260
+ }
261
+
262
+ /// Total content extent: every extent plus the gaps between rows.
263
+ pub fn totalExtent(self: *const VirtualExtentTable) f32 {
264
+ if (self.item_count == 0) return 0;
265
+ return self.estimatePrefix(self.item_count) + self.measured_total_delta +
266
+ self.gap * @as(f32, @floatFromInt(self.item_count - 1));
267
+ }
268
+
269
+ /// The item whose span contains `offset` (the first visible item at
270
+ /// a scroll offset). Monotone bisection over `offsetAtPhysical`.
271
+ pub fn indexAtOffset(self: *const VirtualExtentTable, offset: f32) usize {
272
+ if (self.item_count == 0) return 0;
273
+ const target = @max(0, offset);
274
+ // Largest index whose leading edge is <= target.
275
+ var low: usize = 0;
276
+ var high: usize = self.item_count - 1;
277
+ while (low < high) {
278
+ const mid = (low + high + 1) / 2;
279
+ if (self.offsetAtPhysical(mid) <= target) low = mid else high = mid - 1;
280
+ }
281
+ return low;
282
+ }
283
+
284
+ /// Reconcile the table against the model's current shape. Detects
285
+ /// appends, prepends (base decreased), head truncation (base
286
+ /// increased), and shrinks; folds prepend/truncation extent into
287
+ /// `pending_offset_delta` so the viewport stays put.
288
+ pub fn sync(self: *VirtualExtentTable, args: VirtualExtentSyncArgs) VirtualExtentSyncInfo {
289
+ std.debug.assert(args.id != 0);
290
+ if (self.id != args.id) self.reset();
291
+ // Estimate plumbing refreshes every build (fn/context/gap may
292
+ // be view-local values); the cached sums only rebuild on shape
293
+ // changes, so a stale-looking fn pointer never forces O(n).
294
+ self.estimate_context = args.estimate_context;
295
+ self.estimate_fn = args.estimate_fn;
296
+ self.uniform_estimate = args.uniform_estimate;
297
+
298
+ if (self.id == 0) {
299
+ self.id = args.id;
300
+ self.item_count = args.item_count;
301
+ self.index_base = args.index_base;
302
+ self.gap = nonNegativeFinite(args.gap);
303
+ self.chunk_prefix[0] = 0;
304
+ self.rebuildChunkPrefixFrom(0);
305
+ self.rebuildMeasuredPrefix();
306
+ return .{ .fresh = true };
307
+ }
308
+
309
+ var info = VirtualExtentSyncInfo{ .old_total_extent = self.totalExtent() };
310
+ const old_base = self.index_base;
311
+ const old_count = self.item_count;
312
+ self.gap = nonNegativeFinite(args.gap);
313
+
314
+ if (args.index_base < old_base) {
315
+ // Prepend: logical identities (and measured extents) keep;
316
+ // every retained item's offset grows by the new head's
317
+ // extent, so the same shift keeps the viewport stable.
318
+ // Entries past a simultaneously truncated tail drop.
319
+ self.dropMeasuredAtOrAbove(args.index_base + @as(u64, args.item_count));
320
+ self.index_base = args.index_base;
321
+ self.item_count = args.item_count;
322
+ self.rebuildChunkPrefixFrom(0);
323
+ if (self.measured_prefix_dirty) self.rebuildMeasuredPrefix();
324
+ const prepended_physical: usize = @intCast(@min(old_base - args.index_base, @as(u64, args.item_count)));
325
+ self.pending_offset_delta += self.offsetAtPhysical(prepended_physical);
326
+ info.prepended = true;
327
+ } else if (args.index_base > old_base) {
328
+ // Head truncation: rows scrolled the viewport up by the
329
+ // removed extent; measured entries outside the new logical
330
+ // range drop.
331
+ const removed_extent = self.offsetAtPhysical(@intCast(@min(args.index_base - old_base, @as(u64, old_count))));
332
+ self.dropMeasuredBelow(args.index_base);
333
+ self.dropMeasuredAtOrAbove(args.index_base + @as(u64, args.item_count));
334
+ self.index_base = args.index_base;
335
+ self.item_count = args.item_count;
336
+ self.rebuildChunkPrefixFrom(0);
337
+ self.pending_offset_delta -= removed_extent;
338
+ } else if (args.item_count > old_count) {
339
+ // Append: only the tail chunks change.
340
+ self.item_count = args.item_count;
341
+ self.rebuildChunkPrefixFrom(old_count / virtual_extent_chunk);
342
+ info.appended = true;
343
+ } else if (args.item_count < old_count) {
344
+ self.dropMeasuredAtOrAbove(self.index_base + @as(u64, args.item_count));
345
+ self.item_count = args.item_count;
346
+ self.rebuildChunkPrefixFrom(args.item_count / virtual_extent_chunk);
347
+ }
348
+ if (self.measured_prefix_dirty) self.rebuildMeasuredPrefix();
349
+ return info;
350
+ }
351
+
352
+ fn dropMeasuredBelow(self: *VirtualExtentTable, logical: u64) void {
353
+ var keep_from: usize = 0;
354
+ while (keep_from < self.measured_count and self.measured_index[keep_from] < logical) keep_from += 1;
355
+ if (keep_from == 0) return;
356
+ const remaining = self.measured_count - keep_from;
357
+ std.mem.copyForwards(u64, self.measured_index[0..remaining], self.measured_index[keep_from..self.measured_count]);
358
+ std.mem.copyForwards(f32, self.measured_delta[0..remaining], self.measured_delta[keep_from..self.measured_count]);
359
+ self.measured_count = remaining;
360
+ self.measured_prefix_dirty = true;
361
+ }
362
+
363
+ fn dropMeasuredAtOrAbove(self: *VirtualExtentTable, logical: u64) void {
364
+ while (self.measured_count > 0 and self.measured_index[self.measured_count - 1] >= logical) {
365
+ self.measured_count -= 1;
366
+ }
367
+ self.measured_prefix_dirty = true;
368
+ }
369
+
370
+ /// Start a correction batch anchored on `anchor_physical` (the first
371
+ /// visible row). `rendered_offset` is the anchor's ACTUAL rendered
372
+ /// leading edge this frame — mounted rows stack at intrinsic
373
+ /// heights, which diverge from the table's pre-measure belief
374
+ /// exactly when unmeasured rows sit inside the window, and the
375
+ /// anchoring invariant is about what the user SEES. Null (pure
376
+ /// table-space callers) falls back to the table's current belief.
377
+ /// `endCorrections` folds the anchor's post-correction offset minus
378
+ /// this baseline into `pending_offset_delta`.
379
+ pub fn beginCorrections(self: *VirtualExtentTable, anchor_physical: usize, rendered_offset: ?f32) void {
380
+ std.debug.assert(!self.measured_prefix_dirty);
381
+ self.anchor_physical = @min(anchor_physical, self.item_count);
382
+ self.anchor_offset_before = rendered_offset orelse self.offsetAtPhysical(self.anchor_physical);
383
+ }
384
+
385
+ /// Record one mounted row's measured extent. No-op inside the
386
+ /// epsilon band. When the measured store is full, the entry
387
+ /// FARTHEST from the anchor is evicted (its row drifts back to its
388
+ /// estimate until revisited) — the incoming measurement is dropped
389
+ /// instead if IT is the farthest.
390
+ pub fn recordMeasured(self: *VirtualExtentTable, physical: usize, extent: f32) void {
391
+ if (physical >= self.item_count) return;
392
+ const logical = self.index_base + @as(u64, physical);
393
+ const clean = nonNegativeFinite(extent);
394
+ const estimate = self.estimateAt(physical);
395
+ const delta = clean - estimate;
396
+
397
+ if (self.measuredSlot(logical)) |slot| {
398
+ if (@abs(self.measured_delta[slot] - delta) <= virtual_extent_epsilon) return;
399
+ self.measured_delta[slot] = delta;
400
+ self.measured_prefix_dirty = true;
401
+ return;
402
+ }
403
+ if (@abs(delta) <= virtual_extent_epsilon) return;
404
+
405
+ if (self.measured_count >= max_virtual_measured_items) {
406
+ const anchor_logical = self.index_base + @as(u64, self.anchor_physical);
407
+ const first_distance = absDistance(self.measured_index[0], anchor_logical);
408
+ const last_distance = absDistance(self.measured_index[self.measured_count - 1], anchor_logical);
409
+ const incoming_distance = absDistance(logical, anchor_logical);
410
+ const evict_last = last_distance >= first_distance;
411
+ const evict_distance = if (evict_last) last_distance else first_distance;
412
+ if (incoming_distance >= evict_distance) return;
413
+ if (evict_last) {
414
+ self.measured_count -= 1;
415
+ } else {
416
+ std.mem.copyForwards(u64, self.measured_index[0 .. self.measured_count - 1], self.measured_index[1..self.measured_count]);
417
+ std.mem.copyForwards(f32, self.measured_delta[0 .. self.measured_count - 1], self.measured_delta[1..self.measured_count]);
418
+ self.measured_count -= 1;
419
+ }
420
+ self.measured_prefix_dirty = true;
421
+ }
422
+
423
+ // Insert sorted (windows arrive in ascending order, so this is
424
+ // usually an append or a near-tail insert).
425
+ var slot = self.measured_count;
426
+ while (slot > 0 and self.measured_index[slot - 1] > logical) : (slot -= 1) {}
427
+ std.mem.copyBackwards(u64, self.measured_index[slot + 1 .. self.measured_count + 1], self.measured_index[slot..self.measured_count]);
428
+ std.mem.copyBackwards(f32, self.measured_delta[slot + 1 .. self.measured_count + 1], self.measured_delta[slot..self.measured_count]);
429
+ self.measured_index[slot] = logical;
430
+ self.measured_delta[slot] = delta;
431
+ self.measured_count += 1;
432
+ self.measured_prefix_dirty = true;
433
+ }
434
+
435
+ /// Close the batch: refresh the delta prefix sums and record the
436
+ /// anchor's offset shift so the next window computation moves the
437
+ /// scroll offset by exactly the amount that keeps the anchored row
438
+ /// where the user sees it.
439
+ pub fn endCorrections(self: *VirtualExtentTable) void {
440
+ if (self.measured_prefix_dirty) self.rebuildMeasuredPrefix();
441
+ self.pending_offset_delta += self.offsetAtPhysical(self.anchor_physical) - self.anchor_offset_before;
442
+ }
443
+
444
+ /// The accumulated anchor-preserving offset shift, consumed exactly
445
+ /// once per window computation.
446
+ pub fn takePendingOffsetDelta(self: *VirtualExtentTable) f32 {
447
+ const delta = self.pending_offset_delta;
448
+ self.pending_offset_delta = 0;
449
+ return delta;
450
+ }
451
+ };
452
+
453
+ fn absDistance(a: u64, b: u64) u64 {
454
+ return if (a > b) a - b else b - a;
455
+ }
456
+
457
+ /// Options for a variable-extent window computation (the counterpart of
458
+ /// `VirtualListOptions` for `virtualListRange`).
459
+ pub const VirtualVariableRangeOptions = struct {
460
+ item_count: usize = 0,
461
+ gap: f32 = 0,
462
+ viewport_extent: f32 = 0,
463
+ scroll_offset: f32 = 0,
464
+ overscan: usize = 0,
465
+ index_base: u64 = 0,
466
+ estimate_context: ?*const anyopaque = null,
467
+ estimate_fn: ?VirtualExtentEstimateFn = null,
468
+ uniform_estimate: f32 = 0,
469
+ };
470
+
471
+ /// The result shape shared with the uniform path lives in tokens.zig
472
+ /// (`VirtualListRange`); this module returns plain numbers and lets the
473
+ /// caller assemble it, keeping tokens.zig byte-identical.
474
+ pub const VirtualVariableRange = struct {
475
+ start_index: usize = 0,
476
+ end_index: usize = 0,
477
+ first_visible_index: usize = 0,
478
+ last_visible_index: usize = 0,
479
+ scroll_offset: f32 = 0,
480
+ layout_offset: f32 = 0,
481
+ content_extent: f32 = 0,
482
+ before_extent: f32 = 0,
483
+ after_extent: f32 = 0,
484
+ /// Leading edge of `first_visible_index` — the layout anchor.
485
+ anchor_extent: f32 = 0,
486
+ };
487
+
488
+ /// Compute the visible+overscan window for a variable-extent list. With
489
+ /// a `table` the offsets carry every measured correction; without one
490
+ /// (bare builds, plain `finalize` tests) the math runs on pure
491
+ /// estimates via a linear scan — O(item_count) worst case, fine for
492
+ /// tests, which is why app loops always install a table.
493
+ pub fn virtualVariableListRange(options: VirtualVariableRangeOptions, table: ?*const VirtualExtentTable) VirtualVariableRange {
494
+ if (options.item_count == 0 or options.viewport_extent <= 0) return .{};
495
+ const gap = nonNegativeFinite(options.gap);
496
+ const viewport = options.viewport_extent;
497
+
498
+ var scratch = VirtualExtentTable{};
499
+ const source: *const VirtualExtentTable = table orelse blk: {
500
+ // Stateless fallback: a throwaway estimate-only table built on
501
+ // the spot (no measured corrections to preserve). The chunk
502
+ // sums cost one pass over the estimates per call — bare-build
503
+ // pricing, not app-loop pricing.
504
+ scratch.id = 1;
505
+ scratch.item_count = options.item_count;
506
+ scratch.index_base = options.index_base;
507
+ scratch.gap = gap;
508
+ scratch.estimate_context = options.estimate_context;
509
+ scratch.estimate_fn = options.estimate_fn;
510
+ scratch.uniform_estimate = options.uniform_estimate;
511
+ scratch.chunk_prefix[0] = 0;
512
+ scratch.rebuildChunkPrefixFrom(0);
513
+ break :blk &scratch;
514
+ };
515
+
516
+ const content_extent = source.totalExtent();
517
+ const max_offset = @max(0, content_extent - viewport);
518
+ const raw_offset = if (std.math.isFinite(options.scroll_offset)) options.scroll_offset else 0;
519
+ const offset = std.math.clamp(@max(0, raw_offset), 0, max_offset);
520
+ const layout_offset = std.math.clamp(raw_offset, -viewport, max_offset + viewport);
521
+
522
+ const first_visible = @min(options.item_count - 1, source.indexAtOffset(offset));
523
+ var visible_end = @min(options.item_count, source.indexAtOffset(offset + viewport) + 1);
524
+ if (visible_end <= first_visible) visible_end = first_visible + 1;
525
+ const start_index = if (first_visible > options.overscan) first_visible - options.overscan else 0;
526
+ const end_index = @min(options.item_count, visible_end + options.overscan);
527
+
528
+ return .{
529
+ .start_index = start_index,
530
+ .end_index = end_index,
531
+ .first_visible_index = first_visible,
532
+ .last_visible_index = visible_end - 1,
533
+ .scroll_offset = offset,
534
+ .layout_offset = layout_offset,
535
+ .content_extent = content_extent,
536
+ .before_extent = source.offsetAtPhysical(start_index),
537
+ .after_extent = @max(0, content_extent - source.offsetAtPhysical(end_index)),
538
+ .anchor_extent = source.offsetAtPhysical(first_visible),
539
+ };
540
+ }