drawnui-react 0.1.0-preview.35 → 0.1.0-preview.37

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 (42) hide show
  1. package/SKIPPED.md +3 -0
  2. package/dist/controls/SkiaButton.js +2 -2
  3. package/dist/controls/SkiaCarousel.js +31 -3
  4. package/dist/controls/SkiaCheckbox.js +2 -1
  5. package/dist/controls/SkiaEditor.d.ts +4 -0
  6. package/dist/controls/SkiaEditor.js +16 -4
  7. package/dist/controls/SkiaLabel.d.ts +2 -0
  8. package/dist/controls/SkiaLabel.js +2 -0
  9. package/dist/controls/SkiaLayout.d.ts +2 -0
  10. package/dist/controls/SkiaLayout.js +2 -0
  11. package/dist/controls/SkiaProgress.js +2 -2
  12. package/dist/controls/SkiaRadioButton.js +2 -1
  13. package/dist/controls/SkiaShaderCarousel.js +5 -0
  14. package/dist/controls/SkiaSlider.js +2 -2
  15. package/dist/controls/SkiaSwitch.js +4 -2
  16. package/dist/controls/TooltipStyle.d.ts +52 -0
  17. package/dist/controls/TooltipStyle.js +88 -0
  18. package/dist/core/Accessibility.d.ts +30 -0
  19. package/dist/core/Accessibility.js +162 -3
  20. package/dist/core/Canvas.d.ts +76 -3
  21. package/dist/core/Canvas.js +239 -8
  22. package/dist/core/ControlStyle.d.ts +2 -0
  23. package/dist/core/ControlStyle.js +2 -0
  24. package/dist/core/Hover.d.ts +4 -0
  25. package/dist/core/Hover.js +6 -0
  26. package/dist/core/KeyboardManager.d.ts +7 -0
  27. package/dist/core/KeyboardManager.js +35 -4
  28. package/dist/core/PopupWindows.d.ts +92 -0
  29. package/dist/core/PopupWindows.js +203 -0
  30. package/dist/core/SkiaControl.d.ts +30 -0
  31. package/dist/core/SkiaControl.js +60 -3
  32. package/dist/core/Super.d.ts +7 -0
  33. package/dist/core/Super.js +7 -0
  34. package/dist/core/Tooltips.d.ts +71 -0
  35. package/dist/core/Tooltips.js +205 -0
  36. package/dist/index.d.ts +3 -0
  37. package/dist/index.js +3 -0
  38. package/dist/react/index.d.ts +16 -1
  39. package/dist/react/index.js +51 -11
  40. package/dist/react/reconciler.d.ts +2 -0
  41. package/dist/react/reconciler.js +5 -0
  42. package/package.json +3 -1
@@ -1,6 +1,9 @@
1
1
  import { Super } from "./Super";
2
2
  import { SkiaAccessibilityManager } from "./Accessibility";
3
3
  import { HoverManager } from "./Hover";
4
+ import { TooltipController } from "./Tooltips";
5
+ import { PopupAnchor, PopupLayer } from "./PopupWindows";
6
+ import { KeyboardManager } from "./KeyboardManager";
4
7
  import { Colors, SKRect } from "./Types";
5
8
  import { ContextMenuEventArgs, GestureEventProcessingInfo, PointerData, SKPoint, SkiaGesturesParameters, TouchActionEventArgs, } from "./Gestures";
6
9
  /**
@@ -43,6 +46,69 @@ export class Canvas {
43
46
  AccessibilityManager = new SkiaAccessibilityManager();
44
47
  /** Mouse hover of the controls (drawnui-cross 6m): ReceivesHover / IsHovered / HoverChanged. */
45
48
  Hover = new HoverManager();
49
+ // ---- tooltips (drawnui-cross 6ar) ----
50
+ tooltipController;
51
+ /** Made on first use: a canvas that never shows a tooltip allocates nothing for it. */
52
+ get tooltip() { return this.tooltipController ??= new TooltipController(this); }
53
+ /** Look and timing of the tooltips on this canvas; unset uses `Super.TooltipStyle`. */
54
+ TooltipStyle;
55
+ get TooltipStyleUsed() { return this.TooltipStyle ?? Super.TooltipStyle; }
56
+ /** The text of the tooltip shown now, undefined when none is shown. */
57
+ get ShownTooltip() { return this.tooltip.ShownText; }
58
+ // ---- popup windows (drawnui-cross 6at, the DrawnUi.Rust / .NET API) ----
59
+ popupLayer;
60
+ /** Made on first use, like the tooltip. */
61
+ get popups() { return this.popupLayer ??= new PopupLayer(this); }
62
+ popupKeysHooked = false;
63
+ /** Raised when a popup window closed: picked, a press outside, Escape, the wheel, window blur or ClosePopupWindow. */
64
+ PopupWindowClosed = new Set();
65
+ /**
66
+ * Shows `content` over everything, opening from `anchor` the way native menus do: at a point (a right click, canvas
67
+ * points), or below a rect or a control (a dropdown), flipped to the other side where it does not fit. It closes with
68
+ * a press outside it, Escape, the wheel outside it, window blur, `ClosePopupWindow` and the options.
69
+ */
70
+ OpenPopupWindow(content, anchor, options = {}) {
71
+ const id = this.popups.Open(content, PopupAnchor.From(anchor), options, this);
72
+ this.HookPopupKeys(true);
73
+ if (!options.Passive)
74
+ this.tooltip.Reset(); // a menu opening closes the tooltip
75
+ this.Hover.RequestCheck();
76
+ this.Update();
77
+ return id;
78
+ }
79
+ /** Closes the popup window (nothing when it is closed already). */
80
+ ClosePopupWindow(id) { this.popups.Close(id); this.AfterPopupsChanged(); }
81
+ /** Closes every popup window. */
82
+ ClosePopupWindows() { this.popups.CloseAll(true); this.AfterPopupsChanged(); }
83
+ /** The popup window is still open. */
84
+ IsPopupWindowOpen(id) { return this.popups.IsOpen(id); }
85
+ /** True while a popup window that takes input is open. */
86
+ get HasPopupWindows() { return this.popups.HasInteractive; }
87
+ /** The content of the top popup window that takes input. */
88
+ get TopPopupWindow() { return this.popups.TopInteractive; }
89
+ /** The window stopped being active (blur): popup windows and the tooltip close, as native menus do. */
90
+ OnWindowDeactivated() { this.ClosePopupWindows(); this.tooltip.CloseOnInput(); }
91
+ RaisePopupWindowClosed(id) { for (const h of [...this.PopupWindowClosed])
92
+ h(id); }
93
+ AfterPopupsChanged() {
94
+ if (!this.popups.HasAny)
95
+ this.HookPopupKeys(false);
96
+ this.Hover.RequestCheck();
97
+ this.Update();
98
+ }
99
+ onPopupKey = (key) => { if (key === "Escape" && this.popups.CloseTop())
100
+ this.AfterPopupsChanged(); };
101
+ onPopupChar = () => { };
102
+ HookPopupKeys(on) {
103
+ if (on === this.popupKeysHooked)
104
+ return;
105
+ this.popupKeysHooked = on;
106
+ if (on)
107
+ KeyboardManager.Subscribe(this.onPopupKey, this.onPopupChar);
108
+ else
109
+ KeyboardManager.Unsubscribe(this.onPopupKey, this.onPopupChar);
110
+ }
111
+ onWindowBlur = () => this.OnWindowDeactivated();
46
112
  content;
47
113
  get Content() { return this.content; }
48
114
  set Content(value) {
@@ -78,6 +144,7 @@ export class Canvas {
78
144
  init?.(this);
79
145
  Element.addEventListener("webglcontextlost", this.onContextLost);
80
146
  Element.addEventListener("webglcontextrestored", this.onContextRestored);
147
+ this.Hover.RootAt = (x, y) => this.popupLayer?.At(x, y) ?? this.content;
81
148
  this.observer = new ResizeObserver(() => this.OnResized());
82
149
  this.observer.observe(Element);
83
150
  this.OnResized();
@@ -102,7 +169,8 @@ export class Canvas {
102
169
  cancelAnimationFrame(this.frameId);
103
170
  this.frameId = 0;
104
171
  }
105
- this.surface?.delete();
172
+ // dispose, not delete: a software surface owns pixels CanvasKit allocated for it, which delete() leaves behind
173
+ this.surface?.dispose();
106
174
  this.surface = undefined;
107
175
  }
108
176
  /** On-screen surface at the element's current pixel size, reusing the GL/GrContext when accelerated. */
@@ -165,7 +233,7 @@ export class Canvas {
165
233
  return;
166
234
  if (this.grContext)
167
235
  this.grContext.releaseResourcesAndAbandonContext();
168
- this.surface?.delete();
236
+ this.surface?.dispose();
169
237
  this.surface = undefined;
170
238
  this.grContext?.delete();
171
239
  this.grContext = undefined;
@@ -209,8 +277,15 @@ export class Canvas {
209
277
  root.Arrange(new SKRect(0, 0, w, h), root.WidthRequest, root.HeightRequest, scale);
210
278
  root.Render({ Context: { Canvas: canvas, Surface: this.surface }, Destination: new SKRect(0, 0, w, h), Scale: scale });
211
279
  }
280
+ // popup windows, then the tooltip, over everything
281
+ const top = { Context: { Canvas: canvas, Surface: this.surface }, Destination: new SKRect(0, 0, this.Element.width, this.Element.height), Scale: this.RenderingScale };
282
+ if (this.popupLayer?.HasAny)
283
+ this.popupLayer.Draw(top, top.Destination);
284
+ this.tooltipController?.Draw(top, top.Destination);
212
285
  this.AccessibilityManager.OnFrameEnd(this.RenderingScale, this.Element.width, this.Element.height, () => this.Update());
213
286
  this.Hover.AfterFrame(this.content, this.activeTouchIds.size > 0);
287
+ if (this.Hover.Paused)
288
+ this.tooltipController?.Reset(); // content moves under the pointer
214
289
  const now = performance.now();
215
290
  this.FrameTime = now - started;
216
291
  this.FrameIndex++;
@@ -218,6 +293,7 @@ export class Canvas {
218
293
  while (this.frameTimes.length && this.frameTimes[0] < now - 1000)
219
294
  this.frameTimes.shift();
220
295
  this.FPS = this.frameTimes.length;
296
+ this.ForgetGoneControls();
221
297
  if (executed > 0)
222
298
  this.Update(); // animators running: keep frames coming
223
299
  // C# order: WasDrawn at the end of the frame, then the frame counts as rendered
@@ -345,7 +421,7 @@ export class Canvas {
345
421
  }
346
422
  }
347
423
  finally {
348
- surface.delete();
424
+ surface.dispose(); // its pixels too (CK.MakeSurface allocates them)
349
425
  }
350
426
  }
351
427
  Dispose() {
@@ -357,6 +433,10 @@ export class Canvas {
357
433
  this.Element.removeEventListener("webglcontextlost", this.onContextLost);
358
434
  this.Element.removeEventListener("webglcontextrestored", this.onContextRestored);
359
435
  this.Gestures = "Disabled";
436
+ this.ArrowsStartKeyboardNavigation = false;
437
+ this.tooltipController?.Dispose();
438
+ this.popupLayer?.Dispose();
439
+ this.HookPopupKeys(false);
360
440
  this.observer.disconnect();
361
441
  this.content?.Dispose();
362
442
  this.Content = undefined;
@@ -394,8 +474,13 @@ export class Canvas {
394
474
  if (type === "Moved" && !this.activeTouchIds.has(e.pointerId)) {
395
475
  if (e.pointerType === "touch")
396
476
  return; // touch never hovers
397
- if (this.activeTouchIds.size === 0)
398
- this.Hover.Move(this.content, e.offsetX * this.RenderingScale, e.offsetY * this.RenderingScale);
477
+ const hx = e.offsetX * this.RenderingScale, hy = e.offsetY * this.RenderingScale;
478
+ if (this.activeTouchIds.size === 0) {
479
+ this.Hover.Move(this.content, hx, hy);
480
+ this.tooltip.OnPointerMove(this.Hover.Path, hx, hy);
481
+ }
482
+ if (this.popups.HasAny)
483
+ this.popups.PointerAt(hx, hy);
399
484
  if (e.pointerType === "mouse")
400
485
  this.UpdateCursor();
401
486
  return;
@@ -403,6 +488,8 @@ export class Canvas {
403
488
  if ((type === "Released" || type === "Cancelled") && !this.activeTouchIds.has(e.pointerId))
404
489
  return; // Up of a pointer that never pressed here
405
490
  // Capture so Up outside the element still arrives; throws for synthetic events (tests) — harmless.
491
+ if (type === "Pressed")
492
+ this.tooltip.CloseOnInput();
406
493
  if (type === "Pressed") {
407
494
  try {
408
495
  this.Element.setPointerCapture(e.pointerId);
@@ -430,8 +517,14 @@ export class Canvas {
430
517
  }
431
518
  };
432
519
  /** The mouse left the canvas: hover ends at once, also while content moves. */
433
- onPointerLeave = (e) => { if (e.pointerType !== "touch")
434
- this.Hover.Leave(); };
520
+ onPointerLeave = (e) => {
521
+ if (e.pointerType === "touch")
522
+ return;
523
+ this.Hover.Leave();
524
+ this.tooltip.Reset();
525
+ if (this.popups.HasAny)
526
+ this.popups.PointerAt(undefined, undefined);
527
+ };
435
528
  preventTouch = (e) => e.preventDefault();
436
529
  /** Gestures="Enabled": touch / pen pointers whose Down a control used (see OnTouchAction). */
437
530
  claimedTouches = new Set();
@@ -448,6 +541,19 @@ export class Canvas {
448
541
  const pointerType = e.pointerType;
449
542
  const source = pointerType === "touch" || pointerType === "pen" ? "touch" : pointerType === "mouse" || e.button === 2 ? "mouse" : "keyboard";
450
543
  const args = new ContextMenuEventArgs(new SKPoint(x, y), new SKPoint(x * scale, y * scale), source, e);
544
+ this.tooltip.CloseOnInput();
545
+ // over a popup window its content is asked; elsewhere the popups close and the request goes on, so a new menu can
546
+ // open there (C# PopupLayer ContextMenu)
547
+ const popupRoot = this.popups.HasInteractive ? this.popups.At(args.Pixels.X, args.Pixels.Y) : undefined;
548
+ if (popupRoot) {
549
+ popupRoot.ProcessContextMenu(args.Pixels, args);
550
+ e.preventDefault();
551
+ return;
552
+ }
553
+ if (this.popups.HasInteractive) {
554
+ this.popups.CloseAll(false);
555
+ this.AfterPopupsChanged();
556
+ }
451
557
  let handled = this.content?.ProcessContextMenu(args.Pixels, args) ?? false;
452
558
  if (!handled && this.ContextMenu)
453
559
  handled = this.ContextMenu(this, args) === true;
@@ -496,6 +602,7 @@ export class Canvas {
496
602
  const factor = e.deltaMode === 1 ? 40 : e.deltaMode === 2 ? 800 : 1;
497
603
  const horizontal = Math.abs(e.deltaX) > Math.abs(e.deltaY);
498
604
  args.Wheel = { Delta: (horizontal ? e.deltaX : e.deltaY) * factor, IsHorizontal: horizontal };
605
+ this.tooltip.CloseOnInput();
499
606
  if (this.gestures === "Lock") {
500
607
  e.preventDefault();
501
608
  this.OnGestureEvent(args, "Wheel");
@@ -573,6 +680,7 @@ export class Canvas {
573
680
  el.addEventListener("pointerleave", this.onPointerLeave);
574
681
  el.addEventListener("contextmenu", this.onContextMenu);
575
682
  el.addEventListener("wheel", this.onWheel, { passive: false });
683
+ window.addEventListener("blur", this.onWindowBlur);
576
684
  if (this.gestures === "Lock") {
577
685
  el.addEventListener("touchmove", this.preventTouch, { passive: false });
578
686
  // the canvas owns every touch (DrawnUi.Web applyGestureStyle, DrawnUi.Rust host): no iOS callout or text
@@ -601,6 +709,7 @@ export class Canvas {
601
709
  el.removeEventListener("pointerleave", this.onPointerLeave);
602
710
  el.removeEventListener("contextmenu", this.onContextMenu);
603
711
  el.removeEventListener("wheel", this.onWheel);
712
+ window.removeEventListener("blur", this.onWindowBlur);
604
713
  el.removeEventListener("touchmove", this.preventTouch);
605
714
  el.removeEventListener("touchmove", this.preventClaimedTouch);
606
715
  if (this.pageOverscroll) {
@@ -721,9 +830,114 @@ export class Canvas {
721
830
  static IsSavedGesture(type) {
722
831
  return type === "Panning" || type === "Wheel" || type === "Up";
723
832
  }
724
- /** Entry into the control tree, same shape as DrawnUi Canvas.ProcessGestures. */
833
+ // ---- arrows start keyboard navigation (C# 6aee5c51) ----
834
+ arrowsStart = false;
835
+ /**
836
+ * While no drawn control has keyboard focus (or only one behind the active modal), the arrow keys start keyboard
837
+ * navigation as the first Tab does: Down and Right go to the first Tab stop, Up and Left to the last, and the key is used
838
+ * for that. Once a control has focus the arrows work as usual (inside a list or a menu). Off by default, since games use
839
+ * the arrows as their own keys while nothing is focused: an app turns it on for its menu screens and off while playing.
840
+ */
841
+ get ArrowsStartKeyboardNavigation() { return this.arrowsStart; }
842
+ set ArrowsStartKeyboardNavigation(v) {
843
+ if (this.arrowsStart === v)
844
+ return;
845
+ this.arrowsStart = v;
846
+ if (v)
847
+ KeyboardManager.Subscribe(this.onArrowKey, this.onArrowChar);
848
+ else
849
+ KeyboardManager.Unsubscribe(this.onArrowKey, this.onArrowChar);
850
+ }
851
+ onArrowChar = () => { };
852
+ onArrowKey = (key, e) => {
853
+ const forward = key === "ArrowDown" || key === "ArrowRight" ? true : key === "ArrowUp" || key === "ArrowLeft" ? false : undefined;
854
+ // a page element, a drawn control's element or the editor's input has the keys: nothing to start
855
+ if (forward === undefined || this.disposed || KeyboardManager.IsOwnedByElement(e) || e.defaultPrevented)
856
+ return;
857
+ const mgr = this.AccessibilityManager, focused = mgr.FocusedNode;
858
+ if (focused && !mgr.IsOutsideModal(focused))
859
+ return;
860
+ const first = mgr.NextTabStop(undefined, forward);
861
+ if (!first)
862
+ return;
863
+ e.preventDefault();
864
+ mgr.RequestKeyboardFocus(first);
865
+ this.Update();
866
+ };
867
+ // ---- focus (C# DrawnView FocusedChild / ReportFocus, drawnui-cross 6ap) ----
868
+ focusedChild;
869
+ focusAtDown;
870
+ tapNoFocus = false;
871
+ reportingFocus = false;
872
+ /**
873
+ * A control that left the canvas (removed or disposed) is let go by the focus, the gesture dispatch and the tooltips,
874
+ * so the last control that took input does not keep its page alive (C# 4cb28ab6). Checked once per frame.
875
+ */
876
+ ForgetGoneControls() {
877
+ const gone = (c) => !!c && (c.IsDisposed || c.Superview !== this);
878
+ if (gone(this.focusedChild))
879
+ this.focusedChild = undefined;
880
+ if (gone(this.focusAtDown))
881
+ this.focusAtDown = undefined;
882
+ if (gone(this.gestureOwner))
883
+ this.gestureOwner = null;
884
+ this.tooltipController?.ForgetGone(gone);
885
+ }
886
+ /** The control that has the canvas focus (an editor while it edits, a CanBeFocused control that was tapped). */
887
+ get FocusedChild() { return this.focusedChild; }
888
+ /**
889
+ * Moves the focus. The new control is asked first and the focus moves only when it takes it (a tap on a button leaves an
890
+ * editor focused); undefined clears it. Nothing moves while the focused control has LockFocus. `setter` is a control
891
+ * that focused itself already (an editor on its press) or the focused control letting go itself (Escape, submit).
892
+ */
893
+ ReportFocus(value, setter) {
894
+ if (value === this.focusedChild || this.reportingFocus)
895
+ return;
896
+ if (this.focusedChild?.LockFocus && setter !== this.focusedChild)
897
+ return;
898
+ this.reportingFocus = true;
899
+ try {
900
+ if (value && value !== setter && !value.SetFrameworkFocus(true))
901
+ return;
902
+ const previous = this.focusedChild;
903
+ this.focusedChild = value;
904
+ if (previous && !previous.IsDisposed)
905
+ previous.SetFrameworkFocus(false);
906
+ }
907
+ finally {
908
+ this.reportingFocus = false;
909
+ }
910
+ }
911
+ /** Entry into the control tree; on a completed tap the focus follows it (C# Canvas: focus only on Tapped). */
725
912
  ProcessGestures(root, args) {
913
+ if (args.Type === "Down") {
914
+ this.focusAtDown = this.focusedChild;
915
+ this.tapNoFocus = false;
916
+ }
917
+ const consumed = this.RouteGestures(root, args);
918
+ // a control that claimed the focus during this gesture (an editor on its press) keeps it; a press that closed the
919
+ // popup windows moves nothing
920
+ if (args.Type === "Tapped" && !this.tapNoFocus && this.focusedChild === this.focusAtDown)
921
+ this.ReportFocus(consumed ?? undefined);
922
+ return consumed;
923
+ }
924
+ /** Same shape as DrawnUi Canvas.ProcessGestures. */
925
+ RouteGestures(root, args) {
726
926
  const info = () => new GestureEventProcessingInfo(args.Event.Location, SKPoint.Empty, SKPoint.Empty, null);
927
+ const popups = this.popups, at = args.Event.Location;
928
+ // the rest of a press that closed the popup windows goes nowhere (native menus)
929
+ if (args.Type === "Down")
930
+ popups.SwallowPress = false;
931
+ if (popups.SwallowPress) {
932
+ if (args.Type === "Up")
933
+ popups.SwallowPress = false;
934
+ return null;
935
+ }
936
+ // the wheel outside the popup windows closes them (what they opened from is about to move), before any owner takes it
937
+ if (args.Type === "Wheel" && popups.HasInteractive && !popups.At(at.X, at.Y)) {
938
+ popups.CloseAll(false);
939
+ this.AfterPopupsChanged();
940
+ }
727
941
  // the wheel goes to the press owner only while a press is held; between presses it goes by position, and it
728
942
  // never makes an owner: a wheel over a second scroll moves that one, not the last one the wheel moved
729
943
  // (DrawnUi.Rust input_router "the wheel goes to the owner of the press first"; C# keeps the last wheel consumer)
@@ -745,6 +959,23 @@ export class Canvas {
745
959
  if (!wheel)
746
960
  this.gestureOwner = null;
747
961
  }
962
+ // over a popup window its controls take the gesture and nothing below sees it; a press elsewhere closes them
963
+ if (popups.HasInteractive) {
964
+ const popupRoot = popups.At(at.X, at.Y);
965
+ if (popupRoot) {
966
+ const used = popupRoot.ProcessGestures(args, info()) ?? popupRoot;
967
+ if (!wheel)
968
+ this.gestureOwner = args.Type !== "Up" ? used : null;
969
+ return used;
970
+ }
971
+ if (args.Type === "Down") {
972
+ this.tapNoFocus = true;
973
+ popups.CloseAll(false);
974
+ popups.SwallowPress = true;
975
+ this.AfterPopupsChanged();
976
+ return null;
977
+ }
978
+ }
748
979
  const consumed = root.ProcessGestures(args, info());
749
980
  if (!wheel)
750
981
  this.gestureOwner = consumed && args.Type !== "Up" ? consumed : null;
@@ -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) {
@@ -23,6 +23,10 @@ export declare class HoverManager {
23
23
  private y;
24
24
  private paused;
25
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;
26
30
  /**
27
31
  * The mouse (or a pen in range) moved to (x, y), canvas pixels, nothing pressed. The hit path is taken also while
28
32
  * hover waits (the cursor follows it), hover changes only when nothing moves.
@@ -23,6 +23,10 @@ export class HoverManager {
23
23
  y = 0;
24
24
  paused = false;
25
25
  check = false;
26
+ /** Picks the root under a point (canvas pixels): a popup window over the content, else the content. */
27
+ RootAt;
28
+ /** Content moves under the pointer (a scroll glide, a carousel transition): hover waits. */
29
+ get Paused() { return this.paused; }
26
30
  /**
27
31
  * The mouse (or a pen in range) moved to (x, y), canvas pixels, nothing pressed. The hit path is taken also while
28
32
  * hover waits (the cursor follows it), hover changes only when nothing moves.
@@ -43,6 +47,8 @@ export class HoverManager {
43
47
  path.length = 0;
44
48
  this.PathX.length = 0;
45
49
  this.PathY.length = 0;
50
+ if (this.RootAt)
51
+ root = this.RootAt(this.x, this.y);
46
52
  if (root && root.IsVisible && !root.InputTransparent) {
47
53
  const point = root.TransformPointToLocalSpace(new SKPoint(this.x, this.y));
48
54
  if (root.HitIsInside(point.X, point.Y))
@@ -15,9 +15,16 @@ export declare class KeyboardManager {
15
15
  private static readonly keyChar;
16
16
  static get IsShiftPressed(): boolean;
17
17
  static get IsControlPressed(): boolean;
18
+ /** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
19
+ static IsDispatchingKeyDown: boolean;
18
20
  static get IsAltPressed(): boolean;
19
21
  /** C# AttachToKeyboardAsync / JS attachGlobalKeyboard: idempotent. */
20
22
  static AttachToKeyboard(): void;
23
+ /**
24
+ * The modifier state follows each key event's own flags: a modifier pressed while the page had no focus (its keydown
25
+ * went elsewhere) still counts, and one released elsewhere stops counting.
26
+ */
27
+ private static SyncModifiers;
21
28
  static Subscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
22
29
  static Unsubscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
23
30
  /**
@@ -6,6 +6,8 @@ export class KeyboardManager {
6
6
  static keyChar = new Set();
7
7
  static get IsShiftPressed() { return KeyboardManager.pressed.has("ShiftLeft") || KeyboardManager.pressed.has("ShiftRight"); }
8
8
  static get IsControlPressed() { return KeyboardManager.pressed.has("ControlLeft") || KeyboardManager.pressed.has("ControlRight") || KeyboardManager.pressed.has("MetaLeft") || KeyboardManager.pressed.has("MetaRight"); }
9
+ /** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
10
+ static IsDispatchingKeyDown = false;
9
11
  static get IsAltPressed() { return KeyboardManager.pressed.has("AltLeft") || KeyboardManager.pressed.has("AltRight"); }
10
12
  /** C# AttachToKeyboardAsync / JS attachGlobalKeyboard: idempotent. */
11
13
  static AttachToKeyboard() {
@@ -16,9 +18,16 @@ export class KeyboardManager {
16
18
  window.addEventListener("pointerdown", () => window.focus(), true);
17
19
  window.addEventListener("keydown", (e) => {
18
20
  const code = e.code || "";
21
+ KeyboardManager.SyncModifiers(e);
19
22
  KeyboardManager.pressed.add(code);
20
- for (const h of [...KeyboardManager.keyDown])
21
- h(code, e);
23
+ KeyboardManager.IsDispatchingKeyDown = true;
24
+ try {
25
+ for (const h of [...KeyboardManager.keyDown])
26
+ h(code, e);
27
+ }
28
+ finally {
29
+ KeyboardManager.IsDispatchingKeyDown = false;
30
+ }
22
31
  const proxied = e.target?.dataset?.drawnuiTextInput === "1"; // TextInputProxy: characters come through its input events
23
32
  if (!proxied && e.key && e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey)
24
33
  for (const h of [...KeyboardManager.keyChar])
@@ -26,12 +35,32 @@ export class KeyboardManager {
26
35
  }, true);
27
36
  window.addEventListener("keyup", (e) => {
28
37
  const code = e.code || "";
38
+ KeyboardManager.SyncModifiers(e);
29
39
  KeyboardManager.pressed.delete(code);
30
40
  for (const h of [...KeyboardManager.keyUp])
31
41
  h(code, e);
32
42
  }, true);
33
43
  window.addEventListener("blur", () => KeyboardManager.pressed.clear());
34
44
  }
45
+ /**
46
+ * The modifier state follows each key event's own flags: a modifier pressed while the page had no focus (its keydown
47
+ * went elsewhere) still counts, and one released elsewhere stops counting.
48
+ */
49
+ static SyncModifiers(e) {
50
+ const sync = (down, left, right) => {
51
+ const p = KeyboardManager.pressed;
52
+ if (!down) {
53
+ p.delete(left);
54
+ p.delete(right);
55
+ }
56
+ else if (!p.has(left) && !p.has(right))
57
+ p.add(left);
58
+ };
59
+ sync(!!e.altKey, "AltLeft", "AltRight");
60
+ sync(!!e.ctrlKey, "ControlLeft", "ControlRight");
61
+ sync(!!e.shiftKey, "ShiftLeft", "ShiftRight");
62
+ sync(!!e.metaKey, "MetaLeft", "MetaRight");
63
+ }
35
64
  static Subscribe(down, char, up) {
36
65
  KeyboardManager.AttachToKeyboard();
37
66
  KeyboardManager.keyDown.add(down);
@@ -53,8 +82,10 @@ export class KeyboardManager {
53
82
  * those of its own element.
54
83
  */
55
84
  static IsOwnedByElement(e) {
56
- const tag = e.target?.tagName;
57
- return !!tag && tag !== "BODY" && tag !== "HTML" && tag !== "CANVAS";
85
+ const target = e.target;
86
+ const tag = target?.tagName;
87
+ // the canvas host holds the DOM focus when no drawn control has it: its keys are the app's, as the canvas' own
88
+ return !!tag && tag !== "BODY" && tag !== "HTML" && tag !== "CANVAS" && target?.dataset?.drawnuiHost !== "1";
58
89
  }
59
90
  /**
60
91
  * The key belongs to the input method (an IME composition, a soft keyboard): isComposing, keyCode 229, key "Process"
@@ -0,0 +1,92 @@
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
+ get HasInteractive(): boolean;
68
+ /** The content of the top popup window that takes input. */
69
+ get TopInteractive(): SkiaControl | undefined;
70
+ IsOpen(id: PopupId): boolean;
71
+ Open(root: SkiaControl, anchor: PopupAnchor, options: PopupWindowOptions, superview: SkiaControl["_superview"]): PopupId;
72
+ Close(id: PopupId): void;
73
+ CloseTop(): boolean;
74
+ CloseAll(passiveToo: boolean): void;
75
+ private Remove;
76
+ private static IsInside;
77
+ /** Tab stays inside the top popup window that takes input (a menu, a dropdown) while it is open. */
78
+ private UpdateKeyboardScope;
79
+ /** The top popup window taking input whose content is under the point (canvas pixels). */
80
+ At(x: number, y: number): SkiaControl | undefined;
81
+ /** The pointer is at (x, y) (undefined: off the canvas): popups closing on pointer leave close after 300 ms outside. */
82
+ PointerAt(x: number | undefined, y: number | undefined): void;
83
+ /**
84
+ * Where a popup of `w` x `h` goes for `anchor` (pixels) inside `bounds`: at the anchor's corner, flipped to its other side
85
+ * where it does not fit, then kept inside (C# PopupLayer.Place, Rust place_popup).
86
+ */
87
+ static Place(anchor: SKRect, point: boolean, w: number, h: number, bounds: SKRect): SKRect;
88
+ /** Measures, places and draws every popup over the content, inside `bounds` (canvas pixels). */
89
+ Draw(ctx: DrawingContext, bounds: SKRect): void;
90
+ Dispose(): void;
91
+ }
92
+ export {};