drawnui-react 0.1.0-preview.4 → 0.1.0-preview.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +119 -14
  2. package/SKIPPED.md +36 -26
  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 +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 +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 +48 -2
  20. package/dist/controls/SkiaEditor.js +268 -53
  21. package/dist/controls/SkiaGif.d.ts +7 -0
  22. package/dist/controls/SkiaGif.js +25 -4
  23. package/dist/controls/SkiaImage.d.ts +5 -0
  24. package/dist/controls/SkiaImage.js +48 -14
  25. package/dist/controls/SkiaLabel.d.ts +117 -9
  26. package/dist/controls/SkiaLabel.js +526 -80
  27. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  28. package/dist/controls/SkiaLabelFps.js +41 -0
  29. package/dist/controls/SkiaLayout.d.ts +89 -9
  30. package/dist/controls/SkiaLayout.js +364 -21
  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 +35 -5
  39. package/dist/controls/SkiaScroll.js +252 -32
  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 +13 -2
  45. package/dist/controls/SkiaShape.js +50 -10
  46. package/dist/controls/SkiaSlider.d.ts +20 -2
  47. package/dist/controls/SkiaSlider.js +61 -7
  48. package/dist/controls/SkiaSprite.d.ts +4 -0
  49. package/dist/controls/SkiaSprite.js +22 -10
  50. package/dist/controls/SkiaSvg.d.ts +4 -0
  51. package/dist/controls/SkiaSvg.js +28 -4
  52. package/dist/controls/SkiaSwitch.d.ts +0 -1
  53. package/dist/controls/SkiaSwitch.js +4 -8
  54. package/dist/controls/SkiaToggle.d.ts +25 -5
  55. package/dist/controls/SkiaToggle.js +58 -5
  56. package/dist/controls/SnappingLayout.d.ts +12 -1
  57. package/dist/controls/SnappingLayout.js +21 -2
  58. package/dist/controls/TooltipStyle.d.ts +52 -0
  59. package/dist/controls/TooltipStyle.js +88 -0
  60. package/dist/core/Accessibility.d.ts +134 -0
  61. package/dist/core/Accessibility.js +675 -9
  62. package/dist/core/Animators.d.ts +37 -1
  63. package/dist/core/Animators.js +102 -9
  64. package/dist/core/Canvas.d.ts +222 -10
  65. package/dist/core/Canvas.js +698 -37
  66. package/dist/core/ControlStyle.d.ts +2 -0
  67. package/dist/core/ControlStyle.js +2 -0
  68. package/dist/core/Easing.d.ts +12 -1
  69. package/dist/core/Easing.js +25 -1
  70. package/dist/core/Gestures.d.ts +81 -2
  71. package/dist/core/Gestures.js +177 -3
  72. package/dist/core/Hover.d.ts +51 -0
  73. package/dist/core/Hover.js +140 -0
  74. package/dist/core/ImageEffects.d.ts +2 -0
  75. package/dist/core/ImageEffects.js +2 -0
  76. package/dist/core/KeyboardManager.d.ts +40 -0
  77. package/dist/core/KeyboardManager.js +98 -8
  78. package/dist/core/PopupWindows.d.ts +94 -0
  79. package/dist/core/PopupWindows.js +205 -0
  80. package/dist/core/ScrollAnimators.js +9 -0
  81. package/dist/core/Shaping.d.ts +40 -0
  82. package/dist/core/Shaping.js +224 -0
  83. package/dist/core/SkiaControl.d.ts +279 -10
  84. package/dist/core/SkiaControl.js +621 -64
  85. package/dist/core/SkiaEffect.d.ts +17 -0
  86. package/dist/core/SkiaEffect.js +43 -8
  87. package/dist/core/SkiaImageManager.js +1 -1
  88. package/dist/core/Super.d.ts +29 -2
  89. package/dist/core/Super.js +54 -3
  90. package/dist/core/Tooltips.d.ts +71 -0
  91. package/dist/core/Tooltips.js +205 -0
  92. package/dist/core/Types.d.ts +11 -1
  93. package/dist/core/Types.js +32 -1
  94. package/dist/core/ViewsAdapter.d.ts +7 -2
  95. package/dist/core/ViewsAdapter.js +10 -3
  96. package/dist/index.d.ts +6 -0
  97. package/dist/index.js +6 -0
  98. package/dist/react/SkiaShell.js +65 -26
  99. package/dist/react/index.d.ts +33 -4
  100. package/dist/react/index.js +157 -18
  101. package/dist/react/reconciler.d.ts +20 -0
  102. package/dist/react/reconciler.js +69 -14
  103. package/dist/vite/index.d.ts +9 -0
  104. package/dist/vite/index.js +36 -3
  105. package/package.json +61 -2
@@ -3,7 +3,7 @@ import { SkiaStyles } from "./Styles";
3
3
  import { Colors, SKRect, ScaledSize, Thickness } from "./Types";
4
4
  import { RippleAnimator, SkiaValueAnimator } from "./Animators";
5
5
  import { Easing } from "./Easing";
6
- import { Aria } from "./Accessibility";
6
+ import { AccessibilityModals, Aria } from "./Accessibility";
7
7
  import { ControlTappedEventArgs, GestureEventProcessingInfo, SKPoint, SkiaGesturesInfo, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
8
8
  import { IsPostRendererEffect } from "./SkiaEffect";
9
9
  /** Mirrors DrawnUi CachedObject: what a cached control replays instead of repainting. */
@@ -22,12 +22,29 @@ export class CachedObject {
22
22
  this.Picture = Picture;
23
23
  this.Image = Image;
24
24
  }
25
- /** Replays the cache with its top-left moved to (left, top). */
26
- Draw(canvas, left, top) {
25
+ /** Canvas.GpuEpoch it was made in: after a WebGL context restore it is remade (a picture may replay old GPU images). */
26
+ Epoch = 0;
27
+ /** A picture recorded to be drawn distorted: the images in it sample smoothly (C# CachedObject.PlaybackDistorted). */
28
+ PlaybackDistorted = false;
29
+ /** A picture holding image blits, whose sampling was fixed when it was recorded (C# CachedObject.HasImageBlits). */
30
+ HasImageBlits = false;
31
+ /** C# PaintRenderObject: the blit paint is antialiased (else a turned bitmap keeps stair steps along its own border), dithered when distorted. */
32
+ static blitPaint;
33
+ static blitPaintDithered;
34
+ static BlitPaint(dither) {
35
+ const CK = Super.CK;
36
+ const make = () => { const p = new CK.Paint(); p.setAntiAlias(true); p.setDither(dither); return p; };
37
+ return dither ? (CachedObject.blitPaintDithered ??= make()) : (CachedObject.blitPaint ??= make());
38
+ }
39
+ /** Replays the cache with its top-left moved to (left, top); `smooth` = an image drawn distorted (linear + mipmaps). */
40
+ Draw(canvas, left, top, smooth = false) {
27
41
  const CK = Super.CK;
28
42
  if (this.Image) {
29
- // Nearest sampling: a cached bitmap is blitted 1:1, never resampled.
30
- canvas.drawImageOptions(this.Image, left, top, CK.FilterMode.Nearest, CK.MipmapMode.None, null);
43
+ // nearest keeps a bitmap blitted 1:1 sharp; once scaled, turned or projected it needs smooth sampling (C# 1e4610f6)
44
+ if (smooth)
45
+ canvas.drawImageOptions(this.Image, left, top, CK.FilterMode.Linear, CK.MipmapMode.Linear, CachedObject.BlitPaint(true));
46
+ else
47
+ canvas.drawImageOptions(this.Image, left, top, CK.FilterMode.Nearest, CK.MipmapMode.None, CachedObject.BlitPaint(false));
31
48
  }
32
49
  else if (this.Picture) {
33
50
  const saved = canvas.save();
@@ -36,9 +53,36 @@ export class CachedObject {
36
53
  canvas.restoreToCount(saved);
37
54
  }
38
55
  }
56
+ /**
57
+ * C# GetPictureImage: the picture of a picture cache (Operations, OperationsFull) drawn into an image, made on the
58
+ * first call (on `main`'s GPU context when given) and kept as long as this cache lives. Shader effects read it as
59
+ * their input, so on such a control they work on its own content, as on an Image cache.
60
+ */
61
+ GetPictureImage(main) {
62
+ if (this.pictureImage || !this.Picture)
63
+ return this.pictureImage;
64
+ const w = Math.ceil(this.Bounds.Width), h = Math.ceil(this.Bounds.Height);
65
+ if (w <= 0 || h <= 0)
66
+ return undefined;
67
+ const surface = main?.makeSurface({ ...main.imageInfo(), width: w, height: h }) ?? Super.CK.MakeSurface(w, h);
68
+ if (!surface)
69
+ return undefined;
70
+ const canvas = surface.getCanvas();
71
+ canvas.clear(Super.CK.TRANSPARENT);
72
+ canvas.translate(-this.Bounds.Left, -this.Bounds.Top);
73
+ canvas.drawPicture(this.Picture);
74
+ this.pictureImage = surface.makeImageSnapshot();
75
+ surface.dispose(); // a CK.MakeSurface fallback owns its pixels
76
+ return this.pictureImage;
77
+ }
78
+ pictureImage;
79
+ /** The picture drawn into an image, once GetPictureImage made it. */
80
+ get PictureImage() { return this.pictureImage; }
39
81
  Dispose() {
40
82
  this.Picture?.delete();
41
83
  this.Image?.delete();
84
+ this.pictureImage?.delete();
85
+ this.pictureImage = undefined;
42
86
  }
43
87
  }
44
88
  /**
@@ -48,6 +92,11 @@ export class CachedObject {
48
92
  * Render(ctx) -> background + Paint(ctx),
49
93
  * ProcessGestures(args, apply) -> consumer or null.
50
94
  */
95
+ /**
96
+ * Controls holding something outside the tree while they are on a canvas (a focused editor's keys and caret timer, a
97
+ * game's keys): the canvas calls their OnLeftCanvas when they leave it with a removed or disposed subtree.
98
+ */
99
+ export const CanvasLeaveWatchers = new Set();
51
100
  export class SkiaControl {
52
101
  // ---- layout properties (points) ----
53
102
  HorizontalOptions = "Start";
@@ -66,7 +115,10 @@ export class SkiaControl {
66
115
  Row = 0;
67
116
  ColumnSpan = 1;
68
117
  RowSpan = 1;
69
- Margin = Thickness.Zero;
118
+ margin = Thickness.Zero;
119
+ /** Space around the control (points); a number is the same on every side, as C# XAML (`Thickness.From`). */
120
+ get Margin() { return this.margin; }
121
+ set Margin(v) { this.margin = Thickness.From(v); }
70
122
  /**
71
123
  * DrawnUi LockRatio: 0 = off; positive = square of the LARGER of the two sizes (requests or constraints),
72
124
  * negative = square of the SMALLER one. Infinite sides are ignored, so WidthRequest=150 + LockRatio=1 = 150x150.
@@ -87,6 +139,14 @@ export class SkiaControl {
87
139
  /** Degrees. */
88
140
  SkewX = 0;
89
141
  SkewY = 0;
142
+ /** Degrees, a 3D turn around the horizontal axis through the pivot, seen with perspective (C# RotationX). */
143
+ RotationX = 0;
144
+ /** Degrees, a 3D turn around the vertical axis through the pivot (C# RotationY). */
145
+ RotationY = 0;
146
+ /** Degrees, a 3D turn around the axis facing the viewer, after RotationX and RotationY (C# RotationZ). */
147
+ RotationZ = 0;
148
+ /** Depth: toward the viewer (+, bigger) or away (−, smaller), turned or flat; draws at 576 / (576 − TranslationZ) (C# TranslationZ). */
149
+ TranslationZ = 0;
90
150
  /** Pivot for Rotation/Scale/Skew as a fraction of the box (MAUI default 0.5). */
91
151
  AnchorX = 0.5;
92
152
  AnchorY = 0.5;
@@ -114,8 +174,9 @@ export class SkiaControl {
114
174
  get Scale() { return this.ScaleX; }
115
175
  set Scale(v) { this.ScaleX = v; this.ScaleY = v; }
116
176
  get HasTransform() {
117
- return this.TranslationX !== 0 || this.TranslationY !== 0 || this.Left !== 0 || this.Top !== 0 || this.Rotation !== 0 || this.ScaleX !== 1 || this.ScaleY !== 1 || this.SkewX !== 0 || this.SkewY !== 0;
177
+ return this.TranslationX !== 0 || this.TranslationY !== 0 || this.Left !== 0 || this.Top !== 0 || this.Rotation !== 0 || this.ScaleX !== 1 || this.ScaleY !== 1 || this.SkewX !== 0 || this.SkewY !== 0 || this.Has3d;
118
178
  }
179
+ get Has3d() { return this.RotationX !== 0 || this.RotationY !== 0 || this.RotationZ !== 0 || this.TranslationZ !== 0; }
119
180
  /** Matrix applied at the last render (canvas space), undefined when none; gestures map through its inverse. */
120
181
  RenderTransformMatrix;
121
182
  /** Generic numeric parameters (DrawnUi Value1/Value2): SkiaShape Arc uses start angle / sweep angle in degrees. */
@@ -132,6 +193,7 @@ export class SkiaControl {
132
193
  return;
133
194
  this.bindingContext = value;
134
195
  this.OnBindingContextChanged();
196
+ this.Superview?.Hover?.RequestCheck(); // a recycled cell under a still mouse now shows another item
135
197
  }
136
198
  /** Index of the bound item inside its ItemsSource, -1 when not templated. */
137
199
  ContextIndex = -1;
@@ -164,15 +226,52 @@ export class SkiaControl {
164
226
  compositeSurface;
165
227
  /** Own content or structure changed: the next composite record is a full one. */
166
228
  compositeFull = true;
229
+ /** Where the kept composite surface starts relative to DrawingRect (the effects margin it was laid out with). */
230
+ compositeInsetX = 0;
231
+ compositeInsetY = 0;
167
232
  /** Canvas-pixel bounds this control covered when its parent last recorded it (composite erase region). */
168
233
  lastCompositeBounds;
169
- /** What the last composite record did (diagnostics): "full" or "partial", the number of children re-recorded and which ones. */
170
- LastCompositeRecord = { Mode: "full", Children: 0, Dirty: [] };
234
+ /**
235
+ * What the last composite record did (diagnostics): "full" or "partial", the number of children re-recorded and which
236
+ * ones; Areas: the pixels erased and drawn again for changes deeper than a child (C# Areas), Changed: the controls
237
+ * those areas belong to (C# Changed).
238
+ */
239
+ LastCompositeRecord = { Mode: "full", Children: 0, Dirty: [], Areas: [], Changed: [] };
240
+ /** C# MaxCompositionAreas: more areas than this in one composite record draw it whole instead. */
241
+ static MaxCompositionAreas = 16;
242
+ /** C# MaxCompositionShare: areas covering more than this share of a composite draw it whole instead. */
243
+ static MaxCompositionShare = 0.5;
244
+ /**
245
+ * Changes deeper than a direct child since the last composite record (drawnui-cross 6m): the control, the direct child
246
+ * it is in, where it was drawn before the change (its own drawn bounds, as drawn) and its rect then.
247
+ */
248
+ compositeDeep;
249
+ /** Set while an UpdateDraw climbs: the ancestors re-measure but an ImageComposite among them keeps its partial record. */
250
+ static drawOrigin = null;
171
251
  /** The children a composite record can re-record individually; layouts return their views. */
172
252
  GetCompositeChildren() { return []; }
173
253
  /** C# TrackChildAsDirty (DirtyChildrenTracker): the child changed without a remeasure of this control. */
174
254
  TrackChildAsDirty(child) { if (this.IsCacheComposite)
175
255
  this.DirtyChildrenInternal.add(child); }
256
+ static rejectRect = new Float32Array(4);
257
+ /** Its cache must be recorded before it can be drawn (none, dirty, another type, scale, size or GPU context). */
258
+ CacheStale(scale) {
259
+ const cacheType = this.UsingCacheType;
260
+ if (cacheType === "None")
261
+ return false;
262
+ const o = this.RenderObject, r = cacheType === "Operations" ? this.ExpandedCacheRect(scale) : this.AlignedCacheRect(scale);
263
+ return this.cacheDirty || !o || o.Type !== cacheType || o.Epoch !== (this.Superview?.GpuEpoch ?? 0) || o.Scale !== scale
264
+ || Math.round(o.Bounds.Width) !== Math.round(r.Width) || Math.round(o.Bounds.Height) !== Math.round(r.Height);
265
+ }
266
+ /** Its rect grown by its effects margin, through the matrix it is drawn with, lies outside the canvas clip. */
267
+ OutsideClip(canvas, scale) {
268
+ const b = SkiaControl.MapRect(this.RenderTransformMatrix, this.ExpandedCacheRect(scale)), q = SkiaControl.rejectRect;
269
+ q[0] = b.Left;
270
+ q[1] = b.Top;
271
+ q[2] = b.Right;
272
+ q[3] = b.Bottom;
273
+ return canvas.quickReject(q);
274
+ }
176
275
  /** Drawn bounds in canvas pixels including transforms and effects margins (C# GetTransformedDirtyBounds). */
177
276
  GetTransformedDirtyBounds() {
178
277
  const r = this.ExpandedCacheRect(this.RenderingScale), m = this.RenderTransformMatrix;
@@ -191,6 +290,67 @@ export class SkiaControl {
191
290
  /** Consume every gesture that lands on this control so nothing below (z-order) receives it. */
192
291
  BlockGesturesBelow = false;
193
292
  LockChildrenGestures = "Disabled";
293
+ // ---- focus on a completed tap (drawnui-cross 6ap, C# CanBeFocused / LockFocus / SetFrameworkFocus) ----
294
+ /**
295
+ * A tap this control takes moves the canvas focus to it, and whatever had it (an editor) lets it go. Default false: a
296
+ * plain control declines the focus, so tapping it (a Send button) leaves the current focus alone.
297
+ */
298
+ CanBeFocused = false;
299
+ /** While this control has the canvas focus, taps elsewhere do not move it. */
300
+ LockFocus = false;
301
+ /** The canvas gives (true) or takes (false) the focus; returns whether the control takes it. */
302
+ SetFrameworkFocus(_focus) { return this.CanBeFocused; }
303
+ // ---- hover (drawnui-cross 6m, C# ReceivesHover / IsHovered / HoverChanged) ----
304
+ receivesHover;
305
+ /**
306
+ * Whether this control takes mouse hover: the canvas sets IsHovered while the mouse is over it. Opt-in: false by
307
+ * default, true by default only in the controls that always had hover (SkiaButton, SkiaSlider, the toggles,
308
+ * SkiaRadioButton, SkiaCarousel, SkiaDrawer), never because a control has a tap handler. A HoverChanged handler turns
309
+ * it on (C# fluent OnHovered) unless it is set.
310
+ */
311
+ get ReceivesHover() { return this.receivesHover ?? (this.HoverChanged ? true : this.ReceivesHoverByDefault()); }
312
+ set ReceivesHover(value) { this.receivesHover = value; }
313
+ /** The value of ReceivesHover until it is set. */
314
+ ReceivesHoverByDefault() { return false; }
315
+ isHovered = false;
316
+ /**
317
+ * True while the mouse is over this control and it takes hover. Every such control under the pointer is hovered at
318
+ * once (a card and the button inside it, as CSS :hover); it stays as it is while content moves under the pointer and
319
+ * is checked again when that stops. Touch never hovers.
320
+ */
321
+ get IsHovered() { return this.isHovered; }
322
+ /** IsHovered changed: true when the mouse came over this control, false when it left (C# HoverChanged / OnHovered). */
323
+ HoverChanged;
324
+ /** Set by the canvas's HoverManager. */
325
+ ApplyHover(on) {
326
+ if (this.isHovered === on)
327
+ return;
328
+ this.isHovered = on;
329
+ this.HoverChanged?.(this, on);
330
+ }
331
+ /** A scroll, carousel or drawer moving its content right now: hover waits until it stops (C# IsScrolling / InTransition). */
332
+ MovesContent() { return false; }
333
+ /**
334
+ * Hover hit path (HoverManager): this control is under the point (in its own space), its children under it follow,
335
+ * top-most first, by the routing rules of ProcessGestures. True when this subtree blocks gestures below it, so the
336
+ * controls under it get no hover (a popup over a list).
337
+ */
338
+ CollectHovered(point, into, xs, ys) {
339
+ into.push(this);
340
+ xs?.push(point.X);
341
+ ys?.push(point.Y);
342
+ if (!this.CheckChildrenGesturesLocked("Pointer")) {
343
+ const listeners = this.GetGestureListeners();
344
+ for (let i = listeners.length - 1; i >= 0; i--) {
345
+ const child = listeners[i];
346
+ if (!child.IsVisible || child.InputTransparent || !this.IsGestureForChild(child, point))
347
+ continue;
348
+ if (child.CollectHovered(child.TransformPointToLocalSpace(point), into, xs, ys))
349
+ return true;
350
+ }
351
+ }
352
+ return this.BlockGesturesBelow;
353
+ }
194
354
  // ---- touch feedback (same names as DrawnUi) ----
195
355
  TouchEffectColor = Colors.White;
196
356
  /** Plays a ripple (from the tap point) when Tapped fires. */
@@ -199,6 +359,11 @@ export class SkiaControl {
199
359
  AnimationTappedSpeed = 0;
200
360
  /** Overlay effects drawn above this control's content every frame (ripple etc). */
201
361
  PostAnimators = [];
362
+ /**
363
+ * C# PendingUnattachedAnimators: animators started while no Canvas was above this control yet (e.g. a game loop
364
+ * started in a constructor). They start on the control's first arrange, where C# starts them in SuperViewChanged.
365
+ */
366
+ PendingUnattachedAnimators;
202
367
  // ---- visual effects (C# VisualEffects: attached SkiaEffect objects) ----
203
368
  visualEffects = [];
204
369
  /** Post-renderer effects among VisualEffects (C# EffectPostRenderers). */
@@ -230,10 +395,27 @@ export class SkiaControl {
230
395
  return [];
231
396
  return this.EffectPostRenderers.filter((e) => e.NeedApply);
232
397
  }
233
- /** C# CachedImage: the cached texture and the canvas rect it was rasterized over (Image caches only). */
398
+ /**
399
+ * C# CachedImage: the cached texture (Image caches only) and the canvas rect it covers NOW. Scrolled content is
400
+ * re-arranged here, not drawn through a translated canvas, so a cache recorded before its control moved is blitted
401
+ * at the control's current aligned rect (RenderContent) and its record-time Bounds are stale: an effect sampling it
402
+ * there (the slides of a SkiaShaderCarousel after the page scrolled) was off by the scroll amount.
403
+ */
234
404
  get CachedImage() {
235
405
  const c = this.RenderObject;
236
- return c?.Image ? { Image: c.Image, Bounds: c.Bounds } : undefined;
406
+ if (!c)
407
+ return undefined;
408
+ if (c.Image) {
409
+ const r = this.AlignedCacheRect(c.Scale);
410
+ return { Image: c.Image, Bounds: SKRect.Create(r.Left, r.Top, c.Bounds.Width, c.Bounds.Height) };
411
+ }
412
+ // a picture cache: its picture drawn into an image (made in RenderContent), so effects work on this control's
413
+ // content instead of a snapshot of what is behind it (C# caa1c8c1)
414
+ const image = c.PictureImage;
415
+ if (!image)
416
+ return undefined;
417
+ const r = this.ExpandedCacheRect(c.Scale);
418
+ return { Image: image, Bounds: SKRect.Create(r.Left, r.Top, image.width(), image.height()) };
237
419
  }
238
420
  /** Clip overlay effects to the control's shape (CreateClip). */
239
421
  ClipEffects = true;
@@ -262,6 +444,11 @@ export class SkiaControl {
262
444
  if (!SkiaStyles.IsEmpty)
263
445
  SkiaStyles.Apply(this, atConstruction);
264
446
  }
447
+ /**
448
+ * C# IsChildrenItem: added by the app (JSX children or the `Children` list), not a part the control made itself. A new
449
+ * `Children` list drops only these, so a control's own parts keep their place.
450
+ */
451
+ IsChildrenItem = false;
265
452
  AddSubView(_control) { throw new Error(`DrawnUi: ${this.constructor.name} cannot host children`); }
266
453
  InsertSubView(_index, control) { this.AddSubView(control); }
267
454
  RemoveSubView(_control) { }
@@ -272,6 +459,14 @@ export class SkiaControl {
272
459
  }
273
460
  // ---- state (pixels) ----
274
461
  MeasuredSize = ScaledSize.Default;
462
+ /**
463
+ * The size the control's content needs, in pixels with its margins, after the last measure: as MeasuredSize but a Fill
464
+ * axis keeps the content's size instead of taking the whole constraint (fit-content: requests, min / max applied). A
465
+ * stack that sizes itself to its children on the cross axis reads it (drawnui-cross 6an).
466
+ */
467
+ FitPixels = { Width: 0, Height: 0 };
468
+ /** Set by MeasureAbsolute when the content's fit size differs from the size it returns (a layout with Fill children). */
469
+ fitContentPixels;
275
470
  DrawingRect = SKRect.Empty;
276
471
  RenderingScale = 1;
277
472
  NeedMeasure = true;
@@ -320,6 +515,7 @@ export class SkiaControl {
320
515
  locked = true;
321
516
  }
322
517
  }
518
+ this.fitContentPixels = undefined;
323
519
  const content = this.MeasureAbsolute(w, h, scale);
324
520
  let rw = locked || reqW >= 0 ? w : this.HorizontalOptions === "Fill" && isFinite(w) ? w : content.Pixels.Width;
325
521
  let rh = locked || reqH >= 0 ? h : this.VerticalOptions === "Fill" && isFinite(h) ? h : content.Pixels.Height;
@@ -332,6 +528,19 @@ export class SkiaControl {
332
528
  if (this.MaximumHeightRequest >= 0 && reqH < 0)
333
529
  rh = Math.min(rh, this.MaximumHeightRequest * scale);
334
530
  this.MeasuredSize = ScaledSize.FromPixels(rw + mx, rh + my, scale);
531
+ // fit-content: what the content needs (never more than the constraint), with the requests and min / max
532
+ const fit = this.fitContentPixels ?? { Width: content.Pixels.Width, Height: content.Pixels.Height };
533
+ let fw = locked || reqW >= 0 ? w : Math.min(fit.Width, isFinite(w) ? w : fit.Width);
534
+ let fh = locked || reqH >= 0 ? h : Math.min(fit.Height, isFinite(h) ? h : fit.Height);
535
+ if (this.MinimumWidthRequest >= 0)
536
+ fw = Math.max(fw, this.MinimumWidthRequest * scale);
537
+ if (this.MinimumHeightRequest >= 0)
538
+ fh = Math.max(fh, this.MinimumHeightRequest * scale);
539
+ if (this.MaximumWidthRequest >= 0 && reqW < 0)
540
+ fw = Math.min(fw, this.MaximumWidthRequest * scale);
541
+ if (this.MaximumHeightRequest >= 0 && reqH < 0)
542
+ fh = Math.min(fh, this.MaximumHeightRequest * scale);
543
+ this.FitPixels = { Width: fw + mx, Height: fh + my };
335
544
  this.NeedMeasure = false;
336
545
  return this.MeasuredSize;
337
546
  }
@@ -361,12 +570,37 @@ export class SkiaControl {
361
570
  const fullW = destination.Width - m.HorizontalThickness * scale, fullH = destination.Height - m.VerticalThickness * scale;
362
571
  const x = availL + SkiaControl.Align(this.HorizontalOptions, fullW, w);
363
572
  const y = availT + SkiaControl.Align(this.VerticalOptions, fullH, h);
573
+ const old = this.DrawingRect;
364
574
  this.DrawingRect = SKRect.Create(x, y, w, h);
575
+ this.FollowMatrix(old);
365
576
  this.OnLayoutChanged();
577
+ if (this.PendingUnattachedAnimators)
578
+ this.StartPendingAnimators();
366
579
  // DrawnUi OnLayoutReady: an accessible control registers itself on its first layout
367
580
  if (!this.registeredWithAccessibility && this.IsAccessibilityElement)
368
581
  this.NotifyAccessibility();
369
582
  }
583
+ /**
584
+ * A cached ancestor replays its picture where a re-arrange moved it (a scroll) without rendering this control again,
585
+ * so the matrix made at its last Render moves with its rect: taps, hover and the accessibility rect stay on what is
586
+ * drawn (C# offsets the cached render tree instead). A control that renders again gets a fresh matrix there.
587
+ */
588
+ FollowMatrix(old) {
589
+ const m = this.RenderTransformMatrix, r = this.DrawingRect;
590
+ if (!m || (old.Left === r.Left && old.Top === r.Top))
591
+ return;
592
+ const M = Super.CK.Matrix, dx = r.Left - old.Left, dy = r.Top - old.Top;
593
+ this.RenderTransformMatrix = M.multiply(M.translated(dx, dy), m, M.translated(-dx, -dy));
594
+ }
595
+ /** C# SuperViewChanged: starts the animators queued before this control was attached. */
596
+ StartPendingAnimators() {
597
+ if (!this.Superview)
598
+ return;
599
+ const pending = this.PendingUnattachedAnimators;
600
+ this.PendingUnattachedAnimators = undefined;
601
+ for (const animator of pending)
602
+ animator.Start();
603
+ }
370
604
  // ---- accessibility (DrawnUi ISkiaAccessibilityNode) ----
371
605
  static nextAccessibilityId = 1;
372
606
  /** Stable identity for the DOM overlay. */
@@ -382,11 +616,39 @@ export class SkiaControl {
382
616
  * ARIA role; setting it exposes the control to assistive technology (use `Aria` constants). Unset = the class
383
617
  * default (`SkiaLabel.DefaultAccessibilityRole` etc.), which is itself unset unless the app opts in.
384
618
  */
385
- get AccessibilityRole() { return this.accessibilityRole ?? this.constructor.DefaultAccessibilityRole; }
619
+ get AccessibilityRole() {
620
+ return this.accessibilityRole ?? (this.accessibilityModal ? Aria.RoleDialog : this.constructor.DefaultAccessibilityRole);
621
+ }
386
622
  set AccessibilityRole(v) { if (this.accessibilityRole !== v) {
387
623
  this.accessibilityRole = v;
388
624
  this.AccessibilityChanged();
389
625
  } }
626
+ /**
627
+ * On an arrow-key group (a container with a composite role such as `Aria.RoleMenu` or `Aria.RoleList`): the arrows go
628
+ * round, from the last item to the first and back, instead of stopping at the ends, as in desktop menus. Home / End
629
+ * unchanged. Default false (C# KeyboardWrap, Rust keyboard_wrap).
630
+ */
631
+ KeyboardWrap = false;
632
+ accessibilityModal = false;
633
+ /**
634
+ * A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
635
+ * screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
636
+ * until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
637
+ * keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
638
+ * of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
639
+ */
640
+ get AccessibilityModal() { return this.accessibilityModal; }
641
+ set AccessibilityModal(v) {
642
+ if (this.accessibilityModal === v)
643
+ return;
644
+ this.accessibilityModal = v;
645
+ if (v)
646
+ AccessibilityModals.add(this);
647
+ else
648
+ AccessibilityModals.delete(this);
649
+ this.AccessibilityChanged();
650
+ this.Superview?.Update();
651
+ }
390
652
  /** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
391
653
  static DefaultAccessibilityRole;
392
654
  /** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
@@ -401,8 +663,35 @@ export class SkiaControl {
401
663
  this.accessibilityHint = v;
402
664
  this.AccessibilityChanged();
403
665
  } }
404
- /** Tab stop + activation; unset = true when the control handles Tapped. */
405
- get AccessibilityCanInteract() { return this.accessibilityCanInteract ?? this.DefaultAccessibilityCanInteract(); }
666
+ /** Text of the tooltip shown when the mouse rests on the control (drawnui-cross 6ar); undefined = none. */
667
+ Tooltip;
668
+ /** The control may have tooltip text: the cheap check made on every mouse move. */
669
+ get MayHaveTooltip() {
670
+ return !!this.Tooltip || (Super.TooltipsFromAccessibility && (this.accessibilityHint != null || this.accessibilityLabel != null));
671
+ }
672
+ /**
673
+ * The text of this control's tooltip, undefined for none: `Tooltip`, else with `Super.TooltipsFromAccessibility` its
674
+ * `AccessibilityHint`, else its own `AccessibilityLabel` when it shows no text of its own (icon buttons).
675
+ */
676
+ GetTooltipText() {
677
+ if (this.Tooltip)
678
+ return this.Tooltip;
679
+ if (!Super.TooltipsFromAccessibility)
680
+ return undefined;
681
+ if (this.accessibilityHint)
682
+ return this.accessibilityHint;
683
+ if (this.accessibilityLabel && !this.ShowsText())
684
+ return this.accessibilityLabel;
685
+ return undefined;
686
+ }
687
+ /** The control shows text of its own (a label with text, spans included, inside it). */
688
+ ShowsText() { return false; }
689
+ /**
690
+ * Whether keyboard navigation and assistive technology may focus and use this node: the explicit value, else the class
691
+ * default (true when the control handles Tapped), and in both cases only while a tap could reach the control
692
+ * (CanReceiveGesture), so Tab, Enter / Space and screen-reader activation never use a control the pointer cannot.
693
+ */
694
+ get AccessibilityCanInteract() { return (this.accessibilityCanInteract ?? this.DefaultAccessibilityCanInteract()) && this.CanReceiveGesture("Tapped"); }
406
695
  set AccessibilityCanInteract(v) { if (this.accessibilityCanInteract !== v) {
407
696
  this.accessibilityCanInteract = v;
408
697
  this.AccessibilityChanged();
@@ -413,12 +702,21 @@ export class SkiaControl {
413
702
  * host's pointer cursor. Default: the control as a whole (AccessibilityCanInteract); SkiaLabel adds its tappable spans.
414
703
  */
415
704
  WantsPointerCursor(_x, _y) { return this.AccessibilityCanInteract; }
705
+ /** A range control's value for screen readers (slider, progress); undefined for everything else (drawnui-cross 6c). */
706
+ get AccessibilityValue() { return undefined; }
416
707
  /** aria-pressed for toggles; undefined = not a toggle. */
417
708
  get AccessibilityIsPressed() { return this.accessibilityIsPressed; }
418
709
  set AccessibilityIsPressed(v) { if (this.accessibilityIsPressed !== v) {
419
710
  this.accessibilityIsPressed = v;
420
711
  this.AccessibilityChanged();
421
712
  } }
713
+ accessibilityExpanded;
714
+ /** A control that opens something, such as a menu title: whether it is open now (aria-expanded). Unset: it opens nothing. */
715
+ get AccessibilityExpanded() { return this.accessibilityExpanded; }
716
+ set AccessibilityExpanded(v) { if (this.accessibilityExpanded !== v) {
717
+ this.accessibilityExpanded = v;
718
+ this.AccessibilityChanged();
719
+ } }
422
720
  /** aria-live: `Aria.LivePolite` / `Aria.LiveAssertive`; changes are announced immediately. */
423
721
  get AccessibilityLive() { return this.accessibilityLive; }
424
722
  set AccessibilityLive(v) { if (this.accessibilityLive !== v) {
@@ -487,6 +785,39 @@ export class SkiaControl {
487
785
  }
488
786
  /** Overlay focus arrives on / leaves this node (inputs may activate their sink here). */
489
787
  OnAccessibilityFocused(_focused) { }
788
+ /**
789
+ * Keyboard navigation hands this control the keys it may use while it holds keyboard focus (ArrowLeft / Right / Up /
790
+ * Down, Home, End, PageUp, PageDown, DOM `event.code` names). Return true when the key was used; the default uses none,
791
+ * so the key moves focus inside the arrow-key group around the control.
792
+ */
793
+ OnAccessibilityKey(_key) { return false; }
794
+ /**
795
+ * Whether a pointer gesture of this kind would reach this control, by the rules the gesture dispatch applies: the
796
+ * control and every ancestor draw, none of them is InputTransparent, no ancestor keeps this gesture from its children
797
+ * (LockChildrenGestures, PassNone included) and the control accepts input (AcceptsInput). Opacity does not count, as
798
+ * for the pointer. Keyboard navigation uses it: Tapped for Tab and Enter / Space, Panning for the arrow keys.
799
+ */
800
+ CanReceiveGesture(gesture) {
801
+ if (!this.IsVisible || this.IsDisposed || this.InputTransparent || !this.AcceptsInput())
802
+ return false;
803
+ for (let p = this.Parent; p; p = p.Parent)
804
+ if (!p.IsVisible || p.IsDisposed || p.InputTransparent || p.CheckChildrenGesturesLocked(gesture))
805
+ return false;
806
+ return true;
807
+ }
808
+ /**
809
+ * False while the control ignores input itself: RespondsToGestures = false on a button, toggle, slider, scroll...
810
+ * Taps, keyboard and the accessibility state (reported disabled) all follow it (drawnui-cross 6w). Default true.
811
+ */
812
+ AcceptsInput() { return true; }
813
+ /**
814
+ * What a control that takes no input returns for a gesture that reached it (C# BlockedGestureResult): it keeps a
815
+ * press, tap or long press, so nothing under it reacts to them, and lets moves and wheel go on to the controls around
816
+ * it (a scroll behind it still scrolls).
817
+ */
818
+ BlockedGestureResult(args) {
819
+ return args.Type === "Down" || args.Type === "Tapped" || args.Type === "LongPressing" ? this : null;
820
+ }
490
821
  NotifyAccessibilityFocused(focused) { this.Superview?.AccessibilityManager.NotifyFocused(focused ? this : undefined); }
491
822
  /** DrawnUi SmartMax: larger of two sizes, an infinite one loses. */
492
823
  static SmartMax(a, b) {
@@ -509,6 +840,8 @@ export class SkiaControl {
509
840
  }
510
841
  /** Called after DrawingRect changed; layouts arrange children here. */
511
842
  OnLayoutChanged() { }
843
+ /** A control in CanvasLeaveWatchers left its canvas (removed or disposed): it lets go of what it held there. */
844
+ OnLeftCanvas() { }
512
845
  /** Part of DrawingRect that can actually be seen: intersected with every ancestor (a scroll's box clips its content). */
513
846
  GetVisibleViewport() {
514
847
  const r = this.DrawingRect;
@@ -552,8 +885,25 @@ export class SkiaControl {
552
885
  const applyOpacity = this.Opacity < 1;
553
886
  // C# Left/Top: a cached control is blitted at an offset, no matrix and no save/restore around the subtree
554
887
  const offsetOnly = (this.Left !== 0 || this.Top !== 0) && this.UsingCacheType !== "None" && this.TranslationX === 0 && this.TranslationY === 0
555
- && this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0;
888
+ && this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0 && !this.Has3d;
556
889
  const needTransform = this.HasTransform && !offsetOnly;
890
+ let dx = 0, dy = 0;
891
+ if (needTransform) {
892
+ this.RenderTransformMatrix = this.CreateRenderTransformMatrix(this.DrawingRect, ctx.Scale);
893
+ }
894
+ else if (offsetOnly) {
895
+ dx = this.Left * ctx.Scale;
896
+ dy = this.Top * ctx.Scale;
897
+ this.RenderTransformMatrix = Super.CK.Matrix.translated(dx, dy); // gestures / accessibility still map through it
898
+ }
899
+ else {
900
+ this.RenderTransformMatrix = undefined;
901
+ }
902
+ // drawn entirely outside the clip: skipped with its subtree (C# layout Virtualisation, DrawnUi.Rust); the matrix
903
+ // above stays current for hit tests. A cache that must be recorded is still recorded here, as before, so its cost
904
+ // does not move into the frame where the control scrolls in (DrawnUi.Rust records it then)
905
+ if (this.OutsideClip(canvas, ctx.Scale) && !this.CacheStale(ctx.Scale))
906
+ return;
557
907
  let saved = false;
558
908
  // same as DrawnUi: opacity = a layer with alpha, transforms = canvas matrix around the whole subtree (cache included)
559
909
  if (applyOpacity) {
@@ -567,19 +917,8 @@ export class SkiaControl {
567
917
  canvas.save();
568
918
  saved = true;
569
919
  }
570
- let dx = 0, dy = 0;
571
- if (needTransform) {
572
- this.RenderTransformMatrix = this.CreateRenderTransformMatrix(this.DrawingRect, ctx.Scale);
920
+ if (needTransform)
573
921
  canvas.concat(this.RenderTransformMatrix);
574
- }
575
- else if (offsetOnly) {
576
- dx = this.Left * ctx.Scale;
577
- dy = this.Top * ctx.Scale;
578
- this.RenderTransformMatrix = Super.CK.Matrix.translated(dx, dy); // gestures / accessibility still map through it
579
- }
580
- else {
581
- this.RenderTransformMatrix = undefined;
582
- }
583
922
  if (this.IsClippedToBounds) {
584
923
  if (!saved) {
585
924
  canvas.save();
@@ -592,11 +931,12 @@ export class SkiaControl {
592
931
  if (saved)
593
932
  canvas.restore();
594
933
  }
595
- /** Port of DrawnUi ApplyTransforms: T(-pivot) · rotation · scale/skew · T(pivot) · translation, in canvas pixels. */
934
+ /** Port of DrawnUi ApplyTransforms: T(-pivot) · rotation · scale/skew · 3D · T(pivot) · translation, in canvas pixels. */
596
935
  CreateRenderTransformMatrix(destination, scale) {
597
936
  const M = Super.CK.Matrix;
598
937
  const moveX = (this.TranslationX + this.Left) * scale, moveY = (this.TranslationY + this.Top) * scale;
599
- if (this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0)
938
+ const has3d = this.Has3d;
939
+ if (this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0 && !has3d)
600
940
  return M.translated(moveX, moveY);
601
941
  const px = destination.Left + destination.Width * this.AnchorX;
602
942
  const py = destination.Top + destination.Height * this.AnchorY;
@@ -605,7 +945,36 @@ export class SkiaControl {
605
945
  const scaleSkew = [this.ScaleX, kx, 0, ky, this.ScaleY, 0, 0, 0, 1];
606
946
  const rotation = this.Rotation !== 0 ? M.rotated((Math.PI * this.Rotation) / 180) : M.identity();
607
947
  // multiply(a, b, c) = a·b·c, the right-most applies first
608
- return M.multiply(M.translated(px + moveX, py + moveY), scaleSkew, rotation, M.translated(-px, -py));
948
+ if (!has3d)
949
+ return M.multiply(M.translated(px + moveX, py + moveY), scaleSkew, rotation, M.translated(-px, -py));
950
+ return M.multiply(M.translated(px + moveX, py + moveY), SkiaControl.Create3dMatrix(this.RotationX, this.RotationY, this.RotationZ, this.TranslationZ), scaleSkew, rotation, M.translated(-px, -py));
951
+ }
952
+ /** C# camera distance of the 3D transforms (Sk3dView.CameraDistance): 8 inches at 72 dpi, in canvas pixels. */
953
+ static CameraDistance = 576;
954
+ /**
955
+ * C# Create3dMatrix (Sk3dView): RotationX, then RotationY, then RotationZ (negated) around the pivot, projected from
956
+ * the camera; TranslationZ is depth, a flat control at depth z draws at camera / (camera − z).
957
+ */
958
+ static Create3dMatrix(rotationX, rotationY, rotationZ, translationZ) {
959
+ const d = Math.PI / 180, camera = SkiaControl.CameraDistance;
960
+ const sx = Math.sin(rotationX * d), cx = Math.cos(rotationX * d), sy = Math.sin(rotationY * d), cy = Math.cos(rotationY * d);
961
+ const sz = Math.sin(-rotationZ * d), cz = Math.cos(-rotationZ * d);
962
+ return [
963
+ cy * cz, cy * sz, 0,
964
+ sx * sy * cz - cx * sz, sx * sy * sz + cx * cz, 0,
965
+ (cx * sy * cz + sx * sz) / camera, (cx * sy * sz - sx * cz) / camera, Math.max(camera - translationZ, 1) / camera,
966
+ ];
967
+ }
968
+ /** C# SkiaSamplingOptions.IsMoveOnly: the matrix only moves (or mirrors), so a bitmap keeps its pixels 1:1. */
969
+ static IsMoveOnly(m) {
970
+ return m[1] === 0 && m[3] === 0 && m[6] === 0 && m[7] === 0 && m[8] === 1 && Math.abs(m[0]) === 1 && Math.abs(m[4]) === 1;
971
+ }
972
+ /**
973
+ * C# WillDrawDistorted: what this control draws here ends up scaled, turned, skewed or projected, by its own transforms
974
+ * or a live ancestor's (both in the canvas matrix) or by the picture it is recorded into. Images then sample smoothly.
975
+ */
976
+ WillDrawDistorted(ctx) {
977
+ return !!ctx.Context.PlaybackDistorted || !SkiaControl.IsMoveOnly(ctx.Context.Canvas.getTotalMatrix());
609
978
  }
610
979
  /** Maps a point given in the parent's space into this control's untransformed space (DrawnUi TransformPointToLocalSpace). */
611
980
  TransformPointToLocalSpace(point) {
@@ -641,26 +1010,39 @@ export class SkiaControl {
641
1010
  }
642
1011
  else {
643
1012
  const r = cacheType === "Operations" ? this.ExpandedCacheRect(ctx.Scale) : this.AlignedCacheRect(ctx.Scale);
644
- const stale = this.cacheDirty || !this.RenderObject || this.RenderObject.Type !== cacheType
645
- || this.RenderObject.Scale !== ctx.Scale
646
- || Math.round(this.RenderObject.Bounds.Width) !== Math.round(r.Width) || Math.round(this.RenderObject.Bounds.Height) !== Math.round(r.Height);
647
- if (stale)
1013
+ const epoch = this.Superview?.GpuEpoch ?? 0;
1014
+ if (this.RenderObjectPrevious && this.RenderObjectPrevious.Epoch !== epoch)
1015
+ this.DisposePrevious(); // made on a lost GPU context
1016
+ // a picture replays its image blits with the sampling chosen when it was recorded: recorded again once its
1017
+ // playback turns distorted or straight (C# SamplingMismatch), else a cached child of a turning card stays jagged
1018
+ const o = this.RenderObject;
1019
+ if (this.CacheStale(ctx.Scale) || (o?.Picture && o.HasImageBlits && o.PlaybackDistorted !== this.WillDrawDistorted(ctx)))
648
1020
  this.CreateRenderingObject({ ...ctx, Destination: this.DrawingRect }, cacheType);
649
1021
  if (this.RenderObject) {
650
- // C# DrawRenderObject: with post renderers an Image cache is not blitted, the effects sample it (CachedImage)
651
- // and paint the result; a picture cache has no texture, so it is replayed first and snapshotted by the effect
652
- if (post.length === 0 || !this.RenderObject.Image)
653
- this.RenderObject.Draw(ctx.Context.Canvas, r.Left + dx, r.Top + dy);
1022
+ // C# DrawRenderObject: with post renderers a cache is not blitted, the effects sample it (CachedImage) and paint
1023
+ // the result, so the shader replaces the control; a picture cache hands them its picture drawn into an image
1024
+ // (made once per cache, C# GetPictureImage); drawn as before only when that image could not be made
1025
+ const cache = this.RenderObject;
1026
+ if (post.length > 0 && cache.Picture)
1027
+ cache.GetPictureImage(ctx.Context.Surface);
1028
+ if (post.length === 0 || !(cache.Image ?? cache.PictureImage))
1029
+ this.DrawCache(cache, ctx, r.Left + dx, r.Top + dy);
654
1030
  for (const e of post)
655
1031
  e.Render(own);
656
1032
  }
657
1033
  else if (this.RenderObjectPrevious)
658
- this.RenderObjectPrevious.Draw(ctx.Context.Canvas, r.Left + dx, r.Top + dy); // double buffer: last good frame
1034
+ this.DrawCache(this.RenderObjectPrevious, ctx, r.Left + dx, r.Top + dy); // double buffer: last good frame
659
1035
  else
660
1036
  this.DrawPlaceholder(own);
661
1037
  }
662
1038
  this.ExecutePostAnimators(own);
663
1039
  }
1040
+ /** Blits a cache: an image samples smoothly when drawn distorted; a picture being recorded learns it holds image blits. */
1041
+ DrawCache(cache, ctx, left, top) {
1042
+ if (cache.Image || cache.HasImageBlits)
1043
+ ctx.Context.HasImageBlits = true;
1044
+ cache.Draw(ctx.Context.Canvas, left, top, !!cache.Image && this.WillDrawDistorted(ctx));
1045
+ }
664
1046
  /** Background + Paint(): the part of the control that a cache captures. */
665
1047
  PaintContent(ctx) {
666
1048
  if (this.BackgroundColor || (this.FillGradient && this.FillGradientPaintsBackground()) || this.PaintsBackgroundWithoutColor())
@@ -695,11 +1077,16 @@ export class SkiaControl {
695
1077
  }
696
1078
  if (cacheType === "Operations") {
697
1079
  const recorder = new CK.PictureRecorder();
1080
+ const playbackDistorted = this.WillDrawDistorted(ctx);
698
1081
  const canvas = recorder.beginRecording(CK.LTRBRect(r.Left, r.Top, r.Right, r.Bottom));
699
- this.PaintContent({ ...ctx, Context: { ...ctx.Context, Canvas: canvas, Recording: true } });
1082
+ const recording = { ...ctx.Context, Canvas: canvas, Recording: true, PlaybackDistorted: playbackDistorted, HasImageBlits: false };
1083
+ this.PaintContent({ ...ctx, Context: recording });
700
1084
  const picture = recorder.finishRecordingAsPicture();
701
1085
  recorder.delete();
702
1086
  this.RenderObject = new CachedObject("Operations", r, ctx.Scale, picture);
1087
+ this.RenderObject.Epoch = this.Superview?.GpuEpoch ?? 0;
1088
+ this.RenderObject.PlaybackDistorted = playbackDistorted;
1089
+ this.RenderObject.HasImageBlits = recording.HasImageBlits;
703
1090
  }
704
1091
  else if (cacheType === "ImageComposite") {
705
1092
  this.CreateCompositeRenderingObject(ctx, r, w, h);
@@ -723,6 +1110,7 @@ export class SkiaControl {
723
1110
  const image = offscreen.makeImageSnapshot();
724
1111
  offscreen.delete();
725
1112
  this.RenderObject = new CachedObject(cacheType, r, ctx.Scale, undefined, image);
1113
+ this.RenderObject.Epoch = this.Superview?.GpuEpoch ?? 0;
726
1114
  }
727
1115
  this.cacheDirty = false;
728
1116
  }
@@ -741,7 +1129,9 @@ export class SkiaControl {
741
1129
  }
742
1130
  let surface = this.compositeSurface;
743
1131
  const prev = this.RenderObject;
744
- const sameGeometry = !!surface && !!prev && prev.Type === "ImageComposite" && prev.Scale === ctx.Scale
1132
+ const epoch = this.Superview?.GpuEpoch ?? 0;
1133
+ // the kept surface belongs to the GPU context it was made on: after a context restore it is made again
1134
+ const sameGeometry = !!surface && !!prev && prev.Type === "ImageComposite" && prev.Scale === ctx.Scale && prev.Epoch === epoch
745
1135
  && Math.round(prev.Bounds.Width) === w && Math.round(prev.Bounds.Height) === h;
746
1136
  if (!sameGeometry) {
747
1137
  surface?.delete();
@@ -754,14 +1144,46 @@ export class SkiaControl {
754
1144
  }
755
1145
  const canvas = surface.getCanvas();
756
1146
  const children = this.GetCompositeChildren();
757
- const partial = sameGeometry && !this.compositeFull && this.DirtyChildrenInternal.size > 0 && children.length > 0;
1147
+ const deep = this.compositeDeep;
1148
+ // the same size with another effects margin moves the content inside the surface: record whole (C# 97683f19)
1149
+ const insetX = r.Left - this.DrawingRect.Left, insetY = r.Top - this.DrawingRect.Top;
1150
+ const sameInset = insetX === this.compositeInsetX && insetY === this.compositeInsetY;
1151
+ this.compositeInsetX = insetX;
1152
+ this.compositeInsetY = insetY;
1153
+ let partial = sameGeometry && sameInset && !this.compositeFull && children.length > 0 && (this.DirtyChildrenInternal.size > 0 || !!deep?.length);
1154
+ // changes deeper than a child: only their areas, the child they are in drawn clipped to them (drawnui-cross 6m)
1155
+ const areas = [], changed = [], inside = new Set();
1156
+ if (partial && deep?.length) {
1157
+ let covered = 0;
1158
+ for (const d of deep) {
1159
+ if (!children.includes(d.Child) || this.DirtyChildrenInternal.has(d.Child))
1160
+ continue;
1161
+ const area = SkiaControl.DeepArea(d, this, ctx.Scale);
1162
+ if (area === null) {
1163
+ partial = false;
1164
+ break;
1165
+ }
1166
+ if (!area) {
1167
+ this.DirtyChildrenInternal.add(d.Child);
1168
+ continue;
1169
+ }
1170
+ areas.push(area);
1171
+ changed.push(d.Origin);
1172
+ inside.add(d.Child);
1173
+ covered += area.Width * area.Height;
1174
+ }
1175
+ if (areas.length > SkiaControl.MaxCompositionAreas || covered > r.Width * r.Height * SkiaControl.MaxCompositionShare)
1176
+ partial = false;
1177
+ }
1178
+ if (deep)
1179
+ deep.length = 0;
758
1180
  const offset = prev && sameGeometry ? { X: r.Left - prev.Bounds.Left, Y: r.Top - prev.Bounds.Top } : { X: 0, Y: 0 };
759
1181
  const saved = canvas.save();
760
1182
  canvas.translate(-r.Left, -r.Top);
761
1183
  if (partial) {
762
1184
  // dirty = reported children + siblings intersecting their old or new bounds (C# makes intersecting children dirty too)
763
1185
  const dirty = new Set();
764
- const rects = [];
1186
+ const rects = [...areas];
765
1187
  const boundsOf = (c) => {
766
1188
  const out = [c.GetTransformedDirtyBounds()];
767
1189
  if (c.lastCompositeBounds)
@@ -777,7 +1199,7 @@ export class SkiaControl {
777
1199
  while (grew) {
778
1200
  grew = false;
779
1201
  for (const c of children) {
780
- if (dirty.has(c) || !c.IsVisible)
1202
+ if (dirty.has(c) || inside.has(c) || !c.IsVisible)
781
1203
  continue;
782
1204
  const own = boundsOf(c);
783
1205
  if (rects.some((d) => own.some((o) => o.Left < d.Right && d.Left < o.Right && o.Top < d.Bottom && d.Top < o.Bottom))) {
@@ -804,14 +1226,18 @@ export class SkiaControl {
804
1226
  this.DirtyChildrenInternal.clear();
805
1227
  for (const c of dirty)
806
1228
  this.DirtyChildrenInternal.add(c);
1229
+ for (const c of inside)
1230
+ this.DirtyChildrenInternal.add(c);
1231
+ // children entirely outside the redrawn areas are skipped by their own clip check (Render)
807
1232
  this.PaintContent({ ...ctx, Context: { Canvas: canvas, Surface: surface, Origin: { X: r.Left, Y: r.Top } } });
808
1233
  this.IsRenderingWithComposition = false;
809
- this.LastCompositeRecord = { Mode: "partial", Children: dirty.size, Dirty: [...dirty] };
1234
+ const redrawn = children.filter((c) => this.DirtyChildrenInternal.has(c));
1235
+ this.LastCompositeRecord = { Mode: "partial", Children: redrawn.length, Dirty: redrawn, Areas: areas, Changed: changed };
810
1236
  }
811
1237
  else {
812
1238
  canvas.clear(CK.TRANSPARENT);
813
1239
  this.PaintContent({ ...ctx, Context: { Canvas: canvas, Surface: surface, Origin: { X: r.Left, Y: r.Top } } });
814
- this.LastCompositeRecord = { Mode: "full", Children: children.length, Dirty: children };
1240
+ this.LastCompositeRecord = { Mode: "full", Children: children.length, Dirty: children, Areas: [], Changed: [] };
815
1241
  }
816
1242
  canvas.restoreToCount(saved);
817
1243
  for (const c of children)
@@ -821,6 +1247,7 @@ export class SkiaControl {
821
1247
  const image = surface.makeImageSnapshot();
822
1248
  const old = this.RenderObject;
823
1249
  this.RenderObject = new CachedObject("ImageComposite", r, ctx.Scale, undefined, image);
1250
+ this.RenderObject.Epoch = epoch;
824
1251
  if (old) {
825
1252
  const sv = this.Superview;
826
1253
  if (sv)
@@ -856,7 +1283,11 @@ export class SkiaControl {
856
1283
  /** Marks the cache stale; re-recorded on the next frame (a composite records fully: its own content changed). */
857
1284
  InvalidateCache() { this.cacheDirty = true; this.compositeFull = true; }
858
1285
  /** Effects margin recomputed on the next use (C# InvalidateEffectsMargin). */
859
- InvalidateEffectsMargin() { this.effectsMarginCache = undefined; }
1286
+ InvalidateEffectsMargin() {
1287
+ // a layout's margin aggregates what its children paint outside it: every ancestor recomputes too (C# 97683f19)
1288
+ for (let c = this; c; c = c.Parent)
1289
+ c.effectsMarginCache = undefined;
1290
+ }
860
1291
  /** Draws PostAnimators above content; an effect returning true asks for another frame. */
861
1292
  ExecutePostAnimators(ctx) {
862
1293
  if (this.PostAnimators.length === 0)
@@ -989,9 +1420,16 @@ export class SkiaControl {
989
1420
  ey = 0;
990
1421
  return [sx, sy, ex, ey];
991
1422
  }
992
- /** C# MakeDarker / MakeLighter: HSL lightness scaled down (light < 1) or pushed toward white (light > 1). */
1423
+ /**
1424
+ * A gradient's Light: below 1 red, green and blue multiplied by Light (C# MakeDarker, as Rust); above 1 the HSL
1425
+ * lightness multiplied by Light, clamped to 1, hue and saturation kept (.NET MAUI Color.AddLuminosity, C# f77136c4).
1426
+ */
993
1427
  static AdjustLightness(rgb, light) {
994
1428
  const [r, g, b] = rgb;
1429
+ if (light < 1) {
1430
+ const k = Math.max(0, light);
1431
+ return [r * k, g * k, b * k];
1432
+ }
995
1433
  const max = Math.max(r, g, b), min = Math.min(r, g, b);
996
1434
  let h = 0, s = 0;
997
1435
  let l = (max + min) / 2;
@@ -1006,7 +1444,7 @@ export class SkiaControl {
1006
1444
  h = (r - g) / d + 4;
1007
1445
  h /= 6;
1008
1446
  }
1009
- l = light < 1 ? l * light : l + (1 - l) * (light - 1);
1447
+ l = l * light;
1010
1448
  l = Math.max(0, Math.min(1, l));
1011
1449
  if (s === 0)
1012
1450
  return [l, l, l];
@@ -1031,13 +1469,21 @@ export class SkiaControl {
1031
1469
  Dispose() {
1032
1470
  if (this.IsDisposed)
1033
1471
  return;
1472
+ // disposed while still on a canvas: its subtree's animators stop, once, from the top disposed control
1473
+ if (!this.Parent?.IsDisposed)
1474
+ this.Superview?.ControlLeft(this, true);
1034
1475
  this.IsDisposed = true;
1476
+ if (this.accessibilityModal)
1477
+ AccessibilityModals.delete(this);
1035
1478
  this.OnDisposing();
1036
1479
  for (const c of this.ownAnimations.values())
1037
1480
  c.abort();
1038
1481
  this.ownAnimations.clear();
1039
1482
  for (const e of [...this.PostAnimators])
1040
1483
  e.Stop?.();
1484
+ for (const a of [...(this.PendingUnattachedAnimators ?? [])])
1485
+ a.Stop(); // waiting since it was removed: they end with it
1486
+ this.PendingUnattachedAnimators = undefined;
1041
1487
  this.PostAnimators.length = 0;
1042
1488
  this.DestroyRenderingObject();
1043
1489
  this.compositeSurface?.delete();
@@ -1066,32 +1512,134 @@ export class SkiaControl {
1066
1512
  }
1067
1513
  /** Redraw without remeasure and WITHOUT dropping caches (position/overlay changes). */
1068
1514
  Repaint() {
1069
- this.Superview?.Update();
1515
+ if (!this.UnderHiddenParent())
1516
+ this.Superview?.Update();
1517
+ }
1518
+ /**
1519
+ * A parent (not the control itself) is hidden: a change here asks for no frame and the latest state shows when the
1520
+ * parent is shown again (C# 329f6c44 HiddenUpdateTests, DrawnUi.Rust hidden_updates). The control's own visibility
1521
+ * change still draws: it is the one that hides or shows it.
1522
+ */
1523
+ UnderHiddenParent() {
1524
+ for (let p = this.Parent; p; p = p.Parent)
1525
+ if (!p.IsVisible)
1526
+ return true;
1527
+ return false;
1070
1528
  }
1529
+ /** The control or a parent is hidden: its animators pause until it shows again. */
1530
+ HiddenInTree() { return !this.IsVisible || this.UnderHiddenParent(); }
1531
+ /** The control an invalidation started at while it climbs (InvalidateMeasure): a hidden parent of it wakes no frame. */
1532
+ static invalidateOrigin = null;
1071
1533
  /**
1072
1534
  * Transform / Opacity changed: this control's own cache is still valid (content unchanged) but every ancestor
1073
1535
  * cache holds its composited output, so those are staled before redrawing (DrawnUi RedrawCanvas + parent invalidation).
1074
1536
  */
1075
1537
  RepaintComposition() {
1076
- let child = this, p = this.Parent;
1077
- while (p) {
1538
+ this.ReportToComposites();
1539
+ for (let p = this.Parent; p; p = p.Parent)
1078
1540
  p.cacheDirty = true;
1079
- p.TrackChildAsDirty(child);
1080
- child = p;
1081
- p = p.Parent;
1082
- }
1083
1541
  this.Repaint();
1084
1542
  }
1543
+ /**
1544
+ * Update() for a change of how this control looks, not of its size (a color set through props, C# NeedDraw): the same
1545
+ * re-measure and cache invalidation, but an ImageComposite above redraws only this control's area instead of
1546
+ * recording whole (drawnui-cross 6m). The record still goes whole when the control's rect changed after all.
1547
+ */
1548
+ UpdateDraw() {
1549
+ this.ReportToComposites();
1550
+ const outer = SkiaControl.drawOrigin;
1551
+ SkiaControl.drawOrigin = this;
1552
+ try {
1553
+ this.InvalidateMeasure();
1554
+ }
1555
+ finally {
1556
+ SkiaControl.drawOrigin = outer;
1557
+ }
1558
+ }
1559
+ /**
1560
+ * A change of this control that keeps its layout, to every ImageComposite above: a direct child is drawn again whole
1561
+ * (C# TrackChildAsDirty), a deeper control by its area, read now as it was drawn (its last matrix and effects margin).
1562
+ */
1563
+ ReportToComposites() {
1564
+ let before;
1565
+ let child = this;
1566
+ for (let p = this.Parent; p; child = p, p = p.Parent) {
1567
+ if (!p.IsCacheComposite)
1568
+ continue;
1569
+ if (child === this) {
1570
+ p.TrackChildAsDirty(child);
1571
+ continue;
1572
+ }
1573
+ const deep = p.compositeDeep ??= [];
1574
+ if (deep.some((d) => d.Origin === this))
1575
+ continue;
1576
+ before ??= this.GetTransformedDirtyBounds();
1577
+ const r = this.DrawingRect;
1578
+ deep.push({ Origin: this, Child: child, Before: before, Rect: new SKRect(r.Left, r.Top, r.Right, r.Bottom) });
1579
+ }
1580
+ }
1581
+ /** The matrix this control will be drawn with (Render), from its current properties; undefined when none. */
1582
+ CurrentMatrix(scale) {
1583
+ return this.HasTransform ? this.CreateRenderTransformMatrix(this.DrawingRect, scale) : undefined;
1584
+ }
1585
+ /** Where this control will be drawn: its rect grown by its effects margin, through its current matrix. */
1586
+ DrawnBoundsNow(scale) { return SkiaControl.MapRect(this.CurrentMatrix(scale), this.ExpandedCacheRect(scale)); }
1587
+ static MapRect(m, r) {
1588
+ if (!m)
1589
+ return r;
1590
+ const pts = Super.CK.Matrix.mapPoints(m, [r.Left, r.Top, r.Right, r.Top, r.Right, r.Bottom, r.Left, r.Bottom]);
1591
+ return new SKRect(Math.min(pts[0], pts[2], pts[4], pts[6]), Math.min(pts[1], pts[3], pts[5], pts[7]), Math.max(pts[0], pts[2], pts[4], pts[6]), Math.max(pts[1], pts[3], pts[5], pts[7]));
1592
+ }
1593
+ /** Its output depends on all of its content (a visual effect; a backdrop samples below): a change inside redraws it whole. */
1594
+ get SamplesContent() { return !this.DisableEffects && this.visualEffects.length > 0; }
1595
+ /**
1596
+ * Where a deep change shows inside the composite (drawnui-cross 6m rule b): the control as drawn before and as drawn
1597
+ * now, then through the transform of every ancestor up to the composite. undefined: draw the child whole (an effect
1598
+ * or a backdrop on the way, the control gone from the child); null: the layout changed, record whole.
1599
+ */
1600
+ static DeepArea(d, composite, scale) {
1601
+ const o = d.Origin, r = o.DrawingRect;
1602
+ if (r.Left !== d.Rect.Left || r.Top !== d.Rect.Top || r.Right !== d.Rect.Right || r.Bottom !== d.Rect.Bottom)
1603
+ return null;
1604
+ if (!o.IsVisible)
1605
+ return undefined;
1606
+ const now = o.DrawnBoundsNow(scale);
1607
+ let area = new SKRect(Math.min(now.Left, d.Before.Left), Math.min(now.Top, d.Before.Top), Math.max(now.Right, d.Before.Right), Math.max(now.Bottom, d.Before.Bottom));
1608
+ let p = o.Parent, child = o;
1609
+ for (; p && p !== composite; child = p, p = p.Parent) {
1610
+ if (p.SamplesContent || !p.IsVisible)
1611
+ return undefined;
1612
+ area = SkiaControl.MapRect(p.CurrentMatrix(scale), area);
1613
+ }
1614
+ return p === composite && child === d.Child ? area : undefined;
1615
+ }
1616
+ /**
1617
+ * DrawnUi IsParentIndependent: this control's size never changes the layout around it, so its own invalidation
1618
+ * stops here (ancestors composite again, nothing above re-measures). The parent re-measures it on draw when
1619
+ * NeedMeasure is set. Used by SkiaScroll for its scroll bars.
1620
+ */
1621
+ IsParentIndependent = false;
1085
1622
  /** Size or content may have changed: this control and all ancestors remeasure and re-record. */
1086
1623
  InvalidateMeasure() {
1087
1624
  this.NeedMeasure = true;
1088
1625
  this.cacheDirty = true;
1089
- this.compositeFull = true; // structure may change: a composite cannot patch it
1626
+ // structure may change: a composite cannot patch it; a draw-only change (UpdateDraw) reported its area instead
1627
+ if (SkiaControl.drawOrigin === null || SkiaControl.drawOrigin === this)
1628
+ this.compositeFull = true;
1090
1629
  this.effectsMarginCache = undefined;
1091
- if (this.Parent)
1092
- this.Parent.InvalidateMeasure();
1093
- else
1094
- this.Superview?.Update();
1630
+ const outer = SkiaControl.invalidateOrigin;
1631
+ SkiaControl.invalidateOrigin ??= this;
1632
+ try {
1633
+ if (this.Parent && this.IsParentIndependent)
1634
+ this.RepaintComposition();
1635
+ else if (this.Parent)
1636
+ this.Parent.InvalidateMeasure();
1637
+ else if (!SkiaControl.invalidateOrigin.UnderHiddenParent())
1638
+ this.Superview?.Update();
1639
+ }
1640
+ finally {
1641
+ SkiaControl.invalidateOrigin = outer;
1642
+ }
1095
1643
  }
1096
1644
  // ---- gestures (same names as DrawnUi) ----
1097
1645
  /** Hit rect in pixels (no transforms in this port, so it is DrawingRect). */
@@ -1150,15 +1698,19 @@ export class SkiaControl {
1150
1698
  if (this.ConsumeGestures) {
1151
1699
  const sent = new SkiaGesturesInfo(args, apply);
1152
1700
  this.ConsumeGestures(this, sent);
1153
- if (args.Type !== "Up" && sent.Consumed)
1701
+ if (args.Type !== "Up" && sent.Consumed) {
1702
+ args.Event.Handled = true;
1154
1703
  return this;
1704
+ }
1155
1705
  }
1156
1706
  // C# EffectsGestureProcessors: attached effects that process gestures (ISkiaGestureProcessor) see them first
1157
1707
  if (!this.DisableEffects)
1158
1708
  for (const e of this.visualEffects) {
1159
1709
  const p = e.ProcessGestures;
1160
- if (typeof p === "function" && p.call(e, args, apply) && args.Type !== "Up")
1710
+ if (typeof p === "function" && p.call(e, args, apply) && args.Type !== "Up") {
1711
+ args.Event.Handled = true;
1161
1712
  return this;
1713
+ }
1162
1714
  }
1163
1715
  if (this.CheckChildrenGesturesLocked(args.Type))
1164
1716
  return consumedDefault;
@@ -1195,11 +1747,16 @@ export class SkiaControl {
1195
1747
  return this;
1196
1748
  return consumed ?? consumedDefault;
1197
1749
  }
1750
+ /**
1751
+ * The gesture comes from a finger, a pen or the primary (left) mouse button (C# IsPrimaryPointer). Tap and press
1752
+ * animations (Ripple) play only for those: a right or middle click raises its events but shows no tap feedback.
1753
+ */
1754
+ static IsPrimaryPointer(args) { return (args.Event.Pointer?.Button ?? "Left") === "Left"; }
1198
1755
  /** Fires Tapped (after AnimationTapped feedback); true when a handler existed (= consumed), like DrawnUi SendTapped. */
1199
1756
  SendTapped(args, apply) {
1200
1757
  if (!this.Tapped)
1201
1758
  return false;
1202
- if (this.AnimationTapped === "Ripple") {
1759
+ if (this.AnimationTapped === "Ripple" && SkiaControl.IsPrimaryPointer(args)) {
1203
1760
  const pts = this.GetOffsetInsideControlInPoints(apply.MappedLocation, apply.ChildOffset);
1204
1761
  this.PlayRippleAnimation(this.TouchEffectColor, pts.X, pts.Y, true, this.AnimationTappedSpeed);
1205
1762
  }