drawnui-react 0.1.0-preview.37 → 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 (50) hide show
  1. package/README.md +87 -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/SkiaCarousel.d.ts +1 -1
  8. package/dist/controls/SkiaCarousel.js +5 -1
  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 +17 -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 +26 -2
  32. package/dist/core/Accessibility.js +99 -5
  33. package/dist/core/Canvas.d.ts +34 -3
  34. package/dist/core/Canvas.js +104 -14
  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 +54 -13
  41. package/dist/core/PopupWindows.d.ts +2 -0
  42. package/dist/core/PopupWindows.js +2 -0
  43. package/dist/core/SkiaControl.d.ts +21 -1
  44. package/dist/core/SkiaControl.js +34 -2
  45. package/dist/react/SkiaShell.js +32 -12
  46. package/dist/react/index.d.ts +1 -0
  47. package/dist/react/index.js +15 -5
  48. package/dist/react/reconciler.d.ts +18 -0
  49. package/dist/react/reconciler.js +31 -1
  50. package/package.json +15 -2
@@ -1,5 +1,5 @@
1
1
  import type { Surface } from "canvaskit-wasm";
2
- import type { DrawingContext, SkiaControl } from "./SkiaControl";
2
+ import { type DrawingContext, type SkiaControl } from "./SkiaControl";
3
3
  import type { AnimatorBase } from "./Animators";
4
4
  import { SkiaAccessibilityManager } from "./Accessibility";
5
5
  import { HoverManager } from "./Hover";
@@ -61,6 +61,15 @@ export declare class Canvas {
61
61
  private popupKeysHooked;
62
62
  /** Raised when a popup window closed: picked, a press outside, Escape, the wheel, window blur or ClosePopupWindow. */
63
63
  readonly PopupWindowClosed: Set<(id: PopupId) => void>;
64
+ /** The root controls of the open popup windows, bottom to top: a read-only view for tools (a new array per read). */
65
+ get PopupWindowRoots(): readonly SkiaControl[];
66
+ private wasDrawnListeners?;
67
+ /**
68
+ * Handlers run at the end of every drawn frame, after the `WasDrawn` callback and before the surface is flushed (a
69
+ * tool drawing an overlay on `Surface.getCanvas()`). Made on first use: a canvas without listeners does no work.
70
+ */
71
+ get WasDrawnListeners(): Set<(sender: Canvas) => void>;
72
+ private readonly raiseWasDrawn;
64
73
  /**
65
74
  * Shows `content` over everything, opening from `anchor` the way native menus do: at a point (a right click, canvas
66
75
  * points), or below a rect or a control (a dropdown), flipped to the other side where it does not fit. It closes with
@@ -76,6 +85,19 @@ export declare class Canvas {
76
85
  ClosePopupWindows(): void;
77
86
  /** The popup window is still open. */
78
87
  IsPopupWindowOpen(id: PopupId): boolean;
88
+ /**
89
+ * Moves the keyboard and screen-reader focus to `control` at the end of the next frame, for app code such as a custom
90
+ * menu that moves its highlight (C# DrawnView.SetAccessibilityFocus). A control not drawn yet gets it once it is, within
91
+ * 3 seconds. It wins over the library's own moves in the same frame (a closed popup window giving the keyboard back to
92
+ * its opener); undefined cancels a move still waiting. The focus ring shows only if the keyboard is in use.
93
+ */
94
+ SetAccessibilityFocus(control?: SkiaControl): void;
95
+ /**
96
+ * The drawn control with the keyboard and screen-reader focus (C# KeyboardFocusNode). Set undefined to let no drawn
97
+ * control keep it: the DOM focus goes back to the canvas and the keys belong to the app; a control moves it there.
98
+ */
99
+ get KeyboardFocusNode(): SkiaControl | undefined;
100
+ set KeyboardFocusNode(control: SkiaControl | undefined);
79
101
  /** True while a popup window that takes input is open. */
80
102
  get HasPopupWindows(): boolean;
81
103
  /** The content of the top popup window that takes input. */
@@ -85,7 +107,6 @@ export declare class Canvas {
85
107
  RaisePopupWindowClosed(id: PopupId): void;
86
108
  private AfterPopupsChanged;
87
109
  private readonly onPopupKey;
88
- private readonly onPopupChar;
89
110
  private HookPopupKeys;
90
111
  private readonly onWindowBlur;
91
112
  private content?;
@@ -142,6 +163,13 @@ export declare class Canvas {
142
163
  readonly AnimatingControls: Map<number, AnimatorBase>;
143
164
  RegisterAnimator(animator: AnimatorBase): boolean;
144
165
  UnregisterAnimator(uid: number): void;
166
+ /**
167
+ * `root` leaves this canvas (removed from its parent, replaced as content, disposed): what runs for its subtree stops,
168
+ * as DrawnUi.Rust 44c718f. Its animators leave the frame loop: disposed, they stop; only removed, they pause and wait on
169
+ * their control (PendingUnattachedAnimators), going on from there when it is arranged on a canvas again. A focused editor in it loses the
170
+ * focus, a game in it stops getting keys (CanvasLeaveWatchers). Runs once per removal, never per frame.
171
+ */
172
+ ControlLeft(root: SkiaControl, disposed: boolean): void;
145
173
  /** Ticks every registered animator once; returns how many ran. */
146
174
  protected ExecuteAnimators(frameTimeNanos: number): number;
147
175
  private wakeTimer;
@@ -237,6 +265,10 @@ export declare class Canvas {
237
265
  private DetachInput;
238
266
  /** Port of DrawnUi.Blazor Canvas.OnTouchAction: per-pointer state machine producing Down / Panning / Tapped / Up. */
239
267
  OnTouchAction(args: TouchActionEventArgs): void;
268
+ /** The fingers down, for TouchActionEventArgs.Manipulation (pinch and turn). */
269
+ private readonly fingers;
270
+ /** The press had a second finger: it is no tap (AppoMobi.Blazor.Gestures). */
271
+ private multiTouch;
240
272
  private readonly longPressTimers;
241
273
  private readonly longPressed;
242
274
  /** The long press of a new press: due LongPressTimeMs later unless the pointer moves away or lets go. */
@@ -262,7 +294,6 @@ export declare class Canvas {
262
294
  */
263
295
  get ArrowsStartKeyboardNavigation(): boolean;
264
296
  set ArrowsStartKeyboardNavigation(v: boolean);
265
- private readonly onArrowChar;
266
297
  private readonly onArrowKey;
267
298
  private focusedChild?;
268
299
  private focusAtDown?;
@@ -1,3 +1,4 @@
1
+ import { CanvasLeaveWatchers } from "./SkiaControl";
1
2
  import { Super } from "./Super";
2
3
  import { SkiaAccessibilityManager } from "./Accessibility";
3
4
  import { HoverManager } from "./Hover";
@@ -5,7 +6,7 @@ import { TooltipController } from "./Tooltips";
5
6
  import { PopupAnchor, PopupLayer } from "./PopupWindows";
6
7
  import { KeyboardManager } from "./KeyboardManager";
7
8
  import { Colors, SKRect } from "./Types";
8
- import { ContextMenuEventArgs, GestureEventProcessingInfo, PointerData, SKPoint, SkiaGesturesParameters, TouchActionEventArgs, } from "./Gestures";
9
+ import { ContextMenuEventArgs, GestureEventProcessingInfo, MultitouchTracker, PointerData, SKPoint, SkiaGesturesParameters, TouchActionEventArgs, } from "./Gestures";
9
10
  /**
10
11
  * Mirrors DrawnUi Canvas (DrawnView): hosts one Content control on an HTML canvas element,
11
12
  * owns RenderingScale (devicePixelRatio), the surface, the on-demand frame loop and raw input.
@@ -62,6 +63,15 @@ export class Canvas {
62
63
  popupKeysHooked = false;
63
64
  /** Raised when a popup window closed: picked, a press outside, Escape, the wheel, window blur or ClosePopupWindow. */
64
65
  PopupWindowClosed = new Set();
66
+ /** The root controls of the open popup windows, bottom to top: a read-only view for tools (a new array per read). */
67
+ get PopupWindowRoots() { return this.popupLayer?.Roots ?? []; }
68
+ wasDrawnListeners;
69
+ /**
70
+ * Handlers run at the end of every drawn frame, after the `WasDrawn` callback and before the surface is flushed (a
71
+ * tool drawing an overlay on `Surface.getCanvas()`). Made on first use: a canvas without listeners does no work.
72
+ */
73
+ get WasDrawnListeners() { return this.wasDrawnListeners ??= new Set(); }
74
+ raiseWasDrawn = (f) => f(this);
65
75
  /**
66
76
  * Shows `content` over everything, opening from `anchor` the way native menus do: at a point (a right click, canvas
67
77
  * points), or below a rect or a control (a dropdown), flipped to the other side where it does not fit. It closes with
@@ -82,6 +92,25 @@ export class Canvas {
82
92
  ClosePopupWindows() { this.popups.CloseAll(true); this.AfterPopupsChanged(); }
83
93
  /** The popup window is still open. */
84
94
  IsPopupWindowOpen(id) { return this.popups.IsOpen(id); }
95
+ /**
96
+ * Moves the keyboard and screen-reader focus to `control` at the end of the next frame, for app code such as a custom
97
+ * menu that moves its highlight (C# DrawnView.SetAccessibilityFocus). A control not drawn yet gets it once it is, within
98
+ * 3 seconds. It wins over the library's own moves in the same frame (a closed popup window giving the keyboard back to
99
+ * its opener); undefined cancels a move still waiting. The focus ring shows only if the keyboard is in use.
100
+ */
101
+ SetAccessibilityFocus(control) { this.AccessibilityManager.SetAccessibilityFocus(control); this.Update(); }
102
+ /**
103
+ * The drawn control with the keyboard and screen-reader focus (C# KeyboardFocusNode). Set undefined to let no drawn
104
+ * control keep it: the DOM focus goes back to the canvas and the keys belong to the app; a control moves it there.
105
+ */
106
+ get KeyboardFocusNode() { return this.AccessibilityManager.FocusedNode; }
107
+ set KeyboardFocusNode(control) {
108
+ if (control)
109
+ this.AccessibilityManager.SetAccessibilityFocus(control);
110
+ else
111
+ this.AccessibilityManager.ClearKeyboardFocus();
112
+ this.Update();
113
+ }
85
114
  /** True while a popup window that takes input is open. */
86
115
  get HasPopupWindows() { return this.popups.HasInteractive; }
87
116
  /** The content of the top popup window that takes input. */
@@ -96,24 +125,29 @@ export class Canvas {
96
125
  this.Hover.RequestCheck();
97
126
  this.Update();
98
127
  }
99
- onPopupKey = (key) => { if (key === "Escape" && this.popups.CloseTop())
100
- this.AfterPopupsChanged(); };
101
- onPopupChar = () => { };
128
+ onPopupKey = (key) => {
129
+ if (key !== "Escape" || !this.popups.CloseTop())
130
+ return false;
131
+ this.AfterPopupsChanged();
132
+ return true;
133
+ };
102
134
  HookPopupKeys(on) {
103
135
  if (on === this.popupKeysHooked)
104
136
  return;
105
137
  this.popupKeysHooked = on;
106
138
  if (on)
107
- KeyboardManager.Subscribe(this.onPopupKey, this.onPopupChar);
139
+ KeyboardManager.SubscribeNavigation(this.onPopupKey);
108
140
  else
109
- KeyboardManager.Unsubscribe(this.onPopupKey, this.onPopupChar);
141
+ KeyboardManager.UnsubscribeNavigation(this.onPopupKey);
110
142
  }
111
143
  onWindowBlur = () => this.OnWindowDeactivated();
112
144
  content;
113
145
  get Content() { return this.content; }
114
146
  set Content(value) {
115
- if (this.content)
147
+ if (this.content && this.content !== value) {
148
+ this.ControlLeft(this.content, false);
116
149
  this.content._superview = undefined;
150
+ }
117
151
  this.content = value;
118
152
  if (value) {
119
153
  value.Parent = undefined;
@@ -298,6 +332,9 @@ export class Canvas {
298
332
  this.Update(); // animators running: keep frames coming
299
333
  // C# order: WasDrawn at the end of the frame, then the frame counts as rendered
300
334
  this.WasDrawn?.(this);
335
+ const listeners = this.wasDrawnListeners;
336
+ if (listeners !== undefined && listeners.size > 0)
337
+ listeners.forEach(this.raiseWasDrawn);
301
338
  if (!this.WasRendered && canRender)
302
339
  this.WasRendered = true;
303
340
  }
@@ -321,6 +358,37 @@ export class Canvas {
321
358
  return true;
322
359
  }
323
360
  UnregisterAnimator(uid) { this.AnimatingControls.delete(uid); }
361
+ /**
362
+ * `root` leaves this canvas (removed from its parent, replaced as content, disposed): what runs for its subtree stops,
363
+ * as DrawnUi.Rust 44c718f. Its animators leave the frame loop: disposed, they stop; only removed, they pause and wait on
364
+ * their control (PendingUnattachedAnimators), going on from there when it is arranged on a canvas again. A focused editor in it loses the
365
+ * focus, a game in it stops getting keys (CanvasLeaveWatchers). Runs once per removal, never per frame.
366
+ */
367
+ ControlLeft(root, disposed) {
368
+ const inside = (c) => { for (let p = c; p; p = p.Parent)
369
+ if (p === root)
370
+ return true; return false; };
371
+ for (const a of this.AnimatingControls.values()) {
372
+ const control = a.Parent;
373
+ if (!control || !inside(control))
374
+ continue;
375
+ this.AnimatingControls.delete(a.Uid);
376
+ if (disposed || control.IsDisposed)
377
+ a.Stop();
378
+ else {
379
+ // paused as a hidden control's animator is: the time off the canvas is not counted when it goes on
380
+ if (!a.IsPaused) {
381
+ a.Pause();
382
+ a.PausedWhileHidden = true;
383
+ }
384
+ if (!control.PendingUnattachedAnimators?.includes(a))
385
+ (control.PendingUnattachedAnimators ??= []).push(a);
386
+ }
387
+ }
388
+ for (const c of [...CanvasLeaveWatchers])
389
+ if (inside(c))
390
+ c.OnLeftCanvas();
391
+ }
324
392
  /** Ticks every registered animator once; returns how many ran. */
325
393
  ExecuteAnimators(frameTimeNanos) {
326
394
  let executed = 0, wake = Infinity;
@@ -726,6 +794,7 @@ export class Canvas {
726
794
  this.activeTouchIds.clear();
727
795
  this.pointerDownArgs.clear();
728
796
  this.previousTouchArgs.clear();
797
+ this.fingers.Reset();
729
798
  }
730
799
  /** Port of DrawnUi.Blazor Canvas.OnTouchAction: per-pointer state machine producing Down / Panning / Tapped / Up. */
731
800
  OnTouchAction(args) {
@@ -734,6 +803,17 @@ export class Canvas {
734
803
  const id = args.Id;
735
804
  if (args.Type === "Pressed") {
736
805
  this.ArmLongPress(id, args);
806
+ // the fingers for pinch and turn: the first restarts them, a second one makes the press no tap
807
+ if (this.activeTouchIds.size === 0) {
808
+ this.fingers.Restart(id, args.Location);
809
+ this.multiTouch = false;
810
+ }
811
+ else {
812
+ for (const [other, last] of this.previousTouchArgs)
813
+ this.fingers.AddMovement(other, last.Location); // their latest places
814
+ this.fingers.AddMovement(id, args.Location);
815
+ this.multiTouch = true;
816
+ }
737
817
  this.activeTouchIds.add(id);
738
818
  args.NumberOfTouches = this.activeTouchIds.size;
739
819
  args.StartingLocation = args.Location;
@@ -758,6 +838,8 @@ export class Canvas {
758
838
  const downArgs = this.pointerDownArgs.get(id);
759
839
  args.StartingLocation = downArgs ? downArgs.StartingLocation : args.Location;
760
840
  if (args.Type === "Moved") {
841
+ if (this.activeTouchIds.size > 1)
842
+ args.Manipulation = this.fingers.AddMovement(id, args.Location); // nothing for one finger
761
843
  const threshold = Canvas.TappedCancelMoveThresholdPoints * Math.max(0.1, this.RenderingScale);
762
844
  if (Math.abs(args.Distance.Total.X) >= threshold || Math.abs(args.Distance.Total.Y) >= threshold)
763
845
  this.DisarmLongPress(id);
@@ -770,7 +852,7 @@ export class Canvas {
770
852
  args.IsInContact = args.NumberOfTouches > 1;
771
853
  const longPressed = this.longPressed.delete(id);
772
854
  this.DisarmLongPress(id);
773
- if (!args.IsInContact && downArgs && args.Type === "Released" && !longPressed) {
855
+ if (!args.IsInContact && downArgs && args.Type === "Released" && !longPressed && !this.multiTouch) {
774
856
  const threshold = Canvas.TappedCancelMoveThresholdPoints * Math.max(0.1, this.RenderingScale);
775
857
  if (Math.abs(args.Distance.Total.X) < threshold && Math.abs(args.Distance.Total.Y) < threshold)
776
858
  this.OnGestureEvent(args, "Tapped");
@@ -779,8 +861,16 @@ export class Canvas {
779
861
  this.previousTouchArgs.delete(id);
780
862
  this.pointerDownArgs.delete(id);
781
863
  this.activeTouchIds.delete(id);
864
+ if (this.activeTouchIds.size === 0)
865
+ this.fingers.Reset();
866
+ else
867
+ this.fingers.Lifted(id);
782
868
  }
783
869
  }
870
+ /** The fingers down, for TouchActionEventArgs.Manipulation (pinch and turn). */
871
+ fingers = new MultitouchTracker();
872
+ /** The press had a second finger: it is no tap (AppoMobi.Blazor.Gestures). */
873
+ multiTouch = false;
784
874
  longPressTimers = new Map();
785
875
  longPressed = new Set();
786
876
  /** The long press of a new press: due LongPressTimeMs later unless the pointer moves away or lets go. */
@@ -844,25 +934,25 @@ export class Canvas {
844
934
  return;
845
935
  this.arrowsStart = v;
846
936
  if (v)
847
- KeyboardManager.Subscribe(this.onArrowKey, this.onArrowChar);
937
+ KeyboardManager.SubscribeNavigation(this.onArrowKey);
848
938
  else
849
- KeyboardManager.Unsubscribe(this.onArrowKey, this.onArrowChar);
939
+ KeyboardManager.UnsubscribeNavigation(this.onArrowKey);
850
940
  }
851
- onArrowChar = () => { };
852
941
  onArrowKey = (key, e) => {
853
942
  const forward = key === "ArrowDown" || key === "ArrowRight" ? true : key === "ArrowUp" || key === "ArrowLeft" ? false : undefined;
854
943
  // a page element, a drawn control's element or the editor's input has the keys: nothing to start
855
944
  if (forward === undefined || this.disposed || KeyboardManager.IsOwnedByElement(e) || e.defaultPrevented)
856
- return;
945
+ return false;
857
946
  const mgr = this.AccessibilityManager, focused = mgr.FocusedNode;
858
947
  if (focused && !mgr.IsOutsideModal(focused))
859
- return;
948
+ return false;
860
949
  const first = mgr.NextTabStop(undefined, forward);
861
950
  if (!first)
862
- return;
951
+ return false;
863
952
  e.preventDefault();
864
953
  mgr.RequestKeyboardFocus(first);
865
954
  this.Update();
955
+ return true;
866
956
  };
867
957
  // ---- focus (C# DrawnView FocusedChild / ReportFocus, drawnui-cross 6ap) ----
868
958
  focusedChild;
@@ -54,6 +54,51 @@ export declare class PointerData {
54
54
  /** DOM `buttons` bitmask of the buttons held (1 left, 2 right, 4 middle, 8 back, 16 forward). */
55
55
  PressedButtons: number;
56
56
  }
57
+ /**
58
+ * AppoMobi.Gestures ManipulationInfo: what two or more fingers did since the previous move, on a Panning while they are
59
+ * down. Pinch to zoom from `Scale`, turn from `Rotation`. Pixels.
60
+ */
61
+ export declare class ManipulationInfo {
62
+ /** The middle of the fingers now, and at the previous move. */
63
+ readonly Center: SKPoint;
64
+ readonly PreviousCenter: SKPoint;
65
+ /** The fingers' spread now over the previous one, minus 1: 0.05 = 5% further apart. */
66
+ readonly Scale: number;
67
+ /** Degrees the first two fingers turned since the previous move, the short way (never a jump across ±180). */
68
+ readonly Rotation: number;
69
+ /** `Scale` and `Rotation` added up since the number of fingers last changed. */
70
+ readonly ScaleTotal: number;
71
+ readonly RotationTotal: number;
72
+ readonly TouchesCount: number;
73
+ constructor(
74
+ /** The middle of the fingers now, and at the previous move. */
75
+ Center: SKPoint, PreviousCenter: SKPoint,
76
+ /** The fingers' spread now over the previous one, minus 1: 0.05 = 5% further apart. */
77
+ Scale: number,
78
+ /** Degrees the first two fingers turned since the previous move, the short way (never a jump across ±180). */
79
+ Rotation: number,
80
+ /** `Scale` and `Rotation` added up since the number of fingers last changed. */
81
+ ScaleTotal: number, RotationTotal: number, TouchesCount: number);
82
+ }
83
+ /**
84
+ * The fingers down and what they did (AppoMobi.Gestures MultitouchTracker, after Mapsui; as DrawnUi.Rust): their middle,
85
+ * the first one's distance from it, the first two's angle. A new finger count starts the totals again.
86
+ */
87
+ export declare class MultitouchTracker {
88
+ private readonly fingers;
89
+ private state?;
90
+ private scaleTotal;
91
+ private rotationTotal;
92
+ get Count(): number;
93
+ /** The first finger came down: everything before is forgotten. */
94
+ Restart(id: number, at: SKPoint): void;
95
+ /** A finger came down or moved; what the fingers did while two or more are down and they moved. */
96
+ AddMovement(id: number, at: SKPoint): ManipulationInfo | undefined;
97
+ Lifted(id: number): void;
98
+ Reset(): void;
99
+ private Measure;
100
+ private Calculate;
101
+ }
57
102
  /** AppoMobi.Gestures TouchActionEventArgs. */
58
103
  export declare class TouchActionEventArgs {
59
104
  Id: number;
@@ -66,6 +111,8 @@ export declare class TouchActionEventArgs {
66
111
  Distance: DistanceInfo;
67
112
  NumberOfTouches: number;
68
113
  IsInContact: boolean;
114
+ /** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
115
+ Manipulation?: ManipulationInfo;
69
116
  Scale: number;
70
117
  Timestamp: number;
71
118
  /** ms since the previous event of the same pointer. */
@@ -88,6 +88,97 @@ export class PointerData {
88
88
  /** DOM `buttons` bitmask of the buttons held (1 left, 2 right, 4 middle, 8 back, 16 forward). */
89
89
  PressedButtons = 0;
90
90
  }
91
+ /**
92
+ * AppoMobi.Gestures ManipulationInfo: what two or more fingers did since the previous move, on a Panning while they are
93
+ * down. Pinch to zoom from `Scale`, turn from `Rotation`. Pixels.
94
+ */
95
+ export class ManipulationInfo {
96
+ Center;
97
+ PreviousCenter;
98
+ Scale;
99
+ Rotation;
100
+ ScaleTotal;
101
+ RotationTotal;
102
+ TouchesCount;
103
+ constructor(
104
+ /** The middle of the fingers now, and at the previous move. */
105
+ Center, PreviousCenter,
106
+ /** The fingers' spread now over the previous one, minus 1: 0.05 = 5% further apart. */
107
+ Scale,
108
+ /** Degrees the first two fingers turned since the previous move, the short way (never a jump across ±180). */
109
+ Rotation,
110
+ /** `Scale` and `Rotation` added up since the number of fingers last changed. */
111
+ ScaleTotal, RotationTotal, TouchesCount) {
112
+ this.Center = Center;
113
+ this.PreviousCenter = PreviousCenter;
114
+ this.Scale = Scale;
115
+ this.Rotation = Rotation;
116
+ this.ScaleTotal = ScaleTotal;
117
+ this.RotationTotal = RotationTotal;
118
+ this.TouchesCount = TouchesCount;
119
+ }
120
+ }
121
+ /**
122
+ * The fingers down and what they did (AppoMobi.Gestures MultitouchTracker, after Mapsui; as DrawnUi.Rust): their middle,
123
+ * the first one's distance from it, the first two's angle. A new finger count starts the totals again.
124
+ */
125
+ export class MultitouchTracker {
126
+ fingers = new Map();
127
+ state;
128
+ scaleTotal = 0;
129
+ rotationTotal = 0;
130
+ get Count() { return this.fingers.size; }
131
+ /** The first finger came down: everything before is forgotten. */
132
+ Restart(id, at) {
133
+ this.fingers.clear();
134
+ this.fingers.set(id, at);
135
+ this.scaleTotal = this.rotationTotal = 0;
136
+ this.state = this.Measure();
137
+ }
138
+ /** A finger came down or moved; what the fingers did while two or more are down and they moved. */
139
+ AddMovement(id, at) {
140
+ this.fingers.set(id, at);
141
+ return this.Calculate();
142
+ }
143
+ Lifted(id) { if (this.fingers.delete(id))
144
+ this.Calculate(); }
145
+ Reset() { this.fingers.clear(); this.state = undefined; }
146
+ Measure() {
147
+ const points = [...this.fingers.values()];
148
+ if (points.length === 0)
149
+ return undefined;
150
+ const first = points[0];
151
+ if (points.length === 1)
152
+ return { Center: first, Radius: 0, Angle: 0, Count: 1 };
153
+ let x = 0, y = 0;
154
+ for (const p of points) {
155
+ x += p.X;
156
+ y += p.Y;
157
+ }
158
+ const center = new SKPoint(x / points.length, y / points.length), second = points[1];
159
+ return {
160
+ Center: center, Radius: Math.hypot(first.X - center.X, first.Y - center.Y),
161
+ Angle: (Math.atan2(second.Y - first.Y, second.X - first.X) * 180) / Math.PI, Count: points.length,
162
+ };
163
+ }
164
+ Calculate() {
165
+ const now = this.Measure(), previous = this.state;
166
+ this.state = now;
167
+ if (!now || !previous || now.Count < 2)
168
+ return undefined;
169
+ if (now.Count !== previous.Count) {
170
+ this.scaleTotal = this.rotationTotal = 0;
171
+ return undefined;
172
+ }
173
+ const scale = previous.Radius > 0 && now.Radius !== previous.Radius ? now.Radius / previous.Radius - 1 : 0;
174
+ const rotation = ((((now.Angle - previous.Angle + 540) % 360) + 360) % 360) - 180;
175
+ this.scaleTotal += scale;
176
+ this.rotationTotal += rotation;
177
+ if (now.Center.X === previous.Center.X && now.Center.Y === previous.Center.Y && now.Radius === previous.Radius && now.Angle === previous.Angle)
178
+ return undefined;
179
+ return new ManipulationInfo(now.Center, previous.Center, scale, rotation, this.scaleTotal, this.rotationTotal, now.Count);
180
+ }
181
+ }
91
182
  /** AppoMobi.Gestures TouchActionEventArgs. */
92
183
  export class TouchActionEventArgs {
93
184
  Id = 0;
@@ -100,6 +191,8 @@ export class TouchActionEventArgs {
100
191
  Distance = new DistanceInfo();
101
192
  NumberOfTouches = 1;
102
193
  IsInContact = false;
194
+ /** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
195
+ Manipulation;
103
196
  Scale = 1;
104
197
  Timestamp = performance.now();
105
198
  /** ms since the previous event of the same pointer. */
@@ -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--)