@rive-app/canvas 2.35.4 → 2.36.0

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.35.4",
3
+ "version": "2.36.0",
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
@@ -73,6 +73,11 @@ export declare class RuntimeLoader {
73
73
  private static rive;
74
74
  private static wasmURL;
75
75
  private constructor();
76
+ /**
77
+ * When true, performance.mark / performance.measure entries are emitted for
78
+ * WASM initialization.
79
+ */
80
+ static enablePerfMarks: boolean;
76
81
  private static loadRuntime;
77
82
  static getInstance(callback: RuntimeCallback): void;
78
83
  static awaitInstance(): Promise<rc.RiveCanvas>;
@@ -270,6 +275,13 @@ export interface RiveParameters {
270
275
  * Enum with drawing options for optimizations
271
276
  */
272
277
  drawingOptions?: DrawOptimizationOptions;
278
+ /**
279
+ * Emit performance.mark / performance.measure entries for load lifecycle
280
+ * events and the first 3 render frames. Useful for profiling Rive's
281
+ * contribution to load and render time in browser devtools.
282
+ * False by default.
283
+ */
284
+ enablePerfMarks?: boolean;
273
285
  onLoad?: EventCallback;
274
286
  onLoadError?: EventCallback;
275
287
  onPlay?: EventCallback;
@@ -334,6 +346,11 @@ export interface RiveFileParameters {
334
346
  enableRiveAssetCDN?: boolean;
335
347
  onLoad?: EventCallback;
336
348
  onLoadError?: EventCallback;
349
+ /**
350
+ * Emit performance.mark / performance.measure entries for load lifecycle
351
+ * events. False by default.
352
+ */
353
+ enablePerfMarks?: boolean;
337
354
  }
338
355
  export declare class RiveFile implements rc.FinalizableTarget {
339
356
  private static readonly missingErrorMessage;
@@ -344,6 +361,7 @@ export declare class RiveFile implements rc.FinalizableTarget {
344
361
  private file;
345
362
  private assetLoader;
346
363
  private enableRiveAssetCDN;
364
+ private enablePerfMarks;
347
365
  private eventManager;
348
366
  private referenceCount;
349
367
  private destroyed;
@@ -353,6 +371,8 @@ export declare class RiveFile implements rc.FinalizableTarget {
353
371
  private releaseFile;
354
372
  private releaseBindableArtboards;
355
373
  private initData;
374
+ private loadRiveFileBytes;
375
+ private loadRuntime;
356
376
  init(): Promise<void>;
357
377
  private fireLoadError;
358
378
  /**
@@ -436,6 +456,7 @@ export declare class Rive {
436
456
  private _viewModelInstance;
437
457
  private _dataEnums;
438
458
  private drawOptimization;
459
+ private enablePerfMarks;
439
460
  durations: number[];
440
461
  frameTimes: number[];
441
462
  frameCount: number;
@@ -918,6 +939,10 @@ export declare class ViewModelInstance {
918
939
  incrementReferenceCount(): void;
919
940
  decrementReferenceCount(): void;
920
941
  get properties(): rc.ViewModelProperty[];
942
+ /**
943
+ * Get the name of the ViewModel definition this instance was created from.
944
+ */
945
+ get viewModelName(): string;
921
946
  internalIncrementReferenceCount(): void;
922
947
  cleanup(): void;
923
948
  }
package/rive.js CHANGED
@@ -748,7 +748,7 @@ function Ya(a, b) {
748
748
  return Xa(c, a, b);
749
749
  }));
750
750
  }
751
- var Za, $a, db = {478498:(a, b, c, d, e) => {
751
+ var Za, $a, db = {478802:(a, b, c, d, e) => {
752
752
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
753
753
  return 0;
754
754
  }
@@ -811,11 +811,11 @@ var Za, $a, db = {478498:(a, b, c, d, e) => {
811
811
  }
812
812
  window.h.za += 1;
813
813
  return 1;
814
- }, 480676:() => {
814
+ }, 480980:() => {
815
815
  "undefined" !== typeof window.h && (window.h.Sa.map(function(a) {
816
816
  document.removeEventListener(a, window.h.unlock, !0);
817
817
  }), --window.h.za, 0 === window.h.za && delete window.h);
818
- }, 480980:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 481084:() => {
818
+ }, 481284:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 481388:() => {
819
819
  try {
820
820
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
821
821
  a.close();
@@ -823,7 +823,7 @@ var Za, $a, db = {478498:(a, b, c, d, e) => {
823
823
  } catch (c) {
824
824
  return 0;
825
825
  }
826
- }, 481255:(a, b, c, d, e, f) => {
826
+ }, 481559:(a, b, c, d, e, f) => {
827
827
  if ("undefined" === typeof window.h) {
828
828
  return -1;
829
829
  }
@@ -869,7 +869,7 @@ var Za, $a, db = {478498:(a, b, c, d, e) => {
869
869
  a == window.h.J.xa && g.Z.connect(g.L.destination);
870
870
  g.pb = f;
871
871
  return window.h.sc(g);
872
- }, 484132:a => window.h.qa(a).L.sampleRate, 484205:a => {
872
+ }, 484436:a => window.h.qa(a).L.sampleRate, 484509:a => {
873
873
  a = window.h.qa(a);
874
874
  void 0 !== a.Z && (a.Z.onaudioprocess = function() {
875
875
  }, a.Z.disconnect(), a.Z = void 0);
@@ -877,13 +877,13 @@ var Za, $a, db = {478498:(a, b, c, d, e) => {
877
877
  a.L.close();
878
878
  a.L = void 0;
879
879
  a.pb = void 0;
880
- }, 484605:a => {
880
+ }, 484909:a => {
881
881
  window.h.Ab(a);
882
- }, 484655:a => {
882
+ }, 484959:a => {
883
883
  a = window.h.qa(a);
884
884
  a.L.resume();
885
885
  a.state = window.h.ga.wb;
886
- }, 484794:a => {
886
+ }, 485098:a => {
887
887
  a = window.h.qa(a);
888
888
  a.L.suspend();
889
889
  a.state = window.h.ga.stopped;
@@ -3391,7 +3391,7 @@ moduleRtn = da;
3391
3391
  /* 2 */
3392
3392
  /***/ ((module) => {
3393
3393
 
3394
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.35.4","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}}');
3394
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.36.0","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}}');
3395
3395
 
3396
3396
  /***/ }),
3397
3397
  /* 3 */
@@ -4455,12 +4455,18 @@ var RuntimeLoader = /** @class */ (function () {
4455
4455
  }
4456
4456
  // Loads the runtime
4457
4457
  RuntimeLoader.loadRuntime = function () {
4458
+ if (RuntimeLoader.enablePerfMarks)
4459
+ performance.mark('rive:wasm-init:start');
4458
4460
  _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]({
4459
4461
  // Loads Wasm bundle
4460
4462
  locateFile: function () { return RuntimeLoader.wasmURL; },
4461
4463
  })
4462
4464
  .then(function (rive) {
4463
4465
  var _a;
4466
+ if (RuntimeLoader.enablePerfMarks) {
4467
+ performance.mark('rive:wasm-init:end');
4468
+ performance.measure('rive:wasm-init', 'rive:wasm-init:start', 'rive:wasm-init:end');
4469
+ }
4464
4470
  RuntimeLoader.runtime = rive;
4465
4471
  // Fire all the callbacks
4466
4472
  while (RuntimeLoader.callBackQueue.length > 0) {
@@ -4543,6 +4549,11 @@ var RuntimeLoader = /** @class */ (function () {
4543
4549
  // Path to the Wasm file; default path works for testing only;
4544
4550
  // if embedded wasm is used then this is never used.
4545
4551
  RuntimeLoader.wasmURL = "https://unpkg.com/".concat(package_json__WEBPACK_IMPORTED_MODULE_1__.name, "@").concat(package_json__WEBPACK_IMPORTED_MODULE_1__.version, "/rive.wasm");
4552
+ /**
4553
+ * When true, performance.mark / performance.measure entries are emitted for
4554
+ * WASM initialization.
4555
+ */
4556
+ RuntimeLoader.enablePerfMarks = false;
4546
4557
  return RuntimeLoader;
4547
4558
  }());
4548
4559
 
@@ -5480,6 +5491,8 @@ var RiveFile = /** @class */ (function () {
5480
5491
  function RiveFile(params) {
5481
5492
  // Allow the runtime to automatically load assets hosted in Rive's runtime.
5482
5493
  this.enableRiveAssetCDN = true;
5494
+ // When true, emits performance.mark/measure entries during RiveFile load.
5495
+ this.enablePerfMarks = false;
5483
5496
  this.referenceCount = 0;
5484
5497
  this.destroyed = false;
5485
5498
  this.selfUnref = false;
@@ -5492,6 +5505,9 @@ var RiveFile = /** @class */ (function () {
5492
5505
  typeof params.enableRiveAssetCDN == "boolean"
5493
5506
  ? params.enableRiveAssetCDN
5494
5507
  : true;
5508
+ this.enablePerfMarks = !!params.enablePerfMarks;
5509
+ if (this.enablePerfMarks)
5510
+ RuntimeLoader.enablePerfMarks = true;
5495
5511
  // New event management system
5496
5512
  this.eventManager = new EventManager();
5497
5513
  if (params.onLoad)
@@ -5517,7 +5533,7 @@ var RiveFile = /** @class */ (function () {
5517
5533
  return __generator(this, function (_c) {
5518
5534
  switch (_c.label) {
5519
5535
  case 0:
5520
- if (!this.src) return [3 /*break*/, 2];
5536
+ if (!(this.src && !this.buffer)) return [3 /*break*/, 2];
5521
5537
  _a = this;
5522
5538
  return [4 /*yield*/, loadRiveFile(this.src)];
5523
5539
  case 1:
@@ -5532,11 +5548,16 @@ var RiveFile = /** @class */ (function () {
5532
5548
  loader = loaderWrapper.assetLoader;
5533
5549
  }
5534
5550
  // Load the Rive file
5551
+ if (this.enablePerfMarks)
5552
+ performance.mark('rive:file-load:start');
5535
5553
  _b = this;
5536
5554
  return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
5537
5555
  case 3:
5538
- // Load the Rive file
5539
5556
  _b.file = _c.sent();
5557
+ if (this.enablePerfMarks) {
5558
+ performance.mark('rive:file-load:end');
5559
+ performance.measure('rive:file-load', 'rive:file-load:start', 'rive:file-load:end');
5560
+ }
5540
5561
  fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
5541
5562
  _utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
5542
5563
  if (this.destroyed) {
@@ -5557,9 +5578,45 @@ var RiveFile = /** @class */ (function () {
5557
5578
  });
5558
5579
  });
5559
5580
  };
5581
+ RiveFile.prototype.loadRiveFileBytes = function () {
5582
+ return __awaiter(this, void 0, void 0, function () {
5583
+ var bufferPromise;
5584
+ return __generator(this, function (_a) {
5585
+ if (this.enablePerfMarks)
5586
+ performance.mark('rive:fetch-riv:start');
5587
+ bufferPromise = this.src
5588
+ ? loadRiveFile(this.src)
5589
+ : Promise.resolve(this.buffer);
5590
+ if (this.enablePerfMarks && this.src) {
5591
+ bufferPromise.then(function () {
5592
+ performance.mark('rive:fetch-riv:end');
5593
+ performance.measure('rive:fetch-riv', 'rive:fetch-riv:start', 'rive:fetch-riv:end');
5594
+ });
5595
+ }
5596
+ return [2 /*return*/, bufferPromise];
5597
+ });
5598
+ });
5599
+ };
5600
+ RiveFile.prototype.loadRuntime = function () {
5601
+ return __awaiter(this, void 0, void 0, function () {
5602
+ var runtimePromise;
5603
+ return __generator(this, function (_a) {
5604
+ if (this.enablePerfMarks)
5605
+ performance.mark('rive:await-wasm:start');
5606
+ runtimePromise = RuntimeLoader.awaitInstance();
5607
+ if (this.enablePerfMarks) {
5608
+ runtimePromise.then(function () {
5609
+ performance.mark('rive:await-wasm:end');
5610
+ performance.measure('rive:await-wasm', 'rive:await-wasm:start', 'rive:await-wasm:end');
5611
+ });
5612
+ }
5613
+ return [2 /*return*/, runtimePromise];
5614
+ });
5615
+ });
5616
+ };
5560
5617
  RiveFile.prototype.init = function () {
5561
5618
  return __awaiter(this, void 0, void 0, function () {
5562
- var _a, error_1;
5619
+ var _a, bufferResolved, runtimeResolved, error_1;
5563
5620
  return __generator(this, function (_b) {
5564
5621
  switch (_b.label) {
5565
5622
  case 0:
@@ -5571,16 +5628,24 @@ var RiveFile = /** @class */ (function () {
5571
5628
  _b.label = 1;
5572
5629
  case 1:
5573
5630
  _b.trys.push([1, 4, , 5]);
5574
- _a = this;
5575
- return [4 /*yield*/, RuntimeLoader.awaitInstance()];
5631
+ return [4 /*yield*/, Promise.all([this.loadRiveFileBytes(), this.loadRuntime()])];
5576
5632
  case 2:
5577
- _a.runtime = _b.sent();
5633
+ _a = _b.sent(), bufferResolved = _a[0], runtimeResolved = _a[1];
5578
5634
  if (this.destroyed) {
5579
5635
  return [2 /*return*/];
5580
5636
  }
5637
+ // .riv file buffer and WASM runtime instance
5638
+ this.buffer = bufferResolved;
5639
+ this.runtime = runtimeResolved;
5640
+ if (this.enablePerfMarks)
5641
+ performance.mark('rive:init-data:start');
5581
5642
  return [4 /*yield*/, this.initData()];
5582
5643
  case 3:
5583
5644
  _b.sent();
5645
+ if (this.enablePerfMarks) {
5646
+ performance.mark('rive:init-data:end');
5647
+ performance.measure('rive:init-data', 'rive:init-data:start', 'rive:init-data:end');
5648
+ }
5584
5649
  return [3 /*break*/, 5];
5585
5650
  case 4:
5586
5651
  error_1 = _b.sent();
@@ -5748,6 +5813,8 @@ var Rive = /** @class */ (function () {
5748
5813
  this._viewModelInstance = null;
5749
5814
  this._dataEnums = null;
5750
5815
  this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
5816
+ // When true, emits performance.mark/measure entries for load and render.
5817
+ this.enablePerfMarks = false;
5751
5818
  // Durations to generate a frame for the last second. Used for performance profiling.
5752
5819
  this.durations = [];
5753
5820
  this.frameTimes = [];
@@ -5794,6 +5861,9 @@ var Rive = /** @class */ (function () {
5794
5861
  params.enableRiveAssetCDN === undefined
5795
5862
  ? true
5796
5863
  : params.enableRiveAssetCDN;
5864
+ this.enablePerfMarks = !!params.enablePerfMarks;
5865
+ if (this.enablePerfMarks)
5866
+ RuntimeLoader.enablePerfMarks = true;
5797
5867
  // New event management system
5798
5868
  this.eventManager = new EventManager();
5799
5869
  if (params.onLoad)
@@ -5895,7 +5965,13 @@ var Rive = /** @class */ (function () {
5895
5965
  _this.removeRiveListeners();
5896
5966
  _this.deleteRiveRenderer();
5897
5967
  // Get the canvas where you want to render the animation and create a renderer
5968
+ if (_this.enablePerfMarks)
5969
+ performance.mark('rive:make-renderer:start');
5898
5970
  _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
5971
+ if (_this.enablePerfMarks) {
5972
+ performance.mark('rive:make-renderer:end');
5973
+ performance.measure('rive:make-renderer', 'rive:make-renderer:start', 'rive:make-renderer:end');
5974
+ }
5899
5975
  // Initial size adjustment based on devicePixelRatio if no width/height are
5900
5976
  // specified explicitly
5901
5977
  if (!(_this.canvas.width || _this.canvas.height)) {
@@ -6007,6 +6083,7 @@ var Rive = /** @class */ (function () {
6007
6083
  buffer: this.buffer,
6008
6084
  enableRiveAssetCDN: this.enableRiveAssetCDN,
6009
6085
  assetLoader: this.assetLoader,
6086
+ enablePerfMarks: this.enablePerfMarks,
6010
6087
  });
6011
6088
  this.riveFile = riveFile;
6012
6089
  return [4 /*yield*/, riveFile.init()];
@@ -6173,6 +6250,9 @@ var Rive = /** @class */ (function () {
6173
6250
  // - Advance non-paused state machines by the elapsed number of seconds
6174
6251
  // - Advance to the first frame even when autoplay is false
6175
6252
  var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
6253
+ // Instrument the first 3 frames so the Performance timeline shows precise
6254
+ // per-call latency for advance, draw, and flush without polluting the trace.
6255
+ var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
6176
6256
  for (var _b = 0, activeStateMachines_1 = activeStateMachines; _b < activeStateMachines_1.length; _b++) {
6177
6257
  var stateMachine = activeStateMachines_1[_b];
6178
6258
  // Check for events before the current frame's state machine advance
@@ -6207,7 +6287,13 @@ var Rive = /** @class */ (function () {
6207
6287
  }
6208
6288
  }
6209
6289
  }
6290
+ if (_perfFrame >= 0)
6291
+ performance.mark("rive:sm-advance:start:f".concat(_perfFrame));
6210
6292
  stateMachine.advanceAndApply(elapsedTime);
6293
+ if (_perfFrame >= 0) {
6294
+ performance.mark("rive:sm-advance:end:f".concat(_perfFrame));
6295
+ performance.measure("rive:sm-advance:f".concat(_perfFrame), "rive:sm-advance:start:f".concat(_perfFrame), "rive:sm-advance:end:f".concat(_perfFrame));
6296
+ }
6211
6297
  // stateMachine.instance.apply(this.artboard);
6212
6298
  }
6213
6299
  // Once the animations have been applied to the artboard, advance it
@@ -6227,10 +6313,28 @@ var Rive = /** @class */ (function () {
6227
6313
  renderer.clear();
6228
6314
  renderer.save();
6229
6315
  // Update the renderer alignment if necessary
6316
+ if (_perfFrame >= 0)
6317
+ performance.mark("rive:align-renderer:start:f".concat(_perfFrame));
6230
6318
  this.alignRenderer();
6319
+ if (_perfFrame >= 0) {
6320
+ performance.mark("rive:align-renderer:end:f".concat(_perfFrame));
6321
+ performance.measure("rive:align-renderer:f".concat(_perfFrame), "rive:align-renderer:start:f".concat(_perfFrame), "rive:align-renderer:end:f".concat(_perfFrame));
6322
+ }
6323
+ if (_perfFrame >= 0)
6324
+ performance.mark("rive:artboard-draw:start:f".concat(_perfFrame));
6231
6325
  this.artboard.draw(renderer);
6326
+ if (_perfFrame >= 0) {
6327
+ performance.mark("rive:artboard-draw:end:f".concat(_perfFrame));
6328
+ performance.measure("rive:artboard-draw:f".concat(_perfFrame), "rive:artboard-draw:start:f".concat(_perfFrame), "rive:artboard-draw:end:f".concat(_perfFrame));
6329
+ }
6232
6330
  renderer.restore();
6331
+ if (_perfFrame >= 0)
6332
+ performance.mark("rive:renderer-flush:start:f".concat(_perfFrame));
6233
6333
  renderer.flush();
6334
+ if (_perfFrame >= 0) {
6335
+ performance.mark("rive:renderer-flush:end:f".concat(_perfFrame));
6336
+ performance.measure("rive:renderer-flush:f".concat(_perfFrame), "rive:renderer-flush:start:f".concat(_perfFrame), "rive:renderer-flush:end:f".concat(_perfFrame));
6337
+ }
6234
6338
  this._needsRedraw = false;
6235
6339
  }
6236
6340
  }
@@ -7696,6 +7800,17 @@ var ViewModelInstance = /** @class */ (function () {
7696
7800
  enumerable: false,
7697
7801
  configurable: true
7698
7802
  });
7803
+ Object.defineProperty(ViewModelInstance.prototype, "viewModelName", {
7804
+ /**
7805
+ * Get the name of the ViewModel definition this instance was created from.
7806
+ */
7807
+ get: function () {
7808
+ var _a, _b;
7809
+ return (_b = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.getViewModelName()) !== null && _b !== void 0 ? _b : "";
7810
+ },
7811
+ enumerable: false,
7812
+ configurable: true
7813
+ });
7699
7814
  ViewModelInstance.prototype.internalIncrementReferenceCount = function () {
7700
7815
  this._referenceCount++;
7701
7816
  };