untitled-pixi-live2d-engine 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cubism-legacy.es.js +27 -12
- package/dist/cubism-legacy.js +27 -12
- package/dist/cubism-legacy.min.js +1 -1
- package/dist/cubism.es.js +173 -31
- package/dist/cubism.js +173 -31
- package/dist/cubism.min.js +1 -1
- package/dist/index.es.js +173 -31
- package/dist/index.js +173 -31
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +12 -16
package/dist/index.min.js
CHANGED
|
@@ -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 s=Object.defineProperty,r=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?s(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((s,r)=>{var a=t=>{try{o(i.next(t))}catch(e){r(e)}},n=t=>{try{o(i.throw(t))}catch(e){r(e)}},o=t=>t.done?s(t.value):Promise.resolve(t.value).then(a,n);o((i=i.apply(t,e)).next())});const m={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: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"}))},p={log(t,...e){m.logLevel<=m.LOG_LEVEL_VERBOSE&&console.log(`[${t}]`,...e)},warn(t,...e){m.logLevel<=m.LOG_LEVEL_WARNING&&console.warn(`[${t}]`,...e)},error(t,...e){m.logLevel<=m.LOG_LEVEL_ERROR&&console.error(`[${t}]`,...e)}};function _(t,e,i){return t<e?e:t>i?i:t}function f(t,e){return Math.random()*(e-t)+t}function y(t){return 1024*t*1024}function x(t,e,i,s,r){const a=e[s];null!==a&&typeof a===t&&(i[r]=a)}function M(t,e,i,s,r){const a=e[s];Array.isArray(a)&&(i[r]=a.filter(e=>null!==e&&typeof e===t))}function C(t,e){e.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i))})})}function S(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 v(t,e){const i=t.indexOf(e);-1!==i&&t.splice(i,1)}const P=/^[a-zA-Z][a-zA-Z0-9+.-]*:/;function b(t,e){if(!e)return t;if(P.test(e))return e;if(e.startsWith("/"))return P.test(t)?new URL(e,t).toString():e;if(P.test(t))return new URL(e,t).toString();const i="http://example.com",s=t.startsWith("/")?i+t:`${i}/${t}`,r=new URL(e,s);let a=r.pathname+r.search+r.hash;return!t.startsWith("/")&&a.startsWith("/")&&(a=a.slice(1)),a}class B 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 p.warn(this.tag,`Undefined expression at [${t}]`);if(null===this.expressions[t])return void p.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 w=40/7.5,I=1/150;class F{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=_(t,-1,1),this.targetY=_(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 s=Math.sqrt(u(e,2)+u(i,2)),r=w/(1e3/t);let a=r*(e/s)-this.vx,n=r*(i/s)-this.vy;const o=Math.sqrt(u(a,2)+u(n,2)),l=r*I*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*s)-l);h>d&&(this.vx*=d/h,this.vy*=d/h),this.x+=this.vx,this.y+=this.vy}}class E{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=S(this.url)}normalizeName(){this.name&&"name"!==this.name.toLowerCase()||(this.name=S(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 b(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 s=this.resolveURL(e);if(!t.includes(s)){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 L=(t=>(t[t.NONE=0]="NONE",t[t.IDLE=1]="IDLE",t[t.NORMAL=2]="NORMAL",t[t.FORCE=3]="FORCE",t))(L||{});class V{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 p.log(this.tag,"Cannot start a motion with MotionPriority.NONE."),!1;if(t===this.currentGroup&&e===this.currentIndex)return p.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 p.log(this.tag,"Motion is already reserved.",this.dump(t,e)),!1;if(1===i){if(0!==this.currentPriority)return p.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(t,e)),!1;if(void 0!==this.reservedIdleGroup)return p.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 p.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 p.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,s){if(1===s){if(this.setReservedIdle(void 0,void 0),0!==this.currentPriority)return p.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 p.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,s),!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!m.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 T="SoundManager",R=.5;i.sound.disableAutoPause=!0;class D{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,s)=>{const r=i.Sound.from({url:t,volume:this._volume,preload:!0,loaded:()=>{r.media instanceof i.webaudio.WebAudioMedia||s(new Error(`Error: ${t} is not WebAudioMedia`)),e(r)}})});return yield e}catch(s){return p.warn(T,`Error occurred on "${t}"`,s),null==e||e(s),null}})}static play(t,e){t.play({singleInstance:!0,complete:()=>{null==e||e(),t.destroy()}})}static addAnalyzer(t,e){const i=t.media,s=e.createBufferSource();s.buffer=i.buffer;const r=e.createAnalyser();return r.fftSize=m.fftSize,r.minDecibels=-90,r.maxDecibels=-10,r.smoothingTimeConstant=.85,s.connect(r),s.start(0),this.analysers.push(r),r}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 s=Math.sqrt(i/e.length),r=20*Math.log10(s||u(10,-5)),a=Math.min(Math.max((r-t.minDecibels)/(t.maxDecibels-t.minDecibels),0),1);return parseFloat(a.toFixed(1))}static dispose(t){t.pause(),v(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=>{p.warn(T,"Failed to close AudioContext.",t)})}for(let t=this.audios.length-1;t>=0;t--)this.dispose(this.audios[t])}}g(D,"audios",[]),g(D,"analysers",[]),g(D,"contexts",[]),g(D,"_volume",R);var A=(t=>(t.ALL="ALL",t.IDLE="IDLE",t.NONE="NONE",t))(A||{});class O extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"settings"),g(this,"motionGroups",{}),g(this,"state",new V),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 p.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,s;if(this.destroyed)return;if(!this.getMotionDefinition(t,e))return;const r=null!=(s=(i=this.motionGroups)[t])?s:i[t]=[];if(null===r[e])return void p.warn(this.tag,`Cannot start motion at "${t}"[${e}] because it's already failed in loading.`);if(r[e])return r[e];const a=yield this._loadMotion(t,e);return this.destroyed?void 0:(r[e]=null!=a?a:null,a)})}_loadMotion(t,e){throw new Error("Not implemented.")}initializeAudio(t,e){this.currentAudio=t,D.volume=e,this.currentContext=t.context.audioContext,this.currentAnalyzer=D.addAnalyzer(this.currentAudio,this.currentContext)}speak(t){return c(this,arguments,function*(t,{volume:e=.5,expression:i,resetExpression:s=!0,onFinish:r,onError:a}={}){if(!m.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 D.add(u,(t,e=this)=>{p.error(this.tag,"Error during audio playback:",t),null==a||a(t),s&&i&&e.expressionManager&&e.expressionManager.resetExpression(),e.currentAudio=void 0}),this.initializeAudio(n,e)}catch(h){return p.warn(this.tag,"Failed to create audio",o,h),!1}if(n){let t=!0;try{m.motionSync&&D.play(n,()=>{null==r||r(),s&&i&&this.expressionManager&&this.expressionManager.resetExpression(),this.currentAudio=void 0})}catch(h){p.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=L.NORMAL,{sound:s,volume:r=.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!=L.FORCE)return!1;const h=this.getMotionDefinition(t,e);if(!h)return!1;let d,g;this.currentAudio&&D.dispose(this.currentAudio);const c=s&&s.startsWith("data:");if(s&&!c){const t=document.createElement("a");t.href=s,g=s=t.href}else g=this.getSoundFile(h),g&&(g=this.settings.resolveURL(g));const _=g;if(_)try{d=yield D.add(_,(t,e=this)=>{p.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,r)}catch(y){p.warn(this.tag,"Failed to create audio",g,y)}const f=yield this.loadMotion(t,e);if(d&&m.motionSync)try{D.play(d,(t=this)=>{null==o||o(),n&&a&&t.expressionManager&&t.expressionManager.resetExpression(),t.currentAudio=void 0})}catch(y){p.warn(this.tag,"Failed to play audio",d.url,y)}return this.state.start(f,t,e,i)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),p.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,f&&this._startMotion(f,void 0,u),!0):(d&&(D.dispose(d),this.currentAudio=void 0),!1)})}startRandomMotion(t,e){return c(this,arguments,function*(t,e,{sound:i,volume:s=.5,expression:r,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:s,expression:r,resetExpression:a,onFinish:n,onError:o})}}return!1})}stopSpeaking(){this.currentAudio&&(D.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,L.IDLE)),this.updateParameters(t,e)}mouthSync(){return this.currentAnalyzer?D.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,L.FORCE))return null;const s=this.getMotionDefinition(t,e);if(!s)return null;this.currentAudio&&D.dispose(this.currentAudio);const r=yield this.loadMotion(t,e);return this.state.start(r,t,e,L.FORCE)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),p.log(this.tag,"Start motion:",this.getMotionName(s)),this.emit("motionStart",t,e,void 0),i&&this.expressionManager&&this.state.shouldOverrideExpression()&&(yield this.expressionManager.setExpression(i)),r):null})}getMotionDefinition(t,e){var i,s;const r=null==(s=null==(i=this.definitions)?void 0:i[t])?void 0:s[e];return r||p.warn(this.tag,`Undefined motion at "${t}"[${e}]`),r}}function k(t,e){if(!Array.isArray(t))return[];const i=[];for(const s of t){if(!s||"object"!=typeof s)continue;const t=s,r="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;r&&a&&i.push({id:r,name:a,index:e(r)})}return i}const N={x:0,y:0,width:0,height:0};class U extends e.EventEmitter{constructor(){super(...arguments),g(this,"focusController",new F),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 s=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,r=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*s,-this.height*r)}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 s=this.hitAreas[t];if(!s)return!1;let r=s.index;if(r<0){if(!s.id)return!1;if(r=this.getDrawableIndex(s.id),r<0)return!1;s.index=r}const a=this.getDrawableBounds(r,N);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 s=i[0],r=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];s=Math.min(t,s),r=Math.max(t,r),a=Math.min(e,a),n=Math.max(e,n)}return null!=e||(e={}),e.x=s,e.y=a,e.width=r-s,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),s=this.parallelMotionManager.map(i=>i.update(t,e)),r=i||s.reduce((t,e)=>t||e,!1);return this.emit("afterMotionUpdate"),r}}class z extends Error{constructor(t,e,i,s=!1){super(t),this.url=e,this.status=i,this.aborted=s}}const j=class t{static createXHR(e,i,s,r,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=s,n.onload=()=>{var t;200!==n.status&&0!==n.status||!n.response?null==(t=n.onerror)||t.call(n,new ProgressEvent("error")):r(n.response)},n.onerror=()=>{p.warn("XHRLoader",`Failed to load resource as ${n.responseType} (Status ${n.status}): ${i}`),a(new z("Network error.",i,n.status))},n.onabort=()=>a(new z("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(j,"xhrMap",new WeakMap),g(j,"allXhrSet",new Set),g(j,"loader",t=>new Promise((e,i)=>{const s=t.target,r=t.target&&"function"==typeof j.cancelXHRs?j.cancelXHRs.bind(t.target):void 0,a=j.createXHR(t.target,t.settings?t.settings.resolveURL(t.url):t.url,t.type,i=>{t.result=i,e()},i);if(t.target&&r&&"function"==typeof s.listeners&&"function"==typeof s.once){const t=s.listeners("destroy");Array.isArray(t)&&t.includes(r)||s.once("destroy",r)}a.send()}));let G=j;function X(t,e){let i=-1;return function s(r,a){if(a)return Promise.reject(a);if(r<=i)return Promise.reject(new Error("next() called multiple times"));i=r;const n=t[r];if(!n)return Promise.resolve();try{return Promise.resolve(n(e,s.bind(null,r+1)))}catch(o){const t=o instanceof Error?o:new Error(String(o));return Promise.reject(t)}}(0)}class H{static load(t){return c(this,null,function*(){return yield X(this.middlewares,t),t.result})}}g(H,"middlewares",[G.loader]);class q extends E{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",{}),!q.isValidJSON(t))throw new TypeError("Invalid JSON.");this.moc=t.model,M("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){x("string",t,this,"name","name"),x("string",t,this,"pose","pose"),x("string",t,this,"physics","physics"),x("object",t,this,"layout","layout"),x("object",t,this,"motions","motions"),M("object",t,this,"hit_areas","hitAreas"),M("object",t,this,"expressions","expressions"),M("object",t,this,"init_params","initParams"),M("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 s=0;s<i.length;s++)i[s].file=t(i[s].file,`motions.${e}[${s}].file`),void 0!==i[s].sound&&(i[s].sound=t(i[s].sound,`motions.${e}[${s}].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 Y({lod:t,effectiveScale:e,textureWidth:i,textureHeight:s,lodScaleThreshold:r,lodTextureSizeThreshold:a,lodMaxLevel:n}){if("single-auto"!==W(t))return;if(!Number.isFinite(e)||e<=0)return;const o=Math.floor(i),l=Math.floor(s);if(o<=1||l<=1)return;if(e>=$(r,.5))return;const h=$(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 W(t){return!1===t||"single-auto"===t?t:"full"}function J(t){return"nearest"===t?"nearest":"linear"}function $(t,e){return void 0!==t&&Number.isFinite(t)&&t>0?t:e}function Z(){}const K="Live2DFactory",Q=(t,e)=>c(null,null,function*(){if("string"==typeof t.source){const e=yield H.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()}),tt=(t,e)=>c(null,null,function*(){if(t.source instanceof E)return t.settings=t.source,e();if("object"==typeof t.source){const i=lt.findRuntime(t.source);if(i){const s=i.createModelSettings(t.source);return t.settings=s,t.live2dModel.emit("settingsLoaded",s),e()}}const i=t.source&&"string"==typeof t.source.url?t.source.url:void 0,s=lt.runtimes.map(t=>t.version).join(", ");if(0===lt.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 r=(()=>{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.",s?`Registered runtimes (versions): ${s}`:void 0,r?`Settings JSON keys: ${r}`:void 0,i?`Settings URL: ${i}`:void 0].filter(Boolean).join("\n"))}),et=(t,e)=>{if(t.settings){const i=lt.findRuntime(t.settings);if(i)return i.ready().then(()=>e())}return e()},it=(t,e)=>c(null,null,function*(){yield e();const i=t.internalModel;if(i){const e=t.settings,s=lt.findRuntime(e);if(s){const r=[],a=e instanceof q?"json":"arraybuffer";e.pose&&r.push(H.load({settings:e,url:e.pose,type:a,target:i}).then(e=>{i.pose=s.createPose(i.coreModel,e),t.live2dModel.emit("poseLoaded",i.pose)}).catch(e=>{t.live2dModel.emit("poseLoadError",e),p.warn(K,"Failed to load pose.",e)})),e.physics&&r.push(H.load({settings:e,url:e.physics,type:a,target:i}).then(e=>{i.physics=s.createPhysics(i.coreModel,e),t.live2dModel.emit("physicsLoaded",i.physics)}).catch(e=>{t.live2dModel.emit("physicsLoadError",e),p.warn(K,"Failed to load physics.",e)})),r.length&&(yield Promise.all(r))}}}),st=(t,i)=>c(null,null,function*(){if(!t.settings)throw new TypeError("Missing settings.");{const s=t.live2dModel,r=d({crossOrigin:t.options.crossOrigin},t.options.textureOptions);t.settings instanceof q&&(r.preferCreateImageBitmap=!1);const a=Promise.all(t.settings.textures.map(i=>function(t,i={}){const s=e.loadTextures.config,r=null==s?void 0:s.crossOrigin,a=null==s?void 0:s.preferCreateImageBitmap,n=null==s?void 0:s.preferWorkers;return void 0!==i.crossOrigin&&s&&(s.crossOrigin=i.crossOrigin),!1===i.preferCreateImageBitmap&&s&&(s.preferCreateImageBitmap=!1,s.preferWorkers=!1),e.Assets.load({src:t,data:{autoGenerateMipmaps:"full"===W(i.lod)}}).catch(t=>{if(t instanceof Error)throw t;throw new Error("Texture loading error",{cause:t})}).finally(()=>{s&&(s.crossOrigin=null!=r?r:s.crossOrigin,!1===i.preferCreateImageBitmap&&(s.preferCreateImageBitmap=null!=a?a:s.preferCreateImageBitmap,s.preferWorkers=null!=n?n:s.preferWorkers))})}(t.settings.resolveURL(i),r)));if(a.catch(Z),yield i(),!t.internalModel)throw new TypeError("Missing internal model.");s.internalModel=t.internalModel,s.emit("modelLoaded",t.internalModel),s.textures=yield a,s.emit("textureLoaded",s.textures)}}),rt=(t,e)=>c(null,null,function*(){const i=t.settings;if(i instanceof E){const s=lt.findRuntime(i);if(!s)throw new TypeError("Unknown model settings.");const r=yield H.load({settings:i,url:i.moc,type:"arraybuffer",target:t.live2dModel});if(!s.isValidMoc(r))throw new Error("Invalid moc data");const a=s.createCoreModel(r);return t.internalModel=s.createInternalModel(a,i,t.options),e()}throw new TypeError("Missing settings.")}),at=class t{static resolveURL(e,i){var s;const r=null==(s=t.filesMap[e])?void 0:s[i];if(void 0===r)throw new Error("Cannot find this file from uploaded files: "+i);return r}static upload(e,i){const s={};for(const t of i.getDefinedFiles()){const r=decodeURI(b(i.url,t)),a=e.find(t=>t.webkitRelativePath===r);a&&(s[t]=URL.createObjectURL(a))}t.filesMap[i._objectURL]=s}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 s=yield t.readText(i),r=JSON.parse(s);r.url=i.webkitRelativePath;const a=lt.findRuntime(r);if(!a)throw new Error("Unknown settings JSON");const n=a.createModelSettings(r);return n._objectURL=URL.createObjectURL(i),n})}static readText(t){return c(this,null,function*(){return new Promise((e,i)=>{const s=new FileReader;s.onload=()=>e(s.result),s.onerror=i,s.readAsText(t,"utf8")})})}};g(at,"live2dFactory"),g(at,"filesMap",{}),g(at,"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 at.createSettings(e);i.validateFiles(e.map(t=>encodeURI(t.webkitRelativePath))),at.upload(e,i),i.resolveURL=function(t){return at.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),at.filesMap[t])for(const e of Object.values(at.filesMap[t]))URL.revokeObjectURL(e);delete at.filesMap[t]})})}return e()}));let nt=at;const ot=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,s){return c(this,null,function*(){const r=new Promise(t=>e.once("textureLoaded",t)),a=new Promise(t=>e.once("modelLoaded",t)),n=Promise.all([r,a]).then(()=>e.emit("ready"));yield X(t.live2DModelMiddlewares,{live2dModel:e,source:i,options:s||{}}),yield n,e.emit("load")})}static loadMotion(e,i,s){var r;const a=t=>e.emit("motionLoadError",i,s,t);try{const n=null==(r=e.definitions[i])?void 0:r[s];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[s]||(l[s]=H.load({url:u,settings:e.settings,type:e.motionDataType,target:e}).then(r=>{var a;const o=null==(a=t.motionTasksMap.get(e))?void 0:a[i];o&&(o[s]=void 0);const l=r,u=e.createMotion(l,i,n);return e.emit("motionLoaded",i,s,u),u}).catch(t=>{p.warn(e.tag,`Failed to load motion: ${u}\n`,t),a(t)})),l[s]}catch(n){p.warn(e.tag,`Failed to load motion at "${i}"[${s}]\n`,n),a(n)}return Promise.resolve(void 0)}static loadExpression(e,i){var s;const r=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!=(s=e.expressionDataType)?s:"json";return null!=n[i]||(n[i]=H.load({url:o,settings:e.settings,type:l,target:e}).then(s=>{const r=t.expressionTasksMap.get(e);r&&(r[i]=void 0);const n=s,o=e.createExpression(n,a);return e.emit("expressionLoaded",i,o),o}).catch(t=>{p.warn(e.tag,`Failed to load expression: ${o}\n`,t),r(t)})),n[i]}catch(a){p.warn(e.tag,`Failed to load expression at [${i}]\n`,a),r(a)}return Promise.resolve(void 0)}static releaseMotionTasks(e){t.motionTasksMap.delete(e)}static releaseExpressionTasks(e){t.expressionTasksMap.delete(e)}};g(ot,"runtimes",[]),g(ot,"urlToJSON",Q),g(ot,"jsonToSettings",tt),g(ot,"waitUntilReady",et),g(ot,"setupOptionals",it),g(ot,"setupEssentials",st),g(ot,"createInternalModel",rt),g(ot,"live2DModelMiddlewares",[nt.factory,Q,tt,et,it,st,rt]),g(ot,"motionTasksMap",new WeakMap),g(ot,"expressionTasksMap",new WeakMap);let lt=ot;O.prototype._loadMotion=function(t,e){return lt.loadMotion(this,t,e)},B.prototype._loadExpression=function(t){return lt.loadExpression(this,t)},nt.live2dFactory=lt;const ut=class t{constructor(i,{autoUpdate:s=!0,autoHitTest:r=!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&&(r=n,a=n,p.warn(i.tag,"options.autoInteract is deprecated since v0.5.0, use autoHitTest and autoFocus instead.")),this.model=i,this.ticker=o,this.autoUpdate=s,this.autoHitTest=r,this.autoFocus=a,(r||a)&&(this.model.eventMode="static")}get ticker(){return this._ticker}set ticker(t){var e,i;this._ticker&&this._ticker.remove(dt,this),this._ticker=t,this._autoUpdate&&(null==(e=this._ticker)||e.add(dt,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(dt,this),this._autoUpdate=!0):p.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(dt,this),this._autoUpdate=!1))}get autoHitTest(){return this._autoHitTest}set autoHitTest(t){t!==this.autoHitTest&&(t?this.model.on("pointertap",gt,this):this.model.off("pointertap",gt,this),this._autoHitTest=t)}get autoFocus(){return this._autoFocus}set autoFocus(t){t!==this.autoFocus&&(t?(this.model.on("globalpointermove",ct,this),this.model.on("pointermove",ct,this)):(this.model.off("globalpointermove",ct,this),this.model.off("pointermove",ct,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(ut,"defaultTicker");let ht=ut;function dt(){this.onTickerUpdate()}function gt(t){this.onTap(t)}function ct(t){this.onPointerMove(t)}class mt extends e.Transform{}const pt=new e.Point,_t=new e.Matrix,ft=new e.Matrix,yt={x:0,y:0,width:0,height:0},xt=new e.Bounds;let Mt=!1;class Ct{constructor(t){this.renderer=t}addRenderable(t,e){var i,s;null==(s=null==(i=this.renderer.renderPipes.batch)?void 0:i.break)||s.call(i,e),e.add(t)}execute(t){!t.visible||t.alpha<=0||t.renderLive2D(this.renderer)}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}destroy(){}}g(Ct,"extension",{type:[e.ExtensionType.WebGLPipes],name:"live2d"});const St=Ct;class vt 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 mt),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,s,r,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=ft.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 s=this.resolveTextureForRender(e,i,g);try{this.uploadTextureForRender(t,s,o)}catch(C){if(s===i)throw new Error("Failed to upload Live2D texture.");const r=this.textureLODStates[e];(null==r?void 0:r.texture)===s&&(this.markTextureLODFailure(e,i,r.level),this.destroyTextureLODState(e)),s=i,this.uploadTextureForRender(t,s,o)}this.internalModel.bindTexture(e,t.texture.getGlSource(s.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!=(s=null==u?void 0:u.y)?s:0;const y=_t.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==(r=t.renderTarget)?void 0:r.defaultClearColor,M=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]),M&&(M[0]=x[0],M[1]=x[1],M[2]=x[2],M[3]=x[3]))}),this.textureOptions=null==t?void 0:t.textureOptions,this.anchor=new e.ObservablePoint({_onUpdate:()=>this.onAnchorChange()},0,0),this.automator=new ht(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 lt.setupLive2DModel(i,t,e),i})}static fromSync(t,e){const i=new this(e);return lt.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){ht.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();xt.clear();for(let i=0;i<t.length;i++){const s=t[i],r=this.internalModel.getDrawableIndex(s);if(r<0)continue;const a=this.internalModel.getDrawableBounds(r,yt);Number.isFinite(a.x)&&Number.isFinite(a.y)&&Number.isFinite(a.width)&&Number.isFinite(a.height)&&xt.addFrame(a.x,a.y,a.x+a.width,a.y+a.height,e.Matrix.IDENTITY)}if(this._bounds.clear(),xt.isValid&&xt.isPositive)this._bounds.addFrame(xt.minX,xt.minY,xt.maxX,xt.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 s,r,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||(Mt||(Mt=!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 Ct(t))}(e);const o=e.renderPipes,l=()=>{o.live2d.addRenderable(this,t)},u=()=>{const s=this.children,r=s.length;for(let a=0;a<r;a++)s[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==(r=null==(s=o[i.pipe])?void 0:s.push)||r.call(s,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:s,volume:r=.5,expression:a,resetExpression:n=!0,onFinish:o,onError:l}={}){return void 0===e?this.internalModel.motionManager.startRandomMotion(t,i,{sound:s,volume:r,expression:a,resetExpression:n,onFinish:o,onError:l}):this.internalModel.motionManager.startMotion(t,e,i,{sound:s,volume:r,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:s=!0,onFinish:r,onError:a}={}){return this.internalModel.motionManager.speak(t,{volume:e,expression:i,resetExpression:s,onFinish:r,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){pt.x=t,pt.y=e,this.toModelPosition(pt,pt,!0);const s=pt.x/this.internalModel.originalWidth*2-1,r=pt.y/this.internalModel.originalHeight*2-1,a=Math.atan2(r,s);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 pt.x=t,pt.y=e,this.toModelPosition(pt,pt),this.internalModel.hitTest(pt.x,pt.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,s){var n;const o=Y((l=d({},this.textureOptions),u={effectiveScale:s,textureWidth:i.source.pixelWidth,textureHeight:i.source.pixelHeight},r(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,s,r,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(s,r),h=u.getContext("2d");if(!h)return;try{h.clearRect(0,0,s,r),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,s,r)}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:s,height:r,resolution:1,scaleMode:J(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 s=this.textureLODFailures[t];(null==s?void 0:s.source)!==e&&(s={source:e,levels:new Set},this.textureLODFailures[t]=s),s.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 s=Boolean(e.source._gpuData[t.uid]);!i&&s||(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(!("Live2D"in window))throw new Error("Could not find Cubism 2 runtime. This plugin requires live2d.min.js to be loaded.");const Pt=Live2DMotion.prototype.updateParam;Live2DMotion.prototype.updateParam=function(t,e){Pt.call(this,t,e),e.isFinished()&&this.onFinishHandler&&(this.onFinishHandler(this),delete this.onFinishHandler)};class bt extends AMotion{constructor(t){super(),g(this,"params",[]),this.setFadeIn(t.fade_in>0?t.fade_in:m.expressionFadingDuration),this.setFadeOut(t.fade_out>0?t.fade_out:m.expressionFadingDuration),Array.isArray(t.params)&&t.params.forEach(t=>{const e=t.calc||"add";if("add"===e){const e=t.def||0;t.val-=e}else if("mult"===e){const e=t.def||1;t.val/=e}this.params.push({calc:e,val:t.val,id:t.id})})}updateParamExe(t,e,i,s){this.params.forEach(e=>{t.setParamFloat(e.id,e.val*i)})}}class Bt extends B{constructor(t,e){var i;super(t,e),g(this,"queueManager",new MotionQueueManager),g(this,"definitions"),this.definitions=null!=(i=this.settings.expressions)?i:[],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 new bt(t)}_setExpression(t){return this.queueManager.startMotion(t)}stopAllExpressions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}}function wt(t,e,i){const s=i.getDurationMSec(),r=t.startMotion(i,!0),a=t.motions.find(t=>!!t&&t._$sr===r);return!!a&&(i.updateParamExe(e.coreModel,s,1,a),!0)}class It extends O{constructor(t){super(t),g(this,"definitions"),g(this,"groups",{idle:"idle"}),g(this,"motionDataType","arraybuffer"),g(this,"queueManager",new MotionQueueManager),g(this,"lipSyncIds"),g(this,"expressionManager"),this.definitions=this.settings.motions,this.init(t.options),this.lipSyncIds=["PARAM_MOUTH_OPEN_Y"]}init(t){super.init(t),this.settings.expressions&&(this.expressionManager=new Bt(this.settings,t))}isFinished(){return this.queueManager.isFinished()}createMotion(t,e,i){const s=Live2DMotion.loadMotion(t),r=e===this.groups.idle?m.idleMotionFadingDuration:m.motionFadingDuration;return s.setFadeIn(i.fade_in>0?i.fade_in:r),s.setFadeOut(i.fade_out>0?i.fade_out:r),s}getMotionFile(t){return t.file}getMotionName(t){return t.file}getSoundFile(t){return t.sound}_startMotion(t,e,i){return t.onFinishHandler=e,i&&i.length>0&&(t.motions=t.motions.filter(t=>!i.includes(t._$4P))),this.queueManager.stopAllMotions(),this.queueManager.startMotion(t)}_stopAllMotions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}destroy(){super.destroy(),this.queueManager=void 0}motionLastFrame(t,e){return c(this,arguments,function*(t,e,{expression:i}={}){const s=yield this.getMotionAndApplyExpression(t,e,i);return!!s&&(this.playing=!0,wt(this.queueManager,this.parent,s),this.playing=!1,!0)})}}class Ft extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"manager"),g(this,"settings"),g(this,"state",new V),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=L.NORMAL,s=[]){var r;if(!this.state.reserve(t,e,i))return!1;const a=null==(r=this.manager.definitions[t])?void 0:r[e];if(!a)return!1;const n=yield this.manager.loadMotion(t,e);return!!this.state.start(n,t,e,i)&&(p.log(this.tag,"Start motion:",this.getMotionName(a)),this.emit("motionStart",t,e,void 0),this.playing=!0,this._startMotion(n,void 0,s),!0)})}startRandomMotion(t,e){return c(this,null,function*(){var i;const s=this.manager.definitions[t];if(null==s?void 0:s.length){const r=[],a=null!=(i=this.manager.motionGroups[t])?i:[];for(let e=0;e<s.length;e++)null===a[e]||this.state.isActive(t,e)||r.push(e);if(r.length){const i=r[Math.floor(Math.random()*r.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 Et extends Ft{constructor(t){super(t),g(this,"queueManager",new MotionQueueManager)}isFinished(){return this.queueManager.isFinished()}getMotionName(t){return t.file}_startMotion(t,e,i){return t.onFinishHandler=e,i&&i.length>0&&(t.motions=t.motions.filter(t=>!i.includes(t._$4P))),this.queueManager.stopAllMotions(),this.queueManager.startMotion(t)}_stopAllMotions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}destroy(){super.destroy(),this.queueManager=void 0}playMotionLastFrame(t,e){return c(this,null,function*(){var i;if(!this.state.reserve(t,e,L.FORCE))return!1;const s=null==(i=this.manager.definitions[t])?void 0:i[e];if(!s)return!1;const r=yield this.manager.loadMotion(t,e);return!!this.state.start(r,t,e,L.FORCE)&&(p.log(this.tag,"Start motion:",this.getMotionName(s)),this.queueManager.stopAllMotions(),this.emit("motionStart",t,e,void 0),this.playing=!0,!!wt(this.queueManager,this.parent,r)&&(this.playing=!1,!0))})}}class Lt{constructor(t){g(this,"leftParam"),g(this,"rightParam"),g(this,"blinkInterval",4e3),g(this,"closingDuration",100),g(this,"closedDuration",50),g(this,"openingDuration",150),g(this,"eyeState",0),g(this,"eyeParamValue",1),g(this,"closedTimer",0),g(this,"nextBlinkTimeLeft",this.blinkInterval),this.coreModel=t,this.leftParam=t.getParamIndex("PARAM_EYE_L_OPEN"),this.rightParam=t.getParamIndex("PARAM_EYE_R_OPEN")}setEyeParams(t){this.eyeParamValue=_(t,0,1),this.coreModel.setParamFloat(this.leftParam,this.eyeParamValue),this.coreModel.setParamFloat(this.rightParam,this.eyeParamValue)}update(t){switch(this.eyeState){case 0:this.nextBlinkTimeLeft-=t,this.nextBlinkTimeLeft<0&&(this.eyeState=1,this.nextBlinkTimeLeft=this.blinkInterval+this.closingDuration+this.closedDuration+this.openingDuration+f(0,2e3));break;case 1:this.setEyeParams(this.eyeParamValue+t/this.closingDuration),this.eyeParamValue<=0&&(this.eyeState=2,this.closedTimer=0);break;case 2:this.closedTimer+=t,this.closedTimer>=this.closedDuration&&(this.eyeState=3);break;case 3:this.setEyeParams(this.eyeParamValue+t/this.openingDuration),this.eyeParamValue>=1&&(this.eyeState=0)}}}const Vt=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);class Tt extends U{constructor(t,e,i){super(),g(this,"settings"),g(this,"options"),g(this,"coreModel"),g(this,"motionManager"),g(this,"parallelMotionManager"),g(this,"eyeBlink"),g(this,"eyeballXParamIndex"),g(this,"eyeballYParamIndex"),g(this,"angleXParamIndex"),g(this,"angleYParamIndex"),g(this,"angleZParamIndex"),g(this,"bodyAngleXParamIndex"),g(this,"breathParamIndex"),g(this,"textureFlipY",!0),g(this,"lipSync",!0),g(this,"drawDataCount",0),g(this,"disableCulling",!1),g(this,"hasDrawn",!1),g(this,"customHitAreas"),this.coreModel=t,this.settings=e,this.options=Object.assign({},{breathDepth:1,lipSyncGain:1.5,lipSyncWeight:.4},i),void 0!==(null==i?void 0:i.useHighPrecisionMask)&&!1!==i.useHighPrecisionMask&&p.warn("CubismLegacyInternalModel","`useHighPrecisionMask` is only supported by Cubism 3/4/5 models and will be ignored for Cubism 2 models."),this.motionManager=new It(this),this.parallelMotionManager=[],this.eyeBlink=new Lt(t),this.eyeballXParamIndex=t.getParamIndex("PARAM_EYE_BALL_X"),this.eyeballYParamIndex=t.getParamIndex("PARAM_EYE_BALL_Y"),this.angleXParamIndex=t.getParamIndex("PARAM_ANGLE_X"),this.angleYParamIndex=t.getParamIndex("PARAM_ANGLE_Y"),this.angleZParamIndex=t.getParamIndex("PARAM_ANGLE_Z"),this.bodyAngleXParamIndex=t.getParamIndex("PARAM_BODY_ANGLE_X"),this.breathParamIndex=t.getParamIndex("PARAM_BREATH"),this.init()}init(){super.init(),this.settings.initParams&&this.settings.initParams.forEach(({id:t,value:e})=>this.coreModel.setParamFloat(t,e)),this.settings.initOpacities&&this.settings.initOpacities.forEach(({id:t,value:e})=>this.coreModel.setPartsOpacity(t,e)),this.coreModel.saveParam();const t=this.coreModel.getModelContext()._$aS;(null==t?void 0:t.length)&&(this.drawDataCount=t.length);let e=this.coreModel.drawParamWebGL.culling;Object.defineProperty(this.coreModel.drawParamWebGL,"culling",{set:t=>e=t,get:()=>!this.disableCulling&&e});const i=this.coreModel.getModelContext().clipManager,s=i.setupClip.bind(i);i.setupClip=(t,e)=>{s.call(i,t,e),e.gl.viewport(...this.viewport)}}getSize(){return[this.coreModel.getCanvasWidth(),this.coreModel.getCanvasHeight()]}getLayout(){const t={};if(this.settings.layout)for(const[e,i]of Object.entries(this.settings.layout)){let s=e;"center_x"===e?s="centerX":"center_y"===e&&(s="centerY"),"number"==typeof i&&(t[s]=i)}return t}updateWebGLContext(t,e){const i=this.coreModel.drawParamWebGL;i.firstDraw=!0,i.setGL(t),i.glno=e,i._$NT=null,i._$no=null,i._$vS=null;const s=this.coreModel.getModelContext().clipManager;s.curFrameNo=e;const r=t.getParameter(t.FRAMEBUFFER_BINDING);s.getMaskRenderTexture(),t.bindFramebuffer(t.FRAMEBUFFER,r)}bindTexture(t,e){this.coreModel.setTexture(t,e)}getHitAreaDefs(){var t,e,i;const s=this.settings.json;return k(null!=(i=null!=(e=null!=(t=this.settings.hitAreas)?t:s.hit_areas)?e:s.HitAreas)?i:s.hitAreas,t=>this.coreModel.getDrawDataIndex(t))}getDrawableIDs(){const t=this.coreModel.getModelContext(),e=[];for(let i=0;i<this.drawDataCount;i++){const s=t.getDrawData(i);s&&e.push(s.getDrawDataID().id)}return e}getDrawableIndex(t){return this.coreModel.getDrawDataIndex(t)}getDrawableVertices(t){if("string"==typeof t&&-1===(t=this.coreModel.getDrawDataIndex(t)))throw new TypeError("Unable to find drawable ID: "+t);return this.coreModel.getTransformedPoints(t).slice()}hitTest(t,e){this.hasDrawn||p.warn("Trying to hit-test a Cubism 2 model that has not been rendered yet. Drawable hit areas may be empty until the first draw.");const i=super.hitTest(t,e),s=this.hitTestCustom(t,e);return s.length?i.length?[...new Set([...i,...s])]:s:i}update(t,e){var i,s,r,a;super.update(t,e);const n=this.coreModel,o=this.updateMotions(n,e);if(n.saveParam(),null==(i=this.motionManager.expressionManager)||i.update(n,e),o||null==(s=this.eyeBlink)||s.update(t),this.updateFocus(),this.updateNaturalMovements(t,e),this.lipSync&&this.motionManager.currentAudio){let t=this.motionManager.mouthSync()*this.options.lipSyncGain;const e=1,i=t>0?.1:0;t=Math.pow(t,1.15),t=_(t,i,e);for(let s=0;s<this.motionManager.lipSyncIds.length;++s)this.coreModel.addToParamFloat(this.coreModel.getParamIndex(this.motionManager.lipSyncIds[s]),t,this.options.lipSyncWeight)}null==(r=this.physics)||r.update(e),null==(a=this.pose)||a.update(t),this.emit("beforeModelUpdate"),n.update(),n.loadParam()}updateFocus(){this.coreModel.addToParamFloat(this.eyeballXParamIndex,this.focusController.x),this.coreModel.addToParamFloat(this.eyeballYParamIndex,this.focusController.y),this.coreModel.addToParamFloat(this.angleXParamIndex,30*this.focusController.x),this.coreModel.addToParamFloat(this.angleYParamIndex,30*this.focusController.y),this.coreModel.addToParamFloat(this.angleZParamIndex,this.focusController.x*this.focusController.y*-30),this.coreModel.addToParamFloat(this.bodyAngleXParamIndex,10*this.focusController.x)}updateNaturalMovements(t,e){const i=e/1e3*2*Math.PI;this.coreModel.addToParamFloat(this.angleXParamIndex,15*this.options.breathDepth*Math.sin(i/6.5345)*.5),this.coreModel.addToParamFloat(this.angleYParamIndex,8*this.options.breathDepth*Math.sin(i/3.5345)*.5),this.coreModel.addToParamFloat(this.angleZParamIndex,10*this.options.breathDepth*Math.sin(i/5.5345)*.5),this.coreModel.addToParamFloat(this.bodyAngleXParamIndex,4*this.options.breathDepth*Math.sin(i/15.5345)*.5),this.coreModel.setParamFloat(this.breathParamIndex,.5+.5*Math.sin(i/3.2345))}draw(t){const e=this.disableCulling;t.getParameter(t.FRAMEBUFFER_BINDING)&&(this.disableCulling=!0);const i=this.drawingMatrix;Vt[0]=i.a,Vt[1]=i.b,Vt[4]=i.c,Vt[5]=i.d,Vt[12]=i.tx,Vt[13]=i.ty,this.coreModel.setMatrix(Vt),this.coreModel.draw(),this.hasDrawn=!0,this.disableCulling=e}extendParallelMotionManager(t){for(;this.parallelMotionManager.length<t;)this.parallelMotionManager.push(new Et(this))}destroy(){super.destroy(),this.coreModel=void 0}hitTestCustom(t,e){const i=this.getCustomHitAreas();if(!i)return[];const s=this.originalWidth||this.width,r=this.originalHeight||this.height;if(!s||!r)return[];const a=t/s*2-1,n=1-e/r*2,o=[];for(const[l,u]of Object.entries(i))a>=u.minX&&a<=u.maxX&&n>=u.minY&&n<=u.maxY&&o.push(l);return o}getCustomHitAreas(){var t,e,i,s,r;if(void 0!==this.customHitAreas)return this.customHitAreas;const a=this.settings.json,n=null!=(i=null!=(e=null!=(t=a.hit_areas_custom)?t:a.hitAreasCustom)?e:a.HitAreasCustom)?i:a.HitAreas_Custom;if(!n||"object"!=typeof n)return this.customHitAreas=null,null;const o=n,l={},u=(t,e,i)=>{if(!t||!Array.isArray(e)||!Array.isArray(i))return;if(e.length<2||i.length<2)return;const s=Number(e[0]),r=Number(e[1]),a=Number(i[0]),n=Number(i[1]);Number.isFinite(s)&&Number.isFinite(r)&&Number.isFinite(a)&&Number.isFinite(n)&&(l[t]={minX:Math.min(s,r),maxX:Math.max(s,r),minY:Math.min(a,n),maxY:Math.max(a,n)})};for(const[h,d]of Object.entries(o)){if(h.endsWith("_x")){const t=h.slice(0,-2);u(t,d,o[`${t}_y`]);continue}if(!h.endsWith("_y")&&(d&&"object"==typeof d)){const t=d;u(h,null!=(s=t.x)?s:t.X,null!=(r=t.y)?r:t.Y)}}return this.customHitAreas=Object.keys(l).length?l:null,this.customHitAreas}}const Rt={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE},Dt={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE};class At{constructor(t,e){g(this,"physicsHairs",[]),this.coreModel=t,e.physics_hair&&(this.physicsHairs=e.physics_hair.map(t=>{const e=new PhysicsHair;return e.setup(t.setup.length,t.setup.regist,t.setup.mass),t.src.forEach(({id:t,ptype:i,scale:s,weight:r})=>{const a=Rt[i];a&&e.addSrcParam(a,t,s,r)}),t.targets.forEach(({id:t,ptype:i,scale:s,weight:r})=>{const a=Dt[i];a&&e.addTargetParam(a,t,s,r)}),e}))}update(t){this.physicsHairs.forEach(e=>e.update(this.coreModel,t))}}class Ot{constructor(t){g(this,"paramIndex",-1),g(this,"partsIndex",-1),g(this,"link",[]),this.id=t}initIndex(t){this.paramIndex=t.getParamIndex("VISIBLE:"+this.id),this.partsIndex=t.getPartsDataIndex(PartsDataID.getID(this.id)),t.setParamFloat(this.paramIndex,1)}}class kt{constructor(t,e){g(this,"opacityAnimDuration",500),g(this,"partsGroups",[]),this.coreModel=t,e.parts_visible&&(this.partsGroups=e.parts_visible.map(({group:t})=>t.map(({id:t,link:e})=>{const i=new Ot(t);return e&&(i.link=e.map(t=>new Ot(t))),i})),this.init())}init(){this.partsGroups.forEach(t=>{t.forEach(t=>{if(t.initIndex(this.coreModel),t.paramIndex>=0){const e=0!==this.coreModel.getParamFloat(t.paramIndex);this.coreModel.setPartsOpacity(t.partsIndex,e?1:0),this.coreModel.setParamFloat(t.paramIndex,e?1:0),t.link.length>0&&t.link.forEach(t=>t.initIndex(this.coreModel))}})})}normalizePartsOpacityGroup(t,e){const i=this.coreModel,s=.5;let r=1,a=t.findIndex(({paramIndex:t,partsIndex:e})=>e>=0&&0!==i.getParamFloat(t));if(a>=0){const s=i.getPartsOpacity(t[a].partsIndex);r=_(s+e/this.opacityAnimDuration,0,1)}else a=0,r=1;t.forEach(({partsIndex:t},e)=>{if(t>=0)if(a==e)i.setPartsOpacity(t,r);else{let e,a=i.getPartsOpacity(t);e=r<s?-.5*r/s+1:(1-r)*s/.5;(1-e)*(1-r)>.15&&(e=1-.15/(1-r)),a>e&&(a=e),i.setPartsOpacity(t,a)}})}copyOpacity(t){const e=this.coreModel;t.forEach(({partsIndex:t,link:i})=>{if(t>=0&&i){const s=e.getPartsOpacity(t);i.forEach(({partsIndex:t})=>{t>=0&&e.setPartsOpacity(t,s)})}})}update(t){this.partsGroups.forEach(e=>{this.normalizePartsOpacityGroup(e,t),this.copyOpacity(e)})}}if(lt.registerRuntime({version:2,test:t=>t instanceof q||q.isValidJSON(t),ready:()=>Promise.resolve(),isValidMoc(t){if(t.byteLength<3)return!1;const e=new Int8Array(t,0,3);return"moc"===String.fromCharCode(...e)},createModelSettings:t=>new q(t),createCoreModel(t){const e=Live2DModelWebGL.loadModel(t),i=Live2D.getError();if(i){if(i instanceof Error)throw i;const t="string"==typeof i?i:`Live2D error: ${JSON.stringify(i)}`;throw new Error(t)}return e},createInternalModel:(t,e,i)=>new Tt(t,e,i),createPose:(t,e)=>new kt(t,e),createPhysics:(t,e)=>new At(t,e)}),"undefined"==typeof window||void 0===window.Live2DCubismCore)throw new Error("Could not find Cubism runtime. This plugin requires live2dcubismcore.js to be loaded.");const Nt=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 s=this._size;s<t;s++)this._ptr[s]="function"==typeof e?JSON.parse(JSON.stringify(new e)):e;else for(let s=this._size;s<t;s++)this._ptr[s]=e;else{const e=this._size-t;this._ptr.splice(this._size-e,e)}this._size=t}insert(t,e,i){let s=t._index;const r=e._index,a=i._index,n=a-r;this.prepareCapacity(this._size+n);const o=this._size-s;if(o>0)for(let l=0;l<o;l++)this._ptr.splice(s+l,0,null);for(let l=r;l<a;l++,s++)this._ptr[s]=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 zt(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 zt(this,0)}end(){return new zt(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}};Nt.DefaultSize=10;let Ut=Nt,zt=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 jt,Gt,Xt,Ht,qt,Yt,Wt;(Gt=jt||(jt={})).csmVector=Ut,Gt.iterator=zt;class Jt{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=Jt})(Xt||(Xt={}));class $t{static createIdInternal(t){return new $t(t)}getString(){return this._id}isEqual(t){return"string"==typeof t?this._id.isEqual(t):t instanceof Jt?this._id.isEqual(t.s):t instanceof $t&&this._id.isEqual(t._id.s)}isNotEqual(t){return"string"==typeof t?!this._id.isEqual(t):t instanceof Jt?!this._id.isEqual(t.s):t instanceof $t&&!this._id.isEqual(t._id.s)}constructor(t){this._id="string"!=typeof t?t:new Jt(t)}}(t=>{t.CubismId=$t})(Ht||(Ht={}));class Zt{constructor(){this._ids=new Ut}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=$t.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=Zt})(qt||(qt={}));class Kt{constructor(){this._tr=new Float32Array(16),this.loadIdentity()}static multiply(t,e,i){const s=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);for(let r=0;r<4;++r)for(let i=0;i<4;++i)for(let a=0;a<4;++a)s[i+4*r]+=t[a+4*r]*e[i+4*a];for(let r=0;r<16;++r)i[r]=s[r]}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]);Kt.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]);Kt.multiply(i,this._tr,this._tr)}scale(t,e){this._tr[0]=t,this._tr[5]=e}multiplyByMatrix(t){Kt.multiply(t.getArray(),this._tr,this._tr)}clone(){const t=new Kt;for(let e=0;e<this._tr.length;e++)t._tr[e]=this._tr[e];return t}}(t=>{t.CubismMatrix44=Kt})(Yt||(Yt={}));class Qt{constructor(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s}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=Qt})(Wt||(Wt={}));class te{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,s){t<0?t=0:t>1&&(t=1),e<0?e=0:e>1&&(e=1),i<0?i=0:i>1&&(i=1),s<0?s=0:s>1&&(s=1),this._modelColor.r=t,this._modelColor.g=e,this._modelColor.b=i,this._modelColor.a=s}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 se,this._useHighPrecisionMask=!1,this._mvpMatrix4x4=new Kt,this._mvpMatrix4x4.loadIdentity()}}var ee,ie=(t=>(t[t.CubismBlendMode_Normal=0]="CubismBlendMode_Normal",t[t.CubismBlendMode_Additive=1]="CubismBlendMode_Additive",t[t.CubismBlendMode_Multiplicative=2]="CubismBlendMode_Multiplicative",t))(ie||{});class se{constructor(t=1,e=1,i=1,s=1){this.r=t,this.g=e,this.b=i,this.a=s}}class re{constructor(t,e){this._clippingIdList=t,this._clippingIdCount=e,this._allClippedDrawRect=new Qt,this._layoutBounds=new Qt,this._clippedDrawableIndexList=[],this._matrixForMask=new Kt,this._matrixForDraw=new Kt,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=ie,t.CubismRenderer=te,t.CubismTextureColor=se})(ee||(ee={}));const ae=(t,e,i)=>{((t,e,i)=>{de.print(t,"[CSM]"+e,i)})(t,e+"\n",i)},ne=t=>{console.assert(t)};let oe,le,ue,he;oe=(t,...e)=>{ae(Ue.LogLevel_Debug,"[D]"+t,e)},le=(t,...e)=>{ae(Ue.LogLevel_Info,"[I]"+t,e)},ue=(t,...e)=>{ae(Ue.LogLevel_Warning,"[W]"+t,e)},he=(t,...e)=>{ae(Ue.LogLevel_Error,"[E]"+t,e)};class de{static print(t,e,i){if(t<Oe.getLoggingLevel())return;const s=Oe.coreLogFunction;if(!s)return;s(e.replace(/\{(\d+)\}/g,(t,e)=>i[e]))}static dumpBytes(t,e,i){for(let s=0;s<i;s++)s%16==0&&s>0?this.print(t,"\n"):s%8==0&&s>0&&this.print(t," "),this.print(t,"{0} ",[255&e[s]]);this.print(t,"\n")}constructor(){}}var ge;(t=>{t.CubismDebug=de})(ge||(ge={}));class ce{constructor(t,e){this.first=null==t?null:t,this.second=null==e?null:e}}const me=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 ce(t),this._size+=1):ue("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 s=0;s<this._size;s++)if(this._keyValues[s].first==t){i=s;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 _e(this,0)}end(){return new _e(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 _e(this,e)}dumpAsInt(){for(let t=0;t<this._size;t++)oe("{0} ,",this._keyValues[t]),oe("\n")}};me.DefaultSize=10;let pe=me;class _e{constructor(t,e){this._map=null!=t?t:new pe,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 _e(this._map,this._index++)}decrement(){const t=new _e(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 fe;(t=>{t.csmMap=pe,t.csmPair=ce,t.iterator=_e})(fe||(fe={}));class ye{static parseJsonObject(t,e){return Object.keys(t).forEach(i=>{if("boolean"==typeof t[i]){const s=Boolean(t[i]);e.put(i,new ve(s))}else if("string"==typeof t[i]){const s=String(t[i]);e.put(i,new Pe(s))}else if("number"==typeof t[i]){const s=Number(t[i]);e.put(i,new Se(s))}else t[i]instanceof Array?e.put(i,ye.parseJsonArray(t[i])):t[i]instanceof Object?e.put(i,ye.parseJsonObject(t[i],new Ie)):null==t[i]?e.put(i,new Be):e.put(i,t[i])}),e}static parseJsonArray(t){const e=new we;return Object.keys(t).forEach(i=>{if("number"==typeof Number(i))if("boolean"==typeof t[i]){const s=Boolean(t[i]);e.add(new ve(s))}else if("string"==typeof t[i]){const s=String(t[i]);e.add(new Pe(s))}else if("number"==typeof t[i]){const s=Number(t[i]);e.add(new Se(s))}else t[i]instanceof Array?e.add(this.parseJsonArray(t[i])):t[i]instanceof Object?e.add(this.parseJsonObject(t[i],new Ie)):null==t[i]?e.add(new Be):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 Ie));else if(null==t[i])e.add(new Be);else{const s=Array(t[i]);for(let t=0;t<s.length;t++)e.add(s[t])}}),e}}const xe="Error: type mismatch";let Me=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 Ut){return t}getMap(t){return t}getValueByIndex(e){return t.errorValue.setErrorNotForClientCall(xe)}getValueByString(e){return t.nullValue.setErrorNotForClientCall(xe)}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 be.errorValue}static staticInitializeNotForClientCall(){ve.trueValue=new ve(!0),ve.falseValue=new ve(!1),t.errorValue=new be("ERROR",!0),t.nullValue=new Be,t.dummyKeys=new Ut}static staticReleaseNotForClientCall(){ve.trueValue=null,ve.falseValue=null,t.errorValue=null,t.nullValue=null,t.dummyKeys=null}};class Ce{constructor(t,e){this._parseCallback=ye.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 Ce;return i.parseBytes(t,e,i._parseCallback)?i:(Ce.delete(i),null)}static delete(t){}getRoot(){return this._root}static arrayBufferToString(t){const e=new Uint8Array(t);let i="";for(let s=0,r=e.length;s<r;++s)i+="%"+this.pad(e[s].toString(16));return i=decodeURIComponent(i),i}static pad(t){return t.length<2?"0"+t:t}parseBytes(t,e,i){const s=new Array(1),r=Ce.arrayBufferToString(t);if(this._root=null==i?this.parseValue(r,e,0,s):i(JSON.parse(r),new Ie),this._error){let t="\0";return t="Json parse error : @line "+(this._lineCount+1)+"\n",this._root=new Pe(t),le("{0}",this._root.getRawString()),!1}return null!=this._root||(this._root=new be(new Jt(this._error),!1),!1)}getParseError(){return this._error}checkEndOfFile(){return this._root.getArray()[1].equals("EOF")}parseValue(t,e,i,s){if(this._error)return null;let r,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 r=Ee(t.slice(n),e),s[0]=t.indexOf(e[0]),new Se(r)}case'"':return new Pe(this.parseString(t,e,n+1,s));case"[":return a=this.parseArray(t,e,n+1,s),a;case"{":return a=this.parseObject(t,e,n+1,s),a;case"n":return n+3<e?(a=new Be,s[0]=n+4):this._error="parse null",a;case"t":return n+3<e?(a=ve.trueValue,s[0]=n+4):this._error="parse true",a;case"f":return n+4<e?(a=ve.falseValue,s[0]=n+5):this._error="illegal ',' position",a;case",":return this._error="illegal ',' position",null;case"]":return s[0]=n,null;case"\n":this._lineCount++}}return this._error="illegal end of value",null}parseString(t,e,i,s){if(this._error)return null;if(!t)return this._error="string is null",null;let r,a,n=i;const o=new Jt("");let l=i;for(;n<e;n++)switch(r=t[n],r){case'"':return s[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,s){if(this._error)return null;if(!t)return this._error="buffer is null",null;const r=new Ie;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 s[0]=n+1,r;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],r.put(a,i);t:for(;n<e;n++)switch(o=t[n],o){case",":break t;case"}":return s[0]=n+1,r;case"\n":this._lineCount++}}return this._error="illegal end of perseObject",null}parseArray(t,e,i,s){if(this._error)return null;if(!t)return this._error="buffer is null",null;let r,a=new we,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(r=t[n],r){case",":break t;case"]":return s[0]=n+1,a;case"\n":++this._lineCount}}return a=void 0,this._error="illegal end of parseObject",null}}class Se extends Me{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 ve extends Me{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 Pe extends Me{constructor(t){super(),"string"==typeof t&&(this._stringBuffer=t),t instanceof Jt&&(this._stringBuffer=t.s)}isString(){return!0}getString(t,e){return this._stringBuffer}equals(t){return"string"==typeof t?this._stringBuffer==t:t instanceof Jt&&this._stringBuffer==t.s}}class be extends Pe{isStatic(){return this._isStatic}setErrorNotForClientCall(t){return this._stringBuffer=t,this}constructor(t,e){super(t),this._isStatic=e}isError(){return!0}}class Be extends Me{isNull(){return!0}getString(t,e){return this._stringBuffer}isStatic(){return!0}setErrorNotForClientCall(t){return this._stringBuffer=t,be.nullValue}constructor(){super(),this._stringBuffer="NullValue"}}class we extends Me{constructor(){super(),this._array=new Ut}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 Me.errorValue.setErrorNotForClientCall("Error: index out of bounds");const e=this._array.at(t);return null==e?Me.nullValue:e}getValueByString(t){return Me.errorValue.setErrorNotForClientCall(xe)}getString(t,e){const i=e+"[\n";for(let s=this._array.begin();s.notEqual(this._array.end());s.increment()){const t=s.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 Ie extends Me{constructor(){super(),this._map=new pe}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 Jt){const e=this._map.getValue(t.s);return null==e?Me.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?Me.nullValue:e.ptr().second;return Me.nullValue}getValueByIndex(t){return Me.errorValue.setErrorNotForClientCall(xe)}getString(t,e){this._stringBuffer=e+"{\n";const i=this._map.begin();for(;i.notEqual(this._map.end());){const t=i.ptr().first,s=i.ptr().second;this._stringBuffer+=e+" "+t+" : "+s.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 Ut;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 Fe;function Ee(t,e){let i=0;for(let r=1;;r++){const e=t.slice(r-1,r);if("e"==e||"-"==e||"E"==e)continue;const s=t.substring(0,r),a=Number(s);if(isNaN(a))break;i=r}let s=parseFloat(t);return isNaN(s)&&(s=NaN),e[0]=t.slice(i),s}(t=>{t.CubismJson=Ce,t.JsonArray=we,t.JsonBoolean=ve,t.JsonError=be,t.JsonFloat=Se,t.JsonMap=Ie,t.JsonNullvalue=Be,t.JsonString=Pe,t.Value=Me})(Fe||(Fe={}));let Le=!1,Ve=!1,Te=null,Re=null;const De=Object.freeze({vertexOffset:0,vertexStep:2});function Ae(t){t&&(t=void 0)}class Oe{static startUp(t=null){if(Le)return le("CubismFramework.startUp() is already done."),Le;if(Te=t,null!=Te&&Live2DCubismCore.Logging.csmSetLogFunction(Te.logFunction),Le=!0,Le){const t=Live2DCubismCore.Version.csmGetVersion(),e=(16711680&t)>>16,i=65535&t,s=t;le("Live2D Cubism Core version: {0}.{1}.{2} ({3})",("00"+((4278190080&t)>>24)).slice(-2),("00"+e).slice(-2),("0000"+i).slice(-4),s)}return le("CubismFramework.startUp() is complete."),Le}static cleanUp(){Le=!1,Ve=!1,Te=null,Re=null}static initialize(t=0){ne(Le),Le?Ve?ue("CubismFramework.initialize() skipped, already initialized."):(Me.staticInitializeNotForClientCall(),Re=new Zt,Live2DCubismCore.Memory.initializeAmountOfMemory(t),Ve=!0,le("CubismFramework.initialize() is complete.")):ue("CubismFramework is not started.")}static dispose(){ne(Le),Le?Ve?(Me.staticReleaseNotForClientCall(),Re.release(),Re=null,te.staticRelease(),Ve=!1,le("CubismFramework.dispose() is complete.")):ue("CubismFramework.dispose() skipped, not initialized."):ue("CubismFramework is not started.")}static isStarted(){return Le}static isInitialized(){return Ve}static coreLogFunction(t){Live2DCubismCore.Logging.csmGetLogFunction()&&Live2DCubismCore.Logging.csmGetLogFunction()(t)}static getLoggingLevel(){return null!=Te?Te.loggingLevel:5}static getIdManager(){return Re}constructor(){}}var ke,Ne,Ue=(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))(Ue||{});(t=>{t.Constant=De,t.csmDelete=Ae,t.CubismFramework=Oe})(ke||(ke={}));class ze{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 ze(0,0);return e.x=this.x+t.x,e.y=this.y+t.y,e}substract(t){const e=new ze(0,0);return e.x=this.x-t.x,e.y=this.y-t.y,e}multiply(t){const e=new ze(0,0);return e.x=this.x*t.x,e.y=this.y*t.y,e}multiplyByScaler(t){return this.multiply(new ze(t,t))}division(t){const e=new ze(0,0);return e.x=this.x/t.x,e.y=this.y/t.y,e}divisionByScalar(t){return this.division(new ze(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)}}(t=>{t.CubismVector2=ze})(Ne||(Ne={}));const je=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 s;return i&&(e=-e),e===1/0?s=1/0:(s=Math.exp(Math.log(e)/3),s=(e/(s*s)+2*s)/3),i?-s:s}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 s=this.radianToDegrees(i);return e.x-t.x>0&&(s=-s),s}static radianToDirection(t){const e=new ze;return e.x=this.sin(t),e.y=this.cos(t),e}static quadraticEquation(e,i,s){return this.abs(e)<t.Epsilon?this.abs(i)<t.Epsilon?-s:-s/i:-(i+this.sqrt(i*i-4*e*s))/(2*e)}static cardanoAlgorithmForBezier(e,i,s,r){if(this.abs(e)<t.Epsilon)return this.range(this.quadraticEquation(i,s,r),0,1);const a=i/e,n=s/e,o=(3*n-a*a)/3,l=o/3,u=(2*a*a*a-9*a*n+27*(r/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),s=-u/(2*i),r=this.range(s,-1,1),n=Math.acos(r),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),s=Math.abs(e);let r=i-Math.floor(i/s)*s;return r*=Math.sign(t),r}constructor(){}};je.Epsilon=1e-5;let Ge=je;var Xe,He;(t=>{t.CubismMath=Ge})(Xe||(Xe={}));class qe{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 Ut}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 s=this.updateFadeWeight(e,i);this.doUpdateParameters(t,i,s,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&&de.print(Ue.LogLevel_Error,"motionQueueEntry is null.");let i=this._weight;return i=i*(0==this._fadeInSeconds?1:Ge.getEasingSine((e-t.getFadeInStartTime())/this._fadeInSeconds))*(0==this._fadeOutSeconds||t.getEndTime()<0?1:Ge.getEasingSine((t.getEndTime()-e)/this._fadeOutSeconds)),t.setState(e,i),ne(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=qe})(He||(He={}));const Ye="Parameters",We="Blend",Je=class t extends qe{static create(e,i){const s=new t;return s.parse(e,i),s}doUpdateParameters(t,e,i,s){for(let r=0;r<this._parameters.getSize();++r){const e=this._parameters.at(r);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,s,r,a,n){if(null!=s&&null!=r&&s.isAvailable()){this._fadeWeight=this.updateFadeWeight(s,i);for(let i=0;i<r.getSize();++i){const s=r.at(i);if(null==s.parameterId)continue;const o=s.overwriteValue=e.getParameterValueById(s.parameterId),l=this.getExpressionParameters();let u=-1;for(let t=0;t<l.getSize();++t)if(s.parameterId==l.at(t).parameterId){u=t;break}if(u<0){0==a?(s.additiveValue=t.DefaultAdditiveValue,s.multiplyValue=t.DefaultMultiplyValue,s.overwriteValue=o):(s.additiveValue=this.calculateValue(s.additiveValue,t.DefaultAdditiveValue,n),s.multiplyValue=this.calculateValue(s.multiplyValue,t.DefaultMultiplyValue,n),s.overwriteValue=this.calculateValue(s.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?(s.additiveValue=d,s.multiplyValue=g,s.overwriteValue=c):(s.additiveValue=s.additiveValue*(1-n)+d*n,s.multiplyValue=s.multiplyValue*(1-n)+g*n,s.overwriteValue=s.overwriteValue*(1-n)+c*n)}}}getExpressionParameters(){return this._parameters}getFadeWeight(){return this._fadeWeight}parse(t,e){const i=Ce.create(t,e);if(!i)return;const s=i.getRoot();this.setFadeInTime(s.getValueByString("FadeInTime").toFloat(1)),this.setFadeOutTime(s.getValueByString("FadeOutTime").toFloat(1));const r=s.getValueByString(Ye).getSize();this._parameters.prepareCapacity(r);for(let a=0;a<r;++a){const t=s.getValueByString(Ye).getValueByIndex(a),e=Oe.getIdManager().getId(t.getValueByString("Id").getRawString()),i=t.getValueByString("Value").toFloat();let r;r=t.getValueByString(We).isNull()||"Add"==t.getValueByString(We).getString()?0:"Multiply"==t.getValueByString(We).getString()?1:"Overwrite"==t.getValueByString(We).getString()?2:0;const n=new ti;n.parameterId=e,n.blendType=r,n.value=i,this._parameters.pushBack(n)}Ce.delete(i)}calculateValue(t,e,i){return t*(1-i)+e*i}constructor(){super(),this._parameters=new Ut,this._fadeWeight=0}};Je.DefaultAdditiveValue=0,Je.DefaultMultiplyValue=1;let $e=Je;var Ze,Ke,Qe=(t=>(t[t.Additive=0]="Additive",t[t.Multiply=1]="Multiply",t[t.Overwrite=2]="Overwrite",t))(Qe||{});class ti{}(t=>{t.CubismExpressionMotion=$e,t.ExpressionBlendType=Qe,t.ExpressionParameter=ti})(Ze||(Ze={}));class ei{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&&qe.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=ei})(Ke||(Ke={}));class ii{constructor(){this._userTimeSeconds=0,this._eventCallBack=null,this._eventCustomData=null,this._motions=new Ut}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 si;let s=null;for(let r=0;r<this._motions.getSize();++r)s=this._motions.at(r),null!=s&&s.setFadeOut(s._motion.getFadeOutTime());return s=new ei,s._autoDelete=e,s._motion=t,this._motions.pushBack(s),s._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 s=this._motions.begin();s.notEqual(this._motions.end());){let r=s.ptr();if(null==r){s=this._motions.erase(s);continue}const a=r._motion;if(null==a){r.release(),r=null,s=this._motions.erase(s);continue}a.updateParameters(t,r,e),i=!0;const n=a.getFiredEvent(r.getLastCheckEventSeconds()-r.getStartTime(),e-r.getStartTime());for(let t=0;t<n.getSize();++t)this._eventCallBack(this,n.at(t),this._eventCustomData);r.setLastCheckEventSeconds(e),r.isFinished()?(r.release(),r=null,s=this._motions.erase(s)):(r.isTriggeredFadeOut()&&r.startFadeOut(r.getFadeOutSeconds(),e),s.preIncrement())}return i}}const si=-1;var ri;(t=>{t.CubismMotionQueueManager=ii,t.InvalidMotionQueueEntryHandleValue=si})(ri||(ri={}));class ai extends B{constructor(t,e){var i,s;super(t,e),g(this,"expressionDataType","arraybuffer"),g(this,"queueManager",new ii),g(this,"definitions"),this.definitions=null!=(s=null==(i=t.expressions)?void 0:i.filter(t=>!!t&&"string"==typeof t.File))?s:[],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 $e.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 $e.create(t,t.byteLength)}}var ni,oi=(t=>(t[t.CubismMotionCurveTarget_Model=0]="CubismMotionCurveTarget_Model",t[t.CubismMotionCurveTarget_Parameter=1]="CubismMotionCurveTarget_Parameter",t[t.CubismMotionCurveTarget_PartOpacity=2]="CubismMotionCurveTarget_PartOpacity",t))(oi||{}),li=(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))(li||{});class ui{constructor(){this.time=0,this.value=0}}class hi{constructor(){this.evaluate=null,this.basePointIndex=0,this.segmentType=0}}class di{constructor(){this.type=0,this.segmentCount=0,this.baseSegmentIndex=0,this.fadeInTime=0,this.fadeOutTime=0}}class gi{constructor(){this.fireTime=0}}class ci{constructor(){this.duration=0,this.loop=!1,this.curveCount=0,this.eventCount=0,this.fps=0,this.curves=new Ut,this.segments=new Ut,this.points=new Ut,this.events=new Ut}}(t=>{t.CubismMotionCurve=di,t.CubismMotionCurveTarget=oi,t.CubismMotionData=ci,t.CubismMotionEvent=gi,t.CubismMotionPoint=ui,t.CubismMotionSegment=hi,t.CubismMotionSegmentType=li})(ni||(ni={}));const mi="Meta",pi="Curves",_i="FadeInTime",fi="FadeOutTime",yi="Segments",xi="UserData";class Mi{constructor(t,e){this._json=Ce.create(t,e)}release(){Ce.delete(this._json)}getMotionDuration(){return this._json.getRoot().getValueByString(mi).getValueByString("Duration").toFloat()}isMotionLoop(){return this._json.getRoot().getValueByString(mi).getValueByString("Loop").toBoolean()}hasConsistency(){let t=!0;if(!this._json||!this._json.getRoot())return!1;const e=this._json.getRoot().getValueByString(pi).getVector().getSize();let i=0,s=0;for(let r=0;r<e;++r)for(let t=0;t<this.getMotionCurveSegmentCount(r);){0==t&&(s+=1,t+=2);switch(this.getMotionCurveSegment(r,t)){case li.CubismMotionSegmentType_Linear:s+=1,t+=3;break;case li.CubismMotionSegmentType_Bezier:s+=3,t+=7;break;case li.CubismMotionSegmentType_Stepped:case li.CubismMotionSegmentType_InverseStepped:s+=1,t+=3;break;default:ne(0)}++i}return e!=this.getMotionCurveCount()&&(ue("The number of curves does not match the metadata."),t=!1),i!=this.getMotionTotalSegmentCount()&&(ue("The number of segment does not match the metadata."),t=!1),s!=this.getMotionTotalPointCount()&&(ue("The number of point does not match the metadata."),t=!1),t}getEvaluationOptionFlag(t){return 0==t&&this._json.getRoot().getValueByString(mi).getValueByString("AreBeziersRestricted").toBoolean()}getMotionCurveCount(){return this._json.getRoot().getValueByString(mi).getValueByString("CurveCount").toInt()}getMotionFps(){return this._json.getRoot().getValueByString(mi).getValueByString("Fps").toFloat()}getMotionTotalSegmentCount(){return this._json.getRoot().getValueByString(mi).getValueByString("TotalSegmentCount").toInt()}getMotionTotalPointCount(){return this._json.getRoot().getValueByString(mi).getValueByString("TotalPointCount").toInt()}isExistMotionFadeInTime(){return!this._json.getRoot().getValueByString(mi).getValueByString(_i).isNull()}isExistMotionFadeOutTime(){return!this._json.getRoot().getValueByString(mi).getValueByString(fi).isNull()}getMotionFadeInTime(){return this._json.getRoot().getValueByString(mi).getValueByString(_i).toFloat()}getMotionFadeOutTime(){return this._json.getRoot().getValueByString(mi).getValueByString(fi).toFloat()}getMotionCurveTarget(t){return this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString("Target").getRawString()}getMotionCurveId(t){return Oe.getIdManager().getId(this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString("Id").getRawString())}isExistMotionCurveFadeInTime(t){return!this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString(_i).isNull()}isExistMotionCurveFadeOutTime(t){return!this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString(fi).isNull()}getMotionCurveFadeInTime(t){return this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString(_i).toFloat()}getMotionCurveFadeOutTime(t){return this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString(fi).toFloat()}getMotionCurveSegmentCount(t){return this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString(yi).getVector().getSize()}getMotionCurveSegment(t,e){return this._json.getRoot().getValueByString(pi).getValueByIndex(t).getValueByString(yi).getValueByIndex(e).toFloat()}getEventCount(){return this._json.getRoot().getValueByString(mi).getValueByString("UserDataCount").toInt()}getTotalEventValueSize(){return this._json.getRoot().getValueByString(mi).getValueByString("TotalUserDataSize").toInt()}getEventTime(t){return this._json.getRoot().getValueByString(xi).getValueByIndex(t).getValueByString("Time").toFloat()}getEventValue(t){return new Jt(this._json.getRoot().getValueByString(xi).getValueByIndex(t).getValueByString("Value").getRawString())}}var Ci,Si=(t=>(t[t.EvaluationOptionFlag_AreBeziersRistricted=0]="EvaluationOptionFlag_AreBeziersRistricted",t))(Si||{});(t=>{t.CubismMotionJson=Mi})(Ci||(Ci={}));const vi="Opacity";function Pi(t,e,i){const s=new ui;return s.time=t.time+(e.time-t.time)*i,s.value=t.value+(e.value-t.value)*i,s}function bi(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 Bi(t,e){let i=(e-t[0].time)/(t[3].time-t[0].time);i<0&&(i=0);const s=Pi(t[0],t[1],i),r=Pi(t[1],t[2],i),a=Pi(t[2],t[3],i),n=Pi(s,r,i),o=Pi(r,a,i);return Pi(n,o,i).value}function wi(t,e){const i=e,s=t[0].time,r=t[3].time,a=t[1].time,n=t[2].time,o=r-3*n+3*a-s,l=3*n-6*a+3*s,u=3*a-3*s,h=s-i,d=Ge.cardanoAlgorithmForBezier(o,l,u,h),g=Pi(t[0],t[1],d),c=Pi(t[1],t[2],d),m=Pi(t[2],t[3],d),p=Pi(g,c,d),_=Pi(c,m,d);return Pi(p,_,d).value}function Ii(t,e){return t[0].value}function Fi(t,e){return t[1].value}function Ei(t,e,i,s,r){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==li.CubismMotionSegmentType_Bezier?3:1),t.points.at(l).time>i){n=h;break}if(-1==n)return s&&i<r?function(t,e,i,s,r,a){const n=[new ui,new ui];{const e=t.points.at(s);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 li.CubismMotionSegmentType_Linear:case li.CubismMotionSegmentType_Bezier:default:return bi(n,r);case li.CubismMotionSegmentType_Stepped:return Ii(n);case li.CubismMotionSegmentType_InverseStepped:return Fi(n)}}(t,o-1,t.segments.at(a.baseSegmentIndex).basePointIndex,l,i,r):t.points.at(l).value;const u=t.segments.at(n);return u.evaluate(t.points.get(u.basePointIndex),i)}class Li extends qe{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,s,r=!1){const a=new Li;return a.parse(t,e,r),a._motionData?(a._sourceFrameRate=a._motionData.fps,a._loopDurationSeconds=a._motionData.duration,a._onFinishedMotion=i,a._onBeganMotion=s,a):(Ae(a),null)}doUpdateParameters(t,e,i,s){null==this._modelCurveIdEyeBlink&&(this._modelCurveIdEyeBlink=Oe.getIdManager().getId("EyeBlink")),null==this._modelCurveIdLipSync&&(this._modelCurveIdLipSync=Oe.getIdManager().getId("LipSync")),null==this._modelCurveIdOpacity&&(this._modelCurveIdOpacity=Oe.getIdManager().getId(vi)),1===this._motionBehavior&&this._previousLoopState!==this._isLoop&&(this.adjustEndTime(s),this._previousLoopState=this._isLoop);let r=e-s.getStartTime();r<0&&(r=0);let a=Number.MAX_VALUE,n=Number.MAX_VALUE;const o=64;let l=0,u=0;this._eyeBlinkParameterIds.getSize()>o&&oe("too many eye blink targets : {0}",this._eyeBlinkParameterIds.getSize()),this._lipSyncParameterIds.getSize()>o&&oe("too many lip sync targets : {0}",this._lipSyncParameterIds.getSize());const h=this._fadeInSeconds<=0?1:Ge.getEasingSine((e-s.getFadeInStartTime())/this._fadeInSeconds),d=this._fadeOutSeconds<=0||s.getEndTime()<0?1:Ge.getEasingSine((s.getEndTime()-e)/this._fadeOutSeconds);let g,c,m,p=r,_=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==oi.CubismMotionCurveTarget_Model;++c)g=Ei(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==oi.CubismMotionCurveTarget_Parameter;++c){if(m=t.getParameterIndex(y.at(c).id),-1==m)continue;const r=t.getParameterValueByIndex(m);if(g=Ei(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=r+(g-r)*i;else{let t,i;t=y.at(c).fadeInTime<0?h:0==y.at(c).fadeInTime?1:Ge.getEasingSine((e-s.getFadeInStartTime())/y.at(c).fadeInTime),i=y.at(c).fadeOutTime<0?d:0==y.at(c).fadeOutTime||s.getEndTime()<0?1:Ge.getEasingSine((s.getEndTime()-e)/y.at(c).fadeOutTime);x=r+(g-r)*(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 s=e+(n-e)*i;t.setParameterValueById(this._eyeBlinkParameterIds.at(x),s)}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 s=e+(a-e)*i;t.setParameterValueById(this._lipSyncParameterIds.at(x),s)}for(;c<this._motionData.curveCount&&y.at(c).type==oi.CubismMotionCurveTarget_PartOpacity;++c)m=t.getParameterIndex(y.at(c).id),-1!=m&&(g=Ei(this._motionData,c,p,f,_),t.setParameterValueByIndex(m,g));r>=_&&(this._isLoop?this.updateForNextLoop(s,e,p):(this._onFinishedMotion&&this._onFinishedMotion(this),s.setIsFinished(!0))),this._lastWeight=i}setIsLoop(t){ue("setIsLoop() is a deprecated function. Please use setLoop()."),this._isLoop=t}isLoop(){return ue("isLoop() is a deprecated function. Please use getLoop()."),this._isLoop}setIsLoopFadeIn(t){ue("setIsLoopFadeIn() is a deprecated function. Please use setLoopFadeIn()."),this._isLoopFadeIn=t}isLoopFadeIn(){return ue("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 s=0;s<this._motionData.curveCount;++s)if(t==i.at(s).id)return void(i.at(s).fadeInTime=e)}setParameterFadeOutTime(t,e){const i=this._motionData.curves;for(let s=0;s<this._motionData.curveCount;++s)if(t==i.at(s).id)return void(i.at(s).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 s=new Mi(t,e);if(!s)return s.release(),void(s=void 0);if(i){if(!s.hasConsistency())return s.release(),void he("Inconsistent motion3.json.")}this._motionData=new ci,this._motionData.duration=s.getMotionDuration(),this._motionData.loop=s.isMotionLoop(),this._motionData.curveCount=s.getMotionCurveCount(),this._motionData.fps=s.getMotionFps(),this._motionData.eventCount=s.getEventCount();const r=s.getEvaluationOptionFlag(Si.EvaluationOptionFlag_AreBeziersRistricted);s.isExistMotionFadeInTime()?this._fadeInSeconds=s.getMotionFadeInTime()<0?1:s.getMotionFadeInTime():this._fadeInSeconds=1,s.isExistMotionFadeOutTime()?this._fadeOutSeconds=s.getMotionFadeOutTime()<0?1:s.getMotionFadeOutTime():this._fadeOutSeconds=1,this._motionData.curves.updateSize(this._motionData.curveCount,di,!0),this._motionData.segments.updateSize(s.getMotionTotalSegmentCount(),hi,!0),this._motionData.points.updateSize(s.getMotionTotalPointCount(),ui,!0),this._motionData.events.updateSize(this._motionData.eventCount,gi,!0);let a=0,n=0;for(let o=0;o<this._motionData.curveCount;++o){"Model"==s.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=oi.CubismMotionCurveTarget_Model:"Parameter"==s.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=oi.CubismMotionCurveTarget_Parameter:"PartOpacity"==s.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=oi.CubismMotionCurveTarget_PartOpacity:ue('Warning : Unable to get segment type from Curve! The number of "CurveCount" may be incorrect!'),this._motionData.curves.at(o).id=s.getMotionCurveId(o),this._motionData.curves.at(o).baseSegmentIndex=n,this._motionData.curves.at(o).fadeInTime=s.isExistMotionCurveFadeInTime(o)?s.getMotionCurveFadeInTime(o):-1,this._motionData.curves.at(o).fadeOutTime=s.isExistMotionCurveFadeOutTime(o)?s.getMotionCurveFadeOutTime(o):-1;for(let t=0;t<s.getMotionCurveSegmentCount(o);){0==t?(this._motionData.segments.at(n).basePointIndex=a,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+1),a+=1,t+=2):this._motionData.segments.at(n).basePointIndex=a-1;switch(s.getMotionCurveSegment(o,t)){case li.CubismMotionSegmentType_Linear:this._motionData.segments.at(n).segmentType=li.CubismMotionSegmentType_Linear,this._motionData.segments.at(n).evaluate=bi,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case li.CubismMotionSegmentType_Bezier:this._motionData.segments.at(n).segmentType=li.CubismMotionSegmentType_Bezier,this._motionData.segments.at(n).evaluate=r?Bi:wi,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),this._motionData.points.at(a+1).time=s.getMotionCurveSegment(o,t+3),this._motionData.points.at(a+1).value=s.getMotionCurveSegment(o,t+4),this._motionData.points.at(a+2).time=s.getMotionCurveSegment(o,t+5),this._motionData.points.at(a+2).value=s.getMotionCurveSegment(o,t+6),a+=3,t+=7;break;case li.CubismMotionSegmentType_Stepped:this._motionData.segments.at(n).segmentType=li.CubismMotionSegmentType_Stepped,this._motionData.segments.at(n).evaluate=Ii,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case li.CubismMotionSegmentType_InverseStepped:this._motionData.segments.at(n).segmentType=li.CubismMotionSegmentType_InverseStepped,this._motionData.segments.at(n).evaluate=Fi,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;default:ne(0)}++this._motionData.curves.at(o).segmentCount,++n}}for(let o=0;o<s.getEventCount();++o)this._motionData.events.at(o).fireTime=s.getEventTime(o),this._motionData.events.at(o).value=s.getEventValue(o);s.release(),s=void 0,s=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 Jt(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==oi.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(vi))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==oi.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(vi))return t}return-1}getModelOpacityId(t){if(-1!=t){const e=this._motionData.curves.at(t);if(e.type==oi.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(vi))return Oe.getIdManager().getId(e.id.getString().s)}return null}getModelOpacityValue(){return this._modelOpacity}setDebugMode(t){this._debugMode=t}}var Vi;function Ti(t,e,i){const s=t.startMotion(i,!1),r=t.getCubismMotionQueueEntry(s);if(!r)return!1;r.setStartTime(0),r.setFadeInStartTime(0);const a=i.getDuration(),n=r.getStartTime()+a;return i.doUpdateParameters(e.coreModel,n,1,r),r.setIsFinished(!0),!0}(t=>{t.CubismMotion=Li})(Vi||(Vi={}));class Ri extends O{constructor(t){var e;super(t),g(this,"definitions"),g(this,"groups",{idle:"Idle"}),g(this,"motionDataType","arraybuffer"),g(this,"queueManager",new ii),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 ai(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,s=function(t){if(Di(t))return new Ut;return[]}(e),r=Ai(e);for(let t=0;t<r;t++){const r=Oi(e,t);if(!r)continue;const a=ki(r);a&&i.includes(a)||Ni(s,r)}t._motionData.curves=s,t._motionData.curveCount=Ai(s)}return this.queueManager.stopAllMotions(),this.queueManager.startMotion(t,!1)}_stopAllMotions(){this.queueManager.stopAllMotions()}createMotion(t,e,i){const s=!!this.parent.options.checkMotionConsistency,r=Li.create(t,t.byteLength,void 0,void 0,s),a=new Mi(t,t.byteLength),n=(e===this.groups.idle?m.idleMotionFadingDuration:m.motionFadingDuration)/1e3;return void 0===a.getMotionFadeInTime()&&r.setFadeInTime(i.FadeInTime>0?i.FadeInTime:n),void 0===a.getMotionFadeOutTime()&&r.setFadeOutTime(i.FadeOutTime>0?i.FadeOutTime:n),r.setEffectIds(this.createIdVector(this.eyeBlinkIds),this.createIdVector(this.lipSyncIds)),r}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 s=yield this.getMotionAndApplyExpression(t,e,i);return!!s&&(this.playing=!0,Ti(this.queueManager,this.parent,s),this.playing=!1,!0)})}createIdVector(t){const e=new Ut,i=Oe.getIdManager();for(const s of t)e.pushBack(i.getId(s));return e}}function Di(t){return"function"==typeof t.pushBack}function Ai(t){return Di(t)?t.getSize():t.length}function Oi(t,e){return Di(t)?t.at(e):t[e]}function ki(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 Ni(t,e){Di(t)?t.pushBack(e):t.push(e)}class Ui extends Ft{constructor(t){super(t),g(this,"queueManager",new ii),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,s=function(t){if(zi(t))return new Ut;return[]}(e),r=ji(e);for(let t=0;t<r;t++){const r=Gi(e,t);if(!r)continue;const a=Xi(r);a&&i.includes(a)||Hi(s,r)}t._motionData.curves=s,t._motionData.curveCount=ji(s)}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,L.FORCE))return!1;const s=null==(i=this.manager.definitions[t])?void 0:i[e];if(!s)return!1;const r=yield this.manager.loadMotion(t,e);return!!this.state.start(r,t,e,L.FORCE)&&(p.log(this.tag,"Start motion:",this.getMotionName(s)),this.emit("motionStart",t,e,void 0),this.playing=!0,this.queueManager.stopAllMotions(),Ti(this.queueManager,this.parent,r)?(this.playing=!1,!0):(this.playing=!1,!1))})}}function zi(t){return"function"==typeof t.pushBack}function ji(t){return zi(t)?t.getSize():t.length}function Gi(t,e){return zi(t)?t.at(e):t[e]}function Xi(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 Hi(t,e){zi(t)?t.pushBack(e):t.push(e)}const qi=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 Yi,Wi;(t=>{t.HitAreaBody=qi.HitAreaBody,t.HitAreaHead=qi.HitAreaHead,t.HitAreaPrefix=qi.HitAreaPrefix,t.ParamAngleX=qi.ParamAngleX,t.ParamAngleY=qi.ParamAngleY,t.ParamAngleZ=qi.ParamAngleZ,t.ParamArmLA=qi.ParamArmLA,t.ParamArmLB=qi.ParamArmLB,t.ParamArmRA=qi.ParamArmRA,t.ParamArmRB=qi.ParamArmRB,t.ParamBaseX=qi.ParamBaseX,t.ParamBaseY=qi.ParamBaseY,t.ParamBodyAngleX=qi.ParamBodyAngleX,t.ParamBodyAngleY=qi.ParamBodyAngleY,t.ParamBodyAngleZ=qi.ParamBodyAngleZ,t.ParamBreath=qi.ParamBreath,t.ParamBrowLAngle=qi.ParamBrowLAngle,t.ParamBrowLForm=qi.ParamBrowLForm,t.ParamBrowLX=qi.ParamBrowLX,t.ParamBrowLY=qi.ParamBrowLY,t.ParamBrowRAngle=qi.ParamBrowRAngle,t.ParamBrowRForm=qi.ParamBrowRForm,t.ParamBrowRX=qi.ParamBrowRX,t.ParamBrowRY=qi.ParamBrowRY,t.ParamBustX=qi.ParamBustX,t.ParamBustY=qi.ParamBustY,t.ParamCheek=qi.ParamCheek,t.ParamEyeBallForm=qi.ParamEyeBallForm,t.ParamEyeBallX=qi.ParamEyeBallX,t.ParamEyeBallY=qi.ParamEyeBallY,t.ParamEyeLOpen=qi.ParamEyeLOpen,t.ParamEyeLSmile=qi.ParamEyeLSmile,t.ParamEyeROpen=qi.ParamEyeROpen,t.ParamEyeRSmile=qi.ParamEyeRSmile,t.ParamHairBack=qi.ParamHairBack,t.ParamHairFluffy=qi.ParamHairFluffy,t.ParamHairFront=qi.ParamHairFront,t.ParamHairSide=qi.ParamHairSide,t.ParamHandL=qi.ParamHandL,t.ParamHandR=qi.ParamHandR,t.ParamMouthForm=qi.ParamMouthForm,t.ParamMouthOpenY=qi.ParamMouthOpenY,t.ParamNONE=qi.ParamNONE,t.ParamShoulderY=qi.ParamShoulderY,t.PartsArmLPrefix=qi.PartsArmLPrefix,t.PartsArmPrefix=qi.PartsArmPrefix,t.PartsArmRPrefix=qi.PartsArmRPrefix,t.PartsIdCore=qi.PartsIdCore})(Yi||(Yi={}));class Ji{static create(){return new Ji}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 s=0;s<this._breathParameters.getSize();++s){const e=this._breathParameters.at(s);t.addParameterValueById(e.parameterId,e.offset+e.peak*Math.sin(i/e.cycle),e.weight)}}constructor(){this._currentTime=0}}class $i{constructor(t,e,i,s,r){this.parameterId=null==t?null:t,this.offset=null==e?0:e,this.peak=null==i?0:i,this.cycle=null==s?0:s,this.weight=null==r?0:r}}(t=>{t.BreathParameterData=$i,t.CubismBreath=Ji})(Wi||(Wi={}));const Zi=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 s;this._userTimeSeconds+=i;let r=0;switch(this._blinkingState){case 2:r=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closingSeconds,r>=1&&(r=1,this._blinkingState=3,this._stateStartTimeSeconds=this._userTimeSeconds),s=1-r;break;case 3:r=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closedSeconds,r>=1&&(this._blinkingState=4,this._stateStartTimeSeconds=this._userTimeSeconds),s=0;break;case 4:r=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._openingSeconds,r>=1&&(r=1,this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming()),s=r;break;case 1:this._nextBlinkingTime<this._userTimeSeconds&&(this._blinkingState=2,this._stateStartTimeSeconds=this._userTimeSeconds),s=1;break;default:this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming(),s=1}t.CloseIfZero||(s=-s);for(let t=0;t<this._parameterIds.getSize();++t)e.setParameterValueById(this._parameterIds.at(t),s)}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 Ut,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)}};Zi.CloseIfZero=!0;let Ki=Zi;var Qi,ts=(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))(ts||{});(t=>{t.CubismEyeBlink=Ki,t.EyeState=ts})(Qi||(Qi={}));class es{constructor(t){this._renderTextureCount=0,this._clippingMaskBufferSize=256,this._clippingContextListForMask=new Ut,this._clippingContextListForDraw=new Ut,this._channelColors=new Ut,this._tmpBoundsOnModel=new Qt,this._tmpMatrix=new Kt,this._tmpMatrixForMask=new Kt,this._tmpMatrixForDraw=new Kt,this._clippingContexttConstructor=t;let e=new se;e.r=1,e.g=0,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new se,e.r=0,e.g=1,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new se,e.r=0,e.g=0,e.b=1,e.a=0,this._channelColors.pushBack(e),e=new se,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&&(ue("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&&ue("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 Ut(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 s=this._clippingContextListForMask.at(i),r=s._clippingIdCount;if(r!=e)continue;let a=0;for(let e=0;e<r;e++){const i=s._clippingIdList[e];for(let e=0;e<r;e++)if(t[e]==i){a++;break}}if(a==r)return s}return null}setupMatrixForHighPrecision(t,e){let i=0;for(let s=0;s<this._clippingContextListForMask.getSize();s++){const e=this._clippingContextListForMask.at(s);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 s=this._clippingContextListForMask.at(i),r=s._allClippedDrawRect,a=s._layoutBounds,n=.05;let o=0,l=0;const u=t.getPixelsPerUnit(),h=s.getClippingManager().getClippingMaskBufferSize(),d=a.width*h,g=a.height*h;this._tmpBoundsOnModel.setRect(r),this._tmpBoundsOnModel.width*u>d?(this._tmpBoundsOnModel.expand(r.width*n,0),o=a.width/this._tmpBoundsOnModel.width):o=u/d,this._tmpBoundsOnModel.height*u>g?(this._tmpBoundsOnModel.expand(0,r.height*n),l=a.height/this._tmpBoundsOnModel.height):l=u/g,this.createMatrixForMask(e,a,o,l),s._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),s._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray())}}}createMatrixForMask(t,e,i,s){this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(e.x,e.y),this._tmpMatrix.scaleRelative(i,s),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,s*(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&&he("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 s=t/this._renderTextureCount;const r=t%this._renderTextureCount;s=Math.ceil(s);let a=s/4;const n=s%4;a=~~a;let o=0;for(let l=0;l<this._renderTextureCount;l++)for(let s=0;s<4;s++){let u=a+(s<n?1:0);if(s==n+(a<1?-1:0)&&r>0&&(u-=l<r?0:1),0==u);else if(1==u){const t=this._clippingContextListForMask.at(o++);t._layoutChannelIndex=s,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=s,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 r=this._clippingContextListForMask.at(o++);r._layoutChannelIndex=s,r._layoutBounds.x=.5*e,r._layoutBounds.y=.5*i,r._layoutBounds.width=.5,r._layoutBounds.height=.5,r._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 r=this._clippingContextListForMask.at(o++);r._layoutChannelIndex=s,r._layoutBounds.x=e/3,r._layoutBounds.y=i/3,r._layoutBounds.width=1/3,r._layoutBounds.height=1/3,r._bufferIndex=l}else{he("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,s=Number.MAX_VALUE,r=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*De.vertexStep;for(let t=De.vertexOffset;t<m;t+=De.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<s&&(s=d),g>r&&(r=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=r-i,n=a-s;e._allClippedDrawRect.x=i,e._allClippedDrawRect.y=s,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 is;class ss{constructor(){this._shaderSets=new Ut}release(){this.releaseShaderProgram()}setupShaderProgramForDraw(t,e,i){let s,r,a,n;t.isPremultipliedAlpha()||he("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 ie.CubismBlendMode_Normal:default:h=this._shaderSets.at(1+u),s=this.gl.ONE,r=this.gl.ONE_MINUS_SRC_ALPHA,a=this.gl.ONE,n=this.gl.ONE_MINUS_SRC_ALPHA;break;case ie.CubismBlendMode_Additive:h=this._shaderSets.at(4+u),s=this.gl.ONE,r=this.gl.ONE,a=this.gl.ZERO,n=this.gl.ONE;break;case ie.CubismBlendMode_Multiplicative:h=this._shaderSets.at(7+u),s=this.gl.DST_COLOR,r=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,s=t.getClippingContextBufferForDraw().getClippingManager().getChannelFlagAsColor(i);this.gl.uniform4f(h.uniformChannelFlagLocation,s.r,s.g,s.b,s.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(s,r,a,n)}setupShaderProgramForMask(t,e,i){t.isPremultipliedAlpha()||he("NoPremultipliedAlpha is not allowed"),0==this._shaderSets.getSize()&&this.generateShaders();const s=this._shaderSets.at(0);this.gl.useProgram(s.shaderProgram),null==t._bufferData.vertex&&(t._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.vertex);const r=e.getDrawableVertices(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,r,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(s.attributePositionLocation),this.gl.vertexAttribPointer(s.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(s.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(s.attributeTexCoordLocation),this.gl.vertexAttribPointer(s.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),t.getClippingContextBufferForMask();const l=t.getClippingContextBufferForMask()._layoutChannelIndex,u=t.getClippingContextBufferForMask().getClippingManager().getChannelFlagAsColor(l);this.gl.uniform4f(s.uniformChannelFlagLocation,u.r,u.g,u.b,u.a),this.gl.uniformMatrix4fv(s.uniformClipMatrixLocation,!1,t.getClippingContextBufferForMask()._matrixForMask.getArray());const h=t.getClippingContextBufferForMask()._layoutBounds;this.gl.uniform4f(s.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(s.uniformMultiplyColorLocation,d.r,d.g,d.b,d.a),this.gl.uniform4f(s.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 as);this._shaderSets.at(0).shaderProgram=this.loadShaderProgram(os,ls),this._shaderSets.at(1).shaderProgram=this.loadShaderProgram(us,ds),this._shaderSets.at(2).shaderProgram=this.loadShaderProgram(hs,gs),this._shaderSets.at(3).shaderProgram=this.loadShaderProgram(hs,cs),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(),s=this.compileShaderSource(this.gl.VERTEX_SHADER,t);if(!s)return he("Vertex shader compile error!"),0;let r=this.compileShaderSource(this.gl.FRAGMENT_SHADER,e);if(!r)return he("Vertex shader compile error!"),0;this.gl.attachShader(i,s),this.gl.attachShader(i,r),this.gl.linkProgram(i);return this.gl.getProgramParameter(i,this.gl.LINK_STATUS)?(this.gl.deleteShader(s),this.gl.deleteShader(r),i):(he("Failed to link program: {0}",i),this.gl.deleteShader(s),s=0,this.gl.deleteShader(r),r=0,i&&(this.gl.deleteProgram(i),i=0),0)}compileShaderSource(t,e){const i=e,s=this.gl.createShader(t);if(this.gl.shaderSource(s,i),this.gl.compileShader(s),!s){const t=this.gl.getShaderInfoLog(s);he("Shader compile log: {0} ",t)}return this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)?s:(this.gl.deleteShader(s),null)}setGl(t){this.gl=t}}class rs{static getInstance(){return null==is&&(is=new rs),is}static deleteInstance(){is&&(is.release(),is=null)}constructor(){this._shaderMap=new pe}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 ss;e.setGl(t),this._shaderMap.setValue(t,e)}}}class as{}var ns=(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))(ns||{});const os="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;}",ls="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;}",us="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;}",hs="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;}",ds="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);}",gs="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;}",cs="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 ms;let ps,_s;(t=>{t.CubismShaderSet=as,t.CubismShader_WebGL=ss,t.CubismShaderManager_WebGL=rs,t.ShaderNames=ns})(ms||(ms={}));class fs extends es{getMaskRenderTexture(){if(this._maskTexture&&null!=this._maskTexture.textures)this._maskTexture.frameNo=this._currentFrameNo;else{null!=this._maskRenderTextures&&this._maskRenderTextures.clear(),this._maskRenderTextures=new Ut,null!=this._maskColorBuffers&&this._maskColorBuffers.clear(),this._maskColorBuffers=new Ut;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,_s),this._maskTexture=new ys(this._currentFrameNo,this._maskRenderTextures)}return this._maskTexture.textures}setGL(t){this.gl=t}constructor(){super(xs)}setupClippingContext(t,e){this._currentFrameNo++;let i=0;for(let s=0;s<this._clippingContextListForMask.getSize();s++){const e=this._clippingContextListForMask.at(s);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 Ut(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 s=this._clippingContextListForMask.at(i),r=s._allClippedDrawRect,a=s._layoutBounds,n=.05;let o=0,l=0;const u=this.getMaskRenderTexture().at(s._bufferIndex);this._currentMaskRenderTexture!=u&&(this._currentMaskRenderTexture=u,e.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentMaskRenderTexture)),this._tmpBoundsOnModel.setRect(r),this._tmpBoundsOnModel.expand(r.width*n,r.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()),s._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),s._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray());const h=s._clippingIdCount;for(let i=0;i<h;i++){const r=s._clippingIdList[i];t.getDrawableDynamicFlagVertexPositionsDidChange(r)&&(e.setIsCulling(0!=t.getDrawableCulling(r)),this._clearedFrameBufferFlags.at(s._bufferIndex)||(this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this._clearedFrameBufferFlags.set(s._bufferIndex,!0)),e.setClippingContextBufferForMask(s),e.drawMeshWebGL(t,r))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,_s),e.setClippingContextBufferForMask(null),this.gl.viewport(ps[0],ps[1],ps[2],ps[3])}}getColorBuffer(){return this._maskColorBuffers}getClippingMaskCount(){return this._clippingContextListForMask.getSize()}}class ys{constructor(t,e){this.frameNo=t,this.textures=e}}class xs extends re{constructor(t,e,i){super(e,i),this._owner=t}getClippingManager(){return this._owner}setGl(t){this._owner.setGL(t)}}class Ms{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)):he("'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])):he("'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 Cs extends te{initialize(t,e=1){t.isUsingMasking()&&(this._clippingManager=new fs,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 fs,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 Ms,this.firstDraw=!0,this._textures=new pe,this._sortedDrawableIndexList=new Ut,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 he("'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,_s),this.setClippingContextBufferForMask(null),this.gl.viewport(ps[0],ps[1],ps[2],ps[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()?rs.getInstance().getShader(this.gl).setupShaderProgramForMask(this,t,e):rs.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(){rs.deleteInstance()}setRenderState(t,e){_s=t,ps=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),rs.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 Ss;te.staticRelease=()=>{Cs.doStaticRelease()},(t=>{t.CubismClippingContext=xs,t.CubismClippingManager_WebGL=fs,t.CubismRenderTextureResource=ys,t.CubismRenderer_WebGL=Cs})(Ss||(Ss={}));const vs=new Kt;function Ps(t){if(!t.isUsingMasking())return!1;const e=function(t){var e,i;const s=t.getDrawableMaskCounts(),r=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=s[d])?e:0;if(h+=n,g<=0)continue;o++,u+=n,l=Math.max(l,g);const c=Array.from(null!=(i=r[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 bs extends U{constructor(t,i,s){super(),g(this,"settings"),g(this,"options"),g(this,"coreModel"),g(this,"motionManager"),g(this,"parallelMotionManager"),g(this,"lipSync",!0),g(this,"breath",Ji.create()),g(this,"eyeBlink"),g(this,"renderer",new Cs),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},s),this.idManager=Oe.getIdManager(),this.idParamAngleX=this.getIdSafe(qi.ParamAngleX),this.idParamAngleY=this.getIdSafe(qi.ParamAngleY),this.idParamAngleZ=this.getIdSafe(qi.ParamAngleZ),this.idParamEyeBallX=this.getIdSafe(qi.ParamEyeBallX),this.idParamEyeBallY=this.getIdSafe(qi.ParamEyeBallY),this.idParamBodyAngleX=this.getIdSafe(qi.ParamBodyAngleX),this.idParamBreath=this.getIdSafe(qi.ParamBreath),this.idParamMouthForm=this.getIdSafe(qi.ParamMouthForm),this.motionManager=new Ri(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=Ki.create(this.settings);else{const i=new Ut;for(const t of e)i.pushBack(this.idManager.getId(t));const s=Ki.create();null==(t=s.setParameterIds)||t.call(s,i),this.eyeBlink=s}const i=new Ut;var s,r;i.pushBack(new $i(this.idParamAngleX,0,15*this.options.breathDepth,6.5345,.5)),i.pushBack(new $i(this.idParamAngleY,0,8*this.options.breathDepth,3.5345,.5)),i.pushBack(new $i(this.idParamAngleZ,0,10*this.options.breathDepth,5.5345,.5)),i.pushBack(new $i(this.idParamBodyAngleX,0,4*this.options.breathDepth,15.5345,.5)),i.pushBack(new $i(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(),s=t.getDrawableMasks(),r=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=s[n])?e:[]).slice(0,t).sort((t,e)=>t-e).join(",");r.add(a)}const a=r.size;return a<=36?1:Math.ceil(a/32)}(this.coreModel)),this.renderer.useHighPrecisionMask((s=this.coreModel,"boolean"==typeof(r=this.options.useHighPrecisionMask)?r:Ps(s))),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,s]of Object.entries(e)){t[i.charAt(0).toLowerCase()+i.slice(1)]=s}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),rs.getInstance().setGlContext(t)}bindTexture(t,e){this.renderer.bindTexture(t,e)}getHitAreaDefs(){var t,e,i;const s=this.settings.json;return k(null!=(i=null!=(e=null!=(t=this.settings.hitAreas)?t:s.HitAreas)?e:s.hitAreas)?i:s.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,s,r,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==(r=null==(s=this.eyeBlink)?void 0:s.updateParameters)||r.call(s,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=_(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=vs.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(vs);const s=t.getParameter(t.FRAMEBUFFER_BINDING);this.renderer.setRenderState(s,this.viewport),this.renderer.drawModel()}extendParallelMotionManager(t){for(;this.parallelMotionManager.length<t;)this.parallelMotionManager.push(new Ui(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 Bs{}var ws;(t=>{t.ICubismModelSetting=Bs})(ws||(ws={}));var Is,Fs=(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))(Fs||{});class Es extends Bs{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=Ce.create(t,e),this.getJson()&&(this._jsonValue=new Ut,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(){Ce.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 s=0;s<e;s++)i+=t[s],s<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 Oe.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 s=e.begin();s.notEqual(e.end());s.preIncrement())t.setValue(s.ptr().first,s.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 Oe.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 Oe.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=Es,t.FrequestNode=Fs})(Is||(Is={}));class Ls extends E{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"),!Ls.isValidJSON(t))throw new TypeError("Invalid JSON.");const s=(new TextEncoder).encode(JSON.stringify(t)).buffer;Object.assign(this,new Es(s,s.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 r=this.getFileStem(this.moc);this.setModelName(r,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 s=e.Expressions;return!(void 0!==s&&(!Array.isArray(s)||s.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 s=0;s<i.length;s++){const r=i[s];(null==r?void 0:r.File)&&(r.File=t(r.File,`motions.${e}[${s}].File`),r.Sound&&(r.Sound=t(r.Sound,`motions.${e}[${s}].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 s=[],r=null!=(e=null==(t=this.getEyeBlinkParameterCount)?void 0:t.call(this))?e:0;if(r>0)for(let a=0;a<r;a++){const t=null==(i=this.getEyeBlinkParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&s.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?s.push(t):(null==t?void 0:t.Id)&&s.push(t.Id)}return s}getLipSyncParameters(){var t,e,i;const s=[],r=null!=(e=null==(t=this.getLipSyncParameterCount)?void 0:t.call(this))?e:0;if(r>0)for(let a=0;a<r;a++){const t=null==(i=this.getLipSyncParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&s.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?s.push(t):(null==t?void 0:t.Id)&&s.push(t.Id)}return s}}let Vs;C(Ls,[Es]);let Ts=20,Rs=16;function Ds(t={}){null!=t.memorySizeMB&&(Rs=t.memorySizeMB)}function As(){return Oe.isStarted()?Promise.resolve():(null!=Vs||(Vs=new Promise((t,e)=>{!function i(){try{Os(),t()}catch(s){if(Ts--,Ts<0)return void e(new Error("Failed to start up Cubism framework.",{cause:s}));p.log("Cubism","Startup failed, retrying 10ms later..."),setTimeout(i,10)}}()})),Vs)}function Os(t,e){const i=d({logFunction:console.log,loggingLevel:Ue.LogLevel_Verbose},t),s=null!=e?e:Rs;Oe.startUp(i),Oe.initialize(y(s))}const ks="FadeInTime",Ns="Link";class Us{static create(t,e){const i=Ce.create(t,e);if(!i)return null;const s=new Us,r=i.getRoot();r.getValueByString(ks).isNull()||(s._fadeTimeSeconds=r.getValueByString(ks).toFloat(.5),s._fadeTimeSeconds<0&&(s._fadeTimeSeconds=.5));const a=r.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 r=0;r<e;++r){const e=t.getValueByIndex(r),a=new zs,n=Oe.getIdManager().getId(e.getValueByString("Id").getRawString());if(a.partId=n,!e.getValueByString(Ns).isNull()){const t=e.getValueByString(Ns),i=t.getSize();for(let e=0;e<i;++e){const i=new zs,s=Oe.getIdManager().getId(t.getValueByIndex(e).getString());i.partId=s,a.link.pushBack(i)}}s._partGroups.pushBack(a.clone()),++i}s._partGroupCounts.pushBack(i)}return Ce.delete(i),s}static delete(t){}updateParameters(t,e){t!=this._lastModel&&this.reset(t),this._lastModel=t,e<0&&(e=0);let i=0;for(let s=0;s<this._partGroupCounts.getSize();s++){const r=this._partGroupCounts.at(s);this.doFade(t,e,i,r),i+=r}this.copyPartOpacities(t)}reset(t){let e=0;for(let i=0;i<this._partGroupCounts.getSize();++i){const s=this._partGroupCounts.at(i);for(let i=e;i<e+s;++i){this._partGroups.at(i).initialize(t);const s=this._partGroups.at(i).partIndex,r=this._partGroups.at(i).parameterIndex;if(!(s<0)){t.setPartOpacityByIndex(s,i==e?1:0),t.setParameterValueByIndex(r,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+=s}}copyPartOpacities(t){for(let e=0;e<this._partGroups.getSize();++e){const i=this._partGroups.at(e);if(0==i.link.getSize())continue;const s=this._partGroups.at(e).partIndex,r=t.getPartOpacityByIndex(s);for(let e=0;e<i.link.getSize();++e){const s=i.link.at(e).partIndex;s<0||t.setPartOpacityByIndex(s,r)}}}doFade(t,e,i,s){let r=-1,a=1;const n=.5;for(let o=i;o<i+s;++o){const i=this._partGroups.at(o).partIndex,s=this._partGroups.at(o).parameterIndex;if(t.getParameterValueByIndex(s)>.001){if(r>=0)break;if(r=o,0==this._fadeTimeSeconds){a=1;continue}a=t.getPartOpacityByIndex(i),a+=e/this._fadeTimeSeconds,a>1&&(a=1)}}r<0&&(r=0,a=1);for(let o=i;o<i+s;++o){const e=this._partGroups.at(o).partIndex;if(r==o)t.setPartOpacityByIndex(e,a);else{let i,s=t.getPartOpacityByIndex(e);i=a<n?-.5*a/n+1:(1-a)*n/.5;(1-i)*(1-a)>.15&&(i=1-.15/(1-a)),s>i&&(s=i),t.setPartOpacityByIndex(e,s)}}}constructor(){this._fadeTimeSeconds=.5,this._lastModel=null,this._partGroups=new Ut,this._partGroupCounts=new Ut}}class zs{constructor(t){if(this.parameterIndex=0,this.partIndex=0,this.link=new Ut,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 zs;t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=new Ut;for(let e=this.link.begin();e.notEqual(this.link.end());e.increment())t.link.pushBack(e.ptr().clone());return t}}var js,Gs,Xs;(t=>{t.CubismPose=Us,t.PartData=zs})(js||(js={}));class Hs{constructor(t=!1,e=!1){this.isOverridden=t,this.isParameterRepeated=e}}class qs{constructor(t=!1,e=new se){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class Ys{constructor(t=!1,e=new se){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class Ws{constructor(t=!1,e=!1){this.isOverridden=t,this.isCulling=e}get isOverwritten(){return this.isOverridden}}class Js{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,s,r=1){this._userMultiplyColors.at(t).color.r=e,this._userMultiplyColors.at(t).color.g=i,this._userMultiplyColors.at(t).color.b=s,this._userMultiplyColors.at(t).color.a=r}setScreenColorByTextureColor(t,e){this.setScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setScreenColorByRGBA(t,e,i,s,r=1){this._userScreenColors.at(t).color.r=e,this._userScreenColors.at(t).color.g=i,this._userScreenColors.at(t).color.b=s,this._userScreenColors.at(t).color.a=r}getPartMultiplyColor(t){return this._userPartMultiplyColors.at(t).color}getPartScreenColor(t){return this._userPartScreenColors.at(t).color}setPartColor(t,e,i,s,r,a,n){if(a.at(t).color.r=e,a.at(t).color.g=i,a.at(t).color.b=s,a.at(t).color.a=r,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=s,n.at(a).color.a=r}}setPartMultiplyColorByTextureColor(t,e){this.setPartMultiplyColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartMultiplyColorByRGBA(t,e,i,s,r){this.setPartColor(t,e,i,s,r,this._userPartMultiplyColors,this._userMultiplyColors)}setPartScreenColorByTextureColor(t,e){this.setPartScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartScreenColorByRGBA(t,e,i,s,r){this.setPartColor(t,e,i,s,r,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 ue("getOverwriteFlagForModelMultiplyColors() is a deprecated function. Please use getOverrideFlagForModelMultiplyColors()."),this.getOverrideFlagForModelMultiplyColors()}getOverrideFlagForModelMultiplyColors(){return this._isOverriddenModelMultiplyColors}getOverwriteFlagForModelScreenColors(){return ue("getOverwriteFlagForModelScreenColors() is a deprecated function. Please use getOverrideFlagForModelScreenColors()."),this.getOverrideFlagForModelScreenColors()}getOverrideFlagForModelScreenColors(){return this._isOverriddenModelScreenColors}setOverwriteFlagForModelMultiplyColors(t){ue("setOverwriteFlagForModelMultiplyColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelMultiplyColors(value: boolean)."),this.setOverrideFlagForModelMultiplyColors(t)}setOverrideFlagForModelMultiplyColors(t){this._isOverriddenModelMultiplyColors=t}setOverwriteFlagForModelScreenColors(t){ue("setOverwriteFlagForModelScreenColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelScreenColors(value: boolean)."),this.setOverrideFlagForModelScreenColors(t)}setOverrideFlagForModelScreenColors(t){this._isOverriddenModelScreenColors=t}getOverwriteFlagForDrawableMultiplyColors(t){return ue("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 ue("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){ue("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){ue("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 ue("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 ue("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,s){ue("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,s)}setOverrideColorForPartColors(t,e,i,s){i.at(t).isOverridden=e;for(let r=0;r<this._partChildDrawables.at(t).getSize();++r){const a=this._partChildDrawables.at(t).at(r);s.at(a).isOverridden=e,e&&(s.at(a).color.r=i.at(t).color.r,s.at(a).color.g=i.at(t).color.g,s.at(a).color.b=i.at(t).color.b,s.at(a).color.a=i.at(t).color.a)}}setOverwriteColorForPartMultiplyColors(t,e){ue("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){ue("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 ue("getOverwriteFlagForModelCullings() is a deprecated function. Please use getOverrideFlagForModelCullings()."),this.getOverrideFlagForModelCullings()}getOverrideFlagForModelCullings(){return this._isOverriddenCullings}setOverwriteFlagForModelCullings(t){ue("setOverwriteFlagForModelCullings(isOverriddenCullings: boolean) is a deprecated function. Please use setOverrideFlagForModelCullings(isOverriddenCullings: boolean)."),this.setOverrideFlagForModelCullings(t)}setOverrideFlagForModelCullings(t){this._isOverriddenCullings=t}getOverwriteFlagForDrawableCullings(t){return ue("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){ue("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 Oe.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):(ne(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):(ne(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 Oe.getIdManager().getId(this._model.parameters.ids[t])}getParameterValueByIndex(t){return this._notExistParameterValues.isExist(t)?this._notExistParameterValues.getValue(t):(ne(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):(ne(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 s=this.getParameterIndex(t);this.setParameterValueByIndex(s,e,i)}addParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)+e*i)}addParameterValueById(t,e,i=1){const s=this.getParameterIndex(t);this.addParameterValueByIndex(s,e,i)}isRepeat(t){if(this._notExistParameterValues.isExist(t))return!1;let e;return ne(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;ne(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],s=this._model.parameters.minimumValues[t],r=i-s;if(i<e){const t=Ge.mod(e-i,r);e=Number.isNaN(t)?i:s+t}if(e<s){const t=Ge.mod(s-e,r);e=Number.isNaN(t)?s:i-t}return e}getParameterClampValue(t,e){if(this._notExistParameterValues.isExist(t))return e;ne(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],s=this._model.parameters.minimumValues[t];return Ge.clamp(e,s,i)}getParameterRepeats(t){return 0!=this._model.parameters.repeats[t]}multiplyParameterValueById(t,e,i=1){const s=this.getParameterIndex(t);this.multiplyParameterValueByIndex(s,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 Oe.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,s=new se;return s.r=e[i],s.g=e[i+1],s.b=e[i+2],s.a=e[i+3],s}getDrawableScreenColor(t){const e=this._model.drawables.screenColors,i=4*t,s=new se;return s.r=e[i],s.g=e[i+1],s.b=e[i+2],s.a=e[i+3],s}getDrawableParentPartIndex(t){return this._model.drawables.parentPartIndices[t]}getDrawableBlendMode(t){const e=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(e[t])?ie.CubismBlendMode_Additive:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(e[t])?ie.CubismBlendMode_Multiplicative:ie.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(){ne(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(Oe.getIdManager().getId(t[i])),this._userParameterRepeatDataList.pushBack(new Hs(!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(Oe.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 s=new Ws(!1,!1);for(let r=0;r<t;++r){const t=new se(1,1,1,1),e=new se(0,0,0,1),s=new Ys(!1,t),a=new Ys(!1,e);this._userPartMultiplyColors.pushBack(s),this._userPartScreenColors.pushBack(a),this._partChildDrawables.pushBack(new Ut),this._partChildDrawables.at(r).prepareCapacity(i)}for(let t=0;t<i;++t){const i=new se(1,1,1,1),r=new se(0,0,0,1),a=new qs(!1,i),n=new qs(!1,r);this._drawableIds.pushBack(Oe.getIdManager().getId(e[t])),this._userMultiplyColors.pushBack(a),this._userScreenColors.pushBack(n),this._userCullings.pushBack(s);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 Ut,this._parameterIds=new Ut,this._drawableIds=new Ut,this._partIds=new Ut,this._isOverriddenParameterRepeat=!0,this._isOverriddenModelMultiplyColors=!1,this._isOverriddenModelScreenColors=!1,this._isOverriddenCullings=!1,this._modelOpacity=1,this._userParameterRepeatDataList=new Ut,this._userMultiplyColors=new Ut,this._userScreenColors=new Ut,this._userCullings=new Ut,this._userPartMultiplyColors=new Ut,this._userPartScreenColors=new Ut,this._partChildDrawables=new Ut,this._notExistPartId=new pe,this._notExistParameterId=new pe,this._notExistParameterValues=new pe,this._notExistPartOpacities=new pe}release(){this._model.release(),this._model=null}}(t=>{t.CubismModel=Js})(Gs||(Gs={}));class $s{static create(t,e){let i=null;if(e){if(!this.hasMocConsistency(t))return he("Inconsistent MOC3."),i}const s=Live2DCubismCore.Moc.fromArrayBuffer(t);return s&&(i=new $s(s),i._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(s,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 Js(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(){ne(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=$s})(Xs||(Xs={}));var Zs,Ks=(t=>(t[t.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",t))(Ks||{}),Qs=(t=>(t[t.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",t[t.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",t[t.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",t))(Qs||{});class tr{constructor(){this.gravity=new ze(0,0),this.wind=new ze(0,0)}}class er{}class ir{}class sr{constructor(){this.initialPosition=new ze(0,0),this.position=new ze(0,0),this.lastPosition=new ze(0,0),this.lastGravity=new ze(0,0),this.force=new ze(0,0),this.velocity=new ze(0,0)}}class rr{constructor(){this.normalizationPosition=new ir,this.normalizationAngle=new ir}}class ar{constructor(){this.source=new er}}class nr{constructor(){this.destination=new er,this.translationScale=new ze(0,0)}}class or{constructor(){this.settings=new Ut,this.inputs=new Ut,this.outputs=new Ut,this.particles=new Ut,this.gravity=new ze(0,0),this.wind=new ze(0,0),this.fps=0}}(t=>{t.CubismPhysicsInput=ar,t.CubismPhysicsNormalization=ir,t.CubismPhysicsOutput=nr,t.CubismPhysicsParameter=er,t.CubismPhysicsParticle=sr,t.CubismPhysicsRig=or,t.CubismPhysicsSource=Qs,t.CubismPhysicsSubRig=rr,t.CubismPhysicsTargetType=Ks,t.PhysicsJsonEffectiveForces=tr})(Zs||(Zs={}));const lr="Position",ur="Angle",hr="Type",dr="Meta",gr="EffectiveForces",cr="Gravity",mr="Wind",pr="PhysicsSettings",_r="Normalization",fr="Minimum",yr="Maximum",xr="Default",Mr="Reflect",Cr="Weight",Sr="Input",vr="Output",Pr="Vertices";class br{constructor(t,e){this._json=Ce.create(t,e)}release(){Ce.delete(this._json)}getGravity(){const t=new ze(0,0);return t.x=this._json.getRoot().getValueByString(dr).getValueByString(gr).getValueByString(cr).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString(dr).getValueByString(gr).getValueByString(cr).getValueByString("Y").toFloat(),t}getWind(){const t=new ze(0,0);return t.x=this._json.getRoot().getValueByString(dr).getValueByString(gr).getValueByString(mr).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString(dr).getValueByString(gr).getValueByString(mr).getValueByString("Y").toFloat(),t}getFps(){return this._json.getRoot().getValueByString(dr).getValueByString("Fps").toFloat(0)}getSubRigCount(){return this._json.getRoot().getValueByString(dr).getValueByString("PhysicsSettingCount").toInt()}getTotalInputCount(){return this._json.getRoot().getValueByString(dr).getValueByString("TotalInputCount").toInt()}getTotalOutputCount(){return this._json.getRoot().getValueByString(dr).getValueByString("TotalOutputCount").toInt()}getVertexCount(){return this._json.getRoot().getValueByString(dr).getValueByString("VertexCount").toInt()}getNormalizationPositionMinimumValue(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(_r).getValueByString(lr).getValueByString(fr).toFloat()}getNormalizationPositionMaximumValue(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(_r).getValueByString(lr).getValueByString(yr).toFloat()}getNormalizationPositionDefaultValue(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(_r).getValueByString(lr).getValueByString(xr).toFloat()}getNormalizationAngleMinimumValue(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(_r).getValueByString(ur).getValueByString(fr).toFloat()}getNormalizationAngleMaximumValue(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(_r).getValueByString(ur).getValueByString(yr).toFloat()}getNormalizationAngleDefaultValue(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(_r).getValueByString(ur).getValueByString(xr).toFloat()}getInputCount(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Sr).getVector().getSize()}getInputWeight(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Sr).getValueByIndex(e).getValueByString(Cr).toFloat()}getInputReflect(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Sr).getValueByIndex(e).getValueByString(Mr).toBoolean()}getInputType(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Sr).getValueByIndex(e).getValueByString(hr).getRawString()}getInputSourceId(t,e){return Oe.getIdManager().getId(this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Sr).getValueByIndex(e).getValueByString("Source").getValueByString("Id").getRawString())}getOutputCount(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(vr).getVector().getSize()}getOutputVertexIndex(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(vr).getValueByIndex(e).getValueByString("VertexIndex").toInt()}getOutputAngleScale(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(vr).getValueByIndex(e).getValueByString("Scale").toFloat()}getOutputWeight(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(vr).getValueByIndex(e).getValueByString(Cr).toFloat()}getOutputDestinationId(t,e){return Oe.getIdManager().getId(this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(vr).getValueByIndex(e).getValueByString("Destination").getValueByString("Id").getRawString())}getOutputType(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(vr).getValueByIndex(e).getValueByString(hr).getRawString()}getOutputReflect(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(vr).getValueByIndex(e).getValueByString(Mr).toBoolean()}getParticleCount(t){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Pr).getVector().getSize()}getParticleMobility(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Pr).getValueByIndex(e).getValueByString("Mobility").toFloat()}getParticleDelay(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Pr).getValueByIndex(e).getValueByString("Delay").toFloat()}getParticleAcceleration(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Pr).getValueByIndex(e).getValueByString("Acceleration").toFloat()}getParticleRadius(t,e){return this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Pr).getValueByIndex(e).getValueByString("Radius").toFloat()}getParticlePosition(t,e){const i=new ze(0,0);return i.x=this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Pr).getValueByIndex(e).getValueByString(lr).getValueByString("X").toFloat(),i.y=this._json.getRoot().getValueByString(pr).getValueByIndex(t).getValueByString(Pr).getValueByIndex(e).getValueByString(lr).getValueByString("Y").toFloat(),i}}var Br;(t=>{t.CubismPhysicsJson=br})(Br||(Br={}));const wr="Angle";class Ir{static create(t,e){const i=new Ir;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 or;let i=new br(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,rr,!0),this._physicsRig.inputs.updateSize(i.getTotalInputCount(),ar,!0),this._physicsRig.outputs.updateSize(i.getTotalOutputCount(),nr,!0),this._physicsRig.particles.updateSize(i.getVertexCount(),sr,!0),this._currentRigOutputs.clear(),this._previousRigOutputs.clear();let s=0,r=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=s;for(let r=0;r<this._physicsRig.settings.at(n).inputCount;++r)this._physicsRig.inputs.at(s+r).sourceParameterIndex=-1,this._physicsRig.inputs.at(s+r).weight=i.getInputWeight(n,r),this._physicsRig.inputs.at(s+r).reflect=i.getInputReflect(n,r),"X"==i.getInputType(n,r)?(this._physicsRig.inputs.at(s+r).type=Qs.CubismPhysicsSource_X,this._physicsRig.inputs.at(s+r).getNormalizedParameterValue=Lr):"Y"==i.getInputType(n,r)?(this._physicsRig.inputs.at(s+r).type=Qs.CubismPhysicsSource_Y,this._physicsRig.inputs.at(s+r).getNormalizedParameterValue=Vr):i.getInputType(n,r)==wr&&(this._physicsRig.inputs.at(s+r).type=Qs.CubismPhysicsSource_Angle,this._physicsRig.inputs.at(s+r).getNormalizedParameterValue=Tr),this._physicsRig.inputs.at(s+r).source.targetType=Ks.CubismPhysicsTargetType_Parameter,this._physicsRig.inputs.at(s+r).source.id=i.getInputSourceId(n,r);s+=this._physicsRig.settings.at(n).inputCount,this._physicsRig.settings.at(n).outputCount=i.getOutputCount(n),this._physicsRig.settings.at(n).baseOutputIndex=r;const t=new Er;t.outputs.resize(this._physicsRig.settings.at(n).outputCount);const e=new Er;e.outputs.resize(this._physicsRig.settings.at(n).outputCount);for(let s=0;s<this._physicsRig.settings.at(n).outputCount;++s)t.outputs.set(s,0),e.outputs.set(s,0),this._physicsRig.outputs.at(r+s).destinationParameterIndex=-1,this._physicsRig.outputs.at(r+s).vertexIndex=i.getOutputVertexIndex(n,s),this._physicsRig.outputs.at(r+s).angleScale=i.getOutputAngleScale(n,s),this._physicsRig.outputs.at(r+s).weight=i.getOutputWeight(n,s),this._physicsRig.outputs.at(r+s).destination.targetType=Ks.CubismPhysicsTargetType_Parameter,this._physicsRig.outputs.at(r+s).destination.id=i.getOutputDestinationId(n,s),"X"==i.getOutputType(n,s)?(this._physicsRig.outputs.at(r+s).type=Qs.CubismPhysicsSource_X,this._physicsRig.outputs.at(r+s).getValue=Rr,this._physicsRig.outputs.at(r+s).getScale=kr):"Y"==i.getOutputType(n,s)?(this._physicsRig.outputs.at(r+s).type=Qs.CubismPhysicsSource_Y,this._physicsRig.outputs.at(r+s).getValue=Dr,this._physicsRig.outputs.at(r+s).getScale=Nr):i.getOutputType(n,s)==wr&&(this._physicsRig.outputs.at(r+s).type=Qs.CubismPhysicsSource_Angle,this._physicsRig.outputs.at(r+s).getValue=Ar,this._physicsRig.outputs.at(r+s).getScale=Ur),this._physicsRig.outputs.at(r+s).reflect=i.getOutputReflect(n,s);this._currentRigOutputs.pushBack(t),this._previousRigOutputs.pushBack(e),r+=this._physicsRig.settings.at(n).outputCount,this._physicsRig.settings.at(n).particleCount=i.getParticleCount(n),this._physicsRig.settings.at(n).baseParticleIndex=a;for(let s=0;s<this._physicsRig.settings.at(n).particleCount;++s)this._physicsRig.particles.at(a+s).mobility=i.getParticleMobility(n,s),this._physicsRig.particles.at(a+s).delay=i.getParticleDelay(n,s),this._physicsRig.particles.at(a+s).acceleration=i.getParticleAcceleration(n,s),this._physicsRig.particles.at(a+s).radius=i.getParticleRadius(n,s),this._physicsRig.particles.at(a+s).position=i.getParticlePosition(n,s);a+=this._physicsRig.settings.at(n).particleCount}this.initialize(),i.release(),i=void 0,i=null}stabilization(t){var e,i,s,r;let a,n,o,l;const u=new ze;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!=(r=null==(s=this._parameterInputCaches)?void 0:s.length)?r: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=Ge.degreesToRadian(-a.angle),u.x=u.x*Ge.cos(o)-u.y*Ge.sin(o),u.y=u.x*Ge.sin(o)+u.y*Ge.cos(o),jr(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 s=new ze;s=c[i].position.substract(c[i-1].position),l=g[e].getValue(s,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 r=g[e].destinationParameterIndex,a=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(m.subarray(r))):m.slice(r);Gr(a,_[r],p[r],l,g[e]);for(let t=r,e=0;t<this._parameterCaches.length;t++,e++)m[t]=this._parameterCaches[t]=a[e]}}}evaluate(t,e){var i,s,r,a;let n,o,l,u;const h=new ze;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!=(s=null==(i=this._parameterCaches)?void 0:i.length)?s:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(null!=(a=null==(r=this._parameterInputCaches)?void 0:r.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=Ge.degreesToRadian(-n.angle),h.x=h.x*Ge.cos(l)-h.y*Ge.sin(l),h.y=h.x*Ge.sin(l)+h.y*Ge.cos(l),zr(m,d.particleCount,h,n.angle,this._options.wind,.001*d.normalizationPosition.maximum,x,5);for(let e=0;e<d.outputCount;++e){const s=c[e].vertexIndex;if(-1==c[e].destinationParameterIndex&&(c[e].destinationParameterIndex=t.getParameterIndex(c[e].destination.id)),s<1||s>=d.particleCount)continue;const r=new ze;r.x=m[s].position.x-m[s-1].position.x,r.y=m[s].position.y-m[s-1].position.y,u=c[e].getValue(r,m,s,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);Gr(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 M=this._currentRemainTime/x;this.interpolate(t,M)}interpolate(t,e){let i,s;const r=t.getModel().parameters.values,a=t.getModel().parameters.maximumValues,n=t.getModel().parameters.minimumValues;for(let o=0;o<this._physicsRig.subRigCount;++o){s=this._physicsRig.settings.at(o),i=this._physicsRig.outputs.get(s.baseOutputIndex);for(let t=0;t<s.outputCount;++t){if(-1==i[t].destinationParameterIndex)continue;const s=i[t].destinationParameterIndex,l=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(r.subarray(s))):r.slice(s);Gr(l,n[s],a[s],this._previousRigOutputs.at(o).outputs.at(t)*(1-e)+this._currentRigOutputs.at(o).outputs.at(t)*e,i[t]);for(let t=s,e=0;t<r.length;t++,e++)r[t]=l[e]}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._physicsRig=null,this._options=new Fr,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=new Ut,this._previousRigOutputs=new Ut,this._currentRemainTime=0,this._parameterCaches=null,this._parameterInputCaches=null}release(){this._physicsRig=void 0,this._physicsRig=null}initialize(){let t,e,i;for(let s=0;s<this._physicsRig.subRigCount;++s){e=this._physicsRig.settings.at(s),t=this._physicsRig.particles.get(e.baseParticleIndex),t[0].initialPosition=new ze(0,0),t[0].lastPosition=new ze(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new ze(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new ze(0,0),t[0].force=new ze(0,0);for(let s=1;s<e.particleCount;++s)i=new ze(0,0),i.y=t[s].radius,t[s].initialPosition=new ze(t[s-1].initialPosition.x+i.x,t[s-1].initialPosition.y+i.y),t[s].position=new ze(t[s].initialPosition.x,t[s].initialPosition.y),t[s].lastPosition=new ze(t[s].initialPosition.x,t[s].initialPosition.y),t[s].lastGravity=new ze(0,-1),t[s].lastGravity.y*=-1,t[s].velocity=new ze(0,0),t[s].force=new ze(0,0)}}}class Fr{constructor(){this.gravity=new ze(0,0),this.wind=new ze(0,0)}}class Er{constructor(){this.outputs=new Ut(0)}}function Lr(t,e,i,s,r,a,n,o,l,u){t.x+=Xr(i,s,r,a,n.minimum,n.maximum,n.defalut,l)*u}function Vr(t,e,i,s,r,a,n,o,l,u){t.y+=Xr(i,s,r,a,n.minimum,n.maximum,n.defalut,l)*u}function Tr(t,e,i,s,r,a,n,o,l,u){e.angle+=Xr(i,s,r,a,o.minimum,o.maximum,o.defalut,l)*u}function Rr(t,e,i,s,r){let a=t.x;return s&&(a*=-1),a}function Dr(t,e,i,s,r){let a=t.y;return s&&(a*=-1),a}function Ar(t,e,i,s,r){let a;return r=i>=2?e[i-1].position.substract(e[i-2].position):r.multiplyByScaler(-1),a=Ge.directionToRadian(r,t),s&&(a*=-1),a}function Or(t,e){return Ge.min(t,e)+function(t,e){const i=Ge.max(t,e),s=Ge.min(t,e);return Ge.abs(i-s)}(t,e)/2}function kr(t,e){return JSON.parse(JSON.stringify(t.x))}function Nr(t,e){return JSON.parse(JSON.stringify(t.y))}function Ur(t,e){return JSON.parse(JSON.stringify(e))}function zr(t,e,i,s,r,a,n,o){let l,u,h=new ze(0,0),d=new ze(0,0),g=new ze(0,0),c=new ze(0,0);t[0].position=new ze(i.x,i.y);const m=Ge.degreesToRadian(s),p=Ge.radianToDirection(m);p.normalize();for(let _=1;_<e;++_)t[_].force=p.multiplyByScaler(t[_].acceleration).add(r),t[_].lastPosition=new ze(t[_].position.x,t[_].position.y),l=t[_].delay*n*30,h=t[_].position.substract(t[_-1].position),u=Ge.directionToRadian(t[_].lastGravity,p)/o,h.x=Ge.cos(u)*h.x-h.y*Ge.sin(u),h.y=Ge.sin(u)*h.x+h.y*Ge.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)),Ge.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 ze(0,0),t[_].lastGravity=new ze(p.x,p.y)}function jr(t,e,i,s,r,a){let n=new ze(0,0);t[0].position=new ze(i.x,i.y);const o=Ge.degreesToRadian(s),l=Ge.radianToDirection(o);l.normalize();for(let u=1;u<e;++u)t[u].force=l.multiplyByScaler(t[u].acceleration).add(r),t[u].lastPosition=new ze(t[u].position.x,t[u].position.y),t[u].velocity=new ze(0,0),n=t[u].force,n.normalize(),n=n.multiplyByScaler(t[u].radius),t[u].position=t[u-1].position.add(n),Ge.abs(t[u].position.x)<a&&(t[u].position.x=0),t[u].force=new ze(0,0),t[u].lastGravity=new ze(l.x,l.y)}function Gr(t,e,i,s,r){let a;a=s*r.getScale(r.translationScale,r.angleScale),a<e?(a<r.valueBelowMinimum&&(r.valueBelowMinimum=a),a=e):a>i&&(a>r.valueExceededMaximum&&(r.valueExceededMaximum=a),a=i);const n=r.weight/100;n>=1||(a=t[0]*(1-n)+a*n),t[0]=a}function Xr(t,e,i,s,r,a,n,o){let l=0;const u=Ge.max(i,e);u<t&&(t=u);const h=Ge.min(i,e);h>t&&(t=h);const d=Ge.min(r,a),g=Ge.max(r,a),c=n,m=Or(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 Hr;function qr(){var t;null==(t=this.__moc)||t.release()}(t=>{t.CubismPhysics=Ir,t.Options=Fr})(Hr||(Hr={})),lt.registerRuntime({version:4,ready:As,test:t=>t instanceof Ls||Ls.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 Ls(t),createCoreModel(t,e){const i=$s.create(t,!!(null==e?void 0:e.checkMocConsistency));try{const t=i.createModel();return t.__moc=i,t}catch(s){try{i.release()}catch(r){p.warn("CubismFactory","Failed to release moc after core model creation failed.",r)}throw s}},createInternalModel(t,e,i){const s=new bs(t,e,i),r=t;return r.__moc&&(s.__moc=r.__moc,delete r.__moc,s.once("destroy",qr)),s},createPhysics(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism physics data must be an ArrayBuffer.");return Ir.create(e,e.byteLength)},createPose(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism pose data must be an ArrayBuffer.");return Us.create(e,e.byteLength)}}),t.CubismExpressionManager=ai,t.CubismInternalModel=bs,t.CubismLegacyExpressionManager=Bt,t.CubismLegacyInternalModel=Tt,t.CubismLegacyModelSettings=q,t.CubismLegacyMotionManager=It,t.CubismLegacyParallelMotionManager=Et,t.CubismModelSettings=Ls,t.CubismMotionManager=Ri,t.CubismParallelMotionManager=Ui,t.ExpressionManager=B,t.FileLoader=nt,t.FocusController=F,t.InternalModel=U,t.LOGICAL_HEIGHT=2,t.LOGICAL_WIDTH=2,t.Live2DExpression=bt,t.Live2DEyeBlink=Lt,t.Live2DFactory=lt,t.Live2DLoader=H,t.Live2DModel=vt,t.Live2DPhysics=At,t.Live2DPlugin=St,t.Live2DPose=kt,t.Live2DTransform=mt,t.MBToByte=y,t.ModelSettings=E,t.MotionManager=O,t.MotionPreloadStrategy=A,t.MotionPriority=L,t.MotionState=V,t.SoundManager=D,t.VERSION="1.2.0",t.VOLUME=R,t.XHRLoader=G,t.applyMixins=C,t.clamp=_,t.config=m,t.configureCubismSDK=Ds,t.copyArray=M,t.copyProperty=x,t.cubismReady=As,t.folderName=S,t.logger=p,t.normalizeHitAreaDefs=k,t.rand=f,t.reconfigureCubismSDK=function(t={}){Ds(t),Oe.isInitialized()&&Oe.dispose(),Oe.isStarted()&&Oe.cleanUp(),Os(void 0,t.memorySizeMB)},t.remove=v,t.resolveURL=b,t.startUpCubism=Os,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 s=Object.defineProperty,r=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?s(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((s,r)=>{var a=t=>{try{o(i.next(t))}catch(e){r(e)}},n=t=>{try{o(i.throw(t))}catch(e){r(e)}},o=t=>t.done?s(t.value):Promise.resolve(t.value).then(a,n);o((i=i.apply(t,e)).next())});const m={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: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"}))},p={log(t,...e){m.logLevel<=m.LOG_LEVEL_VERBOSE&&console.log(`[${t}]`,...e)},warn(t,...e){m.logLevel<=m.LOG_LEVEL_WARNING&&console.warn(`[${t}]`,...e)},error(t,...e){m.logLevel<=m.LOG_LEVEL_ERROR&&console.error(`[${t}]`,...e)}};function _(t,e,i){return t<e?e:t>i?i:t}function f(t,e){return Math.random()*(e-t)+t}function y(t){return 1024*t*1024}function x(t,e,i,s,r){const a=e[s];null!==a&&typeof a===t&&(i[r]=a)}function M(t,e,i,s,r){const a=e[s];Array.isArray(a)&&(i[r]=a.filter(e=>null!==e&&typeof e===t))}function C(t,e){e.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i))})})}function S(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 v(t,e){const i=t.indexOf(e);-1!==i&&t.splice(i,1)}const b=/^[a-zA-Z][a-zA-Z0-9+.-]*:/;function P(t,e){if(!e)return t;if(b.test(e))return e;if(e.startsWith("/"))return b.test(t)?new URL(e,t).toString():e;if(b.test(t))return new URL(e,t).toString();const i="http://example.com",s=t.startsWith("/")?i+t:`${i}/${t}`,r=new URL(e,s);let a=r.pathname+r.search+r.hash;return!t.startsWith("/")&&a.startsWith("/")&&(a=a.slice(1)),a}class B 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 p.warn(this.tag,`Undefined expression at [${t}]`);if(null===this.expressions[t])return void p.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 w=40/7.5,I=1/150;class F{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=_(t,-1,1),this.targetY=_(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 s=Math.sqrt(u(e,2)+u(i,2)),r=w/(1e3/t);let a=r*(e/s)-this.vx,n=r*(i/s)-this.vy;const o=Math.sqrt(u(a,2)+u(n,2)),l=r*I*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*s)-l);h>d&&(this.vx*=d/h,this.vy*=d/h),this.x+=this.vx,this.y+=this.vy}}class E{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=S(this.url)}normalizeName(){this.name&&"name"!==this.name.toLowerCase()||(this.name=S(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 P(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 s=this.resolveURL(e);if(!t.includes(s)){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 L=(t=>(t[t.NONE=0]="NONE",t[t.IDLE=1]="IDLE",t[t.NORMAL=2]="NORMAL",t[t.FORCE=3]="FORCE",t))(L||{});class V{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 p.log(this.tag,"Cannot start a motion with MotionPriority.NONE."),!1;if(t===this.currentGroup&&e===this.currentIndex)return p.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 p.log(this.tag,"Motion is already reserved.",this.dump(t,e)),!1;if(1===i){if(0!==this.currentPriority)return p.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(t,e)),!1;if(void 0!==this.reservedIdleGroup)return p.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 p.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 p.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,s){if(1===s){if(this.setReservedIdle(void 0,void 0),0!==this.currentPriority)return p.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 p.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,s),!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!m.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 T="SoundManager",R=.5;i.sound.disableAutoPause=!0;class D{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,s)=>{const r=i.Sound.from({url:t,volume:this._volume,preload:!0,loaded:()=>{r.media instanceof i.webaudio.WebAudioMedia||s(new Error(`Error: ${t} is not WebAudioMedia`)),e(r)}})});return yield e}catch(s){return p.warn(T,`Error occurred on "${t}"`,s),null==e||e(s),null}})}static play(t,e){t.play({singleInstance:!0,complete:()=>{null==e||e(),t.destroy()}})}static addAnalyzer(t,e){const i=t.media,s=e.createBufferSource();s.buffer=i.buffer;const r=e.createAnalyser();return r.fftSize=m.fftSize,r.minDecibels=-90,r.maxDecibels=-10,r.smoothingTimeConstant=.85,s.connect(r),s.start(0),this.analysers.push(r),r}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 s=Math.sqrt(i/e.length),r=20*Math.log10(s||u(10,-5)),a=Math.min(Math.max((r-t.minDecibels)/(t.maxDecibels-t.minDecibels),0),1);return parseFloat(a.toFixed(1))}static dispose(t){t.pause(),v(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=>{p.warn(T,"Failed to close AudioContext.",t)})}for(let t=this.audios.length-1;t>=0;t--)this.dispose(this.audios[t])}}g(D,"audios",[]),g(D,"analysers",[]),g(D,"contexts",[]),g(D,"_volume",R);var A=(t=>(t.ALL="ALL",t.IDLE="IDLE",t.NONE="NONE",t))(A||{});class O extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"settings"),g(this,"motionGroups",{}),g(this,"state",new V),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 p.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,s;if(this.destroyed)return;if(!this.getMotionDefinition(t,e))return;const r=null!=(s=(i=this.motionGroups)[t])?s:i[t]=[];if(null===r[e])return void p.warn(this.tag,`Cannot start motion at "${t}"[${e}] because it's already failed in loading.`);if(r[e])return r[e];const a=yield this._loadMotion(t,e);return this.destroyed?void 0:(r[e]=null!=a?a:null,a)})}_loadMotion(t,e){throw new Error("Not implemented.")}initializeAudio(t,e){this.currentAudio=t,D.volume=e,this.currentContext=t.context.audioContext,this.currentAnalyzer=D.addAnalyzer(this.currentAudio,this.currentContext)}speak(t){return c(this,arguments,function*(t,{volume:e=.5,expression:i,resetExpression:s=!0,onFinish:r,onError:a}={}){if(!m.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 D.add(u,(t,e=this)=>{p.error(this.tag,"Error during audio playback:",t),null==a||a(t),s&&i&&e.expressionManager&&e.expressionManager.resetExpression(),e.currentAudio=void 0}),this.initializeAudio(n,e)}catch(h){return p.warn(this.tag,"Failed to create audio",o,h),!1}if(n){let t=!0;try{m.motionSync&&D.play(n,()=>{null==r||r(),s&&i&&this.expressionManager&&this.expressionManager.resetExpression(),this.currentAudio=void 0})}catch(h){p.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=L.NORMAL,{sound:s,volume:r=.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!=L.FORCE)return!1;const h=this.getMotionDefinition(t,e);if(!h)return!1;let d,g;this.currentAudio&&D.dispose(this.currentAudio);const c=s&&s.startsWith("data:");if(s&&!c){const t=document.createElement("a");t.href=s,g=s=t.href}else g=this.getSoundFile(h),g&&(g=this.settings.resolveURL(g));const _=g;if(_)try{d=yield D.add(_,(t,e=this)=>{p.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,r)}catch(y){p.warn(this.tag,"Failed to create audio",g,y)}const f=yield this.loadMotion(t,e);if(d&&m.motionSync)try{D.play(d,(t=this)=>{null==o||o(),n&&a&&t.expressionManager&&t.expressionManager.resetExpression(),t.currentAudio=void 0})}catch(y){p.warn(this.tag,"Failed to play audio",d.url,y)}return this.state.start(f,t,e,i)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),p.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,f&&this._startMotion(f,void 0,u),!0):(d&&(D.dispose(d),this.currentAudio=void 0),!1)})}startRandomMotion(t,e){return c(this,arguments,function*(t,e,{sound:i,volume:s=.5,expression:r,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:s,expression:r,resetExpression:a,onFinish:n,onError:o})}}return!1})}stopSpeaking(){this.currentAudio&&(D.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,L.IDLE)),this.updateParameters(t,e)}mouthSync(){return this.currentAnalyzer?D.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,L.FORCE))return null;const s=this.getMotionDefinition(t,e);if(!s)return null;this.currentAudio&&D.dispose(this.currentAudio);const r=yield this.loadMotion(t,e);return this.state.start(r,t,e,L.FORCE)?(this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),p.log(this.tag,"Start motion:",this.getMotionName(s)),this.emit("motionStart",t,e,void 0),i&&this.expressionManager&&this.state.shouldOverrideExpression()&&(yield this.expressionManager.setExpression(i)),r):null})}getMotionDefinition(t,e){var i,s;const r=null==(s=null==(i=this.definitions)?void 0:i[t])?void 0:s[e];return r||p.warn(this.tag,`Undefined motion at "${t}"[${e}]`),r}}function k(t,e){return 2*e*t.scale}function N(t){return 2*t.scale}function U(t,e,i){t.scale=i/(2*e)}function z(t,e){t.scale=e/2}function j(t,e){t.x=e}function G(t,e){t.y=e}function X(t,e,i){j(t,i-k(t,e)/2)}function H(t,e){G(t,e-N(t)/2)}function Y(t,e,i){j(t,i-k(t,e))}function q(t,e){G(t,e-N(t))}function W(t,e,i,s){if(e<=0||i<=0)return t.identity(),{width:0,height:0};const r=function(t){const e=[];for(const[i,s]of Object.entries(t))"number"==typeof s&&e.push([i,s]);return e}(s),a=e/i,n={scale:1,x:0,y:0};for(const[u,h]of r)"width"===u?U(n,a,h):"height"===u&&z(n,h);for(const[u,h]of r)"x"===u?j(n,h):"y"===u?G(n,h):"centerX"===u?X(n,a,h):"centerY"===u?H(n,h):"top"===u?G(n,h):"bottom"===u?q(n,h):"left"===u?j(n,h):"right"===u&&Y(n,a,h);const o=i/2,l=2*a/2;return t.identity(),function(t,e){t.a=e,t.b=0,t.c=0,t.d=e}(t,n.scale),t.tx=o*(n.x+l)-e*n.scale/2,t.ty=o*(1-n.y)-i*n.scale/2,{width:e*n.scale,height:i*n.scale}}function J(t,e){if(!Array.isArray(t))return[];const i=[];for(const s of t){if(!s||"object"!=typeof s)continue;const t=s,r="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;r&&a&&i.push({id:r,name:a,index:e(r)})}return i}const $={x:0,y:0,width:0,height:0};class Z extends e.EventEmitter{constructor(){super(...arguments),g(this,"focusController",new F),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=function(t,e,i,s){var r,a;const n=d({width:2,height:2},s),o=null!=(r=n.width)?r:2,l=null!=(a=n.height)?a:2;t.identity(),t.scale(o/2,l/2);const u=e*t.a,h=i*t.d,g=void 0!==n.x&&n.x-o/2||void 0!==n.centerX&&n.centerX||void 0!==n.left&&n.left-o/2||void 0!==n.right&&n.right+o/2||0,c=void 0!==n.y&&n.y-l/2||void 0!==n.centerY&&n.centerY||void 0!==n.top&&n.top-l/2||void 0!==n.bottom&&n.bottom+l/2||0;return t.translate(u*g,-h*c),{width:u,height:h}}(this.localTransform,this.originalWidth,this.originalHeight,this.getLayout());t.width=i.width,t.height=i.height}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 s=this.hitAreas[t];if(!s)return!1;let r=s.index;if(r<0){if(!s.id)return!1;if(r=this.getDrawableIndex(s.id),r<0)return!1;s.index=r}const a=this.getDrawableBounds(r,$);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 s=i[0],r=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];s=Math.min(t,s),r=Math.max(t,r),a=Math.min(e,a),n=Math.max(e,n)}return null!=e||(e={}),e.x=s,e.y=a,e.width=r-s,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),s=this.parallelMotionManager.map(i=>i.update(t,e)),r=i||s.reduce((t,e)=>t||e,!1);return this.emit("afterMotionUpdate"),r}}class K extends Error{constructor(t,e,i,s=!1){super(t),this.url=e,this.status=i,this.aborted=s}}const Q=class t{static createXHR(e,i,s,r,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=s,n.onload=()=>{var t;200!==n.status&&0!==n.status||!n.response?null==(t=n.onerror)||t.call(n,new ProgressEvent("error")):r(n.response)},n.onerror=()=>{p.warn("XHRLoader",`Failed to load resource as ${n.responseType} (Status ${n.status}): ${i}`),a(new K("Network error.",i,n.status))},n.onabort=()=>a(new K("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(Q,"xhrMap",new WeakMap),g(Q,"allXhrSet",new Set),g(Q,"loader",t=>new Promise((e,i)=>{const s=t.target,r=t.target&&"function"==typeof Q.cancelXHRs?Q.cancelXHRs.bind(t.target):void 0,a=Q.createXHR(t.target,t.settings?t.settings.resolveURL(t.url):t.url,t.type,i=>{t.result=i,e()},i);if(t.target&&r&&"function"==typeof s.listeners&&"function"==typeof s.once){const t=s.listeners("destroy");Array.isArray(t)&&t.includes(r)||s.once("destroy",r)}a.send()}));let tt=Q;function et(t,e){let i=-1;return function s(r,a){if(a)return Promise.reject(a);if(r<=i)return Promise.reject(new Error("next() called multiple times"));i=r;const n=t[r];if(!n)return Promise.resolve();try{return Promise.resolve(n(e,s.bind(null,r+1)))}catch(o){const t=o instanceof Error?o:new Error(String(o));return Promise.reject(t)}}(0)}class it{static load(t){return c(this,null,function*(){return yield et(this.middlewares,t),t.result})}}g(it,"middlewares",[tt.loader]);class st extends E{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",{}),!st.isValidJSON(t))throw new TypeError("Invalid JSON.");this.moc=t.model,M("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){x("string",t,this,"name","name"),x("string",t,this,"pose","pose"),x("string",t,this,"physics","physics"),x("object",t,this,"layout","layout"),x("object",t,this,"motions","motions"),M("object",t,this,"hit_areas","hitAreas"),M("object",t,this,"expressions","expressions"),M("object",t,this,"init_params","initParams"),M("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 s=0;s<i.length;s++)i[s].file=t(i[s].file,`motions.${e}[${s}].file`),void 0!==i[s].sound&&(i[s].sound=t(i[s].sound,`motions.${e}[${s}].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 rt({lod:t,effectiveScale:e,textureWidth:i,textureHeight:s,lodScaleThreshold:r,lodTextureSizeThreshold:a,lodMaxLevel:n}){if("single-auto"!==at(t))return;if(!Number.isFinite(e)||e<=0)return;const o=Math.floor(i),l=Math.floor(s);if(o<=1||l<=1)return;if(e>=ot(r,.5))return;const h=ot(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 at(t){return!1===t||"single-auto"===t?t:"full"}function nt(t){return"nearest"===t?"nearest":"linear"}function ot(t,e){return void 0!==t&&Number.isFinite(t)&&t>0?t:e}function lt(){}const ut="Live2DFactory",ht=(t,e)=>c(null,null,function*(){if("string"==typeof t.source){const e=yield it.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()}),dt=(t,e)=>c(null,null,function*(){if(t.source instanceof E)return t.settings=t.source,e();if("object"==typeof t.source){const i=xt.findRuntime(t.source);if(i){const s=i.createModelSettings(t.source);return t.settings=s,t.live2dModel.emit("settingsLoaded",s),e()}}const i=t.source&&"string"==typeof t.source.url?t.source.url:void 0,s=xt.runtimes.map(t=>t.version).join(", ");if(0===xt.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 r=(()=>{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.",s?`Registered runtimes (versions): ${s}`:void 0,r?`Settings JSON keys: ${r}`:void 0,i?`Settings URL: ${i}`:void 0].filter(Boolean).join("\n"))}),gt=(t,e)=>{if(t.settings){const i=xt.findRuntime(t.settings);if(i)return i.ready().then(()=>e())}return e()},ct=(t,e)=>c(null,null,function*(){yield e();const i=t.internalModel;if(i){const e=t.settings,s=xt.findRuntime(e);if(s){const r=[],a=e instanceof st?"json":"arraybuffer";e.pose&&r.push(it.load({settings:e,url:e.pose,type:a,target:i}).then(e=>{i.pose=s.createPose(i.coreModel,e),t.live2dModel.emit("poseLoaded",i.pose)}).catch(e=>{t.live2dModel.emit("poseLoadError",e),p.warn(ut,"Failed to load pose.",e)})),e.physics&&r.push(it.load({settings:e,url:e.physics,type:a,target:i}).then(e=>{i.physics=s.createPhysics(i.coreModel,e),t.live2dModel.emit("physicsLoaded",i.physics)}).catch(e=>{t.live2dModel.emit("physicsLoadError",e),p.warn(ut,"Failed to load physics.",e)})),r.length&&(yield Promise.all(r))}}}),mt=(t,i)=>c(null,null,function*(){if(!t.settings)throw new TypeError("Missing settings.");{const s=t.live2dModel,r=d({crossOrigin:t.options.crossOrigin},t.options.textureOptions);t.settings instanceof st&&(r.preferCreateImageBitmap=!1);const a=Promise.all(t.settings.textures.map(i=>function(t,i={}){const s=e.loadTextures.config,r=null==s?void 0:s.crossOrigin,a=null==s?void 0:s.preferCreateImageBitmap,n=null==s?void 0:s.preferWorkers;return void 0!==i.crossOrigin&&s&&(s.crossOrigin=i.crossOrigin),!1===i.preferCreateImageBitmap&&s&&(s.preferCreateImageBitmap=!1,s.preferWorkers=!1),e.Assets.load({src:t,data:{autoGenerateMipmaps:"full"===at(i.lod)}}).catch(t=>{if(t instanceof Error)throw t;throw new Error("Texture loading error",{cause:t})}).finally(()=>{s&&(s.crossOrigin=null!=r?r:s.crossOrigin,!1===i.preferCreateImageBitmap&&(s.preferCreateImageBitmap=null!=a?a:s.preferCreateImageBitmap,s.preferWorkers=null!=n?n:s.preferWorkers))})}(t.settings.resolveURL(i),r)));if(a.catch(lt),yield i(),!t.internalModel)throw new TypeError("Missing internal model.");s.internalModel=t.internalModel,s.emit("modelLoaded",t.internalModel),s.textures=yield a,s.emit("textureLoaded",s.textures)}}),pt=(t,e)=>c(null,null,function*(){const i=t.settings;if(i instanceof E){const s=xt.findRuntime(i);if(!s)throw new TypeError("Unknown model settings.");const r=yield it.load({settings:i,url:i.moc,type:"arraybuffer",target:t.live2dModel});if(!s.isValidMoc(r))throw new Error("Invalid moc data");const a=s.createCoreModel(r);return t.internalModel=s.createInternalModel(a,i,t.options),e()}throw new TypeError("Missing settings.")}),_t=class t{static resolveURL(e,i){var s;const r=null==(s=t.filesMap[e])?void 0:s[i];if(void 0===r)throw new Error("Cannot find this file from uploaded files: "+i);return r}static upload(e,i){const s={};for(const t of i.getDefinedFiles()){const r=decodeURI(P(i.url,t)),a=e.find(t=>t.webkitRelativePath===r);a&&(s[t]=URL.createObjectURL(a))}t.filesMap[i._objectURL]=s}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 s=yield t.readText(i),r=JSON.parse(s);r.url=i.webkitRelativePath;const a=xt.findRuntime(r);if(!a)throw new Error("Unknown settings JSON");const n=a.createModelSettings(r);return n._objectURL=URL.createObjectURL(i),n})}static readText(t){return c(this,null,function*(){return new Promise((e,i)=>{const s=new FileReader;s.onload=()=>e(s.result),s.onerror=i,s.readAsText(t,"utf8")})})}};g(_t,"live2dFactory"),g(_t,"filesMap",{}),g(_t,"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 _t.createSettings(e);i.validateFiles(e.map(t=>encodeURI(t.webkitRelativePath))),_t.upload(e,i),i.resolveURL=function(t){return _t.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),_t.filesMap[t])for(const e of Object.values(_t.filesMap[t]))URL.revokeObjectURL(e);delete _t.filesMap[t]})})}return e()}));let ft=_t;const yt=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,s){return c(this,null,function*(){const r=new Promise(t=>e.once("textureLoaded",t)),a=new Promise(t=>e.once("modelLoaded",t)),n=Promise.all([r,a]).then(()=>e.emit("ready"));yield et(t.live2DModelMiddlewares,{live2dModel:e,source:i,options:s||{}}),yield n,e.emit("load")})}static loadMotion(e,i,s){var r;const a=t=>e.emit("motionLoadError",i,s,t);try{const n=null==(r=e.definitions[i])?void 0:r[s];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[s]||(l[s]=it.load({url:u,settings:e.settings,type:e.motionDataType,target:e}).then(r=>{var a;const o=null==(a=t.motionTasksMap.get(e))?void 0:a[i];o&&(o[s]=void 0);const l=r,u=e.createMotion(l,i,n);return e.emit("motionLoaded",i,s,u),u}).catch(t=>{p.warn(e.tag,`Failed to load motion: ${u}\n`,t),a(t)})),l[s]}catch(n){p.warn(e.tag,`Failed to load motion at "${i}"[${s}]\n`,n),a(n)}return Promise.resolve(void 0)}static loadExpression(e,i){var s;const r=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!=(s=e.expressionDataType)?s:"json";return null!=n[i]||(n[i]=it.load({url:o,settings:e.settings,type:l,target:e}).then(s=>{const r=t.expressionTasksMap.get(e);r&&(r[i]=void 0);const n=s,o=e.createExpression(n,a);return e.emit("expressionLoaded",i,o),o}).catch(t=>{p.warn(e.tag,`Failed to load expression: ${o}\n`,t),r(t)})),n[i]}catch(a){p.warn(e.tag,`Failed to load expression at [${i}]\n`,a),r(a)}return Promise.resolve(void 0)}static releaseMotionTasks(e){t.motionTasksMap.delete(e)}static releaseExpressionTasks(e){t.expressionTasksMap.delete(e)}};g(yt,"runtimes",[]),g(yt,"urlToJSON",ht),g(yt,"jsonToSettings",dt),g(yt,"waitUntilReady",gt),g(yt,"setupOptionals",ct),g(yt,"setupEssentials",mt),g(yt,"createInternalModel",pt),g(yt,"live2DModelMiddlewares",[ft.factory,ht,dt,gt,ct,mt,pt]),g(yt,"motionTasksMap",new WeakMap),g(yt,"expressionTasksMap",new WeakMap);let xt=yt;O.prototype._loadMotion=function(t,e){return xt.loadMotion(this,t,e)},B.prototype._loadExpression=function(t){return xt.loadExpression(this,t)},ft.live2dFactory=xt;const Mt=class t{constructor(i,{autoUpdate:s=!0,autoHitTest:r=!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&&(r=n,a=n,p.warn(i.tag,"options.autoInteract is deprecated since v0.5.0, use autoHitTest and autoFocus instead.")),this.model=i,this.ticker=o,this.autoUpdate=s,this.autoHitTest=r,this.autoFocus=a,(r||a)&&(this.model.eventMode="static")}get ticker(){return this._ticker}set ticker(t){var e,i;this._ticker&&this._ticker.remove(St,this),this._ticker=t,this._autoUpdate&&(null==(e=this._ticker)||e.add(St,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(St,this),this._autoUpdate=!0):p.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(St,this),this._autoUpdate=!1))}get autoHitTest(){return this._autoHitTest}set autoHitTest(t){t!==this.autoHitTest&&(t?this.model.on("pointertap",vt,this):this.model.off("pointertap",vt,this),this._autoHitTest=t)}get autoFocus(){return this._autoFocus}set autoFocus(t){t!==this.autoFocus&&(t?(this.model.on("globalpointermove",bt,this),this.model.on("pointermove",bt,this)):(this.model.off("globalpointermove",bt,this),this.model.off("pointermove",bt,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(Mt,"defaultTicker");let Ct=Mt;function St(){this.onTickerUpdate()}function vt(t){this.onTap(t)}function bt(t){this.onPointerMove(t)}class Pt extends e.Transform{}const Bt=new e.Point,wt=new e.Matrix,It=new e.Matrix,Ft={x:0,y:0,width:0,height:0},Et=new e.Bounds;let Lt=!1;class Vt{constructor(t){this.renderer=t}addRenderable(t,e){var i,s;null==(s=null==(i=this.renderer.renderPipes.batch)?void 0:i.break)||s.call(i,e),e.add(t)}execute(t){!t.visible||t.alpha<=0||t.renderLive2D(this.renderer)}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}destroy(){}}g(Vt,"extension",{type:[e.ExtensionType.WebGLPipes],name:"live2d"});const Tt=Vt;class Rt 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 Pt),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,s,r,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=It.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 s=this.resolveTextureForRender(e,i,g);try{this.uploadTextureForRender(t,s,o)}catch(C){if(s===i)throw new Error("Failed to upload Live2D texture.");const r=this.textureLODStates[e];(null==r?void 0:r.texture)===s&&(this.markTextureLODFailure(e,i,r.level),this.destroyTextureLODState(e)),s=i,this.uploadTextureForRender(t,s,o)}this.internalModel.bindTexture(e,t.texture.getGlSource(s.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!=(s=null==u?void 0:u.y)?s:0;const y=wt.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==(r=t.renderTarget)?void 0:r.defaultClearColor,M=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]),M&&(M[0]=x[0],M[1]=x[1],M[2]=x[2],M[3]=x[3]))}),this.textureOptions=null==t?void 0:t.textureOptions,this.anchor=new e.ObservablePoint({_onUpdate:()=>this.onAnchorChange()},0,0),this.automator=new Ct(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 xt.setupLive2DModel(i,t,e),i})}static fromSync(t,e){const i=new this(e);return xt.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){Ct.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();Et.clear();for(let i=0;i<t.length;i++){const s=t[i],r=this.internalModel.getDrawableIndex(s);if(r<0)continue;const a=this.internalModel.getDrawableBounds(r,Ft);Number.isFinite(a.x)&&Number.isFinite(a.y)&&Number.isFinite(a.width)&&Number.isFinite(a.height)&&Et.addFrame(a.x,a.y,a.x+a.width,a.y+a.height,e.Matrix.IDENTITY)}if(this._bounds.clear(),Et.isValid&&Et.isPositive)this._bounds.addFrame(Et.minX,Et.minY,Et.maxX,Et.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 s,r,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||(Lt||(Lt=!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 Vt(t))}(e);const o=e.renderPipes,l=()=>{o.live2d.addRenderable(this,t)},u=()=>{const s=this.children,r=s.length;for(let a=0;a<r;a++)s[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==(r=null==(s=o[i.pipe])?void 0:s.push)||r.call(s,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:s,volume:r=.5,expression:a,resetExpression:n=!0,onFinish:o,onError:l}={}){return void 0===e?this.internalModel.motionManager.startRandomMotion(t,i,{sound:s,volume:r,expression:a,resetExpression:n,onFinish:o,onError:l}):this.internalModel.motionManager.startMotion(t,e,i,{sound:s,volume:r,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:s=!0,onFinish:r,onError:a}={}){return this.internalModel.motionManager.speak(t,{volume:e,expression:i,resetExpression:s,onFinish:r,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){Bt.x=t,Bt.y=e,this.toModelPosition(Bt,Bt,!0);const s=Bt.x/this.internalModel.originalWidth*2-1,r=Bt.y/this.internalModel.originalHeight*2-1,a=Math.atan2(r,s);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 Bt.x=t,Bt.y=e,this.toModelPosition(Bt,Bt),this.internalModel.hitTest(Bt.x,Bt.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,s){var n;const o=rt((l=d({},this.textureOptions),u={effectiveScale:s,textureWidth:i.source.pixelWidth,textureHeight:i.source.pixelHeight},r(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,s,r,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(s,r),h=u.getContext("2d");if(!h)return;try{h.clearRect(0,0,s,r),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,s,r)}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:s,height:r,resolution:1,scaleMode:nt(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 s=this.textureLODFailures[t];(null==s?void 0:s.source)!==e&&(s={source:e,levels:new Set},this.textureLODFailures[t]=s),s.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 s=Boolean(e.source._gpuData[t.uid]);!i&&s||(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(!("Live2D"in window))throw new Error("Could not find Cubism 2 runtime. This plugin requires live2d.min.js to be loaded.");const Dt=Live2DMotion.prototype.updateParam;Live2DMotion.prototype.updateParam=function(t,e){Dt.call(this,t,e),e.isFinished()&&this.onFinishHandler&&(this.onFinishHandler(this),delete this.onFinishHandler)};class At extends AMotion{constructor(t){super(),g(this,"params",[]),this.setFadeIn(t.fade_in>0?t.fade_in:m.expressionFadingDuration),this.setFadeOut(t.fade_out>0?t.fade_out:m.expressionFadingDuration),Array.isArray(t.params)&&t.params.forEach(t=>{const e=t.calc||"add";if("add"===e){const e=t.def||0;t.val-=e}else if("mult"===e){const e=t.def||1;t.val/=e}this.params.push({calc:e,val:t.val,id:t.id})})}updateParamExe(t,e,i,s){this.params.forEach(e=>{t.setParamFloat(e.id,e.val*i)})}}class Ot extends B{constructor(t,e){var i;super(t,e),g(this,"queueManager",new MotionQueueManager),g(this,"definitions"),this.definitions=null!=(i=this.settings.expressions)?i:[],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 new At(t)}_setExpression(t){return this.queueManager.startMotion(t)}stopAllExpressions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}}function kt(t,e,i){const s=i.getDurationMSec(),r=t.startMotion(i,!0),a=t.motions.find(t=>!!t&&t._$sr===r);return!!a&&(i.updateParamExe(e.coreModel,s,1,a),!0)}class Nt extends O{constructor(t){super(t),g(this,"definitions"),g(this,"groups",{idle:"idle"}),g(this,"motionDataType","arraybuffer"),g(this,"queueManager",new MotionQueueManager),g(this,"lipSyncIds"),g(this,"expressionManager"),this.definitions=this.settings.motions,this.init(t.options),this.lipSyncIds=["PARAM_MOUTH_OPEN_Y"]}init(t){super.init(t),this.settings.expressions&&(this.expressionManager=new Ot(this.settings,t))}isFinished(){return this.queueManager.isFinished()}createMotion(t,e,i){const s=Live2DMotion.loadMotion(t),r=e===this.groups.idle?m.idleMotionFadingDuration:m.motionFadingDuration;return s.setFadeIn(i.fade_in>0?i.fade_in:r),s.setFadeOut(i.fade_out>0?i.fade_out:r),s}getMotionFile(t){return t.file}getMotionName(t){return t.file}getSoundFile(t){return t.sound}_startMotion(t,e,i){return t.onFinishHandler=e,i&&i.length>0&&(t.motions=t.motions.filter(t=>!i.includes(t._$4P))),this.queueManager.stopAllMotions(),this.queueManager.startMotion(t)}_stopAllMotions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}destroy(){super.destroy(),this.queueManager=void 0}motionLastFrame(t,e){return c(this,arguments,function*(t,e,{expression:i}={}){const s=yield this.getMotionAndApplyExpression(t,e,i);return!!s&&(this.playing=!0,kt(this.queueManager,this.parent,s),this.playing=!1,!0)})}}class Ut extends e.EventEmitter{constructor(t){super(),g(this,"tag"),g(this,"manager"),g(this,"settings"),g(this,"state",new V),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=L.NORMAL,s=[]){var r;if(!this.state.reserve(t,e,i))return!1;const a=null==(r=this.manager.definitions[t])?void 0:r[e];if(!a)return!1;const n=yield this.manager.loadMotion(t,e);return!!this.state.start(n,t,e,i)&&(p.log(this.tag,"Start motion:",this.getMotionName(a)),this.emit("motionStart",t,e,void 0),this.playing=!0,this._startMotion(n,void 0,s),!0)})}startRandomMotion(t,e){return c(this,null,function*(){var i;const s=this.manager.definitions[t];if(null==s?void 0:s.length){const r=[],a=null!=(i=this.manager.motionGroups[t])?i:[];for(let e=0;e<s.length;e++)null===a[e]||this.state.isActive(t,e)||r.push(e);if(r.length){const i=r[Math.floor(Math.random()*r.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 zt extends Ut{constructor(t){super(t),g(this,"queueManager",new MotionQueueManager)}isFinished(){return this.queueManager.isFinished()}getMotionName(t){return t.file}_startMotion(t,e,i){return t.onFinishHandler=e,i&&i.length>0&&(t.motions=t.motions.filter(t=>!i.includes(t._$4P))),this.queueManager.stopAllMotions(),this.queueManager.startMotion(t)}_stopAllMotions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}destroy(){super.destroy(),this.queueManager=void 0}playMotionLastFrame(t,e){return c(this,null,function*(){var i;if(!this.state.reserve(t,e,L.FORCE))return!1;const s=null==(i=this.manager.definitions[t])?void 0:i[e];if(!s)return!1;const r=yield this.manager.loadMotion(t,e);return!!this.state.start(r,t,e,L.FORCE)&&(p.log(this.tag,"Start motion:",this.getMotionName(s)),this.queueManager.stopAllMotions(),this.emit("motionStart",t,e,void 0),this.playing=!0,!!kt(this.queueManager,this.parent,r)&&(this.playing=!1,!0))})}}class jt{constructor(t){g(this,"leftParam"),g(this,"rightParam"),g(this,"blinkInterval",4e3),g(this,"closingDuration",100),g(this,"closedDuration",50),g(this,"openingDuration",150),g(this,"eyeState",0),g(this,"eyeParamValue",1),g(this,"closedTimer",0),g(this,"nextBlinkTimeLeft",this.blinkInterval),this.coreModel=t,this.leftParam=t.getParamIndex("PARAM_EYE_L_OPEN"),this.rightParam=t.getParamIndex("PARAM_EYE_R_OPEN")}setEyeParams(t){this.eyeParamValue=_(t,0,1),this.coreModel.setParamFloat(this.leftParam,this.eyeParamValue),this.coreModel.setParamFloat(this.rightParam,this.eyeParamValue)}update(t){switch(this.eyeState){case 0:this.nextBlinkTimeLeft-=t,this.nextBlinkTimeLeft<0&&(this.eyeState=1,this.nextBlinkTimeLeft=this.blinkInterval+this.closingDuration+this.closedDuration+this.openingDuration+f(0,2e3));break;case 1:this.setEyeParams(this.eyeParamValue+t/this.closingDuration),this.eyeParamValue<=0&&(this.eyeState=2,this.closedTimer=0);break;case 2:this.closedTimer+=t,this.closedTimer>=this.closedDuration&&(this.eyeState=3);break;case 3:this.setEyeParams(this.eyeParamValue+t/this.openingDuration),this.eyeParamValue>=1&&(this.eyeState=0)}}}const Gt=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);class Xt extends Z{constructor(t,e,i){super(),g(this,"settings"),g(this,"options"),g(this,"coreModel"),g(this,"motionManager"),g(this,"parallelMotionManager"),g(this,"eyeBlink"),g(this,"eyeballXParamIndex"),g(this,"eyeballYParamIndex"),g(this,"angleXParamIndex"),g(this,"angleYParamIndex"),g(this,"angleZParamIndex"),g(this,"bodyAngleXParamIndex"),g(this,"breathParamIndex"),g(this,"textureFlipY",!0),g(this,"lipSync",!0),g(this,"drawDataCount",0),g(this,"disableCulling",!1),g(this,"hasDrawn",!1),g(this,"customHitAreas"),this.coreModel=t,this.settings=e,this.options=Object.assign({},{breathDepth:1,lipSyncGain:1.5,lipSyncWeight:.4},i),void 0!==(null==i?void 0:i.useHighPrecisionMask)&&!1!==i.useHighPrecisionMask&&p.warn("CubismLegacyInternalModel","`useHighPrecisionMask` is only supported by Cubism 3/4/5 models and will be ignored for Cubism 2 models."),this.motionManager=new Nt(this),this.parallelMotionManager=[],this.eyeBlink=new jt(t),this.eyeballXParamIndex=t.getParamIndex("PARAM_EYE_BALL_X"),this.eyeballYParamIndex=t.getParamIndex("PARAM_EYE_BALL_Y"),this.angleXParamIndex=t.getParamIndex("PARAM_ANGLE_X"),this.angleYParamIndex=t.getParamIndex("PARAM_ANGLE_Y"),this.angleZParamIndex=t.getParamIndex("PARAM_ANGLE_Z"),this.bodyAngleXParamIndex=t.getParamIndex("PARAM_BODY_ANGLE_X"),this.breathParamIndex=t.getParamIndex("PARAM_BREATH"),this.init()}init(){super.init(),this.settings.initParams&&this.settings.initParams.forEach(({id:t,value:e})=>this.coreModel.setParamFloat(t,e)),this.settings.initOpacities&&this.settings.initOpacities.forEach(({id:t,value:e})=>this.coreModel.setPartsOpacity(t,e)),this.coreModel.saveParam();const t=this.coreModel.getModelContext()._$aS;(null==t?void 0:t.length)&&(this.drawDataCount=t.length);let e=this.coreModel.drawParamWebGL.culling;Object.defineProperty(this.coreModel.drawParamWebGL,"culling",{set:t=>e=t,get:()=>!this.disableCulling&&e});const i=this.coreModel.getModelContext().clipManager,s=i.setupClip.bind(i);i.setupClip=(t,e)=>{s.call(i,t,e),e.gl.viewport(...this.viewport)}}getSize(){return[this.coreModel.getCanvasWidth(),this.coreModel.getCanvasHeight()]}getLayout(){const t={};if(this.settings.layout)for(const[e,i]of Object.entries(this.settings.layout)){let s=e;"center_x"===e?s="centerX":"center_y"===e&&(s="centerY"),"number"==typeof i&&(t[s]=i)}return t}updateWebGLContext(t,e){const i=this.coreModel.drawParamWebGL;i.firstDraw=!0,i.setGL(t),i.glno=e,i._$NT=null,i._$no=null,i._$vS=null;const s=this.coreModel.getModelContext().clipManager;s.curFrameNo=e;const r=t.getParameter(t.FRAMEBUFFER_BINDING);s.getMaskRenderTexture(),t.bindFramebuffer(t.FRAMEBUFFER,r)}bindTexture(t,e){this.coreModel.setTexture(t,e)}getHitAreaDefs(){var t,e,i;const s=this.settings.json;return J(null!=(i=null!=(e=null!=(t=this.settings.hitAreas)?t:s.hit_areas)?e:s.HitAreas)?i:s.hitAreas,t=>this.coreModel.getDrawDataIndex(t))}getDrawableIDs(){const t=this.coreModel.getModelContext(),e=[];for(let i=0;i<this.drawDataCount;i++){const s=t.getDrawData(i);s&&e.push(s.getDrawDataID().id)}return e}getDrawableIndex(t){return this.coreModel.getDrawDataIndex(t)}getDrawableVertices(t){if("string"==typeof t&&-1===(t=this.coreModel.getDrawDataIndex(t)))throw new TypeError("Unable to find drawable ID: "+t);return this.coreModel.getTransformedPoints(t).slice()}hitTest(t,e){this.hasDrawn||p.warn("Trying to hit-test a Cubism 2 model that has not been rendered yet. Drawable hit areas may be empty until the first draw.");const i=super.hitTest(t,e),s=this.hitTestCustom(t,e);return s.length?i.length?[...new Set([...i,...s])]:s:i}update(t,e){var i,s,r,a;super.update(t,e);const n=this.coreModel,o=this.updateMotions(n,e);if(n.saveParam(),null==(i=this.motionManager.expressionManager)||i.update(n,e),o||null==(s=this.eyeBlink)||s.update(t),this.updateFocus(),this.updateNaturalMovements(t,e),this.lipSync&&this.motionManager.currentAudio){let t=this.motionManager.mouthSync()*this.options.lipSyncGain;const e=1,i=t>0?.1:0;t=Math.pow(t,1.15),t=_(t,i,e);for(let s=0;s<this.motionManager.lipSyncIds.length;++s)this.coreModel.addToParamFloat(this.coreModel.getParamIndex(this.motionManager.lipSyncIds[s]),t,this.options.lipSyncWeight)}null==(r=this.physics)||r.update(e),null==(a=this.pose)||a.update(t),this.emit("beforeModelUpdate"),n.update(),n.loadParam()}updateFocus(){this.coreModel.addToParamFloat(this.eyeballXParamIndex,this.focusController.x),this.coreModel.addToParamFloat(this.eyeballYParamIndex,this.focusController.y),this.coreModel.addToParamFloat(this.angleXParamIndex,30*this.focusController.x),this.coreModel.addToParamFloat(this.angleYParamIndex,30*this.focusController.y),this.coreModel.addToParamFloat(this.angleZParamIndex,this.focusController.x*this.focusController.y*-30),this.coreModel.addToParamFloat(this.bodyAngleXParamIndex,10*this.focusController.x)}updateNaturalMovements(t,e){const i=e/1e3*2*Math.PI;this.coreModel.addToParamFloat(this.angleXParamIndex,15*this.options.breathDepth*Math.sin(i/6.5345)*.5),this.coreModel.addToParamFloat(this.angleYParamIndex,8*this.options.breathDepth*Math.sin(i/3.5345)*.5),this.coreModel.addToParamFloat(this.angleZParamIndex,10*this.options.breathDepth*Math.sin(i/5.5345)*.5),this.coreModel.addToParamFloat(this.bodyAngleXParamIndex,4*this.options.breathDepth*Math.sin(i/15.5345)*.5),this.coreModel.setParamFloat(this.breathParamIndex,.5+.5*Math.sin(i/3.2345))}draw(t){const e=this.disableCulling;t.getParameter(t.FRAMEBUFFER_BINDING)&&(this.disableCulling=!0);const i=this.drawingMatrix;Gt[0]=i.a,Gt[1]=i.b,Gt[4]=i.c,Gt[5]=i.d,Gt[12]=i.tx,Gt[13]=i.ty,this.coreModel.setMatrix(Gt),this.coreModel.draw(),this.hasDrawn=!0,this.disableCulling=e}extendParallelMotionManager(t){for(;this.parallelMotionManager.length<t;)this.parallelMotionManager.push(new zt(this))}destroy(){super.destroy(),this.coreModel=void 0}hitTestCustom(t,e){const i=this.getCustomHitAreas();if(!i)return[];const s=this.originalWidth||this.width,r=this.originalHeight||this.height;if(!s||!r)return[];const a=t/s*2-1,n=1-e/r*2,o=[];for(const[l,u]of Object.entries(i))a>=u.minX&&a<=u.maxX&&n>=u.minY&&n<=u.maxY&&o.push(l);return o}getCustomHitAreas(){var t,e,i,s,r;if(void 0!==this.customHitAreas)return this.customHitAreas;const a=this.settings.json,n=null!=(i=null!=(e=null!=(t=a.hit_areas_custom)?t:a.hitAreasCustom)?e:a.HitAreasCustom)?i:a.HitAreas_Custom;if(!n||"object"!=typeof n)return this.customHitAreas=null,null;const o=n,l={},u=(t,e,i)=>{if(!t||!Array.isArray(e)||!Array.isArray(i))return;if(e.length<2||i.length<2)return;const s=Number(e[0]),r=Number(e[1]),a=Number(i[0]),n=Number(i[1]);Number.isFinite(s)&&Number.isFinite(r)&&Number.isFinite(a)&&Number.isFinite(n)&&(l[t]={minX:Math.min(s,r),maxX:Math.max(s,r),minY:Math.min(a,n),maxY:Math.max(a,n)})};for(const[h,d]of Object.entries(o)){if(h.endsWith("_x")){const t=h.slice(0,-2);u(t,d,o[`${t}_y`]);continue}if(!h.endsWith("_y")&&(d&&"object"==typeof d)){const t=d;u(h,null!=(s=t.x)?s:t.X,null!=(r=t.y)?r:t.Y)}}return this.customHitAreas=Object.keys(l).length?l:null,this.customHitAreas}}const Ht={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE},Yt={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE};class qt{constructor(t,e){g(this,"physicsHairs",[]),this.coreModel=t,e.physics_hair&&(this.physicsHairs=e.physics_hair.map(t=>{const e=new PhysicsHair;return e.setup(t.setup.length,t.setup.regist,t.setup.mass),t.src.forEach(({id:t,ptype:i,scale:s,weight:r})=>{const a=Ht[i];a&&e.addSrcParam(a,t,s,r)}),t.targets.forEach(({id:t,ptype:i,scale:s,weight:r})=>{const a=Yt[i];a&&e.addTargetParam(a,t,s,r)}),e}))}update(t){this.physicsHairs.forEach(e=>e.update(this.coreModel,t))}}class Wt{constructor(t){g(this,"paramIndex",-1),g(this,"partsIndex",-1),g(this,"link",[]),this.id=t}initIndex(t){this.paramIndex=t.getParamIndex("VISIBLE:"+this.id),this.partsIndex=t.getPartsDataIndex(PartsDataID.getID(this.id)),t.setParamFloat(this.paramIndex,1)}}class Jt{constructor(t,e){g(this,"opacityAnimDuration",500),g(this,"partsGroups",[]),this.coreModel=t,e.parts_visible&&(this.partsGroups=e.parts_visible.map(({group:t})=>t.map(({id:t,link:e})=>{const i=new Wt(t);return e&&(i.link=e.map(t=>new Wt(t))),i})),this.init())}init(){this.partsGroups.forEach(t=>{t.forEach(t=>{if(t.initIndex(this.coreModel),t.paramIndex>=0){const e=0!==this.coreModel.getParamFloat(t.paramIndex);this.coreModel.setPartsOpacity(t.partsIndex,e?1:0),this.coreModel.setParamFloat(t.paramIndex,e?1:0),t.link.length>0&&t.link.forEach(t=>t.initIndex(this.coreModel))}})})}normalizePartsOpacityGroup(t,e){const i=this.coreModel,s=.5;let r=1,a=t.findIndex(({paramIndex:t,partsIndex:e})=>e>=0&&0!==i.getParamFloat(t));if(a>=0){const s=i.getPartsOpacity(t[a].partsIndex);r=_(s+e/this.opacityAnimDuration,0,1)}else a=0,r=1;t.forEach(({partsIndex:t},e)=>{if(t>=0)if(a==e)i.setPartsOpacity(t,r);else{let e,a=i.getPartsOpacity(t);e=r<s?-.5*r/s+1:(1-r)*s/.5;(1-e)*(1-r)>.15&&(e=1-.15/(1-r)),a>e&&(a=e),i.setPartsOpacity(t,a)}})}copyOpacity(t){const e=this.coreModel;t.forEach(({partsIndex:t,link:i})=>{if(t>=0&&i){const s=e.getPartsOpacity(t);i.forEach(({partsIndex:t})=>{t>=0&&e.setPartsOpacity(t,s)})}})}update(t){this.partsGroups.forEach(e=>{this.normalizePartsOpacityGroup(e,t),this.copyOpacity(e)})}}if(xt.registerRuntime({version:2,test:t=>t instanceof st||st.isValidJSON(t),ready:()=>Promise.resolve(),isValidMoc(t){if(t.byteLength<3)return!1;const e=new Int8Array(t,0,3);return"moc"===String.fromCharCode(...e)},createModelSettings:t=>new st(t),createCoreModel(t){const e=Live2DModelWebGL.loadModel(t),i=Live2D.getError();if(i){if(i instanceof Error)throw i;const t="string"==typeof i?i:`Live2D error: ${JSON.stringify(i)}`;throw new Error(t)}return e},createInternalModel:(t,e,i)=>new Xt(t,e,i),createPose:(t,e)=>new Jt(t,e),createPhysics:(t,e)=>new qt(t,e)}),"undefined"==typeof window||void 0===window.Live2DCubismCore)throw new Error("Could not find Cubism runtime. This plugin requires live2dcubismcore.js to be loaded.");const $t=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 s=this._size;s<t;s++)this._ptr[s]="function"==typeof e?JSON.parse(JSON.stringify(new e)):e;else for(let s=this._size;s<t;s++)this._ptr[s]=e;else{const e=this._size-t;this._ptr.splice(this._size-e,e)}this._size=t}insert(t,e,i){let s=t._index;const r=e._index,a=i._index,n=a-r;this.prepareCapacity(this._size+n);const o=this._size-s;if(o>0)for(let l=0;l<o;l++)this._ptr.splice(s+l,0,null);for(let l=r;l<a;l++,s++)this._ptr[s]=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 Kt(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 Kt(this,0)}end(){return new Kt(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}};$t.DefaultSize=10;let Zt=$t,Kt=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 Qt,te,ee,ie,se,re,ae;(te=Qt||(Qt={})).csmVector=Zt,te.iterator=Kt;class ne{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=ne})(ee||(ee={}));class oe{static createIdInternal(t){return new oe(t)}getString(){return this._id}isEqual(t){return"string"==typeof t?this._id.isEqual(t):t instanceof ne?this._id.isEqual(t.s):t instanceof oe&&this._id.isEqual(t._id.s)}isNotEqual(t){return"string"==typeof t?!this._id.isEqual(t):t instanceof ne?!this._id.isEqual(t.s):t instanceof oe&&!this._id.isEqual(t._id.s)}constructor(t){this._id="string"!=typeof t?t:new ne(t)}}(t=>{t.CubismId=oe})(ie||(ie={}));class le{constructor(){this._ids=new Zt}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=oe.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=le})(se||(se={}));class ue{constructor(){this._tr=new Float32Array(16),this.loadIdentity()}static multiply(t,e,i){const s=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);for(let r=0;r<4;++r)for(let i=0;i<4;++i)for(let a=0;a<4;++a)s[i+4*r]+=t[a+4*r]*e[i+4*a];for(let r=0;r<16;++r)i[r]=s[r]}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]);ue.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]);ue.multiply(i,this._tr,this._tr)}scale(t,e){this._tr[0]=t,this._tr[5]=e}multiplyByMatrix(t){ue.multiply(t.getArray(),this._tr,this._tr)}clone(){const t=new ue;for(let e=0;e<this._tr.length;e++)t._tr[e]=this._tr[e];return t}}(t=>{t.CubismMatrix44=ue})(re||(re={}));class he{constructor(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s}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=he})(ae||(ae={}));class de{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,s){t<0?t=0:t>1&&(t=1),e<0?e=0:e>1&&(e=1),i<0?i=0:i>1&&(i=1),s<0?s=0:s>1&&(s=1),this._modelColor.r=t,this._modelColor.g=e,this._modelColor.b=i,this._modelColor.a=s}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 me,this._useHighPrecisionMask=!1,this._mvpMatrix4x4=new ue,this._mvpMatrix4x4.loadIdentity()}}var ge,ce=(t=>(t[t.CubismBlendMode_Normal=0]="CubismBlendMode_Normal",t[t.CubismBlendMode_Additive=1]="CubismBlendMode_Additive",t[t.CubismBlendMode_Multiplicative=2]="CubismBlendMode_Multiplicative",t))(ce||{});class me{constructor(t=1,e=1,i=1,s=1){this.r=t,this.g=e,this.b=i,this.a=s}}class pe{constructor(t,e){this._clippingIdList=t,this._clippingIdCount=e,this._allClippedDrawRect=new he,this._layoutBounds=new he,this._clippedDrawableIndexList=[],this._matrixForMask=new ue,this._matrixForDraw=new ue,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=ce,t.CubismRenderer=de,t.CubismTextureColor=me})(ge||(ge={}));const _e=(t,e,i)=>{((t,e,i)=>{Se.print(t,"[CSM]"+e,i)})(t,e+"\n",i)},fe=t=>{console.assert(t)};let ye,xe,Me,Ce;ye=(t,...e)=>{_e(Ze.LogLevel_Debug,"[D]"+t,e)},xe=(t,...e)=>{_e(Ze.LogLevel_Info,"[I]"+t,e)},Me=(t,...e)=>{_e(Ze.LogLevel_Warning,"[W]"+t,e)},Ce=(t,...e)=>{_e(Ze.LogLevel_Error,"[E]"+t,e)};class Se{static print(t,e,i){if(t<We.getLoggingLevel())return;const s=We.coreLogFunction;if(!s)return;s(e.replace(/\{(\d+)\}/g,(t,e)=>i[e]))}static dumpBytes(t,e,i){for(let s=0;s<i;s++)s%16==0&&s>0?this.print(t,"\n"):s%8==0&&s>0&&this.print(t," "),this.print(t,"{0} ",[255&e[s]]);this.print(t,"\n")}constructor(){}}var ve;(t=>{t.CubismDebug=Se})(ve||(ve={}));class be{constructor(t,e){this.first=null==t?null:t,this.second=null==e?null:e}}const Pe=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 be(t),this._size+=1):Me("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 s=0;s<this._size;s++)if(this._keyValues[s].first==t){i=s;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 we(this,0)}end(){return new we(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 we(this,e)}dumpAsInt(){for(let t=0;t<this._size;t++)ye("{0} ,",this._keyValues[t]),ye("\n")}};Pe.DefaultSize=10;let Be=Pe;class we{constructor(t,e){this._map=null!=t?t:new Be,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 we(this._map,this._index++)}decrement(){const t=new we(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 Ie;(t=>{t.csmMap=Be,t.csmPair=be,t.iterator=we})(Ie||(Ie={}));class Fe{static parseJsonObject(t,e){return Object.keys(t).forEach(i=>{if("boolean"==typeof t[i]){const s=Boolean(t[i]);e.put(i,new Re(s))}else if("string"==typeof t[i]){const s=String(t[i]);e.put(i,new De(s))}else if("number"==typeof t[i]){const s=Number(t[i]);e.put(i,new Te(s))}else t[i]instanceof Array?e.put(i,Fe.parseJsonArray(t[i])):t[i]instanceof Object?e.put(i,Fe.parseJsonObject(t[i],new Ne)):null==t[i]?e.put(i,new Oe):e.put(i,t[i])}),e}static parseJsonArray(t){const e=new ke;return Object.keys(t).forEach(i=>{if("number"==typeof Number(i))if("boolean"==typeof t[i]){const s=Boolean(t[i]);e.add(new Re(s))}else if("string"==typeof t[i]){const s=String(t[i]);e.add(new De(s))}else if("number"==typeof t[i]){const s=Number(t[i]);e.add(new Te(s))}else t[i]instanceof Array?e.add(this.parseJsonArray(t[i])):t[i]instanceof Object?e.add(this.parseJsonObject(t[i],new Ne)):null==t[i]?e.add(new Oe):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 Ne));else if(null==t[i])e.add(new Oe);else{const s=Array(t[i]);for(let t=0;t<s.length;t++)e.add(s[t])}}),e}}const Ee="Error: type mismatch";let Le=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 Zt){return t}getMap(t){return t}getValueByIndex(e){return t.errorValue.setErrorNotForClientCall(Ee)}getValueByString(e){return t.nullValue.setErrorNotForClientCall(Ee)}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 Ae.errorValue}static staticInitializeNotForClientCall(){Re.trueValue=new Re(!0),Re.falseValue=new Re(!1),t.errorValue=new Ae("ERROR",!0),t.nullValue=new Oe,t.dummyKeys=new Zt}static staticReleaseNotForClientCall(){Re.trueValue=null,Re.falseValue=null,t.errorValue=null,t.nullValue=null,t.dummyKeys=null}};class Ve{constructor(t,e){this._parseCallback=Fe.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 Ve;return i.parseBytes(t,e,i._parseCallback)?i:(Ve.delete(i),null)}static delete(t){}getRoot(){return this._root}static arrayBufferToString(t){const e=new Uint8Array(t);let i="";for(let s=0,r=e.length;s<r;++s)i+="%"+this.pad(e[s].toString(16));return i=decodeURIComponent(i),i}static pad(t){return t.length<2?"0"+t:t}parseBytes(t,e,i){const s=new Array(1),r=Ve.arrayBufferToString(t);if(this._root=null==i?this.parseValue(r,e,0,s):i(JSON.parse(r),new Ne),this._error){let t="\0";return t="Json parse error : @line "+(this._lineCount+1)+"\n",this._root=new De(t),xe("{0}",this._root.getRawString()),!1}return null!=this._root||(this._root=new Ae(new ne(this._error),!1),!1)}getParseError(){return this._error}checkEndOfFile(){return this._root.getArray()[1].equals("EOF")}parseValue(t,e,i,s){if(this._error)return null;let r,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 r=ze(t.slice(n),e),s[0]=t.indexOf(e[0]),new Te(r)}case'"':return new De(this.parseString(t,e,n+1,s));case"[":return a=this.parseArray(t,e,n+1,s),a;case"{":return a=this.parseObject(t,e,n+1,s),a;case"n":return n+3<e?(a=new Oe,s[0]=n+4):this._error="parse null",a;case"t":return n+3<e?(a=Re.trueValue,s[0]=n+4):this._error="parse true",a;case"f":return n+4<e?(a=Re.falseValue,s[0]=n+5):this._error="illegal ',' position",a;case",":return this._error="illegal ',' position",null;case"]":return s[0]=n,null;case"\n":this._lineCount++}}return this._error="illegal end of value",null}parseString(t,e,i,s){if(this._error)return null;if(!t)return this._error="string is null",null;let r,a,n=i;const o=new ne("");let l=i;for(;n<e;n++)switch(r=t[n],r){case'"':return s[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,s){if(this._error)return null;if(!t)return this._error="buffer is null",null;const r=new Ne;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 s[0]=n+1,r;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],r.put(a,i);t:for(;n<e;n++)switch(o=t[n],o){case",":break t;case"}":return s[0]=n+1,r;case"\n":this._lineCount++}}return this._error="illegal end of perseObject",null}parseArray(t,e,i,s){if(this._error)return null;if(!t)return this._error="buffer is null",null;let r,a=new ke,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(r=t[n],r){case",":break t;case"]":return s[0]=n+1,a;case"\n":++this._lineCount}}return a=void 0,this._error="illegal end of parseObject",null}}class Te extends Le{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 Re extends Le{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 De extends Le{constructor(t){super(),"string"==typeof t&&(this._stringBuffer=t),t instanceof ne&&(this._stringBuffer=t.s)}isString(){return!0}getString(t,e){return this._stringBuffer}equals(t){return"string"==typeof t?this._stringBuffer==t:t instanceof ne&&this._stringBuffer==t.s}}class Ae extends De{isStatic(){return this._isStatic}setErrorNotForClientCall(t){return this._stringBuffer=t,this}constructor(t,e){super(t),this._isStatic=e}isError(){return!0}}class Oe extends Le{isNull(){return!0}getString(t,e){return this._stringBuffer}isStatic(){return!0}setErrorNotForClientCall(t){return this._stringBuffer=t,Ae.nullValue}constructor(){super(),this._stringBuffer="NullValue"}}class ke extends Le{constructor(){super(),this._array=new Zt}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 Le.errorValue.setErrorNotForClientCall("Error: index out of bounds");const e=this._array.at(t);return null==e?Le.nullValue:e}getValueByString(t){return Le.errorValue.setErrorNotForClientCall(Ee)}getString(t,e){const i=e+"[\n";for(let s=this._array.begin();s.notEqual(this._array.end());s.increment()){const t=s.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 Ne extends Le{constructor(){super(),this._map=new Be}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 ne){const e=this._map.getValue(t.s);return null==e?Le.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?Le.nullValue:e.ptr().second;return Le.nullValue}getValueByIndex(t){return Le.errorValue.setErrorNotForClientCall(Ee)}getString(t,e){this._stringBuffer=e+"{\n";const i=this._map.begin();for(;i.notEqual(this._map.end());){const t=i.ptr().first,s=i.ptr().second;this._stringBuffer+=e+" "+t+" : "+s.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 Zt;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 Ue;function ze(t,e){let i=0;for(let r=1;;r++){const e=t.slice(r-1,r);if("e"==e||"-"==e||"E"==e)continue;const s=t.substring(0,r),a=Number(s);if(isNaN(a))break;i=r}let s=parseFloat(t);return isNaN(s)&&(s=NaN),e[0]=t.slice(i),s}(t=>{t.CubismJson=Ve,t.JsonArray=ke,t.JsonBoolean=Re,t.JsonError=Ae,t.JsonFloat=Te,t.JsonMap=Ne,t.JsonNullvalue=Oe,t.JsonString=De,t.Value=Le})(Ue||(Ue={}));let je=!1,Ge=!1,Xe=null,He=null;const Ye=Object.freeze({vertexOffset:0,vertexStep:2});function qe(t){t&&(t=void 0)}class We{static startUp(t=null){if(je)return xe("CubismFramework.startUp() is already done."),je;if(Xe=t,null!=Xe&&Live2DCubismCore.Logging.csmSetLogFunction(Xe.logFunction),je=!0,je){const t=Live2DCubismCore.Version.csmGetVersion(),e=(16711680&t)>>16,i=65535&t,s=t;xe("Live2D Cubism Core version: {0}.{1}.{2} ({3})",("00"+((4278190080&t)>>24)).slice(-2),("00"+e).slice(-2),("0000"+i).slice(-4),s)}return xe("CubismFramework.startUp() is complete."),je}static cleanUp(){je=!1,Ge=!1,Xe=null,He=null}static initialize(t=0){fe(je),je?Ge?Me("CubismFramework.initialize() skipped, already initialized."):(Le.staticInitializeNotForClientCall(),He=new le,Live2DCubismCore.Memory.initializeAmountOfMemory(t),Ge=!0,xe("CubismFramework.initialize() is complete.")):Me("CubismFramework is not started.")}static dispose(){fe(je),je?Ge?(Le.staticReleaseNotForClientCall(),He.release(),He=null,de.staticRelease(),Ge=!1,xe("CubismFramework.dispose() is complete.")):Me("CubismFramework.dispose() skipped, not initialized."):Me("CubismFramework is not started.")}static isStarted(){return je}static isInitialized(){return Ge}static coreLogFunction(t){Live2DCubismCore.Logging.csmGetLogFunction()&&Live2DCubismCore.Logging.csmGetLogFunction()(t)}static getLoggingLevel(){return null!=Xe?Xe.loggingLevel:5}static getIdManager(){return He}constructor(){}}var Je,$e,Ze=(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))(Ze||{});(t=>{t.Constant=Ye,t.csmDelete=qe,t.CubismFramework=We})(Je||(Je={}));class Ke{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 Ke(0,0);return e.x=this.x+t.x,e.y=this.y+t.y,e}substract(t){const e=new Ke(0,0);return e.x=this.x-t.x,e.y=this.y-t.y,e}multiply(t){const e=new Ke(0,0);return e.x=this.x*t.x,e.y=this.y*t.y,e}multiplyByScaler(t){return this.multiply(new Ke(t,t))}division(t){const e=new Ke(0,0);return e.x=this.x/t.x,e.y=this.y/t.y,e}divisionByScalar(t){return this.division(new Ke(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)}}(t=>{t.CubismVector2=Ke})($e||($e={}));const Qe=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 s;return i&&(e=-e),e===1/0?s=1/0:(s=Math.exp(Math.log(e)/3),s=(e/(s*s)+2*s)/3),i?-s:s}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 s=this.radianToDegrees(i);return e.x-t.x>0&&(s=-s),s}static radianToDirection(t){const e=new Ke;return e.x=this.sin(t),e.y=this.cos(t),e}static quadraticEquation(e,i,s){return this.abs(e)<t.Epsilon?this.abs(i)<t.Epsilon?-s:-s/i:-(i+this.sqrt(i*i-4*e*s))/(2*e)}static cardanoAlgorithmForBezier(e,i,s,r){if(this.abs(e)<t.Epsilon)return this.range(this.quadraticEquation(i,s,r),0,1);const a=i/e,n=s/e,o=(3*n-a*a)/3,l=o/3,u=(2*a*a*a-9*a*n+27*(r/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),s=-u/(2*i),r=this.range(s,-1,1),n=Math.acos(r),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),s=Math.abs(e);let r=i-Math.floor(i/s)*s;return r*=Math.sign(t),r}constructor(){}};Qe.Epsilon=1e-5;let ti=Qe;var ei,ii;(t=>{t.CubismMath=ti})(ei||(ei={}));class si{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 Zt}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 s=this.updateFadeWeight(e,i);this.doUpdateParameters(t,i,s,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&&Se.print(Ze.LogLevel_Error,"motionQueueEntry is null.");let i=this._weight;return i=i*(0==this._fadeInSeconds?1:ti.getEasingSine((e-t.getFadeInStartTime())/this._fadeInSeconds))*(0==this._fadeOutSeconds||t.getEndTime()<0?1:ti.getEasingSine((t.getEndTime()-e)/this._fadeOutSeconds)),t.setState(e,i),fe(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=si})(ii||(ii={}));const ri="Parameters",ai="Blend",ni=class t extends si{static create(e,i){const s=new t;return s.parse(e,i),s}doUpdateParameters(t,e,i,s){for(let r=0;r<this._parameters.getSize();++r){const e=this._parameters.at(r);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,s,r,a,n){if(null!=s&&null!=r&&s.isAvailable()){this._fadeWeight=this.updateFadeWeight(s,i);for(let i=0;i<r.getSize();++i){const s=r.at(i);if(null==s.parameterId)continue;const o=s.overwriteValue=e.getParameterValueById(s.parameterId),l=this.getExpressionParameters();let u=-1;for(let t=0;t<l.getSize();++t)if(s.parameterId==l.at(t).parameterId){u=t;break}if(u<0){0==a?(s.additiveValue=t.DefaultAdditiveValue,s.multiplyValue=t.DefaultMultiplyValue,s.overwriteValue=o):(s.additiveValue=this.calculateValue(s.additiveValue,t.DefaultAdditiveValue,n),s.multiplyValue=this.calculateValue(s.multiplyValue,t.DefaultMultiplyValue,n),s.overwriteValue=this.calculateValue(s.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?(s.additiveValue=d,s.multiplyValue=g,s.overwriteValue=c):(s.additiveValue=s.additiveValue*(1-n)+d*n,s.multiplyValue=s.multiplyValue*(1-n)+g*n,s.overwriteValue=s.overwriteValue*(1-n)+c*n)}}}getExpressionParameters(){return this._parameters}getFadeWeight(){return this._fadeWeight}parse(t,e){const i=Ve.create(t,e);if(!i)return;const s=i.getRoot();this.setFadeInTime(s.getValueByString("FadeInTime").toFloat(1)),this.setFadeOutTime(s.getValueByString("FadeOutTime").toFloat(1));const r=s.getValueByString(ri).getSize();this._parameters.prepareCapacity(r);for(let a=0;a<r;++a){const t=s.getValueByString(ri).getValueByIndex(a),e=We.getIdManager().getId(t.getValueByString("Id").getRawString()),i=t.getValueByString("Value").toFloat();let r;r=t.getValueByString(ai).isNull()||"Add"==t.getValueByString(ai).getString()?0:"Multiply"==t.getValueByString(ai).getString()?1:"Overwrite"==t.getValueByString(ai).getString()?2:0;const n=new di;n.parameterId=e,n.blendType=r,n.value=i,this._parameters.pushBack(n)}Ve.delete(i)}calculateValue(t,e,i){return t*(1-i)+e*i}constructor(){super(),this._parameters=new Zt,this._fadeWeight=0}};ni.DefaultAdditiveValue=0,ni.DefaultMultiplyValue=1;let oi=ni;var li,ui,hi=(t=>(t[t.Additive=0]="Additive",t[t.Multiply=1]="Multiply",t[t.Overwrite=2]="Overwrite",t))(hi||{});class di{}(t=>{t.CubismExpressionMotion=oi,t.ExpressionBlendType=hi,t.ExpressionParameter=di})(li||(li={}));class gi{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&&si.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=gi})(ui||(ui={}));class ci{constructor(){this._userTimeSeconds=0,this._eventCallBack=null,this._eventCustomData=null,this._motions=new Zt}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 mi;let s=null;for(let r=0;r<this._motions.getSize();++r)s=this._motions.at(r),null!=s&&s.setFadeOut(s._motion.getFadeOutTime());return s=new gi,s._autoDelete=e,s._motion=t,this._motions.pushBack(s),s._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 s=this._motions.begin();s.notEqual(this._motions.end());){let r=s.ptr();if(null==r){s=this._motions.erase(s);continue}const a=r._motion;if(null==a){r.release(),r=null,s=this._motions.erase(s);continue}a.updateParameters(t,r,e),i=!0;const n=a.getFiredEvent(r.getLastCheckEventSeconds()-r.getStartTime(),e-r.getStartTime());for(let t=0;t<n.getSize();++t)this._eventCallBack(this,n.at(t),this._eventCustomData);r.setLastCheckEventSeconds(e),r.isFinished()?(r.release(),r=null,s=this._motions.erase(s)):(r.isTriggeredFadeOut()&&r.startFadeOut(r.getFadeOutSeconds(),e),s.preIncrement())}return i}}const mi=-1;var pi;(t=>{t.CubismMotionQueueManager=ci,t.InvalidMotionQueueEntryHandleValue=mi})(pi||(pi={}));class _i extends B{constructor(t,e){var i,s;super(t,e),g(this,"expressionDataType","arraybuffer"),g(this,"queueManager",new ci),g(this,"definitions"),this.definitions=null!=(s=null==(i=t.expressions)?void 0:i.filter(t=>!!t&&"string"==typeof t.File))?s:[],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 oi.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 oi.create(t,t.byteLength)}}var fi,yi=(t=>(t[t.CubismMotionCurveTarget_Model=0]="CubismMotionCurveTarget_Model",t[t.CubismMotionCurveTarget_Parameter=1]="CubismMotionCurveTarget_Parameter",t[t.CubismMotionCurveTarget_PartOpacity=2]="CubismMotionCurveTarget_PartOpacity",t))(yi||{}),xi=(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))(xi||{});class Mi{constructor(){this.time=0,this.value=0}}class Ci{constructor(){this.evaluate=null,this.basePointIndex=0,this.segmentType=0}}class Si{constructor(){this.type=0,this.segmentCount=0,this.baseSegmentIndex=0,this.fadeInTime=0,this.fadeOutTime=0}}class vi{constructor(){this.fireTime=0}}class bi{constructor(){this.duration=0,this.loop=!1,this.curveCount=0,this.eventCount=0,this.fps=0,this.curves=new Zt,this.segments=new Zt,this.points=new Zt,this.events=new Zt}}(t=>{t.CubismMotionCurve=Si,t.CubismMotionCurveTarget=yi,t.CubismMotionData=bi,t.CubismMotionEvent=vi,t.CubismMotionPoint=Mi,t.CubismMotionSegment=Ci,t.CubismMotionSegmentType=xi})(fi||(fi={}));const Pi="Meta",Bi="Curves",wi="FadeInTime",Ii="FadeOutTime",Fi="Segments",Ei="UserData";class Li{constructor(t,e){this._json=Ve.create(t,e)}release(){Ve.delete(this._json)}getMotionDuration(){return this._json.getRoot().getValueByString(Pi).getValueByString("Duration").toFloat()}isMotionLoop(){return this._json.getRoot().getValueByString(Pi).getValueByString("Loop").toBoolean()}hasConsistency(){let t=!0;if(!this._json||!this._json.getRoot())return!1;const e=this._json.getRoot().getValueByString(Bi).getVector().getSize();let i=0,s=0;for(let r=0;r<e;++r)for(let t=0;t<this.getMotionCurveSegmentCount(r);){0==t&&(s+=1,t+=2);switch(this.getMotionCurveSegment(r,t)){case xi.CubismMotionSegmentType_Linear:s+=1,t+=3;break;case xi.CubismMotionSegmentType_Bezier:s+=3,t+=7;break;case xi.CubismMotionSegmentType_Stepped:case xi.CubismMotionSegmentType_InverseStepped:s+=1,t+=3;break;default:fe(0)}++i}return e!=this.getMotionCurveCount()&&(Me("The number of curves does not match the metadata."),t=!1),i!=this.getMotionTotalSegmentCount()&&(Me("The number of segment does not match the metadata."),t=!1),s!=this.getMotionTotalPointCount()&&(Me("The number of point does not match the metadata."),t=!1),t}getEvaluationOptionFlag(t){return 0==t&&this._json.getRoot().getValueByString(Pi).getValueByString("AreBeziersRestricted").toBoolean()}getMotionCurveCount(){return this._json.getRoot().getValueByString(Pi).getValueByString("CurveCount").toInt()}getMotionFps(){return this._json.getRoot().getValueByString(Pi).getValueByString("Fps").toFloat()}getMotionTotalSegmentCount(){return this._json.getRoot().getValueByString(Pi).getValueByString("TotalSegmentCount").toInt()}getMotionTotalPointCount(){return this._json.getRoot().getValueByString(Pi).getValueByString("TotalPointCount").toInt()}isExistMotionFadeInTime(){return!this._json.getRoot().getValueByString(Pi).getValueByString(wi).isNull()}isExistMotionFadeOutTime(){return!this._json.getRoot().getValueByString(Pi).getValueByString(Ii).isNull()}getMotionFadeInTime(){return this._json.getRoot().getValueByString(Pi).getValueByString(wi).toFloat()}getMotionFadeOutTime(){return this._json.getRoot().getValueByString(Pi).getValueByString(Ii).toFloat()}getMotionCurveTarget(t){return this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString("Target").getRawString()}getMotionCurveId(t){return We.getIdManager().getId(this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString("Id").getRawString())}isExistMotionCurveFadeInTime(t){return!this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString(wi).isNull()}isExistMotionCurveFadeOutTime(t){return!this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString(Ii).isNull()}getMotionCurveFadeInTime(t){return this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString(wi).toFloat()}getMotionCurveFadeOutTime(t){return this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString(Ii).toFloat()}getMotionCurveSegmentCount(t){return this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString(Fi).getVector().getSize()}getMotionCurveSegment(t,e){return this._json.getRoot().getValueByString(Bi).getValueByIndex(t).getValueByString(Fi).getValueByIndex(e).toFloat()}getEventCount(){return this._json.getRoot().getValueByString(Pi).getValueByString("UserDataCount").toInt()}getTotalEventValueSize(){return this._json.getRoot().getValueByString(Pi).getValueByString("TotalUserDataSize").toInt()}getEventTime(t){return this._json.getRoot().getValueByString(Ei).getValueByIndex(t).getValueByString("Time").toFloat()}getEventValue(t){return new ne(this._json.getRoot().getValueByString(Ei).getValueByIndex(t).getValueByString("Value").getRawString())}}var Vi,Ti=(t=>(t[t.EvaluationOptionFlag_AreBeziersRistricted=0]="EvaluationOptionFlag_AreBeziersRistricted",t))(Ti||{});(t=>{t.CubismMotionJson=Li})(Vi||(Vi={}));const Ri="Opacity";function Di(t,e,i){const s=new Mi;return s.time=t.time+(e.time-t.time)*i,s.value=t.value+(e.value-t.value)*i,s}function Ai(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 Oi(t,e){let i=(e-t[0].time)/(t[3].time-t[0].time);i<0&&(i=0);const s=Di(t[0],t[1],i),r=Di(t[1],t[2],i),a=Di(t[2],t[3],i),n=Di(s,r,i),o=Di(r,a,i);return Di(n,o,i).value}function ki(t,e){const i=e,s=t[0].time,r=t[3].time,a=t[1].time,n=t[2].time,o=r-3*n+3*a-s,l=3*n-6*a+3*s,u=3*a-3*s,h=s-i,d=ti.cardanoAlgorithmForBezier(o,l,u,h),g=Di(t[0],t[1],d),c=Di(t[1],t[2],d),m=Di(t[2],t[3],d),p=Di(g,c,d),_=Di(c,m,d);return Di(p,_,d).value}function Ni(t,e){return t[0].value}function Ui(t,e){return t[1].value}function zi(t,e,i,s,r){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==xi.CubismMotionSegmentType_Bezier?3:1),t.points.at(l).time>i){n=h;break}if(-1==n)return s&&i<r?function(t,e,i,s,r,a){const n=[new Mi,new Mi];{const e=t.points.at(s);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 xi.CubismMotionSegmentType_Linear:case xi.CubismMotionSegmentType_Bezier:default:return Ai(n,r);case xi.CubismMotionSegmentType_Stepped:return Ni(n);case xi.CubismMotionSegmentType_InverseStepped:return Ui(n)}}(t,o-1,t.segments.at(a.baseSegmentIndex).basePointIndex,l,i,r):t.points.at(l).value;const u=t.segments.at(n);return u.evaluate(t.points.get(u.basePointIndex),i)}class ji extends si{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,s,r=!1){const a=new ji;return a.parse(t,e,r),a._motionData?(a._sourceFrameRate=a._motionData.fps,a._loopDurationSeconds=a._motionData.duration,a._onFinishedMotion=i,a._onBeganMotion=s,a):(qe(a),null)}doUpdateParameters(t,e,i,s){null==this._modelCurveIdEyeBlink&&(this._modelCurveIdEyeBlink=We.getIdManager().getId("EyeBlink")),null==this._modelCurveIdLipSync&&(this._modelCurveIdLipSync=We.getIdManager().getId("LipSync")),null==this._modelCurveIdOpacity&&(this._modelCurveIdOpacity=We.getIdManager().getId(Ri)),1===this._motionBehavior&&this._previousLoopState!==this._isLoop&&(this.adjustEndTime(s),this._previousLoopState=this._isLoop);let r=e-s.getStartTime();r<0&&(r=0);let a=Number.MAX_VALUE,n=Number.MAX_VALUE;const o=64;let l=0,u=0;this._eyeBlinkParameterIds.getSize()>o&&ye("too many eye blink targets : {0}",this._eyeBlinkParameterIds.getSize()),this._lipSyncParameterIds.getSize()>o&&ye("too many lip sync targets : {0}",this._lipSyncParameterIds.getSize());const h=this._fadeInSeconds<=0?1:ti.getEasingSine((e-s.getFadeInStartTime())/this._fadeInSeconds),d=this._fadeOutSeconds<=0||s.getEndTime()<0?1:ti.getEasingSine((s.getEndTime()-e)/this._fadeOutSeconds);let g,c,m,p=r,_=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==yi.CubismMotionCurveTarget_Model;++c)g=zi(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==yi.CubismMotionCurveTarget_Parameter;++c){if(m=t.getParameterIndex(y.at(c).id),-1==m)continue;const r=t.getParameterValueByIndex(m);if(g=zi(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=r+(g-r)*i;else{let t,i;t=y.at(c).fadeInTime<0?h:0==y.at(c).fadeInTime?1:ti.getEasingSine((e-s.getFadeInStartTime())/y.at(c).fadeInTime),i=y.at(c).fadeOutTime<0?d:0==y.at(c).fadeOutTime||s.getEndTime()<0?1:ti.getEasingSine((s.getEndTime()-e)/y.at(c).fadeOutTime);x=r+(g-r)*(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 s=e+(n-e)*i;t.setParameterValueById(this._eyeBlinkParameterIds.at(x),s)}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 s=e+(a-e)*i;t.setParameterValueById(this._lipSyncParameterIds.at(x),s)}for(;c<this._motionData.curveCount&&y.at(c).type==yi.CubismMotionCurveTarget_PartOpacity;++c)m=t.getParameterIndex(y.at(c).id),-1!=m&&(g=zi(this._motionData,c,p,f,_),t.setParameterValueByIndex(m,g));r>=_&&(this._isLoop?this.updateForNextLoop(s,e,p):(this._onFinishedMotion&&this._onFinishedMotion(this),s.setIsFinished(!0))),this._lastWeight=i}setIsLoop(t){Me("setIsLoop() is a deprecated function. Please use setLoop()."),this._isLoop=t}isLoop(){return Me("isLoop() is a deprecated function. Please use getLoop()."),this._isLoop}setIsLoopFadeIn(t){Me("setIsLoopFadeIn() is a deprecated function. Please use setLoopFadeIn()."),this._isLoopFadeIn=t}isLoopFadeIn(){return Me("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 s=0;s<this._motionData.curveCount;++s)if(t==i.at(s).id)return void(i.at(s).fadeInTime=e)}setParameterFadeOutTime(t,e){const i=this._motionData.curves;for(let s=0;s<this._motionData.curveCount;++s)if(t==i.at(s).id)return void(i.at(s).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 s=new Li(t,e);if(!s)return s.release(),void(s=void 0);if(i){if(!s.hasConsistency())return s.release(),void Ce("Inconsistent motion3.json.")}this._motionData=new bi,this._motionData.duration=s.getMotionDuration(),this._motionData.loop=s.isMotionLoop(),this._motionData.curveCount=s.getMotionCurveCount(),this._motionData.fps=s.getMotionFps(),this._motionData.eventCount=s.getEventCount();const r=s.getEvaluationOptionFlag(Ti.EvaluationOptionFlag_AreBeziersRistricted);s.isExistMotionFadeInTime()?this._fadeInSeconds=s.getMotionFadeInTime()<0?1:s.getMotionFadeInTime():this._fadeInSeconds=1,s.isExistMotionFadeOutTime()?this._fadeOutSeconds=s.getMotionFadeOutTime()<0?1:s.getMotionFadeOutTime():this._fadeOutSeconds=1,this._motionData.curves.updateSize(this._motionData.curveCount,Si,!0),this._motionData.segments.updateSize(s.getMotionTotalSegmentCount(),Ci,!0),this._motionData.points.updateSize(s.getMotionTotalPointCount(),Mi,!0),this._motionData.events.updateSize(this._motionData.eventCount,vi,!0);let a=0,n=0;for(let o=0;o<this._motionData.curveCount;++o){"Model"==s.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=yi.CubismMotionCurveTarget_Model:"Parameter"==s.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=yi.CubismMotionCurveTarget_Parameter:"PartOpacity"==s.getMotionCurveTarget(o)?this._motionData.curves.at(o).type=yi.CubismMotionCurveTarget_PartOpacity:Me('Warning : Unable to get segment type from Curve! The number of "CurveCount" may be incorrect!'),this._motionData.curves.at(o).id=s.getMotionCurveId(o),this._motionData.curves.at(o).baseSegmentIndex=n,this._motionData.curves.at(o).fadeInTime=s.isExistMotionCurveFadeInTime(o)?s.getMotionCurveFadeInTime(o):-1,this._motionData.curves.at(o).fadeOutTime=s.isExistMotionCurveFadeOutTime(o)?s.getMotionCurveFadeOutTime(o):-1;for(let t=0;t<s.getMotionCurveSegmentCount(o);){0==t?(this._motionData.segments.at(n).basePointIndex=a,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+1),a+=1,t+=2):this._motionData.segments.at(n).basePointIndex=a-1;switch(s.getMotionCurveSegment(o,t)){case xi.CubismMotionSegmentType_Linear:this._motionData.segments.at(n).segmentType=xi.CubismMotionSegmentType_Linear,this._motionData.segments.at(n).evaluate=Ai,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case xi.CubismMotionSegmentType_Bezier:this._motionData.segments.at(n).segmentType=xi.CubismMotionSegmentType_Bezier,this._motionData.segments.at(n).evaluate=r?Oi:ki,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),this._motionData.points.at(a+1).time=s.getMotionCurveSegment(o,t+3),this._motionData.points.at(a+1).value=s.getMotionCurveSegment(o,t+4),this._motionData.points.at(a+2).time=s.getMotionCurveSegment(o,t+5),this._motionData.points.at(a+2).value=s.getMotionCurveSegment(o,t+6),a+=3,t+=7;break;case xi.CubismMotionSegmentType_Stepped:this._motionData.segments.at(n).segmentType=xi.CubismMotionSegmentType_Stepped,this._motionData.segments.at(n).evaluate=Ni,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;case xi.CubismMotionSegmentType_InverseStepped:this._motionData.segments.at(n).segmentType=xi.CubismMotionSegmentType_InverseStepped,this._motionData.segments.at(n).evaluate=Ui,this._motionData.points.at(a).time=s.getMotionCurveSegment(o,t+1),this._motionData.points.at(a).value=s.getMotionCurveSegment(o,t+2),a+=1,t+=3;break;default:fe(0)}++this._motionData.curves.at(o).segmentCount,++n}}for(let o=0;o<s.getEventCount();++o)this._motionData.events.at(o).fireTime=s.getEventTime(o),this._motionData.events.at(o).value=s.getEventValue(o);s.release(),s=void 0,s=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 ne(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==yi.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(Ri))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==yi.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(Ri))return t}return-1}getModelOpacityId(t){if(-1!=t){const e=this._motionData.curves.at(t);if(e.type==yi.CubismMotionCurveTarget_Model&&0==e.id.getString().s.localeCompare(Ri))return We.getIdManager().getId(e.id.getString().s)}return null}getModelOpacityValue(){return this._modelOpacity}setDebugMode(t){this._debugMode=t}}var Gi;function Xi(t,e,i){const s=t.startMotion(i,!1),r=t.getCubismMotionQueueEntry(s);if(!r)return!1;r.setStartTime(0),r.setFadeInStartTime(0);const a=i.getDuration(),n=r.getStartTime()+a;return i.doUpdateParameters(e.coreModel,n,1,r),r.setIsFinished(!0),!0}(t=>{t.CubismMotion=ji})(Gi||(Gi={}));class Hi extends O{constructor(t){var e;super(t),g(this,"definitions"),g(this,"groups",{idle:"Idle"}),g(this,"motionDataType","arraybuffer"),g(this,"queueManager",new ci),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 _i(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,s=function(t){if(Yi(t))return new Zt;return[]}(e),r=qi(e);for(let t=0;t<r;t++){const r=Wi(e,t);if(!r)continue;const a=Ji(r);a&&i.includes(a)||$i(s,r)}t._motionData.curves=s,t._motionData.curveCount=qi(s)}return this.queueManager.stopAllMotions(),this.queueManager.startMotion(t,!1)}_stopAllMotions(){this.queueManager.stopAllMotions()}createMotion(t,e,i){const s=!!this.parent.options.checkMotionConsistency,r=ji.create(t,t.byteLength,void 0,void 0,s),a=new Li(t,t.byteLength);r.setLoop(a.isMotionLoop());const n=(e===this.groups.idle?m.idleMotionFadingDuration:m.motionFadingDuration)/1e3;return void 0===a.getMotionFadeInTime()&&r.setFadeInTime(i.FadeInTime>0?i.FadeInTime:n),void 0===a.getMotionFadeOutTime()&&r.setFadeOutTime(i.FadeOutTime>0?i.FadeOutTime:n),r.setEffectIds(this.createIdVector(this.eyeBlinkIds),this.createIdVector(this.lipSyncIds)),r}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 s=yield this.getMotionAndApplyExpression(t,e,i);return!!s&&(this.playing=!0,Xi(this.queueManager,this.parent,s),this.playing=!1,!0)})}createIdVector(t){const e=new Zt,i=We.getIdManager();for(const s of t)e.pushBack(i.getId(s));return e}}function Yi(t){return"function"==typeof t.pushBack}function qi(t){return Yi(t)?t.getSize():t.length}function Wi(t,e){return Yi(t)?t.at(e):t[e]}function Ji(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 $i(t,e){Yi(t)?t.pushBack(e):t.push(e)}class Zi extends Ut{constructor(t){super(t),g(this,"queueManager",new ci),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,s=function(t){if(Ki(t))return new Zt;return[]}(e),r=Qi(e);for(let t=0;t<r;t++){const r=ts(e,t);if(!r)continue;const a=es(r);a&&i.includes(a)||is(s,r)}t._motionData.curves=s,t._motionData.curveCount=Qi(s)}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,L.FORCE))return!1;const s=null==(i=this.manager.definitions[t])?void 0:i[e];if(!s)return!1;const r=yield this.manager.loadMotion(t,e);return!!this.state.start(r,t,e,L.FORCE)&&(p.log(this.tag,"Start motion:",this.getMotionName(s)),this.emit("motionStart",t,e,void 0),this.playing=!0,this.queueManager.stopAllMotions(),Xi(this.queueManager,this.parent,r)?(this.playing=!1,!0):(this.playing=!1,!1))})}}function Ki(t){return"function"==typeof t.pushBack}function Qi(t){return Ki(t)?t.getSize():t.length}function ts(t,e){return Ki(t)?t.at(e):t[e]}function es(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 is(t,e){Ki(t)?t.pushBack(e):t.push(e)}const ss=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 rs,as;(t=>{t.HitAreaBody=ss.HitAreaBody,t.HitAreaHead=ss.HitAreaHead,t.HitAreaPrefix=ss.HitAreaPrefix,t.ParamAngleX=ss.ParamAngleX,t.ParamAngleY=ss.ParamAngleY,t.ParamAngleZ=ss.ParamAngleZ,t.ParamArmLA=ss.ParamArmLA,t.ParamArmLB=ss.ParamArmLB,t.ParamArmRA=ss.ParamArmRA,t.ParamArmRB=ss.ParamArmRB,t.ParamBaseX=ss.ParamBaseX,t.ParamBaseY=ss.ParamBaseY,t.ParamBodyAngleX=ss.ParamBodyAngleX,t.ParamBodyAngleY=ss.ParamBodyAngleY,t.ParamBodyAngleZ=ss.ParamBodyAngleZ,t.ParamBreath=ss.ParamBreath,t.ParamBrowLAngle=ss.ParamBrowLAngle,t.ParamBrowLForm=ss.ParamBrowLForm,t.ParamBrowLX=ss.ParamBrowLX,t.ParamBrowLY=ss.ParamBrowLY,t.ParamBrowRAngle=ss.ParamBrowRAngle,t.ParamBrowRForm=ss.ParamBrowRForm,t.ParamBrowRX=ss.ParamBrowRX,t.ParamBrowRY=ss.ParamBrowRY,t.ParamBustX=ss.ParamBustX,t.ParamBustY=ss.ParamBustY,t.ParamCheek=ss.ParamCheek,t.ParamEyeBallForm=ss.ParamEyeBallForm,t.ParamEyeBallX=ss.ParamEyeBallX,t.ParamEyeBallY=ss.ParamEyeBallY,t.ParamEyeLOpen=ss.ParamEyeLOpen,t.ParamEyeLSmile=ss.ParamEyeLSmile,t.ParamEyeROpen=ss.ParamEyeROpen,t.ParamEyeRSmile=ss.ParamEyeRSmile,t.ParamHairBack=ss.ParamHairBack,t.ParamHairFluffy=ss.ParamHairFluffy,t.ParamHairFront=ss.ParamHairFront,t.ParamHairSide=ss.ParamHairSide,t.ParamHandL=ss.ParamHandL,t.ParamHandR=ss.ParamHandR,t.ParamMouthForm=ss.ParamMouthForm,t.ParamMouthOpenY=ss.ParamMouthOpenY,t.ParamNONE=ss.ParamNONE,t.ParamShoulderY=ss.ParamShoulderY,t.PartsArmLPrefix=ss.PartsArmLPrefix,t.PartsArmPrefix=ss.PartsArmPrefix,t.PartsArmRPrefix=ss.PartsArmRPrefix,t.PartsIdCore=ss.PartsIdCore})(rs||(rs={}));class ns{static create(){return new ns}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 s=0;s<this._breathParameters.getSize();++s){const e=this._breathParameters.at(s);t.addParameterValueById(e.parameterId,e.offset+e.peak*Math.sin(i/e.cycle),e.weight)}}constructor(){this._currentTime=0}}class os{constructor(t,e,i,s,r){this.parameterId=null==t?null:t,this.offset=null==e?0:e,this.peak=null==i?0:i,this.cycle=null==s?0:s,this.weight=null==r?0:r}}(t=>{t.BreathParameterData=os,t.CubismBreath=ns})(as||(as={}));const ls=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 s;this._userTimeSeconds+=i;let r=0;switch(this._blinkingState){case 2:r=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closingSeconds,r>=1&&(r=1,this._blinkingState=3,this._stateStartTimeSeconds=this._userTimeSeconds),s=1-r;break;case 3:r=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closedSeconds,r>=1&&(this._blinkingState=4,this._stateStartTimeSeconds=this._userTimeSeconds),s=0;break;case 4:r=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._openingSeconds,r>=1&&(r=1,this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming()),s=r;break;case 1:this._nextBlinkingTime<this._userTimeSeconds&&(this._blinkingState=2,this._stateStartTimeSeconds=this._userTimeSeconds),s=1;break;default:this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming(),s=1}t.CloseIfZero||(s=-s);for(let t=0;t<this._parameterIds.getSize();++t)e.setParameterValueById(this._parameterIds.at(t),s)}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 Zt,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)}};ls.CloseIfZero=!0;let us=ls;var hs,ds=(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))(ds||{});(t=>{t.CubismEyeBlink=us,t.EyeState=ds})(hs||(hs={}));class gs{constructor(t){this._renderTextureCount=0,this._clippingMaskBufferSize=256,this._clippingContextListForMask=new Zt,this._clippingContextListForDraw=new Zt,this._channelColors=new Zt,this._tmpBoundsOnModel=new he,this._tmpMatrix=new ue,this._tmpMatrixForMask=new ue,this._tmpMatrixForDraw=new ue,this._clippingContexttConstructor=t;let e=new me;e.r=1,e.g=0,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new me,e.r=0,e.g=1,e.b=0,e.a=0,this._channelColors.pushBack(e),e=new me,e.r=0,e.g=0,e.b=1,e.a=0,this._channelColors.pushBack(e),e=new me,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&&(Me("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&&Me("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 Zt(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 s=this._clippingContextListForMask.at(i),r=s._clippingIdCount;if(r!=e)continue;let a=0;for(let e=0;e<r;e++){const i=s._clippingIdList[e];for(let e=0;e<r;e++)if(t[e]==i){a++;break}}if(a==r)return s}return null}setupMatrixForHighPrecision(t,e){let i=0;for(let s=0;s<this._clippingContextListForMask.getSize();s++){const e=this._clippingContextListForMask.at(s);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 s=this._clippingContextListForMask.at(i),r=s._allClippedDrawRect,a=s._layoutBounds,n=.05;let o=0,l=0;const u=t.getPixelsPerUnit(),h=s.getClippingManager().getClippingMaskBufferSize(),d=a.width*h,g=a.height*h;this._tmpBoundsOnModel.setRect(r),this._tmpBoundsOnModel.width*u>d?(this._tmpBoundsOnModel.expand(r.width*n,0),o=a.width/this._tmpBoundsOnModel.width):o=u/d,this._tmpBoundsOnModel.height*u>g?(this._tmpBoundsOnModel.expand(0,r.height*n),l=a.height/this._tmpBoundsOnModel.height):l=u/g,this.createMatrixForMask(e,a,o,l),s._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),s._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray())}}}createMatrixForMask(t,e,i,s){this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(e.x,e.y),this._tmpMatrix.scaleRelative(i,s),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,s*(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&&Ce("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 s=t/this._renderTextureCount;const r=t%this._renderTextureCount;s=Math.ceil(s);let a=s/4;const n=s%4;a=~~a;let o=0;for(let l=0;l<this._renderTextureCount;l++)for(let s=0;s<4;s++){let u=a+(s<n?1:0);if(s==n+(a<1?-1:0)&&r>0&&(u-=l<r?0:1),0==u);else if(1==u){const t=this._clippingContextListForMask.at(o++);t._layoutChannelIndex=s,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=s,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 r=this._clippingContextListForMask.at(o++);r._layoutChannelIndex=s,r._layoutBounds.x=.5*e,r._layoutBounds.y=.5*i,r._layoutBounds.width=.5,r._layoutBounds.height=.5,r._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 r=this._clippingContextListForMask.at(o++);r._layoutChannelIndex=s,r._layoutBounds.x=e/3,r._layoutBounds.y=i/3,r._layoutBounds.width=1/3,r._layoutBounds.height=1/3,r._bufferIndex=l}else{Ce("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,s=Number.MAX_VALUE,r=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*Ye.vertexStep;for(let t=Ye.vertexOffset;t<m;t+=Ye.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<s&&(s=d),g>r&&(r=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=r-i,n=a-s;e._allClippedDrawRect.x=i,e._allClippedDrawRect.y=s,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 cs;class ms{constructor(){this._shaderSets=new Zt}release(){this.releaseShaderProgram()}setupShaderProgramForDraw(t,e,i){let s,r,a,n;t.isPremultipliedAlpha()||Ce("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 ce.CubismBlendMode_Normal:default:h=this._shaderSets.at(1+u),s=this.gl.ONE,r=this.gl.ONE_MINUS_SRC_ALPHA,a=this.gl.ONE,n=this.gl.ONE_MINUS_SRC_ALPHA;break;case ce.CubismBlendMode_Additive:h=this._shaderSets.at(4+u),s=this.gl.ONE,r=this.gl.ONE,a=this.gl.ZERO,n=this.gl.ONE;break;case ce.CubismBlendMode_Multiplicative:h=this._shaderSets.at(7+u),s=this.gl.DST_COLOR,r=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,s=t.getClippingContextBufferForDraw().getClippingManager().getChannelFlagAsColor(i);this.gl.uniform4f(h.uniformChannelFlagLocation,s.r,s.g,s.b,s.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(s,r,a,n)}setupShaderProgramForMask(t,e,i){t.isPremultipliedAlpha()||Ce("NoPremultipliedAlpha is not allowed"),0==this._shaderSets.getSize()&&this.generateShaders();const s=this._shaderSets.at(0);this.gl.useProgram(s.shaderProgram),null==t._bufferData.vertex&&(t._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t._bufferData.vertex);const r=e.getDrawableVertices(i);this.gl.bufferData(this.gl.ARRAY_BUFFER,r,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(s.attributePositionLocation),this.gl.vertexAttribPointer(s.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(s.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(s.attributeTexCoordLocation),this.gl.vertexAttribPointer(s.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),t.getClippingContextBufferForMask();const l=t.getClippingContextBufferForMask()._layoutChannelIndex,u=t.getClippingContextBufferForMask().getClippingManager().getChannelFlagAsColor(l);this.gl.uniform4f(s.uniformChannelFlagLocation,u.r,u.g,u.b,u.a),this.gl.uniformMatrix4fv(s.uniformClipMatrixLocation,!1,t.getClippingContextBufferForMask()._matrixForMask.getArray());const h=t.getClippingContextBufferForMask()._layoutBounds;this.gl.uniform4f(s.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(s.uniformMultiplyColorLocation,d.r,d.g,d.b,d.a),this.gl.uniform4f(s.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 _s);this._shaderSets.at(0).shaderProgram=this.loadShaderProgram(ys,xs),this._shaderSets.at(1).shaderProgram=this.loadShaderProgram(Ms,Ss),this._shaderSets.at(2).shaderProgram=this.loadShaderProgram(Cs,vs),this._shaderSets.at(3).shaderProgram=this.loadShaderProgram(Cs,bs),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(),s=this.compileShaderSource(this.gl.VERTEX_SHADER,t);if(!s)return Ce("Vertex shader compile error!"),0;let r=this.compileShaderSource(this.gl.FRAGMENT_SHADER,e);if(!r)return Ce("Vertex shader compile error!"),0;this.gl.attachShader(i,s),this.gl.attachShader(i,r),this.gl.linkProgram(i);return this.gl.getProgramParameter(i,this.gl.LINK_STATUS)?(this.gl.deleteShader(s),this.gl.deleteShader(r),i):(Ce("Failed to link program: {0}",i),this.gl.deleteShader(s),s=0,this.gl.deleteShader(r),r=0,i&&(this.gl.deleteProgram(i),i=0),0)}compileShaderSource(t,e){const i=e,s=this.gl.createShader(t);if(this.gl.shaderSource(s,i),this.gl.compileShader(s),!s){const t=this.gl.getShaderInfoLog(s);Ce("Shader compile log: {0} ",t)}return this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)?s:(this.gl.deleteShader(s),null)}setGl(t){this.gl=t}}class ps{static getInstance(){return null==cs&&(cs=new ps),cs}static deleteInstance(){cs&&(cs.release(),cs=null)}constructor(){this._shaderMap=new Be}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 ms;e.setGl(t),this._shaderMap.setValue(t,e)}}}class _s{}var fs=(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))(fs||{});const ys="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;}",xs="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;}",Ms="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;}",Cs="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;}",Ss="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);}",vs="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;}",bs="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 Ps;let Bs,ws;(t=>{t.CubismShaderSet=_s,t.CubismShader_WebGL=ms,t.CubismShaderManager_WebGL=ps,t.ShaderNames=fs})(Ps||(Ps={}));class Is extends gs{getMaskRenderTexture(){if(this._maskTexture&&null!=this._maskTexture.textures)this._maskTexture.frameNo=this._currentFrameNo;else{null!=this._maskRenderTextures&&this._maskRenderTextures.clear(),this._maskRenderTextures=new Zt,null!=this._maskColorBuffers&&this._maskColorBuffers.clear(),this._maskColorBuffers=new Zt;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,ws),this._maskTexture=new Fs(this._currentFrameNo,this._maskRenderTextures)}return this._maskTexture.textures}setGL(t){this.gl=t}constructor(){super(Es)}setupClippingContext(t,e){this._currentFrameNo++;let i=0;for(let s=0;s<this._clippingContextListForMask.getSize();s++){const e=this._clippingContextListForMask.at(s);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 Zt(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 s=this._clippingContextListForMask.at(i),r=s._allClippedDrawRect,a=s._layoutBounds,n=.05;let o=0,l=0;const u=this.getMaskRenderTexture().at(s._bufferIndex);this._currentMaskRenderTexture!=u&&(this._currentMaskRenderTexture=u,e.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentMaskRenderTexture)),this._tmpBoundsOnModel.setRect(r),this._tmpBoundsOnModel.expand(r.width*n,r.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()),s._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),s._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray());const h=s._clippingIdCount;for(let i=0;i<h;i++){const r=s._clippingIdList[i];t.getDrawableDynamicFlagVertexPositionsDidChange(r)&&(e.setIsCulling(0!=t.getDrawableCulling(r)),this._clearedFrameBufferFlags.at(s._bufferIndex)||(this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this._clearedFrameBufferFlags.set(s._bufferIndex,!0)),e.setClippingContextBufferForMask(s),e.drawMeshWebGL(t,r))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,ws),e.setClippingContextBufferForMask(null),this.gl.viewport(Bs[0],Bs[1],Bs[2],Bs[3])}}getColorBuffer(){return this._maskColorBuffers}getClippingMaskCount(){return this._clippingContextListForMask.getSize()}}class Fs{constructor(t,e){this.frameNo=t,this.textures=e}}class Es extends pe{constructor(t,e,i){super(e,i),this._owner=t}getClippingManager(){return this._owner}setGl(t){this._owner.setGL(t)}}class Ls{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)):Ce("'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])):Ce("'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 Vs extends de{initialize(t,e=1){t.isUsingMasking()&&(this._clippingManager=new Is,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 Is,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 Ls,this.firstDraw=!0,this._textures=new Be,this._sortedDrawableIndexList=new Zt,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 Ce("'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,ws),this.setClippingContextBufferForMask(null),this.gl.viewport(Bs[0],Bs[1],Bs[2],Bs[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()?ps.getInstance().getShader(this.gl).setupShaderProgramForMask(this,t,e):ps.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(){ps.deleteInstance()}setRenderState(t,e){ws=t,Bs=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),ps.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 Ts;de.staticRelease=()=>{Vs.doStaticRelease()},(t=>{t.CubismClippingContext=Es,t.CubismClippingManager_WebGL=Is,t.CubismRenderTextureResource=Fs,t.CubismRenderer_WebGL=Vs})(Ts||(Ts={}));const Rs=new ue,Ds={CenterX:"centerX",centerX:"centerX",center_x:"centerX",CenterY:"centerY",centerY:"centerY",center_y:"centerY",X:"x",x:"x",Y:"y",y:"y",Width:"width",width:"width",Height:"height",height:"height",Top:"top",top:"top",Bottom:"bottom",bottom:"bottom",Left:"left",left:"left",Right:"right",right:"right"};function As(t){if(!t.isUsingMasking())return!1;const e=function(t){var e,i;const s=t.getDrawableMaskCounts(),r=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=s[d])?e:0;if(h+=n,g<=0)continue;o++,u+=n,l=Math.max(l,g);const c=Array.from(null!=(i=r[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 Os extends Z{constructor(t,i,s){super(),g(this,"settings"),g(this,"options"),g(this,"coreModel"),g(this,"motionManager"),g(this,"parallelMotionManager"),g(this,"lipSync",!0),g(this,"breath",ns.create()),g(this,"eyeBlink"),g(this,"renderer",new Vs),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},s),this.idManager=We.getIdManager(),this.idParamAngleX=this.getIdSafe(ss.ParamAngleX),this.idParamAngleY=this.getIdSafe(ss.ParamAngleY),this.idParamAngleZ=this.getIdSafe(ss.ParamAngleZ),this.idParamEyeBallX=this.getIdSafe(ss.ParamEyeBallX),this.idParamEyeBallY=this.getIdSafe(ss.ParamEyeBallY),this.idParamBodyAngleX=this.getIdSafe(ss.ParamBodyAngleX),this.idParamBreath=this.getIdSafe(ss.ParamBreath),this.idParamMouthForm=this.getIdSafe(ss.ParamMouthForm),this.motionManager=new Hi(this),this.parallelMotionManager=[],this.init()}init(){var t;super.init();const e=this.settings.getEyeBlinkParameters();if(e.length){const i=new Zt;for(const t of e)i.pushBack(this.idManager.getId(t));const s=us.create();null==(t=s.setParameterIds)||t.call(s,i),this.eyeBlink=s}const i=new Zt;var s,r;i.pushBack(new os(this.idParamAngleX,0,15*this.options.breathDepth,6.5345,.5)),i.pushBack(new os(this.idParamAngleY,0,8*this.options.breathDepth,3.5345,.5)),i.pushBack(new os(this.idParamAngleZ,0,10*this.options.breathDepth,5.5345,.5)),i.pushBack(new os(this.idParamBodyAngleX,0,4*this.options.breathDepth,15.5345,.5)),i.pushBack(new os(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(),s=t.getDrawableMasks(),r=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=s[n])?e:[]).slice(0,t).sort((t,e)=>t-e).join(",");r.add(a)}const a=r.size;return a<=36?1:Math.ceil(a/32)}(this.coreModel)),this.renderer.useHighPrecisionMask((s=this.coreModel,"boolean"==typeof(r=this.options.useHighPrecisionMask)?r:As(s))),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,s]of Object.entries(e)){const e=Ds[i];e&&"number"==typeof s&&(t[e]=s)}return t}setupLayout(){const t=this,e=this.getSize();t.originalWidth=e[0],t.originalHeight=e[1],t.pixelsPerUnit=this.coreModel.getModel().canvasinfo.PixelsPerUnit;const i=W(this.localTransform,this.originalWidth,this.originalHeight,this.getLayout());t.width=i.width,t.height=i.height,this.modelTransform.identity().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),ps.getInstance().setGlContext(t)}bindTexture(t,e){this.renderer.bindTexture(t,e)}getHitAreaDefs(){var t,e,i;const s=this.settings.json;return J(null!=(i=null!=(e=null!=(t=this.settings.hitAreas)?t:s.HitAreas)?e:s.hitAreas)?i:s.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,s,r,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==(r=null==(s=this.eyeBlink)?void 0:s.updateParameters)||r.call(s,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=_(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=Rs.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(Rs);const s=t.getParameter(t.FRAMEBUFFER_BINDING);this.renderer.setRenderState(s,this.viewport),this.renderer.drawModel()}extendParallelMotionManager(t){for(;this.parallelMotionManager.length<t;)this.parallelMotionManager.push(new Zi(this))}destroy(){super.destroy(),this.renderer.release(),this.coreModel.release(),this.renderer=void 0,this.coreModel=void 0}}class ks{}var Ns;(t=>{t.ICubismModelSetting=ks})(Ns||(Ns={}));var Us,zs=(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))(zs||{});class js extends ks{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=Ve.create(t,e),this.getJson()&&(this._jsonValue=new Zt,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(){Ve.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 s=0;s<e;s++)i+=t[s],s<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 We.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 s=e.begin();s.notEqual(e.end());s.preIncrement())t.setValue(s.ptr().first,s.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 We.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 We.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=js,t.FrequestNode=zs})(Us||(Us={}));const Gs=[ss.ParamEyeLOpen,ss.ParamEyeROpen];class Xs extends E{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"),!Xs.isValidJSON(t))throw new TypeError("Invalid JSON.");const s=(new TextEncoder).encode(JSON.stringify(t)).buffer;Object.assign(this,new js(s,s.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 r=this.getFileStem(this.moc);this.setModelName(r,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 s=e.Expressions;return!(void 0!==s&&(!Array.isArray(s)||s.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 s=0;s<i.length;s++){const r=i[s];(null==r?void 0:r.File)&&(r.File=t(r.File,`motions.${e}[${s}].File`),r.Sound&&(r.Sound=t(r.Sound,`motions.${e}[${s}].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 s=[],r=null!=(e=null==(t=this.getEyeBlinkParameterCount)?void 0:t.call(this))?e:0;if(r>0)for(let a=0;a<r;a++){const t=null==(i=this.getEyeBlinkParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&s.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?s.push(t):(null==t?void 0:t.Id)&&s.push(t.Id)}return s.length?s:[...Gs]}getLipSyncParameters(){var t,e,i;const s=[],r=null!=(e=null==(t=this.getLipSyncParameterCount)?void 0:t.call(this))?e:0;if(r>0)for(let a=0;a<r;a++){const t=null==(i=this.getLipSyncParameterId)?void 0:i.call(this,a);(null==t?void 0:t.getString)&&s.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?s.push(t):(null==t?void 0:t.Id)&&s.push(t.Id)}return s}}let Hs;C(Xs,[js]);let Ys=20,qs=16;function Ws(t={}){null!=t.memorySizeMB&&(qs=t.memorySizeMB)}function Js(){return We.isStarted()?Promise.resolve():(null!=Hs||(Hs=new Promise((t,e)=>{!function i(){try{$s(),t()}catch(s){if(Ys--,Ys<0)return void e(new Error("Failed to start up Cubism framework.",{cause:s}));p.log("Cubism","Startup failed, retrying 10ms later..."),setTimeout(i,10)}}()})),Hs)}function $s(t,e){const i=d({logFunction:console.log,loggingLevel:Ze.LogLevel_Verbose},t),s=null!=e?e:qs;We.startUp(i),We.initialize(y(s))}const Zs="FadeInTime",Ks="Link";class Qs{static create(t,e){const i=Ve.create(t,e);if(!i)return null;const s=new Qs,r=i.getRoot();r.getValueByString(Zs).isNull()||(s._fadeTimeSeconds=r.getValueByString(Zs).toFloat(.5),s._fadeTimeSeconds<0&&(s._fadeTimeSeconds=.5));const a=r.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 r=0;r<e;++r){const e=t.getValueByIndex(r),a=new tr,n=We.getIdManager().getId(e.getValueByString("Id").getRawString());if(a.partId=n,!e.getValueByString(Ks).isNull()){const t=e.getValueByString(Ks),i=t.getSize();for(let e=0;e<i;++e){const i=new tr,s=We.getIdManager().getId(t.getValueByIndex(e).getString());i.partId=s,a.link.pushBack(i)}}s._partGroups.pushBack(a.clone()),++i}s._partGroupCounts.pushBack(i)}return Ve.delete(i),s}static delete(t){}updateParameters(t,e){t!=this._lastModel&&this.reset(t),this._lastModel=t,e<0&&(e=0);let i=0;for(let s=0;s<this._partGroupCounts.getSize();s++){const r=this._partGroupCounts.at(s);this.doFade(t,e,i,r),i+=r}this.copyPartOpacities(t)}reset(t){let e=0;for(let i=0;i<this._partGroupCounts.getSize();++i){const s=this._partGroupCounts.at(i);for(let i=e;i<e+s;++i){this._partGroups.at(i).initialize(t);const s=this._partGroups.at(i).partIndex,r=this._partGroups.at(i).parameterIndex;if(!(s<0)){t.setPartOpacityByIndex(s,i==e?1:0),t.setParameterValueByIndex(r,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+=s}}copyPartOpacities(t){for(let e=0;e<this._partGroups.getSize();++e){const i=this._partGroups.at(e);if(0==i.link.getSize())continue;const s=this._partGroups.at(e).partIndex,r=t.getPartOpacityByIndex(s);for(let e=0;e<i.link.getSize();++e){const s=i.link.at(e).partIndex;s<0||t.setPartOpacityByIndex(s,r)}}}doFade(t,e,i,s){let r=-1,a=1;const n=.5;for(let o=i;o<i+s;++o){const i=this._partGroups.at(o).partIndex,s=this._partGroups.at(o).parameterIndex;if(t.getParameterValueByIndex(s)>.001){if(r>=0)break;if(r=o,0==this._fadeTimeSeconds){a=1;continue}a=t.getPartOpacityByIndex(i),a+=e/this._fadeTimeSeconds,a>1&&(a=1)}}r<0&&(r=0,a=1);for(let o=i;o<i+s;++o){const e=this._partGroups.at(o).partIndex;if(r==o)t.setPartOpacityByIndex(e,a);else{let i,s=t.getPartOpacityByIndex(e);i=a<n?-.5*a/n+1:(1-a)*n/.5;(1-i)*(1-a)>.15&&(i=1-.15/(1-a)),s>i&&(s=i),t.setPartOpacityByIndex(e,s)}}}constructor(){this._fadeTimeSeconds=.5,this._lastModel=null,this._partGroups=new Zt,this._partGroupCounts=new Zt}}class tr{constructor(t){if(this.parameterIndex=0,this.partIndex=0,this.link=new Zt,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 tr;t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=new Zt;for(let e=this.link.begin();e.notEqual(this.link.end());e.increment())t.link.pushBack(e.ptr().clone());return t}}var er,ir,sr;(t=>{t.CubismPose=Qs,t.PartData=tr})(er||(er={}));class rr{constructor(t=!1,e=!1){this.isOverridden=t,this.isParameterRepeated=e}}class ar{constructor(t=!1,e=new me){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class nr{constructor(t=!1,e=new me){this.isOverridden=t,this.color=e}get isOverwritten(){return this.isOverridden}}class or{constructor(t=!1,e=!1){this.isOverridden=t,this.isCulling=e}get isOverwritten(){return this.isOverridden}}class lr{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,s,r=1){this._userMultiplyColors.at(t).color.r=e,this._userMultiplyColors.at(t).color.g=i,this._userMultiplyColors.at(t).color.b=s,this._userMultiplyColors.at(t).color.a=r}setScreenColorByTextureColor(t,e){this.setScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setScreenColorByRGBA(t,e,i,s,r=1){this._userScreenColors.at(t).color.r=e,this._userScreenColors.at(t).color.g=i,this._userScreenColors.at(t).color.b=s,this._userScreenColors.at(t).color.a=r}getPartMultiplyColor(t){return this._userPartMultiplyColors.at(t).color}getPartScreenColor(t){return this._userPartScreenColors.at(t).color}setPartColor(t,e,i,s,r,a,n){if(a.at(t).color.r=e,a.at(t).color.g=i,a.at(t).color.b=s,a.at(t).color.a=r,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=s,n.at(a).color.a=r}}setPartMultiplyColorByTextureColor(t,e){this.setPartMultiplyColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartMultiplyColorByRGBA(t,e,i,s,r){this.setPartColor(t,e,i,s,r,this._userPartMultiplyColors,this._userMultiplyColors)}setPartScreenColorByTextureColor(t,e){this.setPartScreenColorByRGBA(t,e.r,e.g,e.b,e.a)}setPartScreenColorByRGBA(t,e,i,s,r){this.setPartColor(t,e,i,s,r,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 Me("getOverwriteFlagForModelMultiplyColors() is a deprecated function. Please use getOverrideFlagForModelMultiplyColors()."),this.getOverrideFlagForModelMultiplyColors()}getOverrideFlagForModelMultiplyColors(){return this._isOverriddenModelMultiplyColors}getOverwriteFlagForModelScreenColors(){return Me("getOverwriteFlagForModelScreenColors() is a deprecated function. Please use getOverrideFlagForModelScreenColors()."),this.getOverrideFlagForModelScreenColors()}getOverrideFlagForModelScreenColors(){return this._isOverriddenModelScreenColors}setOverwriteFlagForModelMultiplyColors(t){Me("setOverwriteFlagForModelMultiplyColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelMultiplyColors(value: boolean)."),this.setOverrideFlagForModelMultiplyColors(t)}setOverrideFlagForModelMultiplyColors(t){this._isOverriddenModelMultiplyColors=t}setOverwriteFlagForModelScreenColors(t){Me("setOverwriteFlagForModelScreenColors(value: boolean) is a deprecated function. Please use setOverrideFlagForModelScreenColors(value: boolean)."),this.setOverrideFlagForModelScreenColors(t)}setOverrideFlagForModelScreenColors(t){this._isOverriddenModelScreenColors=t}getOverwriteFlagForDrawableMultiplyColors(t){return Me("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 Me("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){Me("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){Me("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 Me("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 Me("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,s){Me("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,s)}setOverrideColorForPartColors(t,e,i,s){i.at(t).isOverridden=e;for(let r=0;r<this._partChildDrawables.at(t).getSize();++r){const a=this._partChildDrawables.at(t).at(r);s.at(a).isOverridden=e,e&&(s.at(a).color.r=i.at(t).color.r,s.at(a).color.g=i.at(t).color.g,s.at(a).color.b=i.at(t).color.b,s.at(a).color.a=i.at(t).color.a)}}setOverwriteColorForPartMultiplyColors(t,e){Me("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){Me("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 Me("getOverwriteFlagForModelCullings() is a deprecated function. Please use getOverrideFlagForModelCullings()."),this.getOverrideFlagForModelCullings()}getOverrideFlagForModelCullings(){return this._isOverriddenCullings}setOverwriteFlagForModelCullings(t){Me("setOverwriteFlagForModelCullings(isOverriddenCullings: boolean) is a deprecated function. Please use setOverrideFlagForModelCullings(isOverriddenCullings: boolean)."),this.setOverrideFlagForModelCullings(t)}setOverrideFlagForModelCullings(t){this._isOverriddenCullings=t}getOverwriteFlagForDrawableCullings(t){return Me("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){Me("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 We.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):(fe(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):(fe(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 We.getIdManager().getId(this._model.parameters.ids[t])}getParameterValueByIndex(t){return this._notExistParameterValues.isExist(t)?this._notExistParameterValues.getValue(t):(fe(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):(fe(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 s=this.getParameterIndex(t);this.setParameterValueByIndex(s,e,i)}addParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)+e*i)}addParameterValueById(t,e,i=1){const s=this.getParameterIndex(t);this.addParameterValueByIndex(s,e,i)}isRepeat(t){if(this._notExistParameterValues.isExist(t))return!1;let e;return fe(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;fe(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],s=this._model.parameters.minimumValues[t],r=i-s;if(i<e){const t=ti.mod(e-i,r);e=Number.isNaN(t)?i:s+t}if(e<s){const t=ti.mod(s-e,r);e=Number.isNaN(t)?s:i-t}return e}getParameterClampValue(t,e){if(this._notExistParameterValues.isExist(t))return e;fe(0<=t&&t<this.getParameterCount());const i=this._model.parameters.maximumValues[t],s=this._model.parameters.minimumValues[t];return ti.clamp(e,s,i)}getParameterRepeats(t){return 0!=this._model.parameters.repeats[t]}multiplyParameterValueById(t,e,i=1){const s=this.getParameterIndex(t);this.multiplyParameterValueByIndex(s,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 We.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,s=new me;return s.r=e[i],s.g=e[i+1],s.b=e[i+2],s.a=e[i+3],s}getDrawableScreenColor(t){const e=this._model.drawables.screenColors,i=4*t,s=new me;return s.r=e[i],s.g=e[i+1],s.b=e[i+2],s.a=e[i+3],s}getDrawableParentPartIndex(t){return this._model.drawables.parentPartIndices[t]}getDrawableBlendMode(t){const e=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(e[t])?ce.CubismBlendMode_Additive:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(e[t])?ce.CubismBlendMode_Multiplicative:ce.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(){fe(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(We.getIdManager().getId(t[i])),this._userParameterRepeatDataList.pushBack(new rr(!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(We.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 s=new or(!1,!1);for(let r=0;r<t;++r){const t=new me(1,1,1,1),e=new me(0,0,0,1),s=new nr(!1,t),a=new nr(!1,e);this._userPartMultiplyColors.pushBack(s),this._userPartScreenColors.pushBack(a),this._partChildDrawables.pushBack(new Zt),this._partChildDrawables.at(r).prepareCapacity(i)}for(let t=0;t<i;++t){const i=new me(1,1,1,1),r=new me(0,0,0,1),a=new ar(!1,i),n=new ar(!1,r);this._drawableIds.pushBack(We.getIdManager().getId(e[t])),this._userMultiplyColors.pushBack(a),this._userScreenColors.pushBack(n),this._userCullings.pushBack(s);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 Zt,this._parameterIds=new Zt,this._drawableIds=new Zt,this._partIds=new Zt,this._isOverriddenParameterRepeat=!0,this._isOverriddenModelMultiplyColors=!1,this._isOverriddenModelScreenColors=!1,this._isOverriddenCullings=!1,this._modelOpacity=1,this._userParameterRepeatDataList=new Zt,this._userMultiplyColors=new Zt,this._userScreenColors=new Zt,this._userCullings=new Zt,this._userPartMultiplyColors=new Zt,this._userPartScreenColors=new Zt,this._partChildDrawables=new Zt,this._notExistPartId=new Be,this._notExistParameterId=new Be,this._notExistParameterValues=new Be,this._notExistPartOpacities=new Be}release(){this._model.release(),this._model=null}}(t=>{t.CubismModel=lr})(ir||(ir={}));class ur{static create(t,e){let i=null;if(e){if(!this.hasMocConsistency(t))return Ce("Inconsistent MOC3."),i}const s=Live2DCubismCore.Moc.fromArrayBuffer(t);return s&&(i=new ur(s),i._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(s,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 lr(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(){fe(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=ur})(sr||(sr={}));var hr,dr=(t=>(t[t.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",t))(dr||{}),gr=(t=>(t[t.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",t[t.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",t[t.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",t))(gr||{});class cr{constructor(){this.gravity=new Ke(0,0),this.wind=new Ke(0,0)}}class mr{}class pr{}class _r{constructor(){this.initialPosition=new Ke(0,0),this.position=new Ke(0,0),this.lastPosition=new Ke(0,0),this.lastGravity=new Ke(0,0),this.force=new Ke(0,0),this.velocity=new Ke(0,0)}}class fr{constructor(){this.normalizationPosition=new pr,this.normalizationAngle=new pr}}class yr{constructor(){this.source=new mr}}class xr{constructor(){this.destination=new mr,this.translationScale=new Ke(0,0)}}class Mr{constructor(){this.settings=new Zt,this.inputs=new Zt,this.outputs=new Zt,this.particles=new Zt,this.gravity=new Ke(0,0),this.wind=new Ke(0,0),this.fps=0}}(t=>{t.CubismPhysicsInput=yr,t.CubismPhysicsNormalization=pr,t.CubismPhysicsOutput=xr,t.CubismPhysicsParameter=mr,t.CubismPhysicsParticle=_r,t.CubismPhysicsRig=Mr,t.CubismPhysicsSource=gr,t.CubismPhysicsSubRig=fr,t.CubismPhysicsTargetType=dr,t.PhysicsJsonEffectiveForces=cr})(hr||(hr={}));const Cr="Position",Sr="Angle",vr="Type",br="Meta",Pr="EffectiveForces",Br="Gravity",wr="Wind",Ir="PhysicsSettings",Fr="Normalization",Er="Minimum",Lr="Maximum",Vr="Default",Tr="Reflect",Rr="Weight",Dr="Input",Ar="Output",Or="Vertices";class kr{constructor(t,e){this._json=Ve.create(t,e)}release(){Ve.delete(this._json)}getGravity(){const t=new Ke(0,0);return t.x=this._json.getRoot().getValueByString(br).getValueByString(Pr).getValueByString(Br).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString(br).getValueByString(Pr).getValueByString(Br).getValueByString("Y").toFloat(),t}getWind(){const t=new Ke(0,0);return t.x=this._json.getRoot().getValueByString(br).getValueByString(Pr).getValueByString(wr).getValueByString("X").toFloat(),t.y=this._json.getRoot().getValueByString(br).getValueByString(Pr).getValueByString(wr).getValueByString("Y").toFloat(),t}getFps(){return this._json.getRoot().getValueByString(br).getValueByString("Fps").toFloat(0)}getSubRigCount(){return this._json.getRoot().getValueByString(br).getValueByString("PhysicsSettingCount").toInt()}getTotalInputCount(){return this._json.getRoot().getValueByString(br).getValueByString("TotalInputCount").toInt()}getTotalOutputCount(){return this._json.getRoot().getValueByString(br).getValueByString("TotalOutputCount").toInt()}getVertexCount(){return this._json.getRoot().getValueByString(br).getValueByString("VertexCount").toInt()}getNormalizationPositionMinimumValue(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Fr).getValueByString(Cr).getValueByString(Er).toFloat()}getNormalizationPositionMaximumValue(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Fr).getValueByString(Cr).getValueByString(Lr).toFloat()}getNormalizationPositionDefaultValue(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Fr).getValueByString(Cr).getValueByString(Vr).toFloat()}getNormalizationAngleMinimumValue(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Fr).getValueByString(Sr).getValueByString(Er).toFloat()}getNormalizationAngleMaximumValue(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Fr).getValueByString(Sr).getValueByString(Lr).toFloat()}getNormalizationAngleDefaultValue(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Fr).getValueByString(Sr).getValueByString(Vr).toFloat()}getInputCount(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Dr).getVector().getSize()}getInputWeight(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Dr).getValueByIndex(e).getValueByString(Rr).toFloat()}getInputReflect(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Dr).getValueByIndex(e).getValueByString(Tr).toBoolean()}getInputType(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Dr).getValueByIndex(e).getValueByString(vr).getRawString()}getInputSourceId(t,e){return We.getIdManager().getId(this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Dr).getValueByIndex(e).getValueByString("Source").getValueByString("Id").getRawString())}getOutputCount(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Ar).getVector().getSize()}getOutputVertexIndex(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Ar).getValueByIndex(e).getValueByString("VertexIndex").toInt()}getOutputAngleScale(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Ar).getValueByIndex(e).getValueByString("Scale").toFloat()}getOutputWeight(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Ar).getValueByIndex(e).getValueByString(Rr).toFloat()}getOutputDestinationId(t,e){return We.getIdManager().getId(this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Ar).getValueByIndex(e).getValueByString("Destination").getValueByString("Id").getRawString())}getOutputType(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Ar).getValueByIndex(e).getValueByString(vr).getRawString()}getOutputReflect(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Ar).getValueByIndex(e).getValueByString(Tr).toBoolean()}getParticleCount(t){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Or).getVector().getSize()}getParticleMobility(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Or).getValueByIndex(e).getValueByString("Mobility").toFloat()}getParticleDelay(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Or).getValueByIndex(e).getValueByString("Delay").toFloat()}getParticleAcceleration(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Or).getValueByIndex(e).getValueByString("Acceleration").toFloat()}getParticleRadius(t,e){return this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Or).getValueByIndex(e).getValueByString("Radius").toFloat()}getParticlePosition(t,e){const i=new Ke(0,0);return i.x=this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Or).getValueByIndex(e).getValueByString(Cr).getValueByString("X").toFloat(),i.y=this._json.getRoot().getValueByString(Ir).getValueByIndex(t).getValueByString(Or).getValueByIndex(e).getValueByString(Cr).getValueByString("Y").toFloat(),i}}var Nr;(t=>{t.CubismPhysicsJson=kr})(Nr||(Nr={}));const Ur="Angle";class zr{static create(t,e){const i=new zr;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 Mr;let i=new kr(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,fr,!0),this._physicsRig.inputs.updateSize(i.getTotalInputCount(),yr,!0),this._physicsRig.outputs.updateSize(i.getTotalOutputCount(),xr,!0),this._physicsRig.particles.updateSize(i.getVertexCount(),_r,!0),this._currentRigOutputs.clear(),this._previousRigOutputs.clear();let s=0,r=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=s;for(let r=0;r<this._physicsRig.settings.at(n).inputCount;++r)this._physicsRig.inputs.at(s+r).sourceParameterIndex=-1,this._physicsRig.inputs.at(s+r).weight=i.getInputWeight(n,r),this._physicsRig.inputs.at(s+r).reflect=i.getInputReflect(n,r),"X"==i.getInputType(n,r)?(this._physicsRig.inputs.at(s+r).type=gr.CubismPhysicsSource_X,this._physicsRig.inputs.at(s+r).getNormalizedParameterValue=Xr):"Y"==i.getInputType(n,r)?(this._physicsRig.inputs.at(s+r).type=gr.CubismPhysicsSource_Y,this._physicsRig.inputs.at(s+r).getNormalizedParameterValue=Hr):i.getInputType(n,r)==Ur&&(this._physicsRig.inputs.at(s+r).type=gr.CubismPhysicsSource_Angle,this._physicsRig.inputs.at(s+r).getNormalizedParameterValue=Yr),this._physicsRig.inputs.at(s+r).source.targetType=dr.CubismPhysicsTargetType_Parameter,this._physicsRig.inputs.at(s+r).source.id=i.getInputSourceId(n,r);s+=this._physicsRig.settings.at(n).inputCount,this._physicsRig.settings.at(n).outputCount=i.getOutputCount(n),this._physicsRig.settings.at(n).baseOutputIndex=r;const t=new Gr;t.outputs.resize(this._physicsRig.settings.at(n).outputCount);const e=new Gr;e.outputs.resize(this._physicsRig.settings.at(n).outputCount);for(let s=0;s<this._physicsRig.settings.at(n).outputCount;++s)t.outputs.set(s,0),e.outputs.set(s,0),this._physicsRig.outputs.at(r+s).destinationParameterIndex=-1,this._physicsRig.outputs.at(r+s).vertexIndex=i.getOutputVertexIndex(n,s),this._physicsRig.outputs.at(r+s).angleScale=i.getOutputAngleScale(n,s),this._physicsRig.outputs.at(r+s).weight=i.getOutputWeight(n,s),this._physicsRig.outputs.at(r+s).destination.targetType=dr.CubismPhysicsTargetType_Parameter,this._physicsRig.outputs.at(r+s).destination.id=i.getOutputDestinationId(n,s),"X"==i.getOutputType(n,s)?(this._physicsRig.outputs.at(r+s).type=gr.CubismPhysicsSource_X,this._physicsRig.outputs.at(r+s).getValue=qr,this._physicsRig.outputs.at(r+s).getScale=Zr):"Y"==i.getOutputType(n,s)?(this._physicsRig.outputs.at(r+s).type=gr.CubismPhysicsSource_Y,this._physicsRig.outputs.at(r+s).getValue=Wr,this._physicsRig.outputs.at(r+s).getScale=Kr):i.getOutputType(n,s)==Ur&&(this._physicsRig.outputs.at(r+s).type=gr.CubismPhysicsSource_Angle,this._physicsRig.outputs.at(r+s).getValue=Jr,this._physicsRig.outputs.at(r+s).getScale=Qr),this._physicsRig.outputs.at(r+s).reflect=i.getOutputReflect(n,s);this._currentRigOutputs.pushBack(t),this._previousRigOutputs.pushBack(e),r+=this._physicsRig.settings.at(n).outputCount,this._physicsRig.settings.at(n).particleCount=i.getParticleCount(n),this._physicsRig.settings.at(n).baseParticleIndex=a;for(let s=0;s<this._physicsRig.settings.at(n).particleCount;++s)this._physicsRig.particles.at(a+s).mobility=i.getParticleMobility(n,s),this._physicsRig.particles.at(a+s).delay=i.getParticleDelay(n,s),this._physicsRig.particles.at(a+s).acceleration=i.getParticleAcceleration(n,s),this._physicsRig.particles.at(a+s).radius=i.getParticleRadius(n,s),this._physicsRig.particles.at(a+s).position=i.getParticlePosition(n,s);a+=this._physicsRig.settings.at(n).particleCount}this.initialize(),i.release(),i=void 0,i=null}stabilization(t){var e,i,s,r;let a,n,o,l;const u=new Ke;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!=(r=null==(s=this._parameterInputCaches)?void 0:s.length)?r: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=ti.degreesToRadian(-a.angle),u.x=u.x*ti.cos(o)-u.y*ti.sin(o),u.y=u.x*ti.sin(o)+u.y*ti.cos(o),ea(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 s=new Ke;s=c[i].position.substract(c[i-1].position),l=g[e].getValue(s,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 r=g[e].destinationParameterIndex,a=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(m.subarray(r))):m.slice(r);ia(a,_[r],p[r],l,g[e]);for(let t=r,e=0;t<this._parameterCaches.length;t++,e++)m[t]=this._parameterCaches[t]=a[e]}}}evaluate(t,e){var i,s,r,a;let n,o,l,u;const h=new Ke;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!=(s=null==(i=this._parameterCaches)?void 0:i.length)?s:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(null!=(a=null==(r=this._parameterInputCaches)?void 0:r.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=ti.degreesToRadian(-n.angle),h.x=h.x*ti.cos(l)-h.y*ti.sin(l),h.y=h.x*ti.sin(l)+h.y*ti.cos(l),ta(m,d.particleCount,h,n.angle,this._options.wind,.001*d.normalizationPosition.maximum,x,5);for(let e=0;e<d.outputCount;++e){const s=c[e].vertexIndex;if(-1==c[e].destinationParameterIndex&&(c[e].destinationParameterIndex=t.getParameterIndex(c[e].destination.id)),s<1||s>=d.particleCount)continue;const r=new Ke;r.x=m[s].position.x-m[s-1].position.x,r.y=m[s].position.y-m[s-1].position.y,u=c[e].getValue(r,m,s,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);ia(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 M=this._currentRemainTime/x;this.interpolate(t,M)}interpolate(t,e){let i,s;const r=t.getModel().parameters.values,a=t.getModel().parameters.maximumValues,n=t.getModel().parameters.minimumValues;for(let o=0;o<this._physicsRig.subRigCount;++o){s=this._physicsRig.settings.at(o),i=this._physicsRig.outputs.get(s.baseOutputIndex);for(let t=0;t<s.outputCount;++t){if(-1==i[t].destinationParameterIndex)continue;const s=i[t].destinationParameterIndex,l=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(r.subarray(s))):r.slice(s);ia(l,n[s],a[s],this._previousRigOutputs.at(o).outputs.at(t)*(1-e)+this._currentRigOutputs.at(o).outputs.at(t)*e,i[t]);for(let t=s,e=0;t<r.length;t++,e++)r[t]=l[e]}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._physicsRig=null,this._options=new jr,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=new Zt,this._previousRigOutputs=new Zt,this._currentRemainTime=0,this._parameterCaches=null,this._parameterInputCaches=null}release(){this._physicsRig=void 0,this._physicsRig=null}initialize(){let t,e,i;for(let s=0;s<this._physicsRig.subRigCount;++s){e=this._physicsRig.settings.at(s),t=this._physicsRig.particles.get(e.baseParticleIndex),t[0].initialPosition=new Ke(0,0),t[0].lastPosition=new Ke(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new Ke(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new Ke(0,0),t[0].force=new Ke(0,0);for(let s=1;s<e.particleCount;++s)i=new Ke(0,0),i.y=t[s].radius,t[s].initialPosition=new Ke(t[s-1].initialPosition.x+i.x,t[s-1].initialPosition.y+i.y),t[s].position=new Ke(t[s].initialPosition.x,t[s].initialPosition.y),t[s].lastPosition=new Ke(t[s].initialPosition.x,t[s].initialPosition.y),t[s].lastGravity=new Ke(0,-1),t[s].lastGravity.y*=-1,t[s].velocity=new Ke(0,0),t[s].force=new Ke(0,0)}}}class jr{constructor(){this.gravity=new Ke(0,0),this.wind=new Ke(0,0)}}class Gr{constructor(){this.outputs=new Zt(0)}}function Xr(t,e,i,s,r,a,n,o,l,u){t.x+=sa(i,s,r,a,n.minimum,n.maximum,n.defalut,l)*u}function Hr(t,e,i,s,r,a,n,o,l,u){t.y+=sa(i,s,r,a,n.minimum,n.maximum,n.defalut,l)*u}function Yr(t,e,i,s,r,a,n,o,l,u){e.angle+=sa(i,s,r,a,o.minimum,o.maximum,o.defalut,l)*u}function qr(t,e,i,s,r){let a=t.x;return s&&(a*=-1),a}function Wr(t,e,i,s,r){let a=t.y;return s&&(a*=-1),a}function Jr(t,e,i,s,r){let a;return r=i>=2?e[i-1].position.substract(e[i-2].position):r.multiplyByScaler(-1),a=ti.directionToRadian(r,t),s&&(a*=-1),a}function $r(t,e){return ti.min(t,e)+function(t,e){const i=ti.max(t,e),s=ti.min(t,e);return ti.abs(i-s)}(t,e)/2}function Zr(t,e){return JSON.parse(JSON.stringify(t.x))}function Kr(t,e){return JSON.parse(JSON.stringify(t.y))}function Qr(t,e){return JSON.parse(JSON.stringify(e))}function ta(t,e,i,s,r,a,n,o){let l,u,h=new Ke(0,0),d=new Ke(0,0),g=new Ke(0,0),c=new Ke(0,0);t[0].position=new Ke(i.x,i.y);const m=ti.degreesToRadian(s),p=ti.radianToDirection(m);p.normalize();for(let _=1;_<e;++_)t[_].force=p.multiplyByScaler(t[_].acceleration).add(r),t[_].lastPosition=new Ke(t[_].position.x,t[_].position.y),l=t[_].delay*n*30,h=t[_].position.substract(t[_-1].position),u=ti.directionToRadian(t[_].lastGravity,p)/o,h.x=ti.cos(u)*h.x-h.y*ti.sin(u),h.y=ti.sin(u)*h.x+h.y*ti.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)),ti.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 Ke(0,0),t[_].lastGravity=new Ke(p.x,p.y)}function ea(t,e,i,s,r,a){let n=new Ke(0,0);t[0].position=new Ke(i.x,i.y);const o=ti.degreesToRadian(s),l=ti.radianToDirection(o);l.normalize();for(let u=1;u<e;++u)t[u].force=l.multiplyByScaler(t[u].acceleration).add(r),t[u].lastPosition=new Ke(t[u].position.x,t[u].position.y),t[u].velocity=new Ke(0,0),n=t[u].force,n.normalize(),n=n.multiplyByScaler(t[u].radius),t[u].position=t[u-1].position.add(n),ti.abs(t[u].position.x)<a&&(t[u].position.x=0),t[u].force=new Ke(0,0),t[u].lastGravity=new Ke(l.x,l.y)}function ia(t,e,i,s,r){let a;a=s*r.getScale(r.translationScale,r.angleScale),a<e?(a<r.valueBelowMinimum&&(r.valueBelowMinimum=a),a=e):a>i&&(a>r.valueExceededMaximum&&(r.valueExceededMaximum=a),a=i);const n=r.weight/100;n>=1||(a=t[0]*(1-n)+a*n),t[0]=a}function sa(t,e,i,s,r,a,n,o){let l=0;const u=ti.max(i,e);u<t&&(t=u);const h=ti.min(i,e);h>t&&(t=h);const d=ti.min(r,a),g=ti.max(r,a),c=n,m=$r(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 ra;function aa(){var t;null==(t=this.__moc)||t.release()}(t=>{t.CubismPhysics=zr,t.Options=jr})(ra||(ra={})),xt.registerRuntime({version:4,ready:Js,test:t=>t instanceof Xs||Xs.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 Xs(t),createCoreModel(t,e){const i=ur.create(t,!!(null==e?void 0:e.checkMocConsistency));try{const t=i.createModel();return t.__moc=i,t}catch(s){try{i.release()}catch(r){p.warn("CubismFactory","Failed to release moc after core model creation failed.",r)}throw s}},createInternalModel(t,e,i){const s=new Os(t,e,i),r=t;return r.__moc&&(s.__moc=r.__moc,delete r.__moc,s.once("destroy",aa)),s},createPhysics(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism physics data must be an ArrayBuffer.");return zr.create(e,e.byteLength)},createPose(t,e){if(!(e instanceof ArrayBuffer))throw new TypeError("Cubism pose data must be an ArrayBuffer.");return Qs.create(e,e.byteLength)}}),t.CubismExpressionManager=_i,t.CubismInternalModel=Os,t.CubismLegacyExpressionManager=Ot,t.CubismLegacyInternalModel=Xt,t.CubismLegacyModelSettings=st,t.CubismLegacyMotionManager=Nt,t.CubismLegacyParallelMotionManager=zt,t.CubismModelSettings=Xs,t.CubismMotionManager=Hi,t.CubismParallelMotionManager=Zi,t.ExpressionManager=B,t.FileLoader=ft,t.FocusController=F,t.InternalModel=Z,t.LOGICAL_HEIGHT=2,t.LOGICAL_WIDTH=2,t.Live2DExpression=At,t.Live2DEyeBlink=jt,t.Live2DFactory=xt,t.Live2DLoader=it,t.Live2DModel=Rt,t.Live2DPhysics=qt,t.Live2DPlugin=Tt,t.Live2DPose=Jt,t.Live2DTransform=Pt,t.MBToByte=y,t.ModelSettings=E,t.MotionManager=O,t.MotionPreloadStrategy=A,t.MotionPriority=L,t.MotionState=V,t.SoundManager=D,t.VERSION="1.2.2",t.VOLUME=R,t.XHRLoader=tt,t.applyMixins=C,t.clamp=_,t.config=m,t.configureCubismSDK=Ws,t.copyArray=M,t.copyProperty=x,t.cubismReady=Js,t.folderName=S,t.logger=p,t.normalizeHitAreaDefs=J,t.rand=f,t.reconfigureCubismSDK=function(t={}){Ws(t),We.isInitialized()&&We.dispose(),We.isStarted()&&We.cleanUp(),$s(void 0,t.memorySizeMB)},t.remove=v,t.resolveURL=P,t.startUpCubism=$s,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|