@native-sdk/cli 0.0.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
3
|
+
const canvas = @import("root.zig");
|
|
4
|
+
const markdown = @import("markdown.zig");
|
|
5
|
+
const text_spans = @import("text_spans.zig");
|
|
6
|
+
const support = @import("test_support.zig");
|
|
7
|
+
|
|
8
|
+
const testing = std.testing;
|
|
9
|
+
|
|
10
|
+
const markdown_document_fixture = @embedFile("testdata/markdown_document.md");
|
|
11
|
+
|
|
12
|
+
const Msg = union(enum) {
|
|
13
|
+
open_url: []const u8,
|
|
14
|
+
toggle_details: usize,
|
|
15
|
+
noop,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const Md = markdown.Markdown(Msg);
|
|
19
|
+
const Ui = Md.Ui;
|
|
20
|
+
|
|
21
|
+
const TestDoc = struct {
|
|
22
|
+
arena_state: std.heap.ArenaAllocator,
|
|
23
|
+
ui: Ui,
|
|
24
|
+
tree: Ui.Tree = undefined,
|
|
25
|
+
|
|
26
|
+
fn init() TestDoc {
|
|
27
|
+
return .{
|
|
28
|
+
.arena_state = std.heap.ArenaAllocator.init(testing.allocator),
|
|
29
|
+
.ui = undefined,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn build(self: *TestDoc, source: []const u8, options: Md.Options) !Ui.Tree {
|
|
34
|
+
self.ui = Ui.init(self.arena_state.allocator());
|
|
35
|
+
const node = Md.view(&self.ui, source, options);
|
|
36
|
+
self.tree = try self.ui.finalize(node);
|
|
37
|
+
return self.tree;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fn deinit(self: *TestDoc) void {
|
|
41
|
+
self.arena_state.deinit();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
fn countKind(widget: canvas.Widget, kind: canvas.WidgetKind) usize {
|
|
46
|
+
var count: usize = if (widget.kind == kind) 1 else 0;
|
|
47
|
+
for (widget.children) |child| count += countKind(child, kind);
|
|
48
|
+
return count;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn findParagraphContaining(widget: canvas.Widget, fragment: []const u8) ?canvas.Widget {
|
|
52
|
+
if (widget.kind == .text and widget.spans.len > 0 and std.mem.indexOf(u8, widget.text, fragment) != null) return widget;
|
|
53
|
+
for (widget.children) |child| {
|
|
54
|
+
if (findParagraphContaining(child, fragment)) |found| return found;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fn findRoleLabel(widget: canvas.Widget, role: canvas.WidgetRole, label: []const u8) ?canvas.Widget {
|
|
60
|
+
if (widget.semantics.role == role and std.mem.eql(u8, widget.semantics.label, label)) return widget;
|
|
61
|
+
for (widget.children) |child| {
|
|
62
|
+
if (findRoleLabel(child, role, label)) |found| return found;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fn findKindLabel(widget: canvas.Widget, kind: canvas.WidgetKind, label: []const u8) ?canvas.Widget {
|
|
68
|
+
if (widget.kind == kind and (std.mem.eql(u8, widget.semantics.label, label) or std.mem.eql(u8, widget.text, label))) return widget;
|
|
69
|
+
for (widget.children) |child| {
|
|
70
|
+
if (findKindLabel(child, kind, label)) |found| return found;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
test "markdown maps headings, paragraphs, and inline styles onto spans" {
|
|
76
|
+
var doc = TestDoc.init();
|
|
77
|
+
defer doc.deinit();
|
|
78
|
+
const tree = try doc.build(
|
|
79
|
+
\\# Title
|
|
80
|
+
\\
|
|
81
|
+
\\Plain **bold** and *italic* with `code`, ~~gone~~, and [a link](https://example.com).
|
|
82
|
+
, .{ .on_link = Ui.linkMsg(.open_url) });
|
|
83
|
+
|
|
84
|
+
const heading = findParagraphContaining(tree.root, "Title").?;
|
|
85
|
+
try testing.expectEqual(@as(usize, 1), heading.spans.len);
|
|
86
|
+
try testing.expectEqual(canvas.TextSpanWeight.bold, heading.spans[0].weight);
|
|
87
|
+
try testing.expectEqual(markdown.heading_scales[0], heading.spans[0].scale);
|
|
88
|
+
|
|
89
|
+
const paragraph = findParagraphContaining(tree.root, "Plain").?;
|
|
90
|
+
try testing.expectEqualStrings("Plain bold and italic with code, gone, and a link.", paragraph.text);
|
|
91
|
+
|
|
92
|
+
const spans = paragraph.spans;
|
|
93
|
+
try testing.expectEqual(canvas.TextSpanWeight.bold, spans[1].weight);
|
|
94
|
+
try testing.expectEqualStrings("bold", spans[1].text);
|
|
95
|
+
try testing.expect(spans[3].italic);
|
|
96
|
+
try testing.expectEqualStrings("italic", spans[3].text);
|
|
97
|
+
try testing.expect(spans[5].monospace);
|
|
98
|
+
try testing.expectEqualStrings("code", spans[5].text);
|
|
99
|
+
try testing.expect(spans[7].strikethrough);
|
|
100
|
+
try testing.expectEqualStrings("gone", spans[7].text);
|
|
101
|
+
try testing.expectEqualStrings("a link", spans[9].text);
|
|
102
|
+
try testing.expectEqualStrings("https://example.com", spans[9].link);
|
|
103
|
+
|
|
104
|
+
// The link span grew a hit-area child that dispatches on_link's Msg.
|
|
105
|
+
const link_child = paragraph.children[0];
|
|
106
|
+
try testing.expectEqual(canvas.WidgetRole.link, link_child.semantics.role);
|
|
107
|
+
const msg = tree.msgForPointer(link_child.id, .up).?;
|
|
108
|
+
try testing.expectEqualStrings("https://example.com", msg.open_url);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
test "markdown maps lists, task lists, code fences, quotes, and rules" {
|
|
112
|
+
var doc = TestDoc.init();
|
|
113
|
+
defer doc.deinit();
|
|
114
|
+
const tree = try doc.build(
|
|
115
|
+
\\- first
|
|
116
|
+
\\- second
|
|
117
|
+
\\ - nested
|
|
118
|
+
\\
|
|
119
|
+
\\1. one
|
|
120
|
+
\\2. two
|
|
121
|
+
\\
|
|
122
|
+
\\- [ ] todo item
|
|
123
|
+
\\- [x] done item
|
|
124
|
+
\\
|
|
125
|
+
\\> quoted wisdom
|
|
126
|
+
\\
|
|
127
|
+
\\---
|
|
128
|
+
\\
|
|
129
|
+
\\```zig
|
|
130
|
+
\\const x = 1;
|
|
131
|
+
\\```
|
|
132
|
+
, .{});
|
|
133
|
+
|
|
134
|
+
// Two task checkboxes, disabled (display-only), checked state mapped.
|
|
135
|
+
try testing.expectEqual(@as(usize, 2), countKind(tree.root, .checkbox));
|
|
136
|
+
const todo = findKindLabel(tree.root, .checkbox, "todo item").?;
|
|
137
|
+
try testing.expect(todo.state.disabled);
|
|
138
|
+
try testing.expect(!todo.state.selected);
|
|
139
|
+
const done = findKindLabel(tree.root, .checkbox, "done item").?;
|
|
140
|
+
try testing.expect(done.state.selected);
|
|
141
|
+
|
|
142
|
+
// Bullets, ordered markers, nested item, quote bar + rule separators.
|
|
143
|
+
try testing.expect(findParagraphContaining(tree.root, "nested") != null);
|
|
144
|
+
try testing.expect(findParagraphContaining(tree.root, "one") != null);
|
|
145
|
+
try testing.expect(findParagraphContaining(tree.root, "quoted wisdom") != null);
|
|
146
|
+
try testing.expectEqual(@as(usize, 2), countKind(tree.root, .separator));
|
|
147
|
+
|
|
148
|
+
// The fenced block is a panel wrapping a mono paragraph.
|
|
149
|
+
try testing.expectEqual(@as(usize, 1), countKind(tree.root, .panel));
|
|
150
|
+
const code = findParagraphContaining(tree.root, "const x = 1;").?;
|
|
151
|
+
try testing.expect(code.spans[0].monospace);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
test "details blocks are caller-controlled collapsibles" {
|
|
155
|
+
const source =
|
|
156
|
+
\\<details>
|
|
157
|
+
\\<summary>More info</summary>
|
|
158
|
+
\\
|
|
159
|
+
\\Hidden paragraph.
|
|
160
|
+
\\
|
|
161
|
+
\\</details>
|
|
162
|
+
\\
|
|
163
|
+
\\After.
|
|
164
|
+
;
|
|
165
|
+
|
|
166
|
+
var collapsed = TestDoc.init();
|
|
167
|
+
defer collapsed.deinit();
|
|
168
|
+
const collapsed_tree = try collapsed.build(source, .{ .on_details = Md.detailsMsg(.toggle_details) });
|
|
169
|
+
try testing.expect(findParagraphContaining(collapsed_tree.root, "Hidden paragraph") == null);
|
|
170
|
+
try testing.expect(findParagraphContaining(collapsed_tree.root, "After") != null);
|
|
171
|
+
const header = findKindLabel(collapsed_tree.root, .list_item, "▸ More info").?;
|
|
172
|
+
try testing.expectEqual(@as(?bool, false), header.state.expanded);
|
|
173
|
+
const msg = collapsed_tree.msgForPointer(header.id, .up).?;
|
|
174
|
+
try testing.expectEqual(@as(usize, 0), msg.toggle_details);
|
|
175
|
+
|
|
176
|
+
var expanded = TestDoc.init();
|
|
177
|
+
defer expanded.deinit();
|
|
178
|
+
const expanded_tree = try expanded.build(source, .{
|
|
179
|
+
.on_details = Md.detailsMsg(.toggle_details),
|
|
180
|
+
.details_expanded = &.{true},
|
|
181
|
+
});
|
|
182
|
+
try testing.expect(findParagraphContaining(expanded_tree.root, "Hidden paragraph") != null);
|
|
183
|
+
const open_header = findKindLabel(expanded_tree.root, .list_item, "▾ More info").?;
|
|
184
|
+
try testing.expectEqual(@as(?bool, true), open_header.state.expanded);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
test "malformed markdown degrades to literal text and never fails" {
|
|
188
|
+
var doc = TestDoc.init();
|
|
189
|
+
defer doc.deinit();
|
|
190
|
+
const tree = try doc.build(
|
|
191
|
+
\\**unclosed bold and `unclosed code and [broken](link
|
|
192
|
+
\\
|
|
193
|
+
\\```
|
|
194
|
+
\\fence with no close
|
|
195
|
+
, .{});
|
|
196
|
+
|
|
197
|
+
const literal = findParagraphContaining(tree.root, "unclosed bold").?;
|
|
198
|
+
// Everything stayed literal: no bold weight, delimiters preserved.
|
|
199
|
+
try testing.expect(std.mem.indexOf(u8, literal.text, "**unclosed bold") != null);
|
|
200
|
+
try testing.expect(std.mem.indexOf(u8, literal.text, "[broken](link") != null);
|
|
201
|
+
for (literal.spans) |span| try testing.expectEqual(canvas.TextSpanWeight.regular, span.weight);
|
|
202
|
+
|
|
203
|
+
const code = findParagraphContaining(tree.root, "fence with no close").?;
|
|
204
|
+
try testing.expect(code.spans[0].monospace);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
test "empty and pathological inputs build empty-but-valid trees" {
|
|
208
|
+
var doc = TestDoc.init();
|
|
209
|
+
defer doc.deinit();
|
|
210
|
+
_ = try doc.build("", .{});
|
|
211
|
+
|
|
212
|
+
var doc2 = TestDoc.init();
|
|
213
|
+
defer doc2.deinit();
|
|
214
|
+
_ = try doc2.build("\n\n\n</details>\n<summary>stray</summary>\n", .{});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
fn findCellContaining(widget: canvas.Widget, fragment: []const u8) ?canvas.Widget {
|
|
218
|
+
if (widget.kind == .data_cell and std.mem.indexOf(u8, widget.text, fragment) != null) return widget;
|
|
219
|
+
for (widget.children) |child| {
|
|
220
|
+
if (findCellContaining(child, fragment)) |found| return found;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
test "pipe tables map onto table/data_row/data_cell with alignment and header styling" {
|
|
226
|
+
var doc = TestDoc.init();
|
|
227
|
+
defer doc.deinit();
|
|
228
|
+
const tree = try doc.build(
|
|
229
|
+
\\| Variable | Default | Notes |
|
|
230
|
+
\\| :--- | :---: | ---: |
|
|
231
|
+
\\| `PORT` | 3000 | **required** in prod |
|
|
232
|
+
\\| `LOG_LEVEL` | info | see [docs](https://example.com/logs) |
|
|
233
|
+
, .{ .on_link = Ui.linkMsg(.open_url) });
|
|
234
|
+
|
|
235
|
+
try testing.expectEqual(@as(usize, 1), countKind(tree.root, .table));
|
|
236
|
+
try testing.expectEqual(@as(usize, 3), countKind(tree.root, .data_row));
|
|
237
|
+
try testing.expectEqual(@as(usize, 9), countKind(tree.root, .data_cell));
|
|
238
|
+
|
|
239
|
+
// Header cells are bold with delimiter-driven alignment.
|
|
240
|
+
const header_cell = findCellContaining(tree.root, "Variable").?;
|
|
241
|
+
try testing.expectEqual(canvas.TextSpanWeight.bold, header_cell.spans[0].weight);
|
|
242
|
+
try testing.expectEqual(canvas.TextAlign.start, header_cell.text_alignment);
|
|
243
|
+
const centered = findCellContaining(tree.root, "Default").?;
|
|
244
|
+
try testing.expectEqual(canvas.TextAlign.center, centered.text_alignment);
|
|
245
|
+
const trailing = findCellContaining(tree.root, "Notes").?;
|
|
246
|
+
try testing.expectEqual(canvas.TextAlign.end, trailing.text_alignment);
|
|
247
|
+
|
|
248
|
+
// Body cells run the inline grammar: code, bold, and live links.
|
|
249
|
+
const port = findCellContaining(tree.root, "PORT").?;
|
|
250
|
+
try testing.expect(port.spans[0].monospace);
|
|
251
|
+
try testing.expectEqual(canvas.TextSpanWeight.regular, port.spans[0].weight);
|
|
252
|
+
const required = findCellContaining(tree.root, "required").?;
|
|
253
|
+
try testing.expectEqual(canvas.TextSpanWeight.bold, required.spans[0].weight);
|
|
254
|
+
const link_cell = findCellContaining(tree.root, "docs").?;
|
|
255
|
+
const hotspot = link_cell.children[0];
|
|
256
|
+
try testing.expectEqual(canvas.WidgetRole.link, hotspot.semantics.role);
|
|
257
|
+
const msg = tree.msgForPointer(hotspot.id, .up).?;
|
|
258
|
+
try testing.expectEqualStrings("https://example.com/logs", msg.open_url);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
test "table rows pad short rows, drop extra cells, and stop at blank or pipeless lines" {
|
|
262
|
+
var doc = TestDoc.init();
|
|
263
|
+
defer doc.deinit();
|
|
264
|
+
const tree = try doc.build(
|
|
265
|
+
\\| A | B |
|
|
266
|
+
\\| --- | --- |
|
|
267
|
+
\\| one |
|
|
268
|
+
\\| one | two | three |
|
|
269
|
+
\\
|
|
270
|
+
\\After the table.
|
|
271
|
+
, .{});
|
|
272
|
+
|
|
273
|
+
try testing.expectEqual(@as(usize, 1), countKind(tree.root, .table));
|
|
274
|
+
try testing.expectEqual(@as(usize, 3), countKind(tree.root, .data_row));
|
|
275
|
+
// Every row has exactly the header's column count.
|
|
276
|
+
try testing.expectEqual(@as(usize, 6), countKind(tree.root, .data_cell));
|
|
277
|
+
try testing.expect(findCellContaining(tree.root, "three") == null);
|
|
278
|
+
const after = findParagraphContaining(tree.root, "After the table.").?;
|
|
279
|
+
try testing.expectEqual(canvas.WidgetKind.text, after.kind);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
test "tables interrupt paragraphs and escape pipes inside cells" {
|
|
283
|
+
var doc = TestDoc.init();
|
|
284
|
+
defer doc.deinit();
|
|
285
|
+
const tree = try doc.build(
|
|
286
|
+
\\Leading prose
|
|
287
|
+
\\| Cmd | Effect |
|
|
288
|
+
\\| --- | --- |
|
|
289
|
+
\\| `a \| b` | pipe stays |
|
|
290
|
+
, .{});
|
|
291
|
+
|
|
292
|
+
try testing.expect(findParagraphContaining(tree.root, "Leading prose") != null);
|
|
293
|
+
try testing.expect(findParagraphContaining(tree.root, "Cmd") == null);
|
|
294
|
+
try testing.expectEqual(@as(usize, 1), countKind(tree.root, .table));
|
|
295
|
+
const escaped = findCellContaining(tree.root, "a | b").?;
|
|
296
|
+
try testing.expect(escaped.spans[0].monospace);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
test "malformed pipe blocks degrade to plain paragraphs" {
|
|
300
|
+
var doc = TestDoc.init();
|
|
301
|
+
defer doc.deinit();
|
|
302
|
+
|
|
303
|
+
// No delimiter row.
|
|
304
|
+
const tree = try doc.build(
|
|
305
|
+
\\| a | b |
|
|
306
|
+
\\| c | d |
|
|
307
|
+
, .{});
|
|
308
|
+
try testing.expectEqual(@as(usize, 0), countKind(tree.root, .table));
|
|
309
|
+
try testing.expect(findParagraphContaining(tree.root, "| a | b |") != null);
|
|
310
|
+
|
|
311
|
+
// Column-count mismatch between header and delimiter row.
|
|
312
|
+
var doc2 = TestDoc.init();
|
|
313
|
+
defer doc2.deinit();
|
|
314
|
+
const tree2 = try doc2.build(
|
|
315
|
+
\\| a | b | c |
|
|
316
|
+
\\| --- | --- |
|
|
317
|
+
, .{});
|
|
318
|
+
try testing.expectEqual(@as(usize, 0), countKind(tree2.root, .table));
|
|
319
|
+
|
|
320
|
+
// Wider than max_markdown_table_columns degrades rather than dropping columns.
|
|
321
|
+
var doc3 = TestDoc.init();
|
|
322
|
+
defer doc3.deinit();
|
|
323
|
+
const tree3 = try doc3.build(
|
|
324
|
+
\\| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
|
325
|
+
\\| - | - | - | - | - | - | - | - | - |
|
|
326
|
+
, .{});
|
|
327
|
+
try testing.expectEqual(@as(usize, 0), countKind(tree3.root, .table));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
test "the README-shaped fixture renders through the mapper and the reference renderer" {
|
|
331
|
+
var doc = TestDoc.init();
|
|
332
|
+
defer doc.deinit();
|
|
333
|
+
const tree = try doc.build(markdown_document_fixture, .{ .on_link = Ui.linkMsg(.open_url) });
|
|
334
|
+
|
|
335
|
+
// Structure spot checks against the fixture document.
|
|
336
|
+
const title = findParagraphContaining(tree.root, "Fieldnote").?;
|
|
337
|
+
try testing.expectEqual(markdown.heading_scales[0], title.spans[0].scale);
|
|
338
|
+
try testing.expect(findParagraphContaining(tree.root, "Left pane") != null);
|
|
339
|
+
const cli_link = findRoleLabel(tree.root, .link, "`flg`").?;
|
|
340
|
+
const open_msg = tree.msgForPointer(cli_link.id, .up).?;
|
|
341
|
+
try testing.expectEqualStrings("https://example.com/flg", open_msg.open_url);
|
|
342
|
+
try testing.expect(countKind(tree.root, .panel) >= 2); // fenced code blocks
|
|
343
|
+
|
|
344
|
+
// Layout + emit + reference-render the document; the pixel signature is
|
|
345
|
+
// the golden. Estimator-driven and provider-free: deterministic.
|
|
346
|
+
const canvas_width: f32 = 760;
|
|
347
|
+
const canvas_height: f32 = 2400;
|
|
348
|
+
var nodes: [512]canvas.WidgetLayoutNode = undefined;
|
|
349
|
+
const tokens = canvas.DesignTokens{};
|
|
350
|
+
const tree_layout = try canvas.layoutWidgetTreeWithTokens(
|
|
351
|
+
tree.root,
|
|
352
|
+
geometry.RectF.init(20, 20, canvas_width - 40, canvas_height - 40),
|
|
353
|
+
tokens,
|
|
354
|
+
&nodes,
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
var commands: [1024]canvas.CanvasCommand = undefined;
|
|
358
|
+
var builder = canvas.Builder.init(&commands);
|
|
359
|
+
try canvas.emitWidgetLayout(&builder, tree_layout, tokens);
|
|
360
|
+
const list = builder.displayList();
|
|
361
|
+
try testing.expect(list.commands.len > 100);
|
|
362
|
+
|
|
363
|
+
var render_commands: [1024]canvas.RenderCommand = undefined;
|
|
364
|
+
var render_batches: [1024]canvas.RenderBatch = undefined;
|
|
365
|
+
var resources: [1024]canvas.RenderResource = undefined;
|
|
366
|
+
var resource_cache_entries: [1024]canvas.RenderResourceCacheEntry = undefined;
|
|
367
|
+
var resource_cache_actions: [2048]canvas.RenderResourceCacheAction = undefined;
|
|
368
|
+
var glyphs: [4096]canvas.GlyphAtlasEntry = undefined;
|
|
369
|
+
var glyph_cache_entries: [4096]canvas.GlyphAtlasCacheEntry = undefined;
|
|
370
|
+
var glyph_cache_actions: [8192]canvas.GlyphAtlasCacheAction = undefined;
|
|
371
|
+
var changes: [2049]canvas.DiffChange = undefined;
|
|
372
|
+
const frame = try (canvas.DisplayList{ .commands = list.commands }).framePlan(null, .{
|
|
373
|
+
.surface_size = geometry.SizeF.init(canvas_width, canvas_height),
|
|
374
|
+
}, .{
|
|
375
|
+
.render_commands = &render_commands,
|
|
376
|
+
.render_batches = &render_batches,
|
|
377
|
+
.resources = &resources,
|
|
378
|
+
.resource_cache_entries = &resource_cache_entries,
|
|
379
|
+
.resource_cache_actions = &resource_cache_actions,
|
|
380
|
+
.glyph_atlas_entries = &glyphs,
|
|
381
|
+
.glyph_atlas_cache_entries = &glyph_cache_entries,
|
|
382
|
+
.glyph_atlas_cache_actions = &glyph_cache_actions,
|
|
383
|
+
.changes = &changes,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
const width: usize = @intFromFloat(canvas_width);
|
|
387
|
+
const height: usize = @intFromFloat(canvas_height);
|
|
388
|
+
const pixels = try testing.allocator.alloc(u8, width * height * 4);
|
|
389
|
+
defer testing.allocator.free(pixels);
|
|
390
|
+
@memset(pixels, 0);
|
|
391
|
+
const surface = try canvas.ReferenceRenderSurface.init(width, height, pixels);
|
|
392
|
+
try surface.renderPass(frame.renderPass(), canvas.Color.rgb8(255, 255, 255));
|
|
393
|
+
|
|
394
|
+
// Golden: byte-identical reference rendering of the README fixture.
|
|
395
|
+
try testing.expectEqual(markdown_document_reference_signature, support.referenceSurfaceSignature(pixels));
|
|
396
|
+
try support.expectVisiblePixel(surface.pixelRgba8(24, 32));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Reference-renderer pixel signature of the README-shaped fixture at
|
|
400
|
+
// 760x2400 with default tokens and the deterministic bundled-face
|
|
401
|
+
// metrics. It pins the whole document register in one number: heading
|
|
402
|
+
// scales, wrapped bullets and em-dash spacing at the face's real
|
|
403
|
+
// advances, real sans and mono outlines (fixed-pitch runs sit in their
|
|
404
|
+
// 0.6 em cells), GFM tables as borderless cells on hairline row
|
|
405
|
+
// separators, fenced-code panels, and near-black underlined links.
|
|
406
|
+
// Update deliberately when markdown rendering changes, reviewing the
|
|
407
|
+
// rendered pixels first (see reference_tests.zig conventions).
|
|
408
|
+
const markdown_document_reference_signature: u64 = 1138378532370101207;
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
test "bare URLs autolink at word boundaries with trailing punctuation trimmed" {
|
|
412
|
+
var doc = TestDoc.init();
|
|
413
|
+
defer doc.deinit();
|
|
414
|
+
const tree = try doc.build(
|
|
415
|
+
\\See https://example.com/path(1). Also (https://foo.dev/a?b=1), or http://bar.io!
|
|
416
|
+
\\
|
|
417
|
+
\\But nothttps://nope.com stays literal, as does a bare https:// scheme.
|
|
418
|
+
, .{ .on_link = Ui.linkMsg(.open_url) });
|
|
419
|
+
|
|
420
|
+
const paragraph = findParagraphContaining(tree.root, "See").?;
|
|
421
|
+
var links: usize = 0;
|
|
422
|
+
for (paragraph.spans) |span| {
|
|
423
|
+
if (span.link.len == 0) continue;
|
|
424
|
+
links += 1;
|
|
425
|
+
switch (links) {
|
|
426
|
+
// The trailing period is trimmed; the balanced paren is kept.
|
|
427
|
+
1 => try testing.expectEqualStrings("https://example.com/path(1)", span.link),
|
|
428
|
+
// The unbalanced close paren and comma are trimmed.
|
|
429
|
+
2 => try testing.expectEqualStrings("https://foo.dev/a?b=1", span.link),
|
|
430
|
+
3 => try testing.expectEqualStrings("http://bar.io", span.link),
|
|
431
|
+
else => {},
|
|
432
|
+
}
|
|
433
|
+
try testing.expectEqualStrings(span.link, span.text);
|
|
434
|
+
}
|
|
435
|
+
try testing.expectEqual(@as(usize, 3), links);
|
|
436
|
+
|
|
437
|
+
// No word-boundary, or no target after the scheme: literal text.
|
|
438
|
+
const literal = findParagraphContaining(tree.root, "nope").?;
|
|
439
|
+
for (literal.spans) |span| {
|
|
440
|
+
try testing.expectEqual(@as(usize, 0), span.link.len);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Autolinked URLs are pressable through the ordinary link machinery.
|
|
444
|
+
const link_child = paragraph.children[0];
|
|
445
|
+
const msg = tree.msgForPointer(link_child.id, .up).?;
|
|
446
|
+
try testing.expectEqualStrings("https://example.com/path(1)", msg.open_url);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
test "issue refs linkify only with an issue link base, at word boundaries" {
|
|
450
|
+
var doc = TestDoc.init();
|
|
451
|
+
defer doc.deinit();
|
|
452
|
+
|
|
453
|
+
// Without the option, refs stay plain text (no repo context).
|
|
454
|
+
{
|
|
455
|
+
const tree = try doc.build("Fixes #123 for real", .{});
|
|
456
|
+
const paragraph = findParagraphContaining(tree.root, "Fixes").?;
|
|
457
|
+
for (paragraph.spans) |span| {
|
|
458
|
+
try testing.expectEqual(@as(usize, 0), span.link.len);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
doc.deinit();
|
|
462
|
+
doc = TestDoc.init();
|
|
463
|
+
|
|
464
|
+
const tree = try doc.build(
|
|
465
|
+
\\Fixes #123 and (#45), but not path/#6, not ', not #12abc, and not word#7.
|
|
466
|
+
, .{
|
|
467
|
+
.on_link = Ui.linkMsg(.open_url),
|
|
468
|
+
.issue_link_base = "ghissue://",
|
|
469
|
+
});
|
|
470
|
+
const paragraph = findParagraphContaining(tree.root, "Fixes").?;
|
|
471
|
+
var links: usize = 0;
|
|
472
|
+
for (paragraph.spans) |span| {
|
|
473
|
+
if (span.link.len == 0) continue;
|
|
474
|
+
links += 1;
|
|
475
|
+
switch (links) {
|
|
476
|
+
1 => {
|
|
477
|
+
try testing.expectEqualStrings("#123", span.text);
|
|
478
|
+
try testing.expectEqualStrings("ghissue://123", span.link);
|
|
479
|
+
},
|
|
480
|
+
2 => {
|
|
481
|
+
try testing.expectEqualStrings("#45", span.text);
|
|
482
|
+
try testing.expectEqualStrings("ghissue://45", span.link);
|
|
483
|
+
},
|
|
484
|
+
else => {},
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
try testing.expectEqual(@as(usize, 2), links);
|
|
488
|
+
|
|
489
|
+
// The ref press dispatches the composed target through on_link.
|
|
490
|
+
const link_child = paragraph.children[0];
|
|
491
|
+
const msg = tree.msgForPointer(link_child.id, .up).?;
|
|
492
|
+
try testing.expectEqualStrings("ghissue://123", msg.open_url);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
test "real GitHub symbol codepoints keep their bytes and charge the cascade-class advance" {
|
|
496
|
+
var doc = TestDoc.init();
|
|
497
|
+
defer doc.deinit();
|
|
498
|
+
|
|
499
|
+
// Real GitHub-flavored content: ballot-box
|
|
500
|
+
// symbols in a table's status column next to mono cells and an
|
|
501
|
+
// em-dash. The markdown engine deliberately does NOT rewrite the
|
|
502
|
+
// characters (bytes stay byte-identical for selection/copy fidelity;
|
|
503
|
+
// live macOS rendering covers them through CoreText's cascade, pinned
|
|
504
|
+
// in text_metrics_tests) — the engine's job is an honest measured
|
|
505
|
+
// cell for them.
|
|
506
|
+
const tree = try doc.build(
|
|
507
|
+
\\| Status | API group | Effort |
|
|
508
|
+
\\| --- | --- | --- |
|
|
509
|
+
\\| ☐ | `experimental_createProviderRegistry` | — |
|
|
510
|
+
\\| ☑ | `experimental_wrapLanguageModel` | — |
|
|
511
|
+
\\
|
|
512
|
+
, .{});
|
|
513
|
+
|
|
514
|
+
const open_cell = findCellContaining(tree.root, "☐").?;
|
|
515
|
+
try testing.expectEqualStrings("☐", std.mem.trim(u8, open_cell.text, " "));
|
|
516
|
+
|
|
517
|
+
// The estimator charges the ballot box the 0.8 em symbol class (the
|
|
518
|
+
// AppleSymbols cascade advance live text falls back to), not the
|
|
519
|
+
// 0.6 em .notdef advance, so headless layout reserves the same cell
|
|
520
|
+
// class the live host inks.
|
|
521
|
+
const spans = open_cell.spans;
|
|
522
|
+
try testing.expect(spans.len >= 1);
|
|
523
|
+
const width = canvas.text_spans.textSpansIntrinsicWidth(spans, .{ .size = 10 });
|
|
524
|
+
try testing.expectApproxEqAbs(@as(f32, 8), width, 0.01);
|
|
525
|
+
|
|
526
|
+
// Mono cells stay intact single spans (the packet host draws the run
|
|
527
|
+
// as one string with the real mono face; the reference renderer
|
|
528
|
+
// centers each glyph in its fixed 0.6 em cell).
|
|
529
|
+
const mono_cell = findCellContaining(tree.root, "experimental_createProviderRegistry").?;
|
|
530
|
+
var mono_spans: usize = 0;
|
|
531
|
+
for (mono_cell.spans) |span| {
|
|
532
|
+
if (span.monospace) {
|
|
533
|
+
mono_spans += 1;
|
|
534
|
+
try testing.expectEqualStrings("experimental_createProviderRegistry", span.text);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
try testing.expectEqual(@as(usize, 1), mono_spans);
|
|
538
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//! Deterministic key-lookup scratch for the per-frame planners.
|
|
2
|
+
//!
|
|
3
|
+
//! The cache planners (resources, text layouts, glyph atlas) and the
|
|
4
|
+
//! display-list diff all answer the same two questions per entry: "did
|
|
5
|
+
//! the previous frame carry this key?" and "did an earlier entry in THIS
|
|
6
|
+
//! frame already claim it?". Linear scans made both O(n^2) per frame —
|
|
7
|
+
//! at the 2048-command budget that was the dominant cost of the whole
|
|
8
|
+
//! frame plan (measured: ~65-70%% of engine-side interaction cost),
|
|
9
|
+
//! paid identically on a 1-character edit and a full scene swap.
|
|
10
|
+
//!
|
|
11
|
+
//! `HashSlots` is an open-addressing, linear-probing index of `u32`
|
|
12
|
+
//! entry indices (stored +1 so zero means empty) over caller-owned key
|
|
13
|
+
//! storage. It stores NO keys itself: callers walk the probe chain and
|
|
14
|
+
//! compare keys with their existing equality functions, so lookup
|
|
15
|
+
//! results are exactly what the old linear scans returned — the
|
|
16
|
+
//! LOWEST-index equal entry, because chains preserve insertion order.
|
|
17
|
+
//! Planner outputs are therefore byte-identical; only the search cost
|
|
18
|
+
//! changes.
|
|
19
|
+
//!
|
|
20
|
+
//! Capacity discipline: tables must stay at most half full, which
|
|
21
|
+
//! `fitsHashSlots` checks against the planner's input sizes BEFORE the
|
|
22
|
+
//! index path is taken; oversized inputs (library callers with bigger
|
|
23
|
+
//! buffers than the runtime budgets) fall back to the original linear
|
|
24
|
+
//! scans. Instances live in `threadlocal` scratch at the use sites —
|
|
25
|
+
//! the planners run on one thread at a time and the tables are reset
|
|
26
|
+
//! per build, the same pattern as the runtime's frame scratch.
|
|
27
|
+
|
|
28
|
+
const std = @import("std");
|
|
29
|
+
|
|
30
|
+
pub fn HashSlots(comptime slot_count: usize) type {
|
|
31
|
+
comptime std.debug.assert(std.math.isPowerOfTwo(slot_count));
|
|
32
|
+
return struct {
|
|
33
|
+
slots: [slot_count]u32 = @splat(0),
|
|
34
|
+
|
|
35
|
+
const Self = @This();
|
|
36
|
+
|
|
37
|
+
/// Half-full bound: probe chains stay short and insertion can
|
|
38
|
+
/// never wrap the table.
|
|
39
|
+
pub const max_entries = slot_count / 2;
|
|
40
|
+
|
|
41
|
+
pub fn reset(self: *Self) void {
|
|
42
|
+
@memset(&self.slots, 0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
pub const Probe = struct {
|
|
46
|
+
pos: usize,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
pub fn probe(hash: u64) Probe {
|
|
50
|
+
return .{ .pos = @intCast(hash & (slot_count - 1)) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Next candidate entry index along the probe chain, or null at
|
|
54
|
+
/// the first empty slot (which is where `insert` would place the
|
|
55
|
+
/// key being probed for). The caller compares keys — a returned
|
|
56
|
+
/// candidate is a hash-chain neighbor, not necessarily a match.
|
|
57
|
+
pub fn next(self: *const Self, p: *Probe) ?u32 {
|
|
58
|
+
const stored = self.slots[p.pos];
|
|
59
|
+
if (stored == 0) return null;
|
|
60
|
+
p.pos = (p.pos + 1) & (slot_count - 1);
|
|
61
|
+
return stored - 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Insert `index` at the empty slot a fully-walked probe stopped
|
|
65
|
+
/// on. Only valid right after `next` returned null for `p`.
|
|
66
|
+
pub fn insert(self: *Self, p: Probe, index: u32) void {
|
|
67
|
+
self.slots[p.pos] = index + 1;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// True when inputs of the given sizes can use a `HashSlots` index
|
|
73
|
+
/// without exceeding the half-full bound.
|
|
74
|
+
pub fn fitsHashSlots(comptime slot_count: usize, len: usize) bool {
|
|
75
|
+
return len <= HashSlots(slot_count).max_entries;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// Below this many driving entries the linear scans win: they run in a
|
|
79
|
+
/// few microseconds and skip the table resets, which keeps the small-
|
|
80
|
+
/// view floor (a chart tick plans in ~20us total) untouched.
|
|
81
|
+
pub const min_entries_for_index: usize = 64;
|
|
82
|
+
|
|
83
|
+
/// 64-bit integer mix (splitmix64 finalizer) for key hashes: the id and
|
|
84
|
+
/// fingerprint fields feeding these tables are already well-distributed
|
|
85
|
+
/// or sequential ints; the mix spreads both.
|
|
86
|
+
pub fn mixHash(value: u64) u64 {
|
|
87
|
+
var x = value;
|
|
88
|
+
x ^= x >> 30;
|
|
89
|
+
x *%= 0xbf58476d1ce4e5b9;
|
|
90
|
+
x ^= x >> 27;
|
|
91
|
+
x *%= 0x94d049bb133111eb;
|
|
92
|
+
x ^= x >> 31;
|
|
93
|
+
return x;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// f32 hashed by bit pattern with negative zero folded onto positive
|
|
97
|
+
/// zero, so keys equal under float `==` always hash equal (the key
|
|
98
|
+
/// equality functions compare floats with `==`).
|
|
99
|
+
pub fn mixF32(hash: u64, value: f32) u64 {
|
|
100
|
+
const normalized: f32 = if (value == 0) 0 else value;
|
|
101
|
+
const bits: u32 = @bitCast(normalized);
|
|
102
|
+
return mixHash(hash ^ bits);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
test "hash slots find lowest-index equal entry" {
|
|
106
|
+
var table: HashSlots(8) = .{};
|
|
107
|
+
table.reset();
|
|
108
|
+
const keys = [_]u64{ 7, 7, 9 };
|
|
109
|
+
for (keys, 0..) |key, index| {
|
|
110
|
+
var p = HashSlots(8).probe(mixHash(key));
|
|
111
|
+
while (table.next(&p)) |_| {}
|
|
112
|
+
table.insert(p, @intCast(index));
|
|
113
|
+
}
|
|
114
|
+
var p = HashSlots(8).probe(mixHash(7));
|
|
115
|
+
var first_match: ?u32 = null;
|
|
116
|
+
while (table.next(&p)) |candidate| {
|
|
117
|
+
if (keys[candidate] == 7 and first_match == null) first_match = candidate;
|
|
118
|
+
}
|
|
119
|
+
try std.testing.expectEqual(@as(?u32, 0), first_match);
|
|
120
|
+
}
|