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

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 (107) hide show
  1. package/README.md +129 -14
  2. package/SKIPPED.md +36 -26
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +18 -1
  5. package/dist/controls/DrawnGame.d.ts +44 -0
  6. package/dist/controls/DrawnGame.js +82 -0
  7. package/dist/controls/GridStructure.d.ts +16 -2
  8. package/dist/controls/GridStructure.js +40 -4
  9. package/dist/controls/SkiaBackdrop.d.ts +8 -2
  10. package/dist/controls/SkiaBackdrop.js +42 -14
  11. package/dist/controls/SkiaButton.d.ts +17 -3
  12. package/dist/controls/SkiaButton.js +26 -8
  13. package/dist/controls/SkiaCarousel.d.ts +22 -3
  14. package/dist/controls/SkiaCarousel.js +85 -9
  15. package/dist/controls/SkiaCheckbox.d.ts +0 -1
  16. package/dist/controls/SkiaCheckbox.js +2 -7
  17. package/dist/controls/SkiaDrawer.d.ts +15 -0
  18. package/dist/controls/SkiaDrawer.js +42 -7
  19. package/dist/controls/SkiaEditor.d.ts +48 -2
  20. package/dist/controls/SkiaEditor.js +268 -53
  21. package/dist/controls/SkiaGif.d.ts +7 -0
  22. package/dist/controls/SkiaGif.js +25 -4
  23. package/dist/controls/SkiaImage.d.ts +5 -0
  24. package/dist/controls/SkiaImage.js +48 -14
  25. package/dist/controls/SkiaLabel.d.ts +117 -9
  26. package/dist/controls/SkiaLabel.js +526 -80
  27. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  28. package/dist/controls/SkiaLabelFps.js +41 -0
  29. package/dist/controls/SkiaLayout.d.ts +89 -9
  30. package/dist/controls/SkiaLayout.js +364 -21
  31. package/dist/controls/SkiaLottie.js +5 -3
  32. package/dist/controls/SkiaProgress.d.ts +2 -1
  33. package/dist/controls/SkiaProgress.js +8 -5
  34. package/dist/controls/SkiaRadioButton.d.ts +2 -0
  35. package/dist/controls/SkiaRadioButton.js +16 -4
  36. package/dist/controls/SkiaRichLabel.d.ts +1 -1
  37. package/dist/controls/SkiaRichLabel.js +11 -1
  38. package/dist/controls/SkiaScroll.d.ts +35 -5
  39. package/dist/controls/SkiaScroll.js +252 -32
  40. package/dist/controls/SkiaScrollBar.d.ts +27 -0
  41. package/dist/controls/SkiaScrollBar.js +51 -2
  42. package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
  43. package/dist/controls/SkiaShaderCarousel.js +27 -5
  44. package/dist/controls/SkiaShape.d.ts +13 -2
  45. package/dist/controls/SkiaShape.js +50 -10
  46. package/dist/controls/SkiaSlider.d.ts +20 -2
  47. package/dist/controls/SkiaSlider.js +61 -7
  48. package/dist/controls/SkiaSprite.d.ts +4 -0
  49. package/dist/controls/SkiaSprite.js +22 -10
  50. package/dist/controls/SkiaSvg.d.ts +4 -0
  51. package/dist/controls/SkiaSvg.js +28 -4
  52. package/dist/controls/SkiaSwitch.d.ts +0 -1
  53. package/dist/controls/SkiaSwitch.js +4 -8
  54. package/dist/controls/SkiaToggle.d.ts +25 -5
  55. package/dist/controls/SkiaToggle.js +58 -5
  56. package/dist/controls/SnappingLayout.d.ts +12 -1
  57. package/dist/controls/SnappingLayout.js +21 -2
  58. package/dist/controls/TooltipStyle.d.ts +52 -0
  59. package/dist/controls/TooltipStyle.js +88 -0
  60. package/dist/core/Accessibility.d.ts +134 -0
  61. package/dist/core/Accessibility.js +675 -9
  62. package/dist/core/Animators.d.ts +37 -1
  63. package/dist/core/Animators.js +102 -9
  64. package/dist/core/Canvas.d.ts +241 -10
  65. package/dist/core/Canvas.js +739 -44
  66. package/dist/core/ControlStyle.d.ts +2 -0
  67. package/dist/core/ControlStyle.js +2 -0
  68. package/dist/core/DesignerActions.d.ts +32 -0
  69. package/dist/core/DesignerActions.js +68 -0
  70. package/dist/core/Easing.d.ts +12 -1
  71. package/dist/core/Easing.js +25 -1
  72. package/dist/core/Gestures.d.ts +81 -2
  73. package/dist/core/Gestures.js +177 -3
  74. package/dist/core/Hover.d.ts +51 -0
  75. package/dist/core/Hover.js +140 -0
  76. package/dist/core/ImageEffects.d.ts +2 -0
  77. package/dist/core/ImageEffects.js +2 -0
  78. package/dist/core/KeyboardManager.d.ts +40 -0
  79. package/dist/core/KeyboardManager.js +98 -8
  80. package/dist/core/PopupWindows.d.ts +94 -0
  81. package/dist/core/PopupWindows.js +205 -0
  82. package/dist/core/ScrollAnimators.js +9 -0
  83. package/dist/core/Shaping.d.ts +40 -0
  84. package/dist/core/Shaping.js +224 -0
  85. package/dist/core/SkiaControl.d.ts +284 -11
  86. package/dist/core/SkiaControl.js +630 -66
  87. package/dist/core/SkiaEffect.d.ts +17 -0
  88. package/dist/core/SkiaEffect.js +43 -8
  89. package/dist/core/SkiaImageManager.js +1 -1
  90. package/dist/core/Super.d.ts +29 -2
  91. package/dist/core/Super.js +54 -3
  92. package/dist/core/Tooltips.d.ts +71 -0
  93. package/dist/core/Tooltips.js +205 -0
  94. package/dist/core/Types.d.ts +11 -1
  95. package/dist/core/Types.js +32 -1
  96. package/dist/core/ViewsAdapter.d.ts +7 -2
  97. package/dist/core/ViewsAdapter.js +10 -3
  98. package/dist/index.d.ts +7 -0
  99. package/dist/index.js +7 -0
  100. package/dist/react/SkiaShell.js +65 -26
  101. package/dist/react/index.d.ts +51 -4
  102. package/dist/react/index.js +180 -18
  103. package/dist/react/reconciler.d.ts +20 -0
  104. package/dist/react/reconciler.js +69 -14
  105. package/dist/vite/index.d.ts +9 -0
  106. package/dist/vite/index.js +36 -3
  107. package/package.json +66 -2
@@ -1,5 +1,7 @@
1
1
  /** DrawnUi PrebuiltControlStyle: the look a styled control builds its default content with. */
2
2
  export type PrebuiltControlStyle = "Unset" | "Platform" | "Cupertino" | "Material" | "Material3" | "Windows";
3
+ /** Accent of the default look (controls without a ControlStyle): blue #3B82F6, the DrawnUI Designer's and Agent Signals' accent (C# DefaultStyle.Accent). */
4
+ export declare const DefaultAccent = "#3B82F6";
3
5
  /** Resolved look: `Platform` picks from the browser's OS (C# picks from the running platform). */
4
6
  export type ResolvedControlStyle = Exclude<PrebuiltControlStyle, "Platform">;
5
7
  /** C# UsingControlStyle: Platform -> iOS/macOS = Cupertino, Android = Material, Windows = Windows, else the DrawnUi default look. */
@@ -1,3 +1,5 @@
1
+ /** Accent of the default look (controls without a ControlStyle): blue #3B82F6, the DrawnUI Designer's and Agent Signals' accent (C# DefaultStyle.Accent). */
2
+ export const DefaultAccent = "#3B82F6";
1
3
  let platformStyle;
2
4
  /** C# UsingControlStyle: Platform -> iOS/macOS = Cupertino, Android = Material, Windows = Windows, else the DrawnUi default look. */
3
5
  export function ResolveControlStyle(style) {
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Actions an app declares for the DrawnUI Designer (C# DrawnUi.Draw.DesignerActions): named states it can jump to without
3
+ * being played to them (a level, a game state, a dialog). The designer lists them under the app's screens and runs one on
4
+ * a click; AI agents run them through the designer's MCP (`list_actions`, `run_action`).
5
+ *
6
+ * A path names the action and its groups, slash-separated: "Levels/Level 3" shows as "Level 3" under "Levels". Nothing
7
+ * here runs unless a designer is attached: the list only keeps the names and their callbacks.
8
+ *
9
+ * ```ts
10
+ * for (let level = 1; level <= 20; level++) designerAction(`Levels/Level ${level}`, () => game.startLevel(level));
11
+ * designerAction("Dialogs/Options", () => game.showOptions());
12
+ * ```
13
+ */
14
+ export declare class DesignerActions {
15
+ private static readonly items;
16
+ /** Raised after the list changed (an action added, replaced or removed); the designer agent sends the new list. */
17
+ static readonly Changed: Set<() => void>;
18
+ private static RaiseChanged;
19
+ /**
20
+ * Adds an action, or replaces the one with the same path (keeping its place). Returns the function that removes it
21
+ * again (an action a screen offers while it is shown); it removes only this registration, not a later one of the path.
22
+ */
23
+ static Add(path: string, run: () => void): () => void;
24
+ /** Removes the action with this path, if there is one. */
25
+ static Remove(path: string): void;
26
+ /** The declared actions' paths, in the order they were added. */
27
+ static get Paths(): string[];
28
+ /** Runs the action with this path; false when there is no such action. */
29
+ static Run(path: string): boolean;
30
+ }
31
+ /** Declares a Designer action (DesignerActions.Add); returns the function that removes it. Usable outside React. */
32
+ export declare function designerAction(path: string, run: () => void): () => void;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Actions an app declares for the DrawnUI Designer (C# DrawnUi.Draw.DesignerActions): named states it can jump to without
3
+ * being played to them (a level, a game state, a dialog). The designer lists them under the app's screens and runs one on
4
+ * a click; AI agents run them through the designer's MCP (`list_actions`, `run_action`).
5
+ *
6
+ * A path names the action and its groups, slash-separated: "Levels/Level 3" shows as "Level 3" under "Levels". Nothing
7
+ * here runs unless a designer is attached: the list only keeps the names and their callbacks.
8
+ *
9
+ * ```ts
10
+ * for (let level = 1; level <= 20; level++) designerAction(`Levels/Level ${level}`, () => game.startLevel(level));
11
+ * designerAction("Dialogs/Options", () => game.showOptions());
12
+ * ```
13
+ */
14
+ export class DesignerActions {
15
+ static items = [];
16
+ /** Raised after the list changed (an action added, replaced or removed); the designer agent sends the new list. */
17
+ static Changed = new Set();
18
+ static RaiseChanged() { for (const h of [...DesignerActions.Changed])
19
+ h(); }
20
+ /**
21
+ * Adds an action, or replaces the one with the same path (keeping its place). Returns the function that removes it
22
+ * again (an action a screen offers while it is shown); it removes only this registration, not a later one of the path.
23
+ */
24
+ static Add(path, run) {
25
+ if (!path || !path.trim())
26
+ throw new Error("DesignerActions: an action needs a path");
27
+ if (typeof run !== "function")
28
+ throw new Error("DesignerActions: an action needs a function");
29
+ const items = DesignerActions.items, at = items.findIndex((x) => x.Path === path);
30
+ const item = { Path: path, Run: run };
31
+ if (at >= 0)
32
+ items[at] = item;
33
+ else
34
+ items.push(item);
35
+ DesignerActions.RaiseChanged();
36
+ let done = false;
37
+ return () => {
38
+ if (done)
39
+ return;
40
+ done = true;
41
+ const i = DesignerActions.items.indexOf(item);
42
+ if (i < 0)
43
+ return;
44
+ DesignerActions.items.splice(i, 1);
45
+ DesignerActions.RaiseChanged();
46
+ };
47
+ }
48
+ /** Removes the action with this path, if there is one. */
49
+ static Remove(path) {
50
+ const i = DesignerActions.items.findIndex((x) => x.Path === path);
51
+ if (i < 0)
52
+ return;
53
+ DesignerActions.items.splice(i, 1);
54
+ DesignerActions.RaiseChanged();
55
+ }
56
+ /** The declared actions' paths, in the order they were added. */
57
+ static get Paths() { return DesignerActions.items.map((x) => x.Path); }
58
+ /** Runs the action with this path; false when there is no such action. */
59
+ static Run(path) {
60
+ const item = DesignerActions.items.find((x) => x.Path === path);
61
+ if (!item)
62
+ return false;
63
+ item.Run();
64
+ return true;
65
+ }
66
+ }
67
+ /** Declares a Designer action (DesignerActions.Add); returns the function that removes it. Usable outside React. */
68
+ export function designerAction(path, run) { return DesignerActions.Add(path, run); }
@@ -1,4 +1,4 @@
1
- /** Mirrors MAUI Easing (subset): Ease(t) with t in 0..1. */
1
+ /** Mirrors MAUI Easing: Ease(t) with t in 0..1 (Spring* leave 0..1 on the way). */
2
2
  export declare class Easing {
3
3
  private readonly fn;
4
4
  constructor(fn: (x: number) => number);
@@ -9,5 +9,16 @@ export declare class Easing {
9
9
  static readonly CubicInOut: Easing;
10
10
  static readonly SinOut: Easing;
11
11
  static readonly SinIn: Easing;
12
+ /** Half a cosine: slow at both ends. */
13
+ static readonly SinInOut: Easing;
14
+ /** Leaps to the end, bounces three times and settles. */
15
+ static readonly BounceOut: Easing;
16
+ /** Bounces three times, then leaps to the end. */
17
+ static readonly BounceIn: Easing;
18
+ /** Moves away first, then leaps to the end. */
19
+ static readonly SpringIn: Easing;
20
+ /** Goes a little past the end and comes back. */
21
+ static readonly SpringOut: Easing;
22
+ private static Bounce;
12
23
  static readonly Default: Easing;
13
24
  }
@@ -1,4 +1,4 @@
1
- /** Mirrors MAUI Easing (subset): Ease(t) with t in 0..1. */
1
+ /** Mirrors MAUI Easing: Ease(t) with t in 0..1 (Spring* leave 0..1 on the way). */
2
2
  export class Easing {
3
3
  fn;
4
4
  constructor(fn) {
@@ -11,5 +11,29 @@ export class Easing {
11
11
  static CubicInOut = new Easing((x) => (x < 0.5 ? 4 * x ** 3 : (x - 1) * (2 * x - 2) ** 2 + 1));
12
12
  static SinOut = new Easing((x) => Math.sin((x * Math.PI) / 2));
13
13
  static SinIn = new Easing((x) => 1 - Math.cos((x * Math.PI) / 2));
14
+ /** Half a cosine: slow at both ends. */
15
+ static SinInOut = new Easing((x) => -Math.cos(Math.PI * x) / 2 + 0.5);
16
+ /** Leaps to the end, bounces three times and settles. */
17
+ static BounceOut = new Easing(Easing.Bounce);
18
+ /** Bounces three times, then leaps to the end. */
19
+ static BounceIn = new Easing((x) => 1 - Easing.Bounce(1 - x));
20
+ /** Moves away first, then leaps to the end. */
21
+ static SpringIn = new Easing((x) => x * x * ((1.70158 + 1) * x - 1.70158));
22
+ /** Goes a little past the end and comes back. */
23
+ static SpringOut = new Easing((x) => (x - 1) * (x - 1) * ((1.70158 + 1) * (x - 1) + 1.70158) + 1);
24
+ static Bounce(p) {
25
+ if (p < 1 / 2.75)
26
+ return 7.5625 * p * p;
27
+ if (p < 2 / 2.75) {
28
+ p -= 1.5 / 2.75;
29
+ return 7.5625 * p * p + 0.75;
30
+ }
31
+ if (p < 2.5 / 2.75) {
32
+ p -= 2.25 / 2.75;
33
+ return 7.5625 * p * p + 0.9375;
34
+ }
35
+ p -= 2.625 / 2.75;
36
+ return 7.5625 * p * p + 0.984375;
37
+ }
14
38
  static Default = Easing.CubicInOut;
15
39
  }
@@ -9,7 +9,7 @@ export declare class SKPoint {
9
9
  }
10
10
  /** Raw platform action (subset of TouchActionType). */
11
11
  export type TouchActionType = "Pressed" | "Moved" | "Released" | "Cancelled" | "Wheel" | "Pointer";
12
- /** Recognized gesture (TouchActionResult). LongPressing/Pointer/Touch declared for parity, not produced yet. */
12
+ /** Recognized gesture (TouchActionResult). LongPressing after Canvas.LongPressTimeMs held still; Pointer / Touch declared for parity, not produced. */
13
13
  export type TouchActionResult = "Touch" | "Down" | "Up" | "Tapped" | "LongPressing" | "Panning" | "Wheel" | "Pointer";
14
14
  export type GesturesMode = "Disabled" | "Enabled" | "Lock";
15
15
  export type LockTouch = "Disabled" | "Enabled" | "PassNone" | "PassTap" | "PassTapAndLongPress";
@@ -21,6 +21,27 @@ export declare class DistanceInfo {
21
21
  Total: SKPoint;
22
22
  Velocity: SKPoint;
23
23
  }
24
+ /**
25
+ * The last positions of a press with their times (DrawnUi.Rust gestures `Trail`, 6d525f7). Measured only against the
26
+ * previous move, irregular delivery made the velocity worthless: moves handled in one burst (queued pointer events
27
+ * handed over back to back by a busy main thread, WSLg pairs 0.01 ms apart) gave millions of px/s and every fling at
28
+ * the limit. Moves under BurstMs apart are one position; a move's velocity is its displacement over the last WindowMs,
29
+ * the earlier position interpolated; when the previous move is already that old, its own velocity exactly (evenly
30
+ * spaced input at 60 Hz measures as before).
31
+ */
32
+ export declare class VelocityTrail {
33
+ /** A move's velocity is its displacement over this much time. */
34
+ static readonly WindowMs = 16;
35
+ /** Below this since the press no velocity is measured yet: the first moves of a burst. */
36
+ static readonly MinMs = 4;
37
+ /** Moves closer than this came in one burst: one position, at the burst's first time. */
38
+ static readonly BurstMs = 1;
39
+ private static readonly Capacity;
40
+ private readonly points;
41
+ Push(x: number, y: number, t: number): void;
42
+ /** The velocity at (x, y) at time t (ms), pixels per second; `fallback` right after the press. */
43
+ Velocity(x: number, y: number, t: number, fallback: SKPoint): SKPoint;
44
+ }
24
45
  /** AppoMobi.Gestures MouseButton: which button pressed / released (DOM button 0..4). */
25
46
  export type MouseButton = "Left" | "Middle" | "Right" | "XButton1" | "XButton2" | "Extended";
26
47
  export type PointerDeviceType = "Mouse" | "Touch" | "Pen";
@@ -33,6 +54,51 @@ export declare class PointerData {
33
54
  /** DOM `buttons` bitmask of the buttons held (1 left, 2 right, 4 middle, 8 back, 16 forward). */
34
55
  PressedButtons: number;
35
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
+ }
36
102
  /** AppoMobi.Gestures TouchActionEventArgs. */
37
103
  export declare class TouchActionEventArgs {
38
104
  Id: number;
@@ -45,14 +111,27 @@ export declare class TouchActionEventArgs {
45
111
  Distance: DistanceInfo;
46
112
  NumberOfTouches: number;
47
113
  IsInContact: boolean;
114
+ /** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
115
+ Manipulation?: ManipulationInfo;
48
116
  Scale: number;
49
117
  Timestamp: number;
50
118
  /** ms since the previous event of the same pointer. */
51
119
  DeltaTimeMs: number;
52
- /** Mouse wheel: Delta > 0 = wheel down (browser deltaY sign). */
120
+ /** The press's recent positions the velocity is measured over, carried from event to event of one pointer. */
121
+ Trail?: VelocityTrail;
122
+ /**
123
+ * Mouse wheel: Delta > 0 = wheel down / right (browser sign). IsHorizontal: the event is along the X axis (a tilting
124
+ * wheel, the sideways part of a two-finger touchpad swipe), as C# WheelEventArgs.IsHorizontal.
125
+ */
53
126
  Wheel: {
54
127
  Delta: number;
128
+ IsHorizontal?: boolean;
55
129
  };
130
+ /**
131
+ * AppoMobi TouchActionEventArgs.Handled: set by a control that actually used the event. The canvas prevents the
132
+ * browser default (the page scrolling under the wheel) only for a Handled event in `Gestures="Enabled"`.
133
+ */
134
+ Handled: boolean;
56
135
  /** Same as the .NET helper: derives Start/End/Delta/Total from the previous event of the same pointer. */
57
136
  static FillDistanceInfo(current: TouchActionEventArgs, previous: TouchActionEventArgs | undefined): void;
58
137
  }
@@ -18,6 +18,67 @@ export class DistanceInfo {
18
18
  Total = SKPoint.Empty;
19
19
  Velocity = SKPoint.Empty;
20
20
  }
21
+ /**
22
+ * The last positions of a press with their times (DrawnUi.Rust gestures `Trail`, 6d525f7). Measured only against the
23
+ * previous move, irregular delivery made the velocity worthless: moves handled in one burst (queued pointer events
24
+ * handed over back to back by a busy main thread, WSLg pairs 0.01 ms apart) gave millions of px/s and every fling at
25
+ * the limit. Moves under BurstMs apart are one position; a move's velocity is its displacement over the last WindowMs,
26
+ * the earlier position interpolated; when the previous move is already that old, its own velocity exactly (evenly
27
+ * spaced input at 60 Hz measures as before).
28
+ */
29
+ export class VelocityTrail {
30
+ /** A move's velocity is its displacement over this much time. */
31
+ static WindowMs = 16;
32
+ /** Below this since the press no velocity is measured yet: the first moves of a burst. */
33
+ static MinMs = 4;
34
+ /** Moves closer than this came in one burst: one position, at the burst's first time. */
35
+ static BurstMs = 1;
36
+ static Capacity = 16;
37
+ points = [];
38
+ Push(x, y, t) {
39
+ const last = this.points[this.points.length - 1];
40
+ if (last && t - last.T < VelocityTrail.BurstMs) {
41
+ last.X = x;
42
+ last.Y = y;
43
+ return;
44
+ }
45
+ if (this.points.length === VelocityTrail.Capacity)
46
+ this.points.shift();
47
+ this.points.push({ X: x, Y: y, T: t });
48
+ }
49
+ /** The velocity at (x, y) at time t (ms), pixels per second; `fallback` right after the press. */
50
+ Velocity(x, y, t, fallback) {
51
+ let n = this.points.length;
52
+ // a move in the burst of the last position measures from the positions before it
53
+ if (n > 0 && t - this.points[n - 1].T < VelocityTrail.BurstMs)
54
+ n--;
55
+ if (n === 0)
56
+ return fallback;
57
+ const since = t - this.points[0].T;
58
+ if (since < VelocityTrail.MinMs)
59
+ return fallback;
60
+ const window = Math.min(VelocityTrail.WindowMs, since), at = t - window;
61
+ const last = this.points[n - 1];
62
+ if (last.T <= at) {
63
+ const secs = (t - last.T) / 1000;
64
+ return new SKPoint((x - last.X) / secs, (y - last.Y) / secs);
65
+ }
66
+ // the position at `at`: between the two positions around it (the current one included)
67
+ let fromX = this.points[0].X, fromY = this.points[0].Y, prev = this.points[0];
68
+ for (let i = 1; i <= n; i++) {
69
+ const p = i < n ? this.points[i] : { X: x, Y: y, T: t };
70
+ if (p.T >= at) {
71
+ const share = p.T - prev.T < 1e-6 ? 1 : (at - prev.T) / (p.T - prev.T);
72
+ fromX = prev.X + (p.X - prev.X) * share;
73
+ fromY = prev.Y + (p.Y - prev.Y) * share;
74
+ break;
75
+ }
76
+ prev = p;
77
+ }
78
+ const secs = window / 1000;
79
+ return new SKPoint((x - fromX) / secs, (y - fromY) / secs);
80
+ }
81
+ }
21
82
  /** AppoMobi.Gestures PointerData: the device and button behind a Down / Up / Tapped (every button is delivered). */
22
83
  export class PointerData {
23
84
  Button = "Left";
@@ -27,6 +88,97 @@ export class PointerData {
27
88
  /** DOM `buttons` bitmask of the buttons held (1 left, 2 right, 4 middle, 8 back, 16 forward). */
28
89
  PressedButtons = 0;
29
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
+ }
30
182
  /** AppoMobi.Gestures TouchActionEventArgs. */
31
183
  export class TouchActionEventArgs {
32
184
  Id = 0;
@@ -39,12 +191,24 @@ export class TouchActionEventArgs {
39
191
  Distance = new DistanceInfo();
40
192
  NumberOfTouches = 1;
41
193
  IsInContact = false;
194
+ /** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
195
+ Manipulation;
42
196
  Scale = 1;
43
197
  Timestamp = performance.now();
44
198
  /** ms since the previous event of the same pointer. */
45
199
  DeltaTimeMs = 0;
46
- /** Mouse wheel: Delta > 0 = wheel down (browser deltaY sign). */
200
+ /** The press's recent positions the velocity is measured over, carried from event to event of one pointer. */
201
+ Trail;
202
+ /**
203
+ * Mouse wheel: Delta > 0 = wheel down / right (browser sign). IsHorizontal: the event is along the X axis (a tilting
204
+ * wheel, the sideways part of a two-finger touchpad swipe), as C# WheelEventArgs.IsHorizontal.
205
+ */
47
206
  Wheel = { Delta: 0 };
207
+ /**
208
+ * AppoMobi TouchActionEventArgs.Handled: set by a control that actually used the event. The canvas prevents the
209
+ * browser default (the page scrolling under the wheel) only for a Handled event in `Gestures="Enabled"`.
210
+ */
211
+ Handled = false;
48
212
  /** Same as the .NET helper: derives Start/End/Delta/Total from the previous event of the same pointer. */
49
213
  static FillDistanceInfo(current, previous) {
50
214
  if (!previous) {
@@ -60,8 +224,18 @@ export class TouchActionEventArgs {
60
224
  d.End = released ? previous.Location : current.Location;
61
225
  d.Delta = released ? SKPoint.Empty : current.Location.Subtract(previous.Location);
62
226
  d.Total = previous.Distance.Total.Add(d.Delta);
63
- const secs = current.DeltaTimeMs / 1000;
64
- d.Velocity = secs > 0 && !released ? new SKPoint(d.Delta.X / secs, d.Delta.Y / secs) : previous.Distance.Velocity;
227
+ if (released)
228
+ d.Velocity = previous.Distance.Velocity;
229
+ else {
230
+ let trail = previous.Trail;
231
+ if (!trail) {
232
+ trail = new VelocityTrail();
233
+ trail.Push(previous.Location.X, previous.Location.Y, previous.Timestamp);
234
+ }
235
+ d.Velocity = trail.Velocity(current.Location.X, current.Location.Y, current.Timestamp, previous.Distance.Velocity);
236
+ trail.Push(current.Location.X, current.Location.Y, current.Timestamp);
237
+ current.Trail = trail;
238
+ }
65
239
  current.Distance = d;
66
240
  }
67
241
  }
@@ -0,0 +1,51 @@
1
+ import type { SkiaControl } from "./SkiaControl";
2
+ /**
3
+ * DrawnUI hover (drawnui-cross 6m, C# DrawnView ReportHover / CommitHover): every control under the mouse that takes
4
+ * hover (`ReceivesHover`) is hovered, a card and the button inside it alike, as CSS :hover. Decided from the hit path
5
+ * of one pointer position, by the routing rules of ProcessGestures (visible, not InputTransparent, inside, children
6
+ * not locked, nothing below a control that blocks gestures below).
7
+ * While content moves under the pointer (a scroll glide, fling or pan, a carousel or drawer transition) hover is not
8
+ * tracked and what was hovered stays; one check at the last pointer position follows when it stops, and after
9
+ * controls are added or removed, a cell is rebound, a hovered control is hidden or a scroll jumps. Leaving the canvas
10
+ * clears hover at once. Touch never hovers. No allocation on frames where nothing changes.
11
+ */
12
+ export declare class HoverManager {
13
+ /** The hovered controls, root first. */
14
+ readonly Hovered: SkiaControl[];
15
+ private readonly next;
16
+ /** The controls under the pointer at the last hit test, root first, and the pointer in each one's own space. */
17
+ readonly Path: SkiaControl[];
18
+ readonly PathX: number[];
19
+ readonly PathY: number[];
20
+ private readonly movers;
21
+ private hasPointer;
22
+ private x;
23
+ private y;
24
+ private paused;
25
+ private check;
26
+ /** Picks the root under a point (canvas pixels): a popup window over the content, else the content. */
27
+ RootAt?: (x: number, y: number) => SkiaControl | undefined;
28
+ /** Content moves under the pointer (a scroll glide, a carousel transition): hover waits. */
29
+ get Paused(): boolean;
30
+ /**
31
+ * The mouse (or a pen in range) moved to (x, y), canvas pixels, nothing pressed. The hit path is taken also while
32
+ * hover waits (the cursor follows it), hover changes only when nothing moves.
33
+ */
34
+ Move(root: SkiaControl | undefined, x: number, y: number): void;
35
+ /** Fills Path with the controls under the pointer by the routing rules of ProcessGestures. */
36
+ private HitTest;
37
+ /** The pointer left the canvas: nothing is hovered, also while content moves. */
38
+ Leave(): void;
39
+ /** The controls under a still pointer may have changed: checked once at the end of the frame. */
40
+ RequestCheck(): void;
41
+ /** A control that moves its content (MovesContent) while drawn: hover waits while any of them moves. */
42
+ RegisterMover(control: SkiaControl): void;
43
+ /** End of a frame: pause while content moves, else run a pending check (at most one a frame, none while pressed). */
44
+ AfterFrame(root: SkiaControl | undefined, pressed: boolean): void;
45
+ private static Shown;
46
+ /**
47
+ * The hovered set becomes the controls of the hit path that take hover (`fromPath`), or none: the ones that left get
48
+ * HoverChanged(false), then the new ones (true).
49
+ */
50
+ private Apply;
51
+ }