live2dapi-noa 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,29 @@
1
1
  /*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
2
- var Qn=Object.defineProperty;var _e=(e,t)=>()=>(e&&(t=e(e=0)),t);var qe=(e,t)=>{for(var r in t)Qn(e,r,{get:t[r],enumerable:!0})};var m,Me=_e(()=>{m=class extends Error{code;details;constructor(e,t,r){super(t,r),this.name="Live2DError",this.code=e,this.details=r?.details?Object.freeze({...r.details}):void 0}}});function Mt(e){if(e===void 0||e===!1)return;if(typeof e=="string"){if(e.trim()!=="")return;throw new m("invalid-props","idleMotion must be a non-empty motion group name, weighted options or false.")}if(typeof e!="object"||e===null||Array.isArray(e))throw new m("invalid-props","idleMotion weighted options must be an object.");if(typeof e.group!="string"||e.group.trim()==="")throw new m("invalid-props","idleMotion.group must be a non-empty string.");if(!Array.isArray(e.weights)||e.weights.length===0)throw new m("invalid-props","idleMotion.weights must be a non-empty array.");let t=!1;for(let r of e.weights){if(!Number.isFinite(r)||r<0)throw new m("invalid-props","Every idleMotion weight must be a finite, non-negative number.");t||=r>0}if(!t)throw new m("invalid-props","At least one idleMotion weight must be greater than 0.")}function Rr(e,t){if(Mt(e),e===!1)return!1;if(e===void 0)return{group:"Idle"};if(typeof e=="string"){if(t(e)<=0)throw new m("invalid-props",`Unknown idle motion group: ${e}.`);return{group:e}}let r=t(e.group);if(r<=0)throw new m("invalid-props",`Unknown weighted idle motion group: ${e.group}.`);if(e.weights.length!==r)throw new m("invalid-props",`idleMotion.weights has ${e.weights.length} entries but group ${e.group} has ${r} motions.`);return{group:e.group,weights:[...e.weights]}}function Dr(e,t,r=Math.random){if(!t)return Math.min(e-1,Math.floor(r()*e));let i=0;for(let a of t)i=Math.max(i,a);let s=t.reduce((a,l)=>a+l/i,0),n=Math.min(1-Number.EPSILON,Math.max(0,r()))*s;for(let a=0;a<t.length;a++)if(n-=t[a]/i,n<0)return a;return t.length-1}function Pr(e,t,r){if(r!==void 0){if(!Number.isFinite(r)||r<0)throw new m("invalid-props",`${e} ${t} must be a finite, non-negative number of milliseconds.`);return r/1e3}}function Lr(e,t){if(t!==void 0&&(typeof t!="object"||t===null))throw new m("invalid-props",`${e} options must be an object.`);return{fadeInSeconds:Pr(e,"fadeInMs",t?.fadeInMs),fadeOutSeconds:Pr(e,"fadeOutMs",t?.fadeOutMs)}}function Ke(e){return Lr("Motion",e)}function Tr(e){return Lr("Expression",e)}function $e(e){return e.fadeInSeconds!==void 0||e.fadeOutSeconds!==void 0}function Ue(e){if(e!==void 0){if(typeof e!="object"||e===null)throw new m("invalid-props","Motion options must be an object.");if(e.priority!==void 0&&e.priority!=="force"&&e.priority!=="idle"&&e.priority!=="normal")throw new m("invalid-props","Motion priority must be 'force', 'idle' or 'normal'.");Ke(e)}}var xt=_e(()=>{Me()});var Or={};qe(Or,{WLipSyncAudioNode:()=>Et,createWLipSyncNode:()=>Gn,parseBinaryProfile:()=>Nn});function Fr(e,t,r,i,s){let n=2/i,a=n*s,l=1/(1+a+.48*a*a+.235*a*a*a),o=e-t,u=(r+n*o)*s;return wt.value=t+(o+u)*l,wt.velocity=(r-n*u)*l,wt}function Nn(e){let t=new DataView(e),r=0,i=()=>t.getUint8(r++),s=()=>{let u=t.getInt32(r);return r+=4,u},n=()=>String.fromCharCode(t.getUint8(r++)),a=()=>{let u=i(),c=Un.decode(e.slice(r,r+u));return r+=u,c},l=u=>[...new Array(u)].map(c=>(()=>{let d=t.getFloat32(r);return r+=4,d})());if(n()!=="W"||n()!=="L"||n()!=="I"||n()!=="P")throw new Error("Invalid file signature for binary wLipSync profile");let o={targetSampleRate:s(),sampleCount:s(),melFilterBankChannels:i(),compareMethod:i(),mfccNum:12,mfccs:[...new Array(i())],mfccDataCount:i(),useStandardization:i()===1};for(let u=0;u<o.mfccs.length;u++)o.mfccs[u]={name:"",mfccCalibrationDataList:[],values:l(12)};o.means=l(12),o.stdDevs=l(12);for(let u=0;u<o.mfccs.length;u++)o.mfccs[u].name=a();return o}async function Gn(e,t){try{return new Et(e,t)}catch{return await e.audioWorklet.addModule(new URL("data:text/javascript;base64,dmFyIEI9bmV3IFdlYkFzc2VtYmx5Lk1lbW9yeSh7aW5pdGlhbDo0fSksWD17ZW52OnttZW1vcnk6Qn19O2NsYXNzIFUgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3J7aW5wdXRCdWZmZXJJbmRleD0tMTtpbnB1dEJ1ZmZlclB0cj0tMTtpbnB1dEJ1ZmZlclNpemU9LTE7aW5wdXRCdWZmZXI9bnVsbDtsYXN0SW5kZXg9MDt2b2x1bWVQdHI9LTE7dm9sdW1lVmlldz1udWxsO21mY2NzPVtdO2V4cG9ydHM9bnVsbDtjb25zdHJ1Y3RvcihKKXtzdXBlcigpO2xldHt3YXNtTW9kdWxlOlMscHJvZmlsZTprfT1KLnByb2Nlc3Nvck9wdGlvbnM7V2ViQXNzZW1ibHkuaW5zdGFudGlhdGUoUyxYKS50aGVuKChHKT0+e2xldCB6PXRoaXMuZXhwb3J0cz1HLmV4cG9ydHMsRT1rLm1mY2NzLmxlbmd0aCxXPXoubG9hZF9wcm9maWxlKGsudGFyZ2V0U2FtcGxlUmF0ZSxrLnNhbXBsZUNvdW50LGsubWVsRmlsdGVyQmFua0NoYW5uZWxzLGsuY29tcGFyZU1ldGhvZCxFLGsubWZjY0RhdGFDb3VudCxrLnVzZVN0YW5kYXJkaXphdGlvbj8xOjApLFQ9dGhpcy5tZmNjcz1rLm1mY2NzO2lmKCFrLm1lYW5zKXtsZXQgSz1uZXcgRGF0YVZpZXcoQi5idWZmZXIsVyxFKmsubWZjY0RhdGFDb3VudCoxMio0KSxGPTA7Zm9yKGxldCBOIG9mIFQpZm9yKGxldCBRIG9mIE4ubWZjY0NhbGlicmF0aW9uRGF0YUxpc3QpZm9yKGxldCBSIG9mIFEuYXJyYXkpSy5zZXRGbG9hdDMyKEYsUiwhMCksRis9NDt6LnByZWNvbXB1dGVfcHJvZmlsZSgpfWVsc2V7bGV0IEs9ei5nZXRfcHJvZmlsZV9wdHJzKCksRj1uZXcgRGF0YVZpZXcoQi5idWZmZXIsSywxMiksTj1uZXcgRGF0YVZpZXcoQi5idWZmZXIsRi5nZXRJbnQzMigwLCEwKSxFKjEyKjQpO2ZvcihsZXQgQT0wO0E8RTtBKyspZm9yKGxldCBIPTA7SDwxMjtIKyspTi5zZXRGbG9hdDMyKChBKjEyK0gpKjQsVFtBXS52YWx1ZXNbSF0sITApO2xldCBRPW5ldyBEYXRhVmlldyhCLmJ1ZmZlcixGLmdldEludDMyKDQsITApLDQ4KSxSPW5ldyBEYXRhVmlldyhCLmJ1ZmZlcixGLmdldEludDMyKDgsITApLDQ4KTtmb3IobGV0IEE9MDtBPDEyO0ErKylRLnNldEZsb2F0MzIoQSo0LGsubWVhbnNbQV0sITApLFIuc2V0RmxvYXQzMihBKjQsay5zdGREZXZzW0FdLCEwKX16LnNldF9pbnB1dChzYW1wbGVSYXRlKSx0aGlzLmlucHV0QnVmZmVyUHRyPXouZ2V0X2lucHV0X2J1ZmZlcigpLHRoaXMuaW5wdXRCdWZmZXJTaXplPXouZ2V0X2lucHV0X2J1ZmZlcl9zaXplKCksdGhpcy5pbnB1dEJ1ZmZlcj1uZXcgRmxvYXQzMkFycmF5KEIuYnVmZmVyLHRoaXMuaW5wdXRCdWZmZXJQdHIsdGhpcy5pbnB1dEJ1ZmZlclNpemUpLHRoaXMuaW5wdXRCdWZmZXJJbmRleD0wLHRoaXMubGFzdEluZGV4PTAsdGhpcy52b2x1bWVQdHI9ei5nZXRfdm9sdW1lX3B0cigpLHRoaXMudm9sdW1lVmlldz1uZXcgRGF0YVZpZXcoQi5idWZmZXIsdGhpcy52b2x1bWVQdHIsNCl9KX1zdGF0aWMgZ2V0IHBhcmFtZXRlckRlc2NyaXB0b3JzKCl7cmV0dXJuW3tuYW1lOiJibG9ja1NpemUiLGRlZmF1bHRWYWx1ZTo1MTIsbWluVmFsdWU6MTI4LGF1dG9tYXRpb25SYXRlOiJrLXJhdGUifV19cHJvY2VzcyhKLFMsayl7bGV0IEc9SlswXVswXTtpZighRylyZXR1cm4hMDtpZih0aGlzLmlucHV0QnVmZmVySW5kZXg9PT0tMSlyZXR1cm4hMDtmb3IobGV0IHo9MDt6PEcubGVuZ3RoO3orKyl0aGlzLmlucHV0QnVmZmVyW3RoaXMuaW5wdXRCdWZmZXJJbmRleF09R1t6XSx0aGlzLmlucHV0QnVmZmVySW5kZXg9KHRoaXMuaW5wdXRCdWZmZXJJbmRleCsxKSV0aGlzLmlucHV0QnVmZmVyU2l6ZTtpZigodGhpcy5pbnB1dEJ1ZmZlckluZGV4K3RoaXMuaW5wdXRCdWZmZXJTaXplLXRoaXMubGFzdEluZGV4KSV0aGlzLmlucHV0QnVmZmVyU2l6ZT09PWsuYmxvY2tTaXplWzBdKXtsZXQgej10aGlzLmV4cG9ydHMuZXhlY3V0ZSh0aGlzLmlucHV0QnVmZmVySW5kZXgpLEU9dGhpcy52b2x1bWVWaWV3LmdldEZsb2F0MzIoMCwhMCk7dGhpcy5wb3J0LnBvc3RNZXNzYWdlKHt0aW1lc3RhbXA6Y3VycmVudFRpbWUsaW5kZXg6eixuYW1lOnRoaXMubWZjY3Nbel0ubmFtZSx2b2x1bWU6RX0pLHRoaXMubGFzdEluZGV4PXRoaXMuaW5wdXRCdWZmZXJJbmRleH1yZXR1cm4hMH19cmVnaXN0ZXJQcm9jZXNzb3IoIndsaXBzeW5jLXByb2Nlc3NvciIsVSk7Cg==",""+import.meta.url)),new Et(e,t)}}var wt,Vr,Et,Un,kr=_e(async()=>{wt={value:0,velocity:0};Vr={wasmModule:void 0},Et=class extends AudioWorkletNode{openCloseVelocity=0;lastTimestamp=0;weightVelocities={};minVolume=-2.5;maxVolume=-1.5;smoothness=.05;volume=0;weights={};constructor(e,t,r=Vr.wasmModule){super(e,"wlipsync-processor",{processorOptions:{wasmModule:r,profile:t}});for(let i of t.mfccs)this.weights[i.name]=0,this.weightVelocities[i.name]=0;this.port.onmessage=this.onMessage.bind(this)}onMessage(e){let t=e.data.timestamp-this.lastTimestamp;this.lastTimestamp=e.data.timestamp;let r=Number.isNaN(e.data.volume)?0:e.data.volume,i=Math.log10(r);i=(i-this.minVolume)/(this.maxVolume-this.minVolume),i=Math.max(Math.min(i,1),0);let s=Fr(this.volume,i,this.openCloseVelocity,this.smoothness,t);this.volume=s.value,this.openCloseVelocity=s.velocity;for(let n in this.weights){let a=n===e.data.name?1:0,l=Fr(this.weights[n],a,this.weightVelocities[n],this.smoothness,t);this.weights[n]=l.value,this.weightVelocities[n]=l.velocity}}get blockSize(){return this.parameters.get("blockSize").value}set blockSize(e){this.parameters.get("blockSize").setValueAtTime(e,this.context.currentTime)}},Un=new TextDecoder;Vr.wasmModule=await WebAssembly.compileStreaming(fetch("data:application/wasm;base64,AGFzbQEAAAABbRBgAAF/YAAAYAJ/fwBgBn9/f39/fwBgA39/fwBgAn9/AX1gA39/fQBgB39/f39/f38Bf2ABfwBgAX8Bf2AFf39/f38AYAR/f39/AGAFf39/f30AYAZ/f31/f38AYAZ/f319fX8AYAV/f399fwACDwEDZW52Bm1lbW9yeQIABAMdHAEBBwEACAAAAAkKBAsMBAINDg8FBgIGBQMDAwIGnAEXfwFBgIAEC38AQfiwCAt/AEGgsQgLfwBBkLAEC38AQcCwBAt/AEGQgAQLfwBBgIAEC38AQYyABAt/AEH0sAgLfwBB8LAEC38AQfCwCAt/AEGgsQ4LfwBB0LEOC38AQYCABAt/AEHQtQ4LfwBBAAt/AEGAgAQLfwBBgIAEC38AQdC1Dgt/AEGAgBALfwBBAAt/AEEBC38AQYCABAsHtgYzEV9fd2FzbV9jYWxsX2N0b3JzAAAPX19zdGFja19wb2ludGVyAwAMbG9hZF9wcm9maWxlAAIHcHJvZmlsZQMBDnByb2ZpbGVNZmNjUmF3AwIScHJlY29tcHV0ZV9wcm9maWxlAAMMcHJvZmlsZU1lYW5zAwMNcHJvZmlsZVN0ZERldgMEC3Byb2ZpbGVNZmNjAwUQZ2V0X3Byb2ZpbGVfcHRycwAEC3Byb2ZpbGVQdHJzAwYJc2V0X2lucHV0AAUQb3V0cHV0U2FtcGxlUmF0ZQMHEGlucHV0U2FtcGxlQ291bnQDCBBnZXRfaW5wdXRfYnVmZmVyAAYLaW5wdXRCdWZmZXIDCRVnZXRfaW5wdXRfYnVmZmVyX3NpemUABw5nZXRfdm9sdW1lX3B0cgAIBnZvbHVtZQMKB2V4ZWN1dGUACRBjb3B5X3JpbmdfYnVmZmVyAAoKcm1zX3ZvbHVtZQAXD2xvd19wYXNzX2ZpbHRlcgAREWRvd25fc2FtcGxlX2V4YWN0AAwLZG93bl9zYW1wbGUADQxwcmVfZW1waGFzaXMAFg5oYW1taW5nX3dpbmRvdwAPCW5vcm1hbGl6ZQAUA2ZmdAAOD21lbF9maWx0ZXJfYmFuawASC3Bvd2VyX3RvX2RiABUDZGN0AAsHbWZjY091dAMLBnNjb3JlcwMMEmNhbGNfbDFub3JtX3Njb3JlcwAZEmNhbGNfbDJub3JtX3Njb3JlcwAaHWNhbGNfY29zaW5lX3Np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"))});function j(e,t,r,i){if(!e)return i();let s=performance.now();try{return i()}finally{let n=performance.now()-s;t==="frame"?e.framePhase(r,n):e.loadPhase(r,n)}}async function Ce(e,t,r){if(!e)return r();let i=performance.now();try{return await r()}finally{e.loadPhase(t,performance.now()-i)}}function Xn(e,t){if(!t)return;let r=e.getExtension("EXT_disjoint_timer_query_webgl2");if(t.gpuTimerSupport(!!r),!r){t.gpuDraw(null);return}let i,s=[],n=()=>{for(;s.length>0;){let a=s[0];if(!e.getQueryParameter(a,e.QUERY_RESULT_AVAILABLE))return;s.shift();let l=e.getParameter(r.GPU_DISJOINT_EXT)?void 0:Number(e.getQueryParameter(a,e.QUERY_RESULT));t.gpuDraw(l===void 0||!Number.isFinite(l)?null:l/1e6),e.deleteQuery(a)}};return{begin(){if(n(),i)return;let a=e.createQuery();a&&(e.beginQuery(r.TIME_ELAPSED_EXT,a),i=a)},dispose(){i&&(e.endQuery(r.TIME_ELAPSED_EXT),e.deleteQuery(i),i=void 0);for(let a of s)e.deleteQuery(a);s.length=0},end(){i&&(e.endQuery(r.TIME_ELAPSED_EXT),s.push(i),i=void 0)},poll:n}}function Ur(e){return e.split("/").map(t=>t==="."||t===".."?t:encodeURIComponent(t)).join("/")}function Nr(e){return new URL(Ur(e.replace(/^\/+/,"")),Pt).href}function Rt(e){let t=new URL(e);if(t.origin===new URL(Pt).origin)return t.pathname.slice(1).split("/").map(r=>decodeURIComponent(r)).join("/")}function te(e,t){return t.startsWith(Pt)?/^[a-z][a-z\d+.-]*:/i.test(e)||e.startsWith("//")?new URL(e,t).href:new URL(Ur(e),t).href:new URL(e,t).href}function Gr(e){let t=typeof window>"u"?void 0:window.location.href,r=e instanceof URL?new URL(e.href):t?new URL(e,t):new URL(e);return r.pathname.endsWith("/")||(r.pathname+="/"),r.href}function le(e,t,r){return{assetType:e,backend:"cubism-webgl",httpStatus:r,url:Rt(t)??t}}async function Hn(e,t,r,i,s){let n;try{n=await e(t,s)}catch(a){throw s?.aborted?s.reason:new m("model-load-failed",`resolveAsset threw while loading ${t}.`,{cause:a,details:le(i,r)})}if(s?.aborted)throw s.reason;if(n===void 0)throw new m("model-load-failed",`resolveAsset did not provide ${t}. The model declares it, so the source is missing this file or names it differently.`,{details:{...le(i,r),httpStatus:404}});return n instanceof Blob?n:new Blob([n])}async function Wn(e,t,r){let i;try{i=await fetch(e,{signal:r})}catch(s){throw r?.aborted?r.reason:new m("model-load-failed",`Failed to load ${e}.`,{cause:s,details:le(t,e)})}if(!i.ok)throw new m("model-load-failed",`Failed to load ${e}: HTTP ${i.status}`,{details:le(t,e,i.status)});return i}async function Xr(e,t,r,i){let s=i?Rt(e):void 0;return i&&s!==void 0?Hn(i,s,e,t,r):(await Wn(e,t,r)).blob()}async function ue(e,t,r,i){let s=await(await Xr(e,t,r,i)).arrayBuffer();if(s.byteLength===0)throw new m("model-load-failed",`Loaded an empty asset from ${Rt(e)??e}.`,{details:le(t,e)});return s}async function Yn(e,t,r){if(r?.aborted)throw r.reason;if(typeof createImageBitmap=="function")try{return await createImageBitmap(e,{premultiplyAlpha:"premultiply"})}catch(s){throw r?.aborted?r.reason:new m("model-load-failed",`Failed to decode model texture ${t}.`,{cause:s,details:le("texture",t)})}let i=URL.createObjectURL(e);try{return await new Promise((s,n)=>{let a=new Image,l=()=>n(r?.reason);r?.addEventListener("abort",l,{once:!0}),a.onload=()=>{r?.removeEventListener("abort",l),s(a)},a.onerror=()=>{r?.removeEventListener("abort",l),n(new m("model-load-failed",`Failed to decode model texture ${t}.`,{details:le("texture",t)}))},a.src=i})}finally{URL.revokeObjectURL(i)}}function Ne(e){"close"in e&&typeof e.close=="function"&&e.close()}async function Hr(e,t,r,i){let s=await Ce(r,"textureFetch",()=>Xr(e,"texture",t,i));return Ce(r,"textureDecode",()=>Yn(s,e,t))}function Wr(e,t,r,i){let s=e.createTexture();if(!s)throw Ne(t),new m("render-error",`WebGL failed to create a texture for ${r}.`,{details:le("texture",r)});let n=e.getParameter(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL);try{return j(i,"load","textureUpload",()=>{e.bindTexture(e.TEXTURE_2D,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null)}),s}catch(a){throw e.deleteTexture(s),a instanceof m?a:new m("render-error",`Failed to upload model texture ${r} to WebGL.`,{cause:a,details:le("texture",r)})}finally{e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n),Ne(t)}}function Qr(e,t){for(let r of["aria-describedby","aria-hidden","aria-label","role"])e.removeAttribute(r);if(e.textContent="",!!t){if(t.mode==="decorative"){e.setAttribute("aria-hidden","true"),e.setAttribute("role","presentation");return}e.setAttribute("aria-label",t.label),e.setAttribute("role","img"),t.describedBy&&e.setAttribute("aria-describedby",t.describedBy),e.textContent=t.fallbackText??t.label}}function et(e){let t=!0;return()=>{t&&(t=!1,e())}}function zn(e){return e instanceof m?e:new m("render-error",e instanceof Error?e.message:String(e),{cause:e,details:{backend:"cubism-webgl"}})}function xe(e){let t=vt.get(e);if(!t||t.disposed)throw new m("adapter-error","The StageHandle was not created by the active cubism-webgl adapter.",{details:{backend:"cubism-webgl"}});return t}function Yr(e,t,r){if(typeof window>"u")throw new m("browser-only","cubism-webgl can only run in a browser.");let i=document.createElement("canvas");Qr(i,t.accessibility);let s=i.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,stencil:!1});if(!s)throw new m("webgl-unsupported","WebGL2 is required by cubism-webgl.",{details:{backend:"cubism-webgl"}});r?.changeResource("canvas",1),r?.changeResource("context",1);let n=Xn(s,r),a={height:Math.max(1,t.height),width:Math.max(1,t.width)},l=t.resolution??1,o=!1,u=!0,c=!1,d=0,h=0,g=!1,A,p,f=new Set,_=new Set,y=new Set,C=t.maxFps?1e3/t.maxFps:0,b=()=>{i.width=Math.max(1,Math.round(a.width*l)),i.height=Math.max(1,Math.round(a.height*l)),s.viewport(0,0,i.width,i.height);for(let v of f)v.resize(i.width,i.height)},x=()=>{u=!1,cancelAnimationFrame(d),d=0,h=0,A=void 0,p=void 0},B=v=>{if(!(o||c)){c=!0,x();for(let z of y)z(v)}},E=v=>{let z=Math.min(v,100);for(let X of f)X.update(z)},T=()=>{s.bindFramebuffer(s.FRAMEBUFFER,null),s.viewport(0,0,i.width,i.height),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT)},W=()=>{for(let v of f)v.draw()},ee=v=>{if(!u||o)return;d=requestAnimationFrame(ee);let z=p===void 0?0:v-p;if(p=v,h+=z,A!==void 0&&h<C-.25)return;let X=A===void 0?0:v-A;A=v,h=C?h>=C*2?0:Math.max(0,h-C):0;try{if(r)r.framePhase("frameDelta",X),j(r,"frame","stageFrame",()=>{E(X);for(let oe of _)oe(X);T(),n?.begin();try{j(r,"frame","drawCpu",W)}finally{n?.end()}});else{E(X);for(let oe of _)oe(X);T(),W()}f.size>0&&!g&&(g=!0,r?.firstDraw())}catch(oe){B(zn(oe))}},me=v=>{v.preventDefault(),B(new m("render-error","The WebGL context was lost. Call retry() to recreate the Live2D canvas.",{details:{backend:"cubism-webgl"}}))};i.style.display="block",i.style.height="100%",i.style.touchAction="none",i.style.width="100%",i.addEventListener("webglcontextlost",me),e.appendChild(i),b();let ae,Y={attachDriver(v){return f.add(v),v.resize(i.width,i.height),et(()=>{f.delete(v)})},canvas:i,diagnostics:r,disposed:o,gl:s,reportError:B};return ae={dispose:et(()=>{o=!0,Y.disposed=!0,x(),f.clear(),_.clear(),y.clear(),i.removeEventListener("webglcontextlost",me),n?.poll(),n?.dispose(),s.isContextLost()||s.getExtension("WEBGL_lose_context")?.loseContext(),i.width=1,i.height=1,i.remove(),r?.changeResource("context",-1),r?.changeResource("canvas",-1),vt.delete(ae)}),getResolution:()=>l,getSize:()=>({...a}),onError(v){return y.add(v),et(()=>y.delete(v))},onFrame(v){return _.add(v),et(()=>_.delete(v))},pause:x,resize(v,z){a={height:Math.max(1,z),width:Math.max(1,v)},b()},resume(){o||c||u||(u=!0,d=requestAnimationFrame(ee))},setAccessibility(v){Qr(i,v)},setResolution(v){if(!Number.isFinite(v)||v<1)throw new m("invalid-props","Stage resolution must be a finite number greater than or equal to 1.");l=v,b()},toWorld(v,z){let X=i.getBoundingClientRect();return{x:v-X.left,y:z-X.top}}},vt.set(ae,Y),d=requestAnimationFrame(ee),ae}var Pt,vt,Dt=_e(()=>{Me();Pt="https://live2d-web.invalid/";vt=new WeakMap});var gn={};qe(gn,{loadFrameworkModel:()=>dl});function ia(e,t){let r=0;for(let s=1;;s++){let n=e.slice(s-1,s);if(n=="e"||n=="-"||n=="E")continue;let a=e.substring(0,s),l=Number(a);if(isNaN(l))break;r=s}let i=parseFloat(e);return isNaN(i)&&(i=NaN),t[0]=e.slice(r),i}function Le(e){e&&(e=void 0)}function Q(e,t,r=null,i=null){if(e.length<t)if(i)for(let s=e.length;s<t;s++)typeof r=="function"?e[s]=JSON.parse(JSON.stringify(new r)):e[s]=r;else for(let s=e.length;s<t;s++)e[s]=r;else e.length=t}function H(e,t,r){let i=new ze;return i.time=e.time+(t.time-e.time)*r,i.value=e.value+(t.value-e.value)*r,i}function Ts(e,t){let r=(t-e[0].time)/(e[1].time-e[0].time);return r<0&&(r=0),e[0].value+(e[1].value-e[0].value)*r}function Qa(e,t){let r=(t-e[0].time)/(e[3].time-e[0].time);r<0&&(r=0);let i=H(e[0],e[1],r),s=H(e[1],e[2],r),n=H(e[2],e[3],r);return H(H(i,s,r),H(s,n,r),r).value}function Ua(e,t){let r=t,i=e[0].time,s=e[3].time,n=e[1].time,a=e[2].time,l=s-3*a+3*n-i,o=3*a-6*n+3*i,u=3*n-3*i,c=i-r,d=M.cardanoAlgorithmForBezier(l,o,u,c),h=H(e[0],e[1],d),g=H(e[1],e[2],d),A=H(e[2],e[3],d);return H(H(h,g,d),H(g,A,d),d).value}function Fs(e,t){return e[0].value}function Vs(e,t){return e[1].value}function Vt(e,t,r,i,s){let n=e.curves[t],a=-1,l=n.baseSegmentIndex+n.segmentCount,o=0;for(let c=n.baseSegmentIndex;c<l;++c)if(o=e.segments[c].basePointIndex+(e.segments[c].segmentType==1?3:1),e.points[o].time>r){a=c;break}if(a==-1)return i&&r<s?Na(e,l-1,e.segments[n.baseSegmentIndex].basePointIndex,o,r,s):e.points[o].value;let u=e.segments[a];return u.evaluate(e.points.slice(u.basePointIndex),r)}function Na(e,t,r,i,s,n){let a=[new ze,new ze];{let l=e.points[i];a[0].time=l.time,a[0].value=l.value}{let l=e.points[r];a[1].time=n,a[1].value=l.value}switch(e.segments[t].segmentType){case 0:case 1:default:return Ts(a,s);case 2:return Fs(a,s);case 3:return Vs(a,s)}}function ao(e){let t=0;return e>0?t=1:e<0&&(t=-1),t}function oo(e,t,r,i,s,n,a,l,o,u){e.x+=ur(r,i,s,n,a.minimum,a.maximum,a.defalut,o)*u}function lo(e,t,r,i,s,n,a,l,o,u){e.y+=ur(r,i,s,n,a.minimum,a.maximum,a.defalut,o)*u}function uo(e,t,r,i,s,n,a,l,o,u){t.angle+=ur(r,i,s,n,l.minimum,l.maximum,l.defalut,o)*u}function ho(e,t,r,i,s){let n=e.x;return i&&(n*=-1),n}function co(e,t,r,i,s){let n=e.y;return i&&(n*=-1),n}function go(e,t,r,i,s){let n;return r>=2?s=t[r-1].position.substract(t[r-2].position):s=s.multiplyByScaler(-1),n=M.directionToRadian(s,e),i&&(n*=-1),n}function fo(e,t){let r=M.max(e,t),i=M.min(e,t);return M.abs(r-i)}function Ao(e,t){return M.min(e,t)+fo(e,t)/2}function po(e,t){return JSON.parse(JSON.stringify(e.x))}function mo(e,t){return JSON.parse(JSON.stringify(e.y))}function _o(e,t){return JSON.parse(JSON.stringify(t))}function Co(e,t,r,i,s,n,a,l){let o,u,c=new w(0,0),d=new w(0,0),h=new w(0,0),g=new w(0,0);e[0].position=new w(r.x,r.y);let A=M.degreesToRadian(i),p=M.radianToDirection(A);p.normalize();for(let f=1;f<t;++f)e[f].force=p.multiplyByScaler(e[f].acceleration).add(s),e[f].lastPosition=new w(e[f].position.x,e[f].position.y),o=e[f].delay*a*30,c=e[f].position.substract(e[f-1].position),u=M.directionToRadian(e[f].lastGravity,p)/l,c.x=M.cos(u)*c.x-c.y*M.sin(u),c.y=M.sin(u)*c.x+c.y*M.cos(u),e[f].position=e[f-1].position.add(c),d=e[f].velocity.multiplyByScaler(o),h=e[f].force.multiplyByScaler(o).multiplyByScaler(o),e[f].position=e[f].position.add(d).add(h),g=e[f].position.substract(e[f-1].position),g.normalize(),e[f].position=e[f-1].position.add(g.multiplyByScaler(e[f].radius)),M.abs(e[f].position.x)<n&&(e[f].position.x=0),o!=0&&(e[f].velocity=e[f].position.substract(e[f].lastPosition),e[f].velocity=e[f].velocity.divisionByScalar(o),e[f].velocity=e[f].velocity.multiplyByScaler(e[f].mobility)),e[f].force=new w(0,0),e[f].lastGravity=new w(p.x,p.y)}function yo(e,t,r,i,s,n){let a=new w(0,0);e[0].position=new w(r.x,r.y);let l=M.degreesToRadian(i),o=M.radianToDirection(l);o.normalize();for(let u=1;u<t;++u)e[u].force=o.multiplyByScaler(e[u].acceleration).add(s),e[u].lastPosition=new w(e[u].position.x,e[u].position.y),e[u].velocity=new w(0,0),a=e[u].force,a.normalize(),a=a.multiplyByScaler(e[u].radius),e[u].position=e[u-1].position.add(a),M.abs(e[u].position.x)<n&&(e[u].position.x=0),e[u].force=new w(0,0),e[u].lastGravity=new w(o.x,o.y)}function Ut(e,t,r,i,s,n){let a;a=s*n.getScale(n.translationScale,n.angleScale),a<r?(a<n.valueBelowMinimum&&(n.valueBelowMinimum=a),a=r):a>i&&(a>n.valueExceededMaximum&&(n.valueExceededMaximum=a),a=i);let l=n.weight/qt;l>=1||(a=e[t]*(1-l)+a*l),e[t]=a}function ur(e,t,r,i,s,n,a,l){let o=0,u=M.max(r,t);u<e&&(e=u);let c=M.min(r,t);c>e&&(e=c);let d=M.min(s,n),h=M.max(s,n),g=a,A=Ao(c,u),p=e-A;switch(ao(p)){case 1:{let f=h-g,_=u-A;_!=0&&(o=p*(f/_),o+=g);break}case-1:{let f=d-g,_=c-A;_!=0&&(o=p*(f/_),o+=g);break}case 0:o=g;break;default:break}return l?o:o*-1}function qo(e){let t=(e instanceof Error?e.message:String(e)).match(/Failed to load shader (.+?)(?:: HTTP (\d+)|: empty source)$/);return{assetType:"shader",backend:"cubism-webgl",httpStatus:t?.[2]?Number(t[2]):void 0,url:t?.[1]}}function Ko(e){let t=!0;return()=>{t&&(t=!1,e())}}function $o(e){if(ot===0){let t=globalThis.Live2DCubismCore;if(!t||typeof t.MocVersion_53!="number"||typeof t.ColorBlendType_Normal!="number")throw new m("core-missing","cubism-webgl requires Live2D Cubism Core 5.3.",{details:{assetType:"core",backend:"cubism-webgl"}});if(!P.startUp())throw new m("adapter-error","CubismFramework.startUp() failed.",{details:{backend:"cubism-webgl"}});P.initialize()}return ot++,e?.changeResource("frameworkReference",1),Ko(()=>{ot--,e?.changeResource("frameworkReference",-1),ot===0&&P.isInitialized()&&P.dispose()})}function el(e,t){let r=t.transformX(-e.width/2),i=t.transformX(e.width/2),s=t.transformY(-e.height/2),n=t.transformY(e.height/2);return{centerX:(r+i)/2,centerY:(s+n)/2,height:Math.abs(n-s),width:Math.abs(i-r)}}function ds(e,t,r,i){let s=new ne,n=2*t.scale/Math.max(1,e.width),a=2*t.scale/Math.max(1,e.height),l=2*t.x/Math.max(1,e.width)-1,o=1-2*t.y/Math.max(1,e.height);return s.scale(n,a),s.translate(l-i.centerX*n,o-i.centerY*a),s.multiplyByMatrix(r),s}async function tl(e,t){return e.buffer||(e.loading??=t().finally(()=>{e.loading=void 0}),e.buffer=await e.loading),e.buffer}function rl(e,t){return t.fadeInSeconds!==void 0&&e.setFadeInTime(t.fadeInSeconds),t.fadeOutSeconds!==void 0&&e.setFadeOutTime(t.fadeOutSeconds),e}function gs(e,t,r,i){if(!$e(t))return{autoDelete:!1,motion:e.motion,releaseBeforeStart(){},transferToQueue(){}};if(!e.buffer)throw new Error("A fade override needs the motion buffer loaded before playback.");let s=rl(r(e.buffer),t),n=!0;return{autoDelete:!0,motion:s,releaseBeforeStart(){n&&(n=!1,i(s))},transferToQueue(){n=!1}}}function sl(e){let t=!0;return()=>{t&&(t=!1,e())}}function nl(e){return We.set(e,(We.get(e)??0)+1),sl(()=>{let t=(We.get(e)??1)-1;if(t>0){We.set(e,t);return}We.delete(e),hr.getInstance().removeContext(e),q.getInstance().releaseContext(e)})}function As(e){let t=!0;return()=>{t&&(t=!1,e())}}function dn(e,t){return e instanceof m?e:new m("model-load-failed",e instanceof Error?`${t}: ${e.message}`:t,{cause:e})}function se(e,t){return{assetType:e,backend:"cubism-webgl",url:t}}async function dl(e,t,r,i,s={}){let n=xe(e).diagnostics,a=$o(n),l=n?performance.now():0,o;try{let u=s.resolveAsset?Nr(t):new URL(t,window.location.href).href,c=await Ce(n,"modelJsonFetch",()=>ue(u,"model3",s.signal,s.resolveAsset)),d,h;try{let A=JSON.parse(new TextDecoder().decode(c));h=typeof A.Version=="number"&&Number.isFinite(A.Version)?A.Version:void 0,d=j(n,"load","modelJsonParse",()=>new ys(c,c.byteLength))}catch(A){throw new m("model-load-failed",`Failed to parse model3.json ${u}.`,{cause:A,details:se("model3",u)})}let g=Rr(s.idleMotion,A=>d.getMotionCount(A));return o=new cl(e,u,d,r,i,g,a,h,n,s.resolveAsset),await o.initialize(s.signal),n&&n.loadPhase("ready",performance.now()-l),o.toHandle()}catch(u){throw o?o.toHandle().dispose():a(),s.signal?.aborted?s.signal.reason:dn(u,`Failed to load ${t}`)}}var S,zr,ps,Jr,ms,jr,_s,Zr,w,qr,M,Kr,ne,$r,Jn,At,k,Ht,de,V,D,rr,ei,fe,jn,O,Lt,Zn,ti,qn,ri,Kn,Cs,ii,dt,si,pt,$n,R,ea,ni,ta,gt,ra,U,G,ft,K,Oe,Ye,Fe,ir,Ve,ai,Z,we,Ee,Ge,$,P,oi,sa,ys,li,sr,De,ui,nr,na,hi,zt,Ie,ci,ar,di,aa,Tt,gi,fi,oa,la,Jt,jt,Ai,Ft,pi,Ms,mi,xs,_i,Se,Ci,or,yi,ua,ws,bi,ha,ca,Bi,da,ga,tt,fa,Aa,pa,Ii,Te,ma,Es,Si,_a,Ca,ze,vs,Ps,Rs,Ds,Mi,N,ya,ba,Ba,Ia,Sa,Ma,xa,he,wa,Ea,rt,it,xi,wi,va,Pa,Ra,Da,Ls,Ei,La,Ta,Fa,Va,Oa,st,ka,Os,vi,Qs,Pi,Ga,Xa,Ha,lr,Zt,Us,Ns,Gs,Xs,Hs,Ri,Xe,Ot,kt,Qt,Di,Li,ce,nt,Wa,Ya,za,Ti,Fi,Ja,ja,L,ve,Vi,Oi,ki,Qi,Ui,He,Za,ye,qa,Ka,$a,be,eo,to,ro,io,Ws,Ni,Gi,Xi,Hi,so,qt,Wi,no,Kt,zs,Yi,zi,Nt,bo,Bo,Io,Ae,Ji,So,Mo,hr,ji,xo,wo,Eo,vo,Po,Ro,Do,Lo,To,Fo,Vo,Oo,ko,Qo,Uo,Pe,Zi,No,Go,Js,q,Zs,Xo,qi,at,Gt,ct,qs,Ho,cr,Ki,er,$i,es,Wo,Yo,Xt,zo,Jo,jo,$s,ts,Zo,en,tr,rs,rn,is,ge,ss,nn,ns,an,as,on,os,ln,ls,un,us,hn,hs,cn,cs,ot,il,We,al,ol,ll,fs,ul,hl,cl,fn=_e(()=>{Me();xt();Dt();S=Object.freeze({HitAreaPrefix:"HitArea",HitAreaHead:"Head",HitAreaBody:"Body",PartsIdCore:"Parts01Core",PartsArmPrefix:"Parts01Arm_",PartsArmLPrefix:"Parts01ArmL_",PartsArmRPrefix:"Parts01ArmR_",ParamAngleX:"ParamAngleX",ParamAngleY:"ParamAngleY",ParamAngleZ:"ParamAngleZ",ParamEyeLOpen:"ParamEyeLOpen",ParamEyeLSmile:"ParamEyeLSmile",ParamEyeROpen:"ParamEyeROpen",ParamEyeRSmile:"ParamEyeRSmile",ParamEyeBallX:"ParamEyeBallX",ParamEyeBallY:"ParamEyeBallY",ParamEyeBallForm:"ParamEyeBallForm",ParamBrowLY:"ParamBrowLY",ParamBrowRY:"ParamBrowRY",ParamBrowLX:"ParamBrowLX",ParamBrowRX:"ParamBrowRX",ParamBrowLAngle:"ParamBrowLAngle",ParamBrowRAngle:"ParamBrowRAngle",ParamBrowLForm:"ParamBrowLForm",ParamBrowRForm:"ParamBrowRForm",ParamMouthForm:"ParamMouthForm",ParamMouthOpenY:"ParamMouthOpenY",ParamCheek:"ParamCheek",ParamBodyAngleX:"ParamBodyAngleX",ParamBodyAngleY:"ParamBodyAngleY",ParamBodyAngleZ:"ParamBodyAngleZ",ParamBreath:"ParamBreath",ParamArmLA:"ParamArmLA",ParamArmRA:"ParamArmRA",ParamArmLB:"ParamArmLB",ParamArmRB:"ParamArmRB",ParamHandL:"ParamHandL",ParamHandR:"ParamHandR",ParamHairFront:"ParamHairFront",ParamHairSide:"ParamHairSide",ParamHairBack:"ParamHairBack",ParamHairFluffy:"ParamHairFluffy",ParamShoulderY:"ParamShoulderY",ParamBustX:"ParamBustX",ParamBustY:"ParamBustY",ParamBaseX:"ParamBaseX",ParamBaseY:"ParamBaseY",ParamNONE:"NONE:"});(function(e){e.HitAreaBody=S.HitAreaBody,e.HitAreaHead=S.HitAreaHead,e.HitAreaPrefix=S.HitAreaPrefix,e.ParamAngleX=S.ParamAngleX,e.ParamAngleY=S.ParamAngleY,e.ParamAngleZ=S.ParamAngleZ,e.ParamArmLA=S.ParamArmLA,e.ParamArmLB=S.ParamArmLB,e.ParamArmRA=S.ParamArmRA,e.ParamArmRB=S.ParamArmRB,e.ParamBaseX=S.ParamBaseX,e.ParamBaseY=S.ParamBaseY,e.ParamBodyAngleX=S.ParamBodyAngleX,e.ParamBodyAngleY=S.ParamBodyAngleY,e.ParamBodyAngleZ=S.ParamBodyAngleZ,e.ParamBreath=S.ParamBreath,e.ParamBrowLAngle=S.ParamBrowLAngle,e.ParamBrowLForm=S.ParamBrowLForm,e.ParamBrowLX=S.ParamBrowLX,e.ParamBrowLY=S.ParamBrowLY,e.ParamBrowRAngle=S.ParamBrowRAngle,e.ParamBrowRForm=S.ParamBrowRForm,e.ParamBrowRX=S.ParamBrowRX,e.ParamBrowRY=S.ParamBrowRY,e.ParamBustX=S.ParamBustX,e.ParamBustY=S.ParamBustY,e.ParamCheek=S.ParamCheek,e.ParamEyeBallForm=S.ParamEyeBallForm,e.ParamEyeBallX=S.ParamEyeBallX,e.ParamEyeBallY=S.ParamEyeBallY,e.ParamEyeLOpen=S.ParamEyeLOpen,e.ParamEyeLSmile=S.ParamEyeLSmile,e.ParamEyeROpen=S.ParamEyeROpen,e.ParamEyeRSmile=S.ParamEyeRSmile,e.ParamHairBack=S.ParamHairBack,e.ParamHairFluffy=S.ParamHairFluffy,e.ParamHairFront=S.ParamHairFront,e.ParamHairSide=S.ParamHairSide,e.ParamHandL=S.ParamHandL,e.ParamHandR=S.ParamHandR,e.ParamMouthForm=S.ParamMouthForm,e.ParamMouthOpenY=S.ParamMouthOpenY,e.ParamNONE=S.ParamNONE,e.ParamShoulderY=S.ParamShoulderY,e.PartsArmLPrefix=S.PartsArmLPrefix,e.PartsArmPrefix=S.PartsArmPrefix,e.PartsArmRPrefix=S.PartsArmRPrefix,e.PartsIdCore=S.PartsIdCore})(zr||(zr={}));ps=class{};(function(e){e.ICubismModelSetting=ps})(Jr||(Jr={}));ms=class lt{static createIdInternal(t){return new lt(t)}getString(){return this._id}isEqual(t){return typeof t=="string"?this._id==t:t instanceof lt?this._id==t._id:!1}isNotEqual(t){return typeof t=="string"?this._id!=t:t instanceof lt?this._id!=t._id:!1}constructor(t){this._id=t}_id};(function(e){e.CubismId=ms})(jr||(jr={}));_s=class{constructor(){this._ids=new Array}release(){for(let e=0;e<this._ids.length;++e)this._ids[e]=void 0;this._ids=null}registerIds(e){for(let t=0;t<e.length;t++)this.registerId(e[t])}registerId(e){let t=null;if(typeof e=="string"){if((t=this.findId(e))!=null)return t;t=ms.createIdInternal(e),this._ids.push(t)}else return this.registerId(e);return t}getId(e){return this.registerId(e)}isExist(e){return typeof e=="string"?this.findId(e)!=null:this.isExist(e)}findId(e){for(let t=0;t<this._ids.length;++t)if(this._ids[t].getString()==e)return this._ids[t];return null}_ids};(function(e){e.CubismIdManager=_s})(Zr||(Zr={}));w=class Be{x;y;constructor(t,r){this.x=t,this.y=r,this.x=t??0,this.y=r??0}add(t){let r=new Be(0,0);return r.x=this.x+t.x,r.y=this.y+t.y,r}substract(t){let r=new Be(0,0);return r.x=this.x-t.x,r.y=this.y-t.y,r}multiply(t){let r=new Be(0,0);return r.x=this.x*t.x,r.y=this.y*t.y,r}multiplyByScaler(t){return this.multiply(new Be(t,t))}division(t){let r=new Be(0,0);return r.x=this.x/t.x,r.y=this.y/t.y,r}divisionByScalar(t){return this.division(new Be(t,t))}getLength(){return Math.sqrt(this.x*this.x+this.y*this.y)}getDistanceWith(t){return Math.sqrt((this.x-t.x)*(this.x-t.x)+(this.y-t.y)*(this.y-t.y))}dot(t){return this.x*t.x+this.y*t.y}normalize(){let 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)}};(function(e){e.CubismVector2=w})(qr||(qr={}));M=class ut{static Epsilon=1e-5;static range(t,r,i){return t<r?t=r:t>i&&(t=i),t}static sin(t){return Math.sin(t)}static cos(t){return Math.cos(t)}static abs(t){return Math.abs(t)}static sqrt(t){return Math.sqrt(t)}static cbrt(t){if(t===0)return t;let r=t,i=r<0;i&&(r=-r);let s;return r===1/0?s=1/0:(s=Math.exp(Math.log(r)/3),s=(r/(s*s)+2*s)/3),i?-s:s}static getEasingSine(t){return t<0?0:t>1?1:.5-.5*this.cos(t*Math.PI)}static max(t,r){return t>r?t:r}static min(t,r){return t>r?r:t}static clamp(t,r,i){return t<r?r:i<t?i:t}static degreesToRadian(t){return t/180*Math.PI}static radianToDegrees(t){return t*180/Math.PI}static directionToRadian(t,r){let i=Math.atan2(r.y,r.x)-Math.atan2(t.y,t.x);for(;i<-Math.PI;)i+=Math.PI*2;for(;i>Math.PI;)i-=Math.PI*2;return i}static directionToDegrees(t,r){let i=this.directionToRadian(t,r),s=this.radianToDegrees(i);return r.x-t.x>0&&(s=-s),s}static radianToDirection(t){let r=new w;return r.x=this.sin(t),r.y=this.cos(t),r}static quadraticEquation(t,r,i){return this.abs(t)<ut.Epsilon?this.abs(r)<ut.Epsilon?-i:-i/r:-(r+this.sqrt(r*r-4*t*i))/(2*t)}static cardanoAlgorithmForBezier(t,r,i,s){if(this.abs(t)<ut.Epsilon)return this.range(this.quadraticEquation(r,i,s),0,1);let n=r/t,a=i/t,l=s/t,o=(3*a-n*n)/3,u=o/3,c=(2*n*n*n-9*n*a+27*l)/27,d=c/2,h=d*d+u*u*u,g=.5,A=.51;if(h<0){let _=-o/3,y=_*_*_,C=this.sqrt(y),b=-c/(2*C),x=this.range(b,-1,1),B=Math.acos(x),E=2*this.cbrt(C),T=E*this.cos(B/3)-n/3;if(this.abs(T-g)<A)return this.range(T,0,1);let W=E*this.cos((B+2*Math.PI)/3)-n/3;if(this.abs(W-g)<A)return this.range(W,0,1);let ee=E*this.cos((B+4*Math.PI)/3)-n/3;return this.range(ee,0,1)}if(h==0){let _;d<0?_=this.cbrt(-d):_=-this.cbrt(d);let y=2*_-n/3;if(this.abs(y-g)<A)return this.range(y,0,1);let C=-_-n/3;return this.range(C,0,1)}let p=this.sqrt(h),f=this.cbrt(p-d)-this.cbrt(p+d)-n/3;return this.range(f,0,1)}static mod(t,r){if(!isFinite(t)||r===0||isNaN(t)||isNaN(r))return console.warn(`divided: ${t}, divisor: ${r} mod() returns 'NaN'.`),NaN;let i=Math.abs(t),s=Math.abs(r),n=i-Math.floor(i/s)*s;return n*=Math.sign(t),n}constructor(){}};(function(e){e.CubismMath=M})(Kr||(Kr={}));ne=class Re{constructor(){this._tr=new Float32Array(16),this.loadIdentity()}static multiply(t,r,i){let s=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),n=4;for(let a=0;a<n;++a)for(let l=0;l<n;++l)for(let o=0;o<n;++o)s[l+a*4]+=t[o+a*4]*r[l+o*4];for(let a=0;a<16;++a)i[a]=s[a]}loadIdentity(){let 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 r=0;r<16;++r)this._tr[r]=t[r]}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,r){let i=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,t,r,0,1]);Re.multiply(i,this._tr,this._tr)}translate(t,r){this._tr[12]=t,this._tr[13]=r}translateX(t){this._tr[12]=t}translateY(t){this._tr[13]=t}scaleRelative(t,r){let i=new Float32Array([t,0,0,0,0,r,0,0,0,0,1,0,0,0,0,1]);Re.multiply(i,this._tr,this._tr)}scale(t,r){this._tr[0]=t,this._tr[5]=r}multiplyByMatrix(t){Re.multiply(t.getArray(),this._tr,this._tr)}getInvert(){let t=this._tr[0],r=this._tr[1],i=this._tr[2],s=this._tr[4],n=this._tr[5],a=this._tr[6],l=this._tr[8],o=this._tr[9],u=this._tr[10],c=this._tr[12],d=this._tr[13],h=this._tr[14],g=t*(n*u-o*a)-s*(r*u-o*i)+l*(r*a-n*i),A=new Re;if(M.abs(g)<M.Epsilon)return A.loadIdentity(),A;let p=1/g,f=(n*u-o*a)*p,_=-(s*u-l*a)*p,y=(s*o-l*n)*p,C=-(r*u-o*i)*p,b=(t*u-l*i)*p,x=-(t*o-l*r)*p,B=(r*a-n*i)*p,E=-(t*a-s*i)*p,T=(t*n-s*r)*p;return A._tr[0]=f,A._tr[1]=C,A._tr[2]=B,A._tr[3]=0,A._tr[4]=_,A._tr[5]=b,A._tr[6]=E,A._tr[7]=0,A._tr[8]=y,A._tr[9]=x,A._tr[10]=T,A._tr[11]=0,A._tr[12]=-(f*c+_*d+y*h),A._tr[13]=-(C*c+b*d+x*h),A._tr[14]=-(B*c+E*d+T*h),A._tr[15]=1,A}clone(){let t=new Re;for(let r=0;r<this._tr.length;r++)t._tr[r]=this._tr[r];return t}_tr};(function(e){e.CubismMatrix44=ne})($r||($r={}));Jn=(e,t,r)=>{rr.print(e,"[CSM]"+t,r)},At=(e,t,r)=>{Jn(e,t+`
3
- `,r)},k=e=>{e||console.assert(e)};Ht=(e,...t)=>{At(1,"[D]"+e,t)};de=(e,...t)=>{At(2,"[I]"+e,t)};V=(e,...t)=>{At(3,"[W]"+e,t)};D=(e,...t)=>{At(4,"[E]"+e,t)};rr=class{static print(e,t,r){if(e<P.getLoggingLevel())return;let i=P.coreLogFunction;i&&i(t.replace(/\{(\d+)\}/g,(s,n)=>r[n]))}static dumpBytes(e,t,r){for(let i=0;i<r;i++)i%16==0&&i>0?this.print(e,`
2
+ var Xn=Object.defineProperty;var _e=(e,t)=>()=>(e&&(t=e(e=0)),t);var qe=(e,t)=>{for(var r in t)Xn(e,r,{get:t[r],enumerable:!0})};var m,Me=_e(()=>{m=class extends Error{code;details;constructor(e,t,r){super(t,r),this.name="Live2DError",this.code=e,this.details=r?.details?Object.freeze({...r.details}):void 0}}});function Mt(e){if(e===void 0||e===!1)return;if(typeof e=="string"){if(e.trim()!=="")return;throw new m("invalid-props","idleMotion must be a non-empty motion group name, weighted options or false.")}if(typeof e!="object"||e===null||Array.isArray(e))throw new m("invalid-props","idleMotion weighted options must be an object.");if(typeof e.group!="string"||e.group.trim()==="")throw new m("invalid-props","idleMotion.group must be a non-empty string.");if(!Array.isArray(e.weights)||e.weights.length===0)throw new m("invalid-props","idleMotion.weights must be a non-empty array.");let t=!1;for(let r of e.weights){if(!Number.isFinite(r)||r<0)throw new m("invalid-props","Every idleMotion weight must be a finite, non-negative number.");t||=r>0}if(!t)throw new m("invalid-props","At least one idleMotion weight must be greater than 0.")}function Rr(e,t){if(Mt(e),e===!1)return!1;if(e===void 0)return{group:"Idle"};if(typeof e=="string"){if(t(e)<=0)throw new m("invalid-props",`Unknown idle motion group: ${e}.`);return{group:e}}let r=t(e.group);if(r<=0)throw new m("invalid-props",`Unknown weighted idle motion group: ${e.group}.`);if(e.weights.length!==r)throw new m("invalid-props",`idleMotion.weights has ${e.weights.length} entries but group ${e.group} has ${r} motions.`);return{group:e.group,weights:[...e.weights]}}function Dr(e,t,r=Math.random){if(!t)return Math.min(e-1,Math.floor(r()*e));let i=0;for(let a of t)i=Math.max(i,a);let s=t.reduce((a,l)=>a+l/i,0),n=Math.min(1-Number.EPSILON,Math.max(0,r()))*s;for(let a=0;a<t.length;a++)if(n-=t[a]/i,n<0)return a;return t.length-1}function Pr(e,t,r){if(r!==void 0){if(!Number.isFinite(r)||r<0)throw new m("invalid-props",`${e} ${t} must be a finite, non-negative number of milliseconds.`);return r/1e3}}function Lr(e,t){if(t!==void 0&&(typeof t!="object"||t===null))throw new m("invalid-props",`${e} options must be an object.`);return{fadeInSeconds:Pr(e,"fadeInMs",t?.fadeInMs),fadeOutSeconds:Pr(e,"fadeOutMs",t?.fadeOutMs)}}function Ke(e){return Lr("Motion",e)}function Tr(e){return Lr("Expression",e)}function $e(e){return e.fadeInSeconds!==void 0||e.fadeOutSeconds!==void 0}function Ue(e){if(e!==void 0){if(typeof e!="object"||e===null)throw new m("invalid-props","Motion options must be an object.");if(e.priority!==void 0&&e.priority!=="force"&&e.priority!=="idle"&&e.priority!=="normal")throw new m("invalid-props","Motion priority must be 'force', 'idle' or 'normal'.");Ke(e)}}var wt=_e(()=>{Me()});var Vr={};qe(Vr,{WLipSyncAudioNode:()=>Et,createWLipSyncNode:()=>Yn,parseBinaryProfile:()=>Wn});function Fr(e,t,r,i,s){let n=2/i,a=n*s,l=1/(1+a+.48*a*a+.235*a*a*a),o=e-t,u=(r+n*o)*s;return xt.value=t+(o+u)*l,xt.velocity=(r-n*u)*l,xt}function Wn(e){let t=new DataView(e),r=0,i=()=>t.getUint8(r++),s=()=>{let u=t.getInt32(r);return r+=4,u},n=()=>String.fromCharCode(t.getUint8(r++)),a=()=>{let u=i(),h=Hn.decode(e.slice(r,r+u));return r+=u,h},l=u=>[...new Array(u)].map(h=>(()=>{let d=t.getFloat32(r);return r+=4,d})());if(n()!=="W"||n()!=="L"||n()!=="I"||n()!=="P")throw new Error("Invalid file signature for binary wLipSync profile");let o={targetSampleRate:s(),sampleCount:s(),melFilterBankChannels:i(),compareMethod:i(),mfccNum:12,mfccs:[...new Array(i())],mfccDataCount:i(),useStandardization:i()===1};for(let u=0;u<o.mfccs.length;u++)o.mfccs[u]={name:"",mfccCalibrationDataList:[],values:l(12)};o.means=l(12),o.stdDevs=l(12);for(let u=0;u<o.mfccs.length;u++)o.mfccs[u].name=a();return o}async function Yn(e,t){try{return new Et(e,t)}catch{return await e.audioWorklet.addModule(new URL("data:text/javascript;base64,dmFyIEI9bmV3IFdlYkFzc2VtYmx5Lk1lbW9yeSh7aW5pdGlhbDo0fSksWD17ZW52OnttZW1vcnk6Qn19O2NsYXNzIFUgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3J7aW5wdXRCdWZmZXJJbmRleD0tMTtpbnB1dEJ1ZmZlclB0cj0tMTtpbnB1dEJ1ZmZlclNpemU9LTE7aW5wdXRCdWZmZXI9bnVsbDtsYXN0SW5kZXg9MDt2b2x1bWVQdHI9LTE7dm9sdW1lVmlldz1udWxsO21mY2NzPVtdO2V4cG9ydHM9bnVsbDtjb25zdHJ1Y3RvcihKKXtzdXBlcigpO2xldHt3YXNtTW9kdWxlOlMscHJvZmlsZTprfT1KLnByb2Nlc3Nvck9wdGlvbnM7V2ViQXNzZW1ibHkuaW5zdGFudGlhdGUoUyxYKS50aGVuKChHKT0+e2xldCB6PXRoaXMuZXhwb3J0cz1HLmV4cG9ydHMsRT1rLm1mY2NzLmxlbmd0aCxXPXoubG9hZF9wcm9maWxlKGsudGFyZ2V0U2FtcGxlUmF0ZSxrLnNhbXBsZUNvdW50LGsubWVsRmlsdGVyQmFua0NoYW5uZWxzLGsuY29tcGFyZU1ldGhvZCxFLGsubWZjY0RhdGFDb3VudCxrLnVzZVN0YW5kYXJkaXphdGlvbj8xOjApLFQ9dGhpcy5tZmNjcz1rLm1mY2NzO2lmKCFrLm1lYW5zKXtsZXQgSz1uZXcgRGF0YVZpZXcoQi5idWZmZXIsVyxFKmsubWZjY0RhdGFDb3VudCoxMio0KSxGPTA7Zm9yKGxldCBOIG9mIFQpZm9yKGxldCBRIG9mIE4ubWZjY0NhbGlicmF0aW9uRGF0YUxpc3QpZm9yKGxldCBSIG9mIFEuYXJyYXkpSy5zZXRGbG9hdDMyKEYsUiwhMCksRis9NDt6LnByZWNvbXB1dGVfcHJvZmlsZSgpfWVsc2V7bGV0IEs9ei5nZXRfcHJvZmlsZV9wdHJzKCksRj1uZXcgRGF0YVZpZXcoQi5idWZmZXIsSywxMiksTj1uZXcgRGF0YVZpZXcoQi5idWZmZXIsRi5nZXRJbnQzMigwLCEwKSxFKjEyKjQpO2ZvcihsZXQgQT0wO0E8RTtBKyspZm9yKGxldCBIPTA7SDwxMjtIKyspTi5zZXRGbG9hdDMyKChBKjEyK0gpKjQsVFtBXS52YWx1ZXNbSF0sITApO2xldCBRPW5ldyBEYXRhVmlldyhCLmJ1ZmZlcixGLmdldEludDMyKDQsITApLDQ4KSxSPW5ldyBEYXRhVmlldyhCLmJ1ZmZlcixGLmdldEludDMyKDgsITApLDQ4KTtmb3IobGV0IEE9MDtBPDEyO0ErKylRLnNldEZsb2F0MzIoQSo0LGsubWVhbnNbQV0sITApLFIuc2V0RmxvYXQzMihBKjQsay5zdGREZXZzW0FdLCEwKX16LnNldF9pbnB1dChzYW1wbGVSYXRlKSx0aGlzLmlucHV0QnVmZmVyUHRyPXouZ2V0X2lucHV0X2J1ZmZlcigpLHRoaXMuaW5wdXRCdWZmZXJTaXplPXouZ2V0X2lucHV0X2J1ZmZlcl9zaXplKCksdGhpcy5pbnB1dEJ1ZmZlcj1uZXcgRmxvYXQzMkFycmF5KEIuYnVmZmVyLHRoaXMuaW5wdXRCdWZmZXJQdHIsdGhpcy5pbnB1dEJ1ZmZlclNpemUpLHRoaXMuaW5wdXRCdWZmZXJJbmRleD0wLHRoaXMubGFzdEluZGV4PTAsdGhpcy52b2x1bWVQdHI9ei5nZXRfdm9sdW1lX3B0cigpLHRoaXMudm9sdW1lVmlldz1uZXcgRGF0YVZpZXcoQi5idWZmZXIsdGhpcy52b2x1bWVQdHIsNCl9KX1zdGF0aWMgZ2V0IHBhcmFtZXRlckRlc2NyaXB0b3JzKCl7cmV0dXJuW3tuYW1lOiJibG9ja1NpemUiLGRlZmF1bHRWYWx1ZTo1MTIsbWluVmFsdWU6MTI4LGF1dG9tYXRpb25SYXRlOiJrLXJhdGUifV19cHJvY2VzcyhKLFMsayl7bGV0IEc9SlswXVswXTtpZighRylyZXR1cm4hMDtpZih0aGlzLmlucHV0QnVmZmVySW5kZXg9PT0tMSlyZXR1cm4hMDtmb3IobGV0IHo9MDt6PEcubGVuZ3RoO3orKyl0aGlzLmlucHV0QnVmZmVyW3RoaXMuaW5wdXRCdWZmZXJJbmRleF09R1t6XSx0aGlzLmlucHV0QnVmZmVySW5kZXg9KHRoaXMuaW5wdXRCdWZmZXJJbmRleCsxKSV0aGlzLmlucHV0QnVmZmVyU2l6ZTtpZigodGhpcy5pbnB1dEJ1ZmZlckluZGV4K3RoaXMuaW5wdXRCdWZmZXJTaXplLXRoaXMubGFzdEluZGV4KSV0aGlzLmlucHV0QnVmZmVyU2l6ZT09PWsuYmxvY2tTaXplWzBdKXtsZXQgej10aGlzLmV4cG9ydHMuZXhlY3V0ZSh0aGlzLmlucHV0QnVmZmVySW5kZXgpLEU9dGhpcy52b2x1bWVWaWV3LmdldEZsb2F0MzIoMCwhMCk7dGhpcy5wb3J0LnBvc3RNZXNzYWdlKHt0aW1lc3RhbXA6Y3VycmVudFRpbWUsaW5kZXg6eixuYW1lOnRoaXMubWZjY3Nbel0ubmFtZSx2b2x1bWU6RX0pLHRoaXMubGFzdEluZGV4PXRoaXMuaW5wdXRCdWZmZXJJbmRleH1yZXR1cm4hMH19cmVnaXN0ZXJQcm9jZXNzb3IoIndsaXBzeW5jLXByb2Nlc3NvciIsVSk7Cg==",""+import.meta.url)),new Et(e,t)}}var xt,Or,Et,Hn,kr=_e(async()=>{xt={value:0,velocity:0};Or={wasmModule:void 0},Et=class extends AudioWorkletNode{openCloseVelocity=0;lastTimestamp=0;weightVelocities={};minVolume=-2.5;maxVolume=-1.5;smoothness=.05;volume=0;weights={};constructor(e,t,r=Or.wasmModule){super(e,"wlipsync-processor",{processorOptions:{wasmModule:r,profile:t}});for(let i of t.mfccs)this.weights[i.name]=0,this.weightVelocities[i.name]=0;this.port.onmessage=this.onMessage.bind(this)}onMessage(e){let t=e.data.timestamp-this.lastTimestamp;this.lastTimestamp=e.data.timestamp;let r=Number.isNaN(e.data.volume)?0:e.data.volume,i=Math.log10(r);i=(i-this.minVolume)/(this.maxVolume-this.minVolume),i=Math.max(Math.min(i,1),0);let s=Fr(this.volume,i,this.openCloseVelocity,this.smoothness,t);this.volume=s.value,this.openCloseVelocity=s.velocity;for(let n in this.weights){let a=n===e.data.name?1:0,l=Fr(this.weights[n],a,this.weightVelocities[n],this.smoothness,t);this.weights[n]=l.value,this.weightVelocities[n]=l.velocity}}get blockSize(){return this.parameters.get("blockSize").value}set blockSize(e){this.parameters.get("blockSize").setValueAtTime(e,this.context.currentTime)}},Hn=new TextDecoder;Or.wasmModule=await WebAssembly.compileStreaming(fetch("data:application/wasm;base64,AGFzbQEAAAABbRBgAAF/YAAAYAJ/fwBgBn9/f39/fwBgA39/fwBgAn9/AX1gA39/fQBgB39/f39/f38Bf2ABfwBgAX8Bf2AFf39/f38AYAR/f39/AGAFf39/f30AYAZ/f31/f38AYAZ/f319fX8AYAV/f399fwACDwEDZW52Bm1lbW9yeQIABAMdHAEBBwEACAAAAAkKBAsMBAINDg8FBgIGBQMDAwIGnAEXfwFBgIAEC38AQfiwCAt/AEGgsQgLfwBBkLAEC38AQcCwBAt/AEGQgAQLfwBBgIAEC38AQYyABAt/AEH0sAgLfwBB8LAEC38AQfCwCAt/AEGgsQ4LfwBB0LEOC38AQYCABAt/AEHQtQ4LfwBBAAt/AEGAgAQLfwBBgIAEC38AQdC1Dgt/AEGAgBALfwBBAAt/AEEBC38AQYCABAsHtgYzEV9fd2FzbV9jYWxsX2N0b3JzAAAPX19zdGFja19wb2ludGVyAwAMbG9hZF9wcm9maWxlAAIHcHJvZmlsZQMBDnByb2ZpbGVNZmNjUmF3AwIScHJlY29tcHV0ZV9wcm9maWxlAAMMcHJvZmlsZU1lYW5zAwMNcHJvZmlsZVN0ZERldgMEC3Byb2ZpbGVNZmNjAwUQZ2V0X3Byb2ZpbGVfcHRycwAEC3Byb2ZpbGVQdHJzAwYJc2V0X2lucHV0AAUQb3V0cHV0U2FtcGxlUmF0ZQMHEGlucHV0U2FtcGxlQ291bnQDCBBnZXRfaW5wdXRfYnVmZmVyAAYLaW5wdXRCdWZmZXIDCRVnZXRfaW5wdXRfYnVmZmVyX3NpemUABw5nZXRfdm9sdW1lX3B0cgAIBnZvbHVtZQMKB2V4ZWN1dGUACRBjb3B5X3JpbmdfYnVmZmVyAAoKcm1zX3ZvbHVtZQAXD2xvd19wYXNzX2ZpbHRlcgAREWRvd25fc2FtcGxlX2V4YWN0AAwLZG93bl9zYW1wbGUADQxwcmVfZW1waGFzaXMAFg5oYW1taW5nX3dpbmRvdwAPCW5vcm1hbGl6ZQAUA2ZmdAAOD21lbF9maWx0ZXJfYmFuawASC3Bvd2VyX3RvX2RiABUDZGN0AAsHbWZjY091dAMLBnNjb3JlcwMMEmNhbGNfbDFub3JtX3Njb3JlcwAZEmNhbGNfbDJub3JtX3Njb3JlcwAaHWNhbGNfY29zaW5lX3Np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"))});function j(e,t,r,i){if(!e)return i();let s=performance.now();try{return i()}finally{let n=performance.now()-s;t==="frame"?e.framePhase(r,n):e.loadPhase(r,n)}}async function Ce(e,t,r){if(!e)return r();let i=performance.now();try{return await r()}finally{e.loadPhase(t,performance.now()-i)}}function zn(e,t){if(!t)return;let r=e.getExtension("EXT_disjoint_timer_query_webgl2");if(t.gpuTimerSupport(!!r),!r){t.gpuDraw(null);return}let i,s=[],n=()=>{for(;s.length>0;){let a=s[0];if(!e.getQueryParameter(a,e.QUERY_RESULT_AVAILABLE))return;s.shift();let l=e.getParameter(r.GPU_DISJOINT_EXT)?void 0:Number(e.getQueryParameter(a,e.QUERY_RESULT));t.gpuDraw(l===void 0||!Number.isFinite(l)?null:l/1e6),e.deleteQuery(a)}};return{begin(){if(n(),i)return;let a=e.createQuery();a&&(e.beginQuery(r.TIME_ELAPSED_EXT,a),i=a)},dispose(){i&&(e.endQuery(r.TIME_ELAPSED_EXT),e.deleteQuery(i),i=void 0);for(let a of s)e.deleteQuery(a);s.length=0},end(){i&&(e.endQuery(r.TIME_ELAPSED_EXT),s.push(i),i=void 0)},poll:n}}function Ur(e){return e.split("/").map(t=>t==="."||t===".."?t:encodeURIComponent(t)).join("/")}function Nr(e){return new URL(Ur(e.replace(/^\/+/,"")),Pt).href}function Rt(e){let t=new URL(e);if(t.origin===new URL(Pt).origin)return t.pathname.slice(1).split("/").map(r=>decodeURIComponent(r)).join("/")}function te(e,t){return t.startsWith(Pt)?/^[a-z][a-z\d+.-]*:/i.test(e)||e.startsWith("//")?new URL(e,t).href:new URL(Ur(e),t).href:new URL(e,t).href}function Gr(e){let t=typeof window>"u"?void 0:window.location.href,r=e instanceof URL?new URL(e.href):t?new URL(e,t):new URL(e);return r.pathname.endsWith("/")||(r.pathname+="/"),r.href}function le(e,t,r){return{assetType:e,backend:"cubism-webgl",httpStatus:r,url:Rt(t)??t}}async function Jn(e,t,r,i,s){let n;try{n=await e(t,s)}catch(a){throw s?.aborted?s.reason:new m("model-load-failed",`resolveAsset threw while loading ${t}.`,{cause:a,details:le(i,r)})}if(s?.aborted)throw s.reason;if(n===void 0)throw new m("model-load-failed",`resolveAsset did not provide ${t}. The model declares it, so the source is missing this file or names it differently.`,{details:{...le(i,r),httpStatus:404}});return n instanceof Blob?n:new Blob([n])}async function jn(e,t,r){let i;try{i=await fetch(e,{signal:r})}catch(s){throw r?.aborted?r.reason:new m("model-load-failed",`Failed to load ${e}.`,{cause:s,details:le(t,e)})}if(!i.ok)throw new m("model-load-failed",`Failed to load ${e}: HTTP ${i.status}`,{details:le(t,e,i.status)});return i}async function Xr(e,t,r,i){let s=i?Rt(e):void 0;return i&&s!==void 0?Jn(i,s,e,t,r):(await jn(e,t,r)).blob()}async function ue(e,t,r,i){let s=await(await Xr(e,t,r,i)).arrayBuffer();if(s.byteLength===0)throw new m("model-load-failed",`Loaded an empty asset from ${Rt(e)??e}.`,{details:le(t,e)});return s}async function Zn(e,t,r){if(r?.aborted)throw r.reason;if(typeof createImageBitmap=="function")try{return await createImageBitmap(e,{premultiplyAlpha:"premultiply"})}catch(s){throw r?.aborted?r.reason:new m("model-load-failed",`Failed to decode model texture ${t}.`,{cause:s,details:le("texture",t)})}let i=URL.createObjectURL(e);try{return await new Promise((s,n)=>{let a=new Image,l=()=>n(r?.reason);r?.addEventListener("abort",l,{once:!0}),a.onload=()=>{r?.removeEventListener("abort",l),s(a)},a.onerror=()=>{r?.removeEventListener("abort",l),n(new m("model-load-failed",`Failed to decode model texture ${t}.`,{details:le("texture",t)}))},a.src=i})}finally{URL.revokeObjectURL(i)}}function Ne(e){"close"in e&&typeof e.close=="function"&&e.close()}async function Hr(e,t,r,i){let s=await Ce(r,"textureFetch",()=>Xr(e,"texture",t,i));return Ce(r,"textureDecode",()=>Zn(s,e,t))}function Wr(e,t,r,i){let s=e.createTexture();if(!s)throw Ne(t),new m("render-error",`WebGL failed to create a texture for ${r}.`,{details:le("texture",r)});let n=e.getParameter(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL);try{return j(i,"load","textureUpload",()=>{e.bindTexture(e.TEXTURE_2D,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null)}),s}catch(a){throw e.deleteTexture(s),a instanceof m?a:new m("render-error",`Failed to upload model texture ${r} to WebGL.`,{cause:a,details:le("texture",r)})}finally{e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n),Ne(t)}}function Qr(e,t){for(let r of["aria-describedby","aria-hidden","aria-label","role"])e.removeAttribute(r);if(e.textContent="",!!t){if(t.mode==="decorative"){e.setAttribute("aria-hidden","true"),e.setAttribute("role","presentation");return}e.setAttribute("aria-label",t.label),e.setAttribute("role","img"),t.describedBy&&e.setAttribute("aria-describedby",t.describedBy),e.textContent=t.fallbackText??t.label}}function et(e){let t=!0;return()=>{t&&(t=!1,e())}}function qn(e){return e instanceof m?e:new m("render-error",e instanceof Error?e.message:String(e),{cause:e,details:{backend:"cubism-webgl"}})}function we(e){let t=vt.get(e);if(!t||t.disposed)throw new m("adapter-error","The StageHandle was not created by the active cubism-webgl adapter.",{details:{backend:"cubism-webgl"}});return t}function Yr(e,t,r){if(typeof window>"u")throw new m("browser-only","cubism-webgl can only run in a browser.");let i=document.createElement("canvas");Qr(i,t.accessibility);let s=i.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,stencil:!1});if(!s)throw new m("webgl-unsupported","WebGL2 is required by cubism-webgl.",{details:{backend:"cubism-webgl"}});r?.changeResource("canvas",1),r?.changeResource("context",1);let n=zn(s,r),a={height:Math.max(1,t.height),width:Math.max(1,t.width)},l=t.resolution??1,o=!1,u=!0,h=!1,d=0,c=0,g=!1,A,p,f=new Set,_=new Set,y=new Set,C=t.maxFps?1e3/t.maxFps:0,b=()=>{i.width=Math.max(1,Math.round(a.width*l)),i.height=Math.max(1,Math.round(a.height*l)),s.viewport(0,0,i.width,i.height);for(let v of f)v.resize(i.width,i.height)},w=()=>{u=!1,cancelAnimationFrame(d),d=0,c=0,A=void 0,p=void 0},B=v=>{if(!(o||h)){h=!0,w();for(let z of y)z(v)}},E=v=>{let z=Math.min(v,100);for(let X of f)X.update(z)},T=()=>{s.bindFramebuffer(s.FRAMEBUFFER,null),s.viewport(0,0,i.width,i.height),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT)},W=()=>{for(let v of f)v.draw()},ee=v=>{if(!u||o)return;d=requestAnimationFrame(ee);let z=p===void 0?0:v-p;if(p=v,c+=z,A!==void 0&&c<C-.25)return;let X=A===void 0?0:v-A;A=v,c=C?c>=C*2?0:Math.max(0,c-C):0;try{if(r)r.framePhase("frameDelta",X),j(r,"frame","stageFrame",()=>{E(X);for(let oe of _)oe(X);T(),n?.begin();try{j(r,"frame","drawCpu",W)}finally{n?.end()}});else{E(X);for(let oe of _)oe(X);T(),W()}f.size>0&&!g&&(g=!0,r?.firstDraw())}catch(oe){B(qn(oe))}},me=v=>{v.preventDefault(),B(new m("render-error","The WebGL context was lost. Call retry() to recreate the Live2D canvas.",{details:{backend:"cubism-webgl"}}))};i.style.display="block",i.style.height="100%",i.style.touchAction="none",i.style.width="100%",i.addEventListener("webglcontextlost",me),e.appendChild(i),b();let ae,Y={attachDriver(v){return f.add(v),v.resize(i.width,i.height),et(()=>{f.delete(v)})},canvas:i,diagnostics:r,disposed:o,gl:s,reportError:B};return ae={dispose:et(()=>{o=!0,Y.disposed=!0,w(),f.clear(),_.clear(),y.clear(),i.removeEventListener("webglcontextlost",me),n?.poll(),n?.dispose(),s.isContextLost()||s.getExtension("WEBGL_lose_context")?.loseContext(),i.width=1,i.height=1,i.remove(),r?.changeResource("context",-1),r?.changeResource("canvas",-1),vt.delete(ae)}),getResolution:()=>l,getSize:()=>({...a}),onError(v){return y.add(v),et(()=>y.delete(v))},onFrame(v){return _.add(v),et(()=>_.delete(v))},pause:w,resize(v,z){a={height:Math.max(1,z),width:Math.max(1,v)},b()},resume(){o||h||u||(u=!0,d=requestAnimationFrame(ee))},setAccessibility(v){Qr(i,v)},setResolution(v){if(!Number.isFinite(v)||v<1)throw new m("invalid-props","Stage resolution must be a finite number greater than or equal to 1.");l=v,b()},toWorld(v,z){let X=i.getBoundingClientRect();return{x:v-X.left,y:z-X.top}}},vt.set(ae,Y),d=requestAnimationFrame(ee),ae}var Pt,vt,Dt=_e(()=>{Me();Pt="https://live2d-web.invalid/";vt=new WeakMap});var gn={};qe(gn,{loadFrameworkModel:()=>pl});function oa(e,t){let r=0;for(let s=1;;s++){let n=e.slice(s-1,s);if(n=="e"||n=="-"||n=="E")continue;let a=e.substring(0,s),l=Number(a);if(isNaN(l))break;r=s}let i=parseFloat(e);return isNaN(i)&&(i=NaN),t[0]=e.slice(r),i}function Le(e){e&&(e=void 0)}function Q(e,t,r=null,i=null){if(e.length<t)if(i)for(let s=e.length;s<t;s++)typeof r=="function"?e[s]=JSON.parse(JSON.stringify(new r)):e[s]=r;else for(let s=e.length;s<t;s++)e[s]=r;else e.length=t}function H(e,t,r){let i=new ze;return i.time=e.time+(t.time-e.time)*r,i.value=e.value+(t.value-e.value)*r,i}function Ts(e,t){let r=(t-e[0].time)/(e[1].time-e[0].time);return r<0&&(r=0),e[0].value+(e[1].value-e[0].value)*r}function Xa(e,t){let r=(t-e[0].time)/(e[3].time-e[0].time);r<0&&(r=0);let i=H(e[0],e[1],r),s=H(e[1],e[2],r),n=H(e[2],e[3],r);return H(H(i,s,r),H(s,n,r),r).value}function Ha(e,t){let r=t,i=e[0].time,s=e[3].time,n=e[1].time,a=e[2].time,l=s-3*a+3*n-i,o=3*a-6*n+3*i,u=3*n-3*i,h=i-r,d=M.cardanoAlgorithmForBezier(l,o,u,h),c=H(e[0],e[1],d),g=H(e[1],e[2],d),A=H(e[2],e[3],d);return H(H(c,g,d),H(g,A,d),d).value}function Fs(e,t){return e[0].value}function Os(e,t){return e[1].value}function Ot(e,t,r,i,s){let n=e.curves[t],a=-1,l=n.baseSegmentIndex+n.segmentCount,o=0;for(let h=n.baseSegmentIndex;h<l;++h)if(o=e.segments[h].basePointIndex+(e.segments[h].segmentType==1?3:1),e.points[o].time>r){a=h;break}if(a==-1)return i&&r<s?Wa(e,l-1,e.segments[n.baseSegmentIndex].basePointIndex,o,r,s):e.points[o].value;let u=e.segments[a];return u.evaluate(e.points.slice(u.basePointIndex),r)}function Wa(e,t,r,i,s,n){let a=[new ze,new ze];{let l=e.points[i];a[0].time=l.time,a[0].value=l.value}{let l=e.points[r];a[1].time=n,a[1].value=l.value}switch(e.segments[t].segmentType){case 0:case 1:default:return Ts(a,s);case 2:return Fs(a,s);case 3:return Os(a,s)}}function ho(e){let t=0;return e>0?t=1:e<0&&(t=-1),t}function co(e,t,r,i,s,n,a,l,o,u){e.x+=ur(r,i,s,n,a.minimum,a.maximum,a.defalut,o)*u}function go(e,t,r,i,s,n,a,l,o,u){e.y+=ur(r,i,s,n,a.minimum,a.maximum,a.defalut,o)*u}function fo(e,t,r,i,s,n,a,l,o,u){t.angle+=ur(r,i,s,n,l.minimum,l.maximum,l.defalut,o)*u}function Ao(e,t,r,i,s){let n=e.x;return i&&(n*=-1),n}function po(e,t,r,i,s){let n=e.y;return i&&(n*=-1),n}function mo(e,t,r,i,s){let n;return r>=2?s=t[r-1].position.substract(t[r-2].position):s=s.multiplyByScaler(-1),n=M.directionToRadian(s,e),i&&(n*=-1),n}function _o(e,t){let r=M.max(e,t),i=M.min(e,t);return M.abs(r-i)}function Co(e,t){return M.min(e,t)+_o(e,t)/2}function yo(e,t){return JSON.parse(JSON.stringify(e.x))}function bo(e,t){return JSON.parse(JSON.stringify(e.y))}function Bo(e,t){return JSON.parse(JSON.stringify(t))}function Io(e,t,r,i,s,n,a,l){let o,u,h=new x(0,0),d=new x(0,0),c=new x(0,0),g=new x(0,0);e[0].position=new x(r.x,r.y);let A=M.degreesToRadian(i),p=M.radianToDirection(A);p.normalize();for(let f=1;f<t;++f)e[f].force=p.multiplyByScaler(e[f].acceleration).add(s),e[f].lastPosition=new x(e[f].position.x,e[f].position.y),o=e[f].delay*a*30,h=e[f].position.substract(e[f-1].position),u=M.directionToRadian(e[f].lastGravity,p)/l,h.x=M.cos(u)*h.x-h.y*M.sin(u),h.y=M.sin(u)*h.x+h.y*M.cos(u),e[f].position=e[f-1].position.add(h),d=e[f].velocity.multiplyByScaler(o),c=e[f].force.multiplyByScaler(o).multiplyByScaler(o),e[f].position=e[f].position.add(d).add(c),g=e[f].position.substract(e[f-1].position),g.normalize(),e[f].position=e[f-1].position.add(g.multiplyByScaler(e[f].radius)),M.abs(e[f].position.x)<n&&(e[f].position.x=0),o!=0&&(e[f].velocity=e[f].position.substract(e[f].lastPosition),e[f].velocity=e[f].velocity.divisionByScalar(o),e[f].velocity=e[f].velocity.multiplyByScaler(e[f].mobility)),e[f].force=new x(0,0),e[f].lastGravity=new x(p.x,p.y)}function So(e,t,r,i,s,n){let a=new x(0,0);e[0].position=new x(r.x,r.y);let l=M.degreesToRadian(i),o=M.radianToDirection(l);o.normalize();for(let u=1;u<t;++u)e[u].force=o.multiplyByScaler(e[u].acceleration).add(s),e[u].lastPosition=new x(e[u].position.x,e[u].position.y),e[u].velocity=new x(0,0),a=e[u].force,a.normalize(),a=a.multiplyByScaler(e[u].radius),e[u].position=e[u-1].position.add(a),M.abs(e[u].position.x)<n&&(e[u].position.x=0),e[u].force=new x(0,0),e[u].lastGravity=new x(o.x,o.y)}function Ut(e,t,r,i,s,n){let a;a=s*n.getScale(n.translationScale,n.angleScale),a<r?(a<n.valueBelowMinimum&&(n.valueBelowMinimum=a),a=r):a>i&&(a>n.valueExceededMaximum&&(n.valueExceededMaximum=a),a=i);let l=n.weight/qt;l>=1||(a=e[t]*(1-l)+a*l),e[t]=a}function ur(e,t,r,i,s,n,a,l){let o=0,u=M.max(r,t);u<e&&(e=u);let h=M.min(r,t);h>e&&(e=h);let d=M.min(s,n),c=M.max(s,n),g=a,A=Co(h,u),p=e-A;switch(ho(p)){case 1:{let f=c-g,_=u-A;_!=0&&(o=p*(f/_),o+=g);break}case-1:{let f=d-g,_=h-A;_!=0&&(o=p*(f/_),o+=g);break}case 0:o=g;break;default:break}return l?o:o*-1}function tl(e){let t=(e instanceof Error?e.message:String(e)).match(/Failed to load shader (.+?)(?:: HTTP (\d+)|: empty source)$/);return{assetType:"shader",backend:"cubism-webgl",httpStatus:t?.[2]?Number(t[2]):void 0,url:t?.[1]}}function rl(e){let t=!0;return()=>{t&&(t=!1,e())}}function il(e){if(ot===0){let t=globalThis.Live2DCubismCore;if(!t||typeof t.MocVersion_53!="number"||typeof t.ColorBlendType_Normal!="number")throw new m("core-missing","cubism-webgl requires Live2D Cubism Core 5.3.",{details:{assetType:"core",backend:"cubism-webgl"}});if(!P.startUp())throw new m("adapter-error","CubismFramework.startUp() failed.",{details:{backend:"cubism-webgl"}});P.initialize()}return ot++,e?.changeResource("frameworkReference",1),rl(()=>{ot--,e?.changeResource("frameworkReference",-1),ot===0&&P.isInitialized()&&P.dispose()})}function sl(e,t){let r=t.transformX(-e.width/2),i=t.transformX(e.width/2),s=t.transformY(-e.height/2),n=t.transformY(e.height/2);return{centerX:(r+i)/2,centerY:(s+n)/2,height:Math.abs(n-s),width:Math.abs(i-r)}}function ds(e,t,r,i){let s=new ne,n=2*t.scale/Math.max(1,e.width),a=2*t.scale/Math.max(1,e.height),l=2*t.x/Math.max(1,e.width)-1,o=1-2*t.y/Math.max(1,e.height);return s.scale(n,a),s.translate(l-i.centerX*n,o-i.centerY*a),s.multiplyByMatrix(r),s}async function nl(e,t){return e.buffer||(e.loading??=t().finally(()=>{e.loading=void 0}),e.buffer=await e.loading),e.buffer}function al(e,t){return t.fadeInSeconds!==void 0&&e.setFadeInTime(t.fadeInSeconds),t.fadeOutSeconds!==void 0&&e.setFadeOutTime(t.fadeOutSeconds),e}function gs(e,t,r,i){if(!$e(t))return{autoDelete:!1,motion:e.motion,releaseBeforeStart(){},transferToQueue(){}};if(!e.buffer)throw new Error("A fade override needs the motion buffer loaded before playback.");let s=al(r(e.buffer),t),n=!0;return{autoDelete:!0,motion:s,releaseBeforeStart(){n&&(n=!1,i(s))},transferToQueue(){n=!1}}}function ll(e){let t=!0;return()=>{t&&(t=!1,e())}}function ul(e){return We.set(e,(We.get(e)??0)+1),ll(()=>{let t=(We.get(e)??1)-1;if(t>0){We.set(e,t);return}We.delete(e),hr.getInstance().removeContext(e),q.getInstance().releaseContext(e)})}function As(e){let t=!0;return()=>{t&&(t=!1,e())}}function dn(e,t){return e instanceof m?e:new m("model-load-failed",e instanceof Error?`${t}: ${e.message}`:t,{cause:e})}function se(e,t){return{assetType:e,backend:"cubism-webgl",url:t}}async function pl(e,t,r,i,s={}){let n=we(e).diagnostics,a=il(n),l=n?performance.now():0,o;try{let u=s.resolveAsset?Nr(t):new URL(t,window.location.href).href,h=await Ce(n,"modelJsonFetch",()=>ue(u,"model3",s.signal,s.resolveAsset)),d,c;try{let A=JSON.parse(new TextDecoder().decode(h));c=typeof A.Version=="number"&&Number.isFinite(A.Version)?A.Version:void 0,d=j(n,"load","modelJsonParse",()=>new ys(h,h.byteLength))}catch(A){throw new m("model-load-failed",`Failed to parse model3.json ${u}.`,{cause:A,details:se("model3",u)})}let g=Rr(s.idleMotion,A=>d.getMotionCount(A));return o=new Al(e,u,d,r,i,g,a,c,n,s.resolveAsset),await o.initialize(s.signal),n&&n.loadPhase("ready",performance.now()-l),o.toHandle()}catch(u){throw o?o.toHandle().dispose():a(),s.signal?.aborted?s.signal.reason:dn(u,`Failed to load ${t}`)}}var S,zr,ps,Jr,ms,jr,_s,Zr,x,qr,M,Kr,ne,$r,Kn,At,k,Ht,de,O,D,rr,ei,fe,$n,V,Lt,ea,ti,ta,ri,ra,Cs,ii,dt,si,pt,ia,R,sa,ni,na,gt,aa,U,G,ft,K,Ve,Ye,Fe,ir,Oe,ai,Z,xe,Ee,Ge,$,P,oi,la,ys,li,sr,De,ui,nr,ua,hi,zt,Ie,ci,ar,di,ha,Tt,gi,fi,ca,da,Jt,jt,Ai,Ft,pi,Ms,mi,ws,_i,Se,Ci,or,yi,ga,xs,bi,fa,Aa,Bi,pa,ma,tt,_a,Ca,ya,Ii,Te,ba,Es,Si,Ba,Ia,ze,vs,Ps,Rs,Ds,Mi,N,Sa,Ma,wa,xa,Ea,va,Pa,he,Ra,Da,rt,it,wi,xi,La,Ta,Fa,Oa,Ls,Ei,Va,ka,Qa,Ua,Na,st,Ga,Vs,vi,Qs,Pi,Ya,za,Ja,lr,Zt,Us,Ns,Gs,Xs,Hs,Ri,Xe,Vt,kt,Qt,Di,Li,ce,nt,ja,Za,qa,Ti,Fi,Ka,$a,L,ve,Oi,Vi,ki,Qi,Ui,He,eo,ye,to,ro,io,be,so,no,ao,oo,Ws,Ni,Gi,Xi,Hi,lo,qt,Wi,uo,Kt,zs,Yi,zi,Nt,Mo,wo,xo,Ae,Ji,Eo,vo,hr,ji,Po,Ro,Do,Lo,To,Fo,Oo,Vo,ko,Qo,Uo,No,Go,Xo,Ho,Pe,Zi,Wo,Yo,Js,q,Zs,zo,qi,at,Gt,ct,qs,Jo,cr,Ki,er,$i,es,jo,Zo,Xt,qo,Ko,$o,$s,ts,el,en,tr,rs,rn,is,ge,ss,nn,ns,an,as,on,os,ln,ls,un,us,hn,hs,cn,cs,ot,ol,We,hl,cl,dl,fs,gl,fl,Al,fn=_e(()=>{Me();wt();Dt();S=Object.freeze({HitAreaPrefix:"HitArea",HitAreaHead:"Head",HitAreaBody:"Body",PartsIdCore:"Parts01Core",PartsArmPrefix:"Parts01Arm_",PartsArmLPrefix:"Parts01ArmL_",PartsArmRPrefix:"Parts01ArmR_",ParamAngleX:"ParamAngleX",ParamAngleY:"ParamAngleY",ParamAngleZ:"ParamAngleZ",ParamEyeLOpen:"ParamEyeLOpen",ParamEyeLSmile:"ParamEyeLSmile",ParamEyeROpen:"ParamEyeROpen",ParamEyeRSmile:"ParamEyeRSmile",ParamEyeBallX:"ParamEyeBallX",ParamEyeBallY:"ParamEyeBallY",ParamEyeBallForm:"ParamEyeBallForm",ParamBrowLY:"ParamBrowLY",ParamBrowRY:"ParamBrowRY",ParamBrowLX:"ParamBrowLX",ParamBrowRX:"ParamBrowRX",ParamBrowLAngle:"ParamBrowLAngle",ParamBrowRAngle:"ParamBrowRAngle",ParamBrowLForm:"ParamBrowLForm",ParamBrowRForm:"ParamBrowRForm",ParamMouthForm:"ParamMouthForm",ParamMouthOpenY:"ParamMouthOpenY",ParamCheek:"ParamCheek",ParamBodyAngleX:"ParamBodyAngleX",ParamBodyAngleY:"ParamBodyAngleY",ParamBodyAngleZ:"ParamBodyAngleZ",ParamBreath:"ParamBreath",ParamArmLA:"ParamArmLA",ParamArmRA:"ParamArmRA",ParamArmLB:"ParamArmLB",ParamArmRB:"ParamArmRB",ParamHandL:"ParamHandL",ParamHandR:"ParamHandR",ParamHairFront:"ParamHairFront",ParamHairSide:"ParamHairSide",ParamHairBack:"ParamHairBack",ParamHairFluffy:"ParamHairFluffy",ParamShoulderY:"ParamShoulderY",ParamBustX:"ParamBustX",ParamBustY:"ParamBustY",ParamBaseX:"ParamBaseX",ParamBaseY:"ParamBaseY",ParamNONE:"NONE:"});(function(e){e.HitAreaBody=S.HitAreaBody,e.HitAreaHead=S.HitAreaHead,e.HitAreaPrefix=S.HitAreaPrefix,e.ParamAngleX=S.ParamAngleX,e.ParamAngleY=S.ParamAngleY,e.ParamAngleZ=S.ParamAngleZ,e.ParamArmLA=S.ParamArmLA,e.ParamArmLB=S.ParamArmLB,e.ParamArmRA=S.ParamArmRA,e.ParamArmRB=S.ParamArmRB,e.ParamBaseX=S.ParamBaseX,e.ParamBaseY=S.ParamBaseY,e.ParamBodyAngleX=S.ParamBodyAngleX,e.ParamBodyAngleY=S.ParamBodyAngleY,e.ParamBodyAngleZ=S.ParamBodyAngleZ,e.ParamBreath=S.ParamBreath,e.ParamBrowLAngle=S.ParamBrowLAngle,e.ParamBrowLForm=S.ParamBrowLForm,e.ParamBrowLX=S.ParamBrowLX,e.ParamBrowLY=S.ParamBrowLY,e.ParamBrowRAngle=S.ParamBrowRAngle,e.ParamBrowRForm=S.ParamBrowRForm,e.ParamBrowRX=S.ParamBrowRX,e.ParamBrowRY=S.ParamBrowRY,e.ParamBustX=S.ParamBustX,e.ParamBustY=S.ParamBustY,e.ParamCheek=S.ParamCheek,e.ParamEyeBallForm=S.ParamEyeBallForm,e.ParamEyeBallX=S.ParamEyeBallX,e.ParamEyeBallY=S.ParamEyeBallY,e.ParamEyeLOpen=S.ParamEyeLOpen,e.ParamEyeLSmile=S.ParamEyeLSmile,e.ParamEyeROpen=S.ParamEyeROpen,e.ParamEyeRSmile=S.ParamEyeRSmile,e.ParamHairBack=S.ParamHairBack,e.ParamHairFluffy=S.ParamHairFluffy,e.ParamHairFront=S.ParamHairFront,e.ParamHairSide=S.ParamHairSide,e.ParamHandL=S.ParamHandL,e.ParamHandR=S.ParamHandR,e.ParamMouthForm=S.ParamMouthForm,e.ParamMouthOpenY=S.ParamMouthOpenY,e.ParamNONE=S.ParamNONE,e.ParamShoulderY=S.ParamShoulderY,e.PartsArmLPrefix=S.PartsArmLPrefix,e.PartsArmPrefix=S.PartsArmPrefix,e.PartsArmRPrefix=S.PartsArmRPrefix,e.PartsIdCore=S.PartsIdCore})(zr||(zr={}));ps=class{};(function(e){e.ICubismModelSetting=ps})(Jr||(Jr={}));ms=class lt{static createIdInternal(t){return new lt(t)}getString(){return this._id}isEqual(t){return typeof t=="string"?this._id==t:t instanceof lt?this._id==t._id:!1}isNotEqual(t){return typeof t=="string"?this._id!=t:t instanceof lt?this._id!=t._id:!1}constructor(t){this._id=t}_id};(function(e){e.CubismId=ms})(jr||(jr={}));_s=class{constructor(){this._ids=new Array}release(){for(let e=0;e<this._ids.length;++e)this._ids[e]=void 0;this._ids=null}registerIds(e){for(let t=0;t<e.length;t++)this.registerId(e[t])}registerId(e){let t=null;if(typeof e=="string"){if((t=this.findId(e))!=null)return t;t=ms.createIdInternal(e),this._ids.push(t)}else return this.registerId(e);return t}getId(e){return this.registerId(e)}isExist(e){return typeof e=="string"?this.findId(e)!=null:this.isExist(e)}findId(e){for(let t=0;t<this._ids.length;++t)if(this._ids[t].getString()==e)return this._ids[t];return null}_ids};(function(e){e.CubismIdManager=_s})(Zr||(Zr={}));x=class Be{x;y;constructor(t,r){this.x=t,this.y=r,this.x=t??0,this.y=r??0}add(t){let r=new Be(0,0);return r.x=this.x+t.x,r.y=this.y+t.y,r}substract(t){let r=new Be(0,0);return r.x=this.x-t.x,r.y=this.y-t.y,r}multiply(t){let r=new Be(0,0);return r.x=this.x*t.x,r.y=this.y*t.y,r}multiplyByScaler(t){return this.multiply(new Be(t,t))}division(t){let r=new Be(0,0);return r.x=this.x/t.x,r.y=this.y/t.y,r}divisionByScalar(t){return this.division(new Be(t,t))}getLength(){return Math.sqrt(this.x*this.x+this.y*this.y)}getDistanceWith(t){return Math.sqrt((this.x-t.x)*(this.x-t.x)+(this.y-t.y)*(this.y-t.y))}dot(t){return this.x*t.x+this.y*t.y}normalize(){let 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)}};(function(e){e.CubismVector2=x})(qr||(qr={}));M=class ut{static Epsilon=1e-5;static range(t,r,i){return t<r?t=r:t>i&&(t=i),t}static sin(t){return Math.sin(t)}static cos(t){return Math.cos(t)}static abs(t){return Math.abs(t)}static sqrt(t){return Math.sqrt(t)}static cbrt(t){if(t===0)return t;let r=t,i=r<0;i&&(r=-r);let s;return r===1/0?s=1/0:(s=Math.exp(Math.log(r)/3),s=(r/(s*s)+2*s)/3),i?-s:s}static getEasingSine(t){return t<0?0:t>1?1:.5-.5*this.cos(t*Math.PI)}static max(t,r){return t>r?t:r}static min(t,r){return t>r?r:t}static clamp(t,r,i){return t<r?r:i<t?i:t}static degreesToRadian(t){return t/180*Math.PI}static radianToDegrees(t){return t*180/Math.PI}static directionToRadian(t,r){let i=Math.atan2(r.y,r.x)-Math.atan2(t.y,t.x);for(;i<-Math.PI;)i+=Math.PI*2;for(;i>Math.PI;)i-=Math.PI*2;return i}static directionToDegrees(t,r){let i=this.directionToRadian(t,r),s=this.radianToDegrees(i);return r.x-t.x>0&&(s=-s),s}static radianToDirection(t){let r=new x;return r.x=this.sin(t),r.y=this.cos(t),r}static quadraticEquation(t,r,i){return this.abs(t)<ut.Epsilon?this.abs(r)<ut.Epsilon?-i:-i/r:-(r+this.sqrt(r*r-4*t*i))/(2*t)}static cardanoAlgorithmForBezier(t,r,i,s){if(this.abs(t)<ut.Epsilon)return this.range(this.quadraticEquation(r,i,s),0,1);let n=r/t,a=i/t,l=s/t,o=(3*a-n*n)/3,u=o/3,h=(2*n*n*n-9*n*a+27*l)/27,d=h/2,c=d*d+u*u*u,g=.5,A=.51;if(c<0){let _=-o/3,y=_*_*_,C=this.sqrt(y),b=-h/(2*C),w=this.range(b,-1,1),B=Math.acos(w),E=2*this.cbrt(C),T=E*this.cos(B/3)-n/3;if(this.abs(T-g)<A)return this.range(T,0,1);let W=E*this.cos((B+2*Math.PI)/3)-n/3;if(this.abs(W-g)<A)return this.range(W,0,1);let ee=E*this.cos((B+4*Math.PI)/3)-n/3;return this.range(ee,0,1)}if(c==0){let _;d<0?_=this.cbrt(-d):_=-this.cbrt(d);let y=2*_-n/3;if(this.abs(y-g)<A)return this.range(y,0,1);let C=-_-n/3;return this.range(C,0,1)}let p=this.sqrt(c),f=this.cbrt(p-d)-this.cbrt(p+d)-n/3;return this.range(f,0,1)}static mod(t,r){if(!isFinite(t)||r===0||isNaN(t)||isNaN(r))return console.warn(`divided: ${t}, divisor: ${r} mod() returns 'NaN'.`),NaN;let i=Math.abs(t),s=Math.abs(r),n=i-Math.floor(i/s)*s;return n*=Math.sign(t),n}constructor(){}};(function(e){e.CubismMath=M})(Kr||(Kr={}));ne=class Re{constructor(){this._tr=new Float32Array(16),this.loadIdentity()}static multiply(t,r,i){let s=new Float32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),n=4;for(let a=0;a<n;++a)for(let l=0;l<n;++l)for(let o=0;o<n;++o)s[l+a*4]+=t[o+a*4]*r[l+o*4];for(let a=0;a<16;++a)i[a]=s[a]}loadIdentity(){let 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 r=0;r<16;++r)this._tr[r]=t[r]}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,r){let i=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,t,r,0,1]);Re.multiply(i,this._tr,this._tr)}translate(t,r){this._tr[12]=t,this._tr[13]=r}translateX(t){this._tr[12]=t}translateY(t){this._tr[13]=t}scaleRelative(t,r){let i=new Float32Array([t,0,0,0,0,r,0,0,0,0,1,0,0,0,0,1]);Re.multiply(i,this._tr,this._tr)}scale(t,r){this._tr[0]=t,this._tr[5]=r}multiplyByMatrix(t){Re.multiply(t.getArray(),this._tr,this._tr)}getInvert(){let t=this._tr[0],r=this._tr[1],i=this._tr[2],s=this._tr[4],n=this._tr[5],a=this._tr[6],l=this._tr[8],o=this._tr[9],u=this._tr[10],h=this._tr[12],d=this._tr[13],c=this._tr[14],g=t*(n*u-o*a)-s*(r*u-o*i)+l*(r*a-n*i),A=new Re;if(M.abs(g)<M.Epsilon)return A.loadIdentity(),A;let p=1/g,f=(n*u-o*a)*p,_=-(s*u-l*a)*p,y=(s*o-l*n)*p,C=-(r*u-o*i)*p,b=(t*u-l*i)*p,w=-(t*o-l*r)*p,B=(r*a-n*i)*p,E=-(t*a-s*i)*p,T=(t*n-s*r)*p;return A._tr[0]=f,A._tr[1]=C,A._tr[2]=B,A._tr[3]=0,A._tr[4]=_,A._tr[5]=b,A._tr[6]=E,A._tr[7]=0,A._tr[8]=y,A._tr[9]=w,A._tr[10]=T,A._tr[11]=0,A._tr[12]=-(f*h+_*d+y*c),A._tr[13]=-(C*h+b*d+w*c),A._tr[14]=-(B*h+E*d+T*c),A._tr[15]=1,A}clone(){let t=new Re;for(let r=0;r<this._tr.length;r++)t._tr[r]=this._tr[r];return t}_tr};(function(e){e.CubismMatrix44=ne})($r||($r={}));Kn=(e,t,r)=>{rr.print(e,"[CSM]"+t,r)},At=(e,t,r)=>{Kn(e,t+`
3
+ `,r)},k=e=>{e||console.assert(e)};Ht=(e,...t)=>{At(1,"[D]"+e,t)};de=(e,...t)=>{At(2,"[I]"+e,t)};O=(e,...t)=>{At(3,"[W]"+e,t)};D=(e,...t)=>{At(4,"[E]"+e,t)};rr=class{static print(e,t,r){if(e<P.getLoggingLevel())return;let i=P.coreLogFunction;i&&i(t.replace(/\{(\d+)\}/g,(s,n)=>r[n]))}static dumpBytes(e,t,r){for(let i=0;i<r;i++)i%16==0&&i>0?this.print(e,`
4
4
  `):i%8==0&&i>0&&this.print(e," "),this.print(e,"{0} ",[t[i]&255]);this.print(e,`
5
- `)}constructor(){}};(function(e){e.CubismDebug=rr})(ei||(ei={}));fe=class{constructor(e=!1,t=new R){this.isOverridden=e,this.color=t}isOverridden;color},jn=class{_model;_isOverriddenModelMultiplyColors;_isOverriddenModelScreenColors;_userPartScreenColors;_userPartMultiplyColors;_userDrawableScreenColors;_userDrawableMultiplyColors;_userOffscreenScreenColors;_userOffscreenMultiplyColors;constructor(e){this._model=e,this._isOverriddenModelMultiplyColors=!1,this._isOverriddenModelScreenColors=!1,this._userPartScreenColors=[],this._userPartMultiplyColors=[],this._userDrawableScreenColors=[],this._userDrawableMultiplyColors=[],this._userOffscreenScreenColors=[],this._userOffscreenMultiplyColors=[]}initialize(e,t,r){let i=new fe(!1,new R(1,1,1,1)),s=new fe(!1,new R(0,0,0,1));this._userPartMultiplyColors=new Array(e),this._userPartScreenColors=new Array(e);for(let n=0;n<e;n++)this._userPartMultiplyColors[n]=new fe(i.isOverridden,new R(i.color.r,i.color.g,i.color.b,i.color.a)),this._userPartScreenColors[n]=new fe(s.isOverridden,new R(s.color.r,s.color.g,s.color.b,s.color.a));this._userDrawableMultiplyColors=new Array(t),this._userDrawableScreenColors=new Array(t);for(let n=0;n<t;n++)this._userDrawableMultiplyColors[n]=new fe(i.isOverridden,new R(i.color.r,i.color.g,i.color.b,i.color.a)),this._userDrawableScreenColors[n]=new fe(s.isOverridden,new R(s.color.r,s.color.g,s.color.b,s.color.a));this._userOffscreenMultiplyColors=new Array(r),this._userOffscreenScreenColors=new Array(r);for(let n=0;n<r;n++)this._userOffscreenMultiplyColors[n]=new fe(i.isOverridden,new R(i.color.r,i.color.g,i.color.b,i.color.a)),this._userOffscreenScreenColors[n]=new fe(s.isOverridden,new R(s.color.r,s.color.g,s.color.b,s.color.a))}warnIndexOutOfRange(e,t,r){V(`${e}: index is out of range. index=${t}, valid range=[0, ${r}].`)}isValidPartIndex(e,t){return e<0||e>=this._model.getPartCount()?(this.warnIndexOutOfRange(t,e,this._model.getPartCount()-1),!1):!0}isValidDrawableIndex(e,t){return e<0||e>=this._model.getDrawableCount()?(this.warnIndexOutOfRange(t,e,this._model.getDrawableCount()-1),!1):!0}isValidOffscreenIndex(e,t){return e<0||e>=this._model.getOffscreenCount()?(this.warnIndexOutOfRange(t,e,this._model.getOffscreenCount()-1),!1):!0}setMultiplyColorEnabled(e){this._isOverriddenModelMultiplyColors=e}getMultiplyColorEnabled(){return this._isOverriddenModelMultiplyColors}setScreenColorEnabled(e){this._isOverriddenModelScreenColors=e}getScreenColorEnabled(){return this._isOverriddenModelScreenColors}setPartMultiplyColorEnabled(e,t){this.isValidPartIndex(e,"setPartMultiplyColorEnabled")&&this.setPartColorEnabled(e,t,this._userPartMultiplyColors,this._userDrawableMultiplyColors,this._userOffscreenMultiplyColors)}getPartMultiplyColorEnabled(e){return this.isValidPartIndex(e,"getPartMultiplyColorEnabled")?this._userPartMultiplyColors[e].isOverridden:!1}setPartScreenColorEnabled(e,t){this.isValidPartIndex(e,"setPartScreenColorEnabled")&&this.setPartColorEnabled(e,t,this._userPartScreenColors,this._userDrawableScreenColors,this._userOffscreenScreenColors)}getPartScreenColorEnabled(e){return this.isValidPartIndex(e,"getPartScreenColorEnabled")?this._userPartScreenColors[e].isOverridden:!1}setPartMultiplyColorByTextureColor(e,t){this.isValidPartIndex(e,"setPartMultiplyColorByTextureColor")&&this.setPartMultiplyColorByRGBA(e,t.r,t.g,t.b,t.a)}setPartMultiplyColorByRGBA(e,t,r,i,s=1){this.isValidPartIndex(e,"setPartMultiplyColorByRGBA")&&this.setPartColor(e,t,r,i,s,this._userPartMultiplyColors,this._userDrawableMultiplyColors,this._userOffscreenMultiplyColors)}getPartMultiplyColor(e){return this.isValidPartIndex(e,"getPartMultiplyColor")?this._userPartMultiplyColors[e].color:new R(1,1,1,1)}setPartScreenColorByTextureColor(e,t){this.isValidPartIndex(e,"setPartScreenColorByTextureColor")&&this.setPartScreenColorByRGBA(e,t.r,t.g,t.b,t.a)}setPartScreenColorByRGBA(e,t,r,i,s=1){this.isValidPartIndex(e,"setPartScreenColorByRGBA")&&this.setPartColor(e,t,r,i,s,this._userPartScreenColors,this._userDrawableScreenColors,this._userOffscreenScreenColors)}getPartScreenColor(e){return this.isValidPartIndex(e,"getPartScreenColor")?this._userPartScreenColors[e].color:new R(0,0,0,1)}setDrawableMultiplyColorEnabled(e,t){this.isValidDrawableIndex(e,"setDrawableMultiplyColorEnabled")&&(this._userDrawableMultiplyColors[e].isOverridden=t)}getDrawableMultiplyColorEnabled(e){return this.isValidDrawableIndex(e,"getDrawableMultiplyColorEnabled")?this._userDrawableMultiplyColors[e].isOverridden:!1}setDrawableScreenColorEnabled(e,t){this.isValidDrawableIndex(e,"setDrawableScreenColorEnabled")&&(this._userDrawableScreenColors[e].isOverridden=t)}getDrawableScreenColorEnabled(e){return this.isValidDrawableIndex(e,"getDrawableScreenColorEnabled")?this._userDrawableScreenColors[e].isOverridden:!1}setDrawableMultiplyColorByTextureColor(e,t){this.isValidDrawableIndex(e,"setDrawableMultiplyColorByTextureColor")&&this.setDrawableMultiplyColorByRGBA(e,t.r,t.g,t.b,t.a)}setDrawableMultiplyColorByRGBA(e,t,r,i,s=1){this.isValidDrawableIndex(e,"setDrawableMultiplyColorByRGBA")&&(this._userDrawableMultiplyColors[e].color.r=t,this._userDrawableMultiplyColors[e].color.g=r,this._userDrawableMultiplyColors[e].color.b=i,this._userDrawableMultiplyColors[e].color.a=s)}getDrawableMultiplyColor(e){return this.isValidDrawableIndex(e,"getDrawableMultiplyColor")?this.getMultiplyColorEnabled()||this.getDrawableMultiplyColorEnabled(e)?this._userDrawableMultiplyColors[e].color:this._model.getDrawableMultiplyColor(e):new R(1,1,1,1)}setDrawableScreenColorByTextureColor(e,t){this.isValidDrawableIndex(e,"setDrawableScreenColorByTextureColor")&&this.setDrawableScreenColorByRGBA(e,t.r,t.g,t.b,t.a)}setDrawableScreenColorByRGBA(e,t,r,i,s=1){this.isValidDrawableIndex(e,"setDrawableScreenColorByRGBA")&&(this._userDrawableScreenColors[e].color.r=t,this._userDrawableScreenColors[e].color.g=r,this._userDrawableScreenColors[e].color.b=i,this._userDrawableScreenColors[e].color.a=s)}getDrawableScreenColor(e){return this.isValidDrawableIndex(e,"getDrawableScreenColor")?this.getScreenColorEnabled()||this.getDrawableScreenColorEnabled(e)?this._userDrawableScreenColors[e].color:this._model.getDrawableScreenColor(e):new R(0,0,0,1)}setOffscreenMultiplyColorEnabled(e,t){this.isValidOffscreenIndex(e,"setOffscreenMultiplyColorEnabled")&&(this._userOffscreenMultiplyColors[e].isOverridden=t)}getOffscreenMultiplyColorEnabled(e){return this.isValidOffscreenIndex(e,"getOffscreenMultiplyColorEnabled")?this._userOffscreenMultiplyColors[e].isOverridden:!1}setOffscreenScreenColorEnabled(e,t){this.isValidOffscreenIndex(e,"setOffscreenScreenColorEnabled")&&(this._userOffscreenScreenColors[e].isOverridden=t)}getOffscreenScreenColorEnabled(e){return this.isValidOffscreenIndex(e,"getOffscreenScreenColorEnabled")?this._userOffscreenScreenColors[e].isOverridden:!1}setOffscreenMultiplyColorByTextureColor(e,t){this.isValidOffscreenIndex(e,"setOffscreenMultiplyColorByTextureColor")&&this.setOffscreenMultiplyColorByRGBA(e,t.r,t.g,t.b,t.a)}setOffscreenMultiplyColorByRGBA(e,t,r,i,s=1){this.isValidOffscreenIndex(e,"setOffscreenMultiplyColorByRGBA")&&(this._userOffscreenMultiplyColors[e].color.r=t,this._userOffscreenMultiplyColors[e].color.g=r,this._userOffscreenMultiplyColors[e].color.b=i,this._userOffscreenMultiplyColors[e].color.a=s)}getOffscreenMultiplyColor(e){return this.isValidOffscreenIndex(e,"getOffscreenMultiplyColor")?this.getMultiplyColorEnabled()||this.getOffscreenMultiplyColorEnabled(e)?this._userOffscreenMultiplyColors[e].color:this._model.getOffscreenMultiplyColor(e):new R(1,1,1,1)}setOffscreenScreenColorByTextureColor(e,t){this.isValidOffscreenIndex(e,"setOffscreenScreenColorByTextureColor")&&this.setOffscreenScreenColorByRGBA(e,t.r,t.g,t.b,t.a)}setOffscreenScreenColorByRGBA(e,t,r,i,s=1){this.isValidOffscreenIndex(e,"setOffscreenScreenColorByRGBA")&&(this._userOffscreenScreenColors[e].color.r=t,this._userOffscreenScreenColors[e].color.g=r,this._userOffscreenScreenColors[e].color.b=i,this._userOffscreenScreenColors[e].color.a=s)}getOffscreenScreenColor(e){return this.isValidOffscreenIndex(e,"getOffscreenScreenColor")?this.getScreenColorEnabled()||this.getOffscreenScreenColorEnabled(e)?this._userOffscreenScreenColors[e].color:this._model.getOffscreenScreenColor(e):new R(0,0,0,1)}setPartColor(e,t,r,i,s,n,a,l){if(n[e].color.r=t,n[e].color.g=r,n[e].color.b=i,n[e].color.a=s,n[e].isOverridden){let o=this._model.getPartOffscreenIndices()[e];if(o==-1){let u=this._model.getPartsHierarchy();if(u&&u[e])for(let c=0;c<u[e].objects.length;++c){let d=u[e].objects[c];if(d.objectType===0){let h=d.objectIndex;a[h].color.r=t,a[h].color.g=r,a[h].color.b=i,a[h].color.a=s}else{let h=d.objectIndex;this.setPartColor(h,t,r,i,s,n,a,l)}}}else l[o].color.r=t,l[o].color.g=r,l[o].color.b=i,l[o].color.a=s}}setPartColorEnabled(e,t,r,i,s){r[e].isOverridden=t;let n=this._model.getPartOffscreenIndices()[e];if(n==-1){let a=this._model.getPartsHierarchy();if(a&&a[e])for(let l=0;l<a[e].objects.length;++l){let o=a[e].objects[l];if(o.objectType===0){let u=o.objectIndex;i[u].isOverridden=t,t&&(i[u].color.r=r[e].color.r,i[u].color.g=r[e].color.g,i[u].color.b=r[e].color.b,i[u].color.a=r[e].color.a)}else{let u=o.objectIndex;t&&(r[u].color.r=r[e].color.r,r[u].color.g=r[e].color.g,r[u].color.b=r[e].color.b,r[u].color.a=r[e].color.a),this.setPartColorEnabled(u,t,r,i,s)}}}else s[n].isOverridden=t,t&&(s[n].color.r=r[e].color.r,s[n].color.g=r[e].color.g,s[n].color.b=r[e].color.b,s[n].color.a=r[e].color.a)}},O=(function(e){return e[e.ColorBlend_None=-1]="ColorBlend_None",e[e.ColorBlend_Normal=Live2DCubismCore.ColorBlendType_Normal]="ColorBlend_Normal",e[e.ColorBlend_AddGlow=Live2DCubismCore.ColorBlendType_AddGlow]="ColorBlend_AddGlow",e[e.ColorBlend_Add=Live2DCubismCore.ColorBlendType_Add]="ColorBlend_Add",e[e.ColorBlend_Darken=Live2DCubismCore.ColorBlendType_Darken]="ColorBlend_Darken",e[e.ColorBlend_Multiply=Live2DCubismCore.ColorBlendType_Multiply]="ColorBlend_Multiply",e[e.ColorBlend_ColorBurn=Live2DCubismCore.ColorBlendType_ColorBurn]="ColorBlend_ColorBurn",e[e.ColorBlend_LinearBurn=Live2DCubismCore.ColorBlendType_LinearBurn]="ColorBlend_LinearBurn",e[e.ColorBlend_Lighten=Live2DCubismCore.ColorBlendType_Lighten]="ColorBlend_Lighten",e[e.ColorBlend_Screen=Live2DCubismCore.ColorBlendType_Screen]="ColorBlend_Screen",e[e.ColorBlend_ColorDodge=Live2DCubismCore.ColorBlendType_ColorDodge]="ColorBlend_ColorDodge",e[e.ColorBlend_Overlay=Live2DCubismCore.ColorBlendType_Overlay]="ColorBlend_Overlay",e[e.ColorBlend_SoftLight=Live2DCubismCore.ColorBlendType_SoftLight]="ColorBlend_SoftLight",e[e.ColorBlend_HardLight=Live2DCubismCore.ColorBlendType_HardLight]="ColorBlend_HardLight",e[e.ColorBlend_LinearLight=Live2DCubismCore.ColorBlendType_LinearLight]="ColorBlend_LinearLight",e[e.ColorBlend_Hue=Live2DCubismCore.ColorBlendType_Hue]="ColorBlend_Hue",e[e.ColorBlend_Color=Live2DCubismCore.ColorBlendType_Color]="ColorBlend_Color",e[e.ColorBlend_AddCompatible=Live2DCubismCore.ColorBlendType_AddCompatible]="ColorBlend_AddCompatible",e[e.ColorBlend_MultiplyCompatible=Live2DCubismCore.ColorBlendType_MultiplyCompatible]="ColorBlend_MultiplyCompatible",e})({}),Lt=(function(e){return e[e.AlphaBlend_None=-1]="AlphaBlend_None",e[e.AlphaBlend_Over=0]="AlphaBlend_Over",e[e.AlphaBlend_Atop=1]="AlphaBlend_Atop",e[e.AlphaBlend_Out=2]="AlphaBlend_Out",e[e.AlphaBlend_ConjointOver=3]="AlphaBlend_ConjointOver",e[e.AlphaBlend_DisjointOver=4]="AlphaBlend_DisjointOver",e})({}),Zn=class{constructor(e=!1,t=!1){this.isOverridden=e,this.isParameterRepeated=t}isOverridden;isParameterRepeated},ti=class{constructor(e=!1,t=!1){this.isOverridden=e,this.isCulling=t}isOverridden;isCulling},qn=class{drawableIndices;offscreenIndices;constructor(e=new Array,t=new Array){this.drawableIndices=e,this.offscreenIndices=t}},ri=class{objectType;objectIndex;constructor(e,t){this.objectIndex=e,this.objectType=t}},Kn=class{objects;childDrawObjects;constructor(e=new Array,t=new qn){this.objects=e,this.childDrawObjects=t}getChildObjectCount(){return this.objects.length}},Cs=class{update(){this._model.update(),this._model.drawables.resetDynamicFlags()}getPixelsPerUnit(){return this._model==null?0:this._model.canvasinfo.PixelsPerUnit}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(){let e=this._model.parameters.count,t=this._savedParameters.length;for(let r=0;r<e;++r)r<t?this._savedParameters[r]=this._parameterValues[r]:this._savedParameters.push(this._parameterValues[r])}getOverrideMultiplyAndScreenColor(){return this._overrideMultiplyAndScreenColor}getOverrideFlagForModelParameterRepeat(){return this._isOverriddenParameterRepeat}setOverrideFlagForModelParameterRepeat(e){this._isOverriddenParameterRepeat=e}getOverrideFlagForParameterRepeat(e){return this._userParameterRepeatDataList[e].isOverridden}setOverrideFlagForParameterRepeat(e,t){this._userParameterRepeatDataList[e].isOverridden=t}getRepeatFlagForParameterRepeat(e){return this._userParameterRepeatDataList[e].isParameterRepeated}setRepeatFlagForParameterRepeat(e,t){this._userParameterRepeatDataList[e].isParameterRepeated=t}getDrawableCulling(e){if(this.getOverrideFlagForModelCullings()||this.getOverrideFlagForDrawableCullings(e))return this._userDrawableCullings[e].isCulling;let t=this._model.drawables.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(t[e])}setDrawableCulling(e,t){this._userDrawableCullings[e].isCulling=t}getOffscreenCulling(e){if(this.getOverrideFlagForModelCullings()||this.getOverrideFlagForOffscreenCullings(e))return this._userOffscreenCullings[e].isCulling;let t=this._model.offscreens.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(t[e])}setOffscreenCulling(e,t){this._userOffscreenCullings[e].isCulling=t}getOverrideFlagForModelCullings(){return this._isOverriddenCullings}setOverrideFlagForModelCullings(e){this._isOverriddenCullings=e}getOverrideFlagForDrawableCullings(e){return this._userDrawableCullings[e].isOverridden}getOverrideFlagForOffscreenCullings(e){return this._userOffscreenCullings[e].isOverridden}setOverrideFlagForDrawableCullings(e,t){this._userDrawableCullings[e].isOverridden=t}getModelOapcity(){return this._modelOpacity}setModelOapcity(e){this._modelOpacity=e}getModel(){return this._model}getPartIndex(e){let t,r=this._model.parts.count;for(t=0;t<r;++t)if(e==this._partIds[t])return t;return this._notExistPartId.has(e)?this._notExistPartId.get(e):(t=r+this._notExistPartId.size,this._notExistPartId.set(e,t),this._notExistPartOpacities.set(t,null),t)}getPartId(e){let t=this._model.parts.ids[e];return P.getIdManager().getId(t)}getPartCount(){return this._model.parts.count}getPartOffscreenIndices(){return this._model.parts.offscreenIndices}getPartParentPartIndices(){return this._model.parts.parentIndices}setPartOpacityByIndex(e,t){if(this._notExistPartOpacities.has(e)){this._notExistPartOpacities.set(e,t);return}k(0<=e&&e<this.getPartCount()),this._partOpacities[e]=t}setPartOpacityById(e,t){let r=this.getPartIndex(e);r<0||this.setPartOpacityByIndex(r,t)}getPartOpacityByIndex(e){return this._notExistPartOpacities.has(e)?this._notExistPartOpacities.get(e):(k(0<=e&&e<this.getPartCount()),this._partOpacities[e])}getPartOpacityById(e){let t=this.getPartIndex(e);return t<0?0:this.getPartOpacityByIndex(t)}getParameterIndex(e){let t,r=this._model.parameters.count;for(t=0;t<r;++t)if(e==this._parameterIds[t])return t;return this._notExistParameterId.has(e)?this._notExistParameterId.get(e):(t=this._model.parameters.count+this._notExistParameterId.size,this._notExistParameterId.set(e,t),this._notExistParameterValues.set(t,null),t)}getParameterCount(){return this._model.parameters.count}getParameterType(e){return this._model.parameters.types[e]}getParameterMaximumValue(e){return this._model.parameters.maximumValues[e]}getParameterMinimumValue(e){return this._model.parameters.minimumValues[e]}getParameterDefaultValue(e){return this._model.parameters.defaultValues[e]}getParameterId(e){return P.getIdManager().getId(this._model.parameters.ids[e])}getParameterValueByIndex(e){return this._notExistParameterValues.has(e)?this._notExistParameterValues.get(e):(k(0<=e&&e<this.getParameterCount()),this._parameterValues[e])}getParameterValueById(e){let t=this.getParameterIndex(e);return this.getParameterValueByIndex(t)}setParameterValueByIndex(e,t,r=1){if(this._notExistParameterValues.has(e)){this._notExistParameterValues.set(e,r==1?t:this._notExistParameterValues.get(e)*(1-r)+t*r);return}k(0<=e&&e<this.getParameterCount()),this.isRepeat(e)?t=this.getParameterRepeatValue(e,t):t=this.getParameterClampValue(e,t),this._parameterValues[e]=r==1?t:this._parameterValues[e]=this._parameterValues[e]*(1-r)+t*r}setParameterValueById(e,t,r=1){let i=this.getParameterIndex(e);this.setParameterValueByIndex(i,t,r)}addParameterValueByIndex(e,t,r=1){this.setParameterValueByIndex(e,this.getParameterValueByIndex(e)+t*r)}addParameterValueById(e,t,r=1){let i=this.getParameterIndex(e);this.addParameterValueByIndex(i,t,r)}isRepeat(e){if(this._notExistParameterValues.has(e))return!1;k(0<=e&&e<this.getParameterCount());let t;return this._isOverriddenParameterRepeat||this._userParameterRepeatDataList[e].isOverridden?t=this._userParameterRepeatDataList[e].isParameterRepeated:t=this._model.parameters.repeats[e]!=0,t}getParameterRepeatValue(e,t){if(this._notExistParameterValues.has(e))return t;k(0<=e&&e<this.getParameterCount());let r=this._model.parameters.maximumValues[e],i=this._model.parameters.minimumValues[e],s=r-i;if(r<t){let n=M.mod(t-r,s);Number.isNaN(n)?t=r:t=i+n}if(t<i){let n=M.mod(i-t,s);Number.isNaN(n)?t=i:t=r-n}return t}getParameterClampValue(e,t){if(this._notExistParameterValues.has(e))return t;k(0<=e&&e<this.getParameterCount());let r=this._model.parameters.maximumValues[e],i=this._model.parameters.minimumValues[e];return M.clamp(t,i,r)}getParameterRepeats(e){return this._model.parameters.repeats[e]!=0}multiplyParameterValueById(e,t,r=1){let i=this.getParameterIndex(e);this.multiplyParameterValueByIndex(i,t,r)}multiplyParameterValueByIndex(e,t,r=1){this.setParameterValueByIndex(e,this.getParameterValueByIndex(e)*(1+(t-1)*r))}getDrawableIndex(e){let t=this._model.drawables.count;for(let r=0;r<t;++r)if(this._drawableIds[r]==e)return r;return-1}getDrawableCount(){return this._model.drawables.count}getDrawableId(e){let t=this._model.drawables.ids;return P.getIdManager().getId(t[e])}getRenderOrders(){return this._model.getRenderOrders()}getDrawableTextureIndex(e){return this._model.drawables.textureIndices[e]}getDrawableDynamicFlagVertexPositionsDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVertexPositionsDidChangeBit(t[e])}getDrawableVertexIndexCount(e){return this._model.drawables.indexCounts[e]}getDrawableVertexCount(e){return this._model.drawables.vertexCounts[e]}getDrawableVertices(e){return this.getDrawableVertexPositions(e)}getDrawableVertexIndices(e){return this._model.drawables.indices[e]}getDrawableVertexPositions(e){return this._model.drawables.vertexPositions[e]}getDrawableVertexUvs(e){return this._model.drawables.vertexUvs[e]}getDrawableOpacity(e){return this._model.drawables.opacities[e]}getDrawableMultiplyColor(e){this._drawableMultiplyColors==null&&(this._drawableMultiplyColors=new Array(this._model.drawables.count),this._drawableMultiplyColors.fill(new R));let t=this._model.drawables.multiplyColors,r=e*4;return this._drawableMultiplyColors[e].r=t[r],this._drawableMultiplyColors[e].g=t[r+1],this._drawableMultiplyColors[e].b=t[r+2],this._drawableMultiplyColors[e].a=t[r+3],this._drawableMultiplyColors[e]}getDrawableScreenColor(e){this._drawableScreenColors==null&&(this._drawableScreenColors=new Array(this._model.drawables.count),this._drawableScreenColors.fill(new R));let t=this._model.drawables.screenColors,r=e*4;return this._drawableScreenColors[e].r=t[r],this._drawableScreenColors[e].g=t[r+1],this._drawableScreenColors[e].b=t[r+2],this._drawableScreenColors[e].a=t[r+3],this._drawableScreenColors[e]}getOffscreenMultiplyColor(e){this._offscreenMultiplyColors==null&&(this._offscreenMultiplyColors=new Array(this._model.offscreens.count),this._offscreenMultiplyColors.fill(new R));let t=this._model.offscreens.multiplyColors,r=e*4;return this._offscreenMultiplyColors[e].r=t[r],this._offscreenMultiplyColors[e].g=t[r+1],this._offscreenMultiplyColors[e].b=t[r+2],this._offscreenMultiplyColors[e].a=t[r+3],this._offscreenMultiplyColors[e]}getOffscreenScreenColor(e){this._offscreenScreenColors==null&&(this._offscreenScreenColors=new Array(this._model.offscreens.count),this._offscreenScreenColors.fill(new R));let t=this._model.offscreens.screenColors,r=e*4;return this._offscreenScreenColors[e].r=t[r],this._offscreenScreenColors[e].g=t[r+1],this._offscreenScreenColors[e].b=t[r+2],this._offscreenScreenColors[e].a=t[r+3],this._offscreenScreenColors[e]}getDrawableParentPartIndex(e){return this._model.drawables.parentPartIndices[e]}getDrawableBlendMode(e){let t=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(t[e])?1:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(t[e])?2:0}getDrawableColorBlend(e){return this._drawableColorBlends[e]==-1&&(this._drawableColorBlends[e]=this._model.drawables.blendModes[e]&255),this._drawableColorBlends[e]}getDrawableAlphaBlend(e){return this._drawableAlphaBlends[e]==-1&&(this._drawableAlphaBlends[e]=this._model.drawables.blendModes[e]>>8&255),this._drawableAlphaBlends[e]}getDrawableInvertedMaskBit(e){let t=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(t[e])}getDrawableMasks(){return this._model.drawables.masks}getDrawableMaskCounts(){return this._model.drawables.maskCounts}isUsingMasking(){for(let e=0;e<this._model.drawables.count;++e)if(!(this._model.drawables.maskCounts[e]<=0))return!0;return!1}isUsingMaskingForOffscreen(){for(let e=0;e<this.getOffscreenCount();++e)if(!(this._model.offscreens.maskCounts[e]<=0))return!0;return!1}getDrawableDynamicFlagIsVisible(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasIsVisibleBit(t[e])}getDrawableDynamicFlagVisibilityDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVisibilityDidChangeBit(t[e])}getDrawableDynamicFlagOpacityDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasOpacityDidChangeBit(t[e])}getDrawableDynamicFlagRenderOrderDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasRenderOrderDidChangeBit(t[e])}getDrawableDynamicFlagBlendColorDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasBlendColorDidChangeBit(t[e])}getOffscreenCount(){return this._model.offscreens.count}getOffscreenColorBlend(e){return this._offscreenColorBlends[e]==-1&&(this._offscreenColorBlends[e]=this._model.offscreens.blendModes[e]&255),this._offscreenColorBlends[e]}getOffscreenAlphaBlend(e){return this._offscreenAlphaBlends[e]==-1&&(this._offscreenAlphaBlends[e]=this._model.offscreens.blendModes[e]>>8&255),this._offscreenAlphaBlends[e]}getOffscreenOwnerIndices(){return this._model.offscreens.ownerIndices}getOffscreenOpacity(e){return e<0||e>=this._model.offscreens.count?1:this._model.offscreens.opacities[e]}getOffscreenMasks(){return this._model.offscreens.masks}getOffscreenMaskCounts(){return this._model.offscreens.maskCounts}getOffscreenInvertedMask(e){let t=this._model.offscreens.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(t[e])}isBlendModeEnabled(){return this._isBlendModeEnabled}loadParameters(){let e=this._model.parameters.count,t=this._savedParameters.length;e>t&&(e=t);for(let r=0;r<e;++r)this._parameterValues[r]=this._savedParameters[r]}initialize(){k(this._model),this._parameterValues=this._model.parameters.values,this._partOpacities=this._model.parts.opacities,this._offscreenOpacities=this._model.offscreens.opacities,this._parameterMaximumValues=this._model.parameters.maximumValues,this._parameterMinimumValues=this._model.parameters.minimumValues;{let t=this._model.parameters.ids,r=this._model.parameters.count;this._parameterIds.length=r,this._userParameterRepeatDataList.length=r;for(let i=0;i<r;++i)this._parameterIds[i]=P.getIdManager().getId(t[i]),this._userParameterRepeatDataList[i]=new Zn(!1,!1)}let e=this._model.parts.count;{let t=this._model.parts.ids;this._partIds.length=e;for(let r=0;r<e;++r)this._partIds[r]=P.getIdManager().getId(t[r])}{let t=this._model.drawables.ids,r=this._model.drawables.count;this._userDrawableCullings.length=r;let i=new ti(!1,!1);this._userOffscreenCullings.length=this._model.offscreens.count;let s=new ti(!1,!1);for(let a=0;a<r;++a)this._drawableIds.push(P.getIdManager().getId(t[a])),this._userDrawableCullings[a]=i;for(let a=0;a<this._model.offscreens.count;++a)this._userOffscreenCullings[a]=s;if(this.getOffscreenCount()>0)this._isBlendModeEnabled=!0;else{this._model.drawables.blendModes;for(let a=0;a<r;++a){let l=this.getDrawableColorBlend(a),o=this.getDrawableAlphaBlend(a);if(!(l==O.ColorBlend_Normal&&o==0)&&l!=O.ColorBlend_AddCompatible&&l!=O.ColorBlend_MultiplyCompatible){this._isBlendModeEnabled=!0;break}}}this.setupPartsHierarchy();let n=this.getOffscreenCount();this._overrideMultiplyAndScreenColor.initialize(e,r,n)}}getPartsHierarchy(){return this._partsHierarchy}setupPartsHierarchy(){this._partsHierarchy.length=0;let e=this.getPartCount();this._partsHierarchy.length=e;for(let r=0;r<e;++r){let i=new Kn;this._partsHierarchy[r]=i}for(let r=0;r<e;++r){let i=this.getPartParentPartIndices()[r];if(i!==-1){for(let s=0;s<this._partsHierarchy.length;++s)if(s===i){let n=new ri(r,1);this._partsHierarchy[s].objects.push(n);break}}}let t=this.getDrawableCount();for(let r=0;r<t;++r){let i=this.getDrawableParentPartIndex(r);if(i!==-1){for(let s=0;s<this._partsHierarchy.length;++s)if(s===i){let n=new ri(r,0);this._partsHierarchy[s].objects.push(n);break}}}for(let r=0;r<this._partsHierarchy.length;++r)this.getPartChildDrawObjects(r)}getPartChildDrawObjects(e){if(this._partsHierarchy[e].getChildObjectCount()<1)return this._partsHierarchy[e].childDrawObjects;let t=this._partsHierarchy[e].childDrawObjects;if(t.drawableIndices.length!==0||t.offscreenIndices.length!==0)return t;let r=this._partsHierarchy[e].objects;for(let i=0;i<r.length;++i){let s=r[i];if(s.objectType===1){this.getPartChildDrawObjects(s.objectIndex);let n=this._partsHierarchy[s.objectIndex].childDrawObjects;t.drawableIndices.push(...n.drawableIndices),t.offscreenIndices.push(...n.offscreenIndices);let a=this.getOffscreenIndices(),l=a?a[s.objectIndex]:-1;l!==-1&&t.offscreenIndices.push(l)}else s.objectType===0&&t.drawableIndices.push(s.objectIndex)}return t}getOffscreenIndices(){return this._model.parts.offscreenIndices}constructor(e){this._model=e,this._parameterValues=null,this._parameterMaximumValues=null,this._parameterMinimumValues=null,this._partOpacities=null,this._offscreenOpacities=null,this._savedParameters=new Array,this._parameterIds=new Array,this._drawableIds=new Array,this._partIds=new Array,this._isOverriddenParameterRepeat=!0,this._isOverriddenCullings=!1,this._modelOpacity=1,this._overrideMultiplyAndScreenColor=new jn(this),this._isBlendModeEnabled=!1,this._drawableColorBlends=null,this._drawableAlphaBlends=null,this._offscreenColorBlends=null,this._offscreenAlphaBlends=null,this._drawableMultiplyColors=null,this._drawableScreenColors=null,this._offscreenMultiplyColors=null,this._offscreenScreenColors=null,this._userParameterRepeatDataList=new Array,this._userDrawableCullings=new Array,this._userOffscreenCullings=new Array,this._partsHierarchy=new Array,this._notExistPartId=new Map,this._notExistParameterId=new Map,this._notExistParameterValues=new Map,this._notExistPartOpacities=new Map,this._drawableColorBlends=new Array(e.drawables.count).fill(-1),this._drawableAlphaBlends=new Array(e.drawables.count).fill(-1),this._offscreenColorBlends=new Array(e.offscreens.count).fill(-1),this._offscreenAlphaBlends=new Array(e.offscreens.count).fill(-1)}release(){this._model.release(),this._model=null,this._drawableColorBlends=null,this._drawableAlphaBlends=null,this._offscreenColorBlends=null,this._offscreenAlphaBlends=null,this._drawableMultiplyColors=null,this._drawableScreenColors=null,this._offscreenMultiplyColors=null,this._offscreenScreenColors=null}_notExistPartOpacities;_notExistPartId;_notExistParameterValues;_notExistParameterId;_savedParameters;_isOverriddenParameterRepeat;_overrideMultiplyAndScreenColor;_userParameterRepeatDataList;_partsHierarchy;_model;_parameterValues;_parameterMaximumValues;_parameterMinimumValues;_partOpacities;_offscreenOpacities;_modelOpacity;_parameterIds;_partIds;_drawableIds;_isOverriddenCullings;_userDrawableCullings;_userOffscreenCullings;_isBlendModeEnabled;_drawableColorBlends;_drawableAlphaBlends;_offscreenColorBlends;_offscreenAlphaBlends;_drawableMultiplyColors;_drawableScreenColors;_offscreenMultiplyColors;_offscreenScreenColors};(function(e){e.CubismModel=Cs})(ii||(ii={}));dt=class{constructor(e,t,r,i){this.x=e,this.y=t,this.width=r,this.height=i}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(e){this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height}expand(e,t){this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2}x;y;width;height};(function(e){e.csmRect=dt})(si||(si={}));pt=class{static create(){return null}static delete(e){e=null}initialize(e){this._model=e,e.isBlendModeEnabled()&&(this.useHighPrecisionMask(!0),de("This model uses a high-resolution mask because it operates in blend mode."))}drawModel(e=null){this.getModel()!=null&&this.doDrawModel(e)}setMvpMatrix(e){this._mvpMatrix4x4.setMatrix(e.getArray())}getMvpMatrix(){return this._mvpMatrix4x4}setModelColor(e,t,r,i){this._modelColor.r=M.clamp(e,0,1),this._modelColor.g=M.clamp(t,0,1),this._modelColor.b=M.clamp(r,0,1),this._modelColor.a=M.clamp(i,0,1)}getModelColor(){return this._modelColorScratch.r=this._modelColor.r,this._modelColorScratch.g=this._modelColor.g,this._modelColorScratch.b=this._modelColor.b,this._modelColorScratch.a=this._modelColor.a,this._modelColorScratch}getModelColorWithOpacity(e){let t=this._modelColorWithOpacityScratch;return t.r=this._modelColor.r,t.g=this._modelColor.g,t.b=this._modelColor.b,t.a=this._modelColor.a*e,this.isPremultipliedAlpha()&&(t.r*=t.a,t.g*=t.a,t.b*=t.a),t}setIsPremultipliedAlpha(e){this._isPremultipliedAlpha=e}isPremultipliedAlpha(){return this._isPremultipliedAlpha}setIsCulling(e){this._isCulling=e}isCulling(){return this._isCulling}setAnisotropy(e){this._anisotropy=e}getAnisotropy(){return this._anisotropy}getModel(){return this._model}useHighPrecisionMask(e){this._useHighPrecisionMask=e}isUsingHighPrecisionMask(){return this._useHighPrecisionMask}setRenderTargetSize(e,t){this._modelRenderTargetWidth=e,this._modelRenderTargetHeight=t}constructor(e,t){this._modelRenderTargetWidth=e,this._modelRenderTargetHeight=t,this._isCulling=!1,this._isPremultipliedAlpha=!1,this._anisotropy=0,this._model=null,this._modelColor=new R,this._modelColorScratch=new R,this._modelColorWithOpacityScratch=new R,this._useHighPrecisionMask=!1,this._mvpMatrix4x4=new ne,this._mvpMatrix4x4.loadIdentity()}static staticRelease;_mvpMatrix4x4;_modelColor;_modelColorScratch;_modelColorWithOpacityScratch;_isCulling;_isPremultipliedAlpha;_anisotropy;_model;_useHighPrecisionMask;_modelRenderTargetWidth;_modelRenderTargetHeight},$n=(function(e){return e[e.CubismBlendMode_Normal=0]="CubismBlendMode_Normal",e[e.CubismBlendMode_Additive=1]="CubismBlendMode_Additive",e[e.CubismBlendMode_Multiplicative=2]="CubismBlendMode_Multiplicative",e})({}),R=class{constructor(e=1,t=1,r=1,i=1){this.r=e,this.g=t,this.b=r,this.a=i}r;g;b;a},ea=class{constructor(e,t){this._clippingIdList=e,this._clippingIdCount=t,this._allClippedDrawRect=new dt,this._layoutBounds=new dt,this._clippedDrawableIndexList=[],this._clippedOffscreenIndexList=[],this._matrixForMask=new ne,this._matrixForDraw=new ne,this._bufferIndex=0,this._layoutChannelIndex=0}release(){this._layoutBounds!=null&&(this._layoutBounds=null),this._allClippedDrawRect!=null&&(this._allClippedDrawRect=null),this._clippedDrawableIndexList!=null&&(this._clippedDrawableIndexList=null),this._clippedOffscreenIndexList!=null&&(this._clippedOffscreenIndexList=null)}addClippedDrawable(e){this._clippedDrawableIndexList.push(e)}addClippedOffscreen(e){this._clippedOffscreenIndexList.push(e)}_isUsing;_clippingIdList;_clippingIdCount;_layoutChannelIndex;_layoutBounds;_allClippedDrawRect;_matrixForMask;_matrixForDraw;_clippedDrawableIndexList;_clippedOffscreenIndexList;_bufferIndex};(function(e){e.CubismBlendMode=$n,e.CubismRenderer=pt,e.CubismTextureColor=R})(ni||(ni={}));ta=class Wt{static parseJsonObject(t,r){return Object.keys(t).forEach(i=>{if(typeof t[i]=="boolean"){let s=!!t[i];r.put(i,new K(s))}else if(typeof t[i]=="string"){let s=String(t[i]);r.put(i,new Oe(s))}else if(typeof t[i]=="number"){let s=Number(t[i]);r.put(i,new ft(s))}else t[i]instanceof Array?r.put(i,Wt.parseJsonArray(t[i])):t[i]instanceof Object?r.put(i,Wt.parseJsonObject(t[i],new Ve)):t[i]==null?r.put(i,new Fe):r.put(i,t[i])}),r}static parseJsonArray(t){let r=new ir;return Object.keys(t).forEach(i=>{if(typeof Number(i)=="number")if(typeof t[i]=="boolean"){let s=!!t[i];r.add(new K(s))}else if(typeof t[i]=="string"){let s=String(t[i]);r.add(new Oe(s))}else if(typeof t[i]=="number"){let s=Number(t[i]);r.add(new ft(s))}else t[i]instanceof Array?r.add(this.parseJsonArray(t[i])):t[i]instanceof Object?r.add(this.parseJsonObject(t[i],new Ve)):t[i]==null?r.add(new Fe):r.add(t[i]);else if(t[i]instanceof Array)r.add(this.parseJsonArray(t[i]));else if(t[i]instanceof Object)r.add(this.parseJsonObject(t[i],new Ve));else if(t[i]==null)r.add(new Fe);else{let s=Array(t[i]);for(let n=0;n<s.length;n++)r.add(s[n])}}),r}},gt="Error: type mismatch",ra="Error: index out of bounds",U=class re{constructor(){}getRawString(t,r){return this.getString(t,r)}toInt(t=0){return t}toFloat(t=0){return t}toBoolean(t=!1){return t}getSize(){return 0}getArray(t=null){return t}getVector(t=new Array){return t}getMap(t){return t}getValueByIndex(t){return re.errorValue.setErrorNotForClientCall(gt)}getValueByString(t){return re.nullValue.setErrorNotForClientCall(gt)}getKeys(){return re.dummyKeys}isError(){return!1}isNull(){return!1}isBool(){return!1}isFloat(){return!1}isString(){return!1}isArray(){return!1}isMap(){return!1}equals(t){return!1}isStatic(){return!1}setErrorNotForClientCall(t){return Ye.errorValue}static staticInitializeNotForClientCall(){K.trueValue=new K(!0),K.falseValue=new K(!1),re.errorValue=new Ye("ERROR",!0),re.nullValue=new Fe,re.dummyKeys=new Array}static staticReleaseNotForClientCall(){K.trueValue=null,K.falseValue=null,re.errorValue=null,re.nullValue=null,re.dummyKeys=null}_stringBuffer;static dummyKeys;static errorValue;static nullValue},G=class ht{constructor(t,r){this._error=null,this._lineCount=0,this._root=null,t!=null&&this.parseBytes(t,r,this._parseCallback)}static create(t,r){let i=new ht;return i.parseBytes(t,r,i._parseCallback)?i:(ht.delete(i),null)}static delete(t){t=null}getRoot(){return this._root}static arrayBufferToString(t){let r=new Uint8Array(t),i="";for(let s=0,n=r.length;s<n;++s)i+="%"+this.pad(r[s].toString(16));return i=decodeURIComponent(i),i}static pad(t){return t.length<2?"0"+t:t}parseBytes(t,r,i){let s=new Array(1),n=ht.arrayBufferToString(t);if(i==null?this._root=this.parseValue(n,r,0,s):this._root=i(JSON.parse(n),new Ve),this._error){let a="\0";return a="Json parse error : @line "+(this._lineCount+1)+`
6
- `,this._root=new Oe(a),de("{0}",this._root.getRawString()),!1}else if(this._root==null)return this._root=new Ye(this._error,!1),!1;return!0}getParseError(){return this._error}checkEndOfFile(){return this._root.getArray()[1].equals("EOF")}parseValue(t,r,i,s){if(this._error)return null;let n=null,a=i,l;for(;a<r;a++)switch(t[a]){case"-":case".":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{let o=new Array(1);return l=ia(t.slice(a),o),s[0]=t.indexOf(o[0]),new ft(l)}case'"':return new Oe(this.parseString(t,r,a+1,s));case"[":return n=this.parseArray(t,r,a+1,s),n;case"{":return n=this.parseObject(t,r,a+1,s),n;case"n":return a+3<r?(n=new Fe,s[0]=a+4):this._error="parse null",n;case"t":return a+3<r?(n=K.trueValue,s[0]=a+4):this._error="parse true",n;case"f":return a+4<r?(n=K.falseValue,s[0]=a+5):this._error="illegal ',' position",n;case",":return this._error="illegal ',' position",null;case"]":return s[0]=a,null;case`
5
+ `)}constructor(){}};(function(e){e.CubismDebug=rr})(ei||(ei={}));fe=class{constructor(e=!1,t=new R){this.isOverridden=e,this.color=t}isOverridden;color},$n=class{_model;_isOverriddenModelMultiplyColors;_isOverriddenModelScreenColors;_userPartScreenColors;_userPartMultiplyColors;_userDrawableScreenColors;_userDrawableMultiplyColors;_userOffscreenScreenColors;_userOffscreenMultiplyColors;constructor(e){this._model=e,this._isOverriddenModelMultiplyColors=!1,this._isOverriddenModelScreenColors=!1,this._userPartScreenColors=[],this._userPartMultiplyColors=[],this._userDrawableScreenColors=[],this._userDrawableMultiplyColors=[],this._userOffscreenScreenColors=[],this._userOffscreenMultiplyColors=[]}initialize(e,t,r){let i=new fe(!1,new R(1,1,1,1)),s=new fe(!1,new R(0,0,0,1));this._userPartMultiplyColors=new Array(e),this._userPartScreenColors=new Array(e);for(let n=0;n<e;n++)this._userPartMultiplyColors[n]=new fe(i.isOverridden,new R(i.color.r,i.color.g,i.color.b,i.color.a)),this._userPartScreenColors[n]=new fe(s.isOverridden,new R(s.color.r,s.color.g,s.color.b,s.color.a));this._userDrawableMultiplyColors=new Array(t),this._userDrawableScreenColors=new Array(t);for(let n=0;n<t;n++)this._userDrawableMultiplyColors[n]=new fe(i.isOverridden,new R(i.color.r,i.color.g,i.color.b,i.color.a)),this._userDrawableScreenColors[n]=new fe(s.isOverridden,new R(s.color.r,s.color.g,s.color.b,s.color.a));this._userOffscreenMultiplyColors=new Array(r),this._userOffscreenScreenColors=new Array(r);for(let n=0;n<r;n++)this._userOffscreenMultiplyColors[n]=new fe(i.isOverridden,new R(i.color.r,i.color.g,i.color.b,i.color.a)),this._userOffscreenScreenColors[n]=new fe(s.isOverridden,new R(s.color.r,s.color.g,s.color.b,s.color.a))}warnIndexOutOfRange(e,t,r){O(`${e}: index is out of range. index=${t}, valid range=[0, ${r}].`)}isValidPartIndex(e,t){return e<0||e>=this._model.getPartCount()?(this.warnIndexOutOfRange(t,e,this._model.getPartCount()-1),!1):!0}isValidDrawableIndex(e,t){return e<0||e>=this._model.getDrawableCount()?(this.warnIndexOutOfRange(t,e,this._model.getDrawableCount()-1),!1):!0}isValidOffscreenIndex(e,t){return e<0||e>=this._model.getOffscreenCount()?(this.warnIndexOutOfRange(t,e,this._model.getOffscreenCount()-1),!1):!0}setMultiplyColorEnabled(e){this._isOverriddenModelMultiplyColors=e}getMultiplyColorEnabled(){return this._isOverriddenModelMultiplyColors}setScreenColorEnabled(e){this._isOverriddenModelScreenColors=e}getScreenColorEnabled(){return this._isOverriddenModelScreenColors}setPartMultiplyColorEnabled(e,t){this.isValidPartIndex(e,"setPartMultiplyColorEnabled")&&this.setPartColorEnabled(e,t,this._userPartMultiplyColors,this._userDrawableMultiplyColors,this._userOffscreenMultiplyColors)}getPartMultiplyColorEnabled(e){return this.isValidPartIndex(e,"getPartMultiplyColorEnabled")?this._userPartMultiplyColors[e].isOverridden:!1}setPartScreenColorEnabled(e,t){this.isValidPartIndex(e,"setPartScreenColorEnabled")&&this.setPartColorEnabled(e,t,this._userPartScreenColors,this._userDrawableScreenColors,this._userOffscreenScreenColors)}getPartScreenColorEnabled(e){return this.isValidPartIndex(e,"getPartScreenColorEnabled")?this._userPartScreenColors[e].isOverridden:!1}setPartMultiplyColorByTextureColor(e,t){this.isValidPartIndex(e,"setPartMultiplyColorByTextureColor")&&this.setPartMultiplyColorByRGBA(e,t.r,t.g,t.b,t.a)}setPartMultiplyColorByRGBA(e,t,r,i,s=1){this.isValidPartIndex(e,"setPartMultiplyColorByRGBA")&&this.setPartColor(e,t,r,i,s,this._userPartMultiplyColors,this._userDrawableMultiplyColors,this._userOffscreenMultiplyColors)}getPartMultiplyColor(e){return this.isValidPartIndex(e,"getPartMultiplyColor")?this._userPartMultiplyColors[e].color:new R(1,1,1,1)}setPartScreenColorByTextureColor(e,t){this.isValidPartIndex(e,"setPartScreenColorByTextureColor")&&this.setPartScreenColorByRGBA(e,t.r,t.g,t.b,t.a)}setPartScreenColorByRGBA(e,t,r,i,s=1){this.isValidPartIndex(e,"setPartScreenColorByRGBA")&&this.setPartColor(e,t,r,i,s,this._userPartScreenColors,this._userDrawableScreenColors,this._userOffscreenScreenColors)}getPartScreenColor(e){return this.isValidPartIndex(e,"getPartScreenColor")?this._userPartScreenColors[e].color:new R(0,0,0,1)}setDrawableMultiplyColorEnabled(e,t){this.isValidDrawableIndex(e,"setDrawableMultiplyColorEnabled")&&(this._userDrawableMultiplyColors[e].isOverridden=t)}getDrawableMultiplyColorEnabled(e){return this.isValidDrawableIndex(e,"getDrawableMultiplyColorEnabled")?this._userDrawableMultiplyColors[e].isOverridden:!1}setDrawableScreenColorEnabled(e,t){this.isValidDrawableIndex(e,"setDrawableScreenColorEnabled")&&(this._userDrawableScreenColors[e].isOverridden=t)}getDrawableScreenColorEnabled(e){return this.isValidDrawableIndex(e,"getDrawableScreenColorEnabled")?this._userDrawableScreenColors[e].isOverridden:!1}setDrawableMultiplyColorByTextureColor(e,t){this.isValidDrawableIndex(e,"setDrawableMultiplyColorByTextureColor")&&this.setDrawableMultiplyColorByRGBA(e,t.r,t.g,t.b,t.a)}setDrawableMultiplyColorByRGBA(e,t,r,i,s=1){this.isValidDrawableIndex(e,"setDrawableMultiplyColorByRGBA")&&(this._userDrawableMultiplyColors[e].color.r=t,this._userDrawableMultiplyColors[e].color.g=r,this._userDrawableMultiplyColors[e].color.b=i,this._userDrawableMultiplyColors[e].color.a=s)}getDrawableMultiplyColor(e){return this.isValidDrawableIndex(e,"getDrawableMultiplyColor")?this.getMultiplyColorEnabled()||this.getDrawableMultiplyColorEnabled(e)?this._userDrawableMultiplyColors[e].color:this._model.getDrawableMultiplyColor(e):new R(1,1,1,1)}setDrawableScreenColorByTextureColor(e,t){this.isValidDrawableIndex(e,"setDrawableScreenColorByTextureColor")&&this.setDrawableScreenColorByRGBA(e,t.r,t.g,t.b,t.a)}setDrawableScreenColorByRGBA(e,t,r,i,s=1){this.isValidDrawableIndex(e,"setDrawableScreenColorByRGBA")&&(this._userDrawableScreenColors[e].color.r=t,this._userDrawableScreenColors[e].color.g=r,this._userDrawableScreenColors[e].color.b=i,this._userDrawableScreenColors[e].color.a=s)}getDrawableScreenColor(e){return this.isValidDrawableIndex(e,"getDrawableScreenColor")?this.getScreenColorEnabled()||this.getDrawableScreenColorEnabled(e)?this._userDrawableScreenColors[e].color:this._model.getDrawableScreenColor(e):new R(0,0,0,1)}setOffscreenMultiplyColorEnabled(e,t){this.isValidOffscreenIndex(e,"setOffscreenMultiplyColorEnabled")&&(this._userOffscreenMultiplyColors[e].isOverridden=t)}getOffscreenMultiplyColorEnabled(e){return this.isValidOffscreenIndex(e,"getOffscreenMultiplyColorEnabled")?this._userOffscreenMultiplyColors[e].isOverridden:!1}setOffscreenScreenColorEnabled(e,t){this.isValidOffscreenIndex(e,"setOffscreenScreenColorEnabled")&&(this._userOffscreenScreenColors[e].isOverridden=t)}getOffscreenScreenColorEnabled(e){return this.isValidOffscreenIndex(e,"getOffscreenScreenColorEnabled")?this._userOffscreenScreenColors[e].isOverridden:!1}setOffscreenMultiplyColorByTextureColor(e,t){this.isValidOffscreenIndex(e,"setOffscreenMultiplyColorByTextureColor")&&this.setOffscreenMultiplyColorByRGBA(e,t.r,t.g,t.b,t.a)}setOffscreenMultiplyColorByRGBA(e,t,r,i,s=1){this.isValidOffscreenIndex(e,"setOffscreenMultiplyColorByRGBA")&&(this._userOffscreenMultiplyColors[e].color.r=t,this._userOffscreenMultiplyColors[e].color.g=r,this._userOffscreenMultiplyColors[e].color.b=i,this._userOffscreenMultiplyColors[e].color.a=s)}getOffscreenMultiplyColor(e){return this.isValidOffscreenIndex(e,"getOffscreenMultiplyColor")?this.getMultiplyColorEnabled()||this.getOffscreenMultiplyColorEnabled(e)?this._userOffscreenMultiplyColors[e].color:this._model.getOffscreenMultiplyColor(e):new R(1,1,1,1)}setOffscreenScreenColorByTextureColor(e,t){this.isValidOffscreenIndex(e,"setOffscreenScreenColorByTextureColor")&&this.setOffscreenScreenColorByRGBA(e,t.r,t.g,t.b,t.a)}setOffscreenScreenColorByRGBA(e,t,r,i,s=1){this.isValidOffscreenIndex(e,"setOffscreenScreenColorByRGBA")&&(this._userOffscreenScreenColors[e].color.r=t,this._userOffscreenScreenColors[e].color.g=r,this._userOffscreenScreenColors[e].color.b=i,this._userOffscreenScreenColors[e].color.a=s)}getOffscreenScreenColor(e){return this.isValidOffscreenIndex(e,"getOffscreenScreenColor")?this.getScreenColorEnabled()||this.getOffscreenScreenColorEnabled(e)?this._userOffscreenScreenColors[e].color:this._model.getOffscreenScreenColor(e):new R(0,0,0,1)}setPartColor(e,t,r,i,s,n,a,l){if(n[e].color.r=t,n[e].color.g=r,n[e].color.b=i,n[e].color.a=s,n[e].isOverridden){let o=this._model.getPartOffscreenIndices()[e];if(o==-1){let u=this._model.getPartsHierarchy();if(u&&u[e])for(let h=0;h<u[e].objects.length;++h){let d=u[e].objects[h];if(d.objectType===0){let c=d.objectIndex;a[c].color.r=t,a[c].color.g=r,a[c].color.b=i,a[c].color.a=s}else{let c=d.objectIndex;this.setPartColor(c,t,r,i,s,n,a,l)}}}else l[o].color.r=t,l[o].color.g=r,l[o].color.b=i,l[o].color.a=s}}setPartColorEnabled(e,t,r,i,s){r[e].isOverridden=t;let n=this._model.getPartOffscreenIndices()[e];if(n==-1){let a=this._model.getPartsHierarchy();if(a&&a[e])for(let l=0;l<a[e].objects.length;++l){let o=a[e].objects[l];if(o.objectType===0){let u=o.objectIndex;i[u].isOverridden=t,t&&(i[u].color.r=r[e].color.r,i[u].color.g=r[e].color.g,i[u].color.b=r[e].color.b,i[u].color.a=r[e].color.a)}else{let u=o.objectIndex;t&&(r[u].color.r=r[e].color.r,r[u].color.g=r[e].color.g,r[u].color.b=r[e].color.b,r[u].color.a=r[e].color.a),this.setPartColorEnabled(u,t,r,i,s)}}}else s[n].isOverridden=t,t&&(s[n].color.r=r[e].color.r,s[n].color.g=r[e].color.g,s[n].color.b=r[e].color.b,s[n].color.a=r[e].color.a)}},V=(function(e){return e[e.ColorBlend_None=-1]="ColorBlend_None",e[e.ColorBlend_Normal=Live2DCubismCore.ColorBlendType_Normal]="ColorBlend_Normal",e[e.ColorBlend_AddGlow=Live2DCubismCore.ColorBlendType_AddGlow]="ColorBlend_AddGlow",e[e.ColorBlend_Add=Live2DCubismCore.ColorBlendType_Add]="ColorBlend_Add",e[e.ColorBlend_Darken=Live2DCubismCore.ColorBlendType_Darken]="ColorBlend_Darken",e[e.ColorBlend_Multiply=Live2DCubismCore.ColorBlendType_Multiply]="ColorBlend_Multiply",e[e.ColorBlend_ColorBurn=Live2DCubismCore.ColorBlendType_ColorBurn]="ColorBlend_ColorBurn",e[e.ColorBlend_LinearBurn=Live2DCubismCore.ColorBlendType_LinearBurn]="ColorBlend_LinearBurn",e[e.ColorBlend_Lighten=Live2DCubismCore.ColorBlendType_Lighten]="ColorBlend_Lighten",e[e.ColorBlend_Screen=Live2DCubismCore.ColorBlendType_Screen]="ColorBlend_Screen",e[e.ColorBlend_ColorDodge=Live2DCubismCore.ColorBlendType_ColorDodge]="ColorBlend_ColorDodge",e[e.ColorBlend_Overlay=Live2DCubismCore.ColorBlendType_Overlay]="ColorBlend_Overlay",e[e.ColorBlend_SoftLight=Live2DCubismCore.ColorBlendType_SoftLight]="ColorBlend_SoftLight",e[e.ColorBlend_HardLight=Live2DCubismCore.ColorBlendType_HardLight]="ColorBlend_HardLight",e[e.ColorBlend_LinearLight=Live2DCubismCore.ColorBlendType_LinearLight]="ColorBlend_LinearLight",e[e.ColorBlend_Hue=Live2DCubismCore.ColorBlendType_Hue]="ColorBlend_Hue",e[e.ColorBlend_Color=Live2DCubismCore.ColorBlendType_Color]="ColorBlend_Color",e[e.ColorBlend_AddCompatible=Live2DCubismCore.ColorBlendType_AddCompatible]="ColorBlend_AddCompatible",e[e.ColorBlend_MultiplyCompatible=Live2DCubismCore.ColorBlendType_MultiplyCompatible]="ColorBlend_MultiplyCompatible",e})({}),Lt=(function(e){return e[e.AlphaBlend_None=-1]="AlphaBlend_None",e[e.AlphaBlend_Over=0]="AlphaBlend_Over",e[e.AlphaBlend_Atop=1]="AlphaBlend_Atop",e[e.AlphaBlend_Out=2]="AlphaBlend_Out",e[e.AlphaBlend_ConjointOver=3]="AlphaBlend_ConjointOver",e[e.AlphaBlend_DisjointOver=4]="AlphaBlend_DisjointOver",e})({}),ea=class{constructor(e=!1,t=!1){this.isOverridden=e,this.isParameterRepeated=t}isOverridden;isParameterRepeated},ti=class{constructor(e=!1,t=!1){this.isOverridden=e,this.isCulling=t}isOverridden;isCulling},ta=class{drawableIndices;offscreenIndices;constructor(e=new Array,t=new Array){this.drawableIndices=e,this.offscreenIndices=t}},ri=class{objectType;objectIndex;constructor(e,t){this.objectIndex=e,this.objectType=t}},ra=class{objects;childDrawObjects;constructor(e=new Array,t=new ta){this.objects=e,this.childDrawObjects=t}getChildObjectCount(){return this.objects.length}},Cs=class{update(){this._model.update(),this._model.drawables.resetDynamicFlags()}getPixelsPerUnit(){return this._model==null?0:this._model.canvasinfo.PixelsPerUnit}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(){let e=this._model.parameters.count,t=this._savedParameters.length;for(let r=0;r<e;++r)r<t?this._savedParameters[r]=this._parameterValues[r]:this._savedParameters.push(this._parameterValues[r])}getOverrideMultiplyAndScreenColor(){return this._overrideMultiplyAndScreenColor}getOverrideFlagForModelParameterRepeat(){return this._isOverriddenParameterRepeat}setOverrideFlagForModelParameterRepeat(e){this._isOverriddenParameterRepeat=e}getOverrideFlagForParameterRepeat(e){return this._userParameterRepeatDataList[e].isOverridden}setOverrideFlagForParameterRepeat(e,t){this._userParameterRepeatDataList[e].isOverridden=t}getRepeatFlagForParameterRepeat(e){return this._userParameterRepeatDataList[e].isParameterRepeated}setRepeatFlagForParameterRepeat(e,t){this._userParameterRepeatDataList[e].isParameterRepeated=t}getDrawableCulling(e){if(this.getOverrideFlagForModelCullings()||this.getOverrideFlagForDrawableCullings(e))return this._userDrawableCullings[e].isCulling;let t=this._model.drawables.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(t[e])}setDrawableCulling(e,t){this._userDrawableCullings[e].isCulling=t}getOffscreenCulling(e){if(this.getOverrideFlagForModelCullings()||this.getOverrideFlagForOffscreenCullings(e))return this._userOffscreenCullings[e].isCulling;let t=this._model.offscreens.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(t[e])}setOffscreenCulling(e,t){this._userOffscreenCullings[e].isCulling=t}getOverrideFlagForModelCullings(){return this._isOverriddenCullings}setOverrideFlagForModelCullings(e){this._isOverriddenCullings=e}getOverrideFlagForDrawableCullings(e){return this._userDrawableCullings[e].isOverridden}getOverrideFlagForOffscreenCullings(e){return this._userOffscreenCullings[e].isOverridden}setOverrideFlagForDrawableCullings(e,t){this._userDrawableCullings[e].isOverridden=t}getModelOapcity(){return this._modelOpacity}setModelOapcity(e){this._modelOpacity=e}getModel(){return this._model}getPartIndex(e){let t,r=this._model.parts.count;for(t=0;t<r;++t)if(e==this._partIds[t])return t;return this._notExistPartId.has(e)?this._notExistPartId.get(e):(t=r+this._notExistPartId.size,this._notExistPartId.set(e,t),this._notExistPartOpacities.set(t,null),t)}getPartId(e){let t=this._model.parts.ids[e];return P.getIdManager().getId(t)}getPartCount(){return this._model.parts.count}getPartOffscreenIndices(){return this._model.parts.offscreenIndices}getPartParentPartIndices(){return this._model.parts.parentIndices}setPartOpacityByIndex(e,t){if(this._notExistPartOpacities.has(e)){this._notExistPartOpacities.set(e,t);return}k(0<=e&&e<this.getPartCount()),this._partOpacities[e]=t}setPartOpacityById(e,t){let r=this.getPartIndex(e);r<0||this.setPartOpacityByIndex(r,t)}getPartOpacityByIndex(e){return this._notExistPartOpacities.has(e)?this._notExistPartOpacities.get(e):(k(0<=e&&e<this.getPartCount()),this._partOpacities[e])}getPartOpacityById(e){let t=this.getPartIndex(e);return t<0?0:this.getPartOpacityByIndex(t)}getParameterIndex(e){let t,r=this._model.parameters.count;for(t=0;t<r;++t)if(e==this._parameterIds[t])return t;return this._notExistParameterId.has(e)?this._notExistParameterId.get(e):(t=this._model.parameters.count+this._notExistParameterId.size,this._notExistParameterId.set(e,t),this._notExistParameterValues.set(t,null),t)}getParameterCount(){return this._model.parameters.count}getParameterType(e){return this._model.parameters.types[e]}getParameterMaximumValue(e){return this._model.parameters.maximumValues[e]}getParameterMinimumValue(e){return this._model.parameters.minimumValues[e]}getParameterDefaultValue(e){return this._model.parameters.defaultValues[e]}getParameterId(e){return P.getIdManager().getId(this._model.parameters.ids[e])}getParameterValueByIndex(e){return this._notExistParameterValues.has(e)?this._notExistParameterValues.get(e):(k(0<=e&&e<this.getParameterCount()),this._parameterValues[e])}getParameterValueById(e){let t=this.getParameterIndex(e);return this.getParameterValueByIndex(t)}setParameterValueByIndex(e,t,r=1){if(this._notExistParameterValues.has(e)){this._notExistParameterValues.set(e,r==1?t:this._notExistParameterValues.get(e)*(1-r)+t*r);return}k(0<=e&&e<this.getParameterCount()),this.isRepeat(e)?t=this.getParameterRepeatValue(e,t):t=this.getParameterClampValue(e,t),this._parameterValues[e]=r==1?t:this._parameterValues[e]=this._parameterValues[e]*(1-r)+t*r}setParameterValueById(e,t,r=1){let i=this.getParameterIndex(e);this.setParameterValueByIndex(i,t,r)}addParameterValueByIndex(e,t,r=1){this.setParameterValueByIndex(e,this.getParameterValueByIndex(e)+t*r)}addParameterValueById(e,t,r=1){let i=this.getParameterIndex(e);this.addParameterValueByIndex(i,t,r)}isRepeat(e){if(this._notExistParameterValues.has(e))return!1;k(0<=e&&e<this.getParameterCount());let t;return this._isOverriddenParameterRepeat||this._userParameterRepeatDataList[e].isOverridden?t=this._userParameterRepeatDataList[e].isParameterRepeated:t=this._model.parameters.repeats[e]!=0,t}getParameterRepeatValue(e,t){if(this._notExistParameterValues.has(e))return t;k(0<=e&&e<this.getParameterCount());let r=this._model.parameters.maximumValues[e],i=this._model.parameters.minimumValues[e],s=r-i;if(r<t){let n=M.mod(t-r,s);Number.isNaN(n)?t=r:t=i+n}if(t<i){let n=M.mod(i-t,s);Number.isNaN(n)?t=i:t=r-n}return t}getParameterClampValue(e,t){if(this._notExistParameterValues.has(e))return t;k(0<=e&&e<this.getParameterCount());let r=this._model.parameters.maximumValues[e],i=this._model.parameters.minimumValues[e];return M.clamp(t,i,r)}getParameterRepeats(e){return this._model.parameters.repeats[e]!=0}multiplyParameterValueById(e,t,r=1){let i=this.getParameterIndex(e);this.multiplyParameterValueByIndex(i,t,r)}multiplyParameterValueByIndex(e,t,r=1){this.setParameterValueByIndex(e,this.getParameterValueByIndex(e)*(1+(t-1)*r))}getDrawableIndex(e){let t=this._model.drawables.count;for(let r=0;r<t;++r)if(this._drawableIds[r]==e)return r;return-1}getDrawableCount(){return this._model.drawables.count}getDrawableId(e){let t=this._model.drawables.ids;return P.getIdManager().getId(t[e])}getRenderOrders(){return this._model.getRenderOrders()}getDrawableTextureIndex(e){return this._model.drawables.textureIndices[e]}getDrawableDynamicFlagVertexPositionsDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVertexPositionsDidChangeBit(t[e])}getDrawableVertexIndexCount(e){return this._model.drawables.indexCounts[e]}getDrawableVertexCount(e){return this._model.drawables.vertexCounts[e]}getDrawableVertices(e){return this.getDrawableVertexPositions(e)}getDrawableVertexIndices(e){return this._model.drawables.indices[e]}getDrawableVertexPositions(e){return this._model.drawables.vertexPositions[e]}getDrawableVertexUvs(e){return this._model.drawables.vertexUvs[e]}getDrawableOpacity(e){return this._model.drawables.opacities[e]}getDrawableMultiplyColor(e){this._drawableMultiplyColors==null&&(this._drawableMultiplyColors=new Array(this._model.drawables.count),this._drawableMultiplyColors.fill(new R));let t=this._model.drawables.multiplyColors,r=e*4;return this._drawableMultiplyColors[e].r=t[r],this._drawableMultiplyColors[e].g=t[r+1],this._drawableMultiplyColors[e].b=t[r+2],this._drawableMultiplyColors[e].a=t[r+3],this._drawableMultiplyColors[e]}getDrawableScreenColor(e){this._drawableScreenColors==null&&(this._drawableScreenColors=new Array(this._model.drawables.count),this._drawableScreenColors.fill(new R));let t=this._model.drawables.screenColors,r=e*4;return this._drawableScreenColors[e].r=t[r],this._drawableScreenColors[e].g=t[r+1],this._drawableScreenColors[e].b=t[r+2],this._drawableScreenColors[e].a=t[r+3],this._drawableScreenColors[e]}getOffscreenMultiplyColor(e){this._offscreenMultiplyColors==null&&(this._offscreenMultiplyColors=new Array(this._model.offscreens.count),this._offscreenMultiplyColors.fill(new R));let t=this._model.offscreens.multiplyColors,r=e*4;return this._offscreenMultiplyColors[e].r=t[r],this._offscreenMultiplyColors[e].g=t[r+1],this._offscreenMultiplyColors[e].b=t[r+2],this._offscreenMultiplyColors[e].a=t[r+3],this._offscreenMultiplyColors[e]}getOffscreenScreenColor(e){this._offscreenScreenColors==null&&(this._offscreenScreenColors=new Array(this._model.offscreens.count),this._offscreenScreenColors.fill(new R));let t=this._model.offscreens.screenColors,r=e*4;return this._offscreenScreenColors[e].r=t[r],this._offscreenScreenColors[e].g=t[r+1],this._offscreenScreenColors[e].b=t[r+2],this._offscreenScreenColors[e].a=t[r+3],this._offscreenScreenColors[e]}getDrawableParentPartIndex(e){return this._model.drawables.parentPartIndices[e]}getDrawableBlendMode(e){let t=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(t[e])?1:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(t[e])?2:0}getDrawableColorBlend(e){return this._drawableColorBlends[e]==-1&&(this._drawableColorBlends[e]=this._model.drawables.blendModes[e]&255),this._drawableColorBlends[e]}getDrawableAlphaBlend(e){return this._drawableAlphaBlends[e]==-1&&(this._drawableAlphaBlends[e]=this._model.drawables.blendModes[e]>>8&255),this._drawableAlphaBlends[e]}getDrawableInvertedMaskBit(e){let t=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(t[e])}getDrawableMasks(){return this._model.drawables.masks}getDrawableMaskCounts(){return this._model.drawables.maskCounts}isUsingMasking(){for(let e=0;e<this._model.drawables.count;++e)if(!(this._model.drawables.maskCounts[e]<=0))return!0;return!1}isUsingMaskingForOffscreen(){for(let e=0;e<this.getOffscreenCount();++e)if(!(this._model.offscreens.maskCounts[e]<=0))return!0;return!1}getDrawableDynamicFlagIsVisible(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasIsVisibleBit(t[e])}getDrawableDynamicFlagVisibilityDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVisibilityDidChangeBit(t[e])}getDrawableDynamicFlagOpacityDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasOpacityDidChangeBit(t[e])}getDrawableDynamicFlagRenderOrderDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasRenderOrderDidChangeBit(t[e])}getDrawableDynamicFlagBlendColorDidChange(e){let t=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasBlendColorDidChangeBit(t[e])}getOffscreenCount(){return this._model.offscreens.count}getOffscreenColorBlend(e){return this._offscreenColorBlends[e]==-1&&(this._offscreenColorBlends[e]=this._model.offscreens.blendModes[e]&255),this._offscreenColorBlends[e]}getOffscreenAlphaBlend(e){return this._offscreenAlphaBlends[e]==-1&&(this._offscreenAlphaBlends[e]=this._model.offscreens.blendModes[e]>>8&255),this._offscreenAlphaBlends[e]}getOffscreenOwnerIndices(){return this._model.offscreens.ownerIndices}getOffscreenOpacity(e){return e<0||e>=this._model.offscreens.count?1:this._model.offscreens.opacities[e]}getOffscreenMasks(){return this._model.offscreens.masks}getOffscreenMaskCounts(){return this._model.offscreens.maskCounts}getOffscreenInvertedMask(e){let t=this._model.offscreens.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(t[e])}isBlendModeEnabled(){return this._isBlendModeEnabled}loadParameters(){let e=this._model.parameters.count,t=this._savedParameters.length;e>t&&(e=t);for(let r=0;r<e;++r)this._parameterValues[r]=this._savedParameters[r]}initialize(){k(this._model),this._parameterValues=this._model.parameters.values,this._partOpacities=this._model.parts.opacities,this._offscreenOpacities=this._model.offscreens.opacities,this._parameterMaximumValues=this._model.parameters.maximumValues,this._parameterMinimumValues=this._model.parameters.minimumValues;{let t=this._model.parameters.ids,r=this._model.parameters.count;this._parameterIds.length=r,this._userParameterRepeatDataList.length=r;for(let i=0;i<r;++i)this._parameterIds[i]=P.getIdManager().getId(t[i]),this._userParameterRepeatDataList[i]=new ea(!1,!1)}let e=this._model.parts.count;{let t=this._model.parts.ids;this._partIds.length=e;for(let r=0;r<e;++r)this._partIds[r]=P.getIdManager().getId(t[r])}{let t=this._model.drawables.ids,r=this._model.drawables.count;this._userDrawableCullings.length=r;let i=new ti(!1,!1);this._userOffscreenCullings.length=this._model.offscreens.count;let s=new ti(!1,!1);for(let a=0;a<r;++a)this._drawableIds.push(P.getIdManager().getId(t[a])),this._userDrawableCullings[a]=i;for(let a=0;a<this._model.offscreens.count;++a)this._userOffscreenCullings[a]=s;if(this.getOffscreenCount()>0)this._isBlendModeEnabled=!0;else{this._model.drawables.blendModes;for(let a=0;a<r;++a){let l=this.getDrawableColorBlend(a),o=this.getDrawableAlphaBlend(a);if(!(l==V.ColorBlend_Normal&&o==0)&&l!=V.ColorBlend_AddCompatible&&l!=V.ColorBlend_MultiplyCompatible){this._isBlendModeEnabled=!0;break}}}this.setupPartsHierarchy();let n=this.getOffscreenCount();this._overrideMultiplyAndScreenColor.initialize(e,r,n)}}getPartsHierarchy(){return this._partsHierarchy}setupPartsHierarchy(){this._partsHierarchy.length=0;let e=this.getPartCount();this._partsHierarchy.length=e;for(let r=0;r<e;++r){let i=new ra;this._partsHierarchy[r]=i}for(let r=0;r<e;++r){let i=this.getPartParentPartIndices()[r];if(i!==-1){for(let s=0;s<this._partsHierarchy.length;++s)if(s===i){let n=new ri(r,1);this._partsHierarchy[s].objects.push(n);break}}}let t=this.getDrawableCount();for(let r=0;r<t;++r){let i=this.getDrawableParentPartIndex(r);if(i!==-1){for(let s=0;s<this._partsHierarchy.length;++s)if(s===i){let n=new ri(r,0);this._partsHierarchy[s].objects.push(n);break}}}for(let r=0;r<this._partsHierarchy.length;++r)this.getPartChildDrawObjects(r)}getPartChildDrawObjects(e){if(this._partsHierarchy[e].getChildObjectCount()<1)return this._partsHierarchy[e].childDrawObjects;let t=this._partsHierarchy[e].childDrawObjects;if(t.drawableIndices.length!==0||t.offscreenIndices.length!==0)return t;let r=this._partsHierarchy[e].objects;for(let i=0;i<r.length;++i){let s=r[i];if(s.objectType===1){this.getPartChildDrawObjects(s.objectIndex);let n=this._partsHierarchy[s.objectIndex].childDrawObjects;t.drawableIndices.push(...n.drawableIndices),t.offscreenIndices.push(...n.offscreenIndices);let a=this.getOffscreenIndices(),l=a?a[s.objectIndex]:-1;l!==-1&&t.offscreenIndices.push(l)}else s.objectType===0&&t.drawableIndices.push(s.objectIndex)}return t}getOffscreenIndices(){return this._model.parts.offscreenIndices}constructor(e){this._model=e,this._parameterValues=null,this._parameterMaximumValues=null,this._parameterMinimumValues=null,this._partOpacities=null,this._offscreenOpacities=null,this._savedParameters=new Array,this._parameterIds=new Array,this._drawableIds=new Array,this._partIds=new Array,this._isOverriddenParameterRepeat=!0,this._isOverriddenCullings=!1,this._modelOpacity=1,this._overrideMultiplyAndScreenColor=new $n(this),this._isBlendModeEnabled=!1,this._drawableColorBlends=null,this._drawableAlphaBlends=null,this._offscreenColorBlends=null,this._offscreenAlphaBlends=null,this._drawableMultiplyColors=null,this._drawableScreenColors=null,this._offscreenMultiplyColors=null,this._offscreenScreenColors=null,this._userParameterRepeatDataList=new Array,this._userDrawableCullings=new Array,this._userOffscreenCullings=new Array,this._partsHierarchy=new Array,this._notExistPartId=new Map,this._notExistParameterId=new Map,this._notExistParameterValues=new Map,this._notExistPartOpacities=new Map,this._drawableColorBlends=new Array(e.drawables.count).fill(-1),this._drawableAlphaBlends=new Array(e.drawables.count).fill(-1),this._offscreenColorBlends=new Array(e.offscreens.count).fill(-1),this._offscreenAlphaBlends=new Array(e.offscreens.count).fill(-1)}release(){this._model.release(),this._model=null,this._drawableColorBlends=null,this._drawableAlphaBlends=null,this._offscreenColorBlends=null,this._offscreenAlphaBlends=null,this._drawableMultiplyColors=null,this._drawableScreenColors=null,this._offscreenMultiplyColors=null,this._offscreenScreenColors=null}_notExistPartOpacities;_notExistPartId;_notExistParameterValues;_notExistParameterId;_savedParameters;_isOverriddenParameterRepeat;_overrideMultiplyAndScreenColor;_userParameterRepeatDataList;_partsHierarchy;_model;_parameterValues;_parameterMaximumValues;_parameterMinimumValues;_partOpacities;_offscreenOpacities;_modelOpacity;_parameterIds;_partIds;_drawableIds;_isOverriddenCullings;_userDrawableCullings;_userOffscreenCullings;_isBlendModeEnabled;_drawableColorBlends;_drawableAlphaBlends;_offscreenColorBlends;_offscreenAlphaBlends;_drawableMultiplyColors;_drawableScreenColors;_offscreenMultiplyColors;_offscreenScreenColors};(function(e){e.CubismModel=Cs})(ii||(ii={}));dt=class{constructor(e,t,r,i){this.x=e,this.y=t,this.width=r,this.height=i}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(e){this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height}expand(e,t){this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2}x;y;width;height};(function(e){e.csmRect=dt})(si||(si={}));pt=class{static create(){return null}static delete(e){e=null}initialize(e){this._model=e,e.isBlendModeEnabled()&&(this.useHighPrecisionMask(!0),de("This model uses a high-resolution mask because it operates in blend mode."))}drawModel(e=null){this.getModel()!=null&&this.doDrawModel(e)}setMvpMatrix(e){this._mvpMatrix4x4.setMatrix(e.getArray())}getMvpMatrix(){return this._mvpMatrix4x4}setModelColor(e,t,r,i){this._modelColor.r=M.clamp(e,0,1),this._modelColor.g=M.clamp(t,0,1),this._modelColor.b=M.clamp(r,0,1),this._modelColor.a=M.clamp(i,0,1)}getModelColor(){return this._modelColorScratch.r=this._modelColor.r,this._modelColorScratch.g=this._modelColor.g,this._modelColorScratch.b=this._modelColor.b,this._modelColorScratch.a=this._modelColor.a,this._modelColorScratch}getModelColorWithOpacity(e){let t=this._modelColorWithOpacityScratch;return t.r=this._modelColor.r,t.g=this._modelColor.g,t.b=this._modelColor.b,t.a=this._modelColor.a*e,this.isPremultipliedAlpha()&&(t.r*=t.a,t.g*=t.a,t.b*=t.a),t}setIsPremultipliedAlpha(e){this._isPremultipliedAlpha=e}isPremultipliedAlpha(){return this._isPremultipliedAlpha}setIsCulling(e){this._isCulling=e}isCulling(){return this._isCulling}setAnisotropy(e){this._anisotropy=e}getAnisotropy(){return this._anisotropy}getModel(){return this._model}useHighPrecisionMask(e){this._useHighPrecisionMask=e}isUsingHighPrecisionMask(){return this._useHighPrecisionMask}setRenderTargetSize(e,t){this._modelRenderTargetWidth=e,this._modelRenderTargetHeight=t}constructor(e,t){this._modelRenderTargetWidth=e,this._modelRenderTargetHeight=t,this._isCulling=!1,this._isPremultipliedAlpha=!1,this._anisotropy=0,this._model=null,this._modelColor=new R,this._modelColorScratch=new R,this._modelColorWithOpacityScratch=new R,this._useHighPrecisionMask=!1,this._mvpMatrix4x4=new ne,this._mvpMatrix4x4.loadIdentity()}static staticRelease;_mvpMatrix4x4;_modelColor;_modelColorScratch;_modelColorWithOpacityScratch;_isCulling;_isPremultipliedAlpha;_anisotropy;_model;_useHighPrecisionMask;_modelRenderTargetWidth;_modelRenderTargetHeight},ia=(function(e){return e[e.CubismBlendMode_Normal=0]="CubismBlendMode_Normal",e[e.CubismBlendMode_Additive=1]="CubismBlendMode_Additive",e[e.CubismBlendMode_Multiplicative=2]="CubismBlendMode_Multiplicative",e})({}),R=class{constructor(e=1,t=1,r=1,i=1){this.r=e,this.g=t,this.b=r,this.a=i}r;g;b;a},sa=class{constructor(e,t){this._clippingIdList=e,this._clippingIdCount=t,this._allClippedDrawRect=new dt,this._layoutBounds=new dt,this._clippedDrawableIndexList=[],this._clippedOffscreenIndexList=[],this._matrixForMask=new ne,this._matrixForDraw=new ne,this._bufferIndex=0,this._layoutChannelIndex=0}release(){this._layoutBounds!=null&&(this._layoutBounds=null),this._allClippedDrawRect!=null&&(this._allClippedDrawRect=null),this._clippedDrawableIndexList!=null&&(this._clippedDrawableIndexList=null),this._clippedOffscreenIndexList!=null&&(this._clippedOffscreenIndexList=null)}addClippedDrawable(e){this._clippedDrawableIndexList.push(e)}addClippedOffscreen(e){this._clippedOffscreenIndexList.push(e)}_isUsing;_clippingIdList;_clippingIdCount;_layoutChannelIndex;_layoutBounds;_allClippedDrawRect;_matrixForMask;_matrixForDraw;_clippedDrawableIndexList;_clippedOffscreenIndexList;_bufferIndex};(function(e){e.CubismBlendMode=ia,e.CubismRenderer=pt,e.CubismTextureColor=R})(ni||(ni={}));na=class Wt{static parseJsonObject(t,r){return Object.keys(t).forEach(i=>{if(typeof t[i]=="boolean"){let s=!!t[i];r.put(i,new K(s))}else if(typeof t[i]=="string"){let s=String(t[i]);r.put(i,new Ve(s))}else if(typeof t[i]=="number"){let s=Number(t[i]);r.put(i,new ft(s))}else t[i]instanceof Array?r.put(i,Wt.parseJsonArray(t[i])):t[i]instanceof Object?r.put(i,Wt.parseJsonObject(t[i],new Oe)):t[i]==null?r.put(i,new Fe):r.put(i,t[i])}),r}static parseJsonArray(t){let r=new ir;return Object.keys(t).forEach(i=>{if(typeof Number(i)=="number")if(typeof t[i]=="boolean"){let s=!!t[i];r.add(new K(s))}else if(typeof t[i]=="string"){let s=String(t[i]);r.add(new Ve(s))}else if(typeof t[i]=="number"){let s=Number(t[i]);r.add(new ft(s))}else t[i]instanceof Array?r.add(this.parseJsonArray(t[i])):t[i]instanceof Object?r.add(this.parseJsonObject(t[i],new Oe)):t[i]==null?r.add(new Fe):r.add(t[i]);else if(t[i]instanceof Array)r.add(this.parseJsonArray(t[i]));else if(t[i]instanceof Object)r.add(this.parseJsonObject(t[i],new Oe));else if(t[i]==null)r.add(new Fe);else{let s=Array(t[i]);for(let n=0;n<s.length;n++)r.add(s[n])}}),r}},gt="Error: type mismatch",aa="Error: index out of bounds",U=class re{constructor(){}getRawString(t,r){return this.getString(t,r)}toInt(t=0){return t}toFloat(t=0){return t}toBoolean(t=!1){return t}getSize(){return 0}getArray(t=null){return t}getVector(t=new Array){return t}getMap(t){return t}getValueByIndex(t){return re.errorValue.setErrorNotForClientCall(gt)}getValueByString(t){return re.nullValue.setErrorNotForClientCall(gt)}getKeys(){return re.dummyKeys}isError(){return!1}isNull(){return!1}isBool(){return!1}isFloat(){return!1}isString(){return!1}isArray(){return!1}isMap(){return!1}equals(t){return!1}isStatic(){return!1}setErrorNotForClientCall(t){return Ye.errorValue}static staticInitializeNotForClientCall(){K.trueValue=new K(!0),K.falseValue=new K(!1),re.errorValue=new Ye("ERROR",!0),re.nullValue=new Fe,re.dummyKeys=new Array}static staticReleaseNotForClientCall(){K.trueValue=null,K.falseValue=null,re.errorValue=null,re.nullValue=null,re.dummyKeys=null}_stringBuffer;static dummyKeys;static errorValue;static nullValue},G=class ht{constructor(t,r){this._error=null,this._lineCount=0,this._root=null,t!=null&&this.parseBytes(t,r,this._parseCallback)}static create(t,r){let i=new ht;return i.parseBytes(t,r,i._parseCallback)?i:(ht.delete(i),null)}static delete(t){t=null}getRoot(){return this._root}static arrayBufferToString(t){let r=new Uint8Array(t),i="";for(let s=0,n=r.length;s<n;++s)i+="%"+this.pad(r[s].toString(16));return i=decodeURIComponent(i),i}static pad(t){return t.length<2?"0"+t:t}parseBytes(t,r,i){let s=new Array(1),n=ht.arrayBufferToString(t);if(i==null?this._root=this.parseValue(n,r,0,s):this._root=i(JSON.parse(n),new Oe),this._error){let a="\0";return a="Json parse error : @line "+(this._lineCount+1)+`
6
+ `,this._root=new Ve(a),de("{0}",this._root.getRawString()),!1}else if(this._root==null)return this._root=new Ye(this._error,!1),!1;return!0}getParseError(){return this._error}checkEndOfFile(){return this._root.getArray()[1].equals("EOF")}parseValue(t,r,i,s){if(this._error)return null;let n=null,a=i,l;for(;a<r;a++)switch(t[a]){case"-":case".":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{let o=new Array(1);return l=oa(t.slice(a),o),s[0]=t.indexOf(o[0]),new ft(l)}case'"':return new Ve(this.parseString(t,r,a+1,s));case"[":return n=this.parseArray(t,r,a+1,s),n;case"{":return n=this.parseObject(t,r,a+1,s),n;case"n":return a+3<r?(n=new Fe,s[0]=a+4):this._error="parse null",n;case"t":return a+3<r?(n=K.trueValue,s[0]=a+4):this._error="parse true",n;case"f":return a+4<r?(n=K.falseValue,s[0]=a+5):this._error="illegal ',' position",n;case",":return this._error="illegal ',' position",null;case"]":return s[0]=a,null;case`
7
7
  `:this._lineCount++;default:break}return this._error="illegal end of value",null}parseString(t,r,i,s){if(this._error)return null;if(!t)return this._error="string is null",null;let n=i,a,l,o="",u=i;for(;n<r;n++)switch(a=t[n],a){case'"':return s[0]=n+1,o+=t.substr(u,n-u),o;case"//":if(n++,n-1>u&&(o+=t.substr(u,n-u)),u=n+1,n<r)switch(l=t[n],l){case"\\":o+="\\";break;case'"':o+='"';break;case"/":o+="/";break;case"b":o+="\b";break;case"f":o+="\f";break;case"n":o+=`
8
- `;break;case"r":o+="\r";break;case"t":o+=" ";break;case"u":this._error="parse string/unicord escape not supported";break;default:break}else this._error="parse string/escape error";default:break}return this._error="parse string/illegal end",null}parseObject(t,r,i,s){if(this._error)return null;if(!t)return this._error="buffer is null",null;let n=new Ve,a="",l=i,o="",u=Array(1),c=!1;for(;l<r;l++){e:for(;l<r;l++)switch(o=t[l],o){case'"':if(a=this.parseString(t,r,l+1,u),this._error)return null;l=u[0],c=!0;break e;case"}":return s[0]=l+1,n;case":":this._error="illegal ':' position";break;case`
9
- `:this._lineCount++;default:break}if(!c)return this._error="key not found",null;c=!1;e:for(;l<r;l++)switch(o=t[l],o){case":":c=!0,l++;break e;case"}":this._error="illegal '}' position";break;case`
10
- `:this._lineCount++;default:break}if(!c)return this._error="':' not found",null;let d=this.parseValue(t,r,l,u);if(this._error)return null;l=u[0],n.put(a,d);e:for(;l<r;l++)switch(o=t[l],o){case",":break e;case"}":return s[0]=l+1,n;case`
8
+ `;break;case"r":o+="\r";break;case"t":o+=" ";break;case"u":this._error="parse string/unicord escape not supported";break;default:break}else this._error="parse string/escape error";default:break}return this._error="parse string/illegal end",null}parseObject(t,r,i,s){if(this._error)return null;if(!t)return this._error="buffer is null",null;let n=new Oe,a="",l=i,o="",u=Array(1),h=!1;for(;l<r;l++){e:for(;l<r;l++)switch(o=t[l],o){case'"':if(a=this.parseString(t,r,l+1,u),this._error)return null;l=u[0],h=!0;break e;case"}":return s[0]=l+1,n;case":":this._error="illegal ':' position";break;case`
9
+ `:this._lineCount++;default:break}if(!h)return this._error="key not found",null;h=!1;e:for(;l<r;l++)switch(o=t[l],o){case":":h=!0,l++;break e;case"}":this._error="illegal '}' position";break;case`
10
+ `:this._lineCount++;default:break}if(!h)return this._error="':' not found",null;let d=this.parseValue(t,r,l,u);if(this._error)return null;l=u[0],n.put(a,d);e:for(;l<r;l++)switch(o=t[l],o){case",":break e;case"}":return s[0]=l+1,n;case`
11
11
  `:this._lineCount++;default:break}}return this._error="illegal end of perseObject",null}parseArray(t,r,i,s){if(this._error)return null;if(!t)return this._error="buffer is null",null;let n=new ir,a=i,l,o=new Array(1);for(;a<r;a++){let u=this.parseValue(t,r,a,o);if(this._error)return null;a=o[0],u&&n.add(u);e:for(;a<r;a++)switch(l=t[a],l){case",":break e;case"]":return s[0]=a+1,n;case`
12
- `:++this._lineCount;default:break}}return n=void 0,this._error="illegal end of parseObject",null}_parseCallback=ta.parseJsonObject;_error;_lineCount;_root},ft=class extends U{constructor(e){super(),this._value=e}isFloat(){return!0}getString(e,t){return this._value=parseFloat("\0"),this._stringBuffer="\0",this._stringBuffer}toInt(e=0){return parseInt(this._value.toString())}toFloat(e=0){return this._value}equals(e){return typeof e=="number"?Math.round(e)?!1:e==this._value:!1}_value},K=class extends U{isBool(){return!0}toBoolean(e=!1){return this._boolValue}getString(e,t){return this._stringBuffer=this._boolValue?"true":"false",this._stringBuffer}equals(e){return typeof e=="boolean"?e==this._boolValue:!1}isStatic(){return!0}constructor(e){super(),this._boolValue=e}static trueValue;static falseValue;_boolValue},Oe=class extends U{constructor(e){super(),this._stringBuffer=e}isString(){return!0}getString(e,t){return this._stringBuffer}equals(e){return typeof e=="string"?this._stringBuffer==e:!1}},Ye=class extends Oe{isStatic(){return this._isStatic}setErrorNotForClientCall(e){return this._stringBuffer=e,this}constructor(e,t){typeof e=="string"?super(e):super(e),this._isStatic=t}isError(){return!0}_isStatic},Fe=class extends U{isNull(){return!0}getString(e,t){return this._stringBuffer}isStatic(){return!0}setErrorNotForClientCall(e){return this._stringBuffer=e,Ye.nullValue}constructor(){super(),this._stringBuffer="NullValue"}},ir=class extends U{constructor(){super(),this._array=new Array}release(){for(let e=0;e<this._array.length;e++){let t=this._array[e];t&&!t.isStatic()&&(t=void 0,t=null)}}isArray(){return!0}getValueByIndex(e){if(e<0||this._array.length<=e)return U.errorValue.setErrorNotForClientCall(ra);let t=this._array[e];return t??U.nullValue}getValueByString(e){return U.errorValue.setErrorNotForClientCall(gt)}getString(e,t){let r=t+`[
12
+ `:++this._lineCount;default:break}}return n=void 0,this._error="illegal end of parseObject",null}_parseCallback=na.parseJsonObject;_error;_lineCount;_root},ft=class extends U{constructor(e){super(),this._value=e}isFloat(){return!0}getString(e,t){return this._value=parseFloat("\0"),this._stringBuffer="\0",this._stringBuffer}toInt(e=0){return parseInt(this._value.toString())}toFloat(e=0){return this._value}equals(e){return typeof e=="number"?Math.round(e)?!1:e==this._value:!1}_value},K=class extends U{isBool(){return!0}toBoolean(e=!1){return this._boolValue}getString(e,t){return this._stringBuffer=this._boolValue?"true":"false",this._stringBuffer}equals(e){return typeof e=="boolean"?e==this._boolValue:!1}isStatic(){return!0}constructor(e){super(),this._boolValue=e}static trueValue;static falseValue;_boolValue},Ve=class extends U{constructor(e){super(),this._stringBuffer=e}isString(){return!0}getString(e,t){return this._stringBuffer}equals(e){return typeof e=="string"?this._stringBuffer==e:!1}},Ye=class extends Ve{isStatic(){return this._isStatic}setErrorNotForClientCall(e){return this._stringBuffer=e,this}constructor(e,t){typeof e=="string"?super(e):super(e),this._isStatic=t}isError(){return!0}_isStatic},Fe=class extends U{isNull(){return!0}getString(e,t){return this._stringBuffer}isStatic(){return!0}setErrorNotForClientCall(e){return this._stringBuffer=e,Ye.nullValue}constructor(){super(),this._stringBuffer="NullValue"}},ir=class extends U{constructor(){super(),this._array=new Array}release(){for(let e=0;e<this._array.length;e++){let t=this._array[e];t&&!t.isStatic()&&(t=void 0,t=null)}}isArray(){return!0}getValueByIndex(e){if(e<0||this._array.length<=e)return U.errorValue.setErrorNotForClientCall(aa);let t=this._array[e];return t??U.nullValue}getValueByString(e){return U.errorValue.setErrorNotForClientCall(gt)}getString(e,t){let r=t+`[
13
13
  `;for(let i=0;i<this._array.length;i++){let s=this._array[i];this._stringBuffer+=t+""+s.getString(t+" ")+`
14
14
  `}return this._stringBuffer=r+t+`]
15
- `,this._stringBuffer}add(e){this._array.push(e)}getVector(e=null){return this._array}getSize(){return this._array.length}_array},Ve=class extends U{constructor(){super(),this._map=new Map}release(){this._map.clear()}isMap(){return!0}getValueByString(e){let t=this._map.get(e);return t??U.nullValue}getValueByIndex(e){return U.errorValue.setErrorNotForClientCall(gt)}getString(e,t){this._stringBuffer=t+`{
15
+ `,this._stringBuffer}add(e){this._array.push(e)}getVector(e=null){return this._array}getSize(){return this._array.length}_array},Oe=class extends U{constructor(){super(),this._map=new Map}release(){this._map.clear()}isMap(){return!0}getValueByString(e){let t=this._map.get(e);return t??U.nullValue}getValueByIndex(e){return U.errorValue.setErrorNotForClientCall(gt)}getString(e,t){this._stringBuffer=t+`{
16
16
  `;for(let r of this._map){let i=r[0],s=r[1];this._stringBuffer+=t+" "+i+" : "+s.getString(t+" ")+`
17
17
  `}return this._stringBuffer+=t+`}
18
- `,this._stringBuffer}getMap(e){return this._map}put(e,t){this._map.set(e,t)}getKeys(){return this._keys||(this._keys=[...this._map.keys()]),this._keys}getSize(){return this._keys.length}_map;_keys};(function(e){e.CubismJson=G,e.JsonArray=ir,e.JsonBoolean=K,e.JsonError=Ye,e.JsonFloat=ft,e.JsonMap=Ve,e.JsonNullvalue=Fe,e.JsonString=Oe,e.Value=U})(ai||(ai={}));Z=!1,we=!1,Ee=null,Ge=null,$=Object.freeze({vertexOffset:0,vertexStep:2});P=class{static startUp(e=null){if(Z)return de("CubismFramework.startUp() is already done."),Z;if(Ee=e,Ee!=null&&Live2DCubismCore.Logging.csmSetLogFunction(Ee.logFunction),Z=!0,Z){let t=Live2DCubismCore.Version.csmGetVersion(),r=(t&4278190080)>>24,i=(t&16711680)>>16,s=t&65535,n=t;de("Live2D Cubism Core version: {0}.{1}.{2} ({3})",("00"+r).slice(-2),("00"+i).slice(-2),("0000"+s).slice(-4),n)}return de("CubismFramework.startUp() is complete."),Z}static cleanUp(){Z=!1,we=!1,Ee=null,Ge=null}static initialize(e=0){if(k(Z),!Z){V("CubismFramework is not started.");return}if(we){V("CubismFramework.initialize() skipped, already initialized.");return}U.staticInitializeNotForClientCall(),Ge=new _s,Live2DCubismCore.Memory.initializeAmountOfMemory(e),we=!0,de("CubismFramework.initialize() is complete.")}static dispose(){if(k(Z),!Z){V("CubismFramework is not started.");return}if(!we){V("CubismFramework.dispose() skipped, not initialized.");return}U.staticReleaseNotForClientCall(),Ge.release(),Ge=null,pt.staticRelease(),we=!1,de("CubismFramework.dispose() is complete.")}static isStarted(){return Z}static isInitialized(){return we}static coreLogFunction(e){Live2DCubismCore.Logging.csmGetLogFunction()&&Live2DCubismCore.Logging.csmGetLogFunction()(e)}static getLoggingLevel(){return Ee!=null?Ee.loggingLevel:5}static getIdManager(){return Ge}constructor(){}};(function(e){e.Constant=$,e.csmDelete=Le,e.CubismFramework=P})(oi||(oi={}));sa=(function(e){return e[e.FrequestNode_Groups=0]="FrequestNode_Groups",e[e.FrequestNode_Moc=1]="FrequestNode_Moc",e[e.FrequestNode_Motions=2]="FrequestNode_Motions",e[e.FrequestNode_Expressions=3]="FrequestNode_Expressions",e[e.FrequestNode_Textures=4]="FrequestNode_Textures",e[e.FrequestNode_Physics=5]="FrequestNode_Physics",e[e.FrequestNode_Pose=6]="FrequestNode_Pose",e[e.FrequestNode_HitAreas=7]="FrequestNode_HitAreas",e})({}),ys=class extends ps{constructor(e,t){super(),this._json=G.create(e,t),this.getJson()&&(this._jsonValue=[this.getJson().getRoot().getValueByString(this.groups),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.moc),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.motions),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.expressions),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.textures),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.physics),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.pose),this.getJson().getRoot().getValueByString(this.hitAreas)])}release(){G.delete(this._json),this._jsonValue=null}getJson(){return this._json}getModelFileName(){return this.isExistModelFile()?this._jsonValue[1].getRawString():""}getTextureCount(){return this.isExistTextureFiles()?this._jsonValue[4].getSize():0}getTextureDirectory(){let e=this._jsonValue[4].getValueByIndex(0).getRawString().split("/"),t=e.length-1,r="";for(let i=0;i<t;i++)r+=e[i],i<t-1&&(r+="/");return r}getTextureFileName(e){return this._jsonValue[4].getValueByIndex(e).getRawString()}getHitAreasCount(){return this.isExistHitAreas()?this._jsonValue[7].getSize():0}getHitAreaId(e){return P.getIdManager().getId(this._jsonValue[7].getValueByIndex(e).getValueByString(this.id).getRawString())}getHitAreaName(e){return this._jsonValue[7].getValueByIndex(e).getValueByString(this.name).getRawString()}getPhysicsFileName(){return this.isExistPhysicsFile()?this._jsonValue[5].getRawString():""}getPoseFileName(){return this.isExistPoseFile()?this._jsonValue[6].getRawString():""}getExpressionCount(){return this.isExistExpressionFile()?this._jsonValue[3].getSize():0}getExpressionName(e){return this._jsonValue[3].getValueByIndex(e).getValueByString(this.name).getRawString()}getExpressionFileName(e){return this._jsonValue[3].getValueByIndex(e).getValueByString(this.filePath).getRawString()}getMotionGroupCount(){return this.isExistMotionGroups()?this._jsonValue[2].getKeys().length:0}getMotionGroupName(e){return this.isExistMotionGroups()?this._jsonValue[2].getKeys()[e]:null}getMotionCount(e){return this.isExistMotionGroupName(e)?this._jsonValue[2].getValueByString(e).getSize():0}getMotionFileName(e,t){return this.isExistMotionGroupName(e)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.filePath).getRawString():""}getMotionSoundFileName(e,t){return this.isExistMotionSoundFile(e,t)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.soundPath).getRawString():""}getMotionFadeInTimeValue(e,t){return this.isExistMotionFadeIn(e,t)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeInTime).toFloat():-1}getMotionFadeOutTimeValue(e,t){return this.isExistMotionFadeOut(e,t)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeOutTime).toFloat():-1}getUserDataFile(){return this.isExistUserDataFile()?this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData).getRawString():""}getLayoutMap(e){let t=this.getJson().getRoot().getValueByString(this.layout).getMap();if(t==null)return!1;let r=!1;for(let i of t)e.set(i[0],i[1].toFloat()),r=!0;return r}getEyeBlinkParameterCount(){if(!this.isExistEyeBlinkParameters())return 0;let e=0;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.eyeBlink){e=r.getValueByString(this.ids).getVector().length;break}}return e}getEyeBlinkParameterId(e){if(!this.isExistEyeBlinkParameters())return null;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.eyeBlink)return P.getIdManager().getId(r.getValueByString(this.ids).getValueByIndex(e).getRawString())}return null}getLipSyncParameterCount(){if(!this.isExistLipSyncParameters())return 0;let e=0;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.lipSync){e=r.getValueByString(this.ids).getVector().length;break}}return e}getLipSyncParameterId(e){if(!this.isExistLipSyncParameters())return null;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.lipSync)return P.getIdManager().getId(r.getValueByString(this.ids).getValueByIndex(e).getRawString())}return null}isExistModelFile(){let e=this._jsonValue[1];return!e.isNull()&&!e.isError()}isExistTextureFiles(){let e=this._jsonValue[4];return!e.isNull()&&!e.isError()}isExistHitAreas(){let e=this._jsonValue[7];return!e.isNull()&&!e.isError()}isExistPhysicsFile(){let e=this._jsonValue[5];return!e.isNull()&&!e.isError()}isExistPoseFile(){let e=this._jsonValue[6];return!e.isNull()&&!e.isError()}isExistExpressionFile(){let e=this._jsonValue[3];return!e.isNull()&&!e.isError()}isExistMotionGroups(){let e=this._jsonValue[2];return!e.isNull()&&!e.isError()}isExistMotionGroupName(e){let t=this._jsonValue[2].getValueByString(e);return!t.isNull()&&!t.isError()}isExistMotionSoundFile(e,t){let r=this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.soundPath);return!r.isNull()&&!r.isError()}isExistMotionFadeIn(e,t){let r=this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeInTime);return!r.isNull()&&!r.isError()}isExistMotionFadeOut(e,t){let r=this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeOutTime);return!r.isNull()&&!r.isError()}isExistUserDataFile(){let e=this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData);return!e.isNull()&&!e.isError()}isExistEyeBlinkParameters(){if(this._jsonValue[0].isNull()||this._jsonValue[0].isError())return!1;for(let e=0;e<this._jsonValue[0].getSize();++e)if(this._jsonValue[0].getValueByIndex(e).getValueByString(this.name).getRawString()==this.eyeBlink)return!0;return!1}isExistLipSyncParameters(){if(this._jsonValue[0].isNull()||this._jsonValue[0].isError())return!1;for(let e=0;e<this._jsonValue[0].getSize();++e)if(this._jsonValue[0].getValueByIndex(e).getValueByString(this.name).getRawString()==this.lipSync)return!0;return!1}_json;_jsonValue;version="Version";fileReferences="FileReferences";groups="Groups";layout="Layout";hitAreas="HitAreas";moc="Moc";textures="Textures";physics="Physics";pose="Pose";expressions="Expressions";motions="Motions";userData="UserData";name="Name";filePath="File";id="Id";ids="Ids";target="Target";idle="Idle";tapBody="TapBody";pinchIn="PinchIn";pinchOut="PinchOut";shake="Shake";flickHead="FlickHead";parameter="Parameter";soundPath="Sound";fadeInTime="FadeInTime";fadeOutTime="FadeOutTime";centerX="CenterX";centerY="CenterY";x="X";y="Y";width="Width";height="Height";lipSync="LipSync";eyeBlink="EyeBlink";initParameter="init_param";initPartsVisible="init_parts_visible";val="val"};(function(e){e.CubismModelSettingJson=ys,e.FrequestNode=sa})(li||(li={}));sr=class bs{static create(){return new bs}static delete(t){t!=null&&(t=null)}setParameters(t){this._breathParameters=t}getParameters(){return this._breathParameters}updateParameters(t,r){this._currentTime+=r;let i=this._currentTime*2*Math.PI;for(let s=0;s<this._breathParameters.length;++s){let n=this._breathParameters[s];t.addParameterValueById(n.parameterId,n.offset+n.peak*Math.sin(i/n.cycle),n.weight)}}constructor(){this._currentTime=0}_breathParameters;_currentTime},De=class{constructor(e,t,r,i,s){this.parameterId=e??null,this.offset=t??0,this.peak=r??0,this.cycle=i??0,this.weight=s??0}parameterId;offset;peak;cycle;weight};(function(e){e.BreathParameterData=De,e.CubismBreath=sr})(ui||(ui={}));nr=class Yt{static create(t=null){return new Yt(t)}static delete(t){t!=null&&(t=null)}setBlinkingInterval(t){this._blinkingIntervalSeconds=t}setBlinkingSetting(t,r,i){this._closingSeconds=t,this._closedSeconds=r,this._openingSeconds=i}setParameterIds(t){this._parameterIds=t}getParameterIds(){return this._parameterIds}updateParameters(t,r){this._userTimeSeconds+=r;let i,s=0;switch(this._blinkingState){case 2:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closingSeconds,s>=1&&(s=1,this._blinkingState=3,this._stateStartTimeSeconds=this._userTimeSeconds),i=1-s;break;case 3:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closedSeconds,s>=1&&(this._blinkingState=4,this._stateStartTimeSeconds=this._userTimeSeconds),i=0;break;case 4:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._openingSeconds,s>=1&&(s=1,this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming()),i=s;break;case 1:this._nextBlinkingTime<this._userTimeSeconds&&(this._blinkingState=2,this._stateStartTimeSeconds=this._userTimeSeconds),i=1;break;default:this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming(),i=1;break}Yt.CloseIfZero||(i=-i);for(let n=0;n<this._parameterIds.length;++n)t.setParameterValueById(this._parameterIds[n],i)}constructor(t){if(this._blinkingState=0,this._nextBlinkingTime=0,this._stateStartTimeSeconds=0,this._blinkingIntervalSeconds=4,this._closingSeconds=.1,this._closedSeconds=.05,this._openingSeconds=.15,this._userTimeSeconds=0,this._parameterIds=new Array,t!=null){this._parameterIds.length=t.getEyeBlinkParameterCount();for(let r=0;r<t.getEyeBlinkParameterCount();++r)this._parameterIds[r]=t.getEyeBlinkParameterId(r)}}determinNextBlinkingTiming(){let t=Math.random();return this._userTimeSeconds+t*(2*this._blinkingIntervalSeconds-1)}_blinkingState;_parameterIds;_nextBlinkingTime;_stateStartTimeSeconds;_blinkingIntervalSeconds;_closingSeconds;_closedSeconds;_openingSeconds;_userTimeSeconds;static CloseIfZero=!0},na=(function(e){return e[e.EyeState_First=0]="EyeState_First",e[e.EyeState_Interval=1]="EyeState_Interval",e[e.EyeState_Closing=2]="EyeState_Closing",e[e.EyeState_Closed=3]="EyeState_Closed",e[e.EyeState_Opening=4]="EyeState_Opening",e})({});(function(e){e.CubismEyeBlink=nr,e.EyeState=na})(hi||(hi={}));zt=class Bs{static create(){return new Bs}static delete(t){t!=null&&(t=null)}setParameters(t){this._lookParameters=t}getParameters(){return this._lookParameters}updateParameters(t,r,i){for(let s=0;s<this._lookParameters.length;++s){let n=this._lookParameters[s];t.addParameterValueById(n.parameterId,n.factorX*r+n.factorY*i+n.factorXY*r*i)}}constructor(){this._lookParameters=new Array}_lookParameters},Ie=class{constructor(e,t,r,i){this.parameterId=e??null,this.factorX=t??0,this.factorY=r??0,this.factorXY=i??0}parameterId;factorX;factorY;factorXY};(function(e){e.LookParameterData=Ie,e.CubismLook=zt})(ci||(ci={}));ar=class extends ne{constructor(e,t){super(),this._width=e!==void 0?e:0,this._height=t!==void 0?t:0,this.setHeight(2)}setWidth(e){let t=e/this._width,r=t;this.scale(t,r)}setHeight(e){let t=e/this._height,r=t;this.scale(t,r)}setPosition(e,t){this.translate(e,t)}setCenterPosition(e,t){this.centerX(e),this.centerY(t)}top(e){this.setY(e)}bottom(e){let t=this._height*this.getScaleY();this.translateY(e-t)}left(e){this.setX(e)}right(e){let t=this._width*this.getScaleX();this.translateX(e-t)}centerX(e){let t=this._width*this.getScaleX();this.translateX(e-t/2)}setX(e){this.translateX(e)}centerY(e){let t=this._height*this.getScaleY();this.translateY(e-t/2)}setY(e){this.translateY(e)}setupFromLayout(e){let t="width",r="height",n="center_x",a="center_y",o="bottom",u="left",c="right";for(let d of e){let h=d[0],g=d[1];h==t?this.setWidth(g):h==r&&this.setHeight(g)}for(let d of e){let h=d[0],g=d[1];h=="x"?this.setX(g):h=="y"?this.setY(g):h==n?this.centerX(g):h==a?this.centerY(g):h=="top"?this.top(g):h==o?this.bottom(g):h==u?this.left(g):h==c&&this.right(g)}}_width;_height};(function(e){e.CubismModelMatrix=ar})(di||(di={}));aa=.001,Tt=.5,gi="FadeInTime",fi="Link",oa="Groups",la="Id",Jt=class Is{static create(t,r){let i=G.create(t,r);if(!i)return null;let s=new Is,n=i.getRoot();n.getValueByString(gi).isNull()||(s._fadeTimeSeconds=n.getValueByString(gi).toFloat(Tt),s._fadeTimeSeconds<0&&(s._fadeTimeSeconds=Tt));let a=n.getValueByString(oa),l=a.getSize();s._partGroupCounts.length=l;for(let o=0;o<l;++o){let u=a.getValueByIndex(o),c=u.getSize(),d=0;for(let h=0;h<c;++h){let g=u.getValueByIndex(h),A=new jt;if(A.partId=P.getIdManager().getId(g.getValueByString(la).getRawString()),!g.getValueByString(fi).isNull()){let p=g.getValueByString(fi),f=p.getSize();for(let _=0;_<f;++_){let y=new jt;y.partId=P.getIdManager().getId(p.getValueByIndex(_).getString()),A.link.push(y)}}s._partGroups.push(A.clone()),++d}s._partGroupCounts[o]=d}return G.delete(i),s}static delete(t){t!=null&&(t=null)}updateParameters(t,r){t!=this._lastModel&&this.reset(t),this._lastModel=t,r<0&&(r=0);let i=0;for(let s=0;s<this._partGroupCounts.length;s++){let n=this._partGroupCounts[s];this.doFade(t,r,i,n),i+=n}this.copyPartOpacities(t)}reset(t){let r=0;for(let i=0;i<this._partGroupCounts.length;++i){let s=this._partGroupCounts[i];for(let n=r;n<r+s;++n){this._partGroups[n].initialize(t);let a=this._partGroups[n].partIndex,l=this._partGroups[n].parameterIndex;if(!(a<0)){t.setPartOpacityByIndex(a,n==r?1:0),t.setParameterValueByIndex(l,n==r?1:0);for(let o=0;o<this._partGroups[n].link.length;++o)this._partGroups[n].link[o].initialize(t)}}r+=s}}copyPartOpacities(t){for(let r=0;r<this._partGroups.length;++r){let i=this._partGroups[r];if(i.link.length==0)continue;let s=this._partGroups[r].partIndex,n=t.getPartOpacityByIndex(s);for(let a=0;a<i.link.length;++a){let l=i.link[a].partIndex;l<0||t.setPartOpacityByIndex(l,n)}}}doFade(t,r,i,s){let n=-1,a=1,l=.5,o=.15;for(let u=i;u<i+s;++u){let c=this._partGroups[u].partIndex,d=this._partGroups[u].parameterIndex;if(t.getParameterValueByIndex(d)>aa){if(n>=0)break;if(n=u,this._fadeTimeSeconds==0){a=1;continue}a=t.getPartOpacityByIndex(c),a+=r/this._fadeTimeSeconds,a>1&&(a=1)}}n<0&&(n=0,a=1);for(let u=i;u<i+s;++u){let c=this._partGroups[u].partIndex;if(n==u)t.setPartOpacityByIndex(c,a);else{let d=t.getPartOpacityByIndex(c),h;a<l?h=a*(l-1)/l+1:h=(1-a)*l/(1-l),(1-h)*(1-a)>o&&(h=1-o/(1-a)),d>h&&(d=h),t.setPartOpacityByIndex(c,d)}}}constructor(){this._fadeTimeSeconds=Tt,this._lastModel=null,this._partGroups=new Array,this._partGroupCounts=new Array}_partGroups;_partGroupCounts;_fadeTimeSeconds;_lastModel},jt=class Ss{constructor(t){if(this.parameterIndex=0,this.partIndex=0,this.link=new Array,t!=null){this.partId=t.partId,this.link.length=t.link.length;for(let r=0;r<t.link.length;r++)this.link[r]=t.link[r].clone()}}assignment(t){this.partId=t.partId;let r=this.link.length;this.link.length+=t.link.length;for(let i of t.link)this.link[r++]=i.clone();return this}initialize(t){this.parameterIndex=t.getParameterIndex(this.partId),this.partIndex=t.getPartIndex(this.partId),t.setParameterValueByIndex(this.parameterIndex,1)}clone(){let t=new Ss;t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=new Array,t.link.length=this.link.length;for(let r=0;r<this.link.length;r++)t.link[r]=this.link[r].clone();return t}partId;parameterIndex;partIndex;link};(function(e){e.CubismPose=Jt,e.PartData=jt})(Ai||(Ai={}));Ft=30,pi=.01,Ms=class{constructor(){this._faceTargetX=0,this._faceTargetY=0,this._faceX=0,this._faceY=0,this._faceVX=0,this._faceVY=0,this._lastTimeSeconds=0,this._userTimeSeconds=0}update(e){this._userTimeSeconds+=e;let t=40/10*1/Ft;if(this._lastTimeSeconds==0){this._lastTimeSeconds=this._userTimeSeconds;return}let r=(this._userTimeSeconds-this._lastTimeSeconds)*Ft;this._lastTimeSeconds=this._userTimeSeconds;let i=.15*Ft,s=r*t/i,n=this._faceTargetX-this._faceX,a=this._faceTargetY-this._faceY;if(M.abs(n)<=pi&&M.abs(a)<=pi)return;let l=M.sqrt(n*n+a*a),o=t*n/l,u=t*a/l,c=o-this._faceVX,d=u-this._faceVY,h=M.sqrt(c*c+d*d);(h<-s||h>s)&&(c*=s/h,d*=s/h),this._faceVX+=c,this._faceVY+=d;{let g=.5*(M.sqrt(s*s+16*s*l-8*s*l)-s),A=M.sqrt(this._faceVX*this._faceVX+this._faceVY*this._faceVY);A>g&&(this._faceVX*=g/A,this._faceVY*=g/A)}this._faceX+=this._faceVX,this._faceY+=this._faceVY}getX(){return this._faceX}getY(){return this._faceY}set(e,t){this._faceTargetX=e,this._faceTargetY=t}_faceTargetX;_faceTargetY;_faceX;_faceY;_faceVX;_faceVY;_lastTimeSeconds;_userTimeSeconds};(function(e){e.CubismTargetPoint=Ms})(mi||(mi={}));xs=class{constructor(){this._autoDelete=!1,this._motion=null,this._available=!0,this._finished=!1,this._started=!1,this._startTimeSeconds=-1,this._fadeInStartTimeSeconds=0,this._endTimeSeconds=-1,this._stateTimeSeconds=0,this._stateWeight=0,this._lastEventCheckSeconds=0,this._motionQueueEntryHandle=this,this._fadeOutSeconds=0,this._isTriggeredFadeOut=!1}release(){this._autoDelete&&this._motion&&Se.delete(this._motion)}setFadeOut(e){this._fadeOutSeconds=e,this._isTriggeredFadeOut=!0}startFadeOut(e,t){let r=t+e;this._isTriggeredFadeOut=!0,(this._endTimeSeconds<0||r<this._endTimeSeconds)&&(this._endTimeSeconds=r)}isFinished(){return this._finished}isStarted(){return this._started}getStartTime(){return this._startTimeSeconds}getFadeInStartTime(){return this._fadeInStartTimeSeconds}getEndTime(){return this._endTimeSeconds}setStartTime(e){this._startTimeSeconds=e}setFadeInStartTime(e){this._fadeInStartTimeSeconds=e}setEndTime(e){this._endTimeSeconds=e}setIsFinished(e){this._finished=e}setIsStarted(e){this._started=e}isAvailable(){return this._available}setIsAvailable(e){this._available=e}setState(e,t){this._stateTimeSeconds=e,this._stateWeight=t}getStateTime(){return this._stateTimeSeconds}getStateWeight(){return this._stateWeight}getLastCheckEventSeconds(){return this._lastEventCheckSeconds}setLastCheckEventSeconds(e){this._lastEventCheckSeconds=e}isTriggeredFadeOut(){return this._isTriggeredFadeOut}getFadeOutSeconds(){return this._fadeOutSeconds}getCubismMotion(){return this._motion}_autoDelete;_motion;_available;_finished;_started;_startTimeSeconds;_fadeInStartTimeSeconds;_endTimeSeconds;_stateTimeSeconds;_stateWeight;_lastEventCheckSeconds;_fadeOutSeconds;_isTriggeredFadeOut;_motionQueueEntryHandle};(function(e){e.CubismMotionQueueEntry=xs})(_i||(_i={}));Se=class{static delete(e){e.release(),e=null}constructor(){this._fadeInSeconds=-1,this._fadeOutSeconds=-1,this._weight=1,this._offsetSeconds=0,this._isLoop=!1,this._isLoopFadeIn=!0,this._previousLoopState=this._isLoop,this._firedEventValues=new Array}release(){this._weight=0}updateParameters(e,t,r){if(!t.isAvailable()||t.isFinished())return;this.setupMotionQueueEntry(t,r);let i=this.updateFadeWeight(t,r);this.doUpdateParameters(e,r,i,t),t.getEndTime()>0&&t.getEndTime()<r&&t.setIsFinished(!0)}setupMotionQueueEntry(e,t){e==null||e.isStarted()||e.isAvailable()&&(e.setIsStarted(!0),e.setStartTime(t-this._offsetSeconds),e.setFadeInStartTime(t),e.getEndTime()<0&&this.adjustEndTime(e),e._motion._onBeganMotion&&e._motion._onBeganMotion(e._motion))}updateFadeWeight(e,t){e==null&&rr.print(4,"motionQueueEntry is null.");let r=this._weight,i=this._fadeInSeconds==0?1:M.getEasingSine((t-e.getFadeInStartTime())/this._fadeInSeconds),s=this._fadeOutSeconds==0||e.getEndTime()<0?1:M.getEasingSine((e.getEndTime()-t)/this._fadeOutSeconds);return r=r*i*s,e.setState(t,r),k(0<=r&&r<=1),r}setFadeInTime(e){this._fadeInSeconds=e}setFadeOutTime(e){this._fadeOutSeconds=e}getFadeOutTime(){return this._fadeOutSeconds}getFadeInTime(){return this._fadeInSeconds}setWeight(e){this._weight=e}getWeight(){return this._weight}getDuration(){return-1}getLoopDuration(){return-1}setOffsetTime(e){this._offsetSeconds=e}setLoop(e){this._isLoop=e}getLoop(){return this._isLoop}setLoopFadeIn(e){this._isLoopFadeIn=e}getLoopFadeIn(){return this._isLoopFadeIn}getFiredEvent(e,t){return this._firedEventValues}setBeganMotionHandler=e=>this._onBeganMotion=e;getBeganMotionHandler=()=>this._onBeganMotion;setFinishedMotionHandler=e=>this._onFinishedMotion=e;getFinishedMotionHandler=()=>this._onFinishedMotion;isExistModelOpacity(){return!1}getModelOpacityIndex(){return-1}getModelOpacityId(e){return null}getModelOpacityValue(){return 1}adjustEndTime(e){let t=this.getDuration(),r=t<=0?-1:e.getStartTime()+t;e.setEndTime(r)}_fadeInSeconds;_fadeOutSeconds;_weight;_offsetSeconds;_isLoop;_isLoopFadeIn;_previousLoopState;_firedEventValues;_onBeganMotion;_onFinishedMotion};(function(e){e.ACubismMotion=Se})(Ci||(Ci={}));or=class{constructor(){this._userTimeSeconds=0,this._eventCallBack=null,this._eventCustomData=null,this._motions=new Array}release(){for(let e=0;e<this._motions.length;++e)this._motions[e]&&(this._motions[e].release(),this._motions[e]=null);this._motions=null}startMotion(e,t,r){if(e==null)return-1;let i=null;for(let s=0;s<this._motions.length;++s)i=this._motions[s],i?.setFadeOut(i._motion.getFadeOutTime());return i=new xs,i._autoDelete=t,i._motion=e,this._motions.push(i),i._motionQueueEntryHandle}isFinished(){for(let e=0;e<this._motions.length;){let t=this._motions[e];if(t==null){this._motions.splice(e,1);continue}if(t._motion==null){t.release(),t=null,this._motions.splice(e,1);continue}if(t.isFinished())e++;else return!1}return!0}isFinishedByHandle(e){for(let t=0;t<this._motions.length;t++){let r=this._motions[t];if(r!=null&&r._motionQueueEntryHandle==e&&!r.isFinished())return!1}return!0}stopAllMotions(){for(let e=0;e<this._motions.length;e++){let t=this._motions[e];if(t==null){this._motions.splice(e,1);continue}t.release(),this._motions.splice(e,1)}}getCubismMotionQueueEntries(){return this._motions}getCubismMotionQueueEntry(e){for(let t=0;t<this._motions.length;t++){let r=this._motions[t];if(r!=null&&r._motionQueueEntryHandle==e)return r}return null}setEventCallback(e,t=null){this._eventCallBack=e,this._eventCustomData=t}doUpdateMotion(e,t){let r=!1;for(let i=0;i<this._motions.length;){let s=this._motions[i];if(s==null){this._motions.splice(i,1);continue}let n=s._motion;if(n==null){s.release(),s=null,this._motions.splice(i,1);continue}n.updateParameters(e,s,t),r=!0;let a=n.getFiredEvent(s.getLastCheckEventSeconds()-s.getStartTime(),t-s.getStartTime());for(let l=0;l<a.length;++l)this._eventCallBack(this,a[l],this._eventCustomData);s.setLastCheckEventSeconds(t),s.isFinished()?(s.release(),s=null,this._motions.splice(i,1)):(s.isTriggeredFadeOut()&&s.startFadeOut(s.getFadeOutSeconds(),t),i++)}return r}_userTimeSeconds;_motions;_eventCallBack;_eventCustomData};(function(e){e.CubismMotionQueueManager=or,e.InvalidMotionQueueEntryHandleValue=-1})(yi||(yi={}));ua=class{parameterId;additiveValue;multiplyValue;overwriteValue},ws=class extends or{constructor(){super(),this._expressionParameterValues=new Array,this._fadeWeights=new Array}release(){this._expressionParameterValues&&(Le(this._expressionParameterValues),this._expressionParameterValues=null),this._fadeWeights&&(Le(this._fadeWeights),this._fadeWeights=null)}getFadeWeight(e){return e<0||this._fadeWeights.length<1||e>=this._fadeWeights.length?(console.warn("Failed to get the fade weight value. The element at that index does not exist."),-1):this._fadeWeights[e]}setFadeWeight(e,t){if(e<0||this._fadeWeights.length<1||this._fadeWeights.length<=e){console.warn("Failed to set the fade weight value. The element at that index does not exist.");return}this._fadeWeights[e]=t}updateMotion(e,t){this._userTimeSeconds+=t;let r=!1,i=this.getCubismMotionQueueEntries(),s=0,n=0;if(this._fadeWeights.length!==i.length){let a=i.length-this._fadeWeights.length,l=this._fadeWeights.length;this._fadeWeights.length+=a;for(let o=0;o<a;o++)this._fadeWeights[l++]=0}for(let a=0;a<this._motions.length;){let l=this._motions[a];if(l==null){i.splice(a,1);continue}let o=l.getCubismMotion();if(o==null){Le(l),i.splice(a,1);continue}let u=o.getExpressionParameters();if(l.isAvailable())for(let c=0;c<u.length;++c){if(u[c].parameterId==null)continue;let d=-1;for(let g=0;g<this._expressionParameterValues.length;++g)if(this._expressionParameterValues[g].parameterId==u[c].parameterId){d=g;break}if(d>=0)continue;let h=new ua;h.parameterId=u[c].parameterId,h.additiveValue=Te.DefaultAdditiveValue,h.multiplyValue=Te.DefaultMultiplyValue,h.overwriteValue=e.getParameterValueById(h.parameterId),this._expressionParameterValues.push(h)}o.setupMotionQueueEntry(l,this._userTimeSeconds),this.setFadeWeight(n,o.updateFadeWeight(l,this._userTimeSeconds)),o.calculateExpressionParameters(e,this._userTimeSeconds,l,this._expressionParameterValues,n,this.getFadeWeight(n)),s+=o.getFadeInTime()==0?1:M.getEasingSine((this._userTimeSeconds-l.getFadeInStartTime())/o.getFadeInTime()),r=!0,l.isTriggeredFadeOut()&&l.startFadeOut(l.getFadeOutSeconds(),this._userTimeSeconds),++a,++n}if(i.length>1&&this.getFadeWeight(this._fadeWeights.length-1)>=1)for(let a=i.length-2;a>=0;--a){let l=i[a];Le(l),i.splice(a,1),this._fadeWeights.splice(a,1)}s>1&&(s=1);for(let a=0;a<this._expressionParameterValues.length;++a){let l=this._expressionParameterValues[a];e.setParameterValueById(l.parameterId,(l.overwriteValue+l.additiveValue)*l.multiplyValue,s),l.additiveValue=Te.DefaultAdditiveValue,l.multiplyValue=Te.DefaultMultiplyValue}return r}_expressionParameterValues;_fadeWeights;_startExpressionTime};(function(e){e.CubismExpressionMotionManager=ws})(bi||(bi={}));ha="FadeInTime",ca="FadeOutTime",Bi="Parameters",da="Id",ga="Value",tt="Blend",fa="Add",Aa="Multiply",pa="Overwrite",Ii=1,Te=class ie extends Se{static DefaultAdditiveValue=0;static DefaultMultiplyValue=1;static create(t,r){let i=new ie;return i.parse(t,r),i}doUpdateParameters(t,r,i,s){for(let n=0;n<this._parameters.length;++n){let a=this._parameters[n];switch(a.blendType){case 0:t.addParameterValueById(a.parameterId,a.value,i);break;case 1:t.multiplyParameterValueById(a.parameterId,a.value,i);break;case 2:t.setParameterValueById(a.parameterId,a.value,i);break;default:break}}}calculateExpressionParameters(t,r,i,s,n,a){if(!(i==null||s==null)&&i.isAvailable())for(let l=0;l<s.length;++l){let o=s[l];if(o.parameterId==null)continue;let u=o.overwriteValue=t.getParameterValueById(o.parameterId),c=this.getExpressionParameters(),d=-1;for(let f=0;f<c.length;++f)if(o.parameterId==c[f].parameterId){d=f;break}if(d<0){n==0?(o.additiveValue=ie.DefaultAdditiveValue,o.multiplyValue=ie.DefaultMultiplyValue,o.overwriteValue=u):(o.additiveValue=this.calculateValue(o.additiveValue,ie.DefaultAdditiveValue,a),o.multiplyValue=this.calculateValue(o.multiplyValue,ie.DefaultMultiplyValue,a),o.overwriteValue=this.calculateValue(o.overwriteValue,u,a));continue}let h=c[d].value,g,A,p;switch(c[d].blendType){case 0:g=h,A=ie.DefaultMultiplyValue,p=u;break;case 1:g=ie.DefaultAdditiveValue,A=h,p=u;break;case 2:g=ie.DefaultAdditiveValue,A=ie.DefaultMultiplyValue,p=h;break;default:return}n==0?(o.additiveValue=g,o.multiplyValue=A,o.overwriteValue=p):(o.additiveValue=o.additiveValue*(1-a)+g*a,o.multiplyValue=o.multiplyValue*(1-a)+A*a,o.overwriteValue=o.overwriteValue*(1-a)+p*a)}}getExpressionParameters(){return this._parameters}parse(t,r){let i=G.create(t,r);if(!i)return;let s=i.getRoot();this.setFadeInTime(s.getValueByString(ha).toFloat(Ii)),this.setFadeOutTime(s.getValueByString(ca).toFloat(Ii));let n=s.getValueByString(Bi).getSize(),a=this._parameters.length;this._parameters.length+=n;for(let l=0;l<n;++l){let o=s.getValueByString(Bi).getValueByIndex(l),u=P.getIdManager().getId(o.getValueByString(da).getRawString()),c=o.getValueByString(ga).toFloat(),d;o.getValueByString(tt).isNull()||o.getValueByString(tt).getString()==fa?d=0:o.getValueByString(tt).getString()==Aa?d=1:o.getValueByString(tt).getString()==pa?d=2:d=0;let h=new Es;h.parameterId=u,h.blendType=d,h.value=c,this._parameters[a++]=h}G.delete(i)}calculateValue(t,r,i){return t*(1-i)+r*i}constructor(){super(),this._parameters=new Array}_parameters},ma=(function(e){return e[e.Additive=0]="Additive",e[e.Multiply=1]="Multiply",e[e.Overwrite=2]="Overwrite",e})({}),Es=class{parameterId;blendType;value};(function(e){e.CubismExpressionMotion=Te,e.ExpressionBlendType=ma,e.ExpressionParameter=Es})(Si||(Si={}));_a=(function(e){return e[e.CubismMotionCurveTarget_Model=0]="CubismMotionCurveTarget_Model",e[e.CubismMotionCurveTarget_Parameter=1]="CubismMotionCurveTarget_Parameter",e[e.CubismMotionCurveTarget_PartOpacity=2]="CubismMotionCurveTarget_PartOpacity",e})({}),Ca=(function(e){return e[e.CubismMotionSegmentType_Linear=0]="CubismMotionSegmentType_Linear",e[e.CubismMotionSegmentType_Bezier=1]="CubismMotionSegmentType_Bezier",e[e.CubismMotionSegmentType_Stepped=2]="CubismMotionSegmentType_Stepped",e[e.CubismMotionSegmentType_InverseStepped=3]="CubismMotionSegmentType_InverseStepped",e})({}),ze=class{time=0;value=0},vs=class{constructor(){this.evaluate=null,this.basePointIndex=0,this.segmentType=0}evaluate;basePointIndex;segmentType},Ps=class{constructor(){this.type=0,this.segmentCount=0,this.baseSegmentIndex=0,this.fadeInTime=0,this.fadeOutTime=0}type;id;segmentCount;baseSegmentIndex;fadeInTime;fadeOutTime},Rs=class{fireTime=0;value},Ds=class{constructor(){this.duration=0,this.loop=!1,this.curveCount=0,this.eventCount=0,this.fps=0,this.curves=new Array,this.segments=new Array,this.points=new Array,this.events=new Array}duration;loop;curveCount;eventCount;fps;curves;segments;points;events};(function(e){e.CubismMotionCurve=Ps,e.CubismMotionCurveTarget=_a,e.CubismMotionData=Ds,e.CubismMotionEvent=Rs,e.CubismMotionPoint=ze,e.CubismMotionSegment=vs,e.CubismMotionSegmentType=Ca})(Mi||(Mi={}));N="Meta",ya="Duration",ba="Loop",Ba="AreBeziersRestricted",Ia="CurveCount",Sa="Fps",Ma="TotalSegmentCount",xa="TotalPointCount",he="Curves",wa="Target",Ea="Id",rt="FadeInTime",it="FadeOutTime",xi="Segments",wi="UserData",va="UserDataCount",Pa="TotalUserDataSize",Ra="Time",Da="Value",Ls=class{constructor(e,t){this._json=G.create(e,t)}release(){G.delete(this._json)}getMotionDuration(){return this._json.getRoot().getValueByString(N).getValueByString(ya).toFloat()}isMotionLoop(){return this._json.getRoot().getValueByString(N).getValueByString(ba).toBoolean()}hasConsistency(){let e=!0;if(!this._json||!this._json.getRoot())return!1;let t=this._json.getRoot().getValueByString(he).getVector().length,r=0,i=0;for(let s=0;s<t;++s)for(let n=0;n<this.getMotionCurveSegmentCount(s);){switch(n==0&&(i+=1,n+=2),this.getMotionCurveSegment(s,n)){case 0:i+=1,n+=3;break;case 1:i+=3,n+=7;break;case 2:i+=1,n+=3;break;case 3:i+=1,n+=3;break;default:k(0);break}++r}return t!=this.getMotionCurveCount()&&(V("The number of curves does not match the metadata."),e=!1),r!=this.getMotionTotalSegmentCount()&&(V("The number of segment does not match the metadata."),e=!1),i!=this.getMotionTotalPointCount()&&(V("The number of point does not match the metadata."),e=!1),e}getEvaluationOptionFlag(e){return e==0?this._json.getRoot().getValueByString(N).getValueByString(Ba).toBoolean():!1}getMotionCurveCount(){return this._json.getRoot().getValueByString(N).getValueByString(Ia).toInt()}getMotionFps(){return this._json.getRoot().getValueByString(N).getValueByString(Sa).toFloat()}getMotionTotalSegmentCount(){return this._json.getRoot().getValueByString(N).getValueByString(Ma).toInt()}getMotionTotalPointCount(){return this._json.getRoot().getValueByString(N).getValueByString(xa).toInt()}isExistMotionFadeInTime(){return!this._json.getRoot().getValueByString(N).getValueByString(rt).isNull()}isExistMotionFadeOutTime(){return!this._json.getRoot().getValueByString(N).getValueByString(it).isNull()}getMotionFadeInTime(){return this._json.getRoot().getValueByString(N).getValueByString(rt).toFloat()}getMotionFadeOutTime(){return this._json.getRoot().getValueByString(N).getValueByString(it).toFloat()}getMotionCurveTarget(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(wa).getRawString()}getMotionCurveId(e){return P.getIdManager().getId(this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(Ea).getRawString())}isExistMotionCurveFadeInTime(e){return!this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(rt).isNull()}isExistMotionCurveFadeOutTime(e){return!this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(it).isNull()}getMotionCurveFadeInTime(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(rt).toFloat()}getMotionCurveFadeOutTime(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(it).toFloat()}getMotionCurveSegmentCount(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(xi).getVector().length}getMotionCurveSegment(e,t){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(xi).getValueByIndex(t).toFloat()}getEventCount(){return this._json.getRoot().getValueByString(N).getValueByString(va).toInt()}getTotalEventValueSize(){return this._json.getRoot().getValueByString(N).getValueByString(Pa).toInt()}getEventTime(e){return this._json.getRoot().getValueByString(wi).getValueByIndex(e).getValueByString(Ra).toFloat()}getEventValue(e){return this._json.getRoot().getValueByString(wi).getValueByIndex(e).getValueByString(Da).getRawString()}_json};(function(e){e.CubismMotionJson=Ls})(Ei||(Ei={}));La="EyeBlink",Ta="LipSync",Fa="Model",Va="Parameter",Oa="PartOpacity",st="Opacity",ka=!1;Os=class ks extends Se{static create(t,r,i,s,n=!1){let a=new ks;if(a.parse(t,r,n),a._motionData)a._sourceFrameRate=a._motionData.fps,a._loopDurationSeconds=a._motionData.duration,a._onFinishedMotion=i,a._onBeganMotion=s;else return Le(a),null;return a}doUpdateParameters(t,r,i,s){this._modelCurveIdEyeBlink==null&&(this._modelCurveIdEyeBlink=P.getIdManager().getId(La)),this._modelCurveIdLipSync==null&&(this._modelCurveIdLipSync=P.getIdManager().getId(Ta)),this._modelCurveIdOpacity==null&&(this._modelCurveIdOpacity=P.getIdManager().getId(st)),this._motionBehavior===1&&this._previousLoopState!==this._isLoop&&(this.adjustEndTime(s),this._previousLoopState=this._isLoop);let n=r-s.getStartTime();n<0&&(n=0);let a=Number.MAX_VALUE,l=Number.MAX_VALUE,o=64,u=0,c=0;this._eyeBlinkParameterIds.length>o&&Ht("too many eye blink targets : {0}",this._eyeBlinkParameterIds.length),this._lipSyncParameterIds.length>o&&Ht("too many lip sync targets : {0}",this._lipSyncParameterIds.length);let d=this._fadeInSeconds<=0?1:M.getEasingSine((r-s.getFadeInStartTime())/this._fadeInSeconds),h=this._fadeOutSeconds<=0||s.getEndTime()<0?1:M.getEasingSine((s.getEndTime()-r)/this._fadeOutSeconds),g,A,p,f=n,_=this._motionData.duration,y=this._motionBehavior===1&&this._isLoop;if(this._isLoop)for(this._motionBehavior===1&&(_+=1/this._motionData.fps);f>_;)f-=_;let C=this._motionData.curves;for(A=0;A<this._motionData.curveCount&&C[A].type==0;++A)g=Vt(this._motionData,A,f,y,_),C[A].id==this._modelCurveIdEyeBlink?l=g:C[A].id==this._modelCurveIdLipSync?a=g:C[A].id==this._modelCurveIdOpacity&&(this._modelOpacity=g,t.setModelOapcity(this.getModelOpacityValue()));let b=0;for(;A<this._motionData.curveCount&&C[A].type==1;++A){if(b++,p=t.getParameterIndex(C[A].id),p==-1)continue;let x=t.getParameterValueByIndex(p);if(g=Vt(this._motionData,A,f,y,_),l!=Number.MAX_VALUE){for(let E=0;E<this._eyeBlinkParameterIds.length&&E<o;++E)if(this._eyeBlinkParameterIds[E]==C[A].id){g*=l,c|=1<<E;break}}if(a!=Number.MAX_VALUE){for(let E=0;E<this._lipSyncParameterIds.length&&E<o;++E)if(this._lipSyncParameterIds[E]==C[A].id){g+=a,u|=1<<E;break}}t.isRepeat(p)&&(g=t.getParameterRepeatValue(p,g));let B;if(C[A].fadeInTime<0&&C[A].fadeOutTime<0)B=x+(g-x)*i;else{let E,T;C[A].fadeInTime<0?E=d:E=C[A].fadeInTime==0?1:M.getEasingSine((r-s.getFadeInStartTime())/C[A].fadeInTime),C[A].fadeOutTime<0?T=h:T=C[A].fadeOutTime==0||s.getEndTime()<0?1:M.getEasingSine((s.getEndTime()-r)/C[A].fadeOutTime);let W=this._weight*E*T;B=x+(g-x)*W}t.setParameterValueByIndex(p,B,1)}if(l!=Number.MAX_VALUE)for(let x=0;x<this._eyeBlinkParameterIds.length&&x<o;++x){let B=t.getParameterValueById(this._eyeBlinkParameterIds[x]);if(c>>x&1)continue;let E=B+(l-B)*i;t.setParameterValueById(this._eyeBlinkParameterIds[x],E)}if(a!=Number.MAX_VALUE)for(let x=0;x<this._lipSyncParameterIds.length&&x<o;++x){let B=t.getParameterValueById(this._lipSyncParameterIds[x]);if(u>>x&1)continue;let E=B+(a-B)*i;t.setParameterValueById(this._lipSyncParameterIds[x],E)}for(;A<this._motionData.curveCount&&C[A].type==2;++A)p=t.getParameterIndex(C[A].id),p!=-1&&(g=Vt(this._motionData,A,f,y,_),t.setParameterValueByIndex(p,g));n>=_&&(this._isLoop?this.updateForNextLoop(s,r,f):(this._onFinishedMotion&&this._onFinishedMotion(this),s.setIsFinished(!0))),this._lastWeight=i}setMotionBehavior(t){this._motionBehavior=t}getMotionBehavior(){return this._motionBehavior}getDuration(){return this._isLoop?-1:this._loopDurationSeconds}getLoopDuration(){return this._loopDurationSeconds}setParameterFadeInTime(t,r){let i=this._motionData.curves;for(let s=0;s<this._motionData.curveCount;++s)if(t==i[s].id){i[s].fadeInTime=r;return}}setParameterFadeOutTime(t,r){let i=this._motionData.curves;for(let s=0;s<this._motionData.curveCount;++s)if(t==i[s].id){i[s].fadeOutTime=r;return}}getParameterFadeInTime(t){let r=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==r[i].id)return r[i].fadeInTime;return-1}getParameterFadeOutTime(t){let r=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==r[i].id)return r[i].fadeOutTime;return-1}setEffectIds(t,r){this._eyeBlinkParameterIds=t,this._lipSyncParameterIds=r}constructor(){super(),this._sourceFrameRate=30,this._loopDurationSeconds=-1,this._isLoop=!1,this._isLoopFadeIn=!0,this._lastWeight=0,this._motionData=null,this._modelCurveIdEyeBlink=null,this._modelCurveIdLipSync=null,this._modelCurveIdOpacity=null,this._eyeBlinkParameterIds=null,this._lipSyncParameterIds=null,this._modelOpacity=1,this._debugMode=!1}release(){this._motionData=void 0,this._motionData=null}updateForNextLoop(t,r,i){switch(this._motionBehavior){case 1:default:t.setStartTime(r-i),this._isLoopFadeIn&&t.setFadeInStartTime(r-i),this._onFinishedMotion!=null&&this._onFinishedMotion(this);break;case 0:t.setStartTime(r),this._isLoopFadeIn&&t.setFadeInStartTime(r);break}}parse(t,r,i=!1){let s=new Ls(t,r);if(!s){s.release(),s=void 0;return}if(i&&!s.hasConsistency()){s.release(),D("Inconsistent motion3.json.");return}this._motionData=new Ds,this._motionData.duration=s.getMotionDuration(),this._motionData.loop=s.isMotionLoop(),this._motionData.curveCount=s.getMotionCurveCount(),this._motionData.fps=s.getMotionFps(),this._motionData.eventCount=s.getEventCount();let n=s.getEvaluationOptionFlag(0);s.isExistMotionFadeInTime()?this._fadeInSeconds=s.getMotionFadeInTime()<0?1:s.getMotionFadeInTime():this._fadeInSeconds=1,s.isExistMotionFadeOutTime()?this._fadeOutSeconds=s.getMotionFadeOutTime()<0?1:s.getMotionFadeOutTime():this._fadeOutSeconds=1,Q(this._motionData.curves,this._motionData.curveCount,Ps,!0),Q(this._motionData.segments,s.getMotionTotalSegmentCount(),vs,!0),Q(this._motionData.points,s.getMotionTotalPointCount(),ze,!0),Q(this._motionData.events,this._motionData.eventCount,Rs,!0);let a=0,l=0;for(let o=0;o<this._motionData.curveCount;++o){s.getMotionCurveTarget(o)==Fa?this._motionData.curves[o].type=0:s.getMotionCurveTarget(o)==Va?this._motionData.curves[o].type=1:s.getMotionCurveTarget(o)==Oa?this._motionData.curves[o].type=2:V('Warning : Unable to get segment type from Curve! The number of "CurveCount" may be incorrect!'),this._motionData.curves[o].id=s.getMotionCurveId(o),this._motionData.curves[o].baseSegmentIndex=l,this._motionData.curves[o].fadeInTime=s.isExistMotionCurveFadeInTime(o)?s.getMotionCurveFadeInTime(o):-1,this._motionData.curves[o].fadeOutTime=s.isExistMotionCurveFadeOutTime(o)?s.getMotionCurveFadeOutTime(o):-1;for(let u=0;u<s.getMotionCurveSegmentCount(o);){switch(u==0?(this._motionData.segments[l].basePointIndex=a,this._motionData.points[a].time=s.getMotionCurveSegment(o,u),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+1),a+=1,u+=2):this._motionData.segments[l].basePointIndex=a-1,s.getMotionCurveSegment(o,u)){case 0:this._motionData.segments[l].segmentType=0,this._motionData.segments[l].evaluate=Ts,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),a+=1,u+=3;break;case 1:this._motionData.segments[l].segmentType=1,n||ka?this._motionData.segments[l].evaluate=Qa:this._motionData.segments[l].evaluate=Ua,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),this._motionData.points[a+1].time=s.getMotionCurveSegment(o,u+3),this._motionData.points[a+1].value=s.getMotionCurveSegment(o,u+4),this._motionData.points[a+2].time=s.getMotionCurveSegment(o,u+5),this._motionData.points[a+2].value=s.getMotionCurveSegment(o,u+6),a+=3,u+=7;break;case 2:this._motionData.segments[l].segmentType=2,this._motionData.segments[l].evaluate=Fs,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),a+=1,u+=3;break;case 3:this._motionData.segments[l].segmentType=3,this._motionData.segments[l].evaluate=Vs,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),a+=1,u+=3;break;default:k(0);break}++this._motionData.curves[o].segmentCount,++l}}for(let o=0;o<s.getEventCount();++o)this._motionData.events[o].fireTime=s.getEventTime(o),this._motionData.events[o].value=s.getEventValue(o);s.release(),s=void 0,s=null}getFiredEvent(t,r){Q(this._firedEventValues,0);for(let i=0;i<this._motionData.eventCount;++i)this._motionData.events[i].fireTime>t&&this._motionData.events[i].fireTime<=r&&this._firedEventValues.push(this._motionData.events[i].value);return this._firedEventValues}isExistModelOpacity(){for(let t=0;t<this._motionData.curveCount;t++){let r=this._motionData.curves[t];if(r.type==0&&r.id.getString().localeCompare(st)==0)return!0}return!1}getModelOpacityIndex(){if(this.isExistModelOpacity())for(let t=0;t<this._motionData.curveCount;t++){let r=this._motionData.curves[t];if(r.type==0&&r.id.getString().localeCompare(st)==0)return t}return-1}getModelOpacityId(t){if(t!=-1){let r=this._motionData.curves[t];if(r.type==0&&r.id.getString().localeCompare(st)==0)return P.getIdManager().getId(r.id.getString())}return null}getModelOpacityValue(){return this._modelOpacity}setDebugMode(t){this._debugMode=t}_sourceFrameRate;_loopDurationSeconds;_motionBehavior=1;_lastWeight;_motionData;_eyeBlinkParameterIds;_lipSyncParameterIds;_modelCurveIdEyeBlink;_modelCurveIdLipSync;_modelCurveIdOpacity;_modelOpacity;_debugMode};(function(e){e.CubismMotion=Os})(vi||(vi={}));Qs=class extends or{constructor(){super(),this._currentPriority=0,this._reservePriority=0}getCurrentPriority(){return this._currentPriority}getReservePriority(){return this._reservePriority}setReservePriority(e){this._reservePriority=e}startMotionPriority(e,t,r){return r==this._reservePriority&&(this._reservePriority=0),this._currentPriority=r,super.startMotion(e,t)}updateMotion(e,t){this._userTimeSeconds+=t;let r=super.doUpdateMotion(e,this._userTimeSeconds);return this.isFinished()&&(this._currentPriority=0),r}reserveMotion(e){return e<=this._reservePriority||e<=this._currentPriority?!1:(this._reservePriority=e,!0)}_currentPriority;_reservePriority};(function(e){e.CubismMotionManager=Qs})(Pi||(Pi={}));Ga=(function(e){return e[e.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",e})({}),Xa=(function(e){return e[e.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",e[e.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",e[e.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",e})({}),Ha=class{constructor(){this.gravity=new w(0,0),this.wind=new w(0,0)}gravity;wind},lr=class{id;targetType},Zt=class{minimum;maximum;defalut},Us=class{constructor(){this.initialPosition=new w(0,0),this.position=new w(0,0),this.lastPosition=new w(0,0),this.lastGravity=new w(0,0),this.force=new w(0,0),this.velocity=new w(0,0)}initialPosition;mobility;delay;acceleration;radius;position;lastPosition;lastGravity;force;velocity},Ns=class{constructor(){this.normalizationPosition=new Zt,this.normalizationAngle=new Zt}inputCount;outputCount;particleCount;baseInputIndex;baseOutputIndex;baseParticleIndex;normalizationPosition;normalizationAngle},Gs=class{constructor(){this.source=new lr}source;sourceParameterIndex;weight;type;reflect;getNormalizedParameterValue},Xs=class{constructor(){this.destination=new lr,this.translationScale=new w(0,0)}destination;destinationParameterIndex;vertexIndex;translationScale;angleScale;weight;type;reflect;valueBelowMinimum;valueExceededMaximum;getValue;getScale},Hs=class{constructor(){this.settings=new Array,this.inputs=new Array,this.outputs=new Array,this.particles=new Array,this.gravity=new w(0,0),this.wind=new w(0,0),this.fps=0}subRigCount;settings;inputs;outputs;particles;gravity;wind;fps};(function(e){e.CubismPhysicsInput=Gs,e.CubismPhysicsNormalization=Zt,e.CubismPhysicsOutput=Xs,e.CubismPhysicsParameter=lr,e.CubismPhysicsParticle=Us,e.CubismPhysicsRig=Hs,e.CubismPhysicsSource=Xa,e.CubismPhysicsSubRig=Ns,e.CubismPhysicsTargetType=Ga,e.PhysicsJsonEffectiveForces=Ha})(Ri||(Ri={}));Xe="Position",Ot="X",kt="Y",Qt="Angle",Di="Type",Li="Id",ce="Meta",nt="EffectiveForces",Wa="TotalInputCount",Ya="TotalOutputCount",za="PhysicsSettingCount",Ti="Gravity",Fi="Wind",Ja="VertexCount",ja="Fps",L="PhysicsSettings",ve="Normalization",Vi="Minimum",Oi="Maximum",ki="Default",Qi="Reflect",Ui="Weight",He="Input",Za="Source",ye="Output",qa="Scale",Ka="VertexIndex",$a="Destination",be="Vertices",eo="Mobility",to="Delay",ro="Radius",io="Acceleration",Ws=class{constructor(e,t){this._json=G.create(e,t)}release(){G.delete(this._json)}getGravity(){let e=new w(0,0);return e.x=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Ti).getValueByString(Ot).toFloat(),e.y=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Ti).getValueByString(kt).toFloat(),e}getWind(){let e=new w(0,0);return e.x=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Fi).getValueByString(Ot).toFloat(),e.y=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Fi).getValueByString(kt).toFloat(),e}getFps(){return this._json.getRoot().getValueByString(ce).getValueByString(ja).toFloat(0)}getSubRigCount(){return this._json.getRoot().getValueByString(ce).getValueByString(za).toInt()}getTotalInputCount(){return this._json.getRoot().getValueByString(ce).getValueByString(Wa).toInt()}getTotalOutputCount(){return this._json.getRoot().getValueByString(ce).getValueByString(Ya).toInt()}getVertexCount(){return this._json.getRoot().getValueByString(ce).getValueByString(Ja).toInt()}getNormalizationPositionMinimumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Xe).getValueByString(Vi).toFloat()}getNormalizationPositionMaximumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Xe).getValueByString(Oi).toFloat()}getNormalizationPositionDefaultValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Xe).getValueByString(ki).toFloat()}getNormalizationAngleMinimumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Qt).getValueByString(Vi).toFloat()}getNormalizationAngleMaximumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Qt).getValueByString(Oi).toFloat()}getNormalizationAngleDefaultValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Qt).getValueByString(ki).toFloat()}getInputCount(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getVector().length}getInputWeight(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(Ui).toFloat()}getInputReflect(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(Qi).toBoolean()}getInputType(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(Di).getRawString()}getInputSourceId(e,t){return P.getIdManager().getId(this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(Za).getValueByString(Li).getRawString())}getOutputCount(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getVector().length}getOutputVertexIndex(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(Ka).toInt()}getOutputAngleScale(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(qa).toFloat()}getOutputWeight(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(Ui).toFloat()}getOutputDestinationId(e,t){return P.getIdManager().getId(this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString($a).getValueByString(Li).getRawString())}getOutputType(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(Di).getRawString()}getOutputReflect(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(Qi).toBoolean()}getParticleCount(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getVector().length}getParticleMobility(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(eo).toFloat()}getParticleDelay(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(to).toFloat()}getParticleAcceleration(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(io).toFloat()}getParticleRadius(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(ro).toFloat()}getParticlePosition(e,t){let r=new w(0,0);return r.x=this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(Xe).getValueByString(Ot).toFloat(),r.y=this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(Xe).getValueByString(kt).toFloat(),r}_json};(function(e){e.CubismPhysicsJson=Ws})(Ni||(Ni={}));Gi="X",Xi="Y",Hi="Angle",so=5,qt=100,Wi=.001,no=5,Kt=class Ys{static create(t,r){let i=new Ys;return i.parse(t,r),i._physicsRig.gravity.y=0,i}static delete(t){t!=null&&(t.release(),t=null)}parse(t,r){this._physicsRig=new Hs;let i=new Ws(t,r);this._physicsRig.gravity=i.getGravity(),this._physicsRig.wind=i.getWind(),this._physicsRig.subRigCount=i.getSubRigCount(),this._physicsRig.fps=i.getFps(),Q(this._physicsRig.settings,this._physicsRig.subRigCount,Ns,!0),Q(this._physicsRig.inputs,i.getTotalInputCount(),Gs,!0),Q(this._physicsRig.outputs,i.getTotalOutputCount(),Xs,!0),Q(this._physicsRig.particles,i.getVertexCount(),Us,!0),this._currentRigOutputs.length=0,this._previousRigOutputs.length=0;let s=0,n=0,a=0,l=this._currentRigOutputs.length,o=this._previousRigOutputs.length;this._currentRigOutputs.length+=this._physicsRig.settings.length,this._previousRigOutputs.length+=this._physicsRig.settings.length;for(let u=0;u<this._physicsRig.settings.length;++u){this._physicsRig.settings[u].normalizationPosition.minimum=i.getNormalizationPositionMinimumValue(u),this._physicsRig.settings[u].normalizationPosition.maximum=i.getNormalizationPositionMaximumValue(u),this._physicsRig.settings[u].normalizationPosition.defalut=i.getNormalizationPositionDefaultValue(u),this._physicsRig.settings[u].normalizationAngle.minimum=i.getNormalizationAngleMinimumValue(u),this._physicsRig.settings[u].normalizationAngle.maximum=i.getNormalizationAngleMaximumValue(u),this._physicsRig.settings[u].normalizationAngle.defalut=i.getNormalizationAngleDefaultValue(u),this._physicsRig.settings[u].inputCount=i.getInputCount(u),this._physicsRig.settings[u].baseInputIndex=s;for(let h=0;h<this._physicsRig.settings[u].inputCount;++h)this._physicsRig.inputs[s+h].sourceParameterIndex=-1,this._physicsRig.inputs[s+h].weight=i.getInputWeight(u,h),this._physicsRig.inputs[s+h].reflect=i.getInputReflect(u,h),i.getInputType(u,h)==Gi?(this._physicsRig.inputs[s+h].type=0,this._physicsRig.inputs[s+h].getNormalizedParameterValue=oo):i.getInputType(u,h)==Xi?(this._physicsRig.inputs[s+h].type=1,this._physicsRig.inputs[s+h].getNormalizedParameterValue=lo):i.getInputType(u,h)==Hi&&(this._physicsRig.inputs[s+h].type=2,this._physicsRig.inputs[s+h].getNormalizedParameterValue=uo),this._physicsRig.inputs[s+h].source.targetType=0,this._physicsRig.inputs[s+h].source.id=i.getInputSourceId(u,h);s+=this._physicsRig.settings[u].inputCount,this._physicsRig.settings[u].outputCount=i.getOutputCount(u),this._physicsRig.settings[u].baseOutputIndex=n;let c=new Yi;Q(c.outputs,this._physicsRig.settings[u].outputCount,null,!0);let d=new Yi;Q(d.outputs,this._physicsRig.settings[u].outputCount,null,!0);for(let h=0;h<this._physicsRig.settings[u].outputCount;++h)c.outputs[h]=0,d.outputs[h]=0,this._physicsRig.outputs[n+h].destinationParameterIndex=-1,this._physicsRig.outputs[n+h].vertexIndex=i.getOutputVertexIndex(u,h),this._physicsRig.outputs[n+h].angleScale=i.getOutputAngleScale(u,h),this._physicsRig.outputs[n+h].weight=i.getOutputWeight(u,h),this._physicsRig.outputs[n+h].destination.targetType=0,this._physicsRig.outputs[n+h].destination.id=i.getOutputDestinationId(u,h),i.getOutputType(u,h)==Gi?(this._physicsRig.outputs[n+h].type=0,this._physicsRig.outputs[n+h].getValue=ho,this._physicsRig.outputs[n+h].getScale=po):i.getOutputType(u,h)==Xi?(this._physicsRig.outputs[n+h].type=1,this._physicsRig.outputs[n+h].getValue=co,this._physicsRig.outputs[n+h].getScale=mo):i.getOutputType(u,h)==Hi&&(this._physicsRig.outputs[n+h].type=2,this._physicsRig.outputs[n+h].getValue=go,this._physicsRig.outputs[n+h].getScale=_o),this._physicsRig.outputs[n+h].reflect=i.getOutputReflect(u,h);this._currentRigOutputs[l++]=c,this._previousRigOutputs[o++]=d,n+=this._physicsRig.settings[u].outputCount,this._physicsRig.settings[u].particleCount=i.getParticleCount(u),this._physicsRig.settings[u].baseParticleIndex=a;for(let h=0;h<this._physicsRig.settings[u].particleCount;++h)this._physicsRig.particles[a+h].mobility=i.getParticleMobility(u,h),this._physicsRig.particles[a+h].delay=i.getParticleDelay(u,h),this._physicsRig.particles[a+h].acceleration=i.getParticleAcceleration(u,h),this._physicsRig.particles[a+h].radius=i.getParticleRadius(u,h),this._physicsRig.particles[a+h].position=i.getParticlePosition(u,h);a+=this._physicsRig.settings[u].particleCount}this._inputSlices.length=this._physicsRig.subRigCount,this._outputSlices.length=this._physicsRig.subRigCount,this._particleSlices.length=this._physicsRig.subRigCount;for(let u=0;u<this._physicsRig.subRigCount;++u){let c=this._physicsRig.settings[u];this._inputSlices[u]=this._physicsRig.inputs.slice(c.baseInputIndex,c.baseInputIndex+c.inputCount),this._outputSlices[u]=this._physicsRig.outputs.slice(c.baseOutputIndex,c.baseOutputIndex+c.outputCount),this._particleSlices[u]=this._physicsRig.particles.slice(c.baseParticleIndex,c.baseParticleIndex+c.particleCount)}this.initialize(),i.release(),i=void 0,i=null}stabilization(t){let r,i,s,n,a=new w,l,o,u,c,d=t.getModel().parameters.values,h=t.getModel().parameters.maximumValues,g=t.getModel().parameters.minimumValues,A=t.getModel().parameters.defaultValues;(this._parameterCaches?.length??0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(this._parameterInputCaches?.length??0)<t.getParameterCount()&&(this._parameterInputCaches=new Float32Array(t.getParameterCount()));for(let p=0;p<t.getParameterCount();++p)this._parameterCaches[p]=d[p],this._parameterInputCaches[p]=d[p];for(let p=0;p<this._physicsRig.subRigCount;++p){r={angle:0},a.x=0,a.y=0,l=this._physicsRig.settings[p],o=this._inputSlices[p],u=this._outputSlices[p],c=this._particleSlices[p];for(let f=0;f<l.inputCount;++f)i=o[f].weight/qt,o[f].sourceParameterIndex==-1&&(o[f].sourceParameterIndex=t.getParameterIndex(o[f].source.id)),o[f].getNormalizedParameterValue(a,r,d[o[f].sourceParameterIndex],g[o[f].sourceParameterIndex],h[o[f].sourceParameterIndex],A[o[f].sourceParameterIndex],l.normalizationPosition,l.normalizationAngle,o[f].reflect,i),this._parameterCaches[o[f].sourceParameterIndex]=d[o[f].sourceParameterIndex];s=M.degreesToRadian(-r.angle),a.x=a.x*M.cos(s)-a.y*M.sin(s),a.y=a.x*M.sin(s)+a.y*M.cos(s),yo(c,l.particleCount,a,r.angle,this._options.wind,Wi*l.normalizationPosition.maximum);for(let f=0;f<l.outputCount;++f){let _=u[f].vertexIndex;if(u[f].destinationParameterIndex==-1&&(u[f].destinationParameterIndex=t.getParameterIndex(u[f].destination.id)),_<1||_>=l.particleCount)continue;let y=new w;y=c[_].position.substract(c[_-1].position),n=u[f].getValue(y,c,_,u[f].reflect,this._options.gravity),this._currentRigOutputs[p].outputs[f]=n,this._previousRigOutputs[p].outputs[f]=n;let C=u[f].destinationParameterIndex;Ut(d,C,g[C],h[C],n,u[f]),this._parameterCaches[C]=d[C]}}}evaluate(t,r){let i,s,n,a,l=new w,o,u,c,d;if(0>=r)return;let h=t.getModel().parameters.values,g=t.getModel().parameters.maximumValues,A=t.getModel().parameters.minimumValues,p=t.getModel().parameters.defaultValues,f;if(this._currentRemainTime+=r,this._currentRemainTime>no&&(this._currentRemainTime=0),(this._parameterCaches?.length??0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(this._parameterInputCaches?.length??0)<t.getParameterCount()){this._parameterInputCaches=new Float32Array(t.getParameterCount());for(let y=0;y<t.getParameterCount();++y)this._parameterInputCaches[y]=h[y]}for(this._physicsRig.fps>0?f=1/this._physicsRig.fps:f=r;this._currentRemainTime>=f;){for(let C=0;C<this._physicsRig.subRigCount;++C){o=this._physicsRig.settings[C],c=this._outputSlices[C];for(let b=0;b<o.outputCount;++b)this._previousRigOutputs[C].outputs[b]=this._currentRigOutputs[C].outputs[b]}let y=f/this._currentRemainTime;for(let C=0;C<t.getParameterCount();++C)this._parameterCaches[C]=this._parameterInputCaches[C]*(1-y)+h[C]*y,this._parameterInputCaches[C]=this._parameterCaches[C];for(let C=0;C<this._physicsRig.subRigCount;++C){i={angle:0},l.x=0,l.y=0,o=this._physicsRig.settings[C],u=this._inputSlices[C],c=this._outputSlices[C],d=this._particleSlices[C];for(let b=0;b<o.inputCount;++b)s=u[b].weight/qt,u[b].sourceParameterIndex==-1&&(u[b].sourceParameterIndex=t.getParameterIndex(u[b].source.id)),u[b].getNormalizedParameterValue(l,i,this._parameterCaches[u[b].sourceParameterIndex],A[u[b].sourceParameterIndex],g[u[b].sourceParameterIndex],p[u[b].sourceParameterIndex],o.normalizationPosition,o.normalizationAngle,u[b].reflect,s);n=M.degreesToRadian(-i.angle),l.x=l.x*M.cos(n)-l.y*M.sin(n),l.y=l.x*M.sin(n)+l.y*M.cos(n),Co(d,o.particleCount,l,i.angle,this._options.wind,Wi*o.normalizationPosition.maximum,f,so);for(let b=0;b<o.outputCount;++b){let x=c[b].vertexIndex;if(c[b].destinationParameterIndex==-1&&(c[b].destinationParameterIndex=t.getParameterIndex(c[b].destination.id)),x<1||x>=o.particleCount)continue;let B=new w;B.x=d[x].position.x-d[x-1].position.x,B.y=d[x].position.y-d[x-1].position.y,a=c[b].getValue(B,d,x,c[b].reflect,this._options.gravity),this._currentRigOutputs[C].outputs[b]=a;let E=c[b].destinationParameterIndex;Ut(this._parameterCaches,E,A[E],g[E],a,c[b])}}this._currentRemainTime-=f}let _=this._currentRemainTime/f;this.interpolate(t,_)}interpolate(t,r){let i,s,n=t.getModel().parameters.values,a=t.getModel().parameters.maximumValues,l=t.getModel().parameters.minimumValues;for(let o=0;o<this._physicsRig.subRigCount;++o){s=this._physicsRig.settings[o],i=this._outputSlices[o];for(let u=0;u<s.outputCount;++u){if(i[u].destinationParameterIndex==-1)continue;let c=i[u].destinationParameterIndex;Ut(n,c,l[c],a[c],this._previousRigOutputs[o].outputs[u]*(1-r)+this._currentRigOutputs[o].outputs[u]*r,i[u])}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._physicsRig=null,this._options=new zs,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=new Array,this._previousRigOutputs=new Array,this._inputSlices=new Array,this._outputSlices=new Array,this._particleSlices=new Array,this._currentRemainTime=0,this._parameterCaches=null,this._parameterInputCaches=null}release(){this._inputSlices.length=0,this._outputSlices.length=0,this._particleSlices.length=0,this._physicsRig=void 0,this._physicsRig=null}initialize(){let t,r,i;for(let s=0;s<this._physicsRig.subRigCount;++s){r=this._physicsRig.settings[s],t=this._particleSlices[s],t[0].initialPosition=new w(0,0),t[0].lastPosition=new w(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new w(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new w(0,0),t[0].force=new w(0,0);for(let n=1;n<r.particleCount;++n)i=new w(0,0),i.y=t[n].radius,t[n].initialPosition=new w(t[n-1].initialPosition.x+i.x,t[n-1].initialPosition.y+i.y),t[n].position=new w(t[n].initialPosition.x,t[n].initialPosition.y),t[n].lastPosition=new w(t[n].initialPosition.x,t[n].initialPosition.y),t[n].lastGravity=new w(0,-1),t[n].lastGravity.y*=-1,t[n].velocity=new w(0,0),t[n].force=new w(0,0)}}_physicsRig;_options;_currentRigOutputs;_previousRigOutputs;_inputSlices;_outputSlices;_particleSlices;_currentRemainTime;_parameterCaches;_parameterInputCaches},zs=class{constructor(){this.gravity=new w(0,0),this.wind=new w(0,0)}gravity;wind},Yi=class{constructor(){this.outputs=new Array(0)}outputs};(function(e){e.CubismPhysics=Kt,e.Options=zs})(zi||(zi={}));Nt=4,bo=36,Bo=32,Io=class{constructor(e){this._renderTextureCount=0,this._clippingMaskBufferSize=256,this._clippingContextListForMask=new Array,this._clippingContextListForDraw=new Array,this._clippingContextListForOffscreen=new Array,this._tmpBoundsOnModel=new dt,this._tmpMatrix=new ne,this._tmpMatrixForMask=new ne,this._tmpMatrixForDraw=new ne,this._clearedMaskBufferFlags=new Array,this._clippingContexttConstructor=e,this._channelColors=[new R(1,0,0,0),new R(0,1,0,0),new R(0,0,1,0),new R(0,0,0,1)]}release(){for(let e=0;e<this._clippingContextListForMask.length;e++)this._clippingContextListForMask[e]&&(this._clippingContextListForMask[e].release(),this._clippingContextListForMask[e]=void 0),this._clippingContextListForMask[e]=null;this._clippingContextListForMask=null;for(let e=0;e<this._clippingContextListForDraw.length;e++)this._clippingContextListForDraw[e]=null;this._clippingContextListForDraw=null;for(let e=0;e<this._channelColors.length;e++)this._channelColors[e]=null;this._channelColors=null,this._clearedMaskBufferFlags!=null&&(this._clearedMaskBufferFlags.length=0),this._clearedMaskBufferFlags=null}initializeForDrawable(e,t){t%1!=0&&(V("The number of render textures must be specified as an integer. The decimal point is rounded down and corrected to an integer."),t=~~t),t<1&&V("The number of render textures must be an integer greater than or equal to 1. Set the number of render textures to 1."),this._renderTextureCount=t<1?1:t,this._clearedMaskBufferFlags=new Array(this._renderTextureCount),this._clippingContextListForDraw.length=e.getDrawableCount();for(let r=0;r<e.getDrawableCount();r++){if(e.getDrawableMaskCounts()[r]<=0){this._clippingContextListForDraw[r]=null;continue}let i=this.findSameClip(e.getDrawableMasks()[r],e.getDrawableMaskCounts()[r]);i==null&&(i=new this._clippingContexttConstructor(this,e.getDrawableMasks()[r],e.getDrawableMaskCounts()[r]),this._clippingContextListForMask.push(i)),i.addClippedDrawable(r),this._clippingContextListForDraw[r]=i}}initializeForOffscreen(e,t){this._renderTextureCount=t,this._clearedMaskBufferFlags.length=this._renderTextureCount;for(let r=0;r<this._renderTextureCount;++r)this._clearedMaskBufferFlags[r]=!1;this._clippingContextListForOffscreen.length=e.getOffscreenCount();for(let r=0;r<e.getOffscreenCount();++r){if(e.getOffscreenMaskCounts()[r]<=0){this._clippingContextListForOffscreen.push(null);continue}let i=this.findSameClip(e.getOffscreenMasks()[r],e.getOffscreenMaskCounts()[r]);i==null&&(i=new this._clippingContexttConstructor(this,e.getOffscreenMasks()[r],e.getOffscreenMaskCounts()[r]),this._clippingContextListForMask.push(i)),i.addClippedOffscreen(r),this._clippingContextListForOffscreen[r]=i}}findSameClip(e,t){for(let r=0;r<this._clippingContextListForMask.length;r++){let i=this._clippingContextListForMask[r],s=i._clippingIdCount;if(s!=t)continue;let n=0;for(let a=0;a<s;a++){let l=i._clippingIdList[a];for(let o=0;o<s;o++)if(e[o]==l){n++;break}}if(n==s)return i}return null}setupMatrixForHighPrecision(e,t){let r=0;for(let i=0;i<this._clippingContextListForMask.length;i++){let s=this._clippingContextListForMask[i];this.calcClippedDrawableTotalBounds(e,s),s._isUsing&&r++}if(r>0){if(this.setupLayoutBounds(0),this._clearedMaskBufferFlags.length!=this._renderTextureCount){this._clearedMaskBufferFlags.length=this._renderTextureCount;for(let i=0;i<this._renderTextureCount;i++)this._clearedMaskBufferFlags[i]=!1}else for(let i=0;i<this._renderTextureCount;i++)this._clearedMaskBufferFlags[i]=!1;for(let i=0;i<this._clippingContextListForMask.length;i++){let s=this._clippingContextListForMask[i],n=s._allClippedDrawRect,a=s._layoutBounds,l=.05,o=0,u=0,c=e.getPixelsPerUnit(),d=s.getClippingManager().getClippingMaskBufferSize(),h=a.width*d,g=a.height*d;this._tmpBoundsOnModel.setRect(n),this._tmpBoundsOnModel.width*c>h?(this._tmpBoundsOnModel.expand(n.width*l,0),o=a.width/this._tmpBoundsOnModel.width):o=c/h,this._tmpBoundsOnModel.height*c>g?(this._tmpBoundsOnModel.expand(0,n.height*l),u=a.height/this._tmpBoundsOnModel.height):u=c/g,this.createMatrixForMask(t,a,o,u),s._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),s._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray())}}}setupMatrixForOffscreenHighPrecision(e,t,r){let i=0;for(let s=0;s<this._clippingContextListForMask.length;s++){let n=this._clippingContextListForMask[s];this.calcClippedOffscreenTotalBounds(e,n),n._isUsing&&i++}if(!(i<=0)){if(this.setupLayoutBounds(0),this._clearedMaskBufferFlags.length!=this._renderTextureCount){this._clearedMaskBufferFlags.length=this._renderTextureCount;for(let s=0;s<this._renderTextureCount;++s)this._clearedMaskBufferFlags[s]=!1}else for(let s=0;s<this._renderTextureCount;++s)this._clearedMaskBufferFlags[s]=!1;for(let s=0;s<this._clippingContextListForMask.length;s++){let n=this._clippingContextListForMask[s],a=n._allClippedDrawRect,l=n._layoutBounds,o=.05,u=0,c=0,d=e.getPixelsPerUnit(),h=n.getClippingManager().getClippingMaskBufferSize(),g=l.width*h,A=l.height*h;this._tmpBoundsOnModel.setRect(a),this._tmpBoundsOnModel.width*d>g?(this._tmpBoundsOnModel.expand(a.width*o,0),u=l.width/this._tmpBoundsOnModel.width):u=d/g,this._tmpBoundsOnModel.height*d>A?(this._tmpBoundsOnModel.expand(0,a.height*o),c=l.height/this._tmpBoundsOnModel.height):c=d/A,this.createMatrixForMask(t,l,u,c),n._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),n._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray());let p=r.getInvert();n._matrixForDraw.multiplyByMatrix(p)}}}calcClippedOffscreenTotalBounds(e,t){let r=Number.MAX_VALUE,i=Number.MAX_VALUE,s=-Number.MAX_VALUE,n=-Number.MAX_VALUE,a=t._clippedOffscreenIndexList.length,l=new Array;for(let u=0;u<a;u++){let c=t._clippedOffscreenIndexList[u];this.getOffscreenChildDrawableIndexList(e,c,l)}let o=l.length;for(let u=0;u<o;u++){let c=e.getDrawableVertexCount(l[u]),d=e.getDrawableVertices(l[u]),h=Number.MAX_VALUE,g=Number.MAX_VALUE,A=-Number.MAX_VALUE,p=-Number.MAX_VALUE,f=c*$.vertexStep;for(let _=$.vertexOffset;_<f;_+=$.vertexStep){let y=d[_],C=d[_+1];y<h&&(h=y),y>A&&(A=y),C<g&&(g=C),C>p&&(p=C)}h!=Number.MAX_VALUE&&(h<r&&(r=h),g<i&&(i=g),A>s&&(s=A),p>n&&(n=p))}if(r==Number.MAX_VALUE)t._allClippedDrawRect.x=0,t._allClippedDrawRect.y=0,t._allClippedDrawRect.width=0,t._allClippedDrawRect.height=0,t._isUsing=!1;else{t._isUsing=!0;let u=s-r,c=n-i;t._allClippedDrawRect.x=r,t._allClippedDrawRect.y=i,t._allClippedDrawRect.width=u,t._allClippedDrawRect.height=c}}getOffscreenChildDrawableIndexList(e,t,r){let i=e.getOffscreenOwnerIndices()[t];this.getPartChildDrawableIndexList(e,i,r)}getPartChildDrawableIndexList(e,t,r){let i=e.getPartsHierarchy()[t].childDrawObjects;r.push(...i.drawableIndices);for(let s=0;s<i.offscreenIndices.length;++s)this.getOffscreenChildDrawableIndexList(e,i.offscreenIndices[s],r)}createMatrixForMask(e,t,r,i){this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(t.x,t.y),this._tmpMatrix.scaleRelative(r,i),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForMask.setMatrix(this._tmpMatrix.getArray()),this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(t.x,t.y*(e?-1:1)),this._tmpMatrix.scaleRelative(r,i*(e?-1:1)),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForDraw.setMatrix(this._tmpMatrix.getArray())}setupLayoutBounds(e){let t=this._renderTextureCount<=1?bo:Bo*this._renderTextureCount;if(e<=0||e>t){e>t&&D(`not supported mask count : {0}
19
- [Details] render texture count : {1}, mask count : {2}`,e-t,this._renderTextureCount,e);for(let o=0;o<this._clippingContextListForMask.length;o++){let u=this._clippingContextListForMask[o];u._layoutChannelIndex=0,u._layoutBounds.x=0,u._layoutBounds.y=0,u._layoutBounds.width=1,u._layoutBounds.height=1,u._bufferIndex=0}return}let r=this._renderTextureCount<=1?9:8,i=e/this._renderTextureCount,s=e%this._renderTextureCount;i=Math.ceil(i);let n=i/Nt,a=i%Nt;n=~~n;let l=0;for(let o=0;o<this._renderTextureCount;o++)for(let u=0;u<Nt;u++){let c=n+(u<a?1:0),d=a+(n<1?-1:0);if(u==d&&s>0&&(c-=o<s?0:1),c!=0)if(c==1){let h=this._clippingContextListForMask[l++];h._layoutChannelIndex=u,h._layoutBounds.x=0,h._layoutBounds.y=0,h._layoutBounds.width=1,h._layoutBounds.height=1,h._bufferIndex=o}else if(c==2)for(let h=0;h<c;h++){let g=h%2;g=~~g;let A=this._clippingContextListForMask[l++];A._layoutChannelIndex=u,A._layoutBounds.x=g*.5,A._layoutBounds.y=0,A._layoutBounds.width=.5,A._layoutBounds.height=1,A._bufferIndex=o}else if(c<=4)for(let h=0;h<c;h++){let g=h%2,A=h/2;g=~~g,A=~~A;let p=this._clippingContextListForMask[l++];p._layoutChannelIndex=u,p._layoutBounds.x=g*.5,p._layoutBounds.y=A*.5,p._layoutBounds.width=.5,p._layoutBounds.height=.5,p._bufferIndex=o}else if(c<=r)for(let h=0;h<c;h++){let g=h%3,A=h/3;g=~~g,A=~~A;let p=this._clippingContextListForMask[l++];p._layoutChannelIndex=u,p._layoutBounds.x=g/3,p._layoutBounds.y=A/3,p._layoutBounds.width=1/3,p._layoutBounds.height=1/3,p._bufferIndex=o}else{D(`not supported mask count : {0}
20
- [Details] render texture count : {1}, mask count : {2}`,e-t,this._renderTextureCount,e);for(let h=0;h<c;h++){let g=this._clippingContextListForMask[l++];g._layoutChannelIndex=0,g._layoutBounds.x=0,g._layoutBounds.y=0,g._layoutBounds.width=1,g._layoutBounds.height=1,g._bufferIndex=0}}}}calcClippedDrawableTotalBounds(e,t){let r=Number.MAX_VALUE,i=Number.MAX_VALUE,s=Number.MIN_VALUE,n=Number.MIN_VALUE,a=t._clippedDrawableIndexList.length;for(let l=0;l<a;l++){let o=t._clippedDrawableIndexList[l],u=e.getDrawableVertexCount(o),c=e.getDrawableVertices(o),d=Number.MAX_VALUE,h=Number.MAX_VALUE,g=-Number.MAX_VALUE,A=-Number.MAX_VALUE,p=u*$.vertexStep;for(let f=$.vertexOffset;f<p;f+=$.vertexStep){let _=c[f],y=c[f+1];_<d&&(d=_),_>g&&(g=_),y<h&&(h=y),y>A&&(A=y)}if(d!=Number.MAX_VALUE)if(d<r&&(r=d),h<i&&(i=h),g>s&&(s=g),A>n&&(n=A),r==Number.MAX_VALUE)t._allClippedDrawRect.x=0,t._allClippedDrawRect.y=0,t._allClippedDrawRect.width=0,t._allClippedDrawRect.height=0,t._isUsing=!1;else{t._isUsing=!0;let f=s-r,_=n-i;t._allClippedDrawRect.x=r,t._allClippedDrawRect.y=i,t._allClippedDrawRect.width=f,t._allClippedDrawRect.height=_}}}getClippingContextListForDraw(){return this._clippingContextListForDraw}getClippingContextListForOffscreen(){return this._clippingContextListForOffscreen}getClippingMaskBufferSize(){return this._clippingMaskBufferSize}getRenderTextureCount(){return this._renderTextureCount}getChannelFlagAsColor(e){return this._channelColors[e]}setClippingMaskBufferSize(e){this._clippingMaskBufferSize=e}_clearedMaskBufferFlags;_channelColors;_clippingContextListForMask;_clippingContextListForDraw;_clippingContextListForOffscreen;_clippingMaskBufferSize;_renderTextureCount;_tmpMatrix;_tmpMatrixForMask;_tmpMatrixForDraw;_tmpBoundsOnModel;_clippingContexttConstructor},Ae=class{static copyBuffer(e,t,r,i=null,s=!1){if(t==null||r==null)return;if(!(e instanceof WebGL2RenderingContext))throw new Error("WebGL2RenderingContext is required for buffer copy.");let n=s?i:e.getParameter(e.FRAMEBUFFER_BINDING);e.bindFramebuffer(e.READ_FRAMEBUFFER,t.getRenderTexture()),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,r.getRenderTexture()),e.blitFramebuffer(0,0,t.getBufferWidth(),t.getBufferHeight(),0,0,r.getBufferWidth(),r.getBufferHeight(),e.COLOR_BUFFER_BIT,e.NEAREST),e.bindFramebuffer(e.FRAMEBUFFER,n)}beginDraw(e=null,t=!1){if(this._renderTexture==null){console.error("_renderTexture is null");return}e==null&&!t?this._oldFbo=this._gl.getParameter(this._gl.FRAMEBUFFER_BINDING):this._oldFbo=e,this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,this._renderTexture)}endDraw(){this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,this._oldFbo)}clear(e,t,r,i){this._gl.clearColor(e,t,r,i),this._gl.clear(this._gl.COLOR_BUFFER_BIT)}createRenderTarget(e,t,r,i){this.destroyRenderTarget(),this._colorBuffer=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this._colorBuffer),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.bindTexture(e.TEXTURE_2D,null);let s=e.createFramebuffer();return s==null?(D("Failed to create framebuffer"),!1):(e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this._colorBuffer,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE?(D("Framebuffer is not complete"),e.bindFramebuffer(e.FRAMEBUFFER,i),e.deleteFramebuffer(s),this.destroyRenderTarget(),!1):(this._renderTexture=s,this._bufferWidth=t,this._bufferHeight=r,this._gl=e,!0))}destroyRenderTarget(){this._colorBuffer&&(this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.deleteTexture(this._colorBuffer),this._colorBuffer=null),this._renderTexture&&(this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null),this._gl.deleteFramebuffer(this._renderTexture),this._renderTexture=null)}getGL(){return this._gl}getRenderTexture(){return this._renderTexture}getColorBuffer(){return this._colorBuffer}getBufferWidth(){return this._bufferWidth}getBufferHeight(){return this._bufferHeight}isValid(){return this._renderTexture!=null}getOldFBO(){return this._oldFbo}constructor(){this._gl=null,this._colorBuffer=null,this._renderTexture=null,this._bufferWidth=0,this._bufferHeight=0,this._oldFbo=null}_gl;_colorBuffer;_renderTexture;_bufferWidth;_bufferHeight;_oldFbo};(function(e){e.CubismOffscreenSurface_WebGL=Ae})(Ji||(Ji={}));So=class{constructor(e=null,t=null,r=!1){this.colorBuffer=e,this.renderTexture=t,this.inUse=r}clear(){this.colorBuffer=null,this.renderTexture=null,this.inUse=!1}getColorBuffer(){return this.colorBuffer}getRenderTexture(){return this.renderTexture}colorBuffer;renderTexture;inUse},Mo=class{constructor(e){this.gl=e,this.offscreenRenderTargetContainers=new Array,this.previousActiveRenderTextureMaxCount=0,this.currentActiveRenderTextureCount=0,this.hasResetThisFrame=!1,this.width=0,this.height=0}release(){if(this.offscreenRenderTargetContainers!=null){for(let e=0;e<this.offscreenRenderTargetContainers.length;++e){let t=this.offscreenRenderTargetContainers[e];this.gl.deleteTexture(t.colorBuffer),this.gl.deleteFramebuffer(t.renderTexture)}this.offscreenRenderTargetContainers.length=0,this.offscreenRenderTargetContainers=null}}gl;offscreenRenderTargetContainers;previousActiveRenderTextureMaxCount;currentActiveRenderTextureCount;hasResetThisFrame;width;height},hr=class $t{constructor(){this._contextManagers=new Map}release(){if(this._contextManagers!=null){for(let t of this._contextManagers.values())t.release();this._contextManagers.clear(),this._contextManagers=null}$t._instance=null}static getInstance(){return this._instance==null&&(this._instance=new $t),this._instance}getContextManager(t){return this._contextManagers.has(t)||this._contextManagers.set(t,new Mo(t)),this._contextManagers.get(t)}removeContext(t){this._contextManagers.has(t)&&(this._contextManagers.get(t).release(),this._contextManagers.delete(t))}initialize(t,r,i){let s=this.getContextManager(t);if(s.offscreenRenderTargetContainers!=null){for(let n=0;n<s.offscreenRenderTargetContainers.length;++n){let a=s.offscreenRenderTargetContainers[n];s.gl.deleteTexture(a.colorBuffer),s.gl.deleteFramebuffer(a.renderTexture),a.clear()}s.offscreenRenderTargetContainers.length=0}else s.offscreenRenderTargetContainers=new Array;s.width=r,s.height=i,s.previousActiveRenderTextureMaxCount=0,s.currentActiveRenderTextureCount=0,s.hasResetThisFrame=!1}beginFrameProcess(t){let r=this.getContextManager(t);r.hasResetThisFrame||(r.previousActiveRenderTextureMaxCount=0,r.hasResetThisFrame=!0)}endFrameProcess(t){let r=this.getContextManager(t);r.hasResetThisFrame=!1}getContainerSize(t){let r=this.getContextManager(t);return r.offscreenRenderTargetContainers==null?0:r.offscreenRenderTargetContainers.length}getOffscreenRenderTargetContainers(t,r,i,s){let n=this.getContextManager(t);(n.width!=r||n.height!=i||n.offscreenRenderTargetContainers==null)&&this.initialize(t,r,i),this.updateRenderTargetContainerCount(t);let a=this.getUnusedOffscreenRenderTargetContainer(t);return a??this.createOffscreenRenderTargetContainer(t,r,i,s)}getUsingRenderTextureState(t,r){let i=this.getContextManager(t);for(let s=0;s<i.offscreenRenderTargetContainers.length;++s)if(i.offscreenRenderTargetContainers[s].renderTexture==r)return i.offscreenRenderTargetContainers[s].inUse;return!0}startUsingRenderTexture(t,r){let i=this.getContextManager(t);for(let s=0;s<i.offscreenRenderTargetContainers.length;++s)if(i.offscreenRenderTargetContainers[s].renderTexture==r){i.offscreenRenderTargetContainers[s].inUse=!0,this.updateRenderTargetContainerCount(t);break}}stopUsingRenderTexture(t,r){let i=this.getContextManager(t);for(let s=0;s<i.offscreenRenderTargetContainers.length;++s)if(i.offscreenRenderTargetContainers[s].renderTexture==r){i.offscreenRenderTargetContainers[s].inUse=!1,i.currentActiveRenderTextureCount--,i.currentActiveRenderTextureCount<0&&(i.currentActiveRenderTextureCount=0);break}}stopUsingAllRenderTextures(t){let r=this.getContextManager(t);for(let i=0;i<r.offscreenRenderTargetContainers.length;++i)r.offscreenRenderTargetContainers[i].inUse=!1;r.currentActiveRenderTextureCount=0}releaseStaleRenderTextures(t){let r=this.getContextManager(t),i=r.offscreenRenderTargetContainers.length;if(r.hasResetThisFrame||i===0)return;let s=0,n=r.previousActiveRenderTextureMaxCount;for(let a=i;r.previousActiveRenderTextureMaxCount<a;--a){let l=a-1;if(r.offscreenRenderTargetContainers[l].inUse){let u=!1;for(;s<r.previousActiveRenderTextureMaxCount;++s)if(!r.offscreenRenderTargetContainers[s].inUse){let c=r.offscreenRenderTargetContainers[s];r.offscreenRenderTargetContainers[s]=r.offscreenRenderTargetContainers[l],r.offscreenRenderTargetContainers[s].inUse=!0,r.offscreenRenderTargetContainers[l]=c,r.offscreenRenderTargetContainers[l].inUse=!1,u=!0;break}if(!u){n=a;break}}let o=r.offscreenRenderTargetContainers[l];r.gl.bindTexture(r.gl.TEXTURE_2D,null),r.gl.deleteTexture(o.colorBuffer),r.gl.bindFramebuffer(r.gl.FRAMEBUFFER,null),r.gl.deleteFramebuffer(o.renderTexture),o.clear()}Q(r.offscreenRenderTargetContainers,n)}getPreviousActiveRenderTextureCount(t){return this.getContextManager(t).previousActiveRenderTextureMaxCount}getCurrentActiveRenderTextureCount(t){return this.getContextManager(t).currentActiveRenderTextureCount}updateRenderTargetContainerCount(t){let r=this.getContextManager(t);++r.currentActiveRenderTextureCount,r.previousActiveRenderTextureMaxCount=r.currentActiveRenderTextureCount>r.previousActiveRenderTextureMaxCount?r.currentActiveRenderTextureCount:r.previousActiveRenderTextureMaxCount}getUnusedOffscreenRenderTargetContainer(t){let r=this.getContextManager(t);for(let i=0;i<r.offscreenRenderTargetContainers.length;++i){let s=r.offscreenRenderTargetContainers[i];if(s.inUse==!1)return s.inUse=!0,s}return null}createOffscreenRenderTargetContainer(t,r,i,s){let n=new Ae;if(!n.createRenderTarget(t,r,i,s))return D("Failed to create offscreen render texture."),null;let a=new So(n.getColorBuffer(),n.getRenderTexture(),!0);return this.getContextManager(t).offscreenRenderTargetContainers.push(a),a}static _instance;_contextManagers},ji=class extends Ae{initializeOffscreenManager(e,t,r){this._gl=e,this._webGLOffscreenManager=hr.getInstance(),this._webGLOffscreenManager.getContainerSize(e)===0&&this._webGLOffscreenManager.initialize(e,t,r)}setOffscreenRenderTarget(e,t,r,i){this._webGLOffscreenManager==null&&this.initializeOffscreenManager(e,t,r);let s=this._webGLOffscreenManager.getOffscreenRenderTargetContainers(e,t,r,i);if(s==null){D("Failed to acquire offscreen render texture container.");return}this._colorBuffer=s.getColorBuffer(),this._renderTexture=s.getRenderTexture(),this._bufferWidth=t,this._bufferHeight=r,this._gl=e,this._renderTexture==null&&(this._renderTexture=i,D("Failed to create offscreen render texture."))}getUsingRenderTextureState(){return this._webGLOffscreenManager==null||this._gl==null?!0:this._webGLOffscreenManager.getUsingRenderTextureState(this._gl,this._renderTexture)}startUsingRenderTexture(){this._webGLOffscreenManager==null||this._gl==null||this._webGLOffscreenManager.startUsingRenderTexture(this._gl,this._renderTexture)}stopUsingRenderTexture(){this._webGLOffscreenManager==null||this._gl==null||this._webGLOffscreenManager.stopUsingRenderTexture(this._gl,this._renderTexture)}setOffscreenIndex(e){this._offscreenIndex=e}getOffscreenIndex(){return this._offscreenIndex}setOldOffscreen(e){this._oldOffscreen=e}getOldOffscreen(){return this._oldOffscreen}setParentPartOffscreen(e){this._parentOffscreenRenderTarget=e}getParentPartOffscreen(){return this._parentOffscreenRenderTarget}constructor(){super(),this._offscreenIndex=-1,this._parentOffscreenRenderTarget=null,this._oldOffscreen=null,this._webGLOffscreenManager=null}release(){this._webGLOffscreenManager!=null&&this._gl!=null&&this._renderTexture!=null&&this._webGLOffscreenManager.stopUsingRenderTexture(this._gl,this._renderTexture),this._colorBuffer&&this._gl&&(this._gl.deleteTexture(this._colorBuffer),this._colorBuffer=null),this._renderTexture&&this._gl&&(this._gl.deleteFramebuffer(this._renderTexture),this._renderTexture=null),this._webGLOffscreenManager!=null&&(this._webGLOffscreenManager=null),this._oldOffscreen=null,this._parentOffscreenRenderTarget=null}_offscreenIndex;_parentOffscreenRenderTarget;_oldOffscreen;_webGLOffscreenManager},xo="vertshadersrc.vert",wo="vertshadersrcmasked.vert",Eo="vertshadersrcsetupmask.vert",vo="fragshadersrcsetupmask.frag",Po="fragshadersrcpremultipliedalpha.frag",Ro="fragshadersrcmaskpremultipliedalpha.frag",Do="fragshadersrcmaskinvertedpremultipliedalpha.frag",Lo="vertshadersrccopy.vert",To="fragshadersrccopy.frag",Fo="fragshadersrccolorblend.frag",Vo="fragshadersrcalphablend.frag",Oo="vertshadersrcblend.vert",ko="fragshadersrcpremultipliedalphablend.frag",Qo="ColorBlend_",Uo="AlphaBlend_",Zi=new Float32Array([-1,-1,1,-1,-1,1,1,1]),No=new Float32Array([0,0,1,0,0,1,1,1]),Go=new Float32Array([0,1,1,1,0,0,1,0]),Js=class{async loadShader(e,t){let r=e.slice(e.lastIndexOf("/")+1),i=this._shaderSources?.[r];if(i!==void 0){if(i.trim().length==0)throw new Error(`Failed to load shader ${e}: empty source`);return i}let s=await fetch(e,{signal:t});if(!s.ok)throw new Error(`Failed to load shader ${e}: HTTP ${s.status}`);let n=await s.text();if(n.trim().length==0)throw new Error(`Failed to load shader ${e}: empty source`);return n}async loadShaders(e){let t=this._shaderPath??this._defaultShaderPath,r=[{path:t+xo,prop:"_vertShaderSrc"},{path:t+wo,prop:"_vertShaderSrcMasked"},{path:t+Eo,prop:"_vertShaderSrcSetupMask"},{path:t+vo,prop:"_fragShaderSrcSetupMask"},{path:t+Po,prop:"_fragShaderSrcPremultipliedAlpha"},{path:t+Ro,prop:"_fragShaderSrcMaskPremultipliedAlpha"},{path:t+Do,prop:"_fragShaderSrcMaskInvertedPremultipliedAlpha"},{path:t+Lo,prop:"_vertShaderSrcCopy"},{path:t+To,prop:"_fragShaderSrcCopy"},{path:t+Fo,prop:"_fragShaderSrcColorBlend"},{path:t+Vo,prop:"_fragShaderSrcAlphaBlend"},{path:t+Oo,prop:"_vertShaderSrcBlend"},{path:t+ko,prop:"_fragShaderSrcBlend"}];(await Promise.all(r.map(async i=>({prop:i.prop,data:await this.loadShader(i.path,e)})))).forEach(i=>{this[i.prop]=i.data})}constructor(){this._shaderSets=new Array,this._isShaderLoading=!1,this._isShaderLoaded=!1,this._blendShadersRegistered=!1,this._currentProgram=null,this._shaderLoadPromise=null,this._colorBlendMap=new Map,this._colorBlendValues=new Array;let e=Object.keys(O),t=Object.keys(O).map(s=>O[s]);for(let s=0;s<e.length;s++){let n=e[s];if(n.includes(Qo)){let a=n.slice(11),l=parseInt(t[s].toString());this._colorBlendMap.set(l,a),this._colorBlendValues.push(l)}}this._alphaBlendMap=new Map,this._alphaBlendValues=new Array;let r=Object.keys(Lt),i=Object.keys(Lt).map(s=>Lt[s]);for(let s=0;s<r.length;s++){let n=r[s];if(n.includes(Uo)){let a=n.slice(11),l=parseInt(i[s].toString());this._alphaBlendMap.set(l,a),this._alphaBlendValues.push(l)}}this._blendShaderSetMap=new Map,this._shaderCount=11+(this._colorBlendValues.length-3)*(this._alphaBlendValues.length-1)*3,this._defaultShaderPath="../../Framework/Shaders/WebGL/",this._shaderPath=this._defaultShaderPath}release(){this.releaseShaderProgram()}setProgram(e){this._currentProgram!==e&&(this._currentProgram=e,this.gl.useProgram(e))}setupShaderProgramForDrawable(e,t,r){if(e.isPremultipliedAlpha()||D("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders(void 0,t.isBlendModeEnabled()),this._isShaderLoaded==!1){V("Shader program is not initialized.");return}let i,s,n,a,l=e.getClippingContextBufferForDrawable()!=null,o=t.getDrawableInvertedMaskBit(r),u=l?o?2:1:0,c,d=!0;if(t.isBlendModeEnabled()){let b=t.getDrawableColorBlend(r),x=t.getDrawableAlphaBlend(r);if(b==-1||x==-1||b==O.ColorBlend_Normal&&x==0)c=this._shaderSets[1+u],i=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ONE,a=this.gl.ONE_MINUS_SRC_ALPHA;else switch(b){case O.ColorBlend_AddCompatible:c=this._shaderSets[4+u],i=this.gl.ONE,s=this.gl.ONE,n=this.gl.ZERO,a=this.gl.ONE;break;case O.ColorBlend_MultiplyCompatible:c=this._shaderSets[7+u],i=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ZERO,a=this.gl.ONE;break;default:{let B=e._currentOffscreen!=null?e._currentOffscreen:e.getModelRenderTarget(0);Ae.copyBuffer(this.gl,B,e.getModelRenderTarget(1));let E=this._blendShaderSetMap.get(this._colorBlendMap.get(b)+this._alphaBlendMap.get(x));if(E===void 0)throw new Error("Blend shader programs are not registered for this context.");c=this._shaderSets[E+u],i=this.gl.ONE,s=this.gl.ZERO,n=this.gl.ONE,a=this.gl.ZERO,d=!1}break}}else switch(t.getDrawableBlendMode(r)){case 0:default:c=this._shaderSets[1+u],i=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ONE,a=this.gl.ONE_MINUS_SRC_ALPHA;break;case 1:c=this._shaderSets[4+u],i=this.gl.ONE,s=this.gl.ONE,n=this.gl.ZERO,a=this.gl.ONE;break;case 2:c=this._shaderSets[7+u],i=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ZERO,a=this.gl.ONE;break}this.setProgram(c.shaderProgram),e._bufferData.vertex==null&&(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex);let h=t.getDrawableVertices(r);if(this.gl.bufferData(this.gl.ARRAY_BUFFER,h,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(c.attributePositionLocation),this.gl.vertexAttribPointer(c.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),e.bindDrawableUvBuffer(r),this.gl.enableVertexAttribArray(c.attributeTexCoordLocation),this.gl.vertexAttribPointer(c.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),l){this.gl.activeTexture(this.gl.TEXTURE1);let b=e.getDrawableMaskBuffer(e.getClippingContextBufferForDrawable()._bufferIndex).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,b),this.gl.uniform1i(c.samplerTexture1Location,1),this.gl.uniformMatrix4fv(c.uniformClipMatrixLocation,!1,e.getClippingContextBufferForDrawable()._matrixForDraw.getArray());let x=e.getClippingContextBufferForDrawable()._layoutChannelIndex,B=e.getClippingContextBufferForDrawable().getClippingManager().getChannelFlagAsColor(x);this.gl.uniform4f(c.uniformChannelFlagLocation,B.r,B.g,B.b,B.a),t.isBlendModeEnabled()&&this.gl.uniform1f(c.uniformInvertMaskFlagLocation,o?1:0)}let g=t.getDrawableTextureIndex(r),A=e.getBindedTextures().get(g);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,A),this.gl.uniform1i(c.samplerTexture0Location,0);let p=e.getMvpMatrix();this.gl.uniformMatrix4fv(c.uniformMatrixLocation,!1,p.getArray());let f=null;if(t.isBlendModeEnabled()){let b=t.getDrawableOpacity(r);f=new R(b,b,b,b)}else f=e.getModelColorWithOpacity(t.getDrawableOpacity(r));let _=t.getOverrideMultiplyAndScreenColor(),y=_.getDrawableMultiplyColor(r),C=_.getDrawableScreenColor(r);if(this.gl.uniform4f(c.uniformBaseColorLocation,f.r,f.g,f.b,f.a),this.gl.uniform4f(c.uniformMultiplyColorLocation,y.r,y.g,y.b,y.a),this.gl.uniform4f(c.uniformScreenColorLocation,C.r,C.g,C.b,C.a),t.isBlendModeEnabled()&&(this.gl.activeTexture(this.gl.TEXTURE2),!d)){let b=e.getModelRenderTarget(1).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,b),this.gl.uniform1i(c.samplerFrameBufferTextureLocation,2)}e.bindDrawableIndexBuffer(r),this.gl.blendFuncSeparate(i,s,n,a)}setupShaderProgramForOffscreen(e,t,r){if(e.isPremultipliedAlpha()||D("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders(void 0,t.isBlendModeEnabled()),this._isShaderLoaded==!1){V("Shader program is not initialized.");return}let i,s,n,a,l=r.getOffscreenIndex(),o=e.getClippingContextBufferForOffscreen()!=null,u=t.getOffscreenInvertedMask(l),c=o?u?2:1:0,d,h=!0,g=t.getOffscreenColorBlend(l),A=t.getOffscreenAlphaBlend(l);if(g==-1||A==-1||g==O.ColorBlend_Normal&&A==0)d=this._shaderSets[1+c],i=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ONE,a=this.gl.ONE_MINUS_SRC_ALPHA;else switch(g){case O.ColorBlend_AddCompatible:d=this._shaderSets[4+c],i=this.gl.ONE,s=this.gl.ONE,n=this.gl.ZERO,a=this.gl.ONE;break;case O.ColorBlend_MultiplyCompatible:d=this._shaderSets[7+c],i=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ZERO,a=this.gl.ONE;break;default:{let B=r.getOldOffscreen()!=null?r.getOldOffscreen():e.getModelRenderTarget(0);Ae.copyBuffer(this.gl,B,e.getModelRenderTarget(1));let E=this._blendShaderSetMap.get(this._colorBlendMap.get(g)+this._alphaBlendMap.get(A));if(E===void 0)throw new Error("Blend shader programs are not registered for this context.");d=this._shaderSets[E+c],i=this.gl.ONE,s=this.gl.ZERO,n=this.gl.ONE,a=this.gl.ZERO,h=!1}break}this.setProgram(d.shaderProgram),Ae.copyBuffer(this.gl,r,e.getModelRenderTarget(2)),this.gl.activeTexture(this.gl.TEXTURE0);let p=e.getModelRenderTarget(2).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,p),this.gl.uniform1i(d.samplerTexture0Location,0);let f=new ne;f.loadIdentity(),this.gl.uniformMatrix4fv(d.uniformMatrixLocation,!1,f.getArray());let _=t.getOffscreenOpacity(l),y=new R(_,_,_,_),C=t.getOverrideMultiplyAndScreenColor(),b=C.getOffscreenMultiplyColor(l),x=C.getOffscreenScreenColor(l);if(this.gl.uniform4f(d.uniformBaseColorLocation,y.r,y.g,y.b,y.a),this.gl.uniform4f(d.uniformMultiplyColorLocation,b.r,b.g,b.b,b.a),this.gl.uniform4f(d.uniformScreenColorLocation,x.r,x.g,x.b,x.a),this.gl.activeTexture(this.gl.TEXTURE2),!h){let B=e.getModelRenderTarget(1).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,B),this.gl.uniform1i(d.samplerFrameBufferTextureLocation,2)}if(o){this.gl.activeTexture(this.gl.TEXTURE1);let B=e.getOffscreenMaskBuffer(e.getClippingContextBufferForOffscreen()._bufferIndex).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,B),this.gl.uniform1i(d.samplerTexture1Location,1),this.gl.uniformMatrix4fv(d.uniformClipMatrixLocation,!1,e.getClippingContextBufferForOffscreen()._matrixForDraw.getArray());let E=e.getClippingContextBufferForOffscreen()._layoutChannelIndex,T=e.getClippingContextBufferForOffscreen().getClippingManager().getChannelFlagAsColor(E);this.gl.uniform4f(d.uniformChannelFlagLocation,T.r,T.g,T.b,T.a),t.isBlendModeEnabled()&&this.gl.uniform1f(d.uniformInvertMaskFlagLocation,u?1:0)}e._bufferData.vertex||(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,Zi,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(d.attributePositionLocation),this.gl.vertexAttribPointer(d.attributePositionLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),e._bufferData.uv||(e._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,Go,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(d.attributeTexCoordLocation),this.gl.vertexAttribPointer(d.attributeTexCoordLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),this.gl.blendFuncSeparate(i,s,n,a)}setupShaderProgramForMask(e,t,r){if(e.isPremultipliedAlpha()||D("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders(void 0,t.isBlendModeEnabled()),this._isShaderLoaded==!1){V("Shader program is not initialized.");return}let i=this._shaderSets[0];this.setProgram(i.shaderProgram),e._bufferData.vertex==null&&(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex);let s=t.getDrawableVertices(r);this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(i.attributePositionLocation),this.gl.vertexAttribPointer(i.attributePositionLocation,2,this.gl.FLOAT,!1,0,0);let n=t.getDrawableTextureIndex(r),a=e.getBindedTextures().get(n);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(i.samplerTexture0Location,0),e.bindDrawableUvBuffer(r),this.gl.enableVertexAttribArray(i.attributeTexCoordLocation),this.gl.vertexAttribPointer(i.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0);let l=e.getClippingContextBufferForMask()._layoutChannelIndex,o=e.getClippingContextBufferForMask().getClippingManager().getChannelFlagAsColor(l);this.gl.uniform4f(i.uniformChannelFlagLocation,o.r,o.g,o.b,o.a),this.gl.uniformMatrix4fv(i.uniformClipMatrixLocation,!1,e.getClippingContextBufferForMask()._matrixForMask.getArray());let u=e.getClippingContextBufferForMask()._layoutBounds;this.gl.uniform4f(i.uniformBaseColorLocation,u.x*2-1,u.y*2-1,u.getRight()*2-1,u.getBottom()*2-1);let c=this.gl.ZERO,d=this.gl.ONE_MINUS_SRC_COLOR,h=this.gl.ZERO,g=this.gl.ONE_MINUS_SRC_ALPHA;e.bindDrawableIndexBuffer(r),this.gl.blendFuncSeparate(c,d,h,g)}setupShaderProgramForOffscreenRenderTarget(e){if(this._shaderSets.length==0&&this.generateShaders(void 0,e.getModel().isBlendModeEnabled()),this._isShaderLoaded==!1){V("Shader program is not initialized.");return}let t=e.getModelColor();t.r*=t.a,t.g*=t.a,t.b*=t.a,this.copyTexture(e,t)}copyTexture(e,t){let r=this.gl.ONE,i=this.gl.ONE_MINUS_SRC_ALPHA,s=this.gl.ONE,n=this.gl.ONE_MINUS_SRC_ALPHA,a=this._shaderSets[10];this.setProgram(a.shaderProgram),this.gl.uniform4f(a.uniformBaseColorLocation,t.r,t.g,t.b,t.a),this.gl.activeTexture(this.gl.TEXTURE0);let l=e.getModelRenderTarget(0).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,l),this.gl.uniform1i(a.samplerTexture0Location,0),e._bufferData.vertex||(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,Zi,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(a.attributePositionLocation),this.gl.vertexAttribPointer(a.attributePositionLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),e._bufferData.uv||(e._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,No,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(a.attributeTexCoordLocation),this.gl.vertexAttribPointer(a.attributeTexCoordLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),this.gl.blendFuncSeparate(r,i,s,n)}releaseShaderProgram(){let e=new Set;for(let t=0;t<this._shaderSets.length;t++){let r=this._shaderSets[t];r&&(r.shaderProgram&&e.add(r.shaderProgram),r.shaderProgram=null,this._shaderSets[t]=void 0,this._shaderSets[t]=null)}for(let t of e)this.gl.deleteProgram(t);this._shaderSets.length=0,this._blendShaderSetMap.clear(),this._blendShadersRegistered=!1,this._currentProgram=null}generateShaders(e,t=!0){if(this._isShaderLoaded)return t&&!this._blendShadersRegistered&&(this.registerBlendShader(),this._blendShadersRegistered=!0),Promise.resolve();if(this._isShaderLoading)return this._shaderLoadPromise.then(()=>this.generateShaders(e,t));this._isShaderLoading=!0,this._isShaderLoaded=!1,this._shaderSets.length=this._shaderCount;for(let r=0;r<this._shaderCount;r++)this._shaderSets[r]=new Zs;return this._shaderLoadPromise=this.loadShaders(e).then(()=>{this.registerShader(),t&&this.registerBlendShader(),this._blendShadersRegistered=t,this._isShaderLoading=!1,this._isShaderLoaded=!0}).catch(r=>{throw this._isShaderLoading=!1,this._isShaderLoaded=!1,this.releaseShaderProgram(),r}),this._shaderLoadPromise}registerShader(){let e=this._vertShaderSrc,t=this._vertShaderSrcMasked,r=this._vertShaderSrcSetupMask,i=this._fragShaderSrcSetupMask,s=this._fragShaderSrcPremultipliedAlpha,n=this._fragShaderSrcMaskPremultipliedAlpha,a=this._fragShaderSrcMaskInvertedPremultipliedAlpha;this._shaderSets[0].shaderProgram=this.loadShaderProgram(r,i),this._shaderSets[1].shaderProgram=this.loadShaderProgram(e,s),this._shaderSets[2].shaderProgram=this.loadShaderProgram(t,n),this._shaderSets[3].shaderProgram=this.loadShaderProgram(t,a),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[1].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_multiplyColor"),this._shaderSets[1].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_screenColor"),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[2].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_multiplyColor"),this._shaderSets[2].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_screenColor"),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[3].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_multiplyColor"),this._shaderSets[3].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_screenColor"),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[4].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_multiplyColor"),this._shaderSets[4].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_screenColor"),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[5].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_multiplyColor"),this._shaderSets[5].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_screenColor"),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[6].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_multiplyColor"),this._shaderSets[6].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_screenColor"),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[7].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_multiplyColor"),this._shaderSets[7].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_screenColor"),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[8].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_multiplyColor"),this._shaderSets[8].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_screenColor"),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"),this._shaderSets[9].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_multiplyColor"),this._shaderSets[9].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_screenColor")}registerBlendShader(){let e=this._vertShaderSrcCopy,t=this._fragShaderSrcCopy,r=this._shaderSets[10];r.shaderProgram=this.loadShaderProgram(e,t),r.attributeTexCoordLocation=this.gl.getAttribLocation(r.shaderProgram,"a_texCoord"),r.attributePositionLocation=this.gl.getAttribLocation(r.shaderProgram,"a_position"),r.uniformBaseColorLocation=this.gl.getUniformLocation(r.shaderProgram,"u_baseColor");let i=11;for(let s=0;s<this._colorBlendValues.length;s++){if(this._colorBlendValues[s]==-1||this._colorBlendValues[s]==O.ColorBlend_AddCompatible||this._colorBlendValues[s]==O.ColorBlend_MultiplyCompatible)continue;let n=this._colorBlendValues[s],a=`#define COLOR_BLEND_${this._colorBlendMap.get(n).toUpperCase()}
21
- `;for(let l=0;l<this._alphaBlendValues.length;l++){if(this._alphaBlendValues[l]==-1||this._colorBlendValues[s]==O.ColorBlend_Normal&&this._alphaBlendValues[l]==0)continue;let o=this._alphaBlendValues[l],u=`#define ALPHA_BLEND_${this._alphaBlendMap.get(o).toUpperCase()}
18
+ `,this._stringBuffer}getMap(e){return this._map}put(e,t){this._map.set(e,t)}getKeys(){return this._keys||(this._keys=[...this._map.keys()]),this._keys}getSize(){return this._keys.length}_map;_keys};(function(e){e.CubismJson=G,e.JsonArray=ir,e.JsonBoolean=K,e.JsonError=Ye,e.JsonFloat=ft,e.JsonMap=Oe,e.JsonNullvalue=Fe,e.JsonString=Ve,e.Value=U})(ai||(ai={}));Z=!1,xe=!1,Ee=null,Ge=null,$=Object.freeze({vertexOffset:0,vertexStep:2});P=class{static startUp(e=null){if(Z)return de("CubismFramework.startUp() is already done."),Z;if(Ee=e,Ee!=null&&Live2DCubismCore.Logging.csmSetLogFunction(Ee.logFunction),Z=!0,Z){let t=Live2DCubismCore.Version.csmGetVersion(),r=(t&4278190080)>>24,i=(t&16711680)>>16,s=t&65535,n=t;de("Live2D Cubism Core version: {0}.{1}.{2} ({3})",("00"+r).slice(-2),("00"+i).slice(-2),("0000"+s).slice(-4),n)}return de("CubismFramework.startUp() is complete."),Z}static cleanUp(){Z=!1,xe=!1,Ee=null,Ge=null}static initialize(e=0){if(k(Z),!Z){O("CubismFramework is not started.");return}if(xe){O("CubismFramework.initialize() skipped, already initialized.");return}U.staticInitializeNotForClientCall(),Ge=new _s,Live2DCubismCore.Memory.initializeAmountOfMemory(e),xe=!0,de("CubismFramework.initialize() is complete.")}static dispose(){if(k(Z),!Z){O("CubismFramework is not started.");return}if(!xe){O("CubismFramework.dispose() skipped, not initialized.");return}U.staticReleaseNotForClientCall(),Ge.release(),Ge=null,pt.staticRelease(),xe=!1,de("CubismFramework.dispose() is complete.")}static isStarted(){return Z}static isInitialized(){return xe}static coreLogFunction(e){Live2DCubismCore.Logging.csmGetLogFunction()&&Live2DCubismCore.Logging.csmGetLogFunction()(e)}static getLoggingLevel(){return Ee!=null?Ee.loggingLevel:5}static getIdManager(){return Ge}constructor(){}};(function(e){e.Constant=$,e.csmDelete=Le,e.CubismFramework=P})(oi||(oi={}));la=(function(e){return e[e.FrequestNode_Groups=0]="FrequestNode_Groups",e[e.FrequestNode_Moc=1]="FrequestNode_Moc",e[e.FrequestNode_Motions=2]="FrequestNode_Motions",e[e.FrequestNode_Expressions=3]="FrequestNode_Expressions",e[e.FrequestNode_Textures=4]="FrequestNode_Textures",e[e.FrequestNode_Physics=5]="FrequestNode_Physics",e[e.FrequestNode_Pose=6]="FrequestNode_Pose",e[e.FrequestNode_HitAreas=7]="FrequestNode_HitAreas",e})({}),ys=class extends ps{constructor(e,t){super(),this._json=G.create(e,t),this.getJson()&&(this._jsonValue=[this.getJson().getRoot().getValueByString(this.groups),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.moc),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.motions),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.expressions),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.textures),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.physics),this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.pose),this.getJson().getRoot().getValueByString(this.hitAreas)])}release(){G.delete(this._json),this._jsonValue=null}getJson(){return this._json}getModelFileName(){return this.isExistModelFile()?this._jsonValue[1].getRawString():""}getTextureCount(){return this.isExistTextureFiles()?this._jsonValue[4].getSize():0}getTextureDirectory(){let e=this._jsonValue[4].getValueByIndex(0).getRawString().split("/"),t=e.length-1,r="";for(let i=0;i<t;i++)r+=e[i],i<t-1&&(r+="/");return r}getTextureFileName(e){return this._jsonValue[4].getValueByIndex(e).getRawString()}getHitAreasCount(){return this.isExistHitAreas()?this._jsonValue[7].getSize():0}getHitAreaId(e){return P.getIdManager().getId(this._jsonValue[7].getValueByIndex(e).getValueByString(this.id).getRawString())}getHitAreaName(e){return this._jsonValue[7].getValueByIndex(e).getValueByString(this.name).getRawString()}getPhysicsFileName(){return this.isExistPhysicsFile()?this._jsonValue[5].getRawString():""}getPoseFileName(){return this.isExistPoseFile()?this._jsonValue[6].getRawString():""}getExpressionCount(){return this.isExistExpressionFile()?this._jsonValue[3].getSize():0}getExpressionName(e){return this._jsonValue[3].getValueByIndex(e).getValueByString(this.name).getRawString()}getExpressionFileName(e){return this._jsonValue[3].getValueByIndex(e).getValueByString(this.filePath).getRawString()}getMotionGroupCount(){return this.isExistMotionGroups()?this._jsonValue[2].getKeys().length:0}getMotionGroupName(e){return this.isExistMotionGroups()?this._jsonValue[2].getKeys()[e]:null}getMotionCount(e){return this.isExistMotionGroupName(e)?this._jsonValue[2].getValueByString(e).getSize():0}getMotionFileName(e,t){return this.isExistMotionGroupName(e)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.filePath).getRawString():""}getMotionSoundFileName(e,t){return this.isExistMotionSoundFile(e,t)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.soundPath).getRawString():""}getMotionFadeInTimeValue(e,t){return this.isExistMotionFadeIn(e,t)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeInTime).toFloat():-1}getMotionFadeOutTimeValue(e,t){return this.isExistMotionFadeOut(e,t)?this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeOutTime).toFloat():-1}getUserDataFile(){return this.isExistUserDataFile()?this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData).getRawString():""}getLayoutMap(e){let t=this.getJson().getRoot().getValueByString(this.layout).getMap();if(t==null)return!1;let r=!1;for(let i of t)e.set(i[0],i[1].toFloat()),r=!0;return r}getEyeBlinkParameterCount(){if(!this.isExistEyeBlinkParameters())return 0;let e=0;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.eyeBlink){e=r.getValueByString(this.ids).getVector().length;break}}return e}getEyeBlinkParameterId(e){if(!this.isExistEyeBlinkParameters())return null;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.eyeBlink)return P.getIdManager().getId(r.getValueByString(this.ids).getValueByIndex(e).getRawString())}return null}getLipSyncParameterCount(){if(!this.isExistLipSyncParameters())return 0;let e=0;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.lipSync){e=r.getValueByString(this.ids).getVector().length;break}}return e}getLipSyncParameterId(e){if(!this.isExistLipSyncParameters())return null;for(let t=0;t<this._jsonValue[0].getSize();t++){let r=this._jsonValue[0].getValueByIndex(t);if(!(r.isNull()||r.isError())&&r.getValueByString(this.name).getRawString()==this.lipSync)return P.getIdManager().getId(r.getValueByString(this.ids).getValueByIndex(e).getRawString())}return null}isExistModelFile(){let e=this._jsonValue[1];return!e.isNull()&&!e.isError()}isExistTextureFiles(){let e=this._jsonValue[4];return!e.isNull()&&!e.isError()}isExistHitAreas(){let e=this._jsonValue[7];return!e.isNull()&&!e.isError()}isExistPhysicsFile(){let e=this._jsonValue[5];return!e.isNull()&&!e.isError()}isExistPoseFile(){let e=this._jsonValue[6];return!e.isNull()&&!e.isError()}isExistExpressionFile(){let e=this._jsonValue[3];return!e.isNull()&&!e.isError()}isExistMotionGroups(){let e=this._jsonValue[2];return!e.isNull()&&!e.isError()}isExistMotionGroupName(e){let t=this._jsonValue[2].getValueByString(e);return!t.isNull()&&!t.isError()}isExistMotionSoundFile(e,t){let r=this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.soundPath);return!r.isNull()&&!r.isError()}isExistMotionFadeIn(e,t){let r=this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeInTime);return!r.isNull()&&!r.isError()}isExistMotionFadeOut(e,t){let r=this._jsonValue[2].getValueByString(e).getValueByIndex(t).getValueByString(this.fadeOutTime);return!r.isNull()&&!r.isError()}isExistUserDataFile(){let e=this.getJson().getRoot().getValueByString(this.fileReferences).getValueByString(this.userData);return!e.isNull()&&!e.isError()}isExistEyeBlinkParameters(){if(this._jsonValue[0].isNull()||this._jsonValue[0].isError())return!1;for(let e=0;e<this._jsonValue[0].getSize();++e)if(this._jsonValue[0].getValueByIndex(e).getValueByString(this.name).getRawString()==this.eyeBlink)return!0;return!1}isExistLipSyncParameters(){if(this._jsonValue[0].isNull()||this._jsonValue[0].isError())return!1;for(let e=0;e<this._jsonValue[0].getSize();++e)if(this._jsonValue[0].getValueByIndex(e).getValueByString(this.name).getRawString()==this.lipSync)return!0;return!1}_json;_jsonValue;version="Version";fileReferences="FileReferences";groups="Groups";layout="Layout";hitAreas="HitAreas";moc="Moc";textures="Textures";physics="Physics";pose="Pose";expressions="Expressions";motions="Motions";userData="UserData";name="Name";filePath="File";id="Id";ids="Ids";target="Target";idle="Idle";tapBody="TapBody";pinchIn="PinchIn";pinchOut="PinchOut";shake="Shake";flickHead="FlickHead";parameter="Parameter";soundPath="Sound";fadeInTime="FadeInTime";fadeOutTime="FadeOutTime";centerX="CenterX";centerY="CenterY";x="X";y="Y";width="Width";height="Height";lipSync="LipSync";eyeBlink="EyeBlink";initParameter="init_param";initPartsVisible="init_parts_visible";val="val"};(function(e){e.CubismModelSettingJson=ys,e.FrequestNode=la})(li||(li={}));sr=class bs{static create(){return new bs}static delete(t){t!=null&&(t=null)}setParameters(t){this._breathParameters=t}getParameters(){return this._breathParameters}updateParameters(t,r){this._currentTime+=r;let i=this._currentTime*2*Math.PI;for(let s=0;s<this._breathParameters.length;++s){let n=this._breathParameters[s];t.addParameterValueById(n.parameterId,n.offset+n.peak*Math.sin(i/n.cycle),n.weight)}}constructor(){this._currentTime=0}_breathParameters;_currentTime},De=class{constructor(e,t,r,i,s){this.parameterId=e??null,this.offset=t??0,this.peak=r??0,this.cycle=i??0,this.weight=s??0}parameterId;offset;peak;cycle;weight};(function(e){e.BreathParameterData=De,e.CubismBreath=sr})(ui||(ui={}));nr=class Yt{static create(t=null){return new Yt(t)}static delete(t){t!=null&&(t=null)}setBlinkingInterval(t){this._blinkingIntervalSeconds=t}setBlinkingSetting(t,r,i){this._closingSeconds=t,this._closedSeconds=r,this._openingSeconds=i}setParameterIds(t){this._parameterIds=t}getParameterIds(){return this._parameterIds}updateParameters(t,r){this._userTimeSeconds+=r;let i,s=0;switch(this._blinkingState){case 2:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closingSeconds,s>=1&&(s=1,this._blinkingState=3,this._stateStartTimeSeconds=this._userTimeSeconds),i=1-s;break;case 3:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._closedSeconds,s>=1&&(this._blinkingState=4,this._stateStartTimeSeconds=this._userTimeSeconds),i=0;break;case 4:s=(this._userTimeSeconds-this._stateStartTimeSeconds)/this._openingSeconds,s>=1&&(s=1,this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming()),i=s;break;case 1:this._nextBlinkingTime<this._userTimeSeconds&&(this._blinkingState=2,this._stateStartTimeSeconds=this._userTimeSeconds),i=1;break;default:this._blinkingState=1,this._nextBlinkingTime=this.determinNextBlinkingTiming(),i=1;break}Yt.CloseIfZero||(i=-i);for(let n=0;n<this._parameterIds.length;++n)t.setParameterValueById(this._parameterIds[n],i)}constructor(t){if(this._blinkingState=0,this._nextBlinkingTime=0,this._stateStartTimeSeconds=0,this._blinkingIntervalSeconds=4,this._closingSeconds=.1,this._closedSeconds=.05,this._openingSeconds=.15,this._userTimeSeconds=0,this._parameterIds=new Array,t!=null){this._parameterIds.length=t.getEyeBlinkParameterCount();for(let r=0;r<t.getEyeBlinkParameterCount();++r)this._parameterIds[r]=t.getEyeBlinkParameterId(r)}}determinNextBlinkingTiming(){let t=Math.random();return this._userTimeSeconds+t*(2*this._blinkingIntervalSeconds-1)}_blinkingState;_parameterIds;_nextBlinkingTime;_stateStartTimeSeconds;_blinkingIntervalSeconds;_closingSeconds;_closedSeconds;_openingSeconds;_userTimeSeconds;static CloseIfZero=!0},ua=(function(e){return e[e.EyeState_First=0]="EyeState_First",e[e.EyeState_Interval=1]="EyeState_Interval",e[e.EyeState_Closing=2]="EyeState_Closing",e[e.EyeState_Closed=3]="EyeState_Closed",e[e.EyeState_Opening=4]="EyeState_Opening",e})({});(function(e){e.CubismEyeBlink=nr,e.EyeState=ua})(hi||(hi={}));zt=class Bs{static create(){return new Bs}static delete(t){t!=null&&(t=null)}setParameters(t){this._lookParameters=t}getParameters(){return this._lookParameters}updateParameters(t,r,i){for(let s=0;s<this._lookParameters.length;++s){let n=this._lookParameters[s];t.addParameterValueById(n.parameterId,n.factorX*r+n.factorY*i+n.factorXY*r*i)}}constructor(){this._lookParameters=new Array}_lookParameters},Ie=class{constructor(e,t,r,i){this.parameterId=e??null,this.factorX=t??0,this.factorY=r??0,this.factorXY=i??0}parameterId;factorX;factorY;factorXY};(function(e){e.LookParameterData=Ie,e.CubismLook=zt})(ci||(ci={}));ar=class extends ne{constructor(e,t){super(),this._width=e!==void 0?e:0,this._height=t!==void 0?t:0,this.setHeight(2)}setWidth(e){let t=e/this._width,r=t;this.scale(t,r)}setHeight(e){let t=e/this._height,r=t;this.scale(t,r)}setPosition(e,t){this.translate(e,t)}setCenterPosition(e,t){this.centerX(e),this.centerY(t)}top(e){this.setY(e)}bottom(e){let t=this._height*this.getScaleY();this.translateY(e-t)}left(e){this.setX(e)}right(e){let t=this._width*this.getScaleX();this.translateX(e-t)}centerX(e){let t=this._width*this.getScaleX();this.translateX(e-t/2)}setX(e){this.translateX(e)}centerY(e){let t=this._height*this.getScaleY();this.translateY(e-t/2)}setY(e){this.translateY(e)}setupFromLayout(e){let t="width",r="height",n="center_x",a="center_y",o="bottom",u="left",h="right";for(let d of e){let c=d[0],g=d[1];c==t?this.setWidth(g):c==r&&this.setHeight(g)}for(let d of e){let c=d[0],g=d[1];c=="x"?this.setX(g):c=="y"?this.setY(g):c==n?this.centerX(g):c==a?this.centerY(g):c=="top"?this.top(g):c==o?this.bottom(g):c==u?this.left(g):c==h&&this.right(g)}}_width;_height};(function(e){e.CubismModelMatrix=ar})(di||(di={}));ha=.001,Tt=.5,gi="FadeInTime",fi="Link",ca="Groups",da="Id",Jt=class Is{static create(t,r){let i=G.create(t,r);if(!i)return null;let s=new Is,n=i.getRoot();n.getValueByString(gi).isNull()||(s._fadeTimeSeconds=n.getValueByString(gi).toFloat(Tt),s._fadeTimeSeconds<0&&(s._fadeTimeSeconds=Tt));let a=n.getValueByString(ca),l=a.getSize();s._partGroupCounts.length=l;for(let o=0;o<l;++o){let u=a.getValueByIndex(o),h=u.getSize(),d=0;for(let c=0;c<h;++c){let g=u.getValueByIndex(c),A=new jt;if(A.partId=P.getIdManager().getId(g.getValueByString(da).getRawString()),!g.getValueByString(fi).isNull()){let p=g.getValueByString(fi),f=p.getSize();for(let _=0;_<f;++_){let y=new jt;y.partId=P.getIdManager().getId(p.getValueByIndex(_).getString()),A.link.push(y)}}s._partGroups.push(A.clone()),++d}s._partGroupCounts[o]=d}return G.delete(i),s}static delete(t){t!=null&&(t=null)}updateParameters(t,r){t!=this._lastModel&&this.reset(t),this._lastModel=t,r<0&&(r=0);let i=0;for(let s=0;s<this._partGroupCounts.length;s++){let n=this._partGroupCounts[s];this.doFade(t,r,i,n),i+=n}this.copyPartOpacities(t)}reset(t){let r=0;for(let i=0;i<this._partGroupCounts.length;++i){let s=this._partGroupCounts[i];for(let n=r;n<r+s;++n){this._partGroups[n].initialize(t);let a=this._partGroups[n].partIndex,l=this._partGroups[n].parameterIndex;if(!(a<0)){t.setPartOpacityByIndex(a,n==r?1:0),t.setParameterValueByIndex(l,n==r?1:0);for(let o=0;o<this._partGroups[n].link.length;++o)this._partGroups[n].link[o].initialize(t)}}r+=s}}copyPartOpacities(t){for(let r=0;r<this._partGroups.length;++r){let i=this._partGroups[r];if(i.link.length==0)continue;let s=this._partGroups[r].partIndex,n=t.getPartOpacityByIndex(s);for(let a=0;a<i.link.length;++a){let l=i.link[a].partIndex;l<0||t.setPartOpacityByIndex(l,n)}}}doFade(t,r,i,s){let n=-1,a=1,l=.5,o=.15;for(let u=i;u<i+s;++u){let h=this._partGroups[u].partIndex,d=this._partGroups[u].parameterIndex;if(t.getParameterValueByIndex(d)>ha){if(n>=0)break;if(n=u,this._fadeTimeSeconds==0){a=1;continue}a=t.getPartOpacityByIndex(h),a+=r/this._fadeTimeSeconds,a>1&&(a=1)}}n<0&&(n=0,a=1);for(let u=i;u<i+s;++u){let h=this._partGroups[u].partIndex;if(n==u)t.setPartOpacityByIndex(h,a);else{let d=t.getPartOpacityByIndex(h),c;a<l?c=a*(l-1)/l+1:c=(1-a)*l/(1-l),(1-c)*(1-a)>o&&(c=1-o/(1-a)),d>c&&(d=c),t.setPartOpacityByIndex(h,d)}}}constructor(){this._fadeTimeSeconds=Tt,this._lastModel=null,this._partGroups=new Array,this._partGroupCounts=new Array}_partGroups;_partGroupCounts;_fadeTimeSeconds;_lastModel},jt=class Ss{constructor(t){if(this.parameterIndex=0,this.partIndex=0,this.link=new Array,t!=null){this.partId=t.partId,this.link.length=t.link.length;for(let r=0;r<t.link.length;r++)this.link[r]=t.link[r].clone()}}assignment(t){this.partId=t.partId;let r=this.link.length;this.link.length+=t.link.length;for(let i of t.link)this.link[r++]=i.clone();return this}initialize(t){this.parameterIndex=t.getParameterIndex(this.partId),this.partIndex=t.getPartIndex(this.partId),t.setParameterValueByIndex(this.parameterIndex,1)}clone(){let t=new Ss;t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=new Array,t.link.length=this.link.length;for(let r=0;r<this.link.length;r++)t.link[r]=this.link[r].clone();return t}partId;parameterIndex;partIndex;link};(function(e){e.CubismPose=Jt,e.PartData=jt})(Ai||(Ai={}));Ft=30,pi=.01,Ms=class{constructor(){this._faceTargetX=0,this._faceTargetY=0,this._faceX=0,this._faceY=0,this._faceVX=0,this._faceVY=0,this._lastTimeSeconds=0,this._userTimeSeconds=0}update(e){this._userTimeSeconds+=e;let t=40/10*1/Ft;if(this._lastTimeSeconds==0){this._lastTimeSeconds=this._userTimeSeconds;return}let r=(this._userTimeSeconds-this._lastTimeSeconds)*Ft;this._lastTimeSeconds=this._userTimeSeconds;let i=.15*Ft,s=r*t/i,n=this._faceTargetX-this._faceX,a=this._faceTargetY-this._faceY;if(M.abs(n)<=pi&&M.abs(a)<=pi)return;let l=M.sqrt(n*n+a*a),o=t*n/l,u=t*a/l,h=o-this._faceVX,d=u-this._faceVY,c=M.sqrt(h*h+d*d);(c<-s||c>s)&&(h*=s/c,d*=s/c),this._faceVX+=h,this._faceVY+=d;{let g=.5*(M.sqrt(s*s+16*s*l-8*s*l)-s),A=M.sqrt(this._faceVX*this._faceVX+this._faceVY*this._faceVY);A>g&&(this._faceVX*=g/A,this._faceVY*=g/A)}this._faceX+=this._faceVX,this._faceY+=this._faceVY}getX(){return this._faceX}getY(){return this._faceY}set(e,t){this._faceTargetX=e,this._faceTargetY=t}_faceTargetX;_faceTargetY;_faceX;_faceY;_faceVX;_faceVY;_lastTimeSeconds;_userTimeSeconds};(function(e){e.CubismTargetPoint=Ms})(mi||(mi={}));ws=class{constructor(){this._autoDelete=!1,this._motion=null,this._available=!0,this._finished=!1,this._started=!1,this._startTimeSeconds=-1,this._fadeInStartTimeSeconds=0,this._endTimeSeconds=-1,this._stateTimeSeconds=0,this._stateWeight=0,this._lastEventCheckSeconds=0,this._motionQueueEntryHandle=this,this._fadeOutSeconds=0,this._isTriggeredFadeOut=!1}release(){this._autoDelete&&this._motion&&Se.delete(this._motion)}setFadeOut(e){this._fadeOutSeconds=e,this._isTriggeredFadeOut=!0}startFadeOut(e,t){let r=t+e;this._isTriggeredFadeOut=!0,(this._endTimeSeconds<0||r<this._endTimeSeconds)&&(this._endTimeSeconds=r)}isFinished(){return this._finished}isStarted(){return this._started}getStartTime(){return this._startTimeSeconds}getFadeInStartTime(){return this._fadeInStartTimeSeconds}getEndTime(){return this._endTimeSeconds}setStartTime(e){this._startTimeSeconds=e}setFadeInStartTime(e){this._fadeInStartTimeSeconds=e}setEndTime(e){this._endTimeSeconds=e}setIsFinished(e){this._finished=e}setIsStarted(e){this._started=e}isAvailable(){return this._available}setIsAvailable(e){this._available=e}setState(e,t){this._stateTimeSeconds=e,this._stateWeight=t}getStateTime(){return this._stateTimeSeconds}getStateWeight(){return this._stateWeight}getLastCheckEventSeconds(){return this._lastEventCheckSeconds}setLastCheckEventSeconds(e){this._lastEventCheckSeconds=e}isTriggeredFadeOut(){return this._isTriggeredFadeOut}getFadeOutSeconds(){return this._fadeOutSeconds}getCubismMotion(){return this._motion}_autoDelete;_motion;_available;_finished;_started;_startTimeSeconds;_fadeInStartTimeSeconds;_endTimeSeconds;_stateTimeSeconds;_stateWeight;_lastEventCheckSeconds;_fadeOutSeconds;_isTriggeredFadeOut;_motionQueueEntryHandle};(function(e){e.CubismMotionQueueEntry=ws})(_i||(_i={}));Se=class{static delete(e){e.release(),e=null}constructor(){this._fadeInSeconds=-1,this._fadeOutSeconds=-1,this._weight=1,this._offsetSeconds=0,this._isLoop=!1,this._isLoopFadeIn=!0,this._previousLoopState=this._isLoop,this._firedEventValues=new Array}release(){this._weight=0}updateParameters(e,t,r){if(!t.isAvailable()||t.isFinished())return;this.setupMotionQueueEntry(t,r);let i=this.updateFadeWeight(t,r);this.doUpdateParameters(e,r,i,t),t.getEndTime()>0&&t.getEndTime()<r&&t.setIsFinished(!0)}setupMotionQueueEntry(e,t){e==null||e.isStarted()||e.isAvailable()&&(e.setIsStarted(!0),e.setStartTime(t-this._offsetSeconds),e.setFadeInStartTime(t),e.getEndTime()<0&&this.adjustEndTime(e),e._motion._onBeganMotion&&e._motion._onBeganMotion(e._motion))}updateFadeWeight(e,t){e==null&&rr.print(4,"motionQueueEntry is null.");let r=this._weight,i=this._fadeInSeconds==0?1:M.getEasingSine((t-e.getFadeInStartTime())/this._fadeInSeconds),s=this._fadeOutSeconds==0||e.getEndTime()<0?1:M.getEasingSine((e.getEndTime()-t)/this._fadeOutSeconds);return r=r*i*s,e.setState(t,r),k(0<=r&&r<=1),r}setFadeInTime(e){this._fadeInSeconds=e}setFadeOutTime(e){this._fadeOutSeconds=e}getFadeOutTime(){return this._fadeOutSeconds}getFadeInTime(){return this._fadeInSeconds}setWeight(e){this._weight=e}getWeight(){return this._weight}getDuration(){return-1}getLoopDuration(){return-1}setOffsetTime(e){this._offsetSeconds=e}setLoop(e){this._isLoop=e}getLoop(){return this._isLoop}setLoopFadeIn(e){this._isLoopFadeIn=e}getLoopFadeIn(){return this._isLoopFadeIn}getFiredEvent(e,t){return this._firedEventValues}setBeganMotionHandler=e=>this._onBeganMotion=e;getBeganMotionHandler=()=>this._onBeganMotion;setFinishedMotionHandler=e=>this._onFinishedMotion=e;getFinishedMotionHandler=()=>this._onFinishedMotion;isExistModelOpacity(){return!1}getModelOpacityIndex(){return-1}getModelOpacityId(e){return null}getModelOpacityValue(){return 1}adjustEndTime(e){let t=this.getDuration(),r=t<=0?-1:e.getStartTime()+t;e.setEndTime(r)}_fadeInSeconds;_fadeOutSeconds;_weight;_offsetSeconds;_isLoop;_isLoopFadeIn;_previousLoopState;_firedEventValues;_onBeganMotion;_onFinishedMotion};(function(e){e.ACubismMotion=Se})(Ci||(Ci={}));or=class{constructor(){this._userTimeSeconds=0,this._eventCallBack=null,this._eventCustomData=null,this._motions=new Array}release(){for(let e=0;e<this._motions.length;++e)this._motions[e]&&(this._motions[e].release(),this._motions[e]=null);this._motions=null}startMotion(e,t,r){if(e==null)return-1;let i=null;for(let s=0;s<this._motions.length;++s)i=this._motions[s],i?.setFadeOut(i._motion.getFadeOutTime());return i=new ws,i._autoDelete=t,i._motion=e,this._motions.push(i),i._motionQueueEntryHandle}isFinished(){for(let e=0;e<this._motions.length;){let t=this._motions[e];if(t==null){this._motions.splice(e,1);continue}if(t._motion==null){t.release(),t=null,this._motions.splice(e,1);continue}if(t.isFinished())e++;else return!1}return!0}isFinishedByHandle(e){for(let t=0;t<this._motions.length;t++){let r=this._motions[t];if(r!=null&&r._motionQueueEntryHandle==e&&!r.isFinished())return!1}return!0}stopAllMotions(){for(let e=0;e<this._motions.length;e++){let t=this._motions[e];if(t==null){this._motions.splice(e,1);continue}t.release(),this._motions.splice(e,1)}}getCubismMotionQueueEntries(){return this._motions}getCubismMotionQueueEntry(e){for(let t=0;t<this._motions.length;t++){let r=this._motions[t];if(r!=null&&r._motionQueueEntryHandle==e)return r}return null}setEventCallback(e,t=null){this._eventCallBack=e,this._eventCustomData=t}doUpdateMotion(e,t){let r=!1;for(let i=0;i<this._motions.length;){let s=this._motions[i];if(s==null){this._motions.splice(i,1);continue}let n=s._motion;if(n==null){s.release(),s=null,this._motions.splice(i,1);continue}n.updateParameters(e,s,t),r=!0;let a=n.getFiredEvent(s.getLastCheckEventSeconds()-s.getStartTime(),t-s.getStartTime());for(let l=0;l<a.length;++l)this._eventCallBack(this,a[l],this._eventCustomData);s.setLastCheckEventSeconds(t),s.isFinished()?(s.release(),s=null,this._motions.splice(i,1)):(s.isTriggeredFadeOut()&&s.startFadeOut(s.getFadeOutSeconds(),t),i++)}return r}_userTimeSeconds;_motions;_eventCallBack;_eventCustomData};(function(e){e.CubismMotionQueueManager=or,e.InvalidMotionQueueEntryHandleValue=-1})(yi||(yi={}));ga=class{parameterId;additiveValue;multiplyValue;overwriteValue},xs=class extends or{constructor(){super(),this._expressionParameterValues=new Array,this._fadeWeights=new Array}release(){this._expressionParameterValues&&(Le(this._expressionParameterValues),this._expressionParameterValues=null),this._fadeWeights&&(Le(this._fadeWeights),this._fadeWeights=null)}getFadeWeight(e){return e<0||this._fadeWeights.length<1||e>=this._fadeWeights.length?(console.warn("Failed to get the fade weight value. The element at that index does not exist."),-1):this._fadeWeights[e]}setFadeWeight(e,t){if(e<0||this._fadeWeights.length<1||this._fadeWeights.length<=e){console.warn("Failed to set the fade weight value. The element at that index does not exist.");return}this._fadeWeights[e]=t}updateMotion(e,t){this._userTimeSeconds+=t;let r=!1,i=this.getCubismMotionQueueEntries(),s=0,n=0;if(this._fadeWeights.length!==i.length){let a=i.length-this._fadeWeights.length,l=this._fadeWeights.length;this._fadeWeights.length+=a;for(let o=0;o<a;o++)this._fadeWeights[l++]=0}for(let a=0;a<this._motions.length;){let l=this._motions[a];if(l==null){i.splice(a,1);continue}let o=l.getCubismMotion();if(o==null){Le(l),i.splice(a,1);continue}let u=o.getExpressionParameters();if(l.isAvailable())for(let h=0;h<u.length;++h){if(u[h].parameterId==null)continue;let d=-1;for(let g=0;g<this._expressionParameterValues.length;++g)if(this._expressionParameterValues[g].parameterId==u[h].parameterId){d=g;break}if(d>=0)continue;let c=new ga;c.parameterId=u[h].parameterId,c.additiveValue=Te.DefaultAdditiveValue,c.multiplyValue=Te.DefaultMultiplyValue,c.overwriteValue=e.getParameterValueById(c.parameterId),this._expressionParameterValues.push(c)}o.setupMotionQueueEntry(l,this._userTimeSeconds),this.setFadeWeight(n,o.updateFadeWeight(l,this._userTimeSeconds)),o.calculateExpressionParameters(e,this._userTimeSeconds,l,this._expressionParameterValues,n,this.getFadeWeight(n)),s+=o.getFadeInTime()==0?1:M.getEasingSine((this._userTimeSeconds-l.getFadeInStartTime())/o.getFadeInTime()),r=!0,l.isTriggeredFadeOut()&&l.startFadeOut(l.getFadeOutSeconds(),this._userTimeSeconds),++a,++n}if(i.length>1&&this.getFadeWeight(this._fadeWeights.length-1)>=1)for(let a=i.length-2;a>=0;--a){let l=i[a];Le(l),i.splice(a,1),this._fadeWeights.splice(a,1)}s>1&&(s=1);for(let a=0;a<this._expressionParameterValues.length;++a){let l=this._expressionParameterValues[a];e.setParameterValueById(l.parameterId,(l.overwriteValue+l.additiveValue)*l.multiplyValue,s),l.additiveValue=Te.DefaultAdditiveValue,l.multiplyValue=Te.DefaultMultiplyValue}return r}_expressionParameterValues;_fadeWeights;_startExpressionTime};(function(e){e.CubismExpressionMotionManager=xs})(bi||(bi={}));fa="FadeInTime",Aa="FadeOutTime",Bi="Parameters",pa="Id",ma="Value",tt="Blend",_a="Add",Ca="Multiply",ya="Overwrite",Ii=1,Te=class ie extends Se{static DefaultAdditiveValue=0;static DefaultMultiplyValue=1;static create(t,r){let i=new ie;return i.parse(t,r),i}doUpdateParameters(t,r,i,s){for(let n=0;n<this._parameters.length;++n){let a=this._parameters[n];switch(a.blendType){case 0:t.addParameterValueById(a.parameterId,a.value,i);break;case 1:t.multiplyParameterValueById(a.parameterId,a.value,i);break;case 2:t.setParameterValueById(a.parameterId,a.value,i);break;default:break}}}calculateExpressionParameters(t,r,i,s,n,a){if(!(i==null||s==null)&&i.isAvailable())for(let l=0;l<s.length;++l){let o=s[l];if(o.parameterId==null)continue;let u=o.overwriteValue=t.getParameterValueById(o.parameterId),h=this.getExpressionParameters(),d=-1;for(let f=0;f<h.length;++f)if(o.parameterId==h[f].parameterId){d=f;break}if(d<0){n==0?(o.additiveValue=ie.DefaultAdditiveValue,o.multiplyValue=ie.DefaultMultiplyValue,o.overwriteValue=u):(o.additiveValue=this.calculateValue(o.additiveValue,ie.DefaultAdditiveValue,a),o.multiplyValue=this.calculateValue(o.multiplyValue,ie.DefaultMultiplyValue,a),o.overwriteValue=this.calculateValue(o.overwriteValue,u,a));continue}let c=h[d].value,g,A,p;switch(h[d].blendType){case 0:g=c,A=ie.DefaultMultiplyValue,p=u;break;case 1:g=ie.DefaultAdditiveValue,A=c,p=u;break;case 2:g=ie.DefaultAdditiveValue,A=ie.DefaultMultiplyValue,p=c;break;default:return}n==0?(o.additiveValue=g,o.multiplyValue=A,o.overwriteValue=p):(o.additiveValue=o.additiveValue*(1-a)+g*a,o.multiplyValue=o.multiplyValue*(1-a)+A*a,o.overwriteValue=o.overwriteValue*(1-a)+p*a)}}getExpressionParameters(){return this._parameters}parse(t,r){let i=G.create(t,r);if(!i)return;let s=i.getRoot();this.setFadeInTime(s.getValueByString(fa).toFloat(Ii)),this.setFadeOutTime(s.getValueByString(Aa).toFloat(Ii));let n=s.getValueByString(Bi).getSize(),a=this._parameters.length;this._parameters.length+=n;for(let l=0;l<n;++l){let o=s.getValueByString(Bi).getValueByIndex(l),u=P.getIdManager().getId(o.getValueByString(pa).getRawString()),h=o.getValueByString(ma).toFloat(),d;o.getValueByString(tt).isNull()||o.getValueByString(tt).getString()==_a?d=0:o.getValueByString(tt).getString()==Ca?d=1:o.getValueByString(tt).getString()==ya?d=2:d=0;let c=new Es;c.parameterId=u,c.blendType=d,c.value=h,this._parameters[a++]=c}G.delete(i)}calculateValue(t,r,i){return t*(1-i)+r*i}constructor(){super(),this._parameters=new Array}_parameters},ba=(function(e){return e[e.Additive=0]="Additive",e[e.Multiply=1]="Multiply",e[e.Overwrite=2]="Overwrite",e})({}),Es=class{parameterId;blendType;value};(function(e){e.CubismExpressionMotion=Te,e.ExpressionBlendType=ba,e.ExpressionParameter=Es})(Si||(Si={}));Ba=(function(e){return e[e.CubismMotionCurveTarget_Model=0]="CubismMotionCurveTarget_Model",e[e.CubismMotionCurveTarget_Parameter=1]="CubismMotionCurveTarget_Parameter",e[e.CubismMotionCurveTarget_PartOpacity=2]="CubismMotionCurveTarget_PartOpacity",e})({}),Ia=(function(e){return e[e.CubismMotionSegmentType_Linear=0]="CubismMotionSegmentType_Linear",e[e.CubismMotionSegmentType_Bezier=1]="CubismMotionSegmentType_Bezier",e[e.CubismMotionSegmentType_Stepped=2]="CubismMotionSegmentType_Stepped",e[e.CubismMotionSegmentType_InverseStepped=3]="CubismMotionSegmentType_InverseStepped",e})({}),ze=class{time=0;value=0},vs=class{constructor(){this.evaluate=null,this.basePointIndex=0,this.segmentType=0}evaluate;basePointIndex;segmentType},Ps=class{constructor(){this.type=0,this.segmentCount=0,this.baseSegmentIndex=0,this.fadeInTime=0,this.fadeOutTime=0}type;id;segmentCount;baseSegmentIndex;fadeInTime;fadeOutTime},Rs=class{fireTime=0;value},Ds=class{constructor(){this.duration=0,this.loop=!1,this.curveCount=0,this.eventCount=0,this.fps=0,this.curves=new Array,this.segments=new Array,this.points=new Array,this.events=new Array}duration;loop;curveCount;eventCount;fps;curves;segments;points;events};(function(e){e.CubismMotionCurve=Ps,e.CubismMotionCurveTarget=Ba,e.CubismMotionData=Ds,e.CubismMotionEvent=Rs,e.CubismMotionPoint=ze,e.CubismMotionSegment=vs,e.CubismMotionSegmentType=Ia})(Mi||(Mi={}));N="Meta",Sa="Duration",Ma="Loop",wa="AreBeziersRestricted",xa="CurveCount",Ea="Fps",va="TotalSegmentCount",Pa="TotalPointCount",he="Curves",Ra="Target",Da="Id",rt="FadeInTime",it="FadeOutTime",wi="Segments",xi="UserData",La="UserDataCount",Ta="TotalUserDataSize",Fa="Time",Oa="Value",Ls=class{constructor(e,t){this._json=G.create(e,t)}release(){G.delete(this._json)}getMotionDuration(){return this._json.getRoot().getValueByString(N).getValueByString(Sa).toFloat()}isMotionLoop(){return this._json.getRoot().getValueByString(N).getValueByString(Ma).toBoolean()}hasConsistency(){let e=!0;if(!this._json||!this._json.getRoot())return!1;let t=this._json.getRoot().getValueByString(he).getVector().length,r=0,i=0;for(let s=0;s<t;++s)for(let n=0;n<this.getMotionCurveSegmentCount(s);){switch(n==0&&(i+=1,n+=2),this.getMotionCurveSegment(s,n)){case 0:i+=1,n+=3;break;case 1:i+=3,n+=7;break;case 2:i+=1,n+=3;break;case 3:i+=1,n+=3;break;default:k(0);break}++r}return t!=this.getMotionCurveCount()&&(O("The number of curves does not match the metadata."),e=!1),r!=this.getMotionTotalSegmentCount()&&(O("The number of segment does not match the metadata."),e=!1),i!=this.getMotionTotalPointCount()&&(O("The number of point does not match the metadata."),e=!1),e}getEvaluationOptionFlag(e){return e==0?this._json.getRoot().getValueByString(N).getValueByString(wa).toBoolean():!1}getMotionCurveCount(){return this._json.getRoot().getValueByString(N).getValueByString(xa).toInt()}getMotionFps(){return this._json.getRoot().getValueByString(N).getValueByString(Ea).toFloat()}getMotionTotalSegmentCount(){return this._json.getRoot().getValueByString(N).getValueByString(va).toInt()}getMotionTotalPointCount(){return this._json.getRoot().getValueByString(N).getValueByString(Pa).toInt()}isExistMotionFadeInTime(){return!this._json.getRoot().getValueByString(N).getValueByString(rt).isNull()}isExistMotionFadeOutTime(){return!this._json.getRoot().getValueByString(N).getValueByString(it).isNull()}getMotionFadeInTime(){return this._json.getRoot().getValueByString(N).getValueByString(rt).toFloat()}getMotionFadeOutTime(){return this._json.getRoot().getValueByString(N).getValueByString(it).toFloat()}getMotionCurveTarget(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(Ra).getRawString()}getMotionCurveId(e){return P.getIdManager().getId(this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(Da).getRawString())}isExistMotionCurveFadeInTime(e){return!this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(rt).isNull()}isExistMotionCurveFadeOutTime(e){return!this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(it).isNull()}getMotionCurveFadeInTime(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(rt).toFloat()}getMotionCurveFadeOutTime(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(it).toFloat()}getMotionCurveSegmentCount(e){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(wi).getVector().length}getMotionCurveSegment(e,t){return this._json.getRoot().getValueByString(he).getValueByIndex(e).getValueByString(wi).getValueByIndex(t).toFloat()}getEventCount(){return this._json.getRoot().getValueByString(N).getValueByString(La).toInt()}getTotalEventValueSize(){return this._json.getRoot().getValueByString(N).getValueByString(Ta).toInt()}getEventTime(e){return this._json.getRoot().getValueByString(xi).getValueByIndex(e).getValueByString(Fa).toFloat()}getEventValue(e){return this._json.getRoot().getValueByString(xi).getValueByIndex(e).getValueByString(Oa).getRawString()}_json};(function(e){e.CubismMotionJson=Ls})(Ei||(Ei={}));Va="EyeBlink",ka="LipSync",Qa="Model",Ua="Parameter",Na="PartOpacity",st="Opacity",Ga=!1;Vs=class ks extends Se{static create(t,r,i,s,n=!1){let a=new ks;if(a.parse(t,r,n),a._motionData)a._sourceFrameRate=a._motionData.fps,a._loopDurationSeconds=a._motionData.duration,a._onFinishedMotion=i,a._onBeganMotion=s;else return Le(a),null;return a}doUpdateParameters(t,r,i,s){this._modelCurveIdEyeBlink==null&&(this._modelCurveIdEyeBlink=P.getIdManager().getId(Va)),this._modelCurveIdLipSync==null&&(this._modelCurveIdLipSync=P.getIdManager().getId(ka)),this._modelCurveIdOpacity==null&&(this._modelCurveIdOpacity=P.getIdManager().getId(st)),this._motionBehavior===1&&this._previousLoopState!==this._isLoop&&(this.adjustEndTime(s),this._previousLoopState=this._isLoop);let n=r-s.getStartTime();n<0&&(n=0);let a=Number.MAX_VALUE,l=Number.MAX_VALUE,o=64,u=0,h=0;this._eyeBlinkParameterIds.length>o&&Ht("too many eye blink targets : {0}",this._eyeBlinkParameterIds.length),this._lipSyncParameterIds.length>o&&Ht("too many lip sync targets : {0}",this._lipSyncParameterIds.length);let d=this._fadeInSeconds<=0?1:M.getEasingSine((r-s.getFadeInStartTime())/this._fadeInSeconds),c=this._fadeOutSeconds<=0||s.getEndTime()<0?1:M.getEasingSine((s.getEndTime()-r)/this._fadeOutSeconds),g,A,p,f=n,_=this._motionData.duration,y=this._motionBehavior===1&&this._isLoop;if(this._isLoop)for(this._motionBehavior===1&&(_+=1/this._motionData.fps);f>_;)f-=_;let C=this._motionData.curves;for(A=0;A<this._motionData.curveCount&&C[A].type==0;++A)g=Ot(this._motionData,A,f,y,_),C[A].id==this._modelCurveIdEyeBlink?l=g:C[A].id==this._modelCurveIdLipSync?a=g:C[A].id==this._modelCurveIdOpacity&&(this._modelOpacity=g,t.setModelOapcity(this.getModelOpacityValue()));let b=0;for(;A<this._motionData.curveCount&&C[A].type==1;++A){if(b++,p=t.getParameterIndex(C[A].id),p==-1)continue;let w=t.getParameterValueByIndex(p);if(g=Ot(this._motionData,A,f,y,_),l!=Number.MAX_VALUE){for(let E=0;E<this._eyeBlinkParameterIds.length&&E<o;++E)if(this._eyeBlinkParameterIds[E]==C[A].id){g*=l,h|=1<<E;break}}if(a!=Number.MAX_VALUE){for(let E=0;E<this._lipSyncParameterIds.length&&E<o;++E)if(this._lipSyncParameterIds[E]==C[A].id){g+=a,u|=1<<E;break}}t.isRepeat(p)&&(g=t.getParameterRepeatValue(p,g));let B;if(C[A].fadeInTime<0&&C[A].fadeOutTime<0)B=w+(g-w)*i;else{let E,T;C[A].fadeInTime<0?E=d:E=C[A].fadeInTime==0?1:M.getEasingSine((r-s.getFadeInStartTime())/C[A].fadeInTime),C[A].fadeOutTime<0?T=c:T=C[A].fadeOutTime==0||s.getEndTime()<0?1:M.getEasingSine((s.getEndTime()-r)/C[A].fadeOutTime);let W=this._weight*E*T;B=w+(g-w)*W}t.setParameterValueByIndex(p,B,1)}if(l!=Number.MAX_VALUE)for(let w=0;w<this._eyeBlinkParameterIds.length&&w<o;++w){let B=t.getParameterValueById(this._eyeBlinkParameterIds[w]);if(h>>w&1)continue;let E=B+(l-B)*i;t.setParameterValueById(this._eyeBlinkParameterIds[w],E)}if(a!=Number.MAX_VALUE)for(let w=0;w<this._lipSyncParameterIds.length&&w<o;++w){let B=t.getParameterValueById(this._lipSyncParameterIds[w]);if(u>>w&1)continue;let E=B+(a-B)*i;t.setParameterValueById(this._lipSyncParameterIds[w],E)}for(;A<this._motionData.curveCount&&C[A].type==2;++A)p=t.getParameterIndex(C[A].id),p!=-1&&(g=Ot(this._motionData,A,f,y,_),t.setParameterValueByIndex(p,g));n>=_&&(this._isLoop?this.updateForNextLoop(s,r,f):(this._onFinishedMotion&&this._onFinishedMotion(this),s.setIsFinished(!0))),this._lastWeight=i}setMotionBehavior(t){this._motionBehavior=t}getMotionBehavior(){return this._motionBehavior}getDuration(){return this._isLoop?-1:this._loopDurationSeconds}getLoopDuration(){return this._loopDurationSeconds}setParameterFadeInTime(t,r){let i=this._motionData.curves;for(let s=0;s<this._motionData.curveCount;++s)if(t==i[s].id){i[s].fadeInTime=r;return}}setParameterFadeOutTime(t,r){let i=this._motionData.curves;for(let s=0;s<this._motionData.curveCount;++s)if(t==i[s].id){i[s].fadeOutTime=r;return}}getParameterFadeInTime(t){let r=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==r[i].id)return r[i].fadeInTime;return-1}getParameterFadeOutTime(t){let r=this._motionData.curves;for(let i=0;i<this._motionData.curveCount;++i)if(t==r[i].id)return r[i].fadeOutTime;return-1}setEffectIds(t,r){this._eyeBlinkParameterIds=t,this._lipSyncParameterIds=r}constructor(){super(),this._sourceFrameRate=30,this._loopDurationSeconds=-1,this._isLoop=!1,this._isLoopFadeIn=!0,this._lastWeight=0,this._motionData=null,this._modelCurveIdEyeBlink=null,this._modelCurveIdLipSync=null,this._modelCurveIdOpacity=null,this._eyeBlinkParameterIds=null,this._lipSyncParameterIds=null,this._modelOpacity=1,this._debugMode=!1}release(){this._motionData=void 0,this._motionData=null}updateForNextLoop(t,r,i){switch(this._motionBehavior){case 1:default:t.setStartTime(r-i),this._isLoopFadeIn&&t.setFadeInStartTime(r-i),this._onFinishedMotion!=null&&this._onFinishedMotion(this);break;case 0:t.setStartTime(r),this._isLoopFadeIn&&t.setFadeInStartTime(r);break}}parse(t,r,i=!1){let s=new Ls(t,r);if(!s){s.release(),s=void 0;return}if(i&&!s.hasConsistency()){s.release(),D("Inconsistent motion3.json.");return}this._motionData=new Ds,this._motionData.duration=s.getMotionDuration(),this._motionData.loop=s.isMotionLoop(),this._motionData.curveCount=s.getMotionCurveCount(),this._motionData.fps=s.getMotionFps(),this._motionData.eventCount=s.getEventCount();let n=s.getEvaluationOptionFlag(0);s.isExistMotionFadeInTime()?this._fadeInSeconds=s.getMotionFadeInTime()<0?1:s.getMotionFadeInTime():this._fadeInSeconds=1,s.isExistMotionFadeOutTime()?this._fadeOutSeconds=s.getMotionFadeOutTime()<0?1:s.getMotionFadeOutTime():this._fadeOutSeconds=1,Q(this._motionData.curves,this._motionData.curveCount,Ps,!0),Q(this._motionData.segments,s.getMotionTotalSegmentCount(),vs,!0),Q(this._motionData.points,s.getMotionTotalPointCount(),ze,!0),Q(this._motionData.events,this._motionData.eventCount,Rs,!0);let a=0,l=0;for(let o=0;o<this._motionData.curveCount;++o){s.getMotionCurveTarget(o)==Qa?this._motionData.curves[o].type=0:s.getMotionCurveTarget(o)==Ua?this._motionData.curves[o].type=1:s.getMotionCurveTarget(o)==Na?this._motionData.curves[o].type=2:O('Warning : Unable to get segment type from Curve! The number of "CurveCount" may be incorrect!'),this._motionData.curves[o].id=s.getMotionCurveId(o),this._motionData.curves[o].baseSegmentIndex=l,this._motionData.curves[o].fadeInTime=s.isExistMotionCurveFadeInTime(o)?s.getMotionCurveFadeInTime(o):-1,this._motionData.curves[o].fadeOutTime=s.isExistMotionCurveFadeOutTime(o)?s.getMotionCurveFadeOutTime(o):-1;for(let u=0;u<s.getMotionCurveSegmentCount(o);){switch(u==0?(this._motionData.segments[l].basePointIndex=a,this._motionData.points[a].time=s.getMotionCurveSegment(o,u),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+1),a+=1,u+=2):this._motionData.segments[l].basePointIndex=a-1,s.getMotionCurveSegment(o,u)){case 0:this._motionData.segments[l].segmentType=0,this._motionData.segments[l].evaluate=Ts,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),a+=1,u+=3;break;case 1:this._motionData.segments[l].segmentType=1,n||Ga?this._motionData.segments[l].evaluate=Xa:this._motionData.segments[l].evaluate=Ha,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),this._motionData.points[a+1].time=s.getMotionCurveSegment(o,u+3),this._motionData.points[a+1].value=s.getMotionCurveSegment(o,u+4),this._motionData.points[a+2].time=s.getMotionCurveSegment(o,u+5),this._motionData.points[a+2].value=s.getMotionCurveSegment(o,u+6),a+=3,u+=7;break;case 2:this._motionData.segments[l].segmentType=2,this._motionData.segments[l].evaluate=Fs,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),a+=1,u+=3;break;case 3:this._motionData.segments[l].segmentType=3,this._motionData.segments[l].evaluate=Os,this._motionData.points[a].time=s.getMotionCurveSegment(o,u+1),this._motionData.points[a].value=s.getMotionCurveSegment(o,u+2),a+=1,u+=3;break;default:k(0);break}++this._motionData.curves[o].segmentCount,++l}}for(let o=0;o<s.getEventCount();++o)this._motionData.events[o].fireTime=s.getEventTime(o),this._motionData.events[o].value=s.getEventValue(o);s.release(),s=void 0,s=null}getFiredEvent(t,r){Q(this._firedEventValues,0);for(let i=0;i<this._motionData.eventCount;++i)this._motionData.events[i].fireTime>t&&this._motionData.events[i].fireTime<=r&&this._firedEventValues.push(this._motionData.events[i].value);return this._firedEventValues}isExistModelOpacity(){for(let t=0;t<this._motionData.curveCount;t++){let r=this._motionData.curves[t];if(r.type==0&&r.id.getString().localeCompare(st)==0)return!0}return!1}getModelOpacityIndex(){if(this.isExistModelOpacity())for(let t=0;t<this._motionData.curveCount;t++){let r=this._motionData.curves[t];if(r.type==0&&r.id.getString().localeCompare(st)==0)return t}return-1}getModelOpacityId(t){if(t!=-1){let r=this._motionData.curves[t];if(r.type==0&&r.id.getString().localeCompare(st)==0)return P.getIdManager().getId(r.id.getString())}return null}getModelOpacityValue(){return this._modelOpacity}setDebugMode(t){this._debugMode=t}_sourceFrameRate;_loopDurationSeconds;_motionBehavior=1;_lastWeight;_motionData;_eyeBlinkParameterIds;_lipSyncParameterIds;_modelCurveIdEyeBlink;_modelCurveIdLipSync;_modelCurveIdOpacity;_modelOpacity;_debugMode};(function(e){e.CubismMotion=Vs})(vi||(vi={}));Qs=class extends or{constructor(){super(),this._currentPriority=0,this._reservePriority=0}getCurrentPriority(){return this._currentPriority}getReservePriority(){return this._reservePriority}setReservePriority(e){this._reservePriority=e}startMotionPriority(e,t,r){return r==this._reservePriority&&(this._reservePriority=0),this._currentPriority=r,super.startMotion(e,t)}updateMotion(e,t){this._userTimeSeconds+=t;let r=super.doUpdateMotion(e,this._userTimeSeconds);return this.isFinished()&&(this._currentPriority=0),r}reserveMotion(e){return e<=this._reservePriority||e<=this._currentPriority?!1:(this._reservePriority=e,!0)}_currentPriority;_reservePriority};(function(e){e.CubismMotionManager=Qs})(Pi||(Pi={}));Ya=(function(e){return e[e.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",e})({}),za=(function(e){return e[e.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",e[e.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",e[e.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",e})({}),Ja=class{constructor(){this.gravity=new x(0,0),this.wind=new x(0,0)}gravity;wind},lr=class{id;targetType},Zt=class{minimum;maximum;defalut},Us=class{constructor(){this.initialPosition=new x(0,0),this.position=new x(0,0),this.lastPosition=new x(0,0),this.lastGravity=new x(0,0),this.force=new x(0,0),this.velocity=new x(0,0)}initialPosition;mobility;delay;acceleration;radius;position;lastPosition;lastGravity;force;velocity},Ns=class{constructor(){this.normalizationPosition=new Zt,this.normalizationAngle=new Zt}inputCount;outputCount;particleCount;baseInputIndex;baseOutputIndex;baseParticleIndex;normalizationPosition;normalizationAngle},Gs=class{constructor(){this.source=new lr}source;sourceParameterIndex;weight;type;reflect;getNormalizedParameterValue},Xs=class{constructor(){this.destination=new lr,this.translationScale=new x(0,0)}destination;destinationParameterIndex;vertexIndex;translationScale;angleScale;weight;type;reflect;valueBelowMinimum;valueExceededMaximum;getValue;getScale},Hs=class{constructor(){this.settings=new Array,this.inputs=new Array,this.outputs=new Array,this.particles=new Array,this.gravity=new x(0,0),this.wind=new x(0,0),this.fps=0}subRigCount;settings;inputs;outputs;particles;gravity;wind;fps};(function(e){e.CubismPhysicsInput=Gs,e.CubismPhysicsNormalization=Zt,e.CubismPhysicsOutput=Xs,e.CubismPhysicsParameter=lr,e.CubismPhysicsParticle=Us,e.CubismPhysicsRig=Hs,e.CubismPhysicsSource=za,e.CubismPhysicsSubRig=Ns,e.CubismPhysicsTargetType=Ya,e.PhysicsJsonEffectiveForces=Ja})(Ri||(Ri={}));Xe="Position",Vt="X",kt="Y",Qt="Angle",Di="Type",Li="Id",ce="Meta",nt="EffectiveForces",ja="TotalInputCount",Za="TotalOutputCount",qa="PhysicsSettingCount",Ti="Gravity",Fi="Wind",Ka="VertexCount",$a="Fps",L="PhysicsSettings",ve="Normalization",Oi="Minimum",Vi="Maximum",ki="Default",Qi="Reflect",Ui="Weight",He="Input",eo="Source",ye="Output",to="Scale",ro="VertexIndex",io="Destination",be="Vertices",so="Mobility",no="Delay",ao="Radius",oo="Acceleration",Ws=class{constructor(e,t){this._json=G.create(e,t)}release(){G.delete(this._json)}getGravity(){let e=new x(0,0);return e.x=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Ti).getValueByString(Vt).toFloat(),e.y=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Ti).getValueByString(kt).toFloat(),e}getWind(){let e=new x(0,0);return e.x=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Fi).getValueByString(Vt).toFloat(),e.y=this._json.getRoot().getValueByString(ce).getValueByString(nt).getValueByString(Fi).getValueByString(kt).toFloat(),e}getFps(){return this._json.getRoot().getValueByString(ce).getValueByString($a).toFloat(0)}getSubRigCount(){return this._json.getRoot().getValueByString(ce).getValueByString(qa).toInt()}getTotalInputCount(){return this._json.getRoot().getValueByString(ce).getValueByString(ja).toInt()}getTotalOutputCount(){return this._json.getRoot().getValueByString(ce).getValueByString(Za).toInt()}getVertexCount(){return this._json.getRoot().getValueByString(ce).getValueByString(Ka).toInt()}getNormalizationPositionMinimumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Xe).getValueByString(Oi).toFloat()}getNormalizationPositionMaximumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Xe).getValueByString(Vi).toFloat()}getNormalizationPositionDefaultValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Xe).getValueByString(ki).toFloat()}getNormalizationAngleMinimumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Qt).getValueByString(Oi).toFloat()}getNormalizationAngleMaximumValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Qt).getValueByString(Vi).toFloat()}getNormalizationAngleDefaultValue(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ve).getValueByString(Qt).getValueByString(ki).toFloat()}getInputCount(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getVector().length}getInputWeight(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(Ui).toFloat()}getInputReflect(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(Qi).toBoolean()}getInputType(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(Di).getRawString()}getInputSourceId(e,t){return P.getIdManager().getId(this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(He).getValueByIndex(t).getValueByString(eo).getValueByString(Li).getRawString())}getOutputCount(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getVector().length}getOutputVertexIndex(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(ro).toInt()}getOutputAngleScale(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(to).toFloat()}getOutputWeight(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(Ui).toFloat()}getOutputDestinationId(e,t){return P.getIdManager().getId(this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(io).getValueByString(Li).getRawString())}getOutputType(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(Di).getRawString()}getOutputReflect(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(ye).getValueByIndex(t).getValueByString(Qi).toBoolean()}getParticleCount(e){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getVector().length}getParticleMobility(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(so).toFloat()}getParticleDelay(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(no).toFloat()}getParticleAcceleration(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(oo).toFloat()}getParticleRadius(e,t){return this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(ao).toFloat()}getParticlePosition(e,t){let r=new x(0,0);return r.x=this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(Xe).getValueByString(Vt).toFloat(),r.y=this._json.getRoot().getValueByString(L).getValueByIndex(e).getValueByString(be).getValueByIndex(t).getValueByString(Xe).getValueByString(kt).toFloat(),r}_json};(function(e){e.CubismPhysicsJson=Ws})(Ni||(Ni={}));Gi="X",Xi="Y",Hi="Angle",lo=5,qt=100,Wi=.001,uo=5,Kt=class Ys{static create(t,r){let i=new Ys;return i.parse(t,r),i._physicsRig.gravity.y=0,i}static delete(t){t!=null&&(t.release(),t=null)}parse(t,r){this._physicsRig=new Hs;let i=new Ws(t,r);this._physicsRig.gravity=i.getGravity(),this._physicsRig.wind=i.getWind(),this._physicsRig.subRigCount=i.getSubRigCount(),this._physicsRig.fps=i.getFps(),Q(this._physicsRig.settings,this._physicsRig.subRigCount,Ns,!0),Q(this._physicsRig.inputs,i.getTotalInputCount(),Gs,!0),Q(this._physicsRig.outputs,i.getTotalOutputCount(),Xs,!0),Q(this._physicsRig.particles,i.getVertexCount(),Us,!0),this._currentRigOutputs.length=0,this._previousRigOutputs.length=0;let s=0,n=0,a=0,l=this._currentRigOutputs.length,o=this._previousRigOutputs.length;this._currentRigOutputs.length+=this._physicsRig.settings.length,this._previousRigOutputs.length+=this._physicsRig.settings.length;for(let u=0;u<this._physicsRig.settings.length;++u){this._physicsRig.settings[u].normalizationPosition.minimum=i.getNormalizationPositionMinimumValue(u),this._physicsRig.settings[u].normalizationPosition.maximum=i.getNormalizationPositionMaximumValue(u),this._physicsRig.settings[u].normalizationPosition.defalut=i.getNormalizationPositionDefaultValue(u),this._physicsRig.settings[u].normalizationAngle.minimum=i.getNormalizationAngleMinimumValue(u),this._physicsRig.settings[u].normalizationAngle.maximum=i.getNormalizationAngleMaximumValue(u),this._physicsRig.settings[u].normalizationAngle.defalut=i.getNormalizationAngleDefaultValue(u),this._physicsRig.settings[u].inputCount=i.getInputCount(u),this._physicsRig.settings[u].baseInputIndex=s;for(let c=0;c<this._physicsRig.settings[u].inputCount;++c)this._physicsRig.inputs[s+c].sourceParameterIndex=-1,this._physicsRig.inputs[s+c].weight=i.getInputWeight(u,c),this._physicsRig.inputs[s+c].reflect=i.getInputReflect(u,c),i.getInputType(u,c)==Gi?(this._physicsRig.inputs[s+c].type=0,this._physicsRig.inputs[s+c].getNormalizedParameterValue=co):i.getInputType(u,c)==Xi?(this._physicsRig.inputs[s+c].type=1,this._physicsRig.inputs[s+c].getNormalizedParameterValue=go):i.getInputType(u,c)==Hi&&(this._physicsRig.inputs[s+c].type=2,this._physicsRig.inputs[s+c].getNormalizedParameterValue=fo),this._physicsRig.inputs[s+c].source.targetType=0,this._physicsRig.inputs[s+c].source.id=i.getInputSourceId(u,c);s+=this._physicsRig.settings[u].inputCount,this._physicsRig.settings[u].outputCount=i.getOutputCount(u),this._physicsRig.settings[u].baseOutputIndex=n;let h=new Yi;Q(h.outputs,this._physicsRig.settings[u].outputCount,null,!0);let d=new Yi;Q(d.outputs,this._physicsRig.settings[u].outputCount,null,!0);for(let c=0;c<this._physicsRig.settings[u].outputCount;++c)h.outputs[c]=0,d.outputs[c]=0,this._physicsRig.outputs[n+c].destinationParameterIndex=-1,this._physicsRig.outputs[n+c].vertexIndex=i.getOutputVertexIndex(u,c),this._physicsRig.outputs[n+c].angleScale=i.getOutputAngleScale(u,c),this._physicsRig.outputs[n+c].weight=i.getOutputWeight(u,c),this._physicsRig.outputs[n+c].destination.targetType=0,this._physicsRig.outputs[n+c].destination.id=i.getOutputDestinationId(u,c),i.getOutputType(u,c)==Gi?(this._physicsRig.outputs[n+c].type=0,this._physicsRig.outputs[n+c].getValue=Ao,this._physicsRig.outputs[n+c].getScale=yo):i.getOutputType(u,c)==Xi?(this._physicsRig.outputs[n+c].type=1,this._physicsRig.outputs[n+c].getValue=po,this._physicsRig.outputs[n+c].getScale=bo):i.getOutputType(u,c)==Hi&&(this._physicsRig.outputs[n+c].type=2,this._physicsRig.outputs[n+c].getValue=mo,this._physicsRig.outputs[n+c].getScale=Bo),this._physicsRig.outputs[n+c].reflect=i.getOutputReflect(u,c);this._currentRigOutputs[l++]=h,this._previousRigOutputs[o++]=d,n+=this._physicsRig.settings[u].outputCount,this._physicsRig.settings[u].particleCount=i.getParticleCount(u),this._physicsRig.settings[u].baseParticleIndex=a;for(let c=0;c<this._physicsRig.settings[u].particleCount;++c)this._physicsRig.particles[a+c].mobility=i.getParticleMobility(u,c),this._physicsRig.particles[a+c].delay=i.getParticleDelay(u,c),this._physicsRig.particles[a+c].acceleration=i.getParticleAcceleration(u,c),this._physicsRig.particles[a+c].radius=i.getParticleRadius(u,c),this._physicsRig.particles[a+c].position=i.getParticlePosition(u,c);a+=this._physicsRig.settings[u].particleCount}this._inputSlices.length=this._physicsRig.subRigCount,this._outputSlices.length=this._physicsRig.subRigCount,this._particleSlices.length=this._physicsRig.subRigCount;for(let u=0;u<this._physicsRig.subRigCount;++u){let h=this._physicsRig.settings[u];this._inputSlices[u]=this._physicsRig.inputs.slice(h.baseInputIndex,h.baseInputIndex+h.inputCount),this._outputSlices[u]=this._physicsRig.outputs.slice(h.baseOutputIndex,h.baseOutputIndex+h.outputCount),this._particleSlices[u]=this._physicsRig.particles.slice(h.baseParticleIndex,h.baseParticleIndex+h.particleCount)}this.initialize(),i.release(),i=void 0,i=null}stabilization(t){let r,i,s,n,a=new x,l,o,u,h,d=t.getModel().parameters.values,c=t.getModel().parameters.maximumValues,g=t.getModel().parameters.minimumValues,A=t.getModel().parameters.defaultValues;(this._parameterCaches?.length??0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(this._parameterInputCaches?.length??0)<t.getParameterCount()&&(this._parameterInputCaches=new Float32Array(t.getParameterCount()));for(let p=0;p<t.getParameterCount();++p)this._parameterCaches[p]=d[p],this._parameterInputCaches[p]=d[p];for(let p=0;p<this._physicsRig.subRigCount;++p){r={angle:0},a.x=0,a.y=0,l=this._physicsRig.settings[p],o=this._inputSlices[p],u=this._outputSlices[p],h=this._particleSlices[p];for(let f=0;f<l.inputCount;++f)i=o[f].weight/qt,o[f].sourceParameterIndex==-1&&(o[f].sourceParameterIndex=t.getParameterIndex(o[f].source.id)),o[f].getNormalizedParameterValue(a,r,d[o[f].sourceParameterIndex],g[o[f].sourceParameterIndex],c[o[f].sourceParameterIndex],A[o[f].sourceParameterIndex],l.normalizationPosition,l.normalizationAngle,o[f].reflect,i),this._parameterCaches[o[f].sourceParameterIndex]=d[o[f].sourceParameterIndex];s=M.degreesToRadian(-r.angle),a.x=a.x*M.cos(s)-a.y*M.sin(s),a.y=a.x*M.sin(s)+a.y*M.cos(s),So(h,l.particleCount,a,r.angle,this._options.wind,Wi*l.normalizationPosition.maximum);for(let f=0;f<l.outputCount;++f){let _=u[f].vertexIndex;if(u[f].destinationParameterIndex==-1&&(u[f].destinationParameterIndex=t.getParameterIndex(u[f].destination.id)),_<1||_>=l.particleCount)continue;let y=new x;y=h[_].position.substract(h[_-1].position),n=u[f].getValue(y,h,_,u[f].reflect,this._options.gravity),this._currentRigOutputs[p].outputs[f]=n,this._previousRigOutputs[p].outputs[f]=n;let C=u[f].destinationParameterIndex;Ut(d,C,g[C],c[C],n,u[f]),this._parameterCaches[C]=d[C]}}}evaluate(t,r){let i,s,n,a,l=new x,o,u,h,d;if(0>=r)return;let c=t.getModel().parameters.values,g=t.getModel().parameters.maximumValues,A=t.getModel().parameters.minimumValues,p=t.getModel().parameters.defaultValues,f;if(this._currentRemainTime+=r,this._currentRemainTime>uo&&(this._currentRemainTime=0),(this._parameterCaches?.length??0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),(this._parameterInputCaches?.length??0)<t.getParameterCount()){this._parameterInputCaches=new Float32Array(t.getParameterCount());for(let y=0;y<t.getParameterCount();++y)this._parameterInputCaches[y]=c[y]}for(this._physicsRig.fps>0?f=1/this._physicsRig.fps:f=r;this._currentRemainTime>=f;){for(let C=0;C<this._physicsRig.subRigCount;++C){o=this._physicsRig.settings[C],h=this._outputSlices[C];for(let b=0;b<o.outputCount;++b)this._previousRigOutputs[C].outputs[b]=this._currentRigOutputs[C].outputs[b]}let y=f/this._currentRemainTime;for(let C=0;C<t.getParameterCount();++C)this._parameterCaches[C]=this._parameterInputCaches[C]*(1-y)+c[C]*y,this._parameterInputCaches[C]=this._parameterCaches[C];for(let C=0;C<this._physicsRig.subRigCount;++C){i={angle:0},l.x=0,l.y=0,o=this._physicsRig.settings[C],u=this._inputSlices[C],h=this._outputSlices[C],d=this._particleSlices[C];for(let b=0;b<o.inputCount;++b)s=u[b].weight/qt,u[b].sourceParameterIndex==-1&&(u[b].sourceParameterIndex=t.getParameterIndex(u[b].source.id)),u[b].getNormalizedParameterValue(l,i,this._parameterCaches[u[b].sourceParameterIndex],A[u[b].sourceParameterIndex],g[u[b].sourceParameterIndex],p[u[b].sourceParameterIndex],o.normalizationPosition,o.normalizationAngle,u[b].reflect,s);n=M.degreesToRadian(-i.angle),l.x=l.x*M.cos(n)-l.y*M.sin(n),l.y=l.x*M.sin(n)+l.y*M.cos(n),Io(d,o.particleCount,l,i.angle,this._options.wind,Wi*o.normalizationPosition.maximum,f,lo);for(let b=0;b<o.outputCount;++b){let w=h[b].vertexIndex;if(h[b].destinationParameterIndex==-1&&(h[b].destinationParameterIndex=t.getParameterIndex(h[b].destination.id)),w<1||w>=o.particleCount)continue;let B=new x;B.x=d[w].position.x-d[w-1].position.x,B.y=d[w].position.y-d[w-1].position.y,a=h[b].getValue(B,d,w,h[b].reflect,this._options.gravity),this._currentRigOutputs[C].outputs[b]=a;let E=h[b].destinationParameterIndex;Ut(this._parameterCaches,E,A[E],g[E],a,h[b])}}this._currentRemainTime-=f}let _=this._currentRemainTime/f;this.interpolate(t,_)}interpolate(t,r){let i,s,n=t.getModel().parameters.values,a=t.getModel().parameters.maximumValues,l=t.getModel().parameters.minimumValues;for(let o=0;o<this._physicsRig.subRigCount;++o){s=this._physicsRig.settings[o],i=this._outputSlices[o];for(let u=0;u<s.outputCount;++u){if(i[u].destinationParameterIndex==-1)continue;let h=i[u].destinationParameterIndex;Ut(n,h,l[h],a[h],this._previousRigOutputs[o].outputs[u]*(1-r)+this._currentRigOutputs[o].outputs[u]*r,i[u])}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._physicsRig=null,this._options=new zs,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=new Array,this._previousRigOutputs=new Array,this._inputSlices=new Array,this._outputSlices=new Array,this._particleSlices=new Array,this._currentRemainTime=0,this._parameterCaches=null,this._parameterInputCaches=null}release(){this._inputSlices.length=0,this._outputSlices.length=0,this._particleSlices.length=0,this._physicsRig=void 0,this._physicsRig=null}initialize(){let t,r,i;for(let s=0;s<this._physicsRig.subRigCount;++s){r=this._physicsRig.settings[s],t=this._particleSlices[s],t[0].initialPosition=new x(0,0),t[0].lastPosition=new x(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new x(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new x(0,0),t[0].force=new x(0,0);for(let n=1;n<r.particleCount;++n)i=new x(0,0),i.y=t[n].radius,t[n].initialPosition=new x(t[n-1].initialPosition.x+i.x,t[n-1].initialPosition.y+i.y),t[n].position=new x(t[n].initialPosition.x,t[n].initialPosition.y),t[n].lastPosition=new x(t[n].initialPosition.x,t[n].initialPosition.y),t[n].lastGravity=new x(0,-1),t[n].lastGravity.y*=-1,t[n].velocity=new x(0,0),t[n].force=new x(0,0)}}_physicsRig;_options;_currentRigOutputs;_previousRigOutputs;_inputSlices;_outputSlices;_particleSlices;_currentRemainTime;_parameterCaches;_parameterInputCaches},zs=class{constructor(){this.gravity=new x(0,0),this.wind=new x(0,0)}gravity;wind},Yi=class{constructor(){this.outputs=new Array(0)}outputs};(function(e){e.CubismPhysics=Kt,e.Options=zs})(zi||(zi={}));Nt=4,Mo=36,wo=32,xo=class{constructor(e){this._renderTextureCount=0,this._clippingMaskBufferSize=256,this._clippingContextListForMask=new Array,this._clippingContextListForDraw=new Array,this._clippingContextListForOffscreen=new Array,this._tmpBoundsOnModel=new dt,this._tmpMatrix=new ne,this._tmpMatrixForMask=new ne,this._tmpMatrixForDraw=new ne,this._clearedMaskBufferFlags=new Array,this._clippingContexttConstructor=e,this._channelColors=[new R(1,0,0,0),new R(0,1,0,0),new R(0,0,1,0),new R(0,0,0,1)]}release(){for(let e=0;e<this._clippingContextListForMask.length;e++)this._clippingContextListForMask[e]&&(this._clippingContextListForMask[e].release(),this._clippingContextListForMask[e]=void 0),this._clippingContextListForMask[e]=null;this._clippingContextListForMask=null;for(let e=0;e<this._clippingContextListForDraw.length;e++)this._clippingContextListForDraw[e]=null;this._clippingContextListForDraw=null;for(let e=0;e<this._channelColors.length;e++)this._channelColors[e]=null;this._channelColors=null,this._clearedMaskBufferFlags!=null&&(this._clearedMaskBufferFlags.length=0),this._clearedMaskBufferFlags=null}initializeForDrawable(e,t){t%1!=0&&(O("The number of render textures must be specified as an integer. The decimal point is rounded down and corrected to an integer."),t=~~t),t<1&&O("The number of render textures must be an integer greater than or equal to 1. Set the number of render textures to 1."),this._renderTextureCount=t<1?1:t,this._clearedMaskBufferFlags=new Array(this._renderTextureCount),this._clippingContextListForDraw.length=e.getDrawableCount();for(let r=0;r<e.getDrawableCount();r++){if(e.getDrawableMaskCounts()[r]<=0){this._clippingContextListForDraw[r]=null;continue}let i=this.findSameClip(e.getDrawableMasks()[r],e.getDrawableMaskCounts()[r]);i==null&&(i=new this._clippingContexttConstructor(this,e.getDrawableMasks()[r],e.getDrawableMaskCounts()[r]),this._clippingContextListForMask.push(i)),i.addClippedDrawable(r),this._clippingContextListForDraw[r]=i}}initializeForOffscreen(e,t){this._renderTextureCount=t,this._clearedMaskBufferFlags.length=this._renderTextureCount;for(let r=0;r<this._renderTextureCount;++r)this._clearedMaskBufferFlags[r]=!1;this._clippingContextListForOffscreen.length=e.getOffscreenCount();for(let r=0;r<e.getOffscreenCount();++r){if(e.getOffscreenMaskCounts()[r]<=0){this._clippingContextListForOffscreen.push(null);continue}let i=this.findSameClip(e.getOffscreenMasks()[r],e.getOffscreenMaskCounts()[r]);i==null&&(i=new this._clippingContexttConstructor(this,e.getOffscreenMasks()[r],e.getOffscreenMaskCounts()[r]),this._clippingContextListForMask.push(i)),i.addClippedOffscreen(r),this._clippingContextListForOffscreen[r]=i}}findSameClip(e,t){for(let r=0;r<this._clippingContextListForMask.length;r++){let i=this._clippingContextListForMask[r],s=i._clippingIdCount;if(s!=t)continue;let n=0;for(let a=0;a<s;a++){let l=i._clippingIdList[a];for(let o=0;o<s;o++)if(e[o]==l){n++;break}}if(n==s)return i}return null}setupMatrixForHighPrecision(e,t){let r=0;for(let i=0;i<this._clippingContextListForMask.length;i++){let s=this._clippingContextListForMask[i];this.calcClippedDrawableTotalBounds(e,s),s._isUsing&&r++}if(r>0){if(this.setupLayoutBounds(0),this._clearedMaskBufferFlags.length!=this._renderTextureCount){this._clearedMaskBufferFlags.length=this._renderTextureCount;for(let i=0;i<this._renderTextureCount;i++)this._clearedMaskBufferFlags[i]=!1}else for(let i=0;i<this._renderTextureCount;i++)this._clearedMaskBufferFlags[i]=!1;for(let i=0;i<this._clippingContextListForMask.length;i++){let s=this._clippingContextListForMask[i],n=s._allClippedDrawRect,a=s._layoutBounds,l=.05,o=0,u=0,h=e.getPixelsPerUnit(),d=s.getClippingManager().getClippingMaskBufferSize(),c=a.width*d,g=a.height*d;this._tmpBoundsOnModel.setRect(n),this._tmpBoundsOnModel.width*h>c?(this._tmpBoundsOnModel.expand(n.width*l,0),o=a.width/this._tmpBoundsOnModel.width):o=h/c,this._tmpBoundsOnModel.height*h>g?(this._tmpBoundsOnModel.expand(0,n.height*l),u=a.height/this._tmpBoundsOnModel.height):u=h/g,this.createMatrixForMask(t,a,o,u),s._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),s._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray())}}}setupMatrixForOffscreenHighPrecision(e,t,r){let i=0;for(let s=0;s<this._clippingContextListForMask.length;s++){let n=this._clippingContextListForMask[s];this.calcClippedOffscreenTotalBounds(e,n),n._isUsing&&i++}if(!(i<=0)){if(this.setupLayoutBounds(0),this._clearedMaskBufferFlags.length!=this._renderTextureCount){this._clearedMaskBufferFlags.length=this._renderTextureCount;for(let s=0;s<this._renderTextureCount;++s)this._clearedMaskBufferFlags[s]=!1}else for(let s=0;s<this._renderTextureCount;++s)this._clearedMaskBufferFlags[s]=!1;for(let s=0;s<this._clippingContextListForMask.length;s++){let n=this._clippingContextListForMask[s],a=n._allClippedDrawRect,l=n._layoutBounds,o=.05,u=0,h=0,d=e.getPixelsPerUnit(),c=n.getClippingManager().getClippingMaskBufferSize(),g=l.width*c,A=l.height*c;this._tmpBoundsOnModel.setRect(a),this._tmpBoundsOnModel.width*d>g?(this._tmpBoundsOnModel.expand(a.width*o,0),u=l.width/this._tmpBoundsOnModel.width):u=d/g,this._tmpBoundsOnModel.height*d>A?(this._tmpBoundsOnModel.expand(0,a.height*o),h=l.height/this._tmpBoundsOnModel.height):h=d/A,this.createMatrixForMask(t,l,u,h),n._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),n._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray());let p=r.getInvert();n._matrixForDraw.multiplyByMatrix(p)}}}calcClippedOffscreenTotalBounds(e,t){let r=Number.MAX_VALUE,i=Number.MAX_VALUE,s=-Number.MAX_VALUE,n=-Number.MAX_VALUE,a=t._clippedOffscreenIndexList.length,l=new Array;for(let u=0;u<a;u++){let h=t._clippedOffscreenIndexList[u];this.getOffscreenChildDrawableIndexList(e,h,l)}let o=l.length;for(let u=0;u<o;u++){let h=e.getDrawableVertexCount(l[u]),d=e.getDrawableVertices(l[u]),c=Number.MAX_VALUE,g=Number.MAX_VALUE,A=-Number.MAX_VALUE,p=-Number.MAX_VALUE,f=h*$.vertexStep;for(let _=$.vertexOffset;_<f;_+=$.vertexStep){let y=d[_],C=d[_+1];y<c&&(c=y),y>A&&(A=y),C<g&&(g=C),C>p&&(p=C)}c!=Number.MAX_VALUE&&(c<r&&(r=c),g<i&&(i=g),A>s&&(s=A),p>n&&(n=p))}if(r==Number.MAX_VALUE)t._allClippedDrawRect.x=0,t._allClippedDrawRect.y=0,t._allClippedDrawRect.width=0,t._allClippedDrawRect.height=0,t._isUsing=!1;else{t._isUsing=!0;let u=s-r,h=n-i;t._allClippedDrawRect.x=r,t._allClippedDrawRect.y=i,t._allClippedDrawRect.width=u,t._allClippedDrawRect.height=h}}getOffscreenChildDrawableIndexList(e,t,r){let i=e.getOffscreenOwnerIndices()[t];this.getPartChildDrawableIndexList(e,i,r)}getPartChildDrawableIndexList(e,t,r){let i=e.getPartsHierarchy()[t].childDrawObjects;r.push(...i.drawableIndices);for(let s=0;s<i.offscreenIndices.length;++s)this.getOffscreenChildDrawableIndexList(e,i.offscreenIndices[s],r)}createMatrixForMask(e,t,r,i){this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(-1,-1),this._tmpMatrix.scaleRelative(2,2),this._tmpMatrix.translateRelative(t.x,t.y),this._tmpMatrix.scaleRelative(r,i),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForMask.setMatrix(this._tmpMatrix.getArray()),this._tmpMatrix.loadIdentity(),this._tmpMatrix.translateRelative(t.x,t.y*(e?-1:1)),this._tmpMatrix.scaleRelative(r,i*(e?-1:1)),this._tmpMatrix.translateRelative(-this._tmpBoundsOnModel.x,-this._tmpBoundsOnModel.y),this._tmpMatrixForDraw.setMatrix(this._tmpMatrix.getArray())}setupLayoutBounds(e){let t=this._renderTextureCount<=1?Mo:wo*this._renderTextureCount;if(e<=0||e>t){e>t&&D(`not supported mask count : {0}
19
+ [Details] render texture count : {1}, mask count : {2}`,e-t,this._renderTextureCount,e);for(let o=0;o<this._clippingContextListForMask.length;o++){let u=this._clippingContextListForMask[o];u._layoutChannelIndex=0,u._layoutBounds.x=0,u._layoutBounds.y=0,u._layoutBounds.width=1,u._layoutBounds.height=1,u._bufferIndex=0}return}let r=this._renderTextureCount<=1?9:8,i=e/this._renderTextureCount,s=e%this._renderTextureCount;i=Math.ceil(i);let n=i/Nt,a=i%Nt;n=~~n;let l=0;for(let o=0;o<this._renderTextureCount;o++)for(let u=0;u<Nt;u++){let h=n+(u<a?1:0),d=a+(n<1?-1:0);if(u==d&&s>0&&(h-=o<s?0:1),h!=0)if(h==1){let c=this._clippingContextListForMask[l++];c._layoutChannelIndex=u,c._layoutBounds.x=0,c._layoutBounds.y=0,c._layoutBounds.width=1,c._layoutBounds.height=1,c._bufferIndex=o}else if(h==2)for(let c=0;c<h;c++){let g=c%2;g=~~g;let A=this._clippingContextListForMask[l++];A._layoutChannelIndex=u,A._layoutBounds.x=g*.5,A._layoutBounds.y=0,A._layoutBounds.width=.5,A._layoutBounds.height=1,A._bufferIndex=o}else if(h<=4)for(let c=0;c<h;c++){let g=c%2,A=c/2;g=~~g,A=~~A;let p=this._clippingContextListForMask[l++];p._layoutChannelIndex=u,p._layoutBounds.x=g*.5,p._layoutBounds.y=A*.5,p._layoutBounds.width=.5,p._layoutBounds.height=.5,p._bufferIndex=o}else if(h<=r)for(let c=0;c<h;c++){let g=c%3,A=c/3;g=~~g,A=~~A;let p=this._clippingContextListForMask[l++];p._layoutChannelIndex=u,p._layoutBounds.x=g/3,p._layoutBounds.y=A/3,p._layoutBounds.width=1/3,p._layoutBounds.height=1/3,p._bufferIndex=o}else{D(`not supported mask count : {0}
20
+ [Details] render texture count : {1}, mask count : {2}`,e-t,this._renderTextureCount,e);for(let c=0;c<h;c++){let g=this._clippingContextListForMask[l++];g._layoutChannelIndex=0,g._layoutBounds.x=0,g._layoutBounds.y=0,g._layoutBounds.width=1,g._layoutBounds.height=1,g._bufferIndex=0}}}}calcClippedDrawableTotalBounds(e,t){let r=Number.MAX_VALUE,i=Number.MAX_VALUE,s=Number.MIN_VALUE,n=Number.MIN_VALUE,a=t._clippedDrawableIndexList.length;for(let l=0;l<a;l++){let o=t._clippedDrawableIndexList[l],u=e.getDrawableVertexCount(o),h=e.getDrawableVertices(o),d=Number.MAX_VALUE,c=Number.MAX_VALUE,g=-Number.MAX_VALUE,A=-Number.MAX_VALUE,p=u*$.vertexStep;for(let f=$.vertexOffset;f<p;f+=$.vertexStep){let _=h[f],y=h[f+1];_<d&&(d=_),_>g&&(g=_),y<c&&(c=y),y>A&&(A=y)}if(d!=Number.MAX_VALUE)if(d<r&&(r=d),c<i&&(i=c),g>s&&(s=g),A>n&&(n=A),r==Number.MAX_VALUE)t._allClippedDrawRect.x=0,t._allClippedDrawRect.y=0,t._allClippedDrawRect.width=0,t._allClippedDrawRect.height=0,t._isUsing=!1;else{t._isUsing=!0;let f=s-r,_=n-i;t._allClippedDrawRect.x=r,t._allClippedDrawRect.y=i,t._allClippedDrawRect.width=f,t._allClippedDrawRect.height=_}}}getClippingContextListForDraw(){return this._clippingContextListForDraw}getClippingContextListForOffscreen(){return this._clippingContextListForOffscreen}getClippingMaskBufferSize(){return this._clippingMaskBufferSize}getRenderTextureCount(){return this._renderTextureCount}getChannelFlagAsColor(e){return this._channelColors[e]}setClippingMaskBufferSize(e){this._clippingMaskBufferSize=e}_clearedMaskBufferFlags;_channelColors;_clippingContextListForMask;_clippingContextListForDraw;_clippingContextListForOffscreen;_clippingMaskBufferSize;_renderTextureCount;_tmpMatrix;_tmpMatrixForMask;_tmpMatrixForDraw;_tmpBoundsOnModel;_clippingContexttConstructor},Ae=class{static copyBuffer(e,t,r,i=null,s=!1){if(t==null||r==null)return;if(!(e instanceof WebGL2RenderingContext))throw new Error("WebGL2RenderingContext is required for buffer copy.");let n=s?i:e.getParameter(e.FRAMEBUFFER_BINDING);e.bindFramebuffer(e.READ_FRAMEBUFFER,t.getRenderTexture()),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,r.getRenderTexture()),e.blitFramebuffer(0,0,t.getBufferWidth(),t.getBufferHeight(),0,0,r.getBufferWidth(),r.getBufferHeight(),e.COLOR_BUFFER_BIT,e.NEAREST),e.bindFramebuffer(e.FRAMEBUFFER,n)}beginDraw(e=null,t=!1){if(this._renderTexture==null){console.error("_renderTexture is null");return}e==null&&!t?this._oldFbo=this._gl.getParameter(this._gl.FRAMEBUFFER_BINDING):this._oldFbo=e,this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,this._renderTexture)}endDraw(){this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,this._oldFbo)}clear(e,t,r,i){this._gl.clearColor(e,t,r,i),this._gl.clear(this._gl.COLOR_BUFFER_BIT)}createRenderTarget(e,t,r,i){this.destroyRenderTarget(),this._colorBuffer=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this._colorBuffer),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.bindTexture(e.TEXTURE_2D,null);let s=e.createFramebuffer();return s==null?(D("Failed to create framebuffer"),!1):(e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this._colorBuffer,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE?(D("Framebuffer is not complete"),e.bindFramebuffer(e.FRAMEBUFFER,i),e.deleteFramebuffer(s),this.destroyRenderTarget(),!1):(this._renderTexture=s,this._bufferWidth=t,this._bufferHeight=r,this._gl=e,!0))}destroyRenderTarget(){this._colorBuffer&&(this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.deleteTexture(this._colorBuffer),this._colorBuffer=null),this._renderTexture&&(this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null),this._gl.deleteFramebuffer(this._renderTexture),this._renderTexture=null)}getGL(){return this._gl}getRenderTexture(){return this._renderTexture}getColorBuffer(){return this._colorBuffer}getBufferWidth(){return this._bufferWidth}getBufferHeight(){return this._bufferHeight}isValid(){return this._renderTexture!=null}getOldFBO(){return this._oldFbo}constructor(){this._gl=null,this._colorBuffer=null,this._renderTexture=null,this._bufferWidth=0,this._bufferHeight=0,this._oldFbo=null}_gl;_colorBuffer;_renderTexture;_bufferWidth;_bufferHeight;_oldFbo};(function(e){e.CubismOffscreenSurface_WebGL=Ae})(Ji||(Ji={}));Eo=class{constructor(e=null,t=null,r=!1){this.colorBuffer=e,this.renderTexture=t,this.inUse=r}clear(){this.colorBuffer=null,this.renderTexture=null,this.inUse=!1}getColorBuffer(){return this.colorBuffer}getRenderTexture(){return this.renderTexture}colorBuffer;renderTexture;inUse},vo=class{constructor(e){this.gl=e,this.offscreenRenderTargetContainers=new Array,this.previousActiveRenderTextureMaxCount=0,this.currentActiveRenderTextureCount=0,this.hasResetThisFrame=!1,this.width=0,this.height=0}release(){if(this.offscreenRenderTargetContainers!=null){for(let e=0;e<this.offscreenRenderTargetContainers.length;++e){let t=this.offscreenRenderTargetContainers[e];this.gl.deleteTexture(t.colorBuffer),this.gl.deleteFramebuffer(t.renderTexture)}this.offscreenRenderTargetContainers.length=0,this.offscreenRenderTargetContainers=null}}gl;offscreenRenderTargetContainers;previousActiveRenderTextureMaxCount;currentActiveRenderTextureCount;hasResetThisFrame;width;height},hr=class $t{constructor(){this._contextManagers=new Map}release(){if(this._contextManagers!=null){for(let t of this._contextManagers.values())t.release();this._contextManagers.clear(),this._contextManagers=null}$t._instance=null}static getInstance(){return this._instance==null&&(this._instance=new $t),this._instance}getContextManager(t){return this._contextManagers.has(t)||this._contextManagers.set(t,new vo(t)),this._contextManagers.get(t)}removeContext(t){this._contextManagers.has(t)&&(this._contextManagers.get(t).release(),this._contextManagers.delete(t))}initialize(t,r,i){let s=this.getContextManager(t);if(s.offscreenRenderTargetContainers!=null){for(let n=0;n<s.offscreenRenderTargetContainers.length;++n){let a=s.offscreenRenderTargetContainers[n];s.gl.deleteTexture(a.colorBuffer),s.gl.deleteFramebuffer(a.renderTexture),a.clear()}s.offscreenRenderTargetContainers.length=0}else s.offscreenRenderTargetContainers=new Array;s.width=r,s.height=i,s.previousActiveRenderTextureMaxCount=0,s.currentActiveRenderTextureCount=0,s.hasResetThisFrame=!1}beginFrameProcess(t){let r=this.getContextManager(t);r.hasResetThisFrame||(r.previousActiveRenderTextureMaxCount=0,r.hasResetThisFrame=!0)}endFrameProcess(t){let r=this.getContextManager(t);r.hasResetThisFrame=!1}getContainerSize(t){let r=this.getContextManager(t);return r.offscreenRenderTargetContainers==null?0:r.offscreenRenderTargetContainers.length}getOffscreenRenderTargetContainers(t,r,i,s){let n=this.getContextManager(t);(n.width!=r||n.height!=i||n.offscreenRenderTargetContainers==null)&&this.initialize(t,r,i),this.updateRenderTargetContainerCount(t);let a=this.getUnusedOffscreenRenderTargetContainer(t);return a??this.createOffscreenRenderTargetContainer(t,r,i,s)}getUsingRenderTextureState(t,r){let i=this.getContextManager(t);for(let s=0;s<i.offscreenRenderTargetContainers.length;++s)if(i.offscreenRenderTargetContainers[s].renderTexture==r)return i.offscreenRenderTargetContainers[s].inUse;return!0}startUsingRenderTexture(t,r){let i=this.getContextManager(t);for(let s=0;s<i.offscreenRenderTargetContainers.length;++s)if(i.offscreenRenderTargetContainers[s].renderTexture==r){i.offscreenRenderTargetContainers[s].inUse=!0,this.updateRenderTargetContainerCount(t);break}}stopUsingRenderTexture(t,r){let i=this.getContextManager(t);for(let s=0;s<i.offscreenRenderTargetContainers.length;++s)if(i.offscreenRenderTargetContainers[s].renderTexture==r){i.offscreenRenderTargetContainers[s].inUse=!1,i.currentActiveRenderTextureCount--,i.currentActiveRenderTextureCount<0&&(i.currentActiveRenderTextureCount=0);break}}stopUsingAllRenderTextures(t){let r=this.getContextManager(t);for(let i=0;i<r.offscreenRenderTargetContainers.length;++i)r.offscreenRenderTargetContainers[i].inUse=!1;r.currentActiveRenderTextureCount=0}releaseStaleRenderTextures(t){let r=this.getContextManager(t),i=r.offscreenRenderTargetContainers.length;if(r.hasResetThisFrame||i===0)return;let s=0,n=r.previousActiveRenderTextureMaxCount;for(let a=i;r.previousActiveRenderTextureMaxCount<a;--a){let l=a-1;if(r.offscreenRenderTargetContainers[l].inUse){let u=!1;for(;s<r.previousActiveRenderTextureMaxCount;++s)if(!r.offscreenRenderTargetContainers[s].inUse){let h=r.offscreenRenderTargetContainers[s];r.offscreenRenderTargetContainers[s]=r.offscreenRenderTargetContainers[l],r.offscreenRenderTargetContainers[s].inUse=!0,r.offscreenRenderTargetContainers[l]=h,r.offscreenRenderTargetContainers[l].inUse=!1,u=!0;break}if(!u){n=a;break}}let o=r.offscreenRenderTargetContainers[l];r.gl.bindTexture(r.gl.TEXTURE_2D,null),r.gl.deleteTexture(o.colorBuffer),r.gl.bindFramebuffer(r.gl.FRAMEBUFFER,null),r.gl.deleteFramebuffer(o.renderTexture),o.clear()}Q(r.offscreenRenderTargetContainers,n)}getPreviousActiveRenderTextureCount(t){return this.getContextManager(t).previousActiveRenderTextureMaxCount}getCurrentActiveRenderTextureCount(t){return this.getContextManager(t).currentActiveRenderTextureCount}updateRenderTargetContainerCount(t){let r=this.getContextManager(t);++r.currentActiveRenderTextureCount,r.previousActiveRenderTextureMaxCount=r.currentActiveRenderTextureCount>r.previousActiveRenderTextureMaxCount?r.currentActiveRenderTextureCount:r.previousActiveRenderTextureMaxCount}getUnusedOffscreenRenderTargetContainer(t){let r=this.getContextManager(t);for(let i=0;i<r.offscreenRenderTargetContainers.length;++i){let s=r.offscreenRenderTargetContainers[i];if(s.inUse==!1)return s.inUse=!0,s}return null}createOffscreenRenderTargetContainer(t,r,i,s){let n=new Ae;if(!n.createRenderTarget(t,r,i,s))return D("Failed to create offscreen render texture."),null;let a=new Eo(n.getColorBuffer(),n.getRenderTexture(),!0);return this.getContextManager(t).offscreenRenderTargetContainers.push(a),a}static _instance;_contextManagers},ji=class extends Ae{initializeOffscreenManager(e,t,r){this._gl=e,this._webGLOffscreenManager=hr.getInstance(),this._webGLOffscreenManager.getContainerSize(e)===0&&this._webGLOffscreenManager.initialize(e,t,r)}setOffscreenRenderTarget(e,t,r,i){this._webGLOffscreenManager==null&&this.initializeOffscreenManager(e,t,r);let s=this._webGLOffscreenManager.getOffscreenRenderTargetContainers(e,t,r,i);if(s==null){D("Failed to acquire offscreen render texture container.");return}this._colorBuffer=s.getColorBuffer(),this._renderTexture=s.getRenderTexture(),this._bufferWidth=t,this._bufferHeight=r,this._gl=e,this._renderTexture==null&&(this._renderTexture=i,D("Failed to create offscreen render texture."))}getUsingRenderTextureState(){return this._webGLOffscreenManager==null||this._gl==null?!0:this._webGLOffscreenManager.getUsingRenderTextureState(this._gl,this._renderTexture)}startUsingRenderTexture(){this._webGLOffscreenManager==null||this._gl==null||this._webGLOffscreenManager.startUsingRenderTexture(this._gl,this._renderTexture)}stopUsingRenderTexture(){this._webGLOffscreenManager==null||this._gl==null||this._webGLOffscreenManager.stopUsingRenderTexture(this._gl,this._renderTexture)}setOffscreenIndex(e){this._offscreenIndex=e}getOffscreenIndex(){return this._offscreenIndex}setOldOffscreen(e){this._oldOffscreen=e}getOldOffscreen(){return this._oldOffscreen}setParentPartOffscreen(e){this._parentOffscreenRenderTarget=e}getParentPartOffscreen(){return this._parentOffscreenRenderTarget}constructor(){super(),this._offscreenIndex=-1,this._parentOffscreenRenderTarget=null,this._oldOffscreen=null,this._webGLOffscreenManager=null}release(){this._webGLOffscreenManager!=null&&this._gl!=null&&this._renderTexture!=null&&this._webGLOffscreenManager.stopUsingRenderTexture(this._gl,this._renderTexture),this._colorBuffer&&this._gl&&(this._gl.deleteTexture(this._colorBuffer),this._colorBuffer=null),this._renderTexture&&this._gl&&(this._gl.deleteFramebuffer(this._renderTexture),this._renderTexture=null),this._webGLOffscreenManager!=null&&(this._webGLOffscreenManager=null),this._oldOffscreen=null,this._parentOffscreenRenderTarget=null}_offscreenIndex;_parentOffscreenRenderTarget;_oldOffscreen;_webGLOffscreenManager},Po="vertshadersrc.vert",Ro="vertshadersrcmasked.vert",Do="vertshadersrcsetupmask.vert",Lo="fragshadersrcsetupmask.frag",To="fragshadersrcpremultipliedalpha.frag",Fo="fragshadersrcmaskpremultipliedalpha.frag",Oo="fragshadersrcmaskinvertedpremultipliedalpha.frag",Vo="vertshadersrccopy.vert",ko="fragshadersrccopy.frag",Qo="fragshadersrccolorblend.frag",Uo="fragshadersrcalphablend.frag",No="vertshadersrcblend.vert",Go="fragshadersrcpremultipliedalphablend.frag",Xo="ColorBlend_",Ho="AlphaBlend_",Zi=new Float32Array([-1,-1,1,-1,-1,1,1,1]),Wo=new Float32Array([0,0,1,0,0,1,1,1]),Yo=new Float32Array([0,1,1,1,0,0,1,0]),Js=class{async loadShader(e,t){let r=e.slice(e.lastIndexOf("/")+1),i=this._shaderSources?.[r];if(i!==void 0){if(i.trim().length==0)throw new Error(`Failed to load shader ${e}: empty source`);return i}let s=await fetch(e,{signal:t});if(!s.ok)throw new Error(`Failed to load shader ${e}: HTTP ${s.status}`);let n=await s.text();if(n.trim().length==0)throw new Error(`Failed to load shader ${e}: empty source`);return n}async loadShaders(e){let t=this._shaderPath??this._defaultShaderPath,r=[{path:t+Po,prop:"_vertShaderSrc"},{path:t+Ro,prop:"_vertShaderSrcMasked"},{path:t+Do,prop:"_vertShaderSrcSetupMask"},{path:t+Lo,prop:"_fragShaderSrcSetupMask"},{path:t+To,prop:"_fragShaderSrcPremultipliedAlpha"},{path:t+Fo,prop:"_fragShaderSrcMaskPremultipliedAlpha"},{path:t+Oo,prop:"_fragShaderSrcMaskInvertedPremultipliedAlpha"},{path:t+Vo,prop:"_vertShaderSrcCopy"},{path:t+ko,prop:"_fragShaderSrcCopy"},{path:t+Qo,prop:"_fragShaderSrcColorBlend"},{path:t+Uo,prop:"_fragShaderSrcAlphaBlend"},{path:t+No,prop:"_vertShaderSrcBlend"},{path:t+Go,prop:"_fragShaderSrcBlend"}];(await Promise.all(r.map(async i=>({prop:i.prop,data:await this.loadShader(i.path,e)})))).forEach(i=>{this[i.prop]=i.data})}constructor(){this._shaderSets=new Array,this._isShaderLoading=!1,this._isShaderLoaded=!1,this._blendShadersRegistered=!1,this._currentProgram=null,this._shaderLoadPromise=null,this._colorBlendMap=new Map,this._colorBlendValues=new Array;let e=Object.keys(V),t=Object.keys(V).map(s=>V[s]);for(let s=0;s<e.length;s++){let n=e[s];if(n.includes(Xo)){let a=n.slice(11),l=parseInt(t[s].toString());this._colorBlendMap.set(l,a),this._colorBlendValues.push(l)}}this._alphaBlendMap=new Map,this._alphaBlendValues=new Array;let r=Object.keys(Lt),i=Object.keys(Lt).map(s=>Lt[s]);for(let s=0;s<r.length;s++){let n=r[s];if(n.includes(Ho)){let a=n.slice(11),l=parseInt(i[s].toString());this._alphaBlendMap.set(l,a),this._alphaBlendValues.push(l)}}this._blendShaderSetMap=new Map,this._shaderCount=11+(this._colorBlendValues.length-3)*(this._alphaBlendValues.length-1)*3,this._defaultShaderPath="../../Framework/Shaders/WebGL/",this._shaderPath=this._defaultShaderPath}release(){this.releaseShaderProgram()}setProgram(e){this._currentProgram!==e&&(this._currentProgram=e,this.gl.useProgram(e))}setupShaderProgramForDrawable(e,t,r){if(e.isPremultipliedAlpha()||D("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders(void 0,t.isBlendModeEnabled()),this._isShaderLoaded==!1){O("Shader program is not initialized.");return}let i,s,n,a,l=e.getClippingContextBufferForDrawable()!=null,o=t.getDrawableInvertedMaskBit(r),u=l?o?2:1:0,h,d=!0;if(t.isBlendModeEnabled()){let b=t.getDrawableColorBlend(r),w=t.getDrawableAlphaBlend(r);if(b==-1||w==-1||b==V.ColorBlend_Normal&&w==0)h=this._shaderSets[1+u],i=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ONE,a=this.gl.ONE_MINUS_SRC_ALPHA;else switch(b){case V.ColorBlend_AddCompatible:h=this._shaderSets[4+u],i=this.gl.ONE,s=this.gl.ONE,n=this.gl.ZERO,a=this.gl.ONE;break;case V.ColorBlend_MultiplyCompatible:h=this._shaderSets[7+u],i=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ZERO,a=this.gl.ONE;break;default:{let B=e._currentOffscreen!=null?e._currentOffscreen:e.getModelRenderTarget(0);Ae.copyBuffer(this.gl,B,e.getModelRenderTarget(1));let E=this._blendShaderSetMap.get(this._colorBlendMap.get(b)+this._alphaBlendMap.get(w));if(E===void 0)throw new Error("Blend shader programs are not registered for this context.");h=this._shaderSets[E+u],i=this.gl.ONE,s=this.gl.ZERO,n=this.gl.ONE,a=this.gl.ZERO,d=!1}break}}else switch(t.getDrawableBlendMode(r)){case 0:default:h=this._shaderSets[1+u],i=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ONE,a=this.gl.ONE_MINUS_SRC_ALPHA;break;case 1:h=this._shaderSets[4+u],i=this.gl.ONE,s=this.gl.ONE,n=this.gl.ZERO,a=this.gl.ONE;break;case 2:h=this._shaderSets[7+u],i=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ZERO,a=this.gl.ONE;break}this.setProgram(h.shaderProgram),e._bufferData.vertex==null&&(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex);let c=t.getDrawableVertices(r);if(this.gl.bufferData(this.gl.ARRAY_BUFFER,c,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(h.attributePositionLocation),this.gl.vertexAttribPointer(h.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),e.bindDrawableUvBuffer(r),this.gl.enableVertexAttribArray(h.attributeTexCoordLocation),this.gl.vertexAttribPointer(h.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),l){this.gl.activeTexture(this.gl.TEXTURE1);let b=e.getDrawableMaskBuffer(e.getClippingContextBufferForDrawable()._bufferIndex).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,b),this.gl.uniform1i(h.samplerTexture1Location,1),this.gl.uniformMatrix4fv(h.uniformClipMatrixLocation,!1,e.getClippingContextBufferForDrawable()._matrixForDraw.getArray());let w=e.getClippingContextBufferForDrawable()._layoutChannelIndex,B=e.getClippingContextBufferForDrawable().getClippingManager().getChannelFlagAsColor(w);this.gl.uniform4f(h.uniformChannelFlagLocation,B.r,B.g,B.b,B.a),t.isBlendModeEnabled()&&this.gl.uniform1f(h.uniformInvertMaskFlagLocation,o?1:0)}let g=t.getDrawableTextureIndex(r),A=e.getBindedTextures().get(g);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,A),this.gl.uniform1i(h.samplerTexture0Location,0);let p=e.getMvpMatrix();this.gl.uniformMatrix4fv(h.uniformMatrixLocation,!1,p.getArray());let f=null;if(t.isBlendModeEnabled()){let b=t.getDrawableOpacity(r);f=new R(b,b,b,b)}else f=e.getModelColorWithOpacity(t.getDrawableOpacity(r));let _=t.getOverrideMultiplyAndScreenColor(),y=_.getDrawableMultiplyColor(r),C=_.getDrawableScreenColor(r);if(this.gl.uniform4f(h.uniformBaseColorLocation,f.r,f.g,f.b,f.a),this.gl.uniform4f(h.uniformMultiplyColorLocation,y.r,y.g,y.b,y.a),this.gl.uniform4f(h.uniformScreenColorLocation,C.r,C.g,C.b,C.a),t.isBlendModeEnabled()&&(this.gl.activeTexture(this.gl.TEXTURE2),!d)){let b=e.getModelRenderTarget(1).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,b),this.gl.uniform1i(h.samplerFrameBufferTextureLocation,2)}e.bindDrawableIndexBuffer(r),this.gl.blendFuncSeparate(i,s,n,a)}setupShaderProgramForOffscreen(e,t,r){if(e.isPremultipliedAlpha()||D("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders(void 0,t.isBlendModeEnabled()),this._isShaderLoaded==!1){O("Shader program is not initialized.");return}let i,s,n,a,l=r.getOffscreenIndex(),o=e.getClippingContextBufferForOffscreen()!=null,u=t.getOffscreenInvertedMask(l),h=o?u?2:1:0,d,c=!0,g=t.getOffscreenColorBlend(l),A=t.getOffscreenAlphaBlend(l);if(g==-1||A==-1||g==V.ColorBlend_Normal&&A==0)d=this._shaderSets[1+h],i=this.gl.ONE,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ONE,a=this.gl.ONE_MINUS_SRC_ALPHA;else switch(g){case V.ColorBlend_AddCompatible:d=this._shaderSets[4+h],i=this.gl.ONE,s=this.gl.ONE,n=this.gl.ZERO,a=this.gl.ONE;break;case V.ColorBlend_MultiplyCompatible:d=this._shaderSets[7+h],i=this.gl.DST_COLOR,s=this.gl.ONE_MINUS_SRC_ALPHA,n=this.gl.ZERO,a=this.gl.ONE;break;default:{let B=r.getOldOffscreen()!=null?r.getOldOffscreen():e.getModelRenderTarget(0);Ae.copyBuffer(this.gl,B,e.getModelRenderTarget(1));let E=this._blendShaderSetMap.get(this._colorBlendMap.get(g)+this._alphaBlendMap.get(A));if(E===void 0)throw new Error("Blend shader programs are not registered for this context.");d=this._shaderSets[E+h],i=this.gl.ONE,s=this.gl.ZERO,n=this.gl.ONE,a=this.gl.ZERO,c=!1}break}this.setProgram(d.shaderProgram),Ae.copyBuffer(this.gl,r,e.getModelRenderTarget(2)),this.gl.activeTexture(this.gl.TEXTURE0);let p=e.getModelRenderTarget(2).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,p),this.gl.uniform1i(d.samplerTexture0Location,0);let f=new ne;f.loadIdentity(),this.gl.uniformMatrix4fv(d.uniformMatrixLocation,!1,f.getArray());let _=t.getOffscreenOpacity(l),y=new R(_,_,_,_),C=t.getOverrideMultiplyAndScreenColor(),b=C.getOffscreenMultiplyColor(l),w=C.getOffscreenScreenColor(l);if(this.gl.uniform4f(d.uniformBaseColorLocation,y.r,y.g,y.b,y.a),this.gl.uniform4f(d.uniformMultiplyColorLocation,b.r,b.g,b.b,b.a),this.gl.uniform4f(d.uniformScreenColorLocation,w.r,w.g,w.b,w.a),this.gl.activeTexture(this.gl.TEXTURE2),!c){let B=e.getModelRenderTarget(1).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,B),this.gl.uniform1i(d.samplerFrameBufferTextureLocation,2)}if(o){this.gl.activeTexture(this.gl.TEXTURE1);let B=e.getOffscreenMaskBuffer(e.getClippingContextBufferForOffscreen()._bufferIndex).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,B),this.gl.uniform1i(d.samplerTexture1Location,1),this.gl.uniformMatrix4fv(d.uniformClipMatrixLocation,!1,e.getClippingContextBufferForOffscreen()._matrixForDraw.getArray());let E=e.getClippingContextBufferForOffscreen()._layoutChannelIndex,T=e.getClippingContextBufferForOffscreen().getClippingManager().getChannelFlagAsColor(E);this.gl.uniform4f(d.uniformChannelFlagLocation,T.r,T.g,T.b,T.a),t.isBlendModeEnabled()&&this.gl.uniform1f(d.uniformInvertMaskFlagLocation,u?1:0)}e._bufferData.vertex||(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,Zi,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(d.attributePositionLocation),this.gl.vertexAttribPointer(d.attributePositionLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),e._bufferData.uv||(e._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,Yo,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(d.attributeTexCoordLocation),this.gl.vertexAttribPointer(d.attributeTexCoordLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),this.gl.blendFuncSeparate(i,s,n,a)}setupShaderProgramForMask(e,t,r){if(e.isPremultipliedAlpha()||D("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders(void 0,t.isBlendModeEnabled()),this._isShaderLoaded==!1){O("Shader program is not initialized.");return}let i=this._shaderSets[0];this.setProgram(i.shaderProgram),e._bufferData.vertex==null&&(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex);let s=t.getDrawableVertices(r);this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(i.attributePositionLocation),this.gl.vertexAttribPointer(i.attributePositionLocation,2,this.gl.FLOAT,!1,0,0);let n=t.getDrawableTextureIndex(r),a=e.getBindedTextures().get(n);this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(i.samplerTexture0Location,0),e.bindDrawableUvBuffer(r),this.gl.enableVertexAttribArray(i.attributeTexCoordLocation),this.gl.vertexAttribPointer(i.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0);let l=e.getClippingContextBufferForMask()._layoutChannelIndex,o=e.getClippingContextBufferForMask().getClippingManager().getChannelFlagAsColor(l);this.gl.uniform4f(i.uniformChannelFlagLocation,o.r,o.g,o.b,o.a),this.gl.uniformMatrix4fv(i.uniformClipMatrixLocation,!1,e.getClippingContextBufferForMask()._matrixForMask.getArray());let u=e.getClippingContextBufferForMask()._layoutBounds;this.gl.uniform4f(i.uniformBaseColorLocation,u.x*2-1,u.y*2-1,u.getRight()*2-1,u.getBottom()*2-1);let h=this.gl.ZERO,d=this.gl.ONE_MINUS_SRC_COLOR,c=this.gl.ZERO,g=this.gl.ONE_MINUS_SRC_ALPHA;e.bindDrawableIndexBuffer(r),this.gl.blendFuncSeparate(h,d,c,g)}setupShaderProgramForOffscreenRenderTarget(e){if(this._shaderSets.length==0&&this.generateShaders(void 0,e.getModel().isBlendModeEnabled()),this._isShaderLoaded==!1){O("Shader program is not initialized.");return}let t=e.getModelColor();t.r*=t.a,t.g*=t.a,t.b*=t.a,this.copyTexture(e,t)}copyTexture(e,t){let r=this.gl.ONE,i=this.gl.ONE_MINUS_SRC_ALPHA,s=this.gl.ONE,n=this.gl.ONE_MINUS_SRC_ALPHA,a=this._shaderSets[10];this.setProgram(a.shaderProgram),this.gl.uniform4f(a.uniformBaseColorLocation,t.r,t.g,t.b,t.a),this.gl.activeTexture(this.gl.TEXTURE0);let l=e.getModelRenderTarget(0).getColorBuffer();this.gl.bindTexture(this.gl.TEXTURE_2D,l),this.gl.uniform1i(a.samplerTexture0Location,0),e._bufferData.vertex||(e._bufferData.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,Zi,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(a.attributePositionLocation),this.gl.vertexAttribPointer(a.attributePositionLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),e._bufferData.uv||(e._bufferData.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e._bufferData.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,Wo,this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(a.attributeTexCoordLocation),this.gl.vertexAttribPointer(a.attributeTexCoordLocation,2,this.gl.FLOAT,!1,Float32Array.BYTES_PER_ELEMENT*2,0),this.gl.blendFuncSeparate(r,i,s,n)}releaseShaderProgram(){let e=new Set;for(let t=0;t<this._shaderSets.length;t++){let r=this._shaderSets[t];r&&(r.shaderProgram&&e.add(r.shaderProgram),r.shaderProgram=null,this._shaderSets[t]=void 0,this._shaderSets[t]=null)}for(let t of e)this.gl.deleteProgram(t);this._shaderSets.length=0,this._blendShaderSetMap.clear(),this._blendShadersRegistered=!1,this._currentProgram=null}generateShaders(e,t=!0){if(this._isShaderLoaded)return t&&!this._blendShadersRegistered&&(this.registerBlendShader(),this._blendShadersRegistered=!0),Promise.resolve();if(this._isShaderLoading)return this._shaderLoadPromise.then(()=>this.generateShaders(e,t));this._isShaderLoading=!0,this._isShaderLoaded=!1,this._shaderSets.length=this._shaderCount;for(let r=0;r<this._shaderCount;r++)this._shaderSets[r]=new Zs;return this._shaderLoadPromise=this.loadShaders(e).then(()=>{this.registerShader(),t&&this.registerBlendShader(),this._blendShadersRegistered=t,this._isShaderLoading=!1,this._isShaderLoaded=!0}).catch(r=>{throw this._isShaderLoading=!1,this._isShaderLoaded=!1,this.releaseShaderProgram(),r}),this._shaderLoadPromise}registerShader(){let e=this._vertShaderSrc,t=this._vertShaderSrcMasked,r=this._vertShaderSrcSetupMask,i=this._fragShaderSrcSetupMask,s=this._fragShaderSrcPremultipliedAlpha,n=this._fragShaderSrcMaskPremultipliedAlpha,a=this._fragShaderSrcMaskInvertedPremultipliedAlpha;this._shaderSets[0].shaderProgram=this.loadShaderProgram(r,i),this._shaderSets[1].shaderProgram=this.loadShaderProgram(e,s),this._shaderSets[2].shaderProgram=this.loadShaderProgram(t,n),this._shaderSets[3].shaderProgram=this.loadShaderProgram(t,a),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[1].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_multiplyColor"),this._shaderSets[1].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_screenColor"),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[2].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_multiplyColor"),this._shaderSets[2].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_screenColor"),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[3].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_multiplyColor"),this._shaderSets[3].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_screenColor"),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[4].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_multiplyColor"),this._shaderSets[4].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_screenColor"),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[5].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_multiplyColor"),this._shaderSets[5].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_screenColor"),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[6].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_multiplyColor"),this._shaderSets[6].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_screenColor"),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[7].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_multiplyColor"),this._shaderSets[7].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_screenColor"),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[8].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_multiplyColor"),this._shaderSets[8].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_screenColor"),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"),this._shaderSets[9].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_multiplyColor"),this._shaderSets[9].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_screenColor")}registerBlendShader(){let e=this._vertShaderSrcCopy,t=this._fragShaderSrcCopy,r=this._shaderSets[10];r.shaderProgram=this.loadShaderProgram(e,t),r.attributeTexCoordLocation=this.gl.getAttribLocation(r.shaderProgram,"a_texCoord"),r.attributePositionLocation=this.gl.getAttribLocation(r.shaderProgram,"a_position"),r.uniformBaseColorLocation=this.gl.getUniformLocation(r.shaderProgram,"u_baseColor");let i=11;for(let s=0;s<this._colorBlendValues.length;s++){if(this._colorBlendValues[s]==-1||this._colorBlendValues[s]==V.ColorBlend_AddCompatible||this._colorBlendValues[s]==V.ColorBlend_MultiplyCompatible)continue;let n=this._colorBlendValues[s],a=`#define COLOR_BLEND_${this._colorBlendMap.get(n).toUpperCase()}
21
+ `;for(let l=0;l<this._alphaBlendValues.length;l++){if(this._alphaBlendValues[l]==-1||this._colorBlendValues[s]==V.ColorBlend_Normal&&this._alphaBlendValues[l]==0)continue;let o=this._alphaBlendValues[l],u=`#define ALPHA_BLEND_${this._alphaBlendMap.get(o).toUpperCase()}
22
22
  `;this.generateBlendShader(a,u,i),this._blendShaderSetMap.set(this._colorBlendMap.get(this._colorBlendValues[s])+this._alphaBlendMap.get(this._alphaBlendValues[l]),i),i+=3}}}generateBlendShader(e,t,r){for(let i=0;i<3;i++){let s="",n=`precision mediump float;
23
23
  `,a=r+i;if(n+=e,n+=t,n+=this._fragShaderSrcColorBlend,n+=this._fragShaderSrcAlphaBlend,i==1||i==2){let l=`#define CLIPPING_MASK
24
- `;s+=l,n+=l}s+=this._vertShaderSrcBlend,n+=this._fragShaderSrcBlend,this._shaderSets[a].shaderProgram=this.loadShaderProgram(s,n),this._shaderSets[a].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[a].shaderProgram,"a_position"),this._shaderSets[a].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[a].shaderProgram,"a_texCoord"),this._shaderSets[a].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"s_texture0"),this._shaderSets[a].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_matrix"),this._shaderSets[a].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_baseColor"),this._shaderSets[a].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_multiplyColor"),this._shaderSets[a].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_screenColor"),this._shaderSets[a].samplerFrameBufferTextureLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"s_blendTexture"),(i==1||i==2)&&(this._shaderSets[a].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"s_texture1"),this._shaderSets[a].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_clipMatrix"),this._shaderSets[a].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_channelFlag"),this._shaderSets[a].uniformInvertMaskFlagLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_invertClippingMask"))}}loadShaderProgram(e,t){let r=this.gl.createProgram();if(!r)throw new Error("WebGL failed to create a shader program");let i,s;try{i=this.compileShaderSource(this.gl.VERTEX_SHADER,e),s=this.compileShaderSource(this.gl.FRAGMENT_SHADER,t)}catch(n){throw i&&this.gl.deleteShader(i),this.gl.deleteProgram(r),n}if(this.gl.attachShader(r,i),this.gl.attachShader(r,s),this.gl.linkProgram(r),!this.gl.getProgramParameter(r,this.gl.LINK_STATUS)){let n=this.gl.getProgramInfoLog(r);throw D("Failed to link program: {0}",n),this.gl.deleteShader(i),i=0,this.gl.deleteShader(s),s=0,r&&(this.gl.deleteProgram(r),r=0),new Error(`Failed to link WebGL shader program: ${n??"unknown error"}`)}return this.gl.deleteShader(i),this.gl.deleteShader(s),r}compileShaderSource(e,t){let r=t,i=this.gl.createShader(e);if(!i)throw new Error("WebGL failed to create a shader");if(this.gl.shaderSource(i,r),this.gl.compileShader(i),!this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)){let s=this.gl.getShaderInfoLog(i);D("Shader compile log: {0} ",s),this.gl.deleteShader(i);let n=e==this.gl.VERTEX_SHADER?"Vertex":"Fragment";throw new Error(`${n} shader compile error: ${s??"unknown error"}`)}return i}setGl(e){this.gl=e}setShaderPath(e){this._shaderPath=e}setShaderSources(e){this._shaderSources=e}getShaderPath(){return this._shaderPath}_shaderSets;gl;_colorBlendMap;_alphaBlendMap;_colorBlendValues;_alphaBlendValues;_blendShaderSetMap;_shaderCount;_vertShaderSrc;_vertShaderSrcMasked;_vertShaderSrcSetupMask;_fragShaderSrcSetupMask;_fragShaderSrcPremultipliedAlpha;_fragShaderSrcMaskPremultipliedAlpha;_fragShaderSrcMaskInvertedPremultipliedAlpha;_vertShaderSrcCopy;_fragShaderSrcCopy;_fragShaderSrcColorBlend;_fragShaderSrcAlphaBlend;_vertShaderSrcBlend;_fragShaderSrcBlend;_isShaderLoading;_isShaderLoaded;_blendShadersRegistered;_currentProgram;_shaderLoadPromise;_defaultShaderPath;_shaderPath;_shaderSources},q=class js{static getInstance(){return Pe==null&&(Pe=new js),Pe}static deleteInstance(){Pe&&(Pe.release(),Pe=null)}constructor(){this._shaderMap=new Map}release(){for(let t of this._shaderMap)t[1].release();this._shaderMap.clear()}getShader(t){return this._shaderMap.get(t)}setGlContext(t){if(!this._shaderMap.has(t)){let r=new Js;r.setGl(t),this._shaderMap.set(t,r)}}releaseContext(t){let r=this._shaderMap.get(t);r&&(r.release(),this._shaderMap.delete(t))}_shaderMap},Zs=class{shaderProgram;attributePositionLocation;attributeTexCoordLocation;uniformMatrixLocation;uniformClipMatrixLocation;samplerTexture0Location;samplerTexture1Location;uniformBaseColorLocation;uniformChannelFlagLocation;uniformMultiplyColorLocation;uniformScreenColorLocation;samplerFrameBufferTextureLocation;uniformInvertMaskFlagLocation},Xo=(function(e){return e[e.ShaderNames_SetupMask=0]="ShaderNames_SetupMask",e[e.ShaderNames_NormalPremultipliedAlpha=1]="ShaderNames_NormalPremultipliedAlpha",e[e.ShaderNames_NormalMaskedPremultipliedAlpha=2]="ShaderNames_NormalMaskedPremultipliedAlpha",e[e.ShaderNames_NomralMaskedInvertedPremultipliedAlpha=3]="ShaderNames_NomralMaskedInvertedPremultipliedAlpha",e[e.ShaderNames_AddPremultipliedAlpha=4]="ShaderNames_AddPremultipliedAlpha",e[e.ShaderNames_AddMaskedPremultipliedAlpha=5]="ShaderNames_AddMaskedPremultipliedAlpha",e[e.ShaderNames_AddMaskedPremultipliedAlphaInverted=6]="ShaderNames_AddMaskedPremultipliedAlphaInverted",e[e.ShaderNames_MultPremultipliedAlpha=7]="ShaderNames_MultPremultipliedAlpha",e[e.ShaderNames_MultMaskedPremultipliedAlpha=8]="ShaderNames_MultMaskedPremultipliedAlpha",e[e.ShaderNames_MultMaskedPremultipliedAlphaInverted=9]="ShaderNames_MultMaskedPremultipliedAlphaInverted",e[e.ShaderNames_ShaderCount=10]="ShaderNames_ShaderCount",e})({});(function(e){e.CubismShaderSet=Zs,e.CubismShader_WebGL=Js,e.CubismShaderManager_WebGL=q,e.ShaderNames=Xo})(qi||(qi={}));at=-1,Gt=new Uint16Array([0,1,2,2,1,3]),ct=class extends Io{setGL(e){this.gl=e}constructor(){super(qs)}setupClippingContext(e,t,r,i,s,n=!1){let a=0;for(let l=0;l<this._clippingContextListForMask.length;l++){let o=this._clippingContextListForMask[l];switch(s){case 0:default:this.calcClippedDrawableTotalBounds(e,o);break;case 1:this.calcClippedOffscreenTotalBounds(e,o);break}o._isUsing&&a++}if(!(a<=0)){switch(this.gl.viewport(0,0,this._clippingMaskBufferSize,this._clippingMaskBufferSize),s){case 0:default:this._currentMaskBuffer=t.getDrawableMaskBuffer(0);break;case 1:this._currentMaskBuffer=t.getOffscreenMaskBuffer(0);break}if(this._currentMaskBuffer.beginDraw(r,n),t.preDraw(),this.setupLayoutBounds(a),this._clearedMaskBufferFlags.length!=this._renderTextureCount){this._clearedMaskBufferFlags.length=0,this._clearedMaskBufferFlags=new Array(this._renderTextureCount);for(let l=0;l<this._clearedMaskBufferFlags.length;l++)this._clearedMaskBufferFlags[l]=!1}for(let l=0;l<this._clearedMaskBufferFlags.length;l++)this._clearedMaskBufferFlags[l]=!1;for(let l=0;l<this._clippingContextListForMask.length;l++){let o=this._clippingContextListForMask[l],u=o._allClippedDrawRect,c=o._layoutBounds,d=.05,h=0,g=0,A;switch(s){case 0:default:A=t.getDrawableMaskBuffer(o._bufferIndex);break;case 1:A=t.getOffscreenMaskBuffer(o._bufferIndex);break}if(this._currentMaskBuffer!=A&&(this._currentMaskBuffer.endDraw(),this._currentMaskBuffer=A,this._currentMaskBuffer.beginDraw(r,n),t.preDraw()),this._tmpBoundsOnModel.setRect(u),this._tmpBoundsOnModel.expand(u.width*d,u.height*d),h=c.width/this._tmpBoundsOnModel.width,g=c.height/this._tmpBoundsOnModel.height,this.createMatrixForMask(!1,c,h,g),o._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),o._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray()),s==1){let f=t.getMvpMatrix().getInvert();o._matrixForDraw.multiplyByMatrix(f)}let p=o._clippingIdCount;for(let f=0;f<p;f++){let _=o._clippingIdList[f];e.getDrawableDynamicFlagVertexPositionsDidChange(_)&&(t.setIsCulling(e.getDrawableCulling(_)!=!1),this._clearedMaskBufferFlags[o._bufferIndex]||(this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this._clearedMaskBufferFlags[o._bufferIndex]=!0),t.setClippingContextBufferForMask(o),t.drawMeshWebGL(e,_))}}this._currentMaskBuffer.endDraw(),t.setClippingContextBufferForMask(null),this.gl.viewport(i[0],i[1],i[2],i[3])}}getClippingMaskCount(){return this._clippingContextListForMask.length}_currentMaskBuffer;gl},qs=class extends ea{constructor(e,t,r){super(t,r),this._owner=e}getClippingManager(){return this._owner}setGl(e){this._owner.setGL(e)}_owner},Ho=class{setGlEnable(e,t){t?this.gl.enable(e):this.gl.disable(e)}setGlEnableVertexAttribArray(e,t){t?this.gl.enableVertexAttribArray(e):this.gl.disableVertexAttribArray(e)}save(){if(this.gl==null){D(`'gl' is null. WebGLRenderingContext is required.
24
+ `;s+=l,n+=l}s+=this._vertShaderSrcBlend,n+=this._fragShaderSrcBlend,this._shaderSets[a].shaderProgram=this.loadShaderProgram(s,n),this._shaderSets[a].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[a].shaderProgram,"a_position"),this._shaderSets[a].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[a].shaderProgram,"a_texCoord"),this._shaderSets[a].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"s_texture0"),this._shaderSets[a].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_matrix"),this._shaderSets[a].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_baseColor"),this._shaderSets[a].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_multiplyColor"),this._shaderSets[a].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_screenColor"),this._shaderSets[a].samplerFrameBufferTextureLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"s_blendTexture"),(i==1||i==2)&&(this._shaderSets[a].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"s_texture1"),this._shaderSets[a].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_clipMatrix"),this._shaderSets[a].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_channelFlag"),this._shaderSets[a].uniformInvertMaskFlagLocation=this.gl.getUniformLocation(this._shaderSets[a].shaderProgram,"u_invertClippingMask"))}}loadShaderProgram(e,t){let r=this.gl.createProgram();if(!r)throw new Error("WebGL failed to create a shader program");let i,s;try{i=this.compileShaderSource(this.gl.VERTEX_SHADER,e),s=this.compileShaderSource(this.gl.FRAGMENT_SHADER,t)}catch(n){throw i&&this.gl.deleteShader(i),this.gl.deleteProgram(r),n}if(this.gl.attachShader(r,i),this.gl.attachShader(r,s),this.gl.linkProgram(r),!this.gl.getProgramParameter(r,this.gl.LINK_STATUS)){let n=this.gl.getProgramInfoLog(r);throw D("Failed to link program: {0}",n),this.gl.deleteShader(i),i=0,this.gl.deleteShader(s),s=0,r&&(this.gl.deleteProgram(r),r=0),new Error(`Failed to link WebGL shader program: ${n??"unknown error"}`)}return this.gl.deleteShader(i),this.gl.deleteShader(s),r}compileShaderSource(e,t){let r=t,i=this.gl.createShader(e);if(!i)throw new Error("WebGL failed to create a shader");if(this.gl.shaderSource(i,r),this.gl.compileShader(i),!this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)){let s=this.gl.getShaderInfoLog(i);D("Shader compile log: {0} ",s),this.gl.deleteShader(i);let n=e==this.gl.VERTEX_SHADER?"Vertex":"Fragment";throw new Error(`${n} shader compile error: ${s??"unknown error"}`)}return i}setGl(e){this.gl=e}setShaderPath(e){this._shaderPath=e}setShaderSources(e){this._shaderSources=e}getShaderPath(){return this._shaderPath}_shaderSets;gl;_colorBlendMap;_alphaBlendMap;_colorBlendValues;_alphaBlendValues;_blendShaderSetMap;_shaderCount;_vertShaderSrc;_vertShaderSrcMasked;_vertShaderSrcSetupMask;_fragShaderSrcSetupMask;_fragShaderSrcPremultipliedAlpha;_fragShaderSrcMaskPremultipliedAlpha;_fragShaderSrcMaskInvertedPremultipliedAlpha;_vertShaderSrcCopy;_fragShaderSrcCopy;_fragShaderSrcColorBlend;_fragShaderSrcAlphaBlend;_vertShaderSrcBlend;_fragShaderSrcBlend;_isShaderLoading;_isShaderLoaded;_blendShadersRegistered;_currentProgram;_shaderLoadPromise;_defaultShaderPath;_shaderPath;_shaderSources},q=class js{static getInstance(){return Pe==null&&(Pe=new js),Pe}static deleteInstance(){Pe&&(Pe.release(),Pe=null)}constructor(){this._shaderMap=new Map}release(){for(let t of this._shaderMap)t[1].release();this._shaderMap.clear()}getShader(t){return this._shaderMap.get(t)}setGlContext(t){if(!this._shaderMap.has(t)){let r=new Js;r.setGl(t),this._shaderMap.set(t,r)}}releaseContext(t){let r=this._shaderMap.get(t);r&&(r.release(),this._shaderMap.delete(t))}_shaderMap},Zs=class{shaderProgram;attributePositionLocation;attributeTexCoordLocation;uniformMatrixLocation;uniformClipMatrixLocation;samplerTexture0Location;samplerTexture1Location;uniformBaseColorLocation;uniformChannelFlagLocation;uniformMultiplyColorLocation;uniformScreenColorLocation;samplerFrameBufferTextureLocation;uniformInvertMaskFlagLocation},zo=(function(e){return e[e.ShaderNames_SetupMask=0]="ShaderNames_SetupMask",e[e.ShaderNames_NormalPremultipliedAlpha=1]="ShaderNames_NormalPremultipliedAlpha",e[e.ShaderNames_NormalMaskedPremultipliedAlpha=2]="ShaderNames_NormalMaskedPremultipliedAlpha",e[e.ShaderNames_NomralMaskedInvertedPremultipliedAlpha=3]="ShaderNames_NomralMaskedInvertedPremultipliedAlpha",e[e.ShaderNames_AddPremultipliedAlpha=4]="ShaderNames_AddPremultipliedAlpha",e[e.ShaderNames_AddMaskedPremultipliedAlpha=5]="ShaderNames_AddMaskedPremultipliedAlpha",e[e.ShaderNames_AddMaskedPremultipliedAlphaInverted=6]="ShaderNames_AddMaskedPremultipliedAlphaInverted",e[e.ShaderNames_MultPremultipliedAlpha=7]="ShaderNames_MultPremultipliedAlpha",e[e.ShaderNames_MultMaskedPremultipliedAlpha=8]="ShaderNames_MultMaskedPremultipliedAlpha",e[e.ShaderNames_MultMaskedPremultipliedAlphaInverted=9]="ShaderNames_MultMaskedPremultipliedAlphaInverted",e[e.ShaderNames_ShaderCount=10]="ShaderNames_ShaderCount",e})({});(function(e){e.CubismShaderSet=Zs,e.CubismShader_WebGL=Js,e.CubismShaderManager_WebGL=q,e.ShaderNames=zo})(qi||(qi={}));at=-1,Gt=new Uint16Array([0,1,2,2,1,3]),ct=class extends xo{setGL(e){this.gl=e}constructor(){super(qs)}setupClippingContext(e,t,r,i,s,n=!1){let a=0;for(let l=0;l<this._clippingContextListForMask.length;l++){let o=this._clippingContextListForMask[l];switch(s){case 0:default:this.calcClippedDrawableTotalBounds(e,o);break;case 1:this.calcClippedOffscreenTotalBounds(e,o);break}o._isUsing&&a++}if(!(a<=0)){switch(this.gl.viewport(0,0,this._clippingMaskBufferSize,this._clippingMaskBufferSize),s){case 0:default:this._currentMaskBuffer=t.getDrawableMaskBuffer(0);break;case 1:this._currentMaskBuffer=t.getOffscreenMaskBuffer(0);break}if(this._currentMaskBuffer.beginDraw(r,n),t.preDraw(),this.setupLayoutBounds(a),this._clearedMaskBufferFlags.length!=this._renderTextureCount){this._clearedMaskBufferFlags.length=0,this._clearedMaskBufferFlags=new Array(this._renderTextureCount);for(let l=0;l<this._clearedMaskBufferFlags.length;l++)this._clearedMaskBufferFlags[l]=!1}for(let l=0;l<this._clearedMaskBufferFlags.length;l++)this._clearedMaskBufferFlags[l]=!1;for(let l=0;l<this._clippingContextListForMask.length;l++){let o=this._clippingContextListForMask[l],u=o._allClippedDrawRect,h=o._layoutBounds,d=.05,c=0,g=0,A;switch(s){case 0:default:A=t.getDrawableMaskBuffer(o._bufferIndex);break;case 1:A=t.getOffscreenMaskBuffer(o._bufferIndex);break}if(this._currentMaskBuffer!=A&&(this._currentMaskBuffer.endDraw(),this._currentMaskBuffer=A,this._currentMaskBuffer.beginDraw(r,n),t.preDraw()),this._tmpBoundsOnModel.setRect(u),this._tmpBoundsOnModel.expand(u.width*d,u.height*d),c=h.width/this._tmpBoundsOnModel.width,g=h.height/this._tmpBoundsOnModel.height,this.createMatrixForMask(!1,h,c,g),o._matrixForMask.setMatrix(this._tmpMatrixForMask.getArray()),o._matrixForDraw.setMatrix(this._tmpMatrixForDraw.getArray()),s==1){let f=t.getMvpMatrix().getInvert();o._matrixForDraw.multiplyByMatrix(f)}let p=o._clippingIdCount;for(let f=0;f<p;f++){let _=o._clippingIdList[f];e.getDrawableDynamicFlagVertexPositionsDidChange(_)&&(t.setIsCulling(e.getDrawableCulling(_)!=!1),this._clearedMaskBufferFlags[o._bufferIndex]||(this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this._clearedMaskBufferFlags[o._bufferIndex]=!0),t.setClippingContextBufferForMask(o),t.drawMeshWebGL(e,_))}}this._currentMaskBuffer.endDraw(),t.setClippingContextBufferForMask(null),this.gl.viewport(i[0],i[1],i[2],i[3])}}getClippingMaskCount(){return this._clippingContextListForMask.length}_currentMaskBuffer;gl},qs=class extends sa{constructor(e,t,r){super(t,r),this._owner=e}getClippingManager(){return this._owner}setGl(e){this._owner.setGL(e)}_owner},Jo=class{setGlEnable(e,t){t?this.gl.enable(e):this.gl.disable(e)}setGlEnableVertexAttribArray(e,t){t?this.gl.enableVertexAttribArray(e):this.gl.disableVertexAttribArray(e)}save(){if(this.gl==null){D(`'gl' is null. WebGLRenderingContext is required.
25
25
  Please call 'CubimRenderer_WebGL.startUp' function.`);return}this._lastArrayBufferBinding=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING),this._lastElementArrayBufferBinding=this.gl.getParameter(this.gl.ELEMENT_ARRAY_BUFFER_BINDING),this._lastProgram=this.gl.getParameter(this.gl.CURRENT_PROGRAM),this._lastActiveTexture=this.gl.getParameter(this.gl.ACTIVE_TEXTURE),this.gl.activeTexture(this.gl.TEXTURE1),this._lastTexture1Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this.gl.activeTexture(this.gl.TEXTURE0),this._lastTexture0Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this._lastVertexAttribArrayEnabled[0]=this.gl.getVertexAttrib(0,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[1]=this.gl.getVertexAttrib(1,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[2]=this.gl.getVertexAttrib(2,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[3]=this.gl.getVertexAttrib(3,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastScissorTest=this.gl.isEnabled(this.gl.SCISSOR_TEST),this._lastStencilTest=this.gl.isEnabled(this.gl.STENCIL_TEST),this._lastDepthTest=this.gl.isEnabled(this.gl.DEPTH_TEST),this._lastCullFace=this.gl.isEnabled(this.gl.CULL_FACE),this._lastBlend=this.gl.isEnabled(this.gl.BLEND),this._lastFrontFace=this.gl.getParameter(this.gl.FRONT_FACE),this._lastColorMask=this.gl.getParameter(this.gl.COLOR_WRITEMASK),this._lastBlending[0]=this.gl.getParameter(this.gl.BLEND_SRC_RGB),this._lastBlending[1]=this.gl.getParameter(this.gl.BLEND_DST_RGB),this._lastBlending[2]=this.gl.getParameter(this.gl.BLEND_SRC_ALPHA),this._lastBlending[3]=this.gl.getParameter(this.gl.BLEND_DST_ALPHA)}restore(){if(this.gl==null){D(`'gl' is null. WebGLRenderingContext is required.
26
- Please call 'CubimRenderer_WebGL.startUp' function.`);return}this.gl.useProgram(this._lastProgram),this.setGlEnableVertexAttribArray(0,this._lastVertexAttribArrayEnabled[0]),this.setGlEnableVertexAttribArray(1,this._lastVertexAttribArrayEnabled[1]),this.setGlEnableVertexAttribArray(2,this._lastVertexAttribArrayEnabled[2]),this.setGlEnableVertexAttribArray(3,this._lastVertexAttribArrayEnabled[3]),this.setGlEnable(this.gl.SCISSOR_TEST,this._lastScissorTest),this.setGlEnable(this.gl.STENCIL_TEST,this._lastStencilTest),this.setGlEnable(this.gl.DEPTH_TEST,this._lastDepthTest),this.setGlEnable(this.gl.CULL_FACE,this._lastCullFace),this.setGlEnable(this.gl.BLEND,this._lastBlend),this.gl.frontFace(this._lastFrontFace),this.gl.colorMask(this._lastColorMask[0],this._lastColorMask[1],this._lastColorMask[2],this._lastColorMask[3]),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._lastArrayBufferBinding),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._lastElementArrayBufferBinding),this.gl.activeTexture(this.gl.TEXTURE1),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture1Binding2D),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture0Binding2D),this.gl.activeTexture(this._lastActiveTexture),this.gl.blendFuncSeparate(this._lastBlending[0],this._lastBlending[1],this._lastBlending[2],this._lastBlending[3])}setGl(e){this.gl=e}constructor(){this._lastVertexAttribArrayEnabled=new Array(4),this._lastColorMask=new Array(4),this._lastBlending=new Array(4)}_lastArrayBufferBinding;_lastElementArrayBufferBinding;_lastProgram;_lastActiveTexture;_lastTexture0Binding2D;_lastTexture1Binding2D;_lastVertexAttribArrayEnabled;_lastScissorTest;_lastBlend;_lastStencilTest;_lastDepthTest;_lastCullFace;_lastFrontFace;_lastColorMask;_lastBlending;gl},cr=class extends pt{initialize(e,t=1){e.isUsingMasking()&&(this._drawableClippingManager=new ct,this._drawableClippingManager.initializeForDrawable(e,t)),e.isUsingMaskingForOffscreen()&&(this._offscreenClippingManager=new ct,this._offscreenClippingManager.initializeForOffscreen(e,t)),Q(this._sortedObjectsIndexList,e.getDrawableCount()+(e.getOffscreenCount?e.getOffscreenCount():0),0,!0),Q(this._sortedObjectsTypeList,e.getDrawableCount()+(e.getOffscreenCount?e.getOffscreenCount():0),0,!0),super.initialize(e)}setupParentOffscreens(e,t){let r;for(let i=0;i<t;++i){r=null;let s=e.getOffscreenOwnerIndices()[i],n=e.getPartParentPartIndices()[s];for(;n!=-1;){for(let a=0;a<t;++a)if(e.getOffscreenOwnerIndices()[this._offscreenList[a].getOffscreenIndex()]==n){r=this._offscreenList[a];break}if(r!=null)break;n=e.getPartParentPartIndices()[n]}this._offscreenList[i].setParentPartOffscreen(r)}}bindTexture(e,t){this._textures.set(e,t)}getBindedTextures(){return this._textures}setClippingMaskBufferSize(e){if(!this._model.isUsingMasking())return;let t=this._drawableClippingManager.getRenderTextureCount();this._drawableClippingManager.release(),this._drawableClippingManager=void 0,this._drawableClippingManager=null,this._drawableClippingManager=new ct,this._drawableClippingManager.setClippingMaskBufferSize(e),this._drawableClippingManager.initializeForDrawable(this.getModel(),t)}getClippingMaskBufferSize(){return this._model.isUsingMasking()?this._drawableClippingManager.getClippingMaskBufferSize():at}getModelRenderTarget(e){return this._modelRenderTargets[e]}getRenderTextureCount(){return this._model.isUsingMasking()?this._drawableClippingManager.getRenderTextureCount():at}constructor(e,t){super(e,t),this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._rendererProfile=new Ho,this._textures=new Map,this._sortedObjectsIndexList=new Array,this._sortedObjectsTypeList=new Array,this._bufferData={vertex:WebGLBuffer=null,uv:WebGLBuffer=null,index:WebGLBuffer=null},this._drawableIndexBuffers=new Array,this._drawableUvBuffers=new Array,this._renderTargetIndexBuffer=null,this._modelRenderTargets=new Array,this._drawableMasks=new Array,this._currentFbo=null,this._drawableClippingManager=null,this._offscreenClippingManager=null,this._offscreenMasks=new Array,this._offscreenList=new Array}release(){if(this._drawableClippingManager&&(this._drawableClippingManager.release(),this._drawableClippingManager=void 0,this._drawableClippingManager=null),this.gl!=null){this.gl.deleteBuffer(this._bufferData.vertex),this._bufferData.vertex=null,this.gl.deleteBuffer(this._bufferData.uv),this._bufferData.uv=null,this.gl.deleteBuffer(this._bufferData.index),this._bufferData.index=null,this._bufferData=null;for(let e=0;e<this._drawableIndexBuffers.length;e++)this._drawableIndexBuffers[e]!=null&&this.gl.deleteBuffer(this._drawableIndexBuffers[e]);this._drawableIndexBuffers.length=0,this._drawableIndexBuffers=null;for(let e=0;e<this._drawableUvBuffers.length;e++)this._drawableUvBuffers[e]!=null&&this.gl.deleteBuffer(this._drawableUvBuffers[e]);this._drawableUvBuffers.length=0,this._drawableUvBuffers=null,this._renderTargetIndexBuffer!=null&&(this.gl.deleteBuffer(this._renderTargetIndexBuffer),this._renderTargetIndexBuffer=null),this._textures=null;for(let e=0;e<this._modelRenderTargets.length;e++)this._modelRenderTargets[e]!=null&&this._modelRenderTargets[e].isValid()&&this._modelRenderTargets[e].destroyRenderTarget();this._modelRenderTargets.length=0,this._modelRenderTargets=null;for(let e=0;e<this._drawableMasks.length;e++)this._drawableMasks[e]!=null&&this._drawableMasks[e].isValid()&&this._drawableMasks[e].destroyRenderTarget();this._drawableMasks.length=0,this._drawableMasks=null;for(let e=0;e<this._offscreenMasks.length;e++)this._offscreenMasks[e]!=null&&this._offscreenMasks[e].isValid()&&this._offscreenMasks[e].destroyRenderTarget();this._offscreenMasks.length=0,this._offscreenMasks=null;for(let e=0;e<this._offscreenList.length;e++)this._offscreenList[e]!=null&&this._offscreenList[e].isValid()&&this._offscreenList[e].destroyRenderTarget();this._offscreenList.length=0,this._offscreenList=null,this._offscreenClippingManager=null,this._drawableClippingManager=null,this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._rendererProfile=null,this._sortedObjectsIndexList=null,this._sortedObjectsTypeList=null,this._currentFbo=null,this._model=null,this.gl=null}}bindDrawableIndexBuffer(e){let t=this._drawableIndexBuffers[e];t==null?(t=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,this._model.getDrawableVertexIndices(e),this.gl.STATIC_DRAW),this._drawableIndexBuffers[e]=t):this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t)}bindDrawableUvBuffer(e){let t=this._drawableUvBuffers[e];t==null?(t=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t),this.gl.bufferData(this.gl.ARRAY_BUFFER,this._model.getDrawableVertexUvs(e),this.gl.STATIC_DRAW),this._drawableUvBuffers[e]=t):this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t)}bindRenderTargetIndexBuffer(){this._renderTargetIndexBuffer==null?(this._renderTargetIndexBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._renderTargetIndexBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,Gt,this.gl.STATIC_DRAW)):this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._renderTargetIndexBuffer)}loadShaders(e=null,t,r){if(this.gl==null)return Promise.reject(new Error("'gl' is null. WebGLRenderingContext is required. Please call CubismRenderer_WebGL.startUp()."));let i=q.getInstance().getShader(this.gl);return(i._shaderSets.length==0||!i._isShaderLoaded)&&(e!=null&&i.setShaderPath(e),i.setShaderSources(r)),i.generateShaders(t,this._model!=null?this._model.isBlendModeEnabled():!0)}doDrawModel(e=null){this.beforeDrawModelRenderTarget();let t=this._renderStateFbo,r=this._renderStateViewport;if(this._drawableClippingManager!=null){this.preDraw();for(let i=0;i<this._drawableClippingManager.getRenderTextureCount();++i)(this._drawableMasks[i].getBufferWidth()!=this._drawableClippingManager.getClippingMaskBufferSize()||this._drawableMasks[i].getBufferHeight()!=this._drawableClippingManager.getClippingMaskBufferSize())&&this._drawableMasks[i].createRenderTarget(this.gl,this._drawableClippingManager.getClippingMaskBufferSize(),this._drawableClippingManager.getClippingMaskBufferSize(),t);this.isUsingHighPrecisionMask()?this._drawableClippingManager.setupMatrixForHighPrecision(this.getModel(),!1):this._drawableClippingManager.setupClippingContext(this.getModel(),this,t,r,0,this._renderStateKnown)}if(this._offscreenClippingManager!=null){this.preDraw();for(let i=0;i<this._offscreenClippingManager.getRenderTextureCount();++i)(this._offscreenMasks[i].getBufferWidth()!=this._offscreenClippingManager.getClippingMaskBufferSize()||this._offscreenMasks[i].getBufferHeight()!=this._offscreenClippingManager.getClippingMaskBufferSize())&&this._offscreenMasks[i].createRenderTarget(this.gl,this._offscreenClippingManager.getClippingMaskBufferSize(),this._offscreenClippingManager.getClippingMaskBufferSize(),t);this.isUsingHighPrecisionMask()?this._offscreenClippingManager.setupMatrixForOffscreenHighPrecision(this.getModel(),!1,this.getMvpMatrix()):this._offscreenClippingManager.setupClippingContext(this.getModel(),this,t,r,1,this._renderStateKnown)}this.preDraw(),this.drawObjectLoop(t),this.afterDrawModelRenderTarget()}drawObjectLoop(e){let t=this.getModel(),r=t.getDrawableCount(),i=r+t.getOffscreenCount(),s=t.getRenderOrders();this._currentOffscreen=null,this._currentFbo=e,this._modelRootFbo=e;for(let n=0;n<i;++n){let a=s[n];n<r?(this._sortedObjectsIndexList[a]=n,this._sortedObjectsTypeList[a]=0):n<i&&(this._sortedObjectsIndexList[a]=n-r,this._sortedObjectsTypeList[a]=1)}for(let n=0;n<i;++n){let a=this._sortedObjectsIndexList[n],l=this._sortedObjectsTypeList[n];this.renderObject(a,l)}for(;this._currentOffscreen!=null;)this.submitDrawToParentOffscreen(this._currentOffscreen.getOffscreenIndex(),1)}renderObject(e,t){switch(t){case 0:this.drawDrawable(e,this._modelRootFbo);break;case 1:this.addOffscreen(e);break;default:D("Unknown object type: "+t);break}}drawDrawable(e,t){if(!this.getModel().getDrawableDynamicFlagIsVisible(e))return;this.submitDrawToParentOffscreen(e,0);let r=this._drawableClippingManager!=null?this._drawableClippingManager.getClippingContextListForDraw()[e]:null;if(r!=null&&this.isUsingHighPrecisionMask()){r._isUsing&&(this.gl.viewport(0,0,this._drawableClippingManager.getClippingMaskBufferSize(),this._drawableClippingManager.getClippingMaskBufferSize()),this.preDraw(),this.getDrawableMaskBuffer(r._bufferIndex).beginDraw(this._currentFbo),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{let i=r._clippingIdCount;for(let s=0;s<i;s++){let n=r._clippingIdList[s];this._model.getDrawableDynamicFlagVertexPositionsDidChange(n)&&(this.setIsCulling(this._model.getDrawableCulling(n)!=!1),this.setClippingContextBufferForMask(r),this.drawMeshWebGL(this._model,n))}this.getDrawableMaskBuffer(r._bufferIndex).endDraw(),this.setClippingContextBufferForMask(null),this.gl.viewport(0,0,this._modelRenderTargetWidth,this._modelRenderTargetHeight),this.preDraw()}}this.setClippingContextBufferForDrawable(r),this.setIsCulling(this.getModel().getDrawableCulling(e)),this.drawMeshWebGL(this._model,e)}drawMeshWebGL(e,t){if(this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW),this.isGeneratingMask()?q.getInstance().getShader(this.gl).setupShaderProgramForMask(this,e,t):q.getInstance().getShader(this.gl).setupShaderProgramForDrawable(this,e,t),!!q.getInstance().getShader(this.gl)._isShaderLoaded){{let r=e.getDrawableVertexIndexCount(t);this.gl.drawElements(this.gl.TRIANGLES,r,this.gl.UNSIGNED_SHORT,0)}this.setClippingContextBufferForDrawable(null),this.setClippingContextBufferForMask(null)}}submitDrawToParentOffscreen(e,t){if(this._currentOffscreen==null||e==at)return;let r=this.getModel().getOffscreenOwnerIndices()[this._currentOffscreen.getOffscreenIndex()];if(r==at)return;let i=-1;switch(t){case 0:i=this.getModel().getDrawableParentPartIndex(e);break;case 1:i=this.getModel().getPartParentPartIndices()[this.getModel().getOffscreenOwnerIndices()[e]];break;default:return}for(;i!=-1;){if(i==r)return;i=this.getModel().getPartParentPartIndices()[i]}this.drawOffscreen(this._currentOffscreen),this.submitDrawToParentOffscreen(e,t)}addOffscreen(e){if(this._currentOffscreen!=null&&this._currentOffscreen.getOffscreenIndex()!=e){let s=!1,n=this.getModel().getOffscreenOwnerIndices()[e],a=this.getModel().getPartParentPartIndices()[n],l=this._currentOffscreen.getOffscreenIndex(),o=this.getModel().getOffscreenOwnerIndices()[l];for(;a!=-1;){if(a==o){s=!0;break}a=this.getModel().getPartParentPartIndices()[a]}s||this.submitDrawToParentOffscreen(e,1)}let t=this._offscreenList[e];t.getRenderTexture()==null||t.getBufferWidth()!=this._modelRenderTargetWidth||t.getBufferHeight()!=this._modelRenderTargetHeight||t.getUsingRenderTextureState()?t.setOffscreenRenderTarget(this.gl,this._modelRenderTargetWidth,this._modelRenderTargetHeight,this._currentFbo):t.startUsingRenderTexture();let r=t.getParentPartOffscreen();t.setOldOffscreen(r);let i=null;r!=null&&(i=r.getRenderTexture()),i==null&&(i=this._modelRootFbo),t.beginDraw(i),this.gl.viewport(0,0,this._modelRenderTargetWidth,this._modelRenderTargetHeight),t.clear(0,0,0,0),this._currentOffscreen=t,this._currentFbo=t.getRenderTexture()}drawOffscreen(e){let t=e.getOffscreenIndex(),r=this._offscreenClippingManager!=null?this._offscreenClippingManager.getClippingContextListForOffscreen()[t]:null;if(r!=null&&this.isUsingHighPrecisionMask()){r._isUsing&&(this.gl.viewport(0,0,this._offscreenClippingManager.getClippingMaskBufferSize(),this._offscreenClippingManager.getClippingMaskBufferSize()),this.preDraw(),this.getOffscreenMaskBuffer(r._bufferIndex).beginDraw(this._currentFbo),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{let i=r._clippingIdCount;for(let s=0;s<i;s++){let n=r._clippingIdList[s];this.getModel().getDrawableDynamicFlagVertexPositionsDidChange(n)&&(this.setIsCulling(this.getModel().getDrawableCulling(n)!=!1),this.setClippingContextBufferForMask(r),this.drawMeshWebGL(this.getModel(),n))}}this.getOffscreenMaskBuffer(r._bufferIndex).endDraw(),this.setClippingContextBufferForMask(null),this.gl.viewport(0,0,this._modelRenderTargetWidth,this._modelRenderTargetHeight),this.preDraw()}this.setClippingContextBufferForOffscreen(r),this.setIsCulling(this._model.getOffscreenCulling(t)!=!1),this.drawOffscreenWebGL(this.getModel(),e)}drawOffscreenWebGL(e,t){this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW),q.getInstance().getShader(this.gl).setupShaderProgramForOffscreen(this,e,t),t.endDraw(),this._currentOffscreen=this._currentOffscreen.getOldOffscreen(),this._currentFbo=t.getOldFBO(),this._currentFbo==null&&(this._currentOffscreen=this._modelRenderTargets[0],this._currentFbo=this._modelRenderTargets[0].getRenderTexture(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentFbo)),this.bindRenderTargetIndexBuffer(),this.gl.drawElements(this.gl.TRIANGLES,Gt.length,this.gl.UNSIGNED_SHORT,0),t.stopUsingRenderTexture(),this.setClippingContextBufferForMask(null),this.setClippingContextBufferForOffscreen(null)}saveProfile(){this._rendererProfile.save()}restoreProfile(){this._rendererProfile.restore()}beforeDrawModelRenderTarget(){if(this._modelRenderTargets.length!=0){for(let e=0;e<this._modelRenderTargets.length;++e)(this._modelRenderTargets[e].getBufferWidth()!=this._modelRenderTargetWidth||this._modelRenderTargets[e].getBufferHeight()!=this._modelRenderTargetHeight)&&this._modelRenderTargets[e].createRenderTarget(this.gl,this._modelRenderTargetWidth,this._modelRenderTargetHeight,this._currentFbo);this._modelRenderTargets[0].beginDraw(),this._modelRenderTargets[0].clear(0,0,0,0)}}afterDrawModelRenderTarget(){this._modelRenderTargets.length!=0&&(this._modelRenderTargets[0].endDraw(),q.getInstance().getShader(this.gl).setupShaderProgramForOffscreenRenderTarget(this),q.getInstance().getShader(this.gl)._isShaderLoaded&&(this.bindRenderTargetIndexBuffer(),this.gl.drawElements(this.gl.TRIANGLES,Gt.length,this.gl.UNSIGNED_SHORT,0)))}getOffscreenMaskBuffer(e){return this._offscreenMasks[e]}static doStaticRelease(){q.deleteInstance()}setRenderState(e,t){this._renderStateFbo=e,this._renderStateKnown=!0,this._renderStateViewport[0]=t[0],this._renderStateViewport[1]=t[1],this._renderStateViewport[2]=t[2],this._renderStateViewport[3]=t[3],this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.gl.viewport(t[0],t[1],t[2],t[3]),(this._modelRenderTargetWidth!=t[2]||this._modelRenderTargetHeight!=t[3])&&(this._modelRenderTargetWidth=t[2],this._modelRenderTargetHeight=t[3])}preDraw(){if(this.gl.disable(this.gl.SCISSOR_TEST),this.gl.disable(this.gl.STENCIL_TEST),this.gl.disable(this.gl.DEPTH_TEST),this.gl.frontFace(this.gl.CW),this.gl.enable(this.gl.BLEND),this.gl.colorMask(!0,!0,!0,!0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.getAnisotropy()>0&&this._extension)for(let e=0;e<this._textures.size;++e)this.gl.bindTexture(this.gl.TEXTURE_2D,this._textures.get(e)),this.gl.texParameterf(this.gl.TEXTURE_2D,this._extension.TEXTURE_MAX_ANISOTROPY_EXT,this.getAnisotropy())}getDrawableMaskBuffer(e){return this._drawableMasks[e]}setClippingContextBufferForMask(e){this._clippingContextBufferForMask=e}getClippingContextBufferForMask(){return this._clippingContextBufferForMask}setClippingContextBufferForDrawable(e){this._clippingContextBufferForDraw=e}getClippingContextBufferForDrawable(){return this._clippingContextBufferForDraw}setClippingContextBufferForOffscreen(e){this._clippingContextBufferForOffscreen=e}getClippingContextBufferForOffscreen(){return this._clippingContextBufferForOffscreen}isGeneratingMask(){return this.getClippingContextBufferForMask()!=null}startUp(e){if(this.gl=e,this._drawableClippingManager&&this._drawableClippingManager.setGL(e),this._offscreenClippingManager&&this._offscreenClippingManager.setGL(e),q.getInstance().setGlContext(e),this._rendererProfile.setGl(e),this._extension=this.gl.getExtension("EXT_texture_filter_anisotropic")||this.gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this.gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),this._model.isUsingMasking()){this._drawableMasks.length=this._drawableClippingManager.getRenderTextureCount();for(let t=0;t<this._drawableMasks.length;++t){let r=new Ae;r.createRenderTarget(this.gl,this._drawableClippingManager.getClippingMaskBufferSize(),this._drawableClippingManager.getClippingMaskBufferSize(),this._currentFbo),this._drawableMasks[t]=r}}if(this._model.isBlendModeEnabled()){this._modelRenderTargets.length=0;let t=3;this._modelRenderTargets.length=t;for(let i=0;i<t;++i){let s=new ji;s.createRenderTarget(this.gl,this._modelRenderTargetWidth,this._modelRenderTargetHeight,this._currentFbo),this._modelRenderTargets[i]=s}if(this._model.isUsingMaskingForOffscreen()){this._offscreenMasks.length=this._offscreenClippingManager.getRenderTextureCount();for(let i=0;i<this._offscreenMasks.length;++i){let s=new Ae;s.createRenderTarget(this.gl,this._offscreenClippingManager.getClippingMaskBufferSize(),this._offscreenClippingManager.getClippingMaskBufferSize(),this._currentFbo),this._offscreenMasks[i]=s}}let r=this._model.getOffscreenCount();if(r>0){this._offscreenList=new Array(r);for(let i=0;i<r;++i){let s=new ji;s.setOffscreenIndex(i),this._offscreenList[i]=s}this.setupParentOffscreens(this._model,r)}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentFbo)}_textures;_sortedObjectsIndexList;_sortedObjectsTypeList;_rendererProfile;_drawableClippingManager;_clippingContextBufferForMask;_clippingContextBufferForDraw;_clippingContextBufferForOffscreen;_offscreenClippingManager;_modelRenderTargets;_drawableMasks;_offscreenMasks;_offscreenList;_currentFbo;_currentOffscreen;_modelRootFbo;_renderStateFbo=null;_renderStateKnown=!1;_renderStateViewport=[0,0,0,0];_bufferData;_drawableIndexBuffers;_drawableUvBuffers;_renderTargetIndexBuffer;_extension;gl};pt.staticRelease=()=>{cr.doStaticRelease()};(function(e){e.CubismClippingContext=qs,e.CubismClippingManager_WebGL=ct,e.CubismRenderer_WebGL=cr})(Ki||(Ki={}));er=class Ks{static create(t,r){let i=null;if(r&&!this.hasMocConsistency(t))return D("Inconsistent MOC3."),i;let s=Live2DCubismCore.Moc.fromArrayBuffer(t);return s&&(i=new Ks(s),i._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(t)),i}static delete(t){t._moc._release(),t._moc=null,t=null}createModel(){let t=null,r=Live2DCubismCore.Model.fromMoc(this._moc);return r&&(t=new Cs(r),t.initialize(),++this._modelCount),t}deleteModel(t){t!=null&&(t.release(),t=null,--this._modelCount)}constructor(t){this._moc=t,this._modelCount=0,this._mocVersion=0}release(){k(this._modelCount==0),this._moc._release(),this._moc=null}getLatestMocVersion(){return Live2DCubismCore.Version.csmGetLatestMocVersion()}getMocVersion(){return this._mocVersion}static getMocVersionFromBuffer(t){return Live2DCubismCore.Version.csmGetMocVersion(t)}static hasMocConsistency(t){return Live2DCubismCore.Moc.prototype.hasMocConsistency(t)===1}_moc;_modelCount;_mocVersion};(function(e){e.CubismMoc=er})($i||($i={}));es="Meta",Wo="UserDataCount",Yo="TotalUserDataSize",Xt="UserData",zo="Target",Jo="Id",jo="Value",$s=class{constructor(e,t){this._json=G.create(e,t)}release(){G.delete(this._json)}getUserDataCount(){return this._json.getRoot().getValueByString(es).getValueByString(Wo).toInt()}getTotalUserDataSize(){return this._json.getRoot().getValueByString(es).getValueByString(Yo).toInt()}getUserDataTargetType(e){return this._json.getRoot().getValueByString(Xt).getValueByIndex(e).getValueByString(zo).getRawString()}getUserDataId(e){return P.getIdManager().getId(this._json.getRoot().getValueByString(Xt).getValueByIndex(e).getValueByString(Jo).getRawString())}getUserDataValue(e){return this._json.getRoot().getValueByString(Xt).getValueByIndex(e).getValueByString(jo).getRawString()}_json};(function(e){e.CubismModelUserDataJson=$s})(ts||(ts={}));Zo="ArtMesh",en=class{targetType;targetId;value},tr=class tn{static create(t,r){let i=new tn;return i.parseUserData(t,r),i}static delete(t){t!=null&&(t.release(),t=null)}getArtMeshUserDatas(){return this._artMeshUserDataNode}parseUserData(t,r){let i=new $s(t,r);if(!i){i.release(),i=void 0;return}let s=P.getIdManager().getId(Zo),n=i.getUserDataCount(),a=this._userDataNodes.length;this._userDataNodes.length=n;for(let l=0;l<n;l++){let o=new en;o.targetId=i.getUserDataId(l),o.targetType=P.getIdManager().getId(i.getUserDataTargetType(l)),o.value=i.getUserDataValue(l),this._userDataNodes[a++]=o,o.targetType==s&&this._artMeshUserDataNode.push(o)}i.release(),i=void 0}constructor(){this._userDataNodes=new Array,this._artMeshUserDataNode=new Array}release(){for(let t=0;t<this._userDataNodes.length;++t)this._userDataNodes[t]=null;this._userDataNodes=null}_userDataNodes;_artMeshUserDataNode};(function(e){e.CubismModelUserData=tr,e.CubismModelUserDataNode=en})(rs||(rs={}));rn=class sn{isInitialized(){return this._initialized}setInitialized(t){this._initialized=t}isUpdating(){return this._updating}setUpdating(t){this._updating=t}setDragging(t,r){this._dragManager.set(t,r)}getModelMatrix(){return this._modelMatrix}setRenderTargetSize(t,r){this._renderer&&this._renderer.setRenderTargetSize(t,r)}setOpacity(t){this._opacity=t}getOpacity(){return this._opacity}loadModel(t,r=!1){if(this._moc=er.create(t,r),this._moc==null){D("Failed to CubismMoc.create().");return}if(this._model=this._moc.createModel(),this._model==null){D("Failed to CreateModel().");return}this._model.saveParameters(),this._modelMatrix=new ar(this._model.getCanvasWidth(),this._model.getCanvasHeight())}loadMotion(t,r,i,s,n,a,l,o,u=!1){if(t==null||r==0)return D("Failed to loadMotion()."),null;let c=Os.create(t,r,s,n,u);if(c==null)return D("Failed to create motion from buffer in LoadMotion()"),null;if(a){let d=a.getMotionFadeInTimeValue(l,o);d>=0&&c.setFadeInTime(d);let h=a.getMotionFadeOutTimeValue(l,o);h>=0&&c.setFadeOutTime(h)}return c}loadExpression(t,r,i){return t==null||r==0?(D("Failed to loadExpression()."),null):Te.create(t,r)}loadPose(t,r){if(t==null||r==0){D("Failed to loadPose().");return}this._pose=Jt.create(t,r)}loadUserData(t,r){if(t==null||r==0){D("Failed to loadUserData().");return}this._modelUserData=tr.create(t,r)}loadPhysics(t,r){if(t==null||r==0){D("Failed to loadPhysics().");return}this._physics=Kt.create(t,r)}isHit(t,r,i){let s=this._model.getDrawableIndex(t);if(s<0)return!1;let n=this._model.getDrawableVertexCount(s),a=this._model.getDrawableVertices(s),l=a[0],o=a[0],u=a[1],c=a[1];for(let g=1;g<n;++g){let A=a[$.vertexOffset+g*$.vertexStep],p=a[$.vertexOffset+g*$.vertexStep+1];A<l&&(l=A),A>o&&(o=A),p<u&&(u=p),p>c&&(c=p)}let d=this._modelMatrix.invertTransformX(r),h=this._modelMatrix.invertTransformY(i);return l<=d&&d<=o&&u<=h&&h<=c}getModel(){return this._model}getMocVersionFromBuffer(t){return er.getMocVersionFromBuffer(t)}getRenderer(){return this._renderer}createRenderer(t,r,i=1){this._renderer&&this.deleteRenderer(),this._renderer=new cr(t,r),this._renderer.initialize(this._model,i)}deleteRenderer(){this._renderer!=null&&(this._renderer.release(),this._renderer=null)}motionEventFired(t){de("{0}",t)}static cubismDefaultMotionEventCallback(t,r,i){let s=i;s?.motionEventFired(r)}constructor(){this._moc=null,this._model=null,this._motionManager=null,this._expressionManager=null,this._eyeBlink=null,this._breath=null,this._modelMatrix=null,this._pose=null,this._dragManager=null,this._physics=null,this._modelUserData=null,this._initialized=!1,this._updating=!1,this._opacity=1,this._mocConsistency=!1,this._debugMode=!1,this._renderer=null,this._motionManager=new Qs,this._motionManager.setEventCallback(sn.cubismDefaultMotionEventCallback,this),this._expressionManager=new ws,this._dragManager=new Ms}release(){this._motionManager!=null&&(this._motionManager.release(),this._motionManager=null),this._expressionManager!=null&&(this._expressionManager.release(),this._expressionManager=null),this._moc!=null&&(this._moc.deleteModel(this._model),this._moc.release(),this._moc=null),this._modelMatrix=null,Jt.delete(this._pose),nr.delete(this._eyeBlink),sr.delete(this._breath),this._dragManager=null,Kt.delete(this._physics),tr.delete(this._modelUserData),this.deleteRenderer()}_moc;_model;_motionManager;_expressionManager;_eyeBlink;_breath;_modelMatrix;_pose;_dragManager;_physics;_modelUserData;_initialized;_updating;_opacity;_mocConsistency;_motionConsistency;_debugMode;_renderer};(function(e){e.CubismUserModel=rn})(is||(is={}));ge=class{static sortFunction(e,t){if(!e||!t){if(!e&&!t)return 0;if(!e)return 1;if(!t)return-1}return e.getExecutionOrder()-t.getExecutionOrder()}_executionOrder;_changeListeners=[];constructor(e=0){this._executionOrder=e}getExecutionOrder(){return this._executionOrder}setExecutionOrder(e){this._executionOrder!==e&&(this._executionOrder=e,this.notifyChangeListeners())}addChangeListener(e){e&&this._changeListeners.indexOf(e)===-1&&this._changeListeners.push(e)}removeChangeListener(e){let t=this._changeListeners.indexOf(e);t>=0&&this._changeListeners.splice(t,1)}notifyChangeListeners(){for(let e of this._changeListeners)e.onUpdaterChanged(this)}};(function(e){e.ICubismUpdater=ge})(ss||(ss={}));nn=class extends ge{_breath;constructor(e,t){super(t??500),this._breath=e}onLateUpdate(e,t){e&&this._breath.updateParameters(e,t)}};(function(e){e.CubismBreathUpdater=nn})(ns||(ns={}));an=class extends ge{_expressionManager;constructor(e,t){super(t??300),this._expressionManager=e}onLateUpdate(e,t){e&&this._expressionManager.updateMotion(e,t)}};(function(e){e.CubismExpressionUpdater=an})(as||(as={}));on=class extends ge{_motionUpdated;_eyeBlink;constructor(e,t,r){super(r??200),this._motionUpdated=e,this._eyeBlink=t}onLateUpdate(e,t){e&&(this._motionUpdated()||this._eyeBlink.updateParameters(e,t))}};(function(e){e.CubismEyeBlinkUpdater=on})(os||(os={}));ln=class extends ge{_look;_dragManager;constructor(e,t,r){super(r??400),this._look=e,this._dragManager=t}onLateUpdate(e,t){if(!e)return;this._dragManager.update(t);let r=this._dragManager.getX(),i=this._dragManager.getY();this._look.updateParameters(e,r,i)}};(function(e){e.CubismLookUpdater=ln})(ls||(ls={}));un=class extends ge{_physics;constructor(e,t){super(t??600),this._physics=e}onLateUpdate(e,t){e&&this._physics.evaluate(e,t)}};(function(e){e.CubismPhysicsUpdater=un})(us||(us={}));hn=class extends ge{_pose;constructor(e,t){super(t??800),this._pose=e}onLateUpdate(e,t){e&&this._pose.updateParameters(e,t)}};(function(e){e.CubismPoseUpdater=hn})(hs||(hs={}));cn=class{_cubismUpdatableList;_needsSort;constructor(){this._cubismUpdatableList=[],this._needsSort=!1}release(){for(let e of this._cubismUpdatableList)e&&e.removeChangeListener(this);this._cubismUpdatableList.length=0}addUpdatableList(e){e&&(this.hasUpdatable(e)||(this._cubismUpdatableList.push(e),e.addChangeListener(this),this._needsSort=!0))}removeUpdatableList(e){if(!e)return!1;let t=this._cubismUpdatableList.indexOf(e);return t>=0?(this._cubismUpdatableList.splice(t,1),e.removeChangeListener(this),!0):!1}sortUpdatableList(){this._cubismUpdatableList.sort(ge.sortFunction),this._needsSort=!1}onLateUpdate(e,t){if(e){this._needsSort&&this.sortUpdatableList();for(let r=0;r<this._cubismUpdatableList.length;++r){let i=this._cubismUpdatableList[r];i&&i.onLateUpdate(e,t)}}}getUpdatableCount(){return this._cubismUpdatableList.length}getUpdatable(e){return e<0||e>=this._cubismUpdatableList.length?null:this._cubismUpdatableList[e]}hasUpdatable(e){return this._cubismUpdatableList.indexOf(e)>=0}clearUpdatableList(){for(let e of this._cubismUpdatableList)e&&e.removeChangeListener(this);this._cubismUpdatableList.length=0,this._needsSort=!1}onUpdaterChanged(e){this._needsSort=!0}};(function(e){e.CubismUpdateScheduler=cn})(cs||(cs={}));ot=0;il=class{disposed=!1;failure;pending=new Map;track(e){return this.failure?Promise.reject(this.failure):this.disposed?Promise.resolve({status:"disposed"}):new Promise((t,r)=>{this.pending.set(e,{reason:"completed",reject:r,resolve:t})})}interruptActive(){for(let e of this.pending.values())e.reason="interrupted"}settleFinished(e){for(let[t,r]of[...this.pending])e(t)&&(this.pending.delete(t),r.resolve({status:r.reason}))}fail(e){this.failure??=e;for(let t of this.takeAll())t.reject(this.failure)}dispose(){if(!this.disposed){this.disposed=!0;for(let e of this.takeAll())e.resolve({status:"disposed"})}}takeAll(){let e=[...this.pending.values()];return this.pending.clear(),e}},We=new Map;al=1,ol=3,ll=1e3,fs={force:3,idle:1,normal:2};ul=550,hl=class extends ge{callbacks;constructor(e){super(ul),this.callbacks=e}onLateUpdate(e,t){for(let r of this.callbacks)r(t*1e3)}},cl=class extends rn{stage;modelUrl;setting;shaderBaseUrl;shaderSources;idleMotion;releaseFramework;model3Version;diagnostics;resolveAsset;afterMotionCallbacks=new Set;beforePhysicsCallbacks=new Set;assetController=new AbortController;expressionCache=new Map;loadedMotions=new Set;layoutMatrix;manualParameters=new Map;mvpMatrix;motionCache=new Map;motionStates=new il;parameterIds=new Map;renderContext;releaseRenderContext;renderError;stopErrorWatch;pendingExpressionKeys=new Set;pendingMotionKeys=new Set;scheduler=new cn;textures=[];viewport=[0,0,1,1];bounds={centerX:0,centerY:0,height:1,width:1};detachDriver;disposed=!1;expressionGeneration=0;eyeBlinkIds=[];idlePending=!1;look;mvpDirty=!0;motionUpdated=!1;motionGeneration=0;transform={scale:1,x:0,y:0};constructor(e,t,r,i,s,n,a,l,o,u){super(),this.stage=e,this.modelUrl=t,this.setting=r,this.shaderBaseUrl=i,this.shaderSources=s,this.idleMotion=n,this.releaseFramework=a,this.model3Version=l,this.diagnostics=o,this.resolveAsset=u}parameterId(e){let t=this.parameterIds.get(e);if(t)return t;let r=P.getIdManager().getId(e);return this.parameterIds.set(e,r),r}async initialize(e){let t=()=>this.assetController.abort(e?.reason);e?.aborted&&t(),e?.addEventListener("abort",t,{once:!0});try{let r=this.setting.getModelFileName();if(!r)throw new m("model-load-failed","model3.json does not declare FileReferences.Moc.",{details:se("model3",this.modelUrl)});let i=te(r,this.modelUrl),s=await Ce(this.diagnostics,"mocFetch",()=>ue(i,"moc3",this.assetController.signal,this.resolveAsset));try{j(this.diagnostics,"load","mocParse",()=>this.loadModel(s,!0))}catch(l){throw new m("model-load-failed",`Failed to parse moc3 asset ${i}.`,{cause:l,details:se("moc3",i)})}if(!this.getModel())throw new m("model-load-failed","Cubism Core rejected the moc3 model.",{details:se("moc3",i)});this.layoutMatrix=new ar(this.getModel().getCanvasWidth(),this.getModel().getCanvasHeight());let n=new Map;this.setting.getLayoutMap(n),this.layoutMatrix.setupFromLayout(n),this.bounds=el({height:this.getModel().getCanvasHeight(),width:this.getModel().getCanvasWidth()},this.layoutMatrix),await Ce(this.diagnostics,"optionalAssets",()=>this.loadOptionalAssets()),this.setupEffects(),await this.setupRenderer(),this.getModel().saveParameters();let a=xe(this.stage);this.detachDriver=a.attachDriver({draw:()=>this.draw(),resize:(l,o)=>this.resize(l,o),update:l=>this.updateFrame(l)}),this.stopErrorWatch=this.stage.onError(l=>this.failMotions(l)),this.prefetchIdleMotions()}finally{e?.removeEventListener("abort",t)}}async prefetchIdleMotions(){if(await new Promise(t=>{let r,i=()=>{clearTimeout(r),t()};r=setTimeout(()=>{this.assetController.signal.removeEventListener("abort",i),t()},ll),this.assetController.signal.addEventListener("abort",i,{once:!0})}),this.disposed||this.idleMotion===!1)return;let e=this.setting.getMotionCount(this.idleMotion.group);for(let t=0;t<e;t++){if(this.disposed)return;try{await this.loadMotionAsset(this.idleMotion.group,t)}catch{}}}async loadOptionalAssets(){let e=this.assetController.signal,t=this.setting.getPhysicsFileName(),r=this.setting.getPoseFileName(),i=this.setting.getUserDataFile(),s=t?te(t,this.modelUrl):void 0,n=r?te(r,this.modelUrl):void 0,a=i?te(i,this.modelUrl):void 0,[l,o,u]=await Promise.all([s?ue(s,"physics",e,this.resolveAsset):void 0,n?ue(n,"pose",e,this.resolveAsset):void 0,a?ue(a,"user-data",e,this.resolveAsset):void 0]);try{l&&this.loadPhysics(l,l.byteLength)}catch(c){throw new m("model-load-failed",`Failed to parse physics asset ${s}.`,{cause:c,details:se("physics",s)})}try{o&&this.loadPose(o,o.byteLength)}catch(c){throw new m("model-load-failed",`Failed to parse pose asset ${n}.`,{cause:c,details:se("pose",n)})}try{u&&this.loadUserData(u,u.byteLength)}catch(c){throw new m("model-load-failed",`Failed to parse user data asset ${a}.`,{cause:c,details:se("user-data",a)})}}setupEffects(){this.eyeBlinkIds=Array.from({length:this.setting.getEyeBlinkParameterCount()},(e,t)=>this.setting.getEyeBlinkParameterId(t)),this.eyeBlinkIds.length>0&&(this._eyeBlink=nr.create(this.setting),this.scheduler.addUpdatableList(new on(()=>this.motionUpdated,this._eyeBlink,300))),this._breath=sr.create(),this._breath.setParameters([new De(this.parameterId(S.ParamAngleX),0,15,6.5345,.5),new De(this.parameterId(S.ParamAngleY),0,8,3.5345,.5),new De(this.parameterId(S.ParamAngleZ),0,10,5.5345,.5),new De(this.parameterId(S.ParamBodyAngleX),0,4,15.5345,.5),new De(this.parameterId(S.ParamBreath),.5,.5,3.2345,1)]),this.scheduler.addUpdatableList(new nn(this._breath)),this._physics&&this.scheduler.addUpdatableList(new un(this._physics)),this._pose&&this.scheduler.addUpdatableList(new hn(this._pose)),this._expressionManager&&this.scheduler.addUpdatableList(new an(this._expressionManager,200)),this.look=zt.create(),this.look.setParameters([new Ie(this.parameterId(S.ParamAngleX),30,0,0),new Ie(this.parameterId(S.ParamAngleY),0,30,0),new Ie(this.parameterId(S.ParamAngleZ),0,0,-30),new Ie(this.parameterId(S.ParamBodyAngleX),10,0,0),new Ie(this.parameterId(S.ParamEyeBallX),1,0,0),new Ie(this.parameterId(S.ParamEyeBallY),0,1,0)]),this.scheduler.addUpdatableList(new ln(this.look,this._dragManager)),this.scheduler.addUpdatableList(new hl(this.beforePhysicsCallbacks)),this.scheduler.sortUpdatableList()}async setupRenderer(){let{canvas:e,gl:t}=xe(this.stage);this.renderContext=t,this.releaseRenderContext=nl(t),this.createRenderer(e.width,e.height);let r=this.getRenderer();r.startUp(t),r.setIsPremultipliedAlpha(!0);let i=[];for(let a=0;a<this.setting.getTextureCount();a++){let l=this.setting.getTextureFileName(a);if(!l)throw new m("model-load-failed",`model3.json declares an empty texture at index ${a}.`,{details:se("texture",this.modelUrl)});i.push(te(l,this.modelUrl))}let s=i.map(a=>Hr(a,this.assetController.signal,this.diagnostics,this.resolveAsset));for(let a of s)a.catch(()=>{});let n=async()=>{await Promise.allSettled(s.map(async a=>Ne(await a)))};try{await Ce(this.diagnostics,"shaderSetup",()=>r.loadShaders(this.shaderBaseUrl,this.assetController.signal,this.shaderSources))}catch(a){throw await n(),a instanceof m?a:new m("render-error",a instanceof Error?a.message:"Cubism shader loading failed.",{cause:a,details:qo(a)})}try{for(let a=0;a<s.length;a++){let l=await s[a];if(this.assetController.signal.aborted)throw Ne(l),this.assetController.signal.reason;let o=Wr(t,l,i[a],this.diagnostics);this.textures.push(o),this.diagnostics?.changeResource("texture",1),r.bindTexture(a,o)}}catch(a){throw await n(),a}}updateFrame(e){if(this.disposed)return;let t=e/1e3;if(!this.diagnostics){this.getModel().loadParameters(),this.motionUpdated=!1,this._motionManager.isFinished()?this.scheduleIdle():this.motionUpdated=this._motionManager.updateMotion(this.getModel(),t),this.getModel().saveParameters(),this.settleFinishedMotions(),this.scheduler.onLateUpdate(this.getModel(),t);for(let[r,i]of this.manualParameters)this.getModel().setParameterValueById(this.parameterId(r),i);for(let r of this.afterMotionCallbacks)r(e);this.getModel().update();return}j(this.diagnostics,"frame","motion",()=>{this.getModel().loadParameters(),this.motionUpdated=!1,this._motionManager.isFinished()?this.scheduleIdle():this.motionUpdated=this._motionManager.updateMotion(this.getModel(),t),this.getModel().saveParameters()}),this.settleFinishedMotions(),j(this.diagnostics,"frame","effectsPhysicsPose",()=>{this.scheduler.onLateUpdate(this.getModel(),t)}),j(this.diagnostics,"frame","manualParameters",()=>{for(let[r,i]of this.manualParameters)this.getModel().setParameterValueById(this.parameterId(r),i)}),j(this.diagnostics,"frame","externalDrivers",()=>{for(let r of this.afterMotionCallbacks)r(e)}),j(this.diagnostics,"frame","coreUpdate",()=>{this.getModel().update()})}scheduleIdle(){if(this.idleMotion===!1||this.idlePending)return;let{group:e,weights:t}=this.idleMotion,r=this.setting.getMotionCount(e);r!==0&&(this.idlePending=!0,this.playMotion(e,Dr(r,t),al).catch(i=>{this.disposed||xe(this.stage).reportError(dn(i,"Idle motion failed"))}).finally(()=>{this.idlePending=!1}))}async ensureAssetBuffer(e){return await tl(e,()=>ue(e.url,e.type,this.assetController.signal,this.resolveAsset)),e}async loadMotionAsset(e,t){let r=`${e}:${t}`,i=this.motionCache.get(r);if(i)return i;let s=(async()=>{this.pendingMotionKeys.add(r),this.diagnostics?.changeResource("pendingMotion",1);try{let n=te(this.setting.getMotionFileName(e,t),this.modelUrl),a=await ue(n,"motion",this.assetController.signal,this.resolveAsset),l=this.parseMotion(a,r,e,t,n);return this.loadedMotions.add(l),{motion:l,type:"motion",url:n}}finally{this.pendingMotionKeys.delete(r)&&this.diagnostics?.changeResource("pendingMotion",-1)}})();return this.motionCache.set(r,s),s.catch(()=>this.motionCache.delete(r)),s}parseMotion(e,t,r,i,s=te(this.setting.getMotionFileName(r,i),this.modelUrl)){let n=this.loadMotion(e,e.byteLength,t,void 0,void 0,this.setting,r,i,!0);if(!n)throw new m("model-load-failed",`Failed to parse motion ${t}.`,{details:se("motion",s)});return n.setEffectIds(this.eyeBlinkIds,[]),n}motionGroupNames(){return Array.from({length:this.setting.getMotionGroupCount()},(e,t)=>this.setting.getMotionGroupName(t))}failMotions(e){this.renderError??=e,this.motionStates.fail(this.renderError)}settleFinishedMotions(){this.motionStates.settleFinished(e=>this._motionManager.isFinishedByHandle(e))}async playMotion(e,t,r,i={}){if(this.disposed)return{status:"disposed"};if(this.renderError)throw this.renderError;let s=this.setting.getMotionCount(e);if(s===0)throw new m("invalid-props",`Unknown Live2D motion group: ${e}. Available groups: ${this.motionGroupNames().join(", ")||"(none)"}`);let n=t??Math.floor(Math.random()*s);if(!Number.isInteger(n)||n<0||n>=s)throw new m("invalid-props",`Motion index ${n} is outside group ${e} (0-${s-1}).`);if(r===ol)this._motionManager.setReservePriority(r);else if(!this._motionManager.reserveMotion(r))return{status:"skipped"};let a=++this.motionGeneration,l,o;try{let u=await this.loadMotionAsset(e,n);if(this.disposed)return{status:"disposed"};if(a!==this.motionGeneration)return{status:"skipped"};if($e(i)){if(await this.ensureAssetBuffer(u),this.disposed)return{status:"disposed"};if(a!==this.motionGeneration)return{status:"skipped"}}if(o=gs(u,i,c=>this.parseMotion(c,`${e}:${n}`,e,n),c=>Se.delete(c)),l=this._motionManager.startMotionPriority(o.motion,o.autoDelete,r),l===-1)return o.releaseBeforeStart(),{status:"skipped"};o.transferToQueue(),this.motionStates.interruptActive()}catch(u){if(o?.releaseBeforeStart(),this.disposed)return{status:"disposed"};throw a===this.motionGeneration&&this._motionManager.setReservePriority(0),u}return this.motionStates.track(l)}hitTestStagePoint(e,t){if(this.disposed||!this.layoutMatrix)return[];(!this.mvpMatrix||this.mvpDirty)&&(this.mvpMatrix=ds(this.stage.getSize(),this.transform,this.layoutMatrix,this.bounds));let r=this.stage.getSize(),i=e/Math.max(1,r.width)*2-1,s=1-t/Math.max(1,r.height)*2,n=this.mvpMatrix.invertTransformX(i),a=this.mvpMatrix.invertTransformY(s),l=[];for(let o=0;o<this.setting.getHitAreasCount();o++){let u=this.getModel().getDrawableIndex(this.setting.getHitAreaId(o));if(u<0||this.getModel().getDrawableOpacity(u)<=0)continue;let c=this.getModel().getDrawableVertexCount(u),d=this.getModel().getDrawableVertices(u);if(c===0)continue;let h=d[0],g=d[0],A=d[1],p=d[1];for(let f=1;f<c;f++){let _=d[f*2],y=d[f*2+1];h=Math.min(h,_),g=Math.max(g,_),A=Math.min(A,y),p=Math.max(p,y)}n>=h&&n<=g&&a>=A&&a<=p&&l.push(this.setting.getHitAreaName(o))}return l}readModelInfo(){let e={};for(let t of this.motionGroupNames())e[t]=this.setting.getMotionCount(t);return{expressions:Array.from({length:this.setting.getExpressionCount()},(t,r)=>this.setting.getExpressionName(r)),hitAreas:Array.from({length:this.setting.getHitAreasCount()},(t,r)=>this.setting.getHitAreaName(r)),motions:e,model3Version:this.model3Version,mocVersion:this._moc?.getMocVersion(),parameters:Array.from({length:this.getModel().getParameterCount()},(t,r)=>({defaultValue:this.getModel().getParameterDefaultValue(r),id:this.getModel().getParameterId(r).getString(),maximum:this.getModel().getParameterMaximumValue(r),minimum:this.getModel().getParameterMinimumValue(r)}))}}findExpression(e){for(let t=0;t<this.setting.getExpressionCount();t++)if(this.setting.getExpressionName(t)===e)return t;return-1}async loadExpressionAsset(e,t){let r=this.expressionCache.get(e);if(r)return r;let i=(async()=>{this.pendingExpressionKeys.add(e),this.diagnostics?.changeResource("pendingExpression",1);try{let s=te(this.setting.getExpressionFileName(t),this.modelUrl),n=await ue(s,"expression",this.assetController.signal,this.resolveAsset),a=this.parseExpression(n,e,s);return this.loadedMotions.add(a),{motion:a,type:"expression",url:s}}finally{this.pendingExpressionKeys.delete(e)&&this.diagnostics?.changeResource("pendingExpression",-1)}})();return this.expressionCache.set(e,i),i.catch(()=>this.expressionCache.delete(e)),i}parseExpression(e,t,r=te(this.setting.getExpressionFileName(this.findExpression(t)),this.modelUrl)){let i=this.loadExpression(e,e.byteLength,t);if(!i)throw new m("model-load-failed",`Failed to parse expression ${t}.`,{details:se("expression",r)});return i}async playExpression(e,t,r){let i=++this.expressionGeneration,s;try{let n=await this.loadExpressionAsset(e,t);if(this.disposed||i!==this.expressionGeneration||$e(r)&&(await this.ensureAssetBuffer(n),this.disposed||i!==this.expressionGeneration))return;if(s=gs(n,r,a=>this.parseExpression(a,e),a=>Se.delete(a)),this._expressionManager.startMotion(s.motion,s.autoDelete)===-1){s.releaseBeforeStart();return}s.transferToQueue()}catch(n){if(s?.releaseBeforeStart(),!this.disposed)throw n}}draw(){if(this.disposed)return;let{gl:e}=xe(this.stage),t=hr.getInstance();t.beginFrameProcess(e);try{let r=this.getRenderer();if(r.setRenderState(null,this.viewport),!this.layoutMatrix)return;(this.mvpDirty||!this.mvpMatrix)&&(this.mvpMatrix=ds(this.stage.getSize(),this.transform,this.layoutMatrix,this.bounds),this.mvpDirty=!1,r.setMvpMatrix(this.mvpMatrix)),r.drawModel(this.shaderBaseUrl)}finally{t.endFrameProcess(e),t.releaseStaleRenderTextures(e)}}resize(e,t){this.viewport[2]=e,this.viewport[3]=t,this.mvpDirty=!0,this.setRenderTargetSize(e,t)}toHandle(){return{clearExpression:()=>{this.disposed||(this.expressionGeneration++,this._expressionManager.stopAllMotions())},clearParameter:e=>{this.manualParameters.delete(e)},dispose:()=>this.disposeModel(),expression:async(e,t)=>{let r=Tr(t),i=this.setting.getExpressionCount();if(i===0){if(e)throw new m("invalid-props",`Unknown Live2D expression: ${e}`);return}let s=e??this.setting.getExpressionName(Math.floor(Math.random()*i)),n=this.findExpression(s);if(n<0)throw new m("invalid-props",`Unknown Live2D expression: ${s}. Available: ${this.readModelInfo().expressions.join(", ")}`);await this.playExpression(s,n,r)},focus:(e,t)=>{let r=this.stage.getSize();this.setDragging(Math.max(-1,Math.min(1,e/Math.max(1,r.width)*2-1)),Math.max(-1,Math.min(1,1-t/Math.max(1,r.height)*2)))},getIntrinsicSize:()=>({height:this.bounds.height,width:this.bounds.width}),getModelInfo:()=>this.readModelInfo(),getParameter:e=>this.getModel().getParameterValueById(this.parameterId(e)),hitTest:(e,t)=>this.hitTestStagePoint(e,t),isMotionPlaying:()=>!this.disposed&&!this._motionManager.isFinished(),motion:async(e,t,r)=>{Ue(r);let i=Ke(r);await this.playMotion(e,t,fs[r?.priority??"force"],i)},playMotion:(e,t,r)=>{Ue(r);let i=Ke(r);return this.playMotion(e,t,fs[r?.priority??"force"],i)},onAfterMotionUpdate:e=>(this.afterMotionCallbacks.add(e),As(()=>this.afterMotionCallbacks.delete(e))),onBeforePhysicsUpdate:e=>(this.beforePhysicsCallbacks.add(e),As(()=>this.beforePhysicsCallbacks.delete(e))),setParameter:(e,t)=>{this.disposed||(this.manualParameters.set(e,t),this.getModel().setParameterValueById(this.parameterId(e),t))},setTransform:e=>{this.transform={...e},this.mvpDirty=!0}}}disposeModel(){if(this.disposed)return;this.disposed=!0,this.motionGeneration++,this.expressionGeneration++,this.assetController.abort(new DOMException("Model disposed","AbortError"));for(let t=this.pendingMotionKeys.size;t>0;t--)this.diagnostics?.changeResource("pendingMotion",-1);this.pendingMotionKeys.clear();for(let t=this.pendingExpressionKeys.size;t>0;t--)this.diagnostics?.changeResource("pendingExpression",-1);this.pendingExpressionKeys.clear(),this.motionStates.dispose(),this.detachDriver?.(),this.detachDriver=void 0,this.stopErrorWatch?.(),this.stopErrorWatch=void 0,this.afterMotionCallbacks.clear(),this.beforePhysicsCallbacks.clear(),this.scheduler.release(),this.look&&zt.delete(this.look),this.look=void 0;let e=this.renderContext;this.renderContext=void 0;try{if(e)for(let t of this.textures)e.deleteTexture(t);for(let t=0;t<this.textures.length;t++)this.diagnostics?.changeResource("texture",-1);this.textures.length=0,this.motionCache.clear(),this.expressionCache.clear(),this.manualParameters.clear(),this.setting.release(),super.release();for(let t of this.loadedMotions)Se.delete(t);this.loadedMotions.clear(),this.releaseRenderContext?.(),this.releaseRenderContext=void 0}finally{this.releaseFramework()}}}});var pn={};qe(pn,{createCubismWebGLBackend:()=>An,cubismWebGL:()=>Al});function fl(){return Reflect.construct(URL,["./cubism-webgl-shaders/",import.meta.url])}function An(e={}){return{createStage:Yr,async loadModel(t,r,i){let s=Gr(e.shaderBaseUrl??fl()),{loadFrameworkModel:n}=await Promise.resolve().then(()=>(fn(),gn));return n(t,r,s,e.shaderBaseUrl?void 0:gl,i)}}}var gl,Al,mn=_e(()=>{Dt();gl={"fragshadersrcalphablend.frag":`/**
26
+ Please call 'CubimRenderer_WebGL.startUp' function.`);return}this.gl.useProgram(this._lastProgram),this.setGlEnableVertexAttribArray(0,this._lastVertexAttribArrayEnabled[0]),this.setGlEnableVertexAttribArray(1,this._lastVertexAttribArrayEnabled[1]),this.setGlEnableVertexAttribArray(2,this._lastVertexAttribArrayEnabled[2]),this.setGlEnableVertexAttribArray(3,this._lastVertexAttribArrayEnabled[3]),this.setGlEnable(this.gl.SCISSOR_TEST,this._lastScissorTest),this.setGlEnable(this.gl.STENCIL_TEST,this._lastStencilTest),this.setGlEnable(this.gl.DEPTH_TEST,this._lastDepthTest),this.setGlEnable(this.gl.CULL_FACE,this._lastCullFace),this.setGlEnable(this.gl.BLEND,this._lastBlend),this.gl.frontFace(this._lastFrontFace),this.gl.colorMask(this._lastColorMask[0],this._lastColorMask[1],this._lastColorMask[2],this._lastColorMask[3]),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._lastArrayBufferBinding),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._lastElementArrayBufferBinding),this.gl.activeTexture(this.gl.TEXTURE1),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture1Binding2D),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture0Binding2D),this.gl.activeTexture(this._lastActiveTexture),this.gl.blendFuncSeparate(this._lastBlending[0],this._lastBlending[1],this._lastBlending[2],this._lastBlending[3])}setGl(e){this.gl=e}constructor(){this._lastVertexAttribArrayEnabled=new Array(4),this._lastColorMask=new Array(4),this._lastBlending=new Array(4)}_lastArrayBufferBinding;_lastElementArrayBufferBinding;_lastProgram;_lastActiveTexture;_lastTexture0Binding2D;_lastTexture1Binding2D;_lastVertexAttribArrayEnabled;_lastScissorTest;_lastBlend;_lastStencilTest;_lastDepthTest;_lastCullFace;_lastFrontFace;_lastColorMask;_lastBlending;gl},cr=class extends pt{initialize(e,t=1){e.isUsingMasking()&&(this._drawableClippingManager=new ct,this._drawableClippingManager.initializeForDrawable(e,t)),e.isUsingMaskingForOffscreen()&&(this._offscreenClippingManager=new ct,this._offscreenClippingManager.initializeForOffscreen(e,t)),Q(this._sortedObjectsIndexList,e.getDrawableCount()+(e.getOffscreenCount?e.getOffscreenCount():0),0,!0),Q(this._sortedObjectsTypeList,e.getDrawableCount()+(e.getOffscreenCount?e.getOffscreenCount():0),0,!0),super.initialize(e)}setupParentOffscreens(e,t){let r;for(let i=0;i<t;++i){r=null;let s=e.getOffscreenOwnerIndices()[i],n=e.getPartParentPartIndices()[s];for(;n!=-1;){for(let a=0;a<t;++a)if(e.getOffscreenOwnerIndices()[this._offscreenList[a].getOffscreenIndex()]==n){r=this._offscreenList[a];break}if(r!=null)break;n=e.getPartParentPartIndices()[n]}this._offscreenList[i].setParentPartOffscreen(r)}}bindTexture(e,t){this._textures.set(e,t)}getBindedTextures(){return this._textures}setClippingMaskBufferSize(e){if(!this._model.isUsingMasking())return;let t=this._drawableClippingManager.getRenderTextureCount();this._drawableClippingManager.release(),this._drawableClippingManager=void 0,this._drawableClippingManager=null,this._drawableClippingManager=new ct,this._drawableClippingManager.setClippingMaskBufferSize(e),this._drawableClippingManager.initializeForDrawable(this.getModel(),t)}getClippingMaskBufferSize(){return this._model.isUsingMasking()?this._drawableClippingManager.getClippingMaskBufferSize():at}getModelRenderTarget(e){return this._modelRenderTargets[e]}getRenderTextureCount(){return this._model.isUsingMasking()?this._drawableClippingManager.getRenderTextureCount():at}constructor(e,t){super(e,t),this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._rendererProfile=new Jo,this._textures=new Map,this._sortedObjectsIndexList=new Array,this._sortedObjectsTypeList=new Array,this._bufferData={vertex:WebGLBuffer=null,uv:WebGLBuffer=null,index:WebGLBuffer=null},this._drawableIndexBuffers=new Array,this._drawableUvBuffers=new Array,this._renderTargetIndexBuffer=null,this._modelRenderTargets=new Array,this._drawableMasks=new Array,this._currentFbo=null,this._drawableClippingManager=null,this._offscreenClippingManager=null,this._offscreenMasks=new Array,this._offscreenList=new Array}release(){if(this._drawableClippingManager&&(this._drawableClippingManager.release(),this._drawableClippingManager=void 0,this._drawableClippingManager=null),this.gl!=null){this.gl.deleteBuffer(this._bufferData.vertex),this._bufferData.vertex=null,this.gl.deleteBuffer(this._bufferData.uv),this._bufferData.uv=null,this.gl.deleteBuffer(this._bufferData.index),this._bufferData.index=null,this._bufferData=null;for(let e=0;e<this._drawableIndexBuffers.length;e++)this._drawableIndexBuffers[e]!=null&&this.gl.deleteBuffer(this._drawableIndexBuffers[e]);this._drawableIndexBuffers.length=0,this._drawableIndexBuffers=null;for(let e=0;e<this._drawableUvBuffers.length;e++)this._drawableUvBuffers[e]!=null&&this.gl.deleteBuffer(this._drawableUvBuffers[e]);this._drawableUvBuffers.length=0,this._drawableUvBuffers=null,this._renderTargetIndexBuffer!=null&&(this.gl.deleteBuffer(this._renderTargetIndexBuffer),this._renderTargetIndexBuffer=null),this._textures=null;for(let e=0;e<this._modelRenderTargets.length;e++)this._modelRenderTargets[e]!=null&&this._modelRenderTargets[e].isValid()&&this._modelRenderTargets[e].destroyRenderTarget();this._modelRenderTargets.length=0,this._modelRenderTargets=null;for(let e=0;e<this._drawableMasks.length;e++)this._drawableMasks[e]!=null&&this._drawableMasks[e].isValid()&&this._drawableMasks[e].destroyRenderTarget();this._drawableMasks.length=0,this._drawableMasks=null;for(let e=0;e<this._offscreenMasks.length;e++)this._offscreenMasks[e]!=null&&this._offscreenMasks[e].isValid()&&this._offscreenMasks[e].destroyRenderTarget();this._offscreenMasks.length=0,this._offscreenMasks=null;for(let e=0;e<this._offscreenList.length;e++)this._offscreenList[e]!=null&&this._offscreenList[e].isValid()&&this._offscreenList[e].destroyRenderTarget();this._offscreenList.length=0,this._offscreenList=null,this._offscreenClippingManager=null,this._drawableClippingManager=null,this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._rendererProfile=null,this._sortedObjectsIndexList=null,this._sortedObjectsTypeList=null,this._currentFbo=null,this._model=null,this.gl=null}}bindDrawableIndexBuffer(e){let t=this._drawableIndexBuffers[e];t==null?(t=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,this._model.getDrawableVertexIndices(e),this.gl.STATIC_DRAW),this._drawableIndexBuffers[e]=t):this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,t)}bindDrawableUvBuffer(e){let t=this._drawableUvBuffers[e];t==null?(t=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t),this.gl.bufferData(this.gl.ARRAY_BUFFER,this._model.getDrawableVertexUvs(e),this.gl.STATIC_DRAW),this._drawableUvBuffers[e]=t):this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t)}bindRenderTargetIndexBuffer(){this._renderTargetIndexBuffer==null?(this._renderTargetIndexBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._renderTargetIndexBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,Gt,this.gl.STATIC_DRAW)):this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._renderTargetIndexBuffer)}loadShaders(e=null,t,r){if(this.gl==null)return Promise.reject(new Error("'gl' is null. WebGLRenderingContext is required. Please call CubismRenderer_WebGL.startUp()."));let i=q.getInstance().getShader(this.gl);return(i._shaderSets.length==0||!i._isShaderLoaded)&&(e!=null&&i.setShaderPath(e),i.setShaderSources(r)),i.generateShaders(t,this._model!=null?this._model.isBlendModeEnabled():!0)}doDrawModel(e=null){this.beforeDrawModelRenderTarget();let t=this._renderStateFbo,r=this._renderStateViewport;if(this._drawableClippingManager!=null){this.preDraw();for(let i=0;i<this._drawableClippingManager.getRenderTextureCount();++i)(this._drawableMasks[i].getBufferWidth()!=this._drawableClippingManager.getClippingMaskBufferSize()||this._drawableMasks[i].getBufferHeight()!=this._drawableClippingManager.getClippingMaskBufferSize())&&this._drawableMasks[i].createRenderTarget(this.gl,this._drawableClippingManager.getClippingMaskBufferSize(),this._drawableClippingManager.getClippingMaskBufferSize(),t);this.isUsingHighPrecisionMask()?this._drawableClippingManager.setupMatrixForHighPrecision(this.getModel(),!1):this._drawableClippingManager.setupClippingContext(this.getModel(),this,t,r,0,this._renderStateKnown)}if(this._offscreenClippingManager!=null){this.preDraw();for(let i=0;i<this._offscreenClippingManager.getRenderTextureCount();++i)(this._offscreenMasks[i].getBufferWidth()!=this._offscreenClippingManager.getClippingMaskBufferSize()||this._offscreenMasks[i].getBufferHeight()!=this._offscreenClippingManager.getClippingMaskBufferSize())&&this._offscreenMasks[i].createRenderTarget(this.gl,this._offscreenClippingManager.getClippingMaskBufferSize(),this._offscreenClippingManager.getClippingMaskBufferSize(),t);this.isUsingHighPrecisionMask()?this._offscreenClippingManager.setupMatrixForOffscreenHighPrecision(this.getModel(),!1,this.getMvpMatrix()):this._offscreenClippingManager.setupClippingContext(this.getModel(),this,t,r,1,this._renderStateKnown)}this.preDraw(),this.drawObjectLoop(t),this.afterDrawModelRenderTarget()}drawObjectLoop(e){let t=this.getModel(),r=t.getDrawableCount(),i=r+t.getOffscreenCount(),s=t.getRenderOrders();this._currentOffscreen=null,this._currentFbo=e,this._modelRootFbo=e;for(let n=0;n<i;++n){let a=s[n];n<r?(this._sortedObjectsIndexList[a]=n,this._sortedObjectsTypeList[a]=0):n<i&&(this._sortedObjectsIndexList[a]=n-r,this._sortedObjectsTypeList[a]=1)}for(let n=0;n<i;++n){let a=this._sortedObjectsIndexList[n],l=this._sortedObjectsTypeList[n];this.renderObject(a,l)}for(;this._currentOffscreen!=null;)this.submitDrawToParentOffscreen(this._currentOffscreen.getOffscreenIndex(),1)}renderObject(e,t){switch(t){case 0:this.drawDrawable(e,this._modelRootFbo);break;case 1:this.addOffscreen(e);break;default:D("Unknown object type: "+t);break}}drawDrawable(e,t){if(!this.getModel().getDrawableDynamicFlagIsVisible(e))return;this.submitDrawToParentOffscreen(e,0);let r=this._drawableClippingManager!=null?this._drawableClippingManager.getClippingContextListForDraw()[e]:null;if(r!=null&&this.isUsingHighPrecisionMask()){r._isUsing&&(this.gl.viewport(0,0,this._drawableClippingManager.getClippingMaskBufferSize(),this._drawableClippingManager.getClippingMaskBufferSize()),this.preDraw(),this.getDrawableMaskBuffer(r._bufferIndex).beginDraw(this._currentFbo),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{let i=r._clippingIdCount;for(let s=0;s<i;s++){let n=r._clippingIdList[s];this._model.getDrawableDynamicFlagVertexPositionsDidChange(n)&&(this.setIsCulling(this._model.getDrawableCulling(n)!=!1),this.setClippingContextBufferForMask(r),this.drawMeshWebGL(this._model,n))}this.getDrawableMaskBuffer(r._bufferIndex).endDraw(),this.setClippingContextBufferForMask(null),this.gl.viewport(0,0,this._modelRenderTargetWidth,this._modelRenderTargetHeight),this.preDraw()}}this.setClippingContextBufferForDrawable(r),this.setIsCulling(this.getModel().getDrawableCulling(e)),this.drawMeshWebGL(this._model,e)}drawMeshWebGL(e,t){if(this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW),this.isGeneratingMask()?q.getInstance().getShader(this.gl).setupShaderProgramForMask(this,e,t):q.getInstance().getShader(this.gl).setupShaderProgramForDrawable(this,e,t),!!q.getInstance().getShader(this.gl)._isShaderLoaded){{let r=e.getDrawableVertexIndexCount(t);this.gl.drawElements(this.gl.TRIANGLES,r,this.gl.UNSIGNED_SHORT,0)}this.setClippingContextBufferForDrawable(null),this.setClippingContextBufferForMask(null)}}submitDrawToParentOffscreen(e,t){if(this._currentOffscreen==null||e==at)return;let r=this.getModel().getOffscreenOwnerIndices()[this._currentOffscreen.getOffscreenIndex()];if(r==at)return;let i=-1;switch(t){case 0:i=this.getModel().getDrawableParentPartIndex(e);break;case 1:i=this.getModel().getPartParentPartIndices()[this.getModel().getOffscreenOwnerIndices()[e]];break;default:return}for(;i!=-1;){if(i==r)return;i=this.getModel().getPartParentPartIndices()[i]}this.drawOffscreen(this._currentOffscreen),this.submitDrawToParentOffscreen(e,t)}addOffscreen(e){if(this._currentOffscreen!=null&&this._currentOffscreen.getOffscreenIndex()!=e){let s=!1,n=this.getModel().getOffscreenOwnerIndices()[e],a=this.getModel().getPartParentPartIndices()[n],l=this._currentOffscreen.getOffscreenIndex(),o=this.getModel().getOffscreenOwnerIndices()[l];for(;a!=-1;){if(a==o){s=!0;break}a=this.getModel().getPartParentPartIndices()[a]}s||this.submitDrawToParentOffscreen(e,1)}let t=this._offscreenList[e];t.getRenderTexture()==null||t.getBufferWidth()!=this._modelRenderTargetWidth||t.getBufferHeight()!=this._modelRenderTargetHeight||t.getUsingRenderTextureState()?t.setOffscreenRenderTarget(this.gl,this._modelRenderTargetWidth,this._modelRenderTargetHeight,this._currentFbo):t.startUsingRenderTexture();let r=t.getParentPartOffscreen();t.setOldOffscreen(r);let i=null;r!=null&&(i=r.getRenderTexture()),i==null&&(i=this._modelRootFbo),t.beginDraw(i),this.gl.viewport(0,0,this._modelRenderTargetWidth,this._modelRenderTargetHeight),t.clear(0,0,0,0),this._currentOffscreen=t,this._currentFbo=t.getRenderTexture()}drawOffscreen(e){let t=e.getOffscreenIndex(),r=this._offscreenClippingManager!=null?this._offscreenClippingManager.getClippingContextListForOffscreen()[t]:null;if(r!=null&&this.isUsingHighPrecisionMask()){r._isUsing&&(this.gl.viewport(0,0,this._offscreenClippingManager.getClippingMaskBufferSize(),this._offscreenClippingManager.getClippingMaskBufferSize()),this.preDraw(),this.getOffscreenMaskBuffer(r._bufferIndex).beginDraw(this._currentFbo),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{let i=r._clippingIdCount;for(let s=0;s<i;s++){let n=r._clippingIdList[s];this.getModel().getDrawableDynamicFlagVertexPositionsDidChange(n)&&(this.setIsCulling(this.getModel().getDrawableCulling(n)!=!1),this.setClippingContextBufferForMask(r),this.drawMeshWebGL(this.getModel(),n))}}this.getOffscreenMaskBuffer(r._bufferIndex).endDraw(),this.setClippingContextBufferForMask(null),this.gl.viewport(0,0,this._modelRenderTargetWidth,this._modelRenderTargetHeight),this.preDraw()}this.setClippingContextBufferForOffscreen(r),this.setIsCulling(this._model.getOffscreenCulling(t)!=!1),this.drawOffscreenWebGL(this.getModel(),e)}drawOffscreenWebGL(e,t){this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW),q.getInstance().getShader(this.gl).setupShaderProgramForOffscreen(this,e,t),t.endDraw(),this._currentOffscreen=this._currentOffscreen.getOldOffscreen(),this._currentFbo=t.getOldFBO(),this._currentFbo==null&&(this._currentOffscreen=this._modelRenderTargets[0],this._currentFbo=this._modelRenderTargets[0].getRenderTexture(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentFbo)),this.bindRenderTargetIndexBuffer(),this.gl.drawElements(this.gl.TRIANGLES,Gt.length,this.gl.UNSIGNED_SHORT,0),t.stopUsingRenderTexture(),this.setClippingContextBufferForMask(null),this.setClippingContextBufferForOffscreen(null)}saveProfile(){this._rendererProfile.save()}restoreProfile(){this._rendererProfile.restore()}beforeDrawModelRenderTarget(){if(this._modelRenderTargets.length!=0){for(let e=0;e<this._modelRenderTargets.length;++e)(this._modelRenderTargets[e].getBufferWidth()!=this._modelRenderTargetWidth||this._modelRenderTargets[e].getBufferHeight()!=this._modelRenderTargetHeight)&&this._modelRenderTargets[e].createRenderTarget(this.gl,this._modelRenderTargetWidth,this._modelRenderTargetHeight,this._currentFbo);this._modelRenderTargets[0].beginDraw(),this._modelRenderTargets[0].clear(0,0,0,0)}}afterDrawModelRenderTarget(){this._modelRenderTargets.length!=0&&(this._modelRenderTargets[0].endDraw(),q.getInstance().getShader(this.gl).setupShaderProgramForOffscreenRenderTarget(this),q.getInstance().getShader(this.gl)._isShaderLoaded&&(this.bindRenderTargetIndexBuffer(),this.gl.drawElements(this.gl.TRIANGLES,Gt.length,this.gl.UNSIGNED_SHORT,0)))}getOffscreenMaskBuffer(e){return this._offscreenMasks[e]}static doStaticRelease(){q.deleteInstance()}setRenderState(e,t){this._renderStateFbo=e,this._renderStateKnown=!0,this._renderStateViewport[0]=t[0],this._renderStateViewport[1]=t[1],this._renderStateViewport[2]=t[2],this._renderStateViewport[3]=t[3],this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.gl.viewport(t[0],t[1],t[2],t[3]),(this._modelRenderTargetWidth!=t[2]||this._modelRenderTargetHeight!=t[3])&&(this._modelRenderTargetWidth=t[2],this._modelRenderTargetHeight=t[3])}preDraw(){if(this.gl.disable(this.gl.SCISSOR_TEST),this.gl.disable(this.gl.STENCIL_TEST),this.gl.disable(this.gl.DEPTH_TEST),this.gl.frontFace(this.gl.CW),this.gl.enable(this.gl.BLEND),this.gl.colorMask(!0,!0,!0,!0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.getAnisotropy()>0&&this._extension)for(let e=0;e<this._textures.size;++e)this.gl.bindTexture(this.gl.TEXTURE_2D,this._textures.get(e)),this.gl.texParameterf(this.gl.TEXTURE_2D,this._extension.TEXTURE_MAX_ANISOTROPY_EXT,this.getAnisotropy())}getDrawableMaskBuffer(e){return this._drawableMasks[e]}setClippingContextBufferForMask(e){this._clippingContextBufferForMask=e}getClippingContextBufferForMask(){return this._clippingContextBufferForMask}setClippingContextBufferForDrawable(e){this._clippingContextBufferForDraw=e}getClippingContextBufferForDrawable(){return this._clippingContextBufferForDraw}setClippingContextBufferForOffscreen(e){this._clippingContextBufferForOffscreen=e}getClippingContextBufferForOffscreen(){return this._clippingContextBufferForOffscreen}isGeneratingMask(){return this.getClippingContextBufferForMask()!=null}startUp(e){if(this.gl=e,this._drawableClippingManager&&this._drawableClippingManager.setGL(e),this._offscreenClippingManager&&this._offscreenClippingManager.setGL(e),q.getInstance().setGlContext(e),this._rendererProfile.setGl(e),this._extension=this.gl.getExtension("EXT_texture_filter_anisotropic")||this.gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this.gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),this._model.isUsingMasking()){this._drawableMasks.length=this._drawableClippingManager.getRenderTextureCount();for(let t=0;t<this._drawableMasks.length;++t){let r=new Ae;r.createRenderTarget(this.gl,this._drawableClippingManager.getClippingMaskBufferSize(),this._drawableClippingManager.getClippingMaskBufferSize(),this._currentFbo),this._drawableMasks[t]=r}}if(this._model.isBlendModeEnabled()){this._modelRenderTargets.length=0;let t=3;this._modelRenderTargets.length=t;for(let i=0;i<t;++i){let s=new ji;s.createRenderTarget(this.gl,this._modelRenderTargetWidth,this._modelRenderTargetHeight,this._currentFbo),this._modelRenderTargets[i]=s}if(this._model.isUsingMaskingForOffscreen()){this._offscreenMasks.length=this._offscreenClippingManager.getRenderTextureCount();for(let i=0;i<this._offscreenMasks.length;++i){let s=new Ae;s.createRenderTarget(this.gl,this._offscreenClippingManager.getClippingMaskBufferSize(),this._offscreenClippingManager.getClippingMaskBufferSize(),this._currentFbo),this._offscreenMasks[i]=s}}let r=this._model.getOffscreenCount();if(r>0){this._offscreenList=new Array(r);for(let i=0;i<r;++i){let s=new ji;s.setOffscreenIndex(i),this._offscreenList[i]=s}this.setupParentOffscreens(this._model,r)}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._currentFbo)}_textures;_sortedObjectsIndexList;_sortedObjectsTypeList;_rendererProfile;_drawableClippingManager;_clippingContextBufferForMask;_clippingContextBufferForDraw;_clippingContextBufferForOffscreen;_offscreenClippingManager;_modelRenderTargets;_drawableMasks;_offscreenMasks;_offscreenList;_currentFbo;_currentOffscreen;_modelRootFbo;_renderStateFbo=null;_renderStateKnown=!1;_renderStateViewport=[0,0,0,0];_bufferData;_drawableIndexBuffers;_drawableUvBuffers;_renderTargetIndexBuffer;_extension;gl};pt.staticRelease=()=>{cr.doStaticRelease()};(function(e){e.CubismClippingContext=qs,e.CubismClippingManager_WebGL=ct,e.CubismRenderer_WebGL=cr})(Ki||(Ki={}));er=class Ks{static create(t,r){let i=null;if(r&&!this.hasMocConsistency(t))return D("Inconsistent MOC3."),i;let s=Live2DCubismCore.Moc.fromArrayBuffer(t);return s&&(i=new Ks(s),i._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(t)),i}static delete(t){t._moc._release(),t._moc=null,t=null}createModel(){let t=null,r=Live2DCubismCore.Model.fromMoc(this._moc);return r&&(t=new Cs(r),t.initialize(),++this._modelCount),t}deleteModel(t){t!=null&&(t.release(),t=null,--this._modelCount)}constructor(t){this._moc=t,this._modelCount=0,this._mocVersion=0}release(){k(this._modelCount==0),this._moc._release(),this._moc=null}getLatestMocVersion(){return Live2DCubismCore.Version.csmGetLatestMocVersion()}getMocVersion(){return this._mocVersion}static getMocVersionFromBuffer(t){return Live2DCubismCore.Version.csmGetMocVersion(t)}static hasMocConsistency(t){return Live2DCubismCore.Moc.prototype.hasMocConsistency(t)===1}_moc;_modelCount;_mocVersion};(function(e){e.CubismMoc=er})($i||($i={}));es="Meta",jo="UserDataCount",Zo="TotalUserDataSize",Xt="UserData",qo="Target",Ko="Id",$o="Value",$s=class{constructor(e,t){this._json=G.create(e,t)}release(){G.delete(this._json)}getUserDataCount(){return this._json.getRoot().getValueByString(es).getValueByString(jo).toInt()}getTotalUserDataSize(){return this._json.getRoot().getValueByString(es).getValueByString(Zo).toInt()}getUserDataTargetType(e){return this._json.getRoot().getValueByString(Xt).getValueByIndex(e).getValueByString(qo).getRawString()}getUserDataId(e){return P.getIdManager().getId(this._json.getRoot().getValueByString(Xt).getValueByIndex(e).getValueByString(Ko).getRawString())}getUserDataValue(e){return this._json.getRoot().getValueByString(Xt).getValueByIndex(e).getValueByString($o).getRawString()}_json};(function(e){e.CubismModelUserDataJson=$s})(ts||(ts={}));el="ArtMesh",en=class{targetType;targetId;value},tr=class tn{static create(t,r){let i=new tn;return i.parseUserData(t,r),i}static delete(t){t!=null&&(t.release(),t=null)}getArtMeshUserDatas(){return this._artMeshUserDataNode}parseUserData(t,r){let i=new $s(t,r);if(!i){i.release(),i=void 0;return}let s=P.getIdManager().getId(el),n=i.getUserDataCount(),a=this._userDataNodes.length;this._userDataNodes.length=n;for(let l=0;l<n;l++){let o=new en;o.targetId=i.getUserDataId(l),o.targetType=P.getIdManager().getId(i.getUserDataTargetType(l)),o.value=i.getUserDataValue(l),this._userDataNodes[a++]=o,o.targetType==s&&this._artMeshUserDataNode.push(o)}i.release(),i=void 0}constructor(){this._userDataNodes=new Array,this._artMeshUserDataNode=new Array}release(){for(let t=0;t<this._userDataNodes.length;++t)this._userDataNodes[t]=null;this._userDataNodes=null}_userDataNodes;_artMeshUserDataNode};(function(e){e.CubismModelUserData=tr,e.CubismModelUserDataNode=en})(rs||(rs={}));rn=class sn{isInitialized(){return this._initialized}setInitialized(t){this._initialized=t}isUpdating(){return this._updating}setUpdating(t){this._updating=t}setDragging(t,r){this._dragManager.set(t,r)}getModelMatrix(){return this._modelMatrix}setRenderTargetSize(t,r){this._renderer&&this._renderer.setRenderTargetSize(t,r)}setOpacity(t){this._opacity=t}getOpacity(){return this._opacity}loadModel(t,r=!1){if(this._moc=er.create(t,r),this._moc==null){D("Failed to CubismMoc.create().");return}if(this._model=this._moc.createModel(),this._model==null){D("Failed to CreateModel().");return}this._model.saveParameters(),this._modelMatrix=new ar(this._model.getCanvasWidth(),this._model.getCanvasHeight())}loadMotion(t,r,i,s,n,a,l,o,u=!1){if(t==null||r==0)return D("Failed to loadMotion()."),null;let h=Vs.create(t,r,s,n,u);if(h==null)return D("Failed to create motion from buffer in LoadMotion()"),null;if(a){let d=a.getMotionFadeInTimeValue(l,o);d>=0&&h.setFadeInTime(d);let c=a.getMotionFadeOutTimeValue(l,o);c>=0&&h.setFadeOutTime(c)}return h}loadExpression(t,r,i){return t==null||r==0?(D("Failed to loadExpression()."),null):Te.create(t,r)}loadPose(t,r){if(t==null||r==0){D("Failed to loadPose().");return}this._pose=Jt.create(t,r)}loadUserData(t,r){if(t==null||r==0){D("Failed to loadUserData().");return}this._modelUserData=tr.create(t,r)}loadPhysics(t,r){if(t==null||r==0){D("Failed to loadPhysics().");return}this._physics=Kt.create(t,r)}isHit(t,r,i){let s=this._model.getDrawableIndex(t);if(s<0)return!1;let n=this._model.getDrawableVertexCount(s),a=this._model.getDrawableVertices(s),l=a[0],o=a[0],u=a[1],h=a[1];for(let g=1;g<n;++g){let A=a[$.vertexOffset+g*$.vertexStep],p=a[$.vertexOffset+g*$.vertexStep+1];A<l&&(l=A),A>o&&(o=A),p<u&&(u=p),p>h&&(h=p)}let d=this._modelMatrix.invertTransformX(r),c=this._modelMatrix.invertTransformY(i);return l<=d&&d<=o&&u<=c&&c<=h}getModel(){return this._model}getMocVersionFromBuffer(t){return er.getMocVersionFromBuffer(t)}getRenderer(){return this._renderer}createRenderer(t,r,i=1){this._renderer&&this.deleteRenderer(),this._renderer=new cr(t,r),this._renderer.initialize(this._model,i)}deleteRenderer(){this._renderer!=null&&(this._renderer.release(),this._renderer=null)}motionEventFired(t){de("{0}",t)}static cubismDefaultMotionEventCallback(t,r,i){let s=i;s?.motionEventFired(r)}constructor(){this._moc=null,this._model=null,this._motionManager=null,this._expressionManager=null,this._eyeBlink=null,this._breath=null,this._modelMatrix=null,this._pose=null,this._dragManager=null,this._physics=null,this._modelUserData=null,this._initialized=!1,this._updating=!1,this._opacity=1,this._mocConsistency=!1,this._debugMode=!1,this._renderer=null,this._motionManager=new Qs,this._motionManager.setEventCallback(sn.cubismDefaultMotionEventCallback,this),this._expressionManager=new xs,this._dragManager=new Ms}release(){this._motionManager!=null&&(this._motionManager.release(),this._motionManager=null),this._expressionManager!=null&&(this._expressionManager.release(),this._expressionManager=null),this._moc!=null&&(this._moc.deleteModel(this._model),this._moc.release(),this._moc=null),this._modelMatrix=null,Jt.delete(this._pose),nr.delete(this._eyeBlink),sr.delete(this._breath),this._dragManager=null,Kt.delete(this._physics),tr.delete(this._modelUserData),this.deleteRenderer()}_moc;_model;_motionManager;_expressionManager;_eyeBlink;_breath;_modelMatrix;_pose;_dragManager;_physics;_modelUserData;_initialized;_updating;_opacity;_mocConsistency;_motionConsistency;_debugMode;_renderer};(function(e){e.CubismUserModel=rn})(is||(is={}));ge=class{static sortFunction(e,t){if(!e||!t){if(!e&&!t)return 0;if(!e)return 1;if(!t)return-1}return e.getExecutionOrder()-t.getExecutionOrder()}_executionOrder;_changeListeners=[];constructor(e=0){this._executionOrder=e}getExecutionOrder(){return this._executionOrder}setExecutionOrder(e){this._executionOrder!==e&&(this._executionOrder=e,this.notifyChangeListeners())}addChangeListener(e){e&&this._changeListeners.indexOf(e)===-1&&this._changeListeners.push(e)}removeChangeListener(e){let t=this._changeListeners.indexOf(e);t>=0&&this._changeListeners.splice(t,1)}notifyChangeListeners(){for(let e of this._changeListeners)e.onUpdaterChanged(this)}};(function(e){e.ICubismUpdater=ge})(ss||(ss={}));nn=class extends ge{_breath;constructor(e,t){super(t??500),this._breath=e}onLateUpdate(e,t){e&&this._breath.updateParameters(e,t)}};(function(e){e.CubismBreathUpdater=nn})(ns||(ns={}));an=class extends ge{_expressionManager;constructor(e,t){super(t??300),this._expressionManager=e}onLateUpdate(e,t){e&&this._expressionManager.updateMotion(e,t)}};(function(e){e.CubismExpressionUpdater=an})(as||(as={}));on=class extends ge{_motionUpdated;_eyeBlink;constructor(e,t,r){super(r??200),this._motionUpdated=e,this._eyeBlink=t}onLateUpdate(e,t){e&&(this._motionUpdated()||this._eyeBlink.updateParameters(e,t))}};(function(e){e.CubismEyeBlinkUpdater=on})(os||(os={}));ln=class extends ge{_look;_dragManager;constructor(e,t,r){super(r??400),this._look=e,this._dragManager=t}onLateUpdate(e,t){if(!e)return;this._dragManager.update(t);let r=this._dragManager.getX(),i=this._dragManager.getY();this._look.updateParameters(e,r,i)}};(function(e){e.CubismLookUpdater=ln})(ls||(ls={}));un=class extends ge{_physics;constructor(e,t){super(t??600),this._physics=e}onLateUpdate(e,t){e&&this._physics.evaluate(e,t)}};(function(e){e.CubismPhysicsUpdater=un})(us||(us={}));hn=class extends ge{_pose;constructor(e,t){super(t??800),this._pose=e}onLateUpdate(e,t){e&&this._pose.updateParameters(e,t)}};(function(e){e.CubismPoseUpdater=hn})(hs||(hs={}));cn=class{_cubismUpdatableList;_needsSort;constructor(){this._cubismUpdatableList=[],this._needsSort=!1}release(){for(let e of this._cubismUpdatableList)e&&e.removeChangeListener(this);this._cubismUpdatableList.length=0}addUpdatableList(e){e&&(this.hasUpdatable(e)||(this._cubismUpdatableList.push(e),e.addChangeListener(this),this._needsSort=!0))}removeUpdatableList(e){if(!e)return!1;let t=this._cubismUpdatableList.indexOf(e);return t>=0?(this._cubismUpdatableList.splice(t,1),e.removeChangeListener(this),!0):!1}sortUpdatableList(){this._cubismUpdatableList.sort(ge.sortFunction),this._needsSort=!1}onLateUpdate(e,t){if(e){this._needsSort&&this.sortUpdatableList();for(let r=0;r<this._cubismUpdatableList.length;++r){let i=this._cubismUpdatableList[r];i&&i.onLateUpdate(e,t)}}}getUpdatableCount(){return this._cubismUpdatableList.length}getUpdatable(e){return e<0||e>=this._cubismUpdatableList.length?null:this._cubismUpdatableList[e]}hasUpdatable(e){return this._cubismUpdatableList.indexOf(e)>=0}clearUpdatableList(){for(let e of this._cubismUpdatableList)e&&e.removeChangeListener(this);this._cubismUpdatableList.length=0,this._needsSort=!1}onUpdaterChanged(e){this._needsSort=!0}};(function(e){e.CubismUpdateScheduler=cn})(cs||(cs={}));ot=0;ol=class{disposed=!1;failure;pending=new Map;track(e){return this.failure?Promise.reject(this.failure):this.disposed?Promise.resolve({status:"disposed"}):new Promise((t,r)=>{this.pending.set(e,{reason:"completed",reject:r,resolve:t})})}interruptActive(){for(let e of this.pending.values())e.reason="interrupted"}settleFinished(e){for(let[t,r]of[...this.pending])e(t)&&(this.pending.delete(t),r.resolve({status:r.reason}))}fail(e){this.failure??=e;for(let t of this.takeAll())t.reject(this.failure)}dispose(){if(!this.disposed){this.disposed=!0;for(let e of this.takeAll())e.resolve({status:"disposed"})}}takeAll(){let e=[...this.pending.values()];return this.pending.clear(),e}},We=new Map;hl=1,cl=3,dl=1e3,fs={force:3,idle:1,normal:2};gl=550,fl=class extends ge{callbacks;constructor(e){super(gl),this.callbacks=e}onLateUpdate(e,t){for(let r of this.callbacks)r(t*1e3)}},Al=class extends rn{stage;modelUrl;setting;shaderBaseUrl;shaderSources;idleMotion;releaseFramework;model3Version;diagnostics;resolveAsset;afterMotionCallbacks=new Set;beforePhysicsCallbacks=new Set;assetController=new AbortController;expressionCache=new Map;loadedMotions=new Set;layoutMatrix;manualParameters=new Map;mvpMatrix;motionCache=new Map;motionStates=new ol;parameterIds=new Map;renderContext;releaseRenderContext;renderError;stopErrorWatch;pendingExpressionKeys=new Set;pendingMotionKeys=new Set;scheduler=new cn;textures=[];viewport=[0,0,1,1];bounds={centerX:0,centerY:0,height:1,width:1};detachDriver;disposed=!1;expressionGeneration=0;eyeBlinkIds=[];idlePending=!1;look;mvpDirty=!0;motionUpdated=!1;motionGeneration=0;transform={scale:1,x:0,y:0};constructor(e,t,r,i,s,n,a,l,o,u){super(),this.stage=e,this.modelUrl=t,this.setting=r,this.shaderBaseUrl=i,this.shaderSources=s,this.idleMotion=n,this.releaseFramework=a,this.model3Version=l,this.diagnostics=o,this.resolveAsset=u}parameterId(e){let t=this.parameterIds.get(e);if(t)return t;let r=P.getIdManager().getId(e);return this.parameterIds.set(e,r),r}async initialize(e){let t=()=>this.assetController.abort(e?.reason);e?.aborted&&t(),e?.addEventListener("abort",t,{once:!0});try{let r=this.setting.getModelFileName();if(!r)throw new m("model-load-failed","model3.json does not declare FileReferences.Moc.",{details:se("model3",this.modelUrl)});let i=te(r,this.modelUrl),s=await Ce(this.diagnostics,"mocFetch",()=>ue(i,"moc3",this.assetController.signal,this.resolveAsset));try{j(this.diagnostics,"load","mocParse",()=>this.loadModel(s,!0))}catch(l){throw new m("model-load-failed",`Failed to parse moc3 asset ${i}.`,{cause:l,details:se("moc3",i)})}if(!this.getModel())throw new m("model-load-failed","Cubism Core rejected the moc3 model.",{details:se("moc3",i)});this.layoutMatrix=new ar(this.getModel().getCanvasWidth(),this.getModel().getCanvasHeight());let n=new Map;this.setting.getLayoutMap(n),this.layoutMatrix.setupFromLayout(n),this.bounds=sl({height:this.getModel().getCanvasHeight(),width:this.getModel().getCanvasWidth()},this.layoutMatrix),await Ce(this.diagnostics,"optionalAssets",()=>this.loadOptionalAssets()),this.setupEffects(),await this.setupRenderer(),this.getModel().saveParameters();let a=we(this.stage);this.detachDriver=a.attachDriver({draw:()=>this.draw(),resize:(l,o)=>this.resize(l,o),update:l=>this.updateFrame(l)}),this.stopErrorWatch=this.stage.onError(l=>this.failMotions(l)),this.prefetchIdleMotions()}finally{e?.removeEventListener("abort",t)}}async prefetchIdleMotions(){if(await new Promise(t=>{let r,i=()=>{clearTimeout(r),t()};r=setTimeout(()=>{this.assetController.signal.removeEventListener("abort",i),t()},dl),this.assetController.signal.addEventListener("abort",i,{once:!0})}),this.disposed||this.idleMotion===!1)return;let e=this.setting.getMotionCount(this.idleMotion.group);for(let t=0;t<e;t++){if(this.disposed)return;try{await this.loadMotionAsset(this.idleMotion.group,t)}catch{}}}async loadOptionalAssets(){let e=this.assetController.signal,t=this.setting.getPhysicsFileName(),r=this.setting.getPoseFileName(),i=this.setting.getUserDataFile(),s=t?te(t,this.modelUrl):void 0,n=r?te(r,this.modelUrl):void 0,a=i?te(i,this.modelUrl):void 0,[l,o,u]=await Promise.all([s?ue(s,"physics",e,this.resolveAsset):void 0,n?ue(n,"pose",e,this.resolveAsset):void 0,a?ue(a,"user-data",e,this.resolveAsset):void 0]);try{l&&this.loadPhysics(l,l.byteLength)}catch(h){throw new m("model-load-failed",`Failed to parse physics asset ${s}.`,{cause:h,details:se("physics",s)})}try{o&&this.loadPose(o,o.byteLength)}catch(h){throw new m("model-load-failed",`Failed to parse pose asset ${n}.`,{cause:h,details:se("pose",n)})}try{u&&this.loadUserData(u,u.byteLength)}catch(h){throw new m("model-load-failed",`Failed to parse user data asset ${a}.`,{cause:h,details:se("user-data",a)})}}setupEffects(){this.eyeBlinkIds=Array.from({length:this.setting.getEyeBlinkParameterCount()},(e,t)=>this.setting.getEyeBlinkParameterId(t)),this.eyeBlinkIds.length>0&&(this._eyeBlink=nr.create(this.setting),this.scheduler.addUpdatableList(new on(()=>this.motionUpdated,this._eyeBlink,300))),this._breath=sr.create(),this._breath.setParameters([new De(this.parameterId(S.ParamAngleX),0,15,6.5345,.5),new De(this.parameterId(S.ParamAngleY),0,8,3.5345,.5),new De(this.parameterId(S.ParamAngleZ),0,10,5.5345,.5),new De(this.parameterId(S.ParamBodyAngleX),0,4,15.5345,.5),new De(this.parameterId(S.ParamBreath),.5,.5,3.2345,1)]),this.scheduler.addUpdatableList(new nn(this._breath)),this._physics&&this.scheduler.addUpdatableList(new un(this._physics)),this._pose&&this.scheduler.addUpdatableList(new hn(this._pose)),this._expressionManager&&this.scheduler.addUpdatableList(new an(this._expressionManager,200)),this.look=zt.create(),this.look.setParameters([new Ie(this.parameterId(S.ParamAngleX),30,0,0),new Ie(this.parameterId(S.ParamAngleY),0,30,0),new Ie(this.parameterId(S.ParamAngleZ),0,0,-30),new Ie(this.parameterId(S.ParamBodyAngleX),10,0,0),new Ie(this.parameterId(S.ParamEyeBallX),1,0,0),new Ie(this.parameterId(S.ParamEyeBallY),0,1,0)]),this.scheduler.addUpdatableList(new ln(this.look,this._dragManager)),this.scheduler.addUpdatableList(new fl(this.beforePhysicsCallbacks)),this.scheduler.sortUpdatableList()}async setupRenderer(){let{canvas:e,gl:t}=we(this.stage);this.renderContext=t,this.releaseRenderContext=ul(t),this.createRenderer(e.width,e.height);let r=this.getRenderer();r.startUp(t),r.setIsPremultipliedAlpha(!0);let i=[];for(let a=0;a<this.setting.getTextureCount();a++){let l=this.setting.getTextureFileName(a);if(!l)throw new m("model-load-failed",`model3.json declares an empty texture at index ${a}.`,{details:se("texture",this.modelUrl)});i.push(te(l,this.modelUrl))}let s=i.map(a=>Hr(a,this.assetController.signal,this.diagnostics,this.resolveAsset));for(let a of s)a.catch(()=>{});let n=async()=>{await Promise.allSettled(s.map(async a=>Ne(await a)))};try{await Ce(this.diagnostics,"shaderSetup",()=>r.loadShaders(this.shaderBaseUrl,this.assetController.signal,this.shaderSources))}catch(a){throw await n(),a instanceof m?a:new m("render-error",a instanceof Error?a.message:"Cubism shader loading failed.",{cause:a,details:tl(a)})}try{for(let a=0;a<s.length;a++){let l=await s[a];if(this.assetController.signal.aborted)throw Ne(l),this.assetController.signal.reason;let o=Wr(t,l,i[a],this.diagnostics);this.textures.push(o),this.diagnostics?.changeResource("texture",1),r.bindTexture(a,o)}}catch(a){throw await n(),a}}updateFrame(e){if(this.disposed)return;let t=e/1e3;if(!this.diagnostics){this.getModel().loadParameters(),this.motionUpdated=!1,this._motionManager.isFinished()?this.scheduleIdle():this.motionUpdated=this._motionManager.updateMotion(this.getModel(),t),this.getModel().saveParameters(),this.settleFinishedMotions(),this.scheduler.onLateUpdate(this.getModel(),t);for(let[r,i]of this.manualParameters)this.getModel().setParameterValueById(this.parameterId(r),i);for(let r of this.afterMotionCallbacks)r(e);this.getModel().update();return}j(this.diagnostics,"frame","motion",()=>{this.getModel().loadParameters(),this.motionUpdated=!1,this._motionManager.isFinished()?this.scheduleIdle():this.motionUpdated=this._motionManager.updateMotion(this.getModel(),t),this.getModel().saveParameters()}),this.settleFinishedMotions(),j(this.diagnostics,"frame","effectsPhysicsPose",()=>{this.scheduler.onLateUpdate(this.getModel(),t)}),j(this.diagnostics,"frame","manualParameters",()=>{for(let[r,i]of this.manualParameters)this.getModel().setParameterValueById(this.parameterId(r),i)}),j(this.diagnostics,"frame","externalDrivers",()=>{for(let r of this.afterMotionCallbacks)r(e)}),j(this.diagnostics,"frame","coreUpdate",()=>{this.getModel().update()})}scheduleIdle(){if(this.idleMotion===!1||this.idlePending)return;let{group:e,weights:t}=this.idleMotion,r=this.setting.getMotionCount(e);r!==0&&(this.idlePending=!0,this.playMotion(e,Dr(r,t),hl).catch(i=>{this.disposed||we(this.stage).reportError(dn(i,"Idle motion failed"))}).finally(()=>{this.idlePending=!1}))}async ensureAssetBuffer(e){return await nl(e,()=>ue(e.url,e.type,this.assetController.signal,this.resolveAsset)),e}async loadMotionAsset(e,t){let r=`${e}:${t}`,i=this.motionCache.get(r);if(i)return i;let s=(async()=>{this.pendingMotionKeys.add(r),this.diagnostics?.changeResource("pendingMotion",1);try{let n=te(this.setting.getMotionFileName(e,t),this.modelUrl),a=await ue(n,"motion",this.assetController.signal,this.resolveAsset),l=this.parseMotion(a,r,e,t,n);return this.loadedMotions.add(l),{motion:l,type:"motion",url:n}}finally{this.pendingMotionKeys.delete(r)&&this.diagnostics?.changeResource("pendingMotion",-1)}})();return this.motionCache.set(r,s),s.catch(()=>this.motionCache.delete(r)),s}parseMotion(e,t,r,i,s=te(this.setting.getMotionFileName(r,i),this.modelUrl)){let n=this.loadMotion(e,e.byteLength,t,void 0,void 0,this.setting,r,i,!0);if(!n)throw new m("model-load-failed",`Failed to parse motion ${t}.`,{details:se("motion",s)});return n.setEffectIds(this.eyeBlinkIds,[]),n}motionGroupNames(){return Array.from({length:this.setting.getMotionGroupCount()},(e,t)=>this.setting.getMotionGroupName(t))}failMotions(e){this.renderError??=e,this.motionStates.fail(this.renderError)}settleFinishedMotions(){this.motionStates.settleFinished(e=>this._motionManager.isFinishedByHandle(e))}async playMotion(e,t,r,i={}){if(this.disposed)return{status:"disposed"};if(this.renderError)throw this.renderError;let s=this.setting.getMotionCount(e);if(s===0)throw new m("invalid-props",`Unknown Live2D motion group: ${e}. Available groups: ${this.motionGroupNames().join(", ")||"(none)"}`);let n=t??Math.floor(Math.random()*s);if(!Number.isInteger(n)||n<0||n>=s)throw new m("invalid-props",`Motion index ${n} is outside group ${e} (0-${s-1}).`);if(r===cl)this._motionManager.setReservePriority(r);else if(!this._motionManager.reserveMotion(r))return{status:"skipped"};let a=++this.motionGeneration,l,o;try{let u=await this.loadMotionAsset(e,n);if(this.disposed)return{status:"disposed"};if(a!==this.motionGeneration)return{status:"skipped"};if($e(i)){if(await this.ensureAssetBuffer(u),this.disposed)return{status:"disposed"};if(a!==this.motionGeneration)return{status:"skipped"}}if(o=gs(u,i,h=>this.parseMotion(h,`${e}:${n}`,e,n),h=>Se.delete(h)),l=this._motionManager.startMotionPriority(o.motion,o.autoDelete,r),l===-1)return o.releaseBeforeStart(),{status:"skipped"};o.transferToQueue(),this.motionStates.interruptActive()}catch(u){if(o?.releaseBeforeStart(),this.disposed)return{status:"disposed"};throw a===this.motionGeneration&&this._motionManager.setReservePriority(0),u}return this.motionStates.track(l)}hitTestStagePoint(e,t){if(this.disposed||!this.layoutMatrix)return[];(!this.mvpMatrix||this.mvpDirty)&&(this.mvpMatrix=ds(this.stage.getSize(),this.transform,this.layoutMatrix,this.bounds));let r=this.stage.getSize(),i=e/Math.max(1,r.width)*2-1,s=1-t/Math.max(1,r.height)*2,n=this.mvpMatrix.invertTransformX(i),a=this.mvpMatrix.invertTransformY(s),l=[];for(let o=0;o<this.setting.getHitAreasCount();o++){let u=this.getModel().getDrawableIndex(this.setting.getHitAreaId(o));if(u<0||this.getModel().getDrawableOpacity(u)<=0)continue;let h=this.getModel().getDrawableVertexCount(u),d=this.getModel().getDrawableVertices(u);if(h===0)continue;let c=d[0],g=d[0],A=d[1],p=d[1];for(let f=1;f<h;f++){let _=d[f*2],y=d[f*2+1];c=Math.min(c,_),g=Math.max(g,_),A=Math.min(A,y),p=Math.max(p,y)}n>=c&&n<=g&&a>=A&&a<=p&&l.push(this.setting.getHitAreaName(o))}return l}readModelInfo(){let e={};for(let t of this.motionGroupNames())e[t]=this.setting.getMotionCount(t);return{expressions:Array.from({length:this.setting.getExpressionCount()},(t,r)=>this.setting.getExpressionName(r)),hitAreas:Array.from({length:this.setting.getHitAreasCount()},(t,r)=>this.setting.getHitAreaName(r)),motions:e,model3Version:this.model3Version,mocVersion:this._moc?.getMocVersion(),parameters:Array.from({length:this.getModel().getParameterCount()},(t,r)=>({defaultValue:this.getModel().getParameterDefaultValue(r),id:this.getModel().getParameterId(r).getString(),maximum:this.getModel().getParameterMaximumValue(r),minimum:this.getModel().getParameterMinimumValue(r)}))}}findExpression(e){for(let t=0;t<this.setting.getExpressionCount();t++)if(this.setting.getExpressionName(t)===e)return t;return-1}async loadExpressionAsset(e,t){let r=this.expressionCache.get(e);if(r)return r;let i=(async()=>{this.pendingExpressionKeys.add(e),this.diagnostics?.changeResource("pendingExpression",1);try{let s=te(this.setting.getExpressionFileName(t),this.modelUrl),n=await ue(s,"expression",this.assetController.signal,this.resolveAsset),a=this.parseExpression(n,e,s);return this.loadedMotions.add(a),{motion:a,type:"expression",url:s}}finally{this.pendingExpressionKeys.delete(e)&&this.diagnostics?.changeResource("pendingExpression",-1)}})();return this.expressionCache.set(e,i),i.catch(()=>this.expressionCache.delete(e)),i}parseExpression(e,t,r=te(this.setting.getExpressionFileName(this.findExpression(t)),this.modelUrl)){let i=this.loadExpression(e,e.byteLength,t);if(!i)throw new m("model-load-failed",`Failed to parse expression ${t}.`,{details:se("expression",r)});return i}async playExpression(e,t,r){let i=++this.expressionGeneration,s;try{let n=await this.loadExpressionAsset(e,t);if(this.disposed||i!==this.expressionGeneration||$e(r)&&(await this.ensureAssetBuffer(n),this.disposed||i!==this.expressionGeneration))return;if(s=gs(n,r,a=>this.parseExpression(a,e),a=>Se.delete(a)),this._expressionManager.startMotion(s.motion,s.autoDelete)===-1){s.releaseBeforeStart();return}s.transferToQueue()}catch(n){if(s?.releaseBeforeStart(),!this.disposed)throw n}}draw(){if(this.disposed)return;let{gl:e}=we(this.stage),t=hr.getInstance();t.beginFrameProcess(e);try{let r=this.getRenderer();if(r.setRenderState(null,this.viewport),!this.layoutMatrix)return;(this.mvpDirty||!this.mvpMatrix)&&(this.mvpMatrix=ds(this.stage.getSize(),this.transform,this.layoutMatrix,this.bounds),this.mvpDirty=!1,r.setMvpMatrix(this.mvpMatrix)),r.drawModel(this.shaderBaseUrl)}finally{t.endFrameProcess(e),t.releaseStaleRenderTextures(e)}}resize(e,t){this.viewport[2]=e,this.viewport[3]=t,this.mvpDirty=!0,this.setRenderTargetSize(e,t)}toHandle(){return{clearExpression:()=>{this.disposed||(this.expressionGeneration++,this._expressionManager.stopAllMotions())},clearParameter:e=>{this.manualParameters.delete(e)},dispose:()=>this.disposeModel(),expression:async(e,t)=>{let r=Tr(t),i=this.setting.getExpressionCount();if(i===0){if(e)throw new m("invalid-props",`Unknown Live2D expression: ${e}`);return}let s=e??this.setting.getExpressionName(Math.floor(Math.random()*i)),n=this.findExpression(s);if(n<0)throw new m("invalid-props",`Unknown Live2D expression: ${s}. Available: ${this.readModelInfo().expressions.join(", ")}`);await this.playExpression(s,n,r)},focus:(e,t)=>{let r=this.stage.getSize();this.setDragging(Math.max(-1,Math.min(1,e/Math.max(1,r.width)*2-1)),Math.max(-1,Math.min(1,1-t/Math.max(1,r.height)*2)))},getIntrinsicSize:()=>({height:this.bounds.height,width:this.bounds.width}),getModelInfo:()=>this.readModelInfo(),getParameter:e=>this.getModel().getParameterValueById(this.parameterId(e)),hitTest:(e,t)=>this.hitTestStagePoint(e,t),isMotionPlaying:()=>!this.disposed&&!this._motionManager.isFinished(),motion:async(e,t,r)=>{Ue(r);let i=Ke(r);await this.playMotion(e,t,fs[r?.priority??"force"],i)},playMotion:(e,t,r)=>{Ue(r);let i=Ke(r);return this.playMotion(e,t,fs[r?.priority??"force"],i)},onAfterMotionUpdate:e=>(this.afterMotionCallbacks.add(e),As(()=>this.afterMotionCallbacks.delete(e))),onBeforePhysicsUpdate:e=>(this.beforePhysicsCallbacks.add(e),As(()=>this.beforePhysicsCallbacks.delete(e))),setParameter:(e,t)=>{this.disposed||(this.manualParameters.set(e,t),this.getModel().setParameterValueById(this.parameterId(e),t))},setTransform:e=>{this.transform={...e},this.mvpDirty=!0}}}disposeModel(){if(this.disposed)return;this.disposed=!0,this.motionGeneration++,this.expressionGeneration++,this.assetController.abort(new DOMException("Model disposed","AbortError"));for(let t=this.pendingMotionKeys.size;t>0;t--)this.diagnostics?.changeResource("pendingMotion",-1);this.pendingMotionKeys.clear();for(let t=this.pendingExpressionKeys.size;t>0;t--)this.diagnostics?.changeResource("pendingExpression",-1);this.pendingExpressionKeys.clear(),this.motionStates.dispose(),this.detachDriver?.(),this.detachDriver=void 0,this.stopErrorWatch?.(),this.stopErrorWatch=void 0,this.afterMotionCallbacks.clear(),this.beforePhysicsCallbacks.clear(),this.scheduler.release(),this.look&&zt.delete(this.look),this.look=void 0;let e=this.renderContext;this.renderContext=void 0;try{if(e)for(let t of this.textures)e.deleteTexture(t);for(let t=0;t<this.textures.length;t++)this.diagnostics?.changeResource("texture",-1);this.textures.length=0,this.motionCache.clear(),this.expressionCache.clear(),this.manualParameters.clear(),this.setting.release(),super.release();for(let t of this.loadedMotions)Se.delete(t);this.loadedMotions.clear(),this.releaseRenderContext?.(),this.releaseRenderContext=void 0}finally{this.releaseFramework()}}}});var pn={};qe(pn,{createCubismWebGLBackend:()=>An,cubismWebGL:()=>Cl});function _l(){return Reflect.construct(URL,["./cubism-webgl-shaders/",import.meta.url])}function An(e={}){return{createStage:Yr,async loadModel(t,r,i){let s=Gr(e.shaderBaseUrl??_l()),{loadFrameworkModel:n}=await Promise.resolve().then(()=>(fn(),gn));return n(t,r,s,e.shaderBaseUrl?void 0:ml,i)}}}var ml,Cl,mn=_e(()=>{Dt();ml={"fragshadersrcalphablend.frag":`/**
27
27
  * Copyright(c) Live2D Inc. All rights reserved.
28
28
  *
29
29
  * Use of this source code is governed by the Live2D Open Software license
@@ -676,7 +676,7 @@ void main()
676
676
  v_texCoord = a_texCoord;
677
677
  v_texCoord.y = 1.0 - v_texCoord.y;
678
678
  }
679
- `};Al=An()});var In={};qe(In,{mountLive2DDebugOverlay:()=>Bl});function _t(e,{max:t,min:r}){return Number.isFinite(e)?Math.min(t,Math.max(r,e)):r}function pr(e){return{offsetX:_t(e.offsetX,mt.offset),offsetY:_t(e.offsetY,mt.offset),scale:_t(e.scale,mt.scale)}}function pl(e,t){return{x:t.width>0?(e.x-t.left)/t.width-.5:0,y:t.height>0?(e.y-t.top)/t.height-1:0}}function _n(e,t,r){let i=_t(t,mt.scale),s=e.scale===0?1:i/e.scale;return pr({offsetX:r.x-(r.x-e.offsetX)*s,offsetY:r.y-(r.y-e.offsetY)*s,scale:i})}function dr(e,t){return e.scale===t.scale&&e.offsetX===t.offsetX&&e.offsetY===t.offsetY}function Cn(e){return{offsetX:e.offsetX,offsetY:e.offsetY,scale:e.scale,units:"stage"}}function ml(e,t){if(e==="full")return{...Ar};if(e==="upper-body")return{...fr};let r=e.units==="stage",i=e.offsetX??0,s=e.offsetY??0;return pr({offsetX:r?i:t.width>0?i/t.width:0,offsetY:r?s:t.height>0?s/t.height:0,scale:e.scale})}function gr(e){return Number(e.toFixed(3))}function yn(e){let{offsetX:t,offsetY:r,scale:i}=e;return`{ scale: ${gr(i)}, offsetX: ${gr(t)}, offsetY: ${gr(r)}, units: 'stage' }`}function Ct(e){throw new m("invalid-props",e)}function Bn(e){(!e||typeof e!="object")&&Ct("Debug overlay target must be a Live2D instance.");for(let t of["setFit","getFit"])typeof e[t]!="function"&&Ct(`Debug overlay target must provide ${t}().`)}function Bl(e){if(typeof document>"u")throw new m("browser-only","The Live2D debug overlay can only be mounted in a browser.");(!e||typeof e!="object")&&Ct("mountLive2DDebugOverlay options must be an object."),Bn(e.target),e.container instanceof HTMLElement||Ct("mountLive2DDebugOverlay container must be an HTMLElement.");let{container:t}=e,r=e.target,i=!1,s=0,n=!1,a=!1,l=0,o=t.style.position,u=getComputedStyle(t).position;(!u||u==="static")&&(t.style.position="relative");let c=document.createElement("div");c.dataset.live2dDebug="";let d=c.attachShadow({mode:"open"}),h=document.createElement("style");h.textContent=_l;let g=document.createElement("div");g.className="surface",g.tabIndex=0,g.setAttribute("role","application"),g.setAttribute("aria-label","Live2D placement. Drag to move, scroll to zoom, arrow keys to nudge."),g.innerHTML='<div class="frame"></div><div class="crosshair x"></div><div class="crosshair y"></div>';let A=document.createElement("div");A.className="bar";let p=document.createElement("output");p.className="zoom";let f=document.createElement("code");f.className="value",f.hidden=!0;let _=document.createElement("p");_.className="hint",_.textContent="Drag to move, scroll to zoom, arrow keys to nudge.";let y=(I,F,ke)=>{let Qe=document.createElement("button");return Qe.type="button",Qe.textContent=I,ke&&(Qe.className=ke),Qe.addEventListener("click",F),Qe},C=()=>{let I=document.createElement("span");return I.className="divider",I.setAttribute("aria-hidden","true"),I},b=()=>t.getBoundingClientRect(),x=I=>ml(I.getFit(),{height:b().height,width:b().width}),B=x(r),E,T,W,ee,me={...B},ae=()=>{f.textContent=yn(B),p.textContent=`${Math.round(B.scale*100)}%`,E.setAttribute("aria-pressed",String(dr(B,fr))),T.setAttribute("aria-pressed",String(dr(B,Ar))),W.disabled=dr(B,me)},Y=()=>{_.hidden=!0},v=I=>{B=pr(I),ae(),!n&&(n=!0,s=requestAnimationFrame(()=>{if(n=!1,s=0,i)return;let F=Cn(B);a=!0;try{r.setFit(F)}finally{a=!1}e.onChange?.(F)}))},z=I=>{ee.textContent=I,clearTimeout(l),l=window.setTimeout(()=>{i||(ee.textContent="Copy")},2e3)},X=()=>{Y();let I=yn(B),F=navigator.clipboard;if(!F){f.hidden=!1;return}F.writeText(I).then(()=>z("Copied")).catch(()=>{f.hidden=!1})},oe=I=>{Y(),v({...I})},Ir=I=>{Y(),St(I)};E=y("Upper body",()=>oe(fr)),T=y("Full",()=>oe(Ar)),W=y("Reset",()=>oe(me)),ee=y("Copy",X),A.append(y("−",()=>Ir(-.05),"step"),p,y("+",()=>Ir(bn),"step"),C(),E,T,W,C(),ee),d.append(h,g,_,f,A),t.append(c),ae();function St(I){v(_n(B,B.scale+I,{x:B.offsetX,y:B.offsetY}))}let J=null,Sr=I=>{g.dataset.dragging=String(I),A.dataset.dragging=String(I)},Mr=I=>{I.stopPropagation(),I.button===0&&(Y(),g.setPointerCapture(I.pointerId),J={placement:B,pointerId:I.pointerId,x:I.clientX,y:I.clientY},Sr(!0),g.focus())},xr=I=>{if(!J||J.pointerId!==I.pointerId)return;I.stopPropagation();let F=b();v({...J.placement,offsetX:J.placement.offsetX+(I.clientX-J.x)/Math.max(1,F.width),offsetY:J.placement.offsetY+(I.clientY-J.y)/Math.max(1,F.height)})},Ze=I=>{!J||J.pointerId!==I.pointerId||(I.stopPropagation(),g.hasPointerCapture(I.pointerId)&&g.releasePointerCapture(I.pointerId),J=null,Sr(!1))},wr=I=>{I.preventDefault(),I.stopPropagation(),Y();let F=I.deltaMode===1?I.deltaY*16:I.deltaY;v(_n(B,B.scale*Math.exp(-F*.0015),pl({x:I.clientX,y:I.clientY},b())))},Er=I=>{let F=bl[I.key];if(F){I.preventDefault(),Y();let ke=I.shiftKey?yl:Cl;v({...B,offsetX:B.offsetX+F[0]*ke,offsetY:B.offsetY+F[1]*ke});return}I.key==="+"||I.key==="="?(I.preventDefault(),Y(),St(bn)):I.key==="-"&&(I.preventDefault(),Y(),St(-.05))},vr=I=>I.stopPropagation();return g.addEventListener("click",vr),g.addEventListener("pointerdown",Mr),g.addEventListener("pointermove",xr),g.addEventListener("pointerup",Ze),g.addEventListener("pointercancel",Ze),g.addEventListener("wheel",wr,{passive:!1}),g.addEventListener("keydown",Er),{dispose(){i||(i=!0,clearTimeout(l),s&&cancelAnimationFrame(s),s=0,n=!1,g.removeEventListener("click",vr),g.removeEventListener("pointerdown",Mr),g.removeEventListener("pointermove",xr),g.removeEventListener("pointerup",Ze),g.removeEventListener("pointercancel",Ze),g.removeEventListener("wheel",wr),g.removeEventListener("keydown",Er),c.remove(),t.style.position=o)},getFit:()=>Cn(B),refresh(){i||a||(B=x(r),me={...B},ae())},setTarget(I){Bn(I),r=I,B=x(I),me={...B},ae()}}}var mt,fr,Ar,_l,Cl,yl,bn,bl,Sn=_e(()=>{Me();mt={offset:{max:1,min:-1},scale:{max:2.5,min:.25}},fr=Object.freeze({offsetX:0,offsetY:0,scale:1}),Ar=Object.freeze({offsetX:0,offsetY:-.5,scale:.5});_l=`
679
+ `};Cl=An()});var In={};qe(In,{mountLive2DDebugOverlay:()=>wl});function _t(e,{max:t,min:r}){return Number.isFinite(e)?Math.min(t,Math.max(r,e)):r}function pr(e){return{offsetX:_t(e.offsetX,mt.offset),offsetY:_t(e.offsetY,mt.offset),scale:_t(e.scale,mt.scale)}}function yl(e,t){return{x:t.width>0?(e.x-t.left)/t.width-.5:0,y:t.height>0?(e.y-t.top)/t.height-1:0}}function _n(e,t,r){let i=_t(t,mt.scale),s=e.scale===0?1:i/e.scale;return pr({offsetX:r.x-(r.x-e.offsetX)*s,offsetY:r.y-(r.y-e.offsetY)*s,scale:i})}function dr(e,t){return e.scale===t.scale&&e.offsetX===t.offsetX&&e.offsetY===t.offsetY}function Cn(e){return{offsetX:e.offsetX,offsetY:e.offsetY,scale:e.scale,units:"stage"}}function bl(e,t){if(e==="full")return{...Ar};if(e==="upper-body")return{...fr};let r=e.units==="stage",i=e.offsetX??0,s=e.offsetY??0;return pr({offsetX:r?i:t.width>0?i/t.width:0,offsetY:r?s:t.height>0?s/t.height:0,scale:e.scale})}function gr(e){return Number(e.toFixed(3))}function yn(e){let{offsetX:t,offsetY:r,scale:i}=e;return`{ scale: ${gr(i)}, offsetX: ${gr(t)}, offsetY: ${gr(r)}, units: 'stage' }`}function Ct(e){throw new m("invalid-props",e)}function Bn(e){(!e||typeof e!="object")&&Ct("Debug overlay target must be a Live2D instance.");for(let t of["setFit","getFit"])typeof e[t]!="function"&&Ct(`Debug overlay target must provide ${t}().`)}function wl(e){if(typeof document>"u")throw new m("browser-only","The Live2D debug overlay can only be mounted in a browser.");(!e||typeof e!="object")&&Ct("mountLive2DDebugOverlay options must be an object."),Bn(e.target),e.container instanceof HTMLElement||Ct("mountLive2DDebugOverlay container must be an HTMLElement.");let{container:t}=e,r=e.target,i=!1,s=0,n=!1,a=!1,l=0,o=t.style.position,u=getComputedStyle(t).position;(!u||u==="static")&&(t.style.position="relative");let h=document.createElement("div");h.dataset.live2dDebug="";let d=h.attachShadow({mode:"open"}),c=document.createElement("style");c.textContent=Bl;let g=document.createElement("div");g.className="surface",g.tabIndex=0,g.setAttribute("role","application"),g.setAttribute("aria-label","Live2D placement. Drag to move, scroll to zoom, arrow keys to nudge."),g.innerHTML='<div class="frame"></div><div class="crosshair x"></div><div class="crosshair y"></div>';let A=document.createElement("div");A.className="bar";let p=document.createElement("output");p.className="zoom";let f=document.createElement("code");f.className="value",f.hidden=!0;let _=document.createElement("p");_.className="hint",_.textContent="Drag to move, scroll to zoom, arrow keys to nudge.";let y=(I,F,ke)=>{let Qe=document.createElement("button");return Qe.type="button",Qe.textContent=I,ke&&(Qe.className=ke),Qe.addEventListener("click",F),Qe},C=()=>{let I=document.createElement("span");return I.className="divider",I.setAttribute("aria-hidden","true"),I},b=()=>t.getBoundingClientRect(),w=I=>bl(I.getFit(),{height:b().height,width:b().width}),B=w(r),E,T,W,ee,me={...B},ae=()=>{f.textContent=yn(B),p.textContent=`${Math.round(B.scale*100)}%`,E.setAttribute("aria-pressed",String(dr(B,fr))),T.setAttribute("aria-pressed",String(dr(B,Ar))),W.disabled=dr(B,me)},Y=()=>{_.hidden=!0},v=I=>{B=pr(I),ae(),!n&&(n=!0,s=requestAnimationFrame(()=>{if(n=!1,s=0,i)return;let F=Cn(B);a=!0;try{r.setFit(F)}finally{a=!1}e.onChange?.(F)}))},z=I=>{ee.textContent=I,clearTimeout(l),l=window.setTimeout(()=>{i||(ee.textContent="Copy")},2e3)},X=()=>{Y();let I=yn(B),F=navigator.clipboard;if(!F){f.hidden=!1;return}F.writeText(I).then(()=>z("Copied")).catch(()=>{f.hidden=!1})},oe=I=>{Y(),v({...I})},Ir=I=>{Y(),St(I)};E=y("Upper body",()=>oe(fr)),T=y("Full",()=>oe(Ar)),W=y("Reset",()=>oe(me)),ee=y("Copy",X),A.append(y("−",()=>Ir(-.05),"step"),p,y("+",()=>Ir(bn),"step"),C(),E,T,W,C(),ee),d.append(c,g,_,f,A),t.append(h),ae();function St(I){v(_n(B,B.scale+I,{x:B.offsetX,y:B.offsetY}))}let J=null,Sr=I=>{g.dataset.dragging=String(I),A.dataset.dragging=String(I)},Mr=I=>{I.stopPropagation(),I.button===0&&(Y(),g.setPointerCapture(I.pointerId),J={placement:B,pointerId:I.pointerId,x:I.clientX,y:I.clientY},Sr(!0),g.focus())},wr=I=>{if(!J||J.pointerId!==I.pointerId)return;I.stopPropagation();let F=b();v({...J.placement,offsetX:J.placement.offsetX+(I.clientX-J.x)/Math.max(1,F.width),offsetY:J.placement.offsetY+(I.clientY-J.y)/Math.max(1,F.height)})},Ze=I=>{!J||J.pointerId!==I.pointerId||(I.stopPropagation(),g.hasPointerCapture(I.pointerId)&&g.releasePointerCapture(I.pointerId),J=null,Sr(!1))},xr=I=>{I.preventDefault(),I.stopPropagation(),Y();let F=I.deltaMode===1?I.deltaY*16:I.deltaY;v(_n(B,B.scale*Math.exp(-F*.0015),yl({x:I.clientX,y:I.clientY},b())))},Er=I=>{let F=Ml[I.key];if(F){I.preventDefault(),Y();let ke=I.shiftKey?Sl:Il;v({...B,offsetX:B.offsetX+F[0]*ke,offsetY:B.offsetY+F[1]*ke});return}I.key==="+"||I.key==="="?(I.preventDefault(),Y(),St(bn)):I.key==="-"&&(I.preventDefault(),Y(),St(-.05))},vr=I=>I.stopPropagation();return g.addEventListener("click",vr),g.addEventListener("pointerdown",Mr),g.addEventListener("pointermove",wr),g.addEventListener("pointerup",Ze),g.addEventListener("pointercancel",Ze),g.addEventListener("wheel",xr,{passive:!1}),g.addEventListener("keydown",Er),{dispose(){i||(i=!0,clearTimeout(l),s&&cancelAnimationFrame(s),s=0,n=!1,g.removeEventListener("click",vr),g.removeEventListener("pointerdown",Mr),g.removeEventListener("pointermove",wr),g.removeEventListener("pointerup",Ze),g.removeEventListener("pointercancel",Ze),g.removeEventListener("wheel",xr),g.removeEventListener("keydown",Er),h.remove(),t.style.position=o)},getFit:()=>Cn(B),refresh(){i||a||(B=w(r),me={...B},ae())},setTarget(I){Bn(I),r=I,B=w(I),me={...B},ae()}}}var mt,fr,Ar,Bl,Il,Sl,bn,Ml,Sn=_e(()=>{Me();mt={offset:{max:1,min:-1},scale:{max:2.5,min:.25}},fr=Object.freeze({offsetX:0,offsetY:0,scale:1}),Ar=Object.freeze({offsetX:0,offsetY:-.5,scale:.5});Bl=`
680
680
  :host {
681
681
  --debug-accent: #ff718f;
682
682
  --debug-line: #343942;
@@ -808,6 +808,6 @@ button.step { min-width: 28px; padding: 4px 0; font-size: 15px; }
808
808
  }
809
809
 
810
810
  [hidden] { display: none !important; }
811
- `,Cl=.01,yl=.001,bn=.05,bl={ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1]}});Me();xt();var br="https://cubism.live2d.com/sdk-web/core/06/live2dcubismcore.min.js",yt=new Map,Mn=3e4;function Il(e){if(typeof performance>"u"||!performance.getEntriesByName)return;let t=performance.getEntriesByName(e,"resource").at(-1)?.responseStatus;return typeof t=="number"&&t>0?t:void 0}function je(e){return{assetType:"core",httpStatus:e?Il(e):void 0,url:e}}function _r(){return`Live2D Cubism Core is not loaded. Pass a coreUrl option (to createLive2D() or <Live2DCanvas>), for example the OFFICIAL_CUBISM_CORE_URL constant, or load the script before creating a model:
811
+ `,Il=.01,Sl=.001,bn=.05,Ml={ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1]}});Me();wt();var br="https://cubism.live2d.com/sdk-web/core/06/live2dcubismcore.min.js",yt=new Map,Mn=3e4;function xl(e){if(typeof performance>"u"||!performance.getEntriesByName)return;let t=performance.getEntriesByName(e,"resource").at(-1)?.responseStatus;return typeof t=="number"&&t>0?t:void 0}function je(e){return{assetType:"core",httpStatus:e?xl(e):void 0,url:e}}function _r(){return`Live2D Cubism Core is not loaded. Pass a coreUrl option (to createLive2D() or <Live2DCanvas>), for example the OFFICIAL_CUBISM_CORE_URL constant, or load the script before creating a model:
812
812
  <script src="/path/to/live2dcubismcore.min.js"><\/script>
813
- Official SDK download: https://www.live2d.com/sdk/download/web/`}function Sl(){if(typeof window>"u"||typeof document>"u")throw new m("browser-only","live2d-web can only create a stage in a browser.")}function Ml(e){return new Promise((t,r)=>{let i=document.createElement("script"),s=new AbortController,n,a=o=>{if(n!==void 0&&clearTimeout(n),n=void 0,s.abort(),!o){t();return}i.remove(),r(o)},l=o=>{if(o.type==="load"&&window.Live2DCubismCore){a();return}a(o.type==="load"?new m("core-missing",_r(),{details:je(e)}):new m("core-missing",`Failed to load Live2D Cubism Core from ${e}.`,{cause:o,details:je(e)}))};i.addEventListener("load",l,{signal:s.signal}),i.addEventListener("error",l,{signal:s.signal}),n=setTimeout(()=>{a(new m("core-missing",`Live2D Cubism Core did not load from ${e} within ${Mn} ms.`,{details:je(e)}))},Mn),i.src=e,i.async=!0,i.dataset.live2dWebCore="true",document.head.appendChild(i)})}function xl(e,t){return new Promise((r,i)=>{let s=()=>i(t.reason);t.addEventListener("abort",s,{once:!0}),e.then(r,i).finally(()=>{t.removeEventListener("abort",s)})})}async function Tn(e,t={}){Sl();let{signal:r}=t;if(r?.aborted)throw r.reason;if(window.Live2DCubismCore)return;if(!e)throw new m("core-missing",_r(),{details:je()});let i=new URL(e,document.baseURI).href,s=yt.get(i);if(s||(s=Ml(i).finally(()=>{yt.get(i)===s&&yt.delete(i)}),yt.set(i,s)),await(r?xl(s,r):s),r?.aborted)throw r.reason;if(!window.Live2DCubismCore)throw new m("core-missing",_r(),{details:je(i)})}function mr(e){return Number.isFinite(e)&&e>0?e:1e-6}function Fn(e,t,r="upper-body"){let i=e.width/t.width,s=e.height/t.height;if(r==="full")return{scale:mr(Math.min(i,s)),x:e.width/2,y:e.height/2};let n=mr(Math.min(i*2,s*2));if(r==="upper-body")return{scale:n,x:e.width/2,y:e.height};let a=r.offsetX??0,l=r.offsetY??0,o=r.units==="stage";return{scale:mr(n*r.scale),x:e.width/2+(o?a*e.width:a),y:e.height+(o?l*e.height:l)}}var It={desktopMaxResolution:2,desktopPixelBudget:4e6,longFrameMs:33,longFrameRatioThreshold:.05,minResolution:1,mobileMaxResolution:1.5,mobilePixelBudget:15e5,resolutionStep:.25,sampleWindowMs:3e3};function pe(e,t){if(!Number.isFinite(e)||e<=0)throw new m("invalid-props",`${t} must be a finite number greater than 0.`);return e}function Vn(e){let t={...It,...e};if(pe(t.desktopMaxResolution,"quality.desktopMaxResolution"),pe(t.desktopPixelBudget,"quality.desktopPixelBudget"),pe(t.longFrameMs,"quality.longFrameMs"),pe(t.minResolution,"quality.minResolution"),pe(t.mobileMaxResolution,"quality.mobileMaxResolution"),pe(t.mobilePixelBudget,"quality.mobilePixelBudget"),pe(t.resolutionStep,"quality.resolutionStep"),pe(t.sampleWindowMs,"quality.sampleWindowMs"),!Number.isFinite(t.longFrameRatioThreshold)||t.longFrameRatioThreshold<0||t.longFrameRatioThreshold>1)throw new m("invalid-props","quality.longFrameRatioThreshold must be between 0 and 1.");if(t.mobileMaxResolution<t.minResolution||t.desktopMaxResolution<t.minResolution)throw new m("invalid-props","quality max resolutions must be greater than or equal to minResolution.");return t}function xn(e){return Number.isFinite(e)&&e>0?e:1}function Cr(e,t=It){let r=xn(e.width),i=xn(e.height),s=e.mobile?t.mobileMaxResolution:t.desktopMaxResolution,n=e.mobile?t.mobilePixelBudget:t.desktopPixelBudget,a=Number.isFinite(e.devicePixelRatio)&&e.devicePixelRatio>0?e.devicePixelRatio:t.minResolution,l=Math.sqrt(n/(r*i));return Math.max(t.minResolution,Math.min(a,s,l))}function On(e,t,r=It){return!Number.isFinite(e)||e<=r.minResolution?r.minResolution:!Number.isFinite(t)||t<=r.longFrameRatioThreshold?e:Math.max(r.minResolution,Math.round((e-r.resolutionStep)*100)/100)}function yr(e,t){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches||Math.min(e,t)<768}function wl(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function El(e){return Number.isFinite(e)&&e>0?e:0}function wn(e){return Number.isFinite(e)?e:0}function vl(e){return e*e*(3-2*e)}var Pl=class{holdRemainingMs=0;lastForcedValue=0;releaseRemainingMs=0;update(e){if(e.speaking)return this.lastForcedValue=wl(e.mouthOpen),this.releaseRemainingMs=200,this.holdRemainingMs=500,this.lastForcedValue;let t=El(e.deltaMs);if(this.releaseRemainingMs>0){let r=Math.min(this.releaseRemainingMs,t);if(this.releaseRemainingMs-=r,t-=r,this.releaseRemainingMs>0){let i=vl(1-this.releaseRemainingMs/200);return this.lastForcedValue*(1-i)+wn(e.motionValue)*i}if(t===0)return wn(e.motionValue)}return this.holdRemainingMs>0&&(this.holdRemainingMs=Math.max(0,this.holdRemainingMs-t),this.holdRemainingMs>0)?0:null}},Rl=[["A","A"],["E","E"],["I","I"],["O","O"],["U","U"],["S","I"]],Dl=.7,Ll=50,Tl=50,Fl=.7,Vl=.9,bt=new Map,Bt;function En(e){let t=!0;return()=>{t&&(t=!1,e())}}function vn(e){return Number.isFinite(e)?Math.max(0,e):0}function Ol(){return typeof performance>"u"?Date.now():performance.now()}function kl(){return Bt||(Bt=kr().then(()=>Or).catch(e=>{throw Bt=void 0,e})),Bt}function Ql(e){if(e instanceof URL)return e.href;let t=typeof location>"u"?"http://localhost/":location.href;return new URL(e,t).href}function Ul(e,t,r){let i=Ql(e),s=bt.get(i);if(s)return s;let n=r(i).then(async a=>{if(!a.ok)throw new Error(`Failed to load the lip-sync profile (${a.status}).`);return new URL(i).pathname.toLowerCase().endsWith(".bin")?t.parseBinaryProfile(await a.arrayBuffer()):await a.json()});return bt.set(i,n),n.catch(()=>{bt.get(i)===n&&bt.delete(i)}),n}function Nl(e,t,r=fetch){return typeof e=="string"||e instanceof URL?Ul(e,t,r):e instanceof ArrayBuffer?Promise.resolve(t.parseBinaryProfile(e)):Promise.resolve(e)}function Gl(e,t=Ol){let r=0,i=NaN,s=0,n=NaN,a=()=>{let l=Math.min(vn(e.volume)*Vl,1)**Fl,o={A:0,E:0,I:0,O:0,U:0};for(let[u,c]of Rl){let d=Math.min(Dl,vn(e.weights?.[u]??0)*l);o[c]=Math.max(o[c],d)}return Math.max(...Object.values(o))};return()=>{let l=t();if((Number.isNaN(i)||l-i>=Ll)&&(r=a(),i=l),Number.isNaN(n))return s=r,n=l,s;let o=Math.max(0,l-n),u=Math.min(1,o/Tl);return s+=(r-s)*u,n=l,s}}async function Xl(e,t,r={}){if(typeof window<"u"&&window.isSecureContext===!1)throw new Error("wLipSync requires HTTPS or localhost because it uses AudioWorklet.");if(!e.context||!("audioWorklet"in e.context))throw new Error("The source AudioNode context does not support AudioWorklet.");let i=await(r.loadModule??kl)(),s=r.fetcher??(typeof fetch>"u"?void 0:fetch.bind(globalThis));if((typeof t=="string"||t instanceof URL)&&!s)throw new Error("fetch is unavailable, so the lip-sync profile URL cannot be loaded.");let n=await Nl(t,i,s),a=await i.createWLipSyncNode(e.context,n),l=En(()=>{try{a.disconnect()}catch{}try{a.port.close()}catch{}});try{e.connect(a)}catch(u){throw l(),u}let o=Gl(a,r.now);return{dispose:En(()=>{try{e.disconnect(a)}catch{}l()}),getMouthOpen:o,node:a}}function Hl(e,t){if(!Array.isArray(e))throw new m("invalid-props","Motion sequence steps must be an array.");for(let r=0;r<e.length;r++){let i=e[r];if(typeof i!="object"||i===null||Array.isArray(i))throw new m("invalid-props",`Motion sequence step ${r} must be an object.`);if(typeof i.group!="string"||i.group.trim()==="")throw new m("invalid-props",`Motion sequence step ${r} needs a non-empty group.`);let s=t.motions[i.group];if(!Number.isInteger(s)||s<=0)throw new m("invalid-props",`Unknown Live2D motion group in sequence step ${r}: ${i.group}.`);if(i.index!==void 0&&(!Number.isInteger(i.index)||i.index<0||i.index>=s))throw new m("invalid-props",`Motion index ${i.index} is outside group ${i.group} in sequence step ${r}.`);Ue(i.options)}}async function Pn(e,t,r){Hl(e,t);for(let i=0;i<e.length;i++){let s=e[i],n=await r(s.group,s.index,s.options);if(n.status!=="completed")return{completedSteps:i,status:n.status,stepIndex:i}}return{completedSteps:e.length,status:"completed"}}function Rn(e){let t=!0;return()=>{t&&(t=!1,e())}}var Dn=class{setup;report;cleanup;generation=0;constructor(e,t){this.setup=e,this.report=t}attach(e){this.detach();let t=this.generation;try{let r=this.setup(e);r instanceof Promise?r.then(i=>{if(t!==this.generation){i();return}this.cleanup=Rn(i)}).catch(i=>{t===this.generation&&this.report(i)}):this.cleanup=Rn(r)}catch(r){this.report(r)}}detach(){this.generation++,this.cleanup?.(),this.cleanup=void 0}};function Ln(e){let t=!0;return()=>{t&&(t=!1,e())}}function Je(e,t){return e instanceof m?e:new m(t,e instanceof Error?e.message:String(e),{cause:e})}function kn(e){if(e!==void 0){if(!e||typeof e!="object")throw new m("invalid-props","accessibility must be a decorative or image accessibility object.");if(e.mode!=="decorative"&&e.mode!=="image"&&e.mode!==void 0)throw new m("invalid-props",'accessibility.mode must be "decorative" or "image".');if(e.mode!=="decorative"){if(typeof e.label!="string"||e.label.trim()==="")throw new m("invalid-props","image accessibility requires a non-empty label.");for(let[t,r]of[["describedBy",e.describedBy],["fallbackText",e.fallbackText]])if(r!==void 0&&typeof r!="string")throw new m("invalid-props",`accessibility.${t} must be a string when provided.`)}}}function Wl(e){if(typeof window>"u"||typeof document>"u"||typeof HTMLElement>"u")throw new m("browser-only","Live2D can only be created in a browser.");if(!(e.container instanceof HTMLElement))throw new m("invalid-props","container must be an HTMLElement.");if(kn(e.accessibility),e.src!==void 0&&(typeof e.src!="string"||e.src.trim()===""))throw new m("invalid-props","src must be a non-empty model3.json path or URL string.");if(e.resolveAsset!==void 0&&typeof e.resolveAsset!="function")throw new m("invalid-props","resolveAsset must be a function.");if(e.quality!==void 0&&e.resolution!==void 0)throw new m("invalid-props","quality and resolution are mutually exclusive.");if(!Number.isInteger(e.retries??2)||(e.retries??2)<0)throw new m("invalid-props","retries must be a non-negative integer.");if("resolution"in e&&e.resolution!==void 0&&(!Number.isFinite(e.resolution)||e.resolution<1))throw new m("invalid-props","resolution must be a finite number greater than or equal to 1.");if(e.maxFps!==void 0&&(!Number.isFinite(e.maxFps)||e.maxFps<=0))throw new m("invalid-props","maxFps must be a finite number greater than 0.");if(e.pauseWhenOffscreen!==void 0&&typeof e.pauseWhenOffscreen!="boolean")throw new m("invalid-props","pauseWhenOffscreen must be a boolean.");if(e.followPointer!==void 0&&typeof e.followPointer!="boolean")throw new m("invalid-props","followPointer must be a boolean.");if(e.debug!==void 0&&typeof e.debug!="boolean")throw new m("invalid-props","debug must be a boolean.");Mt(e.idleMotion)}function Yl(e,t){return new Promise((r,i)=>{if(t.aborted){i(t.reason);return}let s,n=()=>{clearTimeout(s),i(t.reason)};s=setTimeout(()=>{t.removeEventListener("abort",n),r()},e),t.addEventListener("abort",n,{once:!0})})}var zl=class{options;abortController;disposed=!1;features=[];accessibility;fit;debug;debugOverlay;debugWanted;intersectionObserver;listeners=new Set;models=[];backend;onStageResume;pauseReasons=new Set;resizeAnimationFrame=0;resizeObserver;stage;stageCleanup=[];state={loadingStage:"core",status:"loading"};constructor(e){this.options=e,this.fit=e.fit??"upper-body",this.debug=e.debug??!1,this.accessibility=e.accessibility}get model(){return this.models[0]?.handle}getState=()=>this.state;getModelHandle=()=>this.model??null;subscribe=e=>(this.listeners.add(e),Ln(()=>this.listeners.delete(e)));updateState(e){this.state={...this.state,...e};for(let t of this.listeners)t()}report(e){this.disposed||(this.updateState({error:e,loadingStage:void 0,status:"error"}),this.options.onError?.(e))}readRenderState(e){let t=e.getSize(),r=e.getResolution();return{bufferPixels:Math.round(t.width*t.height*r**2),height:t.height,resolution:r,width:t.width}}async resolveBackend(){if(this.options.backend)return this.options.backend;let{cubismWebGL:e}=await Promise.resolve().then(()=>(mn(),pn));return e}addPauseReason(e){if(this.pauseReasons.has(e))return;let t=this.pauseReasons.size===0;this.pauseReasons.add(e),t&&this.stage?.pause()}removePauseReason(e){!this.pauseReasons.delete(e)||this.pauseReasons.size>0||(this.onStageResume?.(),this.stage?.resume())}teardown(){this.abortController?.abort(),this.abortController=void 0,cancelAnimationFrame(this.resizeAnimationFrame),this.resizeAnimationFrame=0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.onStageResume=void 0,this.resizeObserver?.disconnect(),this.resizeObserver=void 0;for(let e of this.stageCleanup.splice(0).reverse())e();for(let e of[...this.features].reverse())e.detach();for(let e of this.models){this.releaseDebugOverlay(e);for(let t of e.features.splice(0).reverse())t.detach();e.handle.dispose()}this.models=[],this.stage?.dispose(),this.stage=void 0}async start(){if(this.disposed)throw new m("invalid-props","Cannot start a disposed Live2D instance.");Wl(this.options),this.pauseReasons.delete("hidden"),this.pauseReasons.delete("offscreen");let e=this.options.resolution!==void 0?void 0:Vn(typeof this.options.quality=="object"?this.options.quality:void 0),t=new AbortController;this.abortController=t;let r=()=>t.abort(this.options.signal?.reason);this.options.signal?.aborted&&r(),this.options.signal?.addEventListener("abort",r,{once:!0}),this.stageCleanup.push(()=>{this.options.signal?.removeEventListener("abort",r)});try{if(this.updateState({error:void 0,loadingStage:"core",status:"loading"}),await Tn(this.options.coreUrl,{signal:t.signal}),t.signal.aborted)throw t.signal.reason;let i=this.backend??await this.resolveBackend();if(this.backend=i,t.signal.aborted)throw t.signal.reason;this.updateState({loadingStage:"stage"});let s=this.options.container.getBoundingClientRect();(s.width<1||s.height<1)&&console.warn("[live2d-web] The container has zero size, so the canvas will be 1x1 and nothing will be visible. Give the container a CSS width and height.");let n=Math.max(1,s.width),a=Math.max(1,s.height),l=this.options.resolution!==void 0?this.options.resolution:Cr({devicePixelRatio:window.devicePixelRatio,height:a,mobile:yr(n,a),width:n},e),o=i.createStage(this.options.container,{accessibility:this.accessibility,height:a,maxFps:this.options.maxFps,resolution:l,width:n});this.stage=o,this.pauseReasons.size>0&&o.pause(),this.stageCleanup.push(o.onError(p=>{this.report(Je(p,"render-error"))}));let u=0,c=0,d=0;e&&this.stageCleanup.push(o.onFrame(p=>{if(u+=p,c++,p>e.longFrameMs&&d++,u<e.sampleWindowMs)return;let f=On(o.getResolution(),c?d/c:0,e);f<o.getResolution()&&(o.setResolution(f),this.updateState({render:this.readRenderState(o)})),u=0,c=0,d=0}));let h=()=>{if(this.resizeAnimationFrame=0,this.disposed||this.stage!==o)return;let p=this.options.container.getBoundingClientRect(),f=Math.max(1,p.width),_=Math.max(1,p.height);if(!(Math.abs(f-n)<.5&&Math.abs(_-a)<.5)){if(n=f,a=_,e){let y=Cr({devicePixelRatio:window.devicePixelRatio,height:a,mobile:yr(n,a),width:n},e);y<o.getResolution()&&o.setResolution(y)}o.resize(n,a),this.applyFit(),this.updateState({render:this.readRenderState(o)})}},g=()=>{this.resizeAnimationFrame||(this.resizeAnimationFrame=requestAnimationFrame(h))};this.resizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(g),this.resizeObserver?.observe(this.options.container),this.onStageResume=()=>{u=0,c=0,d=0,g()};let A=()=>{document.hidden?this.addPauseReason("hidden"):this.removePauseReason("hidden")};if(document.addEventListener("visibilitychange",A),A(),this.stageCleanup.push(()=>{document.removeEventListener("visibilitychange",A)}),this.intersectionObserver=(this.options.pauseWhenOffscreen??!0)&&typeof IntersectionObserver<"u"?new IntersectionObserver(p=>{let f=p[p.length-1];f&&(f.isIntersecting?this.removePauseReason("offscreen"):this.addPauseReason("offscreen"))}):void 0,this.intersectionObserver?.observe(this.options.container),this.updateState({loadingStage:"model",render:this.readRenderState(o)}),this.options.src!==void 0){let p=await this.loadModel(i,o,this.options.src,t.signal);if(t.signal.aborted||this.stage!==o)throw p.dispose(),t.signal.reason;this.models.push({features:[],fit:this.fit,followPointer:this.options.followPointer??!1,handle:p}),this.applyFit();for(let f of this.features)f.attach(p)}{let p=this.options.container,f=y=>{if(this.stage!==o)return;let C=o.toWorld(y.clientX,y.clientY);for(let b of this.models)b.followPointer&&b.handle.focus(C.x,C.y)},_=()=>{if(this.stage!==o)return;let y=o.getSize();for(let C of this.models)C.followPointer&&C.handle.focus(y.width/2,y.height/2)};p.addEventListener("pointermove",f),p.addEventListener("pointerleave",_),this.stageCleanup.push(()=>{p.removeEventListener("pointermove",f),p.removeEventListener("pointerleave",_)})}this.debug&&this.models[0]&&await this.mountDebugOverlay(o,this.models[0]),this.updateState({error:void 0,loadingStage:void 0,render:this.readRenderState(o),status:"ready"})}catch(i){if(t.signal.aborted){if(this.disposed)return;throw i}let s=Je(i,"adapter-error");throw this.teardown(),this.report(s),s}}async loadModel(e,t,r,i,s){let n=s?.retries??this.options.retries??2,a;for(let l=0;l<=n;l++)try{return await e.loadModel(t,r,{idleMotion:s?.idleMotion??this.options.idleMotion,resolveAsset:s?.resolveAsset??this.options.resolveAsset,signal:i})}catch(o){if(i.aborted)throw o;a=Je(o,"model-load-failed");let u=a.details?.httpStatus;if(a.code==="invalid-props"||u!==void 0&&u>=400&&u<500||l===n)break;await Yl(l===0?250:500,i)}throw a||new m("model-load-failed","The model could not be loaded.")}requireModel(){if(this.disposed)throw new m("invalid-props","The Live2D instance has been disposed.");if(!this.model)throw new m("model-load-failed","The Live2D model is not ready.");return this.model}async mountDebugOverlay(e,t){let{mountLive2DDebugOverlay:r}=await Promise.resolve().then(()=>(Sn(),In));if(this.disposed||this.stage!==e||!this.models.includes(t)||this.debugWanted!==t||this.debugOverlay?.owner===t)return;this.releaseDebugOverlay();let i=r({container:this.options.container,onChange:s=>(t.onFitChange??this.options.onFitChange)?.(s),target:{getFit:()=>typeof t.fit=="object"?{...t.fit}:t.fit,setFit:s=>{t.fit=s,this.applyFit()}}});this.debugOverlay={dispose:i.dispose,owner:t,refresh:i.refresh},this.stageCleanup.push(()=>this.releaseDebugOverlay(t))}releaseDebugOverlay(e){let t=this.debugOverlay;!t||e!==void 0&&t.owner!==e||(this.debugOverlay=void 0,t.dispose())}setDebug(e,t){if(typeof e!="boolean")throw new m("invalid-props","debug must be a boolean.");let r=t??this.models[0];if(!e){this.debugWanted===r&&(this.debugWanted=void 0),this.releaseDebugOverlay(r),t||(this.debug=!1);return}if(t||(this.debug=!0),!this.stage||!r)return;let i=this.debugWanted;this.debugWanted=r,i&&i!==r&&console.warn("[live2d-web] The placement overlay moved to the model that asked for it last. It covers the canvas to take the pointer, so only one model can have it at a time."),this.mountDebugOverlay(this.stage,r)}applyFit(){let e=this.stage;if(!e)return;let t=e.getSize();for(let r of this.models)r.handle.setTransform(Fn(t,r.handle.getIntrinsicSize(),r.fit))}motion(e,t,r){return this.requireModel().motion(e,t,r)}async playMotion(e,t,r){let i=this.requireModel();if(!i.playMotion)throw new m("adapter-error","The selected Live2D backend does not support detailed motion playback.");return i.playMotion(e,t,r)}async sequence(e){let t=this.requireModel();if(!t.playMotion)throw new m("adapter-error","The selected Live2D backend does not support motion sequences.");return Pn(e,t.getModelInfo(),(r,i,s)=>t.playMotion(r,i,s))}isMotionPlaying(){return this.model?.isMotionPlaying()??!1}expression(e,t){return this.requireModel().expression(e,t)}clearExpression(){this.requireModel().clearExpression()}getModelInfo(){return this.requireModel().getModelInfo()}focus(e,t){this.requireModel().focus(e,t)}focusAt(e,t){let r=this.stage;if(!r||this.models.length===0)return;let i=r.toWorld(e,t);for(let s of this.models)s.handle.focus(i.x,i.y)}hitTest(e,t){let r=this.stage;if(!r)return[];let i=r.toWorld(e,t);for(let s=this.models.length-1;s>=0;s--){let n=this.models[s].handle.hitTest(i.x,i.y);if(n.length>0)return n}return[]}getParameter(e){return this.requireModel().getParameter(e)}setParameter(e,t){this.requireModel().setParameter(e,t)}clearParameter(e){this.requireModel().clearParameter(e)}setFit(e){this.fit=e,this.models[0]&&(this.models[0].fit=e),this.applyFit(),this.debugOverlay?.refresh()}async addModel(e){if(this.disposed)throw new m("invalid-props","The Live2D instance has been disposed.");if(!e||typeof e.src!="string"||e.src==="")throw new m("invalid-props","addModel requires a src.");await this.whenStageReady();let t=this.stage,r=this.backend;if(!t||!r)throw new m("invalid-props","The Live2D canvas is not ready. Await createLive2D() before adding a model.");let i=new AbortController,s=()=>i.abort(e.signal?.reason);e.signal?.addEventListener("abort",s,{once:!0});let n;try{n=await this.loadModel(r,t,e.src,i.signal,e)}finally{e.signal?.removeEventListener("abort",s)}if(this.disposed||this.stage!==t)throw n.dispose(),new m("invalid-props","The Live2D canvas went away while the model loaded.");let a={features:[],fit:e.fit??"upper-body",followPointer:e.followPointer??!1,handle:n,onFitChange:e.onFitChange};return this.models.push(a),this.applyFit(),this.createModelHandle(a)}whenStageReady(){return this.stage&&this.backend?Promise.resolve():this.state.status==="error"?Promise.reject(this.state.error??new m("adapter-error","The Live2D canvas failed to start.")):new Promise((e,t)=>{let r=this.subscribe(()=>{if(this.disposed){r(),t(new m("invalid-props","The Live2D instance has been disposed."));return}if(this.stage&&this.backend){r(),e();return}this.state.status==="error"&&(r(),t(this.state.error??new m("adapter-error","The Live2D canvas failed to start.")))})})}createModelHandle(e){let t=()=>{if(!this.models.includes(e))throw new m("invalid-props","This Live2D model has been disposed.");return e.handle};return Object.freeze({addLipSync:r=>this.addLipSync(r,e),addParameterDriver:(r,i)=>this.addParameterDriver(r,i,e),clearExpression:()=>t().clearExpression(),clearParameter:r=>t().clearParameter(r),dispose:()=>{let r=this.models.indexOf(e);if(!(r<0)){this.models.splice(r,1),this.debugWanted===e&&(this.debugWanted=void 0),this.releaseDebugOverlay(e);for(let i of e.features.splice(0))i.detach();e.handle.dispose()}},expression:(r,i)=>t().expression(r,i),focus:(r,i)=>t().focus(r,i),focusAt:(r,i)=>{let s=this.stage;if(!s)return;let n=s.toWorld(r,i);t().focus(n.x,n.y)},getFit:()=>typeof e.fit=="object"?{...e.fit}:e.fit,getModelInfo:()=>t().getModelInfo(),getParameter:r=>t().getParameter(r),hitTest:(r,i)=>{let s=this.stage;if(!s)return[];let n=s.toWorld(r,i);return t().hitTest(n.x,n.y)},isMotionPlaying:()=>t().isMotionPlaying(),motion:(r,i,s)=>t().motion(r,i,s),playMotion:async(r,i,s)=>{let n=t();if(!n.playMotion)throw new m("adapter-error","The selected Live2D backend does not support detailed motion playback.");return n.playMotion(r,i,s)},sequence:async r=>{let i=t();if(!i.playMotion)throw new m("adapter-error","The selected Live2D backend does not support motion sequences.");return Pn(r,i.getModelInfo(),(s,n,a)=>i.playMotion(s,n,a))},setDebug:r=>this.setDebug(r,e),setFit:r=>{e.fit=r,this.applyFit()},setParameter:(r,i)=>t().setParameter(r,i)})}getFit(){return typeof this.fit=="object"?{...this.fit}:this.fit}setAccessibility(e){kn(e),this.accessibility=e,this.stage?.setAccessibility?.(e)}addFeature(e,t){let r=t?.features??this.features;r.push(e);let i=t?.handle??this.model;return i&&e.attach(i),Ln(()=>{e.detach();let s=r.indexOf(e);s>=0&&r.splice(s,1)})}addParameterDriver(e,t,r){if(!t||typeof t.getValue!="function")throw new m("invalid-props","A parameter driver must provide getValue().");return this.addFeature(new Dn(i=>{let s=()=>{i.setParameter(e,t.getValue()),i.clearParameter(e)},n=(t.phase==="before-physics"&&i.onBeforePhysicsUpdate?i.onBeforePhysicsUpdate:i.onAfterMotionUpdate).call(i,s);return()=>{n(),i.clearParameter(e)}},i=>this.report(Je(i,"render-error"))),r)}addLipSync(e,t){let r=n=>{let a=Je(n,"lipsync-error");e.onError?.(a),!e.onError&&this.options.onError?this.options.onError?.(a):!e.onError&&!this.options.onError&&console.error("[live2d-web] lip sync disabled:",a)},i=e.parameterId??"ParamMouthOpenY",s=new Dn(async n=>{let a=new Pl,l="source"in e?await Xl(e.source,e.profile):void 0,o="driver"in e?e.driver:{getMouthOpen:l.getMouthOpen,isSpeaking:e.isSpeaking},u=!1,c=n.onAfterMotionUpdate(d=>{if(!u)try{let h=o.isSpeaking(),g=a.update({deltaMs:d,motionValue:n.getParameter(i),mouthOpen:h?o.getMouthOpen():0,speaking:h});g!==null&&(n.setParameter(i,g),n.clearParameter(i))}catch(h){u=!0,r(h)}});return()=>{c(),n.clearParameter(i),l?.dispose()}},r);return this.addFeature(s,t)}pause(){this.addPauseReason("user")}resume(){this.removePauseReason("user")}async retry(){if(this.disposed)throw new m("invalid-props","Cannot retry a disposed Live2D instance.");this.teardown(),await this.start()}dispose(){this.disposed||(this.disposed=!0,this.teardown(),this.features=[],this.updateState({error:void 0,loadingStage:void 0,render:void 0,status:"disposed"}),this.listeners.clear())}};async function Br(e){let t=new zl(e);try{return await t.start(),t}catch(r){throw t.dispose(),r}}async function Nh(e,t,r,i){if(i.throwIfAborted(),!(e instanceof HTMLCanvasElement))throw new Error("Missing Live2D canvas");let s=document.createElement("div");s.style.cssText="display:inline-block;position:relative;vertical-align:top;line-height:0";let n=document.createElement("div");n.style.cssText="position:absolute;inset:0;cursor:grab";let a=e.style.visibility;e.before(s),s.append(e,n),e.style.visibility="hidden";let l;function o(){l?.dispose(),s.contains(e)&&(s.replaceWith(e),e.style.visibility=a),i.removeEventListener("abort",o)}i.addEventListener("abort",o,{once:!0});try{l=await Br({container:n,src:t,coreUrl:r||br,fit:"full",followPointer:!0,signal:i,onError:h=>console.error("[Live2D]",h)}),i.throwIfAborted();let u=l,{motions:c,expressions:d}=u.getModelInfo();return n.addEventListener("click",h=>{let g=u.hitTest(h.clientX,h.clientY);for(let A of g){let p=Object.keys(c).find(_=>_.replace(/_/g,"").toLowerCase()==="tap"+A.toLowerCase()&&c[_]>0),f=p?u.motion(p,Math.floor(Math.random()*c[p])):A.toLowerCase()==="head"&&d.length?u.expression():void 0;if(f){f.catch(_=>{i.aborted||console.error("[Live2D]",_)});break}}}),{pause:()=>u.pause(),resume:()=>u.resume(),capture(){requestAnimationFrame(()=>{let h=n.querySelector("canvas");if(!h||i.aborted)return;let g=document.createElement("a");g.download="photo.png",g.href=h.toDataURL("image/png"),g.click()})}}}catch(u){throw o(),u}}export{Nh as mountModern};
813
+ Official SDK download: https://www.live2d.com/sdk/download/web/`}function El(){if(typeof window>"u"||typeof document>"u")throw new m("browser-only","live2d-web can only create a stage in a browser.")}function vl(e){return new Promise((t,r)=>{let i=document.createElement("script"),s=new AbortController,n,a=o=>{if(n!==void 0&&clearTimeout(n),n=void 0,s.abort(),!o){t();return}i.remove(),r(o)},l=o=>{if(o.type==="load"&&window.Live2DCubismCore){a();return}a(o.type==="load"?new m("core-missing",_r(),{details:je(e)}):new m("core-missing",`Failed to load Live2D Cubism Core from ${e}.`,{cause:o,details:je(e)}))};i.addEventListener("load",l,{signal:s.signal}),i.addEventListener("error",l,{signal:s.signal}),n=setTimeout(()=>{a(new m("core-missing",`Live2D Cubism Core did not load from ${e} within ${Mn} ms.`,{details:je(e)}))},Mn),i.src=e,i.async=!0,i.dataset.live2dWebCore="true",document.head.appendChild(i)})}function Pl(e,t){return new Promise((r,i)=>{let s=()=>i(t.reason);t.addEventListener("abort",s,{once:!0}),e.then(r,i).finally(()=>{t.removeEventListener("abort",s)})})}async function Tn(e,t={}){El();let{signal:r}=t;if(r?.aborted)throw r.reason;if(window.Live2DCubismCore)return;if(!e)throw new m("core-missing",_r(),{details:je()});let i=new URL(e,document.baseURI).href,s=yt.get(i);if(s||(s=vl(i).finally(()=>{yt.get(i)===s&&yt.delete(i)}),yt.set(i,s)),await(r?Pl(s,r):s),r?.aborted)throw r.reason;if(!window.Live2DCubismCore)throw new m("core-missing",_r(),{details:je(i)})}function mr(e){return Number.isFinite(e)&&e>0?e:1e-6}function Fn(e,t,r="upper-body"){let i=e.width/t.width,s=e.height/t.height;if(r==="full")return{scale:mr(Math.min(i,s)),x:e.width/2,y:e.height/2};let n=mr(Math.min(i*2,s*2));if(r==="upper-body")return{scale:n,x:e.width/2,y:e.height};let a=r.offsetX??0,l=r.offsetY??0,o=r.units==="stage";return{scale:mr(n*r.scale),x:e.width/2+(o?a*e.width:a),y:e.height+(o?l*e.height:l)}}var It={desktopMaxResolution:2,desktopPixelBudget:4e6,longFrameMs:33,longFrameRatioThreshold:.05,minResolution:1,mobileMaxResolution:1.5,mobilePixelBudget:15e5,resolutionStep:.25,sampleWindowMs:3e3};function pe(e,t){if(!Number.isFinite(e)||e<=0)throw new m("invalid-props",`${t} must be a finite number greater than 0.`);return e}function On(e){let t={...It,...e};if(pe(t.desktopMaxResolution,"quality.desktopMaxResolution"),pe(t.desktopPixelBudget,"quality.desktopPixelBudget"),pe(t.longFrameMs,"quality.longFrameMs"),pe(t.minResolution,"quality.minResolution"),pe(t.mobileMaxResolution,"quality.mobileMaxResolution"),pe(t.mobilePixelBudget,"quality.mobilePixelBudget"),pe(t.resolutionStep,"quality.resolutionStep"),pe(t.sampleWindowMs,"quality.sampleWindowMs"),!Number.isFinite(t.longFrameRatioThreshold)||t.longFrameRatioThreshold<0||t.longFrameRatioThreshold>1)throw new m("invalid-props","quality.longFrameRatioThreshold must be between 0 and 1.");if(t.mobileMaxResolution<t.minResolution||t.desktopMaxResolution<t.minResolution)throw new m("invalid-props","quality max resolutions must be greater than or equal to minResolution.");return t}function wn(e){return Number.isFinite(e)&&e>0?e:1}function Cr(e,t=It){let r=wn(e.width),i=wn(e.height),s=e.mobile?t.mobileMaxResolution:t.desktopMaxResolution,n=e.mobile?t.mobilePixelBudget:t.desktopPixelBudget,a=Number.isFinite(e.devicePixelRatio)&&e.devicePixelRatio>0?e.devicePixelRatio:t.minResolution,l=Math.sqrt(n/(r*i));return Math.max(t.minResolution,Math.min(a,s,l))}function Vn(e,t,r=It){return!Number.isFinite(e)||e<=r.minResolution?r.minResolution:!Number.isFinite(t)||t<=r.longFrameRatioThreshold?e:Math.max(r.minResolution,Math.round((e-r.resolutionStep)*100)/100)}function yr(e,t){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches||Math.min(e,t)<768}function Rl(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function Dl(e){return Number.isFinite(e)&&e>0?e:0}function xn(e){return Number.isFinite(e)?e:0}function Ll(e){return e*e*(3-2*e)}var Tl=class{holdRemainingMs=0;lastForcedValue=0;releaseRemainingMs=0;update(e){if(e.speaking)return this.lastForcedValue=Rl(e.mouthOpen),this.releaseRemainingMs=200,this.holdRemainingMs=500,this.lastForcedValue;let t=Dl(e.deltaMs);if(this.releaseRemainingMs>0){let r=Math.min(this.releaseRemainingMs,t);if(this.releaseRemainingMs-=r,t-=r,this.releaseRemainingMs>0){let i=Ll(1-this.releaseRemainingMs/200);return this.lastForcedValue*(1-i)+xn(e.motionValue)*i}if(t===0)return xn(e.motionValue)}return this.holdRemainingMs>0&&(this.holdRemainingMs=Math.max(0,this.holdRemainingMs-t),this.holdRemainingMs>0)?0:null}},Fl=[["A","A"],["E","E"],["I","I"],["O","O"],["U","U"],["S","I"]],Ol=.7,Vl=50,kl=50,Ql=.7,Ul=.9,bt=new Map,Bt;function En(e){let t=!0;return()=>{t&&(t=!1,e())}}function vn(e){return Number.isFinite(e)?Math.max(0,e):0}function Nl(){return typeof performance>"u"?Date.now():performance.now()}function Gl(){return Bt||(Bt=kr().then(()=>Vr).catch(e=>{throw Bt=void 0,e})),Bt}function Xl(e){if(e instanceof URL)return e.href;let t=typeof location>"u"?"http://localhost/":location.href;return new URL(e,t).href}function Hl(e,t,r){let i=Xl(e),s=bt.get(i);if(s)return s;let n=r(i).then(async a=>{if(!a.ok)throw new Error(`Failed to load the lip-sync profile (${a.status}).`);return new URL(i).pathname.toLowerCase().endsWith(".bin")?t.parseBinaryProfile(await a.arrayBuffer()):await a.json()});return bt.set(i,n),n.catch(()=>{bt.get(i)===n&&bt.delete(i)}),n}function Wl(e,t,r=fetch){return typeof e=="string"||e instanceof URL?Hl(e,t,r):e instanceof ArrayBuffer?Promise.resolve(t.parseBinaryProfile(e)):Promise.resolve(e)}function Yl(e,t=Nl){let r=0,i=NaN,s=0,n=NaN,a=()=>{let l=Math.min(vn(e.volume)*Ul,1)**Ql,o={A:0,E:0,I:0,O:0,U:0};for(let[u,h]of Fl){let d=Math.min(Ol,vn(e.weights?.[u]??0)*l);o[h]=Math.max(o[h],d)}return Math.max(...Object.values(o))};return()=>{let l=t();if((Number.isNaN(i)||l-i>=Vl)&&(r=a(),i=l),Number.isNaN(n))return s=r,n=l,s;let o=Math.max(0,l-n),u=Math.min(1,o/kl);return s+=(r-s)*u,n=l,s}}async function zl(e,t,r={}){if(typeof window<"u"&&window.isSecureContext===!1)throw new Error("wLipSync requires HTTPS or localhost because it uses AudioWorklet.");if(!e.context||!("audioWorklet"in e.context))throw new Error("The source AudioNode context does not support AudioWorklet.");let i=await(r.loadModule??Gl)(),s=r.fetcher??(typeof fetch>"u"?void 0:fetch.bind(globalThis));if((typeof t=="string"||t instanceof URL)&&!s)throw new Error("fetch is unavailable, so the lip-sync profile URL cannot be loaded.");let n=await Wl(t,i,s),a=await i.createWLipSyncNode(e.context,n),l=En(()=>{try{a.disconnect()}catch{}try{a.port.close()}catch{}});try{e.connect(a)}catch(u){throw l(),u}let o=Yl(a,r.now);return{dispose:En(()=>{try{e.disconnect(a)}catch{}l()}),getMouthOpen:o,node:a}}function Jl(e,t){if(!Array.isArray(e))throw new m("invalid-props","Motion sequence steps must be an array.");for(let r=0;r<e.length;r++){let i=e[r];if(typeof i!="object"||i===null||Array.isArray(i))throw new m("invalid-props",`Motion sequence step ${r} must be an object.`);if(typeof i.group!="string"||i.group.trim()==="")throw new m("invalid-props",`Motion sequence step ${r} needs a non-empty group.`);let s=t.motions[i.group];if(!Number.isInteger(s)||s<=0)throw new m("invalid-props",`Unknown Live2D motion group in sequence step ${r}: ${i.group}.`);if(i.index!==void 0&&(!Number.isInteger(i.index)||i.index<0||i.index>=s))throw new m("invalid-props",`Motion index ${i.index} is outside group ${i.group} in sequence step ${r}.`);Ue(i.options)}}async function Pn(e,t,r){Jl(e,t);for(let i=0;i<e.length;i++){let s=e[i],n=await r(s.group,s.index,s.options);if(n.status!=="completed")return{completedSteps:i,status:n.status,stepIndex:i}}return{completedSteps:e.length,status:"completed"}}function Rn(e){let t=!0;return()=>{t&&(t=!1,e())}}var Dn=class{setup;report;cleanup;generation=0;constructor(e,t){this.setup=e,this.report=t}attach(e){this.detach();let t=this.generation;try{let r=this.setup(e);r instanceof Promise?r.then(i=>{if(t!==this.generation){i();return}this.cleanup=Rn(i)}).catch(i=>{t===this.generation&&this.report(i)}):this.cleanup=Rn(r)}catch(r){this.report(r)}}detach(){this.generation++,this.cleanup?.(),this.cleanup=void 0}};function Ln(e){let t=!0;return()=>{t&&(t=!1,e())}}function Je(e,t){return e instanceof m?e:new m(t,e instanceof Error?e.message:String(e),{cause:e})}function kn(e){if(e!==void 0){if(!e||typeof e!="object")throw new m("invalid-props","accessibility must be a decorative or image accessibility object.");if(e.mode!=="decorative"&&e.mode!=="image"&&e.mode!==void 0)throw new m("invalid-props",'accessibility.mode must be "decorative" or "image".');if(e.mode!=="decorative"){if(typeof e.label!="string"||e.label.trim()==="")throw new m("invalid-props","image accessibility requires a non-empty label.");for(let[t,r]of[["describedBy",e.describedBy],["fallbackText",e.fallbackText]])if(r!==void 0&&typeof r!="string")throw new m("invalid-props",`accessibility.${t} must be a string when provided.`)}}}function jl(e){if(typeof window>"u"||typeof document>"u"||typeof HTMLElement>"u")throw new m("browser-only","Live2D can only be created in a browser.");if(!(e.container instanceof HTMLElement))throw new m("invalid-props","container must be an HTMLElement.");if(kn(e.accessibility),e.src!==void 0&&(typeof e.src!="string"||e.src.trim()===""))throw new m("invalid-props","src must be a non-empty model3.json path or URL string.");if(e.resolveAsset!==void 0&&typeof e.resolveAsset!="function")throw new m("invalid-props","resolveAsset must be a function.");if(e.quality!==void 0&&e.resolution!==void 0)throw new m("invalid-props","quality and resolution are mutually exclusive.");if(!Number.isInteger(e.retries??2)||(e.retries??2)<0)throw new m("invalid-props","retries must be a non-negative integer.");if("resolution"in e&&e.resolution!==void 0&&(!Number.isFinite(e.resolution)||e.resolution<1))throw new m("invalid-props","resolution must be a finite number greater than or equal to 1.");if(e.maxFps!==void 0&&(!Number.isFinite(e.maxFps)||e.maxFps<=0))throw new m("invalid-props","maxFps must be a finite number greater than 0.");if(e.pauseWhenOffscreen!==void 0&&typeof e.pauseWhenOffscreen!="boolean")throw new m("invalid-props","pauseWhenOffscreen must be a boolean.");if(e.followPointer!==void 0&&typeof e.followPointer!="boolean")throw new m("invalid-props","followPointer must be a boolean.");if(e.debug!==void 0&&typeof e.debug!="boolean")throw new m("invalid-props","debug must be a boolean.");Mt(e.idleMotion)}function Zl(e,t){return new Promise((r,i)=>{if(t.aborted){i(t.reason);return}let s,n=()=>{clearTimeout(s),i(t.reason)};s=setTimeout(()=>{t.removeEventListener("abort",n),r()},e),t.addEventListener("abort",n,{once:!0})})}var ql=class{options;abortController;disposed=!1;features=[];accessibility;fit;debug;debugOverlay;debugWanted;intersectionObserver;listeners=new Set;models=[];backend;onStageResume;pauseReasons=new Set;resizeAnimationFrame=0;resizeObserver;stage;stageCleanup=[];state={loadingStage:"core",status:"loading"};constructor(e){this.options=e,this.fit=e.fit??"upper-body",this.debug=e.debug??!1,this.accessibility=e.accessibility}get model(){return this.models[0]?.handle}getState=()=>this.state;getModelHandle=()=>this.model??null;subscribe=e=>(this.listeners.add(e),Ln(()=>this.listeners.delete(e)));updateState(e){this.state={...this.state,...e};for(let t of this.listeners)t()}report(e){this.disposed||(this.updateState({error:e,loadingStage:void 0,status:"error"}),this.options.onError?.(e))}readRenderState(e){let t=e.getSize(),r=e.getResolution();return{bufferPixels:Math.round(t.width*t.height*r**2),height:t.height,resolution:r,width:t.width}}async resolveBackend(){if(this.options.backend)return this.options.backend;let{cubismWebGL:e}=await Promise.resolve().then(()=>(mn(),pn));return e}addPauseReason(e){if(this.pauseReasons.has(e))return;let t=this.pauseReasons.size===0;this.pauseReasons.add(e),t&&this.stage?.pause()}removePauseReason(e){!this.pauseReasons.delete(e)||this.pauseReasons.size>0||(this.onStageResume?.(),this.stage?.resume())}teardown(){this.abortController?.abort(),this.abortController=void 0,cancelAnimationFrame(this.resizeAnimationFrame),this.resizeAnimationFrame=0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.onStageResume=void 0,this.resizeObserver?.disconnect(),this.resizeObserver=void 0;for(let e of this.stageCleanup.splice(0).reverse())e();for(let e of[...this.features].reverse())e.detach();for(let e of this.models){this.releaseDebugOverlay(e);for(let t of e.features.splice(0).reverse())t.detach();e.handle.dispose()}this.models=[],this.stage?.dispose(),this.stage=void 0}async start(){if(this.disposed)throw new m("invalid-props","Cannot start a disposed Live2D instance.");jl(this.options),this.pauseReasons.delete("hidden"),this.pauseReasons.delete("offscreen");let e=this.options.resolution!==void 0?void 0:On(typeof this.options.quality=="object"?this.options.quality:void 0),t=new AbortController;this.abortController=t;let r=()=>t.abort(this.options.signal?.reason);this.options.signal?.aborted&&r(),this.options.signal?.addEventListener("abort",r,{once:!0}),this.stageCleanup.push(()=>{this.options.signal?.removeEventListener("abort",r)});try{if(this.updateState({error:void 0,loadingStage:"core",status:"loading"}),await Tn(this.options.coreUrl,{signal:t.signal}),t.signal.aborted)throw t.signal.reason;let i=this.backend??await this.resolveBackend();if(this.backend=i,t.signal.aborted)throw t.signal.reason;this.updateState({loadingStage:"stage"});let s=this.options.container.getBoundingClientRect();(s.width<1||s.height<1)&&console.warn("[live2d-web] The container has zero size, so the canvas will be 1x1 and nothing will be visible. Give the container a CSS width and height.");let n=Math.max(1,s.width),a=Math.max(1,s.height),l=this.options.resolution!==void 0?this.options.resolution:Cr({devicePixelRatio:window.devicePixelRatio,height:a,mobile:yr(n,a),width:n},e),o=i.createStage(this.options.container,{accessibility:this.accessibility,height:a,maxFps:this.options.maxFps,resolution:l,width:n});this.stage=o,this.pauseReasons.size>0&&o.pause(),this.stageCleanup.push(o.onError(p=>{this.report(Je(p,"render-error"))}));let u=0,h=0,d=0;e&&this.stageCleanup.push(o.onFrame(p=>{if(u+=p,h++,p>e.longFrameMs&&d++,u<e.sampleWindowMs)return;let f=Vn(o.getResolution(),h?d/h:0,e);f<o.getResolution()&&(o.setResolution(f),this.updateState({render:this.readRenderState(o)})),u=0,h=0,d=0}));let c=()=>{if(this.resizeAnimationFrame=0,this.disposed||this.stage!==o)return;let p=this.options.container.getBoundingClientRect(),f=Math.max(1,p.width),_=Math.max(1,p.height);if(!(Math.abs(f-n)<.5&&Math.abs(_-a)<.5)){if(n=f,a=_,e){let y=Cr({devicePixelRatio:window.devicePixelRatio,height:a,mobile:yr(n,a),width:n},e);y<o.getResolution()&&o.setResolution(y)}o.resize(n,a),this.applyFit(),this.updateState({render:this.readRenderState(o)})}},g=()=>{this.resizeAnimationFrame||(this.resizeAnimationFrame=requestAnimationFrame(c))};this.resizeObserver=typeof ResizeObserver>"u"?void 0:new ResizeObserver(g),this.resizeObserver?.observe(this.options.container),this.onStageResume=()=>{u=0,h=0,d=0,g()};let A=()=>{document.hidden?this.addPauseReason("hidden"):this.removePauseReason("hidden")};if(document.addEventListener("visibilitychange",A),A(),this.stageCleanup.push(()=>{document.removeEventListener("visibilitychange",A)}),this.intersectionObserver=(this.options.pauseWhenOffscreen??!0)&&typeof IntersectionObserver<"u"?new IntersectionObserver(p=>{let f=p[p.length-1];f&&(f.isIntersecting?this.removePauseReason("offscreen"):this.addPauseReason("offscreen"))}):void 0,this.intersectionObserver?.observe(this.options.container),this.updateState({loadingStage:"model",render:this.readRenderState(o)}),this.options.src!==void 0){let p=await this.loadModel(i,o,this.options.src,t.signal);if(t.signal.aborted||this.stage!==o)throw p.dispose(),t.signal.reason;this.models.push({features:[],fit:this.fit,followPointer:this.options.followPointer??!1,handle:p}),this.applyFit();for(let f of this.features)f.attach(p)}{let p=this.options.container,f=y=>{if(this.stage!==o)return;let C=o.toWorld(y.clientX,y.clientY);for(let b of this.models)b.followPointer&&b.handle.focus(C.x,C.y)},_=()=>{if(this.stage!==o)return;let y=o.getSize();for(let C of this.models)C.followPointer&&C.handle.focus(y.width/2,y.height/2)};p.addEventListener("pointermove",f),p.addEventListener("pointerleave",_),this.stageCleanup.push(()=>{p.removeEventListener("pointermove",f),p.removeEventListener("pointerleave",_)})}this.debug&&this.models[0]&&await this.mountDebugOverlay(o,this.models[0]),this.updateState({error:void 0,loadingStage:void 0,render:this.readRenderState(o),status:"ready"})}catch(i){if(t.signal.aborted){if(this.disposed)return;throw i}let s=Je(i,"adapter-error");throw this.teardown(),this.report(s),s}}async loadModel(e,t,r,i,s){let n=s?.retries??this.options.retries??2,a;for(let l=0;l<=n;l++)try{return await e.loadModel(t,r,{idleMotion:s?.idleMotion??this.options.idleMotion,resolveAsset:s?.resolveAsset??this.options.resolveAsset,signal:i})}catch(o){if(i.aborted)throw o;a=Je(o,"model-load-failed");let u=a.details?.httpStatus;if(a.code==="invalid-props"||u!==void 0&&u>=400&&u<500||l===n)break;await Zl(l===0?250:500,i)}throw a||new m("model-load-failed","The model could not be loaded.")}requireModel(){if(this.disposed)throw new m("invalid-props","The Live2D instance has been disposed.");if(!this.model)throw new m("model-load-failed","The Live2D model is not ready.");return this.model}async mountDebugOverlay(e,t){let{mountLive2DDebugOverlay:r}=await Promise.resolve().then(()=>(Sn(),In));if(this.disposed||this.stage!==e||!this.models.includes(t)||this.debugWanted!==t||this.debugOverlay?.owner===t)return;this.releaseDebugOverlay();let i=r({container:this.options.container,onChange:s=>(t.onFitChange??this.options.onFitChange)?.(s),target:{getFit:()=>typeof t.fit=="object"?{...t.fit}:t.fit,setFit:s=>{t.fit=s,this.applyFit()}}});this.debugOverlay={dispose:i.dispose,owner:t,refresh:i.refresh},this.stageCleanup.push(()=>this.releaseDebugOverlay(t))}releaseDebugOverlay(e){let t=this.debugOverlay;!t||e!==void 0&&t.owner!==e||(this.debugOverlay=void 0,t.dispose())}setDebug(e,t){if(typeof e!="boolean")throw new m("invalid-props","debug must be a boolean.");let r=t??this.models[0];if(!e){this.debugWanted===r&&(this.debugWanted=void 0),this.releaseDebugOverlay(r),t||(this.debug=!1);return}if(t||(this.debug=!0),!this.stage||!r)return;let i=this.debugWanted;this.debugWanted=r,i&&i!==r&&console.warn("[live2d-web] The placement overlay moved to the model that asked for it last. It covers the canvas to take the pointer, so only one model can have it at a time."),this.mountDebugOverlay(this.stage,r)}applyFit(){let e=this.stage;if(!e)return;let t=e.getSize();for(let r of this.models)r.handle.setTransform(Fn(t,r.handle.getIntrinsicSize(),r.fit))}motion(e,t,r){return this.requireModel().motion(e,t,r)}async playMotion(e,t,r){let i=this.requireModel();if(!i.playMotion)throw new m("adapter-error","The selected Live2D backend does not support detailed motion playback.");return i.playMotion(e,t,r)}async sequence(e){let t=this.requireModel();if(!t.playMotion)throw new m("adapter-error","The selected Live2D backend does not support motion sequences.");return Pn(e,t.getModelInfo(),(r,i,s)=>t.playMotion(r,i,s))}isMotionPlaying(){return this.model?.isMotionPlaying()??!1}expression(e,t){return this.requireModel().expression(e,t)}clearExpression(){this.requireModel().clearExpression()}getModelInfo(){return this.requireModel().getModelInfo()}focus(e,t){this.requireModel().focus(e,t)}focusAt(e,t){let r=this.stage;if(!r||this.models.length===0)return;let i=r.toWorld(e,t);for(let s of this.models)s.handle.focus(i.x,i.y)}hitTest(e,t){let r=this.stage;if(!r)return[];let i=r.toWorld(e,t);for(let s=this.models.length-1;s>=0;s--){let n=this.models[s].handle.hitTest(i.x,i.y);if(n.length>0)return n}return[]}getParameter(e){return this.requireModel().getParameter(e)}setParameter(e,t){this.requireModel().setParameter(e,t)}clearParameter(e){this.requireModel().clearParameter(e)}setFit(e){this.fit=e,this.models[0]&&(this.models[0].fit=e),this.applyFit(),this.debugOverlay?.refresh()}async addModel(e){if(this.disposed)throw new m("invalid-props","The Live2D instance has been disposed.");if(!e||typeof e.src!="string"||e.src==="")throw new m("invalid-props","addModel requires a src.");await this.whenStageReady();let t=this.stage,r=this.backend;if(!t||!r)throw new m("invalid-props","The Live2D canvas is not ready. Await createLive2D() before adding a model.");let i=new AbortController,s=()=>i.abort(e.signal?.reason);e.signal?.addEventListener("abort",s,{once:!0});let n;try{n=await this.loadModel(r,t,e.src,i.signal,e)}finally{e.signal?.removeEventListener("abort",s)}if(this.disposed||this.stage!==t)throw n.dispose(),new m("invalid-props","The Live2D canvas went away while the model loaded.");let a={features:[],fit:e.fit??"upper-body",followPointer:e.followPointer??!1,handle:n,onFitChange:e.onFitChange};return this.models.push(a),this.applyFit(),this.createModelHandle(a)}whenStageReady(){return this.stage&&this.backend?Promise.resolve():this.state.status==="error"?Promise.reject(this.state.error??new m("adapter-error","The Live2D canvas failed to start.")):new Promise((e,t)=>{let r=this.subscribe(()=>{if(this.disposed){r(),t(new m("invalid-props","The Live2D instance has been disposed."));return}if(this.stage&&this.backend){r(),e();return}this.state.status==="error"&&(r(),t(this.state.error??new m("adapter-error","The Live2D canvas failed to start.")))})})}createModelHandle(e){let t=()=>{if(!this.models.includes(e))throw new m("invalid-props","This Live2D model has been disposed.");return e.handle};return Object.freeze({addLipSync:r=>this.addLipSync(r,e),addParameterDriver:(r,i)=>this.addParameterDriver(r,i,e),clearExpression:()=>t().clearExpression(),clearParameter:r=>t().clearParameter(r),dispose:()=>{let r=this.models.indexOf(e);if(!(r<0)){this.models.splice(r,1),this.debugWanted===e&&(this.debugWanted=void 0),this.releaseDebugOverlay(e);for(let i of e.features.splice(0))i.detach();e.handle.dispose()}},expression:(r,i)=>t().expression(r,i),focus:(r,i)=>t().focus(r,i),focusAt:(r,i)=>{let s=this.stage;if(!s)return;let n=s.toWorld(r,i);t().focus(n.x,n.y)},getFit:()=>typeof e.fit=="object"?{...e.fit}:e.fit,getModelInfo:()=>t().getModelInfo(),getParameter:r=>t().getParameter(r),hitTest:(r,i)=>{let s=this.stage;if(!s)return[];let n=s.toWorld(r,i);return t().hitTest(n.x,n.y)},isMotionPlaying:()=>t().isMotionPlaying(),motion:(r,i,s)=>t().motion(r,i,s),playMotion:async(r,i,s)=>{let n=t();if(!n.playMotion)throw new m("adapter-error","The selected Live2D backend does not support detailed motion playback.");return n.playMotion(r,i,s)},sequence:async r=>{let i=t();if(!i.playMotion)throw new m("adapter-error","The selected Live2D backend does not support motion sequences.");return Pn(r,i.getModelInfo(),(s,n,a)=>i.playMotion(s,n,a))},setDebug:r=>this.setDebug(r,e),setFit:r=>{e.fit=r,this.applyFit()},setParameter:(r,i)=>t().setParameter(r,i)})}getFit(){return typeof this.fit=="object"?{...this.fit}:this.fit}setAccessibility(e){kn(e),this.accessibility=e,this.stage?.setAccessibility?.(e)}addFeature(e,t){let r=t?.features??this.features;r.push(e);let i=t?.handle??this.model;return i&&e.attach(i),Ln(()=>{e.detach();let s=r.indexOf(e);s>=0&&r.splice(s,1)})}addParameterDriver(e,t,r){if(!t||typeof t.getValue!="function")throw new m("invalid-props","A parameter driver must provide getValue().");return this.addFeature(new Dn(i=>{let s=()=>{i.setParameter(e,t.getValue()),i.clearParameter(e)},n=(t.phase==="before-physics"&&i.onBeforePhysicsUpdate?i.onBeforePhysicsUpdate:i.onAfterMotionUpdate).call(i,s);return()=>{n(),i.clearParameter(e)}},i=>this.report(Je(i,"render-error"))),r)}addLipSync(e,t){let r=n=>{let a=Je(n,"lipsync-error");e.onError?.(a),!e.onError&&this.options.onError?this.options.onError?.(a):!e.onError&&!this.options.onError&&console.error("[live2d-web] lip sync disabled:",a)},i=e.parameterId??"ParamMouthOpenY",s=new Dn(async n=>{let a=new Tl,l="source"in e?await zl(e.source,e.profile):void 0,o="driver"in e?e.driver:{getMouthOpen:l.getMouthOpen,isSpeaking:e.isSpeaking},u=!1,h=n.onAfterMotionUpdate(d=>{if(!u)try{let c=o.isSpeaking(),g=a.update({deltaMs:d,motionValue:n.getParameter(i),mouthOpen:c?o.getMouthOpen():0,speaking:c});g!==null&&(n.setParameter(i,g),n.clearParameter(i))}catch(c){u=!0,r(c)}});return()=>{h(),n.clearParameter(i),l?.dispose()}},r);return this.addFeature(s,t)}pause(){this.addPauseReason("user")}resume(){this.removePauseReason("user")}async retry(){if(this.disposed)throw new m("invalid-props","Cannot retry a disposed Live2D instance.");this.teardown(),await this.start()}dispose(){this.disposed||(this.disposed=!0,this.teardown(),this.features=[],this.updateState({error:void 0,loadingStage:void 0,render:void 0,status:"disposed"}),this.listeners.clear())}};async function Br(e){let t=new ql(e);try{return await t.start(),t}catch(r){throw t.dispose(),r}}function Qn(e,t){let r=0,i=0;for(let{Segments:s}of e.Curves){if(s.length<2)throw new Error("Missing motion curve starting point");s.length===2&&s.push(0,e.Meta.Duration,s[1]),r++;for(let n=2;n<s.length;){let a=s[n];if(![0,1,2,3].includes(a))throw new Error("Invalid motion segment type: "+a);let l=a===1?3:1;if(n+=1+2*l,n>s.length)throw new Error("Incomplete motion curve");r+=l,i++}}return e.Meta.CurveCount=e.Curves.length,e.Meta.TotalSegmentCount=i,e.Meta.TotalPointCount=r,t&&(e.Meta.Loop=!1),e}async function Un(e,t){let r=await fetch(e,{signal:t});if(!r.ok)throw new Error("HTTP "+r.status+" loading "+e);return r.json()}async function Nn(e,t,r){let[i,s]=await Promise.all([Un(e,r),t&&Un(t.url,r).catch(u=>{if(r.aborted)throw u;console.warn("[Live2D] Dialogue data unavailable",u)})]),n=[];for(let[u,h]of Object.entries(i.FileReferences.Motions??{}))h.forEach((d,c)=>{if(s&&t)for(let[g,A]of Object.entries(s.motionData)){if(A.motion_name.replace(/\.mtn$/i,".motion3.json")!==d.File||!!A.is_hurt!=(s.variant==="destroy")||!A.touch_area||A.touch_area==="0")continue;let p=s.voiceData[g],f=p?.char_code?.toUpperCase(),_=p?.voice_key?.toUpperCase();n.push({file:d.File,group:u,index:c,area:A.touch_area.toLowerCase(),weight:A.probability,delay:Math.max(0,A.delay||0),caption:p?.caption,sound:f&&_?t.audio.get("AUDIO/"+f+"/"+f+"_"+_+"_JP.OGG"):void 0})}else/^tap_?/i.test(u)&&n.push({file:d.File,group:u,index:c,area:u.replace(/^tap_?/i,"").toLowerCase(),weight:1,delay:0,sound:d.Sound?new URL(d.Sound,e).href:void 0})});let a=decodeURIComponent(new URL(e).pathname.slice(1)),l=new Set(t?n.map(u=>new URL(u.file,e).href):[]);async function o(u,h){if(u===a)return new Blob([JSON.stringify(i)],{type:"application/json"});let d=new URL("/"+u.split("/").map(encodeURIComponent).join("/"),e),c=await fetch(d,{signal:h??r});if(!c.ok)throw new Error("HTTP "+c.status+" loading "+d);if(!d.pathname.toLowerCase().endsWith(".motion3.json"))return c.blob();let g=Qn(await c.json(),l.has(d.href));return new Blob([JSON.stringify(g)],{type:"application/json"})}return{actions:n,src:a,resolveAsset:o}}function Gn(e,t,r,i){let s;function n(){s?.abort(),s=void 0}i.addEventListener("abort",n,{once:!0});async function a(l){n();let o=s=new AbortController,u=l.sound?new Audio(l.sound):void 0,h={},d=!1;function c(p){d&&(d=!1,window.dispatchEvent(new CustomEvent("live2d:dialogue-end",{detail:{playback:h,interrupted:p}})))}o.signal.addEventListener("abort",()=>{u?.pause(),c(!0)},{once:!0});let g=t.playMotion(l.group,l.index).then(p=>{p.status!=="completed"&&o.abort()}),A=async()=>{if(l.delay&&await new Promise(p=>{let f=setTimeout(p,l.delay);o.signal.addEventListener("abort",()=>{clearTimeout(f),p()},{once:!0})}),!o.signal.aborted&&(l.caption&&(d=!0,window.dispatchEvent(Object.assign(new CustomEvent("live2d:dialogue",{detail:l.caption}),{playback:h}))),u)){let p=new Promise(f=>{u.addEventListener("ended",()=>f(),{once:!0}),u.addEventListener("error",()=>f(),{once:!0}),o.signal.addEventListener("abort",()=>f(),{once:!0})});try{await u.play(),await p}catch{}}};try{await Promise.all([g,A()]),c(!1)}finally{o.abort(),s===o&&(s=void 0)}}return e.addEventListener("click",l=>{let o=t.hitTest(l.clientX,l.clientY);for(let u of o){let h=r.filter(d=>d.area===u.toLowerCase()&&d.weight>0);if(h.length){let d=Math.random()*h.reduce((g,A)=>g+A.weight,0),c=h.find(g=>(d-=g.weight)<0)??h[h.length-1];a(c).catch(g=>{i.aborted||console.error("[Live2D]",g)});break}if(u.toLowerCase()==="head"&&t.getModelInfo().expressions.length){t.expression().catch(d=>{i.aborted||console.error("[Live2D]",d)});break}}},{signal:i}),document.addEventListener("visibilitychange",()=>{document.hidden&&n()},{signal:i}),n}async function jh(e,t,r,i,s){if(i.throwIfAborted(),!(e instanceof HTMLCanvasElement))throw new Error("Missing Live2D canvas");let n=document.createElement("div");n.style.cssText="display:inline-block;position:relative;vertical-align:top;line-height:0";let a=document.createElement("div");a.style.cssText="position:absolute;inset:0;cursor:grab";let l=e.style.visibility;e.before(n),n.append(e,a),e.style.visibility="hidden";let o;function u(){o?.dispose(),n.contains(e)&&(n.replaceWith(e),e.style.visibility=l),i.removeEventListener("abort",u)}i.addEventListener("abort",u,{once:!0});try{let{actions:h,src:d,resolveAsset:c}=await Nn(t,s,i);i.throwIfAborted(),o=await Br({container:a,src:d,resolveAsset:c,coreUrl:r||br,fit:"full",followPointer:!0,signal:i,onError:p=>console.error("[Live2D]",p)}),i.throwIfAborted();let g=o,A=Gn(a,g,h,i);return{pause:()=>{A(),g.pause()},resume:()=>g.resume(),capture(){requestAnimationFrame(()=>{let p=a.querySelector("canvas");if(!p||i.aborted)return;let f=document.createElement("a");f.download="photo.png",f.href=p.toDataURL("image/png"),f.click()})}}}catch(h){throw u(),h}}export{jh as mountModern};