@native-sdk/cli 0.7.1 → 0.8.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 (94) hide show
  1. package/build/app.zig +273 -65
  2. package/build/ts_run.mjs +6 -8
  3. package/build.zig +341 -361
  4. package/native-sdk.d.ts +6 -3
  5. package/package.json +13 -11
  6. package/packages/core/compile-surface/core.ts +559 -0
  7. package/packages/core/package-lock.json +375 -12
  8. package/packages/core/package.json +9 -6
  9. package/packages/core/scripts/compiler_typecheck.mjs +58 -0
  10. package/packages/core/scripts/gen_case_tables.mjs +130 -0
  11. package/packages/core/scripts/gen_declarations.mjs +97 -0
  12. package/packages/core/scripts/run_external_core_compiler.mjs +108 -0
  13. package/packages/core/scripts/stage_external_core.mjs +148 -0
  14. package/packages/core/sdk/core.d.ts +363 -0
  15. package/packages/core/sdk/events.d.ts +65 -0
  16. package/packages/core/sdk/text.d.ts +51 -0
  17. package/packages/core/src/checker.ts +3 -3
  18. package/packages/core/src/cli.ts +40 -38
  19. package/packages/core/src/contract.ts +749 -0
  20. package/packages/core/src/devhost.ts +4 -3
  21. package/packages/core/src/diagnostics.ts +5 -7
  22. package/packages/core/src/{transpile.ts → frontend.ts} +38 -50
  23. package/packages/core/src/infer.ts +1 -1
  24. package/packages/core/src/typed_ast.ts +16 -15
  25. package/packages/core/src/wyhash.ts +79 -0
  26. package/skill-data/native-ui/SKILL.md +4 -2
  27. package/skill-data/ts-core/SKILL.md +29 -29
  28. package/src/platform/macos/appkit_host.m +51 -3
  29. package/src/platform/types.zig +4 -0
  30. package/src/platform/windows/gpu_surface_renderer.cpp +2280 -0
  31. package/src/platform/windows/gpu_surface_renderer.h +86 -0
  32. package/src/platform/windows/root.zig +298 -20
  33. package/src/platform/windows/webview2_host.cpp +343 -33
  34. package/src/primitives/canvas/code.zig +50 -0
  35. package/src/primitives/canvas/code_tests.zig +174 -1
  36. package/src/primitives/canvas/frame.zig +45 -1
  37. package/src/primitives/canvas/gpu.zig +6 -0
  38. package/src/primitives/canvas/render_tests.zig +93 -0
  39. package/src/primitives/canvas/root.zig +2 -0
  40. package/src/primitives/canvas/serialization.zig +150 -21
  41. package/src/primitives/canvas/themes/geist.zig +51 -5
  42. package/src/primitives/canvas/tokens.zig +33 -4
  43. package/src/primitives/canvas/ui.zig +52 -7
  44. package/src/primitives/canvas/ui_markup.zig +38 -1
  45. package/src/primitives/canvas/ui_markup_compiled.zig +28 -0
  46. package/src/primitives/canvas/ui_markup_contract.zig +9 -0
  47. package/src/primitives/canvas/ui_markup_view.zig +28 -0
  48. package/src/primitives/canvas/ui_markup_view_tests.zig +10 -2
  49. package/src/primitives/canvas/ui_schema.zig +5 -0
  50. package/src/primitives/canvas/ui_schema_tests.zig +4 -3
  51. package/src/primitives/canvas/ui_tests.zig +14 -0
  52. package/src/primitives/canvas/widget_builtin_tests.zig +513 -13
  53. package/src/primitives/canvas/widget_invalidation.zig +11 -1
  54. package/src/primitives/canvas/widget_layout.zig +260 -21
  55. package/src/primitives/canvas/widget_metrics.zig +45 -9
  56. package/src/primitives/canvas/widget_render.zig +220 -70
  57. package/src/primitives/canvas/widget_render_controls.zig +79 -21
  58. package/src/primitives/canvas/widget_render_style.zig +52 -8
  59. package/src/primitives/canvas/widget_text_input.zig +2 -0
  60. package/src/primitives/canvas/widgets.zig +53 -2
  61. package/src/runtime/canvas_frame.zig +60 -7
  62. package/src/runtime/canvas_frame_invalidation_tests.zig +80 -0
  63. package/src/runtime/canvas_frame_packet_tests.zig +83 -9
  64. package/src/runtime/canvas_frame_patch_tests.zig +16 -0
  65. package/src/runtime/canvas_images.zig +8 -2
  66. package/src/runtime/canvas_widget_clipboard_tests.zig +1 -1
  67. package/src/runtime/canvas_widget_runtime.zig +11 -8
  68. package/src/runtime/effects.zig +6 -0
  69. package/src/runtime/effects_tests.zig +30 -0
  70. package/src/runtime/gpu_surface_events.zig +38 -7
  71. package/src/runtime/media_surface_tests.zig +1 -1
  72. package/src/runtime/runtime_event_tests.zig +74 -0
  73. package/src/runtime/ts_core_host.zig +38 -38
  74. package/src/runtime/ts_ui_app.zig +12 -12
  75. package/src/runtime/ui_app.zig +10 -8
  76. package/src/runtime/ui_app_tests.zig +67 -0
  77. package/src/runtime/view.zig +6 -0
  78. package/src/runtime/view_canvas.zig +15 -0
  79. package/src/runtime/view_widget_text.zig +6 -4
  80. package/src/runtime/window_view_runtime.zig +1 -0
  81. package/src/tooling/manifest.zig +32 -0
  82. package/src/tooling/raw_manifest.zig +4 -0
  83. package/src/tooling/templates.zig +34 -26
  84. package/src/tooling/ts_core.zig +55 -34
  85. package/src/tooling/verbs.zig +1 -1
  86. package/tools/corewire/core_abi.zig +169 -0
  87. package/tools/corewire/emit.zig +2418 -0
  88. package/tools/corewire/emit_facade.zig +3984 -0
  89. package/tools/corewire/emit_profile.zig +501 -0
  90. package/tools/corewire/main.zig +561 -0
  91. package/tools/corewire/shim_rt.zig +632 -0
  92. package/tools/corewire/sidecar.zig +2507 -0
  93. package/packages/core/rt/rt.zig +0 -1986
  94. package/packages/core/src/emitter.ts +0 -11898
@@ -16,6 +16,29 @@ fn spanWithFragment(spans: []const canvas.TextSpan, fragment: []const u8) ?canva
16
16
  return null;
17
17
  }
18
18
 
19
+ test "diff line specs accept one-based values and compact ranges" {
20
+ var storage: [code_model.max_diff_lines]usize = undefined;
21
+ const lines = code_model.parseLineNumberSpec("2-4, 7, 3", &storage).?;
22
+ try testing.expectEqualSlices(usize, &.{ 2, 3, 4, 7 }, lines);
23
+ try testing.expectEqual(@as(usize, 0), code_model.parseLineNumberSpec("", &storage).?.len);
24
+
25
+ const invalid = [_][]const u8{ "0", "4-2", "1-129", "1,,2", "2-", "2-3-4", "nope" };
26
+ for (invalid) |spec| try testing.expect(code_model.parseLineNumberSpec(spec, &storage) == null);
27
+ }
28
+
29
+ test "widget diff metadata round-trips both 128-line masks" {
30
+ var widget = canvas.Widget{ .kind = .text, .code_line_number_digits = 3 };
31
+ const expected = canvas.CodeDiffLines{
32
+ .added = (@as(u128, 1) << 127) | (@as(u128, 1) << 64) | 1,
33
+ .removed = (@as(u128, 1) << 126) | (@as(u128, 1) << 63) | 2,
34
+ };
35
+ widget.setCodeDiffLines(expected);
36
+
37
+ try testing.expectEqual(@as(u8, 3), widget.codeLineNumberDigits());
38
+ try testing.expectEqual(expected.added, widget.codeDiffLines().?.added);
39
+ try testing.expectEqual(expected.removed, widget.codeDiffLines().?.removed);
40
+ }
41
+
19
42
  fn colorAtOffset(spans: []const canvas.TextSpan, offset: usize) ?canvas.TextSpanColor {
20
43
  var cursor: usize = 0;
21
44
  for (spans) |span| {
@@ -781,6 +804,156 @@ test "line numbers are opt-in and stay paired with logical source lines" {
781
804
  try testing.expectEqual(canvas.TextSpanColor.syntax_keyword, spanWithFragment(comment_text.spans, "const").?.color.?);
782
805
  }
783
806
 
807
+ test "diff lines use Geist washes and renderer-owned markers without changing source" {
808
+ const source =
809
+ \\module.exports = {
810
+ \\ experimental: {
811
+ \\ appDir: true,
812
+ \\ },
813
+ \\ appDir: true,
814
+ \\}
815
+ ;
816
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
817
+ defer arena.deinit();
818
+ var ui = Ui.init(arena.allocator());
819
+ const view = try ui.finalize(ui.code(.{
820
+ .language = .javascript,
821
+ .line_numbers = true,
822
+ .added_lines = &.{5},
823
+ .removed_lines = &.{ 2, 3, 4 },
824
+ .wrap = false,
825
+ .width = 360,
826
+ }, source));
827
+ const paragraph = findByText(view.root, source).?;
828
+ try testing.expectEqualStrings(source, paragraph.text);
829
+ const diff_lines = paragraph.codeDiffLines().?;
830
+ try testing.expectEqual(@as(u128, 1) << 4, diff_lines.added);
831
+ try testing.expectEqual((@as(u128, 1) << 1) | (@as(u128, 1) << 2) | (@as(u128, 1) << 3), diff_lines.removed);
832
+
833
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
834
+ const layout = try canvas.layoutWidgetTree(view.root, geometry.RectF.init(0, 0, 360, 140), &nodes);
835
+ for ([_]canvas.ThemePack{ .house, .geist }) |pack| {
836
+ for ([_]canvas.ColorScheme{ .light, .dark }) |scheme| {
837
+ const tokens = canvas.DesignTokens.theme(.{ .pack = pack, .color_scheme = scheme });
838
+ const added_background = if (scheme == .dark)
839
+ canvas.Color.rgb8(18, 54, 27)
840
+ else
841
+ canvas.Color.rgb8(218, 246, 218);
842
+ const removed_background = if (scheme == .dark)
843
+ canvas.Color.rgb8(86, 26, 30)
844
+ else
845
+ canvas.Color.rgb8(255, 230, 230);
846
+ const added_foreground = if (scheme == .dark)
847
+ canvas.Color.rgb8(98, 192, 115)
848
+ else
849
+ canvas.Color.rgb8(41, 122, 58);
850
+ const removed_foreground = if (scheme == .dark)
851
+ canvas.Color.rgb8(255, 97, 102)
852
+ else
853
+ canvas.Color.rgb8(203, 42, 47);
854
+ var commands: [256]canvas.CanvasCommand = undefined;
855
+ var builder = canvas.Builder.init(&commands);
856
+ try canvas.emitWidgetLayout(&builder, layout, tokens);
857
+
858
+ var added_washes: usize = 0;
859
+ var removed_washes: usize = 0;
860
+ var added_markers: usize = 0;
861
+ var removed_markers: usize = 0;
862
+ for (builder.displayList().commands) |command| {
863
+ switch (command) {
864
+ .fill_rect => |fill| {
865
+ if (std.meta.eql(fill.fill.color, added_background)) added_washes += 1;
866
+ if (std.meta.eql(fill.fill.color, removed_background)) removed_washes += 1;
867
+ },
868
+ .draw_text => |draw| {
869
+ if (std.mem.eql(u8, draw.text, "+") and std.meta.eql(draw.color, added_foreground)) added_markers += 1;
870
+ if (std.mem.eql(u8, draw.text, "-") and std.meta.eql(draw.color, removed_foreground)) removed_markers += 1;
871
+ },
872
+ else => {},
873
+ }
874
+ }
875
+ try testing.expectEqual(@as(usize, 1), added_washes);
876
+ try testing.expectEqual(@as(usize, 3), removed_washes);
877
+ try testing.expectEqual(@as(usize, 1), added_markers);
878
+ try testing.expectEqual(@as(usize, 3), removed_markers);
879
+ }
880
+ }
881
+ }
882
+
883
+ test "diff markers reserve a gutter when line numbers are hidden" {
884
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
885
+ defer arena.deinit();
886
+ var ui = Ui.init(arena.allocator());
887
+ const view = try ui.finalize(ui.code(.{ .added_lines = &.{1} }, "added"));
888
+ const paragraph = findByText(view.root, "added").?;
889
+ try testing.expectEqual(@as(u8, 0), paragraph.codeLineNumberDigits());
890
+ try testing.expect(widget_metrics.widgetCodeLineNumberGutterWidth(paragraph, .{}) > 0);
891
+ }
892
+
893
+ test "unwrapped editable diffs paint markers without line numbers" {
894
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
895
+ defer arena.deinit();
896
+ var ui = Ui.init(arena.allocator());
897
+ const view = try ui.finalize(ui.code(.{
898
+ .editable = true,
899
+ .wrap = false,
900
+ .added_lines = &.{1},
901
+ }, "added"));
902
+ var editor = findByText(view.root, "added").?;
903
+ editor.frame = geometry.RectF.init(0, 0, 160, 48);
904
+
905
+ var commands: [64]canvas.CanvasCommand = undefined;
906
+ var builder = canvas.Builder.init(&commands);
907
+ try canvas.emitWidgetTree(&builder, editor, .{});
908
+
909
+ var added_markers: usize = 0;
910
+ for (builder.displayList().commands) |command| {
911
+ if (command == .draw_text and std.mem.eql(u8, command.draw_text.text, "+")) {
912
+ added_markers += 1;
913
+ }
914
+ }
915
+ try testing.expectEqual(@as(usize, 1), added_markers);
916
+ }
917
+
918
+ test "editable diff washes paint behind text selections" {
919
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
920
+ defer arena.deinit();
921
+ var ui = Ui.init(arena.allocator());
922
+ const view = try ui.finalize(ui.code(.{
923
+ .editable = true,
924
+ .wrap = false,
925
+ .added_lines = &.{1},
926
+ }, "added"));
927
+ var editor = findByText(view.root, "added").?;
928
+ editor.frame = geometry.RectF.init(0, 0, 160, 48);
929
+ editor.text_selection = .{ .anchor = 0, .focus = editor.text.len };
930
+
931
+ var tokens = canvas.DesignTokens{};
932
+ const selection_fill = canvas.Color.rgb8(7, 11, 13);
933
+ const added_wash = canvas.Color.rgb8(218, 246, 218);
934
+ tokens.colors.accent = selection_fill;
935
+ tokens.colors.background = canvas.Color.rgb8(255, 255, 255);
936
+
937
+ var commands: [128]canvas.CanvasCommand = undefined;
938
+ var builder = canvas.Builder.init(&commands);
939
+ try canvas.emitWidgetTree(&builder, editor, tokens);
940
+
941
+ var wash_index: ?usize = null;
942
+ var selection_index: ?usize = null;
943
+ for (builder.displayList().commands, 0..) |command, index| {
944
+ if (command != .fill_rect) continue;
945
+ if (std.meta.eql(command.fill_rect.fill.color, added_wash) and
946
+ command.fill_rect.rect.width == editor.frame.width)
947
+ {
948
+ wash_index = index;
949
+ }
950
+ if (std.meta.eql(command.fill_rect.fill.color, selection_fill)) selection_index = index;
951
+ }
952
+ try testing.expect(wash_index != null);
953
+ try testing.expect(selection_index != null);
954
+ try testing.expect(wash_index.? < selection_index.?);
955
+ }
956
+
784
957
  test "line number gutter reserves at least three marker columns" {
785
958
  const tokens = canvas.DesignTokens{};
786
959
  var numbered = canvas.Widget{
@@ -1344,7 +1517,7 @@ test "large code blocks split at the paragraph line capacity without hiding thei
1344
1517
  var group_id: ?canvas.ObjectId = null;
1345
1518
  for (chunk_column.children) |chunk| {
1346
1519
  try testing.expect(chunk.static_text_group_id != 0);
1347
- try testing.expectEqual(expected_offset, chunk.static_text_group_offset);
1520
+ try testing.expectEqual(@as(u64, @intCast(expected_offset)), chunk.static_text_group_offset);
1348
1521
  if (group_id) |expected| {
1349
1522
  try testing.expectEqual(expected, chunk.static_text_group_id);
1350
1523
  } else {
@@ -599,7 +599,7 @@ pub fn buildCanvasFrame(previous: ?DisplayList, next: DisplayList, options: Canv
599
599
  storage.text_layout_cache_actions,
600
600
  );
601
601
 
602
- const full_repaint = options.full_repaint or previous == null;
602
+ var full_repaint = options.full_repaint or previous == null;
603
603
  var changes: []const DiffChange = storage.changes[0..0];
604
604
  var dirty_bounds: ?geometry.RectF = null;
605
605
 
@@ -615,6 +615,18 @@ pub fn buildCanvasFrame(previous: ?DisplayList, next: DisplayList, options: Canv
615
615
  // pixels so a fractional dirty edge cannot erase an unchanged
616
616
  // neighbor's boundary-pixel coverage without redrawing it.
617
617
  dirty_bounds = bleedAlignedDirtyBounds(unionOptionalBounds(dirtyBoundsFromChanges(changes), render_override_dirty_bounds), options.scale, 1, options.surface_size);
618
+ if (incrementalDamageIntersectsBackdropBlur(render_plan.commands, dirty_bounds)) {
619
+ // A backdrop blur reads pixels around its output from the
620
+ // destination as it existed at this point in draw order.
621
+ // Retained pixels outside an incremental scissor already
622
+ // contain the PREVIOUS frame's blur and later commands, so
623
+ // they cannot supply that pre-blur backdrop. Reconstruct it
624
+ // by replaying the complete list whenever damage reaches a
625
+ // blur's resolved read footprint.
626
+ full_repaint = true;
627
+ changes = storage.changes[0..0];
628
+ dirty_bounds = fullRepaintBounds(options.surface_size, render_plan.bounds);
629
+ }
618
630
  }
619
631
 
620
632
  return .{
@@ -649,6 +661,38 @@ pub fn buildCanvasFrame(previous: ?DisplayList, next: DisplayList, options: Canv
649
661
  };
650
662
  }
651
663
 
664
+ /// Whether incremental damage reaches a backdrop blur's resolved read
665
+ /// footprint. Replaying only the dirty output is not sufficient: pixels
666
+ /// outside the scissor hold the previous fully composited frame rather
667
+ /// than the backdrop at the blur command's position in draw order.
668
+ pub fn incrementalDamageIntersectsBackdropBlur(commands: []const RenderCommand, dirty_bounds: ?geometry.RectF) bool {
669
+ const dirty = dirty_bounds orelse return false;
670
+ const normalized_dirty = dirty.normalized();
671
+ for (commands) |command| {
672
+ switch (command.command) {
673
+ .blur => |blur| {
674
+ if (!(blur.radius > 0) or !(command.opacity > 0)) continue;
675
+ var output = command.transform.transformRect(blur.rect.normalized());
676
+ if (command.clip) |clip| output = geometry.RectF.intersection(output, clip.normalized());
677
+ if (output.isEmpty()) continue;
678
+
679
+ // Do not use `command.bounds` here: the render planner
680
+ // intersects that inflated bound with the output clip,
681
+ // while a clipped output pixel still samples backdrop
682
+ // pixels up to `radius` OUTSIDE the clip. Transforming
683
+ // the full local read footprint is a conservative AABB
684
+ // for every sample the surviving output can consume.
685
+ const read_footprint = command.transform.transformRect(
686
+ blur.rect.normalized().inflate(geometry.InsetsF.all(@max(0, blur.radius))),
687
+ ).normalized();
688
+ if (read_footprint.intersects(normalized_dirty)) return true;
689
+ },
690
+ else => {},
691
+ }
692
+ }
693
+ return false;
694
+ }
695
+
652
696
  fn dirtyBoundsFromChanges(changes: []const DiffChange) ?geometry.RectF {
653
697
  var result: ?geometry.RectF = null;
654
698
  for (changes) |change| {
@@ -552,6 +552,12 @@ pub fn canvasGpuCommandFromRenderCommand(command: RenderCommand, command_index:
552
552
  packet_command.uses_resource = true;
553
553
  },
554
554
  .draw_text => |value| {
555
+ // DirectWrite glyph indices are UINT16. A larger author-supplied
556
+ // id cannot ride the positioned-glyph wire faithfully, so keep
557
+ // the packet negotiation truthful and select the pixel path.
558
+ for (value.glyphs) |glyph| {
559
+ if (glyph.id > 65535) return packet_command;
560
+ }
555
561
  packet_command.kind = .draw_text;
556
562
  packet_command.pipeline = .glyph_run;
557
563
  packet_command.paint = .{ .color = value.color };
@@ -2273,6 +2273,57 @@ test "canvas render pass builds gpu packet for backend handoff" {
2273
2273
  try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"effect\":{\"kind\":\"blur\",\"rect\":[44,36,20,20],\"radius\":4}") != null);
2274
2274
  }
2275
2275
 
2276
+ test "gpu packet preserves authoritative text glyph positions" {
2277
+ const glyphs = [_]Glyph{.{
2278
+ .id = 65,
2279
+ .x = 9,
2280
+ .y = 13,
2281
+ .advance = 11,
2282
+ .text_len = 1,
2283
+ }};
2284
+ const bounds = geometry.RectF.init(4, 4, 24, 16);
2285
+ const render_commands = [_]RenderCommand{.{
2286
+ .command = .{ .draw_text = .{
2287
+ .id = 1,
2288
+ .font_id = 7,
2289
+ .size = 12,
2290
+ .origin = geometry.PointF.init(4, 16),
2291
+ .color = Color.rgb8(15, 23, 42),
2292
+ .text = "A",
2293
+ .glyphs = &glyphs,
2294
+ } },
2295
+ .id = 1,
2296
+ .local_bounds = bounds,
2297
+ .bounds = bounds,
2298
+ }};
2299
+
2300
+ var gpu_commands: [1]CanvasGpuCommand = undefined;
2301
+ var planner = CanvasGpuPacketPlanner.init(&gpu_commands);
2302
+ const packet = try planner.build(.{
2303
+ .full_repaint = true,
2304
+ .surface_size = geometry.SizeF.init(32, 24),
2305
+ .commands = &render_commands,
2306
+ });
2307
+
2308
+ try std.testing.expect(packet.fullyRepresentable());
2309
+ try std.testing.expectEqual(@as(usize, 0), packet.unsupported_command_count);
2310
+ try std.testing.expectEqual(CanvasGpuCommandKind.draw_text, packet.commands[0].kind);
2311
+ try std.testing.expectEqualDeep(glyphs[0], packet.commands[0].text.?.glyphs[0]);
2312
+
2313
+ var binary_buffer: [512]u8 = undefined;
2314
+ var binary_writer = std.Io.Writer.fixed(&binary_buffer);
2315
+ try packet.writeBinary(&binary_writer);
2316
+ // id=65, no font override, final pen=(origin.x, origin.y + glyph.y),
2317
+ // advance=11 — the compact v5 record DirectWrite consumes.
2318
+ const positioned_glyph_wire = [_]u8{
2319
+ 0x41, 0x00, 0x00,
2320
+ 0x00, 0x00, 0x80, 0x40,
2321
+ 0x00, 0x00, 0xe8, 0x41,
2322
+ 0x00, 0x00, 0x30, 0x41,
2323
+ };
2324
+ try std.testing.expect(std.mem.indexOf(u8, binary_writer.buffered(), &positioned_glyph_wire) != null);
2325
+ }
2326
+
2276
2327
  test "canvas gpu packet skips clean passes and reports output overflow" {
2277
2328
  var clean_gpu_commands: [1]CanvasGpuCommand = undefined;
2278
2329
  const clean_packet = try (CanvasRenderPass{}).gpuPacket(&clean_gpu_commands);
@@ -2893,6 +2944,48 @@ test "canvas frame plan clips incremental dirty bounds to surface" {
2893
2944
  try std.testing.expect(std.mem.indexOf(u8, profile_json, "\"risk\":\"high\"") != null);
2894
2945
  }
2895
2946
 
2947
+ test "canvas frame plan fully repaints damage inside a backdrop blur apron" {
2948
+ const previous_commands = [_]CanvasCommand{
2949
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(44, 15, 4, 4), .fill = .{ .color = Color.rgb8(255, 0, 0) } } },
2950
+ .{ .push_clip = .{ .id = 2, .rect = geometry.RectF.init(50, 10, 20, 20) } },
2951
+ .{ .blur = .{ .id = 3, .rect = geometry.RectF.init(50, 10, 20, 20), .radius = 8 } },
2952
+ .pop_clip,
2953
+ };
2954
+ const next_commands = [_]CanvasCommand{
2955
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(44, 15, 4, 4), .fill = .{ .color = Color.rgb8(0, 0, 255) } } },
2956
+ previous_commands[1],
2957
+ previous_commands[2],
2958
+ previous_commands[3],
2959
+ };
2960
+
2961
+ var render_commands: [2]RenderCommand = undefined;
2962
+ var render_batches: [2]RenderBatch = undefined;
2963
+ var resources: [1]RenderResource = undefined;
2964
+ var resource_cache_entries: [1]RenderResourceCacheEntry = undefined;
2965
+ var resource_cache_actions: [1]RenderResourceCacheAction = undefined;
2966
+ var glyphs: [0]GlyphAtlasEntry = .{};
2967
+ var changes: [2]DiffChange = undefined;
2968
+ const frame = try (DisplayList{ .commands = &next_commands }).framePlan(.{ .commands = &previous_commands }, .{
2969
+ .surface_size = geometry.SizeF.init(100, 40),
2970
+ }, .{
2971
+ .render_commands = &render_commands,
2972
+ .render_batches = &render_batches,
2973
+ .resources = &resources,
2974
+ .resource_cache_entries = &resource_cache_entries,
2975
+ .resource_cache_actions = &resource_cache_actions,
2976
+ .glyph_atlas_entries = &glyphs,
2977
+ .changes = &changes,
2978
+ });
2979
+
2980
+ // The changed fill ends at x=48, before the blur output begins at
2981
+ // x=50, but inside its radius-8 read footprint. Incremental replay
2982
+ // cannot reconstruct the pre-blur backdrop outside its scissor.
2983
+ try std.testing.expect(frame.full_repaint);
2984
+ try std.testing.expectEqual(@as(usize, 0), frame.changes.len);
2985
+ try expectRect(geometry.RectF.init(0, 0, 100, 40), frame.dirty_bounds);
2986
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.clear, frame.renderPass().loadAction());
2987
+ }
2988
+
2896
2989
  test "canvas frame plan leaves unchanged retained frame clean" {
2897
2990
  const commands = [_]CanvasCommand{
2898
2991
  .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 40, 40), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
@@ -298,6 +298,7 @@ pub const CanvasRenderPass = frame_model.CanvasRenderPass;
298
298
  pub const CanvasFrame = frame_model.CanvasFrame;
299
299
  pub const max_canvas_frame_dirty_rects = frame_model.max_canvas_frame_dirty_rects;
300
300
  pub const buildCanvasFrame = frame_model.buildCanvasFrame;
301
+ pub const incrementalDamageIntersectsBackdropBlur = frame_model.incrementalDamageIntersectsBackdropBlur;
301
302
 
302
303
  // Canvas GPU packet and encoder data live in `gpu.zig`; root keeps the public API stable.
303
304
  pub const CanvasRenderPassLoadAction = gpu_model.CanvasRenderPassLoadAction;
@@ -449,6 +450,7 @@ pub const builtinComponentDescriptor = widget_model.builtinComponentDescriptor;
449
450
  pub const WidgetActions = widget_model.WidgetActions;
450
451
  pub const WidgetSemantics = widget_model.WidgetSemantics;
451
452
  pub const WidgetContextMenuItem = widget_model.WidgetContextMenuItem;
453
+ pub const CodeDiffLines = widget_model.CodeDiffLines;
452
454
  pub const Widget = widget_model.Widget;
453
455
  pub const BuiltinComponentOptions = widget_model.BuiltinComponentOptions;
454
456
  pub const WidgetCommandPart = widget_model.WidgetCommandPart;
@@ -504,16 +504,20 @@ const max_packet_text_layout_lines: usize = 64;
504
504
  /// they can never disagree on line breaks. Returns null when the run
505
505
  /// exceeds the line budget, which keeps the host's legacy wrapping
506
506
  /// fallback.
507
- fn packetTextLayout(value: CanvasGpuText, options: TextLayoutOptions, lines: []TextLine) ?text_model.TextLayout {
508
- return text_model.layoutTextRun(.{
507
+ fn packetDrawText(value: CanvasGpuText) text_model.DrawText {
508
+ return .{
509
509
  .font_id = value.font_id,
510
510
  .size = value.size,
511
511
  .origin = value.origin,
512
512
  .color = value.color,
513
513
  .text = value.text,
514
514
  .glyphs = value.glyphs,
515
- .text_layout = options,
516
- }, options, lines) catch null;
515
+ .text_layout = value.text_layout,
516
+ };
517
+ }
518
+
519
+ fn packetTextLayout(value: CanvasGpuText, options: TextLayoutOptions, lines: []TextLine) ?text_model.TextLayout {
520
+ return text_model.layoutTextRun(packetDrawText(value), options, lines) catch null;
517
521
  }
518
522
 
519
523
  fn writeCanvasGpuTextLinesJson(value: CanvasGpuText, options: TextLayoutOptions, writer: anytype) !void {
@@ -976,22 +980,19 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
976
980
  }
977
981
 
978
982
  // ---------------------------------------------------------------------------
979
- // Compact binary gpu-surface packet encoding (wire format v4).
983
+ // Compact binary gpu-surface packet encoding (wire format v5).
980
984
  //
981
985
  // The version this comment names, the `binary_packet_version` constant
982
- // below, and the host decoder's spec comment (appkit_host.m) must agree;
986
+ // below, and both host decoders' spec comments (appkit_host.m and the
987
+ // Windows gpu_surface_renderer.cpp) must agree;
983
988
  // the `test-wire-format-version-prose` build check pins all three, so
984
989
  // bumping the constant without updating the prose fails the suite.
985
990
  //
986
- // Little-endian, length-prefixed throughout, no field names, no decimal
987
- // formatting, and no glyph arrays (the packet host draws text through the
988
- // system text stack from the run's UTF-8 text plus the engine-measured
989
- // lines, so glyph payloads — the bulk of a text-heavy JSON packet — never
990
- // ride the wire). The AppKit host decoder
991
- // (`NativeSdkPacketDictionaryFromBinary` in appkit_host.m) pins the same
992
- // layout and tag tables independently; a disagreement fails the host
993
- // decode loudly (refused present -> recorded fallback) instead of drawing
994
- // garbage. Bump `binary_packet_version` on ANY layout change.
991
+ // Little-endian, length-prefixed throughout, with no field names or decimal
992
+ // formatting. The AppKit and Windows host decoders pin the same layout
993
+ // and tag tables independently; a disagreement fails host decode loudly
994
+ // (refused present -> recorded fallback) instead of drawing garbage. Bump
995
+ // `binary_packet_version` on ANY layout change.
995
996
  //
996
997
  // v2 (from v1): every header carries a retained-state `generation`, every
997
998
  // command rides behind an explicit retain `key` (its ObjectId, or a
@@ -1013,6 +1014,11 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
1013
1014
  // (the checkbox mark, the spinner arc) with the same cap the reference
1014
1015
  // renderer rasterizes instead of their engine default.
1015
1016
  //
1017
+ // v5 (from v4): text commands carry optional compact positioned-glyph runs
1018
+ // after their UTF-8 text. Each glyph preserves its engine-resolved index,
1019
+ // font override, final pen x/baseline, and advance; synthesized elision
1020
+ // markers ride as positioned UTF-8 fragments.
1021
+ //
1016
1022
  // Layout:
1017
1023
  // "NSGP" u8[4] | version u8 | load_action u8 (1 load / 2 clear /
1018
1024
  // 3 patch) | flags u8 (bit0 scissor, bit1 dirty rect list) | reserved u8
@@ -1030,7 +1036,7 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
1030
1036
  // | order_count u32 | order keys u64[]
1031
1037
 
1032
1038
  pub const binary_packet_magic = "NSGP";
1033
- pub const binary_packet_version: u8 = 4;
1039
+ pub const binary_packet_version: u8 = 5;
1034
1040
 
1035
1041
  /// Most dirty rects a patch header carries: enough to keep far-apart
1036
1042
  /// small changes (a switch plus a status line) from fusing into a
@@ -1422,7 +1428,11 @@ fn writeBinaryImage(image: CanvasGpuImage, writer: anytype) !void {
1422
1428
  }
1423
1429
 
1424
1430
  /// Text draw: font_id u64 | size f32 | origin f32[2] | color f32[4]
1425
- /// | text u32+bytes | has_layout u8 | layout { max_width f32,
1431
+ /// | text u32+bytes | has_positioned_glyphs u8 | [glyph_count u32,
1432
+ /// glyphs { id u16, flags u8 (bit0 font override), [font_id u64],
1433
+ /// x f32, baseline f32, advance f32 }, fragment_count u32, fragments
1434
+ /// { x f32, baseline f32, text u32+bytes }] | has_layout u8 | layout {
1435
+ /// max_width f32,
1426
1436
  /// line_height f32, wrap u8 (0 none / 1 word / 2 character), align u8
1427
1437
  /// (0 start / 1 center / 2 end), has_lines u8, [line_count u32, lines
1428
1438
  /// { x f32, baseline f32, text u32+bytes }] }. Lines carry the same
@@ -1435,6 +1445,9 @@ fn writeBinaryText(text: CanvasGpuText, writer: anytype) !void {
1435
1445
  try writeBinaryPoint(text.origin, writer);
1436
1446
  try writeBinaryColor(text.color, writer);
1437
1447
  try writeBinarySlice(text.text, writer);
1448
+ var lines: [max_packet_text_layout_lines]TextLine = undefined;
1449
+ const layout = if (text.text_layout) |options| packetTextLayout(text, options, &lines) else null;
1450
+ try writeBinaryPositionedText(text, layout, writer);
1438
1451
  const options = text.text_layout orelse {
1439
1452
  try writer.writeByte(0);
1440
1453
  return;
@@ -1452,14 +1465,13 @@ fn writeBinaryText(text: CanvasGpuText, writer: anytype) !void {
1452
1465
  .center => 1,
1453
1466
  .end => 2,
1454
1467
  });
1455
- var lines: [max_packet_text_layout_lines]TextLine = undefined;
1456
- const layout = packetTextLayout(text, options, &lines) orelse {
1468
+ const planned_layout = layout orelse {
1457
1469
  try writer.writeByte(0);
1458
1470
  return;
1459
1471
  };
1460
1472
  try writer.writeByte(1);
1461
- try writer.writeInt(u32, @intCast(layout.lines.len), .little);
1462
- for (layout.lines) |line| {
1473
+ try writer.writeInt(u32, @intCast(planned_layout.lines.len), .little);
1474
+ for (planned_layout.lines) |line| {
1463
1475
  // Elided lines ship painted bytes (kept prefix + ellipsis),
1464
1476
  // mirroring the JSON encoding, so both packet hosts draw the
1465
1477
  // measured extent verbatim.
@@ -1474,6 +1486,123 @@ fn writeBinaryText(text: CanvasGpuText, writer: anytype) !void {
1474
1486
  }
1475
1487
  }
1476
1488
 
1489
+ /// Resolve shaped glyphs onto the same final per-line positions the reference
1490
+ /// renderer uses. Packet hosts can draw these glyph indices directly instead
1491
+ /// of reshaping UTF-8 and discarding authoritative x/y placement. Elision
1492
+ /// markers are separate positioned text fragments because they are synthesized
1493
+ /// by layout and have no source glyph id.
1494
+ fn writeBinaryPositionedText(text: CanvasGpuText, layout: ?text_model.TextLayout, writer: anytype) !void {
1495
+ if (text.glyphs.len == 0) {
1496
+ try writer.writeByte(0);
1497
+ return;
1498
+ }
1499
+ try writer.writeByte(1);
1500
+
1501
+ var glyph_count: usize = 0;
1502
+ if (layout) |planned| {
1503
+ for (planned.lines) |line| {
1504
+ if (line.glyph_start >= text.glyphs.len) continue;
1505
+ glyph_count += @min(line.paintedGlyphLen(), text.glyphs.len - line.glyph_start);
1506
+ }
1507
+ } else {
1508
+ glyph_count = text.glyphs.len;
1509
+ }
1510
+ try writer.writeInt(u32, @intCast(glyph_count), .little);
1511
+
1512
+ const draw_text = packetDrawText(text);
1513
+ if (layout) |planned| {
1514
+ for (planned.lines) |line| {
1515
+ if (line.glyph_start >= text.glyphs.len) continue;
1516
+ const count = @min(line.paintedGlyphLen(), text.glyphs.len - line.glyph_start);
1517
+ if (count == 0) continue;
1518
+ const line_glyphs = text.glyphs[line.glyph_start..][0..count];
1519
+ const raw_bounds = text_model.textLineBounds(
1520
+ draw_text,
1521
+ line.text_start,
1522
+ line.paintedTextLen(),
1523
+ line.glyph_start,
1524
+ count,
1525
+ line.baseline,
1526
+ line.bounds.height,
1527
+ );
1528
+ const first_x = line_glyphs[0].x;
1529
+ const dx = line.bounds.x - raw_bounds.x;
1530
+ for (line_glyphs) |glyph| {
1531
+ try writeBinaryPositionedGlyph(
1532
+ text,
1533
+ glyph,
1534
+ text.origin.x + glyph.x - first_x + dx,
1535
+ line.baseline + glyph.y,
1536
+ writer,
1537
+ );
1538
+ }
1539
+ }
1540
+ } else {
1541
+ const first_x = text.glyphs[0].x;
1542
+ for (text.glyphs) |glyph| {
1543
+ try writeBinaryPositionedGlyph(
1544
+ text,
1545
+ glyph,
1546
+ text.origin.x + glyph.x - first_x,
1547
+ text.origin.y + glyph.y,
1548
+ writer,
1549
+ );
1550
+ }
1551
+ }
1552
+
1553
+ var fragment_count: usize = 0;
1554
+ if (layout) |planned| {
1555
+ for (planned.lines) |line| {
1556
+ const visible_glyphs = if (line.glyph_start < text.glyphs.len)
1557
+ @min(line.paintedGlyphLen(), text.glyphs.len - line.glyph_start)
1558
+ else
1559
+ 0;
1560
+ const start = @min(line.text_start, text.text.len);
1561
+ const end = @min(text.text.len, start + line.paintedTextLen());
1562
+ if ((visible_glyphs == 0 and end > start) or line.hasEllipsis()) fragment_count += 1;
1563
+ }
1564
+ }
1565
+ try writer.writeInt(u32, @intCast(fragment_count), .little);
1566
+ if (layout) |planned| {
1567
+ for (planned.lines) |line| {
1568
+ const visible_glyphs = if (line.glyph_start < text.glyphs.len)
1569
+ @min(line.paintedGlyphLen(), text.glyphs.len - line.glyph_start)
1570
+ else
1571
+ 0;
1572
+ const start = @min(line.text_start, text.text.len);
1573
+ const end = @min(text.text.len, start + line.paintedTextLen());
1574
+ const ellipsis = packetLineEllipsis(line);
1575
+ if (visible_glyphs != 0 and ellipsis.len == 0) continue;
1576
+ if (visible_glyphs == 0 and end == start and ellipsis.len == 0) continue;
1577
+ try writeBinaryF32(if (visible_glyphs == 0) line.bounds.x else line.bounds.maxX() - line.ellipsis_advance, writer);
1578
+ try writeBinaryF32(line.baseline, writer);
1579
+ if (visible_glyphs == 0) {
1580
+ try writer.writeInt(u32, @intCast(end - start + ellipsis.len), .little);
1581
+ try writer.writeAll(text.text[start..end]);
1582
+ try writer.writeAll(ellipsis);
1583
+ } else {
1584
+ try writeBinarySlice(ellipsis, writer);
1585
+ }
1586
+ }
1587
+ }
1588
+ }
1589
+
1590
+ fn writeBinaryPositionedGlyph(
1591
+ text: CanvasGpuText,
1592
+ glyph: Glyph,
1593
+ x: f32,
1594
+ baseline: f32,
1595
+ writer: anytype,
1596
+ ) !void {
1597
+ try writer.writeInt(u16, @intCast(glyph.id), .little);
1598
+ const has_font_override = glyph.font_id != 0;
1599
+ try writer.writeByte(if (has_font_override) 1 else 0);
1600
+ if (has_font_override) try writer.writeInt(u64, glyph.font_id, .little);
1601
+ try writeBinaryF32(x, writer);
1602
+ try writeBinaryF32(baseline, writer);
1603
+ try writeBinaryF32(text_model.estimatedGlyphAdvance(glyph, text.size), writer);
1604
+ }
1605
+
1477
1606
  /// Effect: tag u8 (1 shadow / 2 blur) + payload.
1478
1607
  fn writeBinaryEffect(effect: CanvasGpuEffect, writer: anytype) !void {
1479
1608
  switch (effect) {