drawnui-react 0.1.0-preview.36 → 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 (52) hide show
  1. package/README.md +87 -13
  2. package/SKIPPED.md +6 -5
  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 +36 -4
  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 +22 -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 +41 -5
  32. package/dist/core/Accessibility.js +190 -9
  33. package/dist/core/Canvas.d.ts +49 -2
  34. package/dist/core/Canvas.js +152 -11
  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 +58 -15
  41. package/dist/core/PopupWindows.d.ts +2 -0
  42. package/dist/core/PopupWindows.js +2 -0
  43. package/dist/core/SkiaControl.d.ts +31 -1
  44. package/dist/core/SkiaControl.js +61 -5
  45. package/dist/core/Tooltips.d.ts +2 -0
  46. package/dist/core/Tooltips.js +10 -0
  47. package/dist/react/SkiaShell.js +32 -12
  48. package/dist/react/index.d.ts +4 -1
  49. package/dist/react/index.js +34 -16
  50. package/dist/react/reconciler.d.ts +18 -0
  51. package/dist/react/reconciler.js +31 -1
  52. package/package.json +16 -2
@@ -42,8 +42,8 @@ export class SkiaImage extends SkiaControl {
42
42
  switch (this.AddEffect) {
43
43
  case "Tint": return this.ColorTint !== Colors.Transparent ? SkiaImageEffects.Tint(this.ColorTint, this.EffectBlendMode) : null;
44
44
  case "Darken": return this.Darken !== 0 ? SkiaImageEffects.Darken(this.Darken) : null;
45
- case "BlackAndWhite":
46
- case "Grayscale": return SkiaImageEffects.Grayscale();
45
+ case "BlackAndWhite": return SkiaImageEffects.Grayscale();
46
+ case "Grayscale": return SkiaImageEffects.Grayscale2();
47
47
  case "Pastel": return SkiaImageEffects.Pastel();
48
48
  case "Lighten": return this.Lighten !== 0 ? SkiaImageEffects.Lighten(this.Lighten) : null;
49
49
  case "Sepia": return SkiaImageEffects.Sepia();
@@ -140,7 +140,7 @@ export class SkiaImage extends SkiaControl {
140
140
  if (width * aspectX > dest.Width || height * aspectY > dest.Height)
141
141
  aspectX = aspectY = Math.min(s1, s2);
142
142
  break;
143
- case "Tile": break; // C# too: tiling is SkiaImageTiles
143
+ case "Tile": break; // natural size, repeated over the destination when drawn
144
144
  }
145
145
  return { X: aspectX, Y: aspectY };
146
146
  }
@@ -218,10 +218,39 @@ export class SkiaImage extends SkiaControl {
218
218
  paint.setImageFilter(blur);
219
219
  if (this.PaintColorFilter)
220
220
  paint.setColorFilter(this.PaintColorFilter);
221
- canvas.drawImageRectOptions(img, CK.LTRBRect(0, 0, img.width(), img.height()), CK.LTRBRect(display.Left, display.Top, display.Right, display.Bottom), CK.FilterMode.Linear, CK.MipmapMode.Linear, paint);
221
+ if (this.Aspect === "Tile") {
222
+ // C# DrawSourceRegion: the image at its natural size repeats over the whole destination from the aligned copy
223
+ if (!overflows)
224
+ canvas.clipRect(CK.LTRBRect(dest.Left, dest.Top, dest.Right, dest.Bottom), CK.ClipOp.Intersect, true);
225
+ paint.setShader(this.TileShader(img, display));
226
+ canvas.drawRect(CK.LTRBRect(dest.Left, dest.Top, dest.Right, dest.Bottom), paint);
227
+ }
228
+ else {
229
+ canvas.drawImageRectOptions(img, CK.LTRBRect(0, 0, img.width(), img.height()), CK.LTRBRect(display.Left, display.Top, display.Right, display.Bottom), CK.FilterMode.Linear, CK.MipmapMode.Linear, paint);
230
+ }
222
231
  colorFilter?.delete();
223
232
  blur?.delete();
224
233
  paint.delete();
225
234
  canvas.restoreToCount(saved);
226
235
  }
236
+ tileShader;
237
+ tileShaderKey;
238
+ /** Repeat shader of the image placed at `display`, kept until the image or its placement changes (C# cached fill shader). */
239
+ TileShader(img, display) {
240
+ const k = this.tileShaderKey;
241
+ if (this.tileShader && k && k.Image === img && k.Left === display.Left && k.Top === display.Top && k.Width === display.Width && k.Height === display.Height)
242
+ return this.tileShader;
243
+ this.tileShader?.delete();
244
+ const CK = Super.CK, M = CK.Matrix;
245
+ const local = M.multiply(M.translated(display.Left, display.Top), M.scaled(display.Width / img.width(), display.Height / img.height()));
246
+ this.tileShader = img.makeShaderOptions(CK.TileMode.Repeat, CK.TileMode.Repeat, CK.FilterMode.Linear, CK.MipmapMode.None, local);
247
+ this.tileShaderKey = { Image: img, Left: display.Left, Top: display.Top, Width: display.Width, Height: display.Height };
248
+ return this.tileShader;
249
+ }
250
+ OnDisposing() {
251
+ this.tileShader?.delete();
252
+ this.tileShader = undefined;
253
+ this.tileShaderKey = undefined;
254
+ super.OnDisposing();
255
+ }
227
256
  }
@@ -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);
@@ -203,6 +208,11 @@ export class SkiaShaderCarousel extends SkiaCarousel {
203
208
  if (!this.wasInTransitionAtDown)
204
209
  return super.ScrollToOffset(targetOffset, velocity, animate);
205
210
  this.wasInTransitionAtDown = false;
211
+ // a swipe back against the interrupted transition goes straight to its slide: wrapping that transition up first ran
212
+ // it on to its end and then back, a visible jump forward and back (C# b75f233a)
213
+ const heading = axis(this.gestureOrigin) - axis(this.gestureFrom), turn = axis(targetOffset) - axis(this.gestureOrigin);
214
+ if (heading !== 0 && turn !== 0 && Math.sign(heading) !== Math.sign(turn))
215
+ return super.ScrollToOffset(targetOffset, velocity, animate);
206
216
  // the pan may already have carried the position PAST the interrupted transition's destination toward the new
207
217
  // target: wrapping it up would animate backward first. Only run phase 1 while that destination is still ahead.
208
218
  const toOrigin = axis(this.gestureOrigin) - axis(this.CurrentPosition);
@@ -239,13 +249,20 @@ export class SkiaShaderCarousel extends SkiaCarousel {
239
249
  }
240
250
  return started;
241
251
  }
242
- OnTransitionChanged() {
243
- super.OnTransitionChanged();
244
- // 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();
245
259
  const next = this.pendingTarget;
246
- if (!this.InTransition && next) {
260
+ if (ended && next) {
247
261
  this.pendingTarget = undefined;
248
- 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
249
265
  }
266
+ return ended;
250
267
  }
251
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; }
@@ -1,6 +1,8 @@
1
1
  import type { InputKey } from "./KeyboardManager";
2
2
  import type { SkiaControl } from "./SkiaControl";
3
3
  import { SKRect } from "./Types";
4
+ /** Controls with `AccessibilityModal` set, on every canvas (drawnui-cross 6av). Empty: no modal work at all. */
5
+ export declare const AccessibilityModals: Set<SkiaControl>;
4
6
  /** ARIA role constants (DrawnUi.Models.Aria) for `AccessibilityRole`. */
5
7
  export declare const Aria: {
6
8
  readonly RoleButton: "button";
@@ -92,6 +94,8 @@ export interface AccessibilityNode {
92
94
  /** A role a user operates (Aria.IsInteractiveRole) that cannot take input: aria-disabled, no tab stop. */
93
95
  Disabled: boolean;
94
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;
95
99
  Live?: string;
96
100
  Source: SkiaControl;
97
101
  /** A range control's value (aria-valuenow / min / max / valuetext); its name stays the app's label. */
@@ -125,7 +129,7 @@ export declare class SkiaAccessibilityManager {
125
129
  * Keyboard focus moved by the manager itself (arrow keys in a group): the overlay moves DOM focus to that node's
126
130
  * element (C# KeyboardFocusRequested). Returns the unsubscribe function.
127
131
  */
128
- OnKeyboardFocusRequested(cb: (node: SkiaControl) => void): () => void;
132
+ OnKeyboardFocusRequested(cb: (node: SkiaControl | undefined) => void): () => void;
129
133
  NotifyFocused(node?: SkiaControl): void;
130
134
  /**
131
135
  * Enter / Space from keyboard navigation or a screen reader: activates the node only while a tap could reach it
@@ -161,7 +165,7 @@ export declare class SkiaAccessibilityManager {
161
165
  /**
162
166
  * Moves keyboard focus between the items of the group around `focused`, by item index like a native list: Down / Up in
163
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
164
- * 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
165
169
  * item itself when it is an interactive node, else its first interactive node; items the pointer cannot use are
166
170
  * skipped. An item not realized (recycled cells) is scrolled in with ScrollToIndex when the group is the scroll's
167
171
  * content, and focused once drawn. True when the key belongs to the group.
@@ -169,13 +173,41 @@ export declare class SkiaAccessibilityManager {
169
173
  MoveInGroup(focused: SkiaControl, key: InputKey): boolean;
170
174
  private focusRequest?;
171
175
  private popupFocusRoot?;
176
+ private focusAnyInside;
172
177
  /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
173
178
  RequestKeyboardFocus(control: SkiaControl): void;
179
+ private appFocus?;
180
+ private appFocusDeadline;
181
+ private appFocusThisFrame;
182
+ private clearFocusRequest;
174
183
  /**
175
- * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them. The canvas
176
- * sets it to the top popup window that takes input (a menu, a dropdown), undefined when none is open.
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).
177
189
  */
178
- KeyboardScope?: SkiaControl;
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;
197
+ private popupScope?;
198
+ /**
199
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them: the top
200
+ * popup window that takes input (a menu, a dropdown; set by the canvas), else the active modal.
201
+ */
202
+ get KeyboardScope(): SkiaControl | undefined;
203
+ set KeyboardScope(v: SkiaControl | undefined);
204
+ /** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
205
+ ActiveModal?: SkiaControl;
206
+ private readonly modalReturns;
207
+ /** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
208
+ IsOutsideModal(control: SkiaControl): boolean;
209
+ /** Frame end, only while some control is flagged modal or one was active: follows the top modal. */
210
+ private UpdateActiveModal;
179
211
  /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
180
212
  NextTabStop(from: SkiaControl | undefined, forward: boolean): SkiaControl | undefined;
181
213
  /**
@@ -187,8 +219,12 @@ export declare class SkiaAccessibilityManager {
187
219
  /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
188
220
  private ProcessGroupFocus;
189
221
  private FocusFromKeyboard;
222
+ private Focus;
190
223
  Register(node: SkiaControl): void;
191
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;
192
228
  ForceRebuildOnNextFrame(): void;
193
229
  Unregister(node: SkiaControl): void;
194
230
  UnregisterSubtree(root: SkiaControl): void;