/* Silent pre-generated thinking. Request state changes now; visuals finish at their boundary. */ (function(){ 'use strict'; const stage=document.querySelector('#stage'),player=window.AvatarScene; if(!stage||!player)return; const base=new URL('../',document.currentScript.src).pathname,ids=['glance','reflect','chin']; const scene=document.createElement('div');scene.className='thinking-scene';scene.setAttribute('aria-hidden','true');stage.prepend(scene); let active=false,cursor=-1,entry=null,failed=new Set(); function status(value){scene.dataset.state=value;} function next(){ if(!active)return; let id;for(let n=0;n{v.controls=document.fullscreenElement===v;}); v.addEventListener('webkitbeginfullscreen',()=>{v.controls=true;}); v.addEventListener('webkitendfullscreen',()=>{v.controls=false;}); } function stop(){ active=false;entry=null;player.set('thinking',null); status(player.getCurrent()?.slot==='thinking'?'finishing':'idle'); } function start(){ if(active)return; active=true;failed=new Set(); const shown=player.getCurrent(); // A fresh request arriving during the tail reuses the same motion, never seeks mid-frame. if(shown?.slot==='thinking'&&!shown.failed&&!shown.atEnd){entry=shown;player.set('thinking',shown);status('playing');} else next(); } window.addEventListener('online',()=>{if(active&&!entry){failed.clear();next();}}); window.ThinkingBackground={start,stop,getVideo:()=>player.getCurrent()?.slot==='thinking'?player.getCurrent().video:null}; status('idle'); })();