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

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 (51) hide show
  1. package/README.md +89 -7
  2. package/SKIPPED.md +7 -7
  3. package/dist/controls/GridStructure.d.ts +9 -1
  4. package/dist/controls/GridStructure.js +41 -1
  5. package/dist/controls/SkiaEditor.d.ts +4 -1
  6. package/dist/controls/SkiaEditor.js +25 -6
  7. package/dist/controls/SkiaImage.d.ts +5 -0
  8. package/dist/controls/SkiaImage.js +32 -5
  9. package/dist/controls/SkiaLabel.d.ts +85 -4
  10. package/dist/controls/SkiaLabel.js +406 -20
  11. package/dist/controls/SkiaLabelFps.d.ts +0 -3
  12. package/dist/controls/SkiaLabelFps.js +1 -11
  13. package/dist/controls/SkiaLayout.js +33 -2
  14. package/dist/controls/SkiaScroll.d.ts +51 -2
  15. package/dist/controls/SkiaScroll.js +150 -9
  16. package/dist/controls/SkiaShape.d.ts +2 -0
  17. package/dist/controls/SkiaShape.js +7 -0
  18. package/dist/controls/SkiaShell.d.ts +282 -0
  19. package/dist/controls/SkiaShell.js +972 -0
  20. package/dist/controls/SkiaSprite.js +5 -1
  21. package/dist/core/Accessibility.d.ts +30 -13
  22. package/dist/core/Accessibility.js +237 -43
  23. package/dist/core/Canvas.d.ts +122 -14
  24. package/dist/core/Canvas.js +585 -47
  25. package/dist/core/Gestures.d.ts +11 -1
  26. package/dist/core/Gestures.js +12 -1
  27. package/dist/core/PopupWindows.js +2 -0
  28. package/dist/core/Props.d.ts +11 -0
  29. package/dist/core/Props.js +44 -0
  30. package/dist/core/ScrollAnimators.d.ts +6 -0
  31. package/dist/core/ScrollAnimators.js +7 -1
  32. package/dist/core/SkiaControl.d.ts +24 -4
  33. package/dist/core/SkiaControl.js +59 -13
  34. package/dist/core/SkiaEffect.d.ts +12 -1
  35. package/dist/core/SkiaEffect.js +35 -8
  36. package/dist/core/SkiaImageManager.d.ts +101 -18
  37. package/dist/core/SkiaImageManager.js +318 -63
  38. package/dist/core/Styles.js +7 -1
  39. package/dist/core/Super.d.ts +4 -0
  40. package/dist/core/Super.js +4 -9
  41. package/dist/core/TextInputProxy.d.ts +31 -1
  42. package/dist/core/TextInputProxy.js +97 -15
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.js +1 -0
  45. package/dist/react/SkiaShell.d.ts +8 -74
  46. package/dist/react/SkiaShell.js +163 -514
  47. package/dist/react/index.d.ts +6 -1
  48. package/dist/react/index.js +51 -40
  49. package/dist/react/reconciler.d.ts +12 -0
  50. package/dist/react/reconciler.js +22 -46
  51. package/package.json +37 -4
@@ -121,7 +121,11 @@ export class SkiaSprite extends AnimatedFramesRenderer {
121
121
  const cached = SkiaSprite.CachedSpriteSheets.get(source);
122
122
  if (cached)
123
123
  return cached;
124
- const image = await SkiaImageManager.Instance.LoadImageAsync(source);
124
+ const image = await SkiaImageManager.Instance.LoadImageManagedAsync(source);
125
+ if (!image)
126
+ throw new Error(`DrawnUi: cannot load sprite sheet '${source}'`);
127
+ // the sheets cache holds it for good (the image manager never deletes an image somebody holds)
128
+ SkiaImageManager.Instance.Hold(image);
125
129
  SkiaSprite.CachedSpriteSheets.set(source, image);
126
130
  return image;
127
131
  }
@@ -61,17 +61,6 @@ export declare const Aria: {
61
61
  */
62
62
  readonly IsInteractiveRole: (role?: string) => boolean;
63
63
  };
64
- /** One laid-out text line exposed for native selection (AccessibilityTextSelectable): CSS px relative to the node. */
65
- export interface AccessibilityTextLine {
66
- Text: string;
67
- Left: number;
68
- Top: number;
69
- Width: number;
70
- Height: number;
71
- FontFamily: string;
72
- FontWeight: number;
73
- FontSize: number;
74
- }
75
64
  /**
76
65
  * The value of a range control (a slider, a progress bar): what a screen reader reads and adjusts (drawnui-cross 6c,
77
66
  * C# AccessibilityValue): aria-valuenow / min / max, and aria-valuetext when Text is not empty ("65%", "20 – 80").
@@ -100,8 +89,6 @@ export interface AccessibilityNode {
100
89
  Source: SkiaControl;
101
90
  /** A range control's value (aria-valuenow / min / max / valuetext); its name stays the app's label. */
102
91
  Value?: AccessibilityValue;
103
- /** Real text lines rendered into the overlay so the browser can select / copy them (opt-in per control). */
104
- TextLines?: AccessibilityTextLine[];
105
92
  }
106
93
  /**
107
94
  * Mirrors DrawnUi SkiaAccessibilityManager: registry of accessible controls + a rate-limited snapshot
@@ -174,8 +161,15 @@ export declare class SkiaAccessibilityManager {
174
161
  private focusRequest?;
175
162
  private popupFocusRoot?;
176
163
  private focusAnyInside;
164
+ private popupFocusDeadline;
177
165
  /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
178
166
  RequestKeyboardFocus(control: SkiaControl): void;
167
+ /**
168
+ * How long a keyboard focus request waits for its control to take input again (drawnui-cross 6bs): an app that shows
169
+ * the opener of a dialog again only once the dialog is gone (a HUD hidden under it) still gets the keyboard back there.
170
+ */
171
+ static FocusRequestWaitMs: number;
172
+ private focusRequestDeadline;
179
173
  private appFocus?;
180
174
  private appFocusDeadline;
181
175
  private appFocusThisFrame;
@@ -203,6 +197,11 @@ export declare class SkiaAccessibilityManager {
203
197
  set KeyboardScope(v: SkiaControl | undefined);
204
198
  /** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
205
199
  ActiveModal?: SkiaControl;
200
+ /**
201
+ * The node the overlay names the active modal after (drawnui-cross 6bs): the modal's own when it has a name, else the
202
+ * first named dialog inside it, so a nameless popup host around a dialog reads as that one dialog, not as two.
203
+ */
204
+ get ActiveModalNode(): AccessibilityNode | undefined;
206
205
  private readonly modalReturns;
207
206
  /** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
208
207
  IsOutsideModal(control: SkiaControl): boolean;
@@ -210,6 +209,14 @@ export declare class SkiaAccessibilityManager {
210
209
  private UpdateActiveModal;
211
210
  /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
212
211
  NextTabStop(from: SkiaControl | undefined, forward: boolean): SkiaControl | undefined;
212
+ /**
213
+ * Tab and Shift+Tab through a templated list whose cells are made on demand (DrawnUi.Net ac70a1d9): from a cell the
214
+ * keyboard goes to the next (previous) item, scrolled in and focused once drawn, unless the next stop is in the same
215
+ * cell; at the list's end it leaves the list. Entering the list it goes to its first (last) item. The overlay's DOM order
216
+ * lags the cells made while the list scrolls, so inside a list the browser's own Tab order is not used. True when it
217
+ * took the key.
218
+ */
219
+ TabThroughList(from: SkiaControl, forward: boolean): boolean;
213
220
  /**
214
221
  * A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
215
222
  * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
@@ -226,6 +233,16 @@ export declare class SkiaAccessibilityManager {
226
233
  private readonly liveSaid;
227
234
  private LiveChanged;
228
235
  ForceRebuildOnNextFrame(): void;
236
+ /** The scrolls moving the keyboard's control into view, and when each was asked (FollowScroll). */
237
+ private readonly following;
238
+ /**
239
+ * Scrolls are bringing the keyboard's control into view: every frame they draw rebuilds the overlay until each has
240
+ * stopped, so the overlay's rects are where the controls are and the controls they bring near are there for the next
241
+ * Tab (the timed rebuild could come a second later, and Tab would fall out of the canvas).
242
+ */
243
+ FollowScroll(scrolls: {
244
+ IsScrolling: boolean;
245
+ }[]): void;
229
246
  Unregister(node: SkiaControl): void;
230
247
  UnregisterSubtree(root: SkiaControl): void;
231
248
  /**
@@ -262,9 +262,20 @@ export class SkiaAccessibilityManager {
262
262
  focusRequest;
263
263
  popupFocusRoot;
264
264
  focusAnyInside = false;
265
+ popupFocusDeadline = 0;
265
266
  /** 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; }
267
+ RequestKeyboardFocus(control) {
268
+ if (this.appFocusThisFrame)
269
+ return;
270
+ this.focusRequest = control;
271
+ this.focusRequestDeadline = performance.now() + SkiaAccessibilityManager.FocusRequestWaitMs;
272
+ }
273
+ /**
274
+ * How long a keyboard focus request waits for its control to take input again (drawnui-cross 6bs): an app that shows
275
+ * the opener of a dialog again only once the dialog is gone (a HUD hidden under it) still gets the keyboard back there.
276
+ */
277
+ static FocusRequestWaitMs = 1000;
278
+ focusRequestDeadline = 0;
268
279
  appFocus;
269
280
  appFocusDeadline = 0;
270
281
  appFocusThisFrame = false; // until the frame end: the app said where the focus goes, the library's moves give way
@@ -313,6 +324,19 @@ export class SkiaAccessibilityManager {
313
324
  // ---- modal accessibility scope (drawnui-cross 6av, C# AccessibilityModal) ----
314
325
  /** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
315
326
  ActiveModal;
327
+ /**
328
+ * The node the overlay names the active modal after (drawnui-cross 6bs): the modal's own when it has a name, else the
329
+ * first named dialog inside it, so a nameless popup host around a dialog reads as that one dialog, not as two.
330
+ */
331
+ get ActiveModalNode() {
332
+ const modal = this.ActiveModal;
333
+ if (!modal)
334
+ return undefined;
335
+ const own = this.Snapshot.find((n) => n.Source === modal);
336
+ if (own?.Label)
337
+ return own;
338
+ return this.Snapshot.find((n) => (n.Role === Aria.RoleDialog || n.Role === Aria.RoleAlertDialog) && !!n.Label && n.Source !== modal && IsInside(n.Source, modal)) ?? own;
339
+ }
316
340
  // where the keyboard was when each modal became active, to go back there when it goes
317
341
  modalReturns = new Map();
318
342
  /** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
@@ -336,18 +360,27 @@ export class SkiaAccessibilityManager {
336
360
  this.ActiveModal = next;
337
361
  this.ForceRebuildOnNextFrame(); // readers and Tab switch to the new scope in this frame
338
362
  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
363
  const back = previous && this.modalReturns.get(previous);
346
364
  if (previous)
347
365
  this.modalReturns.delete(previous);
348
366
  // back unless the keyboard went elsewhere meanwhile; a keyboard node that left with the modal (disposed, detached) was in it
349
367
  const leftWithIt = !!keyboard && (keyboard.IsDisposed || !keyboard.Superview);
350
- if (back && (!keyboard || leftWithIt || IsInside(keyboard, previous)) && (!next || IsInside(back, next)))
368
+ const fromPrevious = !!back && (!keyboard || leftWithIt || IsInside(keyboard, previous));
369
+ if (next) {
370
+ // the keyboard is in use: into the modal, and back to `from` when it goes. A dialog handing over to another (How to
371
+ // play, then Paused) passes its own return on, in the same frame or while that return is still waiting (6bs).
372
+ const waiting = this.focusRequest && !this.focusRequest.IsDisposed && !IsInside(this.focusRequest, next) ? this.focusRequest : undefined;
373
+ const from = fromPrevious ? back : waiting ?? (keyboard && !leftWithIt && !IsInside(keyboard, next) ? keyboard : undefined);
374
+ if (from) {
375
+ this.modalReturns.set(next, from);
376
+ this.popupFocusRoot = next;
377
+ this.focusAnyInside = true;
378
+ this.popupFocusDeadline = performance.now() + SkiaAccessibilityManager.FocusRequestWaitMs;
379
+ if (from === this.focusRequest)
380
+ this.focusRequest = undefined;
381
+ }
382
+ }
383
+ if (fromPrevious && (!next || IsInside(back, next)))
351
384
  this.RequestKeyboardFocus(back);
352
385
  }
353
386
  /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
@@ -363,12 +396,48 @@ export class SkiaAccessibilityManager {
363
396
  return stops[(next + stops.length) % stops.length];
364
397
  return next >= 0 && next < stops.length ? stops[next] : undefined;
365
398
  }
399
+ /**
400
+ * Tab and Shift+Tab through a templated list whose cells are made on demand (DrawnUi.Net ac70a1d9): from a cell the
401
+ * keyboard goes to the next (previous) item, scrolled in and focused once drawn, unless the next stop is in the same
402
+ * cell; at the list's end it leaves the list. Entering the list it goes to its first (last) item. The overlay's DOM order
403
+ * lags the cells made while the list scrolls, so inside a list the browser's own Tab order is not used. True when it
404
+ * took the key.
405
+ */
406
+ TabThroughList(from, forward) {
407
+ if (this.KeyboardScope)
408
+ return false;
409
+ const next = this.NextTabStop(from, forward);
410
+ const here = TemplatedCellOf(from), there = next ? TemplatedCellOf(next) : undefined;
411
+ let list, target;
412
+ if (here) {
413
+ const step = forward ? 1 : -1;
414
+ if (there && there.Cell === here.Cell)
415
+ return false; // the next stop is in the same cell: the usual order
416
+ // a Tab while the previous one is still scrolling its item in goes on from that item (as the arrow keys)
417
+ const pending = this.groupRequest?.Group === here.List ? this.groupRequest.Index : undefined;
418
+ list = here.List;
419
+ target = (pending ?? here.Cell.ContextIndex) + step;
420
+ }
421
+ else if (there) {
422
+ list = there.List;
423
+ target = forward ? 0 : ItemCount(list) - 1;
424
+ if (there.Cell.ContextIndex === target)
425
+ return false;
426
+ }
427
+ else
428
+ return false;
429
+ if (target < 0 || target >= ItemCount(list))
430
+ return false;
431
+ this.groupRequest = { Group: list, Scroll: FindScroll(list), Index: target, Step: forward ? 1 : -1, Deadline: performance.now() + 3000, ScrollIssued: false };
432
+ list.Superview?.Update();
433
+ return true;
434
+ }
366
435
  /**
367
436
  * 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
437
  * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
369
438
  */
370
- FocusOpenedPopup(root) { this.popupFocusRoot = root; this.focusAnyInside = false; }
371
- ProcessFocusRequests(scale, w, h) {
439
+ FocusOpenedPopup(root) { this.popupFocusRoot = root; this.focusAnyInside = false; this.popupFocusDeadline = performance.now() + SkiaAccessibilityManager.FocusRequestWaitMs; }
440
+ ProcessFocusRequests(scale, w, h, requestFrame) {
372
441
  const request = this.focusRequest, root = this.popupFocusRoot;
373
442
  this.focusRequest = this.popupFocusRoot = undefined;
374
443
  if (root && !root.IsDisposed && root.Superview) {
@@ -384,9 +453,23 @@ export class SkiaAccessibilityManager {
384
453
  this.FocusFromKeyboard(target.Source, scale, w, h);
385
454
  return;
386
455
  }
456
+ // a modal with nothing to take input yet (its buttons show a moment later): looked at again on the next frames, for a moment
457
+ if (this.focusAnyInside && performance.now() < this.popupFocusDeadline) {
458
+ this.popupFocusRoot = root;
459
+ this.focusRequest ??= request;
460
+ requestFrame();
461
+ return;
462
+ }
387
463
  }
388
- if (request && !request.IsDisposed && request.Superview && request.AccessibilityCanInteract)
464
+ if (!request || request.IsDisposed || !request.Superview)
465
+ return;
466
+ if (request.AccessibilityCanInteract)
389
467
  this.FocusFromKeyboard(request, scale, w, h);
468
+ // not taking input yet (shown again only after a dialog closed): asked again on the next frames, for a moment
469
+ else if (performance.now() < this.focusRequestDeadline) {
470
+ this.focusRequest = request;
471
+ requestFrame();
472
+ }
390
473
  }
391
474
  /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
392
475
  ProcessGroupFocus(scale, w, h, requestFrame) {
@@ -451,6 +534,20 @@ export class SkiaAccessibilityManager {
451
534
  return false;
452
535
  }
453
536
  ForceRebuildOnNextFrame() { this.lastRebuild = -Infinity; this.dirty = true; }
537
+ /** The scrolls moving the keyboard's control into view, and when each was asked (FollowScroll). */
538
+ following = new Map();
539
+ /**
540
+ * Scrolls are bringing the keyboard's control into view: every frame they draw rebuilds the overlay until each has
541
+ * stopped, so the overlay's rects are where the controls are and the controls they bring near are there for the next
542
+ * Tab (the timed rebuild could come a second later, and Tab would fall out of the canvas).
543
+ */
544
+ FollowScroll(scrolls) {
545
+ const now = performance.now();
546
+ for (const s of scrolls)
547
+ this.following.set(s, now);
548
+ if (scrolls.length)
549
+ this.dirty = true;
550
+ }
454
551
  Unregister(node) {
455
552
  if (this.nodes.delete(node)) {
456
553
  node.OnAccessibilityUnregistered();
@@ -483,11 +580,19 @@ export class SkiaAccessibilityManager {
483
580
  if (this.appFocus)
484
581
  this.ProcessAppFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
485
582
  if (this.focusRequest || this.popupFocusRoot)
486
- this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
583
+ this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx, requestFrame);
487
584
  this.appFocusThisFrame = false;
488
585
  if (this.nodes.size === 0 && this.Snapshot.length === 0)
489
586
  return;
490
587
  const now = performance.now();
588
+ if (this.following.size > 0) {
589
+ this.Rebuild(scale, canvasWidthPx, canvasHeightPx);
590
+ // a scroll is followed until it stopped (its animation starts with the next frame; 3 s at most)
591
+ for (const [s, at] of this.following)
592
+ if ((!s.IsScrolling && now - at > 50) || now - at > 3000)
593
+ this.following.delete(s);
594
+ return;
595
+ }
491
596
  const wait = this.MinUpdateIntervalMs - (now - this.lastRebuild);
492
597
  // a live region whose text changed is read on the next frame, not at the next timed rebuild (accessibility-plan B2)
493
598
  if (wait > 0 && this.liveSaid.size > 0 && this.LiveChanged()) {
@@ -513,7 +618,8 @@ export class SkiaAccessibilityManager {
513
618
  n.OnAccessibilityUnregistered();
514
619
  continue;
515
620
  } // detached from the tree
516
- if (!n.IsVisible || !n.IsAccessibilityElement || n.AccessibilityRole === Aria.RolePresentation)
621
+ // at opacity 0 a control is not seen, so it is not read either (DrawnUi.Net 4bd759e8)
622
+ if (!n.IsVisible || n.Opacity <= 0 || !n.IsAccessibilityElement || n.AccessibilityRole === Aria.RolePresentation)
517
623
  continue;
518
624
  if (modal && this.IsOutsideModal(n))
519
625
  continue; // a modal is shown: only its nodes, and those of popup windows over it
@@ -531,26 +637,11 @@ export class SkiaAccessibilityManager {
531
637
  Rect: new SKRect(px.Left / scale, px.Top / scale, px.Right / scale, px.Bottom / scale),
532
638
  CanInteract: n.AccessibilityCanInteract, IsPressed: n.AccessibilityIsPressed, Expanded: n.AccessibilityExpanded, Live: n.AccessibilityLive, Source: n,
533
639
  Disabled: !n.AccessibilityCanInteract && Aria.IsInteractiveRole(n.AccessibilityRole),
534
- TextLines: n.AccessibilityTextSelectable ? n.GetAccessibilityTextLines(scale) : undefined,
535
640
  });
536
641
  }
642
+ list = PresentationalChildren(list);
537
643
  list = SayNamesOnce(list);
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
- }
644
+ list = PageOrder(list, scale);
554
645
  this.liveSaid.clear();
555
646
  // the control's own name (a name given to a child that says it is no change)
556
647
  for (const n of list)
@@ -572,16 +663,6 @@ export class SkiaAccessibilityManager {
572
663
  || Math.abs(x.Rect.Left - y.Rect.Left) > 0.5 || Math.abs(x.Rect.Top - y.Rect.Top) > 0.5
573
664
  || Math.abs(x.Rect.Right - y.Rect.Right) > 0.5 || Math.abs(x.Rect.Bottom - y.Rect.Bottom) > 0.5)
574
665
  return false;
575
- const tx = x.TextLines, ty = y.TextLines;
576
- if (!!tx !== !!ty)
577
- return false;
578
- if (tx && ty) {
579
- if (tx.length !== ty.length)
580
- return false;
581
- for (let j = 0; j < tx.length; j++)
582
- if (tx[j].Text !== ty[j].Text || Math.abs(tx[j].Left - ty[j].Left) > 0.5 || Math.abs(tx[j].Top - ty[j].Top) > 0.5 || tx[j].FontSize !== ty[j].FontSize)
583
- return false;
584
- }
585
666
  }
586
667
  return true;
587
668
  }
@@ -590,13 +671,34 @@ export class SkiaAccessibilityManager {
590
671
  * Each name is said once in the flat overlay (DrawnUi.Rust said_by_child): a text or a heading whose label repeats the
591
672
  * label of the node it is in (its nearest ancestor node) is said by one of them. Under an interactive node (a card
592
673
  * 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.
674
+ * node loses its name and the heading says it.
594
675
  */
676
+ /** Roles whose content is their look, not more nodes (ARIA "children presentational", C# Aria.ChildrenArePresentational). */
677
+ const PresentationalChildrenRoles = new Set(["button", "checkbox", "radio", "switch", "tab", "option", "slider", "progressbar", "meter", "scrollbar", "separator", "img", "menuitemcheckbox", "menuitemradio"]);
678
+ /**
679
+ * The texts inside a button, a radio, a tab, a slider, an image... are its look: its name says them, so they are no nodes
680
+ * (C# SkiaAccessibilityManager.InsidePresentational). A control nested in it and selectable text stay; a link, a group,
681
+ * a list keep their content.
682
+ */
683
+ function PresentationalChildren(list) {
684
+ const bySource = new Map(list.map((x) => [x.Source, x]));
685
+ const inside = (x) => {
686
+ if (Aria.IsInteractiveRole(x.Role) || x.Source.AccessibilityTextSelectable)
687
+ return false;
688
+ for (let p = x.Source.Parent; p; p = p.Parent) {
689
+ const up = bySource.get(p);
690
+ if (up && PresentationalChildrenRoles.has(up.Role))
691
+ return true;
692
+ }
693
+ return false;
694
+ };
695
+ return list.some(inside) ? list.filter((x) => !inside(x)) : list;
696
+ }
595
697
  function SayNamesOnce(list) {
596
698
  const bySource = new Map(list.map((x) => [x.Source, x]));
597
699
  const said = new Set();
598
700
  for (const x of list) {
599
- if (!x.Label || x.TextLines || (x.Role !== Aria.RoleText && x.Role !== Aria.RoleHeading))
701
+ if (!x.Label || (x.Role !== Aria.RoleText && x.Role !== Aria.RoleHeading))
600
702
  continue;
601
703
  let owner;
602
704
  for (let p = x.Source.Parent; p && !owner; p = p.Parent)
@@ -804,6 +906,98 @@ function FindTarget(item) {
804
906
  }
805
907
  return undefined;
806
908
  }
909
+ /** The cell of a templated layout that holds a control, and that layout. */
910
+ function TemplatedCellOf(control) {
911
+ for (let c = control; c?.Parent; c = c.Parent)
912
+ if (asLayout(c.Parent)?.IsTemplated)
913
+ return { List: c.Parent, Cell: c };
914
+ return undefined;
915
+ }
916
+ /** The scrolls a control is inside, outermost first. */
917
+ /**
918
+ * Page order (as DrawnUi.Net SkiaAccessibilityManager.OrderLocked and DrawnUi.Rust): the nodes of a scroll take the scroll's
919
+ * place among the others and are ordered inside it, so content scrolled above or below the viewport never lands before a
920
+ * fixed header or after a footer. Outside scrolls: by top, a row (tops within half the smaller height) read left to right.
921
+ * Inside a scroll: tree order, the order of its content (the Tab order of browsers is the document order too), so a 3D
922
+ * viewer's dots never interleave with the controls beside it.
923
+ */
924
+ function PageOrder(list, scale) {
925
+ const groups = new Map();
926
+ const tops = [];
927
+ for (const n of list) {
928
+ const scroll = OutermostDrawnScroll(n.Source);
929
+ if (!scroll) {
930
+ tops.push({ Rect: n.Rect, Node: n });
931
+ continue;
932
+ }
933
+ let members = groups.get(scroll);
934
+ if (!members) {
935
+ groups.set(scroll, members = []);
936
+ const r = scroll.GetAccessibilityPixelRect();
937
+ tops.push({ Rect: { Top: r.Top / scale, Left: r.Left / scale, Height: r.Height / scale }, Scroll: scroll });
938
+ }
939
+ members.push(n);
940
+ }
941
+ tops.sort((a, b) => a.Rect.Top - b.Rect.Top || a.Rect.Left - b.Rect.Left);
942
+ // reading order: tops within half the smaller height form one row, read left to right (C# RectComparer + LeftComparer)
943
+ for (let start = 0, i = 1; i <= tops.length; i++) {
944
+ if (i < tops.length) {
945
+ const first = tops[start].Rect, next = tops[i].Rect;
946
+ if (next.Top - first.Top < Math.min(first.Height, next.Height) / 2)
947
+ continue;
948
+ }
949
+ if (i - start > 1) {
950
+ const row = tops.slice(start, i).sort((a, b) => a.Rect.Left - b.Rect.Left);
951
+ for (let k = 0; k < row.length; k++)
952
+ tops[start + k] = row[k];
953
+ }
954
+ start = i;
955
+ }
956
+ const out = [];
957
+ for (const t of tops) {
958
+ if (t.Node) {
959
+ out.push(t.Node);
960
+ continue;
961
+ }
962
+ const members = groups.get(t.Scroll);
963
+ if (members.length > 1) {
964
+ const paths = new Map(members.map((m) => [m, TreePath(m.Source, t.Scroll)]));
965
+ members.sort((a, b) => ComparePaths(paths.get(a), paths.get(b)));
966
+ }
967
+ out.push(...members);
968
+ }
969
+ return out;
970
+ }
971
+ /** The outermost scroll around a control that is on screen (has a drawn rect), undefined when none is. */
972
+ function OutermostDrawnScroll(control) {
973
+ let found;
974
+ for (let p = control.Parent; p; p = p.Parent) {
975
+ if (!asScroll(p))
976
+ continue;
977
+ const r = p.GetAccessibilityPixelRect();
978
+ if (r.Width > 0 && r.Height > 0)
979
+ found = p;
980
+ }
981
+ return found;
982
+ }
983
+ /** Child indices from root down to control; a recycled cell counts by its item (C# TreePath). */
984
+ function TreePath(control, root) {
985
+ const path = [];
986
+ for (let c = control; c && c !== root; c = c.Parent) {
987
+ const parent = c.Parent;
988
+ if (!parent)
989
+ break;
990
+ const layout = asLayout(parent);
991
+ path.push(layout?.IsTemplated ? c.ContextIndex : ViewsOf(parent).indexOf(c));
992
+ }
993
+ return path.reverse();
994
+ }
995
+ function ComparePaths(a, b) {
996
+ for (let i = 0; i < Math.min(a.length, b.length); i++)
997
+ if (a[i] !== b[i])
998
+ return a[i] - b[i];
999
+ return a.length - b.length; // a container before what it holds
1000
+ }
807
1001
  /** True when any ancestor is hidden (IsVisible false or Opacity 0): the subtree is not drawn, so it gets no nodes. */
808
1002
  function AccessibilityManagerHiddenByAncestor(control) {
809
1003
  let p = control.Parent;