@rive-app/webgl 1.0.70 → 1.0.73
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 +3 -2
- package/rive.js +124 -85
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
package/package.json
CHANGED
package/rive.d.ts
CHANGED
|
@@ -46,11 +46,11 @@ export declare class Layout {
|
|
|
46
46
|
readonly maxX: number;
|
|
47
47
|
readonly maxY: number;
|
|
48
48
|
constructor(params?: LayoutParameters);
|
|
49
|
-
static new({ fit, alignment, minX, minY, maxX, maxY }: LayoutParameters): Layout;
|
|
49
|
+
static new({ fit, alignment, minX, minY, maxX, maxY, }: LayoutParameters): Layout;
|
|
50
50
|
/**
|
|
51
51
|
* Makes a copy of the layout, replacing any specified parameters
|
|
52
52
|
*/
|
|
53
|
-
copyWith({ fit, alignment, minX, minY, maxX, maxY }: LayoutParameters): Layout;
|
|
53
|
+
copyWith({ fit, alignment, minX, minY, maxX, maxY, }: LayoutParameters): Layout;
|
|
54
54
|
runtimeFit(rive: rc.RiveCanvas): rc.Fit;
|
|
55
55
|
runtimeAlignment(rive: rc.RiveCanvas): rc.Alignment;
|
|
56
56
|
}
|
|
@@ -256,6 +256,7 @@ export declare class Rive {
|
|
|
256
256
|
private readyForPlaying;
|
|
257
257
|
private runtime;
|
|
258
258
|
private artboard;
|
|
259
|
+
private eventCleanup;
|
|
259
260
|
private file;
|
|
260
261
|
private eventManager;
|
|
261
262
|
private taskQueue;
|
package/rive.js
CHANGED
|
@@ -117,7 +117,7 @@ var g=(c&&f?function(){return Ea(e)}:function(){return e.length})(),h=Hc(4+g+1);
|
|
|
117
117
|
Ma,f=Na,g=function(){return B},h=2);L(a,{name:c,fromWireType:function(n){for(var p=B[n>>2],r=g(),w,z=n+4,m=0;m<=p;++m){var q=n+4+m*b;if(m==p||0==r[q>>h])z=d(z,q-z),void 0===w?w=z:(w+=String.fromCharCode(0),w+=z),z=q+b}Vb(n);return w},toWireType:function(n,p){"string"!==typeof p&&N("Cannot pass non-string to C++ string type "+c);var r=f(p),w=Hc(4+r+b);B[w>>2]=r>>h;e(p,w+4,r+b);null!==n&&n.push(Vb,w);return w},argPackAdvance:8,readValueFromPointer:gb,rd:function(n){Vb(n)}})},mb:function(a,b,c,d,e,f){eb[a]=
|
|
118
118
|
{name:M(b),Yd:P(c,d),vd:P(e,f),fe:[]}},cb:function(a,b,c,d,e,f,g,h,n,p){eb[a].fe.push({we:M(b),Ce:c,Ae:P(d,e),Be:f,Ke:g,Je:P(h,n),Le:p})},xb:function(a,b){b=M(b);L(a,{Fe:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},nb:function(){throw"longjmp";},La:function(a,b,c){a=cc(a);b=ec(b,"emval::as");var d=[],e=Kb(d);A[c>>2]=e;return b.toWireType(d,a)},ea:function(a,b,c,d){a=jc[a];b=cc(b);c=ic(c);a(b,c,null,d)},Gc:bc,V:function(a,b){var c=lc(a,b),d=c[0];b=d.name+"_$"+c.slice(1).map(function(r){return r.name}).join("_")+
|
|
119
119
|
"$";var e=mc[b];if(void 0!==e)return e;e=["retType"];for(var f=[d],g="",h=0;h<a-1;++h)g+=(0!==h?", ":"")+"arg"+h,e.push("argType"+h),f.push(c[1+h]);var n="return function "+kb("methodCaller_"+b)+"(handle, name, destructors, args) {\n",p=0;for(h=0;h<a-1;++h)n+=" var arg"+h+" = argType"+h+".readValueFromPointer(args"+(p?"+"+p:"")+");\n",p+=c[h+1].argPackAdvance;n+=" var rv = handle[name]("+g+");\n";for(h=0;h<a-1;++h)c[h+1].deleteObject&&(n+=" argType"+h+".deleteObject(arg"+h+");\n");d.Fe||
|
|
120
|
-
(n+=" return retType.toWireType(destructors, rv);\n");e.push(n+"};\n");a=Zb(e).apply(null,f);e=kc(a);return mc[b]=e},db:function(a,b){a=cc(a);b=cc(b);return Kb(a[b])},K:function(a){4<a&&(Q[a].Zd+=1)},Wa:function(a){return Kb(ic(a))},Aa:function(a){var b=cc(a);fb(b);bc(a)},pa:function(a,b){a=ec(a,"_emval_take_value");a=a.readValueFromPointer(b);return Kb(a)},a:function(){ta("")},
|
|
120
|
+
(n+=" return retType.toWireType(destructors, rv);\n");e.push(n+"};\n");a=Zb(e).apply(null,f);e=kc(a);return mc[b]=e},db:function(a,b){a=cc(a);b=cc(b);return Kb(a[b])},K:function(a){4<a&&(Q[a].Zd+=1)},Wa:function(a){return Kb(ic(a))},Aa:function(a){var b=cc(a);fb(b);bc(a)},pa:function(a,b){a=ec(a,"_emval_take_value");a=a.readValueFromPointer(b);return Kb(a)},a:function(){ta("")},ob:function(a,b){if(0===a)a=Date.now();else if(1===a||4===a)a=nc();else return A[bd()>>2]=28,-1;A[b>>2]=a/1E3|0;A[b+4>>
|
|
121
121
|
2]=a%1E3*1E6|0;return 0},Ya:function(a){t.activeTexture(a)},Xa:function(a,b){t.attachShader(R[a],S[b])},Va:function(a,b,c){t.bindAttribLocation(R[a],b,Ca(c))},Ua:function(a,b){35051==a?t.Wd=b:35052==a&&(t.Ad=b);t.bindBuffer(a,sc[b])},Yb:function(a,b){t.bindFramebuffer(a,tc[b])},Xb:function(a,b){t.bindRenderbuffer(a,uc[b])},Gb:function(a,b){t.bindSampler(a,xc[b])},Ta:function(a,b){t.bindTexture(a,vc[b])},oc:function(a){t.bindVertexArray(wc[a])},lc:function(a){t.bindVertexArray(wc[a])},Sa:function(a,
|
|
122
122
|
b,c,d){t.blendColor(a,b,c,d)},Ra:function(a){t.blendEquation(a)},Qa:function(a,b){t.blendFunc(a,b)},Lb:function(a,b,c,d,e,f,g,h,n,p){t.blitFramebuffer(a,b,c,d,e,f,g,h,n,p)},Pa:function(a,b,c,d){2<=l.version?c?t.bufferData(a,x,d,c,b):t.bufferData(a,b,d):t.bufferData(a,c?x.subarray(c,c+b):b,d)},Oa:function(a,b,c,d){2<=l.version?t.bufferSubData(a,b,x,d,c):t.bufferSubData(a,b,x.subarray(d,d+c))},Wb:function(a){return t.checkFramebufferStatus(a)},Na:function(a){t.clear(a)},Ma:function(a,b,c,d){t.clearColor(a,
|
|
123
123
|
b,c,d)},Ka:function(a){t.clearStencil(a)},$a:function(a,b,c,d){return t.clientWaitSync(yc[a],b,(c>>>0)+4294967296*d)},Ja:function(a,b,c,d){t.colorMask(!!a,!!b,!!c,!!d)},Ia:function(a){t.compileShader(S[a])},Ha:function(a,b,c,d,e,f,g,h){2<=l.version?t.Ad?t.compressedTexImage2D(a,b,c,d,e,f,g,h):t.compressedTexImage2D(a,b,c,d,e,f,x,h,g):t.compressedTexImage2D(a,b,c,d,e,f,h?x.subarray(h,h+g):null)},Ga:function(a,b,c,d,e,f,g,h,n){2<=l.version?t.Ad?t.compressedTexSubImage2D(a,b,c,d,e,f,g,h,n):t.compressedTexSubImage2D(a,
|
|
@@ -146,10 +146,10 @@ b)for(var e=Lc[4*b-1],f=0;f<4*b;f+=4)e[f]=F[d+4*f>>2],e[f+1]=F[d+(4*f+4)>>2],e[f
|
|
|
146
146
|
64*b>>2);t.uniformMatrix4fv(U(a),!!c,e)}},vc:function(a){a=R[a];t.useProgram(a);t.se=a},uc:function(a,b){t.vertexAttrib1f(a,b)},tc:function(a,b){t.vertexAttrib2f(a,F[b>>2],F[b+4>>2])},sc:function(a,b){t.vertexAttrib3f(a,F[b>>2],F[b+4>>2],F[b+8>>2])},rc:function(a,b){t.vertexAttrib4f(a,F[b>>2],F[b+4>>2],F[b+8>>2],F[b+12>>2])},_b:function(a,b){t.vertexAttribDivisor(a,b)},Zb:function(a,b,c,d,e){t.vertexAttribIPointer(a,b,c,d,e)},qc:function(a,b,c,d,e,f){t.vertexAttribPointer(a,b,c,!!d,e,f)},pc:function(a,
|
|
147
147
|
b,c,d){t.viewport(a,b,c,d)},ab:function(a,b,c,d){t.waitSync(yc[a],b,(c>>>0)+4294967296*d)},v:function(a){var b=x.length;a>>>=0;if(2147483648<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);d=Math.max(a,d);0<d%65536&&(d+=65536-d%65536);a:{try{ya.grow(Math.min(2147483648,d)-Oa.byteLength+65535>>>16);Ra();var e=1;break a}catch(f){}e=void 0}if(e)return!0}return!1},qb:function(a,b){var c=0;Oc().forEach(function(d,e){var f=b+c;e=A[a+4*e>>2]=f;for(f=0;f<d.length;++f)Pa[e++>>
|
|
148
148
|
0]=d.charCodeAt(f);Pa[e>>0]=0;c+=d.length+1});return 0},rb:function(a,b){var c=Oc();A[a>>2]=c.length;var d=0;c.forEach(function(e){d+=e.length+1});A[b>>2]=d;return 0},ub:function(){return 0},eb:function(){},sb:function(a,b,c,d){for(var e=0,f=0;f<c;f++){var g=A[b>>2],h=A[b+4>>2];b+=8;for(var n=0;n<h;n++){var p=x[g+n],r=Qc[a];0===p||10===p?((1===a?ua:va)(Ba(r,0)),r.length=0):r.push(p)}e+=h}A[d>>2]=e;return 0},b:function(){return wa},bb:function(a,b){t.bindFramebuffer(a,tc[b])},x:function(a,b){Fc(a,
|
|
149
|
-
b)},n:cd,h:dd,o:ed,s:fd,hb:gd,ib:hd,q:jd,j:kd,d:ld,p:md,i:nd,kb:od,gb:pd,lb:qd,c:function(a){wa=a},
|
|
149
|
+
b)},n:cd,h:dd,o:ed,s:fd,hb:gd,ib:hd,q:jd,j:kd,d:ld,p:md,i:nd,kb:od,gb:pd,lb:qd,c:function(a){wa=a},pb:function(a,b,c,d){return Wc(a,b,c,d)}};
|
|
150
150
|
(function(){function a(e){k.asm=e.exports;ya=k.asm.Hc;Ra();Sa=k.asm.Rc;Ua.unshift(k.asm.Ic);Xa--;k.monitorRunDependencies&&k.monitorRunDependencies(Xa);0==Xa&&(null!==Ya&&(clearInterval(Ya),Ya=null),Za&&(e=Za,Za=null,e()))}function b(e){a(e.instance)}function c(e){return cb().then(function(f){return WebAssembly.instantiate(f,d)}).then(function(f){return f}).then(e,function(f){va("failed to asynchronously prepare wasm: "+f);ta(f)})}var d={a:rd};Xa++;k.monitorRunDependencies&&k.monitorRunDependencies(Xa);
|
|
151
151
|
if(k.instantiateWasm)try{return k.instantiateWasm(d,a)}catch(e){return va("Module.instantiateWasm callback failed with error: "+e),!1}(function(){return xa||"function"!==typeof WebAssembly.instantiateStreaming||$a()||H.startsWith("file://")||"function"!==typeof fetch?c(b):fetch(H,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,d).then(b,function(f){va("wasm streaming compile failed: "+f);va("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ba);
|
|
152
|
-
return{}})();k.___wasm_call_ctors=function(){return(k.___wasm_call_ctors=k.asm.Ic).apply(null,arguments)};var Hc=k._malloc=function(){return(Hc=k._malloc=k.asm.Jc).apply(null,arguments)},
|
|
152
|
+
return{}})();k.___wasm_call_ctors=function(){return(k.___wasm_call_ctors=k.asm.Ic).apply(null,arguments)};var Hc=k._malloc=function(){return(Hc=k._malloc=k.asm.Jc).apply(null,arguments)},bd=k.___errno_location=function(){return(bd=k.___errno_location=k.asm.Kc).apply(null,arguments)},Vb=k._free=function(){return(Vb=k._free=k.asm.Lc).apply(null,arguments)},Ub=k.___getTypeName=function(){return(Ub=k.___getTypeName=k.asm.Mc).apply(null,arguments)};
|
|
153
153
|
k.___embind_register_native_and_builtin_types=function(){return(k.___embind_register_native_and_builtin_types=k.asm.Nc).apply(null,arguments)};var W=k.stackSave=function(){return(W=k.stackSave=k.asm.Oc).apply(null,arguments)},X=k.stackRestore=function(){return(X=k.stackRestore=k.asm.Pc).apply(null,arguments)},Z=k._setThrew=function(){return(Z=k._setThrew=k.asm.Qc).apply(null,arguments)};k.dynCall_iiiij=function(){return(k.dynCall_iiiij=k.asm.Sc).apply(null,arguments)};
|
|
154
154
|
k.dynCall_viiij=function(){return(k.dynCall_viiij=k.asm.Tc).apply(null,arguments)};k.dynCall_iiij=function(){return(k.dynCall_iiij=k.asm.Uc).apply(null,arguments)};k.dynCall_viij=function(){return(k.dynCall_viij=k.asm.Vc).apply(null,arguments)};k.dynCall_jiiiiji=function(){return(k.dynCall_jiiiiji=k.asm.Wc).apply(null,arguments)};k.dynCall_jiiiiii=function(){return(k.dynCall_jiiiiii=k.asm.Xc).apply(null,arguments)};k.dynCall_viiiiij=function(){return(k.dynCall_viiiiij=k.asm.Yc).apply(null,arguments)};
|
|
155
155
|
k.dynCall_jii=function(){return(k.dynCall_jii=k.asm.Zc).apply(null,arguments)};k.dynCall_viji=function(){return(k.dynCall_viji=k.asm._c).apply(null,arguments)};k.dynCall_ji=function(){return(k.dynCall_ji=k.asm.$c).apply(null,arguments)};k.dynCall_iij=function(){return(k.dynCall_iij=k.asm.ad).apply(null,arguments)};k.dynCall_vij=function(){return(k.dynCall_vij=k.asm.bd).apply(null,arguments)};k.dynCall_iijj=function(){return(k.dynCall_iijj=k.asm.cd).apply(null,arguments)};
|
|
@@ -172,7 +172,7 @@ k.run=ud;if(k.preInit)for("function"==typeof k.preInit&&(k.preInit=[k.preInit]);
|
|
|
172
172
|
/* 2 */
|
|
173
173
|
/***/ ((module) => {
|
|
174
174
|
|
|
175
|
-
module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"1.0.
|
|
175
|
+
module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"1.0.73","description":"Rive\'s webgl 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.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
176
176
|
|
|
177
177
|
/***/ }),
|
|
178
178
|
/* 3 */
|
|
@@ -208,56 +208,69 @@ const registerTouchInteractions = ({
|
|
|
208
208
|
alignment,
|
|
209
209
|
}) => {
|
|
210
210
|
if (!canvas || !stateMachines.length || !renderer || !rive || !artboard) {
|
|
211
|
-
return;
|
|
211
|
+
return null;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
const mouseCallback = (event) => {
|
|
215
|
+
const boundingRect = event.currentTarget.getBoundingClientRect();
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
const canvasX = event.clientX - boundingRect.left;
|
|
218
|
+
const canvasY = event.clientY - boundingRect.top;
|
|
219
|
+
const forwardMatrix = rive.computeAlignment(
|
|
220
|
+
fit,
|
|
221
|
+
alignment,
|
|
222
|
+
{
|
|
220
223
|
minX: 0,
|
|
221
224
|
minY: 0,
|
|
222
225
|
maxX: boundingRect.width,
|
|
223
226
|
maxY: boundingRect.height,
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
},
|
|
228
|
+
artboard.bounds
|
|
229
|
+
);
|
|
230
|
+
let invertedMatrix = new rive.Mat2D();
|
|
231
|
+
forwardMatrix.invert(invertedMatrix);
|
|
232
|
+
const canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
|
|
233
|
+
const transformedVector = rive.mapXY(
|
|
234
|
+
invertedMatrix,
|
|
235
|
+
canvasCoordinatesVector
|
|
236
|
+
);
|
|
237
|
+
const transformedX = transformedVector.x();
|
|
238
|
+
const transformedY = transformedVector.y();
|
|
231
239
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
break;
|
|
240
|
+
switch (event.type) {
|
|
241
|
+
// Pointer moving/hovering on the canvas
|
|
242
|
+
case 'mousemove': {
|
|
243
|
+
for (const stateMachine of stateMachines) {
|
|
244
|
+
stateMachine.pointerMove(transformedX, transformedY);
|
|
239
245
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
// Pointer click initiated but not released yet on the canvas
|
|
249
|
+
case 'mousedown': {
|
|
250
|
+
for (const stateMachine of stateMachines) {
|
|
251
|
+
stateMachine.pointerDown(transformedX, transformedY);
|
|
246
252
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
// Pointer click released on the canvas
|
|
256
|
+
case 'mouseup': {
|
|
257
|
+
for (const stateMachine of stateMachines) {
|
|
258
|
+
stateMachine.pointerUp(transformedX, transformedY);
|
|
253
259
|
}
|
|
254
|
-
|
|
260
|
+
break;
|
|
255
261
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
262
|
+
default:
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const callback = mouseCallback.bind(undefined);
|
|
266
|
+
canvas.addEventListener('mousemove', callback);
|
|
267
|
+
canvas.addEventListener('mousedown', callback);
|
|
268
|
+
canvas.addEventListener('mouseup', callback);
|
|
269
|
+
return () => {
|
|
270
|
+
canvas.removeEventListener('mousemove', callback);
|
|
271
|
+
canvas.removeEventListener('mousedown', callback);
|
|
272
|
+
canvas.removeEventListener('mouseup', callback);
|
|
273
|
+
};
|
|
261
274
|
};
|
|
262
275
|
|
|
263
276
|
|
|
@@ -437,7 +450,7 @@ var Layout = /** @class */ (function () {
|
|
|
437
450
|
minX: minX !== null && minX !== void 0 ? minX : this.minX,
|
|
438
451
|
minY: minY !== null && minY !== void 0 ? minY : this.minY,
|
|
439
452
|
maxX: maxX !== null && maxX !== void 0 ? maxX : this.maxX,
|
|
440
|
-
maxY: maxY !== null && maxY !== void 0 ? maxY : this.maxY
|
|
453
|
+
maxY: maxY !== null && maxY !== void 0 ? maxY : this.maxY,
|
|
441
454
|
});
|
|
442
455
|
};
|
|
443
456
|
// Returns fit for the Wasm runtime format
|
|
@@ -501,7 +514,7 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
501
514
|
RuntimeLoader.loadRuntime = function () {
|
|
502
515
|
_rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__.default({
|
|
503
516
|
// Loads Wasm bundle
|
|
504
|
-
locateFile: function (_) { return RuntimeLoader.wasmURL; }
|
|
517
|
+
locateFile: function (_) { return RuntimeLoader.wasmURL; },
|
|
505
518
|
}).then(function (rive) {
|
|
506
519
|
var _a;
|
|
507
520
|
RuntimeLoader.runtime = rive;
|
|
@@ -802,8 +815,8 @@ var Animator = /** @class */ (function () {
|
|
|
802
815
|
animatables = mapToStringArray(animatables);
|
|
803
816
|
// If animatables is empty, play or pause everything
|
|
804
817
|
if (animatables.length === 0) {
|
|
805
|
-
this.animations.forEach(function (a) { return a.playing = playing; });
|
|
806
|
-
this.stateMachines.forEach(function (m) { return m.playing = playing; });
|
|
818
|
+
this.animations.forEach(function (a) { return (a.playing = playing); });
|
|
819
|
+
this.stateMachines.forEach(function (m) { return (m.playing = playing); });
|
|
807
820
|
}
|
|
808
821
|
else {
|
|
809
822
|
// Play/pause already instanced items, or create new instances
|
|
@@ -869,11 +882,11 @@ var Animator = /** @class */ (function () {
|
|
|
869
882
|
return this.add(animatables, true);
|
|
870
883
|
};
|
|
871
884
|
/**
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
885
|
+
* Pauses named animations and state machines, or everything if nothing is
|
|
886
|
+
* specified
|
|
887
|
+
* @param animatables names of the animations and state machines to pause
|
|
888
|
+
* @returns a list of names of the animations and state machines paused
|
|
889
|
+
*/
|
|
877
890
|
Animator.prototype.pause = function (animatables) {
|
|
878
891
|
return this.add(animatables, false);
|
|
879
892
|
};
|
|
@@ -884,8 +897,10 @@ var Animator = /** @class */ (function () {
|
|
|
884
897
|
* @returns a list of names of the animations that were scrubbed
|
|
885
898
|
*/
|
|
886
899
|
Animator.prototype.scrub = function (animatables, value) {
|
|
887
|
-
var forScrubbing = this.animations.filter(function (a) {
|
|
888
|
-
|
|
900
|
+
var forScrubbing = this.animations.filter(function (a) {
|
|
901
|
+
return animatables.includes(a.name);
|
|
902
|
+
});
|
|
903
|
+
forScrubbing.forEach(function (a) { return (a.scrubTo = value); });
|
|
889
904
|
return forScrubbing.map(function (a) { return a.name; });
|
|
890
905
|
};
|
|
891
906
|
Object.defineProperty(Animator.prototype, "playing", {
|
|
@@ -894,7 +909,10 @@ var Animator = /** @class */ (function () {
|
|
|
894
909
|
* playing
|
|
895
910
|
*/
|
|
896
911
|
get: function () {
|
|
897
|
-
return this.animations
|
|
912
|
+
return this.animations
|
|
913
|
+
.filter(function (a) { return a.playing; })
|
|
914
|
+
.map(function (a) { return a.name; })
|
|
915
|
+
.concat(this.stateMachines.filter(function (m) { return m.playing; }).map(function (m) { return m.name; }));
|
|
898
916
|
},
|
|
899
917
|
enumerable: false,
|
|
900
918
|
configurable: true
|
|
@@ -905,7 +923,10 @@ var Animator = /** @class */ (function () {
|
|
|
905
923
|
* paused
|
|
906
924
|
*/
|
|
907
925
|
get: function () {
|
|
908
|
-
return this.animations
|
|
926
|
+
return this.animations
|
|
927
|
+
.filter(function (a) { return !a.playing; })
|
|
928
|
+
.map(function (a) { return a.name; })
|
|
929
|
+
.concat(this.stateMachines.filter(function (m) { return !m.playing; }).map(function (m) { return m.name; }));
|
|
909
930
|
},
|
|
910
931
|
enumerable: false,
|
|
911
932
|
configurable: true
|
|
@@ -922,7 +943,9 @@ var Animator = /** @class */ (function () {
|
|
|
922
943
|
var removedNames = [];
|
|
923
944
|
// Stop everything
|
|
924
945
|
if (animatables.length === 0) {
|
|
925
|
-
removedNames = this.animations
|
|
946
|
+
removedNames = this.animations
|
|
947
|
+
.map(function (a) { return a.name; })
|
|
948
|
+
.concat(this.stateMachines.map(function (m) { return m.name; }));
|
|
926
949
|
// Clean up before emptying the arrays
|
|
927
950
|
this.animations.forEach(function (a) { return a.cleanup(); });
|
|
928
951
|
this.stateMachines.forEach(function (m) { return m.cleanup(); });
|
|
@@ -932,17 +955,23 @@ var Animator = /** @class */ (function () {
|
|
|
932
955
|
}
|
|
933
956
|
else {
|
|
934
957
|
// Remove only the named animations/state machines
|
|
935
|
-
var animationsToRemove = this.animations.filter(function (a) {
|
|
958
|
+
var animationsToRemove = this.animations.filter(function (a) {
|
|
959
|
+
return animatables.includes(a.name);
|
|
960
|
+
});
|
|
936
961
|
animationsToRemove.forEach(function (a) {
|
|
937
962
|
a.cleanup();
|
|
938
963
|
_this.animations.splice(_this.animations.indexOf(a), 1);
|
|
939
964
|
});
|
|
940
|
-
var machinesToRemove = this.stateMachines.filter(function (m) {
|
|
965
|
+
var machinesToRemove = this.stateMachines.filter(function (m) {
|
|
966
|
+
return animatables.includes(m.name);
|
|
967
|
+
});
|
|
941
968
|
machinesToRemove.forEach(function (m) {
|
|
942
969
|
m.cleanup();
|
|
943
970
|
_this.stateMachines.splice(_this.stateMachines.indexOf(m), 1);
|
|
944
971
|
});
|
|
945
|
-
removedNames = animationsToRemove
|
|
972
|
+
removedNames = animationsToRemove
|
|
973
|
+
.map(function (a) { return a.name; })
|
|
974
|
+
.concat(machinesToRemove.map(function (m) { return m.name; }));
|
|
946
975
|
}
|
|
947
976
|
this.eventManager.fire({
|
|
948
977
|
type: EventType.Stop,
|
|
@@ -956,8 +985,8 @@ var Animator = /** @class */ (function () {
|
|
|
956
985
|
* Returns true if at least one animation is active
|
|
957
986
|
*/
|
|
958
987
|
get: function () {
|
|
959
|
-
return this.animations.reduce(function (acc, curr) { return acc || curr.playing; }, false)
|
|
960
|
-
|
|
988
|
+
return (this.animations.reduce(function (acc, curr) { return acc || curr.playing; }, false) ||
|
|
989
|
+
this.stateMachines.reduce(function (acc, curr) { return acc || curr.playing; }, false));
|
|
961
990
|
},
|
|
962
991
|
enumerable: false,
|
|
963
992
|
configurable: true
|
|
@@ -967,8 +996,8 @@ var Animator = /** @class */ (function () {
|
|
|
967
996
|
* Returns true if all animations are paused and there's at least one animation
|
|
968
997
|
*/
|
|
969
998
|
get: function () {
|
|
970
|
-
return !this.isPlaying &&
|
|
971
|
-
(this.animations.length > 0 || this.stateMachines.length > 0);
|
|
999
|
+
return (!this.isPlaying &&
|
|
1000
|
+
(this.animations.length > 0 || this.stateMachines.length > 0));
|
|
972
1001
|
},
|
|
973
1002
|
enumerable: false,
|
|
974
1003
|
configurable: true
|
|
@@ -993,11 +1022,11 @@ var Animator = /** @class */ (function () {
|
|
|
993
1022
|
if (this.animations.length === 0 && this.stateMachines.length === 0) {
|
|
994
1023
|
if (this.artboard.animationCount() > 0) {
|
|
995
1024
|
// Add the first animation
|
|
996
|
-
this.add([instancedName = this.artboard.animationByIndex(0).name], playing, fireEvent);
|
|
1025
|
+
this.add([(instancedName = this.artboard.animationByIndex(0).name)], playing, fireEvent);
|
|
997
1026
|
}
|
|
998
1027
|
else if (this.artboard.stateMachineCount() > 0) {
|
|
999
1028
|
// Add the first state machine
|
|
1000
|
-
this.add([instancedName = this.artboard.stateMachineByIndex(0).name], playing, fireEvent);
|
|
1029
|
+
this.add([(instancedName = this.artboard.stateMachineByIndex(0).name)], playing, fireEvent);
|
|
1001
1030
|
}
|
|
1002
1031
|
}
|
|
1003
1032
|
return instancedName;
|
|
@@ -1017,7 +1046,7 @@ var Animator = /** @class */ (function () {
|
|
|
1017
1046
|
else if (animation.loopValue === 1 && animation.loopCount) {
|
|
1018
1047
|
this.eventManager.fire({
|
|
1019
1048
|
type: EventType.Loop,
|
|
1020
|
-
data: { animation: animation.name, type: LoopType.Loop }
|
|
1049
|
+
data: { animation: animation.name, type: LoopType.Loop },
|
|
1021
1050
|
});
|
|
1022
1051
|
animation.loopCount = 0;
|
|
1023
1052
|
}
|
|
@@ -1027,7 +1056,7 @@ var Animator = /** @class */ (function () {
|
|
|
1027
1056
|
else if (animation.loopValue === 2 && animation.loopCount > 1) {
|
|
1028
1057
|
this.eventManager.fire({
|
|
1029
1058
|
type: EventType.Loop,
|
|
1030
|
-
data: { animation: animation.name, type: LoopType.PingPong }
|
|
1059
|
+
data: { animation: animation.name, type: LoopType.PingPong },
|
|
1031
1060
|
});
|
|
1032
1061
|
animation.loopCount = 0;
|
|
1033
1062
|
}
|
|
@@ -1075,7 +1104,7 @@ var LoopType;
|
|
|
1075
1104
|
(function (LoopType) {
|
|
1076
1105
|
LoopType["OneShot"] = "oneshot";
|
|
1077
1106
|
LoopType["Loop"] = "loop";
|
|
1078
|
-
LoopType["PingPong"] = "pingpong";
|
|
1107
|
+
LoopType["PingPong"] = "pingpong";
|
|
1079
1108
|
})(LoopType || (LoopType = {}));
|
|
1080
1109
|
// Manages Rive events and listeners
|
|
1081
1110
|
var EventManager = /** @class */ (function () {
|
|
@@ -1179,6 +1208,8 @@ var Rive = /** @class */ (function () {
|
|
|
1179
1208
|
this.readyForPlaying = false;
|
|
1180
1209
|
// Runtime artboard
|
|
1181
1210
|
this.artboard = null;
|
|
1211
|
+
// place to clear up event listeners
|
|
1212
|
+
this.eventCleanup = null;
|
|
1182
1213
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
1183
1214
|
this.durations = [];
|
|
1184
1215
|
this.frameTimes = [];
|
|
@@ -1259,7 +1290,8 @@ var Rive = /** @class */ (function () {
|
|
|
1259
1290
|
this.loaded = false;
|
|
1260
1291
|
this.readyForPlaying = false;
|
|
1261
1292
|
// Ensure the runtime is loaded
|
|
1262
|
-
RuntimeLoader.awaitInstance()
|
|
1293
|
+
RuntimeLoader.awaitInstance()
|
|
1294
|
+
.then(function (runtime) {
|
|
1263
1295
|
_this.runtime = runtime;
|
|
1264
1296
|
// Get the canvas where you want to render the animation and create a renderer
|
|
1265
1297
|
_this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
|
|
@@ -1273,7 +1305,7 @@ var Rive = /** @class */ (function () {
|
|
|
1273
1305
|
var activeStateMachineInstances = (_this.animator.stateMachines || [])
|
|
1274
1306
|
.filter(function (sm) { return sm.playing; })
|
|
1275
1307
|
.map(function (sm) { return sm.instance; });
|
|
1276
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
|
|
1308
|
+
_this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
|
|
1277
1309
|
canvas: _this.canvas,
|
|
1278
1310
|
artboard: _this.artboard,
|
|
1279
1311
|
stateMachines: activeStateMachineInstances,
|
|
@@ -1286,7 +1318,8 @@ var Rive = /** @class */ (function () {
|
|
|
1286
1318
|
.catch(function (e) {
|
|
1287
1319
|
console.error(e);
|
|
1288
1320
|
});
|
|
1289
|
-
})
|
|
1321
|
+
})
|
|
1322
|
+
.catch(function (e) {
|
|
1290
1323
|
console.error(e);
|
|
1291
1324
|
});
|
|
1292
1325
|
};
|
|
@@ -1318,7 +1351,7 @@ var Rive = /** @class */ (function () {
|
|
|
1318
1351
|
this.loaded = true;
|
|
1319
1352
|
this.eventManager.fire({
|
|
1320
1353
|
type: EventType.Load,
|
|
1321
|
-
data: (_a = this.src) !== null && _a !== void 0 ? _a : 'buffer'
|
|
1354
|
+
data: (_a = this.src) !== null && _a !== void 0 ? _a : 'buffer',
|
|
1322
1355
|
});
|
|
1323
1356
|
// Flag ready for playback commands and clear the task queue; this order
|
|
1324
1357
|
// is important or it may infinitely recurse
|
|
@@ -1341,9 +1374,9 @@ var Rive = /** @class */ (function () {
|
|
|
1341
1374
|
// Initialize for playback
|
|
1342
1375
|
Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
1343
1376
|
// Fetch the artboard
|
|
1344
|
-
var rootArtboard = artboardName
|
|
1345
|
-
this.file.artboardByName(artboardName)
|
|
1346
|
-
this.file.defaultArtboard();
|
|
1377
|
+
var rootArtboard = artboardName
|
|
1378
|
+
? this.file.artboardByName(artboardName)
|
|
1379
|
+
: this.file.defaultArtboard();
|
|
1347
1380
|
// Check we have a working artboard
|
|
1348
1381
|
if (!rootArtboard) {
|
|
1349
1382
|
var msg = 'Invalid artboard name or no default artboard';
|
|
@@ -1378,7 +1411,7 @@ var Rive = /** @class */ (function () {
|
|
|
1378
1411
|
event: {
|
|
1379
1412
|
type: autoplay ? EventType.Play : EventType.Pause,
|
|
1380
1413
|
data: instanceNames,
|
|
1381
|
-
}
|
|
1414
|
+
},
|
|
1382
1415
|
});
|
|
1383
1416
|
};
|
|
1384
1417
|
// Draws the current artboard frame
|
|
@@ -1398,7 +1431,7 @@ var Rive = /** @class */ (function () {
|
|
|
1398
1431
|
this.lastRenderTime = time;
|
|
1399
1432
|
}
|
|
1400
1433
|
// Handle the onSecond callback
|
|
1401
|
-
this.renderSecondTimer +=
|
|
1434
|
+
this.renderSecondTimer += time - this.lastRenderTime;
|
|
1402
1435
|
if (this.renderSecondTimer > 5000) {
|
|
1403
1436
|
this.renderSecondTimer = 0;
|
|
1404
1437
|
onSecond === null || onSecond === void 0 ? void 0 : onSecond();
|
|
@@ -1409,10 +1442,11 @@ var Rive = /** @class */ (function () {
|
|
|
1409
1442
|
// - Advance non-paused animations by the elapsed number of seconds
|
|
1410
1443
|
// - Advance any animations that require scrubbing
|
|
1411
1444
|
// - Advance to the first frame even when autoplay is false
|
|
1412
|
-
var activeAnimations = this.animator.animations
|
|
1445
|
+
var activeAnimations = this.animator.animations
|
|
1446
|
+
.filter(function (a) { return a.playing || a.needsScrub; })
|
|
1413
1447
|
// The scrubbed animations must be applied first to prevent weird artifacts
|
|
1414
1448
|
// if the playing animations conflict with the scrubbed animating attribuates.
|
|
1415
|
-
.sort(function (first, second) { return first.needsScrub ? -1 : 1; });
|
|
1449
|
+
.sort(function (first, second) { return (first.needsScrub ? -1 : 1); });
|
|
1416
1450
|
for (var _i = 0, activeAnimations_1 = activeAnimations; _i < activeAnimations_1.length; _i++) {
|
|
1417
1451
|
var animation = activeAnimations_1[_i];
|
|
1418
1452
|
animation.advance(elapsedTime);
|
|
@@ -1482,7 +1516,7 @@ var Rive = /** @class */ (function () {
|
|
|
1482
1516
|
minX: _layout.minX,
|
|
1483
1517
|
minY: _layout.minY,
|
|
1484
1518
|
maxX: _layout.maxX,
|
|
1485
|
-
maxY: _layout.maxY
|
|
1519
|
+
maxY: _layout.maxY,
|
|
1486
1520
|
}, artboard.bounds);
|
|
1487
1521
|
};
|
|
1488
1522
|
Object.defineProperty(Rive.prototype, "fps", {
|
|
@@ -1510,6 +1544,9 @@ var Rive = /** @class */ (function () {
|
|
|
1510
1544
|
* might happen.
|
|
1511
1545
|
*/
|
|
1512
1546
|
Rive.prototype.cleanup = function () {
|
|
1547
|
+
if (this.eventCleanup !== null) {
|
|
1548
|
+
this.eventCleanup();
|
|
1549
|
+
}
|
|
1513
1550
|
this.artboard.delete();
|
|
1514
1551
|
// TODO: delete animation and state machine instances
|
|
1515
1552
|
};
|
|
@@ -1588,6 +1625,7 @@ var Rive = /** @class */ (function () {
|
|
|
1588
1625
|
this.cleanup();
|
|
1589
1626
|
// Reinitialize an artboard instance with the state
|
|
1590
1627
|
this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay);
|
|
1628
|
+
this.taskQueue.process();
|
|
1591
1629
|
};
|
|
1592
1630
|
// Loads a new Rive file, keeping listeners in place
|
|
1593
1631
|
Rive.prototype.load = function (params) {
|
|
@@ -1628,7 +1666,7 @@ var Rive = /** @class */ (function () {
|
|
|
1628
1666
|
minX: 0,
|
|
1629
1667
|
minY: 0,
|
|
1630
1668
|
maxX: this.canvas.width,
|
|
1631
|
-
maxY: this.canvas.height
|
|
1669
|
+
maxY: this.canvas.height,
|
|
1632
1670
|
});
|
|
1633
1671
|
};
|
|
1634
1672
|
/**
|
|
@@ -1734,9 +1772,7 @@ var Rive = /** @class */ (function () {
|
|
|
1734
1772
|
if (!this.loaded) {
|
|
1735
1773
|
return [];
|
|
1736
1774
|
}
|
|
1737
|
-
return this.animator.animations
|
|
1738
|
-
.filter(function (a) { return a.playing; })
|
|
1739
|
-
.map(function (a) { return a.name; });
|
|
1775
|
+
return this.animator.animations.filter(function (a) { return a.playing; }).map(function (a) { return a.name; });
|
|
1740
1776
|
},
|
|
1741
1777
|
enumerable: false,
|
|
1742
1778
|
configurable: true
|
|
@@ -1922,7 +1958,10 @@ var Rive = /** @class */ (function () {
|
|
|
1922
1958
|
var input = instance.input(l);
|
|
1923
1959
|
inputContents.push({ name: input.name, type: input.type });
|
|
1924
1960
|
}
|
|
1925
|
-
artboardContents.stateMachines.push({
|
|
1961
|
+
artboardContents.stateMachines.push({
|
|
1962
|
+
name: name_1,
|
|
1963
|
+
inputs: inputContents,
|
|
1964
|
+
});
|
|
1926
1965
|
}
|
|
1927
1966
|
riveContents.artboards.push(artboardContents);
|
|
1928
1967
|
}
|