@rive-app/canvas-lite 2.49.0 → 2.49.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.49.0",
3
+ "version": "2.49.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.js CHANGED
@@ -351,6 +351,29 @@ var RuntimeLoader = /** @class */ (function () {
351
351
  return RuntimeLoader.getInstance(resolve, reject);
352
352
  });
353
353
  };
354
+ /**
355
+ * @internal Resolves once the replay worker's device caps reach the page,
356
+ * so scripts init against them. Null when there is nothing left to wait
357
+ * for, which keeps every later instance's load synchronous.
358
+ */
359
+ RuntimeLoader.awaitReplayCaps = function () {
360
+ var _a, _b;
361
+ if (RuntimeLoader.replayCapsArrived) {
362
+ return null;
363
+ }
364
+ var pending = (_b = (_a = RuntimeLoader.runtime) === null || _a === void 0 ? void 0 : _a.awaitReplayCaps) === null || _b === void 0 ? void 0 : _b.call(_a);
365
+ if (!pending) {
366
+ return null;
367
+ }
368
+ // A worker that never answers must not hold every load back; its caps
369
+ // then bind when the surface does, as before.
370
+ var timeout = new Promise(function (resolve) {
371
+ return setTimeout(resolve, RuntimeLoader.replayCapsTimeoutMs);
372
+ });
373
+ return Promise.race([pending, timeout]).then(function () {
374
+ RuntimeLoader.replayCapsArrived = true;
375
+ });
376
+ };
354
377
  // Manually sets the wasm url
355
378
  RuntimeLoader.setWasmUrl = function (url) {
356
379
  RuntimeLoader.wasmURL = url;
@@ -461,6 +484,8 @@ var RuntimeLoader = /** @class */ (function () {
461
484
  RuntimeLoader.parallelParts = null;
462
485
  // Whether a threaded runtime replays deferred frames on a worker.
463
486
  RuntimeLoader.replayWorker = true;
487
+ RuntimeLoader.replayCapsArrived = false;
488
+ RuntimeLoader.replayCapsTimeoutMs = 2000;
464
489
  // Error callbacks enqueued from .getInstance()
465
490
  RuntimeLoader.errorCallbackQueue = [];
466
491
  /**
@@ -601,7 +626,7 @@ Lc=await (async function(){function b(c){c=Lc=c.exports;pb=c.free;Jc=c.malloc;ob
601
626
  /***/ ((module) => {
602
627
 
603
628
  "use strict";
604
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.49.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","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
629
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.49.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","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
605
630
 
606
631
  /***/ }),
607
632
  /* 7 */
@@ -7763,11 +7788,11 @@ var Rive = /** @class */ (function () {
7763
7788
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
7764
7789
  return __awaiter(this, void 0, void 0, function () {
7765
7790
  var riveFile, error_4, msg;
7766
- var _a, _b, _c, _d;
7767
- return __generator(this, function (_e) {
7768
- switch (_e.label) {
7791
+ var _a, _b, _c, _d, _e, _f;
7792
+ return __generator(this, function (_g) {
7793
+ switch (_g.label) {
7769
7794
  case 0:
7770
- _e.trys.push([0, 5, , 6]);
7795
+ _g.trys.push([0, 8, , 9]);
7771
7796
  // A caller-supplied riveFile is theirs to release; one we import here is
7772
7797
  // ours, which matters if a deferred fallback replaces it below.
7773
7798
  this.ownsRiveFile = this.riveFile == null;
@@ -7784,32 +7809,41 @@ var Rive = /** @class */ (function () {
7784
7809
  this.riveFile = riveFile;
7785
7810
  return [4 /*yield*/, riveFile.init()];
7786
7811
  case 1:
7787
- _e.sent();
7812
+ _g.sent();
7788
7813
  if (this.destroyed) {
7789
7814
  // In the very unlikely scenario where the rive file created by this Rive is shared by
7790
7815
  // another rive file, we only want to destroy it if this file is the only owner.
7791
7816
  riveFile.destroyIfUnused();
7792
7817
  return [2 /*return*/, false];
7793
7818
  }
7794
- _e.label = 2;
7819
+ _g.label = 2;
7795
7820
  case 2:
7796
7821
  if (!(this.riveFile.deferredSession !== null ||
7797
7822
  this.deferredRenderer ||
7798
- ((_b = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.replaysOnWorker) === null || _b === void 0 ? void 0 : _b.call(_a)) === true)) return [3 /*break*/, 4];
7799
- return [4 /*yield*/, this.resolveDeferredRendering()];
7823
+ ((_b = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.replaysOnWorker) === null || _b === void 0 ? void 0 : _b.call(_a)) === true)) return [3 /*break*/, 7];
7824
+ if (!(((_d = (_c = this.renderer) === null || _c === void 0 ? void 0 : _c.replaysOnWorker) === null || _d === void 0 ? void 0 : _d.call(_c)) === true)) return [3 /*break*/, 4];
7825
+ return [4 /*yield*/, _runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader.awaitReplayCaps()];
7800
7826
  case 3:
7801
- _e.sent();
7827
+ _g.sent();
7828
+ _g.label = 4;
7829
+ case 4:
7830
+ if (!!this.destroyed) return [3 /*break*/, 6];
7831
+ return [4 /*yield*/, this.resolveDeferredRendering()];
7832
+ case 5:
7833
+ _g.sent();
7834
+ _g.label = 6;
7835
+ case 6:
7802
7836
  if (this.destroyed) {
7803
7837
  // cleanup() ran during a re-import. Taking a reference now would
7804
7838
  // resurrect a file this instance is never going to draw. Only ours
7805
7839
  // to release — a caller-supplied file stays theirs.
7806
7840
  if (this.ownsRiveFile) {
7807
- (_c = this.riveFile) === null || _c === void 0 ? void 0 : _c.destroyIfUnused();
7841
+ (_e = this.riveFile) === null || _e === void 0 ? void 0 : _e.destroyIfUnused();
7808
7842
  }
7809
7843
  return [2 /*return*/, false];
7810
7844
  }
7811
- _e.label = 4;
7812
- case 4:
7845
+ _g.label = 7;
7846
+ case 7:
7813
7847
  this.file = this.riveFile.getInstance();
7814
7848
  this.reportDisplayScale();
7815
7849
  // Initialize and draw frame
@@ -7829,7 +7863,7 @@ var Rive = /** @class */ (function () {
7829
7863
  this.loaded = true;
7830
7864
  this.eventManager.fire({
7831
7865
  type: EventType.Load,
7832
- data: (_d = this.src) !== null && _d !== void 0 ? _d : "buffer",
7866
+ data: (_f = this.src) !== null && _f !== void 0 ? _f : "buffer",
7833
7867
  });
7834
7868
  }
7835
7869
  catch (e) {
@@ -7847,12 +7881,12 @@ var Rive = /** @class */ (function () {
7847
7881
  this.taskQueue.process();
7848
7882
  this.drawFrame();
7849
7883
  return [2 /*return*/, true];
7850
- case 5:
7851
- error_4 = _e.sent();
7884
+ case 8:
7885
+ error_4 = _g.sent();
7852
7886
  msg = resolveErrorMessage(error_4);
7853
7887
  this.eventManager.fire({ type: EventType.LoadError, data: msg });
7854
7888
  return [2 /*return*/, Promise.reject(msg)];
7855
- case 6: return [2 /*return*/];
7889
+ case 9: return [2 /*return*/];
7856
7890
  }
7857
7891
  });
7858
7892
  });
@@ -8399,8 +8433,13 @@ var Rive = /** @class */ (function () {
8399
8433
  this.lastRenderTime = frameTime;
8400
8434
  this.advanceAndReportChanges(elapsedTime, time);
8401
8435
  var renderer = this.renderer;
8402
- // Do not draw on 0 canvas size
8403
- if (!this._hasZeroSize) {
8436
+ // Don't draw on a 0-size canvas; redraw once it has area. The observer
8437
+ // flags zero size late, so also check the surface itself.
8438
+ var hasSurface = this.canvas.width > 0 && this.canvas.height > 0;
8439
+ if (!hasSurface) {
8440
+ this._needsRedraw = true;
8441
+ }
8442
+ if (!this._hasZeroSize && hasSurface) {
8404
8443
  // If there was no dirt on this frame, do not clear and draw. The deferred
8405
8444
  // term has to be read here, before `clear()` below: clearing opens the
8406
8445
  // session's recording window and marks its stream, so a read taken after