@native-sdk/cli 0.6.2 → 0.7.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.
- package/build.zig +8 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/text.ts +62 -21
- package/skill-data/native-ui/SKILL.md +17 -2
- package/src/platform/macos/appkit_host.h +2 -0
- package/src/platform/macos/appkit_host.m +36 -10
- package/src/platform/macos/root.zig +7 -1
- package/src/platform/types.zig +2 -0
- package/src/primitives/canvas/code.zig +590 -0
- package/src/primitives/canvas/code_tests.zig +1062 -0
- package/src/primitives/canvas/equality.zig +3 -1
- package/src/primitives/canvas/events.zig +4 -0
- package/src/primitives/canvas/layout_audit.zig +3 -1
- package/src/primitives/canvas/markdown.zig +13 -11
- package/src/primitives/canvas/markdown_tests.zig +167 -4
- package/src/primitives/canvas/root.zig +15 -2
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text.zig +10 -0
- package/src/primitives/canvas/text_interaction.zig +164 -22
- package/src/primitives/canvas/text_layout.zig +107 -21
- package/src/primitives/canvas/text_measure_cache.zig +4 -4
- package/src/primitives/canvas/text_span_tests.zig +254 -0
- package/src/primitives/canvas/text_spans.zig +556 -32
- package/src/primitives/canvas/text_tests.zig +86 -0
- package/src/primitives/canvas/themes/geist.zig +29 -0
- package/src/primitives/canvas/tokens.zig +72 -2
- package/src/primitives/canvas/ui.zig +325 -21
- package/src/primitives/canvas/ui_markup.zig +59 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +76 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +33 -0
- package/src/primitives/canvas/ui_markup_contract.zig +34 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +20 -3
- package/src/primitives/canvas/ui_markup_view.zig +73 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +101 -0
- package/src/primitives/canvas/ui_schema.zig +17 -6
- package/src/primitives/canvas/ui_schema_tests.zig +7 -6
- package/src/primitives/canvas/ui_tests.zig +6 -0
- package/src/primitives/canvas/widget_invalidation.zig +3 -0
- package/src/primitives/canvas/widget_layout.zig +57 -8
- package/src/primitives/canvas/widget_layout_tests.zig +35 -0
- package/src/primitives/canvas/widget_metrics.zig +30 -1
- package/src/primitives/canvas/widget_render.zig +454 -9
- package/src/primitives/canvas/widget_runtime.zig +1 -0
- package/src/primitives/canvas/widget_text_input.zig +23 -11
- package/src/primitives/canvas/widget_text_select.zig +2 -2
- package/src/primitives/canvas/widgets.zig +13 -0
- package/src/root.zig +1 -0
- package/src/runtime/api.zig +9 -0
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_limits.zig +7 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +27 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +146 -0
- package/src/runtime/canvas_widget_context_menu.zig +12 -2
- package/src/runtime/canvas_widget_display.zig +15 -1
- package/src/runtime/canvas_widget_events.zig +50 -20
- package/src/runtime/canvas_widget_runtime.zig +74 -12
- package/src/runtime/canvas_widget_state.zig +1 -0
- package/src/runtime/canvas_widget_text_tests.zig +1935 -70
- package/src/runtime/gpu_surface_events.zig +38 -0
- package/src/runtime/view.zig +37 -3
- package/src/runtime/view_widget_text.zig +1242 -14
- package/src/runtime/view_widget_tree.zig +2 -0
|
@@ -4,6 +4,7 @@ const canvas = @import("root.zig");
|
|
|
4
4
|
const text_spans = @import("text_spans.zig");
|
|
5
5
|
const text_metrics = @import("text_metrics.zig");
|
|
6
6
|
const ui_model = @import("ui.zig");
|
|
7
|
+
const widget_text_select = @import("widget_text_select.zig");
|
|
7
8
|
|
|
8
9
|
const testing = std.testing;
|
|
9
10
|
const TextSpan = text_spans.TextSpan;
|
|
@@ -77,6 +78,28 @@ test "mono spans measure and draw with the mono font id" {
|
|
|
77
78
|
try testing.expectApproxEqAbs(@as(f32, 9 * 14 * 0.6), result.runs[1].width, 0.01);
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
test "mono spans preserve source indentation after line breaks" {
|
|
82
|
+
const spans = [_]TextSpan{
|
|
83
|
+
.{ .text = "fn main() {\n ", .monospace = true },
|
|
84
|
+
.{ .text = "return", .monospace = true, .color = .info },
|
|
85
|
+
.{ .text = ";\n}", .monospace = true },
|
|
86
|
+
};
|
|
87
|
+
var runs: [text_spans.max_text_span_runs_per_paragraph]TextSpanRun = undefined;
|
|
88
|
+
const result = layout(&spans, .{ .size = 14, .max_width = 10_000 }, &runs);
|
|
89
|
+
|
|
90
|
+
var indent: ?TextSpanRun = null;
|
|
91
|
+
var keyword: ?TextSpanRun = null;
|
|
92
|
+
for (result.runs) |run| {
|
|
93
|
+
if (run.line_index == 1 and std.mem.eql(u8, run.text, " ")) indent = run;
|
|
94
|
+
if (run.line_index == 1 and std.mem.eql(u8, run.text, "return")) keyword = run;
|
|
95
|
+
}
|
|
96
|
+
try testing.expect(indent != null);
|
|
97
|
+
try testing.expect(keyword != null);
|
|
98
|
+
try testing.expectEqual(@as(f32, 0), indent.?.x);
|
|
99
|
+
try testing.expect(keyword.?.x > 0);
|
|
100
|
+
try testing.expectApproxEqAbs(indent.?.width, keyword.?.x, 0.01);
|
|
101
|
+
}
|
|
102
|
+
|
|
80
103
|
const FakeMeasure = struct {
|
|
81
104
|
calls: usize = 0,
|
|
82
105
|
mono_calls: usize = 0,
|
|
@@ -198,6 +221,112 @@ test "an oversized word cluster-wraps instead of overflowing" {
|
|
|
198
221
|
try testing.expectEqual(@as(usize, 20), total);
|
|
199
222
|
}
|
|
200
223
|
|
|
224
|
+
test "a later visual-line page retains an over-capacity wrapped paragraph" {
|
|
225
|
+
const spans = [_]TextSpan{.{ .text = "a" ** 140 }};
|
|
226
|
+
const options = text_spans.TextSpanLayoutOptions{ .size = 14, .max_width = 1 };
|
|
227
|
+
var first_runs: [text_spans.max_text_span_runs_per_paragraph]TextSpanRun = undefined;
|
|
228
|
+
const first = layout(&spans, options, &first_runs);
|
|
229
|
+
|
|
230
|
+
try testing.expectEqual(@as(usize, 140), first.line_count);
|
|
231
|
+
try testing.expectEqual(text_spans.max_text_span_lines_per_paragraph, first.runs.len);
|
|
232
|
+
try testing.expect(first.truncated);
|
|
233
|
+
|
|
234
|
+
var later_runs: [text_spans.max_text_span_runs_per_paragraph]TextSpanRun = undefined;
|
|
235
|
+
const later = text_spans.layoutTextSpansFromLine(
|
|
236
|
+
&spans,
|
|
237
|
+
options,
|
|
238
|
+
text_spans.max_text_span_lines_per_paragraph,
|
|
239
|
+
&later_runs,
|
|
240
|
+
);
|
|
241
|
+
try testing.expectEqual(first.line_count, later.line_count);
|
|
242
|
+
try testing.expectEqual(first.size.width, later.size.width);
|
|
243
|
+
try testing.expectEqual(first.size.height, later.size.height);
|
|
244
|
+
try testing.expectEqual(@as(usize, 12), later.runs.len);
|
|
245
|
+
try testing.expectEqual(@as(usize, 128), later.runs[0].line_index);
|
|
246
|
+
try testing.expectEqual(@as(usize, 139), later.runs[later.runs.len - 1].line_index);
|
|
247
|
+
try testing.expect(!later.truncated);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const VariableClusterMeasure = struct {
|
|
251
|
+
fn advance(text: []const u8) f32 {
|
|
252
|
+
return switch (text[0]) {
|
|
253
|
+
'a' => 3,
|
|
254
|
+
0xc3 => 10, // é
|
|
255
|
+
0xcc => 0, // combining acute: continuation of the é cluster
|
|
256
|
+
0xe7 => 20, // 界
|
|
257
|
+
'z' => 5,
|
|
258
|
+
'q' => 7,
|
|
259
|
+
else => 1,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
fn measure(_: ?*anyopaque, _: canvas.FontId, _: f32, text: []const u8) f32 {
|
|
264
|
+
var width: f32 = 0;
|
|
265
|
+
var cursor: usize = 0;
|
|
266
|
+
while (cursor < text.len) {
|
|
267
|
+
width += advance(text[cursor..]);
|
|
268
|
+
const sequence_len = std.unicode.utf8ByteSequenceLength(text[cursor]) catch 1;
|
|
269
|
+
cursor += @min(sequence_len, text.len - cursor);
|
|
270
|
+
}
|
|
271
|
+
return width;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
fn measureAdvances(
|
|
275
|
+
_: ?*anyopaque,
|
|
276
|
+
_: canvas.FontId,
|
|
277
|
+
_: f32,
|
|
278
|
+
text: []const u8,
|
|
279
|
+
advances: []f32,
|
|
280
|
+
) bool {
|
|
281
|
+
@memset(advances, 0);
|
|
282
|
+
var cursor: usize = 0;
|
|
283
|
+
while (cursor < text.len) {
|
|
284
|
+
advances[cursor] = advance(text[cursor..]);
|
|
285
|
+
const sequence_len = std.unicode.utf8ByteSequenceLength(text[cursor]) catch 1;
|
|
286
|
+
cursor += @min(sequence_len, text.len - cursor);
|
|
287
|
+
}
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
test "visible run slicing follows measured cluster advances" {
|
|
293
|
+
const source = "a\xc3\xa9\xcc\x81\xe7\x95\x8czq";
|
|
294
|
+
const spans = [_]TextSpan{.{ .text = source }};
|
|
295
|
+
const batched_provider = text_metrics.TextMeasureProvider{
|
|
296
|
+
.measure_fn = VariableClusterMeasure.measure,
|
|
297
|
+
.measure_advances_fn = VariableClusterMeasure.measureAdvances,
|
|
298
|
+
};
|
|
299
|
+
const unbatched_provider = text_metrics.TextMeasureProvider{
|
|
300
|
+
.measure_fn = VariableClusterMeasure.measure,
|
|
301
|
+
};
|
|
302
|
+
var options = text_spans.TextSpanLayoutOptions{
|
|
303
|
+
.size = 14,
|
|
304
|
+
.max_width = 10_000,
|
|
305
|
+
.measure = &batched_provider,
|
|
306
|
+
};
|
|
307
|
+
var runs: [text_spans.max_text_span_runs_per_paragraph]TextSpanRun = undefined;
|
|
308
|
+
const result = layout(&spans, options, &runs);
|
|
309
|
+
try testing.expectEqual(@as(usize, 1), result.runs.len);
|
|
310
|
+
|
|
311
|
+
// The viewport begins inside 界. Keep the preceding é+combining-mark
|
|
312
|
+
// cluster and the following z guard, but neither the leading a nor q.
|
|
313
|
+
for ([_]*const text_metrics.TextMeasureProvider{
|
|
314
|
+
&batched_provider,
|
|
315
|
+
&unbatched_provider,
|
|
316
|
+
}) |provider| {
|
|
317
|
+
options.measure = provider;
|
|
318
|
+
const visible = text_spans.textSpanRunVisibleSlice(
|
|
319
|
+
spans[0],
|
|
320
|
+
result.runs[0],
|
|
321
|
+
options,
|
|
322
|
+
14,
|
|
323
|
+
20,
|
|
324
|
+
).?;
|
|
325
|
+
try testing.expectEqualStrings("\xc3\xa9\xcc\x81\xe7\x95\x8cz", visible.text);
|
|
326
|
+
try testing.expectEqual(@as(f32, 3), visible.x);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
201
330
|
test "center alignment shifts whole lines" {
|
|
202
331
|
const spans = [_]TextSpan{.{ .text = "hi" }};
|
|
203
332
|
var runs: [text_spans.max_text_span_runs_per_paragraph]TextSpanRun = undefined;
|
|
@@ -507,6 +636,131 @@ test "span selection maps points to paragraph offsets and back to rects" {
|
|
|
507
636
|
try testing.expectEqual(@as(usize, 0), text_spans.textSpanSelectionRects(paragraph, &spans, options, .{ .start = 3, .end = 3 }, &rects).len);
|
|
508
637
|
}
|
|
509
638
|
|
|
639
|
+
test "preformatted span hit mapping preserves unpainted source whitespace" {
|
|
640
|
+
const trailing = "value \t\n";
|
|
641
|
+
const trailing_spans = [_]TextSpan{.{
|
|
642
|
+
.text = trailing,
|
|
643
|
+
.monospace = true,
|
|
644
|
+
.color = .syntax_plain,
|
|
645
|
+
}};
|
|
646
|
+
const options = text_spans.TextSpanLayoutOptions{ .size = 14, .max_width = 200 };
|
|
647
|
+
try testing.expectEqual(
|
|
648
|
+
trailing.len,
|
|
649
|
+
text_spans.textSpanOffsetForPoint(
|
|
650
|
+
trailing,
|
|
651
|
+
&trailing_spans,
|
|
652
|
+
options,
|
|
653
|
+
geometry.PointF.init(500, 2),
|
|
654
|
+
).?,
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
const whitespace = " \n\t";
|
|
658
|
+
const whitespace_spans = [_]TextSpan{.{
|
|
659
|
+
.text = whitespace,
|
|
660
|
+
.monospace = true,
|
|
661
|
+
.color = .syntax_plain,
|
|
662
|
+
}};
|
|
663
|
+
try testing.expectEqual(
|
|
664
|
+
@as(usize, 0),
|
|
665
|
+
text_spans.textSpanOffsetForPoint(
|
|
666
|
+
whitespace,
|
|
667
|
+
&whitespace_spans,
|
|
668
|
+
options,
|
|
669
|
+
geometry.PointF.init(-1, 2),
|
|
670
|
+
).?,
|
|
671
|
+
);
|
|
672
|
+
try testing.expectEqual(
|
|
673
|
+
whitespace.len,
|
|
674
|
+
text_spans.textSpanOffsetForPoint(
|
|
675
|
+
whitespace,
|
|
676
|
+
&whitespace_spans,
|
|
677
|
+
options,
|
|
678
|
+
geometry.PointF.init(500, 500),
|
|
679
|
+
).?,
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
test "span hit mapping and selection page beyond the first 128 visual lines" {
|
|
684
|
+
const paragraph = "a" ** 140;
|
|
685
|
+
const spans = [_]TextSpan{.{ .text = paragraph, .monospace = true }};
|
|
686
|
+
const options = text_spans.TextSpanLayoutOptions{ .size = 14, .max_width = 1 };
|
|
687
|
+
var runs: [text_spans.max_text_span_runs_per_paragraph]TextSpanRun = undefined;
|
|
688
|
+
const layout_result = layout(&spans, options, &runs);
|
|
689
|
+
try testing.expectEqual(@as(usize, 140), layout_result.line_count);
|
|
690
|
+
|
|
691
|
+
const later_line: usize = 132;
|
|
692
|
+
const y = (@as(f32, @floatFromInt(later_line)) + 0.5) * layout_result.line_height;
|
|
693
|
+
try testing.expectEqual(
|
|
694
|
+
later_line,
|
|
695
|
+
text_spans.textSpanOffsetForPoint(
|
|
696
|
+
paragraph,
|
|
697
|
+
&spans,
|
|
698
|
+
options,
|
|
699
|
+
geometry.PointF.init(-1, y),
|
|
700
|
+
).?,
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
var rects: [16]canvas.TextSelectionRect = undefined;
|
|
704
|
+
const selection = text_spans.textSpanSelectionRects(
|
|
705
|
+
paragraph,
|
|
706
|
+
&spans,
|
|
707
|
+
options,
|
|
708
|
+
.{ .start = later_line, .end = paragraph.len },
|
|
709
|
+
&rects,
|
|
710
|
+
);
|
|
711
|
+
try testing.expectEqual(paragraph.len - later_line, selection.len);
|
|
712
|
+
try testing.expectEqual(later_line, selection[0].range.start);
|
|
713
|
+
try testing.expectEqual(
|
|
714
|
+
@as(f32, @floatFromInt(later_line)) * layout_result.line_height,
|
|
715
|
+
selection[0].rect.y,
|
|
716
|
+
);
|
|
717
|
+
try testing.expectEqual(paragraph.len, selection[selection.len - 1].range.end);
|
|
718
|
+
|
|
719
|
+
// The renderer's fixed rect budget folds every remaining line,
|
|
720
|
+
// including the second layout page, into its final highlight.
|
|
721
|
+
var bounded_rects: [widget_text_select.max_static_text_selection_rects]canvas.TextSelectionRect = undefined;
|
|
722
|
+
const bounded = text_spans.textSpanSelectionRects(
|
|
723
|
+
paragraph,
|
|
724
|
+
&spans,
|
|
725
|
+
options,
|
|
726
|
+
.{ .start = 0, .end = paragraph.len },
|
|
727
|
+
&bounded_rects,
|
|
728
|
+
);
|
|
729
|
+
try testing.expectEqual(bounded_rects.len, bounded.len);
|
|
730
|
+
try testing.expectEqual(@as(usize, 63), bounded[bounded.len - 1].range.start);
|
|
731
|
+
try testing.expectEqual(paragraph.len, bounded[bounded.len - 1].range.end);
|
|
732
|
+
try testing.expectApproxEqAbs(@as(f32, 0), bounded[bounded.len - 1].rect.x, 0.001);
|
|
733
|
+
try testing.expectApproxEqAbs(63 * layout_result.line_height, bounded[bounded.len - 1].rect.y, 0.001);
|
|
734
|
+
try testing.expectApproxEqAbs(
|
|
735
|
+
(paragraph.len - 63) * layout_result.line_height,
|
|
736
|
+
bounded[bounded.len - 1].rect.height,
|
|
737
|
+
0.001,
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
test "span selection crosses an empty interior visual-line page" {
|
|
742
|
+
const paragraph = "a\n" ++
|
|
743
|
+
("\n" ** (text_spans.max_text_span_lines_per_paragraph * 2)) ++
|
|
744
|
+
"b";
|
|
745
|
+
const spans = [_]TextSpan{.{ .text = paragraph, .monospace = true }};
|
|
746
|
+
const options = text_spans.TextSpanLayoutOptions{ .size = 14, .max_width = 100 };
|
|
747
|
+
|
|
748
|
+
var rects: [4]canvas.TextSelectionRect = undefined;
|
|
749
|
+
const selection = text_spans.textSpanSelectionRects(
|
|
750
|
+
paragraph,
|
|
751
|
+
&spans,
|
|
752
|
+
options,
|
|
753
|
+
.{ .start = 0, .end = paragraph.len },
|
|
754
|
+
&rects,
|
|
755
|
+
);
|
|
756
|
+
|
|
757
|
+
try testing.expectEqual(@as(usize, 2), selection.len);
|
|
758
|
+
try testing.expectEqual(@as(usize, 0), selection[0].range.start);
|
|
759
|
+
try testing.expectEqual(@as(usize, 1), selection[0].range.end);
|
|
760
|
+
try testing.expectEqual(paragraph.len - 1, selection[1].range.start);
|
|
761
|
+
try testing.expectEqual(paragraph.len, selection[1].range.end);
|
|
762
|
+
}
|
|
763
|
+
|
|
510
764
|
test "span selection degrades to unsupported when spans alias other storage" {
|
|
511
765
|
const paragraph = "Hello world";
|
|
512
766
|
// Spans that do NOT slice into `paragraph` (a stack copy: the bytes
|