@rive-app/canvas 2.26.4 → 2.26.6
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 +155 -0
- package/rive.js +632 -50
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +129 -0
- package/rive_fallback.wasm +0 -0
package/rive.js
CHANGED
|
@@ -26,10 +26,10 @@ var Rive = (() => {
|
|
|
26
26
|
return (
|
|
27
27
|
function(moduleArg = {}) {
|
|
28
28
|
|
|
29
|
-
var m = moduleArg, aa,
|
|
29
|
+
var m = moduleArg, aa, ba;
|
|
30
30
|
m.ready = new Promise((a, b) => {
|
|
31
31
|
aa = a;
|
|
32
|
-
|
|
32
|
+
ba = b;
|
|
33
33
|
});
|
|
34
34
|
function fa() {
|
|
35
35
|
function a(g) {
|
|
@@ -266,7 +266,7 @@ const ja = "createConicGradient createImageData createLinearGradient createPatte
|
|
|
266
266
|
b.clearColor(0, 0, 0, 0);
|
|
267
267
|
b.clear(b.COLOR_BUFFER_BIT);
|
|
268
268
|
b.enable(b.SCISSOR_TEST);
|
|
269
|
-
r.sort((H,
|
|
269
|
+
r.sort((H, ca) => ca.wb - H.wb);
|
|
270
270
|
w = v.push(B);
|
|
271
271
|
g != w && (b.bufferData(b.ARRAY_BUFFER, 8 * w, b.DYNAMIC_DRAW), g = w);
|
|
272
272
|
w = 0;
|
|
@@ -274,8 +274,8 @@ const ja = "createConicGradient createImageData createLinearGradient createPatte
|
|
|
274
274
|
b.bufferSubData(b.ARRAY_BUFFER, w, T.Ta), w += 4 * T.Ta.length;
|
|
275
275
|
}
|
|
276
276
|
console.assert(w == 4 * B);
|
|
277
|
-
for (var
|
|
278
|
-
b.bufferSubData(b.ARRAY_BUFFER, w,
|
|
277
|
+
for (var da of r) {
|
|
278
|
+
b.bufferSubData(b.ARRAY_BUFFER, w, da.Db), w += 4 * da.Db.length;
|
|
279
279
|
}
|
|
280
280
|
console.assert(w == 8 * B);
|
|
281
281
|
w = x.push(D);
|
|
@@ -286,15 +286,15 @@ const ja = "createConicGradient createImageData createLinearGradient createPatte
|
|
|
286
286
|
}
|
|
287
287
|
console.assert(T == 2 * D);
|
|
288
288
|
ra = 0;
|
|
289
|
-
|
|
289
|
+
da = !0;
|
|
290
290
|
w = T = 0;
|
|
291
291
|
for (const H of r) {
|
|
292
292
|
H.image.Ka != ra && (b.bindTexture(b.TEXTURE_2D, H.image.Ja || null), ra = H.image.Ka);
|
|
293
|
-
H.mc ? (b.scissor(H.Ya, M - H.Za - H.jb, H.Ac, H.jb),
|
|
293
|
+
H.mc ? (b.scissor(H.Ya, M - H.Za - H.jb, H.Ac, H.jb), da = !0) : da && (b.scissor(0, M - t, k, t), da = !1);
|
|
294
294
|
r = 2 / k;
|
|
295
|
-
const
|
|
296
|
-
b.uniform4f(e, H.ha[0] * r * H.Ba, H.ha[1] *
|
|
297
|
-
b.uniform2f(f, H.ha[4] * r * H.Ba + r * (H.Ya - H.ic * H.Ba) - 1, H.ha[5] *
|
|
295
|
+
const ca = -2 / t;
|
|
296
|
+
b.uniform4f(e, H.ha[0] * r * H.Ba, H.ha[1] * ca * H.Ca, H.ha[2] * r * H.Ba, H.ha[3] * ca * H.Ca);
|
|
297
|
+
b.uniform2f(f, H.ha[4] * r * H.Ba + r * (H.Ya - H.ic * H.Ba) - 1, H.ha[5] * ca * H.Ca + ca * (H.Za - H.jc * H.Ca) + 1);
|
|
298
298
|
b.vertexAttribPointer(0, 2, b.FLOAT, !1, 0, w);
|
|
299
299
|
b.vertexAttribPointer(1, 2, b.FLOAT, !1, 0, w + 4 * B);
|
|
300
300
|
b.drawElements(b.TRIANGLES, H.indices.length, b.UNSIGNED_SHORT, T);
|
|
@@ -351,7 +351,7 @@ m.onRuntimeInitialized = function() {
|
|
|
351
351
|
return "rgba(" + ((16711680 & q) >>> 16) + "," + ((65280 & q) >>> 8) + "," + ((255 & q) >>> 0) + "," + ((4278190080 & q) >>> 24) / 255 + ")";
|
|
352
352
|
}
|
|
353
353
|
function c() {
|
|
354
|
-
0 < M.length && (ka.Qb(w.drawWidth(), w.drawHeight(), M, T,
|
|
354
|
+
0 < M.length && (ka.Qb(w.drawWidth(), w.drawHeight(), M, T, da), M = [], da = T = 0, w.reset(512, 512));
|
|
355
355
|
for (const q of D) {
|
|
356
356
|
for (const y of q.H) {
|
|
357
357
|
y();
|
|
@@ -461,8 +461,8 @@ m.onRuntimeInitialized = function() {
|
|
|
461
461
|
var K = I.cb;
|
|
462
462
|
const Q = I.Ra;
|
|
463
463
|
I.ec ? (I = X - A, K -= J, A = q.createRadialGradient(A, J, 0, A, J, Math.sqrt(I * I + K * K))) : A = q.createLinearGradient(A, J, X, K);
|
|
464
|
-
for (let
|
|
465
|
-
J = Q[
|
|
464
|
+
for (let ea = 0, R = Q.length; ea < R; ea++) {
|
|
465
|
+
J = Q[ea], A.addColorStop(J.stop, b(J.color));
|
|
466
466
|
}
|
|
467
467
|
this.Xa = A;
|
|
468
468
|
this.ja = null;
|
|
@@ -480,7 +480,7 @@ m.onRuntimeInitialized = function() {
|
|
|
480
480
|
}
|
|
481
481
|
},});
|
|
482
482
|
const D = new Set();
|
|
483
|
-
let w = null, M = [], T = 0,
|
|
483
|
+
let w = null, M = [], T = 0, da = 0;
|
|
484
484
|
var ra = m.CanvasRenderer = g.extend("Renderer", {__construct:function(q) {
|
|
485
485
|
this.__parent.__construct.call(this);
|
|
486
486
|
this.S = [1, 0, 0, 1, 0, 0];
|
|
@@ -524,29 +524,29 @@ m.onRuntimeInitialized = function() {
|
|
|
524
524
|
q[G] = y[F + G];
|
|
525
525
|
}
|
|
526
526
|
}, _drawImageMesh:function(q, y, F, G, A, I, J, K, X, Q) {
|
|
527
|
-
var
|
|
527
|
+
var ea = this.C.canvas.width, R = this.C.canvas.height;
|
|
528
528
|
const Yb = X - J, Zb = Q - K;
|
|
529
529
|
J = Math.max(J, 0);
|
|
530
530
|
K = Math.max(K, 0);
|
|
531
|
-
X = Math.min(X,
|
|
531
|
+
X = Math.min(X, ea);
|
|
532
532
|
Q = Math.min(Q, R);
|
|
533
533
|
const Ga = X - J, Ha = Q - K;
|
|
534
|
-
console.assert(Ga <= Math.min(Yb,
|
|
534
|
+
console.assert(Ga <= Math.min(Yb, ea));
|
|
535
535
|
console.assert(Ha <= Math.min(Zb, R));
|
|
536
536
|
if (!(0 >= Ga || 0 >= Ha)) {
|
|
537
537
|
X = Ga < Yb || Ha < Zb;
|
|
538
|
-
|
|
539
|
-
var sa = Math.ceil(Ga * Q), ta = Math.ceil(Ha *
|
|
538
|
+
ea = Q = 1;
|
|
539
|
+
var sa = Math.ceil(Ga * Q), ta = Math.ceil(Ha * ea);
|
|
540
540
|
R = ka.hc();
|
|
541
541
|
sa > R && (Q *= R / sa, sa = R);
|
|
542
|
-
ta > R && (
|
|
542
|
+
ta > R && (ea *= R / ta, ta = R);
|
|
543
543
|
w || (w = new m.DynamicRectanizer(R), w.reset(512, 512));
|
|
544
544
|
R = w.addRect(sa, ta);
|
|
545
545
|
0 > R && (c(), D.add(this), R = w.addRect(sa, ta), console.assert(0 <= R));
|
|
546
546
|
var $b = R & 65535, ac = R >> 16;
|
|
547
|
-
M.push({ha:this.S.slice(this.S.length - 6), image:q, Ya:$b, Za:ac, ic:J, jc:K, Ac:sa, jb:ta, Ba:Q, Ca:
|
|
547
|
+
M.push({ha:this.S.slice(this.S.length - 6), image:q, Ya:$b, Za:ac, ic:J, jc:K, Ac:sa, jb:ta, Ba:Q, Ca:ea, Ta:new Float32Array(G), Db:new Float32Array(A), indices:new Uint16Array(I), mc:X, wb:q.Ka << 1 | (X ? 1 : 0),});
|
|
548
548
|
T += G.length;
|
|
549
|
-
|
|
549
|
+
da += I.length;
|
|
550
550
|
var za = this.C, qd = a(y);
|
|
551
551
|
this.H.push(function() {
|
|
552
552
|
za.save();
|
|
@@ -600,7 +600,7 @@ m.onRuntimeInitialized = function() {
|
|
|
600
600
|
}, makeRenderPath:function() {
|
|
601
601
|
return new r();
|
|
602
602
|
}, makeRenderImage:function() {
|
|
603
|
-
let q =
|
|
603
|
+
let q = ca;
|
|
604
604
|
return new t({xa:() => {
|
|
605
605
|
q.total++;
|
|
606
606
|
}, la:() => {
|
|
@@ -611,18 +611,18 @@ m.onRuntimeInitialized = function() {
|
|
|
611
611
|
}
|
|
612
612
|
},});
|
|
613
613
|
},};
|
|
614
|
-
let H = m.load,
|
|
614
|
+
let H = m.load, ca = null;
|
|
615
615
|
m.load = function(q, y, F = !0) {
|
|
616
616
|
const G = new m.FallbackFileAssetLoader();
|
|
617
617
|
void 0 !== y && G.addLoader(y);
|
|
618
618
|
F && (y = new m.CDNFileAssetLoader(), G.addLoader(y));
|
|
619
619
|
return new Promise(function(A) {
|
|
620
620
|
let I = null;
|
|
621
|
-
|
|
621
|
+
ca = {total:0, loaded:0, ready:function() {
|
|
622
622
|
A(I);
|
|
623
623
|
},};
|
|
624
624
|
I = H(q, G);
|
|
625
|
-
0 ==
|
|
625
|
+
0 == ca.total && A(I);
|
|
626
626
|
});
|
|
627
627
|
};
|
|
628
628
|
let rd = m.RendererWrapper.prototype.align;
|
|
@@ -693,7 +693,7 @@ function Aa(a) {
|
|
|
693
693
|
xa(a);
|
|
694
694
|
Ca = !0;
|
|
695
695
|
a = new WebAssembly.RuntimeError(a + ". Build with -sASSERTIONS for more info.");
|
|
696
|
-
|
|
696
|
+
ba(a);
|
|
697
697
|
throw a;
|
|
698
698
|
}
|
|
699
699
|
function Sa(a) {
|
|
@@ -746,7 +746,7 @@ function Ya(a, b) {
|
|
|
746
746
|
return Xa(c, a, b);
|
|
747
747
|
}));
|
|
748
748
|
}
|
|
749
|
-
var Za, $a, db = {
|
|
749
|
+
var Za, $a, db = {449500:(a, b, c, d, e) => {
|
|
750
750
|
if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
|
|
751
751
|
return 0;
|
|
752
752
|
}
|
|
@@ -809,9 +809,9 @@ var Za, $a, db = {448252:(a, b, c, d, e) => {
|
|
|
809
809
|
}
|
|
810
810
|
window.h.Aa += 1;
|
|
811
811
|
return 1;
|
|
812
|
-
},
|
|
812
|
+
}, 451678:() => {
|
|
813
813
|
"undefined" !== typeof window.h && (--window.h.Aa, 0 === window.h.Aa && delete window.h);
|
|
814
|
-
},
|
|
814
|
+
}, 451842:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 451946:() => {
|
|
815
815
|
try {
|
|
816
816
|
var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
|
|
817
817
|
a.close();
|
|
@@ -819,7 +819,7 @@ var Za, $a, db = {448252:(a, b, c, d, e) => {
|
|
|
819
819
|
} catch (c) {
|
|
820
820
|
return 0;
|
|
821
821
|
}
|
|
822
|
-
},
|
|
822
|
+
}, 452117:(a, b, c, d, e, f) => {
|
|
823
823
|
if ("undefined" === typeof window.h) {
|
|
824
824
|
return -1;
|
|
825
825
|
}
|
|
@@ -865,7 +865,7 @@ var Za, $a, db = {448252:(a, b, c, d, e) => {
|
|
|
865
865
|
a == window.h.I.ya && g.Z.connect(g.J.destination);
|
|
866
866
|
g.pb = f;
|
|
867
867
|
return window.h.yc(g);
|
|
868
|
-
},
|
|
868
|
+
}, 454994:a => window.h.ra(a).J.sampleRate, 455067:a => {
|
|
869
869
|
a = window.h.ra(a);
|
|
870
870
|
void 0 !== a.Z && (a.Z.onaudioprocess = function() {
|
|
871
871
|
}, a.Z.disconnect(), a.Z = void 0);
|
|
@@ -873,13 +873,13 @@ var Za, $a, db = {448252:(a, b, c, d, e) => {
|
|
|
873
873
|
a.J.close();
|
|
874
874
|
a.J = void 0;
|
|
875
875
|
a.pb = void 0;
|
|
876
|
-
},
|
|
876
|
+
}, 455467:a => {
|
|
877
877
|
window.h.Cb(a);
|
|
878
|
-
},
|
|
878
|
+
}, 455517:a => {
|
|
879
879
|
a = window.h.ra(a);
|
|
880
880
|
a.J.resume();
|
|
881
881
|
a.state = window.h.ga.xb;
|
|
882
|
-
},
|
|
882
|
+
}, 455656:a => {
|
|
883
883
|
a = window.h.ra(a);
|
|
884
884
|
a.J.suspend();
|
|
885
885
|
a.state = window.h.ga.stopped;
|
|
@@ -3039,6 +3039,8 @@ var Xd = {__syscall_fcntl64:function(a, b, c) {
|
|
|
3039
3039
|
return sc(a[b]);
|
|
3040
3040
|
}, _emval_incref:function(a) {
|
|
3041
3041
|
4 < a && (U.get(a).tb += 1);
|
|
3042
|
+
}, _emval_new_array:function() {
|
|
3043
|
+
return sc([]);
|
|
3042
3044
|
}, _emval_new_cstring:function(a) {
|
|
3043
3045
|
return sc(Gd(a));
|
|
3044
3046
|
}, _emval_new_object:function() {
|
|
@@ -3284,12 +3286,12 @@ var Xd = {__syscall_fcntl64:function(a, b, c) {
|
|
|
3284
3286
|
try {
|
|
3285
3287
|
return m.instantiateWasm(b, a);
|
|
3286
3288
|
} catch (c) {
|
|
3287
|
-
xa("Module.instantiateWasm callback failed with error: " + c),
|
|
3289
|
+
xa("Module.instantiateWasm callback failed with error: " + c), ba(c);
|
|
3288
3290
|
}
|
|
3289
3291
|
}
|
|
3290
3292
|
Ya(b, function(c) {
|
|
3291
3293
|
a(c.instance);
|
|
3292
|
-
}).catch(
|
|
3294
|
+
}).catch(ba);
|
|
3293
3295
|
return {};
|
|
3294
3296
|
})();
|
|
3295
3297
|
var Ec = a => (Ec = z.free)(a), Wd = a => (Wd = z.malloc)(a), ab = m._ma_device__on_notification_unlocked = a => (ab = m._ma_device__on_notification_unlocked = z.ma_device__on_notification_unlocked)(a);
|
|
@@ -3365,7 +3367,7 @@ $d();
|
|
|
3365
3367
|
/* 2 */
|
|
3366
3368
|
/***/ ((module) => {
|
|
3367
3369
|
|
|
3368
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.26.
|
|
3370
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.26.6","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_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
3369
3371
|
|
|
3370
3372
|
/***/ }),
|
|
3371
3373
|
/* 3 */
|
|
@@ -3824,6 +3826,7 @@ var __webpack_exports__ = {};
|
|
|
3824
3826
|
__webpack_require__.r(__webpack_exports__);
|
|
3825
3827
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3826
3828
|
/* harmony export */ Alignment: () => (/* binding */ Alignment),
|
|
3829
|
+
/* harmony export */ DataEnum: () => (/* binding */ DataEnum),
|
|
3827
3830
|
/* harmony export */ EventType: () => (/* binding */ EventType),
|
|
3828
3831
|
/* harmony export */ Fit: () => (/* binding */ Fit),
|
|
3829
3832
|
/* harmony export */ Layout: () => (/* binding */ Layout),
|
|
@@ -3835,6 +3838,15 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3835
3838
|
/* harmony export */ StateMachineInput: () => (/* binding */ StateMachineInput),
|
|
3836
3839
|
/* harmony export */ StateMachineInputType: () => (/* binding */ StateMachineInputType),
|
|
3837
3840
|
/* harmony export */ Testing: () => (/* binding */ Testing),
|
|
3841
|
+
/* harmony export */ ViewModel: () => (/* binding */ ViewModel),
|
|
3842
|
+
/* harmony export */ ViewModelInstance: () => (/* binding */ ViewModelInstance),
|
|
3843
|
+
/* harmony export */ ViewModelInstanceBoolean: () => (/* binding */ ViewModelInstanceBoolean),
|
|
3844
|
+
/* harmony export */ ViewModelInstanceColor: () => (/* binding */ ViewModelInstanceColor),
|
|
3845
|
+
/* harmony export */ ViewModelInstanceEnum: () => (/* binding */ ViewModelInstanceEnum),
|
|
3846
|
+
/* harmony export */ ViewModelInstanceNumber: () => (/* binding */ ViewModelInstanceNumber),
|
|
3847
|
+
/* harmony export */ ViewModelInstanceString: () => (/* binding */ ViewModelInstanceString),
|
|
3848
|
+
/* harmony export */ ViewModelInstanceTrigger: () => (/* binding */ ViewModelInstanceTrigger),
|
|
3849
|
+
/* harmony export */ ViewModelInstanceValue: () => (/* binding */ ViewModelInstanceValue),
|
|
3838
3850
|
/* harmony export */ decodeAudio: () => (/* binding */ decodeAudio),
|
|
3839
3851
|
/* harmony export */ decodeFont: () => (/* binding */ decodeFont),
|
|
3840
3852
|
/* harmony export */ decodeImage: () => (/* binding */ decodeImage)
|
|
@@ -3858,6 +3870,17 @@ var __extends = (undefined && undefined.__extends) || (function () {
|
|
|
3858
3870
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
3859
3871
|
};
|
|
3860
3872
|
})();
|
|
3873
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
3874
|
+
__assign = Object.assign || function(t) {
|
|
3875
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
3876
|
+
s = arguments[i];
|
|
3877
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
3878
|
+
t[p] = s[p];
|
|
3879
|
+
}
|
|
3880
|
+
return t;
|
|
3881
|
+
};
|
|
3882
|
+
return __assign.apply(this, arguments);
|
|
3883
|
+
};
|
|
3861
3884
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3862
3885
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3863
3886
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -4294,6 +4317,11 @@ var StateMachine = /** @class */ (function () {
|
|
|
4294
4317
|
this.inputs.length = 0;
|
|
4295
4318
|
this.instance.delete();
|
|
4296
4319
|
};
|
|
4320
|
+
StateMachine.prototype.bindViewModelInstance = function (viewModelInstance) {
|
|
4321
|
+
if (viewModelInstance.runtimeInstance != null) {
|
|
4322
|
+
this.instance.bindViewModelInstance(viewModelInstance.runtimeInstance);
|
|
4323
|
+
}
|
|
4324
|
+
};
|
|
4297
4325
|
return StateMachine;
|
|
4298
4326
|
}());
|
|
4299
4327
|
// #endregion
|
|
@@ -4440,6 +4468,9 @@ var Animator = /** @class */ (function () {
|
|
|
4440
4468
|
if (sm) {
|
|
4441
4469
|
var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
|
|
4442
4470
|
this.stateMachines.push(newStateMachine);
|
|
4471
|
+
if (!playing) {
|
|
4472
|
+
newStateMachine.advanceAndApply(0);
|
|
4473
|
+
}
|
|
4443
4474
|
}
|
|
4444
4475
|
else {
|
|
4445
4476
|
// In order to maintain compatibility with current behavior, if a state machine is not found
|
|
@@ -5185,6 +5216,8 @@ var Rive = /** @class */ (function () {
|
|
|
5185
5216
|
this._audioEventListener = null;
|
|
5186
5217
|
// draw method bound to the class
|
|
5187
5218
|
this._boundDraw = null;
|
|
5219
|
+
this._viewModelInstance = null;
|
|
5220
|
+
this._dataEnums = null;
|
|
5188
5221
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
5189
5222
|
this.durations = [];
|
|
5190
5223
|
this.frameTimes = [];
|
|
@@ -5270,6 +5303,7 @@ var Rive = /** @class */ (function () {
|
|
|
5270
5303
|
buffer: this.buffer,
|
|
5271
5304
|
riveFile: this.riveFile,
|
|
5272
5305
|
autoplay: params.autoplay,
|
|
5306
|
+
autoBind: params.autoBind,
|
|
5273
5307
|
animations: params.animations,
|
|
5274
5308
|
stateMachines: params.stateMachines,
|
|
5275
5309
|
artboard: params.artboard,
|
|
@@ -5288,7 +5322,7 @@ var Rive = /** @class */ (function () {
|
|
|
5288
5322
|
// Initializes the Rive object either from constructor or load()
|
|
5289
5323
|
Rive.prototype.init = function (_a) {
|
|
5290
5324
|
var _this = this;
|
|
5291
|
-
var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c;
|
|
5325
|
+
var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c, _d = _a.autoBind, autoBind = _d === void 0 ? false : _d;
|
|
5292
5326
|
if (this.destroyed) {
|
|
5293
5327
|
return;
|
|
5294
5328
|
}
|
|
@@ -5323,7 +5357,7 @@ var Rive = /** @class */ (function () {
|
|
|
5323
5357
|
_this.resizeDrawingSurfaceToCanvas();
|
|
5324
5358
|
}
|
|
5325
5359
|
// Load Rive data from a source uri or a data buffer
|
|
5326
|
-
_this.initData(artboard, startingAnimationNames, startingStateMachineNames, autoplay)
|
|
5360
|
+
_this.initData(artboard, startingAnimationNames, startingStateMachineNames, autoplay, autoBind)
|
|
5327
5361
|
.then(function () { return _this.setupRiveListeners(); })
|
|
5328
5362
|
.catch(function (e) {
|
|
5329
5363
|
console.error(e);
|
|
@@ -5404,7 +5438,7 @@ var Rive = /** @class */ (function () {
|
|
|
5404
5438
|
this._artboardHeight || this.artboard.height;
|
|
5405
5439
|
};
|
|
5406
5440
|
// Initializes runtime with Rive data and preps for playing
|
|
5407
|
-
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
5441
|
+
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
|
|
5408
5442
|
return __awaiter(this, void 0, void 0, function () {
|
|
5409
5443
|
var error_1, msg;
|
|
5410
5444
|
var _a;
|
|
@@ -5430,7 +5464,7 @@ var Rive = /** @class */ (function () {
|
|
|
5430
5464
|
}
|
|
5431
5465
|
this.file = this.riveFile.getInstance();
|
|
5432
5466
|
// Initialize and draw frame
|
|
5433
|
-
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
5467
|
+
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay, autoBind);
|
|
5434
5468
|
// Initialize the artboard size
|
|
5435
5469
|
this.initArtboardSize();
|
|
5436
5470
|
// Check for audio
|
|
@@ -5459,7 +5493,7 @@ var Rive = /** @class */ (function () {
|
|
|
5459
5493
|
});
|
|
5460
5494
|
};
|
|
5461
5495
|
// Initialize for playback
|
|
5462
|
-
Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
5496
|
+
Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
|
|
5463
5497
|
if (!this.file) {
|
|
5464
5498
|
return;
|
|
5465
5499
|
}
|
|
@@ -5504,13 +5538,24 @@ var Rive = /** @class */ (function () {
|
|
|
5504
5538
|
data: instanceNames,
|
|
5505
5539
|
},
|
|
5506
5540
|
});
|
|
5541
|
+
if (autoBind) {
|
|
5542
|
+
var viewModel = this.file.defaultArtboardViewModel(rootArtboard);
|
|
5543
|
+
if (viewModel !== null) {
|
|
5544
|
+
var runtimeInstance = viewModel.defaultInstance();
|
|
5545
|
+
if (runtimeInstance !== null) {
|
|
5546
|
+
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
5547
|
+
this.bindViewModelInstance(viewModelInstance);
|
|
5548
|
+
}
|
|
5549
|
+
}
|
|
5550
|
+
}
|
|
5507
5551
|
};
|
|
5508
5552
|
// Draws the current artboard frame
|
|
5509
5553
|
Rive.prototype.drawFrame = function () {
|
|
5510
|
-
var _a;
|
|
5554
|
+
var _a, _b;
|
|
5511
5555
|
if ((_a = document === null || document === void 0 ? void 0 : document.timeline) === null || _a === void 0 ? void 0 : _a.currentTime) {
|
|
5512
5556
|
if (this.loaded && this.artboard && !this.frameRequestId) {
|
|
5513
5557
|
this._boundDraw(document.timeline.currentTime);
|
|
5558
|
+
(_b = this.runtime) === null || _b === void 0 ? void 0 : _b.resolveAnimationFrame();
|
|
5514
5559
|
}
|
|
5515
5560
|
}
|
|
5516
5561
|
else {
|
|
@@ -5522,6 +5567,7 @@ var Rive = /** @class */ (function () {
|
|
|
5522
5567
|
* @param time the time at which to render a frame
|
|
5523
5568
|
*/
|
|
5524
5569
|
Rive.prototype.draw = function (time, onSecond) {
|
|
5570
|
+
var _a;
|
|
5525
5571
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
5526
5572
|
this.frameRequestId = null;
|
|
5527
5573
|
var before = performance.now();
|
|
@@ -5557,8 +5603,8 @@ var Rive = /** @class */ (function () {
|
|
|
5557
5603
|
// - Advance non-paused state machines by the elapsed number of seconds
|
|
5558
5604
|
// - Advance to the first frame even when autoplay is false
|
|
5559
5605
|
var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
|
|
5560
|
-
for (var
|
|
5561
|
-
var stateMachine = activeStateMachines_1[
|
|
5606
|
+
for (var _b = 0, activeStateMachines_1 = activeStateMachines; _b < activeStateMachines_1.length; _b++) {
|
|
5607
|
+
var stateMachine = activeStateMachines_1[_b];
|
|
5562
5608
|
// Check for events before the current frame's state machine advance
|
|
5563
5609
|
var numEventsReported = stateMachine.reportedEventCount();
|
|
5564
5610
|
if (numEventsReported) {
|
|
@@ -5573,7 +5619,7 @@ var Rive = /** @class */ (function () {
|
|
|
5573
5619
|
// Handle the event side effect if explicitly enabled
|
|
5574
5620
|
if (this.automaticallyHandleEvents) {
|
|
5575
5621
|
var newAnchorTag = document.createElement("a");
|
|
5576
|
-
var
|
|
5622
|
+
var _c = event_1, url = _c.url, target = _c.target;
|
|
5577
5623
|
var sanitizedUrl = (0,_utils__WEBPACK_IMPORTED_MODULE_3__.sanitizeUrl)(url);
|
|
5578
5624
|
url && newAnchorTag.setAttribute("href", sanitizedUrl);
|
|
5579
5625
|
target && newAnchorTag.setAttribute("target", target);
|
|
@@ -5626,6 +5672,7 @@ var Rive = /** @class */ (function () {
|
|
|
5626
5672
|
this.frameTimes.shift();
|
|
5627
5673
|
this.durations.shift();
|
|
5628
5674
|
}
|
|
5675
|
+
(_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.handleCallbacks();
|
|
5629
5676
|
// Calling requestAnimationFrame will rerun draw() at the correct rate:
|
|
5630
5677
|
// https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
|
|
5631
5678
|
if (this.animator.isPlaying) {
|
|
@@ -5683,7 +5730,7 @@ var Rive = /** @class */ (function () {
|
|
|
5683
5730
|
* Rive class
|
|
5684
5731
|
*/
|
|
5685
5732
|
Rive.prototype.cleanup = function () {
|
|
5686
|
-
var _a;
|
|
5733
|
+
var _a, _b;
|
|
5687
5734
|
this.destroyed = true;
|
|
5688
5735
|
// Stop the renderer if it hasn't already been stopped.
|
|
5689
5736
|
this.stopRendering();
|
|
@@ -5704,6 +5751,9 @@ var Rive = /** @class */ (function () {
|
|
|
5704
5751
|
audioManager.remove(this._audioEventListener);
|
|
5705
5752
|
this._audioEventListener = null;
|
|
5706
5753
|
}
|
|
5754
|
+
(_b = this._viewModelInstance) === null || _b === void 0 ? void 0 : _b.cleanup();
|
|
5755
|
+
this._viewModelInstance = null;
|
|
5756
|
+
this._dataEnums = null;
|
|
5707
5757
|
};
|
|
5708
5758
|
/**
|
|
5709
5759
|
* Cleans up the Renderer object. Only call this API if you no longer
|
|
@@ -5855,16 +5905,17 @@ var Rive = /** @class */ (function () {
|
|
|
5855
5905
|
*
|
|
5856
5906
|
*/
|
|
5857
5907
|
Rive.prototype.reset = function (params) {
|
|
5858
|
-
var _a;
|
|
5908
|
+
var _a, _b;
|
|
5859
5909
|
// Get the current artboard, animations, state machines, and playback states
|
|
5860
5910
|
var artBoardName = params === null || params === void 0 ? void 0 : params.artboard;
|
|
5861
5911
|
var animationNames = mapToStringArray(params === null || params === void 0 ? void 0 : params.animations);
|
|
5862
5912
|
var stateMachineNames = mapToStringArray(params === null || params === void 0 ? void 0 : params.stateMachines);
|
|
5863
5913
|
var autoplay = (_a = params === null || params === void 0 ? void 0 : params.autoplay) !== null && _a !== void 0 ? _a : false;
|
|
5914
|
+
var autoBind = (_b = params === null || params === void 0 ? void 0 : params.autoBind) !== null && _b !== void 0 ? _b : false;
|
|
5864
5915
|
// Stop everything and clean up
|
|
5865
5916
|
this.cleanupInstances();
|
|
5866
5917
|
// Reinitialize an artboard instance with the state
|
|
5867
|
-
this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay);
|
|
5918
|
+
this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay, autoBind);
|
|
5868
5919
|
this.taskQueue.process();
|
|
5869
5920
|
};
|
|
5870
5921
|
// Loads a new Rive file, keeping listeners in place
|
|
@@ -6487,6 +6538,62 @@ var Rive = /** @class */ (function () {
|
|
|
6487
6538
|
enumerable: false,
|
|
6488
6539
|
configurable: true
|
|
6489
6540
|
});
|
|
6541
|
+
/**
|
|
6542
|
+
* Initialize the data context with the view model instance.
|
|
6543
|
+
*/
|
|
6544
|
+
Rive.prototype.bindViewModelInstance = function (viewModelInstance) {
|
|
6545
|
+
var _a;
|
|
6546
|
+
if (this.artboard && !this.destroyed) {
|
|
6547
|
+
if (viewModelInstance && viewModelInstance.runtimeInstance) {
|
|
6548
|
+
viewModelInstance.internalIncrementReferenceCount();
|
|
6549
|
+
(_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.cleanup();
|
|
6550
|
+
this._viewModelInstance = viewModelInstance;
|
|
6551
|
+
this.artboard.bindViewModelInstance(viewModelInstance.runtimeInstance);
|
|
6552
|
+
this.animator.stateMachines.forEach(function (stateMachine) {
|
|
6553
|
+
return stateMachine.bindViewModelInstance(viewModelInstance);
|
|
6554
|
+
});
|
|
6555
|
+
}
|
|
6556
|
+
}
|
|
6557
|
+
};
|
|
6558
|
+
Object.defineProperty(Rive.prototype, "viewModelInstance", {
|
|
6559
|
+
get: function () {
|
|
6560
|
+
return this._viewModelInstance;
|
|
6561
|
+
},
|
|
6562
|
+
enumerable: false,
|
|
6563
|
+
configurable: true
|
|
6564
|
+
});
|
|
6565
|
+
Rive.prototype.viewModelByIndex = function (index) {
|
|
6566
|
+
var viewModel = this.file.viewModelByIndex(index);
|
|
6567
|
+
if (viewModel !== null) {
|
|
6568
|
+
return new ViewModel(viewModel);
|
|
6569
|
+
}
|
|
6570
|
+
return null;
|
|
6571
|
+
};
|
|
6572
|
+
Rive.prototype.viewModelByName = function (name) {
|
|
6573
|
+
var viewModel = this.file.viewModelByName(name);
|
|
6574
|
+
if (viewModel !== null) {
|
|
6575
|
+
return new ViewModel(viewModel);
|
|
6576
|
+
}
|
|
6577
|
+
return null;
|
|
6578
|
+
};
|
|
6579
|
+
Rive.prototype.enums = function () {
|
|
6580
|
+
if (this._dataEnums === null) {
|
|
6581
|
+
var dataEnums = this.file.enums();
|
|
6582
|
+
this._dataEnums = dataEnums.map(function (dataEnum) {
|
|
6583
|
+
return new DataEnum(dataEnum);
|
|
6584
|
+
});
|
|
6585
|
+
}
|
|
6586
|
+
return this._dataEnums;
|
|
6587
|
+
};
|
|
6588
|
+
Rive.prototype.defaultViewModel = function () {
|
|
6589
|
+
if (this.artboard) {
|
|
6590
|
+
var viewModel = this.file.defaultArtboardViewModel(this.artboard);
|
|
6591
|
+
if (viewModel) {
|
|
6592
|
+
return new ViewModel(viewModel);
|
|
6593
|
+
}
|
|
6594
|
+
}
|
|
6595
|
+
return null;
|
|
6596
|
+
};
|
|
6490
6597
|
// Error message for missing source or buffer
|
|
6491
6598
|
Rive.missingErrorMessage = "Rive source file or data buffer required";
|
|
6492
6599
|
// Error message for removed rive file
|
|
@@ -6494,6 +6601,481 @@ var Rive = /** @class */ (function () {
|
|
|
6494
6601
|
return Rive;
|
|
6495
6602
|
}());
|
|
6496
6603
|
|
|
6604
|
+
var ViewModel = /** @class */ (function () {
|
|
6605
|
+
function ViewModel(viewModel) {
|
|
6606
|
+
this._viewModel = viewModel;
|
|
6607
|
+
}
|
|
6608
|
+
Object.defineProperty(ViewModel.prototype, "instanceCount", {
|
|
6609
|
+
get: function () {
|
|
6610
|
+
return this._viewModel.instanceCount;
|
|
6611
|
+
},
|
|
6612
|
+
enumerable: false,
|
|
6613
|
+
configurable: true
|
|
6614
|
+
});
|
|
6615
|
+
Object.defineProperty(ViewModel.prototype, "name", {
|
|
6616
|
+
get: function () {
|
|
6617
|
+
return this._viewModel.name;
|
|
6618
|
+
},
|
|
6619
|
+
enumerable: false,
|
|
6620
|
+
configurable: true
|
|
6621
|
+
});
|
|
6622
|
+
ViewModel.prototype.instanceByIndex = function (index) {
|
|
6623
|
+
var instance = this._viewModel.instanceByIndex(index);
|
|
6624
|
+
if (instance !== null) {
|
|
6625
|
+
return new ViewModelInstance(instance, null);
|
|
6626
|
+
}
|
|
6627
|
+
return null;
|
|
6628
|
+
};
|
|
6629
|
+
ViewModel.prototype.instanceByName = function (name) {
|
|
6630
|
+
var instance = this._viewModel.instanceByName(name);
|
|
6631
|
+
if (instance !== null) {
|
|
6632
|
+
return new ViewModelInstance(instance, null);
|
|
6633
|
+
}
|
|
6634
|
+
return null;
|
|
6635
|
+
};
|
|
6636
|
+
ViewModel.prototype.defaultInstance = function () {
|
|
6637
|
+
var runtimeInstance = this._viewModel.defaultInstance();
|
|
6638
|
+
if (runtimeInstance !== null) {
|
|
6639
|
+
return new ViewModelInstance(runtimeInstance, null);
|
|
6640
|
+
}
|
|
6641
|
+
return null;
|
|
6642
|
+
};
|
|
6643
|
+
ViewModel.prototype.instance = function () {
|
|
6644
|
+
var runtimeInstance = this._viewModel.instance();
|
|
6645
|
+
if (runtimeInstance !== null) {
|
|
6646
|
+
return new ViewModelInstance(runtimeInstance, null);
|
|
6647
|
+
}
|
|
6648
|
+
return null;
|
|
6649
|
+
};
|
|
6650
|
+
Object.defineProperty(ViewModel.prototype, "properties", {
|
|
6651
|
+
get: function () {
|
|
6652
|
+
return this._viewModel.getProperties();
|
|
6653
|
+
},
|
|
6654
|
+
enumerable: false,
|
|
6655
|
+
configurable: true
|
|
6656
|
+
});
|
|
6657
|
+
Object.defineProperty(ViewModel.prototype, "instanceNames", {
|
|
6658
|
+
get: function () {
|
|
6659
|
+
return this._viewModel.getInstanceNames();
|
|
6660
|
+
},
|
|
6661
|
+
enumerable: false,
|
|
6662
|
+
configurable: true
|
|
6663
|
+
});
|
|
6664
|
+
return ViewModel;
|
|
6665
|
+
}());
|
|
6666
|
+
|
|
6667
|
+
var DataEnum = /** @class */ (function () {
|
|
6668
|
+
function DataEnum(dataEnum) {
|
|
6669
|
+
this._dataEnum = dataEnum;
|
|
6670
|
+
}
|
|
6671
|
+
Object.defineProperty(DataEnum.prototype, "name", {
|
|
6672
|
+
get: function () {
|
|
6673
|
+
return this._dataEnum.name;
|
|
6674
|
+
},
|
|
6675
|
+
enumerable: false,
|
|
6676
|
+
configurable: true
|
|
6677
|
+
});
|
|
6678
|
+
Object.defineProperty(DataEnum.prototype, "values", {
|
|
6679
|
+
get: function () {
|
|
6680
|
+
return this._dataEnum.values;
|
|
6681
|
+
},
|
|
6682
|
+
enumerable: false,
|
|
6683
|
+
configurable: true
|
|
6684
|
+
});
|
|
6685
|
+
return DataEnum;
|
|
6686
|
+
}());
|
|
6687
|
+
|
|
6688
|
+
var ViewModelInstance = /** @class */ (function () {
|
|
6689
|
+
function ViewModelInstance(runtimeInstance, root) {
|
|
6690
|
+
this._propertiesWithCallbacks = [];
|
|
6691
|
+
this._referenceCount = 0;
|
|
6692
|
+
this._runtimeInstance = runtimeInstance;
|
|
6693
|
+
this._root = root || this;
|
|
6694
|
+
}
|
|
6695
|
+
Object.defineProperty(ViewModelInstance.prototype, "runtimeInstance", {
|
|
6696
|
+
get: function () {
|
|
6697
|
+
return this._runtimeInstance;
|
|
6698
|
+
},
|
|
6699
|
+
enumerable: false,
|
|
6700
|
+
configurable: true
|
|
6701
|
+
});
|
|
6702
|
+
ViewModelInstance.prototype.handleCallbacks = function () {
|
|
6703
|
+
if (this._propertiesWithCallbacks.length !== 0) {
|
|
6704
|
+
this._propertiesWithCallbacks.forEach(function (property) {
|
|
6705
|
+
property.handleCallbacks();
|
|
6706
|
+
});
|
|
6707
|
+
}
|
|
6708
|
+
};
|
|
6709
|
+
ViewModelInstance.prototype.clearCallbacks = function () {
|
|
6710
|
+
this._propertiesWithCallbacks.forEach(function (property) {
|
|
6711
|
+
property.clearCallbacks();
|
|
6712
|
+
});
|
|
6713
|
+
};
|
|
6714
|
+
/**
|
|
6715
|
+
* method to access a property instance of type number belonging
|
|
6716
|
+
* to the view model instance or to a nested view model instance
|
|
6717
|
+
* @param path - path to the number property
|
|
6718
|
+
*/
|
|
6719
|
+
ViewModelInstance.prototype.number = function (path) {
|
|
6720
|
+
var _a;
|
|
6721
|
+
var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.number(path);
|
|
6722
|
+
if (instance) {
|
|
6723
|
+
return new ViewModelInstanceNumber(instance, this._root);
|
|
6724
|
+
}
|
|
6725
|
+
return null;
|
|
6726
|
+
};
|
|
6727
|
+
/**
|
|
6728
|
+
* method to access a property instance of type string belonging
|
|
6729
|
+
* to the view model instance or to a nested view model instance
|
|
6730
|
+
* @param path - path to the number property
|
|
6731
|
+
*/
|
|
6732
|
+
ViewModelInstance.prototype.string = function (path) {
|
|
6733
|
+
var _a;
|
|
6734
|
+
var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.string(path);
|
|
6735
|
+
if (instance) {
|
|
6736
|
+
return new ViewModelInstanceString(instance, this._root);
|
|
6737
|
+
}
|
|
6738
|
+
return null;
|
|
6739
|
+
};
|
|
6740
|
+
/**
|
|
6741
|
+
* method to access a property instance of type boolean belonging
|
|
6742
|
+
* to the view model instance or to a nested view model instance
|
|
6743
|
+
* @param path - path to the number property
|
|
6744
|
+
*/
|
|
6745
|
+
ViewModelInstance.prototype.boolean = function (path) {
|
|
6746
|
+
var _a;
|
|
6747
|
+
var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.boolean(path);
|
|
6748
|
+
if (instance) {
|
|
6749
|
+
return new ViewModelInstanceBoolean(instance, this._root);
|
|
6750
|
+
}
|
|
6751
|
+
return null;
|
|
6752
|
+
};
|
|
6753
|
+
/**
|
|
6754
|
+
* method to access a property instance of type color belonging
|
|
6755
|
+
* to the view model instance or to a nested view model instance
|
|
6756
|
+
* @param path - path to the number property
|
|
6757
|
+
*/
|
|
6758
|
+
ViewModelInstance.prototype.color = function (path) {
|
|
6759
|
+
var _a;
|
|
6760
|
+
var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.color(path);
|
|
6761
|
+
if (instance) {
|
|
6762
|
+
return new ViewModelInstanceColor(instance, this._root);
|
|
6763
|
+
}
|
|
6764
|
+
return null;
|
|
6765
|
+
};
|
|
6766
|
+
/**
|
|
6767
|
+
* method to access a property instance of type trigger belonging
|
|
6768
|
+
* to the view model instance or to a nested view model instance
|
|
6769
|
+
* @param path - path to the number property
|
|
6770
|
+
*/
|
|
6771
|
+
ViewModelInstance.prototype.trigger = function (path) {
|
|
6772
|
+
var _a;
|
|
6773
|
+
var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.trigger(path);
|
|
6774
|
+
if (instance) {
|
|
6775
|
+
return new ViewModelInstanceTrigger(instance, this._root);
|
|
6776
|
+
}
|
|
6777
|
+
return null;
|
|
6778
|
+
};
|
|
6779
|
+
/**
|
|
6780
|
+
* method to access a property instance of type enum belonging
|
|
6781
|
+
* to the view model instance or to a nested view model instance
|
|
6782
|
+
* @param path - path to the number property
|
|
6783
|
+
*/
|
|
6784
|
+
ViewModelInstance.prototype.enum = function (path) {
|
|
6785
|
+
var _a;
|
|
6786
|
+
var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.enum(path);
|
|
6787
|
+
if (instance) {
|
|
6788
|
+
return new ViewModelInstanceEnum(instance, this._root);
|
|
6789
|
+
}
|
|
6790
|
+
return null;
|
|
6791
|
+
};
|
|
6792
|
+
/**
|
|
6793
|
+
* method to access a view model property instance belonging
|
|
6794
|
+
* to the view model instance or to a nested view model instance
|
|
6795
|
+
* @param path - path to the number property
|
|
6796
|
+
*/
|
|
6797
|
+
ViewModelInstance.prototype.viewModel = function (path) {
|
|
6798
|
+
var _a;
|
|
6799
|
+
var viewModelInstance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.viewModel(path);
|
|
6800
|
+
if (viewModelInstance) {
|
|
6801
|
+
return new ViewModelInstance(viewModelInstance, this._root);
|
|
6802
|
+
}
|
|
6803
|
+
return null;
|
|
6804
|
+
};
|
|
6805
|
+
/**
|
|
6806
|
+
* method to replace a view model property with another view model value
|
|
6807
|
+
* @param path - path to the view model property
|
|
6808
|
+
* @param value - view model that will replace the original
|
|
6809
|
+
*/
|
|
6810
|
+
ViewModelInstance.prototype.replaceViewModel = function (path, value) {
|
|
6811
|
+
var _a;
|
|
6812
|
+
if (value.runtimeInstance !== null) {
|
|
6813
|
+
return (((_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.replaceViewModel(path, value.runtimeInstance)) ||
|
|
6814
|
+
false);
|
|
6815
|
+
}
|
|
6816
|
+
return false;
|
|
6817
|
+
};
|
|
6818
|
+
/*
|
|
6819
|
+
* method for internal use, it shouldn't be called externally
|
|
6820
|
+
*/
|
|
6821
|
+
ViewModelInstance.prototype.addToCallbacks = function (property) {
|
|
6822
|
+
if (!this._propertiesWithCallbacks.includes(property)) {
|
|
6823
|
+
this._propertiesWithCallbacks.push(property);
|
|
6824
|
+
}
|
|
6825
|
+
};
|
|
6826
|
+
/*
|
|
6827
|
+
* method for internal use, it shouldn't be called externally
|
|
6828
|
+
*/
|
|
6829
|
+
ViewModelInstance.prototype.removeFromCallbacks = function (property) {
|
|
6830
|
+
if (this._propertiesWithCallbacks.includes(property)) {
|
|
6831
|
+
this._propertiesWithCallbacks = this._propertiesWithCallbacks.filter(function (prop) { return prop !== property; });
|
|
6832
|
+
}
|
|
6833
|
+
};
|
|
6834
|
+
/*
|
|
6835
|
+
* method to add one to the reference counter of the instance.
|
|
6836
|
+
* Use if the file owning the reference is destroyed but the instance needs to stay around
|
|
6837
|
+
*/
|
|
6838
|
+
ViewModelInstance.prototype.incrementReferenceCount = function () {
|
|
6839
|
+
var _a;
|
|
6840
|
+
this._referenceCount++;
|
|
6841
|
+
(_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.incrementReferenceCount();
|
|
6842
|
+
};
|
|
6843
|
+
/*
|
|
6844
|
+
* method to subtract one to the reference counter of the instance.
|
|
6845
|
+
* Use if incrementReferenceCount has been called
|
|
6846
|
+
*/
|
|
6847
|
+
ViewModelInstance.prototype.decrementReferenceCount = function () {
|
|
6848
|
+
var _a;
|
|
6849
|
+
this._referenceCount--;
|
|
6850
|
+
(_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.decrementReferenceCount();
|
|
6851
|
+
};
|
|
6852
|
+
Object.defineProperty(ViewModelInstance.prototype, "properties", {
|
|
6853
|
+
get: function () {
|
|
6854
|
+
var _a;
|
|
6855
|
+
return (((_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.getProperties().map(function (prop) { return (__assign({}, prop)); })) || []);
|
|
6856
|
+
},
|
|
6857
|
+
enumerable: false,
|
|
6858
|
+
configurable: true
|
|
6859
|
+
});
|
|
6860
|
+
ViewModelInstance.prototype.internalIncrementReferenceCount = function () {
|
|
6861
|
+
this._referenceCount++;
|
|
6862
|
+
};
|
|
6863
|
+
ViewModelInstance.prototype.cleanup = function () {
|
|
6864
|
+
this._referenceCount--;
|
|
6865
|
+
if (this._referenceCount <= 0) {
|
|
6866
|
+
this._runtimeInstance = null;
|
|
6867
|
+
this.clearCallbacks();
|
|
6868
|
+
this._propertiesWithCallbacks = [];
|
|
6869
|
+
}
|
|
6870
|
+
};
|
|
6871
|
+
return ViewModelInstance;
|
|
6872
|
+
}());
|
|
6873
|
+
|
|
6874
|
+
var ViewModelInstanceValue = /** @class */ (function () {
|
|
6875
|
+
function ViewModelInstanceValue(instance, root) {
|
|
6876
|
+
this.callbacks = [];
|
|
6877
|
+
this._viewModelInstanceValue = instance;
|
|
6878
|
+
this._rootViewModel = root;
|
|
6879
|
+
}
|
|
6880
|
+
ViewModelInstanceValue.prototype.on = function (callback) {
|
|
6881
|
+
// Since we don't clean the changed flag for properties that don't have listeners,
|
|
6882
|
+
// we clean it the first time we add a listener to it
|
|
6883
|
+
if (this.callbacks.length === 0) {
|
|
6884
|
+
this._viewModelInstanceValue.clearChanges();
|
|
6885
|
+
}
|
|
6886
|
+
if (!this.callbacks.includes(callback)) {
|
|
6887
|
+
this.callbacks.push(callback);
|
|
6888
|
+
this._rootViewModel.addToCallbacks(this);
|
|
6889
|
+
}
|
|
6890
|
+
};
|
|
6891
|
+
ViewModelInstanceValue.prototype.off = function (callback) {
|
|
6892
|
+
if (!callback) {
|
|
6893
|
+
this.callbacks.length = 0;
|
|
6894
|
+
}
|
|
6895
|
+
else {
|
|
6896
|
+
this.callbacks = this.callbacks.filter(function (cb) { return cb !== callback; });
|
|
6897
|
+
}
|
|
6898
|
+
if (this.callbacks.length === 0) {
|
|
6899
|
+
this._rootViewModel.removeFromCallbacks(this);
|
|
6900
|
+
}
|
|
6901
|
+
};
|
|
6902
|
+
ViewModelInstanceValue.prototype.internalHandleCallback = function (callback) { };
|
|
6903
|
+
ViewModelInstanceValue.prototype.handleCallbacks = function () {
|
|
6904
|
+
var _this = this;
|
|
6905
|
+
if (this._viewModelInstanceValue.hasChanged) {
|
|
6906
|
+
this._viewModelInstanceValue.clearChanges();
|
|
6907
|
+
this.callbacks.forEach(function (callback) {
|
|
6908
|
+
_this.internalHandleCallback(callback);
|
|
6909
|
+
});
|
|
6910
|
+
}
|
|
6911
|
+
};
|
|
6912
|
+
ViewModelInstanceValue.prototype.clearCallbacks = function () {
|
|
6913
|
+
this.callbacks.length = 0;
|
|
6914
|
+
};
|
|
6915
|
+
Object.defineProperty(ViewModelInstanceValue.prototype, "name", {
|
|
6916
|
+
get: function () {
|
|
6917
|
+
return this._viewModelInstanceValue.name;
|
|
6918
|
+
},
|
|
6919
|
+
enumerable: false,
|
|
6920
|
+
configurable: true
|
|
6921
|
+
});
|
|
6922
|
+
return ViewModelInstanceValue;
|
|
6923
|
+
}());
|
|
6924
|
+
|
|
6925
|
+
var ViewModelInstanceString = /** @class */ (function (_super) {
|
|
6926
|
+
__extends(ViewModelInstanceString, _super);
|
|
6927
|
+
function ViewModelInstanceString(instance, root) {
|
|
6928
|
+
return _super.call(this, instance, root) || this;
|
|
6929
|
+
}
|
|
6930
|
+
Object.defineProperty(ViewModelInstanceString.prototype, "value", {
|
|
6931
|
+
get: function () {
|
|
6932
|
+
return this._viewModelInstanceValue.value;
|
|
6933
|
+
},
|
|
6934
|
+
set: function (val) {
|
|
6935
|
+
this._viewModelInstanceValue.value = val;
|
|
6936
|
+
},
|
|
6937
|
+
enumerable: false,
|
|
6938
|
+
configurable: true
|
|
6939
|
+
});
|
|
6940
|
+
ViewModelInstanceString.prototype.internalHandleCallback = function (callback) {
|
|
6941
|
+
callback(this.value);
|
|
6942
|
+
};
|
|
6943
|
+
return ViewModelInstanceString;
|
|
6944
|
+
}(ViewModelInstanceValue));
|
|
6945
|
+
|
|
6946
|
+
var ViewModelInstanceNumber = /** @class */ (function (_super) {
|
|
6947
|
+
__extends(ViewModelInstanceNumber, _super);
|
|
6948
|
+
function ViewModelInstanceNumber(instance, root) {
|
|
6949
|
+
return _super.call(this, instance, root) || this;
|
|
6950
|
+
}
|
|
6951
|
+
Object.defineProperty(ViewModelInstanceNumber.prototype, "value", {
|
|
6952
|
+
get: function () {
|
|
6953
|
+
return this._viewModelInstanceValue.value;
|
|
6954
|
+
},
|
|
6955
|
+
set: function (val) {
|
|
6956
|
+
this._viewModelInstanceValue.value = val;
|
|
6957
|
+
},
|
|
6958
|
+
enumerable: false,
|
|
6959
|
+
configurable: true
|
|
6960
|
+
});
|
|
6961
|
+
ViewModelInstanceNumber.prototype.internalHandleCallback = function (callback) {
|
|
6962
|
+
callback(this.value);
|
|
6963
|
+
};
|
|
6964
|
+
return ViewModelInstanceNumber;
|
|
6965
|
+
}(ViewModelInstanceValue));
|
|
6966
|
+
|
|
6967
|
+
var ViewModelInstanceBoolean = /** @class */ (function (_super) {
|
|
6968
|
+
__extends(ViewModelInstanceBoolean, _super);
|
|
6969
|
+
function ViewModelInstanceBoolean(instance, root) {
|
|
6970
|
+
return _super.call(this, instance, root) || this;
|
|
6971
|
+
}
|
|
6972
|
+
Object.defineProperty(ViewModelInstanceBoolean.prototype, "value", {
|
|
6973
|
+
get: function () {
|
|
6974
|
+
return this._viewModelInstanceValue.value;
|
|
6975
|
+
},
|
|
6976
|
+
set: function (val) {
|
|
6977
|
+
this._viewModelInstanceValue.value = val;
|
|
6978
|
+
},
|
|
6979
|
+
enumerable: false,
|
|
6980
|
+
configurable: true
|
|
6981
|
+
});
|
|
6982
|
+
ViewModelInstanceBoolean.prototype.internalHandleCallback = function (callback) {
|
|
6983
|
+
callback(this.value);
|
|
6984
|
+
};
|
|
6985
|
+
return ViewModelInstanceBoolean;
|
|
6986
|
+
}(ViewModelInstanceValue));
|
|
6987
|
+
|
|
6988
|
+
var ViewModelInstanceTrigger = /** @class */ (function (_super) {
|
|
6989
|
+
__extends(ViewModelInstanceTrigger, _super);
|
|
6990
|
+
function ViewModelInstanceTrigger(instance, root) {
|
|
6991
|
+
return _super.call(this, instance, root) || this;
|
|
6992
|
+
}
|
|
6993
|
+
ViewModelInstanceTrigger.prototype.trigger = function () {
|
|
6994
|
+
return this._viewModelInstanceValue.trigger();
|
|
6995
|
+
};
|
|
6996
|
+
ViewModelInstanceTrigger.prototype.internalHandleCallback = function (callback) {
|
|
6997
|
+
callback();
|
|
6998
|
+
};
|
|
6999
|
+
return ViewModelInstanceTrigger;
|
|
7000
|
+
}(ViewModelInstanceValue));
|
|
7001
|
+
|
|
7002
|
+
var ViewModelInstanceEnum = /** @class */ (function (_super) {
|
|
7003
|
+
__extends(ViewModelInstanceEnum, _super);
|
|
7004
|
+
function ViewModelInstanceEnum(instance, root) {
|
|
7005
|
+
return _super.call(this, instance, root) || this;
|
|
7006
|
+
}
|
|
7007
|
+
Object.defineProperty(ViewModelInstanceEnum.prototype, "value", {
|
|
7008
|
+
get: function () {
|
|
7009
|
+
return this._viewModelInstanceValue.value;
|
|
7010
|
+
},
|
|
7011
|
+
set: function (val) {
|
|
7012
|
+
this._viewModelInstanceValue.value = val;
|
|
7013
|
+
},
|
|
7014
|
+
enumerable: false,
|
|
7015
|
+
configurable: true
|
|
7016
|
+
});
|
|
7017
|
+
Object.defineProperty(ViewModelInstanceEnum.prototype, "valueIndex", {
|
|
7018
|
+
get: function () {
|
|
7019
|
+
return this._viewModelInstanceValue
|
|
7020
|
+
.valueIndex;
|
|
7021
|
+
},
|
|
7022
|
+
set: function (val) {
|
|
7023
|
+
this._viewModelInstanceValue.valueIndex = val;
|
|
7024
|
+
},
|
|
7025
|
+
enumerable: false,
|
|
7026
|
+
configurable: true
|
|
7027
|
+
});
|
|
7028
|
+
Object.defineProperty(ViewModelInstanceEnum.prototype, "values", {
|
|
7029
|
+
get: function () {
|
|
7030
|
+
return this._viewModelInstanceValue.values;
|
|
7031
|
+
},
|
|
7032
|
+
enumerable: false,
|
|
7033
|
+
configurable: true
|
|
7034
|
+
});
|
|
7035
|
+
ViewModelInstanceEnum.prototype.internalHandleCallback = function (callback) {
|
|
7036
|
+
callback(this.value);
|
|
7037
|
+
};
|
|
7038
|
+
return ViewModelInstanceEnum;
|
|
7039
|
+
}(ViewModelInstanceValue));
|
|
7040
|
+
|
|
7041
|
+
var ViewModelInstanceColor = /** @class */ (function (_super) {
|
|
7042
|
+
__extends(ViewModelInstanceColor, _super);
|
|
7043
|
+
function ViewModelInstanceColor(instance, root) {
|
|
7044
|
+
return _super.call(this, instance, root) || this;
|
|
7045
|
+
}
|
|
7046
|
+
Object.defineProperty(ViewModelInstanceColor.prototype, "value", {
|
|
7047
|
+
get: function () {
|
|
7048
|
+
return this._viewModelInstanceValue.value;
|
|
7049
|
+
},
|
|
7050
|
+
set: function (val) {
|
|
7051
|
+
this._viewModelInstanceValue.value = val;
|
|
7052
|
+
},
|
|
7053
|
+
enumerable: false,
|
|
7054
|
+
configurable: true
|
|
7055
|
+
});
|
|
7056
|
+
ViewModelInstanceColor.prototype.rgb = function (r, g, b) {
|
|
7057
|
+
this._viewModelInstanceValue.rgb(r, g, b);
|
|
7058
|
+
};
|
|
7059
|
+
ViewModelInstanceColor.prototype.rgba = function (r, g, b, a) {
|
|
7060
|
+
this._viewModelInstanceValue.argb(a, r, g, b);
|
|
7061
|
+
};
|
|
7062
|
+
ViewModelInstanceColor.prototype.argb = function (a, r, g, b) {
|
|
7063
|
+
this._viewModelInstanceValue.argb(a, r, g, b);
|
|
7064
|
+
};
|
|
7065
|
+
// Value 0 to 255
|
|
7066
|
+
ViewModelInstanceColor.prototype.alpha = function (a) {
|
|
7067
|
+
this._viewModelInstanceValue.alpha(a);
|
|
7068
|
+
};
|
|
7069
|
+
// Value 0 to 1
|
|
7070
|
+
ViewModelInstanceColor.prototype.opacity = function (o) {
|
|
7071
|
+
this._viewModelInstanceValue.alpha(Math.round(Math.max(0, Math.min(1, o)) * 255));
|
|
7072
|
+
};
|
|
7073
|
+
ViewModelInstanceColor.prototype.internalHandleCallback = function (callback) {
|
|
7074
|
+
callback(this.value);
|
|
7075
|
+
};
|
|
7076
|
+
return ViewModelInstanceColor;
|
|
7077
|
+
}(ViewModelInstanceValue));
|
|
7078
|
+
|
|
6497
7079
|
// Loads Rive data from a URI via fetch.
|
|
6498
7080
|
var loadRiveFile = function (src) { return __awaiter(void 0, void 0, void 0, function () {
|
|
6499
7081
|
var req, res, buffer;
|