drawnui-react 0.1.0-preview.3 → 0.1.0-preview.31

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 (91) hide show
  1. package/README.md +15 -1
  2. package/SKIPPED.md +32 -25
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +7 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +16 -1
  5. package/dist/controls/DrawnGame.d.ts +40 -0
  6. package/dist/controls/DrawnGame.js +64 -0
  7. package/dist/controls/GridStructure.d.ts +16 -2
  8. package/dist/controls/GridStructure.js +40 -4
  9. package/dist/controls/SkiaBackdrop.d.ts +8 -2
  10. package/dist/controls/SkiaBackdrop.js +42 -14
  11. package/dist/controls/SkiaButton.d.ts +15 -1
  12. package/dist/controls/SkiaButton.js +21 -4
  13. package/dist/controls/SkiaCarousel.d.ts +21 -2
  14. package/dist/controls/SkiaCarousel.js +49 -5
  15. package/dist/controls/SkiaCheckbox.d.ts +0 -1
  16. package/dist/controls/SkiaCheckbox.js +0 -6
  17. package/dist/controls/SkiaDrawer.d.ts +2 -0
  18. package/dist/controls/SkiaDrawer.js +2 -0
  19. package/dist/controls/SkiaEditor.d.ts +38 -1
  20. package/dist/controls/SkiaEditor.js +223 -49
  21. package/dist/controls/SkiaGif.d.ts +3 -0
  22. package/dist/controls/SkiaGif.js +12 -2
  23. package/dist/controls/SkiaImage.js +15 -10
  24. package/dist/controls/SkiaLabel.d.ts +91 -7
  25. package/dist/controls/SkiaLabel.js +420 -71
  26. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  27. package/dist/controls/SkiaLabelFps.js +41 -0
  28. package/dist/controls/SkiaLayout.d.ts +97 -9
  29. package/dist/controls/SkiaLayout.js +387 -22
  30. package/dist/controls/SkiaLottie.js +4 -2
  31. package/dist/controls/SkiaProgress.d.ts +2 -1
  32. package/dist/controls/SkiaProgress.js +6 -3
  33. package/dist/controls/SkiaRadioButton.js +4 -3
  34. package/dist/controls/SkiaRichLabel.d.ts +1 -1
  35. package/dist/controls/SkiaRichLabel.js +11 -1
  36. package/dist/controls/SkiaScroll.d.ts +35 -5
  37. package/dist/controls/SkiaScroll.js +234 -23
  38. package/dist/controls/SkiaScrollBar.d.ts +27 -0
  39. package/dist/controls/SkiaScrollBar.js +51 -2
  40. package/dist/controls/SkiaShaderCarousel.d.ts +5 -0
  41. package/dist/controls/SkiaShaderCarousel.js +5 -0
  42. package/dist/controls/SkiaShape.d.ts +13 -2
  43. package/dist/controls/SkiaShape.js +50 -10
  44. package/dist/controls/SkiaSlider.d.ts +20 -2
  45. package/dist/controls/SkiaSlider.js +59 -5
  46. package/dist/controls/SkiaSprite.d.ts +1 -0
  47. package/dist/controls/SkiaSprite.js +4 -0
  48. package/dist/controls/SkiaSvg.js +1 -1
  49. package/dist/controls/SkiaSwitch.d.ts +0 -1
  50. package/dist/controls/SkiaSwitch.js +0 -6
  51. package/dist/controls/SkiaToggle.d.ts +25 -5
  52. package/dist/controls/SkiaToggle.js +58 -5
  53. package/dist/controls/SnappingLayout.d.ts +12 -1
  54. package/dist/controls/SnappingLayout.js +19 -1
  55. package/dist/core/Accessibility.d.ts +80 -0
  56. package/dist/core/Accessibility.js +421 -8
  57. package/dist/core/Animators.d.ts +37 -1
  58. package/dist/core/Animators.js +102 -9
  59. package/dist/core/Canvas.d.ts +108 -7
  60. package/dist/core/Canvas.js +353 -29
  61. package/dist/core/Easing.d.ts +12 -1
  62. package/dist/core/Easing.js +25 -1
  63. package/dist/core/Gestures.d.ts +34 -2
  64. package/dist/core/Gestures.js +84 -3
  65. package/dist/core/Hover.d.ts +47 -0
  66. package/dist/core/Hover.js +134 -0
  67. package/dist/core/KeyboardManager.d.ts +13 -0
  68. package/dist/core/KeyboardManager.js +18 -0
  69. package/dist/core/ScrollAnimators.js +9 -0
  70. package/dist/core/Shaping.d.ts +40 -0
  71. package/dist/core/Shaping.js +224 -0
  72. package/dist/core/SkiaControl.d.ts +209 -9
  73. package/dist/core/SkiaControl.js +500 -59
  74. package/dist/core/SkiaEffect.d.ts +17 -0
  75. package/dist/core/SkiaEffect.js +43 -8
  76. package/dist/core/SkiaImageManager.js +1 -1
  77. package/dist/core/Super.d.ts +22 -2
  78. package/dist/core/Super.js +47 -3
  79. package/dist/core/Types.d.ts +11 -1
  80. package/dist/core/Types.js +32 -1
  81. package/dist/core/ViewsAdapter.d.ts +7 -2
  82. package/dist/core/ViewsAdapter.js +10 -3
  83. package/dist/index.d.ts +3 -0
  84. package/dist/index.js +3 -0
  85. package/dist/react/SkiaShell.js +33 -14
  86. package/dist/react/index.d.ts +17 -4
  87. package/dist/react/index.js +103 -15
  88. package/dist/react/reconciler.js +33 -13
  89. package/dist/vite/index.d.ts +9 -0
  90. package/dist/vite/index.js +36 -3
  91. package/package.json +42 -3
@@ -1,9 +1,11 @@
1
1
  import { type CSSProperties, type FC, type ReactNode, type Ref } from "react";
2
2
  import { Canvas as CanvasView } from "../core/Canvas";
3
3
  import type { SkiaControl } from "../core/SkiaControl";
4
+ import type { Thickness, ThicknessValue } from "../core/Types";
4
5
  import type { SkiaLabel as SkiaLabelCtrl } from "../controls/SkiaLabel";
5
6
  import type { TextSpan as TextSpanCtrl } from "../controls/TextSpan";
6
7
  import type { SkiaRichLabel as SkiaRichLabelCtrl } from "../controls/SkiaRichLabel";
8
+ import type { SkiaLabelFps as SkiaLabelFpsCtrl } from "../controls/SkiaLabelFps";
7
9
  import type { SkiaSwitch as SkiaSwitchCtrl } from "../controls/SkiaSwitch";
8
10
  import type { SkiaCheckbox as SkiaCheckboxCtrl } from "../controls/SkiaCheckbox";
9
11
  import type { SkiaRadioButton as SkiaRadioButtonCtrl } from "../controls/SkiaRadioButton";
@@ -22,7 +24,7 @@ import type { SkiaScrollBar as SkiaScrollBarCtrl } from "../controls/SkiaScrollB
22
24
  import type { RefreshIndicator as RefreshIndicatorCtrl } from "../controls/RefreshIndicator";
23
25
  import type { SkiaSvg as SkiaSvgCtrl } from "../controls/SkiaSvg";
24
26
  import type { SkiaBackdrop as SkiaBackdropCtrl } from "../controls/SkiaBackdrop";
25
- import type { SkiaEditor as SkiaEditorCtrl } from "../controls/SkiaEditor";
27
+ import { SkiaEditor as SkiaEditorCtrl } from "../controls/SkiaEditor";
26
28
  import type { SkiaSprite as SkiaSpriteCtrl } from "../controls/SkiaSprite";
27
29
  import type { SkiaSpriteSet as SkiaSpriteSetCtrl } from "../controls/SkiaSpriteSet";
28
30
  import type { SkiaLottie as SkiaLottieCtrl } from "../controls/SkiaLottie";
@@ -41,7 +43,7 @@ import type { GesturesMode } from "../core/Gestures";
41
43
  * and never appeared in completion.
42
44
  */
43
45
  type PropsOf<T> = Partial<{
44
- [K in keyof T as T[K] extends Function ? (undefined extends T[K] ? K : never) : K extends "Children" | "Views" | "Parent" | "Spans" | "GridStructure" | "AccessibilityId" | "IsAccessibilityElement" | "HasTransform" | "RenderTransformMatrix" | "RenderObjectPrevious" | "LastMeasuredIndex" | "ItemsInsertedAtStart" | "UsingControlStyle" | "Track" | "Thumb" | "FrameOn" | "FrameOff" | "ViewCheckOn" | "ViewOn" | "ViewText" | "Ratio" | "StartThumbX" | "EndThumbX" | "SnapPoints" | "CurrentPosition" | "CurrentSnap" | "ContentOffsetBounds" | "InTransition" | "CanAnimate" | "MaxIndex" | "ChildrenTotal" | "IsAtStart" | "IsAtEnd" | "ScrollProgress" | "ScrollAmount" | "TransitionProgress" | "LastIndex" | "ChildrenCount" | "Horizontal" | "Animator" | "Animation" | "IsPlaying" | "PlayWhenAvailable" | "TotalFrames" | "HasEffects" | "IsDisposed" | "Label" | "IsMultiline" | "HasSelection" | "LayoutVersion" | "LinesCount" | "MeasuredLineHeight" | "Focused" | "SpriteSheet" | "FrameWidth" | "FrameHeight" | "DurationMs" | "FrameDurationMs" | "CurrentSprite" | "Rects" | "HasTapHandler" | "HasDecorations" | "LinesCount" | "Superview" | "DrawingRect" | "MeasuredSize" | "RenderingScale" | "NeedMeasure" | "_superview" | "HitBoxAuto" | "TotalDown" | "TotalTapped" | "TouchDown" | "PostAnimators" | "LoadedSource" | "IsLoading" | "DisplayRect" | "AspectScale" | "Content" | "ContentSize" | "ContentOffsetBounds" | "OverscrollDistance" | "OverScrolled" | "IsUserPanning" | "IsUserFocused" | "IsScrolling" | "IsTemplated" | "FirstVisibleIndex" | "LastVisibleIndex" | "DebugString" | "ChildrenFactory" | "ContextIndex" | "RenderObject" | "UsingCacheType" | "TransitionEffect" | "TransitionFromIndex" | "TransitionToIndex" | "EffectPostRenderers" | "CachedImage" | "ImageBitmap" | "ShouldSubmitOnEnter" | "Header" | "Footer" | "RefreshIndicator" | "ScrollBar" | "ScrollBarHorizontal" | "IsRunning" | "VisibleRatio" | "CurrentIndex" | "LastCompositeRecord" | "DirtyChildrenInternal" | "IsRenderingWithComposition" ? never : K]: T[K];
46
+ [K in keyof T as T[K] extends Function ? (undefined extends T[K] ? K : never) : K extends "Children" | "Views" | "Parent" | "Spans" | "GridStructure" | "AccessibilityId" | "IsAccessibilityElement" | "HasTransform" | "RenderTransformMatrix" | "RenderObjectPrevious" | "LastMeasuredIndex" | "ItemsInsertedAtStart" | "UsingControlStyle" | "Track" | "Thumb" | "FrameOn" | "FrameOff" | "ViewCheckOn" | "ViewOn" | "ViewText" | "Ratio" | "StartThumbX" | "EndThumbX" | "SnapPoints" | "CurrentPosition" | "CurrentSnap" | "ContentOffsetBounds" | "InTransition" | "CanAnimate" | "MaxIndex" | "ChildrenTotal" | "IsAtStart" | "IsAtEnd" | "ScrollProgress" | "ScrollAmount" | "TransitionProgress" | "LastIndex" | "ChildrenCount" | "Horizontal" | "Animator" | "Animation" | "IsPlaying" | "PlayWhenAvailable" | "TotalFrames" | "HasEffects" | "IsDisposed" | "Label" | "IsMultiline" | "HasSelection" | "LayoutVersion" | "LinesCount" | "MeasuredLineHeight" | "Focused" | "SpriteSheet" | "FrameWidth" | "FrameHeight" | "DurationMs" | "FrameDurationMs" | "CurrentSprite" | "Rects" | "HasTapHandler" | "HasDecorations" | "LinesCount" | "Superview" | "DrawingRect" | "MeasuredSize" | "RenderingScale" | "NeedMeasure" | "_superview" | "HitBoxAuto" | "TotalDown" | "TotalTapped" | "TouchDown" | "PostAnimators" | "LoadedSource" | "IsLoading" | "DisplayRect" | "AspectScale" | "Content" | "ContentSize" | "ContentOffsetBounds" | "OverscrollDistance" | "OverScrolled" | "IsUserPanning" | "IsUserFocused" | "IsScrolling" | "IsTemplated" | "FirstVisibleIndex" | "LastVisibleIndex" | "DebugString" | "ChildrenFactory" | "ContextIndex" | "RenderObject" | "UsingCacheType" | "TransitionEffect" | "TransitionFromIndex" | "TransitionToIndex" | "EffectPostRenderers" | "CachedImage" | "ImageBitmap" | "ShouldSubmitOnEnter" | "Header" | "Footer" | "RefreshIndicator" | "ScrollBar" | "ScrollBarHorizontal" | "IsRunning" | "VisibleRatio" | "CurrentIndex" | "LastCompositeRecord" | "DirtyChildrenInternal" | "IsRenderingWithComposition" | "IsHovered" ? never : K]: T[K] extends Thickness ? ThicknessValue : T[K];
45
47
  }>;
46
48
  /** `ref` receives the engine control instance (react-reconciler getPublicInstance). */
47
49
  type LeafProps<T> = PropsOf<T> & {
@@ -57,10 +59,13 @@ export declare const SkiaStack: FC<LayoutProps<SkiaLayoutCtrl>>;
57
59
  export declare const SkiaRow: FC<LayoutProps<SkiaLayoutCtrl>>;
58
60
  export declare const SkiaLayer: FC<LayoutProps<SkiaLayoutCtrl>>;
59
61
  export declare const SkiaWrap: FC<LayoutProps<SkiaLayoutCtrl>>;
62
+ export declare const SkiaMasonry: FC<LayoutProps<SkiaLayoutCtrl>>;
60
63
  export declare const SkiaGrid: FC<LayoutProps<SkiaLayoutCtrl>>;
61
64
  /** Grid drawing gradient separator lines in its spacing (C# SkiaDecoratedGrid). */
62
65
  export declare const SkiaDecoratedGrid: FC<LayoutProps<SkiaDecoratedGridCtrl>>;
63
66
  export declare const SkiaLabel: FC<LayoutProps<SkiaLabelCtrl>>;
67
+ /** Canvas FPS counter (C# SkiaLabelFps); its value changes only on frames running animators request anyway. */
68
+ export declare const SkiaLabelFps: FC<LeafProps<SkiaLabelFpsCtrl>>;
64
69
  /** Markdown label (C# SkiaRichLabel): Text is markdown, rendered as spans; LinkTapped for [text](url). */
65
70
  export declare const SkiaRichLabel: FC<LeafProps<SkiaRichLabelCtrl>>;
66
71
  /** Child of <SkiaLabel>: a styled fragment (C# TextSpan). */
@@ -100,7 +105,11 @@ export declare const SkiaDrawer: FC<LayoutProps<SkiaDrawerCtrl>>;
100
105
  export interface CanvasProps {
101
106
  BackgroundColor?: Color;
102
107
  RenderingMode?: RenderingModeType;
103
- /** Disabled (default) / Enabled / Lock, like DrawnUi Canvas.Gestures. */
108
+ /**
109
+ * Disabled (default) / Enabled / Lock, like DrawnUi Canvas.Gestures. Enabled shares input with the page like MAUI's
110
+ * Enabled inside a native scroll view: a touch pan along an axis the page can scroll scrolls the page, and the wheel
111
+ * scrolls it unless a control used the wheel. A page that cannot scroll keeps every touch. Lock keeps all input.
112
+ */
104
113
  Gestures?: GesturesMode;
105
114
  children?: ReactNode;
106
115
  style?: CSSProperties;
@@ -109,12 +118,16 @@ export interface CanvasProps {
109
118
  ref?: Ref<CanvasView>;
110
119
  /** Context-menu request (right click / long press / Menu key) no control handled; return true to suppress the browser menu. */
111
120
  ContextMenu?: CanvasView["ContextMenu"];
121
+ /** DrawnView.WillFirstTimeDraw: once, right before the first frame is drawn, with its drawing context. */
122
+ WillFirstTimeDraw?: CanvasView["WillFirstTimeDraw"];
123
+ /** DrawnView.WasDrawn: after every drawn frame. */
124
+ WasDrawn?: CanvasView["WasDrawn"];
112
125
  }
113
126
  /**
114
127
  * Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
115
128
  * Requires Super.UseDrawnUi()...BuildAsync() to have completed.
116
129
  */
117
- export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu }: CanvasProps): import("react").JSX.Element;
130
+ export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }: CanvasProps): import("react").JSX.Element;
118
131
  export type { SkiaControl };
119
132
  export * from "../index";
120
133
  export * from "./SkiaShell";
@@ -1,6 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
3
+ import { SkiaAccessibilityManager } from "../core/Accessibility";
4
+ import { TextInputProxy } from "../core/TextInputProxy";
3
5
  import { Canvas as CanvasView } from "../core/Canvas";
6
+ import { SkiaEditor as SkiaEditorCtrl } from "../controls/SkiaEditor";
4
7
  import { SkiaScroll as SkiaScrollCtrl } from "../controls/SkiaScroll";
5
8
  import { createDrawnRoot } from "./reconciler";
6
9
  /** Typed JSX tags resolved by the reconciler Registry. */
@@ -9,10 +12,13 @@ export const SkiaStack = "SkiaStack";
9
12
  export const SkiaRow = "SkiaRow";
10
13
  export const SkiaLayer = "SkiaLayer";
11
14
  export const SkiaWrap = "SkiaWrap";
15
+ export const SkiaMasonry = "SkiaMasonry";
12
16
  export const SkiaGrid = "SkiaGrid";
13
17
  /** Grid drawing gradient separator lines in its spacing (C# SkiaDecoratedGrid). */
14
18
  export const SkiaDecoratedGrid = "SkiaDecoratedGrid";
15
19
  export const SkiaLabel = "SkiaLabel";
20
+ /** Canvas FPS counter (C# SkiaLabelFps); its value changes only on frames running animators request anyway. */
21
+ export const SkiaLabelFps = "SkiaLabelFps";
16
22
  /** Markdown label (C# SkiaRichLabel): Text is markdown, rendered as spans; LinkTapped for [text](url). */
17
23
  export const SkiaRichLabel = "SkiaRichLabel";
18
24
  /** Child of <SkiaLabel>: a styled fragment (C# TextSpan). */
@@ -66,15 +72,19 @@ function removeStaticContent() {
66
72
  * Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
67
73
  * Requires Super.UseDrawnUi()...BuildAsync() to have completed.
68
74
  */
69
- export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu }) {
75
+ export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }) {
70
76
  const ref = useRef(null);
71
77
  const view = useRef(null);
72
78
  const root = useRef(null);
73
79
  const [engine, setEngine] = useState(null);
74
80
  useLayoutEffect(() => {
75
- const v = new CanvasView(ref.current);
76
- if (RenderingMode)
77
- v.RenderingMode = RenderingMode;
81
+ // the engine draws frame 1 inside its constructor: the draw events and the rendering mode must be on it before that
82
+ const v = new CanvasView(ref.current, (c) => {
83
+ if (RenderingMode)
84
+ c.RenderingMode = RenderingMode;
85
+ c.WillFirstTimeDraw = WillFirstTimeDraw;
86
+ c.WasDrawn = WasDrawn;
87
+ });
78
88
  view.current = v;
79
89
  root.current = createDrawnRoot(v);
80
90
  setEngine(v);
@@ -93,6 +103,8 @@ export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, sty
93
103
  }
94
104
  v.Gestures = Gestures ?? "Disabled";
95
105
  v.ContextMenu = ContextMenu;
106
+ v.WillFirstTimeDraw = WillFirstTimeDraw;
107
+ v.WasDrawn = WasDrawn;
96
108
  root.current.render(children);
97
109
  });
98
110
  // The drawn surface is aria-hidden; the overlay is the accessibility tree (DrawnUi.Blazor pattern).
@@ -108,19 +120,74 @@ const A11Y_CSS = `
108
120
  .drawnui-a11y-text>span{position:absolute;white-space:pre;color:transparent;user-select:text;-webkit-user-select:text;pointer-events:auto;cursor:text;line-height:1;font-kerning:none;font-feature-settings:"kern" 0,"liga" 0,"calt" 0;text-rendering:geometricPrecision}
109
121
  .drawnui-a11y-text>span::selection{background:rgba(110,168,254,.55);color:transparent}
110
122
  `;
123
+ const NAVIGATION_KEYS = new Set(["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "PageUp", "PageDown"]);
111
124
  /**
112
- * Invisible ARIA elements mirroring the accessible drawn controls, positioned over the canvas.
113
- * Improvement over DrawnUi.Blazor: `pointer-events:none`, so hover and every pointer gesture still reach the canvas —
114
- * keyboard (Tab / Enter / Space) and screen-reader activation arrive as DOM events and are routed back as a Tapped.
125
+ * Invisible ARIA elements mirroring the accessible drawn controls, positioned over the canvas (the DrawnUi.Blazor
126
+ * overlay). Improvement over DrawnUi.Blazor: `pointer-events:none`, so hover and every pointer gesture still reach the
127
+ * canvas. Keyboard and screen-reader input arrive as DOM events: Enter / Space activate (a Tapped), the navigation keys
128
+ * go to the focused control and then to its arrow-key group; a group is one Tab stop (roving tabindex).
115
129
  */
130
+ /** aria-valuenow / min / max / valuetext of a range control (drawnui-cross 6c); a slider reads as horizontal. */
131
+ function valueAttributes(n) {
132
+ const v = n.Value;
133
+ if (!v)
134
+ return undefined;
135
+ return { "aria-valuenow": v.Now, "aria-valuemin": v.Min, "aria-valuemax": v.Max, "aria-valuetext": v.Text || undefined, "aria-orientation": n.Role === "slider" ? "horizontal" : undefined };
136
+ }
116
137
  function AccessibilityOverlay({ view }) {
117
138
  const [nodes, setNodes] = useState(() => view.AccessibilityManager.Snapshot);
139
+ // keyboard focus moved by the manager (arrow keys in a group): focus that node's element once it is rendered
140
+ const [focusRequest, setFocusRequest] = useState();
141
+ // the Tab stop of a group moves with keyboard focus: re-render on focus
142
+ const [, setFocusTick] = useState(0);
118
143
  useEffect(() => {
119
144
  const mgr = view.AccessibilityManager;
120
145
  setNodes(mgr.Snapshot);
121
146
  const off = mgr.OnChanged(() => setNodes(mgr.Snapshot));
122
147
  const offLive = mgr.OnLiveRegionUpdated(() => { mgr.ForceRebuildOnNextFrame(); view.Update(); });
123
- return () => { off(); offLive(); };
148
+ const offFocus = mgr.OnKeyboardFocusRequested((node) => { setNodes(mgr.Snapshot); setFocusRequest({ id: node.AccessibilityId }); });
149
+ return () => { off(); offLive(); offFocus(); };
150
+ }, [view]);
151
+ const elementOf = (id) => overlayRef.current?.querySelector(`[data-a11y-id="${id}"]`) ?? undefined;
152
+ useLayoutEffect(() => {
153
+ if (!focusRequest)
154
+ return;
155
+ setFocusRequest(undefined);
156
+ elementOf(focusRequest.id)?.focus({ preventScroll: true });
157
+ }, [focusRequest]);
158
+ // the focused node went away (its page or popup closed): the focus goes to the first Tab stop on screen in reading
159
+ // order instead of falling back to the page (drawnui-cross 6c refocus); a focus the user moved away stays away
160
+ const focusedId = useRef(0);
161
+ useLayoutEffect(() => {
162
+ const id = focusedId.current;
163
+ if (!id || nodes.some((n) => n.Id === id))
164
+ return;
165
+ focusedId.current = 0;
166
+ const active = document.activeElement;
167
+ if (active && active !== document.body)
168
+ return;
169
+ const box = overlayRef.current?.getBoundingClientRect();
170
+ const first = nodes.find((n) => n.CanInteract && view.AccessibilityManager.IsTabStop(n.Source)
171
+ && (!box || (n.Rect.Bottom > 0 && n.Rect.Top < box.height && n.Rect.Right > 0 && n.Rect.Left < box.width)));
172
+ if (first)
173
+ elementOf(first.Id)?.focus({ preventScroll: true });
174
+ }, [nodes]);
175
+ // Tab / Shift+Tab in a text field leave it for the next node, also after a click into it: DOM focus goes to the
176
+ // field's own element (without taking the caret again) and the browser's Tab moves on from there
177
+ const tabbingOut = useRef(0);
178
+ useEffect(() => {
179
+ const onKey = (e) => {
180
+ const editor = SkiaEditorCtrl.Focused;
181
+ if (e.key !== "Tab" || !editor || editor.Superview !== view || !TextInputProxy.IsProxyTarget(e.target))
182
+ return;
183
+ const el = elementOf(editor.AccessibilityId);
184
+ if (!el)
185
+ return;
186
+ tabbingOut.current = editor.AccessibilityId;
187
+ el.focus({ preventScroll: true });
188
+ };
189
+ document.addEventListener("keydown", onKey, true);
190
+ return () => document.removeEventListener("keydown", onKey, true);
124
191
  }, [view]);
125
192
  // selectable text spans take pointer events: the wheel over them is re-dispatched to the canvas so drawn scrolls keep working
126
193
  const overlayRef = useRef(null);
@@ -155,15 +222,36 @@ function AccessibilityOverlay({ view }) {
155
222
  const pin = (e) => { e.currentTarget.scrollTop = 0; e.currentTarget.scrollLeft = 0; };
156
223
  return (_jsxs("div", { className: "drawnui-a11y-overlay", onScroll: pin, ref: overlayRef, children: [_jsx("style", { children: A11Y_CSS }), nodes.map((n) => {
157
224
  const pos = { left: n.Rect.Left, top: n.Rect.Top, width: n.Rect.Width, height: n.Rect.Height };
158
- const activate = () => n.Source.OnAccessibilityActivated();
159
- return n.CanInteract ? (_jsx("div", { role: n.Role, "aria-label": n.Label, title: n.Hint, "aria-pressed": n.Role === "button" ? n.IsPressed : undefined, "aria-checked": n.Role === "switch" || n.Role === "checkbox" || n.Role === "radio" ? n.IsPressed : undefined, "aria-live": n.Live, tabIndex: 0, className: "drawnui-a11y-node", style: { ...pos, fontSize: 0, userSelect: "none" }, onClick: activate, onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") {
160
- e.preventDefault();
161
- activate();
162
- } }, onFocus: (e) => { pin({ currentTarget: e.currentTarget.parentElement }); SkiaScrollCtrl.EnsureVisible(n.Source); n.Source.OnAccessibilityFocused(true); n.Source.NotifyAccessibilityFocused(true); }, onBlur: () => { n.Source.OnAccessibilityFocused(false); n.Source.NotifyAccessibilityFocused(false); }, children: n.Label }, n.Id)) : n.TextLines ? (
225
+ const activate = () => SkiaAccessibilityManager.Activate(n.Source);
226
+ return n.CanInteract ? (_jsx("div", { "data-a11y-id": n.Id, role: n.Role, "aria-label": n.Label, title: n.Hint, ...valueAttributes(n), "aria-pressed": n.Role === "button" ? n.IsPressed : undefined, "aria-checked": n.Role === "switch" || n.Role === "checkbox" || n.Role === "radio" ? n.IsPressed : undefined, "aria-live": n.Live, tabIndex: view.AccessibilityManager.IsTabStop(n.Source) ? 0 : -1, className: "drawnui-a11y-node", style: { ...pos, fontSize: 0, userSelect: "none" }, onClick: activate, onKeyDown: (e) => {
227
+ if (e.key === "Enter" || e.key === " ") {
228
+ e.preventDefault();
229
+ activate();
230
+ }
231
+ else if (NAVIGATION_KEYS.has(e.key) && SkiaAccessibilityManager.Key(n.Source, e.key))
232
+ e.preventDefault();
233
+ }, onFocus: (e) => {
234
+ focusedId.current = n.Id;
235
+ pin({ currentTarget: e.currentTarget.parentElement });
236
+ SkiaScrollCtrl.EnsureVisible(n.Source); // inside every enclosing scroll
237
+ if (tabbingOut.current === n.Id)
238
+ tabbingOut.current = 0; // leaving a text field: it keeps no caret
239
+ else
240
+ n.Source.OnAccessibilityFocused(true); // a text field takes the caret, as after a click
241
+ n.Source.NotifyAccessibilityFocused(true);
242
+ setFocusTick((t) => t + 1);
243
+ }, onBlur: (e) => {
244
+ if (e.currentTarget.isConnected && focusedId.current === n.Id)
245
+ focusedId.current = 0; // moved away on purpose
246
+ if (TextInputProxy.IsProxyTarget(e.relatedTarget))
247
+ return; // a text field moved DOM focus to its own input
248
+ n.Source.OnAccessibilityFocused(false);
249
+ n.Source.NotifyAccessibilityFocused(false);
250
+ }, children: n.Label }, n.Id)) : n.TextLines ? (
163
251
  // AccessibilityTextSelectable: one positioned span per drawn line, in the drawn font, so the browser selects and copies it like HTML
164
- _jsx("div", { role: n.Role, title: n.Hint, "aria-live": n.Live, className: "drawnui-a11y-node drawnui-a11y-text", style: pos, children: n.TextLines.map((l, i) => (_jsxs("span", { "data-w": l.Width, style: { left: l.Left, top: l.Top, height: l.Height, fontFamily: l.FontFamily, fontWeight: l.FontWeight, fontSize: l.FontSize, lineHeight: `${l.Height}px` }, children: [l.Text, i < n.TextLines.length - 1 ? "\n" : ""] }, i))) }, n.Id)) : (
252
+ _jsx("div", { role: n.Role, title: n.Hint, "aria-disabled": n.Disabled || undefined, "aria-live": n.Live, className: "drawnui-a11y-node drawnui-a11y-text", style: pos, children: n.TextLines.map((l, i) => (_jsxs("span", { "data-w": l.Width, style: { left: l.Left, top: l.Top, height: l.Height, fontFamily: l.FontFamily, fontWeight: l.FontWeight, fontSize: l.FontSize, lineHeight: `${l.Height}px` }, children: [l.Text, i < n.TextLines.length - 1 ? "\n" : ""] }, i))) }, n.Id)) : (
165
253
  // static text is exposed as real (transparent) text content; aria-label only for roles that need a name
166
- _jsx("div", { role: n.Role, "aria-label": n.Role === "text" ? undefined : n.Label, title: n.Hint, "aria-live": n.Live, className: "drawnui-a11y-node", style: pos, children: n.Label }, n.Id));
254
+ _jsx("div", { role: n.Role, "aria-label": n.Role === "text" ? undefined : n.Label, title: n.Hint, ...valueAttributes(n), "aria-disabled": n.Disabled || undefined, "aria-live": n.Live, className: "drawnui-a11y-node", style: pos, children: n.Label }, n.Id));
167
255
  })] }));
168
256
  }
169
257
  // One import for apps: React tags + every engine type (Colors, Thickness, Super, gestures, animators...).
@@ -1,9 +1,11 @@
1
1
  import { createContext } from "react";
2
2
  import Reconciler from "react-reconciler";
3
3
  import { ConcurrentRoot, DefaultEventPriority } from "react-reconciler/constants";
4
+ import { SkiaControl } from "../core/SkiaControl";
4
5
  import { SkiaLabel } from "../controls/SkiaLabel";
5
6
  import { TextSpan } from "../controls/TextSpan";
6
7
  import { SkiaRichLabel } from "../controls/SkiaRichLabel";
8
+ import { SkiaLabelFps } from "../controls/SkiaLabelFps";
7
9
  import { SkiaSwitch } from "../controls/SkiaSwitch";
8
10
  import { SkiaCheckbox } from "../controls/SkiaCheckbox";
9
11
  import { SkiaRadioButton } from "../controls/SkiaRadioButton";
@@ -12,7 +14,7 @@ import { SkiaSlider } from "../controls/SkiaSlider";
12
14
  import { SkiaCarousel } from "../controls/SkiaCarousel";
13
15
  import { SkiaShaderCarousel } from "../controls/SkiaShaderCarousel";
14
16
  import { SkiaDrawer } from "../controls/SkiaDrawer";
15
- import { SkiaGrid, SkiaLayer, SkiaLayout, SkiaRow, SkiaStack, SkiaWrap } from "../controls/SkiaLayout";
17
+ import { SkiaGrid, SkiaLayer, SkiaLayout, SkiaMasonry, SkiaRow, SkiaStack, SkiaWrap } from "../controls/SkiaLayout";
16
18
  import { SkiaHotspot } from "../controls/SkiaHotspot";
17
19
  import { SkiaButton } from "../controls/SkiaButton";
18
20
  import { SkiaImage } from "../controls/SkiaImage";
@@ -31,18 +33,20 @@ import { SkiaScroll } from "../controls/SkiaScroll";
31
33
  import { SkiaFrame, SkiaShape } from "../controls/SkiaShape";
32
34
  /** JSX tag name -> engine class. Add a control here to expose it to React. */
33
35
  export const Registry = {
34
- SkiaLayout, SkiaStack, SkiaRow, SkiaLayer, SkiaWrap, SkiaGrid, SkiaDecoratedGrid, SkiaBackdrop, SkiaEditor, SkiaSprite, SkiaSpriteSet, SkiaLabel, SkiaRichLabel, TextSpan, SkiaHotspot, SkiaButton, SkiaImage, SkiaImageTiles, SkiaSvg, SkiaLottie, SkiaGif, SkiaScroll, SkiaScrollBar, RefreshIndicator, SkiaShape, SkiaFrame,
36
+ SkiaLayout, SkiaStack, SkiaRow, SkiaLayer, SkiaWrap, SkiaMasonry, SkiaGrid, SkiaDecoratedGrid, SkiaBackdrop, SkiaEditor, SkiaSprite, SkiaSpriteSet, SkiaLabel, SkiaLabelFps, SkiaRichLabel, TextSpan, SkiaHotspot, SkiaButton, SkiaImage, SkiaImageTiles, SkiaSvg, SkiaLottie, SkiaGif, SkiaScroll, SkiaScrollBar, RefreshIndicator, SkiaShape, SkiaFrame,
35
37
  SkiaSwitch, SkiaCheckbox, SkiaRadioButton, SkiaProgress, SkiaSlider, SkiaCarousel, SkiaShaderCarousel, SkiaDrawer,
36
38
  };
37
39
  const SKIP = new Set(["children", "key", "ref"]);
38
40
  /** Props that change how the subtree is composited, not what it contains: repaint, keep caches (DrawnUi RedrawCanvas). */
39
- const REPAINT_ONLY = new Set(["TranslationX", "TranslationY", "Rotation", "ScaleX", "ScaleY", "Scale", "SkewX", "SkewY", "AnchorX", "AnchorY", "Opacity"]);
41
+ const REPAINT_ONLY = new Set(["TranslationX", "TranslationY", "TranslationZ", "Rotation", "RotationX", "RotationY", "RotationZ", "ScaleX", "ScaleY", "Scale", "SkewX", "SkewY", "AnchorX", "AnchorY", "Opacity"]);
42
+ /** Props that change only how a control looks, never its size (C# NeedDraw): an ImageComposite above redraws only its area. */
43
+ const isDrawOnly = (k) => k.endsWith("Color") || k === "FillGradient" || k === "StrokeGradient";
40
44
  /**
41
45
  * Assigns changed props straight onto the control (same names as the C# properties).
42
46
  * Handler props (functions) are swapped without invalidating: inline arrows change identity every render.
43
47
  */
44
48
  function applyProps(inst, prev, next) {
45
- let changed = false, repaint = false;
49
+ let changed = false, repaint = false, layout = false;
46
50
  for (const k in next) {
47
51
  if (SKIP.has(k) || (prev && prev[k] === next[k]))
48
52
  continue;
@@ -51,23 +55,36 @@ function applyProps(inst, prev, next) {
51
55
  continue;
52
56
  if (REPAINT_ONLY.has(k))
53
57
  repaint = true;
54
- else
58
+ else {
55
59
  changed = true;
60
+ if (!isDrawOnly(k))
61
+ layout = true;
62
+ }
56
63
  }
57
64
  if (prev)
58
65
  for (const k in prev)
59
66
  if (!SKIP.has(k) && !(k in next)) {
60
67
  inst[k] = new inst.constructor()[k];
61
- changed = true;
68
+ changed = layout = true;
62
69
  }
63
- if (changed && prev)
64
- inst.Update();
70
+ if (changed && prev) {
71
+ if (layout || !(inst instanceof SkiaControl))
72
+ inst.Update();
73
+ else
74
+ inst.UpdateDraw();
75
+ }
65
76
  else if (repaint && prev)
66
77
  inst.RepaintComposition?.();
67
78
  }
68
79
  let currentUpdatePriority = DefaultEventPriority;
69
80
  const noop = () => { };
70
81
  const hostContext = {};
82
+ function appendChild(parent, child) {
83
+ if (parent instanceof SkiaLayout)
84
+ return parent.InsertChild(child);
85
+ child.IsChildrenItem = true;
86
+ parent.AddSubView(child);
87
+ }
71
88
  // Record<string, unknown> absorbs members that react-reconciler 0.33 reads but @types 0.32 does not declare yet.
72
89
  const hostConfig = {
73
90
  supportsMutation: true,
@@ -93,12 +110,15 @@ const hostConfig = {
93
110
  createTextInstance(text) {
94
111
  throw new Error(`DrawnUi: raw text "${text}" is not allowed, use <SkiaLabel Text="..." />`);
95
112
  },
96
- appendInitialChild: (parent, child) => parent.AddSubView(child),
97
- appendChild: (parent, child) => parent.AddSubView(child),
113
+ // JSX children are the app's children (C# IsChildrenItem): a layout keeps them in JSX order inside the slots they
114
+ // occupy, so its own parts keep their place; an existing child passed again is a move
115
+ appendInitialChild: (parent, child) => appendChild(parent, child),
116
+ appendChild: (parent, child) => appendChild(parent, child),
98
117
  insertBefore: (parent, child, before) => {
99
- const index = parent instanceof SkiaLayout ? parent.Views.indexOf(before)
100
- : parent instanceof SkiaLabel ? parent.Spans.indexOf(before) : 0;
101
- parent.InsertSubView(index, child);
118
+ if (parent instanceof SkiaLayout)
119
+ return parent.InsertChild(child, before);
120
+ child.IsChildrenItem = true;
121
+ parent.InsertSubView(parent instanceof SkiaLabel ? parent.Spans.indexOf(before) : 0, child);
102
122
  },
103
123
  removeChild: (parent, child) => parent.RemoveSubView(child),
104
124
  appendChildToContainer: (canvas, child) => { canvas.Content = child; },
@@ -1,4 +1,13 @@
1
1
  import type { Plugin } from "vite";
2
+ /**
3
+ * Versioned addresses for the files of the public folder (fonts, images, sprites, shaders, Lottie, favicon). Their
4
+ * names never change, and a browser or CDN may keep them for hours, so after a publish a returning visitor could
5
+ * get new code with an old file. On build every public file gets a short content hash: index.html receives the map
6
+ * as `globalThis.DrawnUiAssetStamps` (read by `Super.ResolveAssetUrl`, which every engine loader fetches through)
7
+ * and its own `href` / `src` links to public files get `?v=<hash>`. A changed file gets a new address, an unchanged
8
+ * one keeps its address and stays cached. Bundled files (hashed names) need nothing. The dev server is left alone.
9
+ */
10
+ export declare function drawnUiAssetStamps(): Plugin;
2
11
  export interface DrawnUiStaticOptions {
3
12
  /**
4
13
  * Pages to generate, as URL hashes / paths appended to the site root ("" = the root page, "#/shapes"...).
@@ -1,9 +1,42 @@
1
1
  /**
2
- * Vite helpers for DrawnUi.React apps: `import { drawnUiStatic } from "drawnui-react/vite"`.
2
+ * Vite helpers for DrawnUi.React apps: `import { drawnUiStatic, drawnUiAssetStamps } from "drawnui-react/vite"`.
3
3
  * Build-time only; the runtime bundle never imports this module and the frame loop knows nothing about it.
4
4
  */
5
- import { readFileSync, writeFileSync } from "node:fs";
6
- import { resolve } from "node:path";
5
+ import { createHash } from "node:crypto";
6
+ import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
7
+ import { join, resolve } from "node:path";
8
+ /**
9
+ * Versioned addresses for the files of the public folder (fonts, images, sprites, shaders, Lottie, favicon). Their
10
+ * names never change, and a browser or CDN may keep them for hours, so after a publish a returning visitor could
11
+ * get new code with an old file. On build every public file gets a short content hash: index.html receives the map
12
+ * as `globalThis.DrawnUiAssetStamps` (read by `Super.ResolveAssetUrl`, which every engine loader fetches through)
13
+ * and its own `href` / `src` links to public files get `?v=<hash>`. A changed file gets a new address, an unchanged
14
+ * one keeps its address and stays cached. Bundled files (hashed names) need nothing. The dev server is left alone.
15
+ */
16
+ export function drawnUiAssetStamps() {
17
+ let stamps = {};
18
+ return {
19
+ name: "drawnui-asset-stamps",
20
+ apply: "build",
21
+ configResolved(config) {
22
+ const dir = config.publicDir;
23
+ if (!dir)
24
+ return;
25
+ for (const rel of readdirSync(dir, { recursive: true })) {
26
+ const file = join(dir, rel);
27
+ if (statSync(file).isFile())
28
+ stamps[rel.replace(/\\/g, "/")] = createHash("sha256").update(readFileSync(file)).digest("hex").slice(0, 10);
29
+ }
30
+ },
31
+ transformIndexHtml(html) {
32
+ const stamped = html.replace(/\b(href|src)="([^"?#:]+)"/g, (m, attr, url) => {
33
+ const v = stamps[url.replace(/^\.?\//, "")];
34
+ return v ? `${attr}="${url}?v=${v}"` : m;
35
+ });
36
+ return { html: stamped, tags: [{ tag: "script", children: `globalThis.DrawnUiAssetStamps=${JSON.stringify(stamps)}`, injectTo: "head-prepend" }] };
37
+ },
38
+ };
39
+ }
7
40
  /**
8
41
  * Generates visible, semantic HTML for crawlers and AI agents from the app's own accessibility tree, at build time.
9
42
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawnui-react",
3
- "version": "0.1.0-preview.3",
3
+ "version": "0.1.0-preview.31",
4
4
  "description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
5
5
  "license": "MIT",
6
6
  "author": "Nick Kovalsky (AppoMobi)",
@@ -53,6 +53,41 @@
53
53
  "typecheck": "tsc --noEmit",
54
54
  "build": "tsc --noEmit && node dev/build-samples.mjs",
55
55
  "sync:skills": "node dev/sync-skills.mjs",
56
+ "check:recycling": "node dev/check.mjs dev/check-recycling.ts",
57
+ "check:keyboard": "node dev/check.mjs dev/check-keyboard.ts",
58
+ "check:wheel": "node dev/check.mjs dev/check-wheel.ts",
59
+ "check:children": "node dev/check.mjs dev/check-children.tsx",
60
+ "check:composite": "node dev/check.mjs dev/check-composite.tsx",
61
+ "check:hover": "node dev/check.mjs dev/check-hover.ts",
62
+ "check:grid-label": "node dev/check.mjs dev/check-grid-label.ts",
63
+ "check:snap": "node dev/check.mjs dev/check-snap.ts",
64
+ "check:game": "node dev/check.mjs dev/check-game.ts",
65
+ "check:animation": "node dev/check.mjs dev/check-animation.ts",
66
+ "check:shape": "node dev/check.mjs dev/check-shape.ts",
67
+ "check:label": "node dev/check.mjs dev/check-label.ts",
68
+ "check:image": "node dev/check.mjs dev/check-image.ts",
69
+ "check:longpress": "node dev/check.mjs dev/check-longpress.ts",
70
+ "check:hidden": "node dev/check.mjs dev/check-hidden.ts",
71
+ "check:shell": "node dev/check.mjs dev/check-shell.tsx",
72
+ "check:wheel-routing": "node dev/check.mjs dev/check-wheel-routing.ts",
73
+ "check:velocity": "node dev/check.mjs dev/check-velocity.ts",
74
+ "check:scroll-index": "node dev/check.mjs dev/check-scroll-index.ts",
75
+ "check:culling": "node dev/check.mjs dev/check-culling.ts",
76
+ "check:responds": "node dev/check.mjs dev/check-responds.ts",
77
+ "check:3d": "node dev/check.mjs dev/check-3d.ts",
78
+ "check:gesture-owner": "node dev/check.mjs dev/check-gesture-owner.ts",
79
+ "check:shader-cache": "node dev/check.mjs dev/check-shader-cache.ts",
80
+ "check:shader-content": "node dev/check.mjs dev/check-shader-content.ts",
81
+ "check:backdrop": "node dev/check.mjs dev/check-backdrop.ts",
82
+ "check:masonry": "node dev/check.mjs dev/check-masonry.ts",
83
+ "check:thickness": "node dev/check.mjs dev/check-thickness.ts",
84
+ "check:scroll-recycled": "node dev/check.mjs dev/check-scroll-recycled.ts",
85
+ "check:masonry-keys": "node dev/check.mjs dev/check-masonry-keys.ts",
86
+ "check:carousel-swipe": "node dev/check.mjs dev/check-carousel-swipe.ts",
87
+ "check:editor-focus": "node dev/check.mjs dev/check-editor-focus.ts",
88
+ "check:shaping": "node dev/check.mjs dev/check-shaping.ts",
89
+ "check:editor-rtl": "node dev/check.mjs dev/check-editor-rtl.ts",
90
+ "check:label-direction": "node dev/check.mjs dev/check-label-direction.ts",
56
91
  "site:extras": "node dev/site-extras.mjs dist/demo",
57
92
  "build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
58
93
  "prepublishOnly": "npm run build:lib",
@@ -65,8 +100,12 @@
65
100
  "vite": ">=5"
66
101
  },
67
102
  "peerDependenciesMeta": {
68
- "playwright-core": { "optional": true },
69
- "vite": { "optional": true }
103
+ "playwright-core": {
104
+ "optional": true
105
+ },
106
+ "vite": {
107
+ "optional": true
108
+ }
70
109
  },
71
110
  "dependencies": {
72
111
  "canvaskit-wasm": "^0.42.0",