@rive-app/canvas 2.37.6 → 2.37.8

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",
3
- "version": "2.37.6",
3
+ "version": "2.37.8",
4
4
  "description": "Rive's canvas based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -215,6 +215,10 @@ export interface RiveParameters {
215
215
  layout?: Layout;
216
216
  autoplay?: boolean;
217
217
  useOffscreenRenderer?: boolean;
218
+ /**
219
+ * Optional tab index to set for the canvas element if there are any Focus nodes within the graphic
220
+ */
221
+ tabIndex?: number;
218
222
  /**
219
223
  * Allow the runtime to automatically load assets hosted in Rive's CDN.
220
224
  * enabled by default.
@@ -316,6 +320,7 @@ export interface RiveLoadParameters {
316
320
  stateMachines?: string | string[];
317
321
  useOffscreenRenderer?: boolean;
318
322
  shouldDisableRiveListeners?: boolean;
323
+ tabIndex?: number;
319
324
  }
320
325
  export interface RiveResetParameters {
321
326
  artboard?: string;
@@ -415,6 +420,7 @@ export declare class Rive {
415
420
  private runtime;
416
421
  private artboard;
417
422
  private eventCleanup;
423
+ private keyboardEventCleanup;
418
424
  private file;
419
425
  private riveFile;
420
426
  private eventManager;
@@ -438,8 +444,11 @@ export declare class Rive {
438
444
  private _currentCanvasHeight;
439
445
  private _audioEventListener;
440
446
  private _boundDraw;
447
+ private _pageVisibilityHandler;
448
+ private _explicitlyStoppedRendering;
441
449
  private _viewModelInstance;
442
450
  private _dataEnums;
451
+ private _tabIndex;
443
452
  private drawOptimization;
444
453
  private enablePerfMarks;
445
454
  durations: number[];
@@ -723,6 +732,13 @@ export declare class Rive {
723
732
  */
724
733
  startRendering(): void;
725
734
  private scheduleRendering;
735
+ /**
736
+ * Called when document.visibilitychange fires (tab change, window minimize, etc.).
737
+ * Cancels the rAF loop on hide and resets the time reference so that no accumulated time is
738
+ * applied to state machines when the tab becomes visible again. This prevents state machine
739
+ * advances with large time deltas when rAF starts up again.
740
+ */
741
+ private _onPageVisibilityChange;
726
742
  /**
727
743
  * Enables frames-per-second (FPS) reporting for the runtime
728
744
  * If no callback is provided, Rive will append a fixed-position div at the top-right corner of
package/rive.js CHANGED
@@ -1084,7 +1084,7 @@ function Za(a, b) {
1084
1084
  return Ya(c, a, b);
1085
1085
  }));
1086
1086
  }
1087
- var $a, ab, eb = {484173:(a, b, c, d, e) => {
1087
+ var $a, ab, eb = {484269:(a, b, c, d, e) => {
1088
1088
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
1089
1089
  return 0;
1090
1090
  }
@@ -1147,11 +1147,11 @@ var $a, ab, eb = {484173:(a, b, c, d, e) => {
1147
1147
  }
1148
1148
  window.h.za += 1;
1149
1149
  return 1;
1150
- }, 486351:() => {
1150
+ }, 486447:() => {
1151
1151
  "undefined" !== typeof window.h && (window.h.Sa.map(function(a) {
1152
1152
  document.removeEventListener(a, window.h.unlock, !0);
1153
1153
  }), --window.h.za, 0 === window.h.za && delete window.h);
1154
- }, 486655:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 486759:() => {
1154
+ }, 486751:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 486855:() => {
1155
1155
  try {
1156
1156
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
1157
1157
  a.close();
@@ -1159,7 +1159,7 @@ var $a, ab, eb = {484173:(a, b, c, d, e) => {
1159
1159
  } catch (c) {
1160
1160
  return 0;
1161
1161
  }
1162
- }, 486930:(a, b, c, d, e, f) => {
1162
+ }, 487026:(a, b, c, d, e, f) => {
1163
1163
  if ("undefined" === typeof window.h) {
1164
1164
  return -1;
1165
1165
  }
@@ -1205,7 +1205,7 @@ var $a, ab, eb = {484173:(a, b, c, d, e) => {
1205
1205
  a == window.h.J.xa && g.Z.connect(g.L.destination);
1206
1206
  g.pb = f;
1207
1207
  return window.h.tc(g);
1208
- }, 489807:a => window.h.qa(a).L.sampleRate, 489880:a => {
1208
+ }, 489903:a => window.h.qa(a).L.sampleRate, 489976:a => {
1209
1209
  a = window.h.qa(a);
1210
1210
  void 0 !== a.Z && (a.Z.onaudioprocess = function() {
1211
1211
  }, a.Z.disconnect(), a.Z = void 0);
@@ -1213,13 +1213,13 @@ var $a, ab, eb = {484173:(a, b, c, d, e) => {
1213
1213
  a.L.close();
1214
1214
  a.L = void 0;
1215
1215
  a.pb = void 0;
1216
- }, 490280:a => {
1216
+ }, 490376:a => {
1217
1217
  window.h.Ab(a);
1218
- }, 490330:a => {
1218
+ }, 490426:a => {
1219
1219
  a = window.h.qa(a);
1220
1220
  a.L.resume();
1221
1221
  a.state = window.h.ga.wb;
1222
- }, 490469:a => {
1222
+ }, 490565:a => {
1223
1223
  a = window.h.qa(a);
1224
1224
  a.L.suspend();
1225
1225
  a.state = window.h.ga.stopped;
@@ -3752,7 +3752,7 @@ moduleRtn = ea;
3752
3752
  /* 5 */
3753
3753
  /***/ ((module) => {
3754
3754
 
3755
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.37.6","description":"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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3755
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.37.8","description":"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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3756
3756
 
3757
3757
  /***/ }),
3758
3758
  /* 6 */
@@ -3760,26 +3760,29 @@ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"
3760
3760
 
3761
3761
  __webpack_require__.r(__webpack_exports__);
3762
3762
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3763
- /* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.AudioAssetWrapper),
3764
- /* harmony export */ AudioWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.AudioWrapper),
3765
- /* harmony export */ BLANK_URL: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.BLANK_URL),
3766
- /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.CustomFileAssetLoaderWrapper),
3767
- /* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileAssetWrapper),
3768
- /* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileFinalizer),
3769
- /* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontAssetWrapper),
3770
- /* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontWrapper),
3771
- /* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageAssetWrapper),
3772
- /* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageWrapper),
3773
- /* harmony export */ RiveFont: () => (/* reexport safe */ _riveFont__WEBPACK_IMPORTED_MODULE_3__.RiveFont),
3774
- /* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.createFinalization),
3775
- /* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.finalizationRegistry),
3763
+ /* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.AudioAssetWrapper),
3764
+ /* harmony export */ AudioWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.AudioWrapper),
3765
+ /* harmony export */ BLANK_URL: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.BLANK_URL),
3766
+ /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.CustomFileAssetLoaderWrapper),
3767
+ /* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FileAssetWrapper),
3768
+ /* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer),
3769
+ /* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FontAssetWrapper),
3770
+ /* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FontWrapper),
3771
+ /* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.ImageAssetWrapper),
3772
+ /* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.ImageWrapper),
3773
+ /* harmony export */ RiveFont: () => (/* reexport safe */ _riveFont__WEBPACK_IMPORTED_MODULE_4__.RiveFont),
3774
+ /* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.createFinalization),
3775
+ /* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry),
3776
+ /* harmony export */ registerKeyboardInteractions: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.registerKeyboardInteractions),
3776
3777
  /* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
3777
- /* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.sanitizeUrl)
3778
+ /* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.sanitizeUrl)
3778
3779
  /* harmony export */ });
3779
3780
  /* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
3780
- /* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
3781
- /* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
3782
- /* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
3781
+ /* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
3782
+ /* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
3783
+ /* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
3784
+ /* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(11);
3785
+
3783
3786
 
3784
3787
 
3785
3788
 
@@ -4081,6 +4084,68 @@ var registerTouchInteractions = function (_a) {
4081
4084
  /* 8 */
4082
4085
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4083
4086
 
4087
+ __webpack_require__.r(__webpack_exports__);
4088
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4089
+ /* harmony export */ registerKeyboardInteractions: () => (/* binding */ registerKeyboardInteractions)
4090
+ /* harmony export */ });
4091
+ /**
4092
+ * Registers focus and tab-traversal event handlers on the canvas to route
4093
+ * Tab/Shift+Tab to the active Rive state machine's focus manager.
4094
+ *
4095
+ * Mirrors registerTouchInteractions for pointer events.
4096
+ *
4097
+ * Returns a cleanup function that removes all registered event listeners,
4098
+ * or null if the setup conditions are not met.
4099
+ */
4100
+ var registerKeyboardInteractions = function (_a) {
4101
+ var canvas = _a.canvas, stateMachine = _a.stateMachine, rive = _a.rive, hasFocusNodes = _a.hasFocusNodes;
4102
+ if (!canvas ||
4103
+ !stateMachine ||
4104
+ !rive ||
4105
+ typeof window === "undefined") {
4106
+ return null;
4107
+ }
4108
+ // Work off an assumption of a single state machine
4109
+ var mainSm = stateMachine;
4110
+ var canvasHasFocus = false;
4111
+ var onCanvasFocus = function (_event) {
4112
+ canvasHasFocus = true;
4113
+ };
4114
+ var onCanvasBlur = function (_event) {
4115
+ canvasHasFocus = false;
4116
+ };
4117
+ var onKeyDown = function (event) {
4118
+ if (!canvasHasFocus)
4119
+ return;
4120
+ if (event.code === "Tab" && hasFocusNodes) {
4121
+ var forward = !event.shiftKey;
4122
+ var focusMoved = forward ? mainSm.focusNext() : mainSm.focusPrevious();
4123
+ if (focusMoved) {
4124
+ // Keep Tab inside the canvas — a Rive node received focus.
4125
+ event.preventDefault();
4126
+ }
4127
+ else {
4128
+ // No more traversable nodes — release Tab to the page.
4129
+ // Since we're not preventing default, blur event will fire on the canvas
4130
+ canvasHasFocus = false;
4131
+ }
4132
+ }
4133
+ };
4134
+ canvas.addEventListener("focus", onCanvasFocus);
4135
+ canvas.addEventListener("blur", onCanvasBlur);
4136
+ canvas.addEventListener("keydown", onKeyDown);
4137
+ return function () {
4138
+ canvas.removeEventListener("focus", onCanvasFocus);
4139
+ canvas.removeEventListener("blur", onCanvasBlur);
4140
+ canvas.removeEventListener("keydown", onKeyDown);
4141
+ };
4142
+ };
4143
+
4144
+
4145
+ /***/ }),
4146
+ /* 9 */
4147
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4148
+
4084
4149
  __webpack_require__.r(__webpack_exports__);
4085
4150
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4086
4151
  /* harmony export */ BLANK_URL: () => (/* binding */ BLANK_URL),
@@ -4131,7 +4196,7 @@ function sanitizeUrl(url) {
4131
4196
 
4132
4197
 
4133
4198
  /***/ }),
4134
- /* 9 */
4199
+ /* 10 */
4135
4200
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4136
4201
 
4137
4202
  __webpack_require__.r(__webpack_exports__);
@@ -4410,7 +4475,7 @@ var createFinalization = function (target, finalizable) {
4410
4475
 
4411
4476
 
4412
4477
  /***/ }),
4413
- /* 10 */
4478
+ /* 11 */
4414
4479
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4415
4480
 
4416
4481
  __webpack_require__.r(__webpack_exports__);
@@ -6029,8 +6094,10 @@ var Rive = /** @class */ (function () {
6029
6094
  this.readyForPlaying = false;
6030
6095
  // Runtime artboard
6031
6096
  this.artboard = null;
6032
- // place to clear up event listeners
6097
+ // place to clear up pointer/touch event listeners
6033
6098
  this.eventCleanup = null;
6099
+ // place to clear up focus/keyboard event listeners
6100
+ this.keyboardEventCleanup = null;
6034
6101
  this.shouldDisableRiveListeners = false;
6035
6102
  this.automaticallyHandleEvents = false;
6036
6103
  this.dispatchPointerExit = true;
@@ -6058,8 +6125,16 @@ var Rive = /** @class */ (function () {
6058
6125
  this._audioEventListener = null;
6059
6126
  // draw method bound to the class
6060
6127
  this._boundDraw = null;
6128
+ // Page visibility handler — prevents state machine advancing / rAF from being invoked with large time delta
6129
+ // when the browser tab is switched back to after being hidden.
6130
+ this._pageVisibilityHandler = null;
6131
+ // True only when the page visibility handler itself cancelled an active frame.
6132
+ // Set by stopRendering(), cleared by startRendering(). Prevents the
6133
+ // visibilitychange handler from restarting a rendering loop the caller intentionally stopped.
6134
+ this._explicitlyStoppedRendering = false;
6061
6135
  this._viewModelInstance = null;
6062
6136
  this._dataEnums = null;
6137
+ this._tabIndex = null;
6063
6138
  this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
6064
6139
  // When true, emits performance.mark/measure entries for load and render.
6065
6140
  this.enablePerfMarks = false;
@@ -6080,12 +6155,18 @@ var Rive = /** @class */ (function () {
6080
6155
  _this.resizeToCanvas();
6081
6156
  }
6082
6157
  };
6158
+ // Tracks the current animation frame request
6159
+ this.frameRequestId = null;
6083
6160
  /**
6084
6161
  * Used be draw to track when a second of active rendering time has passed.
6085
6162
  * Used for debugging purposes
6086
6163
  */
6087
6164
  this.renderSecondTimer = 0;
6088
6165
  this._boundDraw = this.draw.bind(this);
6166
+ if (typeof document !== 'undefined') {
6167
+ this._pageVisibilityHandler = this._onPageVisibilityChange.bind(this);
6168
+ document.addEventListener('visibilitychange', this._pageVisibilityHandler);
6169
+ }
6089
6170
  this.canvas = params.canvas;
6090
6171
  if (params.canvas.constructor === HTMLCanvasElement) {
6091
6172
  this._observed = observers.add(this.canvas, this.onCanvasResize);
@@ -6164,6 +6245,7 @@ var Rive = /** @class */ (function () {
6164
6245
  stateMachines: params.stateMachines,
6165
6246
  artboard: params.artboard,
6166
6247
  useOffscreenRenderer: params.useOffscreenRenderer,
6248
+ tabIndex: params.tabIndex,
6167
6249
  });
6168
6250
  }
6169
6251
  Object.defineProperty(Rive.prototype, "viewModelCount", {
@@ -6185,13 +6267,14 @@ var Rive = /** @class */ (function () {
6185
6267
  // Initializes the Rive object either from constructor or load()
6186
6268
  Rive.prototype.init = function (_a) {
6187
6269
  var _this = this;
6188
- var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c, _d = _a.autoBind, autoBind = _d === void 0 ? false : _d;
6270
+ var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c, _d = _a.autoBind, autoBind = _d === void 0 ? false : _d, tabIndex = _a.tabIndex;
6189
6271
  if (this.destroyed) {
6190
6272
  return;
6191
6273
  }
6192
6274
  this.src = src;
6193
6275
  this.buffer = buffer;
6194
6276
  this.riveFile = riveFile;
6277
+ this._tabIndex = tabIndex !== null && tabIndex !== void 0 ? tabIndex : null;
6195
6278
  // If no source file url specified, it's a bust
6196
6279
  if (!this.src && !this.buffer && !this.riveFile) {
6197
6280
  throw new RiveError(Rive.missingErrorMessage);
@@ -6215,7 +6298,16 @@ var Rive = /** @class */ (function () {
6215
6298
  // Get the canvas where you want to render the animation and create a renderer
6216
6299
  if (_this.enablePerfMarks)
6217
6300
  performance.mark('rive:make-renderer:start');
6218
- _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
6301
+ try {
6302
+ _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
6303
+ if (!_this.renderer) {
6304
+ throw new Error("Renderer is null, cannot render Rive on the canvas.");
6305
+ }
6306
+ }
6307
+ catch (e) {
6308
+ console.error(e);
6309
+ throw new RiveError("Unable to create the renderer, your environment may not support WebGL. Try the @rive-app/canvas runtime as an alternative.");
6310
+ }
6219
6311
  if (_this.enablePerfMarks) {
6220
6312
  performance.mark('rive:make-renderer:end');
6221
6313
  performance.measure('rive:make-renderer', 'rive:make-renderer:start', 'rive:make-renderer:end');
@@ -6253,9 +6345,14 @@ var Rive = /** @class */ (function () {
6253
6345
  if (this.eventCleanup) {
6254
6346
  this.eventCleanup();
6255
6347
  }
6348
+ if (this.keyboardEventCleanup) {
6349
+ this.keyboardEventCleanup();
6350
+ this.keyboardEventCleanup = null;
6351
+ }
6256
6352
  if (!this.shouldDisableRiveListeners) {
6257
- var activeStateMachines = (this.animator.stateMachines || [])
6258
- .filter(function (sm) { return sm.playing && _this.runtime.hasListeners(sm.instance); })
6353
+ var playingStateMachines = this.animator.stateMachines.filter(function (sm) { return sm.playing; });
6354
+ var activeStateMachines = playingStateMachines
6355
+ .filter(function (sm) { return _this.runtime.hasListeners(sm.instance); })
6259
6356
  .map(function (sm) { return sm.instance; });
6260
6357
  var touchScrollEnabledOption = this.isTouchScrollEnabled;
6261
6358
  var dispatchPointerExit = this.dispatchPointerExit;
@@ -6277,6 +6374,27 @@ var Rive = /** @class */ (function () {
6277
6374
  enableMultiTouch: enableMultiTouch,
6278
6375
  layoutScaleFactor: this._layout.layoutScaleFactor,
6279
6376
  });
6377
+ // Wire up keyboard interactions for state machines that have focus nodes.
6378
+ // hasFocusNodes — unified focus tree check, gates tab traversal
6379
+ var smWithFocusNodes = playingStateMachines
6380
+ .filter(function (sm) { return sm.instance.hasFocusNodes(); })
6381
+ .map(function (sm) { return sm.instance; });
6382
+ if (smWithFocusNodes.length) {
6383
+ // Set the canvas as a tabbable element if there are any focus nodes.
6384
+ // Prefer the tabIndex param set by the user, otherwise use 0.
6385
+ // But do not override any explicit tabIndex already set on the canvas, if any.
6386
+ var currentCanvasTabIndex = this.canvas.tabIndex;
6387
+ // By default, canvas elements have a tabIndex of -1
6388
+ if (currentCanvasTabIndex === -1 || isNaN(currentCanvasTabIndex)) {
6389
+ this.canvas.tabIndex = (this._tabIndex !== null ? this._tabIndex : 0);
6390
+ }
6391
+ this.keyboardEventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerKeyboardInteractions)({
6392
+ canvas: this.canvas,
6393
+ stateMachine: smWithFocusNodes[0], // work off assumption of single state machine
6394
+ rive: this.runtime,
6395
+ hasFocusNodes: smWithFocusNodes.length > 0,
6396
+ });
6397
+ }
6280
6398
  }
6281
6399
  };
6282
6400
  /**
@@ -6287,6 +6405,10 @@ var Rive = /** @class */ (function () {
6287
6405
  this.eventCleanup();
6288
6406
  this.eventCleanup = null;
6289
6407
  }
6408
+ if (this.keyboardEventCleanup) {
6409
+ this.keyboardEventCleanup();
6410
+ this.keyboardEventCleanup = null;
6411
+ }
6290
6412
  };
6291
6413
  /**
6292
6414
  * If the instance has audio and the system audio is not ready
@@ -6686,6 +6808,10 @@ var Rive = /** @class */ (function () {
6686
6808
  audioManager.remove(this._audioEventListener);
6687
6809
  this._audioEventListener = null;
6688
6810
  }
6811
+ if (this._pageVisibilityHandler) {
6812
+ document.removeEventListener('visibilitychange', this._pageVisibilityHandler);
6813
+ this._pageVisibilityHandler = null;
6814
+ }
6689
6815
  (_b = this._viewModelInstance) === null || _b === void 0 ? void 0 : _b.cleanup();
6690
6816
  this._viewModelInstance = null;
6691
6817
  this._dataEnums = null;
@@ -6710,6 +6836,10 @@ var Rive = /** @class */ (function () {
6710
6836
  if (this.eventCleanup !== null) {
6711
6837
  this.eventCleanup();
6712
6838
  }
6839
+ if (this.keyboardEventCleanup) {
6840
+ this.keyboardEventCleanup();
6841
+ this.keyboardEventCleanup = null;
6842
+ }
6713
6843
  // Delete all animation and state machine instances
6714
6844
  this.stop();
6715
6845
  if (this.artboard) {
@@ -6778,6 +6908,10 @@ var Rive = /** @class */ (function () {
6778
6908
  if (this.eventCleanup) {
6779
6909
  this.eventCleanup();
6780
6910
  }
6911
+ if (this.keyboardEventCleanup) {
6912
+ this.keyboardEventCleanup();
6913
+ this.keyboardEventCleanup = null;
6914
+ }
6781
6915
  this.setupRiveListeners();
6782
6916
  this.startRendering();
6783
6917
  };
@@ -6795,6 +6929,10 @@ var Rive = /** @class */ (function () {
6795
6929
  if (this.eventCleanup) {
6796
6930
  this.eventCleanup();
6797
6931
  }
6932
+ if (this.keyboardEventCleanup) {
6933
+ this.keyboardEventCleanup();
6934
+ this.keyboardEventCleanup = null;
6935
+ }
6798
6936
  this.animator.pause(animationNames);
6799
6937
  };
6800
6938
  Rive.prototype.scrub = function (animationNames, value) {
@@ -6830,6 +6968,10 @@ var Rive = /** @class */ (function () {
6830
6968
  if (this.eventCleanup) {
6831
6969
  this.eventCleanup();
6832
6970
  }
6971
+ if (this.keyboardEventCleanup) {
6972
+ this.keyboardEventCleanup();
6973
+ this.keyboardEventCleanup = null;
6974
+ }
6833
6975
  };
6834
6976
  /**
6835
6977
  * Resets the animation
@@ -7289,6 +7431,7 @@ var Rive = /** @class */ (function () {
7289
7431
  * they would have been at if rendering had not been stopped.
7290
7432
  */
7291
7433
  Rive.prototype.stopRendering = function () {
7434
+ this._explicitlyStoppedRendering = true;
7292
7435
  if (this.loaded && this.frameRequestId) {
7293
7436
  if (this.runtime.cancelAnimationFrame) {
7294
7437
  this.runtime.cancelAnimationFrame(this.frameRequestId);
@@ -7304,6 +7447,7 @@ var Rive = /** @class */ (function () {
7304
7447
  * renderer is already active, then this will have zero effect.
7305
7448
  */
7306
7449
  Rive.prototype.startRendering = function () {
7450
+ this._explicitlyStoppedRendering = false;
7307
7451
  this.drawFrame();
7308
7452
  };
7309
7453
  Rive.prototype.scheduleRendering = function () {
@@ -7316,6 +7460,31 @@ var Rive = /** @class */ (function () {
7316
7460
  }
7317
7461
  }
7318
7462
  };
7463
+ /**
7464
+ * Called when document.visibilitychange fires (tab change, window minimize, etc.).
7465
+ * Cancels the rAF loop on hide and resets the time reference so that no accumulated time is
7466
+ * applied to state machines when the tab becomes visible again. This prevents state machine
7467
+ * advances with large time deltas when rAF starts up again.
7468
+ */
7469
+ Rive.prototype._onPageVisibilityChange = function () {
7470
+ var _a, _b;
7471
+ if (document.hidden) {
7472
+ if (this.frameRequestId !== null) {
7473
+ if ((_a = this.runtime) === null || _a === void 0 ? void 0 : _a.cancelAnimationFrame) {
7474
+ this.runtime.cancelAnimationFrame(this.frameRequestId);
7475
+ }
7476
+ else {
7477
+ cancelAnimationFrame(this.frameRequestId);
7478
+ }
7479
+ this.frameRequestId = null;
7480
+ }
7481
+ // Reset so the first resumed frame starts with elapsedTime === 0.
7482
+ this.lastRenderTime = 0;
7483
+ }
7484
+ else if (((_b = this.animator) === null || _b === void 0 ? void 0 : _b.isPlaying) && !this._explicitlyStoppedRendering) {
7485
+ this.scheduleRendering();
7486
+ }
7487
+ };
7319
7488
  /**
7320
7489
  * Enables frames-per-second (FPS) reporting for the runtime
7321
7490
  * If no callback is provided, Rive will append a fixed-position div at the top-right corner of