@rive-app/canvas-lite 2.40.0 → 2.40.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/canvas-lite",
3
- "version": "2.40.0",
3
+ "version": "2.40.1",
4
4
  "description": "A lite version of Rive's canvas based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.js CHANGED
@@ -449,7 +449,7 @@ Hc=await (async function(){function b(c){c=Hc=c.exports;gb=c.V;Ec=c.W;fb=c.X;Fc=
449
449
  /* 5 */
450
450
  /***/ ((module) => {
451
451
 
452
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.40.0","description":"A lite version of Rive\'s canvas based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.js.map","rive.wasm","rive_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
452
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.40.1","description":"A lite version of Rive\'s canvas based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.js.map","rive.wasm","rive_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
453
453
 
454
454
  /***/ }),
455
455
  /* 6 */
@@ -2605,21 +2605,21 @@ __webpack_require__.r(__webpack_exports__);
2605
2605
  /* harmony export */ KeyboardInteractions: () => (/* binding */ KeyboardInteractions)
2606
2606
  /* harmony export */ });
2607
2607
  /**
2608
- * Tracks the relationship between the canvas's DOM focus and Rive's internal focus for the
2609
- * current focus session.
2608
+ * Tracks the relationship between DOM focus inside this Rive focus domain (canvas or semantic overlay)
2609
+ * and Rive's internal focus for the current focus session.
2610
2610
  *
2611
- * NotFocused — the canvas is not the active DOM element, or Rive entered and then released focus
2612
- * internally this session. Either way the next Tab should move on to the next page
2613
- * element, so Tab events are ignored.
2614
- * EntryPending — the canvas has DOM focus but Rive holds no active focus node yet, and the next Tab should enter
2615
- * the focus tree. This is the resting state for pointer-driven focus (a click on the
2616
- * canvas), or an edge case for keyboard focus where initial focus action did not land on a focus node.
2617
- * RiveFocused — a Rive node currently holds focus. Tab/Shift+Tab are routed to the Rive focus
2618
- * manager and trapped inside the canvas until Rive notifies focus has ended.
2611
+ * NotFocused — DOM focus left the domain, Rive released focus internally, or Tab walked
2612
+ * off the end of the tree. Keyboard input isn't ours, so Tab is ignored and
2613
+ * reaches the next page element.
2614
+ * EntryPending — DOM focus is inside the domain but Rive holds no node yet, so the next Tab
2615
+ * enters the focus tree. Set by pointer focus on the canvas, by assistive technology (AT) focus landing
2616
+ * in the overlay, and by keyboard focus whose entry attempt found no eligible node.
2617
+ * RiveFocused — a Rive node holds focus. Tab/Shift+Tab route to the Rive focus manager and stay
2618
+ * inside the domain until either Rive reports focus ended (pollFocusState) or
2619
+ * focusNext()/focusPrevious() returns false at the edge of the tree.
2619
2620
  *
2620
- * When keyboard focus lands on the canvas, onCanvasFocus reads the direction focus came from and
2621
- * moves into the focus tree immediately, going straight to RiveFocused. EntryPending is only set via pointer focus (or keyboard focus
2622
- * where focusNext()/focusPrevious() return false but respects tabindex).
2621
+ * Keyboard focus on the canvas enters the tree immediately: onCanvasFocus infers direction from
2622
+ * where focus came from and goes straight to RiveFocused when a node accepts.
2623
2623
  */
2624
2624
  var FocusSessionState;
2625
2625
  (function (FocusSessionState) {
@@ -2628,7 +2628,9 @@ var FocusSessionState;
2628
2628
  FocusSessionState["RiveFocused"] = "riveFocused";
2629
2629
  })(FocusSessionState || (FocusSessionState = {}));
2630
2630
  /**
2631
- * Manages keyboard and DOM focus interactions for a Rive canvas.
2631
+ * Manages keyboard and DOM focus interactions for Rive's focus domain (<canvas> or semantic overlay).
2632
+ * Because keyboard events can apply on either part of the domain, we need to track what events we should
2633
+ * handle/intercept, and when to release focus back to the page outside of the domain.
2632
2634
  *
2633
2635
  * Tracks the canvas focus session state (focusSessionState) and routes
2634
2636
  * Tab/Shift+Tab to the Rive state machine's focus manager. Exposes shared
@@ -2674,17 +2676,45 @@ var KeyboardInteractions = /** @class */ (function () {
2674
2676
  _this.focusSessionState = FocusSessionState.RiveFocused;
2675
2677
  }
2676
2678
  };
2677
- this.onCanvasBlur = function (_event) {
2679
+ /**
2680
+ * Marks internal state that the canvas has lost DOM focus. Do not actually clear
2681
+ * Rive focus though if:
2682
+ * 1. DOM focus is still within Rive domain (i.e., semantic overlay)
2683
+ * 2. Document just lost focus (i.e. tab switching)
2684
+ *
2685
+ * When we're not in either of those buckets, it's safe to call `clearFocus()` on the SMI.
2686
+ */
2687
+ this.onCanvasBlur = function (event) {
2678
2688
  _this.focusSessionState = FocusSessionState.NotFocused;
2679
2689
  _this.canvasHasFocus = false;
2690
+ var movedWithinFocusDomain = _this.isInFocusDomain(event.relatedTarget);
2691
+ var documentLostFocus = event.relatedTarget === null && !document.hasFocus();
2692
+ if (movedWithinFocusDomain || documentLostFocus)
2693
+ return;
2694
+ _this.mainSm.clearFocus();
2680
2695
  };
2696
+ /**
2697
+ * Assistive technology (AT) focus landing inside the overlay is DOM focus inside the Rive focus domain, so open a
2698
+ * session even when no Rive node holds focus yet. shouldRiveHandleKeyEvent treats NotFocused
2699
+ * as authoritative, so without this the overlay's Tab keydowns reach onKeyDown and get dropped
2700
+ * at that gate — the browser would move focus out of Rive instead of to the next focus node.
2701
+ */
2681
2702
  this.onOverlayFocusIn = function (event) {
2682
- if (_this.isInOverlay(event.target)) {
2683
- _this.focusDomainReleased = false;
2684
- }
2703
+ if (!_this.isInOverlay(event.target))
2704
+ return;
2705
+ _this.focusDomainReleased = false;
2706
+ if (!_this.hasFocusNodes)
2707
+ return;
2708
+ if (_this.focusSessionState !== FocusSessionState.NotFocused)
2709
+ return;
2710
+ _this.focusSessionState = _this.mainSm.focusState().hasFocus
2711
+ ? FocusSessionState.RiveFocused
2712
+ : FocusSessionState.EntryPending;
2685
2713
  };
2686
- this.onFocusDomainHostFocusIn = function (_event) {
2714
+ /** Overlay listeners attach lazily, so the first focusin only ever lands here. */
2715
+ this.onFocusDomainHostFocusIn = function (event) {
2687
2716
  _this.syncOverlayListener();
2717
+ _this.onOverlayFocusIn(event);
2688
2718
  };
2689
2719
  this.onKeyDown = function (event) {
2690
2720
  _this.syncOverlayListener();
@@ -2697,7 +2727,7 @@ var KeyboardInteractions = /** @class */ (function () {
2697
2727
  var forward = !event.shiftKey;
2698
2728
  var focusMoved = forward ? _this.mainSm.focusNext() : _this.mainSm.focusPrevious();
2699
2729
  if (focusMoved) {
2700
- // A Rive node accepted focus — keep trapping Tab inside the canvas.
2730
+ // A Rive node accepted focus — keep trapping Tab inside Rive.
2701
2731
  _this.focusSessionState = FocusSessionState.RiveFocused;
2702
2732
  event.preventDefault();
2703
2733
  }
@@ -2733,27 +2763,34 @@ var KeyboardInteractions = /** @class */ (function () {
2733
2763
  /**
2734
2764
  * Called by pollFocusState on the Rive instance when it observes hasFocus=true. Rive acquired
2735
2765
  * focus internally (e.g. via a listener action or state transition) without a DOM focus event,
2736
- * so mark the session RiveFocused.
2766
+ * so mark the session RiveFocused. This cannot resurrect a session that a DOM blur ended,
2767
+ * because onCanvasBlur clears Rive's focus alongside it.
2737
2768
  */
2738
2769
  KeyboardInteractions.prototype.notifyRiveFocused = function () {
2739
2770
  this.focusSessionState = FocusSessionState.RiveFocused;
2740
2771
  };
2741
2772
  /**
2742
- * Whether Rive should handle this keydown — i.e. it currently owns keyboard input.
2743
- * True when focus is anywhere in the Rive focus domain (the canvas itself or the
2744
- * accessibility overlay), OR a focus session is active and the key landed on the
2745
- * canvas.
2773
+ * Determine if Rive should handle keyboard input. If session state is `NotFocused` - no.
2774
+ * DOM focus stays parked on the canvas after Rive releases focus internally, and that Tab
2775
+ * has to reach the page rather than re-enter the tree.
2776
+ *
2777
+ * Otherwise, the event still has to belong to Rive:
2778
+ * 1. If the current DOM focus is in Rive domain (canvas or semantic overlay)
2779
+ * 2. If the target for the key input is for the semantic overlay, or the canvas
2746
2780
  */
2747
2781
  KeyboardInteractions.prototype.shouldRiveHandleKeyEvent = function (event) {
2782
+ if (this.focusSessionState === FocusSessionState.NotFocused)
2783
+ return false;
2748
2784
  var inFocusDomain = this.isInFocusDomain(document.activeElement) ||
2749
2785
  this.isInOverlay(event.target);
2750
- if (inFocusDomain)
2751
- return true;
2752
- var sessionActive = this.focusSessionState !== FocusSessionState.NotFocused;
2753
2786
  var eventOnCanvas = event.target === this.canvas;
2754
- return sessionActive && (this.canvasHasFocus || eventOnCanvas);
2787
+ return inFocusDomain || this.canvasHasFocus || eventOnCanvas;
2755
2788
  };
2756
- /** Rive focus domain = the canvas itself OR the accessibility overlay. */
2789
+ /**
2790
+ * The Rive focus domain: the DOM that counts as "inside" Rive for focus purposes — today the
2791
+ * canvas itself OR the accessibility overlay subtree. Anything added later belongs here, so
2792
+ * session bookkeeping and keydown routing pick it up for free.
2793
+ */
2757
2794
  KeyboardInteractions.prototype.isInFocusDomain = function (target) {
2758
2795
  if (target === this.canvas)
2759
2796
  return true;
@@ -5460,8 +5497,9 @@ var Rive = /** @class */ (function () {
5460
5497
  // Rive has an active focus node. Mark the session RiveFocused so Tab stays
5461
5498
  // trapped and a later internal release (hasFocus true → false) is detected.
5462
5499
  this._keyboardInteractions.notifyRiveFocused();
5463
- // Only steal DOM focus on the false→true transition. If hasFocus stays
5464
- // true across frames and the user clicks away, do not re-focus the canvas again.
5500
+ // Only steal DOM focus on the false→true transition. Rive can hold focus across
5501
+ // frames while DOM focus sits elsewhere — a window switch preserves runtime focus
5502
+ // by design — and that must not re-focus the canvas again.
5465
5503
  if (!this._prevHasFocus) {
5466
5504
  // Steal DOM focus to the canvas only when focus isn't already held
5467
5505
  // somewhere inside this instance's focus scope. When the accessibility
@@ -5482,8 +5520,9 @@ var Rive = /** @class */ (function () {
5482
5520
  this._prevHasFocus = false;
5483
5521
  // hasFocus is false — only act when Rive previously held focus and released it internally
5484
5522
  // (state change clears focus). Release the DOM Tab trap so the next Tab moves to the next
5485
- // page element. EntryPending and NotFocused cases are intentional no-ops — EntryPending in
5486
- // particular must stay in its state (a click awaiting its first Tab) rather than be reset here.
5523
+ // page element. A DOM blur reaches here too now that onCanvasBlur clears Rive focus, but it
5524
+ // has already set NotFocused, so this is a no-op. EntryPending and NotFocused are likewise
5525
+ // intentional no-ops — EntryPending must stay put (a click awaiting its first Tab).
5487
5526
  if (this._keyboardInteractions.focusSessionState === _utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.RiveFocused) {
5488
5527
  this._keyboardInteractions.setFocusSessionState(_utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.NotFocused);
5489
5528
  }