drawnui-react 0.1.0-preview.8 → 1.0.1

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 (117) hide show
  1. package/README.md +229 -22
  2. package/SKIPPED.md +38 -29
  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 +25 -3
  8. package/dist/controls/GridStructure.js +81 -5
  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 +51 -2
  20. package/dist/controls/SkiaEditor.js +292 -58
  21. package/dist/controls/SkiaGif.d.ts +7 -0
  22. package/dist/controls/SkiaGif.js +25 -4
  23. package/dist/controls/SkiaImage.d.ts +10 -0
  24. package/dist/controls/SkiaImage.js +80 -19
  25. package/dist/controls/SkiaLabel.d.ts +200 -11
  26. package/dist/controls/SkiaLabel.js +925 -93
  27. package/dist/controls/SkiaLabelFps.d.ts +12 -0
  28. package/dist/controls/SkiaLabelFps.js +35 -0
  29. package/dist/controls/SkiaLayout.d.ts +89 -9
  30. package/dist/controls/SkiaLayout.js +397 -23
  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 +86 -7
  39. package/dist/controls/SkiaScroll.js +361 -40
  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 +15 -2
  45. package/dist/controls/SkiaShape.js +57 -10
  46. package/dist/controls/SkiaShell.d.ts +282 -0
  47. package/dist/controls/SkiaShell.js +972 -0
  48. package/dist/controls/SkiaSlider.d.ts +20 -2
  49. package/dist/controls/SkiaSlider.js +61 -7
  50. package/dist/controls/SkiaSprite.d.ts +4 -0
  51. package/dist/controls/SkiaSprite.js +27 -11
  52. package/dist/controls/SkiaSvg.d.ts +4 -0
  53. package/dist/controls/SkiaSvg.js +28 -4
  54. package/dist/controls/SkiaSwitch.d.ts +0 -1
  55. package/dist/controls/SkiaSwitch.js +4 -8
  56. package/dist/controls/SkiaToggle.d.ts +25 -5
  57. package/dist/controls/SkiaToggle.js +58 -5
  58. package/dist/controls/SnappingLayout.d.ts +12 -1
  59. package/dist/controls/SnappingLayout.js +21 -2
  60. package/dist/controls/TooltipStyle.d.ts +52 -0
  61. package/dist/controls/TooltipStyle.js +88 -0
  62. package/dist/core/Accessibility.d.ts +162 -11
  63. package/dist/core/Accessibility.js +882 -22
  64. package/dist/core/Animators.d.ts +37 -1
  65. package/dist/core/Animators.js +102 -9
  66. package/dist/core/Canvas.d.ts +307 -8
  67. package/dist/core/Canvas.js +1202 -66
  68. package/dist/core/ControlStyle.d.ts +2 -0
  69. package/dist/core/ControlStyle.js +2 -0
  70. package/dist/core/DesignerActions.d.ts +32 -0
  71. package/dist/core/DesignerActions.js +68 -0
  72. package/dist/core/Easing.d.ts +12 -1
  73. package/dist/core/Easing.js +25 -1
  74. package/dist/core/Gestures.d.ts +86 -2
  75. package/dist/core/Gestures.js +184 -4
  76. package/dist/core/Hover.d.ts +51 -0
  77. package/dist/core/Hover.js +140 -0
  78. package/dist/core/ImageEffects.d.ts +2 -0
  79. package/dist/core/ImageEffects.js +2 -0
  80. package/dist/core/KeyboardManager.d.ts +40 -0
  81. package/dist/core/KeyboardManager.js +98 -8
  82. package/dist/core/PopupWindows.d.ts +94 -0
  83. package/dist/core/PopupWindows.js +207 -0
  84. package/dist/core/Props.d.ts +11 -0
  85. package/dist/core/Props.js +44 -0
  86. package/dist/core/ScrollAnimators.d.ts +6 -0
  87. package/dist/core/ScrollAnimators.js +16 -1
  88. package/dist/core/Shaping.d.ts +40 -0
  89. package/dist/core/Shaping.js +224 -0
  90. package/dist/core/SkiaControl.d.ts +306 -13
  91. package/dist/core/SkiaControl.js +681 -75
  92. package/dist/core/SkiaEffect.d.ts +29 -1
  93. package/dist/core/SkiaEffect.js +78 -16
  94. package/dist/core/SkiaImageManager.d.ts +101 -18
  95. package/dist/core/SkiaImageManager.js +318 -63
  96. package/dist/core/Styles.js +7 -1
  97. package/dist/core/Super.d.ts +33 -2
  98. package/dist/core/Super.js +58 -12
  99. package/dist/core/TextInputProxy.d.ts +31 -1
  100. package/dist/core/TextInputProxy.js +97 -15
  101. package/dist/core/Tooltips.d.ts +71 -0
  102. package/dist/core/Tooltips.js +205 -0
  103. package/dist/core/Types.d.ts +11 -1
  104. package/dist/core/Types.js +32 -1
  105. package/dist/core/ViewsAdapter.d.ts +7 -2
  106. package/dist/core/ViewsAdapter.js +10 -3
  107. package/dist/index.d.ts +8 -0
  108. package/dist/index.js +8 -0
  109. package/dist/react/SkiaShell.d.ts +8 -74
  110. package/dist/react/SkiaShell.js +163 -475
  111. package/dist/react/index.d.ts +48 -4
  112. package/dist/react/index.js +210 -43
  113. package/dist/react/reconciler.d.ts +32 -0
  114. package/dist/react/reconciler.js +71 -40
  115. package/dist/vite/index.d.ts +9 -0
  116. package/dist/vite/index.js +36 -3
  117. package/package.json +103 -5
@@ -11,6 +11,12 @@ export type ScrollBarDock = "End" | "Start";
11
11
  */
12
12
  export interface IScrollBar {
13
13
  SetScrollProgress(orientation: ScrollOrientation, progress: number, thumbSizeRatio: number, overscrollPts: number, isScrolling: boolean): void;
14
+ /** Optional desktop behavior: the bar takes the gesture that starts on it (thumb drag, track press). */
15
+ IsDraggable?: boolean;
16
+ /** Canvas pixels; true when the point is on the bar and a drag starts. */
17
+ BeginDrag?(x: number, y: number): boolean;
18
+ /** Scroll progress 0..1 for the pointer during a drag started by BeginDrag. */
19
+ GetDragProgress?(x: number, y: number): number;
14
20
  }
15
21
  /**
16
22
  * Mirrors DrawnUi SkiaScrollBar: thin rounded thumb over an optional track, docked at the right edge for vertical
@@ -41,6 +47,19 @@ export declare class SkiaScrollBar extends SkiaLayout implements IScrollBar {
41
47
  /** Fade out after scrolling stops. */
42
48
  AutoHide: boolean;
43
49
  HideDelaySecs: number;
50
+ /** Duration in seconds of the fade-out once HideDelaySecs has passed. */
51
+ HideDurationSecs: number;
52
+ /**
53
+ * Lets the user drag the thumb and press the track to jump there (desktop scroll bar behavior). The owning
54
+ * SkiaScroll then takes the whole gesture, from down to up, when it starts on the bar. Default false: the bar only
55
+ * indicates and every gesture passes through to the content.
56
+ */
57
+ IsDraggable: boolean;
58
+ /** Extra grab area in points on both sides of the bar, across the scrolling axis, so a thin bar is easy to hit with a mouse. */
59
+ GrabPadding: number;
60
+ private thumbOffsetPts;
61
+ private dragGrabPx;
62
+ private hasTravel;
44
63
  protected readonly thumb: SkiaShape;
45
64
  protected readonly track: SkiaShape;
46
65
  private hideTimer;
@@ -52,5 +71,13 @@ export declare class SkiaScrollBar extends SkiaLayout implements IScrollBar {
52
71
  protected ApplyOrientation(): void;
53
72
  SetScrollProgress(orientation: ScrollOrientation, progress: number, thumbSizeRatio: number, overscrollPts: number, isScrolling: boolean): void;
54
73
  private CancelHide;
74
+ /**
75
+ * Called by the owning scroll on touch down, coordinates in canvas pixels. True when the point is on the bar (track
76
+ * plus GrabPadding) and a drag starts: on the thumb it keeps the grab point, on the track the thumb jumps to center
77
+ * under the pointer.
78
+ */
79
+ BeginDrag(x: number, y: number): boolean;
80
+ /** Scroll progress 0..1 for the pointer position during a drag started by BeginDrag, coordinates in canvas pixels. */
81
+ GetDragProgress(x: number, y: number): number;
55
82
  protected OnDisposing(): void;
56
83
  }
@@ -1,4 +1,4 @@
1
- import { Colors, Thickness } from "../core/Types";
1
+ import { Colors, SKRect, Thickness } from "../core/Types";
2
2
  import { SkiaLayout } from "./SkiaLayout";
3
3
  import { SkiaShape } from "./SkiaShape";
4
4
  /**
@@ -49,6 +49,19 @@ export class SkiaScrollBar extends SkiaLayout {
49
49
  /** Fade out after scrolling stops. */
50
50
  AutoHide = true;
51
51
  HideDelaySecs = 1;
52
+ /** Duration in seconds of the fade-out once HideDelaySecs has passed. */
53
+ HideDurationSecs = 0.25;
54
+ /**
55
+ * Lets the user drag the thumb and press the track to jump there (desktop scroll bar behavior). The owning
56
+ * SkiaScroll then takes the whole gesture, from down to up, when it starts on the bar. Default false: the bar only
57
+ * indicates and every gesture passes through to the content.
58
+ */
59
+ IsDraggable = false;
60
+ /** Extra grab area in points on both sides of the bar, across the scrolling axis, so a thin bar is easy to hit with a mouse. */
61
+ GrabPadding = 8;
62
+ thumbOffsetPts = 0;
63
+ dragGrabPx = 0;
64
+ hasTravel = false;
52
65
  thumb = new SkiaShape();
53
66
  track = new SkiaShape();
54
67
  hideTimer = 0;
@@ -62,6 +75,7 @@ export class SkiaScrollBar extends SkiaLayout {
62
75
  this.HorizontalOptions = "Fill";
63
76
  this.VerticalOptions = "Fill";
64
77
  this.InputTransparent = true; // display only, gestures pass through
78
+ this.IsParentIndependent = true; // the bar's look (thumb squashed on overscroll) never changes the layout around it
65
79
  this.Opacity = 0; // hidden until the first scroll
66
80
  this.track.Type = "Rectangle";
67
81
  this.track.BackgroundColor = this.trackColor;
@@ -127,6 +141,8 @@ export class SkiaScrollBar extends SkiaLayout {
127
141
  thumbLen = Math.max(this.MinThumbSize / 2, thumbLen - Math.abs(overscrollPts)); // squash on bounce
128
142
  const travel = track - thumbLen;
129
143
  const offset = Math.max(0, Math.min(1, progress)) * travel;
144
+ this.thumbOffsetPts = offset;
145
+ this.hasTravel = travel > 0;
130
146
  if (Math.abs(thumbLen - this.lastThumbLen) > 0.5) {
131
147
  this.lastThumbLen = thumbLen;
132
148
  if (orientation === "Horizontal")
@@ -142,7 +158,7 @@ export class SkiaScrollBar extends SkiaLayout {
142
158
  this.CancelHide();
143
159
  this.Opacity = 1;
144
160
  if (this.AutoHide && !isScrolling) {
145
- this.hideTimer = window.setTimeout(() => { this.hideTimer = 0; this.hideAbort = new AbortController(); void this.FadeToAsync(0, 250, undefined, this.hideAbort.signal); }, this.HideDelaySecs * 1000);
161
+ this.hideTimer = window.setTimeout(() => { this.hideTimer = 0; this.hideAbort = new AbortController(); void this.FadeToAsync(0, Math.max(0, this.HideDurationSecs * 1000), undefined, this.hideAbort.signal); }, this.HideDelaySecs * 1000);
146
162
  }
147
163
  this.RepaintComposition();
148
164
  }
@@ -154,5 +170,38 @@ export class SkiaScrollBar extends SkiaLayout {
154
170
  this.hideAbort?.abort();
155
171
  this.hideAbort = undefined;
156
172
  }
173
+ /**
174
+ * Called by the owning scroll on touch down, coordinates in canvas pixels. True when the point is on the bar (track
175
+ * plus GrabPadding) and a drag starts: on the thumb it keeps the grab point, on the track the thumb jumps to center
176
+ * under the pointer.
177
+ */
178
+ BeginDrag(x, y) {
179
+ if (!this.IsDraggable || !this.hasTravel)
180
+ return false;
181
+ const scale = this.RenderingScale || 1;
182
+ const track = this.track.DrawingRect;
183
+ const pad = this.GrabPadding * scale;
184
+ const vertical = this.orientation !== "Horizontal";
185
+ const hit = vertical ? new SKRect(track.Left - pad, track.Top, track.Right + pad, track.Bottom) : new SKRect(track.Left, track.Top - pad, track.Right, track.Bottom + pad);
186
+ if (x < hit.Left || x > hit.Right || y < hit.Top || y > hit.Bottom)
187
+ return false;
188
+ // an auto-hidden bar that gets grabbed shows again right away: never drag something invisible
189
+ this.CancelHide();
190
+ this.Opacity = 1;
191
+ const pos = vertical ? y - track.Top : x - track.Left;
192
+ const thumbStart = this.thumbOffsetPts * scale, thumbLen = this.lastThumbLen * scale;
193
+ this.dragGrabPx = pos >= thumbStart && pos <= thumbStart + thumbLen ? pos - thumbStart : thumbLen / 2;
194
+ this.RepaintComposition();
195
+ return true;
196
+ }
197
+ /** Scroll progress 0..1 for the pointer position during a drag started by BeginDrag, coordinates in canvas pixels. */
198
+ GetDragProgress(x, y) {
199
+ const scale = this.RenderingScale || 1;
200
+ const track = this.track.DrawingRect;
201
+ const vertical = this.orientation !== "Horizontal";
202
+ const pos = (vertical ? y - track.Top : x - track.Left) - this.dragGrabPx;
203
+ const travel = (vertical ? track.Height : track.Width) - this.lastThumbLen * scale;
204
+ return travel > 0 ? Math.max(0, Math.min(1, pos / travel)) : 0;
205
+ }
157
206
  OnDisposing() { this.CancelHide(); super.OnDisposing(); }
158
207
  }
@@ -56,6 +56,11 @@ export declare class SkiaShaderCarousel extends SkiaCarousel {
56
56
  protected OnScrollProgressChanged(): void;
57
57
  /** Slides never move: the transition effect renders the change (C# AnimateVisibleChild no-op). */
58
58
  protected SlideOffset(_offset: SKPoint): SKPoint;
59
+ /**
60
+ * Slides all sit on the same rect, so only the selected one may take gestures: otherwise the topmost slide in the
61
+ * gesture list (the last on-screen one, a neighbour exactly one width away counts as on screen) caught every tap.
62
+ */
63
+ protected IsSlideHitTestable(index: number): boolean;
59
64
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
60
65
  /**
61
66
  * Gesture targeting (C#): one gesture moves at most one slide from the slide it started on; a flick moves one slide
@@ -63,5 +68,10 @@ export declare class SkiaShaderCarousel extends SkiaCarousel {
63
68
  * first wraps that transition up within InterruptedTransitionMs, then the new one plays.
64
69
  */
65
70
  protected ScrollToOffset(targetOffset: SKPoint, velocity: SKPoint, animate: boolean): boolean;
66
- 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;
67
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;
@@ -145,6 +146,11 @@ export class SkiaShaderCarousel extends SkiaCarousel {
145
146
  }
146
147
  /** Slides never move: the transition effect renders the change (C# AnimateVisibleChild no-op). */
147
148
  SlideOffset(_offset) { return SKPoint.Empty; }
149
+ /**
150
+ * Slides all sit on the same rect, so only the selected one may take gestures: otherwise the topmost slide in the
151
+ * gesture list (the last on-screen one, a neighbour exactly one width away counts as on screen) caught every tap.
152
+ */
153
+ IsSlideHitTestable(index) { return index === this.SelectedIndex; }
148
154
  ProcessGestures(args, apply) {
149
155
  if (args.Type === "Down") {
150
156
  const interrupted = this.InTransition;
@@ -174,6 +180,10 @@ export class SkiaShaderCarousel extends SkiaCarousel {
174
180
  * first wraps that transition up within InterruptedTransitionMs, then the new one plays.
175
181
  */
176
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;
177
187
  if (!this.inGestureRelease || !animate || this.SnapPoints.length < 2)
178
188
  return super.ScrollToOffset(targetOffset, velocity, animate);
179
189
  const axis = (p) => (this.IsVertical ? p.Y : p.X);
@@ -198,6 +208,11 @@ export class SkiaShaderCarousel extends SkiaCarousel {
198
208
  if (!this.wasInTransitionAtDown)
199
209
  return super.ScrollToOffset(targetOffset, velocity, animate);
200
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);
201
216
  // the pan may already have carried the position PAST the interrupted transition's destination toward the new
202
217
  // target: wrapping it up would animate backward first. Only run phase 1 while that destination is still ahead.
203
218
  const toOrigin = axis(this.gestureOrigin) - axis(this.CurrentPosition);
@@ -234,13 +249,20 @@ export class SkiaShaderCarousel extends SkiaCarousel {
234
249
  }
235
250
  return started;
236
251
  }
237
- OnTransitionChanged() {
238
- super.OnTransitionChanged();
239
- // 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();
240
259
  const next = this.pendingTarget;
241
- if (!this.InTransition && next) {
260
+ if (ended && next) {
242
261
  this.pendingTarget = undefined;
243
- 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
244
265
  }
266
+ return ended;
245
267
  }
246
268
  }
@@ -20,6 +20,10 @@ export declare class SkiaShape extends SkiaLayout {
20
20
  StrokeCap: StrokeCap;
21
21
  /** Gradient painted along the stroke instead of StrokeColor (C# StrokeGradient). */
22
22
  StrokeGradient?: SkiaGradient;
23
+ /** Dashes in points: on, off, on, off... (C# StrokePath, each rounded to pixels). Empty = a solid line. */
24
+ StrokePath?: number[];
25
+ /** Blend mode of the stroke, an SKBlendMode name (C# StrokeBlendMode). */
26
+ StrokeBlendMode: string;
23
27
  /** Raised (Bevel) or pressed-in (Emboss) edges, drawn with Bevel after the background (C# BevelType). */
24
28
  BevelType: BevelType;
25
29
  private bevel?;
@@ -43,16 +47,25 @@ export declare class SkiaShape extends SkiaLayout {
43
47
  static ShadowFilter(shadow: SkiaShadow, scale: number): import("canvaskit-wasm").ImageFilter;
44
48
  constructor();
45
49
  private StrokePixels;
46
- /** Rect the outline is drawn on: bounds deflated by half the stroke so the stroke stays inside. */
50
+ /**
51
+ * The outline the stroke runs on (C# CalculateShapeSizeForStroke): the bounds inset by half the stroke rounded up, at
52
+ * least a pixel, then on whole pixels inward, so a 1 px stroke on a plain rectangle sits on the line between two
53
+ * pixels as upstream draws it.
54
+ */
47
55
  private StrokeAwareRect;
56
+ /** The fill (C# MeasuredStrokeAwareClipSize): a third of the stroke inside the outline, so it does not show under the stroke's edge. */
57
+ private BackgroundRect;
48
58
  private UsesStroke;
49
59
  /** Builds the outline path for rect (canvas pixels). Caller deletes it. */
50
- protected CreateShapePath(rect: SKRect, scale: number): Path;
60
+ /** `radiusReduce`: pixels taken off every corner radius (the fill inside a thick stroke, C# GetCorrectedBackgroundRadii). */
61
+ protected CreateShapePath(rect: SKRect, scale: number, radiusReduce?: number): Path;
51
62
  /** Children live inside the stroke (full width) + Padding. */
52
63
  private ChildrenRect;
53
64
  /** Clip for overlay effects (ripple) and children: the shape itself, inset by the stroke. */
54
65
  CreateClip(): Path;
55
66
  protected OnLayoutChanged(): void;
67
+ /** C# SkiaShape: the fill's blend mode is the shape's FillBlendMode, also over a FillGradient's own. */
68
+ protected CreateBackgroundPaint(rect: SKRect): import("canvaskit-wasm").Paint;
56
69
  protected PaintBackground(ctx: DrawingContext): void;
57
70
  /** C# PaintBevelEffect: two stroked edge paths (top/left and bottom/right) in the light / shadow colors. */
58
71
  private PaintBevelEffect;
@@ -17,6 +17,10 @@ export class SkiaShape extends SkiaLayout {
17
17
  StrokeCap = "Round";
18
18
  /** Gradient painted along the stroke instead of StrokeColor (C# StrokeGradient). */
19
19
  StrokeGradient;
20
+ /** Dashes in points: on, off, on, off... (C# StrokePath, each rounded to pixels). Empty = a solid line. */
21
+ StrokePath;
22
+ /** Blend mode of the stroke, an SKBlendMode name (C# StrokeBlendMode). */
23
+ StrokeBlendMode = "SrcOver";
20
24
  /** Raised (Bevel) or pressed-in (Emboss) edges, drawn with Bevel after the background (C# BevelType). */
21
25
  BevelType = "None";
22
26
  bevel;
@@ -66,14 +70,28 @@ export class SkiaShape extends SkiaLayout {
66
70
  return 0;
67
71
  return this.StrokeWidth > 0 ? this.StrokeWidth * scale : -this.StrokeWidth;
68
72
  }
69
- /** Rect the outline is drawn on: bounds deflated by half the stroke so the stroke stays inside. */
73
+ /**
74
+ * The outline the stroke runs on (C# CalculateShapeSizeForStroke): the bounds inset by half the stroke rounded up, at
75
+ * least a pixel, then on whole pixels inward, so a 1 px stroke on a plain rectangle sits on the line between two
76
+ * pixels as upstream draws it.
77
+ */
70
78
  StrokeAwareRect(r, scale) {
71
- const half = this.StrokePixels(scale) / 2;
72
- return new SKRect(r.Left + half, r.Top + half, r.Right - half, r.Bottom - half);
79
+ if (!this.UsesStroke())
80
+ return r;
81
+ const half = this.StrokePixels(scale) / 2, inset = half < 0.5 ? 1 : Math.ceil(half);
82
+ return new SKRect(Math.ceil(r.Left + inset), Math.ceil(r.Top + inset), Math.floor(r.Right - inset), Math.floor(r.Bottom - inset));
83
+ }
84
+ /** The fill (C# MeasuredStrokeAwareClipSize): a third of the stroke inside the outline, so it does not show under the stroke's edge. */
85
+ BackgroundRect(r, scale) {
86
+ if (!this.UsesStroke())
87
+ return r;
88
+ const o = this.StrokeAwareRect(r, scale), k = this.StrokePixels(scale) / 3;
89
+ return new SKRect(o.Left + k, o.Top + k, o.Right - k, o.Bottom - k);
73
90
  }
74
91
  UsesStroke() { return this.StrokeWidth !== 0 && this.StrokeColor !== Colors.Transparent; }
75
92
  /** Builds the outline path for rect (canvas pixels). Caller deletes it. */
76
- CreateShapePath(rect, scale) {
93
+ /** `radiusReduce`: pixels taken off every corner radius (the fill inside a thick stroke, C# GetCorrectedBackgroundRadii). */
94
+ CreateShapePath(rect, scale, radiusReduce = 0) {
77
95
  const CK = Super.CK;
78
96
  const b = new CK.PathBuilder();
79
97
  const type = this.Type;
@@ -114,7 +132,8 @@ export class SkiaShape extends SkiaLayout {
114
132
  else {
115
133
  const c = this.cornerRadius;
116
134
  if (c.TopLeft || c.TopRight || c.BottomLeft || c.BottomRight) {
117
- const tl = c.TopLeft * scale, tr = c.TopRight * scale, br = c.BottomRight * scale, bl = c.BottomLeft * scale;
135
+ const k = (v) => Math.max(0, v * scale - radiusReduce);
136
+ const tl = k(c.TopLeft), tr = k(c.TopRight), br = k(c.BottomRight), bl = k(c.BottomLeft);
118
137
  b.addRRect(Float32Array.of(rect.Left, rect.Top, rect.Right, rect.Bottom, tl, tl, tr, tr, br, br, bl, bl));
119
138
  }
120
139
  else {
@@ -145,14 +164,24 @@ export class SkiaShape extends SkiaLayout {
145
164
  this.DrawingRect = saved;
146
165
  }
147
166
  // ---- paint ----
167
+ /** C# SkiaShape: the fill's blend mode is the shape's FillBlendMode, also over a FillGradient's own. */
168
+ CreateBackgroundPaint(rect) {
169
+ const paint = super.CreateBackgroundPaint(rect);
170
+ if (this.FillBlendMode !== "SrcOver")
171
+ paint.setBlendMode(Super.CK.BlendMode[this.FillBlendMode]);
172
+ return paint;
173
+ }
148
174
  PaintBackground(ctx) {
149
175
  const type = this.Type;
150
176
  if (type === "Arc" || type === "Line")
151
177
  return; // open shapes: stroke only
152
178
  const CK = Super.CK;
153
179
  const canvas = ctx.Context.Canvas;
154
- const rect = this.StrokeAwareRect(ctx.Destination, ctx.Scale);
155
- const path = this.CreateShapePath(rect, ctx.Scale);
180
+ const rect = this.BackgroundRect(ctx.Destination, ctx.Scale);
181
+ // inside a stroke wider than a point the corners of the fill are rounded less (C# GetCorrectedBackgroundRadii)
182
+ const outline = this.StrokeAwareRect(ctx.Destination, ctx.Scale);
183
+ const reduce = this.UsesStroke() && this.StrokeWidth > 1 ? Math.min((outline.Width - rect.Width) / 2, (outline.Height - rect.Height) / 2) : 0;
184
+ const path = this.CreateShapePath(rect, ctx.Scale, reduce);
156
185
  // C# PaintWithShadowsInternal: the fill is drawn once per shadow with a drop-shadow filter; a hollow shape
157
186
  // (ClipBackgroundColor) clips its own outline away so only the shadow outside remains
158
187
  for (const shadow of this.shadows) {
@@ -295,18 +324,36 @@ export class SkiaShape extends SkiaLayout {
295
324
  clip.delete();
296
325
  }
297
326
  if (this.UsesStroke()) {
298
- const rect = this.StrokeAwareRect(ctx.Destination, ctx.Scale);
299
- const path = this.CreateShapePath(rect, ctx.Scale);
327
+ const scale = ctx.Scale, px = this.StrokePixels(scale), type = this.Type;
328
+ let rect = this.StrokeAwareRect(ctx.Destination, scale);
329
+ const c = this.cornerRadius;
330
+ const rounded = type === "Rectangle" && !!(c.TopLeft || c.TopRight || c.BottomLeft || c.BottomRight);
331
+ // C# PaintStroke: on curves a stroke of a point or less is thinned (its antialiasing makes it look heavier than
332
+ // the straight parts), a thin rounded rectangle runs through pixel centers, a line is at least a pixel wide
333
+ const curved = rounded || type === "Circle" || type === "Ellipse" || type === "Arc" || type === "Path";
334
+ const width = type === "Line" ? Math.max(1, px) : curved && px <= scale ? px * 0.55 : px;
335
+ if (rounded && px <= 2 * scale) {
336
+ const even = (v) => { const r = Math.round(v); return Math.abs(v % 1) === 0.5 && r % 2 !== 0 ? r - 1 : r; }; // C# Math.Round: ties to even
337
+ rect = new SKRect(even(rect.Left) + 0.5, even(rect.Top) + 0.5, even(rect.Right) - 0.5, even(rect.Bottom) - 0.5);
338
+ }
339
+ const path = this.CreateShapePath(rect, scale);
300
340
  const paint = new CK.Paint();
301
341
  paint.setAntiAlias(true);
302
342
  paint.setStyle(CK.PaintStyle.Stroke);
303
- paint.setStrokeWidth(Math.max(1, this.StrokePixels(ctx.Scale)));
343
+ paint.setStrokeWidth(width);
304
344
  paint.setColor(Super.ParseColor(this.StrokeColor));
305
345
  if (this.StrokeGradient)
306
346
  this.SetupGradient(paint, this.StrokeGradient, rect);
347
+ const blend = CK.BlendMode[this.StrokeBlendMode];
348
+ if (blend && this.StrokeBlendMode !== "SrcOver")
349
+ paint.setBlendMode(blend);
307
350
  paint.setStrokeCap(this.StrokeCap === "Butt" ? CK.StrokeCap.Butt : this.StrokeCap === "Square" ? CK.StrokeCap.Square : CK.StrokeCap.Round);
308
351
  paint.setStrokeJoin(this.StrokeCap === "Round" ? CK.StrokeJoin.Round : CK.StrokeJoin.Miter);
352
+ const dash = this.StrokePath?.length ? CK.PathEffect.MakeDash(this.StrokePath.map((v) => Math.round(v * scale)), 0) : null;
353
+ if (dash)
354
+ paint.setPathEffect(dash);
309
355
  canvas.drawPath(path, paint);
356
+ dash?.delete();
310
357
  paint.delete();
311
358
  path.delete();
312
359
  }