drawnui-react 0.1.0-preview.23 → 0.1.0-preview.25

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.
@@ -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, SKRect, 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). */
@@ -157,7 +160,12 @@ export declare class SkiaLayout extends SkiaControl {
157
160
  * one measured, and every item is placed again from the sizes known.
158
161
  */
159
162
  private MeasureMasonry;
160
- /** Masonry: where the slot of item `index` was arranged (pixels), also while no view shows it; undefined otherwise. */
163
+ /**
164
+ * Where item `index` of a recycled templated Row / Wrap / Grid / split Column / Masonry was arranged (pixels), from
165
+ * its slot, also while no view shows it (ScrollToIndex to an item off screen); undefined otherwise.
166
+ */
167
+ GetItemRect(index: number): SKRect | undefined;
168
+ /** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
161
169
  GetMasonryItemRect(index: number): SKRect | undefined;
162
170
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
163
171
  private MeasureGrid;
@@ -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;
@@ -609,13 +612,18 @@ export class SkiaLayout extends SkiaControl {
609
612
  const used = Math.min(columns, this.wrapSlots.length);
610
613
  return { w: used > 0 ? used * columnWidth + (used - 1) * spacing : 0, h: Math.max(0, ...bottoms) };
611
614
  }
612
- /** Masonry: where the slot of item `index` was arranged (pixels), also while no view shows it; undefined otherwise. */
613
- GetMasonryItemRect(index) {
614
- if (!this.IsMasonry || !this.IsRecycledLayout)
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)
615
621
  return undefined;
616
622
  const d = this.slots?.[index]?.Destination;
617
623
  return d && d.Width > 0 ? d : undefined;
618
624
  }
625
+ /** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
626
+ GetMasonryItemRect(index) { return this.IsMasonry ? this.GetItemRect(index) : undefined; }
619
627
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
620
628
  MeasureGrid(widthPx, heightPx, scale) {
621
629
  const wPts = widthPx / scale, hPts = heightPx / scale;
@@ -778,7 +786,7 @@ export class SkiaLayout extends SkiaControl {
778
786
  * The item's offset and height are real, not estimated (C# LastMeasuredIndexLocal >= index): MeasureVisible knows
779
787
  * them once the measured prefix passed the item; the other strategies always do.
780
788
  */
781
- IsItemMeasured(index) { return this.IsMasonry || this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
789
+ IsItemMeasured(index) { return !this.IsTemplatedList || this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
782
790
  /** Pixel offset of item index from the top of the layout content (inside padding). */
783
791
  GetItemOffsetPixels(index) {
784
792
  const scale = this.RenderingScale;
@@ -871,8 +871,8 @@ 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
- // a masonry's recycled slots know every item's place, shown or not
875
- const r = layout.GetMasonryItemRect(i) ?? layout.ChildrenFactory.GetViewForIndex(i)?.DrawingRect;
874
+ // recycled slots know every item's place, shown or not
875
+ const r = layout.GetItemRect(i) ?? layout.ChildrenFactory.GetViewForIndex(i)?.DrawingRect;
876
876
  if (!r)
877
877
  return undefined;
878
878
  const c = this.content.DrawingRect;
@@ -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
  }
@@ -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> & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawnui-react",
3
- "version": "0.1.0-preview.23",
3
+ "version": "0.1.0-preview.25",
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)",
@@ -80,6 +80,8 @@
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
82
  "check:masonry": "node dev/check.mjs dev/check-masonry.ts",
83
+ "check:thickness": "node dev/check.mjs dev/check-thickness.ts",
84
+ "check:scroll-recycled": "node dev/check.mjs dev/check-scroll-recycled.ts",
83
85
  "site:extras": "node dev/site-extras.mjs dist/demo",
84
86
  "build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
85
87
  "prepublishOnly": "npm run build:lib",