@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
package/build.zig CHANGED
@@ -1140,6 +1140,10 @@ pub fn build(b: *std.Build) void {
1140
1140
  // An assistive client's AXFocused WRITE must move the app's
1141
1141
  // real focus, not just flip a flag on the snapshot element.
1142
1142
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "setAccessibilityFocused" },
1143
+ // Native Edit-menu validation follows the retained editor's actual
1144
+ // history directions instead of merely checking text focus.
1145
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "focusedText.canUndo" },
1146
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "focusedText.canRedo" },
1143
1147
  });
1144
1148
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-accessibility-text-ranges", "Verify AppKit GPU widget accessibility publishes text selection ranges", &.{
1145
1149
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilitySelectedTextRange" },
@@ -1198,6 +1202,10 @@ pub fn build(b: *std.Build) void {
1198
1202
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)selectAll:(id)sender" },
1199
1203
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@selector(selectAll:)" },
1200
1204
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"a\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1205
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)undo:(id)sender" },
1206
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)redo:(id)sender" },
1207
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"z\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1208
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"z\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand | NativeSdkShortcutModifierShift)" },
1201
1209
  // Modified horizontal navigation must bypass AppKit's selector
1202
1210
  // rewrite: the shared editor consumes the raw modifiers, and a
1203
1211
  // terminal translates them to its shell/protocol bindings.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,14 +32,14 @@
32
32
  "@typescript/typescript6": "6.0.2"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@native-sdk/cli-darwin-arm64": "0.6.2",
36
- "@native-sdk/cli-darwin-x64": "0.6.2",
37
- "@native-sdk/cli-linux-arm64-gnu": "0.6.2",
38
- "@native-sdk/cli-linux-arm64-musl": "0.6.2",
39
- "@native-sdk/cli-linux-x64-gnu": "0.6.2",
40
- "@native-sdk/cli-linux-x64-musl": "0.6.2",
41
- "@native-sdk/cli-win32-arm64": "0.6.2",
42
- "@native-sdk/cli-win32-x64": "0.6.2"
35
+ "@native-sdk/cli-darwin-arm64": "0.7.0",
36
+ "@native-sdk/cli-darwin-x64": "0.7.0",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.7.0",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.7.0",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.7.0",
40
+ "@native-sdk/cli-linux-x64-musl": "0.7.0",
41
+ "@native-sdk/cli-win32-arm64": "0.7.0",
42
+ "@native-sdk/cli-win32-x64": "0.7.0"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.6.2",
9
+ "version": "0.7.0",
10
10
  "devDependencies": {
11
11
  "@typescript/old": "npm:typescript@6.0.3",
12
12
  "@typescript/typescript6": "6.0.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,8 @@
14
14
  // call returns a new state and never touches its inputs.
15
15
  //
16
16
  // Offsets are BYTE offsets, always snapped to UTF-8 sequence boundaries
17
- // before use, so a caret can never land inside a multi-byte character.
17
+ // before use, so a caret can never land inside a multi-byte character or
18
+ // between the two bytes of a CRLF hard-line boundary.
18
19
  // Capacity is the caller's fixed byte budget (mirror your runtime
19
20
  // TextBuffer's): an edit whose result would not fit returns null — the
20
21
  // refuse-whole contract — and `clampedInsertEvent` recovers the one case
@@ -128,6 +129,42 @@ function nextTextOffset(text: Uint8Array, offset: number): number {
128
129
  return next;
129
130
  }
130
131
 
132
+ // Caret editing treats CRLF as one hard-line boundary. Raw text ranges
133
+ // continue to use snapTextOffset so they may address either delimiter byte.
134
+ function snapTextCaretOffset(text: Uint8Array, offset: number): number {
135
+ const cursor = snapTextOffset(text, offset);
136
+ if (
137
+ cursor > 0 &&
138
+ cursor < text.length &&
139
+ text[cursor] === 0x0a &&
140
+ text[cursor - 1] === 0x0d
141
+ ) {
142
+ return cursor - 1;
143
+ }
144
+ return cursor;
145
+ }
146
+
147
+ function previousTextCaretOffset(text: Uint8Array, offset: number): number {
148
+ const previous = previousTextOffset(text, offset);
149
+ if (previous > 0 && text[previous] === 0x0a && text[previous - 1] === 0x0d) {
150
+ return previous - 1;
151
+ }
152
+ return previous;
153
+ }
154
+
155
+ function nextTextCaretOffset(text: Uint8Array, offset: number): number {
156
+ const cursor = snapTextOffset(text, offset);
157
+ if (
158
+ cursor < text.length &&
159
+ text[cursor] === 0x0d &&
160
+ cursor + 1 < text.length &&
161
+ text[cursor + 1] === 0x0a
162
+ ) {
163
+ return cursor + 2;
164
+ }
165
+ return nextTextOffset(text, cursor);
166
+ }
167
+
131
168
  function isAsciiAlphanumeric(b: number): boolean {
132
169
  return (b >= 0x30 && b <= 0x39) || (b >= 0x41 && b <= 0x5a) || (b >= 0x61 && b <= 0x7a);
133
170
  }
@@ -179,10 +216,10 @@ function nextTextWordOffset(text: Uint8Array, offset: number): number {
179
216
  return cursor;
180
217
  }
181
218
 
182
- function snapTextSelection(text: Uint8Array, selection: TextSelection): TextSelection {
219
+ function snapTextCaretSelection(text: Uint8Array, selection: TextSelection): TextSelection {
183
220
  return {
184
- anchor: snapTextOffset(text, selection.anchor),
185
- focus: snapTextOffset(text, selection.focus),
221
+ anchor: snapTextCaretOffset(text, selection.anchor),
222
+ focus: snapTextCaretOffset(text, selection.focus),
186
223
  };
187
224
  }
188
225
 
@@ -226,8 +263,9 @@ function replaceTextRange(
226
263
  function normalizeTextEditState(state: TextEditState): TextEditState {
227
264
  return {
228
265
  text: state.text,
229
- selection: snapTextSelection(state.text, state.selection),
230
- composition: state.composition !== null ? snapTextRange(state.text, state.composition) : null,
266
+ selection: snapTextCaretSelection(state.text, state.selection),
267
+ composition:
268
+ state.composition !== null ? snapTextRange(state.text, state.composition) : null,
231
269
  };
232
270
  }
233
271
 
@@ -246,7 +284,7 @@ function replaceTextEditRange(
246
284
  ): TextEditState | null {
247
285
  const result = replaceTextRange(state.text, range, replacement, capacity);
248
286
  if (result === null) return null;
249
- const cursor = snapTextOffset(
287
+ const cursor = snapTextCaretOffset(
250
288
  result.text,
251
289
  result.insertedStart + Math.min(cursorOffset, replacement.length),
252
290
  );
@@ -264,10 +302,10 @@ function setTextComposition(
264
302
  capacity: number,
265
303
  ): TextEditState | null {
266
304
  const range = activeTextReplaceRange(state);
267
- const cursor = snapTextOffset(text, cursorIn === null ? text.length : cursorIn);
305
+ const cursor = snapTextCaretOffset(text, cursorIn === null ? text.length : cursorIn);
268
306
  const result = replaceTextRange(state.text, range, text, capacity);
269
307
  if (result === null) return null;
270
- const absoluteCursor = snapTextOffset(result.text, result.insertedStart + cursor);
308
+ const absoluteCursor = snapTextCaretOffset(result.text, result.insertedStart + cursor);
271
309
  return {
272
310
  text: result.text,
273
311
  selection: { anchor: absoluteCursor, focus: absoluteCursor },
@@ -282,7 +320,10 @@ function cancelTextComposition(state: TextEditState, capacity: number): TextEdit
282
320
  if (result === null) return null;
283
321
  return {
284
322
  text: result.text,
285
- selection: { anchor: result.insertedStart, focus: result.insertedStart },
323
+ selection: snapTextCaretSelection(result.text, {
324
+ anchor: result.insertedStart,
325
+ focus: result.insertedStart,
326
+ }),
286
327
  composition: null,
287
328
  };
288
329
  }
@@ -292,13 +333,13 @@ function deleteBackwardTextEdit(state: TextEditState, capacity: number): TextEdi
292
333
  if (!rangeIsCollapsed(range, state.text.length)) {
293
334
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
294
335
  }
295
- const caret = snapTextOffset(state.text, state.selection.focus);
336
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
296
337
  if (caret === 0) {
297
338
  return { text: state.text, selection: { anchor: 0, focus: 0 }, composition: null };
298
339
  }
299
340
  return replaceTextEditRange(
300
341
  state,
301
- { start: previousTextOffset(state.text, caret), end: caret },
342
+ { start: previousTextCaretOffset(state.text, caret), end: caret },
302
343
  new Uint8Array(0),
303
344
  capacity,
304
345
  null,
@@ -311,14 +352,14 @@ function deleteForwardTextEdit(state: TextEditState, capacity: number): TextEdit
311
352
  if (!rangeIsCollapsed(range, state.text.length)) {
312
353
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
313
354
  }
314
- const caret = snapTextOffset(state.text, state.selection.focus);
355
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
315
356
  if (caret >= state.text.length) {
316
357
  const len = state.text.length;
317
358
  return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
318
359
  }
319
360
  return replaceTextEditRange(
320
361
  state,
321
- { start: caret, end: nextTextOffset(state.text, caret) },
362
+ { start: caret, end: nextTextCaretOffset(state.text, caret) },
322
363
  new Uint8Array(0),
323
364
  capacity,
324
365
  null,
@@ -331,7 +372,7 @@ function deleteWordBackwardTextEdit(state: TextEditState, capacity: number): Tex
331
372
  if (!rangeIsCollapsed(range, state.text.length)) {
332
373
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
333
374
  }
334
- const caret = snapTextOffset(state.text, state.selection.focus);
375
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
335
376
  if (caret === 0) {
336
377
  return { text: state.text, selection: { anchor: 0, focus: 0 }, composition: null };
337
378
  }
@@ -350,7 +391,7 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
350
391
  if (!rangeIsCollapsed(range, state.text.length)) {
351
392
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
352
393
  }
353
- const caret = snapTextOffset(state.text, state.selection.focus);
394
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
354
395
  if (caret >= state.text.length) {
355
396
  const len = state.text.length;
356
397
  return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
@@ -367,13 +408,13 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
367
408
 
368
409
  function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState {
369
410
  const range = selectionRange(state.selection, state.text.length);
370
- const focus = snapTextOffset(state.text, state.selection.focus);
411
+ const focus = snapTextCaretOffset(state.text, state.selection.focus);
371
412
  const collapsed = rangeIsCollapsed(range, state.text.length);
372
413
  let target: number;
373
414
  if (move.direction === "previous") {
374
- target = !move.extend && !collapsed ? range.start : previousTextOffset(state.text, focus);
415
+ target = !move.extend && !collapsed ? range.start : previousTextCaretOffset(state.text, focus);
375
416
  } else if (move.direction === "next") {
376
- target = !move.extend && !collapsed ? range.end : nextTextOffset(state.text, focus);
417
+ target = !move.extend && !collapsed ? range.end : nextTextCaretOffset(state.text, focus);
377
418
  } else if (move.direction === "previous_word") {
378
419
  target = !move.extend && !collapsed ? range.start : previousTextWordOffset(state.text, focus);
379
420
  } else if (move.direction === "next_word") {
@@ -388,7 +429,7 @@ function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState
388
429
  : { anchor: target, focus: target };
389
430
  return {
390
431
  text: state.text,
391
- selection: snapTextSelection(state.text, selection),
432
+ selection: snapTextCaretSelection(state.text, selection),
392
433
  composition: null,
393
434
  };
394
435
  }
@@ -427,7 +468,7 @@ export function applyTextInputEvent(
427
468
  case "set_selection":
428
469
  return {
429
470
  text: normalized.text,
430
- selection: snapTextSelection(normalized.text, event.selection),
471
+ selection: snapTextCaretSelection(normalized.text, event.selection),
431
472
  composition: null,
432
473
  };
433
474
  case "set_composition":
@@ -182,6 +182,7 @@ Automation drives the native path honestly: snapshots list every widget's declar
182
182
  | `icon` | vector icon leaf | `name` picks the icon: a bare literal is a curated built-in stroke icon (compile-checked; 49 names: search, plus, x, x-circle, check, check-circle, chevron-up/down/left/right, arrow-up/down/right, menu, panel-left, panel-right, settings, terminal, wrench, trash, edit, copy, external-link, play, pause, skip-back/forward, shuffle, repeat, music, volume, info, alert, download, save, folder, folder-open, file-text, sun, moon, eye, clock, git-pull-request, git-merge, git-branch, circle-dot, archive, refresh-cw, send); `app:<name>` reaches an icon the app registered at boot with `canvas.icons.registerAppIcons` (declare the table as `pub const app_icons` on the app root so `native check` verifies the name against the model contract), and one `{binding}` defers the choice to model data - an unknown resolved name draws the missing-icon fallback (a slashed circle) with a Debug warning naming the value, never a silent gap; tint with `foreground`, size with `width`/`height` |
183
183
  | `media-surface` | media surface leaf | composites a texture produced OUTSIDE the widget tree (video decoder, camera, an external renderer like mpv) into the layout like any widget — clipped, z-ordered, rounded. `surface="{binding}"` (required) binds the model-owned u64 surface id a Zig-tier producer targets (`runtime.acquireMediaSurfaceProducer` pushes RGBA8 frames, latest-wins, paced by the presented-frame clock; 0 = unbound, draws nothing; usable ids are nonzero values below the reserved bit 63). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content). Texture contents are presentation chrome: goldens, reference screenshots, and session replay show the deterministic id-derived placeholder, never producer frames |
184
184
  | `image` | runtime image leaf | draws a RUNTIME-REGISTERED image by its model-owned u64 ImageId — the id `Cmd.imageLoad` (TS) or `fx.loadImage`/`fx.registerImageBytes` (Zig) registered pixels under. `image="{binding}"` (required) binds a model field/fn; ids are model data, never markup literals, and 0 draws nothing (store the id only when the load reports loaded — see the Images section). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content) |
185
+ | `code` | highlighted source surface | `source="{binding}"` (required) provides source text and `language="tsx"` selects a literal lexer name; wraps by default, `line-numbers` opts into logical line numbers, and `wrap="false"` preserves lines inside one horizontal scroll region. HTML-family highlighting distinguishes HTML/XML/SVG and JSX/TSX tags, attributes, strings, comments, and embedded expressions. Zig builder: `ui.code(CodeOptions, source)` |
185
186
  | `markdown` | rendered markdown subtree | leaf; `source` is one `{binding}` — see "Markdown in markup" |
186
187
  | `stepper` > `step` | composite stage track | `active="{index}"` (required) derives each step's completed/active/pending state; steps are text leaves (no attributes) joined by connectors; stepper also takes `key`, `global-key`, `label` |
187
188
  | `timeline` > `timeline-item` | composite ledger list | items only inside a timeline (for/if fine); items are leaves — `title` (required), `description`, `meta`, `indicator`, `variant`, `connector="false"` on the last item, `selected`; `on-press` makes the whole item pressable with a trailing chevron |
@@ -353,7 +354,7 @@ The `examples/feed` app is the reference: a 100,000-post deterministic MIXED-HEI
353
354
 
354
355
  Color and radius come from the design tokens, referenced by token NAME — literals only, no bindings, no raw colors (dynamic styling stays in Zig via `ElementOptions.style`):
355
356
 
356
- - Color attributes: `background`, `foreground`, `accent`, `accent-foreground`, `border-color`, `focus-ring`. Values are `canvas.ColorTokens` field names — the complete list: `background`, `surface`, `surface_subtle`, `surface_pressed`, `text`, `text_muted`, `border`, `accent`, `accent_text`, `destructive`, `destructive_text`, `success`, `success_text`, `warning`, `warning_text`, `info`, `info_text`, `focus_ring`, `shadow`, `disabled`. `info` is the violet identity hue beside the status trio (merged PR badges, "new" chips). (`border-color`, not bare `border` — that name is reserved for a future width shorthand.)
357
+ - Color attributes: `background`, `foreground`, `accent`, `accent-foreground`, `border-color`, `focus-ring`. Values are `canvas.ColorTokens` field names — the complete list: `background`, `surface`, `surface_subtle`, `surface_pressed`, `text`, `text_muted`, `syntax_plain`, `syntax_comment`, `syntax_keyword`, `syntax_literal`, `syntax_function`, `syntax_property`, `syntax_constant`, `border`, `accent`, `accent_text`, `destructive`, `destructive_text`, `success`, `success_text`, `warning`, `warning_text`, `info`, `info_text`, `focus_ring`, `shadow`, `scrim`, `disabled`. The `syntax_*` roles are the Geist Code Block palette used automatically by `ui.code` and Markdown fences in both built-in packs. `info` is the violet identity hue beside the status trio (merged PR badges, "new" chips). (`border-color`, not bare `border` — that name is reserved for a future width shorthand.)
357
358
  - `radius` — `canvas.RadiusTokens` field names: `sm`, `md`, `lg`, `xl`.
358
359
 
359
360
  ```html
@@ -967,6 +968,20 @@ Rules and semantics:
967
968
 
968
969
  Both engines implement templates, defaults, slots, and imports: the interpreter expands at build time (hot reload re-resolves imports from disk, so edits to imported files reload), and the compiled engine inlines at comptime with the identical result. A document with imports compiles through `canvas.CompiledMarkupImports(Model, Msg, "root.native", &sources)` where `sources` is a `canvas.ui_markup.SourceFile` set (`.{ .path = "components/cards.native", .source = @embedFile("components/cards.native") }`, paths relative to the root file's directory); pass the same set on `MarkupOptions.sources` for the runtime engine. See `examples/kanban/src/board.native` + `examples/kanban/src/components/board-column.native`.
969
970
 
971
+ ## Code in markup: `<code>`
972
+
973
+ A source-bound highlighted surface shared with Markdown fences:
974
+
975
+ ```html
976
+ <code source="{snippet}" language="tsx" line-numbers wrap="false" width="480" label="Component source" />
977
+ ```
978
+
979
+ - `source` is one required `{binding}` producing `[]const u8`; the element has no children.
980
+ - `language` is a literal lexer name: Zig, JS/TS, JSX/TSX, JSON, shell, Python, Rust, C-family, Go, HTML/XML/SVG, CSS-family, or SQL. Omit it for plain monospace.
981
+ - Wrapping is on by default. `wrap="false"` keeps logical lines intact inside one horizontal scroll region. A definite `height` makes overflow scroll vertically; with wrapping off, that constrained region scrolls on both axes.
982
+ - `line-numbers` is off by default. Wrapped logical lines stay paired with their number. Numbered mode is limited to 128 logical lines and a reserved share of the per-view node and text-span budgets; sources that exceed any bound preserve all code and omit the gutter.
983
+ - Zig builder: `ui.code(.{ .language = .html, .line_numbers = true, .wrap = false }, model.snippet)`. The public lexer helpers are under `native_sdk.canvas.code`.
984
+
970
985
  ## Markdown in markup: `<markdown>`
971
986
 
972
987
  A leaf element that renders a markdown string (the GFM subset below) as ordinary widgets, wiring `native_sdk.markdown` for you — both engines implement it identically:
@@ -1080,7 +1095,7 @@ Md.view(ui, model.body_markdown, .{
1080
1095
  })
1081
1096
  ```
1082
1097
 
1083
- - Supported: `#`–`###` headings, paragraphs with `**bold**`/`*italic*`/`` `code` ``/`~~strike~~`/`[links](url)`, bare `http(s)://` URLs (autolink, trailing punctuation trimmed), `#123` issue refs (opt-in: set `Options.issue_link_base` and the ref links to base ++ number), bullet + ordered + task lists (task checkboxes are display-only, disabled), fenced code blocks, `> blockquotes`, `---` rules, GFM pipe tables (header bold, `:---`/`:--:`/`---:` column alignment, inline spans + clickable links inside cells, `\|` escapes a pipe in a cell; columns share width equally, and a missing/mismatched delimiter row degrades the block to paragraphs), `<details><summary>`.
1098
+ - Supported: `#`–`###` headings, paragraphs with `**bold**`/`*italic*`/`` `code` ``/`~~strike~~`/`[links](url)`, bare `http(s)://` URLs (autolink, trailing punctuation trimmed), `#123` issue refs (opt-in: set `Options.issue_link_base` and the ref links to base ++ number), bullet + ordered + task lists (task checkboxes are display-only, disabled), fenced code blocks (source indentation preserved; they lower through `ui.code` with wrapping on and line numbers off; recognized Zig, JS/TS, JSX/TSX, JSON, shell, Python, Rust, C-family, Go, HTML/XML/SVG, CSS-family, and SQL info strings get theme-token syntax highlighting; unknown tags stay plain mono), `> blockquotes`, `---` rules, GFM pipe tables (header bold, `:---`/`:--:`/`---:` column alignment, inline spans + clickable links inside cells, `\|` escapes a pipe in a cell; columns share width equally, and a missing/mismatched delimiter row degrades the block to paragraphs), `<details><summary>`.
1084
1099
  - Not in v1 (degrades to plain text, never fails): reference links, raw HTML, footnotes, backslash escapes (except `\|` in table rows).
1085
1100
  - `<details>` state is elm-style: the CALLER owns the expanded flags. Keep a bounded `details_expanded: [8]bool` in the model, toggle it in `update` on the details message, and pass the slice back in.
1086
1101
 
@@ -171,6 +171,8 @@ enum {
171
171
  NATIVE_SDK_APPKIT_WIDGET_STATE_REQUIRED = 1u << 6,
172
172
  NATIVE_SDK_APPKIT_WIDGET_STATE_READ_ONLY = 1u << 7,
173
173
  NATIVE_SDK_APPKIT_WIDGET_STATE_INVALID = 1u << 8,
174
+ NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_UNDO = 1u << 9,
175
+ NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_REDO = 1u << 10,
174
176
  };
175
177
 
176
178
  enum {
@@ -405,6 +405,8 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
405
405
  @property(nonatomic, assign) NativeSdkMetalSurfaceView *surfaceView;
406
406
  @property(nonatomic, assign) uint64_t widgetId;
407
407
  @property(nonatomic, assign) uint32_t actionFlags;
408
+ @property(nonatomic, assign) BOOL canUndo;
409
+ @property(nonatomic, assign) BOOL canRedo;
408
410
  - (BOOL)emitSetTextAccessibilityValue:(id)value;
409
411
  - (BOOL)emitSetSelectionAccessibilityValue:(id)value;
410
412
  @end
@@ -5538,6 +5540,8 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5538
5540
  element.accessibilityEnabled = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_ENABLED) != 0;
5539
5541
  element.accessibilityFocused = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_FOCUSED) != 0;
5540
5542
  element.accessibilitySelected = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_SELECTED) != 0;
5543
+ element.canUndo = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_UNDO) != 0;
5544
+ element.canRedo = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_REDO) != 0;
5541
5545
  if ((node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_EXPANDED) != 0) {
5542
5546
  element.accessibilityExpanded = YES;
5543
5547
  } else if ((node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_COLLAPSED) != 0) {
@@ -7014,6 +7018,20 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7014
7018
  [self emitSelectAllTextInputCommand];
7015
7019
  }
7016
7020
 
7021
+ // The runtime owns canvas-editor history, so Edit-menu actions take the
7022
+ // same Command+Z / Command+Shift+Z route as physical keyboard events.
7023
+ - (void)undo:(id)sender {
7024
+ (void)sender;
7025
+ if (![self focusedTextAccessibilityElement]) return;
7026
+ [self emitSyntheticKeyDownWithKey:@"z" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)];
7027
+ }
7028
+
7029
+ - (void)redo:(id)sender {
7030
+ (void)sender;
7031
+ if (![self focusedTextAccessibilityElement]) return;
7032
+ [self emitSyntheticKeyDownWithKey:@"z" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand | NativeSdkShortcutModifierShift)];
7033
+ }
7034
+
7017
7035
  // Edit-menu clipboard actions on the canvas: the runtime already
7018
7036
  // resolves cmd+C/X/V key events against the focused editable widget or
7019
7037
  // the view's text selection, so the menu items ride the same path as
@@ -7039,8 +7057,18 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7039
7057
  }
7040
7058
 
7041
7059
  - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
7042
- if (menuItem.action == @selector(cut:) || menuItem.action == @selector(paste:) || menuItem.action == @selector(selectAll:)) {
7043
- return [self focusedTextAccessibilityElement] != nil;
7060
+ NativeSdkWidgetAccessibilityElement *focusedText =
7061
+ (NativeSdkWidgetAccessibilityElement *)[self focusedTextAccessibilityElement];
7062
+ if (menuItem.action == @selector(undo:)) {
7063
+ return focusedText != nil && focusedText.canUndo;
7064
+ }
7065
+ if (menuItem.action == @selector(redo:)) {
7066
+ return focusedText != nil && focusedText.canRedo;
7067
+ }
7068
+ if (menuItem.action == @selector(cut:) ||
7069
+ menuItem.action == @selector(paste:) ||
7070
+ menuItem.action == @selector(selectAll:)) {
7071
+ return focusedText != nil;
7044
7072
  }
7045
7073
  return YES;
7046
7074
  }
@@ -8989,14 +9017,12 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
8989
9017
  [mainMenu addItem:editMenuItem];
8990
9018
  NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"Edit"];
8991
9019
  [editMenuItem setSubmenu:editMenu];
8992
- if (self.hasWebContent) {
8993
- // Undo/Redo answer only inside web content (the webview's own
8994
- // editing stack); the canvas text editor has no undo stack, so
8995
- // canvas-only apps do not show items nothing can perform.
8996
- [editMenu addItem:[self menuItem:@"Undo" action:@selector(undo:) key:@"z" modifiers:NSEventModifierFlagCommand]];
8997
- [editMenu addItem:[self menuItem:@"Redo" action:@selector(redo:) key:@"Z" modifiers:NSEventModifierFlagCommand]];
8998
- [editMenu addItem:[NSMenuItem separatorItem]];
8999
- }
9020
+ // Web content answers through its native responder. A focused canvas
9021
+ // editor answers through NativeSdkGpuSurfaceView's synthetic-key
9022
+ // bridge into the runtime's per-editor history.
9023
+ [editMenu addItem:[self menuItem:@"Undo" action:@selector(undo:) key:@"z" modifiers:NSEventModifierFlagCommand]];
9024
+ [editMenu addItem:[self menuItem:@"Redo" action:@selector(redo:) key:@"Z" modifiers:NSEventModifierFlagCommand]];
9025
+ [editMenu addItem:[NSMenuItem separatorItem]];
9000
9026
  [editMenu addItem:[self menuItem:@"Cut" action:@selector(cut:) key:@"x" modifiers:NSEventModifierFlagCommand]];
9001
9027
  [editMenu addItem:[self menuItem:@"Copy" action:@selector(copy:) key:@"c" modifiers:NSEventModifierFlagCommand]];
9002
9028
  [editMenu addItem:[self menuItem:@"Paste" action:@selector(paste:) key:@"v" modifiers:NSEventModifierFlagCommand]];
@@ -375,6 +375,8 @@ const widget_state_collapsed: u32 = 1 << 5;
375
375
  const widget_state_required: u32 = 1 << 6;
376
376
  const widget_state_read_only: u32 = 1 << 7;
377
377
  const widget_state_invalid: u32 = 1 << 8;
378
+ const widget_state_can_undo: u32 = 1 << 9;
379
+ const widget_state_can_redo: u32 = 1 << 10;
378
380
  const widget_action_focus: u32 = 1 << 0;
379
381
  const widget_action_press: u32 = 1 << 1;
380
382
  const widget_action_toggle: u32 = 1 << 2;
@@ -1917,6 +1919,8 @@ fn widgetStateFlags(node: platform_mod.WidgetAccessibilityNode) u32 {
1917
1919
  if (node.required) flags |= widget_state_required;
1918
1920
  if (node.read_only) flags |= widget_state_read_only;
1919
1921
  if (node.invalid) flags |= widget_state_invalid;
1922
+ if (node.can_undo) flags |= widget_state_can_undo;
1923
+ if (node.can_redo) flags |= widget_state_can_redo;
1920
1924
  return flags;
1921
1925
  }
1922
1926
 
@@ -2651,13 +2655,15 @@ test "mac widget accessibility maps retained action flags" {
2651
2655
  }
2652
2656
 
2653
2657
  test "mac widget accessibility maps widget state flags" {
2654
- const expanded = widgetStateFlags(.{ .enabled = true, .expanded = true, .required = true, .read_only = true, .invalid = true });
2658
+ const expanded = widgetStateFlags(.{ .enabled = true, .expanded = true, .required = true, .read_only = true, .invalid = true, .can_undo = true, .can_redo = true });
2655
2659
  try std.testing.expect(expanded & widget_state_enabled != 0);
2656
2660
  try std.testing.expect(expanded & widget_state_expanded != 0);
2657
2661
  try std.testing.expect(expanded & widget_state_collapsed == 0);
2658
2662
  try std.testing.expect(expanded & widget_state_required != 0);
2659
2663
  try std.testing.expect(expanded & widget_state_read_only != 0);
2660
2664
  try std.testing.expect(expanded & widget_state_invalid != 0);
2665
+ try std.testing.expect(expanded & widget_state_can_undo != 0);
2666
+ try std.testing.expect(expanded & widget_state_can_redo != 0);
2661
2667
 
2662
2668
  const collapsed = widgetStateFlags(.{ .enabled = true, .expanded = false });
2663
2669
  try std.testing.expect(collapsed & widget_state_enabled != 0);
@@ -2154,6 +2154,8 @@ pub const WidgetAccessibilityNode = struct {
2154
2154
  required: bool = false,
2155
2155
  read_only: bool = false,
2156
2156
  invalid: bool = false,
2157
+ can_undo: bool = false,
2158
+ can_redo: bool = false,
2157
2159
  focusable: bool = false,
2158
2160
  actions: WidgetAccessibilityActions = .{},
2159
2161
  };