@rive-app/webgl2 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/webgl2",
3
- "version": "2.37.6",
3
+ "version": "2.37.8",
4
4
  "description": "Rive's webgl2 based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
@@ -25,6 +25,7 @@
25
25
  "files": [
26
26
  "rive.js",
27
27
  "rive.wasm",
28
+ "rive_fallback.wasm",
28
29
  "rive.js.map",
29
30
  "rive.d.ts",
30
31
  "rive_advanced.mjs.d.ts",
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
@@ -617,6 +617,9 @@ l.onRuntimeInitialized = function() {
617
617
  C.width = 1;
618
618
  C.height = 1;
619
619
  d = b(C, A);
620
+ if (!d) {
621
+ return null;
622
+ }
620
623
  d.Ya = !!d.T.getExtension("WEBGL_shader_pixel_local_storage");
621
624
  d.Db = Math.min(d.T.getParameter(d.T.MAX_RENDERBUFFER_SIZE), d.T.getParameter(d.T.MAX_TEXTURE_SIZE));
622
625
  d.Ka = !d.Ya;
@@ -626,6 +629,9 @@ l.onRuntimeInitialized = function() {
626
629
  return d;
627
630
  }
628
631
  d = z(!0);
632
+ if (!d) {
633
+ throw "Unable to create WebGL context, your environment may not support WebGL. Try out @rive-app/canvas as an alternative.";
634
+ }
629
635
  d.Ka || (d = z(!1));
630
636
  }
631
637
  return u ? new a(r) : b(r, d.Ka);
@@ -763,7 +769,7 @@ function Na(a, b) {
763
769
  return Ma(c, a, b);
764
770
  }));
765
771
  }
766
- var Oa, Pa, Ta = {569592:(a, b, c, d, e) => {
772
+ var Oa, Pa, Ta = {569016:(a, b, c, d, e) => {
767
773
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
768
774
  return 0;
769
775
  }
@@ -826,11 +832,11 @@ var Oa, Pa, Ta = {569592:(a, b, c, d, e) => {
826
832
  }
827
833
  window.h.Ea += 1;
828
834
  return 1;
829
- }, 571770:() => {
835
+ }, 571194:() => {
830
836
  "undefined" !== typeof window.h && (window.h.Xa.map(function(a) {
831
837
  document.removeEventListener(a, window.h.unlock, !0);
832
838
  }), --window.h.Ea, 0 === window.h.Ea && delete window.h);
833
- }, 572074:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 572178:() => {
839
+ }, 571498:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 571602:() => {
834
840
  try {
835
841
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
836
842
  a.close();
@@ -838,7 +844,7 @@ var Oa, Pa, Ta = {569592:(a, b, c, d, e) => {
838
844
  } catch (c) {
839
845
  return 0;
840
846
  }
841
- }, 572349:(a, b, c, d, e, f) => {
847
+ }, 571773:(a, b, c, d, e, f) => {
842
848
  if ("undefined" === typeof window.h) {
843
849
  return -1;
844
850
  }
@@ -884,7 +890,7 @@ var Oa, Pa, Ta = {569592:(a, b, c, d, e) => {
884
890
  a == window.h.I.Ba && g.Y.connect(g.K.destination);
885
891
  g.nb = f;
886
892
  return window.h.mc(g);
887
- }, 575226:a => window.h.sa(a).K.sampleRate, 575299:a => {
893
+ }, 574650:a => window.h.sa(a).K.sampleRate, 574723:a => {
888
894
  a = window.h.sa(a);
889
895
  void 0 !== a.Y && (a.Y.onaudioprocess = function() {
890
896
  }, a.Y.disconnect(), a.Y = void 0);
@@ -892,13 +898,13 @@ var Oa, Pa, Ta = {569592:(a, b, c, d, e) => {
892
898
  a.K.close();
893
899
  a.K = void 0;
894
900
  a.nb = void 0;
895
- }, 575699:a => {
901
+ }, 575123:a => {
896
902
  window.h.yb(a);
897
- }, 575749:a => {
903
+ }, 575173:a => {
898
904
  a = window.h.sa(a);
899
905
  a.K.resume();
900
906
  a.state = window.h.ha.ub;
901
- }, 575888:a => {
907
+ }, 575312:a => {
902
908
  a = window.h.sa(a);
903
909
  a.K.suspend();
904
910
  a.state = window.h.ha.stopped;
@@ -3901,7 +3907,7 @@ moduleRtn = ca;
3901
3907
  /* 5 */
3902
3908
  /***/ ((module) => {
3903
3909
 
3904
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.37.6","description":"Rive\'s webgl2 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)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3910
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.37.8","description":"Rive\'s webgl2 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)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3905
3911
 
3906
3912
  /***/ }),
3907
3913
  /* 6 */
@@ -3909,26 +3915,29 @@ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"
3909
3915
 
3910
3916
  __webpack_require__.r(__webpack_exports__);
3911
3917
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3912
- /* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.AudioAssetWrapper),
3913
- /* harmony export */ AudioWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.AudioWrapper),
3914
- /* harmony export */ BLANK_URL: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.BLANK_URL),
3915
- /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.CustomFileAssetLoaderWrapper),
3916
- /* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileAssetWrapper),
3917
- /* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileFinalizer),
3918
- /* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontAssetWrapper),
3919
- /* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontWrapper),
3920
- /* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageAssetWrapper),
3921
- /* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageWrapper),
3922
- /* harmony export */ RiveFont: () => (/* reexport safe */ _riveFont__WEBPACK_IMPORTED_MODULE_3__.RiveFont),
3923
- /* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.createFinalization),
3924
- /* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.finalizationRegistry),
3918
+ /* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.AudioAssetWrapper),
3919
+ /* harmony export */ AudioWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.AudioWrapper),
3920
+ /* harmony export */ BLANK_URL: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.BLANK_URL),
3921
+ /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.CustomFileAssetLoaderWrapper),
3922
+ /* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FileAssetWrapper),
3923
+ /* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer),
3924
+ /* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FontAssetWrapper),
3925
+ /* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FontWrapper),
3926
+ /* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.ImageAssetWrapper),
3927
+ /* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.ImageWrapper),
3928
+ /* harmony export */ RiveFont: () => (/* reexport safe */ _riveFont__WEBPACK_IMPORTED_MODULE_4__.RiveFont),
3929
+ /* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.createFinalization),
3930
+ /* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry),
3931
+ /* harmony export */ registerKeyboardInteractions: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.registerKeyboardInteractions),
3925
3932
  /* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
3926
- /* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.sanitizeUrl)
3933
+ /* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.sanitizeUrl)
3927
3934
  /* harmony export */ });
3928
3935
  /* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
3929
- /* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
3930
- /* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
3931
- /* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
3936
+ /* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
3937
+ /* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
3938
+ /* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
3939
+ /* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(11);
3940
+
3932
3941
 
3933
3942
 
3934
3943
 
@@ -4230,6 +4239,68 @@ var registerTouchInteractions = function (_a) {
4230
4239
  /* 8 */
4231
4240
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4232
4241
 
4242
+ __webpack_require__.r(__webpack_exports__);
4243
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4244
+ /* harmony export */ registerKeyboardInteractions: () => (/* binding */ registerKeyboardInteractions)
4245
+ /* harmony export */ });
4246
+ /**
4247
+ * Registers focus and tab-traversal event handlers on the canvas to route
4248
+ * Tab/Shift+Tab to the active Rive state machine's focus manager.
4249
+ *
4250
+ * Mirrors registerTouchInteractions for pointer events.
4251
+ *
4252
+ * Returns a cleanup function that removes all registered event listeners,
4253
+ * or null if the setup conditions are not met.
4254
+ */
4255
+ var registerKeyboardInteractions = function (_a) {
4256
+ var canvas = _a.canvas, stateMachine = _a.stateMachine, rive = _a.rive, hasFocusNodes = _a.hasFocusNodes;
4257
+ if (!canvas ||
4258
+ !stateMachine ||
4259
+ !rive ||
4260
+ typeof window === "undefined") {
4261
+ return null;
4262
+ }
4263
+ // Work off an assumption of a single state machine
4264
+ var mainSm = stateMachine;
4265
+ var canvasHasFocus = false;
4266
+ var onCanvasFocus = function (_event) {
4267
+ canvasHasFocus = true;
4268
+ };
4269
+ var onCanvasBlur = function (_event) {
4270
+ canvasHasFocus = false;
4271
+ };
4272
+ var onKeyDown = function (event) {
4273
+ if (!canvasHasFocus)
4274
+ return;
4275
+ if (event.code === "Tab" && hasFocusNodes) {
4276
+ var forward = !event.shiftKey;
4277
+ var focusMoved = forward ? mainSm.focusNext() : mainSm.focusPrevious();
4278
+ if (focusMoved) {
4279
+ // Keep Tab inside the canvas — a Rive node received focus.
4280
+ event.preventDefault();
4281
+ }
4282
+ else {
4283
+ // No more traversable nodes — release Tab to the page.
4284
+ // Since we're not preventing default, blur event will fire on the canvas
4285
+ canvasHasFocus = false;
4286
+ }
4287
+ }
4288
+ };
4289
+ canvas.addEventListener("focus", onCanvasFocus);
4290
+ canvas.addEventListener("blur", onCanvasBlur);
4291
+ canvas.addEventListener("keydown", onKeyDown);
4292
+ return function () {
4293
+ canvas.removeEventListener("focus", onCanvasFocus);
4294
+ canvas.removeEventListener("blur", onCanvasBlur);
4295
+ canvas.removeEventListener("keydown", onKeyDown);
4296
+ };
4297
+ };
4298
+
4299
+
4300
+ /***/ }),
4301
+ /* 9 */
4302
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4303
+
4233
4304
  __webpack_require__.r(__webpack_exports__);
4234
4305
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4235
4306
  /* harmony export */ BLANK_URL: () => (/* binding */ BLANK_URL),
@@ -4280,7 +4351,7 @@ function sanitizeUrl(url) {
4280
4351
 
4281
4352
 
4282
4353
  /***/ }),
4283
- /* 9 */
4354
+ /* 10 */
4284
4355
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4285
4356
 
4286
4357
  __webpack_require__.r(__webpack_exports__);
@@ -4559,7 +4630,7 @@ var createFinalization = function (target, finalizable) {
4559
4630
 
4560
4631
 
4561
4632
  /***/ }),
4562
- /* 10 */
4633
+ /* 11 */
4563
4634
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4564
4635
 
4565
4636
  __webpack_require__.r(__webpack_exports__);
@@ -6178,8 +6249,10 @@ var Rive = /** @class */ (function () {
6178
6249
  this.readyForPlaying = false;
6179
6250
  // Runtime artboard
6180
6251
  this.artboard = null;
6181
- // place to clear up event listeners
6252
+ // place to clear up pointer/touch event listeners
6182
6253
  this.eventCleanup = null;
6254
+ // place to clear up focus/keyboard event listeners
6255
+ this.keyboardEventCleanup = null;
6183
6256
  this.shouldDisableRiveListeners = false;
6184
6257
  this.automaticallyHandleEvents = false;
6185
6258
  this.dispatchPointerExit = true;
@@ -6207,8 +6280,16 @@ var Rive = /** @class */ (function () {
6207
6280
  this._audioEventListener = null;
6208
6281
  // draw method bound to the class
6209
6282
  this._boundDraw = null;
6283
+ // Page visibility handler — prevents state machine advancing / rAF from being invoked with large time delta
6284
+ // when the browser tab is switched back to after being hidden.
6285
+ this._pageVisibilityHandler = null;
6286
+ // True only when the page visibility handler itself cancelled an active frame.
6287
+ // Set by stopRendering(), cleared by startRendering(). Prevents the
6288
+ // visibilitychange handler from restarting a rendering loop the caller intentionally stopped.
6289
+ this._explicitlyStoppedRendering = false;
6210
6290
  this._viewModelInstance = null;
6211
6291
  this._dataEnums = null;
6292
+ this._tabIndex = null;
6212
6293
  this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
6213
6294
  // When true, emits performance.mark/measure entries for load and render.
6214
6295
  this.enablePerfMarks = false;
@@ -6229,12 +6310,18 @@ var Rive = /** @class */ (function () {
6229
6310
  _this.resizeToCanvas();
6230
6311
  }
6231
6312
  };
6313
+ // Tracks the current animation frame request
6314
+ this.frameRequestId = null;
6232
6315
  /**
6233
6316
  * Used be draw to track when a second of active rendering time has passed.
6234
6317
  * Used for debugging purposes
6235
6318
  */
6236
6319
  this.renderSecondTimer = 0;
6237
6320
  this._boundDraw = this.draw.bind(this);
6321
+ if (typeof document !== 'undefined') {
6322
+ this._pageVisibilityHandler = this._onPageVisibilityChange.bind(this);
6323
+ document.addEventListener('visibilitychange', this._pageVisibilityHandler);
6324
+ }
6238
6325
  this.canvas = params.canvas;
6239
6326
  if (params.canvas.constructor === HTMLCanvasElement) {
6240
6327
  this._observed = observers.add(this.canvas, this.onCanvasResize);
@@ -6313,6 +6400,7 @@ var Rive = /** @class */ (function () {
6313
6400
  stateMachines: params.stateMachines,
6314
6401
  artboard: params.artboard,
6315
6402
  useOffscreenRenderer: params.useOffscreenRenderer,
6403
+ tabIndex: params.tabIndex,
6316
6404
  });
6317
6405
  }
6318
6406
  Object.defineProperty(Rive.prototype, "viewModelCount", {
@@ -6334,13 +6422,14 @@ var Rive = /** @class */ (function () {
6334
6422
  // Initializes the Rive object either from constructor or load()
6335
6423
  Rive.prototype.init = function (_a) {
6336
6424
  var _this = this;
6337
- 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;
6425
+ 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;
6338
6426
  if (this.destroyed) {
6339
6427
  return;
6340
6428
  }
6341
6429
  this.src = src;
6342
6430
  this.buffer = buffer;
6343
6431
  this.riveFile = riveFile;
6432
+ this._tabIndex = tabIndex !== null && tabIndex !== void 0 ? tabIndex : null;
6344
6433
  // If no source file url specified, it's a bust
6345
6434
  if (!this.src && !this.buffer && !this.riveFile) {
6346
6435
  throw new RiveError(Rive.missingErrorMessage);
@@ -6364,7 +6453,16 @@ var Rive = /** @class */ (function () {
6364
6453
  // Get the canvas where you want to render the animation and create a renderer
6365
6454
  if (_this.enablePerfMarks)
6366
6455
  performance.mark('rive:make-renderer:start');
6367
- _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
6456
+ try {
6457
+ _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
6458
+ if (!_this.renderer) {
6459
+ throw new Error("Renderer is null, cannot render Rive on the canvas.");
6460
+ }
6461
+ }
6462
+ catch (e) {
6463
+ console.error(e);
6464
+ throw new RiveError("Unable to create the renderer, your environment may not support WebGL. Try the @rive-app/canvas runtime as an alternative.");
6465
+ }
6368
6466
  if (_this.enablePerfMarks) {
6369
6467
  performance.mark('rive:make-renderer:end');
6370
6468
  performance.measure('rive:make-renderer', 'rive:make-renderer:start', 'rive:make-renderer:end');
@@ -6402,9 +6500,14 @@ var Rive = /** @class */ (function () {
6402
6500
  if (this.eventCleanup) {
6403
6501
  this.eventCleanup();
6404
6502
  }
6503
+ if (this.keyboardEventCleanup) {
6504
+ this.keyboardEventCleanup();
6505
+ this.keyboardEventCleanup = null;
6506
+ }
6405
6507
  if (!this.shouldDisableRiveListeners) {
6406
- var activeStateMachines = (this.animator.stateMachines || [])
6407
- .filter(function (sm) { return sm.playing && _this.runtime.hasListeners(sm.instance); })
6508
+ var playingStateMachines = this.animator.stateMachines.filter(function (sm) { return sm.playing; });
6509
+ var activeStateMachines = playingStateMachines
6510
+ .filter(function (sm) { return _this.runtime.hasListeners(sm.instance); })
6408
6511
  .map(function (sm) { return sm.instance; });
6409
6512
  var touchScrollEnabledOption = this.isTouchScrollEnabled;
6410
6513
  var dispatchPointerExit = this.dispatchPointerExit;
@@ -6426,6 +6529,27 @@ var Rive = /** @class */ (function () {
6426
6529
  enableMultiTouch: enableMultiTouch,
6427
6530
  layoutScaleFactor: this._layout.layoutScaleFactor,
6428
6531
  });
6532
+ // Wire up keyboard interactions for state machines that have focus nodes.
6533
+ // hasFocusNodes — unified focus tree check, gates tab traversal
6534
+ var smWithFocusNodes = playingStateMachines
6535
+ .filter(function (sm) { return sm.instance.hasFocusNodes(); })
6536
+ .map(function (sm) { return sm.instance; });
6537
+ if (smWithFocusNodes.length) {
6538
+ // Set the canvas as a tabbable element if there are any focus nodes.
6539
+ // Prefer the tabIndex param set by the user, otherwise use 0.
6540
+ // But do not override any explicit tabIndex already set on the canvas, if any.
6541
+ var currentCanvasTabIndex = this.canvas.tabIndex;
6542
+ // By default, canvas elements have a tabIndex of -1
6543
+ if (currentCanvasTabIndex === -1 || isNaN(currentCanvasTabIndex)) {
6544
+ this.canvas.tabIndex = (this._tabIndex !== null ? this._tabIndex : 0);
6545
+ }
6546
+ this.keyboardEventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerKeyboardInteractions)({
6547
+ canvas: this.canvas,
6548
+ stateMachine: smWithFocusNodes[0], // work off assumption of single state machine
6549
+ rive: this.runtime,
6550
+ hasFocusNodes: smWithFocusNodes.length > 0,
6551
+ });
6552
+ }
6429
6553
  }
6430
6554
  };
6431
6555
  /**
@@ -6436,6 +6560,10 @@ var Rive = /** @class */ (function () {
6436
6560
  this.eventCleanup();
6437
6561
  this.eventCleanup = null;
6438
6562
  }
6563
+ if (this.keyboardEventCleanup) {
6564
+ this.keyboardEventCleanup();
6565
+ this.keyboardEventCleanup = null;
6566
+ }
6439
6567
  };
6440
6568
  /**
6441
6569
  * If the instance has audio and the system audio is not ready
@@ -6835,6 +6963,10 @@ var Rive = /** @class */ (function () {
6835
6963
  audioManager.remove(this._audioEventListener);
6836
6964
  this._audioEventListener = null;
6837
6965
  }
6966
+ if (this._pageVisibilityHandler) {
6967
+ document.removeEventListener('visibilitychange', this._pageVisibilityHandler);
6968
+ this._pageVisibilityHandler = null;
6969
+ }
6838
6970
  (_b = this._viewModelInstance) === null || _b === void 0 ? void 0 : _b.cleanup();
6839
6971
  this._viewModelInstance = null;
6840
6972
  this._dataEnums = null;
@@ -6859,6 +6991,10 @@ var Rive = /** @class */ (function () {
6859
6991
  if (this.eventCleanup !== null) {
6860
6992
  this.eventCleanup();
6861
6993
  }
6994
+ if (this.keyboardEventCleanup) {
6995
+ this.keyboardEventCleanup();
6996
+ this.keyboardEventCleanup = null;
6997
+ }
6862
6998
  // Delete all animation and state machine instances
6863
6999
  this.stop();
6864
7000
  if (this.artboard) {
@@ -6927,6 +7063,10 @@ var Rive = /** @class */ (function () {
6927
7063
  if (this.eventCleanup) {
6928
7064
  this.eventCleanup();
6929
7065
  }
7066
+ if (this.keyboardEventCleanup) {
7067
+ this.keyboardEventCleanup();
7068
+ this.keyboardEventCleanup = null;
7069
+ }
6930
7070
  this.setupRiveListeners();
6931
7071
  this.startRendering();
6932
7072
  };
@@ -6944,6 +7084,10 @@ var Rive = /** @class */ (function () {
6944
7084
  if (this.eventCleanup) {
6945
7085
  this.eventCleanup();
6946
7086
  }
7087
+ if (this.keyboardEventCleanup) {
7088
+ this.keyboardEventCleanup();
7089
+ this.keyboardEventCleanup = null;
7090
+ }
6947
7091
  this.animator.pause(animationNames);
6948
7092
  };
6949
7093
  Rive.prototype.scrub = function (animationNames, value) {
@@ -6979,6 +7123,10 @@ var Rive = /** @class */ (function () {
6979
7123
  if (this.eventCleanup) {
6980
7124
  this.eventCleanup();
6981
7125
  }
7126
+ if (this.keyboardEventCleanup) {
7127
+ this.keyboardEventCleanup();
7128
+ this.keyboardEventCleanup = null;
7129
+ }
6982
7130
  };
6983
7131
  /**
6984
7132
  * Resets the animation
@@ -7438,6 +7586,7 @@ var Rive = /** @class */ (function () {
7438
7586
  * they would have been at if rendering had not been stopped.
7439
7587
  */
7440
7588
  Rive.prototype.stopRendering = function () {
7589
+ this._explicitlyStoppedRendering = true;
7441
7590
  if (this.loaded && this.frameRequestId) {
7442
7591
  if (this.runtime.cancelAnimationFrame) {
7443
7592
  this.runtime.cancelAnimationFrame(this.frameRequestId);
@@ -7453,6 +7602,7 @@ var Rive = /** @class */ (function () {
7453
7602
  * renderer is already active, then this will have zero effect.
7454
7603
  */
7455
7604
  Rive.prototype.startRendering = function () {
7605
+ this._explicitlyStoppedRendering = false;
7456
7606
  this.drawFrame();
7457
7607
  };
7458
7608
  Rive.prototype.scheduleRendering = function () {
@@ -7465,6 +7615,31 @@ var Rive = /** @class */ (function () {
7465
7615
  }
7466
7616
  }
7467
7617
  };
7618
+ /**
7619
+ * Called when document.visibilitychange fires (tab change, window minimize, etc.).
7620
+ * Cancels the rAF loop on hide and resets the time reference so that no accumulated time is
7621
+ * applied to state machines when the tab becomes visible again. This prevents state machine
7622
+ * advances with large time deltas when rAF starts up again.
7623
+ */
7624
+ Rive.prototype._onPageVisibilityChange = function () {
7625
+ var _a, _b;
7626
+ if (document.hidden) {
7627
+ if (this.frameRequestId !== null) {
7628
+ if ((_a = this.runtime) === null || _a === void 0 ? void 0 : _a.cancelAnimationFrame) {
7629
+ this.runtime.cancelAnimationFrame(this.frameRequestId);
7630
+ }
7631
+ else {
7632
+ cancelAnimationFrame(this.frameRequestId);
7633
+ }
7634
+ this.frameRequestId = null;
7635
+ }
7636
+ // Reset so the first resumed frame starts with elapsedTime === 0.
7637
+ this.lastRenderTime = 0;
7638
+ }
7639
+ else if (((_b = this.animator) === null || _b === void 0 ? void 0 : _b.isPlaying) && !this._explicitlyStoppedRendering) {
7640
+ this.scheduleRendering();
7641
+ }
7642
+ };
7468
7643
  /**
7469
7644
  * Enables frames-per-second (FPS) reporting for the runtime
7470
7645
  * If no callback is provided, Rive will append a fixed-position div at the top-right corner of