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
@@ -1,6 +1,5 @@
1
1
  import { SKPoint } from "../core/Gestures";
2
2
  import { Super } from "../core/Super";
3
- import { SkiaValueAnimator } from "../core/Animators";
4
3
  import { ResolveControlStyle } from "../core/ControlStyle";
5
4
  import { KeyboardManager } from "../core/KeyboardManager";
6
5
  import { TextInputProxy } from "../core/TextInputProxy";
@@ -59,6 +58,8 @@ export class SkiaEditor extends SkiaShape {
59
58
  CanShowCursor = true;
60
59
  SelectionColor = "#5590CFFE";
61
60
  cursorPosition = 0;
61
+ /** A caret position was given (by the app, a tap, a selection): focusing keeps it; otherwise focusing puts the caret at the end. */
62
+ cursorPlaced = false;
62
63
  selectionLength = 0;
63
64
  isFocused = false;
64
65
  controlStyle = "Unset";
@@ -67,18 +68,30 @@ export class SkiaEditor extends SkiaShape {
67
68
  placeholder = new SkiaLabel();
68
69
  scrollX = 0;
69
70
  scrollY = 0;
70
- blink = new SkiaValueAnimator(this);
71
+ /** The caret blinks on a timer, asleep between blinks: no frame runs while it waits (DrawnUi.Rust editor_rules). */
72
+ blinkTimer = 0;
71
73
  caretVisible = true;
72
74
  subscribed = false;
73
75
  stubSelectionStop = -1;
74
76
  selectionMovingEdge = -1;
75
77
  onKeyDown = (key, e) => this.OnKeyDown(key, e);
76
- onKeyChar = (ch, e) => { e.preventDefault(); this.StubTypeText(ch); };
78
+ onKeyChar = (ch, e) => {
79
+ if (KeyboardManager.IsOwnedByElement(e) || KeyboardManager.IsInputMethodKey(e))
80
+ return; // a page control or the IME owns it
81
+ e.preventDefault();
82
+ this.StubTypeText(ch);
83
+ };
77
84
  selectionAnchor = -1;
78
85
  dragSelecting = false;
79
86
  styleApplied = {};
80
87
  layoutVersion = -1;
81
88
  boxes = [];
89
+ /** The glyph box starting at a text index, and the one ending at it. */
90
+ boxAt = new Map();
91
+ boxEnd = new Map();
92
+ /** Grapheme boundaries of the text, the places a caret may stand. */
93
+ stops = [0];
94
+ stopsText = "";
82
95
  constructor() {
83
96
  super();
84
97
  this.Type = "Rectangle";
@@ -93,15 +106,6 @@ export class SkiaEditor extends SkiaShape {
93
106
  this.placeholder.IsVisible = false;
94
107
  this.AddSubView(this.placeholder);
95
108
  this.AddSubView(this.Label);
96
- this.blink.mMinValue = 0;
97
- this.blink.mMaxValue = 1;
98
- this.blink.Speed = 1000;
99
- this.blink.Repeat = -1;
100
- this.blink.OnUpdated = (v) => { const visible = v < 0.5; if (visible !== this.caretVisible) {
101
- this.caretVisible = visible;
102
- this.InvalidateCache();
103
- this.RepaintComposition();
104
- } };
105
109
  this.ApplyControlStyleVisuals();
106
110
  this.UpdateLabel();
107
111
  }
@@ -178,6 +182,7 @@ export class SkiaEditor extends SkiaShape {
178
182
  /** Caret index (UTF-16 units) = the left edge of the selection when one exists. */
179
183
  get CursorPosition() { return this.cursorPosition; }
180
184
  set CursorPosition(v) {
185
+ this.cursorPlaced = true;
181
186
  const p = Math.max(0, Math.min(this.text.length, v | 0));
182
187
  if (p === this.cursorPosition)
183
188
  return;
@@ -192,9 +197,22 @@ export class SkiaEditor extends SkiaShape {
192
197
  this.selectionLength = l;
193
198
  this.OnCursorMoved();
194
199
  }
200
+ /** Shows the caret for a full half second, then blinks every 500 ms. */
201
+ StartBlink() {
202
+ this.StopBlink();
203
+ this.caretVisible = true;
204
+ this.blinkTimer = window.setInterval(() => { this.caretVisible = !this.caretVisible; this.InvalidateCache(); this.RepaintComposition(); }, 500);
205
+ }
206
+ StopBlink() { if (this.blinkTimer) {
207
+ clearInterval(this.blinkTimer);
208
+ this.blinkTimer = 0;
209
+ } }
195
210
  OnCursorMoved() {
196
211
  this.ScrollToCaret();
197
- this.caretVisible = true;
212
+ if (this.isFocused)
213
+ this.StartBlink();
214
+ else
215
+ this.caretVisible = true;
198
216
  TextInputProxy.Sync(this);
199
217
  this.CursorMoved?.(this);
200
218
  this.InvalidateCache();
@@ -209,9 +227,16 @@ export class SkiaEditor extends SkiaShape {
209
227
  if (SkiaEditor.Focused && SkiaEditor.Focused !== this)
210
228
  SkiaEditor.Focused.IsFocused = false;
211
229
  SkiaEditor.Focused = this;
230
+ // focused with no caret placed (from code, by the keyboard): the caret goes to the end of the text, as a tap after
231
+ // the text does, and the native field takes that position when it attaches (C# 2285b422: typing appends)
232
+ if (!this.cursorPlaced) {
233
+ this.cursorPlaced = true;
234
+ this.cursorPosition = this.text.length;
235
+ this.selectionLength = 0;
236
+ this.ScrollToCaret();
237
+ }
212
238
  this.SetFocusNative(true);
213
- this.caretVisible = true;
214
- this.blink.Start();
239
+ this.StartBlink();
215
240
  }
216
241
  else {
217
242
  if (SkiaEditor.Focused === this)
@@ -220,7 +245,7 @@ export class SkiaEditor extends SkiaShape {
220
245
  this.dragSelecting = false;
221
246
  this.stubSelectionStop = -1;
222
247
  this.selectionMovingEdge = -1;
223
- this.blink.Stop();
248
+ this.StopBlink();
224
249
  this.SetFocusNative(false);
225
250
  }
226
251
  this.FocusChanged?.(this, v);
@@ -305,6 +330,14 @@ export class SkiaEditor extends SkiaShape {
305
330
  MeasureAbsolute(w, h, scale) {
306
331
  const px = this.Padding.HorizontalThickness * scale, py = this.Padding.VerticalThickness * scale;
307
332
  const innerW = isFinite(w) ? Math.max(0, w - px) : Infinity;
333
+ // Single-line: the label is Start-aligned and measures to its content, so Center / End alignment had nothing to
334
+ // align in. Give it the field as a MINIMUM: short text centers in the field, longer text still grows past it and
335
+ // scrolls (C# 2e334ddd).
336
+ const minWidth = !this.IsMultiline && this.horizontalTextAlignment !== "Start" && isFinite(innerW) && innerW > 0 ? innerW / scale : -1;
337
+ if (this.Label.MinimumWidthRequest !== minWidth) {
338
+ this.Label.MinimumWidthRequest = minWidth;
339
+ this.Label.NeedMeasure = true;
340
+ }
308
341
  const labelSize = this.Label.Measure(this.IsMultiline ? innerW : Infinity, Infinity, scale);
309
342
  if (this.placeholder.IsVisible)
310
343
  this.placeholder.Measure(innerW, Infinity, scale);
@@ -355,34 +388,89 @@ export class SkiaEditor extends SkiaShape {
355
388
  this.OnLayoutChanged();
356
389
  }
357
390
  // ---- caret / selection geometry (pixels relative to the label's DrawingRect) ----
391
+ // Rules shared with DrawnUi.Rust (drawnui-cross 6ak): boxes are visual, the caret at index i is the trailing edge of
392
+ // character i - 1 on its line (the leading edge of the first character at a line start), taps and Left / Right go to
393
+ // the grapheme boundary whose caret x is nearest.
358
394
  Boxes() {
359
395
  if (this.layoutVersion !== this.Label.LayoutVersion) {
360
396
  this.boxes = this.Label.GetGlyphBoxes();
361
397
  this.layoutVersion = this.Label.LayoutVersion;
398
+ this.boxAt.clear();
399
+ this.boxEnd.clear();
400
+ for (const b of this.boxes) {
401
+ this.boxAt.set(b.Index, b);
402
+ this.boxEnd.set(b.Index + b.Length, b);
403
+ }
362
404
  }
363
405
  return this.boxes;
364
406
  }
365
- /** Rect of the caret before character `index` (label pixels), or undefined before the first layout. */
366
- CaretRectLabelPx(index = this.cursorPosition + this.selectionLength) {
367
- const boxes = this.Boxes();
407
+ Stops() {
408
+ if (this.stopsText !== this.text) {
409
+ this.stopsText = this.text;
410
+ this.stops = SkiaEditor.Graphemes(this.text).map((g) => g.index);
411
+ this.stops.push(this.text.length);
412
+ }
413
+ return this.stops;
414
+ }
415
+ /** The laid-out line a caret index belongs to: the line holding the character before it, else the one starting at it. */
416
+ static LineOf(index, lines) {
417
+ for (const l of lines)
418
+ if (index > l.Start && index <= l.End)
419
+ return l;
420
+ for (const l of lines)
421
+ if (index === l.Start)
422
+ return l;
423
+ let line = lines[0];
424
+ for (const l of lines)
425
+ if (l.Start <= index)
426
+ line = l; // in a space wrapped away: the line before it
427
+ return line;
428
+ }
429
+ /** Where the caret before character `index` stands (label pixels): its x, the direction of the text there, its line box. */
430
+ CaretPlace(index) {
368
431
  const lines = this.Label.GetLineBoxes();
369
432
  if (lines.length === 0)
370
433
  return undefined;
434
+ const boxes = this.Boxes();
435
+ const line = SkiaEditor.LineOf(index, lines);
436
+ const trailing = (b) => ({ X: b.Rtl ? b.Left : b.Left + b.Width, Rtl: !!b.Rtl, Top: b.Top, Height: b.Height });
437
+ if (index > line.Start) {
438
+ let prev = this.boxEnd.get(index);
439
+ if (!prev || prev.Line !== line.Line) {
440
+ prev = undefined;
441
+ for (const b of boxes)
442
+ if (b.Line === line.Line && b.Index < index)
443
+ prev = b;
444
+ }
445
+ if (prev)
446
+ return trailing(prev);
447
+ }
448
+ const cur = this.boxAt.get(index);
449
+ if (cur && cur.Line === line.Line)
450
+ return { X: cur.Rtl ? cur.Left + cur.Width : cur.Left, Rtl: !!cur.Rtl, Top: cur.Top, Height: cur.Height };
451
+ return { X: line.Left, Rtl: false, Top: line.Top, Height: line.Height };
452
+ }
453
+ /** Rect of the caret before character `index` (label pixels), or undefined before the first layout. */
454
+ CaretRectLabelPx(index = this.cursorPosition + this.selectionLength) {
455
+ const place = this.CaretPlace(index);
456
+ if (!place)
457
+ return undefined;
371
458
  const caretW = 2 * this.RenderingScale;
372
- const at = boxes.find((b) => b.Index === index);
373
- if (at)
374
- return SKRect.Create(at.Left, at.Top, caretW, at.Height);
375
- let prev;
376
- for (const b of boxes) {
377
- if (b.Index < index)
378
- prev = b;
379
- else
380
- break;
459
+ return SKRect.Create(place.Rtl ? place.X - caretW : place.X, place.Top, caretW, place.Height);
460
+ }
461
+ /** The grapheme boundary of a line whose caret x is nearest to `x` (a tie: the smaller index). */
462
+ NearestStop(line, x) {
463
+ let best = -1, bestD = Infinity;
464
+ for (const i of this.Stops()) {
465
+ if (i < line.Start || i > line.End)
466
+ continue;
467
+ const d = Math.abs((this.CaretPlace(i)?.X ?? 0) - x);
468
+ if (d < bestD - 0.01) {
469
+ best = i;
470
+ bestD = d;
471
+ }
381
472
  }
382
- if (prev)
383
- return SKRect.Create(prev.Left + prev.Width, prev.Top, caretW, prev.Height);
384
- const first = lines[0];
385
- return SKRect.Create(first.Left, first.Top, caretW, first.Height);
473
+ return best >= 0 ? best : Math.min(line.Start, this.text.length);
386
474
  }
387
475
  /** C# GetCursorPosition: the text index nearest to a point in label pixels. */
388
476
  HitTestIndex(x, y) {
@@ -395,16 +483,54 @@ export class SkiaEditor extends SkiaShape {
395
483
  line = l;
396
484
  break;
397
485
  }
398
- const boxes = this.Boxes().filter((b) => b.Line === line.Line);
399
- if (boxes.length === 0)
400
- return Math.min(line.Start, this.text.length);
401
- if (x <= boxes[0].Left)
402
- return boxes[0].Index;
403
- for (const b of boxes)
404
- if (x < b.Left + b.Width)
405
- return x < b.Left + b.Width / 2 ? b.Index : b.Index + b.Length;
406
- const last = boxes[boxes.length - 1];
407
- return Math.min(last.Index + last.Length, this.text.length);
486
+ return this.NearestStop(line, x);
487
+ }
488
+ /**
489
+ * Left / Right from a caret index: the grapheme boundary on its line whose caret x is nearest that way (equal x: the
490
+ * one logically nearest); at the visual edge of the line one grapheme logically, forward for Right in a
491
+ * left-to-right paragraph and backward in a right-to-left one (Left the other way round).
492
+ */
493
+ VisualTarget(from, dir) {
494
+ const lines = this.Label.GetLineBoxes();
495
+ const stops = this.Stops();
496
+ let line;
497
+ if (lines.length > 0) {
498
+ line = SkiaEditor.LineOf(from, lines);
499
+ const x0 = this.CaretPlace(from)?.X ?? 0;
500
+ let best = -1, bestX = 0;
501
+ for (const i of stops) {
502
+ if (i < line.Start || i > line.End || i === from)
503
+ continue;
504
+ const x = this.CaretPlace(i)?.X ?? 0;
505
+ if ((x - x0) * dir <= 0.01)
506
+ continue;
507
+ if (best < 0 || (x - bestX) * dir < -0.01 || (Math.abs(x - bestX) <= 0.01 && Math.abs(i - from) < Math.abs(best - from))) {
508
+ best = i;
509
+ bestX = x;
510
+ }
511
+ }
512
+ if (best >= 0)
513
+ return best;
514
+ }
515
+ const start = Math.max(this.text.lastIndexOf(ParagraphBreak, from - 1) + 1, 0);
516
+ const end = this.text.indexOf(ParagraphBreak, from);
517
+ const step = SkiaLabel.FirstStrongIsRtl(this.text.slice(start, end < 0 ? undefined : end)) ? -dir : dir;
518
+ let to = from;
519
+ if (step > 0) {
520
+ for (const i of stops)
521
+ if (i > from) {
522
+ to = i;
523
+ break;
524
+ }
525
+ }
526
+ else
527
+ for (let k = stops.length - 1; k >= 0; k--)
528
+ if (stops[k] < from) {
529
+ to = stops[k];
530
+ break;
531
+ }
532
+ // the step only crosses to the next or previous line: inside a mixed line the visual end stays put
533
+ return line && lines.length > 0 && SkiaEditor.LineOf(to, lines) === line ? from : to;
408
534
  }
409
535
  LabelPoint(args, apply, starting = false) {
410
536
  const loc = starting ? args.Event.StartingLocation : apply.MappedLocation;
@@ -424,9 +550,10 @@ export class SkiaEditor extends SkiaShape {
424
550
  const paint = new CK.Paint();
425
551
  paint.setColor(Super.ParseColor(this.SelectionColor));
426
552
  const end = this.cursorPosition + this.selectionLength;
553
+ // every selected character's own visual box: across a direction boundary the highlight can be two blocks
427
554
  for (const b of this.Boxes())
428
- if (b.Index >= this.cursorPosition && b.Index < end)
429
- canvas.drawRect(CK.LTRBRect(lr.Left + b.Left, lr.Top + b.Top, lr.Left + b.Left + Math.max(b.Width, 2), lr.Top + b.Top + b.Height), paint);
555
+ if (b.Index >= this.cursorPosition && b.Index < end && b.Width > 0)
556
+ canvas.drawRect(CK.LTRBRect(lr.Left + b.Left, lr.Top + b.Top, lr.Left + b.Left + b.Width, lr.Top + b.Top + b.Height), paint);
430
557
  paint.delete();
431
558
  canvas.restoreToCount(saved);
432
559
  }
@@ -468,6 +595,7 @@ export class SkiaEditor extends SkiaShape {
468
595
  this.stubSelectionStop = -1;
469
596
  this.selectionMovingEdge = -1;
470
597
  }
598
+ this.cursorPlaced = true;
471
599
  if (!this.isFocused)
472
600
  this.IsFocused = true;
473
601
  this.OnCursorMoved();
@@ -489,6 +617,7 @@ export class SkiaEditor extends SkiaShape {
489
617
  this.SelectWord(this.HitTestIndex(p.X, p.Y));
490
618
  this.dragSelecting = true;
491
619
  this.selectionAnchor = this.cursorPosition;
620
+ this.cursorPlaced = true;
492
621
  if (!this.isFocused)
493
622
  this.IsFocused = true;
494
623
  return this;
@@ -500,7 +629,15 @@ export class SkiaEditor extends SkiaShape {
500
629
  }
501
630
  return this;
502
631
  }
503
- OnAccessibilityActivated() { this.IsFocused = true; }
632
+ /** A text field is a Tab stop by default, like a native text box, with no Tapped handler needed. */
633
+ DefaultAccessibilityCanInteract() { return true; }
634
+ /** Keyboard navigation reached the field (Tab) or left it: take the caret and the input sink like a native text box, or release them. */
635
+ OnAccessibilityFocused(focused) { this.IsFocused = focused; }
636
+ /** Enter / Space on the field while it has no caret start editing; while editing they are text. */
637
+ OnAccessibilityActivated() { if (!this.IsFocused)
638
+ this.OnAccessibilityFocused(true); }
639
+ /** While editing, arrows, Home / End and PageUp / PageDown belong to the text: they never move a surrounding group. */
640
+ OnAccessibilityKey(_key) { return this.IsFocused; }
504
641
  DefaultAccessibilityLabel() { return this.text || this.placeholderText || undefined; }
505
642
  // ---- editing API (C# names) ----
506
643
  Submit() {
@@ -517,6 +654,7 @@ export class SkiaEditor extends SkiaShape {
517
654
  }
518
655
  SelectAll() { this.SetSelection(0, this.text.length); }
519
656
  SetSelection(start, end) {
657
+ this.cursorPlaced = true;
520
658
  const s = Math.max(0, Math.min(this.text.length, Math.min(start, end))), e = Math.max(0, Math.min(this.text.length, Math.max(start, end)));
521
659
  this.cursorPosition = s;
522
660
  this.selectionLength = e - s;
@@ -580,6 +718,10 @@ export class SkiaEditor extends SkiaShape {
580
718
  OnKeyDown(key, e) {
581
719
  const shift = KeyboardManager.IsShiftPressed, ctrl = KeyboardManager.IsControlPressed, alt = KeyboardManager.IsAltPressed;
582
720
  const handled = () => e.preventDefault();
721
+ // keys of another element (a page field or button, an overlay node) and of the input method are not the editor's:
722
+ // a composition keeps its arrows, Escape and Backspace (C# 845b26e9, GitHub #231)
723
+ if (KeyboardManager.IsInputMethodKey(e) || (KeyboardManager.IsOwnedByElement(e) && !TextInputProxy.IsProxyTarget(e.target)))
724
+ return;
583
725
  // with the hidden textarea focused these keys become input / clipboard events there and are applied from those
584
726
  if (TextInputProxy.IsActive(this) && TextInputProxy.IsProxyTarget(e.target) && (key === "Backspace" || key === "Delete" || key === "Enter" || key === "NumpadEnter" || (ctrl && (key === "KeyC" || key === "KeyX" || key === "KeyV"))))
585
727
  return;
@@ -599,11 +741,11 @@ export class SkiaEditor extends SkiaShape {
599
741
  break;
600
742
  case "ArrowLeft":
601
743
  handled();
602
- this.StubMoveCursor(-1, shift);
744
+ this.MoveVisual(-1, shift);
603
745
  break;
604
746
  case "ArrowRight":
605
747
  handled();
606
- this.StubMoveCursor(1, shift);
748
+ this.MoveVisual(1, shift);
607
749
  break;
608
750
  case "ArrowUp":
609
751
  if (this.IsMultiline) {
@@ -725,6 +867,39 @@ export class SkiaEditor extends SkiaShape {
725
867
  this.selectionMovingEdge = -1;
726
868
  this.OnCursorMoved();
727
869
  }
870
+ /**
871
+ * Arrow Left (-1) / Right (1): visual moves, as native text fields (see VisualTarget). Without Shift a selection
872
+ * collapses to its visually left (Left) or right (Right) edge; with Shift its moving edge moves.
873
+ */
874
+ MoveVisual(dir, extendSelection = false) {
875
+ if (!extendSelection && this.HasSelection) {
876
+ const a = this.cursorPosition, b = this.cursorPosition + this.selectionLength;
877
+ const xa = this.CaretPlace(a)?.X ?? 0, xb = this.CaretPlace(b)?.X ?? 0;
878
+ const to = dir < 0 ? (xa <= xb ? a : b) : (xa >= xb ? a : b);
879
+ this.cursorPosition = to;
880
+ this.selectionLength = 0;
881
+ this.stubSelectionStop = -1;
882
+ this.selectionMovingEdge = -1;
883
+ this.OnCursorMoved();
884
+ return;
885
+ }
886
+ // a selection made by dragging has no moving edge yet: its end moves
887
+ if (extendSelection && this.HasSelection && this.selectionMovingEdge < 0) {
888
+ this.stubSelectionStop = this.cursorPosition;
889
+ this.selectionMovingEdge = this.cursorPosition + this.selectionLength;
890
+ }
891
+ const from = extendSelection && this.HasSelection ? this.selectionMovingEdge : this.cursorPosition;
892
+ if (extendSelection && !this.HasSelection) {
893
+ this.stubSelectionStop = this.cursorPosition;
894
+ this.selectionMovingEdge = this.cursorPosition;
895
+ }
896
+ const to = this.VisualTarget(from, dir);
897
+ if (extendSelection) {
898
+ this.StubMoveCursor(to - this.selectionMovingEdge, true);
899
+ return;
900
+ }
901
+ this.StubMoveCursor(to - this.cursorPosition, false);
902
+ }
728
903
  StubSelectRange(start, length) {
729
904
  const len = this.text.length;
730
905
  const s = Math.max(0, Math.min(len, start)), l = Math.max(0, Math.min(len - s, length));
@@ -794,8 +969,7 @@ export class SkiaEditor extends SkiaShape {
794
969
  return out;
795
970
  }
796
971
  OnDisposing() {
797
- this.blink.Stop();
798
- this.blink.Dispose();
972
+ this.StopBlink();
799
973
  if (SkiaEditor.Focused === this)
800
974
  SkiaEditor.Focused = undefined;
801
975
  this.SetFocusNative(false);
@@ -14,6 +14,8 @@ export declare class GifAnimation {
14
14
  private positionsMs;
15
15
  /** Negative = the last frame. */
16
16
  SeekFrame(frame: number): void;
17
+ /** Start (ms) of the frame after the one at `msTime`; DurationMs after the last one. */
18
+ NextFrameStartMs(msTime: number): number;
17
19
  GetFrameNumber(msTime: number): number;
18
20
  /** Decodes every frame of an encoded GIF (CanvasKit AnimatedImage). */
19
21
  LoadFromBytes(bytes: ArrayBuffer): void;
@@ -37,6 +39,7 @@ export declare class SkiaGif extends AnimatedFramesRenderer {
37
39
  set Source(v: string);
38
40
  Start(delayMs?: number): void;
39
41
  protected OnAnimatorUpdated(value: number): void;
42
+ protected NextChangeMs(value: number): number | undefined;
40
43
  /** Seeks by time in ms (the animator range is 0..DurationMs). */
41
44
  protected OnAnimatorSeeking(time: number): void;
42
45
  protected OnAnimatorInitializing(): void;
@@ -21,6 +21,13 @@ export class GifAnimation {
21
21
  if (frame >= 0 && frame <= this.TotalFrames - 1)
22
22
  this.Frame = this.Frames[frame];
23
23
  }
24
+ /** Start (ms) of the frame after the one at `msTime`; DurationMs after the last one. */
25
+ NextFrameStartMs(msTime) {
26
+ for (let i = 0; i < this.positionsMs.length; i++)
27
+ if (msTime < this.positionsMs[i])
28
+ return this.positionsMs[i];
29
+ return this.DurationMs;
30
+ }
24
31
  GetFrameNumber(msTime) {
25
32
  if (this.positionsMs.length === 0 || this.DurationMs <= 0)
26
33
  return 0;
@@ -87,7 +94,9 @@ export class SkiaGif extends AnimatedFramesRenderer {
87
94
  loadGeneration = 0;
88
95
  constructor() {
89
96
  super();
90
- this.UseCache = "ImageDoubleBuffered";
97
+ // C# ImageDoubleBuffered pays off where a thread bakes the bitmap; on the web it is one offscreen pass per frame
98
+ // change, so the web engines draw a GIF frame with no cache (drawnui-cross rule 3)
99
+ this.UseCache = "None";
91
100
  }
92
101
  get Source() { return this.source; }
93
102
  set Source(v) { if (this.source !== v) {
@@ -97,6 +106,7 @@ export class SkiaGif extends AnimatedFramesRenderer {
97
106
  Start(delayMs = 0) { if ((this.Animation?.TotalFrames ?? 0) > 0)
98
107
  super.Start(delayMs); }
99
108
  OnAnimatorUpdated(value) { this.Seek(value); }
109
+ NextChangeMs(value) { return this.Animation && this.Animation.DurationMs > 0 ? this.Animation.NextFrameStartMs(value) : undefined; }
100
110
  /** Seeks by time in ms (the animator range is 0..DurationMs). */
101
111
  OnAnimatorSeeking(time) {
102
112
  const a = this.Animation;
@@ -158,7 +168,7 @@ export class SkiaGif extends AnimatedFramesRenderer {
158
168
  async LoadSource(source) {
159
169
  if (!source)
160
170
  return undefined;
161
- const r = await fetch(source);
171
+ const r = await fetch(Super.ResolveAssetUrl(source));
162
172
  if (!r.ok)
163
173
  throw new Error(`${r.status} ${source}`);
164
174
  const animation = new GifAnimation();
@@ -164,20 +164,25 @@ export class SkiaImage extends SkiaControl {
164
164
  MeasureAbsolute(widthConstraint, heightConstraint, scale) {
165
165
  const img = this.LoadedSource;
166
166
  let w = widthConstraint, h = heightConstraint;
167
- if (img) {
168
- const aspect = img.width() / img.height();
169
- if (!isFinite(w) && isFinite(h))
170
- w = h * aspect;
171
- else if (!isFinite(h) && isFinite(w))
172
- h = w / aspect;
167
+ // nothing loaded: the box it is offered (C# OnMeasuring), an unbounded side 0
168
+ if (!img) {
169
+ this.AspectScale = { X: 0, Y: 0 };
170
+ return ScaledSize.FromPixels(isFinite(w) ? w : 0, isFinite(h) ? h : 0, scale);
173
171
  }
174
- if (!isFinite(w) || !isFinite(h)) {
172
+ const iw = img.width(), ih = img.height();
173
+ if (!isFinite(w) && isFinite(h))
174
+ w = h * iw / ih;
175
+ else if (!isFinite(h) && isFinite(w))
176
+ h = w * ih / iw;
177
+ if (!isFinite(w) || !isFinite(h) || iw <= 0 || ih <= 0) {
175
178
  this.AspectScale = { X: 0, Y: 0 };
176
179
  return ScaledSize.FromPixels(0, 0, scale);
177
180
  }
178
- if (img)
179
- this.AspectScale = SkiaImage.RescaleAspect(img.width(), img.height(), SKRect.Create(0, 0, w, h), this.Aspect);
180
- return ScaledSize.FromPixels(w, h, scale);
181
+ // C# OnMeasuring / DrawnUi.Rust: an auto-sized side is the bitmap's pixels scaled by the aspect for this box, never
182
+ // more than the box (a Fill or requested side still takes its box in Measure)
183
+ const s = SkiaImage.RescaleAspect(iw, ih, SKRect.Create(0, 0, w, h), this.Aspect);
184
+ this.AspectScale = s;
185
+ return ScaledSize.FromPixels(Math.min(iw * s.X, w), Math.min(ih * s.Y, h), scale);
181
186
  }
182
187
  Paint(ctx) {
183
188
  const img = this.LoadedSource;