1(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,4398,t=>{"use strict";var e=t.i(32655),i=t.i(63217),s=t.i(94927);t.i(38532);var h=t.i(70789);function r(t){return"pterodactyl"!==t.typeConfig.type||t.yPos>=100?"jump":t.yPos>=75?"duck":"clear"}class a{onLog;nextId=0;handled=new WeakSet;ducking=!1;restartTimer=null;constructor(t){this.onLog=t}step(t){let{trex:e}=t,i=e.xPos+e.config.width,s=t.obstacles.find(t=>t.xPos+t.width>i&&"clear"!==r(t));if(!s)return void this.setDuck(t,!1);let h=s.xPos-i,a=r(s),n=t.currentSpeed+(s.typeConfig.speedOffset??0);if("duck"===a){let e=h<=11*n;this.setDuck(t,e),e&&!this.handled.has(s)&&(this.handled.add(s),this.log(s,"duck under the pterodactyl",t));return}h<=8*n&&(this.setDuck(t,!1),!e.jumping&&(t.press(),this.handled.has(s)||(this.handled.add(s),this.log(s,this.jumpPhrase(s),t))))}onCrash(t){this.ducking=!1,this.emit('act("restart the run")',`score ${t.score}`),this.restartTimer=setTimeout(()=>t.restart(),1400)}reset(){this.handled=new WeakSet,this.ducking=!1}start(){this.emit('observe("what is in the dino\'s way")',"watching")}stop(){this.restartTimer&&clearTimeout(this.restartTimer),this.restartTimer=null}jumpPhrase(t){return"pterodactyl"===t.typeConfig.type?"jump over the pterodactyl":t.size>1?`jump over the ${t.size} cacti`:"jump over the cactus"}setDuck(t,e){this.ducking!==e&&(this.ducking=e,t.duck(e))}log(t,e,i){this.emit(`act("${e}")`,`${t.typeConfig.type} \xb7 ${i.currentSpeed.toFixed(1)}x`)}emit(t,e){this.onLog({id:this.nextId++,call:t,meta:e})}}let n={cactusLarge:{x:332,y:2},cactusSmall:{x:228,y:2},cloud:{x:86,y:2},horizon:{x:2,y:54},moon:{x:484,y:2},pterodactyl:{x:134,y:2},restart:{x:2,y:68},textSprite:{x:655,y:2},tRex:{x:848,y:2},star:{x:645,y:2}},o={cactusLarge:{x:652,y:2},cactusSmall:{x:446,y:2},cloud:{x:166,y:2},horizon:{x:2,y:104},moon:{x:954,y:2},pterodactyl:{x:260,y:2},restart:{x:2,y:130},textSprite:{x:1294,y:2},tRex:{x:1678,y:2},star:{x:1276,y:2}},c=[{type:"cactusSmall",width:17,height:35,yPos:105,multipleSpeed:4,minGap:120,minSpeed:0,collisionBoxes:[{x:0,y:7,width:5,height:27},{x:4,y:0,width:6,height:34},{x:10,y:4,width:7,height:14}]},{type:"cactusLarge",width:25,height:50,yPos:90,multipleSpeed:7,minGap:120,minSpeed:0,collisionBoxes:[{x:0,y:12,width:7,height:38},{x:8,y:0,width:7,height:49},{x:13,y:10,width:10,height:38}]},{type:"pterodactyl",width:46,height:40,yPos:[100,75,50],yPosMobile:[100,50],multipleSpeed:999,minSpeed:8.5,minGap:150,collisionBoxes:[{x:15,y:15,width:16,height:5},{x:18,y:21,width:24,height:6},{x:2,y:14,width:4,height:3},{x:6,y:10,width:4,height:7},{x:10,y:8,width:6,height:9}],numFrames:2,frameRate:1e3/6,speedOffset:.8}];function d(t,e){return Math.floor(Math.random()*(e-t+1))+t}function l(t,e){return t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.height+t.y>e.y}let u={dropVelocity:-5,gravity:.6,height:47,initialJumpVelocity:-10,introDuration:400,maxJumpHeight:30,minJumpHeight:30,speedDropCoefficient:3,startXPos:50,width:44,widthDuck:59},p=[{x:1,y:18,width:55,height:25}],m=[{x:22,y:0,width:17,height:16},{x:1,y:18,width:30,height:9},{x:10,y:35,width:14,height:8},{x:1,y:24,width:29,height:5},{x:5,y:30,width:21,height:4},{x:9,y:34,width:15,height:4}],g={WAITING:{frames:[44,0],msPerFrame:1e3/3},RUNNING:{frames:[88,132],msPerFrame:1e3/12},CRASHED:{frames:[220],msPerFrame:1e3/60},JUMPING:{frames:[0],msPerFrame:1e3/60},DUCKING:{frames:[264,323],msPerFrame:125}};class x{config={...u};playingIntro=!1;xPos=0;yPos=0;jumpCount=0;ducking=!1;blinkCount=0;jumping=!1;speedDrop=!1;status="WAITING";ctx;sheet;xInitialPos=0;introProgress=0;groundYPos=0;currentFrame=0;currentAnimFrames=[];blinkDelay=0;animStartTime=0;timer=0;msPerFrame=16.666666666666668;jumpVelocity=0;reachedMinHeight=!1;minJumpHeight;constructor(t,e){this.ctx=t,this.sheet=e,this.groundYPos=150-this.config.height-10,this.yPos=this.groundYPos,this.minJumpHeight=this.groundYPos-this.config.minJumpHeight,this.draw(0,0),this.update(0,"WAITING")}update(t,e){this.timer+=t,void 0!==e&&(this.status=e,this.currentFrame=0,this.msPerFrame=g[e].msPerFrame,this.currentAnimFrames=g[e].frames,"WAITING"===e&&(this.animStartTime=performance.now(),this.setBlinkDelay())),this.playingIntro&&this.xPos<this.config.startXPos&&(this.introProgress+=this.config.startXPos/this.config.introDuration*t,this.xPos=Math.min(this.config.startXPos,Math.round(this.introProgress)),this.xInitialPos=this.xPos),"WAITING"===this.status?this.blink(performance.now()):this.draw(this.currentAnimFrames[this.currentFrame],0),this.timer>=this.msPerFrame&&(this.currentFrame=this.currentFrame===this.currentAnimFrames.length-1?0:this.currentFrame+1,this.timer=0),this.speedDrop&&this.yPos===this.groundYPos&&(this.speedDrop=!1,this.setDuck(!0))}draw(t,e){let i=t,s=e,h=this.ducking&&"CRASHED"!==this.status?this.config.widthDuck:this.config.width,r=this.config.height;this.sheet.hidpi&&(i*=2,s*=2,h*=2,r*=2),i+=this.sheet.pos.tRex.x,s+=this.sheet.pos.tRex.y,this.ducking&&"CRASHED"!==this.status?this.ctx.drawImage(this.sheet.image,i,s,h,r,this.xPos,this.yPos,this.config.widthDuck,this.config.height):(this.ducking&&"CRASHED"===this.status&&this.xPos++,this.ctx.drawImage(this.sheet.image,i,s,h,r,this.xPos,this.yPos,this.config.width,this.config.height))}redraw(){this.draw(this.currentAnimFrames[this.currentFrame]??0,0)}setBlinkDelay(){this.blinkDelay=Math.ceil(7e3*Math.random())}blink(t){t-this.animStartTime>=this.blinkDelay&&(this.draw(this.currentAnimFrames[this.currentFrame],0),1===this.currentFrame&&(this.setBlinkDelay(),this.animStartTime=t,this.blinkCount++))}startJump(t){this.jumping||(this.update(0,"JUMPING"),this.jumpVelocity=this.config.initialJumpVelocity-t/10,this.jumping=!0,this.reachedMinHeight=!1,this.speedDrop=!1)}endJump(){this.reachedMinHeight&&this.jumpVelocity<this.config.dropVelocity&&(this.jumpVelocity=this.config.dropVelocity)}updateJump(t){let e=t/g[this.status].msPerFrame;this.speedDrop?this.yPos+=Math.round(this.jumpVelocity*this.config.speedDropCoefficient*e):this.yPos+=Math.round(this.jumpVelocity*e),this.jumpVelocity+=this.config.gravity*e,(this.yPos<this.minJumpHeight||this.speedDrop)&&(this.reachedMinHeight=!0),(this.yPos<this.config.maxJumpHeight||this.speedDrop)&&this.endJump(),this.yPos>this.groundYPos&&(this.reset(),this.jumpCount++)}setSpeedDrop(){this.speedDrop=!0,this.jumpVelocity=1}setDuck(t){t&&"DUCKING"!==this.status?(this.update(0,"DUCKING"),this.ducking=!0):"DUCKING"===this.status&&(this.update(0,"RUNNING"),this.ducking=!1)}reset(){this.xPos=this.xInitialPos,this.yPos=this.groundYPos,this.jumpVelocity=0,this.jumping=!1,this.ducking=!1,this.update(0,"RUNNING"),this.speedDrop=!1,this.jumpCount=0}getCollisionBoxes(){return this.ducking?p:m}}class y{collisionBoxes=[];followingObstacleCreated=!1;gap=0;remove=!1;size;width=0;xPos;yPos=0;typeConfig;ctx;sheet;spritePos;speedOffset=0;currentFrame=0;timer=0;constructor(t,e,i,s,h,r){if(this.ctx=t,this.sheet=e,this.typeConfig=i,this.spritePos=e.pos[i.type],this.size=d(1,3),this.xPos=s+i.width,this.cloneCollisionBoxes(),this.size>1&&this.typeConfig.multipleSpeed>r&&(this.size=1),this.width=this.typeConfig.width*this.size,Array.isArray(this.typeConfig.yPos)){const t=this.t
1ypeConfig.yPos;this.yPos=t[d(0,t.length-1)]}else this.yPos=this.typeConfig.yPos;this.draw(),this.size>1&&(this.collisionBoxes[1].width=this.width-this.collisionBoxes[0].width-this.collisionBoxes[2].width,this.collisionBoxes[2].x=this.width-this.collisionBoxes[2].width),this.typeConfig.speedOffset&&(this.speedOffset=Math.random()>.5?this.typeConfig.speedOffset:-this.typeConfig.speedOffset),this.gap=this.getGap(h,r)}draw(){let t=this.typeConfig.width,e=this.typeConfig.height;this.sheet.hidpi&&(t*=2,e*=2);let i=t*this.size*(.5*(this.size-1))+this.spritePos.x;this.currentFrame>0&&(i+=t*this.currentFrame),this.ctx.drawImage(this.sheet.image,i,this.spritePos.y,t*this.size,e,this.xPos,this.yPos,this.typeConfig.width*this.size,this.typeConfig.height)}update(t,e){!this.remove&&(this.typeConfig.speedOffset&&(e+=this.speedOffset),this.xPos-=Math.floor(60*e/1e3*t),this.typeConfig.numFrames&&(this.timer+=t,this.timer>=this.typeConfig.frameRate&&(this.currentFrame=this.currentFrame===this.typeConfig.numFrames-1?0:this.currentFrame+1,this.timer=0)),this.draw(),this.isVisible()||(this.remove=!0))}getGap(t,e){let i=Math.round(this.width*e+this.typeConfig.minGap*t);return d(i,Math.round(1.5*i))}isVisible(){return this.xPos+this.width>0}cloneCollisionBoxes(){this.collisionBoxes=this.typeConfig.collisionBoxes.map(t=>({...t}))}}class f{gap;xPos;remove=!1;yPos;ctx;sheet;constructor(t,e,i){this.ctx=t,this.sheet=e,this.xPos=i,this.gap=d(100,400),this.yPos=d(30,71),this.draw()}draw(){let t=this.sheet.hidpi?92:46,e=this.sheet.hidpi?28:14;this.ctx.drawImage(this.sheet.image,this.sheet.pos.cloud.x,this.sheet.pos.cloud.y,t,e,this.xPos,this.yPos,46,14)}update(t){!this.remove&&(this.xPos-=Math.ceil(t),this.draw(),this.xPos+46<=0&&(this.remove=!0))}}class w{ctx;sheet;spritePos;xPos;yPos;sourceXPos;sourceWidth;sourceHeight;constructor(t,e){this.ctx=t,this.sheet=e,this.spritePos={x:e.hidpi?4:2,y:e.hidpi?104:52},this.sourceXPos=[this.spritePos.x,this.spritePos.x+600],this.xPos=[0,600],this.yPos=127,this.sourceWidth=e.hidpi?1200:600,this.sourceHeight=e.hidpi?24:12,this.draw()}getRandomType(){return 600*!!(Math.random()>.5)}draw(){for(let t of[0,1])this.ctx.drawImage(this.sheet.image,this.sourceXPos[t],this.spritePos.y,this.sourceWidth,this.sourceHeight,this.xPos[t],this.yPos,600,12)}updateXPos(t,e){let i=+(0===t);this.xPos[t]-=e,this.xPos[i]=this.xPos[t]+600,this.xPos[t]<=-600&&(this.xPos[t]+=1200,this.xPos[i]=this.xPos[t]-600,this.sourceXPos[t]=this.getRandomType()+this.spritePos.x)}update(t,e){this.updateXPos(this.xPos[0]<=0?0:1,Math.floor(.06*e*t)),this.draw()}reset(){this.xPos[0]=0,this.xPos[1]=600}}let v=[140,120,100,60,40,20,0];class P{ctx;sheet;xPos=0;yPos=30;currentPhase=0;opacity=0;containerWidth;stars=[];drawStars=!1;constructor(t,e,i){this.ctx=t,this.sheet=e,this.containerWidth=i,this.placeStars()}update(t){if(t&&0===this.opacity&&(this.currentPhase++,this.currentPhase>=v.length&&(this.currentPhase=0)),t&&(this.opacity<1||0===this.opacity)?this.opacity+=.035:this.opacity>0&&(this.opacity-=.035),this.opacity>0){if(this.xPos=this.updateXPos(this.xPos,.25),this.drawStars)for(let t of this.stars)t.x=this.updateXPos(t.x,.3);this.draw()}else this.opacity=0,this.placeStars();this.drawStars=!0}updateXPos(t,e){return t<-20?this.containerWidth:t-e}draw(){let t=this.sheet.hidpi,e=v[this.currentPhase],i=3===this.currentPhase?40:20,s=40,h=this.sheet.pos.moon.x+e,r=i,a=9;if(t&&(i*=2,s*=2,h=this.sheet.pos.moon.x+2*e,a*=2),this.ctx.save(),this.ctx.globalAlpha=this.opacity,this.drawStars)for(let t of this.stars)this.ctx.drawImage(this.sheet.image,this.sheet.pos.star.x,t.sourceY,a,a,Math.round(t.x),t.y,9,9);this.ctx.drawImage(this.sheet.image,h,this.sheet.pos.moon.y,i,s,Math.round(this.xPos),this.yPos,r,40),this.ctx.globalAlpha=1,this.ctx.restore()}placeStars(){let t=Math.round(this.containerWidth/2),e=this.sheet.hidpi?18:9;this.stars=Array.from({length:2},(i,s)=>({x:d(t*s,t*(s+1)),y:d(0,70),sourceY:this.sheet.pos.star.y+e*s}))}reset(){this.currentPhase=0,this.opacity=0,this.update(!1)}}class S{achievement=!1;ctx;sheet;x=0;y=5;maxScore=0;highScore="";digits=[];defaultString="";flashTimer=0;flashIterations=0;maxScoreUnits=5;constructor(t,e,i){this.ctx=t,this.sheet=e;let s="";this.calcXPos(i);for(let t=0;t<this.maxScoreUnits;t++)this.draw(t,0),this.defaultString+="0",s+="9";this.maxScore=parseInt(s,10)}calcXPos(t){this.x=t-11*(this.maxScoreUnits+1)}draw(t,e,i){let s=10,h=13,r=10*e;this.sheet.hidpi&&(s*=2,h*=2,r*=2),r+=this.sheet.pos.textSprite.x,this.ctx.save();let a=this.x-2*this.maxScoreUnits*10;this.ctx.translate(i?a:this.x,this.y),this.ctx.drawImage(this.sheet.image,r,this.sheet.pos.textSprite.y,s,h,11*t,this.y,10,13),this.ctx.restore(
1)}getActualDistance(t){return t?Math.round(.025*t):0}update(t,e){let i=!0,s=!1;if(this.achievement?this.flashIterations<=3?(this.flashTimer+=t,this.flashTimer<250?i=!1:this.flashTimer>500&&(this.flashTimer=0,this.flashIterations++)):(this.achievement=!1,this.flashIterations=0,this.flashTimer=0):((e=this.getActualDistance(e))>this.maxScore&&5===this.maxScoreUnits&&(this.maxScoreUnits++,this.maxScore=parseInt(this.maxScore+"9",10)),e>0?(e%100==0&&(this.achievement=!0,this.flashTimer=0,s=!0),this.digits=(this.defaultString+e).slice(-this.maxScoreUnits).split("")):this.digits=this.defaultString.split("")),i)for(let t=this.digits.length-1;t>=0;t--)this.draw(t,parseInt(this.digits[t],10));return this.drawHighScore(),s}drawHighScore(){if(this.highScore){this.ctx.save(),this.ctx.globalAlpha=.8;for(let t=this.highScore.length-1;t>=0;t--){let e=this.highScore[t],i=parseInt(e,10);if(isNaN(i))if("H"===e)i=10;else{if("I"!==e)continue;i=11}this.draw(t,i,!0)}this.ctx.restore()}}setHighScore(t){let e=(this.defaultString+this.getActualDistance(t)).slice(-this.maxScoreUnits);this.highScore="HI "+e}reset(){this.update(0,0),this.achievement=!1}}let b={frames:[0,36,72,108,144,180,216,252],msPerFrame:875/8};class k{ctx;sheet;canvasWidth;canvasHeight;frameTimeStamp=0;animTimer=0;currentFrame=0;rafId=null;constructor(t,e,i,s){this.ctx=t,this.sheet=e,this.canvasWidth=i,this.canvasHeight=s}updateDimensions(t,e){this.canvasWidth=t,e&&(this.canvasHeight=e),this.currentFrame=b.frames.length-1}drawGameOverText(){let t=0,e=13,i=191,s=11;this.sheet.hidpi&&(t*=2,e*=2,i*=2,s*=2),t+=this.sheet.pos.textSprite.x,e+=this.sheet.pos.textSprite.y,this.ctx.drawImage(this.sheet.image,t,e,i,s,Math.round(this.canvasWidth/2-95.5),Math.round((this.canvasHeight-25)/3),191,11)}drawRestartButton(){let t=b.frames[this.currentFrame],e=36,i=32;this.sheet.hidpi&&(e*=2,i*=2,t*=2),this.ctx.drawImage(this.sheet.image,this.sheet.pos.restart.x+t,this.sheet.pos.restart.y,e,i,this.canvasWidth/2-16,this.canvasHeight/2,36,32)}getRestartBounds(){return{x:this.canvasWidth/2-16,y:this.canvasHeight/2,width:36,height:32}}draw(){this.drawGameOverText(),this.drawRestartButton(),this.update()}update=()=>{let t=performance.now(),e=t-(this.frameTimeStamp||t);if(this.frameTimeStamp=t,this.animTimer+=e,0===this.currentFrame&&this.animTimer>875)this.animTimer=0,this.currentFrame++,this.drawRestartButton();else if(this.currentFrame>0&&this.currentFrame<b.frames.length)this.animTimer>=b.msPerFrame&&(this.currentFrame++,this.drawRestartButton());else if(this.currentFrame===b.frames.length)return void this.reset();this.rafId=requestAnimationFrame(this.update)};reset(){this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.animTimer=0,this.frameTimeStamp=0,this.currentFrame=0}}function I(t,e){return{x:t.x+e.x,y:t.y+e.y,width:t.width,height:t.height}}let C="stagehand.dino.highScore";function T(t){let e=t.composedPath()[0]??t.target;return!!e?.closest?.("a[href], button")}class D{obstacles=[];ctx;sheet;width;clouds=[];horizonLine;nightMode;obstacleHistory=[];constructor(t,e,i){this.ctx=t,this.sheet=e,this.width=i,this.horizonLine=new w(t,e),this.nightMode=new P(t,e,i),this.addCloud()}update(t,e,i,s){this.horizonLine.update(t,e),this.nightMode.update(s),this.updateClouds(t,e),i&&this.updateObstacles(t,e)}updateClouds(t,e){let i=2e-4*t*e;if(0===this.clouds.length)return void this.addCloud();for(let t=this.clouds.length-1;t>=0;t--)this.clouds[t].update(i);let s=this.clouds[this.clouds.length-1];this.clouds.length<6&&this.width-s.xPos>s.gap&&.5>Math.random()&&this.addCloud(),this.clouds=this.clouds.filter(t=>!t.remove)}updateObstacles(t,e){for(let i of this.obstacles)i.update(t,e);this.obstacles=this.obstacles.filter(t=>!t.remove);let i=this.obstacles[this.obstacles.length-1];i?!i.followingObstacleCreated&&i.isVisible()&&i.xPos+i.width+i.gap<this.width&&(this.addNewObstacle(e),i.followingObstacleCreated=!0):this.addNewObstacle(e)}addNewObstacle(t){let e=c[d(0,c.length-1)];this.duplicateObstacleCheck(e.type)||t<e.minSpeed?this.addNewObstacle(t):(this.obstacles.push(new y(this.ctx,this.sheet,e,this.width,.6,t)),this.obstacleHistory.unshift(e.type),this.obstacleHistory.length>1&&this.obstacleHistory.splice(2))}duplicateObstacleCheck(t){let e=0;for(let i of this.obstacleHistory)e=i===t?e+1:0;return e>=2}addCloud(){this.clouds.push(new f(this.ctx,this.sheet,this.width))}resize(t){this.width=t}reset(){this.obstacles=[],this.horizonLine.reset(),this.nightMode.reset()}}class j{agent=null;currentSpeed=6;crashed=!1;playing=!1;inverted=!1;distanceRan=0;container;trex;canvas;ctx;sheet;horizon;distanceMeter;gameOverPanel;options;width=600;activated=!1;paused=!1;playingIntro=!1;introAnimation=null;runningTime=0;highestScore=0;invertTimer=0;invertTrigger=!1;time=0;rafId=0;msPerFrame=1e3/60;detachers=[];constructor(t,e){this.options=e,this.sheet={image:e.image,hidpi:e.hidpi,pos:e.hidpi?o:n},this.container=document.createElement("div"),this.container.style.cssText="position:relative;height:150px;overflow:hidden;max-width:600px",this.canvas=document.createElement("canvas"),this.canvas.width=600,this.canvas.height=150,this.canvas.style.cssText="display:block;position:absolute;top:0;left:0",this.canvas.tabIndex=0,this.canvas.setAttribute("role","application"),this.canvas.setAttribute("aria-label","Dino runner game. Press space or up arrow to jump, down arrow to duck."),this.container.append(this.canvas),t.append(this.container),this.ctx=this.canvas.getContext("2d"),this.horizon=new D(this.ctx,this.sheet,this.width),this.distanceMeter=new S(this.ctx,this.sheet,this.width),this.gameOverPanel=new k(this.ctx,this.sheet,this.width,150),this.trex=new x(this.ctx,this.sheet),this.loadHighScore(),this.adjustDimensions(),this.listen(),this.publish(),this.startLoop()}adjustDimensions(){let t=this.container.parentElement?.clientWidth??600;this.width=Math.max(240,Math.min(600,t)),this.canvas.width=this.width,this.canvas.height=150,this.container.style.width=`${this.width}px`,this.sheet.hidpi&&(this.canvas.width=2*this.width,this.canvas.height=300,this.canvas.style.width=`${this.width}px`,this.canvas.style.height="150px",this.ctx.scale(2,2)),this.horizon.resize(this.width),this.distanceMeter.calcXPos(this.width),this.gameOverPanel.updateDimensions(this.width),this.clearCanvas(),this.horizon.update(0,0,!0,!1),this.trex.update(0),this.trex.redraw(),this.crashed&&this.gameOverPanel.draw()}listen(){let t=t=>this.onKeyDown(t),e=t=>this.onKeyUp(t),i=t=>{t.preventDefault(),this.canvas.focus(),this.crashed?this.handleGameOverClick(t):this.press()},s=()=>this.release(),h=()=>this.adjustDimensions(),r=()=>{document.hidden||!document.hasFocus()?this.pause():this.crashed||this.resume()};document.addEventListener("keydown",t),document.addEventListener("keyup",e),this.container.addEventListener("pointerdown",i),this.container.addEventListener("pointerup",s),window.addEventListener("resize",h),document.addEventListener("visibilitychange",r),window.addEventListener("blur",r),window.addEventListener("focus",r),this.detachers.push(()=>{document.removeEventListener("keydown",t),document.removeEventListener("keyup",e),this.container.removeEventListener("pointerdown",i),this.container.removeEventListener("pointerup",s),window.removeEventListener("resize",h),document.removeEventListener("visibilitychange",r),window.removeEventListener("blur",r),window.removeEventListener("focus",r)})}onKeyDown(t){if(t.metaKey||t.ctrlKey||t.altKey||(0,s.isTypingTarget)(t)||T(t)||!this.container.contains(document.activeElement))return;let e=" "===t.key||"ArrowUp"===t.key,i="ArrowDown"===t.key;(e||i)&&(t.preventDefault(),!this.crashed&&!this.paused&&(e?this.press():this.playing&&(this.trex.jumping?this.trex.setSpeedDrop():this.trex.ducking||this.trex.setDuck(!0))))}onKeyUp(t){if((0,s.isTypingTarget)(t)||T(t)||!this.container.contains(document.activeElement))return;let e=" "===t.key||"ArrowUp"===t.key,i="Enter"===t.key;if(this.playing&&!this.crashed&&e)this.trex.endJump();else if("ArrowDown"===t.key)this.trex.speedDrop=!1,this.trex.setDuck(!1);else if(this.crashed){let s=performance.now()-this.time;(i||e&&s>=1200)&&(t.preventDefault(),this.restart())}else this.paused&&e&&(this.trex.reset(),this.resume())}press(){!this.crashed&&(this.playing||(this.playing=!0,this.time=performance.now(),this.publish(),this.startLoop()),this.trex.jumping||this.trex.ducking||this.trex.startJump(this.currentSpeed))}release(){this.playing&&!this.crashed&&this.trex.endJump()}focus(){this.canvas.focus({preventScroll:!0})}duck(t){this.playing&&!this.crashed&&(t&&this.trex.jumping?this.trex.setSpeedDrop():this.trex.setDuck(t))}handleGameOverClick(t){let e=this.canvas.getBoundingClientRect(),i=t.clientX-e.left,s=t.clientY-e.top,h=this.gameOverPanel.getRestartBounds();i>=h.x&&i<=h.x+h.width&&s>=h.y&&s<=h.y+h.height&&this.restart()}playIntro(){this.activated||this.crashed||(this.playingIntro=!0,this.trex.playingIntro=!0,this.activated=!0,this.introAnimation=this.container.animate([{width:`${this.trex.config.width}px`},{width:`${this.width}px`}],{duration:400,easing:"ease-out",fill:"both"}),this.introAnimation.onfinish=()=>this.startGame())}startGame(){this.introAnimation?.cancel(),this.introAnimation=null,this.container.style.width=`${this.width}px`,this.runningTime=0,this.playingIntro=!1,this.trex.playingIntro=!1}clearCanvas(){this.ctx.clearRect(0,0,this.width,150)}
1startLoop(){this.rafId||(this.time=performance.now(),this.rafId=requestAnimationFrame(this.update))}update=()=>{this.rafId=0;let t=performance.now(),e=t-(this.time||t);if(this.time=t,this.playing){this.clearCanvas(),this.trex.jumping&&this.trex.updateJump(e),this.runningTime+=e;let t=this.runningTime>3e3;1!==this.trex.jumpCount||this.playingIntro||this.playIntro(),this.playingIntro?this.horizon.update(0,this.currentSpeed,t,!1):(e=this.activated?e:0,this.horizon.update(e,this.currentSpeed,t,this.inverted)),this.agent&&t&&this.agent.step(this,e);let i=this.horizon.obstacles[0];if(t&&i&&function(t,e){let i={x:e.xPos+1,y:e.yPos+1,width:e.config.width-2,height:e.config.height-2},s={x:t.xPos+1,y:t.yPos+1,width:t.typeConfig.width*t.size-2,height:t.typeConfig.height-2};if(!l(i,s))return!1;for(let h of e.getCollisionBoxes())for(let e of t.collisionBoxes)if(l(I(h,i),I(e,s)))return!0;return!1}(i,this.trex))this.gameOver();else{let t=e/this.msPerFrame;this.distanceRan+=this.currentSpeed*t,this.currentSpeed<13&&(this.currentSpeed=Math.min(13,this.currentSpeed+.001*t))}this.distanceMeter.update(e,Math.ceil(this.distanceRan)),this.updateNightMode(e)}(this.playing||!this.activated&&this.trex.blinkCount<3)&&(this.trex.update(e),this.rafId=requestAnimationFrame(this.update))};updateNightMode(t){if(this.invertTimer>12e3)this.invertTimer=0,this.invertTrigger=!1,this.setInverted(!1);else if(this.invertTimer)this.invertTimer+=t;else{let e=this.distanceMeter.getActualDistance(Math.ceil(this.distanceRan));e>0&&(this.invertTrigger=!(e%700),this.invertTrigger&&0===this.invertTimer&&(this.invertTimer+=t,this.setInverted(!0)))}}setInverted(t){this.inverted!==t&&(this.inverted=t,this.publish())}gameOver(){this.stop(),this.crashed=!0,this.distanceMeter.achievement=!1,this.trex.update(100,"CRASHED"),this.gameOverPanel.draw(),this.distanceRan>this.highestScore&&(this.highestScore=Math.ceil(this.distanceRan),this.distanceMeter.setHighScore(this.highestScore),this.saveHighScore()),this.time=performance.now(),this.publish(),this.agent?.onCrash(this)}stop(){this.playing=!1,this.paused=!0,cancelAnimationFrame(this.rafId),this.rafId=0}pause(){this.playing&&this.stop()}resume(){this.crashed||this.playing||!this.paused||(this.playing=!0,this.paused=!1,this.trex.update(0,"RUNNING"),this.time=performance.now(),this.publish(),this.startLoop())}restart(){this.rafId||(this.runningTime=0,this.playing=!0,this.paused=!1,this.crashed=!1,this.distanceRan=0,this.currentSpeed=6,this.time=performance.now(),this.clearCanvas(),this.distanceMeter.reset(),this.horizon.reset(),this.trex.reset(),this.setInverted(!1),this.invertTimer=0,this.invertTrigger=!1,this.gameOverPanel.reset(),this.agent?.reset(),this.publish(),this.startLoop())}get score(){return this.distanceMeter.getActualDistance(Math.ceil(this.distanceRan))}get obstacles(){return this.horizon.obstacles}loadHighScore(){let t=Number(localStorage.getItem(C));Number.isFinite(t)&&t>0&&(this.highestScore=t,this.distanceMeter.setHighScore(t))}saveHighScore(){try{localStorage.setItem(C,String(this.highestScore))}catch{}}publish(){this.options.onStatus({started:this.activated||this.playing,playing:this.playing,crashed:this.crashed,score:this.score,highScore:this.distanceMeter.getActualDistance(this.highestScore),inverted:this.inverted})}destroy(){for(let t of(this.stop(),this.gameOverPanel.reset(),this.detachers))t();this.detachers=[],this.container.remove()}}var F=t.i(16960),M=t.i(90233);let N=new Set([" ","ArrowUp","ArrowDown","Enter"]),A={started:!1,playing:!1,crashed:!1,score:0,highScore:0,inverted:!1};t.s(["DinoGame",0,function(){let t=(0,i.useRef)(null),r=(0,i.useRef)(null),n=(0,i.useRef)(null),o=(0,i.useRef)(null),c=(0,i.useRef)(null),d=(0,i.useRef)(0),[l,u]=(0,i.useState)(!1),[p,m]=(0,i.useState)(A),[g,x]=(0,i.useState)(!1),[y,f]=(0,i.useState)([]),w=(0,i.useRef)(!1),v=(0,i.useRef)("keyboard"),P=(0,i.useRef)(!1),S=(0,i.useRef)(!1),b=(0,i.useRef)(!1),k=(0,i.useCallback)((t,e)=>{("button"===e||"hotkey"===e)&&(b.current=!t),w.current!==t&&(w.current=t,x(t),(0,M.track)("dino_agent_toggled",{on:t,source:e}),t&&("button"===e||"hotkey"===e)&&(0,F.unlock)("agent"))},[]);(0,i.useEffect)(()=>{p.started!==P.current&&(P.current=p.started,p.started&&(0,M.track)("dino_started",{input:w.current?"agent":v.current}
1)),p.crashed!==S.current&&(S.current=p.crashed,p.crashed&&(0,M.track)("dino_crashed",{score:p.score,high_score:p.highScore,record:p.score>0&&p.score>=p.highScore}))},[p]),(0,i.useEffect)(()=>{(0,F.unlock)("dino")},[]),(0,i.useEffect)(()=>{let e,i,s,h=t.current;if(!h)return;let r=(e=window.devicePixelRatio>1,(i=new Image).src=e?"/dino/200-offline-sprite.png":"/dino/100-offline-sprite.png",s=i.decode?.().catch(()=>void 0)??new Promise(t=>{i.onload=()=>t(),i.onerror=()=>t()}),{image:i,hidpi:e,ready:s}),a=null,n=!1;return r.ready.then(()=>{n||(o.current=a=new j(h,{image:r.image,hidpi:r.hidpi,onStatus:m}),document.activeElement&&document.activeElement!==document.body||a.focus(),u(!0))}),()=>{n=!0,a?.destroy(),o.current=null}},[]);let I=(0,i.useCallback)(t=>{f(e=>[...e.slice(-3),{...t,id:(e[e.length-1]?.id??-1)+1}])},[]);return(0,i.useEffect)(()=>{let t=o.current;if(!t||!l)return;if(!g){c.current?.stop(),c.current=null,t.agent=null;return}let e=new a(I);return c.current=e,t.agent=e,e.start(),t.crashed?t.restart():t.playing||t.press(),()=>e.stop()},[g,I,l]),(0,i.useEffect)(()=>{d.current=performance.now();let t=t=>{(!(t instanceof KeyboardEvent)||N.has(t.key))&&(v.current=t instanceof KeyboardEvent?"keyboard":"pointer",d.current=performance.now(),k(!1,"play_input"))},e=window.matchMedia("(prefers-reduced-motion: reduce)"),i=setInterval(()=>{b.current||e.matches||performance.now()-d.current>=1e4&&k(!0,"idle_timeout")},1e3),s=r.current;return window.addEventListener("keydown",t),s?.addEventListener("pointerdown",t),()=>{clearInterval(i),window.removeEventListener("keydown",t),s?.removeEventListener("pointerdown",t)}},[k]),(0,i.useEffect)(()=>{function t(t){"a"!==t.key&&"A"!==t.key||t.metaKey||t.ctrlKey||t.altKey||(0,s.isTypingTarget)(t)||n.current?.contains(document.activeElement)&&(t.preventDefault(),k(!w.current,"hotkey"))}return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[k]),(0,e.jsxs)("div",{ref:n,className:"w-full max-w-[600px]",children:[(0,e.jsx)("div",{ref:r,style:{filter:p.inverted?"invert(1)":"none",transition:"filter 1s ease"},className:"relative h-[150px] w-full bg-dino-bg",children:(0,e.jsx)("div",{ref:t})}),(0,e.jsxs)("p",{"aria-live":"polite",className:"sr-only",children:["score ",p.score,", best ",p.highScore]}),(0,e.jsxs)("div",{className:"mt-3 flex flex-wrap items-baseline justify-between gap-x-4 gap-y-2",children:[(0,e.jsxs)("button",{onClick:()=>{d.current=performance.now(),k(!w.current,"button")},"aria-pressed":g,className:`inline-flex items-center gap-2 border px-2.5 py-1.5 font-bbmono text-[10px] whitespace-nowrap lowercase transition-colors ${g?"border-chrome-green/50 bg-chrome-green/8 text-chrome-green-ink":"border-chrome-edge text-chrome-dim hover:border-chrome-ink hover:text-chrome-ink"}`,children:[(0,e.jsx)("span",{className:`size-1.5 rounded-full ${g?"animate-pulse bg-chrome-green":"bg-chrome-mute"}`}),g?"stagehand is playing":"let stagehand play",(0,e.jsx)("span",{className:"text-chrome-dim",children:"[a]"})]}),(0,e.jsxs)("span",{className:`${h.mono} shrink-0 text-chrome-dim`,children:[(0,e.jsx)("span",{className:"not-hoverable:hidden",children:"space to jump · â to duck"}),(0,e.jsx)("span",{className:"hidden not-hoverable:inline",children:"tap to jump"})]})]}),(0,e.jsx)("div",{"aria-hidden":!g,className:"overflow-hidden transition-[height] duration-500 ease-out",style:{height:104*!!g},children:(0,e.jsx)("div",{className:"mt-3 overflow-hidden border border-chrome-edge bg-white px-3 py-2.5",style:{height:92},children:0===y.length?(0,e.jsxs)("p",{className:`${h.mono} text-chrome-mute`,children:["//"," waiting for the first obstacle"]}):(0,e.jsx)("ol",{className:"font-bbmono text-[11px] leading-[1.65]",children:y.map((t,i)=>(0,e.jsxs)("li",{className:`flex items-baseline gap-2 ${i===y.length-1?"text-chrome-ink":"text-chrome-mute"}`,children:[(0,e.jsx)("span",{className:"text-chrome-green-ink",children:"âº"}),(0,e.jsxs)("span",{className:"truncate",children:["stagehand.",(0,e.jsx)("span",{className:"text-chrome-green-ink",children:t.call})]}),(0,e.jsx)("span",{className:"ml-auto shrink-0 text-chrome-mute",children:t.meta})]},t.id))})})})]})}],4398)}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.