@native-sdk/cli 0.0.0 → 0.4.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 (367) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/bin/native.js +156 -0
  5. package/build/app.zig +716 -0
  6. package/build.zig +2593 -0
  7. package/build.zig.zon +24 -0
  8. package/native-sdk.d.ts +615 -0
  9. package/package.json +44 -8
  10. package/skill-data/automation/SKILL.md +248 -0
  11. package/skill-data/core/SKILL.md +249 -0
  12. package/skill-data/core/references/app-model-runtime.md +141 -0
  13. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  14. package/skill-data/core/references/frontend-assets.md +124 -0
  15. package/skill-data/core/references/project-anatomy.md +108 -0
  16. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  17. package/skill-data/native-ui/SKILL.md +1080 -0
  18. package/skills/native-sdk/SKILL.md +33 -0
  19. package/src/app_runner/root.zig +740 -0
  20. package/src/assets/root.zig +20 -0
  21. package/src/automation/protocol.zig +285 -0
  22. package/src/automation/root.zig +13 -0
  23. package/src/automation/server.zig +506 -0
  24. package/src/automation/snapshot.zig +1202 -0
  25. package/src/automation/watcher.zig +165 -0
  26. package/src/bridge/root.zig +507 -0
  27. package/src/debug/root.zig +246 -0
  28. package/src/embed/app_exports.zig +11 -0
  29. package/src/embed/c_api.zig +793 -0
  30. package/src/embed/c_exports.zig +10 -0
  31. package/src/embed/chrome.zig +168 -0
  32. package/src/embed/conversions.zig +359 -0
  33. package/src/embed/host.zig +960 -0
  34. package/src/embed/root.zig +81 -0
  35. package/src/embed/tests.zig +2552 -0
  36. package/src/embed/types.zig +382 -0
  37. package/src/embed/ui_host.zig +289 -0
  38. package/src/extensions/root.zig +197 -0
  39. package/src/frontend/root.zig +48 -0
  40. package/src/js/root.zig +65 -0
  41. package/src/platform/android/NativeSdkActivity.java +1370 -0
  42. package/src/platform/android/android_host.c +696 -0
  43. package/src/platform/android/files.zig +9 -0
  44. package/src/platform/android/native_sdk_app.h +237 -0
  45. package/src/platform/ios/files.zig +8 -0
  46. package/src/platform/ios/native_sdk_app.h +289 -0
  47. package/src/platform/ios/uikit_host.m +2739 -0
  48. package/src/platform/linux/cef_host.cpp +599 -0
  49. package/src/platform/linux/gtk_host.c +5362 -0
  50. package/src/platform/linux/gtk_host.h +265 -0
  51. package/src/platform/linux/root.zig +1519 -0
  52. package/src/platform/macos/appkit_host.h +604 -0
  53. package/src/platform/macos/appkit_host.m +10392 -0
  54. package/src/platform/macos/automation_host.h +14 -0
  55. package/src/platform/macos/automation_host.m +12 -0
  56. package/src/platform/macos/cef_host.mm +3028 -0
  57. package/src/platform/macos/root.zig +2260 -0
  58. package/src/platform/null_platform.zig +2232 -0
  59. package/src/platform/null_platform_tests.zig +670 -0
  60. package/src/platform/policy_values.zig +14 -0
  61. package/src/platform/root.zig +181 -0
  62. package/src/platform/types.zig +2681 -0
  63. package/src/platform/windows/cef_host.cpp +3 -0
  64. package/src/platform/windows/root.zig +1521 -0
  65. package/src/platform/windows/webview2_host.cpp +6230 -0
  66. package/src/primitives/app_dirs/root.zig +440 -0
  67. package/src/primitives/app_manifest/root.zig +109 -0
  68. package/src/primitives/app_manifest/tests.zig +758 -0
  69. package/src/primitives/app_manifest/types.zig +587 -0
  70. package/src/primitives/app_manifest/validation.zig +828 -0
  71. package/src/primitives/assets/root.zig +520 -0
  72. package/src/primitives/canvas/a11y_audit.zig +390 -0
  73. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  74. package/src/primitives/canvas/app_icon.zig +1590 -0
  75. package/src/primitives/canvas/chart.zig +392 -0
  76. package/src/primitives/canvas/chart_tests.zig +751 -0
  77. package/src/primitives/canvas/commands.zig +446 -0
  78. package/src/primitives/canvas/drawing.zig +309 -0
  79. package/src/primitives/canvas/equality.zig +316 -0
  80. package/src/primitives/canvas/events.zig +696 -0
  81. package/src/primitives/canvas/font_coverage.zig +118 -0
  82. package/src/primitives/canvas/font_ttf.zig +510 -0
  83. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  84. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  85. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  86. package/src/primitives/canvas/frame.zig +679 -0
  87. package/src/primitives/canvas/frame_metrics.zig +462 -0
  88. package/src/primitives/canvas/gpu.zig +639 -0
  89. package/src/primitives/canvas/hash.zig +112 -0
  90. package/src/primitives/canvas/icons/alert.svg +1 -0
  91. package/src/primitives/canvas/icons/archive.svg +1 -0
  92. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  93. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  94. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  95. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  96. package/src/primitives/canvas/icons/check.svg +1 -0
  97. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  98. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  99. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  100. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  101. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  102. package/src/primitives/canvas/icons/clock.svg +1 -0
  103. package/src/primitives/canvas/icons/copy.svg +1 -0
  104. package/src/primitives/canvas/icons/download.svg +1 -0
  105. package/src/primitives/canvas/icons/edit.svg +1 -0
  106. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  107. package/src/primitives/canvas/icons/external-link.svg +1 -0
  108. package/src/primitives/canvas/icons/eye.svg +1 -0
  109. package/src/primitives/canvas/icons/file-text.svg +1 -0
  110. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  111. package/src/primitives/canvas/icons/folder.svg +1 -0
  112. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  113. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  114. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  115. package/src/primitives/canvas/icons/info.svg +1 -0
  116. package/src/primitives/canvas/icons/menu.svg +1 -0
  117. package/src/primitives/canvas/icons/missing.svg +1 -0
  118. package/src/primitives/canvas/icons/moon.svg +1 -0
  119. package/src/primitives/canvas/icons/music.svg +1 -0
  120. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  121. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  122. package/src/primitives/canvas/icons/pause.svg +1 -0
  123. package/src/primitives/canvas/icons/play.svg +1 -0
  124. package/src/primitives/canvas/icons/plus.svg +1 -0
  125. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  126. package/src/primitives/canvas/icons/repeat.svg +1 -0
  127. package/src/primitives/canvas/icons/save.svg +1 -0
  128. package/src/primitives/canvas/icons/search.svg +1 -0
  129. package/src/primitives/canvas/icons/send.svg +1 -0
  130. package/src/primitives/canvas/icons/settings.svg +1 -0
  131. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  132. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  133. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  134. package/src/primitives/canvas/icons/sun.svg +1 -0
  135. package/src/primitives/canvas/icons/terminal.svg +1 -0
  136. package/src/primitives/canvas/icons/trash.svg +1 -0
  137. package/src/primitives/canvas/icons/volume.svg +1 -0
  138. package/src/primitives/canvas/icons/wrench.svg +1 -0
  139. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  140. package/src/primitives/canvas/icons/x.svg +1 -0
  141. package/src/primitives/canvas/icons.zig +249 -0
  142. package/src/primitives/canvas/layout_audit.zig +744 -0
  143. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  144. package/src/primitives/canvas/markdown.zig +1031 -0
  145. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  146. package/src/primitives/canvas/markdown_tests.zig +538 -0
  147. package/src/primitives/canvas/plan_key_index.zig +120 -0
  148. package/src/primitives/canvas/png.zig +355 -0
  149. package/src/primitives/canvas/reference.zig +1457 -0
  150. package/src/primitives/canvas/reference_blur.zig +104 -0
  151. package/src/primitives/canvas/reference_memo.zig +322 -0
  152. package/src/primitives/canvas/reference_paths.zig +184 -0
  153. package/src/primitives/canvas/reference_tests.zig +1650 -0
  154. package/src/primitives/canvas/render.zig +747 -0
  155. package/src/primitives/canvas/render_effects.zig +255 -0
  156. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  157. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  158. package/src/primitives/canvas/render_images.zig +247 -0
  159. package/src/primitives/canvas/render_layers.zig +260 -0
  160. package/src/primitives/canvas/render_paths.zig +347 -0
  161. package/src/primitives/canvas/render_resources.zig +51 -0
  162. package/src/primitives/canvas/render_tests.zig +3186 -0
  163. package/src/primitives/canvas/root.zig +744 -0
  164. package/src/primitives/canvas/serialization.zig +1528 -0
  165. package/src/primitives/canvas/svg_icon.zig +636 -0
  166. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  167. package/src/primitives/canvas/test_support.zig +422 -0
  168. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  169. package/src/primitives/canvas/tests.zig +30 -0
  170. package/src/primitives/canvas/text.zig +82 -0
  171. package/src/primitives/canvas/text_atlas.zig +408 -0
  172. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  173. package/src/primitives/canvas/text_interaction.zig +615 -0
  174. package/src/primitives/canvas/text_layout.zig +1069 -0
  175. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  176. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  177. package/src/primitives/canvas/text_layout_types.zig +128 -0
  178. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  179. package/src/primitives/canvas/text_metrics.zig +309 -0
  180. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  181. package/src/primitives/canvas/text_span_tests.zig +608 -0
  182. package/src/primitives/canvas/text_spans.zig +1010 -0
  183. package/src/primitives/canvas/text_tests.zig +1949 -0
  184. package/src/primitives/canvas/themes/geist.zig +470 -0
  185. package/src/primitives/canvas/tokens.zig +1522 -0
  186. package/src/primitives/canvas/ui.zig +2686 -0
  187. package/src/primitives/canvas/ui_markup.zig +3791 -0
  188. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  189. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  190. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  191. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  192. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  193. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  194. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  195. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  196. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  197. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  198. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  199. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  200. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  201. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  202. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  203. package/src/primitives/canvas/ui_provenance.zig +96 -0
  204. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  205. package/src/primitives/canvas/ui_schema.zig +825 -0
  206. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  207. package/src/primitives/canvas/ui_tests.zig +1432 -0
  208. package/src/primitives/canvas/vector.zig +919 -0
  209. package/src/primitives/canvas/vector_tests.zig +547 -0
  210. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  211. package/src/primitives/canvas/virtual_extents.zig +540 -0
  212. package/src/primitives/canvas/widget_access.zig +208 -0
  213. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  214. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  215. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  216. package/src/primitives/canvas/widget_layout.zig +2055 -0
  217. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  218. package/src/primitives/canvas/widget_metrics.zig +228 -0
  219. package/src/primitives/canvas/widget_render.zig +2534 -0
  220. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  221. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  222. package/src/primitives/canvas/widget_render_style.zig +626 -0
  223. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  224. package/src/primitives/canvas/widget_routing.zig +475 -0
  225. package/src/primitives/canvas/widget_runtime.zig +307 -0
  226. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  227. package/src/primitives/canvas/widget_semantics.zig +480 -0
  228. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  229. package/src/primitives/canvas/widget_tests.zig +8 -0
  230. package/src/primitives/canvas/widget_text_input.zig +351 -0
  231. package/src/primitives/canvas/widget_text_select.zig +147 -0
  232. package/src/primitives/canvas/widget_tree.zig +232 -0
  233. package/src/primitives/canvas/widgets.zig +1319 -0
  234. package/src/primitives/diagnostics/root.zig +445 -0
  235. package/src/primitives/geometry/root.zig +889 -0
  236. package/src/primitives/json/root.zig +272 -0
  237. package/src/primitives/platform_info/root.zig +450 -0
  238. package/src/primitives/trace/root.zig +569 -0
  239. package/src/root.zig +165 -0
  240. package/src/runtime/api.zig +431 -0
  241. package/src/runtime/async_bridge.zig +49 -0
  242. package/src/runtime/automation_commands.zig +686 -0
  243. package/src/runtime/automation_liveness_tests.zig +140 -0
  244. package/src/runtime/automation_snapshot.zig +246 -0
  245. package/src/runtime/automation_widget_dispatch.zig +617 -0
  246. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  247. package/src/runtime/bridge_payload.zig +194 -0
  248. package/src/runtime/bridge_permission_tests.zig +551 -0
  249. package/src/runtime/bridge_responses.zig +414 -0
  250. package/src/runtime/builtin_bridge.zig +554 -0
  251. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  252. package/src/runtime/canvas_font_tests.zig +410 -0
  253. package/src/runtime/canvas_fonts.zig +229 -0
  254. package/src/runtime/canvas_frame.zig +1734 -0
  255. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  256. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  257. package/src/runtime/canvas_frame_helpers.zig +414 -0
  258. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  259. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  260. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  261. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  262. package/src/runtime/canvas_frame_tests.zig +9 -0
  263. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  264. package/src/runtime/canvas_image_tests.zig +362 -0
  265. package/src/runtime/canvas_images.zig +224 -0
  266. package/src/runtime/canvas_limits.zig +317 -0
  267. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  268. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  269. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  270. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  271. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  272. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  273. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  274. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  275. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  276. package/src/runtime/canvas_widget_display.zig +677 -0
  277. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  278. package/src/runtime/canvas_widget_events.zig +1098 -0
  279. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  280. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  281. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  282. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  283. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  284. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  285. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  286. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  287. package/src/runtime/canvas_widget_state.zig +798 -0
  288. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  289. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  290. package/src/runtime/clock.zig +231 -0
  291. package/src/runtime/core.zig +927 -0
  292. package/src/runtime/effects.zig +4197 -0
  293. package/src/runtime/effects_audio_tests.zig +690 -0
  294. package/src/runtime/effects_clipboard_tests.zig +317 -0
  295. package/src/runtime/effects_fetch_tests.zig +1031 -0
  296. package/src/runtime/effects_file_tests.zig +407 -0
  297. package/src/runtime/effects_tests.zig +1251 -0
  298. package/src/runtime/flow.zig +1175 -0
  299. package/src/runtime/frame_profile.zig +221 -0
  300. package/src/runtime/gpu_surface_events.zig +639 -0
  301. package/src/runtime/launch_timing.zig +59 -0
  302. package/src/runtime/markdown_app_tests.zig +224 -0
  303. package/src/runtime/native_command_event_tests.zig +431 -0
  304. package/src/runtime/platform_bridge_tests.zig +8 -0
  305. package/src/runtime/platform_config_tests.zig +392 -0
  306. package/src/runtime/root.zig +150 -0
  307. package/src/runtime/runtime_event_tests.zig +1079 -0
  308. package/src/runtime/session_journal.zig +1522 -0
  309. package/src/runtime/session_record.zig +332 -0
  310. package/src/runtime/session_replay.zig +274 -0
  311. package/src/runtime/session_state.zig +30 -0
  312. package/src/runtime/session_tests.zig +399 -0
  313. package/src/runtime/shell_layout.zig +472 -0
  314. package/src/runtime/shell_layout_tests.zig +1246 -0
  315. package/src/runtime/shell_view_tests.zig +604 -0
  316. package/src/runtime/state.zig +110 -0
  317. package/src/runtime/system_services.zig +392 -0
  318. package/src/runtime/test_support.zig +79 -0
  319. package/src/runtime/tests.zig +30 -0
  320. package/src/runtime/ui_app.zig +3290 -0
  321. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  322. package/src/runtime/ui_app_provenance.zig +370 -0
  323. package/src/runtime/ui_app_tests.zig +3254 -0
  324. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  325. package/src/runtime/ui_app_window_tests.zig +442 -0
  326. package/src/runtime/validation.zig +206 -0
  327. package/src/runtime/view.zig +908 -0
  328. package/src/runtime/view_canvas.zig +850 -0
  329. package/src/runtime/view_widget_control.zig +433 -0
  330. package/src/runtime/view_widget_scroll.zig +360 -0
  331. package/src/runtime/view_widget_text.zig +275 -0
  332. package/src/runtime/view_widget_tree.zig +843 -0
  333. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  334. package/src/runtime/widget_bridge.zig +231 -0
  335. package/src/runtime/window_command_bridge_tests.zig +403 -0
  336. package/src/runtime/window_storage.zig +255 -0
  337. package/src/runtime/window_view_runtime.zig +727 -0
  338. package/src/runtime/window_views.zig +334 -0
  339. package/src/security/root.zig +118 -0
  340. package/src/tooling/android.zig +1172 -0
  341. package/src/tooling/assets.zig +128 -0
  342. package/src/tooling/buildgraph.zig +379 -0
  343. package/src/tooling/cef.zig +671 -0
  344. package/src/tooling/codesign.zig +172 -0
  345. package/src/tooling/components/identity_tests.zig +185 -0
  346. package/src/tooling/components/stepper.zig +113 -0
  347. package/src/tooling/components/timeline.native +27 -0
  348. package/src/tooling/components/timeline_item.zig +131 -0
  349. package/src/tooling/default_icon.icns +0 -0
  350. package/src/tooling/default_icon.png +0 -0
  351. package/src/tooling/dev.zig +172 -0
  352. package/src/tooling/doctor.zig +349 -0
  353. package/src/tooling/eject_components.zig +170 -0
  354. package/src/tooling/embedlib.zig +290 -0
  355. package/src/tooling/ios.zig +528 -0
  356. package/src/tooling/manifest.zig +1939 -0
  357. package/src/tooling/package.zig +2388 -0
  358. package/src/tooling/process_tree.zig +114 -0
  359. package/src/tooling/raw_manifest.zig +193 -0
  360. package/src/tooling/root.zig +22 -0
  361. package/src/tooling/templates.zig +3191 -0
  362. package/src/tooling/toolchain.zig +371 -0
  363. package/src/tooling/verbs.zig +204 -0
  364. package/src/tooling/web_engine.zig +135 -0
  365. package/src/tooling/xcodeproj.zig +462 -0
  366. package/src/window_state/root.zig +507 -0
  367. package/index.js +0 -2
@@ -0,0 +1,471 @@
1
+ //! Hostile-input corpus for the markdown mapper: real-world-nasty GitHub
2
+ //! content — pathological nesting, gigantic tables, kilochar words, mixed
3
+ //! RTL/CJK/emoji/ZWJ, unterminated fences, bracket/autolink bombs, HTML
4
+ //! soup, NUL bytes and invalid UTF-8, and multi-megabyte documents.
5
+ //!
6
+ //! The contract under test is the mapper's own: every input degrades
7
+ //! loudly-or-gracefully — `view` never panics, never hangs (parse work and
8
+ //! arena growth stay linear in the source), and always yields a valid
9
+ //! finalized tree (truncation is deterministic, documented, and bounded).
10
+ //! Timing is pinned by construction: the bomb documents are sized so a
11
+ //! reintroduced quadratic scan or join turns this suite from milliseconds
12
+ //! into minutes — loud in any gate.
13
+ //!
14
+ //! Two layers:
15
+ //! - targeted fixtures for each hostile shape (built inline so the
16
+ //! pathology is visible next to its assertions), and
17
+ //! - a seed-pinned generator that splices those shapes into random
18
+ //! documents (deterministic across runs; the seed is a constant).
19
+
20
+ const std = @import("std");
21
+ const geometry = @import("geometry");
22
+ const canvas = @import("root.zig");
23
+ const markdown = @import("markdown.zig");
24
+ const text_spans = @import("text_spans.zig");
25
+ const support = @import("test_support.zig");
26
+
27
+ const testing = std.testing;
28
+
29
+ const Msg = union(enum) {
30
+ open_url: []const u8,
31
+ toggle_details: usize,
32
+ noop,
33
+ };
34
+
35
+ const Md = markdown.Markdown(Msg);
36
+ const Ui = Md.Ui;
37
+
38
+ /// Arena growth bound for a build: parsing must stay LINEAR in the
39
+ /// source. The constant is honest about the mapper's real shape — every
40
+ /// container block eagerly allocates a `max_markdown_blocks_per_container`
41
+ /// node buffer (64 nodes x a multi-KiB `Ui.Node`), and one table costs a
42
+ /// 64-row buffer (~315 KiB measured), so container-dense documents run
43
+ /// ~180x their source bytes (measured: 100-deep nesting 15 KiB -> 2.7 MiB).
44
+ /// 256x + a one-table floor keeps the assert green for every legitimate
45
+ /// shape while a quadratic join (megabytes-per-source-KiB) still blows
46
+ /// through it by orders of magnitude.
47
+ fn arenaBound(source_len: usize) usize {
48
+ return source_len * 256 + 512 * 1024;
49
+ }
50
+
51
+ const BuildResult = struct {
52
+ widgets: usize,
53
+ text_bytes: usize,
54
+ };
55
+
56
+ /// Build `source` through the mapper with every hostile-relevant option
57
+ /// on, finalize, walk the tree, and enforce the linear-arena bound.
58
+ fn buildHostile(source: []const u8) !BuildResult {
59
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
60
+ defer arena_state.deinit();
61
+ var ui = Ui.init(arena_state.allocator());
62
+ const expanded = [_]bool{true} ** markdown.max_markdown_details_per_document;
63
+ const node = Md.view(&ui, source, .{
64
+ .on_link = Ui.linkMsg(.open_url),
65
+ .on_details = Md.detailsMsg(.toggle_details),
66
+ .details_expanded = &expanded,
67
+ .issue_link_base = "ghissue://",
68
+ });
69
+ const tree = try ui.finalize(node);
70
+ var result = BuildResult{ .widgets = 0, .text_bytes = 0 };
71
+ walk(tree.root, &result);
72
+ const capacity = arena_state.queryCapacity();
73
+ if (capacity > arenaBound(source.len)) {
74
+ std.debug.print(
75
+ "markdown build arena grew superlinearly: source={d} bytes, arena={d} bytes (bound {d})\n",
76
+ .{ source.len, capacity, arenaBound(source.len) },
77
+ );
78
+ return error.ArenaGrowthSuperlinear;
79
+ }
80
+ return result;
81
+ }
82
+
83
+ fn walk(widget: canvas.Widget, result: *BuildResult) void {
84
+ result.widgets += 1;
85
+ result.text_bytes += widget.text.len;
86
+ for (widget.spans) |span| result.text_bytes += span.text.len;
87
+ for (widget.children) |child| walk(child, result);
88
+ }
89
+
90
+ /// Layout, emit, frame-plan, and reference-render a built tree — the
91
+ /// full deterministic pipeline the README golden runs, at a smaller
92
+ /// surface. Hostile text must come out the other end as pixels (or as a
93
+ /// named budget error from the fixed-capacity harness arrays), never a
94
+ /// panic.
95
+ fn renderHostile(source: []const u8) !void {
96
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
97
+ defer arena_state.deinit();
98
+ var ui = Ui.init(arena_state.allocator());
99
+ const node = Md.view(&ui, source, .{ .on_link = Ui.linkMsg(.open_url) });
100
+ const tree = try ui.finalize(node);
101
+
102
+ const canvas_width: f32 = 480;
103
+ const canvas_height: f32 = 960;
104
+ var nodes: [512]canvas.WidgetLayoutNode = undefined;
105
+ const tokens = canvas.DesignTokens{};
106
+ const tree_layout = try canvas.layoutWidgetTreeWithTokens(
107
+ tree.root,
108
+ geometry.RectF.init(20, 20, canvas_width - 40, canvas_height - 40),
109
+ tokens,
110
+ &nodes,
111
+ );
112
+
113
+ var commands: [1024]canvas.CanvasCommand = undefined;
114
+ var builder = canvas.Builder.init(&commands);
115
+ try canvas.emitWidgetLayout(&builder, tree_layout, tokens);
116
+ const list = builder.displayList();
117
+
118
+ var render_commands: [1024]canvas.RenderCommand = undefined;
119
+ var render_batches: [1024]canvas.RenderBatch = undefined;
120
+ var resources: [1024]canvas.RenderResource = undefined;
121
+ var resource_cache_entries: [1024]canvas.RenderResourceCacheEntry = undefined;
122
+ var resource_cache_actions: [2048]canvas.RenderResourceCacheAction = undefined;
123
+ var glyphs: [4096]canvas.GlyphAtlasEntry = undefined;
124
+ var glyph_cache_entries: [4096]canvas.GlyphAtlasCacheEntry = undefined;
125
+ var glyph_cache_actions: [8192]canvas.GlyphAtlasCacheAction = undefined;
126
+ var changes: [2049]canvas.DiffChange = undefined;
127
+ const frame = try (canvas.DisplayList{ .commands = list.commands }).framePlan(null, .{
128
+ .surface_size = geometry.SizeF.init(canvas_width, canvas_height),
129
+ }, .{
130
+ .render_commands = &render_commands,
131
+ .render_batches = &render_batches,
132
+ .resources = &resources,
133
+ .resource_cache_entries = &resource_cache_entries,
134
+ .resource_cache_actions = &resource_cache_actions,
135
+ .glyph_atlas_entries = &glyphs,
136
+ .glyph_atlas_cache_entries = &glyph_cache_entries,
137
+ .glyph_atlas_cache_actions = &glyph_cache_actions,
138
+ .changes = &changes,
139
+ });
140
+
141
+ const width: usize = @intFromFloat(canvas_width);
142
+ const height: usize = @intFromFloat(canvas_height);
143
+ const pixels = try testing.allocator.alloc(u8, width * height * 4);
144
+ defer testing.allocator.free(pixels);
145
+ @memset(pixels, 0);
146
+ const surface = try canvas.ReferenceRenderSurface.init(width, height, pixels);
147
+ try surface.renderPass(frame.renderPass(), canvas.Color.rgb8(255, 255, 255));
148
+ }
149
+
150
+ test "hostile: 100-deep quotes, lists, and details nesting stay bounded" {
151
+ var buffer: [64 * 1024]u8 = undefined;
152
+ var stream = std.Io.Writer.fixed(&buffer);
153
+
154
+ // 100-deep blockquote markers on one line, then 100 quote lines.
155
+ for (0..100) |_| try stream.writeAll("> ");
156
+ try stream.writeAll("deep quote\n\n");
157
+ for (0..100) |_| try stream.writeAll("> another quoted line\n");
158
+ try stream.writeAll("\n");
159
+ // 100-deep list indentation (clamps at max_markdown_list_depth).
160
+ for (0..100) |depth| {
161
+ for (0..depth) |_| try stream.writeAll(" ");
162
+ try stream.writeAll("- item\n");
163
+ }
164
+ try stream.writeAll("\n");
165
+ // Details nested past max_markdown_details_per_document, all expanded.
166
+ for (0..40) |_| try stream.writeAll("<details>\n<summary>s</summary>\n\nbody\n\n");
167
+ for (0..40) |_| try stream.writeAll("</details>\n");
168
+
169
+ const result = try buildHostile(stream.buffered());
170
+ try testing.expect(result.widgets > 0);
171
+ }
172
+
173
+ test "hostile: gigantic tables truncate deterministically" {
174
+ var buffer: [512 * 1024]u8 = undefined;
175
+ var stream = std.Io.Writer.fixed(&buffer);
176
+
177
+ // Max-width table with thousands of rows: rows past
178
+ // max_markdown_table_rows drop, columns past the cap degrade the
179
+ // whole block to paragraphs (pinned by markdown_tests) — either way
180
+ // the tree stays valid and bounded.
181
+ try stream.writeAll("| a | b | c | d | e | f | g | h |\n");
182
+ try stream.writeAll("| - | - | - | - | - | - | - | - |\n");
183
+ for (0..4000) |_| try stream.writeAll("| **x** | `y` | [l](https://e.com) | ~~s~~ | v | w | #12 | z |\n");
184
+
185
+ const result = try buildHostile(stream.buffered());
186
+ try testing.expect(result.widgets > 0);
187
+ }
188
+
189
+ test "hostile: kilochar single words and megabyte paragraphs join in linear memory" {
190
+ const allocator = testing.allocator;
191
+
192
+ // A 10k-char single word inside prose.
193
+ {
194
+ var buffer: [16 * 1024]u8 = undefined;
195
+ var stream = std.Io.Writer.fixed(&buffer);
196
+ try stream.writeAll("before ");
197
+ for (0..10_000) |_| try stream.writeAll("a");
198
+ try stream.writeAll(" after");
199
+ _ = try buildHostile(stream.buffered());
200
+ }
201
+
202
+ // One paragraph, no blank lines, ~1 MiB of short lines: the join
203
+ // must be one-pass (a per-line re-join is quadratic in both time and
204
+ // arena) and the paragraph must truncate at its documented budget.
205
+ {
206
+ const source = try allocator.alloc(u8, 1024 * 1024);
207
+ defer allocator.free(source);
208
+ @memset(source, 'w');
209
+ var index: usize = 40;
210
+ while (index < source.len) : (index += 41) source[index] = '\n';
211
+ _ = try buildHostile(source);
212
+ }
213
+ }
214
+
215
+ test "hostile: bracket, autolink, and reference-link bombs parse in linear time" {
216
+ const allocator = testing.allocator;
217
+ const bomb_len = 256 * 1024;
218
+ const source = try allocator.alloc(u8, bomb_len);
219
+ defer allocator.free(source);
220
+
221
+ // '[' wall with one ']' at the end: every position used to rescan to
222
+ // the terminator looking for `](`.
223
+ @memset(source, '[');
224
+ source[bomb_len - 1] = ']';
225
+ _ = try buildHostile(source);
226
+
227
+ // '<' wall: every position used to rescan for '>' and fail the
228
+ // autolink test.
229
+ @memset(source, '<');
230
+ source[bomb_len - 1] = '>';
231
+ _ = try buildHostile(source);
232
+
233
+ // '[a](x' units with the lone ')' at the end: the ']' is always
234
+ // nearby but the ')' scan used to run to the terminator each time.
235
+ {
236
+ var index: usize = 0;
237
+ while (index + 5 <= bomb_len) : (index += 5) {
238
+ @memcpy(source[index..][0..5], "[a](x");
239
+ }
240
+ @memset(source[bomb_len - (bomb_len % 5) ..], 'x');
241
+ source[bomb_len - 1] = ')';
242
+ _ = try buildHostile(source);
243
+ }
244
+
245
+ // Interleaved '[<' wall with a link tail: the link title-strip and
246
+ // the autolink target check both probe for ' ' from different
247
+ // offsets — with a shared memo they evict each other back into
248
+ // quadratic rescans.
249
+ {
250
+ // Tail: "]()" makes every '[' parse fail AFTER its title-space
251
+ // probe (empty target), and " ://x>" lets every '<' reach its
252
+ // target-space probe — the two probe streams interleave.
253
+ const tail = "]() ://x> en";
254
+ var index: usize = 0;
255
+ while (index + 2 <= bomb_len - tail.len) : (index += 2) {
256
+ @memcpy(source[index..][0..2], "[<");
257
+ }
258
+ @memcpy(source[bomb_len - tail.len ..][0..tail.len], tail);
259
+ _ = try buildHostile(source);
260
+ }
261
+
262
+ // Reference-link bomb: thousands of definitions (unsupported ->
263
+ // literal text) with no blank lines — one giant paragraph.
264
+ {
265
+ var stream = std.Io.Writer.fixed(source);
266
+ while (stream.buffered().len + 32 < bomb_len) {
267
+ try stream.writeAll("[ref]: https://example.com/path\n");
268
+ }
269
+ _ = try buildHostile(stream.buffered());
270
+ }
271
+ }
272
+
273
+ test "hostile: bare-url paren tails trim in linear time" {
274
+ const allocator = testing.allocator;
275
+ const source = try allocator.alloc(u8, 256 * 1024);
276
+ defer allocator.free(source);
277
+ @memcpy(source[0..12], "https://e.c/");
278
+ @memset(source[12..], ')');
279
+ _ = try buildHostile(source);
280
+
281
+ // Balanced-paren URL of the same size — the keep path.
282
+ @memset(source[12..], '(');
283
+ @memset(source[12 + (source.len - 12) / 2 ..], ')');
284
+ _ = try buildHostile(source);
285
+ }
286
+
287
+ test "hostile: unterminated fences, HTML soup, and stray closers stay valid" {
288
+ _ = try buildHostile(
289
+ \\```zig
290
+ \\fence with no close, ever
291
+ \\| a | b |
292
+ \\<details>
293
+ );
294
+ _ = try buildHostile(
295
+ \\<div class="x"><span>soup</span><table><tr><td>no
296
+ \\</details></summary><details open><DETAILS><summary>
297
+ \\<script>alert(1)</script><!-- comment --><br/><hr>
298
+ \\<summary>orphan</summary>
299
+ \\</details>
300
+ );
301
+ _ = try buildHostile("<details>\n<summary>unclosed forever");
302
+ // Delimiter row with no header above it.
303
+ _ = try buildHostile("| --- | --- |\n| a | b |\n");
304
+ }
305
+
306
+ test "hostile: NUL bytes and invalid UTF-8 degrade to renderable text" {
307
+ // Real invalid sequences: NUL, lone continuation, truncated lead,
308
+ // CESU surrogate half, overlong encoding, and 0xFF. The mapper is
309
+ // byte-oriented (bytes pass through to spans); the text pipeline must
310
+ // measure and render them by UTF-8 scalar with fallback glyphs.
311
+ const nasty = "plain \x00 nul **bo\x80ld** `co\xc3de` [li\xed\xa0\x80nk](https://e.com) \xc0\xaf over \xff end";
312
+ const result = try buildHostile(nasty);
313
+ try testing.expect(result.widgets > 0);
314
+ try renderHostile(nasty);
315
+
316
+ // A NUL-ridden fenced block keeps its bytes (zero-copy slice).
317
+ _ = try buildHostile("```\n\x00\x00\x00\x01\x02\xfe\xff\n```\n");
318
+ }
319
+
320
+ test "hostile: mixed RTL, CJK, emoji, and ZWJ sequences render" {
321
+ const mixed =
322
+ \\# שלום עולם — مرحبا بالعالم
323
+ \\
324
+ \\日本語テキストと**한국어 텍스트**が *مختلطة مع العربية* です。
325
+ \\
326
+ \\Family: 👨‍👩‍👧‍👦 flags: 🏳️‍🌈 skin: 👍🏽 combining: éé́́ zalgo: h̸̡̪̯ͨ͊̽̅̾̎e̸̢̪̯ͨ͊̽̅̾̎
327
+ \\
328
+ \\| עמודה | 列 | 🙂 |
329
+ \\| --- | --- | --- |
330
+ \\| ‏RTL‏ | 值 | 👨‍👩‍👧‍👦 |
331
+ ;
332
+ const result = try buildHostile(mixed);
333
+ try testing.expect(result.widgets > 0);
334
+ try renderHostile(mixed);
335
+ }
336
+
337
+ test "hostile: five-megabyte document builds bounded and fast" {
338
+ const allocator = testing.allocator;
339
+ const source = try allocator.alloc(u8, 5 * 1024 * 1024);
340
+ defer allocator.free(source);
341
+
342
+ // Worst realistic shape: one paragraph the whole way down (no blank
343
+ // lines, so the 64-block cap cannot save the parse early).
344
+ @memset(source, 'm');
345
+ var index: usize = 60;
346
+ while (index < source.len) : (index += 61) source[index] = '\n';
347
+ _ = try buildHostile(source);
348
+
349
+ // And the block-heavy shape: parsing stops at the container cap.
350
+ var stream = std.Io.Writer.fixed(source);
351
+ while (stream.buffered().len + 64 < source.len) {
352
+ try stream.writeAll("# heading\n\nparagraph body with **bold** text\n\n- item one\n- item two\n\n");
353
+ }
354
+ _ = try buildHostile(stream.buffered());
355
+ }
356
+
357
+ // ------------------------------------------------------------- generator
358
+
359
+ /// Hostile fragment producers for the seed-pinned generator. Each writes
360
+ /// one document fragment; the fuzz loop splices a random handful together
361
+ /// and builds the result. Deterministic: fixed seed, fixed sizes.
362
+ const Fragment = enum {
363
+ deep_quotes,
364
+ deep_list,
365
+ wide_table,
366
+ long_word,
367
+ bracket_run,
368
+ angle_run,
369
+ star_run,
370
+ fence_open,
371
+ html_soup,
372
+ nul_run,
373
+ invalid_utf8,
374
+ unicode_soup,
375
+ url_paren_tail,
376
+ issue_refs,
377
+ details_open,
378
+ details_close,
379
+ blank,
380
+
381
+ fn emit(self: Fragment, stream: *std.Io.Writer, random: std.Random) !void {
382
+ switch (self) {
383
+ .deep_quotes => {
384
+ const depth = random.intRangeAtMost(usize, 1, 120);
385
+ for (0..depth) |_| try stream.writeAll(">");
386
+ try stream.writeAll(" quoted\n");
387
+ },
388
+ .deep_list => {
389
+ const depth = random.intRangeAtMost(usize, 0, 40);
390
+ for (0..depth) |_| try stream.writeAll(" ");
391
+ try stream.writeAll("- [x] item **b** `c`\n");
392
+ },
393
+ .wide_table => {
394
+ const columns = random.intRangeAtMost(usize, 1, 12);
395
+ const rows = random.intRangeAtMost(usize, 1, 80);
396
+ for (0..rows + 2) |row| {
397
+ for (0..columns) |_| {
398
+ try stream.writeAll(if (row == 1) "| --- " else "| `c` \\| **b** ");
399
+ }
400
+ try stream.writeAll("|\n");
401
+ }
402
+ },
403
+ .long_word => {
404
+ const length = random.intRangeAtMost(usize, 100, 4000);
405
+ for (0..length) |_| try stream.writeAll("w");
406
+ try stream.writeAll("\n");
407
+ },
408
+ .bracket_run => {
409
+ const length = random.intRangeAtMost(usize, 10, 2000);
410
+ for (0..length) |_| try stream.writeAll("[");
411
+ if (random.boolean()) try stream.writeAll("]");
412
+ try stream.writeAll("\n");
413
+ },
414
+ .angle_run => {
415
+ const length = random.intRangeAtMost(usize, 10, 2000);
416
+ for (0..length) |_| try stream.writeAll("<");
417
+ if (random.boolean()) try stream.writeAll(">");
418
+ try stream.writeAll("\n");
419
+ },
420
+ .star_run => {
421
+ const length = random.intRangeAtMost(usize, 10, 2000);
422
+ for (0..length) |_| try stream.writeAll(if (random.boolean()) "*" else "_");
423
+ try stream.writeAll("\n");
424
+ },
425
+ .fence_open => try stream.writeAll("```zig\nunterminated\n"),
426
+ .html_soup => try stream.writeAll("<div><span a=\"b\"><script>x</script></summary></details><details>\n"),
427
+ .nul_run => {
428
+ const length = random.intRangeAtMost(usize, 1, 64);
429
+ for (0..length) |_| try stream.writeAll("\x00");
430
+ try stream.writeAll("\n");
431
+ },
432
+ .invalid_utf8 => try stream.writeAll("\x80\xc3\xed\xa0\x80\xc0\xaf\xff\xfe\n"),
433
+ .unicode_soup => try stream.writeAll("שלום 日本語 👨‍👩‍👧‍👦 🏳️‍🌈 é́́ مرحبا\n"),
434
+ .url_paren_tail => {
435
+ try stream.writeAll("https://e.com/x");
436
+ const length = random.intRangeAtMost(usize, 1, 500);
437
+ for (0..length) |_| try stream.writeAll(")");
438
+ try stream.writeAll("\n");
439
+ },
440
+ .issue_refs => {
441
+ const count = random.intRangeAtMost(usize, 1, 200);
442
+ for (0..count) |_| try stream.writeAll("#123 ");
443
+ try stream.writeAll("\n");
444
+ },
445
+ .details_open => try stream.writeAll("<details>\n<summary>s **b**</summary>\n"),
446
+ .details_close => try stream.writeAll("</details>\n"),
447
+ .blank => try stream.writeAll("\n"),
448
+ }
449
+ }
450
+ };
451
+
452
+ test "hostile: seed-pinned fuzz corpus builds bounded trees" {
453
+ const allocator = testing.allocator;
454
+ const buffer = try allocator.alloc(u8, 256 * 1024);
455
+ defer allocator.free(buffer);
456
+
457
+ // Fixed seed: the corpus is identical on every run and every machine.
458
+ var prng = std.Random.DefaultPrng.init(0x6d61726b646f776e);
459
+ const random = prng.random();
460
+ const fragments = std.enums.values(Fragment);
461
+
462
+ for (0..48) |_| {
463
+ var stream = std.Io.Writer.fixed(buffer);
464
+ const count = random.intRangeAtMost(usize, 3, 40);
465
+ for (0..count) |_| {
466
+ const fragment = fragments[random.intRangeAtMost(usize, 0, fragments.len - 1)];
467
+ fragment.emit(&stream, random) catch break; // buffer full: use what fits
468
+ }
469
+ _ = try buildHostile(stream.buffered());
470
+ }
471
+ }