@native-sdk/cli 0.10.0 → 0.11.0

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 (465) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +320 -60
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +1818 -87
  8. package/package.json +19 -14
  9. package/packages/core/compile-surface/core.ts +134 -72
  10. package/packages/core/package-lock.json +75 -357
  11. package/packages/core/package.json +25 -4
  12. package/packages/core/scripts/compiler_command.mjs +17 -12
  13. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  14. package/packages/core/scripts/gen_declarations.mjs +3 -2
  15. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  16. package/packages/core/scripts/install_scriptc.mjs +182 -0
  17. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  18. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  19. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  20. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  21. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  22. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  23. package/packages/core/scripts/run_native_tests.mjs +22 -0
  24. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  25. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  26. package/packages/core/scripts/stage_external_core.mjs +57 -1
  27. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  28. package/packages/core/sdk/bytes.d.ts +2 -0
  29. package/packages/core/sdk/bytes.ts +86 -0
  30. package/packages/core/sdk/core.d.ts +308 -4
  31. package/packages/core/sdk/core.ts +320 -84
  32. package/packages/core/sdk/events.d.ts +247 -0
  33. package/packages/core/sdk/events.ts +230 -2
  34. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  35. package/packages/core/sdk/internal/image_identity.ts +71 -0
  36. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  37. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  38. package/packages/core/sdk/text.d.ts +27 -0
  39. package/packages/core/sdk/text.ts +206 -15
  40. package/packages/core/sdk/theme.d.ts +251 -0
  41. package/packages/core/sdk/theme.ts +267 -0
  42. package/packages/core/src/authorization.ts +137 -0
  43. package/packages/core/src/automation_commands.ts +201 -0
  44. package/packages/core/src/automation_interactions.ts +92 -0
  45. package/packages/core/src/bridge_descriptors.ts +104 -0
  46. package/packages/core/src/builtin_coordination.ts +172 -0
  47. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  48. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  49. package/packages/core/src/canvas_scene_observation.ts +145 -0
  50. package/packages/core/src/chart_content.ts +161 -0
  51. package/packages/core/src/chart_plans.ts +432 -0
  52. package/packages/core/src/checker.ts +166 -19
  53. package/packages/core/src/code_content.ts +580 -0
  54. package/packages/core/src/command_coordination.ts +140 -0
  55. package/packages/core/src/component_composition.ts +94 -0
  56. package/packages/core/src/component_construction.ts +149 -0
  57. package/packages/core/src/contract.ts +25 -7
  58. package/packages/core/src/control_appearance.ts +232 -0
  59. package/packages/core/src/control_commands.ts +115 -0
  60. package/packages/core/src/control_content.ts +105 -0
  61. package/packages/core/src/control_geometry.ts +107 -0
  62. package/packages/core/src/control_payloads.ts +119 -0
  63. package/packages/core/src/control_primitives.ts +134 -0
  64. package/packages/core/src/devhost.ts +82 -7
  65. package/packages/core/src/devhost_journal.mjs +30 -7
  66. package/packages/core/src/effect_plans.ts +71 -0
  67. package/packages/core/src/flow_measurement.ts +121 -0
  68. package/packages/core/src/font_registry.ts +37 -0
  69. package/packages/core/src/glyph_atlas.ts +86 -0
  70. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  71. package/packages/core/src/gpu_planning.ts +123 -0
  72. package/packages/core/src/gpu_presentation.ts +55 -0
  73. package/packages/core/src/host_flow.ts +89 -0
  74. package/packages/core/src/host_input_regions.ts +165 -0
  75. package/packages/core/src/image_registry.ts +66 -0
  76. package/packages/core/src/indicator_plans.ts +132 -0
  77. package/packages/core/src/infer.ts +150 -8
  78. package/packages/core/src/input_composition.ts +116 -0
  79. package/packages/core/src/intrinsic_measure.ts +100 -0
  80. package/packages/core/src/layout_coordination.ts +207 -0
  81. package/packages/core/src/leaf_plans.ts +134 -0
  82. package/packages/core/src/markup_development.ts +160 -0
  83. package/packages/core/src/measurement_coordination.ts +185 -0
  84. package/packages/core/src/modules.ts +1 -1
  85. package/packages/core/src/motion_sampling.ts +100 -0
  86. package/packages/core/src/paragraph_layout.ts +192 -0
  87. package/packages/core/src/portable_sources.json +74 -0
  88. package/packages/core/src/portable_sources.ts +17 -0
  89. package/packages/core/src/registered_font.ts +93 -0
  90. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  91. package/packages/core/src/render_coordination.ts +170 -0
  92. package/packages/core/src/render_resources.ts +234 -0
  93. package/packages/core/src/runtime_policy.ts +3930 -0
  94. package/packages/core/src/scalar_text.ts +84 -0
  95. package/packages/core/src/service_contract.ts +2 -1
  96. package/packages/core/src/session_codecs.ts +309 -0
  97. package/packages/core/src/shell_admission.ts +126 -0
  98. package/packages/core/src/shell_coordination.ts +93 -0
  99. package/packages/core/src/sqlite_cli.ts +11 -0
  100. package/packages/core/src/status_validation.ts +232 -0
  101. package/packages/core/src/stream_policy.ts +63 -0
  102. package/packages/core/src/surface_recipes.ts +136 -0
  103. package/packages/core/src/system_admission.ts +60 -0
  104. package/packages/core/src/terminal_paint.ts +436 -0
  105. package/packages/core/src/text_document_width.ts +81 -0
  106. package/packages/core/src/text_measurement_cache.ts +69 -0
  107. package/packages/core/src/text_query_layout.ts +179 -0
  108. package/packages/core/src/text_run_layout.ts +410 -0
  109. package/packages/core/src/text_span_queries.ts +355 -0
  110. package/packages/core/src/typed_ast.ts +18 -1
  111. package/packages/core/src/types.ts +7 -5
  112. package/packages/core/src/vector_effects.ts +98 -0
  113. package/packages/core/src/vector_raster.ts +243 -0
  114. package/packages/core/src/view_components.ts +2415 -0
  115. package/packages/core/src/view_coordination.ts +198 -0
  116. package/packages/core/src/view_frontend.ts +980 -0
  117. package/packages/core/src/widget_audits.ts +202 -0
  118. package/packages/core/src/widget_changes.ts +258 -0
  119. package/packages/core/src/widget_metrics.ts +139 -0
  120. package/packages/core/src/widget_motion.ts +171 -0
  121. package/packages/core/src/widget_paint.ts +272 -0
  122. package/packages/core/src/widget_paint_walk.ts +203 -0
  123. package/packages/core/src/widget_presentation.ts +141 -0
  124. package/packages/core/src/widget_routing.ts +262 -0
  125. package/packages/core/src/window_lifecycle.ts +92 -0
  126. package/packages/core/testing/index.ts +430 -0
  127. package/schemas/app.schema.json +13 -0
  128. package/skill-data/core/SKILL.md +2 -2
  129. package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
  130. package/skill-data/native-ui/SKILL.md +76 -17
  131. package/skill-data/ts-core/SKILL.md +113 -9
  132. package/skill-data/ts-services/SKILL.md +1 -1
  133. package/skill-data/ts-services/references/service-surface.md +264 -144
  134. package/src/app_runner/root.zig +25 -12
  135. package/src/app_runner/ts_compiled_view.zig +1631 -0
  136. package/src/app_runner/ts_core_main.zig +143 -10
  137. package/src/app_runner/ts_core_mobile.zig +24 -12
  138. package/src/automation/server.zig +1 -3
  139. package/src/automation/snapshot.zig +9 -637
  140. package/src/automation/snapshot_reference.zig +656 -0
  141. package/src/automation/snapshot_serialization.zig +566 -0
  142. package/src/platform/linux/gtk_host.c +36 -24
  143. package/src/platform/linux/gtk_pixels.h +118 -0
  144. package/src/platform/linux/gtk_pixels_test.c +241 -0
  145. package/src/platform/linux/root.zig +2 -0
  146. package/src/platform/macos/appkit_host.m +188 -30
  147. package/src/platform/macos/pointer_motion_test.m +96 -0
  148. package/src/platform/macos/scroll_driver_test.m +105 -0
  149. package/src/platform/macos/spectrum_bins.h +34 -0
  150. package/src/platform/macos/spectrum_bins_test.c +56 -0
  151. package/src/platform/macos/text_keyboard_test.m +80 -0
  152. package/src/platform/macos/widget_focus_test.m +66 -0
  153. package/src/platform/null_platform.zig +26 -2
  154. package/src/platform/null_platform_tests.zig +13 -0
  155. package/src/platform/root.zig +1 -0
  156. package/src/platform/types.zig +13 -0
  157. package/src/platform/windows/root.zig +2 -0
  158. package/src/platform/windows/webview2_host.cpp +7 -2
  159. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  160. package/src/primitives/app_manifest/root.zig +2 -0
  161. package/src/primitives/app_manifest/tests.zig +4 -1
  162. package/src/primitives/app_manifest/validation.zig +2 -0
  163. package/src/primitives/canvas/a11y_audit.zig +3 -1
  164. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  165. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  166. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  167. package/src/primitives/canvas/code_content_policy.zig +162 -0
  168. package/src/primitives/canvas/commands.zig +29 -1
  169. package/src/primitives/canvas/component_composition.zig +125 -0
  170. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  171. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  172. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  173. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  174. package/src/primitives/canvas/control_command_policy.zig +75 -0
  175. package/src/primitives/canvas/control_content_policy.zig +90 -0
  176. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  177. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  178. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  179. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  180. package/src/primitives/canvas/events.zig +1027 -1
  181. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  182. package/src/primitives/canvas/frame.zig +92 -23
  183. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  184. package/src/primitives/canvas/gpu.zig +10 -0
  185. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  186. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  187. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  188. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  189. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  190. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  191. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  192. package/src/primitives/canvas/layout_audit.zig +5 -2
  193. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  194. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  195. package/src/primitives/canvas/markdown.zig +13 -3
  196. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  197. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  198. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  199. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  200. package/src/primitives/canvas/reference.zig +12 -6
  201. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  202. package/src/primitives/canvas/render.zig +48 -0
  203. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  204. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  205. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  206. package/src/primitives/canvas/render_effects.zig +14 -0
  207. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  208. package/src/primitives/canvas/render_images.zig +14 -0
  209. package/src/primitives/canvas/render_layers.zig +14 -0
  210. package/src/primitives/canvas/render_override_policy.zig +119 -0
  211. package/src/primitives/canvas/render_paths.zig +14 -0
  212. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  213. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  214. package/src/primitives/canvas/root.zig +100 -0
  215. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  216. package/src/primitives/canvas/serialization.zig +8 -1
  217. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  218. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  219. package/src/primitives/canvas/terminal_grid.zig +10 -696
  220. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  221. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  222. package/src/primitives/canvas/text.zig +1 -0
  223. package/src/primitives/canvas/text_atlas.zig +113 -0
  224. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  225. package/src/primitives/canvas/text_document_policy.zig +120 -0
  226. package/src/primitives/canvas/text_layout.zig +51 -2
  227. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  228. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  229. package/src/primitives/canvas/text_layout_types.zig +3 -0
  230. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  231. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  232. package/src/primitives/canvas/text_metrics.zig +23 -0
  233. package/src/primitives/canvas/text_query_policy.zig +156 -0
  234. package/src/primitives/canvas/text_run_policy.zig +252 -0
  235. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  236. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  237. package/src/primitives/canvas/text_spans.zig +280 -8
  238. package/src/primitives/canvas/text_tests.zig +10 -0
  239. package/src/primitives/canvas/tokens.zig +38 -0
  240. package/src/primitives/canvas/ui.zig +250 -83
  241. package/src/primitives/canvas/ui_markup.zig +139 -33
  242. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  243. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  244. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  245. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  246. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  247. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  248. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  249. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  250. package/src/primitives/canvas/ui_schema.zig +13 -1
  251. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  252. package/src/primitives/canvas/ui_tests.zig +1 -0
  253. package/src/primitives/canvas/vector.zig +36 -2
  254. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  255. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  256. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  257. package/src/primitives/canvas/virtual_extents.zig +99 -3
  258. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  259. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  260. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  261. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  262. package/src/primitives/canvas/widget_layout.zig +673 -128
  263. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  264. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  265. package/src/primitives/canvas/widget_metrics.zig +45 -6
  266. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  267. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  268. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  269. package/src/primitives/canvas/widget_render.zig +744 -74
  270. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  271. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  272. package/src/primitives/canvas/widget_render_style.zig +94 -0
  273. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  274. package/src/primitives/canvas/widget_routing.zig +75 -0
  275. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  276. package/src/primitives/canvas/widget_runtime.zig +20 -1
  277. package/src/primitives/canvas/widget_semantics.zig +25 -0
  278. package/src/primitives/canvas/widget_text_input.zig +86 -23
  279. package/src/primitives/canvas/widget_text_select.zig +1 -0
  280. package/src/primitives/canvas/widget_tree.zig +8 -1
  281. package/src/primitives/canvas/widgets.zig +42 -12
  282. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  283. package/src/root.zig +21 -0
  284. package/src/runtime/accessibility_policy.zig +122 -0
  285. package/src/runtime/api.zig +28 -0
  286. package/src/runtime/app_dispatch_policy.zig +68 -0
  287. package/src/runtime/authorization_policy.zig +150 -0
  288. package/src/runtime/automation_command_policy.zig +241 -0
  289. package/src/runtime/automation_interaction_policy.zig +107 -0
  290. package/src/runtime/automation_snapshot.zig +52 -22
  291. package/src/runtime/automation_snapshot_reference.zig +290 -0
  292. package/src/runtime/automation_widget_dispatch.zig +267 -355
  293. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  294. package/src/runtime/blob_policy.zig +58 -0
  295. package/src/runtime/blob_reference.zig +64 -0
  296. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  297. package/src/runtime/builtin_bridge.zig +180 -44
  298. package/src/runtime/builtin_coordination_policy.zig +121 -0
  299. package/src/runtime/callback_policy_test_reference.zig +97 -0
  300. package/src/runtime/canvas_drag_policy.zig +94 -0
  301. package/src/runtime/canvas_fonts.zig +38 -10
  302. package/src/runtime/canvas_frame.zig +590 -134
  303. package/src/runtime/canvas_frame_helpers.zig +1 -0
  304. package/src/runtime/canvas_hover_policy.zig +131 -0
  305. package/src/runtime/canvas_images.zig +59 -30
  306. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  307. package/src/runtime/canvas_limits.zig +1 -1
  308. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  309. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  310. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  311. package/src/runtime/canvas_widget_display.zig +110 -9
  312. package/src/runtime/canvas_widget_events.zig +718 -328
  313. package/src/runtime/canvas_widget_runtime.zig +437 -81
  314. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  315. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  316. package/src/runtime/canvas_widget_state.zig +93 -56
  317. package/src/runtime/channel_sources.zig +80 -0
  318. package/src/runtime/command_policy.zig +161 -0
  319. package/src/runtime/component_policy.zig +83 -0
  320. package/src/runtime/core.zig +156 -6
  321. package/src/runtime/desktop_files.zig +189 -0
  322. package/src/runtime/effects.zig +466 -29
  323. package/src/runtime/effects_tests.zig +28 -0
  324. package/src/runtime/file_policy_test_reference.zig +113 -0
  325. package/src/runtime/flow.zig +418 -341
  326. package/src/runtime/flow_reference.zig +1426 -0
  327. package/src/runtime/font_registry_policy.zig +72 -0
  328. package/src/runtime/frame_profile.zig +24 -33
  329. package/src/runtime/gpu_surface_events.zig +97 -35
  330. package/src/runtime/host_event_pump.zig +303 -0
  331. package/src/runtime/host_event_pump_reference.zig +268 -0
  332. package/src/runtime/host_flow_policy.zig +155 -0
  333. package/src/runtime/host_input_regions_policy.zig +156 -0
  334. package/src/runtime/image_registry_policy.zig +94 -0
  335. package/src/runtime/input_composition_policy.zig +138 -0
  336. package/src/runtime/journal_policy.zig +66 -0
  337. package/src/runtime/journal_reference.zig +53 -0
  338. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  339. package/src/runtime/markup_development_policy.zig +91 -0
  340. package/src/runtime/media_surface.zig +40 -1
  341. package/src/runtime/motion_sampling_policy.zig +159 -0
  342. package/src/runtime/recording_policy.zig +42 -0
  343. package/src/runtime/render_animation_policy.zig +206 -0
  344. package/src/runtime/replay_policy.zig +66 -0
  345. package/src/runtime/replay_policy_reference.zig +326 -0
  346. package/src/runtime/replay_progress_policy.zig +64 -0
  347. package/src/runtime/replay_progress_reference.zig +34 -0
  348. package/src/runtime/request_policy_test_reference.zig +188 -0
  349. package/src/runtime/root.zig +13 -0
  350. package/src/runtime/session_blobs.zig +157 -58
  351. package/src/runtime/session_blobs_reference.zig +692 -0
  352. package/src/runtime/session_codec.zig +361 -0
  353. package/src/runtime/session_codec_reference.zig +1027 -0
  354. package/src/runtime/session_journal.zig +246 -983
  355. package/src/runtime/session_record.zig +224 -45
  356. package/src/runtime/session_replay.zig +157 -415
  357. package/src/runtime/session_tests.zig +552 -0
  358. package/src/runtime/shell_admission_policy.zig +225 -0
  359. package/src/runtime/shell_coordination_policy.zig +138 -0
  360. package/src/runtime/shell_layout.zig +126 -1
  361. package/src/runtime/snapshot_policy.zig +60 -0
  362. package/src/runtime/snapshot_reference.zig +64 -0
  363. package/src/runtime/state.zig +16 -0
  364. package/src/runtime/status_validation.zig +190 -0
  365. package/src/runtime/system_admission_policy.zig +140 -0
  366. package/src/runtime/system_services.zig +46 -36
  367. package/src/runtime/tests.zig +1 -0
  368. package/src/runtime/ts_canvas_hooks.zig +261 -0
  369. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  370. package/src/runtime/ts_canvas_icons.zig +234 -0
  371. package/src/runtime/ts_core_host.zig +2325 -411
  372. package/src/runtime/ts_core_host_tests.zig +1982 -0
  373. package/src/runtime/ts_test_host.zig +699 -0
  374. package/src/runtime/ts_ui_app.zig +1087 -45
  375. package/src/runtime/ui_app.zig +1117 -629
  376. package/src/runtime/ui_app_provenance.zig +147 -5
  377. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  378. package/src/runtime/ui_app_tests.zig +619 -9
  379. package/src/runtime/ui_app_window_tests.zig +89 -0
  380. package/src/runtime/view.zig +25 -0
  381. package/src/runtime/view_canvas.zig +30 -6
  382. package/src/runtime/view_coordination_policy.zig +147 -0
  383. package/src/runtime/view_widget_control.zig +51 -14
  384. package/src/runtime/view_widget_scroll.zig +16 -5
  385. package/src/runtime/view_widget_text.zig +153 -68
  386. package/src/runtime/view_widget_tree.zig +460 -56
  387. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  388. package/src/runtime/widget_motion_policy.zig +238 -0
  389. package/src/runtime/window_command_bridge_tests.zig +63 -0
  390. package/src/runtime/window_lifecycle_policy.zig +127 -0
  391. package/src/runtime/window_storage.zig +74 -8
  392. package/src/runtime/window_view_runtime.zig +148 -33
  393. package/src/runtime/window_views.zig +163 -10
  394. package/src/tooling/codesign.zig +125 -74
  395. package/src/tooling/components/identity_tests.zig +62 -36
  396. package/src/tooling/components/stepper.native +24 -0
  397. package/src/tooling/components/stepper.zig +0 -19
  398. package/src/tooling/components/timeline-item.native +22 -0
  399. package/src/tooling/components/timeline.native +5 -3
  400. package/src/tooling/components/timeline_item.zig +0 -32
  401. package/src/tooling/eject_components.zig +76 -8
  402. package/src/tooling/ios.zig +66 -12
  403. package/src/tooling/manifest.zig +35 -0
  404. package/src/tooling/package.zig +85 -1
  405. package/src/tooling/raw_manifest.zig +6 -0
  406. package/src/tooling/templates.zig +15 -3
  407. package/src/tooling/ts_core.zig +13 -3
  408. package/src/tooling/verbs.zig +22 -0
  409. package/tools/corewire/build_profile.mjs +54 -0
  410. package/tools/corewire/contract_intake.ts +303 -0
  411. package/tools/corewire/contract_intake.zig +82 -0
  412. package/tools/corewire/core.test.ts +166 -0
  413. package/tools/corewire/core_abi.zig +51 -0
  414. package/tools/corewire/core_cases.ts +233 -0
  415. package/tools/corewire/core_contract.ts +407 -0
  416. package/tools/corewire/core_emission.ts +136 -0
  417. package/tools/corewire/core_emission.zig +69 -0
  418. package/tools/corewire/core_goldens.json +3110 -0
  419. package/tools/corewire/core_policy.ts +14 -0
  420. package/tools/corewire/core_policy.zig +48 -0
  421. package/tools/corewire/core_projection.ts +360 -0
  422. package/tools/corewire/core_vocabulary.ts +6 -0
  423. package/tools/corewire/emit.zig +19 -1590
  424. package/tools/corewire/emit_facade.ts +714 -0
  425. package/tools/corewire/emit_facade.zig +10 -3752
  426. package/tools/corewire/emit_mirror.ts +290 -0
  427. package/tools/corewire/emit_profile.ts +50 -0
  428. package/tools/corewire/emit_service.ts +331 -0
  429. package/tools/corewire/emit_service.zig +23 -842
  430. package/tools/corewire/entry.test.ts +95 -0
  431. package/tools/corewire/entry_coordination.ts +127 -0
  432. package/tools/corewire/entry_coordination.zig +190 -0
  433. package/tools/corewire/facade_templates.ts +85 -0
  434. package/tools/corewire/filesystem.test.ts +166 -0
  435. package/tools/corewire/filesystem_coordination.ts +213 -0
  436. package/tools/corewire/filesystem_coordination.zig +245 -0
  437. package/tools/corewire/intake.test.ts +35 -0
  438. package/tools/corewire/intake_cases.ts +55 -0
  439. package/tools/corewire/intake_goldens.json +12237 -0
  440. package/tools/corewire/invocation.test.ts +24 -0
  441. package/tools/corewire/invocation.ts +175 -0
  442. package/tools/corewire/invocation.zig +136 -0
  443. package/tools/corewire/invocation_cases.ts +60 -0
  444. package/tools/corewire/invocation_fixture.ts +33 -0
  445. package/tools/corewire/invocation_goldens.json +1143 -0
  446. package/tools/corewire/invocation_tests.zig +111 -0
  447. package/tools/corewire/invocation_usage.ts +2 -0
  448. package/tools/corewire/lossless_projection.ts +96 -0
  449. package/tools/corewire/main.zig +7 -680
  450. package/tools/corewire/main_reference.zig +415 -0
  451. package/tools/corewire/mirror_templates.ts +55 -0
  452. package/tools/corewire/profile.test.ts +248 -0
  453. package/tools/corewire/profile.zig +56 -0
  454. package/tools/corewire/profile_emission.ts +202 -0
  455. package/tools/corewire/profile_library.json +29 -0
  456. package/tools/corewire/profile_tests.zig +136 -0
  457. package/tools/corewire/service.test.ts +75 -0
  458. package/tools/corewire/service_cases.ts +61 -0
  459. package/tools/corewire/service_contract.zig +40 -146
  460. package/tools/corewire/service_goldens.json +650 -0
  461. package/tools/corewire/service_projection.zig +52 -0
  462. package/tools/corewire/service_templates.ts +14 -0
  463. package/tools/corewire/shim_rt.zig +9 -0
  464. package/tools/corewire/sidecar.zig +267 -1438
  465. package/tools/corewire/emit_profile.zig +0 -521
@@ -325,6 +325,7 @@ pub fn canvasWidgetPointerEventFromGpuInput(input_event: GpuSurfaceInputEvent) ?
325
325
  .phase = phase,
326
326
  .point = geometry.PointF.init(input_event.x, input_event.y),
327
327
  .delta = geometry.OffsetF.init(input_event.delta_x, input_event.delta_y),
328
+ .scroll_is_detented = input_event.scroll_is_detented,
328
329
  .pointer_id = input_event.pointer_id,
329
330
  .button = input_event.button,
330
331
  .modifiers = canvasWidgetKeyboardModifiers(input_event.modifiers),
@@ -0,0 +1,131 @@
1
+ //! Portable hover message coordination through the copied-byte surface policy.
2
+ //! Native owns exact identity bytes, layout facts, deep captures and fallible effects.
3
+ const std = @import("std");
4
+ const canvas = @import("canvas");
5
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
6
+ pub const Stage = enum(u8) { view, diff, refresh, refresh_entry, capture, leave, enter, unwind, drain, continuation };
7
+ pub const Request = struct { stage: Stage, a: u8 = 0, b: u8 = 0, facts: u8 = 0 };
8
+ pub fn decide(policy: Policy, r: Request) u8 {
9
+ if (policy) |callback| {
10
+ const bytes = [_]u8{ 36, @intFromEnum(r.stage), r.a, r.b, r.facts, 0 };
11
+ var result: [1]u8 = undefined;
12
+ if (callback(&bytes, &result) != 1) @panic("invalid compiled hover decision size");
13
+ const max: u8 = switch (r.stage) {
14
+ .view => 2,
15
+ .capture => 4,
16
+ .leave, .enter => 3,
17
+ else => 1,
18
+ };
19
+ if (result[0] > max) @panic("invalid compiled hover decision");
20
+ return result[0];
21
+ }
22
+ return reference(r);
23
+ }
24
+ pub fn reference(r: Request) u8 {
25
+ return switch (r.stage) {
26
+ .view => if (r.facts & 3 != 3) 0 else if (r.facts & 4 != 0) 2 else if (r.facts & 8 == 0) 1 else 0,
27
+ .refresh => @intFromBool(r.facts & 1 != 0 and r.facts & 2 == 0 and r.facts & 12 == 12),
28
+ .refresh_entry => @intFromBool(r.facts & 1 == 0 and r.facts & 2 != 0),
29
+ .capture => if (r.b == 0) 1 else if (r.b == 2) 4 else if (r.a == 1) 2 else if (r.facts == 0) 3 else 0,
30
+ .leave => if (r.facts & 1 != 0) 0 else if (r.facts & 2 != 0) 1 else if (r.facts & 12 == 12) 2 else 3,
31
+ .enter => if (r.facts & 1 == 0) 0 else if (r.facts & 2 == 0) 1 else if (r.facts & 12 != 12) 2 else 3,
32
+ .drain => @intFromBool(r.facts == 1),
33
+ .continuation => @intFromBool(r.a < 64 and r.facts == 1),
34
+ .diff, .unwind => unreachable,
35
+ };
36
+ }
37
+ pub const Plan = struct {
38
+ identical: bool = false,
39
+ entering: bool = false,
40
+ retained: [canvas.max_widget_depth]u8 = @splat(255),
41
+ leaving: [canvas.max_widget_depth]u8 = @splat(255),
42
+ leave_count: usize = 0,
43
+ };
44
+ pub fn plan(policy: Policy, same_view: bool, mirror: []const canvas.ObjectId, standing: []const canvas.ObjectId) Plan {
45
+ if (policy) |callback| {
46
+ var bytes: [6 + canvas.max_widget_depth * 16]u8 = undefined;
47
+ bytes[0..6].* = .{ 36, 1, @intFromBool(same_view), @intCast(mirror.len), @intCast(standing.len), 0 };
48
+ var offset: usize = 6;
49
+ for (mirror) |id| {
50
+ std.mem.writeInt(u64, bytes[offset..][0..8], id, .little);
51
+ offset += 8;
52
+ }
53
+ for (standing) |id| {
54
+ std.mem.writeInt(u64, bytes[offset..][0..8], id, .little);
55
+ offset += 8;
56
+ }
57
+ var output: [3 + canvas.max_widget_depth * 2]u8 = undefined;
58
+ const size = 3 + standing.len + mirror.len;
59
+ if (callback(bytes[0..offset], output[0..size]) != size or output[0] > 1 or output[1] > 1 or output[2] > mirror.len) @panic("invalid compiled hover plan");
60
+ var out: Plan = .{ .identical = output[0] == 1, .entering = output[1] == 1, .leave_count = output[2] };
61
+ for (output[3..][0..standing.len], 0..) |index, position| {
62
+ if (index != 255 and index >= mirror.len) @panic("invalid compiled hover retained index");
63
+ out.retained[position] = index;
64
+ }
65
+ for (output[3 + standing.len ..][0..mirror.len], 0..) |index, position| {
66
+ if (position < out.leave_count) {
67
+ if (index >= mirror.len or (position > 0 and index >= out.leaving[position - 1])) @panic("invalid compiled hover leave order");
68
+ } else if (index != 255) @panic("invalid compiled hover reserved index");
69
+ out.leaving[position] = index;
70
+ }
71
+ return out;
72
+ }
73
+ return referencePlan(same_view, mirror, standing);
74
+ }
75
+ pub fn referencePlan(same_view: bool, mirror: []const canvas.ObjectId, standing: []const canvas.ObjectId) Plan {
76
+ var out: Plan = .{ .identical = same_view and mirror.len == standing.len };
77
+ for (standing, 0..) |id, position| {
78
+ if (same_view) for (mirror, 0..) |candidate, index| {
79
+ if (candidate != id) continue;
80
+ out.retained[position] = @intCast(index);
81
+ if (position != index) out.identical = false;
82
+ break;
83
+ };
84
+ if (out.retained[position] == 255) {
85
+ out.entering = true;
86
+ out.identical = false;
87
+ }
88
+ }
89
+ var index = mirror.len;
90
+ while (index > 0) {
91
+ index -= 1;
92
+ var retained = false;
93
+ if (same_view) for (standing) |id| {
94
+ if (id == mirror[index]) {
95
+ retained = true;
96
+ break;
97
+ }
98
+ };
99
+ if (!retained) {
100
+ out.leaving[out.leave_count] = @intCast(index);
101
+ out.leave_count += 1;
102
+ }
103
+ }
104
+ return out;
105
+ }
106
+ pub const Compaction = struct { kept: [canvas.max_widget_depth]u8 = @splat(255), len: usize = 0 };
107
+ pub fn unwind(policy: Policy, entering: []const bool, from: usize) Compaction {
108
+ var out: Compaction = .{};
109
+ if (policy) |callback| {
110
+ var bytes: [6 + canvas.max_widget_depth]u8 = undefined;
111
+ bytes[0..6].* = .{ 36, 7, @intCast(from), @intCast(entering.len), 0, 0 };
112
+ for (entering, 0..) |flag, index| bytes[6 + index] = @intFromBool(flag);
113
+ var result: [1 + canvas.max_widget_depth]u8 = undefined;
114
+ const size = 1 + entering.len;
115
+ if (callback(bytes[0 .. 6 + entering.len], result[0..size]) != size or result[0] > entering.len) @panic("invalid compiled hover compaction");
116
+ out.len = result[0];
117
+ for (result[1..size], 0..) |index, position| {
118
+ if (position < out.len) {
119
+ if (index >= entering.len or (position > 0 and index <= out.kept[position - 1])) @panic("invalid compiled hover kept index");
120
+ } else if (index != 255) @panic("invalid compiled hover reserved index");
121
+ out.kept[position] = index;
122
+ }
123
+ return out;
124
+ }
125
+ for (entering, 0..) |flag, index| {
126
+ if (index >= from and flag) continue;
127
+ out.kept[out.len] = @intCast(index);
128
+ out.len += 1;
129
+ }
130
+ return out;
131
+ }
@@ -29,6 +29,7 @@
29
29
  //! encoded inputs decode-to-fit — never silent.
30
30
 
31
31
  const std = @import("std");
32
+ const registry_policy = @import("image_registry_policy.zig");
32
33
  const canvas = @import("canvas");
33
34
  const canvas_frame_module = @import("canvas_frame.zig");
34
35
  const canvas_limits = @import("canvas_limits.zig");
@@ -94,23 +95,32 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
94
95
  /// not be allocated; the registry is unchanged and the same
95
96
  /// registration can be retried once memory recovers).
96
97
  pub fn registerCanvasImage(self: *Runtime, id: canvas.ImageId, width: usize, height: usize, rgba8: []const u8) anyerror!void {
97
- if (id == 0) return error.InvalidImageId;
98
- // The high bit is the media-surface texture namespace
99
- // (`canvas.media_surface_image_id_bit`): producer-pushed
100
- // textures and registered images share one flat id space,
101
- // so a registration inside the reserved namespace is
102
- // refused loudly rather than shadowed silently.
103
- if ((id & canvas.media_surface_image_id_bit) != 0) return error.InvalidImageId;
104
- if (width == 0 or height == 0) return error.InvalidImageDimensions;
105
- const row_len = std.math.mul(usize, width, 4) catch return error.InvalidImageDimensions;
106
- const byte_len = std.math.mul(usize, row_len, height) catch return error.InvalidImageDimensions;
107
- if (rgba8.len != byte_len) return error.InvalidImageDimensions;
108
- if (byte_len > self.max_image_pixel_bytes) return error.ImageTooLarge;
98
+ const index = if (self.image_registry_policy) |policy| compiled: {
99
+ var scratch: [max_registered_canvas_images]registry_policy.Record = undefined;
100
+ const program = registry_policy.plan(policy, .register, registry_policy.imageRecords(self, &scratch), max_registered_canvas_images, .{ .id = id, .width = width, .height = height, .length = rgba8.len, .budget = self.max_image_pixel_bytes });
101
+ try program.admit();
102
+ break :compiled program.selected.?;
103
+ } else native: {
104
+ if (id == 0) return error.InvalidImageId;
105
+ // The high bit is the media-surface texture namespace
106
+ // (`canvas.media_surface_image_id_bit`): producer-pushed
107
+ // textures and registered images share one flat id space,
108
+ // so a registration inside the reserved namespace is
109
+ // refused loudly rather than shadowed silently.
110
+ if ((id & canvas.media_surface_image_id_bit) != 0) return error.InvalidImageId;
111
+ if (width == 0 or height == 0) return error.InvalidImageDimensions;
112
+ const row_len = std.math.mul(usize, width, 4) catch return error.InvalidImageDimensions;
113
+ const native_byte_len = std.math.mul(usize, row_len, height) catch return error.InvalidImageDimensions;
114
+ if (rgba8.len != native_byte_len) return error.InvalidImageDimensions;
115
+ if (native_byte_len > self.max_image_pixel_bytes) return error.ImageTooLarge;
109
116
 
110
- const index = findCanvasImageIndex(self, id) orelse blk: {
111
- if (self.canvas_image_count >= max_registered_canvas_images) return error.ImageRegistryFull;
112
- break :blk self.canvas_image_count;
117
+ const native_index = findCanvasImageIndex(self, id) orelse blk: {
118
+ if (self.canvas_image_count >= max_registered_canvas_images) return error.ImageRegistryFull;
119
+ break :blk self.canvas_image_count;
120
+ };
121
+ break :native native_index;
113
122
  };
123
+ const byte_len = rgba8.len;
114
124
  if (self.canvas_image_pixels[index].len == 0) {
115
125
  // The slot's pixel buffer, allocated LAZILY at the
116
126
  // slot's first registration (one slot-budget block from
@@ -163,19 +173,24 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
163
173
  /// `registerCanvasImage` refuses (0 and the reserved
164
174
  /// media-surface namespace) and fires before any decode work.
165
175
  pub fn registerCanvasImageBytes(self: *Runtime, id: canvas.ImageId, bytes: []const u8) anyerror!RegisteredCanvasImage {
166
- if (id == 0) return error.InvalidImageId;
167
- // Same reserved-namespace refusal as `registerCanvasImage`
168
- // (see the comment there), checked before the decode so an
169
- // unusable id never reaches the platform codec — the caller
170
- // gets `error.InvalidImageId`, not a codec error, and pays
171
- // no decode cost for it.
172
- if ((id & canvas.media_surface_image_id_bit) != 0) return error.InvalidImageId;
173
- // Every encoded-registration entry point shares imageLoad's
174
- // fixed source contract. Direct fx.registerImageBytes and
175
- // Runtime.registerCanvasImageBytes calls must not hand an
176
- // arbitrarily large allocation to a host codec merely because
177
- // they bypassed the file/fetch executor.
178
- if (bytes.len > effects_mod.max_effect_image_source_bytes) return error.ImageTooLarge;
176
+ if (self.image_registry_policy) |policy| {
177
+ const program = registry_policy.plan(policy, .encoded, &.{}, max_registered_canvas_images, .{ .id = id, .length = bytes.len, .source_limit = effects_mod.max_effect_image_source_bytes });
178
+ try program.admit();
179
+ } else {
180
+ if (id == 0) return error.InvalidImageId;
181
+ // Same reserved-namespace refusal as `registerCanvasImage`
182
+ // (see the comment there), checked before the decode so an
183
+ // unusable id never reaches the platform codec — the caller
184
+ // gets `error.InvalidImageId`, not a codec error, and pays
185
+ // no decode cost for it.
186
+ if ((id & canvas.media_surface_image_id_bit) != 0) return error.InvalidImageId;
187
+ // Every encoded-registration entry point shares imageLoad's
188
+ // fixed source contract. Direct fx.registerImageBytes and
189
+ // Runtime.registerCanvasImageBytes calls must not hand an
190
+ // arbitrarily large allocation to a host codec merely because
191
+ // they bypassed the file/fetch executor.
192
+ if (bytes.len > effects_mod.max_effect_image_source_bytes) return error.ImageTooLarge;
193
+ }
179
194
  const scratch_len = self.max_image_pixel_bytes + self.max_image_pixel_bytes / 4;
180
195
  const scratch = try imageDecodeScratch(scratch_len);
181
196
  const decoded = try self.options.platform.services.decodeImage(bytes, scratch, self.max_image_pixel_bytes / 4);
@@ -189,7 +204,12 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
189
204
  /// image on their next frame (draws referencing a missing id
190
205
  /// skip, exactly like an unregistered id).
191
206
  pub fn unregisterCanvasImage(self: *Runtime, id: canvas.ImageId) bool {
192
- const index = findCanvasImageIndex(self, id) orelse return false;
207
+ const index = if (self.image_registry_policy) |policy| compiled: {
208
+ var scratch: [max_registered_canvas_images]registry_policy.Record = undefined;
209
+ const program = registry_policy.plan(policy, .remove, registry_policy.imageRecords(self, &scratch), max_registered_canvas_images, .{ .id = id });
210
+ if (program.action == 0) return false;
211
+ break :compiled program.selected.?;
212
+ } else findCanvasImageIndex(self, id) orelse return false;
193
213
  const last = self.canvas_image_count - 1;
194
214
  if (index != last) {
195
215
  self.canvas_image_entries[index] = self.canvas_image_entries[last];
@@ -289,6 +309,10 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
289
309
  }
290
310
 
291
311
  fn findCanvasImageIndex(self: *const Runtime, id: canvas.ImageId) ?usize {
312
+ if (self.image_registry_policy) |policy| {
313
+ var scratch: [max_registered_canvas_images]registry_policy.Record = undefined;
314
+ return registry_policy.plan(policy, .lookup, registry_policy.imageRecords(self, &scratch), max_registered_canvas_images, .{ .id = id }).selected;
315
+ }
292
316
  for (self.canvas_image_entries[0..self.canvas_image_count], 0..) |entry, index| {
293
317
  if (entry.id == id) return index;
294
318
  }
@@ -304,7 +328,12 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
304
328
  pub fn noteCanvasImagesChanged(self: *Runtime) void {
305
329
  const frame_methods = canvas_frame_module.RuntimeCanvasFrames(Runtime);
306
330
  for (self.views[0..self.view_count], 0..) |*view, index| {
307
- if (!view.open or view.kind != .gpu_surface) continue;
331
+ if (self.image_registry_policy) |policy| {
332
+ // Observe the current iterator slot after earlier frame
333
+ // callbacks, retaining the original iterator's extent.
334
+ const record = registry_policy.Record{ .flags = @as(u32, @intFromBool(view.open)) | (@as(u32, @intFromBool(view.kind == .gpu_surface)) << 1) };
335
+ if (registry_policy.plan(policy, .repaint, &.{record}, 32, .{}).action == 0) continue;
336
+ } else if (!view.open or view.kind != .gpu_surface) continue;
308
337
  view.presented_canvas_valid = false;
309
338
  self.invalidateFor(.state, view.frame);
310
339
  frame_methods.requestCanvasFrameForView(self, index) catch {};
@@ -0,0 +1,154 @@
1
+ //! Portable keyboard focus decisions. The reference is retained for Zig-core
2
+ //! apps; compiled views supply the same copied-byte policy via the existing
3
+ //! surface callback. Native keeps identities, retained geometry and effects.
4
+ const std = @import("std");
5
+ const canvas = @import("canvas");
6
+ const platform = @import("../platform/root.zig");
7
+
8
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
9
+ pub const Stage = enum(u8) { intent, lifetime, group, edge, spatial, coordinate, commit, visibility, caret, moved };
10
+ pub const Intent = enum(u8) { none, tab, back_tab, home, end, left, right, up, down };
11
+ pub const Action = enum(u8) { stop, tab_target, tab_commit, tab_visible, tab_visible_commit, tab_fallback, tab_fallback_commit, tab_finish, menu, tree_edge, group_edge, tree, group, spatial, commit, radio_commit, radio_next, moved, capture_tab };
12
+ pub const Facts = struct {
13
+ pub const present: u16 = 1;
14
+ pub const moved: u16 = 2;
15
+ pub const different: u16 = 4;
16
+ pub const same: u16 = 8;
17
+ pub const initial: u16 = 16;
18
+ pub const radio_scope: u16 = 32;
19
+ pub const focused: u16 = 64;
20
+ pub const quiet: u16 = 128;
21
+ pub const owner: u16 = 512;
22
+ pub const nonzero: u16 = 1024;
23
+ pub const budget: u16 = 2048;
24
+ pub const allowed: u16 = 4096;
25
+ };
26
+ pub const Request = struct {
27
+ stage: Stage,
28
+ a: u8 = 0,
29
+ b: u8 = 0,
30
+ c: u8 = 0,
31
+ kind: ?canvas.WidgetKind = null,
32
+ parent: ?canvas.WidgetKind = null,
33
+ target: ?canvas.WidgetKind = null,
34
+ facts: u16 = 0,
35
+ };
36
+
37
+ pub fn decide(policy: Policy, request: Request) u8 {
38
+ if (policy) |callback| {
39
+ var bytes = [10]u8{ 34, @intFromEnum(request.stage), request.a, request.b, request.c, code(request.kind), code(request.parent), code(request.target), 0, 0 };
40
+ std.mem.writeInt(u16, bytes[8..10], request.facts, .little);
41
+ var result: [1]u8 = undefined;
42
+ const max: u8 = switch (request.stage) {
43
+ .intent => 8,
44
+ .lifetime, .group => 2,
45
+ .coordinate => 18,
46
+ .commit => 7,
47
+ else => 1,
48
+ };
49
+ if (callback(&bytes, &result) != 1 or result[0] > max or (request.stage == .commit and result[0] != 0 and result[0] != 1 and result[0] != 7)) @panic("invalid compiled keyboard focus result");
50
+ return result[0];
51
+ }
52
+ return reference(request);
53
+ }
54
+ fn code(kind: ?canvas.WidgetKind) u8 {
55
+ return if (kind) |value| @intCast(canvas.widgetKindCode(value)) else 63;
56
+ }
57
+ pub fn phase(input: platform.GpuSurfaceInputEvent) u8 {
58
+ return switch (input.kind) {
59
+ .key_down => 0,
60
+ .key_up => 1,
61
+ else => 2,
62
+ };
63
+ }
64
+ pub fn key(value: []const u8) u8 {
65
+ const names = [_][]const u8{ "tab", "home", "end", "arrowleft", "arrowright", "arrowup", "arrowdown" };
66
+ for (names, 1..) |name, index| if (std.ascii.eqlIgnoreCase(value, name)) return @intCast(index);
67
+ return 0;
68
+ }
69
+ pub fn modifiers(input: platform.GpuSurfaceInputEvent) u8 {
70
+ const m = input.modifiers;
71
+ return @as(u8, if (m.shift) 1 else 0) | @as(u8, if (m.control) 2 else 0) | @as(u8, if (m.option) 4 else 0) | @as(u8, if (m.command) 8 else 0) | @as(u8, if (m.primary) 16 else 0);
72
+ }
73
+ pub fn directionCode(value: canvas.WidgetFocusDirection) u8 {
74
+ return switch (value) {
75
+ .forward => 0,
76
+ .backward => 1,
77
+ .left => 2,
78
+ .right => 3,
79
+ .up => 4,
80
+ .down => 5,
81
+ };
82
+ }
83
+ pub fn direction(intent: Intent) canvas.WidgetFocusDirection {
84
+ return switch (intent) {
85
+ .back_tab => .backward,
86
+ .left, .end => .left,
87
+ .right, .home => .right,
88
+ .up => .up,
89
+ .down => .down,
90
+ else => .forward,
91
+ };
92
+ }
93
+
94
+ pub fn reference(r: Request) u8 {
95
+ const horizontal = r.a == 2 or r.a == 3;
96
+ const vertical = r.a == 4 or r.a == 5;
97
+ const button_parent = r.parent == .button_group or r.parent == .pagination or r.parent == .breadcrumb;
98
+ const toggle_parent = r.parent == .button_group or r.parent == .toggle_group;
99
+ switch (r.stage) {
100
+ .intent => {
101
+ if (r.a != 0) return 0;
102
+ if (r.b == 1) {
103
+ if (r.facts & 1 != 0 or (r.facts & 2 != 0 and r.c == 0)) return 0;
104
+ return if (r.c & 1 != 0) 2 else 1;
105
+ }
106
+ if (r.c & 30 != 0) return 0;
107
+ if (r.b == 2 and r.c == 0) return 3;
108
+ if (r.b == 3 and r.c == 0) return 4;
109
+ return if (r.b >= 4 and r.b <= 7) r.b + 1 else 0;
110
+ },
111
+ .lifetime => return if (r.a < 2 and r.b == 1 and r.facts & 1 != 0) (if (r.a == 1) 2 else 1) else 0,
112
+ .group => {
113
+ const horizontal_group = (button_parent and (r.kind == .button or r.kind == .icon_button)) or (r.parent == .toggle_group and r.kind == .toggle_button) or (r.parent == .tabs and r.kind == .segmented_control);
114
+ const vertical_group = (r.parent == .list and r.kind == .list_item) or ((r.parent == .menu_surface or r.parent == .dropdown_menu) and r.kind == .menu_item);
115
+ if ((horizontal_group and horizontal) or (vertical_group and vertical)) return if (r.a == 2 or r.a == 4) 1 else 2;
116
+ return 0;
117
+ },
118
+ .edge => return @intFromBool(r.kind == .list_item or r.kind == .menu_item or r.kind == .data_cell or r.kind == .segmented_control or r.kind == .radio or ((r.kind == .button or r.kind == .icon_button) and button_parent) or (r.kind == .toggle_button and toggle_parent)),
119
+ .spatial => {
120
+ if (r.kind != r.target) return 0;
121
+ if (r.kind == .data_cell) return 1;
122
+ if (r.kind == .radio) return if (r.facts & 6 != 0) @intFromBool(r.facts & 10 == 10) else @intCast(r.facts & 1);
123
+ return @intFromBool(r.facts & 1 != 0 and (((r.kind == .list_item or r.kind == .menu_item) and vertical) or (r.kind == .segmented_control and horizontal) or ((r.kind == .button or r.kind == .icon_button) and button_parent and horizontal) or (r.kind == .toggle_button and toggle_parent and horizontal)));
124
+ },
125
+ .coordinate => {
126
+ const present = r.facts & Facts.present != 0;
127
+ const moved = r.facts & Facts.moved != 0;
128
+ const different = r.facts & Facts.different != 0;
129
+ const action: Action = @enumFromInt(r.b);
130
+ return @intFromEnum(switch (action) {
131
+ .stop => if (r.a == 1 or r.a == 2) Action.tab_target else if (r.a != 0 and r.facts & 192 == 64) (if (r.a == 3 or r.a == 4) Action.tree_edge else if ((r.a == 7 or r.a == 8) and (r.kind == .button or r.kind == .icon_button or r.kind == .select or r.kind == .combobox)) Action.menu else Action.tree) else Action.stop,
132
+ .tab_target => if (present) Action.tab_commit else Action.stop,
133
+ .tab_commit => if (moved) Action.tab_finish else if (different) Action.tab_visible else Action.tab_finish,
134
+ .tab_visible => if (present and r.facts & Facts.same == 0) Action.tab_visible_commit else Action.tab_fallback,
135
+ .tab_visible_commit => if (moved) Action.tab_finish else Action.tab_fallback,
136
+ .tab_fallback => if (present and r.facts & Facts.same == 0) Action.tab_fallback_commit else Action.stop,
137
+ .tab_fallback_commit => Action.tab_finish,
138
+ .tab_finish => if (moved) (if (r.facts & Facts.owner != 0) Action.capture_tab else Action.moved) else Action.stop,
139
+ .menu => if (present) Action.commit else Action.tree,
140
+ .tree_edge => if (present) Action.commit else Action.group_edge,
141
+ .group_edge, .group => if (present) (if (r.kind == .radio and r.facts & Facts.radio_scope != 0) (if (r.facts & 3076 == 3076) Action.radio_commit else Action.stop) else Action.commit) else (if (action == .group) Action.spatial else Action.stop),
142
+ .tree => if (present) Action.commit else Action.group,
143
+ .spatial => if (present and r.facts & Facts.allowed != 0) Action.commit else Action.stop,
144
+ .commit => if (moved) Action.moved else Action.stop,
145
+ .radio_commit => if (moved) Action.moved else Action.radio_next,
146
+ .radio_next => if (present and r.facts & 24 == 0 and r.facts & 3076 == 3076) Action.radio_commit else Action.stop,
147
+ .moved, .capture_tab => Action.stop,
148
+ });
149
+ },
150
+ .commit => return if (r.facts & 3 == 3) 0 else 1 | @as(u8, if (r.a == 1 and r.facts & 4 != 0) 6 else 0),
151
+ .visibility => return @intFromBool(r.a == 1 or r.a == 2 or r.facts != 0),
152
+ .caret, .moved => return @intFromBool(r.facts == 7),
153
+ }
154
+ }
@@ -199,7 +199,7 @@ pub const max_canvas_widget_source_text_entries_per_view: usize = 256;
199
199
  /// plus inserted bytes exceed the pool simply starts a fresh history.
200
200
  pub const max_canvas_widget_text_history_bytes_per_view: usize = max_canvas_widget_text_bytes_per_view;
201
201
  pub const max_canvas_widget_inline_text_history_bytes_per_view: usize = 64 * 1024;
202
- pub const max_canvas_widget_text_history_entries_per_view: usize = 128;
202
+ pub const max_canvas_widget_text_history_entries_per_view: usize = canvas.max_text_history_timeline_entries;
203
203
  // Inline styled runs retained across all `.text` widgets of a view. Each
204
204
  // span is a small struct (style flags + slices into the widget text
205
205
  // bytes); per-paragraph capacity is `canvas.max_text_spans_per_paragraph`.
@@ -0,0 +1,86 @@
1
+ //! Copied presentation decisions. Native supplies capabilities and installs
2
+ //! accepted state; it never repeats the compiled lifecycle policy.
3
+ const std = @import("std");
4
+ const builtin = @import("builtin");
5
+ const platform = @import("../platform/root.zig");
6
+ pub const Policy = *const fn ([]const u8, []u8) usize;
7
+ pub const Mode = enum(u8) { requested, start, built, uploaded, encoded, pixels, baseline, gathered, fallback, image_action, image, direct, rendering };
8
+ pub const Instruction = enum(u32) { skipped, packet, upload, encode, pixels, done, gather, adopt, invalidate, observe_image };
9
+ pub const Refusal = enum(u32) { none, missing_service, unsupported_command };
10
+ pub const Facts = struct {
11
+ requires_render: bool = false,
12
+ view_exists: bool = false,
13
+ software: bool = false,
14
+ packet_service: bool = false,
15
+ representable: bool = false,
16
+ ok: bool = false,
17
+ retained_pixels: bool = false,
18
+ current: bool = false,
19
+ image_upload: bool = false,
20
+ image_index_present: bool = false,
21
+ command_capacity: usize = 0,
22
+ packet_capacity: usize = 0,
23
+ scratch_capacity: usize = 0,
24
+ pixel_bytes: usize = 0,
25
+ fallback_count: usize = 0,
26
+ logged_count: usize = 0,
27
+ detail_bytes: usize = 0,
28
+ detail_capacity: usize = 0,
29
+ image_index: usize = 0,
30
+ image_count: usize = 0,
31
+ image_width: usize = 0,
32
+ image_height: usize = 0,
33
+ image_bytes: usize = 0,
34
+ previous_reason: platform.GpuPresentFallbackReason = .none,
35
+ reason: platform.GpuPresentFallbackReason = .none,
36
+ };
37
+ pub const Program = struct {
38
+ instruction: Instruction,
39
+ refusal: Refusal,
40
+ use_scratch: bool,
41
+ should_log: bool,
42
+ overflow: bool,
43
+ fallback_count: usize,
44
+ logged_count: usize,
45
+ detail_bytes: usize,
46
+ };
47
+ fn word(bytes: []const u8, at: usize) u32 {
48
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
49
+ }
50
+ fn wide(bytes: []const u8, at: usize) u64 {
51
+ return std.mem.readInt(u64, bytes[at..][0..8], .little);
52
+ }
53
+ pub fn resultValid(bytes: []const u8) bool {
54
+ return bytes.len == 64 and word(bytes, 0) == 1 and word(bytes, 4) <= 9 and
55
+ word(bytes, 8) <= 2 and word(bytes, 12) <= 7 and std.mem.allEqual(u8, bytes[40..], 0) and
56
+ wide(bytes, 16) <= std.math.maxInt(usize) and wide(bytes, 24) <= std.math.maxInt(usize) and wide(bytes, 32) <= std.math.maxInt(usize);
57
+ }
58
+ pub fn plan(mode: Mode, facts: Facts, owner: Policy) Program {
59
+ var request: [128]u8 = @splat(0);
60
+ request[0..4].* = .{ 77, 1, @intFromEnum(mode), @as(u8, @intFromBool(builtin.mode == .Debug or builtin.mode == .ReleaseSafe)) | (@as(u8, @intFromBool(@bitSizeOf(usize) == 32)) << 1) };
61
+ var flags: u32 = 0;
62
+ inline for (.{ "requires_render", "view_exists", "software", "packet_service", "representable", "ok", "retained_pixels", "current", "image_upload", "image_index_present" }, 0..) |field, i|
63
+ flags |= @as(u32, @intFromBool(@field(facts, field))) << @intCast(i);
64
+ std.mem.writeInt(u32, request[4..8], flags, .little);
65
+ inline for (.{ "command_capacity", "packet_capacity", "scratch_capacity", "pixel_bytes", "fallback_count", "logged_count", "detail_bytes", "detail_capacity", "image_index", "image_count", "image_width", "image_height", "image_bytes" }, 0..) |field, i|
66
+ std.mem.writeInt(u64, request[8 + i * 8 ..][0..8], @field(facts, field), .little);
67
+ std.mem.writeInt(u32, request[112..116], @intFromEnum(facts.previous_reason), .little);
68
+ std.mem.writeInt(u32, request[116..120], @intFromEnum(facts.reason), .little);
69
+ var output: [64]u8 = @splat(0xa5);
70
+ const length = owner(&request, &output);
71
+ if (length > output.len or !resultValid(output[0..length])) @panic("invalid compiled presentation lifecycle result");
72
+ const mutations = word(&output, 12);
73
+ return .{ .instruction = @enumFromInt(word(&output, 4)), .refusal = @enumFromInt(word(&output, 8)), .use_scratch = mutations & 1 != 0, .should_log = mutations & 2 != 0, .overflow = mutations & 4 != 0, .fallback_count = @intCast(wide(&output, 16)), .logged_count = @intCast(wide(&output, 24)), .detail_bytes = @intCast(wide(&output, 32)) };
74
+ }
75
+
76
+ test "presentation lifecycle transport rejects unbounded instructions and incomplete envelopes" {
77
+ var output: [64]u8 = @splat(0);
78
+ std.mem.writeInt(u32, output[0..4], 1, .little);
79
+ try std.testing.expect(resultValid(&output));
80
+ for (0..output.len) |length| try std.testing.expect(!resultValid(output[0..length]));
81
+ for ([_]usize{ 0, 4, 8, 12, 40, 44, 48, 52, 56, 60 }) |at| {
82
+ var bad = output;
83
+ std.mem.writeInt(u32, bad[at..][0..4], 0xffffffff, .little);
84
+ try std.testing.expect(!resultValid(&bad));
85
+ }
86
+ }