drawnui-react 0.1.0-preview.22 → 0.1.0-preview.24

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.
package/SKIPPED.md CHANGED
@@ -70,6 +70,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
70
70
  | `ItemsSourceWindow` / `WindowSourceThreshold` (built-in window over huge sources) | not needed | The C# window bounds pipeline work (structures, pools, measures) for `MeasureFirst`/`MeasureAll` over big collections. React `MeasureVisible` measures on demand and keeps only visible cells realized, so the pipeline is already O(visible); memory of the array itself belongs to the app (paginate with `LoadMore*`). Revisit only if `MeasureAll` over 100k+ items becomes a requirement. |
71
71
  | `MeasureItemsStrategy="MeasureVisible"` + background measurement | ported | Initial pass measures enough items to fill the viewport (≥ `BackgroundMeasurementBatchSize`), content extent = exact prefix + average × remaining (C# MeasureList estimate), visible cells measured on demand and laid out with their real heights, the prefix grows in `requestIdleCallback` slices (time-budgeted, then one `InvalidateMeasure`), `LastMeasuredIndex`, `DebugString` shows `measured n/N`. Not ported: cancellation/`_pendingStructureChanges` interplay, `UsePreparedViews`, windowed sources, anchor correction when an estimate above the viewport changes (content may shift by the delta). |
72
72
  | `SkiaLayout` Wrap (static children) + `SkiaWrap` alias | ported | Left-to-right flow, `Spacing` between items and rows, row height = tallest item. Not ported: `Split`, main-axis `Fill` children sharing a row (1.9.7.4 flex-fill), `UseDynamicColumns`, RTL. |
73
+ | `SkiaLayout` Masonry + `SkiaMasonry` alias (Split 2, horizontal fill) | ported | C# `MeasureMasonry` / `BuildMasonryLayout`: `Split` columns of width round((width - (Split - 1) * Spacing) / Split), every visible item measured unbounded at that width and placed at the bottom of the shortest column (the first on a tie), `Spacing` between columns and items. Children or `ItemsSource` + `ItemTemplate` (recycled slots, taps, `ScrollToIndex` from the slot rect, `LoadMore`); a templated slot keeps its item's size, so an appended page or a changed item is the only one measured and every item is placed again. No items window. Content = used columns wide, tallest column high. `npm run check:masonry` (C# MasonryLayoutTests) |
73
74
  | `SkiaLayout` Grid (static children) + `SkiaGrid` alias | ported | Port of `SkiaGridStructure` (MAUI grid manager): `ColumnDefinitions`/`RowDefinitions` as `"*, 2*, Auto, 100"` or arrays, `DefaultColumnDefinition`/`DefaultRowDefinition` (Auto, like C#), `ColumnSpacing`/`RowSpacing`, child `Column`/`Row`/`ColumnSpan`/`RowSpan` (plain props instead of attached properties), implicit tracks, unknown/known measure passes, span resolution, star compression, Fill-child minimums, last-track stretch when the grid fills, remeasure at final cells. Not ported: `Split`/`Invert` (templated grids), `UseDynamicColumns`, `SkiaDecoratedGrid`, `GetOrderedSubviews` ZIndex ordering. |
74
75
  | `SkiaLabel` | partial | Word wrap (+ character break for long words), `MaxLines` with tail ellipsis, `LineBreakMode` (NoWrap / wraps / Tail; Head/Middle behave as Tail), `HorizontalTextAlignment` Start/Center/End (Fill* accepted, align Start), `VerticalTextAlignment`, `LineSpacing`, `LineHeight`, `FontWeight` + `FontAttributes` via faces registered per weight (`AddFont(src, alias, weight)`, nearest weight wins, synthetic bold (`setEmbolden`) when the nearest face is lighter than 600 — C# `Font.Embolden`; italic = synthetic skew when no italic face; empty `FontFamily` = the first registered family, weights included), `TextTransform`, `Padding`, `LinesCount`; defaults as C# (`FontSize` 12, `TextColor` GreenYellow). `FontFamilyFallback` ported and extended: comma-separated chain (`"FontSymbols,FontSymbols2"`), per-codepoint run segmentation, spaces always stay on the main font; `fonts.AddSymbols()` (`FontSymbols` = Noto Sans Math subset, `FontSymbols2` = Noto Sans Symbols 2 subset) and `fonts.AddEmojis()` (`FontEmoji` = Noto Color Emoji faces+hands subset) ship the same subsets as DrawnUi.Blazor. `Spans` ported as `<TextSpan>` children: `Text`, `TextColor`/`FontSize`/`FontFamily` (unset = inherit from the label, like C# HasSetColor/HasSetSize/HasSetFont), `FontWeight`, `IsBold`, `IsItalic`, `Underline`/`UnderlineWidth`, `Strikeout`/`StrikeoutWidth`/`StrikeoutColor` (Red default), `BackgroundColor`, `Tapped` + `ForceCaptureInput` (hit-tested through per-fragment `Rects`, ripple on the label, `OnSpanTapped` overridable), mixed sizes on one line share a baseline. TextSpan not ported: `ParagraphColor`, `CommandTapped`, per-span `LineSpacing`/`LineHeight`, `AutoFindFont`, `DrawingOffset`, `Shape`/glyph shaping. `CharacterSpacing` (C#: (value - 1) points after every glyph, measured, wrapped and cut at the drawn width), Chinese / Japanese line breaks between characters with kinsoku (C# FitAtBreak, `CanBreakInsideWord`). Not ported: `AutoFont`, `AutoSize`/`AutoSizeText`, `DropShadow*`, text `StrokeColor`/`StrokeWidth`/`StrokeGradient`, `GradientByLines`, `MonoForDigits`, `KeepSpacesOnLineBreaks`, `Format`, RTL/bidi, hyphenation, `SkiaRichLabel`/markdown. |
75
76
  | `SkiaHotspot` | ported | Fill/Fill, `Tapped`, `Down`, `Up`, `LockPanning`, `TouchDown`; consumes only Tapped like the C# one. No `AnimationTapped`/ripple/shimmer. |
@@ -1,6 +1,6 @@
1
1
  import { type DrawingContext, SkiaControl } from "../core/SkiaControl";
2
2
  import { type GestureEventProcessingInfo, type SkiaGesturesParameters } from "../core/Gestures";
3
- import { type Color, type DrawTextAlignment, type FontAttributes, type LineBreakMode, ScaledSize, type SkiaGradient, type TextAlignment, type TextTransform, Thickness } from "../core/Types";
3
+ import { type Color, type DrawTextAlignment, type FontAttributes, type LineBreakMode, ScaledSize, type SkiaGradient, type TextAlignment, type TextTransform, Thickness, type ThicknessValue } from "../core/Types";
4
4
  import { TextSpan } from "./TextSpan";
5
5
  /** One code point of the laid-out text: its UTF-16 index/length in Text and its box in pixels relative to DrawingRect. */
6
6
  export interface GlyphBox {
@@ -103,7 +103,7 @@ export declare class SkiaLabel extends SkiaControl {
103
103
  get TextTransform(): TextTransform;
104
104
  set TextTransform(v: TextTransform);
105
105
  get Padding(): Thickness;
106
- set Padding(v: Thickness);
106
+ set Padding(v: ThicknessValue);
107
107
  /** Number of laid-out lines after the last measure. */
108
108
  get LinesCount(): number;
109
109
  AddSubView(control: SkiaControl | TextSpan): void;
@@ -96,7 +96,7 @@ export class SkiaLabel extends SkiaControl {
96
96
  get TextTransform() { return this.textTransform; }
97
97
  set TextTransform(v) { this.Set("textTransform", v); }
98
98
  get Padding() { return this.padding; }
99
- set Padding(v) { this.Set("padding", v); }
99
+ set Padding(v) { this.Set("padding", Thickness.From(v)); }
100
100
  /** Number of laid-out lines after the last measure. */
101
101
  get LinesCount() { return this.lines.length; }
102
102
  // ---- spans as children (reconciler AddSubView / InsertSubView / RemoveSubView) ----
@@ -1,6 +1,6 @@
1
1
  import { type DrawingContext, SkiaControl } from "../core/SkiaControl";
2
2
  import { ViewsAdapter } from "../core/ViewsAdapter";
3
- import { type GridLength, type LayoutType, type MeasuringStrategy, type RecyclingTemplate, ScaledSize, type ShapeType, Thickness } from "../core/Types";
3
+ import { type GridLength, type LayoutType, type MeasuringStrategy, type RecyclingTemplate, SKRect, ScaledSize, type ShapeType, Thickness, type ThicknessValue } from "../core/Types";
4
4
  import { SkiaGridStructure } from "./GridStructure";
5
5
  /**
6
6
  * Mirrors DrawnUi SkiaLayout (Absolute / Column / Row / Wrap / Grid).
@@ -16,7 +16,10 @@ export declare class SkiaLayout extends SkiaControl {
16
16
  /** Layout type. SkiaShape redeclares it as ShapeType (any shape value lays out as Absolute), like the C# hidden Type. */
17
17
  Type: LayoutType | ShapeType;
18
18
  Spacing: number;
19
- Padding: Thickness;
19
+ private padding;
20
+ /** Space inside the layout around its children (points); a number is the same on every side (`Thickness.From`). */
21
+ get Padding(): Thickness;
22
+ set Padding(v: ThicknessValue);
20
23
  ColumnDefinitions?: string | GridLength[];
21
24
  RowDefinitions?: string | GridLength[];
22
25
  /** Track used for columns/rows a child references but no definition declares (C# default: Auto). */
@@ -148,6 +151,17 @@ export declare class SkiaLayout extends SkiaControl {
148
151
  * Split items; `DynamicColumns` lets a short last row spread over the width.
149
152
  */
150
153
  private MeasureWrap;
154
+ private get IsMasonry();
155
+ /**
156
+ * C# MeasureMasonry / BuildMasonryLayout: Split columns of equal width, every item measured unbounded at the column
157
+ * width and put at the bottom of the shortest column (the first on a tie), so items of different heights leave no
158
+ * gaps; Spacing between columns and between items. Every item is laid out (no items window). A templated slot keeps
159
+ * the size of its item, so an appended page or an item that asked to be measured again (an image arrived) is the only
160
+ * one measured, and every item is placed again from the sizes known.
161
+ */
162
+ private MeasureMasonry;
163
+ /** Masonry: where the slot of item `index` was arranged (pixels), also while no view shows it; undefined otherwise. */
164
+ GetMasonryItemRect(index: number): SKRect | undefined;
151
165
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
152
166
  private MeasureGrid;
153
167
  /** Templated Column: content = padding + sum of item heights + gaps; width = the constraint (cells fill). */
@@ -214,6 +228,10 @@ export declare class SkiaLayer extends SkiaLayout {
214
228
  export declare class SkiaGrid extends SkiaLayout {
215
229
  constructor();
216
230
  }
231
+ /** SkiaLayout Type=Masonry + Split 2 + HorizontalOptions=Fill (DrawnUi alias): columns, each item to the shortest one. */
232
+ export declare class SkiaMasonry extends SkiaLayout {
233
+ constructor();
234
+ }
217
235
  /** SkiaLayout Type=Wrap + HorizontalOptions=Fill (DrawnUi alias): responsive flow of fixed-size children. */
218
236
  export declare class SkiaWrap extends SkiaLayout {
219
237
  constructor();
@@ -82,7 +82,10 @@ export class SkiaLayout extends SkiaControl {
82
82
  /** Layout type. SkiaShape redeclares it as ShapeType (any shape value lays out as Absolute), like the C# hidden Type. */
83
83
  Type = "Absolute";
84
84
  Spacing = 0;
85
- 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); }
86
89
  // ---- grid (same names as DrawnUi; definitions as "*, 2*, Auto, 100" or an array) ----
87
90
  ColumnDefinitions;
88
91
  RowDefinitions;
@@ -144,7 +147,7 @@ export class SkiaLayout extends SkiaControl {
144
147
  return;
145
148
  const old = this.itemsSource;
146
149
  this.itemsSource = value;
147
- 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)) {
148
151
  this.InvalidateMeasure();
149
152
  return;
150
153
  }
@@ -308,8 +311,11 @@ export class SkiaLayout extends SkiaControl {
308
311
  return this.views;
309
312
  const n = this.itemsSource.length;
310
313
  if (this.IsRecycledLayout) {
311
- if (this.slots?.length !== n)
312
- this.slots = Array.from({ length: n }, (_, i) => new TemplatedSlot(i, this.ChildrenFactory));
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
+ }
313
319
  return this.slots;
314
320
  }
315
321
  const out = [];
@@ -483,6 +489,10 @@ export class SkiaLayout extends SkiaControl {
483
489
  const s = this.MeasureWrap(w, scale);
484
490
  return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
485
491
  }
492
+ if (this.IsMasonry) {
493
+ const s = this.MeasureMasonry(w, scale);
494
+ return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
495
+ }
486
496
  if (this.Type === "Grid") {
487
497
  const s = this.MeasureGrid(w, h, scale);
488
498
  return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
@@ -573,6 +583,42 @@ export class SkiaLayout extends SkiaControl {
573
583
  finishRow(true);
574
584
  return { w: maxW, h: this.wrapSlots.length ? y + rowH : 0 };
575
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
+ /** Masonry: where the slot of item `index` was arranged (pixels), also while no view shows it; undefined otherwise. */
616
+ GetMasonryItemRect(index) {
617
+ if (!this.IsMasonry || !this.IsRecycledLayout)
618
+ return undefined;
619
+ const d = this.slots?.[index]?.Destination;
620
+ return d && d.Width > 0 ? d : undefined;
621
+ }
576
622
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
577
623
  MeasureGrid(widthPx, heightPx, scale) {
578
624
  const wPts = widthPx / scale, hPts = heightPx / scale;
@@ -735,7 +781,7 @@ export class SkiaLayout extends SkiaControl {
735
781
  * The item's offset and height are real, not estimated (C# LastMeasuredIndexLocal >= index): MeasureVisible knows
736
782
  * them once the measured prefix passed the item; the other strategies always do.
737
783
  */
738
- IsItemMeasured(index) { return this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
784
+ IsItemMeasured(index) { return this.IsMasonry || this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
739
785
  /** Pixel offset of item index from the top of the layout content (inside padding). */
740
786
  GetItemOffsetPixels(index) {
741
787
  const scale = this.RenderingScale;
@@ -783,7 +829,7 @@ export class SkiaLayout extends SkiaControl {
783
829
  const inner = new SKRect(r.Left + p.Left * scale, r.Top + p.Top * scale, r.Right - p.Right * scale, r.Bottom - p.Bottom * scale);
784
830
  const gap = this.Spacing * scale;
785
831
  let cursor = this.Type === "Row" ? inner.Left : inner.Top;
786
- if (this.IsWrapFlow) {
832
+ if (this.IsWrapFlow || this.IsMasonry) {
787
833
  for (const s of this.wrapSlots)
788
834
  s.view.Arrange(SKRect.Create(inner.Left + s.x, inner.Top + s.y, s.w, s.h), s.view.WidthRequest, s.view.HeightRequest, scale);
789
835
  return;
@@ -1014,6 +1060,10 @@ export class SkiaLayer extends SkiaLayout {
1014
1060
  export class SkiaGrid extends SkiaLayout {
1015
1061
  constructor() { super(); this.Type = "Grid"; this.HorizontalOptions = "Fill"; }
1016
1062
  }
1063
+ /** SkiaLayout Type=Masonry + Split 2 + HorizontalOptions=Fill (DrawnUi alias): columns, each item to the shortest one. */
1064
+ export class SkiaMasonry extends SkiaLayout {
1065
+ constructor() { super(); this.Type = "Masonry"; this.Split = 2; this.HorizontalOptions = "Fill"; }
1066
+ }
1017
1067
  /** SkiaLayout Type=Wrap + HorizontalOptions=Fill (DrawnUi alias): responsive flow of fixed-size children. */
1018
1068
  export class SkiaWrap extends SkiaLayout {
1019
1069
  constructor() { super(); this.Type = "Wrap"; this.HorizontalOptions = "Fill"; }
@@ -871,10 +871,11 @@ export class SkiaScroll extends SkiaControl {
871
871
  else {
872
872
  // A templated Row / Wrap / Grid realizes every item (C# non-list layouts are not virtualized): read the cell's
873
873
  // arranged rect, like C# reads the structure cell's Destination.
874
- const cell = layout.ChildrenFactory.GetViewForIndex(i);
875
- if (!cell)
874
+ // a masonry's recycled slots know every item's place, shown or not
875
+ const r = layout.GetMasonryItemRect(i) ?? layout.ChildrenFactory.GetViewForIndex(i)?.DrawingRect;
876
+ if (!r)
876
877
  return undefined;
877
- const r = cell.DrawingRect, c = this.content.DrawingRect;
878
+ const c = this.content.DrawingRect;
878
879
  itemStart = (horizontal ? r.Left - c.Left : r.Top - c.Top) / scale;
879
880
  itemSize = (horizontal ? r.Width : r.Height) / scale;
880
881
  }
@@ -1,5 +1,5 @@
1
1
  import type { Canvas as SkCanvas, Image, Path, SkPicture, Surface } from "canvaskit-wasm";
2
- import { type Color, type LayoutOptions, SKRect, ScaledSize, type SkiaCacheType, type SkiaGradient, type SkiaTouchAnimation, Thickness } from "./Types";
2
+ import { type Color, type LayoutOptions, SKRect, ScaledSize, type SkiaCacheType, type SkiaGradient, type SkiaTouchAnimation, Thickness, type ThicknessValue } from "./Types";
3
3
  import { type AnimatorBase, type IOverlayEffect } from "./Animators";
4
4
  import { Easing } from "./Easing";
5
5
  import type { Canvas } from "./Canvas";
@@ -87,7 +87,10 @@ export declare class SkiaControl {
87
87
  Row: number;
88
88
  ColumnSpan: number;
89
89
  RowSpan: number;
90
- Margin: Thickness;
90
+ private margin;
91
+ /** Space around the control (points); a number is the same on every side, as C# XAML (`Thickness.From`). */
92
+ get Margin(): Thickness;
93
+ set Margin(v: ThicknessValue);
91
94
  /**
92
95
  * DrawnUi LockRatio: 0 = off; positive = square of the LARGER of the two sizes (requests or constraints),
93
96
  * negative = square of the SMALLER one. Infinite sides are ignored, so WidthRequest=150 + LockRatio=1 = 150x150.
@@ -110,7 +110,10 @@ export class SkiaControl {
110
110
  Row = 0;
111
111
  ColumnSpan = 1;
112
112
  RowSpan = 1;
113
- Margin = Thickness.Zero;
113
+ margin = Thickness.Zero;
114
+ /** Space around the control (points); a number is the same on every side, as C# XAML (`Thickness.From`). */
115
+ get Margin() { return this.margin; }
116
+ set Margin(v) { this.margin = Thickness.From(v); }
114
117
  /**
115
118
  * DrawnUi LockRatio: 0 = off; positive = square of the LARGER of the two sizes (requests or constraints),
116
119
  * negative = square of the SMALLER one. Infinite sides are ignored, so WidthRequest=150 + LockRatio=1 = 150x150.
@@ -1,6 +1,8 @@
1
1
  /** MAUI LayoutOptions subset used by DrawnUi. */
2
2
  export type LayoutOptions = "Start" | "Center" | "End" | "Fill";
3
3
  /** MAUI Thickness with the same ctor overloads: (all) / (horizontal, vertical) / (l, t, r, b). */
4
+ /** What a Thickness-typed property accepts: a Thickness, a number (every side) or the C# string form "12" / "12,6" / "l,t,r,b". */
5
+ export type ThicknessValue = Thickness | number | string;
4
6
  export declare class Thickness {
5
7
  Left: number;
6
8
  Top: number;
@@ -8,6 +10,14 @@ export declare class Thickness {
8
10
  Bottom: number;
9
11
  constructor(a?: number, b?: number, c?: number, d?: number);
10
12
  static readonly Zero: Thickness;
13
+ private static warned?;
14
+ /**
15
+ * What a Thickness-typed property (Margin, Padding) is given, as a Thickness: a number is the same on every side
16
+ * (C# XAML `Padding="12"`), the C# string forms "12", "12,6" (horizontal, vertical) and "1,2,3,4" (left, top, right,
17
+ * bottom) are read the same way. Anything else is Zero with a one-time console warning: never NaN, which would
18
+ * blank the control.
19
+ */
20
+ static From(value: unknown): Thickness;
11
21
  get HorizontalThickness(): number;
12
22
  get VerticalThickness(): number;
13
23
  }
@@ -75,7 +85,7 @@ export type TextTransform = "None" | "Lowercase" | "Uppercase" | "Titlecase";
75
85
  /** DrawnUi DrawerDirection: the edge a SkiaDrawer slides from. */
76
86
  export type DrawerDirection = "FromBottom" | "FromTop" | "FromLeft" | "FromRight";
77
87
  /** DrawnUi LayoutType. */
78
- export type LayoutType = "Absolute" | "Column" | "Row" | "Wrap" | "Grid";
88
+ export type LayoutType = "Absolute" | "Column" | "Row" | "Wrap" | "Grid" | "Masonry";
79
89
  /** MAUI ReturnType: what the keyboard's return key means (SkiaEditor: Send submits a multiline editor). */
80
90
  export type ReturnType = "Default" | "Done" | "Go" | "Next" | "Search" | "Send";
81
91
  /** DrawnUi SkiaEditor.SkiaEditorKeyboard. */
@@ -1,5 +1,4 @@
1
1
  // Mirrors DrawnUi (.NET) value types with the same names. Units: points unless a name says Pixels.
2
- /** MAUI Thickness with the same ctor overloads: (all) / (horizontal, vertical) / (l, t, r, b). */
3
2
  export class Thickness {
4
3
  Left;
5
4
  Top;
@@ -21,6 +20,38 @@ export class Thickness {
21
20
  }
22
21
  }
23
22
  static Zero = new Thickness();
23
+ static warned;
24
+ /**
25
+ * What a Thickness-typed property (Margin, Padding) is given, as a Thickness: a number is the same on every side
26
+ * (C# XAML `Padding="12"`), the C# string forms "12", "12,6" (horizontal, vertical) and "1,2,3,4" (left, top, right,
27
+ * bottom) are read the same way. Anything else is Zero with a one-time console warning: never NaN, which would
28
+ * blank the control.
29
+ */
30
+ static From(value) {
31
+ if (value instanceof Thickness)
32
+ return value;
33
+ if (typeof value === "number" && Number.isFinite(value))
34
+ return new Thickness(value);
35
+ if (typeof value === "string") {
36
+ const n = value.split(",").map((s) => Number(s.trim()));
37
+ if (n.every((x) => Number.isFinite(x))) {
38
+ if (n.length === 1)
39
+ return new Thickness(n[0]);
40
+ if (n.length === 2)
41
+ return new Thickness(n[0], n[1]);
42
+ if (n.length === 4)
43
+ return new Thickness(n[0], n[1], n[2], n[3]);
44
+ }
45
+ }
46
+ if (value == null)
47
+ return Thickness.Zero;
48
+ const key = String(value);
49
+ if (!(Thickness.warned ??= new Set()).has(key)) {
50
+ Thickness.warned.add(key);
51
+ console.warn(`[DrawnUi] ${key} is not a thickness (a Thickness, a number, or "h,v" / "l,t,r,b"): 0 is used.`);
52
+ }
53
+ return Thickness.Zero;
54
+ }
24
55
  get HorizontalThickness() { return this.Left + this.Right; }
25
56
  get VerticalThickness() { return this.Top + this.Bottom; }
26
57
  }
@@ -1,6 +1,7 @@
1
1
  import { type CSSProperties, type FC, type ReactNode, type Ref } from "react";
2
2
  import { Canvas as CanvasView } from "../core/Canvas";
3
3
  import type { SkiaControl } from "../core/SkiaControl";
4
+ import type { Thickness, ThicknessValue } from "../core/Types";
4
5
  import type { SkiaLabel as SkiaLabelCtrl } from "../controls/SkiaLabel";
5
6
  import type { TextSpan as TextSpanCtrl } from "../controls/TextSpan";
6
7
  import type { SkiaRichLabel as SkiaRichLabelCtrl } from "../controls/SkiaRichLabel";
@@ -42,7 +43,7 @@ import type { GesturesMode } from "../core/Gestures";
42
43
  * and never appeared in completion.
43
44
  */
44
45
  type PropsOf<T> = Partial<{
45
- [K in keyof T as T[K] extends Function ? (undefined extends T[K] ? K : never) : K extends "Children" | "Views" | "Parent" | "Spans" | "GridStructure" | "AccessibilityId" | "IsAccessibilityElement" | "HasTransform" | "RenderTransformMatrix" | "RenderObjectPrevious" | "LastMeasuredIndex" | "ItemsInsertedAtStart" | "UsingControlStyle" | "Track" | "Thumb" | "FrameOn" | "FrameOff" | "ViewCheckOn" | "ViewOn" | "ViewText" | "Ratio" | "StartThumbX" | "EndThumbX" | "SnapPoints" | "CurrentPosition" | "CurrentSnap" | "ContentOffsetBounds" | "InTransition" | "CanAnimate" | "MaxIndex" | "ChildrenTotal" | "IsAtStart" | "IsAtEnd" | "ScrollProgress" | "ScrollAmount" | "TransitionProgress" | "LastIndex" | "ChildrenCount" | "Horizontal" | "Animator" | "Animation" | "IsPlaying" | "PlayWhenAvailable" | "TotalFrames" | "HasEffects" | "IsDisposed" | "Label" | "IsMultiline" | "HasSelection" | "LayoutVersion" | "LinesCount" | "MeasuredLineHeight" | "Focused" | "SpriteSheet" | "FrameWidth" | "FrameHeight" | "DurationMs" | "FrameDurationMs" | "CurrentSprite" | "Rects" | "HasTapHandler" | "HasDecorations" | "LinesCount" | "Superview" | "DrawingRect" | "MeasuredSize" | "RenderingScale" | "NeedMeasure" | "_superview" | "HitBoxAuto" | "TotalDown" | "TotalTapped" | "TouchDown" | "PostAnimators" | "LoadedSource" | "IsLoading" | "DisplayRect" | "AspectScale" | "Content" | "ContentSize" | "ContentOffsetBounds" | "OverscrollDistance" | "OverScrolled" | "IsUserPanning" | "IsUserFocused" | "IsScrolling" | "IsTemplated" | "FirstVisibleIndex" | "LastVisibleIndex" | "DebugString" | "ChildrenFactory" | "ContextIndex" | "RenderObject" | "UsingCacheType" | "TransitionEffect" | "TransitionFromIndex" | "TransitionToIndex" | "EffectPostRenderers" | "CachedImage" | "ImageBitmap" | "ShouldSubmitOnEnter" | "Header" | "Footer" | "RefreshIndicator" | "ScrollBar" | "ScrollBarHorizontal" | "IsRunning" | "VisibleRatio" | "CurrentIndex" | "LastCompositeRecord" | "DirtyChildrenInternal" | "IsRenderingWithComposition" | "IsHovered" ? never : K]: T[K];
46
+ [K in keyof T as T[K] extends Function ? (undefined extends T[K] ? K : never) : K extends "Children" | "Views" | "Parent" | "Spans" | "GridStructure" | "AccessibilityId" | "IsAccessibilityElement" | "HasTransform" | "RenderTransformMatrix" | "RenderObjectPrevious" | "LastMeasuredIndex" | "ItemsInsertedAtStart" | "UsingControlStyle" | "Track" | "Thumb" | "FrameOn" | "FrameOff" | "ViewCheckOn" | "ViewOn" | "ViewText" | "Ratio" | "StartThumbX" | "EndThumbX" | "SnapPoints" | "CurrentPosition" | "CurrentSnap" | "ContentOffsetBounds" | "InTransition" | "CanAnimate" | "MaxIndex" | "ChildrenTotal" | "IsAtStart" | "IsAtEnd" | "ScrollProgress" | "ScrollAmount" | "TransitionProgress" | "LastIndex" | "ChildrenCount" | "Horizontal" | "Animator" | "Animation" | "IsPlaying" | "PlayWhenAvailable" | "TotalFrames" | "HasEffects" | "IsDisposed" | "Label" | "IsMultiline" | "HasSelection" | "LayoutVersion" | "LinesCount" | "MeasuredLineHeight" | "Focused" | "SpriteSheet" | "FrameWidth" | "FrameHeight" | "DurationMs" | "FrameDurationMs" | "CurrentSprite" | "Rects" | "HasTapHandler" | "HasDecorations" | "LinesCount" | "Superview" | "DrawingRect" | "MeasuredSize" | "RenderingScale" | "NeedMeasure" | "_superview" | "HitBoxAuto" | "TotalDown" | "TotalTapped" | "TouchDown" | "PostAnimators" | "LoadedSource" | "IsLoading" | "DisplayRect" | "AspectScale" | "Content" | "ContentSize" | "ContentOffsetBounds" | "OverscrollDistance" | "OverScrolled" | "IsUserPanning" | "IsUserFocused" | "IsScrolling" | "IsTemplated" | "FirstVisibleIndex" | "LastVisibleIndex" | "DebugString" | "ChildrenFactory" | "ContextIndex" | "RenderObject" | "UsingCacheType" | "TransitionEffect" | "TransitionFromIndex" | "TransitionToIndex" | "EffectPostRenderers" | "CachedImage" | "ImageBitmap" | "ShouldSubmitOnEnter" | "Header" | "Footer" | "RefreshIndicator" | "ScrollBar" | "ScrollBarHorizontal" | "IsRunning" | "VisibleRatio" | "CurrentIndex" | "LastCompositeRecord" | "DirtyChildrenInternal" | "IsRenderingWithComposition" | "IsHovered" ? never : K]: T[K] extends Thickness ? ThicknessValue : T[K];
46
47
  }>;
47
48
  /** `ref` receives the engine control instance (react-reconciler getPublicInstance). */
48
49
  type LeafProps<T> = PropsOf<T> & {
@@ -58,6 +59,7 @@ export declare const SkiaStack: FC<LayoutProps<SkiaLayoutCtrl>>;
58
59
  export declare const SkiaRow: FC<LayoutProps<SkiaLayoutCtrl>>;
59
60
  export declare const SkiaLayer: FC<LayoutProps<SkiaLayoutCtrl>>;
60
61
  export declare const SkiaWrap: FC<LayoutProps<SkiaLayoutCtrl>>;
62
+ export declare const SkiaMasonry: FC<LayoutProps<SkiaLayoutCtrl>>;
61
63
  export declare const SkiaGrid: FC<LayoutProps<SkiaLayoutCtrl>>;
62
64
  /** Grid drawing gradient separator lines in its spacing (C# SkiaDecoratedGrid). */
63
65
  export declare const SkiaDecoratedGrid: FC<LayoutProps<SkiaDecoratedGridCtrl>>;
@@ -12,6 +12,7 @@ export const SkiaStack = "SkiaStack";
12
12
  export const SkiaRow = "SkiaRow";
13
13
  export const SkiaLayer = "SkiaLayer";
14
14
  export const SkiaWrap = "SkiaWrap";
15
+ export const SkiaMasonry = "SkiaMasonry";
15
16
  export const SkiaGrid = "SkiaGrid";
16
17
  /** Grid drawing gradient separator lines in its spacing (C# SkiaDecoratedGrid). */
17
18
  export const SkiaDecoratedGrid = "SkiaDecoratedGrid";
@@ -14,7 +14,7 @@ import { SkiaSlider } from "../controls/SkiaSlider";
14
14
  import { SkiaCarousel } from "../controls/SkiaCarousel";
15
15
  import { SkiaShaderCarousel } from "../controls/SkiaShaderCarousel";
16
16
  import { SkiaDrawer } from "../controls/SkiaDrawer";
17
- import { SkiaGrid, SkiaLayer, SkiaLayout, SkiaRow, SkiaStack, SkiaWrap } from "../controls/SkiaLayout";
17
+ import { SkiaGrid, SkiaLayer, SkiaLayout, SkiaMasonry, SkiaRow, SkiaStack, SkiaWrap } from "../controls/SkiaLayout";
18
18
  import { SkiaHotspot } from "../controls/SkiaHotspot";
19
19
  import { SkiaButton } from "../controls/SkiaButton";
20
20
  import { SkiaImage } from "../controls/SkiaImage";
@@ -33,7 +33,7 @@ import { SkiaScroll } from "../controls/SkiaScroll";
33
33
  import { SkiaFrame, SkiaShape } from "../controls/SkiaShape";
34
34
  /** JSX tag name -> engine class. Add a control here to expose it to React. */
35
35
  export const Registry = {
36
- SkiaLayout, SkiaStack, SkiaRow, SkiaLayer, SkiaWrap, SkiaGrid, SkiaDecoratedGrid, SkiaBackdrop, SkiaEditor, SkiaSprite, SkiaSpriteSet, SkiaLabel, SkiaLabelFps, SkiaRichLabel, TextSpan, SkiaHotspot, SkiaButton, SkiaImage, SkiaImageTiles, SkiaSvg, SkiaLottie, SkiaGif, SkiaScroll, SkiaScrollBar, RefreshIndicator, SkiaShape, SkiaFrame,
36
+ SkiaLayout, SkiaStack, SkiaRow, SkiaLayer, SkiaWrap, SkiaMasonry, SkiaGrid, SkiaDecoratedGrid, SkiaBackdrop, SkiaEditor, SkiaSprite, SkiaSpriteSet, SkiaLabel, SkiaLabelFps, SkiaRichLabel, TextSpan, SkiaHotspot, SkiaButton, SkiaImage, SkiaImageTiles, SkiaSvg, SkiaLottie, SkiaGif, SkiaScroll, SkiaScrollBar, RefreshIndicator, SkiaShape, SkiaFrame,
37
37
  SkiaSwitch, SkiaCheckbox, SkiaRadioButton, SkiaProgress, SkiaSlider, SkiaCarousel, SkiaShaderCarousel, SkiaDrawer,
38
38
  };
39
39
  const SKIP = new Set(["children", "key", "ref"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawnui-react",
3
- "version": "0.1.0-preview.22",
3
+ "version": "0.1.0-preview.24",
4
4
  "description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
5
5
  "license": "MIT",
6
6
  "author": "Nick Kovalsky (AppoMobi)",
@@ -79,6 +79,8 @@
79
79
  "check:shader-cache": "node dev/check.mjs dev/check-shader-cache.ts",
80
80
  "check:shader-content": "node dev/check.mjs dev/check-shader-content.ts",
81
81
  "check:backdrop": "node dev/check.mjs dev/check-backdrop.ts",
82
+ "check:masonry": "node dev/check.mjs dev/check-masonry.ts",
83
+ "check:thickness": "node dev/check.mjs dev/check-thickness.ts",
82
84
  "site:extras": "node dev/site-extras.mjs dist/demo",
83
85
  "build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
84
86
  "prepublishOnly": "npm run build:lib",