drawnui-react 0.1.0-preview.3 → 0.1.0-preview.31

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 (91) hide show
  1. package/README.md +15 -1
  2. package/SKIPPED.md +32 -25
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +7 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +16 -1
  5. package/dist/controls/DrawnGame.d.ts +40 -0
  6. package/dist/controls/DrawnGame.js +64 -0
  7. package/dist/controls/GridStructure.d.ts +16 -2
  8. package/dist/controls/GridStructure.js +40 -4
  9. package/dist/controls/SkiaBackdrop.d.ts +8 -2
  10. package/dist/controls/SkiaBackdrop.js +42 -14
  11. package/dist/controls/SkiaButton.d.ts +15 -1
  12. package/dist/controls/SkiaButton.js +21 -4
  13. package/dist/controls/SkiaCarousel.d.ts +21 -2
  14. package/dist/controls/SkiaCarousel.js +49 -5
  15. package/dist/controls/SkiaCheckbox.d.ts +0 -1
  16. package/dist/controls/SkiaCheckbox.js +0 -6
  17. package/dist/controls/SkiaDrawer.d.ts +2 -0
  18. package/dist/controls/SkiaDrawer.js +2 -0
  19. package/dist/controls/SkiaEditor.d.ts +38 -1
  20. package/dist/controls/SkiaEditor.js +223 -49
  21. package/dist/controls/SkiaGif.d.ts +3 -0
  22. package/dist/controls/SkiaGif.js +12 -2
  23. package/dist/controls/SkiaImage.js +15 -10
  24. package/dist/controls/SkiaLabel.d.ts +91 -7
  25. package/dist/controls/SkiaLabel.js +420 -71
  26. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  27. package/dist/controls/SkiaLabelFps.js +41 -0
  28. package/dist/controls/SkiaLayout.d.ts +97 -9
  29. package/dist/controls/SkiaLayout.js +387 -22
  30. package/dist/controls/SkiaLottie.js +4 -2
  31. package/dist/controls/SkiaProgress.d.ts +2 -1
  32. package/dist/controls/SkiaProgress.js +6 -3
  33. package/dist/controls/SkiaRadioButton.js +4 -3
  34. package/dist/controls/SkiaRichLabel.d.ts +1 -1
  35. package/dist/controls/SkiaRichLabel.js +11 -1
  36. package/dist/controls/SkiaScroll.d.ts +35 -5
  37. package/dist/controls/SkiaScroll.js +234 -23
  38. package/dist/controls/SkiaScrollBar.d.ts +27 -0
  39. package/dist/controls/SkiaScrollBar.js +51 -2
  40. package/dist/controls/SkiaShaderCarousel.d.ts +5 -0
  41. package/dist/controls/SkiaShaderCarousel.js +5 -0
  42. package/dist/controls/SkiaShape.d.ts +13 -2
  43. package/dist/controls/SkiaShape.js +50 -10
  44. package/dist/controls/SkiaSlider.d.ts +20 -2
  45. package/dist/controls/SkiaSlider.js +59 -5
  46. package/dist/controls/SkiaSprite.d.ts +1 -0
  47. package/dist/controls/SkiaSprite.js +4 -0
  48. package/dist/controls/SkiaSvg.js +1 -1
  49. package/dist/controls/SkiaSwitch.d.ts +0 -1
  50. package/dist/controls/SkiaSwitch.js +0 -6
  51. package/dist/controls/SkiaToggle.d.ts +25 -5
  52. package/dist/controls/SkiaToggle.js +58 -5
  53. package/dist/controls/SnappingLayout.d.ts +12 -1
  54. package/dist/controls/SnappingLayout.js +19 -1
  55. package/dist/core/Accessibility.d.ts +80 -0
  56. package/dist/core/Accessibility.js +421 -8
  57. package/dist/core/Animators.d.ts +37 -1
  58. package/dist/core/Animators.js +102 -9
  59. package/dist/core/Canvas.d.ts +108 -7
  60. package/dist/core/Canvas.js +353 -29
  61. package/dist/core/Easing.d.ts +12 -1
  62. package/dist/core/Easing.js +25 -1
  63. package/dist/core/Gestures.d.ts +34 -2
  64. package/dist/core/Gestures.js +84 -3
  65. package/dist/core/Hover.d.ts +47 -0
  66. package/dist/core/Hover.js +134 -0
  67. package/dist/core/KeyboardManager.d.ts +13 -0
  68. package/dist/core/KeyboardManager.js +18 -0
  69. package/dist/core/ScrollAnimators.js +9 -0
  70. package/dist/core/Shaping.d.ts +40 -0
  71. package/dist/core/Shaping.js +224 -0
  72. package/dist/core/SkiaControl.d.ts +209 -9
  73. package/dist/core/SkiaControl.js +500 -59
  74. package/dist/core/SkiaEffect.d.ts +17 -0
  75. package/dist/core/SkiaEffect.js +43 -8
  76. package/dist/core/SkiaImageManager.js +1 -1
  77. package/dist/core/Super.d.ts +22 -2
  78. package/dist/core/Super.js +47 -3
  79. package/dist/core/Types.d.ts +11 -1
  80. package/dist/core/Types.js +32 -1
  81. package/dist/core/ViewsAdapter.d.ts +7 -2
  82. package/dist/core/ViewsAdapter.js +10 -3
  83. package/dist/index.d.ts +3 -0
  84. package/dist/index.js +3 -0
  85. package/dist/react/SkiaShell.js +33 -14
  86. package/dist/react/index.d.ts +17 -4
  87. package/dist/react/index.js +103 -15
  88. package/dist/react/reconciler.js +33 -13
  89. package/dist/vite/index.d.ts +9 -0
  90. package/dist/vite/index.js +36 -3
  91. package/package.json +42 -3
@@ -1,3 +1,4 @@
1
+ import type { InputKey } from "./KeyboardManager";
1
2
  import type { SkiaControl } from "./SkiaControl";
2
3
  import { SKRect } from "./Types";
3
4
  /** ARIA role constants (DrawnUi.Models.Aria) for `AccessibilityRole`. */
@@ -38,10 +39,25 @@ export declare const Aria: {
38
39
  readonly RoleRegion: "region";
39
40
  readonly RoleNavigation: "navigation";
40
41
  readonly RoleMain: "main";
42
+ readonly RoleGrid: "grid";
43
+ readonly RoleToolbar: "toolbar";
44
+ readonly RoleRadioGroup: "radiogroup";
45
+ readonly RoleMenuBar: "menubar";
41
46
  /** Removes the control from the accessibility tree even when a default role would apply (inner label of a button). */
42
47
  readonly RolePresentation: "presentation";
43
48
  readonly LivePolite: "polite";
44
49
  readonly LiveAssertive: "assertive";
50
+ /**
51
+ * Container roles whose items the arrow keys walk (C# Aria.IsCompositeRole): a layout with one of them is one Tab stop,
52
+ * its current item, and the arrow keys move between its items.
53
+ */
54
+ readonly IsCompositeRole: (role?: string) => boolean;
55
+ /**
56
+ * Roles a user operates (C# Aria.IsInteractiveRole, as DrawnUi.Rust is_control_role): a node with one of them that
57
+ * cannot take input is read as disabled (aria-disabled). C# also lists listbox and scrollbar; here a listbox is an
58
+ * arrow-key group and groups are never disabled.
59
+ */
60
+ readonly IsInteractiveRole: (role?: string) => boolean;
45
61
  };
46
62
  /** One laid-out text line exposed for native selection (AccessibilityTextSelectable): CSS px relative to the node. */
47
63
  export interface AccessibilityTextLine {
@@ -54,6 +70,17 @@ export interface AccessibilityTextLine {
54
70
  FontWeight: number;
55
71
  FontSize: number;
56
72
  }
73
+ /**
74
+ * The value of a range control (a slider, a progress bar): what a screen reader reads and adjusts (drawnui-cross 6c,
75
+ * C# AccessibilityValue): aria-valuenow / min / max, and aria-valuetext when Text is not empty ("65%", "20 – 80").
76
+ */
77
+ export interface AccessibilityValue {
78
+ Now: number;
79
+ Min: number;
80
+ Max: number;
81
+ Step: number;
82
+ Text: string;
83
+ }
57
84
  /** One entry of the accessibility snapshot (DrawnUi AccessibilityNode). Rect is CSS pixels relative to the canvas. */
58
85
  export interface AccessibilityNode {
59
86
  Id: number;
@@ -62,9 +89,13 @@ export interface AccessibilityNode {
62
89
  Role: string;
63
90
  Rect: SKRect;
64
91
  CanInteract: boolean;
92
+ /** A role a user operates (Aria.IsInteractiveRole) that cannot take input: aria-disabled, no tab stop. */
93
+ Disabled: boolean;
65
94
  IsPressed?: boolean;
66
95
  Live?: string;
67
96
  Source: SkiaControl;
97
+ /** A range control's value (aria-valuenow / min / max / valuetext); its name stays the app's label. */
98
+ Value?: AccessibilityValue;
68
99
  /** Real text lines rendered into the overlay so the browser can select / copy them (opt-in per control). */
69
100
  TextLines?: AccessibilityTextLine[];
70
101
  }
@@ -81,6 +112,7 @@ export declare class SkiaAccessibilityManager {
81
112
  private pending;
82
113
  private readonly changed;
83
114
  private readonly liveUpdated;
115
+ private readonly keyboardFocusRequested;
84
116
  /** Minimum milliseconds between snapshot rebuilds. */
85
117
  MinUpdateIntervalMs: number;
86
118
  Snapshot: AccessibilityNode[];
@@ -89,7 +121,54 @@ export declare class SkiaAccessibilityManager {
89
121
  OnChanged(cb: () => void): () => void;
90
122
  /** Fired immediately (bypassing the rate limit) when a live-region node's value changes. */
91
123
  OnLiveRegionUpdated(cb: (node: SkiaControl) => void): () => void;
124
+ /**
125
+ * Keyboard focus moved by the manager itself (arrow keys in a group): the overlay moves DOM focus to that node's
126
+ * element (C# KeyboardFocusRequested). Returns the unsubscribe function.
127
+ */
128
+ OnKeyboardFocusRequested(cb: (node: SkiaControl) => void): () => void;
92
129
  NotifyFocused(node?: SkiaControl): void;
130
+ /**
131
+ * Enter / Space from keyboard navigation or a screen reader: activates the node only while a tap could reach it
132
+ * (AccessibilityCanInteract), the rule every head applies.
133
+ */
134
+ static Activate(node?: SkiaControl): boolean;
135
+ /**
136
+ * Arrow keys, Home / End, PageUp / PageDown for the node in keyboard focus: the control gets them first, only while a
137
+ * pan could reach it (a slider steps its value); keys it does not use move keyboard focus between the items of the
138
+ * group around it (MoveInGroup). True when the key was used.
139
+ */
140
+ static Key(node: SkiaControl | undefined, key: InputKey): boolean;
141
+ /** Last focused node of each group: where Tab enters the group. */
142
+ private readonly groupFocus;
143
+ private groupRequest?;
144
+ /**
145
+ * The arrow-key group around `control`: its nearest ancestor with a composite role (Aria.IsCompositeRole, e.g.
146
+ * Aria.RoleList on a SkiaStack), and the item of that group holding the control (one of its children, a cell).
147
+ */
148
+ static TryFindGroup(control: SkiaControl): {
149
+ Group: SkiaControl;
150
+ Item: SkiaControl;
151
+ } | undefined;
152
+ /** Remembers where keyboard focus is inside its group, so the next Tab into the group lands there. */
153
+ private NoteFocus;
154
+ /**
155
+ * Whether Tab / Shift+Tab stop on this node. A group of items is one Tab stop, like a native list: its current item
156
+ * (the one keyboard focus last had there, else the group's first usable node) plus the controls inside that same
157
+ * item; the arrow keys move between items. Every node outside a group is a stop.
158
+ */
159
+ IsTabStop(node: SkiaControl): boolean;
160
+ /**
161
+ * Moves keyboard focus between the items of the group around `focused`, by item index like a native list: Down / Up in
162
+ * a Column, Right / Left in a Row, all four in a Wrap, a Grid or a Split layout (Up / Down by one row), Home / End to the
163
+ * first / last item, PageDown / PageUp by one viewport of the scroll around it. No wrap at the ends. The target is the
164
+ * item itself when it is an interactive node, else its first interactive node; items the pointer cannot use are
165
+ * skipped. An item not realized (recycled cells) is scrolled in with ScrollToIndex when the group is the scroll's
166
+ * content, and focused once drawn. True when the key belongs to the group.
167
+ */
168
+ MoveInGroup(focused: SkiaControl, key: InputKey): boolean;
169
+ /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
170
+ private ProcessGroupFocus;
171
+ private FocusFromKeyboard;
93
172
  Register(node: SkiaControl): void;
94
173
  NotifyUpdated(node: SkiaControl): void;
95
174
  ForceRebuildOnNextFrame(): void;
@@ -100,5 +179,6 @@ export declare class SkiaAccessibilityManager {
100
179
  * per MinUpdateIntervalMs otherwise (keeps rects in sync with scrolling); notifies only when the snapshot differs.
101
180
  */
102
181
  OnFrameEnd(scale: number, canvasWidthPx: number, canvasHeightPx: number, requestFrame: () => void): void;
182
+ private Rebuild;
103
183
  private static Same;
104
184
  }
@@ -12,11 +12,33 @@ export const Aria = {
12
12
  RoleSeparator: "separator", RoleProgressBar: "progressbar", RoleTooltip: "tooltip", RoleDialog: "dialog",
13
13
  RoleAlertDialog: "alertdialog", RoleStatus: "status", RoleAlert: "alert", RoleGroup: "group", RoleRegion: "region",
14
14
  RoleNavigation: "navigation", RoleMain: "main",
15
+ // containers of items: with one of these roles a layout is an arrow-key group (IsCompositeRole)
16
+ RoleGrid: "grid", RoleToolbar: "toolbar", RoleRadioGroup: "radiogroup", RoleMenuBar: "menubar",
15
17
  /** Removes the control from the accessibility tree even when a default role would apply (inner label of a button). */
16
18
  RolePresentation: "presentation",
17
19
  // live regions
18
20
  LivePolite: "polite", LiveAssertive: "assertive",
21
+ /**
22
+ * Container roles whose items the arrow keys walk (C# Aria.IsCompositeRole): a layout with one of them is one Tab stop,
23
+ * its current item, and the arrow keys move between its items.
24
+ */
25
+ IsCompositeRole(role) {
26
+ return role === "list" || role === "listbox" || role === "grid" || role === "toolbar" || role === "radiogroup"
27
+ || role === "tablist" || role === "menu" || role === "menubar";
28
+ },
29
+ /**
30
+ * Roles a user operates (C# Aria.IsInteractiveRole, as DrawnUi.Rust is_control_role): a node with one of them that
31
+ * cannot take input is read as disabled (aria-disabled). C# also lists listbox and scrollbar; here a listbox is an
32
+ * arrow-key group and groups are never disabled.
33
+ */
34
+ IsInteractiveRole(role) {
35
+ return role === "button" || role === "link" || role === "checkbox" || role === "radio" || role === "switch"
36
+ || role === "slider" || role === "spinbutton" || role === "textbox" || role === "searchbox" || role === "combobox"
37
+ || role === "option" || role === "tab" || role === "menuitem" || role === "menuitemcheckbox" || role === "menuitemradio";
38
+ },
19
39
  };
40
+ const asLayout = (c) => ("ChildrenFactory" in c && "Split" in c ? c : undefined);
41
+ const asScroll = (c) => ("ScrollToIndex" in c && "ViewportOffsetY" in c ? c : undefined);
20
42
  /**
21
43
  * Mirrors DrawnUi SkiaAccessibilityManager: registry of accessible controls + a rate-limited snapshot
22
44
  * (at most one rebuild per MinUpdateIntervalMs, taken at frame end) that the DOM overlay renders.
@@ -30,6 +52,7 @@ export class SkiaAccessibilityManager {
30
52
  pending = 0;
31
53
  changed = new Set();
32
54
  liveUpdated = new Set();
55
+ keyboardFocusRequested = new Set();
33
56
  /** Minimum milliseconds between snapshot rebuilds. */
34
57
  MinUpdateIntervalMs = 1000;
35
58
  Snapshot = [];
@@ -38,8 +61,199 @@ export class SkiaAccessibilityManager {
38
61
  OnChanged(cb) { this.changed.add(cb); return () => this.changed.delete(cb); }
39
62
  /** Fired immediately (bypassing the rate limit) when a live-region node's value changes. */
40
63
  OnLiveRegionUpdated(cb) { this.liveUpdated.add(cb); return () => this.liveUpdated.delete(cb); }
41
- NotifyFocused(node) { if (this.FocusedNode !== node)
42
- this.FocusedNode = node; }
64
+ /**
65
+ * Keyboard focus moved by the manager itself (arrow keys in a group): the overlay moves DOM focus to that node's
66
+ * element (C# KeyboardFocusRequested). Returns the unsubscribe function.
67
+ */
68
+ OnKeyboardFocusRequested(cb) { this.keyboardFocusRequested.add(cb); return () => this.keyboardFocusRequested.delete(cb); }
69
+ NotifyFocused(node) {
70
+ if (this.FocusedNode === node)
71
+ return;
72
+ this.NoteFocus(node);
73
+ this.FocusedNode = node;
74
+ }
75
+ /**
76
+ * Enter / Space from keyboard navigation or a screen reader: activates the node only while a tap could reach it
77
+ * (AccessibilityCanInteract), the rule every head applies.
78
+ */
79
+ static Activate(node) {
80
+ if (!node || !node.AccessibilityCanInteract)
81
+ return false;
82
+ node.OnAccessibilityActivated();
83
+ node.Superview?.AccessibilityManager.ForceRebuildOnNextFrame(); // a screen reader reads the new state right back
84
+ return true;
85
+ }
86
+ /**
87
+ * Arrow keys, Home / End, PageUp / PageDown for the node in keyboard focus: the control gets them first, only while a
88
+ * pan could reach it (a slider steps its value); keys it does not use move keyboard focus between the items of the
89
+ * group around it (MoveInGroup). True when the key was used.
90
+ */
91
+ static Key(node, key) {
92
+ if (!node)
93
+ return false;
94
+ if (node.CanReceiveGesture("Panning") && node.OnAccessibilityKey(key)) {
95
+ node.Superview?.AccessibilityManager.ForceRebuildOnNextFrame(); // the new value is read right back, not a second later
96
+ return true;
97
+ }
98
+ return node.Superview?.AccessibilityManager.MoveInGroup(node, key) ?? false;
99
+ }
100
+ // ---- arrow-key groups (C# SkiaAccessibilityManager, "Arrow-key groups") ----
101
+ /** Last focused node of each group: where Tab enters the group. */
102
+ groupFocus = new WeakMap();
103
+ groupRequest;
104
+ /**
105
+ * The arrow-key group around `control`: its nearest ancestor with a composite role (Aria.IsCompositeRole, e.g.
106
+ * Aria.RoleList on a SkiaStack), and the item of that group holding the control (one of its children, a cell).
107
+ */
108
+ static TryFindGroup(control) {
109
+ for (let child = control, parent = control.Parent; parent; child = parent, parent = parent.Parent) {
110
+ if (Aria.IsCompositeRole(parent.AccessibilityRole))
111
+ return { Group: parent, Item: child };
112
+ }
113
+ return undefined;
114
+ }
115
+ /** Remembers where keyboard focus is inside its group, so the next Tab into the group lands there. */
116
+ NoteFocus(node) {
117
+ const found = node && SkiaAccessibilityManager.TryFindGroup(node);
118
+ if (found)
119
+ this.groupFocus.set(found.Group, node);
120
+ }
121
+ /**
122
+ * Whether Tab / Shift+Tab stop on this node. A group of items is one Tab stop, like a native list: its current item
123
+ * (the one keyboard focus last had there, else the group's first usable node) plus the controls inside that same
124
+ * item; the arrow keys move between items. Every node outside a group is a stop.
125
+ */
126
+ IsTabStop(node) {
127
+ const found = SkiaAccessibilityManager.TryFindGroup(node);
128
+ if (!found)
129
+ return true;
130
+ let stopItem;
131
+ const remembered = this.groupFocus.get(found.Group);
132
+ const current = remembered && !remembered.IsDisposed && remembered.AccessibilityCanInteract && this.Snapshot.some((n) => n.Source === remembered)
133
+ ? SkiaAccessibilityManager.TryFindGroup(remembered) : undefined;
134
+ if (current && current.Group === found.Group)
135
+ stopItem = current.Item;
136
+ else {
137
+ for (const n of this.Snapshot) {
138
+ if (!n.Source.AccessibilityCanInteract)
139
+ continue;
140
+ const g = SkiaAccessibilityManager.TryFindGroup(n.Source);
141
+ if (g && g.Group === found.Group) {
142
+ stopItem = g.Item;
143
+ break;
144
+ }
145
+ }
146
+ }
147
+ return !stopItem || stopItem === found.Item;
148
+ }
149
+ /**
150
+ * Moves keyboard focus between the items of the group around `focused`, by item index like a native list: Down / Up in
151
+ * a Column, Right / Left in a Row, all four in a Wrap, a Grid or a Split layout (Up / Down by one row), Home / End to the
152
+ * first / last item, PageDown / PageUp by one viewport of the scroll around it. No wrap at the ends. The target is the
153
+ * item itself when it is an interactive node, else its first interactive node; items the pointer cannot use are
154
+ * skipped. An item not realized (recycled cells) is scrolled in with ScrollToIndex when the group is the scroll's
155
+ * content, and focused once drawn. True when the key belongs to the group.
156
+ */
157
+ MoveInGroup(focused, key) {
158
+ const found = SkiaAccessibilityManager.TryFindGroup(focused);
159
+ if (!found)
160
+ return false;
161
+ const { Group: group, Item: item } = found;
162
+ const scroll = FindScroll(group), axis = AxisOf(group), count = ItemCount(group);
163
+ const current = this.groupRequest?.Group === group ? this.groupRequest.Index : IndexOf(group, item);
164
+ if (current < 0 || count < 1)
165
+ return false;
166
+ const row = axis === "Both" ? RowLength(group) : 1;
167
+ const vertical = axis !== "Horizontal";
168
+ const page = () => PageSize(scroll, item, vertical) * row;
169
+ let target, step;
170
+ const layout = asLayout(group), masonry = layout?.Type === "Masonry" ? MasonryTarget(layout, current, key, scroll) : undefined;
171
+ if (masonry !== undefined) {
172
+ target = masonry;
173
+ step = key === "ArrowDown" || key === "ArrowRight" || key === "PageDown" ? 1 : -1;
174
+ }
175
+ else if ((key === "ArrowDown" && axis === "Vertical") || (key === "ArrowRight" && axis !== "Vertical")) {
176
+ target = current + 1;
177
+ step = 1;
178
+ }
179
+ else if ((key === "ArrowUp" && axis === "Vertical") || (key === "ArrowLeft" && axis !== "Vertical")) {
180
+ target = current - 1;
181
+ step = -1;
182
+ }
183
+ else if (key === "ArrowDown" && axis === "Both") {
184
+ target = Math.min(count - 1, current + row);
185
+ step = 1;
186
+ }
187
+ else if (key === "ArrowUp" && axis === "Both") {
188
+ target = Math.max(0, current - row);
189
+ step = -1;
190
+ }
191
+ else if (key === "Home") {
192
+ target = 0;
193
+ step = 1;
194
+ }
195
+ else if (key === "End") {
196
+ target = count - 1;
197
+ step = -1;
198
+ }
199
+ else if (key === "PageDown" && scroll) {
200
+ target = Math.min(count - 1, current + page());
201
+ step = 1;
202
+ }
203
+ else if (key === "PageUp" && scroll) {
204
+ target = Math.max(0, current - page());
205
+ step = -1;
206
+ }
207
+ else
208
+ return false;
209
+ if (target < 0 || target >= count || target === current)
210
+ return true; // at the end of the group nothing happens, the key still belongs to it
211
+ this.groupRequest = { Group: group, Scroll: scroll, Index: target, Step: step, Deadline: performance.now() + 3000, ScrollIssued: false };
212
+ group.Superview?.Update(); // resolved at the end of the next frame, together with the snapshot
213
+ return true;
214
+ }
215
+ /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
216
+ ProcessGroupFocus(scale, w, h, requestFrame) {
217
+ const request = this.groupRequest;
218
+ if (!request)
219
+ return;
220
+ const cell = ItemAt(request.Group, request.Index);
221
+ if (cell && IsDrawn(cell)) {
222
+ const node = FindTarget(cell);
223
+ if (node) {
224
+ this.groupRequest = undefined;
225
+ this.FocusFromKeyboard(node, scale, w, h);
226
+ return;
227
+ }
228
+ // this item cannot take input: go on to the next one in the same direction
229
+ request.Index += request.Step;
230
+ if (request.Index < 0 || request.Index >= ItemCount(request.Group)) {
231
+ this.groupRequest = undefined;
232
+ return;
233
+ }
234
+ request.Deadline = performance.now() + 3000;
235
+ request.ScrollIssued = false;
236
+ }
237
+ else if (performance.now() > request.Deadline || request.Group.IsDisposed) {
238
+ this.groupRequest = undefined;
239
+ return;
240
+ }
241
+ if (!request.ScrollIssued) {
242
+ request.ScrollIssued = true;
243
+ const next = ItemAt(request.Group, request.Index);
244
+ if ((!next || !IsDrawn(next)) && request.Scroll && request.Scroll.Content === request.Group) {
245
+ request.Scroll.ScrollToIndex(request.Index, true, request.Step > 0 ? "End" : "Start");
246
+ }
247
+ }
248
+ requestFrame(); // keep frames coming until the item is drawn
249
+ }
250
+ FocusFromKeyboard(node, scale, w, h) {
251
+ this.Rebuild(scale, w, h); // the overlay looks the node up in the snapshot: make sure it is there now
252
+ this.NoteFocus(node);
253
+ this.FocusedNode = node;
254
+ for (const cb of this.keyboardFocusRequested)
255
+ cb(node);
256
+ }
43
257
  Register(node) { this.nodes.add(node); this.dirty = true; }
44
258
  NotifyUpdated(node) {
45
259
  if (!this.nodes.has(node))
@@ -49,7 +263,7 @@ export class SkiaAccessibilityManager {
49
263
  for (const cb of this.liveUpdated)
50
264
  cb(node);
51
265
  }
52
- ForceRebuildOnNextFrame() { this.lastRebuild = 0; this.dirty = true; }
266
+ ForceRebuildOnNextFrame() { this.lastRebuild = -Infinity; this.dirty = true; }
53
267
  Unregister(node) {
54
268
  if (this.nodes.delete(node)) {
55
269
  node.OnAccessibilityUnregistered();
@@ -70,6 +284,7 @@ export class SkiaAccessibilityManager {
70
284
  * per MinUpdateIntervalMs otherwise (keeps rects in sync with scrolling); notifies only when the snapshot differs.
71
285
  */
72
286
  OnFrameEnd(scale, canvasWidthPx, canvasHeightPx, requestFrame) {
287
+ this.ProcessGroupFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
73
288
  if (this.nodes.size === 0 && this.Snapshot.length === 0)
74
289
  return;
75
290
  const now = performance.now();
@@ -80,9 +295,12 @@ export class SkiaAccessibilityManager {
80
295
  this.pending = window.setTimeout(() => { this.pending = 0; requestFrame(); }, wait);
81
296
  return;
82
297
  }
298
+ this.Rebuild(scale, canvasWidthPx, canvasHeightPx);
299
+ }
300
+ Rebuild(scale, canvasWidthPx, canvasHeightPx) {
83
301
  this.dirty = false;
84
- this.lastRebuild = now;
85
- const list = [];
302
+ this.lastRebuild = performance.now();
303
+ let list = [];
86
304
  for (const n of this.nodes) {
87
305
  if (!n.Superview) {
88
306
  this.nodes.delete(n);
@@ -101,13 +319,30 @@ export class SkiaAccessibilityManager {
101
319
  if (px.Right < -canvasWidthPx || px.Bottom < -canvasHeightPx || px.Left > 2 * canvasWidthPx || px.Top > 2 * canvasHeightPx)
102
320
  continue;
103
321
  list.push({
104
- Id: n.AccessibilityId, Label: n.AccessibilityLabel, Hint: n.AccessibilityHint, Role: n.AccessibilityRole,
322
+ Id: n.AccessibilityId, Label: n.AccessibilityLabel, Hint: n.AccessibilityHint, Role: n.AccessibilityRole, Value: n.AccessibilityValue,
105
323
  Rect: new SKRect(px.Left / scale, px.Top / scale, px.Right / scale, px.Bottom / scale),
106
324
  CanInteract: n.AccessibilityCanInteract, IsPressed: n.AccessibilityIsPressed, Live: n.AccessibilityLive, Source: n,
325
+ Disabled: !n.AccessibilityCanInteract && Aria.IsInteractiveRole(n.AccessibilityRole),
107
326
  TextLines: n.AccessibilityTextSelectable ? n.GetAccessibilityTextLines(scale) : undefined,
108
327
  });
109
328
  }
329
+ list = SayNamesOnce(list);
110
330
  list.sort((a, b) => a.Rect.Top - b.Rect.Top || a.Rect.Left - b.Rect.Left);
331
+ // reading order: nodes whose tops are within half the smaller height form one row, read left to right, so a row of
332
+ // vertically centered controls of different heights keeps its visual order (C# RectComparer + LeftComparer)
333
+ for (let start = 0, i = 1; i <= list.length; i++) {
334
+ if (i < list.length) {
335
+ const first = list[start].Rect, next = list[i].Rect;
336
+ if (next.Top - first.Top < Math.min(first.Height, next.Height) / 2)
337
+ continue;
338
+ }
339
+ if (i - start > 1) {
340
+ const row = list.slice(start, i).sort((a, b) => a.Rect.Left - b.Rect.Left);
341
+ for (let k = 0; k < row.length; k++)
342
+ list[start + k] = row[k];
343
+ }
344
+ start = i;
345
+ }
111
346
  if (SkiaAccessibilityManager.Same(list, this.Snapshot))
112
347
  return;
113
348
  this.Snapshot = list;
@@ -119,8 +354,8 @@ export class SkiaAccessibilityManager {
119
354
  return false;
120
355
  for (let i = 0; i < a.length; i++) {
121
356
  const x = a[i], y = b[i];
122
- if (x.Source !== y.Source || x.Label !== y.Label || x.Hint !== y.Hint || x.Role !== y.Role || x.CanInteract !== y.CanInteract
123
- || x.IsPressed !== y.IsPressed || x.Live !== y.Live
357
+ if (x.Source !== y.Source || x.Label !== y.Label || x.Hint !== y.Hint || x.Role !== y.Role || x.CanInteract !== y.CanInteract || x.Disabled !== y.Disabled
358
+ || x.IsPressed !== y.IsPressed || x.Live !== y.Live || !SameValue(x.Value, y.Value)
124
359
  || Math.abs(x.Rect.Left - y.Rect.Left) > 0.5 || Math.abs(x.Rect.Top - y.Rect.Top) > 0.5
125
360
  || Math.abs(x.Rect.Right - y.Rect.Right) > 0.5 || Math.abs(x.Rect.Bottom - y.Rect.Bottom) > 0.5)
126
361
  return false;
@@ -138,6 +373,184 @@ export class SkiaAccessibilityManager {
138
373
  return true;
139
374
  }
140
375
  }
376
+ /**
377
+ * Each name is said once in the flat overlay (DrawnUi.Rust said_by_child): a text or a heading whose label repeats the
378
+ * label of the node it is in (its nearest ancestor node) is said by one of them. Under an interactive node (a card
379
+ * button) the child is left out, the button keeps its name; under any other node (a group card and its title) the
380
+ * node loses its name and the heading says it. Selectable text (TextLines) always stays.
381
+ */
382
+ function SayNamesOnce(list) {
383
+ const bySource = new Map(list.map((x) => [x.Source, x]));
384
+ const said = new Set();
385
+ for (const x of list) {
386
+ if (!x.Label || x.TextLines || (x.Role !== Aria.RoleText && x.Role !== Aria.RoleHeading))
387
+ continue;
388
+ let owner;
389
+ for (let p = x.Source.Parent; p && !owner; p = p.Parent)
390
+ owner = bySource.get(p);
391
+ if (!owner || owner.Label !== x.Label)
392
+ continue;
393
+ if (owner.CanInteract)
394
+ said.add(x);
395
+ else
396
+ owner.Label = undefined;
397
+ }
398
+ return said.size ? list.filter((x) => !said.has(x)) : list;
399
+ }
400
+ function SameValue(a, b) {
401
+ return a === b || (!!a && !!b && a.Now === b.Now && a.Min === b.Min && a.Max === b.Max && a.Step === b.Step && a.Text === b.Text);
402
+ }
403
+ // ---- group helpers (duck-typed layouts and scrolls) ----
404
+ /** Children of a control (a layout's Views, a scroll's Content). */
405
+ function ViewsOf(c) {
406
+ if ("Views" in c)
407
+ return c.Views;
408
+ const content = c.Content;
409
+ return content ? [content] : [];
410
+ }
411
+ function FindScroll(group) {
412
+ for (let p = group.Parent; p; p = p.Parent) {
413
+ const s = asScroll(p);
414
+ if (s)
415
+ return s;
416
+ }
417
+ return undefined;
418
+ }
419
+ /** Down / Up in a Column, Right / Left in a Row, all four in a Wrap, a Grid or a Split layout. */
420
+ function AxisOf(group) {
421
+ const l = asLayout(group);
422
+ if (!l)
423
+ return "Vertical";
424
+ if (l.Type === "Column")
425
+ return l.Split <= 1 ? "Vertical" : "Both";
426
+ if (l.Type === "Row")
427
+ return "Horizontal";
428
+ if (l.Type === "Absolute")
429
+ return "Vertical";
430
+ return "Both";
431
+ }
432
+ /** Items per row of a 2D group: Split when set, else the items sharing the row of `item`. */
433
+ /**
434
+ * Items per row of a 2D group: the Split, else the items on the row of the group's first item. C# counts the focused
435
+ * item's row, which the short last row of a wrap leaves short (Up from it skipped items); DrawnUi.Rust afef66f.
436
+ */
437
+ function RowLength(group) {
438
+ const l = asLayout(group);
439
+ if (l && l.Split > 1)
440
+ return l.Split;
441
+ const first = ItemAt(group, 0) ?? FirstRealized(group);
442
+ if (!first)
443
+ return 1;
444
+ const top = first.GetAccessibilityPixelRect();
445
+ if (top.Height <= 0)
446
+ return 1;
447
+ const mid = (top.Top + top.Bottom) / 2;
448
+ let count = 0;
449
+ for (const child of ViewsOf(group)) {
450
+ const r = child.GetAccessibilityPixelRect();
451
+ if (r.Height > 0 && Math.abs((r.Top + r.Bottom) / 2 - mid) < top.Height / 2)
452
+ count++;
453
+ }
454
+ return Math.max(1, count);
455
+ }
456
+ function ItemCount(group) {
457
+ const l = asLayout(group);
458
+ return l?.IsTemplated ? l.ItemsSource?.length ?? 0 : ViewsOf(group).length;
459
+ }
460
+ function IndexOf(group, item) {
461
+ const l = asLayout(group);
462
+ return l?.IsTemplated ? item.ContextIndex : ViewsOf(group).indexOf(item);
463
+ }
464
+ /** The view of an item: the realized cell of a templated layout (none when its cell is not in use), else the child. */
465
+ function ItemAt(group, index) {
466
+ const l = asLayout(group);
467
+ if (l?.IsTemplated) {
468
+ const v = l.ChildrenFactory.GetViewForIndex(index);
469
+ return v && v.ContextIndex === index ? v : undefined;
470
+ }
471
+ return index >= 0 && index < ViewsOf(group).length ? ViewsOf(group)[index] : undefined;
472
+ }
473
+ /** The realized item with the lowest index (item 0 of a scrolled recycled group may not be realized). */
474
+ function FirstRealized(group) {
475
+ let best;
476
+ for (const v of ViewsOf(group))
477
+ if (!best || IndexOf(group, v) < IndexOf(group, best))
478
+ best = v;
479
+ return best;
480
+ }
481
+ /** Arranged on the canvas: realized and laid out (a templated layout keeps only the cells it draws in use). */
482
+ function IsDrawn(control) {
483
+ const r = control.GetAccessibilityPixelRect();
484
+ return !!control.Superview && r.Width > 0 && r.Height > 0;
485
+ }
486
+ /** Items per viewport of the scroll around the group. */
487
+ /**
488
+ * C# MasonryTarget (2ad608d1): the target of an arrow or page key in a Masonry group, from the placed items. Up / Down go
489
+ * to the previous / next item of the same column, Left / Right to the item of the neighbour column nearest in height,
490
+ * PageUp / PageDown up to one viewport along the column (else the next / previous item of the column). `current` when
491
+ * there is no item that way; undefined for other keys or no placement (the generic rules apply).
492
+ */
493
+ function MasonryTarget(layout, current, key, scroll) {
494
+ if (key !== "ArrowDown" && key !== "ArrowUp" && key !== "ArrowLeft" && key !== "ArrowRight" && key !== "PageDown" && key !== "PageUp")
495
+ return undefined;
496
+ const cells = layout.GetMasonryPlacement?.() ?? [];
497
+ const focused = cells.find((c) => c.Index === current);
498
+ if (!focused)
499
+ return undefined;
500
+ const lefts = [...new Set(cells.map((c) => Math.round(c.Rect.Left)))].sort((a, b) => a - b);
501
+ const columnOf = (c) => lefts.indexOf(Math.round(c.Rect.Left));
502
+ const col = columnOf(focused), top = focused.Rect.Top, mid = (focused.Rect.Top + focused.Rect.Bottom) / 2;
503
+ const column = cells.filter((c) => columnOf(c) === col).sort((a, b) => a.Rect.Top - b.Rect.Top);
504
+ const below = column.filter((c) => c.Rect.Top > top), above = column.filter((c) => c.Rect.Top < top);
505
+ const viewport = scroll ? scroll.DrawingRect.Height : 0;
506
+ let found;
507
+ if (key === "ArrowDown")
508
+ found = below[0];
509
+ else if (key === "ArrowUp")
510
+ found = above[above.length - 1];
511
+ else if (key === "ArrowRight" || key === "ArrowLeft") {
512
+ const next = col + (key === "ArrowRight" ? 1 : -1);
513
+ let best = Infinity;
514
+ for (const c of cells) {
515
+ if (columnOf(c) !== next)
516
+ continue;
517
+ const d = Math.abs((c.Rect.Top + c.Rect.Bottom) / 2 - mid);
518
+ if (d < best) {
519
+ best = d;
520
+ found = c;
521
+ }
522
+ }
523
+ }
524
+ else {
525
+ if (!scroll)
526
+ return undefined;
527
+ if (key === "PageDown") {
528
+ const within = below.filter((c) => c.Rect.Top <= top + viewport);
529
+ found = within[within.length - 1] ?? below[0];
530
+ }
531
+ else {
532
+ const within = above.filter((c) => c.Rect.Top >= top - viewport);
533
+ found = within[0] ?? above[above.length - 1];
534
+ }
535
+ }
536
+ return found?.Index ?? current;
537
+ }
538
+ function PageSize(scroll, item, vertical) {
539
+ const v = scroll.DrawingRect, size = item.MeasuredSize.Pixels;
540
+ const viewport = vertical ? v.Height : v.Width, s = vertical ? size.Height : size.Width;
541
+ return s > 0 ? Math.max(1, Math.floor(viewport / s)) : 1;
542
+ }
543
+ /** The item itself when it is an interactive node, else its first interactive node in tree order. */
544
+ function FindTarget(item) {
545
+ if (item.IsAccessibilityElement && item.AccessibilityCanInteract)
546
+ return item;
547
+ for (const child of ViewsOf(item)) {
548
+ const found = FindTarget(child);
549
+ if (found)
550
+ return found;
551
+ }
552
+ return undefined;
553
+ }
141
554
  /** True when any ancestor is hidden (IsVisible false or Opacity 0): the subtree is not drawn, so it gets no nodes. */
142
555
  function AccessibilityManagerHiddenByAncestor(control) {
143
556
  let p = control.Parent;