@rive-app/canvas-lite 2.22.0 → 2.23.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-lite",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
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
@@ -357,6 +357,8 @@ export declare class Rive {
357
357
  private automaticallyHandleEvents;
358
358
  private enableRiveAssetCDN;
359
359
  private _volume;
360
+ private _artboardWidth;
361
+ private _artboardHeight;
360
362
  private _devicePixelRatioUsed;
361
363
  private _hasZeroSize;
362
364
  durations: number[];
@@ -384,6 +386,7 @@ export declare class Rive {
384
386
  * we hook the instance to the audio manager
385
387
  */
386
388
  private initializeAudio;
389
+ private initArtboardSize;
387
390
  private initData;
388
391
  private initArtboard;
389
392
  drawFrame(): void;
@@ -479,7 +482,12 @@ export declare class Rive {
479
482
  * Accounts for devicePixelRatio as a multiplier to render the size of the canvas drawing surface.
480
483
  * Uses the size of the backing canvas to set new width/height attributes. Need to re-render
481
484
  * and resize the layout to match the new drawing surface afterwards.
482
- * Useful function for consumers to include in a window resize listener
485
+ * Useful function for consumers to include in a window resize listener.
486
+ *
487
+ * This method will set the {@link devicePixelRatioUsed} property.
488
+ *
489
+ * Optionally, you can provide a {@link customDevicePixelRatio} to provide a
490
+ * custom value.
483
491
  */
484
492
  resizeDrawingSurfaceToCanvas(customDevicePixelRatio?: number): void;
485
493
  get source(): string;
@@ -647,10 +655,46 @@ export declare class Rive {
647
655
  */
648
656
  get contents(): RiveFileContents;
649
657
  /**
650
- * getter and setter for the volume of the artboard
658
+ * Getter / Setter for the volume of the artboard
651
659
  */
652
660
  get volume(): number;
653
661
  set volume(value: number);
662
+ /**
663
+ * The width of the artboard.
664
+ *
665
+ * This will return undefined if the artboard is not loaded yet and a custom
666
+ * width has not been set.
667
+ *
668
+ * Do not set this value manually when using {@link resizeDrawingSurfaceToCanvas}
669
+ * with a {@link Layout.fit} of {@link Fit.Layout}, as the artboard width is
670
+ * automatically set.
671
+ */
672
+ get artboardWidth(): number | undefined;
673
+ set artboardWidth(value: number);
674
+ /**
675
+ * The height of the artboard.
676
+ *
677
+ * This will return undefined if the artboard is not loaded yet and a custom
678
+ * height has not been set.
679
+ *
680
+ * Do not set this value manually when using {@link resizeDrawingSurfaceToCanvas}
681
+ * with a {@link Layout.fit} of {@link Fit.Layout}, as the artboard height is
682
+ * automatically set.
683
+ */
684
+ get artboardHeight(): number | undefined;
685
+ set artboardHeight(value: number);
686
+ /**
687
+ * Reset the artboard size to its original values.
688
+ */
689
+ resetArtboardSize(): void;
690
+ /**
691
+ * The device pixel ratio used in rendering and canvas/artboard resizing.
692
+ *
693
+ * This value will be overidden by the device pixel ratio used in
694
+ * {@link resizeDrawingSurfaceToCanvas}. If you use that method, do not set this value.
695
+ */
696
+ get devicePixelRatioUsed(): number;
697
+ set devicePixelRatioUsed(value: number);
654
698
  }
655
699
  /**
656
700
  * Contents of a state machine input
package/rive.js CHANGED
@@ -2269,7 +2269,7 @@ Qc();
2269
2269
  /* 2 */
2270
2270
  /***/ ((module) => {
2271
2271
 
2272
- module.exports = JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.22.0","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}}');
2272
+ module.exports = JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.23.0","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}}');
2273
2273
 
2274
2274
  /***/ }),
2275
2275
  /* 3 */
@@ -2470,7 +2470,7 @@ var getClientCoordinates = function (event, isTouchScrollEnabled) {
2470
2470
  * the state machine pointer move/up/down functions based on cursor interaction
2471
2471
  */
2472
2472
  var registerTouchInteractions = function (_a) {
2473
- var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _c = _a.isTouchScrollEnabled, isTouchScrollEnabled = _c === void 0 ? false : _c;
2473
+ var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _c = _a.isTouchScrollEnabled, isTouchScrollEnabled = _c === void 0 ? false : _c, _d = _a.layoutScaleFactor, layoutScaleFactor = _d === void 0 ? 1.0 : _d;
2474
2474
  if (!canvas ||
2475
2475
  !stateMachines.length ||
2476
2476
  !renderer ||
@@ -2525,7 +2525,7 @@ var registerTouchInteractions = function (_a) {
2525
2525
  minY: 0,
2526
2526
  maxX: boundingRect.width,
2527
2527
  maxY: boundingRect.height,
2528
- }, artboard.bounds);
2528
+ }, artboard.bounds, layoutScaleFactor);
2529
2529
  var invertedMatrix = new rive.Mat2D();
2530
2530
  forwardMatrix.invert(invertedMatrix);
2531
2531
  var canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
@@ -3998,6 +3998,11 @@ var Rive = /** @class */ (function () {
3998
3998
  this.enableRiveAssetCDN = true;
3999
3999
  // Keep a local value of the set volume to update it asynchronously
4000
4000
  this._volume = 1;
4001
+ // Keep a local value of the set width to update it asynchronously
4002
+ this._artboardWidth = undefined;
4003
+ // Keep a local value of the set height to update it asynchronously
4004
+ this._artboardHeight = undefined;
4005
+ // Keep a local value of the device pixel ratio used in rendering and canvas/artboard resizing
4001
4006
  this._devicePixelRatioUsed = 1;
4002
4007
  // Whether the canvas element's size is 0
4003
4008
  this._hasZeroSize = false;
@@ -4160,6 +4165,7 @@ var Rive = /** @class */ (function () {
4160
4165
  fit: this._layout.runtimeFit(this.runtime),
4161
4166
  alignment: this._layout.runtimeAlignment(this.runtime),
4162
4167
  isTouchScrollEnabled: touchScrollEnabledOption,
4168
+ layoutScaleFactor: this._layout.layoutScaleFactor,
4163
4169
  });
4164
4170
  }
4165
4171
  };
@@ -4189,6 +4195,15 @@ var Rive = /** @class */ (function () {
4189
4195
  }
4190
4196
  }
4191
4197
  };
4198
+ Rive.prototype.initArtboardSize = function () {
4199
+ if (!this.artboard)
4200
+ return;
4201
+ // Use preset values if they are not undefined
4202
+ this._artboardWidth = this.artboard.width =
4203
+ this._artboardWidth || this.artboard.width;
4204
+ this._artboardHeight = this.artboard.height =
4205
+ this._artboardHeight || this.artboard.height;
4206
+ };
4192
4207
  // Initializes runtime with Rive data and preps for playing
4193
4208
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
4194
4209
  var _a;
@@ -4213,6 +4228,8 @@ var Rive = /** @class */ (function () {
4213
4228
  this.file = this.riveFile.getInstance();
4214
4229
  // Initialize and draw frame
4215
4230
  this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
4231
+ // Initialize the artboard size
4232
+ this.initArtboardSize();
4216
4233
  // Check for audio
4217
4234
  this.initializeAudio();
4218
4235
  // Everything's set up, emit a load event
@@ -4672,13 +4689,18 @@ var Rive = /** @class */ (function () {
4672
4689
  * Accounts for devicePixelRatio as a multiplier to render the size of the canvas drawing surface.
4673
4690
  * Uses the size of the backing canvas to set new width/height attributes. Need to re-render
4674
4691
  * and resize the layout to match the new drawing surface afterwards.
4675
- * Useful function for consumers to include in a window resize listener
4692
+ * Useful function for consumers to include in a window resize listener.
4693
+ *
4694
+ * This method will set the {@link devicePixelRatioUsed} property.
4695
+ *
4696
+ * Optionally, you can provide a {@link customDevicePixelRatio} to provide a
4697
+ * custom value.
4676
4698
  */
4677
4699
  Rive.prototype.resizeDrawingSurfaceToCanvas = function (customDevicePixelRatio) {
4678
4700
  if (this.canvas instanceof HTMLCanvasElement && !!window) {
4679
4701
  var _a = this.canvas.getBoundingClientRect(), width = _a.width, height = _a.height;
4680
4702
  var dpr = customDevicePixelRatio || window.devicePixelRatio || 1;
4681
- this._devicePixelRatioUsed = dpr;
4703
+ this.devicePixelRatioUsed = dpr;
4682
4704
  this.canvas.width = dpr * width;
4683
4705
  this.canvas.height = dpr * height;
4684
4706
  this.startRendering();
@@ -5138,7 +5160,7 @@ var Rive = /** @class */ (function () {
5138
5160
  });
5139
5161
  Object.defineProperty(Rive.prototype, "volume", {
5140
5162
  /**
5141
- * getter and setter for the volume of the artboard
5163
+ * Getter / Setter for the volume of the artboard
5142
5164
  */
5143
5165
  get: function () {
5144
5166
  if (this.artboard && this.artboard.volume !== this._volume) {
@@ -5155,6 +5177,89 @@ var Rive = /** @class */ (function () {
5155
5177
  enumerable: false,
5156
5178
  configurable: true
5157
5179
  });
5180
+ Object.defineProperty(Rive.prototype, "artboardWidth", {
5181
+ /**
5182
+ * The width of the artboard.
5183
+ *
5184
+ * This will return undefined if the artboard is not loaded yet and a custom
5185
+ * width has not been set.
5186
+ *
5187
+ * Do not set this value manually when using {@link resizeDrawingSurfaceToCanvas}
5188
+ * with a {@link Layout.fit} of {@link Fit.Layout}, as the artboard width is
5189
+ * automatically set.
5190
+ */
5191
+ get: function () {
5192
+ if (this.artboard) {
5193
+ return this.artboard.width;
5194
+ }
5195
+ return this._artboardWidth;
5196
+ },
5197
+ set: function (value) {
5198
+ this._artboardWidth = value;
5199
+ if (this.artboard) {
5200
+ this.artboard.width = value;
5201
+ }
5202
+ },
5203
+ enumerable: false,
5204
+ configurable: true
5205
+ });
5206
+ Object.defineProperty(Rive.prototype, "artboardHeight", {
5207
+ /**
5208
+ * The height of the artboard.
5209
+ *
5210
+ * This will return undefined if the artboard is not loaded yet and a custom
5211
+ * height has not been set.
5212
+ *
5213
+ * Do not set this value manually when using {@link resizeDrawingSurfaceToCanvas}
5214
+ * with a {@link Layout.fit} of {@link Fit.Layout}, as the artboard height is
5215
+ * automatically set.
5216
+ */
5217
+ get: function () {
5218
+ if (this.artboard) {
5219
+ return this.artboard.height;
5220
+ }
5221
+ return this._artboardHeight;
5222
+ },
5223
+ set: function (value) {
5224
+ this._artboardHeight = value;
5225
+ if (this.artboard) {
5226
+ this.artboard.height = value;
5227
+ }
5228
+ },
5229
+ enumerable: false,
5230
+ configurable: true
5231
+ });
5232
+ /**
5233
+ * Reset the artboard size to its original values.
5234
+ */
5235
+ Rive.prototype.resetArtboardSize = function () {
5236
+ if (this.artboard) {
5237
+ this.artboard.resetArtboardSize();
5238
+ this._artboardWidth = this.artboard.width;
5239
+ this._artboardHeight = this.artboard.height;
5240
+ }
5241
+ else {
5242
+ // If the artboard isn't loaded, we need to reset the custom width and height
5243
+ this._artboardWidth = undefined;
5244
+ this._artboardHeight = undefined;
5245
+ }
5246
+ };
5247
+ Object.defineProperty(Rive.prototype, "devicePixelRatioUsed", {
5248
+ /**
5249
+ * The device pixel ratio used in rendering and canvas/artboard resizing.
5250
+ *
5251
+ * This value will be overidden by the device pixel ratio used in
5252
+ * {@link resizeDrawingSurfaceToCanvas}. If you use that method, do not set this value.
5253
+ */
5254
+ get: function () {
5255
+ return this._devicePixelRatioUsed;
5256
+ },
5257
+ set: function (value) {
5258
+ this._devicePixelRatioUsed = value;
5259
+ },
5260
+ enumerable: false,
5261
+ configurable: true
5262
+ });
5158
5263
  // Error message for missing source or buffer
5159
5264
  Rive.missingErrorMessage = "Rive source file or data buffer required";
5160
5265
  return Rive;