drawnui-react 0.1.0-preview.4 → 0.1.0-preview.41

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 (107) hide show
  1. package/README.md +129 -14
  2. package/SKIPPED.md +36 -26
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +18 -1
  5. package/dist/controls/DrawnGame.d.ts +44 -0
  6. package/dist/controls/DrawnGame.js +82 -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 +17 -3
  12. package/dist/controls/SkiaButton.js +26 -8
  13. package/dist/controls/SkiaCarousel.d.ts +22 -3
  14. package/dist/controls/SkiaCarousel.js +85 -9
  15. package/dist/controls/SkiaCheckbox.d.ts +0 -1
  16. package/dist/controls/SkiaCheckbox.js +2 -7
  17. package/dist/controls/SkiaDrawer.d.ts +15 -0
  18. package/dist/controls/SkiaDrawer.js +42 -7
  19. package/dist/controls/SkiaEditor.d.ts +48 -2
  20. package/dist/controls/SkiaEditor.js +268 -53
  21. package/dist/controls/SkiaGif.d.ts +7 -0
  22. package/dist/controls/SkiaGif.js +25 -4
  23. package/dist/controls/SkiaImage.d.ts +5 -0
  24. package/dist/controls/SkiaImage.js +48 -14
  25. package/dist/controls/SkiaLabel.d.ts +117 -9
  26. package/dist/controls/SkiaLabel.js +526 -80
  27. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  28. package/dist/controls/SkiaLabelFps.js +41 -0
  29. package/dist/controls/SkiaLayout.d.ts +89 -9
  30. package/dist/controls/SkiaLayout.js +364 -21
  31. package/dist/controls/SkiaLottie.js +5 -3
  32. package/dist/controls/SkiaProgress.d.ts +2 -1
  33. package/dist/controls/SkiaProgress.js +8 -5
  34. package/dist/controls/SkiaRadioButton.d.ts +2 -0
  35. package/dist/controls/SkiaRadioButton.js +16 -4
  36. package/dist/controls/SkiaRichLabel.d.ts +1 -1
  37. package/dist/controls/SkiaRichLabel.js +11 -1
  38. package/dist/controls/SkiaScroll.d.ts +35 -5
  39. package/dist/controls/SkiaScroll.js +252 -32
  40. package/dist/controls/SkiaScrollBar.d.ts +27 -0
  41. package/dist/controls/SkiaScrollBar.js +51 -2
  42. package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
  43. package/dist/controls/SkiaShaderCarousel.js +27 -5
  44. package/dist/controls/SkiaShape.d.ts +13 -2
  45. package/dist/controls/SkiaShape.js +50 -10
  46. package/dist/controls/SkiaSlider.d.ts +20 -2
  47. package/dist/controls/SkiaSlider.js +61 -7
  48. package/dist/controls/SkiaSprite.d.ts +4 -0
  49. package/dist/controls/SkiaSprite.js +22 -10
  50. package/dist/controls/SkiaSvg.d.ts +4 -0
  51. package/dist/controls/SkiaSvg.js +28 -4
  52. package/dist/controls/SkiaSwitch.d.ts +0 -1
  53. package/dist/controls/SkiaSwitch.js +4 -8
  54. package/dist/controls/SkiaToggle.d.ts +25 -5
  55. package/dist/controls/SkiaToggle.js +58 -5
  56. package/dist/controls/SnappingLayout.d.ts +12 -1
  57. package/dist/controls/SnappingLayout.js +21 -2
  58. package/dist/controls/TooltipStyle.d.ts +52 -0
  59. package/dist/controls/TooltipStyle.js +88 -0
  60. package/dist/core/Accessibility.d.ts +134 -0
  61. package/dist/core/Accessibility.js +675 -9
  62. package/dist/core/Animators.d.ts +37 -1
  63. package/dist/core/Animators.js +102 -9
  64. package/dist/core/Canvas.d.ts +241 -10
  65. package/dist/core/Canvas.js +739 -44
  66. package/dist/core/ControlStyle.d.ts +2 -0
  67. package/dist/core/ControlStyle.js +2 -0
  68. package/dist/core/DesignerActions.d.ts +32 -0
  69. package/dist/core/DesignerActions.js +68 -0
  70. package/dist/core/Easing.d.ts +12 -1
  71. package/dist/core/Easing.js +25 -1
  72. package/dist/core/Gestures.d.ts +81 -2
  73. package/dist/core/Gestures.js +177 -3
  74. package/dist/core/Hover.d.ts +51 -0
  75. package/dist/core/Hover.js +140 -0
  76. package/dist/core/ImageEffects.d.ts +2 -0
  77. package/dist/core/ImageEffects.js +2 -0
  78. package/dist/core/KeyboardManager.d.ts +40 -0
  79. package/dist/core/KeyboardManager.js +98 -8
  80. package/dist/core/PopupWindows.d.ts +94 -0
  81. package/dist/core/PopupWindows.js +205 -0
  82. package/dist/core/ScrollAnimators.js +9 -0
  83. package/dist/core/Shaping.d.ts +40 -0
  84. package/dist/core/Shaping.js +224 -0
  85. package/dist/core/SkiaControl.d.ts +284 -11
  86. package/dist/core/SkiaControl.js +630 -66
  87. package/dist/core/SkiaEffect.d.ts +17 -0
  88. package/dist/core/SkiaEffect.js +43 -8
  89. package/dist/core/SkiaImageManager.js +1 -1
  90. package/dist/core/Super.d.ts +29 -2
  91. package/dist/core/Super.js +54 -3
  92. package/dist/core/Tooltips.d.ts +71 -0
  93. package/dist/core/Tooltips.js +205 -0
  94. package/dist/core/Types.d.ts +11 -1
  95. package/dist/core/Types.js +32 -1
  96. package/dist/core/ViewsAdapter.d.ts +7 -2
  97. package/dist/core/ViewsAdapter.js +10 -3
  98. package/dist/index.d.ts +7 -0
  99. package/dist/index.js +7 -0
  100. package/dist/react/SkiaShell.js +65 -26
  101. package/dist/react/index.d.ts +51 -4
  102. package/dist/react/index.js +180 -18
  103. package/dist/react/reconciler.d.ts +20 -0
  104. package/dist/react/reconciler.js +69 -14
  105. package/dist/vite/index.d.ts +9 -0
  106. package/dist/vite/index.js +36 -3
  107. package/package.json +66 -2
@@ -1,4 +1,6 @@
1
1
  import { SKRect } from "./Types";
2
+ /** Controls with `AccessibilityModal` set, on every canvas (drawnui-cross 6av). Empty: no modal work at all. */
3
+ export const AccessibilityModals = new Set();
2
4
  /** ARIA role constants (DrawnUi.Models.Aria) for `AccessibilityRole`. */
3
5
  export const Aria = {
4
6
  // interactive widgets
@@ -12,11 +14,33 @@ export const Aria = {
12
14
  RoleSeparator: "separator", RoleProgressBar: "progressbar", RoleTooltip: "tooltip", RoleDialog: "dialog",
13
15
  RoleAlertDialog: "alertdialog", RoleStatus: "status", RoleAlert: "alert", RoleGroup: "group", RoleRegion: "region",
14
16
  RoleNavigation: "navigation", RoleMain: "main",
17
+ // containers of items: with one of these roles a layout is an arrow-key group (IsCompositeRole)
18
+ RoleGrid: "grid", RoleToolbar: "toolbar", RoleRadioGroup: "radiogroup", RoleMenuBar: "menubar",
15
19
  /** Removes the control from the accessibility tree even when a default role would apply (inner label of a button). */
16
20
  RolePresentation: "presentation",
17
21
  // live regions
18
22
  LivePolite: "polite", LiveAssertive: "assertive",
23
+ /**
24
+ * Container roles whose items the arrow keys walk (C# Aria.IsCompositeRole): a layout with one of them is one Tab stop,
25
+ * its current item, and the arrow keys move between its items.
26
+ */
27
+ IsCompositeRole(role) {
28
+ return role === "list" || role === "listbox" || role === "grid" || role === "toolbar" || role === "radiogroup"
29
+ || role === "tablist" || role === "menu" || role === "menubar";
30
+ },
31
+ /**
32
+ * Roles a user operates (C# Aria.IsInteractiveRole, as DrawnUi.Rust is_control_role): a node with one of them that
33
+ * cannot take input is read as disabled (aria-disabled). C# also lists listbox and scrollbar; here a listbox is an
34
+ * arrow-key group and groups are never disabled.
35
+ */
36
+ IsInteractiveRole(role) {
37
+ return role === "button" || role === "link" || role === "checkbox" || role === "radio" || role === "switch"
38
+ || role === "slider" || role === "spinbutton" || role === "textbox" || role === "searchbox" || role === "combobox"
39
+ || role === "option" || role === "tab" || role === "menuitem" || role === "menuitemcheckbox" || role === "menuitemradio";
40
+ },
19
41
  };
42
+ const asLayout = (c) => ("ChildrenFactory" in c && "Split" in c ? c : undefined);
43
+ const asScroll = (c) => ("ScrollToIndex" in c && "ViewportOffsetY" in c ? c : undefined);
20
44
  /**
21
45
  * Mirrors DrawnUi SkiaAccessibilityManager: registry of accessible controls + a rate-limited snapshot
22
46
  * (at most one rebuild per MinUpdateIntervalMs, taken at frame end) that the DOM overlay renders.
@@ -30,6 +54,7 @@ export class SkiaAccessibilityManager {
30
54
  pending = 0;
31
55
  changed = new Set();
32
56
  liveUpdated = new Set();
57
+ keyboardFocusRequested = new Set();
33
58
  /** Minimum milliseconds between snapshot rebuilds. */
34
59
  MinUpdateIntervalMs = 1000;
35
60
  Snapshot = [];
@@ -38,8 +63,376 @@ export class SkiaAccessibilityManager {
38
63
  OnChanged(cb) { this.changed.add(cb); return () => this.changed.delete(cb); }
39
64
  /** Fired immediately (bypassing the rate limit) when a live-region node's value changes. */
40
65
  OnLiveRegionUpdated(cb) { this.liveUpdated.add(cb); return () => this.liveUpdated.delete(cb); }
41
- NotifyFocused(node) { if (this.FocusedNode !== node)
42
- this.FocusedNode = node; }
66
+ /**
67
+ * Keyboard focus moved by the manager itself (arrow keys in a group): the overlay moves DOM focus to that node's
68
+ * element (C# KeyboardFocusRequested). Returns the unsubscribe function.
69
+ */
70
+ OnKeyboardFocusRequested(cb) { this.keyboardFocusRequested.add(cb); return () => this.keyboardFocusRequested.delete(cb); }
71
+ NotifyFocused(node) {
72
+ if (this.FocusedNode === node)
73
+ return;
74
+ this.NoteFocus(node);
75
+ this.FocusedNode = node;
76
+ }
77
+ /**
78
+ * Enter / Space from keyboard navigation or a screen reader: activates the node only while a tap could reach it
79
+ * (AccessibilityCanInteract), the rule every head applies.
80
+ */
81
+ static Activate(node) {
82
+ if (!node || !node.AccessibilityCanInteract)
83
+ return false;
84
+ node.OnAccessibilityActivated();
85
+ node.Superview?.AccessibilityManager.ForceRebuildOnNextFrame(); // a screen reader reads the new state right back
86
+ return true;
87
+ }
88
+ /**
89
+ * Arrow keys, Home / End, PageUp / PageDown for the node in keyboard focus: the control gets them first, only while a
90
+ * pan could reach it (a slider steps its value); keys it does not use move keyboard focus between the items of the
91
+ * group around it (MoveInGroup). True when the key was used.
92
+ */
93
+ static Key(node, key) {
94
+ if (!node)
95
+ return false;
96
+ if (node.CanReceiveGesture("Panning") && node.OnAccessibilityKey(key)) {
97
+ node.Superview?.AccessibilityManager.ForceRebuildOnNextFrame(); // the new value is read right back, not a second later
98
+ return true;
99
+ }
100
+ return node.Superview?.AccessibilityManager.MoveInGroup(node, key) ?? false;
101
+ }
102
+ // ---- arrow-key groups (C# SkiaAccessibilityManager, "Arrow-key groups") ----
103
+ /** Last focused node of each group: where Tab enters the group. */
104
+ groupFocus = new WeakMap();
105
+ groupRequest;
106
+ /**
107
+ * The arrow-key group around `control`: its nearest ancestor with a composite role (Aria.IsCompositeRole, e.g.
108
+ * Aria.RoleList on a SkiaStack), and the item of that group holding the control (one of its children, a cell).
109
+ */
110
+ static TryFindGroup(control) {
111
+ const path = [];
112
+ for (let child = control, parent = control.Parent; parent; child = parent, parent = parent.Parent) {
113
+ path.push(child);
114
+ if (!Aria.IsCompositeRole(parent.AccessibilityRole))
115
+ continue;
116
+ // drawnui-cross 6ao: the role may sit on a wrapper (a menu shape around a column of lines); the items are the
117
+ // children of the control that holds them, found down the path through single children that are not nodes
118
+ let holder = parent, k = path.length - 1;
119
+ while (k > 0 && ViewsOf(holder).length === 1 && !IsInteractiveNode(path[k])) {
120
+ holder = path[k];
121
+ k--;
122
+ }
123
+ return { Group: parent, Item: path[k], Holder: holder };
124
+ }
125
+ return undefined;
126
+ }
127
+ /** Remembers where keyboard focus is inside its group, so the next Tab into the group lands there. */
128
+ NoteFocus(node) {
129
+ const found = node && SkiaAccessibilityManager.TryFindGroup(node);
130
+ if (found)
131
+ this.groupFocus.set(found.Group, node);
132
+ }
133
+ /**
134
+ * Whether Tab / Shift+Tab stop on this node. A group of items is one Tab stop, like a native list: its current item
135
+ * (the one keyboard focus last had there, else the group's first usable node) plus the controls inside that same
136
+ * item; the arrow keys move between items. Every node outside a group is a stop.
137
+ */
138
+ IsTabStop(node) {
139
+ // an open popup window keeps the keyboard: Tab never leaves it, as with native menus
140
+ const scope = this.KeyboardScope;
141
+ if (scope) {
142
+ let c = node;
143
+ while (c && c !== scope)
144
+ c = c.Parent;
145
+ if (!c)
146
+ return false;
147
+ }
148
+ const found = SkiaAccessibilityManager.TryFindGroup(node);
149
+ if (!found)
150
+ return true;
151
+ let stopItem;
152
+ const remembered = this.groupFocus.get(found.Group);
153
+ const current = remembered && !remembered.IsDisposed && remembered.AccessibilityCanInteract && this.Snapshot.some((n) => n.Source === remembered)
154
+ ? SkiaAccessibilityManager.TryFindGroup(remembered) : undefined;
155
+ if (current && current.Group === found.Group)
156
+ stopItem = current.Item;
157
+ else {
158
+ for (const n of this.Snapshot) {
159
+ if (!n.Source.AccessibilityCanInteract)
160
+ continue;
161
+ const g = SkiaAccessibilityManager.TryFindGroup(n.Source);
162
+ if (g && g.Group === found.Group) {
163
+ stopItem = g.Item;
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ return !stopItem || stopItem === found.Item;
169
+ }
170
+ /**
171
+ * Moves keyboard focus between the items of the group around `focused`, by item index like a native list: Down / Up in
172
+ * 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
173
+ * first / last item, PageDown / PageUp by one viewport of the scroll around it. The ends stop the arrows, unless the group has KeyboardWrap. The target is the
174
+ * item itself when it is an interactive node, else its first interactive node; items the pointer cannot use are
175
+ * skipped. An item not realized (recycled cells) is scrolled in with ScrollToIndex when the group is the scroll's
176
+ * content, and focused once drawn. True when the key belongs to the group.
177
+ */
178
+ MoveInGroup(focused, key) {
179
+ const found = SkiaAccessibilityManager.TryFindGroup(focused);
180
+ if (!found)
181
+ return false;
182
+ const { Holder: group, Item: item } = found;
183
+ // a menu, list or radio group whose items are not the children of one layout (a panel with a title, a divider and
184
+ // columns of items): its items in reading order, one after another (drawnui-cross 6ao rule 1b, as DrawnUi.Rust)
185
+ const role = found.Group.AccessibilityRole;
186
+ const linear = role === Aria.RoleMenu || role === Aria.RoleMenuBar || role === Aria.RoleList || role === Aria.RoleListBox || role === Aria.RoleRadioGroup;
187
+ const holdsMany = (child) => this.Snapshot.filter((n) => n.CanInteract && IsInside(n.Source, child)).length > 1;
188
+ if (linear && item !== focused && ViewsOf(group).some(holdsMany)) {
189
+ const items = this.Snapshot.filter((n) => n.CanInteract && SkiaAccessibilityManager.TryFindGroup(n.Source)?.Group === found.Group).map((n) => n.Source);
190
+ const current = items.indexOf(focused);
191
+ if (current < 0)
192
+ return false;
193
+ const n = items.length, wrap = found.Group.KeyboardWrap || group.KeyboardWrap;
194
+ const target = key === "ArrowDown" || key === "ArrowRight" ? (wrap ? (current + 1) % n : Math.min(current + 1, n - 1))
195
+ : key === "ArrowUp" || key === "ArrowLeft" ? (wrap ? (current - 1 + n) % n : Math.max(current - 1, 0))
196
+ : key === "Home" ? 0 : key === "End" ? n - 1 : -1;
197
+ if (target < 0)
198
+ return false;
199
+ if (target !== current) {
200
+ this.RequestKeyboardFocus(items[target]);
201
+ found.Group.Superview?.Update();
202
+ }
203
+ return true;
204
+ }
205
+ const scroll = FindScroll(group), axis = AxisOf(group), count = ItemCount(group);
206
+ const current = this.groupRequest?.Group === group ? this.groupRequest.Index : IndexOf(group, item);
207
+ if (current < 0 || count < 1)
208
+ return false;
209
+ const row = axis === "Both" ? RowLength(group) : 1;
210
+ const vertical = axis !== "Horizontal";
211
+ const page = () => PageSize(scroll, item, vertical) * row;
212
+ let target, step;
213
+ const layout = asLayout(group), masonry = layout?.Type === "Masonry" ? MasonryTarget(layout, current, key, scroll) : undefined;
214
+ if (masonry !== undefined) {
215
+ target = masonry;
216
+ step = key === "ArrowDown" || key === "ArrowRight" || key === "PageDown" ? 1 : -1;
217
+ }
218
+ else if ((key === "ArrowDown" && axis === "Vertical") || (key === "ArrowRight" && axis !== "Vertical")) {
219
+ target = current + 1;
220
+ step = 1;
221
+ }
222
+ else if ((key === "ArrowUp" && axis === "Vertical") || (key === "ArrowLeft" && axis !== "Vertical")) {
223
+ target = current - 1;
224
+ step = -1;
225
+ }
226
+ else if (key === "ArrowDown" && axis === "Both") {
227
+ target = Math.min(count - 1, current + row);
228
+ step = 1;
229
+ }
230
+ else if (key === "ArrowUp" && axis === "Both") {
231
+ target = Math.max(0, current - row);
232
+ step = -1;
233
+ }
234
+ else if (key === "Home") {
235
+ target = 0;
236
+ step = 1;
237
+ }
238
+ else if (key === "End") {
239
+ target = count - 1;
240
+ step = -1;
241
+ }
242
+ else if (key === "PageDown" && scroll) {
243
+ target = Math.min(count - 1, current + page());
244
+ step = 1;
245
+ }
246
+ else if (key === "PageUp" && scroll) {
247
+ target = Math.max(0, current - page());
248
+ step = -1;
249
+ }
250
+ else
251
+ return false;
252
+ // KeyboardWrap on the group: the arrows go round, the last item to the first and back
253
+ if ((target < 0 || target >= count) && key.startsWith("Arrow") && (found.Group.KeyboardWrap || group.KeyboardWrap))
254
+ target = target < 0 ? count - 1 : 0;
255
+ if (target < 0 || target >= count || target === current)
256
+ return true; // at the end of the group nothing happens, the key still belongs to it
257
+ this.groupRequest = { Group: group, Scroll: scroll, Index: target, Step: step, Deadline: performance.now() + 3000, ScrollIssued: false };
258
+ group.Superview?.Update(); // resolved at the end of the next frame, together with the snapshot
259
+ return true;
260
+ }
261
+ // ---- keyboard focus moved by popup windows (drawnui-cross 6ao rule 2, and back to the opener on close) ----
262
+ focusRequest;
263
+ popupFocusRoot;
264
+ focusAnyInside = false;
265
+ /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
266
+ RequestKeyboardFocus(control) { if (!this.appFocusThisFrame)
267
+ this.focusRequest = control; }
268
+ appFocus;
269
+ appFocusDeadline = 0;
270
+ appFocusThisFrame = false; // until the frame end: the app said where the focus goes, the library's moves give way
271
+ clearFocusRequest = false;
272
+ /**
273
+ * App code moves the keyboard and screen-reader focus at the end of the next frame (C# DrawnView.SetAccessibilityFocus,
274
+ * Rust `Cx::set_accessibility_focus`), for a custom menu that moves its highlight: to `control`, which gets it once
275
+ * drawn, within 3 seconds. It wins over the library's own moves in the same frame (a group's arrow move, a closed popup
276
+ * window giving the keyboard back to its opener); undefined cancels a move still waiting, the focus stays where it is.
277
+ * The focus ring shows only if the keyboard is in use (the browser's focus-visible).
278
+ */
279
+ SetAccessibilityFocus(control) {
280
+ this.appFocusThisFrame = true;
281
+ this.focusRequest = undefined;
282
+ this.groupRequest = undefined;
283
+ this.appFocus = control;
284
+ this.appFocusDeadline = performance.now() + 3000;
285
+ control?.Superview?.Update();
286
+ }
287
+ /**
288
+ * No drawn control keeps the keyboard and screen-reader focus (C# KeyboardFocusNode = null): at the end of the next
289
+ * frame the DOM focus goes back to the canvas and the keys belong to the app again.
290
+ */
291
+ ClearKeyboardFocus() { this.appFocus = undefined; this.clearFocusRequest = true; }
292
+ ProcessAppFocus(scale, w, h, requestFrame) {
293
+ const wanted = this.appFocus;
294
+ if (wanted.IsDisposed || performance.now() > this.appFocusDeadline) {
295
+ this.appFocus = undefined;
296
+ return;
297
+ }
298
+ this.Rebuild(scale, w, h);
299
+ if (!this.Snapshot.some((n) => n.Source === wanted)) {
300
+ requestFrame();
301
+ return;
302
+ } // not drawn yet: look again next frame
303
+ this.appFocus = undefined;
304
+ this.Focus(wanted);
305
+ }
306
+ popupScope;
307
+ /**
308
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them: the top
309
+ * popup window that takes input (a menu, a dropdown; set by the canvas), else the active modal.
310
+ */
311
+ get KeyboardScope() { return this.popupScope ?? this.ActiveModal; }
312
+ set KeyboardScope(v) { this.popupScope = v; }
313
+ // ---- modal accessibility scope (drawnui-cross 6av, C# AccessibilityModal) ----
314
+ /** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
315
+ ActiveModal;
316
+ // where the keyboard was when each modal became active, to go back there when it goes
317
+ modalReturns = new Map();
318
+ /** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
319
+ IsOutsideModal(control) {
320
+ const modal = this.ActiveModal;
321
+ return !!modal && !IsInside(control, modal) && TopRoot(control) === TopRoot(modal);
322
+ }
323
+ /** Frame end, only while some control is flagged modal or one was active: follows the top modal. */
324
+ UpdateActiveModal() {
325
+ let next;
326
+ for (const m of AccessibilityModals) {
327
+ if (m.IsDisposed || !m.IsVisible || m.Opacity <= 0 || AccessibilityManagerHiddenByAncestor(m)
328
+ || m.Superview?.AccessibilityManager !== this || !IsDrawn(m))
329
+ continue;
330
+ if (!next || IsDrawnAbove(m, next))
331
+ next = m;
332
+ }
333
+ const previous = this.ActiveModal;
334
+ if (previous === next)
335
+ return;
336
+ this.ActiveModal = next;
337
+ this.ForceRebuildOnNextFrame(); // readers and Tab switch to the new scope in this frame
338
+ const keyboard = this.FocusedNode;
339
+ if (next && keyboard && !IsInside(keyboard, next)) {
340
+ // the keyboard is in use: into the modal, and back here when it goes
341
+ this.modalReturns.set(next, keyboard);
342
+ this.popupFocusRoot = next;
343
+ this.focusAnyInside = true;
344
+ }
345
+ const back = previous && this.modalReturns.get(previous);
346
+ if (previous)
347
+ this.modalReturns.delete(previous);
348
+ // back unless the keyboard went elsewhere meanwhile; a keyboard node that left with the modal (disposed, detached) was in it
349
+ const leftWithIt = !!keyboard && (keyboard.IsDisposed || !keyboard.Superview);
350
+ if (back && (!keyboard || leftWithIt || IsInside(keyboard, previous)) && (!next || IsInside(back, next)))
351
+ this.RequestKeyboardFocus(back);
352
+ }
353
+ /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
354
+ NextTabStop(from, forward) {
355
+ const stops = this.Snapshot.filter((n) => n.CanInteract && this.IsTabStop(n.Source)).map((n) => n.Source);
356
+ if (stops.length === 0)
357
+ return undefined;
358
+ let current = from ? stops.indexOf(from) : -1;
359
+ if (current < 0)
360
+ current = forward ? -1 : stops.length;
361
+ const next = forward ? current + 1 : current - 1;
362
+ if (this.KeyboardScope)
363
+ return stops[(next + stops.length) % stops.length];
364
+ return next >= 0 && next < stops.length ? stops[next] : undefined;
365
+ }
366
+ /**
367
+ * A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
368
+ * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
369
+ */
370
+ FocusOpenedPopup(root) { this.popupFocusRoot = root; this.focusAnyInside = false; }
371
+ ProcessFocusRequests(scale, w, h) {
372
+ const request = this.focusRequest, root = this.popupFocusRoot;
373
+ this.focusRequest = this.popupFocusRoot = undefined;
374
+ if (root && !root.IsDisposed && root.Superview) {
375
+ this.Rebuild(scale, w, h);
376
+ const inside = (c) => { for (let p = c; p; p = p.Parent)
377
+ if (p === root)
378
+ return true; return false; };
379
+ const choice = (role) => role === Aria.RoleRadio || role === Aria.RoleMenuItemRadio || role === "option" || role === "tab";
380
+ // a popup: the items of its arrow-key group; a modal: its first control that takes input
381
+ const items = this.Snapshot.filter((n) => n.CanInteract && inside(n.Source) && (this.focusAnyInside || SkiaAccessibilityManager.TryFindGroup(n.Source)));
382
+ const target = items.find((n) => n.IsPressed === true && choice(n.Role)) ?? items[0];
383
+ if (target) {
384
+ this.FocusFromKeyboard(target.Source, scale, w, h);
385
+ return;
386
+ }
387
+ }
388
+ if (request && !request.IsDisposed && request.Superview && request.AccessibilityCanInteract)
389
+ this.FocusFromKeyboard(request, scale, w, h);
390
+ }
391
+ /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
392
+ ProcessGroupFocus(scale, w, h, requestFrame) {
393
+ const request = this.groupRequest;
394
+ if (!request)
395
+ return;
396
+ const cell = ItemAt(request.Group, request.Index);
397
+ if (cell && IsDrawn(cell)) {
398
+ const node = FindTarget(cell);
399
+ if (node) {
400
+ this.groupRequest = undefined;
401
+ this.FocusFromKeyboard(node, scale, w, h);
402
+ return;
403
+ }
404
+ // this item cannot take input: go on to the next one in the same direction
405
+ request.Index += request.Step;
406
+ if (request.Index < 0 || request.Index >= ItemCount(request.Group)) {
407
+ this.groupRequest = undefined;
408
+ return;
409
+ }
410
+ request.Deadline = performance.now() + 3000;
411
+ request.ScrollIssued = false;
412
+ }
413
+ else if (performance.now() > request.Deadline || request.Group.IsDisposed) {
414
+ this.groupRequest = undefined;
415
+ return;
416
+ }
417
+ if (!request.ScrollIssued) {
418
+ request.ScrollIssued = true;
419
+ const next = ItemAt(request.Group, request.Index);
420
+ if ((!next || !IsDrawn(next)) && request.Scroll && request.Scroll.Content === request.Group) {
421
+ request.Scroll.ScrollToIndex(request.Index, true, request.Step > 0 ? "End" : "Start");
422
+ }
423
+ }
424
+ requestFrame(); // keep frames coming until the item is drawn
425
+ }
426
+ FocusFromKeyboard(node, scale, w, h) {
427
+ this.Rebuild(scale, w, h); // the overlay looks the node up in the snapshot: make sure it is there now
428
+ this.Focus(node);
429
+ }
430
+ Focus(node) {
431
+ this.NoteFocus(node);
432
+ this.FocusedNode = node;
433
+ for (const cb of this.keyboardFocusRequested)
434
+ cb(node);
435
+ }
43
436
  Register(node) { this.nodes.add(node); this.dirty = true; }
44
437
  NotifyUpdated(node) {
45
438
  if (!this.nodes.has(node))
@@ -49,7 +442,15 @@ export class SkiaAccessibilityManager {
49
442
  for (const cb of this.liveUpdated)
50
443
  cb(node);
51
444
  }
52
- ForceRebuildOnNextFrame() { this.lastRebuild = 0; this.dirty = true; }
445
+ /** What the last snapshot says for each live region, to rebuild on the next frame when that changes. */
446
+ liveSaid = new Map();
447
+ LiveChanged() {
448
+ for (const [control, said] of this.liveSaid)
449
+ if (!control.IsDisposed && (control.AccessibilityLabel ?? "") !== said)
450
+ return true;
451
+ return false;
452
+ }
453
+ ForceRebuildOnNextFrame() { this.lastRebuild = -Infinity; this.dirty = true; }
53
454
  Unregister(node) {
54
455
  if (this.nodes.delete(node)) {
55
456
  node.OnAccessibilityUnregistered();
@@ -70,19 +471,42 @@ export class SkiaAccessibilityManager {
70
471
  * per MinUpdateIntervalMs otherwise (keeps rects in sync with scrolling); notifies only when the snapshot differs.
71
472
  */
72
473
  OnFrameEnd(scale, canvasWidthPx, canvasHeightPx, requestFrame) {
474
+ if (AccessibilityModals.size > 0 || this.ActiveModal)
475
+ this.UpdateActiveModal();
476
+ this.ProcessGroupFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
477
+ if (this.clearFocusRequest) {
478
+ this.clearFocusRequest = false;
479
+ this.FocusedNode = undefined;
480
+ for (const cb of this.keyboardFocusRequested)
481
+ cb(undefined);
482
+ }
483
+ if (this.appFocus)
484
+ this.ProcessAppFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
485
+ if (this.focusRequest || this.popupFocusRoot)
486
+ this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
487
+ this.appFocusThisFrame = false;
73
488
  if (this.nodes.size === 0 && this.Snapshot.length === 0)
74
489
  return;
75
490
  const now = performance.now();
76
491
  const wait = this.MinUpdateIntervalMs - (now - this.lastRebuild);
492
+ // a live region whose text changed is read on the next frame, not at the next timed rebuild (accessibility-plan B2)
493
+ if (wait > 0 && this.liveSaid.size > 0 && this.LiveChanged()) {
494
+ this.Rebuild(scale, canvasWidthPx, canvasHeightPx);
495
+ return;
496
+ }
77
497
  if (wait > 0) {
78
498
  // rate-limited: rendering is on demand, so make sure a frame comes back once the interval has passed
79
499
  if (!this.pending)
80
500
  this.pending = window.setTimeout(() => { this.pending = 0; requestFrame(); }, wait);
81
501
  return;
82
502
  }
503
+ this.Rebuild(scale, canvasWidthPx, canvasHeightPx);
504
+ }
505
+ Rebuild(scale, canvasWidthPx, canvasHeightPx) {
83
506
  this.dirty = false;
84
- this.lastRebuild = now;
85
- const list = [];
507
+ this.lastRebuild = performance.now();
508
+ let list = [];
509
+ const modal = this.ActiveModal;
86
510
  for (const n of this.nodes) {
87
511
  if (!n.Superview) {
88
512
  this.nodes.delete(n);
@@ -91,6 +515,8 @@ export class SkiaAccessibilityManager {
91
515
  } // detached from the tree
92
516
  if (!n.IsVisible || !n.IsAccessibilityElement || n.AccessibilityRole === Aria.RolePresentation)
93
517
  continue;
518
+ if (modal && this.IsOutsideModal(n))
519
+ continue; // a modal is shown: only its nodes, and those of popup windows over it
94
520
  if (AccessibilityManagerHiddenByAncestor(n))
95
521
  continue; // e.g. the root page kept mounted under a pushed shell page
96
522
  const px = n.GetAccessibilityPixelRect();
@@ -101,13 +527,35 @@ export class SkiaAccessibilityManager {
101
527
  if (px.Right < -canvasWidthPx || px.Bottom < -canvasHeightPx || px.Left > 2 * canvasWidthPx || px.Top > 2 * canvasHeightPx)
102
528
  continue;
103
529
  list.push({
104
- Id: n.AccessibilityId, Label: n.AccessibilityLabel, Hint: n.AccessibilityHint, Role: n.AccessibilityRole,
530
+ Id: n.AccessibilityId, Label: n.AccessibilityLabel, Hint: n.AccessibilityHint, Role: n.AccessibilityRole, Value: n.AccessibilityValue,
105
531
  Rect: new SKRect(px.Left / scale, px.Top / scale, px.Right / scale, px.Bottom / scale),
106
- CanInteract: n.AccessibilityCanInteract, IsPressed: n.AccessibilityIsPressed, Live: n.AccessibilityLive, Source: n,
532
+ CanInteract: n.AccessibilityCanInteract, IsPressed: n.AccessibilityIsPressed, Expanded: n.AccessibilityExpanded, Live: n.AccessibilityLive, Source: n,
533
+ Disabled: !n.AccessibilityCanInteract && Aria.IsInteractiveRole(n.AccessibilityRole),
107
534
  TextLines: n.AccessibilityTextSelectable ? n.GetAccessibilityTextLines(scale) : undefined,
108
535
  });
109
536
  }
537
+ list = SayNamesOnce(list);
110
538
  list.sort((a, b) => a.Rect.Top - b.Rect.Top || a.Rect.Left - b.Rect.Left);
539
+ // reading order: nodes whose tops are within half the smaller height form one row, read left to right, so a row of
540
+ // vertically centered controls of different heights keeps its visual order (C# RectComparer + LeftComparer)
541
+ for (let start = 0, i = 1; i <= list.length; i++) {
542
+ if (i < list.length) {
543
+ const first = list[start].Rect, next = list[i].Rect;
544
+ if (next.Top - first.Top < Math.min(first.Height, next.Height) / 2)
545
+ continue;
546
+ }
547
+ if (i - start > 1) {
548
+ const row = list.slice(start, i).sort((a, b) => a.Rect.Left - b.Rect.Left);
549
+ for (let k = 0; k < row.length; k++)
550
+ list[start + k] = row[k];
551
+ }
552
+ start = i;
553
+ }
554
+ this.liveSaid.clear();
555
+ // the control's own name (a name given to a child that says it is no change)
556
+ for (const n of list)
557
+ if (n.Live)
558
+ this.liveSaid.set(n.Source, n.Source.AccessibilityLabel ?? "");
111
559
  if (SkiaAccessibilityManager.Same(list, this.Snapshot))
112
560
  return;
113
561
  this.Snapshot = list;
@@ -119,8 +567,8 @@ export class SkiaAccessibilityManager {
119
567
  return false;
120
568
  for (let i = 0; i < a.length; i++) {
121
569
  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
570
+ 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
571
+ || x.IsPressed !== y.IsPressed || x.Expanded !== y.Expanded || x.Live !== y.Live || !SameValue(x.Value, y.Value)
124
572
  || Math.abs(x.Rect.Left - y.Rect.Left) > 0.5 || Math.abs(x.Rect.Top - y.Rect.Top) > 0.5
125
573
  || Math.abs(x.Rect.Right - y.Rect.Right) > 0.5 || Math.abs(x.Rect.Bottom - y.Rect.Bottom) > 0.5)
126
574
  return false;
@@ -138,6 +586,224 @@ export class SkiaAccessibilityManager {
138
586
  return true;
139
587
  }
140
588
  }
589
+ /**
590
+ * Each name is said once in the flat overlay (DrawnUi.Rust said_by_child): a text or a heading whose label repeats the
591
+ * label of the node it is in (its nearest ancestor node) is said by one of them. Under an interactive node (a card
592
+ * button) the child is left out, the button keeps its name; under any other node (a group card and its title) the
593
+ * node loses its name and the heading says it. Selectable text (TextLines) always stays.
594
+ */
595
+ function SayNamesOnce(list) {
596
+ const bySource = new Map(list.map((x) => [x.Source, x]));
597
+ const said = new Set();
598
+ for (const x of list) {
599
+ if (!x.Label || x.TextLines || (x.Role !== Aria.RoleText && x.Role !== Aria.RoleHeading))
600
+ continue;
601
+ let owner;
602
+ for (let p = x.Source.Parent; p && !owner; p = p.Parent)
603
+ owner = bySource.get(p);
604
+ if (!owner || owner.Label !== x.Label)
605
+ continue;
606
+ // a dialog keeps its name though its title says it too: readers announce the dialog by name on entry
607
+ if (owner.Role === Aria.RoleDialog || owner.Role === Aria.RoleAlertDialog)
608
+ continue;
609
+ if (owner.CanInteract)
610
+ said.add(x);
611
+ else
612
+ owner.Label = undefined;
613
+ }
614
+ return said.size ? list.filter((x) => !said.has(x)) : list;
615
+ }
616
+ function SameValue(a, b) {
617
+ 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);
618
+ }
619
+ // ---- group helpers (duck-typed layouts and scrolls) ----
620
+ function IsInside(control, root) {
621
+ for (let c = control; c; c = c.Parent)
622
+ if (c === root)
623
+ return true;
624
+ return false;
625
+ }
626
+ /** The top of the tree a control is in: the canvas content, or a popup window's root. */
627
+ function TopRoot(control) {
628
+ let c = control;
629
+ while (c.Parent)
630
+ c = c.Parent;
631
+ return c;
632
+ }
633
+ /** Drawing order: `a` draws over `b` (ZIndex, then tree order; a nested control over its ancestor). */
634
+ function IsDrawnAbove(a, b) {
635
+ const path = (c) => { const p = []; for (let x = c; x; x = x.Parent)
636
+ p.unshift(x); return p; };
637
+ const pa = path(a), pb = path(b);
638
+ let i = 0;
639
+ while (i < pa.length && i < pb.length && pa[i] === pb[i])
640
+ i++;
641
+ if (i === pa.length)
642
+ return false; // a contains b
643
+ if (i === pb.length)
644
+ return true; // b contains a
645
+ if (i === 0)
646
+ return false; // different trees (a popup window): the first one found stays
647
+ const sa = pa[i], sb = pb[i];
648
+ if (sa.ZIndex !== sb.ZIndex)
649
+ return sa.ZIndex > sb.ZIndex;
650
+ const views = ViewsOf(sa.Parent);
651
+ return views.indexOf(sa) > views.indexOf(sb);
652
+ }
653
+ /** A node the keyboard can land on: a role that is not presentation and takes input. */
654
+ function IsInteractiveNode(c) {
655
+ return !!c.AccessibilityRole && c.AccessibilityRole !== Aria.RolePresentation && c.IsAccessibilityElement && c.AccessibilityCanInteract;
656
+ }
657
+ /** Children of a control (a layout's Views, a scroll's Content). */
658
+ function ViewsOf(c) {
659
+ if ("Views" in c)
660
+ return c.Views;
661
+ const content = c.Content;
662
+ return content ? [content] : [];
663
+ }
664
+ function FindScroll(group) {
665
+ for (let p = group.Parent; p; p = p.Parent) {
666
+ const s = asScroll(p);
667
+ if (s)
668
+ return s;
669
+ }
670
+ return undefined;
671
+ }
672
+ /** Down / Up in a Column, Right / Left in a Row, all four in a Wrap, a Grid or a Split layout. */
673
+ function AxisOf(group) {
674
+ const l = asLayout(group);
675
+ if (!l)
676
+ return "Vertical";
677
+ if (l.Type === "Column")
678
+ return l.Split <= 1 ? "Vertical" : "Both";
679
+ if (l.Type === "Row")
680
+ return "Horizontal";
681
+ if (l.Type === "Absolute")
682
+ return "Vertical";
683
+ return "Both";
684
+ }
685
+ /** Items per row of a 2D group: Split when set, else the items sharing the row of `item`. */
686
+ /**
687
+ * 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
688
+ * item's row, which the short last row of a wrap leaves short (Up from it skipped items); DrawnUi.Rust afef66f.
689
+ */
690
+ function RowLength(group) {
691
+ const l = asLayout(group);
692
+ if (l && l.Split > 1)
693
+ return l.Split;
694
+ const first = ItemAt(group, 0) ?? FirstRealized(group);
695
+ if (!first)
696
+ return 1;
697
+ const top = first.GetAccessibilityPixelRect();
698
+ if (top.Height <= 0)
699
+ return 1;
700
+ const mid = (top.Top + top.Bottom) / 2;
701
+ let count = 0;
702
+ for (const child of ViewsOf(group)) {
703
+ const r = child.GetAccessibilityPixelRect();
704
+ if (r.Height > 0 && Math.abs((r.Top + r.Bottom) / 2 - mid) < top.Height / 2)
705
+ count++;
706
+ }
707
+ return Math.max(1, count);
708
+ }
709
+ function ItemCount(group) {
710
+ const l = asLayout(group);
711
+ return l?.IsTemplated ? l.ItemsSource?.length ?? 0 : ViewsOf(group).length;
712
+ }
713
+ function IndexOf(group, item) {
714
+ const l = asLayout(group);
715
+ return l?.IsTemplated ? item.ContextIndex : ViewsOf(group).indexOf(item);
716
+ }
717
+ /** The view of an item: the realized cell of a templated layout (none when its cell is not in use), else the child. */
718
+ function ItemAt(group, index) {
719
+ const l = asLayout(group);
720
+ if (l?.IsTemplated) {
721
+ const v = l.ChildrenFactory.GetViewForIndex(index);
722
+ return v && v.ContextIndex === index ? v : undefined;
723
+ }
724
+ return index >= 0 && index < ViewsOf(group).length ? ViewsOf(group)[index] : undefined;
725
+ }
726
+ /** The realized item with the lowest index (item 0 of a scrolled recycled group may not be realized). */
727
+ function FirstRealized(group) {
728
+ let best;
729
+ for (const v of ViewsOf(group))
730
+ if (!best || IndexOf(group, v) < IndexOf(group, best))
731
+ best = v;
732
+ return best;
733
+ }
734
+ /** Arranged on the canvas: realized and laid out (a templated layout keeps only the cells it draws in use). */
735
+ function IsDrawn(control) {
736
+ const r = control.GetAccessibilityPixelRect();
737
+ return !!control.Superview && r.Width > 0 && r.Height > 0;
738
+ }
739
+ /** Items per viewport of the scroll around the group. */
740
+ /**
741
+ * C# MasonryTarget (2ad608d1): the target of an arrow or page key in a Masonry group, from the placed items. Up / Down go
742
+ * to the previous / next item of the same column, Left / Right to the item of the neighbour column nearest in height,
743
+ * PageUp / PageDown up to one viewport along the column (else the next / previous item of the column). `current` when
744
+ * there is no item that way; undefined for other keys or no placement (the generic rules apply).
745
+ */
746
+ function MasonryTarget(layout, current, key, scroll) {
747
+ if (key !== "ArrowDown" && key !== "ArrowUp" && key !== "ArrowLeft" && key !== "ArrowRight" && key !== "PageDown" && key !== "PageUp")
748
+ return undefined;
749
+ const cells = layout.GetMasonryPlacement?.() ?? [];
750
+ const focused = cells.find((c) => c.Index === current);
751
+ if (!focused)
752
+ return undefined;
753
+ const lefts = [...new Set(cells.map((c) => Math.round(c.Rect.Left)))].sort((a, b) => a - b);
754
+ const columnOf = (c) => lefts.indexOf(Math.round(c.Rect.Left));
755
+ const col = columnOf(focused), top = focused.Rect.Top, mid = (focused.Rect.Top + focused.Rect.Bottom) / 2;
756
+ const column = cells.filter((c) => columnOf(c) === col).sort((a, b) => a.Rect.Top - b.Rect.Top);
757
+ const below = column.filter((c) => c.Rect.Top > top), above = column.filter((c) => c.Rect.Top < top);
758
+ const viewport = scroll ? scroll.DrawingRect.Height : 0;
759
+ let found;
760
+ if (key === "ArrowDown")
761
+ found = below[0];
762
+ else if (key === "ArrowUp")
763
+ found = above[above.length - 1];
764
+ else if (key === "ArrowRight" || key === "ArrowLeft") {
765
+ const next = col + (key === "ArrowRight" ? 1 : -1);
766
+ let best = Infinity;
767
+ for (const c of cells) {
768
+ if (columnOf(c) !== next)
769
+ continue;
770
+ const d = Math.abs((c.Rect.Top + c.Rect.Bottom) / 2 - mid);
771
+ if (d < best) {
772
+ best = d;
773
+ found = c;
774
+ }
775
+ }
776
+ }
777
+ else {
778
+ if (!scroll)
779
+ return undefined;
780
+ if (key === "PageDown") {
781
+ const within = below.filter((c) => c.Rect.Top <= top + viewport);
782
+ found = within[within.length - 1] ?? below[0];
783
+ }
784
+ else {
785
+ const within = above.filter((c) => c.Rect.Top >= top - viewport);
786
+ found = within[0] ?? above[above.length - 1];
787
+ }
788
+ }
789
+ return found?.Index ?? current;
790
+ }
791
+ function PageSize(scroll, item, vertical) {
792
+ const v = scroll.DrawingRect, size = item.MeasuredSize.Pixels;
793
+ const viewport = vertical ? v.Height : v.Width, s = vertical ? size.Height : size.Width;
794
+ return s > 0 ? Math.max(1, Math.floor(viewport / s)) : 1;
795
+ }
796
+ /** The item itself when it is an interactive node, else its first interactive node in tree order. */
797
+ function FindTarget(item) {
798
+ if (item.IsAccessibilityElement && item.AccessibilityCanInteract)
799
+ return item;
800
+ for (const child of ViewsOf(item)) {
801
+ const found = FindTarget(child);
802
+ if (found)
803
+ return found;
804
+ }
805
+ return undefined;
806
+ }
141
807
  /** True when any ancestor is hidden (IsVisible false or Opacity 0): the subtree is not drawn, so it gets no nodes. */
142
808
  function AccessibilityManagerHiddenByAncestor(control) {
143
809
  let p = control.Parent;