@rive-app/webgl-single 1.0.14 → 1.0.15

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-single",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Rive's webgl based web api with bundled wasm.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -255,6 +255,9 @@ export declare class Rive {
255
255
  private taskQueue;
256
256
  private animator;
257
257
  private static readonly missingErrorMessage;
258
+ durations: number[];
259
+ frameTimes: number[];
260
+ frameCount: number;
258
261
  constructor(params: RiveParameters);
259
262
  static new(params: RiveParameters): Rive;
260
263
  private init;
@@ -276,6 +279,8 @@ export declare class Rive {
276
279
  * Align the renderer
277
280
  */
278
281
  private alignRenderer;
282
+ get fps(): number;
283
+ get frameTime(): string | 0;
279
284
  /**
280
285
  * Cleans up any Wasm-generated objects that need to be manually destroyed:
281
286
  * artboard instances, animation instances, state machine instances.
package/rive.js CHANGED
@@ -168,7 +168,7 @@ k.run=sd;if(k.preInit)for("function"==typeof k.preInit&&(k.preInit=[k.preInit]);
168
168
  /* 2 */
169
169
  /***/ ((module) => {
170
170
 
171
- module.exports = JSON.parse('{"name":"@rive-app/webgl-single","version":"1.0.14","description":"Rive\'s webgl based web api with bundled wasm.","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.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
171
+ module.exports = JSON.parse('{"name":"@rive-app/webgl-single","version":"1.0.15","description":"Rive\'s webgl based web api with bundled wasm.","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.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
172
172
 
173
173
  /***/ })
174
174
  /******/ ]);
@@ -1062,6 +1062,10 @@ var Rive = /** @class */ (function () {
1062
1062
  this.readyForPlaying = false;
1063
1063
  // Runtime artboard
1064
1064
  this.artboard = null;
1065
+ // Durations to generate a frame for the last second. Used for performance profiling.
1066
+ this.durations = [];
1067
+ this.frameTimes = [];
1068
+ this.frameCount = 0;
1065
1069
  /**
1066
1070
  * Used be draw to track when a second of active rendering time has passed. Used for debugging purposes
1067
1071
  */
@@ -1250,6 +1254,7 @@ var Rive = /** @class */ (function () {
1250
1254
  * @param time the time at which to render a frame
1251
1255
  */
1252
1256
  Rive.prototype.draw = function (time, onSecond) {
1257
+ var before = performance.now();
1253
1258
  // Clear the frameRequestId, as we're now rendering a fresh frame
1254
1259
  this.frameRequestId = null;
1255
1260
  // On the first pass, make sure lastTime has a valid value
@@ -1300,6 +1305,15 @@ var Rive = /** @class */ (function () {
1300
1305
  this.animator.handleLooping();
1301
1306
  // Check for any state machines that had a state change
1302
1307
  this.animator.handleStateChanges();
1308
+ // Add duration to create frame to durations array
1309
+ this.frameCount++;
1310
+ var after = performance.now();
1311
+ this.frameTimes.push(after);
1312
+ this.durations.push(after - before);
1313
+ while (this.frameTimes[0] <= after - 1000) {
1314
+ this.frameTimes.shift();
1315
+ this.durations.shift();
1316
+ }
1303
1317
  // Calling requestAnimationFrame will rerun draw() at the correct rate:
1304
1318
  // https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
1305
1319
  if (this.animator.isPlaying) {
@@ -1325,8 +1339,6 @@ var Rive = /** @class */ (function () {
1325
1339
  var _a = this, renderer = _a.renderer, runtime = _a.runtime, _layout = _a._layout, artboard = _a.artboard;
1326
1340
  // Canvas must be wiped to prevent artifacts
1327
1341
  renderer.clear();
1328
- // Now save so that future changes to align can restore
1329
- renderer.save();
1330
1342
  // Align things up safe in the knowledge we can restore if changed
1331
1343
  renderer.align(_layout.runtimeFit(runtime), _layout.runtimeAlignment(runtime), {
1332
1344
  minX: _layout.minX,
@@ -1335,6 +1347,23 @@ var Rive = /** @class */ (function () {
1335
1347
  maxY: _layout.maxY
1336
1348
  }, artboard.bounds);
1337
1349
  };
1350
+ Object.defineProperty(Rive.prototype, "fps", {
1351
+ get: function () {
1352
+ return this.durations.length;
1353
+ },
1354
+ enumerable: false,
1355
+ configurable: true
1356
+ });
1357
+ Object.defineProperty(Rive.prototype, "frameTime", {
1358
+ get: function () {
1359
+ if (this.durations.length === 0) {
1360
+ return 0;
1361
+ }
1362
+ return (this.durations.reduce(function (a, b) { return a + b; }, 0) / this.durations.length).toFixed(4);
1363
+ },
1364
+ enumerable: false,
1365
+ configurable: true
1366
+ });
1338
1367
  /**
1339
1368
  * Cleans up any Wasm-generated objects that need to be manually destroyed:
1340
1369
  * artboard instances, animation instances, state machine instances.