drawnui-react 0.1.0-preview.9 → 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 +37 -28
  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
@@ -2,19 +2,95 @@ import { SkiaControl } from "../core/SkiaControl";
2
2
  import { ViewsAdapter } from "../core/ViewsAdapter";
3
3
  import { SKRect, ScaledSize, Thickness } from "../core/Types";
4
4
  import { SkiaGridStructure } from "./GridStructure";
5
+ /**
6
+ * The place of one item in a recycled templated Row / Wrap / Grid / split Column. C# measures the structure on one
7
+ * template instance bound to each item in turn: Measure here binds a pooled view to the item, keeps its size, the
8
+ * constraints and what the template decided for that item, then gives the view back unless the item is on screen.
9
+ * The same item measured again with the same constraints keeps its size without a rebind (as the list keeps its item
10
+ * heights: a new ItemsSource array is how content changes). Arrange only records the slot; the drawing pass binds a
11
+ * view to each slot it draws.
12
+ */
13
+ class TemplatedSlot {
14
+ Index;
15
+ factory;
16
+ IsVisible = true;
17
+ Row = 0;
18
+ Column = 0;
19
+ RowSpan = 1;
20
+ ColumnSpan = 1;
21
+ HorizontalOptions = "Start";
22
+ VerticalOptions = "Start";
23
+ Margin = Thickness.Zero;
24
+ WidthRequest = -1;
25
+ HeightRequest = -1;
26
+ MinimumWidthRequest = -1;
27
+ MinimumHeightRequest = -1;
28
+ MeasuredSize = ScaledSize.Default;
29
+ /** The view's fit-content size from the same measure (SkiaControl.FitPixels). */
30
+ FitPixels = { Width: 0, Height: 0 };
31
+ WidthConstraint = Infinity;
32
+ HeightConstraint = Infinity;
33
+ /** The rect the layout arranged this slot in (pixels). */
34
+ Destination = SKRect.Empty;
35
+ /** The view last arranged in this slot and the Destination it got, so an unchanged view is not arranged twice. */
36
+ ArrangedView;
37
+ ArrangedFor;
38
+ measuredItem;
39
+ measuredScale = 0;
40
+ constructor(Index, factory) {
41
+ this.Index = Index;
42
+ this.factory = factory;
43
+ }
44
+ Measure(widthConstraint, heightConstraint, scale) {
45
+ const shown = this.factory.GetViewForIndex(this.Index), item = this.factory.Items[this.Index];
46
+ if (!shown && item === this.measuredItem && scale === this.measuredScale
47
+ && Object.is(widthConstraint, this.WidthConstraint) && Object.is(heightConstraint, this.HeightConstraint))
48
+ return this.MeasuredSize;
49
+ const view = shown ?? this.factory.GetOrCreateViewForIndex(this.Index, true);
50
+ if (!view) {
51
+ this.FitPixels = { Width: 0, Height: 0 };
52
+ return (this.MeasuredSize = ScaledSize.Default);
53
+ }
54
+ this.MeasuredSize = view.Measure(widthConstraint, heightConstraint, scale);
55
+ this.FitPixels = view.FitPixels;
56
+ this.measuredItem = item;
57
+ this.measuredScale = scale;
58
+ this.WidthConstraint = widthConstraint;
59
+ this.HeightConstraint = heightConstraint;
60
+ this.IsVisible = view.IsVisible;
61
+ this.RowSpan = view.RowSpan;
62
+ this.ColumnSpan = view.ColumnSpan;
63
+ this.HorizontalOptions = view.HorizontalOptions;
64
+ this.VerticalOptions = view.VerticalOptions;
65
+ this.Margin = view.Margin;
66
+ this.WidthRequest = view.WidthRequest;
67
+ this.HeightRequest = view.HeightRequest;
68
+ this.MinimumWidthRequest = view.MinimumWidthRequest;
69
+ this.MinimumHeightRequest = view.MinimumHeightRequest;
70
+ if (!shown)
71
+ this.factory.ReleaseViewAt(this.Index);
72
+ return this.MeasuredSize;
73
+ }
74
+ Arrange(destination, _widthRequest, _heightRequest, _scale) { this.Destination = destination; }
75
+ }
5
76
  /**
6
77
  * Mirrors DrawnUi SkiaLayout (Absolute / Column / Row / Wrap / Grid).
7
78
  * Column/Row give children an infinite main axis (MAUI stack semantics: Fill on the main axis = auto-sized).
8
79
  *
9
- * Templated mode (ItemsSource + ItemTemplate) is a Column only: cells are created through the ViewsAdapter for
10
- * the indexes inside the visible viewport (+ VirtualisationInflated), everything else is arithmetic —
11
- * MeasureFirst measures one cell and assumes uniform size, MeasureAll measures every item once.
80
+ * Templated mode (ItemsSource + ItemTemplate): a single-column Column is the virtualized list, cells are created through
81
+ * the ViewsAdapter for the indexes inside the visible viewport (+ VirtualisationInflated), everything else is arithmetic —
82
+ * MeasureAll (default) measures every item once, MeasureFirst measures one cell and assumes uniform size. A templated
83
+ * Row / Wrap / Grid / split Column follows RecyclingTemplate: Enabled measures every item on pooled views and binds views
84
+ * only to the slots drawn, Disabled keeps one view per item.
12
85
  */
13
86
  export class SkiaLayout extends SkiaControl {
14
87
  /** Layout type. SkiaShape redeclares it as ShapeType (any shape value lays out as Absolute), like the C# hidden Type. */
15
88
  Type = "Absolute";
16
89
  Spacing = 0;
17
- Padding = Thickness.Zero;
90
+ padding = Thickness.Zero;
91
+ /** Space inside the layout around its children (points); a number is the same on every side (`Thickness.From`). */
92
+ get Padding() { return this.padding; }
93
+ set Padding(v) { this.padding = Thickness.From(v); }
18
94
  // ---- grid (same names as DrawnUi; definitions as "*, 2*, Auto, 100" or an array) ----
19
95
  ColumnDefinitions;
20
96
  RowDefinitions;
@@ -26,7 +102,16 @@ export class SkiaLayout extends SkiaControl {
26
102
  /** Structure computed by the last measure; cells are arranged from it. */
27
103
  GridStructure;
28
104
  // ---- templated children (same names as DrawnUi) ----
29
- RecyclingTemplate = "Enabled";
105
+ recyclingTemplate = "Enabled";
106
+ /** Enabled: views come from a pool and are bound to the items being drawn; Disabled: one view per item, never rebound. */
107
+ get RecyclingTemplate() { return this.recyclingTemplate; }
108
+ set RecyclingTemplate(value) {
109
+ if (this.recyclingTemplate === value)
110
+ return;
111
+ this.recyclingTemplate = value;
112
+ if (this.itemTemplate)
113
+ this.ApplyItemsSource(); // the pool follows the mode
114
+ }
30
115
  /** Column count for Column / Wrap content and a templated Grid (0 = free flow); C# Split. */
31
116
  Split = 0;
32
117
  /** Split > 0: every slot keeps the same width (true) or the cell keeps its measured width (C# SplitAlign). */
@@ -35,7 +120,8 @@ export class SkiaLayout extends SkiaControl {
35
120
  DynamicColumns = false;
36
121
  /** Templated Grid: fill column-major (top to bottom, then next column) instead of row-major (C# Invert). */
37
122
  Invert = false;
38
- MeasureItemsStrategy = "MeasureFirst";
123
+ /** Default MeasureAll (DrawnUi 1.10.6.20): every item keeps its own size; MeasureFirst is explicit uniform rows. */
124
+ MeasureItemsStrategy = "MeasureAll";
39
125
  /** Realized views per item (Disabled) or a recycled pool for the visible range (Enabled). */
40
126
  ChildrenFactory = new ViewsAdapter(this);
41
127
  FirstVisibleIndex = -1;
@@ -43,7 +129,7 @@ export class SkiaLayout extends SkiaControl {
43
129
  itemsSource;
44
130
  itemTemplate;
45
131
  structureDirty = true;
46
- /** Per-item heights in pixels (MeasureAll) or a single uniform height (MeasureFirst). */
132
+ /** Per-item heights in pixels (MeasureAll, the default) or a single uniform height (MeasureFirst). */
47
133
  itemHeights = [];
48
134
  uniformHeight = 0;
49
135
  measuredWidthPx = 0;
@@ -66,7 +152,7 @@ export class SkiaLayout extends SkiaControl {
66
152
  return;
67
153
  const old = this.itemsSource;
68
154
  this.itemsSource = value;
69
- if (value && old && this.IsTemplated && !this.structureDirty && this.ApplyIncrementalChange(old, value)) {
155
+ if (value && old && this.IsTemplated && !this.IsMasonry && !this.structureDirty && this.ApplyIncrementalChange(old, value)) {
70
156
  this.InvalidateMeasure();
71
157
  return;
72
158
  }
@@ -215,13 +301,29 @@ export class SkiaLayout extends SkiaControl {
215
301
  this.ApplyItemsSource();
216
302
  }
217
303
  get IsTemplated() { return !!this.itemTemplate && !!this.itemsSource; }
218
- /** The virtualized list case: a templated single-column Column. Templated Row / Wrap / Grid realize every item. */
304
+ /** The virtualized list case: a templated single-column Column. */
219
305
  get IsTemplatedList() { return this.IsTemplated && this.Type === "Column" && this.Split <= 1; }
220
- /** Views taking part in the layout pass: static children, or every item of a templated Row / Wrap / Grid (C# non-list layouts are not virtualized). */
306
+ /** A templated Row / Wrap / Grid / split Column with RecyclingTemplate Enabled: slots measured on pooled views, views bound to the slots drawn. */
307
+ get IsRecycledLayout() { return this.IsTemplated && !this.IsTemplatedList && this.recyclingTemplate === "Enabled"; }
308
+ /** Slots of a recycled layout, one per item. */
309
+ slots;
310
+ /**
311
+ * What the layout pass measures and arranges: static children; the slots of a recycled templated layout; or, with
312
+ * RecyclingTemplate Disabled, one realized view per item.
313
+ */
221
314
  LayoutViews() {
222
315
  if (!this.IsTemplated)
223
316
  return this.views;
224
- const n = this.itemsSource.length, out = [];
317
+ const n = this.itemsSource.length;
318
+ if (this.IsRecycledLayout) {
319
+ if (this.slots?.length !== n) {
320
+ // a masonry keeps the slots it has: an appended page (LoadMore) measures only the new items
321
+ const keep = this.IsMasonry ? this.slots ?? [] : [];
322
+ this.slots = Array.from({ length: n }, (_, i) => keep[i] ?? new TemplatedSlot(i, this.ChildrenFactory));
323
+ }
324
+ return this.slots;
325
+ }
326
+ const out = [];
225
327
  for (let i = 0; i < n; i++) {
226
328
  const v = this.ChildrenFactory.GetOrCreateViewForIndex(i);
227
329
  if (v)
@@ -231,7 +333,8 @@ export class SkiaLayout extends SkiaControl {
231
333
  }
232
334
  /** Drops realized cells and rebuilds the structure (DrawnUi ApplyItemsSource). */
233
335
  ApplyItemsSource() {
234
- this.ChildrenFactory.Initialize(this.itemTemplate, this.itemsSource ?? [], this.RecyclingTemplate);
336
+ this.ChildrenFactory.Initialize(this.itemTemplate, this.itemsSource ?? [], this.recyclingTemplate);
337
+ this.slots = undefined;
235
338
  this.structureDirty = true;
236
339
  this.InvalidateMeasure();
237
340
  }
@@ -267,11 +370,69 @@ export class SkiaLayout extends SkiaControl {
267
370
  get Views() { return this.IsTemplated ? this.ChildrenFactory.GetViewsInUse() : this.views; }
268
371
  /** Settable children list like DrawnUi Children (ignored while templated). */
269
372
  get Children() { return this.views; }
373
+ /**
374
+ * C# Children reset (ChildrenCollectionSync, 66a1eb02): the app's children the new list no longer holds are removed,
375
+ * the ones it gained are added, then all of them take the list's order inside the slots app children occupy, so the
376
+ * parts a control made itself keep their place.
377
+ */
270
378
  set Children(value) {
379
+ const keep = new Set(value);
380
+ for (const v of [...this.views])
381
+ if (v.IsChildrenItem && !keep.has(v))
382
+ this.RemoveSubView(v);
383
+ const inViews = new Set(this.views);
384
+ for (const v of value) {
385
+ v.IsChildrenItem = true;
386
+ if (!inViews.has(v))
387
+ this.AddSubView(v);
388
+ }
389
+ this.OrderChildren(value);
390
+ }
391
+ /**
392
+ * C# Insert / Move of a Children collection (the reconciler's appendChild / insertBefore): `child` goes before
393
+ * `before` among the app's children, or last without it. A new child is attached at the end of the views and an
394
+ * append stops there; otherwise the app's children take their new order inside the slots they occupy.
395
+ */
396
+ InsertChild(child, before) {
397
+ child.IsChildrenItem = true;
398
+ const attached = child.Parent === this && this.views.includes(child);
399
+ if (!attached)
400
+ this.AddSubView(child);
401
+ if (!attached && !before)
402
+ return;
403
+ const order = this.views.filter((v) => v.IsChildrenItem && v !== child);
404
+ const at = before ? order.indexOf(before) : -1;
405
+ order.splice(at < 0 ? order.length : at, 0, child);
406
+ this.OrderChildren(order);
407
+ }
408
+ /** C# OrderViews: the given children, in their order, inside the slots they occupy in the views; nothing else moves. */
409
+ OrderChildren(ordered) {
410
+ const inViews = new Set(this.views);
411
+ const present = ordered.filter((v) => inViews.delete(v));
412
+ if (present.length < 2)
413
+ return;
414
+ const isChild = new Set(present);
415
+ let next = 0, changed = false;
416
+ for (let i = 0; i < this.views.length && next < present.length; i++) {
417
+ if (!isChild.has(this.views[i]))
418
+ continue;
419
+ if (this.views[i] !== present[next]) {
420
+ this.views[i] = present[next];
421
+ changed = true;
422
+ }
423
+ next++;
424
+ }
425
+ if (changed) {
426
+ this.orderedViews = undefined;
427
+ this.InvalidateMeasure();
428
+ }
429
+ }
430
+ /** A child showing text (a caption inside a button) is text of its own: the accessibility label then makes no tooltip. */
431
+ ShowsText() { return this.views.some((v) => v.ShowsText()); }
432
+ /** C# ClearChildren: removes every subview, the control's own parts included. */
433
+ ClearChildren() {
271
434
  for (const v of [...this.views])
272
435
  this.RemoveSubView(v);
273
- for (const v of value)
274
- this.AddSubView(v);
275
436
  }
276
437
  orderedViews;
277
438
  /** Static children sorted by ZIndex (stable), computed once per change (C# GetOrderedSubviews). */
@@ -298,10 +459,18 @@ export class SkiaLayout extends SkiaControl {
298
459
  }
299
460
  AddSubView(control) { this.InsertSubView(this.views.length, control); }
300
461
  InsertSubView(index, control) {
462
+ // already a child: a move (React reorders keyed children by inserting an existing one elsewhere), never a 2nd copy
463
+ const at = control.Parent === this ? this.views.indexOf(control) : -1;
464
+ if (at >= 0) {
465
+ this.views.splice(at, 1);
466
+ if (at < index)
467
+ index--;
468
+ }
301
469
  control.Parent = this;
302
- this.views.splice(index, 0, control);
470
+ this.views.splice(Math.min(Math.max(0, index), this.views.length), 0, control);
303
471
  this.orderedViews = undefined;
304
472
  this.InvalidateMeasure();
473
+ this.Superview?.Hover?.RequestCheck(); // a popup / page under a still mouse
305
474
  }
306
475
  RemoveSubView(control) {
307
476
  const i = this.views.indexOf(control);
@@ -309,8 +478,11 @@ export class SkiaLayout extends SkiaControl {
309
478
  return;
310
479
  this.views.splice(i, 1);
311
480
  this.orderedViews = undefined;
481
+ const canvas = this.Superview;
482
+ canvas?.ControlLeft(control, false);
312
483
  control.Parent = undefined;
313
484
  this.InvalidateMeasure();
485
+ canvas?.Hover?.RequestCheck();
314
486
  }
315
487
  // ---- measure ----
316
488
  MeasureAbsolute(widthConstraint, heightConstraint, scale) {
@@ -326,10 +498,17 @@ export class SkiaLayout extends SkiaControl {
326
498
  const s = this.MeasureWrap(w, scale);
327
499
  return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
328
500
  }
501
+ if (this.IsMasonry) {
502
+ const s = this.MeasureMasonry(w, scale);
503
+ return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
504
+ }
329
505
  if (this.Type === "Grid") {
330
506
  const s = this.MeasureGrid(w, h, scale);
331
507
  return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
332
508
  }
509
+ // fit-content of the children on the cross axis (Fill children included, drawnui-cross 6an)
510
+ let fitW = 0, fitH = 0;
511
+ const visible = [];
333
512
  for (const v of this.LayoutViews()) {
334
513
  if (!v.IsVisible)
335
514
  continue;
@@ -349,13 +528,69 @@ export class SkiaLayout extends SkiaControl {
349
528
  cw = Math.max(cw, s.Pixels.Width);
350
529
  ch = Math.max(ch, s.Pixels.Height);
351
530
  }
531
+ fitW = Math.max(fitW, v.FitPixels.Width);
532
+ fitH = Math.max(fitH, v.FitPixels.Height);
533
+ visible.push(v);
352
534
  n++;
353
535
  }
536
+ // a stack that sizes itself on its cross axis (no request, not Fill, or Fill on an unbounded axis) is as wide / tall
537
+ // as its widest / tallest child needs; its Fill children are measured again at that size, so their wrapped heights /
538
+ // widths are the drawn ones
539
+ if (this.Type === "Column" && (this.HorizontalOptions !== "Fill" || !isFinite(w)) && this.WidthRequest < 0 && this.LockRatio === 0) {
540
+ const size = isFinite(w) ? Math.min(fitW, w) : fitW;
541
+ if (size !== cw) {
542
+ cw = size;
543
+ ch = 0;
544
+ for (const v of visible)
545
+ ch += (v.HorizontalOptions === "Fill" && v.WidthRequest < 0 ? v.Measure(size, Infinity, scale) : v.MeasuredSize).Pixels.Height;
546
+ }
547
+ }
548
+ else if (this.Type === "Row" && (this.VerticalOptions !== "Fill" || !isFinite(h)) && this.HeightRequest < 0 && this.LockRatio === 0) {
549
+ const size = isFinite(h) ? Math.min(fitH, h) : fitH;
550
+ if (size !== ch) {
551
+ ch = size;
552
+ cw = 0;
553
+ for (const v of visible)
554
+ cw += (v.VerticalOptions === "Fill" && v.HeightRequest < 0 ? v.Measure(Infinity, size, scale) : v.MeasuredSize).Pixels.Width;
555
+ }
556
+ }
557
+ else if (this.Type !== "Column" && this.Type !== "Row" && this.LockRatio === 0) {
558
+ // a layer without its own size on an axis is as big as its children there, where a Fill child with no content of
559
+ // its own (a background shape, a backdrop) counts only with its requests: it takes the layer's size, measured again
560
+ // at it (as DrawnUI for Rust and .NET). A Fill child with content still sizes the layer as before.
561
+ const autoW = (this.HorizontalOptions !== "Fill" || !isFinite(w)) && this.WidthRequest < 0;
562
+ const autoH = (this.VerticalOptions !== "Fill" || !isFinite(h)) && this.HeightRequest < 0;
563
+ if (autoW || autoH) {
564
+ const emptyX = (v) => v.HorizontalOptions === "Fill" && v.WidthRequest < 0 && v.FitPixels.Width - v.Margin.HorizontalThickness * scale <= 0;
565
+ const emptyY = (v) => v.VerticalOptions === "Fill" && v.HeightRequest < 0 && v.FitPixels.Height - v.Margin.VerticalThickness * scale <= 0;
566
+ let sw = 0, sh = 0;
567
+ for (const v of visible) {
568
+ sw = Math.max(sw, emptyX(v) ? v.FitPixels.Width : v.MeasuredSize.Pixels.Width);
569
+ sh = Math.max(sh, emptyY(v) ? v.FitPixels.Height : v.MeasuredSize.Pixels.Height);
570
+ }
571
+ if (!autoW)
572
+ sw = cw;
573
+ if (!autoH)
574
+ sh = ch;
575
+ if (sw !== cw || sh !== ch) {
576
+ cw = sw;
577
+ ch = sh;
578
+ for (const v of visible)
579
+ if ((autoW && emptyX(v)) || (autoH && emptyY(v)))
580
+ v.Measure(autoW ? sw : w, autoH ? sh : h, scale);
581
+ }
582
+ }
583
+ }
354
584
  const gaps = Math.max(0, n - 1) * gap;
355
585
  if (this.Type === "Column")
356
586
  ch += gaps;
357
587
  if (this.Type === "Row")
358
588
  cw += gaps;
589
+ // what this layout's own content needs, for a stack around it (a Fill layout still returns the whole constraint)
590
+ this.fitContentPixels = {
591
+ Width: (this.Type === "Row" ? cw : Math.min(cw, fitW)) + px,
592
+ Height: (this.Type === "Column" ? ch : Math.min(ch, fitH)) + py,
593
+ };
359
594
  return ScaledSize.FromPixels(cw + px, ch + py, scale);
360
595
  }
361
596
  /** Wrap rows computed by the last measure: [childIndex, x, y, w, h] in pixels relative to the padded box. */
@@ -416,6 +651,60 @@ export class SkiaLayout extends SkiaControl {
416
651
  finishRow(true);
417
652
  return { w: maxW, h: this.wrapSlots.length ? y + rowH : 0 };
418
653
  }
654
+ get IsMasonry() { return this.Type === "Masonry"; }
655
+ /**
656
+ * C# MeasureMasonry / BuildMasonryLayout: Split columns of equal width, every item measured unbounded at the column
657
+ * width and put at the bottom of the shortest column (the first on a tie), so items of different heights leave no
658
+ * gaps; Spacing between columns and between items. Every item is laid out (no items window). A templated slot keeps
659
+ * the size of its item, so an appended page or an item that asked to be measured again (an image arrived) is the only
660
+ * one measured, and every item is placed again from the sizes known.
661
+ */
662
+ MeasureMasonry(width, scale) {
663
+ const columns = Math.max(1, this.Split);
664
+ const spacing = Math.round(this.Spacing * scale);
665
+ const columnWidth = columns > 1 ? Math.round((width - (columns - 1) * this.Spacing * scale) / columns) : width;
666
+ const bottoms = new Array(columns).fill(0), rows = new Array(columns).fill(0);
667
+ this.wrapSlots = [];
668
+ for (const v of this.LayoutViews()) {
669
+ if (!v.IsVisible)
670
+ continue;
671
+ let column = 0;
672
+ for (let c = 1; c < columns; c++)
673
+ if (bottoms[c] < bottoms[column])
674
+ column = c;
675
+ const h = v.Measure(columnWidth, Infinity, scale).Pixels.Height;
676
+ const x = column * (columnWidth + spacing), y = bottoms[column] + (rows[column]++ > 0 ? spacing : 0);
677
+ this.wrapSlots.push({ view: v, x, y, w: columnWidth, h });
678
+ bottoms[column] = y + h;
679
+ }
680
+ const used = Math.min(columns, this.wrapSlots.length);
681
+ return { w: used > 0 ? used * columnWidth + (used - 1) * spacing : 0, h: Math.max(0, ...bottoms) };
682
+ }
683
+ /**
684
+ * Where item `index` of a recycled templated Row / Wrap / Grid / split Column / Masonry was arranged (pixels), from
685
+ * its slot, also while no view shows it (ScrollToIndex to an item off screen); undefined otherwise.
686
+ */
687
+ GetItemRect(index) {
688
+ if (!this.IsRecycledLayout)
689
+ return undefined;
690
+ const d = this.slots?.[index]?.Destination;
691
+ return d && d.Width > 0 ? d : undefined;
692
+ }
693
+ /**
694
+ * Masonry: every placed item with its rect (pixels), in item order: what keyboard navigation follows, since the
695
+ * columns have uneven heights and the item `Split` places later is rarely under the focused one.
696
+ */
697
+ GetMasonryPlacement() {
698
+ if (!this.IsMasonry)
699
+ return [];
700
+ const r = this.DrawingRect, p = this.Padding, s = this.RenderingScale, left = r.Left + p.Left * s, top = r.Top + p.Top * s;
701
+ return this.wrapSlots.map((w) => ({
702
+ Index: w.view instanceof TemplatedSlot ? w.view.Index : this.IsTemplated ? w.view.ContextIndex : this.views.indexOf(w.view),
703
+ Rect: SKRect.Create(left + w.x, top + w.y, w.w, w.h),
704
+ }));
705
+ }
706
+ /** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
707
+ GetMasonryItemRect(index) { return this.IsMasonry ? this.GetItemRect(index) : undefined; }
419
708
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
420
709
  MeasureGrid(widthPx, heightPx, scale) {
421
710
  const wPts = widthPx / scale, hPts = heightPx / scale;
@@ -434,7 +723,7 @@ export class SkiaLayout extends SkiaControl {
434
723
  }
435
724
  });
436
725
  }
437
- const g = new SkiaGridStructure(this, wPts, hPts, scale);
726
+ const g = new SkiaGridStructure(this, wPts, hPts, scale, this.LayoutViews());
438
727
  g.DecompressStars(wPts, hPts);
439
728
  const needAutoWidth = this.WidthRequest < 0 && this.HorizontalOptions !== "Fill";
440
729
  const needAutoHeight = this.HeightRequest < 0 && this.VerticalOptions !== "Fill";
@@ -574,6 +863,11 @@ export class SkiaLayout extends SkiaControl {
574
863
  this.ChildrenFactory.ReleaseViewAt(index);
575
864
  return h;
576
865
  }
866
+ /**
867
+ * The item's offset and height are real, not estimated (C# LastMeasuredIndexLocal >= index): MeasureVisible knows
868
+ * them once the measured prefix passed the item; the other strategies always do.
869
+ */
870
+ IsItemMeasured(index) { return !this.IsTemplatedList || this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
577
871
  /** Pixel offset of item index from the top of the layout content (inside padding). */
578
872
  GetItemOffsetPixels(index) {
579
873
  const scale = this.RenderingScale;
@@ -599,13 +893,29 @@ export class SkiaLayout extends SkiaControl {
599
893
  OnLayoutChanged() {
600
894
  if (this.IsTemplatedList)
601
895
  return; // cells are arranged per frame for the visible range only
896
+ this.ArrangeChildren();
897
+ // views on screen follow their slots also when a cache above skips the drawing pass (gestures, accessibility)
898
+ if (this.IsRecycledLayout) {
899
+ const scale = this.RenderingScale;
900
+ for (const v of this.ChildrenFactory.GetViewsInUse()) {
901
+ const s = this.slots?.[v.ContextIndex];
902
+ if (s) {
903
+ v.Arrange(s.Destination, v.WidthRequest, v.HeightRequest, scale);
904
+ s.ArrangedView = v;
905
+ s.ArrangedFor = s.Destination;
906
+ }
907
+ }
908
+ }
909
+ }
910
+ /** Static children and realized views are arranged; the slots of a recycled layout record where their item goes. */
911
+ ArrangeChildren() {
602
912
  const scale = this.RenderingScale;
603
913
  const p = this.Padding;
604
914
  const r = this.DrawingRect;
605
915
  const inner = new SKRect(r.Left + p.Left * scale, r.Top + p.Top * scale, r.Right - p.Right * scale, r.Bottom - p.Bottom * scale);
606
916
  const gap = this.Spacing * scale;
607
917
  let cursor = this.Type === "Row" ? inner.Left : inner.Top;
608
- if (this.IsWrapFlow) {
918
+ if (this.IsWrapFlow || this.IsMasonry) {
609
919
  for (const s of this.wrapSlots)
610
920
  s.view.Arrange(SKRect.Create(inner.Left + s.x, inner.Top + s.y, s.w, s.h), s.view.WidthRequest, s.view.HeightRequest, scale);
611
921
  return;
@@ -622,17 +932,21 @@ export class SkiaLayout extends SkiaControl {
622
932
  }
623
933
  return;
624
934
  }
935
+ // main axis of a stack: an End child gets the room up to the end of the stack, so it sits there (a button after a
936
+ // text in a full-width row); every child still takes only its measured size from the flow (DrawnUI for Rust)
625
937
  for (const v of this.LayoutViews()) {
626
938
  if (!v.IsVisible)
627
939
  continue;
628
940
  if (this.Type === "Column") {
629
941
  const h = v.MeasuredSize.Pixels.Height;
630
- v.Arrange(new SKRect(inner.Left, cursor, inner.Right, cursor + h), v.WidthRequest, v.HeightRequest, scale);
942
+ const end = v.VerticalOptions === "End" ? Math.max(inner.Bottom, cursor + h) : cursor + h;
943
+ v.Arrange(new SKRect(inner.Left, cursor, inner.Right, end), v.WidthRequest, v.HeightRequest, scale);
631
944
  cursor += h + gap;
632
945
  }
633
946
  else if (this.Type === "Row") {
634
947
  const w = v.MeasuredSize.Pixels.Width;
635
- v.Arrange(new SKRect(cursor, inner.Top, cursor + w, inner.Bottom), v.WidthRequest, v.HeightRequest, scale);
948
+ const end = v.HorizontalOptions === "End" ? Math.max(inner.Right, cursor + w) : cursor + w;
949
+ v.Arrange(new SKRect(cursor, inner.Top, end, inner.Bottom), v.WidthRequest, v.HeightRequest, scale);
636
950
  cursor += w + gap;
637
951
  }
638
952
  else {
@@ -645,12 +959,68 @@ export class SkiaLayout extends SkiaControl {
645
959
  this.PaintTemplated(ctx);
646
960
  return;
647
961
  }
962
+ if (this.IsRecycledLayout) {
963
+ this.PaintSlots(ctx);
964
+ return;
965
+ }
648
966
  const composing = this.IsRenderingWithComposition;
649
- for (const v of this.GetOrderedSubviews())
650
- if (!composing || this.DirtyChildrenInternal.has(v))
651
- v.Render(ctx);
967
+ for (const v of this.GetOrderedSubviews()) {
968
+ if (composing && !this.DirtyChildrenInternal.has(v))
969
+ continue;
970
+ v.Render(ctx); // a child entirely outside the clip skips itself
971
+ }
972
+ }
973
+ GetCompositeChildren() { return this.IsTemplatedList || this.IsRecycledLayout ? [] : this.GetOrderedSubviews(); }
974
+ drawnSlots = new Set();
975
+ /**
976
+ * Recycled templated layout (C# DrawStack): a view from the pool is bound to each slot that can be seen and drawn
977
+ * there; the views of the other slots go back to the pool.
978
+ */
979
+ PaintSlots(ctx) {
980
+ const slots = this.slots ?? [], f = this.ChildrenFactory, scale = this.RenderingScale, area = this.SlotsArea();
981
+ const drawn = this.drawnSlots;
982
+ drawn.clear();
983
+ for (const s of slots) {
984
+ const d = s.Destination;
985
+ if (s.IsVisible && d.Right > area.Left && d.Left < area.Right && d.Bottom > area.Top && d.Top < area.Bottom)
986
+ drawn.add(s.Index);
987
+ }
988
+ f.ReleaseExcept(drawn);
989
+ this.FirstVisibleIndex = this.LastVisibleIndex = -1;
990
+ for (const i of drawn) {
991
+ const s = slots[i], view = f.GetOrCreateViewForIndex(i, true);
992
+ if (!view)
993
+ continue;
994
+ // a view last measured for another item is measured for this one; the whole size is compared because a Wrap has
995
+ // no main-axis size key (C# 3d7bd78f)
996
+ const has = view.MeasuredSize.Pixels, want = s.MeasuredSize.Pixels;
997
+ if (Math.abs(has.Width - want.Width) > 1 || Math.abs(has.Height - want.Height) > 1)
998
+ view.NeedMeasure = true;
999
+ const size = view.MeasuredSize;
1000
+ view.Measure(s.WidthConstraint, s.HeightConstraint, scale);
1001
+ if (s.ArrangedView !== view || s.ArrangedFor !== s.Destination || view.MeasuredSize !== size) {
1002
+ view.Arrange(s.Destination, view.WidthRequest, view.HeightRequest, scale);
1003
+ s.ArrangedView = view;
1004
+ s.ArrangedFor = s.Destination;
1005
+ }
1006
+ view.Render(ctx);
1007
+ if (this.FirstVisibleIndex < 0)
1008
+ this.FirstVisibleIndex = i;
1009
+ this.LastVisibleIndex = i;
1010
+ }
1011
+ }
1012
+ /**
1013
+ * Where slots are drawn (C# GetOnScreenVisibleArea): what can be seen, inflated by VirtualisationInflated. Under a
1014
+ * cache (this layout's or an ancestor's, below the nearest scroll) every slot, because the cache is blitted later at
1015
+ * other offsets.
1016
+ */
1017
+ SlotsArea() {
1018
+ for (let c = this; c && !("ViewportOffsetY" in c); c = c.Parent)
1019
+ if (c.UsingCacheType !== "None")
1020
+ return this.DrawingRect;
1021
+ const v = this.GetVisibleViewport(), inflate = this.VirtualisationInflated * this.RenderingScale;
1022
+ return new SKRect(v.Left - inflate, v.Top - inflate, v.Right + inflate, v.Bottom + inflate);
652
1023
  }
653
- GetCompositeChildren() { return this.IsTemplatedList ? [] : this.GetOrderedSubviews(); }
654
1024
  /** Realizes, binds, arranges and draws only the cells intersecting the visible viewport (+ inflation). */
655
1025
  PaintTemplated(ctx) {
656
1026
  const items = this.itemsSource;
@@ -780,6 +1150,10 @@ export class SkiaLayer extends SkiaLayout {
780
1150
  export class SkiaGrid extends SkiaLayout {
781
1151
  constructor() { super(); this.Type = "Grid"; this.HorizontalOptions = "Fill"; }
782
1152
  }
1153
+ /** SkiaLayout Type=Masonry + Split 2 + HorizontalOptions=Fill (DrawnUi alias): columns, each item to the shortest one. */
1154
+ export class SkiaMasonry extends SkiaLayout {
1155
+ constructor() { super(); this.Type = "Masonry"; this.Split = 2; this.HorizontalOptions = "Fill"; }
1156
+ }
783
1157
  /** SkiaLayout Type=Wrap + HorizontalOptions=Fill (DrawnUi alias): responsive flow of fixed-size children. */
784
1158
  export class SkiaWrap extends SkiaLayout {
785
1159
  constructor() { super(); this.Type = "Wrap"; this.HorizontalOptions = "Fill"; }
@@ -32,7 +32,9 @@ export class SkiaLottie extends AnimatedFramesRenderer {
32
32
  Animation;
33
33
  constructor() {
34
34
  super();
35
- this.UseCache = "ImageDoubleBuffered";
35
+ // C# ImageDoubleBuffered pays off where a thread bakes the bitmap; on the web it is one offscreen pass per frame
36
+ // while playing, so the web engines default to Operations (drawnui-cross rule 3)
37
+ this.UseCache = "Operations";
36
38
  }
37
39
  get Source() { return this.source; }
38
40
  set Source(v) { if (this.source !== v) {
@@ -121,7 +123,7 @@ export class SkiaLottie extends AnimatedFramesRenderer {
121
123
  if (!this.Animation || !this.Animator)
122
124
  return;
123
125
  const durationMs = this.Animation.duration() * 1000;
124
- this.Animator.Speed = this.SpeedRatio < 1 ? durationMs * (1 + this.SpeedRatio) : durationMs / this.SpeedRatio;
126
+ this.Animator.Speed = this.GetPlaybackDurationMs(durationMs);
125
127
  }
126
128
  OnAnimatorInitializing() {
127
129
  if (!this.Animation || !this.Animator)
@@ -174,7 +176,7 @@ export class SkiaLottie extends AnimatedFramesRenderer {
174
176
  return Promise.resolve(cached);
175
177
  let p = SkiaLottie.inFlight.get(source);
176
178
  if (!p) {
177
- p = fetch(source).then(async (r) => { if (!r.ok)
179
+ p = fetch(Super.ResolveAssetUrl(source)).then(async (r) => { if (!r.ok)
178
180
  throw new Error(`${r.status} ${source}`); const json = await r.text(); SkiaLottie.CachedAnimations.set(source, json); return json; })
179
181
  .finally(() => SkiaLottie.inFlight.delete(source));
180
182
  SkiaLottie.inFlight.set(source, p);
@@ -36,5 +36,6 @@ export declare class SkiaProgress extends SkiaControl {
36
36
  get Ratio(): number;
37
37
  protected MeasureAbsolute(w: number, _h: number, scale: number): ScaledSize;
38
38
  protected Paint(ctx: DrawingContext): void;
39
- protected DefaultAccessibilityLabel(): string | undefined;
39
+ /** Value between Min and Max, read as "65%"; the name is the app's AccessibilityLabel only (drawnui-cross 6c). */
40
+ get AccessibilityValue(): import("../core/Accessibility").AccessibilityValue;
40
41
  }