@rive-app/webgl 2.3.1 → 2.4.0
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 +21 -2
- package/rive.js +62 -5
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +65 -0
package/package.json
CHANGED
package/rive.d.ts
CHANGED
|
@@ -95,6 +95,10 @@ export declare class StateMachineInput {
|
|
|
95
95
|
*/
|
|
96
96
|
fire(): void;
|
|
97
97
|
}
|
|
98
|
+
export declare enum RiveEventType {
|
|
99
|
+
General = 128,
|
|
100
|
+
OpenUrl = 131
|
|
101
|
+
}
|
|
98
102
|
/**
|
|
99
103
|
* Supported event types triggered in Rive
|
|
100
104
|
*/
|
|
@@ -107,11 +111,13 @@ export declare enum EventType {
|
|
|
107
111
|
Loop = "loop",
|
|
108
112
|
Draw = "draw",
|
|
109
113
|
Advance = "advance",
|
|
110
|
-
StateChange = "statechange"
|
|
114
|
+
StateChange = "statechange",
|
|
115
|
+
RiveEvent = "riveevent"
|
|
111
116
|
}
|
|
117
|
+
export type RiveEventPayload = rc.RiveEvent | rc.OpenUrlEvent;
|
|
112
118
|
export interface Event {
|
|
113
119
|
type: EventType;
|
|
114
|
-
data?: string | string[] | LoopEvent | number;
|
|
120
|
+
data?: string | string[] | LoopEvent | number | RiveEventPayload;
|
|
115
121
|
}
|
|
116
122
|
/**
|
|
117
123
|
* Looping types: one-shot, loop, and ping-pong
|
|
@@ -189,6 +195,18 @@ export interface RiveParameters {
|
|
|
189
195
|
* will be attached to the <canvas> element
|
|
190
196
|
*/
|
|
191
197
|
shouldDisableRiveListeners?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Enable Rive Events to be handled by the runtime. This means any special Rive Event may have
|
|
200
|
+
* a side effect that takes place implicitly.
|
|
201
|
+
*
|
|
202
|
+
* For example, if during the render loop an OpenUrlEvent is detected, the
|
|
203
|
+
* browser may try to open the specified URL in the payload.
|
|
204
|
+
*
|
|
205
|
+
* This flag is false by default to prevent any unwanted behaviors from taking place.
|
|
206
|
+
* This means any special Rive Event will have to be handled manually by subscribing to
|
|
207
|
+
* EventType.RiveEvent
|
|
208
|
+
*/
|
|
209
|
+
automaticallyHandleEvents?: boolean;
|
|
192
210
|
onLoad?: EventCallback;
|
|
193
211
|
onLoadError?: EventCallback;
|
|
194
212
|
onPlay?: EventCallback;
|
|
@@ -266,6 +284,7 @@ export declare class Rive {
|
|
|
266
284
|
private animator;
|
|
267
285
|
private static readonly missingErrorMessage;
|
|
268
286
|
private shouldDisableRiveListeners;
|
|
287
|
+
private automaticallyHandleEvents;
|
|
269
288
|
durations: number[];
|
|
270
289
|
frameTimes: number[];
|
|
271
290
|
frameCount: number;
|
package/rive.js
CHANGED
|
@@ -96,7 +96,7 @@ O.prototype.fromWireType=function(a){function b(){return this.Jd?lb(this.fd.td,{
|
|
|
96
96
|
Object.assign(Jb.prototype,{get(a){return this.rd[a]},has(a){return void 0!==this.rd[a]},we(a){var b=this.de.pop()||this.rd.length;this.rd[b]=a;return b},ze(a){this.rd[a]=void 0;this.de.push(a)}});Q.rd.push({value:void 0},{value:null},{value:!0},{value:!1});Q.be=Q.rd.length;k.count_emval_handles=function(){for(var a=0,b=Q.be;b<Q.rd.length;++b)void 0!==Q.rd[b]&&++a;return a};for(var t,V=0;32>V;++V)yc.push(Array(V));var Wc=new Float32Array(288);for(V=0;288>V;++V)Jc[V]=Wc.subarray(0,V+1);var Xc=new Int32Array(288);
|
|
97
97
|
for(V=0;288>V;++V)Kc[V]=Xc.subarray(0,V+1);
|
|
98
98
|
var ld={sb:function(a){var b=Oa[a];delete Oa[a];var c=b.Td,d=b.sd,e=b.ce,f=e.map(g=>g.Ee).concat(e.map(g=>g.Me));K([a],f,g=>{var h={};e.forEach((m,p)=>{var r=g[p],v=m.Ce,z=m.De,l=g[p+e.length],q=m.Le,u=m.Ne;h[m.xe]={read:x=>r.fromWireType(v(z,x)),write:(x,E)=>{var B=[];q(u,x,l.toWireType(B,E));Pa(B)}}});return[{name:b.name,fromWireType:function(m){var p={},r;for(r in h)p[r]=h[r].read(m);d(m);return p},toWireType:function(m,p){for(var r in h)if(!(r in p))throw new TypeError(`Missing field: "${r}"`);var v=
|
|
99
|
-
c();for(r in h)h[r].write(v,p[r]);null!==m&&m.push(d,v);return v},argPackAdvance:8,readValueFromPointer:Qa,nd:d}]})},db:function(){},ub:function(a,b,c,d,e){var f=Wa(c);b=M(b);L(a,{name:b,fromWireType:function(g){return!!g},toWireType:function(g,h){return h?d:e},argPackAdvance:8,readValueFromPointer:function(g){if(1===c)var h=ua;else if(2===c)h=va;else if(4===c)h=C;else throw new TypeError("Unknown boolean type size: "+b);return this.fromWireType(h[g>>f])},nd:null})},
|
|
99
|
+
c();for(r in h)h[r].write(v,p[r]);null!==m&&m.push(d,v);return v},argPackAdvance:8,readValueFromPointer:Qa,nd:d}]})},db:function(){},ub:function(a,b,c,d,e){var f=Wa(c);b=M(b);L(a,{name:b,fromWireType:function(g){return!!g},toWireType:function(g,h){return h?d:e},argPackAdvance:8,readValueFromPointer:function(g){if(1===c)var h=ua;else if(2===c)h=va;else if(4===c)h=C;else throw new TypeError("Unknown boolean type size: "+b);return this.fromWireType(h[g>>f])},nd:null})},h:function(a,b,c,d,e,f,g,h,m,p,
|
|
100
100
|
r,v,z){r=M(r);f=P(e,f);h&&(h=P(g,h));p&&(p=P(m,p));z=P(v,z);var l=ob(r);rb(l,function(){Fb(`Cannot construct ${r} due to unbound types`,[d])});K([a,b,c],d?[d]:[],function(q){q=q[0];if(d){var u=q.fd;var x=u.td}else x=nb.prototype;q=pb(l,function(){if(Object.getPrototypeOf(this)!==E)throw new Ya("Use 'new' to construct "+r);if(void 0===B.ud)throw new Ya(r+" has no accessible constructor");var J=B.ud[arguments.length];if(void 0===J)throw new Ya(`Tried to invoke ctor of ${r} with invalid number of parameters (${arguments.length}) - expected (${Object.keys(B.ud).toString()}) parameters instead!`);
|
|
101
101
|
return J.apply(this,arguments)});var E=Object.create(x,{constructor:{value:q}});q.prototype=E;var B=new sb(r,q,E,z,u,f,h,p);B.jd&&(void 0===B.jd.Wd&&(B.jd.Wd=[]),B.jd.Wd.push(B));u=new O(r,B,!0,!1);x=new O(r+"*",B,!1,!1);var F=new O(r+" const*",B,!1,!0);fb[a]={pointerType:x,pe:F};zb(l,q);return[u,x,F]})},y:function(a,b,c,d,e,f,g,h){b=M(b);f=P(e,f);K([],[a],function(m){m=m[0];var p=`${m.name}.${b}`,r={get(){Fb(`Cannot access ${p} due to unbound types`,[c])},enumerable:!0,configurable:!0};r.set=h?()=>
|
|
102
102
|
{Fb(`Cannot access ${p} due to unbound types`,[c])}:()=>{N(`${p} is a read-only property`)};Object.defineProperty(m.fd.constructor,b,r);K([],[c],function(v){v=v[0];var z={get(){return v.fromWireType(f(d))},enumerable:!0};h&&(h=P(g,h),z.set=l=>{var q=[];h(d,v.toWireType(q,l));Pa(q)});Object.defineProperty(m.fd.constructor,b,z);return[]});return[]})},r:function(a,b,c,d,e,f){var g=Hb(b,c);e=P(d,e);K([],[a],function(h){h=h[0];var m=`constructor ${h.name}`;void 0===h.fd.ud&&(h.fd.ud=[]);if(void 0!==h.fd.ud[b-
|
|
@@ -104,13 +104,13 @@ return J.apply(this,arguments)});var E=Object.create(x,{constructor:{value:q}});
|
|
|
104
104
|
m)}p=p[0];var v=`${p.name}.${b}`;b.startsWith("@@")&&(b=Symbol[b.substring(2)]);h&&p.fd.Je.push(b);var z=p.fd.td,l=z[b];void 0===l||void 0===l.kd&&l.className!==p.name&&l.Hd===c-2?(r.Hd=c-2,r.className=p.name,z[b]=r):(qb(z,b,v),z[b].kd[c-2]=r);K([],m,function(q){q=Ib(v,q,p,f,g);void 0===z[b].kd?(q.Hd=c-2,z[b]=q):z[b].kd[c-2]=q;return[]});return[]})},f:function(a,b,c,d,e,f,g,h,m,p){b=M(b);e=P(d,e);K([],[a],function(r){r=r[0];var v=`${r.name}.${b}`,z={get(){Fb(`Cannot access ${v} due to unbound types`,
|
|
105
105
|
[c,g])},enumerable:!0,configurable:!0};z.set=m?()=>{Fb(`Cannot access ${v} due to unbound types`,[c,g])}:()=>{N(v+" is a read-only property")};Object.defineProperty(r.fd.td,b,z);K([],m?[c,g]:[c],function(l){var q=l[0],u={get(){var E=Gb(this,r,v+" getter");return q.fromWireType(e(f,E))},enumerable:!0};if(m){m=P(h,m);var x=l[1];u.set=function(E){var B=Gb(this,r,v+" setter"),F=[];m(p,B,x.toWireType(F,E));Pa(F)}}Object.defineProperty(r.fd.td,b,u);return[]});return[]})},tb:function(a,b){b=M(b);L(a,{name:b,
|
|
106
106
|
fromWireType:function(c){var d=Lb(c);Kb(c);return d},toWireType:function(c,d){return xb(d)},argPackAdvance:8,readValueFromPointer:Qa,nd:null})},F:function(a,b,c,d){function e(){}c=Wa(c);b=M(b);e.values={};L(a,{name:b,constructor:e,fromWireType:function(f){return this.constructor.values[f]},toWireType:function(f,g){return g.value},argPackAdvance:8,readValueFromPointer:Mb(b,c,d),nd:null});rb(b,e)},k:function(a,b,c){var d=Nb(a,"enum");b=M(b);a=d.constructor;d=Object.create(d.constructor.prototype,{value:{value:c},
|
|
107
|
-
constructor:{value:pb(`${d.name}_${b}`,function(){})}});a.values[c]=d;a[b]=d},D:function(a,b,c){c=Wa(c);b=M(b);L(a,{name:b,fromWireType:function(d){return d},toWireType:function(d,e){return e},argPackAdvance:8,readValueFromPointer:Ob(b,c),nd:null})},s:function(a,b,c,d,e,f){var g=Hb(b,c);a=M(a);e=P(d,e);rb(a,function(){Fb(`Cannot call ${a} due to unbound types`,g)},b-1);K([],g,function(h){zb(a,Ib(a,[h[0],null].concat(h.slice(1)),null,e,f),b-1);return[]})},
|
|
107
|
+
constructor:{value:pb(`${d.name}_${b}`,function(){})}});a.values[c]=d;a[b]=d},D:function(a,b,c){c=Wa(c);b=M(b);L(a,{name:b,fromWireType:function(d){return d},toWireType:function(d,e){return e},argPackAdvance:8,readValueFromPointer:Ob(b,c),nd:null})},s:function(a,b,c,d,e,f){var g=Hb(b,c);a=M(a);e=P(d,e);rb(a,function(){Fb(`Cannot call ${a} due to unbound types`,g)},b-1);K([],g,function(h){zb(a,Ib(a,[h[0],null].concat(h.slice(1)),null,e,f),b-1);return[]})},o:function(a,b,c,d,e){b=M(b);-1===e&&(e=4294967295);
|
|
108
108
|
e=Wa(c);var f=h=>h;if(0===d){var g=32-8*c;f=h=>h<<g>>>g}c=b.includes("unsigned")?function(h,m){return m>>>0}:function(h,m){return m};L(a,{name:b,fromWireType:f,toWireType:c,argPackAdvance:8,readValueFromPointer:Pb(b,e,0!==d),nd:null})},j:function(a,b,c){function d(f){f>>=2;var g=D;return new e(g.buffer,g[f+1],g[f])}var e=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][b];c=M(c);L(a,{name:c,fromWireType:d,argPackAdvance:8,readValueFromPointer:d},{Fe:!0})},
|
|
109
109
|
E:function(a,b){b=M(b);var c="std::string"===b;L(a,{name:b,fromWireType:function(d){var e=D[d>>2],f=d+4;if(c)for(var g=f,h=0;h<=e;++h){var m=f+h;if(h==e||0==A[m]){g=g?Tb(A,g,m-g):"";if(void 0===p)var p=g;else p+=String.fromCharCode(0),p+=g;g=m+1}}else{p=Array(e);for(h=0;h<e;++h)p[h]=String.fromCharCode(A[f+h]);p=p.join("")}Eb(d);return p},toWireType:function(d,e){e instanceof ArrayBuffer&&(e=new Uint8Array(e));var f="string"==typeof e;f||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof
|
|
110
110
|
Int8Array||N("Cannot pass non-string to std::string");var g=c&&f?Rb(e):e.length;var h=Ec(4+g+1),m=h+4;D[h>>2]=g;if(c&&f)Qb(e,A,m,g+1);else if(f)for(f=0;f<g;++f){var p=e.charCodeAt(f);255<p&&(Eb(m),N("String has UTF-16 code units that do not fit in 8 bits"));A[m+f]=p}else for(f=0;f<g;++f)A[m+f]=e[f];null!==d&&d.push(Eb,h);return h},argPackAdvance:8,readValueFromPointer:Qa,nd:function(d){Eb(d)}})},x:function(a,b,c){c=M(c);if(2===b){var d=Vb;var e=Wb;var f=Xb;var g=()=>wa;var h=1}else 4===b&&(d=Yb,e=
|
|
111
111
|
Zb,f=$b,g=()=>D,h=2);L(a,{name:c,fromWireType:function(m){for(var p=D[m>>2],r=g(),v,z=m+4,l=0;l<=p;++l){var q=m+4+l*b;if(l==p||0==r[q>>h])z=d(z,q-z),void 0===v?v=z:(v+=String.fromCharCode(0),v+=z),z=q+b}Eb(m);return v},toWireType:function(m,p){"string"!=typeof p&&N(`Cannot pass non-string to C++ string type ${c}`);var r=f(p),v=Ec(4+r+b);D[v>>2]=r>>h;e(p,v+4,r+b);null!==m&&m.push(Eb,v);return v},argPackAdvance:8,readValueFromPointer:Qa,nd:function(m){Eb(m)}})},Kb:function(a,b,c,d,e,f){Oa[a]={name:M(b),
|
|
112
|
-
Td:P(c,d),sd:P(e,f),ce:[]}},zb:function(a,b,c,d,e,f,g,h,m,p){Oa[a].ce.push({xe:M(b),Ee:c,Ce:P(d,e),De:f,Me:g,Le:P(h,m),Ne:p})},vb:function(a,b){b=M(b);L(a,{He:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},mb:()=>!0,ib:()=>{throw Infinity;},gb:function(a,b,c){a=Lb(a);b=Nb(b,"emval::as");var d=[],e=xb(d);D[c>>2]=e;return b.toWireType(d,a)},ab:function(a,b,c,d){a=cc[a];b=Lb(b);c=bc(c);a(b,c,null,d)},
|
|
113
|
-
"$";var e=fc[b];if(void 0!==e)return e;var f=Array(a-1);e=dc((g,h,m,p)=>{for(var r=0,v=0;v<a-1;++v)f[v]=c[v+1].readValueFromPointer(p+r),r+=c[v+1].argPackAdvance;g=g[h].apply(g,f);for(v=0;v<a-1;++v)c[v+1].se&&c[v+1].se(f[v]);if(!d.He)return d.toWireType(m,g)});return fc[b]=e},jb:function(a,b){a=Lb(a);b=Lb(b);return xb(a[b])},A:function(a){4<a&&(Q.get(a).he+=1)},q:function(a){return xb(bc(a))},z:function(){return xb({})},bb:function(a){var b=Lb(a);Pa(b);Kb(a)},
|
|
112
|
+
Td:P(c,d),sd:P(e,f),ce:[]}},zb:function(a,b,c,d,e,f,g,h,m,p){Oa[a].ce.push({xe:M(b),Ee:c,Ce:P(d,e),De:f,Me:g,Le:P(h,m),Ne:p})},vb:function(a,b){b=M(b);L(a,{He:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},mb:()=>!0,ib:()=>{throw Infinity;},gb:function(a,b,c){a=Lb(a);b=Nb(b,"emval::as");var d=[],e=xb(d);D[c>>2]=e;return b.toWireType(d,a)},ab:function(a,b,c,d){a=cc[a];b=Lb(b);c=bc(c);a(b,c,null,d)},g:Kb,$a:function(a,b){var c=ec(a,b),d=c[0];b=d.name+"_$"+c.slice(1).map(function(g){return g.name}).join("_")+
|
|
113
|
+
"$";var e=fc[b];if(void 0!==e)return e;var f=Array(a-1);e=dc((g,h,m,p)=>{for(var r=0,v=0;v<a-1;++v)f[v]=c[v+1].readValueFromPointer(p+r),r+=c[v+1].argPackAdvance;g=g[h].apply(g,f);for(v=0;v<a-1;++v)c[v+1].se&&c[v+1].se(f[v]);if(!d.He)return d.toWireType(m,g)});return fc[b]=e},jb:function(a,b){a=Lb(a);b=Lb(b);return xb(a[b])},A:function(a){4<a&&(Q.get(a).he+=1)},q:function(a){return xb(bc(a))},z:function(){return xb({})},bb:function(a){var b=Lb(a);Pa(b);Kb(a)},n:function(a,b,c){a=Lb(a);b=Lb(b);c=Lb(c);
|
|
114
114
|
a[b]=c},v:function(a,b){a=Nb(a,"_emval_take_value");a=a.readValueFromPointer(b);return xb(a)},a:()=>{ra("")},nb:()=>performance.now(),Va:function(a){t.activeTexture(a)},Ua:function(a,b){t.attachShader(R[a],S[b])},Ta:function(a,b,c){t.bindAttribLocation(R[a],b,c?Tb(A,c):"")},Sa:function(a,b){35051==a?t.Rd=b:35052==a&&(t.zd=b);t.bindBuffer(a,kc[b])},Xb:vc,Wb:function(a,b){t.bindRenderbuffer(a,mc[b])},Eb:function(a,b){t.bindSampler(a,pc[b])},Ra:function(a,b){t.bindTexture(a,nc[b])},nc:wc,kc:wc,Qa:function(a,
|
|
115
115
|
b,c,d){t.blendColor(a,b,c,d)},Pa:function(a){t.blendEquation(a)},Oa:function(a,b){t.blendFunc(a,b)},Jb:function(a,b,c,d,e,f,g,h,m,p){t.blitFramebuffer(a,b,c,d,e,f,g,h,m,p)},Na:function(a,b,c,d){2<=n.version?c&&b?t.bufferData(a,A,d,c,b):t.bufferData(a,b,d):t.bufferData(a,c?A.subarray(c,c+b):b,d)},Ma:function(a,b,c,d){2<=n.version?c&&t.bufferSubData(a,b,A,d,c):t.bufferSubData(a,b,A.subarray(d,d+c))},Vb:function(a){return t.checkFramebufferStatus(a)},La:function(a){t.clear(a)},Ka:function(a,b,c,d){t.clearColor(a,
|
|
116
116
|
b,c,d)},Ja:function(a){t.clearStencil(a)},Ya:function(a,b,c,d){return t.clientWaitSync(qc[a],b,(c>>>0)+4294967296*d)},Ia:function(a,b,c,d){t.colorMask(!!a,!!b,!!c,!!d)},Ha:function(a){t.compileShader(S[a])},Ga:function(a,b,c,d,e,f,g,h){2<=n.version?t.zd||!g?t.compressedTexImage2D(a,b,c,d,e,f,g,h):t.compressedTexImage2D(a,b,c,d,e,f,A,h,g):t.compressedTexImage2D(a,b,c,d,e,f,h?A.subarray(h,h+g):null)},Fa:function(a,b,c,d,e,f,g,h,m){2<=n.version?t.zd||!h?t.compressedTexSubImage2D(a,b,c,d,e,f,g,h,m):t.compressedTexSubImage2D(a,
|
|
@@ -161,7 +161,7 @@ if(k.preInit)for("function"==typeof k.preInit&&(k.preInit=[k.preInit]);0<k.preIn
|
|
|
161
161
|
/* 2 */
|
|
162
162
|
/***/ ((module) => {
|
|
163
163
|
|
|
164
|
-
module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.
|
|
164
|
+
module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.4.0","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}}');
|
|
165
165
|
|
|
166
166
|
/***/ }),
|
|
167
167
|
/* 3 */
|
|
@@ -376,6 +376,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
376
376
|
/* harmony export */ Layout: () => (/* binding */ Layout),
|
|
377
377
|
/* harmony export */ LoopType: () => (/* binding */ LoopType),
|
|
378
378
|
/* harmony export */ Rive: () => (/* binding */ Rive),
|
|
379
|
+
/* harmony export */ RiveEventType: () => (/* binding */ RiveEventType),
|
|
379
380
|
/* harmony export */ RuntimeLoader: () => (/* binding */ RuntimeLoader),
|
|
380
381
|
/* harmony export */ StateMachineInput: () => (/* binding */ StateMachineInput),
|
|
381
382
|
/* harmony export */ StateMachineInputType: () => (/* binding */ StateMachineInputType),
|
|
@@ -739,6 +740,11 @@ var StateMachineInput = /** @class */ (function () {
|
|
|
739
740
|
return StateMachineInput;
|
|
740
741
|
}());
|
|
741
742
|
|
|
743
|
+
var RiveEventType;
|
|
744
|
+
(function (RiveEventType) {
|
|
745
|
+
RiveEventType[RiveEventType["General"] = 128] = "General";
|
|
746
|
+
RiveEventType[RiveEventType["OpenUrl"] = 131] = "OpenUrl";
|
|
747
|
+
})(RiveEventType || (RiveEventType = {}));
|
|
742
748
|
var StateMachine = /** @class */ (function () {
|
|
743
749
|
/**
|
|
744
750
|
* @constructor
|
|
@@ -784,6 +790,23 @@ var StateMachine = /** @class */ (function () {
|
|
|
784
790
|
StateMachine.prototype.advance = function (time) {
|
|
785
791
|
this.instance.advance(time);
|
|
786
792
|
};
|
|
793
|
+
/**
|
|
794
|
+
* Returns the number of events reported from the last advance call
|
|
795
|
+
* @returns Number of events reported
|
|
796
|
+
*/
|
|
797
|
+
StateMachine.prototype.reportedEventCount = function () {
|
|
798
|
+
return this.instance.reportedEventCount();
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* Returns a RiveEvent object emitted from the last advance call at the given index
|
|
802
|
+
* of a list of potentially multiple events. If an event at the index is not found,
|
|
803
|
+
* undefined is returned.
|
|
804
|
+
* @param i index of the event reported in a list of potentially multiple events
|
|
805
|
+
* @returns RiveEvent or extended RiveEvent object returned, or undefined
|
|
806
|
+
*/
|
|
807
|
+
StateMachine.prototype.reportedEventAt = function (i) {
|
|
808
|
+
return this.instance.reportedEventAt(i);
|
|
809
|
+
};
|
|
787
810
|
/**
|
|
788
811
|
* Fetches references to the state machine's inputs and caches them
|
|
789
812
|
* @param runtime an instance of the runtime; needed for the SMIInput types
|
|
@@ -1142,6 +1165,7 @@ var EventType;
|
|
|
1142
1165
|
EventType["Draw"] = "draw";
|
|
1143
1166
|
EventType["Advance"] = "advance";
|
|
1144
1167
|
EventType["StateChange"] = "statechange";
|
|
1168
|
+
EventType["RiveEvent"] = "riveevent";
|
|
1145
1169
|
})(EventType || (EventType = {}));
|
|
1146
1170
|
/**
|
|
1147
1171
|
* Looping types: one-shot, loop, and ping-pong
|
|
@@ -1252,6 +1276,7 @@ var Rive = /** @class */ (function () {
|
|
|
1252
1276
|
// place to clear up event listeners
|
|
1253
1277
|
this.eventCleanup = null;
|
|
1254
1278
|
this.shouldDisableRiveListeners = false;
|
|
1279
|
+
this.automaticallyHandleEvents = false;
|
|
1255
1280
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
1256
1281
|
this.durations = [];
|
|
1257
1282
|
this.frameTimes = [];
|
|
@@ -1266,6 +1291,7 @@ var Rive = /** @class */ (function () {
|
|
|
1266
1291
|
this.buffer = params.buffer;
|
|
1267
1292
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
1268
1293
|
this.shouldDisableRiveListeners = !!params.shouldDisableRiveListeners;
|
|
1294
|
+
this.automaticallyHandleEvents = !!params.automaticallyHandleEvents;
|
|
1269
1295
|
// New event management system
|
|
1270
1296
|
this.eventManager = new EventManager();
|
|
1271
1297
|
if (params.onLoad)
|
|
@@ -1510,6 +1536,37 @@ var Rive = /** @class */ (function () {
|
|
|
1510
1536
|
var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
|
|
1511
1537
|
for (var _a = 0, activeStateMachines_1 = activeStateMachines; _a < activeStateMachines_1.length; _a++) {
|
|
1512
1538
|
var stateMachine = activeStateMachines_1[_a];
|
|
1539
|
+
// Check for events before the current frame's state machine advance
|
|
1540
|
+
var numEventsReported = stateMachine.reportedEventCount();
|
|
1541
|
+
if (numEventsReported) {
|
|
1542
|
+
for (var i = 0; i < numEventsReported; i++) {
|
|
1543
|
+
var event_1 = stateMachine.reportedEventAt(i);
|
|
1544
|
+
if (event_1) {
|
|
1545
|
+
if (event_1.type === RiveEventType.OpenUrl) {
|
|
1546
|
+
this.eventManager.fire({
|
|
1547
|
+
type: EventType.RiveEvent,
|
|
1548
|
+
data: event_1,
|
|
1549
|
+
});
|
|
1550
|
+
// Handle the event side effect if explicitly enabled
|
|
1551
|
+
if (this.automaticallyHandleEvents) {
|
|
1552
|
+
var newAnchorTag = document.createElement("a");
|
|
1553
|
+
var _b = event_1, url = _b.url, target = _b.target;
|
|
1554
|
+
url && newAnchorTag.setAttribute("href", url);
|
|
1555
|
+
target && newAnchorTag.setAttribute("target", target);
|
|
1556
|
+
if (url) {
|
|
1557
|
+
newAnchorTag.click();
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
else {
|
|
1562
|
+
this.eventManager.fire({
|
|
1563
|
+
type: EventType.RiveEvent,
|
|
1564
|
+
data: event_1,
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1513
1570
|
stateMachine.advance(elapsedTime);
|
|
1514
1571
|
// stateMachine.instance.apply(this.artboard);
|
|
1515
1572
|
}
|