@rive-app/canvas-lite 2.32.2 → 2.33.1

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.32.2",
3
+ "version": "2.33.1",
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
@@ -33,6 +33,10 @@ export declare enum Alignment {
33
33
  BottomCenter = "bottomCenter",
34
34
  BottomRight = "bottomRight"
35
35
  }
36
+ export declare enum DrawOptimizationOptions {
37
+ AlwaysDraw = "alwaysDraw",
38
+ DrawOnChanged = "drawOnChanged"
39
+ }
36
40
  export interface LayoutParameters {
37
41
  fit?: Fit;
38
42
  alignment?: Alignment;
@@ -260,6 +264,10 @@ export interface RiveParameters {
260
264
  * Enables multi touch support
261
265
  */
262
266
  enableMultiTouch?: boolean;
267
+ /**
268
+ * Enum with drawing options for optimizations
269
+ */
270
+ drawingOptions?: DrawOptimizationOptions;
263
271
  onLoad?: EventCallback;
264
272
  onLoadError?: EventCallback;
265
273
  onPlay?: EventCallback;
@@ -421,6 +429,7 @@ export declare class Rive {
421
429
  private _boundDraw;
422
430
  private _viewModelInstance;
423
431
  private _dataEnums;
432
+ private drawOptimization;
424
433
  durations: number[];
425
434
  frameTimes: number[];
426
435
  frameCount: number;
@@ -700,6 +709,7 @@ export declare class Rive {
700
709
  * renderer is already active, then this will have zero effect.
701
710
  */
702
711
  startRendering(): void;
712
+ private scheduleRendering;
703
713
  /**
704
714
  * Enables frames-per-second (FPS) reporting for the runtime
705
715
  * If no callback is provided, Rive will append a fixed-position div at the top-right corner of
package/rive.js CHANGED
@@ -2194,7 +2194,7 @@ moduleRtn = ca;
2194
2194
  /* 2 */
2195
2195
  /***/ ((module) => {
2196
2196
 
2197
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.32.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}}');
2197
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.33.1","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}}');
2198
2198
 
2199
2199
  /***/ }),
2200
2200
  /* 3 */
@@ -3009,6 +3009,7 @@ __webpack_require__.r(__webpack_exports__);
3009
3009
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3010
3010
  /* harmony export */ Alignment: () => (/* binding */ Alignment),
3011
3011
  /* harmony export */ DataEnum: () => (/* binding */ DataEnum),
3012
+ /* harmony export */ DrawOptimizationOptions: () => (/* binding */ DrawOptimizationOptions),
3012
3013
  /* harmony export */ EventType: () => (/* binding */ EventType),
3013
3014
  /* harmony export */ Fit: () => (/* binding */ Fit),
3014
3015
  /* harmony export */ Layout: () => (/* binding */ Layout),
@@ -3156,6 +3157,12 @@ var Alignment;
3156
3157
  Alignment["BottomCenter"] = "bottomCenter";
3157
3158
  Alignment["BottomRight"] = "bottomRight";
3158
3159
  })(Alignment || (Alignment = {}));
3160
+ // Drawing optimization options
3161
+ var DrawOptimizationOptions;
3162
+ (function (DrawOptimizationOptions) {
3163
+ DrawOptimizationOptions["AlwaysDraw"] = "alwaysDraw";
3164
+ DrawOptimizationOptions["DrawOnChanged"] = "drawOnChanged";
3165
+ })(DrawOptimizationOptions || (DrawOptimizationOptions = {}));
3159
3166
  // Alignment options for Rive animations in a HTML canvas
3160
3167
  var Layout = /** @class */ (function () {
3161
3168
  function Layout(params) {
@@ -4478,7 +4485,7 @@ var RiveFile = /** @class */ (function () {
4478
4485
  var Rive = /** @class */ (function () {
4479
4486
  function Rive(params) {
4480
4487
  var _this = this;
4481
- var _a;
4488
+ var _a, _b;
4482
4489
  // Tracks if a Rive file is loaded
4483
4490
  this.loaded = false;
4484
4491
  // Tracks if a Rive file is destroyed
@@ -4520,6 +4527,7 @@ var Rive = /** @class */ (function () {
4520
4527
  this._boundDraw = null;
4521
4528
  this._viewModelInstance = null;
4522
4529
  this._dataEnums = null;
4530
+ this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
4523
4531
  // Durations to generate a frame for the last second. Used for performance profiling.
4524
4532
  this.durations = [];
4525
4533
  this.frameTimes = [];
@@ -4559,6 +4567,7 @@ var Rive = /** @class */ (function () {
4559
4567
  ? params.dispatchPointerExit
4560
4568
  : this.dispatchPointerExit;
4561
4569
  this.enableMultiTouch = !!params.enableMultiTouch;
4570
+ this.drawOptimization = (_b = params.drawingOptions) !== null && _b !== void 0 ? _b : this.drawOptimization;
4562
4571
  this.enableRiveAssetCDN =
4563
4572
  params.enableRiveAssetCDN === undefined
4564
4573
  ? true
@@ -4883,7 +4892,7 @@ var Rive = /** @class */ (function () {
4883
4892
  }
4884
4893
  }
4885
4894
  else {
4886
- this.startRendering();
4895
+ this.scheduleRendering();
4887
4896
  }
4888
4897
  };
4889
4898
  /**
@@ -4970,17 +4979,21 @@ var Rive = /** @class */ (function () {
4970
4979
  this.artboard.advance(elapsedTime);
4971
4980
  }
4972
4981
  var renderer = this.renderer;
4973
- // Canvas must be wiped to prevent artifacts
4974
- renderer.clear();
4975
- renderer.save();
4976
- // Update the renderer alignment if necessary
4977
- this.alignRenderer();
4978
4982
  // Do not draw on 0 canvas size
4979
4983
  if (!this._hasZeroSize) {
4980
- this.artboard.draw(renderer);
4984
+ // If there was no dirt on this frame, do not clear and draw
4985
+ if (this.drawOptimization == DrawOptimizationOptions.AlwaysDraw ||
4986
+ this.artboard.didChange()) {
4987
+ // Canvas must be wiped to prevent artifacts
4988
+ renderer.clear();
4989
+ renderer.save();
4990
+ // Update the renderer alignment if necessary
4991
+ this.alignRenderer();
4992
+ this.artboard.draw(renderer);
4993
+ renderer.restore();
4994
+ renderer.flush();
4995
+ }
4981
4996
  }
4982
- renderer.restore();
4983
- renderer.flush();
4984
4997
  // Check for any animations that looped
4985
4998
  this.animator.handleLooping();
4986
4999
  // Check for any state machines that had a state change
@@ -5001,7 +5014,7 @@ var Rive = /** @class */ (function () {
5001
5014
  // https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
5002
5015
  if (this.animator.isPlaying) {
5003
5016
  // Request a new rendering frame
5004
- this.startRendering();
5017
+ this.scheduleRendering();
5005
5018
  }
5006
5019
  else if (this.animator.isPaused) {
5007
5020
  // Reset the end time so on playback it starts at the correct frame
@@ -5691,6 +5704,9 @@ var Rive = /** @class */ (function () {
5691
5704
  * renderer is already active, then this will have zero effect.
5692
5705
  */
5693
5706
  Rive.prototype.startRendering = function () {
5707
+ this.drawFrame();
5708
+ };
5709
+ Rive.prototype.scheduleRendering = function () {
5694
5710
  if (this.loaded && this.artboard && !this.frameRequestId) {
5695
5711
  if (this.runtime.requestAnimationFrame) {
5696
5712
  this.frameRequestId = this.runtime.requestAnimationFrame(this._boundDraw);