@rive-app/canvas 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +30 -0
  2. package/rive.js +1732 -0
  3. package/rive.wasm +0 -0
package/rive.js ADDED
@@ -0,0 +1,1732 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["rive"] = factory();
8
+ else
9
+ root["rive"] = factory();
10
+ })(this, function() {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ "use strict";
13
+ /******/ var __webpack_modules__ = ([
14
+ /* 0 */,
15
+ /* 1 */
16
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
17
+
18
+ __webpack_require__.r(__webpack_exports__);
19
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
20
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
21
+ /* harmony export */ });
22
+
23
+ var Rive = (function() {
24
+ var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
25
+ if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
26
+ return (
27
+ function(Rive) {
28
+ Rive = Rive || {};
29
+
30
+
31
+ null;var h;h||(h=typeof Rive !== 'undefined' ? Rive : {});var aa,ba;h.ready=new Promise(function(a,b){aa=a;ba=b});
32
+ Rive.onRuntimeInitialized=function(){function a(n){switch(n){case k.srcOver:return"source-over";case k.screen:return"screen";case k.overlay:return"overlay";case k.darken:return"darken";case k.lighten:return"lighten";case k.colorDodge:return"color-dodge";case k.colorBurn:return"color-burn";case k.hardLight:return"hard-light";case k.softLight:return"soft-light";case k.difference:return"difference";case k.exclusion:return"exclusion";case k.multiply:return"multiply";case k.hue:return"hue";case k.saturation:return"saturation";
33
+ case k.color:return"color";case k.luminosity:return"luminosity"}}function b(n){return"rgba("+((16711680&n)>>>16)+","+((65280&n)>>>8)+","+((255&n)>>>0)+","+((4278190080&n)>>>24)/255+")"}const c=Rive.RenderPaintStyle,d=Rive.RenderPath,e=Rive.RenderPaint,f=Rive.Renderer,m=Rive.StrokeCap,g=Rive.StrokeJoin,k=Rive.BlendMode,l=c.fill,p=c.stroke,q=Rive.FillRule.evenOdd;var u=Rive.RenderImage.extend("CanvasRenderImage",{__construct:function(){this.__parent.__construct.call(this)},decode:function(n){var t=
34
+ this,v=new Image;v.src=URL.createObjectURL(new Blob([n],{type:"image/png"}));v.onload=function(){t.Ja=v;t.size(v.width,v.height)}}}),z=d.extend("CanvasRenderPath",{__construct:function(){this.__parent.__construct.call(this);this.ea=new Path2D},reset:function(){this.ea=new Path2D},addPath:function(n,t){var v=this.ea,w=v.addPath;n=n.ea;const y=new DOMMatrix;y.a=t.xx;y.b=t.xy;y.c=t.yx;y.d=t.yy;y.e=t.tx;y.f=t.ty;w.call(v,n,y)},fillRule:function(n){this.ya=n},moveTo:function(n,t){this.ea.moveTo(n,t)},
35
+ lineTo:function(n,t){this.ea.lineTo(n,t)},cubicTo:function(n,t,v,w,y,L){this.ea.bezierCurveTo(n,t,v,w,y,L)},close:function(){this.ea.closePath()}}),x=e.extend("CanvasRenderPaint",{color:function(n){this.za=b(n)},thickness:function(n){this.La=n},join:function(n){switch(n){case g.miter:this.ra="miter";break;case g.round:this.ra="round";break;case g.bevel:this.ra="bevel"}},cap:function(n){switch(n){case m.butt:this.qa="butt";break;case m.round:this.qa="round";break;case m.square:this.qa="square"}},style:function(n){this.Ka=
36
+ n},blendMode:function(n){this.Ia=a(n)},linearGradient:function(n,t,v,w){this.na={Ga:n,Ha:t,Ba:v,Ca:w,wa:[]}},radialGradient:function(n,t,v,w){this.na={Ga:n,Ha:t,Ba:v,Ca:w,wa:[],Va:!0}},addStop:function(n,t){this.na.wa.push({color:n,stop:t})},completeGradient:function(){},draw:function(n,t){let v=this.Ka;var w=this.za,y=this.na;n.globalCompositeOperation=this.Ia;if(null!=y){w=y.Ga;var L=y.Ha;const cb=y.Ba;var sa=y.Ca;const db=y.wa;y.Va?(y=cb-w,sa-=L,w=n.createRadialGradient(w,L,0,w,L,Math.sqrt(y*y+
37
+ sa*sa))):w=n.createLinearGradient(w,L,cb,sa);for(let Ma=0,Gb=db.length;Ma<Gb;Ma++)L=db[Ma],w.addColorStop(L.stop,b(L.color));this.za=w;this.na=null}switch(v){case p:n.strokeStyle=w;n.lineWidth=this.La;n.lineCap=this.qa;n.lineJoin=this.ra;n.stroke(t.ea);break;case l:n.fillStyle=w,n.fill(t.ea,t.ya===q?"evenodd":"nonzero")}}}),I=Rive.CanvasRenderer=f.extend("Renderer",{__construct:function(n){this.__parent.__construct.call(this);this.ha=n.getContext("2d");this.xa=n},save:function(){this.ha.save()},restore:function(){this.ha.restore()},
38
+ transform:function(n){this.ha.transform(n.xx,n.xy,n.yx,n.yy,n.tx,n.ty)},drawPath:function(n,t){t.draw(this.ha,n)},drawImage:function(n,t,v){if(n=n.Ja){var w=this.ha;w.globalCompositeOperation=a(t);w.globalAlpha=v;w.drawImage(n,0,0);w.globalAlpha=1}},clipPath:function(n){this.ha.clip(n.ea,n.ya===q?"evenodd":"nonzero")},clear:function(){this.ha.clearRect(0,0,this.xa.width,this.xa.height)},flush:function(){}});Rive.makeRenderer=function(n){return new I(n)};Rive.renderFactory={makeRenderPaint:function(){return new x},
39
+ makeRenderPath:function(){return new z},makeRenderImage:function(){return new u}}};var ca={},r;for(r in h)h.hasOwnProperty(r)&&(ca[r]=h[r]);var da="object"===typeof window,ea="function"===typeof importScripts,A="",fa,ha,ia,B,C;
40
+ if("object"===typeof process&&"object"===typeof process.versions&&"string"===typeof process.versions.node)A=ea?require("path").dirname(A)+"/":__dirname+"/",fa=function(a,b){B||(B=require("fs"));C||(C=require("path"));a=C.normalize(a);return B.readFileSync(a,b?null:"utf8")},ia=function(a){a=fa(a,!0);a.buffer||(a=new Uint8Array(a));a.buffer||D("Assertion failed: undefined");return a},ha=function(a,b,c){B||(B=require("fs"));C||(C=require("path"));a=C.normalize(a);B.readFile(a,function(d,e){d?c(d):b(e.buffer)})},
41
+ 1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),process.on("uncaughtException",function(a){throw a;}),process.on("unhandledRejection",function(a){throw a;}),h.inspect=function(){return"[Emscripten Module object]"};else if(da||ea)ea?A=self.location.href:"undefined"!==typeof document&&document.currentScript&&(A=document.currentScript.src),_scriptDir&&(A=_scriptDir),0!==A.indexOf("blob:")?A=A.substr(0,A.replace(/[?#].*/,"").lastIndexOf("/")+1):A="",fa=function(a){var b=
42
+ new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},ea&&(ia=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),ha=function(a,b,c){var d=new XMLHttpRequest;d.open("GET",a,!0);d.responseType="arraybuffer";d.onload=function(){200==d.status||0==d.status&&d.response?b(d.response):c()};d.onerror=c;d.send(null)};var ja=h.print||console.log.bind(console),ka=h.printErr||console.warn.bind(console);
43
+ for(r in ca)ca.hasOwnProperty(r)&&(h[r]=ca[r]);ca=null;var la;h.wasmBinary&&(la=h.wasmBinary);var noExitRuntime=h.noExitRuntime||!0;"object"!==typeof WebAssembly&&D("no native wasm support detected");var ma,na=!1,oa="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;
44
+ function pa(a,b,c){var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16<c-b&&a.subarray&&oa)return oa.decode(a.subarray(b,c));for(d="";b<c;){var e=a[b++];if(e&128){var f=a[b++]&63;if(192==(e&224))d+=String.fromCharCode((e&31)<<6|f);else{var m=a[b++]&63;e=224==(e&240)?(e&15)<<12|f<<6|m:(e&7)<<18|f<<12|m<<6|a[b++]&63;65536>e?d+=String.fromCharCode(e):(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|e&1023))}}else d+=String.fromCharCode(e)}return d}
45
+ function qa(a,b,c){var d=E;if(0<c){c=b+c-1;for(var e=0;e<a.length;++e){var f=a.charCodeAt(e);if(55296<=f&&57343>=f){var m=a.charCodeAt(++e);f=65536+((f&1023)<<10)|m&1023}if(127>=f){if(b>=c)break;d[b++]=f}else{if(2047>=f){if(b+1>=c)break;d[b++]=192|f>>6}else{if(65535>=f){if(b+2>=c)break;d[b++]=224|f>>12}else{if(b+3>=c)break;d[b++]=240|f>>18;d[b++]=128|f>>12&63}d[b++]=128|f>>6&63}d[b++]=128|f&63}}d[b]=0}}var ra="undefined"!==typeof TextDecoder?new TextDecoder("utf-16le"):void 0;
46
+ function ta(a,b){var c=a>>1;for(var d=c+b/2;!(c>=d)&&ua[c];)++c;c<<=1;if(32<c-a&&ra)return ra.decode(E.subarray(a,c));c="";for(d=0;!(d>=b/2);++d){var e=F[a+2*d>>1];if(0==e)break;c+=String.fromCharCode(e)}return c}function va(a,b,c){void 0===c&&(c=2147483647);if(2>c)return 0;c-=2;var d=b;c=c<2*a.length?c/2:a.length;for(var e=0;e<c;++e)F[b>>1]=a.charCodeAt(e),b+=2;F[b>>1]=0;return b-d}function wa(a){return 2*a.length}
47
+ function xa(a,b){for(var c=0,d="";!(c>=b/4);){var e=G[a+4*c>>2];if(0==e)break;++c;65536<=e?(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|e&1023)):d+=String.fromCharCode(e)}return d}function ya(a,b,c){void 0===c&&(c=2147483647);if(4>c)return 0;var d=b;c=d+c-4;for(var e=0;e<a.length;++e){var f=a.charCodeAt(e);if(55296<=f&&57343>=f){var m=a.charCodeAt(++e);f=65536+((f&1023)<<10)|m&1023}G[b>>2]=f;b+=4;if(b+4>c)break}G[b>>2]=0;return b-d}
48
+ function za(a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=d&&++c;b+=4}return b}var Aa,Ba,E,F,ua,G,H,Ca,Da;function Ea(){var a=ma.buffer;Aa=a;h.HEAP8=Ba=new Int8Array(a);h.HEAP16=F=new Int16Array(a);h.HEAP32=G=new Int32Array(a);h.HEAPU8=E=new Uint8Array(a);h.HEAPU16=ua=new Uint16Array(a);h.HEAPU32=H=new Uint32Array(a);h.HEAPF32=Ca=new Float32Array(a);h.HEAPF64=Da=new Float64Array(a)}var Fa,Ga=[],Ha=[],Ia=[];function Ja(){var a=h.preRun.shift();Ga.unshift(a)}
49
+ var J=0,Ka=null,La=null;h.preloadedImages={};h.preloadedAudios={};function D(a){if(h.onAbort)h.onAbort(a);a="Aborted("+a+")";ka(a);na=!0;a=new WebAssembly.RuntimeError(a+". Build with -s ASSERTIONS=1 for more info.");ba(a);throw a;}function Na(){return K.startsWith("data:application/octet-stream;base64,")}var K;K="canvas_advanced.wasm";if(!Na()){var Oa=K;K=h.locateFile?h.locateFile(Oa,A):A+Oa}
50
+ function Pa(){var a=K;try{if(a==K&&la)return new Uint8Array(la);if(ia)return ia(a);throw"both async and sync fetching of the wasm failed";}catch(b){D(b)}}
51
+ function Qa(){if(!la&&(da||ea)){if("function"===typeof fetch&&!K.startsWith("file://"))return fetch(K,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+K+"'";return a.arrayBuffer()}).catch(function(){return Pa()});if(ha)return new Promise(function(a,b){ha(K,function(c){a(new Uint8Array(c))},b)})}return Promise.resolve().then(function(){return Pa()})}
52
+ function Ra(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(h);else{var c=b.cb;"number"===typeof c?void 0===b.sa?Fa.get(c)():Fa.get(c)(b.sa):c(void 0===b.sa?null:b.sa)}}}function Sa(a){if(void 0===a)return"_unknown";a=a.replace(/[^a-zA-Z0-9_]/g,"$");var b=a.charCodeAt(0);return 48<=b&&57>=b?"_"+a:a}function Ta(a,b){a=Sa(a);return(new Function("body","return function "+a+'() {\n "use strict"; return body.apply(this, arguments);\n};\n'))(b)}
53
+ var M=[{},{value:void 0},{value:null},{value:!0},{value:!1}],Ua=[];function Va(a){var b=Error,c=Ta(a,function(d){this.name=a;this.message=d;d=Error(d).stack;void 0!==d&&(this.stack=this.toString()+"\n"+d.replace(/^Error(:[^\n]*)?\n/,""))});c.prototype=Object.create(b.prototype);c.prototype.constructor=c;c.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message};return c}var Wa=void 0;function N(a){throw new Wa(a);}
54
+ function O(a){a||N("Cannot use deleted val. handle = "+a);return M[a].value}function P(a){switch(a){case void 0:return 1;case null:return 2;case !0:return 3;case !1:return 4;default:var b=Ua.length?Ua.pop():M.length;M[b]={va:1,value:a};return b}}var Xa=void 0,Ya=void 0;function Q(a){for(var b="";E[a];)b+=Ya[E[a++]];return b}var Za=[];function $a(){for(;Za.length;){var a=Za.pop();a.V.ka=!1;a["delete"]()}}var ab=void 0,R={};
55
+ function bb(a,b){for(void 0===b&&N("ptr should not be undefined");a.$;)b=a.ma(b),a=a.$;return b}var S={};function eb(a){a=fb(a);var b=Q(a);T(a);return b}function gb(a,b){var c=S[a];void 0===c&&N(b+" has unknown type "+eb(a));return c}function hb(){}var ib=!1;function jb(a){--a.count.value;0===a.count.value&&(a.aa?a.da.ga(a.aa):a.Y.W.ga(a.X))}
56
+ function kb(a){if("undefined"===typeof FinalizationGroup)return kb=function(b){return b},a;ib=new FinalizationGroup(function(b){for(var c=b.next();!c.done;c=b.next())c=c.value,c.X?jb(c):console.warn("object already deleted: "+c.X)});kb=function(b){ib.register(b,b.V,b.V);return b};hb=function(b){ib.unregister(b.V)};return kb(a)}var lb={};function mb(a){for(;a.length;){var b=a.pop();a.pop()(b)}}function nb(a){return this.fromWireType(H[a>>2])}var ob={},pb={},qb=void 0;
57
+ function rb(a){throw new qb(a);}function U(a,b,c){function d(g){g=c(g);g.length!==a.length&&rb("Mismatched type converter count");for(var k=0;k<a.length;++k)V(a[k],g[k])}a.forEach(function(g){pb[g]=b});var e=Array(b.length),f=[],m=0;b.forEach(function(g,k){S.hasOwnProperty(g)?e[k]=S[g]:(f.push(g),ob.hasOwnProperty(g)||(ob[g]=[]),ob[g].push(function(){e[k]=S[g];++m;m===f.length&&d(e)}))});0===f.length&&d(e)}
58
+ function sb(a){switch(a){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+a);}}
59
+ function V(a,b,c){c=c||{};if(!("argPackAdvance"in b))throw new TypeError("registerType registeredInstance requires argPackAdvance");var d=b.name;a||N('type "'+d+'" must have a positive integer typeid pointer');if(S.hasOwnProperty(a)){if(c.Ua)return;N("Cannot register type '"+d+"' twice")}S[a]=b;delete pb[a];ob.hasOwnProperty(a)&&(b=ob[a],delete ob[a],b.forEach(function(e){e()}))}function tb(a){N(a.V.Y.W.name+" instance already deleted")}function W(){}var ub={};
60
+ function vb(a,b,c){if(void 0===a[b].Z){var d=a[b];a[b]=function(){a[b].Z.hasOwnProperty(arguments.length)||N("Function '"+c+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+a[b].Z+")!");return a[b].Z[arguments.length].apply(this,arguments)};a[b].Z=[];a[b].Z[d.ja]=d}}
61
+ function wb(a,b,c){h.hasOwnProperty(a)?((void 0===c||void 0!==h[a].Z&&void 0!==h[a].Z[c])&&N("Cannot register public name '"+a+"' twice"),vb(h,a,a),h.hasOwnProperty(c)&&N("Cannot register multiple overloads of a function with the same number of arguments ("+c+")!"),h[a].Z[c]=b):(h[a]=b,void 0!==c&&(h[a].eb=c))}function xb(a,b,c,d,e,f,m,g){this.name=a;this.constructor=b;this.fa=c;this.ga=d;this.$=e;this.Pa=f;this.ma=m;this.Na=g;this.Ea=[]}
62
+ function yb(a,b,c){for(;b!==c;)b.ma||N("Expected null or instance of "+c.name+", got an instance of "+b.name),a=b.ma(a),b=b.$;return a}function zb(a,b){if(null===b)return this.ta&&N("null is not a valid "+this.name),0;b.V||N('Cannot pass "'+Ab(b)+'" as a '+this.name);b.V.X||N("Cannot pass deleted object as a pointer of type "+this.name);return yb(b.V.X,b.V.Y.W,this.W)}
63
+ function Bb(a,b){if(null===b){this.ta&&N("null is not a valid "+this.name);if(this.pa){var c=this.ua();null!==a&&a.push(this.ga,c);return c}return 0}b.V||N('Cannot pass "'+Ab(b)+'" as a '+this.name);b.V.X||N("Cannot pass deleted object as a pointer of type "+this.name);!this.oa&&b.V.Y.oa&&N("Cannot convert argument of type "+(b.V.da?b.V.da.name:b.V.Y.name)+" to parameter type "+this.name);c=yb(b.V.X,b.V.Y.W,this.W);if(this.pa)switch(void 0===b.V.aa&&N("Passing raw pointer to smart pointer is illegal"),
64
+ this.bb){case 0:b.V.da===this?c=b.V.aa:N("Cannot convert argument of type "+(b.V.da?b.V.da.name:b.V.Y.name)+" to parameter type "+this.name);break;case 1:c=b.V.aa;break;case 2:if(b.V.da===this)c=b.V.aa;else{var d=b.clone();c=this.Ya(c,P(function(){d["delete"]()}));null!==a&&a.push(this.ga,c)}break;default:N("Unsupporting sharing policy")}return c}
65
+ function Cb(a,b){if(null===b)return this.ta&&N("null is not a valid "+this.name),0;b.V||N('Cannot pass "'+Ab(b)+'" as a '+this.name);b.V.X||N("Cannot pass deleted object as a pointer of type "+this.name);b.V.Y.oa&&N("Cannot convert argument of type "+b.V.Y.name+" to parameter type "+this.name);return yb(b.V.X,b.V.Y.W,this.W)}function Db(a,b,c){if(b===c)return a;if(void 0===c.$)return null;a=Db(a,b,c.$);return null===a?null:c.Na(a)}function Eb(a,b){b=bb(a,b);return R[b]}
66
+ function Fb(a,b){b.Y&&b.X||rb("makeClassHandle requires ptr and ptrType");!!b.da!==!!b.aa&&rb("Both smartPtrType and smartPtr must be specified");b.count={value:1};return kb(Object.create(a,{V:{value:b}}))}function X(a,b,c,d){this.name=a;this.W=b;this.ta=c;this.oa=d;this.pa=!1;this.ga=this.Ya=this.ua=this.Fa=this.bb=this.Xa=void 0;void 0!==b.$?this.toWireType=Bb:(this.toWireType=d?zb:Cb,this.ba=null)}
67
+ function Hb(a,b,c){h.hasOwnProperty(a)||rb("Replacing nonexistant public symbol");void 0!==h[a].Z&&void 0!==c?h[a].Z[c]=b:(h[a]=b,h[a].ja=c)}function Ib(a,b){var c=[];return function(){c.length=arguments.length;for(var d=0;d<arguments.length;d++)c[d]=arguments[d];a.includes("j")?(d=h["dynCall_"+a],d=c&&c.length?d.apply(null,[b].concat(c)):d.call(null,b)):d=Fa.get(b).apply(null,c);return d}}
68
+ function Y(a,b){a=Q(a);var c=a.includes("j")?Ib(a,b):Fa.get(b);"function"!==typeof c&&N("unknown function pointer with signature "+a+": "+b);return c}var Jb=void 0;function Z(a,b){function c(f){e[f]||S[f]||(pb[f]?pb[f].forEach(c):(d.push(f),e[f]=!0))}var d=[],e={};b.forEach(c);throw new Jb(a+": "+d.map(eb).join([", "]));}
69
+ function Kb(a){var b=Function;if(!(b instanceof Function))throw new TypeError("new_ called with constructor type "+typeof b+" which is not a function");var c=Ta(b.name||"unknownFunctionName",function(){});c.prototype=b.prototype;c=new c;a=b.apply(c,a);return a instanceof Object?a:c}
70
+ function Lb(a,b,c,d,e){var f=b.length;2>f&&N("argTypes array size mismatch! Must at least get return value and 'this' types!");var m=null!==b[1]&&null!==c,g=!1;for(c=1;c<b.length;++c)if(null!==b[c]&&void 0===b[c].ba){g=!0;break}var k="void"!==b[0].name,l="",p="";for(c=0;c<f-2;++c)l+=(0!==c?", ":"")+"arg"+c,p+=(0!==c?", ":"")+"arg"+c+"Wired";a="return function "+Sa(a)+"("+l+") {\nif (arguments.length !== "+(f-2)+") {\nthrowBindingError('function "+a+" called with ' + arguments.length + ' arguments, expected "+
71
+ (f-2)+" args!');\n}\n";g&&(a+="var destructors = [];\n");var q=g?"destructors":"null";l="throwBindingError invoker fn runDestructors retType classParam".split(" ");d=[N,d,e,mb,b[0],b[1]];m&&(a+="var thisWired = classParam.toWireType("+q+", this);\n");for(c=0;c<f-2;++c)a+="var arg"+c+"Wired = argType"+c+".toWireType("+q+", arg"+c+"); // "+b[c+2].name+"\n",l.push("argType"+c),d.push(b[c+2]);m&&(p="thisWired"+(0<p.length?", ":"")+p);a+=(k?"var rv = ":"")+"invoker(fn"+(0<p.length?", ":"")+p+");\n";if(g)a+=
72
+ "runDestructors(destructors);\n";else for(c=m?1:2;c<b.length;++c)f=1===c?"thisWired":"arg"+(c-2)+"Wired",null!==b[c].ba&&(a+=f+"_dtor("+f+"); // "+b[c].name+"\n",l.push(f+"_dtor"),d.push(b[c].ba));k&&(a+="var ret = retType.fromWireType(rv);\nreturn ret;\n");l.push(a+"}\n");return Kb(l).apply(null,d)}function Mb(a,b){for(var c=[],d=0;d<a;d++)c.push(G[(b>>2)+d]);return c}
73
+ function Nb(a,b,c){a instanceof Object||N(c+' with invalid "this": '+a);a instanceof b.W.constructor||N(c+' incompatible with "this" of type '+a.constructor.name);a.V.X||N("cannot call emscripten binding method "+c+" on deleted object");return yb(a.V.X,a.V.Y.W,b.W)}function Ob(a){4<a&&0===--M[a].va&&(M[a]=void 0,Ua.push(a))}
74
+ function Pb(a,b,c){switch(b){case 0:return function(d){return this.fromWireType((c?Ba:E)[d])};case 1:return function(d){return this.fromWireType((c?F:ua)[d>>1])};case 2:return function(d){return this.fromWireType((c?G:H)[d>>2])};default:throw new TypeError("Unknown integer type: "+a);}}function Ab(a){if(null===a)return"null";var b=typeof a;return"object"===b||"array"===b||"function"===b?a.toString():""+a}
75
+ function Qb(a,b){switch(b){case 2:return function(c){return this.fromWireType(Ca[c>>2])};case 3:return function(c){return this.fromWireType(Da[c>>3])};default:throw new TypeError("Unknown float type: "+a);}}
76
+ function Rb(a,b,c){switch(b){case 0:return c?function(d){return Ba[d]}:function(d){return E[d]};case 1:return c?function(d){return F[d>>1]}:function(d){return ua[d>>1]};case 2:return c?function(d){return G[d>>2]}:function(d){return H[d>>2]};default:throw new TypeError("Unknown integer type: "+a);}}var Sb={};function Tb(a){var b=Sb[a];return void 0===b?Q(a):b}var Ub=[];function Vb(a){var b=Ub.length;Ub.push(a);return b}
77
+ function Wb(a,b){for(var c=Array(a),d=0;d<a;++d)c[d]=gb(G[(b>>2)+d],"parameter "+d);return c}var Xb=[],Yb=[null,[],[]];Wa=h.BindingError=Va("BindingError");h.count_emval_handles=function(){for(var a=0,b=5;b<M.length;++b)void 0!==M[b]&&++a;return a};h.get_first_emval=function(){for(var a=5;a<M.length;++a)if(void 0!==M[a])return M[a];return null};Xa=h.PureVirtualError=Va("PureVirtualError");for(var Zb=Array(256),$b=0;256>$b;++$b)Zb[$b]=String.fromCharCode($b);Ya=Zb;h.getInheritedInstanceCount=function(){return Object.keys(R).length};
78
+ h.getLiveInheritedInstances=function(){var a=[],b;for(b in R)R.hasOwnProperty(b)&&a.push(R[b]);return a};h.flushPendingDeletes=$a;h.setDelayFunction=function(a){ab=a;Za.length&&ab&&ab($a)};qb=h.InternalError=Va("InternalError");W.prototype.isAliasOf=function(a){if(!(this instanceof W&&a instanceof W))return!1;var b=this.V.Y.W,c=this.V.X,d=a.V.Y.W;for(a=a.V.X;b.$;)c=b.ma(c),b=b.$;for(;d.$;)a=d.ma(a),d=d.$;return b===d&&c===a};
79
+ W.prototype.clone=function(){this.V.X||tb(this);if(this.V.la)return this.V.count.value+=1,this;var a=kb,b=Object,c=b.create,d=Object.getPrototypeOf(this),e=this.V;a=a(c.call(b,d,{V:{value:{count:e.count,ka:e.ka,la:e.la,X:e.X,Y:e.Y,aa:e.aa,da:e.da}}}));a.V.count.value+=1;a.V.ka=!1;return a};W.prototype["delete"]=function(){this.V.X||tb(this);this.V.ka&&!this.V.la&&N("Object already scheduled for deletion");hb(this);jb(this.V);this.V.la||(this.V.aa=void 0,this.V.X=void 0)};W.prototype.isDeleted=function(){return!this.V.X};
80
+ W.prototype.deleteLater=function(){this.V.X||tb(this);this.V.ka&&!this.V.la&&N("Object already scheduled for deletion");Za.push(this);1===Za.length&&ab&&ab($a);this.V.ka=!0;return this};X.prototype.Qa=function(a){this.Fa&&(a=this.Fa(a));return a};X.prototype.Aa=function(a){this.ga&&this.ga(a)};X.prototype.argPackAdvance=8;X.prototype.readValueFromPointer=nb;X.prototype.deleteObject=function(a){if(null!==a)a["delete"]()};
81
+ X.prototype.fromWireType=function(a){function b(){return this.pa?Fb(this.W.fa,{Y:this.Xa,X:c,da:this,aa:a}):Fb(this.W.fa,{Y:this,X:a})}var c=this.Qa(a);if(!c)return this.Aa(a),null;var d=Eb(this.W,c);if(void 0!==d){if(0===d.V.count.value)return d.V.X=c,d.V.aa=a,d.clone();d=d.clone();this.Aa(a);return d}d=this.W.Pa(c);d=ub[d];if(!d)return b.call(this);d=this.oa?d.Ma:d.pointerType;var e=Db(c,this.W,d.W);return null===e?b.call(this):this.pa?Fb(d.W.fa,{Y:d,X:e,da:this,aa:a}):Fb(d.W.fa,{Y:d,X:e})};
82
+ Jb=h.UnboundTypeError=Va("UnboundTypeError");
83
+ var bc={m:function(a,b,c){a=Q(a);b=gb(b,"wrapper");c=O(c);var d=[].slice,e=b.W,f=e.fa,m=e.$.fa,g=e.$.constructor;a=Ta(a,function(){e.$.Ea.forEach(function(l){if(this[l]===m[l])throw new Xa("Pure virtual function "+l+" must be implemented in JavaScript");}.bind(this));Object.defineProperty(this,"__parent",{value:f});this.__construct.apply(this,d.call(arguments))});f.__construct=function(){this===f&&N("Pass correct 'this' to __construct");var l=g.implement.apply(void 0,[this].concat(d.call(arguments)));
84
+ hb(l);var p=l.V;l.notifyOnDestruction();p.la=!0;Object.defineProperties(this,{V:{value:p}});kb(this);l=p.X;l=bb(e,l);R.hasOwnProperty(l)?N("Tried to register registered instance: "+l):R[l]=this};f.__destruct=function(){this===f&&N("Pass correct 'this' to __destruct");hb(this);var l=this.V.X;l=bb(e,l);R.hasOwnProperty(l)?delete R[l]:N("Tried to unregister unregistered instance: "+l)};a.prototype=Object.create(f);for(var k in c)a.prototype[k]=c[k];return P(a)},H:function(a){var b=lb[a];delete lb[a];
85
+ var c=b.ua,d=b.ga,e=b.Da,f=e.map(function(m){return m.Ta}).concat(e.map(function(m){return m.$a}));U([a],f,function(m){var g={};e.forEach(function(k,l){var p=m[l],q=k.Ra,u=k.Sa,z=m[l+e.length],x=k.Za,I=k.ab;g[k.Oa]={read:function(n){return p.fromWireType(q(u,n))},write:function(n,t){var v=[];x(I,n,z.toWireType(v,t));mb(v)}}});return[{name:b.name,fromWireType:function(k){var l={},p;for(p in g)l[p]=g[p].read(k);d(k);return l},toWireType:function(k,l){for(var p in g)if(!(p in l))throw new TypeError('Missing field: "'+
86
+ p+'"');var q=c();for(p in g)g[p].write(q,l[p]);null!==k&&k.push(d,q);return q},argPackAdvance:8,readValueFromPointer:nb,ba:d}]})},y:function(){},E:function(a,b,c,d,e){var f=sb(c);b=Q(b);V(a,{name:b,fromWireType:function(m){return!!m},toWireType:function(m,g){return g?d:e},argPackAdvance:8,readValueFromPointer:function(m){if(1===c)var g=Ba;else if(2===c)g=F;else if(4===c)g=G;else throw new TypeError("Unknown boolean type size: "+b);return this.fromWireType(g[m>>f])},ba:null})},c:function(a,b,c,d,e,
87
+ f,m,g,k,l,p,q,u){p=Q(p);f=Y(e,f);g&&(g=Y(m,g));l&&(l=Y(k,l));u=Y(q,u);var z=Sa(p);wb(z,function(){Z("Cannot construct "+p+" due to unbound types",[d])});U([a,b,c],d?[d]:[],function(x){x=x[0];if(d){var I=x.W;var n=I.fa}else n=W.prototype;x=Ta(z,function(){if(Object.getPrototypeOf(this)!==t)throw new Wa("Use 'new' to construct "+p);if(void 0===v.ia)throw new Wa(p+" has no accessible constructor");var y=v.ia[arguments.length];if(void 0===y)throw new Wa("Tried to invoke ctor of "+p+" with invalid number of parameters ("+
88
+ arguments.length+") - expected ("+Object.keys(v.ia).toString()+") parameters instead!");return y.apply(this,arguments)});var t=Object.create(n,{constructor:{value:x}});x.prototype=t;var v=new xb(p,x,t,u,I,f,g,l);I=new X(p,v,!0,!1);n=new X(p+"*",v,!1,!1);var w=new X(p+" const*",v,!1,!0);ub[a]={pointerType:n,Ma:w};Hb(z,x);return[I,n,w]})},i:function(a,b,c,d,e,f,m){var g=Mb(c,d);b=Q(b);f=Y(e,f);U([],[a],function(k){function l(){Z("Cannot call "+p+" due to unbound types",g)}k=k[0];var p=k.name+"."+b;
89
+ b.startsWith("@@")&&(b=Symbol[b.substring(2)]);var q=k.W.constructor;void 0===q[b]?(l.ja=c-1,q[b]=l):(vb(q,b,p),q[b].Z[c-1]=l);U([],g,function(u){u=[u[0],null].concat(u.slice(1));u=Lb(p,u,null,f,m);void 0===q[b].Z?(u.ja=c-1,q[b]=u):q[b].Z[c-1]=u;return[]});return[]})},f:function(a,b,c,d,e,f,m,g){b=Q(b);f=Y(e,f);U([],[a],function(k){k=k[0];var l=k.name+"."+b,p={get:function(){Z("Cannot access "+l+" due to unbound types",[c])},enumerable:!0,configurable:!0};p.set=g?function(){Z("Cannot access "+l+" due to unbound types",
90
+ [c])}:function(){N(l+" is a read-only property")};Object.defineProperty(k.W.constructor,b,p);U([],[c],function(q){q=q[0];var u={get:function(){return q.fromWireType(f(d))},enumerable:!0};g&&(g=Y(m,g),u.set=function(z){var x=[];g(d,q.toWireType(x,z));mb(x)});Object.defineProperty(k.W.constructor,b,u);return[]});return[]})},p:function(a,b,c,d,e,f){0<b||D("Assertion failed: undefined");var m=Mb(b,c);e=Y(d,e);U([],[a],function(g){g=g[0];var k="constructor "+g.name;void 0===g.W.ia&&(g.W.ia=[]);if(void 0!==
91
+ g.W.ia[b-1])throw new Wa("Cannot register multiple constructors with identical number of parameters ("+(b-1)+") for class '"+g.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");g.W.ia[b-1]=function(){Z("Cannot construct "+g.name+" due to unbound types",m)};U([],m,function(l){l.splice(1,0,null);g.W.ia[b-1]=Lb(k,l,null,e,f);return[]});return[]})},a:function(a,b,c,d,e,f,m,g){var k=Mb(c,d);b=Q(b);f=Y(e,f);U([],[a],function(l){function p(){Z("Cannot call "+
92
+ q+" due to unbound types",k)}l=l[0];var q=l.name+"."+b;b.startsWith("@@")&&(b=Symbol[b.substring(2)]);g&&l.W.Ea.push(b);var u=l.W.fa,z=u[b];void 0===z||void 0===z.Z&&z.className!==l.name&&z.ja===c-2?(p.ja=c-2,p.className=l.name,u[b]=p):(vb(u,b,q),u[b].Z[c-2]=p);U([],k,function(x){x=Lb(q,x,l,f,m);void 0===u[b].Z?(x.ja=c-2,u[b]=x):u[b].Z[c-2]=x;return[]});return[]})},b:function(a,b,c,d,e,f,m,g,k,l){b=Q(b);e=Y(d,e);U([],[a],function(p){p=p[0];var q=p.name+"."+b,u={get:function(){Z("Cannot access "+q+
93
+ " due to unbound types",[c,m])},enumerable:!0,configurable:!0};u.set=k?function(){Z("Cannot access "+q+" due to unbound types",[c,m])}:function(){N(q+" is a read-only property")};Object.defineProperty(p.W.fa,b,u);U([],k?[c,m]:[c],function(z){var x=z[0],I={get:function(){var t=Nb(this,p,q+" getter");return x.fromWireType(e(f,t))},enumerable:!0};if(k){k=Y(g,k);var n=z[1];I.set=function(t){var v=Nb(this,p,q+" setter"),w=[];k(l,v,n.toWireType(w,t));mb(w)}}Object.defineProperty(p.W.fa,b,I);return[]});
94
+ return[]})},D:function(a,b){b=Q(b);V(a,{name:b,fromWireType:function(c){var d=O(c);Ob(c);return d},toWireType:function(c,d){return P(d)},argPackAdvance:8,readValueFromPointer:nb,ba:null})},k:function(a,b,c,d){function e(){}c=sb(c);b=Q(b);e.values={};V(a,{name:b,constructor:e,fromWireType:function(f){return this.constructor.values[f]},toWireType:function(f,m){return m.value},argPackAdvance:8,readValueFromPointer:Pb(b,c,d),ba:null});wb(b,e)},j:function(a,b,c){var d=gb(a,"enum");b=Q(b);a=d.constructor;
95
+ d=Object.create(d.constructor.prototype,{value:{value:c},constructor:{value:Ta(d.name+"_"+b,function(){})}});a.values[c]=d;a[b]=d},r:function(a,b,c){c=sb(c);b=Q(b);V(a,{name:b,fromWireType:function(d){return d},toWireType:function(d,e){return e},argPackAdvance:8,readValueFromPointer:Qb(b,c),ba:null})},K:function(a,b,c,d,e,f){var m=Mb(b,c);a=Q(a);e=Y(d,e);wb(a,function(){Z("Cannot call "+a+" due to unbound types",m)},b-1);U([],m,function(g){g=[g[0],null].concat(g.slice(1));Hb(a,Lb(a,g,null,e,f),b-
96
+ 1);return[]})},h:function(a,b,c,d,e){function f(l){return l}b=Q(b);-1===e&&(e=4294967295);var m=sb(c);if(0===d){var g=32-8*c;f=function(l){return l<<g>>>g}}var k=b.includes("unsigned");V(a,{name:b,fromWireType:f,toWireType:function(l,p){if("number"!==typeof p&&"boolean"!==typeof p)throw new TypeError('Cannot convert "'+Ab(p)+'" to '+this.name);if(p<d||p>e)throw new TypeError('Passing a number "'+Ab(p)+'" from JS side to C/C++ side to an argument of type "'+b+'", which is outside the valid range ['+
97
+ d+", "+e+"]!");return k?p>>>0:p|0},argPackAdvance:8,readValueFromPointer:Rb(b,m,0!==d),ba:null})},g:function(a,b,c){function d(f){f>>=2;var m=H;return new e(Aa,m[f+1],m[f])}var e=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][b];c=Q(c);V(a,{name:c,fromWireType:d,argPackAdvance:8,readValueFromPointer:d},{Ua:!0})},s:function(a,b){b=Q(b);var c="std::string"===b;V(a,{name:b,fromWireType:function(d){var e=H[d>>2];if(c)for(var f=d+4,m=0;m<=e;++m){var g=d+
98
+ 4+m;if(m==e||0==E[g]){f=f?pa(E,f,g-f):"";if(void 0===k)var k=f;else k+=String.fromCharCode(0),k+=f;f=g+1}}else{k=Array(e);for(m=0;m<e;++m)k[m]=String.fromCharCode(E[d+4+m]);k=k.join("")}T(d);return k},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 Int8Array||N("Cannot pass non-string to std::string");var m=(c&&f?function(){for(var l=0,p=0;p<e.length;++p){var q=e.charCodeAt(p);
99
+ 55296<=q&&57343>=q&&(q=65536+((q&1023)<<10)|e.charCodeAt(++p)&1023);127>=q?++l:l=2047>=q?l+2:65535>=q?l+3:l+4}return l}:function(){return e.length})(),g=ac(4+m+1);H[g>>2]=m;if(c&&f)qa(e,g+4,m+1);else if(f)for(f=0;f<m;++f){var k=e.charCodeAt(f);255<k&&(T(g),N("String has UTF-16 code units that do not fit in 8 bits"));E[g+4+f]=k}else for(f=0;f<m;++f)E[g+4+f]=e[f];null!==d&&d.push(T,g);return g},argPackAdvance:8,readValueFromPointer:nb,ba:function(d){T(d)}})},o:function(a,b,c){c=Q(c);if(2===b){var d=
100
+ ta;var e=va;var f=wa;var m=function(){return ua};var g=1}else 4===b&&(d=xa,e=ya,f=za,m=function(){return H},g=2);V(a,{name:c,fromWireType:function(k){for(var l=H[k>>2],p=m(),q,u=k+4,z=0;z<=l;++z){var x=k+4+z*b;if(z==l||0==p[x>>g])u=d(u,x-u),void 0===q?q=u:(q+=String.fromCharCode(0),q+=u),u=x+b}T(k);return q},toWireType:function(k,l){"string"!==typeof l&&N("Cannot pass non-string to C++ string type "+c);var p=f(l),q=ac(4+p+b);H[q>>2]=p>>g;e(l,q+4,p+b);null!==k&&k.push(T,q);return q},argPackAdvance:8,
101
+ readValueFromPointer:nb,ba:function(k){T(k)}})},I:function(a,b,c,d,e,f){lb[a]={name:Q(b),ua:Y(c,d),ga:Y(e,f),Da:[]}},G:function(a,b,c,d,e,f,m,g,k,l){lb[a].Da.push({Oa:Q(b),Ta:c,Ra:Y(d,e),Sa:f,$a:m,Za:Y(g,k),ab:l})},F:function(a,b){b=Q(b);V(a,{Wa:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},l:function(a,b,c){a=O(a);b=gb(b,"emval::as");var d=[],e=P(d);G[c>>2]=e;return b.toWireType(d,a)},q:function(a,b,c,d,e){a=Ub[a];b=O(b);c=Tb(c);var f=[];G[d>>2]=P(f);return a(b,
102
+ c,f,e)},e:function(a,b,c,d){a=Ub[a];b=O(b);c=Tb(c);a(b,c,null,d)},J:Ob,d:function(a,b){var c=Wb(a,b),d=c[0];b=d.name+"_$"+c.slice(1).map(function(p){return p.name}).join("_")+"$";var e=Xb[b];if(void 0!==e)return e;e=["retType"];for(var f=[d],m="",g=0;g<a-1;++g)m+=(0!==g?", ":"")+"arg"+g,e.push("argType"+g),f.push(c[1+g]);var k="return function "+Sa("methodCaller_"+b)+"(handle, name, destructors, args) {\n",l=0;for(g=0;g<a-1;++g)k+=" var arg"+g+" = argType"+g+".readValueFromPointer(args"+(l?"+"+
103
+ l:"")+");\n",l+=c[g+1].argPackAdvance;k+=" var rv = handle[name]("+m+");\n";for(g=0;g<a-1;++g)c[g+1].deleteObject&&(k+=" argType"+g+".deleteObject(arg"+g+");\n");d.Wa||(k+=" return retType.toWireType(destructors, rv);\n");e.push(k+"};\n");a=Kb(e).apply(null,f);e=Vb(a);return Xb[b]=e},M:function(a){a=Tb(a);return P(h[a])},v:function(a,b){a=O(a);b=O(b);return P(a[b])},L:function(a){4<a&&(M[a].va+=1)},u:function(a){return P(Tb(a))},w:function(a){var b=O(a);mb(b);Ob(a)},C:function(a,b){a=gb(a,
104
+ "_emval_take_value");a=a.readValueFromPointer(b);return P(a)},t:function(){D("")},n:function(a){var b=E.length;a>>>=0;if(2147483648<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);d=Math.max(a,d);0<d%65536&&(d+=65536-d%65536);a:{try{ma.grow(Math.min(2147483648,d)-Aa.byteLength+65535>>>16);Ea();var e=1;break a}catch(f){}e=void 0}if(e)return!0}return!1},A:function(){return 0},x:function(){},B:function(a,b,c,d){for(var e=0,f=0;f<c;f++){var m=G[b>>2],g=G[b+4>>2];b+=8;for(var k=
105
+ 0;k<g;k++){var l=E[m+k],p=Yb[a];0===l||10===l?((1===a?ja:ka)(pa(p,0)),p.length=0):p.push(l)}e+=g}G[d>>2]=e;return 0},z:function(){}};
106
+ (function(){function a(e){h.asm=e.exports;ma=h.asm.N;Ea();Fa=h.asm.T;Ha.unshift(h.asm.O);J--;h.monitorRunDependencies&&h.monitorRunDependencies(J);0==J&&(null!==Ka&&(clearInterval(Ka),Ka=null),La&&(e=La,La=null,e()))}function b(e){a(e.instance)}function c(e){return Qa().then(function(f){return WebAssembly.instantiate(f,d)}).then(function(f){return f}).then(e,function(f){ka("failed to asynchronously prepare wasm: "+f);D(f)})}var d={a:bc};J++;h.monitorRunDependencies&&h.monitorRunDependencies(J);if(h.instantiateWasm)try{return h.instantiateWasm(d,
107
+ a)}catch(e){return ka("Module.instantiateWasm callback failed with error: "+e),!1}(function(){return la||"function"!==typeof WebAssembly.instantiateStreaming||Na()||K.startsWith("file://")||"function"!==typeof fetch?c(b):fetch(K,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,d).then(b,function(f){ka("wasm streaming compile failed: "+f);ka("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ba);return{}})();
108
+ h.___wasm_call_ctors=function(){return(h.___wasm_call_ctors=h.asm.O).apply(null,arguments)};var ac=h._malloc=function(){return(ac=h._malloc=h.asm.P).apply(null,arguments)},fb=h.___getTypeName=function(){return(fb=h.___getTypeName=h.asm.Q).apply(null,arguments)};h.___embind_register_native_and_builtin_types=function(){return(h.___embind_register_native_and_builtin_types=h.asm.R).apply(null,arguments)};var T=h._free=function(){return(T=h._free=h.asm.S).apply(null,arguments)};
109
+ h.dynCall_jiji=function(){return(h.dynCall_jiji=h.asm.U).apply(null,arguments)};var cc;La=function dc(){cc||ec();cc||(La=dc)};
110
+ function ec(){function a(){if(!cc&&(cc=!0,h.calledRun=!0,!na)){Ra(Ha);aa(h);if(h.onRuntimeInitialized)h.onRuntimeInitialized();if(h.postRun)for("function"==typeof h.postRun&&(h.postRun=[h.postRun]);h.postRun.length;){var b=h.postRun.shift();Ia.unshift(b)}Ra(Ia)}}if(!(0<J)){if(h.preRun)for("function"==typeof h.preRun&&(h.preRun=[h.preRun]);h.preRun.length;)Ja();Ra(Ga);0<J||(h.setStatus?(h.setStatus("Running..."),setTimeout(function(){setTimeout(function(){h.setStatus("")},1);a()},1)):a())}}h.run=ec;
111
+ if(h.preInit)for("function"==typeof h.preInit&&(h.preInit=[h.preInit]);0<h.preInit.length;)h.preInit.pop()();ec();
112
+
113
+
114
+ return Rive.ready
115
+ }
116
+ );
117
+ })();
118
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Rive);
119
+
120
+ /***/ }),
121
+ /* 2 */
122
+ /***/ ((module) => {
123
+
124
+ module.exports = JSON.parse('{"name":"@rive-app/canvas","version":"1.0.2","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.wasm"],"typings":"rive.d.ts","dependencies":{}}');
125
+
126
+ /***/ })
127
+ /******/ ]);
128
+ /************************************************************************/
129
+ /******/ // The module cache
130
+ /******/ var __webpack_module_cache__ = {};
131
+ /******/
132
+ /******/ // The require function
133
+ /******/ function __webpack_require__(moduleId) {
134
+ /******/ // Check if module is in cache
135
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
136
+ /******/ if (cachedModule !== undefined) {
137
+ /******/ return cachedModule.exports;
138
+ /******/ }
139
+ /******/ // Create a new module (and put it into the cache)
140
+ /******/ var module = __webpack_module_cache__[moduleId] = {
141
+ /******/ // no module.id needed
142
+ /******/ // no module.loaded needed
143
+ /******/ exports: {}
144
+ /******/ };
145
+ /******/
146
+ /******/ // Execute the module function
147
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
148
+ /******/
149
+ /******/ // Return the exports of the module
150
+ /******/ return module.exports;
151
+ /******/ }
152
+ /******/
153
+ /************************************************************************/
154
+ /******/ /* webpack/runtime/define property getters */
155
+ /******/ (() => {
156
+ /******/ // define getter functions for harmony exports
157
+ /******/ __webpack_require__.d = (exports, definition) => {
158
+ /******/ for(var key in definition) {
159
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
160
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
161
+ /******/ }
162
+ /******/ }
163
+ /******/ };
164
+ /******/ })();
165
+ /******/
166
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
167
+ /******/ (() => {
168
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
169
+ /******/ })();
170
+ /******/
171
+ /******/ /* webpack/runtime/make namespace object */
172
+ /******/ (() => {
173
+ /******/ // define __esModule on exports
174
+ /******/ __webpack_require__.r = (exports) => {
175
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
176
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
177
+ /******/ }
178
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
179
+ /******/ };
180
+ /******/ })();
181
+ /******/
182
+ /************************************************************************/
183
+ var __webpack_exports__ = {};
184
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
185
+ (() => {
186
+ __webpack_require__.r(__webpack_exports__);
187
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
188
+ /* harmony export */ "Fit": () => (/* binding */ Fit),
189
+ /* harmony export */ "Alignment": () => (/* binding */ Alignment),
190
+ /* harmony export */ "Layout": () => (/* binding */ Layout),
191
+ /* harmony export */ "RuntimeLoader": () => (/* binding */ RuntimeLoader),
192
+ /* harmony export */ "StateMachineInputType": () => (/* binding */ StateMachineInputType),
193
+ /* harmony export */ "StateMachineInput": () => (/* binding */ StateMachineInput),
194
+ /* harmony export */ "EventType": () => (/* binding */ EventType),
195
+ /* harmony export */ "LoopType": () => (/* binding */ LoopType),
196
+ /* harmony export */ "Rive": () => (/* binding */ Rive),
197
+ /* harmony export */ "Testing": () => (/* binding */ Testing)
198
+ /* harmony export */ });
199
+ /* harmony import */ var _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
200
+ /* harmony import */ var package_json__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
201
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
202
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
203
+ return new (P || (P = Promise))(function (resolve, reject) {
204
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
205
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
206
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
207
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
208
+ });
209
+ };
210
+ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
211
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
212
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
213
+ function verb(n) { return function (v) { return step([n, v]); }; }
214
+ function step(op) {
215
+ if (f) throw new TypeError("Generator is already executing.");
216
+ while (_) try {
217
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
218
+ if (y = 0, t) op = [op[0] & 2, t.value];
219
+ switch (op[0]) {
220
+ case 0: case 1: t = op; break;
221
+ case 4: _.label++; return { value: op[1], done: false };
222
+ case 5: _.label++; y = op[1]; op = [0]; continue;
223
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
224
+ default:
225
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
226
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
227
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
228
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
229
+ if (t[2]) _.ops.pop();
230
+ _.trys.pop(); continue;
231
+ }
232
+ op = body.call(thisArg, _);
233
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
234
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
235
+ }
236
+ };
237
+
238
+
239
+ // Tracks playback states; numbers map to the runtime's numerical values
240
+ // i.e. play: 0, pause: 1, stop: 2
241
+ var PlaybackState;
242
+ (function (PlaybackState) {
243
+ PlaybackState[PlaybackState["Play"] = 0] = "Play";
244
+ PlaybackState[PlaybackState["Pause"] = 1] = "Pause";
245
+ PlaybackState[PlaybackState["Stop"] = 2] = "Stop";
246
+ })(PlaybackState || (PlaybackState = {}));
247
+ // #region layout
248
+ // Fit options for the canvas
249
+ var Fit;
250
+ (function (Fit) {
251
+ Fit["Cover"] = "cover";
252
+ Fit["Contain"] = "contain";
253
+ Fit["Fill"] = "fill";
254
+ Fit["FitWidth"] = "fitWidth";
255
+ Fit["FitHeight"] = "fitHeight";
256
+ Fit["None"] = "none";
257
+ Fit["ScaleDown"] = "scaleDown";
258
+ })(Fit || (Fit = {}));
259
+ // Alignment options for the canvas
260
+ var Alignment;
261
+ (function (Alignment) {
262
+ Alignment["Center"] = "center";
263
+ Alignment["TopLeft"] = "topLeft";
264
+ Alignment["TopCenter"] = "topCenter";
265
+ Alignment["TopRight"] = "topRight";
266
+ Alignment["CenterLeft"] = "centerLeft";
267
+ Alignment["CenterRight"] = "centerRight";
268
+ Alignment["BottomLeft"] = "bottomLeft";
269
+ Alignment["BottomCenter"] = "bottomCenter";
270
+ Alignment["BottomRight"] = "bottomRight";
271
+ })(Alignment || (Alignment = {}));
272
+ // Alignment options for Rive animations in a HTML canvas
273
+ var Layout = /** @class */ (function () {
274
+ function Layout(params) {
275
+ var _a, _b, _c, _d, _e, _f;
276
+ this.fit = (_a = params === null || params === void 0 ? void 0 : params.fit) !== null && _a !== void 0 ? _a : Fit.Contain;
277
+ this.alignment = (_b = params === null || params === void 0 ? void 0 : params.alignment) !== null && _b !== void 0 ? _b : Alignment.Center;
278
+ this.minX = (_c = params === null || params === void 0 ? void 0 : params.minX) !== null && _c !== void 0 ? _c : 0;
279
+ this.minY = (_d = params === null || params === void 0 ? void 0 : params.minY) !== null && _d !== void 0 ? _d : 0;
280
+ this.maxX = (_e = params === null || params === void 0 ? void 0 : params.maxX) !== null && _e !== void 0 ? _e : 0;
281
+ this.maxY = (_f = params === null || params === void 0 ? void 0 : params.maxY) !== null && _f !== void 0 ? _f : 0;
282
+ }
283
+ // Alternative constructor to build a Layout from an interface/object
284
+ Layout.new = function (_a) {
285
+ var fit = _a.fit, alignment = _a.alignment, minX = _a.minX, minY = _a.minY, maxX = _a.maxX, maxY = _a.maxY;
286
+ console.warn('This function is deprecated: please use `new Layout({})` instead');
287
+ return new Layout({ fit: fit, alignment: alignment, minX: minX, minY: minY, maxX: maxX, maxY: maxY });
288
+ };
289
+ /**
290
+ * Makes a copy of the layout, replacing any specified parameters
291
+ */
292
+ Layout.prototype.copyWith = function (_a) {
293
+ var fit = _a.fit, alignment = _a.alignment, minX = _a.minX, minY = _a.minY, maxX = _a.maxX, maxY = _a.maxY;
294
+ return new Layout({
295
+ fit: fit !== null && fit !== void 0 ? fit : this.fit,
296
+ alignment: alignment !== null && alignment !== void 0 ? alignment : this.alignment,
297
+ minX: minX !== null && minX !== void 0 ? minX : this.minX,
298
+ minY: minY !== null && minY !== void 0 ? minY : this.minY,
299
+ maxX: maxX !== null && maxX !== void 0 ? maxX : this.maxX,
300
+ maxY: maxY !== null && maxY !== void 0 ? maxY : this.maxY
301
+ });
302
+ };
303
+ // Returns fit for the Wasm runtime format
304
+ Layout.prototype.runtimeFit = function (rive) {
305
+ if (this.cachedRuntimeFit)
306
+ return this.cachedRuntimeFit;
307
+ var fit;
308
+ if (this.fit === Fit.Cover)
309
+ fit = rive.Fit.cover;
310
+ else if (this.fit === Fit.Contain)
311
+ fit = rive.Fit.contain;
312
+ else if (this.fit === Fit.Fill)
313
+ fit = rive.Fit.fill;
314
+ else if (this.fit === Fit.FitWidth)
315
+ fit = rive.Fit.fitWidth;
316
+ else if (this.fit === Fit.FitHeight)
317
+ fit = rive.Fit.fitHeight;
318
+ else if (this.fit === Fit.ScaleDown)
319
+ fit = rive.Fit.scaleDown;
320
+ else
321
+ fit = rive.Fit.none;
322
+ this.cachedRuntimeFit = fit;
323
+ return fit;
324
+ };
325
+ // Returns alignment for the Wasm runtime format
326
+ Layout.prototype.runtimeAlignment = function (rive) {
327
+ if (this.cachedRuntimeAlignment)
328
+ return this.cachedRuntimeAlignment;
329
+ var alignment;
330
+ if (this.alignment === Alignment.TopLeft)
331
+ alignment = rive.Alignment.topLeft;
332
+ else if (this.alignment === Alignment.TopCenter)
333
+ alignment = rive.Alignment.topCenter;
334
+ else if (this.alignment === Alignment.TopRight)
335
+ alignment = rive.Alignment.topRight;
336
+ else if (this.alignment === Alignment.CenterLeft)
337
+ alignment = rive.Alignment.centerLeft;
338
+ else if (this.alignment === Alignment.CenterRight)
339
+ alignment = rive.Alignment.centerRight;
340
+ else if (this.alignment === Alignment.BottomLeft)
341
+ alignment = rive.Alignment.bottomLeft;
342
+ else if (this.alignment === Alignment.BottomCenter)
343
+ alignment = rive.Alignment.bottomCenter;
344
+ else if (this.alignment === Alignment.BottomRight)
345
+ alignment = rive.Alignment.bottomRight;
346
+ else
347
+ alignment = rive.Alignment.center;
348
+ this.cachedRuntimeAlignment = alignment;
349
+ return alignment;
350
+ };
351
+ return Layout;
352
+ }());
353
+
354
+ // Runtime singleton; use getInstance to provide a callback that returns the
355
+ // Rive runtime
356
+ var RuntimeLoader = /** @class */ (function () {
357
+ // Class is never instantiated
358
+ function RuntimeLoader() {
359
+ }
360
+ // Loads the runtime
361
+ RuntimeLoader.loadRuntime = function () {
362
+ _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__.default({
363
+ // Loads Wasm bundle
364
+ locateFile: function (_) { return RuntimeLoader.wasmURL; }
365
+ }).then(function (rive) {
366
+ var _a;
367
+ RuntimeLoader.runtime = rive;
368
+ // Fire all the callbacks
369
+ while (RuntimeLoader.callBackQueue.length > 0) {
370
+ (_a = RuntimeLoader.callBackQueue.shift()) === null || _a === void 0 ? void 0 : _a(RuntimeLoader.runtime);
371
+ }
372
+ });
373
+ };
374
+ // Provides a runtime instance via a callback
375
+ RuntimeLoader.getInstance = function (callback) {
376
+ // If it's not loading, start loading runtime
377
+ if (!RuntimeLoader.isLoading) {
378
+ RuntimeLoader.isLoading = true;
379
+ RuntimeLoader.loadRuntime();
380
+ }
381
+ if (!RuntimeLoader.runtime) {
382
+ RuntimeLoader.callBackQueue.push(callback);
383
+ }
384
+ else {
385
+ callback(RuntimeLoader.runtime);
386
+ }
387
+ };
388
+ // Provides a runtime instance via a promise
389
+ RuntimeLoader.awaitInstance = function () {
390
+ return new Promise(function (resolve, reject) {
391
+ return RuntimeLoader.getInstance(function (rive) { return resolve(rive); });
392
+ });
393
+ };
394
+ // Manually sets the wasm url
395
+ RuntimeLoader.setWasmUrl = function (url) {
396
+ RuntimeLoader.wasmURL = url;
397
+ };
398
+ // Flag to indicate that loading has started/completed
399
+ RuntimeLoader.isLoading = false;
400
+ // List of callbacks for the runtime that come in while loading
401
+ RuntimeLoader.callBackQueue = [];
402
+ // Path to the Wasm file; default path works for testing only;
403
+ // if embedded wasm is used then this is never used.
404
+ RuntimeLoader.wasmURL = "https://unpkg.com/" + package_json__WEBPACK_IMPORTED_MODULE_1__.name + "@" + package_json__WEBPACK_IMPORTED_MODULE_1__.version + "/rive.wasm";
405
+ return RuntimeLoader;
406
+ }());
407
+
408
+ // #endregion
409
+ // #region animations
410
+ // Wraps animations and instances from the runtime and keeps track of playback
411
+ // state
412
+ var Animation = /** @class */ (function () {
413
+ /**
414
+ * Constructs a new animation
415
+ * @constructor
416
+ * @param {any} animation: runtime animation object
417
+ * @param {any} instance: runtime animation instance object
418
+ */
419
+ function Animation(animation, runtime, playing) {
420
+ this.animation = animation;
421
+ this.playing = playing;
422
+ this.loopCount = 0;
423
+ // Time to which the animation should move to on the next render
424
+ this.scrubTo = null;
425
+ this.instance = new runtime.LinearAnimationInstance(animation);
426
+ }
427
+ Object.defineProperty(Animation.prototype, "name", {
428
+ // Returns the animation's name
429
+ get: function () {
430
+ return this.animation.name;
431
+ },
432
+ enumerable: false,
433
+ configurable: true
434
+ });
435
+ Object.defineProperty(Animation.prototype, "time", {
436
+ // Returns the animation's current time
437
+ get: function () {
438
+ return this.instance.time;
439
+ },
440
+ // Sets the animation's current time
441
+ set: function (value) {
442
+ this.instance.time = value;
443
+ },
444
+ enumerable: false,
445
+ configurable: true
446
+ });
447
+ Object.defineProperty(Animation.prototype, "loopValue", {
448
+ // Returns the animation's loop type
449
+ get: function () {
450
+ return this.animation.loopValue;
451
+ },
452
+ enumerable: false,
453
+ configurable: true
454
+ });
455
+ /**
456
+ * Advances the animation by the give time. If the animation needs scrubbing,
457
+ * time is ignored and the stored scrub value is used.
458
+ * @param time the time to advance the animation by if no scrubbing required
459
+ */
460
+ Animation.prototype.advance = function (time) {
461
+ if (this.scrubTo === null) {
462
+ this.instance.advance(time);
463
+ }
464
+ else {
465
+ this.instance.time = 0;
466
+ this.instance.advance(this.scrubTo);
467
+ this.scrubTo = null;
468
+ }
469
+ };
470
+ Object.defineProperty(Animation.prototype, "needsScrub", {
471
+ get: function () {
472
+ return this.scrubTo !== null;
473
+ },
474
+ enumerable: false,
475
+ configurable: true
476
+ });
477
+ /**
478
+ * Deletes the backing Wasm animation instance; once this is called, this
479
+ * animation is no more.
480
+ */
481
+ Animation.prototype.cleanup = function () {
482
+ this.instance.delete();
483
+ };
484
+ return Animation;
485
+ }());
486
+ // #endregion
487
+ // #region state machines
488
+ var StateMachineInputType;
489
+ (function (StateMachineInputType) {
490
+ StateMachineInputType[StateMachineInputType["Number"] = 56] = "Number";
491
+ StateMachineInputType[StateMachineInputType["Trigger"] = 58] = "Trigger";
492
+ StateMachineInputType[StateMachineInputType["Boolean"] = 59] = "Boolean";
493
+ })(StateMachineInputType || (StateMachineInputType = {}));
494
+ /**
495
+ * An input for a state machine
496
+ */
497
+ var StateMachineInput = /** @class */ (function () {
498
+ function StateMachineInput(type, runtimeInput) {
499
+ this.type = type;
500
+ this.runtimeInput = runtimeInput;
501
+ }
502
+ Object.defineProperty(StateMachineInput.prototype, "name", {
503
+ /**
504
+ * Returns the name of the input
505
+ */
506
+ get: function () {
507
+ return this.runtimeInput.name;
508
+ },
509
+ enumerable: false,
510
+ configurable: true
511
+ });
512
+ Object.defineProperty(StateMachineInput.prototype, "value", {
513
+ /**
514
+ * Returns the current value of the input
515
+ */
516
+ get: function () {
517
+ return this.runtimeInput.value;
518
+ },
519
+ /**
520
+ * Sets the value of the input
521
+ */
522
+ set: function (value) {
523
+ this.runtimeInput.value = value;
524
+ },
525
+ enumerable: false,
526
+ configurable: true
527
+ });
528
+ /**
529
+ * Fires a trigger; does nothing on Number or Boolean input types
530
+ */
531
+ StateMachineInput.prototype.fire = function () {
532
+ if (this.type === StateMachineInputType.Trigger) {
533
+ this.runtimeInput.fire();
534
+ }
535
+ };
536
+ return StateMachineInput;
537
+ }());
538
+
539
+ var StateMachine = /** @class */ (function () {
540
+ /**
541
+ * @constructor
542
+ * @param stateMachine runtime state machine object
543
+ * @param instance runtime state machine instance object
544
+ */
545
+ function StateMachine(stateMachine, runtime, playing) {
546
+ this.stateMachine = stateMachine;
547
+ this.playing = playing;
548
+ /**
549
+ * Caches the inputs from the runtime
550
+ */
551
+ this.inputs = [];
552
+ this.instance = new runtime.StateMachineInstance(stateMachine);
553
+ this.initInputs(runtime);
554
+ }
555
+ Object.defineProperty(StateMachine.prototype, "name", {
556
+ get: function () {
557
+ return this.stateMachine.name;
558
+ },
559
+ enumerable: false,
560
+ configurable: true
561
+ });
562
+ Object.defineProperty(StateMachine.prototype, "statesChanged", {
563
+ /**
564
+ * Returns a list of state names that have changed on this frame
565
+ */
566
+ get: function () {
567
+ var names = [];
568
+ for (var i = 0; i < this.instance.stateChangedCount(); i++) {
569
+ names.push(this.instance.stateChangedNameByIndex(i));
570
+ }
571
+ return names;
572
+ },
573
+ enumerable: false,
574
+ configurable: true
575
+ });
576
+ /**
577
+ * Fetches references to the state machine's inputs and caches them
578
+ * @param runtime an instance of the runtime; needed for the SMIInput types
579
+ */
580
+ StateMachine.prototype.initInputs = function (runtime) {
581
+ // Fetch the inputs from the runtime if we don't have them
582
+ for (var i = 0; i < this.instance.inputCount(); i++) {
583
+ var input = this.instance.input(i);
584
+ this.inputs.push(this.mapRuntimeInput(input, runtime));
585
+ }
586
+ };
587
+ /**
588
+ * Maps a runtime input to it's appropriate type
589
+ * @param input
590
+ */
591
+ StateMachine.prototype.mapRuntimeInput = function (input, runtime) {
592
+ if (input.type === runtime.SMIInput.bool) {
593
+ return new StateMachineInput(StateMachineInputType.Boolean, input.asBool());
594
+ }
595
+ else if (input.type === runtime.SMIInput.number) {
596
+ return new StateMachineInput(StateMachineInputType.Number, input.asNumber());
597
+ }
598
+ else if (input.type === runtime.SMIInput.trigger) {
599
+ return new StateMachineInput(StateMachineInputType.Trigger, input.asTrigger());
600
+ }
601
+ };
602
+ /**
603
+ * Deletes the backing Wasm state machine instance; once this is called, this
604
+ * state machine is no more.
605
+ */
606
+ StateMachine.prototype.cleanup = function () {
607
+ this.instance.delete();
608
+ };
609
+ return StateMachine;
610
+ }());
611
+ // #endregion
612
+ // #region animator
613
+ /**
614
+ * Manages animation
615
+ */
616
+ var Animator = /** @class */ (function () {
617
+ /**
618
+ * Constructs a new animator
619
+ * @constructor
620
+ * @param runtime Rive runtime; needed to instance animations & state machines
621
+ * @param artboard the artboard that holds all animations and state machines
622
+ * @param animations optional list of animations
623
+ * @param stateMachines optional list of state machines
624
+ */
625
+ function Animator(runtime, artboard, eventManager, animations, stateMachines) {
626
+ if (animations === void 0) { animations = []; }
627
+ if (stateMachines === void 0) { stateMachines = []; }
628
+ this.runtime = runtime;
629
+ this.artboard = artboard;
630
+ this.eventManager = eventManager;
631
+ this.animations = animations;
632
+ this.stateMachines = stateMachines;
633
+ }
634
+ /**
635
+ * Adds animations and state machines by their names. If names are shared
636
+ * between animations & state machines, then the first one found will be
637
+ * created. Best not to use the same names for these in your Rive file.
638
+ * @param animatable the name(s) of animations and state machines to add
639
+ * @returns a list of names of the playing animations and state machines
640
+ */
641
+ Animator.prototype.add = function (animatables, playing, fireEvent) {
642
+ if (fireEvent === void 0) { fireEvent = true; }
643
+ animatables = mapToStringArray(animatables);
644
+ // If animatables is empty, play or pause everything
645
+ if (animatables.length === 0) {
646
+ this.animations.forEach(function (a) { return a.playing = playing; });
647
+ this.stateMachines.forEach(function (m) { return m.playing = playing; });
648
+ }
649
+ else {
650
+ // Play/pause already instanced items, or create new instances
651
+ var instancedAnimationNames = this.animations.map(function (a) { return a.name; });
652
+ var instancedMachineNames = this.stateMachines.map(function (m) { return m.name; });
653
+ for (var i in animatables) {
654
+ var aIndex = instancedAnimationNames.indexOf(animatables[i]);
655
+ var mIndex = instancedMachineNames.indexOf(animatables[i]);
656
+ if (aIndex >= 0 || mIndex >= 0) {
657
+ if (aIndex >= 0) {
658
+ // Animation is instanced, play/pause it
659
+ this.animations[aIndex].playing = playing;
660
+ }
661
+ else {
662
+ // State machine is instanced, play/pause it
663
+ this.stateMachines[mIndex].playing = playing;
664
+ }
665
+ }
666
+ else {
667
+ // Try to create a new animation instance
668
+ var anim = this.artboard.animationByName(animatables[i]);
669
+ if (anim) {
670
+ this.animations.push(new Animation(anim, this.runtime, playing));
671
+ }
672
+ else {
673
+ // Try to create a new state machine instance
674
+ var sm = this.artboard.stateMachineByName(animatables[i]);
675
+ if (sm) {
676
+ this.stateMachines.push(new StateMachine(sm, this.runtime, playing));
677
+ }
678
+ }
679
+ }
680
+ }
681
+ }
682
+ // Fire play/paused events for animations
683
+ if (fireEvent) {
684
+ if (playing) {
685
+ this.eventManager.fire({
686
+ type: EventType.Play,
687
+ data: this.playing,
688
+ });
689
+ }
690
+ else {
691
+ this.eventManager.fire({
692
+ type: EventType.Pause,
693
+ data: this.paused,
694
+ });
695
+ }
696
+ }
697
+ return playing ? this.playing : this.paused;
698
+ };
699
+ /**
700
+ * Play the named animations/state machines
701
+ * @param animatables the names of the animations/machines to play; plays all if empty
702
+ * @returns a list of the playing items
703
+ */
704
+ Animator.prototype.play = function (animatables) {
705
+ return this.add(animatables, true);
706
+ };
707
+ /**
708
+ * Pauses named animations and state machines, or everything if nothing is
709
+ * specified
710
+ * @param animatables names of the animations and state machines to pause
711
+ * @returns a list of names of the animations and state machines paused
712
+ */
713
+ Animator.prototype.pause = function (animatables) {
714
+ return this.add(animatables, false);
715
+ };
716
+ /**
717
+ * Set time of named animations
718
+ * @param animations names of the animations to scrub
719
+ * @param value time scrub value, a floating point number to which the playhead is jumped
720
+ * @returns a list of names of the animations that were scrubbed
721
+ */
722
+ Animator.prototype.scrub = function (animatables, value) {
723
+ var forScrubbing = this.animations.filter(function (a) { return animatables.includes(a.name); });
724
+ forScrubbing.forEach(function (a) { return a.scrubTo = value; });
725
+ return forScrubbing.map(function (a) { return a.name; });
726
+ };
727
+ Object.defineProperty(Animator.prototype, "playing", {
728
+ /**
729
+ * Returns a list of names of all animations and state machines currently
730
+ * playing
731
+ */
732
+ get: function () {
733
+ return this.animations.filter(function (a) { return a.playing; }).map(function (a) { return a.name; }).concat(this.stateMachines.filter(function (m) { return m.playing; }).map(function (m) { return m.name; }));
734
+ },
735
+ enumerable: false,
736
+ configurable: true
737
+ });
738
+ Object.defineProperty(Animator.prototype, "paused", {
739
+ /**
740
+ * Returns a list of names of all animations and state machines currently
741
+ * paused
742
+ */
743
+ get: function () {
744
+ return this.animations.filter(function (a) { return !a.playing; }).map(function (a) { return a.name; }).concat(this.stateMachines.filter(function (m) { return !m.playing; }).map(function (m) { return m.name; }));
745
+ },
746
+ enumerable: false,
747
+ configurable: true
748
+ });
749
+ /**
750
+ * Stops and removes all named animations and state machines
751
+ * @param animatables animations and state machines to remove
752
+ * @returns a list of names of removed items
753
+ */
754
+ Animator.prototype.stop = function (animatables) {
755
+ var _this = this;
756
+ animatables = mapToStringArray(animatables);
757
+ // If nothing's specified, wipe them out, all of them
758
+ var removedNames = [];
759
+ // Stop everything
760
+ if (animatables.length === 0) {
761
+ removedNames = this.animations.map(function (a) { return a.name; }).concat(this.stateMachines.map(function (m) { return m.name; }));
762
+ // Clean up before emptying the arrays
763
+ this.animations.forEach(function (a) { return a.cleanup(); });
764
+ this.stateMachines.forEach(function (m) { return m.cleanup(); });
765
+ // Empty out the arrays
766
+ this.animations.splice(0, this.animations.length);
767
+ this.stateMachines.splice(0, this.stateMachines.length);
768
+ }
769
+ else {
770
+ // Remove only the named animations/state machines
771
+ var animationsToRemove = this.animations.filter(function (a) { return animatables.includes(a.name); });
772
+ animationsToRemove.forEach(function (a) {
773
+ a.cleanup();
774
+ _this.animations.splice(_this.animations.indexOf(a), 1);
775
+ });
776
+ var machinesToRemove = this.stateMachines.filter(function (m) { return animatables.includes(m.name); });
777
+ machinesToRemove.forEach(function (m) {
778
+ m.cleanup();
779
+ _this.stateMachines.splice(_this.stateMachines.indexOf(m), 1);
780
+ });
781
+ removedNames = animationsToRemove.map(function (a) { return a.name; }).concat(machinesToRemove.map(function (m) { return m.name; }));
782
+ }
783
+ this.eventManager.fire({
784
+ type: EventType.Stop,
785
+ data: removedNames,
786
+ });
787
+ // Return the list of animations removed
788
+ return removedNames;
789
+ };
790
+ Object.defineProperty(Animator.prototype, "isPlaying", {
791
+ /**
792
+ * Returns true if at least one animation is active
793
+ */
794
+ get: function () {
795
+ return this.animations.reduce(function (acc, curr) { return acc || curr.playing; }, false)
796
+ || this.stateMachines.reduce(function (acc, curr) { return acc || curr.playing; }, false);
797
+ },
798
+ enumerable: false,
799
+ configurable: true
800
+ });
801
+ Object.defineProperty(Animator.prototype, "isPaused", {
802
+ /**
803
+ * Returns true if all animations are paused and there's at least one animation
804
+ */
805
+ get: function () {
806
+ return !this.isPlaying &&
807
+ (this.animations.length > 0 || this.stateMachines.length > 0);
808
+ },
809
+ enumerable: false,
810
+ configurable: true
811
+ });
812
+ Object.defineProperty(Animator.prototype, "isStopped", {
813
+ /**
814
+ * Returns true if there are no playing or paused animations/state machines
815
+ */
816
+ get: function () {
817
+ return this.animations.length === 0 && this.stateMachines.length === 0;
818
+ },
819
+ enumerable: false,
820
+ configurable: true
821
+ });
822
+ /**
823
+ * If there are no animations or state machines, add the first one found
824
+ * @returns the name of the animation or state machine instanced
825
+ */
826
+ Animator.prototype.atLeastOne = function (playing, fireEvent) {
827
+ if (fireEvent === void 0) { fireEvent = true; }
828
+ var instancedName;
829
+ if (this.animations.length === 0 && this.stateMachines.length === 0) {
830
+ if (this.artboard.animationCount() > 0) {
831
+ // Add the first animation
832
+ this.add([instancedName = this.artboard.animationByIndex(0).name], playing, fireEvent);
833
+ }
834
+ else if (this.artboard.stateMachineCount() > 0) {
835
+ // Add the first state machine
836
+ this.add([instancedName = this.artboard.stateMachineByIndex(0).name], playing, fireEvent);
837
+ }
838
+ }
839
+ return instancedName;
840
+ };
841
+ /**
842
+ * Checks if any animations have looped and if so, fire the appropriate event
843
+ */
844
+ Animator.prototype.handleLooping = function () {
845
+ for (var _i = 0, _a = this.animations.filter(function (a) { return a.playing; }); _i < _a.length; _i++) {
846
+ var animation = _a[_i];
847
+ // Emit if the animation looped
848
+ if (animation.loopValue === 0 && animation.loopCount) {
849
+ animation.loopCount = 0;
850
+ // This is a one-shot; if it has ended, delete the instance
851
+ this.stop(animation.name);
852
+ }
853
+ else if (animation.loopValue === 1 && animation.loopCount) {
854
+ this.eventManager.fire({
855
+ type: EventType.Loop,
856
+ data: { animation: animation.name, type: LoopType.Loop }
857
+ });
858
+ animation.loopCount = 0;
859
+ }
860
+ // Wasm indicates a loop at each time the animation
861
+ // changes direction, so a full loop/lap occurs every
862
+ // two loop counts
863
+ else if (animation.loopValue === 2 && animation.loopCount > 1) {
864
+ this.eventManager.fire({
865
+ type: EventType.Loop,
866
+ data: { animation: animation.name, type: LoopType.PingPong }
867
+ });
868
+ animation.loopCount = 0;
869
+ }
870
+ }
871
+ };
872
+ /**
873
+ * Checks if states have changed in state machines and fires a statechange
874
+ * event
875
+ */
876
+ Animator.prototype.handleStateChanges = function () {
877
+ var statesChanged = [];
878
+ for (var _i = 0, _a = this.stateMachines.filter(function (sm) { return sm.playing; }); _i < _a.length; _i++) {
879
+ var stateMachine = _a[_i];
880
+ statesChanged.push.apply(statesChanged, stateMachine.statesChanged);
881
+ }
882
+ if (statesChanged.length > 0) {
883
+ this.eventManager.fire({
884
+ type: EventType.StateChange,
885
+ data: statesChanged,
886
+ });
887
+ }
888
+ };
889
+ return Animator;
890
+ }());
891
+ // #endregion
892
+ // #region events
893
+ /**
894
+ * Supported event types triggered in Rive
895
+ */
896
+ var EventType;
897
+ (function (EventType) {
898
+ EventType["Load"] = "load";
899
+ EventType["LoadError"] = "loaderror";
900
+ EventType["Play"] = "play";
901
+ EventType["Pause"] = "pause";
902
+ EventType["Stop"] = "stop";
903
+ EventType["Loop"] = "loop";
904
+ EventType["Draw"] = "draw";
905
+ EventType["StateChange"] = "statechange";
906
+ })(EventType || (EventType = {}));
907
+ /**
908
+ * Looping types: one-shot, loop, and ping-pong
909
+ */
910
+ var LoopType;
911
+ (function (LoopType) {
912
+ LoopType["OneShot"] = "oneshot";
913
+ LoopType["Loop"] = "loop";
914
+ LoopType["PingPong"] = "pingpong"; // has value 2 in runtime
915
+ })(LoopType || (LoopType = {}));
916
+ // Manages Rive events and listeners
917
+ var EventManager = /** @class */ (function () {
918
+ function EventManager(listeners) {
919
+ if (listeners === void 0) { listeners = []; }
920
+ this.listeners = listeners;
921
+ }
922
+ // Gets listeners of specified type
923
+ EventManager.prototype.getListeners = function (type) {
924
+ return this.listeners.filter(function (e) { return e.type === type; });
925
+ };
926
+ // Adds a listener
927
+ EventManager.prototype.add = function (listener) {
928
+ if (!this.listeners.includes(listener)) {
929
+ this.listeners.push(listener);
930
+ }
931
+ };
932
+ /**
933
+ * Removes a listener
934
+ * @param listener the listener with the callback to be removed
935
+ */
936
+ EventManager.prototype.remove = function (listener) {
937
+ // We can't simply look for the listener as it'll be a different instance to
938
+ // one originally subscribed. Find all the listeners of the right type and
939
+ // then check their callbacks which should match.
940
+ for (var i = 0; i < this.listeners.length; i++) {
941
+ var currentListener = this.listeners[i];
942
+ if (currentListener.type === listener.type) {
943
+ if (currentListener.callback === listener.callback) {
944
+ this.listeners.splice(i, 1);
945
+ break;
946
+ }
947
+ }
948
+ }
949
+ };
950
+ /**
951
+ * Clears all listeners of specified type, or every listener if no type is
952
+ * specified
953
+ * @param type the type of listeners to clear, or all listeners if not
954
+ * specified
955
+ */
956
+ EventManager.prototype.removeAll = function (type) {
957
+ var _this = this;
958
+ if (!type) {
959
+ this.listeners.splice(0, this.listeners.length);
960
+ }
961
+ else {
962
+ this.listeners
963
+ .filter(function (l) { return l.type === type; })
964
+ .forEach(function (l) { return _this.remove(l); });
965
+ }
966
+ };
967
+ // Fires an event
968
+ EventManager.prototype.fire = function (event) {
969
+ var eventListeners = this.getListeners(event.type);
970
+ eventListeners.forEach(function (listener) { return listener.callback(event); });
971
+ };
972
+ return EventManager;
973
+ }());
974
+ // Manages a queue of tasks
975
+ var TaskQueueManager = /** @class */ (function () {
976
+ function TaskQueueManager(eventManager) {
977
+ this.eventManager = eventManager;
978
+ this.queue = [];
979
+ }
980
+ // Adds a task top the queue
981
+ TaskQueueManager.prototype.add = function (task) {
982
+ this.queue.push(task);
983
+ };
984
+ // Processes all tasks in the queue
985
+ TaskQueueManager.prototype.process = function () {
986
+ while (this.queue.length > 0) {
987
+ var task = this.queue.shift();
988
+ task === null || task === void 0 ? void 0 : task.action();
989
+ if (task === null || task === void 0 ? void 0 : task.event) {
990
+ this.eventManager.fire(task.event);
991
+ }
992
+ }
993
+ };
994
+ return TaskQueueManager;
995
+ }());
996
+ var Rive = /** @class */ (function () {
997
+ function Rive(params) {
998
+ var _a;
999
+ // Flag to indicate if the layout has changed; used by the renderer to know
1000
+ // when to align
1001
+ this._updateLayout = true;
1002
+ /**
1003
+ * Flag to active/deactivate renderer
1004
+ */
1005
+ this.isRendererActive = true;
1006
+ // Tracks if a Rive file is loaded
1007
+ this.loaded = false;
1008
+ /**
1009
+ * Tracks if a Rive file is loaded; we need this in addition to loaded as some
1010
+ * commands (e.g. contents) can be called as soon as the file is loaded.
1011
+ * However, playback commands need to be queued and run in order once initial
1012
+ * animations and autoplay has been sorted out. This applies to play, pause,
1013
+ * and start.
1014
+ */
1015
+ this.readyForPlaying = false;
1016
+ // Runtime artboard
1017
+ this.artboard = null;
1018
+ /**
1019
+ * Used be draw to track when a second of active rendering time has passed. Used for debugging purposes
1020
+ */
1021
+ this.renderSecondTimer = 0;
1022
+ this.canvas = params.canvas;
1023
+ this.src = params.src;
1024
+ this.buffer = params.buffer;
1025
+ this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
1026
+ // New event management system
1027
+ this.eventManager = new EventManager();
1028
+ if (params.onLoad)
1029
+ this.on(EventType.Load, params.onLoad);
1030
+ if (params.onLoadError)
1031
+ this.on(EventType.LoadError, params.onLoadError);
1032
+ if (params.onPlay)
1033
+ this.on(EventType.Play, params.onPlay);
1034
+ if (params.onPause)
1035
+ this.on(EventType.Pause, params.onPause);
1036
+ if (params.onStop)
1037
+ this.on(EventType.Stop, params.onStop);
1038
+ if (params.onLoop)
1039
+ this.on(EventType.Loop, params.onLoop);
1040
+ if (params.onStateChange)
1041
+ this.on(EventType.StateChange, params.onStateChange);
1042
+ /**
1043
+ * @deprecated Use camelCase'd versions instead.
1044
+ */
1045
+ if (params.onload && !params.onLoad)
1046
+ this.on(EventType.Load, params.onload);
1047
+ if (params.onloaderror && !params.onLoadError)
1048
+ this.on(EventType.LoadError, params.onloaderror);
1049
+ if (params.onplay && !params.onPlay)
1050
+ this.on(EventType.Play, params.onplay);
1051
+ if (params.onpause && !params.onPause)
1052
+ this.on(EventType.Pause, params.onpause);
1053
+ if (params.onstop && !params.onStop)
1054
+ this.on(EventType.Stop, params.onstop);
1055
+ if (params.onloop && !params.onLoop)
1056
+ this.on(EventType.Loop, params.onloop);
1057
+ if (params.onstatechange && !params.onStateChange)
1058
+ this.on(EventType.StateChange, params.onstatechange);
1059
+ // Hook up the task queue
1060
+ this.taskQueue = new TaskQueueManager(this.eventManager);
1061
+ this.init({
1062
+ src: this.src,
1063
+ buffer: this.buffer,
1064
+ autoplay: params.autoplay,
1065
+ animations: params.animations,
1066
+ stateMachines: params.stateMachines,
1067
+ artboard: params.artboard
1068
+ });
1069
+ }
1070
+ // Alternative constructor to build a Rive instance from an interface/object
1071
+ Rive.new = function (params) {
1072
+ console.warn('This function is deprecated: please use `new Rive({})` instead');
1073
+ return new Rive(params);
1074
+ };
1075
+ // Initializes the Rive object either from constructor or load()
1076
+ Rive.prototype.init = function (_a) {
1077
+ var _this = this;
1078
+ var src = _a.src, buffer = _a.buffer, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b;
1079
+ this.src = src;
1080
+ this.buffer = buffer;
1081
+ // If no source file url specified, it's a bust
1082
+ if (!this.src && !this.buffer) {
1083
+ throw new Error(Rive.missingErrorMessage);
1084
+ }
1085
+ // List of animations that should be initialized.
1086
+ var startingAnimationNames = mapToStringArray(animations);
1087
+ // List of state machines that should be initialized
1088
+ var startingStateMachineNames = mapToStringArray(stateMachines);
1089
+ // Ensure loaded is marked as false if loading new file
1090
+ this.loaded = false;
1091
+ this.readyForPlaying = false;
1092
+ // Ensure the runtime is loaded
1093
+ RuntimeLoader.awaitInstance().then(function (runtime) {
1094
+ _this.runtime = runtime;
1095
+ // Load Rive data from a source uri or a data buffer
1096
+ _this.initData(artboard, startingAnimationNames, startingStateMachineNames, autoplay).catch(function (e) {
1097
+ console.error(e);
1098
+ });
1099
+ }).catch(function (e) {
1100
+ console.error(e);
1101
+ });
1102
+ };
1103
+ // Initializes runtime with Rive data and preps for playing
1104
+ Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
1105
+ var _a;
1106
+ return __awaiter(this, void 0, void 0, function () {
1107
+ var _b, _c, msg;
1108
+ return __generator(this, function (_d) {
1109
+ switch (_d.label) {
1110
+ case 0:
1111
+ if (!this.src) return [3 /*break*/, 2];
1112
+ _b = this;
1113
+ return [4 /*yield*/, loadRiveFile(this.src)];
1114
+ case 1:
1115
+ _b.buffer = _d.sent();
1116
+ _d.label = 2;
1117
+ case 2:
1118
+ // Load the Rive file
1119
+ _c = this;
1120
+ return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer))];
1121
+ case 3:
1122
+ // Load the Rive file
1123
+ _c.file = _d.sent();
1124
+ if (this.file) {
1125
+ // Initialize and draw frame
1126
+ this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
1127
+ // Everything's set up, emit a load event
1128
+ this.loaded = true;
1129
+ this.eventManager.fire({
1130
+ type: EventType.Load,
1131
+ data: (_a = this.src) !== null && _a !== void 0 ? _a : 'buffer'
1132
+ });
1133
+ // Flag ready for playback commands and clear the task queue; this order
1134
+ // is important or it may infinitely recurse
1135
+ this.readyForPlaying = true;
1136
+ this.taskQueue.process();
1137
+ this.drawFrame();
1138
+ return [2 /*return*/, Promise.resolve()];
1139
+ }
1140
+ else {
1141
+ msg = 'Problem loading file; may be corrupt!';
1142
+ console.warn(msg);
1143
+ this.eventManager.fire({ type: EventType.LoadError, data: msg });
1144
+ return [2 /*return*/, Promise.reject(msg)];
1145
+ }
1146
+ return [2 /*return*/];
1147
+ }
1148
+ });
1149
+ });
1150
+ };
1151
+ // Initialize for playback
1152
+ Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay) {
1153
+ // Fetch the artboard
1154
+ var rootArtboard = artboardName ?
1155
+ this.file.artboardByName(artboardName) :
1156
+ this.file.defaultArtboard();
1157
+ // Check we have a working artboard
1158
+ if (!rootArtboard) {
1159
+ var msg = 'Invalid artboard name or no default artboard';
1160
+ console.warn(msg);
1161
+ this.eventManager.fire({ type: EventType.LoadError, data: msg });
1162
+ return;
1163
+ }
1164
+ // Instance the artboard
1165
+ this.artboard = rootArtboard.instance();
1166
+ // Check that the artboard has at least 1 animation
1167
+ if (this.artboard.animationCount() < 1) {
1168
+ var msg = 'Artboard has no animations';
1169
+ this.eventManager.fire({ type: EventType.LoadError, data: msg });
1170
+ throw msg;
1171
+ }
1172
+ // Initialize the animator
1173
+ this.animator = new Animator(this.runtime, this.artboard, this.eventManager);
1174
+ // Get the canvas where you want to render the animation and create a renderer
1175
+ this.renderer = this.runtime.makeRenderer(this.canvas);
1176
+ // Initialize the animations; as loaded hasn't happened yet, we need to
1177
+ // suppress firing the play/pause events until the load event has fired. To
1178
+ // do this we tell the animator to suppress firing events, and add event
1179
+ // firing to the task queue.
1180
+ var instanceNames;
1181
+ if (animationNames.length > 0 || stateMachineNames.length > 0) {
1182
+ instanceNames = animationNames.concat(stateMachineNames);
1183
+ this.animator.add(instanceNames, autoplay, false);
1184
+ }
1185
+ else {
1186
+ instanceNames = [this.animator.atLeastOne(autoplay, false)];
1187
+ }
1188
+ // Queue up firing the playback events
1189
+ this.taskQueue.add({
1190
+ action: function () { },
1191
+ event: {
1192
+ type: autoplay ? EventType.Play : EventType.Pause,
1193
+ data: instanceNames,
1194
+ }
1195
+ });
1196
+ };
1197
+ // Draws the current artboard frame
1198
+ Rive.prototype.drawFrame = function () {
1199
+ this.startRendering();
1200
+ };
1201
+ /**
1202
+ * Draw rendering loop; renders animation frames at the correct time interval.
1203
+ * @param time the time at which to render a frame
1204
+ */
1205
+ Rive.prototype.draw = function (time, onSecond) {
1206
+ // Clear the frameRequestId, as we're now rendering a fresh frame
1207
+ this.frameRequestId = null;
1208
+ // On the first pass, make sure lastTime has a valid value
1209
+ if (!this.lastRenderTime) {
1210
+ this.lastRenderTime = time;
1211
+ }
1212
+ // Handle the onSecond callback
1213
+ this.renderSecondTimer += (time - this.lastRenderTime);
1214
+ if (this.renderSecondTimer > 5000) {
1215
+ this.renderSecondTimer = 0;
1216
+ onSecond === null || onSecond === void 0 ? void 0 : onSecond();
1217
+ }
1218
+ // Calculate the elapsed time between frames in seconds
1219
+ var elapsedTime = (time - this.lastRenderTime) / 1000;
1220
+ this.lastRenderTime = time;
1221
+ // Advance non-paused animations by the elapsed number of seconds
1222
+ // Also advance any animations that require scrubbing
1223
+ var activeAnimations = this.animator.animations.filter(function (a) { return a.playing || a.needsScrub; })
1224
+ // The scrubbed animations must be applied first to prevent weird artifacts
1225
+ // if the playing animations conflict with the scrubbed animating attribuates.
1226
+ .sort(function (first, second) { return first.needsScrub ? -1 : 1; });
1227
+ for (var _i = 0, activeAnimations_1 = activeAnimations; _i < activeAnimations_1.length; _i++) {
1228
+ var animation = activeAnimations_1[_i];
1229
+ animation.advance(elapsedTime);
1230
+ if (animation.instance.didLoop) {
1231
+ animation.loopCount += 1;
1232
+ }
1233
+ animation.instance.apply(this.artboard, 1.0);
1234
+ }
1235
+ // Advance non-paused state machines by the elapsed number of seconds
1236
+ var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
1237
+ for (var _a = 0, activeStateMachines_1 = activeStateMachines; _a < activeStateMachines_1.length; _a++) {
1238
+ var stateMachine = activeStateMachines_1[_a];
1239
+ stateMachine.instance.advance(this.artboard, elapsedTime);
1240
+ // stateMachine.instance.apply(this.artboard);
1241
+ }
1242
+ // Once the animations have been applied to the artboard, advance it
1243
+ // by the elapsed time.
1244
+ this.artboard.advance(elapsedTime);
1245
+ var renderer = this.renderer;
1246
+ renderer.save();
1247
+ // Update the renderer alignment if necessary
1248
+ this.alignRenderer();
1249
+ this.artboard.draw(renderer);
1250
+ renderer.restore();
1251
+ renderer.flush();
1252
+ // Check for any animations that looped
1253
+ this.animator.handleLooping();
1254
+ // Check for any state machines that had a state change
1255
+ this.animator.handleStateChanges();
1256
+ // Calling requestAnimationFrame will rerun draw() at the correct rate:
1257
+ // https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
1258
+ if (this.animator.isPlaying) {
1259
+ // Request a new rendering frame
1260
+ this.startRendering();
1261
+ }
1262
+ else if (this.animator.isPaused) {
1263
+ // Reset the end time so on playback it starts at the correct frame
1264
+ this.lastRenderTime = 0;
1265
+ }
1266
+ else if (this.animator.isStopped) {
1267
+ // Reset animation instances, artboard and time
1268
+ // TODO: implement this properly when we have instancing
1269
+ // this.initArtboard();
1270
+ // this.drawFrame();
1271
+ this.lastRenderTime = 0;
1272
+ }
1273
+ };
1274
+ /**
1275
+ * Align the renderer
1276
+ */
1277
+ Rive.prototype.alignRenderer = function () {
1278
+ var _a = this, renderer = _a.renderer, runtime = _a.runtime, _layout = _a._layout, artboard = _a.artboard;
1279
+ // Canvas must be wiped to prevent artifacts
1280
+ renderer.clear();
1281
+ // Now save so that future changes to align can restore
1282
+ renderer.save();
1283
+ // Align things up safe in the knowledge we can restore if changed
1284
+ renderer.align(_layout.runtimeFit(runtime), _layout.runtimeAlignment(runtime), {
1285
+ minX: _layout.minX,
1286
+ minY: _layout.minY,
1287
+ maxX: _layout.maxX,
1288
+ maxY: _layout.maxY
1289
+ }, artboard.bounds);
1290
+ };
1291
+ /**
1292
+ * Cleans up any Wasm-generated objects that need to be manually destroyed:
1293
+ * artboard instances, animation instances, state machine instances.
1294
+ *
1295
+ * Once this is called, things will need to be reinitialized or bad things
1296
+ * might happen.
1297
+ */
1298
+ Rive.prototype.cleanup = function () {
1299
+ this.artboard.delete();
1300
+ // TODO: delete animation and state machine instances
1301
+ };
1302
+ // Plays specified animations; if none specified, it unpauses everything.
1303
+ Rive.prototype.play = function (animationNames, autoplay) {
1304
+ var _this = this;
1305
+ animationNames = mapToStringArray(animationNames);
1306
+ // If the file's not loaded, queue up the play
1307
+ if (!this.readyForPlaying) {
1308
+ this.taskQueue.add({
1309
+ action: function () { return _this.play(animationNames, autoplay); },
1310
+ });
1311
+ return;
1312
+ }
1313
+ this.animator.play(animationNames);
1314
+ this.startRendering();
1315
+ };
1316
+ // Pauses specified animations; if none specified, pauses all.
1317
+ Rive.prototype.pause = function (animationNames) {
1318
+ var _this = this;
1319
+ animationNames = mapToStringArray(animationNames);
1320
+ // If the file's not loaded, early out, nothing to pause
1321
+ if (!this.readyForPlaying) {
1322
+ this.taskQueue.add({
1323
+ action: function () { return _this.pause(animationNames); },
1324
+ });
1325
+ return;
1326
+ }
1327
+ this.animator.pause(animationNames);
1328
+ };
1329
+ Rive.prototype.scrub = function (animationNames, value) {
1330
+ var _this = this;
1331
+ animationNames = mapToStringArray(animationNames);
1332
+ // If the file's not loaded, early out, nothing to pause
1333
+ if (!this.readyForPlaying) {
1334
+ this.taskQueue.add({
1335
+ action: function () { return _this.scrub(animationNames, value); },
1336
+ });
1337
+ return;
1338
+ }
1339
+ // Scrub the animation time; we draw a single frame here so that if
1340
+ // nothing's currently playing, the scrubbed animation is still rendered/
1341
+ this.animator.scrub(animationNames, value || 0);
1342
+ this.drawFrame();
1343
+ };
1344
+ // Stops specified animations; if none specifies, stops them all.
1345
+ Rive.prototype.stop = function (animationNames) {
1346
+ var _this = this;
1347
+ animationNames = mapToStringArray(animationNames);
1348
+ // If the file's not loaded, early out, nothing to pause
1349
+ if (!this.readyForPlaying) {
1350
+ this.taskQueue.add({
1351
+ action: function () { return _this.stop(animationNames); },
1352
+ });
1353
+ return;
1354
+ }
1355
+ this.animator.stop(animationNames);
1356
+ };
1357
+ /**
1358
+ * Resets the animation
1359
+ * @param artboard the name of the artboard, or default if none given
1360
+ * @param animations the names of animations for playback
1361
+ * @param stateMachines the names of state machines for playback
1362
+ * @param autoplay whether to autoplay when reset, defaults to false
1363
+ *
1364
+ */
1365
+ Rive.prototype.reset = function (params) {
1366
+ var _a;
1367
+ // Get the current artboard, animations, state machines, and playback states
1368
+ var artBoardName = params === null || params === void 0 ? void 0 : params.artboard;
1369
+ var animationNames = mapToStringArray(params === null || params === void 0 ? void 0 : params.animations);
1370
+ var stateMachineNames = mapToStringArray(params === null || params === void 0 ? void 0 : params.stateMachines);
1371
+ var autoplay = (_a = params === null || params === void 0 ? void 0 : params.autoplay) !== null && _a !== void 0 ? _a : false;
1372
+ // Stop everything and clean up
1373
+ this.stop();
1374
+ this.cleanup();
1375
+ // Reinitialize an artboard instance with the state
1376
+ this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay);
1377
+ };
1378
+ // Loads a new Rive file, keeping listeners in place
1379
+ Rive.prototype.load = function (params) {
1380
+ // Stop all animations
1381
+ this.stop();
1382
+ // Reinitialize
1383
+ this.init(params);
1384
+ };
1385
+ Object.defineProperty(Rive.prototype, "layout", {
1386
+ /**
1387
+ * Returns the current layout. Note that layout should be treated as
1388
+ * immutable. If you want to change the layout, create a new one use the
1389
+ * layout setter
1390
+ */
1391
+ get: function () {
1392
+ return this._layout;
1393
+ },
1394
+ // Sets a new layout
1395
+ set: function (layout) {
1396
+ this._layout = layout;
1397
+ // If the maxX or maxY are 0, then set them to the canvas width and height
1398
+ if (!layout.maxX || !layout.maxY) {
1399
+ this.resizeToCanvas();
1400
+ }
1401
+ if (this.loaded && !this.animator.isPlaying) {
1402
+ this.drawFrame();
1403
+ }
1404
+ },
1405
+ enumerable: false,
1406
+ configurable: true
1407
+ });
1408
+ /**
1409
+ * Sets the layout bounds to the current canvas size; this is typically called
1410
+ * when the canvas is resized
1411
+ */
1412
+ Rive.prototype.resizeToCanvas = function () {
1413
+ this._layout = this.layout.copyWith({
1414
+ minX: 0,
1415
+ minY: 0,
1416
+ maxX: this.canvas.width,
1417
+ maxY: this.canvas.height
1418
+ });
1419
+ };
1420
+ Object.defineProperty(Rive.prototype, "source", {
1421
+ // Returns the animation source, which may be undefined
1422
+ get: function () {
1423
+ return this.src;
1424
+ },
1425
+ enumerable: false,
1426
+ configurable: true
1427
+ });
1428
+ Object.defineProperty(Rive.prototype, "activeArtboard", {
1429
+ /**
1430
+ * Returns the name of the active artboard
1431
+ */
1432
+ get: function () {
1433
+ return this.artboard.name;
1434
+ },
1435
+ enumerable: false,
1436
+ configurable: true
1437
+ });
1438
+ Object.defineProperty(Rive.prototype, "animationNames", {
1439
+ // Returns a list of animation names on the chosen artboard
1440
+ get: function () {
1441
+ // If the file's not loaded, we got nothing to return
1442
+ if (!this.loaded) {
1443
+ return [];
1444
+ }
1445
+ var animationNames = [];
1446
+ for (var i = 0; i < this.artboard.animationCount(); i++) {
1447
+ animationNames.push(this.artboard.animationByIndex(i).name);
1448
+ }
1449
+ return animationNames;
1450
+ },
1451
+ enumerable: false,
1452
+ configurable: true
1453
+ });
1454
+ Object.defineProperty(Rive.prototype, "stateMachineNames", {
1455
+ /**
1456
+ * Returns a list of state machine names from the current artboard
1457
+ */
1458
+ get: function () {
1459
+ // If the file's not loaded, we got nothing to return
1460
+ if (!this.loaded) {
1461
+ return [];
1462
+ }
1463
+ var stateMachineNames = [];
1464
+ for (var i = 0; i < this.artboard.stateMachineCount(); i++) {
1465
+ stateMachineNames.push(this.artboard.stateMachineByIndex(i).name);
1466
+ }
1467
+ return stateMachineNames;
1468
+ },
1469
+ enumerable: false,
1470
+ configurable: true
1471
+ });
1472
+ /**
1473
+ * Returns the inputs for the specified instanced state machine, or an empty
1474
+ * list if the name is invalid or the state machine is not instanced
1475
+ * @param name the state machine name
1476
+ * @returns the inputs for the named state machine
1477
+ */
1478
+ Rive.prototype.stateMachineInputs = function (name) {
1479
+ // If the file's not loaded, early out, nothing to pause
1480
+ if (!this.loaded) {
1481
+ return;
1482
+ }
1483
+ var stateMachine = this.animator.stateMachines.find(function (m) { return m.name === name; });
1484
+ return stateMachine === null || stateMachine === void 0 ? void 0 : stateMachine.inputs;
1485
+ };
1486
+ Object.defineProperty(Rive.prototype, "playingStateMachineNames", {
1487
+ // Returns a list of playing machine names
1488
+ get: function () {
1489
+ // If the file's not loaded, we got nothing to return
1490
+ if (!this.loaded) {
1491
+ return [];
1492
+ }
1493
+ return this.animator.stateMachines
1494
+ .filter(function (m) { return m.playing; })
1495
+ .map(function (m) { return m.name; });
1496
+ },
1497
+ enumerable: false,
1498
+ configurable: true
1499
+ });
1500
+ Object.defineProperty(Rive.prototype, "playingAnimationNames", {
1501
+ // Returns a list of playing animation names
1502
+ get: function () {
1503
+ // If the file's not loaded, we got nothing to return
1504
+ if (!this.loaded) {
1505
+ return [];
1506
+ }
1507
+ return this.animator.animations
1508
+ .filter(function (a) { return a.playing; })
1509
+ .map(function (a) { return a.name; });
1510
+ },
1511
+ enumerable: false,
1512
+ configurable: true
1513
+ });
1514
+ Object.defineProperty(Rive.prototype, "pausedAnimationNames", {
1515
+ // Returns a list of paused animation names
1516
+ get: function () {
1517
+ // If the file's not loaded, we got nothing to return
1518
+ if (!this.loaded) {
1519
+ return [];
1520
+ }
1521
+ return this.animator.animations
1522
+ .filter(function (a) { return !a.playing; })
1523
+ .map(function (a) { return a.name; });
1524
+ },
1525
+ enumerable: false,
1526
+ configurable: true
1527
+ });
1528
+ Object.defineProperty(Rive.prototype, "pausedStateMachineNames", {
1529
+ /**
1530
+ * Returns a list of paused machine names
1531
+ * @returns a list of state machine names that are paused
1532
+ */
1533
+ get: function () {
1534
+ // If the file's not loaded, we got nothing to return
1535
+ if (!this.loaded) {
1536
+ return [];
1537
+ }
1538
+ return this.animator.stateMachines
1539
+ .filter(function (m) { return !m.playing; })
1540
+ .map(function (m) { return m.name; });
1541
+ },
1542
+ enumerable: false,
1543
+ configurable: true
1544
+ });
1545
+ Object.defineProperty(Rive.prototype, "isPlaying", {
1546
+ /**
1547
+ * @returns true if any animation is playing
1548
+ */
1549
+ get: function () {
1550
+ return this.animator.isPlaying;
1551
+ },
1552
+ enumerable: false,
1553
+ configurable: true
1554
+ });
1555
+ Object.defineProperty(Rive.prototype, "isPaused", {
1556
+ /**
1557
+ * @returns true if all instanced animations are paused
1558
+ */
1559
+ get: function () {
1560
+ return this.animator.isPaused;
1561
+ },
1562
+ enumerable: false,
1563
+ configurable: true
1564
+ });
1565
+ Object.defineProperty(Rive.prototype, "isStopped", {
1566
+ /**
1567
+ * @returns true if no animations are playing or paused
1568
+ */
1569
+ get: function () {
1570
+ return this.animator.isStopped;
1571
+ },
1572
+ enumerable: false,
1573
+ configurable: true
1574
+ });
1575
+ Object.defineProperty(Rive.prototype, "bounds", {
1576
+ /**
1577
+ * @returns the bounds of the current artboard, or undefined if the artboard
1578
+ * isn't loaded yet.
1579
+ */
1580
+ get: function () {
1581
+ return this.artboard ? this.artboard.bounds : undefined;
1582
+ },
1583
+ enumerable: false,
1584
+ configurable: true
1585
+ });
1586
+ /**
1587
+ * Subscribe to Rive-generated events
1588
+ * @param type the type of event to subscribe to
1589
+ * @param callback callback to fire when the event occurs
1590
+ */
1591
+ Rive.prototype.on = function (type, callback) {
1592
+ this.eventManager.add({
1593
+ type: type,
1594
+ callback: callback,
1595
+ });
1596
+ };
1597
+ /**
1598
+ * Unsubscribes from a Rive-generated event
1599
+ * @param callback the callback to unsubscribe from
1600
+ */
1601
+ Rive.prototype.unsubscribe = function (type, callback) {
1602
+ this.eventManager.remove({
1603
+ type: type,
1604
+ callback: callback,
1605
+ });
1606
+ };
1607
+ /**
1608
+ * Unsubscribes all listeners from an event type, or everything if no type is
1609
+ * given
1610
+ * @param type the type of event to unsubscribe from, or all types if
1611
+ * undefined
1612
+ */
1613
+ Rive.prototype.unsubscribeAll = function (type) {
1614
+ this.eventManager.removeAll(type);
1615
+ };
1616
+ /**
1617
+ * Stops the rendering loop; this is different from pausing in that it doesn't
1618
+ * change the state of any animation. It stops rendering from occurring. This
1619
+ * is designed for situations such as when Rive isn't visible.
1620
+ *
1621
+ * The only way to start rendering again is to call `startRendering`.
1622
+ * Animations that are marked as playing will start from the position that
1623
+ * they would have been at if rendering had not been stopped.
1624
+ */
1625
+ Rive.prototype.stopRendering = function () {
1626
+ if (this.loaded && this.frameRequestId) {
1627
+ cancelAnimationFrame(this.frameRequestId);
1628
+ this.frameRequestId = null;
1629
+ }
1630
+ };
1631
+ /**
1632
+ * Starts the rendering loop if it has been previously stopped. If the
1633
+ * renderer is already active, then this will have zero effect.
1634
+ */
1635
+ Rive.prototype.startRendering = function () {
1636
+ if (this.loaded && !this.frameRequestId) {
1637
+ this.frameRequestId = requestAnimationFrame(this.draw.bind(this));
1638
+ }
1639
+ };
1640
+ Object.defineProperty(Rive.prototype, "contents", {
1641
+ /**
1642
+ * Returns the contents of a Rive file: the artboards, animations, and state machines
1643
+ */
1644
+ get: function () {
1645
+ if (!this.loaded) {
1646
+ return undefined;
1647
+ }
1648
+ var riveContents = {
1649
+ artboards: [],
1650
+ };
1651
+ for (var i = 0; i < this.file.artboardCount(); i++) {
1652
+ var artboard = this.file.artboardByIndex(i);
1653
+ var artboardContents = {
1654
+ name: artboard.name,
1655
+ animations: [],
1656
+ stateMachines: [],
1657
+ };
1658
+ for (var j = 0; j < artboard.animationCount(); j++) {
1659
+ var animation = artboard.animationByIndex(j);
1660
+ artboardContents.animations.push(animation.name);
1661
+ }
1662
+ for (var k = 0; k < artboard.stateMachineCount(); k++) {
1663
+ var stateMachine = artboard.stateMachineByIndex(k);
1664
+ var name_1 = stateMachine.name;
1665
+ var instance = new this.runtime.StateMachineInstance(stateMachine);
1666
+ var inputContents = [];
1667
+ for (var l = 0; l < instance.inputCount(); l++) {
1668
+ var input = instance.input(l);
1669
+ inputContents.push({ name: input.name, type: input.type });
1670
+ }
1671
+ artboardContents.stateMachines.push({ name: name_1, inputs: inputContents });
1672
+ }
1673
+ riveContents.artboards.push(artboardContents);
1674
+ }
1675
+ return riveContents;
1676
+ },
1677
+ enumerable: false,
1678
+ configurable: true
1679
+ });
1680
+ // Error message for missing source or buffer
1681
+ Rive.missingErrorMessage = 'Rive source file or data buffer required';
1682
+ return Rive;
1683
+ }());
1684
+
1685
+ // Loads Rive data from a URI via fetch.
1686
+ var loadRiveFile = function (src) { return __awaiter(void 0, void 0, void 0, function () {
1687
+ var req, res, buffer;
1688
+ return __generator(this, function (_a) {
1689
+ switch (_a.label) {
1690
+ case 0:
1691
+ req = new Request(src);
1692
+ return [4 /*yield*/, fetch(req)];
1693
+ case 1:
1694
+ res = _a.sent();
1695
+ return [4 /*yield*/, res.arrayBuffer()];
1696
+ case 2:
1697
+ buffer = _a.sent();
1698
+ return [2 /*return*/, buffer];
1699
+ }
1700
+ });
1701
+ }); };
1702
+ // #endregion
1703
+ // #region utility functions
1704
+ /*
1705
+ * Utility function to ensure an object is a string array
1706
+ */
1707
+ var mapToStringArray = function (obj) {
1708
+ if (typeof obj === 'string') {
1709
+ return [obj];
1710
+ }
1711
+ else if (obj instanceof Array) {
1712
+ return obj;
1713
+ }
1714
+ // If obj is undefined, return empty array
1715
+ return [];
1716
+ };
1717
+ // #endregion
1718
+ // #region testing utilities
1719
+ // Exports to only be used for tests
1720
+ var Testing = {
1721
+ EventManager: EventManager,
1722
+ TaskQueueManager: TaskQueueManager,
1723
+ };
1724
+ // #endregion
1725
+
1726
+ })();
1727
+
1728
+ /******/ return __webpack_exports__;
1729
+ /******/ })()
1730
+ ;
1731
+ });
1732
+ //# sourceMappingURL=rive.js.map