drawnui-react 0.1.0-preview.4 → 0.1.0-preview.40

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 (105) hide show
  1. package/README.md +119 -14
  2. package/SKIPPED.md +36 -26
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +18 -1
  5. package/dist/controls/DrawnGame.d.ts +44 -0
  6. package/dist/controls/DrawnGame.js +82 -0
  7. package/dist/controls/GridStructure.d.ts +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 +17 -3
  12. package/dist/controls/SkiaButton.js +26 -8
  13. package/dist/controls/SkiaCarousel.d.ts +22 -3
  14. package/dist/controls/SkiaCarousel.js +85 -9
  15. package/dist/controls/SkiaCheckbox.d.ts +0 -1
  16. package/dist/controls/SkiaCheckbox.js +2 -7
  17. package/dist/controls/SkiaDrawer.d.ts +15 -0
  18. package/dist/controls/SkiaDrawer.js +42 -7
  19. package/dist/controls/SkiaEditor.d.ts +48 -2
  20. package/dist/controls/SkiaEditor.js +268 -53
  21. package/dist/controls/SkiaGif.d.ts +7 -0
  22. package/dist/controls/SkiaGif.js +25 -4
  23. package/dist/controls/SkiaImage.d.ts +5 -0
  24. package/dist/controls/SkiaImage.js +48 -14
  25. package/dist/controls/SkiaLabel.d.ts +117 -9
  26. package/dist/controls/SkiaLabel.js +526 -80
  27. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  28. package/dist/controls/SkiaLabelFps.js +41 -0
  29. package/dist/controls/SkiaLayout.d.ts +89 -9
  30. package/dist/controls/SkiaLayout.js +364 -21
  31. package/dist/controls/SkiaLottie.js +5 -3
  32. package/dist/controls/SkiaProgress.d.ts +2 -1
  33. package/dist/controls/SkiaProgress.js +8 -5
  34. package/dist/controls/SkiaRadioButton.d.ts +2 -0
  35. package/dist/controls/SkiaRadioButton.js +16 -4
  36. package/dist/controls/SkiaRichLabel.d.ts +1 -1
  37. package/dist/controls/SkiaRichLabel.js +11 -1
  38. package/dist/controls/SkiaScroll.d.ts +35 -5
  39. package/dist/controls/SkiaScroll.js +252 -32
  40. package/dist/controls/SkiaScrollBar.d.ts +27 -0
  41. package/dist/controls/SkiaScrollBar.js +51 -2
  42. package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
  43. package/dist/controls/SkiaShaderCarousel.js +27 -5
  44. package/dist/controls/SkiaShape.d.ts +13 -2
  45. package/dist/controls/SkiaShape.js +50 -10
  46. package/dist/controls/SkiaSlider.d.ts +20 -2
  47. package/dist/controls/SkiaSlider.js +61 -7
  48. package/dist/controls/SkiaSprite.d.ts +4 -0
  49. package/dist/controls/SkiaSprite.js +22 -10
  50. package/dist/controls/SkiaSvg.d.ts +4 -0
  51. package/dist/controls/SkiaSvg.js +28 -4
  52. package/dist/controls/SkiaSwitch.d.ts +0 -1
  53. package/dist/controls/SkiaSwitch.js +4 -8
  54. package/dist/controls/SkiaToggle.d.ts +25 -5
  55. package/dist/controls/SkiaToggle.js +58 -5
  56. package/dist/controls/SnappingLayout.d.ts +12 -1
  57. package/dist/controls/SnappingLayout.js +21 -2
  58. package/dist/controls/TooltipStyle.d.ts +52 -0
  59. package/dist/controls/TooltipStyle.js +88 -0
  60. package/dist/core/Accessibility.d.ts +134 -0
  61. package/dist/core/Accessibility.js +675 -9
  62. package/dist/core/Animators.d.ts +37 -1
  63. package/dist/core/Animators.js +102 -9
  64. package/dist/core/Canvas.d.ts +222 -10
  65. package/dist/core/Canvas.js +698 -37
  66. package/dist/core/ControlStyle.d.ts +2 -0
  67. package/dist/core/ControlStyle.js +2 -0
  68. package/dist/core/Easing.d.ts +12 -1
  69. package/dist/core/Easing.js +25 -1
  70. package/dist/core/Gestures.d.ts +81 -2
  71. package/dist/core/Gestures.js +177 -3
  72. package/dist/core/Hover.d.ts +51 -0
  73. package/dist/core/Hover.js +140 -0
  74. package/dist/core/ImageEffects.d.ts +2 -0
  75. package/dist/core/ImageEffects.js +2 -0
  76. package/dist/core/KeyboardManager.d.ts +40 -0
  77. package/dist/core/KeyboardManager.js +98 -8
  78. package/dist/core/PopupWindows.d.ts +94 -0
  79. package/dist/core/PopupWindows.js +205 -0
  80. package/dist/core/ScrollAnimators.js +9 -0
  81. package/dist/core/Shaping.d.ts +40 -0
  82. package/dist/core/Shaping.js +224 -0
  83. package/dist/core/SkiaControl.d.ts +279 -10
  84. package/dist/core/SkiaControl.js +621 -64
  85. package/dist/core/SkiaEffect.d.ts +17 -0
  86. package/dist/core/SkiaEffect.js +43 -8
  87. package/dist/core/SkiaImageManager.js +1 -1
  88. package/dist/core/Super.d.ts +29 -2
  89. package/dist/core/Super.js +54 -3
  90. package/dist/core/Tooltips.d.ts +71 -0
  91. package/dist/core/Tooltips.js +205 -0
  92. package/dist/core/Types.d.ts +11 -1
  93. package/dist/core/Types.js +32 -1
  94. package/dist/core/ViewsAdapter.d.ts +7 -2
  95. package/dist/core/ViewsAdapter.js +10 -3
  96. package/dist/index.d.ts +6 -0
  97. package/dist/index.js +6 -0
  98. package/dist/react/SkiaShell.js +65 -26
  99. package/dist/react/index.d.ts +33 -4
  100. package/dist/react/index.js +157 -18
  101. package/dist/react/reconciler.d.ts +20 -0
  102. package/dist/react/reconciler.js +69 -14
  103. package/dist/vite/index.d.ts +9 -0
  104. package/dist/vite/index.js +36 -3
  105. package/package.json +61 -2
@@ -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;
@@ -46,12 +46,39 @@ export declare class Super {
46
46
  static readonly Fonts: Map<string, Map<number, Typeface>>;
47
47
  /** First registered font, or CanvasKit's built-in one. */
48
48
  static DefaultTypeface?: Typeface;
49
+ /**
50
+ * App-wide opt-in (drawnui-cross 6ar): a control without a `Tooltip` shows its `AccessibilityHint` as tooltip, else its
51
+ * `AccessibilityLabel` when it shows no text of its own, so icon buttons get their screen-reader name as tooltip.
52
+ */
53
+ static TooltipsFromAccessibility: boolean;
54
+ /** Look and timing of the tooltips (a `TooltipStyle`), for every canvas without its own. Read when a tooltip is built. */
55
+ static TooltipStyle?: import("./Tooltips").TooltipStyleLike;
49
56
  /** CanvasKit's built-in face: what an empty FontFamily resolves to, like C# SKTypeface.CreateDefault(). */
50
57
  static SkiaDefaultTypeface?: Typeface;
51
58
  private static readonly fontCache;
59
+ /** Every face loaded from data, each under a family of its own: the paragraph module shapes text with them (`Shaping`). */
60
+ static ShapingFonts?: TypefaceFontProvider;
61
+ private static readonly shapingFamilyOfFace;
62
+ private static readonly shapingFamilyOfFont;
63
+ /**
64
+ * A face from font file data, also usable for shaping (complex scripts, emoji sequences, right to left). Register fonts
65
+ * by alias with `Super.Fonts` / ConfigureFonts; this only makes the face. Undefined when the data is no font.
66
+ */
67
+ static LoadFace(data: ArrayBuffer | Uint8Array): Typeface | undefined;
68
+ /** The shaping family of a font made by GetFont, undefined for faces without shaping data (CanvasKit's built-in face). */
69
+ static ShapingFamilyOf(font: Font): string | undefined;
70
+ /** Any shaping family (the bidirectional pass needs one, its font does not matter). */
71
+ static AnyShapingFamily(): string | undefined;
52
72
  static UseDrawnUi(): DrawnUiBuilder;
53
73
  /** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
54
74
  static CacheEnabled: boolean;
75
+ /**
76
+ * Address every engine loader fetches a source from (images, sprites, fonts, SVG, GIF, Lottie, shaders); caches
77
+ * stay keyed by the source itself. Web-only, no C# counterpart. Default: a file listed in
78
+ * `globalThis.DrawnUiAssetStamps` (written into index.html by the `drawnUiAssetStamps()` Vite plugin) gets
79
+ * `?v=<content hash>`, so a browser never keeps an old copy of a changed file. Replace it to map sources elsewhere.
80
+ */
81
+ static ResolveAssetUrl: (source: string) => string;
55
82
  private static readonly colorCache;
56
83
  /**
57
84
  * 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);
@@ -116,12 +116,58 @@ export class Super {
116
116
  static Fonts = new Map();
117
117
  /** First registered font, or CanvasKit's built-in one. */
118
118
  static DefaultTypeface;
119
+ /**
120
+ * App-wide opt-in (drawnui-cross 6ar): a control without a `Tooltip` shows its `AccessibilityHint` as tooltip, else its
121
+ * `AccessibilityLabel` when it shows no text of its own, so icon buttons get their screen-reader name as tooltip.
122
+ */
123
+ static TooltipsFromAccessibility = false;
124
+ /** Look and timing of the tooltips (a `TooltipStyle`), for every canvas without its own. Read when a tooltip is built. */
125
+ static TooltipStyle;
119
126
  /** CanvasKit's built-in face: what an empty FontFamily resolves to, like C# SKTypeface.CreateDefault(). */
120
127
  static SkiaDefaultTypeface;
121
128
  static fontCache = new Map();
129
+ /** Every face loaded from data, each under a family of its own: the paragraph module shapes text with them (`Shaping`). */
130
+ static ShapingFonts;
131
+ static shapingFamilyOfFace = new Map();
132
+ static shapingFamilyOfFont = new WeakMap();
133
+ /**
134
+ * A face from font file data, also usable for shaping (complex scripts, emoji sequences, right to left). Register fonts
135
+ * by alias with `Super.Fonts` / ConfigureFonts; this only makes the face. Undefined when the data is no font.
136
+ */
137
+ static LoadFace(data) {
138
+ const CK = Super.CK;
139
+ Super.ShapingFonts ??= CK.TypefaceFontProvider.Make();
140
+ const family = `drawnui-shaping-${Super.shapingFamilyOfFace.size}`;
141
+ Super.ShapingFonts.registerFont(data, family);
142
+ const face = Super.ShapingFonts.matchFamilyStyle(family, { weight: CK.FontWeight.Normal, width: CK.FontWidth.Normal, slant: CK.FontSlant.Upright });
143
+ if (face) {
144
+ Super.shapingFamilyOfFace.set(face, family);
145
+ return face;
146
+ }
147
+ return CK.Typeface.MakeFreeTypeFaceFromData(data instanceof Uint8Array ? data.slice().buffer : data) ?? undefined;
148
+ }
149
+ /** The shaping family of a font made by GetFont, undefined for faces without shaping data (CanvasKit's built-in face). */
150
+ static ShapingFamilyOf(font) { return Super.shapingFamilyOfFont.get(font); }
151
+ /** Any shaping family (the bidirectional pass needs one, its font does not matter). */
152
+ static AnyShapingFamily() { for (const f of Super.shapingFamilyOfFace.values())
153
+ return f; return undefined; }
122
154
  static UseDrawnUi() { return new DrawnUiBuilder(); }
123
155
  /** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
124
156
  static CacheEnabled = true;
157
+ /**
158
+ * Address every engine loader fetches a source from (images, sprites, fonts, SVG, GIF, Lottie, shaders); caches
159
+ * stay keyed by the source itself. Web-only, no C# counterpart. Default: a file listed in
160
+ * `globalThis.DrawnUiAssetStamps` (written into index.html by the `drawnUiAssetStamps()` Vite plugin) gets
161
+ * `?v=<content hash>`, so a browser never keeps an old copy of a changed file. Replace it to map sources elsewhere.
162
+ */
163
+ static ResolveAssetUrl = (source) => {
164
+ const stamps = globalThis.DrawnUiAssetStamps;
165
+ if (!stamps)
166
+ return source;
167
+ const q = source.indexOf("?");
168
+ const v = stamps[(q < 0 ? source : source.slice(0, q)).replace(/^\.?\//, "")];
169
+ return v ? `${source}${q < 0 ? "?" : "&"}v=${v}` : source;
170
+ };
125
171
  static colorCache = new Map();
126
172
  /**
127
173
  * Color string -> CanvasKit color. Hex follows the MAUI/DrawnUi convention: #RGB, #ARGB, #RRGGBB, #AARRGGBB
@@ -183,11 +229,16 @@ export class Super {
183
229
  const resolved = Super.ResolveTypeface(alias, weight);
184
230
  font = new Super.CK.Font(resolved.Typeface, sizePx);
185
231
  font.setSubpixel(true);
232
+ // unhinted advances: the same text widths on every platform and engine (drawnui-cross 6f, DrawnUi.Rust fonts.rs)
233
+ font.setLinearMetrics(true);
186
234
  if (italic)
187
235
  font.setSkewX(-0.25);
188
236
  // no bold face registered: synthetic bold, like C# Font.Embolden = IsBold
189
237
  if (weight >= 600 && resolved.Weight < 600)
190
238
  font.setEmbolden(true);
239
+ const family = resolved.Typeface ? Super.shapingFamilyOfFace.get(resolved.Typeface) : undefined;
240
+ if (family)
241
+ Super.shapingFamilyOfFont.set(font, family);
191
242
  Super.fontCache.set(key, font);
192
243
  }
193
244
  return font;
@@ -0,0 +1,71 @@
1
+ import type { DrawingContext, SkiaControl } from "./SkiaControl";
2
+ import { SKRect } from "./Types";
3
+ /** What the tooltip controller reads from a style (the TooltipStyle class in the controls implements it). */
4
+ export interface TooltipStyleLike {
5
+ MaxWidth: number;
6
+ ShowDelayMs: number;
7
+ FollowWindowMs: number;
8
+ AtCursor: boolean;
9
+ OffsetX: number;
10
+ OffsetY: number;
11
+ CreateTooltip?: (text: string) => SkiaControl;
12
+ CreateDefault(text: string): SkiaControl;
13
+ }
14
+ /** The canvas side the controller needs. */
15
+ interface TooltipHostCanvas {
16
+ readonly RenderingScale: number;
17
+ Update(): void;
18
+ DisposeObject(o: {
19
+ Dispose(): void;
20
+ }): void;
21
+ readonly TooltipStyleUsed: TooltipStyleLike;
22
+ }
23
+ /**
24
+ * The tooltip of one canvas (drawnui-cross 6ar, C# DrawnView.Tooltip): after the mouse rests on the innermost control
25
+ * with tooltip text, its tooltip shows, attached to it; the next one shows at once while one is shown or just closed.
26
+ * It closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch, and after a
27
+ * press stays closed until the mouse reaches another control. Separate from hover. Drawn last, inside the canvas, with
28
+ * no input and no accessibility node.
29
+ */
30
+ export declare class TooltipController {
31
+ private readonly canvas;
32
+ private owner?;
33
+ private text?;
34
+ private suppressed?;
35
+ private shownText?;
36
+ private anchor;
37
+ private pointer;
38
+ private cursor;
39
+ private closedAt;
40
+ private timer;
41
+ private keysHooked;
42
+ private view?;
43
+ private viewText?;
44
+ private viewRect;
45
+ private viewScale;
46
+ constructor(canvas: TooltipHostCanvas);
47
+ /** The text of the tooltip shown now, undefined when none is shown. */
48
+ get ShownText(): string | undefined;
49
+ /**
50
+ * The mouse moved, nothing pressed: `path` is the hover hit path (root first), (x, y) the pointer in canvas pixels.
51
+ * The innermost control with tooltip text wins.
52
+ */
53
+ OnPointerMove(path: readonly SkiaControl[], x: number, y: number): void;
54
+ private Show;
55
+ private CancelTimer;
56
+ /** Closes the tooltip and cancels a pending one. */
57
+ private Hide;
58
+ /** Any input that is not a plain mouse move (press, wheel, key, window blur): closed until the mouse reaches another control. */
59
+ CloseOnInput(): void;
60
+ /** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
61
+ /** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
62
+ ForgetGone(gone: (c: SkiaControl | undefined) => boolean): void;
63
+ Reset(): void;
64
+ private readonly onKey;
65
+ private readonly onChar;
66
+ private HookKeys;
67
+ /** Draws the tooltip over everything, inside `bounds` (canvas pixels). */
68
+ Draw(ctx: DrawingContext, bounds: SKRect): void;
69
+ Dispose(): void;
70
+ }
71
+ export {};
@@ -0,0 +1,205 @@
1
+ import { SKPoint } from "./Gestures";
2
+ import { SKRect } from "./Types";
3
+ import { KeyboardManager } from "./KeyboardManager";
4
+ /** Where a control is on the canvas now, in pixels: through caches, scroll offsets and transforms (C# OnScreenRect). */
5
+ function OnScreenRect(control) {
6
+ const r = control.GetAccessibilityPixelRect();
7
+ return r.Width > 0 || r.Height > 0 ? r : control.DrawingRect;
8
+ }
9
+ /**
10
+ * The tooltip of one canvas (drawnui-cross 6ar, C# DrawnView.Tooltip): after the mouse rests on the innermost control
11
+ * with tooltip text, its tooltip shows, attached to it; the next one shows at once while one is shown or just closed.
12
+ * It closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch, and after a
13
+ * press stays closed until the mouse reaches another control. Separate from hover. Drawn last, inside the canvas, with
14
+ * no input and no accessibility node.
15
+ */
16
+ export class TooltipController {
17
+ canvas;
18
+ owner;
19
+ text;
20
+ suppressed;
21
+ shownText;
22
+ anchor = SKRect.Empty;
23
+ pointer = SKPoint.Empty;
24
+ cursor = SKPoint.Empty;
25
+ closedAt = 0;
26
+ timer = 0;
27
+ keysHooked = false;
28
+ view;
29
+ viewText;
30
+ viewRect = SKRect.Empty;
31
+ viewScale = 0;
32
+ constructor(canvas) {
33
+ this.canvas = canvas;
34
+ }
35
+ /** The text of the tooltip shown now, undefined when none is shown. */
36
+ get ShownText() { return this.shownText; }
37
+ /**
38
+ * The mouse moved, nothing pressed: `path` is the hover hit path (root first), (x, y) the pointer in canvas pixels.
39
+ * The innermost control with tooltip text wins.
40
+ */
41
+ OnPointerMove(path, x, y) {
42
+ let owner, text;
43
+ for (let i = path.length - 1; i >= 0; i--) {
44
+ const c = path[i];
45
+ if (!c.MayHaveTooltip || c.IsDisposed)
46
+ continue;
47
+ text = c.GetTooltipText();
48
+ if (text) {
49
+ owner = c;
50
+ break;
51
+ }
52
+ }
53
+ // a press closed it: it stays closed until the mouse leaves that control
54
+ if (this.suppressed) {
55
+ if (owner === this.suppressed)
56
+ return;
57
+ this.suppressed = undefined;
58
+ }
59
+ if (!owner || !text) {
60
+ this.owner = undefined;
61
+ this.text = undefined;
62
+ this.Hide();
63
+ return;
64
+ }
65
+ this.pointer = new SKPoint(x, y);
66
+ if (owner === this.owner && text === this.text)
67
+ return; // still on the same control: the tooltip stays where it opened
68
+ this.owner = owner;
69
+ this.text = text;
70
+ this.HookKeys(true);
71
+ const style = this.canvas.TooltipStyleUsed;
72
+ this.CancelTimer();
73
+ if (this.shownText !== undefined || (this.closedAt !== 0 && performance.now() - this.closedAt < style.FollowWindowMs)) {
74
+ // moving from one tooltip to the next: no new wait
75
+ this.Show();
76
+ return;
77
+ }
78
+ this.timer = window.setTimeout(() => { this.timer = 0; if (this.owner)
79
+ this.Show(); }, Math.max(0, style.ShowDelayMs));
80
+ }
81
+ Show() {
82
+ if (!this.owner || !this.text)
83
+ return;
84
+ this.shownText = this.text;
85
+ this.anchor = OnScreenRect(this.owner);
86
+ this.cursor = this.pointer;
87
+ this.canvas.Update();
88
+ }
89
+ CancelTimer() { if (this.timer) {
90
+ clearTimeout(this.timer);
91
+ this.timer = 0;
92
+ } }
93
+ /** Closes the tooltip and cancels a pending one. */
94
+ Hide() {
95
+ this.CancelTimer();
96
+ if (!this.owner)
97
+ this.HookKeys(false);
98
+ if (this.shownText === undefined)
99
+ return;
100
+ this.shownText = undefined;
101
+ this.closedAt = performance.now();
102
+ this.canvas.Update();
103
+ }
104
+ /** Any input that is not a plain mouse move (press, wheel, key, window blur): closed until the mouse reaches another control. */
105
+ CloseOnInput() {
106
+ if (!this.owner && this.shownText === undefined)
107
+ return;
108
+ this.suppressed = this.owner;
109
+ this.owner = undefined;
110
+ this.text = undefined;
111
+ this.Hide();
112
+ this.HookKeys(false);
113
+ }
114
+ /** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
115
+ /** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
116
+ ForgetGone(gone) {
117
+ if (gone(this.suppressed))
118
+ this.suppressed = undefined;
119
+ if (gone(this.owner)) {
120
+ this.owner = undefined;
121
+ this.text = undefined;
122
+ this.Hide();
123
+ }
124
+ }
125
+ Reset() {
126
+ this.owner = undefined;
127
+ this.text = undefined;
128
+ this.suppressed = undefined;
129
+ this.Hide();
130
+ this.HookKeys(false);
131
+ }
132
+ onKey = () => this.CloseOnInput();
133
+ onChar = () => { };
134
+ HookKeys(on) {
135
+ if (on === this.keysHooked)
136
+ return;
137
+ this.keysHooked = on;
138
+ if (on)
139
+ KeyboardManager.Subscribe(this.onKey, this.onChar);
140
+ else
141
+ KeyboardManager.Unsubscribe(this.onKey, this.onChar);
142
+ }
143
+ /** Draws the tooltip over everything, inside `bounds` (canvas pixels). */
144
+ Draw(ctx, bounds) {
145
+ const text = this.shownText;
146
+ if (text === undefined) {
147
+ if (this.view) {
148
+ this.canvas.DisposeObject(this.view);
149
+ this.view = undefined;
150
+ this.viewText = undefined;
151
+ }
152
+ return;
153
+ }
154
+ const scale = ctx.Scale;
155
+ if (!this.view || this.viewText !== text || this.viewScale !== scale) {
156
+ if (this.view)
157
+ this.canvas.DisposeObject(this.view);
158
+ const style = this.canvas.TooltipStyleUsed;
159
+ const view = style.CreateTooltip?.(text) ?? style.CreateDefault(text);
160
+ view._superview = this.canvas;
161
+ view.Parent = undefined;
162
+ view.InputTransparent = true;
163
+ this.view = view;
164
+ this.viewText = text;
165
+ this.viewScale = scale;
166
+ // a finite width lets long text wrap: MaxWidth, never wider than the canvas
167
+ const margin = view.Margin;
168
+ const maxWidth = Math.min(bounds.Width, (style.MaxWidth + margin.HorizontalThickness) * scale);
169
+ const measured = view.Measure(maxWidth, Infinity, scale).Pixels;
170
+ const width = measured.Width, height = measured.Height;
171
+ // attached to its control (centered above it, below where there is no room) or at the cursor (below right of the
172
+ // pointer, above where there is no room); the offsets shift it, the vertical one mirrored on the flipped side
173
+ const boxWidth = width - margin.HorizontalThickness * scale, boxHeight = height - margin.VerticalThickness * scale;
174
+ const gap = 6 * scale, offsetX = style.OffsetX * scale, offsetY = style.OffsetY * scale;
175
+ const anchor = this.anchor, cursor = this.cursor;
176
+ let boxLeft, boxTop, flippedTop;
177
+ if (style.AtCursor) {
178
+ boxLeft = cursor.X + 4 * scale + offsetX;
179
+ boxTop = cursor.Y + 20 * scale + offsetY; // clear of the pointer's arrow
180
+ flippedTop = cursor.Y - gap - boxHeight - offsetY;
181
+ }
182
+ else {
183
+ boxLeft = (anchor.Left + anchor.Right) / 2 - boxWidth / 2 + offsetX;
184
+ boxTop = anchor.Top - gap - boxHeight + offsetY;
185
+ flippedTop = anchor.Bottom + gap - offsetY;
186
+ }
187
+ if (style.AtCursor ? boxTop + boxHeight > bounds.Bottom : boxTop < bounds.Top)
188
+ boxTop = flippedTop;
189
+ boxLeft = Math.max(bounds.Left, Math.min(boxLeft, bounds.Right - boxWidth));
190
+ boxTop = Math.max(bounds.Top, Math.min(boxTop, bounds.Bottom - boxHeight));
191
+ const left = boxLeft - margin.Left * scale, top = boxTop - margin.Top * scale;
192
+ this.viewRect = new SKRect(left, top, left + width, top + height);
193
+ view.Arrange(this.viewRect, view.WidthRequest, view.HeightRequest, scale);
194
+ }
195
+ this.view.Render({ Context: ctx.Context, Destination: this.viewRect, Scale: scale });
196
+ }
197
+ Dispose() {
198
+ this.CancelTimer();
199
+ this.HookKeys(false);
200
+ if (this.view) {
201
+ this.view.Dispose();
202
+ this.view = undefined;
203
+ }
204
+ }
205
+ }
@@ -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. */