drawnui-react 0.1.0-preview.3 → 0.1.0-preview.31

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 (91) hide show
  1. package/README.md +15 -1
  2. package/SKIPPED.md +32 -25
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +7 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +16 -1
  5. package/dist/controls/DrawnGame.d.ts +40 -0
  6. package/dist/controls/DrawnGame.js +64 -0
  7. package/dist/controls/GridStructure.d.ts +16 -2
  8. package/dist/controls/GridStructure.js +40 -4
  9. package/dist/controls/SkiaBackdrop.d.ts +8 -2
  10. package/dist/controls/SkiaBackdrop.js +42 -14
  11. package/dist/controls/SkiaButton.d.ts +15 -1
  12. package/dist/controls/SkiaButton.js +21 -4
  13. package/dist/controls/SkiaCarousel.d.ts +21 -2
  14. package/dist/controls/SkiaCarousel.js +49 -5
  15. package/dist/controls/SkiaCheckbox.d.ts +0 -1
  16. package/dist/controls/SkiaCheckbox.js +0 -6
  17. package/dist/controls/SkiaDrawer.d.ts +2 -0
  18. package/dist/controls/SkiaDrawer.js +2 -0
  19. package/dist/controls/SkiaEditor.d.ts +38 -1
  20. package/dist/controls/SkiaEditor.js +223 -49
  21. package/dist/controls/SkiaGif.d.ts +3 -0
  22. package/dist/controls/SkiaGif.js +12 -2
  23. package/dist/controls/SkiaImage.js +15 -10
  24. package/dist/controls/SkiaLabel.d.ts +91 -7
  25. package/dist/controls/SkiaLabel.js +420 -71
  26. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  27. package/dist/controls/SkiaLabelFps.js +41 -0
  28. package/dist/controls/SkiaLayout.d.ts +97 -9
  29. package/dist/controls/SkiaLayout.js +387 -22
  30. package/dist/controls/SkiaLottie.js +4 -2
  31. package/dist/controls/SkiaProgress.d.ts +2 -1
  32. package/dist/controls/SkiaProgress.js +6 -3
  33. package/dist/controls/SkiaRadioButton.js +4 -3
  34. package/dist/controls/SkiaRichLabel.d.ts +1 -1
  35. package/dist/controls/SkiaRichLabel.js +11 -1
  36. package/dist/controls/SkiaScroll.d.ts +35 -5
  37. package/dist/controls/SkiaScroll.js +234 -23
  38. package/dist/controls/SkiaScrollBar.d.ts +27 -0
  39. package/dist/controls/SkiaScrollBar.js +51 -2
  40. package/dist/controls/SkiaShaderCarousel.d.ts +5 -0
  41. package/dist/controls/SkiaShaderCarousel.js +5 -0
  42. package/dist/controls/SkiaShape.d.ts +13 -2
  43. package/dist/controls/SkiaShape.js +50 -10
  44. package/dist/controls/SkiaSlider.d.ts +20 -2
  45. package/dist/controls/SkiaSlider.js +59 -5
  46. package/dist/controls/SkiaSprite.d.ts +1 -0
  47. package/dist/controls/SkiaSprite.js +4 -0
  48. package/dist/controls/SkiaSvg.js +1 -1
  49. package/dist/controls/SkiaSwitch.d.ts +0 -1
  50. package/dist/controls/SkiaSwitch.js +0 -6
  51. package/dist/controls/SkiaToggle.d.ts +25 -5
  52. package/dist/controls/SkiaToggle.js +58 -5
  53. package/dist/controls/SnappingLayout.d.ts +12 -1
  54. package/dist/controls/SnappingLayout.js +19 -1
  55. package/dist/core/Accessibility.d.ts +80 -0
  56. package/dist/core/Accessibility.js +421 -8
  57. package/dist/core/Animators.d.ts +37 -1
  58. package/dist/core/Animators.js +102 -9
  59. package/dist/core/Canvas.d.ts +108 -7
  60. package/dist/core/Canvas.js +353 -29
  61. package/dist/core/Easing.d.ts +12 -1
  62. package/dist/core/Easing.js +25 -1
  63. package/dist/core/Gestures.d.ts +34 -2
  64. package/dist/core/Gestures.js +84 -3
  65. package/dist/core/Hover.d.ts +47 -0
  66. package/dist/core/Hover.js +134 -0
  67. package/dist/core/KeyboardManager.d.ts +13 -0
  68. package/dist/core/KeyboardManager.js +18 -0
  69. package/dist/core/ScrollAnimators.js +9 -0
  70. package/dist/core/Shaping.d.ts +40 -0
  71. package/dist/core/Shaping.js +224 -0
  72. package/dist/core/SkiaControl.d.ts +209 -9
  73. package/dist/core/SkiaControl.js +500 -59
  74. package/dist/core/SkiaEffect.d.ts +17 -0
  75. package/dist/core/SkiaEffect.js +43 -8
  76. package/dist/core/SkiaImageManager.js +1 -1
  77. package/dist/core/Super.d.ts +22 -2
  78. package/dist/core/Super.js +47 -3
  79. package/dist/core/Types.d.ts +11 -1
  80. package/dist/core/Types.js +32 -1
  81. package/dist/core/ViewsAdapter.d.ts +7 -2
  82. package/dist/core/ViewsAdapter.js +10 -3
  83. package/dist/index.d.ts +3 -0
  84. package/dist/index.js +3 -0
  85. package/dist/react/SkiaShell.js +33 -14
  86. package/dist/react/index.d.ts +17 -4
  87. package/dist/react/index.js +103 -15
  88. package/dist/react/reconciler.js +33 -13
  89. package/dist/vite/index.d.ts +9 -0
  90. package/dist/vite/index.js +36 -3
  91. package/package.json +42 -3
@@ -2,19 +2,90 @@ 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
+ WidthConstraint = Infinity;
30
+ HeightConstraint = Infinity;
31
+ /** The rect the layout arranged this slot in (pixels). */
32
+ Destination = SKRect.Empty;
33
+ /** The view last arranged in this slot and the Destination it got, so an unchanged view is not arranged twice. */
34
+ ArrangedView;
35
+ ArrangedFor;
36
+ measuredItem;
37
+ measuredScale = 0;
38
+ constructor(Index, factory) {
39
+ this.Index = Index;
40
+ this.factory = factory;
41
+ }
42
+ Measure(widthConstraint, heightConstraint, scale) {
43
+ const shown = this.factory.GetViewForIndex(this.Index), item = this.factory.Items[this.Index];
44
+ if (!shown && item === this.measuredItem && scale === this.measuredScale
45
+ && Object.is(widthConstraint, this.WidthConstraint) && Object.is(heightConstraint, this.HeightConstraint))
46
+ return this.MeasuredSize;
47
+ const view = shown ?? this.factory.GetOrCreateViewForIndex(this.Index, true);
48
+ if (!view)
49
+ return (this.MeasuredSize = ScaledSize.Default);
50
+ this.MeasuredSize = view.Measure(widthConstraint, heightConstraint, scale);
51
+ this.measuredItem = item;
52
+ this.measuredScale = scale;
53
+ this.WidthConstraint = widthConstraint;
54
+ this.HeightConstraint = heightConstraint;
55
+ this.IsVisible = view.IsVisible;
56
+ this.RowSpan = view.RowSpan;
57
+ this.ColumnSpan = view.ColumnSpan;
58
+ this.HorizontalOptions = view.HorizontalOptions;
59
+ this.VerticalOptions = view.VerticalOptions;
60
+ this.Margin = view.Margin;
61
+ this.WidthRequest = view.WidthRequest;
62
+ this.HeightRequest = view.HeightRequest;
63
+ this.MinimumWidthRequest = view.MinimumWidthRequest;
64
+ this.MinimumHeightRequest = view.MinimumHeightRequest;
65
+ if (!shown)
66
+ this.factory.ReleaseViewAt(this.Index);
67
+ return this.MeasuredSize;
68
+ }
69
+ Arrange(destination, _widthRequest, _heightRequest, _scale) { this.Destination = destination; }
70
+ }
5
71
  /**
6
72
  * Mirrors DrawnUi SkiaLayout (Absolute / Column / Row / Wrap / Grid).
7
73
  * Column/Row give children an infinite main axis (MAUI stack semantics: Fill on the main axis = auto-sized).
8
74
  *
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.
75
+ * Templated mode (ItemsSource + ItemTemplate): a single-column Column is the virtualized list, cells are created through
76
+ * the ViewsAdapter for the indexes inside the visible viewport (+ VirtualisationInflated), everything else is arithmetic —
77
+ * MeasureAll (default) measures every item once, MeasureFirst measures one cell and assumes uniform size. A templated
78
+ * Row / Wrap / Grid / split Column follows RecyclingTemplate: Enabled measures every item on pooled views and binds views
79
+ * only to the slots drawn, Disabled keeps one view per item.
12
80
  */
13
81
  export class SkiaLayout extends SkiaControl {
14
82
  /** Layout type. SkiaShape redeclares it as ShapeType (any shape value lays out as Absolute), like the C# hidden Type. */
15
83
  Type = "Absolute";
16
84
  Spacing = 0;
17
- Padding = Thickness.Zero;
85
+ padding = Thickness.Zero;
86
+ /** Space inside the layout around its children (points); a number is the same on every side (`Thickness.From`). */
87
+ get Padding() { return this.padding; }
88
+ set Padding(v) { this.padding = Thickness.From(v); }
18
89
  // ---- grid (same names as DrawnUi; definitions as "*, 2*, Auto, 100" or an array) ----
19
90
  ColumnDefinitions;
20
91
  RowDefinitions;
@@ -26,7 +97,16 @@ export class SkiaLayout extends SkiaControl {
26
97
  /** Structure computed by the last measure; cells are arranged from it. */
27
98
  GridStructure;
28
99
  // ---- templated children (same names as DrawnUi) ----
29
- RecyclingTemplate = "Enabled";
100
+ recyclingTemplate = "Enabled";
101
+ /** Enabled: views come from a pool and are bound to the items being drawn; Disabled: one view per item, never rebound. */
102
+ get RecyclingTemplate() { return this.recyclingTemplate; }
103
+ set RecyclingTemplate(value) {
104
+ if (this.recyclingTemplate === value)
105
+ return;
106
+ this.recyclingTemplate = value;
107
+ if (this.itemTemplate)
108
+ this.ApplyItemsSource(); // the pool follows the mode
109
+ }
30
110
  /** Column count for Column / Wrap content and a templated Grid (0 = free flow); C# Split. */
31
111
  Split = 0;
32
112
  /** Split > 0: every slot keeps the same width (true) or the cell keeps its measured width (C# SplitAlign). */
@@ -35,7 +115,8 @@ export class SkiaLayout extends SkiaControl {
35
115
  DynamicColumns = false;
36
116
  /** Templated Grid: fill column-major (top to bottom, then next column) instead of row-major (C# Invert). */
37
117
  Invert = false;
38
- MeasureItemsStrategy = "MeasureFirst";
118
+ /** Default MeasureAll (DrawnUi 1.10.6.20): every item keeps its own size; MeasureFirst is explicit uniform rows. */
119
+ MeasureItemsStrategy = "MeasureAll";
39
120
  /** Realized views per item (Disabled) or a recycled pool for the visible range (Enabled). */
40
121
  ChildrenFactory = new ViewsAdapter(this);
41
122
  FirstVisibleIndex = -1;
@@ -43,7 +124,7 @@ export class SkiaLayout extends SkiaControl {
43
124
  itemsSource;
44
125
  itemTemplate;
45
126
  structureDirty = true;
46
- /** Per-item heights in pixels (MeasureAll) or a single uniform height (MeasureFirst). */
127
+ /** Per-item heights in pixels (MeasureAll, the default) or a single uniform height (MeasureFirst). */
47
128
  itemHeights = [];
48
129
  uniformHeight = 0;
49
130
  measuredWidthPx = 0;
@@ -66,7 +147,7 @@ export class SkiaLayout extends SkiaControl {
66
147
  return;
67
148
  const old = this.itemsSource;
68
149
  this.itemsSource = value;
69
- if (value && old && this.IsTemplated && !this.structureDirty && this.ApplyIncrementalChange(old, value)) {
150
+ if (value && old && this.IsTemplated && !this.IsMasonry && !this.structureDirty && this.ApplyIncrementalChange(old, value)) {
70
151
  this.InvalidateMeasure();
71
152
  return;
72
153
  }
@@ -87,7 +168,11 @@ export class SkiaLayout extends SkiaControl {
87
168
  */
88
169
  ApplyIncrementalChange(old, items) {
89
170
  const n = items.length, o = old.length;
90
- if (n <= o || o === 0)
171
+ if (o === 0)
172
+ return false;
173
+ if (n === o)
174
+ return this.ApplyReorderChange(old, items);
175
+ if (n < o)
91
176
  return false;
92
177
  const k = n - o;
93
178
  const scale = this.RenderingScale, gap = this.Spacing * scale, w = this.measuredWidthPx;
@@ -143,6 +228,65 @@ export class SkiaLayout extends SkiaControl {
143
228
  }
144
229
  return false;
145
230
  }
231
+ /**
232
+ * Same items in another order — a drag-to-reorder, or any code writing a permuted array. DrawnUi handles the
233
+ * matching `ObservableCollection.Move` by keeping the structure and only rebinding the contexts, because its
234
+ * arrange re-flows each row from its bound view (`HandleStructurePreservingMove` / `ApplyMoveChange`, 2026-09-08).
235
+ * The measured heights here are index-keyed and authoritative, so they travel with their items instead: nothing is
236
+ * remeasured, the extent cannot change, and the scroll keeps its offset. Rebuilding instead would reset
237
+ * `MeasureVisible` to "exact for the first screen, estimated after" and throw a scrolled list back towards the top.
238
+ * Returns false when the two arrays are not a permutation of each other, so a real content change still rebuilds.
239
+ */
240
+ ApplyReorderChange(old, items) {
241
+ const n = items.length;
242
+ if (this.MeasureItemsStrategy === "MeasureAll" && this.itemHeights.length !== n)
243
+ return false;
244
+ if (this.MeasureItemsStrategy === "MeasureVisible" && this.mvHeights.length !== n)
245
+ return false;
246
+ const moved = [];
247
+ for (let i = 0; i < n; i++)
248
+ if (old[i] !== items[i])
249
+ moved.push(i);
250
+ if (moved.length === 0) {
251
+ this.ChildrenFactory.UpdateItems(items);
252
+ return true;
253
+ } // same order, new array reference
254
+ // every slot that changed must hold an item that was in one of those slots before, otherwise this is not a reorder
255
+ const free = new Map();
256
+ for (const i of moved) {
257
+ const q = free.get(old[i]);
258
+ if (q)
259
+ q.push(i);
260
+ else
261
+ free.set(old[i], [i]);
262
+ }
263
+ const from = new Int32Array(n);
264
+ for (let i = 0; i < n; i++)
265
+ from[i] = i;
266
+ for (const i of moved) {
267
+ const q = free.get(items[i]);
268
+ if (!q || q.length === 0)
269
+ return false;
270
+ from[i] = q.shift();
271
+ }
272
+ if (this.MeasureItemsStrategy === "MeasureAll") {
273
+ const was = this.itemHeights;
274
+ this.itemHeights = Array.from({ length: n }, (_, i) => was[from[i]]);
275
+ }
276
+ else if (this.MeasureItemsStrategy === "MeasureVisible") {
277
+ const was = this.mvHeights, heights = new Float64Array(n);
278
+ for (let i = 0; i < n; i++)
279
+ heights[i] = was[from[i]];
280
+ this.mvHeights = heights;
281
+ // an item that was never measured can land inside the exact prefix: rebuild it over the leading measured run
282
+ this.mvPrefix = new Float64Array(n + 1);
283
+ this.mvMeasured = 0;
284
+ this.MvExtendPrefix(this.Spacing * this.RenderingScale);
285
+ }
286
+ // MeasureFirst has one height for every row, so a reorder is a pure rebind there (same as the C# note).
287
+ this.ChildrenFactory.UpdateItems(items);
288
+ return true;
289
+ }
146
290
  /** Factory creating one cell (DrawnUi DataTemplate). Cells receive the item as BindingContext. */
147
291
  get ItemTemplate() { return this.itemTemplate; }
148
292
  set ItemTemplate(value) {
@@ -152,13 +296,29 @@ export class SkiaLayout extends SkiaControl {
152
296
  this.ApplyItemsSource();
153
297
  }
154
298
  get IsTemplated() { return !!this.itemTemplate && !!this.itemsSource; }
155
- /** The virtualized list case: a templated single-column Column. Templated Row / Wrap / Grid realize every item. */
299
+ /** The virtualized list case: a templated single-column Column. */
156
300
  get IsTemplatedList() { return this.IsTemplated && this.Type === "Column" && this.Split <= 1; }
157
- /** 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). */
301
+ /** A templated Row / Wrap / Grid / split Column with RecyclingTemplate Enabled: slots measured on pooled views, views bound to the slots drawn. */
302
+ get IsRecycledLayout() { return this.IsTemplated && !this.IsTemplatedList && this.recyclingTemplate === "Enabled"; }
303
+ /** Slots of a recycled layout, one per item. */
304
+ slots;
305
+ /**
306
+ * What the layout pass measures and arranges: static children; the slots of a recycled templated layout; or, with
307
+ * RecyclingTemplate Disabled, one realized view per item.
308
+ */
158
309
  LayoutViews() {
159
310
  if (!this.IsTemplated)
160
311
  return this.views;
161
- const n = this.itemsSource.length, out = [];
312
+ const n = this.itemsSource.length;
313
+ if (this.IsRecycledLayout) {
314
+ if (this.slots?.length !== n) {
315
+ // a masonry keeps the slots it has: an appended page (LoadMore) measures only the new items
316
+ const keep = this.IsMasonry ? this.slots ?? [] : [];
317
+ this.slots = Array.from({ length: n }, (_, i) => keep[i] ?? new TemplatedSlot(i, this.ChildrenFactory));
318
+ }
319
+ return this.slots;
320
+ }
321
+ const out = [];
162
322
  for (let i = 0; i < n; i++) {
163
323
  const v = this.ChildrenFactory.GetOrCreateViewForIndex(i);
164
324
  if (v)
@@ -168,7 +328,8 @@ export class SkiaLayout extends SkiaControl {
168
328
  }
169
329
  /** Drops realized cells and rebuilds the structure (DrawnUi ApplyItemsSource). */
170
330
  ApplyItemsSource() {
171
- this.ChildrenFactory.Initialize(this.itemTemplate, this.itemsSource ?? [], this.RecyclingTemplate);
331
+ this.ChildrenFactory.Initialize(this.itemTemplate, this.itemsSource ?? [], this.recyclingTemplate);
332
+ this.slots = undefined;
172
333
  this.structureDirty = true;
173
334
  this.InvalidateMeasure();
174
335
  }
@@ -204,11 +365,67 @@ export class SkiaLayout extends SkiaControl {
204
365
  get Views() { return this.IsTemplated ? this.ChildrenFactory.GetViewsInUse() : this.views; }
205
366
  /** Settable children list like DrawnUi Children (ignored while templated). */
206
367
  get Children() { return this.views; }
368
+ /**
369
+ * C# Children reset (ChildrenCollectionSync, 66a1eb02): the app's children the new list no longer holds are removed,
370
+ * the ones it gained are added, then all of them take the list's order inside the slots app children occupy, so the
371
+ * parts a control made itself keep their place.
372
+ */
207
373
  set Children(value) {
374
+ const keep = new Set(value);
375
+ for (const v of [...this.views])
376
+ if (v.IsChildrenItem && !keep.has(v))
377
+ this.RemoveSubView(v);
378
+ const inViews = new Set(this.views);
379
+ for (const v of value) {
380
+ v.IsChildrenItem = true;
381
+ if (!inViews.has(v))
382
+ this.AddSubView(v);
383
+ }
384
+ this.OrderChildren(value);
385
+ }
386
+ /**
387
+ * C# Insert / Move of a Children collection (the reconciler's appendChild / insertBefore): `child` goes before
388
+ * `before` among the app's children, or last without it. A new child is attached at the end of the views and an
389
+ * append stops there; otherwise the app's children take their new order inside the slots they occupy.
390
+ */
391
+ InsertChild(child, before) {
392
+ child.IsChildrenItem = true;
393
+ const attached = child.Parent === this && this.views.includes(child);
394
+ if (!attached)
395
+ this.AddSubView(child);
396
+ if (!attached && !before)
397
+ return;
398
+ const order = this.views.filter((v) => v.IsChildrenItem && v !== child);
399
+ const at = before ? order.indexOf(before) : -1;
400
+ order.splice(at < 0 ? order.length : at, 0, child);
401
+ this.OrderChildren(order);
402
+ }
403
+ /** C# OrderViews: the given children, in their order, inside the slots they occupy in the views; nothing else moves. */
404
+ OrderChildren(ordered) {
405
+ const inViews = new Set(this.views);
406
+ const present = ordered.filter((v) => inViews.delete(v));
407
+ if (present.length < 2)
408
+ return;
409
+ const isChild = new Set(present);
410
+ let next = 0, changed = false;
411
+ for (let i = 0; i < this.views.length && next < present.length; i++) {
412
+ if (!isChild.has(this.views[i]))
413
+ continue;
414
+ if (this.views[i] !== present[next]) {
415
+ this.views[i] = present[next];
416
+ changed = true;
417
+ }
418
+ next++;
419
+ }
420
+ if (changed) {
421
+ this.orderedViews = undefined;
422
+ this.InvalidateMeasure();
423
+ }
424
+ }
425
+ /** C# ClearChildren: removes every subview, the control's own parts included. */
426
+ ClearChildren() {
208
427
  for (const v of [...this.views])
209
428
  this.RemoveSubView(v);
210
- for (const v of value)
211
- this.AddSubView(v);
212
429
  }
213
430
  orderedViews;
214
431
  /** Static children sorted by ZIndex (stable), computed once per change (C# GetOrderedSubviews). */
@@ -235,10 +452,18 @@ export class SkiaLayout extends SkiaControl {
235
452
  }
236
453
  AddSubView(control) { this.InsertSubView(this.views.length, control); }
237
454
  InsertSubView(index, control) {
455
+ // already a child: a move (React reorders keyed children by inserting an existing one elsewhere), never a 2nd copy
456
+ const at = control.Parent === this ? this.views.indexOf(control) : -1;
457
+ if (at >= 0) {
458
+ this.views.splice(at, 1);
459
+ if (at < index)
460
+ index--;
461
+ }
238
462
  control.Parent = this;
239
- this.views.splice(index, 0, control);
463
+ this.views.splice(Math.min(Math.max(0, index), this.views.length), 0, control);
240
464
  this.orderedViews = undefined;
241
465
  this.InvalidateMeasure();
466
+ this.Superview?.Hover?.RequestCheck(); // a popup / page under a still mouse
242
467
  }
243
468
  RemoveSubView(control) {
244
469
  const i = this.views.indexOf(control);
@@ -248,6 +473,7 @@ export class SkiaLayout extends SkiaControl {
248
473
  this.orderedViews = undefined;
249
474
  control.Parent = undefined;
250
475
  this.InvalidateMeasure();
476
+ this.Superview?.Hover?.RequestCheck();
251
477
  }
252
478
  // ---- measure ----
253
479
  MeasureAbsolute(widthConstraint, heightConstraint, scale) {
@@ -263,6 +489,10 @@ export class SkiaLayout extends SkiaControl {
263
489
  const s = this.MeasureWrap(w, scale);
264
490
  return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
265
491
  }
492
+ if (this.IsMasonry) {
493
+ const s = this.MeasureMasonry(w, scale);
494
+ return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
495
+ }
266
496
  if (this.Type === "Grid") {
267
497
  const s = this.MeasureGrid(w, h, scale);
268
498
  return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
@@ -353,6 +583,60 @@ export class SkiaLayout extends SkiaControl {
353
583
  finishRow(true);
354
584
  return { w: maxW, h: this.wrapSlots.length ? y + rowH : 0 };
355
585
  }
586
+ get IsMasonry() { return this.Type === "Masonry"; }
587
+ /**
588
+ * C# MeasureMasonry / BuildMasonryLayout: Split columns of equal width, every item measured unbounded at the column
589
+ * width and put at the bottom of the shortest column (the first on a tie), so items of different heights leave no
590
+ * gaps; Spacing between columns and between items. Every item is laid out (no items window). A templated slot keeps
591
+ * the size of its item, so an appended page or an item that asked to be measured again (an image arrived) is the only
592
+ * one measured, and every item is placed again from the sizes known.
593
+ */
594
+ MeasureMasonry(width, scale) {
595
+ const columns = Math.max(1, this.Split);
596
+ const spacing = Math.round(this.Spacing * scale);
597
+ const columnWidth = columns > 1 ? Math.round((width - (columns - 1) * this.Spacing * scale) / columns) : width;
598
+ const bottoms = new Array(columns).fill(0), rows = new Array(columns).fill(0);
599
+ this.wrapSlots = [];
600
+ for (const v of this.LayoutViews()) {
601
+ if (!v.IsVisible)
602
+ continue;
603
+ let column = 0;
604
+ for (let c = 1; c < columns; c++)
605
+ if (bottoms[c] < bottoms[column])
606
+ column = c;
607
+ const h = v.Measure(columnWidth, Infinity, scale).Pixels.Height;
608
+ const x = column * (columnWidth + spacing), y = bottoms[column] + (rows[column]++ > 0 ? spacing : 0);
609
+ this.wrapSlots.push({ view: v, x, y, w: columnWidth, h });
610
+ bottoms[column] = y + h;
611
+ }
612
+ const used = Math.min(columns, this.wrapSlots.length);
613
+ return { w: used > 0 ? used * columnWidth + (used - 1) * spacing : 0, h: Math.max(0, ...bottoms) };
614
+ }
615
+ /**
616
+ * Where item `index` of a recycled templated Row / Wrap / Grid / split Column / Masonry was arranged (pixels), from
617
+ * its slot, also while no view shows it (ScrollToIndex to an item off screen); undefined otherwise.
618
+ */
619
+ GetItemRect(index) {
620
+ if (!this.IsRecycledLayout)
621
+ return undefined;
622
+ const d = this.slots?.[index]?.Destination;
623
+ return d && d.Width > 0 ? d : undefined;
624
+ }
625
+ /**
626
+ * Masonry: every placed item with its rect (pixels), in item order: what keyboard navigation follows, since the
627
+ * columns have uneven heights and the item `Split` places later is rarely under the focused one.
628
+ */
629
+ GetMasonryPlacement() {
630
+ if (!this.IsMasonry)
631
+ return [];
632
+ const r = this.DrawingRect, p = this.Padding, s = this.RenderingScale, left = r.Left + p.Left * s, top = r.Top + p.Top * s;
633
+ return this.wrapSlots.map((w) => ({
634
+ Index: w.view instanceof TemplatedSlot ? w.view.Index : this.IsTemplated ? w.view.ContextIndex : this.views.indexOf(w.view),
635
+ Rect: SKRect.Create(left + w.x, top + w.y, w.w, w.h),
636
+ }));
637
+ }
638
+ /** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
639
+ GetMasonryItemRect(index) { return this.IsMasonry ? this.GetItemRect(index) : undefined; }
356
640
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
357
641
  MeasureGrid(widthPx, heightPx, scale) {
358
642
  const wPts = widthPx / scale, hPts = heightPx / scale;
@@ -371,7 +655,7 @@ export class SkiaLayout extends SkiaControl {
371
655
  }
372
656
  });
373
657
  }
374
- const g = new SkiaGridStructure(this, wPts, hPts, scale);
658
+ const g = new SkiaGridStructure(this, wPts, hPts, scale, this.LayoutViews());
375
659
  g.DecompressStars(wPts, hPts);
376
660
  const needAutoWidth = this.WidthRequest < 0 && this.HorizontalOptions !== "Fill";
377
661
  const needAutoHeight = this.HeightRequest < 0 && this.VerticalOptions !== "Fill";
@@ -511,6 +795,11 @@ export class SkiaLayout extends SkiaControl {
511
795
  this.ChildrenFactory.ReleaseViewAt(index);
512
796
  return h;
513
797
  }
798
+ /**
799
+ * The item's offset and height are real, not estimated (C# LastMeasuredIndexLocal >= index): MeasureVisible knows
800
+ * them once the measured prefix passed the item; the other strategies always do.
801
+ */
802
+ IsItemMeasured(index) { return !this.IsTemplatedList || this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
514
803
  /** Pixel offset of item index from the top of the layout content (inside padding). */
515
804
  GetItemOffsetPixels(index) {
516
805
  const scale = this.RenderingScale;
@@ -536,13 +825,29 @@ export class SkiaLayout extends SkiaControl {
536
825
  OnLayoutChanged() {
537
826
  if (this.IsTemplatedList)
538
827
  return; // cells are arranged per frame for the visible range only
828
+ this.ArrangeChildren();
829
+ // views on screen follow their slots also when a cache above skips the drawing pass (gestures, accessibility)
830
+ if (this.IsRecycledLayout) {
831
+ const scale = this.RenderingScale;
832
+ for (const v of this.ChildrenFactory.GetViewsInUse()) {
833
+ const s = this.slots?.[v.ContextIndex];
834
+ if (s) {
835
+ v.Arrange(s.Destination, v.WidthRequest, v.HeightRequest, scale);
836
+ s.ArrangedView = v;
837
+ s.ArrangedFor = s.Destination;
838
+ }
839
+ }
840
+ }
841
+ }
842
+ /** Static children and realized views are arranged; the slots of a recycled layout record where their item goes. */
843
+ ArrangeChildren() {
539
844
  const scale = this.RenderingScale;
540
845
  const p = this.Padding;
541
846
  const r = this.DrawingRect;
542
847
  const inner = new SKRect(r.Left + p.Left * scale, r.Top + p.Top * scale, r.Right - p.Right * scale, r.Bottom - p.Bottom * scale);
543
848
  const gap = this.Spacing * scale;
544
849
  let cursor = this.Type === "Row" ? inner.Left : inner.Top;
545
- if (this.IsWrapFlow) {
850
+ if (this.IsWrapFlow || this.IsMasonry) {
546
851
  for (const s of this.wrapSlots)
547
852
  s.view.Arrange(SKRect.Create(inner.Left + s.x, inner.Top + s.y, s.w, s.h), s.view.WidthRequest, s.view.HeightRequest, scale);
548
853
  return;
@@ -582,12 +887,68 @@ export class SkiaLayout extends SkiaControl {
582
887
  this.PaintTemplated(ctx);
583
888
  return;
584
889
  }
890
+ if (this.IsRecycledLayout) {
891
+ this.PaintSlots(ctx);
892
+ return;
893
+ }
585
894
  const composing = this.IsRenderingWithComposition;
586
- for (const v of this.GetOrderedSubviews())
587
- if (!composing || this.DirtyChildrenInternal.has(v))
588
- v.Render(ctx);
895
+ for (const v of this.GetOrderedSubviews()) {
896
+ if (composing && !this.DirtyChildrenInternal.has(v))
897
+ continue;
898
+ v.Render(ctx); // a child entirely outside the clip skips itself
899
+ }
900
+ }
901
+ GetCompositeChildren() { return this.IsTemplatedList || this.IsRecycledLayout ? [] : this.GetOrderedSubviews(); }
902
+ drawnSlots = new Set();
903
+ /**
904
+ * Recycled templated layout (C# DrawStack): a view from the pool is bound to each slot that can be seen and drawn
905
+ * there; the views of the other slots go back to the pool.
906
+ */
907
+ PaintSlots(ctx) {
908
+ const slots = this.slots ?? [], f = this.ChildrenFactory, scale = this.RenderingScale, area = this.SlotsArea();
909
+ const drawn = this.drawnSlots;
910
+ drawn.clear();
911
+ for (const s of slots) {
912
+ const d = s.Destination;
913
+ if (s.IsVisible && d.Right > area.Left && d.Left < area.Right && d.Bottom > area.Top && d.Top < area.Bottom)
914
+ drawn.add(s.Index);
915
+ }
916
+ f.ReleaseExcept(drawn);
917
+ this.FirstVisibleIndex = this.LastVisibleIndex = -1;
918
+ for (const i of drawn) {
919
+ const s = slots[i], view = f.GetOrCreateViewForIndex(i, true);
920
+ if (!view)
921
+ continue;
922
+ // a view last measured for another item is measured for this one; the whole size is compared because a Wrap has
923
+ // no main-axis size key (C# 3d7bd78f)
924
+ const has = view.MeasuredSize.Pixels, want = s.MeasuredSize.Pixels;
925
+ if (Math.abs(has.Width - want.Width) > 1 || Math.abs(has.Height - want.Height) > 1)
926
+ view.NeedMeasure = true;
927
+ const size = view.MeasuredSize;
928
+ view.Measure(s.WidthConstraint, s.HeightConstraint, scale);
929
+ if (s.ArrangedView !== view || s.ArrangedFor !== s.Destination || view.MeasuredSize !== size) {
930
+ view.Arrange(s.Destination, view.WidthRequest, view.HeightRequest, scale);
931
+ s.ArrangedView = view;
932
+ s.ArrangedFor = s.Destination;
933
+ }
934
+ view.Render(ctx);
935
+ if (this.FirstVisibleIndex < 0)
936
+ this.FirstVisibleIndex = i;
937
+ this.LastVisibleIndex = i;
938
+ }
939
+ }
940
+ /**
941
+ * Where slots are drawn (C# GetOnScreenVisibleArea): what can be seen, inflated by VirtualisationInflated. Under a
942
+ * cache (this layout's or an ancestor's, below the nearest scroll) every slot, because the cache is blitted later at
943
+ * other offsets.
944
+ */
945
+ SlotsArea() {
946
+ for (let c = this; c && !("ViewportOffsetY" in c); c = c.Parent)
947
+ if (c.UsingCacheType !== "None")
948
+ return this.DrawingRect;
949
+ const v = this.GetVisibleViewport(), inflate = this.VirtualisationInflated * this.RenderingScale;
950
+ return new SKRect(v.Left - inflate, v.Top - inflate, v.Right + inflate, v.Bottom + inflate);
589
951
  }
590
- GetCompositeChildren() { return this.IsTemplatedList ? [] : this.GetOrderedSubviews(); }
591
952
  /** Realizes, binds, arranges and draws only the cells intersecting the visible viewport (+ inflation). */
592
953
  PaintTemplated(ctx) {
593
954
  const items = this.itemsSource;
@@ -717,6 +1078,10 @@ export class SkiaLayer extends SkiaLayout {
717
1078
  export class SkiaGrid extends SkiaLayout {
718
1079
  constructor() { super(); this.Type = "Grid"; this.HorizontalOptions = "Fill"; }
719
1080
  }
1081
+ /** SkiaLayout Type=Masonry + Split 2 + HorizontalOptions=Fill (DrawnUi alias): columns, each item to the shortest one. */
1082
+ export class SkiaMasonry extends SkiaLayout {
1083
+ constructor() { super(); this.Type = "Masonry"; this.Split = 2; this.HorizontalOptions = "Fill"; }
1084
+ }
720
1085
  /** SkiaLayout Type=Wrap + HorizontalOptions=Fill (DrawnUi alias): responsive flow of fixed-size children. */
721
1086
  export class SkiaWrap extends SkiaLayout {
722
1087
  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) {
@@ -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
  }
@@ -33,9 +33,9 @@ export class SkiaProgress extends SkiaControl {
33
33
  set Max(v) { this.max = v; this.Update(); }
34
34
  /** Unset = per-style palette. */
35
35
  get TrackColor() { return this.trackColor ?? SkiaProgress.Palette(this.UsingControlStyle).track; }
36
- set TrackColor(v) { this.trackColor = v; this.Update(); }
36
+ set TrackColor(v) { this.trackColor = v; this.UpdateDraw(); }
37
37
  get ProgressColor() { return this.progressColor ?? SkiaProgress.Palette(this.UsingControlStyle).progress; }
38
- set ProgressColor(v) { this.progressColor = v; this.Update(); }
38
+ set ProgressColor(v) { this.progressColor = v; this.UpdateDraw(); }
39
39
  /** C# ResolvedTrackColor / ResolvedProgressColor / track heights per style. */
40
40
  static Palette(s) {
41
41
  switch (s) {
@@ -76,5 +76,8 @@ export class SkiaProgress extends SkiaControl {
76
76
  }
77
77
  paint.delete();
78
78
  }
79
- DefaultAccessibilityLabel() { return `${Math.round(this.Ratio * 100)}%`; }
79
+ /** Value between Min and Max, read as "65%"; the name is the app's AccessibilityLabel only (drawnui-cross 6c). */
80
+ get AccessibilityValue() {
81
+ return { Now: this.value, Min: this.min, Max: this.max, Step: 0, Text: `${Math.round(this.Ratio * 100)}%` };
82
+ }
80
83
  }
@@ -37,8 +37,7 @@ export class SkiaRadioButton extends SkiaToggle {
37
37
  return table[this.UsingControlStyle]?.[name];
38
38
  }
39
39
  CreateDefaultContent() {
40
- if (this.MinimumHeightRequest < 0)
41
- this.MinimumHeightRequest = 24;
40
+ this.SetMinimumContentHeight(24);
42
41
  const s = this.usingStyle;
43
42
  const size = s === "Unset" ? 18 : 20;
44
43
  const box = new SkiaLayout();
@@ -145,8 +144,10 @@ export class SkiaRadioButton extends SkiaToggle {
145
144
  super.OnToggledChanged();
146
145
  }
147
146
  ProcessGestures(args, apply) {
147
+ if (!this.RespondsToGestures)
148
+ return this.BlockedGestureResult(args); // a tap does not select it, nor reach controls under it
148
149
  if (args.Type === "Tapped") {
149
- if (!this.IsToggled && this.RespondsToGestures) {
150
+ if (!this.IsToggled) {
150
151
  this.IsToggled = true;
151
152
  return this;
152
153
  }
@@ -72,6 +72,6 @@ export declare class SkiaRichLabel extends SkiaLabel {
72
72
  private RenderDocument;
73
73
  /** Blocks are separated by one line break once something was emitted (C# hadParagraph). */
74
74
  private BeginBlock;
75
- /** Inline markdown: `code`, **bold**, __bold__, *italic*, _italic_, ~~strike~~, [text](url), backslash escapes. */
75
+ /** Inline markdown: `code`, ***bold italic***, ___bold italic___, **bold**, __bold__, *italic*, _italic_, ~~strike~~, [text](url), backslash escapes. */
76
76
  private RenderInlines;
77
77
  }