@rive-app/webgl 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/webgl",
3
- "version": "2.35.4",
3
+ "version": "2.36.0",
4
4
  "description": "Rive's webgl 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
@@ -393,7 +393,7 @@ function Ra(a, b) {
393
393
  return Qa(c, a, b);
394
394
  }));
395
395
  }
396
- var Sa, Ta, Xa = {728114:(a, b, c, d, e) => {
396
+ var Sa, Ta, Xa = {728434:(a, b, c, d, e) => {
397
397
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
398
398
  return 0;
399
399
  }
@@ -456,11 +456,11 @@ var Sa, Ta, Xa = {728114:(a, b, c, d, e) => {
456
456
  }
457
457
  window.h.Ca += 1;
458
458
  return 1;
459
- }, 730292:() => {
459
+ }, 730612:() => {
460
460
  "undefined" !== typeof window.h && (window.h.Ra.map(function(a) {
461
461
  document.removeEventListener(a, window.h.unlock, !0);
462
462
  }), --window.h.Ca, 0 === window.h.Ca && delete window.h);
463
- }, 730596:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 730700:() => {
463
+ }, 730916:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 731020:() => {
464
464
  try {
465
465
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
466
466
  a.close();
@@ -468,7 +468,7 @@ var Sa, Ta, Xa = {728114:(a, b, c, d, e) => {
468
468
  } catch (c) {
469
469
  return 0;
470
470
  }
471
- }, 730871:(a, b, c, d, e, f) => {
471
+ }, 731191:(a, b, c, d, e, f) => {
472
472
  if ("undefined" === typeof window.h) {
473
473
  return -1;
474
474
  }
@@ -514,7 +514,7 @@ var Sa, Ta, Xa = {728114:(a, b, c, d, e) => {
514
514
  a == window.h.H.Aa && g.W.connect(g.J.destination);
515
515
  g.kb = f;
516
516
  return window.h.fc(g);
517
- }, 733748:a => window.h.ra(a).J.sampleRate, 733821:a => {
517
+ }, 734068:a => window.h.ra(a).J.sampleRate, 734141:a => {
518
518
  a = window.h.ra(a);
519
519
  void 0 !== a.W && (a.W.onaudioprocess = function() {
520
520
  }, a.W.disconnect(), a.W = void 0);
@@ -522,13 +522,13 @@ var Sa, Ta, Xa = {728114:(a, b, c, d, e) => {
522
522
  a.J.close();
523
523
  a.J = void 0;
524
524
  a.kb = void 0;
525
- }, 734221:a => {
525
+ }, 734541:a => {
526
526
  window.h.ub(a);
527
- }, 734271:a => {
527
+ }, 734591:a => {
528
528
  a = window.h.ra(a);
529
529
  a.J.resume();
530
530
  a.state = window.h.ga.qb;
531
- }, 734410:a => {
531
+ }, 734730:a => {
532
532
  a = window.h.ra(a);
533
533
  a.J.suspend();
534
534
  a.state = window.h.ga.stopped;
@@ -3935,7 +3935,7 @@ moduleRtn = ca;
3935
3935
  /* 2 */
3936
3936
  /***/ ((module) => {
3937
3937
 
3938
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.35.4","description":"Rive\'s webgl 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.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3938
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.36.0","description":"Rive\'s webgl 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.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3939
3939
 
3940
3940
  /***/ }),
3941
3941
  /* 3 */
@@ -4999,12 +4999,18 @@ var RuntimeLoader = /** @class */ (function () {
4999
4999
  }
5000
5000
  // Loads the runtime
5001
5001
  RuntimeLoader.loadRuntime = function () {
5002
+ if (RuntimeLoader.enablePerfMarks)
5003
+ performance.mark('rive:wasm-init:start');
5002
5004
  _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]({
5003
5005
  // Loads Wasm bundle
5004
5006
  locateFile: function () { return RuntimeLoader.wasmURL; },
5005
5007
  })
5006
5008
  .then(function (rive) {
5007
5009
  var _a;
5010
+ if (RuntimeLoader.enablePerfMarks) {
5011
+ performance.mark('rive:wasm-init:end');
5012
+ performance.measure('rive:wasm-init', 'rive:wasm-init:start', 'rive:wasm-init:end');
5013
+ }
5008
5014
  RuntimeLoader.runtime = rive;
5009
5015
  // Fire all the callbacks
5010
5016
  while (RuntimeLoader.callBackQueue.length > 0) {
@@ -5087,6 +5093,11 @@ var RuntimeLoader = /** @class */ (function () {
5087
5093
  // Path to the Wasm file; default path works for testing only;
5088
5094
  // if embedded wasm is used then this is never used.
5089
5095
  RuntimeLoader.wasmURL = "https://unpkg.com/".concat(package_json__WEBPACK_IMPORTED_MODULE_1__.name, "@").concat(package_json__WEBPACK_IMPORTED_MODULE_1__.version, "/rive.wasm");
5096
+ /**
5097
+ * When true, performance.mark / performance.measure entries are emitted for
5098
+ * WASM initialization.
5099
+ */
5100
+ RuntimeLoader.enablePerfMarks = false;
5090
5101
  return RuntimeLoader;
5091
5102
  }());
5092
5103
 
@@ -6024,6 +6035,8 @@ var RiveFile = /** @class */ (function () {
6024
6035
  function RiveFile(params) {
6025
6036
  // Allow the runtime to automatically load assets hosted in Rive's runtime.
6026
6037
  this.enableRiveAssetCDN = true;
6038
+ // When true, emits performance.mark/measure entries during RiveFile load.
6039
+ this.enablePerfMarks = false;
6027
6040
  this.referenceCount = 0;
6028
6041
  this.destroyed = false;
6029
6042
  this.selfUnref = false;
@@ -6036,6 +6049,9 @@ var RiveFile = /** @class */ (function () {
6036
6049
  typeof params.enableRiveAssetCDN == "boolean"
6037
6050
  ? params.enableRiveAssetCDN
6038
6051
  : true;
6052
+ this.enablePerfMarks = !!params.enablePerfMarks;
6053
+ if (this.enablePerfMarks)
6054
+ RuntimeLoader.enablePerfMarks = true;
6039
6055
  // New event management system
6040
6056
  this.eventManager = new EventManager();
6041
6057
  if (params.onLoad)
@@ -6061,7 +6077,7 @@ var RiveFile = /** @class */ (function () {
6061
6077
  return __generator(this, function (_c) {
6062
6078
  switch (_c.label) {
6063
6079
  case 0:
6064
- if (!this.src) return [3 /*break*/, 2];
6080
+ if (!(this.src && !this.buffer)) return [3 /*break*/, 2];
6065
6081
  _a = this;
6066
6082
  return [4 /*yield*/, loadRiveFile(this.src)];
6067
6083
  case 1:
@@ -6076,11 +6092,16 @@ var RiveFile = /** @class */ (function () {
6076
6092
  loader = loaderWrapper.assetLoader;
6077
6093
  }
6078
6094
  // Load the Rive file
6095
+ if (this.enablePerfMarks)
6096
+ performance.mark('rive:file-load:start');
6079
6097
  _b = this;
6080
6098
  return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
6081
6099
  case 3:
6082
- // Load the Rive file
6083
6100
  _b.file = _c.sent();
6101
+ if (this.enablePerfMarks) {
6102
+ performance.mark('rive:file-load:end');
6103
+ performance.measure('rive:file-load', 'rive:file-load:start', 'rive:file-load:end');
6104
+ }
6084
6105
  fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
6085
6106
  _utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
6086
6107
  if (this.destroyed) {
@@ -6101,9 +6122,45 @@ var RiveFile = /** @class */ (function () {
6101
6122
  });
6102
6123
  });
6103
6124
  };
6125
+ RiveFile.prototype.loadRiveFileBytes = function () {
6126
+ return __awaiter(this, void 0, void 0, function () {
6127
+ var bufferPromise;
6128
+ return __generator(this, function (_a) {
6129
+ if (this.enablePerfMarks)
6130
+ performance.mark('rive:fetch-riv:start');
6131
+ bufferPromise = this.src
6132
+ ? loadRiveFile(this.src)
6133
+ : Promise.resolve(this.buffer);
6134
+ if (this.enablePerfMarks && this.src) {
6135
+ bufferPromise.then(function () {
6136
+ performance.mark('rive:fetch-riv:end');
6137
+ performance.measure('rive:fetch-riv', 'rive:fetch-riv:start', 'rive:fetch-riv:end');
6138
+ });
6139
+ }
6140
+ return [2 /*return*/, bufferPromise];
6141
+ });
6142
+ });
6143
+ };
6144
+ RiveFile.prototype.loadRuntime = function () {
6145
+ return __awaiter(this, void 0, void 0, function () {
6146
+ var runtimePromise;
6147
+ return __generator(this, function (_a) {
6148
+ if (this.enablePerfMarks)
6149
+ performance.mark('rive:await-wasm:start');
6150
+ runtimePromise = RuntimeLoader.awaitInstance();
6151
+ if (this.enablePerfMarks) {
6152
+ runtimePromise.then(function () {
6153
+ performance.mark('rive:await-wasm:end');
6154
+ performance.measure('rive:await-wasm', 'rive:await-wasm:start', 'rive:await-wasm:end');
6155
+ });
6156
+ }
6157
+ return [2 /*return*/, runtimePromise];
6158
+ });
6159
+ });
6160
+ };
6104
6161
  RiveFile.prototype.init = function () {
6105
6162
  return __awaiter(this, void 0, void 0, function () {
6106
- var _a, error_1;
6163
+ var _a, bufferResolved, runtimeResolved, error_1;
6107
6164
  return __generator(this, function (_b) {
6108
6165
  switch (_b.label) {
6109
6166
  case 0:
@@ -6115,16 +6172,24 @@ var RiveFile = /** @class */ (function () {
6115
6172
  _b.label = 1;
6116
6173
  case 1:
6117
6174
  _b.trys.push([1, 4, , 5]);
6118
- _a = this;
6119
- return [4 /*yield*/, RuntimeLoader.awaitInstance()];
6175
+ return [4 /*yield*/, Promise.all([this.loadRiveFileBytes(), this.loadRuntime()])];
6120
6176
  case 2:
6121
- _a.runtime = _b.sent();
6177
+ _a = _b.sent(), bufferResolved = _a[0], runtimeResolved = _a[1];
6122
6178
  if (this.destroyed) {
6123
6179
  return [2 /*return*/];
6124
6180
  }
6181
+ // .riv file buffer and WASM runtime instance
6182
+ this.buffer = bufferResolved;
6183
+ this.runtime = runtimeResolved;
6184
+ if (this.enablePerfMarks)
6185
+ performance.mark('rive:init-data:start');
6125
6186
  return [4 /*yield*/, this.initData()];
6126
6187
  case 3:
6127
6188
  _b.sent();
6189
+ if (this.enablePerfMarks) {
6190
+ performance.mark('rive:init-data:end');
6191
+ performance.measure('rive:init-data', 'rive:init-data:start', 'rive:init-data:end');
6192
+ }
6128
6193
  return [3 /*break*/, 5];
6129
6194
  case 4:
6130
6195
  error_1 = _b.sent();
@@ -6292,6 +6357,8 @@ var Rive = /** @class */ (function () {
6292
6357
  this._viewModelInstance = null;
6293
6358
  this._dataEnums = null;
6294
6359
  this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
6360
+ // When true, emits performance.mark/measure entries for load and render.
6361
+ this.enablePerfMarks = false;
6295
6362
  // Durations to generate a frame for the last second. Used for performance profiling.
6296
6363
  this.durations = [];
6297
6364
  this.frameTimes = [];
@@ -6338,6 +6405,9 @@ var Rive = /** @class */ (function () {
6338
6405
  params.enableRiveAssetCDN === undefined
6339
6406
  ? true
6340
6407
  : params.enableRiveAssetCDN;
6408
+ this.enablePerfMarks = !!params.enablePerfMarks;
6409
+ if (this.enablePerfMarks)
6410
+ RuntimeLoader.enablePerfMarks = true;
6341
6411
  // New event management system
6342
6412
  this.eventManager = new EventManager();
6343
6413
  if (params.onLoad)
@@ -6439,7 +6509,13 @@ var Rive = /** @class */ (function () {
6439
6509
  _this.removeRiveListeners();
6440
6510
  _this.deleteRiveRenderer();
6441
6511
  // Get the canvas where you want to render the animation and create a renderer
6512
+ if (_this.enablePerfMarks)
6513
+ performance.mark('rive:make-renderer:start');
6442
6514
  _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
6515
+ if (_this.enablePerfMarks) {
6516
+ performance.mark('rive:make-renderer:end');
6517
+ performance.measure('rive:make-renderer', 'rive:make-renderer:start', 'rive:make-renderer:end');
6518
+ }
6443
6519
  // Initial size adjustment based on devicePixelRatio if no width/height are
6444
6520
  // specified explicitly
6445
6521
  if (!(_this.canvas.width || _this.canvas.height)) {
@@ -6551,6 +6627,7 @@ var Rive = /** @class */ (function () {
6551
6627
  buffer: this.buffer,
6552
6628
  enableRiveAssetCDN: this.enableRiveAssetCDN,
6553
6629
  assetLoader: this.assetLoader,
6630
+ enablePerfMarks: this.enablePerfMarks,
6554
6631
  });
6555
6632
  this.riveFile = riveFile;
6556
6633
  return [4 /*yield*/, riveFile.init()];
@@ -6717,6 +6794,9 @@ var Rive = /** @class */ (function () {
6717
6794
  // - Advance non-paused state machines by the elapsed number of seconds
6718
6795
  // - Advance to the first frame even when autoplay is false
6719
6796
  var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
6797
+ // Instrument the first 3 frames so the Performance timeline shows precise
6798
+ // per-call latency for advance, draw, and flush without polluting the trace.
6799
+ var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
6720
6800
  for (var _b = 0, activeStateMachines_1 = activeStateMachines; _b < activeStateMachines_1.length; _b++) {
6721
6801
  var stateMachine = activeStateMachines_1[_b];
6722
6802
  // Check for events before the current frame's state machine advance
@@ -6751,7 +6831,13 @@ var Rive = /** @class */ (function () {
6751
6831
  }
6752
6832
  }
6753
6833
  }
6834
+ if (_perfFrame >= 0)
6835
+ performance.mark("rive:sm-advance:start:f".concat(_perfFrame));
6754
6836
  stateMachine.advanceAndApply(elapsedTime);
6837
+ if (_perfFrame >= 0) {
6838
+ performance.mark("rive:sm-advance:end:f".concat(_perfFrame));
6839
+ performance.measure("rive:sm-advance:f".concat(_perfFrame), "rive:sm-advance:start:f".concat(_perfFrame), "rive:sm-advance:end:f".concat(_perfFrame));
6840
+ }
6755
6841
  // stateMachine.instance.apply(this.artboard);
6756
6842
  }
6757
6843
  // Once the animations have been applied to the artboard, advance it
@@ -6771,10 +6857,28 @@ var Rive = /** @class */ (function () {
6771
6857
  renderer.clear();
6772
6858
  renderer.save();
6773
6859
  // Update the renderer alignment if necessary
6860
+ if (_perfFrame >= 0)
6861
+ performance.mark("rive:align-renderer:start:f".concat(_perfFrame));
6774
6862
  this.alignRenderer();
6863
+ if (_perfFrame >= 0) {
6864
+ performance.mark("rive:align-renderer:end:f".concat(_perfFrame));
6865
+ performance.measure("rive:align-renderer:f".concat(_perfFrame), "rive:align-renderer:start:f".concat(_perfFrame), "rive:align-renderer:end:f".concat(_perfFrame));
6866
+ }
6867
+ if (_perfFrame >= 0)
6868
+ performance.mark("rive:artboard-draw:start:f".concat(_perfFrame));
6775
6869
  this.artboard.draw(renderer);
6870
+ if (_perfFrame >= 0) {
6871
+ performance.mark("rive:artboard-draw:end:f".concat(_perfFrame));
6872
+ performance.measure("rive:artboard-draw:f".concat(_perfFrame), "rive:artboard-draw:start:f".concat(_perfFrame), "rive:artboard-draw:end:f".concat(_perfFrame));
6873
+ }
6776
6874
  renderer.restore();
6875
+ if (_perfFrame >= 0)
6876
+ performance.mark("rive:renderer-flush:start:f".concat(_perfFrame));
6777
6877
  renderer.flush();
6878
+ if (_perfFrame >= 0) {
6879
+ performance.mark("rive:renderer-flush:end:f".concat(_perfFrame));
6880
+ performance.measure("rive:renderer-flush:f".concat(_perfFrame), "rive:renderer-flush:start:f".concat(_perfFrame), "rive:renderer-flush:end:f".concat(_perfFrame));
6881
+ }
6778
6882
  this._needsRedraw = false;
6779
6883
  }
6780
6884
  }
@@ -8240,6 +8344,17 @@ var ViewModelInstance = /** @class */ (function () {
8240
8344
  enumerable: false,
8241
8345
  configurable: true
8242
8346
  });
8347
+ Object.defineProperty(ViewModelInstance.prototype, "viewModelName", {
8348
+ /**
8349
+ * Get the name of the ViewModel definition this instance was created from.
8350
+ */
8351
+ get: function () {
8352
+ var _a, _b;
8353
+ return (_b = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.getViewModelName()) !== null && _b !== void 0 ? _b : "";
8354
+ },
8355
+ enumerable: false,
8356
+ configurable: true
8357
+ });
8243
8358
  ViewModelInstance.prototype.internalIncrementReferenceCount = function () {
8244
8359
  this._referenceCount++;
8245
8360
  };