untitled-pixi-live2d-engine 1.2.0 → 1.2.1

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.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("pixi.js"),require("@pixi/sound")):"function"==typeof define&&define.amd?define(["exports","pixi.js","@pixi/sound"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).PIXI=t.PIXI||{},t.PIXI.live2d=t.PIXI.live2d||{}),t.PIXI,t.PIXI)}(this,function(t,e,i){"use strict";var r=Object.defineProperty,s=Object.defineProperties,a=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,u=Math.pow,h=(t,e,i)=>e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,d=(t,e)=>{for(var i in e||(e={}))o.call(e,i)&&h(t,i,e[i]);if(n)for(var i of n(e))l.call(e,i)&&h(t,i,e[i]);return t},g=(t,e,i)=>h(t,"symbol"!=typeof e?e+"":e,i),c=(t,e,i)=>new Promise((r,s)=>{var a=t=>{try{o(i.next(t))}catch(e){s(e)}},n=t=>{try{o(i.throw(t))}catch(e){s(e)}},o=t=>t.done?r(t.value):Promise.resolve(t.value).then(a,n);o((i=i.apply(t,e)).next())});const m=class t{constructor(t=0){t<1?(this._ptr=[],this._capacity=0,this._size=0):(this._ptr=new Array(t),this._capacity=t,this._size=0)}at(t){return this._ptr[t]}set(t,e){this._ptr[t]=e}get(t=0){const e=new Array;for(let i=t;i<this._size;i++)e.push(this._ptr[i]);return e}pushBack(e){this._size>=this._capacity&&this.prepareCapacity(0==this._capacity?t.DefaultSize:2*this._capacity),this._ptr[this._size++]=e}clear(){this._ptr.length=0,this._size=0}getSize(){return this._size}assign(t,e){this._size<t&&this.prepareCapacity(t);for(let i=0;i<t;i++)this._ptr[i]=e;this._size=t}resize(t,e=null){this.updateSize(t,e,!0)}updateSize(t,e=null,i=!0){if(this._size<t)if(this.prepareCapacity(t),i)for(let r=this._size;r<t;r++)this._ptr[r]="function"==typeof e?JSON.parse(JSON.stringify(new e)):e;else for(let r=this._size;r<t;r++)this._ptr[r]=e;else{const e=this._size-t;this._ptr.splice(this._size-e,e)}this._size=t}insert(t,e,i){let r=t._index;const s=e._index,a=i._index,n=a-s;this.prepareCapacity(this._size+n);const o=this._size-r;if(o>0)for(let l=0;l<o;l++)this._ptr.splice(r+l,0,null);for(let l=s;l<a;l++,r++)this._ptr[r]=e._vector._ptr[l];this._size=this._size+n}remove(t){return!(t<0||this._size<=t)&&(this._ptr.splice(t,1),--this._size,!0)}erase(t){const e=t._index;if(e<0||this._size<=e)return t;this._ptr.splice(e,1),--this._size;return new _(this,e)}prepareCapacity(t){t>this._capacity&&(0==this._capacity?(this._ptr=new Array(t),this._capacity=t):(this._ptr.length=t,this._capacity=t))}begin(){return 0==this._size?this.end():new _(this,0)}end(){return new _(this,this._size)}getOffset(e){const i=new t;return i._ptr=this.get(e),i._size=this.get(e).length,i._capacity=this.get(e).length,i}};m.DefaultSize=10;let p=m,_=class t{constructor(t,e){this._vector=null!=t?t:null,this._index=null!=e?e:0}set(t){return this._index=t._index,this._vector=t._vector,this}preIncrement(){return++this._index,this}preDecrement(){return--this._index,this}increment(){return new t(this._vector,this._index++)}decrement(){return new t(this._vector,this._index--)}ptr(){return this._vector._ptr[this._index]}substitution(t){return this._index=t._index,this._vector=t._vector,this}notEqual(t){return this._index!=t._index||this._vector!=t._vector}};var f,y,x,C,M,S,v;(y=f||(f={})).csmVector=p,y.iterator=_;class b{append(t,e){return this.s+=void 0!==e?t.substr(0,e):t,this}expansion(t,e){for(let i=0;i<t;i++)this.append(e);return this}getBytes(){return encodeURIComponent(this.s).replace(/%../g,"x").length}getLength(){return this.s.length}isLess(t){return this.s<t.s}isGreat(t){return this.s>t.s}isEqual(t){return this.s==t}isEmpty(){return 0==this.s.length}constructor(t){this.s=t}}(t=>{t.csmString=b})(x||(x={}));class P{static createIdInternal(t){return new P(t)}getString(){return this._id}isEqual(t){return"string"==typeof t?this._id.isEqual(t):t instanceof b?this._id.isEqual(t.s):t instanceof P&&this._id.isEqual(t._id.s)}isNotEqual(t){return"string"==typeof t?!this._id.isEqual(t):t instanceof b?!this._id.isEqual(t.s):t instanceof P&&!this._id.isEqual(t._id.s)}constructor(t){this._id="string"!=typeof t?t:new b(t)}}(t=>{t.CubismId=P})(C||(C={}));class B{constructor(){this._ids=new p}release(){for(let t=0;t<this._ids.getSize();++t)this._ids.set(t,void 0);this._ids=null}registerIds(t){for(let e=0;e<t.length;e++)this.registerId(t[e])}registerId(t){let e=null;return"string"!=typeof t?this.registerId(t.s):(null!=(e=this.findId(t))||(e=P.createIdInternal(t),this._ids.pushBack(e)),e)}getId(t){return this.registerId(t)}isExist(t){return"string"==typeof t?null!=this.findId(t):this.isExist(t.s)}findId(t){for(let e=0;e<this._ids.getSize();++e)if(this._ids.at(e).getString().isEqual(t))return this._ids.at(e);return null}}(t=>{t.CubismIdManager=B})(M||(M={}));class w{constructor(){this._tr=new Float32Array(16),this.loadIdentity()}static multiply(t,e,i){const r=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);for(let s=0;s<4;++s)for(let i=0;i<4;++i)for(let a=0;a<4;++a)r[i+4*s]+=t[a+4*s]*e[i+4*a];for(let s=0;s<16;++s)i[s]=r[s]}loadIdentity(){const t=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);this.setMatrix(t)}setMatrix(t){for(let e=0;e<16;++e)this._tr[e]=t[e]}getArray(){return this._tr}getScaleX(){return this._tr[0]}getScaleY(){return this._tr[5]}getTranslateX(){return this._tr[12]}getTranslateY(){return this._tr[13]}transformX(t){return this._tr[0]*t+this._tr[12]}transformY(t){return this._tr[5]*t+this._tr[13]}invertTransformX(t){return(t-this._tr[12])/this._tr[0]}invertTransformY(t){return(t-this._tr[13])/this._tr[5]}translateRelative(t,e){const i=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,t,e,0,1]);w.multiply(i,this._tr,this._tr)}translate(t,e){this._tr[12]=t,this._tr[13]=e}translateX(t){this._tr[12]=t}translateY(t){this._tr[13]=t}scaleRelative(t,e){const i=new Float32Array([t,0,0,0,0,e,0,0,0,0,1,0,0,0,0,1]);w.multiply(i,this._tr,this._tr)}scale(t,e){this._tr[0]=t,this._tr[5]=e}multiplyByMatrix(t){w.multiply(t.getArray(),this._tr,this._tr)}clone(){const t=new w;for(let e=0;e<this._tr.length;e++)t._tr[e]=this._tr[e];return t}}(t=>{t.CubismMatrix44=w})(S||(S={}));class F{constructor(t,e,i,r){this.x=t,this.y=e,this.width=i,this.height=r}getCenterX(){return this.x+.5*this.width}getCenterY(){return this.y+.5*this.height}getRight(){return this.x+this.width}getBottom(){return this.y+this.height}setRect(t){this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height}expand(t,e){this.x-=t,this.y-=e,this.width+=2*t,this.height+=2*e}}(t=>{t.csmRect=F})(v||(v={}));class I{static create(){return null}static delete(t){}initialize(t){this._model=t}drawModel(){null!=this.getModel()&&(this.saveProfile(),this.doDrawModel(),this.restoreProfile())}setMvpMatrix(t){this._mvpMatrix4x4.setMatrix(t.getArray())}getMvpMatrix(){return this._mvpMatrix4x4}setModelColor(t,e,i,r){t<0?t=0:t>1&&(t=1),e<0?e=0:e>1&&(e=1),i<0?i=0:i>1&&(i=1),r<0?r=0:r>1&&(r=1),this._modelColor.r=t,this._modelColor.g=e,this._modelColor.b=i,this._modelColor.a=r}getModelColor(){return JSON.parse(JSON.stringify(this._modelColor))}getModelColorWithOpacity(t){const e=this.getModelColor();return e.a*=t,this.isPremultipliedAlpha()&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}setIsPremultipliedAlpha(t){this._isPremultipliedAlpha=t}isPremultipliedAlpha(){return this._isPremultipliedAlpha}setIsCulling(t){this._isCulling=t}isCulling(){return this._isCulling}setAnisotropy(t){this._anisotropy=t}getAnisotropy(){return this._anisotropy}getModel(){return this._model}useHighPrecisionMask(t){this._useHighPrecisionMask=t}isUsingHighPrecisionMask(){return this._useHighPrecisionMask}constructor(){this._isCulling=!1,this._isPremultipliedAlpha=!1,this._anisotropy=0,this._model=null,this._modelColor=new L,this._useHighPrecisionMask=!1,this._mvpMatrix4x4=new w,this._mvpMatrix4x4.loadIdentity()}}var E,V=(t=>(t[t.CubismBlendMode_Normal=0]="CubismBlendMode_Normal",t[t.CubismBlendMode_Additive=1]="CubismBlendMode_Additive",t[t.CubismBlendMode_Multiplicative=2]="CubismBlendMode_Multiplicative",t))(V||{});class L{constructor(t=1,e=1,i=1,r=1){this.r=t,this.g=e,this.b=i,this.a=r}}class R{constructor(t,e){this._clippingIdList=t,this._clippingIdCount=e,this._allClippedDrawRect=new F,this._layoutBounds=new F,this._clippedDrawableIndexList=[],this._matrixForMask=new w,this._matrixForDraw=new w,this._bufferIndex=0}release(){null!=this._layoutBounds&&(this._layoutBounds=null),null!=this._allClippedDrawRect&&(this._allClippedDrawRect=null),null!=this._clippedDrawableIndexList&&(this._clippedDrawableIndexList=null)}addClippedDrawable(t){this._clippedDrawableIndexList.push(t)}}(t=>{t.CubismBlendMode=V,t.CubismRenderer=I,t.CubismTextureColor=L})(E||(E={}));const T=Object.freeze(Object.defineProperty({__proto__:null,CSM_LOG_LEVEL:0,CSM_LOG_LEVEL_DEBUG:1,CSM_LOG_LEVEL_ERROR:4,CSM_LOG_LEVEL_INFO:2,CSM_LOG_LEVEL_OFF:5,CSM_LOG_LEVEL_VERBOSE:0,CSM_LOG_LEVEL_WARNING:3},Symbol.toStringTag,{value:"Module"})),D=(t,e,i)=>{((t,e,i)=>{z.print(t,"[CSM]"+e,i)})(t,e+"\n",i)},A=t=>{console.assert(t)};let O,k,N,U;O=(t,...e)=>{D(mt.LogLevel_Debug,"[D]"+t,e)},k=(t,...e)=>{D(mt.LogLevel_Info,"[I]"+t,e)},N=(t,...e)=>{D(mt.LogLevel_Warning,"[W]"+t,e)},U=(t,...e)=>{D(mt.LogLevel_Error,"[E]"+t,e)};class z{static print(t,e,i){if(t<ct.getLoggingLevel())return;const r=ct.coreLogFunction;if(!r)return;r(e.replace(/\{(\d+)\}/g,(t,e)=>i[e]))}static dumpBytes(t,e,i){for(let r=0;r<i;r++)r%16==0&&r>0?this.print(t,"\n"):r%8==0&&r>0&&this.print(t," "),this.print(t,"{0} ",[255&e[r]]);this.print(t,"\n")}constructor(){}}var j;(t=>{t.CubismDebug=z})(j||(j={}));class G{constructor(t,e){this.first=null==t?null:t,this.second=null==e?null:e}}const X=class t{constructor(t){null!=t?t<1?(this._keyValues=[],this._dummyValue=null,this._size=0):(this._keyValues=new Array(t),this._size=t):(this._keyValues=[],this._dummyValue=null,this._size=0)}release(){this.clear()}appendKey(t){let e=-1;for(let i=0;i<this._size;i++)if(this._keyValues[i].first==t){e=i;break}-1==e?(this.prepareCapacity(this._size+1,!1),this._keyValues[this._size]=new G(t),this._size+=1):N("The key `{0}` is already append.",t)}getValue(t){let e=-1;for(let i=0;i<this._size;i++)if(this._keyValues[i].first==t){e=i;break}return e>=0?this._keyValues[e].second:(this.appendKey(t),this._keyValues[this._size-1].second)}setValue(t,e){let i=-1;for(let r=0;r<this._size;r++)if(this._keyValues[r].first==t){i=r;break}i>=0?this._keyValues[i].second=e:(this.appendKey(t),this._keyValues[this._size-1].second=e)}isExist(t){for(let e=0;e<this._size;e++)if(this._keyValues[e].first==t)return!0;return!1}clear(){this._keyValues=void 0,this._keyValues=null,this._keyValues=[],this._size=0}getSize(){return this._size}prepareCapacity(e,i){e>this._keyValues.length&&(0==this._keyValues.length?(!i&&e<t.DefaultSize&&(e=t.DefaultSize),this._keyValues.length=e):(!i&&e<2*this._keyValues.length&&(e=2*this._keyValues.length),this._keyValues.length=e))}begin(){return new q(this,0)}end(){return new q(this,this._size)}erase(t){const e=t._index;if(e<0||this._size<=e)return t;this._keyValues.splice(e,1),--this._size;return new q(this,e)}dumpAsInt(){for(let t=0;t<this._size;t++)O("{0} ,",this._keyValues[t]),O("\n")}};X.DefaultSize=10;let H=X;class q{constructor(t,e){this._map=null!=t?t:new H,this._index=null!=e?e:0}set(t){return this._index=t._index,this._map=t._map,this}preIncrement(){return++this._index,this}preDecrement(){return--this._index,this}increment(){return new q(this._map,this._index++)}decrement(){const t=new q(this._map,this._index);return this._map=t._map,this._index=t._index,this}ptr(){return this._map._keyValues[this._index]}notEqual(t){return this._index!=t._index||this._map!=t._map}}var Y;(t=>{t.csmMap=H,t.csmPair=G,t.iterator=q})(Y||(Y={}));class W{static parseJsonObject(t,e){return Object.keys(t).forEach(i=>{if("boolean"==typeof t[i]){const r=Boolean(t[i]);e.put(i,new Q(r))}else if("string"==typeof t[i]){const r=String(t[i]);e.put(i,new tt(r))}else if("number"==typeof t[i]){const r=Number(t[i]);e.put(i,new K(r))}else t[i]instanceof Array?e.put(i,W.parseJsonArray(t[i])):t[i]instanceof Object?e.put(i,W.parseJsonObject(t[i],new st)):null==t[i]?e.put(i,new it):e.put(i,t[i])}),e}static parseJsonArray(t){const e=new rt;return Object.keys(t).forEach(i=>{if("number"==typeof Number(i))if("boolean"==typeof t[i]){const r=Boolean(t[i]);e.add(new Q(r))}else if("string"==typeof t[i]){const r=String(t[i]);e.add(new tt(r))}else if("number"==typeof t[i]){const r=Number(t[i]);e.add(new K(r))}else t[i]instanceof Array?e.add(this.parseJsonArray(t[i])):t[i]instanceof Object?e.add(this.parseJsonObject(t[i],new st)):null==t[i]?e.add(new it):e.add(t[i]);else if(t[i]instanceof Array)e.add(this.parseJsonArray(t[i]));else if(t[i]instanceof Object)e.add(this.parseJsonObject(t[i],new st));else if(null==t[i])e.add(new it);else{const r=Array(t[i]);for(let t=0;t<r.length;t++)e.add(r[t])}}),e}}const J="Error: type mismatch";let $=class t{constructor(){}getRawString(t,e){return this.getString(t,e)}toInt(t=0){return t}toFloat(t=0){return t}toBoolean(t=!1){return t}getSize(){return 0}getArray(t=null){return t}getVector(t=new p){return t}getMap(t){return t}getValueByIndex(e){return t.errorValue.setErrorNotForClientCall(J)}getValueByString(e){return t.nullValue.setErrorNotForClientCall(J)}getKeys(){return t.dummyKeys}isError(){return!1}isNull(){return!1}isBool(){return!1}isFloat(){return!1}isString(){return!1}isArray(){return!1}isMap(){return!1}equals(t){return!1}isStatic(){return!1}setErrorNotForClientCall(t){return et.errorValue}static staticInitializeNotForClientCall(){Q.trueValue=new Q(!0),Q.falseValue=new Q(!1),t.errorValue=new et("ERROR",!0),t.nullValue=new it,t.dummyKeys=new p}static staticReleaseNotForClientCall(){Q.trueValue=null,Q.falseValue=null,t.errorValue=null,t.nullValue=null,t.dummyKeys=null}};class Z{constructor(t,e){this._parseCallback=W.parseJsonObject,this._error=null,this._lineCount=0,this._root=null,null!=t&&this.parseBytes(t,e,this._parseCallback)}static create(t,e){const i=new Z;return i.parseBytes(t,e,i._parseCallback)?i:(Z.delete(i),null)}static delete(t){}getRoot(){return this._root}static arrayBufferToString(t){const e=new Uint8Array(t);let i="";for(let r=0,s=e.length;r<s;++r)i+="%"+this.pad(e[r].toString(16));return i=decodeURIComponent(i),i}static pad(t){return t.length<2?"0"+t:t}parseBytes(t,e,i){const r=new Array(1),s=Z.arrayBufferToString(t);if(this._root=null==i?this.parseValue(s,e,0,r):i(JSON.parse(s),new st),this._error){let t="\0";return t="Json parse error : @line "+(this._lineCount+1)+"\n",this._root=new tt(t),k("{0}",this._root.getRawString()),!1}return null!=this._root||(this._root=new et(new b(this._error),!1),!1)}getParseError(){return this._error}checkEndOfFile(){return this._root.getArray()[1].equals("EOF")}parseValue(t,e,i,r){if(this._error)return null;let s,a=null,n=i;for(;n<e;n++){switch(t[n]){case"-":case".":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{const e=new Array(1);return s=nt(t.slice(n),e),r[0]=t.indexOf(e[0]),new K(s)}case'"':return new tt(this.parseString(t,e,n+1,r));case"[":return a=this.parseArray(t,e,n+1,r),a;case"{":return a=this.parseObject(t,e,n+1,r),a;case"n":return n+3<e?(a=new it,r[0]=n+4):this._error="parse null",a;case"t":return n+3<e?(a=Q.trueValue,r[0]=n+4):this._error="parse true",a;case"f":return n+4<e?(a=Q.falseValue,r[0]=n+5):this._error="illegal ',' position",a;case",":return this._error="illegal ',' position",null;case"]":return r[0]=n,null;case"\n":this._lineCount++}}return this._error="illegal end of value",null}parseString(t,e,i,r){if(this._error)return null;if(!t)return this._error="string is null",null;let s,a,n=i;const o=new b("");let l=i;for(;n<e;n++)switch(s=t[n],s){case'"':return r[0]=n+1,o.append(t.slice(l),n-l),o.s;case"//":if(n++,n-1>l&&o.append(t.slice(l),n-l),l=n+1,n<e)switch(a=t[n],a){case"\\":o.expansion(1,"\\");break;case'"':o.expansion(1,'"');break;case"/":o.expansion(1,"/");break;case"b":o.expansion(1,"\b");break;case"f":o.expansion(1,"\f");break;case"n":o.expansion(1,"\n");break;case"r":o.expansion(1,"\r");break;case"t":o.expansion(1,"\t");break;case"u":this._error="parse string/unicord escape not supported"}else this._error="parse string/escape error"}return this._error="parse string/illegal end",null}parseObject(t,e,i,r){if(this._error)return null;if(!t)return this._error="buffer is null",null;const s=new st;let a="",n=i,o="";const l=Array(1);let u=!1;for(;n<e;n++){t:for(;n<e;n++)switch(o=t[n],o){case'"':if(a=this.parseString(t,e,n+1,l),this._error)return null;n=l[0],u=!0;break t;case"}":return r[0]=n+1,s;case":":this._error="illegal ':' position";break;case"\n":this._lineCount++}if(!u)return this._error="key not found",null;u=!1;t:for(;n<e;n++)switch(o=t[n],o){case":":u=!0,n++;break t;case"}":this._error="illegal '}' position";break;case"\n":this._lineCount++}if(!u)return this._error="':' not found",null;const i=this.parseValue(t,e,n,l);if(this._error)return null;n=l[0],s.put(a,i);t:for(;n<e;n++)switch(o=t[n],o){case",":break t;case"}":return r[0]=n+1,s;case"\n":this._lineCount++}}return this._error="illegal end of perseObject",null}parseArray(t,e,i,r){if(this._error)return null;if(!t)return this._error="buffer is null",null;let s,a=new rt,n=i;const o=new Array(1);for(;n<e;n++){const i=this.parseValue(t,e,n,o);if(this._error)return null;n=o[0],i&&a.add(i);t:for(;n<e;n++)switch(s=t[n],s){case",":break t;case"]":return r[0]=n+1,a;case"\n":++this._lineCount}}return a=void 0,this._error="illegal end of parseObject",null}}class K extends ${constructor(t){super(),this._value=t}isFloat(){return!0}getString(t,e){return this._value=parseFloat("\0"),this._stringBuffer="\0",this._stringBuffer}toInt(t=0){return parseInt(this._value.toString())}toFloat(t=0){return this._value}equals(t){return"number"==typeof t&&(!Math.round(t)&&t==this._value)}}class Q extends ${isBool(){return!0}toBoolean(t=!1){return this._boolValue}getString(t,e){return this._stringBuffer=this._boolValue?"true":"false",this._stringBuffer}equals(t){return"boolean"==typeof t&&t==this._boolValue}isStatic(){return!0}constructor(t){super(),this._boolValue=t}}class tt extends ${constructor(t){super(),"string"==typeof t&&(this._stringBuffer=t),t instanceof b&&(this._stringBuffer=t.s)}isString(){return!0}getString(t,e){return this._stringBuffer}equals(t){return"string"==typeof t?this._stringBuffer==t:t instanceof b&&this._stringBuffer==t.s}}class et extends tt{isStatic(){return this._isStatic}setErrorNotForClientCall(t){return this._stringBuffer=t,this}constructor(t,e){super(t),this._isStatic=e}isError(){return!0}}class it extends ${isNull(){return!0}getString(t,e){return this._stringBuffer}isStatic(){return!0}setErrorNotForClientCall(t){return this._stringBuffer=t,et.nullValue}constructor(){super(),this._stringBuffer="NullValue"}}class rt extends ${constructor(){super(),this._array=new p}release(){for(let t=this._array.begin();t.notEqual(this._array.end());t.preIncrement()){let e=t.ptr();e&&!e.isStatic()&&(e=void 0,e=null)}}isArray(){return!0}getValueByIndex(t){if(t<0||this._array.getSize()<=t)return $.errorValue.setErrorNotForClientCall("Error: index out of bounds");const e=this._array.at(t);return null==e?$.nullValue:e}getValueByString(t){return $.errorValue.setErrorNotForClientCall(J)}getString(t,e){const i=e+"[\n";for(let r=this._array.begin();r.notEqual(this._array.end());r.increment()){const t=r.ptr();this._stringBuffer+=e+""+t.getString(e+" ")+"\n"}return this._stringBuffer=i+e+"]\n",this._stringBuffer}add(t){this._array.pushBack(t)}getVector(t=null){return this._array}getSize(){return this._array.getSize()}}class st extends ${constructor(){super(),this._map=new H}release(){const t=this._map.begin();for(;t.notEqual(this._map.end());){let e=t.ptr().second;e&&!e.isStatic()&&(e=void 0,e=null),t.preIncrement()}}isMap(){return!0}getValueByString(t){if(t instanceof b){const e=this._map.getValue(t.s);return null==e?$.nullValue:e}for(let e=this._map.begin();e.notEqual(this._map.end());e.preIncrement())if(e.ptr().first==t)return null==e.ptr().second?$.nullValue:e.ptr().second;return $.nullValue}getValueByIndex(t){return $.errorValue.setErrorNotForClientCall(J)}getString(t,e){this._stringBuffer=e+"{\n";const i=this._map.begin();for(;i.notEqual(this._map.end());){const t=i.ptr().first,r=i.ptr().second;this._stringBuffer+=e+" "+t+" : "+r.getString(e+" ")+" \n",i.preIncrement()}return this._stringBuffer+=e+"}\n",this._stringBuffer}getMap(t){return this._map}put(t,e){this._map.setValue(t,e)}getKeys(){if(!this._keys){this._keys=new p;const t=this._map.begin();for(;t.notEqual(this._map.end());){const e=t.ptr().first;this._keys.pushBack(e),t.preIncrement()}}return this._keys}getSize(){return this._keys.getSize()}}var at;function nt(t,e){let i=0;for(let s=1;;s++){const e=t.slice(s-1,s);if("e"==e||"-"==e||"E"==e)continue;const r=t.substring(0,s),a=Number(r);if(isNaN(a))break;i=s}let r=parseFloat(t);return isNaN(r)&&(r=NaN),e[0]=t.slice(i),r}(t=>{t.CubismJson=Z,t.JsonArray=rt,t.JsonBoolean=Q,t.JsonError=et,t.JsonFloat=K,t.JsonMap=st,t.JsonNullvalue=it,t.JsonString=tt,t.Value=$})(at||(at={}));let ot=!1,lt=!1,ut=null,ht=null;const dt=Object.freeze({vertexOffset:0,vertexStep:2});function gt(t){t&&(t=void 0)}class ct{static startUp(t=null){if(ot)return k("CubismFramework.startUp() is already done."),ot;if(ut=t,null!=ut&&Live2DCubismCore.Logging.csmSetLogFunction(ut.logFunction),ot=!0,ot){const t=Live2DCubismCore.Version.csmGetVersion(),e=(16711680&t)>>16,i=65535&t,r=t;k("Live2D Cubism Core version: {0}.{1}.{2} ({3})",("00"+((4278190080&t)>>24)).slice(-2),("00"+e).slice(-2),("0000"+i).slice(-4),r)}return k("CubismFramework.startUp() is complete."),ot}static cleanUp(){ot=!1,lt=!1,ut=null,ht=null}static initialize(t=0){A(ot),ot?lt?N("CubismFramework.initialize() skipped, already initialized."):($.staticInitializeNotForClientCall(),ht=new B,Live2DCubismCore.Memory.initializeAmountOfMemory(t),lt=!0,k("CubismFramework.initialize() is complete.")):N("CubismFramework is not started.")}static dispose(){A(ot),ot?lt?($.staticReleaseNotForClientCall(),ht.release(),ht=null,I.staticRelease(),lt=!1,k("CubismFramework.dispose() is complete.")):N("CubismFramework.dispose() skipped, not initialized."):N("CubismFramework is not started.")}static isStarted(){return ot}static isInitialized(){return lt}static coreLogFunction(t){Live2DCubismCore.Logging.csmGetLogFunction()&&Live2DCubismCore.Logging.csmGetLogFunction()(t)}static getLoggingLevel(){return null!=ut?ut.loggingLevel:5}static getIdManager(){return ht}constructor(){}}var mt=(t=>(t[t.LogLevel_Verbose=0]="LogLevel_Verbose",t[t.LogLevel_Debug=1]="LogLevel_Debug",t[t.LogLevel_Info=2]="LogLevel_Info",t[t.LogLevel_Warning=3]="LogLevel_Warning",t[t.LogLevel_Error=4]="LogLevel_Error",t[t.LogLevel_Off=5]="LogLevel_Off",t))(mt||{});t.Live2DCubismFramework=void 0,(t=>{t.Constant=dt,t.csmDelete=gt,t.CubismFramework=ct})(t.Live2DCubismFramework||(t.Live2DCubismFramework={}));const pt={LOG_LEVEL_VERBOSE:0,LOG_LEVEL_WARNING:1,LOG_LEVEL_ERROR:2,LOG_LEVEL_NONE:999,logLevel:1,sound:!0,fftSize:512,motionSync:!0,motionFadingDuration:500,idleMotionFadingDuration:2e3,expressionFadingDuration:500,preserveExpressionOnMotion:!0,cubism:T},_t={log(t,...e){pt.logLevel<=pt.LOG_LEVEL_VERBOSE&&console.log(`[${t}]`,...e)},warn(t,...e){pt.logLevel<=pt.LOG_LEVEL_WARNING&&console.warn(`[${t}]`,...e)},error(t,...e){pt.logLevel<=pt.LOG_LEVEL_ERROR&&console.error(`[${t}]`,...e)}};function ft(t,e,i){return t<e?e:t>i?i:t}function yt(t){return 1024*t*1024}function xt(t,e,i,r,s){const a=e[r];null!==a&&typeof a===t&&(i[s]=a)}function Ct(t,e,i,r,s){const a=e[r];Array.isArray(a)&&(i[s]=a.filter(e=>null!==e&&typeof e===t))}function Mt(t,e){e.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i))})})}function St(t){let e=t.lastIndexOf("/");return-1!=e&&(t=t.slice(0,e)),e=t.lastIndexOf("/"),-1!==e&&(t=t.slice(e+1)),t}function vt(t,e){const i=t.indexOf(e);-1!==i&&t.splice(i,1)}const bt=/^[a-zA-Z][a-zA-Z0-9+.-]*:/;function Pt(t,e){if(!e)return t;if(bt.test(e))return e;if(e.startsWith("/"))return bt.test(t)?new URL(e,t).toString():e;if(bt.test(t))return new URL(e,t).toString();const i="http://example.com",r=t.startsWith("/")?i+t:`${i}/${t}`,s=new URL(e,r);let a=s.pathname+s.search+s.hash;return!t.startsWith("/")&&a.startsWith("/")&&(a=a.slice(1)),a}class Bt extends e.EventEmitter{constructor(t,e){super(),g(this,"expressionDataType","json"),g(this,"tag"),g(this,"settings"),g(this,"expressions",[]),g(this,"defaultExpression"),g(this,"currentExpression"),g(this,"reserveExpressionIndex",-1),g(this,"destroyed",!1),this.settings=t,this.tag=`ExpressionManager(${t.name})`}init(){this.defaultExpression=this.createDefaultExpression(),this.currentExpression=this.defaultExpression,this.stopAllExpressions()}createDefaultExpression(){return this.createExpression({},void 0)}loadExpression(t){return c(this,null,function*(){if(!this.definitions[t])return void _t.warn(this.tag,`Undefined expression at [${t}]`);if(null===this.expressions[t])return void _t.warn(this.tag,`Cannot set expression at [${t}] because it's already failed in loading.`);if(this.expressions[t])return this.expressions[t];const e=yield this._loadExpression(t);return this.expressions[t]=e,e})}_loadExpression(t){throw new Error("Not implemented.")}setRandomExpression(){return c(this,null,function*(){if(this.definitions.length){const t=[];for(let e=0;e<this.definitions.length;e++)null!==this.expressions[e]&&this.expressions[e]!==this.currentExpression&&e!==this.reserveExpressionIndex&&t.push(e);if(t.length){const e=Math.floor(Math.random()*t.length);return this.setExpression(e)}}return!1})}resetExpression(){this._setExpression(this.defaultExpression)}restoreExpression(){this._setExpression(this.currentExpression)}setExpression(t){return c(this,null,function*(){if("number"!=typeof t&&(t=this.getExpressionIndex(t)),!(t>-1&&t<this.definitions.length))return!1;if(t===this.expressions.indexOf(this.currentExpression))return!1;this.reserveExpressionIndex=t;const e=yield this.loadExpression(t);return!(!e||this.reserveExpressionIndex!==t)&&(this.reserveExpressionIndex=-1,this.currentExpression=e,this._setExpression(e),!0)})}update(t,e){return!this.isFinished()&&this.updateParameters(t,e)}destroy(){this.destroyed=!0,this.emit("destroy");this.definitions=void 0,this.expressions=void 0}}const wt=40/7.5,Ft=1/150;class It{constructor(){g(this,"targetX",0),g(this,"targetY",0),g(this,"x",0),g(this,"y",0),g(this,"vx",0),g(this,"vy",0)}focus(t,e,i=!1){this.targetX=ft(t,-1,1),this.targetY=ft(e,-1,1),i&&(this.x=this.targetX,this.y=this.targetY)}update(t){const e=this.targetX-this.x,i=this.targetY-this.y;if(Math.abs(e)<.01&&Math.abs(i)<.01)return;const r=Math.sqrt(u(e,2)+u(i,2)),s=wt/(1e3/t);let a=s*(e/r)-this.vx,n=s*(i/r)-this.vy;const o=Math.sqrt(u(a,2)+u(n,2)),l=s*Ft*t;o>l&&(a*=l/o,n*=l/o),this.vx+=a,this.vy+=n;const h=Math.sqrt(u(this.vx,2)+u(this.vy,2)),d=.5*(Math.sqrt(u(l,2)+8*l*r)-l);h>d&&(this.vx*=d/h,this.vy*=d/h),this.x+=this.vx,this.y+=this.vy}}class Et{constructor(t){g(this,"json"),g(this,"name"),g(this,"url"),g(this,"pose"),g(this,"physics"),this.json=t,this.url=t.url,this.name=St(this.url)}normalizeName(){this.name&&"name"!==this.name.toLowerCase()||(this.name=St(this.url))}setModelName(...t){for(const e of t){const t="string"==typeof e?e.trim():"";if(t&&"name"!==t.toLowerCase())return void(this.name=t)}this.normalizeName()}getFileStem(t){if(!t)return;const e=t.split(/[/\\]/).filter(Boolean).pop();return null==e?void 0:e.replace(/\.[^.]+$/,"")}resolveURL(t){return Pt(this.url,t)}replaceFiles(t){this.moc=t(this.moc,"moc"),void 0!==this.pose&&(this.pose=t(this.pose,"pose")),void 0!==this.physics&&(this.physics=t(this.physics,"physics"));for(let e=0;e<this.textures.length;e++)this.textures[e]=t(this.textures[e],`textures[${e}]`)}getDefinedFiles(){const t=[];return this.replaceFiles(e=>(t.push(e),e)),t}validateFiles(t){const e=(e,i)=>{const r=this.resolveURL(e);if(!t.includes(r)){if(i)throw new Error(`File "${e}" is defined in settings, but doesn't exist in given files`);return!1}return!0};[this.moc,...this.textures].forEach(t=>e(t,!0));return this.getDefinedFiles().filter(t=>e(t,!1))}}var Vt=(t=>(t[t.NONE=0]="NONE",t[t.IDLE=1]="IDLE",t[t.NORMAL=2]="NORMAL",t[t.FORCE=3]="FORCE",t))(Vt||{});class Lt{constructor(){g(this,"tag"),g(this,"debug",!1),g(this,"currentPriority",0),g(this,"reservePriority",0),g(this,"currentGroup"),g(this,"currentIndex"),g(this,"reservedGroup"),g(this,"reservedIndex"),g(this,"reservedIdleGroup"),g(this,"reservedIdleIndex")}reserve(t,e,i){if(i<=0)return _t.log(this.tag,"Cannot start a motion with MotionPriority.NONE."),!1;if(t===this.currentGroup&&e===this.currentIndex)return _t.log(this.tag,"Motion is already playing.",this.dump(t,e)),!1;if(t===this.reservedGroup&&e===this.reservedIndex||t===this.reservedIdleGroup&&e===this.reservedIdleIndex)return _t.log(this.tag,"Motion is already reserved.",this.dump(t,e)),!1;if(1===i){if(0!==this.currentPriority)return _t.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(t,e)),!1;if(void 0!==this.reservedIdleGroup)return _t.log(this.tag,"Cannot start idle motion because another idle motion has reserved.",this.dump(t,e)),!1;this.setReservedIdle(t,e)}else{if(i<3){if(i<=this.currentPriority)return _t.log(this.tag,"Cannot start motion because another motion is playing as an equivalent or higher priority.",this.dump(t,e)),!1;if(i<=this.reservePriority)return _t.log(this.tag,"Cannot start motion because another motion has reserved as an equivalent or higher priority.",this.dump(t,e)),!1}this.setReserved(t,e,i)}return!0}start(t,e,i,r){if(1===r){if(this.setReservedIdle(void 0,void 0),0!==this.currentPriority)return _t.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(e,i)),!1}else{if(e!==this.reservedGroup||i!==this.reservedIndex)return _t.log(this.tag,"Cannot start motion because another motion has taken the place.",this.dump(e,i)),!1;this.setReserved(void 0,void 0,0)}return!!t&&(this.setCurrent(e,i,r),!0)}complete(){this.setCurrent(void 0,void 0,0)}setCurrent(t,e,i){this.currentPriority=i,this.currentGroup=t,this.currentIndex=e}setReserved(t,e,i){this.reservePriority=i,this.reservedGroup=t,this.reservedIndex=e}setReservedIdle(t,e){this.reservedIdleGroup=t,this.reservedIdleIndex=e}isActive(t,e){return t===this.currentGroup&&e===this.currentIndex||t===this.reservedGroup&&e===this.reservedIndex||t===this.reservedIdleGroup&&e===this.reservedIdleIndex}reset(){this.setCurrent(void 0,void 0,0),this.setReserved(void 0,void 0,0),this.setReservedIdle(void 0,void 0)}shouldRequestIdleMotion(){return void 0===this.currentGroup&&void 0===this.reservedIdleGroup}shouldOverrideExpression(){return!pt.preserveExpressionOnMotion&&this.currentPriority>1}dump(t,e){if(this.debug){return`\n<Requested> group = "${t}", index = ${e}\n`+["currentPriority","reservePriority","currentGroup","currentIndex","reservedGroup","reservedIndex","reservedIdleGroup","reservedIdleIndex"].map(t=>"["+t+"] "+this[t]).join("\n")}return""}}const Rt="SoundManager",Tt=.5;i.sound.disableAutoPause=!0;class Dt{static get volume(){return this._volume}static set volume(t){this._volume=(t>1?1:t<0?0:t)||0,this.audios.forEach(t=>t.volume=this._volume)}static add(t,e){return c(this,null,function*(){try{const e=new Promise((e,r)=>{const s=i.Sound.from({url:t,volume:this._volume,preload:!0,loaded:()=>{s.media instanceof i.webaudio.WebAudioMedia||r(new Error(`Error: ${t} is not WebAudioMedia`)),e(s)}})});return yield e}catch(r){return _t.warn(Rt,`Error occurred on "${t}"`,r),null==e||e(r),null}})}static play(t,e){t.play({singleInstance:!0,complete:()=>{null==e||e(),t.destroy()}})}static addAnalyzer(t,e){const i=t.media,r=e.createBufferSource();r.buffer=i.buffer;const s=e.createAnalyser();return s.fftSize=pt.fftSize,s.minDecibels=-90,s.maxDecibels=-10,s.smoothingTimeConstant=.85,r.connect(s),r.start(0),this.analysers.push(s),s}static analyze(t){if(!t)return parseFloat(Math.random().toFixed(1));const e=new Float32Array(t.fftSize);t.getFloatTimeDomainData(e);let i=0;for(let n=0;n<e.length;n++)i+=u(e[n],2);const r=Math.sqrt(i/e.length),s=20*Math.log10(r||u(10,-5)),a=Math.min(Math.max((s-t.minDecibels)/(t.maxDecibels-t.minDecibels),0),1);return parseFloat(a.toFixed(1))}static dispose(t){t.pause(),vt(this.audios,t)}static destroy(){for(let t=this.contexts.length-1;t>=0;t--){const e=this.contexts[t];null==e||e.close().catch(t=>{_t.warn(Rt,"Failed to close AudioContext.",t)})}for(let t=this.audios.length-1;t>=0;t--)this.dispose(this.audios[t])}}g(Dt,"audios",[]),g(Dt,"analysers",[]),g(Dt,"contexts",[]),g(Dt,"_volume",Tt);var At=(t=>(t.ALL="ALL",t.IDLE="IDLE",t.NONE="NONE",t))(At||{});class Ot extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"settings"),g(this,"motionGroups",{}),g(this,"state",new Lt),g(this,"currentAudio"),g(this,"currentAnalyzer"),g(this,"currentContext"),g(this,"playing",!1),g(this,"destroyed",!1),g(this,"parent"),this.settings=t.settings,this.tag=`MotionManager(${this.settings.name})`,this.state.tag=this.tag,this.parent=t}init(t){(null==t?void 0:t.idleMotionGroup)&&(this.groups.idle=t.idleMotionGroup),this.setupMotions(t),this.stopAllMotions()}setupMotions(t){if(!this.definitions)return void _t.warn(this.tag,"Motion definitions are not initialized.");for(const i of Object.keys(this.definitions))this.motionGroups[i]=[];let e;switch(null==t?void 0:t.motionPreload){case"NONE":return;case"ALL":e=Object.keys(this.definitions);break;default:e=[this.groups.idle]}for(const i of e){const t=this.definitions[i];if(t)for(let e=0;e<t.length;e++)this.loadMotion(i,e)}}loadMotion(t,e){return c(this,null,function*(){var i,r;if(this.destroyed)return;if(!this.getMotionDefinition(t,e))return;const s=null!=(r=(i=this.motionGroups)[t])?r:i[t]=[];if(null===s[e])return void _t.warn(this.tag,`Cannot start motion at "${t}"[${e}] because it's already failed in loading.`);if(s[e])return s[e];const a=yield this._loadMotion(t,e);return this.destroyed?void 0:(s[e]=null!=a?a:null,a)})}_loadMotion(t,e){throw new Error("Not implemented.")}initializeAudio(t,e){this.currentAudio=t,Dt.volume=e,this.currentContext=t.context.audioContext,this.currentAnalyzer=Dt.addAnalyzer(this.currentAudio,this.currentContext)}speak(t){return c(this,arguments,function*(t,{volume:e=.5,expression:i,resetExpression:r=!0,onFinish:s,onError:a}={}){if(!pt.sound)return!1;let n,o;if(this.currentAudio&&this.currentAudio.isPlaying)return!1;const l=t&&t.startsWith("data:");if(t&&!l){const e=document.createElement("a");e.href=t,o=t=e.href}else o="data:audio/";const u=t;if(u)try{n=yield Dt.add(u,(t,e=this)=>{_t.error(this.tag,"Error during audio playback:",t),null==a||a(t),r&&i&&e.expressionManager&&e.expressionManager.resetExpression(),e.currentAudio=void 0}),this.initializeAudio(n,e)}catch(h){return _t.warn(this.tag,"Failed to create audio",o,h),!1}if(n){let t=!0;try{pt.motionSync&&Dt.play(n,()=>{null==s||s(),r&&i&&this.expressionManager&&this.expressionManager.resetExpression(),this.currentAudio=void 0})}catch(h){_t.warn(this.tag,"Failed to play audio",n.url,h),t=!1}if(!t)return!1}return this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),i&&this.expressionManager&&(yield this.expressionManager.setExpression(i)),this.playing=!0,!0})}startMotion(t,e){return c(this,arguments,function*(t,e,i=Vt.NORMAL,{sound:r,volume:s=.5,expression:a,resetExpression:n=!0,onFinish:o,onError:l,ignoreParamIds:u=[]}={}){if(this.destroyed)return!1;if(!this.state.reserve(t,e,i))return!1;if(this.currentAudio&&this.currentAudio.isPlaying&&i!=Vt.FORCE)return!1;const h=this.getMotionDefinition(t,e);if(!h)return!1;let d,g;this.currentAudio&&Dt.dispose(this.currentAudio);const c=r&&r.startsWith("data:");if(r&&!c){const t=document.createElement("a");t.href=r,g=r=t.href}else g=this.getSoundFile(h),g&&(g=this.settings.resolveURL(g));const m=g;if(m)try{d=yield Dt.add(m,(t,e=this)=>{_t.error(this.tag,"Error during audio playback:",t),null==l||l(t),n&&a&&e.expressionManager&&e.expressionManager.resetExpression(),e.currentAudio=void 0}),this.initializeAudio(d,s)}catch(_){_t.warn(this.tag,"Failed to create audio",g,_)}const p=yield this.loadMotion(t,e);if(d&&pt.motionSync)try{Dt.play(d,(t=this)=>{null==o||o(),n&&a&&t.expressionManager&&t.expressionManager.resetExpression(),t.currentAudio=void 0})}catch(_){_t.warn(this.tag,"Failed to play audio",d.url,_)}return this.state.start(p,t,e,i)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),_t.log(this.tag,"Start motion:",this.getMotionName(h)),this.emit("motionStart",t,e,d),a&&this.expressionManager&&this.state.shouldOverrideExpression()&&(yield this.expressionManager.setExpression(a)),this.playing=!0,p&&this._startMotion(p,void 0,u),!0):(d&&(Dt.dispose(d),this.currentAudio=void 0),!1)})}startRandomMotion(t,e){return c(this,arguments,function*(t,e,{sound:i,volume:r=.5,expression:s,resetExpression:a=!0,onFinish:n,onError:o}={}){var l,u;if(this.destroyed)return!1;const h=null==(l=this.definitions)?void 0:l[t];if(null==h?void 0:h.length){const l=[],d=null!=(u=this.motionGroups[t])?u:[];for(let e=0;e<h.length;e++)null===d[e]||this.state.isActive(t,e)||l.push(e);if(l.length){const u=l[Math.floor(Math.random()*l.length)];return this.startMotion(t,u,e,{sound:i,volume:r,expression:s,resetExpression:a,onFinish:n,onError:o})}}return!1})}stopSpeaking(){this.currentAudio&&(Dt.dispose(this.currentAudio),this.currentAudio=void 0)}stopAllMotions(){this._stopAllMotions(),this.state.reset(),this.stopSpeaking()}update(t,e){var i;return this.isFinished()&&(this.playing&&(this.playing=!1,this.emit("motionFinish")),this.state.shouldOverrideExpression()&&(null==(i=this.expressionManager)||i.restoreExpression()),this.state.complete(),this.state.shouldRequestIdleMotion()&&this.startRandomMotion(this.groups.idle,Vt.IDLE)),this.updateParameters(t,e)}mouthSync(){return this.currentAnalyzer?Dt.analyze(this.currentAnalyzer):0}destroy(){var t;this.destroyed=!0,this.emit("destroy"),this.stopAllMotions(),null==(t=this.expressionManager)||t.destroy();this.definitions=void 0,this.motionGroups=void 0}getMotionAndApplyExpression(t,e,i){return c(this,null,function*(){if(this.destroyed)return null;if(!this.state.reserve(t,e,Vt.FORCE))return null;const r=this.getMotionDefinition(t,e);if(!r)return null;this.currentAudio&&Dt.dispose(this.currentAudio);const s=yield this.loadMotion(t,e);return this.state.start(s,t,e,Vt.FORCE)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),_t.log(this.tag,"Start motion:",this.getMotionName(r)),this.emit("motionStart",t,e,void 0),i&&this.expressionManager&&this.state.shouldOverrideExpression()&&(yield this.expressionManager.setExpression(i)),s):null})}getMotionDefinition(t,e){var i,r;const s=null==(r=null==(i=this.definitions)?void 0:i[t])?void 0:r[e];return s||_t.warn(this.tag,`Undefined motion at "${t}"[${e}]`),s}}function kt(t,e){if(!Array.isArray(t))return[];const i=[];for(const r of t){if(!r||"object"!=typeof r)continue;const t=r,s="string"==typeof t.id?t.id:"string"==typeof t.Id?t.Id:void 0,a="string"==typeof t.name?t.name:"string"==typeof t.Name?t.Name:void 0;s&&a&&i.push({id:s,name:a,index:e(s)})}return i}const Nt={x:0,y:0,width:0,height:0};class Ut extends e.EventEmitter{constructor(){super(...arguments),g(this,"focusController",new It),g(this,"pose"),g(this,"physics"),g(this,"originalWidth",0),g(this,"originalHeight",0),g(this,"width",0),g(this,"height",0),g(this,"localTransform",new e.Matrix),g(this,"drawingMatrix",new e.Matrix),g(this,"hitAreas",{}),g(this,"textureFlipY",!1),g(this,"viewport",[0,0,0,0]),g(this,"destroyed",!1)}init(){this.setupLayout(),this.setupHitAreas()}setupLayout(){const t=this,e=this.getSize();t.originalWidth=e[0],t.originalHeight=e[1];const i=Object.assign({width:2,height:2},this.getLayout());this.localTransform.scale(i.width/2,i.height/2),t.width=this.originalWidth*this.localTransform.a,t.height=this.originalHeight*this.localTransform.d;const r=void 0!==i.x&&i.x-i.width/2||void 0!==i.centerX&&i.centerX||void 0!==i.left&&i.left-i.width/2||void 0!==i.right&&i.right+i.width/2||0,s=void 0!==i.y&&i.y-i.height/2||void 0!==i.centerY&&i.centerY||void 0!==i.top&&i.top-i.height/2||void 0!==i.bottom&&i.bottom+i.height/2||0;this.localTransform.translate(this.width*r,-this.height*s)}setupHitAreas(){const t=this.getHitAreaDefs();this.hitAreas={};for(const e of t)e.name&&(this.hitAreas[e.name]=e)}hitTest(t,e){return Object.keys(this.hitAreas).filter(i=>this.isHit(i,t,e))}isHit(t,e,i){const r=this.hitAreas[t];if(!r)return!1;let s=r.index;if(s<0){if(!r.id)return!1;if(s=this.getDrawableIndex(r.id),s<0)return!1;r.index=s}const a=this.getDrawableBounds(s,Nt);return a.x<=e&&e<=a.x+a.width&&a.y<=i&&i<=a.y+a.height}getDrawableBounds(t,e){const i=this.getDrawableVertices(t);let r=i[0],s=i[0],a=i[1],n=i[1];for(let o=0;o<i.length;o+=2){const t=i[o],e=i[o+1];r=Math.min(t,r),s=Math.max(t,s),a=Math.min(e,a),n=Math.max(e,n)}return null!=e||(e={}),e.x=r,e.y=a,e.width=s-r,e.height=n-a,e}updateTransform(t){this.drawingMatrix.copyFrom(t).append(this.localTransform)}update(t,e){this.focusController.update(t)}destroy(){this.destroyed=!0,this.emit("destroy"),this.motionManager.destroy(),this.motionManager=void 0,this.parallelMotionManager.forEach(t=>t.destroy()),this.parallelMotionManager=[]}updateMotions(t,e){this.emit("beforeMotionUpdate");const i=this.motionManager.update(t,e),r=this.parallelMotionManager.map(i=>i.update(t,e)),s=i||r.reduce((t,e)=>t||e,!1);return this.emit("afterMotionUpdate"),s}}class zt extends Error{constructor(t,e,i,r=!1){super(t),this.url=e,this.status=i,this.aborted=r}}const jt=class t{static createXHR(e,i,r,s,a){const n=new XMLHttpRequest;if(t.allXhrSet.add(n),e){let i=t.xhrMap.get(e);i?i.add(n):(i=new Set([n]),t.xhrMap.set(e,i))}return n.open("GET",i),n.responseType=r,n.onload=()=>{var t;200!==n.status&&0!==n.status||!n.response?null==(t=n.onerror)||t.call(n,new ProgressEvent("error")):s(n.response)},n.onerror=()=>{_t.warn("XHRLoader",`Failed to load resource as ${n.responseType} (Status ${n.status}): ${i}`),a(new zt("Network error.",i,n.status))},n.onabort=()=>a(new zt("Aborted.",i,n.status,!0)),n.onloadend=()=>{var i;t.allXhrSet.delete(n),e&&(null==(i=t.xhrMap.get(e))||i.delete(n))},n}static cancelXHRs(){var e;null==(e=t.xhrMap.get(this))||e.forEach(e=>{e.abort(),t.allXhrSet.delete(e)}),t.xhrMap.delete(this)}static release(){t.allXhrSet.forEach(t=>t.abort()),t.allXhrSet.clear(),t.xhrMap=new WeakMap}};g(jt,"xhrMap",new WeakMap),g(jt,"allXhrSet",new Set),g(jt,"loader",t=>new Promise((e,i)=>{const r=t.target,s=t.target&&"function"==typeof jt.cancelXHRs?jt.cancelXHRs.bind(t.target):void 0,a=jt.createXHR(t.target,t.settings?t.settings.resolveURL(t.url):t.url,t.type,i=>{t.result=i,e()},i);if(t.target&&s&&"function"==typeof r.listeners&&"function"==typeof r.once){const t=r.listeners("destroy");Array.isArray(t)&&t.includes(s)||r.once("destroy",s)}a.send()}));let Gt=jt;function Xt(t,e){let i=-1;return function r(s,a){if(a)return Promise.reject(a);if(s<=i)return Promise.reject(new Error("next() called multiple times"));i=s;const n=t[s];if(!n)return Promise.resolve();try{return Promise.resolve(n(e,r.bind(null,s+1)))}catch(o){const t=o instanceof Error?o:new Error(String(o));return Promise.reject(t)}}(0)}class Ht{static load(t){return c(this,null,function*(){return yield Xt(this.middlewares,t),t.result})}}g(Ht,"middlewares",[Gt.loader]);class qt extends Et{constructor(t){if(super(t),g(this,"moc"),g(this,"textures"),g(this,"layout"),g(this,"hitAreas"),g(this,"initParams"),g(this,"initOpacities"),g(this,"expressions"),g(this,"motions",{}),!qt.isValidJSON(t))throw new TypeError("Invalid JSON.");this.moc=t.model,Ct("string",t,this,"textures","textures"),this.copy(t)}static isValidJSON(t){if(!t||"object"!=typeof t)return!1;const e=!!Array.isArray(t.textures)&&t.textures.every(t=>"string"==typeof t);return"string"==typeof t.model&&e}copy(t){xt("string",t,this,"name","name"),xt("string",t,this,"pose","pose"),xt("string",t,this,"physics","physics"),xt("object",t,this,"layout","layout"),xt("object",t,this,"motions","motions"),Ct("object",t,this,"hit_areas","hitAreas"),Ct("object",t,this,"expressions","expressions"),Ct("object",t,this,"init_params","initParams"),Ct("object",t,this,"init_opacities","initOpacities");const e=this.getFileStem(this.moc);this.setModelName(this.name,e)}replaceFiles(t){super.replaceFiles(t);for(const[e,i]of Object.entries(this.motions))for(let r=0;r<i.length;r++)i[r].file=t(i[r].file,`motions.${e}[${r}].file`),void 0!==i[r].sound&&(i[r].sound=t(i[r].sound,`motions.${e}[${r}].sound`));if(this.expressions)for(let e=0;e<this.expressions.length;e++)this.expressions[e].file=t(this.expressions[e].file,`expressions[${e}].file`)}}function Yt({lod:t,effectiveScale:e,textureWidth:i,textureHeight:r,lodScaleThreshold:s,lodTextureSizeThreshold:a,lodMaxLevel:n}){if("single-auto"!==Wt(t))return;if(!Number.isFinite(e)||e<=0)return;const o=Math.floor(i),l=Math.floor(r);if(o<=1||l<=1)return;if(e>=$t(s,.5))return;const h=$t(a,4096);if(Math.max(o,l)<h)return;const d=Math.round(Math.log2(1/e)),g=Math.max(1,Math.floor(Math.log2(Math.max(o,l)))),c=Math.min(g,(p=g,void 0!==(m=n)&&Number.isFinite(m)&&m>=1?Math.floor(m):p));var m,p;const _=function(t,e,i){return Math.min(i,Math.max(e,t))}(Math.max(1,d),1,c),f=u(2,_);return{level:_,width:Math.max(1,Math.round(o/f)),height:Math.max(1,Math.round(l/f))}}function Wt(t){return!1===t||"single-auto"===t?t:"full"}function Jt(t){return"nearest"===t?"nearest":"linear"}function $t(t,e){return void 0!==t&&Number.isFinite(t)&&t>0?t:e}function Zt(){}const Kt="Live2DFactory",Qt=(t,e)=>c(null,null,function*(){if("string"==typeof t.source){const e=yield Ht.load({url:t.source,type:"json",target:t.live2dModel});e.url="string"==typeof e.url?e.url:t.source,t.source=e,t.live2dModel.emit("settingsJSONLoaded",e)}return e()}),te=(t,e)=>c(null,null,function*(){if(t.source instanceof Et)return t.settings=t.source,e();if("object"==typeof t.source){const i=le.findRuntime(t.source);if(i){const r=i.createModelSettings(t.source);return t.settings=r,t.live2dModel.emit("settingsLoaded",r),e()}}const i=t.source&&"string"==typeof t.source.url?t.source.url:void 0,r=le.runtimes.map(t=>t.version).join(", ");if(0===le.runtimes.length)throw new TypeError(["Unknown settings format: no Live2D runtimes registered.",'Import a published runtime entry before loading models (e.g. "<package>/cubism" for Cubism 3/4/5, "<package>/cubism-legacy" for Cubism 2).',i?`Settings URL: ${i}`:void 0].filter(Boolean).join("\n"));const s=(()=>{try{if(!t.source||"object"!=typeof t.source||Array.isArray(t.source))return;return Object.keys(t.source).slice(0,30).join(", ")}catch(e){return}})();throw new TypeError(["Unknown settings format: no matching runtime found for the loaded settings JSON.",r?`Registered runtimes (versions): ${r}`:void 0,s?`Settings JSON keys: ${s}`:void 0,i?`Settings URL: ${i}`:void 0].filter(Boolean).join("\n"))}),ee=(t,e)=>{if(t.settings){const i=le.findRuntime(t.settings);if(i)return i.ready().then(()=>e())}return e()},ie=(t,e)=>c(null,null,function*(){yield e();const i=t.internalModel;if(i){const e=t.settings,r=le.findRuntime(e);if(r){const s=[],a=e instanceof qt?"json":"arraybuffer";e.pose&&s.push(Ht.load({settings:e,url:e.pose,type:a,target:i}).then(e=>{i.pose=r.createPose(i.coreModel,e),t.live2dModel.emit("poseLoaded",i.pose)}).catch(e=>{t.live2dModel.emit("poseLoadError",e),_t.warn(Kt,"Failed to load pose.",e)})),e.physics&&s.push(Ht.load({settings:e,url:e.physics,type:a,target:i}).then(e=>{i.physics=r.createPhysics(i.coreModel,e),t.live2dModel.emit("physicsLoaded",i.physics)}).catch(e=>{t.live2dModel.emit("physicsLoadError",e),_t.warn(Kt,"Failed to load physics.",e)})),s.length&&(yield Promise.all(s))}}}),re=(t,i)=>c(null,null,function*(){if(!t.settings)throw new TypeError("Missing settings.");{const r=t.live2dModel,s=d({crossOrigin:t.options.crossOrigin},t.options.textureOptions);t.settings instanceof qt&&(s.preferCreateImageBitmap=!1);const a=Promise.all(t.settings.textures.map(i=>function(t,i={}){const r=e.loadTextures.config,s=null==r?void 0:r.crossOrigin,a=null==r?void 0:r.preferCreateImageBitmap,n=null==r?void 0:r.preferWorkers;return void 0!==i.crossOrigin&&r&&(r.crossOrigin=i.crossOrigin),!1===i.preferCreateImageBitmap&&r&&(r.preferCreateImageBitmap=!1,r.preferWorkers=!1),e.Assets.load({src:t,data:{autoGenerateMipmaps:"full"===Wt(i.lod)}}).catch(t=>{if(t instanceof Error)throw t;throw new Error("Texture loading error",{cause:t})}).finally(()=>{r&&(r.crossOrigin=null!=s?s:r.crossOrigin,!1===i.preferCreateImageBitmap&&(r.preferCreateImageBitmap=null!=a?a:r.preferCreateImageBitmap,r.preferWorkers=null!=n?n:r.preferWorkers))})}(t.settings.resolveURL(i),s)));if(a.catch(Zt),yield i(),!t.internalModel)throw new TypeError("Missing internal model.");r.internalModel=t.internalModel,r.emit("modelLoaded",t.internalModel),r.textures=yield a,r.emit("textureLoaded",r.textures)}}),se=(t,e)=>c(null,null,function*(){const i=t.settings;if(i instanceof Et){const r=le.findRuntime(i);if(!r)throw new TypeError("Unknown model settings.");const s=yield Ht.load({settings:i,url:i.moc,type:"arraybuffer",target:t.live2dModel});if(!r.isValidMoc(s))throw new Error("Invalid moc data");const a=r.createCoreModel(s);return t.internalModel=r.createInternalModel(a,i,t.options),e()}throw new TypeError("Missing settings.")}),ae=class t{static resolveURL(e,i){var r;const s=null==(r=t.filesMap[e])?void 0:r[i];if(void 0===s)throw new Error("Cannot find this file from uploaded files: "+i);return s}static upload(e,i){const r={};for(const t of i.getDefinedFiles()){const s=decodeURI(Pt(i.url,t)),a=e.find(t=>t.webkitRelativePath===s);a&&(r[t]=URL.createObjectURL(a))}t.filesMap[i._objectURL]=r}static createSettings(e){return c(this,null,function*(){const i=e.find(t=>t.name.endsWith("model.json")||t.name.endsWith("model3.json"));if(!i)throw new TypeError("Settings file not found");const r=yield t.readText(i),s=JSON.parse(r);s.url=i.webkitRelativePath;const a=le.findRuntime(s);if(!a)throw new Error("Unknown settings JSON");const n=a.createModelSettings(s);return n._objectURL=URL.createObjectURL(i),n})}static readText(t){return c(this,null,function*(){return new Promise((e,i)=>{const r=new FileReader;r.onload=()=>e(r.result),r.onerror=i,r.readAsText(t,"utf8")})})}};g(ae,"live2dFactory"),g(ae,"filesMap",{}),g(ae,"factory",(t,e)=>c(null,null,function*(){if(Array.isArray(t.source)&&t.source[0]instanceof File){const e=t.source;let i=e.settings;if(i){if(!i._objectURL)throw new Error('"_objectURL" must be specified in ModelSettings')}else i=yield ae.createSettings(e);i.validateFiles(e.map(t=>encodeURI(t.webkitRelativePath))),ae.upload(e,i),i.resolveURL=function(t){return ae.resolveURL(this._objectURL,t)},t.source=i,t.live2dModel.once("modelLoaded",t=>{t.once("destroy",function(){const t=this.settings._objectURL;if(URL.revokeObjectURL(t),ae.filesMap[t])for(const e of Object.values(ae.filesMap[t]))URL.revokeObjectURL(e);delete ae.filesMap[t]})})}return e()}));let ne=ae;const oe=class t{static registerRuntime(e){t.runtimes.push(e),t.runtimes.sort((t,e)=>e.version-t.version)}static findRuntime(e){for(const i of t.runtimes)if(i.test(e))return i}static setupLive2DModel(e,i,r){return c(this,null,function*(){const s=new Promise(t=>e.once("textureLoaded",t)),a=new Promise(t=>e.once("modelLoaded",t)),n=Promise.all([s,a]).then(()=>e.emit("ready"));yield Xt(t.live2DModelMiddlewares,{live2dModel:e,source:i,options:r||{}}),yield n,e.emit("load")})}static loadMotion(e,i,r){var s;const a=t=>e.emit("motionLoadError",i,r,t);try{const n=null==(s=e.definitions[i])?void 0:s[r];if(!n)return Promise.resolve(void 0);e.once("destroy",()=>t.releaseMotionTasks(e));let o=t.motionTasksMap.get(e);o||(o={},t.motionTasksMap.set(e,o));let l=o[i];l||(l=[],o[i]=l);const u=e.getMotionFile(n);return null!=l[r]||(l[r]=Ht.load({url:u,settings:e.settings,type:e.motionDataType,target:e}).then(s=>{var a;const o=null==(a=t.motionTasksMap.get(e))?void 0:a[i];o&&(o[r]=void 0);const l=s,u=e.createMotion(l,i,n);return e.emit("motionLoaded",i,r,u),u}).catch(t=>{_t.warn(e.tag,`Failed to load motion: ${u}\n`,t),a(t)})),l[r]}catch(n){_t.warn(e.tag,`Failed to load motion at "${i}"[${r}]\n`,n),a(n)}return Promise.resolve(void 0)}static loadExpression(e,i){var r;const s=t=>e.emit("expressionLoadError",i,t);try{const a=e.definitions[i];if(!a)return Promise.resolve(void 0);e.once("destroy",()=>t.releaseExpressionTasks(e));let n=t.expressionTasksMap.get(e);n||(n=[],t.expressionTasksMap.set(e,n));const o=e.getExpressionFile(a),l=null!=(r=e.expressionDataType)?r:"json";return null!=n[i]||(n[i]=Ht.load({url:o,settings:e.settings,type:l,target:e}).then(r=>{const s=t.expressionTasksMap.get(e);s&&(s[i]=void 0);const n=r,o=e.createExpression(n,a);return e.emit("expressionLoaded",i,o),o}).catch(t=>{_t.warn(e.tag,`Failed to load expression: ${o}\n`,t),s(t)})),n[i]}catch(a){_t.warn(e.tag,`Failed to load expression at [${i}]\n`,a),s(a)}return Promise.resolve(void 0)}static releaseMotionTasks(e){t.motionTasksMap.delete(e)}static releaseExpressionTasks(e){t.expressionTasksMap.delete(e)}};g(oe,"runtimes",[]),g(oe,"urlToJSON",Qt),g(oe,"jsonToSettings",te),g(oe,"waitUntilReady",ee),g(oe,"setupOptionals",ie),g(oe,"setupEssentials",re),g(oe,"createInternalModel",se),g(oe,"live2DModelMiddlewares",[ne.factory,Qt,te,ee,ie,re,se]),g(oe,"motionTasksMap",new WeakMap),g(oe,"expressionTasksMap",new WeakMap);let le=oe;Ot.prototype._loadMotion=function(t,e){return le.loadMotion(this,t,e)},Bt.prototype._loadExpression=function(t){return le.loadExpression(this,t)},ne.live2dFactory=le;const ue=class t{constructor(i,{autoUpdate:r=!0,autoHitTest:s=!0,autoFocus:a=!0,autoInteract:n,ticker:o}={}){var l;g(this,"model"),g(this,"destroyed",!1),g(this,"_ticker"),g(this,"_autoUpdate",!1),g(this,"_autoHitTest",!1),g(this,"_autoFocus",!1),null!=o||(o=null!=(l=t.defaultTicker)?l:"undefined"!=typeof PIXI?PIXI.Ticker.shared:e.Ticker.shared),void 0!==n&&(s=n,a=n,_t.warn(i.tag,"options.autoInteract is deprecated since v0.5.0, use autoHitTest and autoFocus instead.")),this.model=i,this.ticker=o,this.autoUpdate=r,this.autoHitTest=s,this.autoFocus=a,(s||a)&&(this.model.eventMode="static")}get ticker(){return this._ticker}set ticker(t){var e,i;this._ticker&&this._ticker.remove(de,this),this._ticker=t,this._autoUpdate&&(null==(e=this._ticker)||e.add(de,this),null==(i=this._ticker)||i.start())}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){var e;this.destroyed||(t?this._ticker?(this._ticker.add(de,this),this._autoUpdate=!0):_t.warn(this.model.tag,"No Ticker to be used for automatic updates. Either set option.ticker when creating Live2DModel, or expose PIXI to global scope (window.PIXI = PIXI)."):(null==(e=this._ticker)||e.remove(de,this),this._autoUpdate=!1))}get autoHitTest(){return this._autoHitTest}set autoHitTest(t){t!==this.autoHitTest&&(t?this.model.on("pointertap",ge,this):this.model.off("pointertap",ge,this),this._autoHitTest=t)}get autoFocus(){return this._autoFocus}set autoFocus(t){t!==this.autoFocus&&(t?(this.model.on("globalpointermove",ce,this),this.model.on("pointermove",ce,this)):(this.model.off("globalpointermove",ce,this),this.model.off("pointermove",ce,this)),this._autoFocus=t)}get autoInteract(){return this._autoHitTest&&this._autoFocus}set autoInteract(t){this.autoHitTest=t,this.autoFocus=t}onTickerUpdate(){const t=this.ticker.deltaMS;this.model.update(t)}onTap(t){this.model.tap(t.global.x,t.global.y)}onPointerMove(t){this.model.focus(t.global.x,t.global.y)}destroy(){this.autoFocus=!1,this.autoHitTest=!1,this.autoUpdate=!1,this.ticker=void 0,this.destroyed=!0}};g(ue,"defaultTicker");let he=ue;function de(){this.onTickerUpdate()}function ge(t){this.onTap(t)}function ce(t){this.onPointerMove(t)}class me extends e.Transform{}const pe=new e.Point,_e=new e.Matrix,fe=new e.Matrix,ye={x:0,y:0,width:0,height:0},xe=new e.Bounds;let Ce=!1;class Me{constructor(t){this.renderer=t}addRenderable(t,e){var i,r;null==(r=null==(i=this.renderer.renderPipes.batch)?void 0:i.break)||r.call(i,e),e.add(t)}execute(t){!t.visible||t.alpha<=0||t.renderLive2D(this.renderer)}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}destroy(){}}g(Me,"extension",{type:[e.ExtensionType.WebGLPipes],name:"live2d"});const Se=Me;class ve extends e.Container{constructor(t){super(),g(this,"renderPipeId","live2d"),g(this,"tag","Live2DModel(uninitialized)"),g(this,"internalModel"),g(this,"textures",[]),g(this,"textureOptions"),g(this,"textureLODStates",[]),g(this,"textureLODFailures",[]),g(this,"transform",new me),g(this,"anchor"),g(this,"_bounds",new e.Bounds),g(this,"_boundsDirty",!0),g(this,"_boundsRetryAfterDraw",!1),g(this,"gl",null),g(this,"elapsedTime",0),g(this,"deltaTime",0),g(this,"automator"),g(this,"currentGlId",0),g(this,"renderLive2D",t=>{var i,r,s,a,n;if(!(t instanceof e.WebGLRenderer))throw new Error("Renderer is not supported");t.geometry.resetState(),t.shader.resetState(),t.texture.resetState();let o=!1;this.gl!==t.gl&&(this.gl=t.gl,this.internalModel.updateWebGLContext(t.gl,this.generateUID()),o=!0);const{projectionMatrix:l,offset:u,worldTransformMatrix:h}=t.globalUniforms.globalUniformData,d=fe.copyFrom(h).append(this.groupTransform),g=(c=d,Math.max(Math.hypot(c.a,c.b),Math.hypot(c.c,c.d))*t.resolution);var c;for(let e=0;e<this.textures.length;e++){const i=this.textures[e];let r=this.resolveTextureForRender(e,i,g);try{this.uploadTextureForRender(t,r,o)}catch(M){if(r===i)throw new Error("Failed to upload Live2D texture.");const s=this.textureLODStates[e];(null==s?void 0:s.texture)===r&&(this.markTextureLODFailure(e,i,s.level),this.destroyTextureLODState(e)),r=i,this.uploadTextureForRender(t,r,o)}this.internalModel.bindTexture(e,t.texture.getGlSource(r.source).texture)}const m=t.renderTarget.viewport,p=t.renderTarget.renderTarget;let _=m.y;if(null==p?void 0:p.isRoot){_=p.colorTexture.source.pixelHeight-m.height-m.y}this.internalModel.viewport=[m.x,_,m.width,m.height];const f=this.deltaTime;this.deltaTime=0,f&&this.internalModel.update(f,this.elapsedTime),d.tx-=null!=(i=null==u?void 0:u.x)?i:0,d.ty-=null!=(r=null==u?void 0:u.y)?r:0;const y=_e.copyFrom(l).append(d);this.internalModel.updateTransform(y),this.internalModel.draw(t.gl),this._boundsRetryAfterDraw&&this.updateDrawableBounds(),t.state.resetState(),t.texture.resetState();const x=null==(s=t.renderTarget)?void 0:s.defaultClearColor,C=null==(n=null==(a=t.renderTarget)?void 0:a.adaptor)?void 0:n._clearColorCache;x&&(t.gl.clearColor(x[0],x[1],x[2],x[3]),C&&(C[0]=x[0],C[1]=x[1],C[2]=x[2],C[3]=x[3]))}),this.textureOptions=null==t?void 0:t.textureOptions,this.anchor=new e.ObservablePoint({_onUpdate:()=>this.onAnchorChange()},0,0),this.automator=new he(this,t),this.once("modelLoaded",()=>this.initializeOnModelLoad(t))}get isRenderable(){return!0}get canBundle(){return!1}static from(t,e){return c(this,null,function*(){const i=new this(e);return yield le.setupLive2DModel(i,t,e),i})}static fromSync(t,e){const i=new this(e);return le.setupLive2DModel(i,t,e).then(()=>{var t;return null==(t=null==e?void 0:e.onLoad)?void 0:t.call(e)}).catch(t=>{var i;return null==(i=null==e?void 0:e.onError)?void 0:i.call(e,t)}),i}static registerTicker(t){he.defaultTicker=t.shared}get bounds(){return this.internalModel?(this._boundsDirty&&this.updateDrawableBounds(),this._bounds):(this._bounds.set(0,0,0,0),this._bounds)}updateDrawableBounds(){if(!this.internalModel)return this._bounds.set(0,0,0,0),void(this._boundsDirty=!1);const t=this.internalModel.getDrawableIDs();xe.clear();for(let i=0;i<t.length;i++){const r=t[i],s=this.internalModel.getDrawableIndex(r);if(s<0)continue;const a=this.internalModel.getDrawableBounds(s,ye);Number.isFinite(a.x)&&Number.isFinite(a.y)&&Number.isFinite(a.width)&&Number.isFinite(a.height)&&xe.addFrame(a.x,a.y,a.x+a.width,a.y+a.height,e.Matrix.IDENTITY)}if(this._bounds.clear(),xe.isValid&&xe.isPositive)this._bounds.addFrame(xe.minX,xe.minY,xe.maxX,xe.maxY,this.internalModel.localTransform),this._boundsRetryAfterDraw=!1;else{const t=this.internalModel.originalWidth||this.internalModel.width,e=this.internalModel.originalHeight||this.internalModel.height;this._bounds.addFrame(0,0,t,e,this.internalModel.localTransform),this._boundsRetryAfterDraw=!0}this._boundsDirty=!1}generateUID(){return++this.currentGlId}collectRenderables(t,e,i){var r,s,a,n;if(this.parentRenderLayer&&this.parentRenderLayer!==i)return;if(this.globalDisplayStatus<7)return;if(!this.includeInBuild)return;this.sortableChildren&&this.sortChildren(),function(t){const e=t;e.renderPipes.live2d||(Ce||(Ce=!0,console.warn("[untitled-pixi-live2d-engine] Lazy Live2D render pipe registration is deprecated. Register Live2DPlugin explicitly with `extensions.add(Live2DPlugin)` before creating the Pixi renderer.")),e.renderPipes.live2d=new Me(t))}(e);const o=e.renderPipes,l=()=>{o.live2d.addRenderable(this,t)},u=()=>{const r=this.children,s=r.length;for(let a=0;a<s;a++)r[a].collectRenderables(t,e,i)},h=this.effects;if(h){for(let e=0;e<h.length;e++){const i=h[e],a=i.filters;if(a)for(const t of a)t&&"number"==typeof t.resolution&&1===t.resolution&&(t.resolution="inherit");null==(s=null==(r=o[i.pipe])?void 0:r.push)||s.call(r,i,this,t)}l(),u();for(let e=h.length-1;e>=0;e--){const i=h[e];null==(n=null==(a=o[i.pipe])?void 0:a.pop)||n.call(a,i,this,t)}}else l(),u()}initializeOnModelLoad(t){this.tag=`Live2DModel(${this.internalModel.settings.name})`,this.onAnchorChange(),this.updateDrawableBounds()}onAnchorChange(){this.internalModel&&this.pivot&&this.pivot.set(this.anchor.x*this.internalModel.width,this.anchor.y*this.internalModel.height)}motion(t,e,i){return c(this,arguments,function*(t,e,i,{sound:r,volume:s=.5,expression:a,resetExpression:n=!0,onFinish:o,onError:l}={}){return void 0===e?this.internalModel.motionManager.startRandomMotion(t,i,{sound:r,volume:s,expression:a,resetExpression:n,onFinish:o,onError:l}):this.internalModel.motionManager.startMotion(t,e,i,{sound:r,volume:s,expression:a,resetExpression:n,onFinish:o,onError:l})})}motionLastFrame(t,e){return c(this,arguments,function*(t,e,{expression:i}={}){return this.internalModel.motionManager.motionLastFrame(t,e,{expression:i})})}parallelMotion(t){return c(this,null,function*(){this.internalModel.extendParallelMotionManager(t.length);const e=t.map((t,e)=>this.internalModel.parallelMotionManager[e].startMotion(t.group,t.index,t.priority)),i=[];for(const t of e)i.push(yield t);return i})}parallelLastFrame(t){return c(this,null,function*(){this.internalModel.extendParallelMotionManager(t.length);const e=t.map((t,e)=>this.internalModel.parallelMotionManager[e].playMotionLastFrame(t.group,t.index)),i=[];for(const t of e)i.push(yield t);return i})}stopMotions(){return this.internalModel.motionManager.stopAllMotions()}speak(t,{volume:e=.5,expression:i,resetExpression:r=!0,onFinish:s,onError:a}={}){return this.internalModel.motionManager.speak(t,{volume:e,expression:i,resetExpression:r,onFinish:s,onError:a})}stopSpeaking(){return this.internalModel.motionManager.stopSpeaking()}expression(t){return this.internalModel.motionManager.expressionManager?void 0===t?this.internalModel.motionManager.expressionManager.setRandomExpression():this.internalModel.motionManager.expressionManager.setExpression(t):Promise.resolve(!1)}focus(t,e,i=!1){pe.x=t,pe.y=e,this.toModelPosition(pe,pe,!0);const r=pe.x/this.internalModel.originalWidth*2-1,s=pe.y/this.internalModel.originalHeight*2-1,a=Math.atan2(s,r);this.internalModel.focusController.focus(Math.cos(a),-Math.sin(a),i)}tap(t,e){const i=this.hitTest(t,e);i.length&&this.emit("hit",i)}hitTest(t,e){return pe.x=t,pe.y=e,this.toModelPosition(pe,pe),this.internalModel.hitTest(pe.x,pe.y)}toModelPosition(t,e=t.clone(),i){return i||this.updateLocalTransform(),this.toLocal(t,void 0,e,i),this.internalModel.localTransform.applyInverse(e,e),e}containsPoint(t){return this.bounds.containsPoint(t.x,t.y)}_calculateBounds(){if(!this.internalModel)return void this.getBounds().set(0,0,0,0);const t=this.internalModel.width,e=this.internalModel.height;this.getBounds().addFrame(0,0,t,e,this.transform.matrix)}update(t){this.deltaTime+=t,this.elapsedTime+=t}resolveTextureForRender(t,i,r){var n;const o=Yt((l=d({},this.textureOptions),u={effectiveScale:r,textureWidth:i.source.pixelWidth,textureHeight:i.source.pixelHeight},s(l,a(u))));var l,u;if(!o)return i;const h=this.textureLODFailures[t];if((null==h?void 0:h.source)===i&&h.levels.has(o.level))return i;const g=this.textureLODStates[t];if((null==g?void 0:g.source)===i&&g.level===o.level&&!g.texture.destroyed)return g.texture;this.destroyTextureLODState(t);const c=function(t,i,r,s,a){var n,o;const l=t.source.resource;if(!function(t){if(!t||"object"!=typeof t)return!1;const{width:e,height:i}=t;return"number"==typeof e&&e>0&&"number"==typeof i&&i>0}(l))return;const u=e.DOMAdapter.get().createCanvas(r,s),h=u.getContext("2d");if(!h)return;try{h.clearRect(0,0,r,s),h.imageSmoothingEnabled="nearest"!==a,"imageSmoothingQuality"in h&&"nearest"!==a&&(h.imageSmoothingQuality="high"),h.drawImage(l,0,0,t.source.pixelWidth,t.source.pixelHeight,0,0,r,s)}catch(g){return}const d=`${null!=(o=null!=(n=t.label)?n:t.source.label)?o:"Live2DTexture"} LOD ${i}`;return new e.Texture({label:d,source:new e.CanvasSource({resource:u,width:r,height:s,resolution:1,scaleMode:Jt(a),autoGenerateMipmaps:!1,label:d})})}(i,o.level,o.width,o.height,null==(n=this.textureOptions)?void 0:n.lodFilter);return c?(this.textureLODStates[t]={source:i,level:o.level,texture:c},c):(this.markTextureLODFailure(t,i,o.level),i)}markTextureLODFailure(t,e,i){let r=this.textureLODFailures[t];(null==r?void 0:r.source)!==e&&(r={source:e,levels:new Set},this.textureLODFailures[t]=r),r.levels.add(i)}destroyTextureLODState(t){const e=this.textureLODStates[t];e&&(e.texture.destroy(!0),this.textureLODStates[t]=void 0)}destroyTextureLODStates(){for(let t=0;t<this.textureLODStates.length;t++)this.destroyTextureLODState(t);this.textureLODFailures.length=0}uploadTextureForRender(t,e,i){const r=Boolean(e.source._gpuData[t.uid]);!i&&r||(t.gl.pixelStorei(WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL,this.internalModel.textureFlipY),t.texture.bind(e,0))}destroy(t){this.emit("destroy"),this.destroyTextureLODStates(),(null==t?void 0:t.texture)&&this.textures.forEach(e=>e.destroy(t.baseTexture)),this.automator.destroy(),this.internalModel.destroy(),super.destroy(t)}}if("undefined"==typeof window||void 0===window.Live2DCubismCore)throw new Error("Could not find Cubism runtime. This plugin requires live2dcubismcore.js to be loaded.");class be{constructor(t,e){this.x=t,this.y=e,this.x=null==t?0:t,this.y=null==e?0:e}add(t){const e=new be(0,0);return e.x=this.x+t.x,e.y=this.y+t.y,e}substract(t){const e=new be(0,0);return e.x=this.x-t.x,e.y=this.y-t.y,e}multiply(t){const e=new be(0,0);return e.x=this.x*t.x,e.y=this.y*t.y,e}multiplyByScaler(t){return this.multiply(new be(t,t))}division(t){const e=new be(0,0);return e.x=this.x/t.x,e.y=this.y/t.y,e}divisionByScalar(t){return this.division(new be(t,t))}getLength(){return Math.sqrt(this.x*this.x+this.y*this.y)}getDistanceWith(t){return Math.sqrt((this.x-t.x)*(this.x-t.x)+(this.y-t.y)*(this.y-t.y))}dot(t){return this.x*t.x+this.y*t.y}normalize(){const t=Math.pow(this.x*this.x+this.y*this.y,.5);this.x=this.x/t,this.y=this.y/t}isEqual(t){return this.x==t.x&&this.y==t.y}isNotEqual(t){return!this.isEqual(t)}}var Pe;(t=>{t.CubismVector2=be})(Pe||(Pe={}));const Be=class t{static range(t,e,i){return t<e?t=e:t>i&&(t=i),t}static sin(t){return Math.sin(t)}static cos(t){return Math.cos(t)}static abs(t){return Math.abs(t)}static sqrt(t){return Math.sqrt(t)}static cbrt(t){if(0===t)return t;let e=t;const i=e<0;let r;return i&&(e=-e),e===1/0?r=1/0:(r=Math.exp(Math.log(e)/3),r=(e/(r*r)+2*r)/3),i?-r:r}static getEasingSine(t){return t<0?0:t>1?1:.5-.5*this.cos(t*Math.PI)}static max(t,e){return t>e?t:e}static min(t,e){return t>e?e:t}static clamp(t,e,i){return t<e?e:i<t?i:t}static degreesToRadian(t){return t/180*Math.PI}static radianToDegrees(t){return 180*t/Math.PI}static directionToRadian(t,e){let i=Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x);for(;i<-Math.PI;)i+=2*Math.PI;for(;i>Math.PI;)i-=2*Math.PI;return i}static directionToDegrees(t,e){const i=this.directionToRadian(t,e);let r=this.radianToDegrees(i);return e.x-t.x>0&&(r=-r),r}static radianToDirection(t){const e=new be;return e.x=this.sin(t),e.y=this.cos(t),e}static quadraticEquation(e,i,r){return this.abs(e)<t.Epsilon?this.abs(i)<t.Epsilon?-r:-r/i:-(i+this.sqrt(i*i-4*e*r))/(2*e)}static cardanoAlgorithmForBezier(e,i,r,s){if(this.abs(e)<t.Epsilon)return this.range(this.quadraticEquation(i,r,s),0,1);const a=i/e,n=r/e,o=(3*n-a*a)/3,l=o/3,u=(2*a*a*a-9*a*n+27*(s/e))/27,h=u/2,d=h*h+l*l*l,g=.5,c=.51;if(d<0){const t=-o/3,e=t*t*t,i=this.sqrt(e),r=-u/(2*i),s=this.range(r,-1,1),n=Math.acos(s),l=2*this.cbrt(i),h=l*this.cos(n/3)-a/3;if(this.abs(h-g)<c)return this.range(h,0,1);const d=l*this.cos((n+2*Math.PI)/3)-a/3;if(this.abs(d-g)<c)return this.range(d,0,1);const m=l*this.cos((n+4*Math.PI)/3)-a/3;return this.range(m,0,1)}if(0==d){let t;t=h<0?this.cbrt(-h):-this.cbrt(h);const e=2*t-a/3;if(this.abs(e-g)<c)return this.range(e,0,1);const i=-t-a/3;return this.range(i,0,1)}const m=this.sqrt(d),p=this.cbrt(m-h)-this.cbrt(m+h)-a/3;return this.range(p,0,1)}static mod(t,e){if(!isFinite(t)||0===e||isNaN(t)||isNaN(e))return console.warn(`divided: ${t}, divisor: ${e} mod() returns 'NaN'.`),NaN;const i=Math.abs(t),r=Math.abs(e);let s=i-Math.floor(i/r)*r;return s*=Math.sign(t),s}constructor(){}};Be.Epsilon=1e-5;let we=Be;var Fe,Ie;(t=>{t.CubismMath=we})(Fe||(Fe={}));class Ee{constructor(){this.setBeganMotionHandler=t=>this._onBeganMotion=t,this.getBeganMotionHandler=()=>this._onBeganMotion,this.setFinishedMotionHandler=t=>this._onFinishedMotion=t,this.getFinishedMotionHandler=()=>this._onFinishedMotion,this._fadeInSeconds=-1,this._fadeOutSeconds=-1,this._weight=1,this._offsetSeconds=0,this._isLoop=!1,this._isLoopFadeIn=!0,this._previousLoopState=this._isLoop,this._firedEventValues=new p}static delete(t){t.release(),t=null}release(){this._weight=0}updateParameters(t,e,i){if(!e.isAvailable()||e.isFinished())return;this.setupMotionQueueEntry(e,i);const r=this.updateFadeWeight(e,i);this.doUpdateParameters(t,i,r,e),e.getEndTime()>0&&e.getEndTime()<i&&e.setIsFinished(!0)}setupMotionQueueEntry(t,e){null==t||t.isStarted()||t.isAvailable()&&(t.setIsStarted(!0),t.setStartTime(e-this._offsetSeconds),t.setFadeInStartTime(e),t.getEndTime()<0&&this.adjustEndTime(t),t._motion._onBeganMotion&&t._motion._onBeganMotion(t._motion))}updateFadeWeight(t,e){null==t&&z.print(mt.LogLevel_Error,"motionQueueEntry is null.");let i=this._weight;return i=i*(0==this._fadeInSeconds?1:we.getEasingSine((e-t.getFadeInStartTime())/this._fadeInSeconds))*(0==this._fadeOutSeconds||t.getEndTime()<0?1:we.getEasingSine((t.getEndTime()-e)/this._fadeOutSeconds)),t.setState(e,i),A(0<=i&&i<=1),i}setFadeInTime(t){this._fadeInSeconds=t}setFadeOutTime(t){this._fadeOutSeconds=t}getFadeOutTime(){return this._fadeOutSeconds}getFadeInTime(){return this._fadeInSeconds}setWeight(t){this._weight=t}getWeight(){return this._weight}getDuration(){return-1}getLoopDuration(){return-1}setOffsetTime(t){this._offsetSeconds=t}setLoop(t){this._isLoop=t}getLoop(){return this._isLoop}setLoopFadeIn(t){this._isLoopFadeIn=t}getLoopFadeIn(){return this._isLoopFadeIn}getFiredEvent(t,e){return this._firedEventValues}isExistModelOpacity(){return!1}getModelOpacityIndex(){return-1}getModelOpacityId(t){return null}getModelOpacityValue(){return 1}adjustEndTime(t){const e=this.getDuration(),i=e<=0?-1:t.getStartTime()+e;t.setEndTime(i)}}(t=>{t.ACubismMotion=Ee})(Ie||(Ie={}));const Ve="Parameters",Le="Blend",Re=class t extends Ee{static create(e,i){const r=new t;return r.parse(e,i),r}doUpdateParameters(t,e,i,r){for(let s=0;s<this._parameters.getSize();++s){const e=this._parameters.at(s);switch(e.blendType){case 0:t.addParameterValueById(e.parameterId,e.value,i);break;case 1:t.multiplyParameterValueById(e.parameterId,e.value,i);break;case 2:t.setParameterValueById(e.parameterId,e.value,i)}}}calculateExpressionParameters(e,i,r,s,a,n){if(null!=r&&null!=s&&r.isAvailable()){this._fadeWeight=this.updateFadeWeight(r,i);for(let i=0;i<s.getSize();++i){const r=s.at(i);if(null==r.parameterId)continue;const o=r.overwriteValue=e.getParameterValueById(r.parameterId),l=this.getExpressionParameters();let u=-1;for(let t=0;t<l.getSize();++t)if(r.parameterId==l.at(t).parameterId){u=t;break}if(u<0){0==a?(r.additiveValue=t.DefaultAdditiveValue,r.multiplyValue=t.DefaultMultiplyValue,r.overwriteValue=o):(r.additiveValue=this.calculateValue(r.additiveValue,t.DefaultAdditiveValue,n),r.multiplyValue=this.calculateValue(r.multiplyValue,t.DefaultMultiplyValue,n),r.overwriteValue=this.calculateValue(r.overwriteValue,o,n));continue}const h=l.at(u).value;let d,g,c;switch(l.at(u).blendType){case 0:d=h,g=t.DefaultMultiplyValue,c=o;break;case 1:d=t.DefaultAdditiveValue,g=h,c=o;break;case 2:d=t.DefaultAdditiveValue,g=t.DefaultMultiplyValue,c=h;break;default:return}0==a?(r.additiveValue=d,r.multiplyValue=g,r.overwriteValue=c):(r.additiveValue=r.additiveValue*(1-n)+d*n,r.multiplyValue=r.multiplyValue*(1-n)+g*n,r.overwriteValue=r.overwriteValue*(1-n)+c*n)}}}getExpressionParameters(){return this._parameters}getFadeWeight(){return this._fadeWeight}parse(t,e){const i=Z.create(t,e);if(!i)return;const r=i.getRoot();this.setFadeInTime(r.getValueByString("FadeInTime").toFloat(1)),this.setFadeOutTime(r.getValueByString("FadeOutTime").toFloat(1));const s=r.getValueByString(Ve).getSize();this._parameters.prepareCapacity(s);for(let a=0;a<s;++a){const t=r.getValueByString(Ve).getValueByIndex(a),e=ct.getIdManager().getId(t.getValueByString("Id").getRawString()),i=t.getValueByString("Value").toFloat();let s;s=t.getValueByString(Le).isNull()||"Add"==t.getValueByString(Le).getString()?0:"Multiply"==t.getValueByString(Le).getString()?1:"Overwrite"==t.getValueByString(Le).getString()?2:0;const n=new ke;n.parameterId=e,n.blendType=s,n.value=i,this._parameters.pushBack(n)}Z.delete(i)}calculateValue(t,e,i){return t*(1-i)+e*i}constructor(){super(),this._parameters=new p,this._fadeWeight=0}};Re.DefaultAdditiveValue=0,Re.DefaultMultiplyValue=1;let Te=Re;var De,Ae,Oe=(t=>(t[t.Additive=0]="Additive",t[t.Multiply=1]="Multiply",t[t.Overwrite=2]="Overwrite",t))(Oe||{});class ke{}(t=>{t.CubismExpressionMotion=Te,t.ExpressionBlendType=Oe,t.ExpressionParameter=ke})(De||(De={}));class Ne{constructor(){this._autoDelete=!1,this._motion=null,this._available=!0,this._finished=!1,this._started=!1,this._startTimeSeconds=-1,this._fadeInStartTimeSeconds=0,this._endTimeSeconds=-1,this._stateTimeSeconds=0,this._stateWeight=0,this._lastEventCheckSeconds=0,this._motionQueueEntryHandle=this,this._fadeOutSeconds=0,this._isTriggeredFadeOut=!1}release(){this._autoDelete&&this._motion&&Ee.delete(this._motion)}setFadeOut(t){this._fadeOutSeconds=t,this._isTriggeredFadeOut=!0}startFadeOut(t,e){const i=e+t;this._isTriggeredFadeOut=!0,(this._endTimeSeconds<0||i<this._endTimeSeconds)&&(this._endTimeSeconds=i)}isFinished(){return this._finished}isStarted(){return this._started}getStartTime(){return this._startTimeSeconds}getFadeInStartTime(){return this._fadeInStartTimeSeconds}getEndTime(){return this._endTimeSeconds}setStartTime(t){this._startTimeSeconds=t}setFadeInStartTime(t){this._fadeInStartTimeSeconds=t}setEndTime(t){this._endTimeSeconds=t}setIsFinished(t){this._finished=t}setIsStarted(t){this._started=t}isAvailable(){return this._available}setIsAvailable(t){this._available=t}setState(t,e){this._stateTimeSeconds=t,this._stateWeight=e}getStateTime(){return this._stateTimeSeconds}getStateWeight(){return this._stateWeight}getLastCheckEventSeconds(){return this._lastEventCheckSeconds}setLastCheckEventSeconds(t){this._lastEventCheckSeconds=t}isTriggeredFadeOut(){return this._isTriggeredFadeOut}getFadeOutSeconds(){return this._fadeOutSeconds}getCubismMotion(){return this._motion}}(t=>{t.CubismMotionQueueEntry=Ne})(Ae||(Ae={}));class Ue{constructor(){this._userTimeSeconds=0,this._eventCallBack=null,this._eventCustomData=null,this._motions=new p}release(){for(let t=0;t<this._motions.getSize();++t)this._motions.at(t)&&(this._motions.at(t).release(),this._motions.set(t,null));this._motions=null}startMotion(t,e,i){if(null==t)return ze;let r=null;for(let s=0;s<this._motions.getSize();++s)r=this._motions.at(s),null!=r&&r.setFadeOut(r._motion.getFadeOutTime());return r=new Ne,r._autoDelete=e,r._motion=t,this._motions.pushBack(r),r._motionQueueEntryHandle}isFinished(){for(let t=this._motions.begin();t.notEqual(this._motions.end());){let e=t.ptr();if(null==e){t=this._motions.erase(t);continue}if(null!=e._motion){if(!e.isFinished())return!1;t.preIncrement()}else e.release(),e=null,t=this._motions.erase(t)}return!0}isFinishedByHandle(t){for(let e=this._motions.begin();e.notEqual(this._motions.end());e.increment()){const i=e.ptr();if(null!=i&&(i._motionQueueEntryHandle==t&&!i.isFinished()))return!1}return!0}stopAllMotions(){for(let t=this._motions.begin();t.notEqual(this._motions.end());){let e=t.ptr();null!=e?(e.release(),e=null,t=this._motions.erase(t)):t=this._motions.erase(t)}}getCubismMotionQueueEntries(){return this._motions}getCubismMotionQueueEntry(t){for(let e=this._motions.begin();e.notEqual(this._motions.end());e.preIncrement()){const i=e.ptr();if(null!=i&&i._motionQueueEntryHandle==t)return i}return null}setEventCallback(t,e=null){this._eventCallBack=t,this._eventCustomData=e}doUpdateMotion(t,e){let i=!1;for(let r=this._motions.begin();r.notEqual(this._motions.end());){let s=r.ptr();if(null==s){r=this._motions.erase(r);continue}const a=s._motion;if(null==a){s.release(),s=null,r=this._motions.erase(r);continue}a.updateParameters(t,s,e),i=!0;const n=a.getFiredEvent(s.getLastCheckEventSeconds()-s.getStartTime(),e-s.getStartTime());for(let t=0;t<n.getSize();++t)this._eventCallBack(this,n.at(t),this._eventCustomData);s.setLastCheckEventSeconds(e),s.isFinished()?(s.release(),s=null,r=this._motions.erase(r)):(s.isTriggeredFadeOut()&&s.startFadeOut(s.getFadeOutSeconds(),e),r.preIncrement())}return i}}const ze=-1;var je;(t=>{t.CubismMotionQueueManager=Ue,t.InvalidMotionQueueEntryHandleValue=ze})(je||(je={}));class Ge extends Bt{constructor(t,e){var i,r;super(t,e),g(this,"expressionDataType","arraybuffer"),g(this,"queueManager",new Ue),g(this,"definitions"),this.definitions=null!=(r=null==(i=t.expressions)?void 0:i.filter(t=>!!t&&"string"==typeof t.File))?r:[],this.init()}isFinished(){return this.queueManager.isFinished()}getExpressionIndex(t){return this.definitions.findIndex(e=>e.Name===t)}getExpressionFile(t){return t.File}createExpression(t,e){return Te.create(t,t.byteLength)}_setExpression(t){return this.queueManager.startMotion(t,!1)}stopAllExpressions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.doUpdateMotion(t,e)}createDefaultExpression(){const t=(new TextEncoder).encode(JSON.stringify({FadeInTime:0,FadeOutTime:0,Parameters:[]})).buffer;return Te.create(t,t.byteLength)}}var Xe,He=(t=>(t[t.CubismMotionCurveTarget_Model=0]="CubismMotionCurveTarget_Model",t[t.CubismMotionCurveTarget_Parameter=1]="CubismMotionCurveTarget_Parameter",t[t.CubismMotionCurveTarget_PartOpacity=2]="CubismMotionCurveTarget_PartOpacity",t))(He||{}),qe=(t=>(t[t.CubismMotionSegmentType_Linear=0]="CubismMotionSegmentType_Linear",t[t.CubismMotionSegmentType_Bezier=1]="CubismMotionSegmentType_Bezier",t[t.CubismMotionSegmentType_Stepped=2]="CubismMotionSegmentType_Stepped",t[t.CubismMotionSegmentType_InverseStepped=3]="CubismMotionSegmentType_InverseStepped",t))(qe||{});class Ye{constructor(){this.time=0,this.value=0}}class We{constructor(){this.evaluate=null,this.basePointIndex=0,this.segmentType=0}}class Je{constructor(){this.type=0,this.segmentCount=0,this.baseSegmentIndex=0,this.fadeInTime=0,this.fadeOutTime=0}}class $e{constructor(){this.fireTime=0}}class Ze{constructor(){this.duration=0,this.loop=!1,this.curveCount=0,this.eventCount=0,this.fps=0,this.curves=new p,this.segments=new p,this.points=new p,this.events=new p}}(t=>{t.CubismMotionCurve=Je,t.CubismMotionCurveTarget=He,t.CubismMotionData=Ze,t.CubismMotionEvent=$e,t.CubismMotionPoint=Ye,t.CubismMotionSegment=We,t.CubismMotionSegmentType=qe})(Xe||(Xe={}));const Ke="Meta",Qe="Curves",ti="FadeInTime",ei="FadeOutTime",ii="Segments",ri="UserData";class si{constructor(t,e){this._json=Z.create(t,e)}release(){Z.delete(this._json)}getMotionDuration(){return this._json.getRoot().getValueByString(Ke).getValueByString("Duration").toFloat()}isMotionLoop(){return this._json.getRoot().getValueByString(Ke).getValueByString("Loop").toBoolean()}hasConsistency(){let t=!0;if(!this._json||!this._json.getRoot())return!1;const e=this._json.getRoot().getValueByString(Qe).getVector().getSize();let i=0,r=0;for(let s=0;s<e;++s)for(let t=0;t<this.getMotionCurveSegmentCount(s);){0==t&&(r+=1,t+=2);switch(this.getMotionCurveSegment(s,t)){case qe.CubismMotionSegmentType_Linear:r+=1,t+=3;break;case qe.CubismMotionSegmentType_Bezier:r+=3,t+=7;break;case qe.CubismMotionSegmentType_Stepped:case qe.CubismMotionSegmentType_InverseStepped:r+=1,t+=3;break;default:A(0)}++i}return e!=this.getMotionCurveCount()&&(N("The number of curves does not match the metadata."),t=!1),i!=this.getMotionTotalSegmentCount()&&(N("The number of segment does not match the metadata."),t=!1),r!=this.getMotionTotalPointCount()&&(N("The number of point does not match the metadata."),t=!1),t}getEvaluationOptionFlag(t){return 0==t&&this._json.getRoot().getValueByString(Ke).getValueByString("AreBeziersRestricted").toBoolean()}getMotionCurveCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("CurveCount").toInt()}getMotionFps(){return this._json.getRoot().getValueByString(Ke).getValueByString("Fps").toFloat()}getMotionTotalSegmentCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("TotalSegmentCount").toInt()}getMotionTotalPointCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("TotalPointCount").toInt()}isExistMotionFadeInTime(){return!this._json.getRoot().getValueByString(Ke).getValueByString(ti).isNull()}isExistMotionFadeOutTime(){return!this._json.getRoot().getValueByString(Ke).getValueByString(ei).isNull()}getMotionFadeInTime(){return this._json.getRoot().getValueByString(Ke).getValueByString(ti).toFloat()}getMotionFadeOutTime(){return this._json.getRoot().getValueByString(Ke).getValueByString(ei).toFloat()}getMotionCurveTarget(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString("Target").getRawString()}getMotionCurveId(t){return ct.getIdManager().getId(this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString("Id").getRawString())}isExistMotionCurveFadeInTime(t){return!this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ti).isNull()}isExistMotionCurveFadeOutTime(t){return!this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ei).isNull()}getMotionCurveFadeInTime(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ti).toFloat()}getMotionCurveFadeOutTime(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ei).toFloat()}getMotionCurveSegmentCount(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ii).getVector().getSize()}getMotionCurveSegment(t,e){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ii).getValueByIndex(e).toFloat()}getEventCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("UserDataCount").toInt()}getTotalEventValueSize(){return this._json.getRoot().getValueByString(Ke).getValueByString("TotalUserDataSize").toInt()}getEventTime(t){return this._json.getRoot().getValueByString(ri).getValueByIndex(t).getValueByString("Time").toFloat()}getEventValue(t){return new b(this._json.getRoot().getValueByString(ri).getValueByIndex(t).getValueByString("Value").getRawString())}}var ai,ni=(t=>(t[t.EvaluationOptionFlag_AreBeziersRistricted=0]="EvaluationOptionFlag_AreBeziersRistricted",t))(ni||{});(t=>{t.CubismMotionJson=si})(ai||(ai={}));const oi="Opacity";function li(t,e,i){const r=new Ye;return r.time=t.time+(e.time-t.time)*i,r.value=t.value+(e.value-t.value)*i,r}function ui(t,e){let i=(e-t[0].time)/(t[1].time-t[0].time);return i<0&&(i=0),t[0].value+(t[1].value-t[0].value)*i}function hi(t,e){let i=(e-t[0].time)/(t[3].time-t[0].time);i<0&&(i=0);const r=li(t[0],t[1],i),s=li(t[1],t[2],i),a=li(t[2],t[3],i),n=li(r,s,i),o=li(s,a,i);return li(n,o,i).value}function di(t,e){const i=e,r=t[0].time,s=t[3].time,a=t[1].time,n=t[2].time,o=s-3*n+3*a-r,l=3*n-6*a+3*r,u=3*a-3*r,h=r-i,d=we.cardanoAlgorithmForBezier(o,l,u,h),g=li(t[0],t[1],d),c=li(t[1],t[2],d),m=li(t[2],t[3],d),p=li(g,c,d),_=li(c,m,d);return li(p,_,d).value}function gi(t,e){return t[0].value}function ci(t,e){return t[1].value}function mi(t,e,i,r,s){const a=t.curves.at(e);let n=-1;const o=a.baseSegmentIndex+a.segmentCount;let l=0;for(let h=a.baseSegmentIndex;h<o;++h)if(l=t.segments.at(h).basePointIndex+(t.segments.at(h).segmentType==qe.CubismMotionSegmentType_Bezier?3:1),t.points.at(l).time>i){n=h;break}if(-1==n)return r&&i<s?function(t,e,i,r,s,a){const n=[new Ye,new Ye];{const e=t.points.at(r);n[0].time=e.time,n[0].value=e.value}{const e=t.points.at(i);n[1].time=a,n[1].value=e.value}switch(t.segments.at(e).segmentType){case qe.CubismMotionSegmentType_Linear:case qe.CubismMotionSegmentType_Bezier:default:return ui(n,s);case qe.CubismMotionSegmentType_Stepped:return gi(n);case qe.CubismMotionSegmentType_InverseStepped:return ci(n)}}(t,o-1,t.segments.at(a.baseSegmentIndex).basePointIndex,l,i,s):t.points.at(l).value;const u=t.segments.at(n);return u.evaluate(t.points.get(u.basePointIndex),i)}class pi extends Ee{constructor(){super(),this._motionBehavior=1,this._sourceFrameRate=30,this._loopDurationSeconds=-1,this._isLoop=!1,this._isLoopFadeIn=!0,this._lastWeight=0,this._motionData=null,this._modelCurveIdEyeBlink=null,this._modelCurveIdLipSync=null,this._modelCurveIdOpacity=null,this._eyeBlinkParameterIds=null,this._lipSyncParameterIds=null,this._modelOpacity=1,this._debugMode=!1}static create(t,e,i,r,s=!1){const a=new pi;return a.parse(t,e,s),a._motionData?(a._sourceFrameRate=a._motionData.fps,a._loopDurationSeconds=a._motionData.duration,a._onFinishedMotion=i,a._onBeganMotion=r,a):(gt(a),null)}doUpdateParameters(t,e,i,r){null==this._modelCurveIdEyeBlink&&(this._modelCurveIdEyeBlink=ct.getIdManager().getId("EyeBlink")),null==this._modelCurveIdLipSync&&(this._modelCurveIdLipSync=ct.getIdManager().getId("LipSync")),null==this._modelCurveIdOpacity&&(this._modelCurveIdOpacity=ct.getIdManager().getId(oi)),1===this._motionBehavior&&this._previousLoopState!==this._isLoop&&(this.adjustEndTime(r),this._previousLoopState=this._isLoop);let s=e-r.getStartTime();s<0&&(s=0);let a=Number.MAX_VALUE,n=Number.MAX_VALUE;const o=64;let l=0,u=0;this._eyeBlinkParameterIds.getSize()>o&&O("too many eye blink targets : {0}",this._eyeBlinkParameterIds.getSize()),this._lipSyncParameterIds.getSize()>o&&O("too many lip sync targets : {0}",this._lipSyncParameterIds.getSize());const h=this._fadeInSeconds<=0?1:we.getEasingSine((e-r.getFadeInStartTime())/this._fadeInSeconds),d=this._fadeOutSeconds<=0||r.getEndTime()<0?1:we.getEasingSine((r.getEndTime()-e)/this._fadeOutSeconds);let g,c,m,p=s,_=this._motionData.duration;const f=1===this._motionBehavior&&this._isLoop;if(this._isLoop)for(1===this._motionBehavior&&(_+=1/this._motionData.fps);p>_;)p-=_;const y=this._motionData.curves;for(c=0;c<this._motionData.curveCount&&y.at(c).type==He.CubismMotionCurveTarget_Model;++c)g=mi(this._motionData,c,p,f,_),y.at(c).id==this._modelCurveIdEyeBlink?n=g:y.at(c).id==this._modelCurveIdLipSync?a=g:y.at(c).id==this._modelCurveIdOpacity&&(this._modelOpacity=g,t.setModelOapcity(this.getModelOpacityValue()));for(;c<this._motionData.curveCount&&y.at(c).type==He.CubismMotionCurveTarget_Parameter;++c){if(m=t.getParameterIndex(y.at(c).id),-1==m)continue;const s=t.getParameterValueByIndex(m);if(g=mi(this._motionData,c,p,f,_),n!=Number.MAX_VALUE)for(let t=0;t<this._eyeBlinkParameterIds.getSize()&&t<o;++t)if(this._eyeBlinkParameterIds.at(t)==y.at(c).id){g*=n,u|=1<<t;break}if(a!=Number.MAX_VALUE)for(let t=0;t<this._lipSyncParameterIds.getSize()&&t<o;++t)if(this._lipSyncParameterIds.at(t)==y.at(c).id){g+=a,l|=1<<t;break}let x;if(t.isRepeat(m)&&(g=t.getParameterRepeatValue(m,g)),y.at(c).fadeInTime<0&&y.at(c).fadeOutTime<0)x=s+(g-s)*i;else{let t,i;t=y.at(c).fadeInTime<0?h:0==y.at(c).fadeInTime?1:we.getEasingSine((e-r.getFadeInStartTime())/y.at(c).fadeInTime),i=y.at(c).fadeOutTime<0?d:0==y.at(c).fadeOutTime||r.getEndTime()<0?1:we.getEasingSine((r.getEndTime()-e)/y.at(c).fadeOutTime);x=s+(g-s)*(this._weight*t*i)}t.setParameterValueByIndex(m,x,1)}if(n!=Number.MAX_VALUE)for(let x=0;x<this._eyeBlinkParameterIds.getSize()&&x<o;++x){const e=t.getParameterValueById(this._eyeBlinkParameterIds.at(x));if(u>>x&1)continue;const r=e+(n-e)*i;t.setParameterValueById(this._eyeBlinkParameterIds.at(x),r)}if(a!=Number.MAX_VALUE)for(let x=0;x<this._lipSyncParameterIds.getSize()&&x<o;++x){const e=t.getParameterValueById(this._lipSyncParameterIds.at(x));if(l>>x&1)continue;const r=e+(a-e)*i;t.setParameterValueById(this._lipSyncParameterIds.at(x),r)}for(;c<this._motionData.curveCount&&y.at(c).type==He.CubismMotionCurveTarget_PartOpacity;++c)m=t.getParameterIndex(y.at(c).id),-1!=m&&(g=mi(this._motionData,c,p,f,_),t.setParameterValueByIndex(m,g));s>=_&&(this._isLoop?this.updateForNextLoop(r,e,p):(this._onFinishedMotion&&this._onFinishedMotion(this),r.setIsFinished(!0))),this._lastWeight=i}setIsLoop(t){N("setIsLoop() is a deprecated function. Please use setLoop()."),this._isLoop=t}isLoop(){return N("isLoop() is a deprecated function. Please use getLoop()."),this._isLoop}setIsLoopFadeIn(t){N("setIsLoopFadeIn() is a deprecated function. Please use setLoopFadeIn()."),this._isLoopFadeIn=t}isLoopFadeIn(){return N("isLoopFadeIn() is a deprecated function. Please use getLoopFadeIn()."),this._isLoopFadeIn}setMotionBehavior(t){this._motionBehavior=t}getMotionBehavior(){return this._motionBehavior}getDuration(){return this._isLoop?-1:this._loopDurationSeconds}getLoopDuration(){return this._loopDurationSeconds}setParameterFadeInTime(t,e){const i=this._motionData.curves;for(let r=0;r<this._motionData.curveCount;++r)if(t==i.at(r).id)return void(i.at(r).fadeInTime=e)}setParameterFadeOutTime(t,e){const i=this._motionData.curves;for(let r=0;r<this._motionData.curveCount;++r)if(t==i.at(r).id)return void(i.at(r).fadeOutTime=e)}getParameterFadeInTime(t){const e=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==e.at(i).id)return e.at(i).fadeInTime;return-1}getParameterFadeOutTime(t){const e=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==e.at(i).id)return e.at(i).fadeOutTime;return-1}setEffectIds(t,e){this._eyeBlinkParameterIds=t,this._lipSyncParameterIds=e}release(){this._motionData=void 0,this._motionData=null}updateForNextLoop(t,e,i){switch(this._motionBehavior){case 1:default:t.setStartTime(e-i),this._isLoopFadeIn&&t.setFadeInStartTime(e-i),null!=this._onFinishedMotion&&this._onFinishedMotion(this);break;case 0:t.setStartTime(e),this._isLoopFadeIn&&t.setFadeInStartTime(e)}}parse(t,e,i=!1){let r=new si(t,e);if(!r)return r.release(),void(r=void 0);if(i){if(!r.hasConsistency())return r.release(),void U("Inconsistent motion3.json.")}this._motionData=new Ze,this._motionData.duration=r.getMotionDuration(),this._motionData.loop=r.isMotionLoop(),this._motionData.curveCount=r.getMotionCurveCount(),this._motionData.fps=r.getMotionFps(),this._motionData.eventCount=r.getEventCount();const s=r.getEvaluationOptionFlag(ni.EvaluationOptionFlag_AreBeziersRistricted);r.isExistMotionFadeInTime()?this._fadeInSeconds=r.getMotionFadeInTime()<0?1:r.getMotionFadeInTime():this._fadeInSeconds=1,r.isExistMotionFadeOutTime()?this._fadeOutSeconds=r.getMotionFadeOutTime()<0?1:r.getMotionFadeOutTime():this._fadeOutSeconds=1,this._motionData.curves.updateSize(this._motionData.curveCount,Je,!0),this._motionData.segments.updateSize(r.getMotionTotalSegmentCount(),We,!0),this._motionData.points.updateSize(r.getMotionTotalPointCount(),Ye,!0),this._motionData.events.updateSize(this._motionData.eventCount,$e,!0);let a=0,n=0;for(let o=0;o<this._motionData.curveCount;++o){"Model"==r.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=He.CubismMotionCurveTarget_Model:"Parameter"==r.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=He.CubismMotionCurveTarget_Parameter:"PartOpacity"==r.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=He.CubismMotionCurveTarget_PartOpacity:N('Warning : Unable to get segment type from Curve! The number of "CurveCount" may be incorrect!'),this._motionData.curves.at(o).id=r.getMotionCurveId(o),this._motionData.curves.at(o).baseSegmentIndex=n,this._motionData.curves.at(o).fadeInTime=r.isExistMotionCurveFadeInTime(o)?r.getMotionCurveFadeInTime(o):-1,this._motionData.curves.at(o).fadeOutTime=r.isExistMotionCurveFadeOutTime(o)?r.getMotionCurveFadeOutTime(o):-1;for(let t=0;t<r.getMotionCurveSegmentCount(o);){0==t?(this._motionData.segments.at(n).basePointIndex=a,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+1),a+=1,t+=2):this._motionData.segments.at(n).basePointIndex=a-1;switch(r.getMotionCurveSegment(o,t)){case qe.CubismMotionSegmentType_Linear:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_Linear,this._motionData.segments.at(n).evaluate=ui,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case qe.CubismMotionSegmentType_Bezier:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_Bezier,this._motionData.segments.at(n).evaluate=s?hi:di,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),this._motionData.points.at(a+1).time=r.getMotionCurveSegment(o,t+3),this._motionData.points.at(a+1).value=r.getMotionCurveSegment(o,t+4),this._motionData.points.at(a+2).time=r.getMotionCurveSegment(o,t+5),this._motionData.points.at(a+2).value=r.getMotionCurveSegment(o,t+6),a+=3,t+=7;break;case qe.CubismMotionSegmentType_Stepped:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_Stepped,this._motionData.segments.at(n).evaluate=gi,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case qe.CubismMotionSegmentType_InverseStepped:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_InverseStepped,this._motionData.segments.at(n).evaluate=ci,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;default:A(0)}++this._motionData.curves.at(o).segmentCount,++n}}for(let o=0;o<r.getEventCount();++o)this._motionData.events.at(o).fireTime=r.getEventTime(o),this._motionData.events.at(o).value=r.getEventValue(o);r.release(),r=void 0,r=null}getFiredEvent(t,e){this._firedEventValues.updateSize(0);for(let i=0;i<this._motionData.eventCount;++i)this._motionData.events.at(i).fireTime>t&&this._motionData.events.at(i).fireTime<=e&&this._firedEventValues.pushBack(new b(this._motionData.events.at(i).value.s));return this._firedEventValues}isExistModelOpacity(){for(let t=0;t<this._motionData.curveCount;t++){const e=this._motionData.curves.at(t);if(e.type==He.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(oi))return!0}return!1}getModelOpacityIndex(){if(this.isExistModelOpacity())for(let t=0;t<this._motionData.curveCount;t++){const e=this._motionData.curves.at(t);if(e.type==He.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(oi))return t}return-1}getModelOpacityId(t){if(-1!=t){const e=this._motionData.curves.at(t);if(e.type==He.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(oi))return ct.getIdManager().getId(e.id.getString().s)}return null}getModelOpacityValue(){return this._modelOpacity}setDebugMode(t){this._debugMode=t}}var _i;function fi(t,e,i){const r=t.startMotion(i,!1),s=t.getCubismMotionQueueEntry(r);if(!s)return!1;s.setStartTime(0),s.setFadeInStartTime(0);const a=i.getDuration(),n=s.getStartTime()+a;return i.doUpdateParameters(e.coreModel,n,1,s),s.setIsFinished(!0),!0}(t=>{t.CubismMotion=pi})(_i||(_i={}));class yi extends Ot{constructor(t){var e;super(t),g(this,"definitions"),g(this,"groups",{idle:"Idle"}),g(this,"motionDataType","arraybuffer"),g(this,"queueManager",new Ue),g(this,"expressionManager"),g(this,"eyeBlinkIds"),g(this,"lipSyncIds",["ParamMouthOpenY"]),this.definitions=null!=(e=t.settings.motions)?e:{},this.eyeBlinkIds=t.settings.getEyeBlinkParameters()||[];const i=t.settings.getLipSyncParameters();(null==i?void 0:i.length)&&(this.lipSyncIds=i),this.init(t.options)}init(t){super.init(t),this.settings.expressions&&(this.expressionManager=new Ge(this.settings,t)),this.queueManager.setEventCallback((t,e)=>{const i="string"==typeof e?e:"number"==typeof e?String(e):e&&"object"==typeof e?e.s:"undefined";this.emit("motion:"+i)})}isFinished(){return this.queueManager.isFinished()}_startMotion(t,e,i){if(t.setFinishedMotionHandler(e),i&&i.length>0){const e=t._motionData.curves,r=function(t){if(xi(t))return new p;return[]}(e),s=Ci(e);for(let t=0;t<s;t++){const s=Mi(e,t);if(!s)continue;const a=Si(s);a&&i.includes(a)||vi(r,s)}t._motionData.curves=r,t._motionData.curveCount=Ci(r)}return this.queueManager.stopAllMotions(),this.queueManager.startMotion(t,!1)}_stopAllMotions(){this.queueManager.stopAllMotions()}createMotion(t,e,i){const r=!!this.parent.options.checkMotionConsistency,s=pi.create(t,t.byteLength,void 0,void 0,r),a=new si(t,t.byteLength),n=(e===this.groups.idle?pt.idleMotionFadingDuration:pt.motionFadingDuration)/1e3;return void 0===a.getMotionFadeInTime()&&s.setFadeInTime(i.FadeInTime>0?i.FadeInTime:n),void 0===a.getMotionFadeOutTime()&&s.setFadeOutTime(i.FadeOutTime>0?i.FadeOutTime:n),s.setEffectIds(this.createIdVector(this.eyeBlinkIds),this.createIdVector(this.lipSyncIds)),s}getMotionFile(t){return t.File}getMotionName(t){return t.File}getSoundFile(t){return t.Sound}updateParameters(t,e){return this.queueManager.doUpdateMotion(t,e)}destroy(){super.destroy(),this.queueManager.release(),this.queueManager=void 0}motionLastFrame(t,e){return c(this,arguments,function*(t,e,{expression:i}={}){const r=yield this.getMotionAndApplyExpression(t,e,i);return!!r&&(this.playing=!0,fi(this.queueManager,this.parent,r),this.playing=!1,!0)})}createIdVector(t){const e=new p,i=ct.getIdManager();for(const r of t)e.pushBack(i.getId(r));return e}}function xi(t){return"function"==typeof t.pushBack}function Ci(t){return xi(t)?t.getSize():t.length}function Mi(t,e){return xi(t)?t.at(e):t[e]}function Si(t){if(!t||"object"!=typeof t)return;const e=t.id;return"string"==typeof e?e:e&&"function"==typeof e.getString?e.getString().s:void 0}function vi(t,e){xi(t)?t.pushBack(e):t.push(e)}class bi extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"manager"),g(this,"settings"),g(this,"state",new Lt),g(this,"playing",!1),g(this,"destroyed",!1),g(this,"parent"),this.settings=t.settings,this.tag=`ParallelMotionManager(${this.settings.name})`,this.state.tag=this.tag,this.manager=t.motionManager,this.parent=t}startMotion(t,e){return c(this,arguments,function*(t,e,i=Vt.NORMAL,r=[]){var s;if(!this.state.reserve(t,e,i))return!1;const a=null==(s=this.manager.definitions[t])?void 0:s[e];if(!a)return!1;const n=yield this.manager.loadMotion(t,e);return!!this.state.start(n,t,e,i)&&(_t.log(this.tag,"Start motion:",this.getMotionName(a)),this.emit("motionStart",t,e,void 0),this.playing=!0,this._startMotion(n,void 0,r),!0)})}startRandomMotion(t,e){return c(this,null,function*(){var i;const r=this.manager.definitions[t];if(null==r?void 0:r.length){const s=[],a=null!=(i=this.manager.motionGroups[t])?i:[];for(let e=0;e<r.length;e++)null===a[e]||this.state.isActive(t,e)||s.push(e);if(s.length){const i=s[Math.floor(Math.random()*s.length)];return this.startMotion(t,i,e)}}return!1})}stopAllMotions(){this._stopAllMotions(),this.state.reset()}update(t,e){return this.isFinished()&&(this.playing&&(this.playing=!1,this.emit("motionFinish")),this.state.complete()),this.updateParameters(t,e)}destroy(){this.destroyed=!0,this.emit("destroy"),this.stopAllMotions()}}class Pi extends bi{constructor(t){super(t),g(this,"queueManager",new Ue),this.init()}init(){this.queueManager.setEventCallback((t,e)=>{const i="string"==typeof e?e:"number"==typeof e?String(e):e&&"object"==typeof e?e.s:"undefined";this.emit("motion:"+i)})}isFinished(){return this.queueManager.isFinished()}_startMotion(t,e,i){if(t.setFinishedMotionHandler(e),i&&i.length>0){const e=t._motionData.curves,r=function(t){if(Bi(t))return new p;return[]}(e),s=wi(e);for(let t=0;t<s;t++){const s=Fi(e,t);if(!s)continue;const a=Ii(s);a&&i.includes(a)||Ei(r,s)}t._motionData.curves=r,t._motionData.curveCount=wi(r)}return this.queueManager.stopAllMotions(),this.queueManager.startMotion(t,!1)}_stopAllMotions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.doUpdateMotion(t,e)}getMotionName(t){return t.File}destroy(){super.destroy(),this.queueManager.release(),this.queueManager=void 0}playMotionLastFrame(t,e){return c(this,null,function*(){var i;if(!this.state.reserve(t,e,Vt.FORCE))return!1;const r=null==(i=this.manager.definitions[t])?void 0:i[e];if(!r)return!1;const s=yield this.manager.loadMotion(t,e);return!!this.state.start(s,t,e,Vt.FORCE)&&(_t.log(this.tag,"Start motion:",this.getMotionName(r)),this.emit("motionStart",t,e,void 0),this.playing=!0,this.queueManager.stopAllMotions(),fi(this.queueManager,this.parent,s)?(this.playing=!1,!0):(this.playing=!1,!1))})}}function Bi(t){return"function"==typeof t.pushBack}function wi(t){return Bi(t)?t.getSize():t.length}function Fi(t,e){return Bi(t)?t.at(e):t[e]}function Ii(t){if(!t||"object"!=typeof t)return;const e=t.id;return"string"==typeof e?e:e&&"function"==typeof e.getString?e.getString().s:void 0}function Ei(t,e){Bi(t)?t.pushBack(e):t.push(e)}const Vi=Object.freeze({HitAreaPrefix:"HitArea",HitAreaHead:"Head",HitAreaBody:"Body",PartsIdCore:"Parts01Core",PartsArmPrefix:"Parts01Arm_",PartsArmLPrefix:"Parts01ArmL_",PartsArmRPrefix:"Parts01ArmR_",ParamAngleX:"ParamAngleX",ParamAngleY:"ParamAngleY",ParamAngleZ:"ParamAngleZ",ParamEyeLOpen:"ParamEyeLOpen",ParamEyeLSmile:"ParamEyeLSmile",ParamEyeROpen:"ParamEyeROpen",ParamEyeRSmile:"ParamEyeRSmile",ParamEyeBallX:"ParamEyeBallX",ParamEyeBallY:"ParamEyeBallY",ParamEyeBallForm:"ParamEyeBallForm",ParamBrowLY:"ParamBrowLY",ParamBrowRY:"ParamBrowRY",ParamBrowLX:"ParamBrowLX",ParamBrowRX:"ParamBrowRX",ParamBrowLAngle:"ParamBrowLAngle",ParamBrowRAngle:"ParamBrowRAngle",ParamBrowLForm:"ParamBrowLForm",ParamBrowRForm:"ParamBrowRForm",ParamMouthForm:"ParamMouthForm",ParamMouthOpenY:"ParamMouthOpenY",ParamCheek:"ParamCheek",ParamBodyAngleX:"ParamBodyAngleX",ParamBodyAngleY:"ParamBodyAngleY",ParamBodyAngleZ:"ParamBodyAngleZ",ParamBreath:"ParamBreath",ParamArmLA:"ParamArmLA",ParamArmRA:"ParamArmRA",ParamArmLB:"ParamArmLB",ParamArmRB:"ParamArmRB",ParamHandL:"ParamHandL",ParamHandR:"ParamHandR",ParamHairFront:"ParamHairFront",ParamHairSide:"ParamHairSide",ParamHairBack:"ParamHairBack",ParamHairFluffy:"ParamHairFluffy",ParamShoulderY:"ParamShoulderY",ParamBustX:"ParamBustX",ParamBustY:"ParamBustY",ParamBaseX:"ParamBaseX",ParamBaseY:"ParamBaseY",ParamNONE:"NONE:"});var Li,Ri;(t=>{t.HitAreaBody=Vi.HitAreaBody,t.HitAreaHead=Vi.HitAreaHead,t.HitAreaPrefix=Vi.HitAreaPrefix,t.ParamAngleX=Vi.ParamAngleX,t.ParamAngleY=Vi.ParamAngleY,t.ParamAngleZ=Vi.ParamAngleZ,t.ParamArmLA=Vi.ParamArmLA,t.ParamArmLB=Vi.ParamArmLB,t.ParamArmRA=Vi.ParamArmRA,t.ParamArmRB=Vi.ParamArmRB,t.ParamBaseX=Vi.ParamBaseX,t.ParamBaseY=Vi.ParamBaseY,t.ParamBodyAngleX=Vi.ParamBodyAngleX,t.ParamBodyAngleY=Vi.ParamBodyAngleY,t.ParamBodyAngleZ=Vi.ParamBodyAngleZ,t.ParamBreath=Vi.ParamBreath,t.ParamBrowLAngle=Vi.ParamBrowLAngle,t.ParamBrowLForm=Vi.ParamBrowLForm,t.ParamBrowLX=Vi.ParamBrowLX,t.ParamBrowLY=Vi.ParamBrowLY,t.ParamBrowRAngle=Vi.ParamBrowRAngle,t.ParamBrowRForm=Vi.ParamBrowRForm,t.ParamBrowRX=Vi.ParamBrowRX,t.ParamBrowRY=Vi.ParamBrowRY,t.ParamBustX=Vi.ParamBustX,t.ParamBustY=Vi.ParamBustY,t.ParamCheek=Vi.ParamCheek,t.ParamEyeBallForm=Vi.ParamEyeBallForm,t.ParamEyeBallX=Vi.ParamEyeBallX,t.ParamEyeBallY=Vi.ParamEyeBallY,t.ParamEyeLOpen=Vi.ParamEyeLOpen,t.ParamEyeLSmile=Vi.ParamEyeLSmile,t.ParamEyeROpen=Vi.ParamEyeROpen,t.ParamEyeRSmile=Vi.ParamEyeRSmile,t.ParamHairBack=Vi.ParamHairBack,t.ParamHairFluffy=Vi.ParamHairFluffy,t.ParamHairFront=Vi.ParamHairFront,t.ParamHairSide=Vi.ParamHairSide,t.ParamHandL=Vi.ParamHandL,t.ParamHandR=Vi.ParamHandR,t.ParamMouthForm=Vi.ParamMouthForm,t.ParamMouthOpenY=Vi.ParamMouthOpenY,t.ParamNONE=Vi.ParamNONE,t.ParamShoulderY=Vi.ParamShoulderY,t.PartsArmLPrefix=Vi.PartsArmLPrefix,t.PartsArmPrefix=Vi.PartsArmPrefix,t.PartsArmRPrefix=Vi.PartsArmRPrefix,t.PartsIdCore=Vi.PartsIdCore})(Li||(Li={}));class Ti{static create(){return new Ti}static delete(t){}setParameters(t){this._breathParameters=t}getParameters(){return this._breathParameters}updateParameters(t,e){this._currentTime+=e;const i=2*this._currentTime*Math.PI;for(let r=0;r<this._breathParameters.getSize();++r){const e=this._breathParameters.at(r);t.addParameterValueById(e.parameterId,e.offset+e.peak*Math.sin(i/e.cycle),e.weight)}}constructor(){this._currentTime=0}}class Di{constructor(t,e,i,r,s){this.parameterId=null==t?null:t,this.offset=null==e?0:e,this.peak=null==i?0:i,this.cycle=null==r?0:r,this.weight=null==s?0:s}}(t=>{t.BreathParameterData=Di,t.CubismBreath=Ti})(Ri||(Ri={}));const Ai=class t{static create(e=null){return new t(e)}static delete(t){}setBlinkingInterval(t){this._blinkingIntervalSeconds=t}setBlinkingSetting(t,e,i){this._closingSeconds=t,this._closedSeconds=e,this._openingSeconds=i}setParameterIds(t){this._parameterIds=t}getParameterIds(){return this._parameterIds}updateParameters(e,i){let r;this._userTimeSeconds+=i;let s=0;switch(this._blinkingState){case 2:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closingSeconds,s>=1&&(s=1,this._blinkingState=3,this._stateStartTimeSeconds=this._userTimeSeconds),r=1-s;break;case 3:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closedSeconds,s>=1&&(this._blinkingState=4,this._stateStartTimeSeconds=this._userTimeSeconds),r=0;break;case 4:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._openingSeconds,s>=1&&(s=1,this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming()),r=s;break;case 1:this._nextBlinkingTime<this._userTimeSeconds&&(this._blinkingState=2,this._stateStartTimeSeconds=this._userTimeSeconds),r=1;break;default:this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming(),r=1}t.CloseIfZero||(r=-r);for(let t=0;t<this._parameterIds.getSize();++t)e.setParameterValueById(this._parameterIds.at(t),r)}constructor(t){if(this._blinkingState=0,this._nextBlinkingTime=0,this._stateStartTimeSeconds=0,this._blinkingIntervalSeconds=4,this._closingSeconds=.1,this._closedSeconds=.05,this._openingSeconds=.15,this._userTimeSeconds=0,this._parameterIds=new p,null!=t)for(let e=0;e<t.getEyeBlinkParameterCount();++e)this._parameterIds.pushBack(t.getEyeBlinkParameterId(e))}determinNextBlinkingTiming(){const t=Math.random();return this._userTimeSeconds+t*(2*this._blinkingIntervalSeconds-1)}};Ai.CloseIfZero=!0;let Oi=Ai;var ki,Ni=(t=>(t[t.EyeState_First=0]="EyeState_First",t[t.EyeState_Interval=1]="EyeState_Interval",t[t.EyeState_Closing=2]="EyeState_Closing",t[t.EyeState_Closed=3]="EyeState_Closed",t[t.EyeState_Opening=4]="EyeState_Opening",t))(Ni||{});(t=>{t.CubismEyeBlink=Oi,t.EyeState=Ni})(ki||(ki={}));class Ui{constructor(t){this._renderTextureCount=0,this._clippingMaskBufferSize=256,this._clippingContextListForMask=new p,this._clippingContextListForDraw=new p,this._channelColors=new p,this._tmpBoundsOnModel=new F,this._tmpMatrix=new w,this._tmpMatrixForMask=new w,this._tmpMatrixForDraw=new w,this._clippingContexttConstructor=t;let e=new L;e.r=1,e.g=0,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new L,e.r=0,e.g=1,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new L,e.r=0,e.g=0,e.b=1,e.a=0,this._channelColors.pushBack(e),e=new L,e.r=0,e.g=0,e.b=0,e.a=1,this._channelColors.pushBack(e)}release(){for(let t=0;t<this._clippingContextListForMask.getSize();t++)this._clippingContextListForMask.at(t)&&(this._clippingContextListForMask.at(t).release(),this._clippingContextListForMask.set(t,void 0)),this._clippingContextListForMask.set(t,null);this._clippingContextListForMask=null;for(let t=0;t<this._clippingContextListForDraw.getSize();t++)this._clippingContextListForDraw.set(t,null);this._clippingContextListForDraw=null;for(let t=0;t<this._channelColors.getSize();t++)this._channelColors.set(t,null);this._channelColors=null,null!=this._clearedFrameBufferFlags&&this._clearedFrameBufferFlags.clear(),this._clearedFrameBufferFlags=null}initialize(t,e){e%1!=0&&(N("The number of render textures must be specified as an integer. The decimal point is rounded down and corrected to an integer."),e=~~e),e<1&&N("The number of render textures must be an integer greater than or equal to 1. Set the number of render textures to 1."),this._renderTextureCount=e<1?1:e,this._clearedFrameBufferFlags=new p(this._renderTextureCount);for(let i=0;i<t.getDrawableCount();i++){if(t.getDrawableMaskCounts()[i]<=0){this._clippingContextListForDraw.pushBack(null);continue}let e=this.findSameClip(t.getDrawableMasks()[i],t.getDrawableMaskCounts()[i]);null==e&&(e=new this._clippingContexttConstructor(this,t.getDrawableMasks()[i],t.getDrawableMaskCounts()[i]),this._clippingContextListForMask.pushBack(e)),e.addClippedDrawable(i),this._clippingContextListForDraw.pushBack(e)}}findSameClip(t,e){for(let i=0;i<this._clippingContextListForMask.getSize();i++){const r=this._clippingContextListForMask.at(i),s=r._clippingIdCount;if(s!=e)continue;let a=0;for(let e=0;e<s;e++){const i=r._clippingIdList[e];for(let e=0;e<s;e++)if(t[e]==i){a++;break}}if(a==s)return r}return null}setupMatrixForHighPrecision(t,e){let i=0;for(let r=0;r<this._clippingContextListForMask.getSize();r++){const e=this._clippingContextListForMask.at(r);this.calcClippedDrawTotalBounds(t,e),e._isUsing&&i++}if(i>0){if(this.setupLayoutBounds(0),this._clearedFrameBufferFlags.getSize()!=this._renderTextureCount){this._clearedFrameBufferFlags.clear();for(let t=0;t<this._renderTextureCount;t++)this._clearedFrameBufferFlags.pushBack(!1)}else for(let t=0;t<this._renderTextureCount;t++)this._clearedFrameBufferFlags.set(t,!1);for(let i=0;i<this._clippingContextListForMask.getSize();i++){const r=this._clippingContextListForMask.at(i),s=r._allClippedDrawRect,a=r._layoutBounds,n=.05;let o=0,l=0;const u=t.getPixelsPerUnit(),h=r.getClippingManager().getClippingMaskBufferSize(),d=a.width*h,g=a.height*h;this._tmpBoundsOnModel.setRect(s),this._tmpBoundsOnModel.width*u>d?(this._tmpBoundsOnModel.expand(s.width*n,0),o=a.width/this._tmpBoundsOnModel.width):o=u/d,this._tmpBoundsOnModel.height*u>g?(this._tmpBoundsOnModel.expand(0,s.height*n),l=a.height/this._tmpBoundsOnModel.height):l=u/g,this.createMatrixForMask(e,a,o,l),r._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),r._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray())}}}createMatrixForMask(t,e,i,r){this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(e.x,e.y),this._tmpMatrix.scaleRelative(i,r),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForMask.setMatrix(this._tmpMatrix.getArray()),this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(e.x,e.y*(t?-1:1)),this._tmpMatrix.scaleRelative(i,r*(t?-1:1)),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForDraw.setMatrix(this._tmpMatrix.getArray())}setupLayoutBounds(t){const e=this._renderTextureCount<=1?36:32*this._renderTextureCount;if(t<=0||t>e){t>e&&U("not supported mask count : {0}\n[Details] render texture count : {1}, mask count : {2}",t-e,this._renderTextureCount,t);for(let t=0;t<this._clippingContextListForMask.getSize();t++){const e=this._clippingContextListForMask.at(t);e._layoutChannelIndex=0,e._layoutBounds.x=0,e._layoutBounds.y=0,e._layoutBounds.width=1,e._layoutBounds.height=1,e._bufferIndex=0}return}const i=this._renderTextureCount<=1?9:8;let r=t/this._renderTextureCount;const s=t%this._renderTextureCount;r=Math.ceil(r);let a=r/4;const n=r%4;a=~~a;let o=0;for(let l=0;l<this._renderTextureCount;l++)for(let r=0;r<4;r++){let u=a+(r<n?1:0);if(r==n+(a<1?-1:0)&&s>0&&(u-=l<s?0:1),0==u);else if(1==u){const t=this._clippingContextListForMask.at(o++);t._layoutChannelIndex=r,t._layoutBounds.x=0,t._layoutBounds.y=0,t._layoutBounds.width=1,t._layoutBounds.height=1,t._bufferIndex=l}else if(2==u)for(let t=0;t<u;t++){let e=t%2;e=~~e;const i=this._clippingContextListForMask.at(o++);i._layoutChannelIndex=r,i._layoutBounds.x=.5*e,i._layoutBounds.y=0,i._layoutBounds.width=.5,i._layoutBounds.height=1,i._bufferIndex=l}else if(u<=4)for(let t=0;t<u;t++){let e=t%2,i=t/2;e=~~e,i=~~i;const s=this._clippingContextListForMask.at(o++);s._layoutChannelIndex=r,s._layoutBounds.x=.5*e,s._layoutBounds.y=.5*i,s._layoutBounds.width=.5,s._layoutBounds.height=.5,s._bufferIndex=l}else if(u<=i)for(let t=0;t<u;t++){let e=t%3,i=t/3;e=~~e,i=~~i;const s=this._clippingContextListForMask.at(o++);s._layoutChannelIndex=r,s._layoutBounds.x=e/3,s._layoutBounds.y=i/3,s._layoutBounds.width=1/3,s._layoutBounds.height=1/3,s._bufferIndex=l}else{U("not supported mask count : {0}\n[Details] render texture count : {1}, mask count : {2}",t-e,this._renderTextureCount,t);for(let t=0;t<u;t++){const t=this._clippingContextListForMask.at(o++);t._layoutChannelIndex=0,t._layoutBounds.x=0,t._layoutBounds.y=0,t._layoutBounds.width=1,t._layoutBounds.height=1,t._bufferIndex=0}}}}calcClippedDrawTotalBounds(t,e){let i=Number.MAX_VALUE,r=Number.MAX_VALUE,s=Number.MIN_VALUE,a=Number.MIN_VALUE;const n=e._clippedDrawableIndexList.length;for(let o=0;o<n;o++){const n=e._clippedDrawableIndexList[o],l=t.getDrawableVertexCount(n),u=t.getDrawableVertices(n);let h=Number.MAX_VALUE,d=Number.MAX_VALUE,g=-Number.MAX_VALUE,c=-Number.MAX_VALUE;const m=l*dt.vertexStep;for(let t=dt.vertexOffset;t<m;t+=dt.vertexStep){const e=u[t],i=u[t+1];e<h&&(h=e),e>g&&(g=e),i<d&&(d=i),i>c&&(c=i)}if(h!=Number.MAX_VALUE)if(h<i&&(i=h),d<r&&(r=d),g>s&&(s=g),c>a&&(a=c),i==Number.MAX_VALUE)e._allClippedDrawRect.x=0,e._allClippedDrawRect.y=0,e._allClippedDrawRect.width=0,e._allClippedDrawRect.height=0,e._isUsing=!1;else{e._isUsing=!0;const t=s-i,n=a-r;e._allClippedDrawRect.x=i,e._allClippedDrawRect.y=r,e._allClippedDrawRect.width=t,e._allClippedDrawRect.height=n}}}getClippingContextListForDraw(){return this._clippingContextListForDraw}getClippingMaskBufferSize(){return this._clippingMaskBufferSize}getRenderTextureCount(){return this._renderTextureCount}getChannelFlagAsColor(t){return this._channelColors.at(t)}setClippingMaskBufferSize(t){this._clippingMaskBufferSize=t}}let zi;class ji{constructor(){this._shaderSets=new p}release(){this.releaseShaderProgram()}setupShaderProgramForDraw(t,e,i){let r,s,a,n;t.isPremultipliedAlpha()||U("NoPremultipliedAlpha is not allowed"),0==this._shaderSets.getSize()&&this.generateShaders();const o=null!=t.getClippingContextBufferForDraw(),l=e.getDrawableInvertedMaskBit(i),u=o?l?2:1:0;let h;switch(e.getDrawableBlendMode(i)){case V.CubismBlendMode_Normal:default:h=this._shaderSets.at(1+u),r=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,a=this.gl.ONE,n=this.gl.ONE_MINUS_SRC_ALPHA;break;case V.CubismBlendMode_Additive:h=this._shaderSets.at(4+u),r=this.gl.ONE,s=this.gl.ONE,a=this.gl.ZERO,n=this.gl.ONE;break;case V.CubismBlendMode_Multiplicative:h=this._shaderSets.at(7+u),r=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,a=this.gl.ZERO,n=this.gl.ONE}this.gl.useProgram(h.shaderProgram),null==t._bufferData.vertex&&(t._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.vertex);const d=e.getDrawableVertices(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,d,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(h.attributePositionLocation),this.gl.vertexAttribPointer(h.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),null==t._bufferData.uv&&(t._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.uv);const g=e.getDrawableVertexUvs(i);if(this.gl.bufferData(this.gl.ARRAY_BUFFER,g,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(h.attributeTexCoordLocation),this.gl.vertexAttribPointer(h.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),o){this.gl.activeTexture(this.gl.TEXTURE1);const e=t.getClippingContextBufferForDraw().getClippingManager().getColorBuffer().at(t.getClippingContextBufferForDraw()._bufferIndex);this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(h.samplerTexture1Location,1),this.gl.uniformMatrix4fv(h.uniformClipMatrixLocation,!1,t.getClippingContextBufferForDraw()._matrixForDraw.getArray());const i=t.getClippingContextBufferForDraw()._layoutChannelIndex,r=t.getClippingContextBufferForDraw().getClippingManager().getChannelFlagAsColor(i);this.gl.uniform4f(h.uniformChannelFlagLocation,r.r,r.g,r.b,r.a)}const c=e.getDrawableTextureIndex(i),m=t.getBindedTextures().getValue(c);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,m),this.gl.uniform1i(h.samplerTexture0Location,0);const p=t.getMvpMatrix();this.gl.uniformMatrix4fv(h.uniformMatrixLocation,!1,p.getArray());const _=t.getModelColorWithOpacity(e.getDrawableOpacity(i)),f=e.getMultiplyColor(i),y=e.getScreenColor(i);this.gl.uniform4f(h.uniformBaseColorLocation,_.r,_.g,_.b,_.a),this.gl.uniform4f(h.uniformMultiplyColorLocation,f.r,f.g,f.b,f.a),this.gl.uniform4f(h.uniformScreenColorLocation,y.r,y.g,y.b,y.a),null==t._bufferData.index&&(t._bufferData.index=this.gl.createBuffer());const x=e.getDrawableVertexIndices(i);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t._bufferData.index),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,x,this.gl.DYNAMIC_DRAW),this.gl.blendFuncSeparate(r,s,a,n)}setupShaderProgramForMask(t,e,i){t.isPremultipliedAlpha()||U("NoPremultipliedAlpha is not allowed"),0==this._shaderSets.getSize()&&this.generateShaders();const r=this._shaderSets.at(0);this.gl.useProgram(r.shaderProgram),null==t._bufferData.vertex&&(t._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.vertex);const s=e.getDrawableVertices(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(r.attributePositionLocation),this.gl.vertexAttribPointer(r.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),null==t._bufferData.uv&&(t._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.uv);const a=e.getDrawableTextureIndex(i),n=t.getBindedTextures().getValue(a);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(r.samplerTexture0Location,0),null==t._bufferData.uv&&(t._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.uv);const o=e.getDrawableVertexUvs(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(r.attributeTexCoordLocation),this.gl.vertexAttribPointer(r.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),t.getClippingContextBufferForMask();const l=t.getClippingContextBufferForMask()._layoutChannelIndex,u=t.getClippingContextBufferForMask().getClippingManager().getChannelFlagAsColor(l);this.gl.uniform4f(r.uniformChannelFlagLocation,u.r,u.g,u.b,u.a),this.gl.uniformMatrix4fv(r.uniformClipMatrixLocation,!1,t.getClippingContextBufferForMask()._matrixForMask.getArray());const h=t.getClippingContextBufferForMask()._layoutBounds;this.gl.uniform4f(r.uniformBaseColorLocation,2*h.x-1,2*h.y-1,2*h.getRight()-1,2*h.getBottom()-1);const d=e.getMultiplyColor(i),g=e.getScreenColor(i);this.gl.uniform4f(r.uniformMultiplyColorLocation,d.r,d.g,d.b,d.a),this.gl.uniform4f(r.uniformScreenColorLocation,g.r,g.g,g.b,g.a);const c=this.gl.ZERO,m=this.gl.ONE_MINUS_SRC_COLOR,p=this.gl.ZERO,_=this.gl.ONE_MINUS_SRC_ALPHA;null==t._bufferData.index&&(t._bufferData.index=this.gl.createBuffer());const f=e.getDrawableVertexIndices(i);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t._bufferData.index),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,f,this.gl.DYNAMIC_DRAW),this.gl.blendFuncSeparate(c,m,p,_)}releaseShaderProgram(){for(let t=0;t<this._shaderSets.getSize();t++)this.gl.deleteProgram(this._shaderSets.at(t).shaderProgram),this._shaderSets.at(t).shaderProgram=0,this._shaderSets.set(t,void 0),this._shaderSets.set(t,null)}generateShaders(){for(let t=0;t<10;t++)this._shaderSets.pushBack(new Xi);this._shaderSets.at(0).shaderProgram=this.loadShaderProgram(qi,Yi),this._shaderSets.at(1).shaderProgram=this.loadShaderProgram(Wi,$i),this._shaderSets.at(2).shaderProgram=this.loadShaderProgram(Ji,Zi),this._shaderSets.at(3).shaderProgram=this.loadShaderProgram(Ji,Ki),this._shaderSets.at(4).shaderProgram=this._shaderSets.at(1).shaderProgram,this._shaderSets.at(5).shaderProgram=this._shaderSets.at(2).shaderProgram,this._shaderSets.at(6).shaderProgram=this._shaderSets.at(3).shaderProgram,this._shaderSets.at(7).shaderProgram=this._shaderSets.at(1).shaderProgram,this._shaderSets.at(8).shaderProgram=this._shaderSets.at(2).shaderProgram,this._shaderSets.at(9).shaderProgram=this._shaderSets.at(3).shaderProgram,this._shaderSets.at(0).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(0).shaderProgram,"a_position"),this._shaderSets.at(0).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(0).shaderProgram,"a_texCoord"),this._shaderSets.at(0).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"s_texture0"),this._shaderSets.at(0).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_clipMatrix"),this._shaderSets.at(0).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_channelFlag"),this._shaderSets.at(0).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_baseColor"),this._shaderSets.at(0).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_multiplyColor"),this._shaderSets.at(0).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_screenColor"),this._shaderSets.at(1).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(1).shaderProgram,"a_position"),this._shaderSets.at(1).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(1).shaderProgram,"a_texCoord"),this._shaderSets.at(1).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"s_texture0"),this._shaderSets.at(1).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_matrix"),this._shaderSets.at(1).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_baseColor"),this._shaderSets.at(1).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_multiplyColor"),this._shaderSets.at(1).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_screenColor"),this._shaderSets.at(2).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(2).shaderProgram,"a_position"),this._shaderSets.at(2).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(2).shaderProgram,"a_texCoord"),this._shaderSets.at(2).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"s_texture0"),this._shaderSets.at(2).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"s_texture1"),this._shaderSets.at(2).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_matrix"),this._shaderSets.at(2).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_clipMatrix"),this._shaderSets.at(2).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_channelFlag"),this._shaderSets.at(2).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_baseColor"),this._shaderSets.at(2).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_multiplyColor"),this._shaderSets.at(2).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_screenColor"),this._shaderSets.at(3).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(3).shaderProgram,"a_position"),this._shaderSets.at(3).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(3).shaderProgram,"a_texCoord"),this._shaderSets.at(3).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"s_texture0"),this._shaderSets.at(3).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"s_texture1"),this._shaderSets.at(3).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_matrix"),this._shaderSets.at(3).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_clipMatrix"),this._shaderSets.at(3).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_channelFlag"),this._shaderSets.at(3).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_baseColor"),this._shaderSets.at(3).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_multiplyColor"),this._shaderSets.at(3).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_screenColor"),this._shaderSets.at(4).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(4).shaderProgram,"a_position"),this._shaderSets.at(4).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(4).shaderProgram,"a_texCoord"),this._shaderSets.at(4).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"s_texture0"),this._shaderSets.at(4).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_matrix"),this._shaderSets.at(4).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_baseColor"),this._shaderSets.at(4).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_multiplyColor"),this._shaderSets.at(4).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_screenColor"),this._shaderSets.at(5).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(5).shaderProgram,"a_position"),this._shaderSets.at(5).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(5).shaderProgram,"a_texCoord"),this._shaderSets.at(5).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"s_texture0"),this._shaderSets.at(5).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"s_texture1"),this._shaderSets.at(5).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_matrix"),this._shaderSets.at(5).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_clipMatrix"),this._shaderSets.at(5).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_channelFlag"),this._shaderSets.at(5).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_baseColor"),this._shaderSets.at(5).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_multiplyColor"),this._shaderSets.at(5).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_screenColor"),this._shaderSets.at(6).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(6).shaderProgram,"a_position"),this._shaderSets.at(6).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(6).shaderProgram,"a_texCoord"),this._shaderSets.at(6).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"s_texture0"),this._shaderSets.at(6).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"s_texture1"),this._shaderSets.at(6).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_matrix"),this._shaderSets.at(6).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_clipMatrix"),this._shaderSets.at(6).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_channelFlag"),this._shaderSets.at(6).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_baseColor"),this._shaderSets.at(6).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_multiplyColor"),this._shaderSets.at(6).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_screenColor"),this._shaderSets.at(7).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(7).shaderProgram,"a_position"),this._shaderSets.at(7).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(7).shaderProgram,"a_texCoord"),this._shaderSets.at(7).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"s_texture0"),this._shaderSets.at(7).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_matrix"),this._shaderSets.at(7).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_baseColor"),this._shaderSets.at(7).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_multiplyColor"),this._shaderSets.at(7).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_screenColor"),this._shaderSets.at(8).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(8).shaderProgram,"a_position"),this._shaderSets.at(8).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(8).shaderProgram,"a_texCoord"),this._shaderSets.at(8).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"s_texture0"),this._shaderSets.at(8).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"s_texture1"),this._shaderSets.at(8).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_matrix"),this._shaderSets.at(8).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_clipMatrix"),this._shaderSets.at(8).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_channelFlag"),this._shaderSets.at(8).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_baseColor"),this._shaderSets.at(8).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_multiplyColor"),this._shaderSets.at(8).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_screenColor"),this._shaderSets.at(9).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(9).shaderProgram,"a_position"),this._shaderSets.at(9).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(9).shaderProgram,"a_texCoord"),this._shaderSets.at(9).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"s_texture0"),this._shaderSets.at(9).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"s_texture1"),this._shaderSets.at(9).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_matrix"),this._shaderSets.at(9).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_clipMatrix"),this._shaderSets.at(9).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_channelFlag"),this._shaderSets.at(9).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_baseColor"),this._shaderSets.at(9).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_multiplyColor"),this._shaderSets.at(9).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_screenColor")}loadShaderProgram(t,e){let i=this.gl.createProgram(),r=this.compileShaderSource(this.gl.VERTEX_SHADER,t);if(!r)return U("Vertex shader compile error!"),0;let s=this.compileShaderSource(this.gl.FRAGMENT_SHADER,e);if(!s)return U("Vertex shader compile error!"),0;this.gl.attachShader(i,r),this.gl.attachShader(i,s),this.gl.linkProgram(i);return this.gl.getProgramParameter(i,this.gl.LINK_STATUS)?(this.gl.deleteShader(r),this.gl.deleteShader(s),i):(U("Failed to link program: {0}",i),this.gl.deleteShader(r),r=0,this.gl.deleteShader(s),s=0,i&&(this.gl.deleteProgram(i),i=0),0)}compileShaderSource(t,e){const i=e,r=this.gl.createShader(t);if(this.gl.shaderSource(r,i),this.gl.compileShader(r),!r){const t=this.gl.getShaderInfoLog(r);U("Shader compile log: {0} ",t)}return this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS)?r:(this.gl.deleteShader(r),null)}setGl(t){this.gl=t}}class Gi{static getInstance(){return null==zi&&(zi=new Gi),zi}static deleteInstance(){zi&&(zi.release(),zi=null)}constructor(){this._shaderMap=new H}release(){for(const t=this._shaderMap.begin();t.notEqual(this._shaderMap.end());t.preIncrement())t.ptr().second.release();this._shaderMap.clear()}getShader(t){return this._shaderMap.getValue(t)}setGlContext(t){if(!this._shaderMap.isExist(t)){const e=new ji;e.setGl(t),this._shaderMap.setValue(t,e)}}}class Xi{}var Hi=(t=>(t[t.ShaderNames_SetupMask=0]="ShaderNames_SetupMask",t[t.ShaderNames_NormalPremultipliedAlpha=1]="ShaderNames_NormalPremultipliedAlpha",t[t.ShaderNames_NormalMaskedPremultipliedAlpha=2]="ShaderNames_NormalMaskedPremultipliedAlpha",t[t.ShaderNames_NomralMaskedInvertedPremultipliedAlpha=3]="ShaderNames_NomralMaskedInvertedPremultipliedAlpha",t[t.ShaderNames_AddPremultipliedAlpha=4]="ShaderNames_AddPremultipliedAlpha",t[t.ShaderNames_AddMaskedPremultipliedAlpha=5]="ShaderNames_AddMaskedPremultipliedAlpha",t[t.ShaderNames_AddMaskedPremultipliedAlphaInverted=6]="ShaderNames_AddMaskedPremultipliedAlphaInverted",t[t.ShaderNames_MultPremultipliedAlpha=7]="ShaderNames_MultPremultipliedAlpha",t[t.ShaderNames_MultMaskedPremultipliedAlpha=8]="ShaderNames_MultMaskedPremultipliedAlpha",t[t.ShaderNames_MultMaskedPremultipliedAlphaInverted=9]="ShaderNames_MultMaskedPremultipliedAlphaInverted",t))(Hi||{});const qi="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;varying vec4 v_myPos;uniform mat4 u_clipMatrix;void main(){ gl_Position = u_clipMatrix * a_position; v_myPos = u_clipMatrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",Yi="precision mediump float;varying vec2 v_texCoord;varying vec4 v_myPos;uniform vec4 u_baseColor;uniform vec4 u_channelFlag;uniform sampler2D s_texture0;void main(){ float isInside = step(u_baseColor.x, v_myPos.x/v_myPos.w) * step(u_baseColor.y, v_myPos.y/v_myPos.w) * step(v_myPos.x/v_myPos.w, u_baseColor.z) * step(v_myPos.y/v_myPos.w, u_baseColor.w); gl_FragColor = u_channelFlag * texture2D(s_texture0, v_texCoord).a * isInside;}",Wi="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;uniform mat4 u_matrix;void main(){ gl_Position = u_matrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",Ji="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform mat4 u_matrix;uniform mat4 u_clipMatrix;void main(){ gl_Position = u_matrix * a_position; v_clipPos = u_clipMatrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",$i="precision mediump float;varying vec2 v_texCoord;uniform vec4 u_baseColor;uniform sampler2D s_texture0;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 color = texColor * u_baseColor; gl_FragColor = vec4(color.rgb, color.a);}",Zi="precision mediump float;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform vec4 u_baseColor;uniform vec4 u_channelFlag;uniform sampler2D s_texture0;uniform sampler2D s_texture1;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 col_formask = texColor * u_baseColor; vec4 clipMask = (1.0 - texture2D(s_texture1, v_clipPos.xy / v_clipPos.w)) * u_channelFlag; float maskVal = clipMask.r + clipMask.g + clipMask.b + clipMask.a; col_formask = col_formask * maskVal; gl_FragColor = col_formask;}",Ki="precision mediump float;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform sampler2D s_texture0;uniform sampler2D s_texture1;uniform vec4 u_channelFlag;uniform vec4 u_baseColor;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 col_formask = texColor * u_baseColor; vec4 clipMask = (1.0 - texture2D(s_texture1, v_clipPos.xy / v_clipPos.w)) * u_channelFlag; float maskVal = clipMask.r + clipMask.g + clipMask.b + clipMask.a; col_formask = col_formask * (1.0 - maskVal); gl_FragColor = col_formask;}";var Qi;let tr,er;(t=>{t.CubismShaderSet=Xi,t.CubismShader_WebGL=ji,t.CubismShaderManager_WebGL=Gi,t.ShaderNames=Hi})(Qi||(Qi={}));class ir extends Ui{getMaskRenderTexture(){if(this._maskTexture&&null!=this._maskTexture.textures)this._maskTexture.frameNo=this._currentFrameNo;else{null!=this._maskRenderTextures&&this._maskRenderTextures.clear(),this._maskRenderTextures=new p,null!=this._maskColorBuffers&&this._maskColorBuffers.clear(),this._maskColorBuffers=new p;const t=this._clippingMaskBufferSize;for(let e=0;e<this._renderTextureCount;e++)this._maskColorBuffers.pushBack(this.gl.createTexture()),this.gl.bindTexture(this.gl.TEXTURE_2D,this._maskColorBuffers.at(e)),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,t,t,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this._maskRenderTextures.pushBack(this.gl.createFramebuffer()),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._maskRenderTextures.at(e)),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this._maskColorBuffers.at(e),0);this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,er),this._maskTexture=new rr(this._currentFrameNo,this._maskRenderTextures)}return this._maskTexture.textures}setGL(t){this.gl=t}constructor(){super(sr)}setupClippingContext(t,e){this._currentFrameNo++;let i=0;for(let r=0;r<this._clippingContextListForMask.getSize();r++){const e=this._clippingContextListForMask.at(r);this.calcClippedDrawTotalBounds(t,e),e._isUsing&&i++}if(i>0){this.gl.viewport(0,0,this._clippingMaskBufferSize,this._clippingMaskBufferSize),this._currentMaskRenderTexture=this.getMaskRenderTexture().at(0),e.preDraw(),this.setupLayoutBounds(i),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentMaskRenderTexture),this._clearedFrameBufferFlags.getSize()!=this._renderTextureCount&&(this._clearedFrameBufferFlags.clear(),this._clearedFrameBufferFlags=new p(this._renderTextureCount));for(let t=0;t<this._clearedFrameBufferFlags.getSize();t++)this._clearedFrameBufferFlags.set(t,!1);for(let i=0;i<this._clippingContextListForMask.getSize();i++){const r=this._clippingContextListForMask.at(i),s=r._allClippedDrawRect,a=r._layoutBounds,n=.05;let o=0,l=0;const u=this.getMaskRenderTexture().at(r._bufferIndex);this._currentMaskRenderTexture!=u&&(this._currentMaskRenderTexture=u,e.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentMaskRenderTexture)),this._tmpBoundsOnModel.setRect(s),this._tmpBoundsOnModel.expand(s.width*n,s.height*n),o=a.width/this._tmpBoundsOnModel.width,l=a.height/this._tmpBoundsOnModel.height,this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(a.x,a.y),this._tmpMatrix.scaleRelative(o,l),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForMask.setMatrix(this._tmpMatrix.getArray()),this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(a.x,a.y),this._tmpMatrix.scaleRelative(o,l),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForDraw.setMatrix(this._tmpMatrix.getArray()),r._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),r._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray());const h=r._clippingIdCount;for(let i=0;i<h;i++){const s=r._clippingIdList[i];t.getDrawableDynamicFlagVertexPositionsDidChange(s)&&(e.setIsCulling(0!=t.getDrawableCulling(s)),this._clearedFrameBufferFlags.at(r._bufferIndex)||(this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this._clearedFrameBufferFlags.set(r._bufferIndex,!0)),e.setClippingContextBufferForMask(r),e.drawMeshWebGL(t,s))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,er),e.setClippingContextBufferForMask(null),this.gl.viewport(tr[0],tr[1],tr[2],tr[3])}}getColorBuffer(){return this._maskColorBuffers}getClippingMaskCount(){return this._clippingContextListForMask.getSize()}}class rr{constructor(t,e){this.frameNo=t,this.textures=e}}class sr extends R{constructor(t,e,i){super(e,i),this._owner=t}getClippingManager(){return this._owner}setGl(t){this._owner.setGL(t)}}class ar{setGlEnable(t,e){e?this.gl.enable(t):this.gl.disable(t)}setGlEnableVertexAttribArray(t,e){e?this.gl.enableVertexAttribArray(t):this.gl.disableVertexAttribArray(t)}save(){null!=this.gl?(this._lastArrayBufferBinding=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING),this._lastElementArrayBufferBinding=this.gl.getParameter(this.gl.ELEMENT_ARRAY_BUFFER_BINDING),this._lastProgram=this.gl.getParameter(this.gl.CURRENT_PROGRAM),this._lastActiveTexture=this.gl.getParameter(this.gl.ACTIVE_TEXTURE),this.gl.activeTexture(this.gl.TEXTURE1),this._lastTexture1Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this.gl.activeTexture(this.gl.TEXTURE0),this._lastTexture0Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this._lastVertexAttribArrayEnabled[0]=this.gl.getVertexAttrib(0,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[1]=this.gl.getVertexAttrib(1,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[2]=this.gl.getVertexAttrib(2,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[3]=this.gl.getVertexAttrib(3,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastScissorTest=this.gl.isEnabled(this.gl.SCISSOR_TEST),this._lastStencilTest=this.gl.isEnabled(this.gl.STENCIL_TEST),this._lastDepthTest=this.gl.isEnabled(this.gl.DEPTH_TEST),this._lastCullFace=this.gl.isEnabled(this.gl.CULL_FACE),this._lastBlend=this.gl.isEnabled(this.gl.BLEND),this._lastFrontFace=this.gl.getParameter(this.gl.FRONT_FACE),this._lastColorMask=this.gl.getParameter(this.gl.COLOR_WRITEMASK),this._lastBlending[0]=this.gl.getParameter(this.gl.BLEND_SRC_RGB),this._lastBlending[1]=this.gl.getParameter(this.gl.BLEND_DST_RGB),this._lastBlending[2]=this.gl.getParameter(this.gl.BLEND_SRC_ALPHA),this._lastBlending[3]=this.gl.getParameter(this.gl.BLEND_DST_ALPHA),this._lastFBO=this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING),this._lastViewport=this.gl.getParameter(this.gl.VIEWPORT)):U("'gl' is null. WebGLRenderingContext is required.\nPlease call 'CubimRenderer_WebGL.startUp' function.")}restore(){null!=this.gl?(this.gl.useProgram(this._lastProgram),this.setGlEnableVertexAttribArray(0,this._lastVertexAttribArrayEnabled[0]),this.setGlEnableVertexAttribArray(1,this._lastVertexAttribArrayEnabled[1]),this.setGlEnableVertexAttribArray(2,this._lastVertexAttribArrayEnabled[2]),this.setGlEnableVertexAttribArray(3,this._lastVertexAttribArrayEnabled[3]),this.setGlEnable(this.gl.SCISSOR_TEST,this._lastScissorTest),this.setGlEnable(this.gl.STENCIL_TEST,this._lastStencilTest),this.setGlEnable(this.gl.DEPTH_TEST,this._lastDepthTest),this.setGlEnable(this.gl.CULL_FACE,this._lastCullFace),this.setGlEnable(this.gl.BLEND,this._lastBlend),this.gl.frontFace(this._lastFrontFace),this.gl.colorMask(this._lastColorMask[0],this._lastColorMask[1],this._lastColorMask[2],this._lastColorMask[3]),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._lastArrayBufferBinding),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._lastElementArrayBufferBinding),this.gl.activeTexture(this.gl.TEXTURE1),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture1Binding2D),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture0Binding2D),this.gl.activeTexture(this._lastActiveTexture),this.gl.blendFuncSeparate(this._lastBlending[0],this._lastBlending[1],this._lastBlending[2],this._lastBlending[3])):U("'gl' is null. WebGLRenderingContext is required.\nPlease call 'CubimRenderer_WebGL.startUp' function.")}setGl(t){this.gl=t}constructor(){this._lastVertexAttribArrayEnabled=new Array(4),this._lastColorMask=new Array(4),this._lastBlending=new Array(4),this._lastViewport=new Array(4)}}class nr extends I{initialize(t,e=1){t.isUsingMasking()&&(this._clippingManager=new ir,this._clippingManager.initialize(t,e)),this._sortedDrawableIndexList.resize(t.getDrawableCount(),0),super.initialize(t)}bindTexture(t,e){this._textures.setValue(t,e)}getBindedTextures(){return this._textures}setClippingMaskBufferSize(t){if(!this._model.isUsingMasking())return;const e=this._clippingManager.getRenderTextureCount();this._clippingManager.release(),this._clippingManager=void 0,this._clippingManager=null,this._clippingManager=new ir,this._clippingManager.setClippingMaskBufferSize(t),this._clippingManager.initialize(this.getModel(),e)}getClippingMaskBufferSize(){return this._model.isUsingMasking()?this._clippingManager.getClippingMaskBufferSize():-1}getRenderTextureCount(){return this._model.isUsingMasking()?this._clippingManager.getRenderTextureCount():-1}constructor(){super(),this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._rendererProfile=new ar,this.firstDraw=!0,this._textures=new H,this._sortedDrawableIndexList=new p,this._bufferData={vertex:WebGLBuffer=null,uv:WebGLBuffer=null,index:WebGLBuffer=null},this._textures.prepareCapacity(32,!0)}release(){this._clippingManager&&(this._clippingManager.release(),this._clippingManager=void 0,this._clippingManager=null),null!=this.gl&&(this.gl.deleteBuffer(this._bufferData.vertex),this._bufferData.vertex=null,this.gl.deleteBuffer(this._bufferData.uv),this._bufferData.uv=null,this.gl.deleteBuffer(this._bufferData.index),this._bufferData.index=null,this._bufferData=null,this._textures=null)}doDrawModel(){if(null==this.gl)return void U("'gl' is null. WebGLRenderingContext is required.\nPlease call 'CubimRenderer_WebGL.startUp' function.");null!=this._clippingManager&&(this.preDraw(),this.isUsingHighPrecisionMask()?this._clippingManager.setupMatrixForHighPrecision(this.getModel(),!1):this._clippingManager.setupClippingContext(this.getModel(),this)),this.preDraw();const t=this.getModel().getDrawableCount(),e=this.getModel().getDrawableRenderOrders();for(let i=0;i<t;++i){const t=e[i];this._sortedDrawableIndexList.set(t,i)}for(let i=0;i<t;++i){const t=this._sortedDrawableIndexList.at(i);if(!this.getModel().getDrawableDynamicFlagIsVisible(t))continue;const e=null!=this._clippingManager?this._clippingManager.getClippingContextListForDraw().at(t):null;if(null!=e&&this.isUsingHighPrecisionMask()){e._isUsing&&(this.gl.viewport(0,0,this._clippingManager.getClippingMaskBufferSize(),this._clippingManager.getClippingMaskBufferSize()),this.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e.getClippingManager().getMaskRenderTexture().at(e._bufferIndex)),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{const t=e._clippingIdCount;for(let i=0;i<t;i++){const t=e._clippingIdList[i];this._model.getDrawableDynamicFlagVertexPositionsDidChange(t)&&(this.setIsCulling(0!=this._model.getDrawableCulling(t)),this.setClippingContextBufferForMask(e),this.drawMeshWebGL(this._model,t))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,er),this.setClippingContextBufferForMask(null),this.gl.viewport(tr[0],tr[1],tr[2],tr[3]),this.preDraw()}this.setClippingContextBufferForDraw(e),this.setIsCulling(this.getModel().getDrawableCulling(t)),this.drawMeshWebGL(this._model,t)}}drawMeshWebGL(t,e){this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW),this.isGeneratingMask()?Gi.getInstance().getShader(this.gl).setupShaderProgramForMask(this,t,e):Gi.getInstance().getShader(this.gl).setupShaderProgramForDraw(this,t,e);{const i=t.getDrawableVertexIndexCount(e);this.gl.drawElements(this.gl.TRIANGLES,i,this.gl.UNSIGNED_SHORT,0)}this.gl.useProgram(null),this.setClippingContextBufferForDraw(null),this.setClippingContextBufferForMask(null)}saveProfile(){this._rendererProfile.save()}restoreProfile(){this._rendererProfile.restore()}static doStaticRelease(){Gi.deleteInstance()}setRenderState(t,e){er=t,tr=e}preDraw(){if(this.firstDraw&&(this.firstDraw=!1),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.disable(this.gl.STENCIL_TEST),this.gl.disable(this.gl.DEPTH_TEST),this.gl.frontFace(this.gl.CW),this.gl.enable(this.gl.BLEND),this.gl.colorMask(!0,!0,!0,!0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.getAnisotropy()>0&&this._extension)for(let t=0;t<this._textures.getSize();++t)this.gl.bindTexture(this.gl.TEXTURE_2D,this._textures.getValue(t)),this.gl.texParameterf(this.gl.TEXTURE_2D,this._extension.TEXTURE_MAX_ANISOTROPY_EXT,this.getAnisotropy())}setClippingContextBufferForMask(t){this._clippingContextBufferForMask=t}getClippingContextBufferForMask(){return this._clippingContextBufferForMask}setClippingContextBufferForDraw(t){this._clippingContextBufferForDraw=t}getClippingContextBufferForDraw(){return this._clippingContextBufferForDraw}isGeneratingMask(){return null!=this.getClippingContextBufferForMask()}startUp(t){this.gl=t,this._clippingManager&&this._clippingManager.setGL(t),Gi.getInstance().setGlContext(t),this._rendererProfile.setGl(t),this._extension=this.gl.getExtension("EXT_texture_filter_anisotropic")||this.gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this.gl.getExtension("MOZ_EXT_texture_filter_anisotropic")}}var or;I.staticRelease=()=>{nr.doStaticRelease()},(t=>{t.CubismClippingContext=sr,t.CubismClippingManager_WebGL=ir,t.CubismRenderTextureResource=rr,t.CubismRenderer_WebGL=nr})(or||(or={}));const lr=new w;function ur(t){if(!t.isUsingMasking())return!1;const e=function(t){var e,i;const r=t.getDrawableMaskCounts(),s=t.getDrawableMasks(),a=new Set,n=t.getDrawableCount();let o=0,l=0,u=0,h=0;for(let d=0;d<n;d++){const n=t.getDrawableVertexCount(d),g=null!=(e=r[d])?e:0;if(h+=n,g<=0)continue;o++,u+=n,l=Math.max(l,g);const c=Array.from(null!=(i=s[d])?i:[]).slice(0,g).sort((t,e)=>t-e).join(",");a.add(c)}return{maskedDrawableCount:o,uniqueMaskSetCount:a.size,maxMasksPerDrawable:l,maskedVertexCount:u,totalVertexCount:h}}(t),i=e.totalVertexCount>0?e.maskedVertexCount/e.totalVertexCount:0;return e.uniqueMaskSetCount>16||e.maskedDrawableCount>64||e.maxMasksPerDrawable>=3||e.maskedVertexCount>4096||i>=.5&&e.maskedDrawableCount>24}class hr extends Ut{constructor(t,i,r){super(),g(this,"settings"),g(this,"options"),g(this,"coreModel"),g(this,"motionManager"),g(this,"parallelMotionManager"),g(this,"lipSync",!0),g(this,"breath",Ti.create()),g(this,"eyeBlink"),g(this,"renderer",new nr),g(this,"idManager"),g(this,"idParamAngleX"),g(this,"idParamAngleY"),g(this,"idParamAngleZ"),g(this,"idParamEyeBallX"),g(this,"idParamEyeBallY"),g(this,"idParamBodyAngleX"),g(this,"idParamBreath"),g(this,"idParamMouthForm"),g(this,"pixelsPerUnit",1),g(this,"modelTransform",new e.Matrix),this.coreModel=t,this.settings=i,this.options=Object.assign({},{breathDepth:1,lipSyncGain:1.5,lipSyncWeight:.4},r),this.idManager=ct.getIdManager(),this.idParamAngleX=this.getIdSafe(Vi.ParamAngleX),this.idParamAngleY=this.getIdSafe(Vi.ParamAngleY),this.idParamAngleZ=this.getIdSafe(Vi.ParamAngleZ),this.idParamEyeBallX=this.getIdSafe(Vi.ParamEyeBallX),this.idParamEyeBallY=this.getIdSafe(Vi.ParamEyeBallY),this.idParamBodyAngleX=this.getIdSafe(Vi.ParamBodyAngleX),this.idParamBreath=this.getIdSafe(Vi.ParamBreath),this.idParamMouthForm=this.getIdSafe(Vi.ParamMouthForm),this.motionManager=new yi(this),this.parallelMotionManager=[],this.init()}init(){var t;super.init();const e=this.settings.getEyeBlinkParameters();if(e.length)if(this.isCubismModelSetting(this.settings))this.eyeBlink=Oi.create(this.settings);else{const i=new p;for(const t of e)i.pushBack(this.idManager.getId(t));const r=Oi.create();null==(t=r.setParameterIds)||t.call(r,i),this.eyeBlink=r}const i=new p;var r,s;i.pushBack(new Di(this.idParamAngleX,0,15*this.options.breathDepth,6.5345,.5)),i.pushBack(new Di(this.idParamAngleY,0,8*this.options.breathDepth,3.5345,.5)),i.pushBack(new Di(this.idParamAngleZ,0,10*this.options.breathDepth,5.5345,.5)),i.pushBack(new Di(this.idParamBodyAngleX,0,4*this.options.breathDepth,15.5345,.5)),i.pushBack(new Di(this.idParamBreath,0,.5,3.2345,.5)),this.breath.setParameters(i),this.renderer.initialize(this.coreModel,function(t){var e;if(!t.isUsingMasking())return 1;const i=t.getDrawableMaskCounts(),r=t.getDrawableMasks(),s=new Set;for(let n=0;n<t.getDrawableCount();n++){const t=i[n];if(!t||t<=0)continue;const a=Array.from(null!=(e=r[n])?e:[]).slice(0,t).sort((t,e)=>t-e).join(",");s.add(a)}const a=s.size;return a<=36?1:Math.ceil(a/32)}(this.coreModel)),this.renderer.useHighPrecisionMask((r=this.coreModel,"boolean"==typeof(s=this.options.useHighPrecisionMask)?s:ur(r))),this.renderer.setIsPremultipliedAlpha(!0)}getIdSafe(t){return this.idManager.getId(null!=t?t:"")}getSize(){return[this.coreModel.getModel().canvasinfo.CanvasWidth,this.coreModel.getModel().canvasinfo.CanvasHeight]}getLayout(){const t={},e=this.settings.layout;if(e)for(const[i,r]of Object.entries(e)){t[i.charAt(0).toLowerCase()+i.slice(1)]=r}return t}setupLayout(){super.setupLayout(),this.pixelsPerUnit=this.coreModel.getModel().canvasinfo.PixelsPerUnit,this.modelTransform.scale(this.pixelsPerUnit,this.pixelsPerUnit).translate(this.originalWidth/2,this.originalHeight/2)}updateWebGLContext(t,e){this.renderer.firstDraw=!0,this.renderer._bufferData={vertex:null,uv:null,index:null},this.renderer.startUp(t),this.renderer._clippingManager&&(this.renderer._clippingManager._currentFrameNo=e),Gi.getInstance().setGlContext(t)}bindTexture(t,e){this.renderer.bindTexture(t,e)}getHitAreaDefs(){var t,e,i;const r=this.settings.json;return kt(null!=(i=null!=(e=null!=(t=this.settings.hitAreas)?t:r.HitAreas)?e:r.hitAreas)?i:r.hit_areas,t=>this.coreModel.getDrawableIndex(this.idManager.getId(t)))}getDrawableIDs(){const t=this.coreModel.getDrawableCount(),e=[];for(let i=0;i<t;i++)e.push(this.coreModel.getDrawableId(i).getString().s);return e}getDrawableIndex(t){return this.coreModel.getDrawableIndex(this.idManager.getId(t))}getDrawableVertices(t){if("string"==typeof t){const e=t;if(-1===(t=this.getDrawableIndex(e)))throw new TypeError("Unable to find drawable ID: "+e)}const e=this.coreModel.getDrawableVertices(t).slice();for(let i=0;i<e.length;i+=2)e[i]=e[i]*this.pixelsPerUnit+this.originalWidth/2,e[i+1]=-e[i+1]*this.pixelsPerUnit+this.originalHeight/2;return e}updateTransform(t){this.drawingMatrix.copyFrom(this.modelTransform).prepend(this.localTransform).prepend(t)}update(t,e){var i,r,s,a,n;super.update(t,e),t/=1e3,e/=1e3;const o=this.coreModel,l=this.updateMotions(o,e);if(o.saveParameters(),null==(i=this.motionManager.expressionManager)||i.update(o,e),l||null==(s=null==(r=this.eyeBlink)?void 0:r.updateParameters)||s.call(r,o,t),this.updateFocus(),this.updateNaturalMovements(1e3*t,1e3*e),this.lipSync&&this.motionManager.currentAudio){let t=this.motionManager.mouthSync()*this.options.lipSyncGain;t=Math.pow(t,1.15);t=ft(t,t>0?.1:0,1),this.motionManager.lipSyncIds.forEach(e=>{o.addParameterValueById(this.getIdSafe(e),t,this.options.lipSyncWeight)})}null==(a=this.physics)||a.evaluate(o,t),null==(n=this.pose)||n.updateParameters(o,t),this.emit("beforeModelUpdate"),o.update(),o.loadParameters()}updateFocus(){this.coreModel.addParameterValueById(this.idParamEyeBallX,this.focusController.x),this.coreModel.addParameterValueById(this.idParamEyeBallY,this.focusController.y),this.coreModel.addParameterValueById(this.idParamAngleX,30*this.focusController.x),this.coreModel.addParameterValueById(this.idParamAngleY,30*this.focusController.y),this.coreModel.addParameterValueById(this.idParamAngleZ,this.focusController.x*this.focusController.y*-30),this.coreModel.addParameterValueById(this.idParamBodyAngleX,10*this.focusController.x)}updateFacialEmotion(t){this.coreModel.addParameterValueById(this.idParamMouthForm,t)}updateNaturalMovements(t,e){var i;null==(i=this.breath)||i.updateParameters(this.coreModel,t/1e3)}draw(t){const e=this.drawingMatrix,i=lr.getArray();i[0]=e.a,i[1]=e.b,i[4]=-e.c,i[5]=-e.d,i[12]=e.tx,i[13]=e.ty,this.renderer.setMvpMatrix(lr);const r=t.getParameter(t.FRAMEBUFFER_BINDING);this.renderer.setRenderState(r,this.viewport),this.renderer.drawModel()}extendParallelMotionManager(t){for(;this.parallelMotionManager.length<t;)this.parallelMotionManager.push(new Pi(this))}destroy(){super.destroy(),this.renderer.release(),this.coreModel.release(),this.renderer=void 0,this.coreModel=void 0}isCubismModelSetting(t){return"function"==typeof t.getEyeBlinkParameterCount&&"function"==typeof t.getEyeBlinkParameterId}}class dr{}var gr;(t=>{t.ICubismModelSetting=dr})(gr||(gr={}));var cr,mr=(t=>(t[t.FrequestNode_Groups=0]="FrequestNode_Groups",t[t.FrequestNode_Moc=1]="FrequestNode_Moc",t[t.FrequestNode_Motions=2]="FrequestNode_Motions",t[t.FrequestNode_Expressions=3]="FrequestNode_Expressions",t[t.FrequestNode_Textures=4]="FrequestNode_Textures",t[t.FrequestNode_Physics=5]="FrequestNode_Physics",t[t.FrequestNode_Pose=6]="FrequestNode_Pose",t[t.FrequestNode_HitAreas=7]="FrequestNode_HitAreas",t))(mr||{});class pr extends dr{constructor(t,e){super(),this.version="Version",this.fileReferences="FileReferences",this.groups="Groups",this.layout="Layout",this.hitAreas="HitAreas",this.moc="Moc",this.textures="Textures",this.physics="Physics",this.pose="Pose",this.expressions="Expressions",this.motions="Motions",this.userData="UserData",this.name="Name",this.filePath="File",this.id="Id",this.ids="Ids",this.target="Target",this.idle="Idle",this.tapBody="TapBody",this.pinchIn="PinchIn",this.pinchOut="PinchOut",this.shake="Shake",this.flickHead="FlickHead",this.parameter="Parameter",this.soundPath="Sound",this.fadeInTime="FadeInTime",this.fadeOutTime="FadeOutTime",this.centerX="CenterX",this.centerY="CenterY",this.x="X",this.y="Y",this.width="Width",this.height="Height",this.lipSync="LipSync",this.eyeBlink="EyeBlink",this.initParameter="init_param",this.initPartsVisible="init_parts_visible",this.val="val",this._json=Z.create(t,e),this.getJson()&&(this._jsonValue=new p,this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.groups)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.moc)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.motions)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.expressions)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.textures)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.physics)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.pose)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.hitAreas)))}release(){Z.delete(this._json),this._jsonValue=null}getJson(){return this._json}getModelFileName(){return this.isExistModelFile()?this._jsonValue.at(1).getRawString():""}getTextureCount(){return this.isExistTextureFiles()?this._jsonValue.at(4).getSize():0}getTextureDirectory(){const t=this._jsonValue.at(4).getValueByIndex(0).getRawString().split("/"),e=t.length-1;let i="";for(let r=0;r<e;r++)i+=t[r],r<e-1&&(i+="/");return i}getTextureFileName(t){return this._jsonValue.at(4).getValueByIndex(t).getRawString()}getHitAreasCount(){return this.isExistHitAreas()?this._jsonValue.at(7).getSize():0}getHitAreaId(t){return ct.getIdManager().getId(this._jsonValue.at(7).getValueByIndex(t).getValueByString(this.id).getRawString())}getHitAreaName(t){return this._jsonValue.at(7).getValueByIndex(t).getValueByString(this.name).getRawString()}getPhysicsFileName(){return this.isExistPhysicsFile()?this._jsonValue.at(5).getRawString():""}getPoseFileName(){return this.isExistPoseFile()?this._jsonValue.at(6).getRawString():""}getExpressionCount(){return this.isExistExpressionFile()?this._jsonValue.at(3).getSize():0}getExpressionName(t){return this._jsonValue.at(3).getValueByIndex(t).getValueByString(this.name).getRawString()}getExpressionFileName(t){return this._jsonValue.at(3).getValueByIndex(t).getValueByString(this.filePath).getRawString()}getMotionGroupCount(){return this.isExistMotionGroups()?this._jsonValue.at(2).getKeys().getSize():0}getMotionGroupName(t){return this.isExistMotionGroups()?this._jsonValue.at(2).getKeys().at(t):null}getMotionCount(t){return this.isExistMotionGroupName(t)?this._jsonValue.at(2).getValueByString(t).getSize():0}getMotionFileName(t,e){return this.isExistMotionGroupName(t)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.filePath).getRawString():""}getMotionSoundFileName(t,e){return this.isExistMotionSoundFile(t,e)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.soundPath).getRawString():""}getMotionFadeInTimeValue(t,e){return this.isExistMotionFadeIn(t,e)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeInTime).toFloat():-1}getMotionFadeOutTimeValue(t,e){return this.isExistMotionFadeOut(t,e)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeOutTime).toFloat():-1}getUserDataFile(){return this.isExistUserDataFile()?this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData).getRawString():""}getLayoutMap(t){const e=this.getJson().getRoot().getValueByString(this.layout).getMap();if(null==e)return!1;let i=!1;for(const r=e.begin();r.notEqual(e.end());r.preIncrement())t.setValue(r.ptr().first,r.ptr().second.toFloat()),i=!0;return i}getEyeBlinkParameterCount(){if(!this.isExistEyeBlinkParameters())return 0;let t=0;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.eyeBlink){t=i.getValueByString(this.ids).getVector().getSize();break}}return t}getEyeBlinkParameterId(t){if(!this.isExistEyeBlinkParameters())return null;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.eyeBlink)return ct.getIdManager().getId(i.getValueByString(this.ids).getValueByIndex(t).getRawString())}return null}getLipSyncParameterCount(){if(!this.isExistLipSyncParameters())return 0;let t=0;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.lipSync){t=i.getValueByString(this.ids).getVector().getSize();break}}return t}getLipSyncParameterId(t){if(!this.isExistLipSyncParameters())return null;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.lipSync)return ct.getIdManager().getId(i.getValueByString(this.ids).getValueByIndex(t).getRawString())}return null}isExistModelFile(){const t=this._jsonValue.at(1);return!t.isNull()&&!t.isError()}isExistTextureFiles(){const t=this._jsonValue.at(4);return!t.isNull()&&!t.isError()}isExistHitAreas(){const t=this._jsonValue.at(7);return!t.isNull()&&!t.isError()}isExistPhysicsFile(){const t=this._jsonValue.at(5);return!t.isNull()&&!t.isError()}isExistPoseFile(){const t=this._jsonValue.at(6);return!t.isNull()&&!t.isError()}isExistExpressionFile(){const t=this._jsonValue.at(3);return!t.isNull()&&!t.isError()}isExistMotionGroups(){const t=this._jsonValue.at(2);return!t.isNull()&&!t.isError()}isExistMotionGroupName(t){const e=this._jsonValue.at(2).getValueByString(t);return!e.isNull()&&!e.isError()}isExistMotionSoundFile(t,e){const i=this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.soundPath);return!i.isNull()&&!i.isError()}isExistMotionFadeIn(t,e){const i=this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeInTime);return!i.isNull()&&!i.isError()}isExistMotionFadeOut(t,e){const i=this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeOutTime);return!i.isNull()&&!i.isError()}isExistUserDataFile(){const t=this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData);return!t.isNull()&&!t.isError()}isExistEyeBlinkParameters(){if(this._jsonValue.at(0).isNull()||this._jsonValue.at(0).isError())return!1;for(let t=0;t<this._jsonValue.at(0).getSize();++t)if(this._jsonValue.at(0).getValueByIndex(t).getValueByString(this.name).getRawString()==this.eyeBlink)return!0;return!1}isExistLipSyncParameters(){if(this._jsonValue.at(0).isNull()||this._jsonValue.at(0).isError())return!1;for(let t=0;t<this._jsonValue.at(0).getSize();++t)if(this._jsonValue.at(0).getValueByIndex(t).getValueByString(this.name).getRawString()==this.lipSync)return!0;return!1}}(t=>{t.CubismModelSettingJson=pr,t.FrequestNode=mr})(cr||(cr={}));class _r extends Et{constructor(t){var e,i;if(super(t),g(this,"moc"),g(this,"textures"),g(this,"layout"),g(this,"hitAreas"),g(this,"expressions"),g(this,"motions"),!_r.isValidJSON(t))throw new TypeError("Invalid JSON.");const r=(new TextEncoder).encode(JSON.stringify(t)).buffer;Object.assign(this,new pr(r,r.byteLength)),this.moc=t.FileReferences.Moc,this.textures=[...t.FileReferences.Textures],this.pose=t.FileReferences.Pose,this.physics=t.FileReferences.Physics,this.expressions=null==(e=t.FileReferences.Expressions)?void 0:e.filter(t=>!!t&&"string"==typeof t.File),this.motions=null!=(i=t.FileReferences.Motions)?i:t.Motions,this.layout=t.Layout,this.hitAreas=t.HitAreas;const s=this.getFileStem(this.moc);this.setModelName(s,this.name)}static isValidJSON(t){if(!t||"object"!=typeof t)return!1;const e=t.FileReferences;if(!e||"object"!=typeof e||"string"!=typeof e.Moc)return!1;const i=e.Textures;if(!Array.isArray(i)||0===i.length)return!1;if(!i.every(t=>"string"==typeof t))return!1;const r=e.Expressions;return!(void 0!==r&&(!Array.isArray(r)||r.some(t=>!(t=>!!t&&"string"==typeof t.File)(t))))}replaceFiles(t){if(super.replaceFiles(t),this.motions)for(const[e,i]of Object.entries(this.motions))for(let r=0;r<i.length;r++){const s=i[r];(null==s?void 0:s.File)&&(s.File=t(s.File,`motions.${e}[${r}].File`),s.Sound&&(s.Sound=t(s.Sound,`motions.${e}[${r}].Sound`)))}if(this.expressions)for(let e=0;e<this.expressions.length;e++){const i=this.expressions[e];(null==i?void 0:i.File)&&(i.File=t(i.File,`expressions[${e}].File`))}}getEyeBlinkParameters(){var t,e,i;const r=[],s=null!=(e=null==(t=this.getEyeBlinkParameterCount)?void 0:t.call(this))?e:0;if(s>0)for(let a=0;a<s;a++){const t=null==(i=this.getEyeBlinkParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&r.push(t.getString().s)}else if(Array.isArray(this.json.Groups)){const t=this.json.Groups;for(const e of t)if("EyeBlink"===(null==e?void 0:e.Name)&&Array.isArray(e.Ids))for(const t of e.Ids)"string"==typeof t?r.push(t):(null==t?void 0:t.Id)&&r.push(t.Id)}return r}getLipSyncParameters(){var t,e,i;const r=[],s=null!=(e=null==(t=this.getLipSyncParameterCount)?void 0:t.call(this))?e:0;if(s>0)for(let a=0;a<s;a++){const t=null==(i=this.getLipSyncParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&r.push(t.getString().s)}else if(Array.isArray(this.json.Groups)){const t=this.json.Groups;for(const e of t)if("LipSync"===(null==e?void 0:e.Name)&&Array.isArray(e.Ids))for(const t of e.Ids)"string"==typeof t?r.push(t):(null==t?void 0:t.Id)&&r.push(t.Id)}return r}}let fr;Mt(_r,[pr]);let yr=20,xr=16;function Cr(t={}){null!=t.memorySizeMB&&(xr=t.memorySizeMB)}function Mr(){return ct.isStarted()?Promise.resolve():(null!=fr||(fr=new Promise((t,e)=>{!function i(){try{Sr(),t()}catch(r){if(yr--,yr<0)return void e(new Error("Failed to start up Cubism framework.",{cause:r}));_t.log("Cubism","Startup failed, retrying 10ms later..."),setTimeout(i,10)}}()})),fr)}function Sr(t,e){const i=d({logFunction:console.log,loggingLevel:mt.LogLevel_Verbose},t),r=null!=e?e:xr;ct.startUp(i),ct.initialize(yt(r))}const vr="FadeInTime",br="Link";class Pr{static create(t,e){const i=Z.create(t,e);if(!i)return null;const r=new Pr,s=i.getRoot();s.getValueByString(vr).isNull()||(r._fadeTimeSeconds=s.getValueByString(vr).toFloat(.5),r._fadeTimeSeconds<0&&(r._fadeTimeSeconds=.5));const a=s.getValueByString("Groups"),n=a.getSize();for(let o=0;o<n;++o){const t=a.getValueByIndex(o),e=t.getSize();let i=0;for(let s=0;s<e;++s){const e=t.getValueByIndex(s),a=new Br,n=ct.getIdManager().getId(e.getValueByString("Id").getRawString());if(a.partId=n,!e.getValueByString(br).isNull()){const t=e.getValueByString(br),i=t.getSize();for(let e=0;e<i;++e){const i=new Br,r=ct.getIdManager().getId(t.getValueByIndex(e).getString());i.partId=r,a.link.pushBack(i)}}r._partGroups.pushBack(a.clone()),++i}r._partGroupCounts.pushBack(i)}return Z.delete(i),r}static delete(t){}updateParameters(t,e){t!=this._lastModel&&this.reset(t),this._lastModel=t,e<0&&(e=0);let i=0;for(let r=0;r<this._partGroupCounts.getSize();r++){const s=this._partGroupCounts.at(r);this.doFade(t,e,i,s),i+=s}this.copyPartOpacities(t)}reset(t){let e=0;for(let i=0;i<this._partGroupCounts.getSize();++i){const r=this._partGroupCounts.at(i);for(let i=e;i<e+r;++i){this._partGroups.at(i).initialize(t);const r=this._partGroups.at(i).partIndex,s=this._partGroups.at(i).parameterIndex;if(!(r<0)){t.setPartOpacityByIndex(r,i==e?1:0),t.setParameterValueByIndex(s,i==e?1:0);for(let e=0;e<this._partGroups.at(i).link.getSize();++e)this._partGroups.at(i).link.at(e).initialize(t)}}e+=r}}copyPartOpacities(t){for(let e=0;e<this._partGroups.getSize();++e){const i=this._partGroups.at(e);if(0==i.link.getSize())continue;const r=this._partGroups.at(e).partIndex,s=t.getPartOpacityByIndex(r);for(let e=0;e<i.link.getSize();++e){const r=i.link.at(e).partIndex;r<0||t.setPartOpacityByIndex(r,s)}}}doFade(t,e,i,r){let s=-1,a=1;const n=.5;for(let o=i;o<i+r;++o){const i=this._partGroups.at(o).partIndex,r=this._partGroups.at(o).parameterIndex;if(t.getParameterValueByIndex(r)>.001){if(s>=0)break;if(s=o,0==this._fadeTimeSeconds){a=1;continue}a=t.getPartOpacityByIndex(i),a+=e/this._fadeTimeSeconds,a>1&&(a=1)}}s<0&&(s=0,a=1);for(let o=i;o<i+r;++o){const e=this._partGroups.at(o).partIndex;if(s==o)t.setPartOpacityByIndex(e,a);else{let i,r=t.getPartOpacityByIndex(e);i=a<n?-.5*a/n+1:(1-a)*n/.5;(1-i)*(1-a)>.15&&(i=1-.15/(1-a)),r>i&&(r=i),t.setPartOpacityByIndex(e,r)}}}constructor(){this._fadeTimeSeconds=.5,this._lastModel=null,this._partGroups=new p,this._partGroupCounts=new p}}class Br{constructor(t){if(this.parameterIndex=0,this.partIndex=0,this.link=new p,null!=t){this.partId=t.partId;for(const e=t.link.begin();e.notEqual(t.link.end());e.preIncrement())this.link.pushBack(e.ptr().clone())}}assignment(t){this.partId=t.partId;for(const e=t.link.begin();e.notEqual(t.link.end());e.preIncrement())this.link.pushBack(e.ptr().clone());return this}initialize(t){this.parameterIndex=t.getParameterIndex(this.partId),this.partIndex=t.getPartIndex(this.partId),t.setParameterValueByIndex(this.parameterIndex,1)}clone(){const t=new Br;t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=new p;for(let e=this.link.begin();e.notEqual(this.link.end());e.increment())t.link.pushBack(e.ptr().clone());return t}}var wr,Fr,Ir;(t=>{t.CubismPose=Pr,t.PartData=Br})(wr||(wr={}));class Er{constructor(t=!1,e=!1){this.isOverridden=t,this.isParameterRepeated=e}}class Vr{constructor(t=!1,e=new L){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class Lr{constructor(t=!1,e=new L){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class Rr{constructor(t=!1,e=!1){this.isOverridden=t,this.isCulling=e}get isOverwritten(){return this.isOverridden}}class Tr{update(){this._model.update(),this._model.drawables.resetDynamicFlags()}getPixelsPerUnit(){return null==this._model?0:this._model.canvasinfo.PixelsPerUnit}getCanvasWidth(){return null==this._model?0:this._model.canvasinfo.CanvasWidth/this._model.canvasinfo.PixelsPerUnit}getCanvasHeight(){return null==this._model?0:this._model.canvasinfo.CanvasHeight/this._model.canvasinfo.PixelsPerUnit}saveParameters(){const t=this._model.parameters.count,e=this._savedParameters.getSize();for(let i=0;i<t;++i)i<e?this._savedParameters.set(i,this._parameterValues[i]):this._savedParameters.pushBack(this._parameterValues[i])}getMultiplyColor(t){if(this.getOverrideFlagForModelMultiplyColors()||this.getOverrideFlagForDrawableMultiplyColors(t))return this._userMultiplyColors.at(t).color;return this.getDrawableMultiplyColor(t)}getScreenColor(t){if(this.getOverrideFlagForModelScreenColors()||this.getOverrideFlagForDrawableScreenColors(t))return this._userScreenColors.at(t).color;return this.getDrawableScreenColor(t)}setMultiplyColorByTextureColor(t,e){this.setMultiplyColorByRGBA(t,e.r,e.g,e.b,e.a)}setMultiplyColorByRGBA(t,e,i,r,s=1){this._userMultiplyColors.at(t).color.r=e,this._userMultiplyColors.at(t).color.g=i,this._userMultiplyColors.at(t).color.b=r,this._userMultiplyColors.at(t).color.a=s}setScreenColorByTextureColor(t,e){this.setScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setScreenColorByRGBA(t,e,i,r,s=1){this._userScreenColors.at(t).color.r=e,this._userScreenColors.at(t).color.g=i,this._userScreenColors.at(t).color.b=r,this._userScreenColors.at(t).color.a=s}getPartMultiplyColor(t){return this._userPartMultiplyColors.at(t).color}getPartScreenColor(t){return this._userPartScreenColors.at(t).color}setPartColor(t,e,i,r,s,a,n){if(a.at(t).color.r=e,a.at(t).color.g=i,a.at(t).color.b=r,a.at(t).color.a=s,a.at(t).isOverridden)for(let o=0;o<this._partChildDrawables.at(t).getSize();++o){const a=this._partChildDrawables.at(t).at(o);n.at(a).color.r=e,n.at(a).color.g=i,n.at(a).color.b=r,n.at(a).color.a=s}}setPartMultiplyColorByTextureColor(t,e){this.setPartMultiplyColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartMultiplyColorByRGBA(t,e,i,r,s){this.setPartColor(t,e,i,r,s,this._userPartMultiplyColors,this._userMultiplyColors)}setPartScreenColorByTextureColor(t,e){this.setPartScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartScreenColorByRGBA(t,e,i,r,s){this.setPartColor(t,e,i,r,s,this._userPartScreenColors,this._userScreenColors)}getOverrideFlagForModelParameterRepeat(){return this._isOverriddenParameterRepeat}setOverrideFlagForModelParameterRepeat(t){this._isOverriddenParameterRepeat=t}getOverrideFlagForParameterRepeat(t){return this._userParameterRepeatDataList.at(t).isOverridden}setOverrideFlagForParameterRepeat(t,e){this._userParameterRepeatDataList.at(t).isOverridden=e}getRepeatFlagForParameterRepeat(t){return this._userParameterRepeatDataList.at(t).isParameterRepeated}setRepeatFlagForParameterRepeat(t,e){this._userParameterRepeatDataList.at(t).isParameterRepeated=e}getOverwriteFlagForModelMultiplyColors(){return N("getOverwriteFlagForModelMultiplyColors() is a deprecated function. Please use getOverrideFlagForModelMultiplyColors()."),this.getOverrideFlagForModelMultiplyColors()}getOverrideFlagForModelMultiplyColors(){return this._isOverriddenModelMultiplyColors}getOverwriteFlagForModelScreenColors(){return N("getOverwriteFlagForModelScreenColors() is a deprecated function. Please use getOverrideFlagForModelScreenColors()."),this.getOverrideFlagForModelScreenColors()}getOverrideFlagForModelScreenColors(){return this._isOverriddenModelScreenColors}setOverwriteFlagForModelMultiplyColors(t){N("setOverwriteFlagForModelMultiplyColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelMultiplyColors(value: boolean)."),this.setOverrideFlagForModelMultiplyColors(t)}setOverrideFlagForModelMultiplyColors(t){this._isOverriddenModelMultiplyColors=t}setOverwriteFlagForModelScreenColors(t){N("setOverwriteFlagForModelScreenColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelScreenColors(value: boolean)."),this.setOverrideFlagForModelScreenColors(t)}setOverrideFlagForModelScreenColors(t){this._isOverriddenModelScreenColors=t}getOverwriteFlagForDrawableMultiplyColors(t){return N("getOverwriteFlagForDrawableMultiplyColors(drawableindex: number) is a deprecated function. Please use getOverrideFlagForDrawableMultiplyColors(drawableindex: number)."),this.getOverrideFlagForDrawableMultiplyColors(t)}getOverrideFlagForDrawableMultiplyColors(t){return this._userMultiplyColors.at(t).isOverridden}getOverwriteFlagForDrawableScreenColors(t){return N("getOverwriteFlagForDrawableScreenColors(drawableindex: number) is a deprecated function. Please use getOverrideFlagForDrawableScreenColors(drawableindex: number)."),this.getOverrideFlagForDrawableScreenColors(t)}getOverrideFlagForDrawableScreenColors(t){return this._userScreenColors.at(t).isOverridden}setOverwriteFlagForDrawableMultiplyColors(t,e){N("setOverwriteFlagForDrawableMultiplyColors(drawableindex: number, value: boolean) is a deprecated function. Please use setOverrideFlagForDrawableMultiplyColors(drawableindex: number, value: boolean)."),this.setOverrideFlagForDrawableMultiplyColors(t,e)}setOverrideFlagForDrawableMultiplyColors(t,e){this._userMultiplyColors.at(t).isOverridden=e}setOverwriteFlagForDrawableScreenColors(t,e){N("setOverwriteFlagForDrawableScreenColors(drawableindex: number, value: boolean) is a deprecated function. Please use setOverrideFlagForDrawableScreenColors(drawableindex: number, value: boolean)."),this.setOverrideFlagForDrawableScreenColors(t,e)}setOverrideFlagForDrawableScreenColors(t,e){this._userScreenColors.at(t).isOverridden=e}getOverwriteColorForPartMultiplyColors(t){return N("getOverwriteColorForPartMultiplyColors(partIndex: number) is a deprecated function. Please use getOverrideColorForPartMultiplyColors(partIndex: number)."),this.getOverrideColorForPartMultiplyColors(t)}getOverrideColorForPartMultiplyColors(t){return this._userPartMultiplyColors.at(t).isOverridden}getOverwriteColorForPartScreenColors(t){return N("getOverwriteColorForPartScreenColors(partIndex: number) is a deprecated function. Please use getOverrideColorForPartScreenColors(partIndex: number)."),this.getOverrideColorForPartScreenColors(t)}getOverrideColorForPartScreenColors(t){return this._userPartScreenColors.at(t).isOverridden}setOverwriteColorForPartColors(t,e,i,r){N("setOverwriteColorForPartColors(partIndex: number, value: boolean, partColors: csmVector<PartColorData>, drawableColors: csmVector<DrawableColorData>) is a deprecated function. Please use setOverrideColorForPartColors(partIndex: number, value: boolean, partColors: csmVector<PartColorData>, drawableColors: csmVector<DrawableColorData>)."),this.setOverrideColorForPartColors(t,e,i,r)}setOverrideColorForPartColors(t,e,i,r){i.at(t).isOverridden=e;for(let s=0;s<this._partChildDrawables.at(t).getSize();++s){const a=this._partChildDrawables.at(t).at(s);r.at(a).isOverridden=e,e&&(r.at(a).color.r=i.at(t).color.r,r.at(a).color.g=i.at(t).color.g,r.at(a).color.b=i.at(t).color.b,r.at(a).color.a=i.at(t).color.a)}}setOverwriteColorForPartMultiplyColors(t,e){N("setOverwriteColorForPartMultiplyColors(partIndex: number, value: boolean) is a deprecated function. Please use setOverrideColorForPartMultiplyColors(partIndex: number, value: boolean)."),this.setOverrideColorForPartMultiplyColors(t,e)}setOverrideColorForPartMultiplyColors(t,e){this._userPartMultiplyColors.at(t).isOverridden=e,this.setOverrideColorForPartColors(t,e,this._userPartMultiplyColors,this._userMultiplyColors)}setOverwriteColorForPartScreenColors(t,e){N("setOverwriteColorForPartScreenColors(partIndex: number, value: boolean) is a deprecated function. Please use setOverrideColorForPartScreenColors(partIndex: number, value: boolean)."),this.setOverrideColorForPartScreenColors(t,e)}setOverrideColorForPartScreenColors(t,e){this._userPartScreenColors.at(t).isOverridden=e,this.setOverrideColorForPartColors(t,e,this._userPartScreenColors,this._userScreenColors)}getDrawableCulling(t){if(this.getOverrideFlagForModelCullings()||this.getOverrideFlagForDrawableCullings(t))return this._userCullings.at(t).isCulling;const e=this._model.drawables.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(e[t])}setDrawableCulling(t,e){this._userCullings.at(t).isCulling=e}getOverwriteFlagForModelCullings(){return N("getOverwriteFlagForModelCullings() is a deprecated function. Please use getOverrideFlagForModelCullings()."),this.getOverrideFlagForModelCullings()}getOverrideFlagForModelCullings(){return this._isOverriddenCullings}setOverwriteFlagForModelCullings(t){N("setOverwriteFlagForModelCullings(isOverriddenCullings: boolean) is a deprecated function. Please use setOverrideFlagForModelCullings(isOverriddenCullings: boolean)."),this.setOverrideFlagForModelCullings(t)}setOverrideFlagForModelCullings(t){this._isOverriddenCullings=t}getOverwriteFlagForDrawableCullings(t){return N("getOverwriteFlagForDrawableCullings(drawableIndex: number) is a deprecated function. Please use getOverrideFlagForDrawableCullings(drawableIndex: number)."),this.getOverrideFlagForDrawableCullings(t)}getOverrideFlagForDrawableCullings(t){return this._userCullings.at(t).isOverridden}setOverwriteFlagForDrawableCullings(t,e){N("setOverwriteFlagForDrawableCullings(drawableIndex: number, isOverriddenCullings: boolean) is a deprecated function. Please use setOverrideFlagForDrawableCullings(drawableIndex: number, isOverriddenCullings: boolean)."),this.setOverrideFlagForDrawableCullings(t,e)}setOverrideFlagForDrawableCullings(t,e){this._userCullings.at(t).isOverridden=e}getModelOapcity(){return this._modelOpacity}setModelOapcity(t){this._modelOpacity=t}getModel(){return this._model}getPartIndex(t){let e;const i=this._model.parts.count;for(e=0;e<i;++e)if(t==this._partIds.at(e))return e;return this._notExistPartId.isExist(t)?this._notExistPartId.getValue(t):(e=i+this._notExistPartId.getSize(),this._notExistPartId.setValue(t,e),this._notExistPartOpacities.appendKey(e),e)}getPartId(t){const e=this._model.parts.ids[t];return ct.getIdManager().getId(e)}getPartCount(){return this._model.parts.count}getPartParentPartIndices(){return this._model.parts.parentIndices}setPartOpacityByIndex(t,e){this._notExistPartOpacities.isExist(t)?this._notExistPartOpacities.setValue(t,e):(A(0<=t&&t<this.getPartCount()),this._partOpacities[t]=e)}setPartOpacityById(t,e){const i=this.getPartIndex(t);i<0||this.setPartOpacityByIndex(i,e)}getPartOpacityByIndex(t){return this._notExistPartOpacities.isExist(t)?this._notExistPartOpacities.getValue(t):(A(0<=t&&t<this.getPartCount()),this._partOpacities[t])}getPartOpacityById(t){const e=this.getPartIndex(t);return e<0?0:this.getPartOpacityByIndex(e)}getParameterIndex(t){let e;const i=this._model.parameters.count;for(e=0;e<i;++e)if(t==this._parameterIds.at(e))return e;return this._notExistParameterId.isExist(t)?this._notExistParameterId.getValue(t):(e=this._model.parameters.count+this._notExistParameterId.getSize(),this._notExistParameterId.setValue(t,e),this._notExistParameterValues.appendKey(e),e)}getParameterCount(){return this._model.parameters.count}getParameterType(t){return this._model.parameters.types[t]}getParameterMaximumValue(t){return this._model.parameters.maximumValues[t]}getParameterMinimumValue(t){return this._model.parameters.minimumValues[t]}getParameterDefaultValue(t){return this._model.parameters.defaultValues[t]}getParameterId(t){return ct.getIdManager().getId(this._model.parameters.ids[t])}getParameterValueByIndex(t){return this._notExistParameterValues.isExist(t)?this._notExistParameterValues.getValue(t):(A(0<=t&&t<this.getParameterCount()),this._parameterValues[t])}getParameterValueById(t){const e=this.getParameterIndex(t);return this.getParameterValueByIndex(e)}setParameterValueByIndex(t,e,i=1){this._notExistParameterValues.isExist(t)?this._notExistParameterValues.setValue(t,1==i?e:this._notExistParameterValues.getValue(t)*(1-i)+e*i):(A(0<=t&&t<this.getParameterCount()),e=this.isRepeat(t)?this.getParameterRepeatValue(t,e):this.getParameterClampValue(t,e),this._parameterValues[t]=1==i?e:this._parameterValues[t]=this._parameterValues[t]*(1-i)+e*i)}setParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.setParameterValueByIndex(r,e,i)}addParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)+e*i)}addParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.addParameterValueByIndex(r,e,i)}isRepeat(t){if(this._notExistParameterValues.isExist(t))return!1;let e;return A(0<=t&&t<this.getParameterCount()),e=this._isOverriddenParameterRepeat||this._userParameterRepeatDataList.at(t).isOverridden?this._userParameterRepeatDataList.at(t).isParameterRepeated:0!=this._model.parameters.repeats[t],e}getParameterRepeatValue(t,e){if(this._notExistParameterValues.isExist(t))return e;A(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],r=this._model.parameters.minimumValues[t],s=i-r;if(i<e){const t=we.mod(e-i,s);e=Number.isNaN(t)?i:r+t}if(e<r){const t=we.mod(r-e,s);e=Number.isNaN(t)?r:i-t}return e}getParameterClampValue(t,e){if(this._notExistParameterValues.isExist(t))return e;A(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],r=this._model.parameters.minimumValues[t];return we.clamp(e,r,i)}getParameterRepeats(t){return 0!=this._model.parameters.repeats[t]}multiplyParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.multiplyParameterValueByIndex(r,e,i)}multiplyParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)*(1+(e-1)*i))}getDrawableIndex(t){const e=this._model.drawables.count;for(let i=0;i<e;++i)if(this._drawableIds.at(i)==t)return i;return-1}getDrawableCount(){return this._model.drawables.count}getDrawableId(t){const e=this._model.drawables.ids;return ct.getIdManager().getId(e[t])}getDrawableRenderOrders(){return this._model.drawables.renderOrders}getDrawableTextureIndices(t){return this.getDrawableTextureIndex(t)}getDrawableTextureIndex(t){return this._model.drawables.textureIndices[t]}getDrawableDynamicFlagVertexPositionsDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVertexPositionsDidChangeBit(e[t])}getDrawableVertexIndexCount(t){return this._model.drawables.indexCounts[t]}getDrawableVertexCount(t){return this._model.drawables.vertexCounts[t]}getDrawableVertices(t){return this.getDrawableVertexPositions(t)}getDrawableVertexIndices(t){return this._model.drawables.indices[t]}getDrawableVertexPositions(t){return this._model.drawables.vertexPositions[t]}getDrawableVertexUvs(t){return this._model.drawables.vertexUvs[t]}getDrawableOpacity(t){return this._model.drawables.opacities[t]}getDrawableMultiplyColor(t){const e=this._model.drawables.multiplyColors,i=4*t,r=new L;return r.r=e[i],r.g=e[i+1],r.b=e[i+2],r.a=e[i+3],r}getDrawableScreenColor(t){const e=this._model.drawables.screenColors,i=4*t,r=new L;return r.r=e[i],r.g=e[i+1],r.b=e[i+2],r.a=e[i+3],r}getDrawableParentPartIndex(t){return this._model.drawables.parentPartIndices[t]}getDrawableBlendMode(t){const e=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(e[t])?V.CubismBlendMode_Additive:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(e[t])?V.CubismBlendMode_Multiplicative:V.CubismBlendMode_Normal}getDrawableInvertedMaskBit(t){const e=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(e[t])}getDrawableMasks(){return this._model.drawables.masks}getDrawableMaskCounts(){return this._model.drawables.maskCounts}isUsingMasking(){for(let t=0;t<this._model.drawables.count;++t)if(!(this._model.drawables.maskCounts[t]<=0))return!0;return!1}getDrawableDynamicFlagIsVisible(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasIsVisibleBit(e[t])}getDrawableDynamicFlagVisibilityDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVisibilityDidChangeBit(e[t])}getDrawableDynamicFlagOpacityDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasOpacityDidChangeBit(e[t])}getDrawableDynamicFlagRenderOrderDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasRenderOrderDidChangeBit(e[t])}getDrawableDynamicFlagBlendColorDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasBlendColorDidChangeBit(e[t])}loadParameters(){let t=this._model.parameters.count;const e=this._savedParameters.getSize();t>e&&(t=e);for(let i=0;i<t;++i)this._parameterValues[i]=this._savedParameters.at(i)}initialize(){A(this._model),this._parameterValues=this._model.parameters.values,this._partOpacities=this._model.parts.opacities,this._parameterMaximumValues=this._model.parameters.maximumValues,this._parameterMinimumValues=this._model.parameters.minimumValues;{const t=this._model.parameters.ids,e=this._model.parameters.count;this._parameterIds.prepareCapacity(e),this._userParameterRepeatDataList.prepareCapacity(e);for(let i=0;i<e;++i)this._parameterIds.pushBack(ct.getIdManager().getId(t[i])),this._userParameterRepeatDataList.pushBack(new Er(!1,!1))}const t=this._model.parts.count;{const e=this._model.parts.ids;this._partIds.prepareCapacity(t);for(let i=0;i<t;++i)this._partIds.pushBack(ct.getIdManager().getId(e[i]));this._userPartMultiplyColors.prepareCapacity(t),this._userPartScreenColors.prepareCapacity(t),this._partChildDrawables.prepareCapacity(t)}{const e=this._model.drawables.ids,i=this._model.drawables.count;this._userMultiplyColors.prepareCapacity(i),this._userScreenColors.prepareCapacity(i),this._userCullings.prepareCapacity(i);const r=new Rr(!1,!1);for(let s=0;s<t;++s){const t=new L(1,1,1,1),e=new L(0,0,0,1),r=new Lr(!1,t),a=new Lr(!1,e);this._userPartMultiplyColors.pushBack(r),this._userPartScreenColors.pushBack(a),this._partChildDrawables.pushBack(new p),this._partChildDrawables.at(s).prepareCapacity(i)}for(let t=0;t<i;++t){const i=new L(1,1,1,1),s=new L(0,0,0,1),a=new Vr(!1,i),n=new Vr(!1,s);this._drawableIds.pushBack(ct.getIdManager().getId(e[t])),this._userMultiplyColors.pushBack(a),this._userScreenColors.pushBack(n),this._userCullings.pushBack(r);const o=this.getDrawableParentPartIndex(t);o>=0&&this._partChildDrawables.at(o).pushBack(t)}}}constructor(t){this._model=t,this._parameterValues=null,this._parameterMaximumValues=null,this._parameterMinimumValues=null,this._partOpacities=null,this._savedParameters=new p,this._parameterIds=new p,this._drawableIds=new p,this._partIds=new p,this._isOverriddenParameterRepeat=!0,this._isOverriddenModelMultiplyColors=!1,this._isOverriddenModelScreenColors=!1,this._isOverriddenCullings=!1,this._modelOpacity=1,this._userParameterRepeatDataList=new p,this._userMultiplyColors=new p,this._userScreenColors=new p,this._userCullings=new p,this._userPartMultiplyColors=new p,this._userPartScreenColors=new p,this._partChildDrawables=new p,this._notExistPartId=new H,this._notExistParameterId=new H,this._notExistParameterValues=new H,this._notExistPartOpacities=new H}release(){this._model.release(),this._model=null}}(t=>{t.CubismModel=Tr})(Fr||(Fr={}));class Dr{static create(t,e){let i=null;if(e){if(!this.hasMocConsistency(t))return U("Inconsistent MOC3."),i}const r=Live2DCubismCore.Moc.fromArrayBuffer(t);return r&&(i=new Dr(r),i._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(r,t)),i}static delete(t){t._moc._release(),t._moc=null,t=null}createModel(){let t=null;const e=Live2DCubismCore.Model.fromMoc(this._moc);return e&&(t=new Tr(e),t.initialize(),++this._modelCount),t}deleteModel(t){null!=t&&(t.release(),t=null,--this._modelCount)}constructor(t){this._moc=t,this._modelCount=0,this._mocVersion=0}release(){A(0==this._modelCount),this._moc._release(),this._moc=null}getLatestMocVersion(){return Live2DCubismCore.Version.csmGetLatestMocVersion()}getMocVersion(){return this._mocVersion}static hasMocConsistency(t){return 1===Live2DCubismCore.Moc.prototype.hasMocConsistency(t)}}(t=>{t.CubismMoc=Dr})(Ir||(Ir={}));var Ar,Or=(t=>(t[t.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",t))(Or||{}),kr=(t=>(t[t.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",t[t.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",t[t.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",t))(kr||{});class Nr{constructor(){this.gravity=new be(0,0),this.wind=new be(0,0)}}class Ur{}class zr{}class jr{constructor(){this.initialPosition=new be(0,0),this.position=new be(0,0),this.lastPosition=new be(0,0),this.lastGravity=new be(0,0),this.force=new be(0,0),this.velocity=new be(0,0)}}class Gr{constructor(){this.normalizationPosition=new zr,this.normalizationAngle=new zr}}class Xr{constructor(){this.source=new Ur}}class Hr{constructor(){this.destination=new Ur,this.translationScale=new be(0,0)}}class qr{constructor(){this.settings=new p,this.inputs=new p,this.outputs=new p,this.particles=new p,this.gravity=new be(0,0),this.wind=new be(0,0),this.fps=0}}(t=>{t.CubismPhysicsInput=Xr,t.CubismPhysicsNormalization=zr,t.CubismPhysicsOutput=Hr,t.CubismPhysicsParameter=Ur,t.CubismPhysicsParticle=jr,t.CubismPhysicsRig=qr,t.CubismPhysicsSource=kr,t.CubismPhysicsSubRig=Gr,t.CubismPhysicsTargetType=Or,t.PhysicsJsonEffectiveForces=Nr})(Ar||(Ar={}));const Yr="Position",Wr="Angle",Jr="Type",$r="Meta",Zr="EffectiveForces",Kr="Gravity",Qr="Wind",ts="PhysicsSettings",es="Normalization",is="Minimum",rs="Maximum",ss="Default",as="Reflect",ns="Weight",os="Input",ls="Output",us="Vertices";class hs{constructor(t,e){this._json=Z.create(t,e)}release(){Z.delete(this._json)}getGravity(){const t=new be(0,0);return t.x=this._json.getRoot().getValueByString($r).getValueByString(Zr).getValueByString(Kr).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString($r).getValueByString(Zr).getValueByString(Kr).getValueByString("Y").toFloat(),t}getWind(){const t=new be(0,0);return t.x=this._json.getRoot().getValueByString($r).getValueByString(Zr).getValueByString(Qr).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString($r).getValueByString(Zr).getValueByString(Qr).getValueByString("Y").toFloat(),t}getFps(){return this._json.getRoot().getValueByString($r).getValueByString("Fps").toFloat(0)}getSubRigCount(){return this._json.getRoot().getValueByString($r).getValueByString("PhysicsSettingCount").toInt()}getTotalInputCount(){return this._json.getRoot().getValueByString($r).getValueByString("TotalInputCount").toInt()}getTotalOutputCount(){return this._json.getRoot().getValueByString($r).getValueByString("TotalOutputCount").toInt()}getVertexCount(){return this._json.getRoot().getValueByString($r).getValueByString("VertexCount").toInt()}getNormalizationPositionMinimumValue(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(es).getValueByString(Yr).getValueByString(is).toFloat()}getNormalizationPositionMaximumValue(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(es).getValueByString(Yr).getValueByString(rs).toFloat()}getNormalizationPositionDefaultValue(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(es).getValueByString(Yr).getValueByString(ss).toFloat()}getNormalizationAngleMinimumValue(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(es).getValueByString(Wr).getValueByString(is).toFloat()}getNormalizationAngleMaximumValue(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(es).getValueByString(Wr).getValueByString(rs).toFloat()}getNormalizationAngleDefaultValue(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(es).getValueByString(Wr).getValueByString(ss).toFloat()}getInputCount(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(os).getVector().getSize()}getInputWeight(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(os).getValueByIndex(e).getValueByString(ns).toFloat()}getInputReflect(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(os).getValueByIndex(e).getValueByString(as).toBoolean()}getInputType(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(os).getValueByIndex(e).getValueByString(Jr).getRawString()}getInputSourceId(t,e){return ct.getIdManager().getId(this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(os).getValueByIndex(e).getValueByString("Source").getValueByString("Id").getRawString())}getOutputCount(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(ls).getVector().getSize()}getOutputVertexIndex(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString("VertexIndex").toInt()}getOutputAngleScale(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString("Scale").toFloat()}getOutputWeight(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString(ns).toFloat()}getOutputDestinationId(t,e){return ct.getIdManager().getId(this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString("Destination").getValueByString("Id").getRawString())}getOutputType(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString(Jr).getRawString()}getOutputReflect(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString(as).toBoolean()}getParticleCount(t){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(us).getVector().getSize()}getParticleMobility(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString("Mobility").toFloat()}getParticleDelay(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString("Delay").toFloat()}getParticleAcceleration(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString("Acceleration").toFloat()}getParticleRadius(t,e){return this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString("Radius").toFloat()}getParticlePosition(t,e){const i=new be(0,0);return i.x=this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString(Yr).getValueByString("X").toFloat(),i.y=this._json.getRoot().getValueByString(ts).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString(Yr).getValueByString("Y").toFloat(),i}}var ds;(t=>{t.CubismPhysicsJson=hs})(ds||(ds={}));const gs="Angle";class cs{static create(t,e){const i=new cs;return i.parse(t,e),i._physicsRig.gravity.y=0,i}static delete(t){null!=t&&(t.release(),t=null)}parse(t,e){this._physicsRig=new qr;let i=new hs(t,e);this._physicsRig.gravity=i.getGravity(),this._physicsRig.wind=i.getWind(),this._physicsRig.subRigCount=i.getSubRigCount(),this._physicsRig.fps=i.getFps(),this._physicsRig.settings.updateSize(this._physicsRig.subRigCount,Gr,!0),this._physicsRig.inputs.updateSize(i.getTotalInputCount(),Xr,!0),this._physicsRig.outputs.updateSize(i.getTotalOutputCount(),Hr,!0),this._physicsRig.particles.updateSize(i.getVertexCount(),jr,!0),this._currentRigOutputs.clear(),this._previousRigOutputs.clear();let r=0,s=0,a=0;for(let n=0;n<this._physicsRig.settings.getSize();++n){this._physicsRig.settings.at(n).normalizationPosition.minimum=i.getNormalizationPositionMinimumValue(n),this._physicsRig.settings.at(n).normalizationPosition.maximum=i.getNormalizationPositionMaximumValue(n),this._physicsRig.settings.at(n).normalizationPosition.defalut=i.getNormalizationPositionDefaultValue(n),this._physicsRig.settings.at(n).normalizationAngle.minimum=i.getNormalizationAngleMinimumValue(n),this._physicsRig.settings.at(n).normalizationAngle.maximum=i.getNormalizationAngleMaximumValue(n),this._physicsRig.settings.at(n).normalizationAngle.defalut=i.getNormalizationAngleDefaultValue(n),this._physicsRig.settings.at(n).inputCount=i.getInputCount(n),this._physicsRig.settings.at(n).baseInputIndex=r;for(let s=0;s<this._physicsRig.settings.at(n).inputCount;++s)this._physicsRig.inputs.at(r+s).sourceParameterIndex=-1,this._physicsRig.inputs.at(r+s).weight=i.getInputWeight(n,s),this._physicsRig.inputs.at(r+s).reflect=i.getInputReflect(n,s),"X"==i.getInputType(n,s)?(this._physicsRig.inputs.at(r+s).type=kr.CubismPhysicsSource_X,this._physicsRig.inputs.at(r+s).getNormalizedParameterValue=_s):"Y"==i.getInputType(n,s)?(this._physicsRig.inputs.at(r+s).type=kr.CubismPhysicsSource_Y,this._physicsRig.inputs.at(r+s).getNormalizedParameterValue=fs):i.getInputType(n,s)==gs&&(this._physicsRig.inputs.at(r+s).type=kr.CubismPhysicsSource_Angle,this._physicsRig.inputs.at(r+s).getNormalizedParameterValue=ys),this._physicsRig.inputs.at(r+s).source.targetType=Or.CubismPhysicsTargetType_Parameter,this._physicsRig.inputs.at(r+s).source.id=i.getInputSourceId(n,s);r+=this._physicsRig.settings.at(n).inputCount,this._physicsRig.settings.at(n).outputCount=i.getOutputCount(n),this._physicsRig.settings.at(n).baseOutputIndex=s;const t=new ps;t.outputs.resize(this._physicsRig.settings.at(n).outputCount);const e=new ps;e.outputs.resize(this._physicsRig.settings.at(n).outputCount);for(let r=0;r<this._physicsRig.settings.at(n).outputCount;++r)t.outputs.set(r,0),e.outputs.set(r,0),this._physicsRig.outputs.at(s+r).destinationParameterIndex=-1,this._physicsRig.outputs.at(s+r).vertexIndex=i.getOutputVertexIndex(n,r),this._physicsRig.outputs.at(s+r).angleScale=i.getOutputAngleScale(n,r),this._physicsRig.outputs.at(s+r).weight=i.getOutputWeight(n,r),this._physicsRig.outputs.at(s+r).destination.targetType=Or.CubismPhysicsTargetType_Parameter,this._physicsRig.outputs.at(s+r).destination.id=i.getOutputDestinationId(n,r),"X"==i.getOutputType(n,r)?(this._physicsRig.outputs.at(s+r).type=kr.CubismPhysicsSource_X,this._physicsRig.outputs.at(s+r).getValue=xs,this._physicsRig.outputs.at(s+r).getScale=vs):"Y"==i.getOutputType(n,r)?(this._physicsRig.outputs.at(s+r).type=kr.CubismPhysicsSource_Y,this._physicsRig.outputs.at(s+r).getValue=Cs,this._physicsRig.outputs.at(s+r).getScale=bs):i.getOutputType(n,r)==gs&&(this._physicsRig.outputs.at(s+r).type=kr.CubismPhysicsSource_Angle,this._physicsRig.outputs.at(s+r).getValue=Ms,this._physicsRig.outputs.at(s+r).getScale=Ps),this._physicsRig.outputs.at(s+r).reflect=i.getOutputReflect(n,r);this._currentRigOutputs.pushBack(t),this._previousRigOutputs.pushBack(e),s+=this._physicsRig.settings.at(n).outputCount,this._physicsRig.settings.at(n).particleCount=i.getParticleCount(n),this._physicsRig.settings.at(n).baseParticleIndex=a;for(let r=0;r<this._physicsRig.settings.at(n).particleCount;++r)this._physicsRig.particles.at(a+r).mobility=i.getParticleMobility(n,r),this._physicsRig.particles.at(a+r).delay=i.getParticleDelay(n,r),this._physicsRig.particles.at(a+r).acceleration=i.getParticleAcceleration(n,r),this._physicsRig.particles.at(a+r).radius=i.getParticleRadius(n,r),this._physicsRig.particles.at(a+r).position=i.getParticlePosition(n,r);a+=this._physicsRig.settings.at(n).particleCount}this.initialize(),i.release(),i=void 0,i=null}stabilization(t){var e,i,r,s;let a,n,o,l;const u=new be;let h,d,g,c;const m=t.getModel().parameters.values,p=t.getModel().parameters.maximumValues,_=t.getModel().parameters.minimumValues,f=t.getModel().parameters.defaultValues;(null!=(i=null==(e=this._parameterCaches)?void 0:e.length)?i:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(null!=(s=null==(r=this._parameterInputCaches)?void 0:r.length)?s:0)<t.getParameterCount()&&(this._parameterInputCaches=new Float32Array(t.getParameterCount()));for(let y=0;y<t.getParameterCount();++y)this._parameterCaches[y]=m[y],this._parameterInputCaches[y]=m[y];for(let y=0;y<this._physicsRig.subRigCount;++y){a={angle:0},u.x=0,u.y=0,h=this._physicsRig.settings.at(y),d=this._physicsRig.inputs.get(h.baseInputIndex),g=this._physicsRig.outputs.get(h.baseOutputIndex),c=this._physicsRig.particles.get(h.baseParticleIndex);for(let e=0;e<h.inputCount;++e)n=d[e].weight/100,-1==d[e].sourceParameterIndex&&(d[e].sourceParameterIndex=t.getParameterIndex(d[e].source.id)),d[e].getNormalizedParameterValue(u,a,m[d[e].sourceParameterIndex],_[d[e].sourceParameterIndex],p[d[e].sourceParameterIndex],f[d[e].sourceParameterIndex],h.normalizationPosition,h.normalizationAngle,d[e].reflect,n),this._parameterCaches[d[e].sourceParameterIndex]=m[d[e].sourceParameterIndex];o=we.degreesToRadian(-a.angle),u.x=u.x*we.cos(o)-u.y*we.sin(o),u.y=u.x*we.sin(o)+u.y*we.cos(o),ws(c,h.particleCount,u,a.angle,this._options.wind,.001*h.normalizationPosition.maximum);for(let e=0;e<h.outputCount;++e){const i=g[e].vertexIndex;if(-1==g[e].destinationParameterIndex&&(g[e].destinationParameterIndex=t.getParameterIndex(g[e].destination.id)),i<1||i>=h.particleCount)continue;let r=new be;r=c[i].position.substract(c[i-1].position),l=g[e].getValue(r,c,i,g[e].reflect,this._options.gravity),this._currentRigOutputs.at(y).outputs.set(e,l),this._previousRigOutputs.at(y).outputs.set(e,l);const s=g[e].destinationParameterIndex,a=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(m.subarray(s))):m.slice(s);Fs(a,_[s],p[s],l,g[e]);for(let t=s,e=0;t<this._parameterCaches.length;t++,e++)m[t]=this._parameterCaches[t]=a[e]}}}evaluate(t,e){var i,r,s,a;let n,o,l,u;const h=new be;let d,g,c,m;if(0>=e)return;const p=t.getModel().parameters.values,_=t.getModel().parameters.maximumValues,f=t.getModel().parameters.minimumValues,y=t.getModel().parameters.defaultValues;let x;if(this._currentRemainTime+=e,this._currentRemainTime>5&&(this._currentRemainTime=0),(null!=(r=null==(i=this._parameterCaches)?void 0:i.length)?r:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(null!=(a=null==(s=this._parameterInputCaches)?void 0:s.length)?a:0)<t.getParameterCount()){this._parameterInputCaches=new Float32Array(t.getParameterCount());for(let e=0;e<t.getParameterCount();++e)this._parameterInputCaches[e]=p[e]}for(x=this._physicsRig.fps>0?1/this._physicsRig.fps:e;this._currentRemainTime>=x;){for(let t=0;t<this._physicsRig.subRigCount;++t){d=this._physicsRig.settings.at(t),c=this._physicsRig.outputs.get(d.baseOutputIndex);for(let e=0;e<d.outputCount;++e)this._previousRigOutputs.at(t).outputs.set(e,this._currentRigOutputs.at(t).outputs.at(e))}const e=x/this._currentRemainTime;for(let i=0;i<t.getParameterCount();++i)this._parameterCaches[i]=this._parameterInputCaches[i]*(1-e)+p[i]*e,this._parameterInputCaches[i]=this._parameterCaches[i];for(let i=0;i<this._physicsRig.subRigCount;++i){n={angle:0},h.x=0,h.y=0,d=this._physicsRig.settings.at(i),g=this._physicsRig.inputs.get(d.baseInputIndex),c=this._physicsRig.outputs.get(d.baseOutputIndex),m=this._physicsRig.particles.get(d.baseParticleIndex);for(let e=0;e<d.inputCount;++e)o=g[e].weight/100,-1==g[e].sourceParameterIndex&&(g[e].sourceParameterIndex=t.getParameterIndex(g[e].source.id)),g[e].getNormalizedParameterValue(h,n,this._parameterCaches[g[e].sourceParameterIndex],f[g[e].sourceParameterIndex],_[g[e].sourceParameterIndex],y[g[e].sourceParameterIndex],d.normalizationPosition,d.normalizationAngle,g[e].reflect,o);l=we.degreesToRadian(-n.angle),h.x=h.x*we.cos(l)-h.y*we.sin(l),h.y=h.x*we.sin(l)+h.y*we.cos(l),Bs(m,d.particleCount,h,n.angle,this._options.wind,.001*d.normalizationPosition.maximum,x,5);for(let e=0;e<d.outputCount;++e){const r=c[e].vertexIndex;if(-1==c[e].destinationParameterIndex&&(c[e].destinationParameterIndex=t.getParameterIndex(c[e].destination.id)),r<1||r>=d.particleCount)continue;const s=new be;s.x=m[r].position.x-m[r-1].position.x,s.y=m[r].position.y-m[r-1].position.y,u=c[e].getValue(s,m,r,c[e].reflect,this._options.gravity),this._currentRigOutputs.at(i).outputs.set(e,u);const a=c[e].destinationParameterIndex,n=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(this._parameterCaches.subarray(a))):this._parameterCaches.slice(a);Fs(n,f[a],_[a],u,c[e]);for(let t=a,e=0;t<this._parameterCaches.length;t++,e++)this._parameterCaches[t]=n[e]}}this._currentRemainTime-=x}const C=this._currentRemainTime/x;this.interpolate(t,C)}interpolate(t,e){let i,r;const s=t.getModel().parameters.values,a=t.getModel().parameters.maximumValues,n=t.getModel().parameters.minimumValues;for(let o=0;o<this._physicsRig.subRigCount;++o){r=this._physicsRig.settings.at(o),i=this._physicsRig.outputs.get(r.baseOutputIndex);for(let t=0;t<r.outputCount;++t){if(-1==i[t].destinationParameterIndex)continue;const r=i[t].destinationParameterIndex,l=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(s.subarray(r))):s.slice(r);Fs(l,n[r],a[r],this._previousRigOutputs.at(o).outputs.at(t)*(1-e)+this._currentRigOutputs.at(o).outputs.at(t)*e,i[t]);for(let t=r,e=0;t<s.length;t++,e++)s[t]=l[e]}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._physicsRig=null,this._options=new ms,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=new p,this._previousRigOutputs=new p,this._currentRemainTime=0,this._parameterCaches=null,this._parameterInputCaches=null}release(){this._physicsRig=void 0,this._physicsRig=null}initialize(){let t,e,i;for(let r=0;r<this._physicsRig.subRigCount;++r){e=this._physicsRig.settings.at(r),t=this._physicsRig.particles.get(e.baseParticleIndex),t[0].initialPosition=new be(0,0),t[0].lastPosition=new be(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new be(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new be(0,0),t[0].force=new be(0,0);for(let r=1;r<e.particleCount;++r)i=new be(0,0),i.y=t[r].radius,t[r].initialPosition=new be(t[r-1].initialPosition.x+i.x,t[r-1].initialPosition.y+i.y),t[r].position=new be(t[r].initialPosition.x,t[r].initialPosition.y),t[r].lastPosition=new be(t[r].initialPosition.x,t[r].initialPosition.y),t[r].lastGravity=new be(0,-1),t[r].lastGravity.y*=-1,t[r].velocity=new be(0,0),t[r].force=new be(0,0)}}}class ms{constructor(){this.gravity=new be(0,0),this.wind=new be(0,0)}}class ps{constructor(){this.outputs=new p(0)}}function _s(t,e,i,r,s,a,n,o,l,u){t.x+=Is(i,r,s,a,n.minimum,n.maximum,n.defalut,l)*u}function fs(t,e,i,r,s,a,n,o,l,u){t.y+=Is(i,r,s,a,n.minimum,n.maximum,n.defalut,l)*u}function ys(t,e,i,r,s,a,n,o,l,u){e.angle+=Is(i,r,s,a,o.minimum,o.maximum,o.defalut,l)*u}function xs(t,e,i,r,s){let a=t.x;return r&&(a*=-1),a}function Cs(t,e,i,r,s){let a=t.y;return r&&(a*=-1),a}function Ms(t,e,i,r,s){let a;return s=i>=2?e[i-1].position.substract(e[i-2].position):s.multiplyByScaler(-1),a=we.directionToRadian(s,t),r&&(a*=-1),a}function Ss(t,e){return we.min(t,e)+function(t,e){const i=we.max(t,e),r=we.min(t,e);return we.abs(i-r)}(t,e)/2}function vs(t,e){return JSON.parse(JSON.stringify(t.x))}function bs(t,e){return JSON.parse(JSON.stringify(t.y))}function Ps(t,e){return JSON.parse(JSON.stringify(e))}function Bs(t,e,i,r,s,a,n,o){let l,u,h=new be(0,0),d=new be(0,0),g=new be(0,0),c=new be(0,0);t[0].position=new be(i.x,i.y);const m=we.degreesToRadian(r),p=we.radianToDirection(m);p.normalize();for(let _=1;_<e;++_)t[_].force=p.multiplyByScaler(t[_].acceleration).add(s),t[_].lastPosition=new be(t[_].position.x,t[_].position.y),l=t[_].delay*n*30,h=t[_].position.substract(t[_-1].position),u=we.directionToRadian(t[_].lastGravity,p)/o,h.x=we.cos(u)*h.x-h.y*we.sin(u),h.y=we.sin(u)*h.x+h.y*we.cos(u),t[_].position=t[_-1].position.add(h),d=t[_].velocity.multiplyByScaler(l),g=t[_].force.multiplyByScaler(l).multiplyByScaler(l),t[_].position=t[_].position.add(d).add(g),c=t[_].position.substract(t[_-1].position),c.normalize(),t[_].position=t[_-1].position.add(c.multiplyByScaler(t[_].radius)),we.abs(t[_].position.x)<a&&(t[_].position.x=0),0!=l&&(t[_].velocity=t[_].position.substract(t[_].lastPosition),t[_].velocity=t[_].velocity.divisionByScalar(l),t[_].velocity=t[_].velocity.multiplyByScaler(t[_].mobility)),t[_].force=new be(0,0),t[_].lastGravity=new be(p.x,p.y)}function ws(t,e,i,r,s,a){let n=new be(0,0);t[0].position=new be(i.x,i.y);const o=we.degreesToRadian(r),l=we.radianToDirection(o);l.normalize();for(let u=1;u<e;++u)t[u].force=l.multiplyByScaler(t[u].acceleration).add(s),t[u].lastPosition=new be(t[u].position.x,t[u].position.y),t[u].velocity=new be(0,0),n=t[u].force,n.normalize(),n=n.multiplyByScaler(t[u].radius),t[u].position=t[u-1].position.add(n),we.abs(t[u].position.x)<a&&(t[u].position.x=0),t[u].force=new be(0,0),t[u].lastGravity=new be(l.x,l.y)}function Fs(t,e,i,r,s){let a;a=r*s.getScale(s.translationScale,s.angleScale),a<e?(a<s.valueBelowMinimum&&(s.valueBelowMinimum=a),a=e):a>i&&(a>s.valueExceededMaximum&&(s.valueExceededMaximum=a),a=i);const n=s.weight/100;n>=1||(a=t[0]*(1-n)+a*n),t[0]=a}function Is(t,e,i,r,s,a,n,o){let l=0;const u=we.max(i,e);u<t&&(t=u);const h=we.min(i,e);h>t&&(t=h);const d=we.min(s,a),g=we.max(s,a),c=n,m=Ss(h,u),p=t-m;switch(function(t){let e=0;return t>0?e=1:t<0&&(e=-1),e}(p)){case 1:{const t=u-m;0!=t&&(l=p*((g-c)/t),l+=c);break}case-1:{const t=h-m;0!=t&&(l=p*((d-c)/t),l+=c);break}case 0:l=c}return o?l:-1*l}var Es;function Vs(){var t;null==(t=this.__moc)||t.release()}(t=>{t.CubismPhysics=cs,t.Options=ms})(Es||(Es={})),le.registerRuntime({version:4,ready:Mr,test:t=>t instanceof _r||_r.isValidJSON(t),isValidMoc(t){if(t.byteLength<4)return!1;const e=new Int8Array(t,0,4);return"MOC3"===String.fromCharCode(...e)},createModelSettings:t=>new _r(t),createCoreModel(t,e){const i=Dr.create(t,!!(null==e?void 0:e.checkMocConsistency));try{const t=i.createModel();return t.__moc=i,t}catch(r){try{i.release()}catch(s){_t.warn("CubismFactory","Failed to release moc after core model creation failed.",s)}throw r}},createInternalModel(t,e,i){const r=new hr(t,e,i),s=t;return s.__moc&&(r.__moc=s.__moc,delete s.__moc,r.once("destroy",Vs)),r},createPhysics(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism physics data must be an ArrayBuffer.");return cs.create(e,e.byteLength)},createPose(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism pose data must be an ArrayBuffer.");return Pr.create(e,e.byteLength)}}),t.Constant=dt,t.CubismExpressionManager=Ge,t.CubismFramework=ct,t.CubismInternalModel=hr,t.CubismModelSettings=_r,t.CubismMotionManager=yi,t.CubismParallelMotionManager=Pi,t.ExpressionManager=Bt,t.FileLoader=ne,t.FocusController=It,t.InternalModel=Ut,t.LOGICAL_HEIGHT=2,t.LOGICAL_WIDTH=2,t.Live2DFactory=le,t.Live2DLoader=Ht,t.Live2DModel=ve,t.Live2DPlugin=Se,t.Live2DTransform=me,t.LogLevel=mt,t.MBToByte=yt,t.ModelSettings=Et,t.MotionManager=Ot,t.MotionPreloadStrategy=At,t.MotionPriority=Vt,t.MotionState=Lt,t.Option=class{},t.SoundManager=Dt,t.VERSION="1.2.0",t.VOLUME=Tt,t.XHRLoader=Gt,t.applyMixins=Mt,t.clamp=ft,t.config=pt,t.configureCubismSDK=Cr,t.copyArray=Ct,t.copyProperty=xt,t.csmDelete=gt,t.cubismReady=Mr,t.folderName=St,t.logger=_t,t.normalizeHitAreaDefs=kt,t.rand=function(t,e){return Math.random()*(e-t)+t},t.reconfigureCubismSDK=function(t={}){Cr(t),ct.isInitialized()&&ct.dispose(),ct.isStarted()&&ct.cleanUp(),Sr(void 0,t.memorySizeMB)},t.remove=vt,t.resolveURL=Pt,t.startUpCubism=Sr,t.strtod=nt,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("pixi.js"),require("@pixi/sound")):"function"==typeof define&&define.amd?define(["exports","pixi.js","@pixi/sound"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).PIXI=t.PIXI||{},t.PIXI.live2d=t.PIXI.live2d||{}),t.PIXI,t.PIXI)}(this,function(t,e,i){"use strict";var r=Object.defineProperty,s=Object.defineProperties,a=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,u=Math.pow,h=(t,e,i)=>e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,d=(t,e)=>{for(var i in e||(e={}))o.call(e,i)&&h(t,i,e[i]);if(n)for(var i of n(e))l.call(e,i)&&h(t,i,e[i]);return t},g=(t,e,i)=>h(t,"symbol"!=typeof e?e+"":e,i),c=(t,e,i)=>new Promise((r,s)=>{var a=t=>{try{o(i.next(t))}catch(e){s(e)}},n=t=>{try{o(i.throw(t))}catch(e){s(e)}},o=t=>t.done?r(t.value):Promise.resolve(t.value).then(a,n);o((i=i.apply(t,e)).next())});const m=class t{constructor(t=0){t<1?(this._ptr=[],this._capacity=0,this._size=0):(this._ptr=new Array(t),this._capacity=t,this._size=0)}at(t){return this._ptr[t]}set(t,e){this._ptr[t]=e}get(t=0){const e=new Array;for(let i=t;i<this._size;i++)e.push(this._ptr[i]);return e}pushBack(e){this._size>=this._capacity&&this.prepareCapacity(0==this._capacity?t.DefaultSize:2*this._capacity),this._ptr[this._size++]=e}clear(){this._ptr.length=0,this._size=0}getSize(){return this._size}assign(t,e){this._size<t&&this.prepareCapacity(t);for(let i=0;i<t;i++)this._ptr[i]=e;this._size=t}resize(t,e=null){this.updateSize(t,e,!0)}updateSize(t,e=null,i=!0){if(this._size<t)if(this.prepareCapacity(t),i)for(let r=this._size;r<t;r++)this._ptr[r]="function"==typeof e?JSON.parse(JSON.stringify(new e)):e;else for(let r=this._size;r<t;r++)this._ptr[r]=e;else{const e=this._size-t;this._ptr.splice(this._size-e,e)}this._size=t}insert(t,e,i){let r=t._index;const s=e._index,a=i._index,n=a-s;this.prepareCapacity(this._size+n);const o=this._size-r;if(o>0)for(let l=0;l<o;l++)this._ptr.splice(r+l,0,null);for(let l=s;l<a;l++,r++)this._ptr[r]=e._vector._ptr[l];this._size=this._size+n}remove(t){return!(t<0||this._size<=t)&&(this._ptr.splice(t,1),--this._size,!0)}erase(t){const e=t._index;if(e<0||this._size<=e)return t;this._ptr.splice(e,1),--this._size;return new _(this,e)}prepareCapacity(t){t>this._capacity&&(0==this._capacity?(this._ptr=new Array(t),this._capacity=t):(this._ptr.length=t,this._capacity=t))}begin(){return 0==this._size?this.end():new _(this,0)}end(){return new _(this,this._size)}getOffset(e){const i=new t;return i._ptr=this.get(e),i._size=this.get(e).length,i._capacity=this.get(e).length,i}};m.DefaultSize=10;let p=m,_=class t{constructor(t,e){this._vector=null!=t?t:null,this._index=null!=e?e:0}set(t){return this._index=t._index,this._vector=t._vector,this}preIncrement(){return++this._index,this}preDecrement(){return--this._index,this}increment(){return new t(this._vector,this._index++)}decrement(){return new t(this._vector,this._index--)}ptr(){return this._vector._ptr[this._index]}substitution(t){return this._index=t._index,this._vector=t._vector,this}notEqual(t){return this._index!=t._index||this._vector!=t._vector}};var f,y,x,C,M,S,v;(y=f||(f={})).csmVector=p,y.iterator=_;class b{append(t,e){return this.s+=void 0!==e?t.substr(0,e):t,this}expansion(t,e){for(let i=0;i<t;i++)this.append(e);return this}getBytes(){return encodeURIComponent(this.s).replace(/%../g,"x").length}getLength(){return this.s.length}isLess(t){return this.s<t.s}isGreat(t){return this.s>t.s}isEqual(t){return this.s==t}isEmpty(){return 0==this.s.length}constructor(t){this.s=t}}(t=>{t.csmString=b})(x||(x={}));class P{static createIdInternal(t){return new P(t)}getString(){return this._id}isEqual(t){return"string"==typeof t?this._id.isEqual(t):t instanceof b?this._id.isEqual(t.s):t instanceof P&&this._id.isEqual(t._id.s)}isNotEqual(t){return"string"==typeof t?!this._id.isEqual(t):t instanceof b?!this._id.isEqual(t.s):t instanceof P&&!this._id.isEqual(t._id.s)}constructor(t){this._id="string"!=typeof t?t:new b(t)}}(t=>{t.CubismId=P})(C||(C={}));class B{constructor(){this._ids=new p}release(){for(let t=0;t<this._ids.getSize();++t)this._ids.set(t,void 0);this._ids=null}registerIds(t){for(let e=0;e<t.length;e++)this.registerId(t[e])}registerId(t){let e=null;return"string"!=typeof t?this.registerId(t.s):(null!=(e=this.findId(t))||(e=P.createIdInternal(t),this._ids.pushBack(e)),e)}getId(t){return this.registerId(t)}isExist(t){return"string"==typeof t?null!=this.findId(t):this.isExist(t.s)}findId(t){for(let e=0;e<this._ids.getSize();++e)if(this._ids.at(e).getString().isEqual(t))return this._ids.at(e);return null}}(t=>{t.CubismIdManager=B})(M||(M={}));class w{constructor(){this._tr=new Float32Array(16),this.loadIdentity()}static multiply(t,e,i){const r=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);for(let s=0;s<4;++s)for(let i=0;i<4;++i)for(let a=0;a<4;++a)r[i+4*s]+=t[a+4*s]*e[i+4*a];for(let s=0;s<16;++s)i[s]=r[s]}loadIdentity(){const t=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);this.setMatrix(t)}setMatrix(t){for(let e=0;e<16;++e)this._tr[e]=t[e]}getArray(){return this._tr}getScaleX(){return this._tr[0]}getScaleY(){return this._tr[5]}getTranslateX(){return this._tr[12]}getTranslateY(){return this._tr[13]}transformX(t){return this._tr[0]*t+this._tr[12]}transformY(t){return this._tr[5]*t+this._tr[13]}invertTransformX(t){return(t-this._tr[12])/this._tr[0]}invertTransformY(t){return(t-this._tr[13])/this._tr[5]}translateRelative(t,e){const i=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,t,e,0,1]);w.multiply(i,this._tr,this._tr)}translate(t,e){this._tr[12]=t,this._tr[13]=e}translateX(t){this._tr[12]=t}translateY(t){this._tr[13]=t}scaleRelative(t,e){const i=new Float32Array([t,0,0,0,0,e,0,0,0,0,1,0,0,0,0,1]);w.multiply(i,this._tr,this._tr)}scale(t,e){this._tr[0]=t,this._tr[5]=e}multiplyByMatrix(t){w.multiply(t.getArray(),this._tr,this._tr)}clone(){const t=new w;for(let e=0;e<this._tr.length;e++)t._tr[e]=this._tr[e];return t}}(t=>{t.CubismMatrix44=w})(S||(S={}));class F{constructor(t,e,i,r){this.x=t,this.y=e,this.width=i,this.height=r}getCenterX(){return this.x+.5*this.width}getCenterY(){return this.y+.5*this.height}getRight(){return this.x+this.width}getBottom(){return this.y+this.height}setRect(t){this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height}expand(t,e){this.x-=t,this.y-=e,this.width+=2*t,this.height+=2*e}}(t=>{t.csmRect=F})(v||(v={}));class I{static create(){return null}static delete(t){}initialize(t){this._model=t}drawModel(){null!=this.getModel()&&(this.saveProfile(),this.doDrawModel(),this.restoreProfile())}setMvpMatrix(t){this._mvpMatrix4x4.setMatrix(t.getArray())}getMvpMatrix(){return this._mvpMatrix4x4}setModelColor(t,e,i,r){t<0?t=0:t>1&&(t=1),e<0?e=0:e>1&&(e=1),i<0?i=0:i>1&&(i=1),r<0?r=0:r>1&&(r=1),this._modelColor.r=t,this._modelColor.g=e,this._modelColor.b=i,this._modelColor.a=r}getModelColor(){return JSON.parse(JSON.stringify(this._modelColor))}getModelColorWithOpacity(t){const e=this.getModelColor();return e.a*=t,this.isPremultipliedAlpha()&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}setIsPremultipliedAlpha(t){this._isPremultipliedAlpha=t}isPremultipliedAlpha(){return this._isPremultipliedAlpha}setIsCulling(t){this._isCulling=t}isCulling(){return this._isCulling}setAnisotropy(t){this._anisotropy=t}getAnisotropy(){return this._anisotropy}getModel(){return this._model}useHighPrecisionMask(t){this._useHighPrecisionMask=t}isUsingHighPrecisionMask(){return this._useHighPrecisionMask}constructor(){this._isCulling=!1,this._isPremultipliedAlpha=!1,this._anisotropy=0,this._model=null,this._modelColor=new L,this._useHighPrecisionMask=!1,this._mvpMatrix4x4=new w,this._mvpMatrix4x4.loadIdentity()}}var E,V=(t=>(t[t.CubismBlendMode_Normal=0]="CubismBlendMode_Normal",t[t.CubismBlendMode_Additive=1]="CubismBlendMode_Additive",t[t.CubismBlendMode_Multiplicative=2]="CubismBlendMode_Multiplicative",t))(V||{});class L{constructor(t=1,e=1,i=1,r=1){this.r=t,this.g=e,this.b=i,this.a=r}}class R{constructor(t,e){this._clippingIdList=t,this._clippingIdCount=e,this._allClippedDrawRect=new F,this._layoutBounds=new F,this._clippedDrawableIndexList=[],this._matrixForMask=new w,this._matrixForDraw=new w,this._bufferIndex=0}release(){null!=this._layoutBounds&&(this._layoutBounds=null),null!=this._allClippedDrawRect&&(this._allClippedDrawRect=null),null!=this._clippedDrawableIndexList&&(this._clippedDrawableIndexList=null)}addClippedDrawable(t){this._clippedDrawableIndexList.push(t)}}(t=>{t.CubismBlendMode=V,t.CubismRenderer=I,t.CubismTextureColor=L})(E||(E={}));const T=Object.freeze(Object.defineProperty({__proto__:null,CSM_LOG_LEVEL:0,CSM_LOG_LEVEL_DEBUG:1,CSM_LOG_LEVEL_ERROR:4,CSM_LOG_LEVEL_INFO:2,CSM_LOG_LEVEL_OFF:5,CSM_LOG_LEVEL_VERBOSE:0,CSM_LOG_LEVEL_WARNING:3},Symbol.toStringTag,{value:"Module"})),D=(t,e,i)=>{((t,e,i)=>{z.print(t,"[CSM]"+e,i)})(t,e+"\n",i)},A=t=>{console.assert(t)};let O,k,N,U;O=(t,...e)=>{D(mt.LogLevel_Debug,"[D]"+t,e)},k=(t,...e)=>{D(mt.LogLevel_Info,"[I]"+t,e)},N=(t,...e)=>{D(mt.LogLevel_Warning,"[W]"+t,e)},U=(t,...e)=>{D(mt.LogLevel_Error,"[E]"+t,e)};class z{static print(t,e,i){if(t<ct.getLoggingLevel())return;const r=ct.coreLogFunction;if(!r)return;r(e.replace(/\{(\d+)\}/g,(t,e)=>i[e]))}static dumpBytes(t,e,i){for(let r=0;r<i;r++)r%16==0&&r>0?this.print(t,"\n"):r%8==0&&r>0&&this.print(t," "),this.print(t,"{0} ",[255&e[r]]);this.print(t,"\n")}constructor(){}}var j;(t=>{t.CubismDebug=z})(j||(j={}));class G{constructor(t,e){this.first=null==t?null:t,this.second=null==e?null:e}}const X=class t{constructor(t){null!=t?t<1?(this._keyValues=[],this._dummyValue=null,this._size=0):(this._keyValues=new Array(t),this._size=t):(this._keyValues=[],this._dummyValue=null,this._size=0)}release(){this.clear()}appendKey(t){let e=-1;for(let i=0;i<this._size;i++)if(this._keyValues[i].first==t){e=i;break}-1==e?(this.prepareCapacity(this._size+1,!1),this._keyValues[this._size]=new G(t),this._size+=1):N("The key `{0}` is already append.",t)}getValue(t){let e=-1;for(let i=0;i<this._size;i++)if(this._keyValues[i].first==t){e=i;break}return e>=0?this._keyValues[e].second:(this.appendKey(t),this._keyValues[this._size-1].second)}setValue(t,e){let i=-1;for(let r=0;r<this._size;r++)if(this._keyValues[r].first==t){i=r;break}i>=0?this._keyValues[i].second=e:(this.appendKey(t),this._keyValues[this._size-1].second=e)}isExist(t){for(let e=0;e<this._size;e++)if(this._keyValues[e].first==t)return!0;return!1}clear(){this._keyValues=void 0,this._keyValues=null,this._keyValues=[],this._size=0}getSize(){return this._size}prepareCapacity(e,i){e>this._keyValues.length&&(0==this._keyValues.length?(!i&&e<t.DefaultSize&&(e=t.DefaultSize),this._keyValues.length=e):(!i&&e<2*this._keyValues.length&&(e=2*this._keyValues.length),this._keyValues.length=e))}begin(){return new q(this,0)}end(){return new q(this,this._size)}erase(t){const e=t._index;if(e<0||this._size<=e)return t;this._keyValues.splice(e,1),--this._size;return new q(this,e)}dumpAsInt(){for(let t=0;t<this._size;t++)O("{0} ,",this._keyValues[t]),O("\n")}};X.DefaultSize=10;let H=X;class q{constructor(t,e){this._map=null!=t?t:new H,this._index=null!=e?e:0}set(t){return this._index=t._index,this._map=t._map,this}preIncrement(){return++this._index,this}preDecrement(){return--this._index,this}increment(){return new q(this._map,this._index++)}decrement(){const t=new q(this._map,this._index);return this._map=t._map,this._index=t._index,this}ptr(){return this._map._keyValues[this._index]}notEqual(t){return this._index!=t._index||this._map!=t._map}}var Y;(t=>{t.csmMap=H,t.csmPair=G,t.iterator=q})(Y||(Y={}));class W{static parseJsonObject(t,e){return Object.keys(t).forEach(i=>{if("boolean"==typeof t[i]){const r=Boolean(t[i]);e.put(i,new Q(r))}else if("string"==typeof t[i]){const r=String(t[i]);e.put(i,new tt(r))}else if("number"==typeof t[i]){const r=Number(t[i]);e.put(i,new K(r))}else t[i]instanceof Array?e.put(i,W.parseJsonArray(t[i])):t[i]instanceof Object?e.put(i,W.parseJsonObject(t[i],new st)):null==t[i]?e.put(i,new it):e.put(i,t[i])}),e}static parseJsonArray(t){const e=new rt;return Object.keys(t).forEach(i=>{if("number"==typeof Number(i))if("boolean"==typeof t[i]){const r=Boolean(t[i]);e.add(new Q(r))}else if("string"==typeof t[i]){const r=String(t[i]);e.add(new tt(r))}else if("number"==typeof t[i]){const r=Number(t[i]);e.add(new K(r))}else t[i]instanceof Array?e.add(this.parseJsonArray(t[i])):t[i]instanceof Object?e.add(this.parseJsonObject(t[i],new st)):null==t[i]?e.add(new it):e.add(t[i]);else if(t[i]instanceof Array)e.add(this.parseJsonArray(t[i]));else if(t[i]instanceof Object)e.add(this.parseJsonObject(t[i],new st));else if(null==t[i])e.add(new it);else{const r=Array(t[i]);for(let t=0;t<r.length;t++)e.add(r[t])}}),e}}const J="Error: type mismatch";let $=class t{constructor(){}getRawString(t,e){return this.getString(t,e)}toInt(t=0){return t}toFloat(t=0){return t}toBoolean(t=!1){return t}getSize(){return 0}getArray(t=null){return t}getVector(t=new p){return t}getMap(t){return t}getValueByIndex(e){return t.errorValue.setErrorNotForClientCall(J)}getValueByString(e){return t.nullValue.setErrorNotForClientCall(J)}getKeys(){return t.dummyKeys}isError(){return!1}isNull(){return!1}isBool(){return!1}isFloat(){return!1}isString(){return!1}isArray(){return!1}isMap(){return!1}equals(t){return!1}isStatic(){return!1}setErrorNotForClientCall(t){return et.errorValue}static staticInitializeNotForClientCall(){Q.trueValue=new Q(!0),Q.falseValue=new Q(!1),t.errorValue=new et("ERROR",!0),t.nullValue=new it,t.dummyKeys=new p}static staticReleaseNotForClientCall(){Q.trueValue=null,Q.falseValue=null,t.errorValue=null,t.nullValue=null,t.dummyKeys=null}};class Z{constructor(t,e){this._parseCallback=W.parseJsonObject,this._error=null,this._lineCount=0,this._root=null,null!=t&&this.parseBytes(t,e,this._parseCallback)}static create(t,e){const i=new Z;return i.parseBytes(t,e,i._parseCallback)?i:(Z.delete(i),null)}static delete(t){}getRoot(){return this._root}static arrayBufferToString(t){const e=new Uint8Array(t);let i="";for(let r=0,s=e.length;r<s;++r)i+="%"+this.pad(e[r].toString(16));return i=decodeURIComponent(i),i}static pad(t){return t.length<2?"0"+t:t}parseBytes(t,e,i){const r=new Array(1),s=Z.arrayBufferToString(t);if(this._root=null==i?this.parseValue(s,e,0,r):i(JSON.parse(s),new st),this._error){let t="\0";return t="Json parse error : @line "+(this._lineCount+1)+"\n",this._root=new tt(t),k("{0}",this._root.getRawString()),!1}return null!=this._root||(this._root=new et(new b(this._error),!1),!1)}getParseError(){return this._error}checkEndOfFile(){return this._root.getArray()[1].equals("EOF")}parseValue(t,e,i,r){if(this._error)return null;let s,a=null,n=i;for(;n<e;n++){switch(t[n]){case"-":case".":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{const e=new Array(1);return s=nt(t.slice(n),e),r[0]=t.indexOf(e[0]),new K(s)}case'"':return new tt(this.parseString(t,e,n+1,r));case"[":return a=this.parseArray(t,e,n+1,r),a;case"{":return a=this.parseObject(t,e,n+1,r),a;case"n":return n+3<e?(a=new it,r[0]=n+4):this._error="parse null",a;case"t":return n+3<e?(a=Q.trueValue,r[0]=n+4):this._error="parse true",a;case"f":return n+4<e?(a=Q.falseValue,r[0]=n+5):this._error="illegal ',' position",a;case",":return this._error="illegal ',' position",null;case"]":return r[0]=n,null;case"\n":this._lineCount++}}return this._error="illegal end of value",null}parseString(t,e,i,r){if(this._error)return null;if(!t)return this._error="string is null",null;let s,a,n=i;const o=new b("");let l=i;for(;n<e;n++)switch(s=t[n],s){case'"':return r[0]=n+1,o.append(t.slice(l),n-l),o.s;case"//":if(n++,n-1>l&&o.append(t.slice(l),n-l),l=n+1,n<e)switch(a=t[n],a){case"\\":o.expansion(1,"\\");break;case'"':o.expansion(1,'"');break;case"/":o.expansion(1,"/");break;case"b":o.expansion(1,"\b");break;case"f":o.expansion(1,"\f");break;case"n":o.expansion(1,"\n");break;case"r":o.expansion(1,"\r");break;case"t":o.expansion(1,"\t");break;case"u":this._error="parse string/unicord escape not supported"}else this._error="parse string/escape error"}return this._error="parse string/illegal end",null}parseObject(t,e,i,r){if(this._error)return null;if(!t)return this._error="buffer is null",null;const s=new st;let a="",n=i,o="";const l=Array(1);let u=!1;for(;n<e;n++){t:for(;n<e;n++)switch(o=t[n],o){case'"':if(a=this.parseString(t,e,n+1,l),this._error)return null;n=l[0],u=!0;break t;case"}":return r[0]=n+1,s;case":":this._error="illegal ':' position";break;case"\n":this._lineCount++}if(!u)return this._error="key not found",null;u=!1;t:for(;n<e;n++)switch(o=t[n],o){case":":u=!0,n++;break t;case"}":this._error="illegal '}' position";break;case"\n":this._lineCount++}if(!u)return this._error="':' not found",null;const i=this.parseValue(t,e,n,l);if(this._error)return null;n=l[0],s.put(a,i);t:for(;n<e;n++)switch(o=t[n],o){case",":break t;case"}":return r[0]=n+1,s;case"\n":this._lineCount++}}return this._error="illegal end of perseObject",null}parseArray(t,e,i,r){if(this._error)return null;if(!t)return this._error="buffer is null",null;let s,a=new rt,n=i;const o=new Array(1);for(;n<e;n++){const i=this.parseValue(t,e,n,o);if(this._error)return null;n=o[0],i&&a.add(i);t:for(;n<e;n++)switch(s=t[n],s){case",":break t;case"]":return r[0]=n+1,a;case"\n":++this._lineCount}}return a=void 0,this._error="illegal end of parseObject",null}}class K extends ${constructor(t){super(),this._value=t}isFloat(){return!0}getString(t,e){return this._value=parseFloat("\0"),this._stringBuffer="\0",this._stringBuffer}toInt(t=0){return parseInt(this._value.toString())}toFloat(t=0){return this._value}equals(t){return"number"==typeof t&&(!Math.round(t)&&t==this._value)}}class Q extends ${isBool(){return!0}toBoolean(t=!1){return this._boolValue}getString(t,e){return this._stringBuffer=this._boolValue?"true":"false",this._stringBuffer}equals(t){return"boolean"==typeof t&&t==this._boolValue}isStatic(){return!0}constructor(t){super(),this._boolValue=t}}class tt extends ${constructor(t){super(),"string"==typeof t&&(this._stringBuffer=t),t instanceof b&&(this._stringBuffer=t.s)}isString(){return!0}getString(t,e){return this._stringBuffer}equals(t){return"string"==typeof t?this._stringBuffer==t:t instanceof b&&this._stringBuffer==t.s}}class et extends tt{isStatic(){return this._isStatic}setErrorNotForClientCall(t){return this._stringBuffer=t,this}constructor(t,e){super(t),this._isStatic=e}isError(){return!0}}class it extends ${isNull(){return!0}getString(t,e){return this._stringBuffer}isStatic(){return!0}setErrorNotForClientCall(t){return this._stringBuffer=t,et.nullValue}constructor(){super(),this._stringBuffer="NullValue"}}class rt extends ${constructor(){super(),this._array=new p}release(){for(let t=this._array.begin();t.notEqual(this._array.end());t.preIncrement()){let e=t.ptr();e&&!e.isStatic()&&(e=void 0,e=null)}}isArray(){return!0}getValueByIndex(t){if(t<0||this._array.getSize()<=t)return $.errorValue.setErrorNotForClientCall("Error: index out of bounds");const e=this._array.at(t);return null==e?$.nullValue:e}getValueByString(t){return $.errorValue.setErrorNotForClientCall(J)}getString(t,e){const i=e+"[\n";for(let r=this._array.begin();r.notEqual(this._array.end());r.increment()){const t=r.ptr();this._stringBuffer+=e+""+t.getString(e+" ")+"\n"}return this._stringBuffer=i+e+"]\n",this._stringBuffer}add(t){this._array.pushBack(t)}getVector(t=null){return this._array}getSize(){return this._array.getSize()}}class st extends ${constructor(){super(),this._map=new H}release(){const t=this._map.begin();for(;t.notEqual(this._map.end());){let e=t.ptr().second;e&&!e.isStatic()&&(e=void 0,e=null),t.preIncrement()}}isMap(){return!0}getValueByString(t){if(t instanceof b){const e=this._map.getValue(t.s);return null==e?$.nullValue:e}for(let e=this._map.begin();e.notEqual(this._map.end());e.preIncrement())if(e.ptr().first==t)return null==e.ptr().second?$.nullValue:e.ptr().second;return $.nullValue}getValueByIndex(t){return $.errorValue.setErrorNotForClientCall(J)}getString(t,e){this._stringBuffer=e+"{\n";const i=this._map.begin();for(;i.notEqual(this._map.end());){const t=i.ptr().first,r=i.ptr().second;this._stringBuffer+=e+" "+t+" : "+r.getString(e+" ")+" \n",i.preIncrement()}return this._stringBuffer+=e+"}\n",this._stringBuffer}getMap(t){return this._map}put(t,e){this._map.setValue(t,e)}getKeys(){if(!this._keys){this._keys=new p;const t=this._map.begin();for(;t.notEqual(this._map.end());){const e=t.ptr().first;this._keys.pushBack(e),t.preIncrement()}}return this._keys}getSize(){return this._keys.getSize()}}var at;function nt(t,e){let i=0;for(let s=1;;s++){const e=t.slice(s-1,s);if("e"==e||"-"==e||"E"==e)continue;const r=t.substring(0,s),a=Number(r);if(isNaN(a))break;i=s}let r=parseFloat(t);return isNaN(r)&&(r=NaN),e[0]=t.slice(i),r}(t=>{t.CubismJson=Z,t.JsonArray=rt,t.JsonBoolean=Q,t.JsonError=et,t.JsonFloat=K,t.JsonMap=st,t.JsonNullvalue=it,t.JsonString=tt,t.Value=$})(at||(at={}));let ot=!1,lt=!1,ut=null,ht=null;const dt=Object.freeze({vertexOffset:0,vertexStep:2});function gt(t){t&&(t=void 0)}class ct{static startUp(t=null){if(ot)return k("CubismFramework.startUp() is already done."),ot;if(ut=t,null!=ut&&Live2DCubismCore.Logging.csmSetLogFunction(ut.logFunction),ot=!0,ot){const t=Live2DCubismCore.Version.csmGetVersion(),e=(16711680&t)>>16,i=65535&t,r=t;k("Live2D Cubism Core version: {0}.{1}.{2} ({3})",("00"+((4278190080&t)>>24)).slice(-2),("00"+e).slice(-2),("0000"+i).slice(-4),r)}return k("CubismFramework.startUp() is complete."),ot}static cleanUp(){ot=!1,lt=!1,ut=null,ht=null}static initialize(t=0){A(ot),ot?lt?N("CubismFramework.initialize() skipped, already initialized."):($.staticInitializeNotForClientCall(),ht=new B,Live2DCubismCore.Memory.initializeAmountOfMemory(t),lt=!0,k("CubismFramework.initialize() is complete.")):N("CubismFramework is not started.")}static dispose(){A(ot),ot?lt?($.staticReleaseNotForClientCall(),ht.release(),ht=null,I.staticRelease(),lt=!1,k("CubismFramework.dispose() is complete.")):N("CubismFramework.dispose() skipped, not initialized."):N("CubismFramework is not started.")}static isStarted(){return ot}static isInitialized(){return lt}static coreLogFunction(t){Live2DCubismCore.Logging.csmGetLogFunction()&&Live2DCubismCore.Logging.csmGetLogFunction()(t)}static getLoggingLevel(){return null!=ut?ut.loggingLevel:5}static getIdManager(){return ht}constructor(){}}var mt=(t=>(t[t.LogLevel_Verbose=0]="LogLevel_Verbose",t[t.LogLevel_Debug=1]="LogLevel_Debug",t[t.LogLevel_Info=2]="LogLevel_Info",t[t.LogLevel_Warning=3]="LogLevel_Warning",t[t.LogLevel_Error=4]="LogLevel_Error",t[t.LogLevel_Off=5]="LogLevel_Off",t))(mt||{});t.Live2DCubismFramework=void 0,(t=>{t.Constant=dt,t.csmDelete=gt,t.CubismFramework=ct})(t.Live2DCubismFramework||(t.Live2DCubismFramework={}));const pt={LOG_LEVEL_VERBOSE:0,LOG_LEVEL_WARNING:1,LOG_LEVEL_ERROR:2,LOG_LEVEL_NONE:999,logLevel:1,sound:!0,fftSize:512,motionSync:!0,motionFadingDuration:500,idleMotionFadingDuration:2e3,expressionFadingDuration:500,preserveExpressionOnMotion:!0,cubism:T},_t={log(t,...e){pt.logLevel<=pt.LOG_LEVEL_VERBOSE&&console.log(`[${t}]`,...e)},warn(t,...e){pt.logLevel<=pt.LOG_LEVEL_WARNING&&console.warn(`[${t}]`,...e)},error(t,...e){pt.logLevel<=pt.LOG_LEVEL_ERROR&&console.error(`[${t}]`,...e)}};function ft(t,e,i){return t<e?e:t>i?i:t}function yt(t){return 1024*t*1024}function xt(t,e,i,r,s){const a=e[r];null!==a&&typeof a===t&&(i[s]=a)}function Ct(t,e,i,r,s){const a=e[r];Array.isArray(a)&&(i[s]=a.filter(e=>null!==e&&typeof e===t))}function Mt(t,e){e.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i))})})}function St(t){let e=t.lastIndexOf("/");return-1!=e&&(t=t.slice(0,e)),e=t.lastIndexOf("/"),-1!==e&&(t=t.slice(e+1)),t}function vt(t,e){const i=t.indexOf(e);-1!==i&&t.splice(i,1)}const bt=/^[a-zA-Z][a-zA-Z0-9+.-]*:/;function Pt(t,e){if(!e)return t;if(bt.test(e))return e;if(e.startsWith("/"))return bt.test(t)?new URL(e,t).toString():e;if(bt.test(t))return new URL(e,t).toString();const i="http://example.com",r=t.startsWith("/")?i+t:`${i}/${t}`,s=new URL(e,r);let a=s.pathname+s.search+s.hash;return!t.startsWith("/")&&a.startsWith("/")&&(a=a.slice(1)),a}class Bt extends e.EventEmitter{constructor(t,e){super(),g(this,"expressionDataType","json"),g(this,"tag"),g(this,"settings"),g(this,"expressions",[]),g(this,"defaultExpression"),g(this,"currentExpression"),g(this,"reserveExpressionIndex",-1),g(this,"destroyed",!1),this.settings=t,this.tag=`ExpressionManager(${t.name})`}init(){this.defaultExpression=this.createDefaultExpression(),this.currentExpression=this.defaultExpression,this.stopAllExpressions()}createDefaultExpression(){return this.createExpression({},void 0)}loadExpression(t){return c(this,null,function*(){if(!this.definitions[t])return void _t.warn(this.tag,`Undefined expression at [${t}]`);if(null===this.expressions[t])return void _t.warn(this.tag,`Cannot set expression at [${t}] because it's already failed in loading.`);if(this.expressions[t])return this.expressions[t];const e=yield this._loadExpression(t);return this.expressions[t]=e,e})}_loadExpression(t){throw new Error("Not implemented.")}setRandomExpression(){return c(this,null,function*(){if(this.definitions.length){const t=[];for(let e=0;e<this.definitions.length;e++)null!==this.expressions[e]&&this.expressions[e]!==this.currentExpression&&e!==this.reserveExpressionIndex&&t.push(e);if(t.length){const e=Math.floor(Math.random()*t.length);return this.setExpression(e)}}return!1})}resetExpression(){this._setExpression(this.defaultExpression)}restoreExpression(){this._setExpression(this.currentExpression)}setExpression(t){return c(this,null,function*(){if("number"!=typeof t&&(t=this.getExpressionIndex(t)),!(t>-1&&t<this.definitions.length))return!1;if(t===this.expressions.indexOf(this.currentExpression))return!1;this.reserveExpressionIndex=t;const e=yield this.loadExpression(t);return!(!e||this.reserveExpressionIndex!==t)&&(this.reserveExpressionIndex=-1,this.currentExpression=e,this._setExpression(e),!0)})}update(t,e){return!this.isFinished()&&this.updateParameters(t,e)}destroy(){this.destroyed=!0,this.emit("destroy");this.definitions=void 0,this.expressions=void 0}}const wt=40/7.5,Ft=1/150;class It{constructor(){g(this,"targetX",0),g(this,"targetY",0),g(this,"x",0),g(this,"y",0),g(this,"vx",0),g(this,"vy",0)}focus(t,e,i=!1){this.targetX=ft(t,-1,1),this.targetY=ft(e,-1,1),i&&(this.x=this.targetX,this.y=this.targetY)}update(t){const e=this.targetX-this.x,i=this.targetY-this.y;if(Math.abs(e)<.01&&Math.abs(i)<.01)return;const r=Math.sqrt(u(e,2)+u(i,2)),s=wt/(1e3/t);let a=s*(e/r)-this.vx,n=s*(i/r)-this.vy;const o=Math.sqrt(u(a,2)+u(n,2)),l=s*Ft*t;o>l&&(a*=l/o,n*=l/o),this.vx+=a,this.vy+=n;const h=Math.sqrt(u(this.vx,2)+u(this.vy,2)),d=.5*(Math.sqrt(u(l,2)+8*l*r)-l);h>d&&(this.vx*=d/h,this.vy*=d/h),this.x+=this.vx,this.y+=this.vy}}class Et{constructor(t){g(this,"json"),g(this,"name"),g(this,"url"),g(this,"pose"),g(this,"physics"),this.json=t,this.url=t.url,this.name=St(this.url)}normalizeName(){this.name&&"name"!==this.name.toLowerCase()||(this.name=St(this.url))}setModelName(...t){for(const e of t){const t="string"==typeof e?e.trim():"";if(t&&"name"!==t.toLowerCase())return void(this.name=t)}this.normalizeName()}getFileStem(t){if(!t)return;const e=t.split(/[/\\]/).filter(Boolean).pop();return null==e?void 0:e.replace(/\.[^.]+$/,"")}resolveURL(t){return Pt(this.url,t)}replaceFiles(t){this.moc=t(this.moc,"moc"),void 0!==this.pose&&(this.pose=t(this.pose,"pose")),void 0!==this.physics&&(this.physics=t(this.physics,"physics"));for(let e=0;e<this.textures.length;e++)this.textures[e]=t(this.textures[e],`textures[${e}]`)}getDefinedFiles(){const t=[];return this.replaceFiles(e=>(t.push(e),e)),t}validateFiles(t){const e=(e,i)=>{const r=this.resolveURL(e);if(!t.includes(r)){if(i)throw new Error(`File "${e}" is defined in settings, but doesn't exist in given files`);return!1}return!0};[this.moc,...this.textures].forEach(t=>e(t,!0));return this.getDefinedFiles().filter(t=>e(t,!1))}}var Vt=(t=>(t[t.NONE=0]="NONE",t[t.IDLE=1]="IDLE",t[t.NORMAL=2]="NORMAL",t[t.FORCE=3]="FORCE",t))(Vt||{});class Lt{constructor(){g(this,"tag"),g(this,"debug",!1),g(this,"currentPriority",0),g(this,"reservePriority",0),g(this,"currentGroup"),g(this,"currentIndex"),g(this,"reservedGroup"),g(this,"reservedIndex"),g(this,"reservedIdleGroup"),g(this,"reservedIdleIndex")}reserve(t,e,i){if(i<=0)return _t.log(this.tag,"Cannot start a motion with MotionPriority.NONE."),!1;if(t===this.currentGroup&&e===this.currentIndex)return _t.log(this.tag,"Motion is already playing.",this.dump(t,e)),!1;if(t===this.reservedGroup&&e===this.reservedIndex||t===this.reservedIdleGroup&&e===this.reservedIdleIndex)return _t.log(this.tag,"Motion is already reserved.",this.dump(t,e)),!1;if(1===i){if(0!==this.currentPriority)return _t.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(t,e)),!1;if(void 0!==this.reservedIdleGroup)return _t.log(this.tag,"Cannot start idle motion because another idle motion has reserved.",this.dump(t,e)),!1;this.setReservedIdle(t,e)}else{if(i<3){if(i<=this.currentPriority)return _t.log(this.tag,"Cannot start motion because another motion is playing as an equivalent or higher priority.",this.dump(t,e)),!1;if(i<=this.reservePriority)return _t.log(this.tag,"Cannot start motion because another motion has reserved as an equivalent or higher priority.",this.dump(t,e)),!1}this.setReserved(t,e,i)}return!0}start(t,e,i,r){if(1===r){if(this.setReservedIdle(void 0,void 0),0!==this.currentPriority)return _t.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(e,i)),!1}else{if(e!==this.reservedGroup||i!==this.reservedIndex)return _t.log(this.tag,"Cannot start motion because another motion has taken the place.",this.dump(e,i)),!1;this.setReserved(void 0,void 0,0)}return!!t&&(this.setCurrent(e,i,r),!0)}complete(){this.setCurrent(void 0,void 0,0)}setCurrent(t,e,i){this.currentPriority=i,this.currentGroup=t,this.currentIndex=e}setReserved(t,e,i){this.reservePriority=i,this.reservedGroup=t,this.reservedIndex=e}setReservedIdle(t,e){this.reservedIdleGroup=t,this.reservedIdleIndex=e}isActive(t,e){return t===this.currentGroup&&e===this.currentIndex||t===this.reservedGroup&&e===this.reservedIndex||t===this.reservedIdleGroup&&e===this.reservedIdleIndex}reset(){this.setCurrent(void 0,void 0,0),this.setReserved(void 0,void 0,0),this.setReservedIdle(void 0,void 0)}shouldRequestIdleMotion(){return void 0===this.currentGroup&&void 0===this.reservedIdleGroup}shouldOverrideExpression(){return!pt.preserveExpressionOnMotion&&this.currentPriority>1}dump(t,e){if(this.debug){return`\n<Requested> group = "${t}", index = ${e}\n`+["currentPriority","reservePriority","currentGroup","currentIndex","reservedGroup","reservedIndex","reservedIdleGroup","reservedIdleIndex"].map(t=>"["+t+"] "+this[t]).join("\n")}return""}}const Rt="SoundManager",Tt=.5;i.sound.disableAutoPause=!0;class Dt{static get volume(){return this._volume}static set volume(t){this._volume=(t>1?1:t<0?0:t)||0,this.audios.forEach(t=>t.volume=this._volume)}static add(t,e){return c(this,null,function*(){try{const e=new Promise((e,r)=>{const s=i.Sound.from({url:t,volume:this._volume,preload:!0,loaded:()=>{s.media instanceof i.webaudio.WebAudioMedia||r(new Error(`Error: ${t} is not WebAudioMedia`)),e(s)}})});return yield e}catch(r){return _t.warn(Rt,`Error occurred on "${t}"`,r),null==e||e(r),null}})}static play(t,e){t.play({singleInstance:!0,complete:()=>{null==e||e(),t.destroy()}})}static addAnalyzer(t,e){const i=t.media,r=e.createBufferSource();r.buffer=i.buffer;const s=e.createAnalyser();return s.fftSize=pt.fftSize,s.minDecibels=-90,s.maxDecibels=-10,s.smoothingTimeConstant=.85,r.connect(s),r.start(0),this.analysers.push(s),s}static analyze(t){if(!t)return parseFloat(Math.random().toFixed(1));const e=new Float32Array(t.fftSize);t.getFloatTimeDomainData(e);let i=0;for(let n=0;n<e.length;n++)i+=u(e[n],2);const r=Math.sqrt(i/e.length),s=20*Math.log10(r||u(10,-5)),a=Math.min(Math.max((s-t.minDecibels)/(t.maxDecibels-t.minDecibels),0),1);return parseFloat(a.toFixed(1))}static dispose(t){t.pause(),vt(this.audios,t)}static destroy(){for(let t=this.contexts.length-1;t>=0;t--){const e=this.contexts[t];null==e||e.close().catch(t=>{_t.warn(Rt,"Failed to close AudioContext.",t)})}for(let t=this.audios.length-1;t>=0;t--)this.dispose(this.audios[t])}}g(Dt,"audios",[]),g(Dt,"analysers",[]),g(Dt,"contexts",[]),g(Dt,"_volume",Tt);var At=(t=>(t.ALL="ALL",t.IDLE="IDLE",t.NONE="NONE",t))(At||{});class Ot extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"settings"),g(this,"motionGroups",{}),g(this,"state",new Lt),g(this,"currentAudio"),g(this,"currentAnalyzer"),g(this,"currentContext"),g(this,"playing",!1),g(this,"destroyed",!1),g(this,"parent"),this.settings=t.settings,this.tag=`MotionManager(${this.settings.name})`,this.state.tag=this.tag,this.parent=t}init(t){(null==t?void 0:t.idleMotionGroup)&&(this.groups.idle=t.idleMotionGroup),this.setupMotions(t),this.stopAllMotions()}setupMotions(t){if(!this.definitions)return void _t.warn(this.tag,"Motion definitions are not initialized.");for(const i of Object.keys(this.definitions))this.motionGroups[i]=[];let e;switch(null==t?void 0:t.motionPreload){case"NONE":return;case"ALL":e=Object.keys(this.definitions);break;default:e=[this.groups.idle]}for(const i of e){const t=this.definitions[i];if(t)for(let e=0;e<t.length;e++)this.loadMotion(i,e)}}loadMotion(t,e){return c(this,null,function*(){var i,r;if(this.destroyed)return;if(!this.getMotionDefinition(t,e))return;const s=null!=(r=(i=this.motionGroups)[t])?r:i[t]=[];if(null===s[e])return void _t.warn(this.tag,`Cannot start motion at "${t}"[${e}] because it's already failed in loading.`);if(s[e])return s[e];const a=yield this._loadMotion(t,e);return this.destroyed?void 0:(s[e]=null!=a?a:null,a)})}_loadMotion(t,e){throw new Error("Not implemented.")}initializeAudio(t,e){this.currentAudio=t,Dt.volume=e,this.currentContext=t.context.audioContext,this.currentAnalyzer=Dt.addAnalyzer(this.currentAudio,this.currentContext)}speak(t){return c(this,arguments,function*(t,{volume:e=.5,expression:i,resetExpression:r=!0,onFinish:s,onError:a}={}){if(!pt.sound)return!1;let n,o;if(this.currentAudio&&this.currentAudio.isPlaying)return!1;const l=t&&t.startsWith("data:");if(t&&!l){const e=document.createElement("a");e.href=t,o=t=e.href}else o="data:audio/";const u=t;if(u)try{n=yield Dt.add(u,(t,e=this)=>{_t.error(this.tag,"Error during audio playback:",t),null==a||a(t),r&&i&&e.expressionManager&&e.expressionManager.resetExpression(),e.currentAudio=void 0}),this.initializeAudio(n,e)}catch(h){return _t.warn(this.tag,"Failed to create audio",o,h),!1}if(n){let t=!0;try{pt.motionSync&&Dt.play(n,()=>{null==s||s(),r&&i&&this.expressionManager&&this.expressionManager.resetExpression(),this.currentAudio=void 0})}catch(h){_t.warn(this.tag,"Failed to play audio",n.url,h),t=!1}if(!t)return!1}return this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),i&&this.expressionManager&&(yield this.expressionManager.setExpression(i)),this.playing=!0,!0})}startMotion(t,e){return c(this,arguments,function*(t,e,i=Vt.NORMAL,{sound:r,volume:s=.5,expression:a,resetExpression:n=!0,onFinish:o,onError:l,ignoreParamIds:u=[]}={}){if(this.destroyed)return!1;if(!this.state.reserve(t,e,i))return!1;if(this.currentAudio&&this.currentAudio.isPlaying&&i!=Vt.FORCE)return!1;const h=this.getMotionDefinition(t,e);if(!h)return!1;let d,g;this.currentAudio&&Dt.dispose(this.currentAudio);const c=r&&r.startsWith("data:");if(r&&!c){const t=document.createElement("a");t.href=r,g=r=t.href}else g=this.getSoundFile(h),g&&(g=this.settings.resolveURL(g));const m=g;if(m)try{d=yield Dt.add(m,(t,e=this)=>{_t.error(this.tag,"Error during audio playback:",t),null==l||l(t),n&&a&&e.expressionManager&&e.expressionManager.resetExpression(),e.currentAudio=void 0}),this.initializeAudio(d,s)}catch(_){_t.warn(this.tag,"Failed to create audio",g,_)}const p=yield this.loadMotion(t,e);if(d&&pt.motionSync)try{Dt.play(d,(t=this)=>{null==o||o(),n&&a&&t.expressionManager&&t.expressionManager.resetExpression(),t.currentAudio=void 0})}catch(_){_t.warn(this.tag,"Failed to play audio",d.url,_)}return this.state.start(p,t,e,i)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),_t.log(this.tag,"Start motion:",this.getMotionName(h)),this.emit("motionStart",t,e,d),a&&this.expressionManager&&this.state.shouldOverrideExpression()&&(yield this.expressionManager.setExpression(a)),this.playing=!0,p&&this._startMotion(p,void 0,u),!0):(d&&(Dt.dispose(d),this.currentAudio=void 0),!1)})}startRandomMotion(t,e){return c(this,arguments,function*(t,e,{sound:i,volume:r=.5,expression:s,resetExpression:a=!0,onFinish:n,onError:o}={}){var l,u;if(this.destroyed)return!1;const h=null==(l=this.definitions)?void 0:l[t];if(null==h?void 0:h.length){const l=[],d=null!=(u=this.motionGroups[t])?u:[];for(let e=0;e<h.length;e++)null===d[e]||this.state.isActive(t,e)||l.push(e);if(l.length){const u=l[Math.floor(Math.random()*l.length)];return this.startMotion(t,u,e,{sound:i,volume:r,expression:s,resetExpression:a,onFinish:n,onError:o})}}return!1})}stopSpeaking(){this.currentAudio&&(Dt.dispose(this.currentAudio),this.currentAudio=void 0)}stopAllMotions(){this._stopAllMotions(),this.state.reset(),this.stopSpeaking()}update(t,e){var i;return this.isFinished()&&(this.playing&&(this.playing=!1,this.emit("motionFinish")),this.state.shouldOverrideExpression()&&(null==(i=this.expressionManager)||i.restoreExpression()),this.state.complete(),this.state.shouldRequestIdleMotion()&&this.startRandomMotion(this.groups.idle,Vt.IDLE)),this.updateParameters(t,e)}mouthSync(){return this.currentAnalyzer?Dt.analyze(this.currentAnalyzer):0}destroy(){var t;this.destroyed=!0,this.emit("destroy"),this.stopAllMotions(),null==(t=this.expressionManager)||t.destroy();this.definitions=void 0,this.motionGroups=void 0}getMotionAndApplyExpression(t,e,i){return c(this,null,function*(){if(this.destroyed)return null;if(!this.state.reserve(t,e,Vt.FORCE))return null;const r=this.getMotionDefinition(t,e);if(!r)return null;this.currentAudio&&Dt.dispose(this.currentAudio);const s=yield this.loadMotion(t,e);return this.state.start(s,t,e,Vt.FORCE)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),_t.log(this.tag,"Start motion:",this.getMotionName(r)),this.emit("motionStart",t,e,void 0),i&&this.expressionManager&&this.state.shouldOverrideExpression()&&(yield this.expressionManager.setExpression(i)),s):null})}getMotionDefinition(t,e){var i,r;const s=null==(r=null==(i=this.definitions)?void 0:i[t])?void 0:r[e];return s||_t.warn(this.tag,`Undefined motion at "${t}"[${e}]`),s}}function kt(t,e){if(!Array.isArray(t))return[];const i=[];for(const r of t){if(!r||"object"!=typeof r)continue;const t=r,s="string"==typeof t.id?t.id:"string"==typeof t.Id?t.Id:void 0,a="string"==typeof t.name?t.name:"string"==typeof t.Name?t.Name:void 0;s&&a&&i.push({id:s,name:a,index:e(s)})}return i}const Nt={x:0,y:0,width:0,height:0};class Ut extends e.EventEmitter{constructor(){super(...arguments),g(this,"focusController",new It),g(this,"pose"),g(this,"physics"),g(this,"originalWidth",0),g(this,"originalHeight",0),g(this,"width",0),g(this,"height",0),g(this,"localTransform",new e.Matrix),g(this,"drawingMatrix",new e.Matrix),g(this,"hitAreas",{}),g(this,"textureFlipY",!1),g(this,"viewport",[0,0,0,0]),g(this,"destroyed",!1)}init(){this.setupLayout(),this.setupHitAreas()}setupLayout(){const t=this,e=this.getSize();t.originalWidth=e[0],t.originalHeight=e[1];const i=Object.assign({width:2,height:2},this.getLayout());this.localTransform.scale(i.width/2,i.height/2),t.width=this.originalWidth*this.localTransform.a,t.height=this.originalHeight*this.localTransform.d;const r=void 0!==i.x&&i.x-i.width/2||void 0!==i.centerX&&i.centerX||void 0!==i.left&&i.left-i.width/2||void 0!==i.right&&i.right+i.width/2||0,s=void 0!==i.y&&i.y-i.height/2||void 0!==i.centerY&&i.centerY||void 0!==i.top&&i.top-i.height/2||void 0!==i.bottom&&i.bottom+i.height/2||0;this.localTransform.translate(this.width*r,-this.height*s)}setupHitAreas(){const t=this.getHitAreaDefs();this.hitAreas={};for(const e of t)e.name&&(this.hitAreas[e.name]=e)}hitTest(t,e){return Object.keys(this.hitAreas).filter(i=>this.isHit(i,t,e))}isHit(t,e,i){const r=this.hitAreas[t];if(!r)return!1;let s=r.index;if(s<0){if(!r.id)return!1;if(s=this.getDrawableIndex(r.id),s<0)return!1;r.index=s}const a=this.getDrawableBounds(s,Nt);return a.x<=e&&e<=a.x+a.width&&a.y<=i&&i<=a.y+a.height}getDrawableBounds(t,e){const i=this.getDrawableVertices(t);let r=i[0],s=i[0],a=i[1],n=i[1];for(let o=0;o<i.length;o+=2){const t=i[o],e=i[o+1];r=Math.min(t,r),s=Math.max(t,s),a=Math.min(e,a),n=Math.max(e,n)}return null!=e||(e={}),e.x=r,e.y=a,e.width=s-r,e.height=n-a,e}updateTransform(t){this.drawingMatrix.copyFrom(t).append(this.localTransform)}update(t,e){this.focusController.update(t)}destroy(){this.destroyed=!0,this.emit("destroy"),this.motionManager.destroy(),this.motionManager=void 0,this.parallelMotionManager.forEach(t=>t.destroy()),this.parallelMotionManager=[]}updateMotions(t,e){this.emit("beforeMotionUpdate");const i=this.motionManager.update(t,e),r=this.parallelMotionManager.map(i=>i.update(t,e)),s=i||r.reduce((t,e)=>t||e,!1);return this.emit("afterMotionUpdate"),s}}class zt extends Error{constructor(t,e,i,r=!1){super(t),this.url=e,this.status=i,this.aborted=r}}const jt=class t{static createXHR(e,i,r,s,a){const n=new XMLHttpRequest;if(t.allXhrSet.add(n),e){let i=t.xhrMap.get(e);i?i.add(n):(i=new Set([n]),t.xhrMap.set(e,i))}return n.open("GET",i),n.responseType=r,n.onload=()=>{var t;200!==n.status&&0!==n.status||!n.response?null==(t=n.onerror)||t.call(n,new ProgressEvent("error")):s(n.response)},n.onerror=()=>{_t.warn("XHRLoader",`Failed to load resource as ${n.responseType} (Status ${n.status}): ${i}`),a(new zt("Network error.",i,n.status))},n.onabort=()=>a(new zt("Aborted.",i,n.status,!0)),n.onloadend=()=>{var i;t.allXhrSet.delete(n),e&&(null==(i=t.xhrMap.get(e))||i.delete(n))},n}static cancelXHRs(){var e;null==(e=t.xhrMap.get(this))||e.forEach(e=>{e.abort(),t.allXhrSet.delete(e)}),t.xhrMap.delete(this)}static release(){t.allXhrSet.forEach(t=>t.abort()),t.allXhrSet.clear(),t.xhrMap=new WeakMap}};g(jt,"xhrMap",new WeakMap),g(jt,"allXhrSet",new Set),g(jt,"loader",t=>new Promise((e,i)=>{const r=t.target,s=t.target&&"function"==typeof jt.cancelXHRs?jt.cancelXHRs.bind(t.target):void 0,a=jt.createXHR(t.target,t.settings?t.settings.resolveURL(t.url):t.url,t.type,i=>{t.result=i,e()},i);if(t.target&&s&&"function"==typeof r.listeners&&"function"==typeof r.once){const t=r.listeners("destroy");Array.isArray(t)&&t.includes(s)||r.once("destroy",s)}a.send()}));let Gt=jt;function Xt(t,e){let i=-1;return function r(s,a){if(a)return Promise.reject(a);if(s<=i)return Promise.reject(new Error("next() called multiple times"));i=s;const n=t[s];if(!n)return Promise.resolve();try{return Promise.resolve(n(e,r.bind(null,s+1)))}catch(o){const t=o instanceof Error?o:new Error(String(o));return Promise.reject(t)}}(0)}class Ht{static load(t){return c(this,null,function*(){return yield Xt(this.middlewares,t),t.result})}}g(Ht,"middlewares",[Gt.loader]);class qt extends Et{constructor(t){if(super(t),g(this,"moc"),g(this,"textures"),g(this,"layout"),g(this,"hitAreas"),g(this,"initParams"),g(this,"initOpacities"),g(this,"expressions"),g(this,"motions",{}),!qt.isValidJSON(t))throw new TypeError("Invalid JSON.");this.moc=t.model,Ct("string",t,this,"textures","textures"),this.copy(t)}static isValidJSON(t){if(!t||"object"!=typeof t)return!1;const e=!!Array.isArray(t.textures)&&t.textures.every(t=>"string"==typeof t);return"string"==typeof t.model&&e}copy(t){xt("string",t,this,"name","name"),xt("string",t,this,"pose","pose"),xt("string",t,this,"physics","physics"),xt("object",t,this,"layout","layout"),xt("object",t,this,"motions","motions"),Ct("object",t,this,"hit_areas","hitAreas"),Ct("object",t,this,"expressions","expressions"),Ct("object",t,this,"init_params","initParams"),Ct("object",t,this,"init_opacities","initOpacities");const e=this.getFileStem(this.moc);this.setModelName(this.name,e)}replaceFiles(t){super.replaceFiles(t);for(const[e,i]of Object.entries(this.motions))for(let r=0;r<i.length;r++)i[r].file=t(i[r].file,`motions.${e}[${r}].file`),void 0!==i[r].sound&&(i[r].sound=t(i[r].sound,`motions.${e}[${r}].sound`));if(this.expressions)for(let e=0;e<this.expressions.length;e++)this.expressions[e].file=t(this.expressions[e].file,`expressions[${e}].file`)}}function Yt({lod:t,effectiveScale:e,textureWidth:i,textureHeight:r,lodScaleThreshold:s,lodTextureSizeThreshold:a,lodMaxLevel:n}){if("single-auto"!==Wt(t))return;if(!Number.isFinite(e)||e<=0)return;const o=Math.floor(i),l=Math.floor(r);if(o<=1||l<=1)return;if(e>=$t(s,.5))return;const h=$t(a,4096);if(Math.max(o,l)<h)return;const d=Math.round(Math.log2(1/e)),g=Math.max(1,Math.floor(Math.log2(Math.max(o,l)))),c=Math.min(g,(p=g,void 0!==(m=n)&&Number.isFinite(m)&&m>=1?Math.floor(m):p));var m,p;const _=function(t,e,i){return Math.min(i,Math.max(e,t))}(Math.max(1,d),1,c),f=u(2,_);return{level:_,width:Math.max(1,Math.round(o/f)),height:Math.max(1,Math.round(l/f))}}function Wt(t){return!1===t||"single-auto"===t?t:"full"}function Jt(t){return"nearest"===t?"nearest":"linear"}function $t(t,e){return void 0!==t&&Number.isFinite(t)&&t>0?t:e}function Zt(){}const Kt="Live2DFactory",Qt=(t,e)=>c(null,null,function*(){if("string"==typeof t.source){const e=yield Ht.load({url:t.source,type:"json",target:t.live2dModel});e.url="string"==typeof e.url?e.url:t.source,t.source=e,t.live2dModel.emit("settingsJSONLoaded",e)}return e()}),te=(t,e)=>c(null,null,function*(){if(t.source instanceof Et)return t.settings=t.source,e();if("object"==typeof t.source){const i=le.findRuntime(t.source);if(i){const r=i.createModelSettings(t.source);return t.settings=r,t.live2dModel.emit("settingsLoaded",r),e()}}const i=t.source&&"string"==typeof t.source.url?t.source.url:void 0,r=le.runtimes.map(t=>t.version).join(", ");if(0===le.runtimes.length)throw new TypeError(["Unknown settings format: no Live2D runtimes registered.",'Import a published runtime entry before loading models (e.g. "<package>/cubism" for Cubism 3/4/5, "<package>/cubism-legacy" for Cubism 2).',i?`Settings URL: ${i}`:void 0].filter(Boolean).join("\n"));const s=(()=>{try{if(!t.source||"object"!=typeof t.source||Array.isArray(t.source))return;return Object.keys(t.source).slice(0,30).join(", ")}catch(e){return}})();throw new TypeError(["Unknown settings format: no matching runtime found for the loaded settings JSON.",r?`Registered runtimes (versions): ${r}`:void 0,s?`Settings JSON keys: ${s}`:void 0,i?`Settings URL: ${i}`:void 0].filter(Boolean).join("\n"))}),ee=(t,e)=>{if(t.settings){const i=le.findRuntime(t.settings);if(i)return i.ready().then(()=>e())}return e()},ie=(t,e)=>c(null,null,function*(){yield e();const i=t.internalModel;if(i){const e=t.settings,r=le.findRuntime(e);if(r){const s=[],a=e instanceof qt?"json":"arraybuffer";e.pose&&s.push(Ht.load({settings:e,url:e.pose,type:a,target:i}).then(e=>{i.pose=r.createPose(i.coreModel,e),t.live2dModel.emit("poseLoaded",i.pose)}).catch(e=>{t.live2dModel.emit("poseLoadError",e),_t.warn(Kt,"Failed to load pose.",e)})),e.physics&&s.push(Ht.load({settings:e,url:e.physics,type:a,target:i}).then(e=>{i.physics=r.createPhysics(i.coreModel,e),t.live2dModel.emit("physicsLoaded",i.physics)}).catch(e=>{t.live2dModel.emit("physicsLoadError",e),_t.warn(Kt,"Failed to load physics.",e)})),s.length&&(yield Promise.all(s))}}}),re=(t,i)=>c(null,null,function*(){if(!t.settings)throw new TypeError("Missing settings.");{const r=t.live2dModel,s=d({crossOrigin:t.options.crossOrigin},t.options.textureOptions);t.settings instanceof qt&&(s.preferCreateImageBitmap=!1);const a=Promise.all(t.settings.textures.map(i=>function(t,i={}){const r=e.loadTextures.config,s=null==r?void 0:r.crossOrigin,a=null==r?void 0:r.preferCreateImageBitmap,n=null==r?void 0:r.preferWorkers;return void 0!==i.crossOrigin&&r&&(r.crossOrigin=i.crossOrigin),!1===i.preferCreateImageBitmap&&r&&(r.preferCreateImageBitmap=!1,r.preferWorkers=!1),e.Assets.load({src:t,data:{autoGenerateMipmaps:"full"===Wt(i.lod)}}).catch(t=>{if(t instanceof Error)throw t;throw new Error("Texture loading error",{cause:t})}).finally(()=>{r&&(r.crossOrigin=null!=s?s:r.crossOrigin,!1===i.preferCreateImageBitmap&&(r.preferCreateImageBitmap=null!=a?a:r.preferCreateImageBitmap,r.preferWorkers=null!=n?n:r.preferWorkers))})}(t.settings.resolveURL(i),s)));if(a.catch(Zt),yield i(),!t.internalModel)throw new TypeError("Missing internal model.");r.internalModel=t.internalModel,r.emit("modelLoaded",t.internalModel),r.textures=yield a,r.emit("textureLoaded",r.textures)}}),se=(t,e)=>c(null,null,function*(){const i=t.settings;if(i instanceof Et){const r=le.findRuntime(i);if(!r)throw new TypeError("Unknown model settings.");const s=yield Ht.load({settings:i,url:i.moc,type:"arraybuffer",target:t.live2dModel});if(!r.isValidMoc(s))throw new Error("Invalid moc data");const a=r.createCoreModel(s);return t.internalModel=r.createInternalModel(a,i,t.options),e()}throw new TypeError("Missing settings.")}),ae=class t{static resolveURL(e,i){var r;const s=null==(r=t.filesMap[e])?void 0:r[i];if(void 0===s)throw new Error("Cannot find this file from uploaded files: "+i);return s}static upload(e,i){const r={};for(const t of i.getDefinedFiles()){const s=decodeURI(Pt(i.url,t)),a=e.find(t=>t.webkitRelativePath===s);a&&(r[t]=URL.createObjectURL(a))}t.filesMap[i._objectURL]=r}static createSettings(e){return c(this,null,function*(){const i=e.find(t=>t.name.endsWith("model.json")||t.name.endsWith("model3.json"));if(!i)throw new TypeError("Settings file not found");const r=yield t.readText(i),s=JSON.parse(r);s.url=i.webkitRelativePath;const a=le.findRuntime(s);if(!a)throw new Error("Unknown settings JSON");const n=a.createModelSettings(s);return n._objectURL=URL.createObjectURL(i),n})}static readText(t){return c(this,null,function*(){return new Promise((e,i)=>{const r=new FileReader;r.onload=()=>e(r.result),r.onerror=i,r.readAsText(t,"utf8")})})}};g(ae,"live2dFactory"),g(ae,"filesMap",{}),g(ae,"factory",(t,e)=>c(null,null,function*(){if(Array.isArray(t.source)&&t.source[0]instanceof File){const e=t.source;let i=e.settings;if(i){if(!i._objectURL)throw new Error('"_objectURL" must be specified in ModelSettings')}else i=yield ae.createSettings(e);i.validateFiles(e.map(t=>encodeURI(t.webkitRelativePath))),ae.upload(e,i),i.resolveURL=function(t){return ae.resolveURL(this._objectURL,t)},t.source=i,t.live2dModel.once("modelLoaded",t=>{t.once("destroy",function(){const t=this.settings._objectURL;if(URL.revokeObjectURL(t),ae.filesMap[t])for(const e of Object.values(ae.filesMap[t]))URL.revokeObjectURL(e);delete ae.filesMap[t]})})}return e()}));let ne=ae;const oe=class t{static registerRuntime(e){t.runtimes.push(e),t.runtimes.sort((t,e)=>e.version-t.version)}static findRuntime(e){for(const i of t.runtimes)if(i.test(e))return i}static setupLive2DModel(e,i,r){return c(this,null,function*(){const s=new Promise(t=>e.once("textureLoaded",t)),a=new Promise(t=>e.once("modelLoaded",t)),n=Promise.all([s,a]).then(()=>e.emit("ready"));yield Xt(t.live2DModelMiddlewares,{live2dModel:e,source:i,options:r||{}}),yield n,e.emit("load")})}static loadMotion(e,i,r){var s;const a=t=>e.emit("motionLoadError",i,r,t);try{const n=null==(s=e.definitions[i])?void 0:s[r];if(!n)return Promise.resolve(void 0);e.once("destroy",()=>t.releaseMotionTasks(e));let o=t.motionTasksMap.get(e);o||(o={},t.motionTasksMap.set(e,o));let l=o[i];l||(l=[],o[i]=l);const u=e.getMotionFile(n);return null!=l[r]||(l[r]=Ht.load({url:u,settings:e.settings,type:e.motionDataType,target:e}).then(s=>{var a;const o=null==(a=t.motionTasksMap.get(e))?void 0:a[i];o&&(o[r]=void 0);const l=s,u=e.createMotion(l,i,n);return e.emit("motionLoaded",i,r,u),u}).catch(t=>{_t.warn(e.tag,`Failed to load motion: ${u}\n`,t),a(t)})),l[r]}catch(n){_t.warn(e.tag,`Failed to load motion at "${i}"[${r}]\n`,n),a(n)}return Promise.resolve(void 0)}static loadExpression(e,i){var r;const s=t=>e.emit("expressionLoadError",i,t);try{const a=e.definitions[i];if(!a)return Promise.resolve(void 0);e.once("destroy",()=>t.releaseExpressionTasks(e));let n=t.expressionTasksMap.get(e);n||(n=[],t.expressionTasksMap.set(e,n));const o=e.getExpressionFile(a),l=null!=(r=e.expressionDataType)?r:"json";return null!=n[i]||(n[i]=Ht.load({url:o,settings:e.settings,type:l,target:e}).then(r=>{const s=t.expressionTasksMap.get(e);s&&(s[i]=void 0);const n=r,o=e.createExpression(n,a);return e.emit("expressionLoaded",i,o),o}).catch(t=>{_t.warn(e.tag,`Failed to load expression: ${o}\n`,t),s(t)})),n[i]}catch(a){_t.warn(e.tag,`Failed to load expression at [${i}]\n`,a),s(a)}return Promise.resolve(void 0)}static releaseMotionTasks(e){t.motionTasksMap.delete(e)}static releaseExpressionTasks(e){t.expressionTasksMap.delete(e)}};g(oe,"runtimes",[]),g(oe,"urlToJSON",Qt),g(oe,"jsonToSettings",te),g(oe,"waitUntilReady",ee),g(oe,"setupOptionals",ie),g(oe,"setupEssentials",re),g(oe,"createInternalModel",se),g(oe,"live2DModelMiddlewares",[ne.factory,Qt,te,ee,ie,re,se]),g(oe,"motionTasksMap",new WeakMap),g(oe,"expressionTasksMap",new WeakMap);let le=oe;Ot.prototype._loadMotion=function(t,e){return le.loadMotion(this,t,e)},Bt.prototype._loadExpression=function(t){return le.loadExpression(this,t)},ne.live2dFactory=le;const ue=class t{constructor(i,{autoUpdate:r=!0,autoHitTest:s=!0,autoFocus:a=!0,autoInteract:n,ticker:o}={}){var l;g(this,"model"),g(this,"destroyed",!1),g(this,"_ticker"),g(this,"_autoUpdate",!1),g(this,"_autoHitTest",!1),g(this,"_autoFocus",!1),null!=o||(o=null!=(l=t.defaultTicker)?l:"undefined"!=typeof PIXI?PIXI.Ticker.shared:e.Ticker.shared),void 0!==n&&(s=n,a=n,_t.warn(i.tag,"options.autoInteract is deprecated since v0.5.0, use autoHitTest and autoFocus instead.")),this.model=i,this.ticker=o,this.autoUpdate=r,this.autoHitTest=s,this.autoFocus=a,(s||a)&&(this.model.eventMode="static")}get ticker(){return this._ticker}set ticker(t){var e,i;this._ticker&&this._ticker.remove(de,this),this._ticker=t,this._autoUpdate&&(null==(e=this._ticker)||e.add(de,this),null==(i=this._ticker)||i.start())}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){var e;this.destroyed||(t?this._ticker?(this._ticker.add(de,this),this._autoUpdate=!0):_t.warn(this.model.tag,"No Ticker to be used for automatic updates. Either set option.ticker when creating Live2DModel, or expose PIXI to global scope (window.PIXI = PIXI)."):(null==(e=this._ticker)||e.remove(de,this),this._autoUpdate=!1))}get autoHitTest(){return this._autoHitTest}set autoHitTest(t){t!==this.autoHitTest&&(t?this.model.on("pointertap",ge,this):this.model.off("pointertap",ge,this),this._autoHitTest=t)}get autoFocus(){return this._autoFocus}set autoFocus(t){t!==this.autoFocus&&(t?(this.model.on("globalpointermove",ce,this),this.model.on("pointermove",ce,this)):(this.model.off("globalpointermove",ce,this),this.model.off("pointermove",ce,this)),this._autoFocus=t)}get autoInteract(){return this._autoHitTest&&this._autoFocus}set autoInteract(t){this.autoHitTest=t,this.autoFocus=t}onTickerUpdate(){const t=this.ticker.deltaMS;this.model.update(t)}onTap(t){this.model.tap(t.global.x,t.global.y)}onPointerMove(t){this.model.focus(t.global.x,t.global.y)}destroy(){this.autoFocus=!1,this.autoHitTest=!1,this.autoUpdate=!1,this.ticker=void 0,this.destroyed=!0}};g(ue,"defaultTicker");let he=ue;function de(){this.onTickerUpdate()}function ge(t){this.onTap(t)}function ce(t){this.onPointerMove(t)}class me extends e.Transform{}const pe=new e.Point,_e=new e.Matrix,fe=new e.Matrix,ye={x:0,y:0,width:0,height:0},xe=new e.Bounds;let Ce=!1;class Me{constructor(t){this.renderer=t}addRenderable(t,e){var i,r;null==(r=null==(i=this.renderer.renderPipes.batch)?void 0:i.break)||r.call(i,e),e.add(t)}execute(t){!t.visible||t.alpha<=0||t.renderLive2D(this.renderer)}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}destroy(){}}g(Me,"extension",{type:[e.ExtensionType.WebGLPipes],name:"live2d"});const Se=Me;class ve extends e.Container{constructor(t){super(),g(this,"renderPipeId","live2d"),g(this,"tag","Live2DModel(uninitialized)"),g(this,"internalModel"),g(this,"textures",[]),g(this,"textureOptions"),g(this,"textureLODStates",[]),g(this,"textureLODFailures",[]),g(this,"transform",new me),g(this,"anchor"),g(this,"_bounds",new e.Bounds),g(this,"_boundsDirty",!0),g(this,"_boundsRetryAfterDraw",!1),g(this,"gl",null),g(this,"elapsedTime",0),g(this,"deltaTime",0),g(this,"automator"),g(this,"currentGlId",0),g(this,"renderLive2D",t=>{var i,r,s,a,n;if(!(t instanceof e.WebGLRenderer))throw new Error("Renderer is not supported");t.geometry.resetState(),t.shader.resetState(),t.texture.resetState();let o=!1;this.gl!==t.gl&&(this.gl=t.gl,this.internalModel.updateWebGLContext(t.gl,this.generateUID()),o=!0);const{projectionMatrix:l,offset:u,worldTransformMatrix:h}=t.globalUniforms.globalUniformData,d=fe.copyFrom(h).append(this.groupTransform),g=(c=d,Math.max(Math.hypot(c.a,c.b),Math.hypot(c.c,c.d))*t.resolution);var c;for(let e=0;e<this.textures.length;e++){const i=this.textures[e];let r=this.resolveTextureForRender(e,i,g);try{this.uploadTextureForRender(t,r,o)}catch(M){if(r===i)throw new Error("Failed to upload Live2D texture.");const s=this.textureLODStates[e];(null==s?void 0:s.texture)===r&&(this.markTextureLODFailure(e,i,s.level),this.destroyTextureLODState(e)),r=i,this.uploadTextureForRender(t,r,o)}this.internalModel.bindTexture(e,t.texture.getGlSource(r.source).texture)}const m=t.renderTarget.viewport,p=t.renderTarget.renderTarget;let _=m.y;if(null==p?void 0:p.isRoot){_=p.colorTexture.source.pixelHeight-m.height-m.y}this.internalModel.viewport=[m.x,_,m.width,m.height];const f=this.deltaTime;this.deltaTime=0,f&&this.internalModel.update(f,this.elapsedTime),d.tx-=null!=(i=null==u?void 0:u.x)?i:0,d.ty-=null!=(r=null==u?void 0:u.y)?r:0;const y=_e.copyFrom(l).append(d);this.internalModel.updateTransform(y),this.internalModel.draw(t.gl),this._boundsRetryAfterDraw&&this.updateDrawableBounds(),t.state.resetState(),t.texture.resetState();const x=null==(s=t.renderTarget)?void 0:s.defaultClearColor,C=null==(n=null==(a=t.renderTarget)?void 0:a.adaptor)?void 0:n._clearColorCache;x&&(t.gl.clearColor(x[0],x[1],x[2],x[3]),C&&(C[0]=x[0],C[1]=x[1],C[2]=x[2],C[3]=x[3]))}),this.textureOptions=null==t?void 0:t.textureOptions,this.anchor=new e.ObservablePoint({_onUpdate:()=>this.onAnchorChange()},0,0),this.automator=new he(this,t),this.once("modelLoaded",()=>this.initializeOnModelLoad(t))}get isRenderable(){return!0}get canBundle(){return!1}static from(t,e){return c(this,null,function*(){const i=new this(e);return yield le.setupLive2DModel(i,t,e),i})}static fromSync(t,e){const i=new this(e);return le.setupLive2DModel(i,t,e).then(()=>{var t;return null==(t=null==e?void 0:e.onLoad)?void 0:t.call(e)}).catch(t=>{var i;return null==(i=null==e?void 0:e.onError)?void 0:i.call(e,t)}),i}static registerTicker(t){he.defaultTicker=t.shared}get bounds(){return this.internalModel?(this._boundsDirty&&this.updateDrawableBounds(),this._bounds):(this._bounds.set(0,0,0,0),this._bounds)}updateDrawableBounds(){if(!this.internalModel)return this._bounds.set(0,0,0,0),void(this._boundsDirty=!1);const t=this.internalModel.getDrawableIDs();xe.clear();for(let i=0;i<t.length;i++){const r=t[i],s=this.internalModel.getDrawableIndex(r);if(s<0)continue;const a=this.internalModel.getDrawableBounds(s,ye);Number.isFinite(a.x)&&Number.isFinite(a.y)&&Number.isFinite(a.width)&&Number.isFinite(a.height)&&xe.addFrame(a.x,a.y,a.x+a.width,a.y+a.height,e.Matrix.IDENTITY)}if(this._bounds.clear(),xe.isValid&&xe.isPositive)this._bounds.addFrame(xe.minX,xe.minY,xe.maxX,xe.maxY,this.internalModel.localTransform),this._boundsRetryAfterDraw=!1;else{const t=this.internalModel.originalWidth||this.internalModel.width,e=this.internalModel.originalHeight||this.internalModel.height;this._bounds.addFrame(0,0,t,e,this.internalModel.localTransform),this._boundsRetryAfterDraw=!0}this._boundsDirty=!1}generateUID(){return++this.currentGlId}collectRenderables(t,e,i){var r,s,a,n;if(this.parentRenderLayer&&this.parentRenderLayer!==i)return;if(this.globalDisplayStatus<7)return;if(!this.includeInBuild)return;this.sortableChildren&&this.sortChildren(),function(t){const e=t;e.renderPipes.live2d||(Ce||(Ce=!0,console.warn("[untitled-pixi-live2d-engine] Lazy Live2D render pipe registration is deprecated. Register Live2DPlugin explicitly with `extensions.add(Live2DPlugin)` before creating the Pixi renderer.")),e.renderPipes.live2d=new Me(t))}(e);const o=e.renderPipes,l=()=>{o.live2d.addRenderable(this,t)},u=()=>{const r=this.children,s=r.length;for(let a=0;a<s;a++)r[a].collectRenderables(t,e,i)},h=this.effects;if(h){for(let e=0;e<h.length;e++){const i=h[e],a=i.filters;if(a)for(const t of a)t&&"number"==typeof t.resolution&&1===t.resolution&&(t.resolution="inherit");null==(s=null==(r=o[i.pipe])?void 0:r.push)||s.call(r,i,this,t)}l(),u();for(let e=h.length-1;e>=0;e--){const i=h[e];null==(n=null==(a=o[i.pipe])?void 0:a.pop)||n.call(a,i,this,t)}}else l(),u()}initializeOnModelLoad(t){this.tag=`Live2DModel(${this.internalModel.settings.name})`,this.onAnchorChange(),this.updateDrawableBounds()}onAnchorChange(){this.internalModel&&this.pivot&&this.pivot.set(this.anchor.x*this.internalModel.width,this.anchor.y*this.internalModel.height)}motion(t,e,i){return c(this,arguments,function*(t,e,i,{sound:r,volume:s=.5,expression:a,resetExpression:n=!0,onFinish:o,onError:l}={}){return void 0===e?this.internalModel.motionManager.startRandomMotion(t,i,{sound:r,volume:s,expression:a,resetExpression:n,onFinish:o,onError:l}):this.internalModel.motionManager.startMotion(t,e,i,{sound:r,volume:s,expression:a,resetExpression:n,onFinish:o,onError:l})})}motionLastFrame(t,e){return c(this,arguments,function*(t,e,{expression:i}={}){return this.internalModel.motionManager.motionLastFrame(t,e,{expression:i})})}parallelMotion(t){return c(this,null,function*(){this.internalModel.extendParallelMotionManager(t.length);const e=t.map((t,e)=>this.internalModel.parallelMotionManager[e].startMotion(t.group,t.index,t.priority)),i=[];for(const t of e)i.push(yield t);return i})}parallelLastFrame(t){return c(this,null,function*(){this.internalModel.extendParallelMotionManager(t.length);const e=t.map((t,e)=>this.internalModel.parallelMotionManager[e].playMotionLastFrame(t.group,t.index)),i=[];for(const t of e)i.push(yield t);return i})}stopMotions(){return this.internalModel.motionManager.stopAllMotions()}speak(t,{volume:e=.5,expression:i,resetExpression:r=!0,onFinish:s,onError:a}={}){return this.internalModel.motionManager.speak(t,{volume:e,expression:i,resetExpression:r,onFinish:s,onError:a})}stopSpeaking(){return this.internalModel.motionManager.stopSpeaking()}expression(t){return this.internalModel.motionManager.expressionManager?void 0===t?this.internalModel.motionManager.expressionManager.setRandomExpression():this.internalModel.motionManager.expressionManager.setExpression(t):Promise.resolve(!1)}focus(t,e,i=!1){pe.x=t,pe.y=e,this.toModelPosition(pe,pe,!0);const r=pe.x/this.internalModel.originalWidth*2-1,s=pe.y/this.internalModel.originalHeight*2-1,a=Math.atan2(s,r);this.internalModel.focusController.focus(Math.cos(a),-Math.sin(a),i)}tap(t,e){const i=this.hitTest(t,e);i.length&&this.emit("hit",i)}hitTest(t,e){return pe.x=t,pe.y=e,this.toModelPosition(pe,pe),this.internalModel.hitTest(pe.x,pe.y)}toModelPosition(t,e=t.clone(),i){return i||this.updateLocalTransform(),this.toLocal(t,void 0,e,i),this.internalModel.localTransform.applyInverse(e,e),e}containsPoint(t){return this.bounds.containsPoint(t.x,t.y)}_calculateBounds(){if(!this.internalModel)return void this.getBounds().set(0,0,0,0);const t=this.internalModel.width,e=this.internalModel.height;this.getBounds().addFrame(0,0,t,e,this.transform.matrix)}update(t){this.deltaTime+=t,this.elapsedTime+=t}resolveTextureForRender(t,i,r){var n;const o=Yt((l=d({},this.textureOptions),u={effectiveScale:r,textureWidth:i.source.pixelWidth,textureHeight:i.source.pixelHeight},s(l,a(u))));var l,u;if(!o)return i;const h=this.textureLODFailures[t];if((null==h?void 0:h.source)===i&&h.levels.has(o.level))return i;const g=this.textureLODStates[t];if((null==g?void 0:g.source)===i&&g.level===o.level&&!g.texture.destroyed)return g.texture;this.destroyTextureLODState(t);const c=function(t,i,r,s,a){var n,o;const l=t.source.resource;if(!function(t){if(!t||"object"!=typeof t)return!1;const{width:e,height:i}=t;return"number"==typeof e&&e>0&&"number"==typeof i&&i>0}(l))return;const u=e.DOMAdapter.get().createCanvas(r,s),h=u.getContext("2d");if(!h)return;try{h.clearRect(0,0,r,s),h.imageSmoothingEnabled="nearest"!==a,"imageSmoothingQuality"in h&&"nearest"!==a&&(h.imageSmoothingQuality="high"),h.drawImage(l,0,0,t.source.pixelWidth,t.source.pixelHeight,0,0,r,s)}catch(g){return}const d=`${null!=(o=null!=(n=t.label)?n:t.source.label)?o:"Live2DTexture"} LOD ${i}`;return new e.Texture({label:d,source:new e.CanvasSource({resource:u,width:r,height:s,resolution:1,scaleMode:Jt(a),autoGenerateMipmaps:!1,label:d})})}(i,o.level,o.width,o.height,null==(n=this.textureOptions)?void 0:n.lodFilter);return c?(this.textureLODStates[t]={source:i,level:o.level,texture:c},c):(this.markTextureLODFailure(t,i,o.level),i)}markTextureLODFailure(t,e,i){let r=this.textureLODFailures[t];(null==r?void 0:r.source)!==e&&(r={source:e,levels:new Set},this.textureLODFailures[t]=r),r.levels.add(i)}destroyTextureLODState(t){const e=this.textureLODStates[t];e&&(e.texture.destroy(!0),this.textureLODStates[t]=void 0)}destroyTextureLODStates(){for(let t=0;t<this.textureLODStates.length;t++)this.destroyTextureLODState(t);this.textureLODFailures.length=0}uploadTextureForRender(t,e,i){const r=Boolean(e.source._gpuData[t.uid]);!i&&r||(t.gl.pixelStorei(WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL,this.internalModel.textureFlipY),t.texture.bind(e,0))}destroy(t){this.emit("destroy"),this.destroyTextureLODStates(),(null==t?void 0:t.texture)&&this.textures.forEach(e=>e.destroy(t.baseTexture)),this.automator.destroy(),this.internalModel.destroy(),super.destroy(t)}}if("undefined"==typeof window||void 0===window.Live2DCubismCore)throw new Error("Could not find Cubism runtime. This plugin requires live2dcubismcore.js to be loaded.");class be{constructor(t,e){this.x=t,this.y=e,this.x=null==t?0:t,this.y=null==e?0:e}add(t){const e=new be(0,0);return e.x=this.x+t.x,e.y=this.y+t.y,e}substract(t){const e=new be(0,0);return e.x=this.x-t.x,e.y=this.y-t.y,e}multiply(t){const e=new be(0,0);return e.x=this.x*t.x,e.y=this.y*t.y,e}multiplyByScaler(t){return this.multiply(new be(t,t))}division(t){const e=new be(0,0);return e.x=this.x/t.x,e.y=this.y/t.y,e}divisionByScalar(t){return this.division(new be(t,t))}getLength(){return Math.sqrt(this.x*this.x+this.y*this.y)}getDistanceWith(t){return Math.sqrt((this.x-t.x)*(this.x-t.x)+(this.y-t.y)*(this.y-t.y))}dot(t){return this.x*t.x+this.y*t.y}normalize(){const t=Math.pow(this.x*this.x+this.y*this.y,.5);this.x=this.x/t,this.y=this.y/t}isEqual(t){return this.x==t.x&&this.y==t.y}isNotEqual(t){return!this.isEqual(t)}}var Pe;(t=>{t.CubismVector2=be})(Pe||(Pe={}));const Be=class t{static range(t,e,i){return t<e?t=e:t>i&&(t=i),t}static sin(t){return Math.sin(t)}static cos(t){return Math.cos(t)}static abs(t){return Math.abs(t)}static sqrt(t){return Math.sqrt(t)}static cbrt(t){if(0===t)return t;let e=t;const i=e<0;let r;return i&&(e=-e),e===1/0?r=1/0:(r=Math.exp(Math.log(e)/3),r=(e/(r*r)+2*r)/3),i?-r:r}static getEasingSine(t){return t<0?0:t>1?1:.5-.5*this.cos(t*Math.PI)}static max(t,e){return t>e?t:e}static min(t,e){return t>e?e:t}static clamp(t,e,i){return t<e?e:i<t?i:t}static degreesToRadian(t){return t/180*Math.PI}static radianToDegrees(t){return 180*t/Math.PI}static directionToRadian(t,e){let i=Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x);for(;i<-Math.PI;)i+=2*Math.PI;for(;i>Math.PI;)i-=2*Math.PI;return i}static directionToDegrees(t,e){const i=this.directionToRadian(t,e);let r=this.radianToDegrees(i);return e.x-t.x>0&&(r=-r),r}static radianToDirection(t){const e=new be;return e.x=this.sin(t),e.y=this.cos(t),e}static quadraticEquation(e,i,r){return this.abs(e)<t.Epsilon?this.abs(i)<t.Epsilon?-r:-r/i:-(i+this.sqrt(i*i-4*e*r))/(2*e)}static cardanoAlgorithmForBezier(e,i,r,s){if(this.abs(e)<t.Epsilon)return this.range(this.quadraticEquation(i,r,s),0,1);const a=i/e,n=r/e,o=(3*n-a*a)/3,l=o/3,u=(2*a*a*a-9*a*n+27*(s/e))/27,h=u/2,d=h*h+l*l*l,g=.5,c=.51;if(d<0){const t=-o/3,e=t*t*t,i=this.sqrt(e),r=-u/(2*i),s=this.range(r,-1,1),n=Math.acos(s),l=2*this.cbrt(i),h=l*this.cos(n/3)-a/3;if(this.abs(h-g)<c)return this.range(h,0,1);const d=l*this.cos((n+2*Math.PI)/3)-a/3;if(this.abs(d-g)<c)return this.range(d,0,1);const m=l*this.cos((n+4*Math.PI)/3)-a/3;return this.range(m,0,1)}if(0==d){let t;t=h<0?this.cbrt(-h):-this.cbrt(h);const e=2*t-a/3;if(this.abs(e-g)<c)return this.range(e,0,1);const i=-t-a/3;return this.range(i,0,1)}const m=this.sqrt(d),p=this.cbrt(m-h)-this.cbrt(m+h)-a/3;return this.range(p,0,1)}static mod(t,e){if(!isFinite(t)||0===e||isNaN(t)||isNaN(e))return console.warn(`divided: ${t}, divisor: ${e} mod() returns 'NaN'.`),NaN;const i=Math.abs(t),r=Math.abs(e);let s=i-Math.floor(i/r)*r;return s*=Math.sign(t),s}constructor(){}};Be.Epsilon=1e-5;let we=Be;var Fe,Ie;(t=>{t.CubismMath=we})(Fe||(Fe={}));class Ee{constructor(){this.setBeganMotionHandler=t=>this._onBeganMotion=t,this.getBeganMotionHandler=()=>this._onBeganMotion,this.setFinishedMotionHandler=t=>this._onFinishedMotion=t,this.getFinishedMotionHandler=()=>this._onFinishedMotion,this._fadeInSeconds=-1,this._fadeOutSeconds=-1,this._weight=1,this._offsetSeconds=0,this._isLoop=!1,this._isLoopFadeIn=!0,this._previousLoopState=this._isLoop,this._firedEventValues=new p}static delete(t){t.release(),t=null}release(){this._weight=0}updateParameters(t,e,i){if(!e.isAvailable()||e.isFinished())return;this.setupMotionQueueEntry(e,i);const r=this.updateFadeWeight(e,i);this.doUpdateParameters(t,i,r,e),e.getEndTime()>0&&e.getEndTime()<i&&e.setIsFinished(!0)}setupMotionQueueEntry(t,e){null==t||t.isStarted()||t.isAvailable()&&(t.setIsStarted(!0),t.setStartTime(e-this._offsetSeconds),t.setFadeInStartTime(e),t.getEndTime()<0&&this.adjustEndTime(t),t._motion._onBeganMotion&&t._motion._onBeganMotion(t._motion))}updateFadeWeight(t,e){null==t&&z.print(mt.LogLevel_Error,"motionQueueEntry is null.");let i=this._weight;return i=i*(0==this._fadeInSeconds?1:we.getEasingSine((e-t.getFadeInStartTime())/this._fadeInSeconds))*(0==this._fadeOutSeconds||t.getEndTime()<0?1:we.getEasingSine((t.getEndTime()-e)/this._fadeOutSeconds)),t.setState(e,i),A(0<=i&&i<=1),i}setFadeInTime(t){this._fadeInSeconds=t}setFadeOutTime(t){this._fadeOutSeconds=t}getFadeOutTime(){return this._fadeOutSeconds}getFadeInTime(){return this._fadeInSeconds}setWeight(t){this._weight=t}getWeight(){return this._weight}getDuration(){return-1}getLoopDuration(){return-1}setOffsetTime(t){this._offsetSeconds=t}setLoop(t){this._isLoop=t}getLoop(){return this._isLoop}setLoopFadeIn(t){this._isLoopFadeIn=t}getLoopFadeIn(){return this._isLoopFadeIn}getFiredEvent(t,e){return this._firedEventValues}isExistModelOpacity(){return!1}getModelOpacityIndex(){return-1}getModelOpacityId(t){return null}getModelOpacityValue(){return 1}adjustEndTime(t){const e=this.getDuration(),i=e<=0?-1:t.getStartTime()+e;t.setEndTime(i)}}(t=>{t.ACubismMotion=Ee})(Ie||(Ie={}));const Ve="Parameters",Le="Blend",Re=class t extends Ee{static create(e,i){const r=new t;return r.parse(e,i),r}doUpdateParameters(t,e,i,r){for(let s=0;s<this._parameters.getSize();++s){const e=this._parameters.at(s);switch(e.blendType){case 0:t.addParameterValueById(e.parameterId,e.value,i);break;case 1:t.multiplyParameterValueById(e.parameterId,e.value,i);break;case 2:t.setParameterValueById(e.parameterId,e.value,i)}}}calculateExpressionParameters(e,i,r,s,a,n){if(null!=r&&null!=s&&r.isAvailable()){this._fadeWeight=this.updateFadeWeight(r,i);for(let i=0;i<s.getSize();++i){const r=s.at(i);if(null==r.parameterId)continue;const o=r.overwriteValue=e.getParameterValueById(r.parameterId),l=this.getExpressionParameters();let u=-1;for(let t=0;t<l.getSize();++t)if(r.parameterId==l.at(t).parameterId){u=t;break}if(u<0){0==a?(r.additiveValue=t.DefaultAdditiveValue,r.multiplyValue=t.DefaultMultiplyValue,r.overwriteValue=o):(r.additiveValue=this.calculateValue(r.additiveValue,t.DefaultAdditiveValue,n),r.multiplyValue=this.calculateValue(r.multiplyValue,t.DefaultMultiplyValue,n),r.overwriteValue=this.calculateValue(r.overwriteValue,o,n));continue}const h=l.at(u).value;let d,g,c;switch(l.at(u).blendType){case 0:d=h,g=t.DefaultMultiplyValue,c=o;break;case 1:d=t.DefaultAdditiveValue,g=h,c=o;break;case 2:d=t.DefaultAdditiveValue,g=t.DefaultMultiplyValue,c=h;break;default:return}0==a?(r.additiveValue=d,r.multiplyValue=g,r.overwriteValue=c):(r.additiveValue=r.additiveValue*(1-n)+d*n,r.multiplyValue=r.multiplyValue*(1-n)+g*n,r.overwriteValue=r.overwriteValue*(1-n)+c*n)}}}getExpressionParameters(){return this._parameters}getFadeWeight(){return this._fadeWeight}parse(t,e){const i=Z.create(t,e);if(!i)return;const r=i.getRoot();this.setFadeInTime(r.getValueByString("FadeInTime").toFloat(1)),this.setFadeOutTime(r.getValueByString("FadeOutTime").toFloat(1));const s=r.getValueByString(Ve).getSize();this._parameters.prepareCapacity(s);for(let a=0;a<s;++a){const t=r.getValueByString(Ve).getValueByIndex(a),e=ct.getIdManager().getId(t.getValueByString("Id").getRawString()),i=t.getValueByString("Value").toFloat();let s;s=t.getValueByString(Le).isNull()||"Add"==t.getValueByString(Le).getString()?0:"Multiply"==t.getValueByString(Le).getString()?1:"Overwrite"==t.getValueByString(Le).getString()?2:0;const n=new ke;n.parameterId=e,n.blendType=s,n.value=i,this._parameters.pushBack(n)}Z.delete(i)}calculateValue(t,e,i){return t*(1-i)+e*i}constructor(){super(),this._parameters=new p,this._fadeWeight=0}};Re.DefaultAdditiveValue=0,Re.DefaultMultiplyValue=1;let Te=Re;var De,Ae,Oe=(t=>(t[t.Additive=0]="Additive",t[t.Multiply=1]="Multiply",t[t.Overwrite=2]="Overwrite",t))(Oe||{});class ke{}(t=>{t.CubismExpressionMotion=Te,t.ExpressionBlendType=Oe,t.ExpressionParameter=ke})(De||(De={}));class Ne{constructor(){this._autoDelete=!1,this._motion=null,this._available=!0,this._finished=!1,this._started=!1,this._startTimeSeconds=-1,this._fadeInStartTimeSeconds=0,this._endTimeSeconds=-1,this._stateTimeSeconds=0,this._stateWeight=0,this._lastEventCheckSeconds=0,this._motionQueueEntryHandle=this,this._fadeOutSeconds=0,this._isTriggeredFadeOut=!1}release(){this._autoDelete&&this._motion&&Ee.delete(this._motion)}setFadeOut(t){this._fadeOutSeconds=t,this._isTriggeredFadeOut=!0}startFadeOut(t,e){const i=e+t;this._isTriggeredFadeOut=!0,(this._endTimeSeconds<0||i<this._endTimeSeconds)&&(this._endTimeSeconds=i)}isFinished(){return this._finished}isStarted(){return this._started}getStartTime(){return this._startTimeSeconds}getFadeInStartTime(){return this._fadeInStartTimeSeconds}getEndTime(){return this._endTimeSeconds}setStartTime(t){this._startTimeSeconds=t}setFadeInStartTime(t){this._fadeInStartTimeSeconds=t}setEndTime(t){this._endTimeSeconds=t}setIsFinished(t){this._finished=t}setIsStarted(t){this._started=t}isAvailable(){return this._available}setIsAvailable(t){this._available=t}setState(t,e){this._stateTimeSeconds=t,this._stateWeight=e}getStateTime(){return this._stateTimeSeconds}getStateWeight(){return this._stateWeight}getLastCheckEventSeconds(){return this._lastEventCheckSeconds}setLastCheckEventSeconds(t){this._lastEventCheckSeconds=t}isTriggeredFadeOut(){return this._isTriggeredFadeOut}getFadeOutSeconds(){return this._fadeOutSeconds}getCubismMotion(){return this._motion}}(t=>{t.CubismMotionQueueEntry=Ne})(Ae||(Ae={}));class Ue{constructor(){this._userTimeSeconds=0,this._eventCallBack=null,this._eventCustomData=null,this._motions=new p}release(){for(let t=0;t<this._motions.getSize();++t)this._motions.at(t)&&(this._motions.at(t).release(),this._motions.set(t,null));this._motions=null}startMotion(t,e,i){if(null==t)return ze;let r=null;for(let s=0;s<this._motions.getSize();++s)r=this._motions.at(s),null!=r&&r.setFadeOut(r._motion.getFadeOutTime());return r=new Ne,r._autoDelete=e,r._motion=t,this._motions.pushBack(r),r._motionQueueEntryHandle}isFinished(){for(let t=this._motions.begin();t.notEqual(this._motions.end());){let e=t.ptr();if(null==e){t=this._motions.erase(t);continue}if(null!=e._motion){if(!e.isFinished())return!1;t.preIncrement()}else e.release(),e=null,t=this._motions.erase(t)}return!0}isFinishedByHandle(t){for(let e=this._motions.begin();e.notEqual(this._motions.end());e.increment()){const i=e.ptr();if(null!=i&&(i._motionQueueEntryHandle==t&&!i.isFinished()))return!1}return!0}stopAllMotions(){for(let t=this._motions.begin();t.notEqual(this._motions.end());){let e=t.ptr();null!=e?(e.release(),e=null,t=this._motions.erase(t)):t=this._motions.erase(t)}}getCubismMotionQueueEntries(){return this._motions}getCubismMotionQueueEntry(t){for(let e=this._motions.begin();e.notEqual(this._motions.end());e.preIncrement()){const i=e.ptr();if(null!=i&&i._motionQueueEntryHandle==t)return i}return null}setEventCallback(t,e=null){this._eventCallBack=t,this._eventCustomData=e}doUpdateMotion(t,e){let i=!1;for(let r=this._motions.begin();r.notEqual(this._motions.end());){let s=r.ptr();if(null==s){r=this._motions.erase(r);continue}const a=s._motion;if(null==a){s.release(),s=null,r=this._motions.erase(r);continue}a.updateParameters(t,s,e),i=!0;const n=a.getFiredEvent(s.getLastCheckEventSeconds()-s.getStartTime(),e-s.getStartTime());for(let t=0;t<n.getSize();++t)this._eventCallBack(this,n.at(t),this._eventCustomData);s.setLastCheckEventSeconds(e),s.isFinished()?(s.release(),s=null,r=this._motions.erase(r)):(s.isTriggeredFadeOut()&&s.startFadeOut(s.getFadeOutSeconds(),e),r.preIncrement())}return i}}const ze=-1;var je;(t=>{t.CubismMotionQueueManager=Ue,t.InvalidMotionQueueEntryHandleValue=ze})(je||(je={}));class Ge extends Bt{constructor(t,e){var i,r;super(t,e),g(this,"expressionDataType","arraybuffer"),g(this,"queueManager",new Ue),g(this,"definitions"),this.definitions=null!=(r=null==(i=t.expressions)?void 0:i.filter(t=>!!t&&"string"==typeof t.File))?r:[],this.init()}isFinished(){return this.queueManager.isFinished()}getExpressionIndex(t){return this.definitions.findIndex(e=>e.Name===t)}getExpressionFile(t){return t.File}createExpression(t,e){return Te.create(t,t.byteLength)}_setExpression(t){return this.queueManager.startMotion(t,!1)}stopAllExpressions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.doUpdateMotion(t,e)}createDefaultExpression(){const t=(new TextEncoder).encode(JSON.stringify({FadeInTime:0,FadeOutTime:0,Parameters:[]})).buffer;return Te.create(t,t.byteLength)}}var Xe,He=(t=>(t[t.CubismMotionCurveTarget_Model=0]="CubismMotionCurveTarget_Model",t[t.CubismMotionCurveTarget_Parameter=1]="CubismMotionCurveTarget_Parameter",t[t.CubismMotionCurveTarget_PartOpacity=2]="CubismMotionCurveTarget_PartOpacity",t))(He||{}),qe=(t=>(t[t.CubismMotionSegmentType_Linear=0]="CubismMotionSegmentType_Linear",t[t.CubismMotionSegmentType_Bezier=1]="CubismMotionSegmentType_Bezier",t[t.CubismMotionSegmentType_Stepped=2]="CubismMotionSegmentType_Stepped",t[t.CubismMotionSegmentType_InverseStepped=3]="CubismMotionSegmentType_InverseStepped",t))(qe||{});class Ye{constructor(){this.time=0,this.value=0}}class We{constructor(){this.evaluate=null,this.basePointIndex=0,this.segmentType=0}}class Je{constructor(){this.type=0,this.segmentCount=0,this.baseSegmentIndex=0,this.fadeInTime=0,this.fadeOutTime=0}}class $e{constructor(){this.fireTime=0}}class Ze{constructor(){this.duration=0,this.loop=!1,this.curveCount=0,this.eventCount=0,this.fps=0,this.curves=new p,this.segments=new p,this.points=new p,this.events=new p}}(t=>{t.CubismMotionCurve=Je,t.CubismMotionCurveTarget=He,t.CubismMotionData=Ze,t.CubismMotionEvent=$e,t.CubismMotionPoint=Ye,t.CubismMotionSegment=We,t.CubismMotionSegmentType=qe})(Xe||(Xe={}));const Ke="Meta",Qe="Curves",ti="FadeInTime",ei="FadeOutTime",ii="Segments",ri="UserData";class si{constructor(t,e){this._json=Z.create(t,e)}release(){Z.delete(this._json)}getMotionDuration(){return this._json.getRoot().getValueByString(Ke).getValueByString("Duration").toFloat()}isMotionLoop(){return this._json.getRoot().getValueByString(Ke).getValueByString("Loop").toBoolean()}hasConsistency(){let t=!0;if(!this._json||!this._json.getRoot())return!1;const e=this._json.getRoot().getValueByString(Qe).getVector().getSize();let i=0,r=0;for(let s=0;s<e;++s)for(let t=0;t<this.getMotionCurveSegmentCount(s);){0==t&&(r+=1,t+=2);switch(this.getMotionCurveSegment(s,t)){case qe.CubismMotionSegmentType_Linear:r+=1,t+=3;break;case qe.CubismMotionSegmentType_Bezier:r+=3,t+=7;break;case qe.CubismMotionSegmentType_Stepped:case qe.CubismMotionSegmentType_InverseStepped:r+=1,t+=3;break;default:A(0)}++i}return e!=this.getMotionCurveCount()&&(N("The number of curves does not match the metadata."),t=!1),i!=this.getMotionTotalSegmentCount()&&(N("The number of segment does not match the metadata."),t=!1),r!=this.getMotionTotalPointCount()&&(N("The number of point does not match the metadata."),t=!1),t}getEvaluationOptionFlag(t){return 0==t&&this._json.getRoot().getValueByString(Ke).getValueByString("AreBeziersRestricted").toBoolean()}getMotionCurveCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("CurveCount").toInt()}getMotionFps(){return this._json.getRoot().getValueByString(Ke).getValueByString("Fps").toFloat()}getMotionTotalSegmentCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("TotalSegmentCount").toInt()}getMotionTotalPointCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("TotalPointCount").toInt()}isExistMotionFadeInTime(){return!this._json.getRoot().getValueByString(Ke).getValueByString(ti).isNull()}isExistMotionFadeOutTime(){return!this._json.getRoot().getValueByString(Ke).getValueByString(ei).isNull()}getMotionFadeInTime(){return this._json.getRoot().getValueByString(Ke).getValueByString(ti).toFloat()}getMotionFadeOutTime(){return this._json.getRoot().getValueByString(Ke).getValueByString(ei).toFloat()}getMotionCurveTarget(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString("Target").getRawString()}getMotionCurveId(t){return ct.getIdManager().getId(this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString("Id").getRawString())}isExistMotionCurveFadeInTime(t){return!this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ti).isNull()}isExistMotionCurveFadeOutTime(t){return!this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ei).isNull()}getMotionCurveFadeInTime(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ti).toFloat()}getMotionCurveFadeOutTime(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ei).toFloat()}getMotionCurveSegmentCount(t){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ii).getVector().getSize()}getMotionCurveSegment(t,e){return this._json.getRoot().getValueByString(Qe).getValueByIndex(t).getValueByString(ii).getValueByIndex(e).toFloat()}getEventCount(){return this._json.getRoot().getValueByString(Ke).getValueByString("UserDataCount").toInt()}getTotalEventValueSize(){return this._json.getRoot().getValueByString(Ke).getValueByString("TotalUserDataSize").toInt()}getEventTime(t){return this._json.getRoot().getValueByString(ri).getValueByIndex(t).getValueByString("Time").toFloat()}getEventValue(t){return new b(this._json.getRoot().getValueByString(ri).getValueByIndex(t).getValueByString("Value").getRawString())}}var ai,ni=(t=>(t[t.EvaluationOptionFlag_AreBeziersRistricted=0]="EvaluationOptionFlag_AreBeziersRistricted",t))(ni||{});(t=>{t.CubismMotionJson=si})(ai||(ai={}));const oi="Opacity";function li(t,e,i){const r=new Ye;return r.time=t.time+(e.time-t.time)*i,r.value=t.value+(e.value-t.value)*i,r}function ui(t,e){let i=(e-t[0].time)/(t[1].time-t[0].time);return i<0&&(i=0),t[0].value+(t[1].value-t[0].value)*i}function hi(t,e){let i=(e-t[0].time)/(t[3].time-t[0].time);i<0&&(i=0);const r=li(t[0],t[1],i),s=li(t[1],t[2],i),a=li(t[2],t[3],i),n=li(r,s,i),o=li(s,a,i);return li(n,o,i).value}function di(t,e){const i=e,r=t[0].time,s=t[3].time,a=t[1].time,n=t[2].time,o=s-3*n+3*a-r,l=3*n-6*a+3*r,u=3*a-3*r,h=r-i,d=we.cardanoAlgorithmForBezier(o,l,u,h),g=li(t[0],t[1],d),c=li(t[1],t[2],d),m=li(t[2],t[3],d),p=li(g,c,d),_=li(c,m,d);return li(p,_,d).value}function gi(t,e){return t[0].value}function ci(t,e){return t[1].value}function mi(t,e,i,r,s){const a=t.curves.at(e);let n=-1;const o=a.baseSegmentIndex+a.segmentCount;let l=0;for(let h=a.baseSegmentIndex;h<o;++h)if(l=t.segments.at(h).basePointIndex+(t.segments.at(h).segmentType==qe.CubismMotionSegmentType_Bezier?3:1),t.points.at(l).time>i){n=h;break}if(-1==n)return r&&i<s?function(t,e,i,r,s,a){const n=[new Ye,new Ye];{const e=t.points.at(r);n[0].time=e.time,n[0].value=e.value}{const e=t.points.at(i);n[1].time=a,n[1].value=e.value}switch(t.segments.at(e).segmentType){case qe.CubismMotionSegmentType_Linear:case qe.CubismMotionSegmentType_Bezier:default:return ui(n,s);case qe.CubismMotionSegmentType_Stepped:return gi(n);case qe.CubismMotionSegmentType_InverseStepped:return ci(n)}}(t,o-1,t.segments.at(a.baseSegmentIndex).basePointIndex,l,i,s):t.points.at(l).value;const u=t.segments.at(n);return u.evaluate(t.points.get(u.basePointIndex),i)}class pi extends Ee{constructor(){super(),this._motionBehavior=1,this._sourceFrameRate=30,this._loopDurationSeconds=-1,this._isLoop=!1,this._isLoopFadeIn=!0,this._lastWeight=0,this._motionData=null,this._modelCurveIdEyeBlink=null,this._modelCurveIdLipSync=null,this._modelCurveIdOpacity=null,this._eyeBlinkParameterIds=null,this._lipSyncParameterIds=null,this._modelOpacity=1,this._debugMode=!1}static create(t,e,i,r,s=!1){const a=new pi;return a.parse(t,e,s),a._motionData?(a._sourceFrameRate=a._motionData.fps,a._loopDurationSeconds=a._motionData.duration,a._onFinishedMotion=i,a._onBeganMotion=r,a):(gt(a),null)}doUpdateParameters(t,e,i,r){null==this._modelCurveIdEyeBlink&&(this._modelCurveIdEyeBlink=ct.getIdManager().getId("EyeBlink")),null==this._modelCurveIdLipSync&&(this._modelCurveIdLipSync=ct.getIdManager().getId("LipSync")),null==this._modelCurveIdOpacity&&(this._modelCurveIdOpacity=ct.getIdManager().getId(oi)),1===this._motionBehavior&&this._previousLoopState!==this._isLoop&&(this.adjustEndTime(r),this._previousLoopState=this._isLoop);let s=e-r.getStartTime();s<0&&(s=0);let a=Number.MAX_VALUE,n=Number.MAX_VALUE;const o=64;let l=0,u=0;this._eyeBlinkParameterIds.getSize()>o&&O("too many eye blink targets : {0}",this._eyeBlinkParameterIds.getSize()),this._lipSyncParameterIds.getSize()>o&&O("too many lip sync targets : {0}",this._lipSyncParameterIds.getSize());const h=this._fadeInSeconds<=0?1:we.getEasingSine((e-r.getFadeInStartTime())/this._fadeInSeconds),d=this._fadeOutSeconds<=0||r.getEndTime()<0?1:we.getEasingSine((r.getEndTime()-e)/this._fadeOutSeconds);let g,c,m,p=s,_=this._motionData.duration;const f=1===this._motionBehavior&&this._isLoop;if(this._isLoop)for(1===this._motionBehavior&&(_+=1/this._motionData.fps);p>_;)p-=_;const y=this._motionData.curves;for(c=0;c<this._motionData.curveCount&&y.at(c).type==He.CubismMotionCurveTarget_Model;++c)g=mi(this._motionData,c,p,f,_),y.at(c).id==this._modelCurveIdEyeBlink?n=g:y.at(c).id==this._modelCurveIdLipSync?a=g:y.at(c).id==this._modelCurveIdOpacity&&(this._modelOpacity=g,t.setModelOapcity(this.getModelOpacityValue()));for(;c<this._motionData.curveCount&&y.at(c).type==He.CubismMotionCurveTarget_Parameter;++c){if(m=t.getParameterIndex(y.at(c).id),-1==m)continue;const s=t.getParameterValueByIndex(m);if(g=mi(this._motionData,c,p,f,_),n!=Number.MAX_VALUE)for(let t=0;t<this._eyeBlinkParameterIds.getSize()&&t<o;++t)if(this._eyeBlinkParameterIds.at(t)==y.at(c).id){g*=n,u|=1<<t;break}if(a!=Number.MAX_VALUE)for(let t=0;t<this._lipSyncParameterIds.getSize()&&t<o;++t)if(this._lipSyncParameterIds.at(t)==y.at(c).id){g+=a,l|=1<<t;break}let x;if(t.isRepeat(m)&&(g=t.getParameterRepeatValue(m,g)),y.at(c).fadeInTime<0&&y.at(c).fadeOutTime<0)x=s+(g-s)*i;else{let t,i;t=y.at(c).fadeInTime<0?h:0==y.at(c).fadeInTime?1:we.getEasingSine((e-r.getFadeInStartTime())/y.at(c).fadeInTime),i=y.at(c).fadeOutTime<0?d:0==y.at(c).fadeOutTime||r.getEndTime()<0?1:we.getEasingSine((r.getEndTime()-e)/y.at(c).fadeOutTime);x=s+(g-s)*(this._weight*t*i)}t.setParameterValueByIndex(m,x,1)}if(n!=Number.MAX_VALUE)for(let x=0;x<this._eyeBlinkParameterIds.getSize()&&x<o;++x){const e=t.getParameterValueById(this._eyeBlinkParameterIds.at(x));if(u>>x&1)continue;const r=e+(n-e)*i;t.setParameterValueById(this._eyeBlinkParameterIds.at(x),r)}if(a!=Number.MAX_VALUE)for(let x=0;x<this._lipSyncParameterIds.getSize()&&x<o;++x){const e=t.getParameterValueById(this._lipSyncParameterIds.at(x));if(l>>x&1)continue;const r=e+(a-e)*i;t.setParameterValueById(this._lipSyncParameterIds.at(x),r)}for(;c<this._motionData.curveCount&&y.at(c).type==He.CubismMotionCurveTarget_PartOpacity;++c)m=t.getParameterIndex(y.at(c).id),-1!=m&&(g=mi(this._motionData,c,p,f,_),t.setParameterValueByIndex(m,g));s>=_&&(this._isLoop?this.updateForNextLoop(r,e,p):(this._onFinishedMotion&&this._onFinishedMotion(this),r.setIsFinished(!0))),this._lastWeight=i}setIsLoop(t){N("setIsLoop() is a deprecated function. Please use setLoop()."),this._isLoop=t}isLoop(){return N("isLoop() is a deprecated function. Please use getLoop()."),this._isLoop}setIsLoopFadeIn(t){N("setIsLoopFadeIn() is a deprecated function. Please use setLoopFadeIn()."),this._isLoopFadeIn=t}isLoopFadeIn(){return N("isLoopFadeIn() is a deprecated function. Please use getLoopFadeIn()."),this._isLoopFadeIn}setMotionBehavior(t){this._motionBehavior=t}getMotionBehavior(){return this._motionBehavior}getDuration(){return this._isLoop?-1:this._loopDurationSeconds}getLoopDuration(){return this._loopDurationSeconds}setParameterFadeInTime(t,e){const i=this._motionData.curves;for(let r=0;r<this._motionData.curveCount;++r)if(t==i.at(r).id)return void(i.at(r).fadeInTime=e)}setParameterFadeOutTime(t,e){const i=this._motionData.curves;for(let r=0;r<this._motionData.curveCount;++r)if(t==i.at(r).id)return void(i.at(r).fadeOutTime=e)}getParameterFadeInTime(t){const e=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==e.at(i).id)return e.at(i).fadeInTime;return-1}getParameterFadeOutTime(t){const e=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==e.at(i).id)return e.at(i).fadeOutTime;return-1}setEffectIds(t,e){this._eyeBlinkParameterIds=t,this._lipSyncParameterIds=e}release(){this._motionData=void 0,this._motionData=null}updateForNextLoop(t,e,i){switch(this._motionBehavior){case 1:default:t.setStartTime(e-i),this._isLoopFadeIn&&t.setFadeInStartTime(e-i),null!=this._onFinishedMotion&&this._onFinishedMotion(this);break;case 0:t.setStartTime(e),this._isLoopFadeIn&&t.setFadeInStartTime(e)}}parse(t,e,i=!1){let r=new si(t,e);if(!r)return r.release(),void(r=void 0);if(i){if(!r.hasConsistency())return r.release(),void U("Inconsistent motion3.json.")}this._motionData=new Ze,this._motionData.duration=r.getMotionDuration(),this._motionData.loop=r.isMotionLoop(),this._motionData.curveCount=r.getMotionCurveCount(),this._motionData.fps=r.getMotionFps(),this._motionData.eventCount=r.getEventCount();const s=r.getEvaluationOptionFlag(ni.EvaluationOptionFlag_AreBeziersRistricted);r.isExistMotionFadeInTime()?this._fadeInSeconds=r.getMotionFadeInTime()<0?1:r.getMotionFadeInTime():this._fadeInSeconds=1,r.isExistMotionFadeOutTime()?this._fadeOutSeconds=r.getMotionFadeOutTime()<0?1:r.getMotionFadeOutTime():this._fadeOutSeconds=1,this._motionData.curves.updateSize(this._motionData.curveCount,Je,!0),this._motionData.segments.updateSize(r.getMotionTotalSegmentCount(),We,!0),this._motionData.points.updateSize(r.getMotionTotalPointCount(),Ye,!0),this._motionData.events.updateSize(this._motionData.eventCount,$e,!0);let a=0,n=0;for(let o=0;o<this._motionData.curveCount;++o){"Model"==r.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=He.CubismMotionCurveTarget_Model:"Parameter"==r.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=He.CubismMotionCurveTarget_Parameter:"PartOpacity"==r.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=He.CubismMotionCurveTarget_PartOpacity:N('Warning : Unable to get segment type from Curve! The number of "CurveCount" may be incorrect!'),this._motionData.curves.at(o).id=r.getMotionCurveId(o),this._motionData.curves.at(o).baseSegmentIndex=n,this._motionData.curves.at(o).fadeInTime=r.isExistMotionCurveFadeInTime(o)?r.getMotionCurveFadeInTime(o):-1,this._motionData.curves.at(o).fadeOutTime=r.isExistMotionCurveFadeOutTime(o)?r.getMotionCurveFadeOutTime(o):-1;for(let t=0;t<r.getMotionCurveSegmentCount(o);){0==t?(this._motionData.segments.at(n).basePointIndex=a,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+1),a+=1,t+=2):this._motionData.segments.at(n).basePointIndex=a-1;switch(r.getMotionCurveSegment(o,t)){case qe.CubismMotionSegmentType_Linear:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_Linear,this._motionData.segments.at(n).evaluate=ui,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case qe.CubismMotionSegmentType_Bezier:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_Bezier,this._motionData.segments.at(n).evaluate=s?hi:di,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),this._motionData.points.at(a+1).time=r.getMotionCurveSegment(o,t+3),this._motionData.points.at(a+1).value=r.getMotionCurveSegment(o,t+4),this._motionData.points.at(a+2).time=r.getMotionCurveSegment(o,t+5),this._motionData.points.at(a+2).value=r.getMotionCurveSegment(o,t+6),a+=3,t+=7;break;case qe.CubismMotionSegmentType_Stepped:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_Stepped,this._motionData.segments.at(n).evaluate=gi,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case qe.CubismMotionSegmentType_InverseStepped:this._motionData.segments.at(n).segmentType=qe.CubismMotionSegmentType_InverseStepped,this._motionData.segments.at(n).evaluate=ci,this._motionData.points.at(a).time=r.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=r.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;default:A(0)}++this._motionData.curves.at(o).segmentCount,++n}}for(let o=0;o<r.getEventCount();++o)this._motionData.events.at(o).fireTime=r.getEventTime(o),this._motionData.events.at(o).value=r.getEventValue(o);r.release(),r=void 0,r=null}getFiredEvent(t,e){this._firedEventValues.updateSize(0);for(let i=0;i<this._motionData.eventCount;++i)this._motionData.events.at(i).fireTime>t&&this._motionData.events.at(i).fireTime<=e&&this._firedEventValues.pushBack(new b(this._motionData.events.at(i).value.s));return this._firedEventValues}isExistModelOpacity(){for(let t=0;t<this._motionData.curveCount;t++){const e=this._motionData.curves.at(t);if(e.type==He.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(oi))return!0}return!1}getModelOpacityIndex(){if(this.isExistModelOpacity())for(let t=0;t<this._motionData.curveCount;t++){const e=this._motionData.curves.at(t);if(e.type==He.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(oi))return t}return-1}getModelOpacityId(t){if(-1!=t){const e=this._motionData.curves.at(t);if(e.type==He.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(oi))return ct.getIdManager().getId(e.id.getString().s)}return null}getModelOpacityValue(){return this._modelOpacity}setDebugMode(t){this._debugMode=t}}var _i;function fi(t,e,i){const r=t.startMotion(i,!1),s=t.getCubismMotionQueueEntry(r);if(!s)return!1;s.setStartTime(0),s.setFadeInStartTime(0);const a=i.getDuration(),n=s.getStartTime()+a;return i.doUpdateParameters(e.coreModel,n,1,s),s.setIsFinished(!0),!0}(t=>{t.CubismMotion=pi})(_i||(_i={}));class yi extends Ot{constructor(t){var e;super(t),g(this,"definitions"),g(this,"groups",{idle:"Idle"}),g(this,"motionDataType","arraybuffer"),g(this,"queueManager",new Ue),g(this,"expressionManager"),g(this,"eyeBlinkIds"),g(this,"lipSyncIds",["ParamMouthOpenY"]),this.definitions=null!=(e=t.settings.motions)?e:{},this.eyeBlinkIds=t.settings.getEyeBlinkParameters()||[];const i=t.settings.getLipSyncParameters();(null==i?void 0:i.length)&&(this.lipSyncIds=i),this.init(t.options)}init(t){super.init(t),this.settings.expressions&&(this.expressionManager=new Ge(this.settings,t)),this.queueManager.setEventCallback((t,e)=>{const i="string"==typeof e?e:"number"==typeof e?String(e):e&&"object"==typeof e?e.s:"undefined";this.emit("motion:"+i)})}isFinished(){return this.queueManager.isFinished()}_startMotion(t,e,i){if(t.setFinishedMotionHandler(e),i&&i.length>0){const e=t._motionData.curves,r=function(t){if(xi(t))return new p;return[]}(e),s=Ci(e);for(let t=0;t<s;t++){const s=Mi(e,t);if(!s)continue;const a=Si(s);a&&i.includes(a)||vi(r,s)}t._motionData.curves=r,t._motionData.curveCount=Ci(r)}return this.queueManager.stopAllMotions(),this.queueManager.startMotion(t,!1)}_stopAllMotions(){this.queueManager.stopAllMotions()}createMotion(t,e,i){const r=!!this.parent.options.checkMotionConsistency,s=pi.create(t,t.byteLength,void 0,void 0,r),a=new si(t,t.byteLength),n=(e===this.groups.idle?pt.idleMotionFadingDuration:pt.motionFadingDuration)/1e3;return void 0===a.getMotionFadeInTime()&&s.setFadeInTime(i.FadeInTime>0?i.FadeInTime:n),void 0===a.getMotionFadeOutTime()&&s.setFadeOutTime(i.FadeOutTime>0?i.FadeOutTime:n),s.setEffectIds(this.createIdVector(this.eyeBlinkIds),this.createIdVector(this.lipSyncIds)),s}getMotionFile(t){return t.File}getMotionName(t){return t.File}getSoundFile(t){return t.Sound}updateParameters(t,e){return this.queueManager.doUpdateMotion(t,e)}destroy(){super.destroy(),this.queueManager.release(),this.queueManager=void 0}motionLastFrame(t,e){return c(this,arguments,function*(t,e,{expression:i}={}){const r=yield this.getMotionAndApplyExpression(t,e,i);return!!r&&(this.playing=!0,fi(this.queueManager,this.parent,r),this.playing=!1,!0)})}createIdVector(t){const e=new p,i=ct.getIdManager();for(const r of t)e.pushBack(i.getId(r));return e}}function xi(t){return"function"==typeof t.pushBack}function Ci(t){return xi(t)?t.getSize():t.length}function Mi(t,e){return xi(t)?t.at(e):t[e]}function Si(t){if(!t||"object"!=typeof t)return;const e=t.id;return"string"==typeof e?e:e&&"function"==typeof e.getString?e.getString().s:void 0}function vi(t,e){xi(t)?t.pushBack(e):t.push(e)}class bi extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"manager"),g(this,"settings"),g(this,"state",new Lt),g(this,"playing",!1),g(this,"destroyed",!1),g(this,"parent"),this.settings=t.settings,this.tag=`ParallelMotionManager(${this.settings.name})`,this.state.tag=this.tag,this.manager=t.motionManager,this.parent=t}startMotion(t,e){return c(this,arguments,function*(t,e,i=Vt.NORMAL,r=[]){var s;if(!this.state.reserve(t,e,i))return!1;const a=null==(s=this.manager.definitions[t])?void 0:s[e];if(!a)return!1;const n=yield this.manager.loadMotion(t,e);return!!this.state.start(n,t,e,i)&&(_t.log(this.tag,"Start motion:",this.getMotionName(a)),this.emit("motionStart",t,e,void 0),this.playing=!0,this._startMotion(n,void 0,r),!0)})}startRandomMotion(t,e){return c(this,null,function*(){var i;const r=this.manager.definitions[t];if(null==r?void 0:r.length){const s=[],a=null!=(i=this.manager.motionGroups[t])?i:[];for(let e=0;e<r.length;e++)null===a[e]||this.state.isActive(t,e)||s.push(e);if(s.length){const i=s[Math.floor(Math.random()*s.length)];return this.startMotion(t,i,e)}}return!1})}stopAllMotions(){this._stopAllMotions(),this.state.reset()}update(t,e){return this.isFinished()&&(this.playing&&(this.playing=!1,this.emit("motionFinish")),this.state.complete()),this.updateParameters(t,e)}destroy(){this.destroyed=!0,this.emit("destroy"),this.stopAllMotions()}}class Pi extends bi{constructor(t){super(t),g(this,"queueManager",new Ue),this.init()}init(){this.queueManager.setEventCallback((t,e)=>{const i="string"==typeof e?e:"number"==typeof e?String(e):e&&"object"==typeof e?e.s:"undefined";this.emit("motion:"+i)})}isFinished(){return this.queueManager.isFinished()}_startMotion(t,e,i){if(t.setFinishedMotionHandler(e),i&&i.length>0){const e=t._motionData.curves,r=function(t){if(Bi(t))return new p;return[]}(e),s=wi(e);for(let t=0;t<s;t++){const s=Fi(e,t);if(!s)continue;const a=Ii(s);a&&i.includes(a)||Ei(r,s)}t._motionData.curves=r,t._motionData.curveCount=wi(r)}return this.queueManager.stopAllMotions(),this.queueManager.startMotion(t,!1)}_stopAllMotions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.doUpdateMotion(t,e)}getMotionName(t){return t.File}destroy(){super.destroy(),this.queueManager.release(),this.queueManager=void 0}playMotionLastFrame(t,e){return c(this,null,function*(){var i;if(!this.state.reserve(t,e,Vt.FORCE))return!1;const r=null==(i=this.manager.definitions[t])?void 0:i[e];if(!r)return!1;const s=yield this.manager.loadMotion(t,e);return!!this.state.start(s,t,e,Vt.FORCE)&&(_t.log(this.tag,"Start motion:",this.getMotionName(r)),this.emit("motionStart",t,e,void 0),this.playing=!0,this.queueManager.stopAllMotions(),fi(this.queueManager,this.parent,s)?(this.playing=!1,!0):(this.playing=!1,!1))})}}function Bi(t){return"function"==typeof t.pushBack}function wi(t){return Bi(t)?t.getSize():t.length}function Fi(t,e){return Bi(t)?t.at(e):t[e]}function Ii(t){if(!t||"object"!=typeof t)return;const e=t.id;return"string"==typeof e?e:e&&"function"==typeof e.getString?e.getString().s:void 0}function Ei(t,e){Bi(t)?t.pushBack(e):t.push(e)}const Vi=Object.freeze({HitAreaPrefix:"HitArea",HitAreaHead:"Head",HitAreaBody:"Body",PartsIdCore:"Parts01Core",PartsArmPrefix:"Parts01Arm_",PartsArmLPrefix:"Parts01ArmL_",PartsArmRPrefix:"Parts01ArmR_",ParamAngleX:"ParamAngleX",ParamAngleY:"ParamAngleY",ParamAngleZ:"ParamAngleZ",ParamEyeLOpen:"ParamEyeLOpen",ParamEyeLSmile:"ParamEyeLSmile",ParamEyeROpen:"ParamEyeROpen",ParamEyeRSmile:"ParamEyeRSmile",ParamEyeBallX:"ParamEyeBallX",ParamEyeBallY:"ParamEyeBallY",ParamEyeBallForm:"ParamEyeBallForm",ParamBrowLY:"ParamBrowLY",ParamBrowRY:"ParamBrowRY",ParamBrowLX:"ParamBrowLX",ParamBrowRX:"ParamBrowRX",ParamBrowLAngle:"ParamBrowLAngle",ParamBrowRAngle:"ParamBrowRAngle",ParamBrowLForm:"ParamBrowLForm",ParamBrowRForm:"ParamBrowRForm",ParamMouthForm:"ParamMouthForm",ParamMouthOpenY:"ParamMouthOpenY",ParamCheek:"ParamCheek",ParamBodyAngleX:"ParamBodyAngleX",ParamBodyAngleY:"ParamBodyAngleY",ParamBodyAngleZ:"ParamBodyAngleZ",ParamBreath:"ParamBreath",ParamArmLA:"ParamArmLA",ParamArmRA:"ParamArmRA",ParamArmLB:"ParamArmLB",ParamArmRB:"ParamArmRB",ParamHandL:"ParamHandL",ParamHandR:"ParamHandR",ParamHairFront:"ParamHairFront",ParamHairSide:"ParamHairSide",ParamHairBack:"ParamHairBack",ParamHairFluffy:"ParamHairFluffy",ParamShoulderY:"ParamShoulderY",ParamBustX:"ParamBustX",ParamBustY:"ParamBustY",ParamBaseX:"ParamBaseX",ParamBaseY:"ParamBaseY",ParamNONE:"NONE:"});var Li,Ri;(t=>{t.HitAreaBody=Vi.HitAreaBody,t.HitAreaHead=Vi.HitAreaHead,t.HitAreaPrefix=Vi.HitAreaPrefix,t.ParamAngleX=Vi.ParamAngleX,t.ParamAngleY=Vi.ParamAngleY,t.ParamAngleZ=Vi.ParamAngleZ,t.ParamArmLA=Vi.ParamArmLA,t.ParamArmLB=Vi.ParamArmLB,t.ParamArmRA=Vi.ParamArmRA,t.ParamArmRB=Vi.ParamArmRB,t.ParamBaseX=Vi.ParamBaseX,t.ParamBaseY=Vi.ParamBaseY,t.ParamBodyAngleX=Vi.ParamBodyAngleX,t.ParamBodyAngleY=Vi.ParamBodyAngleY,t.ParamBodyAngleZ=Vi.ParamBodyAngleZ,t.ParamBreath=Vi.ParamBreath,t.ParamBrowLAngle=Vi.ParamBrowLAngle,t.ParamBrowLForm=Vi.ParamBrowLForm,t.ParamBrowLX=Vi.ParamBrowLX,t.ParamBrowLY=Vi.ParamBrowLY,t.ParamBrowRAngle=Vi.ParamBrowRAngle,t.ParamBrowRForm=Vi.ParamBrowRForm,t.ParamBrowRX=Vi.ParamBrowRX,t.ParamBrowRY=Vi.ParamBrowRY,t.ParamBustX=Vi.ParamBustX,t.ParamBustY=Vi.ParamBustY,t.ParamCheek=Vi.ParamCheek,t.ParamEyeBallForm=Vi.ParamEyeBallForm,t.ParamEyeBallX=Vi.ParamEyeBallX,t.ParamEyeBallY=Vi.ParamEyeBallY,t.ParamEyeLOpen=Vi.ParamEyeLOpen,t.ParamEyeLSmile=Vi.ParamEyeLSmile,t.ParamEyeROpen=Vi.ParamEyeROpen,t.ParamEyeRSmile=Vi.ParamEyeRSmile,t.ParamHairBack=Vi.ParamHairBack,t.ParamHairFluffy=Vi.ParamHairFluffy,t.ParamHairFront=Vi.ParamHairFront,t.ParamHairSide=Vi.ParamHairSide,t.ParamHandL=Vi.ParamHandL,t.ParamHandR=Vi.ParamHandR,t.ParamMouthForm=Vi.ParamMouthForm,t.ParamMouthOpenY=Vi.ParamMouthOpenY,t.ParamNONE=Vi.ParamNONE,t.ParamShoulderY=Vi.ParamShoulderY,t.PartsArmLPrefix=Vi.PartsArmLPrefix,t.PartsArmPrefix=Vi.PartsArmPrefix,t.PartsArmRPrefix=Vi.PartsArmRPrefix,t.PartsIdCore=Vi.PartsIdCore})(Li||(Li={}));class Ti{static create(){return new Ti}static delete(t){}setParameters(t){this._breathParameters=t}getParameters(){return this._breathParameters}updateParameters(t,e){this._currentTime+=e;const i=2*this._currentTime*Math.PI;for(let r=0;r<this._breathParameters.getSize();++r){const e=this._breathParameters.at(r);t.addParameterValueById(e.parameterId,e.offset+e.peak*Math.sin(i/e.cycle),e.weight)}}constructor(){this._currentTime=0}}class Di{constructor(t,e,i,r,s){this.parameterId=null==t?null:t,this.offset=null==e?0:e,this.peak=null==i?0:i,this.cycle=null==r?0:r,this.weight=null==s?0:s}}(t=>{t.BreathParameterData=Di,t.CubismBreath=Ti})(Ri||(Ri={}));const Ai=class t{static create(e=null){return new t(e)}static delete(t){}setBlinkingInterval(t){this._blinkingIntervalSeconds=t}setBlinkingSetting(t,e,i){this._closingSeconds=t,this._closedSeconds=e,this._openingSeconds=i}setParameterIds(t){this._parameterIds=t}getParameterIds(){return this._parameterIds}updateParameters(e,i){let r;this._userTimeSeconds+=i;let s=0;switch(this._blinkingState){case 2:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closingSeconds,s>=1&&(s=1,this._blinkingState=3,this._stateStartTimeSeconds=this._userTimeSeconds),r=1-s;break;case 3:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closedSeconds,s>=1&&(this._blinkingState=4,this._stateStartTimeSeconds=this._userTimeSeconds),r=0;break;case 4:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._openingSeconds,s>=1&&(s=1,this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming()),r=s;break;case 1:this._nextBlinkingTime<this._userTimeSeconds&&(this._blinkingState=2,this._stateStartTimeSeconds=this._userTimeSeconds),r=1;break;default:this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming(),r=1}t.CloseIfZero||(r=-r);for(let t=0;t<this._parameterIds.getSize();++t)e.setParameterValueById(this._parameterIds.at(t),r)}constructor(t){if(this._blinkingState=0,this._nextBlinkingTime=0,this._stateStartTimeSeconds=0,this._blinkingIntervalSeconds=4,this._closingSeconds=.1,this._closedSeconds=.05,this._openingSeconds=.15,this._userTimeSeconds=0,this._parameterIds=new p,null!=t)for(let e=0;e<t.getEyeBlinkParameterCount();++e)this._parameterIds.pushBack(t.getEyeBlinkParameterId(e))}determinNextBlinkingTiming(){const t=Math.random();return this._userTimeSeconds+t*(2*this._blinkingIntervalSeconds-1)}};Ai.CloseIfZero=!0;let Oi=Ai;var ki,Ni=(t=>(t[t.EyeState_First=0]="EyeState_First",t[t.EyeState_Interval=1]="EyeState_Interval",t[t.EyeState_Closing=2]="EyeState_Closing",t[t.EyeState_Closed=3]="EyeState_Closed",t[t.EyeState_Opening=4]="EyeState_Opening",t))(Ni||{});(t=>{t.CubismEyeBlink=Oi,t.EyeState=Ni})(ki||(ki={}));class Ui{constructor(t){this._renderTextureCount=0,this._clippingMaskBufferSize=256,this._clippingContextListForMask=new p,this._clippingContextListForDraw=new p,this._channelColors=new p,this._tmpBoundsOnModel=new F,this._tmpMatrix=new w,this._tmpMatrixForMask=new w,this._tmpMatrixForDraw=new w,this._clippingContexttConstructor=t;let e=new L;e.r=1,e.g=0,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new L,e.r=0,e.g=1,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new L,e.r=0,e.g=0,e.b=1,e.a=0,this._channelColors.pushBack(e),e=new L,e.r=0,e.g=0,e.b=0,e.a=1,this._channelColors.pushBack(e)}release(){for(let t=0;t<this._clippingContextListForMask.getSize();t++)this._clippingContextListForMask.at(t)&&(this._clippingContextListForMask.at(t).release(),this._clippingContextListForMask.set(t,void 0)),this._clippingContextListForMask.set(t,null);this._clippingContextListForMask=null;for(let t=0;t<this._clippingContextListForDraw.getSize();t++)this._clippingContextListForDraw.set(t,null);this._clippingContextListForDraw=null;for(let t=0;t<this._channelColors.getSize();t++)this._channelColors.set(t,null);this._channelColors=null,null!=this._clearedFrameBufferFlags&&this._clearedFrameBufferFlags.clear(),this._clearedFrameBufferFlags=null}initialize(t,e){e%1!=0&&(N("The number of render textures must be specified as an integer. The decimal point is rounded down and corrected to an integer."),e=~~e),e<1&&N("The number of render textures must be an integer greater than or equal to 1. Set the number of render textures to 1."),this._renderTextureCount=e<1?1:e,this._clearedFrameBufferFlags=new p(this._renderTextureCount);for(let i=0;i<t.getDrawableCount();i++){if(t.getDrawableMaskCounts()[i]<=0){this._clippingContextListForDraw.pushBack(null);continue}let e=this.findSameClip(t.getDrawableMasks()[i],t.getDrawableMaskCounts()[i]);null==e&&(e=new this._clippingContexttConstructor(this,t.getDrawableMasks()[i],t.getDrawableMaskCounts()[i]),this._clippingContextListForMask.pushBack(e)),e.addClippedDrawable(i),this._clippingContextListForDraw.pushBack(e)}}findSameClip(t,e){for(let i=0;i<this._clippingContextListForMask.getSize();i++){const r=this._clippingContextListForMask.at(i),s=r._clippingIdCount;if(s!=e)continue;let a=0;for(let e=0;e<s;e++){const i=r._clippingIdList[e];for(let e=0;e<s;e++)if(t[e]==i){a++;break}}if(a==s)return r}return null}setupMatrixForHighPrecision(t,e){let i=0;for(let r=0;r<this._clippingContextListForMask.getSize();r++){const e=this._clippingContextListForMask.at(r);this.calcClippedDrawTotalBounds(t,e),e._isUsing&&i++}if(i>0){if(this.setupLayoutBounds(0),this._clearedFrameBufferFlags.getSize()!=this._renderTextureCount){this._clearedFrameBufferFlags.clear();for(let t=0;t<this._renderTextureCount;t++)this._clearedFrameBufferFlags.pushBack(!1)}else for(let t=0;t<this._renderTextureCount;t++)this._clearedFrameBufferFlags.set(t,!1);for(let i=0;i<this._clippingContextListForMask.getSize();i++){const r=this._clippingContextListForMask.at(i),s=r._allClippedDrawRect,a=r._layoutBounds,n=.05;let o=0,l=0;const u=t.getPixelsPerUnit(),h=r.getClippingManager().getClippingMaskBufferSize(),d=a.width*h,g=a.height*h;this._tmpBoundsOnModel.setRect(s),this._tmpBoundsOnModel.width*u>d?(this._tmpBoundsOnModel.expand(s.width*n,0),o=a.width/this._tmpBoundsOnModel.width):o=u/d,this._tmpBoundsOnModel.height*u>g?(this._tmpBoundsOnModel.expand(0,s.height*n),l=a.height/this._tmpBoundsOnModel.height):l=u/g,this.createMatrixForMask(e,a,o,l),r._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),r._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray())}}}createMatrixForMask(t,e,i,r){this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(e.x,e.y),this._tmpMatrix.scaleRelative(i,r),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForMask.setMatrix(this._tmpMatrix.getArray()),this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(e.x,e.y*(t?-1:1)),this._tmpMatrix.scaleRelative(i,r*(t?-1:1)),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForDraw.setMatrix(this._tmpMatrix.getArray())}setupLayoutBounds(t){const e=this._renderTextureCount<=1?36:32*this._renderTextureCount;if(t<=0||t>e){t>e&&U("not supported mask count : {0}\n[Details] render texture count : {1}, mask count : {2}",t-e,this._renderTextureCount,t);for(let t=0;t<this._clippingContextListForMask.getSize();t++){const e=this._clippingContextListForMask.at(t);e._layoutChannelIndex=0,e._layoutBounds.x=0,e._layoutBounds.y=0,e._layoutBounds.width=1,e._layoutBounds.height=1,e._bufferIndex=0}return}const i=this._renderTextureCount<=1?9:8;let r=t/this._renderTextureCount;const s=t%this._renderTextureCount;r=Math.ceil(r);let a=r/4;const n=r%4;a=~~a;let o=0;for(let l=0;l<this._renderTextureCount;l++)for(let r=0;r<4;r++){let u=a+(r<n?1:0);if(r==n+(a<1?-1:0)&&s>0&&(u-=l<s?0:1),0==u);else if(1==u){const t=this._clippingContextListForMask.at(o++);t._layoutChannelIndex=r,t._layoutBounds.x=0,t._layoutBounds.y=0,t._layoutBounds.width=1,t._layoutBounds.height=1,t._bufferIndex=l}else if(2==u)for(let t=0;t<u;t++){let e=t%2;e=~~e;const i=this._clippingContextListForMask.at(o++);i._layoutChannelIndex=r,i._layoutBounds.x=.5*e,i._layoutBounds.y=0,i._layoutBounds.width=.5,i._layoutBounds.height=1,i._bufferIndex=l}else if(u<=4)for(let t=0;t<u;t++){let e=t%2,i=t/2;e=~~e,i=~~i;const s=this._clippingContextListForMask.at(o++);s._layoutChannelIndex=r,s._layoutBounds.x=.5*e,s._layoutBounds.y=.5*i,s._layoutBounds.width=.5,s._layoutBounds.height=.5,s._bufferIndex=l}else if(u<=i)for(let t=0;t<u;t++){let e=t%3,i=t/3;e=~~e,i=~~i;const s=this._clippingContextListForMask.at(o++);s._layoutChannelIndex=r,s._layoutBounds.x=e/3,s._layoutBounds.y=i/3,s._layoutBounds.width=1/3,s._layoutBounds.height=1/3,s._bufferIndex=l}else{U("not supported mask count : {0}\n[Details] render texture count : {1}, mask count : {2}",t-e,this._renderTextureCount,t);for(let t=0;t<u;t++){const t=this._clippingContextListForMask.at(o++);t._layoutChannelIndex=0,t._layoutBounds.x=0,t._layoutBounds.y=0,t._layoutBounds.width=1,t._layoutBounds.height=1,t._bufferIndex=0}}}}calcClippedDrawTotalBounds(t,e){let i=Number.MAX_VALUE,r=Number.MAX_VALUE,s=Number.MIN_VALUE,a=Number.MIN_VALUE;const n=e._clippedDrawableIndexList.length;for(let o=0;o<n;o++){const n=e._clippedDrawableIndexList[o],l=t.getDrawableVertexCount(n),u=t.getDrawableVertices(n);let h=Number.MAX_VALUE,d=Number.MAX_VALUE,g=-Number.MAX_VALUE,c=-Number.MAX_VALUE;const m=l*dt.vertexStep;for(let t=dt.vertexOffset;t<m;t+=dt.vertexStep){const e=u[t],i=u[t+1];e<h&&(h=e),e>g&&(g=e),i<d&&(d=i),i>c&&(c=i)}if(h!=Number.MAX_VALUE)if(h<i&&(i=h),d<r&&(r=d),g>s&&(s=g),c>a&&(a=c),i==Number.MAX_VALUE)e._allClippedDrawRect.x=0,e._allClippedDrawRect.y=0,e._allClippedDrawRect.width=0,e._allClippedDrawRect.height=0,e._isUsing=!1;else{e._isUsing=!0;const t=s-i,n=a-r;e._allClippedDrawRect.x=i,e._allClippedDrawRect.y=r,e._allClippedDrawRect.width=t,e._allClippedDrawRect.height=n}}}getClippingContextListForDraw(){return this._clippingContextListForDraw}getClippingMaskBufferSize(){return this._clippingMaskBufferSize}getRenderTextureCount(){return this._renderTextureCount}getChannelFlagAsColor(t){return this._channelColors.at(t)}setClippingMaskBufferSize(t){this._clippingMaskBufferSize=t}}let zi;class ji{constructor(){this._shaderSets=new p}release(){this.releaseShaderProgram()}setupShaderProgramForDraw(t,e,i){let r,s,a,n;t.isPremultipliedAlpha()||U("NoPremultipliedAlpha is not allowed"),0==this._shaderSets.getSize()&&this.generateShaders();const o=null!=t.getClippingContextBufferForDraw(),l=e.getDrawableInvertedMaskBit(i),u=o?l?2:1:0;let h;switch(e.getDrawableBlendMode(i)){case V.CubismBlendMode_Normal:default:h=this._shaderSets.at(1+u),r=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,a=this.gl.ONE,n=this.gl.ONE_MINUS_SRC_ALPHA;break;case V.CubismBlendMode_Additive:h=this._shaderSets.at(4+u),r=this.gl.ONE,s=this.gl.ONE,a=this.gl.ZERO,n=this.gl.ONE;break;case V.CubismBlendMode_Multiplicative:h=this._shaderSets.at(7+u),r=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,a=this.gl.ZERO,n=this.gl.ONE}this.gl.useProgram(h.shaderProgram),null==t._bufferData.vertex&&(t._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.vertex);const d=e.getDrawableVertices(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,d,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(h.attributePositionLocation),this.gl.vertexAttribPointer(h.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),null==t._bufferData.uv&&(t._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.uv);const g=e.getDrawableVertexUvs(i);if(this.gl.bufferData(this.gl.ARRAY_BUFFER,g,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(h.attributeTexCoordLocation),this.gl.vertexAttribPointer(h.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),o){this.gl.activeTexture(this.gl.TEXTURE1);const e=t.getClippingContextBufferForDraw().getClippingManager().getColorBuffer().at(t.getClippingContextBufferForDraw()._bufferIndex);this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(h.samplerTexture1Location,1),this.gl.uniformMatrix4fv(h.uniformClipMatrixLocation,!1,t.getClippingContextBufferForDraw()._matrixForDraw.getArray());const i=t.getClippingContextBufferForDraw()._layoutChannelIndex,r=t.getClippingContextBufferForDraw().getClippingManager().getChannelFlagAsColor(i);this.gl.uniform4f(h.uniformChannelFlagLocation,r.r,r.g,r.b,r.a)}const c=e.getDrawableTextureIndex(i),m=t.getBindedTextures().getValue(c);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,m),this.gl.uniform1i(h.samplerTexture0Location,0);const p=t.getMvpMatrix();this.gl.uniformMatrix4fv(h.uniformMatrixLocation,!1,p.getArray());const _=t.getModelColorWithOpacity(e.getDrawableOpacity(i)),f=e.getMultiplyColor(i),y=e.getScreenColor(i);this.gl.uniform4f(h.uniformBaseColorLocation,_.r,_.g,_.b,_.a),this.gl.uniform4f(h.uniformMultiplyColorLocation,f.r,f.g,f.b,f.a),this.gl.uniform4f(h.uniformScreenColorLocation,y.r,y.g,y.b,y.a),null==t._bufferData.index&&(t._bufferData.index=this.gl.createBuffer());const x=e.getDrawableVertexIndices(i);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t._bufferData.index),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,x,this.gl.DYNAMIC_DRAW),this.gl.blendFuncSeparate(r,s,a,n)}setupShaderProgramForMask(t,e,i){t.isPremultipliedAlpha()||U("NoPremultipliedAlpha is not allowed"),0==this._shaderSets.getSize()&&this.generateShaders();const r=this._shaderSets.at(0);this.gl.useProgram(r.shaderProgram),null==t._bufferData.vertex&&(t._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.vertex);const s=e.getDrawableVertices(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(r.attributePositionLocation),this.gl.vertexAttribPointer(r.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),null==t._bufferData.uv&&(t._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.uv);const a=e.getDrawableTextureIndex(i),n=t.getBindedTextures().getValue(a);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.uniform1i(r.samplerTexture0Location,0),null==t._bufferData.uv&&(t._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.uv);const o=e.getDrawableVertexUvs(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(r.attributeTexCoordLocation),this.gl.vertexAttribPointer(r.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),t.getClippingContextBufferForMask();const l=t.getClippingContextBufferForMask()._layoutChannelIndex,u=t.getClippingContextBufferForMask().getClippingManager().getChannelFlagAsColor(l);this.gl.uniform4f(r.uniformChannelFlagLocation,u.r,u.g,u.b,u.a),this.gl.uniformMatrix4fv(r.uniformClipMatrixLocation,!1,t.getClippingContextBufferForMask()._matrixForMask.getArray());const h=t.getClippingContextBufferForMask()._layoutBounds;this.gl.uniform4f(r.uniformBaseColorLocation,2*h.x-1,2*h.y-1,2*h.getRight()-1,2*h.getBottom()-1);const d=e.getMultiplyColor(i),g=e.getScreenColor(i);this.gl.uniform4f(r.uniformMultiplyColorLocation,d.r,d.g,d.b,d.a),this.gl.uniform4f(r.uniformScreenColorLocation,g.r,g.g,g.b,g.a);const c=this.gl.ZERO,m=this.gl.ONE_MINUS_SRC_COLOR,p=this.gl.ZERO,_=this.gl.ONE_MINUS_SRC_ALPHA;null==t._bufferData.index&&(t._bufferData.index=this.gl.createBuffer());const f=e.getDrawableVertexIndices(i);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t._bufferData.index),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,f,this.gl.DYNAMIC_DRAW),this.gl.blendFuncSeparate(c,m,p,_)}releaseShaderProgram(){for(let t=0;t<this._shaderSets.getSize();t++)this.gl.deleteProgram(this._shaderSets.at(t).shaderProgram),this._shaderSets.at(t).shaderProgram=0,this._shaderSets.set(t,void 0),this._shaderSets.set(t,null)}generateShaders(){for(let t=0;t<10;t++)this._shaderSets.pushBack(new Xi);this._shaderSets.at(0).shaderProgram=this.loadShaderProgram(qi,Yi),this._shaderSets.at(1).shaderProgram=this.loadShaderProgram(Wi,$i),this._shaderSets.at(2).shaderProgram=this.loadShaderProgram(Ji,Zi),this._shaderSets.at(3).shaderProgram=this.loadShaderProgram(Ji,Ki),this._shaderSets.at(4).shaderProgram=this._shaderSets.at(1).shaderProgram,this._shaderSets.at(5).shaderProgram=this._shaderSets.at(2).shaderProgram,this._shaderSets.at(6).shaderProgram=this._shaderSets.at(3).shaderProgram,this._shaderSets.at(7).shaderProgram=this._shaderSets.at(1).shaderProgram,this._shaderSets.at(8).shaderProgram=this._shaderSets.at(2).shaderProgram,this._shaderSets.at(9).shaderProgram=this._shaderSets.at(3).shaderProgram,this._shaderSets.at(0).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(0).shaderProgram,"a_position"),this._shaderSets.at(0).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(0).shaderProgram,"a_texCoord"),this._shaderSets.at(0).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"s_texture0"),this._shaderSets.at(0).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_clipMatrix"),this._shaderSets.at(0).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_channelFlag"),this._shaderSets.at(0).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_baseColor"),this._shaderSets.at(0).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_multiplyColor"),this._shaderSets.at(0).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(0).shaderProgram,"u_screenColor"),this._shaderSets.at(1).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(1).shaderProgram,"a_position"),this._shaderSets.at(1).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(1).shaderProgram,"a_texCoord"),this._shaderSets.at(1).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"s_texture0"),this._shaderSets.at(1).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_matrix"),this._shaderSets.at(1).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_baseColor"),this._shaderSets.at(1).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_multiplyColor"),this._shaderSets.at(1).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(1).shaderProgram,"u_screenColor"),this._shaderSets.at(2).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(2).shaderProgram,"a_position"),this._shaderSets.at(2).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(2).shaderProgram,"a_texCoord"),this._shaderSets.at(2).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"s_texture0"),this._shaderSets.at(2).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"s_texture1"),this._shaderSets.at(2).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_matrix"),this._shaderSets.at(2).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_clipMatrix"),this._shaderSets.at(2).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_channelFlag"),this._shaderSets.at(2).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_baseColor"),this._shaderSets.at(2).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_multiplyColor"),this._shaderSets.at(2).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(2).shaderProgram,"u_screenColor"),this._shaderSets.at(3).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(3).shaderProgram,"a_position"),this._shaderSets.at(3).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(3).shaderProgram,"a_texCoord"),this._shaderSets.at(3).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"s_texture0"),this._shaderSets.at(3).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"s_texture1"),this._shaderSets.at(3).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_matrix"),this._shaderSets.at(3).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_clipMatrix"),this._shaderSets.at(3).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_channelFlag"),this._shaderSets.at(3).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_baseColor"),this._shaderSets.at(3).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_multiplyColor"),this._shaderSets.at(3).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(3).shaderProgram,"u_screenColor"),this._shaderSets.at(4).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(4).shaderProgram,"a_position"),this._shaderSets.at(4).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(4).shaderProgram,"a_texCoord"),this._shaderSets.at(4).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"s_texture0"),this._shaderSets.at(4).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_matrix"),this._shaderSets.at(4).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_baseColor"),this._shaderSets.at(4).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_multiplyColor"),this._shaderSets.at(4).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(4).shaderProgram,"u_screenColor"),this._shaderSets.at(5).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(5).shaderProgram,"a_position"),this._shaderSets.at(5).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(5).shaderProgram,"a_texCoord"),this._shaderSets.at(5).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"s_texture0"),this._shaderSets.at(5).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"s_texture1"),this._shaderSets.at(5).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_matrix"),this._shaderSets.at(5).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_clipMatrix"),this._shaderSets.at(5).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_channelFlag"),this._shaderSets.at(5).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_baseColor"),this._shaderSets.at(5).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_multiplyColor"),this._shaderSets.at(5).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(5).shaderProgram,"u_screenColor"),this._shaderSets.at(6).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(6).shaderProgram,"a_position"),this._shaderSets.at(6).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(6).shaderProgram,"a_texCoord"),this._shaderSets.at(6).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"s_texture0"),this._shaderSets.at(6).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"s_texture1"),this._shaderSets.at(6).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_matrix"),this._shaderSets.at(6).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_clipMatrix"),this._shaderSets.at(6).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_channelFlag"),this._shaderSets.at(6).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_baseColor"),this._shaderSets.at(6).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_multiplyColor"),this._shaderSets.at(6).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(6).shaderProgram,"u_screenColor"),this._shaderSets.at(7).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(7).shaderProgram,"a_position"),this._shaderSets.at(7).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(7).shaderProgram,"a_texCoord"),this._shaderSets.at(7).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"s_texture0"),this._shaderSets.at(7).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_matrix"),this._shaderSets.at(7).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_baseColor"),this._shaderSets.at(7).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_multiplyColor"),this._shaderSets.at(7).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(7).shaderProgram,"u_screenColor"),this._shaderSets.at(8).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(8).shaderProgram,"a_position"),this._shaderSets.at(8).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(8).shaderProgram,"a_texCoord"),this._shaderSets.at(8).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"s_texture0"),this._shaderSets.at(8).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"s_texture1"),this._shaderSets.at(8).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_matrix"),this._shaderSets.at(8).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_clipMatrix"),this._shaderSets.at(8).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_channelFlag"),this._shaderSets.at(8).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_baseColor"),this._shaderSets.at(8).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_multiplyColor"),this._shaderSets.at(8).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(8).shaderProgram,"u_screenColor"),this._shaderSets.at(9).attributePositionLocation=this.gl.getAttribLocation(this._shaderSets.at(9).shaderProgram,"a_position"),this._shaderSets.at(9).attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets.at(9).shaderProgram,"a_texCoord"),this._shaderSets.at(9).samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"s_texture0"),this._shaderSets.at(9).samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"s_texture1"),this._shaderSets.at(9).uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_matrix"),this._shaderSets.at(9).uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_clipMatrix"),this._shaderSets.at(9).uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_channelFlag"),this._shaderSets.at(9).uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_baseColor"),this._shaderSets.at(9).uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_multiplyColor"),this._shaderSets.at(9).uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets.at(9).shaderProgram,"u_screenColor")}loadShaderProgram(t,e){let i=this.gl.createProgram(),r=this.compileShaderSource(this.gl.VERTEX_SHADER,t);if(!r)return U("Vertex shader compile error!"),0;let s=this.compileShaderSource(this.gl.FRAGMENT_SHADER,e);if(!s)return U("Vertex shader compile error!"),0;this.gl.attachShader(i,r),this.gl.attachShader(i,s),this.gl.linkProgram(i);return this.gl.getProgramParameter(i,this.gl.LINK_STATUS)?(this.gl.deleteShader(r),this.gl.deleteShader(s),i):(U("Failed to link program: {0}",i),this.gl.deleteShader(r),r=0,this.gl.deleteShader(s),s=0,i&&(this.gl.deleteProgram(i),i=0),0)}compileShaderSource(t,e){const i=e,r=this.gl.createShader(t);if(this.gl.shaderSource(r,i),this.gl.compileShader(r),!r){const t=this.gl.getShaderInfoLog(r);U("Shader compile log: {0} ",t)}return this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS)?r:(this.gl.deleteShader(r),null)}setGl(t){this.gl=t}}class Gi{static getInstance(){return null==zi&&(zi=new Gi),zi}static deleteInstance(){zi&&(zi.release(),zi=null)}constructor(){this._shaderMap=new H}release(){for(const t=this._shaderMap.begin();t.notEqual(this._shaderMap.end());t.preIncrement())t.ptr().second.release();this._shaderMap.clear()}getShader(t){return this._shaderMap.getValue(t)}setGlContext(t){if(!this._shaderMap.isExist(t)){const e=new ji;e.setGl(t),this._shaderMap.setValue(t,e)}}}class Xi{}var Hi=(t=>(t[t.ShaderNames_SetupMask=0]="ShaderNames_SetupMask",t[t.ShaderNames_NormalPremultipliedAlpha=1]="ShaderNames_NormalPremultipliedAlpha",t[t.ShaderNames_NormalMaskedPremultipliedAlpha=2]="ShaderNames_NormalMaskedPremultipliedAlpha",t[t.ShaderNames_NomralMaskedInvertedPremultipliedAlpha=3]="ShaderNames_NomralMaskedInvertedPremultipliedAlpha",t[t.ShaderNames_AddPremultipliedAlpha=4]="ShaderNames_AddPremultipliedAlpha",t[t.ShaderNames_AddMaskedPremultipliedAlpha=5]="ShaderNames_AddMaskedPremultipliedAlpha",t[t.ShaderNames_AddMaskedPremultipliedAlphaInverted=6]="ShaderNames_AddMaskedPremultipliedAlphaInverted",t[t.ShaderNames_MultPremultipliedAlpha=7]="ShaderNames_MultPremultipliedAlpha",t[t.ShaderNames_MultMaskedPremultipliedAlpha=8]="ShaderNames_MultMaskedPremultipliedAlpha",t[t.ShaderNames_MultMaskedPremultipliedAlphaInverted=9]="ShaderNames_MultMaskedPremultipliedAlphaInverted",t))(Hi||{});const qi="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;varying vec4 v_myPos;uniform mat4 u_clipMatrix;void main(){ gl_Position = u_clipMatrix * a_position; v_myPos = u_clipMatrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",Yi="precision mediump float;varying vec2 v_texCoord;varying vec4 v_myPos;uniform vec4 u_baseColor;uniform vec4 u_channelFlag;uniform sampler2D s_texture0;void main(){ float isInside = step(u_baseColor.x, v_myPos.x/v_myPos.w) * step(u_baseColor.y, v_myPos.y/v_myPos.w) * step(v_myPos.x/v_myPos.w, u_baseColor.z) * step(v_myPos.y/v_myPos.w, u_baseColor.w); gl_FragColor = u_channelFlag * texture2D(s_texture0, v_texCoord).a * isInside;}",Wi="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;uniform mat4 u_matrix;void main(){ gl_Position = u_matrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",Ji="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform mat4 u_matrix;uniform mat4 u_clipMatrix;void main(){ gl_Position = u_matrix * a_position; v_clipPos = u_clipMatrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",$i="precision mediump float;varying vec2 v_texCoord;uniform vec4 u_baseColor;uniform sampler2D s_texture0;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 color = texColor * u_baseColor; gl_FragColor = vec4(color.rgb, color.a);}",Zi="precision mediump float;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform vec4 u_baseColor;uniform vec4 u_channelFlag;uniform sampler2D s_texture0;uniform sampler2D s_texture1;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 col_formask = texColor * u_baseColor; vec4 clipMask = (1.0 - texture2D(s_texture1, v_clipPos.xy / v_clipPos.w)) * u_channelFlag; float maskVal = clipMask.r + clipMask.g + clipMask.b + clipMask.a; col_formask = col_formask * maskVal; gl_FragColor = col_formask;}",Ki="precision mediump float;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform sampler2D s_texture0;uniform sampler2D s_texture1;uniform vec4 u_channelFlag;uniform vec4 u_baseColor;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 col_formask = texColor * u_baseColor; vec4 clipMask = (1.0 - texture2D(s_texture1, v_clipPos.xy / v_clipPos.w)) * u_channelFlag; float maskVal = clipMask.r + clipMask.g + clipMask.b + clipMask.a; col_formask = col_formask * (1.0 - maskVal); gl_FragColor = col_formask;}";var Qi;let tr,er;(t=>{t.CubismShaderSet=Xi,t.CubismShader_WebGL=ji,t.CubismShaderManager_WebGL=Gi,t.ShaderNames=Hi})(Qi||(Qi={}));class ir extends Ui{getMaskRenderTexture(){if(this._maskTexture&&null!=this._maskTexture.textures)this._maskTexture.frameNo=this._currentFrameNo;else{null!=this._maskRenderTextures&&this._maskRenderTextures.clear(),this._maskRenderTextures=new p,null!=this._maskColorBuffers&&this._maskColorBuffers.clear(),this._maskColorBuffers=new p;const t=this._clippingMaskBufferSize;for(let e=0;e<this._renderTextureCount;e++)this._maskColorBuffers.pushBack(this.gl.createTexture()),this.gl.bindTexture(this.gl.TEXTURE_2D,this._maskColorBuffers.at(e)),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,t,t,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this._maskRenderTextures.pushBack(this.gl.createFramebuffer()),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._maskRenderTextures.at(e)),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this._maskColorBuffers.at(e),0);this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,er),this._maskTexture=new rr(this._currentFrameNo,this._maskRenderTextures)}return this._maskTexture.textures}setGL(t){this.gl=t}constructor(){super(sr)}setupClippingContext(t,e){this._currentFrameNo++;let i=0;for(let r=0;r<this._clippingContextListForMask.getSize();r++){const e=this._clippingContextListForMask.at(r);this.calcClippedDrawTotalBounds(t,e),e._isUsing&&i++}if(i>0){this.gl.viewport(0,0,this._clippingMaskBufferSize,this._clippingMaskBufferSize),this._currentMaskRenderTexture=this.getMaskRenderTexture().at(0),e.preDraw(),this.setupLayoutBounds(i),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentMaskRenderTexture),this._clearedFrameBufferFlags.getSize()!=this._renderTextureCount&&(this._clearedFrameBufferFlags.clear(),this._clearedFrameBufferFlags=new p(this._renderTextureCount));for(let t=0;t<this._clearedFrameBufferFlags.getSize();t++)this._clearedFrameBufferFlags.set(t,!1);for(let i=0;i<this._clippingContextListForMask.getSize();i++){const r=this._clippingContextListForMask.at(i),s=r._allClippedDrawRect,a=r._layoutBounds,n=.05;let o=0,l=0;const u=this.getMaskRenderTexture().at(r._bufferIndex);this._currentMaskRenderTexture!=u&&(this._currentMaskRenderTexture=u,e.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentMaskRenderTexture)),this._tmpBoundsOnModel.setRect(s),this._tmpBoundsOnModel.expand(s.width*n,s.height*n),o=a.width/this._tmpBoundsOnModel.width,l=a.height/this._tmpBoundsOnModel.height,this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(a.x,a.y),this._tmpMatrix.scaleRelative(o,l),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForMask.setMatrix(this._tmpMatrix.getArray()),this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(a.x,a.y),this._tmpMatrix.scaleRelative(o,l),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForDraw.setMatrix(this._tmpMatrix.getArray()),r._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),r._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray());const h=r._clippingIdCount;for(let i=0;i<h;i++){const s=r._clippingIdList[i];t.getDrawableDynamicFlagVertexPositionsDidChange(s)&&(e.setIsCulling(0!=t.getDrawableCulling(s)),this._clearedFrameBufferFlags.at(r._bufferIndex)||(this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this._clearedFrameBufferFlags.set(r._bufferIndex,!0)),e.setClippingContextBufferForMask(r),e.drawMeshWebGL(t,s))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,er),e.setClippingContextBufferForMask(null),this.gl.viewport(tr[0],tr[1],tr[2],tr[3])}}getColorBuffer(){return this._maskColorBuffers}getClippingMaskCount(){return this._clippingContextListForMask.getSize()}}class rr{constructor(t,e){this.frameNo=t,this.textures=e}}class sr extends R{constructor(t,e,i){super(e,i),this._owner=t}getClippingManager(){return this._owner}setGl(t){this._owner.setGL(t)}}class ar{setGlEnable(t,e){e?this.gl.enable(t):this.gl.disable(t)}setGlEnableVertexAttribArray(t,e){e?this.gl.enableVertexAttribArray(t):this.gl.disableVertexAttribArray(t)}save(){null!=this.gl?(this._lastArrayBufferBinding=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING),this._lastElementArrayBufferBinding=this.gl.getParameter(this.gl.ELEMENT_ARRAY_BUFFER_BINDING),this._lastProgram=this.gl.getParameter(this.gl.CURRENT_PROGRAM),this._lastActiveTexture=this.gl.getParameter(this.gl.ACTIVE_TEXTURE),this.gl.activeTexture(this.gl.TEXTURE1),this._lastTexture1Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this.gl.activeTexture(this.gl.TEXTURE0),this._lastTexture0Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this._lastVertexAttribArrayEnabled[0]=this.gl.getVertexAttrib(0,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[1]=this.gl.getVertexAttrib(1,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[2]=this.gl.getVertexAttrib(2,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[3]=this.gl.getVertexAttrib(3,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastScissorTest=this.gl.isEnabled(this.gl.SCISSOR_TEST),this._lastStencilTest=this.gl.isEnabled(this.gl.STENCIL_TEST),this._lastDepthTest=this.gl.isEnabled(this.gl.DEPTH_TEST),this._lastCullFace=this.gl.isEnabled(this.gl.CULL_FACE),this._lastBlend=this.gl.isEnabled(this.gl.BLEND),this._lastFrontFace=this.gl.getParameter(this.gl.FRONT_FACE),this._lastColorMask=this.gl.getParameter(this.gl.COLOR_WRITEMASK),this._lastBlending[0]=this.gl.getParameter(this.gl.BLEND_SRC_RGB),this._lastBlending[1]=this.gl.getParameter(this.gl.BLEND_DST_RGB),this._lastBlending[2]=this.gl.getParameter(this.gl.BLEND_SRC_ALPHA),this._lastBlending[3]=this.gl.getParameter(this.gl.BLEND_DST_ALPHA),this._lastFBO=this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING),this._lastViewport=this.gl.getParameter(this.gl.VIEWPORT)):U("'gl' is null. WebGLRenderingContext is required.\nPlease call 'CubimRenderer_WebGL.startUp' function.")}restore(){null!=this.gl?(this.gl.useProgram(this._lastProgram),this.setGlEnableVertexAttribArray(0,this._lastVertexAttribArrayEnabled[0]),this.setGlEnableVertexAttribArray(1,this._lastVertexAttribArrayEnabled[1]),this.setGlEnableVertexAttribArray(2,this._lastVertexAttribArrayEnabled[2]),this.setGlEnableVertexAttribArray(3,this._lastVertexAttribArrayEnabled[3]),this.setGlEnable(this.gl.SCISSOR_TEST,this._lastScissorTest),this.setGlEnable(this.gl.STENCIL_TEST,this._lastStencilTest),this.setGlEnable(this.gl.DEPTH_TEST,this._lastDepthTest),this.setGlEnable(this.gl.CULL_FACE,this._lastCullFace),this.setGlEnable(this.gl.BLEND,this._lastBlend),this.gl.frontFace(this._lastFrontFace),this.gl.colorMask(this._lastColorMask[0],this._lastColorMask[1],this._lastColorMask[2],this._lastColorMask[3]),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._lastArrayBufferBinding),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._lastElementArrayBufferBinding),this.gl.activeTexture(this.gl.TEXTURE1),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture1Binding2D),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture0Binding2D),this.gl.activeTexture(this._lastActiveTexture),this.gl.blendFuncSeparate(this._lastBlending[0],this._lastBlending[1],this._lastBlending[2],this._lastBlending[3])):U("'gl' is null. WebGLRenderingContext is required.\nPlease call 'CubimRenderer_WebGL.startUp' function.")}setGl(t){this.gl=t}constructor(){this._lastVertexAttribArrayEnabled=new Array(4),this._lastColorMask=new Array(4),this._lastBlending=new Array(4),this._lastViewport=new Array(4)}}class nr extends I{initialize(t,e=1){t.isUsingMasking()&&(this._clippingManager=new ir,this._clippingManager.initialize(t,e)),this._sortedDrawableIndexList.resize(t.getDrawableCount(),0),super.initialize(t)}bindTexture(t,e){this._textures.setValue(t,e)}getBindedTextures(){return this._textures}setClippingMaskBufferSize(t){if(!this._model.isUsingMasking())return;const e=this._clippingManager.getRenderTextureCount();this._clippingManager.release(),this._clippingManager=void 0,this._clippingManager=null,this._clippingManager=new ir,this._clippingManager.setClippingMaskBufferSize(t),this._clippingManager.initialize(this.getModel(),e)}getClippingMaskBufferSize(){return this._model.isUsingMasking()?this._clippingManager.getClippingMaskBufferSize():-1}getRenderTextureCount(){return this._model.isUsingMasking()?this._clippingManager.getRenderTextureCount():-1}constructor(){super(),this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._rendererProfile=new ar,this.firstDraw=!0,this._textures=new H,this._sortedDrawableIndexList=new p,this._bufferData={vertex:WebGLBuffer=null,uv:WebGLBuffer=null,index:WebGLBuffer=null},this._textures.prepareCapacity(32,!0)}release(){this._clippingManager&&(this._clippingManager.release(),this._clippingManager=void 0,this._clippingManager=null),null!=this.gl&&(this.gl.deleteBuffer(this._bufferData.vertex),this._bufferData.vertex=null,this.gl.deleteBuffer(this._bufferData.uv),this._bufferData.uv=null,this.gl.deleteBuffer(this._bufferData.index),this._bufferData.index=null,this._bufferData=null,this._textures=null)}doDrawModel(){if(null==this.gl)return void U("'gl' is null. WebGLRenderingContext is required.\nPlease call 'CubimRenderer_WebGL.startUp' function.");null!=this._clippingManager&&(this.preDraw(),this.isUsingHighPrecisionMask()?this._clippingManager.setupMatrixForHighPrecision(this.getModel(),!1):this._clippingManager.setupClippingContext(this.getModel(),this)),this.preDraw();const t=this.getModel().getDrawableCount(),e=this.getModel().getDrawableRenderOrders();for(let i=0;i<t;++i){const t=e[i];this._sortedDrawableIndexList.set(t,i)}for(let i=0;i<t;++i){const t=this._sortedDrawableIndexList.at(i);if(!this.getModel().getDrawableDynamicFlagIsVisible(t))continue;const e=null!=this._clippingManager?this._clippingManager.getClippingContextListForDraw().at(t):null;if(null!=e&&this.isUsingHighPrecisionMask()){e._isUsing&&(this.gl.viewport(0,0,this._clippingManager.getClippingMaskBufferSize(),this._clippingManager.getClippingMaskBufferSize()),this.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e.getClippingManager().getMaskRenderTexture().at(e._bufferIndex)),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{const t=e._clippingIdCount;for(let i=0;i<t;i++){const t=e._clippingIdList[i];this._model.getDrawableDynamicFlagVertexPositionsDidChange(t)&&(this.setIsCulling(0!=this._model.getDrawableCulling(t)),this.setClippingContextBufferForMask(e),this.drawMeshWebGL(this._model,t))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,er),this.setClippingContextBufferForMask(null),this.gl.viewport(tr[0],tr[1],tr[2],tr[3]),this.preDraw()}this.setClippingContextBufferForDraw(e),this.setIsCulling(this.getModel().getDrawableCulling(t)),this.drawMeshWebGL(this._model,t)}}drawMeshWebGL(t,e){this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW),this.isGeneratingMask()?Gi.getInstance().getShader(this.gl).setupShaderProgramForMask(this,t,e):Gi.getInstance().getShader(this.gl).setupShaderProgramForDraw(this,t,e);{const i=t.getDrawableVertexIndexCount(e);this.gl.drawElements(this.gl.TRIANGLES,i,this.gl.UNSIGNED_SHORT,0)}this.gl.useProgram(null),this.setClippingContextBufferForDraw(null),this.setClippingContextBufferForMask(null)}saveProfile(){this._rendererProfile.save()}restoreProfile(){this._rendererProfile.restore()}static doStaticRelease(){Gi.deleteInstance()}setRenderState(t,e){er=t,tr=e}preDraw(){if(this.firstDraw&&(this.firstDraw=!1),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.disable(this.gl.STENCIL_TEST),this.gl.disable(this.gl.DEPTH_TEST),this.gl.frontFace(this.gl.CW),this.gl.enable(this.gl.BLEND),this.gl.colorMask(!0,!0,!0,!0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.getAnisotropy()>0&&this._extension)for(let t=0;t<this._textures.getSize();++t)this.gl.bindTexture(this.gl.TEXTURE_2D,this._textures.getValue(t)),this.gl.texParameterf(this.gl.TEXTURE_2D,this._extension.TEXTURE_MAX_ANISOTROPY_EXT,this.getAnisotropy())}setClippingContextBufferForMask(t){this._clippingContextBufferForMask=t}getClippingContextBufferForMask(){return this._clippingContextBufferForMask}setClippingContextBufferForDraw(t){this._clippingContextBufferForDraw=t}getClippingContextBufferForDraw(){return this._clippingContextBufferForDraw}isGeneratingMask(){return null!=this.getClippingContextBufferForMask()}startUp(t){this.gl=t,this._clippingManager&&this._clippingManager.setGL(t),Gi.getInstance().setGlContext(t),this._rendererProfile.setGl(t),this._extension=this.gl.getExtension("EXT_texture_filter_anisotropic")||this.gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this.gl.getExtension("MOZ_EXT_texture_filter_anisotropic")}}var or;I.staticRelease=()=>{nr.doStaticRelease()},(t=>{t.CubismClippingContext=sr,t.CubismClippingManager_WebGL=ir,t.CubismRenderTextureResource=rr,t.CubismRenderer_WebGL=nr})(or||(or={}));const lr=new w;function ur(t){if(!t.isUsingMasking())return!1;const e=function(t){var e,i;const r=t.getDrawableMaskCounts(),s=t.getDrawableMasks(),a=new Set,n=t.getDrawableCount();let o=0,l=0,u=0,h=0;for(let d=0;d<n;d++){const n=t.getDrawableVertexCount(d),g=null!=(e=r[d])?e:0;if(h+=n,g<=0)continue;o++,u+=n,l=Math.max(l,g);const c=Array.from(null!=(i=s[d])?i:[]).slice(0,g).sort((t,e)=>t-e).join(",");a.add(c)}return{maskedDrawableCount:o,uniqueMaskSetCount:a.size,maxMasksPerDrawable:l,maskedVertexCount:u,totalVertexCount:h}}(t),i=e.totalVertexCount>0?e.maskedVertexCount/e.totalVertexCount:0;return e.uniqueMaskSetCount>16||e.maskedDrawableCount>64||e.maxMasksPerDrawable>=3||e.maskedVertexCount>4096||i>=.5&&e.maskedDrawableCount>24}class hr extends Ut{constructor(t,i,r){super(),g(this,"settings"),g(this,"options"),g(this,"coreModel"),g(this,"motionManager"),g(this,"parallelMotionManager"),g(this,"lipSync",!0),g(this,"breath",Ti.create()),g(this,"eyeBlink"),g(this,"renderer",new nr),g(this,"idManager"),g(this,"idParamAngleX"),g(this,"idParamAngleY"),g(this,"idParamAngleZ"),g(this,"idParamEyeBallX"),g(this,"idParamEyeBallY"),g(this,"idParamBodyAngleX"),g(this,"idParamBreath"),g(this,"idParamMouthForm"),g(this,"pixelsPerUnit",1),g(this,"modelTransform",new e.Matrix),this.coreModel=t,this.settings=i,this.options=Object.assign({},{breathDepth:1,lipSyncGain:1.5,lipSyncWeight:.4},r),this.idManager=ct.getIdManager(),this.idParamAngleX=this.getIdSafe(Vi.ParamAngleX),this.idParamAngleY=this.getIdSafe(Vi.ParamAngleY),this.idParamAngleZ=this.getIdSafe(Vi.ParamAngleZ),this.idParamEyeBallX=this.getIdSafe(Vi.ParamEyeBallX),this.idParamEyeBallY=this.getIdSafe(Vi.ParamEyeBallY),this.idParamBodyAngleX=this.getIdSafe(Vi.ParamBodyAngleX),this.idParamBreath=this.getIdSafe(Vi.ParamBreath),this.idParamMouthForm=this.getIdSafe(Vi.ParamMouthForm),this.motionManager=new yi(this),this.parallelMotionManager=[],this.init()}init(){var t;super.init();const e=this.settings.getEyeBlinkParameters();if(e.length){const i=new p;for(const t of e)i.pushBack(this.idManager.getId(t));const r=Oi.create();null==(t=r.setParameterIds)||t.call(r,i),this.eyeBlink=r}const i=new p;var r,s;i.pushBack(new Di(this.idParamAngleX,0,15*this.options.breathDepth,6.5345,.5)),i.pushBack(new Di(this.idParamAngleY,0,8*this.options.breathDepth,3.5345,.5)),i.pushBack(new Di(this.idParamAngleZ,0,10*this.options.breathDepth,5.5345,.5)),i.pushBack(new Di(this.idParamBodyAngleX,0,4*this.options.breathDepth,15.5345,.5)),i.pushBack(new Di(this.idParamBreath,0,.5,3.2345,.5)),this.breath.setParameters(i),this.renderer.initialize(this.coreModel,function(t){var e;if(!t.isUsingMasking())return 1;const i=t.getDrawableMaskCounts(),r=t.getDrawableMasks(),s=new Set;for(let n=0;n<t.getDrawableCount();n++){const t=i[n];if(!t||t<=0)continue;const a=Array.from(null!=(e=r[n])?e:[]).slice(0,t).sort((t,e)=>t-e).join(",");s.add(a)}const a=s.size;return a<=36?1:Math.ceil(a/32)}(this.coreModel)),this.renderer.useHighPrecisionMask((r=this.coreModel,"boolean"==typeof(s=this.options.useHighPrecisionMask)?s:ur(r))),this.renderer.setIsPremultipliedAlpha(!0)}getIdSafe(t){return this.idManager.getId(null!=t?t:"")}getSize(){return[this.coreModel.getModel().canvasinfo.CanvasWidth,this.coreModel.getModel().canvasinfo.CanvasHeight]}getLayout(){const t={},e=this.settings.layout;if(e)for(const[i,r]of Object.entries(e)){t[i.charAt(0).toLowerCase()+i.slice(1)]=r}return t}setupLayout(){super.setupLayout(),this.pixelsPerUnit=this.coreModel.getModel().canvasinfo.PixelsPerUnit,this.modelTransform.scale(this.pixelsPerUnit,this.pixelsPerUnit).translate(this.originalWidth/2,this.originalHeight/2)}updateWebGLContext(t,e){this.renderer.firstDraw=!0,this.renderer._bufferData={vertex:null,uv:null,index:null},this.renderer.startUp(t),this.renderer._clippingManager&&(this.renderer._clippingManager._currentFrameNo=e),Gi.getInstance().setGlContext(t)}bindTexture(t,e){this.renderer.bindTexture(t,e)}getHitAreaDefs(){var t,e,i;const r=this.settings.json;return kt(null!=(i=null!=(e=null!=(t=this.settings.hitAreas)?t:r.HitAreas)?e:r.hitAreas)?i:r.hit_areas,t=>this.coreModel.getDrawableIndex(this.idManager.getId(t)))}getDrawableIDs(){const t=this.coreModel.getDrawableCount(),e=[];for(let i=0;i<t;i++)e.push(this.coreModel.getDrawableId(i).getString().s);return e}getDrawableIndex(t){return this.coreModel.getDrawableIndex(this.idManager.getId(t))}getDrawableVertices(t){if("string"==typeof t){const e=t;if(-1===(t=this.getDrawableIndex(e)))throw new TypeError("Unable to find drawable ID: "+e)}const e=this.coreModel.getDrawableVertices(t).slice();for(let i=0;i<e.length;i+=2)e[i]=e[i]*this.pixelsPerUnit+this.originalWidth/2,e[i+1]=-e[i+1]*this.pixelsPerUnit+this.originalHeight/2;return e}updateTransform(t){this.drawingMatrix.copyFrom(this.modelTransform).prepend(this.localTransform).prepend(t)}update(t,e){var i,r,s,a,n;super.update(t,e),t/=1e3,e/=1e3;const o=this.coreModel,l=this.updateMotions(o,e);if(o.saveParameters(),null==(i=this.motionManager.expressionManager)||i.update(o,e),l||null==(s=null==(r=this.eyeBlink)?void 0:r.updateParameters)||s.call(r,o,t),this.updateFocus(),this.updateNaturalMovements(1e3*t,1e3*e),this.lipSync&&this.motionManager.currentAudio){let t=this.motionManager.mouthSync()*this.options.lipSyncGain;t=Math.pow(t,1.15);t=ft(t,t>0?.1:0,1),this.motionManager.lipSyncIds.forEach(e=>{o.addParameterValueById(this.getIdSafe(e),t,this.options.lipSyncWeight)})}null==(a=this.physics)||a.evaluate(o,t),null==(n=this.pose)||n.updateParameters(o,t),this.emit("beforeModelUpdate"),o.update(),o.loadParameters()}updateFocus(){this.coreModel.addParameterValueById(this.idParamEyeBallX,this.focusController.x),this.coreModel.addParameterValueById(this.idParamEyeBallY,this.focusController.y),this.coreModel.addParameterValueById(this.idParamAngleX,30*this.focusController.x),this.coreModel.addParameterValueById(this.idParamAngleY,30*this.focusController.y),this.coreModel.addParameterValueById(this.idParamAngleZ,this.focusController.x*this.focusController.y*-30),this.coreModel.addParameterValueById(this.idParamBodyAngleX,10*this.focusController.x)}updateFacialEmotion(t){this.coreModel.addParameterValueById(this.idParamMouthForm,t)}updateNaturalMovements(t,e){var i;null==(i=this.breath)||i.updateParameters(this.coreModel,t/1e3)}draw(t){const e=this.drawingMatrix,i=lr.getArray();i[0]=e.a,i[1]=e.b,i[4]=-e.c,i[5]=-e.d,i[12]=e.tx,i[13]=e.ty,this.renderer.setMvpMatrix(lr);const r=t.getParameter(t.FRAMEBUFFER_BINDING);this.renderer.setRenderState(r,this.viewport),this.renderer.drawModel()}extendParallelMotionManager(t){for(;this.parallelMotionManager.length<t;)this.parallelMotionManager.push(new Pi(this))}destroy(){super.destroy(),this.renderer.release(),this.coreModel.release(),this.renderer=void 0,this.coreModel=void 0}}class dr{}var gr;(t=>{t.ICubismModelSetting=dr})(gr||(gr={}));var cr,mr=(t=>(t[t.FrequestNode_Groups=0]="FrequestNode_Groups",t[t.FrequestNode_Moc=1]="FrequestNode_Moc",t[t.FrequestNode_Motions=2]="FrequestNode_Motions",t[t.FrequestNode_Expressions=3]="FrequestNode_Expressions",t[t.FrequestNode_Textures=4]="FrequestNode_Textures",t[t.FrequestNode_Physics=5]="FrequestNode_Physics",t[t.FrequestNode_Pose=6]="FrequestNode_Pose",t[t.FrequestNode_HitAreas=7]="FrequestNode_HitAreas",t))(mr||{});class pr extends dr{constructor(t,e){super(),this.version="Version",this.fileReferences="FileReferences",this.groups="Groups",this.layout="Layout",this.hitAreas="HitAreas",this.moc="Moc",this.textures="Textures",this.physics="Physics",this.pose="Pose",this.expressions="Expressions",this.motions="Motions",this.userData="UserData",this.name="Name",this.filePath="File",this.id="Id",this.ids="Ids",this.target="Target",this.idle="Idle",this.tapBody="TapBody",this.pinchIn="PinchIn",this.pinchOut="PinchOut",this.shake="Shake",this.flickHead="FlickHead",this.parameter="Parameter",this.soundPath="Sound",this.fadeInTime="FadeInTime",this.fadeOutTime="FadeOutTime",this.centerX="CenterX",this.centerY="CenterY",this.x="X",this.y="Y",this.width="Width",this.height="Height",this.lipSync="LipSync",this.eyeBlink="EyeBlink",this.initParameter="init_param",this.initPartsVisible="init_parts_visible",this.val="val",this._json=Z.create(t,e),this.getJson()&&(this._jsonValue=new p,this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.groups)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.moc)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.motions)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.expressions)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.textures)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.physics)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.pose)),this._jsonValue.pushBack(this.getJson().getRoot().getValueByString(this.hitAreas)))}release(){Z.delete(this._json),this._jsonValue=null}getJson(){return this._json}getModelFileName(){return this.isExistModelFile()?this._jsonValue.at(1).getRawString():""}getTextureCount(){return this.isExistTextureFiles()?this._jsonValue.at(4).getSize():0}getTextureDirectory(){const t=this._jsonValue.at(4).getValueByIndex(0).getRawString().split("/"),e=t.length-1;let i="";for(let r=0;r<e;r++)i+=t[r],r<e-1&&(i+="/");return i}getTextureFileName(t){return this._jsonValue.at(4).getValueByIndex(t).getRawString()}getHitAreasCount(){return this.isExistHitAreas()?this._jsonValue.at(7).getSize():0}getHitAreaId(t){return ct.getIdManager().getId(this._jsonValue.at(7).getValueByIndex(t).getValueByString(this.id).getRawString())}getHitAreaName(t){return this._jsonValue.at(7).getValueByIndex(t).getValueByString(this.name).getRawString()}getPhysicsFileName(){return this.isExistPhysicsFile()?this._jsonValue.at(5).getRawString():""}getPoseFileName(){return this.isExistPoseFile()?this._jsonValue.at(6).getRawString():""}getExpressionCount(){return this.isExistExpressionFile()?this._jsonValue.at(3).getSize():0}getExpressionName(t){return this._jsonValue.at(3).getValueByIndex(t).getValueByString(this.name).getRawString()}getExpressionFileName(t){return this._jsonValue.at(3).getValueByIndex(t).getValueByString(this.filePath).getRawString()}getMotionGroupCount(){return this.isExistMotionGroups()?this._jsonValue.at(2).getKeys().getSize():0}getMotionGroupName(t){return this.isExistMotionGroups()?this._jsonValue.at(2).getKeys().at(t):null}getMotionCount(t){return this.isExistMotionGroupName(t)?this._jsonValue.at(2).getValueByString(t).getSize():0}getMotionFileName(t,e){return this.isExistMotionGroupName(t)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.filePath).getRawString():""}getMotionSoundFileName(t,e){return this.isExistMotionSoundFile(t,e)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.soundPath).getRawString():""}getMotionFadeInTimeValue(t,e){return this.isExistMotionFadeIn(t,e)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeInTime).toFloat():-1}getMotionFadeOutTimeValue(t,e){return this.isExistMotionFadeOut(t,e)?this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeOutTime).toFloat():-1}getUserDataFile(){return this.isExistUserDataFile()?this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData).getRawString():""}getLayoutMap(t){const e=this.getJson().getRoot().getValueByString(this.layout).getMap();if(null==e)return!1;let i=!1;for(const r=e.begin();r.notEqual(e.end());r.preIncrement())t.setValue(r.ptr().first,r.ptr().second.toFloat()),i=!0;return i}getEyeBlinkParameterCount(){if(!this.isExistEyeBlinkParameters())return 0;let t=0;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.eyeBlink){t=i.getValueByString(this.ids).getVector().getSize();break}}return t}getEyeBlinkParameterId(t){if(!this.isExistEyeBlinkParameters())return null;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.eyeBlink)return ct.getIdManager().getId(i.getValueByString(this.ids).getValueByIndex(t).getRawString())}return null}getLipSyncParameterCount(){if(!this.isExistLipSyncParameters())return 0;let t=0;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.lipSync){t=i.getValueByString(this.ids).getVector().getSize();break}}return t}getLipSyncParameterId(t){if(!this.isExistLipSyncParameters())return null;for(let e=0;e<this._jsonValue.at(0).getSize();e++){const i=this._jsonValue.at(0).getValueByIndex(e);if(!i.isNull()&&!i.isError()&&i.getValueByString(this.name).getRawString()==this.lipSync)return ct.getIdManager().getId(i.getValueByString(this.ids).getValueByIndex(t).getRawString())}return null}isExistModelFile(){const t=this._jsonValue.at(1);return!t.isNull()&&!t.isError()}isExistTextureFiles(){const t=this._jsonValue.at(4);return!t.isNull()&&!t.isError()}isExistHitAreas(){const t=this._jsonValue.at(7);return!t.isNull()&&!t.isError()}isExistPhysicsFile(){const t=this._jsonValue.at(5);return!t.isNull()&&!t.isError()}isExistPoseFile(){const t=this._jsonValue.at(6);return!t.isNull()&&!t.isError()}isExistExpressionFile(){const t=this._jsonValue.at(3);return!t.isNull()&&!t.isError()}isExistMotionGroups(){const t=this._jsonValue.at(2);return!t.isNull()&&!t.isError()}isExistMotionGroupName(t){const e=this._jsonValue.at(2).getValueByString(t);return!e.isNull()&&!e.isError()}isExistMotionSoundFile(t,e){const i=this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.soundPath);return!i.isNull()&&!i.isError()}isExistMotionFadeIn(t,e){const i=this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeInTime);return!i.isNull()&&!i.isError()}isExistMotionFadeOut(t,e){const i=this._jsonValue.at(2).getValueByString(t).getValueByIndex(e).getValueByString(this.fadeOutTime);return!i.isNull()&&!i.isError()}isExistUserDataFile(){const t=this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData);return!t.isNull()&&!t.isError()}isExistEyeBlinkParameters(){if(this._jsonValue.at(0).isNull()||this._jsonValue.at(0).isError())return!1;for(let t=0;t<this._jsonValue.at(0).getSize();++t)if(this._jsonValue.at(0).getValueByIndex(t).getValueByString(this.name).getRawString()==this.eyeBlink)return!0;return!1}isExistLipSyncParameters(){if(this._jsonValue.at(0).isNull()||this._jsonValue.at(0).isError())return!1;for(let t=0;t<this._jsonValue.at(0).getSize();++t)if(this._jsonValue.at(0).getValueByIndex(t).getValueByString(this.name).getRawString()==this.lipSync)return!0;return!1}}(t=>{t.CubismModelSettingJson=pr,t.FrequestNode=mr})(cr||(cr={}));const _r=[Vi.ParamEyeLOpen,Vi.ParamEyeROpen];class fr extends Et{constructor(t){var e,i;if(super(t),g(this,"moc"),g(this,"textures"),g(this,"layout"),g(this,"hitAreas"),g(this,"expressions"),g(this,"motions"),!fr.isValidJSON(t))throw new TypeError("Invalid JSON.");const r=(new TextEncoder).encode(JSON.stringify(t)).buffer;Object.assign(this,new pr(r,r.byteLength)),this.moc=t.FileReferences.Moc,this.textures=[...t.FileReferences.Textures],this.pose=t.FileReferences.Pose,this.physics=t.FileReferences.Physics,this.expressions=null==(e=t.FileReferences.Expressions)?void 0:e.filter(t=>!!t&&"string"==typeof t.File),this.motions=null!=(i=t.FileReferences.Motions)?i:t.Motions,this.layout=t.Layout,this.hitAreas=t.HitAreas;const s=this.getFileStem(this.moc);this.setModelName(s,this.name)}static isValidJSON(t){if(!t||"object"!=typeof t)return!1;const e=t.FileReferences;if(!e||"object"!=typeof e||"string"!=typeof e.Moc)return!1;const i=e.Textures;if(!Array.isArray(i)||0===i.length)return!1;if(!i.every(t=>"string"==typeof t))return!1;const r=e.Expressions;return!(void 0!==r&&(!Array.isArray(r)||r.some(t=>!(t=>!!t&&"string"==typeof t.File)(t))))}replaceFiles(t){if(super.replaceFiles(t),this.motions)for(const[e,i]of Object.entries(this.motions))for(let r=0;r<i.length;r++){const s=i[r];(null==s?void 0:s.File)&&(s.File=t(s.File,`motions.${e}[${r}].File`),s.Sound&&(s.Sound=t(s.Sound,`motions.${e}[${r}].Sound`)))}if(this.expressions)for(let e=0;e<this.expressions.length;e++){const i=this.expressions[e];(null==i?void 0:i.File)&&(i.File=t(i.File,`expressions[${e}].File`))}}getEyeBlinkParameters(){var t,e,i;const r=[],s=null!=(e=null==(t=this.getEyeBlinkParameterCount)?void 0:t.call(this))?e:0;if(s>0)for(let a=0;a<s;a++){const t=null==(i=this.getEyeBlinkParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&r.push(t.getString().s)}else if(Array.isArray(this.json.Groups)){const t=this.json.Groups;for(const e of t)if("EyeBlink"===(null==e?void 0:e.Name)&&Array.isArray(e.Ids))for(const t of e.Ids)"string"==typeof t?r.push(t):(null==t?void 0:t.Id)&&r.push(t.Id)}return r.length?r:[..._r]}getLipSyncParameters(){var t,e,i;const r=[],s=null!=(e=null==(t=this.getLipSyncParameterCount)?void 0:t.call(this))?e:0;if(s>0)for(let a=0;a<s;a++){const t=null==(i=this.getLipSyncParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&r.push(t.getString().s)}else if(Array.isArray(this.json.Groups)){const t=this.json.Groups;for(const e of t)if("LipSync"===(null==e?void 0:e.Name)&&Array.isArray(e.Ids))for(const t of e.Ids)"string"==typeof t?r.push(t):(null==t?void 0:t.Id)&&r.push(t.Id)}return r}}let yr;Mt(fr,[pr]);let xr=20,Cr=16;function Mr(t={}){null!=t.memorySizeMB&&(Cr=t.memorySizeMB)}function Sr(){return ct.isStarted()?Promise.resolve():(null!=yr||(yr=new Promise((t,e)=>{!function i(){try{vr(),t()}catch(r){if(xr--,xr<0)return void e(new Error("Failed to start up Cubism framework.",{cause:r}));_t.log("Cubism","Startup failed, retrying 10ms later..."),setTimeout(i,10)}}()})),yr)}function vr(t,e){const i=d({logFunction:console.log,loggingLevel:mt.LogLevel_Verbose},t),r=null!=e?e:Cr;ct.startUp(i),ct.initialize(yt(r))}const br="FadeInTime",Pr="Link";class Br{static create(t,e){const i=Z.create(t,e);if(!i)return null;const r=new Br,s=i.getRoot();s.getValueByString(br).isNull()||(r._fadeTimeSeconds=s.getValueByString(br).toFloat(.5),r._fadeTimeSeconds<0&&(r._fadeTimeSeconds=.5));const a=s.getValueByString("Groups"),n=a.getSize();for(let o=0;o<n;++o){const t=a.getValueByIndex(o),e=t.getSize();let i=0;for(let s=0;s<e;++s){const e=t.getValueByIndex(s),a=new wr,n=ct.getIdManager().getId(e.getValueByString("Id").getRawString());if(a.partId=n,!e.getValueByString(Pr).isNull()){const t=e.getValueByString(Pr),i=t.getSize();for(let e=0;e<i;++e){const i=new wr,r=ct.getIdManager().getId(t.getValueByIndex(e).getString());i.partId=r,a.link.pushBack(i)}}r._partGroups.pushBack(a.clone()),++i}r._partGroupCounts.pushBack(i)}return Z.delete(i),r}static delete(t){}updateParameters(t,e){t!=this._lastModel&&this.reset(t),this._lastModel=t,e<0&&(e=0);let i=0;for(let r=0;r<this._partGroupCounts.getSize();r++){const s=this._partGroupCounts.at(r);this.doFade(t,e,i,s),i+=s}this.copyPartOpacities(t)}reset(t){let e=0;for(let i=0;i<this._partGroupCounts.getSize();++i){const r=this._partGroupCounts.at(i);for(let i=e;i<e+r;++i){this._partGroups.at(i).initialize(t);const r=this._partGroups.at(i).partIndex,s=this._partGroups.at(i).parameterIndex;if(!(r<0)){t.setPartOpacityByIndex(r,i==e?1:0),t.setParameterValueByIndex(s,i==e?1:0);for(let e=0;e<this._partGroups.at(i).link.getSize();++e)this._partGroups.at(i).link.at(e).initialize(t)}}e+=r}}copyPartOpacities(t){for(let e=0;e<this._partGroups.getSize();++e){const i=this._partGroups.at(e);if(0==i.link.getSize())continue;const r=this._partGroups.at(e).partIndex,s=t.getPartOpacityByIndex(r);for(let e=0;e<i.link.getSize();++e){const r=i.link.at(e).partIndex;r<0||t.setPartOpacityByIndex(r,s)}}}doFade(t,e,i,r){let s=-1,a=1;const n=.5;for(let o=i;o<i+r;++o){const i=this._partGroups.at(o).partIndex,r=this._partGroups.at(o).parameterIndex;if(t.getParameterValueByIndex(r)>.001){if(s>=0)break;if(s=o,0==this._fadeTimeSeconds){a=1;continue}a=t.getPartOpacityByIndex(i),a+=e/this._fadeTimeSeconds,a>1&&(a=1)}}s<0&&(s=0,a=1);for(let o=i;o<i+r;++o){const e=this._partGroups.at(o).partIndex;if(s==o)t.setPartOpacityByIndex(e,a);else{let i,r=t.getPartOpacityByIndex(e);i=a<n?-.5*a/n+1:(1-a)*n/.5;(1-i)*(1-a)>.15&&(i=1-.15/(1-a)),r>i&&(r=i),t.setPartOpacityByIndex(e,r)}}}constructor(){this._fadeTimeSeconds=.5,this._lastModel=null,this._partGroups=new p,this._partGroupCounts=new p}}class wr{constructor(t){if(this.parameterIndex=0,this.partIndex=0,this.link=new p,null!=t){this.partId=t.partId;for(const e=t.link.begin();e.notEqual(t.link.end());e.preIncrement())this.link.pushBack(e.ptr().clone())}}assignment(t){this.partId=t.partId;for(const e=t.link.begin();e.notEqual(t.link.end());e.preIncrement())this.link.pushBack(e.ptr().clone());return this}initialize(t){this.parameterIndex=t.getParameterIndex(this.partId),this.partIndex=t.getPartIndex(this.partId),t.setParameterValueByIndex(this.parameterIndex,1)}clone(){const t=new wr;t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=new p;for(let e=this.link.begin();e.notEqual(this.link.end());e.increment())t.link.pushBack(e.ptr().clone());return t}}var Fr,Ir,Er;(t=>{t.CubismPose=Br,t.PartData=wr})(Fr||(Fr={}));class Vr{constructor(t=!1,e=!1){this.isOverridden=t,this.isParameterRepeated=e}}class Lr{constructor(t=!1,e=new L){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class Rr{constructor(t=!1,e=new L){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class Tr{constructor(t=!1,e=!1){this.isOverridden=t,this.isCulling=e}get isOverwritten(){return this.isOverridden}}class Dr{update(){this._model.update(),this._model.drawables.resetDynamicFlags()}getPixelsPerUnit(){return null==this._model?0:this._model.canvasinfo.PixelsPerUnit}getCanvasWidth(){return null==this._model?0:this._model.canvasinfo.CanvasWidth/this._model.canvasinfo.PixelsPerUnit}getCanvasHeight(){return null==this._model?0:this._model.canvasinfo.CanvasHeight/this._model.canvasinfo.PixelsPerUnit}saveParameters(){const t=this._model.parameters.count,e=this._savedParameters.getSize();for(let i=0;i<t;++i)i<e?this._savedParameters.set(i,this._parameterValues[i]):this._savedParameters.pushBack(this._parameterValues[i])}getMultiplyColor(t){if(this.getOverrideFlagForModelMultiplyColors()||this.getOverrideFlagForDrawableMultiplyColors(t))return this._userMultiplyColors.at(t).color;return this.getDrawableMultiplyColor(t)}getScreenColor(t){if(this.getOverrideFlagForModelScreenColors()||this.getOverrideFlagForDrawableScreenColors(t))return this._userScreenColors.at(t).color;return this.getDrawableScreenColor(t)}setMultiplyColorByTextureColor(t,e){this.setMultiplyColorByRGBA(t,e.r,e.g,e.b,e.a)}setMultiplyColorByRGBA(t,e,i,r,s=1){this._userMultiplyColors.at(t).color.r=e,this._userMultiplyColors.at(t).color.g=i,this._userMultiplyColors.at(t).color.b=r,this._userMultiplyColors.at(t).color.a=s}setScreenColorByTextureColor(t,e){this.setScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setScreenColorByRGBA(t,e,i,r,s=1){this._userScreenColors.at(t).color.r=e,this._userScreenColors.at(t).color.g=i,this._userScreenColors.at(t).color.b=r,this._userScreenColors.at(t).color.a=s}getPartMultiplyColor(t){return this._userPartMultiplyColors.at(t).color}getPartScreenColor(t){return this._userPartScreenColors.at(t).color}setPartColor(t,e,i,r,s,a,n){if(a.at(t).color.r=e,a.at(t).color.g=i,a.at(t).color.b=r,a.at(t).color.a=s,a.at(t).isOverridden)for(let o=0;o<this._partChildDrawables.at(t).getSize();++o){const a=this._partChildDrawables.at(t).at(o);n.at(a).color.r=e,n.at(a).color.g=i,n.at(a).color.b=r,n.at(a).color.a=s}}setPartMultiplyColorByTextureColor(t,e){this.setPartMultiplyColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartMultiplyColorByRGBA(t,e,i,r,s){this.setPartColor(t,e,i,r,s,this._userPartMultiplyColors,this._userMultiplyColors)}setPartScreenColorByTextureColor(t,e){this.setPartScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartScreenColorByRGBA(t,e,i,r,s){this.setPartColor(t,e,i,r,s,this._userPartScreenColors,this._userScreenColors)}getOverrideFlagForModelParameterRepeat(){return this._isOverriddenParameterRepeat}setOverrideFlagForModelParameterRepeat(t){this._isOverriddenParameterRepeat=t}getOverrideFlagForParameterRepeat(t){return this._userParameterRepeatDataList.at(t).isOverridden}setOverrideFlagForParameterRepeat(t,e){this._userParameterRepeatDataList.at(t).isOverridden=e}getRepeatFlagForParameterRepeat(t){return this._userParameterRepeatDataList.at(t).isParameterRepeated}setRepeatFlagForParameterRepeat(t,e){this._userParameterRepeatDataList.at(t).isParameterRepeated=e}getOverwriteFlagForModelMultiplyColors(){return N("getOverwriteFlagForModelMultiplyColors() is a deprecated function. Please use getOverrideFlagForModelMultiplyColors()."),this.getOverrideFlagForModelMultiplyColors()}getOverrideFlagForModelMultiplyColors(){return this._isOverriddenModelMultiplyColors}getOverwriteFlagForModelScreenColors(){return N("getOverwriteFlagForModelScreenColors() is a deprecated function. Please use getOverrideFlagForModelScreenColors()."),this.getOverrideFlagForModelScreenColors()}getOverrideFlagForModelScreenColors(){return this._isOverriddenModelScreenColors}setOverwriteFlagForModelMultiplyColors(t){N("setOverwriteFlagForModelMultiplyColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelMultiplyColors(value: boolean)."),this.setOverrideFlagForModelMultiplyColors(t)}setOverrideFlagForModelMultiplyColors(t){this._isOverriddenModelMultiplyColors=t}setOverwriteFlagForModelScreenColors(t){N("setOverwriteFlagForModelScreenColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelScreenColors(value: boolean)."),this.setOverrideFlagForModelScreenColors(t)}setOverrideFlagForModelScreenColors(t){this._isOverriddenModelScreenColors=t}getOverwriteFlagForDrawableMultiplyColors(t){return N("getOverwriteFlagForDrawableMultiplyColors(drawableindex: number) is a deprecated function. Please use getOverrideFlagForDrawableMultiplyColors(drawableindex: number)."),this.getOverrideFlagForDrawableMultiplyColors(t)}getOverrideFlagForDrawableMultiplyColors(t){return this._userMultiplyColors.at(t).isOverridden}getOverwriteFlagForDrawableScreenColors(t){return N("getOverwriteFlagForDrawableScreenColors(drawableindex: number) is a deprecated function. Please use getOverrideFlagForDrawableScreenColors(drawableindex: number)."),this.getOverrideFlagForDrawableScreenColors(t)}getOverrideFlagForDrawableScreenColors(t){return this._userScreenColors.at(t).isOverridden}setOverwriteFlagForDrawableMultiplyColors(t,e){N("setOverwriteFlagForDrawableMultiplyColors(drawableindex: number, value: boolean) is a deprecated function. Please use setOverrideFlagForDrawableMultiplyColors(drawableindex: number, value: boolean)."),this.setOverrideFlagForDrawableMultiplyColors(t,e)}setOverrideFlagForDrawableMultiplyColors(t,e){this._userMultiplyColors.at(t).isOverridden=e}setOverwriteFlagForDrawableScreenColors(t,e){N("setOverwriteFlagForDrawableScreenColors(drawableindex: number, value: boolean) is a deprecated function. Please use setOverrideFlagForDrawableScreenColors(drawableindex: number, value: boolean)."),this.setOverrideFlagForDrawableScreenColors(t,e)}setOverrideFlagForDrawableScreenColors(t,e){this._userScreenColors.at(t).isOverridden=e}getOverwriteColorForPartMultiplyColors(t){return N("getOverwriteColorForPartMultiplyColors(partIndex: number) is a deprecated function. Please use getOverrideColorForPartMultiplyColors(partIndex: number)."),this.getOverrideColorForPartMultiplyColors(t)}getOverrideColorForPartMultiplyColors(t){return this._userPartMultiplyColors.at(t).isOverridden}getOverwriteColorForPartScreenColors(t){return N("getOverwriteColorForPartScreenColors(partIndex: number) is a deprecated function. Please use getOverrideColorForPartScreenColors(partIndex: number)."),this.getOverrideColorForPartScreenColors(t)}getOverrideColorForPartScreenColors(t){return this._userPartScreenColors.at(t).isOverridden}setOverwriteColorForPartColors(t,e,i,r){N("setOverwriteColorForPartColors(partIndex: number, value: boolean, partColors: csmVector<PartColorData>, drawableColors: csmVector<DrawableColorData>) is a deprecated function. Please use setOverrideColorForPartColors(partIndex: number, value: boolean, partColors: csmVector<PartColorData>, drawableColors: csmVector<DrawableColorData>)."),this.setOverrideColorForPartColors(t,e,i,r)}setOverrideColorForPartColors(t,e,i,r){i.at(t).isOverridden=e;for(let s=0;s<this._partChildDrawables.at(t).getSize();++s){const a=this._partChildDrawables.at(t).at(s);r.at(a).isOverridden=e,e&&(r.at(a).color.r=i.at(t).color.r,r.at(a).color.g=i.at(t).color.g,r.at(a).color.b=i.at(t).color.b,r.at(a).color.a=i.at(t).color.a)}}setOverwriteColorForPartMultiplyColors(t,e){N("setOverwriteColorForPartMultiplyColors(partIndex: number, value: boolean) is a deprecated function. Please use setOverrideColorForPartMultiplyColors(partIndex: number, value: boolean)."),this.setOverrideColorForPartMultiplyColors(t,e)}setOverrideColorForPartMultiplyColors(t,e){this._userPartMultiplyColors.at(t).isOverridden=e,this.setOverrideColorForPartColors(t,e,this._userPartMultiplyColors,this._userMultiplyColors)}setOverwriteColorForPartScreenColors(t,e){N("setOverwriteColorForPartScreenColors(partIndex: number, value: boolean) is a deprecated function. Please use setOverrideColorForPartScreenColors(partIndex: number, value: boolean)."),this.setOverrideColorForPartScreenColors(t,e)}setOverrideColorForPartScreenColors(t,e){this._userPartScreenColors.at(t).isOverridden=e,this.setOverrideColorForPartColors(t,e,this._userPartScreenColors,this._userScreenColors)}getDrawableCulling(t){if(this.getOverrideFlagForModelCullings()||this.getOverrideFlagForDrawableCullings(t))return this._userCullings.at(t).isCulling;const e=this._model.drawables.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(e[t])}setDrawableCulling(t,e){this._userCullings.at(t).isCulling=e}getOverwriteFlagForModelCullings(){return N("getOverwriteFlagForModelCullings() is a deprecated function. Please use getOverrideFlagForModelCullings()."),this.getOverrideFlagForModelCullings()}getOverrideFlagForModelCullings(){return this._isOverriddenCullings}setOverwriteFlagForModelCullings(t){N("setOverwriteFlagForModelCullings(isOverriddenCullings: boolean) is a deprecated function. Please use setOverrideFlagForModelCullings(isOverriddenCullings: boolean)."),this.setOverrideFlagForModelCullings(t)}setOverrideFlagForModelCullings(t){this._isOverriddenCullings=t}getOverwriteFlagForDrawableCullings(t){return N("getOverwriteFlagForDrawableCullings(drawableIndex: number) is a deprecated function. Please use getOverrideFlagForDrawableCullings(drawableIndex: number)."),this.getOverrideFlagForDrawableCullings(t)}getOverrideFlagForDrawableCullings(t){return this._userCullings.at(t).isOverridden}setOverwriteFlagForDrawableCullings(t,e){N("setOverwriteFlagForDrawableCullings(drawableIndex: number, isOverriddenCullings: boolean) is a deprecated function. Please use setOverrideFlagForDrawableCullings(drawableIndex: number, isOverriddenCullings: boolean)."),this.setOverrideFlagForDrawableCullings(t,e)}setOverrideFlagForDrawableCullings(t,e){this._userCullings.at(t).isOverridden=e}getModelOapcity(){return this._modelOpacity}setModelOapcity(t){this._modelOpacity=t}getModel(){return this._model}getPartIndex(t){let e;const i=this._model.parts.count;for(e=0;e<i;++e)if(t==this._partIds.at(e))return e;return this._notExistPartId.isExist(t)?this._notExistPartId.getValue(t):(e=i+this._notExistPartId.getSize(),this._notExistPartId.setValue(t,e),this._notExistPartOpacities.appendKey(e),e)}getPartId(t){const e=this._model.parts.ids[t];return ct.getIdManager().getId(e)}getPartCount(){return this._model.parts.count}getPartParentPartIndices(){return this._model.parts.parentIndices}setPartOpacityByIndex(t,e){this._notExistPartOpacities.isExist(t)?this._notExistPartOpacities.setValue(t,e):(A(0<=t&&t<this.getPartCount()),this._partOpacities[t]=e)}setPartOpacityById(t,e){const i=this.getPartIndex(t);i<0||this.setPartOpacityByIndex(i,e)}getPartOpacityByIndex(t){return this._notExistPartOpacities.isExist(t)?this._notExistPartOpacities.getValue(t):(A(0<=t&&t<this.getPartCount()),this._partOpacities[t])}getPartOpacityById(t){const e=this.getPartIndex(t);return e<0?0:this.getPartOpacityByIndex(e)}getParameterIndex(t){let e;const i=this._model.parameters.count;for(e=0;e<i;++e)if(t==this._parameterIds.at(e))return e;return this._notExistParameterId.isExist(t)?this._notExistParameterId.getValue(t):(e=this._model.parameters.count+this._notExistParameterId.getSize(),this._notExistParameterId.setValue(t,e),this._notExistParameterValues.appendKey(e),e)}getParameterCount(){return this._model.parameters.count}getParameterType(t){return this._model.parameters.types[t]}getParameterMaximumValue(t){return this._model.parameters.maximumValues[t]}getParameterMinimumValue(t){return this._model.parameters.minimumValues[t]}getParameterDefaultValue(t){return this._model.parameters.defaultValues[t]}getParameterId(t){return ct.getIdManager().getId(this._model.parameters.ids[t])}getParameterValueByIndex(t){return this._notExistParameterValues.isExist(t)?this._notExistParameterValues.getValue(t):(A(0<=t&&t<this.getParameterCount()),this._parameterValues[t])}getParameterValueById(t){const e=this.getParameterIndex(t);return this.getParameterValueByIndex(e)}setParameterValueByIndex(t,e,i=1){this._notExistParameterValues.isExist(t)?this._notExistParameterValues.setValue(t,1==i?e:this._notExistParameterValues.getValue(t)*(1-i)+e*i):(A(0<=t&&t<this.getParameterCount()),e=this.isRepeat(t)?this.getParameterRepeatValue(t,e):this.getParameterClampValue(t,e),this._parameterValues[t]=1==i?e:this._parameterValues[t]=this._parameterValues[t]*(1-i)+e*i)}setParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.setParameterValueByIndex(r,e,i)}addParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)+e*i)}addParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.addParameterValueByIndex(r,e,i)}isRepeat(t){if(this._notExistParameterValues.isExist(t))return!1;let e;return A(0<=t&&t<this.getParameterCount()),e=this._isOverriddenParameterRepeat||this._userParameterRepeatDataList.at(t).isOverridden?this._userParameterRepeatDataList.at(t).isParameterRepeated:0!=this._model.parameters.repeats[t],e}getParameterRepeatValue(t,e){if(this._notExistParameterValues.isExist(t))return e;A(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],r=this._model.parameters.minimumValues[t],s=i-r;if(i<e){const t=we.mod(e-i,s);e=Number.isNaN(t)?i:r+t}if(e<r){const t=we.mod(r-e,s);e=Number.isNaN(t)?r:i-t}return e}getParameterClampValue(t,e){if(this._notExistParameterValues.isExist(t))return e;A(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],r=this._model.parameters.minimumValues[t];return we.clamp(e,r,i)}getParameterRepeats(t){return 0!=this._model.parameters.repeats[t]}multiplyParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.multiplyParameterValueByIndex(r,e,i)}multiplyParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)*(1+(e-1)*i))}getDrawableIndex(t){const e=this._model.drawables.count;for(let i=0;i<e;++i)if(this._drawableIds.at(i)==t)return i;return-1}getDrawableCount(){return this._model.drawables.count}getDrawableId(t){const e=this._model.drawables.ids;return ct.getIdManager().getId(e[t])}getDrawableRenderOrders(){return this._model.drawables.renderOrders}getDrawableTextureIndices(t){return this.getDrawableTextureIndex(t)}getDrawableTextureIndex(t){return this._model.drawables.textureIndices[t]}getDrawableDynamicFlagVertexPositionsDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVertexPositionsDidChangeBit(e[t])}getDrawableVertexIndexCount(t){return this._model.drawables.indexCounts[t]}getDrawableVertexCount(t){return this._model.drawables.vertexCounts[t]}getDrawableVertices(t){return this.getDrawableVertexPositions(t)}getDrawableVertexIndices(t){return this._model.drawables.indices[t]}getDrawableVertexPositions(t){return this._model.drawables.vertexPositions[t]}getDrawableVertexUvs(t){return this._model.drawables.vertexUvs[t]}getDrawableOpacity(t){return this._model.drawables.opacities[t]}getDrawableMultiplyColor(t){const e=this._model.drawables.multiplyColors,i=4*t,r=new L;return r.r=e[i],r.g=e[i+1],r.b=e[i+2],r.a=e[i+3],r}getDrawableScreenColor(t){const e=this._model.drawables.screenColors,i=4*t,r=new L;return r.r=e[i],r.g=e[i+1],r.b=e[i+2],r.a=e[i+3],r}getDrawableParentPartIndex(t){return this._model.drawables.parentPartIndices[t]}getDrawableBlendMode(t){const e=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(e[t])?V.CubismBlendMode_Additive:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(e[t])?V.CubismBlendMode_Multiplicative:V.CubismBlendMode_Normal}getDrawableInvertedMaskBit(t){const e=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(e[t])}getDrawableMasks(){return this._model.drawables.masks}getDrawableMaskCounts(){return this._model.drawables.maskCounts}isUsingMasking(){for(let t=0;t<this._model.drawables.count;++t)if(!(this._model.drawables.maskCounts[t]<=0))return!0;return!1}getDrawableDynamicFlagIsVisible(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasIsVisibleBit(e[t])}getDrawableDynamicFlagVisibilityDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVisibilityDidChangeBit(e[t])}getDrawableDynamicFlagOpacityDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasOpacityDidChangeBit(e[t])}getDrawableDynamicFlagRenderOrderDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasRenderOrderDidChangeBit(e[t])}getDrawableDynamicFlagBlendColorDidChange(t){const e=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasBlendColorDidChangeBit(e[t])}loadParameters(){let t=this._model.parameters.count;const e=this._savedParameters.getSize();t>e&&(t=e);for(let i=0;i<t;++i)this._parameterValues[i]=this._savedParameters.at(i)}initialize(){A(this._model),this._parameterValues=this._model.parameters.values,this._partOpacities=this._model.parts.opacities,this._parameterMaximumValues=this._model.parameters.maximumValues,this._parameterMinimumValues=this._model.parameters.minimumValues;{const t=this._model.parameters.ids,e=this._model.parameters.count;this._parameterIds.prepareCapacity(e),this._userParameterRepeatDataList.prepareCapacity(e);for(let i=0;i<e;++i)this._parameterIds.pushBack(ct.getIdManager().getId(t[i])),this._userParameterRepeatDataList.pushBack(new Vr(!1,!1))}const t=this._model.parts.count;{const e=this._model.parts.ids;this._partIds.prepareCapacity(t);for(let i=0;i<t;++i)this._partIds.pushBack(ct.getIdManager().getId(e[i]));this._userPartMultiplyColors.prepareCapacity(t),this._userPartScreenColors.prepareCapacity(t),this._partChildDrawables.prepareCapacity(t)}{const e=this._model.drawables.ids,i=this._model.drawables.count;this._userMultiplyColors.prepareCapacity(i),this._userScreenColors.prepareCapacity(i),this._userCullings.prepareCapacity(i);const r=new Tr(!1,!1);for(let s=0;s<t;++s){const t=new L(1,1,1,1),e=new L(0,0,0,1),r=new Rr(!1,t),a=new Rr(!1,e);this._userPartMultiplyColors.pushBack(r),this._userPartScreenColors.pushBack(a),this._partChildDrawables.pushBack(new p),this._partChildDrawables.at(s).prepareCapacity(i)}for(let t=0;t<i;++t){const i=new L(1,1,1,1),s=new L(0,0,0,1),a=new Lr(!1,i),n=new Lr(!1,s);this._drawableIds.pushBack(ct.getIdManager().getId(e[t])),this._userMultiplyColors.pushBack(a),this._userScreenColors.pushBack(n),this._userCullings.pushBack(r);const o=this.getDrawableParentPartIndex(t);o>=0&&this._partChildDrawables.at(o).pushBack(t)}}}constructor(t){this._model=t,this._parameterValues=null,this._parameterMaximumValues=null,this._parameterMinimumValues=null,this._partOpacities=null,this._savedParameters=new p,this._parameterIds=new p,this._drawableIds=new p,this._partIds=new p,this._isOverriddenParameterRepeat=!0,this._isOverriddenModelMultiplyColors=!1,this._isOverriddenModelScreenColors=!1,this._isOverriddenCullings=!1,this._modelOpacity=1,this._userParameterRepeatDataList=new p,this._userMultiplyColors=new p,this._userScreenColors=new p,this._userCullings=new p,this._userPartMultiplyColors=new p,this._userPartScreenColors=new p,this._partChildDrawables=new p,this._notExistPartId=new H,this._notExistParameterId=new H,this._notExistParameterValues=new H,this._notExistPartOpacities=new H}release(){this._model.release(),this._model=null}}(t=>{t.CubismModel=Dr})(Ir||(Ir={}));class Ar{static create(t,e){let i=null;if(e){if(!this.hasMocConsistency(t))return U("Inconsistent MOC3."),i}const r=Live2DCubismCore.Moc.fromArrayBuffer(t);return r&&(i=new Ar(r),i._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(r,t)),i}static delete(t){t._moc._release(),t._moc=null,t=null}createModel(){let t=null;const e=Live2DCubismCore.Model.fromMoc(this._moc);return e&&(t=new Dr(e),t.initialize(),++this._modelCount),t}deleteModel(t){null!=t&&(t.release(),t=null,--this._modelCount)}constructor(t){this._moc=t,this._modelCount=0,this._mocVersion=0}release(){A(0==this._modelCount),this._moc._release(),this._moc=null}getLatestMocVersion(){return Live2DCubismCore.Version.csmGetLatestMocVersion()}getMocVersion(){return this._mocVersion}static hasMocConsistency(t){return 1===Live2DCubismCore.Moc.prototype.hasMocConsistency(t)}}(t=>{t.CubismMoc=Ar})(Er||(Er={}));var Or,kr=(t=>(t[t.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",t))(kr||{}),Nr=(t=>(t[t.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",t[t.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",t[t.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",t))(Nr||{});class Ur{constructor(){this.gravity=new be(0,0),this.wind=new be(0,0)}}class zr{}class jr{}class Gr{constructor(){this.initialPosition=new be(0,0),this.position=new be(0,0),this.lastPosition=new be(0,0),this.lastGravity=new be(0,0),this.force=new be(0,0),this.velocity=new be(0,0)}}class Xr{constructor(){this.normalizationPosition=new jr,this.normalizationAngle=new jr}}class Hr{constructor(){this.source=new zr}}class qr{constructor(){this.destination=new zr,this.translationScale=new be(0,0)}}class Yr{constructor(){this.settings=new p,this.inputs=new p,this.outputs=new p,this.particles=new p,this.gravity=new be(0,0),this.wind=new be(0,0),this.fps=0}}(t=>{t.CubismPhysicsInput=Hr,t.CubismPhysicsNormalization=jr,t.CubismPhysicsOutput=qr,t.CubismPhysicsParameter=zr,t.CubismPhysicsParticle=Gr,t.CubismPhysicsRig=Yr,t.CubismPhysicsSource=Nr,t.CubismPhysicsSubRig=Xr,t.CubismPhysicsTargetType=kr,t.PhysicsJsonEffectiveForces=Ur})(Or||(Or={}));const Wr="Position",Jr="Angle",$r="Type",Zr="Meta",Kr="EffectiveForces",Qr="Gravity",ts="Wind",es="PhysicsSettings",is="Normalization",rs="Minimum",ss="Maximum",as="Default",ns="Reflect",os="Weight",ls="Input",us="Output",hs="Vertices";class ds{constructor(t,e){this._json=Z.create(t,e)}release(){Z.delete(this._json)}getGravity(){const t=new be(0,0);return t.x=this._json.getRoot().getValueByString(Zr).getValueByString(Kr).getValueByString(Qr).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString(Zr).getValueByString(Kr).getValueByString(Qr).getValueByString("Y").toFloat(),t}getWind(){const t=new be(0,0);return t.x=this._json.getRoot().getValueByString(Zr).getValueByString(Kr).getValueByString(ts).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString(Zr).getValueByString(Kr).getValueByString(ts).getValueByString("Y").toFloat(),t}getFps(){return this._json.getRoot().getValueByString(Zr).getValueByString("Fps").toFloat(0)}getSubRigCount(){return this._json.getRoot().getValueByString(Zr).getValueByString("PhysicsSettingCount").toInt()}getTotalInputCount(){return this._json.getRoot().getValueByString(Zr).getValueByString("TotalInputCount").toInt()}getTotalOutputCount(){return this._json.getRoot().getValueByString(Zr).getValueByString("TotalOutputCount").toInt()}getVertexCount(){return this._json.getRoot().getValueByString(Zr).getValueByString("VertexCount").toInt()}getNormalizationPositionMinimumValue(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(is).getValueByString(Wr).getValueByString(rs).toFloat()}getNormalizationPositionMaximumValue(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(is).getValueByString(Wr).getValueByString(ss).toFloat()}getNormalizationPositionDefaultValue(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(is).getValueByString(Wr).getValueByString(as).toFloat()}getNormalizationAngleMinimumValue(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(is).getValueByString(Jr).getValueByString(rs).toFloat()}getNormalizationAngleMaximumValue(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(is).getValueByString(Jr).getValueByString(ss).toFloat()}getNormalizationAngleDefaultValue(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(is).getValueByString(Jr).getValueByString(as).toFloat()}getInputCount(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(ls).getVector().getSize()}getInputWeight(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString(os).toFloat()}getInputReflect(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString(ns).toBoolean()}getInputType(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString($r).getRawString()}getInputSourceId(t,e){return ct.getIdManager().getId(this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(ls).getValueByIndex(e).getValueByString("Source").getValueByString("Id").getRawString())}getOutputCount(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(us).getVector().getSize()}getOutputVertexIndex(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString("VertexIndex").toInt()}getOutputAngleScale(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString("Scale").toFloat()}getOutputWeight(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString(os).toFloat()}getOutputDestinationId(t,e){return ct.getIdManager().getId(this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString("Destination").getValueByString("Id").getRawString())}getOutputType(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString($r).getRawString()}getOutputReflect(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(us).getValueByIndex(e).getValueByString(ns).toBoolean()}getParticleCount(t){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(hs).getVector().getSize()}getParticleMobility(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(hs).getValueByIndex(e).getValueByString("Mobility").toFloat()}getParticleDelay(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(hs).getValueByIndex(e).getValueByString("Delay").toFloat()}getParticleAcceleration(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(hs).getValueByIndex(e).getValueByString("Acceleration").toFloat()}getParticleRadius(t,e){return this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(hs).getValueByIndex(e).getValueByString("Radius").toFloat()}getParticlePosition(t,e){const i=new be(0,0);return i.x=this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(hs).getValueByIndex(e).getValueByString(Wr).getValueByString("X").toFloat(),i.y=this._json.getRoot().getValueByString(es).getValueByIndex(t).getValueByString(hs).getValueByIndex(e).getValueByString(Wr).getValueByString("Y").toFloat(),i}}var gs;(t=>{t.CubismPhysicsJson=ds})(gs||(gs={}));const cs="Angle";class ms{static create(t,e){const i=new ms;return i.parse(t,e),i._physicsRig.gravity.y=0,i}static delete(t){null!=t&&(t.release(),t=null)}parse(t,e){this._physicsRig=new Yr;let i=new ds(t,e);this._physicsRig.gravity=i.getGravity(),this._physicsRig.wind=i.getWind(),this._physicsRig.subRigCount=i.getSubRigCount(),this._physicsRig.fps=i.getFps(),this._physicsRig.settings.updateSize(this._physicsRig.subRigCount,Xr,!0),this._physicsRig.inputs.updateSize(i.getTotalInputCount(),Hr,!0),this._physicsRig.outputs.updateSize(i.getTotalOutputCount(),qr,!0),this._physicsRig.particles.updateSize(i.getVertexCount(),Gr,!0),this._currentRigOutputs.clear(),this._previousRigOutputs.clear();let r=0,s=0,a=0;for(let n=0;n<this._physicsRig.settings.getSize();++n){this._physicsRig.settings.at(n).normalizationPosition.minimum=i.getNormalizationPositionMinimumValue(n),this._physicsRig.settings.at(n).normalizationPosition.maximum=i.getNormalizationPositionMaximumValue(n),this._physicsRig.settings.at(n).normalizationPosition.defalut=i.getNormalizationPositionDefaultValue(n),this._physicsRig.settings.at(n).normalizationAngle.minimum=i.getNormalizationAngleMinimumValue(n),this._physicsRig.settings.at(n).normalizationAngle.maximum=i.getNormalizationAngleMaximumValue(n),this._physicsRig.settings.at(n).normalizationAngle.defalut=i.getNormalizationAngleDefaultValue(n),this._physicsRig.settings.at(n).inputCount=i.getInputCount(n),this._physicsRig.settings.at(n).baseInputIndex=r;for(let s=0;s<this._physicsRig.settings.at(n).inputCount;++s)this._physicsRig.inputs.at(r+s).sourceParameterIndex=-1,this._physicsRig.inputs.at(r+s).weight=i.getInputWeight(n,s),this._physicsRig.inputs.at(r+s).reflect=i.getInputReflect(n,s),"X"==i.getInputType(n,s)?(this._physicsRig.inputs.at(r+s).type=Nr.CubismPhysicsSource_X,this._physicsRig.inputs.at(r+s).getNormalizedParameterValue=fs):"Y"==i.getInputType(n,s)?(this._physicsRig.inputs.at(r+s).type=Nr.CubismPhysicsSource_Y,this._physicsRig.inputs.at(r+s).getNormalizedParameterValue=ys):i.getInputType(n,s)==cs&&(this._physicsRig.inputs.at(r+s).type=Nr.CubismPhysicsSource_Angle,this._physicsRig.inputs.at(r+s).getNormalizedParameterValue=xs),this._physicsRig.inputs.at(r+s).source.targetType=kr.CubismPhysicsTargetType_Parameter,this._physicsRig.inputs.at(r+s).source.id=i.getInputSourceId(n,s);r+=this._physicsRig.settings.at(n).inputCount,this._physicsRig.settings.at(n).outputCount=i.getOutputCount(n),this._physicsRig.settings.at(n).baseOutputIndex=s;const t=new _s;t.outputs.resize(this._physicsRig.settings.at(n).outputCount);const e=new _s;e.outputs.resize(this._physicsRig.settings.at(n).outputCount);for(let r=0;r<this._physicsRig.settings.at(n).outputCount;++r)t.outputs.set(r,0),e.outputs.set(r,0),this._physicsRig.outputs.at(s+r).destinationParameterIndex=-1,this._physicsRig.outputs.at(s+r).vertexIndex=i.getOutputVertexIndex(n,r),this._physicsRig.outputs.at(s+r).angleScale=i.getOutputAngleScale(n,r),this._physicsRig.outputs.at(s+r).weight=i.getOutputWeight(n,r),this._physicsRig.outputs.at(s+r).destination.targetType=kr.CubismPhysicsTargetType_Parameter,this._physicsRig.outputs.at(s+r).destination.id=i.getOutputDestinationId(n,r),"X"==i.getOutputType(n,r)?(this._physicsRig.outputs.at(s+r).type=Nr.CubismPhysicsSource_X,this._physicsRig.outputs.at(s+r).getValue=Cs,this._physicsRig.outputs.at(s+r).getScale=bs):"Y"==i.getOutputType(n,r)?(this._physicsRig.outputs.at(s+r).type=Nr.CubismPhysicsSource_Y,this._physicsRig.outputs.at(s+r).getValue=Ms,this._physicsRig.outputs.at(s+r).getScale=Ps):i.getOutputType(n,r)==cs&&(this._physicsRig.outputs.at(s+r).type=Nr.CubismPhysicsSource_Angle,this._physicsRig.outputs.at(s+r).getValue=Ss,this._physicsRig.outputs.at(s+r).getScale=Bs),this._physicsRig.outputs.at(s+r).reflect=i.getOutputReflect(n,r);this._currentRigOutputs.pushBack(t),this._previousRigOutputs.pushBack(e),s+=this._physicsRig.settings.at(n).outputCount,this._physicsRig.settings.at(n).particleCount=i.getParticleCount(n),this._physicsRig.settings.at(n).baseParticleIndex=a;for(let r=0;r<this._physicsRig.settings.at(n).particleCount;++r)this._physicsRig.particles.at(a+r).mobility=i.getParticleMobility(n,r),this._physicsRig.particles.at(a+r).delay=i.getParticleDelay(n,r),this._physicsRig.particles.at(a+r).acceleration=i.getParticleAcceleration(n,r),this._physicsRig.particles.at(a+r).radius=i.getParticleRadius(n,r),this._physicsRig.particles.at(a+r).position=i.getParticlePosition(n,r);a+=this._physicsRig.settings.at(n).particleCount}this.initialize(),i.release(),i=void 0,i=null}stabilization(t){var e,i,r,s;let a,n,o,l;const u=new be;let h,d,g,c;const m=t.getModel().parameters.values,p=t.getModel().parameters.maximumValues,_=t.getModel().parameters.minimumValues,f=t.getModel().parameters.defaultValues;(null!=(i=null==(e=this._parameterCaches)?void 0:e.length)?i:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(null!=(s=null==(r=this._parameterInputCaches)?void 0:r.length)?s:0)<t.getParameterCount()&&(this._parameterInputCaches=new Float32Array(t.getParameterCount()));for(let y=0;y<t.getParameterCount();++y)this._parameterCaches[y]=m[y],this._parameterInputCaches[y]=m[y];for(let y=0;y<this._physicsRig.subRigCount;++y){a={angle:0},u.x=0,u.y=0,h=this._physicsRig.settings.at(y),d=this._physicsRig.inputs.get(h.baseInputIndex),g=this._physicsRig.outputs.get(h.baseOutputIndex),c=this._physicsRig.particles.get(h.baseParticleIndex);for(let e=0;e<h.inputCount;++e)n=d[e].weight/100,-1==d[e].sourceParameterIndex&&(d[e].sourceParameterIndex=t.getParameterIndex(d[e].source.id)),d[e].getNormalizedParameterValue(u,a,m[d[e].sourceParameterIndex],_[d[e].sourceParameterIndex],p[d[e].sourceParameterIndex],f[d[e].sourceParameterIndex],h.normalizationPosition,h.normalizationAngle,d[e].reflect,n),this._parameterCaches[d[e].sourceParameterIndex]=m[d[e].sourceParameterIndex];o=we.degreesToRadian(-a.angle),u.x=u.x*we.cos(o)-u.y*we.sin(o),u.y=u.x*we.sin(o)+u.y*we.cos(o),Fs(c,h.particleCount,u,a.angle,this._options.wind,.001*h.normalizationPosition.maximum);for(let e=0;e<h.outputCount;++e){const i=g[e].vertexIndex;if(-1==g[e].destinationParameterIndex&&(g[e].destinationParameterIndex=t.getParameterIndex(g[e].destination.id)),i<1||i>=h.particleCount)continue;let r=new be;r=c[i].position.substract(c[i-1].position),l=g[e].getValue(r,c,i,g[e].reflect,this._options.gravity),this._currentRigOutputs.at(y).outputs.set(e,l),this._previousRigOutputs.at(y).outputs.set(e,l);const s=g[e].destinationParameterIndex,a=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(m.subarray(s))):m.slice(s);Is(a,_[s],p[s],l,g[e]);for(let t=s,e=0;t<this._parameterCaches.length;t++,e++)m[t]=this._parameterCaches[t]=a[e]}}}evaluate(t,e){var i,r,s,a;let n,o,l,u;const h=new be;let d,g,c,m;if(0>=e)return;const p=t.getModel().parameters.values,_=t.getModel().parameters.maximumValues,f=t.getModel().parameters.minimumValues,y=t.getModel().parameters.defaultValues;let x;if(this._currentRemainTime+=e,this._currentRemainTime>5&&(this._currentRemainTime=0),(null!=(r=null==(i=this._parameterCaches)?void 0:i.length)?r:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(null!=(a=null==(s=this._parameterInputCaches)?void 0:s.length)?a:0)<t.getParameterCount()){this._parameterInputCaches=new Float32Array(t.getParameterCount());for(let e=0;e<t.getParameterCount();++e)this._parameterInputCaches[e]=p[e]}for(x=this._physicsRig.fps>0?1/this._physicsRig.fps:e;this._currentRemainTime>=x;){for(let t=0;t<this._physicsRig.subRigCount;++t){d=this._physicsRig.settings.at(t),c=this._physicsRig.outputs.get(d.baseOutputIndex);for(let e=0;e<d.outputCount;++e)this._previousRigOutputs.at(t).outputs.set(e,this._currentRigOutputs.at(t).outputs.at(e))}const e=x/this._currentRemainTime;for(let i=0;i<t.getParameterCount();++i)this._parameterCaches[i]=this._parameterInputCaches[i]*(1-e)+p[i]*e,this._parameterInputCaches[i]=this._parameterCaches[i];for(let i=0;i<this._physicsRig.subRigCount;++i){n={angle:0},h.x=0,h.y=0,d=this._physicsRig.settings.at(i),g=this._physicsRig.inputs.get(d.baseInputIndex),c=this._physicsRig.outputs.get(d.baseOutputIndex),m=this._physicsRig.particles.get(d.baseParticleIndex);for(let e=0;e<d.inputCount;++e)o=g[e].weight/100,-1==g[e].sourceParameterIndex&&(g[e].sourceParameterIndex=t.getParameterIndex(g[e].source.id)),g[e].getNormalizedParameterValue(h,n,this._parameterCaches[g[e].sourceParameterIndex],f[g[e].sourceParameterIndex],_[g[e].sourceParameterIndex],y[g[e].sourceParameterIndex],d.normalizationPosition,d.normalizationAngle,g[e].reflect,o);l=we.degreesToRadian(-n.angle),h.x=h.x*we.cos(l)-h.y*we.sin(l),h.y=h.x*we.sin(l)+h.y*we.cos(l),ws(m,d.particleCount,h,n.angle,this._options.wind,.001*d.normalizationPosition.maximum,x,5);for(let e=0;e<d.outputCount;++e){const r=c[e].vertexIndex;if(-1==c[e].destinationParameterIndex&&(c[e].destinationParameterIndex=t.getParameterIndex(c[e].destination.id)),r<1||r>=d.particleCount)continue;const s=new be;s.x=m[r].position.x-m[r-1].position.x,s.y=m[r].position.y-m[r-1].position.y,u=c[e].getValue(s,m,r,c[e].reflect,this._options.gravity),this._currentRigOutputs.at(i).outputs.set(e,u);const a=c[e].destinationParameterIndex,n=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(this._parameterCaches.subarray(a))):this._parameterCaches.slice(a);Is(n,f[a],_[a],u,c[e]);for(let t=a,e=0;t<this._parameterCaches.length;t++,e++)this._parameterCaches[t]=n[e]}}this._currentRemainTime-=x}const C=this._currentRemainTime/x;this.interpolate(t,C)}interpolate(t,e){let i,r;const s=t.getModel().parameters.values,a=t.getModel().parameters.maximumValues,n=t.getModel().parameters.minimumValues;for(let o=0;o<this._physicsRig.subRigCount;++o){r=this._physicsRig.settings.at(o),i=this._physicsRig.outputs.get(r.baseOutputIndex);for(let t=0;t<r.outputCount;++t){if(-1==i[t].destinationParameterIndex)continue;const r=i[t].destinationParameterIndex,l=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(s.subarray(r))):s.slice(r);Is(l,n[r],a[r],this._previousRigOutputs.at(o).outputs.at(t)*(1-e)+this._currentRigOutputs.at(o).outputs.at(t)*e,i[t]);for(let t=r,e=0;t<s.length;t++,e++)s[t]=l[e]}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._physicsRig=null,this._options=new ps,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=new p,this._previousRigOutputs=new p,this._currentRemainTime=0,this._parameterCaches=null,this._parameterInputCaches=null}release(){this._physicsRig=void 0,this._physicsRig=null}initialize(){let t,e,i;for(let r=0;r<this._physicsRig.subRigCount;++r){e=this._physicsRig.settings.at(r),t=this._physicsRig.particles.get(e.baseParticleIndex),t[0].initialPosition=new be(0,0),t[0].lastPosition=new be(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new be(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new be(0,0),t[0].force=new be(0,0);for(let r=1;r<e.particleCount;++r)i=new be(0,0),i.y=t[r].radius,t[r].initialPosition=new be(t[r-1].initialPosition.x+i.x,t[r-1].initialPosition.y+i.y),t[r].position=new be(t[r].initialPosition.x,t[r].initialPosition.y),t[r].lastPosition=new be(t[r].initialPosition.x,t[r].initialPosition.y),t[r].lastGravity=new be(0,-1),t[r].lastGravity.y*=-1,t[r].velocity=new be(0,0),t[r].force=new be(0,0)}}}class ps{constructor(){this.gravity=new be(0,0),this.wind=new be(0,0)}}class _s{constructor(){this.outputs=new p(0)}}function fs(t,e,i,r,s,a,n,o,l,u){t.x+=Es(i,r,s,a,n.minimum,n.maximum,n.defalut,l)*u}function ys(t,e,i,r,s,a,n,o,l,u){t.y+=Es(i,r,s,a,n.minimum,n.maximum,n.defalut,l)*u}function xs(t,e,i,r,s,a,n,o,l,u){e.angle+=Es(i,r,s,a,o.minimum,o.maximum,o.defalut,l)*u}function Cs(t,e,i,r,s){let a=t.x;return r&&(a*=-1),a}function Ms(t,e,i,r,s){let a=t.y;return r&&(a*=-1),a}function Ss(t,e,i,r,s){let a;return s=i>=2?e[i-1].position.substract(e[i-2].position):s.multiplyByScaler(-1),a=we.directionToRadian(s,t),r&&(a*=-1),a}function vs(t,e){return we.min(t,e)+function(t,e){const i=we.max(t,e),r=we.min(t,e);return we.abs(i-r)}(t,e)/2}function bs(t,e){return JSON.parse(JSON.stringify(t.x))}function Ps(t,e){return JSON.parse(JSON.stringify(t.y))}function Bs(t,e){return JSON.parse(JSON.stringify(e))}function ws(t,e,i,r,s,a,n,o){let l,u,h=new be(0,0),d=new be(0,0),g=new be(0,0),c=new be(0,0);t[0].position=new be(i.x,i.y);const m=we.degreesToRadian(r),p=we.radianToDirection(m);p.normalize();for(let _=1;_<e;++_)t[_].force=p.multiplyByScaler(t[_].acceleration).add(s),t[_].lastPosition=new be(t[_].position.x,t[_].position.y),l=t[_].delay*n*30,h=t[_].position.substract(t[_-1].position),u=we.directionToRadian(t[_].lastGravity,p)/o,h.x=we.cos(u)*h.x-h.y*we.sin(u),h.y=we.sin(u)*h.x+h.y*we.cos(u),t[_].position=t[_-1].position.add(h),d=t[_].velocity.multiplyByScaler(l),g=t[_].force.multiplyByScaler(l).multiplyByScaler(l),t[_].position=t[_].position.add(d).add(g),c=t[_].position.substract(t[_-1].position),c.normalize(),t[_].position=t[_-1].position.add(c.multiplyByScaler(t[_].radius)),we.abs(t[_].position.x)<a&&(t[_].position.x=0),0!=l&&(t[_].velocity=t[_].position.substract(t[_].lastPosition),t[_].velocity=t[_].velocity.divisionByScalar(l),t[_].velocity=t[_].velocity.multiplyByScaler(t[_].mobility)),t[_].force=new be(0,0),t[_].lastGravity=new be(p.x,p.y)}function Fs(t,e,i,r,s,a){let n=new be(0,0);t[0].position=new be(i.x,i.y);const o=we.degreesToRadian(r),l=we.radianToDirection(o);l.normalize();for(let u=1;u<e;++u)t[u].force=l.multiplyByScaler(t[u].acceleration).add(s),t[u].lastPosition=new be(t[u].position.x,t[u].position.y),t[u].velocity=new be(0,0),n=t[u].force,n.normalize(),n=n.multiplyByScaler(t[u].radius),t[u].position=t[u-1].position.add(n),we.abs(t[u].position.x)<a&&(t[u].position.x=0),t[u].force=new be(0,0),t[u].lastGravity=new be(l.x,l.y)}function Is(t,e,i,r,s){let a;a=r*s.getScale(s.translationScale,s.angleScale),a<e?(a<s.valueBelowMinimum&&(s.valueBelowMinimum=a),a=e):a>i&&(a>s.valueExceededMaximum&&(s.valueExceededMaximum=a),a=i);const n=s.weight/100;n>=1||(a=t[0]*(1-n)+a*n),t[0]=a}function Es(t,e,i,r,s,a,n,o){let l=0;const u=we.max(i,e);u<t&&(t=u);const h=we.min(i,e);h>t&&(t=h);const d=we.min(s,a),g=we.max(s,a),c=n,m=vs(h,u),p=t-m;switch(function(t){let e=0;return t>0?e=1:t<0&&(e=-1),e}(p)){case 1:{const t=u-m;0!=t&&(l=p*((g-c)/t),l+=c);break}case-1:{const t=h-m;0!=t&&(l=p*((d-c)/t),l+=c);break}case 0:l=c}return o?l:-1*l}var Vs;function Ls(){var t;null==(t=this.__moc)||t.release()}(t=>{t.CubismPhysics=ms,t.Options=ps})(Vs||(Vs={})),le.registerRuntime({version:4,ready:Sr,test:t=>t instanceof fr||fr.isValidJSON(t),isValidMoc(t){if(t.byteLength<4)return!1;const e=new Int8Array(t,0,4);return"MOC3"===String.fromCharCode(...e)},createModelSettings:t=>new fr(t),createCoreModel(t,e){const i=Ar.create(t,!!(null==e?void 0:e.checkMocConsistency));try{const t=i.createModel();return t.__moc=i,t}catch(r){try{i.release()}catch(s){_t.warn("CubismFactory","Failed to release moc after core model creation failed.",s)}throw r}},createInternalModel(t,e,i){const r=new hr(t,e,i),s=t;return s.__moc&&(r.__moc=s.__moc,delete s.__moc,r.once("destroy",Ls)),r},createPhysics(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism physics data must be an ArrayBuffer.");return ms.create(e,e.byteLength)},createPose(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism pose data must be an ArrayBuffer.");return Br.create(e,e.byteLength)}}),t.Constant=dt,t.CubismExpressionManager=Ge,t.CubismFramework=ct,t.CubismInternalModel=hr,t.CubismModelSettings=fr,t.CubismMotionManager=yi,t.CubismParallelMotionManager=Pi,t.ExpressionManager=Bt,t.FileLoader=ne,t.FocusController=It,t.InternalModel=Ut,t.LOGICAL_HEIGHT=2,t.LOGICAL_WIDTH=2,t.Live2DFactory=le,t.Live2DLoader=Ht,t.Live2DModel=ve,t.Live2DPlugin=Se,t.Live2DTransform=me,t.LogLevel=mt,t.MBToByte=yt,t.ModelSettings=Et,t.MotionManager=Ot,t.MotionPreloadStrategy=At,t.MotionPriority=Vt,t.MotionState=Lt,t.Option=class{},t.SoundManager=Dt,t.VERSION="1.2.1",t.VOLUME=Tt,t.XHRLoader=Gt,t.applyMixins=Mt,t.clamp=ft,t.config=pt,t.configureCubismSDK=Mr,t.copyArray=Ct,t.copyProperty=xt,t.csmDelete=gt,t.cubismReady=Sr,t.folderName=St,t.logger=_t,t.normalizeHitAreaDefs=kt,t.rand=function(t,e){return Math.random()*(e-t)+t},t.reconfigureCubismSDK=function(t={}){Mr(t),ct.isInitialized()&&ct.dispose(),ct.isStarted()&&ct.cleanUp(),vr(void 0,t.memorySizeMB)},t.remove=vt,t.resolveURL=Pt,t.startUpCubism=vr,t.strtod=nt,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});