@rive-app/canvas 1.0.74 → 1.0.77
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 +123 -84
- 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
|
@@ -29,8 +29,8 @@ function(Rive) {
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
null;var k;k||(k=typeof Rive !== 'undefined' ? Rive : {});var aa,ba;k.ready=new Promise(function(b,a){aa=b;ba=a});
|
|
32
|
-
function ca(){function b(n){const g=d;c=a=0;d=new Map;g.forEach(m=>{try{m(n)}catch(h){console.error(h)}});this.Pa();e&&e.ib()}let a=0,c=0,d=new Map,e=null,f=null;this.requestAnimationFrame=function(n){a||(a=
|
|
33
|
-
"
|
|
32
|
+
function ca(){function b(n){const g=d;c=a=0;d=new Map;g.forEach(m=>{try{m(n)}catch(h){console.error(h)}});this.Pa();e&&e.ib()}let a=0,c=0,d=new Map,e=null,f=null;this.requestAnimationFrame=function(n){a||(a=requestAnimationFrame(b.bind(this)));const g=++c;d.set(g,n);return g};this.cancelAnimationFrame=function(n){d.delete(n);a&&0==d.size&&(cancelAnimationFrame(a),a=0)};this.gb=function(n){f&&(document.body.remove(f),f=null);n||(f=document.createElement("div"),f.style.backgroundColor="black",f.style.position=
|
|
33
|
+
"fixed",f.style.right=0,f.style.top=0,f.style.color="white",f.style.padding="4px",f.innerHTML="RIVE FPS",n=function(g){f.innerHTML="RIVE FPS "+g.toFixed(1)},document.body.appendChild(f));e=new function(){let g=0,m=0;this.ib=function(){var h=performance.now();m?(++g,h-=m,1E3<h&&(n(1E3*g/h),g=m=0)):(m=h,g=0)}}};this.cb=function(){f&&(document.body.remove(f),f=null);e=null};this.Pa=function(){}}
|
|
34
34
|
function da(b){console.assert(!0);const a=new Map;let c=-Infinity;this.push=function(d){d=d+((1<<b)-1)>>b;a.has(d)&&clearTimeout(a.get(d));a.set(d,setTimeout(function(){a.delete(d);0==a.length?c=-Infinity:d==c&&(c=Math.max(...a.keys()),console.assert(c<d))},1E3));c=Math.max(d,c);return c<<b}}
|
|
35
35
|
const fa=new function(){function b(){if(!a){var t=document.createElement("canvas"),x={alpha:1,depth:0,stencil:0,antialias:0,premultipliedAlpha:1,preserveDrawingBuffer:0,preferLowPowerToHighPerformance:0,failIfMajorPerformanceCaveat:0,enableExtensionsByDefault:1,explicitSwapControl:1,renderViaOffscreenBackBuffer:1};let q=t.getContext("webgl2",x);if(q)c=2;else if(q=t.getContext("webgl",x))c=1;else return console.log("No WebGL support. Image mesh will not be drawn."),!1;d=Math.min(q.getParameter(q.MAX_RENDERBUFFER_SIZE),
|
|
36
36
|
q.getParameter(q.MAX_TEXTURE_SIZE));function F(G,v,A){v=q.createShader(v);q.shaderSource(v,A);q.compileShader(v);A=q.getShaderInfoLog(v);if(0<A.length)throw A;q.attachShader(G,v)}t=q.createProgram();F(t,q.VERTEX_SHADER,"attribute vec2 vertex;\n attribute vec2 uv;\n uniform vec4 mat;\n uniform vec2 translate;\n varying vec2 st;\n void main() {\n st = uv;\n gl_Position = vec4(mat2(mat) * vertex + translate, 0, 1);\n }");
|
|
@@ -137,7 +137,7 @@ k.run=Bc;if(k.preInit)for("function"==typeof k.preInit&&(k.preInit=[k.preInit]);
|
|
|
137
137
|
/* 2 */
|
|
138
138
|
/***/ ((module) => {
|
|
139
139
|
|
|
140
|
-
module.exports = JSON.parse('{"name":"@rive-app/canvas","version":"1.0.
|
|
140
|
+
module.exports = JSON.parse('{"name":"@rive-app/canvas","version":"1.0.77","description":"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.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
141
141
|
|
|
142
142
|
/***/ }),
|
|
143
143
|
/* 3 */
|
|
@@ -173,56 +173,69 @@ const registerTouchInteractions = ({
|
|
|
173
173
|
alignment,
|
|
174
174
|
}) => {
|
|
175
175
|
if (!canvas || !stateMachines.length || !renderer || !rive || !artboard) {
|
|
176
|
-
return;
|
|
176
|
+
return null;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
const mouseCallback = (event) => {
|
|
180
|
+
const boundingRect = event.currentTarget.getBoundingClientRect();
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
const canvasX = event.clientX - boundingRect.left;
|
|
183
|
+
const canvasY = event.clientY - boundingRect.top;
|
|
184
|
+
const forwardMatrix = rive.computeAlignment(
|
|
185
|
+
fit,
|
|
186
|
+
alignment,
|
|
187
|
+
{
|
|
185
188
|
minX: 0,
|
|
186
189
|
minY: 0,
|
|
187
190
|
maxX: boundingRect.width,
|
|
188
191
|
maxY: boundingRect.height,
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
},
|
|
193
|
+
artboard.bounds
|
|
194
|
+
);
|
|
195
|
+
let invertedMatrix = new rive.Mat2D();
|
|
196
|
+
forwardMatrix.invert(invertedMatrix);
|
|
197
|
+
const canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
|
|
198
|
+
const transformedVector = rive.mapXY(
|
|
199
|
+
invertedMatrix,
|
|
200
|
+
canvasCoordinatesVector
|
|
201
|
+
);
|
|
202
|
+
const transformedX = transformedVector.x();
|
|
203
|
+
const transformedY = transformedVector.y();
|
|
196
204
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
break;
|
|
205
|
+
switch (event.type) {
|
|
206
|
+
// Pointer moving/hovering on the canvas
|
|
207
|
+
case 'mousemove': {
|
|
208
|
+
for (const stateMachine of stateMachines) {
|
|
209
|
+
stateMachine.pointerMove(transformedX, transformedY);
|
|
204
210
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
// Pointer click initiated but not released yet on the canvas
|
|
214
|
+
case 'mousedown': {
|
|
215
|
+
for (const stateMachine of stateMachines) {
|
|
216
|
+
stateMachine.pointerDown(transformedX, transformedY);
|
|
211
217
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
// Pointer click released on the canvas
|
|
221
|
+
case 'mouseup': {
|
|
222
|
+
for (const stateMachine of stateMachines) {
|
|
223
|
+
stateMachine.pointerUp(transformedX, transformedY);
|
|
218
224
|
}
|
|
219
|
-
|
|
225
|
+
break;
|
|
220
226
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
227
|
+
default:
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const callback = mouseCallback.bind(undefined);
|
|
231
|
+
canvas.addEventListener('mousemove', callback);
|
|
232
|
+
canvas.addEventListener('mousedown', callback);
|
|
233
|
+
canvas.addEventListener('mouseup', callback);
|
|
234
|
+
return () => {
|
|
235
|
+
canvas.removeEventListener('mousemove', callback);
|
|
236
|
+
canvas.removeEventListener('mousedown', callback);
|
|
237
|
+
canvas.removeEventListener('mouseup', callback);
|
|
238
|
+
};
|
|
226
239
|
};
|
|
227
240
|
|
|
228
241
|
|
|
@@ -402,7 +415,7 @@ var Layout = /** @class */ (function () {
|
|
|
402
415
|
minX: minX !== null && minX !== void 0 ? minX : this.minX,
|
|
403
416
|
minY: minY !== null && minY !== void 0 ? minY : this.minY,
|
|
404
417
|
maxX: maxX !== null && maxX !== void 0 ? maxX : this.maxX,
|
|
405
|
-
maxY: maxY !== null && maxY !== void 0 ? maxY : this.maxY
|
|
418
|
+
maxY: maxY !== null && maxY !== void 0 ? maxY : this.maxY,
|
|
406
419
|
});
|
|
407
420
|
};
|
|
408
421
|
// Returns fit for the Wasm runtime format
|
|
@@ -466,7 +479,7 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
466
479
|
RuntimeLoader.loadRuntime = function () {
|
|
467
480
|
_rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__.default({
|
|
468
481
|
// Loads Wasm bundle
|
|
469
|
-
locateFile: function (_) { return RuntimeLoader.wasmURL; }
|
|
482
|
+
locateFile: function (_) { return RuntimeLoader.wasmURL; },
|
|
470
483
|
}).then(function (rive) {
|
|
471
484
|
var _a;
|
|
472
485
|
RuntimeLoader.runtime = rive;
|
|
@@ -767,8 +780,8 @@ var Animator = /** @class */ (function () {
|
|
|
767
780
|
animatables = mapToStringArray(animatables);
|
|
768
781
|
// If animatables is empty, play or pause everything
|
|
769
782
|
if (animatables.length === 0) {
|
|
770
|
-
this.animations.forEach(function (a) { return a.playing = playing; });
|
|
771
|
-
this.stateMachines.forEach(function (m) { return m.playing = playing; });
|
|
783
|
+
this.animations.forEach(function (a) { return (a.playing = playing); });
|
|
784
|
+
this.stateMachines.forEach(function (m) { return (m.playing = playing); });
|
|
772
785
|
}
|
|
773
786
|
else {
|
|
774
787
|
// Play/pause already instanced items, or create new instances
|
|
@@ -834,11 +847,11 @@ var Animator = /** @class */ (function () {
|
|
|
834
847
|
return this.add(animatables, true);
|
|
835
848
|
};
|
|
836
849
|
/**
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
850
|
+
* Pauses named animations and state machines, or everything if nothing is
|
|
851
|
+
* specified
|
|
852
|
+
* @param animatables names of the animations and state machines to pause
|
|
853
|
+
* @returns a list of names of the animations and state machines paused
|
|
854
|
+
*/
|
|
842
855
|
Animator.prototype.pause = function (animatables) {
|
|
843
856
|
return this.add(animatables, false);
|
|
844
857
|
};
|
|
@@ -849,8 +862,10 @@ var Animator = /** @class */ (function () {
|
|
|
849
862
|
* @returns a list of names of the animations that were scrubbed
|
|
850
863
|
*/
|
|
851
864
|
Animator.prototype.scrub = function (animatables, value) {
|
|
852
|
-
var forScrubbing = this.animations.filter(function (a) {
|
|
853
|
-
|
|
865
|
+
var forScrubbing = this.animations.filter(function (a) {
|
|
866
|
+
return animatables.includes(a.name);
|
|
867
|
+
});
|
|
868
|
+
forScrubbing.forEach(function (a) { return (a.scrubTo = value); });
|
|
854
869
|
return forScrubbing.map(function (a) { return a.name; });
|
|
855
870
|
};
|
|
856
871
|
Object.defineProperty(Animator.prototype, "playing", {
|
|
@@ -859,7 +874,10 @@ var Animator = /** @class */ (function () {
|
|
|
859
874
|
* playing
|
|
860
875
|
*/
|
|
861
876
|
get: function () {
|
|
862
|
-
return this.animations
|
|
877
|
+
return this.animations
|
|
878
|
+
.filter(function (a) { return a.playing; })
|
|
879
|
+
.map(function (a) { return a.name; })
|
|
880
|
+
.concat(this.stateMachines.filter(function (m) { return m.playing; }).map(function (m) { return m.name; }));
|
|
863
881
|
},
|
|
864
882
|
enumerable: false,
|
|
865
883
|
configurable: true
|
|
@@ -870,7 +888,10 @@ var Animator = /** @class */ (function () {
|
|
|
870
888
|
* paused
|
|
871
889
|
*/
|
|
872
890
|
get: function () {
|
|
873
|
-
return this.animations
|
|
891
|
+
return this.animations
|
|
892
|
+
.filter(function (a) { return !a.playing; })
|
|
893
|
+
.map(function (a) { return a.name; })
|
|
894
|
+
.concat(this.stateMachines.filter(function (m) { return !m.playing; }).map(function (m) { return m.name; }));
|
|
874
895
|
},
|
|
875
896
|
enumerable: false,
|
|
876
897
|
configurable: true
|
|
@@ -887,7 +908,9 @@ var Animator = /** @class */ (function () {
|
|
|
887
908
|
var removedNames = [];
|
|
888
909
|
// Stop everything
|
|
889
910
|
if (animatables.length === 0) {
|
|
890
|
-
removedNames = this.animations
|
|
911
|
+
removedNames = this.animations
|
|
912
|
+
.map(function (a) { return a.name; })
|
|
913
|
+
.concat(this.stateMachines.map(function (m) { return m.name; }));
|
|
891
914
|
// Clean up before emptying the arrays
|
|
892
915
|
this.animations.forEach(function (a) { return a.cleanup(); });
|
|
893
916
|
this.stateMachines.forEach(function (m) { return m.cleanup(); });
|
|
@@ -897,17 +920,23 @@ var Animator = /** @class */ (function () {
|
|
|
897
920
|
}
|
|
898
921
|
else {
|
|
899
922
|
// Remove only the named animations/state machines
|
|
900
|
-
var animationsToRemove = this.animations.filter(function (a) {
|
|
923
|
+
var animationsToRemove = this.animations.filter(function (a) {
|
|
924
|
+
return animatables.includes(a.name);
|
|
925
|
+
});
|
|
901
926
|
animationsToRemove.forEach(function (a) {
|
|
902
927
|
a.cleanup();
|
|
903
928
|
_this.animations.splice(_this.animations.indexOf(a), 1);
|
|
904
929
|
});
|
|
905
|
-
var machinesToRemove = this.stateMachines.filter(function (m) {
|
|
930
|
+
var machinesToRemove = this.stateMachines.filter(function (m) {
|
|
931
|
+
return animatables.includes(m.name);
|
|
932
|
+
});
|
|
906
933
|
machinesToRemove.forEach(function (m) {
|
|
907
934
|
m.cleanup();
|
|
908
935
|
_this.stateMachines.splice(_this.stateMachines.indexOf(m), 1);
|
|
909
936
|
});
|
|
910
|
-
removedNames = animationsToRemove
|
|
937
|
+
removedNames = animationsToRemove
|
|
938
|
+
.map(function (a) { return a.name; })
|
|
939
|
+
.concat(machinesToRemove.map(function (m) { return m.name; }));
|
|
911
940
|
}
|
|
912
941
|
this.eventManager.fire({
|
|
913
942
|
type: EventType.Stop,
|
|
@@ -921,8 +950,8 @@ var Animator = /** @class */ (function () {
|
|
|
921
950
|
* Returns true if at least one animation is active
|
|
922
951
|
*/
|
|
923
952
|
get: function () {
|
|
924
|
-
return this.animations.reduce(function (acc, curr) { return acc || curr.playing; }, false)
|
|
925
|
-
|
|
953
|
+
return (this.animations.reduce(function (acc, curr) { return acc || curr.playing; }, false) ||
|
|
954
|
+
this.stateMachines.reduce(function (acc, curr) { return acc || curr.playing; }, false));
|
|
926
955
|
},
|
|
927
956
|
enumerable: false,
|
|
928
957
|
configurable: true
|
|
@@ -932,8 +961,8 @@ var Animator = /** @class */ (function () {
|
|
|
932
961
|
* Returns true if all animations are paused and there's at least one animation
|
|
933
962
|
*/
|
|
934
963
|
get: function () {
|
|
935
|
-
return !this.isPlaying &&
|
|
936
|
-
(this.animations.length > 0 || this.stateMachines.length > 0);
|
|
964
|
+
return (!this.isPlaying &&
|
|
965
|
+
(this.animations.length > 0 || this.stateMachines.length > 0));
|
|
937
966
|
},
|
|
938
967
|
enumerable: false,
|
|
939
968
|
configurable: true
|
|
@@ -958,11 +987,11 @@ var Animator = /** @class */ (function () {
|
|
|
958
987
|
if (this.animations.length === 0 && this.stateMachines.length === 0) {
|
|
959
988
|
if (this.artboard.animationCount() > 0) {
|
|
960
989
|
// Add the first animation
|
|
961
|
-
this.add([instancedName = this.artboard.animationByIndex(0).name], playing, fireEvent);
|
|
990
|
+
this.add([(instancedName = this.artboard.animationByIndex(0).name)], playing, fireEvent);
|
|
962
991
|
}
|
|
963
992
|
else if (this.artboard.stateMachineCount() > 0) {
|
|
964
993
|
// Add the first state machine
|
|
965
|
-
this.add([instancedName = this.artboard.stateMachineByIndex(0).name], playing, fireEvent);
|
|
994
|
+
this.add([(instancedName = this.artboard.stateMachineByIndex(0).name)], playing, fireEvent);
|
|
966
995
|
}
|
|
967
996
|
}
|
|
968
997
|
return instancedName;
|
|
@@ -982,7 +1011,7 @@ var Animator = /** @class */ (function () {
|
|
|
982
1011
|
else if (animation.loopValue === 1 && animation.loopCount) {
|
|
983
1012
|
this.eventManager.fire({
|
|
984
1013
|
type: EventType.Loop,
|
|
985
|
-
data: { animation: animation.name, type: LoopType.Loop }
|
|
1014
|
+
data: { animation: animation.name, type: LoopType.Loop },
|
|
986
1015
|
});
|
|
987
1016
|
animation.loopCount = 0;
|
|
988
1017
|
}
|
|
@@ -992,7 +1021,7 @@ var Animator = /** @class */ (function () {
|
|
|
992
1021
|
else if (animation.loopValue === 2 && animation.loopCount > 1) {
|
|
993
1022
|
this.eventManager.fire({
|
|
994
1023
|
type: EventType.Loop,
|
|
995
|
-
data: { animation: animation.name, type: LoopType.PingPong }
|
|
1024
|
+
data: { animation: animation.name, type: LoopType.PingPong },
|
|
996
1025
|
});
|
|
997
1026
|
animation.loopCount = 0;
|
|
998
1027
|
}
|
|
@@ -1040,7 +1069,7 @@ var LoopType;
|
|
|
1040
1069
|
(function (LoopType) {
|
|
1041
1070
|
LoopType["OneShot"] = "oneshot";
|
|
1042
1071
|
LoopType["Loop"] = "loop";
|
|
1043
|
-
LoopType["PingPong"] = "pingpong";
|
|
1072
|
+
LoopType["PingPong"] = "pingpong";
|
|
1044
1073
|
})(LoopType || (LoopType = {}));
|
|
1045
1074
|
// Manages Rive events and listeners
|
|
1046
1075
|
var EventManager = /** @class */ (function () {
|
|
@@ -1144,6 +1173,8 @@ var Rive = /** @class */ (function () {
|
|
|
1144
1173
|
this.readyForPlaying = false;
|
|
1145
1174
|
// Runtime artboard
|
|
1146
1175
|
this.artboard = null;
|
|
1176
|
+
// place to clear up event listeners
|
|
1177
|
+
this.eventCleanup = null;
|
|
1147
1178
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
1148
1179
|
this.durations = [];
|
|
1149
1180
|
this.frameTimes = [];
|
|
@@ -1224,7 +1255,8 @@ var Rive = /** @class */ (function () {
|
|
|
1224
1255
|
this.loaded = false;
|
|
1225
1256
|
this.readyForPlaying = false;
|
|
1226
1257
|
// Ensure the runtime is loaded
|
|
1227
|
-
RuntimeLoader.awaitInstance()
|
|
1258
|
+
RuntimeLoader.awaitInstance()
|
|
1259
|
+
.then(function (runtime) {
|
|
1228
1260
|
_this.runtime = runtime;
|
|
1229
1261
|
// Get the canvas where you want to render the animation and create a renderer
|
|
1230
1262
|
_this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
|
|
@@ -1238,7 +1270,7 @@ var Rive = /** @class */ (function () {
|
|
|
1238
1270
|
var activeStateMachineInstances = (_this.animator.stateMachines || [])
|
|
1239
1271
|
.filter(function (sm) { return sm.playing; })
|
|
1240
1272
|
.map(function (sm) { return sm.instance; });
|
|
1241
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
|
|
1273
|
+
_this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
|
|
1242
1274
|
canvas: _this.canvas,
|
|
1243
1275
|
artboard: _this.artboard,
|
|
1244
1276
|
stateMachines: activeStateMachineInstances,
|
|
@@ -1251,7 +1283,8 @@ var Rive = /** @class */ (function () {
|
|
|
1251
1283
|
.catch(function (e) {
|
|
1252
1284
|
console.error(e);
|
|
1253
1285
|
});
|
|
1254
|
-
})
|
|
1286
|
+
})
|
|
1287
|
+
.catch(function (e) {
|
|
1255
1288
|
console.error(e);
|
|
1256
1289
|
});
|
|
1257
1290
|
};
|
|
@@ -1283,7 +1316,7 @@ var Rive = /** @class */ (function () {
|
|
|
1283
1316
|
this.loaded = true;
|
|
1284
1317
|
this.eventManager.fire({
|
|
1285
1318
|
type: EventType.Load,
|
|
1286
|
-
data: (_a = this.src) !== null && _a !== void 0 ? _a : 'buffer'
|
|
1319
|
+
data: (_a = this.src) !== null && _a !== void 0 ? _a : 'buffer',
|
|
1287
1320
|
});
|
|
1288
1321
|
// Flag ready for playback commands and clear the task queue; this order
|
|
1289
1322
|
// is important or it may infinitely recurse
|
|
@@ -1306,9 +1339,9 @@ var Rive = /** @class */ (function () {
|
|
|
1306
1339
|
// Initialize for playback
|
|
1307
1340
|
Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
1308
1341
|
// Fetch the artboard
|
|
1309
|
-
var rootArtboard = artboardName
|
|
1310
|
-
this.file.artboardByName(artboardName)
|
|
1311
|
-
this.file.defaultArtboard();
|
|
1342
|
+
var rootArtboard = artboardName
|
|
1343
|
+
? this.file.artboardByName(artboardName)
|
|
1344
|
+
: this.file.defaultArtboard();
|
|
1312
1345
|
// Check we have a working artboard
|
|
1313
1346
|
if (!rootArtboard) {
|
|
1314
1347
|
var msg = 'Invalid artboard name or no default artboard';
|
|
@@ -1343,7 +1376,7 @@ var Rive = /** @class */ (function () {
|
|
|
1343
1376
|
event: {
|
|
1344
1377
|
type: autoplay ? EventType.Play : EventType.Pause,
|
|
1345
1378
|
data: instanceNames,
|
|
1346
|
-
}
|
|
1379
|
+
},
|
|
1347
1380
|
});
|
|
1348
1381
|
};
|
|
1349
1382
|
// Draws the current artboard frame
|
|
@@ -1363,7 +1396,7 @@ var Rive = /** @class */ (function () {
|
|
|
1363
1396
|
this.lastRenderTime = time;
|
|
1364
1397
|
}
|
|
1365
1398
|
// Handle the onSecond callback
|
|
1366
|
-
this.renderSecondTimer +=
|
|
1399
|
+
this.renderSecondTimer += time - this.lastRenderTime;
|
|
1367
1400
|
if (this.renderSecondTimer > 5000) {
|
|
1368
1401
|
this.renderSecondTimer = 0;
|
|
1369
1402
|
onSecond === null || onSecond === void 0 ? void 0 : onSecond();
|
|
@@ -1374,10 +1407,11 @@ var Rive = /** @class */ (function () {
|
|
|
1374
1407
|
// - Advance non-paused animations by the elapsed number of seconds
|
|
1375
1408
|
// - Advance any animations that require scrubbing
|
|
1376
1409
|
// - Advance to the first frame even when autoplay is false
|
|
1377
|
-
var activeAnimations = this.animator.animations
|
|
1410
|
+
var activeAnimations = this.animator.animations
|
|
1411
|
+
.filter(function (a) { return a.playing || a.needsScrub; })
|
|
1378
1412
|
// The scrubbed animations must be applied first to prevent weird artifacts
|
|
1379
1413
|
// if the playing animations conflict with the scrubbed animating attribuates.
|
|
1380
|
-
.sort(function (first, second) { return first.needsScrub ? -1 : 1; });
|
|
1414
|
+
.sort(function (first, second) { return (first.needsScrub ? -1 : 1); });
|
|
1381
1415
|
for (var _i = 0, activeAnimations_1 = activeAnimations; _i < activeAnimations_1.length; _i++) {
|
|
1382
1416
|
var animation = activeAnimations_1[_i];
|
|
1383
1417
|
animation.advance(elapsedTime);
|
|
@@ -1447,7 +1481,7 @@ var Rive = /** @class */ (function () {
|
|
|
1447
1481
|
minX: _layout.minX,
|
|
1448
1482
|
minY: _layout.minY,
|
|
1449
1483
|
maxX: _layout.maxX,
|
|
1450
|
-
maxY: _layout.maxY
|
|
1484
|
+
maxY: _layout.maxY,
|
|
1451
1485
|
}, artboard.bounds);
|
|
1452
1486
|
};
|
|
1453
1487
|
Object.defineProperty(Rive.prototype, "fps", {
|
|
@@ -1475,6 +1509,9 @@ var Rive = /** @class */ (function () {
|
|
|
1475
1509
|
* might happen.
|
|
1476
1510
|
*/
|
|
1477
1511
|
Rive.prototype.cleanup = function () {
|
|
1512
|
+
if (this.eventCleanup !== null) {
|
|
1513
|
+
this.eventCleanup();
|
|
1514
|
+
}
|
|
1478
1515
|
this.artboard.delete();
|
|
1479
1516
|
// TODO: delete animation and state machine instances
|
|
1480
1517
|
};
|
|
@@ -1553,6 +1590,7 @@ var Rive = /** @class */ (function () {
|
|
|
1553
1590
|
this.cleanup();
|
|
1554
1591
|
// Reinitialize an artboard instance with the state
|
|
1555
1592
|
this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay);
|
|
1593
|
+
this.taskQueue.process();
|
|
1556
1594
|
};
|
|
1557
1595
|
// Loads a new Rive file, keeping listeners in place
|
|
1558
1596
|
Rive.prototype.load = function (params) {
|
|
@@ -1593,7 +1631,7 @@ var Rive = /** @class */ (function () {
|
|
|
1593
1631
|
minX: 0,
|
|
1594
1632
|
minY: 0,
|
|
1595
1633
|
maxX: this.canvas.width,
|
|
1596
|
-
maxY: this.canvas.height
|
|
1634
|
+
maxY: this.canvas.height,
|
|
1597
1635
|
});
|
|
1598
1636
|
};
|
|
1599
1637
|
/**
|
|
@@ -1699,9 +1737,7 @@ var Rive = /** @class */ (function () {
|
|
|
1699
1737
|
if (!this.loaded) {
|
|
1700
1738
|
return [];
|
|
1701
1739
|
}
|
|
1702
|
-
return this.animator.animations
|
|
1703
|
-
.filter(function (a) { return a.playing; })
|
|
1704
|
-
.map(function (a) { return a.name; });
|
|
1740
|
+
return this.animator.animations.filter(function (a) { return a.playing; }).map(function (a) { return a.name; });
|
|
1705
1741
|
},
|
|
1706
1742
|
enumerable: false,
|
|
1707
1743
|
configurable: true
|
|
@@ -1887,7 +1923,10 @@ var Rive = /** @class */ (function () {
|
|
|
1887
1923
|
var input = instance.input(l);
|
|
1888
1924
|
inputContents.push({ name: input.name, type: input.type });
|
|
1889
1925
|
}
|
|
1890
|
-
artboardContents.stateMachines.push({
|
|
1926
|
+
artboardContents.stateMachines.push({
|
|
1927
|
+
name: name_1,
|
|
1928
|
+
inputs: inputContents,
|
|
1929
|
+
});
|
|
1891
1930
|
}
|
|
1892
1931
|
riveContents.artboards.push(artboardContents);
|
|
1893
1932
|
}
|