@native-sdk/cli 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.zig +41 -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/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +39 -3
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +3 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +69 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/macos/appkit_host.h +11 -0
- package/src/platform/macos/appkit_host.m +130 -0
- package/src/platform/macos/root.zig +34 -0
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +118 -4
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +26 -0
- package/src/primitives/canvas/tokens.zig +170 -7
- package/src/primitives/canvas/ui.zig +62 -7
- package/src/primitives/canvas/ui_markup.zig +51 -4
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
- package/src/primitives/canvas/ui_markup_tests.zig +73 -0
- package/src/primitives/canvas/ui_markup_view.zig +63 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
- package/src/primitives/canvas/ui_schema.zig +31 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +259 -0
- package/src/primitives/canvas/widget_layout.zig +13 -5
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +28 -0
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +13 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +159 -28
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +26 -0
- package/src/runtime/canvas_images.zig +33 -7
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +1295 -7
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +88 -6
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +112 -6
- package/src/runtime/flow.zig +51 -1
- package/src/runtime/gpu_surface_events.zig +51 -5
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +9 -0
- package/src/runtime/session_journal.zig +52 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +575 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +64 -1
- package/src/runtime/ui_app_tests.zig +794 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
|
@@ -393,16 +393,33 @@ pub fn canvasWidgetEditableTextKind(kind: canvas.WidgetKind) bool {
|
|
|
393
393
|
return kind == .input or kind == .text_field or kind == .search_field or kind == .combobox or kind == .textarea;
|
|
394
394
|
}
|
|
395
395
|
|
|
396
|
-
/// Clipboard paste text
|
|
397
|
-
/// storage can absorb (the bytes
|
|
398
|
-
/// Clamping lands on a UTF-8
|
|
399
|
-
///
|
|
396
|
+
/// Clipboard paste text sanitized for the target kind and then clamped
|
|
397
|
+
/// to what the view's shared widget text storage can absorb (the bytes
|
|
398
|
+
/// the edit replaces are freed first). Clamping lands on a UTF-8
|
|
399
|
+
/// boundary; `truncated` is the loud flag the runtime forwards to apps
|
|
400
|
+
/// on the keyboard event.
|
|
400
401
|
pub const CanvasWidgetPasteClamp = struct {
|
|
401
402
|
text: []const u8 = "",
|
|
402
403
|
truncated: bool = false,
|
|
403
404
|
};
|
|
404
405
|
|
|
405
406
|
pub fn clampCanvasWidgetPasteText(widget: canvas.Widget, view_text_len: usize, text: []const u8) CanvasWidgetPasteClamp {
|
|
407
|
+
// Sanitize BEFORE clamping — the shared step for BOTH paste entry
|
|
408
|
+
// points (the cmd+V shortcut and the context-menu Paste). A
|
|
409
|
+
// single-line target strips \r/\n at the edit-derivation seam
|
|
410
|
+
// anyway, so capacity must be measured against the bytes that
|
|
411
|
+
// actually land: clamping the raw clipboard first discarded valid
|
|
412
|
+
// suffix text near the limit ("a\nbc" into 3 free bytes clamped to
|
|
413
|
+
// "a\nb" and then sanitized to "ab", when the sanitized "abc" fits
|
|
414
|
+
// whole). The stamped edit is the post-clamp bytes, so the retained
|
|
415
|
+
// editor and the app's `on_input` mirror still hear identically —
|
|
416
|
+
// the seam's re-sanitize is a no-op on already-stripped text. A
|
|
417
|
+
// paste that sanitizes to nothing clamps to nothing; that is the
|
|
418
|
+
// sanitize rule speaking, NOT capacity, so `truncated` stays false.
|
|
419
|
+
const sanitized = if (canvas.sanitizedSingleLineTextInputEvent(widget.kind, .{ .insert_text = text })) |event|
|
|
420
|
+
event.insert_text
|
|
421
|
+
else
|
|
422
|
+
return .{};
|
|
406
423
|
const capacity = @import("canvas_limits.zig").max_canvas_widget_text_bytes_per_view;
|
|
407
424
|
const replaced_len = blk: {
|
|
408
425
|
if (widget.text_composition) |composition| break :blk composition.byteLen(widget.text.len);
|
|
@@ -411,9 +428,9 @@ pub fn clampCanvasWidgetPasteText(widget: canvas.Widget, view_text_len: usize, t
|
|
|
411
428
|
};
|
|
412
429
|
const used = view_text_len -| replaced_len;
|
|
413
430
|
const available = capacity -| used;
|
|
414
|
-
if (
|
|
415
|
-
const clamped = canvas.snapTextOffset(
|
|
416
|
-
return .{ .text =
|
|
431
|
+
if (sanitized.len <= available) return .{ .text = sanitized };
|
|
432
|
+
const clamped = canvas.snapTextOffset(sanitized, available);
|
|
433
|
+
return .{ .text = sanitized[0..clamped], .truncated = true };
|
|
417
434
|
}
|
|
418
435
|
|
|
419
436
|
pub fn canvasWidgetSingleLineTextKind(kind: canvas.WidgetKind) bool {
|
|
@@ -128,7 +128,7 @@ pub fn RuntimeCanvasWidgetScrollDrivers(comptime Runtime: type) type {
|
|
|
128
128
|
const dirty = try self.views[index].applyCanvasWidgetScrollDriverOffset(node_index, event.offset_y) orelse return;
|
|
129
129
|
|
|
130
130
|
const previous_cursor = self.views[index].canvas_widget_cursor;
|
|
131
|
-
self
|
|
131
|
+
try CanvasWidgetEventMethods().reconcileCanvasWidgetRenderStateAfterScrollWithTooltipIntent(self, index, null);
|
|
132
132
|
if (previous_cursor != self.views[index].canvas_widget_cursor) {
|
|
133
133
|
try CanvasWidgetEventMethods().syncCanvasWidgetCursorForView(self, index);
|
|
134
134
|
}
|
|
@@ -25,6 +25,7 @@ const CanvasWidgetTextReconcileEntry = canvas_widget_runtime.CanvasWidgetTextRec
|
|
|
25
25
|
const canvasWidgetLayoutTreeWithRuntimeReconcileState = canvas_widget_runtime.canvasWidgetLayoutTreeWithRuntimeReconcileState;
|
|
26
26
|
const canvasWidgetEditableTextKind = canvas_widget_runtime.canvasWidgetEditableTextKind;
|
|
27
27
|
const canvasWidgetAccessibilityActionSupported = widget_bridge.canvasWidgetAccessibilityActionSupported;
|
|
28
|
+
const platformWidgetAccessibilityActionKindFromCanvas = widget_bridge.platformWidgetAccessibilityActionKindFromCanvas;
|
|
28
29
|
const canvasWidgetBooleanSelected = canvas_widget_runtime.canvasWidgetBooleanSelected;
|
|
29
30
|
|
|
30
31
|
pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
|
|
@@ -95,6 +96,40 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
|
|
|
95
96
|
// and force-pushing the clamp into the live bounce (visible
|
|
96
97
|
// jitter). Non-driver platforms clamp exactly as before.
|
|
97
98
|
canvas_widget_runtime.clampCanvasWidgetLayoutScrollOffsets(reconciled_nodes[0..reconciled_layout.nodes.len], null);
|
|
99
|
+
// Runtime-owned tooltip visibility normalizes BEFORE the
|
|
100
|
+
// diff: the retained tree carries the intent machine's
|
|
101
|
+
// hidden stamps on anchored tooltips while the source
|
|
102
|
+
// declares authored visibility, so diffing them as-is
|
|
103
|
+
// reported a spurious visibility invalidation (a dirty
|
|
104
|
+
// repaint region for chrome that never changed) on EVERY
|
|
105
|
+
// rebuild containing a hidden anchored tooltip. The stamp
|
|
106
|
+
// uses the prune VERDICT against the reconciled tree — the
|
|
107
|
+
// shown id adoption will actually keep — WITHOUT mutating
|
|
108
|
+
// the live intent registers yet: everything between here
|
|
109
|
+
// and a retained tree is fallible (`diffWithTokens` can
|
|
110
|
+
// overflow its invalidation scratch, and
|
|
111
|
+
// `copyWidgetLayoutTree` rejects node/anchored-surface
|
|
112
|
+
// limits and every retained-pool budget before it resets
|
|
113
|
+
// the pools), and a register prune applied ahead of a
|
|
114
|
+
// failure left the OLD tree stamped visible with cleared
|
|
115
|
+
// registers — a tooltip no transition could ever hide
|
|
116
|
+
// again. The register mutation lands inside
|
|
117
|
+
// `copyWidgetLayoutTree`'s own prune, after the fallible
|
|
118
|
+
// steps succeed, where it applies this same verdict; an
|
|
119
|
+
// unchanged rebuild still diffs clean, a SHOWN tooltip
|
|
120
|
+
// stays visibly shown across the rebuild (no hide-then-show
|
|
121
|
+
// frame pair), and a rebuild that breaks the shown binding
|
|
122
|
+
// still diffs the hide honestly.
|
|
123
|
+
const prospective_shown_tooltip_id = self.views[index].canvasTooltipShownIdSurvivingLayout(reconciled_layout);
|
|
124
|
+
// Pre-adoption tooltip bindings for the standing hover and
|
|
125
|
+
// keyboard focus-visible owners, captured while the OLD
|
|
126
|
+
// tree is still retained (the copy below replaces it): the
|
|
127
|
+
// adoption reconcile at the bottom compares them against
|
|
128
|
+
// the adopted tree to catch a tooltip mounted/replaced/
|
|
129
|
+
// rekeyed beneath a stable owner — a change neither the
|
|
130
|
+
// hover re-hit-test nor the register prune can see.
|
|
131
|
+
const adoption_tooltip_bindings = CanvasWidgetEventMethods(Runtime).captureCanvasTooltipAdoptionBindings(self, index);
|
|
132
|
+
self.views[index].applyCanvasTooltipVisibilityToNodesForShownId(reconciled_nodes[0..reconciled_layout.nodes.len], prospective_shown_tooltip_id);
|
|
98
133
|
const invalidations = try canvas.WidgetLayoutTree.diffWithTokens(previous_layout, reconciled_layout, tokens, &self.canvas_widget_invalidations_scratch);
|
|
99
134
|
const previous_render_state = self.views[index].canvasWidgetRenderState();
|
|
100
135
|
const next_render_state = CanvasWidgetEventMethods(Runtime).canvasWidgetRenderStateAfterLayout(previous_render_state, reconciled_layout);
|
|
@@ -151,6 +186,16 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
|
|
|
151
186
|
// the user was looking at, and the tween walks it to the
|
|
152
187
|
// declared pose one presented frame at a time.
|
|
153
188
|
try applyCanvasWidgetDisclosureTweenPlan(self, index, disclosure_plan);
|
|
189
|
+
// Re-hit-test the stationary pointer against the ADOPTED
|
|
190
|
+
// tree, after every pose restore above settles the frames
|
|
191
|
+
// the user actually sees and BEFORE the display refresh
|
|
192
|
+
// publishes them: the prune at the top validates only
|
|
193
|
+
// tooltip/owner identity and hover survives by ID, so a
|
|
194
|
+
// rebuild that MOVES a same-ID trigger away from (or
|
|
195
|
+
// under) the stationary pointer must step hover ownership
|
|
196
|
+
// and the tooltip intent machine exactly like the
|
|
197
|
+
// point-blind scroll paths do.
|
|
198
|
+
try CanvasWidgetEventMethods(Runtime).reconcileCanvasWidgetInteractionAfterLayoutAdoption(self, index, adoption_tooltip_bindings);
|
|
154
199
|
const requested_frame = try CanvasWidgetDisplayMethods(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
155
200
|
if ((layout_dirty or widget_revision_changed) and !requested_frame) try CanvasFrameMethods(Runtime).requestCanvasFrameForView(self, index);
|
|
156
201
|
return self.views[index].info();
|
|
@@ -187,6 +232,38 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
|
|
|
187
232
|
const actions = AutomationWidgetMethods(Runtime).canvasWidgetActionsForId(self, index, action.id) orelse return error.InvalidCommand;
|
|
188
233
|
if (!canvasWidgetAccessibilityActionSupported(actions, action.action)) return error.InvalidCommand;
|
|
189
234
|
|
|
235
|
+
// Session recording, outer-wins on BOTH entry surfaces: the
|
|
236
|
+
// platform AX path arrives with its journaled tag-23 event
|
|
237
|
+
// already on the recorder's staging stack (flow.zig staged
|
|
238
|
+
// it), but the DIRECT verb surfaces (an embed host's
|
|
239
|
+
// `widgetAction`, automation `widget_action` commands) reach
|
|
240
|
+
// here with no platform event at all. Their verbs journal
|
|
241
|
+
// only UNTARGETED children routed by focus, while the focus
|
|
242
|
+
// write itself (`focusAutomationCanvasWidget`) is a direct
|
|
243
|
+
// unjournaled state change — so a fresh replay delivered the
|
|
244
|
+
// children against whatever focus the session happened to
|
|
245
|
+
// hold and a first-in-session composition landed nowhere.
|
|
246
|
+
// Stage the same synthetic `widget_accessibility_action`
|
|
247
|
+
// record the platform path carries: its suppression window
|
|
248
|
+
// keeps the children out of the journal and replay re-runs
|
|
249
|
+
// this whole dispatch — focus included — through the tag-23
|
|
250
|
+
// arm in flow.zig. When the platform event IS already staged,
|
|
251
|
+
// this nested stage lands inside its suppression window as a
|
|
252
|
+
// never-written placeholder, so no double record; the commit
|
|
253
|
+
// below pops it symmetrically. Effect results drained during
|
|
254
|
+
// the verb still write through ahead of the record, and
|
|
255
|
+
// event_count/checkpoint ordinals only ever see the one
|
|
256
|
+
// surviving record (checkpoints fire at staging depth 0).
|
|
257
|
+
if (self.options.session_recorder) |recorder| recorder.stageEvent(.{ .widget_accessibility_action = .{
|
|
258
|
+
.window_id = window_id,
|
|
259
|
+
.label = label,
|
|
260
|
+
.id = action.id,
|
|
261
|
+
.action = platformWidgetAccessibilityActionKindFromCanvas(action.action),
|
|
262
|
+
.text = action.text,
|
|
263
|
+
.selection = if (action.selection) |selection| .{ .start = selection.anchor, .end = selection.focus } else null,
|
|
264
|
+
} });
|
|
265
|
+
defer if (self.options.session_recorder) |recorder| recorder.commitEvent();
|
|
266
|
+
|
|
190
267
|
// Every assistive action rides the SAME machinery the
|
|
191
268
|
// automation widget verbs use — the key-driven activation for
|
|
192
269
|
// press/toggle/increment/decrement (quiet-list-row ring
|
|
@@ -209,10 +286,10 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
|
|
|
209
286
|
.increment => try AutomationWidgetMethods(Runtime).dispatchAutomationWidgetKey(self, app, index, action.id, self.views[index].canvasWidgetStepKey(action.id, .increment)),
|
|
210
287
|
.decrement => try AutomationWidgetMethods(Runtime).dispatchAutomationWidgetKey(self, app, index, action.id, self.views[index].canvasWidgetStepKey(action.id, .decrement)),
|
|
211
288
|
.set_text => try AutomationWidgetMethods(Runtime).setAutomationCanvasWidgetText(self, app, index, action.id, action.text),
|
|
212
|
-
.set_selection => try AutomationWidgetMethods(Runtime).editAutomationCanvasWidgetText(self, index, action.id, .{ .set_selection = action.selection orelse return error.InvalidCommand }),
|
|
213
|
-
.set_composition => try AutomationWidgetMethods(Runtime).
|
|
214
|
-
.commit_composition => try AutomationWidgetMethods(Runtime).
|
|
215
|
-
.cancel_composition => try AutomationWidgetMethods(Runtime).
|
|
289
|
+
.set_selection => try AutomationWidgetMethods(Runtime).editAutomationCanvasWidgetText(self, app, index, action.id, .{ .set_selection = action.selection orelse return error.InvalidCommand }),
|
|
290
|
+
.set_composition => try AutomationWidgetMethods(Runtime).composeAutomationCanvasWidgetText(self, app, index, action.id, .ime_set_composition, action.text),
|
|
291
|
+
.commit_composition => try AutomationWidgetMethods(Runtime).composeAutomationCanvasWidgetText(self, app, index, action.id, .ime_commit_composition, ""),
|
|
292
|
+
.cancel_composition => try AutomationWidgetMethods(Runtime).composeAutomationCanvasWidgetText(self, app, index, action.id, .ime_cancel_composition, ""),
|
|
216
293
|
.select => try AutomationWidgetMethods(Runtime).selectAutomationCanvasWidget(self, index, action.id),
|
|
217
294
|
.drag => try AutomationWidgetMethods(Runtime).dispatchAutomationCanvasWidgetDrag(self, app, index, action.id, action.text),
|
|
218
295
|
.drop_files => try AutomationWidgetMethods(Runtime).dispatchAutomationCanvasWidgetFileDrop(self, app, index, action.id, action.text),
|
|
@@ -233,7 +310,7 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
|
|
|
233
310
|
|
|
234
311
|
const dirty = try self.views[index].stepCanvasWidgetKineticScroll(dt_ms) orelse return self.views[index].info();
|
|
235
312
|
const previous_cursor = self.views[index].canvas_widget_cursor;
|
|
236
|
-
self
|
|
313
|
+
try CanvasWidgetEventMethods(Runtime).reconcileCanvasWidgetRenderStateAfterScrollWithTooltipIntent(self, index, null);
|
|
237
314
|
if (previous_cursor != self.views[index].canvas_widget_cursor) try CanvasWidgetEventMethods(Runtime).syncCanvasWidgetCursorForView(self, index);
|
|
238
315
|
try CanvasWidgetEventMethods(Runtime).invalidateForCanvasWidgetDirty(self, index, dirty);
|
|
239
316
|
_ = try CanvasWidgetDisplayMethods(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
@@ -742,7 +819,12 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
|
|
|
742
819
|
if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
|
|
743
820
|
if (!self.views[index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
|
|
744
821
|
|
|
745
|
-
|
|
822
|
+
// Direct runtime edits sanitize like every other insertion
|
|
823
|
+
// source (the keyboard choke point's rule): a single-line
|
|
824
|
+
// field's editor never accepts a line break, whoever writes.
|
|
825
|
+
const node = self.views[index].widgetLayoutTree().findById(id) orelse return error.InvalidCommand;
|
|
826
|
+
const sanitized = canvas.sanitizedSingleLineTextInputEvent(node.widget.kind, edit) orelse return self.views[index].info();
|
|
827
|
+
const dirty = try self.views[index].applyCanvasWidgetTextEdit(id, sanitized) orelse return self.views[index].info();
|
|
746
828
|
try CanvasWidgetEventMethods(Runtime).invalidateForCanvasWidgetDirty(self, index, dirty);
|
|
747
829
|
_ = try CanvasWidgetDisplayMethods(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
748
830
|
return self.views[index].info();
|
|
@@ -65,6 +65,18 @@ const builtinBridgeErrorMessage = support.builtinBridgeErrorMessage;
|
|
|
65
65
|
const testViewByLabel = support.testViewByLabel;
|
|
66
66
|
const testCanvasWidgetPartId = support.testCanvasWidgetPartId;
|
|
67
67
|
|
|
68
|
+
test "the builder's presented-text store mirrors the per-view draw-text budget" {
|
|
69
|
+
// The chart path-element lockstep's sibling: presented single-line
|
|
70
|
+
// bytes persist into `Builder.text_bytes`, and the store can only
|
|
71
|
+
// overflow (falling back to raw bytes under the forced clip) on a
|
|
72
|
+
// frame the runtime's per-view display-list copy would refuse
|
|
73
|
+
// anyway. Keep the two budgets from drifting.
|
|
74
|
+
try std.testing.expectEqual(
|
|
75
|
+
@import("canvas_limits.zig").max_canvas_text_bytes_per_view,
|
|
76
|
+
canvas.max_display_list_text_bytes,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
test "runtime exposes retained canvas widget text geometry" {
|
|
69
81
|
const TestApp = struct {
|
|
70
82
|
fn app(self: *@This()) App {
|
|
@@ -588,6 +600,271 @@ test "plain Enter inserts a newline in a canvas textarea; chorded Enter never ed
|
|
|
588
600
|
try std.testing.expectEqualStrings("First\n", retained.nodes[1].widget.text);
|
|
589
601
|
}
|
|
590
602
|
|
|
603
|
+
test "Enter in a single-line input never inserts, even when the host stuffs a newline into the key event" {
|
|
604
|
+
const TestApp = struct {
|
|
605
|
+
fn app(self: *@This()) App {
|
|
606
|
+
return .{ .context = self, .name = "gpu-widget-input-enter", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
611
|
+
defer harness.destroy(std.testing.allocator);
|
|
612
|
+
harness.null_platform.gpu_surfaces = true;
|
|
613
|
+
var app_state: TestApp = .{};
|
|
614
|
+
const app = app_state.app();
|
|
615
|
+
try harness.start(app);
|
|
616
|
+
|
|
617
|
+
_ = try harness.runtime.createView(.{
|
|
618
|
+
.window_id = 1,
|
|
619
|
+
.label = "canvas",
|
|
620
|
+
.kind = .gpu_surface,
|
|
621
|
+
.frame = geometry.RectF.init(0, 0, 260, 160),
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
const input = canvas.Widget{
|
|
625
|
+
.id = 2,
|
|
626
|
+
.kind = .input,
|
|
627
|
+
.frame = geometry.RectF.init(12, 16, 180, 32),
|
|
628
|
+
.text = "Draft",
|
|
629
|
+
.semantics = .{ .label = "Title" },
|
|
630
|
+
};
|
|
631
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
632
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{input} }, geometry.RectF.init(0, 0, 260, 160), &nodes);
|
|
633
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
634
|
+
|
|
635
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
636
|
+
.window_id = 1,
|
|
637
|
+
.label = "canvas",
|
|
638
|
+
.kind = .pointer_down,
|
|
639
|
+
.x = 100,
|
|
640
|
+
.y = 30,
|
|
641
|
+
} });
|
|
642
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
643
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
644
|
+
.window_id = 1,
|
|
645
|
+
.label = "canvas",
|
|
646
|
+
.kind = .key_down,
|
|
647
|
+
.key = "a",
|
|
648
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
649
|
+
} });
|
|
650
|
+
|
|
651
|
+
// The macOS-host shape: Return as a bare `enter` keydown. Enter in a
|
|
652
|
+
// single-line field submits; it is NOT an edit.
|
|
653
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
654
|
+
.window_id = 1,
|
|
655
|
+
.label = "canvas",
|
|
656
|
+
.kind = .key_down,
|
|
657
|
+
.key = "enter",
|
|
658
|
+
} });
|
|
659
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
660
|
+
try std.testing.expectEqualStrings("Draft", retained.nodes[1].widget.text);
|
|
661
|
+
try std.testing.expectEqualDeep(canvas.TextSelection{ .anchor = 0, .focus = 5 }, retained.nodes[1].widget.text_selection.?);
|
|
662
|
+
|
|
663
|
+
// A host that stuffs the newline into the key event's text payload
|
|
664
|
+
// still edits nothing: the sanitized insert strips to empty and
|
|
665
|
+
// suppresses — the live selection is not deleted.
|
|
666
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
667
|
+
.window_id = 1,
|
|
668
|
+
.label = "canvas",
|
|
669
|
+
.kind = .key_down,
|
|
670
|
+
.key = "enter",
|
|
671
|
+
.text = "\n",
|
|
672
|
+
} });
|
|
673
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
674
|
+
.window_id = 1,
|
|
675
|
+
.label = "canvas",
|
|
676
|
+
.kind = .key_down,
|
|
677
|
+
.key = "enter",
|
|
678
|
+
.text = "\r",
|
|
679
|
+
} });
|
|
680
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
681
|
+
try std.testing.expectEqualStrings("Draft", retained.nodes[1].widget.text);
|
|
682
|
+
try std.testing.expectEqualDeep(canvas.TextSelection{ .anchor = 0, .focus = 5 }, retained.nodes[1].widget.text_selection.?);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
test "automation set_text with line breaks lands sanitized in single-line fields and raw in textareas" {
|
|
686
|
+
const TestApp = struct {
|
|
687
|
+
fn app(self: *@This()) App {
|
|
688
|
+
return .{ .context = self, .name = "gpu-widget-set-text-breaks", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
693
|
+
defer harness.destroy(std.testing.allocator);
|
|
694
|
+
harness.null_platform.gpu_surfaces = true;
|
|
695
|
+
var app_state: TestApp = .{};
|
|
696
|
+
const app = app_state.app();
|
|
697
|
+
try harness.start(app);
|
|
698
|
+
|
|
699
|
+
_ = try harness.runtime.createView(.{
|
|
700
|
+
.window_id = 1,
|
|
701
|
+
.label = "canvas",
|
|
702
|
+
.kind = .gpu_surface,
|
|
703
|
+
.frame = geometry.RectF.init(0, 0, 320, 220),
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
const children = [_]canvas.Widget{
|
|
707
|
+
.{
|
|
708
|
+
.id = 2,
|
|
709
|
+
.kind = .search_field,
|
|
710
|
+
.frame = geometry.RectF.init(12, 16, 200, 36),
|
|
711
|
+
.text = "",
|
|
712
|
+
.semantics = .{ .label = "Query" },
|
|
713
|
+
},
|
|
714
|
+
.{
|
|
715
|
+
.id = 3,
|
|
716
|
+
.kind = .textarea,
|
|
717
|
+
.frame = geometry.RectF.init(12, 64, 280, 100),
|
|
718
|
+
.text = "",
|
|
719
|
+
.semantics = .{ .label = "Notes" },
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
723
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 320, 220), &nodes);
|
|
724
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
725
|
+
|
|
726
|
+
// Automation set_text rides the REAL text-input event path, so its
|
|
727
|
+
// line breaks sanitize at the same seam a paste does.
|
|
728
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .set_text, .value = "edge\ncustomers\r\nfirst" });
|
|
729
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
730
|
+
try std.testing.expectEqualStrings("edgecustomersfirst", retained.nodes[1].widget.text);
|
|
731
|
+
|
|
732
|
+
// The textarea takes the same payload verbatim.
|
|
733
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .set_text, .value = "edge\ncustomers\r\nfirst" });
|
|
734
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
735
|
+
try std.testing.expectEqualStrings("edge\ncustomers\r\nfirst", retained.nodes[2].widget.text);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
test "ime composition with a newline sanitizes into single-line fields before commit" {
|
|
739
|
+
const TestApp = struct {
|
|
740
|
+
fn app(self: *@This()) App {
|
|
741
|
+
return .{ .context = self, .name = "gpu-widget-ime-newline", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
746
|
+
defer harness.destroy(std.testing.allocator);
|
|
747
|
+
harness.null_platform.gpu_surfaces = true;
|
|
748
|
+
var app_state: TestApp = .{};
|
|
749
|
+
const app = app_state.app();
|
|
750
|
+
try harness.start(app);
|
|
751
|
+
|
|
752
|
+
_ = try harness.runtime.createView(.{
|
|
753
|
+
.window_id = 1,
|
|
754
|
+
.label = "canvas",
|
|
755
|
+
.kind = .gpu_surface,
|
|
756
|
+
.frame = geometry.RectF.init(0, 0, 260, 120),
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
const text_field = canvas.Widget{
|
|
760
|
+
.id = 2,
|
|
761
|
+
.kind = .text_field,
|
|
762
|
+
.frame = geometry.RectF.init(12, 16, 180, 36),
|
|
763
|
+
.text = "Cafe",
|
|
764
|
+
.semantics = .{ .label = "Name" },
|
|
765
|
+
};
|
|
766
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
767
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{text_field} }, geometry.RectF.init(0, 0, 260, 120), &nodes);
|
|
768
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
769
|
+
|
|
770
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
771
|
+
.window_id = 1,
|
|
772
|
+
.label = "canvas",
|
|
773
|
+
.kind = .pointer_down,
|
|
774
|
+
.x = 100,
|
|
775
|
+
.y = 30,
|
|
776
|
+
} });
|
|
777
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
778
|
+
|
|
779
|
+
// A composition PREVIEW carrying a newline sanitizes at the same
|
|
780
|
+
// seam every insert does — the preview in the retained editor holds
|
|
781
|
+
// the stripped bytes, so the COMMIT (which lands whatever the
|
|
782
|
+
// preview holds) can never commit a line break.
|
|
783
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
784
|
+
.window_id = 1,
|
|
785
|
+
.label = "canvas",
|
|
786
|
+
.kind = .ime_set_composition,
|
|
787
|
+
.text = " au\nlait",
|
|
788
|
+
.composition_cursor = 8,
|
|
789
|
+
} });
|
|
790
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
791
|
+
try std.testing.expectEqualStrings("Cafe aulait", retained.nodes[1].widget.text);
|
|
792
|
+
try std.testing.expectEqualDeep(canvas.TextRange.init(4, 11), retained.nodes[1].widget.text_composition.?);
|
|
793
|
+
|
|
794
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
795
|
+
.window_id = 1,
|
|
796
|
+
.label = "canvas",
|
|
797
|
+
.kind = .ime_commit_composition,
|
|
798
|
+
} });
|
|
799
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
800
|
+
try std.testing.expectEqualStrings("Cafe aulait", retained.nodes[1].widget.text);
|
|
801
|
+
try std.testing.expect(retained.nodes[1].widget.text_composition == null);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
test "a model-set single-line value with a newline paints one line inside the field" {
|
|
805
|
+
const TestApp = struct {
|
|
806
|
+
fn app(self: *@This()) App {
|
|
807
|
+
return .{ .context = self, .name = "gpu-widget-value-newline", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
812
|
+
defer harness.destroy(std.testing.allocator);
|
|
813
|
+
harness.null_platform.gpu_surfaces = true;
|
|
814
|
+
var app_state: TestApp = .{};
|
|
815
|
+
const app = app_state.app();
|
|
816
|
+
try harness.start(app);
|
|
817
|
+
|
|
818
|
+
_ = try harness.runtime.createView(.{
|
|
819
|
+
.window_id = 1,
|
|
820
|
+
.label = "canvas",
|
|
821
|
+
.kind = .gpu_surface,
|
|
822
|
+
.frame = geometry.RectF.init(0, 0, 320, 120),
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// A Zig core can put a newline into a field's VALUE today; the
|
|
826
|
+
// sanitize seam only guards EDITS. The retained value keeps the raw
|
|
827
|
+
// bytes (semantics and automation report honestly), but the painted
|
|
828
|
+
// text presents the breaks as spaces on ONE line, under a forced
|
|
829
|
+
// content-rect clip — nothing escapes the rounded border.
|
|
830
|
+
const input = canvas.Widget{
|
|
831
|
+
.id = 2,
|
|
832
|
+
.kind = .input,
|
|
833
|
+
.frame = geometry.RectF.init(12, 16, 200, 32),
|
|
834
|
+
.text = "one\ntwo",
|
|
835
|
+
.semantics = .{ .label = "Title" },
|
|
836
|
+
};
|
|
837
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
838
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{input} }, geometry.RectF.init(0, 0, 320, 120), &nodes);
|
|
839
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
840
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
841
|
+
|
|
842
|
+
const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
843
|
+
var saw_presented_text = false;
|
|
844
|
+
var saw_clip = false;
|
|
845
|
+
for (display_list.commands) |command| {
|
|
846
|
+
switch (command) {
|
|
847
|
+
.draw_text => |text| {
|
|
848
|
+
if (text.id == testCanvasWidgetPartId(2, 3)) {
|
|
849
|
+
try std.testing.expectEqualStrings("one two", text.text);
|
|
850
|
+
saw_presented_text = true;
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
.push_clip => |clip| {
|
|
854
|
+
if (clip.id == testCanvasWidgetPartId(2, 16)) saw_clip = true;
|
|
855
|
+
},
|
|
856
|
+
else => {},
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
try std.testing.expect(saw_presented_text);
|
|
860
|
+
try std.testing.expect(saw_clip);
|
|
861
|
+
|
|
862
|
+
// Semantics (and therefore automation and assistive tech) still read
|
|
863
|
+
// the RAW model value: presentation never rewrites the model.
|
|
864
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
865
|
+
try std.testing.expectEqualStrings("one\ntwo", snapshot.widgets[0].text_value);
|
|
866
|
+
}
|
|
867
|
+
|
|
591
868
|
test "runtime applies ime composition edits to canvas text fields" {
|
|
592
869
|
const TestApp = struct {
|
|
593
870
|
fn app(self: *@This()) App {
|