webgal-engine 4.6.4 → 4.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -1,14 +0,0 @@
1
- import{C as De,O as Ae,A as Be,P as ke,M as ft,T as Re,E as kt,u as Rt,a as bt}from"./index-R1tKotR6.js";var W=Math.pow,I=(s,t,e)=>new Promise((i,r)=>{var a=l=>{try{o(e.next(l))}catch(h){r(h)}},n=l=>{try{o(e.throw(l))}catch(h){r(h)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,n);o((e=e.apply(s,t)).next())});const Zt=2,Kt=2;var ct;(s=>{s.supportMoreMaskDivisions=!0,s.setOpacityFromMotion=!1})(ct||(ct={}));var w;(s=>{s.LOG_LEVEL_VERBOSE=0,s.LOG_LEVEL_WARNING=1,s.LOG_LEVEL_ERROR=2,s.LOG_LEVEL_NONE=999,s.logLevel=s.LOG_LEVEL_WARNING,s.sound=!0,s.motionSync=!0,s.motionFadingDuration=500,s.idleMotionFadingDuration=2e3,s.expressionFadingDuration=500,s.preserveExpressionOnMotion=!0,s.cubism4=ct,s.legacyExpressionBlendMode=!1})(w||(w={}));const C={log(s,...t){w.logLevel<=w.LOG_LEVEL_VERBOSE&&console.log(`[${s}]`,...t)},warn(s,...t){w.logLevel<=w.LOG_LEVEL_WARNING&&console.warn(`[${s}]`,...t)},error(s,...t){w.logLevel<=w.LOG_LEVEL_ERROR&&console.error(`[${s}]`,...t)}};function yt(s,t,e){return s<t?t:s>e?e:s}function Oe(s,t){return Math.random()*(t-s)+s}function rt(s,t,e,i,r){const a=t[i];a!==null&&typeof a===s&&(e[r]=a)}function at(s,t,e,i,r){const a=t[i];Array.isArray(a)&&(e[r]=a.filter(n=>n!==null&&typeof n===s))}function me(s,t){t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(i=>{i!=="constructor"&&Object.defineProperty(s.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i))})})}function Ue(s){let t=s.lastIndexOf("/");return t!=-1&&(s=s.slice(0,t)),t=s.lastIndexOf("/"),t!==-1&&(s=s.slice(t+1)),s}function Ve(s,t){const e=s.indexOf(t);e!==-1&&s.splice(e,1)}class Ot extends kt{constructor(t,e){super(),this.expressions=[],this.reserveExpressionIndex=-1,this.destroyed=!1,this.settings=t,this.tag=`ExpressionManager(${t.name})`}init(){this.defaultExpression=this.createExpression({},void 0),this.currentExpression=this.defaultExpression,this.stopAllExpressions()}loadExpression(t){return I(this,null,function*(){if(!this.definitions[t]){C.warn(this.tag,`Undefined expression at [${t}]`);return}if(this.expressions[t]===null){C.warn(this.tag,`Cannot set expression at [${t}] because it's already failed in loading.`);return}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 I(this,null,function*(){if(this.definitions.length){const t=[];for(let e=0;e<this.definitions.length;e++)this.expressions[e]!==null&&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 I(this,null,function*(){if(typeof t!="number"&&(t=this.getExpressionIndex(t)),!(t>-1&&t<this.definitions.length)||t===this.expressions.indexOf(this.currentExpression))return!1;this.reserveExpressionIndex=t;const e=yield this.loadExpression(t);return!e||this.reserveExpressionIndex!==t?!1:(this.reserveExpressionIndex=-1,this.currentExpression=e,this._setExpression(e),!0)})}update(t,e){return this.isFinished()?!1:this.updateParameters(t,e)}destroy(){this.destroyed=!0,this.emit("destroy");const t=this;t.definitions=void 0,t.expressions=void 0}}const Qt=.01,Ne=40/7.5,Ge=1/(.15*1e3);class ze{constructor(){this.targetX=0,this.targetY=0,this.x=0,this.y=0,this.vx=0,this.vy=0}focus(t,e,i=!1){this.targetX=yt(t,-1,1),this.targetY=yt(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)<Qt&&Math.abs(i)<Qt)return;const r=Math.sqrt(W(e,2)+W(i,2)),a=Ne/(1e3/t);let n=a*(e/r)-this.vx,o=a*(i/r)-this.vy;const l=Math.sqrt(W(n,2)+W(o,2)),h=a*Ge*t;l>h&&(n*=h/l,o*=h/l),this.vx+=n,this.vy+=o;const u=Math.sqrt(W(this.vx,2)+W(this.vy,2)),c=.5*(Math.sqrt(W(h,2)+8*h*r)-h);u>c&&(this.vx*=c/u,this.vy*=c/u),this.x+=this.vx,this.y+=this.vy}}class vt{constructor(t){this.json=t;let e=t.url;if(typeof e!="string")throw new TypeError("The `url` field in settings JSON must be defined as a string.");this.url=e,this.name=Ue(this.url)}resolveURL(t){return Rt.resolve(this.url,t)}replaceFiles(t){this.moc=t(this.moc,"moc"),this.pose!==void 0&&(this.pose=t(this.pose,"pose")),this.physics!==void 0&&(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=(a,n)=>{const o=this.resolveURL(a);if(!t.includes(o)){if(n)throw new Error(`File "${a}" is defined in settings, but doesn't exist in given files`);return!1}return!0};return[this.moc,...this.textures].forEach(a=>e(a,!0)),this.getDefinedFiles().filter(a=>e(a,!1))}}var Et=(s=>(s[s.NONE=0]="NONE",s[s.IDLE=1]="IDLE",s[s.NORMAL=2]="NORMAL",s[s.FORCE=3]="FORCE",s))(Et||{});class Xe{constructor(){this.debug=!1,this.currentPriority=0,this.reservePriority=0}reserve(t,e,i){if(i<=0)return C.log(this.tag,"Cannot start a motion with MotionPriority.NONE."),!1;if(t===this.currentGroup&&e===this.currentIndex)return C.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 C.log(this.tag,"Motion is already reserved.",this.dump(t,e)),!1;if(i===1){if(this.currentPriority!==0)return C.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(t,e)),!1;if(this.reservedIdleGroup!==void 0)return C.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 C.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 C.log(this.tag,"Cannot start motion because another motion has reserved as an equivalent or higher priority.",this.dump(t,e)),!1}this.setReserved(t,e,i)}return!0}start(t,e,i,r){if(r===1){if(this.setReservedIdle(void 0,void 0),this.currentPriority!==0)return C.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 C.log(this.tag,"Cannot start motion because another motion has taken the place.",this.dump(e,i)),!1;this.setReserved(void 0,void 0,0)}return t?(this.setCurrent(e,i,r),!0):!1}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 this.currentGroup===void 0&&this.reservedIdleGroup===void 0}shouldOverrideExpression(){return!w.preserveExpressionOnMotion&&this.currentPriority>1}dump(t,e){if(this.debug){const i=["currentPriority","reservePriority","currentGroup","currentIndex","reservedGroup","reservedIndex","reservedIdleGroup","reservedIdleIndex"];return`
2
- <Requested> group = "${t}", index = ${e}
3
- `+i.map(r=>"["+r+"] "+this[r]).join(`
4
- `)}return""}}const je="SoundManager",We=.5;class Z{static get volume(){return this._volume}static set volume(t){this._volume=(t>1?1:t<0?0:t)||0,this.audios.forEach(e=>e.volume=this._volume)}static add(t,e,i){const r=new Audio(t);return r.volume=this._volume,r.preload="auto",r.addEventListener("ended",()=>{this.dispose(r),e==null||e()}),r.addEventListener("error",a=>{this.dispose(r),C.warn(je,`Error occurred on "${t}"`,a.error),i==null||i(a.error)}),this.audios.push(r),r}static play(t){return new Promise((e,i)=>{var r;(r=t.play())==null||r.catch(a=>{t.dispatchEvent(new ErrorEvent("error",{error:a})),i(a)}),t.readyState===t.HAVE_ENOUGH_DATA?e():t.addEventListener("canplaythrough",e)})}static dispose(t){t.pause(),t.removeAttribute("src"),Ve(this.audios,t)}static destroy(){for(let t=this.audios.length-1;t>=0;t--)this.dispose(this.audios[t])}}Z.audios=[];Z._volume=We;class Mt extends kt{constructor(t,e){super(),this.motionGroups={},this.state=new Xe,this.playing=!1,this.destroyed=!1,this.settings=t,this.tag=`MotionManager(${t.name})`,this.state.tag=this.tag}init(t){t!=null&&t.idleMotionGroup&&(this.groups.idle=t.idleMotionGroup),this.setupMotions(t),this.stopAllMotions()}setupMotions(t){for(const i of Object.keys(this.definitions))this.motionGroups[i]=[];let e;switch(t==null?void 0:t.motionPreload){case"NONE":return;case"ALL":e=Object.keys(this.definitions);break;case"IDLE":default:e=[this.groups.idle];break}for(const i of e)if(this.definitions[i])for(let r=0;r<this.definitions[i].length;r++)this.loadMotion(i,r).then()}loadMotion(t,e){return I(this,null,function*(){var i;if(!((i=this.definitions[t])!=null&&i[e])){C.warn(this.tag,`Undefined motion at "${t}"[${e}]`);return}if(this.motionGroups[t][e]===null){C.warn(this.tag,`Cannot start motion at "${t}"[${e}] because it's already failed in loading.`);return}if(this.motionGroups[t][e])return this.motionGroups[t][e];const r=yield this._loadMotion(t,e);if(!this.destroyed)return this.motionGroups[t][e]=r??null,r})}_loadMotion(t,e){throw new Error("Not implemented.")}startMotion(t,e){return I(this,arguments,function*(i,r,a=Et.NORMAL){var n;if(!this.state.reserve(i,r,a))return!1;const o=(n=this.definitions[i])==null?void 0:n[r];if(!o)return!1;this.currentAudio&&Z.dispose(this.currentAudio);let l;if(w.sound){const u=this.getSoundFile(o);if(u)try{l=Z.add(this.settings.resolveURL(u),()=>this.currentAudio=void 0,()=>this.currentAudio=void 0),this.currentAudio=l}catch(c){C.warn(this.tag,"Failed to create audio",u,c)}}const h=yield this.loadMotion(i,r);if(l){const u=Z.play(l).catch(c=>C.warn(this.tag,"Failed to play audio",l.src,c));w.motionSync&&(yield u)}return this.state.start(h,i,r,a)?(C.log(this.tag,"Start motion:",this.getMotionName(o)),this.emit("motionStart",i,r,l),this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),this.playing=!0,this._startMotion(h),!0):(l&&(Z.dispose(l),this.currentAudio=void 0),!1)})}startRandomMotion(t,e){return I(this,null,function*(){const i=this.definitions[t];if(i!=null&&i.length){const r=[];for(let a=0;a<i.length;a++)this.motionGroups[t][a]!==null&&!this.state.isActive(t,a)&&r.push(a);if(r.length){const a=Math.floor(Math.random()*r.length);return this.startMotion(t,r[a],e)}}return!1})}stopAllMotions(){this._stopAllMotions(),this.state.reset(),this.currentAudio&&(Z.dispose(this.currentAudio),this.currentAudio=void 0)}update(t,e){var i;return this.isFinished()&&(this.playing&&(this.playing=!1,this.emit("motionFinish")),this.state.shouldOverrideExpression()&&((i=this.expressionManager)==null||i.restoreExpression()),this.state.complete(),this.state.shouldRequestIdleMotion()&&this.startRandomMotion(this.groups.idle,Et.IDLE)),this.updateParameters(t,e)}destroy(){var t;this.destroyed=!0,this.emit("destroy"),this.stopAllMotions(),(t=this.expressionManager)==null||t.destroy();const e=this;e.definitions=void 0,e.motionGroups=void 0}}const pe={blinkInterval:24*60*60*1e3,blinkIntervalRandom:1e3,closingDuration:100,closedDuration:50,openingDuration:150},Ye={x:0,y:0,width:0,height:0};class _e extends kt{constructor(){super(...arguments),this.focusController=new ze,this.originalWidth=0,this.originalHeight=0,this.width=0,this.height=0,this.localTransform=new ft,this.drawingMatrix=new ft,this.hitAreas={},this.textureFlipY=!1,this.viewport=[0,0,0,0],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:Zt,height:Kt},this.getLayout());this.localTransform.scale(i.width/Zt,i.height/Kt),t.width=this.originalWidth*this.localTransform.a,t.height=this.originalHeight*this.localTransform.d;const r=i.x!==void 0&&i.x-i.width/2||i.centerX!==void 0&&i.centerX||i.left!==void 0&&i.left-i.width/2||i.right!==void 0&&i.right+i.width/2||0,a=i.y!==void 0&&i.y-i.height/2||i.centerY!==void 0&&i.centerY||i.top!==void 0&&i.top-i.height/2||i.bottom!==void 0&&i.bottom+i.height/2||0;this.localTransform.translate(this.width*r,-this.height*a)}setupHitAreas(){const t=this.getHitAreaDefs().filter(e=>e.index>=0);for(const e of t)this.hitAreas[e.name]=e}hitTest(t,e){return Object.keys(this.hitAreas).filter(i=>this.isHit(i,t,e))}isHit(t,e,i){if(!this.hitAreas[t])return!1;const r=this.hitAreas[t].index,a=this.getDrawableBounds(r,Ye);return a.x<=e&&e<=a.x+a.width&&a.y<=i&&i<=a.y+a.height}getDrawableBounds(t,e){const i=this.getDrawableVertices(t);let r=i[0],a=i[0],n=i[1],o=i[1];for(let l=0;l<i.length;l+=2){const h=i[l],u=i[l+1];r=Math.min(h,r),a=Math.max(h,a),n=Math.min(u,n),o=Math.max(u,o)}return e??(e={}),e.x=r,e.y=n,e.width=a-r,e.height=o-n,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}}const He="XHRLoader";class te extends Error{constructor(t,e,i,r=!1){super(t),this.url=e,this.status=i,this.aborted=r}}const E=class{static createXHR(s,t,e,i,r){const a=new XMLHttpRequest;if(E.allXhrSet.add(a),s){let n=E.xhrMap.get(s);n?n.add(a):(n=new Set([a]),E.xhrMap.set(s,n)),s.listeners("destroy").includes(E.cancelXHRs)||s.once("destroy",E.cancelXHRs)}return a.open("GET",t),a.responseType=e,a.onload=()=>{(a.status===200||a.status===0)&&a.response?i(a.response):a.onerror()},a.onerror=()=>{C.warn(He,`Failed to load resource as ${a.responseType} (Status ${a.status}): ${t}`),r(new te("Network error.",t,a.status))},a.onabort=()=>r(new te("Aborted.",t,a.status,!0)),a.onloadend=()=>{var n;E.allXhrSet.delete(a),s&&((n=E.xhrMap.get(s))==null||n.delete(a))},a}static cancelXHRs(){var s;(s=E.xhrMap.get(this))==null||s.forEach(t=>{t.abort(),E.allXhrSet.delete(t)}),E.xhrMap.delete(this)}static release(){E.allXhrSet.forEach(s=>s.abort()),E.allXhrSet.clear(),E.xhrMap=new WeakMap}};let Pt=E;Pt.xhrMap=new WeakMap;Pt.allXhrSet=new Set;Pt.loader=(s,t)=>new Promise((e,i)=>{E.createXHR(s.target,s.settings?s.settings.resolveURL(s.url):s.url,s.type,a=>{s.result=a,e()},i).send()});function fe(s,t){let e=-1;return i(0);function i(r,a){if(a)return Promise.reject(a);if(r<=e)return Promise.reject(new Error("next() called multiple times"));e=r;const n=s[r];if(!n)return Promise.resolve();try{return Promise.resolve(n(t,i.bind(null,r+1)))}catch(o){return Promise.reject(o)}}}class j{static load(t){return fe(this.middlewares,t).then(()=>t.result)}}j.middlewares=[Pt.loader];function qe(s,t={}){var e;const i={resourceOptions:{crossorigin:t.crossOrigin}};if(bt.fromURL)return bt.fromURL(s,i).catch(n=>{if(n instanceof Error)throw n;const o=new Error("Texture loading error");throw o.event=n,o});i.resourceOptions.autoLoad=!1;const r=bt.from(s,i);if(r.baseTexture.valid)return Promise.resolve(r);const a=r.baseTexture.resource;return(e=a._live2d_load)!=null||(a._live2d_load=new Promise((n,o)=>{const l=h=>{a.source.removeEventListener("error",l);const u=new Error("Texture loading error");u.event=h,o(u)};a.source.addEventListener("error",l),a.load().then(()=>n(r)).catch(l)})),a._live2d_load}const ee="Live2DFactory",ye=(s,t)=>I(void 0,null,function*(){if(typeof s.source=="string"){const e=yield j.load({url:s.source,type:"json",target:s.live2dModel});e.url=s.source,s.source=e,s.live2dModel.emit("settingsJSONLoaded",e)}return t()}),xe=(s,t)=>I(void 0,null,function*(){if(s.source instanceof vt)return s.settings=s.source,t();if(typeof s.source=="object"){const e=b.findRuntime(s.source);if(e){const i=e.createModelSettings(s.source);return s.settings=i,s.live2dModel.emit("settingsLoaded",i),t()}}throw new TypeError("Unknown settings format.")}),ve=(s,t)=>{if(s.settings){const e=b.findRuntime(s.settings);if(e)return e.ready().then(t)}return t()},Me=(s,t)=>I(void 0,null,function*(){yield t();const e=s.internalModel;if(e){const i=s.settings,r=b.findRuntime(i);if(r){const a=[];i.pose&&a.push(j.load({settings:i,url:i.pose,type:"json",target:e}).then(n=>{e.pose=r.createPose(e.coreModel,n),s.live2dModel.emit("poseLoaded",e.pose)}).catch(n=>{s.live2dModel.emit("poseLoadError",n),C.warn(ee,"Failed to load pose.",n)})),i.physics&&a.push(j.load({settings:i,url:i.physics,type:"json",target:e}).then(n=>{e.physics=r.createPhysics(e.coreModel,n),s.live2dModel.emit("physicsLoaded",e.physics)}).catch(n=>{s.live2dModel.emit("physicsLoadError",n),C.warn(ee,"Failed to load physics.",n)})),a.length&&(yield Promise.all(a))}}}),Pe=(s,t)=>I(void 0,null,function*(){if(s.settings){const e=s.live2dModel,i=s.settings.textures.map(r=>{const a=s.settings.resolveURL(r);return qe(a,{crossOrigin:s.options.crossOrigin})});if(yield t(),s.internalModel)e.internalModel=s.internalModel,e.emit("modelLoaded",s.internalModel);else throw new TypeError("Missing internal model.");e.textures=yield Promise.all(i),e.emit("textureLoaded",e.textures)}else throw new TypeError("Missing settings.")}),Ce=(s,t)=>I(void 0,null,function*(){const e=s.settings;if(e instanceof vt){const i=b.findRuntime(e);if(!i)throw new TypeError("Unknown model settings.");const r=yield j.load({settings:e,url:e.moc,type:"arraybuffer",target:s.live2dModel});if(!i.isValidMoc(r))throw new Error("Invalid moc data");const a=i.createCoreModel(r);return s.internalModel=i.createInternalModel(a,e,s.options),t()}throw new TypeError("Missing settings.")}),L=class{static registerRuntime(s){L.runtimes.push(s),L.runtimes.sort((t,e)=>e.version-t.version)}static findRuntime(s){for(const t of L.runtimes)if(t.test(s))return t}static setupLive2DModel(s,t,e){return I(this,null,function*(){const i=new Promise(n=>s.once("textureLoaded",n)),r=new Promise(n=>s.once("modelLoaded",n)),a=Promise.all([i,r]).then(()=>s.emit("ready"));yield fe(L.live2DModelMiddlewares,{live2dModel:s,source:t,options:e||{}}),yield a,s.emit("load")})}static loadMotion(s,t,e){var i,r;const a=n=>s.emit("motionLoadError",t,e,n);try{const n=(i=s.definitions[t])==null?void 0:i[e];if(!n)return Promise.resolve(void 0);s.listeners("destroy").includes(L.releaseTasks)||s.once("destroy",L.releaseTasks);let o=L.motionTasksMap.get(s);o||(o={},L.motionTasksMap.set(s,o));let l=o[t];l||(l=[],o[t]=l);const h=s.getMotionFile(n);return(r=l[e])!=null||(l[e]=j.load({url:h,settings:s.settings,type:s.motionDataType,target:s}).then(u=>{var c;const d=(c=L.motionTasksMap.get(s))==null?void 0:c[t];d&&delete d[e];const _=s.createMotion(u,t,n);return s.emit("motionLoaded",t,e,_),_}).catch(u=>{C.warn(s.tag,`Failed to load motion: ${h}
5
- `,u),a(u)})),l[e]}catch(n){C.warn(s.tag,`Failed to load motion at "${t}"[${e}]
6
- `,n),a(n)}return Promise.resolve(void 0)}static loadExpression(s,t){var e;const i=r=>s.emit("expressionLoadError",t,r);try{const r=s.definitions[t];if(!r)return Promise.resolve(void 0);s.listeners("destroy").includes(L.releaseTasks)||s.once("destroy",L.releaseTasks);let a=L.expressionTasksMap.get(s);a||(a=[],L.expressionTasksMap.set(s,a));const n=s.getExpressionFile(r);return(e=a[t])!=null||(a[t]=j.load({url:n,settings:s.settings,type:"json",target:s}).then(o=>{const l=L.expressionTasksMap.get(s);l&&delete l[t];const h=s.createExpression(o,r);return s.emit("expressionLoaded",t,h),h}).catch(o=>{C.warn(s.tag,`Failed to load expression: ${n}
7
- `,o),i(o)})),a[t]}catch(r){C.warn(s.tag,`Failed to load expression at [${t}]
8
- `,r),i(r)}return Promise.resolve(void 0)}static releaseTasks(){this instanceof Mt?L.motionTasksMap.delete(this):L.expressionTasksMap.delete(this)}};let b=L;b.runtimes=[];b.urlToJSON=ye;b.jsonToSettings=xe;b.waitUntilReady=ve;b.setupOptionals=Me;b.setupEssentials=Pe;b.createInternalModel=Ce;b.live2DModelMiddlewares=[ye,xe,ve,Me,Pe,Ce];b.motionTasksMap=new WeakMap;b.expressionTasksMap=new WeakMap;Mt.prototype._loadMotion=function(s,t){return b.loadMotion(this,s,t)};Ot.prototype._loadExpression=function(s){return b.loadExpression(this,s)};class $e{constructor(){this._autoInteract=!1}get autoInteract(){return this._autoInteract}set autoInteract(t){t!==this._autoInteract&&(t?this.on("pointertap",ie,this):this.off("pointertap",ie,this),this._autoInteract=t)}registerInteraction(t){t!==this.interactionManager&&(this.unregisterInteraction(),this._autoInteract&&t&&(this.interactionManager=t,t.on("pointermove",se,this)))}unregisterInteraction(){var t;this.interactionManager&&((t=this.interactionManager)==null||t.off("pointermove",se,this),this.interactionManager=void 0)}}function ie(s){this.tap(s.data.global.x,s.data.global.y)}function se(s){this.focus(s.data.global.x,s.data.global.y)}class Je extends Re{}const D=new ke,Ze=new ft;let G;class Ke extends De{constructor(t){super(),this.tag="Live2DModel(uninitialized)",this.textures=[],this.transform=new Je,this.anchor=new Ae(this.onAnchorChange,this,0,0),this.glContextID=-1,this.elapsedTime=performance.now(),this.deltaTime=0,this.overrideBounds={x0:0,y0:0,x1:0,y1:0},this._autoUpdate=!1,this._alphaFilter=new Be(1),this._lastWorldAlpha=1,this.filters=this.filters?[...this.filters,this._alphaFilter]:[this._alphaFilter],this.once("modelLoaded",()=>this.init(t))}static from(t,e){const i=new this(e);return b.setupLive2DModel(i,t,e).then(()=>i)}static fromSync(t,e){const i=new this(e);return b.setupLive2DModel(i,t,e).then(e==null?void 0:e.onLoad).catch(e==null?void 0:e.onError),i}static registerTicker(t){G=t}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){var e;G||(G=(e=window.PIXI)==null?void 0:e.Ticker),t?this._destroyed||(G?(G.shared.add(this.onTickerUpdate,this),this._autoUpdate=!0):C.warn(this.tag,"No Ticker registered, please call Live2DModel.registerTicker(Ticker).")):(G==null||G.shared.remove(this.onTickerUpdate,this),this._autoUpdate=!1)}updateAlphaFilter(){const t=this.worldAlpha;this._alphaFilter.alpha=t,this._lastWorldAlpha=t}checkAlphaChange(){this.worldAlpha!==this._lastWorldAlpha&&this.updateAlphaFilter()}init(t){this.tag=`Live2DModel(${this.internalModel.settings.name})`;const e=Object.assign({autoUpdate:!0,autoInteract:!0},t);e.autoInteract&&(this.interactive=!0),e.overWriteBounds&&(this.overrideBounds=e.overWriteBounds),this.autoInteract=e.autoInteract,this.autoUpdate=e.autoUpdate}onAnchorChange(){this.pivot.set(this.anchor.x*this.internalModel.width,this.anchor.y*this.internalModel.height)}motion(t,e,i){return e===void 0?this.internalModel.motionManager.startRandomMotion(t,i):this.internalModel.motionManager.startMotion(t,e,i)}expression(t){return this.internalModel.motionManager.expressionManager?t===void 0?this.internalModel.motionManager.expressionManager.setRandomExpression():this.internalModel.motionManager.expressionManager.setExpression(t):Promise.resolve(!1)}focus(t,e,i=!1){D.x=t,D.y=e,this.toModelPosition(D,D,!0);let r=D.x/this.internalModel.originalWidth*2-1,a=D.y/this.internalModel.originalHeight*2-1,n=Math.atan2(a,r);this.internalModel.focusController.focus(Math.cos(n),-Math.sin(n),i)}tap(t,e){const i=this.hitTest(t,e);i.length&&(C.log(this.tag,"Hit",i),this.emit("hit",i))}hitTest(t,e){return D.x=t,D.y=e,this.toModelPosition(D,D),this.internalModel.hitTest(D.x,D.y)}toModelPosition(t,e=t.clone(),i){return i||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.transform.worldTransform.applyInverse(t,e),this.internalModel.localTransform.applyInverse(e,e),e}containsPoint(t){return this.getBounds(!0).contains(t.x,t.y)}_calculateBounds(){this._bounds.addFrame(this.transform,this.overrideBounds.x0,this.overrideBounds.y0,this.internalModel.width+this.overrideBounds.x1,this.internalModel.height+this.overrideBounds.y1)}onTickerUpdate(){this.update(G.shared.deltaMS)}update(t){this.deltaTime+=t,this.elapsedTime+=t}_render(t){this.checkAlphaChange(),this.registerInteraction(t.plugins.interaction),t.batch.reset(),t.geometry.reset(),t.shader.reset(),t.state.reset();let e=!1;this.glContextID!==t.CONTEXT_UID&&(this.glContextID=t.CONTEXT_UID,this.internalModel.updateWebGLContext(t.gl,this.glContextID),e=!0);for(let a=0;a<this.textures.length;a++){const n=this.textures[a];n.valid&&((e||!n.baseTexture._glTextures[this.glContextID])&&(t.gl.pixelStorei(WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL,this.internalModel.textureFlipY),t.texture.bind(n.baseTexture,0)),this.internalModel.bindTexture(a,n.baseTexture._glTextures[this.glContextID].texture),n.baseTexture.touched=t.textureGC.count)}const i=t.framebuffer.viewport;this.internalModel.viewport=[i.x,i.y,i.width,i.height],this.deltaTime&&(this.internalModel.update(this.deltaTime,this.elapsedTime),this.deltaTime=0);const r=Ze.copyFrom(t.globalUniforms.uniforms.projectionMatrix).append(this.worldTransform);this.internalModel.updateTransform(r),this.internalModel.draw(t.gl),t.state.reset(),t.texture.reset()}destroy(t){this.emit("destroy"),this.autoUpdate=!1,this.unregisterInteraction(),t!=null&&t.texture&&this.textures.forEach(e=>e.destroy(t.baseTexture)),this.internalModel.destroy(),super.destroy(t)}}me(Ke,[$e]);const U=class{static resolveURL(s,t){var e;const i=(e=U.filesMap[s])==null?void 0:e[t];if(i===void 0)throw new Error("Cannot find this file from uploaded files: "+t);return i}static upload(s,t){return I(this,null,function*(){const e={};for(const i of t.getDefinedFiles()){const r=decodeURI(Rt.resolve(t.url,i)),a=s.find(n=>n.webkitRelativePath===r);a&&(e[i]=URL.createObjectURL(a))}U.filesMap[t._objectURL]=e})}static createSettings(s){return I(this,null,function*(){const t=s.find(n=>n.name.endsWith("model.json")||n.name.endsWith("model3.json"));if(!t)throw new TypeError("Settings file not found");const e=yield U.readText(t),i=JSON.parse(e);i.url=t.webkitRelativePath;const r=b.findRuntime(i);if(!r)throw new Error("Unknown settings JSON");const a=r.createModelSettings(i);return a._objectURL=URL.createObjectURL(t),a})}static readText(s){return I(this,null,function*(){return new Promise((t,e)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=e,i.readAsText(s,"utf8")})})}};let Ut=U;Ut.filesMap={};Ut.factory=(s,t)=>I(void 0,null,function*(){if(Array.isArray(s.source)&&s.source[0]instanceof File){const e=s.source;let i=e.settings;if(!i)i=yield U.createSettings(e);else if(!i._objectURL)throw new Error('"_objectURL" must be specified in ModelSettings');i.validateFiles(e.map(r=>encodeURI(r.webkitRelativePath))),yield U.upload(e,i),i.resolveURL=function(r){return U.resolveURL(this._objectURL,r)},s.source=i,s.live2dModel.once("modelLoaded",r=>{r.once("destroy",function(){const a=this.settings._objectURL;if(URL.revokeObjectURL(a),U.filesMap[a])for(const n of Object.values(U.filesMap[a]))URL.revokeObjectURL(n);delete U.filesMap[a]})})}return t()});b.live2DModelMiddlewares.unshift(Ut.factory);const F=class{static unzip(s,t){return I(this,null,function*(){const e=yield F.getFilePaths(s),i=[];for(const a of t.getDefinedFiles()){const n=decodeURI(Rt.resolve(t.url,a));e.includes(n)&&i.push(n)}const r=yield F.getFiles(s,i);for(let a=0;a<r.length;a++){const n=i[a],o=r[a];Object.defineProperty(o,"webkitRelativePath",{value:n})}return r})}static createSettings(s){return I(this,null,function*(){const e=(yield F.getFilePaths(s)).find(n=>n.endsWith("model.json")||n.endsWith("model3.json"));if(!e)throw new Error("Settings file not found");const i=yield F.readText(s,e);if(!i)throw new Error("Empty settings file: "+e);const r=JSON.parse(i);r.url=e;const a=b.findRuntime(r);if(!a)throw new Error("Unknown settings JSON");return a.createModelSettings(r)})}static zipReader(s,t){return I(this,null,function*(){throw new Error("Not implemented")})}static getFilePaths(s){return I(this,null,function*(){throw new Error("Not implemented")})}static getFiles(s,t){return I(this,null,function*(){throw new Error("Not implemented")})}static readText(s,t){return I(this,null,function*(){throw new Error("Not implemented")})}static releaseReader(s){}};let Ct=F;Ct.ZIP_PROTOCOL="zip://";Ct.uid=0;Ct.factory=(s,t)=>I(void 0,null,function*(){const e=s.source;let i,r,a;if(typeof e=="string"&&(e.endsWith(".zip")||e.startsWith(F.ZIP_PROTOCOL))?(e.startsWith(F.ZIP_PROTOCOL)?i=e.slice(F.ZIP_PROTOCOL.length):i=e,r=yield j.load({url:i,type:"blob",target:s.live2dModel})):Array.isArray(e)&&e.length===1&&e[0]instanceof File&&e[0].name.endsWith(".zip")&&(r=e[0],i=URL.createObjectURL(r),a=e.settings),r){if(!r.size)throw new Error("Empty zip file");const n=yield F.zipReader(r,i);a||(a=yield F.createSettings(n)),a._objectURL=F.ZIP_PROTOCOL+F.uid+"/"+a.url;const o=yield F.unzip(n,a);o.settings=a,s.source=o,i.startsWith("blob:")&&s.live2dModel.once("modelLoaded",l=>{l.once("destroy",function(){URL.revokeObjectURL(i)})}),F.releaseReader(n)}return t()});b.live2DModelMiddlewares.unshift(Ct.factory);if(!window.Live2D)throw new Error("Could not find Cubism 2 runtime. This plugin requires live2d.min.js to be loaded.");const Qe=Live2DMotion.prototype.updateParam;Live2DMotion.prototype.updateParam=function(s,t){Qe.call(this,s,t),t.isFinished()&&this.onFinishHandler&&(this.onFinishHandler(this),delete this.onFinishHandler)};class ti extends AMotion{constructor(t){super(),this.params=[],this.setFadeIn(t.fade_in>0?t.fade_in:w.expressionFadingDuration),this.setFadeOut(t.fade_out>0?t.fade_out:w.expressionFadingDuration),Array.isArray(t.params)&&t.params.forEach(e=>{const i=e.calc||"add";if(i==="add"){const r=e.def||0;e.val-=r}else if(i==="mult"){const r=e.def||1;e.val/=r}this.params.push({calc:i,val:e.val,id:e.id})})}updateParamExe(t,e,i,r){this.params.forEach(a=>{if(w.legacyExpressionBlendMode){let n=t.getParamFloat(a.id);t.setParamFloat(a.id,a.val*i+n*(1-i))}else switch(a.calc){case"set":t.setParamFloat(a.id,a.val,i);break;case"add":t.addToParamFloat(a.id,a.val*i);break;case"mult":t.multParamFloat(a.id,a.val,i);break}})}}class ei extends Ot{constructor(t,e){var i;super(t,e),this.queueManager=new MotionQueueManager,this.definitions=(i=this.settings.expressions)!=null?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 ti(t)}_setExpression(t){return this.queueManager.startMotion(t)}stopAllExpressions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}}class ii extends Mt{constructor(t,e){super(t,e),this.groups={idle:"idle"},this.motionDataType="arraybuffer",this.queueManager=new MotionQueueManager,this.definitions=this.settings.motions,this.init(e)}init(t){super.init(t),this.settings.expressions&&(this.expressionManager=new ei(this.settings,t))}isFinished(){return this.queueManager.isFinished()}createMotion(t,e,i){const r=Live2DMotion.loadMotion(t),a=e===this.groups.idle?w.idleMotionFadingDuration:w.motionFadingDuration;return r.setFadeIn(i.fade_in>0?i.fade_in:a),r.setFadeOut(i.fade_out>0?i.fade_out:a),r}getMotionFile(t){return t.file}getMotionName(t){return t.file}getSoundFile(t){return t.sound}_startMotion(t,e){return t.onFinishHandler=e,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}}class si{constructor(t){this.coreModel=t,this.blinkInterval=4e3,this.blinkIntervalRandom=1e3,this.closingDuration=100,this.closedDuration=50,this.openingDuration=150,this.eyeState=0,this.eyeParamValue=1,this.closedTimer=0,this.nextBlinkTimeLeft=this.blinkInterval,this.leftParam=t.getParamIndex("PARAM_EYE_L_OPEN"),this.rightParam=t.getParamIndex("PARAM_EYE_R_OPEN"),this.recalculateBlinkInterval()}setEyeParams(t){this.eyeParamValue=yt(t,0,1),this.coreModel.multParamFloat(this.leftParam,this.eyeParamValue),this.coreModel.multParamFloat(this.rightParam,this.eyeParamValue)}recalculateBlinkInterval(){let t=this.blinkInterval;t+=Oe(-1,1)*this.blinkIntervalRandom,t=Math.max(t,0),this.nextBlinkTimeLeft=t}update(t){switch(this.eyeState){case 0:this.nextBlinkTimeLeft-=t,this.nextBlinkTimeLeft<0&&(this.eyeState=1,this.recalculateBlinkInterval());break;case 1:this.eyeParamValue=this.eyeParamValue-t/this.closingDuration,this.setEyeParams(Math.max(this.eyeParamValue,0)),this.eyeParamValue<=0&&(this.eyeState=2,this.closedTimer=0,this.eyeParamValue=0);break;case 2:this.closedTimer+=t,this.setEyeParams(this.eyeParamValue),this.closedTimer>=this.closedDuration&&(this.eyeState=3);break;case 3:this.eyeParamValue=this.eyeParamValue+t/this.openingDuration,this.setEyeParams(Math.min(this.eyeParamValue,1)),this.eyeParamValue>=1&&(this.eyeState=0,this.eyeParamValue=1);break}}}const Y=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);class ri extends _e{constructor(t,e,i){super(),this.textureFlipY=!0,this.drawDataCount=0,this.disableCulling=!1,this.coreModel=t,this.settings=e,this.motionManager=new ii(e,i),this.eyeBlink=new si(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:a,value:n})=>this.coreModel.setParamFloat(a,n)),this.settings.initOpacities&&this.settings.initOpacities.forEach(({id:a,value:n})=>this.coreModel.setPartsOpacity(a,n)),this.coreModel.saveParam();const t=this.coreModel.getModelContext()._$aS;t!=null&&t.length&&(this.drawDataCount=t.length);let e=this.coreModel.drawParamWebGL.culling;Object.defineProperty(this.coreModel.drawParamWebGL,"culling",{set:a=>e=a,get:()=>this.disableCulling?!1:e});const i=this.coreModel.getModelContext().clipManager,r=i.setupClip;i.setupClip=(a,n)=>{r.call(i,a,n),n.gl.viewport(...this.viewport)},this.setBlinkParam(pe)}getSize(){return[this.coreModel.getCanvasWidth(),this.coreModel.getCanvasHeight()]}getLayout(){const t={};if(this.settings.layout)for(const e of Object.keys(this.settings.layout)){let i=e;e==="center_x"?i="centerX":e==="center_y"&&(i="centerY"),t[i]=this.settings.layout[e]}return t}updateWebGLContext(t,e){const i=this.coreModel.drawParamWebGL;i.firstDraw=!0,i.setGL(t),i.glno=e;for(const n in i)i.hasOwnProperty(n)&&i[n]instanceof WebGLBuffer&&(i[n]=null);const r=this.coreModel.getModelContext().clipManager;r.curFrameNo=e;const a=t.getParameter(t.FRAMEBUFFER_BINDING);r.getMaskRenderTexture(),t.bindFramebuffer(t.FRAMEBUFFER,a)}bindTexture(t,e){this.coreModel.setTexture(t,e)}getHitAreaDefs(){var t;return((t=this.settings.hitAreas)==null?void 0:t.map(e=>({id:e.id,name:e.name,index:this.coreModel.getDrawDataIndex(e.id)})))||[]}getDrawableIDs(){const t=this.coreModel.getModelContext(),e=[];for(let i=0;i<this.drawDataCount;i++){const r=t.getDrawData(i);r&&e.push(r.getDrawDataID().id)}return e}getDrawableIndex(t){return this.coreModel.getDrawDataIndex(t)}getDrawableVertices(t){if(typeof t=="string"&&(t=this.coreModel.getDrawDataIndex(t),t===-1))throw new TypeError("Unable to find drawable ID: "+t);return this.coreModel.getTransformedPoints(t).slice()}update(t,e){var i,r,a,n;super.update(t,e);const o=this.coreModel;this.emit("beforeMotionUpdate");const l=this.motionManager.update(this.coreModel,e);this.emit("afterMotionUpdate"),o.saveParam(),(i=this.motionManager.expressionManager)==null||i.update(o,e),l||(r=this.eyeBlink)==null||r.update(t),this.updateFocus(),this.updateNaturalMovements(t,e),(a=this.physics)==null||a.update(e),(n=this.pose)==null||n.update(t),this.emit("beforeModelUpdate"),o.update(),o.loadParam()}updateFocus(){this.coreModel.addToParamFloat(this.eyeballXParamIndex,this.focusController.x),this.coreModel.addToParamFloat(this.eyeballYParamIndex,this.focusController.y),this.coreModel.addToParamFloat(this.angleXParamIndex,this.focusController.x*30),this.coreModel.addToParamFloat(this.angleYParamIndex,this.focusController.y*30),this.coreModel.addToParamFloat(this.angleZParamIndex,this.focusController.x*this.focusController.y*-30),this.coreModel.addToParamFloat(this.bodyAngleXParamIndex,this.focusController.x*10)}updateNaturalMovements(t,e){const i=e/1e3*2*Math.PI;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;Y[0]=i.a,Y[1]=i.b,Y[4]=i.c,Y[5]=i.d,Y[12]=i.tx,Y[13]=i.ty,this.coreModel.setMatrix(Y),this.coreModel.draw(),this.disableCulling=e}destroy(){super.destroy(),this.coreModel=void 0}setBlinkParam(t){if(this.eyeBlink)try{this.eyeBlink.blinkInterval=t.blinkInterval,this.eyeBlink.blinkIntervalRandom=t.blinkIntervalRandom,this.eyeBlink.closingDuration=t.closingDuration,this.eyeBlink.closedDuration=t.closedDuration,this.eyeBlink.openingDuration=t.openingDuration,this.eyeBlink.recalculateBlinkInterval()}catch(e){console.error("Failed to set blink parameters:",e)}}}class dt extends vt{constructor(t){if(super(t),this.motions={},!dt.isValidJSON(t))throw new TypeError("Invalid JSON.");this.moc=t.model,at("string",t,this,"textures","textures"),this.copy(t)}static isValidJSON(t){var e;return!!t&&typeof t.model=="string"&&((e=t.textures)==null?void 0:e.length)>0&&t.textures.every(i=>typeof i=="string")}copy(t){rt("string",t,this,"name","name"),rt("string",t,this,"pose","pose"),rt("string",t,this,"physics","physics"),rt("object",t,this,"layout","layout"),rt("object",t,this,"motions","motions"),at("object",t,this,"hit_areas","hitAreas"),at("object",t,this,"expressions","expressions"),at("object",t,this,"init_params","initParams"),at("object",t,this,"init_opacities","initOpacities")}replaceFiles(t){super.replaceFiles(t);for(const[e,i]of Object.entries(this.motions))for(let r=0;r<i.length;r++)i[r].file=t(i[r].file,`motions.${e}[${r}].file`),i[r].sound!==void 0&&(i[r].sound=t(i[r].sound,`motions.${e}[${r}].sound`));if(this.expressions)for(let e=0;e<this.expressions.length;e++)this.expressions[e].file=t(this.expressions[e].file,`expressions[${e}].file`)}}const ai={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE},ni={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE};class oi{constructor(t,e){this.coreModel=t,this.physicsHairs=[],e.physics_hair&&(this.physicsHairs=e.physics_hair.map(i=>{const r=new PhysicsHair;return r.setup(i.setup.length,i.setup.regist,i.setup.mass),i.src.forEach(({id:a,ptype:n,scale:o,weight:l})=>{const h=ai[n];h&&r.addSrcParam(h,a,o,l)}),i.targets.forEach(({id:a,ptype:n,scale:o,weight:l})=>{const h=ni[n];h&&r.addTargetParam(h,a,o,l)}),r}))}update(t){this.physicsHairs.forEach(e=>e.update(this.coreModel,t))}}class re{constructor(t){this.id=t,this.paramIndex=-1,this.partsIndex=-1,this.link=[]}initIndex(t){this.paramIndex=t.getParamIndex("VISIBLE:"+this.id),this.partsIndex=t.getPartsDataIndex(PartsDataID.getID(this.id)),t.setParamFloat(this.paramIndex,1)}}class li{constructor(t,e){this.coreModel=t,this.opacityAnimDuration=500,this.partsGroups=[],e.parts_visible&&(this.partsGroups=e.parts_visible.map(({group:i})=>i.map(({id:r,link:a})=>{const n=new re(r);return a&&(n.link=a.map(o=>new re(o))),n})),this.init())}init(){this.partsGroups.forEach(t=>{t.forEach(e=>{if(e.initIndex(this.coreModel),e.paramIndex>=0){const i=this.coreModel.getParamFloat(e.paramIndex)!==0;this.coreModel.setPartsOpacity(e.partsIndex,i?1:0),this.coreModel.setParamFloat(e.paramIndex,i?1:0),e.link.length>0&&e.link.forEach(r=>r.initIndex(this.coreModel))}})})}normalizePartsOpacityGroup(t,e){const i=this.coreModel,r=.5,a=.15;let n=1,o=t.findIndex(({paramIndex:l,partsIndex:h})=>h>=0&&i.getParamFloat(l)!==0);if(o>=0){const l=i.getPartsOpacity(t[o].partsIndex);n=yt(l+e/this.opacityAnimDuration,0,1)}else o=0,n=1;t.forEach(({partsIndex:l},h)=>{if(l>=0)if(o==h)i.setPartsOpacity(l,n);else{let u=i.getPartsOpacity(l),c;n<r?c=n*(r-1)/r+1:c=(1-n)*r/(1-r),(1-c)*(1-n)>a&&(c=1-a/(1-n)),u>c&&(u=c),i.setPartsOpacity(l,u)}})}copyOpacity(t){const e=this.coreModel;t.forEach(({partsIndex:i,link:r})=>{if(i>=0&&r){const a=e.getPartsOpacity(i);r.forEach(({partsIndex:n})=>{n>=0&&e.setPartsOpacity(n,a)})}})}update(t){this.partsGroups.forEach(e=>{this.normalizePartsOpacityGroup(e,t),this.copyOpacity(e)})}}b.registerRuntime({version:2,test(s){return s instanceof dt||dt.isValidJSON(s)},ready(){return Promise.resolve()},isValidMoc(s){if(s.byteLength<3)return!1;const t=new Int8Array(s,0,3);return String.fromCharCode(...t)==="moc"},createModelSettings(s){return new dt(s)},createCoreModel(s){const t=Live2DModelWebGL.loadModel(s),e=Live2D.getError();if(e)throw e;return t},createInternalModel(s,t,e){return new ri(s,t,e)},createPose(s,t){return new li(s,t)},createPhysics(s,t){return new oi(s,t)}});if(!window.Live2DCubismCore)throw new Error("Could not find Cubism 4 runtime. This plugin requires live2dcubismcore.js to be loaded.");class y{constructor(t,e){this.x=t||0,this.y=e||0}add(t){const e=new y(0,0);return e.x=this.x+t.x,e.y=this.y+t.y,e}substract(t){const e=new y(0,0);return e.x=this.x-t.x,e.y=this.y-t.y,e}multiply(t){const e=new y(0,0);return e.x=this.x*t.x,e.y=this.y*t.y,e}multiplyByScaler(t){return this.multiply(new y(t,t))}division(t){const e=new y(0,0);return e.x=this.x/t.x,e.y=this.y/t.y,e}divisionByScalar(t){return this.division(new y(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)}}const _t=class{static range(s,t,e){return s<t?s=t:s>e&&(s=e),s}static sin(s){return Math.sin(s)}static cos(s){return Math.cos(s)}static abs(s){return Math.abs(s)}static sqrt(s){return Math.sqrt(s)}static cbrt(s){if(s===0)return s;let t=s;const e=t<0;e&&(t=-t);let i;return t===1/0?i=1/0:(i=Math.exp(Math.log(t)/3),i=(t/(i*i)+2*i)/3),e?-i:i}static getEasingSine(s){return s<0?0:s>1?1:.5-.5*this.cos(s*Math.PI)}static max(s,t){return s>t?s:t}static min(s,t){return s>t?t:s}static degreesToRadian(s){return s/180*Math.PI}static radianToDegrees(s){return s*180/Math.PI}static directionToRadian(s,t){const e=Math.atan2(t.y,t.x),i=Math.atan2(s.y,s.x);let r=e-i;for(;r<-Math.PI;)r+=Math.PI*2;for(;r>Math.PI;)r-=Math.PI*2;return r}static directionToDegrees(s,t){const e=this.directionToRadian(s,t);let i=this.radianToDegrees(e);return t.x-s.x>0&&(i=-i),i}static radianToDirection(s){const t=new y;return t.x=this.sin(s),t.y=this.cos(s),t}static quadraticEquation(s,t,e){return this.abs(s)<_t.Epsilon?this.abs(t)<_t.Epsilon?-e:-e/t:-(t+this.sqrt(t*t-4*s*e))/(2*s)}static cardanoAlgorithmForBezier(s,t,e,i){if(this.sqrt(s)<_t.Epsilon)return this.range(this.quadraticEquation(t,e,i),0,1);const r=t/s,a=e/s,n=i/s,o=(3*a-r*r)/3,l=o/3,h=(2*r*r*r-9*r*a+27*n)/27,u=h/2,c=u*u+l*l*l,d=.5,_=d+.01;if(c<0){const f=-o/3,x=f*f*f,M=this.sqrt(x),T=-h/(2*M),P=this.range(T,-1,1),V=Math.acos(P),N=2*this.cbrt(M),$t=N*this.cos(V/3)-r/3;if(this.abs($t-d)<_)return this.range($t,0,1);const Jt=N*this.cos((V+2*Math.PI)/3)-r/3;if(this.abs(Jt-d)<_)return this.range(Jt,0,1);const Fe=N*this.cos((V+4*Math.PI)/3)-r/3;return this.range(Fe,0,1)}if(c==0){let f;u<0?f=this.cbrt(-u):f=-this.cbrt(u);const x=2*f-r/3;if(this.abs(x-d)<_)return this.range(x,0,1);const M=-f-r/3;return this.range(M,0,1)}const p=this.sqrt(c),v=this.cbrt(p-u),m=this.cbrt(p+u),g=v-m-r/3;return this.range(g,0,1)}constructor(){}};let S=_t;S.Epsilon=1e-5;class k{constructor(){this._tr=new Float32Array(16),this.loadIdentity()}static multiply(t,e,i){const r=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),a=4;for(let n=0;n<a;++n)for(let o=0;o<a;++o)for(let l=0;l<a;++l)r[o+n*4]+=t[l+n*4]*e[o+l*4];for(let n=0;n<16;++n)i[n]=r[n]}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]);k.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]);k.multiply(i,this._tr,this._tr)}scale(t,e){this._tr[0]=t,this._tr[5]=e}multiplyByMatrix(t){k.multiply(t.getArray(),this._tr,this._tr)}clone(){const t=new k;for(let e=0;e<this._tr.length;e++)t._tr[e]=this._tr[e];return t}}class Vt{initialize(t){this._model=t}drawModel(){this.getModel()!=null&&this.doDrawModel()}setMvpMatrix(t){this._mvpMatrix4x4.setMatrix(t.getArray())}getMvpMatrix(){return this._mvpMatrix4x4}setModelColor(t,e,i,r){t<0?t=0:t>1&&(t=1),e<0?e=0:e>1&&(e=1),i<0?i=0:i>1&&(i=1),r<0?r=0:r>1&&(r=1),this._modelColor.R=t,this._modelColor.G=e,this._modelColor.B=i,this._modelColor.A=r}getModelColor(){return Object.assign({},this._modelColor)}setIsPremultipliedAlpha(t){this._isPremultipliedAlpha=t}isPremultipliedAlpha(){return this._isPremultipliedAlpha}setIsCulling(t){this._isCulling=t}isCulling(){return this._isCulling}setAnisotropy(t){this._anisortopy=t}getAnisotropy(){return this._anisortopy}getModel(){return this._model}constructor(){this._isCulling=!1,this._isPremultipliedAlpha=!1,this._anisortopy=0,this._modelColor=new ot,this._mvpMatrix4x4=new k,this._mvpMatrix4x4.loadIdentity()}}var X=(s=>(s[s.CubismBlendMode_Normal=0]="CubismBlendMode_Normal",s[s.CubismBlendMode_Additive=1]="CubismBlendMode_Additive",s[s.CubismBlendMode_Multiplicative=2]="CubismBlendMode_Multiplicative",s))(X||{});class ot{constructor(){this.R=1,this.G=1,this.B=1,this.A=1}}let R=!1,Q=!1,tt;const It={vertexOffset:0,vertexStep:2};class gt{static startUp(t){if(R)return nt("CubismFramework.startUp() is already done."),R;if(Live2DCubismCore._isStarted)return R=!0,!0;if(Live2DCubismCore._isStarted=!0,tt=t,tt&&Live2DCubismCore.Logging.csmSetLogFunction(tt.logFunction),R=!0,R){const e=Live2DCubismCore.Version.csmGetVersion(),i=(e&4278190080)>>24,r=(e&16711680)>>16,a=e&65535,n=e;nt("Live2D Cubism Core version: {0}.{1}.{2} ({3})",("00"+i).slice(-2),("00"+r).slice(-2),("0000"+a).slice(-4),n)}return nt("CubismFramework.startUp() is complete."),R}static cleanUp(){R=!1,Q=!1,tt=void 0}static initialize(){if(!R){lt("CubismFramework is not started.");return}if(Q){lt("CubismFramework.initialize() skipped, already initialized.");return}Q=!0,nt("CubismFramework.initialize() is complete.")}static dispose(){if(!R){lt("CubismFramework is not started.");return}if(!Q){lt("CubismFramework.dispose() skipped, not initialized.");return}Vt.staticRelease(),Q=!1,nt("CubismFramework.dispose() is complete.")}static isStarted(){return R}static isInitialized(){return Q}static coreLogFunction(t){Live2DCubismCore.Logging.csmGetLogFunction()&&Live2DCubismCore.Logging.csmGetLogFunction()(t)}static getLoggingLevel(){return tt!=null?tt.loggingLevel:K.LogLevel_Off}constructor(){}}var K=(s=>(s[s.LogLevel_Verbose=0]="LogLevel_Verbose",s[s.LogLevel_Debug=1]="LogLevel_Debug",s[s.LogLevel_Info=2]="LogLevel_Info",s[s.LogLevel_Warning=3]="LogLevel_Warning",s[s.LogLevel_Error=4]="LogLevel_Error",s[s.LogLevel_Off=5]="LogLevel_Off",s))(K||{});const mt=()=>{};function ae(s,...t){St.print(K.LogLevel_Debug,"[CSM][D]"+s+`
9
- `,t)}function nt(s,...t){St.print(K.LogLevel_Info,"[CSM][I]"+s+`
10
- `,t)}function lt(s,...t){St.print(K.LogLevel_Warning,"[CSM][W]"+s+`
11
- `,t)}function et(s,...t){St.print(K.LogLevel_Error,"[CSM][E]"+s+`
12
- `,t)}class St{static print(t,e,i){if(t<gt.getLoggingLevel())return;const r=gt.coreLogFunction;if(!r)return;const a=e.replace(/{(\d+)}/g,(n,o)=>i[o]);r(a)}static dumpBytes(t,e,i){for(let r=0;r<i;r++)r%16==0&&r>0?this.print(t,`
13
- `):r%8==0&&r>0&&this.print(t," "),this.print(t,"{0} ",[e[r]&255]);this.print(t,`
14
- `)}constructor(){}}class Se{constructor(){this._fadeInSeconds=-1,this._fadeOutSeconds=-1,this._weight=1,this._offsetSeconds=0,this._firedEventValues=[]}release(){this._weight=0}updateParameters(t,e,i){if(!e.isAvailable()||e.isFinished())return;if(!e.isStarted()){e.setIsStarted(!0),e.setStartTime(i-this._offsetSeconds),e.setFadeInStartTime(i);const o=this.getDuration();e.getEndTime()<0&&e.setEndTime(o<=0?-1:e.getStartTime()+o)}let r=this._weight;const a=this._fadeInSeconds==0?1:S.getEasingSine((i-e.getFadeInStartTime())/this._fadeInSeconds),n=this._fadeOutSeconds==0||e.getEndTime()<0?1:S.getEasingSine((e.getEndTime()-i)/this._fadeOutSeconds);r=r*a*n,e.setState(i,r),this.doUpdateParameters(t,i,r,e),e.getEndTime()>0&&e.getEndTime()<i&&e.setIsFinished(!0)}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}getFiredEvent(t,e){return this._firedEventValues}setFinishedMotionHandler(t){this._onFinishedMotion=t}getFinishedMotionHandler(){return this._onFinishedMotion}}const ne=1;class Nt extends Se{constructor(){super(),this._parameters=[]}static create(t){const e=new Nt,i=t.FadeInTime,r=t.FadeOutTime;e.setFadeInTime(i!==void 0?i:ne),e.setFadeOutTime(r!==void 0?r:ne);const a=t.Parameters||[];for(let n=0;n<a.length;++n){const o=a[n],l=o.Id,h=o.Value;let u;switch(o.Blend){case"Multiply":u=q.ExpressionBlendType_Multiply;break;case"Overwrite":u=q.ExpressionBlendType_Overwrite;break;case"Add":default:u=q.ExpressionBlendType_Add;break}const c={parameterId:l,blendType:u,value:h};e._parameters.push(c)}return e}doUpdateParameters(t,e,i,r){for(let a=0;a<this._parameters.length;++a){const n=this._parameters[a];switch(n.blendType){case q.ExpressionBlendType_Add:{t.addParameterValueById(n.parameterId,n.value,i);break}case q.ExpressionBlendType_Multiply:{t.multiplyParameterValueById(n.parameterId,n.value,i);break}case q.ExpressionBlendType_Overwrite:{t.setParameterValueById(n.parameterId,n.value,i);break}}}}}var q=(s=>(s[s.ExpressionBlendType_Add=0]="ExpressionBlendType_Add",s[s.ExpressionBlendType_Multiply=1]="ExpressionBlendType_Multiply",s[s.ExpressionBlendType_Overwrite=2]="ExpressionBlendType_Overwrite",s))(q||{});class hi{constructor(){this._autoDelete=!1,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&&this._motion.release()}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}}class be{constructor(){this._userTimeSeconds=0,this._eventCustomData=null,this._motions=[]}release(){for(let t=0;t<this._motions.length;++t)this._motions[t]&&this._motions[t].release();this._motions=void 0}startMotion(t,e,i){if(t==null)return ui;let r;for(let a=0;a<this._motions.length;++a)r=this._motions[a],r!=null&&r.setFadeOut(r._motion.getFadeOutTime());return r=new hi,r._autoDelete=e,r._motion=t,this._motions.push(r),r._motionQueueEntryHandle}isFinished(){let t=0;for(;t<this._motions.length;){const e=this._motions[t];if(e==null){this._motions.splice(t,1);continue}if(e._motion==null){e.release(),this._motions.splice(t,1);continue}if(!e.isFinished())return!1;t++}return!0}isFinishedByHandle(t){for(let e=0;e<this._motions.length;e++){const i=this._motions[e];if(i!=null&&i._motionQueueEntryHandle==t&&!i.isFinished())return!1}return!0}stopAllMotions(){for(let t=0;t<this._motions.length;t++){const e=this._motions[t];e!=null&&e.release()}this._motions=[]}getCubismMotionQueueEntry(t){return this._motions.find(e=>e!=null&&e._motionQueueEntryHandle==t)}setEventCallback(t,e=null){this._eventCallBack=t,this._eventCustomData=e}doUpdateMotion(t,e){let i=!1,r=0;for(;r<this._motions.length;){const a=this._motions[r];if(a==null){this._motions.splice(r,1);continue}const n=a._motion;if(n==null){a.release(),this._motions.splice(r,1);continue}n.updateParameters(t,a,e),i=!0;const o=n.getFiredEvent(a.getLastCheckEventSeconds()-a.getStartTime(),e-a.getStartTime());for(let l=0;l<o.length;++l)this._eventCallBack(this,o[l],this._eventCustomData);a.setLastCheckEventSeconds(e),a.isFinished()?(a.release(),this._motions.splice(r,1)):(a.isTriggeredFadeOut()&&a.startFadeOut(a.getFadeOutSeconds(),e),r++)}return i}}const ui=-1;class di extends Ot{constructor(t,e){var i;super(t,e),this.queueManager=new be,this.definitions=(i=t.expressions)!=null?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 Nt.create(t)}_setExpression(t){return this.queueManager.startMotion(t,!1,performance.now())}stopAllExpressions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.doUpdateMotion(t,e)}}class Ie{constructor(t){this.groups=t.Groups,this.hitAreas=t.HitAreas,this.layout=t.Layout,this.moc=t.FileReferences.Moc,this.expressions=t.FileReferences.Expressions,this.motions=t.FileReferences.Motions,this.textures=t.FileReferences.Textures,this.physics=t.FileReferences.Physics,this.pose=t.FileReferences.Pose}getEyeBlinkParameters(){var t,e;return(e=(t=this.groups)==null?void 0:t.find(i=>i.Name==="EyeBlink"))==null?void 0:e.Ids}getLipSyncParameters(){var t,e;return(e=(t=this.groups)==null?void 0:t.find(i=>i.Name==="LipSync"))==null?void 0:e.Ids}}class it extends vt{constructor(t){if(super(t),!it.isValidJSON(t))throw new TypeError("Invalid JSON.");Object.assign(this,new Ie(t))}static isValidJSON(t){var e;return!!(t!=null&&t.FileReferences)&&typeof t.FileReferences.Moc=="string"&&((e=t.FileReferences.Textures)==null?void 0:e.length)>0&&t.FileReferences.Textures.every(i=>typeof i=="string")}replaceFiles(t){if(super.replaceFiles(t),this.motions)for(const[e,i]of Object.entries(this.motions))for(let r=0;r<i.length;r++)i[r].File=t(i[r].File,`motions.${e}[${r}].File`),i[r].Sound!==void 0&&(i[r].Sound=t(i[r].Sound,`motions.${e}[${r}].Sound`));if(this.expressions)for(let e=0;e<this.expressions.length;e++)this.expressions[e].File=t(this.expressions[e].File,`expressions[${e}].File`)}}me(it,[Ie]);var $=(s=>(s[s.CubismMotionCurveTarget_Model=0]="CubismMotionCurveTarget_Model",s[s.CubismMotionCurveTarget_Parameter=1]="CubismMotionCurveTarget_Parameter",s[s.CubismMotionCurveTarget_PartOpacity=2]="CubismMotionCurveTarget_PartOpacity",s))($||{}),O=(s=>(s[s.CubismMotionSegmentType_Linear=0]="CubismMotionSegmentType_Linear",s[s.CubismMotionSegmentType_Bezier=1]="CubismMotionSegmentType_Bezier",s[s.CubismMotionSegmentType_Stepped=2]="CubismMotionSegmentType_Stepped",s[s.CubismMotionSegmentType_InverseStepped=3]="CubismMotionSegmentType_InverseStepped",s))(O||{});class z{constructor(t=0,e=0){this.time=t,this.value=e}}class ci{constructor(){this.basePointIndex=0,this.segmentType=0}}class gi{constructor(){this.id="",this.type=0,this.segmentCount=0,this.baseSegmentIndex=0,this.fadeInTime=0,this.fadeOutTime=0}}class mi{constructor(){this.fireTime=0,this.value=""}}class pi{constructor(){this.duration=0,this.loop=!1,this.curveCount=0,this.eventCount=0,this.fps=0,this.curves=[],this.segments=[],this.points=[],this.events=[]}}class we{constructor(t){this._json=t}release(){this._json=void 0}getMotionDuration(){return this._json.Meta.Duration}isMotionLoop(){return this._json.Meta.Loop||!1}getEvaluationOptionFlag(t){return Gt.EvaluationOptionFlag_AreBeziersRistricted==t?!!this._json.Meta.AreBeziersRestricted:!1}getMotionCurveCount(){return this._json.Meta.CurveCount}getMotionFps(){return this._json.Meta.Fps}getMotionTotalSegmentCount(){return this._json.Meta.TotalSegmentCount}getMotionTotalPointCount(){return this._json.Meta.TotalPointCount}getMotionFadeInTime(){return this._json.Meta.FadeInTime}getMotionFadeOutTime(){return this._json.Meta.FadeOutTime}getMotionCurveTarget(t){return this._json.Curves[t].Target}getMotionCurveId(t){return this._json.Curves[t].Id}getMotionCurveFadeInTime(t){return this._json.Curves[t].FadeInTime}getMotionCurveFadeOutTime(t){return this._json.Curves[t].FadeOutTime}getMotionCurveSegmentCount(t){return this._json.Curves[t].Segments.length}getMotionCurveSegment(t,e){return this._json.Curves[t].Segments[e]}getEventCount(){return this._json.Meta.UserDataCount||0}getTotalEventValueSize(){return this._json.Meta.TotalUserDataSize}getEventTime(t){return this._json.UserData[t].Time}getEventValue(t){return this._json.UserData[t].Value}}var Gt=(s=>(s[s.EvaluationOptionFlag_AreBeziersRistricted=0]="EvaluationOptionFlag_AreBeziersRistricted",s))(Gt||{});const _i="EyeBlink",fi="LipSync",yi="Model",xi="Parameter",vi="PartOpacity",Mi=!1;function B(s,t,e){const i=new z;return i.time=s.time+(t.time-s.time)*e,i.value=s.value+(t.value-s.value)*e,i}function Pi(s,t){let e=(t-s[0].time)/(s[1].time-s[0].time);return e<0&&(e=0),s[0].value+(s[1].value-s[0].value)*e}function Ci(s,t){let e=(t-s[0].time)/(s[3].time-s[0].time);e<0&&(e=0);const i=B(s[0],s[1],e),r=B(s[1],s[2],e),a=B(s[2],s[3],e),n=B(i,r,e),o=B(r,a,e);return B(n,o,e).value}function Si(s,t){const e=t,i=s[0].time,r=s[3].time,a=s[1].time,n=s[2].time,o=r-3*n+3*a-i,l=3*n-6*a+3*i,h=3*a-3*i,u=i-e,c=S.cardanoAlgorithmForBezier(o,l,h,u),d=B(s[0],s[1],c),_=B(s[1],s[2],c),p=B(s[2],s[3],c),v=B(d,_,c),m=B(_,p,c);return B(v,m,c).value}function bi(s,t){return s[0].value}function Ii(s,t){return s[1].value}function wt(s,t,e){const i=s.curves[t];let r=-1;const a=i.baseSegmentIndex+i.segmentCount;let n=0;for(let l=i.baseSegmentIndex;l<a;++l)if(n=s.segments[l].basePointIndex+(s.segments[l].segmentType==O.CubismMotionSegmentType_Bezier?3:1),s.points[n].time>e){r=l;break}if(r==-1)return s.points[n].value;const o=s.segments[r];return o.evaluate(s.points.slice(o.basePointIndex),e)}class zt extends Se{constructor(){super(),this._eyeBlinkParameterIds=[],this._lipSyncParameterIds=[],this._sourceFrameRate=30,this._loopDurationSeconds=-1,this._isLoop=!1,this._isLoopFadeIn=!0,this._lastWeight=0}static create(t,e){const i=new zt;return i.parse(t),i._sourceFrameRate=i._motionData.fps,i._loopDurationSeconds=i._motionData.duration,i._onFinishedMotion=e,i}doUpdateParameters(t,e,i,r){this._modelCurveIdEyeBlink==null&&(this._modelCurveIdEyeBlink=_i),this._modelCurveIdLipSync==null&&(this._modelCurveIdLipSync=fi);let a=e-r.getStartTime();a<0&&(a=0);let n=Number.MAX_VALUE,o=Number.MAX_VALUE;const l=64;let h=0,u=0;this._eyeBlinkParameterIds.length>l&&ae("too many eye blink targets : {0}",this._eyeBlinkParameterIds.length),this._lipSyncParameterIds.length>l&&ae("too many lip sync targets : {0}",this._lipSyncParameterIds.length);const c=this._fadeInSeconds<=0?1:S.getEasingSine((e-r.getFadeInStartTime())/this._fadeInSeconds),d=this._fadeOutSeconds<=0||r.getEndTime()<0?1:S.getEasingSine((r.getEndTime()-e)/this._fadeOutSeconds);let _,p,v,m=a;if(this._isLoop)for(;m>this._motionData.duration;)m-=this._motionData.duration;const g=this._motionData.curves;for(p=0;p<this._motionData.curveCount&&g[p].type==$.CubismMotionCurveTarget_Model;++p)_=wt(this._motionData,p,m),g[p].id==this._modelCurveIdEyeBlink?o=_:g[p].id==this._modelCurveIdLipSync&&(n=_);for(;p<this._motionData.curveCount&&g[p].type==$.CubismMotionCurveTarget_Parameter;++p){if(v=t.getParameterIndex(g[p].id),v==-1)continue;const f=t.getParameterValueByIndex(v);if(_=wt(this._motionData,p,m),o!=Number.MAX_VALUE){for(let M=0;M<this._eyeBlinkParameterIds.length&&M<l;++M)if(this._eyeBlinkParameterIds[M]==g[p].id){_*=o,u|=1<<M;break}}if(n!=Number.MAX_VALUE){for(let M=0;M<this._lipSyncParameterIds.length&&M<l;++M)if(this._lipSyncParameterIds[M]==g[p].id){_+=n,h|=1<<M;break}}let x;if(g[p].fadeInTime<0&&g[p].fadeOutTime<0)x=f+(_-f)*i;else{let M,T;g[p].fadeInTime<0?M=c:M=g[p].fadeInTime==0?1:S.getEasingSine((e-r.getFadeInStartTime())/g[p].fadeInTime),g[p].fadeOutTime<0?T=d:T=g[p].fadeOutTime==0||r.getEndTime()<0?1:S.getEasingSine((r.getEndTime()-e)/g[p].fadeOutTime);const P=this._weight*M*T;x=f+(_-f)*P}t.setParameterValueByIndex(v,x,1)}{if(o!=Number.MAX_VALUE)for(let f=0;f<this._eyeBlinkParameterIds.length&&f<l;++f){const x=t.getParameterValueById(this._eyeBlinkParameterIds[f]);if(u>>f&1)continue;const M=x+(o-x)*i;t.setParameterValueById(this._eyeBlinkParameterIds[f],M)}if(n!=Number.MAX_VALUE)for(let f=0;f<this._lipSyncParameterIds.length&&f<l;++f){const x=t.getParameterValueById(this._lipSyncParameterIds[f]);if(h>>f&1)continue;const M=x+(n-x)*i;t.setParameterValueById(this._lipSyncParameterIds[f],M)}}for(;p<this._motionData.curveCount&&g[p].type==$.CubismMotionCurveTarget_PartOpacity;++p)if(_=wt(this._motionData,p,m),ct.setOpacityFromMotion)t.setPartOpacityById(g[p].id,_);else{if(v=t.getParameterIndex(g[p].id),v==-1)continue;t.setParameterValueByIndex(v,_)}a>=this._motionData.duration&&(this._isLoop?(r.setStartTime(e),this._isLoopFadeIn&&r.setFadeInStartTime(e)):(this._onFinishedMotion&&this._onFinishedMotion(this),r.setIsFinished(!0))),this._lastWeight=i}setIsLoop(t){this._isLoop=t}isLoop(){return this._isLoop}setIsLoopFadeIn(t){this._isLoopFadeIn=t}isLoopFadeIn(){return this._isLoopFadeIn}getDuration(){return this._isLoop?-1:this._loopDurationSeconds}getLoopDuration(){return this._loopDurationSeconds}setParameterFadeInTime(t,e){const i=this._motionData.curves;for(let r=0;r<this._motionData.curveCount;++r)if(t==i[r].id){i[r].fadeInTime=e;return}}setParameterFadeOutTime(t,e){const i=this._motionData.curves;for(let r=0;r<this._motionData.curveCount;++r)if(t==i[r].id){i[r].fadeOutTime=e;return}}getParameterFadeInTime(t){const e=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==e[i].id)return e[i].fadeInTime;return-1}getParameterFadeOutTime(t){const e=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==e[i].id)return e[i].fadeOutTime;return-1}setEffectIds(t,e){this._eyeBlinkParameterIds=t,this._lipSyncParameterIds=e}release(){this._motionData=void 0}parse(t){this._motionData=new pi;let e=new we(t);this._motionData.duration=e.getMotionDuration(),this._motionData.loop=e.isMotionLoop(),this._motionData.curveCount=e.getMotionCurveCount(),this._motionData.fps=e.getMotionFps(),this._motionData.eventCount=e.getEventCount();const i=e.getEvaluationOptionFlag(Gt.EvaluationOptionFlag_AreBeziersRistricted),r=e.getMotionFadeInTime(),a=e.getMotionFadeOutTime();r!==void 0?this._fadeInSeconds=r<0?1:r:this._fadeInSeconds=1,a!==void 0?this._fadeOutSeconds=a<0?1:a:this._fadeOutSeconds=1,this._motionData.curves=Array.from({length:this._motionData.curveCount}).map(()=>new gi),this._motionData.segments=Array.from({length:e.getMotionTotalSegmentCount()}).map(()=>new ci),this._motionData.events=Array.from({length:this._motionData.eventCount}).map(()=>new mi),this._motionData.points=[];let n=0,o=0;for(let l=0;l<this._motionData.curveCount;++l){const h=this._motionData.curves[l];switch(e.getMotionCurveTarget(l)){case yi:h.type=$.CubismMotionCurveTarget_Model;break;case xi:h.type=$.CubismMotionCurveTarget_Parameter;break;case vi:h.type=$.CubismMotionCurveTarget_PartOpacity;break;default:lt('Warning : Unable to get segment type from Curve! The number of "CurveCount" may be incorrect!')}h.id=e.getMotionCurveId(l),h.baseSegmentIndex=o;const u=e.getMotionCurveFadeInTime(l),c=e.getMotionCurveFadeOutTime(l);h.fadeInTime=u!==void 0?u:-1,h.fadeOutTime=c!==void 0?c:-1;for(let d=0;d<e.getMotionCurveSegmentCount(l);){switch(d==0?(this._motionData.segments[o].basePointIndex=n,this._motionData.points[n]=new z(e.getMotionCurveSegment(l,d),e.getMotionCurveSegment(l,d+1)),n+=1,d+=2):this._motionData.segments[o].basePointIndex=n-1,e.getMotionCurveSegment(l,d)){case O.CubismMotionSegmentType_Linear:{this._motionData.segments[o].segmentType=O.CubismMotionSegmentType_Linear,this._motionData.segments[o].evaluate=Pi,this._motionData.points[n]=new z(e.getMotionCurveSegment(l,d+1),e.getMotionCurveSegment(l,d+2)),n+=1,d+=3;break}case O.CubismMotionSegmentType_Bezier:{this._motionData.segments[o].segmentType=O.CubismMotionSegmentType_Bezier,i||Mi?this._motionData.segments[o].evaluate=Ci:this._motionData.segments[o].evaluate=Si,this._motionData.points[n]=new z(e.getMotionCurveSegment(l,d+1),e.getMotionCurveSegment(l,d+2)),this._motionData.points[n+1]=new z(e.getMotionCurveSegment(l,d+3),e.getMotionCurveSegment(l,d+4)),this._motionData.points[n+2]=new z(e.getMotionCurveSegment(l,d+5),e.getMotionCurveSegment(l,d+6)),n+=3,d+=7;break}case O.CubismMotionSegmentType_Stepped:{this._motionData.segments[o].segmentType=O.CubismMotionSegmentType_Stepped,this._motionData.segments[o].evaluate=bi,this._motionData.points[n]=new z(e.getMotionCurveSegment(l,d+1),e.getMotionCurveSegment(l,d+2)),n+=1,d+=3;break}case O.CubismMotionSegmentType_InverseStepped:{this._motionData.segments[o].segmentType=O.CubismMotionSegmentType_InverseStepped,this._motionData.segments[o].evaluate=Ii,this._motionData.points[n]=new z(e.getMotionCurveSegment(l,d+1),e.getMotionCurveSegment(l,d+2)),n+=1,d+=3;break}}++h.segmentCount,++o}this._motionData.curves.push(h)}for(let l=0;l<e.getEventCount();++l)this._motionData.events[l].fireTime=e.getEventTime(l),this._motionData.events[l].value=e.getEventValue(l);e.release()}getFiredEvent(t,e){this._firedEventValues.length=0;for(let i=0;i<this._motionData.eventCount;++i)this._motionData.events[i].fireTime>t&&this._motionData.events[i].fireTime<=e&&this._firedEventValues.push(this._motionData.events[i].value);return this._firedEventValues}}class wi extends Mt{constructor(t,e){var i;super(t,e),this.groups={idle:"Idle"},this.motionDataType="json",this.queueManager=new be,this.definitions=(i=t.motions)!=null?i:{},this.eyeBlinkIds=t.getEyeBlinkParameters()||[],this.lipSyncIds=t.getLipSyncParameters()||[],this.init(e)}init(t){super.init(t),this.settings.expressions&&(this.expressionManager=new di(this.settings,t)),this.queueManager.setEventCallback((e,i,r)=>{this.emit("motion:"+i)})}isFinished(){return this.queueManager.isFinished()}_startMotion(t,e){return t.setFinishedMotionHandler(e),this.queueManager.stopAllMotions(),this.queueManager.startMotion(t,!1,performance.now())}_stopAllMotions(){this.queueManager.stopAllMotions()}createMotion(t,e,i){const r=zt.create(t),a=new we(t),n=(e===this.groups.idle?w.idleMotionFadingDuration:w.motionFadingDuration)/1e3;return a.getMotionFadeInTime()===void 0&&r.setFadeInTime(i.FadeInTime>0?i.FadeInTime:n),a.getMotionFadeOutTime()===void 0&&r.setFadeOutTime(i.FadeOutTime>0?i.FadeOutTime:n),r.setEffectIds(this.eyeBlinkIds,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}}const Ti="ParamAngleX",Li="ParamAngleY",Ei="ParamAngleZ",Fi="ParamEyeBallX",Di="ParamEyeBallY",Ai="ParamBodyAngleX",Bi="ParamBreath";class Xt{constructor(){this._breathParameters=[],this._currentTime=0}static create(){return new Xt}setParameters(t){this._breathParameters=t}getParameters(){return this._breathParameters}updateParameters(t,e){this._currentTime+=e;const i=this._currentTime*2*3.14159;for(let r=0;r<this._breathParameters.length;++r){const a=this._breathParameters[r];t.addParameterValueById(a.parameterId,a.offset+a.peak*Math.sin(i/a.cycle),a.weight)}}}class ki{constructor(t,e,i,r,a){this.parameterId=t??void 0,this.offset=e??0,this.peak=i??0,this.cycle=r??0,this.weight=a??0}}const Ft=class{static create(s){return new Ft(s)}setBlinkingInterval(s){this._blinkingIntervalSeconds=s}setBlinkingSetting(s,t,e){this._closingSeconds=s,this._closedSeconds=t,this._openingSeconds=e}setParameterIds(s){this._parameterIds=s}getParameterIds(){return this._parameterIds}updateParameters(s,t){this._userTimeSeconds+=t;let e,i=0;switch(this._blinkingState){case A.EyeState_Closing:i=this._userTimeSeconds/this._closingSeconds,i>=1&&(i=1,this._blinkingState=A.EyeState_Closed,this._userTimeSeconds=0),e=1-i;break;case A.EyeState_Closed:i=this._userTimeSeconds/this._closedSeconds,i>=1&&(this._blinkingState=A.EyeState_Opening,this._userTimeSeconds=0),e=0;break;case A.EyeState_Opening:i=this._userTimeSeconds/this._openingSeconds,i>=1&&(i=1,this._blinkingState=A.EyeState_Interval,this._nextBlinkingTime=this.determinNextBlinkingTiming(),this._userTimeSeconds=0),e=i;break;case A.EyeState_Interval:this._nextBlinkingTime<this._userTimeSeconds&&(this._blinkingState=A.EyeState_Closing,this._userTimeSeconds=0),e=1;break;case A.EyeState_First:default:this._blinkingState=A.EyeState_Interval,this._nextBlinkingTime=this.determinNextBlinkingTiming(),e=1;break}Ft.CloseIfZero||(e=-e);for(let r=0;r<this._parameterIds.length;++r){const a=this._parameterIds[r];typeof a=="string"&&s.setParameterValueById(a,e)}}constructor(s){var t,e;this._blinkingState=A.EyeState_First,this._nextBlinkingTime=0,this._stateStartTimeSeconds=0,this._blinkingIntervalSeconds=4,this._blinkingIntervalRandomSeconds=1,this._closingSeconds=.1,this._closedSeconds=.05,this._openingSeconds=.15,this._userTimeSeconds=0,this._parameterIds=[],s!=null&&(this._parameterIds=(e=(t=s.getEyeBlinkParameters())==null?void 0:t.slice())!=null?e:this._parameterIds)}determinNextBlinkingTiming(){let s=this._blinkingIntervalSeconds;return s+=(Math.random()*2-1)*this._blinkingIntervalRandomSeconds,s=Math.max(s,0),s}};let Te=Ft;Te.CloseIfZero=!0;var A=(s=>(s[s.EyeState_First=0]="EyeState_First",s[s.EyeState_Interval=1]="EyeState_Interval",s[s.EyeState_Closing=2]="EyeState_Closing",s[s.EyeState_Closed=3]="EyeState_Closed",s[s.EyeState_Opening=4]="EyeState_Opening",s))(A||{});class Dt{constructor(t=0,e=0,i=0,r=0){this.x=t,this.y=e,this.width=i,this.height=r}getCenterX(){return this.x+.5*this.width}getCenterY(){return this.y+.5*this.height}getRight(){return this.x+this.width}getBottom(){return this.y+this.height}setRect(t){this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height}expand(t,e){this.x-=t,this.y-=e,this.width+=t*2,this.height+=e*2}}const Tt=4,Ri=10;let H,ht,At;class Lt{getChannelFlagAsColor(t){return this._channelColors[t]}getMaskRenderTexture(){let t=0;if(this._maskTexture&&this._maskTexture.texture!=0&&(this._maskTexture.frameNo=this._currentFrameNo,t=this._maskTexture.texture),t==0){const e=this._clippingMaskBufferSize;this._colorBuffer=this.gl.createTexture(),this.gl.bindTexture(this.gl.TEXTURE_2D,this._colorBuffer),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,e,e,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),t=this.gl.createFramebuffer(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this._colorBuffer,0),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,At),this._maskTexture=new Oi(this._currentFrameNo,t)}return t}setGL(t){this.gl=t}calcClippedDrawTotalBounds(t,e){let i=Number.MAX_VALUE,r=Number.MAX_VALUE,a=Number.MIN_VALUE,n=Number.MIN_VALUE;const o=e._clippedDrawableIndexList.length;for(let l=0;l<o;l++){const h=e._clippedDrawableIndexList[l],u=t.getDrawableVertexCount(h),c=t.getDrawableVertices(h);let d=Number.MAX_VALUE,_=Number.MAX_VALUE,p=Number.MIN_VALUE,v=Number.MIN_VALUE;const m=u*It.vertexStep;for(let g=It.vertexOffset;g<m;g+=It.vertexStep){const f=c[g],x=c[g+1];f<d&&(d=f),f>p&&(p=f),x<_&&(_=x),x>v&&(v=x)}if(d!=Number.MAX_VALUE)if(d<i&&(i=d),_<r&&(r=_),p>a&&(a=p),v>n&&(n=v),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 g=a-i,f=n-r;e._allClippedDrawRect.x=i,e._allClippedDrawRect.y=r,e._allClippedDrawRect.width=g,e._allClippedDrawRect.height=f}}}constructor(){this._maskRenderTexture=null,this._colorBuffer=null,this._currentFrameNo=0,this._clippingMaskBufferSize=256,this._clippingContextListForMask=[],this._clippingContextListForDraw=[],this._channelColors=[],this._tmpBoundsOnModel=new Dt,this._tmpMatrix=new k,this._tmpMatrixForMask=new k,this._tmpMatrixForDraw=new k;let t=new ot;t.R=1,t.G=0,t.B=0,t.A=0,this._channelColors.push(t),t=new ot,t.R=0,t.G=1,t.B=0,t.A=0,this._channelColors.push(t),t=new ot,t.R=0,t.G=0,t.B=1,t.A=0,this._channelColors.push(t),t=new ot,t.R=0,t.G=0,t.B=0,t.A=1,this._channelColors.push(t)}release(){var t,e,i;const r=this;for(let a=0;a<this._clippingContextListForMask.length;a++)this._clippingContextListForMask[a]&&((t=this._clippingContextListForMask[a])==null||t.release());r._clippingContextListForMask=void 0,r._clippingContextListForDraw=void 0,this._maskTexture&&((e=this.gl)==null||e.deleteFramebuffer(this._maskTexture.texture),r._maskTexture=void 0),r._channelColors=void 0,(i=this.gl)==null||i.deleteTexture(this._colorBuffer),this._colorBuffer=null}initialize(t,e,i,r){for(let a=0;a<e;a++){if(r[a]<=0){this._clippingContextListForDraw.push(null);continue}let n=this.findSameClip(i[a],r[a]);n==null&&(n=new Ui(this,i[a],r[a]),this._clippingContextListForMask.push(n)),n.addClippedDrawable(a),this._clippingContextListForDraw.push(n)}}setupClippingContext(t,e){this._currentFrameNo++;let i=0;for(let r=0;r<this._clippingContextListForMask.length;r++){const a=this._clippingContextListForMask[r];this.calcClippedDrawTotalBounds(t,a),a._isUsing&&i++}if(i>0){this.gl.viewport(0,0,this._clippingMaskBufferSize,this._clippingMaskBufferSize),this._maskRenderTexture=this.getMaskRenderTexture(),e.getMvpMatrix(),e.preDraw(),this.setupLayoutBounds(i),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._maskRenderTexture),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT);for(let r=0;r<this._clippingContextListForMask.length;r++){const a=this._clippingContextListForMask[r],n=a._allClippedDrawRect,o=a._layoutBounds,l=.05;this._tmpBoundsOnModel.setRect(n),this._tmpBoundsOnModel.expand(n.width*l,n.height*l);const h=o.width/this._tmpBoundsOnModel.width,u=o.height/this._tmpBoundsOnModel.height;this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(o.x,o.y),this._tmpMatrix.scaleRelative(h,u),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForMask.setMatrix(this._tmpMatrix.getArray()),this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(o.x,o.y),this._tmpMatrix.scaleRelative(h,u),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForDraw.setMatrix(this._tmpMatrix.getArray()),a._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),a._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray());const c=a._clippingIdCount;for(let d=0;d<c;d++){const _=a._clippingIdList[d];t.getDrawableDynamicFlagVertexPositionsDidChange(_)&&(e.setIsCulling(t.getDrawableCulling(_)!=!1),e.setClippingContextBufferForMask(a),e.drawMesh(t.getDrawableTextureIndices(_),t.getDrawableVertexIndexCount(_),t.getDrawableVertexCount(_),t.getDrawableVertexIndices(_),t.getDrawableVertices(_),t.getDrawableVertexUvs(_),t.getDrawableOpacity(_),X.CubismBlendMode_Normal,!1))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,At),e.setClippingContextBufferForMask(null),this.gl.viewport(ht[0],ht[1],ht[2],ht[3])}}findSameClip(t,e){for(let i=0;i<this._clippingContextListForMask.length;i++){const r=this._clippingContextListForMask[i],a=r._clippingIdCount;if(a!=e)continue;let n=0;for(let o=0;o<a;o++){const l=r._clippingIdList[o];for(let h=0;h<a;h++)if(t[h]==l){n++;break}}if(n==a)return r}return null}setupLayoutBounds(t){let e=t/Tt,i=t%Tt;e=~~e,i=~~i;let r=0;for(let a=0;a<Tt;a++){const n=e+(a<i?1:0);if(n!=0)if(n==1){const o=this._clippingContextListForMask[r++];o._layoutChannelNo=a,o._layoutBounds.x=0,o._layoutBounds.y=0,o._layoutBounds.width=1,o._layoutBounds.height=1}else if(n==2)for(let o=0;o<n;o++){let l=o%2;l=~~l;const h=this._clippingContextListForMask[r++];h._layoutChannelNo=a,h._layoutBounds.x=l*.5,h._layoutBounds.y=0,h._layoutBounds.width=.5,h._layoutBounds.height=1}else if(n<=4)for(let o=0;o<n;o++){let l=o%2,h=o/2;l=~~l,h=~~h;const u=this._clippingContextListForMask[r++];u._layoutChannelNo=a,u._layoutBounds.x=l*.5,u._layoutBounds.y=h*.5,u._layoutBounds.width=.5,u._layoutBounds.height=.5}else if(n<=9)for(let o=0;o<n;o++){let l=o%3,h=o/3;l=~~l,h=~~h;const u=this._clippingContextListForMask[r++];u._layoutChannelNo=a,u._layoutBounds.x=l/3,u._layoutBounds.y=h/3,u._layoutBounds.width=1/3,u._layoutBounds.height=1/3}else if(ct.supportMoreMaskDivisions&&n<=16)for(let o=0;o<n;o++){let l=o%4,h=o/4;l=~~l,h=~~h;const u=this._clippingContextListForMask[r++];u._layoutChannelNo=a,u._layoutBounds.x=l/4,u._layoutBounds.y=h/4,u._layoutBounds.width=1/4,u._layoutBounds.height=1/4}else et("not supported mask count : {0}",n)}}getColorBuffer(){return this._colorBuffer}getClippingContextListForDraw(){return this._clippingContextListForDraw}setClippingMaskBufferSize(t){this._clippingMaskBufferSize=t}getClippingMaskBufferSize(){return this._clippingMaskBufferSize}}class Oi{constructor(t,e){this.frameNo=t,this.texture=e}}class Ui{constructor(t,e,i){this._isUsing=!1,this._owner=t,this._clippingIdList=e,this._clippingIdCount=i,this._allClippedDrawRect=new Dt,this._layoutBounds=new Dt,this._clippedDrawableIndexList=[],this._matrixForMask=new k,this._matrixForDraw=new k}release(){const t=this;t._layoutBounds=void 0,t._allClippedDrawRect=void 0,t._clippedDrawableIndexList=void 0}addClippedDrawable(t){this._clippedDrawableIndexList.push(t)}getClippingManager(){return this._owner}setGl(t){this._owner.setGL(t)}}class st{static getInstance(){return H==null&&(H=new st),H}static deleteInstance(){H&&(H.release(),H=void 0)}constructor(){this._shaderSets=[]}release(){this.releaseShaderProgram()}setupShaderProgram(t,e,i,r,a,n,o,l,h,u,c,d,_){c||et("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders();let p,v,m,g;const f=t.getClippingContextBufferForMask();if(f!=null){const x=this._shaderSets[ut.ShaderNames_SetupMask];this.gl.useProgram(x.shaderProgram),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(x.samplerTexture0Location,0),o.vertex==null&&(o.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,o.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,r,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(x.attributePositionLocation),this.gl.vertexAttribPointer(x.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),o.uv==null&&(o.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,o.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(x.attributeTexCoordLocation),this.gl.vertexAttribPointer(x.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0);const M=f._layoutChannelNo,T=f.getClippingManager().getChannelFlagAsColor(M);this.gl.uniform4f(x.uniformChannelFlagLocation,T.R,T.G,T.B,T.A),this.gl.uniformMatrix4fv(x.uniformClipMatrixLocation,!1,f._matrixForMask.getArray());const P=f._layoutBounds;this.gl.uniform4f(x.uniformBaseColorLocation,P.x*2-1,P.y*2-1,P.getRight()*2-1,P.getBottom()*2-1),p=this.gl.ZERO,v=this.gl.ONE_MINUS_SRC_COLOR,m=this.gl.ZERO,g=this.gl.ONE_MINUS_SRC_ALPHA}else{const x=t.getClippingContextBufferForDraw(),T=x!=null?_?2:1:0;let P;switch(h){case X.CubismBlendMode_Normal:default:P=this._shaderSets[ut.ShaderNames_NormalPremultipliedAlpha+T],p=this.gl.ONE,v=this.gl.ONE_MINUS_SRC_ALPHA,m=this.gl.ONE,g=this.gl.ONE_MINUS_SRC_ALPHA;break;case X.CubismBlendMode_Additive:P=this._shaderSets[ut.ShaderNames_AddPremultipliedAlpha+T],p=this.gl.ONE,v=this.gl.ONE,m=this.gl.ZERO,g=this.gl.ONE;break;case X.CubismBlendMode_Multiplicative:P=this._shaderSets[ut.ShaderNames_MultPremultipliedAlpha+T],p=this.gl.DST_COLOR,v=this.gl.ONE_MINUS_SRC_ALPHA,m=this.gl.ZERO,g=this.gl.ONE;break}if(this.gl.useProgram(P.shaderProgram),o.vertex==null&&(o.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,o.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,r,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(P.attributePositionLocation),this.gl.vertexAttribPointer(P.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),o.uv==null&&(o.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,o.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(P.attributeTexCoordLocation),this.gl.vertexAttribPointer(P.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),x!=null){this.gl.activeTexture(this.gl.TEXTURE1);const V=x.getClippingManager().getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,V),this.gl.uniform1i(P.samplerTexture1Location,1),this.gl.uniformMatrix4fv(P.uniformClipMatrixLocation,!1,x._matrixForDraw.getArray());const qt=x._layoutChannelNo,N=x.getClippingManager().getChannelFlagAsColor(qt);this.gl.uniform4f(P.uniformChannelFlagLocation,N.R,N.G,N.B,N.A)}this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(P.samplerTexture0Location,0),this.gl.uniformMatrix4fv(P.uniformMatrixLocation,!1,d.getArray()),this.gl.uniform4f(P.uniformBaseColorLocation,u.R,u.G,u.B,u.A)}o.index==null&&(o.index=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,o.index),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,a,this.gl.DYNAMIC_DRAW),this.gl.blendFuncSeparate(p,v,m,g)}releaseShaderProgram(){for(let t=0;t<this._shaderSets.length;t++)this.gl.deleteProgram(this._shaderSets[t].shaderProgram),this._shaderSets[t].shaderProgram=0;this._shaderSets=[]}generateShaders(){for(let t=0;t<Ri;t++)this._shaderSets.push({});this._shaderSets[0].shaderProgram=this.loadShaderProgram(Vi,Ni),this._shaderSets[1].shaderProgram=this.loadShaderProgram(Gi,zi),this._shaderSets[2].shaderProgram=this.loadShaderProgram(oe,Xi),this._shaderSets[3].shaderProgram=this.loadShaderProgram(oe,ji),this._shaderSets[4].shaderProgram=this._shaderSets[1].shaderProgram,this._shaderSets[5].shaderProgram=this._shaderSets[2].shaderProgram,this._shaderSets[6].shaderProgram=this._shaderSets[3].shaderProgram,this._shaderSets[7].shaderProgram=this._shaderSets[1].shaderProgram,this._shaderSets[8].shaderProgram=this._shaderSets[2].shaderProgram,this._shaderSets[9].shaderProgram=this._shaderSets[3].shaderProgram,this._shaderSets[0].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[0].shaderProgram,"a_position"),this._shaderSets[0].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[0].shaderProgram,"a_texCoord"),this._shaderSets[0].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"s_texture0"),this._shaderSets[0].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_clipMatrix"),this._shaderSets[0].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_channelFlag"),this._shaderSets[0].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_baseColor"),this._shaderSets[1].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[1].shaderProgram,"a_position"),this._shaderSets[1].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[1].shaderProgram,"a_texCoord"),this._shaderSets[1].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"s_texture0"),this._shaderSets[1].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_matrix"),this._shaderSets[1].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_baseColor"),this._shaderSets[2].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[2].shaderProgram,"a_position"),this._shaderSets[2].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[2].shaderProgram,"a_texCoord"),this._shaderSets[2].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"s_texture0"),this._shaderSets[2].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"s_texture1"),this._shaderSets[2].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_matrix"),this._shaderSets[2].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_clipMatrix"),this._shaderSets[2].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_channelFlag"),this._shaderSets[2].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_baseColor"),this._shaderSets[3].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[3].shaderProgram,"a_position"),this._shaderSets[3].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[3].shaderProgram,"a_texCoord"),this._shaderSets[3].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"s_texture0"),this._shaderSets[3].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"s_texture1"),this._shaderSets[3].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_matrix"),this._shaderSets[3].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_clipMatrix"),this._shaderSets[3].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_channelFlag"),this._shaderSets[3].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_baseColor"),this._shaderSets[4].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[4].shaderProgram,"a_position"),this._shaderSets[4].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[4].shaderProgram,"a_texCoord"),this._shaderSets[4].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"s_texture0"),this._shaderSets[4].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_matrix"),this._shaderSets[4].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_baseColor"),this._shaderSets[5].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[5].shaderProgram,"a_position"),this._shaderSets[5].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[5].shaderProgram,"a_texCoord"),this._shaderSets[5].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"s_texture0"),this._shaderSets[5].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"s_texture1"),this._shaderSets[5].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_matrix"),this._shaderSets[5].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_clipMatrix"),this._shaderSets[5].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_channelFlag"),this._shaderSets[5].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_baseColor"),this._shaderSets[6].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[6].shaderProgram,"a_position"),this._shaderSets[6].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[6].shaderProgram,"a_texCoord"),this._shaderSets[6].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"s_texture0"),this._shaderSets[6].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"s_texture1"),this._shaderSets[6].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_matrix"),this._shaderSets[6].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_clipMatrix"),this._shaderSets[6].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_channelFlag"),this._shaderSets[6].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_baseColor"),this._shaderSets[7].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[7].shaderProgram,"a_position"),this._shaderSets[7].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[7].shaderProgram,"a_texCoord"),this._shaderSets[7].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"s_texture0"),this._shaderSets[7].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_matrix"),this._shaderSets[7].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_baseColor"),this._shaderSets[8].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[8].shaderProgram,"a_position"),this._shaderSets[8].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[8].shaderProgram,"a_texCoord"),this._shaderSets[8].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"s_texture0"),this._shaderSets[8].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"s_texture1"),this._shaderSets[8].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_matrix"),this._shaderSets[8].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_clipMatrix"),this._shaderSets[8].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_channelFlag"),this._shaderSets[8].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_baseColor"),this._shaderSets[9].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[9].shaderProgram,"a_position"),this._shaderSets[9].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[9].shaderProgram,"a_texCoord"),this._shaderSets[9].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"s_texture0"),this._shaderSets[9].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"s_texture1"),this._shaderSets[9].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_matrix"),this._shaderSets[9].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_clipMatrix"),this._shaderSets[9].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_channelFlag"),this._shaderSets[9].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_baseColor")}loadShaderProgram(t,e){let i=this.gl.createProgram(),r=this.compileShaderSource(this.gl.VERTEX_SHADER,t);if(!r)return et("Vertex shader compile error!"),0;let a=this.compileShaderSource(this.gl.FRAGMENT_SHADER,e);return a?(this.gl.attachShader(i,r),this.gl.attachShader(i,a),this.gl.linkProgram(i),this.gl.getProgramParameter(i,this.gl.LINK_STATUS)?(this.gl.deleteShader(r),this.gl.deleteShader(a),i):(et("Failed to link program: {0}",i),this.gl.deleteShader(r),this.gl.deleteShader(a),i&&this.gl.deleteProgram(i),0)):(et("Vertex shader compile error!"),0)}compileShaderSource(t,e){const i=e,r=this.gl.createShader(t);if(this.gl.shaderSource(r,i),this.gl.compileShader(r),!r){const n=this.gl.getShaderInfoLog(r);et("Shader compile log: {0} ",n)}return this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS)?r:(this.gl.deleteShader(r),null)}setGl(t){this.gl=t}}var ut=(s=>(s[s.ShaderNames_SetupMask=0]="ShaderNames_SetupMask",s[s.ShaderNames_NormalPremultipliedAlpha=1]="ShaderNames_NormalPremultipliedAlpha",s[s.ShaderNames_NormalMaskedPremultipliedAlpha=2]="ShaderNames_NormalMaskedPremultipliedAlpha",s[s.ShaderNames_NomralMaskedInvertedPremultipliedAlpha=3]="ShaderNames_NomralMaskedInvertedPremultipliedAlpha",s[s.ShaderNames_AddPremultipliedAlpha=4]="ShaderNames_AddPremultipliedAlpha",s[s.ShaderNames_AddMaskedPremultipliedAlpha=5]="ShaderNames_AddMaskedPremultipliedAlpha",s[s.ShaderNames_AddMaskedPremultipliedAlphaInverted=6]="ShaderNames_AddMaskedPremultipliedAlphaInverted",s[s.ShaderNames_MultPremultipliedAlpha=7]="ShaderNames_MultPremultipliedAlpha",s[s.ShaderNames_MultMaskedPremultipliedAlpha=8]="ShaderNames_MultMaskedPremultipliedAlpha",s[s.ShaderNames_MultMaskedPremultipliedAlphaInverted=9]="ShaderNames_MultMaskedPremultipliedAlphaInverted",s))(ut||{});const Vi="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;}",Ni="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;}",Gi="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;}",oe="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;}",zi="precision mediump float;varying vec2 v_texCoord;uniform vec4 u_baseColor;uniform sampler2D s_texture0;void main(){ gl_FragColor = texture2D(s_texture0 , v_texCoord) * u_baseColor;}",Xi="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;void main(){ vec4 col_formask = texture2D(s_texture0 , v_texCoord) * 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;}",ji="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;void main(){vec4 col_formask = texture2D(s_texture0, v_texCoord) * 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;}";class Le extends Vt{constructor(){super(),this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._clippingManager=new Lt,this.firstDraw=!0,this._textures={},this._sortedDrawableIndexList=[],this._bufferData={vertex:null,uv:null,index:null}}initialize(t){t.isUsingMasking()&&(this._clippingManager=new Lt,this._clippingManager.initialize(t,t.getDrawableCount(),t.getDrawableMasks(),t.getDrawableMaskCounts()));for(let e=t.getDrawableCount()-1;e>=0;e--)this._sortedDrawableIndexList[e]=0;super.initialize(t)}bindTexture(t,e){this._textures[t]=e}getBindedTextures(){return this._textures}setClippingMaskBufferSize(t){this._clippingManager.release(),this._clippingManager=new Lt,this._clippingManager.setClippingMaskBufferSize(t),this._clippingManager.initialize(this.getModel(),this.getModel().getDrawableCount(),this.getModel().getDrawableMasks(),this.getModel().getDrawableMaskCounts())}getClippingMaskBufferSize(){return this._clippingManager.getClippingMaskBufferSize()}release(){var t,e,i;const r=this;this._clippingManager.release(),r._clippingManager=void 0,(t=this.gl)==null||t.deleteBuffer(this._bufferData.vertex),this._bufferData.vertex=null,(e=this.gl)==null||e.deleteBuffer(this._bufferData.uv),this._bufferData.uv=null,(i=this.gl)==null||i.deleteBuffer(this._bufferData.index),this._bufferData.index=null,r._bufferData=void 0,r._textures=void 0}doDrawModel(){this.preDraw(),this._clippingManager!=null&&this._clippingManager.setupClippingContext(this.getModel(),this);const t=this.getModel().getDrawableCount(),e=this.getModel().getDrawableRenderOrders();for(let i=0;i<t;++i){const r=e[i];this._sortedDrawableIndexList[r]=i}for(let i=0;i<t;++i){const r=this._sortedDrawableIndexList[i];this.getModel().getDrawableDynamicFlagIsVisible(r)&&(this.setClippingContextBufferForDraw(this._clippingManager!=null?this._clippingManager.getClippingContextListForDraw()[r]:null),this.setIsCulling(this.getModel().getDrawableCulling(r)),this.drawMesh(this.getModel().getDrawableTextureIndices(r),this.getModel().getDrawableVertexIndexCount(r),this.getModel().getDrawableVertexCount(r),this.getModel().getDrawableVertexIndices(r),this.getModel().getDrawableVertices(r),this.getModel().getDrawableVertexUvs(r),this.getModel().getDrawableOpacity(r),this.getModel().getDrawableBlendMode(r),this.getModel().getDrawableInvertedMaskBit(r)))}}drawMesh(t,e,i,r,a,n,o,l,h){this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW);const u=this.getModelColor();this.getClippingContextBufferForMask()==null&&(u.A*=o,this.isPremultipliedAlpha()&&(u.R*=u.A,u.G*=u.A,u.B*=u.A));let c=null;this._textures[t]!=null&&(c=this._textures[t]),st.getInstance().setupShaderProgram(this,c,i,a,r,n,this._bufferData,o,l,u,this.isPremultipliedAlpha(),this.getMvpMatrix(),h),this.gl.drawElements(this.gl.TRIANGLES,e,this.gl.UNSIGNED_SHORT,0),this.gl.useProgram(null),this.setClippingContextBufferForDraw(null),this.setClippingContextBufferForMask(null)}static doStaticRelease(){st.deleteInstance()}setRenderState(t,e){At=t,ht=e}preDraw(){this.firstDraw&&(this.firstDraw=!1,this._anisortopy=this.gl.getExtension("EXT_texture_filter_anisotropic")||this.gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this.gl.getExtension("MOZ_EXT_texture_filter_anisotropic")),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)}setClippingContextBufferForMask(t){this._clippingContextBufferForMask=t}getClippingContextBufferForMask(){return this._clippingContextBufferForMask}setClippingContextBufferForDraw(t){this._clippingContextBufferForDraw=t}getClippingContextBufferForDraw(){return this._clippingContextBufferForDraw}startUp(t){this.gl=t,this._clippingManager.setGL(t),st.getInstance().setGl(t)}}Vt.staticRelease=()=>{Le.doStaticRelease()};const le=new k;class Wi extends _e{constructor(t,e,i){super(),this.lipSync=!0,this.breath=Xt.create(),this.renderer=new Le,this.idParamAngleX=Ti,this.idParamAngleY=Li,this.idParamAngleZ=Ei,this.idParamEyeBallX=Fi,this.idParamEyeBallY=Di,this.idParamBodyAngleX=Ai,this.idParamBreath=Bi,this.pixelsPerUnit=1,this.centeringTransform=new ft,this.coreModel=t,this.settings=e,this.motionManager=new wi(e,i),this.init()}init(){var t;super.init(),((t=this.settings.getEyeBlinkParameters())==null?void 0:t.length)>0&&(this.eyeBlink=Te.create(this.settings)),this.breath.setParameters([new ki(this.idParamBreath,0,.5,3.2345,.5)]),this.renderer.initialize(this.coreModel),this.renderer.setIsPremultipliedAlpha(!0),this.setBlinkParam(pe)}getSize(){return[this.coreModel.getModel().canvasinfo.CanvasWidth,this.coreModel.getModel().canvasinfo.CanvasHeight]}getLayout(){const t={};if(this.settings.layout)for(const e of Object.keys(this.settings.layout)){const i=e.charAt(0).toLowerCase()+e.slice(1);t[i]=this.settings.layout[e]}return t}setupLayout(){super.setupLayout(),this.pixelsPerUnit=this.coreModel.getModel().canvasinfo.PixelsPerUnit,this.centeringTransform.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._currentFrameNo=e,this.renderer._clippingManager._maskTexture=void 0,st.getInstance()._shaderSets=[]}bindTexture(t,e){this.renderer.bindTexture(t,e)}getHitAreaDefs(){var t,e;return(e=(t=this.settings.hitAreas)==null?void 0:t.map(i=>({id:i.Id,name:i.Name,index:this.coreModel.getDrawableIndex(i.Id)})))!=null?e:[]}getDrawableIDs(){return this.coreModel.getDrawableIds()}getDrawableIndex(t){return this.coreModel.getDrawableIndex(t)}getDrawableVertices(t){if(typeof t=="string"&&(t=this.coreModel.getDrawableIndex(t),t===-1))throw new TypeError("Unable to find drawable ID: "+t);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.centeringTransform).prepend(this.localTransform).prepend(t)}update(t,e){var i,r,a,n;super.update(t,e),t/=1e3,e/=1e3;const o=this.coreModel;this.emit("beforeMotionUpdate");const l=this.motionManager.update(this.coreModel,e);this.emit("afterMotionUpdate"),o.saveParameters(),(i=this.motionManager.expressionManager)==null||i.update(o,e),l||(r=this.eyeBlink)==null||r.updateParameters(o,t),this.updateFocus(),this.updateNaturalMovements(t*1e3,e*1e3),(a=this.physics)==null||a.evaluate(o,t),(n=this.pose)==null||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,this.focusController.x*30),this.coreModel.addParameterValueById(this.idParamAngleY,this.focusController.y*30),this.coreModel.addParameterValueById(this.idParamAngleZ,this.focusController.x*this.focusController.y*-30),this.coreModel.addParameterValueById(this.idParamBodyAngleX,this.focusController.x*10)}updateNaturalMovements(t,e){var i;(i=this.breath)==null||i.updateParameters(this.coreModel,t/1e3)}draw(t){const e=this.drawingMatrix,i=le.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(le),this.renderer.setRenderState(t.getParameter(t.FRAMEBUFFER_BINDING),this.viewport),this.renderer.drawModel()}destroy(){super.destroy(),this.renderer.release(),this.coreModel.release(),this.renderer=void 0,this.coreModel=void 0}setBlinkParam(t){if(this.eyeBlink)try{this.eyeBlink._blinkingIntervalSeconds=t.blinkInterval/1e3,this.eyeBlink._blinkingIntervalRandomSeconds=t.blinkIntervalRandom/1e3,this.eyeBlink._closingSeconds=t.closingDuration/1e3,this.eyeBlink._closedSeconds=t.closedDuration/1e3,this.eyeBlink._openingSeconds=t.openingDuration/1e3,this.eyeBlink._nextBlinkingTime=this.eyeBlink.determinNextBlinkingTiming()}catch(e){console.error("Failed to set blink parameters:",e)}}}let pt,he=20;function Yi(){return gt.isStarted()?Promise.resolve():(pt??(pt=new Promise((s,t)=>{function e(){try{Hi(),s()}catch(i){if(he--,he<0){const r=new Error("Failed to start up Cubism 4 framework.");r.cause=i,t(r);return}C.log("Cubism4","Startup failed, retrying 10ms later..."),setTimeout(e,10)}}e()})),pt)}function Hi(s){s=Object.assign({logFunction:console.log,loggingLevel:K.LogLevel_Verbose},s),gt.startUp(s),gt.initialize()}const qi=.001,ue=.5;class jt{static create(t){const e=new jt;typeof t.FadeInTime=="number"&&(e._fadeTimeSeconds=t.FadeInTime,e._fadeTimeSeconds<=0&&(e._fadeTimeSeconds=ue));const i=t.Groups,r=i.length;for(let a=0;a<r;++a){const n=i[a],o=n.length;let l=0;for(let h=0;h<o;++h){const u=n[h],c=new xt;c.partId=u.Id;const d=u.Link;if(d){const _=d.length;for(let p=0;p<_;++p){const v=new xt;v.partId=d[p],c.link.push(v)}}e._partGroups.push(c),++l}e._partGroupCounts.push(l)}return e}updateParameters(t,e){t!=this._lastModel&&this.reset(t),this._lastModel=t,e<0&&(e=0);let i=0;for(let r=0;r<this._partGroupCounts.length;r++){const a=this._partGroupCounts[r];this.doFade(t,e,i,a),i+=a}this.copyPartOpacities(t)}reset(t){let e=0;for(let i=0;i<this._partGroupCounts.length;++i){const r=this._partGroupCounts[i];for(let a=e;a<e+r;++a){this._partGroups[a].initialize(t);const n=this._partGroups[a].partIndex,o=this._partGroups[a].parameterIndex;if(!(n<0)){t.setPartOpacityByIndex(n,a==e?1:0),t.setParameterValueByIndex(o,a==e?1:0);for(let l=0;l<this._partGroups[a].link.length;++l)this._partGroups[a].link[l].initialize(t)}}e+=r}}copyPartOpacities(t){for(let e=0;e<this._partGroups.length;++e){const i=this._partGroups[e];if(i.link.length==0)continue;const r=this._partGroups[e].partIndex,a=t.getPartOpacityByIndex(r);for(let n=0;n<i.link.length;++n){const l=i.link[n].partIndex;l<0||t.setPartOpacityByIndex(l,a)}}}doFade(t,e,i,r){let a=-1,n=1;const o=.5,l=.15;for(let h=i;h<i+r;++h){const u=this._partGroups[h].partIndex,c=this._partGroups[h].parameterIndex;if(t.getParameterValueByIndex(c)>qi){if(a>=0)break;a=h,n=t.getPartOpacityByIndex(u),n+=e/this._fadeTimeSeconds,n>1&&(n=1)}}a<0&&(a=0,n=1);for(let h=i;h<i+r;++h){const u=this._partGroups[h].partIndex;if(a==h)t.setPartOpacityByIndex(u,n);else{let c=t.getPartOpacityByIndex(u),d;n<o?d=n*(o-1)/o+1:d=(1-n)*o/(1-o),(1-d)*(1-n)>l&&(d=1-l/(1-n)),c>d&&(c=d),t.setPartOpacityByIndex(u,c)}}}constructor(){this._fadeTimeSeconds=ue,this._lastModel=void 0,this._partGroups=[],this._partGroupCounts=[]}}class xt{constructor(t){this.parameterIndex=0,this.partIndex=0,this.partId="",this.link=[],t!=null&&this.assignment(t)}assignment(t){return this.partId=t.partId,this.link=t.link.map(e=>e.clone()),this}initialize(t){this.parameterIndex=t.getParameterIndex(this.partId),this.partIndex=t.getPartIndex(this.partId),t.setParameterValueByIndex(this.parameterIndex,1)}clone(){const t=new xt;return t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=this.link.map(e=>e.clone()),t}}class $i{update(){this._model.update(),this._model.drawables.resetDynamicFlags()}getCanvasWidth(){return this._model==null?0:this._model.canvasinfo.CanvasWidth/this._model.canvasinfo.PixelsPerUnit}getCanvasHeight(){return this._model==null?0:this._model.canvasinfo.CanvasHeight/this._model.canvasinfo.PixelsPerUnit}saveParameters(){const t=this._model.parameters.count,e=this._savedParameters.length;for(let i=0;i<t;++i)i<e?this._savedParameters[i]=this._parameterValues[i]:this._savedParameters.push(this._parameterValues[i])}getModel(){return this._model}getPartIndex(t){let e;const i=this._model.parts.count;for(e=0;e<i;++e)if(t==this._partIds[e])return e;return t in this._notExistPartId?this._notExistPartId[t]:(e=i+this._notExistPartId.length,this._notExistPartId[t]=e,this._notExistPartOpacities[e]=0,e)}getPartCount(){return this._model.parts.count}setPartOpacityByIndex(t,e){if(t in this._notExistPartOpacities){this._notExistPartOpacities[t]=e;return}mt(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 t in this._notExistPartOpacities?this._notExistPartOpacities[t]:(mt(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[e])return e;return t in this._notExistParameterId?this._notExistParameterId[t]:(e=this._model.parameters.count+Object.keys(this._notExistParameterId).length,this._notExistParameterId[t]=e,this._notExistParameterValues[e]=0,e)}getParameterCount(){return this._model.parameters.count}getParameterMaximumValue(t){return this._model.parameters.maximumValues[t]}getParameterMinimumValue(t){return this._model.parameters.minimumValues[t]}getParameterDefaultValue(t){return this._model.parameters.defaultValues[t]}getParameterValueByIndex(t){return t in this._notExistParameterValues?this._notExistParameterValues[t]:(mt(0<=t&&t<this.getParameterCount()),this._parameterValues[t])}getParameterValueById(t){const e=this.getParameterIndex(t);return this.getParameterValueByIndex(e)}setParameterValueByIndex(t,e,i=1){if(t in this._notExistParameterValues){this._notExistParameterValues[t]=i==1?e:this._notExistParameterValues[t]*(1-i)+e*i;return}mt(0<=t&&t<this.getParameterCount()),this._model.parameters.maximumValues[t]<e&&(e=this._model.parameters.maximumValues[t]),this._model.parameters.minimumValues[t]>e&&(e=this._model.parameters.minimumValues[t]),this._parameterValues[t]=i==1?e:this._parameterValues[t]=this._parameterValues[t]*(1-i)+e*i}setParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.setParameterValueByIndex(r,e,i)}addParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)+e*i)}addParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.addParameterValueByIndex(r,e,i)}multiplyParameterValueById(t,e,i=1){const r=this.getParameterIndex(t);this.multiplyParameterValueByIndex(r,e,i)}multiplyParameterValueByIndex(t,e,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)*(1+(e-1)*i))}getDrawableIds(){return this._drawableIds.slice()}getDrawableIndex(t){const e=this._model.drawables.count;for(let i=0;i<e;++i)if(this._drawableIds[i]==t)return i;return-1}getDrawableCount(){return this._model.drawables.count}getDrawableId(t){return this._model.drawables.ids[t]}getDrawableRenderOrders(){return this._model.drawables.renderOrders}getDrawableTextureIndices(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]}getDrawableCulling(t){const e=this._model.drawables.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(e[t])}getDrawableBlendMode(t){const e=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(e[t])?X.CubismBlendMode_Additive:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(e[t])?X.CubismBlendMode_Multiplicative:X.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])}loadParameters(){let t=this._model.parameters.count;const e=this._savedParameters.length;t>e&&(t=e);for(let i=0;i<t;++i)this._parameterValues[i]=this._savedParameters[i]}initialize(){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;for(let i=0;i<e;++i)this._parameterIds.push(t[i])}{const t=this._model.parts.ids,e=this._model.parts.count;for(let i=0;i<e;++i)this._partIds.push(t[i])}{const t=this._model.drawables.ids,e=this._model.drawables.count;for(let i=0;i<e;++i)this._drawableIds.push(t[i])}}constructor(t){this._model=t,this._savedParameters=[],this._parameterIds=[],this._drawableIds=[],this._partIds=[],this._notExistPartId={},this._notExistParameterId={},this._notExistParameterValues={},this._notExistPartOpacities={},this.initialize()}release(){this._model.release(),this._model=void 0}}class Wt{static create(t){const e=Live2DCubismCore.Moc.fromArrayBuffer(t);if(e)return new Wt(e);throw new Error("Unknown error")}createModel(){let t;const e=Live2DCubismCore.Model.fromMoc(this._moc);if(e)return t=new $i(e),++this._modelCount,t;throw new Error("Unknown error")}deleteModel(t){t!=null&&--this._modelCount}constructor(t){this._moc=t,this._modelCount=0}release(){this._moc._release(),this._moc=void 0}}var Bt=(s=>(s[s.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",s))(Bt||{}),J=(s=>(s[s.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",s[s.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",s[s.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",s))(J||{});class Ji{constructor(){this.initialPosition=new y(0,0),this.position=new y(0,0),this.lastPosition=new y(0,0),this.lastGravity=new y(0,0),this.force=new y(0,0),this.velocity=new y(0,0)}}class Zi{constructor(){this.normalizationPosition={},this.normalizationAngle={}}}class Ki{constructor(){this.source={}}}class Qi{constructor(){this.destination={},this.translationScale=new y(0,0)}}class ts{constructor(){this.settings=[],this.inputs=[],this.outputs=[],this.particles=[],this.gravity=new y(0,0),this.wind=new y(0,0)}}class es{constructor(t){this._json=t}release(){this._json=void 0}getGravity(){const t=new y(0,0);return t.x=this._json.Meta.EffectiveForces.Gravity.X,t.y=this._json.Meta.EffectiveForces.Gravity.Y,t}getWind(){const t=new y(0,0);return t.x=this._json.Meta.EffectiveForces.Wind.X,t.y=this._json.Meta.EffectiveForces.Wind.Y,t}getSubRigCount(){return this._json.Meta.PhysicsSettingCount}getTotalInputCount(){return this._json.Meta.TotalInputCount}getTotalOutputCount(){return this._json.Meta.TotalOutputCount}getVertexCount(){return this._json.Meta.VertexCount}getNormalizationPositionMinimumValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Minimum}getNormalizationPositionMaximumValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Maximum}getNormalizationPositionDefaultValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Default}getNormalizationAngleMinimumValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Minimum}getNormalizationAngleMaximumValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Maximum}getNormalizationAngleDefaultValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Default}getInputCount(t){return this._json.PhysicsSettings[t].Input.length}getInputWeight(t,e){return this._json.PhysicsSettings[t].Input[e].Weight}getInputReflect(t,e){return this._json.PhysicsSettings[t].Input[e].Reflect}getInputType(t,e){return this._json.PhysicsSettings[t].Input[e].Type}getInputSourceId(t,e){return this._json.PhysicsSettings[t].Input[e].Source.Id}getOutputCount(t){return this._json.PhysicsSettings[t].Output.length}getOutputVertexIndex(t,e){return this._json.PhysicsSettings[t].Output[e].VertexIndex}getOutputAngleScale(t,e){return this._json.PhysicsSettings[t].Output[e].Scale}getOutputWeight(t,e){return this._json.PhysicsSettings[t].Output[e].Weight}getOutputDestinationId(t,e){return this._json.PhysicsSettings[t].Output[e].Destination.Id}getOutputType(t,e){return this._json.PhysicsSettings[t].Output[e].Type}getOutputReflect(t,e){return this._json.PhysicsSettings[t].Output[e].Reflect}getParticleCount(t){return this._json.PhysicsSettings[t].Vertices.length}getParticleMobility(t,e){return this._json.PhysicsSettings[t].Vertices[e].Mobility}getParticleDelay(t,e){return this._json.PhysicsSettings[t].Vertices[e].Delay}getParticleAcceleration(t,e){return this._json.PhysicsSettings[t].Vertices[e].Acceleration}getParticleRadius(t,e){return this._json.PhysicsSettings[t].Vertices[e].Radius}getParticlePosition(t,e){const i=new y(0,0);return i.x=this._json.PhysicsSettings[t].Vertices[e].Position.X,i.y=this._json.PhysicsSettings[t].Vertices[e].Position.Y,i}}const de="X",ce="Y",ge="Angle",is=5,Ee=100,ss=.001;class Yt{static create(t){const e=new Yt;return e.parse(t),e._physicsRig.gravity.y=0,e}evaluate(t,e){let i,r,a,n;const o=new y;let l,h,u,c,d,_,p,v;d=t.getModel().parameters.values,_=t.getModel().parameters.maximumValues,p=t.getModel().parameters.minimumValues,v=t.getModel().parameters.defaultValues;for(let m=0;m<this._physicsRig.subRigCount;++m){i={angle:0},o.x=0,o.y=0,l=this._physicsRig.settings[m],h=this._physicsRig.inputs.slice(l.baseInputIndex),u=this._physicsRig.outputs.slice(l.baseOutputIndex),c=this._physicsRig.particles.slice(l.baseParticleIndex);for(let g=0;g<l.inputCount;++g)r=h[g].weight/Ee,h[g].sourceParameterIndex==-1&&(h[g].sourceParameterIndex=t.getParameterIndex(h[g].source.id)),h[g].getNormalizedParameterValue(o,i,d[h[g].sourceParameterIndex],p[h[g].sourceParameterIndex],_[h[g].sourceParameterIndex],v[h[g].sourceParameterIndex],l.normalizationPosition,l.normalizationAngle,h[g].reflect,r);a=S.degreesToRadian(-i.angle),o.x=o.x*S.cos(a)-o.y*S.sin(a),o.y=o.x*S.sin(a)+o.y*S.cos(a),_s(c,l.particleCount,o,i.angle,this._options.wind,ss*l.normalizationPosition.maximum,e,is);for(let g=0;g<l.outputCount;++g){const f=u[g].vertexIndex;if(f<1||f>=l.particleCount)break;u[g].destinationParameterIndex==-1&&(u[g].destinationParameterIndex=t.getParameterIndex(u[g].destination.id));const x=new y;x.x=c[f].position.x-c[f-1].position.x,x.y=c[f].position.y-c[f-1].position.y,n=u[g].getValue(x,c,f,u[g].reflect,this._options.gravity);const M=u[g].destinationParameterIndex,T=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(d.subarray(M))):d.slice(M);fs(T,p[M],_[M],n,u[g]);for(let P=M,V=0;P<d.length;P++,V++)d[P]=T[V]}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._options=new rs,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0}release(){this._physicsRig=void 0}parse(t){this._physicsRig=new ts;let e=new es(t);this._physicsRig.gravity=e.getGravity(),this._physicsRig.wind=e.getWind(),this._physicsRig.subRigCount=e.getSubRigCount();let i=0,r=0,a=0;for(let n=0;n<this._physicsRig.subRigCount;++n){const o=new Zi;o.normalizationPosition.minimum=e.getNormalizationPositionMinimumValue(n),o.normalizationPosition.maximum=e.getNormalizationPositionMaximumValue(n),o.normalizationPosition.defalut=e.getNormalizationPositionDefaultValue(n),o.normalizationAngle.minimum=e.getNormalizationAngleMinimumValue(n),o.normalizationAngle.maximum=e.getNormalizationAngleMaximumValue(n),o.normalizationAngle.defalut=e.getNormalizationAngleDefaultValue(n),o.inputCount=e.getInputCount(n),o.baseInputIndex=i,i+=o.inputCount;for(let l=0;l<o.inputCount;++l){const h=new Ki;switch(h.sourceParameterIndex=-1,h.weight=e.getInputWeight(n,l),h.reflect=e.getInputReflect(n,l),e.getInputType(n,l)){case de:h.type=J.CubismPhysicsSource_X,h.getNormalizedParameterValue=as;break;case ce:h.type=J.CubismPhysicsSource_Y,h.getNormalizedParameterValue=ns;break;case ge:h.type=J.CubismPhysicsSource_Angle,h.getNormalizedParameterValue=os;break}h.source.targetType=Bt.CubismPhysicsTargetType_Parameter,h.source.id=e.getInputSourceId(n,l),this._physicsRig.inputs.push(h)}o.outputCount=e.getOutputCount(n),o.baseOutputIndex=r,r+=o.outputCount;for(let l=0;l<o.outputCount;++l){const h=new Qi;switch(h.destinationParameterIndex=-1,h.vertexIndex=e.getOutputVertexIndex(n,l),h.angleScale=e.getOutputAngleScale(n,l),h.weight=e.getOutputWeight(n,l),h.destination.targetType=Bt.CubismPhysicsTargetType_Parameter,h.destination.id=e.getOutputDestinationId(n,l),e.getOutputType(n,l)){case de:h.type=J.CubismPhysicsSource_X,h.getValue=ls,h.getScale=gs;break;case ce:h.type=J.CubismPhysicsSource_Y,h.getValue=hs,h.getScale=ms;break;case ge:h.type=J.CubismPhysicsSource_Angle,h.getValue=us,h.getScale=ps;break}h.reflect=e.getOutputReflect(n,l),this._physicsRig.outputs.push(h)}o.particleCount=e.getParticleCount(n),o.baseParticleIndex=a,a+=o.particleCount;for(let l=0;l<o.particleCount;++l){const h=new Ji;h.mobility=e.getParticleMobility(n,l),h.delay=e.getParticleDelay(n,l),h.acceleration=e.getParticleAcceleration(n,l),h.radius=e.getParticleRadius(n,l),h.position=e.getParticlePosition(n,l),this._physicsRig.particles.push(h)}this._physicsRig.settings.push(o)}this.initialize(),e.release()}initialize(){let t,e,i;for(let r=0;r<this._physicsRig.subRigCount;++r){e=this._physicsRig.settings[r],t=this._physicsRig.particles.slice(e.baseParticleIndex),t[0].initialPosition=new y(0,0),t[0].lastPosition=new y(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new y(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new y(0,0),t[0].force=new y(0,0);for(let a=1;a<e.particleCount;++a)i=new y(0,0),i.y=t[a].radius,t[a].initialPosition=new y(t[a-1].initialPosition.x+i.x,t[a-1].initialPosition.y+i.y),t[a].position=new y(t[a].initialPosition.x,t[a].initialPosition.y),t[a].lastPosition=new y(t[a].initialPosition.x,t[a].initialPosition.y),t[a].lastGravity=new y(0,-1),t[a].lastGravity.y*=-1,t[a].velocity=new y(0,0),t[a].force=new y(0,0)}}}class rs{constructor(){this.gravity=new y(0,0),this.wind=new y(0,0)}}function as(s,t,e,i,r,a,n,o,l,h){s.x+=Ht(e,i,r,a,n.minimum,n.maximum,n.defalut,l)*h}function ns(s,t,e,i,r,a,n,o,l,h){s.y+=Ht(e,i,r,a,n.minimum,n.maximum,n.defalut,l)*h}function os(s,t,e,i,r,a,n,o,l,h){t.angle+=Ht(e,i,r,a,o.minimum,o.maximum,o.defalut,l)*h}function ls(s,t,e,i,r){let a=s.x;return i&&(a*=-1),a}function hs(s,t,e,i,r){let a=s.y;return i&&(a*=-1),a}function us(s,t,e,i,r){let a;return e>=2?r=t[e-1].position.substract(t[e-2].position):r=r.multiplyByScaler(-1),a=S.directionToRadian(r,s),i&&(a*=-1),a}function ds(s,t){return Math.abs(Math.max(s,t)-Math.min(s,t))}function cs(s,t){return Math.min(s,t)+ds(s,t)/2}function gs(s,t){return s.x}function ms(s,t){return s.y}function ps(s,t){return t}function _s(s,t,e,i,r,a,n,o){let l,h,u,c,d=new y(0,0),_=new y(0,0),p=new y(0,0),v=new y(0,0);s[0].position=new y(e.x,e.y),l=S.degreesToRadian(i),c=S.radianToDirection(l),c.normalize();for(let m=1;m<t;++m)s[m].force=c.multiplyByScaler(s[m].acceleration).add(r),s[m].lastPosition=new y(s[m].position.x,s[m].position.y),h=s[m].delay*n*30,d=s[m].position.substract(s[m-1].position),u=S.directionToRadian(s[m].lastGravity,c)/o,d.x=S.cos(u)*d.x-d.y*S.sin(u),d.y=S.sin(u)*d.x+d.y*S.cos(u),s[m].position=s[m-1].position.add(d),_=s[m].velocity.multiplyByScaler(h),p=s[m].force.multiplyByScaler(h).multiplyByScaler(h),s[m].position=s[m].position.add(_).add(p),v=s[m].position.substract(s[m-1].position),v.normalize(),s[m].position=s[m-1].position.add(v.multiplyByScaler(s[m].radius)),S.abs(s[m].position.x)<a&&(s[m].position.x=0),h!=0&&(s[m].velocity=s[m].position.substract(s[m].lastPosition),s[m].velocity=s[m].velocity.divisionByScalar(h),s[m].velocity=s[m].velocity.multiplyByScaler(s[m].mobility)),s[m].force=new y(0,0),s[m].lastGravity=new y(c.x,c.y)}function fs(s,t,e,i,r){let a,n,o;a=r.getScale(r.translationScale,r.angleScale),n=i*a,n<t?(n<r.valueBelowMinimum&&(r.valueBelowMinimum=n),n=t):n>e&&(n>r.valueExceededMaximum&&(r.valueExceededMaximum=n),n=e),o=r.weight/Ee,o>=1||(n=s[0]*(1-o)+n*o),s[0]=n}function Ht(s,t,e,i,r,a,n,o){let l=0;const h=S.max(e,t);h<s&&(s=h);const u=S.min(e,t);u>s&&(s=u);const c=S.min(r,a),d=S.max(r,a),_=n,p=cs(u,h),v=s-p;switch(Math.sign(v)){case 1:{const m=d-_,g=h-p;g!=0&&(l=v*(m/g),l+=_);break}case-1:{const m=c-_,g=u-p;g!=0&&(l=v*(m/g),l+=_);break}case 0:{l=_;break}}return o?l:l*-1}b.registerRuntime({version:4,ready:Yi,test(s){return s instanceof it||it.isValidJSON(s)},isValidMoc(s){if(s.byteLength<4)return!1;const t=new Int8Array(s,0,4);return String.fromCharCode(...t)==="MOC3"},createModelSettings(s){return new it(s)},createCoreModel(s){const t=Wt.create(s);try{const e=t.createModel();return e.__moc=t,e}catch(e){try{t.release()}catch{}throw e}},createInternalModel(s,t,e){const i=new Wi(s,t,e),r=s;return r.__moc&&(i.__moc=r.__moc,delete r.__moc,i.once("destroy",ys)),i},createPhysics(s,t){return Yt.create(t)},createPose(s,t){return jt.create(t)}});function ys(){var s;(s=this.__moc)==null||s.release()}export{ei as Cubism2ExpressionManager,ri as Cubism2InternalModel,dt as Cubism2ModelSettings,ii as Cubism2MotionManager,di as Cubism4ExpressionManager,Wi as Cubism4InternalModel,it as Cubism4ModelSettings,wi as Cubism4MotionManager,Ot as ExpressionManager,Ut as FileLoader,ze as FocusController,$e as InteractionMixin,_e as InternalModel,Kt as LOGICAL_HEIGHT,Zt as LOGICAL_WIDTH,ti as Live2DExpression,si as Live2DEyeBlink,b as Live2DFactory,j as Live2DLoader,Ke as Live2DModel,oi as Live2DPhysics,li as Live2DPose,Je as Live2DTransform,vt as ModelSettings,Mt as MotionManager,Et as MotionPriority,Xe as MotionState,Z as SoundManager,Pt as XHRLoader,Ct as ZipLoader,me as applyMixins,pe as baseBlinkParam,yt as clamp,w as config,at as copyArray,rt as copyProperty,Yi as cubism4Ready,Ue as folderName,C as logger,Oe as rand,Ve as remove,Hi as startUpCubism4};
Binary file