cubism2.min.js 41 KB

1
  1. var __pow=Math.pow,__async=(t,e,s)=>new Promise(((i,r)=>{var o=t=>{try{a(s.next(t))}catch(e){r(e)}},n=t=>{try{a(s.throw(t))}catch(e){r(e)}},a=t=>t.done?i(t.value):Promise.resolve(t.value).then(o,n);a((s=s.apply(t,e)).next())}));!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@pixi/utils"),require("@pixi/math"),require("@pixi/core"),require("@pixi/display")):"function"==typeof define&&define.amd?define(["exports","@pixi/utils","@pixi/math","@pixi/core","@pixi/display"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).PIXI=t.PIXI||{},t.PIXI.live2d=t.PIXI.live2d||{}),t.PIXI.utils,t.PIXI,t.PIXI,t.PIXI)}(this,(function(t,e,s,i,r){"use strict";var o,n,a;(n=o||(o={})).supportMoreMaskDivisions=!0,n.setOpacityFromMotion=!1,t.config=void 0,(a=t.config||(t.config={})).LOG_LEVEL_VERBOSE=0,a.LOG_LEVEL_WARNING=1,a.LOG_LEVEL_ERROR=2,a.LOG_LEVEL_NONE=999,a.logLevel=a.LOG_LEVEL_WARNING,a.sound=!0,a.motionSync=!0,a.motionFadingDuration=500,a.idleMotionFadingDuration=2e3,a.expressionFadingDuration=500,a.preserveExpressionOnMotion=!0,a.cubism4=o;const l={log(e,...s){t.config.logLevel<=t.config.LOG_LEVEL_VERBOSE&&console.log(`[${e}]`,...s)},warn(e,...s){t.config.logLevel<=t.config.LOG_LEVEL_WARNING&&console.warn(`[${e}]`,...s)},error(e,...s){t.config.logLevel<=t.config.LOG_LEVEL_ERROR&&console.error(`[${e}]`,...s)}};function d(t,e,s){return t<e?e:t>s?s:t}function h(t,e){return Math.random()*(e-t)+t}function c(t,e,s,i,r){const o=e[i];null!==o&&typeof o===t&&(s[r]=o)}function u(t,e,s,i,r){const o=e[i];Array.isArray(o)&&(s[r]=o.filter((e=>null!==e&&typeof e===t)))}function p(t,e){e.forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((s=>{"constructor"!==s&&Object.defineProperty(t.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s))}))}))}function g(t){let e=t.lastIndexOf("/");return-1!=e&&(t=t.slice(0,e)),e=t.lastIndexOf("/"),-1!==e&&(t=t.slice(e+1)),t}function m(t,e){const s=t.indexOf(e);-1!==s&&t.splice(s,1)}class f extends e.EventEmitter{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 __async(this,null,(function*(){if(!this.definitions[t])return void l.warn(this.tag,`Undefined expression at [${t}]`);if(null===this.expressions[t])return void l.warn(this.tag,`Cannot set expression at [${t}] because it's already failed in loading.`);if(this.expressions[t])return this.expressions[t];const e=yield this._loadExpression(t);return this.expressions[t]=e,e}))}_loadExpression(t){throw new Error("Not implemented.")}setRandomExpression(){return __async(this,null,(function*(){if(this.definitions.length){const t=[];for(let e=0;e<this.definitions.length;e++)null!==this.expressions[e]&&this.expressions[e]!==this.currentExpression&&e!==this.reserveExpressionIndex&&t.push(e);if(t.length){const e=Math.floor(Math.random()*t.length);return this.setExpression(e)}}return!1}))}resetExpression(){this._setExpression(this.defaultExpression)}restoreExpression(){this._setExpression(this.currentExpression)}setExpression(t){return __async(this,null,(function*(){if("number"!=typeof t&&(t=this.getExpressionIndex(t)),!(t>-1&&t<this.definitions.length))return!1;if(t===this.expressions.indexOf(this.currentExpression))return!1;this.reserveExpressionIndex=t;const e=yield this.loadExpression(t);return!(!e||this.reserveExpressionIndex!==t)&&(this.reserveExpressionIndex=-1,this.currentExpression=e,this._setExpression(e),!0)}))}update(t,e){return!this.isFinished()&&this.updateParameters(t,e)}destroy(){this.destroyed=!0,this.emit("destroy");this.definitions=void 0,this.expressions=void 0}}class y{constructor(){this.targetX=0,this.targetY=0,this.x=0,this.y=0,this.vx=0,this.vy=0}focus(t,e,s=!1){this.targetX=d(t,-1,1),this.targetY=d(e,-1,1),s&&(this.x=this.targetX,this.y=this.targetY)}update(t){const e=this.targetX-this.x,s=this.targetY-this.y;if(Math.abs(e)<.01&&Math.abs(s)<.01)return;const i=Math.sqrt(__pow(e,2)+__pow(s,2)),r=5.333333333333333/(1e3/t);let o=r*(e/i)-this.vx,n=r*(s/i)-this.vy;const a=Math.sqrt(__pow(o,2)+__pow(n,2)),l=.006666666666666667*r*t;a>l&&(o*=l/a,n*=l/a),this.vx+=o,this.vy+=n;const d=Math.sqrt(__pow(this.vx,2)+__pow(this.vy,2)),h=.5*(Math.sqrt(__pow(l,2)+8*l*i)-l);d>h&&(this.vx*=h/d,this.vy*=h/d),this.x+=this.vx,this.y+=this.vy}}class M{constructor(t){this.json=t;let e=t.url;if("string"!=typeof e)throw new TypeError("The `url` field in settings JSON must be defined as a string.");this.url=e,this.name=g(this.url)}resolveURL(t){return e.url.resolve(this.url,t)}replaceFiles(t){this.moc=t(this.moc,"moc"),void 0!==this.pose&&(this.pose=t(this.pose,"pose")),void 0!==this.physics&&(this.physics=t(this.physics,"physics"));for(let e=0;e<this.textures.length;e++)this.textures[e]=t(this.textures[e],`textures[${e}]`)}getDefinedFiles(){const t=[];return this.replaceFiles((e=>(t.push(e),e))),t}validateFiles(t){const e=(e,s)=>{const i=this.resolveURL(e);if(!t.includes(i)){if(s)throw new Error(`File "${e}" is defined in settings, but doesn't exist in given files`);return!1}return!0};[this.moc,...this.textures].forEach((t=>e(t,!0)));return this.getDefinedFiles().filter((t=>e(t,!1)))}}var x=(t=>(t[t.NONE=0]="NONE",t[t.IDLE=1]="IDLE",t[t.NORMAL=2]="NORMAL",t[t.FORCE=3]="FORCE",t))(x||{});class v{constructor(){this.debug=!1,this.currentPriority=0,this.reservePriority=0}reserve(t,e,s){if(s<=0)return l.log(this.tag,"Cannot start a motion with MotionPriority.NONE."),!1;if(t===this.currentGroup&&e===this.currentIndex)return l.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 l.log(this.tag,"Motion is already reserved.",this.dump(t,e)),!1;if(1===s){if(0!==this.currentPriority)return l.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(t,e)),!1;if(void 0!==this.reservedIdleGroup)return l.log(this.tag,"Cannot start idle motion because another idle motion has reserved.",this.dump(t,e)),!1;this.setReservedIdle(t,e)}else{if(s<3){if(s<=this.currentPriority)return l.log(this.tag,"Cannot start motion because another motion is playing as an equivalent or higher priority.",this.dump(t,e)),!1;if(s<=this.reservePriority)return l.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,s)}return!0}start(t,e,s,i){if(1===i){if(this.setReservedIdle(void 0,void 0),0!==this.currentPriority)return l.log(this.tag,"Cannot start idle motion because another motion is playing.",this.dump(e,s)),!1}else{if(e!==this.reservedGroup||s!==this.reservedIndex)return l.log(this.tag,"Cannot start motion because another motion has taken the place.",this.dump(e,s)),!1;this.setReserved(void 0,void 0,0)}return!!t&&(this.setCurrent(e,s,i),!0)}complete(){this.setCurrent(void 0,void 0,0)}setCurrent(t,e,s){this.currentPriority=s,this.currentGroup=t,this.currentIndex=e}setReserved(t,e,s){this.reservePriority=s,this.reservedGroup=t,this.reservedIndex=e}setReservedIdle(t,e){this.reservedIdleGroup=t,this.reservedIdleIndex=e}isActive(t,e){return t===this.currentGroup&&e===this.currentIndex||t===this.reservedGroup&&e===this.reservedIndex||t===this.reservedIdleGroup&&e===this.reservedIdleIndex}reset(){this.setCurrent(void 0,void 0,0),this.setReserved(void 0,void 0,0),this.setReservedIdle(void 0,void 0)}shouldRequestIdleMotion(){return void 0===this.currentGroup&&void 0===this.reservedIdleGroup}shouldOverrideExpression(){return!t.config.preserveExpressionOnMotion&&this.currentPriority>1}dump(t,e){if(this.debug){return`\n<Requested> group = "${t}", index = ${e}\n`+["currentPriority","reservePriority","currentGroup","currentIndex","reservedGroup","reservedIndex","reservedIdleGroup","reservedIdleIndex"].map((t=>"["+t+"] "+this[t])).join("\n")}return""}}class P{static get volume(){return this._volume}static set volume(t){this._volume=(t>1?1:t<0?0:t)||0,this.audios.forEach((t=>t.volume=this._volume))}static add(t,e,s){const i=new Audio(t);return i.volume=this._volume,i.preload="auto",i.addEventListener("ended",(()=>{this.dispose(i),null==e||e()})),i.addEventListener("error",(e=>{this.dispose(i),l.warn("SoundManager",`Error occurred on "${t}"`,e.error),null==s||s(e.error)})),this.audios.push(i),i}static play(t){return new Promise(((e,s)=>{var i;null==(i=t.play())||i.catch((e=>{t.dispatchEvent(new ErrorEvent("error",{error:e})),s(e)})),t.readyState===t.HAVE_ENOUGH_DATA?e():t.addEventListener("canplaythrough",e)}))}static dispose(t){t.pause(),t.removeAttribute("src"),m(this.audios,t)}static destroy(){for(let t=this.audios.length-1;t>=0;t--)this.dispose(this.audios[t])}}P.audios=[],P._volume=.5;var w=(t=>(t.ALL="ALL",t.IDLE="IDLE",t.NONE="NONE",t))(w||{});class _ extends e.EventEmitter{constructor(t,e){super(),this.motionGroups={},this.state=new v,this.playing=!1,this.destroyed=!1,this.settings=t,this.tag=`MotionManager(${t.name})`,this.state.tag=this.tag}init(t){(null==t?void 0:t.idleMotionGroup)&&(this.groups.idle=t.idleMotionGroup),this.setupMotions(t),this.stopAllMotions()}setupMotions(t){for(const s of Object.keys(this.definitions))this.motionGroups[s]=[];let e;switch(null==t?void 0:t.motionPreload){case"NONE":return;case"ALL":e=Object.keys(this.definitions);break;default:e=[this.groups.idle]}for(const s of e)if(this.definitions[s])for(let t=0;t<this.definitions[s].length;t++)this.loadMotion(s,t).then()}loadMotion(t,e){return __async(this,null,(function*(){var s;if(!(null==(s=this.definitions[t])?void 0:s[e]))return void l.warn(this.tag,`Undefined motion at "${t}"[${e}]`);if(null===this.motionGroups[t][e])return void l.warn(this.tag,`Cannot start motion at "${t}"[${e}] because it's already failed in loading.`);if(this.motionGroups[t][e])return this.motionGroups[t][e];const i=yield this._loadMotion(t,e);return this.destroyed?void 0:(this.motionGroups[t][e]=null!=i?i:null,i)}))}_loadMotion(t,e){throw new Error("Not implemented.")}startMotion(e,s){return __async(this,arguments,(function*(e,s,i=x.NORMAL){var r;if(!this.state.reserve(e,s,i))return!1;const o=null==(r=this.definitions[e])?void 0:r[s];if(!o)return!1;let n;if(this.currentAudio&&P.dispose(this.currentAudio),t.config.sound){const t=this.getSoundFile(o);if(t)try{n=P.add(this.settings.resolveURL(t),(()=>this.currentAudio=void 0),(()=>this.currentAudio=void 0)),this.currentAudio=n}catch(d){l.warn(this.tag,"Failed to create audio",t,d)}}const a=yield this.loadMotion(e,s);if(n){const e=P.play(n).catch((t=>l.warn(this.tag,"Failed to play audio",n.src,t)));t.config.motionSync&&(yield e)}return this.state.start(a,e,s,i)?(l.log(this.tag,"Start motion:",this.getMotionName(o)),this.emit("motionStart",e,s,n),this.state.shouldOverrideExpression()&&this.expressionManager&&this.expressionManager.resetExpression(),this.playing=!0,this._startMotion(a),!0):(n&&(P.dispose(n),this.currentAudio=void 0),!1)}))}startRandomMotion(t,e){return __async(this,null,(function*(){const s=this.definitions[t];if(null==s?void 0:s.length){const i=[];for(let e=0;e<s.length;e++)null===this.motionGroups[t][e]||this.state.isActive(t,e)||i.push(e);if(i.length){const s=Math.floor(Math.random()*i.length);return this.startMotion(t,i[s],e)}}return!1}))}stopAllMotions(){this._stopAllMotions(),this.state.reset(),this.currentAudio&&(P.dispose(this.currentAudio),this.currentAudio=void 0)}update(t,e){var s;return this.isFinished()&&(this.playing&&(this.playing=!1,this.emit("motionFinish")),this.state.shouldOverrideExpression()&&(null==(s=this.expressionManager)||s.restoreExpression()),this.state.complete(),this.state.shouldRequestIdleMotion()&&this.startRandomMotion(this.groups.idle,x.IDLE)),this.updateParameters(t,e)}destroy(){var t;this.destroyed=!0,this.emit("destroy"),this.stopAllMotions(),null==(t=this.expressionManager)||t.destroy();this.definitions=void 0,this.motionGroups=void 0}}const E={x:0,y:0,width:0,height:0};class I extends e.EventEmitter{constructor(){super(...arguments),this.focusController=new y,this.originalWidth=0,this.originalHeight=0,this.width=0,this.height=0,this.localTransform=new s.Matrix,this.drawingMatrix=new s.Matrix,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 s=Object.assign({width:2,height:2},this.getLayout());this.localTransform.scale(s.width/2,s.height/2),t.width=this.originalWidth*this.localTransform.a,t.height=this.originalHeight*this.localTransform.d;const i=void 0!==s.x&&s.x-s.width/2||void 0!==s.centerX&&s.centerX||void 0!==s.left&&s.left-s.width/2||void 0!==s.right&&s.right+s.width/2||0,r=void 0!==s.y&&s.y-s.height/2||void 0!==s.centerY&&s.centerY||void 0!==s.top&&s.top-s.height/2||void 0!==s.bottom&&s.bottom+s.height/2||0;this.localTransform.translate(this.width*i,-this.height*r)}setupHitAreas(){const t=this.getHitAreaDefs().filter((t=>t.index>=0));for(const e of t)this.hitAreas[e.name]=e}hitTest(t,e){return Object.keys(this.hitAreas).filter((s=>this.isHit(s,t,e)))}isHit(t,e,s){if(!this.hitAreas[t])return!1;const i=this.hitAreas[t].index,r=this.getDrawableBounds(i,E);return r.x<=e&&e<=r.x+r.width&&r.y<=s&&s<=r.y+r.height}getDrawableBounds(t,e){const s=this.getDrawableVertices(t);let i=s[0],r=s[0],o=s[1],n=s[1];for(let a=0;a<s.length;a+=2){const t=s[a],e=s[a+1];i=Math.min(t,i),r=Math.max(t,r),o=Math.min(e,o),n=Math.max(e,n)}return null!=e||(e={}),e.x=i,e.y=o,e.width=r-i,e.height=n-o,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}}class L extends Error{constructor(t,e,s,i=!1){super(t),this.url=e,this.status=s,this.aborted=i}}const b=class{static createXHR(t,e,s,i,r){const o=new XMLHttpRequest;if(b.allXhrSet.add(o),t){let e=b.xhrMap.get(t);e?e.add(o):(e=new Set([o]),b.xhrMap.set(t,e)),t.listeners("destroy").includes(b.cancelXHRs)||t.once("destroy",b.cancelXHRs)}return o.open("GET",e),o.responseType=s,o.onload=()=>{200!==o.status&&0!==o.status||!o.response?o.onerror():i(o.response)},o.onerror=()=>{l.warn("XHRLoader",`Failed to load resource as ${o.responseType} (Status ${o.status}): ${e}`),r(new L("Network error.",e,o.status))},o.onabort=()=>r(new L("Aborted.",e,o.status,!0)),o.onloadend=()=>{var e;b.allXhrSet.delete(o),t&&(null==(e=b.xhrMap.get(t))||e.delete(o))},o}static cancelXHRs(){var t;null==(t=b.xhrMap.get(this))||t.forEach((t=>{t.abort(),b.allXhrSet.delete(t)})),b.xhrMap.delete(this)}static release(){b.allXhrSet.forEach((t=>t.abort())),b.allXhrSet.clear(),b.xhrMap=new WeakMap}};let T=b;function O(t,e){let s=-1;return function i(r,o){if(o)return Promise.reject(o);if(r<=s)return Promise.reject(new Error("next() called multiple times"));s=r;const n=t[r];if(!n)return Promise.resolve();try{return Promise.resolve(n(e,i.bind(null,r+1)))}catch(a){return Promise.reject(a)}}(0)}T.xhrMap=new WeakMap,T.allXhrSet=new Set,T.loader=(t,e)=>new Promise(((e,s)=>{b.createXHR(t.target,t.settings?t.settings.resolveURL(t.url):t.url,t.type,(s=>{t.result=s,e()}),s).send()}));class R{static load(t){return O(this.middlewares,t).then((()=>t.result))}}R.middlewares=[T.loader];const F="Live2DFactory",A=(t,e)=>__async(this,null,(function*(){if("string"==typeof t.source){const e=yield R.load({url:t.source,type:"json",target:t.live2dModel});e.url=t.source,t.source=e,t.live2dModel.emit("settingsJSONLoaded",e)}return e()})),D=(t,e)=>__async(this,null,(function*(){if(t.source instanceof M)return t.settings=t.source,e();if("object"==typeof t.source){const s=N.findRuntime(t.source);if(s){const i=s.createModelSettings(t.source);return t.settings=i,t.live2dModel.emit("settingsLoaded",i),e()}}throw new TypeError("Unknown settings format.")})),C=(t,e)=>{if(t.settings){const s=N.findRuntime(t.settings);if(s)return s.ready().then(e)}return e()},S=(t,e)=>__async(this,null,(function*(){yield e();const s=t.internalModel;if(s){const e=t.settings,i=N.findRuntime(e);if(i){const r=[];e.pose&&r.push(R.load({settings:e,url:e.pose,type:"json",target:s}).then((e=>{s.pose=i.createPose(s.coreModel,e),t.live2dModel.emit("poseLoaded",s.pose)})).catch((e=>{t.live2dModel.emit("poseLoadError",e),l.warn(F,"Failed to load pose.",e)}))),e.physics&&r.push(R.load({settings:e,url:e.physics,type:"json",target:s}).then((e=>{s.physics=i.createPhysics(s.coreModel,e),t.live2dModel.emit("physicsLoaded",s.physics)})).catch((e=>{t.live2dModel.emit("physicsLoadError",e),l.warn(F,"Failed to load physics.",e)}))),r.length&&(yield Promise.all(r))}}})),G=(t,e)=>__async(this,null,(function*(){if(!t.settings)throw new TypeError("Missing settings.");{const s=t.live2dModel,r=t.settings.textures.map((e=>function(t,e={}){const s={resourceOptions:{crossorigin:e.crossOrigin}};if(i.Texture.fromURL)return i.Texture.fromURL(t,s).catch((t=>{if(t instanceof Error)throw t;const e=new Error("Texture loading error");throw e.event=t,e}));s.resourceOptions.autoLoad=!1;const r=i.Texture.from(t,s);if(r.baseTexture.valid)return Promise.resolve(r);const o=r.baseTexture.resource;return null!=o._live2d_load||(o._live2d_load=new Promise(((t,e)=>{const s=t=>{o.source.removeEventListener("error",s);const i=new Error("Texture loading error");i.event=t,e(i)};o.source.addEventListener("error",s),o.load().then((()=>t(r))).catch(s)}))),o._live2d_load}(t.settings.resolveURL(e),{crossOrigin:t.options.crossOrigin})));if(yield e(),!t.internalModel)throw new TypeError("Missing internal model.");s.internalModel=t.internalModel,s.emit("modelLoaded",t.internalModel),s.textures=yield Promise.all(r),s.emit("textureLoaded",s.textures)}})),U=(t,e)=>__async(this,null,(function*(){const s=t.settings;if(s instanceof M){const i=N.findRuntime(s);if(!i)throw new TypeError("Unknown model settings.");const r=yield R.load({settings:s,url:s.moc,type:"arraybuffer",target:t.live2dModel});if(!i.isValidMoc(r))throw new Error("Invalid moc data");const o=i.createCoreModel(r);return t.internalModel=i.createInternalModel(o,s,t.options),e()}throw new TypeError("Missing settings.")})),k=class{static registerRuntime(t){k.runtimes.push(t),k.runtimes.sort(((t,e)=>e.version-t.version))}static findRuntime(t){for(const e of k.runtimes)if(e.test(t))return e}static setupLive2DModel(t,e,s){return __async(this,null,(function*(){const i=new Promise((e=>t.once("textureLoaded",e))),r=new Promise((e=>t.once("modelLoaded",e))),o=Promise.all([i,r]).then((()=>t.emit("ready")));yield O(k.live2DModelMiddlewares,{live2dModel:t,source:e,options:s||{}}),yield o,t.emit("load")}))}static loadMotion(t,e,s){var i;const r=i=>t.emit("motionLoadError",e,s,i);try{const o=null==(i=t.definitions[e])?void 0:i[s];if(!o)return Promise.resolve(void 0);t.listeners("destroy").includes(k.releaseTasks)||t.once("destroy",k.releaseTasks);let n=k.motionTasksMap.get(t);n||(n={},k.motionTasksMap.set(t,n));let a=n[e];a||(a=[],n[e]=a);const d=t.getMotionFile(o);return null!=a[s]||(a[s]=R.load({url:d,settings:t.settings,type:t.motionDataType,target:t}).then((i=>{var r;const n=null==(r=k.motionTasksMap.get(t))?void 0:r[e];n&&delete n[s];const a=t.createMotion(i,e,o);return t.emit("motionLoaded",e,s,a),a})).catch((e=>{l.warn(t.tag,`Failed to load motion: ${d}\n`,e),r(e)}))),a[s]}catch(o){l.warn(t.tag,`Failed to load motion at "${e}"[${s}]\n`,o),r(o)}return Promise.resolve(void 0)}static loadExpression(t,e){const s=s=>t.emit("expressionLoadError",e,s);try{const i=t.definitions[e];if(!i)return Promise.resolve(void 0);t.listeners("destroy").includes(k.releaseTasks)||t.once("destroy",k.releaseTasks);let r=k.expressionTasksMap.get(t);r||(r=[],k.expressionTasksMap.set(t,r));const o=t.getExpressionFile(i);return null!=r[e]||(r[e]=R.load({url:o,settings:t.settings,type:"json",target:t}).then((s=>{const r=k.expressionTasksMap.get(t);r&&delete r[e];const o=t.createExpression(s,i);return t.emit("expressionLoaded",e,o),o})).catch((e=>{l.warn(t.tag,`Failed to load expression: ${o}\n`,e),s(e)}))),r[e]}catch(i){l.warn(t.tag,`Failed to load expression at [${e}]\n`,i),s(i)}return Promise.resolve(void 0)}static releaseTasks(){this instanceof _?k.motionTasksMap.delete(this):k.expressionTasksMap.delete(this)}};let N=k;N.runtimes=[],N.urlToJSON=A,N.jsonToSettings=D,N.waitUntilReady=C,N.setupOptionals=S,N.setupEssentials=G,N.createInternalModel=U,N.live2DModelMiddlewares=[A,D,C,S,G,U],N.motionTasksMap=new WeakMap,N.expressionTasksMap=new WeakMap,_.prototype._loadMotion=function(t,e){return N.loadMotion(this,t,e)},f.prototype._loadExpression=function(t){return N.loadExpression(this,t)};class j{constructor(){this._autoInteract=!1}get autoInteract(){return this._autoInteract}set autoInteract(t){t!==this._autoInteract&&(t?this.on("pointertap",X,this):this.off("pointertap",X,this),this._autoInteract=t)}registerInteraction(t){t!==this.interactionManager&&(this.unregisterInteraction(),this._autoInteract&&t&&(this.interactionManager=t,t.on("pointermove",H,this)))}unregisterInteraction(){var t;this.interactionManager&&(null==(t=this.interactionManager)||t.off("pointermove",H,this),this.interactionManager=void 0)}}function X(t){this.tap(t.data.global.x,t.data.global.y)}function H(t){this.focus(t.data.global.x,t.data.global.y)}class W extends s.Transform{}const $=new s.Point,V=new s.Matrix;let q;class B extends r.Container{constructor(t){super(),this.tag="Live2DModel(uninitialized)",this.textures=[],this.transform=new W,this.anchor=new s.ObservablePoint(this.onAnchorChange,this,0,0),this.glContextID=-1,this.elapsedTime=performance.now(),this.deltaTime=0,this._autoUpdate=!1,this.once("modelLoaded",(()=>this.init(t)))}static from(t,e){const s=new this(e);return N.setupLive2DModel(s,t,e).then((()=>s))}static fromSync(t,e){const s=new this(e);return N.setupLive2DModel(s,t,e).then(null==e?void 0:e.onLoad).catch(null==e?void 0:e.onError),s}static registerTicker(t){q=t}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){var e;q||(q=null==(e=window.PIXI)?void 0:e.Ticker),t?this._destroyed||(q?(q.shared.add(this.onTickerUpdate,this),this._autoUpdate=!0):l.warn(this.tag,"No Ticker registered, please call Live2DModel.registerTicker(Ticker).")):(null==q||q.shared.remove(this.onTickerUpdate,this),this._autoUpdate=!1)}init(t){this.tag=`Live2DModel(${this.internalModel.settings.name})`;const e=Object.assign({autoUpdate:!0,autoInteract:!0},t);e.autoInteract&&(this.interactive=!0),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,s){return void 0===e?this.internalModel.motionManager.startRandomMotion(t,s):this.internalModel.motionManager.startMotion(t,e,s)}expression(t){return this.internalModel.motionManager.expressionManager?void 0===t?this.internalModel.motionManager.expressionManager.setRandomExpression():this.internalModel.motionManager.expressionManager.setExpression(t):Promise.resolve(!1)}focus(t,e,s=!1){$.x=t,$.y=e,this.toModelPosition($,$,!0);let i=$.x/this.internalModel.originalWidth*2-1,r=$.y/this.internalModel.originalHeight*2-1,o=Math.atan2(r,i);this.internalModel.focusController.focus(Math.cos(o),-Math.sin(o),s)}tap(t,e){const s=this.hitTest(t,e);s.length&&(l.log(this.tag,"Hit",s),this.emit("hit",s))}hitTest(t,e){return $.x=t,$.y=e,this.toModelPosition($,$),this.internalModel.hitTest($.x,$.y)}toModelPosition(t,e=t.clone(),s){return s||(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,0,0,this.internalModel.width,this.internalModel.height)}onTickerUpdate(){this.update(q.shared.deltaMS)}update(t){this.deltaTime+=t,this.elapsedTime+=t}_render(t){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 r=0;r<this.textures.length;r++){const s=this.textures[r];s.valid&&(!e&&s.baseTexture._glTextures[this.glContextID]||(t.gl.pixelStorei(WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL,this.internalModel.textureFlipY),t.texture.bind(s.baseTexture,0)),this.internalModel.bindTexture(r,s.baseTexture._glTextures[this.glContextID].texture),s.baseTexture.touched=t.textureGC.count)}const s=t.framebuffer.viewport;this.internalModel.viewport=[s.x,s.y,s.width,s.height],this.deltaTime&&(this.internalModel.update(this.deltaTime,this.elapsedTime),this.deltaTime=0);const i=V.copyFrom(t.globalUniforms.uniforms.projectionMatrix).append(this.worldTransform);this.internalModel.updateTransform(i),this.internalModel.draw(t.gl),t.state.reset(),t.texture.reset()}destroy(t){this.emit("destroy"),this.autoUpdate=!1,this.unregisterInteraction(),(null==t?void 0:t.texture)&&this.textures.forEach((e=>e.destroy(t.baseTexture))),this.internalModel.destroy(),super.destroy(t)}}p(B,[j]);const Y=class{static resolveURL(t,e){var s;const i=null==(s=Y.filesMap[t])?void 0:s[e];if(void 0===i)throw new Error("Cannot find this file from uploaded files: "+e);return i}static upload(t,s){return __async(this,null,(function*(){const i={};for(const r of s.getDefinedFiles()){const o=decodeURI(e.url.resolve(s.url,r)),n=t.find((t=>t.webkitRelativePath===o));n&&(i[r]=URL.createObjectURL(n))}Y.filesMap[s._objectURL]=i}))}static createSettings(t){return __async(this,null,(function*(){const e=t.find((t=>t.name.endsWith("model.json")||t.name.endsWith("model3.json")));if(!e)throw new TypeError("Settings file not found");const s=yield Y.readText(e),i=JSON.parse(s);i.url=e.webkitRelativePath;const r=N.findRuntime(i);if(!r)throw new Error("Unknown settings JSON");const o=r.createModelSettings(i);return o._objectURL=URL.createObjectURL(e),o}))}static readText(t){return __async(this,null,(function*(){return new Promise(((e,s)=>{const i=new FileReader;i.onload=()=>e(i.result),i.onerror=s,i.readAsText(t,"utf8")}))}))}};let z=Y;z.filesMap={},z.factory=(t,e)=>__async(this,null,(function*(){if(Array.isArray(t.source)&&t.source[0]instanceof File){const e=t.source;let s=e.settings;if(s){if(!s._objectURL)throw new Error('"_objectURL" must be specified in ModelSettings')}else s=yield Y.createSettings(e);s.validateFiles(e.map((t=>encodeURI(t.webkitRelativePath)))),yield Y.upload(e,s),s.resolveURL=function(t){return Y.resolveURL(this._objectURL,t)},t.source=s,t.live2dModel.once("modelLoaded",(t=>{t.once("destroy",(function(){const t=this.settings._objectURL;if(URL.revokeObjectURL(t),Y.filesMap[t])for(const e of Object.values(Y.filesMap[t]))URL.revokeObjectURL(e);delete Y.filesMap[t]}))}))}return e()})),N.live2DModelMiddlewares.unshift(z.factory);const J=class{static unzip(t,s){return __async(this,null,(function*(){const i=yield J.getFilePaths(t),r=[];for(const t of s.getDefinedFiles()){const o=decodeURI(e.url.resolve(s.url,t));i.includes(o)&&r.push(o)}const o=yield J.getFiles(t,r);for(let t=0;t<o.length;t++){const e=r[t],s=o[t];Object.defineProperty(s,"webkitRelativePath",{value:e})}return o}))}static createSettings(t){return __async(this,null,(function*(){const e=(yield J.getFilePaths(t)).find((t=>t.endsWith("model.json")||t.endsWith("model3.json")));if(!e)throw new Error("Settings file not found");const s=yield J.readText(t,e);if(!s)throw new Error("Empty settings file: "+e);const i=JSON.parse(s);i.url=e;const r=N.findRuntime(i);if(!r)throw new Error("Unknown settings JSON");return r.createModelSettings(i)}))}static zipReader(t,e){return __async(this,null,(function*(){throw new Error("Not implemented")}))}static getFilePaths(t){return __async(this,null,(function*(){throw new Error("Not implemented")}))}static getFiles(t,e){return __async(this,null,(function*(){throw new Error("Not implemented")}))}static readText(t,e){return __async(this,null,(function*(){throw new Error("Not implemented")}))}static releaseReader(t){}};let Z=J;if(Z.ZIP_PROTOCOL="zip://",Z.uid=0,Z.factory=(t,e)=>__async(this,null,(function*(){const s=t.source;let i,r,o;if("string"==typeof s&&(s.endsWith(".zip")||s.startsWith(J.ZIP_PROTOCOL))?(i=s.startsWith(J.ZIP_PROTOCOL)?s.slice(J.ZIP_PROTOCOL.length):s,r=yield R.load({url:i,type:"blob",target:t.live2dModel})):Array.isArray(s)&&1===s.length&&s[0]instanceof File&&s[0].name.endsWith(".zip")&&(r=s[0],i=URL.createObjectURL(r),o=s.settings),r){if(!r.size)throw new Error("Empty zip file");const e=yield J.zipReader(r,i);o||(o=yield J.createSettings(e)),o._objectURL=J.ZIP_PROTOCOL+J.uid+"/"+o.url;const s=yield J.unzip(e,o);s.settings=o,t.source=s,i.startsWith("blob:")&&t.live2dModel.once("modelLoaded",(t=>{t.once("destroy",(function(){URL.revokeObjectURL(i)}))})),J.releaseReader(e)}return e()})),N.live2DModelMiddlewares.unshift(Z.factory),!window.Live2D)throw new Error("Could not find Cubism 2 runtime. This plugin requires live2d.min.js to be loaded.");const Q=Live2DMotion.prototype.updateParam;Live2DMotion.prototype.updateParam=function(t,e){Q.call(this,t,e),e.isFinished()&&this.onFinishHandler&&(this.onFinishHandler(this),delete this.onFinishHandler)};class K extends AMotion{constructor(e){super(),this.params=[],this.setFadeIn(e.fade_in>0?e.fade_in:t.config.expressionFadingDuration),this.setFadeOut(e.fade_out>0?e.fade_out:t.config.expressionFadingDuration),Array.isArray(e.params)&&e.params.forEach((t=>{const e=t.calc||"add";if("add"===e){const e=t.def||0;t.val-=e}else if("mult"===e){const e=t.def||1;t.val/=e}this.params.push({calc:e,val:t.val,id:t.id})}))}updateParamExe(t,e,s,i){this.params.forEach((e=>{t.setParamFloat(e.id,e.val*s)}))}}class tt extends f{constructor(t,e){var s;super(t,e),this.queueManager=new MotionQueueManager,this.definitions=null!=(s=this.settings.expressions)?s:[],this.init()}isFinished(){return this.queueManager.isFinished()}getExpressionIndex(t){return this.definitions.findIndex((e=>e.name===t))}getExpressionFile(t){return t.file}createExpression(t,e){return new K(t)}_setExpression(t){return this.queueManager.startMotion(t)}stopAllExpressions(){this.queueManager.stopAllMotions()}updateParameters(t,e){return this.queueManager.updateParam(t)}}class et extends _{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 tt(this.settings,t))}isFinished(){return this.queueManager.isFinished()}createMotion(e,s,i){const r=Live2DMotion.loadMotion(e),o=s===this.groups.idle?t.config.idleMotionFadingDuration:t.config.motionFadingDuration;return r.setFadeIn(i.fade_in>0?i.fade_in:o),r.setFadeOut(i.fade_out>0?i.fade_out:o),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 st{constructor(t){this.coreModel=t,this.blinkInterval=4e3,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")}setEyeParams(t){this.eyeParamValue=d(t,0,1),this.coreModel.setParamFloat(this.leftParam,this.eyeParamValue),this.coreModel.setParamFloat(this.rightParam,this.eyeParamValue)}update(t){switch(this.eyeState){case 0:this.nextBlinkTimeLeft-=t,this.nextBlinkTimeLeft<0&&(this.eyeState=1,this.nextBlinkTimeLeft=this.blinkInterval+this.closingDuration+this.closedDuration+this.openingDuration+h(0,2e3));break;case 1:this.setEyeParams(this.eyeParamValue+t/this.closingDuration),this.eyeParamValue<=0&&(this.eyeState=2,this.closedTimer=0);break;case 2:this.closedTimer+=t,this.closedTimer>=this.closedDuration&&(this.eyeState=3);break;case 3:this.setEyeParams(this.eyeParamValue+t/this.openingDuration),this.eyeParamValue>=1&&(this.eyeState=0)}}}const it=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);class rt extends I{constructor(t,e,s){super(),this.textureFlipY=!0,this.drawDataCount=0,this.disableCulling=!1,this.coreModel=t,this.settings=e,this.motionManager=new et(e,s),this.eyeBlink=new st(t),this.eyeballXParamIndex=t.getParamIndex("PARAM_EYE_BALL_X"),this.eyeballYParamIndex=t.getParamIndex("PARAM_EYE_BALL_Y"),this.angleXParamIndex=t.getParamIndex("PARAM_ANGLE_X"),this.angleYParamIndex=t.getParamIndex("PARAM_ANGLE_Y"),this.angleZParamIndex=t.getParamIndex("PARAM_ANGLE_Z"),this.bodyAngleXParamIndex=t.getParamIndex("PARAM_BODY_ANGLE_X"),this.breathParamIndex=t.getParamIndex("PARAM_BREATH"),this.init()}init(){super.init(),this.settings.initParams&&this.settings.initParams.forEach((({id:t,value:e})=>this.coreModel.setParamFloat(t,e))),this.settings.initOpacities&&this.settings.initOpacities.forEach((({id:t,value:e})=>this.coreModel.setPartsOpacity(t,e))),this.coreModel.saveParam();const t=this.coreModel.getModelContext()._$aS;(null==t?void 0:t.length)&&(this.drawDataCount=t.length);let e=this.coreModel.drawParamWebGL.culling;Object.defineProperty(this.coreModel.drawParamWebGL,"culling",{set:t=>e=t,get:()=>!this.disableCulling&&e});const s=this.coreModel.getModelContext().clipManager,i=s.setupClip;s.setupClip=(t,e)=>{i.call(s,t,e),e.gl.viewport(...this.viewport)}}getSize(){return[this.coreModel.getCanvasWidth(),this.coreModel.getCanvasHeight()]}getLayout(){const t={};if(this.settings.layout)for(const e of Object.keys(this.settings.layout)){let s=e;"center_x"===e?s="centerX":"center_y"===e&&(s="centerY"),t[s]=this.settings.layout[e]}return t}updateWebGLContext(t,e){const s=this.coreModel.drawParamWebGL;s.firstDraw=!0,s.setGL(t),s.glno=e;for(const o in s)s.hasOwnProperty(o)&&s[o]instanceof WebGLBuffer&&(s[o]=null);const i=this.coreModel.getModelContext().clipManager;i.curFrameNo=e;const r=t.getParameter(t.FRAMEBUFFER_BINDING);i.getMaskRenderTexture(),t.bindFramebuffer(t.FRAMEBUFFER,r)}bindTexture(t,e){this.coreModel.setTexture(t,e)}getHitAreaDefs(){var t;return(null==(t=this.settings.hitAreas)?void 0:t.map((t=>({id:t.id,name:t.name,index:this.coreModel.getDrawDataIndex(t.id)}))))||[]}getDrawableIDs(){const t=this.coreModel.getModelContext(),e=[];for(let s=0;s<this.drawDataCount;s++){const i=t.getDrawData(s);i&&e.push(i.getDrawDataID().id)}return e}getDrawableIndex(t){return this.coreModel.getDrawDataIndex(t)}getDrawableVertices(t){if("string"==typeof t&&-1===(t=this.coreModel.getDrawDataIndex(t)))throw new TypeError("Unable to find drawable ID: "+t);return this.coreModel.getTransformedPoints(t).slice()}update(t,e){var s,i,r,o;super.update(t,e);const n=this.coreModel;this.emit("beforeMotionUpdate");const a=this.motionManager.update(this.coreModel,e);this.emit("afterMotionUpdate"),n.saveParam(),null==(s=this.motionManager.expressionManager)||s.update(n,e),a||null==(i=this.eyeBlink)||i.update(t),this.updateFocus(),this.updateNaturalMovements(t,e),null==(r=this.physics)||r.update(e),null==(o=this.pose)||o.update(t),this.emit("beforeModelUpdate"),n.update(),n.loadParam()}updateFocus(){this.coreModel.addToParamFloat(this.eyeballXParamIndex,this.focusController.x),this.coreModel.addToParamFloat(this.eyeballYParamIndex,this.focusController.y),this.coreModel.addToParamFloat(this.angleXParamIndex,30*this.focusController.x),this.coreModel.addToParamFloat(this.angleYParamIndex,30*this.focusController.y),this.coreModel.addToParamFloat(this.angleZParamIndex,this.focusController.x*this.focusController.y*-30),this.coreModel.addToParamFloat(this.bodyAngleXParamIndex,10*this.focusController.x)}updateNaturalMovements(t,e){const s=e/1e3*2*Math.PI;this.coreModel.addToParamFloat(this.angleXParamIndex,15*Math.sin(s/6.5345)*.5),this.coreModel.addToParamFloat(this.angleYParamIndex,8*Math.sin(s/3.5345)*.5),this.coreModel.addToParamFloat(this.angleZParamIndex,10*Math.sin(s/5.5345)*.5),this.coreModel.addToParamFloat(this.bodyAngleXParamIndex,4*Math.sin(s/15.5345)*.5),this.coreModel.setParamFloat(this.breathParamIndex,.5+.5*Math.sin(s/3.2345))}draw(t){const e=this.disableCulling;t.getParameter(t.FRAMEBUFFER_BINDING)&&(this.disableCulling=!0);const s=this.drawingMatrix;it[0]=s.a,it[1]=s.b,it[4]=s.c,it[5]=s.d,it[12]=s.tx,it[13]=s.ty,this.coreModel.setMatrix(it),this.coreModel.draw(),this.disableCulling=e}destroy(){super.destroy(),this.coreModel=void 0}}class ot extends M{constructor(t){if(super(t),this.motions={},!ot.isValidJSON(t))throw new TypeError("Invalid JSON.");this.moc=t.model,u("string",t,this,"textures","textures"),this.copy(t)}static isValidJSON(t){var e;return!!t&&"string"==typeof t.model&&(null==(e=t.textures)?void 0:e.length)>0&&t.textures.every((t=>"string"==typeof t))}copy(t){c("string",t,this,"name","name"),c("string",t,this,"pose","pose"),c("string",t,this,"physics","physics"),c("object",t,this,"layout","layout"),c("object",t,this,"motions","motions"),u("object",t,this,"hit_areas","hitAreas"),u("object",t,this,"expressions","expressions"),u("object",t,this,"init_params","initParams"),u("object",t,this,"init_opacities","initOpacities")}replaceFiles(t){super.replaceFiles(t);for(const[e,s]of Object.entries(this.motions))for(let i=0;i<s.length;i++)s[i].file=t(s[i].file,`motions.${e}[${i}].file`),void 0!==s[i].sound&&(s[i].sound=t(s[i].sound,`motions.${e}[${i}].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 nt={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE},at={x:PhysicsHair.Src.SRC_TO_X,y:PhysicsHair.Src.SRC_TO_Y,angle:PhysicsHair.Src.SRC_TO_G_ANGLE};class lt{constructor(t,e){this.coreModel=t,this.physicsHairs=[],e.physics_hair&&(this.physicsHairs=e.physics_hair.map((t=>{const e=new PhysicsHair;return e.setup(t.setup.length,t.setup.regist,t.setup.mass),t.src.forEach((({id:t,ptype:s,scale:i,weight:r})=>{const o=nt[s];o&&e.addSrcParam(o,t,i,r)})),t.targets.forEach((({id:t,ptype:s,scale:i,weight:r})=>{const o=at[s];o&&e.addTargetParam(o,t,i,r)})),e})))}update(t){this.physicsHairs.forEach((e=>e.update(this.coreModel,t)))}}class dt{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 ht{constructor(t,e){this.coreModel=t,this.opacityAnimDuration=500,this.partsGroups=[],e.parts_visible&&(this.partsGroups=e.parts_visible.map((({group:t})=>t.map((({id:t,link:e})=>{const s=new dt(t);return e&&(s.link=e.map((t=>new dt(t)))),s})))),this.init())}init(){this.partsGroups.forEach((t=>{t.forEach((t=>{if(t.initIndex(this.coreModel),t.paramIndex>=0){const e=0!==this.coreModel.getParamFloat(t.paramIndex);this.coreModel.setPartsOpacity(t.partsIndex,e?1:0),this.coreModel.setParamFloat(t.paramIndex,e?1:0),t.link.length>0&&t.link.forEach((t=>t.initIndex(this.coreModel)))}}))}))}normalizePartsOpacityGroup(t,e){const s=this.coreModel,i=.5;let r=1,o=t.findIndex((({paramIndex:t,partsIndex:e})=>e>=0&&0!==s.getParamFloat(t)));if(o>=0){const i=s.getPartsOpacity(t[o].partsIndex);r=d(i+e/this.opacityAnimDuration,0,1)}else o=0,r=1;t.forEach((({partsIndex:t},e)=>{if(t>=0)if(o==e)s.setPartsOpacity(t,r);else{let e,o=s.getPartsOpacity(t);e=r<i?-.5*r/i+1:(1-r)*i/.5,(1-e)*(1-r)>.15&&(e=1-.15/(1-r)),o>e&&(o=e),s.setPartsOpacity(t,o)}}))}copyOpacity(t){const e=this.coreModel;t.forEach((({partsIndex:t,link:s})=>{if(t>=0&&s){const i=e.getPartsOpacity(t);s.forEach((({partsIndex:t})=>{t>=0&&e.setPartsOpacity(t,i)}))}}))}update(t){this.partsGroups.forEach((e=>{this.normalizePartsOpacityGroup(e,t),this.copyOpacity(e)}))}}N.registerRuntime({version:2,test:t=>t instanceof ot||ot.isValidJSON(t),ready:()=>Promise.resolve(),isValidMoc(t){if(t.byteLength<3)return!1;const e=new Int8Array(t,0,3);return"moc"===String.fromCharCode(...e)},createModelSettings:t=>new ot(t),createCoreModel(t){const e=Live2DModelWebGL.loadModel(t),s=Live2D.getError();if(s)throw s;return e},createInternalModel:(t,e,s)=>new rt(t,e,s),createPose:(t,e)=>new ht(t,e),createPhysics:(t,e)=>new lt(t,e)}),t.Cubism2ExpressionManager=tt,t.Cubism2InternalModel=rt,t.Cubism2ModelSettings=ot,t.Cubism2MotionManager=et,t.ExpressionManager=f,t.FileLoader=z,t.FocusController=y,t.InteractionMixin=j,t.InternalModel=I,t.LOGICAL_HEIGHT=2,t.LOGICAL_WIDTH=2,t.Live2DExpression=K,t.Live2DEyeBlink=st,t.Live2DFactory=N,t.Live2DLoader=R,t.Live2DModel=B,t.Live2DPhysics=lt,t.Live2DPose=ht,t.Live2DTransform=W,t.ModelSettings=M,t.MotionManager=_,t.MotionPreloadStrategy=w,t.MotionPriority=x,t.MotionState=v,t.SoundManager=P,t.VERSION="0.4.0",t.XHRLoader=T,t.ZipLoader=Z,t.applyMixins=p,t.clamp=d,t.copyArray=u,t.copyProperty=c,t.folderName=g,t.logger=l,t.rand=h,t.remove=m,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));