@rive-app/webgl-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/webgl-single",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
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
@@ -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
@@ -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.18","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.19","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
  /******/ ]);
@@ -1115,7 +1115,7 @@ var Rive = /** @class */ (function () {
1115
1115
  autoplay: params.autoplay,
1116
1116
  animations: params.animations,
1117
1117
  stateMachines: params.stateMachines,
1118
- artboard: params.artboard
1118
+ artboard: params.artboard,
1119
1119
  });
1120
1120
  }
1121
1121
  // Alternative constructor to build a Rive instance from an interface/object
@@ -1145,6 +1145,10 @@ var Rive = /** @class */ (function () {
1145
1145
  _this.runtime = runtime;
1146
1146
  // Get the canvas where you want to render the animation and create a renderer
1147
1147
  _this.renderer = _this.runtime.makeRenderer(_this.canvas);
1148
+ // Initial size adjustment based on devicePixelRatio if no width/height are specified explicitly
1149
+ if (!(_this.canvas.width || _this.canvas.height)) {
1150
+ _this.resizeDrawingSurfaceToCanvas();
1151
+ }
1148
1152
  // Load Rive data from a source uri or a data buffer
1149
1153
  _this.initData(artboard, startingAnimationNames, startingStateMachineNames, autoplay).catch(function (e) {
1150
1154
  console.error(e);
@@ -1493,6 +1497,22 @@ var Rive = /** @class */ (function () {
1493
1497
  maxY: this.canvas.height
1494
1498
  });
1495
1499
  };
1500
+ /**
1501
+ * Accounts for devicePixelRatio as a multiplier to render the size of the canvas drawing surface.
1502
+ * Uses the size of the backing canvas to set new width/height attributes. Need to re-render
1503
+ * and resize the layout to match the new drawing surface afterwards. Useful function for consumers
1504
+ * to include in a window resize listener
1505
+ */
1506
+ Rive.prototype.resizeDrawingSurfaceToCanvas = function () {
1507
+ if (this.canvas instanceof HTMLCanvasElement && !!window) {
1508
+ var _a = this.canvas.getBoundingClientRect(), width = _a.width, height = _a.height;
1509
+ var dpr = window.devicePixelRatio || 1;
1510
+ this.canvas.width = dpr * width;
1511
+ this.canvas.height = dpr * height;
1512
+ this.startRendering();
1513
+ this.resizeToCanvas();
1514
+ }
1515
+ };
1496
1516
  Object.defineProperty(Rive.prototype, "source", {
1497
1517
  // Returns the animation source, which may be undefined
1498
1518
  get: function () {