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

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 (50) hide show
  1. package/README.md +87 -13
  2. package/SKIPPED.md +6 -6
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +2 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +2 -0
  5. package/dist/controls/DrawnGame.d.ts +5 -1
  6. package/dist/controls/DrawnGame.js +22 -4
  7. package/dist/controls/SkiaCarousel.d.ts +1 -1
  8. package/dist/controls/SkiaCarousel.js +5 -1
  9. package/dist/controls/SkiaDrawer.d.ts +13 -0
  10. package/dist/controls/SkiaDrawer.js +40 -7
  11. package/dist/controls/SkiaEditor.d.ts +3 -1
  12. package/dist/controls/SkiaEditor.js +5 -0
  13. package/dist/controls/SkiaGif.d.ts +4 -0
  14. package/dist/controls/SkiaGif.js +13 -2
  15. package/dist/controls/SkiaImage.d.ts +5 -0
  16. package/dist/controls/SkiaImage.js +33 -4
  17. package/dist/controls/SkiaLabel.d.ts +7 -1
  18. package/dist/controls/SkiaLabel.js +9 -3
  19. package/dist/controls/SkiaLayout.js +3 -1
  20. package/dist/controls/SkiaLottie.js +1 -1
  21. package/dist/controls/SkiaRadioButton.d.ts +2 -0
  22. package/dist/controls/SkiaRadioButton.js +10 -0
  23. package/dist/controls/SkiaScroll.js +18 -9
  24. package/dist/controls/SkiaShaderCarousel.d.ts +6 -1
  25. package/dist/controls/SkiaShaderCarousel.js +17 -5
  26. package/dist/controls/SkiaSprite.d.ts +3 -0
  27. package/dist/controls/SkiaSprite.js +18 -10
  28. package/dist/controls/SkiaSvg.d.ts +4 -0
  29. package/dist/controls/SkiaSvg.js +27 -3
  30. package/dist/controls/SnappingLayout.js +2 -1
  31. package/dist/core/Accessibility.d.ts +26 -2
  32. package/dist/core/Accessibility.js +99 -5
  33. package/dist/core/Canvas.d.ts +34 -3
  34. package/dist/core/Canvas.js +104 -14
  35. package/dist/core/Gestures.d.ts +47 -0
  36. package/dist/core/Gestures.js +93 -0
  37. package/dist/core/ImageEffects.d.ts +2 -0
  38. package/dist/core/ImageEffects.js +2 -0
  39. package/dist/core/KeyboardManager.d.ts +20 -0
  40. package/dist/core/KeyboardManager.js +54 -13
  41. package/dist/core/PopupWindows.d.ts +2 -0
  42. package/dist/core/PopupWindows.js +2 -0
  43. package/dist/core/SkiaControl.d.ts +21 -1
  44. package/dist/core/SkiaControl.js +34 -2
  45. package/dist/react/SkiaShell.js +32 -12
  46. package/dist/react/index.d.ts +1 -0
  47. package/dist/react/index.js +15 -5
  48. package/dist/react/reconciler.d.ts +18 -0
  49. package/dist/react/reconciler.js +31 -1
  50. package/package.json +15 -2
@@ -253,8 +253,14 @@ export declare class SkiaLabel extends SkiaControl {
253
253
  private HasDropShadow;
254
254
  /** C# measurement: stroke adds StrokeWidth*2 on each axis, the shadow adds DropShadowSize + offset (pixels). */
255
255
  private EffectsExtra;
256
- /** C# SkiaLabel.SetupBackgroundPaint: no BackgroundColor = no background, the gradient goes on the glyphs. */
256
+ /**
257
+ * FillGradient goes to one place (C# 9637994b, as DrawnUi.Rust): the background of a label that paints one (a
258
+ * BackgroundColor with alpha above 0), whose glyphs keep TextColor; else the glyphs.
259
+ */
257
260
  protected FillGradientPaintsBackground(): boolean;
261
+ private HasBackground;
262
+ /** The gradient the glyphs are painted with: none when the label's background takes FillGradient. */
263
+ protected get TextFillGradient(): SkiaGradient | undefined;
258
264
  protected Paint(ctx: DrawingContext): void;
259
265
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
260
266
  /** Pointer cursor over a tappable span (the label itself may not be tappable). */
@@ -863,8 +863,14 @@ export class SkiaLabel extends SkiaControl {
863
863
  const sh = this.HasDropShadow() ? (this.DropShadowSize + this.DropShadowOffsetY) * scale : 0;
864
864
  return { W: stroke + sw, H: stroke + sh, Stroke: stroke };
865
865
  }
866
- /** C# SkiaLabel.SetupBackgroundPaint: no BackgroundColor = no background, the gradient goes on the glyphs. */
867
- FillGradientPaintsBackground() { return !!this.BackgroundColor; }
866
+ /**
867
+ * FillGradient goes to one place (C# 9637994b, as DrawnUi.Rust): the background of a label that paints one (a
868
+ * BackgroundColor with alpha above 0), whose glyphs keep TextColor; else the glyphs.
869
+ */
870
+ FillGradientPaintsBackground() { return this.HasBackground(); }
871
+ HasBackground() { return !!this.BackgroundColor && Super.ParseColor(this.BackgroundColor)[3] > 0; }
872
+ /** The gradient the glyphs are painted with: none when the label's background takes FillGradient. */
873
+ get TextFillGradient() { return this.HasBackground() ? undefined : this.FillGradient; }
868
874
  Paint(ctx) {
869
875
  if (this.lines.length === 0 || !this.mainFonts)
870
876
  return;
@@ -938,7 +944,7 @@ export class SkiaLabel extends SkiaControl {
938
944
  }
939
945
  canvas.drawGlyphs(ids, positions, rx, ry, run.Font, paint);
940
946
  };
941
- const gradient = this.FillGradient;
947
+ const gradient = this.TextFillGradient;
942
948
  const textRect = new SKRect(left, top, right, bottom);
943
949
  for (const line of this.lines) {
944
950
  y += this.ParagraphSpace(line);
@@ -478,9 +478,11 @@ export class SkiaLayout extends SkiaControl {
478
478
  return;
479
479
  this.views.splice(i, 1);
480
480
  this.orderedViews = undefined;
481
+ const canvas = this.Superview;
482
+ canvas?.ControlLeft(control, false);
481
483
  control.Parent = undefined;
482
484
  this.InvalidateMeasure();
483
- this.Superview?.Hover?.RequestCheck();
485
+ canvas?.Hover?.RequestCheck();
484
486
  }
485
487
  // ---- measure ----
486
488
  MeasureAbsolute(widthConstraint, heightConstraint, scale) {
@@ -123,7 +123,7 @@ export class SkiaLottie extends AnimatedFramesRenderer {
123
123
  if (!this.Animation || !this.Animator)
124
124
  return;
125
125
  const durationMs = this.Animation.duration() * 1000;
126
- this.Animator.Speed = this.SpeedRatio < 1 ? durationMs * (1 + this.SpeedRatio) : durationMs / this.SpeedRatio;
126
+ this.Animator.Speed = this.GetPlaybackDurationMs(durationMs);
127
127
  }
128
128
  OnAnimatorInitializing() {
129
129
  if (!this.Animation || !this.Animator)
@@ -26,6 +26,8 @@ export declare class SkiaRadioButton extends SkiaToggle {
26
26
  private dot?;
27
27
  ApplyProperties(): void;
28
28
  protected DefaultAccessibilityLabel(): string | undefined;
29
+ /** A disposed radio leaves its group, and an empty group goes: the module-level registry keeps no page alive. */
30
+ protected OnDisposing(): void;
29
31
  private UpdateGroup;
30
32
  protected OnToggledChanged(): void;
31
33
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
@@ -121,6 +121,16 @@ export class SkiaRadioButton extends SkiaToggle {
121
121
  }
122
122
  DefaultAccessibilityLabel() { return this.text || undefined; }
123
123
  // ---- group (C# RadioButtons.All) ----
124
+ /** A disposed radio leaves its group, and an empty group goes: the module-level registry keeps no page alive. */
125
+ OnDisposing() {
126
+ if (this.groupKey) {
127
+ const set = groups.get(this.groupKey);
128
+ set?.delete(this);
129
+ if (set?.size === 0)
130
+ groups.delete(this.groupKey);
131
+ }
132
+ super.OnDisposing();
133
+ }
124
134
  UpdateGroup() {
125
135
  if (this.groupKey)
126
136
  groups.get(this.groupKey)?.delete(this);
@@ -42,16 +42,20 @@ export class SkiaScroll extends SkiaControl {
42
42
  /** A view before the content along the scroll axis; `Tag="Header"` on a JSX child sets it. */
43
43
  get Header() { return this.header; }
44
44
  set Header(v) { if (this.header === v)
45
- return; if (this.header)
46
- this.header.Parent = undefined; this.header = v; if (v) {
45
+ return; if (this.header) {
46
+ this.Superview?.ControlLeft(this.header, false);
47
+ this.header.Parent = undefined;
48
+ } this.header = v; if (v) {
47
49
  v.Parent = this;
48
50
  v.ZIndex = 1;
49
51
  } this.InvalidateMeasure(); }
50
52
  /** A view after the content along the scroll axis; `Tag="Footer"` on a JSX child sets it. */
51
53
  get Footer() { return this.footer; }
52
54
  set Footer(v) { if (this.footer === v)
53
- return; if (this.footer)
54
- this.footer.Parent = undefined; this.footer = v; if (v)
55
+ return; if (this.footer) {
56
+ this.Superview?.ControlLeft(this.footer, false);
57
+ this.footer.Parent = undefined;
58
+ } this.footer = v; if (v)
55
59
  v.Parent = this; this.InvalidateMeasure(); }
56
60
  /** The header stays at the viewport start while the content scrolls under it (drawn over the content unless HeaderBehind). */
57
61
  HeaderSticky = false;
@@ -165,8 +169,10 @@ export class SkiaScroll extends SkiaControl {
165
169
  /** The pull-to-refresh view (IRefreshIndicator control); `Tag="RefreshIndicator"` on a JSX child sets it. */
166
170
  get RefreshIndicator() { return this.refreshIndicator; }
167
171
  set RefreshIndicator(v) { if (this.refreshIndicator === v)
168
- return; if (this.refreshIndicator)
169
- this.refreshIndicator.Parent = undefined; this.refreshIndicator = v; if (v)
172
+ return; if (this.refreshIndicator) {
173
+ this.Superview?.ControlLeft(this.refreshIndicator, false);
174
+ this.refreshIndicator.Parent = undefined;
175
+ } this.refreshIndicator = v; if (v)
170
176
  v.Parent = this; this.InvalidateMeasure(); }
171
177
  isRefreshing = false;
172
178
  wasRefreshing = false;
@@ -382,6 +388,7 @@ export class SkiaScroll extends SkiaControl {
382
388
  if (this.content === value)
383
389
  return;
384
390
  if (this.content) {
391
+ this.Superview?.ControlLeft(this.content, false);
385
392
  this.content.Parent = undefined;
386
393
  if (this.content instanceof SkiaLayout)
387
394
  this.content.ItemsInsertedAtStart = undefined;
@@ -565,10 +572,12 @@ export class SkiaScroll extends SkiaControl {
565
572
  this.footerSize = this.footer && this.footer.IsVisible ? this.footer.Measure(widthConstraint, heightConstraint, scale) : ScaledSize.Default;
566
573
  if (this.refreshIndicator)
567
574
  this.refreshIndicator.Measure(widthConstraint, heightConstraint, scale);
575
+ // C# SetMeasuredAdaptToContentSize: the scroll's own size is its content's, up to the space it is given; a side with
576
+ // a request or Fill takes its box in Measure (NeedAutoWidth / NeedAutoHeight)
568
577
  const extra = (this.HeaderExtentPts + this.FooterExtentPts) * scale;
569
- const rw = isFinite(widthConstraint) ? widthConstraint : this.ContentSize.Pixels.Width + (this.Orientation === "Horizontal" ? extra : 0);
570
- const rh = isFinite(heightConstraint) ? heightConstraint : this.ContentSize.Pixels.Height + (this.Orientation !== "Horizontal" ? extra : 0);
571
- return ScaledSize.FromPixels(rw, rh, scale);
578
+ const cw = this.ContentSize.Pixels.Width + (this.Orientation === "Horizontal" ? extra : 0);
579
+ const ch = this.ContentSize.Pixels.Height + (this.Orientation !== "Horizontal" ? extra : 0);
580
+ return ScaledSize.FromPixels(Math.min(cw, widthConstraint), Math.min(ch, heightConstraint), scale);
572
581
  }
573
582
  OnLayoutChanged() {
574
583
  const scale = this.RenderingScale;
@@ -68,5 +68,10 @@ export declare class SkiaShaderCarousel extends SkiaCarousel {
68
68
  * first wraps that transition up within InterruptedTransitionMs, then the new one plays.
69
69
  */
70
70
  protected ScrollToOffset(targetOffset: SKPoint, velocity: SKPoint, animate: boolean): boolean;
71
- protected OnTransitionChanged(): void;
71
+ /**
72
+ * Phase 2 of an interrupted swipe starts here, the moment phase 1 arrives, so the carousel never reports a stop between
73
+ * the two phases: InTransition stays true and Stopped fires once, at real rest (C# f4628b7e, drawnui-cross 6y). A stop in
74
+ * between let an app move its slides there, and the queued raw offset then replayed in the new slides.
75
+ */
76
+ CheckTransitionEnded(): boolean;
72
77
  }
@@ -83,6 +83,7 @@ export class SkiaShaderCarousel extends SkiaCarousel {
83
83
  return super.MeasureAbsolute(w, h, scale);
84
84
  }
85
85
  OnChildrenInitialized() {
86
+ this.pendingTarget = undefined; // new slides: an offset queued for the old ones means nothing here
86
87
  this.indexFrom = -1;
87
88
  this.indexTo = -1;
88
89
  this.indexFromLast = -1;
@@ -179,6 +180,10 @@ export class SkiaShaderCarousel extends SkiaCarousel {
179
180
  * first wraps that transition up within InterruptedTransitionMs, then the new one plays.
180
181
  */
181
182
  ScrollToOffset(targetOffset, velocity, animate) {
183
+ // a real move by code (ScrollTo, SelectedIndex, GoNext / GoPrev) drops a queued phase 2: its raw offset would replay
184
+ // over that move; the carousel's own echo of its index (a target already at CurrentSnap) is not a move and keeps it
185
+ if (!this.inGestureRelease && (targetOffset.X !== this.CurrentSnap.X || targetOffset.Y !== this.CurrentSnap.Y))
186
+ this.pendingTarget = undefined;
182
187
  if (!this.inGestureRelease || !animate || this.SnapPoints.length < 2)
183
188
  return super.ScrollToOffset(targetOffset, velocity, animate);
184
189
  const axis = (p) => (this.IsVertical ? p.Y : p.X);
@@ -244,13 +249,20 @@ export class SkiaShaderCarousel extends SkiaCarousel {
244
249
  }
245
250
  return started;
246
251
  }
247
- OnTransitionChanged() {
248
- super.OnTransitionChanged();
249
- // phase 2: the interrupted transition is wrapped up, now go where the swipe pointed
252
+ /**
253
+ * Phase 2 of an interrupted swipe starts here, the moment phase 1 arrives, so the carousel never reports a stop between
254
+ * the two phases: InTransition stays true and Stopped fires once, at real rest (C# f4628b7e, drawnui-cross 6y). A stop in
255
+ * between let an app move its slides there, and the queued raw offset then replayed in the new slides.
256
+ */
257
+ CheckTransitionEnded() {
258
+ const ended = super.CheckTransitionEnded();
250
259
  const next = this.pendingTarget;
251
- if (!this.InTransition && next) {
260
+ if (ended && next) {
252
261
  this.pendingTarget = undefined;
253
- this.ScrollToOffset(next, SKPoint.Empty, true);
262
+ this.FixPosition(); // looped: back from a virtual slot first, as at every stop
263
+ if (this.ScrollToOffset(next, SKPoint.Empty, true))
264
+ return false; // phase 2 runs
254
265
  }
266
+ return ended;
255
267
  }
256
268
  }
@@ -81,6 +81,7 @@ export declare class SkiaSprite extends AnimatedFramesRenderer {
81
81
  static LoadSourceAsync(source: string): Promise<Image>;
82
82
  SetSpriteSheet(image: Image): void;
83
83
  protected RecalculateFrames(): void;
84
+ /** The frame index (position in FrameSequence when one is set) at a time in ms; negative counts back from the end. */
84
85
  protected GetFrameNumberFromTime(msTime: number): number;
85
86
  protected SetCurrentFrame(frameNumber: number): void;
86
87
  /** Transparent borders of a frame, scanned once (C# ScanFrameContentBounds over the bitmap alpha). */
@@ -91,6 +92,8 @@ export declare class SkiaSprite extends AnimatedFramesRenderer {
91
92
  protected OnAnimatorInitializing(): void;
92
93
  protected ApplySpeed(): void;
93
94
  protected CheckCanStartAnimator(): boolean;
95
+ /** Shows DefaultFrame (a frame index, -1 = last) when not playing. */
96
+ protected ApplyDefaultFrame(): void;
94
97
  Start(delayMs?: number): void;
95
98
  protected MeasureAbsolute(widthConstraint: number, heightConstraint: number, scale: number): ScaledSize;
96
99
  /** C# ResolveFrameMetrics: source rect of the trimmed content and its display rect inside dest. */
@@ -74,9 +74,6 @@ export class SkiaSprite extends AnimatedFramesRenderer {
74
74
  set FramesPerSecond(v) { if (this.framesPerSecond !== v) {
75
75
  this.framesPerSecond = v;
76
76
  this.RecalculateFrames();
77
- if (this.Animator) {
78
- this.OnAnimatorInitializing();
79
- }
80
77
  } }
81
78
  /** Custom order of frames to play instead of 0..TotalFrames-1. */
82
79
  get FrameSequence() { return this.frameSequence; }
@@ -160,22 +157,30 @@ export class SkiaSprite extends AnimatedFramesRenderer {
160
157
  this.DurationMs = this.TotalFrames * this.FrameDurationMs;
161
158
  this.lastColumns = this.columns;
162
159
  this.lastRows = this.rows;
160
+ if (this.Animator) {
161
+ // FramesPerSecond, FrameSequence, MaxFrames or the grid changed after loading: the animator range and the shown
162
+ // frame follow the new frames
163
+ this.ApplySpeed();
164
+ this.Animator.mMaxValue = this.DurationMs;
165
+ this.SetCurrentFrame(this.currentFrame);
166
+ }
163
167
  }
168
+ /** The frame index (position in FrameSequence when one is set) at a time in ms; negative counts back from the end. */
164
169
  GetFrameNumberFromTime(msTime) {
165
170
  if (this.DurationMs <= 0)
166
171
  return 0;
167
- if (msTime < 0)
168
- msTime = this.DurationMs + msTime;
169
172
  msTime %= this.DurationMs;
170
- const frame = Math.floor(msTime / this.FrameDurationMs);
171
- if (this.frameSequence && this.frameSequence.length > 0)
172
- return frame % this.frameSequence.length;
173
+ if (msTime < 0)
174
+ msTime += this.DurationMs;
175
+ // the epsilon keeps the exact start time of a frame on that frame: k * d / d can come out a hair below k
176
+ const frame = Math.floor(msTime / this.FrameDurationMs + 1e-9);
173
177
  return Math.min(frame, this.TotalFrames - 1);
174
178
  }
175
179
  SetCurrentFrame(frameNumber) {
176
180
  if (!this.SpriteSheet || this.TotalFrames === 0)
177
181
  return;
178
- frameNumber = Math.max(0, Math.min(frameNumber, this.TotalFrames - 1));
182
+ if (frameNumber < 0 || frameNumber >= this.TotalFrames)
183
+ frameNumber = this.TotalFrames - 1; // negative = the last frame
179
184
  const actual = this.frameSequence && this.frameSequence.length > 0 ? this.frameSequence[Math.min(frameNumber, this.frameSequence.length - 1)] : frameNumber;
180
185
  this.currentFrame = frameNumber;
181
186
  const framesX = Math.max(1, this.columns);
@@ -249,9 +254,12 @@ export class SkiaSprite extends AnimatedFramesRenderer {
249
254
  ApplySpeed() {
250
255
  if (!this.SpriteSheet || !this.Animator)
251
256
  return;
252
- this.Animator.Speed = this.SpeedRatio < 1 ? this.DurationMs * (1 + this.SpeedRatio) : this.DurationMs / this.SpeedRatio;
257
+ this.Animator.Speed = this.GetPlaybackDurationMs(this.DurationMs);
253
258
  }
254
259
  CheckCanStartAnimator() { return !!this.SpriteSheet && this.TotalFrames > 0; }
260
+ /** Shows DefaultFrame (a frame index, -1 = last) when not playing. */
261
+ ApplyDefaultFrame() { if (!this.IsPlaying)
262
+ this.SetCurrentFrame(this.DefaultFrame); }
255
263
  Start(delayMs = 0) { if (this.SpriteSheet && this.TotalFrames > 0)
256
264
  super.Start(delayMs); }
257
265
  // ---- measure / draw (C# SpriteFrameImage: AspectFit of the FRAME into the box, then the placement config) ----
@@ -33,6 +33,10 @@ export declare class SkiaSvg extends SkiaControl {
33
33
  private Clear;
34
34
  protected OnDisposing(): void;
35
35
  private DropRaster;
36
+ private tileShader?;
37
+ private tileShaderAt;
38
+ /** Repeat shader of the raster placed at `display`, kept until the raster or its placement changes (C# picture shader). */
39
+ private TileShader;
36
40
  private Decode;
37
41
  /** Natural size: the decoded image's, else the viewBox (SVGs without width/height decode as 0x0 or 300x150). */
38
42
  private static IntrinsicSize;
@@ -74,10 +74,26 @@ export class SkiaSvg extends SkiaControl {
74
74
  }
75
75
  OnDisposing() { this.loadGeneration++; this.DropRaster(); }
76
76
  DropRaster() {
77
+ this.tileShader?.delete();
78
+ this.tileShader = undefined;
77
79
  this.raster?.delete();
78
80
  this.raster = undefined;
79
81
  this.rasterKey = "";
80
82
  }
83
+ tileShader;
84
+ tileShaderAt = "";
85
+ /** Repeat shader of the raster placed at `display`, kept until the raster or its placement changes (C# picture shader). */
86
+ TileShader(raster, display) {
87
+ const at = `${display.Left},${display.Top},${display.Width},${display.Height}`;
88
+ if (this.tileShader && this.tileShaderAt === at)
89
+ return this.tileShader;
90
+ this.tileShader?.delete();
91
+ const CK = Super.CK, M = CK.Matrix;
92
+ const local = M.multiply(M.translated(display.Left, display.Top), M.scaled(display.Width / raster.width(), display.Height / raster.height()));
93
+ this.tileShader = raster.makeShaderOptions(CK.TileMode.Repeat, CK.TileMode.Repeat, CK.FilterMode.Linear, CK.MipmapMode.None, local);
94
+ this.tileShaderAt = at;
95
+ return this.tileShader;
96
+ }
81
97
  async Decode(svg, sourceName, generation) {
82
98
  this.IsLoading = true;
83
99
  // browsers refuse to rasterize an <img> SVG whose root has no xmlns (SkiaSharp's parser does not care)
@@ -154,7 +170,9 @@ export class SkiaSvg extends SkiaControl {
154
170
  if (!this.element || Width <= 0 || Height <= 0)
155
171
  return;
156
172
  const dest = ctx.Destination;
157
- const scaled = SkiaImage.RescaleAspect(Width, Height, dest, this.Aspect);
173
+ // Tile: the picture at its natural size (one SVG unit per point), repeated from the aligned copy (C# de5ba4bb)
174
+ const tile = this.Aspect === "Tile";
175
+ const scaled = tile ? { X: ctx.Scale, Y: ctx.Scale } : SkiaImage.RescaleAspect(Width, Height, dest, this.Aspect);
158
176
  const display = SkiaImage.CalculateDisplayRect(dest, Width * scaled.X, Height * scaled.Y, this.HorizontalAlignment, this.VerticalAlignment);
159
177
  this.DisplayRect = display;
160
178
  const raster = this.GetRaster(Math.round(display.Width), Math.round(display.Height));
@@ -164,7 +182,7 @@ export class SkiaSvg extends SkiaControl {
164
182
  const canvas = ctx.Context.Canvas;
165
183
  const overflows = display.Left < dest.Left || display.Top < dest.Top || display.Right > dest.Right || display.Bottom > dest.Bottom;
166
184
  const saved = canvas.save();
167
- if (overflows)
185
+ if (overflows || tile)
168
186
  canvas.clipRect(CK.LTRBRect(dest.Left, dest.Top, dest.Right, dest.Bottom), CK.ClipOp.Intersect, true);
169
187
  const paint = new CK.Paint();
170
188
  paint.setAntiAlias(true);
@@ -174,7 +192,13 @@ export class SkiaSvg extends SkiaControl {
174
192
  paint.setColorFilter(filter);
175
193
  filter.delete();
176
194
  }
177
- canvas.drawImageRectOptions(raster, CK.LTRBRect(0, 0, raster.width(), raster.height()), CK.LTRBRect(display.Left, display.Top, display.Right, display.Bottom), CK.FilterMode.Linear, CK.MipmapMode.None, paint);
195
+ if (tile) {
196
+ paint.setShader(this.TileShader(raster, display));
197
+ canvas.drawRect(CK.LTRBRect(dest.Left, dest.Top, dest.Right, dest.Bottom), paint);
198
+ }
199
+ else {
200
+ canvas.drawImageRectOptions(raster, CK.LTRBRect(0, 0, raster.width(), raster.height()), CK.LTRBRect(display.Left, display.Top, display.Right, display.Bottom), CK.FilterMode.Linear, CK.MipmapMode.None, paint);
201
+ }
178
202
  paint.delete();
179
203
  canvas.restoreToCount(saved);
180
204
  }
@@ -70,7 +70,8 @@ export class SnappingLayout extends SkiaLayout {
70
70
  return; // interrupted / restarted: not a finished transition
71
71
  this.InTransition = !this.CheckTransitionEnded();
72
72
  this.UpdateReportedPosition(); // subclasses gate reporting on InTransition: report the settled state now
73
- this.Stopped?.(this, this.CurrentPosition);
73
+ if (!this.InTransition)
74
+ this.Stopped?.(this, this.CurrentPosition); // at real rest only (a queued next move keeps it in transition)
74
75
  }
75
76
  OnDisposing() { this.StopSnapAnimators(); }
76
77
  get IsSnapAnimating() { return this.springX.IsRunning || this.springY.IsRunning || this.range.IsRunning; }
@@ -94,6 +94,8 @@ export interface AccessibilityNode {
94
94
  /** A role a user operates (Aria.IsInteractiveRole) that cannot take input: aria-disabled, no tab stop. */
95
95
  Disabled: boolean;
96
96
  IsPressed?: boolean;
97
+ /** A control that opens something (a menu title): open or closed (aria-expanded); undefined when it opens nothing. */
98
+ Expanded?: boolean;
97
99
  Live?: string;
98
100
  Source: SkiaControl;
99
101
  /** A range control's value (aria-valuenow / min / max / valuetext); its name stays the app's label. */
@@ -127,7 +129,7 @@ export declare class SkiaAccessibilityManager {
127
129
  * Keyboard focus moved by the manager itself (arrow keys in a group): the overlay moves DOM focus to that node's
128
130
  * element (C# KeyboardFocusRequested). Returns the unsubscribe function.
129
131
  */
130
- OnKeyboardFocusRequested(cb: (node: SkiaControl) => void): () => void;
132
+ OnKeyboardFocusRequested(cb: (node: SkiaControl | undefined) => void): () => void;
131
133
  NotifyFocused(node?: SkiaControl): void;
132
134
  /**
133
135
  * Enter / Space from keyboard navigation or a screen reader: activates the node only while a tap could reach it
@@ -163,7 +165,7 @@ export declare class SkiaAccessibilityManager {
163
165
  /**
164
166
  * Moves keyboard focus between the items of the group around `focused`, by item index like a native list: Down / Up in
165
167
  * a Column, Right / Left in a Row, all four in a Wrap, a Grid or a Split layout (Up / Down by one row), Home / End to the
166
- * first / last item, PageDown / PageUp by one viewport of the scroll around it. No wrap at the ends. The target is the
168
+ * first / last item, PageDown / PageUp by one viewport of the scroll around it. The ends stop the arrows, unless the group has KeyboardWrap. The target is the
167
169
  * item itself when it is an interactive node, else its first interactive node; items the pointer cannot use are
168
170
  * skipped. An item not realized (recycled cells) is scrolled in with ScrollToIndex when the group is the scroll's
169
171
  * content, and focused once drawn. True when the key belongs to the group.
@@ -174,6 +176,24 @@ export declare class SkiaAccessibilityManager {
174
176
  private focusAnyInside;
175
177
  /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
176
178
  RequestKeyboardFocus(control: SkiaControl): void;
179
+ private appFocus?;
180
+ private appFocusDeadline;
181
+ private appFocusThisFrame;
182
+ private clearFocusRequest;
183
+ /**
184
+ * App code moves the keyboard and screen-reader focus at the end of the next frame (C# DrawnView.SetAccessibilityFocus,
185
+ * Rust `Cx::set_accessibility_focus`), for a custom menu that moves its highlight: to `control`, which gets it once
186
+ * drawn, within 3 seconds. It wins over the library's own moves in the same frame (a group's arrow move, a closed popup
187
+ * window giving the keyboard back to its opener); undefined cancels a move still waiting, the focus stays where it is.
188
+ * The focus ring shows only if the keyboard is in use (the browser's focus-visible).
189
+ */
190
+ SetAccessibilityFocus(control?: SkiaControl): void;
191
+ /**
192
+ * No drawn control keeps the keyboard and screen-reader focus (C# KeyboardFocusNode = null): at the end of the next
193
+ * frame the DOM focus goes back to the canvas and the keys belong to the app again.
194
+ */
195
+ ClearKeyboardFocus(): void;
196
+ private ProcessAppFocus;
177
197
  private popupScope?;
178
198
  /**
179
199
  * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them: the top
@@ -199,8 +219,12 @@ export declare class SkiaAccessibilityManager {
199
219
  /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
200
220
  private ProcessGroupFocus;
201
221
  private FocusFromKeyboard;
222
+ private Focus;
202
223
  Register(node: SkiaControl): void;
203
224
  NotifyUpdated(node: SkiaControl): void;
225
+ /** What the last snapshot says for each live region, to rebuild on the next frame when that changes. */
226
+ private readonly liveSaid;
227
+ private LiveChanged;
204
228
  ForceRebuildOnNextFrame(): void;
205
229
  Unregister(node: SkiaControl): void;
206
230
  UnregisterSubtree(root: SkiaControl): void;
@@ -170,7 +170,7 @@ export class SkiaAccessibilityManager {
170
170
  /**
171
171
  * Moves keyboard focus between the items of the group around `focused`, by item index like a native list: Down / Up in
172
172
  * a Column, Right / Left in a Row, all four in a Wrap, a Grid or a Split layout (Up / Down by one row), Home / End to the
173
- * first / last item, PageDown / PageUp by one viewport of the scroll around it. No wrap at the ends. The target is the
173
+ * first / last item, PageDown / PageUp by one viewport of the scroll around it. The ends stop the arrows, unless the group has KeyboardWrap. The target is the
174
174
  * item itself when it is an interactive node, else its first interactive node; items the pointer cannot use are
175
175
  * skipped. An item not realized (recycled cells) is scrolled in with ScrollToIndex when the group is the scroll's
176
176
  * content, and focused once drawn. True when the key belongs to the group.
@@ -180,6 +180,28 @@ export class SkiaAccessibilityManager {
180
180
  if (!found)
181
181
  return false;
182
182
  const { Holder: group, Item: item } = found;
183
+ // a menu, list or radio group whose items are not the children of one layout (a panel with a title, a divider and
184
+ // columns of items): its items in reading order, one after another (drawnui-cross 6ao rule 1b, as DrawnUi.Rust)
185
+ const role = found.Group.AccessibilityRole;
186
+ const linear = role === Aria.RoleMenu || role === Aria.RoleMenuBar || role === Aria.RoleList || role === Aria.RoleListBox || role === Aria.RoleRadioGroup;
187
+ const holdsMany = (child) => this.Snapshot.filter((n) => n.CanInteract && IsInside(n.Source, child)).length > 1;
188
+ if (linear && item !== focused && ViewsOf(group).some(holdsMany)) {
189
+ const items = this.Snapshot.filter((n) => n.CanInteract && SkiaAccessibilityManager.TryFindGroup(n.Source)?.Group === found.Group).map((n) => n.Source);
190
+ const current = items.indexOf(focused);
191
+ if (current < 0)
192
+ return false;
193
+ const n = items.length, wrap = found.Group.KeyboardWrap || group.KeyboardWrap;
194
+ const target = key === "ArrowDown" || key === "ArrowRight" ? (wrap ? (current + 1) % n : Math.min(current + 1, n - 1))
195
+ : key === "ArrowUp" || key === "ArrowLeft" ? (wrap ? (current - 1 + n) % n : Math.max(current - 1, 0))
196
+ : key === "Home" ? 0 : key === "End" ? n - 1 : -1;
197
+ if (target < 0)
198
+ return false;
199
+ if (target !== current) {
200
+ this.RequestKeyboardFocus(items[target]);
201
+ found.Group.Superview?.Update();
202
+ }
203
+ return true;
204
+ }
183
205
  const scroll = FindScroll(group), axis = AxisOf(group), count = ItemCount(group);
184
206
  const current = this.groupRequest?.Group === group ? this.groupRequest.Index : IndexOf(group, item);
185
207
  if (current < 0 || count < 1)
@@ -227,6 +249,9 @@ export class SkiaAccessibilityManager {
227
249
  }
228
250
  else
229
251
  return false;
252
+ // KeyboardWrap on the group: the arrows go round, the last item to the first and back
253
+ if ((target < 0 || target >= count) && key.startsWith("Arrow") && (found.Group.KeyboardWrap || group.KeyboardWrap))
254
+ target = target < 0 ? count - 1 : 0;
230
255
  if (target < 0 || target >= count || target === current)
231
256
  return true; // at the end of the group nothing happens, the key still belongs to it
232
257
  this.groupRequest = { Group: group, Scroll: scroll, Index: target, Step: step, Deadline: performance.now() + 3000, ScrollIssued: false };
@@ -238,7 +263,46 @@ export class SkiaAccessibilityManager {
238
263
  popupFocusRoot;
239
264
  focusAnyInside = false;
240
265
  /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
241
- RequestKeyboardFocus(control) { this.focusRequest = control; }
266
+ RequestKeyboardFocus(control) { if (!this.appFocusThisFrame)
267
+ this.focusRequest = control; }
268
+ appFocus;
269
+ appFocusDeadline = 0;
270
+ appFocusThisFrame = false; // until the frame end: the app said where the focus goes, the library's moves give way
271
+ clearFocusRequest = false;
272
+ /**
273
+ * App code moves the keyboard and screen-reader focus at the end of the next frame (C# DrawnView.SetAccessibilityFocus,
274
+ * Rust `Cx::set_accessibility_focus`), for a custom menu that moves its highlight: to `control`, which gets it once
275
+ * drawn, within 3 seconds. It wins over the library's own moves in the same frame (a group's arrow move, a closed popup
276
+ * window giving the keyboard back to its opener); undefined cancels a move still waiting, the focus stays where it is.
277
+ * The focus ring shows only if the keyboard is in use (the browser's focus-visible).
278
+ */
279
+ SetAccessibilityFocus(control) {
280
+ this.appFocusThisFrame = true;
281
+ this.focusRequest = undefined;
282
+ this.groupRequest = undefined;
283
+ this.appFocus = control;
284
+ this.appFocusDeadline = performance.now() + 3000;
285
+ control?.Superview?.Update();
286
+ }
287
+ /**
288
+ * No drawn control keeps the keyboard and screen-reader focus (C# KeyboardFocusNode = null): at the end of the next
289
+ * frame the DOM focus goes back to the canvas and the keys belong to the app again.
290
+ */
291
+ ClearKeyboardFocus() { this.appFocus = undefined; this.clearFocusRequest = true; }
292
+ ProcessAppFocus(scale, w, h, requestFrame) {
293
+ const wanted = this.appFocus;
294
+ if (wanted.IsDisposed || performance.now() > this.appFocusDeadline) {
295
+ this.appFocus = undefined;
296
+ return;
297
+ }
298
+ this.Rebuild(scale, w, h);
299
+ if (!this.Snapshot.some((n) => n.Source === wanted)) {
300
+ requestFrame();
301
+ return;
302
+ } // not drawn yet: look again next frame
303
+ this.appFocus = undefined;
304
+ this.Focus(wanted);
305
+ }
242
306
  popupScope;
243
307
  /**
244
308
  * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them: the top
@@ -284,7 +348,7 @@ export class SkiaAccessibilityManager {
284
348
  // back unless the keyboard went elsewhere meanwhile; a keyboard node that left with the modal (disposed, detached) was in it
285
349
  const leftWithIt = !!keyboard && (keyboard.IsDisposed || !keyboard.Superview);
286
350
  if (back && (!keyboard || leftWithIt || IsInside(keyboard, previous)) && (!next || IsInside(back, next)))
287
- this.focusRequest = back;
351
+ this.RequestKeyboardFocus(back);
288
352
  }
289
353
  /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
290
354
  NextTabStop(from, forward) {
@@ -361,6 +425,9 @@ export class SkiaAccessibilityManager {
361
425
  }
362
426
  FocusFromKeyboard(node, scale, w, h) {
363
427
  this.Rebuild(scale, w, h); // the overlay looks the node up in the snapshot: make sure it is there now
428
+ this.Focus(node);
429
+ }
430
+ Focus(node) {
364
431
  this.NoteFocus(node);
365
432
  this.FocusedNode = node;
366
433
  for (const cb of this.keyboardFocusRequested)
@@ -375,6 +442,14 @@ export class SkiaAccessibilityManager {
375
442
  for (const cb of this.liveUpdated)
376
443
  cb(node);
377
444
  }
445
+ /** What the last snapshot says for each live region, to rebuild on the next frame when that changes. */
446
+ liveSaid = new Map();
447
+ LiveChanged() {
448
+ for (const [control, said] of this.liveSaid)
449
+ if (!control.IsDisposed && (control.AccessibilityLabel ?? "") !== said)
450
+ return true;
451
+ return false;
452
+ }
378
453
  ForceRebuildOnNextFrame() { this.lastRebuild = -Infinity; this.dirty = true; }
379
454
  Unregister(node) {
380
455
  if (this.nodes.delete(node)) {
@@ -399,12 +474,26 @@ export class SkiaAccessibilityManager {
399
474
  if (AccessibilityModals.size > 0 || this.ActiveModal)
400
475
  this.UpdateActiveModal();
401
476
  this.ProcessGroupFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
477
+ if (this.clearFocusRequest) {
478
+ this.clearFocusRequest = false;
479
+ this.FocusedNode = undefined;
480
+ for (const cb of this.keyboardFocusRequested)
481
+ cb(undefined);
482
+ }
483
+ if (this.appFocus)
484
+ this.ProcessAppFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
402
485
  if (this.focusRequest || this.popupFocusRoot)
403
486
  this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
487
+ this.appFocusThisFrame = false;
404
488
  if (this.nodes.size === 0 && this.Snapshot.length === 0)
405
489
  return;
406
490
  const now = performance.now();
407
491
  const wait = this.MinUpdateIntervalMs - (now - this.lastRebuild);
492
+ // a live region whose text changed is read on the next frame, not at the next timed rebuild (accessibility-plan B2)
493
+ if (wait > 0 && this.liveSaid.size > 0 && this.LiveChanged()) {
494
+ this.Rebuild(scale, canvasWidthPx, canvasHeightPx);
495
+ return;
496
+ }
408
497
  if (wait > 0) {
409
498
  // rate-limited: rendering is on demand, so make sure a frame comes back once the interval has passed
410
499
  if (!this.pending)
@@ -440,7 +529,7 @@ export class SkiaAccessibilityManager {
440
529
  list.push({
441
530
  Id: n.AccessibilityId, Label: n.AccessibilityLabel, Hint: n.AccessibilityHint, Role: n.AccessibilityRole, Value: n.AccessibilityValue,
442
531
  Rect: new SKRect(px.Left / scale, px.Top / scale, px.Right / scale, px.Bottom / scale),
443
- CanInteract: n.AccessibilityCanInteract, IsPressed: n.AccessibilityIsPressed, Live: n.AccessibilityLive, Source: n,
532
+ CanInteract: n.AccessibilityCanInteract, IsPressed: n.AccessibilityIsPressed, Expanded: n.AccessibilityExpanded, Live: n.AccessibilityLive, Source: n,
444
533
  Disabled: !n.AccessibilityCanInteract && Aria.IsInteractiveRole(n.AccessibilityRole),
445
534
  TextLines: n.AccessibilityTextSelectable ? n.GetAccessibilityTextLines(scale) : undefined,
446
535
  });
@@ -462,6 +551,11 @@ export class SkiaAccessibilityManager {
462
551
  }
463
552
  start = i;
464
553
  }
554
+ this.liveSaid.clear();
555
+ // the control's own name (a name given to a child that says it is no change)
556
+ for (const n of list)
557
+ if (n.Live)
558
+ this.liveSaid.set(n.Source, n.Source.AccessibilityLabel ?? "");
465
559
  if (SkiaAccessibilityManager.Same(list, this.Snapshot))
466
560
  return;
467
561
  this.Snapshot = list;
@@ -474,7 +568,7 @@ export class SkiaAccessibilityManager {
474
568
  for (let i = 0; i < a.length; i++) {
475
569
  const x = a[i], y = b[i];
476
570
  if (x.Source !== y.Source || x.Label !== y.Label || x.Hint !== y.Hint || x.Role !== y.Role || x.CanInteract !== y.CanInteract || x.Disabled !== y.Disabled
477
- || x.IsPressed !== y.IsPressed || x.Live !== y.Live || !SameValue(x.Value, y.Value)
571
+ || x.IsPressed !== y.IsPressed || x.Expanded !== y.Expanded || x.Live !== y.Live || !SameValue(x.Value, y.Value)
478
572
  || Math.abs(x.Rect.Left - y.Rect.Left) > 0.5 || Math.abs(x.Rect.Top - y.Rect.Top) > 0.5
479
573
  || Math.abs(x.Rect.Right - y.Rect.Right) > 0.5 || Math.abs(x.Rect.Bottom - y.Rect.Bottom) > 0.5)
480
574
  return false;