drawnui-react 0.1.0-preview.4 → 0.1.0-preview.40
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 +119 -14
- package/SKIPPED.md +36 -26
- 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 +16 -2
- package/dist/controls/GridStructure.js +40 -4
- 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 +48 -2
- package/dist/controls/SkiaEditor.js +268 -53
- package/dist/controls/SkiaGif.d.ts +7 -0
- package/dist/controls/SkiaGif.js +25 -4
- package/dist/controls/SkiaImage.d.ts +5 -0
- package/dist/controls/SkiaImage.js +48 -14
- package/dist/controls/SkiaLabel.d.ts +117 -9
- package/dist/controls/SkiaLabel.js +526 -80
- package/dist/controls/SkiaLabelFps.d.ts +16 -0
- package/dist/controls/SkiaLabelFps.js +41 -0
- package/dist/controls/SkiaLayout.d.ts +89 -9
- package/dist/controls/SkiaLayout.js +364 -21
- 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 +35 -5
- package/dist/controls/SkiaScroll.js +252 -32
- 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 +13 -2
- package/dist/controls/SkiaShape.js +50 -10
- 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 +22 -10
- 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 +134 -0
- package/dist/core/Accessibility.js +675 -9
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +222 -10
- package/dist/core/Canvas.js +698 -37
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +81 -2
- package/dist/core/Gestures.js +177 -3
- 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 +205 -0
- package/dist/core/ScrollAnimators.js +9 -0
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +279 -10
- package/dist/core/SkiaControl.js +621 -64
- package/dist/core/SkiaEffect.d.ts +17 -0
- package/dist/core/SkiaEffect.js +43 -8
- package/dist/core/SkiaImageManager.js +1 -1
- package/dist/core/Super.d.ts +29 -2
- package/dist/core/Super.js +54 -3
- 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 +6 -0
- package/dist/index.js +6 -0
- package/dist/react/SkiaShell.js +65 -26
- package/dist/react/index.d.ts +33 -4
- package/dist/react/index.js +157 -18
- package/dist/react/reconciler.d.ts +20 -0
- package/dist/react/reconciler.js +69 -14
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +61 -2
|
@@ -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,13 +18,48 @@ 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;
|
|
34
|
+
/** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
|
|
35
|
+
static IsDispatchingKeyDown: boolean;
|
|
18
36
|
static get IsAltPressed(): boolean;
|
|
19
37
|
/** C# AttachToKeyboardAsync / JS attachGlobalKeyboard: idempotent. */
|
|
20
38
|
static AttachToKeyboard(): void;
|
|
39
|
+
/**
|
|
40
|
+
* The modifier state follows each key event's own flags: a modifier pressed while the page had no focus (its keydown
|
|
41
|
+
* went elsewhere) still counts, and one released elsewhere stops counting.
|
|
42
|
+
*/
|
|
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;
|
|
21
48
|
static Subscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
|
|
22
49
|
static Unsubscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
|
|
50
|
+
/**
|
|
51
|
+
* Hooks observe keys, they never take them from the element that owns them (C# 845b26e9, GitHub #231). True when a
|
|
52
|
+
* focused DOM element is the key's target: a page input, textarea, select, button, link or contenteditable, an
|
|
53
|
+
* accessibility overlay node, the drawn editor's hidden textarea. False when the key goes to the page itself (body,
|
|
54
|
+
* html) or the canvas. A handler that acts on keys (edits, moves, calls preventDefault) skips owned keys, except
|
|
55
|
+
* those of its own element.
|
|
56
|
+
*/
|
|
57
|
+
static IsOwnedByElement(e: KeyboardEvent): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The key belongs to the input method (an IME composition, a soft keyboard): isComposing, keyCode 229, key "Process"
|
|
60
|
+
* or "Unidentified". Its result arrives as input events (TextInputProxy), never act on the key itself.
|
|
61
|
+
*/
|
|
62
|
+
static IsInputMethodKey(e: KeyboardEvent): boolean;
|
|
23
63
|
/** JS blurExternalTextInput: a page text input outside the canvas would keep receiving the keys. */
|
|
24
64
|
static BlurExternalTextInput(): void;
|
|
25
65
|
}
|
|
@@ -4,8 +4,21 @@ 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"); }
|
|
20
|
+
/** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
|
|
21
|
+
static IsDispatchingKeyDown = false;
|
|
9
22
|
static get IsAltPressed() { return KeyboardManager.pressed.has("AltLeft") || KeyboardManager.pressed.has("AltRight"); }
|
|
10
23
|
/** C# AttachToKeyboardAsync / JS attachGlobalKeyboard: idempotent. */
|
|
11
24
|
static AttachToKeyboard() {
|
|
@@ -15,23 +28,80 @@ export class KeyboardManager {
|
|
|
15
28
|
// inside a cross-frame iframe the embedding page keeps DOM focus: a pointerdown pulls it to this window
|
|
16
29
|
window.addEventListener("pointerdown", () => window.focus(), true);
|
|
17
30
|
window.addEventListener("keydown", (e) => {
|
|
18
|
-
|
|
19
|
-
KeyboardManager.pressed.add(code);
|
|
20
|
-
for (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
KeyboardManager.SyncModifiers(e);
|
|
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;
|
|
37
|
+
}
|
|
38
|
+
KeyboardManager.RaiseKeyDown(e);
|
|
26
39
|
}, true);
|
|
40
|
+
window.addEventListener("keydown", (e) => {
|
|
41
|
+
if (KeyboardManager.deferred !== e)
|
|
42
|
+
return;
|
|
43
|
+
KeyboardManager.deferred = undefined;
|
|
44
|
+
KeyboardManager.RaiseKeyDown(e);
|
|
45
|
+
});
|
|
27
46
|
window.addEventListener("keyup", (e) => {
|
|
28
47
|
const code = e.code || "";
|
|
48
|
+
KeyboardManager.SyncModifiers(e);
|
|
29
49
|
KeyboardManager.pressed.delete(code);
|
|
50
|
+
if (KeyboardManager.usedKey === code)
|
|
51
|
+
KeyboardManager.usedKey = undefined;
|
|
30
52
|
for (const h of [...KeyboardManager.keyUp])
|
|
31
53
|
h(code, e);
|
|
32
54
|
}, true);
|
|
33
55
|
window.addEventListener("blur", () => KeyboardManager.pressed.clear());
|
|
34
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The modifier state follows each key event's own flags: a modifier pressed while the page had no focus (its keydown
|
|
59
|
+
* went elsewhere) still counts, and one released elsewhere stops counting.
|
|
60
|
+
*/
|
|
61
|
+
static SyncModifiers(e) {
|
|
62
|
+
const sync = (down, left, right) => {
|
|
63
|
+
const p = KeyboardManager.pressed;
|
|
64
|
+
if (!down) {
|
|
65
|
+
p.delete(left);
|
|
66
|
+
p.delete(right);
|
|
67
|
+
}
|
|
68
|
+
else if (!p.has(left) && !p.has(right))
|
|
69
|
+
p.add(left);
|
|
70
|
+
};
|
|
71
|
+
sync(!!e.altKey, "AltLeft", "AltRight");
|
|
72
|
+
sync(!!e.ctrlKey, "ControlLeft", "ControlRight");
|
|
73
|
+
sync(!!e.shiftKey, "ShiftLeft", "ShiftRight");
|
|
74
|
+
sync(!!e.metaKey, "MetaLeft", "MetaRight");
|
|
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); }
|
|
35
105
|
static Subscribe(down, char, up) {
|
|
36
106
|
KeyboardManager.AttachToKeyboard();
|
|
37
107
|
KeyboardManager.keyDown.add(down);
|
|
@@ -45,6 +115,26 @@ export class KeyboardManager {
|
|
|
45
115
|
if (up)
|
|
46
116
|
KeyboardManager.keyUp.delete(up);
|
|
47
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Hooks observe keys, they never take them from the element that owns them (C# 845b26e9, GitHub #231). True when a
|
|
120
|
+
* focused DOM element is the key's target: a page input, textarea, select, button, link or contenteditable, an
|
|
121
|
+
* accessibility overlay node, the drawn editor's hidden textarea. False when the key goes to the page itself (body,
|
|
122
|
+
* html) or the canvas. A handler that acts on keys (edits, moves, calls preventDefault) skips owned keys, except
|
|
123
|
+
* those of its own element.
|
|
124
|
+
*/
|
|
125
|
+
static IsOwnedByElement(e) {
|
|
126
|
+
const target = e.target;
|
|
127
|
+
const tag = target?.tagName;
|
|
128
|
+
// the canvas host holds the DOM focus when no drawn control has it: its keys are the app's, as the canvas' own
|
|
129
|
+
return !!tag && tag !== "BODY" && tag !== "HTML" && tag !== "CANVAS" && target?.dataset?.drawnuiHost !== "1";
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The key belongs to the input method (an IME composition, a soft keyboard): isComposing, keyCode 229, key "Process"
|
|
133
|
+
* or "Unidentified". Its result arrives as input events (TextInputProxy), never act on the key itself.
|
|
134
|
+
*/
|
|
135
|
+
static IsInputMethodKey(e) {
|
|
136
|
+
return e.isComposing || e.keyCode === 229 || e.key === "Process" || e.key === "Unidentified";
|
|
137
|
+
}
|
|
48
138
|
/** JS blurExternalTextInput: a page text input outside the canvas would keep receiving the keys. */
|
|
49
139
|
static BlurExternalTextInput() {
|
|
50
140
|
const a = typeof document !== "undefined" ? document.activeElement : null;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { DrawingContext, SkiaControl } from "./SkiaControl";
|
|
2
|
+
import { SKPoint } from "./Gestures";
|
|
3
|
+
import { SKRect } from "./Types";
|
|
4
|
+
import { type SkiaAccessibilityManager } from "./Accessibility";
|
|
5
|
+
/** A popup window opened with `Canvas.OpenPopupWindow` (drawnui-cross 6at, C# PopupId, Rust PopupId). */
|
|
6
|
+
export type PopupId = number;
|
|
7
|
+
/** Where a popup window opens from, in canvas points, or a control (C# PopupAnchor, Rust PopupAnchor). */
|
|
8
|
+
export declare class PopupAnchor {
|
|
9
|
+
/** The point or the rect, in canvas points (empty for a control). */
|
|
10
|
+
readonly Rect: SKRect;
|
|
11
|
+
/** A point: the popup's top-left corner is there; where the canvas ends it opens to the left of the point, or above it. */
|
|
12
|
+
readonly IsPoint: boolean;
|
|
13
|
+
/** A control: the popup opens below the rect it is drawn at now, as for a rect. */
|
|
14
|
+
readonly Control?: SkiaControl | undefined;
|
|
15
|
+
private constructor();
|
|
16
|
+
/** A point (where a right click was), in canvas points. */
|
|
17
|
+
static AtPoint(point: SKPoint): PopupAnchor;
|
|
18
|
+
/** A rect (the button a dropdown belongs to), in canvas points: below it, left edges together; where the canvas ends, above it or right edges together. */
|
|
19
|
+
static AtRect(rect: SKRect): PopupAnchor;
|
|
20
|
+
/** A control: as a rect, with the rect it is drawn at now (moved, scaled, scrolled). */
|
|
21
|
+
static AtControl(control: SkiaControl): PopupAnchor;
|
|
22
|
+
/** A point, a rect or a control as an anchor. */
|
|
23
|
+
static From(anchor: PopupAnchor | SKPoint | SKRect | SkiaControl | {
|
|
24
|
+
X: number;
|
|
25
|
+
Y: number;
|
|
26
|
+
}): PopupAnchor;
|
|
27
|
+
/** The anchor in canvas pixels. */
|
|
28
|
+
Pixels(scale: number): SKRect;
|
|
29
|
+
}
|
|
30
|
+
/** How a popup window behaves; the defaults: sized to its content, closed by a press outside it, Escape or the app. */
|
|
31
|
+
export interface PopupWindowOptions {
|
|
32
|
+
/** Its size in points; unset: the size its content measures to. Never larger than the canvas. */
|
|
33
|
+
Size?: {
|
|
34
|
+
Width: number;
|
|
35
|
+
Height: number;
|
|
36
|
+
};
|
|
37
|
+
/** It also closes once the mouse has stayed outside it (or off the canvas) for 300 ms. */
|
|
38
|
+
CloseOnPointerLeave?: boolean;
|
|
39
|
+
/** Drawn on the canvas, inside it: always so in the browser (accepted for the same API as the other engines). */
|
|
40
|
+
OnCanvas?: boolean;
|
|
41
|
+
/** A window of its own drawn on the CPU (desktop engines); no effect in the browser. */
|
|
42
|
+
Cpu?: boolean;
|
|
43
|
+
/** Shows only, as a tooltip: takes no input, has no accessibility node, Escape and a press outside leave it open. */
|
|
44
|
+
Passive?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** The canvas side the layer needs. */
|
|
47
|
+
interface PopupHostCanvas {
|
|
48
|
+
Update(): void;
|
|
49
|
+
DisposeObject(o: {
|
|
50
|
+
Dispose(): void;
|
|
51
|
+
}): void;
|
|
52
|
+
RaisePopupWindowClosed(id: PopupId): void;
|
|
53
|
+
readonly AccessibilityManager: SkiaAccessibilityManager;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The popup windows of one canvas (C# PopupLayer): drawn over everything, given input first, closed by a press outside
|
|
57
|
+
* (the rest of that press goes nowhere, as with native menus).
|
|
58
|
+
*/
|
|
59
|
+
export declare class PopupLayer {
|
|
60
|
+
private readonly canvas;
|
|
61
|
+
private readonly popups;
|
|
62
|
+
private nextId;
|
|
63
|
+
/** A press outside closed the popups: the rest of that press goes nowhere. */
|
|
64
|
+
SwallowPress: boolean;
|
|
65
|
+
constructor(canvas: PopupHostCanvas);
|
|
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[];
|
|
69
|
+
get HasInteractive(): boolean;
|
|
70
|
+
/** The content of the top popup window that takes input. */
|
|
71
|
+
get TopInteractive(): SkiaControl | undefined;
|
|
72
|
+
IsOpen(id: PopupId): boolean;
|
|
73
|
+
Open(root: SkiaControl, anchor: PopupAnchor, options: PopupWindowOptions, superview: SkiaControl["_superview"]): PopupId;
|
|
74
|
+
Close(id: PopupId): void;
|
|
75
|
+
CloseTop(): boolean;
|
|
76
|
+
CloseAll(passiveToo: boolean): void;
|
|
77
|
+
private Remove;
|
|
78
|
+
private static IsInside;
|
|
79
|
+
/** Tab stays inside the top popup window that takes input (a menu, a dropdown) while it is open. */
|
|
80
|
+
private UpdateKeyboardScope;
|
|
81
|
+
/** The top popup window taking input whose content is under the point (canvas pixels). */
|
|
82
|
+
At(x: number, y: number): SkiaControl | undefined;
|
|
83
|
+
/** The pointer is at (x, y) (undefined: off the canvas): popups closing on pointer leave close after 300 ms outside. */
|
|
84
|
+
PointerAt(x: number | undefined, y: number | undefined): void;
|
|
85
|
+
/**
|
|
86
|
+
* Where a popup of `w` x `h` goes for `anchor` (pixels) inside `bounds`: at the anchor's corner, flipped to its other side
|
|
87
|
+
* where it does not fit, then kept inside (C# PopupLayer.Place, Rust place_popup).
|
|
88
|
+
*/
|
|
89
|
+
static Place(anchor: SKRect, point: boolean, w: number, h: number, bounds: SKRect): SKRect;
|
|
90
|
+
/** Measures, places and draws every popup over the content, inside `bounds` (canvas pixels). */
|
|
91
|
+
Draw(ctx: DrawingContext, bounds: SKRect): void;
|
|
92
|
+
Dispose(): void;
|
|
93
|
+
}
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { SKPoint } from "./Gestures";
|
|
2
|
+
import { SKRect } from "./Types";
|
|
3
|
+
import { KeyboardManager } from "./KeyboardManager";
|
|
4
|
+
import { Aria } from "./Accessibility";
|
|
5
|
+
/** Where a popup window opens from, in canvas points, or a control (C# PopupAnchor, Rust PopupAnchor). */
|
|
6
|
+
export class PopupAnchor {
|
|
7
|
+
Rect;
|
|
8
|
+
IsPoint;
|
|
9
|
+
Control;
|
|
10
|
+
constructor(
|
|
11
|
+
/** The point or the rect, in canvas points (empty for a control). */
|
|
12
|
+
Rect,
|
|
13
|
+
/** A point: the popup's top-left corner is there; where the canvas ends it opens to the left of the point, or above it. */
|
|
14
|
+
IsPoint,
|
|
15
|
+
/** A control: the popup opens below the rect it is drawn at now, as for a rect. */
|
|
16
|
+
Control) {
|
|
17
|
+
this.Rect = Rect;
|
|
18
|
+
this.IsPoint = IsPoint;
|
|
19
|
+
this.Control = Control;
|
|
20
|
+
}
|
|
21
|
+
/** A point (where a right click was), in canvas points. */
|
|
22
|
+
static AtPoint(point) { return new PopupAnchor(new SKRect(point.X, point.Y, point.X, point.Y), true); }
|
|
23
|
+
/** A rect (the button a dropdown belongs to), in canvas points: below it, left edges together; where the canvas ends, above it or right edges together. */
|
|
24
|
+
static AtRect(rect) { return new PopupAnchor(rect, false); }
|
|
25
|
+
/** A control: as a rect, with the rect it is drawn at now (moved, scaled, scrolled). */
|
|
26
|
+
static AtControl(control) { return new PopupAnchor(SKRect.Empty, false, control); }
|
|
27
|
+
/** A point, a rect or a control as an anchor. */
|
|
28
|
+
static From(anchor) {
|
|
29
|
+
if (anchor instanceof PopupAnchor)
|
|
30
|
+
return anchor;
|
|
31
|
+
if (typeof anchor.Measure === "function")
|
|
32
|
+
return PopupAnchor.AtControl(anchor);
|
|
33
|
+
if ("Right" in anchor && "Bottom" in anchor) {
|
|
34
|
+
const r = anchor;
|
|
35
|
+
return PopupAnchor.AtRect(new SKRect(r.Left, r.Top, r.Right, r.Bottom));
|
|
36
|
+
}
|
|
37
|
+
const p = anchor;
|
|
38
|
+
return PopupAnchor.AtPoint(new SKPoint(p.X, p.Y));
|
|
39
|
+
}
|
|
40
|
+
/** The anchor in canvas pixels. */
|
|
41
|
+
Pixels(scale) {
|
|
42
|
+
if (this.Control) {
|
|
43
|
+
const r = this.Control.GetAccessibilityPixelRect(); // on screen now: through caches and scroll offsets
|
|
44
|
+
return r.Width > 0 || r.Height > 0 ? r : this.Control.DrawingRect;
|
|
45
|
+
}
|
|
46
|
+
const r = this.Rect;
|
|
47
|
+
return new SKRect(r.Left * scale, r.Top * scale, r.Right * scale, r.Bottom * scale);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The popup windows of one canvas (C# PopupLayer): drawn over everything, given input first, closed by a press outside
|
|
52
|
+
* (the rest of that press goes nowhere, as with native menus).
|
|
53
|
+
*/
|
|
54
|
+
export class PopupLayer {
|
|
55
|
+
canvas;
|
|
56
|
+
popups = [];
|
|
57
|
+
nextId = 0;
|
|
58
|
+
/** A press outside closed the popups: the rest of that press goes nowhere. */
|
|
59
|
+
SwallowPress = false;
|
|
60
|
+
constructor(canvas) {
|
|
61
|
+
this.canvas = canvas;
|
|
62
|
+
}
|
|
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); }
|
|
66
|
+
get HasInteractive() { return this.popups.some((p) => !p.Options.Passive); }
|
|
67
|
+
/** The content of the top popup window that takes input. */
|
|
68
|
+
get TopInteractive() { for (let i = this.popups.length - 1; i >= 0; i--)
|
|
69
|
+
if (!this.popups[i].Options.Passive)
|
|
70
|
+
return this.popups[i].Root; return undefined; }
|
|
71
|
+
IsOpen(id) { return this.popups.some((p) => p.Id === id); }
|
|
72
|
+
Open(root, anchor, options, superview) {
|
|
73
|
+
root.HorizontalOptions = "Start";
|
|
74
|
+
root.VerticalOptions = "Start";
|
|
75
|
+
if (options.Size) {
|
|
76
|
+
root.WidthRequest = options.Size.Width;
|
|
77
|
+
root.HeightRequest = options.Size.Height;
|
|
78
|
+
}
|
|
79
|
+
if (options.Passive) {
|
|
80
|
+
root.InputTransparent = true;
|
|
81
|
+
root.AccessibilityRole ??= Aria.RolePresentation;
|
|
82
|
+
}
|
|
83
|
+
root.Parent = undefined;
|
|
84
|
+
root._superview = superview;
|
|
85
|
+
const a11y = this.canvas.AccessibilityManager;
|
|
86
|
+
const popup = { Id: ++this.nextId, Root: root, Anchor: anchor, Options: options, Rect: SKRect.Empty, LeftAt: 0 };
|
|
87
|
+
// opened from the keyboard (Enter on a focused control, a key handler such as Alt+F): it takes the keyboard (6ao) and
|
|
88
|
+
// gives it back when it closes, to the control it opens from, else to where the keyboard was (unless that is inside a
|
|
89
|
+
// popup closing now: Left / Right in a menu bar). A popup opened with the mouse leaves the keyboard alone.
|
|
90
|
+
if (!options.Passive && (a11y.FocusedNode || KeyboardManager.IsDispatchingKeyDown)) {
|
|
91
|
+
const keyboard = a11y.FocusedNode;
|
|
92
|
+
popup.Opener = anchor.Control ?? (keyboard && !this.popups.some((p) => PopupLayer.IsInside(keyboard, p.Root)) ? keyboard : undefined);
|
|
93
|
+
a11y.FocusOpenedPopup(root);
|
|
94
|
+
}
|
|
95
|
+
this.popups.push(popup);
|
|
96
|
+
this.UpdateKeyboardScope();
|
|
97
|
+
return popup.Id;
|
|
98
|
+
}
|
|
99
|
+
Close(id) { const p = this.popups.find((x) => x.Id === id); if (p)
|
|
100
|
+
this.Remove(p); }
|
|
101
|
+
CloseTop() {
|
|
102
|
+
for (let i = this.popups.length - 1; i >= 0; i--)
|
|
103
|
+
if (!this.popups[i].Options.Passive) {
|
|
104
|
+
this.Remove(this.popups[i]);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
CloseAll(passiveToo) {
|
|
110
|
+
for (const p of [...this.popups])
|
|
111
|
+
if (passiveToo || !p.Options.Passive)
|
|
112
|
+
this.Remove(p);
|
|
113
|
+
}
|
|
114
|
+
Remove(popup) {
|
|
115
|
+
const i = this.popups.indexOf(popup);
|
|
116
|
+
if (i < 0)
|
|
117
|
+
return;
|
|
118
|
+
this.popups.splice(i, 1);
|
|
119
|
+
// its nodes leave the accessibility tree with this frame, not when the disposal runs after it
|
|
120
|
+
const a11y = this.canvas.AccessibilityManager;
|
|
121
|
+
const focused = a11y.FocusedNode;
|
|
122
|
+
// the keyboard was in it (or nowhere): it goes back to the control the popup opened from, as native menus do
|
|
123
|
+
if (popup.Opener && (!focused || PopupLayer.IsInside(focused, popup.Root)))
|
|
124
|
+
a11y.RequestKeyboardFocus(popup.Opener);
|
|
125
|
+
this.UpdateKeyboardScope();
|
|
126
|
+
a11y.UnregisterSubtree(popup.Root);
|
|
127
|
+
a11y.ForceRebuildOnNextFrame();
|
|
128
|
+
this.canvas.DisposeObject(popup.Root);
|
|
129
|
+
this.canvas.Update();
|
|
130
|
+
this.canvas.RaisePopupWindowClosed(popup.Id);
|
|
131
|
+
}
|
|
132
|
+
static IsInside(control, root) {
|
|
133
|
+
for (let c = control; c; c = c.Parent)
|
|
134
|
+
if (c === root)
|
|
135
|
+
return true;
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
/** Tab stays inside the top popup window that takes input (a menu, a dropdown) while it is open. */
|
|
139
|
+
UpdateKeyboardScope() {
|
|
140
|
+
let top;
|
|
141
|
+
for (let i = this.popups.length - 1; i >= 0 && !top; i--)
|
|
142
|
+
if (!this.popups[i].Options.Passive)
|
|
143
|
+
top = this.popups[i].Root;
|
|
144
|
+
this.canvas.AccessibilityManager.KeyboardScope = top;
|
|
145
|
+
}
|
|
146
|
+
/** The top popup window taking input whose content is under the point (canvas pixels). */
|
|
147
|
+
At(x, y) {
|
|
148
|
+
for (let i = this.popups.length - 1; i >= 0; i--) {
|
|
149
|
+
const p = this.popups[i];
|
|
150
|
+
if (!p.Options.Passive && p.Root.IsVisible && p.Root.HitIsInside(x, y))
|
|
151
|
+
return p.Root;
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
/** The pointer is at (x, y) (undefined: off the canvas): popups closing on pointer leave close after 300 ms outside. */
|
|
156
|
+
PointerAt(x, y) {
|
|
157
|
+
const now = performance.now();
|
|
158
|
+
for (const p of [...this.popups]) {
|
|
159
|
+
if (!p.Options.CloseOnPointerLeave)
|
|
160
|
+
continue;
|
|
161
|
+
const inside = x !== undefined && y !== undefined && p.Root.HitIsInside(x, y);
|
|
162
|
+
if (inside) {
|
|
163
|
+
p.LeftAt = 0;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (!p.LeftAt) {
|
|
167
|
+
p.LeftAt = now;
|
|
168
|
+
window.setTimeout(() => { if (p.LeftAt && performance.now() - p.LeftAt >= 300)
|
|
169
|
+
this.Remove(p); }, 310);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Where a popup of `w` x `h` goes for `anchor` (pixels) inside `bounds`: at the anchor's corner, flipped to its other side
|
|
175
|
+
* where it does not fit, then kept inside (C# PopupLayer.Place, Rust place_popup).
|
|
176
|
+
*/
|
|
177
|
+
static Place(anchor, point, w, h, bounds) {
|
|
178
|
+
w = Math.max(0, Math.min(w, bounds.Width));
|
|
179
|
+
h = Math.max(0, Math.min(h, bounds.Height));
|
|
180
|
+
let left = anchor.Left;
|
|
181
|
+
if (left + w > bounds.Right)
|
|
182
|
+
left = point ? anchor.Left - w : anchor.Right - w;
|
|
183
|
+
let top = anchor.Bottom;
|
|
184
|
+
if (top + h > bounds.Bottom)
|
|
185
|
+
top = anchor.Top - h;
|
|
186
|
+
left = Math.round(Math.min(Math.max(left, bounds.Left), bounds.Right - w));
|
|
187
|
+
top = Math.round(Math.min(Math.max(top, bounds.Top), bounds.Bottom - h));
|
|
188
|
+
return new SKRect(left, top, left + Math.round(w), top + Math.round(h));
|
|
189
|
+
}
|
|
190
|
+
/** Measures, places and draws every popup over the content, inside `bounds` (canvas pixels). */
|
|
191
|
+
Draw(ctx, bounds) {
|
|
192
|
+
const scale = ctx.Scale;
|
|
193
|
+
for (const p of this.popups) {
|
|
194
|
+
const root = p.Root;
|
|
195
|
+
const size = root.Measure(bounds.Width, bounds.Height, scale).Pixels;
|
|
196
|
+
if (size.Width <= 0 || size.Height <= 0)
|
|
197
|
+
continue;
|
|
198
|
+
p.Rect = PopupLayer.Place(p.Anchor.Pixels(scale), p.Anchor.IsPoint, size.Width, size.Height, bounds);
|
|
199
|
+
root.Arrange(p.Rect, root.WidthRequest, root.HeightRequest, scale);
|
|
200
|
+
root.Render({ Context: ctx.Context, Destination: p.Rect, Scale: scale });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
Dispose() { for (const p of this.popups.splice(0))
|
|
204
|
+
p.Root.Dispose(); }
|
|
205
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Mirrors DrawnUi scrolling physics: DecelerationTimingParameters + ScrollFlingAnimator (fling),
|
|
2
2
|
// Spring + SpringTimingParameters + SpringWithVelocityAnimator (bounce), VelocityAccumulator, RubberBandUtils.
|
|
3
3
|
import { SkiaValueAnimator } from "./Animators";
|
|
4
|
+
import { VelocityTrail } from "./Gestures";
|
|
4
5
|
/** UIKit-style exponential deceleration: value(t) = v0 * (rate^(1000 t) - 1) / k, k = 1000 ln(rate). */
|
|
5
6
|
export class DecelerationTimingParameters {
|
|
6
7
|
InitialValue;
|
|
@@ -201,6 +202,14 @@ export class VelocityAccumulator {
|
|
|
201
202
|
Clear() { this.samples.length = 0; }
|
|
202
203
|
CaptureVelocity(x, y, arrivedTimeNanos = 0) {
|
|
203
204
|
const time = arrivedTimeNanos > 0 ? arrivedTimeNanos / 1e6 : performance.now();
|
|
205
|
+
// a move in the same burst as the last one replaces it: the first move of a burst carries only part of the burst's
|
|
206
|
+
// distance (DrawnUi.Rust VelocityAccumulator, 6d525f7)
|
|
207
|
+
const last = this.samples[this.samples.length - 1];
|
|
208
|
+
if (last && time - last.time < VelocityTrail.BurstMs) {
|
|
209
|
+
last.X = x;
|
|
210
|
+
last.Y = y;
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
204
213
|
if (this.samples.length === VelocityAccumulator.MaxSampleSize)
|
|
205
214
|
this.samples.shift();
|
|
206
215
|
this.samples.push({ X: x, Y: y, time });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Font } from "canvaskit-wasm";
|
|
2
|
+
/**
|
|
3
|
+
* Text shaping (C# SkiaLabel DrawShapedText, HarfBuzzSharp there; DrawnUi.Rust shaping.rs, harfrust) for the text that
|
|
4
|
+
* needs it: complex scripts whose letters join or reorder (Arabic, Hebrew marks, Indic, Thai...) and emoji sequences
|
|
5
|
+
* (ZWJ families, skin tones, flags, keycaps). Everything else keeps the plain path: one glyph per character.
|
|
6
|
+
* HarfBuzz and ICU come with the CanvasKit paragraph module, already in the build (no extra wasm): a run is laid out as a
|
|
7
|
+
* one-font paragraph and its shaped glyphs are read back; the label keeps its own line breaking and font fallback.
|
|
8
|
+
*/
|
|
9
|
+
/** C# SkiaLabel.UnicodeNeedsShaping, plus the characters that make emoji sequences and the right-to-left scripts C# leaves out. */
|
|
10
|
+
export declare function NeedsShaping(cp: number): boolean;
|
|
11
|
+
/** Characters that belong to the glyph before them (an emoji sequence or a mark): they keep its font (C# JoinsPreviousGlyph). */
|
|
12
|
+
export declare function JoinsPrevious(cp: number): boolean;
|
|
13
|
+
/** Right-to-left letters: a paragraph with one of them gets the bidirectional pass. */
|
|
14
|
+
export declare function IsRtl(cp: number): boolean;
|
|
15
|
+
/** Whether a text has a character `test` accepts. */
|
|
16
|
+
export declare function HasCodePoint(text: string, test: (cp: number) => boolean): boolean;
|
|
17
|
+
/** One shaped run: glyphs from x = 0 on the baseline, in visual order, and the advance of every code point in logical order (a cluster's advance on its first code point). */
|
|
18
|
+
export interface Shaped {
|
|
19
|
+
Glyphs: Uint16Array;
|
|
20
|
+
Positions: Float32Array;
|
|
21
|
+
Advances: number[];
|
|
22
|
+
Width: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Shapes `text` with `font` in one direction (the caller splits runs by font and by bidirectional level), `spacing`
|
|
26
|
+
* pixels after every code point. Undefined when the font was not registered through the font registry (no shaping
|
|
27
|
+
* data): the caller keeps its plain glyphs.
|
|
28
|
+
*/
|
|
29
|
+
export declare function Shape(font: Font, text: string, rtl: boolean, spacing: number): Shaped | undefined;
|
|
30
|
+
/** The visual runs of a line: for every UTF-16 index, the rank of its run from the left and whether it runs right to left. */
|
|
31
|
+
export interface BidiMap {
|
|
32
|
+
Rank: Int32Array;
|
|
33
|
+
Rtl: Uint8Array;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Bidirectional runs of a line (Unicode bidirectional algorithm, ICU in CanvasKit), read from the visual order of a
|
|
37
|
+
* paragraph of that line: digits after Arabic in a left-to-right paragraph stay with the Arabic run (level 2), as the
|
|
38
|
+
* algorithm orders them. Undefined when no font was registered for shaping.
|
|
39
|
+
*/
|
|
40
|
+
export declare function BidiRuns(text: string, rtlParagraph: boolean): BidiMap | undefined;
|