drawnui-react 0.1.0-preview.36 → 0.1.0-preview.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKIPPED.md CHANGED
@@ -55,6 +55,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
55
55
  | `ContextMenu` (right click / long press / Menu key, React extension) | ported (web-only) | `SkiaControl.ContextMenu` / `Canvas.ContextMenu` handlers with `ContextMenuEventArgs` (`Location` points, `Pixels`, `Local` px in the control, `Source`, `Native`); the DOM `contextmenu` event is routed like a tap (`ProcessContextMenu`: visible non-transparent children top-most first through `TransformPointToLocalSpace`, then the control, then the canvas). `true` = handled, browser menu suppressed; nothing handled = browser menu. Not in DrawnUi.Net. |
56
56
  | Tooltips (`SkiaControl.Tooltip`, `Super.TooltipsFromAccessibility`, `TooltipStyle`) | ported | drawnui-cross 6ar: shows after `ShowDelayMs` on the innermost control with tooltip text, the next one at once within `FollowWindowMs`; attached to the control (centered 6 pt above, below where there is no room) or `AtCursor`, `OffsetX` / `OffsetY`, anchored on screen now, kept inside the canvas; closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch; no hover, no accessibility node; `CreateTooltip` for custom content. Drawn in the canvas only (a browser page has no windows past its edge). |
57
57
  | Popup windows (`Canvas.OpenPopupWindow` / `ClosePopupWindow` / `ClosePopupWindows` / `IsPopupWindowOpen`, `PopupAnchor`, `PopupWindowOptions`, `PopupWindowClosed`) | ported | drawnui-cross 6at, the DrawnUi.Rust / .NET API (C# names): anchor a point, a rect or a control (below it, flipped where it does not fit, kept inside); drawn over everything, given input and hover first; closes on a press outside (the rest of that press goes nowhere), Escape, the wheel outside, window blur and from code; options `Size`, `CloseOnPointerLeave`, `Passive`; `OnCanvas` / `Cpu` accepted, always on the canvas. React extra: `OpenPopupWindow(canvas, jsx, anchor, options)` renders JSX content and unmounts it on close. |
58
+ | `AccessibilityModal`, `Canvas.ArrowsStartKeyboardNavigation` | ported | drawnui-cross 6av, C# 6e87c9ae / 914428d2 / 981ff09e / 86467ece / 77d1dca4 / 6aee5c51: a shown modal limits screen readers and Tab to its subtree plus popup windows (topmost wins), reads as a dialog with its name, takes the keyboard when it appears with the keyboard in use and gives it back when it goes; the flat overlay's container is the dialog (role, name, aria-modal). With nothing focused (or only a control behind the modal) and the canvas option on, an arrow starts keyboard navigation. Shell popups and modals do not set the flag yet. |
58
59
  | Keyboard navigation (drawnui-cross 6c) | ported | Through the accessibility overlay, the DrawnUi.Blazor way: Tab / Shift+Tab walk the interactive nodes in reading order, Enter / Space activate (`SkiaAccessibilityManager.Activate`), ArrowLeft / Right / Up / Down, Home / End, PageUp / PageDown go to the focused control first (`OnAccessibilityKey`, `SkiaAccessibilityManager.Key`: `SkiaSlider` steps, `SkiaEditor` keeps them while editing), then to its arrow-key group (`MoveInGroup`). A container with a composite role (`Aria.IsCompositeRole`: list, listbox, grid, toolbar, radiogroup, tablist, menu, menubar) is one Tab stop (roving tabindex, `IsTabStop`, entered on the item focused last); the arrows move by item index (Column: Up / Down, Row: Left / Right, Wrap / Grid / Split: all four, Up / Down by a row), no wrap, items not realized are scrolled in with `ScrollToIndex` and focused once drawn (`OnKeyboardFocusRequested`). `SkiaEditor` is a Tab stop: Tab in takes the caret, Tab / Shift+Tab leave it for the next node (also after a click into it). Focus ring = the overlay element's `:focus-visible` outline; focus scrolls the node into view in every enclosing scroll. Not ported: `FocusedChild` / canvas `KeyboardFocusNode`, Escape leaving the drawn nodes, a canvas-drawn focus ring. |
59
60
  | Canvas draw events | ported | `WillFirstTimeDraw` (once, right before the first frame drawn on a ready surface, with that frame's `{ Canvas, Surface }`), `WasDrawn` (after every frame, no context, like the C# `null`), `WasRendered` (set after the first frame completes, so the first `WasDrawn` still sees `false`, C# order), `CanRender` (surface ready). JSX: `<Canvas WillFirstTimeDraw WasDrawn>`; the engine draws frame 1 in its constructor, so the component hands both callbacks to the constructor's `init`. Not ported: `WillDraw`. |
60
61
  | Rendering stats | partial | `Canvas.FPS` (frames drawn over the last second) and `Canvas.FrameTime` (ms of the last measure + arrange + render, GPU flush excluded) are computed every frame and reachable from React through the `<Canvas>` ref. `SkiaLabelFps` ported (label on top, input-transparent, parent-independent, re-measures itself on draw; its value changes only on frames that running animators request, see PARITY). Not ported: `SkiaLabelFps.ForceRefresh` / `Format` / `MonoForDigits`, `Super.EnableRenderingStats`. |
@@ -236,6 +236,26 @@ export class SkiaCarousel extends SnappingLayout {
236
236
  ScrollToNearestAnchor(location, velocity) {
237
237
  const t = this.SnapVelocityThreshold;
238
238
  velocity = new SKPoint(Math.abs(velocity.X) < t ? 0 : velocity.X, Math.abs(velocity.Y) < t ? 0 : velocity.Y);
239
+ const home = this.releaseHome;
240
+ if (this.ApplyLoopedLogic && home && this.SnapPoints.length > 1) {
241
+ // a finger release on a looped carousel: one slide at most from the slide the gesture started on, counted along the
242
+ // strip, so across the edge it is the virtual slot next to it. A flick goes one slide its way, a slow drag to the
243
+ // nearest of that slide and its two neighbours. Measured from the slide nearest the release instead, a drag past
244
+ // the middle went the wrong way at the wrap (C# 11196529)
245
+ const step = new SKPoint(this.SnapPoints[1].X - this.SnapPoints[0].X, this.SnapPoints[1].Y - this.SnapPoints[0].Y);
246
+ const stepAxis = this.IsVertical ? step.Y : step.X;
247
+ if (stepAxis !== 0) {
248
+ const vel = this.IsVertical ? velocity.Y : velocity.X;
249
+ const moved = this.IsVertical ? location.Y - home.Y : location.X - home.X;
250
+ const k = vel !== 0 ? Math.sign(vel) * Math.sign(stepAxis) : Math.max(-1, Math.min(1, Math.round(moved / stepAxis)));
251
+ const target = new SKPoint(home.X + step.X * k, home.Y + step.Y * k);
252
+ if (SnappingLayout.Dist(location, target) >= 0.5)
253
+ this.ScrollToOffset(target, velocity, this.CanAnimate);
254
+ else
255
+ this.UpdateReportedPosition();
256
+ return;
257
+ }
258
+ }
239
259
  if (this.ApplyLoopedLogic) {
240
260
  const origin = this.FindNearestAnchorInternal(location, velocity);
241
261
  const target = this.SelectNextAnchor(origin, velocity);
@@ -305,9 +325,17 @@ export class SkiaCarousel extends SnappingLayout {
305
325
  /** C# FixIndex: a virtual anchor becomes the real one, the position keeps its offset (visually identical, looped drawing wraps). */
306
326
  FixIndex() {
307
327
  if (this.IsLooped && this.SnapPoints.length > 1 && this.selectedIndex >= 0 && this.selectedIndex < this.SnapPoints.length) {
308
- const snap = this.GetVirtualAnchor(this.CurrentPosition);
309
- const ox = this.CurrentPosition.X - snap.Location.X, oy = this.CurrentPosition.Y - snap.Location.Y;
310
- const real = this.SnapPoints[this.selectedIndex];
328
+ // the offset is measured from the anchor that stands for the selected slide where the position is now: the slide
329
+ // itself or its virtual copy past an edge. From the nearest anchor of another slide it moved a wrap in progress (the
330
+ // last slide 3% toward the first) onto another pair (C# b75f233a)
331
+ const real = this.SnapPoints[this.selectedIndex], last = this.MaxIndex;
332
+ let anchor = real;
333
+ for (const v of this.GetVirtualSnapPoints()) {
334
+ const standsFor = v.Id === this.selectedIndex || (v.Id === -1 && this.selectedIndex === last) || (v.Id === -2 && this.selectedIndex === 0);
335
+ if (standsFor && SnappingLayout.Dist(v.Location, this.CurrentPosition) < SnappingLayout.Dist(anchor, this.CurrentPosition))
336
+ anchor = v.Location;
337
+ }
338
+ const ox = this.CurrentPosition.X - anchor.X, oy = this.CurrentPosition.Y - anchor.Y;
311
339
  this.CurrentSnap = real;
312
340
  this.CurrentPosition = new SKPoint(real.X + ox, real.Y + oy);
313
341
  }
@@ -203,6 +203,11 @@ export class SkiaShaderCarousel extends SkiaCarousel {
203
203
  if (!this.wasInTransitionAtDown)
204
204
  return super.ScrollToOffset(targetOffset, velocity, animate);
205
205
  this.wasInTransitionAtDown = false;
206
+ // a swipe back against the interrupted transition goes straight to its slide: wrapping that transition up first ran
207
+ // it on to its end and then back, a visible jump forward and back (C# b75f233a)
208
+ const heading = axis(this.gestureOrigin) - axis(this.gestureFrom), turn = axis(targetOffset) - axis(this.gestureOrigin);
209
+ if (heading !== 0 && turn !== 0 && Math.sign(heading) !== Math.sign(turn))
210
+ return super.ScrollToOffset(targetOffset, velocity, animate);
206
211
  // the pan may already have carried the position PAST the interrupted transition's destination toward the new
207
212
  // target: wrapping it up would animate backward first. Only run phase 1 while that destination is still ahead.
208
213
  const toOrigin = axis(this.gestureOrigin) - axis(this.CurrentPosition);
@@ -1,6 +1,8 @@
1
1
  import type { InputKey } from "./KeyboardManager";
2
2
  import type { SkiaControl } from "./SkiaControl";
3
3
  import { SKRect } from "./Types";
4
+ /** Controls with `AccessibilityModal` set, on every canvas (drawnui-cross 6av). Empty: no modal work at all. */
5
+ export declare const AccessibilityModals: Set<SkiaControl>;
4
6
  /** ARIA role constants (DrawnUi.Models.Aria) for `AccessibilityRole`. */
5
7
  export declare const Aria: {
6
8
  readonly RoleButton: "button";
@@ -169,13 +171,23 @@ export declare class SkiaAccessibilityManager {
169
171
  MoveInGroup(focused: SkiaControl, key: InputKey): boolean;
170
172
  private focusRequest?;
171
173
  private popupFocusRoot?;
174
+ private focusAnyInside;
172
175
  /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
173
176
  RequestKeyboardFocus(control: SkiaControl): void;
177
+ private popupScope?;
174
178
  /**
175
- * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them. The canvas
176
- * sets it to the top popup window that takes input (a menu, a dropdown), undefined when none is open.
179
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them: the top
180
+ * popup window that takes input (a menu, a dropdown; set by the canvas), else the active modal.
177
181
  */
178
- KeyboardScope?: SkiaControl;
182
+ get KeyboardScope(): SkiaControl | undefined;
183
+ set KeyboardScope(v: SkiaControl | undefined);
184
+ /** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
185
+ ActiveModal?: SkiaControl;
186
+ private readonly modalReturns;
187
+ /** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
188
+ IsOutsideModal(control: SkiaControl): boolean;
189
+ /** Frame end, only while some control is flagged modal or one was active: follows the top modal. */
190
+ private UpdateActiveModal;
179
191
  /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
180
192
  NextTabStop(from: SkiaControl | undefined, forward: boolean): SkiaControl | undefined;
181
193
  /**
@@ -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
@@ -234,13 +236,56 @@ export class SkiaAccessibilityManager {
234
236
  // ---- keyboard focus moved by popup windows (drawnui-cross 6ao rule 2, and back to the opener on close) ----
235
237
  focusRequest;
236
238
  popupFocusRoot;
239
+ focusAnyInside = false;
237
240
  /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
238
241
  RequestKeyboardFocus(control) { this.focusRequest = control; }
242
+ popupScope;
239
243
  /**
240
- * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them. The canvas
241
- * sets it to the top popup window that takes input (a menu, a dropdown), undefined when none is open.
244
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them: the top
245
+ * popup window that takes input (a menu, a dropdown; set by the canvas), else the active modal.
242
246
  */
243
- KeyboardScope;
247
+ get KeyboardScope() { return this.popupScope ?? this.ActiveModal; }
248
+ set KeyboardScope(v) { this.popupScope = v; }
249
+ // ---- modal accessibility scope (drawnui-cross 6av, C# AccessibilityModal) ----
250
+ /** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
251
+ ActiveModal;
252
+ // where the keyboard was when each modal became active, to go back there when it goes
253
+ modalReturns = new Map();
254
+ /** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
255
+ IsOutsideModal(control) {
256
+ const modal = this.ActiveModal;
257
+ return !!modal && !IsInside(control, modal) && TopRoot(control) === TopRoot(modal);
258
+ }
259
+ /** Frame end, only while some control is flagged modal or one was active: follows the top modal. */
260
+ UpdateActiveModal() {
261
+ let next;
262
+ for (const m of AccessibilityModals) {
263
+ if (m.IsDisposed || !m.IsVisible || m.Opacity <= 0 || AccessibilityManagerHiddenByAncestor(m)
264
+ || m.Superview?.AccessibilityManager !== this || !IsDrawn(m))
265
+ continue;
266
+ if (!next || IsDrawnAbove(m, next))
267
+ next = m;
268
+ }
269
+ const previous = this.ActiveModal;
270
+ if (previous === next)
271
+ return;
272
+ this.ActiveModal = next;
273
+ this.ForceRebuildOnNextFrame(); // readers and Tab switch to the new scope in this frame
274
+ const keyboard = this.FocusedNode;
275
+ if (next && keyboard && !IsInside(keyboard, next)) {
276
+ // the keyboard is in use: into the modal, and back here when it goes
277
+ this.modalReturns.set(next, keyboard);
278
+ this.popupFocusRoot = next;
279
+ this.focusAnyInside = true;
280
+ }
281
+ const back = previous && this.modalReturns.get(previous);
282
+ if (previous)
283
+ this.modalReturns.delete(previous);
284
+ // back unless the keyboard went elsewhere meanwhile; a keyboard node that left with the modal (disposed, detached) was in it
285
+ const leftWithIt = !!keyboard && (keyboard.IsDisposed || !keyboard.Superview);
286
+ if (back && (!keyboard || leftWithIt || IsInside(keyboard, previous)) && (!next || IsInside(back, next)))
287
+ this.focusRequest = back;
288
+ }
244
289
  /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
245
290
  NextTabStop(from, forward) {
246
291
  const stops = this.Snapshot.filter((n) => n.CanInteract && this.IsTabStop(n.Source)).map((n) => n.Source);
@@ -258,7 +303,7 @@ export class SkiaAccessibilityManager {
258
303
  * A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
259
304
  * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
260
305
  */
261
- FocusOpenedPopup(root) { this.popupFocusRoot = root; }
306
+ FocusOpenedPopup(root) { this.popupFocusRoot = root; this.focusAnyInside = false; }
262
307
  ProcessFocusRequests(scale, w, h) {
263
308
  const request = this.focusRequest, root = this.popupFocusRoot;
264
309
  this.focusRequest = this.popupFocusRoot = undefined;
@@ -268,7 +313,8 @@ export class SkiaAccessibilityManager {
268
313
  if (p === root)
269
314
  return true; return false; };
270
315
  const choice = (role) => role === Aria.RoleRadio || role === Aria.RoleMenuItemRadio || role === "option" || role === "tab";
271
- const items = this.Snapshot.filter((n) => n.CanInteract && inside(n.Source) && SkiaAccessibilityManager.TryFindGroup(n.Source));
316
+ // a popup: the items of its arrow-key group; a modal: its first control that takes input
317
+ const items = this.Snapshot.filter((n) => n.CanInteract && inside(n.Source) && (this.focusAnyInside || SkiaAccessibilityManager.TryFindGroup(n.Source)));
272
318
  const target = items.find((n) => n.IsPressed === true && choice(n.Role)) ?? items[0];
273
319
  if (target) {
274
320
  this.FocusFromKeyboard(target.Source, scale, w, h);
@@ -350,6 +396,8 @@ export class SkiaAccessibilityManager {
350
396
  * per MinUpdateIntervalMs otherwise (keeps rects in sync with scrolling); notifies only when the snapshot differs.
351
397
  */
352
398
  OnFrameEnd(scale, canvasWidthPx, canvasHeightPx, requestFrame) {
399
+ if (AccessibilityModals.size > 0 || this.ActiveModal)
400
+ this.UpdateActiveModal();
353
401
  this.ProcessGroupFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
354
402
  if (this.focusRequest || this.popupFocusRoot)
355
403
  this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
@@ -369,6 +417,7 @@ export class SkiaAccessibilityManager {
369
417
  this.dirty = false;
370
418
  this.lastRebuild = performance.now();
371
419
  let list = [];
420
+ const modal = this.ActiveModal;
372
421
  for (const n of this.nodes) {
373
422
  if (!n.Superview) {
374
423
  this.nodes.delete(n);
@@ -377,6 +426,8 @@ export class SkiaAccessibilityManager {
377
426
  } // detached from the tree
378
427
  if (!n.IsVisible || !n.IsAccessibilityElement || n.AccessibilityRole === Aria.RolePresentation)
379
428
  continue;
429
+ if (modal && this.IsOutsideModal(n))
430
+ continue; // a modal is shown: only its nodes, and those of popup windows over it
380
431
  if (AccessibilityManagerHiddenByAncestor(n))
381
432
  continue; // e.g. the root page kept mounted under a pushed shell page
382
433
  const px = n.GetAccessibilityPixelRect();
@@ -458,6 +509,9 @@ function SayNamesOnce(list) {
458
509
  owner = bySource.get(p);
459
510
  if (!owner || owner.Label !== x.Label)
460
511
  continue;
512
+ // a dialog keeps its name though its title says it too: readers announce the dialog by name on entry
513
+ if (owner.Role === Aria.RoleDialog || owner.Role === Aria.RoleAlertDialog)
514
+ continue;
461
515
  if (owner.CanInteract)
462
516
  said.add(x);
463
517
  else
@@ -469,6 +523,39 @@ function SameValue(a, b) {
469
523
  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);
470
524
  }
471
525
  // ---- group helpers (duck-typed layouts and scrolls) ----
526
+ function IsInside(control, root) {
527
+ for (let c = control; c; c = c.Parent)
528
+ if (c === root)
529
+ return true;
530
+ return false;
531
+ }
532
+ /** The top of the tree a control is in: the canvas content, or a popup window's root. */
533
+ function TopRoot(control) {
534
+ let c = control;
535
+ while (c.Parent)
536
+ c = c.Parent;
537
+ return c;
538
+ }
539
+ /** Drawing order: `a` draws over `b` (ZIndex, then tree order; a nested control over its ancestor). */
540
+ function IsDrawnAbove(a, b) {
541
+ const path = (c) => { const p = []; for (let x = c; x; x = x.Parent)
542
+ p.unshift(x); return p; };
543
+ const pa = path(a), pb = path(b);
544
+ let i = 0;
545
+ while (i < pa.length && i < pb.length && pa[i] === pb[i])
546
+ i++;
547
+ if (i === pa.length)
548
+ return false; // a contains b
549
+ if (i === pb.length)
550
+ return true; // b contains a
551
+ if (i === 0)
552
+ return false; // different trees (a popup window): the first one found stays
553
+ const sa = pa[i], sb = pb[i];
554
+ if (sa.ZIndex !== sb.ZIndex)
555
+ return sa.ZIndex > sb.ZIndex;
556
+ const views = ViewsOf(sa.Parent);
557
+ return views.indexOf(sa) > views.indexOf(sb);
558
+ }
472
559
  /** A node the keyboard can land on: a role that is not presentation and takes input. */
473
560
  function IsInteractiveNode(c) {
474
561
  return !!c.AccessibilityRole && c.AccessibilityRole !== Aria.RolePresentation && c.IsAccessibilityElement && c.AccessibilityCanInteract;
@@ -253,10 +253,26 @@ export declare class Canvas {
253
253
  private gestureOwner;
254
254
  /** DrawnUi IsSavedGesture: the types replayed to the owner instead of being routed again. */
255
255
  private static IsSavedGesture;
256
+ private arrowsStart;
257
+ /**
258
+ * While no drawn control has keyboard focus (or only one behind the active modal), the arrow keys start keyboard
259
+ * navigation as the first Tab does: Down and Right go to the first Tab stop, Up and Left to the last, and the key is used
260
+ * for that. Once a control has focus the arrows work as usual (inside a list or a menu). Off by default, since games use
261
+ * the arrows as their own keys while nothing is focused: an app turns it on for its menu screens and off while playing.
262
+ */
263
+ get ArrowsStartKeyboardNavigation(): boolean;
264
+ set ArrowsStartKeyboardNavigation(v: boolean);
265
+ private readonly onArrowChar;
266
+ private readonly onArrowKey;
256
267
  private focusedChild?;
257
268
  private focusAtDown?;
258
269
  private tapNoFocus;
259
270
  private reportingFocus;
271
+ /**
272
+ * A control that left the canvas (removed or disposed) is let go by the focus, the gesture dispatch and the tooltips,
273
+ * so the last control that took input does not keep its page alive (C# 4cb28ab6). Checked once per frame.
274
+ */
275
+ private ForgetGoneControls;
260
276
  /** The control that has the canvas focus (an editor while it edits, a CanBeFocused control that was tapped). */
261
277
  get FocusedChild(): SkiaControl | undefined;
262
278
  /**
@@ -169,7 +169,8 @@ export class Canvas {
169
169
  cancelAnimationFrame(this.frameId);
170
170
  this.frameId = 0;
171
171
  }
172
- this.surface?.delete();
172
+ // dispose, not delete: a software surface owns pixels CanvasKit allocated for it, which delete() leaves behind
173
+ this.surface?.dispose();
173
174
  this.surface = undefined;
174
175
  }
175
176
  /** On-screen surface at the element's current pixel size, reusing the GL/GrContext when accelerated. */
@@ -232,7 +233,7 @@ export class Canvas {
232
233
  return;
233
234
  if (this.grContext)
234
235
  this.grContext.releaseResourcesAndAbandonContext();
235
- this.surface?.delete();
236
+ this.surface?.dispose();
236
237
  this.surface = undefined;
237
238
  this.grContext?.delete();
238
239
  this.grContext = undefined;
@@ -292,6 +293,7 @@ export class Canvas {
292
293
  while (this.frameTimes.length && this.frameTimes[0] < now - 1000)
293
294
  this.frameTimes.shift();
294
295
  this.FPS = this.frameTimes.length;
296
+ this.ForgetGoneControls();
295
297
  if (executed > 0)
296
298
  this.Update(); // animators running: keep frames coming
297
299
  // C# order: WasDrawn at the end of the frame, then the frame counts as rendered
@@ -419,7 +421,7 @@ export class Canvas {
419
421
  }
420
422
  }
421
423
  finally {
422
- surface.delete();
424
+ surface.dispose(); // its pixels too (CK.MakeSurface allocates them)
423
425
  }
424
426
  }
425
427
  Dispose() {
@@ -431,6 +433,7 @@ export class Canvas {
431
433
  this.Element.removeEventListener("webglcontextlost", this.onContextLost);
432
434
  this.Element.removeEventListener("webglcontextrestored", this.onContextRestored);
433
435
  this.Gestures = "Disabled";
436
+ this.ArrowsStartKeyboardNavigation = false;
434
437
  this.tooltipController?.Dispose();
435
438
  this.popupLayer?.Dispose();
436
439
  this.HookPopupKeys(false);
@@ -827,11 +830,59 @@ export class Canvas {
827
830
  static IsSavedGesture(type) {
828
831
  return type === "Panning" || type === "Wheel" || type === "Up";
829
832
  }
833
+ // ---- arrows start keyboard navigation (C# 6aee5c51) ----
834
+ arrowsStart = false;
835
+ /**
836
+ * While no drawn control has keyboard focus (or only one behind the active modal), the arrow keys start keyboard
837
+ * navigation as the first Tab does: Down and Right go to the first Tab stop, Up and Left to the last, and the key is used
838
+ * for that. Once a control has focus the arrows work as usual (inside a list or a menu). Off by default, since games use
839
+ * the arrows as their own keys while nothing is focused: an app turns it on for its menu screens and off while playing.
840
+ */
841
+ get ArrowsStartKeyboardNavigation() { return this.arrowsStart; }
842
+ set ArrowsStartKeyboardNavigation(v) {
843
+ if (this.arrowsStart === v)
844
+ return;
845
+ this.arrowsStart = v;
846
+ if (v)
847
+ KeyboardManager.Subscribe(this.onArrowKey, this.onArrowChar);
848
+ else
849
+ KeyboardManager.Unsubscribe(this.onArrowKey, this.onArrowChar);
850
+ }
851
+ onArrowChar = () => { };
852
+ onArrowKey = (key, e) => {
853
+ const forward = key === "ArrowDown" || key === "ArrowRight" ? true : key === "ArrowUp" || key === "ArrowLeft" ? false : undefined;
854
+ // a page element, a drawn control's element or the editor's input has the keys: nothing to start
855
+ if (forward === undefined || this.disposed || KeyboardManager.IsOwnedByElement(e) || e.defaultPrevented)
856
+ return;
857
+ const mgr = this.AccessibilityManager, focused = mgr.FocusedNode;
858
+ if (focused && !mgr.IsOutsideModal(focused))
859
+ return;
860
+ const first = mgr.NextTabStop(undefined, forward);
861
+ if (!first)
862
+ return;
863
+ e.preventDefault();
864
+ mgr.RequestKeyboardFocus(first);
865
+ this.Update();
866
+ };
830
867
  // ---- focus (C# DrawnView FocusedChild / ReportFocus, drawnui-cross 6ap) ----
831
868
  focusedChild;
832
869
  focusAtDown;
833
870
  tapNoFocus = false;
834
871
  reportingFocus = false;
872
+ /**
873
+ * A control that left the canvas (removed or disposed) is let go by the focus, the gesture dispatch and the tooltips,
874
+ * so the last control that took input does not keep its page alive (C# 4cb28ab6). Checked once per frame.
875
+ */
876
+ ForgetGoneControls() {
877
+ const gone = (c) => !!c && (c.IsDisposed || c.Superview !== this);
878
+ if (gone(this.focusedChild))
879
+ this.focusedChild = undefined;
880
+ if (gone(this.focusAtDown))
881
+ this.focusAtDown = undefined;
882
+ if (gone(this.gestureOwner))
883
+ this.gestureOwner = null;
884
+ this.tooltipController?.ForgetGone(gone);
885
+ }
835
886
  /** The control that has the canvas focus (an editor while it edits, a CanBeFocused control that was tapped). */
836
887
  get FocusedChild() { return this.focusedChild; }
837
888
  /**
@@ -82,8 +82,10 @@ export class KeyboardManager {
82
82
  * those of its own element.
83
83
  */
84
84
  static IsOwnedByElement(e) {
85
- const tag = e.target?.tagName;
86
- return !!tag && tag !== "BODY" && tag !== "HTML" && tag !== "CANVAS";
85
+ const target = e.target;
86
+ const tag = target?.tagName;
87
+ // the canvas host holds the DOM focus when no drawn control has it: its keys are the app's, as the canvas' own
88
+ return !!tag && tag !== "BODY" && tag !== "HTML" && tag !== "CANVAS" && target?.dataset?.drawnuiHost !== "1";
87
89
  }
88
90
  /**
89
91
  * The key belongs to the input method (an IME composition, a soft keyboard): isComposing, keyCode 229, key "Process"
@@ -373,6 +373,16 @@ export declare class SkiaControl {
373
373
  */
374
374
  get AccessibilityRole(): string | undefined;
375
375
  set AccessibilityRole(v: string | undefined);
376
+ private accessibilityModal;
377
+ /**
378
+ * A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
379
+ * screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
380
+ * until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
381
+ * keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
382
+ * of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
383
+ */
384
+ get AccessibilityModal(): boolean;
385
+ set AccessibilityModal(v: boolean);
376
386
  /** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
377
387
  static DefaultAccessibilityRole?: string;
378
388
  /** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
@@ -3,7 +3,7 @@ import { SkiaStyles } from "./Styles";
3
3
  import { Colors, SKRect, ScaledSize, Thickness } from "./Types";
4
4
  import { RippleAnimator, SkiaValueAnimator } from "./Animators";
5
5
  import { Easing } from "./Easing";
6
- import { Aria } from "./Accessibility";
6
+ import { AccessibilityModals, Aria } from "./Accessibility";
7
7
  import { ControlTappedEventArgs, GestureEventProcessingInfo, SKPoint, SkiaGesturesInfo, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
8
8
  import { IsPostRendererEffect } from "./SkiaEffect";
9
9
  /** Mirrors DrawnUi CachedObject: what a cached control replays instead of repainting. */
@@ -72,7 +72,7 @@ export class CachedObject {
72
72
  canvas.translate(-this.Bounds.Left, -this.Bounds.Top);
73
73
  canvas.drawPicture(this.Picture);
74
74
  this.pictureImage = surface.makeImageSnapshot();
75
- surface.delete();
75
+ surface.dispose(); // a CK.MakeSurface fallback owns its pixels
76
76
  return this.pictureImage;
77
77
  }
78
78
  pictureImage;
@@ -611,11 +611,33 @@ export class SkiaControl {
611
611
  * ARIA role; setting it exposes the control to assistive technology (use `Aria` constants). Unset = the class
612
612
  * default (`SkiaLabel.DefaultAccessibilityRole` etc.), which is itself unset unless the app opts in.
613
613
  */
614
- get AccessibilityRole() { return this.accessibilityRole ?? this.constructor.DefaultAccessibilityRole; }
614
+ get AccessibilityRole() {
615
+ return this.accessibilityRole ?? (this.accessibilityModal ? Aria.RoleDialog : this.constructor.DefaultAccessibilityRole);
616
+ }
615
617
  set AccessibilityRole(v) { if (this.accessibilityRole !== v) {
616
618
  this.accessibilityRole = v;
617
619
  this.AccessibilityChanged();
618
620
  } }
621
+ accessibilityModal = false;
622
+ /**
623
+ * A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
624
+ * screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
625
+ * until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
626
+ * keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
627
+ * of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
628
+ */
629
+ get AccessibilityModal() { return this.accessibilityModal; }
630
+ set AccessibilityModal(v) {
631
+ if (this.accessibilityModal === v)
632
+ return;
633
+ this.accessibilityModal = v;
634
+ if (v)
635
+ AccessibilityModals.add(this);
636
+ else
637
+ AccessibilityModals.delete(this);
638
+ this.AccessibilityChanged();
639
+ this.Superview?.Update();
640
+ }
619
641
  /** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
620
642
  static DefaultAccessibilityRole;
621
643
  /** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
@@ -1421,6 +1443,8 @@ export class SkiaControl {
1421
1443
  if (this.IsDisposed)
1422
1444
  return;
1423
1445
  this.IsDisposed = true;
1446
+ if (this.accessibilityModal)
1447
+ AccessibilityModals.delete(this);
1424
1448
  this.OnDisposing();
1425
1449
  for (const c of this.ownAnimations.values())
1426
1450
  c.abort();
@@ -58,6 +58,8 @@ export declare class TooltipController {
58
58
  /** Any input that is not a plain mouse move (press, wheel, key, window blur): closed until the mouse reaches another control. */
59
59
  CloseOnInput(): void;
60
60
  /** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
61
+ /** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
62
+ ForgetGone(gone: (c: SkiaControl | undefined) => boolean): void;
61
63
  Reset(): void;
62
64
  private readonly onKey;
63
65
  private readonly onChar;
@@ -112,6 +112,16 @@ export class TooltipController {
112
112
  this.HookKeys(false);
113
113
  }
114
114
  /** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
115
+ /** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
116
+ ForgetGone(gone) {
117
+ if (gone(this.suppressed))
118
+ this.suppressed = undefined;
119
+ if (gone(this.owner)) {
120
+ this.owner = undefined;
121
+ this.text = undefined;
122
+ this.Hide();
123
+ }
124
+ }
115
125
  Reset() {
116
126
  this.owner = undefined;
117
127
  this.text = undefined;
@@ -114,6 +114,8 @@ export interface CanvasProps {
114
114
  * scrolls it unless a control used the wheel. A page that cannot scroll keeps every touch. Lock keeps all input.
115
115
  */
116
116
  Gestures?: GesturesMode;
117
+ /** While nothing has keyboard focus, an arrow key starts keyboard navigation as the first Tab does (off by default: games keep their arrows). */
118
+ ArrowsStartKeyboardNavigation?: boolean;
117
119
  children?: ReactNode;
118
120
  style?: CSSProperties;
119
121
  className?: string;
@@ -140,7 +142,7 @@ export declare function OpenPopupWindow(canvas: CanvasView, content: ReactNode,
140
142
  * Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
141
143
  * Requires Super.UseDrawnUi()...BuildAsync() to have completed.
142
144
  */
143
- export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }: CanvasProps): import("react").JSX.Element;
145
+ export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, ArrowsStartKeyboardNavigation, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }: CanvasProps): import("react").JSX.Element;
144
146
  export type { SkiaControl };
145
147
  export * from "../index";
146
148
  export * from "./SkiaShell";
@@ -97,7 +97,7 @@ export function OpenPopupWindow(canvas, content, anchor, options) {
97
97
  * Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
98
98
  * Requires Super.UseDrawnUi()...BuildAsync() to have completed.
99
99
  */
100
- export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }) {
100
+ export function Canvas({ BackgroundColor, RenderingMode, Gestures, ArrowsStartKeyboardNavigation, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }) {
101
101
  const ref = useRef(null);
102
102
  const view = useRef(null);
103
103
  const root = useRef(null);
@@ -127,13 +127,16 @@ export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, sty
127
127
  v.Update();
128
128
  }
129
129
  v.Gestures = Gestures ?? "Disabled";
130
+ v.ArrowsStartKeyboardNavigation = ArrowsStartKeyboardNavigation ?? false;
130
131
  v.ContextMenu = ContextMenu;
131
132
  v.WillFirstTimeDraw = WillFirstTimeDraw;
132
133
  v.WasDrawn = WasDrawn;
133
134
  root.current.render(children);
134
135
  });
135
- // The drawn surface is aria-hidden; the overlay is the accessibility tree (DrawnUi.Blazor pattern).
136
- return (_jsxs("div", { className: className, style: { position: "relative", ...style }, children: [_jsx("canvas", { ref: ref, "aria-hidden": true, style: { display: "block", width: "100%", height: "100%" } }), engine && _jsx(AccessibilityOverlay, { view: engine })] }));
136
+ // The drawn surface is aria-hidden; the overlay is the accessibility tree (DrawnUi.Blazor pattern). The host takes the
137
+ // DOM focus (from code only, no ring) when the focused control leaves: no control is focused and the keys belong to the
138
+ // app, as in the other engines, while a screen reader stays at the canvas instead of the top of the page.
139
+ return (_jsxs("div", { className: className, tabIndex: -1, "data-drawnui-host": "1", style: { position: "relative", outline: "none", ...style }, children: [_jsx("canvas", { ref: ref, "aria-hidden": true, style: { display: "block", width: "100%", height: "100%" } }), engine && _jsx(AccessibilityOverlay, { view: engine })] }));
137
140
  }
138
141
  const A11Y_CSS = `
139
142
  .drawnui-a11y-overlay{position:absolute;inset:0;overflow:hidden;pointer-events:none;user-select:none;-webkit-user-select:none}
@@ -180,22 +183,21 @@ function AccessibilityOverlay({ view }) {
180
183
  setFocusRequest(undefined);
181
184
  elementOf(focusRequest.id)?.focus({ preventScroll: true });
182
185
  }, [focusRequest]);
183
- // the focused node went away (its page or popup closed): the focus goes to the first Tab stop on screen in reading
184
- // order instead of falling back to the page (drawnui-cross 6c refocus); a focus the user moved away stays away
186
+ // the focused node went away (its page or popup closed): no control keeps the focus and its ring goes with it, the keys
187
+ // belong to the app again (as in the other engines); the DOM focus stays on the canvas host, so a screen reader is not
188
+ // thrown to the top of the page and the next Tab starts from the canvas. A focus the user moved away stays away.
185
189
  const focusedId = useRef(0);
186
190
  useLayoutEffect(() => {
187
191
  const id = focusedId.current;
188
192
  if (!id || nodes.some((n) => n.Id === id))
189
193
  return;
190
194
  focusedId.current = 0;
195
+ if (view.AccessibilityManager.FocusedNode?.AccessibilityId === id)
196
+ view.AccessibilityManager.NotifyFocused(undefined);
191
197
  const active = document.activeElement;
192
198
  if (active && active !== document.body)
193
199
  return;
194
- const box = overlayRef.current?.getBoundingClientRect();
195
- const first = nodes.find((n) => n.CanInteract && view.AccessibilityManager.IsTabStop(n.Source)
196
- && (!box || (n.Rect.Bottom > 0 && n.Rect.Top < box.height && n.Rect.Right > 0 && n.Rect.Left < box.width)));
197
- if (first)
198
- elementOf(first.Id)?.focus({ preventScroll: true });
200
+ overlayRef.current?.parentElement?.focus({ preventScroll: true });
199
201
  }, [nodes]);
200
202
  // Tab / Shift+Tab in a text field leave it for the next node, also after a click into it: DOM focus goes to the
201
203
  // field's own element (without taking the caret again) and the browser's Tab moves on from there
@@ -245,7 +247,13 @@ function AccessibilityOverlay({ view }) {
245
247
  return null;
246
248
  // the browser scrolls an overflow:hidden container to reveal a focused child; the overlay must stay pinned to the canvas
247
249
  const pin = (e) => { e.currentTarget.scrollTop = 0; e.currentTarget.scrollLeft = 0; };
248
- return (_jsxs("div", { className: "drawnui-a11y-overlay", onScroll: pin, ref: overlayRef, children: [_jsx("style", { children: A11Y_CSS }), nodes.map((n) => {
250
+ // an active modal (drawnui-cross 6av): the overlay itself is the dialog (role, name, aria-modal) around the dialog's
251
+ // controls, which are its elements; aria-modal on a separate element of this flat overlay would hide them
252
+ const modal = view.AccessibilityManager.ActiveModal;
253
+ const modalNode = modal ? nodes.find((n) => n.Source === modal) : undefined;
254
+ return (_jsxs("div", { className: "drawnui-a11y-overlay", onScroll: pin, ref: overlayRef, role: modal ? modalNode?.Role ?? "dialog" : undefined, "aria-label": modalNode?.Label, "aria-modal": modal ? true : undefined, children: [_jsx("style", { children: A11Y_CSS }), nodes.map((n) => {
255
+ if (n === modalNode)
256
+ return null;
249
257
  const pos = { left: n.Rect.Left, top: n.Rect.Top, width: n.Rect.Width, height: n.Rect.Height };
250
258
  const activate = () => SkiaAccessibilityManager.Activate(n.Source);
251
259
  return n.CanInteract ? (_jsx("div", { "data-a11y-id": n.Id, role: n.Role, "aria-label": n.Label, title: n.Hint, ...valueAttributes(n), "aria-pressed": n.Role === "button" ? n.IsPressed : undefined, "aria-checked": n.Role === "switch" || n.Role === "checkbox" || n.Role === "radio" ? n.IsPressed : undefined, "aria-live": n.Live, tabIndex: view.AccessibilityManager.IsTabStop(n.Source) ? 0 : -1, className: "drawnui-a11y-node", style: { ...pos, fontSize: 0, userSelect: "none" }, onClick: activate, onKeyDown: (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawnui-react",
3
- "version": "0.1.0-preview.36",
3
+ "version": "0.1.0-preview.37",
4
4
  "description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
5
5
  "license": "MIT",
6
6
  "author": "Nick Kovalsky (AppoMobi)",
@@ -91,6 +91,7 @@
91
91
  "check:stack-fit": "node dev/check.mjs dev/check-stack-fit.ts",
92
92
  "check:label-reuse": "node dev/check.mjs dev/check-label-reuse.ts",
93
93
  "check:popups-tooltips": "node dev/check.mjs dev/check-popups-tooltips.ts",
94
+ "check:carousel-loop": "node dev/check.mjs dev/check-carousel-loop.ts",
94
95
  "bench:relayout": "node dev/check.mjs dev/bench-relayout.ts",
95
96
  "site:extras": "node dev/site-extras.mjs dist/demo",
96
97
  "build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",