@rive-app/canvas-single 1.0.18 → 1.0.19

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-single",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Rive's high-level canvas based web api all in one js file.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -315,6 +315,13 @@ export declare class Rive {
315
315
  * when the canvas is resized
316
316
  */
317
317
  resizeToCanvas(): void;
318
+ /**
319
+ * Accounts for devicePixelRatio as a multiplier to render the size of the canvas drawing surface.
320
+ * Uses the size of the backing canvas to set new width/height attributes. Need to re-render
321
+ * and resize the layout to match the new drawing surface afterwards. Useful function for consumers
322
+ * to include in a window resize listener
323
+ */
324
+ resizeDrawingSurfaceToCanvas(): void;
318
325
  get source(): string;
319
326
  /**
320
327
  * Returns the name of the active artboard
package/rive.js CHANGED
@@ -124,7 +124,7 @@ if(h.preInit)for("function"==typeof h.preInit&&(h.preInit=[h.preInit]);0<h.preIn
124
124
  /* 2 */
125
125
  /***/ ((module) => {
126
126
 
127
- module.exports = JSON.parse('{"name":"@rive-app/canvas-single","version":"1.0.18","description":"Rive\'s high-level canvas based web api all in one js file.","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}}');
127
+ module.exports = JSON.parse('{"name":"@rive-app/canvas-single","version":"1.0.19","description":"Rive\'s high-level canvas based web api all in one js file.","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}}');
128
128
 
129
129
  /***/ })
130
130
  /******/ ]);
@@ -1071,7 +1071,7 @@ var Rive = /** @class */ (function () {
1071
1071
  autoplay: params.autoplay,
1072
1072
  animations: params.animations,
1073
1073
  stateMachines: params.stateMachines,
1074
- artboard: params.artboard
1074
+ artboard: params.artboard,
1075
1075
  });
1076
1076
  }
1077
1077
  // Alternative constructor to build a Rive instance from an interface/object
@@ -1101,6 +1101,10 @@ var Rive = /** @class */ (function () {
1101
1101
  _this.runtime = runtime;
1102
1102
  // Get the canvas where you want to render the animation and create a renderer
1103
1103
  _this.renderer = _this.runtime.makeRenderer(_this.canvas);
1104
+ // Initial size adjustment based on devicePixelRatio if no width/height are specified explicitly
1105
+ if (!(_this.canvas.width || _this.canvas.height)) {
1106
+ _this.resizeDrawingSurfaceToCanvas();
1107
+ }
1104
1108
  // Load Rive data from a source uri or a data buffer
1105
1109
  _this.initData(artboard, startingAnimationNames, startingStateMachineNames, autoplay).catch(function (e) {
1106
1110
  console.error(e);
@@ -1449,6 +1453,22 @@ var Rive = /** @class */ (function () {
1449
1453
  maxY: this.canvas.height
1450
1454
  });
1451
1455
  };
1456
+ /**
1457
+ * Accounts for devicePixelRatio as a multiplier to render the size of the canvas drawing surface.
1458
+ * Uses the size of the backing canvas to set new width/height attributes. Need to re-render
1459
+ * and resize the layout to match the new drawing surface afterwards. Useful function for consumers
1460
+ * to include in a window resize listener
1461
+ */
1462
+ Rive.prototype.resizeDrawingSurfaceToCanvas = function () {
1463
+ if (this.canvas instanceof HTMLCanvasElement && !!window) {
1464
+ var _a = this.canvas.getBoundingClientRect(), width = _a.width, height = _a.height;
1465
+ var dpr = window.devicePixelRatio || 1;
1466
+ this.canvas.width = dpr * width;
1467
+ this.canvas.height = dpr * height;
1468
+ this.startRendering();
1469
+ this.resizeToCanvas();
1470
+ }
1471
+ };
1452
1472
  Object.defineProperty(Rive.prototype, "source", {
1453
1473
  // Returns the animation source, which may be undefined
1454
1474
  get: function () {