@rive-app/canvas 2.32.1 → 2.33.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.32.1",
3
+ "version": "2.33.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
@@ -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
@@ -732,7 +732,7 @@ function Wa(a, b) {
732
732
  return Va(c, a, b);
733
733
  }));
734
734
  }
735
- var Xa, Ya, bb = {464448:(a, b, c, d, e) => {
735
+ var Xa, Ya, bb = {467490:(a, b, c, d, e) => {
736
736
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
737
737
  return 0;
738
738
  }
@@ -795,11 +795,11 @@ var Xa, Ya, bb = {464448:(a, b, c, d, e) => {
795
795
  }
796
796
  window.h.ya += 1;
797
797
  return 1;
798
- }, 466626:() => {
798
+ }, 469668:() => {
799
799
  "undefined" !== typeof window.h && (window.h.Ra.map(function(a) {
800
800
  document.removeEventListener(a, window.h.unlock, !0);
801
801
  }), --window.h.ya, 0 === window.h.ya && delete window.h);
802
- }, 466930:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 467034:() => {
802
+ }, 469972:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 470076:() => {
803
803
  try {
804
804
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
805
805
  a.close();
@@ -807,7 +807,7 @@ var Xa, Ya, bb = {464448:(a, b, c, d, e) => {
807
807
  } catch (c) {
808
808
  return 0;
809
809
  }
810
- }, 467205:(a, b, c, d, e, f) => {
810
+ }, 470247:(a, b, c, d, e, f) => {
811
811
  if ("undefined" === typeof window.h) {
812
812
  return -1;
813
813
  }
@@ -853,7 +853,7 @@ var Xa, Ya, bb = {464448:(a, b, c, d, e) => {
853
853
  a == window.h.I.wa && g.Y.connect(g.K.destination);
854
854
  g.ob = f;
855
855
  return window.h.rc(g);
856
- }, 470082:a => window.h.pa(a).K.sampleRate, 470155:a => {
856
+ }, 473124:a => window.h.pa(a).K.sampleRate, 473197:a => {
857
857
  a = window.h.pa(a);
858
858
  void 0 !== a.Y && (a.Y.onaudioprocess = function() {
859
859
  }, a.Y.disconnect(), a.Y = void 0);
@@ -861,13 +861,13 @@ var Xa, Ya, bb = {464448:(a, b, c, d, e) => {
861
861
  a.K.close();
862
862
  a.K = void 0;
863
863
  a.ob = void 0;
864
- }, 470555:a => {
864
+ }, 473597:a => {
865
865
  window.h.zb(a);
866
- }, 470605:a => {
866
+ }, 473647:a => {
867
867
  a = window.h.pa(a);
868
868
  a.K.resume();
869
869
  a.state = window.h.fa.vb;
870
- }, 470744:a => {
870
+ }, 473786:a => {
871
871
  a = window.h.pa(a);
872
872
  a.K.suspend();
873
873
  a.state = window.h.fa.stopped;
@@ -3225,6 +3225,8 @@ var Yd = {__syscall_fcntl64:function(a, b, c) {
3225
3225
  }
3226
3226
  return w.$;
3227
3227
  }
3228
+ }, isWindowsBrowser:function() {
3229
+ return -1 < navigator.platform.indexOf("Win");
3228
3230
  }, strftime_l:(a, b, c, d) => Ud(a, b, c, d)}, X = function() {
3229
3231
  function a(c) {
3230
3232
  X = c.exports;
@@ -3325,7 +3327,7 @@ moduleRtn = da;
3325
3327
  /* 2 */
3326
3328
  /***/ ((module) => {
3327
3329
 
3328
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.32.1","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}}');
3330
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.33.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}}');
3329
3331
 
3330
3332
  /***/ }),
3331
3333
  /* 3 */
@@ -4140,6 +4142,7 @@ __webpack_require__.r(__webpack_exports__);
4140
4142
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4141
4143
  /* harmony export */ Alignment: () => (/* binding */ Alignment),
4142
4144
  /* harmony export */ DataEnum: () => (/* binding */ DataEnum),
4145
+ /* harmony export */ DrawOptimizationOptions: () => (/* binding */ DrawOptimizationOptions),
4143
4146
  /* harmony export */ EventType: () => (/* binding */ EventType),
4144
4147
  /* harmony export */ Fit: () => (/* binding */ Fit),
4145
4148
  /* harmony export */ Layout: () => (/* binding */ Layout),
@@ -4287,6 +4290,12 @@ var Alignment;
4287
4290
  Alignment["BottomCenter"] = "bottomCenter";
4288
4291
  Alignment["BottomRight"] = "bottomRight";
4289
4292
  })(Alignment || (Alignment = {}));
4293
+ // Drawing optimization options
4294
+ var DrawOptimizationOptions;
4295
+ (function (DrawOptimizationOptions) {
4296
+ DrawOptimizationOptions["AlwaysDraw"] = "alwaysDraw";
4297
+ DrawOptimizationOptions["DrawOnChanged"] = "drawOnChanged";
4298
+ })(DrawOptimizationOptions || (DrawOptimizationOptions = {}));
4290
4299
  // Alignment options for Rive animations in a HTML canvas
4291
4300
  var Layout = /** @class */ (function () {
4292
4301
  function Layout(params) {
@@ -5609,7 +5618,7 @@ var RiveFile = /** @class */ (function () {
5609
5618
  var Rive = /** @class */ (function () {
5610
5619
  function Rive(params) {
5611
5620
  var _this = this;
5612
- var _a;
5621
+ var _a, _b;
5613
5622
  // Tracks if a Rive file is loaded
5614
5623
  this.loaded = false;
5615
5624
  // Tracks if a Rive file is destroyed
@@ -5651,6 +5660,7 @@ var Rive = /** @class */ (function () {
5651
5660
  this._boundDraw = null;
5652
5661
  this._viewModelInstance = null;
5653
5662
  this._dataEnums = null;
5663
+ this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
5654
5664
  // Durations to generate a frame for the last second. Used for performance profiling.
5655
5665
  this.durations = [];
5656
5666
  this.frameTimes = [];
@@ -5690,6 +5700,7 @@ var Rive = /** @class */ (function () {
5690
5700
  ? params.dispatchPointerExit
5691
5701
  : this.dispatchPointerExit;
5692
5702
  this.enableMultiTouch = !!params.enableMultiTouch;
5703
+ this.drawOptimization = (_b = params.drawingOptions) !== null && _b !== void 0 ? _b : this.drawOptimization;
5693
5704
  this.enableRiveAssetCDN =
5694
5705
  params.enableRiveAssetCDN === undefined
5695
5706
  ? true
@@ -6014,7 +6025,7 @@ var Rive = /** @class */ (function () {
6014
6025
  }
6015
6026
  }
6016
6027
  else {
6017
- this.startRendering();
6028
+ this.scheduleRendering();
6018
6029
  }
6019
6030
  };
6020
6031
  /**
@@ -6101,17 +6112,21 @@ var Rive = /** @class */ (function () {
6101
6112
  this.artboard.advance(elapsedTime);
6102
6113
  }
6103
6114
  var renderer = this.renderer;
6104
- // Canvas must be wiped to prevent artifacts
6105
- renderer.clear();
6106
- renderer.save();
6107
- // Update the renderer alignment if necessary
6108
- this.alignRenderer();
6109
6115
  // Do not draw on 0 canvas size
6110
6116
  if (!this._hasZeroSize) {
6111
- this.artboard.draw(renderer);
6117
+ // If there was no dirt on this frame, do not clear and draw
6118
+ if (this.drawOptimization == DrawOptimizationOptions.AlwaysDraw ||
6119
+ this.artboard.didChange()) {
6120
+ // Canvas must be wiped to prevent artifacts
6121
+ renderer.clear();
6122
+ renderer.save();
6123
+ // Update the renderer alignment if necessary
6124
+ this.alignRenderer();
6125
+ this.artboard.draw(renderer);
6126
+ renderer.restore();
6127
+ renderer.flush();
6128
+ }
6112
6129
  }
6113
- renderer.restore();
6114
- renderer.flush();
6115
6130
  // Check for any animations that looped
6116
6131
  this.animator.handleLooping();
6117
6132
  // Check for any state machines that had a state change
@@ -6132,7 +6147,7 @@ var Rive = /** @class */ (function () {
6132
6147
  // https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
6133
6148
  if (this.animator.isPlaying) {
6134
6149
  // Request a new rendering frame
6135
- this.startRendering();
6150
+ this.scheduleRendering();
6136
6151
  }
6137
6152
  else if (this.animator.isPaused) {
6138
6153
  // Reset the end time so on playback it starts at the correct frame
@@ -6822,6 +6837,9 @@ var Rive = /** @class */ (function () {
6822
6837
  * renderer is already active, then this will have zero effect.
6823
6838
  */
6824
6839
  Rive.prototype.startRendering = function () {
6840
+ this.drawFrame();
6841
+ };
6842
+ Rive.prototype.scheduleRendering = function () {
6825
6843
  if (this.loaded && this.artboard && !this.frameRequestId) {
6826
6844
  if (this.runtime.requestAnimationFrame) {
6827
6845
  this.frameRequestId = this.runtime.requestAnimationFrame(this._boundDraw);