@rive-app/canvas-lite 2.31.2 → 2.31.4

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.31.2",
3
+ "version": "2.31.4",
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.d.ts CHANGED
@@ -306,7 +306,7 @@ export interface RiveFileParameters {
306
306
  onLoad?: EventCallback;
307
307
  onLoadError?: EventCallback;
308
308
  }
309
- export declare class RiveFile {
309
+ export declare class RiveFile implements rc.FinalizableTarget {
310
310
  private static readonly missingErrorMessage;
311
311
  private static readonly fileLoadErrorMessage;
312
312
  private src;
@@ -318,7 +318,9 @@ export declare class RiveFile {
318
318
  private eventManager;
319
319
  private referenceCount;
320
320
  private destroyed;
321
+ selfUnref: boolean;
321
322
  constructor(params: RiveFileParameters);
323
+ private releaseFile;
322
324
  private initData;
323
325
  init(): Promise<void>;
324
326
  private fireLoadError;
package/rive.js CHANGED
@@ -2272,7 +2272,7 @@ Qc();
2272
2272
  /* 2 */
2273
2273
  /***/ ((module) => {
2274
2274
 
2275
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.31.2","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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
2275
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.31.4","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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
2276
2276
 
2277
2277
  /***/ }),
2278
2278
  /* 3 */
@@ -2419,11 +2419,12 @@ __webpack_require__.r(__webpack_exports__);
2419
2419
  /* harmony export */ BLANK_URL: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.BLANK_URL),
2420
2420
  /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.CustomFileAssetLoaderWrapper),
2421
2421
  /* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileAssetWrapper),
2422
- /* harmony export */ Finalizable: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.Finalizable),
2422
+ /* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FileFinalizer),
2423
2423
  /* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontAssetWrapper),
2424
2424
  /* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.FontWrapper),
2425
2425
  /* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageAssetWrapper),
2426
2426
  /* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.ImageWrapper),
2427
+ /* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.createFinalization),
2427
2428
  /* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_2__.finalizationRegistry),
2428
2429
  /* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
2429
2430
  /* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_1__.sanitizeUrl)
@@ -2690,11 +2691,12 @@ __webpack_require__.r(__webpack_exports__);
2690
2691
  /* harmony export */ AudioWrapper: () => (/* binding */ AudioWrapper),
2691
2692
  /* harmony export */ CustomFileAssetLoaderWrapper: () => (/* binding */ CustomFileAssetLoaderWrapper),
2692
2693
  /* harmony export */ FileAssetWrapper: () => (/* binding */ FileAssetWrapper),
2693
- /* harmony export */ Finalizable: () => (/* binding */ Finalizable),
2694
+ /* harmony export */ FileFinalizer: () => (/* binding */ FileFinalizer),
2694
2695
  /* harmony export */ FontAssetWrapper: () => (/* binding */ FontAssetWrapper),
2695
2696
  /* harmony export */ FontWrapper: () => (/* binding */ FontWrapper),
2696
2697
  /* harmony export */ ImageAssetWrapper: () => (/* binding */ ImageAssetWrapper),
2697
2698
  /* harmony export */ ImageWrapper: () => (/* binding */ ImageWrapper),
2699
+ /* harmony export */ createFinalization: () => (/* binding */ createFinalization),
2698
2700
  /* harmony export */ finalizationRegistry: () => (/* binding */ finalizationRegistry)
2699
2701
  /* harmony export */ });
2700
2702
  var __extends = (undefined && undefined.__extends) || (function () {
@@ -2712,11 +2714,33 @@ var __extends = (undefined && undefined.__extends) || (function () {
2712
2714
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2713
2715
  };
2714
2716
  })();
2715
- var Finalizable = /** @class */ (function () {
2716
- function Finalizable() {
2717
+ var FileFinalizer = /** @class */ (function () {
2718
+ function FileFinalizer(file) {
2717
2719
  this.selfUnref = false;
2720
+ this._file = file;
2718
2721
  }
2719
- return Finalizable;
2722
+ FileFinalizer.prototype.unref = function () {
2723
+ if (this._file) {
2724
+ this._file.unref();
2725
+ }
2726
+ };
2727
+ return FileFinalizer;
2728
+ }());
2729
+ var ObjectFinalizer = /** @class */ (function () {
2730
+ function ObjectFinalizer(finalizableObject) {
2731
+ this._finalizableObject = finalizableObject;
2732
+ }
2733
+ ObjectFinalizer.prototype.unref = function () {
2734
+ this._finalizableObject.unref();
2735
+ };
2736
+ return ObjectFinalizer;
2737
+ }());
2738
+ var AssetWrapper = /** @class */ (function () {
2739
+ function AssetWrapper() {
2740
+ this.selfUnref = false;
2741
+ }
2742
+ AssetWrapper.prototype.unref = function () { };
2743
+ return AssetWrapper;
2720
2744
  }());
2721
2745
  var ImageWrapper = /** @class */ (function (_super) {
2722
2746
  __extends(ImageWrapper, _super);
@@ -2738,7 +2762,7 @@ var ImageWrapper = /** @class */ (function (_super) {
2738
2762
  }
2739
2763
  };
2740
2764
  return ImageWrapper;
2741
- }(Finalizable));
2765
+ }(AssetWrapper));
2742
2766
  var AudioWrapper = /** @class */ (function (_super) {
2743
2767
  __extends(AudioWrapper, _super);
2744
2768
  function AudioWrapper(audio) {
@@ -2759,7 +2783,7 @@ var AudioWrapper = /** @class */ (function (_super) {
2759
2783
  }
2760
2784
  };
2761
2785
  return AudioWrapper;
2762
- }(Finalizable));
2786
+ }(AssetWrapper));
2763
2787
  var FontWrapper = /** @class */ (function (_super) {
2764
2788
  __extends(FontWrapper, _super);
2765
2789
  function FontWrapper(font) {
@@ -2780,7 +2804,7 @@ var FontWrapper = /** @class */ (function (_super) {
2780
2804
  }
2781
2805
  };
2782
2806
  return FontWrapper;
2783
- }(Finalizable));
2807
+ }(AssetWrapper));
2784
2808
  var CustomFileAssetLoaderWrapper = /** @class */ (function () {
2785
2809
  function CustomFileAssetLoaderWrapper(runtime, loaderCallback) {
2786
2810
  this._assetLoaderCallback = loaderCallback;
@@ -2927,8 +2951,12 @@ var MyFinalizationRegistry = typeof FinalizationRegistry !== "undefined"
2927
2951
  ? FinalizationRegistry
2928
2952
  : FakeFinalizationRegistry;
2929
2953
  var finalizationRegistry = new MyFinalizationRegistry(function (ob) {
2930
- ob.unref();
2954
+ ob === null || ob === void 0 ? void 0 : ob.unref();
2931
2955
  });
2956
+ var createFinalization = function (target, finalizable) {
2957
+ var finalizer = new ObjectFinalizer(finalizable);
2958
+ finalizationRegistry.register(target, finalizer);
2959
+ };
2932
2960
 
2933
2961
 
2934
2962
 
@@ -3658,9 +3686,6 @@ var Animator = /** @class */ (function () {
3658
3686
  if (sm) {
3659
3687
  var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
3660
3688
  this.stateMachines.push(newStateMachine);
3661
- if (!playing) {
3662
- newStateMachine.advanceAndApply(0);
3663
- }
3664
3689
  }
3665
3690
  else {
3666
3691
  console.warn("State Machine with name ".concat(animatables[i], " not found."));
@@ -3679,6 +3704,16 @@ var Animator = /** @class */ (function () {
3679
3704
  Animator.prototype.play = function (animatables) {
3680
3705
  return this.add(animatables, true);
3681
3706
  };
3707
+ /**
3708
+ * Advance state machines if they are paused after initialization
3709
+ */
3710
+ Animator.prototype.advanceIfPaused = function () {
3711
+ this.stateMachines.forEach(function (sm) {
3712
+ if (!sm.playing) {
3713
+ sm.advanceAndApply(0);
3714
+ }
3715
+ });
3716
+ };
3682
3717
  /**
3683
3718
  * Pauses named animations and state machines, or everything if nothing is
3684
3719
  * specified
@@ -4222,6 +4257,7 @@ var RiveFile = /** @class */ (function () {
4222
4257
  this.enableRiveAssetCDN = true;
4223
4258
  this.referenceCount = 0;
4224
4259
  this.destroyed = false;
4260
+ this.selfUnref = false;
4225
4261
  this.src = params.src;
4226
4262
  this.buffer = params.buffer;
4227
4263
  if (params.assetLoader)
@@ -4237,19 +4273,25 @@ var RiveFile = /** @class */ (function () {
4237
4273
  if (params.onLoadError)
4238
4274
  this.on(EventType.LoadError, params.onLoadError);
4239
4275
  }
4276
+ RiveFile.prototype.releaseFile = function () {
4277
+ var _a;
4278
+ if (this.selfUnref) {
4279
+ (_a = this.file) === null || _a === void 0 ? void 0 : _a.unref();
4280
+ }
4281
+ this.file = null;
4282
+ };
4240
4283
  RiveFile.prototype.initData = function () {
4241
4284
  return __awaiter(this, void 0, void 0, function () {
4242
- var _a, loader, loaderWrapper, _b;
4243
- var _c;
4244
- return __generator(this, function (_d) {
4245
- switch (_d.label) {
4285
+ var _a, loader, loaderWrapper, _b, fileFinalizer;
4286
+ return __generator(this, function (_c) {
4287
+ switch (_c.label) {
4246
4288
  case 0:
4247
4289
  if (!this.src) return [3 /*break*/, 2];
4248
4290
  _a = this;
4249
4291
  return [4 /*yield*/, loadRiveFile(this.src)];
4250
4292
  case 1:
4251
- _a.buffer = _d.sent();
4252
- _d.label = 2;
4293
+ _a.buffer = _c.sent();
4294
+ _c.label = 2;
4253
4295
  case 2:
4254
4296
  if (this.destroyed) {
4255
4297
  return [2 /*return*/];
@@ -4263,10 +4305,11 @@ var RiveFile = /** @class */ (function () {
4263
4305
  return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
4264
4306
  case 3:
4265
4307
  // Load the Rive file
4266
- _b.file = _d.sent();
4308
+ _b.file = _c.sent();
4309
+ fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
4310
+ _utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
4267
4311
  if (this.destroyed) {
4268
- (_c = this.file) === null || _c === void 0 ? void 0 : _c.delete();
4269
- this.file = null;
4312
+ this.releaseFile();
4270
4313
  return [2 /*return*/];
4271
4314
  }
4272
4315
  if (this.file !== null) {
@@ -4347,12 +4390,10 @@ var RiveFile = /** @class */ (function () {
4347
4390
  });
4348
4391
  };
4349
4392
  RiveFile.prototype.cleanup = function () {
4350
- var _a;
4351
4393
  this.referenceCount -= 1;
4352
4394
  if (this.referenceCount <= 0) {
4353
4395
  this.removeAllRiveEventListeners();
4354
- (_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
4355
- this.file = null;
4396
+ this.releaseFile();
4356
4397
  this.destroyed = true;
4357
4398
  }
4358
4399
  };
@@ -4704,6 +4745,9 @@ var Rive = /** @class */ (function () {
4704
4745
  type: EventType.Load,
4705
4746
  data: (_a = this.src) !== null && _a !== void 0 ? _a : "buffer",
4706
4747
  });
4748
+ // Only initialize paused state machines after the load event has been fired
4749
+ // to allow users to initialize inputs and view models before the first advance
4750
+ this.animator.advanceIfPaused();
4707
4751
  // Flag ready for playback commands and clear the task queue; this order
4708
4752
  // is important or it may infinitely recurse
4709
4753
  this.readyForPlaying = true;
@@ -4739,12 +4783,6 @@ var Rive = /** @class */ (function () {
4739
4783
  }
4740
4784
  this.artboard = rootArtboard;
4741
4785
  rootArtboard.volume = this._volume * audioManager.systemVolume;
4742
- // Check that the artboard has at least 1 animation
4743
- if (this.artboard.animationCount() < 1) {
4744
- var msg = "Artboard has no animations";
4745
- this.eventManager.fire({ type: EventType.LoadError, data: msg });
4746
- throw msg;
4747
- }
4748
4786
  // Initialize the animator
4749
4787
  this.animator = new Animator(this.runtime, this.artboard, this.eventManager);
4750
4788
  // Initialize the animations; as loaded hasn't happened yet, we need to