@rive-app/canvas-lite 2.49.0 → 2.49.2
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 +1 -1
- package/rive.d.ts +1 -0
- package/rive.js +205 -25
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +13 -0
- package/rive_fallback.wasm +0 -0
- package/runtimeLoader.d.ts +8 -0
- package/utils/index.d.ts +1 -0
- package/utils/replayPacer.d.ts +24 -0
package/package.json
CHANGED
package/rive.d.ts
CHANGED
|
@@ -883,6 +883,7 @@ export declare class Rive {
|
|
|
883
883
|
private lastRenderTime;
|
|
884
884
|
private static batchStart;
|
|
885
885
|
private frameRequestId;
|
|
886
|
+
private replayPacer;
|
|
886
887
|
/**
|
|
887
888
|
* Used be draw to track when a second of active rendering time has passed.
|
|
888
889
|
* Used for debugging purposes
|
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
|
/**
|
|
@@ -503,7 +528,7 @@ w)a.canvas.width=q,a.canvas.height=w;a.viewport(0,0,q,w);a.disable(a.SCISSOR_TES
|
|
|
503
528
|
console.assert(E==8*C);E=A.push(G);g!=E&&(a.bufferData(a.ELEMENT_ARRAY_BUFFER,2*E,a.DYNAMIC_DRAW),g=E);H=0;for(var R of p)a.bufferSubData(a.ELEMENT_ARRAY_BUFFER,H,R.N.indices),H+=2*R.N.indices.length;console.assert(H==2*G);R=0;L=!1;E=H=0;for(const I of p){p=I.N;p.image.Ca!=R&&(a.bindTexture(a.TEXTURE_2D,p.image.V||null),R=p.image.Ca);I.Za?(a.scissor(I.qb,w-I.rb-I.Xa,I.Vb,I.Xa),L||(a.enable(a.SCISSOR_TEST),L=!0)):L&&(a.disable(a.SCISSOR_TEST),L=!1);const S=I.pb,Y=2/q,ca=-2/w;a.uniform4f(f,S[0]*Y,S[1]*
|
|
504
529
|
ca,S[2]*Y,S[3]*ca);a.uniform2f(m,S[4]*Y-1,S[5]*ca+1);a.vertexAttribPointer(0,2,a.FLOAT,!1,0,E);a.vertexAttribPointer(1,2,a.FLOAT,!1,0,E+4*C);a.drawElements(a.TRIANGLES,p.indices.length,a.UNSIGNED_SHORT,H);E+=4*p.pa.length;H+=2*p.indices.length}console.assert(E==4*C);console.assert(H==2*G)}};this.canvas=function(){return b()&&a.canvas}};class ua{constructor(){this.eb=!1}canvas(){return oa.canvas()||null}}const va=new qa;
|
|
505
530
|
function wa(b,a,c,d,f,m){const h=new DOMMatrix;h.a=b;h.b=a;h.c=c;h.d=d;h.e=f;h.f=m;return h}const xa="createConicGradient createImageData createLinearGradient createPattern createRadialGradient getContextAttributes getImageData getLineDash getTransform isContextLost isPointInPath isPointInStroke measureText".split(" "),ya=l.onRuntimeInitialized;
|
|
506
|
-
l.onRuntimeInitialized=function(){function b(e){switch(e){case z.srcOver:return"source-over";case z.
|
|
531
|
+
l.onRuntimeInitialized=function(){function b(e){switch(e){case z.srcOver:return"source-over";case z.additive:return"lighter";case z.screen:return"screen";case z.overlay:return"overlay";case z.darken:return"darken";case z.lighten:return"lighten";case z.colorDodge:return"color-dodge";case z.colorBurn:return"color-burn";case z.hardLight:return"hard-light";case z.softLight:return"soft-light";case z.difference:return"difference";case z.exclusion:return"exclusion";case z.multiply:return"multiply";case z.hue:return"hue";
|
|
507
532
|
case z.saturation:return"saturation";case z.color:return"color";case z.luminosity:return"luminosity"}}function a(e){return"rgba("+((16711680&e)>>>16)+","+((65280&e)>>>8)+","+((255&e)>>>0)+","+((4278190080&e)>>>24)/255+")"}function c(e,k,t,u,v){return{fb:e,gb:k,Sa:t,Ta:u,type:v,Ka:[],T:null}}function d(e,k,t,u){if(k.Y===H&&!(0<k.Z))return null;t=1===t;return{Ha:e.La(t?k.xa:null),gradientTransform:t?k.ca:null,Ub:t?k.Z*k.Ba:k.Z,fillRule:e.ha===L?"evenodd":"nonzero",opacity:u,style:k.Y,color:k.sa,Wa:k.I,
|
|
508
533
|
tb:k.ra,join:k.ya,sb:k.qa}}function f(e,k){return k.Y!==H||0<k.Z?{path:e.kb(e.ha),Ga:k.lb()}:null}function m(){if(0!==I.m.length){var e=na();if(0!==e){var k=Math.min(I.na.push(I.i.drawWidth()),e);e=Math.min(I.$.push(I.i.drawHeight()),e);oa.Ab(k,e,I.m)}}for(const t of ta){for(const u of t.G)u();t.G=[]}ta.clear();for(const t of I.m)t.Pb();I.m=[];I.i&&I.i.reset(512,512)}ya&&ya();var h=l.RenderPaintStyle,g=l.FillRule;const n=l.RenderPath,r=l.RenderPaint,A=l.Renderer,q=l.StrokeCap,w=l.StrokeJoin,p=l.StrokePosition,
|
|
509
534
|
z=l.BlendMode,C=l.ImageFilter,G=l.ImageWrap,E=h.fill,H=h.stroke,L=g.evenOdd,R=g.nonZero,I=va,S=I.M;let Y=1;var ca=l.RenderImage.extend("CanvasRenderImage",{__construct:function({ea:e,oa:k}={}){this.__parent.__construct.call(this);this.Ca=Y;Y=Y+1&2147483647||1;this.ea=e;this.oa=k;this.V=this.Pa=this.ia=this.wa=null},__destruct:function(){this.V&&(oa.xb(this.V),this.V=null);this.ia&&URL.revokeObjectURL(this.ia);this.__parent.__destruct.call(this)},decode:function(e){var k=this;k.oa&&k.oa(k);var t=new Image;
|
|
@@ -512,7 +537,7 @@ y:k}),this.path.lineTo(e.x,e.y)):this.path.lineTo(e,k)}wb(e,k,t,u,v,B){this.m=nu
|
|
|
512
537
|
this.m||this.ua||(this.M(),this.ua=!0)}dispose(){}}class sa{constructor(e){this.Lb=e;this.$=this.M=0;this.m=null;this.i=e(null)}clear(){this.na(null)}Da(e,k){for(((null===k?null!==this.m:null===this.m||this.m.a!==k.a||this.m.b!==k.b||this.m.c!==k.c||this.m.d!==k.d||this.m.e!==k.e||this.m.f!==k.f)||this.$<e.length&&(0<this.M||this.i.ua))&&this.na(k);this.$<e.length;)e[this.$++](this.i);this.i.Va();this.M++;return this.i.path}Ja(e){null!==this.i&&e===this.i.path&&this.M--}dispose(){this.i.dispose();
|
|
513
538
|
this.i=null}na(e){this.i.dispose();this.$=this.M=0;this.m=e;this.i=this.Lb(e)}}var Ea=n.extend("CanvasRenderPath",{__construct:function(){this.__parent.__construct.call(this);this.W=[];this.ja=new sa(e=>new ra(e));this.ka=new sa(e=>new ra(e));this.X=new Map;this.ha=R;this.va=!1},__destruct:function(){this.ja.dispose();this.ka.dispose();for(const e of this.X.values())e.dispose();this.X.clear();this.__parent.__destruct.call(this)},rewind:function(){this.W.length=0;this.ja.clear();this.ka.clear();for(const e of this.X.values())e.clear();
|
|
514
539
|
this.va=!1},addPath:function(e,k,t,u,v,B,D){const y=e.W.slice();this.ba(x=>x.addPath(y,k,t,u,v,B,D))},fillRule:function(e){this.ha=e},moveTo:function(e,k){this.va=!0;this.ba(t=>t.moveTo(e,k))},lineTo:function(e,k){this.Oa();this.ba(t=>t.lineTo(e,k))},cubicTo:function(e,k,t,u,v,B){this.Oa();this.ba(D=>D.wb(e,k,t,u,v,B))},close:function(){this.ba(e=>e.close())},Oa:function(){this.va||this.moveTo(0,0)},ba:function(e){this.W.push(e)},La:function(e){e=null===e?this.ja.Da(this.W,null):this.ka.Da(this.W,
|
|
515
|
-
e);e.ref&&e.ref();return e},kb:function(e){var k=this.X.get(e);void 0===k&&(k=new sa(()=>S.
|
|
540
|
+
e);e.ref&&e.ref();return e},kb:function(e){var k=this.X.get(e);void 0===k&&(k=new sa(()=>S.Yb(e)),this.X.set(e,k));k=k.Da(this.W,null);k.ref&&k.ref();return k},za:function(e){this.ja.Ja(e);this.ka.Ja(e);for(const k of this.X.values())k.Ja(e);e.unref&&e.unref()}});const bc=c(0,0,0,0,0);var dc=r.extend("CanvasRenderPaint",{__construct:function(){this.__parent.__construct.call(this);this.Y=E;this.sa=4278190080;this.Z=1;this.ya=w.miter;this.ra=q.butt;this.Aa=p.center;this.ta=0;this.qa=b(z.srcOver);this.xa=
|
|
516
541
|
this.A=this.ca=this.I=null;this.Ba=1;this.B=0;this.S=null;this.Qa=-1},__destruct:function(){null!==this.S&&(l.unrefWebGL2Paint(this.S),this.S=null);this.__parent.__destruct.call(this)},color:function(e){this.sa=e;this.I=null;this.B++},thickness:function(e){this.Z=Math.abs(e);this.B++},join:function(e){this.ya=e;this.B++},cap:function(e){this.ra=e;this.B++},strokePosition:function(e){this.Aa=e;this.B++},feather:function(e){this.ta=Math.abs(e);this.B++},style:function(e){this.Y=e;this.B++},blendMode:function(e){this.qa=
|
|
517
542
|
b(e);this.B++},clearGradient:function(){this.I=null;this.B++},linearGradient:function(e,k,t,u){this.I=c(e,k,t,u,0);this.B++},radialGradient:function(e,k,t,u){this.I=c(e,k,t,u,1);this.B++},angularGradient:function(){this.I=c(0,0,0,0,2);this.B++},addStop:function(e,k){this.I.Ka.push({color:e,stop:k});this.I.T=null;this.B++},modulatedImage:function(e,k,t,u,v,B,D,y,x,J){const K=e.wa;K?this.A={image:K,jb:e.Pa,filter:k,Wb:t,Xb:u,transform:wa(v,B,D,y,x,J)}:this.A=null},completeGradient:function(){},_setGradientTransform:function(e,
|
|
518
543
|
k,t,u,v,B,D,y,x,J,K,P,T){1===e&&0===k&&0===t&&1===u&&0===v&&0===B?this.xa=this.ca=null:(this.ca=wa(e,k,t,u,v,B),this.xa=wa(D,y,x,J,K,P));this.Ba=T;this.B++},lb:function(){if(this.Qa!==this.B){null!==this.S&&l.unrefWebGL2Paint(this.S);const k=null!==this.I?this.I:bc;let t=null,u=null;if(null!==this.I){var e=k.Ka;t=new Uint32Array(e.length);u=new Float32Array(e.length);for(let ja=0,cc=e.length;ja<cc;ja++)t[ja]=e[ja].color,u[ja]=e[ja].stop}e=null;let v=C.bilinear,B=G.clamp,D=G.clamp,y=1,x=0,J=0,K=1,
|
|
@@ -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.
|
|
629
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.49.2","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 */
|
|
@@ -2753,6 +2778,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2753
2778
|
/* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.ImageAssetWrapper),
|
|
2754
2779
|
/* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.ImageWrapper),
|
|
2755
2780
|
/* harmony export */ KeyboardInteractions: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.KeyboardInteractions),
|
|
2781
|
+
/* harmony export */ ReplayPacer: () => (/* reexport safe */ _replayPacer__WEBPACK_IMPORTED_MODULE_6__.ReplayPacer),
|
|
2756
2782
|
/* harmony export */ RiveFont: () => (/* reexport safe */ _riveFont__WEBPACK_IMPORTED_MODULE_5__.RiveFont),
|
|
2757
2783
|
/* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.createFinalization),
|
|
2758
2784
|
/* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.finalizationRegistry),
|
|
@@ -2765,6 +2791,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2765
2791
|
/* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(20);
|
|
2766
2792
|
/* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(21);
|
|
2767
2793
|
/* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(22);
|
|
2794
|
+
/* harmony import */ var _replayPacer__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(23);
|
|
2795
|
+
|
|
2768
2796
|
|
|
2769
2797
|
|
|
2770
2798
|
|
|
@@ -5199,6 +5227,138 @@ var RiveFont = /** @class */ (function () {
|
|
|
5199
5227
|
|
|
5200
5228
|
|
|
5201
5229
|
|
|
5230
|
+
/***/ }),
|
|
5231
|
+
/* 23 */
|
|
5232
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5233
|
+
|
|
5234
|
+
"use strict";
|
|
5235
|
+
__webpack_require__.r(__webpack_exports__);
|
|
5236
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5237
|
+
/* harmony export */ ReplayPacer: () => (/* binding */ ReplayPacer)
|
|
5238
|
+
/* harmony export */ });
|
|
5239
|
+
var kRefreshSamples = 15;
|
|
5240
|
+
// The frames the worker's replay time averages over, plus the three still in
|
|
5241
|
+
// flight when the cadence changes.
|
|
5242
|
+
var kSettleFrames = 12;
|
|
5243
|
+
var kProbeAfterMs = 1000;
|
|
5244
|
+
var kMaxProbeAfterMs = 16000;
|
|
5245
|
+
// A worker only slightly slower than its cadence fills its queue now and then,
|
|
5246
|
+
// a worker that keeps up almost never.
|
|
5247
|
+
var kBackupWindow = 60;
|
|
5248
|
+
var kSaturatedBackups = 3;
|
|
5249
|
+
var median = function (values) {
|
|
5250
|
+
var sorted = values.slice().sort(function (a, b) { return a - b; });
|
|
5251
|
+
return sorted[sorted.length >> 1];
|
|
5252
|
+
};
|
|
5253
|
+
/**
|
|
5254
|
+
* Paces recording to a replay worker slower than the display. Recording as
|
|
5255
|
+
* soon as its queue frees sends frames in bursts, so instead they go out every
|
|
5256
|
+
* N refreshes, with N following the worker's recent replay time.
|
|
5257
|
+
*/
|
|
5258
|
+
var ReplayPacer = /** @class */ (function () {
|
|
5259
|
+
function ReplayPacer() {
|
|
5260
|
+
this.lastTime = 0;
|
|
5261
|
+
this.lastRecord = 0;
|
|
5262
|
+
this.intervals = [];
|
|
5263
|
+
this.divisor = 1;
|
|
5264
|
+
// Frames recorded since the divisor changed, which the replay time still
|
|
5265
|
+
// averages in.
|
|
5266
|
+
this.settle = 0;
|
|
5267
|
+
this.nextProbe = 0;
|
|
5268
|
+
this.probing = false;
|
|
5269
|
+
// Failed probes back off, since each one costs a few uneven frames.
|
|
5270
|
+
this.probeAfter = kProbeAfterMs;
|
|
5271
|
+
// Whether the worker's queue filled since the last decision.
|
|
5272
|
+
this.backedUp = false;
|
|
5273
|
+
this.recentBackups = [];
|
|
5274
|
+
}
|
|
5275
|
+
/**
|
|
5276
|
+
* Called on every animation frame. Returns whether this one should record,
|
|
5277
|
+
* given the worker's replay time and whether its queue has room.
|
|
5278
|
+
*/
|
|
5279
|
+
ReplayPacer.prototype.shouldRecord = function (time, replayMs, accepts) {
|
|
5280
|
+
if (this.lastTime && time > this.lastTime) {
|
|
5281
|
+
this.intervals.push(time - this.lastTime);
|
|
5282
|
+
if (this.intervals.length > kRefreshSamples) {
|
|
5283
|
+
this.intervals.shift();
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5286
|
+
this.lastTime = time;
|
|
5287
|
+
if (!accepts) {
|
|
5288
|
+
// A canvas the worker has yet to take refuses frames too.
|
|
5289
|
+
if (replayMs > 0) {
|
|
5290
|
+
this.backedUp = true;
|
|
5291
|
+
}
|
|
5292
|
+
return false;
|
|
5293
|
+
}
|
|
5294
|
+
if (replayMs > 0 && this.intervals.length > 0) {
|
|
5295
|
+
var refresh = median(this.intervals);
|
|
5296
|
+
if (this.settle === 0) {
|
|
5297
|
+
this.adapt(time, replayMs / refresh);
|
|
5298
|
+
}
|
|
5299
|
+
if (this.divisor > 1 &&
|
|
5300
|
+
time - this.lastRecord < (this.divisor - 0.5) * refresh) {
|
|
5301
|
+
return false;
|
|
5302
|
+
}
|
|
5303
|
+
}
|
|
5304
|
+
this.lastRecord = time;
|
|
5305
|
+
this.settle = Math.max(0, this.settle - 1);
|
|
5306
|
+
return true;
|
|
5307
|
+
};
|
|
5308
|
+
ReplayPacer.prototype.adapt = function (time, ratio) {
|
|
5309
|
+
var divisor = this.divisor;
|
|
5310
|
+
var backedUp = this.backedUp;
|
|
5311
|
+
this.backedUp = false;
|
|
5312
|
+
this.recentBackups.push(backedUp);
|
|
5313
|
+
if (this.recentBackups.length > kBackupWindow) {
|
|
5314
|
+
this.recentBackups.shift();
|
|
5315
|
+
}
|
|
5316
|
+
var saturated = this.recentBackups.filter(Boolean).length >= kSaturatedBackups;
|
|
5317
|
+
var lagging = ratio > divisor * 1.1;
|
|
5318
|
+
// A worker that keeps up never fills its queue, however long each frame
|
|
5319
|
+
// takes to finish, so only a lag with a full queue slows the cadence. A
|
|
5320
|
+
// probe fails on either, since it settled at the new cadence.
|
|
5321
|
+
if (this.probing
|
|
5322
|
+
? lagging || backedUp
|
|
5323
|
+
: (lagging && backedUp) || (ratio > divisor && saturated)) {
|
|
5324
|
+
this.probeAfter = this.probing
|
|
5325
|
+
? Math.min(this.probeAfter * 2, kMaxProbeAfterMs)
|
|
5326
|
+
: kProbeAfterMs;
|
|
5327
|
+
this.setDivisor(time, Math.max(divisor + 1, Math.ceil(ratio)));
|
|
5328
|
+
}
|
|
5329
|
+
else if (ratio < (divisor - 1) * 0.9) {
|
|
5330
|
+
// Paced frames no longer overlap, so their replay time is a ceiling
|
|
5331
|
+
// and a faster cadence under it is safe.
|
|
5332
|
+
this.probeAfter = kProbeAfterMs;
|
|
5333
|
+
this.setDivisor(time, Math.max(1, Math.ceil(ratio / 0.9)));
|
|
5334
|
+
}
|
|
5335
|
+
else if (this.probing) {
|
|
5336
|
+
// A worker only slightly too slow takes a while to fill its queue.
|
|
5337
|
+
if (this.recentBackups.length >= kBackupWindow) {
|
|
5338
|
+
this.probing = false;
|
|
5339
|
+
this.probeAfter = kProbeAfterMs;
|
|
5340
|
+
}
|
|
5341
|
+
}
|
|
5342
|
+
else if (divisor > 1 && time >= this.nextProbe) {
|
|
5343
|
+
// Frames that overlap on the GPU can keep up with a cadence shorter
|
|
5344
|
+
// than one frame's replay, which only trying it shows.
|
|
5345
|
+
this.setDivisor(time, divisor - 1);
|
|
5346
|
+
this.probing = true;
|
|
5347
|
+
}
|
|
5348
|
+
};
|
|
5349
|
+
ReplayPacer.prototype.setDivisor = function (time, divisor) {
|
|
5350
|
+
this.divisor = divisor;
|
|
5351
|
+
this.settle = kSettleFrames;
|
|
5352
|
+
this.probing = false;
|
|
5353
|
+
this.backedUp = false;
|
|
5354
|
+
this.recentBackups = [];
|
|
5355
|
+
this.nextProbe = time + this.probeAfter;
|
|
5356
|
+
};
|
|
5357
|
+
return ReplayPacer;
|
|
5358
|
+
}());
|
|
5359
|
+
|
|
5360
|
+
|
|
5361
|
+
|
|
5202
5362
|
/***/ })
|
|
5203
5363
|
/******/ ]);
|
|
5204
5364
|
/************************************************************************/
|
|
@@ -7278,6 +7438,7 @@ var Rive = /** @class */ (function () {
|
|
|
7278
7438
|
this.lastRenderTime = 0;
|
|
7279
7439
|
// Tracks the current animation frame request
|
|
7280
7440
|
this.frameRequestId = null;
|
|
7441
|
+
this.replayPacer = new _utils__WEBPACK_IMPORTED_MODULE_3__.ReplayPacer();
|
|
7281
7442
|
/**
|
|
7282
7443
|
* Used be draw to track when a second of active rendering time has passed.
|
|
7283
7444
|
* Used for debugging purposes
|
|
@@ -7763,11 +7924,11 @@ var Rive = /** @class */ (function () {
|
|
|
7763
7924
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
|
|
7764
7925
|
return __awaiter(this, void 0, void 0, function () {
|
|
7765
7926
|
var riveFile, error_4, msg;
|
|
7766
|
-
var _a, _b, _c, _d;
|
|
7767
|
-
return __generator(this, function (
|
|
7768
|
-
switch (
|
|
7927
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7928
|
+
return __generator(this, function (_g) {
|
|
7929
|
+
switch (_g.label) {
|
|
7769
7930
|
case 0:
|
|
7770
|
-
|
|
7931
|
+
_g.trys.push([0, 8, , 9]);
|
|
7771
7932
|
// A caller-supplied riveFile is theirs to release; one we import here is
|
|
7772
7933
|
// ours, which matters if a deferred fallback replaces it below.
|
|
7773
7934
|
this.ownsRiveFile = this.riveFile == null;
|
|
@@ -7784,32 +7945,41 @@ var Rive = /** @class */ (function () {
|
|
|
7784
7945
|
this.riveFile = riveFile;
|
|
7785
7946
|
return [4 /*yield*/, riveFile.init()];
|
|
7786
7947
|
case 1:
|
|
7787
|
-
|
|
7948
|
+
_g.sent();
|
|
7788
7949
|
if (this.destroyed) {
|
|
7789
7950
|
// In the very unlikely scenario where the rive file created by this Rive is shared by
|
|
7790
7951
|
// another rive file, we only want to destroy it if this file is the only owner.
|
|
7791
7952
|
riveFile.destroyIfUnused();
|
|
7792
7953
|
return [2 /*return*/, false];
|
|
7793
7954
|
}
|
|
7794
|
-
|
|
7955
|
+
_g.label = 2;
|
|
7795
7956
|
case 2:
|
|
7796
7957
|
if (!(this.riveFile.deferredSession !== null ||
|
|
7797
7958
|
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*/,
|
|
7799
|
-
return [
|
|
7959
|
+
((_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];
|
|
7960
|
+
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];
|
|
7961
|
+
return [4 /*yield*/, _runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader.awaitReplayCaps()];
|
|
7800
7962
|
case 3:
|
|
7801
|
-
|
|
7963
|
+
_g.sent();
|
|
7964
|
+
_g.label = 4;
|
|
7965
|
+
case 4:
|
|
7966
|
+
if (!!this.destroyed) return [3 /*break*/, 6];
|
|
7967
|
+
return [4 /*yield*/, this.resolveDeferredRendering()];
|
|
7968
|
+
case 5:
|
|
7969
|
+
_g.sent();
|
|
7970
|
+
_g.label = 6;
|
|
7971
|
+
case 6:
|
|
7802
7972
|
if (this.destroyed) {
|
|
7803
7973
|
// cleanup() ran during a re-import. Taking a reference now would
|
|
7804
7974
|
// resurrect a file this instance is never going to draw. Only ours
|
|
7805
7975
|
// to release — a caller-supplied file stays theirs.
|
|
7806
7976
|
if (this.ownsRiveFile) {
|
|
7807
|
-
(
|
|
7977
|
+
(_e = this.riveFile) === null || _e === void 0 ? void 0 : _e.destroyIfUnused();
|
|
7808
7978
|
}
|
|
7809
7979
|
return [2 /*return*/, false];
|
|
7810
7980
|
}
|
|
7811
|
-
|
|
7812
|
-
case
|
|
7981
|
+
_g.label = 7;
|
|
7982
|
+
case 7:
|
|
7813
7983
|
this.file = this.riveFile.getInstance();
|
|
7814
7984
|
this.reportDisplayScale();
|
|
7815
7985
|
// Initialize and draw frame
|
|
@@ -7829,7 +7999,7 @@ var Rive = /** @class */ (function () {
|
|
|
7829
7999
|
this.loaded = true;
|
|
7830
8000
|
this.eventManager.fire({
|
|
7831
8001
|
type: EventType.Load,
|
|
7832
|
-
data: (
|
|
8002
|
+
data: (_f = this.src) !== null && _f !== void 0 ? _f : "buffer",
|
|
7833
8003
|
});
|
|
7834
8004
|
}
|
|
7835
8005
|
catch (e) {
|
|
@@ -7847,12 +8017,12 @@ var Rive = /** @class */ (function () {
|
|
|
7847
8017
|
this.taskQueue.process();
|
|
7848
8018
|
this.drawFrame();
|
|
7849
8019
|
return [2 /*return*/, true];
|
|
7850
|
-
case
|
|
7851
|
-
error_4 =
|
|
8020
|
+
case 8:
|
|
8021
|
+
error_4 = _g.sent();
|
|
7852
8022
|
msg = resolveErrorMessage(error_4);
|
|
7853
8023
|
this.eventManager.fire({ type: EventType.LoadError, data: msg });
|
|
7854
8024
|
return [2 /*return*/, Promise.reject(msg)];
|
|
7855
|
-
case
|
|
8025
|
+
case 9: return [2 /*return*/];
|
|
7856
8026
|
}
|
|
7857
8027
|
});
|
|
7858
8028
|
});
|
|
@@ -8348,7 +8518,7 @@ var Rive = /** @class */ (function () {
|
|
|
8348
8518
|
* @param time the rAF timestamp, or null to draw now without advancing
|
|
8349
8519
|
*/
|
|
8350
8520
|
Rive.prototype.draw = function (time, onSecond) {
|
|
8351
|
-
var _a, _b, _c, _d;
|
|
8521
|
+
var _a, _b, _c, _d, _e, _f;
|
|
8352
8522
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
8353
8523
|
this.frameRequestId = null;
|
|
8354
8524
|
// load() tears the artboard down and re-inits asynchronously; a frame
|
|
@@ -8362,10 +8532,15 @@ var Rive = /** @class */ (function () {
|
|
|
8362
8532
|
this.reloadForRestoredContext();
|
|
8363
8533
|
return;
|
|
8364
8534
|
}
|
|
8365
|
-
// The replay worker has yet to take the canvas,
|
|
8366
|
-
// frames
|
|
8535
|
+
// The replay worker has yet to take the canvas, is still on earlier
|
|
8536
|
+
// frames, or is slower than the display and this frame falls between its
|
|
8537
|
+
// paced ones. Waiting keeps its queue bounded, and the frame that follows
|
|
8367
8538
|
// advances by the whole wait, so playback keeps time.
|
|
8368
|
-
|
|
8539
|
+
var accepts = ((_d = (_c = this.renderer) === null || _c === void 0 ? void 0 : _c.acceptsFrame) === null || _d === void 0 ? void 0 : _d.call(_c)) !== false;
|
|
8540
|
+
var replayMs = (_f = (_e = this.renderer) === null || _e === void 0 ? void 0 : _e.replayMs) === null || _f === void 0 ? void 0 : _f.call(_e);
|
|
8541
|
+
if (time !== null && replayMs !== undefined
|
|
8542
|
+
? !this.replayPacer.shouldRecord(time, replayMs, accepts)
|
|
8543
|
+
: !accepts) {
|
|
8369
8544
|
this.scheduleRendering();
|
|
8370
8545
|
return;
|
|
8371
8546
|
}
|
|
@@ -8399,8 +8574,13 @@ var Rive = /** @class */ (function () {
|
|
|
8399
8574
|
this.lastRenderTime = frameTime;
|
|
8400
8575
|
this.advanceAndReportChanges(elapsedTime, time);
|
|
8401
8576
|
var renderer = this.renderer;
|
|
8402
|
-
//
|
|
8403
|
-
|
|
8577
|
+
// Don't draw on a 0-size canvas; redraw once it has area. The observer
|
|
8578
|
+
// flags zero size late, so also check the surface itself.
|
|
8579
|
+
var hasSurface = this.canvas.width > 0 && this.canvas.height > 0;
|
|
8580
|
+
if (!hasSurface) {
|
|
8581
|
+
this._needsRedraw = true;
|
|
8582
|
+
}
|
|
8583
|
+
if (!this._hasZeroSize && hasSurface) {
|
|
8404
8584
|
// If there was no dirt on this frame, do not clear and draw. The deferred
|
|
8405
8585
|
// term has to be read here, before `clear()` below: clearing opens the
|
|
8406
8586
|
// session's recording window and marks its stream, so a read taken after
|