@native-sdk/cli 0.4.1 → 0.4.3

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 (48) hide show
  1. package/assets/native-sdk.manifest +17 -1
  2. package/build/app.zig +40 -1
  3. package/build.zig +49 -3
  4. package/package.json +10 -9
  5. package/src/platform/macos/appkit_host.m +21 -6
  6. package/src/platform/windows/webview2_host.cpp +377 -72
  7. package/src/primitives/canvas/chart.zig +8 -7
  8. package/src/primitives/canvas/chart_tests.zig +2 -2
  9. package/src/primitives/canvas/commands.zig +27 -0
  10. package/src/primitives/canvas/gpu.zig +8 -0
  11. package/src/primitives/canvas/markdown_tests.zig +1 -1
  12. package/src/primitives/canvas/reference.zig +215 -7
  13. package/src/primitives/canvas/reference_tests.zig +326 -7
  14. package/src/primitives/canvas/root.zig +3 -0
  15. package/src/primitives/canvas/serialization.zig +16 -3
  16. package/src/primitives/canvas/test_support.zig +3 -0
  17. package/src/primitives/canvas/themes/geist.zig +6 -0
  18. package/src/primitives/canvas/tokens.zig +7 -0
  19. package/src/primitives/canvas/widget_builtin_tests.zig +439 -3
  20. package/src/primitives/canvas/widget_render.zig +29 -41
  21. package/src/primitives/canvas/widget_render_controls.zig +73 -43
  22. package/src/primitives/canvas/widget_render_style.zig +53 -0
  23. package/src/primitives/canvas/widget_render_surfaces.zig +19 -18
  24. package/src/primitives/canvas/widget_runtime.zig +3 -0
  25. package/src/primitives/canvas/widget_runtime_tests.zig +20 -21
  26. package/src/primitives/canvas/widget_text_input.zig +104 -1
  27. package/src/runtime/canvas_frame_packet_tests.zig +9 -1
  28. package/src/runtime/canvas_frame_patch_tests.zig +39 -1
  29. package/src/runtime/canvas_widget_control_tests.zig +4 -4
  30. package/src/runtime/canvas_widget_runtime.zig +23 -3
  31. package/src/runtime/canvas_widget_text_tests.zig +101 -0
  32. package/src/runtime/ui_app.zig +78 -10
  33. package/src/runtime/ui_app_tests.zig +109 -0
  34. package/src/runtime/ui_app_window_tests.zig +93 -0
  35. package/src/runtime/view.zig +1 -1
  36. package/src/runtime/view_widget_scroll.zig +12 -1
  37. package/src/runtime/view_widget_text.zig +6 -2
  38. package/src/tooling/buildgraph.zig +112 -2
  39. package/src/tooling/junction.zig +247 -0
  40. package/src/tooling/package.zig +45 -0
  41. package/src/tooling/root.zig +1 -0
  42. package/src/tooling/templates.zig +102 -2
  43. package/third_party/webview2/LICENSE.txt +27 -0
  44. package/third_party/webview2/README.md +19 -0
  45. package/third_party/webview2/arm64/WebView2Loader.dll +0 -0
  46. package/third_party/webview2/include/EventToken.h +12 -0
  47. package/third_party/webview2/include/WebView2.h +60636 -0
  48. package/third_party/webview2/x64/WebView2Loader.dll +0 -0
@@ -628,12 +628,328 @@ test "reference renderer captures Phase 2 primitive signature" {
628
628
  const surface = (try ReferenceRenderSurface.initWithScratch(32, 24, &pixels, &scratch)).withImages(&images);
629
629
  try surface.renderPass(frame.renderPass(), Color.rgb8(0, 0, 0));
630
630
 
631
- try std.testing.expectEqual(@as(u64, 12197497484215834747), referenceSurfaceSignature(&pixels));
631
+ try std.testing.expectEqual(@as(u64, 8143217197410062006), referenceSurfaceSignature(&pixels));
632
632
  try expectVisiblePixel(surface.pixelRgba8(6, 6));
633
633
  try expectVisiblePixel(surface.pixelRgba8(20, 8));
634
634
  try expectVisiblePixel(surface.pixelRgba8(6, 16));
635
635
  }
636
636
 
637
+ // ---------------------------------------------------------------------------
638
+ // Rounded-rect coverage shape fidelity.
639
+ //
640
+ // The anti-aliased rounded-rect rasterization derives per-pixel coverage
641
+ // from one continuous signed-distance field of the whole shape. These
642
+ // tests hold that coverage against ground truth — 16x16 supersampling of
643
+ // the exact point-in-shape predicate per pixel — with two assertions:
644
+ //
645
+ // 1. NO PROTRUSION: any pixel the supersampled shape leaves empty must
646
+ // stay empty. A coverage model that treats perimeter regions
647
+ // differently (an arc ramp handing off to a binary straight edge)
648
+ // disagrees with itself about where the boundary is and pushes
649
+ // nubs outside the silhouette; this catches that class of bug
650
+ // exactly.
651
+ // 2. BOUNDED DEVIATION: the worst per-pixel difference stays within
652
+ // the intrinsic error of distance-ramp coverage. A half-pixel
653
+ // linear ramp reproduces box-filter coverage exactly on straight
654
+ // edges; on arcs it deviates more as curvature tightens, and at a
655
+ // sharp concave ring corner the distance-to-coverage mapping has a
656
+ // known worst case of ~1/4 at the single corner pixel. The
657
+ // per-case bounds encode those regimes with a small margin; the
658
+ // discontinuous-coverage bug class lands far outside them (2-4x).
659
+
660
+ const roundedRectCoverageFidelityCase = struct {
661
+ kind: enum { fill, stroke },
662
+ rect: geometry.RectF,
663
+ radius: Radius,
664
+ stroke_width: f32 = 0,
665
+ /// Max per-pixel |rendered - supersampled| in 1/255 levels.
666
+ tolerance: i32,
667
+ };
668
+
669
+ fn fidelityClampRadius(value: f32, max_radius: f32) f32 {
670
+ return std.math.clamp(@max(0, value), 0, max_radius);
671
+ }
672
+
673
+ fn fidelityInCorner(x: f32, y: f32, cx: f32, cy: f32, r: f32) bool {
674
+ if (r <= 0) return false;
675
+ const dx = x - cx;
676
+ const dy = y - cy;
677
+ return dx * dx + dy * dy <= r * r;
678
+ }
679
+
680
+ /// The exact rounded-rect interior predicate the supersampled ground
681
+ /// truth integrates: the rect with each corner replaced by a quarter
682
+ /// disc of its (clamped) radius.
683
+ fn fidelityInRoundedRect(x: f32, y: f32, rect: geometry.RectF, radius: Radius) bool {
684
+ if (rect.width <= 0 or rect.height <= 0) return false;
685
+ if (x < rect.x or x > rect.x + rect.width or y < rect.y or y > rect.y + rect.height) return false;
686
+ const max_radius = @min(rect.width, rect.height) * 0.5;
687
+ const top_left = fidelityClampRadius(radius.top_left, max_radius);
688
+ const top_right = fidelityClampRadius(radius.top_right, max_radius);
689
+ const bottom_right = fidelityClampRadius(radius.bottom_right, max_radius);
690
+ const bottom_left = fidelityClampRadius(radius.bottom_left, max_radius);
691
+ const max_x = rect.x + rect.width;
692
+ const max_y = rect.y + rect.height;
693
+ if (x < rect.x + top_left and y < rect.y + top_left) return fidelityInCorner(x, y, rect.x + top_left, rect.y + top_left, top_left);
694
+ if (x >= max_x - top_right and y < rect.y + top_right) return fidelityInCorner(x, y, max_x - top_right, rect.y + top_right, top_right);
695
+ if (x >= max_x - bottom_right and y >= max_y - bottom_right) return fidelityInCorner(x, y, max_x - bottom_right, max_y - bottom_right, bottom_right);
696
+ if (x < rect.x + bottom_left and y >= max_y - bottom_left) return fidelityInCorner(x, y, rect.x + bottom_left, max_y - bottom_left, bottom_left);
697
+ return true;
698
+ }
699
+
700
+ fn fidelityOutsetRadius(radius: Radius, outset: f32) Radius {
701
+ return .{
702
+ .top_left = @max(0, radius.top_left + outset),
703
+ .top_right = @max(0, radius.top_right + outset),
704
+ .bottom_right = @max(0, radius.bottom_right + outset),
705
+ .bottom_left = @max(0, radius.bottom_left + outset),
706
+ };
707
+ }
708
+
709
+ /// Ground-truth alpha of one pixel: the fraction of a 16x16 subsample
710
+ /// grid inside the case's shape (the stroke ring is outer minus inner,
711
+ /// derived exactly as the renderer derives them), quantized to a byte
712
+ /// like the renderer's blend quantizes coverage.
713
+ fn fidelityTruthAlpha(case: roundedRectCoverageFidelityCase, px: usize, py: usize) u8 {
714
+ const half = case.stroke_width * 0.5;
715
+ const outer = case.rect.inflate(geometry.InsetsF.all(half));
716
+ const inner = case.rect.deflate(geometry.InsetsF.all(@min(half, @min(case.rect.width, case.rect.height) * 0.5)));
717
+ const outer_radius = fidelityOutsetRadius(case.radius, half);
718
+ const inner_radius = fidelityOutsetRadius(case.radius, -half);
719
+ var covered: usize = 0;
720
+ var sub_y: usize = 0;
721
+ while (sub_y < 16) : (sub_y += 1) {
722
+ var sub_x: usize = 0;
723
+ while (sub_x < 16) : (sub_x += 1) {
724
+ const x = @as(f32, @floatFromInt(px)) + (@as(f32, @floatFromInt(sub_x)) + 0.5) / 16.0;
725
+ const y = @as(f32, @floatFromInt(py)) + (@as(f32, @floatFromInt(sub_y)) + 0.5) / 16.0;
726
+ const in = switch (case.kind) {
727
+ .fill => fidelityInRoundedRect(x, y, case.rect, case.radius),
728
+ .stroke => fidelityInRoundedRect(x, y, outer, outer_radius) and !fidelityInRoundedRect(x, y, inner, inner_radius),
729
+ };
730
+ if (in) covered += 1;
731
+ }
732
+ }
733
+ return @intFromFloat(@round(@as(f32, @floatFromInt(covered)) / 256.0 * 255.0));
734
+ }
735
+
736
+ test "rounded-rect coverage matches supersampled ground truth with no silhouette protrusion" {
737
+ const fidelity_width: usize = 48;
738
+ const fidelity_height: usize = 40;
739
+ const white = Color{ .r = 1, .g = 1, .b = 1, .a = 1 };
740
+ const cases = [_]roundedRectCoverageFidelityCase{
741
+ // Button-shaped fills: smooth arcs, integer and fractional bounds.
742
+ .{ .kind = .fill, .rect = geometry.RectF.init(6, 5, 30, 22), .radius = Radius.all(8), .tolerance = 16 },
743
+ .{ .kind = .fill, .rect = geometry.RectF.init(6.3, 5.7, 29.4, 21.6), .radius = Radius.all(8), .tolerance = 16 },
744
+ // Pill: the radius clamps to the half-height.
745
+ .{ .kind = .fill, .rect = geometry.RectF.init(4, 6, 40, 20), .radius = Radius.all(22), .tolerance = 16 },
746
+ // Tight curvature and mixed per-corner radii (one square corner).
747
+ .{ .kind = .fill, .rect = geometry.RectF.init(10.2, 8.6, 21.7, 14.3), .radius = Radius.all(0.75), .tolerance = 32 },
748
+ .{ .kind = .fill, .rect = geometry.RectF.init(7.6, 6.2, 30.8, 24.9), .radius = .{ .top_left = 0, .top_right = 6, .bottom_right = 12, .bottom_left = 2 }, .tolerance = 32 },
749
+ // Thin borders: both ring edges from the same field.
750
+ .{ .kind = .stroke, .rect = geometry.RectF.init(8, 7, 28, 20), .radius = Radius.all(6), .stroke_width = 1, .tolerance = 20 },
751
+ .{ .kind = .stroke, .rect = geometry.RectF.init(8.4, 7.8, 27.3, 19.5), .radius = Radius.all(6), .stroke_width = 2, .tolerance = 20 },
752
+ .{ .kind = .stroke, .rect = geometry.RectF.init(9.1, 8.3, 25.6, 17.2), .radius = Radius.all(0.75), .stroke_width = 1, .tolerance = 32 },
753
+ // Thick border whose inset radius bottoms out: the ring's inner
754
+ // corners go sharp and concave, the distance-ramp worst case.
755
+ .{ .kind = .stroke, .rect = geometry.RectF.init(8, 7, 28, 20), .radius = Radius.all(1), .stroke_width = 3, .tolerance = 72 },
756
+ };
757
+
758
+ for (cases) |case| {
759
+ var pixels: [fidelity_width * fidelity_height * 4]u8 = undefined;
760
+ const surface = try ReferenceRenderSurface.init(fidelity_width, fidelity_height, &pixels);
761
+ const bounds = geometry.RectF.init(0, 0, fidelity_width, fidelity_height);
762
+ const command = RenderCommand{
763
+ .command = switch (case.kind) {
764
+ .fill => .{ .fill_rounded_rect = .{ .rect = case.rect, .radius = case.radius, .fill = .{ .color = white } } },
765
+ .stroke => .{ .stroke_rect = .{ .rect = case.rect, .radius = case.radius, .stroke = .{ .fill = .{ .color = white }, .width = case.stroke_width } } },
766
+ },
767
+ .local_bounds = bounds,
768
+ .bounds = bounds,
769
+ };
770
+ const pass = CanvasRenderPass{
771
+ .surface_size = geometry.SizeF.init(fidelity_width, fidelity_height),
772
+ .scale = 1,
773
+ .full_repaint = true,
774
+ .commands = &.{command},
775
+ };
776
+ try surface.renderPass(pass, Color{ .r = 0, .g = 0, .b = 0, .a = 0 });
777
+
778
+ var y: usize = 0;
779
+ while (y < fidelity_height) : (y += 1) {
780
+ var x: usize = 0;
781
+ while (x < fidelity_width) : (x += 1) {
782
+ const rendered: i32 = surface.pixelRgba8(x, y)[3];
783
+ const truth: i32 = fidelityTruthAlpha(case, x, y);
784
+ if (truth == 0) try std.testing.expectEqual(@as(i32, 0), rendered);
785
+ try std.testing.expect(@max(rendered - truth, truth - rendered) <= case.tolerance);
786
+ }
787
+ }
788
+ }
789
+ }
790
+
791
+ // ---------------------------------------------------------------------------
792
+ // Coverage blend-space split.
793
+ //
794
+ // Geometry (paths, rounded rects) blends its anti-aliased edge coverage
795
+ // in linear light; glyph coverage blends in sRGB to preserve text
796
+ // weight. These tests pin the split from both sides with independently
797
+ // computed ground truth, so a refactor can never silently swap the two
798
+ // (a swap fails BOTH assertions, loudly).
799
+
800
+ /// The exact sRGB decode the renderer's 256-entry byte table holds.
801
+ fn blendSplitSrgbToLinear(value: f32) f32 {
802
+ const channel = std.math.clamp(value, 0, 1);
803
+ if (channel <= 0.04045) return channel / 12.92;
804
+ return std.math.pow(f32, (channel + 0.055) / 1.055, 2.4);
805
+ }
806
+
807
+ fn blendSplitLinearToSrgb(value: f32) f32 {
808
+ const channel = std.math.clamp(value, 0, 1);
809
+ if (channel <= 0.0031308) return channel * 12.92;
810
+ return 1.055 * std.math.pow(f32, channel, 1.0 / 2.4) - 0.055;
811
+ }
812
+
813
+ /// The renderer's encode-table lookup, replicated: nearest of 4096
814
+ /// evenly spaced entries, then the final byte rounding.
815
+ fn blendSplitEncodeByte(value: f32) u8 {
816
+ const index = @round(std.math.clamp(value, 0, 1) * 4095.0);
817
+ return @intFromFloat(@round(blendSplitLinearToSrgb(index / 4095.0) * 255.0));
818
+ }
819
+
820
+ /// Linear-light coverage blend of an opaque source byte over an opaque
821
+ /// destination byte, from the same LUT math the renderer tabulates.
822
+ fn blendSplitLinearByte(src: u8, dst: u8, coverage: f32) u8 {
823
+ const src_linear = blendSplitSrgbToLinear(@as(f32, @floatFromInt(src)) / 255.0);
824
+ const dst_linear = blendSplitSrgbToLinear(@as(f32, @floatFromInt(dst)) / 255.0);
825
+ return blendSplitEncodeByte(src_linear * coverage + dst_linear * (1 - coverage));
826
+ }
827
+
828
+ /// sRGB-space coverage blend of the same pixel (the historical fold).
829
+ fn blendSplitSrgbByte(src: u8, dst: u8, coverage: f32) u8 {
830
+ const src_f = @as(f32, @floatFromInt(src)) / 255.0;
831
+ const dst_f = @as(f32, @floatFromInt(dst)) / 255.0;
832
+ return @intFromFloat(@round((src_f * coverage + dst_f * (1 - coverage)) * 255.0));
833
+ }
834
+
835
+ fn blendSplitRenderPass(surface: ReferenceRenderSurface, command: RenderCommand, clear: Color, width: usize, height: usize) !void {
836
+ const pass = CanvasRenderPass{
837
+ .surface_size = geometry.SizeF.init(@floatFromInt(width), @floatFromInt(height)),
838
+ .scale = 1,
839
+ .full_repaint = true,
840
+ .commands = &.{command},
841
+ };
842
+ try surface.renderPass(pass, clear);
843
+ }
844
+
845
+ test "geometry edge coverage blends in linear light, computed from the LUT math" {
846
+ // A black path whose right edge splits pixel column 12 exactly in
847
+ // half: the vector core reports coverage 0.5 there, interiors 1.
848
+ const split_width: usize = 24;
849
+ const split_height: usize = 16;
850
+ const white = Color{ .r = 1, .g = 1, .b = 1, .a = 1 };
851
+ const black = Color{ .r = 0, .g = 0, .b = 0, .a = 1 };
852
+ const bounds = geometry.RectF.init(0, 0, split_width, split_height);
853
+ const elements = [_]PathElement{
854
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(4, 4), geometry.PointF.zero(), geometry.PointF.zero() } },
855
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(12.5, 4), geometry.PointF.zero(), geometry.PointF.zero() } },
856
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(12.5, 12), geometry.PointF.zero(), geometry.PointF.zero() } },
857
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(4, 12), geometry.PointF.zero(), geometry.PointF.zero() } },
858
+ .{ .verb = .close, .points = .{ geometry.PointF.zero(), geometry.PointF.zero(), geometry.PointF.zero() } },
859
+ };
860
+
861
+ const linear_edge = blendSplitLinearByte(0, 255, 0.5);
862
+ const srgb_edge = blendSplitSrgbByte(0, 255, 0.5);
863
+ // The split is only observable if the two spaces disagree here.
864
+ try std.testing.expect(linear_edge != srgb_edge);
865
+
866
+ // fill_path: the vector-core geometry route.
867
+ {
868
+ var pixels: [split_width * split_height * 4]u8 = undefined;
869
+ const surface = try ReferenceRenderSurface.init(split_width, split_height, &pixels);
870
+ try blendSplitRenderPass(surface, .{
871
+ .command = .{ .fill_path = .{ .elements = &elements, .fill = .{ .color = black } } },
872
+ .local_bounds = bounds,
873
+ .bounds = bounds,
874
+ }, white, split_width, split_height);
875
+ // Fully covered interior pixels stay bit-identical to the plain
876
+ // sRGB blend: an opaque source at coverage 1 is a copy in either
877
+ // space.
878
+ try expectPixelRgba8(.{ 0, 0, 0, 255 }, surface, 8, 8);
879
+ // The half-covered edge pixel holds the linear-light value.
880
+ try expectPixelRgba8(.{ linear_edge, linear_edge, linear_edge, 255 }, surface, 12, 8);
881
+ }
882
+
883
+ // fill_rounded_rect: the signed-distance geometry route. Its right
884
+ // edge is a straight segment at the same half-pixel boundary (the
885
+ // radius-2 corners are far from row 8), so coverage is 0.5 again.
886
+ {
887
+ var pixels: [split_width * split_height * 4]u8 = undefined;
888
+ const surface = try ReferenceRenderSurface.init(split_width, split_height, &pixels);
889
+ try blendSplitRenderPass(surface, .{
890
+ .command = .{ .fill_rounded_rect = .{ .rect = geometry.RectF.init(4, 4, 8.5, 8), .radius = Radius.all(2), .fill = .{ .color = black } } },
891
+ .local_bounds = bounds,
892
+ .bounds = bounds,
893
+ }, white, split_width, split_height);
894
+ try expectPixelRgba8(.{ 0, 0, 0, 255 }, surface, 8, 8);
895
+ try expectPixelRgba8(.{ linear_edge, linear_edge, linear_edge, 255 }, surface, 12, 8);
896
+ }
897
+ }
898
+
899
+ test "glyph edge coverage blends in sRGB, not linear light" {
900
+ // The same discrimination from the text side: render one glyph twice
901
+ // — once over transparent (whose alpha channel IS the coverage, in
902
+ // any blend space) and once over white — then check every fringe
903
+ // pixel of the white render against both models. Text must track the
904
+ // sRGB fold and stay far from the linear-light value at mid
905
+ // coverage, so inverting the sink's blend space can never pass.
906
+ const glyph_width: usize = 32;
907
+ const glyph_height: usize = 48;
908
+ const white = Color{ .r = 1, .g = 1, .b = 1, .a = 1 };
909
+ const black = Color{ .r = 0, .g = 0, .b = 0, .a = 1 };
910
+ const clear = Color{ .r = 0, .g = 0, .b = 0, .a = 0 };
911
+ const bounds = geometry.RectF.init(0, 0, glyph_width, glyph_height);
912
+ const command = RenderCommand{
913
+ .command = .{ .draw_text = .{ .size = 32, .origin = geometry.PointF.init(4, 40), .color = black, .text = "o" } },
914
+ .local_bounds = bounds,
915
+ .bounds = bounds,
916
+ };
917
+
918
+ var coverage_pixels: [glyph_width * glyph_height * 4]u8 = undefined;
919
+ const coverage_surface = try ReferenceRenderSurface.init(glyph_width, glyph_height, &coverage_pixels);
920
+ try blendSplitRenderPass(coverage_surface, command, clear, glyph_width, glyph_height);
921
+
922
+ var blended_pixels: [glyph_width * glyph_height * 4]u8 = undefined;
923
+ const blended_surface = try ReferenceRenderSurface.init(glyph_width, glyph_height, &blended_pixels);
924
+ try blendSplitRenderPass(blended_surface, command, white, glyph_width, glyph_height);
925
+
926
+ var mid_coverage_pixels: usize = 0;
927
+ var y: usize = 0;
928
+ while (y < glyph_height) : (y += 1) {
929
+ var x: usize = 0;
930
+ while (x < glyph_width) : (x += 1) {
931
+ const coverage_byte = coverage_surface.pixelRgba8(x, y)[3];
932
+ if (coverage_byte == 0 or coverage_byte == 255) continue;
933
+ const coverage = @as(f32, @floatFromInt(coverage_byte)) / 255.0;
934
+ const rendered: i32 = blended_surface.pixelRgba8(x, y)[0];
935
+ const srgb_expected: i32 = blendSplitSrgbByte(0, 255, coverage);
936
+ // One level of slack: the recovered coverage byte is itself
937
+ // rounded, so the re-derived sRGB fold can sit one step off
938
+ // the value blended from the unrounded coverage.
939
+ try std.testing.expect(@max(rendered - srgb_expected, srgb_expected - rendered) <= 1);
940
+ // Mid-coverage fringes are where the spaces disagree most;
941
+ // hold text a wide margin away from the linear value there.
942
+ if (coverage_byte >= 64 and coverage_byte <= 192) {
943
+ mid_coverage_pixels += 1;
944
+ const linear_expected: i32 = blendSplitLinearByte(0, 255, coverage);
945
+ try std.testing.expect(linear_expected - rendered >= 16);
946
+ }
947
+ }
948
+ }
949
+ // The glyph must actually have exercised the fringe band.
950
+ try std.testing.expect(mid_coverage_pixels >= 4);
951
+ }
952
+
637
953
  test "reference renderer applies clip transform and opacity" {
638
954
  const commands = [_]CanvasCommand{
639
955
  .{ .push_clip = .{ .rect = geometry.RectF.init(1, 1, 2, 2) } },
@@ -811,13 +1127,16 @@ test "reference renderer strokes paths: butt caps end at the segment, round caps
811
1127
  // One horizontal unit-width segment, rendered once per cap shape.
812
1128
  // The end pixels (0,1) and (2,1) are where the caps live: the butt
813
1129
  // cap stops at the endpoint (the segment covers exactly half of each
814
- // end pixel — 128 after coverage rounding), while the round cap
815
- // bulges a half-width semicircle past it (75% coverage per the
816
- // anti-aliased vector core). Interior and off-stroke pixels are
817
- // cap-independent.
1130
+ // end pixel), while the round cap bulges a half-width semicircle
1131
+ // past it (75% coverage per the anti-aliased vector core). Interior
1132
+ // and off-stroke pixels are cap-independent. The expected end-pixel
1133
+ // bytes are the LINEAR-LIGHT encodings of those coverages over black
1134
+ // — geometry edge coverage blends in linear light (see the renderer's
1135
+ // `CoverageBlend`), so 50% coverage of a 255 channel re-encodes to
1136
+ // 188 and 75% to 225, not the 128/191 sRGB-space folds.
818
1137
  const cases = [_]struct { cap: canvas.LineCap, end_coverage: u8 }{
819
- .{ .cap = .butt, .end_coverage = 128 },
820
- .{ .cap = .round, .end_coverage = 191 },
1138
+ .{ .cap = .butt, .end_coverage = 188 },
1139
+ .{ .cap = .round, .end_coverage = 225 },
821
1140
  };
822
1141
  for (cases) |case| {
823
1142
  const elements = [_]PathElement{
@@ -631,6 +631,9 @@ pub const textInputClearButtonHitRect = widget_runtime.textInputClearButtonHitRe
631
631
  pub const textInputContentExtentForWidget = widget_runtime.textInputContentExtentForWidget;
632
632
  pub const textInputMaxScrollOffsetForWidget = widget_runtime.textInputMaxScrollOffsetForWidget;
633
633
  pub const clampedTextInputScrollOffsetForWidget = widget_runtime.clampedTextInputScrollOffsetForWidget;
634
+ pub const textInputMaxHorizontalScrollOffsetForWidget = widget_runtime.textInputMaxHorizontalScrollOffsetForWidget;
635
+ pub const clampedTextInputHorizontalScrollOffsetForWidget = widget_runtime.clampedTextInputHorizontalScrollOffsetForWidget;
636
+ pub const textInputCaretVisibleScrollOffsetForWidget = widget_runtime.textInputCaretVisibleScrollOffsetForWidget;
634
637
  pub const intrinsicWidgetSize = widget_runtime.intrinsicWidgetSize;
635
638
  pub const cursorForWidgetHit = widget_runtime.cursorForWidgetHit;
636
639
  pub const cursorForWidgetTarget = widget_runtime.cursorForWidgetTarget;
@@ -348,6 +348,8 @@ fn writeCanvasGpuCommandJson(command: CanvasGpuCommand, writer: anytype) !void {
348
348
  try writer.writeAll(",\"paint\":");
349
349
  try writeCanvasGpuPaintJson(command.paint, writer);
350
350
  try writer.print(",\"strokeWidth\":{d}", .{command.stroke_width});
351
+ try writer.writeAll(",\"cap\":");
352
+ try json.writeString(writer, @tagName(command.cap));
351
353
  try writer.writeAll(",\"image\":");
352
354
  try writeCanvasGpuImageJson(command.image, writer);
353
355
  try writer.writeAll(",\"text\":");
@@ -974,7 +976,7 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
974
976
  }
975
977
 
976
978
  // ---------------------------------------------------------------------------
977
- // Compact binary gpu-surface packet encoding (wire format v3).
979
+ // Compact binary gpu-surface packet encoding (wire format v4).
978
980
  //
979
981
  // The version this comment names, the `binary_packet_version` constant
980
982
  // below, and the host decoder's spec comment (appkit_host.m) must agree;
@@ -1006,6 +1008,11 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
1006
1008
  // scissor stays the union of the list (hosts may honor either; pixels
1007
1009
  // outside every rect are unchanged by construction).
1008
1010
  //
1011
+ // v4 (from v3): every command carries a stroke end-cap code (u8, 0 butt
1012
+ // / 1 round) after stroke_width, so packet hosts stroke open subpaths
1013
+ // (the checkbox mark, the spinner arc) with the same cap the reference
1014
+ // renderer rasterizes instead of their engine default.
1015
+ //
1009
1016
  // Layout:
1010
1017
  // "NSGP" u8[4] | version u8 | load_action u8 (1 load / 2 clear /
1011
1018
  // 3 patch) | flags u8 (bit0 scissor, bit1 dirty rect list) | reserved u8
@@ -1023,7 +1030,7 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
1023
1030
  // | order_count u32 | order keys u64[]
1024
1031
 
1025
1032
  pub const binary_packet_magic = "NSGP";
1026
- pub const binary_packet_version: u8 = 3;
1033
+ pub const binary_packet_version: u8 = 4;
1027
1034
 
1028
1035
  /// Most dirty rects a patch header carries: enough to keep far-apart
1029
1036
  /// small changes (a switch plus a status line) from fusing into a
@@ -1054,6 +1061,7 @@ pub fn canvasGpuCommandFingerprint(command: CanvasGpuCommand) u64 {
1054
1061
  h = hash.resourceHashRect(h, command.bounds);
1055
1062
  h = hash.resourceHashF32(h, command.opacity);
1056
1063
  h = hash.resourceHashF32(h, command.stroke_width);
1064
+ h = hash.resourceHashEnum(h, @intFromEnum(command.cap));
1057
1065
  h = hash.resourceHashOptionalObjectId(h, command.id);
1058
1066
  h = hash.resourceHashOptionalRect(h, command.clip);
1059
1067
  h = hash.resourceHashAffine(h, command.transform);
@@ -1254,7 +1262,8 @@ const binary_command_flag_text: u8 = 0x40;
1254
1262
  const binary_command_flag_effect: u8 = 0x80;
1255
1263
 
1256
1264
  /// Command layout: kind u8 | flags u8 | bounds f32[4] | opacity f32
1257
- /// | stroke_width f32 | [id u64] | [clip f32[4]] | [transform f32[6]]
1265
+ /// | stroke_width f32 | cap u8 (0 butt / 1 round) | [id u64]
1266
+ /// | [clip f32[4]] | [transform f32[6]]
1258
1267
  /// | [shape] | [paint] | [image] | [text] | [effect] — each optional
1259
1268
  /// section present exactly when its flag bit is set. The identity
1260
1269
  /// transform is elided (the flag doubles as "non-identity").
@@ -1276,6 +1285,10 @@ fn writeCanvasGpuCommandBinary(command: CanvasGpuCommand, writer: anytype) !void
1276
1285
  try writeBinaryRect(command.bounds, writer);
1277
1286
  try writeBinaryF32(command.opacity, writer);
1278
1287
  try writeBinaryF32(command.stroke_width, writer);
1288
+ try writer.writeByte(switch (command.cap) {
1289
+ .butt => 0,
1290
+ .round => 1,
1291
+ });
1279
1292
  if (command.id) |id| try writer.writeInt(u64, id, .little);
1280
1293
  if (command.clip) |clip| try writeBinaryRect(clip, writer);
1281
1294
  if (!identity_transform) try writeBinaryAffine(command.transform, writer);
@@ -314,6 +314,9 @@ pub const textInputViewportForWidget = canvas.textInputViewportForWidget;
314
314
  pub const textInputContentExtentForWidget = canvas.textInputContentExtentForWidget;
315
315
  pub const textInputMaxScrollOffsetForWidget = canvas.textInputMaxScrollOffsetForWidget;
316
316
  pub const clampedTextInputScrollOffsetForWidget = canvas.clampedTextInputScrollOffsetForWidget;
317
+ pub const textInputMaxHorizontalScrollOffsetForWidget = canvas.textInputMaxHorizontalScrollOffsetForWidget;
318
+ pub const clampedTextInputHorizontalScrollOffsetForWidget = canvas.clampedTextInputHorizontalScrollOffsetForWidget;
319
+ pub const textInputCaretVisibleScrollOffsetForWidget = canvas.textInputCaretVisibleScrollOffsetForWidget;
317
320
  pub const intrinsicWidgetSize = canvas.intrinsicWidgetSize;
318
321
  pub const cursorForWidgetHit = canvas.cursorForWidgetHit;
319
322
  pub const cursorForWidgetTarget = canvas.cursorForWidgetTarget;
@@ -54,6 +54,12 @@ pub fn designTokens(color_scheme: ColorScheme, contrast: ColorContrast) DesignTo
54
54
  // then a 2px blue ring — the stroke defaults already carry that
55
55
  // geometry, restated here so the pack is explicit about it.
56
56
  .stroke = .{ .hairline = 1, .regular = 1, .focus = 2, .focus_offset = 2 },
57
+ // Crisp 1px lines are core to this register: geometry pixel
58
+ // snapping lands hairline borders on whole device columns. The
59
+ // runtime stamps the live surface scale on top; apps opt out
60
+ // through the token override (`.pixel_snap = .{ .geometry =
61
+ // false }`).
62
+ .pixel_snap = .{ .geometry = true },
57
63
  // Shadows are quiet: a 2px settle under raised cards, one
58
64
  // dominant 16/24 layer under overlays. Buttons stay flat.
59
65
  .shadow = .{
@@ -1478,6 +1478,13 @@ pub const DesignTokens = struct {
1478
1478
  .house => .{
1479
1479
  .colors = ColorTokens.theme(options.color_scheme, options.contrast),
1480
1480
  .controls = ControlTokens.theme(options.color_scheme, options.contrast),
1481
+ // Geometry pixel snapping is part of the house register:
1482
+ // hairline borders land on whole device columns (crisp
1483
+ // 1px lines) and intrinsic boxes round to the device
1484
+ // grid. The runtime stamps the live surface scale on
1485
+ // top; apps opt out through the token override
1486
+ // (`.pixel_snap = .{ .geometry = false }`).
1487
+ .pixel_snap = .{ .geometry = true },
1481
1488
  },
1482
1489
  .geist => geist_theme.designTokens(options.color_scheme, options.contrast),
1483
1490
  };