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

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 (52) hide show
  1. package/README.md +87 -13
  2. package/SKIPPED.md +6 -5
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +2 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +2 -0
  5. package/dist/controls/DrawnGame.d.ts +5 -1
  6. package/dist/controls/DrawnGame.js +22 -4
  7. package/dist/controls/SkiaCarousel.d.ts +1 -1
  8. package/dist/controls/SkiaCarousel.js +36 -4
  9. package/dist/controls/SkiaDrawer.d.ts +13 -0
  10. package/dist/controls/SkiaDrawer.js +40 -7
  11. package/dist/controls/SkiaEditor.d.ts +3 -1
  12. package/dist/controls/SkiaEditor.js +5 -0
  13. package/dist/controls/SkiaGif.d.ts +4 -0
  14. package/dist/controls/SkiaGif.js +13 -2
  15. package/dist/controls/SkiaImage.d.ts +5 -0
  16. package/dist/controls/SkiaImage.js +33 -4
  17. package/dist/controls/SkiaLabel.d.ts +7 -1
  18. package/dist/controls/SkiaLabel.js +9 -3
  19. package/dist/controls/SkiaLayout.js +3 -1
  20. package/dist/controls/SkiaLottie.js +1 -1
  21. package/dist/controls/SkiaRadioButton.d.ts +2 -0
  22. package/dist/controls/SkiaRadioButton.js +10 -0
  23. package/dist/controls/SkiaScroll.js +18 -9
  24. package/dist/controls/SkiaShaderCarousel.d.ts +6 -1
  25. package/dist/controls/SkiaShaderCarousel.js +22 -5
  26. package/dist/controls/SkiaSprite.d.ts +3 -0
  27. package/dist/controls/SkiaSprite.js +18 -10
  28. package/dist/controls/SkiaSvg.d.ts +4 -0
  29. package/dist/controls/SkiaSvg.js +27 -3
  30. package/dist/controls/SnappingLayout.js +2 -1
  31. package/dist/core/Accessibility.d.ts +41 -5
  32. package/dist/core/Accessibility.js +190 -9
  33. package/dist/core/Canvas.d.ts +49 -2
  34. package/dist/core/Canvas.js +152 -11
  35. package/dist/core/Gestures.d.ts +47 -0
  36. package/dist/core/Gestures.js +93 -0
  37. package/dist/core/ImageEffects.d.ts +2 -0
  38. package/dist/core/ImageEffects.js +2 -0
  39. package/dist/core/KeyboardManager.d.ts +20 -0
  40. package/dist/core/KeyboardManager.js +58 -15
  41. package/dist/core/PopupWindows.d.ts +2 -0
  42. package/dist/core/PopupWindows.js +2 -0
  43. package/dist/core/SkiaControl.d.ts +31 -1
  44. package/dist/core/SkiaControl.js +61 -5
  45. package/dist/core/Tooltips.d.ts +2 -0
  46. package/dist/core/Tooltips.js +10 -0
  47. package/dist/react/SkiaShell.js +32 -12
  48. package/dist/react/index.d.ts +4 -1
  49. package/dist/react/index.js +34 -16
  50. package/dist/react/reconciler.d.ts +18 -0
  51. package/dist/react/reconciler.js +31 -1
  52. package/package.json +16 -2
@@ -70,6 +70,11 @@ export declare class CachedObject {
70
70
  * Render(ctx) -> background + Paint(ctx),
71
71
  * ProcessGestures(args, apply) -> consumer or null.
72
72
  */
73
+ /**
74
+ * Controls holding something outside the tree while they are on a canvas (a focused editor's keys and caret timer, a
75
+ * game's keys): the canvas calls their OnLeftCanvas when they leave it with a removed or disposed subtree.
76
+ */
77
+ export declare const CanvasLeaveWatchers: Set<SkiaControl>;
73
78
  export declare class SkiaControl {
74
79
  HorizontalOptions: LayoutOptions;
75
80
  VerticalOptions: LayoutOptions;
@@ -373,6 +378,22 @@ export declare class SkiaControl {
373
378
  */
374
379
  get AccessibilityRole(): string | undefined;
375
380
  set AccessibilityRole(v: string | undefined);
381
+ /**
382
+ * On an arrow-key group (a container with a composite role such as `Aria.RoleMenu` or `Aria.RoleList`): the arrows go
383
+ * round, from the last item to the first and back, instead of stopping at the ends, as in desktop menus. Home / End
384
+ * unchanged. Default false (C# KeyboardWrap, Rust keyboard_wrap).
385
+ */
386
+ KeyboardWrap: boolean;
387
+ private accessibilityModal;
388
+ /**
389
+ * A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
390
+ * screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
391
+ * until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
392
+ * keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
393
+ * of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
394
+ */
395
+ get AccessibilityModal(): boolean;
396
+ set AccessibilityModal(v: boolean);
376
397
  /** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
377
398
  static DefaultAccessibilityRole?: string;
378
399
  /** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
@@ -410,6 +431,10 @@ export declare class SkiaControl {
410
431
  /** aria-pressed for toggles; undefined = not a toggle. */
411
432
  get AccessibilityIsPressed(): boolean | undefined;
412
433
  set AccessibilityIsPressed(v: boolean | undefined);
434
+ private accessibilityExpanded?;
435
+ /** A control that opens something, such as a menu title: whether it is open now (aria-expanded). Unset: it opens nothing. */
436
+ get AccessibilityExpanded(): boolean | undefined;
437
+ set AccessibilityExpanded(v: boolean | undefined);
413
438
  /** aria-live: `Aria.LivePolite` / `Aria.LiveAssertive`; changes are announced immediately. */
414
439
  get AccessibilityLive(): string | undefined;
415
440
  set AccessibilityLive(v: string | undefined);
@@ -467,6 +492,8 @@ export declare class SkiaControl {
467
492
  private static Align;
468
493
  /** Called after DrawingRect changed; layouts arrange children here. */
469
494
  protected OnLayoutChanged(): void;
495
+ /** A control in CanvasLeaveWatchers left its canvas (removed or disposed): it lets go of what it held there. */
496
+ OnLeftCanvas(): void;
470
497
  /** Part of DrawingRect that can actually be seen: intersected with every ancestor (a scroll's box clips its content). */
471
498
  GetVisibleViewport(): SKRect;
472
499
  /** Draws the control: from its cache when it has one, else background + Paint(); overlays always live. */
@@ -553,7 +580,10 @@ export declare class SkiaControl {
553
580
  CreateGradient(rect: SKRect, g: SkiaGradient): import("canvaskit-wasm").Shader | null;
554
581
  /** C# SkiaGradient.LinearGradientAngleToPoints (CSS angle -> start/end ratios). */
555
582
  static LinearGradientAngleToPoints(direction: number): [number, number, number, number];
556
- /** C# MakeDarker / MakeLighter: HSL lightness scaled down (light < 1) or pushed toward white (light > 1). */
583
+ /**
584
+ * A gradient's Light: below 1 red, green and blue multiplied by Light (C# MakeDarker, as Rust); above 1 the HSL
585
+ * lightness multiplied by Light, clamped to 1, hue and saturation kept (.NET MAUI Color.AddLuminosity, C# f77136c4).
586
+ */
557
587
  static AdjustLightness(rgb: [number, number, number], light: number): [number, number, number];
558
588
  /** Override to draw own content into ctx.Destination. */
559
589
  protected Paint(_ctx: DrawingContext): void;
@@ -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;
@@ -92,6 +92,11 @@ export class CachedObject {
92
92
  * Render(ctx) -> background + Paint(ctx),
93
93
  * ProcessGestures(args, apply) -> consumer or null.
94
94
  */
95
+ /**
96
+ * Controls holding something outside the tree while they are on a canvas (a focused editor's keys and caret timer, a
97
+ * game's keys): the canvas calls their OnLeftCanvas when they leave it with a removed or disposed subtree.
98
+ */
99
+ export const CanvasLeaveWatchers = new Set();
95
100
  export class SkiaControl {
96
101
  // ---- layout properties (points) ----
97
102
  HorizontalOptions = "Start";
@@ -611,11 +616,39 @@ export class SkiaControl {
611
616
  * ARIA role; setting it exposes the control to assistive technology (use `Aria` constants). Unset = the class
612
617
  * default (`SkiaLabel.DefaultAccessibilityRole` etc.), which is itself unset unless the app opts in.
613
618
  */
614
- get AccessibilityRole() { return this.accessibilityRole ?? this.constructor.DefaultAccessibilityRole; }
619
+ get AccessibilityRole() {
620
+ return this.accessibilityRole ?? (this.accessibilityModal ? Aria.RoleDialog : this.constructor.DefaultAccessibilityRole);
621
+ }
615
622
  set AccessibilityRole(v) { if (this.accessibilityRole !== v) {
616
623
  this.accessibilityRole = v;
617
624
  this.AccessibilityChanged();
618
625
  } }
626
+ /**
627
+ * On an arrow-key group (a container with a composite role such as `Aria.RoleMenu` or `Aria.RoleList`): the arrows go
628
+ * round, from the last item to the first and back, instead of stopping at the ends, as in desktop menus. Home / End
629
+ * unchanged. Default false (C# KeyboardWrap, Rust keyboard_wrap).
630
+ */
631
+ KeyboardWrap = false;
632
+ accessibilityModal = false;
633
+ /**
634
+ * A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
635
+ * screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
636
+ * until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
637
+ * keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
638
+ * of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
639
+ */
640
+ get AccessibilityModal() { return this.accessibilityModal; }
641
+ set AccessibilityModal(v) {
642
+ if (this.accessibilityModal === v)
643
+ return;
644
+ this.accessibilityModal = v;
645
+ if (v)
646
+ AccessibilityModals.add(this);
647
+ else
648
+ AccessibilityModals.delete(this);
649
+ this.AccessibilityChanged();
650
+ this.Superview?.Update();
651
+ }
619
652
  /** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
620
653
  static DefaultAccessibilityRole;
621
654
  /** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
@@ -677,6 +710,13 @@ export class SkiaControl {
677
710
  this.accessibilityIsPressed = v;
678
711
  this.AccessibilityChanged();
679
712
  } }
713
+ accessibilityExpanded;
714
+ /** A control that opens something, such as a menu title: whether it is open now (aria-expanded). Unset: it opens nothing. */
715
+ get AccessibilityExpanded() { return this.accessibilityExpanded; }
716
+ set AccessibilityExpanded(v) { if (this.accessibilityExpanded !== v) {
717
+ this.accessibilityExpanded = v;
718
+ this.AccessibilityChanged();
719
+ } }
680
720
  /** aria-live: `Aria.LivePolite` / `Aria.LiveAssertive`; changes are announced immediately. */
681
721
  get AccessibilityLive() { return this.accessibilityLive; }
682
722
  set AccessibilityLive(v) { if (this.accessibilityLive !== v) {
@@ -800,6 +840,8 @@ export class SkiaControl {
800
840
  }
801
841
  /** Called after DrawingRect changed; layouts arrange children here. */
802
842
  OnLayoutChanged() { }
843
+ /** A control in CanvasLeaveWatchers left its canvas (removed or disposed): it lets go of what it held there. */
844
+ OnLeftCanvas() { }
803
845
  /** Part of DrawingRect that can actually be seen: intersected with every ancestor (a scroll's box clips its content). */
804
846
  GetVisibleViewport() {
805
847
  const r = this.DrawingRect;
@@ -1378,9 +1420,16 @@ export class SkiaControl {
1378
1420
  ey = 0;
1379
1421
  return [sx, sy, ex, ey];
1380
1422
  }
1381
- /** C# MakeDarker / MakeLighter: HSL lightness scaled down (light < 1) or pushed toward white (light > 1). */
1423
+ /**
1424
+ * A gradient's Light: below 1 red, green and blue multiplied by Light (C# MakeDarker, as Rust); above 1 the HSL
1425
+ * lightness multiplied by Light, clamped to 1, hue and saturation kept (.NET MAUI Color.AddLuminosity, C# f77136c4).
1426
+ */
1382
1427
  static AdjustLightness(rgb, light) {
1383
1428
  const [r, g, b] = rgb;
1429
+ if (light < 1) {
1430
+ const k = Math.max(0, light);
1431
+ return [r * k, g * k, b * k];
1432
+ }
1384
1433
  const max = Math.max(r, g, b), min = Math.min(r, g, b);
1385
1434
  let h = 0, s = 0;
1386
1435
  let l = (max + min) / 2;
@@ -1395,7 +1444,7 @@ export class SkiaControl {
1395
1444
  h = (r - g) / d + 4;
1396
1445
  h /= 6;
1397
1446
  }
1398
- l = light < 1 ? l * light : l + (1 - l) * (light - 1);
1447
+ l = l * light;
1399
1448
  l = Math.max(0, Math.min(1, l));
1400
1449
  if (s === 0)
1401
1450
  return [l, l, l];
@@ -1420,13 +1469,20 @@ export class SkiaControl {
1420
1469
  Dispose() {
1421
1470
  if (this.IsDisposed)
1422
1471
  return;
1472
+ // disposed while still on a canvas: its subtree's animators stop, once, from the top disposed control
1473
+ if (!this.Parent?.IsDisposed)
1474
+ this.Superview?.ControlLeft(this, true);
1423
1475
  this.IsDisposed = true;
1476
+ if (this.accessibilityModal)
1477
+ AccessibilityModals.delete(this);
1424
1478
  this.OnDisposing();
1425
1479
  for (const c of this.ownAnimations.values())
1426
1480
  c.abort();
1427
1481
  this.ownAnimations.clear();
1428
1482
  for (const e of [...this.PostAnimators])
1429
1483
  e.Stop?.();
1484
+ for (const a of [...(this.PendingUnattachedAnimators ?? [])])
1485
+ a.Stop(); // waiting since it was removed: they end with it
1430
1486
  this.PendingUnattachedAnimators = undefined;
1431
1487
  this.PostAnimators.length = 0;
1432
1488
  this.DestroyRenderingObject();
@@ -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;
@@ -213,7 +213,10 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
213
213
  const closeWhenBackgroundTapped = options?.closeWhenBackgroundTapped ?? true;
214
214
  const showOverlay = options?.showOverlay ?? true;
215
215
  const overlay = options?.backgroundColor ?? ShellDefaults.PopupBackgroundColor;
216
- entry.node = (_jsxs(SkiaLayer, { VerticalOptions: "Fill", HorizontalOptions: "Fill", ZIndex: ShellDefaults.ZIndexPopups + entry.id, BlockGesturesBelow: true, Opacity: animated ? 0.1 : 1, ref: (c) => { if (c)
216
+ entry.node = (
217
+ // a dialog for screen readers and the keyboard while open (drawnui-cross 6av, C# 2be842b8): its outside-tap close
218
+ // stays, but the wrapper is no Tab stop; the backdrop is no node
219
+ _jsxs(SkiaLayer, { VerticalOptions: "Fill", HorizontalOptions: "Fill", ZIndex: ShellDefaults.ZIndexPopups + entry.id, BlockGesturesBelow: true, Opacity: animated ? 0.1 : 1, AccessibilityModal: true, AccessibilityCanInteract: false, ref: (c) => { if (c)
217
220
  entry.ctrl = c; }, Tapped: (_, e) => {
218
221
  // C# PopupWrapper: a tap outside the content closes it
219
222
  const c = entry.content;
@@ -236,12 +239,28 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
236
239
  await closePopup(p, false); }, [closePopup]);
237
240
  // ---- modals ----
238
241
  const removeModal = useCallback((m) => setModals((list) => list.filter((x) => x !== m)), []);
242
+ /**
243
+ * A modal leaves the modal stack the moment its close starts, whatever started it (PopModalAsync, a swipe, IsOpen =
244
+ * false): ModalsCount and CanGoBack drop it and Navigated Pop is raised; its drawer takes no more pans. It stays on
245
+ * screen until its slide ends (drawnui-cross 6s, C# SkiaShell.LeaveModalStack).
246
+ */
247
+ const [, setStackChanged] = useState(0);
248
+ const leaveModalStack = useCallback((m) => {
249
+ if (m.left)
250
+ return;
251
+ m.left = true;
252
+ if (m.drawer)
253
+ m.drawer.RespondsToGestures = false;
254
+ setStackChanged((t) => t + 1);
255
+ navigated(live.current.stack[live.current.stack.length - 1] ?? "", "Pop");
256
+ }, [navigated]);
239
257
  const popModalNow = useCallback(async (top, animated) => {
240
258
  if (top.closing)
241
259
  return false;
242
260
  if (!canNavigate(live.current.stack[live.current.stack.length - 1] ?? "", "Pop", top.drawer, top.drawer))
243
261
  return false;
244
262
  top.closing = true;
263
+ leaveModalStack(top);
245
264
  if (top.drawer && top.drawer.IsOpen) {
246
265
  top.drawer.Animated = animated;
247
266
  const done = new Promise((r) => { const prev = top.drawer.StateTransitionComplete; top.drawer.StateTransitionComplete = (d, o) => { prev?.(d, o); if (!o)
@@ -251,9 +270,8 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
251
270
  await AnimateWithTimeout(done);
252
271
  }
253
272
  removeModal(top);
254
- navigated(live.current.stack[live.current.stack.length - 1] ?? "", "Pop");
255
273
  return true;
256
- }, [removeModal, canNavigate, navigated]);
274
+ }, [removeModal, canNavigate, leaveModalStack]);
257
275
  const PushModalAsync = useCallback(async (content, options) => {
258
276
  const animated = options?.animated ?? true;
259
277
  if (!canNavigate(live.current.stack[live.current.stack.length - 1] ?? "", "Push"))
@@ -270,8 +288,10 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
270
288
  entry.closing = true;
271
289
  removeModal(entry);
272
290
  } };
273
- entry.node = (_jsxs(SkiaLayer, { VerticalOptions: "Fill", HorizontalOptions: "Fill", ZIndex: ShellDefaults.ZIndexModals + entry.id, BlockGesturesBelow: true, children: [overlay && _jsx(SkiaBackdrop, { Blur: ShellDefaults.PopupsBackgroundBlur, BackgroundColor: overlay, InputTransparent: true }), _jsx(SkiaDrawer, { ref: (d) => { if (d)
274
- entry.drawer = d; }, Direction: "FromBottom", HeaderSize: 0, HorizontalOptions: "Fill", VerticalOptions: "Fill", RespondsToGestures: options?.useGestures ?? false, Animated: animated, Bounces: false, BlockGesturesBelow: true, StateTransitionComplete: (d, isOpen) => { if (isOpen)
291
+ entry.node = (
292
+ // a dialog for screen readers and the keyboard while open (drawnui-cross 6av, C# 2be842b8)
293
+ _jsxs(SkiaLayer, { VerticalOptions: "Fill", HorizontalOptions: "Fill", ZIndex: ShellDefaults.ZIndexModals + entry.id, BlockGesturesBelow: true, AccessibilityModal: true, children: [overlay && _jsx(SkiaBackdrop, { Blur: ShellDefaults.PopupsBackgroundBlur, BackgroundColor: overlay, InputTransparent: true }), _jsx(SkiaDrawer, { ref: (d) => { if (d)
294
+ entry.drawer = d; }, Direction: "FromBottom", HeaderSize: 0, HorizontalOptions: "Fill", VerticalOptions: "Fill", RespondsToGestures: options?.useGestures ?? false, Animated: animated, Bounces: false, BlockGesturesBelow: true, ClosingStarted: () => leaveModalStack(entry), StateTransitionComplete: (d, isOpen) => { if (isOpen)
275
295
  opened();
276
296
  else if (!d.IsOpen)
277
297
  userClosed(); }, IsOpenChanged: (_, isOpen) => { if (!isOpen && !animated)
@@ -288,10 +308,9 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
288
308
  }
289
309
  await AnimateWithTimeout(openedPromise);
290
310
  navigated(live.current.stack[live.current.stack.length - 1] ?? "", "Push", drawer);
291
- }, [removeModal, pushHistory, backThroughHistory, canNavigate, navigated]);
311
+ }, [removeModal, pushHistory, backThroughHistory, canNavigate, navigated, leaveModalStack]);
292
312
  const PopModalAsync = useCallback(async (animated = true) => {
293
- const list = live.current.modals;
294
- const top = list[list.length - 1];
313
+ const top = [...live.current.modals].reverse().find((m) => !m.left); // a modal sliding out has left the stack
295
314
  if (!top || top.closing)
296
315
  return;
297
316
  if (top.history && backThroughHistory("modal")) {
@@ -340,7 +359,7 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
340
359
  await closePopup(ps[ps.length - 1], animated);
341
360
  return;
342
361
  }
343
- if (ms.length) {
362
+ if (ms.some((m) => !m.left)) {
344
363
  await PopModalAsync(animated);
345
364
  return;
346
365
  }
@@ -465,12 +484,13 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
465
484
  window.addEventListener("popstate", onPop);
466
485
  return () => window.removeEventListener("popstate", onPop);
467
486
  }, [historyOn, Routes, closePopupNow, popModalNow, popPage]);
487
+ const inStack = modals.filter((m) => !m.left).length; // modals sliding out have left the stack
468
488
  const nav = useMemo(() => ({
469
- GoToAsync, GoBackAsync, PopToRootAsync, NavigationStack: stack, CanGoBack: stack.length > 0 || popups.length > 0 || modals.length > 0, Route: route, Arguments: { ...SplitRoute(route).args, ...argsInMemory.current.get(route) },
489
+ GoToAsync, GoBackAsync, PopToRootAsync, NavigationStack: stack, CanGoBack: stack.length > 0 || popups.length > 0 || inStack > 0, Route: route, Arguments: { ...SplitRoute(route).args, ...argsInMemory.current.get(route) },
470
490
  OpenPopupAsync, ClosePopupAsync, CloseAllPopups, PushModalAsync, PopModalAsync, ShowToast, CloseAllToasts,
471
- PopupsCount: popups.length, ModalsCount: modals.length, ToastsCount: toasts.length,
491
+ PopupsCount: popups.length, ModalsCount: inStack, ToastsCount: toasts.length,
472
492
  SelectedTab: selectedTab, SelectTabAsync, PopTabToRootAsync,
473
- }), [GoToAsync, GoBackAsync, PopToRootAsync, stack, route, OpenPopupAsync, ClosePopupAsync, CloseAllPopups, PushModalAsync, PopModalAsync, ShowToast, CloseAllToasts, popups.length, modals.length, toasts.length, selectedTab, SelectTabAsync, PopTabToRootAsync]);
493
+ }), [GoToAsync, GoBackAsync, PopToRootAsync, stack, route, OpenPopupAsync, ClosePopupAsync, CloseAllPopups, PushModalAsync, PopModalAsync, ShowToast, CloseAllToasts, popups.length, inStack, toasts.length, selectedTab, SelectTabAsync, PopTabToRootAsync]);
474
494
  useImperativeHandle(ref, () => nav, [nav]);
475
495
  const visiblePages = leaving && !stack.includes(leaving) ? [...stack, leaving] : stack;
476
496
  const topRoute = visiblePages[visiblePages.length - 1] ?? "";
@@ -36,6 +36,7 @@ import { SkiaScroll as SkiaScrollCtrl } from "../controls/SkiaScroll";
36
36
  import type { SkiaShape as SkiaShapeCtrl } from "../controls/SkiaShape";
37
37
  import type { Color, RenderingModeType } from "../core/Types";
38
38
  import type { GesturesMode } from "../core/Gestures";
39
+ export { DesignerSourceOf, type DesignerSource } from "./reconciler";
39
40
  /**
40
41
  * Public settable properties of a control become its JSX props, same PascalCase names as C#.
41
42
  *
@@ -114,6 +115,8 @@ export interface CanvasProps {
114
115
  * scrolls it unless a control used the wheel. A page that cannot scroll keeps every touch. Lock keeps all input.
115
116
  */
116
117
  Gestures?: GesturesMode;
118
+ /** While nothing has keyboard focus, an arrow key starts keyboard navigation as the first Tab does (off by default: games keep their arrows). */
119
+ ArrowsStartKeyboardNavigation?: boolean;
117
120
  children?: ReactNode;
118
121
  style?: CSSProperties;
119
122
  className?: string;
@@ -140,7 +143,7 @@ export declare function OpenPopupWindow(canvas: CanvasView, content: ReactNode,
140
143
  * Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
141
144
  * Requires Super.UseDrawnUi()...BuildAsync() to have completed.
142
145
  */
143
- export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }: CanvasProps): import("react").JSX.Element;
146
+ export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, ArrowsStartKeyboardNavigation, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }: CanvasProps): import("react").JSX.Element;
144
147
  export type { SkiaControl };
145
148
  export * from "../index";
146
149
  export * from "./SkiaShell";
@@ -1,11 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
3
3
  import { SkiaAccessibilityManager } from "../core/Accessibility";
4
+ import { KeyboardManager } from "../core/KeyboardManager";
4
5
  import { TextInputProxy } from "../core/TextInputProxy";
5
6
  import { Canvas as CanvasView } from "../core/Canvas";
6
7
  import { SkiaEditor as SkiaEditorCtrl } from "../controls/SkiaEditor";
7
8
  import { SkiaScroll as SkiaScrollCtrl } from "../controls/SkiaScroll";
8
9
  import { createDrawnRoot } from "./reconciler";
10
+ export { DesignerSourceOf } from "./reconciler";
9
11
  /** Typed JSX tags resolved by the reconciler Registry. */
10
12
  export const SkiaLayout = "SkiaLayout";
11
13
  export const SkiaStack = "SkiaStack";
@@ -97,7 +99,7 @@ export function OpenPopupWindow(canvas, content, anchor, options) {
97
99
  * Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
98
100
  * Requires Super.UseDrawnUi()...BuildAsync() to have completed.
99
101
  */
100
- export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }) {
102
+ export function Canvas({ BackgroundColor, RenderingMode, Gestures, ArrowsStartKeyboardNavigation, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }) {
101
103
  const ref = useRef(null);
102
104
  const view = useRef(null);
103
105
  const root = useRef(null);
@@ -127,13 +129,16 @@ export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, sty
127
129
  v.Update();
128
130
  }
129
131
  v.Gestures = Gestures ?? "Disabled";
132
+ v.ArrowsStartKeyboardNavigation = ArrowsStartKeyboardNavigation ?? false;
130
133
  v.ContextMenu = ContextMenu;
131
134
  v.WillFirstTimeDraw = WillFirstTimeDraw;
132
135
  v.WasDrawn = WasDrawn;
133
136
  root.current.render(children);
134
137
  });
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 })] }));
138
+ // The drawn surface is aria-hidden; the overlay is the accessibility tree (DrawnUi.Blazor pattern). The host takes the
139
+ // DOM focus (from code only, no ring) when the focused control leaves: no control is focused and the keys belong to the
140
+ // app, as in the other engines, while a screen reader stays at the canvas instead of the top of the page.
141
+ 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
142
  }
138
143
  const A11Y_CSS = `
139
144
  .drawnui-a11y-overlay{position:absolute;inset:0;overflow:hidden;pointer-events:none;user-select:none;-webkit-user-select:none}
@@ -170,7 +175,7 @@ function AccessibilityOverlay({ view }) {
170
175
  setNodes(mgr.Snapshot);
171
176
  const off = mgr.OnChanged(() => setNodes(mgr.Snapshot));
172
177
  const offLive = mgr.OnLiveRegionUpdated(() => { mgr.ForceRebuildOnNextFrame(); view.Update(); });
173
- const offFocus = mgr.OnKeyboardFocusRequested((node) => { setNodes(mgr.Snapshot); setFocusRequest({ id: node.AccessibilityId }); });
178
+ const offFocus = mgr.OnKeyboardFocusRequested((node) => { setNodes(mgr.Snapshot); setFocusRequest({ id: node?.AccessibilityId ?? 0 }); });
174
179
  return () => { off(); offLive(); offFocus(); };
175
180
  }, [view]);
176
181
  const elementOf = (id) => overlayRef.current?.querySelector(`[data-a11y-id="${id}"]`) ?? undefined;
@@ -178,24 +183,27 @@ function AccessibilityOverlay({ view }) {
178
183
  if (!focusRequest)
179
184
  return;
180
185
  setFocusRequest(undefined);
181
- elementOf(focusRequest.id)?.focus({ preventScroll: true });
186
+ // no node: the app took the focus away (SetAccessibilityFocus()), the DOM focus goes back to the canvas host
187
+ if (!focusRequest.id)
188
+ overlayRef.current?.parentElement?.focus({ preventScroll: true });
189
+ else
190
+ elementOf(focusRequest.id)?.focus({ preventScroll: true });
182
191
  }, [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
192
+ // the focused node went away (its page or popup closed): no control keeps the focus and its ring goes with it, the keys
193
+ // belong to the app again (as in the other engines); the DOM focus stays on the canvas host, so a screen reader is not
194
+ // thrown to the top of the page and the next Tab starts from the canvas. A focus the user moved away stays away.
185
195
  const focusedId = useRef(0);
186
196
  useLayoutEffect(() => {
187
197
  const id = focusedId.current;
188
198
  if (!id || nodes.some((n) => n.Id === id))
189
199
  return;
190
200
  focusedId.current = 0;
201
+ if (view.AccessibilityManager.FocusedNode?.AccessibilityId === id)
202
+ view.AccessibilityManager.NotifyFocused(undefined);
191
203
  const active = document.activeElement;
192
204
  if (active && active !== document.body)
193
205
  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 });
206
+ overlayRef.current?.parentElement?.focus({ preventScroll: true });
199
207
  }, [nodes]);
200
208
  // 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
209
  // field's own element (without taking the caret again) and the browser's Tab moves on from there
@@ -245,13 +253,21 @@ function AccessibilityOverlay({ view }) {
245
253
  return null;
246
254
  // the browser scrolls an overflow:hidden container to reveal a focused child; the overlay must stay pinned to the canvas
247
255
  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) => {
256
+ // an active modal (drawnui-cross 6av): the overlay itself is the dialog (role, name, aria-modal) around the dialog's
257
+ // controls, which are its elements; aria-modal on a separate element of this flat overlay would hide them
258
+ const modal = view.AccessibilityManager.ActiveModal;
259
+ const modalNode = modal ? nodes.find((n) => n.Source === modal) : undefined;
260
+ 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) => {
261
+ if (n === modalNode)
262
+ return null;
249
263
  const pos = { left: n.Rect.Left, top: n.Rect.Top, width: n.Rect.Width, height: n.Rect.Height };
250
264
  const activate = () => SkiaAccessibilityManager.Activate(n.Source);
251
- 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) => {
265
+ 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-expanded": n.Expanded, "aria-haspopup": n.Expanded !== undefined && n.Role === "menuitem" ? "menu" : 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) => {
266
+ // the canvas navigation gets the key first; the app's KeyDown runs after it with IsKeyHandled (6az)
252
267
  if (e.key === "Enter" || e.key === " ") {
253
268
  e.preventDefault();
254
- activate();
269
+ if (activate())
270
+ KeyboardManager.MarkKeyHandled(e.nativeEvent.code);
255
271
  }
256
272
  else if (e.key === "Tab" && view.AccessibilityManager.KeyboardScope) {
257
273
  // an open popup window keeps the keyboard: Tab goes round its stops (a menu is one stop)
@@ -260,8 +276,10 @@ function AccessibilityOverlay({ view }) {
260
276
  if (next)
261
277
  elementOf(next.AccessibilityId)?.focus({ preventScroll: true });
262
278
  }
263
- else if (NAVIGATION_KEYS.has(e.key) && SkiaAccessibilityManager.Key(n.Source, e.key))
279
+ else if (NAVIGATION_KEYS.has(e.key) && SkiaAccessibilityManager.Key(n.Source, e.key)) {
264
280
  e.preventDefault();
281
+ KeyboardManager.MarkKeyHandled(e.nativeEvent.code);
282
+ }
265
283
  }, onFocus: (e) => {
266
284
  focusedId.current = n.Id;
267
285
  pin({ currentTarget: e.currentTarget.parentElement });
@@ -6,6 +6,24 @@ import { TextSpan } from "../controls/TextSpan";
6
6
  type HostInstance = SkiaControl | TextSpan;
7
7
  /** JSX tag name -> engine class. Add a control here to expose it to React. */
8
8
  export declare const Registry: Record<string, new () => HostInstance>;
9
+ /** What DrawnUI Designer reads about the JSX element that created a control (dev builds; undefined in production). */
10
+ export interface DesignerSource {
11
+ /** The React fiber that created the control. */
12
+ Fiber: unknown;
13
+ /** The name of the component that rendered the element (the fiber's owner). */
14
+ Component?: string;
15
+ /** The raw stack captured where the element was created. */
16
+ Stack?: string;
17
+ /** The first app frame of that stack: positions in the served (transformed) module, map them through its source map. */
18
+ File?: string;
19
+ Line?: number;
20
+ Column?: number;
21
+ }
22
+ /**
23
+ * The JSX element that created `control`, for DrawnUI Designer: its fiber, owner component and source position (parsed
24
+ * from the fiber's stack only when asked). Undefined in production builds and for controls made outside React.
25
+ */
26
+ export declare function DesignerSourceOf(control: SkiaControl): DesignerSource | undefined;
9
27
  /** Creates a React root whose container is an engine Canvas. */
10
28
  export declare function createDrawnRoot(canvas: Canvas): {
11
29
  render(children: ReactNode): void;
@@ -76,6 +76,34 @@ function applyProps(inst, prev, next) {
76
76
  else if (repaint && prev)
77
77
  inst.RepaintComposition?.();
78
78
  }
79
+ // DrawnUI Designer, dev builds only: the React fiber that created each control (DesignerSourceOf). Vite replaces
80
+ // import.meta.env.DEV, false in production builds, so the map and its use compile away; without Vite it is undefined
81
+ // and nothing is kept.
82
+ const designerSources = import.meta.env?.DEV ? new WeakMap() : undefined;
83
+ /**
84
+ * The JSX element that created `control`, for DrawnUI Designer: its fiber, owner component and source position (parsed
85
+ * from the fiber's stack only when asked). Undefined in production builds and for controls made outside React.
86
+ */
87
+ export function DesignerSourceOf(control) {
88
+ if (!import.meta.env?.DEV)
89
+ return undefined;
90
+ const fiber = designerSources?.get(control);
91
+ if (!fiber)
92
+ return undefined;
93
+ const owner = fiber._debugOwner?.type;
94
+ const stack = fiber._debugStack?.stack;
95
+ const source = { Fiber: fiber, Component: typeof owner === "string" ? owner : owner?.displayName ?? owner?.name, Stack: stack };
96
+ // React's stack: "Error: react-stack-top-frame", the jsx runtime's own frame, then the frame that wrote the JSX
97
+ // ("at Card (url-or-path:line:col)", or "at url-or-path:line:col" for an anonymous function)
98
+ const frames = stack?.split("\n").filter((l) => /^\s*at /.test(l)) ?? [];
99
+ const m = frames.length > 1 ? /^\s*at (?:.*? \()?(.+?):(\d+):(\d+)\)?\s*$/.exec(frames[1]) : null;
100
+ if (m) {
101
+ source.File = m[1];
102
+ source.Line = Number(m[2]);
103
+ source.Column = Number(m[3]);
104
+ }
105
+ return source;
106
+ }
79
107
  let currentUpdatePriority = DefaultEventPriority;
80
108
  const noop = () => { };
81
109
  const hostContext = {};
@@ -97,7 +125,7 @@ const hostConfig = {
97
125
  cancelTimeout: clearTimeout,
98
126
  supportsMicrotasks: true,
99
127
  scheduleMicrotask: queueMicrotask,
100
- createInstance(type, props) {
128
+ createInstance(type, props, _root, _host, fiber) {
101
129
  const ctor = Registry[type];
102
130
  if (!ctor)
103
131
  throw new Error(`DrawnUi: unknown control <${type}>`);
@@ -105,6 +133,8 @@ const hostConfig = {
105
133
  // ConfigureStyles defaults first, the JSX props below override them (a TextSpan is not a control, it has none)
106
134
  inst.ApplyInitialStyles?.(true);
107
135
  applyProps(inst, null, props);
136
+ if (import.meta.env?.DEV)
137
+ designerSources.set(inst, fiber);
108
138
  return inst;
109
139
  },
110
140
  createTextInstance(text) {
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.38",
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,20 @@
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",
95
+ "check:release": "node dev/check.mjs dev/check-release.tsx",
96
+ "check:designer-dev": "node dev/check.mjs dev/check-designer-dev.tsx",
97
+ "check:keyboard-wrap": "node dev/check.mjs dev/check-keyboard-wrap.ts",
98
+ "check:removed": "node dev/check.mjs dev/check-removed.ts",
99
+ "check:key-routing": "node dev/check.mjs dev/check-key-routing.ts",
100
+ "check:drawer-interrupted": "node dev/check.mjs dev/check-drawer-interrupted.ts",
101
+ "check:animated-frames": "node dev/check.mjs dev/check-animated-frames.ts",
102
+ "check:image-features": "node dev/check.mjs dev/check-image-features.ts",
103
+ "check:shader-carousel-interrupted": "node dev/check.mjs dev/check-shader-carousel-interrupted.ts",
104
+ "check:shell-modal": "node dev/check.mjs dev/check-shell-modal.tsx",
105
+ "check:multitouch": "node dev/check.mjs dev/check-multitouch.ts",
106
+ "check:scroll-size": "node dev/check.mjs dev/check-scroll-size.ts",
107
+ "audit:a11y": "node dev/audit-a11y.mjs",
94
108
  "bench:relayout": "node dev/check.mjs dev/bench-relayout.ts",
95
109
  "site:extras": "node dev/site-extras.mjs dist/demo",
96
110
  "build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
@@ -125,6 +139,6 @@
125
139
  "react": "^19.2.0",
126
140
  "react-dom": "^19.2.0",
127
141
  "typescript": "^5.9.0",
128
- "vite": "^7.0.0"
142
+ "vite": "^7.3.7"
129
143
  }
130
144
  }