(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const f of i.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&s(f)}).observe(document,{childList:!0,subtree:!0});function r(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(n){if(n.ep)return;n.ep=!0;const i=r(n);fetch(n.href,i)}})();const K="cr_dev_447dcf88dbc378796a6903e2091858f5",j=12e3,Y=500,U=1.5,A=[[.1,.1],[.9,.1],[.5,.5],[.1,.9],[.9,.9]],a=e=>document.getElementById(e),V=a("demo-stage"),_=a("passage"),c=a("scan-canvas"),u=a("demo-video"),R=a("demo-idle"),E=a("read-badge"),$=a("read-count"),T=a("replay-bar"),P=a("cal-overlay"),L=a("cal-target"),J=a("cal-note");let o=null,w=null,C=!1,y=[],x=null;const b=e=>e&&(e.style.display=""),d=e=>e&&(e.style.display="none");var W;(W=a("btn-start"))==null||W.addEventListener("click",Q);var z;(z=a("btn-sample"))==null||z.addEventListener("click",q);var B;(B=a("btn-replay"))==null||B.addEventListener("click",()=>H(y));var F;(F=a("btn-again"))==null||F.addEventListener("click",S);function S(){N(),d(T),d(E),d(P),d(u),ie(),b(R)}function N(){C=!1;try{o&&(o.onGaze=null,o.stop(),o.destroy())}catch{}o=null,w&&(w.getTracks().forEach(e=>e.stop()),w=null)}async function Q(){if(d(R),typeof CREyeTracker>"u")return alert("SDK failed to load."),S();try{w=await navigator.mediaDevices.getUserMedia({video:{width:640,height:480},audio:!1}),u.srcObject=w,b(u),await u.play()}catch{return alert("Camera unavailable — showing a sample replay instead."),q()}try{o=new CREyeTracker({apiKey:K,distance:50,screenWidthPx:document.documentElement.clientWidth,screenHeightPx:document.documentElement.clientHeight,onLog:()=>{}}),o.attachVideo(u),await o.init(),await o.start()}catch(e){return alert("Eye tracker failed to start: "+(e&&e.message||e)),S()}await X(),await ee()}function X(){return new Promise(e=>{b(P),J.textContent="Calibration — follow the dot with your eyes",o.calibrationStart();let t=0;const r=()=>{if(t>=A.length){o.onCalibrationSample=null,o.onCalibrationPointReady=null,o.calibrationEnd(),o.getCalibration().then(()=>{d(P),e()});return}const[s,n]=A[t];Z(s,n),v(0),setTimeout(()=>{o.onCalibrationSample=i=>v(i.progress),o.onCalibrationPointReady=()=>{o.commitCaliPoint(),v(1),t++,setTimeout(r,400)},o.setCaliTarget(s,n)},Y)};r()})}function Z(e,t){L.style.left=e*100+"%",L.style.top=t*100+"%"}function v(e){L.style.setProperty("--p",String(e))}function ee(){return new Promise(e=>{d(P),b(E),x=_.getBoundingClientRect(),y=[],C=!0,o.onGaze=te;const t=performance.now(),r=()=>{const s=j-(performance.now()-t);if($.textContent=Math.max(0,s/1e3).toFixed(1)+"s",s<=0){C=!1,o.onGaze=null,N(),d(E),d(u),D(),e();return}requestAnimationFrame(r)};r()})}function te(e){if(!C||!e||e.state!==0||e.x<0)return;const t=e.x*window.innerWidth,r=e.y*window.innerHeight;y.push({nx:(t-x.left)/x.width,ny:(r-x.top)/x.height,t:e.t,fix:!!e.isFix})}function q(){d(R),d(u),y=ne(),D()}function ne(){const e=[],t=i=>(Math.random()-.5)*i;let n=0;for(let i=0;i<7;i++){const f=.13+i/6*.74;for(let h=0;h<6;h++){const g=.07+h/5*.86,p=170+Math.random()*150;for(let m=0;m<4;m++)e.push({nx:g+t(.02),ny:f+t(.015),t:n,fix:!0}),n+=p/4;n+=28,e.push({nx:g,ny:f,t:n,fix:!1})}n+=60,e.push({nx:.9,ny:f,t:n,fix:!1}),n+=90}return e}function D(){b(T),requestAnimationFrame(()=>H(y))}function G(){const e=_.getBoundingClientRect(),t=V.getBoundingClientRect();c.width=e.width,c.height=e.height,c.style.left=e.left-t.left+"px",c.style.top=e.top-t.top+"px",c.style.width=e.width+"px",c.style.height=e.height+"px"}function ie(){const e=c.getContext("2d");e&&e.clearRect(0,0,c.width,c.height)}function H(e){if(!e||!e.length)return;G();const t=c.getContext("2d"),r=c.width,s=c.height,n=e[0].t,i=e[e.length-1].t-n||1,f=performance.now(),h=()=>{const g=(performance.now()-f)*U;t.clearRect(0,0,r,s);let p=0;t.lineWidth=2,t.strokeStyle="rgba(122,162,255,0.5)",t.beginPath();let m=!1;for(let l=0;lg);l++){p=l;const O=e[l].nx*r,I=e[l].ny*s;m?t.lineTo(O,I):(t.moveTo(O,I),m=!0)}t.stroke(),t.fillStyle="rgba(94,234,212,0.13)";for(let l=0;l<=p;l++)e[l].fix&&(t.beginPath(),t.arc(e[l].nx*r,e[l].ny*s,9,0,Math.PI*2),t.fill());const k=e[p].nx*r,M=e[p].ny*s;t.fillStyle="#5eead4",t.beginPath(),t.arc(k,M,6,0,Math.PI*2),t.fill(),t.strokeStyle="rgba(94,234,212,0.45)",t.lineWidth=2,t.beginPath(),t.arc(k,M,12,0,Math.PI*2),t.stroke(),g{y.length&&T.style.display!=="none"&&G()});