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

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 +78 -7
  25. package/dist/controls/SkiaLabel.js +379 -60
  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 +41 -3
@@ -119,12 +119,29 @@ export declare class SkiaShaderEffect extends SkiaEffect implements IPostRendere
119
119
  get NeedApply(): boolean;
120
120
  /** Loads (async, once) and compiles (sync) when needed; true when a compiled effect exists. */
121
121
  EnsureCompiled(): boolean;
122
+ /**
123
+ * C# ShouldInvalidateParentCache (default false): animation ticks, `SetUniform` and `UpdateUniforms()` only redraw
124
+ * this effect over the parent's cache (ancestor caches still redraw), because the effect paints over the parent's
125
+ * cached content and a uniform change needs no new cache. True: they also invalidate the parent's cache, so the parent
126
+ * re-renders its content on every change; set it when that content refreshes only through the effect's redraws (a
127
+ * custom Paint reading changing data without calling Update()). `Update()` always invalidates the cache.
128
+ */
129
+ ShouldInvalidateParentCache: boolean;
130
+ /** Call after changing a value only the shader reads (a uniform, an animation progress): redraws the effect over the parent's cache, or `Update()` when ShouldInvalidateParentCache is true. */
131
+ UpdateUniforms(): void;
122
132
  SetUniform(name: string, ...values: number[]): this;
123
133
  ReleaseFrozenSnapshot(): void;
124
134
  private DisposeImage;
125
135
  protected ApplyShaderSource(): void;
126
136
  /** Snapshot of what the parent painted (C# CreateSnapshot): the surface the pixels are on, mapped through its origin. */
127
137
  protected CreateSnapshot(ctx: DrawingContext, destination: SKRect): CachedTexture | undefined;
138
+ private frozenEpoch;
139
+ /** Canvas.GpuEpoch: GPU textures made before a WebGL context restore are made again. */
140
+ protected GpuEpoch(): number;
141
+ /** Where the parent was when the texture was frozen (Once): the texture moves with it, as its cache does. */
142
+ private frozenAt?;
143
+ private ParentOrigin;
144
+ private FollowParent;
128
145
  /** C# GetPrimaryTexture: the parent's cache, a frozen snapshot (Once) or nothing (Never). */
129
146
  protected GetPrimaryTexture(_ctx: DrawingContext, _destination: SKRect): CachedTexture | undefined;
130
147
  /** Image → shader with the effect's sampling, translated so texel (0,0) = bounds top-left; cached per image. */
@@ -2,7 +2,7 @@ import { SkiaValueAnimator } from "./Animators";
2
2
  import { Easing } from "./Easing";
3
3
  import { SkiaImageManager } from "./SkiaImageManager";
4
4
  import { Super } from "./Super";
5
- import { Thickness } from "./Types";
5
+ import { SKRect, Thickness } from "./Types";
6
6
  /**
7
7
  * Mirrors DrawnUi SkiaEffect: something attached to a control through `VisualEffects`. `Update()` re-renders the
8
8
  * parent (C# invalidates the parent's cache and redraws), `GetEffectMargin` reports what it paints outside the box.
@@ -116,11 +116,27 @@ export class SkiaShaderEffect extends SkiaEffect {
116
116
  }
117
117
  return this.compiled !== undefined;
118
118
  }
119
+ /**
120
+ * C# ShouldInvalidateParentCache (default false): animation ticks, `SetUniform` and `UpdateUniforms()` only redraw
121
+ * this effect over the parent's cache (ancestor caches still redraw), because the effect paints over the parent's
122
+ * cached content and a uniform change needs no new cache. True: they also invalidate the parent's cache, so the parent
123
+ * re-renders its content on every change; set it when that content refreshes only through the effect's redraws (a
124
+ * custom Paint reading changing data without calling Update()). `Update()` always invalidates the cache.
125
+ */
126
+ ShouldInvalidateParentCache = false;
127
+ /** Call after changing a value only the shader reads (a uniform, an animation progress): redraws the effect over the parent's cache, or `Update()` when ShouldInvalidateParentCache is true. */
128
+ UpdateUniforms() {
129
+ if (this.ShouldInvalidateParentCache) {
130
+ this.Update();
131
+ return;
132
+ }
133
+ this.Parent?.RepaintComposition();
134
+ }
119
135
  // ---- uniforms API (C# SetUniform overloads) ----
120
136
  SetUniform(name, ...values) {
121
137
  if (name && values.length > 0) {
122
138
  this.Uniforms.set(name, values);
123
- this.Update();
139
+ this.UpdateUniforms();
124
140
  }
125
141
  return this;
126
142
  }
@@ -129,6 +145,7 @@ export class SkiaShaderEffect extends SkiaEffect {
129
145
  this.DisposeImage(this.frozen.Image);
130
146
  this.frozen = undefined;
131
147
  this.frozenOwned = false;
148
+ this.frozenAt = undefined;
132
149
  }
133
150
  DisposeImage(image) {
134
151
  const sv = this.Parent?.Superview;
@@ -158,12 +175,27 @@ export class SkiaShaderEffect extends SkiaEffect {
158
175
  return undefined;
159
176
  return { Image: image, Bounds: destination, Origin: { X: ox, Y: oy } };
160
177
  }
178
+ frozenEpoch = 0;
179
+ /** Canvas.GpuEpoch: GPU textures made before a WebGL context restore are made again. */
180
+ GpuEpoch() { return this.Parent?.Superview?.GpuEpoch ?? 0; }
181
+ /** Where the parent was when the texture was frozen (Once): the texture moves with it, as its cache does. */
182
+ frozenAt;
183
+ ParentOrigin() { const r = this.Parent?.DrawingRect; return { X: r?.Left ?? 0, Y: r?.Top ?? 0 }; }
184
+ FollowParent(texture) {
185
+ if (!texture || !this.frozenAt)
186
+ return texture;
187
+ const now = this.ParentOrigin(), dx = now.X - this.frozenAt.X, dy = now.Y - this.frozenAt.Y;
188
+ if (dx === 0 && dy === 0)
189
+ return texture;
190
+ const b = texture.Bounds;
191
+ return { Image: texture.Image, Bounds: new SKRect(b.Left + dx, b.Top + dy, b.Right + dx, b.Bottom + dy), Origin: texture.Origin && { X: texture.Origin.X + dx, Y: texture.Origin.Y + dy } };
192
+ }
161
193
  /** C# GetPrimaryTexture: the parent's cache, a frozen snapshot (Once) or nothing (Never). */
162
194
  GetPrimaryTexture(_ctx, _destination) {
163
195
  switch (this.UseBackground) {
164
196
  case "Never": return undefined;
165
197
  case "Once":
166
- if (!this.AquiredBackground || !this.frozen) {
198
+ if (!this.AquiredBackground || !this.frozen || this.frozenEpoch !== this.GpuEpoch()) { // a frozen texture of a lost GPU context is taken again
167
199
  this.ReleaseFrozenSnapshot();
168
200
  let snapshot = this.Parent?.CachedImage;
169
201
  let owned = false;
@@ -175,9 +207,11 @@ export class SkiaShaderEffect extends SkiaEffect {
175
207
  this.frozen = snapshot;
176
208
  this.frozenOwned = owned;
177
209
  this.AquiredBackground = true;
210
+ this.frozenAt = this.ParentOrigin();
211
+ this.frozenEpoch = this.GpuEpoch();
178
212
  }
179
213
  }
180
- return this.frozen;
214
+ return this.FollowParent(this.frozen);
181
215
  default:
182
216
  return this.Parent?.CachedImage;
183
217
  }
@@ -228,7 +262,7 @@ export class SkiaShaderEffect extends SkiaEffect {
228
262
  static async FetchText(url) {
229
263
  let p = sourceCache.get(url);
230
264
  if (!p) {
231
- p = fetch(url).then((r) => { if (!r.ok)
265
+ p = fetch(Super.ResolveAssetUrl(url)).then((r) => { if (!r.ok)
232
266
  throw new Error(`${r.status} ${url}`); return r.text(); });
233
267
  sourceCache.set(url, p);
234
268
  }
@@ -420,7 +454,8 @@ export class ShaderDoubleTexturesEffect extends SkiaShaderEffect {
420
454
  return undefined;
421
455
  const w = Math.round(d.Width), h = Math.round(d.Height);
422
456
  const cur = slot === "p" ? this.resizedPrimary : this.resizedSecondary;
423
- if (cur && cur.source === source && cur.w === w && cur.h === h)
457
+ const epoch = this.GpuEpoch();
458
+ if (cur && cur.source === source && cur.w === w && cur.h === h && cur.epoch === epoch)
424
459
  return cur.image;
425
460
  const main = ctx.Context.Surface;
426
461
  if (!main)
@@ -435,7 +470,7 @@ export class ShaderDoubleTexturesEffect extends SkiaShaderEffect {
435
470
  const image = surface.makeImageSnapshot();
436
471
  surface.delete();
437
472
  cur?.image.delete();
438
- const entry = { source, w, h, image };
473
+ const entry = { source, w, h, epoch, image };
439
474
  if (slot === "p")
440
475
  this.resizedPrimary = entry;
441
476
  else
@@ -546,7 +581,7 @@ export class AnimatedShaderEffect extends SkiaShaderEffect {
546
581
  return;
547
582
  if (!this.Animator) {
548
583
  const a = new SkiaValueAnimator(parent);
549
- a.OnUpdated = (v) => { this.Progress = v; this.Update(); };
584
+ a.OnUpdated = (v) => { this.Progress = v; this.UpdateUniforms(); };
550
585
  a.Finished = () => this.Completed?.(this);
551
586
  this.Animator = a;
552
587
  }
@@ -39,7 +39,7 @@ export class SkiaImageManager {
39
39
  return inflight;
40
40
  }
41
41
  async Fetch(source, signal) {
42
- const response = await fetch(source, signal ? { signal } : undefined);
42
+ const response = await fetch(Super.ResolveAssetUrl(source), signal ? { signal } : undefined);
43
43
  if (!response.ok)
44
44
  throw new Error(`DrawnUi: ${response.status} loading image '${source}'`);
45
45
  const image = Super.CK.MakeImageFromEncoded(await response.arrayBuffer());
@@ -1,6 +1,6 @@
1
1
  import { Thickness } from "./Types";
2
2
  import { StylesCollection } from "./Styles";
3
- import type { CanvasKit, Font, Typeface } from "canvaskit-wasm";
3
+ import type { CanvasKit, Font, Typeface, TypefaceFontProvider } from "canvaskit-wasm";
4
4
  /** Mirrors DrawnUi.Net IFontCollection: fonts.AddFont(source, alias[, weight]), plus the Blazor-head AddSymbols/AddEmojis. */
5
5
  export declare class FontCollection {
6
6
  /** Where the shipped subset fonts are served from (the demo copies them to public/fonts). */
@@ -12,7 +12,7 @@ export declare class FontCollection {
12
12
  }[];
13
13
  /** Noto Sans Math + Symbols 2 subsets as "FontSymbols" / "FontSymbols2" (arrows, math, misc symbols) — DrawnUi.Blazor AddSymbols. */
14
14
  AddSymbols(): FontCollection;
15
- /** Noto Color Emoji subset (faces + hands) as "FontEmoji" — DrawnUi.Blazor AddEmojis. */
15
+ /** Noto Color Emoji subset (faces, hands, skin tones and a few objects) as "FontEmoji" — DrawnUi.Blazor AddEmojis. */
16
16
  AddEmojis(): FontCollection;
17
17
  /** Registers a face under an alias; weight 100..900 lets FontWeight / FontAttributes=Bold pick the right file. */
18
18
  AddFont(source: string, alias: string, weight?: number): FontCollection;
@@ -49,9 +49,29 @@ export declare class Super {
49
49
  /** CanvasKit's built-in face: what an empty FontFamily resolves to, like C# SKTypeface.CreateDefault(). */
50
50
  static SkiaDefaultTypeface?: Typeface;
51
51
  private static readonly fontCache;
52
+ /** Every face loaded from data, each under a family of its own: the paragraph module shapes text with them (`Shaping`). */
53
+ static ShapingFonts?: TypefaceFontProvider;
54
+ private static readonly shapingFamilyOfFace;
55
+ private static readonly shapingFamilyOfFont;
56
+ /**
57
+ * A face from font file data, also usable for shaping (complex scripts, emoji sequences, right to left). Register fonts
58
+ * by alias with `Super.Fonts` / ConfigureFonts; this only makes the face. Undefined when the data is no font.
59
+ */
60
+ static LoadFace(data: ArrayBuffer | Uint8Array): Typeface | undefined;
61
+ /** The shaping family of a font made by GetFont, undefined for faces without shaping data (CanvasKit's built-in face). */
62
+ static ShapingFamilyOf(font: Font): string | undefined;
63
+ /** Any shaping family (the bidirectional pass needs one, its font does not matter). */
64
+ static AnyShapingFamily(): string | undefined;
52
65
  static UseDrawnUi(): DrawnUiBuilder;
53
66
  /** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
54
67
  static CacheEnabled: boolean;
68
+ /**
69
+ * Address every engine loader fetches a source from (images, sprites, fonts, SVG, GIF, Lottie, shaders); caches
70
+ * stay keyed by the source itself. Web-only, no C# counterpart. Default: a file listed in
71
+ * `globalThis.DrawnUiAssetStamps` (written into index.html by the `drawnUiAssetStamps()` Vite plugin) gets
72
+ * `?v=<content hash>`, so a browser never keeps an old copy of a changed file. Replace it to map sources elsewhere.
73
+ */
74
+ static ResolveAssetUrl: (source: string) => string;
55
75
  private static readonly colorCache;
56
76
  /**
57
77
  * Color string -> CanvasKit color. Hex follows the MAUI/DrawnUi convention: #RGB, #ARGB, #RRGGBB, #AARRGGBB
@@ -13,7 +13,7 @@ export class FontCollection {
13
13
  return this.AddFont(FontCollection.ContentRoot + "NotoSansMathSymbols-Subset.ttf", "FontSymbols")
14
14
  .AddFont(FontCollection.ContentRoot + "NotoSansSymbols2-Subset.ttf", "FontSymbols2");
15
15
  }
16
- /** Noto Color Emoji subset (faces + hands) as "FontEmoji" — DrawnUi.Blazor AddEmojis. */
16
+ /** Noto Color Emoji subset (faces, hands, skin tones and a few objects) as "FontEmoji" — DrawnUi.Blazor AddEmojis. */
17
17
  AddEmojis() {
18
18
  return this.AddFont(FontCollection.ContentRoot + "NotoColorEmoji-Subset.ttf", "FontEmoji");
19
19
  }
@@ -46,8 +46,8 @@ export class DrawnUiBuilder {
46
46
  for (const f of this.fonts.Fonts) {
47
47
  let face = loaded.get(f.Source);
48
48
  if (!face) {
49
- const data = await (await fetch(f.Source)).arrayBuffer();
50
- face = Super.CK.Typeface.MakeFreeTypeFaceFromData(data) ?? undefined;
49
+ const data = await (await fetch(Super.ResolveAssetUrl(f.Source))).arrayBuffer();
50
+ face = Super.LoadFace(data);
51
51
  if (!face)
52
52
  throw new Error(`DrawnUi: cannot load font '${f.Source}'`);
53
53
  loaded.set(f.Source, face);
@@ -119,9 +119,48 @@ export class Super {
119
119
  /** CanvasKit's built-in face: what an empty FontFamily resolves to, like C# SKTypeface.CreateDefault(). */
120
120
  static SkiaDefaultTypeface;
121
121
  static fontCache = new Map();
122
+ /** Every face loaded from data, each under a family of its own: the paragraph module shapes text with them (`Shaping`). */
123
+ static ShapingFonts;
124
+ static shapingFamilyOfFace = new Map();
125
+ static shapingFamilyOfFont = new WeakMap();
126
+ /**
127
+ * A face from font file data, also usable for shaping (complex scripts, emoji sequences, right to left). Register fonts
128
+ * by alias with `Super.Fonts` / ConfigureFonts; this only makes the face. Undefined when the data is no font.
129
+ */
130
+ static LoadFace(data) {
131
+ const CK = Super.CK;
132
+ Super.ShapingFonts ??= CK.TypefaceFontProvider.Make();
133
+ const family = `drawnui-shaping-${Super.shapingFamilyOfFace.size}`;
134
+ Super.ShapingFonts.registerFont(data, family);
135
+ const face = Super.ShapingFonts.matchFamilyStyle(family, { weight: CK.FontWeight.Normal, width: CK.FontWidth.Normal, slant: CK.FontSlant.Upright });
136
+ if (face) {
137
+ Super.shapingFamilyOfFace.set(face, family);
138
+ return face;
139
+ }
140
+ return CK.Typeface.MakeFreeTypeFaceFromData(data instanceof Uint8Array ? data.slice().buffer : data) ?? undefined;
141
+ }
142
+ /** The shaping family of a font made by GetFont, undefined for faces without shaping data (CanvasKit's built-in face). */
143
+ static ShapingFamilyOf(font) { return Super.shapingFamilyOfFont.get(font); }
144
+ /** Any shaping family (the bidirectional pass needs one, its font does not matter). */
145
+ static AnyShapingFamily() { for (const f of Super.shapingFamilyOfFace.values())
146
+ return f; return undefined; }
122
147
  static UseDrawnUi() { return new DrawnUiBuilder(); }
123
148
  /** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
124
149
  static CacheEnabled = true;
150
+ /**
151
+ * Address every engine loader fetches a source from (images, sprites, fonts, SVG, GIF, Lottie, shaders); caches
152
+ * stay keyed by the source itself. Web-only, no C# counterpart. Default: a file listed in
153
+ * `globalThis.DrawnUiAssetStamps` (written into index.html by the `drawnUiAssetStamps()` Vite plugin) gets
154
+ * `?v=<content hash>`, so a browser never keeps an old copy of a changed file. Replace it to map sources elsewhere.
155
+ */
156
+ static ResolveAssetUrl = (source) => {
157
+ const stamps = globalThis.DrawnUiAssetStamps;
158
+ if (!stamps)
159
+ return source;
160
+ const q = source.indexOf("?");
161
+ const v = stamps[(q < 0 ? source : source.slice(0, q)).replace(/^\.?\//, "")];
162
+ return v ? `${source}${q < 0 ? "?" : "&"}v=${v}` : source;
163
+ };
125
164
  static colorCache = new Map();
126
165
  /**
127
166
  * Color string -> CanvasKit color. Hex follows the MAUI/DrawnUi convention: #RGB, #ARGB, #RRGGBB, #AARRGGBB
@@ -183,11 +222,16 @@ export class Super {
183
222
  const resolved = Super.ResolveTypeface(alias, weight);
184
223
  font = new Super.CK.Font(resolved.Typeface, sizePx);
185
224
  font.setSubpixel(true);
225
+ // unhinted advances: the same text widths on every platform and engine (drawnui-cross 6f, DrawnUi.Rust fonts.rs)
226
+ font.setLinearMetrics(true);
186
227
  if (italic)
187
228
  font.setSkewX(-0.25);
188
229
  // no bold face registered: synthetic bold, like C# Font.Embolden = IsBold
189
230
  if (weight >= 600 && resolved.Weight < 600)
190
231
  font.setEmbolden(true);
232
+ const family = resolved.Typeface ? Super.shapingFamilyOfFace.get(resolved.Typeface) : undefined;
233
+ if (family)
234
+ Super.shapingFamilyOfFont.set(font, family);
191
235
  Super.fontCache.set(key, font);
192
236
  }
193
237
  return font;
@@ -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
  }
@@ -16,6 +16,8 @@ export declare class ViewsAdapter {
16
16
  Created: number;
17
17
  constructor(parent: SkiaControl);
18
18
  get PoolSize(): number;
19
+ /** The items views are bound to. */
20
+ get Items(): readonly unknown[];
19
21
  get InUseCount(): number;
20
22
  /** New template / items / mode: every realized view is dropped (DrawnUi ApplyItemsSource). */
21
23
  Initialize(template: (() => SkiaControl) | undefined, items: readonly unknown[], recycling: RecyclingTemplate): void;
@@ -26,8 +28,11 @@ export declare class ViewsAdapter {
26
28
  ShiftIndices(by: number, items: readonly unknown[]): void;
27
29
  /** The realized view for an index, if any (no creation). */
28
30
  GetViewForIndex(index: number): SkiaControl | undefined;
29
- /** View bound to items[index]: existing, recycled from the pool, or freshly created. */
30
- GetOrCreateViewForIndex(index: number): SkiaControl | undefined;
31
+ /**
32
+ * View bound to items[index]: existing, recycled from the pool, or freshly created. `quiet`: bound before it is
33
+ * attached, so the rebind invalidates the view alone and not the layout, which measures or draws it right away.
34
+ */
35
+ GetOrCreateViewForIndex(index: number, quiet?: boolean): SkiaControl | undefined;
31
36
  /** Index left the visible range: recycled views go back to the pool, non-recycled ones stay realized. */
32
37
  ReleaseViewAt(index: number): void;
33
38
  /** Releases every realized index outside [first, last]. */
@@ -16,6 +16,8 @@ export class ViewsAdapter {
16
16
  this.parent = parent;
17
17
  }
18
18
  get PoolSize() { return this.pool.length; }
19
+ /** The items views are bound to. */
20
+ get Items() { return this.items; }
19
21
  get InUseCount() { return this.inUse.size; }
20
22
  /** New template / items / mode: every realized view is dropped (DrawnUi ApplyItemsSource). */
21
23
  Initialize(template, items, recycling) {
@@ -52,8 +54,11 @@ export class ViewsAdapter {
52
54
  }
53
55
  /** The realized view for an index, if any (no creation). */
54
56
  GetViewForIndex(index) { return this.inUse.get(index); }
55
- /** View bound to items[index]: existing, recycled from the pool, or freshly created. */
56
- GetOrCreateViewForIndex(index) {
57
+ /**
58
+ * View bound to items[index]: existing, recycled from the pool, or freshly created. `quiet`: bound before it is
59
+ * attached, so the rebind invalidates the view alone and not the layout, which measures or draws it right away.
60
+ */
61
+ GetOrCreateViewForIndex(index, quiet = false) {
57
62
  const existing = this.inUse.get(index);
58
63
  if (existing)
59
64
  return existing;
@@ -64,9 +69,11 @@ export class ViewsAdapter {
64
69
  view = this.template();
65
70
  this.Created++;
66
71
  }
67
- view.Parent = this.parent;
72
+ if (!quiet)
73
+ view.Parent = this.parent;
68
74
  view.ContextIndex = index;
69
75
  view.BindingContext = this.items[index];
76
+ view.Parent = this.parent;
70
77
  this.inUse.set(index, view);
71
78
  return view;
72
79
  }
package/dist/index.d.ts CHANGED
@@ -9,9 +9,11 @@ export * from "./core/SkiaControl";
9
9
  export * from "./core/Canvas";
10
10
  export * from "./controls/SkiaLayout";
11
11
  export * from "./core/Accessibility";
12
+ export * from "./core/Hover";
12
13
  export * from "./controls/SkiaLabel";
13
14
  export * from "./controls/TextSpan";
14
15
  export * from "./controls/SkiaRichLabel";
16
+ export * from "./controls/SkiaLabelFps";
15
17
  export * from "./core/ControlStyle";
16
18
  export * from "./core/ImageEffects";
17
19
  export * from "./controls/SkiaToggle";
@@ -40,6 +42,7 @@ export * from "./controls/SkiaBackdrop";
40
42
  export * from "./controls/SkiaEditor";
41
43
  export * from "./controls/SkiaSprite";
42
44
  export * from "./controls/SkiaSpriteSet";
45
+ export * from "./controls/DrawnGame";
43
46
  export * from "./core/KeyboardManager";
44
47
  export * from "./controls/AnimatedFramesRenderer";
45
48
  export * from "./controls/SkiaLottie";
package/dist/index.js CHANGED
@@ -9,9 +9,11 @@ export * from "./core/SkiaControl";
9
9
  export * from "./core/Canvas";
10
10
  export * from "./controls/SkiaLayout";
11
11
  export * from "./core/Accessibility";
12
+ export * from "./core/Hover";
12
13
  export * from "./controls/SkiaLabel";
13
14
  export * from "./controls/TextSpan";
14
15
  export * from "./controls/SkiaRichLabel";
16
+ export * from "./controls/SkiaLabelFps";
15
17
  export * from "./core/ControlStyle";
16
18
  export * from "./core/ImageEffects";
17
19
  export * from "./controls/SkiaToggle";
@@ -40,6 +42,7 @@ export * from "./controls/SkiaBackdrop";
40
42
  export * from "./controls/SkiaEditor";
41
43
  export * from "./controls/SkiaSprite";
42
44
  export * from "./controls/SkiaSpriteSet";
45
+ export * from "./controls/DrawnGame";
43
46
  export * from "./core/KeyboardManager";
44
47
  export * from "./controls/AnimatedFramesRenderer";
45
48
  export * from "./controls/SkiaLottie";
@@ -389,6 +389,12 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
389
389
  prev ? prev.TranslateToAsync(-dir * w, 0, TabsAnimationSpeed, TabsEasing) : Promise.resolve(),
390
390
  ]), TabsAnimationSpeed + 500);
391
391
  }
392
+ // the tab left stays mounted (its state kept): hidden first, then back in place for its next turn
393
+ if (prev) {
394
+ prev.IsVisible = false;
395
+ prev.TranslationX = 0;
396
+ prev.TranslationY = 0;
397
+ }
392
398
  setTabTransition(null);
393
399
  }, [hasTabs, Tabs, AnimateTabs, TabsAnimationSpeed]);
394
400
  // popstate: the browser popped OUR last entry (back) — or moved forward to a hash we can rebuild
@@ -405,7 +411,13 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
405
411
  }
406
412
  const onPop = () => {
407
413
  const depth = window.history.state?.[HISTORY_KEY] ?? 0;
408
- if (depth < history.current.length) {
414
+ const target = parseHash();
415
+ // a Back lands on one of OUR entries: its hash is the stack it was pushed with (the first N pages, N = the page
416
+ // entries below it). A typed hash or a plain <a href="#/route"> makes a new entry with no state (depth 0):
417
+ // that is a navigation to the hash, not a Back to the root
418
+ const pagesBelow = history.current.slice(0, depth).filter((k) => k === "page").length;
419
+ const back = depth < history.current.length && target.join("/") === live.current.stack.slice(0, pagesBelow).join("/");
420
+ if (back) {
409
421
  // back: unwind our entries down to depth
410
422
  void (async () => {
411
423
  while (history.current.length > depth) {
@@ -441,9 +453,8 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
441
453
  })();
442
454
  }
443
455
  else {
444
- // forward (depth grew), or the same depth with another hash = a plain <a href="#/route"> link or a typed hash:
456
+ // forward (depth grew), or another hash = a plain <a href="#/route"> link or a typed hash:
445
457
  // the hash names the pages, rebuild the stack without animation (overlays cannot be restored)
446
- const target = parseHash();
447
458
  if (depth === history.current.length && target.join("/") === live.current.stack.join("/"))
448
459
  return;
449
460
  history.current = target.map(() => "page");
@@ -466,28 +477,36 @@ export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBa
466
477
  const transitioning = transitions > 0 || leaving !== null;
467
478
  const rootBottom = hasTabs ? TabBarHeight + insets.Bottom : 0;
468
479
  const navTop = NavBarHeight + insets.Top;
469
- const rootNode = hasTabs ? RenderRoute(Tabs[selectedTab]?.route ?? "") : children;
480
+ // every tab keeps its root and its pages mounted (state, scroll positions), only the selected one shows (C# tab
481
+ // views, DrawnUi.Rust "tabs keep their stacks")
482
+ const tabIndexes = hasTabs ? Tabs.map((_, i) => i) : [0];
470
483
  const entering = tabTransition ? { TranslationX: tabTransition.dir * 0.75 * (typeof window !== "undefined" ? window.innerWidth : 0), Opacity: 0.001, ZIndex: 1 } : {};
471
- return (_jsx(ShellContext.Provider, { value: nav, children: _jsxs(SkiaLayer, { VerticalOptions: "Fill", children: [tabTransition && (_jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, 0, 0, rootBottom), ZIndex: 0, BackgroundColor: PageBackgroundColor, ref: (c) => { if (c)
472
- tabRoots.current.set(tabTransition.from, c); }, children: RenderRoute(Tabs[tabTransition.from]?.route ?? "") }, `tab-leaving-${tabTransition.from}`)), _jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, 0, 0, rootBottom), IsVisible: visiblePages.length === 0 || transitioning, BackgroundColor: hasTabs ? PageBackgroundColor : undefined, ...entering, ref: (c) => { if (c)
473
- tabRoots.current.set(selectedTab, c); }, children: rootNode }, hasTabs ? `tab-${selectedTab}` : "root"), visiblePages.map((r, i) => (_jsxs(PageHost, { route: r, speed: PagesAnimationSpeed, visible: r === topRoute || transitioning, background: PageBackgroundColor, bottom: rootBottom, register: (c) => { if (c)
484
+ return (_jsx(ShellContext.Provider, { value: nav, children: _jsxs(SkiaLayer, { VerticalOptions: "Fill", children: [tabIndexes.map((t) => {
485
+ const selected = t === selectedTab;
486
+ return (_jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, 0, 0, rootBottom), BackgroundColor: hasTabs ? PageBackgroundColor : undefined, IsVisible: selected ? visiblePages.length === 0 || transitioning : tabTransition?.from === t, ZIndex: 0, ...(selected ? entering : {}), ref: (c) => { if (c)
487
+ tabRoots.current.set(t, c); }, children: hasTabs ? RenderRoute(Tabs[t]?.route ?? "") : children }, hasTabs ? `tab-${t}` : "root"));
488
+ }), tabIndexes.flatMap((t) => (t === selectedTab ? visiblePages : stacks[t] ?? []).map((r, i) => (_jsxs(PageHost, { route: r, speed: PagesAnimationSpeed, active: t === selectedTab, visible: t === selectedTab && (r === topRoute || transitioning), background: PageBackgroundColor, bottom: rootBottom, register: (c) => { if (c)
474
489
  pageCtrls.current.set(r, c);
475
490
  else
476
- pageCtrls.current.delete(r); }, children: [_jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, navTop, 0, 0), children: RenderRoute(r) }), _jsxs(SkiaLayer, { HeightRequest: navTop, BackgroundColor: NavBarColor, Padding: new Thickness(0, insets.Top, 0, 0), children: [_jsx(SkiaButton, { Text: "\u2039 Back", BackgroundColor: "#00000000", TextColor: "#6EA8FE", FontSize: 16, VerticalOptions: "Center", Margin: new Thickness(8, 0), ApplyEffect: "Ripple", Tapped: () => void GoBackAsync(), AccessibilityRole: "button", AccessibilityLabel: "Back" }), _jsx(SkiaLabel, { Text: Titles?.[RouteName(r)] ?? RouteName(r), FontSize: 18, FontFamily: "FontTextBold", TextColor: Colors.White, HorizontalOptions: "Fill", HorizontalTextAlignment: "Center", VerticalOptions: "Center", MaxLines: 1, Margin: new Thickness(96, 0), AccessibilityRole: "heading" }), _jsx(SkiaButton, { Text: "Home", BackgroundColor: "#00000000", TextColor: "#6EA8FE", FontSize: 16, HorizontalOptions: "End", VerticalOptions: "Center", Margin: new Thickness(0, 0, 8, 0), ApplyEffect: "Ripple", Tapped: () => void PopToRootAsync(), AccessibilityRole: "button", AccessibilityLabel: "Home" }), _jsx(SkiaLayer, { HeightRequest: 1, VerticalOptions: "End", BackgroundColor: "#343A40" })] })] }, `${selectedTab}:${r}#${i}`))), hasTabs && (_jsxs(SkiaLayer, { HeightRequest: TabBarHeight + insets.Bottom, VerticalOptions: "End", BackgroundColor: TabBarColor, ZIndex: ShellDefaults.ZIndexModals - 1, BlockGesturesBelow: true, Padding: new Thickness(0, 0, 0, insets.Bottom), children: [_jsx(SkiaLayer, { HeightRequest: 1, BackgroundColor: "#343A40" }), _jsx(SkiaGrid, { ColumnDefinitions: Tabs.map(() => "*").join(","), HorizontalOptions: "Fill", VerticalOptions: "Fill", children: Tabs.map((t, i) => (_jsxs(SkiaLayer, { Column: i, HorizontalOptions: "Fill", VerticalOptions: "Fill", AnimationTapped: "Ripple", Tapped: () => void SelectTabAsync(i), AccessibilityRole: "button", AccessibilityLabel: t.title, children: [_jsx(SkiaLabel, { Text: t.title, FontSize: 13, FontFamily: i === selectedTab ? "FontTextBold" : undefined, TextColor: i === selectedTab ? ShellDefaults.TabSelectedColor : ShellDefaults.TabColor, HorizontalOptions: "Center", VerticalOptions: "Center", AccessibilityRole: "presentation" }), i === selectedTab && _jsx(SkiaShape, { Type: "Rectangle", HeightRequest: 3, WidthRequest: 36, CornerRadius: 2, BackgroundColor: ShellDefaults.TabSelectedColor, HorizontalOptions: "Center", VerticalOptions: "End" })] }, t.route))) })] })), modals.map((m) => m.node), popups.map((p) => p.node), toasts.map((t) => t.node)] }) }));
491
+ pageCtrls.current.delete(r); }, children: [_jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, navTop, 0, 0), children: RenderRoute(r) }), _jsxs(SkiaLayer, { HeightRequest: navTop, BackgroundColor: NavBarColor, Padding: new Thickness(0, insets.Top, 0, 0), children: [_jsx(SkiaButton, { Text: "\u2039 Back", BackgroundColor: "#00000000", TextColor: "#6EA8FE", FontSize: 16, VerticalOptions: "Center", Margin: new Thickness(8, 0), ApplyEffect: "Ripple", Tapped: () => void GoBackAsync(), AccessibilityRole: "button", AccessibilityLabel: "Back" }), _jsx(SkiaLabel, { Text: Titles?.[RouteName(r)] ?? RouteName(r), FontSize: 18, FontFamily: "FontTextBold", TextColor: Colors.White, HorizontalOptions: "Fill", HorizontalTextAlignment: "Center", VerticalOptions: "Center", MaxLines: 1, Margin: new Thickness(96, 0), AccessibilityRole: "heading" }), _jsx(SkiaButton, { Text: "Home", BackgroundColor: "#00000000", TextColor: "#6EA8FE", FontSize: 16, HorizontalOptions: "End", VerticalOptions: "Center", Margin: new Thickness(0, 0, 8, 0), ApplyEffect: "Ripple", Tapped: () => void PopToRootAsync(), AccessibilityRole: "button", AccessibilityLabel: "Home" }), _jsx(SkiaLayer, { HeightRequest: 1, VerticalOptions: "End", BackgroundColor: "#343A40" })] })] }, `${t}:${r}#${i}`)))), hasTabs && (_jsxs(SkiaLayer, { HeightRequest: TabBarHeight + insets.Bottom, VerticalOptions: "End", BackgroundColor: TabBarColor, ZIndex: ShellDefaults.ZIndexModals - 1, BlockGesturesBelow: true, Padding: new Thickness(0, 0, 0, insets.Bottom), children: [_jsx(SkiaLayer, { HeightRequest: 1, BackgroundColor: "#343A40" }), _jsx(SkiaGrid, { ColumnDefinitions: Tabs.map(() => "*").join(","), HorizontalOptions: "Fill", VerticalOptions: "Fill", children: Tabs.map((t, i) => (_jsxs(SkiaLayer, { Column: i, HorizontalOptions: "Fill", VerticalOptions: "Fill", AnimationTapped: "Ripple", Tapped: () => void SelectTabAsync(i), AccessibilityRole: "button", AccessibilityLabel: t.title, children: [_jsx(SkiaLabel, { Text: t.title, FontSize: 13, FontFamily: i === selectedTab ? "FontTextBold" : undefined, TextColor: i === selectedTab ? ShellDefaults.TabSelectedColor : ShellDefaults.TabColor, HorizontalOptions: "Center", VerticalOptions: "Center", AccessibilityRole: "presentation" }), i === selectedTab && _jsx(SkiaShape, { Type: "Rectangle", HeightRequest: 3, WidthRequest: 36, CornerRadius: 2, BackgroundColor: ShellDefaults.TabSelectedColor, HorizontalOptions: "Center", VerticalOptions: "End" })] }, t.route))) })] })), modals.map((m) => m.node), popups.map((p) => p.node), toasts.map((t) => t.node)] }) }));
477
492
  });
478
493
  /** A pushed page: slides in from the right on mount (C# SkiaViewSwitcher PushView), covers what is below. */
479
- function PageHost({ route, speed, visible, background, bottom, register, children }) {
494
+ function PageHost({ route, speed, active, visible, background, bottom, register, children }) {
480
495
  const ctrl = useRef(null);
496
+ // slides in once, when pushed; a page of another tab stays mounted and is registered only while its tab is selected
481
497
  useEffect(() => {
482
498
  const c = ctrl.current;
483
- if (!c)
484
- return;
485
- register(c);
486
- if (speed > 0) {
499
+ if (c && speed > 0) {
487
500
  c.TranslationX = CanvasWidthPts(c);
488
501
  void c.TranslateToAsync(0, 0, speed);
489
502
  }
490
- return () => register(null);
491
503
  }, [route]); // eslint-disable-line react-hooks/exhaustive-deps
504
+ useEffect(() => {
505
+ const c = ctrl.current;
506
+ if (!c || !active)
507
+ return;
508
+ register(c);
509
+ return () => register(null);
510
+ }, [route, active]); // eslint-disable-line react-hooks/exhaustive-deps
492
511
  return (_jsx(SkiaLayer, { ref: (c) => { ctrl.current = c; }, VerticalOptions: "Fill", HorizontalOptions: "Fill", Margin: new Thickness(0, 0, 0, bottom), BackgroundColor: background, IsVisible: visible, BlockGesturesBelow: true, children: children }));
493
512
  }