@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.
Files changed (64) hide show
  1. package/build.zig +8 -0
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/text.ts +62 -21
  6. package/skill-data/native-ui/SKILL.md +17 -2
  7. package/src/platform/macos/appkit_host.h +2 -0
  8. package/src/platform/macos/appkit_host.m +36 -10
  9. package/src/platform/macos/root.zig +7 -1
  10. package/src/platform/types.zig +2 -0
  11. package/src/primitives/canvas/code.zig +590 -0
  12. package/src/primitives/canvas/code_tests.zig +1062 -0
  13. package/src/primitives/canvas/equality.zig +3 -1
  14. package/src/primitives/canvas/events.zig +4 -0
  15. package/src/primitives/canvas/layout_audit.zig +3 -1
  16. package/src/primitives/canvas/markdown.zig +13 -11
  17. package/src/primitives/canvas/markdown_tests.zig +167 -4
  18. package/src/primitives/canvas/root.zig +15 -2
  19. package/src/primitives/canvas/tests.zig +1 -0
  20. package/src/primitives/canvas/text.zig +10 -0
  21. package/src/primitives/canvas/text_interaction.zig +164 -22
  22. package/src/primitives/canvas/text_layout.zig +107 -21
  23. package/src/primitives/canvas/text_measure_cache.zig +4 -4
  24. package/src/primitives/canvas/text_span_tests.zig +254 -0
  25. package/src/primitives/canvas/text_spans.zig +556 -32
  26. package/src/primitives/canvas/text_tests.zig +86 -0
  27. package/src/primitives/canvas/themes/geist.zig +29 -0
  28. package/src/primitives/canvas/tokens.zig +72 -2
  29. package/src/primitives/canvas/ui.zig +325 -21
  30. package/src/primitives/canvas/ui_markup.zig +59 -2
  31. package/src/primitives/canvas/ui_markup_compiled.zig +76 -0
  32. package/src/primitives/canvas/ui_markup_compiled_tests.zig +33 -0
  33. package/src/primitives/canvas/ui_markup_contract.zig +34 -0
  34. package/src/primitives/canvas/ui_markup_reflect.zig +20 -3
  35. package/src/primitives/canvas/ui_markup_view.zig +73 -0
  36. package/src/primitives/canvas/ui_markup_view_tests.zig +101 -0
  37. package/src/primitives/canvas/ui_schema.zig +17 -6
  38. package/src/primitives/canvas/ui_schema_tests.zig +7 -6
  39. package/src/primitives/canvas/ui_tests.zig +6 -0
  40. package/src/primitives/canvas/widget_invalidation.zig +3 -0
  41. package/src/primitives/canvas/widget_layout.zig +57 -8
  42. package/src/primitives/canvas/widget_layout_tests.zig +35 -0
  43. package/src/primitives/canvas/widget_metrics.zig +30 -1
  44. package/src/primitives/canvas/widget_render.zig +454 -9
  45. package/src/primitives/canvas/widget_runtime.zig +1 -0
  46. package/src/primitives/canvas/widget_text_input.zig +23 -11
  47. package/src/primitives/canvas/widget_text_select.zig +2 -2
  48. package/src/primitives/canvas/widgets.zig +13 -0
  49. package/src/root.zig +1 -0
  50. package/src/runtime/api.zig +9 -0
  51. package/src/runtime/canvas_frame_helpers.zig +1 -0
  52. package/src/runtime/canvas_limits.zig +7 -0
  53. package/src/runtime/canvas_widget_accessibility_tests.zig +27 -1
  54. package/src/runtime/canvas_widget_clipboard_tests.zig +146 -0
  55. package/src/runtime/canvas_widget_context_menu.zig +12 -2
  56. package/src/runtime/canvas_widget_display.zig +15 -1
  57. package/src/runtime/canvas_widget_events.zig +50 -20
  58. package/src/runtime/canvas_widget_runtime.zig +74 -12
  59. package/src/runtime/canvas_widget_state.zig +1 -0
  60. package/src/runtime/canvas_widget_text_tests.zig +1935 -70
  61. package/src/runtime/gpu_surface_events.zig +38 -0
  62. package/src/runtime/view.zig +37 -3
  63. package/src/runtime/view_widget_text.zig +1242 -14
  64. package/src/runtime/view_widget_tree.zig +2 -0
@@ -748,6 +748,29 @@ test "text edit state tracks ime composition ranges" {
748
748
  try std.testing.expect(state.composition == null);
749
749
  }
750
750
 
751
+ test "ime composition owns exact bytes when its preview completes CRLF" {
752
+ var preview_storage: [64]u8 = undefined;
753
+ var update_storage: [64]u8 = undefined;
754
+ var cancel_storage: [64]u8 = undefined;
755
+
756
+ const initial = TextEditState{
757
+ .text = "a\nb",
758
+ .selection = TextSelection.collapsed(1),
759
+ };
760
+ const preview = try initial.apply(.{ .set_composition = .{ .text = "\r", .cursor = 1 } }, &preview_storage);
761
+ try std.testing.expectEqualStrings("a\r\nb", preview.text);
762
+ try std.testing.expectEqualDeep(TextRange.init(1, 2), preview.composition.?);
763
+
764
+ const updated = try preview.apply(.{ .set_composition = .{ .text = "X", .cursor = 1 } }, &update_storage);
765
+ try std.testing.expectEqualStrings("aX\nb", updated.text);
766
+ try std.testing.expectEqualDeep(TextRange.init(1, 2), updated.composition.?);
767
+
768
+ const cancelled = try preview.apply(.cancel_composition, &cancel_storage);
769
+ try std.testing.expectEqualStrings("a\nb", cancelled.text);
770
+ try std.testing.expectEqualDeep(TextSelection.collapsed(1), cancelled.selection);
771
+ try std.testing.expect(cancelled.composition == null);
772
+ }
773
+
751
774
  test "text bounds follow utf8 scalar fallback and shaped y offsets" {
752
775
  // Metric boxes inflate by the ink allowance (left/bottom 0.1em,
753
776
  // right 0.35em) so real glyph outlines never clip at the bounds.
@@ -1124,6 +1147,44 @@ test "text layout maps caret selection and points across wrapped fallback lines"
1124
1147
  try expectRectApprox(geometry.RectF.init(4, 10, 24.25, 28), folded[0].rect);
1125
1148
  }
1126
1149
 
1150
+ test "unbroken soft wraps preserve downstream caret affinity" {
1151
+ const text = DrawText{
1152
+ .font_id = 1,
1153
+ .size = 10,
1154
+ .origin = geometry.PointF.init(4, 20),
1155
+ .color = Color.rgb8(0, 0, 0),
1156
+ .text = "abcdefghijklmnopqrstuvwxyz",
1157
+ };
1158
+ const options = TextLayoutOptions{ .max_width = 30, .line_height = 14, .wrap = .word };
1159
+ var lines: [8]TextLine = undefined;
1160
+ const layout = try layoutTextRun(text, options, &lines);
1161
+ try std.testing.expect(layout.lines.len > 1);
1162
+
1163
+ const first_range = text_model.textLineRange(text, layout.lines[0]);
1164
+ const second_range = text_model.textLineRange(text, layout.lines[1]);
1165
+ try std.testing.expectEqual(first_range.end, second_range.start);
1166
+
1167
+ const point = geometry.PointF.init(
1168
+ layout.lines[1].bounds.x - 1,
1169
+ layout.lines[1].bounds.y + layout.lines[1].bounds.height * 0.5,
1170
+ );
1171
+ const streamed = canvas.layoutTextCaretPositionForPoint(text, options, point).?;
1172
+ const buffered = canvas.textCaretPositionForLayoutPoint(text, layout, point).?;
1173
+ try std.testing.expectEqualDeep(
1174
+ canvas.TextCaretPosition{ .offset = second_range.start, .affinity = .downstream },
1175
+ streamed,
1176
+ );
1177
+ try std.testing.expectEqualDeep(streamed, buffered);
1178
+
1179
+ const upstream = canvas.layoutTextCaretRectWithAffinity(text, options, streamed.offset, .upstream).?;
1180
+ const downstream = canvas.layoutTextCaretRectWithAffinity(text, options, streamed.offset, streamed.affinity).?;
1181
+ try std.testing.expectApproxEqAbs(layout.lines[0].bounds.y, upstream.y, 0.001);
1182
+ try std.testing.expectApproxEqAbs(layout.lines[1].bounds.y, downstream.y, 0.001);
1183
+
1184
+ const buffered_downstream = canvas.textCaretRectForLayoutWithAffinity(text, layout, streamed.offset, streamed.affinity).?;
1185
+ try std.testing.expectApproxEqAbs(downstream.y, buffered_downstream.y, 0.001);
1186
+ }
1187
+
1127
1188
  test "text layout maps caret selection and points across shaped glyph lines" {
1128
1189
  const glyphs = [_]Glyph{
1129
1190
  .{ .id = 1, .x = 2, .y = -3, .advance = 5 },
@@ -1510,6 +1571,31 @@ test "text layout handles newlines and shaped glyph runs" {
1510
1571
  try expectRect(geometry.RectF.init(3, 4, 19, 20), shaped.lines[0].bounds);
1511
1572
  }
1512
1573
 
1574
+ test "word-wrapped hard lines preserve leading spaces and caret advances" {
1575
+ const text = DrawText{
1576
+ .font_id = 1,
1577
+ .size = 12,
1578
+ .origin = geometry.PointF.init(0, 12),
1579
+ .color = Color.rgb8(0, 0, 0),
1580
+ .text = "One\n ",
1581
+ };
1582
+ const options = TextLayoutOptions{ .max_width = 100, .line_height = 16, .wrap = .word };
1583
+ var lines: [2]TextLine = undefined;
1584
+ const layout = try layoutTextRun(text, options, &lines);
1585
+
1586
+ try std.testing.expectEqual(@as(usize, 2), layout.lineCount());
1587
+ try std.testing.expectEqual(@as(usize, 4), layout.lines[1].text_start);
1588
+ try std.testing.expectEqual(@as(usize, 2), layout.lines[1].text_len);
1589
+
1590
+ const line_start = layoutTextCaretRect(text, options, 4).?;
1591
+ const first_space = layoutTextCaretRect(text, options, 5).?;
1592
+ const second_space = layoutTextCaretRect(text, options, 6).?;
1593
+ try std.testing.expectEqual(line_start.y, first_space.y);
1594
+ try std.testing.expectEqual(first_space.y, second_space.y);
1595
+ try std.testing.expect(first_space.x > line_start.x);
1596
+ try std.testing.expect(second_space.x > first_space.x);
1597
+ }
1598
+
1513
1599
  test "text layout bounds shaped glyph positions and vertical offsets" {
1514
1600
  const glyphs = [_]Glyph{
1515
1601
  .{ .id = 1, .x = 2, .y = -3, .advance = 5 },
@@ -153,6 +153,14 @@ fn light() ColorTokens {
153
153
  .text = Color.rgb8(23, 23, 23),
154
154
  // Secondary ink: gray-900 #4d4d4d.
155
155
  .text_muted = Color.rgb8(77, 77, 77),
156
+ // Geist Code Block syntax inks (the published 900 steps).
157
+ .syntax_plain = Color.rgb8(23, 23, 23),
158
+ .syntax_comment = Color.rgb8(77, 77, 77),
159
+ .syntax_keyword = Color.rgb8(189, 40, 100),
160
+ .syntax_literal = Color.rgb8(41, 122, 58),
161
+ .syntax_function = Color.rgb8(120, 32, 188),
162
+ .syntax_property = Color.rgb8(203, 42, 47),
163
+ .syntax_constant = Color.rgb8(0, 104, 214),
156
164
  // Hairline: black at 8% — the translucent border register.
157
165
  .border = Color.rgba8(0, 0, 0, 20),
158
166
  // The monochrome primary FILL: pure black #000000 filled
@@ -205,6 +213,13 @@ fn dark() ColorTokens {
205
213
  .text = Color.rgb8(237, 237, 237),
206
214
  // Secondary ink: gray-900 #a0a0a0.
207
215
  .text_muted = Color.rgb8(160, 160, 160),
216
+ .syntax_plain = Color.rgb8(237, 237, 237),
217
+ .syntax_comment = Color.rgb8(161, 161, 161),
218
+ .syntax_keyword = Color.rgb8(247, 95, 143),
219
+ .syntax_literal = Color.rgb8(98, 192, 115),
220
+ .syntax_function = Color.rgb8(191, 122, 240),
221
+ .syntax_property = Color.rgb8(255, 97, 102),
222
+ .syntax_constant = Color.rgb8(82, 168, 255),
208
223
  // Hairline: white at 14% — hairlines brighten what they overlap.
209
224
  .border = Color.rgba8(255, 255, 255, 36),
210
225
  // Porcelain primary with black knockout text.
@@ -247,6 +262,13 @@ fn highContrastLight() ColorTokens {
247
262
  .text = Color.rgb8(0, 0, 0),
248
263
  // Secondary ink darkens to gray-1000.
249
264
  .text_muted = Color.rgb8(23, 23, 23),
265
+ .syntax_plain = Color.rgb8(23, 23, 23),
266
+ .syntax_comment = Color.rgb8(77, 77, 77),
267
+ .syntax_keyword = Color.rgb8(189, 40, 100),
268
+ .syntax_literal = Color.rgb8(41, 122, 58),
269
+ .syntax_function = Color.rgb8(120, 32, 188),
270
+ .syntax_property = Color.rgb8(203, 42, 47),
271
+ .syntax_constant = Color.rgb8(0, 104, 214),
250
272
  .border = Color.rgba8(0, 0, 0, 180),
251
273
  .accent = Color.rgb8(0, 0, 0),
252
274
  .accent_text = Color.rgb8(255, 255, 255),
@@ -281,6 +303,13 @@ fn highContrastDark() ColorTokens {
281
303
  .surface_pressed = Color.rgb8(41, 41, 41),
282
304
  .text = Color.rgb8(255, 255, 255),
283
305
  .text_muted = Color.rgb8(237, 237, 237),
306
+ .syntax_plain = Color.rgb8(237, 237, 237),
307
+ .syntax_comment = Color.rgb8(161, 161, 161),
308
+ .syntax_keyword = Color.rgb8(247, 95, 143),
309
+ .syntax_literal = Color.rgb8(98, 192, 115),
310
+ .syntax_function = Color.rgb8(191, 122, 240),
311
+ .syntax_property = Color.rgb8(255, 97, 102),
312
+ .syntax_constant = Color.rgb8(82, 168, 255),
284
313
  .border = Color.rgba8(255, 255, 255, 190),
285
314
  .accent = Color.rgb8(255, 255, 255),
286
315
  .accent_text = Color.rgb8(0, 0, 0),
@@ -132,6 +132,20 @@ pub const ColorTokens = struct {
132
132
  text: Color = Color.rgb8(10, 10, 10),
133
133
  /// Muted foreground; oklch(0.556 0 0) = #737373.
134
134
  text_muted: Color = Color.rgb8(115, 115, 115),
135
+ /// Source-code ink follows the Geist Code Block palette in every
136
+ /// built-in pack. Dedicated roles keep syntax highlighting independent
137
+ /// from the app's semantic success/warning/info colors. Transparent is
138
+ /// the compatibility sentinel for an older custom palette that omitted
139
+ /// these newer fields: syntax resolution inherits `text` (or
140
+ /// `text_muted` for comments), so a dark palette never silently picks up
141
+ /// the light register's near-black ink.
142
+ syntax_plain: Color = Color.rgba8(0, 0, 0, 0),
143
+ syntax_comment: Color = Color.rgba8(0, 0, 0, 0),
144
+ syntax_keyword: Color = Color.rgba8(0, 0, 0, 0),
145
+ syntax_literal: Color = Color.rgba8(0, 0, 0, 0),
146
+ syntax_function: Color = Color.rgba8(0, 0, 0, 0),
147
+ syntax_property: Color = Color.rgba8(0, 0, 0, 0),
148
+ syntax_constant: Color = Color.rgba8(0, 0, 0, 0),
135
149
  /// Border/input hairline; oklch(0.922 0 0) = #e5e5e5.
136
150
  border: Color = Color.rgb8(229, 229, 229),
137
151
  /// Primary; oklch(0.205 0 0) = #171717 — the monochrome near-black
@@ -183,7 +197,15 @@ pub const ColorTokens = struct {
183
197
  }
184
198
 
185
199
  pub fn light() ColorTokens {
186
- return .{};
200
+ return .{
201
+ .syntax_plain = Color.rgb8(23, 23, 23),
202
+ .syntax_comment = Color.rgb8(77, 77, 77),
203
+ .syntax_keyword = Color.rgb8(189, 40, 100),
204
+ .syntax_literal = Color.rgb8(41, 122, 58),
205
+ .syntax_function = Color.rgb8(120, 32, 188),
206
+ .syntax_property = Color.rgb8(203, 42, 47),
207
+ .syntax_constant = Color.rgb8(0, 104, 214),
208
+ };
187
209
  }
188
210
 
189
211
  pub fn dark() ColorTokens {
@@ -203,6 +225,13 @@ pub const ColorTokens = struct {
203
225
  .text = Color.rgb8(250, 250, 250),
204
226
  // Muted foreground; oklch(0.708 0 0) = #a1a1a1.
205
227
  .text_muted = Color.rgb8(161, 161, 161),
228
+ .syntax_plain = Color.rgb8(237, 237, 237),
229
+ .syntax_comment = Color.rgb8(161, 161, 161),
230
+ .syntax_keyword = Color.rgb8(247, 95, 143),
231
+ .syntax_literal = Color.rgb8(98, 192, 115),
232
+ .syntax_function = Color.rgb8(191, 122, 240),
233
+ .syntax_property = Color.rgb8(255, 97, 102),
234
+ .syntax_constant = Color.rgb8(82, 168, 255),
206
235
  // Dark borders are translucent white (10%), not a gray fill:
207
236
  // hairlines brighten what they overlap instead of muddying it.
208
237
  .border = Color.rgba8(255, 255, 255, 26),
@@ -241,6 +270,13 @@ pub const ColorTokens = struct {
241
270
  .surface_pressed = Color.rgb8(229, 229, 229),
242
271
  .text = Color.rgb8(0, 0, 0),
243
272
  .text_muted = Color.rgb8(64, 64, 64),
273
+ .syntax_plain = Color.rgb8(23, 23, 23),
274
+ .syntax_comment = Color.rgb8(77, 77, 77),
275
+ .syntax_keyword = Color.rgb8(189, 40, 100),
276
+ .syntax_literal = Color.rgb8(41, 122, 58),
277
+ .syntax_function = Color.rgb8(120, 32, 188),
278
+ .syntax_property = Color.rgb8(203, 42, 47),
279
+ .syntax_constant = Color.rgb8(0, 104, 214),
244
280
  .border = Color.rgba8(0, 0, 0, 180),
245
281
  // The monochrome primary at its contrast extreme: pure
246
282
  // black filled controls, 21:1 against the white accent
@@ -276,6 +312,13 @@ pub const ColorTokens = struct {
276
312
  .surface_pressed = Color.rgb8(38, 38, 38),
277
313
  .text = Color.rgb8(255, 255, 255),
278
314
  .text_muted = Color.rgb8(229, 229, 229),
315
+ .syntax_plain = Color.rgb8(237, 237, 237),
316
+ .syntax_comment = Color.rgb8(161, 161, 161),
317
+ .syntax_keyword = Color.rgb8(247, 95, 143),
318
+ .syntax_literal = Color.rgb8(98, 192, 115),
319
+ .syntax_function = Color.rgb8(191, 122, 240),
320
+ .syntax_property = Color.rgb8(255, 97, 102),
321
+ .syntax_constant = Color.rgb8(82, 168, 255),
279
322
  .border = Color.rgba8(255, 255, 255, 190),
280
323
  // The monochrome primary at its contrast extreme: pure
281
324
  // white filled controls, 21:1 against the black accent
@@ -303,6 +346,26 @@ pub const ColorTokens = struct {
303
346
  }
304
347
  };
305
348
 
349
+ /// Resolve one named color token, including the compatibility inheritance
350
+ /// for syntax roles omitted by older custom palettes.
351
+ pub fn colorTokenValue(colors: ColorTokens, ref: std.meta.FieldEnum(ColorTokens)) Color {
352
+ const value = switch (ref) {
353
+ inline else => |tag| @field(colors, @tagName(tag)),
354
+ };
355
+ if (value.a != 0) return value;
356
+ return switch (ref) {
357
+ .syntax_comment => colors.text_muted,
358
+ .syntax_plain,
359
+ .syntax_keyword,
360
+ .syntax_literal,
361
+ .syntax_function,
362
+ .syntax_property,
363
+ .syntax_constant,
364
+ => colors.text,
365
+ else => value,
366
+ };
367
+ }
368
+
306
369
  pub const FontFamily = enum {
307
370
  geist,
308
371
  geist_mono,
@@ -1205,6 +1268,13 @@ pub const ColorTokenOverrides = struct {
1205
1268
  surface_pressed: ?Color = null,
1206
1269
  text: ?Color = null,
1207
1270
  text_muted: ?Color = null,
1271
+ syntax_plain: ?Color = null,
1272
+ syntax_comment: ?Color = null,
1273
+ syntax_keyword: ?Color = null,
1274
+ syntax_literal: ?Color = null,
1275
+ syntax_function: ?Color = null,
1276
+ syntax_property: ?Color = null,
1277
+ syntax_constant: ?Color = null,
1208
1278
  border: ?Color = null,
1209
1279
  accent: ?Color = null,
1210
1280
  accent_text: ?Color = null,
@@ -1767,7 +1837,7 @@ pub const DesignTokenOverrides = struct {
1767
1837
  };
1768
1838
 
1769
1839
  pub const DesignTokens = struct {
1770
- colors: ColorTokens = .{},
1840
+ colors: ColorTokens = ColorTokens.light(),
1771
1841
  typography: TypographyTokens = .{},
1772
1842
  spacing: SpacingTokens = .{},
1773
1843
  radius: RadiusTokens = .{},