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

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 +94 -13
  2. package/SKIPPED.md +6 -6
  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/SkiaButton.d.ts +2 -2
  8. package/dist/controls/SkiaButton.js +3 -2
  9. package/dist/controls/SkiaCarousel.d.ts +1 -1
  10. package/dist/controls/SkiaCarousel.js +5 -1
  11. package/dist/controls/SkiaDrawer.d.ts +13 -0
  12. package/dist/controls/SkiaDrawer.js +40 -7
  13. package/dist/controls/SkiaEditor.d.ts +3 -1
  14. package/dist/controls/SkiaEditor.js +5 -0
  15. package/dist/controls/SkiaGif.d.ts +4 -0
  16. package/dist/controls/SkiaGif.js +13 -2
  17. package/dist/controls/SkiaImage.d.ts +5 -0
  18. package/dist/controls/SkiaImage.js +33 -4
  19. package/dist/controls/SkiaLabel.d.ts +7 -1
  20. package/dist/controls/SkiaLabel.js +11 -4
  21. package/dist/controls/SkiaLayout.js +3 -1
  22. package/dist/controls/SkiaLottie.js +1 -1
  23. package/dist/controls/SkiaRadioButton.d.ts +2 -0
  24. package/dist/controls/SkiaRadioButton.js +10 -0
  25. package/dist/controls/SkiaScroll.js +18 -9
  26. package/dist/controls/SkiaShaderCarousel.d.ts +6 -1
  27. package/dist/controls/SkiaShaderCarousel.js +17 -5
  28. package/dist/controls/SkiaSprite.d.ts +3 -0
  29. package/dist/controls/SkiaSprite.js +18 -10
  30. package/dist/controls/SkiaSvg.d.ts +4 -0
  31. package/dist/controls/SkiaSvg.js +27 -3
  32. package/dist/controls/SnappingLayout.js +2 -1
  33. package/dist/core/Accessibility.d.ts +26 -2
  34. package/dist/core/Accessibility.js +99 -5
  35. package/dist/core/Canvas.d.ts +34 -3
  36. package/dist/core/Canvas.js +104 -14
  37. package/dist/core/Gestures.d.ts +47 -0
  38. package/dist/core/Gestures.js +93 -0
  39. package/dist/core/ImageEffects.d.ts +2 -0
  40. package/dist/core/ImageEffects.js +2 -0
  41. package/dist/core/KeyboardManager.d.ts +20 -0
  42. package/dist/core/KeyboardManager.js +54 -13
  43. package/dist/core/PopupWindows.d.ts +2 -0
  44. package/dist/core/PopupWindows.js +2 -0
  45. package/dist/core/SkiaControl.d.ts +26 -1
  46. package/dist/core/SkiaControl.js +40 -3
  47. package/dist/react/SkiaShell.js +32 -12
  48. package/dist/react/index.d.ts +1 -0
  49. package/dist/react/index.js +15 -5
  50. package/dist/react/reconciler.d.ts +18 -0
  51. package/dist/react/reconciler.js +31 -1
  52. package/package.json +16 -2
@@ -14,6 +14,8 @@ export declare const SkiaImageEffects: {
14
14
  Darken(amount: number): ColorFilter;
15
15
  Lighten(amount: number): ColorFilter;
16
16
  Grayscale(): ColorFilter;
17
+ /** C# Grayscale2: the luminance weights the Grayscale effect uses (BlackAndWhite keeps Grayscale's). */
18
+ Grayscale2(): ColorFilter;
17
19
  Pastel(): ColorFilter;
18
20
  Sepia(): ColorFilter;
19
21
  InvertColors(): ColorFilter;
@@ -12,6 +12,8 @@ export const SkiaImageEffects = {
12
12
  Darken(amount) { const a = -amount / 255; return SkiaImageEffects.Matrix([1, 0, 0, 0, a, 0, 1, 0, 0, a, 0, 0, 1, 0, a, 0, 0, 0, 1, 0]); },
13
13
  Lighten(amount) { const a = amount / 255; return SkiaImageEffects.Matrix([1, 0, 0, 0, a, 0, 1, 0, 0, a, 0, 0, 1, 0, a, 0, 0, 0, 1, 0]); },
14
14
  Grayscale() { return SkiaImageEffects.Matrix([0.2989, 0.587, 0.114, 0, 0, 0.2989, 0.587, 0.114, 0, 0, 0.2989, 0.587, 0.114, 0, 0, 0, 0, 0, 1, 0]); },
15
+ /** C# Grayscale2: the luminance weights the Grayscale effect uses (BlackAndWhite keeps Grayscale's). */
16
+ Grayscale2() { return SkiaImageEffects.Matrix([0.21, 0.72, 0.07, 0, 0, 0.21, 0.72, 0.07, 0, 0, 0.21, 0.72, 0.07, 0, 0, 0, 0, 0, 1, 0]); },
15
17
  Pastel() { return SkiaImageEffects.Matrix([0.75, 0.25, 0.25, 0, 0, 0.25, 0.75, 0.25, 0, 0, 0.25, 0.25, 0.75, 0, 0, 0, 0, 0, 1, 0]); },
16
18
  Sepia() { return SkiaImageEffects.Matrix([0.393, 0.769, 0.189, 0, 0, 0.349, 0.686, 0.168, 0, 0, 0.272, 0.534, 0.131, 0, 0, 0, 0, 0, 1, 0]); },
17
19
  InvertColors() { return SkiaImageEffects.Matrix([-1, 0, 0, 0, 1, 0, -1, 0, 0, 1, 0, 0, -1, 0, 1, 0, 0, 0, 1, 0]); },
@@ -5,6 +5,11 @@
5
5
  * subscribes while focused. Characters typed into the hidden TextInputProxy textarea (IME, soft keyboard) arrive
6
6
  * as input events there, so its key events are not forwarded as KeyChar here (a React-port addition over
7
7
  * DrawnUi.Blazor, which has no DOM text input).
8
+ *
9
+ * One key routing order on every head (drawnui-cross 6az, C# KeyboardManager.IsKeyHandled): the canvas keyboard
10
+ * navigation gets a key first (an accessibility overlay node: activation, group arrows, slider steps; then the canvas'
11
+ * own handlers: Escape closing a popup window, arrows starting navigation), then the app's KeyDown handlers run with
12
+ * `IsKeyHandled` telling whether navigation used it. Tab belongs to the browser.
8
13
  */
9
14
  export type InputKey = string;
10
15
  export declare class KeyboardManager {
@@ -13,6 +18,17 @@ export declare class KeyboardManager {
13
18
  private static readonly keyDown;
14
19
  private static readonly keyUp;
15
20
  private static readonly keyChar;
21
+ private static readonly navigation;
22
+ private static usedKey?;
23
+ private static deferred?;
24
+ /**
25
+ * True while KeyDown handlers run for a key the canvas keyboard navigation already used: Enter / Space activated the
26
+ * focused control, an arrow moved inside a list or a menu or stepped a slider, Escape closed a popup window. An app
27
+ * handler that would act on the same key (a menu that opens on Enter) skips it, so one press does one thing.
28
+ */
29
+ static IsKeyHandled: boolean;
30
+ /** For the accessibility overlay and canvas navigation: `key` was used, the KeyDown raised next for it reports IsKeyHandled. */
31
+ static MarkKeyHandled(key: InputKey): void;
16
32
  static get IsShiftPressed(): boolean;
17
33
  static get IsControlPressed(): boolean;
18
34
  /** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
@@ -25,6 +41,10 @@ export declare class KeyboardManager {
25
41
  * went elsewhere) still counts, and one released elsewhere stops counting.
26
42
  */
27
43
  private static SyncModifiers;
44
+ private static RaiseKeyDown;
45
+ /** For the canvas: keyboard navigation that runs before the app's KeyDown handlers; returns true when it used the key. */
46
+ static SubscribeNavigation(handler: (key: InputKey, e: KeyboardEvent) => boolean): void;
47
+ static UnsubscribeNavigation(handler: (key: InputKey, e: KeyboardEvent) => boolean): void;
28
48
  static Subscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
29
49
  static Unsubscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
30
50
  /**
@@ -4,6 +4,17 @@ export class KeyboardManager {
4
4
  static keyDown = new Set();
5
5
  static keyUp = new Set();
6
6
  static keyChar = new Set();
7
+ static navigation = new Set();
8
+ static usedKey;
9
+ static deferred;
10
+ /**
11
+ * True while KeyDown handlers run for a key the canvas keyboard navigation already used: Enter / Space activated the
12
+ * focused control, an arrow moved inside a list or a menu or stepped a slider, Escape closed a popup window. An app
13
+ * handler that would act on the same key (a menu that opens on Enter) skips it, so one press does one thing.
14
+ */
15
+ static IsKeyHandled = false;
16
+ /** For the accessibility overlay and canvas navigation: `key` was used, the KeyDown raised next for it reports IsKeyHandled. */
17
+ static MarkKeyHandled(key) { KeyboardManager.usedKey = key; }
7
18
  static get IsShiftPressed() { return KeyboardManager.pressed.has("ShiftLeft") || KeyboardManager.pressed.has("ShiftRight"); }
8
19
  static get IsControlPressed() { return KeyboardManager.pressed.has("ControlLeft") || KeyboardManager.pressed.has("ControlRight") || KeyboardManager.pressed.has("MetaLeft") || KeyboardManager.pressed.has("MetaRight"); }
9
20
  /** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
@@ -17,26 +28,27 @@ export class KeyboardManager {
17
28
  // inside a cross-frame iframe the embedding page keeps DOM focus: a pointerdown pulls it to this window
18
29
  window.addEventListener("pointerdown", () => window.focus(), true);
19
30
  window.addEventListener("keydown", (e) => {
20
- const code = e.code || "";
21
31
  KeyboardManager.SyncModifiers(e);
22
- KeyboardManager.pressed.add(code);
23
- KeyboardManager.IsDispatchingKeyDown = true;
24
- try {
25
- for (const h of [...KeyboardManager.keyDown])
26
- h(code, e);
27
- }
28
- finally {
29
- KeyboardManager.IsDispatchingKeyDown = false;
32
+ KeyboardManager.pressed.add(e.code || "");
33
+ // a key for an overlay node: its keydown (the canvas navigation) runs first, the key is raised when it bubbles here
34
+ if (e.target?.dataset?.a11yId) {
35
+ KeyboardManager.deferred = e;
36
+ return;
30
37
  }
31
- const proxied = e.target?.dataset?.drawnuiTextInput === "1"; // TextInputProxy: characters come through its input events
32
- if (!proxied && e.key && e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey)
33
- for (const h of [...KeyboardManager.keyChar])
34
- h(e.key, e);
38
+ KeyboardManager.RaiseKeyDown(e);
35
39
  }, true);
40
+ window.addEventListener("keydown", (e) => {
41
+ if (KeyboardManager.deferred !== e)
42
+ return;
43
+ KeyboardManager.deferred = undefined;
44
+ KeyboardManager.RaiseKeyDown(e);
45
+ });
36
46
  window.addEventListener("keyup", (e) => {
37
47
  const code = e.code || "";
38
48
  KeyboardManager.SyncModifiers(e);
39
49
  KeyboardManager.pressed.delete(code);
50
+ if (KeyboardManager.usedKey === code)
51
+ KeyboardManager.usedKey = undefined;
40
52
  for (const h of [...KeyboardManager.keyUp])
41
53
  h(code, e);
42
54
  }, true);
@@ -61,6 +73,35 @@ export class KeyboardManager {
61
73
  sync(!!e.shiftKey, "ShiftLeft", "ShiftRight");
62
74
  sync(!!e.metaKey, "MetaLeft", "MetaRight");
63
75
  }
76
+ static RaiseKeyDown(e) {
77
+ const code = e.code || "";
78
+ let used = KeyboardManager.usedKey === code;
79
+ KeyboardManager.usedKey = undefined;
80
+ KeyboardManager.IsDispatchingKeyDown = true;
81
+ try {
82
+ // the canvas' own navigation (a popup window's Escape, arrows starting navigation), then the app with the result
83
+ if (!used)
84
+ for (const h of [...KeyboardManager.navigation])
85
+ if (h(code, e)) {
86
+ used = true;
87
+ break;
88
+ }
89
+ KeyboardManager.IsKeyHandled = used;
90
+ for (const h of [...KeyboardManager.keyDown])
91
+ h(code, e);
92
+ }
93
+ finally {
94
+ KeyboardManager.IsDispatchingKeyDown = false;
95
+ KeyboardManager.IsKeyHandled = false;
96
+ }
97
+ const proxied = e.target?.dataset?.drawnuiTextInput === "1"; // TextInputProxy: characters come through its input events
98
+ if (!proxied && e.key && e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey)
99
+ for (const h of [...KeyboardManager.keyChar])
100
+ h(e.key, e);
101
+ }
102
+ /** For the canvas: keyboard navigation that runs before the app's KeyDown handlers; returns true when it used the key. */
103
+ static SubscribeNavigation(handler) { KeyboardManager.AttachToKeyboard(); KeyboardManager.navigation.add(handler); }
104
+ static UnsubscribeNavigation(handler) { KeyboardManager.navigation.delete(handler); }
64
105
  static Subscribe(down, char, up) {
65
106
  KeyboardManager.AttachToKeyboard();
66
107
  KeyboardManager.keyDown.add(down);
@@ -64,6 +64,8 @@ export declare class PopupLayer {
64
64
  SwallowPress: boolean;
65
65
  constructor(canvas: PopupHostCanvas);
66
66
  get HasAny(): boolean;
67
+ /** The root controls of the open popup windows, bottom to top (a new array per call). */
68
+ get Roots(): SkiaControl[];
67
69
  get HasInteractive(): boolean;
68
70
  /** The content of the top popup window that takes input. */
69
71
  get TopInteractive(): SkiaControl | undefined;
@@ -61,6 +61,8 @@ export class PopupLayer {
61
61
  this.canvas = canvas;
62
62
  }
63
63
  get HasAny() { return this.popups.length > 0; }
64
+ /** The root controls of the open popup windows, bottom to top (a new array per call). */
65
+ get Roots() { return this.popups.map((p) => p.Root); }
64
66
  get HasInteractive() { return this.popups.some((p) => !p.Options.Passive); }
65
67
  /** The content of the top popup window that takes input. */
66
68
  get TopInteractive() { for (let i = this.popups.length - 1; i >= 0; i--)
@@ -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,12 @@ 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;
376
387
  private accessibilityModal;
377
388
  /**
378
389
  * A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
@@ -420,6 +431,10 @@ export declare class SkiaControl {
420
431
  /** aria-pressed for toggles; undefined = not a toggle. */
421
432
  get AccessibilityIsPressed(): boolean | undefined;
422
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);
423
438
  /** aria-live: `Aria.LivePolite` / `Aria.LiveAssertive`; changes are announced immediately. */
424
439
  get AccessibilityLive(): string | undefined;
425
440
  set AccessibilityLive(v: string | undefined);
@@ -477,6 +492,8 @@ export declare class SkiaControl {
477
492
  private static Align;
478
493
  /** Called after DrawingRect changed; layouts arrange children here. */
479
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;
480
497
  /** Part of DrawingRect that can actually be seen: intersected with every ancestor (a scroll's box clips its content). */
481
498
  GetVisibleViewport(): SKRect;
482
499
  /** Draws the control: from its cache when it has one, else background + Paint(); overlays always live. */
@@ -563,7 +580,10 @@ export declare class SkiaControl {
563
580
  CreateGradient(rect: SKRect, g: SkiaGradient): import("canvaskit-wasm").Shader | null;
564
581
  /** C# SkiaGradient.LinearGradientAngleToPoints (CSS angle -> start/end ratios). */
565
582
  static LinearGradientAngleToPoints(direction: number): [number, number, number, number];
566
- /** 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
+ */
567
587
  static AdjustLightness(rgb: [number, number, number], light: number): [number, number, number];
568
588
  /** Override to draw own content into ctx.Destination. */
569
589
  protected Paint(_ctx: DrawingContext): void;
@@ -648,6 +668,11 @@ export declare class SkiaControl {
648
668
  * ConsumeGestures hook -> children top-most first -> own Tapped. Returns the consumer or null.
649
669
  */
650
670
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
671
+ /**
672
+ * The gesture comes from a finger, a pen or the primary (left) mouse button (C# IsPrimaryPointer). Tap and press
673
+ * animations (Ripple) play only for those: a right or middle click raises its events but shows no tap feedback.
674
+ */
675
+ static IsPrimaryPointer(args: SkiaGesturesParameters): boolean;
651
676
  /** Fires Tapped (after AnimationTapped feedback); true when a handler existed (= consumed), like DrawnUi SendTapped. */
652
677
  protected SendTapped(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): boolean;
653
678
  /** Canvas-pixel touch location -> points relative to this control's top-left. */
@@ -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";
@@ -618,6 +623,12 @@ export class SkiaControl {
618
623
  this.accessibilityRole = v;
619
624
  this.AccessibilityChanged();
620
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;
621
632
  accessibilityModal = false;
622
633
  /**
623
634
  * A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
@@ -699,6 +710,13 @@ export class SkiaControl {
699
710
  this.accessibilityIsPressed = v;
700
711
  this.AccessibilityChanged();
701
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
+ } }
702
720
  /** aria-live: `Aria.LivePolite` / `Aria.LiveAssertive`; changes are announced immediately. */
703
721
  get AccessibilityLive() { return this.accessibilityLive; }
704
722
  set AccessibilityLive(v) { if (this.accessibilityLive !== v) {
@@ -822,6 +840,8 @@ export class SkiaControl {
822
840
  }
823
841
  /** Called after DrawingRect changed; layouts arrange children here. */
824
842
  OnLayoutChanged() { }
843
+ /** A control in CanvasLeaveWatchers left its canvas (removed or disposed): it lets go of what it held there. */
844
+ OnLeftCanvas() { }
825
845
  /** Part of DrawingRect that can actually be seen: intersected with every ancestor (a scroll's box clips its content). */
826
846
  GetVisibleViewport() {
827
847
  const r = this.DrawingRect;
@@ -1400,9 +1420,16 @@ export class SkiaControl {
1400
1420
  ey = 0;
1401
1421
  return [sx, sy, ex, ey];
1402
1422
  }
1403
- /** 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
+ */
1404
1427
  static AdjustLightness(rgb, light) {
1405
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
+ }
1406
1433
  const max = Math.max(r, g, b), min = Math.min(r, g, b);
1407
1434
  let h = 0, s = 0;
1408
1435
  let l = (max + min) / 2;
@@ -1417,7 +1444,7 @@ export class SkiaControl {
1417
1444
  h = (r - g) / d + 4;
1418
1445
  h /= 6;
1419
1446
  }
1420
- l = light < 1 ? l * light : l + (1 - l) * (light - 1);
1447
+ l = l * light;
1421
1448
  l = Math.max(0, Math.min(1, l));
1422
1449
  if (s === 0)
1423
1450
  return [l, l, l];
@@ -1442,6 +1469,9 @@ export class SkiaControl {
1442
1469
  Dispose() {
1443
1470
  if (this.IsDisposed)
1444
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);
1445
1475
  this.IsDisposed = true;
1446
1476
  if (this.accessibilityModal)
1447
1477
  AccessibilityModals.delete(this);
@@ -1451,6 +1481,8 @@ export class SkiaControl {
1451
1481
  this.ownAnimations.clear();
1452
1482
  for (const e of [...this.PostAnimators])
1453
1483
  e.Stop?.();
1484
+ for (const a of [...(this.PendingUnattachedAnimators ?? [])])
1485
+ a.Stop(); // waiting since it was removed: they end with it
1454
1486
  this.PendingUnattachedAnimators = undefined;
1455
1487
  this.PostAnimators.length = 0;
1456
1488
  this.DestroyRenderingObject();
@@ -1715,11 +1747,16 @@ export class SkiaControl {
1715
1747
  return this;
1716
1748
  return consumed ?? consumedDefault;
1717
1749
  }
1750
+ /**
1751
+ * The gesture comes from a finger, a pen or the primary (left) mouse button (C# IsPrimaryPointer). Tap and press
1752
+ * animations (Ripple) play only for those: a right or middle click raises its events but shows no tap feedback.
1753
+ */
1754
+ static IsPrimaryPointer(args) { return (args.Event.Pointer?.Button ?? "Left") === "Left"; }
1718
1755
  /** Fires Tapped (after AnimationTapped feedback); true when a handler existed (= consumed), like DrawnUi SendTapped. */
1719
1756
  SendTapped(args, apply) {
1720
1757
  if (!this.Tapped)
1721
1758
  return false;
1722
- if (this.AnimationTapped === "Ripple") {
1759
+ if (this.AnimationTapped === "Ripple" && SkiaControl.IsPrimaryPointer(args)) {
1723
1760
  const pts = this.GetOffsetInsideControlInPoints(apply.MappedLocation, apply.ChildOffset);
1724
1761
  this.PlayRippleAnimation(this.TouchEffectColor, pts.X, pts.Y, true, this.AnimationTappedSpeed);
1725
1762
  }
@@ -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
  *
@@ -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";
@@ -173,7 +175,7 @@ function AccessibilityOverlay({ view }) {
173
175
  setNodes(mgr.Snapshot);
174
176
  const off = mgr.OnChanged(() => setNodes(mgr.Snapshot));
175
177
  const offLive = mgr.OnLiveRegionUpdated(() => { mgr.ForceRebuildOnNextFrame(); view.Update(); });
176
- 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 }); });
177
179
  return () => { off(); offLive(); offFocus(); };
178
180
  }, [view]);
179
181
  const elementOf = (id) => overlayRef.current?.querySelector(`[data-a11y-id="${id}"]`) ?? undefined;
@@ -181,7 +183,11 @@ function AccessibilityOverlay({ view }) {
181
183
  if (!focusRequest)
182
184
  return;
183
185
  setFocusRequest(undefined);
184
- 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 });
185
191
  }, [focusRequest]);
186
192
  // the focused node went away (its page or popup closed): no control keeps the focus and its ring goes with it, the keys
187
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
@@ -256,10 +262,12 @@ function AccessibilityOverlay({ view }) {
256
262
  return null;
257
263
  const pos = { left: n.Rect.Left, top: n.Rect.Top, width: n.Rect.Width, height: n.Rect.Height };
258
264
  const activate = () => SkiaAccessibilityManager.Activate(n.Source);
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) => {
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)
260
267
  if (e.key === "Enter" || e.key === " ") {
261
268
  e.preventDefault();
262
- activate();
269
+ if (activate())
270
+ KeyboardManager.MarkKeyHandled(e.nativeEvent.code);
263
271
  }
264
272
  else if (e.key === "Tab" && view.AccessibilityManager.KeyboardScope) {
265
273
  // an open popup window keeps the keyboard: Tab goes round its stops (a menu is one stop)
@@ -268,8 +276,10 @@ function AccessibilityOverlay({ view }) {
268
276
  if (next)
269
277
  elementOf(next.AccessibilityId)?.focus({ preventScroll: true });
270
278
  }
271
- 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)) {
272
280
  e.preventDefault();
281
+ KeyboardManager.MarkKeyHandled(e.nativeEvent.code);
282
+ }
273
283
  }, onFocus: (e) => {
274
284
  focusedId.current = n.Id;
275
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) {