drawnui-react 0.1.0-preview.8 → 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.
Files changed (117) hide show
  1. package/README.md +229 -22
  2. package/SKIPPED.md +38 -29
  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 +25 -3
  8. package/dist/controls/GridStructure.js +81 -5
  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 +51 -2
  20. package/dist/controls/SkiaEditor.js +292 -58
  21. package/dist/controls/SkiaGif.d.ts +7 -0
  22. package/dist/controls/SkiaGif.js +25 -4
  23. package/dist/controls/SkiaImage.d.ts +10 -0
  24. package/dist/controls/SkiaImage.js +80 -19
  25. package/dist/controls/SkiaLabel.d.ts +200 -11
  26. package/dist/controls/SkiaLabel.js +925 -93
  27. package/dist/controls/SkiaLabelFps.d.ts +12 -0
  28. package/dist/controls/SkiaLabelFps.js +35 -0
  29. package/dist/controls/SkiaLayout.d.ts +89 -9
  30. package/dist/controls/SkiaLayout.js +397 -23
  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 +86 -7
  39. package/dist/controls/SkiaScroll.js +361 -40
  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 +15 -2
  45. package/dist/controls/SkiaShape.js +57 -10
  46. package/dist/controls/SkiaShell.d.ts +282 -0
  47. package/dist/controls/SkiaShell.js +972 -0
  48. package/dist/controls/SkiaSlider.d.ts +20 -2
  49. package/dist/controls/SkiaSlider.js +61 -7
  50. package/dist/controls/SkiaSprite.d.ts +4 -0
  51. package/dist/controls/SkiaSprite.js +27 -11
  52. package/dist/controls/SkiaSvg.d.ts +4 -0
  53. package/dist/controls/SkiaSvg.js +28 -4
  54. package/dist/controls/SkiaSwitch.d.ts +0 -1
  55. package/dist/controls/SkiaSwitch.js +4 -8
  56. package/dist/controls/SkiaToggle.d.ts +25 -5
  57. package/dist/controls/SkiaToggle.js +58 -5
  58. package/dist/controls/SnappingLayout.d.ts +12 -1
  59. package/dist/controls/SnappingLayout.js +21 -2
  60. package/dist/controls/TooltipStyle.d.ts +52 -0
  61. package/dist/controls/TooltipStyle.js +88 -0
  62. package/dist/core/Accessibility.d.ts +162 -11
  63. package/dist/core/Accessibility.js +882 -22
  64. package/dist/core/Animators.d.ts +37 -1
  65. package/dist/core/Animators.js +102 -9
  66. package/dist/core/Canvas.d.ts +307 -8
  67. package/dist/core/Canvas.js +1202 -66
  68. package/dist/core/ControlStyle.d.ts +2 -0
  69. package/dist/core/ControlStyle.js +2 -0
  70. package/dist/core/DesignerActions.d.ts +32 -0
  71. package/dist/core/DesignerActions.js +68 -0
  72. package/dist/core/Easing.d.ts +12 -1
  73. package/dist/core/Easing.js +25 -1
  74. package/dist/core/Gestures.d.ts +86 -2
  75. package/dist/core/Gestures.js +184 -4
  76. package/dist/core/Hover.d.ts +51 -0
  77. package/dist/core/Hover.js +140 -0
  78. package/dist/core/ImageEffects.d.ts +2 -0
  79. package/dist/core/ImageEffects.js +2 -0
  80. package/dist/core/KeyboardManager.d.ts +40 -0
  81. package/dist/core/KeyboardManager.js +98 -8
  82. package/dist/core/PopupWindows.d.ts +94 -0
  83. package/dist/core/PopupWindows.js +207 -0
  84. package/dist/core/Props.d.ts +11 -0
  85. package/dist/core/Props.js +44 -0
  86. package/dist/core/ScrollAnimators.d.ts +6 -0
  87. package/dist/core/ScrollAnimators.js +16 -1
  88. package/dist/core/Shaping.d.ts +40 -0
  89. package/dist/core/Shaping.js +224 -0
  90. package/dist/core/SkiaControl.d.ts +306 -13
  91. package/dist/core/SkiaControl.js +681 -75
  92. package/dist/core/SkiaEffect.d.ts +29 -1
  93. package/dist/core/SkiaEffect.js +78 -16
  94. package/dist/core/SkiaImageManager.d.ts +101 -18
  95. package/dist/core/SkiaImageManager.js +318 -63
  96. package/dist/core/Styles.js +7 -1
  97. package/dist/core/Super.d.ts +33 -2
  98. package/dist/core/Super.js +58 -12
  99. package/dist/core/TextInputProxy.d.ts +31 -1
  100. package/dist/core/TextInputProxy.js +97 -15
  101. package/dist/core/Tooltips.d.ts +71 -0
  102. package/dist/core/Tooltips.js +205 -0
  103. package/dist/core/Types.d.ts +11 -1
  104. package/dist/core/Types.js +32 -1
  105. package/dist/core/ViewsAdapter.d.ts +7 -2
  106. package/dist/core/ViewsAdapter.js +10 -3
  107. package/dist/index.d.ts +8 -0
  108. package/dist/index.js +8 -0
  109. package/dist/react/SkiaShell.d.ts +8 -74
  110. package/dist/react/SkiaShell.js +163 -475
  111. package/dist/react/index.d.ts +48 -4
  112. package/dist/react/index.js +210 -43
  113. package/dist/react/reconciler.d.ts +32 -0
  114. package/dist/react/reconciler.js +71 -40
  115. package/dist/vite/index.d.ts +9 -0
  116. package/dist/vite/index.js +36 -3
  117. package/package.json +103 -5
@@ -12,6 +12,10 @@ export declare class TextInputProxy {
12
12
  private static element?;
13
13
  private static owner?;
14
14
  private static composing;
15
+ /** The field took focus from a touch tap: its keys come from the soft keyboard (the return key ends editing). */
16
+ private static byTouch;
17
+ /** Set by the canvas while it runs a touch release's gestures (a field focused by them was focused by a touch). */
18
+ static TouchGesture: boolean;
15
19
  private static applying;
16
20
  /** The textarea (created on first use); KeyboardManager recognizes it through `data-drawnui-text-input`. */
17
21
  static get Element(): HTMLTextAreaElement | undefined;
@@ -20,12 +24,38 @@ export declare class TextInputProxy {
20
24
  private static Create;
21
25
  /** The editor took focus: the textarea mirrors it and gets DOM focus (soft keyboard, IME). */
22
26
  static Attach(editor: SkiaEditor): void;
27
+ /** The input got DOM focus in the task running now (Attach): a tap that focused the field needs nothing more. */
28
+ private static focusedNow;
29
+ /**
30
+ * The canvas calls it at the end of a tap's release (the pointerup, the user gesture iOS requires to open the soft
31
+ * keyboard): a tap on the focused field gives its input DOM focus inside that gesture, so the keyboard opens on the first
32
+ * tap and comes back on a tap after the user closed it. A touch anywhere else leaves it as it is: the keyboard the user
33
+ * closed stays closed while the page is scrolled. True when the tap was on the focused field (its input has focus now).
34
+ */
35
+ static FocusFromTap(clientX: number, clientY: number, touch?: boolean): boolean;
23
36
  static Detach(editor: SkiaEditor): void;
37
+ private static blurAfterTouch;
38
+ /** The input has focus from a touch release (its keyboard is up): a tap on another field needs no blur and focus. */
39
+ private static keyboardUp;
40
+ /** The canvas calls it at the end of each touch release, after FocusFromTap: a field left during the press lets go now. */
41
+ static AfterTouchEnd(): void;
24
42
  private static Configure;
25
43
  /** Editor text / selection changed: mirror it (never while an IME composition is in flight). */
26
44
  static Sync(editor: SkiaEditor): void;
27
- /** Puts the textarea over the editor so mobile browsers scroll the right spot into view. */
45
+ /**
46
+ * Where the hidden input sits: a field focused by a touch keeps it fixed at the top-left corner, never over the field (as
47
+ * the DrawnUi.Net web heads), so iOS never pans the page to reveal it (a scroll with AdaptToKeyboardAuto moves the
48
+ * field above the keyboard); a field focused by a mouse or the keyboard has it over the field, so a desktop input
49
+ * method opens its candidate window next to the text.
50
+ */
28
51
  private static Place;
52
+ private static placedLeft;
53
+ private static placedTop;
54
+ /**
55
+ * After each frame of the canvas: a focused field that moved (its page scrolled) takes its hidden input along, so a
56
+ * desktop input method keeps its window next to the text. Nothing to do while no field is focused.
57
+ */
58
+ static AfterFrame(canvas: unknown): void;
29
59
  /** The textarea changed (typing, IME commit, paste, undo): diff against the editor and replay through the stubs. */
30
60
  private static ApplyFromElement;
31
61
  }
@@ -11,6 +11,10 @@ export class TextInputProxy {
11
11
  static element;
12
12
  static owner;
13
13
  static composing = false;
14
+ /** The field took focus from a touch tap: its keys come from the soft keyboard (the return key ends editing). */
15
+ static byTouch = false;
16
+ /** Set by the canvas while it runs a touch release's gestures (a field focused by them was focused by a touch). */
17
+ static TouchGesture = false;
14
18
  static applying = false;
15
19
  /** The textarea (created on first use); KeyboardManager recognizes it through `data-drawnui-text-input`. */
16
20
  static get Element() { return TextInputProxy.element; }
@@ -27,12 +31,13 @@ export class TextInputProxy {
27
31
  el.setAttribute("autocorrect", "off");
28
32
  el.setAttribute("autocapitalize", "off");
29
33
  el.rows = 1;
30
- // fixed 1x1 box over the caret: invisible, still focusable, 16px font keeps iOS from zooming the page
34
+ // a fixed 1x1 box (where it sits: Place): invisible, still focusable, the 16px font keeps iOS from zooming the page
31
35
  el.style.cssText = "position:fixed;left:0;top:0;width:1px;height:1px;padding:0;border:0;margin:0;opacity:0.01;font-size:16px;line-height:1;resize:none;overflow:hidden;outline:none;background:transparent;color:transparent;caret-color:transparent;pointer-events:none;z-index:-1;";
32
36
  el.addEventListener("compositionstart", () => { TextInputProxy.composing = true; });
33
37
  el.addEventListener("compositionend", () => { TextInputProxy.composing = false; TextInputProxy.ApplyFromElement(); });
34
38
  el.addEventListener("input", () => TextInputProxy.ApplyFromElement());
35
39
  el.addEventListener("blur", () => {
40
+ TextInputProxy.keyboardUp = false;
36
41
  // focus moved to another DOM text field (a page input): the drawn editor loses focus like C# BlurExternalTextInput
37
42
  queueMicrotask(() => {
38
43
  const a = document.activeElement;
@@ -41,12 +46,6 @@ export class TextInputProxy {
41
46
  owner.IsFocused = false;
42
47
  });
43
48
  });
44
- // a tap on the canvas moves DOM focus to the body: give it back to the proxy synchronously (keeps the soft keyboard)
45
- window.addEventListener("pointerup", (e) => {
46
- const owner = TextInputProxy.owner;
47
- if (owner && owner.IsFocused && e.target?.tagName === "CANVAS")
48
- el.focus({ preventScroll: true });
49
- }, true);
50
49
  document.body.appendChild(el);
51
50
  return el;
52
51
  }
@@ -57,16 +56,73 @@ export class TextInputProxy {
57
56
  return;
58
57
  TextInputProxy.owner = editor;
59
58
  TextInputProxy.composing = false;
59
+ TextInputProxy.byTouch = TextInputProxy.TouchGesture || !!editor.Superview?.TouchPressed;
60
60
  TextInputProxy.Configure(editor, el);
61
61
  TextInputProxy.Sync(editor);
62
+ // a touch press: the input takes focus in its touchend (FocusFromTap), the only place iOS opens the keyboard from; a
63
+ // focus taken earlier would leave it focused with no keyboard
64
+ if (editor.Superview?.TouchPressed)
65
+ return;
62
66
  el.focus({ preventScroll: true });
67
+ TextInputProxy.focusedNow = true;
68
+ queueMicrotask(() => { TextInputProxy.focusedNow = false; });
69
+ }
70
+ /** The input got DOM focus in the task running now (Attach): a tap that focused the field needs nothing more. */
71
+ static focusedNow = false;
72
+ /**
73
+ * The canvas calls it at the end of a tap's release (the pointerup, the user gesture iOS requires to open the soft
74
+ * keyboard): a tap on the focused field gives its input DOM focus inside that gesture, so the keyboard opens on the first
75
+ * tap and comes back on a tap after the user closed it. A touch anywhere else leaves it as it is: the keyboard the user
76
+ * closed stays closed while the page is scrolled. True when the tap was on the focused field (its input has focus now).
77
+ */
78
+ static FocusFromTap(clientX, clientY, touch = false) {
79
+ const owner = TextInputProxy.owner, el = TextInputProxy.element;
80
+ if (!owner || !el || !owner.IsFocused)
81
+ return false;
82
+ const canvas = owner.Superview?.Element;
83
+ if (!canvas)
84
+ return false;
85
+ const b = canvas.getBoundingClientRect(), k = owner.RenderingScale || 1, r = owner.GetAccessibilityPixelRect();
86
+ const x = (clientX - b.left) * k, y = (clientY - b.top) * k;
87
+ if (x < r.Left || x > r.Right || y < r.Top || y > r.Bottom)
88
+ return false;
89
+ TextInputProxy.byTouch = touch;
90
+ if (!TextInputProxy.focusedNow && !(touch && TextInputProxy.keyboardUp && document.activeElement === el)) {
91
+ // focus() on the input that has focus already does not open the keyboard: take it off and back on, inside the tap
92
+ if (document.activeElement === el)
93
+ el.blur();
94
+ el.focus({ preventScroll: true });
95
+ }
96
+ if (touch)
97
+ TextInputProxy.keyboardUp = true;
98
+ TextInputProxy.Sync(owner);
99
+ return true;
63
100
  }
64
101
  static Detach(editor) {
65
102
  if (TextInputProxy.owner !== editor)
66
103
  return;
67
104
  TextInputProxy.owner = undefined;
68
105
  const el = TextInputProxy.element;
69
- if (el && document.activeElement === el)
106
+ if (!el || document.activeElement !== el)
107
+ return;
108
+ // a touch press may be moving to another field: the input keeps focus (the keyboard stays up, no hide and show) until
109
+ // the touch ends (AfterTouchEnd); with no field then, it lets go
110
+ if (TextInputProxy.TouchGesture || editor.Superview?.TouchPressed) {
111
+ TextInputProxy.blurAfterTouch = true;
112
+ return;
113
+ }
114
+ el.blur();
115
+ }
116
+ static blurAfterTouch = false;
117
+ /** The input has focus from a touch release (its keyboard is up): a tap on another field needs no blur and focus. */
118
+ static keyboardUp = false;
119
+ /** The canvas calls it at the end of each touch release, after FocusFromTap: a field left during the press lets go now. */
120
+ static AfterTouchEnd() {
121
+ if (!TextInputProxy.blurAfterTouch)
122
+ return;
123
+ TextInputProxy.blurAfterTouch = false;
124
+ const el = TextInputProxy.element;
125
+ if (!TextInputProxy.owner && el && document.activeElement === el)
70
126
  el.blur();
71
127
  }
72
128
  static Configure(editor, el) {
@@ -88,16 +144,38 @@ export class TextInputProxy {
88
144
  el.setSelectionRange(start, end);
89
145
  TextInputProxy.Place(editor, el);
90
146
  }
91
- /** Puts the textarea over the editor so mobile browsers scroll the right spot into view. */
147
+ /**
148
+ * Where the hidden input sits: a field focused by a touch keeps it fixed at the top-left corner, never over the field (as
149
+ * the DrawnUi.Net web heads), so iOS never pans the page to reveal it (a scroll with AdaptToKeyboardAuto moves the
150
+ * field above the keyboard); a field focused by a mouse or the keyboard has it over the field, so a desktop input
151
+ * method opens its candidate window next to the text.
152
+ */
92
153
  static Place(editor, el) {
154
+ let left = 0, top = 0;
93
155
  const canvas = editor.Superview?.Element;
94
- if (!canvas)
156
+ if (!TextInputProxy.byTouch && canvas) {
157
+ const b = canvas.getBoundingClientRect(), scale = editor.RenderingScale || 1, r = editor.GetAccessibilityPixelRect();
158
+ left = Math.round(b.left + r.Left / scale);
159
+ top = Math.round(b.top + r.Top / scale);
160
+ }
161
+ if (left === TextInputProxy.placedLeft && top === TextInputProxy.placedTop)
162
+ return;
163
+ TextInputProxy.placedLeft = left;
164
+ TextInputProxy.placedTop = top;
165
+ el.style.left = `${left}px`;
166
+ el.style.top = `${top}px`;
167
+ }
168
+ static placedLeft = 0;
169
+ static placedTop = 0;
170
+ /**
171
+ * After each frame of the canvas: a focused field that moved (its page scrolled) takes its hidden input along, so a
172
+ * desktop input method keeps its window next to the text. Nothing to do while no field is focused.
173
+ */
174
+ static AfterFrame(canvas) {
175
+ const owner = TextInputProxy.owner, el = TextInputProxy.element;
176
+ if (!owner || !el || TextInputProxy.byTouch || owner.Superview !== canvas)
95
177
  return;
96
- const b = canvas.getBoundingClientRect();
97
- const scale = editor.RenderingScale || 1;
98
- const r = editor.DrawingRect;
99
- el.style.left = `${Math.round(b.left + r.Left / scale)}px`;
100
- el.style.top = `${Math.round(b.top + r.Top / scale)}px`;
178
+ TextInputProxy.Place(owner, el);
101
179
  }
102
180
  /** The textarea changed (typing, IME commit, paste, undo): diff against the editor and replay through the stubs. */
103
181
  static ApplyFromElement() {
@@ -130,6 +208,10 @@ export class TextInputProxy {
130
208
  else if (endPrev > start)
131
209
  editor.StubBackspace();
132
210
  editor.StubPressEnter(false, false);
211
+ // the soft keyboard's return key (done / go / search / send) in a single-line field ends editing and closes the
212
+ // keyboard, as a MAUI single-line field; a physical keyboard's Enter keeps the field focused (the Blazor rule)
213
+ if (TextInputProxy.byTouch && !editor.IsMultiline && ["done", "go", "search", "send"].includes(el.enterKeyHint))
214
+ editor.IsFocused = false;
133
215
  }
134
216
  else if (inserted)
135
217
  editor.StubTypeText(inserted);
@@ -0,0 +1,71 @@
1
+ import type { DrawingContext, SkiaControl } from "./SkiaControl";
2
+ import { SKRect } from "./Types";
3
+ /** What the tooltip controller reads from a style (the TooltipStyle class in the controls implements it). */
4
+ export interface TooltipStyleLike {
5
+ MaxWidth: number;
6
+ ShowDelayMs: number;
7
+ FollowWindowMs: number;
8
+ AtCursor: boolean;
9
+ OffsetX: number;
10
+ OffsetY: number;
11
+ CreateTooltip?: (text: string) => SkiaControl;
12
+ CreateDefault(text: string): SkiaControl;
13
+ }
14
+ /** The canvas side the controller needs. */
15
+ interface TooltipHostCanvas {
16
+ readonly RenderingScale: number;
17
+ Update(): void;
18
+ DisposeObject(o: {
19
+ Dispose(): void;
20
+ }): void;
21
+ readonly TooltipStyleUsed: TooltipStyleLike;
22
+ }
23
+ /**
24
+ * The tooltip of one canvas (drawnui-cross 6ar, C# DrawnView.Tooltip): after the mouse rests on the innermost control
25
+ * with tooltip text, its tooltip shows, attached to it; the next one shows at once while one is shown or just closed.
26
+ * It closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch, and after a
27
+ * press stays closed until the mouse reaches another control. Separate from hover. Drawn last, inside the canvas, with
28
+ * no input and no accessibility node.
29
+ */
30
+ export declare class TooltipController {
31
+ private readonly canvas;
32
+ private owner?;
33
+ private text?;
34
+ private suppressed?;
35
+ private shownText?;
36
+ private anchor;
37
+ private pointer;
38
+ private cursor;
39
+ private closedAt;
40
+ private timer;
41
+ private keysHooked;
42
+ private view?;
43
+ private viewText?;
44
+ private viewRect;
45
+ private viewScale;
46
+ constructor(canvas: TooltipHostCanvas);
47
+ /** The text of the tooltip shown now, undefined when none is shown. */
48
+ get ShownText(): string | undefined;
49
+ /**
50
+ * The mouse moved, nothing pressed: `path` is the hover hit path (root first), (x, y) the pointer in canvas pixels.
51
+ * The innermost control with tooltip text wins.
52
+ */
53
+ OnPointerMove(path: readonly SkiaControl[], x: number, y: number): void;
54
+ private Show;
55
+ private CancelTimer;
56
+ /** Closes the tooltip and cancels a pending one. */
57
+ private Hide;
58
+ /** Any input that is not a plain mouse move (press, wheel, key, window blur): closed until the mouse reaches another control. */
59
+ CloseOnInput(): void;
60
+ /** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
61
+ /** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
62
+ ForgetGone(gone: (c: SkiaControl | undefined) => boolean): void;
63
+ Reset(): void;
64
+ private readonly onKey;
65
+ private readonly onChar;
66
+ private HookKeys;
67
+ /** Draws the tooltip over everything, inside `bounds` (canvas pixels). */
68
+ Draw(ctx: DrawingContext, bounds: SKRect): void;
69
+ Dispose(): void;
70
+ }
71
+ export {};
@@ -0,0 +1,205 @@
1
+ import { SKPoint } from "./Gestures";
2
+ import { SKRect } from "./Types";
3
+ import { KeyboardManager } from "./KeyboardManager";
4
+ /** Where a control is on the canvas now, in pixels: through caches, scroll offsets and transforms (C# OnScreenRect). */
5
+ function OnScreenRect(control) {
6
+ const r = control.GetAccessibilityPixelRect();
7
+ return r.Width > 0 || r.Height > 0 ? r : control.DrawingRect;
8
+ }
9
+ /**
10
+ * The tooltip of one canvas (drawnui-cross 6ar, C# DrawnView.Tooltip): after the mouse rests on the innermost control
11
+ * with tooltip text, its tooltip shows, attached to it; the next one shows at once while one is shown or just closed.
12
+ * It closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch, and after a
13
+ * press stays closed until the mouse reaches another control. Separate from hover. Drawn last, inside the canvas, with
14
+ * no input and no accessibility node.
15
+ */
16
+ export class TooltipController {
17
+ canvas;
18
+ owner;
19
+ text;
20
+ suppressed;
21
+ shownText;
22
+ anchor = SKRect.Empty;
23
+ pointer = SKPoint.Empty;
24
+ cursor = SKPoint.Empty;
25
+ closedAt = 0;
26
+ timer = 0;
27
+ keysHooked = false;
28
+ view;
29
+ viewText;
30
+ viewRect = SKRect.Empty;
31
+ viewScale = 0;
32
+ constructor(canvas) {
33
+ this.canvas = canvas;
34
+ }
35
+ /** The text of the tooltip shown now, undefined when none is shown. */
36
+ get ShownText() { return this.shownText; }
37
+ /**
38
+ * The mouse moved, nothing pressed: `path` is the hover hit path (root first), (x, y) the pointer in canvas pixels.
39
+ * The innermost control with tooltip text wins.
40
+ */
41
+ OnPointerMove(path, x, y) {
42
+ let owner, text;
43
+ for (let i = path.length - 1; i >= 0; i--) {
44
+ const c = path[i];
45
+ if (!c.MayHaveTooltip || c.IsDisposed)
46
+ continue;
47
+ text = c.GetTooltipText();
48
+ if (text) {
49
+ owner = c;
50
+ break;
51
+ }
52
+ }
53
+ // a press closed it: it stays closed until the mouse leaves that control
54
+ if (this.suppressed) {
55
+ if (owner === this.suppressed)
56
+ return;
57
+ this.suppressed = undefined;
58
+ }
59
+ if (!owner || !text) {
60
+ this.owner = undefined;
61
+ this.text = undefined;
62
+ this.Hide();
63
+ return;
64
+ }
65
+ this.pointer = new SKPoint(x, y);
66
+ if (owner === this.owner && text === this.text)
67
+ return; // still on the same control: the tooltip stays where it opened
68
+ this.owner = owner;
69
+ this.text = text;
70
+ this.HookKeys(true);
71
+ const style = this.canvas.TooltipStyleUsed;
72
+ this.CancelTimer();
73
+ if (this.shownText !== undefined || (this.closedAt !== 0 && performance.now() - this.closedAt < style.FollowWindowMs)) {
74
+ // moving from one tooltip to the next: no new wait
75
+ this.Show();
76
+ return;
77
+ }
78
+ this.timer = window.setTimeout(() => { this.timer = 0; if (this.owner)
79
+ this.Show(); }, Math.max(0, style.ShowDelayMs));
80
+ }
81
+ Show() {
82
+ if (!this.owner || !this.text)
83
+ return;
84
+ this.shownText = this.text;
85
+ this.anchor = OnScreenRect(this.owner);
86
+ this.cursor = this.pointer;
87
+ this.canvas.Update();
88
+ }
89
+ CancelTimer() { if (this.timer) {
90
+ clearTimeout(this.timer);
91
+ this.timer = 0;
92
+ } }
93
+ /** Closes the tooltip and cancels a pending one. */
94
+ Hide() {
95
+ this.CancelTimer();
96
+ if (!this.owner)
97
+ this.HookKeys(false);
98
+ if (this.shownText === undefined)
99
+ return;
100
+ this.shownText = undefined;
101
+ this.closedAt = performance.now();
102
+ this.canvas.Update();
103
+ }
104
+ /** Any input that is not a plain mouse move (press, wheel, key, window blur): closed until the mouse reaches another control. */
105
+ CloseOnInput() {
106
+ if (!this.owner && this.shownText === undefined)
107
+ return;
108
+ this.suppressed = this.owner;
109
+ this.owner = undefined;
110
+ this.text = undefined;
111
+ this.Hide();
112
+ this.HookKeys(false);
113
+ }
114
+ /** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
115
+ /** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
116
+ ForgetGone(gone) {
117
+ if (gone(this.suppressed))
118
+ this.suppressed = undefined;
119
+ if (gone(this.owner)) {
120
+ this.owner = undefined;
121
+ this.text = undefined;
122
+ this.Hide();
123
+ }
124
+ }
125
+ Reset() {
126
+ this.owner = undefined;
127
+ this.text = undefined;
128
+ this.suppressed = undefined;
129
+ this.Hide();
130
+ this.HookKeys(false);
131
+ }
132
+ onKey = () => this.CloseOnInput();
133
+ onChar = () => { };
134
+ HookKeys(on) {
135
+ if (on === this.keysHooked)
136
+ return;
137
+ this.keysHooked = on;
138
+ if (on)
139
+ KeyboardManager.Subscribe(this.onKey, this.onChar);
140
+ else
141
+ KeyboardManager.Unsubscribe(this.onKey, this.onChar);
142
+ }
143
+ /** Draws the tooltip over everything, inside `bounds` (canvas pixels). */
144
+ Draw(ctx, bounds) {
145
+ const text = this.shownText;
146
+ if (text === undefined) {
147
+ if (this.view) {
148
+ this.canvas.DisposeObject(this.view);
149
+ this.view = undefined;
150
+ this.viewText = undefined;
151
+ }
152
+ return;
153
+ }
154
+ const scale = ctx.Scale;
155
+ if (!this.view || this.viewText !== text || this.viewScale !== scale) {
156
+ if (this.view)
157
+ this.canvas.DisposeObject(this.view);
158
+ const style = this.canvas.TooltipStyleUsed;
159
+ const view = style.CreateTooltip?.(text) ?? style.CreateDefault(text);
160
+ view._superview = this.canvas;
161
+ view.Parent = undefined;
162
+ view.InputTransparent = true;
163
+ this.view = view;
164
+ this.viewText = text;
165
+ this.viewScale = scale;
166
+ // a finite width lets long text wrap: MaxWidth, never wider than the canvas
167
+ const margin = view.Margin;
168
+ const maxWidth = Math.min(bounds.Width, (style.MaxWidth + margin.HorizontalThickness) * scale);
169
+ const measured = view.Measure(maxWidth, Infinity, scale).Pixels;
170
+ const width = measured.Width, height = measured.Height;
171
+ // attached to its control (centered above it, below where there is no room) or at the cursor (below right of the
172
+ // pointer, above where there is no room); the offsets shift it, the vertical one mirrored on the flipped side
173
+ const boxWidth = width - margin.HorizontalThickness * scale, boxHeight = height - margin.VerticalThickness * scale;
174
+ const gap = 6 * scale, offsetX = style.OffsetX * scale, offsetY = style.OffsetY * scale;
175
+ const anchor = this.anchor, cursor = this.cursor;
176
+ let boxLeft, boxTop, flippedTop;
177
+ if (style.AtCursor) {
178
+ boxLeft = cursor.X + 4 * scale + offsetX;
179
+ boxTop = cursor.Y + 20 * scale + offsetY; // clear of the pointer's arrow
180
+ flippedTop = cursor.Y - gap - boxHeight - offsetY;
181
+ }
182
+ else {
183
+ boxLeft = (anchor.Left + anchor.Right) / 2 - boxWidth / 2 + offsetX;
184
+ boxTop = anchor.Top - gap - boxHeight + offsetY;
185
+ flippedTop = anchor.Bottom + gap - offsetY;
186
+ }
187
+ if (style.AtCursor ? boxTop + boxHeight > bounds.Bottom : boxTop < bounds.Top)
188
+ boxTop = flippedTop;
189
+ boxLeft = Math.max(bounds.Left, Math.min(boxLeft, bounds.Right - boxWidth));
190
+ boxTop = Math.max(bounds.Top, Math.min(boxTop, bounds.Bottom - boxHeight));
191
+ const left = boxLeft - margin.Left * scale, top = boxTop - margin.Top * scale;
192
+ this.viewRect = new SKRect(left, top, left + width, top + height);
193
+ view.Arrange(this.viewRect, view.WidthRequest, view.HeightRequest, scale);
194
+ }
195
+ this.view.Render({ Context: ctx.Context, Destination: this.viewRect, Scale: scale });
196
+ }
197
+ Dispose() {
198
+ this.CancelTimer();
199
+ this.HookKeys(false);
200
+ if (this.view) {
201
+ this.view.Dispose();
202
+ this.view = undefined;
203
+ }
204
+ }
205
+ }
@@ -1,6 +1,8 @@
1
1
  /** MAUI LayoutOptions subset used by DrawnUi. */
2
2
  export type LayoutOptions = "Start" | "Center" | "End" | "Fill";
3
3
  /** MAUI Thickness with the same ctor overloads: (all) / (horizontal, vertical) / (l, t, r, b). */
4
+ /** What a Thickness-typed property accepts: a Thickness, a number (every side) or the C# string form "12" / "12,6" / "l,t,r,b". */
5
+ export type ThicknessValue = Thickness | number | string;
4
6
  export declare class Thickness {
5
7
  Left: number;
6
8
  Top: number;
@@ -8,6 +10,14 @@ export declare class Thickness {
8
10
  Bottom: number;
9
11
  constructor(a?: number, b?: number, c?: number, d?: number);
10
12
  static readonly Zero: Thickness;
13
+ private static warned?;
14
+ /**
15
+ * What a Thickness-typed property (Margin, Padding) is given, as a Thickness: a number is the same on every side
16
+ * (C# XAML `Padding="12"`), the C# string forms "12", "12,6" (horizontal, vertical) and "1,2,3,4" (left, top, right,
17
+ * bottom) are read the same way. Anything else is Zero with a one-time console warning: never NaN, which would
18
+ * blank the control.
19
+ */
20
+ static From(value: unknown): Thickness;
11
21
  get HorizontalThickness(): number;
12
22
  get VerticalThickness(): number;
13
23
  }
@@ -75,7 +85,7 @@ export type TextTransform = "None" | "Lowercase" | "Uppercase" | "Titlecase";
75
85
  /** DrawnUi DrawerDirection: the edge a SkiaDrawer slides from. */
76
86
  export type DrawerDirection = "FromBottom" | "FromTop" | "FromLeft" | "FromRight";
77
87
  /** DrawnUi LayoutType. */
78
- export type LayoutType = "Absolute" | "Column" | "Row" | "Wrap" | "Grid";
88
+ export type LayoutType = "Absolute" | "Column" | "Row" | "Wrap" | "Grid" | "Masonry";
79
89
  /** MAUI ReturnType: what the keyboard's return key means (SkiaEditor: Send submits a multiline editor). */
80
90
  export type ReturnType = "Default" | "Done" | "Go" | "Next" | "Search" | "Send";
81
91
  /** DrawnUi SkiaEditor.SkiaEditorKeyboard. */
@@ -1,5 +1,4 @@
1
1
  // Mirrors DrawnUi (.NET) value types with the same names. Units: points unless a name says Pixels.
2
- /** MAUI Thickness with the same ctor overloads: (all) / (horizontal, vertical) / (l, t, r, b). */
3
2
  export class Thickness {
4
3
  Left;
5
4
  Top;
@@ -21,6 +20,38 @@ export class Thickness {
21
20
  }
22
21
  }
23
22
  static Zero = new Thickness();
23
+ static warned;
24
+ /**
25
+ * What a Thickness-typed property (Margin, Padding) is given, as a Thickness: a number is the same on every side
26
+ * (C# XAML `Padding="12"`), the C# string forms "12", "12,6" (horizontal, vertical) and "1,2,3,4" (left, top, right,
27
+ * bottom) are read the same way. Anything else is Zero with a one-time console warning: never NaN, which would
28
+ * blank the control.
29
+ */
30
+ static From(value) {
31
+ if (value instanceof Thickness)
32
+ return value;
33
+ if (typeof value === "number" && Number.isFinite(value))
34
+ return new Thickness(value);
35
+ if (typeof value === "string") {
36
+ const n = value.split(",").map((s) => Number(s.trim()));
37
+ if (n.every((x) => Number.isFinite(x))) {
38
+ if (n.length === 1)
39
+ return new Thickness(n[0]);
40
+ if (n.length === 2)
41
+ return new Thickness(n[0], n[1]);
42
+ if (n.length === 4)
43
+ return new Thickness(n[0], n[1], n[2], n[3]);
44
+ }
45
+ }
46
+ if (value == null)
47
+ return Thickness.Zero;
48
+ const key = String(value);
49
+ if (!(Thickness.warned ??= new Set()).has(key)) {
50
+ Thickness.warned.add(key);
51
+ console.warn(`[DrawnUi] ${key} is not a thickness (a Thickness, a number, or "h,v" / "l,t,r,b"): 0 is used.`);
52
+ }
53
+ return Thickness.Zero;
54
+ }
24
55
  get HorizontalThickness() { return this.Left + this.Right; }
25
56
  get VerticalThickness() { return this.Top + this.Bottom; }
26
57
  }
@@ -16,6 +16,8 @@ export declare class ViewsAdapter {
16
16
  Created: number;
17
17
  constructor(parent: SkiaControl);
18
18
  get PoolSize(): number;
19
+ /** The items views are bound to. */
20
+ get Items(): readonly unknown[];
19
21
  get InUseCount(): number;
20
22
  /** New template / items / mode: every realized view is dropped (DrawnUi ApplyItemsSource). */
21
23
  Initialize(template: (() => SkiaControl) | undefined, items: readonly unknown[], recycling: RecyclingTemplate): void;
@@ -26,8 +28,11 @@ export declare class ViewsAdapter {
26
28
  ShiftIndices(by: number, items: readonly unknown[]): void;
27
29
  /** The realized view for an index, if any (no creation). */
28
30
  GetViewForIndex(index: number): SkiaControl | undefined;
29
- /** View bound to items[index]: existing, recycled from the pool, or freshly created. */
30
- GetOrCreateViewForIndex(index: number): SkiaControl | undefined;
31
+ /**
32
+ * View bound to items[index]: existing, recycled from the pool, or freshly created. `quiet`: bound before it is
33
+ * attached, so the rebind invalidates the view alone and not the layout, which measures or draws it right away.
34
+ */
35
+ GetOrCreateViewForIndex(index: number, quiet?: boolean): SkiaControl | undefined;
31
36
  /** Index left the visible range: recycled views go back to the pool, non-recycled ones stay realized. */
32
37
  ReleaseViewAt(index: number): void;
33
38
  /** Releases every realized index outside [first, last]. */
@@ -16,6 +16,8 @@ export class ViewsAdapter {
16
16
  this.parent = parent;
17
17
  }
18
18
  get PoolSize() { return this.pool.length; }
19
+ /** The items views are bound to. */
20
+ get Items() { return this.items; }
19
21
  get InUseCount() { return this.inUse.size; }
20
22
  /** New template / items / mode: every realized view is dropped (DrawnUi ApplyItemsSource). */
21
23
  Initialize(template, items, recycling) {
@@ -52,8 +54,11 @@ export class ViewsAdapter {
52
54
  }
53
55
  /** The realized view for an index, if any (no creation). */
54
56
  GetViewForIndex(index) { return this.inUse.get(index); }
55
- /** View bound to items[index]: existing, recycled from the pool, or freshly created. */
56
- GetOrCreateViewForIndex(index) {
57
+ /**
58
+ * View bound to items[index]: existing, recycled from the pool, or freshly created. `quiet`: bound before it is
59
+ * attached, so the rebind invalidates the view alone and not the layout, which measures or draws it right away.
60
+ */
61
+ GetOrCreateViewForIndex(index, quiet = false) {
57
62
  const existing = this.inUse.get(index);
58
63
  if (existing)
59
64
  return existing;
@@ -64,9 +69,11 @@ export class ViewsAdapter {
64
69
  view = this.template();
65
70
  this.Created++;
66
71
  }
67
- view.Parent = this.parent;
72
+ if (!quiet)
73
+ view.Parent = this.parent;
68
74
  view.ContextIndex = index;
69
75
  view.BindingContext = this.items[index];
76
+ view.Parent = this.parent;
70
77
  this.inUse.set(index, view);
71
78
  return view;
72
79
  }
package/dist/index.d.ts CHANGED
@@ -9,9 +9,14 @@ export * from "./core/SkiaControl";
9
9
  export * from "./core/Canvas";
10
10
  export * from "./controls/SkiaLayout";
11
11
  export * from "./core/Accessibility";
12
+ export * from "./core/Hover";
13
+ export * from "./core/Tooltips";
14
+ export * from "./core/PopupWindows";
12
15
  export * from "./controls/SkiaLabel";
13
16
  export * from "./controls/TextSpan";
14
17
  export * from "./controls/SkiaRichLabel";
18
+ export * from "./controls/SkiaLabelFps";
19
+ export * from "./controls/TooltipStyle";
15
20
  export * from "./core/ControlStyle";
16
21
  export * from "./core/ImageEffects";
17
22
  export * from "./controls/SkiaToggle";
@@ -30,6 +35,7 @@ export * from "./controls/RefreshIndicator";
30
35
  export * from "./core/TextInputProxy";
31
36
  export * from "./core/SkiaEffect";
32
37
  export * from "./controls/SkiaDrawer";
38
+ export * from "./controls/SkiaShell";
33
39
  export * from "./controls/SkiaHotspot";
34
40
  export * from "./controls/SkiaShape";
35
41
  export * from "./controls/SkiaButton";
@@ -40,6 +46,7 @@ export * from "./controls/SkiaBackdrop";
40
46
  export * from "./controls/SkiaEditor";
41
47
  export * from "./controls/SkiaSprite";
42
48
  export * from "./controls/SkiaSpriteSet";
49
+ export * from "./controls/DrawnGame";
43
50
  export * from "./core/KeyboardManager";
44
51
  export * from "./controls/AnimatedFramesRenderer";
45
52
  export * from "./controls/SkiaLottie";
@@ -47,3 +54,4 @@ export * from "./controls/SkiaGif";
47
54
  export * from "./controls/SkiaScroll";
48
55
  export * from "./controls/SkiaDynamicDrawnCell";
49
56
  export * from "./core/ViewsAdapter";
57
+ export * from "./core/DesignerActions";