@rive-app/canvas 2.31.1 → 2.31.3

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.31.1",
3
+ "version": "2.31.3",
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
@@ -1,4 +1,5 @@
1
1
  import * as rc from "./rive_advanced.mjs";
2
+ import { FinalizableTarget } from "./utils";
2
3
  export type AssetLoadCallback = (asset: rc.FileAsset, bytes: Uint8Array) => Boolean;
3
4
  export type { FileAsset, AudioAsset, FontAsset, ImageAsset, } from "./rive_advanced.mjs";
4
5
  /**
@@ -306,7 +307,7 @@ export interface RiveFileParameters {
306
307
  onLoad?: EventCallback;
307
308
  onLoadError?: EventCallback;
308
309
  }
309
- export declare class RiveFile {
310
+ export declare class RiveFile implements FinalizableTarget {
310
311
  private static readonly missingErrorMessage;
311
312
  private static readonly fileLoadErrorMessage;
312
313
  private src;
@@ -318,7 +319,9 @@ export declare class RiveFile {
318
319
  private eventManager;
319
320
  private referenceCount;
320
321
  private destroyed;
322
+ selfUnref: boolean;
321
323
  constructor(params: RiveFileParameters);
324
+ private releaseFile;
322
325
  private initData;
323
326
  init(): Promise<void>;
324
327
  private fireLoadError;
package/rive.js CHANGED
@@ -747,7 +747,7 @@ function Xa(a, b) {
747
747
  return Wa(c, a, b);
748
748
  }));
749
749
  }
750
- var Ya, Za, cb = {460364:(a, b, c, d, e) => {
750
+ var Ya, Za, cb = {461560:(a, b, c, d, e) => {
751
751
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
752
752
  return 0;
753
753
  }
@@ -810,11 +810,11 @@ var Ya, Za, cb = {460364:(a, b, c, d, e) => {
810
810
  }
811
811
  window.h.Aa += 1;
812
812
  return 1;
813
- }, 462542:() => {
813
+ }, 463738:() => {
814
814
  "undefined" !== typeof window.h && (window.h.Ta.map(function(a) {
815
815
  document.removeEventListener(a, window.h.unlock, !0);
816
816
  }), --window.h.Aa, 0 === window.h.Aa && delete window.h);
817
- }, 462846:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 462950:() => {
817
+ }, 464042:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 464146:() => {
818
818
  try {
819
819
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
820
820
  a.close();
@@ -822,7 +822,7 @@ var Ya, Za, cb = {460364:(a, b, c, d, e) => {
822
822
  } catch (c) {
823
823
  return 0;
824
824
  }
825
- }, 463121:(a, b, c, d, e, f) => {
825
+ }, 464317:(a, b, c, d, e, f) => {
826
826
  if ("undefined" === typeof window.h) {
827
827
  return -1;
828
828
  }
@@ -868,7 +868,7 @@ var Ya, Za, cb = {460364:(a, b, c, d, e) => {
868
868
  a == window.h.I.ya && g.Z.connect(g.J.destination);
869
869
  g.qb = f;
870
870
  return window.h.yc(g);
871
- }, 465998:a => window.h.ra(a).J.sampleRate, 466071:a => {
871
+ }, 467194:a => window.h.ra(a).J.sampleRate, 467267:a => {
872
872
  a = window.h.ra(a);
873
873
  void 0 !== a.Z && (a.Z.onaudioprocess = function() {
874
874
  }, a.Z.disconnect(), a.Z = void 0);
@@ -876,13 +876,13 @@ var Ya, Za, cb = {460364:(a, b, c, d, e) => {
876
876
  a.J.close();
877
877
  a.J = void 0;
878
878
  a.qb = void 0;
879
- }, 466471:a => {
879
+ }, 467667:a => {
880
880
  window.h.Cb(a);
881
- }, 466521:a => {
881
+ }, 467717:a => {
882
882
  a = window.h.ra(a);
883
883
  a.J.resume();
884
884
  a.state = window.h.ga.yb;
885
- }, 466660:a => {
885
+ }, 467856:a => {
886
886
  a = window.h.ra(a);
887
887
  a.J.suspend();
888
888
  a.state = window.h.ga.stopped;
@@ -3370,7 +3370,7 @@ $d();
3370
3370
  /* 2 */
3371
3371
  /***/ ((module) => {
3372
3372
 
3373
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.31.1","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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3373
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.31.3","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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3374
3374
 
3375
3375
  /***/ }),
3376
3376
  /* 3 */
@@ -3517,11 +3517,12 @@ __webpack_require__.r(__webpack_exports__);
3517
3517
  /* harmony export */ BLANK_URL: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.BLANK_URL),
3518
3518
  /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.CustomFileAssetLoaderWrapper),
3519
3519
  /* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileAssetWrapper),
3520
- /* harmony export */ Finalizable: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.Finalizable),
3520
+ /* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileFinalizer),
3521
3521
  /* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontAssetWrapper),
3522
3522
  /* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontWrapper),
3523
3523
  /* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageAssetWrapper),
3524
3524
  /* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageWrapper),
3525
+ /* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.createFinalization),
3525
3526
  /* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.finalizationRegistry),
3526
3527
  /* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
3527
3528
  /* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.sanitizeUrl)
@@ -3788,11 +3789,12 @@ __webpack_require__.r(__webpack_exports__);
3788
3789
  /* harmony export */ AudioWrapper: () => (/* binding */ AudioWrapper),
3789
3790
  /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* binding */ CustomFileAssetLoaderWrapper),
3790
3791
  /* harmony export */ FileAssetWrapper: () => (/* binding */ FileAssetWrapper),
3791
- /* harmony export */ Finalizable: () => (/* binding */ Finalizable),
3792
+ /* harmony export */ FileFinalizer: () => (/* binding */ FileFinalizer),
3792
3793
  /* harmony export */ FontAssetWrapper: () => (/* binding */ FontAssetWrapper),
3793
3794
  /* harmony export */ FontWrapper: () => (/* binding */ FontWrapper),
3794
3795
  /* harmony export */ ImageAssetWrapper: () => (/* binding */ ImageAssetWrapper),
3795
3796
  /* harmony export */ ImageWrapper: () => (/* binding */ ImageWrapper),
3797
+ /* harmony export */ createFinalization: () => (/* binding */ createFinalization),
3796
3798
  /* harmony export */ finalizationRegistry: () => (/* binding */ finalizationRegistry)
3797
3799
  /* harmony export */ });
3798
3800
  var __extends = (undefined && undefined.__extends) || (function () {
@@ -3810,11 +3812,33 @@ var __extends = (undefined && undefined.__extends) || (function () {
3810
3812
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3811
3813
  };
3812
3814
  })();
3813
- var Finalizable = /** @class */ (function () {
3814
- function Finalizable() {
3815
+ var FileFinalizer = /** @class */ (function () {
3816
+ function FileFinalizer(file) {
3815
3817
  this.selfUnref = false;
3818
+ this._file = file;
3816
3819
  }
3817
- return Finalizable;
3820
+ FileFinalizer.prototype.unref = function () {
3821
+ if (this._file) {
3822
+ this._file.unref();
3823
+ }
3824
+ };
3825
+ return FileFinalizer;
3826
+ }());
3827
+ var ObjectFinalizer = /** @class */ (function () {
3828
+ function ObjectFinalizer(finalizableObject) {
3829
+ this._finalizableObject = finalizableObject;
3830
+ }
3831
+ ObjectFinalizer.prototype.unref = function () {
3832
+ this._finalizableObject.unref();
3833
+ };
3834
+ return ObjectFinalizer;
3835
+ }());
3836
+ var AssetWrapper = /** @class */ (function () {
3837
+ function AssetWrapper() {
3838
+ this.selfUnref = false;
3839
+ }
3840
+ AssetWrapper.prototype.unref = function () { };
3841
+ return AssetWrapper;
3818
3842
  }());
3819
3843
  var ImageWrapper = /** @class */ (function (_super) {
3820
3844
  __extends(ImageWrapper, _super);
@@ -3836,7 +3860,7 @@ var ImageWrapper = /** @class */ (function (_super) {
3836
3860
  }
3837
3861
  };
3838
3862
  return ImageWrapper;
3839
- }(Finalizable));
3863
+ }(AssetWrapper));
3840
3864
  var AudioWrapper = /** @class */ (function (_super) {
3841
3865
  __extends(AudioWrapper, _super);
3842
3866
  function AudioWrapper(audio) {
@@ -3857,7 +3881,7 @@ var AudioWrapper = /** @class */ (function (_super) {
3857
3881
  }
3858
3882
  };
3859
3883
  return AudioWrapper;
3860
- }(Finalizable));
3884
+ }(AssetWrapper));
3861
3885
  var FontWrapper = /** @class */ (function (_super) {
3862
3886
  __extends(FontWrapper, _super);
3863
3887
  function FontWrapper(font) {
@@ -3878,7 +3902,7 @@ var FontWrapper = /** @class */ (function (_super) {
3878
3902
  }
3879
3903
  };
3880
3904
  return FontWrapper;
3881
- }(Finalizable));
3905
+ }(AssetWrapper));
3882
3906
  var CustomFileAssetLoaderWrapper = /** @class */ (function () {
3883
3907
  function CustomFileAssetLoaderWrapper(runtime, loaderCallback) {
3884
3908
  this._assetLoaderCallback = loaderCallback;
@@ -4025,8 +4049,12 @@ var MyFinalizationRegistry = typeof FinalizationRegistry !== "undefined"
4025
4049
  ? FinalizationRegistry
4026
4050
  : FakeFinalizationRegistry;
4027
4051
  var finalizationRegistry = new MyFinalizationRegistry(function (ob) {
4028
- ob.unref();
4052
+ ob === null || ob === void 0 ? void 0 : ob.unref();
4029
4053
  });
4054
+ var createFinalization = function (target, finalizable) {
4055
+ var finalizer = new ObjectFinalizer(finalizable);
4056
+ finalizationRegistry.register(target, finalizer);
4057
+ };
4030
4058
 
4031
4059
 
4032
4060
 
@@ -4756,9 +4784,6 @@ var Animator = /** @class */ (function () {
4756
4784
  if (sm) {
4757
4785
  var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
4758
4786
  this.stateMachines.push(newStateMachine);
4759
- if (!playing) {
4760
- newStateMachine.advanceAndApply(0);
4761
- }
4762
4787
  }
4763
4788
  else {
4764
4789
  console.warn("State Machine with name ".concat(animatables[i], " not found."));
@@ -4777,6 +4802,16 @@ var Animator = /** @class */ (function () {
4777
4802
  Animator.prototype.play = function (animatables) {
4778
4803
  return this.add(animatables, true);
4779
4804
  };
4805
+ /**
4806
+ * Advance state machines if they are paused after initialization
4807
+ */
4808
+ Animator.prototype.advanceIfPaused = function () {
4809
+ this.stateMachines.forEach(function (sm) {
4810
+ if (!sm.playing) {
4811
+ sm.advanceAndApply(0);
4812
+ }
4813
+ });
4814
+ };
4780
4815
  /**
4781
4816
  * Pauses named animations and state machines, or everything if nothing is
4782
4817
  * specified
@@ -5320,6 +5355,7 @@ var RiveFile = /** @class */ (function () {
5320
5355
  this.enableRiveAssetCDN = true;
5321
5356
  this.referenceCount = 0;
5322
5357
  this.destroyed = false;
5358
+ this.selfUnref = false;
5323
5359
  this.src = params.src;
5324
5360
  this.buffer = params.buffer;
5325
5361
  if (params.assetLoader)
@@ -5335,19 +5371,25 @@ var RiveFile = /** @class */ (function () {
5335
5371
  if (params.onLoadError)
5336
5372
  this.on(EventType.LoadError, params.onLoadError);
5337
5373
  }
5374
+ RiveFile.prototype.releaseFile = function () {
5375
+ var _a;
5376
+ if (this.selfUnref) {
5377
+ (_a = this.file) === null || _a === void 0 ? void 0 : _a.unref();
5378
+ }
5379
+ this.file = null;
5380
+ };
5338
5381
  RiveFile.prototype.initData = function () {
5339
5382
  return __awaiter(this, void 0, void 0, function () {
5340
- var _a, loader, loaderWrapper, _b;
5341
- var _c;
5342
- return __generator(this, function (_d) {
5343
- switch (_d.label) {
5383
+ var _a, loader, loaderWrapper, _b, fileFinalizer;
5384
+ return __generator(this, function (_c) {
5385
+ switch (_c.label) {
5344
5386
  case 0:
5345
5387
  if (!this.src) return [3 /*break*/, 2];
5346
5388
  _a = this;
5347
5389
  return [4 /*yield*/, loadRiveFile(this.src)];
5348
5390
  case 1:
5349
- _a.buffer = _d.sent();
5350
- _d.label = 2;
5391
+ _a.buffer = _c.sent();
5392
+ _c.label = 2;
5351
5393
  case 2:
5352
5394
  if (this.destroyed) {
5353
5395
  return [2 /*return*/];
@@ -5361,10 +5403,11 @@ var RiveFile = /** @class */ (function () {
5361
5403
  return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
5362
5404
  case 3:
5363
5405
  // Load the Rive file
5364
- _b.file = _d.sent();
5406
+ _b.file = _c.sent();
5407
+ fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
5408
+ _utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
5365
5409
  if (this.destroyed) {
5366
- (_c = this.file) === null || _c === void 0 ? void 0 : _c.delete();
5367
- this.file = null;
5410
+ this.releaseFile();
5368
5411
  return [2 /*return*/];
5369
5412
  }
5370
5413
  if (this.file !== null) {
@@ -5445,12 +5488,10 @@ var RiveFile = /** @class */ (function () {
5445
5488
  });
5446
5489
  };
5447
5490
  RiveFile.prototype.cleanup = function () {
5448
- var _a;
5449
5491
  this.referenceCount -= 1;
5450
5492
  if (this.referenceCount <= 0) {
5451
5493
  this.removeAllRiveEventListeners();
5452
- (_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
5453
- this.file = null;
5494
+ this.releaseFile();
5454
5495
  this.destroyed = true;
5455
5496
  }
5456
5497
  };
@@ -5802,6 +5843,9 @@ var Rive = /** @class */ (function () {
5802
5843
  type: EventType.Load,
5803
5844
  data: (_a = this.src) !== null && _a !== void 0 ? _a : "buffer",
5804
5845
  });
5846
+ // Only initialize paused state machines after the load event has been fired
5847
+ // to allow users to initialize inputs and view models before the first advance
5848
+ this.animator.advanceIfPaused();
5805
5849
  // Flag ready for playback commands and clear the task queue; this order
5806
5850
  // is important or it may infinitely recurse
5807
5851
  this.readyForPlaying = true;
@@ -5837,12 +5881,6 @@ var Rive = /** @class */ (function () {
5837
5881
  }
5838
5882
  this.artboard = rootArtboard;
5839
5883
  rootArtboard.volume = this._volume * audioManager.systemVolume;
5840
- // Check that the artboard has at least 1 animation
5841
- if (this.artboard.animationCount() < 1) {
5842
- var msg = "Artboard has no animations";
5843
- this.eventManager.fire({ type: EventType.LoadError, data: msg });
5844
- throw msg;
5845
- }
5846
5884
  // Initialize the animator
5847
5885
  this.animator = new Animator(this.runtime, this.artboard, this.eventManager);
5848
5886
  // Initialize the animations; as loaded hasn't happened yet, we need to