drawnui-react 0.1.0-preview.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +229 -22
- package/SKIPPED.md +37 -28
- package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
- package/dist/controls/AnimatedFramesRenderer.js +18 -1
- package/dist/controls/DrawnGame.d.ts +44 -0
- package/dist/controls/DrawnGame.js +82 -0
- package/dist/controls/GridStructure.d.ts +25 -3
- package/dist/controls/GridStructure.js +81 -5
- package/dist/controls/SkiaBackdrop.d.ts +8 -2
- package/dist/controls/SkiaBackdrop.js +42 -14
- package/dist/controls/SkiaButton.d.ts +17 -3
- package/dist/controls/SkiaButton.js +26 -8
- package/dist/controls/SkiaCarousel.d.ts +22 -3
- package/dist/controls/SkiaCarousel.js +85 -9
- package/dist/controls/SkiaCheckbox.d.ts +0 -1
- package/dist/controls/SkiaCheckbox.js +2 -7
- package/dist/controls/SkiaDrawer.d.ts +15 -0
- package/dist/controls/SkiaDrawer.js +42 -7
- package/dist/controls/SkiaEditor.d.ts +51 -2
- package/dist/controls/SkiaEditor.js +292 -58
- package/dist/controls/SkiaGif.d.ts +7 -0
- package/dist/controls/SkiaGif.js +25 -4
- package/dist/controls/SkiaImage.d.ts +10 -0
- package/dist/controls/SkiaImage.js +80 -19
- package/dist/controls/SkiaLabel.d.ts +200 -11
- package/dist/controls/SkiaLabel.js +925 -93
- package/dist/controls/SkiaLabelFps.d.ts +12 -0
- package/dist/controls/SkiaLabelFps.js +35 -0
- package/dist/controls/SkiaLayout.d.ts +89 -9
- package/dist/controls/SkiaLayout.js +397 -23
- package/dist/controls/SkiaLottie.js +5 -3
- package/dist/controls/SkiaProgress.d.ts +2 -1
- package/dist/controls/SkiaProgress.js +8 -5
- package/dist/controls/SkiaRadioButton.d.ts +2 -0
- package/dist/controls/SkiaRadioButton.js +16 -4
- package/dist/controls/SkiaRichLabel.d.ts +1 -1
- package/dist/controls/SkiaRichLabel.js +11 -1
- package/dist/controls/SkiaScroll.d.ts +86 -7
- package/dist/controls/SkiaScroll.js +361 -40
- package/dist/controls/SkiaScrollBar.d.ts +27 -0
- package/dist/controls/SkiaScrollBar.js +51 -2
- package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
- package/dist/controls/SkiaShaderCarousel.js +27 -5
- package/dist/controls/SkiaShape.d.ts +15 -2
- package/dist/controls/SkiaShape.js +57 -10
- package/dist/controls/SkiaShell.d.ts +282 -0
- package/dist/controls/SkiaShell.js +972 -0
- package/dist/controls/SkiaSlider.d.ts +20 -2
- package/dist/controls/SkiaSlider.js +61 -7
- package/dist/controls/SkiaSprite.d.ts +4 -0
- package/dist/controls/SkiaSprite.js +27 -11
- package/dist/controls/SkiaSvg.d.ts +4 -0
- package/dist/controls/SkiaSvg.js +28 -4
- package/dist/controls/SkiaSwitch.d.ts +0 -1
- package/dist/controls/SkiaSwitch.js +4 -8
- package/dist/controls/SkiaToggle.d.ts +25 -5
- package/dist/controls/SkiaToggle.js +58 -5
- package/dist/controls/SnappingLayout.d.ts +12 -1
- package/dist/controls/SnappingLayout.js +21 -2
- package/dist/controls/TooltipStyle.d.ts +52 -0
- package/dist/controls/TooltipStyle.js +88 -0
- package/dist/core/Accessibility.d.ts +162 -11
- package/dist/core/Accessibility.js +882 -22
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +307 -8
- package/dist/core/Canvas.js +1202 -66
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/DesignerActions.d.ts +32 -0
- package/dist/core/DesignerActions.js +68 -0
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +86 -2
- package/dist/core/Gestures.js +184 -4
- package/dist/core/Hover.d.ts +51 -0
- package/dist/core/Hover.js +140 -0
- package/dist/core/ImageEffects.d.ts +2 -0
- package/dist/core/ImageEffects.js +2 -0
- package/dist/core/KeyboardManager.d.ts +40 -0
- package/dist/core/KeyboardManager.js +98 -8
- package/dist/core/PopupWindows.d.ts +94 -0
- package/dist/core/PopupWindows.js +207 -0
- package/dist/core/Props.d.ts +11 -0
- package/dist/core/Props.js +44 -0
- package/dist/core/ScrollAnimators.d.ts +6 -0
- package/dist/core/ScrollAnimators.js +16 -1
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +306 -13
- package/dist/core/SkiaControl.js +681 -75
- package/dist/core/SkiaEffect.d.ts +29 -1
- package/dist/core/SkiaEffect.js +78 -16
- package/dist/core/SkiaImageManager.d.ts +101 -18
- package/dist/core/SkiaImageManager.js +318 -63
- package/dist/core/Styles.js +7 -1
- package/dist/core/Super.d.ts +33 -2
- package/dist/core/Super.js +58 -12
- package/dist/core/TextInputProxy.d.ts +31 -1
- package/dist/core/TextInputProxy.js +97 -15
- package/dist/core/Tooltips.d.ts +71 -0
- package/dist/core/Tooltips.js +205 -0
- package/dist/core/Types.d.ts +11 -1
- package/dist/core/Types.js +32 -1
- package/dist/core/ViewsAdapter.d.ts +7 -2
- package/dist/core/ViewsAdapter.js +10 -3
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/react/SkiaShell.d.ts +8 -74
- package/dist/react/SkiaShell.js +163 -475
- package/dist/react/index.d.ts +48 -4
- package/dist/react/index.js +210 -43
- package/dist/react/reconciler.d.ts +32 -0
- package/dist/react/reconciler.js +71 -40
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +103 -5
|
@@ -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); }
|
package/dist/core/Easing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Mirrors MAUI Easing
|
|
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
|
}
|
package/dist/core/Easing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Mirrors MAUI Easing
|
|
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
|
}
|
package/dist/core/Gestures.d.ts
CHANGED
|
@@ -9,7 +9,15 @@ 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
|
-
/**
|
|
12
|
+
/** Gesture settings shared by every canvas (AppoMobi TouchEffect, same names on every DrawnUI engine). */
|
|
13
|
+
export declare class TouchEffect {
|
|
14
|
+
/**
|
|
15
|
+
* How long a press is held without moving past Canvas.TappedCancelMoveThresholdPoints to be a LongPressing, at the press
|
|
16
|
+
* point; its release sends no Tapped. A timer, no frames while waiting. Default 750 ms on every engine (drawnui-cross 6cf).
|
|
17
|
+
*/
|
|
18
|
+
static LongPressTimeMsDefault: number;
|
|
19
|
+
}
|
|
20
|
+
/** Recognized gesture (TouchActionResult). LongPressing after TouchEffect.LongPressTimeMsDefault held still; Pointer / Touch declared for parity, not produced. */
|
|
13
21
|
export type TouchActionResult = "Touch" | "Down" | "Up" | "Tapped" | "LongPressing" | "Panning" | "Wheel" | "Pointer";
|
|
14
22
|
export type GesturesMode = "Disabled" | "Enabled" | "Lock";
|
|
15
23
|
export type LockTouch = "Disabled" | "Enabled" | "PassNone" | "PassTap" | "PassTapAndLongPress";
|
|
@@ -21,6 +29,27 @@ export declare class DistanceInfo {
|
|
|
21
29
|
Total: SKPoint;
|
|
22
30
|
Velocity: SKPoint;
|
|
23
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* The last positions of a press with their times (DrawnUi.Rust gestures `Trail`, 6d525f7). Measured only against the
|
|
34
|
+
* previous move, irregular delivery made the velocity worthless: moves handled in one burst (queued pointer events
|
|
35
|
+
* 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
|
|
36
|
+
* the limit. Moves under BurstMs apart are one position; a move's velocity is its displacement over the last WindowMs,
|
|
37
|
+
* the earlier position interpolated; when the previous move is already that old, its own velocity exactly (evenly
|
|
38
|
+
* spaced input at 60 Hz measures as before).
|
|
39
|
+
*/
|
|
40
|
+
export declare class VelocityTrail {
|
|
41
|
+
/** A move's velocity is its displacement over this much time. */
|
|
42
|
+
static readonly WindowMs = 16;
|
|
43
|
+
/** Below this since the press no velocity is measured yet: the first moves of a burst. */
|
|
44
|
+
static readonly MinMs = 4;
|
|
45
|
+
/** Moves closer than this came in one burst: one position, at the burst's first time. */
|
|
46
|
+
static readonly BurstMs = 1;
|
|
47
|
+
private static readonly Capacity;
|
|
48
|
+
private readonly points;
|
|
49
|
+
Push(x: number, y: number, t: number): void;
|
|
50
|
+
/** The velocity at (x, y) at time t (ms), pixels per second; `fallback` right after the press. */
|
|
51
|
+
Velocity(x: number, y: number, t: number, fallback: SKPoint): SKPoint;
|
|
52
|
+
}
|
|
24
53
|
/** AppoMobi.Gestures MouseButton: which button pressed / released (DOM button 0..4). */
|
|
25
54
|
export type MouseButton = "Left" | "Middle" | "Right" | "XButton1" | "XButton2" | "Extended";
|
|
26
55
|
export type PointerDeviceType = "Mouse" | "Touch" | "Pen";
|
|
@@ -33,6 +62,51 @@ export declare class PointerData {
|
|
|
33
62
|
/** DOM `buttons` bitmask of the buttons held (1 left, 2 right, 4 middle, 8 back, 16 forward). */
|
|
34
63
|
PressedButtons: number;
|
|
35
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* AppoMobi.Gestures ManipulationInfo: what two or more fingers did since the previous move, on a Panning while they are
|
|
67
|
+
* down. Pinch to zoom from `Scale`, turn from `Rotation`. Pixels.
|
|
68
|
+
*/
|
|
69
|
+
export declare class ManipulationInfo {
|
|
70
|
+
/** The middle of the fingers now, and at the previous move. */
|
|
71
|
+
readonly Center: SKPoint;
|
|
72
|
+
readonly PreviousCenter: SKPoint;
|
|
73
|
+
/** The fingers' spread now over the previous one, minus 1: 0.05 = 5% further apart. */
|
|
74
|
+
readonly Scale: number;
|
|
75
|
+
/** Degrees the first two fingers turned since the previous move, the short way (never a jump across ±180). */
|
|
76
|
+
readonly Rotation: number;
|
|
77
|
+
/** `Scale` and `Rotation` added up since the number of fingers last changed. */
|
|
78
|
+
readonly ScaleTotal: number;
|
|
79
|
+
readonly RotationTotal: number;
|
|
80
|
+
readonly TouchesCount: number;
|
|
81
|
+
constructor(
|
|
82
|
+
/** The middle of the fingers now, and at the previous move. */
|
|
83
|
+
Center: SKPoint, PreviousCenter: SKPoint,
|
|
84
|
+
/** The fingers' spread now over the previous one, minus 1: 0.05 = 5% further apart. */
|
|
85
|
+
Scale: number,
|
|
86
|
+
/** Degrees the first two fingers turned since the previous move, the short way (never a jump across ±180). */
|
|
87
|
+
Rotation: number,
|
|
88
|
+
/** `Scale` and `Rotation` added up since the number of fingers last changed. */
|
|
89
|
+
ScaleTotal: number, RotationTotal: number, TouchesCount: number);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The fingers down and what they did (AppoMobi.Gestures MultitouchTracker, after Mapsui; as DrawnUi.Rust): their middle,
|
|
93
|
+
* the first one's distance from it, the first two's angle. A new finger count starts the totals again.
|
|
94
|
+
*/
|
|
95
|
+
export declare class MultitouchTracker {
|
|
96
|
+
private readonly fingers;
|
|
97
|
+
private state?;
|
|
98
|
+
private scaleTotal;
|
|
99
|
+
private rotationTotal;
|
|
100
|
+
get Count(): number;
|
|
101
|
+
/** The first finger came down: everything before is forgotten. */
|
|
102
|
+
Restart(id: number, at: SKPoint): void;
|
|
103
|
+
/** A finger came down or moved; what the fingers did while two or more are down and they moved. */
|
|
104
|
+
AddMovement(id: number, at: SKPoint): ManipulationInfo | undefined;
|
|
105
|
+
Lifted(id: number): void;
|
|
106
|
+
Reset(): void;
|
|
107
|
+
private Measure;
|
|
108
|
+
private Calculate;
|
|
109
|
+
}
|
|
36
110
|
/** AppoMobi.Gestures TouchActionEventArgs. */
|
|
37
111
|
export declare class TouchActionEventArgs {
|
|
38
112
|
Id: number;
|
|
@@ -45,13 +119,23 @@ export declare class TouchActionEventArgs {
|
|
|
45
119
|
Distance: DistanceInfo;
|
|
46
120
|
NumberOfTouches: number;
|
|
47
121
|
IsInContact: boolean;
|
|
122
|
+
/** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
|
|
123
|
+
Manipulation?: ManipulationInfo;
|
|
48
124
|
Scale: number;
|
|
125
|
+
/** When the event happened (ms, performance.now() time): the browser event's timeStamp, now for one made in code. */
|
|
49
126
|
Timestamp: number;
|
|
50
127
|
/** ms since the previous event of the same pointer. */
|
|
51
128
|
DeltaTimeMs: number;
|
|
52
|
-
/**
|
|
129
|
+
/** The press's recent positions the velocity is measured over, carried from event to event of one pointer. */
|
|
130
|
+
Trail?: VelocityTrail;
|
|
131
|
+
/**
|
|
132
|
+
* Mouse wheel: Delta > 0 = wheel down / right (browser sign). IsHorizontal: the event is along the X axis (a tilting
|
|
133
|
+
* wheel, the sideways part of a two-finger touchpad swipe), as C# WheelEventArgs.IsHorizontal.
|
|
134
|
+
*/
|
|
53
135
|
Wheel: {
|
|
54
136
|
Delta: number;
|
|
137
|
+
IsHorizontal?: boolean;
|
|
138
|
+
IsZoom?: boolean;
|
|
55
139
|
};
|
|
56
140
|
/**
|
|
57
141
|
* AppoMobi TouchActionEventArgs.Handled: set by a control that actually used the event. The canvas prevents the
|
package/dist/core/Gestures.js
CHANGED
|
@@ -10,6 +10,14 @@ export class SKPoint {
|
|
|
10
10
|
Add(p) { return new SKPoint(this.X + p.X, this.Y + p.Y); }
|
|
11
11
|
Subtract(p) { return new SKPoint(this.X - p.X, this.Y - p.Y); }
|
|
12
12
|
}
|
|
13
|
+
/** Gesture settings shared by every canvas (AppoMobi TouchEffect, same names on every DrawnUI engine). */
|
|
14
|
+
export class TouchEffect {
|
|
15
|
+
/**
|
|
16
|
+
* How long a press is held without moving past Canvas.TappedCancelMoveThresholdPoints to be a LongPressing, at the press
|
|
17
|
+
* point; its release sends no Tapped. A timer, no frames while waiting. Default 750 ms on every engine (drawnui-cross 6cf).
|
|
18
|
+
*/
|
|
19
|
+
static LongPressTimeMsDefault = 750;
|
|
20
|
+
}
|
|
13
21
|
/** TouchActionEventArgs.DistanceInfo. Velocity is pixels per second. */
|
|
14
22
|
export class DistanceInfo {
|
|
15
23
|
Start = SKPoint.Empty;
|
|
@@ -18,6 +26,67 @@ export class DistanceInfo {
|
|
|
18
26
|
Total = SKPoint.Empty;
|
|
19
27
|
Velocity = SKPoint.Empty;
|
|
20
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The last positions of a press with their times (DrawnUi.Rust gestures `Trail`, 6d525f7). Measured only against the
|
|
31
|
+
* previous move, irregular delivery made the velocity worthless: moves handled in one burst (queued pointer events
|
|
32
|
+
* 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
|
|
33
|
+
* the limit. Moves under BurstMs apart are one position; a move's velocity is its displacement over the last WindowMs,
|
|
34
|
+
* the earlier position interpolated; when the previous move is already that old, its own velocity exactly (evenly
|
|
35
|
+
* spaced input at 60 Hz measures as before).
|
|
36
|
+
*/
|
|
37
|
+
export class VelocityTrail {
|
|
38
|
+
/** A move's velocity is its displacement over this much time. */
|
|
39
|
+
static WindowMs = 16;
|
|
40
|
+
/** Below this since the press no velocity is measured yet: the first moves of a burst. */
|
|
41
|
+
static MinMs = 4;
|
|
42
|
+
/** Moves closer than this came in one burst: one position, at the burst's first time. */
|
|
43
|
+
static BurstMs = 1;
|
|
44
|
+
static Capacity = 16;
|
|
45
|
+
points = [];
|
|
46
|
+
Push(x, y, t) {
|
|
47
|
+
const last = this.points[this.points.length - 1];
|
|
48
|
+
if (last && t - last.T < VelocityTrail.BurstMs) {
|
|
49
|
+
last.X = x;
|
|
50
|
+
last.Y = y;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (this.points.length === VelocityTrail.Capacity)
|
|
54
|
+
this.points.shift();
|
|
55
|
+
this.points.push({ X: x, Y: y, T: t });
|
|
56
|
+
}
|
|
57
|
+
/** The velocity at (x, y) at time t (ms), pixels per second; `fallback` right after the press. */
|
|
58
|
+
Velocity(x, y, t, fallback) {
|
|
59
|
+
let n = this.points.length;
|
|
60
|
+
// a move in the burst of the last position measures from the positions before it
|
|
61
|
+
if (n > 0 && t - this.points[n - 1].T < VelocityTrail.BurstMs)
|
|
62
|
+
n--;
|
|
63
|
+
if (n === 0)
|
|
64
|
+
return fallback;
|
|
65
|
+
const since = t - this.points[0].T;
|
|
66
|
+
if (since < VelocityTrail.MinMs)
|
|
67
|
+
return fallback;
|
|
68
|
+
const window = Math.min(VelocityTrail.WindowMs, since), at = t - window;
|
|
69
|
+
const last = this.points[n - 1];
|
|
70
|
+
if (last.T <= at) {
|
|
71
|
+
const secs = (t - last.T) / 1000;
|
|
72
|
+
return new SKPoint((x - last.X) / secs, (y - last.Y) / secs);
|
|
73
|
+
}
|
|
74
|
+
// the position at `at`: between the two positions around it (the current one included)
|
|
75
|
+
let fromX = this.points[0].X, fromY = this.points[0].Y, prev = this.points[0];
|
|
76
|
+
for (let i = 1; i <= n; i++) {
|
|
77
|
+
const p = i < n ? this.points[i] : { X: x, Y: y, T: t };
|
|
78
|
+
if (p.T >= at) {
|
|
79
|
+
const share = p.T - prev.T < 1e-6 ? 1 : (at - prev.T) / (p.T - prev.T);
|
|
80
|
+
fromX = prev.X + (p.X - prev.X) * share;
|
|
81
|
+
fromY = prev.Y + (p.Y - prev.Y) * share;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
prev = p;
|
|
85
|
+
}
|
|
86
|
+
const secs = window / 1000;
|
|
87
|
+
return new SKPoint((x - fromX) / secs, (y - fromY) / secs);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
21
90
|
/** AppoMobi.Gestures PointerData: the device and button behind a Down / Up / Tapped (every button is delivered). */
|
|
22
91
|
export class PointerData {
|
|
23
92
|
Button = "Left";
|
|
@@ -27,6 +96,97 @@ export class PointerData {
|
|
|
27
96
|
/** DOM `buttons` bitmask of the buttons held (1 left, 2 right, 4 middle, 8 back, 16 forward). */
|
|
28
97
|
PressedButtons = 0;
|
|
29
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* AppoMobi.Gestures ManipulationInfo: what two or more fingers did since the previous move, on a Panning while they are
|
|
101
|
+
* down. Pinch to zoom from `Scale`, turn from `Rotation`. Pixels.
|
|
102
|
+
*/
|
|
103
|
+
export class ManipulationInfo {
|
|
104
|
+
Center;
|
|
105
|
+
PreviousCenter;
|
|
106
|
+
Scale;
|
|
107
|
+
Rotation;
|
|
108
|
+
ScaleTotal;
|
|
109
|
+
RotationTotal;
|
|
110
|
+
TouchesCount;
|
|
111
|
+
constructor(
|
|
112
|
+
/** The middle of the fingers now, and at the previous move. */
|
|
113
|
+
Center, PreviousCenter,
|
|
114
|
+
/** The fingers' spread now over the previous one, minus 1: 0.05 = 5% further apart. */
|
|
115
|
+
Scale,
|
|
116
|
+
/** Degrees the first two fingers turned since the previous move, the short way (never a jump across ±180). */
|
|
117
|
+
Rotation,
|
|
118
|
+
/** `Scale` and `Rotation` added up since the number of fingers last changed. */
|
|
119
|
+
ScaleTotal, RotationTotal, TouchesCount) {
|
|
120
|
+
this.Center = Center;
|
|
121
|
+
this.PreviousCenter = PreviousCenter;
|
|
122
|
+
this.Scale = Scale;
|
|
123
|
+
this.Rotation = Rotation;
|
|
124
|
+
this.ScaleTotal = ScaleTotal;
|
|
125
|
+
this.RotationTotal = RotationTotal;
|
|
126
|
+
this.TouchesCount = TouchesCount;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The fingers down and what they did (AppoMobi.Gestures MultitouchTracker, after Mapsui; as DrawnUi.Rust): their middle,
|
|
131
|
+
* the first one's distance from it, the first two's angle. A new finger count starts the totals again.
|
|
132
|
+
*/
|
|
133
|
+
export class MultitouchTracker {
|
|
134
|
+
fingers = new Map();
|
|
135
|
+
state;
|
|
136
|
+
scaleTotal = 0;
|
|
137
|
+
rotationTotal = 0;
|
|
138
|
+
get Count() { return this.fingers.size; }
|
|
139
|
+
/** The first finger came down: everything before is forgotten. */
|
|
140
|
+
Restart(id, at) {
|
|
141
|
+
this.fingers.clear();
|
|
142
|
+
this.fingers.set(id, at);
|
|
143
|
+
this.scaleTotal = this.rotationTotal = 0;
|
|
144
|
+
this.state = this.Measure();
|
|
145
|
+
}
|
|
146
|
+
/** A finger came down or moved; what the fingers did while two or more are down and they moved. */
|
|
147
|
+
AddMovement(id, at) {
|
|
148
|
+
this.fingers.set(id, at);
|
|
149
|
+
return this.Calculate();
|
|
150
|
+
}
|
|
151
|
+
Lifted(id) { if (this.fingers.delete(id))
|
|
152
|
+
this.Calculate(); }
|
|
153
|
+
Reset() { this.fingers.clear(); this.state = undefined; }
|
|
154
|
+
Measure() {
|
|
155
|
+
const points = [...this.fingers.values()];
|
|
156
|
+
if (points.length === 0)
|
|
157
|
+
return undefined;
|
|
158
|
+
const first = points[0];
|
|
159
|
+
if (points.length === 1)
|
|
160
|
+
return { Center: first, Radius: 0, Angle: 0, Count: 1 };
|
|
161
|
+
let x = 0, y = 0;
|
|
162
|
+
for (const p of points) {
|
|
163
|
+
x += p.X;
|
|
164
|
+
y += p.Y;
|
|
165
|
+
}
|
|
166
|
+
const center = new SKPoint(x / points.length, y / points.length), second = points[1];
|
|
167
|
+
return {
|
|
168
|
+
Center: center, Radius: Math.hypot(first.X - center.X, first.Y - center.Y),
|
|
169
|
+
Angle: (Math.atan2(second.Y - first.Y, second.X - first.X) * 180) / Math.PI, Count: points.length,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
Calculate() {
|
|
173
|
+
const now = this.Measure(), previous = this.state;
|
|
174
|
+
this.state = now;
|
|
175
|
+
if (!now || !previous || now.Count < 2)
|
|
176
|
+
return undefined;
|
|
177
|
+
if (now.Count !== previous.Count) {
|
|
178
|
+
this.scaleTotal = this.rotationTotal = 0;
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
const scale = previous.Radius > 0 && now.Radius !== previous.Radius ? now.Radius / previous.Radius - 1 : 0;
|
|
182
|
+
const rotation = ((((now.Angle - previous.Angle + 540) % 360) + 360) % 360) - 180;
|
|
183
|
+
this.scaleTotal += scale;
|
|
184
|
+
this.rotationTotal += rotation;
|
|
185
|
+
if (now.Center.X === previous.Center.X && now.Center.Y === previous.Center.Y && now.Radius === previous.Radius && now.Angle === previous.Angle)
|
|
186
|
+
return undefined;
|
|
187
|
+
return new ManipulationInfo(now.Center, previous.Center, scale, rotation, this.scaleTotal, this.rotationTotal, now.Count);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
30
190
|
/** AppoMobi.Gestures TouchActionEventArgs. */
|
|
31
191
|
export class TouchActionEventArgs {
|
|
32
192
|
Id = 0;
|
|
@@ -39,11 +199,19 @@ export class TouchActionEventArgs {
|
|
|
39
199
|
Distance = new DistanceInfo();
|
|
40
200
|
NumberOfTouches = 1;
|
|
41
201
|
IsInContact = false;
|
|
202
|
+
/** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
|
|
203
|
+
Manipulation;
|
|
42
204
|
Scale = 1;
|
|
205
|
+
/** When the event happened (ms, performance.now() time): the browser event's timeStamp, now for one made in code. */
|
|
43
206
|
Timestamp = performance.now();
|
|
44
207
|
/** ms since the previous event of the same pointer. */
|
|
45
208
|
DeltaTimeMs = 0;
|
|
46
|
-
/**
|
|
209
|
+
/** The press's recent positions the velocity is measured over, carried from event to event of one pointer. */
|
|
210
|
+
Trail;
|
|
211
|
+
/**
|
|
212
|
+
* Mouse wheel: Delta > 0 = wheel down / right (browser sign). IsHorizontal: the event is along the X axis (a tilting
|
|
213
|
+
* wheel, the sideways part of a two-finger touchpad swipe), as C# WheelEventArgs.IsHorizontal.
|
|
214
|
+
*/
|
|
47
215
|
Wheel = { Delta: 0 };
|
|
48
216
|
/**
|
|
49
217
|
* AppoMobi TouchActionEventArgs.Handled: set by a control that actually used the event. The canvas prevents the
|
|
@@ -65,8 +233,18 @@ export class TouchActionEventArgs {
|
|
|
65
233
|
d.End = released ? previous.Location : current.Location;
|
|
66
234
|
d.Delta = released ? SKPoint.Empty : current.Location.Subtract(previous.Location);
|
|
67
235
|
d.Total = previous.Distance.Total.Add(d.Delta);
|
|
68
|
-
|
|
69
|
-
|
|
236
|
+
if (released)
|
|
237
|
+
d.Velocity = previous.Distance.Velocity;
|
|
238
|
+
else {
|
|
239
|
+
let trail = previous.Trail;
|
|
240
|
+
if (!trail) {
|
|
241
|
+
trail = new VelocityTrail();
|
|
242
|
+
trail.Push(previous.Location.X, previous.Location.Y, previous.Timestamp);
|
|
243
|
+
}
|
|
244
|
+
d.Velocity = trail.Velocity(current.Location.X, current.Location.Y, current.Timestamp, previous.Distance.Velocity);
|
|
245
|
+
trail.Push(current.Location.X, current.Location.Y, current.Timestamp);
|
|
246
|
+
current.Trail = trail;
|
|
247
|
+
}
|
|
70
248
|
current.Distance = d;
|
|
71
249
|
}
|
|
72
250
|
}
|
|
@@ -79,7 +257,9 @@ export class SkiaGesturesParameters {
|
|
|
79
257
|
const p = new SkiaGesturesParameters();
|
|
80
258
|
p.Type = action;
|
|
81
259
|
p.Event = args;
|
|
82
|
-
|
|
260
|
+
// when its event happened, not when a frame got to it (a slow frame holds the events back; a double tap is judged
|
|
261
|
+
// by when the taps happened)
|
|
262
|
+
p.ArrivedTimeNanos = Math.round(args.Timestamp * 1e6);
|
|
83
263
|
return p;
|
|
84
264
|
}
|
|
85
265
|
}
|
|
@@ -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
|
+
}
|