@streamoji/aitwin 0.1.7 → 0.1.8
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";function Y(e,t,n){return{width:e.crop?.source_width??t,height:e.crop?.source_height??n}}function Z(e,t){const n=e.crop;return{x:t?.source_x??n?.x??0,y:t?.source_y??n?.y??0,width:t?.source_w??n?.width??e.frame_width??0,height:t?.source_h??n?.height??e.frame_height??0}}function V(e){return e?(e.w??0)>0&&(e.h??0)>0:!1}function tt(e){const t=e.trim();if(t.length%2!==0)throw new Error("Invalid hex key");const n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=Number.parseInt(t.slice(r,r+2),16);return n}function b(e){return Uint8Array.from(e)}function et(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}async function nt(e,t){if(!t)throw new Error("Asset key is required for encrypted assets");if(e.byteLength<28)throw new Error("Encrypted payload too small");const n=new Uint8Array(e),r=b(n.subarray(0,12)),s=b(n.subarray(12,28)),a=b(n.subarray(28)),o=b(et(a,s)),c=await crypto.subtle.importKey("raw",tt(t),{name:"AES-GCM"},!1,["decrypt"]);return crypto.subtle.decrypt({name:"AES-GCM",iv:r,tagLength:128},c,o)}async function O(e,t){const n=await fetch(e);if(!n.ok)throw new Error(`Failed to load encrypted asset: ${e}`);const r=await n.arrayBuffer();return nt(r,t)}async function rt(e,t){if(!t)throw new Error("Missing asset key for encrypted JSON");const n=await O(e,t),r=new TextDecoder().decode(n);return JSON.parse(r)}async function st(e){const t=new Blob([e],{type:"image/webp"});return createImageBitmap(t)}async function at(e){const t=new Blob([e],{type:"image/png"});return createImageBitmap(t)}const y=15,C=["t01_0.17","t02_0.33","t03_0.50","t04_0.67","t05_0.83"],ot=C.length,U=new Set(["aa__kk","aa__nn","aa__sil","CH__aa","CH__DD","CH__E","CH__FF","CH__I","CH__kk","CH__nn","CH__O","CH__PP","CH__RR","CH__sil","CH__SS","CH__TH","CH__U","DD__aa","DD__E","DD__FF","DD__I","DD__kk","DD__nn","DD__O","DD__PP","DD__RR","DD__sil","DD__SS","DD__TH","DD__U","E__aa","E__FF","E__I","E__kk","E__nn","E__O","E__PP","E__RR","E__sil","E__SS","E__TH","E__U","FF__aa","FF__I","FF__kk","FF__nn","FF__O","FF__PP","FF__RR","FF__sil","FF__SS","FF__TH","FF__U","I__aa","I__kk","I__nn","I__O","I__PP","I__RR","I__sil","I__SS","I__TH","I__U","kk__nn","kk__sil","nn__sil","O__aa","O__kk","O__nn","O__PP","O__RR","O__sil","O__SS","O__TH","O__U","PP__aa","PP__kk","PP__nn","PP__RR","PP__sil","PP__SS","PP__TH","PP__U","RR__aa","RR__kk","RR__nn","RR__sil","RR__SS","RR__TH","RR__U","SS__aa","SS__kk","SS__nn","SS__sil","SS__TH","SS__U","TH__aa","TH__kk","TH__nn","TH__sil","TH__U","U__aa","U__kk","U__nn","U__sil"]);function v(e,t){return`${e}__${t}`}function N(e,t){return`pairs/${e}/${t}_minus_sil.png`}function L(e){return`${e}_minus_sil.png`}function it(e,t){if(e===t)return[];const n=[],r=v(e,t);if(U.has(r)){for(const a of C)n.push(N(r,a));return n}const s=v(t,e);if(U.has(s)){for(let a=ot-1;a>=0;a--)n.push(N(s,C[a]));return n}return[]}function ct(e){return e<16?[]:e<35?[2]:e<51?[0,4]:e<67?[0,2,4]:e<83?[0,1,2,3]:[0,1,2,3,4]}function _t(e,t){return ct(t).map(r=>e[r]).filter(r=>r!=null)}function lt(e,t,n){if(!n)return`${e}/${t}`;const r=t.split("/").pop()??t,s=r.includes(".")?r.slice(0,r.lastIndexOf(".")):r;return`${e}/${s}.bin`}function ft(e,t,n,r,s=y){const a=new OffscreenCanvas(n,r),o=a.getContext("2d",{willReadFrequently:!0});o.drawImage(e,0,0,n,r);const c=o.getImageData(0,0,n,r),i=o.createImageData(n,r);i.data.set(c.data);const f=new OffscreenCanvas(n,r).getContext("2d",{willReadFrequently:!0});for(const p of t){f.clearRect(0,0,n,r),f.drawImage(p,0,0,n,r);const u=f.getImageData(0,0,n,r);for(let l=0;l<i.data.length;l+=4){const M=u.data[l],Q=u.data[l+1],X=u.data[l+2];Math.max(M,Q,X)>s&&(i.data[l]=M,i.data[l+1]=Q,i.data[l+2]=X,i.data[l+3]=255)}}return o.putImageData(i,0,0),a}const W=-1;function ut(e){return e<0}let g=0,z=Promise.resolve(),m=!1;function x(e){const t=z.then(e);return z=t.then(()=>{},()=>{}),t}function D(e,t){const n=t>0?-t:W,r={type:"renderDone",requestId:e,generation:n};self.postMessage(r)}async function dt(e){const t=typeof e.liveSeq=="number"?e.liveSeq:0;if(m){D(e.requestId,t);return}if(t>0&&(g=t),!d)throw new Error("Worker not initialized");if(t>0&&t!==g){D(e.requestId,t);return}if(await S(h??void 0),t>0&&t!==g){D(e.requestId,t);return}if(await j(d,e.diffPath,e.expressionDiffPath??null,e.threshold??y),t>0&&t!==g){D(e.requestId,t);return}const n=t>0?-t:W;await T(n),D(e.requestId,t)}let d=null,I=null,h=null,$=null,F="sil";const k=new Map;function E(){if(!$)throw new Error("Worker assets not configured");return $}function K(){const e=E();return e.encrypted?`${e.binBase}/sil.bin`:`${e.twinBase}/sil.png`}function wt(){const e=E();return e.encrypted?`${e.binBase}/atlas.bin`:`${e.twinBase}/atlas.json`}function ht(){const e=E();return e.encrypted?`${e.binBase}/expression_atlas.bin`:`${e.twinBase}/expression_atlas.json`}function pt(){const e=E();return e.encrypted?e.binBase:e.twinBase}function R(){return E().encrypted}async function B(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to load image: ${e}`);const n=await t.blob();return createImageBitmap(n)}async function yt(e){return R()?at(await O(K(),e??"")):B(K())}async function J(e,t,n){const r=R(),s=r?await rt(e,n):await fetch(e).then(_=>{if(!_.ok)throw new Error(`Failed to load ${e}`);return _.json()}),a=s.sheets?.[0];if(!a?.path)throw new Error(`${e} has no sheets[0].path`);const o=r?await st(await O(lt(t,a.path,r),n??"")):await B(`${t}/${a.path}`),c=new Map;for(const _ of s.cells??[])_.path&&c.set(_.path,_);const i=new Map;for(const _ of s.sheets??[])i.set(_.index,_);return{atlas:o,atlasMeta:s,cellByPath:c,sheetByIndex:i,diffBase:t}}async function S(e){if(R()&&!e)throw new Error("Encrypted assets enabled but no key provided");if(I&&(!R()||h===(e??null)))return I;h=e??null,k.clear();const t=pt();return I=(async()=>{const n=await yt(e),r=await J(wt(),t,e);let s=null;try{s=await J(ht(),t,e)}catch{s=null}return{sil:n,viseme:r,expression:s}})(),I}function A(e){return Y(e.viseme.atlasMeta,e.sil.width,e.sil.height)}function gt(e,t){if(!e.sheetByIndex.get(t.sheet??0))throw new Error(`Unknown sheet index: ${t.sheet}`);const r=new OffscreenCanvas(t.w,t.h);return r.getContext("2d",{willReadFrequently:!0}).drawImage(e.atlas,t.x,t.y,t.w,t.h,0,0,t.w,t.h),r}async function mt(e){return createImageBitmap(e)}async function G(e,t,n){const r=`${t.diffBase}::${n}`,s=k.get(r);if(s)return s;const a=(async()=>{const o=t.cellByPath.get(n);if(!o)throw new Error(`No atlas cell for path: ${n}`);const c=Z(t.atlasMeta,o),i=A(e);if(V(o)){const p=gt(t,o),u=new OffscreenCanvas(i.width,i.height),l=u.getContext("2d");return l.fillStyle="#000",l.fillRect(0,0,i.width,i.height),l.drawImage(p,c.x,c.y),mt(u)}const _=`${t.diffBase}/${n}`,f=await B(_);if(f.width===i.width&&f.height===i.height)return f;throw f.close(),new Error(`Diff PNG wrong size for ${n}`)})();return k.set(r,a),a}function P(e,t){const n={type:"status",label:e,generation:t};self.postMessage(n)}function Dt(e,t){const n={type:"error",requestId:e,message:t};self.postMessage(n)}async function T(e){if(!d)return;const t=ut(e);if(!t&&e!==w)return;const n=await createImageBitmap(d);if(!t&&e!==w){n.close();return}const r={type:"frame",bitmap:n,generation:e};self.postMessage(r,{transfer:[n]})}function It(e,t,n){return new Promise((r,s)=>{setTimeout(()=>{t!==n?s(new DOMException("Aborted","AbortError")):r()},e)})}async function j(e,t,n,r=y){const s=await S(h??void 0),{width:a,height:o}=A(s);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);const c=[];if(t){if(!s.viseme.cellByPath.get(t))throw new Error(`No viseme atlas cell for path: ${t}`);c.push(await G(s,s.viseme,t))}if(n&&s.expression){if(!s.expression.cellByPath.get(n))throw new Error(`No expression atlas cell for path: ${n}`);c.push(await G(s,s.expression,n))}const i=e.getContext("2d");if(i.clearRect(0,0,a,o),c.length===0){i.drawImage(s.sil,0,0,a,o);return}const _=ft(s.sil,c,a,o,r);i.drawImage(_,0,0)}async function q(e,t,n,r,s=y){await j(e,t,n,s),await T(r)}async function H(e,t,n){F="sil";const r=await S(h??void 0);if(t!==n)throw new DOMException("Aborted","AbortError");const{width:s,height:a}=A(r);e.width=s,e.height=a;const o=e.getContext("2d");o.clearRect(0,0,s,a),o.drawImage(r.sil,0,0,s,a),await T(t)}async function Et(e,t,n,r,s={}){const a=s.from??F,o=s.transitionDurationMs??400,c=s.gapMs??o,i=s.threshold??y;if(await S(h??void 0),a===t){if(P(t,n),t==="sil"?await H(e,n,r):await q(e,L(t),null,n,i),n!==r)throw new DOMException("Aborted","AbortError");F=t;return}const _=it(a,t),f=_t(_,c),p=f.length>0?o/f.length:0;f.length===0&&P(`${a} → ${t} (no pair; final only)`,n);for(let u=0;u<f.length;u++){if(n!==r)throw new DOMException("Aborted","AbortError");const l=f[u],M=l.split("/").pop()?.replace("_minus_sil.png","")??`frame ${u}`;if(P(`${a} → ${t} (${M})`,n),await q(e,l,null,n,i),n!==r)throw new DOMException("Aborted","AbortError");p>0&&await It(p,n,r)}if(n!==r)throw new DOMException("Aborted","AbortError");if(P(t,n),t==="sil"?await H(e,n,r):await q(e,L(t),null,n,i),n!==r)throw new DOMException("Aborted","AbortError");F=t}let w=0;self.onmessage=e=>{const t=e.data;(async()=>{try{switch(t.type){case"init":{d=new OffscreenCanvas(1,1);const n={type:"ready",requestId:t.requestId};self.postMessage(n);break}case"loadAssets":{$=t.urls,I=null,h=null,k.clear();const n=await S(t.keyHex),{width:r,height:s}=A(n),a={type:"loadAssetsDone",requestId:t.requestId,width:r,height:s};self.postMessage(a);break}case"cancelLiveDraws":{g+=1;const n={type:"renderDone",requestId:t.requestId,generation:w};self.postMessage(n);break}case"drawFrame":{await x(()=>dt(t));break}case"renderSil":{await x(async()=>{m=!0;try{if(w=t.generation,!d)throw new Error("Worker not initialized");await H(d,t.generation,w)}finally{m=!1}});const n={type:"renderDone",requestId:t.requestId,generation:t.generation};self.postMessage(n);break}case"renderViseme":{await x(async()=>{m=!0;try{if(w=t.generation,!d)throw new Error("Worker not initialized");await Et(d,t.to,t.generation,w,{from:t.from,transitionDurationMs:t.transitionDurationMs,gapMs:t.gapMs,threshold:t.threshold})}finally{m=!1}});const n={type:"renderDone",requestId:t.requestId,generation:t.generation};self.postMessage(n);break}default:break}}catch(n){if(n instanceof DOMException&&n.name==="AbortError"){const r={type:"renderAborted",requestId:t.requestId,generation:"generation"in t?t.generation:w};self.postMessage(r);return}Dt(t.requestId,n instanceof Error?n.message:String(n))}})()}})();
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(){"use strict";function j(e,t,n){return{width:e.crop?.source_width??t,height:e.crop?.source_height??n}}function Q(e,t){const n=e.crop;return{x:t?.source_x??n?.x??0,y:t?.source_y??n?.y??0,width:t?.source_w??n?.width??e.frame_width??0,height:t?.source_h??n?.height??e.frame_height??0}}function X(e){return e?(e.w??0)>0&&(e.h??0)>0:!1}function Y(e){const t=e.trim();if(t.length%2!==0)throw new Error("Invalid hex key");const n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=Number.parseInt(t.slice(r,r+2),16);return n}function I(e){return Uint8Array.from(e)}function Z(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}async function V(e,t){if(!t)throw new Error("Asset key is required for encrypted assets");if(e.byteLength<28)throw new Error("Encrypted payload too small");const n=new Uint8Array(e),r=I(n.subarray(0,12)),s=I(n.subarray(12,28)),a=I(n.subarray(28)),o=I(Z(a,s)),_=await crypto.subtle.importKey("raw",Y(t),{name:"AES-GCM"},!1,["decrypt"]);return crypto.subtle.decrypt({name:"AES-GCM",iv:r,tagLength:128},_,o)}async function M(e,t){const n=await fetch(e);if(!n.ok)throw new Error(`Failed to load encrypted asset: ${e}`);const r=await n.arrayBuffer();return V(r,t)}async function tt(e,t){if(!t)throw new Error("Missing asset key for encrypted JSON");const n=await M(e,t),r=new TextDecoder().decode(n);return JSON.parse(r)}async function et(e){const t=new Blob([e],{type:"image/webp"});return createImageBitmap(t)}async function nt(e){const t=new Blob([e],{type:"image/png"});return createImageBitmap(t)}const p=15,C=["t01_0.17","t02_0.33","t03_0.50","t04_0.67","t05_0.83"],rt=C.length,H=new Set(["aa__kk","aa__nn","aa__sil","CH__aa","CH__DD","CH__E","CH__FF","CH__I","CH__kk","CH__nn","CH__O","CH__PP","CH__RR","CH__sil","CH__SS","CH__TH","CH__U","DD__aa","DD__E","DD__FF","DD__I","DD__kk","DD__nn","DD__O","DD__PP","DD__RR","DD__sil","DD__SS","DD__TH","DD__U","E__aa","E__FF","E__I","E__kk","E__nn","E__O","E__PP","E__RR","E__sil","E__SS","E__TH","E__U","FF__aa","FF__I","FF__kk","FF__nn","FF__O","FF__PP","FF__RR","FF__sil","FF__SS","FF__TH","FF__U","I__aa","I__kk","I__nn","I__O","I__PP","I__RR","I__sil","I__SS","I__TH","I__U","kk__nn","kk__sil","nn__sil","O__aa","O__kk","O__nn","O__PP","O__RR","O__sil","O__SS","O__TH","O__U","PP__aa","PP__kk","PP__nn","PP__RR","PP__sil","PP__SS","PP__TH","PP__U","RR__aa","RR__kk","RR__nn","RR__sil","RR__SS","RR__TH","RR__U","SS__aa","SS__kk","SS__nn","SS__sil","SS__TH","SS__U","TH__aa","TH__kk","TH__nn","TH__sil","TH__U","U__aa","U__kk","U__nn","U__sil"]);function v(e,t){return`${e}__${t}`}function U(e,t){return`pairs/${e}/${t}_minus_sil.png`}function q(e){return`${e}_minus_sil.png`}function st(e,t){if(e===t)return[];const n=[],r=v(e,t);if(H.has(r)){for(const a of C)n.push(U(r,a));return n}const s=v(t,e);if(H.has(s)){for(let a=rt-1;a>=0;a--)n.push(U(s,C[a]));return n}return[]}function at(e){return e<16?[]:e<35?[2]:e<51?[0,4]:e<67?[0,2,4]:e<83?[0,1,2,3]:[0,1,2,3,4]}function ot(e,t){return at(t).map(r=>e[r]).filter(r=>r!=null)}function it(e,t,n){if(!n)return`${e}/${t}`;const r=t.split("/").pop()??t,s=r.includes(".")?r.slice(0,r.lastIndexOf(".")):r;return`${e}/${s}.bin`}function ct(e,t,n,r,s=p){const a=new OffscreenCanvas(n,r),o=a.getContext("2d",{willReadFrequently:!0});o.drawImage(e,0,0,n,r);const _=o.getImageData(0,0,n,r),i=o.createImageData(n,r);i.data.set(_.data);const f=new OffscreenCanvas(n,r).getContext("2d",{willReadFrequently:!0});for(const D of t){f.clearRect(0,0,n,r),f.drawImage(D,0,0,n,r);const d=f.getImageData(0,0,n,r);for(let c=0;c<i.data.length;c+=4){const E=d.data[c],O=d.data[c+1],G=d.data[c+2];Math.max(E,O,G)>s&&(i.data[c]=E,i.data[c+1]=O,i.data[c+2]=G,i.data[c+3]=255)}}return o.putImageData(i,0,0),a}const N=-1;function _t(e){return e<0}let S=0,L=Promise.resolve();function b(e,t){const n=t>0?-t:N,r={type:"renderDone",requestId:e,generation:n};self.postMessage(r)}async function lt(e){const t=typeof e.liveSeq=="number"?e.liveSeq:0;if(t>0&&(S=t),!u)throw new Error("Worker not initialized");if(t>0&&t!==S){b(e.requestId,t);return}if(await m(w??void 0),t>0&&t!==S){b(e.requestId,t);return}if(await J(u,e.diffPath,e.expressionDiffPath??null,e.threshold??p),t>0&&t!==S){b(e.requestId,t);return}const n=t>0?-t:N;await B(n),b(e.requestId,t)}let u=null,y=null,w=null,x=null,F="sil";const k=new Map;function g(){if(!x)throw new Error("Worker assets not configured");return x}function W(){const e=g();return e.encrypted?`${e.binBase}/sil.bin`:`${e.twinBase}/sil.png`}function ft(){const e=g();return e.encrypted?`${e.binBase}/atlas.bin`:`${e.twinBase}/atlas.json`}function ut(){const e=g();return e.encrypted?`${e.binBase}/expression_atlas.bin`:`${e.twinBase}/expression_atlas.json`}function dt(){const e=g();return e.encrypted?e.binBase:e.twinBase}function R(){return g().encrypted}async function $(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to load image: ${e}`);const n=await t.blob();return createImageBitmap(n)}async function z(e,t,n){const r=R(),s=r?await tt(e,n):await fetch(e).then(l=>{if(!l.ok)throw new Error(`Failed to load ${e}`);return l.json()}),a=s.sheets?.[0];if(!a?.path)throw new Error(`${e} has no sheets[0].path`);const o=r?await et(await M(it(t,a.path,r),n??"")):await $(`${t}/${a.path}`),_=new Map;for(const l of s.cells??[])l.path&&_.set(l.path,l);const i=new Map;for(const l of s.sheets??[])i.set(l.index,l);return{atlas:o,atlasMeta:s,cellByPath:_,sheetByIndex:i,diffBase:t}}async function m(e){if(R()&&!e)throw new Error("Encrypted assets enabled but no key provided");if(y&&(!R()||w===(e??null)))return y;w=e??null,k.clear();const t=dt();return y=(async()=>{const n=R()?await nt(await M(W(),e??"")):await $(W()),r=await z(ft(),t,e);let s=null;try{s=await z(ut(),t,e)}catch{s=null}return{sil:n,viseme:r,expression:s}})(),y}function A(e){return j(e.viseme.atlasMeta,e.sil.width,e.sil.height)}function wt(e,t){if(!e.sheetByIndex.get(t.sheet??0))throw new Error(`Unknown sheet index: ${t.sheet}`);const r=new OffscreenCanvas(t.w,t.h);return r.getContext("2d",{willReadFrequently:!0}).drawImage(e.atlas,t.x,t.y,t.w,t.h,0,0,t.w,t.h),r}async function ht(e){return createImageBitmap(e)}async function K(e,t,n){const r=`${t.diffBase}::${n}`,s=k.get(r);if(s)return s;const a=(async()=>{const o=t.cellByPath.get(n);if(!o)throw new Error(`No atlas cell for path: ${n}`);const _=Q(t.atlasMeta,o),i=A(e);if(X(o)){const D=wt(t,o),d=new OffscreenCanvas(i.width,i.height),c=d.getContext("2d");return c.fillStyle="#000",c.fillRect(0,0,i.width,i.height),c.drawImage(D,_.x,_.y),ht(d)}const l=`${t.diffBase}/${n}`,f=await $(l);if(f.width===i.width&&f.height===i.height)return f;throw f.close(),new Error(`Diff PNG wrong size for ${n}`)})();return k.set(r,a),a}function P(e,t){const n={type:"status",label:e,generation:t};self.postMessage(n)}function pt(e,t){const n={type:"error",requestId:e,message:t};self.postMessage(n)}async function B(e){if(!u)return;const t=_t(e);if(!t&&e!==h)return;const n=await createImageBitmap(u);if(!t&&e!==h){n.close();return}const r={type:"frame",bitmap:n,generation:e};self.postMessage(r,{transfer:[n]})}function yt(e,t,n){return new Promise((r,s)=>{setTimeout(()=>{t!==n?s(new DOMException("Aborted","AbortError")):r()},e)})}async function J(e,t,n,r=p){const s=await m(w??void 0),{width:a,height:o}=A(s);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);const _=[];if(t){if(!s.viseme.cellByPath.get(t))throw new Error(`No viseme atlas cell for path: ${t}`);_.push(await K(s,s.viseme,t))}if(n&&s.expression){if(!s.expression.cellByPath.get(n))throw new Error(`No expression atlas cell for path: ${n}`);_.push(await K(s,s.expression,n))}const i=e.getContext("2d");if(i.clearRect(0,0,a,o),_.length===0){i.drawImage(s.sil,0,0,a,o);return}const l=ct(s.sil,_,a,o,r);i.drawImage(l,0,0)}async function T(e,t,n,r,s=p){await J(e,t,n,s),await B(r)}async function gt(e,t,n){F="sil";const r=await m(w??void 0);if(t!==n)throw new DOMException("Aborted","AbortError");const{width:s,height:a}=A(r);e.width=s,e.height=a;const o=e.getContext("2d");o.clearRect(0,0,s,a),o.drawImage(r.sil,0,0,s,a),await B(t)}async function mt(e,t,n,r,s={}){const a=s.from??F,o=s.transitionDurationMs??400,_=s.gapMs??o,i=s.threshold??p;if(await m(w??void 0),a===t){if(P(t,n),await T(e,q(t),null,n,i),n!==r)throw new DOMException("Aborted","AbortError");F=t;return}const l=st(a,t),f=ot(l,_),D=q(t),d=f.length>0?o/f.length:0;f.length===0&&P(`${a} → ${t} (no pair; final only)`,n);for(let c=0;c<f.length;c++){if(n!==r)throw new DOMException("Aborted","AbortError");const E=f[c],O=E.split("/").pop()?.replace("_minus_sil.png","")??`frame ${c}`;if(P(`${a} → ${t} (${O})`,n),await T(e,E,null,n,i),n!==r)throw new DOMException("Aborted","AbortError");d>0&&await yt(d,n,r)}if(n!==r)throw new DOMException("Aborted","AbortError");if(P(t,n),await T(e,D,null,n,i),n!==r)throw new DOMException("Aborted","AbortError");F=t}let h=0;self.onmessage=e=>{const t=e.data;(async()=>{try{switch(t.type){case"init":{u=new OffscreenCanvas(1,1);const n={type:"ready",requestId:t.requestId};self.postMessage(n);break}case"loadAssets":{x=t.urls,y=null,w=null,k.clear();const n=await m(t.keyHex),{width:r,height:s}=A(n),a={type:"loadAssetsDone",requestId:t.requestId,width:r,height:s};self.postMessage(a);break}case"drawFrame":{await new Promise((n,r)=>{L=L.then(()=>lt(t)).then(n).catch(r)});break}case"renderSil":{if(h=t.generation,!u)throw new Error("Worker not initialized");await gt(u,t.generation,h);const n={type:"renderDone",requestId:t.requestId,generation:t.generation};self.postMessage(n);break}case"renderViseme":{if(h=t.generation,!u)throw new Error("Worker not initialized");await mt(u,t.to,t.generation,h,{from:t.from,transitionDurationMs:t.transitionDurationMs,gapMs:t.gapMs,threshold:t.threshold});const n={type:"renderDone",requestId:t.requestId,generation:t.generation};self.postMessage(n);break}default:break}}catch(n){if(n instanceof DOMException&&n.name==="AbortError"){const r={type:"renderAborted",requestId:t.requestId,generation:"generation"in t?t.generation:h};self.postMessage(r);return}pt(t.requestId,n instanceof Error?n.message:String(n))}})()}})();
|