drawnui-react 0.1.0-preview.42 → 0.1.0-preview.43

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.
@@ -9,7 +9,15 @@ export declare class SKPoint {
9
9
  }
10
10
  /** Raw platform action (subset of TouchActionType). */
11
11
  export type TouchActionType = "Pressed" | "Moved" | "Released" | "Cancelled" | "Wheel" | "Pointer";
12
- /** Recognized gesture (TouchActionResult). LongPressing after Canvas.LongPressTimeMs held still; Pointer / Touch declared for parity, not produced. */
12
+ /** Gesture settings shared by every canvas (AppoMobi TouchEffect, same names on every DrawnUI engine). */
13
+ export declare class TouchEffect {
14
+ /**
15
+ * How long a press is held without moving past Canvas.TappedCancelMoveThresholdPoints to be a LongPressing, at the press
16
+ * point; its release sends no Tapped. A timer, no frames while waiting. Default 750 ms on every engine (drawnui-cross 6cf).
17
+ */
18
+ static LongPressTimeMsDefault: number;
19
+ }
20
+ /** Recognized gesture (TouchActionResult). LongPressing after TouchEffect.LongPressTimeMsDefault held still; Pointer / Touch declared for parity, not produced. */
13
21
  export type TouchActionResult = "Touch" | "Down" | "Up" | "Tapped" | "LongPressing" | "Panning" | "Wheel" | "Pointer";
14
22
  export type GesturesMode = "Disabled" | "Enabled" | "Lock";
15
23
  export type LockTouch = "Disabled" | "Enabled" | "PassNone" | "PassTap" | "PassTapAndLongPress";
@@ -114,6 +122,7 @@ export declare class TouchActionEventArgs {
114
122
  /** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
115
123
  Manipulation?: ManipulationInfo;
116
124
  Scale: number;
125
+ /** When the event happened (ms, performance.now() time): the browser event's timeStamp, now for one made in code. */
117
126
  Timestamp: number;
118
127
  /** ms since the previous event of the same pointer. */
119
128
  DeltaTimeMs: number;
@@ -10,6 +10,14 @@ export class SKPoint {
10
10
  Add(p) { return new SKPoint(this.X + p.X, this.Y + p.Y); }
11
11
  Subtract(p) { return new SKPoint(this.X - p.X, this.Y - p.Y); }
12
12
  }
13
+ /** Gesture settings shared by every canvas (AppoMobi TouchEffect, same names on every DrawnUI engine). */
14
+ export class TouchEffect {
15
+ /**
16
+ * How long a press is held without moving past Canvas.TappedCancelMoveThresholdPoints to be a LongPressing, at the press
17
+ * point; its release sends no Tapped. A timer, no frames while waiting. Default 750 ms on every engine (drawnui-cross 6cf).
18
+ */
19
+ static LongPressTimeMsDefault = 750;
20
+ }
13
21
  /** TouchActionEventArgs.DistanceInfo. Velocity is pixels per second. */
14
22
  export class DistanceInfo {
15
23
  Start = SKPoint.Empty;
@@ -194,6 +202,7 @@ export class TouchActionEventArgs {
194
202
  /** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
195
203
  Manipulation;
196
204
  Scale = 1;
205
+ /** When the event happened (ms, performance.now() time): the browser event's timeStamp, now for one made in code. */
197
206
  Timestamp = performance.now();
198
207
  /** ms since the previous event of the same pointer. */
199
208
  DeltaTimeMs = 0;
@@ -248,7 +257,9 @@ export class SkiaGesturesParameters {
248
257
  const p = new SkiaGesturesParameters();
249
258
  p.Type = action;
250
259
  p.Event = args;
251
- p.ArrivedTimeNanos = Math.round(performance.now() * 1e6);
260
+ // when its event happened, not when a frame got to it (a slow frame holds the events back; a double tap is judged
261
+ // by when the taps happened)
262
+ p.ArrivedTimeNanos = Math.round(args.Timestamp * 1e6);
252
263
  return p;
253
264
  }
254
265
  }
@@ -94,6 +94,8 @@ export class PopupLayer {
94
94
  }
95
95
  this.popups.push(popup);
96
96
  this.UpdateKeyboardScope();
97
+ // its nodes join the accessibility tree with its first frame (a Tab right after it opened goes into it)
98
+ a11y.ForceRebuildOnNextFrame();
97
99
  return popup.Id;
98
100
  }
99
101
  Close(id) { const p = this.popups.find((x) => x.Id === id); if (p)
@@ -72,8 +72,14 @@ export declare class VelocityAccumulator {
72
72
  private readonly samples;
73
73
  private static readonly MaxSampleSize;
74
74
  private static readonly ConsiderationTimeframeMs;
75
+ /** The clock (ms) the release is judged on, for checks that drive gestures on a virtual clock (C# ClockOverrideNanos). */
76
+ static Clock?: () => number;
75
77
  Clear(): void;
76
78
  CaptureVelocity(x: number, y: number, arrivedTimeNanos?: number): void;
79
+ /**
80
+ * The release velocity from the samples of the last 150 ms before NOW (as DrawnUi.Net): after a short app freeze a
81
+ * flick handled late does not fling (samples are dated by when their events happened).
82
+ */
77
83
  CalculateFinalVelocity(clampAbsolute?: number): {
78
84
  X: number;
79
85
  Y: number;
@@ -199,6 +199,8 @@ export class VelocityAccumulator {
199
199
  samples = [];
200
200
  static MaxSampleSize = 5;
201
201
  static ConsiderationTimeframeMs = 150;
202
+ /** The clock (ms) the release is judged on, for checks that drive gestures on a virtual clock (C# ClockOverrideNanos). */
203
+ static Clock;
202
204
  Clear() { this.samples.length = 0; }
203
205
  CaptureVelocity(x, y, arrivedTimeNanos = 0) {
204
206
  const time = arrivedTimeNanos > 0 ? arrivedTimeNanos / 1e6 : performance.now();
@@ -214,8 +216,12 @@ export class VelocityAccumulator {
214
216
  this.samples.shift();
215
217
  this.samples.push({ X: x, Y: y, time });
216
218
  }
219
+ /**
220
+ * The release velocity from the samples of the last 150 ms before NOW (as DrawnUi.Net): after a short app freeze a
221
+ * flick handled late does not fling (samples are dated by when their events happened).
222
+ */
217
223
  CalculateFinalVelocity(clampAbsolute = 0) {
218
- const now = performance.now();
224
+ const now = VelocityAccumulator.Clock?.() ?? performance.now();
219
225
  const relevant = this.samples.filter((s) => now - s.time <= VelocityAccumulator.ConsiderationTimeframeMs);
220
226
  if (relevant.length === 0)
221
227
  return { X: 0, Y: 0 };
@@ -4,6 +4,7 @@ import { type AnimatorBase, type IOverlayEffect } from "./Animators";
4
4
  import { Easing } from "./Easing";
5
5
  import type { Canvas } from "./Canvas";
6
6
  import type { InputKey } from "./KeyboardManager";
7
+ import type { BlendMode } from "./ImageEffects";
7
8
  import { ContextMenuEventArgs, ControlTappedEventArgs, GestureEventProcessingInfo, type LockTouch, SKPoint, SkiaGesturesInfo, SkiaGesturesParameters } from "./Gestures";
8
9
  import { type CachedTexture, type IPostRendererEffect, type SkiaEffect } from "./SkiaEffect";
9
10
  /** Mirrors DrawnUi DrawingContext: ctx.Context.Canvas / Surface, ctx.Destination (pixels), ctx.Scale. */
@@ -104,6 +105,8 @@ export declare class SkiaControl {
104
105
  BackgroundColor?: Color;
105
106
  /** Gradient painted as the background (over BackgroundColor). */
106
107
  FillGradient?: SkiaGradient;
108
+ /** Blend mode of the background fill, an SKBlendMode name (C# FillBlendMode); here a FillGradient's own BlendMode wins, on a SkiaShape this one does. */
109
+ FillBlendMode: BlendMode;
107
110
  IsVisible: boolean;
108
111
  Tag?: string;
109
112
  TranslationX: number;
@@ -459,8 +462,6 @@ export declare class SkiaControl {
459
462
  */
460
463
  get AccessibilityTextSelectable(): boolean;
461
464
  set AccessibilityTextSelectable(v: boolean);
462
- /** Text lines for AccessibilityTextSelectable in CSS px relative to the node (SkiaLabel implements it). */
463
- GetAccessibilityTextLines(_scale: number): import("./Accessibility").AccessibilityTextLine[];
464
465
  /** Hit rect in canvas pixels used to position the overlay element: the drawn (transformed) bounds, like C# HitBoxWithTransforms. */
465
466
  GetAccessibilityPixelRect(): SKRect;
466
467
  /** Registers on first call, marks the snapshot dirty afterwards. */
@@ -127,6 +127,8 @@ export class SkiaControl {
127
127
  BackgroundColor;
128
128
  /** Gradient painted as the background (over BackgroundColor). */
129
129
  FillGradient;
130
+ /** Blend mode of the background fill, an SKBlendMode name (C# FillBlendMode); here a FillGradient's own BlendMode wins, on a SkiaShape this one does. */
131
+ FillBlendMode = "SrcOver";
130
132
  IsVisible = true;
131
133
  Tag;
132
134
  // ---- render transforms (MAUI VisualElement names; points, applied at render around DrawingRect) ----
@@ -756,8 +758,6 @@ export class SkiaControl {
756
758
  this.accessibilityTextSelectable = v;
757
759
  this.AccessibilityChanged();
758
760
  } }
759
- /** Text lines for AccessibilityTextSelectable in CSS px relative to the node (SkiaLabel implements it). */
760
- GetAccessibilityTextLines(_scale) { return []; }
761
761
  /** Hit rect in canvas pixels used to position the overlay element: the drawn (transformed) bounds, like C# HitBoxWithTransforms. */
762
762
  GetAccessibilityPixelRect() {
763
763
  const r = this.DrawingRect, m = this.RenderTransformMatrix;
@@ -1361,6 +1361,8 @@ export class SkiaControl {
1361
1361
  paint.setAntiAlias(true);
1362
1362
  if (this.BackgroundColor)
1363
1363
  paint.setColor(Super.ParseColor(this.BackgroundColor));
1364
+ if (this.FillBlendMode !== "SrcOver")
1365
+ paint.setBlendMode(CK.BlendMode[this.FillBlendMode]);
1364
1366
  if (this.FillGradient && this.FillGradientPaintsBackground())
1365
1367
  this.SetupGradient(paint, this.FillGradient, rect);
1366
1368
  return paint;
@@ -36,11 +36,8 @@ export declare class SkiaImageManager {
36
36
  static HttpRetryMaxAttempts: number;
37
37
  /** Base address of relative sources (DrawnUi HttpBaseAddress); unset, they resolve against the page. */
38
38
  static HttpBaseAddress?: string;
39
- /**
40
- * C# CanReload: raised when a load failed (with its source and why) so the caller may retry later, and when
41
- * `IsLoadingLocked` is turned off (no arguments).
42
- */
43
- CanReload?: (source?: string, error?: Error) => void;
39
+ /** C# CanReload: raised when `IsLoadingLocked` is turned off, so what waited or failed meanwhile may load again. */
40
+ CanReload?: () => void;
44
41
  private readonly cache;
45
42
  /** Every image the manager made and still tracks: cached ones and the copies it handed out. */
46
43
  private readonly owned;
@@ -109,9 +106,13 @@ export declare class SkiaImageManager {
109
106
  /**
110
107
  * Queued, cached load (C# LoadImageManagedAsync): a cached image resolves at once, the rest wait their turn by priority;
111
108
  * one fetch serves every request of the same source. Resolves to the shared image (ReuseBitmaps) or a copy of its own,
112
- * undefined when it could not be loaded (CanReload hears why).
109
+ * undefined when it could not be loaded. As the DrawnUi.Net Blazor head: when the caller's signal aborts a cached load,
110
+ * or a load waiting for IsLoadingLocked, the promise rejects with the abort (an AbortError, C# OperationCanceledException);
111
+ * with UseCache off a cancelled load resolves to undefined.
113
112
  */
114
113
  LoadImageManagedAsync(source: string, signal?: AbortSignal, priority?: LoadPriority): Promise<Image | undefined>;
114
+ /** C# Task.WaitAsync(token): rejects with the abort when the signal aborts; the load itself goes on for the others. */
115
+ private static WithCancel;
115
116
  private Enqueue;
116
117
  /** A fresh image goes into the cache; the cached one (an equal source loaded meanwhile) wins. */
117
118
  private Cached;
@@ -35,10 +35,7 @@ export class SkiaImageManager {
35
35
  static HttpRetryMaxAttempts = 3;
36
36
  /** Base address of relative sources (DrawnUi HttpBaseAddress); unset, they resolve against the page. */
37
37
  static HttpBaseAddress;
38
- /**
39
- * C# CanReload: raised when a load failed (with its source and why) so the caller may retry later, and when
40
- * `IsLoadingLocked` is turned off (no arguments).
41
- */
38
+ /** C# CanReload: raised when `IsLoadingLocked` is turned off, so what waited or failed meanwhile may load again. */
42
39
  CanReload;
43
40
  cache = new Map();
44
41
  /** Every image the manager made and still tracks: cached ones and the copies it handed out. */
@@ -270,13 +267,15 @@ export class SkiaImageManager {
270
267
  /**
271
268
  * Queued, cached load (C# LoadImageManagedAsync): a cached image resolves at once, the rest wait their turn by priority;
272
269
  * one fetch serves every request of the same source. Resolves to the shared image (ReuseBitmaps) or a copy of its own,
273
- * undefined when it could not be loaded (CanReload hears why).
270
+ * undefined when it could not be loaded. As the DrawnUi.Net Blazor head: when the caller's signal aborts a cached load,
271
+ * or a load waiting for IsLoadingLocked, the promise rejects with the abort (an AbortError, C# OperationCanceledException);
272
+ * with UseCache off a cancelled load resolves to undefined.
274
273
  */
275
274
  async LoadImageManagedAsync(source, signal, priority = "Normal") {
276
275
  if (!source)
277
276
  return undefined;
278
277
  while (this.locked)
279
- await this.unlocked;
278
+ await SkiaImageManager.WithCancel(this.unlocked, signal);
280
279
  const key = SkiaImageManager.Key(source);
281
280
  if (!SkiaImageManager.UseCache)
282
281
  return this.Enqueue(key, source, priority, signal, false);
@@ -289,7 +288,20 @@ export class SkiaImageManager {
289
288
  this.inflight.set(key, task);
290
289
  void task.finally(() => this.inflight.delete(key));
291
290
  }
292
- return this.HandOut(await task, key);
291
+ return this.HandOut(await SkiaImageManager.WithCancel(task, signal), key);
292
+ }
293
+ /** C# Task.WaitAsync(token): rejects with the abort when the signal aborts; the load itself goes on for the others. */
294
+ static WithCancel(task, signal) {
295
+ if (!signal)
296
+ return task;
297
+ const reason = () => signal.reason ?? new DOMException("image load cancelled", "AbortError");
298
+ if (signal.aborted)
299
+ return Promise.reject(reason());
300
+ return new Promise((resolve, reject) => {
301
+ const abort = () => reject(reason());
302
+ signal.addEventListener("abort", abort, { once: true });
303
+ task.then((v) => { signal.removeEventListener("abort", abort); resolve(v); }, (e) => { signal.removeEventListener("abort", abort); reject(e); });
304
+ });
293
305
  }
294
306
  Enqueue(key, source, priority, signal, cache) {
295
307
  return new Promise((resolve) => {
@@ -332,11 +344,9 @@ export class SkiaImageManager {
332
344
  continue;
333
345
  }
334
346
  this.running++;
335
- void this.Fetch(item.source, item.signal).then(({ Image: image, Error: error }) => {
347
+ void this.Fetch(item.source, item.signal).then(({ Image: image }) => {
336
348
  if (image)
337
349
  this.Track(image, item.key);
338
- else
339
- this.CanReload?.(item.source, error);
340
350
  // the first requester caches it; the others get what is cached
341
351
  for (const r of requesters)
342
352
  r.resolve(image);
@@ -70,6 +70,8 @@ export declare class Super {
70
70
  /** Any shaping family (the bidirectional pass needs one, its font does not matter). */
71
71
  static AnyShapingFamily(): string | undefined;
72
72
  static UseDrawnUi(): DrawnUiBuilder;
73
+ /** C# Super.SetClipboardText: puts text on the clipboard (selection copies go through it; replace it to observe or redirect them). */
74
+ static SetClipboardText: (text: string) => void;
73
75
  /** C# Super.OpenLink: opens an address in a new browser tab (noopener: the opened page gets no handle on this one). */
74
76
  static OpenLink(url: string): void;
75
77
  /** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
@@ -51,15 +51,6 @@ export class DrawnUiBuilder {
51
51
  if (!face)
52
52
  throw new Error(`DrawnUi: cannot load font '${f.Source}'`);
53
53
  loaded.set(f.Source, face);
54
- // the same face as a CSS font under the alias: the accessibility overlay's selectable text lines up with the drawn glyphs
55
- if (typeof FontFace !== "undefined" && typeof document !== "undefined") {
56
- try {
57
- const css = new FontFace(f.Alias, data, { weight: String(f.Weight) });
58
- await css.load();
59
- document.fonts.add(css);
60
- }
61
- catch { /* selection text falls back to a system font */ }
62
- }
63
54
  }
64
55
  let weights = Super.Fonts.get(f.Alias);
65
56
  if (!weights) {
@@ -152,6 +143,8 @@ export class Super {
152
143
  static AnyShapingFamily() { for (const f of Super.shapingFamilyOfFace.values())
153
144
  return f; return undefined; }
154
145
  static UseDrawnUi() { return new DrawnUiBuilder(); }
146
+ /** C# Super.SetClipboardText: puts text on the clipboard (selection copies go through it; replace it to observe or redirect them). */
147
+ static SetClipboardText = (text) => { void navigator.clipboard?.writeText(text).catch(() => { }); };
155
148
  /** C# Super.OpenLink: opens an address in a new browser tab (noopener: the opened page gets no handle on this one). */
156
149
  static OpenLink(url) { window.open(url, "_blank", "noopener"); }
157
150
  /** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
@@ -12,6 +12,10 @@ export declare class TextInputProxy {
12
12
  private static element?;
13
13
  private static owner?;
14
14
  private static composing;
15
+ /** The field took focus from a touch tap: its keys come from the soft keyboard (the return key ends editing). */
16
+ private static byTouch;
17
+ /** Set by the canvas while it runs a touch release's gestures (a field focused by them was focused by a touch). */
18
+ static TouchGesture: boolean;
15
19
  private static applying;
16
20
  /** The textarea (created on first use); KeyboardManager recognizes it through `data-drawnui-text-input`. */
17
21
  static get Element(): HTMLTextAreaElement | undefined;
@@ -20,12 +24,38 @@ export declare class TextInputProxy {
20
24
  private static Create;
21
25
  /** The editor took focus: the textarea mirrors it and gets DOM focus (soft keyboard, IME). */
22
26
  static Attach(editor: SkiaEditor): void;
27
+ /** The input got DOM focus in the task running now (Attach): a tap that focused the field needs nothing more. */
28
+ private static focusedNow;
29
+ /**
30
+ * The canvas calls it at the end of a tap's release (the pointerup, the user gesture iOS requires to open the soft
31
+ * keyboard): a tap on the focused field gives its input DOM focus inside that gesture, so the keyboard opens on the first
32
+ * tap and comes back on a tap after the user closed it. A touch anywhere else leaves it as it is: the keyboard the user
33
+ * closed stays closed while the page is scrolled. True when the tap was on the focused field (its input has focus now).
34
+ */
35
+ static FocusFromTap(clientX: number, clientY: number, touch?: boolean): boolean;
23
36
  static Detach(editor: SkiaEditor): void;
37
+ private static blurAfterTouch;
38
+ /** The input has focus from a touch release (its keyboard is up): a tap on another field needs no blur and focus. */
39
+ private static keyboardUp;
40
+ /** The canvas calls it at the end of each touch release, after FocusFromTap: a field left during the press lets go now. */
41
+ static AfterTouchEnd(): void;
24
42
  private static Configure;
25
43
  /** Editor text / selection changed: mirror it (never while an IME composition is in flight). */
26
44
  static Sync(editor: SkiaEditor): void;
27
- /** Puts the textarea over the editor so mobile browsers scroll the right spot into view. */
45
+ /**
46
+ * Where the hidden input sits: a field focused by a touch keeps it fixed at the top-left corner, never over the field (as
47
+ * the DrawnUi.Net web heads), so iOS never pans the page to reveal it (a scroll with AdaptToKeyboardAuto moves the
48
+ * field above the keyboard); a field focused by a mouse or the keyboard has it over the field, so a desktop input
49
+ * method opens its candidate window next to the text.
50
+ */
28
51
  private static Place;
52
+ private static placedLeft;
53
+ private static placedTop;
54
+ /**
55
+ * After each frame of the canvas: a focused field that moved (its page scrolled) takes its hidden input along, so a
56
+ * desktop input method keeps its window next to the text. Nothing to do while no field is focused.
57
+ */
58
+ static AfterFrame(canvas: unknown): void;
29
59
  /** The textarea changed (typing, IME commit, paste, undo): diff against the editor and replay through the stubs. */
30
60
  private static ApplyFromElement;
31
61
  }
@@ -11,6 +11,10 @@ export class TextInputProxy {
11
11
  static element;
12
12
  static owner;
13
13
  static composing = false;
14
+ /** The field took focus from a touch tap: its keys come from the soft keyboard (the return key ends editing). */
15
+ static byTouch = false;
16
+ /** Set by the canvas while it runs a touch release's gestures (a field focused by them was focused by a touch). */
17
+ static TouchGesture = false;
14
18
  static applying = false;
15
19
  /** The textarea (created on first use); KeyboardManager recognizes it through `data-drawnui-text-input`. */
16
20
  static get Element() { return TextInputProxy.element; }
@@ -27,12 +31,13 @@ export class TextInputProxy {
27
31
  el.setAttribute("autocorrect", "off");
28
32
  el.setAttribute("autocapitalize", "off");
29
33
  el.rows = 1;
30
- // fixed 1x1 box over the caret: invisible, still focusable, 16px font keeps iOS from zooming the page
34
+ // a fixed 1x1 box (where it sits: Place): invisible, still focusable, the 16px font keeps iOS from zooming the page
31
35
  el.style.cssText = "position:fixed;left:0;top:0;width:1px;height:1px;padding:0;border:0;margin:0;opacity:0.01;font-size:16px;line-height:1;resize:none;overflow:hidden;outline:none;background:transparent;color:transparent;caret-color:transparent;pointer-events:none;z-index:-1;";
32
36
  el.addEventListener("compositionstart", () => { TextInputProxy.composing = true; });
33
37
  el.addEventListener("compositionend", () => { TextInputProxy.composing = false; TextInputProxy.ApplyFromElement(); });
34
38
  el.addEventListener("input", () => TextInputProxy.ApplyFromElement());
35
39
  el.addEventListener("blur", () => {
40
+ TextInputProxy.keyboardUp = false;
36
41
  // focus moved to another DOM text field (a page input): the drawn editor loses focus like C# BlurExternalTextInput
37
42
  queueMicrotask(() => {
38
43
  const a = document.activeElement;
@@ -41,12 +46,6 @@ export class TextInputProxy {
41
46
  owner.IsFocused = false;
42
47
  });
43
48
  });
44
- // a tap on the canvas moves DOM focus to the body: give it back to the proxy synchronously (keeps the soft keyboard)
45
- window.addEventListener("pointerup", (e) => {
46
- const owner = TextInputProxy.owner;
47
- if (owner && owner.IsFocused && e.target?.tagName === "CANVAS")
48
- el.focus({ preventScroll: true });
49
- }, true);
50
49
  document.body.appendChild(el);
51
50
  return el;
52
51
  }
@@ -57,16 +56,73 @@ export class TextInputProxy {
57
56
  return;
58
57
  TextInputProxy.owner = editor;
59
58
  TextInputProxy.composing = false;
59
+ TextInputProxy.byTouch = TextInputProxy.TouchGesture || !!editor.Superview?.TouchPressed;
60
60
  TextInputProxy.Configure(editor, el);
61
61
  TextInputProxy.Sync(editor);
62
+ // a touch press: the input takes focus in its touchend (FocusFromTap), the only place iOS opens the keyboard from; a
63
+ // focus taken earlier would leave it focused with no keyboard
64
+ if (editor.Superview?.TouchPressed)
65
+ return;
62
66
  el.focus({ preventScroll: true });
67
+ TextInputProxy.focusedNow = true;
68
+ queueMicrotask(() => { TextInputProxy.focusedNow = false; });
69
+ }
70
+ /** The input got DOM focus in the task running now (Attach): a tap that focused the field needs nothing more. */
71
+ static focusedNow = false;
72
+ /**
73
+ * The canvas calls it at the end of a tap's release (the pointerup, the user gesture iOS requires to open the soft
74
+ * keyboard): a tap on the focused field gives its input DOM focus inside that gesture, so the keyboard opens on the first
75
+ * tap and comes back on a tap after the user closed it. A touch anywhere else leaves it as it is: the keyboard the user
76
+ * closed stays closed while the page is scrolled. True when the tap was on the focused field (its input has focus now).
77
+ */
78
+ static FocusFromTap(clientX, clientY, touch = false) {
79
+ const owner = TextInputProxy.owner, el = TextInputProxy.element;
80
+ if (!owner || !el || !owner.IsFocused)
81
+ return false;
82
+ const canvas = owner.Superview?.Element;
83
+ if (!canvas)
84
+ return false;
85
+ const b = canvas.getBoundingClientRect(), k = owner.RenderingScale || 1, r = owner.GetAccessibilityPixelRect();
86
+ const x = (clientX - b.left) * k, y = (clientY - b.top) * k;
87
+ if (x < r.Left || x > r.Right || y < r.Top || y > r.Bottom)
88
+ return false;
89
+ TextInputProxy.byTouch = touch;
90
+ if (!TextInputProxy.focusedNow && !(touch && TextInputProxy.keyboardUp && document.activeElement === el)) {
91
+ // focus() on the input that has focus already does not open the keyboard: take it off and back on, inside the tap
92
+ if (document.activeElement === el)
93
+ el.blur();
94
+ el.focus({ preventScroll: true });
95
+ }
96
+ if (touch)
97
+ TextInputProxy.keyboardUp = true;
98
+ TextInputProxy.Sync(owner);
99
+ return true;
63
100
  }
64
101
  static Detach(editor) {
65
102
  if (TextInputProxy.owner !== editor)
66
103
  return;
67
104
  TextInputProxy.owner = undefined;
68
105
  const el = TextInputProxy.element;
69
- if (el && document.activeElement === el)
106
+ if (!el || document.activeElement !== el)
107
+ return;
108
+ // a touch press may be moving to another field: the input keeps focus (the keyboard stays up, no hide and show) until
109
+ // the touch ends (AfterTouchEnd); with no field then, it lets go
110
+ if (TextInputProxy.TouchGesture || editor.Superview?.TouchPressed) {
111
+ TextInputProxy.blurAfterTouch = true;
112
+ return;
113
+ }
114
+ el.blur();
115
+ }
116
+ static blurAfterTouch = false;
117
+ /** The input has focus from a touch release (its keyboard is up): a tap on another field needs no blur and focus. */
118
+ static keyboardUp = false;
119
+ /** The canvas calls it at the end of each touch release, after FocusFromTap: a field left during the press lets go now. */
120
+ static AfterTouchEnd() {
121
+ if (!TextInputProxy.blurAfterTouch)
122
+ return;
123
+ TextInputProxy.blurAfterTouch = false;
124
+ const el = TextInputProxy.element;
125
+ if (!TextInputProxy.owner && el && document.activeElement === el)
70
126
  el.blur();
71
127
  }
72
128
  static Configure(editor, el) {
@@ -88,16 +144,38 @@ export class TextInputProxy {
88
144
  el.setSelectionRange(start, end);
89
145
  TextInputProxy.Place(editor, el);
90
146
  }
91
- /** Puts the textarea over the editor so mobile browsers scroll the right spot into view. */
147
+ /**
148
+ * Where the hidden input sits: a field focused by a touch keeps it fixed at the top-left corner, never over the field (as
149
+ * the DrawnUi.Net web heads), so iOS never pans the page to reveal it (a scroll with AdaptToKeyboardAuto moves the
150
+ * field above the keyboard); a field focused by a mouse or the keyboard has it over the field, so a desktop input
151
+ * method opens its candidate window next to the text.
152
+ */
92
153
  static Place(editor, el) {
154
+ let left = 0, top = 0;
93
155
  const canvas = editor.Superview?.Element;
94
- if (!canvas)
156
+ if (!TextInputProxy.byTouch && canvas) {
157
+ const b = canvas.getBoundingClientRect(), scale = editor.RenderingScale || 1, r = editor.GetAccessibilityPixelRect();
158
+ left = Math.round(b.left + r.Left / scale);
159
+ top = Math.round(b.top + r.Top / scale);
160
+ }
161
+ if (left === TextInputProxy.placedLeft && top === TextInputProxy.placedTop)
162
+ return;
163
+ TextInputProxy.placedLeft = left;
164
+ TextInputProxy.placedTop = top;
165
+ el.style.left = `${left}px`;
166
+ el.style.top = `${top}px`;
167
+ }
168
+ static placedLeft = 0;
169
+ static placedTop = 0;
170
+ /**
171
+ * After each frame of the canvas: a focused field that moved (its page scrolled) takes its hidden input along, so a
172
+ * desktop input method keeps its window next to the text. Nothing to do while no field is focused.
173
+ */
174
+ static AfterFrame(canvas) {
175
+ const owner = TextInputProxy.owner, el = TextInputProxy.element;
176
+ if (!owner || !el || TextInputProxy.byTouch || owner.Superview !== canvas)
95
177
  return;
96
- const b = canvas.getBoundingClientRect();
97
- const scale = editor.RenderingScale || 1;
98
- const r = editor.DrawingRect;
99
- el.style.left = `${Math.round(b.left + r.Left / scale)}px`;
100
- el.style.top = `${Math.round(b.top + r.Top / scale)}px`;
178
+ TextInputProxy.Place(owner, el);
101
179
  }
102
180
  /** The textarea changed (typing, IME commit, paste, undo): diff against the editor and replay through the stubs. */
103
181
  static ApplyFromElement() {
@@ -130,6 +208,10 @@ export class TextInputProxy {
130
208
  else if (endPrev > start)
131
209
  editor.StubBackspace();
132
210
  editor.StubPressEnter(false, false);
211
+ // the soft keyboard's return key (done / go / search / send) in a single-line field ends editing and closes the
212
+ // keyboard, as a MAUI single-line field; a physical keyboard's Enter keeps the field focused (the Blazor rule)
213
+ if (TextInputProxy.byTouch && !editor.IsMultiline && ["done", "go", "search", "send"].includes(el.enterKeyHint))
214
+ editor.IsFocused = false;
133
215
  }
134
216
  else if (inserted)
135
217
  editor.StubTypeText(inserted);
@@ -5,7 +5,7 @@ import type { PopupAnchor, PopupId, PopupWindowOptions } from "../core/PopupWind
5
5
  import type { SKPoint } from "../core/Gestures";
6
6
  import type { SKRect } from "../core/Types";
7
7
  import type { Thickness, ThicknessValue } from "../core/Types";
8
- import type { SkiaLabel as SkiaLabelCtrl } from "../controls/SkiaLabel";
8
+ import { SkiaLabel as SkiaLabelCtrl } from "../controls/SkiaLabel";
9
9
  import type { TextSpan as TextSpanCtrl } from "../controls/TextSpan";
10
10
  import type { SkiaRichLabel as SkiaRichLabelCtrl } from "../controls/SkiaRichLabel";
11
11
  import type { SkiaLabelFps as SkiaLabelFpsCtrl } from "../controls/SkiaLabelFps";