@rive-app/webgl2 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/webgl2",
3
- "version": "2.35.4",
3
+ "version": "2.36.0",
4
4
  "description": "Rive's webgl2 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
@@ -427,7 +427,7 @@ function Na(a, b) {
427
427
  return Ma(c, a, b);
428
428
  }));
429
429
  }
430
- var Oa, Pa, Ta = {562865:(a, b, c, d, e) => {
430
+ var Oa, Pa, Ta = {563121:(a, b, c, d, e) => {
431
431
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
432
432
  return 0;
433
433
  }
@@ -490,11 +490,11 @@ var Oa, Pa, Ta = {562865:(a, b, c, d, e) => {
490
490
  }
491
491
  window.h.Ea += 1;
492
492
  return 1;
493
- }, 565043:() => {
493
+ }, 565299:() => {
494
494
  "undefined" !== typeof window.h && (window.h.Xa.map(function(a) {
495
495
  document.removeEventListener(a, window.h.unlock, !0);
496
496
  }), --window.h.Ea, 0 === window.h.Ea && delete window.h);
497
- }, 565347:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 565451:() => {
497
+ }, 565603:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 565707:() => {
498
498
  try {
499
499
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
500
500
  a.close();
@@ -502,7 +502,7 @@ var Oa, Pa, Ta = {562865:(a, b, c, d, e) => {
502
502
  } catch (c) {
503
503
  return 0;
504
504
  }
505
- }, 565622:(a, b, c, d, e, f) => {
505
+ }, 565878:(a, b, c, d, e, f) => {
506
506
  if ("undefined" === typeof window.h) {
507
507
  return -1;
508
508
  }
@@ -548,7 +548,7 @@ var Oa, Pa, Ta = {562865:(a, b, c, d, e) => {
548
548
  a == window.h.I.Ca && g.Y.connect(g.K.destination);
549
549
  g.nb = f;
550
550
  return window.h.lc(g);
551
- }, 568499:a => window.h.ta(a).K.sampleRate, 568572:a => {
551
+ }, 568755:a => window.h.ta(a).K.sampleRate, 568828:a => {
552
552
  a = window.h.ta(a);
553
553
  void 0 !== a.Y && (a.Y.onaudioprocess = function() {
554
554
  }, a.Y.disconnect(), a.Y = void 0);
@@ -556,13 +556,13 @@ var Oa, Pa, Ta = {562865:(a, b, c, d, e) => {
556
556
  a.K.close();
557
557
  a.K = void 0;
558
558
  a.nb = void 0;
559
- }, 568972:a => {
559
+ }, 569228:a => {
560
560
  window.h.yb(a);
561
- }, 569022:a => {
561
+ }, 569278:a => {
562
562
  a = window.h.ta(a);
563
563
  a.K.resume();
564
564
  a.state = window.h.ia.ub;
565
- }, 569161:a => {
565
+ }, 569417:a => {
566
566
  a = window.h.ta(a);
567
567
  a.K.suspend();
568
568
  a.state = window.h.ia.stopped;
@@ -3546,7 +3546,7 @@ moduleRtn = ca;
3546
3546
  /* 2 */
3547
3547
  /***/ ((module) => {
3548
3548
 
3549
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.35.4","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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3549
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.36.0","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"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3550
3550
 
3551
3551
  /***/ }),
3552
3552
  /* 3 */
@@ -4610,12 +4610,18 @@ var RuntimeLoader = /** @class */ (function () {
4610
4610
  }
4611
4611
  // Loads the runtime
4612
4612
  RuntimeLoader.loadRuntime = function () {
4613
+ if (RuntimeLoader.enablePerfMarks)
4614
+ performance.mark('rive:wasm-init:start');
4613
4615
  _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]({
4614
4616
  // Loads Wasm bundle
4615
4617
  locateFile: function () { return RuntimeLoader.wasmURL; },
4616
4618
  })
4617
4619
  .then(function (rive) {
4618
4620
  var _a;
4621
+ if (RuntimeLoader.enablePerfMarks) {
4622
+ performance.mark('rive:wasm-init:end');
4623
+ performance.measure('rive:wasm-init', 'rive:wasm-init:start', 'rive:wasm-init:end');
4624
+ }
4619
4625
  RuntimeLoader.runtime = rive;
4620
4626
  // Fire all the callbacks
4621
4627
  while (RuntimeLoader.callBackQueue.length > 0) {
@@ -4698,6 +4704,11 @@ var RuntimeLoader = /** @class */ (function () {
4698
4704
  // Path to the Wasm file; default path works for testing only;
4699
4705
  // if embedded wasm is used then this is never used.
4700
4706
  RuntimeLoader.wasmURL = "https://unpkg.com/".concat(package_json__WEBPACK_IMPORTED_MODULE_1__.name, "@").concat(package_json__WEBPACK_IMPORTED_MODULE_1__.version, "/rive.wasm");
4707
+ /**
4708
+ * When true, performance.mark / performance.measure entries are emitted for
4709
+ * WASM initialization.
4710
+ */
4711
+ RuntimeLoader.enablePerfMarks = false;
4701
4712
  return RuntimeLoader;
4702
4713
  }());
4703
4714
 
@@ -5635,6 +5646,8 @@ var RiveFile = /** @class */ (function () {
5635
5646
  function RiveFile(params) {
5636
5647
  // Allow the runtime to automatically load assets hosted in Rive's runtime.
5637
5648
  this.enableRiveAssetCDN = true;
5649
+ // When true, emits performance.mark/measure entries during RiveFile load.
5650
+ this.enablePerfMarks = false;
5638
5651
  this.referenceCount = 0;
5639
5652
  this.destroyed = false;
5640
5653
  this.selfUnref = false;
@@ -5647,6 +5660,9 @@ var RiveFile = /** @class */ (function () {
5647
5660
  typeof params.enableRiveAssetCDN == "boolean"
5648
5661
  ? params.enableRiveAssetCDN
5649
5662
  : true;
5663
+ this.enablePerfMarks = !!params.enablePerfMarks;
5664
+ if (this.enablePerfMarks)
5665
+ RuntimeLoader.enablePerfMarks = true;
5650
5666
  // New event management system
5651
5667
  this.eventManager = new EventManager();
5652
5668
  if (params.onLoad)
@@ -5672,7 +5688,7 @@ var RiveFile = /** @class */ (function () {
5672
5688
  return __generator(this, function (_c) {
5673
5689
  switch (_c.label) {
5674
5690
  case 0:
5675
- if (!this.src) return [3 /*break*/, 2];
5691
+ if (!(this.src && !this.buffer)) return [3 /*break*/, 2];
5676
5692
  _a = this;
5677
5693
  return [4 /*yield*/, loadRiveFile(this.src)];
5678
5694
  case 1:
@@ -5687,11 +5703,16 @@ var RiveFile = /** @class */ (function () {
5687
5703
  loader = loaderWrapper.assetLoader;
5688
5704
  }
5689
5705
  // Load the Rive file
5706
+ if (this.enablePerfMarks)
5707
+ performance.mark('rive:file-load:start');
5690
5708
  _b = this;
5691
5709
  return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
5692
5710
  case 3:
5693
- // Load the Rive file
5694
5711
  _b.file = _c.sent();
5712
+ if (this.enablePerfMarks) {
5713
+ performance.mark('rive:file-load:end');
5714
+ performance.measure('rive:file-load', 'rive:file-load:start', 'rive:file-load:end');
5715
+ }
5695
5716
  fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
5696
5717
  _utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
5697
5718
  if (this.destroyed) {
@@ -5712,9 +5733,45 @@ var RiveFile = /** @class */ (function () {
5712
5733
  });
5713
5734
  });
5714
5735
  };
5736
+ RiveFile.prototype.loadRiveFileBytes = function () {
5737
+ return __awaiter(this, void 0, void 0, function () {
5738
+ var bufferPromise;
5739
+ return __generator(this, function (_a) {
5740
+ if (this.enablePerfMarks)
5741
+ performance.mark('rive:fetch-riv:start');
5742
+ bufferPromise = this.src
5743
+ ? loadRiveFile(this.src)
5744
+ : Promise.resolve(this.buffer);
5745
+ if (this.enablePerfMarks && this.src) {
5746
+ bufferPromise.then(function () {
5747
+ performance.mark('rive:fetch-riv:end');
5748
+ performance.measure('rive:fetch-riv', 'rive:fetch-riv:start', 'rive:fetch-riv:end');
5749
+ });
5750
+ }
5751
+ return [2 /*return*/, bufferPromise];
5752
+ });
5753
+ });
5754
+ };
5755
+ RiveFile.prototype.loadRuntime = function () {
5756
+ return __awaiter(this, void 0, void 0, function () {
5757
+ var runtimePromise;
5758
+ return __generator(this, function (_a) {
5759
+ if (this.enablePerfMarks)
5760
+ performance.mark('rive:await-wasm:start');
5761
+ runtimePromise = RuntimeLoader.awaitInstance();
5762
+ if (this.enablePerfMarks) {
5763
+ runtimePromise.then(function () {
5764
+ performance.mark('rive:await-wasm:end');
5765
+ performance.measure('rive:await-wasm', 'rive:await-wasm:start', 'rive:await-wasm:end');
5766
+ });
5767
+ }
5768
+ return [2 /*return*/, runtimePromise];
5769
+ });
5770
+ });
5771
+ };
5715
5772
  RiveFile.prototype.init = function () {
5716
5773
  return __awaiter(this, void 0, void 0, function () {
5717
- var _a, error_1;
5774
+ var _a, bufferResolved, runtimeResolved, error_1;
5718
5775
  return __generator(this, function (_b) {
5719
5776
  switch (_b.label) {
5720
5777
  case 0:
@@ -5726,16 +5783,24 @@ var RiveFile = /** @class */ (function () {
5726
5783
  _b.label = 1;
5727
5784
  case 1:
5728
5785
  _b.trys.push([1, 4, , 5]);
5729
- _a = this;
5730
- return [4 /*yield*/, RuntimeLoader.awaitInstance()];
5786
+ return [4 /*yield*/, Promise.all([this.loadRiveFileBytes(), this.loadRuntime()])];
5731
5787
  case 2:
5732
- _a.runtime = _b.sent();
5788
+ _a = _b.sent(), bufferResolved = _a[0], runtimeResolved = _a[1];
5733
5789
  if (this.destroyed) {
5734
5790
  return [2 /*return*/];
5735
5791
  }
5792
+ // .riv file buffer and WASM runtime instance
5793
+ this.buffer = bufferResolved;
5794
+ this.runtime = runtimeResolved;
5795
+ if (this.enablePerfMarks)
5796
+ performance.mark('rive:init-data:start');
5736
5797
  return [4 /*yield*/, this.initData()];
5737
5798
  case 3:
5738
5799
  _b.sent();
5800
+ if (this.enablePerfMarks) {
5801
+ performance.mark('rive:init-data:end');
5802
+ performance.measure('rive:init-data', 'rive:init-data:start', 'rive:init-data:end');
5803
+ }
5739
5804
  return [3 /*break*/, 5];
5740
5805
  case 4:
5741
5806
  error_1 = _b.sent();
@@ -5903,6 +5968,8 @@ var Rive = /** @class */ (function () {
5903
5968
  this._viewModelInstance = null;
5904
5969
  this._dataEnums = null;
5905
5970
  this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
5971
+ // When true, emits performance.mark/measure entries for load and render.
5972
+ this.enablePerfMarks = false;
5906
5973
  // Durations to generate a frame for the last second. Used for performance profiling.
5907
5974
  this.durations = [];
5908
5975
  this.frameTimes = [];
@@ -5949,6 +6016,9 @@ var Rive = /** @class */ (function () {
5949
6016
  params.enableRiveAssetCDN === undefined
5950
6017
  ? true
5951
6018
  : params.enableRiveAssetCDN;
6019
+ this.enablePerfMarks = !!params.enablePerfMarks;
6020
+ if (this.enablePerfMarks)
6021
+ RuntimeLoader.enablePerfMarks = true;
5952
6022
  // New event management system
5953
6023
  this.eventManager = new EventManager();
5954
6024
  if (params.onLoad)
@@ -6050,7 +6120,13 @@ var Rive = /** @class */ (function () {
6050
6120
  _this.removeRiveListeners();
6051
6121
  _this.deleteRiveRenderer();
6052
6122
  // Get the canvas where you want to render the animation and create a renderer
6123
+ if (_this.enablePerfMarks)
6124
+ performance.mark('rive:make-renderer:start');
6053
6125
  _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
6126
+ if (_this.enablePerfMarks) {
6127
+ performance.mark('rive:make-renderer:end');
6128
+ performance.measure('rive:make-renderer', 'rive:make-renderer:start', 'rive:make-renderer:end');
6129
+ }
6054
6130
  // Initial size adjustment based on devicePixelRatio if no width/height are
6055
6131
  // specified explicitly
6056
6132
  if (!(_this.canvas.width || _this.canvas.height)) {
@@ -6162,6 +6238,7 @@ var Rive = /** @class */ (function () {
6162
6238
  buffer: this.buffer,
6163
6239
  enableRiveAssetCDN: this.enableRiveAssetCDN,
6164
6240
  assetLoader: this.assetLoader,
6241
+ enablePerfMarks: this.enablePerfMarks,
6165
6242
  });
6166
6243
  this.riveFile = riveFile;
6167
6244
  return [4 /*yield*/, riveFile.init()];
@@ -6328,6 +6405,9 @@ var Rive = /** @class */ (function () {
6328
6405
  // - Advance non-paused state machines by the elapsed number of seconds
6329
6406
  // - Advance to the first frame even when autoplay is false
6330
6407
  var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
6408
+ // Instrument the first 3 frames so the Performance timeline shows precise
6409
+ // per-call latency for advance, draw, and flush without polluting the trace.
6410
+ var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
6331
6411
  for (var _b = 0, activeStateMachines_1 = activeStateMachines; _b < activeStateMachines_1.length; _b++) {
6332
6412
  var stateMachine = activeStateMachines_1[_b];
6333
6413
  // Check for events before the current frame's state machine advance
@@ -6362,7 +6442,13 @@ var Rive = /** @class */ (function () {
6362
6442
  }
6363
6443
  }
6364
6444
  }
6445
+ if (_perfFrame >= 0)
6446
+ performance.mark("rive:sm-advance:start:f".concat(_perfFrame));
6365
6447
  stateMachine.advanceAndApply(elapsedTime);
6448
+ if (_perfFrame >= 0) {
6449
+ performance.mark("rive:sm-advance:end:f".concat(_perfFrame));
6450
+ performance.measure("rive:sm-advance:f".concat(_perfFrame), "rive:sm-advance:start:f".concat(_perfFrame), "rive:sm-advance:end:f".concat(_perfFrame));
6451
+ }
6366
6452
  // stateMachine.instance.apply(this.artboard);
6367
6453
  }
6368
6454
  // Once the animations have been applied to the artboard, advance it
@@ -6382,10 +6468,28 @@ var Rive = /** @class */ (function () {
6382
6468
  renderer.clear();
6383
6469
  renderer.save();
6384
6470
  // Update the renderer alignment if necessary
6471
+ if (_perfFrame >= 0)
6472
+ performance.mark("rive:align-renderer:start:f".concat(_perfFrame));
6385
6473
  this.alignRenderer();
6474
+ if (_perfFrame >= 0) {
6475
+ performance.mark("rive:align-renderer:end:f".concat(_perfFrame));
6476
+ performance.measure("rive:align-renderer:f".concat(_perfFrame), "rive:align-renderer:start:f".concat(_perfFrame), "rive:align-renderer:end:f".concat(_perfFrame));
6477
+ }
6478
+ if (_perfFrame >= 0)
6479
+ performance.mark("rive:artboard-draw:start:f".concat(_perfFrame));
6386
6480
  this.artboard.draw(renderer);
6481
+ if (_perfFrame >= 0) {
6482
+ performance.mark("rive:artboard-draw:end:f".concat(_perfFrame));
6483
+ performance.measure("rive:artboard-draw:f".concat(_perfFrame), "rive:artboard-draw:start:f".concat(_perfFrame), "rive:artboard-draw:end:f".concat(_perfFrame));
6484
+ }
6387
6485
  renderer.restore();
6486
+ if (_perfFrame >= 0)
6487
+ performance.mark("rive:renderer-flush:start:f".concat(_perfFrame));
6388
6488
  renderer.flush();
6489
+ if (_perfFrame >= 0) {
6490
+ performance.mark("rive:renderer-flush:end:f".concat(_perfFrame));
6491
+ performance.measure("rive:renderer-flush:f".concat(_perfFrame), "rive:renderer-flush:start:f".concat(_perfFrame), "rive:renderer-flush:end:f".concat(_perfFrame));
6492
+ }
6389
6493
  this._needsRedraw = false;
6390
6494
  }
6391
6495
  }
@@ -7851,6 +7955,17 @@ var ViewModelInstance = /** @class */ (function () {
7851
7955
  enumerable: false,
7852
7956
  configurable: true
7853
7957
  });
7958
+ Object.defineProperty(ViewModelInstance.prototype, "viewModelName", {
7959
+ /**
7960
+ * Get the name of the ViewModel definition this instance was created from.
7961
+ */
7962
+ get: function () {
7963
+ var _a, _b;
7964
+ return (_b = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.getViewModelName()) !== null && _b !== void 0 ? _b : "";
7965
+ },
7966
+ enumerable: false,
7967
+ configurable: true
7968
+ });
7854
7969
  ViewModelInstance.prototype.internalIncrementReferenceCount = function () {
7855
7970
  this._referenceCount++;
7856
7971
  };