@joy-ride/game 0.28.0 → 0.29.1
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.
- package/README.md +1 -0
- package/bookmarklet.d.ts +1 -1
- package/bookmarklet.js +1 -1
- package/embed-chunks/{CodeBlock-ZJVQKkJK.js → CodeBlock-CmdFck30.js} +1 -1
- package/embed-chunks/{Documentation-C1avN9ar.js → Documentation-C5yd8S9T.js} +3 -3
- package/embed-chunks/{EmbedPanel-G7q47IIF.js → EmbedPanel-BDZ9gPAY.js} +1 -1
- package/embed-chunks/{JoyRideView-iI9D7qYG.js → JoyRideView-CGO2LlqF.js} +1 -1
- package/embed-chunks/{configuration~index~embed-yIM-mirE.js → configuration~index~embed-CRXVkf5S.js} +1 -1
- package/embed-chunks/configuration~index~embed~bookmarklet-6dUo7fKK.js +1 -0
- package/embed-chunks/configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~Documentation~JoyRideView~~n76yhyet-C39ouO-X.js +1 -0
- package/embed-chunks/{configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~JoyRideView~browser-sessio~iaaa3ndj-DuwqBPZc.js → configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~JoyRideView~browser-sessio~iaaa3ndj-DF2q8EGO.js} +1 -1
- package/embed-chunks/{runtime~JoyRideView~browser-session-core-D0evk3rV.js → runtime~JoyRideView~browser-session-core-W3T3KGBY.js} +1 -1
- package/embed-chunks/runtime~browser-session-core-ABdeer0k.js +1 -0
- package/embed-chunks/{runtime~index~embed-DRvLAw-Q.js → runtime~index~embed-Cdk1V9Yq.js} +2 -2
- package/embed-chunks/{runtime~index~embed~vehicle-popover~browser-session-core~renderer-7QR7zJ4G.js → runtime~index~embed~vehicle-popover~browser-session-core~renderer-DKaOSaI2.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover-B9yI0IDm.js → runtime~vehicle-popover-B9t-I45z.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover~browser-session-core-CG3br9PK.js → runtime~vehicle-popover~browser-session-core-hzAmTyN1.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover~browser-session-core~renderer-D9Tkkuld.js → runtime~vehicle-popover~browser-session-core~renderer-DRXQjSAc.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover~renderer-CucvcM5-.js → runtime~vehicle-popover~renderer-CFfqUX4J.js} +3 -3
- package/embed-chunks/{src-DpO0cT8m.js → src-v40jgxEo.js} +2 -2
- package/embed-chunks/{vehicle-catalog~index~embed-CP-EevYT.js → vehicle-catalog~index~embed-CkmzFsdm.js} +1 -1
- package/embed-chunks/{vehicle-popover-Dn9KYK8F.js → vehicle-popover-Cah1Jwwj.js} +1 -1
- package/embed.js +1 -1
- package/{index-CTJwxnBj.d.ts → index-Cr-53zu5.d.ts} +10 -9
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/npm-chunks/{Documentation-C0eIjv6u.js → Documentation-C8s_aL0s.js} +3 -3
- package/npm-chunks/{EmbedPanel-f5UGGrmb.js → EmbedPanel-a4F6OnOH.js} +1 -1
- package/npm-chunks/{JoyRideView-D5KwW5-l.js → JoyRideView-BAXi_AFI.js} +1 -1
- package/npm-chunks/VehicleHint-CS6L9FO9.js +1 -0
- package/npm-chunks/{configuration~react-DUPESsWt.js → configuration~react-B3URe5Hp.js} +1 -1
- package/npm-chunks/configuration~react~vehicle-popover~EmbedPanel~Documentation~JoyRideView~browser-session-co~fvauaeow-C39ouO-X.js +1 -0
- package/npm-chunks/{configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core-PAwcrwen.js → configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core-BLdLriTd.js} +1 -1
- package/npm-chunks/{configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core~renderer-DjaRQi9I.js → configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core~renderer-D5v3L-_1.js} +1 -1
- package/npm-chunks/configuration~react~vehicle-popover~JoyRideView~browser-session-core~renderer-BASSGxIF.js +1 -0
- package/npm-chunks/{runtime~JoyRideView~browser-session-core-CqexK4_9.js → runtime~JoyRideView~browser-session-core-7d-89abo.js} +1 -1
- package/npm-chunks/runtime~browser-session-core-CTEOkb8N.js +1 -0
- package/npm-chunks/{runtime~react-BiRrgv8z.js → runtime~react-DuHGu6qC.js} +1 -1
- package/npm-chunks/{runtime~react~browser-session-core-BwCcJzcZ.js → runtime~react~browser-session-core-BOMyEw_b.js} +1 -1
- package/npm-chunks/{runtime~react~vehicle-popover~browser-session-core~renderer-DKpExYhH.js → runtime~react~vehicle-popover~browser-session-core~renderer-5hzldoVR.js} +1 -1
- package/npm-chunks/{runtime~vehicle-popover-QsSxwpN_.js → runtime~vehicle-popover-DF_vkfqT.js} +1 -1
- package/npm-chunks/{runtime~vehicle-popover~browser-session-core-CrZME-1Y.js → runtime~vehicle-popover~browser-session-core-CDg6b0po.js} +1 -1
- package/npm-chunks/{runtime~vehicle-popover~browser-session-core~renderer-L2_7uaz1.js → runtime~vehicle-popover~browser-session-core~renderer-D_NBXTcG.js} +1 -1
- package/npm-chunks/{runtime~vehicle-popover~renderer-4k-iW9CG.js → runtime~vehicle-popover~renderer-C7Eq6aHr.js} +3 -3
- package/npm-chunks/{sync-shadow-theme-BfMjtxaN.js → sync-shadow-theme-CTVN45GY.js} +1 -1
- package/npm-chunks/{theme-DdVUqUf4.js → theme-CkSpDTIL.js} +1 -1
- package/npm-chunks/{vehicle-catalog~react~browser-session-core-Ck9lXSBn.js → vehicle-catalog~react~browser-session-core-CxP3HQ_B.js} +1 -1
- package/npm-chunks/{vehicle-popover-CVncA-Cd.js → vehicle-popover-CYhUl7Ae.js} +1 -1
- package/package.json +1 -1
- package/{playground-CSIrDKFk.d.ts → playground-C1crX0w5.d.ts} +4 -8
- package/react.d.ts +7 -5
- package/react.js +10 -10
- package/embed-chunks/configuration~index~embed~bookmarklet-D5yd-nGZ.js +0 -1
- package/embed-chunks/configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~Documentation~JoyRideView~~n76yhyet-CxkUNnei.js +0 -1
- package/embed-chunks/runtime~browser-session-core-Coi2m2K_.js +0 -1
- package/npm-chunks/VehicleHint-YUZ0kRNw.js +0 -1
- package/npm-chunks/configuration~react~vehicle-popover~EmbedPanel~Documentation~JoyRideView~browser-session-co~fvauaeow-CxkUNnei.js +0 -1
- package/npm-chunks/configuration~react~vehicle-popover~JoyRideView~browser-session-core~renderer-BwD100vD.js +0 -1
- package/npm-chunks/runtime~browser-session-core-CnigdG4N.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-XKyaHtl9.js";import{a as t,c as n,i as r,l as i,o as a,r as o,s,u as c}from"./definitions~index~embed~bookmarklet~vehicle-popover~Documentation~JoyRideView~browser-sessi~fklztn3g-BG7sJuWo.js";import{r as l,t as u}from"./definitions~index~embed~vehicle-popover~browser-session-core~renderer-RDNEXk_b.js";import{S as d,_ as f,a as p,c as m,g as h,i as g,l as _,m as v,n as y,o as b,s as x,u as S,x as C}from"./runtime~index~embed~vehicle-popover~browser-session-core~renderer-7QR7zJ4G.js";import{a as w}from"./configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~Documentation~JoyRideView~~n76yhyet-CxkUNnei.js";import{n as ee,t as te}from"./configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~JoyRideView~browser-sessio~iaaa3ndj-DuwqBPZc.js";import{l as T,n as E}from"./configuration~index~embed~bookmarklet-D5yd-nGZ.js";import{E as ne,M as D,S as re,d as ie,f as ae,h as oe,j as se,l as ce,m as O,n as le,o as ue,p as de,t as fe,u as pe,x as me}from"./runtime~vehicle-popover~browser-session-core~renderer-D9Tkkuld.js";import{r as he}from"./controls~index~embed~vehicle-popover~JoyRideView~browser-session-core~renderer-Cnf30Q_A.js";var k=[`low`,`medium`,`high`],ge=1e3/60,_e=2e3,ve=8,ye=2e3,be=1e4,xe=12e4,Se=5e3,Ce=class{cap=k.length-1;misses=[];lastTime=null;lastChange=-1/0;lastStepUp=-1/0;stepUpDelay=be;get limit(){return k[this.cap]}apply(e){return k[Math.min(k.indexOf(e),this.cap)]}sample(e,t,n,r){let i=this.lastTime;if(this.lastTime=e,i===null)return!1;let a=e-i;if(!(a>0)||a>250)return!1;for(a>ge*1.5&&t<ge*.8&&n&&this.misses.push(e);this.misses.length&&e-this.misses[0]>_e;)this.misses.shift();if(e-this.lastChange<ye)return!1;let o=k.indexOf(r);return this.misses.length>=ve&&Math.min(this.cap,o)>0?(e-this.lastStepUp<Se&&(this.stepUpDelay=Math.min(xe,this.stepUpDelay*2)),this.cap=Math.min(this.cap,o)-1,this.changed(e),!0):n&&this.cap<o&&!this.misses.length&&e-this.lastChange>=this.stepUpDelay?(this.cap++,this.lastStepUp=e,this.changed(e),!0):!1}restoreLimit(e){this.cap=e?Math.max(0,k.indexOf(e)):k.length-1,this.misses=[],this.lastTime=null}reset(){this.cap=k.length-1,this.misses=[],this.lastTime=null,this.lastChange=this.lastStepUp=-1/0,this.stepUpDelay=be}changed(e){this.lastChange=e,this.misses=[]}};function we(e,t,n){let r=e.size,i=r*.74,a=0,o=0,s=0;for(let c=0;c<6;c++){let l=t*(c+.5)/6*2,u=n*(c+.5)/6*2,d=e.curlX*l*l*l+e.twist*n*2*l*l,f=e.curlY*u*u*u-e.twist*t*1.3*u*u;a+=Math.cos(d)*r*t/6,o+=Math.cos(f)*i*n/6,s+=Math.sin(d)*r*t/6+Math.sin(f)*i*n/6}let c=Math.max(0,t+n-.62);s+=c*c*r*(.35+e.fold);let l=Math.cos(e.tilt),u=Math.sin(e.tilt);return{x:a,y:o*l-s*u,z:o*u+s*l}}var Te=(e,t)=>{let n=Math.imul((e|0)&15^Math.imul(t+17,374761393),668265263);return n=Math.imul(n^n>>>13,1274126177),((n^n>>>16)>>>0)/4294967296},Ee=new Map,De=new Map;function Oe(e){let t=Ee.get(e);if(t)return t;let n=e.replace(/^#/,``),r=/^[\da-f]{3}$/i.test(n)?[...n].map(e=>e+e).join(``):n,i=/^[\da-f]{6}$/i.test(r)?[0,2,4].map(e=>parseInt(r.slice(e,e+2),16)):e.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/)?.slice(1,4).map(Number)??[195,190,174];return Ee.size>=128&&Ee.delete(Ee.keys().next().value),Ee.set(e,i),i}function ke(e,t){let n=Math.round(t),r=`${e}:${n}`,i=De.get(r);if(i)return i;let a=`rgb(${Oe(e).map(e=>Math.max(0,Math.min(255,e+n))).join(` `)})`;return De.size>=512&&De.delete(De.keys().next().value),De.set(r,a),a}function Ae(e,t){e.beginPath(),t.forEach(([t,n],r)=>{r?e.lineTo(t,n):e.moveTo(t,n)}),e.closePath()}function je(e,t,n){let r=Math.max(0,t.z),i=1+Math.min(.65,r/90);e.save(),e.translate(t.x+r*.13,t.y+r*.1),e.rotate(t.angle),e.fillStyle=`#000`,e.globalAlpha=t.opacity*(n?.12:.15)/(1+r/26),e.beginPath(),e.ellipse(0,0,t.size*.46*i,t.size*.27*i,0,0,Math.PI*2),e.fill(),r<5&&(e.globalAlpha*=(1-r/5)*.6,e.beginPath(),e.ellipse(0,0,t.size*.36,t.size*.19,0,0,Math.PI*2),e.fill()),e.restore()}function Me(e,t){let n=[];for(let e=0;e<=2;e++)n.push(Array.from({length:9},(n,r)=>we(t,r/8-.5,e/2-.5)));let r=t.z<.5?Math.max(0,-Math.min(...n.flat().map(e=>e.z))):0,i=e=>[e.x,e.y-(e.z+r)*.48],a=[];for(let e=0;e<2;e++)for(let t=0;t<8;t++){let r=n[e][t],i=n[e][t+1],o=n[e+1][t+1],s=n[e+1][t],c=i.x-r.x,l=i.y-r.y,u=i.z-r.z,d=s.x-r.x,f=s.y-r.y,p=s.z-r.z,m=l*p-u*f,h=u*d-c*p,g=c*f-l*d,_=Math.max(.001,Math.hypot(m,h,g)),v=g+h*.48>0,y=(m*-.35+h*-.45+Math.abs(g)*.7)/_;a.push({a:r,b:i,c:o,d:s,col:t,row:e,front:v,light:y,depth:(r.z+i.z+o.z+s.z)/4})}a.sort((e,t)=>e.depth-t.depth);for(let n of a){let{a:r,b:a,c:o,d:s,front:c,light:l,row:u,col:d}=n;if(Ae(e,[i(r),i(a),i(o),i(s)]),e.fillStyle=ke(t.color,(c?0:-32)+(l-.7)*45),e.fill(),c&&d>0&&d<(u===0?6:8)&&u<3){e.strokeStyle=ke(t.color,-100),e.lineWidth=t.size*(u===0?.027:.013);let n=i({x:(r.x+s.x)*.5,y:(r.y+s.y)*.5,z:(r.z+s.z)*.5}),c=i({x:(a.x+o.x)*.5,y:(a.y+o.y)*.5,z:(a.z+o.z)*.5});if(e.beginPath(),e.moveTo(...n),e.lineTo(...c),e.stroke(),u>0){let t=i({x:r.x*.2+s.x*.8,y:r.y*.2+s.y*.8,z:r.z*.2+s.z*.8}),n=i({x:a.x*.2+o.x*.8,y:a.y*.2+o.y*.8,z:a.z*.2+o.z*.8});e.beginPath(),e.moveTo(...t),e.lineTo(...n),e.stroke()}}}}function Ne(e,t){let n=t.size,r=t.size*(.35+Te(t.seed,61)*.2),i=Math.cos(t.tilt);if(e.scale(1,Math.abs(i)<.08?.08:i),e.beginPath(),e.moveTo(-n*.48,0),e.bezierCurveTo(-n*.15,-r*.7,n*.18,-r*.6,n*.5,-r*.08),e.bezierCurveTo(n*.12,r*.65,-n*.25,r*.45,-n*.48,0),e.fillStyle=ke(t.color,i<0?14:0),e.fill(),e.beginPath(),e.moveTo(-n*.48,0),e.bezierCurveTo(-n*.15,-r*.7,n*.18,-r*.6,n*.5,-r*.08),e.quadraticCurveTo(0,-r*t.fold*.2,-n*.48,0),e.fillStyle=ke(t.color,-13-t.fold*9),e.fill(),e.strokeStyle=ke(t.color,-35),e.lineWidth=.45,e.globalAlpha*=.55,e.beginPath(),e.moveTo(-n*.63,r*.08),e.quadraticCurveTo(-n*.08,-r*t.fold*.2,n*.46,-r*.07),e.stroke(),n>10){e.lineWidth=.3;for(let t of[-.18,.08])e.beginPath(),e.moveTo(n*t,0),e.lineTo(n*(t+.1),-r*.3),e.moveTo(n*t,0),e.lineTo(n*(t-.03),r*.28),e.stroke()}}var A=new Map,Pe=0,Fe=0,Ie=()=>({sprites:A.size,bytes:Pe});function Le(e,t){t.kind===`paper`?Me(e,t):t.kind===`leaf`&&Ne(e,t)}function Re(e){if(typeof OffscreenCanvas<`u`)return new OffscreenCanvas(e,e);if(typeof document>`u`||typeof HTMLCanvasElement>`u`)return null;let t=document.createElement(`canvas`);return!(t instanceof HTMLCanvasElement)||!t.getContext?null:(t.width=t.height=e,t)}function ze(e,t,n){if(t.z>.1||Math.abs(t.vz)>.1||Math.hypot(t.vx,t.vy)>.75||t.kind===`paper`&&Math.abs(t.curlVelocityX)+Math.abs(t.curlVelocityY)+Math.abs(t.twistVelocity)>.03)return!1;let r=Math.max(4,Math.round(t.size/4)*4),i=Math.round(t.fold*5)/5,a=Math.cos(t.tilt)<0?4:0,o=a*Math.PI/4;if(Math.abs(Math.sin(t.tilt))>.015)return!1;let s=Math.round(t.curlX*4)/4,c=Math.round(t.curlY*4)/4,l=Math.round(t.twist*4)/4,u=`${s}:${c}:${l}:${t.kind}:${t.seed&15}:${t.color}:${r}:${i}:${a}:${n}`,d=A.get(u),f={...t,size:r,fold:i,tilt:o,curlX:s,curlY:c,twist:l,opacity:1};if(!d){let e=r*1.4+4,t=Math.ceil(e*n),i=t*t*4;if(A.size>=128||Pe+i>8388608){for(let[e,t]of A)if(!(Fe-t.used<120)&&(A.delete(e),`close`in t.canvas&&t.canvas.close(),Pe-=t.bytes,A.size<128&&Pe+i<=8388608))break}if(A.size<128&&Pe+i<=8388608){let r=Re(t),a=r?.getContext(`2d`);r&&a&&(a.scale(n,n),a.translate(e/2,e/2),Le(a,f),d={canvas:`transferToImageBitmap`in r?r.transferToImageBitmap():r,extent:e,bytes:i,used:Fe},A.set(u,d),Pe+=i)}}return e.scale(t.size/r,t.size/r),d?(d.used=Fe,e.drawImage(d.canvas,-d.extent/2,-d.extent/2,d.extent,d.extent)):(e.save(),Le(e,f),e.restore()),!0}function Be(e,t,n,r,i=`ground`){i===`ground`&&Fe++;let a=e.getTransform(),o=Math.min(8,Math.max(1,Math.ceil(Math.hypot(a.a,a.b)))),s=n.x+n.width,c=n.y+n.height;for(let a of t){if(a.opacity<=0)continue;let t=a.size+Math.max(0,a.z)*.35;a.x+t<n.x||a.x-t>s||a.y+t<n.y||a.y-t>c||(i===`ground`&&je(e,a,r),i===`ground`==a.z<4&&(e.save(),e.translate(a.x,a.y-Math.max(0,a.z)*.22),e.rotate(a.angle),e.globalAlpha=a.opacity,ze(e,a,o)||Le(e,a),e.restore()))}}function Ve(e){if(e.exhaust.outlets)return e.exhaust.outlets.map(e=>({...e}));let t=e.geometry.lengthM*(e.image?.scale??1),n=e.geometry.widthM*.3,r=e.exhaust.layout;return(r===`left-right`?[-n,n]:r===`left`?[-n]:r===`right`?[n]:[0]).map(e=>({xM:-t/2-.025,yM:e}))}function He(e){let{tireLengthM:t,tireWidthM:n}=e.geometry;return e.image?{length:t*(e.image.wheelVisualScale?.length??.64),width:n*(e.image.wheelVisualScale?.width??.82)}:{length:t,width:n}}function Ue(e,t,n,r,i){let a=D(t,e.naturalWidth,e.naturalHeight),o=Math.min(1,512/Math.max(a.source.width,a.source.height)),s=document.createElement(`canvas`);s.width=Math.max(1,Math.round(a.source.width*o)),s.height=Math.max(1,Math.round(a.source.height*o));let c=s.getContext(`2d`);if(!c)return null;n?c.drawImage(n,0,0,s.width,s.height):c.drawImage(e,a.source.x,a.source.y,a.source.width,a.source.height,0,0,s.width,s.height),c.globalCompositeOperation=`source-in`,c.fillStyle=`#101916`,c.fillRect(0,0,s.width,s.height);let l=`filter`in c,u=e=>{let t=Math.ceil(e*4),n=a.lengthM*r,o=a.widthM*r,c=document.createElement(`canvas`);c.width=Math.max(1,Math.ceil((n+t*2)*i)),c.height=Math.max(1,Math.ceil((o+t*2)*i));let u=c.getContext(`2d`);if(!u)return null;let d=c.width*2;return l?u.filter=`blur(${e*i}px)`:(u.shadowColor=`#101916`,u.shadowBlur=e*i*2,u.shadowOffsetX=d),u.drawImage(s,t*i-(l?0:d),t*i,n*i,o*i),{canvas:c,padding:t}};return{soft:u(6),close:u(1.5),pixelsPerMeter:r,lengthM:a.lengthM,widthM:a.widthM}}var We={width:56,height:56},Ge=8,Ke=10,qe=6;function Je(e,t,n=Ge){let{width:r,height:i}=We,a=r/2,o=i/2,s=e.x-t.width/2,c=e.y-t.height/2,l=Math.hypot(s,c)||1,u={x:s/l,y:c/l},d=Math.max(0,t.width/2-a-Ke-Ge),f=Math.max(0,t.height/2-o-Ke-(c<0?n:Ge)),p=Math.min(Math.abs(s)?d/Math.abs(s):1/0,Math.abs(c)?f/Math.abs(c):1/0),m={x:t.width/2+s*(Number.isFinite(p)?p:0),y:t.height/2+c*(Number.isFinite(p)?p:0)},h={x:u.x*a,y:u.y*o},g={x:h.x+u.x*Ke,y:h.y+u.y*Ke},_=Math.sqrt((r/2)**2-qe**2),v={x:u.x*_,y:u.y*_};return{center:m,direction:u,edge:h,tip:g,left:{x:v.x-u.y*qe,y:v.y+u.x*qe},right:{x:v.x+u.y*qe,y:v.y-u.x*qe},width:r,height:i}}var Ye=5120,Xe=5121,Ze=5122,Qe=5123,$e=5124,et=5125,tt=5126,nt=32819,rt=32820,it=33635,at=5131,ot=33640,st=35899,ct=35902,lt=36269,ut=34042,dt={};{let e=dt;e[Ye]=Int8Array,e[Xe]=Uint8Array,e[Ze]=Int16Array,e[Qe]=Uint16Array,e[$e]=Int32Array,e[et]=Uint32Array,e[tt]=Float32Array,e[nt]=Uint16Array,e[rt]=Uint16Array,e[it]=Uint16Array,e[at]=Uint16Array,e[ot]=Uint32Array,e[st]=Uint32Array,e[ct]=Uint32Array,e[lt]=Uint32Array,e[ut]=Uint32Array}function ft(...e){console.error(...e)}var pt=new Map;function mt(e,t){if(!e||typeof e!=`object`)return!1;let n=pt.get(t);n||(n=new WeakMap,pt.set(t,n));let r=n.get(e);if(r===void 0){let i=Object.prototype.toString.call(e);r=i.substring(8,i.length-1)===t,n.set(e,r)}return r}function ht(e,t){return typeof WebGLBuffer<`u`&&mt(t,`WebGLBuffer`)}function gt(e,t){return typeof WebGLTexture<`u`&&mt(t,`WebGLTexture`)}function _t(e,t){return typeof WebGLSampler<`u`&&mt(t,`WebGLSampler`)}var vt=35044,yt=34962;function bt(e,t,n,r,i){e.bindBuffer(t,n),e.bufferData(t,r,i||vt)}function xt(e,t,n,r){if(ht(e,t))return t;n||=yt;let i=e.createBuffer();return bt(e,n,i,t,r),i}function St(e){return!!e.texStorage2D}var Ct=function(){let e={},t={};function n(n){let r=n.constructor.name;if(!e[r]){for(let e in n)if(typeof n[e]==`number`){let r=t[n[e]];t[n[e]]=r?`${r} | ${e}`:e}e[r]=!0}}return function(e,r){return n(e),t[r]||(typeof r==`number`?`0x${r.toString(16)}`:r)}}();new Uint8Array([128,192,255,255]);var wt=6406,j=6407,M=6408,Tt=6409,Et=6410,Dt=6402,Ot=34041,kt=3553,At=34067,jt=32879,Mt=35866,Nt=34069,Pt=10241,Ft=10240,It=10242,Lt=10243,Rt=32882,zt=33082,Bt=33083,Vt=33084,Ht=33085,Ut=34892,Wt=34893,Gt=37443,Kt=37441,qt=37440,Jt=33321,Yt=36756,Xt=33325,Zt=33326,Qt=33330,$t=33329,en=33338,tn=33337,nn=33340,rn=33339,an=33323,on=36757,sn=33327,cn=33328,ln=33336,un=33335,dn=33332,fn=33331,pn=33334,mn=33333,hn=32849,gn=35905,_n=36194,vn=36758,yn=35898,bn=35901,xn=34843,Sn=34837,Cn=36221,wn=36239,Tn=36215,En=36233,Dn=36209,On=36227,kn=32856,An=35907,jn=36759,Mn=32855,Nn=32854,Pn=32857,Fn=34842,In=34836,Ln=36220,Rn=36238,zn=36975,Bn=36214,Vn=36232,Hn=36226,Un=36208,Wn=33189,Gn=33190,Kn=36012,qn=36013,Jn=35056,N=5120,P=5121,Yn=5122,Xn=5123,Zn=5124,Qn=5125,F=5126,$n=32819,er=32820,tr=33635,I=5131,nr=36193,rr=33640,ir=35899,ar=35902,or=36269,sr=34042,cr=33319,lr=33320,ur=6403,dr=36244,fr=36248,L=36249,pr=33776,mr=33777,hr=33778,gr=33779,_r=35916,vr=35917,yr=35918,br=35919,xr=36196,Sr=37488,Cr=37489,wr=37490,Tr=37491,Er=37492,Dr=37493,Or=37494,kr=37495,Ar=37496,jr=37497,Mr=35840,Nr=35841,Pr=35842,Fr=35843,Ir=37808,Lr=37809,Rr=37810,zr=37811,Br=37812,Vr=37813,Hr=37814,Ur=37815,Wr=37816,Gr=37817,Kr=37818,qr=37819,Jr=37820,Yr=37821,Xr=37840,Zr=37841,Qr=37842,$r=37843,ei=37844,ti=37845,ni=37846,ri=37847,ii=37848,ai=37849,oi=37850,si=37851,ci=37852,li=37853,ui=36492,di=36493,fi=36494,pi=36495,mi=36283,hi=36284,gi=36285,_i=36286,vi={};{let e=vi;e[wt]={numColorComponents:1},e[Tt]={numColorComponents:1},e[Et]={numColorComponents:2},e[j]={numColorComponents:3},e[M]={numColorComponents:4},e[ur]={numColorComponents:1},e[dr]={numColorComponents:1},e[cr]={numColorComponents:2},e[lr]={numColorComponents:2},e[j]={numColorComponents:3},e[fr]={numColorComponents:3},e[M]={numColorComponents:4},e[L]={numColorComponents:4},e[Dt]={numColorComponents:1},e[Ot]={numColorComponents:2}}var yi;function bi(e){if(!yi){let e={};e[wt]={textureFormat:wt,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[P,I,nr,F]},e[Tt]={textureFormat:Tt,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[P,I,nr,F]},e[Et]={textureFormat:Et,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2,4,4,8],type:[P,I,nr,F]},e[j]={textureFormat:j,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,6,6,12,2],type:[P,I,nr,F,tr]},e[M]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,8,8,16,2,2],type:[P,I,nr,F,$n,er]},e[Dt]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[Qn,Xn]},e[Jt]={textureFormat:ur,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1],type:[P]},e[Yt]={textureFormat:ur,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[1],type:[N]},e[Xt]={textureFormat:ur,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4,2],type:[F,I]},e[Zt]={textureFormat:ur,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[4],type:[F]},e[Qt]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[P]},e[$t]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[N]},e[dn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[Xn]},e[fn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[Yn]},e[pn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Qn]},e[mn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Zn]},e[an]={textureFormat:cr,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2],type:[P]},e[on]={textureFormat:cr,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[2],type:[N]},e[sn]={textureFormat:cr,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[8,4],type:[F,I]},e[cn]={textureFormat:cr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[8],type:[F]},e[ln]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[P]},e[un]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[N]},e[en]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Xn]},e[tn]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Yn]},e[nn]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Qn]},e[rn]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Zn]},e[hn]={textureFormat:j,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3],type:[P]},e[gn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[P]},e[_n]={textureFormat:j,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,2],type:[P,tr]},e[vn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[N]},e[yn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[F,I,ir]},e[bn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[F,I,ar]},e[xn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6],type:[F,I]},e[Sn]={textureFormat:j,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[F]},e[Cn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[P]},e[wn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[N]},e[Tn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[Xn]},e[En]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[Yn]},e[Dn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[Qn]},e[On]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[Zn]},e[kn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[P]},e[An]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[P]},e[jn]={textureFormat:M,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4],type:[N]},e[Mn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2,4],type:[P,er,rr]},e[Nn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2],type:[P,$n]},e[Pn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[rr]},e[Fn]={textureFormat:M,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[16,8],type:[F,I]},e[In]={textureFormat:M,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[16],type:[F]},e[Ln]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[P]},e[Rn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[N]},e[zn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[rr]},e[Bn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Xn]},e[Vn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Yn]},e[Hn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[Zn]},e[Un]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[Qn]},e[Wn]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[Xn,Qn]},e[Gn]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Qn]},e[Kn]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[F]},e[Jn]={textureFormat:Ot,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[sr]},e[qn]={textureFormat:Ot,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[or]},Object.keys(e).forEach(function(t){let n=e[t];n.bytesPerElementMap={},n.bytesPerElement.forEach(function(e,t){let r=n.type[t];n.bytesPerElementMap[r]=e})});let t={bytes:8,width:4,height:4},n={bytes:16,width:4,height:4};e[pr]={textureFormat:pr,colorRenderable:!1,textureFilterable:!0,block:t},e[mr]={textureFormat:mr,colorRenderable:!1,textureFilterable:!0,block:t},e[hr]={textureFormat:hr,colorRenderable:!1,textureFilterable:!0,block:n},e[gr]={textureFormat:gr,colorRenderable:!1,textureFilterable:!0,block:n},e[_r]={textureFormat:_r,colorRenderable:!1,textureFilterable:!0,block:t},e[vr]={textureFormat:vr,colorRenderable:!1,textureFilterable:!0,block:t},e[yr]={textureFormat:yr,colorRenderable:!1,textureFilterable:!0,block:n},e[br]={textureFormat:br,colorRenderable:!1,textureFilterable:!0,block:n},e[xr]={textureFormat:xr,colorRenderable:!1,textureFilterable:!0,block:t},e[Sr]={textureFormat:Sr,colorRenderable:!1,textureFilterable:!0,block:t},e[Cr]={textureFormat:Cr,colorRenderable:!1,textureFilterable:!0,block:t},e[wr]={textureFormat:wr,colorRenderable:!1,textureFilterable:!0,block:n},e[Tr]={textureFormat:Tr,colorRenderable:!1,textureFilterable:!0,block:n},e[Er]={textureFormat:Er,colorRenderable:!1,textureFilterable:!0,block:t},e[Dr]={textureFormat:Dr,colorRenderable:!1,textureFilterable:!0,block:t},e[Or]={textureFormat:Or,colorRenderable:!1,textureFilterable:!0,block:t},e[kr]={textureFormat:kr,colorRenderable:!1,textureFilterable:!0,block:t},e[Ar]={textureFormat:Ar,colorRenderable:!1,textureFilterable:!0,block:n},e[jr]={textureFormat:jr,colorRenderable:!1,textureFilterable:!0,block:n},e[Mr]={textureFormat:Mr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:8,height:8}},e[Nr]={textureFormat:Nr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:16,height:8}},e[Pr]={textureFormat:Pr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:8,height:8}},e[Fr]={textureFormat:Fr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:16,height:8}},e[Ir]={textureFormat:Ir,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:4,height:4}},e[Lr]={textureFormat:Lr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:4}},e[Rr]={textureFormat:Rr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:5}},e[zr]={textureFormat:zr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:5}},e[Br]={textureFormat:Br,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:6}},e[Vr]={textureFormat:Vr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:5}},e[Hr]={textureFormat:Hr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:6}},e[Ur]={textureFormat:Ur,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:8}},e[Wr]={textureFormat:Wr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:5}},e[Gr]={textureFormat:Gr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:6}},e[Kr]={textureFormat:Kr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:8}},e[qr]={textureFormat:qr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:10}},e[Jr]={textureFormat:Jr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:10}},e[Yr]={textureFormat:Yr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:12}},e[Xr]={textureFormat:Xr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:4,height:4}},e[Zr]={textureFormat:Zr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:4}},e[Qr]={textureFormat:Qr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:5}},e[$r]={textureFormat:$r,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:5}},e[ei]={textureFormat:ei,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:6}},e[ti]={textureFormat:ti,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:5}},e[ni]={textureFormat:ni,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:6}},e[ri]={textureFormat:ri,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:8}},e[ii]={textureFormat:ii,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:5}},e[ai]={textureFormat:ai,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:6}},e[oi]={textureFormat:oi,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:8}},e[si]={textureFormat:si,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:10}},e[ci]={textureFormat:ci,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:10}},e[li]={textureFormat:li,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:12}},e[ui]={textureFormat:ui,colorRenderable:!1,textureFilterable:!0,block:n},e[di]={textureFormat:di,colorRenderable:!1,textureFilterable:!0,block:n},e[fi]={textureFormat:fi,colorRenderable:!1,textureFilterable:!0,block:n},e[pi]={textureFormat:pi,colorRenderable:!1,textureFilterable:!0,block:n},e[mi]={textureFormat:mi,colorRenderable:!1,textureFilterable:!0,block:t},e[hi]={textureFormat:hi,colorRenderable:!1,textureFilterable:!0,block:t},e[gi]={textureFormat:gi,colorRenderable:!1,textureFilterable:!0,block:t},e[_i]={textureFormat:_i,colorRenderable:!1,textureFilterable:!0,block:t},yi=e}let t=yi[e];if(!t)throw Error(`unknown internal format`);return t}function xi(e){let t=bi(e);if(!t)throw Error(`unknown internal format`);return{format:t.textureFormat,type:t.type?.[0]??P}}function Si(e,t,n){let r,i,a;t.colorspaceConversion!==void 0&&(r=e.getParameter(Gt),e.pixelStorei(Gt,t.colorspaceConversion)),t.premultiplyAlpha!==void 0&&(i=e.getParameter(Kt),e.pixelStorei(Kt,t.premultiplyAlpha)),t.flipY!==void 0&&(a=e.getParameter(qt),e.pixelStorei(qt,t.flipY)),n(),r!==void 0&&e.pixelStorei(Gt,r),i!==void 0&&e.pixelStorei(Kt,i),a!==void 0&&e.pixelStorei(qt,a)}function Ci(e,t,n,r){r.minMag&&(n.call(e,t,Pt,r.minMag),n.call(e,t,Ft,r.minMag)),r.min&&n.call(e,t,Pt,r.min),r.mag&&n.call(e,t,Ft,r.mag),r.wrap&&(n.call(e,t,It,r.wrap),n.call(e,t,Lt,r.wrap),(t===jt||_t(e,t))&&n.call(e,t,Rt,r.wrap)),r.wrapR&&n.call(e,t,Rt,r.wrapR),r.wrapS&&n.call(e,t,It,r.wrapS),r.wrapT&&n.call(e,t,Lt,r.wrapT),r.minLod!==void 0&&n.call(e,t,zt,r.minLod),r.maxLod!==void 0&&n.call(e,t,Bt,r.maxLod),r.baseLevel!==void 0&&n.call(e,t,Vt,r.baseLevel),r.maxLevel!==void 0&&n.call(e,t,Ht,r.maxLevel),r.compareFunc!==void 0&&n.call(e,t,Wt,r.compareFunc),r.compareMode!==void 0&&n.call(e,t,Ut,r.compareMode)}function wi(e,t,n){let r=n.target||kt;e.bindTexture(r,t),Ci(e,r,e.texParameteri,n)}function Ti(e,t,n){let r=n.target||kt;e.bindTexture(r,t);let i=n.level||0,a=n.internalFormat||n.format||M,o=xi(a),s=n.format||o.format,c=n.type||o.type;Si(e,n,()=>{if(r===At)for(let t=0;t<6;++t)e.texImage2D(Nt+t,i,a,n.width,n.height,0,s,c,null);else r===jt||r===Mt?e.texImage3D(r,i,a,n.width,n.height,n.depth,0,s,c,null):e.texImage2D(r,i,a,n.width,n.height,0,s,c,null)})}var Ei=ft;function Di(e){return typeof document<`u`&&document.getElementById?document.getElementById(e):null}var Oi=33984,ki=34962,Ai=34963,ji=35713,Mi=35714,Ni=35632,Pi=35633,Fi=35981,Ii=35718,Li=35721,Ri=35971,zi=35382,Bi=35396,Vi=35398,Hi=35392,Ui=35395,Wi=5126,Gi=35664,Ki=35665,qi=35666,Ji=5124,Yi=35667,Xi=35668,Zi=35669,Qi=35670,$i=35671,ea=35672,ta=35673,na=35674,ra=35675,ia=35676,aa=35678,oa=35680,sa=35679,ca=35682,la=35685,ua=35686,da=35687,fa=35688,pa=35689,ma=35690,ha=36289,ga=36292,_a=36293,va=5125,ya=36294,ba=36295,xa=36296,Sa=36298,Ca=36299,wa=36300,Ta=36303,Ea=36306,Da=36307,Oa=36308,ka=36311,Aa=3553,ja=34067,Ma=32879,Na=35866,R={};function Pa(e,t){return R[t].bindPoint}function Fa(e,t){return function(n){e.uniform1f(t,n)}}function Ia(e,t){return function(n){e.uniform1fv(t,n)}}function La(e,t){return function(n){e.uniform2fv(t,n)}}function Ra(e,t){return function(n){e.uniform3fv(t,n)}}function za(e,t){return function(n){e.uniform4fv(t,n)}}function Ba(e,t){return function(n){e.uniform1i(t,n)}}function Va(e,t){return function(n){e.uniform1iv(t,n)}}function Ha(e,t){return function(n){e.uniform2iv(t,n)}}function Ua(e,t){return function(n){e.uniform3iv(t,n)}}function Wa(e,t){return function(n){e.uniform4iv(t,n)}}function Ga(e,t){return function(n){e.uniform1ui(t,n)}}function Ka(e,t){return function(n){e.uniform1uiv(t,n)}}function qa(e,t){return function(n){e.uniform2uiv(t,n)}}function Ja(e,t){return function(n){e.uniform3uiv(t,n)}}function Ya(e,t){return function(n){e.uniform4uiv(t,n)}}function Xa(e,t){return function(n){e.uniformMatrix2fv(t,!1,n)}}function Za(e,t){return function(n){e.uniformMatrix3fv(t,!1,n)}}function Qa(e,t){return function(n){e.uniformMatrix4fv(t,!1,n)}}function $a(e,t){return function(n){e.uniformMatrix2x3fv(t,!1,n)}}function eo(e,t){return function(n){e.uniformMatrix3x2fv(t,!1,n)}}function to(e,t){return function(n){e.uniformMatrix2x4fv(t,!1,n)}}function no(e,t){return function(n){e.uniformMatrix4x2fv(t,!1,n)}}function ro(e,t){return function(n){e.uniformMatrix3x4fv(t,!1,n)}}function io(e,t){return function(n){e.uniformMatrix4x3fv(t,!1,n)}}function z(e,t,n,r){let i=Pa(e,t);return St(e)?function(t){let a,o;!t||gt(e,t)?(a=t,o=null):(a=t.texture,o=t.sampler),e.uniform1i(r,n),e.activeTexture(Oi+n),e.bindTexture(i,a),e.bindSampler(n,o)}:function(t){e.uniform1i(r,n),e.activeTexture(Oi+n),e.bindTexture(i,t)}}function B(e,t,n,r,i){let a=Pa(e,t),o=new Int32Array(i);for(let e=0;e<i;++e)o[e]=n+e;return St(e)?function(t){e.uniform1iv(r,o),t.forEach(function(t,r){e.activeTexture(Oi+o[r]);let i,s;!t||gt(e,t)?(i=t,s=null):(i=t.texture,s=t.sampler),e.bindSampler(n,s),e.bindTexture(a,i)})}:function(t){e.uniform1iv(r,o),t.forEach(function(t,n){e.activeTexture(Oi+o[n]),e.bindTexture(a,t)})}}R[Wi]={Type:Float32Array,size:4,setter:Fa,arraySetter:Ia},R[Gi]={Type:Float32Array,size:8,setter:La,cols:2},R[Ki]={Type:Float32Array,size:12,setter:Ra,cols:3},R[qi]={Type:Float32Array,size:16,setter:za,cols:4},R[Ji]={Type:Int32Array,size:4,setter:Ba,arraySetter:Va},R[Yi]={Type:Int32Array,size:8,setter:Ha,cols:2},R[Xi]={Type:Int32Array,size:12,setter:Ua,cols:3},R[Zi]={Type:Int32Array,size:16,setter:Wa,cols:4},R[va]={Type:Uint32Array,size:4,setter:Ga,arraySetter:Ka},R[ya]={Type:Uint32Array,size:8,setter:qa,cols:2},R[ba]={Type:Uint32Array,size:12,setter:Ja,cols:3},R[xa]={Type:Uint32Array,size:16,setter:Ya,cols:4},R[Qi]={Type:Uint32Array,size:4,setter:Ba,arraySetter:Va},R[$i]={Type:Uint32Array,size:8,setter:Ha,cols:2},R[ea]={Type:Uint32Array,size:12,setter:Ua,cols:3},R[ta]={Type:Uint32Array,size:16,setter:Wa,cols:4},R[na]={Type:Float32Array,size:32,setter:Xa,rows:2,cols:2},R[ra]={Type:Float32Array,size:48,setter:Za,rows:3,cols:3},R[ia]={Type:Float32Array,size:64,setter:Qa,rows:4,cols:4},R[la]={Type:Float32Array,size:32,setter:$a,rows:2,cols:3},R[ua]={Type:Float32Array,size:32,setter:to,rows:2,cols:4},R[da]={Type:Float32Array,size:48,setter:eo,rows:3,cols:2},R[fa]={Type:Float32Array,size:48,setter:ro,rows:3,cols:4},R[pa]={Type:Float32Array,size:64,setter:no,rows:4,cols:2},R[ma]={Type:Float32Array,size:64,setter:io,rows:4,cols:3},R[aa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[oa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[sa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Ma},R[ca]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[ha]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na},R[ga]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na},R[_a]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[Sa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[Ca]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Ma},R[wa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[Ta]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na},R[Ea]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[Da]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Ma},R[Oa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[ka]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na};function ao(e,t){return function(n){if(n.value)switch(e.disableVertexAttribArray(t),n.value.length){case 4:e.vertexAttrib4fv(t,n.value);break;case 3:e.vertexAttrib3fv(t,n.value);break;case 2:e.vertexAttrib2fv(t,n.value);break;case 1:e.vertexAttrib1fv(t,n.value);break;default:throw Error(`the length of a float constant value must be between 1 and 4!`)}else e.bindBuffer(ki,n.buffer),e.enableVertexAttribArray(t),e.vertexAttribPointer(t,n.numComponents||n.size,n.type||Wi,n.normalize||!1,n.stride||0,n.offset||0),e.vertexAttribDivisor&&e.vertexAttribDivisor(t,n.divisor||0)}}function V(e,t){return function(n){if(n.value){if(e.disableVertexAttribArray(t),n.value.length===4)e.vertexAttrib4iv(t,n.value);else throw Error(`The length of an integer constant value must be 4!`)}else e.bindBuffer(ki,n.buffer),e.enableVertexAttribArray(t),e.vertexAttribIPointer(t,n.numComponents||n.size,n.type||Ji,n.stride||0,n.offset||0),e.vertexAttribDivisor&&e.vertexAttribDivisor(t,n.divisor||0)}}function oo(e,t){return function(n){if(n.value){if(e.disableVertexAttribArray(t),n.value.length===4)e.vertexAttrib4uiv(t,n.value);else throw Error(`The length of an unsigned integer constant value must be 4!`)}else e.bindBuffer(ki,n.buffer),e.enableVertexAttribArray(t),e.vertexAttribIPointer(t,n.numComponents||n.size,n.type||va,n.stride||0,n.offset||0),e.vertexAttribDivisor&&e.vertexAttribDivisor(t,n.divisor||0)}}function so(e,t,n){let r=n.size,i=n.count;return function(n){e.bindBuffer(ki,n.buffer);let a=n.size||n.numComponents||r,o=a/i,s=n.type||Wi,c=R[s].size*a,l=n.normalize||!1,u=n.offset||0,d=c/i;for(let r=0;r<i;++r)e.enableVertexAttribArray(t+r),e.vertexAttribPointer(t+r,o,s,l,c,u+d*r),e.vertexAttribDivisor&&e.vertexAttribDivisor(t+r,n.divisor||0)}}var H={};H[Wi]={size:4,setter:ao},H[Gi]={size:8,setter:ao},H[Ki]={size:12,setter:ao},H[qi]={size:16,setter:ao},H[Ji]={size:4,setter:V},H[Yi]={size:8,setter:V},H[Xi]={size:12,setter:V},H[Zi]={size:16,setter:V},H[va]={size:4,setter:oo},H[ya]={size:8,setter:oo},H[ba]={size:12,setter:oo},H[xa]={size:16,setter:oo},H[Qi]={size:4,setter:V},H[$i]={size:8,setter:V},H[ea]={size:12,setter:V},H[ta]={size:16,setter:V},H[na]={size:4,setter:so,count:2},H[ra]={size:9,setter:so,count:3},H[ia]={size:16,setter:so,count:4};var co=/ERROR:\s*\d+:(\d+)/gi;function lo(e,t=``,n=0){let r=[...t.matchAll(co)],i=new Map(r.map((e,n)=>{let i=parseInt(e[1]),a=r[n+1],o=a?a.index:t.length,s=t.substring(e.index,o);return[i-1,s]}));return e.split(`
|
|
1
|
+
import{n as e}from"./rolldown-runtime-XKyaHtl9.js";import{a as t,c as n,i as r,l as i,o as a,r as o,s,u as c}from"./definitions~index~embed~bookmarklet~vehicle-popover~Documentation~JoyRideView~browser-sessi~fklztn3g-BG7sJuWo.js";import{r as l,t as u}from"./definitions~index~embed~vehicle-popover~browser-session-core~renderer-RDNEXk_b.js";import{S as d,_ as f,a as p,c as m,g as h,i as g,l as _,m as v,n as y,o as b,s as x,u as S,x as C}from"./runtime~index~embed~vehicle-popover~browser-session-core~renderer-DKaOSaI2.js";import{a as w}from"./configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~Documentation~JoyRideView~~n76yhyet-C39ouO-X.js";import{n as ee,t as te}from"./configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~JoyRideView~browser-sessio~iaaa3ndj-DF2q8EGO.js";import{l as T,n as E}from"./configuration~index~embed~bookmarklet-6dUo7fKK.js";import{E as ne,M as D,S as re,d as ie,f as ae,h as oe,j as se,l as ce,m as O,n as le,o as ue,p as de,t as fe,u as pe,x as me}from"./runtime~vehicle-popover~browser-session-core~renderer-DRXQjSAc.js";import{r as he}from"./controls~index~embed~vehicle-popover~JoyRideView~browser-session-core~renderer-Cnf30Q_A.js";var k=[`low`,`medium`,`high`],ge=1e3/60,_e=2e3,ve=8,ye=2e3,be=1e4,xe=12e4,Se=5e3,Ce=class{cap=k.length-1;misses=[];lastTime=null;lastChange=-1/0;lastStepUp=-1/0;stepUpDelay=be;get limit(){return k[this.cap]}apply(e){return k[Math.min(k.indexOf(e),this.cap)]}sample(e,t,n,r){let i=this.lastTime;if(this.lastTime=e,i===null)return!1;let a=e-i;if(!(a>0)||a>250)return!1;for(a>ge*1.5&&t<ge*.8&&n&&this.misses.push(e);this.misses.length&&e-this.misses[0]>_e;)this.misses.shift();if(e-this.lastChange<ye)return!1;let o=k.indexOf(r);return this.misses.length>=ve&&Math.min(this.cap,o)>0?(e-this.lastStepUp<Se&&(this.stepUpDelay=Math.min(xe,this.stepUpDelay*2)),this.cap=Math.min(this.cap,o)-1,this.changed(e),!0):n&&this.cap<o&&!this.misses.length&&e-this.lastChange>=this.stepUpDelay?(this.cap++,this.lastStepUp=e,this.changed(e),!0):!1}restoreLimit(e){this.cap=e?Math.max(0,k.indexOf(e)):k.length-1,this.misses=[],this.lastTime=null}reset(){this.cap=k.length-1,this.misses=[],this.lastTime=null,this.lastChange=this.lastStepUp=-1/0,this.stepUpDelay=be}changed(e){this.lastChange=e,this.misses=[]}};function we(e,t,n){let r=e.size,i=r*.74,a=0,o=0,s=0;for(let c=0;c<6;c++){let l=t*(c+.5)/6*2,u=n*(c+.5)/6*2,d=e.curlX*l*l*l+e.twist*n*2*l*l,f=e.curlY*u*u*u-e.twist*t*1.3*u*u;a+=Math.cos(d)*r*t/6,o+=Math.cos(f)*i*n/6,s+=Math.sin(d)*r*t/6+Math.sin(f)*i*n/6}let c=Math.max(0,t+n-.62);s+=c*c*r*(.35+e.fold);let l=Math.cos(e.tilt),u=Math.sin(e.tilt);return{x:a,y:o*l-s*u,z:o*u+s*l}}var Te=(e,t)=>{let n=Math.imul((e|0)&15^Math.imul(t+17,374761393),668265263);return n=Math.imul(n^n>>>13,1274126177),((n^n>>>16)>>>0)/4294967296},Ee=new Map,De=new Map;function Oe(e){let t=Ee.get(e);if(t)return t;let n=e.replace(/^#/,``),r=/^[\da-f]{3}$/i.test(n)?[...n].map(e=>e+e).join(``):n,i=/^[\da-f]{6}$/i.test(r)?[0,2,4].map(e=>parseInt(r.slice(e,e+2),16)):e.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/)?.slice(1,4).map(Number)??[195,190,174];return Ee.size>=128&&Ee.delete(Ee.keys().next().value),Ee.set(e,i),i}function ke(e,t){let n=Math.round(t),r=`${e}:${n}`,i=De.get(r);if(i)return i;let a=`rgb(${Oe(e).map(e=>Math.max(0,Math.min(255,e+n))).join(` `)})`;return De.size>=512&&De.delete(De.keys().next().value),De.set(r,a),a}function Ae(e,t){e.beginPath(),t.forEach(([t,n],r)=>{r?e.lineTo(t,n):e.moveTo(t,n)}),e.closePath()}function je(e,t,n){let r=Math.max(0,t.z),i=1+Math.min(.65,r/90);e.save(),e.translate(t.x+r*.13,t.y+r*.1),e.rotate(t.angle),e.fillStyle=`#000`,e.globalAlpha=t.opacity*(n?.12:.15)/(1+r/26),e.beginPath(),e.ellipse(0,0,t.size*.46*i,t.size*.27*i,0,0,Math.PI*2),e.fill(),r<5&&(e.globalAlpha*=(1-r/5)*.6,e.beginPath(),e.ellipse(0,0,t.size*.36,t.size*.19,0,0,Math.PI*2),e.fill()),e.restore()}function Me(e,t){let n=[];for(let e=0;e<=2;e++)n.push(Array.from({length:9},(n,r)=>we(t,r/8-.5,e/2-.5)));let r=t.z<.5?Math.max(0,-Math.min(...n.flat().map(e=>e.z))):0,i=e=>[e.x,e.y-(e.z+r)*.48],a=[];for(let e=0;e<2;e++)for(let t=0;t<8;t++){let r=n[e][t],i=n[e][t+1],o=n[e+1][t+1],s=n[e+1][t],c=i.x-r.x,l=i.y-r.y,u=i.z-r.z,d=s.x-r.x,f=s.y-r.y,p=s.z-r.z,m=l*p-u*f,h=u*d-c*p,g=c*f-l*d,_=Math.max(.001,Math.hypot(m,h,g)),v=g+h*.48>0,y=(m*-.35+h*-.45+Math.abs(g)*.7)/_;a.push({a:r,b:i,c:o,d:s,col:t,row:e,front:v,light:y,depth:(r.z+i.z+o.z+s.z)/4})}a.sort((e,t)=>e.depth-t.depth);for(let n of a){let{a:r,b:a,c:o,d:s,front:c,light:l,row:u,col:d}=n;if(Ae(e,[i(r),i(a),i(o),i(s)]),e.fillStyle=ke(t.color,(c?0:-32)+(l-.7)*45),e.fill(),c&&d>0&&d<(u===0?6:8)&&u<3){e.strokeStyle=ke(t.color,-100),e.lineWidth=t.size*(u===0?.027:.013);let n=i({x:(r.x+s.x)*.5,y:(r.y+s.y)*.5,z:(r.z+s.z)*.5}),c=i({x:(a.x+o.x)*.5,y:(a.y+o.y)*.5,z:(a.z+o.z)*.5});if(e.beginPath(),e.moveTo(...n),e.lineTo(...c),e.stroke(),u>0){let t=i({x:r.x*.2+s.x*.8,y:r.y*.2+s.y*.8,z:r.z*.2+s.z*.8}),n=i({x:a.x*.2+o.x*.8,y:a.y*.2+o.y*.8,z:a.z*.2+o.z*.8});e.beginPath(),e.moveTo(...t),e.lineTo(...n),e.stroke()}}}}function Ne(e,t){let n=t.size,r=t.size*(.35+Te(t.seed,61)*.2),i=Math.cos(t.tilt);if(e.scale(1,Math.abs(i)<.08?.08:i),e.beginPath(),e.moveTo(-n*.48,0),e.bezierCurveTo(-n*.15,-r*.7,n*.18,-r*.6,n*.5,-r*.08),e.bezierCurveTo(n*.12,r*.65,-n*.25,r*.45,-n*.48,0),e.fillStyle=ke(t.color,i<0?14:0),e.fill(),e.beginPath(),e.moveTo(-n*.48,0),e.bezierCurveTo(-n*.15,-r*.7,n*.18,-r*.6,n*.5,-r*.08),e.quadraticCurveTo(0,-r*t.fold*.2,-n*.48,0),e.fillStyle=ke(t.color,-13-t.fold*9),e.fill(),e.strokeStyle=ke(t.color,-35),e.lineWidth=.45,e.globalAlpha*=.55,e.beginPath(),e.moveTo(-n*.63,r*.08),e.quadraticCurveTo(-n*.08,-r*t.fold*.2,n*.46,-r*.07),e.stroke(),n>10){e.lineWidth=.3;for(let t of[-.18,.08])e.beginPath(),e.moveTo(n*t,0),e.lineTo(n*(t+.1),-r*.3),e.moveTo(n*t,0),e.lineTo(n*(t-.03),r*.28),e.stroke()}}var A=new Map,Pe=0,Fe=0,Ie=()=>({sprites:A.size,bytes:Pe});function Le(e,t){t.kind===`paper`?Me(e,t):t.kind===`leaf`&&Ne(e,t)}function Re(e){if(typeof OffscreenCanvas<`u`)return new OffscreenCanvas(e,e);if(typeof document>`u`||typeof HTMLCanvasElement>`u`)return null;let t=document.createElement(`canvas`);return!(t instanceof HTMLCanvasElement)||!t.getContext?null:(t.width=t.height=e,t)}function ze(e,t,n){if(t.z>.1||Math.abs(t.vz)>.1||Math.hypot(t.vx,t.vy)>.75||t.kind===`paper`&&Math.abs(t.curlVelocityX)+Math.abs(t.curlVelocityY)+Math.abs(t.twistVelocity)>.03)return!1;let r=Math.max(4,Math.round(t.size/4)*4),i=Math.round(t.fold*5)/5,a=Math.cos(t.tilt)<0?4:0,o=a*Math.PI/4;if(Math.abs(Math.sin(t.tilt))>.015)return!1;let s=Math.round(t.curlX*4)/4,c=Math.round(t.curlY*4)/4,l=Math.round(t.twist*4)/4,u=`${s}:${c}:${l}:${t.kind}:${t.seed&15}:${t.color}:${r}:${i}:${a}:${n}`,d=A.get(u),f={...t,size:r,fold:i,tilt:o,curlX:s,curlY:c,twist:l,opacity:1};if(!d){let e=r*1.4+4,t=Math.ceil(e*n),i=t*t*4;if(A.size>=128||Pe+i>8388608){for(let[e,t]of A)if(!(Fe-t.used<120)&&(A.delete(e),`close`in t.canvas&&t.canvas.close(),Pe-=t.bytes,A.size<128&&Pe+i<=8388608))break}if(A.size<128&&Pe+i<=8388608){let r=Re(t),a=r?.getContext(`2d`);r&&a&&(a.scale(n,n),a.translate(e/2,e/2),Le(a,f),d={canvas:`transferToImageBitmap`in r?r.transferToImageBitmap():r,extent:e,bytes:i,used:Fe},A.set(u,d),Pe+=i)}}return e.scale(t.size/r,t.size/r),d?(d.used=Fe,e.drawImage(d.canvas,-d.extent/2,-d.extent/2,d.extent,d.extent)):(e.save(),Le(e,f),e.restore()),!0}function Be(e,t,n,r,i=`ground`){i===`ground`&&Fe++;let a=e.getTransform(),o=Math.min(8,Math.max(1,Math.ceil(Math.hypot(a.a,a.b)))),s=n.x+n.width,c=n.y+n.height;for(let a of t){if(a.opacity<=0)continue;let t=a.size+Math.max(0,a.z)*.35;a.x+t<n.x||a.x-t>s||a.y+t<n.y||a.y-t>c||(i===`ground`&&je(e,a,r),i===`ground`==a.z<4&&(e.save(),e.translate(a.x,a.y-Math.max(0,a.z)*.22),e.rotate(a.angle),e.globalAlpha=a.opacity,ze(e,a,o)||Le(e,a),e.restore()))}}function Ve(e){if(e.exhaust.outlets)return e.exhaust.outlets.map(e=>({...e}));let t=e.geometry.lengthM*(e.image?.scale??1),n=e.geometry.widthM*.3,r=e.exhaust.layout;return(r===`left-right`?[-n,n]:r===`left`?[-n]:r===`right`?[n]:[0]).map(e=>({xM:-t/2-.025,yM:e}))}function He(e){let{tireLengthM:t,tireWidthM:n}=e.geometry;return e.image?{length:t*(e.image.wheelVisualScale?.length??.64),width:n*(e.image.wheelVisualScale?.width??.82)}:{length:t,width:n}}function Ue(e,t,n,r,i){let a=D(t,e.naturalWidth,e.naturalHeight),o=Math.min(1,512/Math.max(a.source.width,a.source.height)),s=document.createElement(`canvas`);s.width=Math.max(1,Math.round(a.source.width*o)),s.height=Math.max(1,Math.round(a.source.height*o));let c=s.getContext(`2d`);if(!c)return null;n?c.drawImage(n,0,0,s.width,s.height):c.drawImage(e,a.source.x,a.source.y,a.source.width,a.source.height,0,0,s.width,s.height),c.globalCompositeOperation=`source-in`,c.fillStyle=`#101916`,c.fillRect(0,0,s.width,s.height);let l=`filter`in c,u=e=>{let t=Math.ceil(e*4),n=a.lengthM*r,o=a.widthM*r,c=document.createElement(`canvas`);c.width=Math.max(1,Math.ceil((n+t*2)*i)),c.height=Math.max(1,Math.ceil((o+t*2)*i));let u=c.getContext(`2d`);if(!u)return null;let d=c.width*2;return l?u.filter=`blur(${e*i}px)`:(u.shadowColor=`#101916`,u.shadowBlur=e*i*2,u.shadowOffsetX=d),u.drawImage(s,t*i-(l?0:d),t*i,n*i,o*i),{canvas:c,padding:t}};return{soft:u(6),close:u(1.5),pixelsPerMeter:r,lengthM:a.lengthM,widthM:a.widthM}}var We={width:56,height:56},Ge=8,Ke=10,qe=6;function Je(e,t,n=Ge){let{width:r,height:i}=We,a=r/2,o=i/2,s=e.x-t.width/2,c=e.y-t.height/2,l=Math.hypot(s,c)||1,u={x:s/l,y:c/l},d=Math.max(0,t.width/2-a-Ke-Ge),f=Math.max(0,t.height/2-o-Ke-(c<0?n:Ge)),p=Math.min(Math.abs(s)?d/Math.abs(s):1/0,Math.abs(c)?f/Math.abs(c):1/0),m={x:t.width/2+s*(Number.isFinite(p)?p:0),y:t.height/2+c*(Number.isFinite(p)?p:0)},h={x:u.x*a,y:u.y*o},g={x:h.x+u.x*Ke,y:h.y+u.y*Ke},_=Math.sqrt((r/2)**2-qe**2),v={x:u.x*_,y:u.y*_};return{center:m,direction:u,edge:h,tip:g,left:{x:v.x-u.y*qe,y:v.y+u.x*qe},right:{x:v.x+u.y*qe,y:v.y-u.x*qe},width:r,height:i}}var Ye=5120,Xe=5121,Ze=5122,Qe=5123,$e=5124,et=5125,tt=5126,nt=32819,rt=32820,it=33635,at=5131,ot=33640,st=35899,ct=35902,lt=36269,ut=34042,dt={};{let e=dt;e[Ye]=Int8Array,e[Xe]=Uint8Array,e[Ze]=Int16Array,e[Qe]=Uint16Array,e[$e]=Int32Array,e[et]=Uint32Array,e[tt]=Float32Array,e[nt]=Uint16Array,e[rt]=Uint16Array,e[it]=Uint16Array,e[at]=Uint16Array,e[ot]=Uint32Array,e[st]=Uint32Array,e[ct]=Uint32Array,e[lt]=Uint32Array,e[ut]=Uint32Array}function ft(...e){console.error(...e)}var pt=new Map;function mt(e,t){if(!e||typeof e!=`object`)return!1;let n=pt.get(t);n||(n=new WeakMap,pt.set(t,n));let r=n.get(e);if(r===void 0){let i=Object.prototype.toString.call(e);r=i.substring(8,i.length-1)===t,n.set(e,r)}return r}function ht(e,t){return typeof WebGLBuffer<`u`&&mt(t,`WebGLBuffer`)}function gt(e,t){return typeof WebGLTexture<`u`&&mt(t,`WebGLTexture`)}function _t(e,t){return typeof WebGLSampler<`u`&&mt(t,`WebGLSampler`)}var vt=35044,yt=34962;function bt(e,t,n,r,i){e.bindBuffer(t,n),e.bufferData(t,r,i||vt)}function xt(e,t,n,r){if(ht(e,t))return t;n||=yt;let i=e.createBuffer();return bt(e,n,i,t,r),i}function St(e){return!!e.texStorage2D}var Ct=function(){let e={},t={};function n(n){let r=n.constructor.name;if(!e[r]){for(let e in n)if(typeof n[e]==`number`){let r=t[n[e]];t[n[e]]=r?`${r} | ${e}`:e}e[r]=!0}}return function(e,r){return n(e),t[r]||(typeof r==`number`?`0x${r.toString(16)}`:r)}}();new Uint8Array([128,192,255,255]);var wt=6406,j=6407,M=6408,Tt=6409,Et=6410,Dt=6402,Ot=34041,kt=3553,At=34067,jt=32879,Mt=35866,Nt=34069,Pt=10241,Ft=10240,It=10242,Lt=10243,Rt=32882,zt=33082,Bt=33083,Vt=33084,Ht=33085,Ut=34892,Wt=34893,Gt=37443,Kt=37441,qt=37440,Jt=33321,Yt=36756,Xt=33325,Zt=33326,Qt=33330,$t=33329,en=33338,tn=33337,nn=33340,rn=33339,an=33323,on=36757,sn=33327,cn=33328,ln=33336,un=33335,dn=33332,fn=33331,pn=33334,mn=33333,hn=32849,gn=35905,_n=36194,vn=36758,yn=35898,bn=35901,xn=34843,Sn=34837,Cn=36221,wn=36239,Tn=36215,En=36233,Dn=36209,On=36227,kn=32856,An=35907,jn=36759,Mn=32855,Nn=32854,Pn=32857,Fn=34842,In=34836,Ln=36220,Rn=36238,zn=36975,Bn=36214,Vn=36232,Hn=36226,Un=36208,Wn=33189,Gn=33190,Kn=36012,qn=36013,Jn=35056,N=5120,P=5121,Yn=5122,Xn=5123,Zn=5124,Qn=5125,F=5126,$n=32819,er=32820,tr=33635,I=5131,nr=36193,rr=33640,ir=35899,ar=35902,or=36269,sr=34042,cr=33319,lr=33320,ur=6403,dr=36244,fr=36248,L=36249,pr=33776,mr=33777,hr=33778,gr=33779,_r=35916,vr=35917,yr=35918,br=35919,xr=36196,Sr=37488,Cr=37489,wr=37490,Tr=37491,Er=37492,Dr=37493,Or=37494,kr=37495,Ar=37496,jr=37497,Mr=35840,Nr=35841,Pr=35842,Fr=35843,Ir=37808,Lr=37809,Rr=37810,zr=37811,Br=37812,Vr=37813,Hr=37814,Ur=37815,Wr=37816,Gr=37817,Kr=37818,qr=37819,Jr=37820,Yr=37821,Xr=37840,Zr=37841,Qr=37842,$r=37843,ei=37844,ti=37845,ni=37846,ri=37847,ii=37848,ai=37849,oi=37850,si=37851,ci=37852,li=37853,ui=36492,di=36493,fi=36494,pi=36495,mi=36283,hi=36284,gi=36285,_i=36286,vi={};{let e=vi;e[wt]={numColorComponents:1},e[Tt]={numColorComponents:1},e[Et]={numColorComponents:2},e[j]={numColorComponents:3},e[M]={numColorComponents:4},e[ur]={numColorComponents:1},e[dr]={numColorComponents:1},e[cr]={numColorComponents:2},e[lr]={numColorComponents:2},e[j]={numColorComponents:3},e[fr]={numColorComponents:3},e[M]={numColorComponents:4},e[L]={numColorComponents:4},e[Dt]={numColorComponents:1},e[Ot]={numColorComponents:2}}var yi;function bi(e){if(!yi){let e={};e[wt]={textureFormat:wt,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[P,I,nr,F]},e[Tt]={textureFormat:Tt,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[P,I,nr,F]},e[Et]={textureFormat:Et,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2,4,4,8],type:[P,I,nr,F]},e[j]={textureFormat:j,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,6,6,12,2],type:[P,I,nr,F,tr]},e[M]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,8,8,16,2,2],type:[P,I,nr,F,$n,er]},e[Dt]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[Qn,Xn]},e[Jt]={textureFormat:ur,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1],type:[P]},e[Yt]={textureFormat:ur,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[1],type:[N]},e[Xt]={textureFormat:ur,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4,2],type:[F,I]},e[Zt]={textureFormat:ur,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[4],type:[F]},e[Qt]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[P]},e[$t]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[N]},e[dn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[Xn]},e[fn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[Yn]},e[pn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Qn]},e[mn]={textureFormat:dr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Zn]},e[an]={textureFormat:cr,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2],type:[P]},e[on]={textureFormat:cr,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[2],type:[N]},e[sn]={textureFormat:cr,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[8,4],type:[F,I]},e[cn]={textureFormat:cr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[8],type:[F]},e[ln]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[P]},e[un]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[N]},e[en]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Xn]},e[tn]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Yn]},e[nn]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Qn]},e[rn]={textureFormat:lr,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Zn]},e[hn]={textureFormat:j,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3],type:[P]},e[gn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[P]},e[_n]={textureFormat:j,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,2],type:[P,tr]},e[vn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[N]},e[yn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[F,I,ir]},e[bn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[F,I,ar]},e[xn]={textureFormat:j,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6],type:[F,I]},e[Sn]={textureFormat:j,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[F]},e[Cn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[P]},e[wn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[N]},e[Tn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[Xn]},e[En]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[Yn]},e[Dn]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[Qn]},e[On]={textureFormat:fr,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[Zn]},e[kn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[P]},e[An]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[P]},e[jn]={textureFormat:M,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4],type:[N]},e[Mn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2,4],type:[P,er,rr]},e[Nn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2],type:[P,$n]},e[Pn]={textureFormat:M,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[rr]},e[Fn]={textureFormat:M,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[16,8],type:[F,I]},e[In]={textureFormat:M,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[16],type:[F]},e[Ln]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[P]},e[Rn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[N]},e[zn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[rr]},e[Bn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Xn]},e[Vn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Yn]},e[Hn]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[Zn]},e[Un]={textureFormat:L,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[Qn]},e[Wn]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[Xn,Qn]},e[Gn]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Qn]},e[Kn]={textureFormat:Dt,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[F]},e[Jn]={textureFormat:Ot,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[sr]},e[qn]={textureFormat:Ot,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[or]},Object.keys(e).forEach(function(t){let n=e[t];n.bytesPerElementMap={},n.bytesPerElement.forEach(function(e,t){let r=n.type[t];n.bytesPerElementMap[r]=e})});let t={bytes:8,width:4,height:4},n={bytes:16,width:4,height:4};e[pr]={textureFormat:pr,colorRenderable:!1,textureFilterable:!0,block:t},e[mr]={textureFormat:mr,colorRenderable:!1,textureFilterable:!0,block:t},e[hr]={textureFormat:hr,colorRenderable:!1,textureFilterable:!0,block:n},e[gr]={textureFormat:gr,colorRenderable:!1,textureFilterable:!0,block:n},e[_r]={textureFormat:_r,colorRenderable:!1,textureFilterable:!0,block:t},e[vr]={textureFormat:vr,colorRenderable:!1,textureFilterable:!0,block:t},e[yr]={textureFormat:yr,colorRenderable:!1,textureFilterable:!0,block:n},e[br]={textureFormat:br,colorRenderable:!1,textureFilterable:!0,block:n},e[xr]={textureFormat:xr,colorRenderable:!1,textureFilterable:!0,block:t},e[Sr]={textureFormat:Sr,colorRenderable:!1,textureFilterable:!0,block:t},e[Cr]={textureFormat:Cr,colorRenderable:!1,textureFilterable:!0,block:t},e[wr]={textureFormat:wr,colorRenderable:!1,textureFilterable:!0,block:n},e[Tr]={textureFormat:Tr,colorRenderable:!1,textureFilterable:!0,block:n},e[Er]={textureFormat:Er,colorRenderable:!1,textureFilterable:!0,block:t},e[Dr]={textureFormat:Dr,colorRenderable:!1,textureFilterable:!0,block:t},e[Or]={textureFormat:Or,colorRenderable:!1,textureFilterable:!0,block:t},e[kr]={textureFormat:kr,colorRenderable:!1,textureFilterable:!0,block:t},e[Ar]={textureFormat:Ar,colorRenderable:!1,textureFilterable:!0,block:n},e[jr]={textureFormat:jr,colorRenderable:!1,textureFilterable:!0,block:n},e[Mr]={textureFormat:Mr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:8,height:8}},e[Nr]={textureFormat:Nr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:16,height:8}},e[Pr]={textureFormat:Pr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:8,height:8}},e[Fr]={textureFormat:Fr,colorRenderable:!1,textureFilterable:!0,block:{bytes:32,width:16,height:8}},e[Ir]={textureFormat:Ir,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:4,height:4}},e[Lr]={textureFormat:Lr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:4}},e[Rr]={textureFormat:Rr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:5}},e[zr]={textureFormat:zr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:5}},e[Br]={textureFormat:Br,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:6}},e[Vr]={textureFormat:Vr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:5}},e[Hr]={textureFormat:Hr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:6}},e[Ur]={textureFormat:Ur,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:8}},e[Wr]={textureFormat:Wr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:5}},e[Gr]={textureFormat:Gr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:6}},e[Kr]={textureFormat:Kr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:8}},e[qr]={textureFormat:qr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:10}},e[Jr]={textureFormat:Jr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:10}},e[Yr]={textureFormat:Yr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:12}},e[Xr]={textureFormat:Xr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:4,height:4}},e[Zr]={textureFormat:Zr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:4}},e[Qr]={textureFormat:Qr,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:5,height:5}},e[$r]={textureFormat:$r,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:5}},e[ei]={textureFormat:ei,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:6,height:6}},e[ti]={textureFormat:ti,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:5}},e[ni]={textureFormat:ni,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:6}},e[ri]={textureFormat:ri,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:8,height:8}},e[ii]={textureFormat:ii,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:5}},e[ai]={textureFormat:ai,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:6}},e[oi]={textureFormat:oi,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:8}},e[si]={textureFormat:si,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:10,height:10}},e[ci]={textureFormat:ci,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:10}},e[li]={textureFormat:li,colorRenderable:!1,textureFilterable:!0,block:{bytes:16,width:12,height:12}},e[ui]={textureFormat:ui,colorRenderable:!1,textureFilterable:!0,block:n},e[di]={textureFormat:di,colorRenderable:!1,textureFilterable:!0,block:n},e[fi]={textureFormat:fi,colorRenderable:!1,textureFilterable:!0,block:n},e[pi]={textureFormat:pi,colorRenderable:!1,textureFilterable:!0,block:n},e[mi]={textureFormat:mi,colorRenderable:!1,textureFilterable:!0,block:t},e[hi]={textureFormat:hi,colorRenderable:!1,textureFilterable:!0,block:t},e[gi]={textureFormat:gi,colorRenderable:!1,textureFilterable:!0,block:t},e[_i]={textureFormat:_i,colorRenderable:!1,textureFilterable:!0,block:t},yi=e}let t=yi[e];if(!t)throw Error(`unknown internal format`);return t}function xi(e){let t=bi(e);if(!t)throw Error(`unknown internal format`);return{format:t.textureFormat,type:t.type?.[0]??P}}function Si(e,t,n){let r,i,a;t.colorspaceConversion!==void 0&&(r=e.getParameter(Gt),e.pixelStorei(Gt,t.colorspaceConversion)),t.premultiplyAlpha!==void 0&&(i=e.getParameter(Kt),e.pixelStorei(Kt,t.premultiplyAlpha)),t.flipY!==void 0&&(a=e.getParameter(qt),e.pixelStorei(qt,t.flipY)),n(),r!==void 0&&e.pixelStorei(Gt,r),i!==void 0&&e.pixelStorei(Kt,i),a!==void 0&&e.pixelStorei(qt,a)}function Ci(e,t,n,r){r.minMag&&(n.call(e,t,Pt,r.minMag),n.call(e,t,Ft,r.minMag)),r.min&&n.call(e,t,Pt,r.min),r.mag&&n.call(e,t,Ft,r.mag),r.wrap&&(n.call(e,t,It,r.wrap),n.call(e,t,Lt,r.wrap),(t===jt||_t(e,t))&&n.call(e,t,Rt,r.wrap)),r.wrapR&&n.call(e,t,Rt,r.wrapR),r.wrapS&&n.call(e,t,It,r.wrapS),r.wrapT&&n.call(e,t,Lt,r.wrapT),r.minLod!==void 0&&n.call(e,t,zt,r.minLod),r.maxLod!==void 0&&n.call(e,t,Bt,r.maxLod),r.baseLevel!==void 0&&n.call(e,t,Vt,r.baseLevel),r.maxLevel!==void 0&&n.call(e,t,Ht,r.maxLevel),r.compareFunc!==void 0&&n.call(e,t,Wt,r.compareFunc),r.compareMode!==void 0&&n.call(e,t,Ut,r.compareMode)}function wi(e,t,n){let r=n.target||kt;e.bindTexture(r,t),Ci(e,r,e.texParameteri,n)}function Ti(e,t,n){let r=n.target||kt;e.bindTexture(r,t);let i=n.level||0,a=n.internalFormat||n.format||M,o=xi(a),s=n.format||o.format,c=n.type||o.type;Si(e,n,()=>{if(r===At)for(let t=0;t<6;++t)e.texImage2D(Nt+t,i,a,n.width,n.height,0,s,c,null);else r===jt||r===Mt?e.texImage3D(r,i,a,n.width,n.height,n.depth,0,s,c,null):e.texImage2D(r,i,a,n.width,n.height,0,s,c,null)})}var Ei=ft;function Di(e){return typeof document<`u`&&document.getElementById?document.getElementById(e):null}var Oi=33984,ki=34962,Ai=34963,ji=35713,Mi=35714,Ni=35632,Pi=35633,Fi=35981,Ii=35718,Li=35721,Ri=35971,zi=35382,Bi=35396,Vi=35398,Hi=35392,Ui=35395,Wi=5126,Gi=35664,Ki=35665,qi=35666,Ji=5124,Yi=35667,Xi=35668,Zi=35669,Qi=35670,$i=35671,ea=35672,ta=35673,na=35674,ra=35675,ia=35676,aa=35678,oa=35680,sa=35679,ca=35682,la=35685,ua=35686,da=35687,fa=35688,pa=35689,ma=35690,ha=36289,ga=36292,_a=36293,va=5125,ya=36294,ba=36295,xa=36296,Sa=36298,Ca=36299,wa=36300,Ta=36303,Ea=36306,Da=36307,Oa=36308,ka=36311,Aa=3553,ja=34067,Ma=32879,Na=35866,R={};function Pa(e,t){return R[t].bindPoint}function Fa(e,t){return function(n){e.uniform1f(t,n)}}function Ia(e,t){return function(n){e.uniform1fv(t,n)}}function La(e,t){return function(n){e.uniform2fv(t,n)}}function Ra(e,t){return function(n){e.uniform3fv(t,n)}}function za(e,t){return function(n){e.uniform4fv(t,n)}}function Ba(e,t){return function(n){e.uniform1i(t,n)}}function Va(e,t){return function(n){e.uniform1iv(t,n)}}function Ha(e,t){return function(n){e.uniform2iv(t,n)}}function Ua(e,t){return function(n){e.uniform3iv(t,n)}}function Wa(e,t){return function(n){e.uniform4iv(t,n)}}function Ga(e,t){return function(n){e.uniform1ui(t,n)}}function Ka(e,t){return function(n){e.uniform1uiv(t,n)}}function qa(e,t){return function(n){e.uniform2uiv(t,n)}}function Ja(e,t){return function(n){e.uniform3uiv(t,n)}}function Ya(e,t){return function(n){e.uniform4uiv(t,n)}}function Xa(e,t){return function(n){e.uniformMatrix2fv(t,!1,n)}}function Za(e,t){return function(n){e.uniformMatrix3fv(t,!1,n)}}function Qa(e,t){return function(n){e.uniformMatrix4fv(t,!1,n)}}function $a(e,t){return function(n){e.uniformMatrix2x3fv(t,!1,n)}}function eo(e,t){return function(n){e.uniformMatrix3x2fv(t,!1,n)}}function to(e,t){return function(n){e.uniformMatrix2x4fv(t,!1,n)}}function no(e,t){return function(n){e.uniformMatrix4x2fv(t,!1,n)}}function ro(e,t){return function(n){e.uniformMatrix3x4fv(t,!1,n)}}function io(e,t){return function(n){e.uniformMatrix4x3fv(t,!1,n)}}function z(e,t,n,r){let i=Pa(e,t);return St(e)?function(t){let a,o;!t||gt(e,t)?(a=t,o=null):(a=t.texture,o=t.sampler),e.uniform1i(r,n),e.activeTexture(Oi+n),e.bindTexture(i,a),e.bindSampler(n,o)}:function(t){e.uniform1i(r,n),e.activeTexture(Oi+n),e.bindTexture(i,t)}}function B(e,t,n,r,i){let a=Pa(e,t),o=new Int32Array(i);for(let e=0;e<i;++e)o[e]=n+e;return St(e)?function(t){e.uniform1iv(r,o),t.forEach(function(t,r){e.activeTexture(Oi+o[r]);let i,s;!t||gt(e,t)?(i=t,s=null):(i=t.texture,s=t.sampler),e.bindSampler(n,s),e.bindTexture(a,i)})}:function(t){e.uniform1iv(r,o),t.forEach(function(t,n){e.activeTexture(Oi+o[n]),e.bindTexture(a,t)})}}R[Wi]={Type:Float32Array,size:4,setter:Fa,arraySetter:Ia},R[Gi]={Type:Float32Array,size:8,setter:La,cols:2},R[Ki]={Type:Float32Array,size:12,setter:Ra,cols:3},R[qi]={Type:Float32Array,size:16,setter:za,cols:4},R[Ji]={Type:Int32Array,size:4,setter:Ba,arraySetter:Va},R[Yi]={Type:Int32Array,size:8,setter:Ha,cols:2},R[Xi]={Type:Int32Array,size:12,setter:Ua,cols:3},R[Zi]={Type:Int32Array,size:16,setter:Wa,cols:4},R[va]={Type:Uint32Array,size:4,setter:Ga,arraySetter:Ka},R[ya]={Type:Uint32Array,size:8,setter:qa,cols:2},R[ba]={Type:Uint32Array,size:12,setter:Ja,cols:3},R[xa]={Type:Uint32Array,size:16,setter:Ya,cols:4},R[Qi]={Type:Uint32Array,size:4,setter:Ba,arraySetter:Va},R[$i]={Type:Uint32Array,size:8,setter:Ha,cols:2},R[ea]={Type:Uint32Array,size:12,setter:Ua,cols:3},R[ta]={Type:Uint32Array,size:16,setter:Wa,cols:4},R[na]={Type:Float32Array,size:32,setter:Xa,rows:2,cols:2},R[ra]={Type:Float32Array,size:48,setter:Za,rows:3,cols:3},R[ia]={Type:Float32Array,size:64,setter:Qa,rows:4,cols:4},R[la]={Type:Float32Array,size:32,setter:$a,rows:2,cols:3},R[ua]={Type:Float32Array,size:32,setter:to,rows:2,cols:4},R[da]={Type:Float32Array,size:48,setter:eo,rows:3,cols:2},R[fa]={Type:Float32Array,size:48,setter:ro,rows:3,cols:4},R[pa]={Type:Float32Array,size:64,setter:no,rows:4,cols:2},R[ma]={Type:Float32Array,size:64,setter:io,rows:4,cols:3},R[aa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[oa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[sa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Ma},R[ca]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[ha]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na},R[ga]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na},R[_a]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[Sa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[Ca]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Ma},R[wa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[Ta]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na},R[Ea]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Aa},R[Da]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Ma},R[Oa]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:ja},R[ka]={Type:null,size:0,setter:z,arraySetter:B,bindPoint:Na};function ao(e,t){return function(n){if(n.value)switch(e.disableVertexAttribArray(t),n.value.length){case 4:e.vertexAttrib4fv(t,n.value);break;case 3:e.vertexAttrib3fv(t,n.value);break;case 2:e.vertexAttrib2fv(t,n.value);break;case 1:e.vertexAttrib1fv(t,n.value);break;default:throw Error(`the length of a float constant value must be between 1 and 4!`)}else e.bindBuffer(ki,n.buffer),e.enableVertexAttribArray(t),e.vertexAttribPointer(t,n.numComponents||n.size,n.type||Wi,n.normalize||!1,n.stride||0,n.offset||0),e.vertexAttribDivisor&&e.vertexAttribDivisor(t,n.divisor||0)}}function V(e,t){return function(n){if(n.value){if(e.disableVertexAttribArray(t),n.value.length===4)e.vertexAttrib4iv(t,n.value);else throw Error(`The length of an integer constant value must be 4!`)}else e.bindBuffer(ki,n.buffer),e.enableVertexAttribArray(t),e.vertexAttribIPointer(t,n.numComponents||n.size,n.type||Ji,n.stride||0,n.offset||0),e.vertexAttribDivisor&&e.vertexAttribDivisor(t,n.divisor||0)}}function oo(e,t){return function(n){if(n.value){if(e.disableVertexAttribArray(t),n.value.length===4)e.vertexAttrib4uiv(t,n.value);else throw Error(`The length of an unsigned integer constant value must be 4!`)}else e.bindBuffer(ki,n.buffer),e.enableVertexAttribArray(t),e.vertexAttribIPointer(t,n.numComponents||n.size,n.type||va,n.stride||0,n.offset||0),e.vertexAttribDivisor&&e.vertexAttribDivisor(t,n.divisor||0)}}function so(e,t,n){let r=n.size,i=n.count;return function(n){e.bindBuffer(ki,n.buffer);let a=n.size||n.numComponents||r,o=a/i,s=n.type||Wi,c=R[s].size*a,l=n.normalize||!1,u=n.offset||0,d=c/i;for(let r=0;r<i;++r)e.enableVertexAttribArray(t+r),e.vertexAttribPointer(t+r,o,s,l,c,u+d*r),e.vertexAttribDivisor&&e.vertexAttribDivisor(t+r,n.divisor||0)}}var H={};H[Wi]={size:4,setter:ao},H[Gi]={size:8,setter:ao},H[Ki]={size:12,setter:ao},H[qi]={size:16,setter:ao},H[Ji]={size:4,setter:V},H[Yi]={size:8,setter:V},H[Xi]={size:12,setter:V},H[Zi]={size:16,setter:V},H[va]={size:4,setter:oo},H[ya]={size:8,setter:oo},H[ba]={size:12,setter:oo},H[xa]={size:16,setter:oo},H[Qi]={size:4,setter:V},H[$i]={size:8,setter:V},H[ea]={size:12,setter:V},H[ta]={size:16,setter:V},H[na]={size:4,setter:so,count:2},H[ra]={size:9,setter:so,count:3},H[ia]={size:16,setter:so,count:4};var co=/ERROR:\s*\d+:(\d+)/gi;function lo(e,t=``,n=0){let r=[...t.matchAll(co)],i=new Map(r.map((e,n)=>{let i=parseInt(e[1]),a=r[n+1],o=a?a.index:t.length,s=t.substring(e.index,o);return[i-1,s]}));return e.split(`
|
|
2
2
|
`).map((e,t)=>{let r=i.get(t);return`${t+1+n}: ${e}${r?`\n\n^^^ ${r}`:``}`}).join(`
|
|
3
3
|
`)}var uo=/^[ \t]*\n/;function fo(e){let t=0;return uo.test(e)&&(t=1,e=e.replace(uo,``)),{lineOffset:t,shaderSource:e}}function po(e,t,n,r){if(r||=Ei,!e.getShaderParameter(n,ji)){let i=e.getShaderInfoLog(n),{lineOffset:a,shaderSource:o}=fo(e.getShaderSource(n)),s=`${lo(o,i,a)}\nError compiling ${Ct(e,t)}: ${i}`;return r(s),s}return``}function mo(e,t,n){let r,i,a;if(typeof t==`function`&&(n=t,t=void 0),typeof e==`function`)n=e,e=void 0;else if(e&&!Array.isArray(e)){let t=e;n=t.errorCallback,e=t.attribLocations,r=t.transformFeedbackVaryings,i=t.transformFeedbackMode,a=t.callback}let o=n||Ei,s=[],c={errorCallback(e,...t){s.push(e),o(e,...t)},transformFeedbackVaryings:r,transformFeedbackMode:i,callback:a,errors:s};{let n={};Array.isArray(e)?e.forEach(function(e,r){n[e]=t?t[r]:r}):n=e||{},c.attribLocations=n}return c}var ho=[`VERTEX_SHADER`,`FRAGMENT_SHADER`];function go(e,t){if(t.indexOf(`frag`)>=0)return Ni;if(t.indexOf(`vert`)>=0)return Pi}function _o(e,t,n){let r=e.getAttachedShaders(t);for(let t of r)n.has(t)||e.deleteShader(t);e.deleteProgram(t)}var vo=(e=0)=>new Promise(t=>setTimeout(t,e));function yo(e,t,n){let r=e.createProgram(),{attribLocations:i,transformFeedbackVaryings:a,transformFeedbackMode:o}=mo(n);for(let n=0;n<t.length;++n){let i=t[n];if(typeof i==`string`){let t=Di(i),r=t?t.text:i,a=e[ho[n]];t&&t.type&&(a=go(e,t.type)||a),i=e.createShader(a),e.shaderSource(i,fo(r).shaderSource),e.compileShader(i)}e.attachShader(r,i)}Object.entries(i).forEach(([t,n])=>e.bindAttribLocation(r,n,t));{let t=a;t&&(t.attribs&&(t=t.attribs),Array.isArray(t)||(t=Object.keys(t)),e.transformFeedbackVaryings(r,t,o||Fi))}return e.linkProgram(r),r}function bo(e,t,n,r,i){let a=mo(n,r,i),o=new Set(t),s=yo(e,t,a);function c(e,t){let n=So(e,t,a.errorCallback);return n&&_o(e,t,o),n}if(a.callback)xo(e,s).then(()=>{let t=c(e,s);a.callback(t,t?void 0:s)});else return c(e,s)?void 0:s}async function xo(e,t){let n=e.getExtension(`KHR_parallel_shader_compile`),r=n?(e,t)=>e.getProgramParameter(t,n.COMPLETION_STATUS_KHR):()=>!0,i=0;do await vo(i),i=1e3/60;while(!r(e,t))}function So(e,t,n){if(n||=Ei,!e.getProgramParameter(t,Mi)){let r=e.getProgramInfoLog(t);return n(`Error in program linking: ${r}`),`${r}\n${e.getAttachedShaders(t).map(t=>po(e,e.getShaderParameter(t,e.SHADER_TYPE),t,n)).filter(e=>e).join(`
|
|
4
4
|
`)}`}}function Co(e,t,n,r,i){return bo(e,t,n,r,i)}function wo(e){let t=e.name;return t.startsWith(`gl_`)||t.startsWith(`webgl_`)}var To=/(\.|\[|]|\w+)/g,Eo=e=>e>=`0`&&e<=`9`;function Do(e,t,n,r){let i=e.split(To).filter(e=>e!==``),a=0,o=``;for(;;){let e=i[a++];o+=e;let s=Eo(e[0]),c=s?parseInt(e):e;if(s&&(o+=i[a++]),a===i.length){n[c]=t;break}{let e=i[a++],t=e===`[`,s=n[c]||(t?[]:{});n[c]=s,n=s,r[o]=r[o]||function(e){return function(t){jo(e,t)}}(s),o+=e}}}function Oo(e,t){let n=0;function r(t,r,i){let a=r.name.endsWith(`[0]`),o=r.type,s=R[o];if(!s)throw Error(`unknown type: 0x${o.toString(16)}`);let c;if(s.bindPoint){let t=n;n+=r.size,c=a?s.arraySetter(e,o,t,i,r.size):s.setter(e,o,t,i,r.size)}else c=s.arraySetter&&a?s.arraySetter(e,i):s.setter(e,i);return c.location=i,c}let i={},a={},o=e.getProgramParameter(t,Ii);for(let n=0;n<o;++n){let o=e.getActiveUniform(t,n);if(wo(o))continue;let s=o.name;s.endsWith(`[0]`)&&(s=s.substr(0,s.length-3));let c=e.getUniformLocation(t,o.name);if(c){let e=r(t,o,c);i[s]=e,Do(s,e,a,i)}}return i}function ko(e,t){let n={},r=e.getProgramParameter(t,Ri);for(let i=0;i<r;++i){let r=e.getTransformFeedbackVarying(t,i);n[r.name]={index:i,type:r.type,size:r.size}}return n}function Ao(e,t){let n=e.getProgramParameter(t,Ii),r=[],i=[];for(let a=0;a<n;++a){i.push(a),r.push({});let n=e.getActiveUniform(t,a);r[a].name=n.name}[[`UNIFORM_TYPE`,`type`],[`UNIFORM_SIZE`,`size`],[`UNIFORM_BLOCK_INDEX`,`blockNdx`],[`UNIFORM_OFFSET`,`offset`]].forEach(function(n){let a=n[0],o=n[1];e.getActiveUniforms(t,i,e[a]).forEach(function(e,t){r[t][o]=e})});let a={},o=e.getProgramParameter(t,zi);for(let n=0;n<o;++n){let r=e.getActiveUniformBlockName(t,n),i={index:e.getUniformBlockIndex(t,r),usedByVertexShader:e.getActiveUniformBlockParameter(t,n,Bi),usedByFragmentShader:e.getActiveUniformBlockParameter(t,n,Vi),size:e.getActiveUniformBlockParameter(t,n,Hi),uniformIndices:e.getActiveUniformBlockParameter(t,n,Ui)};i.used=i.usedByVertexShader||i.usedByFragmentShader,a[r]=i}return{blockSpecs:a,uniformData:r}}function jo(e,t){for(let n in t){let r=e[n];typeof r==`function`?r(t[n]):jo(e[n],t[n])}}function Mo(e,...t){let n=e.uniformSetters||e,r=t.length;for(let e=0;e<r;++e){let r=t[e];if(Array.isArray(r)){let e=r.length;for(let t=0;t<e;++t)Mo(n,r[t])}else for(let e in r){let t=n[e];t&&t(r[e])}}}function No(e,t){let n={},r=e.getProgramParameter(t,Li);for(let i=0;i<r;++i){let r=e.getActiveAttrib(t,i);if(wo(r))continue;let a=e.getAttribLocation(t,r.name),o=H[r.type],s=o.setter(e,a,o);s.location=a,n[r.name]=s}return n}function Po(e,t){for(let n in t){let r=e[n];r&&r(t[n])}}function Fo(e,t,n){n.vertexArrayObject?e.bindVertexArray(n.vertexArrayObject):(Po(t.attribSetters||t,n.attribs),n.indices&&e.bindBuffer(Ai,n.indices))}function Io(e,t){let n=Oo(e,t),r=No(e,t),i={program:t,uniformSetters:n,attribSetters:r,uniformLocations:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.location])),attribLocations:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,t.location]))};return St(e)&&(i.uniformBlockSpec=Ao(e,t),i.transformFeedbackInfo=ko(e,t)),i}var Lo=36160,Ro=6402,zo=33190,Bo=36012,Vo=35056,Ho=36013,Uo=32854,Wo=32855,Go=36194,Ko=33189,qo=6401,Jo=36168,Yo=34041,Xo=36096,Zo=36128,Qo=33306,U={};U[Yo]=Qo,U[qo]=Zo,U[Jo]=Zo,U[Ro]=Xo,U[Ko]=Xo,U[zo]=Xo,U[Bo]=Xo,U[Vo]=Qo,U[Ho]=Qo;var $o={};$o[Uo]=!0,$o[Wo]=!0,$o[Go]=!0,$o[Yo]=!0,$o[Ko]=!0,$o[qo]=!0,$o[Jo]=!0;function es(e,t,n){n||=Lo,t?(e.bindFramebuffer(n,t.framebuffer),e.viewport(0,0,t.width,t.height)):(e.bindFramebuffer(n,null),e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight))}var ts=new WeakMap;function ns(e,t,n,r){let i=[],a=Co(e,[t,n],{errorCallback:e=>i.push(e)});if(!a)throw Error(`${r} shader: ${i.join(`
|
|
@@ -94,7 +94,7 @@ void main() {
|
|
|
94
94
|
vec3 body = (colored + light) * bodyAlpha;
|
|
95
95
|
vec3 glow = surfaceTint * glowAlpha * (1.0 - bodyAlpha);
|
|
96
96
|
color = vec4(min(body + glow, vec3(alpha)), alpha);
|
|
97
|
-
}`,fs=class{canvas=document.createElement(`canvas`);capture=document.createElement(`canvas`);bloomCapture=document.createElement(`canvas`);materials=new Map;gl=null;program=null;initialized=!1;disposed=!1;failedSources=new WeakSet;size=new Float32Array(4);directions=new Float32Array(12);colors=new Float32Array(12);contacts=new Float32Array(12);padding=64;onLost=e=>{e.preventDefault(),this.materials.clear(),this.program=null};onRestored=()=>{!this.disposed&&this.gl&&(this.program=ns(this.gl,us,ds,`Pickup refraction`))};initialize(){if(this.initialized=!0,this.gl=this.canvas.getContext(`webgl2`,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1}),this.gl){try{this.program=ns(this.gl,us,ds,`Pickup refraction`)}catch{this.gl=null;return}this.canvas.addEventListener(`webglcontextlost`,this.onLost),this.canvas.addEventListener(`webglcontextrestored`,this.onRestored)}}destroyMaterial(e){this.gl?.deleteTexture(e.texture),this.gl?.deleteTexture(e.bloomTexture)}clearMaterials(){for(let e of this.materials.values())this.destroyMaterial(e);this.materials.clear()}draw(e,t,n,r,i,a,o,s,c=4.5){if(!s.length||this.disposed||this.failedSources.has(n)||(this.initialized||this.initialize(),!this.gl||!this.program))return!1;let l=Math.max(16,Math.round(272*a/Math.max(a,o))),u=Math.max(16,Math.round(272*o/Math.max(a,o))),f=this.materials.get(t);if(f&&(f.source!==n||f.revision!==i||f.width!==l||f.height!==u)&&(this.destroyMaterial(f),this.materials.delete(t),f=void 0),!f){if(this.materials.size>=8){let e=this.materials.keys().next().value;this.destroyMaterial(this.materials.get(e)),this.materials.delete(e)}this.capture.width=l+this.padding*2,this.capture.height=u+this.padding*2;let e=this.capture.getContext(`2d`);if(!e)return!1;e.drawImage(n,r.x,r.y,r.width,r.height,this.padding,this.padding,l,u),this.bloomCapture.width=this.capture.width,this.bloomCapture.height=this.capture.height;let a=this.bloomCapture.getContext(`2d`);if(!a)return!1;if(typeof a.filter==`string`)a.filter=`blur(8px)`,a.drawImage(this.capture,0,0);else{let e=this.bloomCapture.width*2;a.shadowColor=`#ffffff`,a.shadowBlur=16,a.shadowOffsetX=e,a.drawImage(this.capture,-e,0)}try{f=this.upload(n,i,l,u)}catch{return this.failedSources.add(n),!1}this.materials.set(t,f),d(`pickup sprite uploads`)}let p=l+this.padding*2,m=u+this.padding*2;(this.canvas.width!==p||this.canvas.height!==m)&&(this.canvas.width=p,this.canvas.height=m),this.size.set([l,u,this.padding,Math.min(3,s.length)]);for(let e=0;e<Math.min(3,s.length);e++){let t=s[e];this.directions.set([Math.cos(t.angle),-Math.sin(t.angle),t.age/t.duration,t.strength],e*4),this.colors.set([...t.color,t.variation],e*4),this.contacts.set([t.origin?.x??0,-(t.origin?.y??0),+!!t.origin,t.velocity*t.duration/c],e*4)}let h=this.gl;h.viewport(0,0,p,m),h.useProgram(this.program),as(this.program,{sprite:f.texture,bloom:f.bloomTexture,size:this.size,directionTime:this.directions,tint:this.colors,contact:this.contacts}),h.drawArrays(h.TRIANGLES,0,3);let g=this.padding*a/l,_=this.padding*o/u;return e.drawImage(this.canvas,-a/2-g,-o/2-_,a+g*2,o+_*2),d(`pickup shader passes`),d(`composited megapixels`,p*m/1e6),!0}upload(e,t,n,r){let i=this.gl,a=[];try{for(let e of[this.capture,this.bloomCapture]){let t=i.createTexture();if(!t)throw Error(`Unable to allocate pickup material`);a.push(t),i.bindTexture(i.TEXTURE_2D,t),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!1),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,e)}let[o,s]=a;return{source:e,revision:t,width:n,height:r,texture:o,bloomTexture:s}}catch(e){for(let e of a)i.deleteTexture(e);throw e}}reset(){this.clearMaterials()}dispose(){this.disposed=!0,this.clearMaterials(),this.canvas.removeEventListener(`webglcontextlost`,this.onLost),this.canvas.removeEventListener(`webglcontextrestored`,this.onRestored),this.gl&&this.program&&G(this.gl,this.program),this.gl=null,this.program=null}},ps=8;function ms(e,t,n){let r=n*.45,i=0;for(let n=0;n<8;n++){let n=i+1;if(n>=r)break;let a=new Set,o=i;for(let i of e.elementsFromPoint(t,n))for(let e=i;e;e=e.parentElement){if(a.has(e))continue;a.add(e);let t=getComputedStyle(e);if(t.position!==`fixed`&&t.position!==`sticky`||t.visibility===`hidden`||t.opacity===`0`)continue;let i=e.getBoundingClientRect();i.top<=n&&i.bottom>n&&i.bottom<r&&(o=Math.max(o,i.bottom))}if(o<=i)break;i=o}return i+ps}var hs=class{camera;constructor(e){this.camera=e}pickupLayer=null;dispose(){this.pickupLayer?.dispose()}captureState(){return l({previousCarVelocity:this.previousCarVelocity,poseOffset:this.poseOffset,poseVelocity:this.poseVelocity,poseForce:this.poseForce,wheelPhase:this.wheelPhase})}restoreState(e){let t=l(e);this.previousCarVelocity=t.previousCarVelocity,this.poseOffset=t.poseOffset,this.poseVelocity=t.poseVelocity,this.poseForce=t.poseForce,this.wheelPhase=t.wheelPhase,this.clearMaterials()}clearMaterials(){this.pickupLayer?.reset(),this.carImages.clear(),this.pickupFallbacks=new WeakMap,this.pristineShadows=new WeakMap,this.deformedShadows=new WeakMap}reset(){this.pickupLayer?.reset(),this.markers=[],this.previousCarVelocity=null,this.poseOffset=S(),this.poseVelocity=S(),this.poseForce=S(),this.wheelPhase=[0,0,0,0]}carImages=new Map;pickupFallbacks=new WeakMap;pristineShadows=new WeakMap;deformedShadows=new WeakMap;previousCarVelocity=null;poseOffset=S();poseVelocity=S();poseForce=S();wheelPhase=[0,0,0,0];carVisualOffset(e){return _(m(S(this.poseOffset.x,-this.poseOffset.y),-e.body.angle),this.camera.zoom)}updateCarPose(e,t){if(e.mode!==`car`){this.previousCarVelocity=null,this.poseOffset=S(),this.poseVelocity=S(),this.poseForce=S();return}let n=e.body.velocity,r=this.previousCarVelocity?_(b(n,this.previousCarVelocity),1/Math.max(t,1e-4)):S();this.previousCarVelocity={...n};let i=m(r,-e.body.angle),a=1-Math.exp(-t/.11);this.poseForce=x(this.poseForce,_(b(S(y(i.x,-15,15),y(i.y,-15,15)),this.poseForce),a));let o=S(y(-this.poseForce.x*.006,-.055,.055),0);this.poseVelocity=x(this.poseVelocity,_(b(_(b(o,this.poseOffset),65),_(this.poseVelocity,15)),t)),this.poseOffset=x(this.poseOffset,_(this.poseVelocity,t)),e.car.tires.forEach((n,r)=>{this.wheelPhase[r]=(this.wheelPhase[r]+t*Math.abs(n.wheelSurfaceSpeedMps)/Math.max(.18,e.car.preset.geometry.tireLengthM*.45))%1})}line(e,t,n,r,i=1){let a=this.camera.screen(t),o=this.camera.screen(n);e.strokeStyle=r,e.lineWidth=i,e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(o.x,o.y),e.stroke()}outline(e,t,n){e.beginPath(),t.forEach((t,n)=>{let r=this.camera.screen(t);n?e.lineTo(r.x,r.y):e.moveTo(r.x,r.y)}),e.closePath(),e.fillStyle=`${n}15`,e.fill(),e.strokeStyle=n,e.lineWidth=2,e.stroke()}imageFor(e){let t=e.image?.src;if(!t)return null;let n=this.carImages.get(t);return n||(n=new Image,n.crossOrigin=`anonymous`,n.src=t,this.carImages.set(t,n)),n.complete&&n.naturalWidth?n:null}imageLoadState(e){let t=e.image?.src;return!t||this.imageFor(e)?`ready`:this.carImages.get(t)?.complete?`failed`:`loading`}markers=[];markerInset={x:NaN,scrollX:NaN,scrollY:NaN,width:NaN,height:NaN,at:0,value:8};topMarkerInset(e){if(!this.camera.overlay||e.y>=this.camera.height/2)return 8;let t=this.camera.regionScale,n=y(Je(e,this.camera).center.x*t,1,window.innerWidth-1),r=performance.now(),i=this.markerInset;return(r-i.at>200||Math.abs(n-i.x)>24||i.scrollX!==window.scrollX||i.scrollY!==window.scrollY||i.width!==window.innerWidth||i.height!==window.innerHeight)&&(this.markerInset={x:n,scrollX:window.scrollX,scrollY:window.scrollY,width:window.innerWidth,height:window.innerHeight,at:r,value:ms(document,n,window.innerHeight)}),this.markerInset.value/t}markerAt(e){return[...this.markers].reverse().find(t=>Math.hypot(e.x-t.x,e.y-t.y)<=t.width/2+3)?.vehicle??null}drawVehicleMarkers(e,t,n){if(this.markers=[],n)for(let n of t){let{sim:r}=n;if(r.mode!==`car`||r.car.explodedAt!==null)continue;let i=x(this.camera.screen(r.body.position),n===t[0]?this.carVisualOffset(r):S()),a=Math.max(r.car.preset.geometry.lengthM,r.car.preset.geometry.widthM)*this.camera.zoom*.5;if(i.x+a>=0&&i.x-a<=this.camera.width&&i.y+a>=0&&i.y-a<=this.camera.height)continue;let o=Je(i,this.camera,this.topMarkerInset(i)),{width:s,height:c}=o,{x:l,y:u}=o.center;this.markers.push({vehicle:n,x:l,y:u,width:s,height:c}),e.save(),e.translate(l,u),e.shadowColor=`#00000030`,e.shadowBlur=10,e.shadowOffsetY=2,e.fillStyle=`#ffffff`,e.beginPath(),e.arc(0,0,s/2,0,Math.PI*2),e.fill(),e.shadowColor=`transparent`,e.strokeStyle=`#19212640`,e.lineWidth=1,e.stroke();let d=this.imageFor(r.car.preset);if(e.save(),e.rotate(-r.body.angle),d){let t=D(r.car.preset,d.naturalWidth,d.naturalHeight),n=35*t.widthM/t.lengthM;e.drawImage(d,t.source.x,t.source.y,t.source.width,t.source.height,-35/2,-n/2,35,n)}else e.fillStyle=`#192126`,e.beginPath(),e.roundRect(-13,-5,26,10,5),e.fill();e.restore();let{left:f,right:p,tip:m}=o;e.fillStyle=`#ffffff`,e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(m.x,m.y),e.lineTo(p.x,p.y),e.closePath(),e.fill(),e.strokeStyle=`#19212640`,e.lineWidth=1,e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(m.x,m.y),e.lineTo(p.x,p.y),e.stroke(),e.restore()}}shadowFor(e,t,n){let r=this.imageFor(e);if(!r)return null;let i=D(e,r.naturalWidth,r.naturalHeight),a=t?.spriteFor(r,i)??null,o=Math.max(1,Math.round(this.camera.zoom/2)*2),s=`${JSON.stringify(e.image?.crop)}|${e.image?.scale}|${e.geometry.lengthM}:${e.geometry.widthM}|${o}:${n}`;if(t&&a){let i=`${s}|${t.geometryRevision}`,c=this.deformedShadows.get(t);if(c?.image===r&&c.key===i)return c.shadow;d(`shadow rebuilds`);let l=Ue(r,e,a,o,n);return this.deformedShadows.set(t,{image:r,key:i,shadow:l}),l}let c=this.pristineShadows.get(r);c||(c=new Map,this.pristineShadows.set(r,c));let l=c.get(s);return l||(d(`shadow rebuilds`),l=Ue(r,e,a,o,n),c.set(s,l),c.size>12&&c.delete(c.keys().next().value)),l}vehicleBodyPath(e,t,n,r,i){if(!i?.hasDamage){e.roundRect(-t/2,-n/2,t,n,r);return}let a=Math.min(r,n/2),o=[{x:t/2-a,y:-n/2+a,start:-Math.PI/2},{x:t/2-a,y:n/2-a,start:0},{x:-t/2+a,y:n/2-a,start:Math.PI/2},{x:-t/2+a,y:-n/2+a,start:Math.PI}],s=!0;for(let t of o)for(let n=0;n<=8;n++){let r=t.start+n*Math.PI/16,o=S(t.x+Math.cos(r)*a,t.y+Math.sin(r)*a),c=i.point(_(o,1/this.camera.zoom)),l=c.x*this.camera.zoom,u=c.y*this.camera.zoom;s?(e.moveTo(l,u),s=!1):e.lineTo(l,u)}e.closePath()}carGround(e,t,n,r,i){performance.now();let a=t.body,o=t.car.preset.geometry,s=this.camera.screen(a.position),c=o.lengthM*this.camera.zoom,l=o.widthM*this.camera.zoom,u=y(p(this.poseForce)/13,0,1),f=e.globalAlpha;e.save(),e.translate(s.x,s.y),e.rotate(-a.angle),e.save(),e.translate(-this.poseOffset.x*this.camera.zoom*.2+2,this.poseOffset.y*this.camera.zoom*.2+4);let m=i?this.shadowFor(t.car.preset,n,r):null;if(m){let t=m.lengthM*this.camera.zoom,n=m.widthM*this.camera.zoom,r=this.camera.zoom/m.pixelsPerMeter,i=(i,a)=>{let o=i.padding*r;d(`shadow composites`),e.drawImage(i.canvas,-t/2-o,-n/2+a-o,t+o*2,n+o*2)};e.globalAlpha=f*(.43+u*.05),m.soft&&i(m.soft,3),e.globalAlpha=f*.14,m.close&&i(m.close,2)}else if(i){e.fillStyle=`rgba(13, 20, 20, ${.18+u*.045})`,e.shadowColor=`rgba(8, 14, 16, 0.43)`,e.shadowBlur=12+u*5,e.shadowOffsetY=2,e.beginPath();let r=t.car.preset.visual,i=r?l*.86:l*.84,a=r?r.shape===`suv`?9:r.shape===`supercar`?24:19:l*.34;this.vehicleBodyPath(e,r?c:c*.96,i,a,n),e.fill()}e.restore(),t.car.tires.forEach((n,r)=>{let i=He(t.car.preset),o=i.length*this.camera.zoom,s=i.width*this.camera.zoom;e.save(),e.translate(n.local.x*this.camera.zoom,-n.local.y*this.camera.zoom),e.rotate(-n.angle),e.fillStyle=`#121719`,e.beginPath(),e.roundRect(-o/2,-s/2,o,s,Math.min(3.5,s*.33)),e.fill(),e.save(),e.beginPath(),e.roundRect(-o/2+1,-s/2+1,o-2,s-2,Math.min(3,s*.3)),e.clip();let c=this.wheelPhase[r]??0,l=n.spinning?1:y(p(a.velocity)/24,0,.65),u=Math.max(4.2,o/4);e.strokeStyle=n.spinning?`rgba(170, 181, 178, 0.38)`:`rgba(125, 139, 137, 0.34)`,e.lineWidth=n.spinning?2:1.25;for(let t=-3;t<=4;t++){let n=t*u+c*u;e.beginPath(),e.moveTo(n-l*2,-s*.31),e.lineTo(n+l*2,s*.31),e.stroke()}l>.2&&(e.fillStyle=`rgba(137, 150, 147, ${.08+l*.1})`,e.fillRect(-o*.4,-s*.09,o*.8,s*.18)),e.restore(),e.strokeStyle=`rgba(6, 10, 11, 0.8)`,e.lineWidth=1.2,e.beginPath(),e.roundRect(-o/2,-s/2,o,s,Math.min(3.5,s*.33)),e.stroke(),e.restore()}),e.restore()}car(e,t,n,r,i,a){let o=n.car.preset,s=o.geometry,c=this.imageFor(o);if(a&&!this.pickupLayer&&(this.pickupLayer=new fs),c){let n=this.camera.screen(t.position),s=D(o,c.naturalWidth,c.naturalHeight),l=r?.spriteFor(c,s);if(e.save(),e.translate(n.x,n.y),e.rotate(-t.angle),oe(e,o,this.camera.zoom,s.lengthM,s.widthM,i,a?.pickupEffect.active.length?s.lengthM*.25:0),a?.pickupEffect.active.length&&this.pickupLayer?.draw(e,a,l??c,l?{x:0,y:0,width:l.width,height:l.height}:s.source,`${r?.geometryRevision??0}:${JSON.stringify(s.source)}`,s.lengthM*this.camera.zoom,s.widthM*this.camera.zoom,a.pickupEffect.active,s.lengthM)){e.restore();return}l?e.drawImage(l,-s.lengthM*this.camera.zoom/2,-s.widthM*this.camera.zoom/2,s.lengthM*this.camera.zoom,s.widthM*this.camera.zoom):e.drawImage(c,s.source.x,s.source.y,s.source.width,s.source.height,-s.lengthM*this.camera.zoom/2,-s.widthM*this.camera.zoom/2,s.lengthM*this.camera.zoom,s.widthM*this.camera.zoom),d(`vehicle sprites`),e.restore();return}if(a?.pickupEffect.active.length){let c=s.lengthM*this.camera.zoom,l=s.widthM*this.camera.zoom,u=`${o.id}:${this.camera.zoom}:${r?.geometryRevision??0}:${JSON.stringify(o.visual)}`,d=this.pickupFallbacks.get(a);if(!d||d.revision!==u){let e=document.createElement(`canvas`),o=384/Math.max(c,l);e.width=Math.max(1,Math.ceil(c*o)),e.height=Math.max(1,Math.ceil(l*o));let s=e.getContext(`2d`);if(s){let o=this.camera.screen(t.position);s.scale(e.width/c,e.height/l),s.translate(c/2,l/2),s.rotate(t.angle),s.translate(-o.x,-o.y),this.car(s,t,n,r,i),d={revision:u,canvas:e},this.pickupFallbacks.set(a,d)}}if(d){let n=this.camera.screen(t.position);e.save(),e.translate(n.x,n.y),e.rotate(-t.angle);let r=this.pickupLayer?.draw(e,a,d.canvas,{x:0,y:0,width:d.canvas.width,height:d.canvas.height},u,c,l,a.pickupEffect.active,s.lengthM);if(e.restore(),r)return}}if(o.visual){this.styledCar(e,t,n,r);return}let l=s.lengthM/2,u=s.widthM/2,f=[S(-l,-u),S(l,-u),S(l,u),S(-l,u)].map(e=>t.world(e));this.outline(e,f,`#8ce6c5`),this.line(e,t.world(S(s.wheelbaseM/4,-s.trackWidthM/2)),t.world(S(s.wheelbaseM/4,s.trackWidthM/2)),`#8ce6c5`,2),this.center(e,t,`#8ce6c5`)}exhaustOutlets(e){return Ve(e.car.preset).map(({xM:e,yM:t})=>S(e,t))}exhaust(e,t){let n=this.camera.screen(t.body.position);e.save(),e.translate(n.x,n.y),e.rotate(-t.body.angle);let r=this.exhaustOutlets(t);for(let t of r)e.fillStyle=`rgba(25, 31, 33, 0.62)`,e.beginPath(),e.ellipse(t.x*this.camera.zoom,-t.y*this.camera.zoom,Math.max(1.3,this.camera.zoom*.065),Math.max(1.2,this.camera.zoom*.055),0,0,Math.PI*2),e.fill();e.restore()}styledCar(e,t,n,r){let{geometry:i,visual:a}=n.car.preset;if(!a)return;let o=this.camera.screen(t.position),s=i.lengthM*this.camera.zoom,c=i.widthM*this.camera.zoom*.86,l=a.shape===`suv`?9:a.shape===`supercar`?24:19;e.save(),e.translate(o.x,o.y),e.rotate(-t.angle),e.beginPath(),this.vehicleBodyPath(e,s,c,l,r),e.fillStyle=a.color,e.fill(),e.strokeStyle=`rgba(18, 29, 27, 0.72)`,e.lineWidth=2,e.stroke(),e.fillStyle=`rgba(16, 32, 36, 0.8)`;let u=s*(a.shape===`suv`?.52:a.shape===`supercar`?.32:.4),d=c*(a.shape===`suv`?.72:.64),f=a.shape===`supercar`?-s*.08:-s*.015;e.beginPath(),e.roundRect(f-u/2,-d/2,u,d,a.shape===`suv`?7:14),e.fill(),e.strokeStyle=`rgba(235, 245, 241, 0.58)`,e.lineWidth=2,e.beginPath(),e.moveTo(f+u*.16,-d/2+3),e.lineTo(f+u*.16,d/2-3),e.stroke(),e.fillStyle=`rgba(255, 246, 205, 0.9)`;let p=T(n.car.preset);for(let t of[-1,1])e.beginPath(),e.ellipse(p.headlights.xM*this.camera.zoom,t*p.headlights.yM*this.camera.zoom,4,3,0,0,Math.PI*2),e.fill();e.fillStyle=`rgba(139, 28, 21, 0.88)`;for(let t of[-1,1])e.fillRect(p.taillights.xM*this.camera.zoom-2,t*p.taillights.yM*this.camera.zoom-3,4,6);e.restore()}ship(e,t,n){let r=n.ship,i=r.craft,a=t.world(r.counterweight);this.line(e,t.world(x(r.counterweight,S(r.radius))),t.world(x(i,S(-.6))),`#ff6262`,2);let o=this.camera.screen(a);e.beginPath(),e.arc(o.x,o.y,r.radius*this.camera.zoom,0,Math.PI*2),e.fillStyle=`#ff626215`,e.fill(),e.strokeStyle=`#ff6262`,e.lineWidth=2,e.stroke();let s=[S(1.2),S(-.6,-.8),S(-.6,.8)].map(e=>t.world(x(i,m(e,r.headAngle))));this.outline(e,s,`#ff6262`),this.center(e,t,`#ff6262`)}brick(e,t){this.outline(e,[S(-2,-1),S(2,-1),S(2,1),S(-2,1)].map(e=>t.world(e)),`#f6bd79`),this.center(e,t,`#f6bd79`)}center(e,t,n){let r=this.camera.screen(t.position);e.fillStyle=n,e.beginPath(),e.arc(r.x,r.y,3,0,Math.PI*2),e.fill(),!this.camera.overlay&&p(t.velocity)>.1&&this.line(e,t.position,x(t.position,_(t.velocity,.35)),`#658da0`)}},gs=.055,_s=e=>{let t=Math.sin(e*127.1+311.7)*43758.5453;return t-Math.floor(t)};function vs(e,t,n){if(!Number.isFinite(n)||n<=0)return[];let r=Math.min(e.age,e.duration*.8),i=e.age-n,a=i<=1e-7?0:Math.floor((i+1e-7)/gs)+1,o=Math.floor((r+1e-7)/gs);if(a>o)return[];let s={x:Math.cos(e.angle),y:Math.sin(e.angle)},c=Math.min(t.lengthM/(2*Math.max(1e-4,Math.abs(s.x))),t.widthM/(2*Math.max(1e-4,Math.abs(s.y)))),l=e.origin?{x:e.origin.x*t.lengthM,y:e.origin.y*t.widthM}:{x:-s.x*c,y:-s.y*c},u=Math.max(1.8,Math.min(5,e.velocity*e.duration/t.lengthM*2.2)),d=Math.hypot(t.lengthM*.5+Math.abs(l.x),t.widthM*.5+Math.abs(l.y)),f=[];for(let n=a;n<=o;n++){let r=n*gs/e.duration*u*t.lengthM;for(let i=0;i<2;i++){let a=e.variation*1999+n*83+i*257,o,s=1/0,c=Math.min(r,d)*Math.sqrt(_s(a+9));for(let e=0;e<32;e++){let n=_s(a+e*2+1),i=_s(a+e*2+2),u=t.alpha;if(u&&!u.solid[Math.floor(i*u.rows)*u.columns+Math.floor(n*u.columns)])continue;let d={x:(n-.5)*t.lengthM,y:(.5-i)*t.widthM},f=Math.hypot(d.x-l.x,d.y-l.y);if(f>r+t.lengthM*.17)continue;let p=Math.abs(f-c);p<s&&(s=p,o=d)}o&&f.push(o)}}return f}function ys(e,t,n){return n?S(n.x+n.width/2,n.y+n.height/2):S(e/2,t/2)}function bs(e,t,n){let r=ys(e,t,n);return Math.ceil(2*Math.hypot(Math.max(r.x,e-r.x),Math.max(r.y,t-r.y)))}function xs(e,t,n,r){return x(n,m(b(e,t),r))}function Ss(e,t,n,r){return x(t,m(b(e,n),-r))}function Cs(e,t,n){return _(S(e,t),n/2)}function ws(e,t,n,r){return e+Math.atan2(Math.sin(t-e),Math.cos(t-e))*(r<=0?1:1-Math.exp(-Math.max(0,n)/r))}function Ts(e,t,n){return{x:e.x<n?e.x-n:e.x>t.width-n?e.x-(t.width-n):0,y:e.y<n?e.y-n:e.y>t.height-n?e.y-(t.height-n):0}}function Es(e,t,n){let r=Math.min(Math.max(1,t.width-32)/Math.max(1,e.width+160),Math.max(1,t.height-32)/Math.max(1,e.height+160));return Math.max(.1,Math.min(3,n??r))}function Ds(e,t){let n=null;for(let r of e){let e=r.bounds;t.x<e.x||t.y<e.y||t.x>=e.x+e.width||t.y>=e.y+e.height||(!n||n.element.contains(r.element)||!r.element.contains(n.element)&&e.width*e.height<n.bounds.width*n.bounds.height)&&(n=r)}return n}var Os=class{projection;regions=[];measuredAt=-1/0;constructor(e=ae){this.projection=e}at(e,t,n){return n-this.measuredAt>120&&(this.measuredAt=n,this.regions=Array.from(document.querySelectorAll(`[data-jr-camera],[data-jr-camera-zoom]`)).filter(e=>!e.closest(`[data-jr-ui],[data-jr-overlay]`)).flatMap(e=>{let n=e.getAttribute(`data-jr-camera`);if(n!==null&&n!==`fixed`&&n!==`follow`)return[];let r=this.projection.viewportRectToDocument(e.getBoundingClientRect(),t);if(r.width<=0||r.height<=0)return[];let i=e.getAttribute(`data-jr-camera-zoom`),a=i?.trim()?Number(i):NaN;return n===null&&(!Number.isFinite(a)||a<=0)?[]:[{element:e,bounds:r,fixed:n===`fixed`,zoom:Number.isFinite(a)&&a>0?a:void 0}]})),Ds(this.regions.filter(e=>e.element.isConnected),e)}reset(){this.regions=[],this.measuredAt=-1/0}},ks=class{overlay;canvasWorld;requestResize;constructor(e,t,n){this.overlay=e,this.canvasWorld=t,this.requestResize=n,e&&(this.originScroll=S(window.scrollX,window.scrollY),this.observedScroll={...this.originScroll},this.pageSize={width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight})}resize(){this.requestResize()}get pixelSpace(){return this.overlay||this.canvasWorld}get timeSeconds(){return this.lastFrame/1e3}rebaseTime(e){this.lastFrame=e}captureState(){return l({outputWidth:this.outputWidth,outputHeight:this.outputHeight,cameraRotation:this.cameraRotation,cameraLock:this.cameraLock,cameraSmoothing:this.cameraSmoothing,cameraLockInitialized:this.cameraLockInitialized,width:this.width,height:this.height,dpr:this.dpr,smokeMargin:this.smokeMargin,regionScale:this.regionScale,canvasWorldScale:this.canvasWorldScale,cameraFrame:this.cameraFrame,camera:this.camera,zoom:this.zoom,baseZoom:this.baseZoom,slowMoScale:this.slowMoScale,zoomAnchor:this.zoomAnchor,pageSize:this.pageSize,lastFrame:this.lastFrame,originScroll:this.originScroll,observedScroll:this.observedScroll,virtualScroll:this.virtualScroll,followInterrupted:this.followInterrupted,deadZone:this.deadZone})}restoreState(e){let t=l(e);this.vehicleReveal=null,this.outputWidth=t.outputWidth,this.outputHeight=t.outputHeight,this.cameraRotation=t.cameraRotation,this.cameraLock=t.cameraLock,this.cameraSmoothing=t.cameraSmoothing,this.cameraLockInitialized=t.cameraLockInitialized,this.width=t.width,this.height=t.height,this.dpr=t.dpr,this.smokeMargin=t.smokeMargin,this.regionScale=t.regionScale,this.canvasWorldScale=t.canvasWorldScale,this.cameraFrame=t.cameraFrame,this.camera=t.camera,this.zoom=t.zoom,this.baseZoom=t.baseZoom,this.slowMoScale=t.slowMoScale,this.zoomAnchor=t.zoomAnchor,this.pageSize=t.pageSize,this.lastFrame=t.lastFrame,this.originScroll=t.originScroll,this.observedScroll=t.observedScroll,this.virtualScroll=t.virtualScroll,this.followInterrupted=t.followInterrupted,this.deadZone=t.deadZone}restorePresentation(){this.setVirtualScroll({...this.virtualScroll}),this.overlay&&(window.scrollTo(this.observedScroll.x,this.observedScroll.y),de(),this.resize(),this.cameraRegions.reset(),this.activeCameraRegion||this.regionScale!==1?this.pageScene.apply(this.regionScale,this.sceneScroll()):this.pageScene.clear())}reset(){this.vehicleReveal=null,this.camera=S(),this.cameraLockInitialized=!1,this.slowMoZoom=1,this.zoomAnchor=S(),this.overlay&&(this.pageSize={width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight}),this.pageScene.clear(),this.activeCameraRegion=null,this.cameraRegions.reset(),this.regionScale=this.canvasWorld?this.canvasWorldScale:1,this.resize(),this.setVirtualScroll(S())}vehicleReveal=null;revealVehicle(e,t=550){this.overlay&&(this.syncScroll(),this.followInterrupted=!0,this.vehicleReveal={sim:e,start:this.sceneScroll(),started:null,duration:t})}advanceVehicleReveal(e,t){let n=this.vehicleReveal;if(!n)return;n.started??=e;let r=n.duration<=0?1:y((e-n.started)/n.duration,0,1),i=r*r*(3-2*r),a=b(this.documentPoint(n.sim.body.position),S(this.width/2,this.height/2));!this.virtualScroll.x&&a.x>=-this.width/2&&a.x<=this.pageSize.width-this.width/2&&(a.x=y(a.x,0,Math.max(0,this.pageSize.width-this.width))),!this.virtualScroll.y&&a.y>=-this.height/2&&a.y<=this.pageSize.height-this.height/2&&(a.y=y(a.y,0,Math.max(0,this.pageSize.height-this.height))),this.moveSceneTo(x(n.start,_(b(a,n.start),i))),r===1&&(this.vehicleReveal=null,n.sim===t&&(this.followInterrupted=!1))}resetFollow(){this.vehicleReveal=null,this.overlay&&(this.originScroll=S(window.scrollX,window.scrollY),this.observedScroll={...this.originScroll},this.followInterrupted=!1)}dispose(){this.vehicleReveal=null,this.pageScene.clear(),this.setVirtualScroll(S()),de()}resizeLayout(e,t,n){this.outputWidth=e,this.outputHeight=t;let r=this.canvasWorld&&this.cameraLock,i=r?bs(e,t,this.cameraFrame):0,a=(r?i:e)/this.regionScale,o=(r?i:t)/this.regionScale;this.overlay&&this.width>1&&(a!==this.width||o!==this.height)&&(this.originScroll.x+=(this.width-a)/2,this.originScroll.y+=(this.height-o)/2),this.width=a,this.height=o;let s=Math.min(e,t);this.baseZoom=this.canvasWorld?28:this.overlay?Math.max(14,Math.min(28,s/11)):Math.max(1,Math.min(s<600?32:28,(s-32)/10,s/25)),this.zoom=this.baseZoom*(this.canvasWorld||this.overlay?1:this.slowMoZoom),this.overlay&&this.regionScale===1&&!this.virtualScroll.x&&!this.virtualScroll.y&&(this.pageSize={width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight}),this.smokeMargin=this.canvasWorld?96/this.regionScale:this.pixelSpace?Math.min(112,Math.max(72,Math.min(this.width,this.height)*.1)):0;let c=this.width*this.height;this.dpr=Math.min(2*(this.canvasWorld?this.regionScale:1),n*this.regionScale,Math.sqrt(24e6/c),16384/Math.max(this.width,this.height))}outputWidth=1;outputHeight=1;cameraRotation=0;cameraLock=!1;cameraSmoothing=.25;cameraLockInitialized=!1;width=1;height=1;dpr=1;smokeMargin=0;pageScene=new ie;cameraRegions=new Os(this.pageScene);get documentProjection(){return this.pageScene}activeCameraRegion=null;regionScale=1;canvasWorldScale=1;cameraFrame=null;camera=S();zoom=28;baseZoom=28;slowMoScale=1;get slowMoZoom(){return this.slowMoScale??1}set slowMoZoom(e){this.slowMoScale=e}zoomAnchor=S();pageSize={width:1,height:1};lastFrame=0;originScroll=S();observedScroll=S();virtualScroll=S();followInterrupted=!1;deadZone=!0;screen(e){return S(this.width/2+(e.x-this.camera.x)*this.zoom,this.height/2-(e.y-this.camera.y)*this.zoom)}world(e){return S(this.camera.x+(e.x-this.width/2)/this.zoom,this.camera.y-(e.y-this.height/2)/this.zoom)}vehicleViewportPosition(e){return this.overlay&&this.syncScroll(),this.screen(e)}sceneScroll(){return this.canvasWorld?S(this.camera.x*28-this.width/2,-this.camera.y*28-this.height/2):x(O(),this.virtualScroll)}virtualOffset(){return{...this.virtualScroll}}documentPoint(e){return this.canvasWorld?re(e):(this.overlay&&this.syncScroll(),x(this.screen(e),this.sceneScroll()))}worldFromDocument(e){return this.canvasWorld?me(e):(this.overlay&&this.syncScroll(),this.world(b(e,this.sceneScroll())))}documentScale(){return this.canvasWorld?28:this.zoom}particlePoint(e){return this.pixelSpace?this.documentPoint(e):{...e}}particleScale(){return this.pixelSpace?this.documentScale():1}viewportSize(){return{width:this.width,height:this.height}}presentationScale(){return this.regionScale}setCanvasWorldScale(e,t=1.5){if(!this.canvasWorld)return;this.canvasWorldScale=Math.max(.2,Math.min(Math.max(.2,Math.min(4,Number.isFinite(t)?t:1.5)),Number.isFinite(e)?e:1));let n=this.canvasWorldScale*this.slowMoZoom;this.regionScale!==n&&(this.regionScale=n,this.resize())}setCameraFrame(e){this.cameraFrame=e,this.canvasWorld&&this.cameraLock&&this.resize()}setCameraLock(e){this.canvasWorld&&this.cameraLock!==e&&(this.cameraLock=e,this.cameraLockInitialized=!1,e||(this.cameraRotation=0),this.resize())}viewportFromDocument(e){let t=_(b(e,this.sceneScroll()),this.regionScale);return this.canvasWorld&&this.cameraLock?xs(t,Cs(this.width,this.height,this.regionScale),ys(this.outputWidth,this.outputHeight,this.cameraFrame),this.cameraRotation):t}documentFromViewport(e){let t=this.canvasWorld&&this.cameraLock?Ss(e,Cs(this.width,this.height,this.regionScale),ys(this.outputWidth,this.outputHeight,this.cameraFrame),this.cameraRotation):e;return x(_(t,1/this.regionScale),this.sceneScroll())}bounds(){this.overlay&&this.syncScroll();let e=this.width/(2*this.zoom)-3/this.zoom,t=this.height/(2*this.zoom)-3/this.zoom;return{left:this.camera.x-e,right:this.camera.x+e,bottom:this.camera.y-t,top:this.camera.y+t}}setVirtualScroll(e){if(!this.overlay)return;this.virtualScroll=S(Math.abs(e.x)<.01?0:e.x,Math.abs(e.y)<.01?0:e.y);let t=document.body;this.virtualScroll.x||this.virtualScroll.y?(t.dataset.jrVirtualCamera===void 0&&(t.dataset.jrVirtualCamera=``),t.style.setProperty(`--joy-ride-scene-x`,`${-this.virtualScroll.x}px`),t.style.setProperty(`--joy-ride-scene-y`,`${-this.virtualScroll.y}px`)):(t.dataset.jrVirtualCamera!==void 0&&delete t.dataset.jrVirtualCamera,t.style.removeProperty(`--joy-ride-scene-x`),t.style.removeProperty(`--joy-ride-scene-y`))}syncScroll(e=!1){let t=S(O().x,O().y);if(!e){let e=b(t,this.observedScroll);p(e)>.5&&(this.followInterrupted=!0)}this.observedScroll=t,(this.activeCameraRegion||this.regionScale!==1)&&this.pageScene?.apply(this.regionScale,this.sceneScroll());let n=x(t,this.virtualScroll);this.camera=S((n.x-this.originScroll.x-this.zoomAnchor.x*(this.baseZoom-this.zoom))/this.zoom,-(n.y-this.originScroll.y+this.zoomAnchor.y*(this.baseZoom-this.zoom))/this.zoom)}resumeFollow(){this.vehicleReveal=null,this.overlay&&(this.syncScroll(),this.followInterrupted=!1)}interruptFollow(){this.vehicleReveal=null,this.overlay&&(this.followInterrupted=!0)}restorePage(e){if(!this.overlay||!this.virtualScroll.x&&!this.virtualScroll.y&&!this.activeCameraRegion&&this.regionScale===1)return!1;this.syncScroll(!0);let t=_(this.screen(e.body.position),this.regionScale??1);return(this.activeCameraRegion||this.regionScale!==1)&&(this.slowMoZoom=1,this.pageScene.clear(),this.activeCameraRegion=null,this.regionScale=1,this.resize()),this.setVirtualScroll(S()),this.syncScroll(!0),e.body.position=this.world(t),!0}followDocument(e){if(!this.overlay)return!1;if(this.vehicleReveal||this.activeCameraRegion?.fixed)return!0;if(this.zoomAnchor={...e.body.position},this.syncScroll(),this.followInterrupted)return!1;let t=this.screen(e.body.position),n=Math.max(e.car.preset.geometry.lengthM*this.zoom/2+12,Math.min(this.width,this.height)*.25),r=Ts(t,{width:this.width,height:this.height},n);if(r.x||r.y){if(e.barrier)window.scrollBy({left:r.x,top:r.y,behavior:`instant`}),de();else{let e=S(r.x*this.virtualScroll.x<0?Math.sign(r.x)*Math.min(Math.abs(r.x),Math.abs(this.virtualScroll.x)):0,r.y*this.virtualScroll.y<0?Math.sign(r.y)*Math.min(Math.abs(r.y),Math.abs(this.virtualScroll.y)):0);this.setVirtualScroll(x(this.virtualScroll,e));let t=b(r,e),n=O();(t.x||t.y)&&(window.scrollBy({left:t.x,top:t.y,behavior:`instant`}),de());let i=b(O(),n);this.setVirtualScroll(x(this.virtualScroll,b(t,i)))}}return this.syncScroll(!0),!0}moveSceneTo(e){window.scrollBy({left:e.x-O().x,top:e.y-O().y,behavior:`instant`}),de(),this.setVirtualScroll(S(e.x-O().x,e.y-O().y)),this.syncScroll(!0)}updateCameraRegion(e,t){let n=this.cameraFrame??{x:0,y:0,width:window.innerWidth,height:window.innerHeight},r=this.activeCameraRegion!==null&&!e,i=e!==null&&this.activeCameraRegion?.element!==e.element,a=(e?e.fixed?Es(e.bounds,n,e.zoom):Math.max(.1,Math.min(3,e.zoom??1)):1)*this.slowMoZoom,o=this.regionScale,s=_(b(t,this.sceneScroll()),o);if(this.activeCameraRegion=e,r&&this.pageScene.clear(),Math.abs(a-this.regionScale)>1e-4&&(this.regionScale=a,this.resize()),e?.fixed){this.zoom=this.baseZoom;let t=e.bounds;this.moveSceneTo(S(t.x+t.width/2-(n.x+n.width/2)/this.regionScale,t.y+t.height/2-(n.y+n.height/2)/this.regionScale))}else(r||i)&&(this.followInterrupted=!1,this.moveSceneTo(S(t.x-this.width/2,t.y-this.height/2)));!e?.fixed&&!r&&!i&&Math.abs(a-o)>1e-4&&this.moveSceneTo(b(t,_(s,1/a))),e||a!==1?this.pageScene.apply(this.regionScale,this.sceneScroll()):this.pageScene.clear()}cameraStep(e,t){let n=this.lastFrame?y((t-this.lastFrame)/1e3,0,.1):1/60;this.lastFrame=t;let r=e.body;if(this.canvasWorld){if(this.cameraLock){let e=r.angle-Math.PI/2,t=!this.cameraLockInitialized||p(b(r.position,this.camera))>40;this.cameraRotation=t?e:ws(this.cameraRotation,e,n,this.cameraSmoothing),t&&(this.camera={...r.position}),this.cameraLockInitialized=!0}else this.cameraRotation=0}let i=S(this.width/2+r.position.x*this.baseZoom+this.originScroll.x,this.height/2-r.position.y*this.baseZoom+this.originScroll.y),a=this.overlay?this.cameraRegions.at(i,this.virtualScroll,t):null;this.overlay&&this.updateCameraRegion(a,i);let o=this.zoom;if(this.canvasWorld){let e=this.canvasWorldScale*this.slowMoZoom;Math.abs(this.regionScale-e)>1e-4&&(this.regionScale=e,this.resize()),this.zoom=this.baseZoom}else this.zoom=this.baseZoom*(this.overlay?1:this.slowMoZoom);if(this.overlay){this.zoomAnchor={...r.position},this.syncScroll(),this.advanceVehicleReveal(t,e);return}if(e.barrier)return;let s=o/this.zoom;if(this.camera=S(r.position.x-(r.position.x-this.camera.x)*s,r.position.y-(r.position.y-this.camera.y)*s),this.canvasWorld&&this.cameraLock){let e=this.cameraSmoothing<=0?1:1-Math.exp(-n/this.cameraSmoothing);this.camera=x(this.camera,_(b(r.position,this.camera),e));return}if(!this.deadZone){let e=this.canvasWorld&&!this.cameraLock?this.cameraFrame:null;this.camera=e?S(r.position.x-((e.x+e.width/2)/this.regionScale-this.width/2)/this.zoom,r.position.y+((e.y+e.height/2)/this.regionScale-this.height/2)/this.zoom):{...r.position};return}let c=this.width*.18/this.zoom,l=this.height*.18/this.zoom,u=S(r.position.x-y(r.position.x-this.camera.x,-c,c),r.position.y-y(r.position.y-this.camera.y,-l,l));this.camera=x(this.camera,_(b(u,this.camera),1-Math.exp(-16*n)))}},As=class{canvas;camera;overlay;canvasWorld;sceneCanvas=null;sceneContext;documentOrigin={x:0,y:0};originalPosition;constructor(e,t,n,r){this.canvas=e,this.camera=t,this.overlay=n,this.canvasWorld=r;let i=e.getContext(`2d`);if(!i)throw Error(`Joy Ride requires a 2D canvas context.`);this.sceneContext=i,this.originalPosition={position:e.style.position,left:e.style.left,top:e.style.top,translate:e.style.translate}}setAbsoluteViewport(){this.overlay&&(this.canvas.style.position=`absolute`,this.measureDocumentOrigin(),this.place())}measureDocumentOrigin(){if(!this.overlay)return;if(!this.canvas.offsetParent){this.documentOrigin={x:0,y:0};return}let e=this.canvas.offsetParent,t=e.getBoundingClientRect(),n=O();this.documentOrigin={x:t.left+n.x+e.clientLeft,y:t.top+n.y+e.clientTop}}place(){if(!this.overlay)return;let e=O();this.canvas.style.left!==`0px`&&(this.canvas.style.left=`0px`),this.canvas.style.top!==`0px`&&(this.canvas.style.top=`0px`);let t=`${e.x-this.documentOrigin.x}px ${e.y-this.documentOrigin.y}px`;this.canvas.style.translate!==t&&(this.canvas.style.translate=t)}get context(){return this.sceneContext}resize(){let e=Math.max(1,this.overlay?window.innerWidth:this.canvas.clientWidth),t=Math.max(1,this.overlay?window.innerHeight:this.canvas.clientHeight),n=e/this.camera.regionScale!==this.camera.width||t/this.camera.regionScale!==this.camera.height;this.camera.resizeLayout(e,t,window.devicePixelRatio||1);let r=this.canvasWorld&&this.camera.cameraLock;r?(this.sceneCanvas??=document.createElement(`canvas`),this.sceneContext=this.sceneCanvas.getContext(`2d`)):this.sceneCanvas&&(this.sceneContext=this.canvas.getContext(`2d`)),this.overlay&&(n||this.canvas.style.width!==`${this.camera.width}px`)&&(this.canvas.style.width=`${this.camera.width}px`,this.canvas.style.height=`${this.camera.height}px`,this.canvas.style.transformOrigin=`0 0`,this.canvas.style.scale=String(this.camera.regionScale));let i=Math.round(this.camera.width*this.camera.dpr),a=Math.round(this.camera.height*this.camera.dpr),o=r?this.sceneCanvas:this.canvas;if((o.width!==i||o.height!==a)&&(o.width=i,o.height=a),r){let n=this.camera.dpr/this.camera.regionScale,r=Math.round(e*n),i=Math.round(t*n);this.canvas.width!==r&&(this.canvas.width=r),this.canvas.height!==i&&(this.canvas.height=i)}return this.sceneContext.setTransform(this.camera.dpr,0,0,this.camera.dpr,0,0),this.measureDocumentOrigin(),this.canvasWorld?this.camera.dpr:void 0}clear(){this.place(),this.sceneContext.setTransform(this.camera.dpr,0,0,this.camera.dpr,0,0),this.sceneContext.clearRect(0,0,this.camera.width,this.camera.height)}presentLockedCamera(){if(!this.canvasWorld||!this.camera.cameraLock||!this.sceneCanvas)return;let e=this.canvas.getContext(`2d`),t=this.camera.dpr/this.camera.regionScale,n=ys(this.camera.outputWidth,this.camera.outputHeight,this.camera.cameraFrame);e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,this.canvas.width,this.canvas.height),e.save(),e.translate(n.x*t,n.y*t),e.rotate(this.camera.cameraRotation),e.drawImage(this.sceneCanvas,-this.sceneCanvas.width/2,-this.sceneCanvas.height/2),e.restore()}dispose(){this.sceneCanvas&&=(this.sceneCanvas.width=1,this.sceneCanvas.height=1,null),this.canvas.style.scale=``,this.canvas.style.transformOrigin=``,this.overlay&&(this.canvas.style.position=this.originalPosition.position,this.canvas.style.left=this.originalPosition.left,this.canvas.style.top=this.originalPosition.top,this.canvas.style.translate=this.originalPosition.translate)}},js=class{frameRate=new pe;captureState(){return this.frameRate.captureState()}restoreState(e){this.frameRate.restoreState(e)}draw(e,t,n,r,i){let a=e,o=t.body,s=this.frameRate.sample(n);a.save();let c=He(t.car.preset);for(let e of t.car.tires){let t=r(o.world(e.local));a.strokeStyle=e.front?`#00dcff`:`#ffae31`,a.lineWidth=2;let n=[S(-c.length/2,-c.width/2),S(c.length/2,-c.width/2),S(c.length/2,c.width/2),S(-c.length/2,c.width/2)].map(t=>r(o.world(x(e.local,m(t,e.angle)))));a.beginPath(),n.forEach((e,t)=>t?a.lineTo(e.x,e.y):a.moveTo(e.x,e.y)),a.closePath(),a.stroke(),a.beginPath(),a.arc(t.x,t.y,4,0,Math.PI*2),a.stroke(),a.beginPath(),a.moveTo(t.x-7,t.y),a.lineTo(t.x+7,t.y),a.moveTo(t.x,t.y-7),a.lineTo(t.x,t.y+7),a.stroke(),a.font=`bold 10px ui-monospace, SFMono-Regular, monospace`,a.fillStyle=e.front?`#007e91`:`#895000`,a.fillText(`${e.front?`F`:`R`}${e.local.y>0?`L`:`R`}${e.skidding?` SKID`:``}`,t.x+8,t.y-8)}let l=r(o.position),u=(e,t,n)=>{let r=x(l,_(e,n));a.strokeStyle=t,a.fillStyle=t,a.lineWidth=2.5,a.beginPath(),a.moveTo(l.x,l.y),a.lineTo(r.x,r.y),a.stroke();let i=Math.atan2(e.y,e.x);a.beginPath(),a.moveTo(r.x,r.y),a.lineTo(r.x-Math.cos(i-.5)*9,r.y-Math.sin(i-.5)*9),a.lineTo(r.x-Math.cos(i+.5)*9,r.y-Math.sin(i+.5)*9),a.closePath(),a.fill()};u(S(Math.cos(o.angle),-Math.sin(o.angle)),`#00c4df`,67);let d=p(o.velocity);d>.2&&u(S(o.velocity.x/d,-o.velocity.y/d),`#f05bd6`,48+Math.min(32,d));let f=Math.atan2(o.velocity.y,o.velocity.x),h=Math.atan2(Math.sin(o.angle-f),Math.cos(o.angle-f)),g=Math.max(...t.car.tires.filter(e=>e.front).map(e=>e.gripUtilization)),v=Math.max(...t.car.tires.filter(e=>!e.front).map(e=>e.gripUtilization)),y=t.car.tires.map(e=>`${e.front?`F`:`R`}${e.local.y>0?`L`:`R`} ${e.slipSpeedMps.toFixed(1)}${e.skidding?`*`:``}`).join(` `),b=[`${t.car.preset.name} · ${(d*3.6).toFixed(0)} km/h · ${Math.round(s)} FPS`,`input T ${t.lastInput.throttle} S ${t.lastInput.steer} brake ${Number(t.lastInput.action)}`,`body ${Math.round(o.angle*180/Math.PI)}° travel ${Math.round(f*180/Math.PI)}° slip ${Math.round(h*180/Math.PI)}°`,`front load ${(t.car.frontLoadFraction*100).toFixed(0)}% burnout ${Number(t.car.burnout)} charge ${t.car.boostCharge.toFixed(2)}`,`grip use F ${g.toFixed(2)} R ${v.toFixed(2)} drift ${Number(t.car.drifting)} donut ${Number(t.car.donuting)}`,`drift ${Number(t.car.fastDrifting)} countersteer ${Number(t.car.countersteering)}`,`roof rocket ${i.rocketState}`,`side guns ${i.gunState} · ${i.bulletCount} bullets`,`tire slip m/s ${y}`,`fluid ${i.fluidEngine} ${i.quality} ${i.fluidCols}×${i.fluidRows}`,`shared fire ${i.fireCols}×${i.fireRows} · ${i.groundedFireCount} grounded sources`,`cyan = nose/shape pink = travel amber = walls`,`wheel cyan = front wheel amber = rear violet = letters`];a.fillStyle=`rgba(10, 21, 24, 0.87)`,a.fillRect(12,88,Math.min(430,i.width-24),b.length*18+18),a.font=`12px ui-monospace, SFMono-Regular, monospace`,a.fillStyle=`#f1f5f3`,b.forEach((e,t)=>a.fillText(e,22,110+t*18)),a.restore()}},K=1024,Ms=Math.PI*2,Ns=Array.from({length:K},(e,t)=>({x:Math.cos(t/K*Ms),y:Math.sin(t/K*Ms)}));function Ps(e,t,n){return n.filter(n=>{let r=Math.max(n.x-e.x,0,e.x-n.x-n.width),i=Math.max(n.y-e.y,0,e.y-n.y-n.height);return n.width>0&&n.height>0&&r*r+i*i<=t*t})}function Fs(e,t,n){let r=Math.abs(t.x)<1e-8,i=Math.abs(t.y)<1e-8;if(r&&(e.x<n.x||e.x>n.x+n.width)||i&&(e.y<n.y||e.y>n.y+n.height))return 1/0;let a=r?-1/0:(n.x-e.x)/t.x,o=r?1/0:(n.x+n.width-e.x)/t.x,s=i?-1/0:(n.y-e.y)/t.y,c=i?1/0:(n.y+n.height-e.y)/t.y,l=Math.max(0,Math.min(a,o),Math.min(s,c));return l<=Math.min(Math.max(a,o),Math.max(s,c))?l:1/0}function Is(e,t,n){let r=Ps(e,t,n);if(!r.length)return;let i=new Float32Array(K);for(let n=0;n<i.length;n++){let a=t;for(let t of r)a=Math.min(a,Fs(e,Ns[n],t));i[n]=a/t}return{range:t,distances:i}}function Ls(e,t,n,r){for(let i of Ps(t,n,r)){if(t.x>=i.x&&t.x<=i.x+i.width&&t.y>=i.y&&t.y<=i.y+i.height){e.beginPath(),e.clip();return}let r=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],a=e=>{let r=1+n*4/Math.max(.001,Math.hypot(e.x-t.x,e.y-t.y));return{x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r}};for(let i=0;i<r.length;i++){let o=r[i],s=r[(i+1)%r.length];if((s.x-o.x)*(t.y-o.y)-(s.y-o.y)*(t.x-o.x)>=0)continue;let c=a(o),l=a(s);e.beginPath(),e.rect(t.x-n,t.y-n,n*2,n*2),e.moveTo(o.x,o.y),e.lineTo(s.x,s.y),e.lineTo(l.x,l.y),e.lineTo(c.x,c.y),e.closePath(),e.clip(`evenodd`)}}}var Rs=[.82,.91,1],zs=[1,.045,.018],Bs=e=>Math.max(0,Math.min(1,e));function Vs(e){let t=/^#([\da-f]{6})$/i.exec(e);if(!t)return[.4,.9,1];let n=parseInt(t[1],16);return[(n>>16)/255,(n>>8&255)/255,(n&255)/255]}function Hs(e,t,n){let r=Math.cos(e.angle),i=Math.sin(e.angle);return{x:e.center.x+r*t-i*n,y:e.center.y+i*t+r*n}}var Us=class{sprites=new WeakMap;halos=new WeakMap;beam=null;sprite(e){let t=e.image;if(!t||!t.complete||!t.naturalWidth)return null;let n=e.source??{x:0,y:0,width:t.naturalWidth,height:t.naturalHeight},r=e.mounts.taillights.map(t=>`${Math.round(t.x/e.width*1e4)},${Math.round(t.y/e.height*1e4)}`).join(`;`),i=`${n.x},${n.y},${n.width},${n.height}|${r}`,a=this.sprites.get(t);if(a||(a=new Map,this.sprites.set(t,a)),a.has(i))return a.get(i)??null;let o=document.createElement(`canvas`);o.width=192,o.height=Math.max(24,Math.round(192*n.height/n.width));let s=o.getContext(`2d`,{willReadFrequently:!0});if(!s)return a.set(i,null),null;s.drawImage(t,n.x,n.y,n.width,n.height,0,0,o.width,o.height);let c;try{c=s.getImageData(0,0,o.width,o.height)}catch{return a.set(i,null),null}let l=s.createImageData(o.width,o.height),u=0;for(let t=0;t<o.height;t++)for(let n=0;n<o.width;n++){let r=(t*o.width+n)*4,i=c.data[r],a=c.data[r+1],s=c.data[r+2],d=c.data[r+3];n<o.width*.27&&i>100&&i>a*1.6&&i>s*1.5&&d>100&&e.mounts.taillights.some(r=>{let i=n-(.5+r.x/e.width)*o.width,a=t-(.5+r.y/e.height)*o.height;return i*i+a*a<(o.height*.18)**2})&&(l.data[r]=255,l.data[r+1]=22,l.data[r+2]=5,l.data[r+3]=Math.min(235,d),u++),c.data[r]=255,c.data[r+1]=255,c.data[r+2]=255,c.data[r+3]=d>90?255:0}s.putImageData(c,0,0);let d=null;u>1&&u<o.width*o.height*.055&&(d=document.createElement(`canvas`),d.width=o.width,d.height=o.height,d.getContext(`2d`)?.putImageData(l,0,0));let f={silhouette:o,brakes:d};return a.size>=8&&a.clear(),a.set(i,f),f}halo(e,t){let n=this.halos.get(e);n||(n=new Map,this.halos.set(e,n));let r=n.get(t);if(r)return r;let i=document.createElement(`canvas`);i.width=e.width+64,i.height=e.height+64;let a=i.getContext(`2d`);a.drawImage(e,32,32),a.globalCompositeOperation=`source-in`,a.fillStyle=t,a.fillRect(0,0,i.width,i.height),a.globalCompositeOperation=`source-over`;let o=document.createElement(`canvas`);o.width=i.width,o.height=i.height,o.getContext(`2d`).drawImage(i,0,0),a.clearRect(0,0,i.width,i.height),a.filter=`blur(14px)`,a.globalAlpha=.92,a.drawImage(o,-2,-5,o.width+4,o.height+10),a.filter=`blur(7px)`,a.globalAlpha=.9,a.drawImage(o,0,0),a.filter=`blur(3px)`,a.globalAlpha=.8,a.strokeStyle=t,a.lineWidth=3,a.lineCap=`round`;for(let t of[-1,1])a.beginPath(),a.moveTo(32+e.width*.18,32+e.height*(.5+t*.34)),a.lineTo(32+e.width*.82,32+e.height*(.5+t*.34)),a.stroke();return a.filter=`none`,a.globalAlpha=1,n.size>8&&n.clear(),n.set(t,i),i}beamImage(){if(this.beam)return this.beam;let e=document.createElement(`canvas`);e.width=256,e.height=128;let t=e.getContext(`2d`),n=t.createImageData(e.width,e.height);for(let t=0;t<e.height;t++)for(let r=0;r<e.width;r++){let i=r/e.width,a=(t/e.height-.5)*2,o=.035+i*.94,s=Bs((1-i)/.4),c=Math.exp(-a*a/(o*o))*s*s*(3-2*s),l=(t*e.width+r)*4;n.data[l]=210,n.data[l+1]=230,n.data[l+2]=255,n.data[l+3]=Math.round(c*255)}return t.putImageData(n,0,0),this.beam=e,e}clip(e,t,n,r){t.walls?.length&&(e.rotate(-t.angle),e.translate(-t.center.x,-t.center.y),Ls(e,Hs(t,n.x,n.y),r,t.walls),e.translate(t.center.x,t.center.y),e.rotate(t.angle))}ground(e,t){let n=t.opacity??1,r=t.options.brakeLights?Bs(t.braking):0;if(!(n<=0||t.width<=0)){if(e.save(),e.translate(t.center.x,t.center.y),e.rotate(t.angle),e.globalCompositeOperation=`screen`,t.dark&&t.options.underglow&&t.options.underglowOpacity>0){e.save(),this.clip(e,t,{x:0,y:0},t.width*1.5);let r=this.sprite(t);if(e.globalAlpha=Bs(t.options.underglowOpacity)*n,r){let n=this.halo(r.silhouette,t.options.underglow),i=32/r.silhouette.width*t.width,a=32/r.silhouette.height*t.height;e.drawImage(n,-t.width/2-i,-t.height/2-a,t.width+i*2,t.height+a*2)}else e.shadowColor=t.options.underglow,e.shadowBlur=t.height*.5,e.fillStyle=t.options.underglow,e.beginPath(),e.roundRect(-t.width*.43,-t.height*.38,t.width*.86,t.height*.76,t.height*.22),e.fill(),e.shadowBlur=0;e.restore()}if(t.dark&&t.options.headlights)for(let r of t.mounts.headlights)e.save(),this.clip(e,t,r,t.width*6.2),e.globalAlpha=.085*n,e.drawImage(this.beamImage(),r.x,r.y-t.width*.68,t.width*5.7,t.width*1.36),e.restore();if(t.dark&&t.options.taillights||r>0){let i=r;for(let{x:r,y:a}of t.mounts.taillights){let o=t.height*(.48+i*.38);e.save(),this.clip(e,t,{x:r,y:a},o),e.globalAlpha=.1;let s=e.createRadialGradient(r,a,0,r,a,o),c=(t.dark?.12+i*.19:i*.13)*n;s.addColorStop(0,`rgba(255,30,8,${c})`),s.addColorStop(1,`rgba(255,20,4,0)`),e.fillStyle=s,e.fillRect(r-o,a-o,o*2,o*2),e.restore()}}e.restore()}}glints(e,t){e.save(),e.translate(t.center.x,t.center.y),e.rotate(t.angle),e.globalCompositeOperation=`screen`;let n=t.opacity??1,r=t.options.brakeLights?Bs(t.braking):0;if(r>0){let i=this.sprite(t)?.brakes;i&&(e.globalAlpha=r*n*(t.dark?.9:.52),e.shadowColor=`#ff250d`,e.shadowBlur=t.height*(t.dark?.16:.055),e.drawImage(i,-t.width/2,-t.height/2,t.width,t.height))}for(let i of[!0,!1])if(!(i?!(t.dark&&t.options.headlights):!(t.dark&&t.options.taillights||r>0)))for(let a of t.mounts[i?`headlights`:`taillights`]){e.save(),e.globalAlpha=n*(i?.75:t.dark?.34+r*.6:r*.45);let o=t.height*(i?.15:.12);this.clip(e,t,a,o);let s=e.createRadialGradient(a.x,a.y,0,a.x,a.y,o);s.addColorStop(0,i?`#e6f1ffd9`:`#ff3518c0`),s.addColorStop(.28,i?`#c1dcff70`:`#ff230760`),s.addColorStop(1,i?`#c1dcff00`:`#ff230700`),e.fillStyle=s,e.beginPath(),e.arc(a.x,a.y,o,0,Math.PI*2),e.fill(),e.restore()}e.restore()}smokeLights(e){let t=[],n={x:Math.cos(e.angle),y:Math.sin(e.angle)},r=e.opacity??1,i=e.options.brakeLights?Bs(e.braking):0;if(e.dark&&e.options.headlights)for(let i of e.mounts.headlights)t.push({point:Hs(e,i.x,i.y),direction:n,color:Rs,range:e.width*6.2,radius:e.height*.075,spread:.14,intensity:1.7*r});if(e.dark&&e.options.taillights||i>0)for(let a of e.mounts.taillights)t.push({point:Hs(e,a.x,a.y),direction:{x:-n.x,y:-n.y},color:zs,range:e.width*(i>0?1.6:.9),radius:e.height*.15,spread:.46,intensity:r*(e.dark?.24+i*.85:i*.42)});if(e.dark&&e.options.underglow&&e.options.underglowOpacity>0)for(let n of[-.27,0,.27])t.push({point:Hs(e,e.width*n,0),direction:{x:0,y:0},color:Vs(e.options.underglow),range:e.height,radius:e.height*.8,spread:0,intensity:r*e.options.underglowOpacity*.8});return t.map(t=>{let n=Is(t.point,Math.max(t.range,t.radius*4),e.walls??[]);return n?{...t,shadow:n}:t})}},Ws={light:{ink:`#161c17`,alphaScale:1},dark:{ink:`#a9adb0`,alphaScale:1.7}};function Gs(e){let t=e.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);if(!t)return!1;let[,n,r,i]=t.map(Number);return n*.2126+r*.7152+i*.0722<112}function Ks(e){let t=0,n=0,r=0,i=0;for(let a of e.layers){let e=`layers`in a?Ks(a):[a.color[0]*a.alpha,a.color[1]*a.alpha,a.color[2]*a.alpha,a.alpha];if(t+=(1-i)*e[0],n+=(1-i)*e[1],r+=(1-i)*e[2],i+=(1-i)*e[3],i>=.9999)break}return[t*e.opacity,n*e.opacity,r*e.opacity,i*e.opacity]}function qs(e,t=!1){let n={opacity:1,layers:[]},r=new Map,i=new Map,a=e=>{let t=r.get(e);return t||(t=getComputedStyle(e),r.set(e,t)),t},o=e=>{let t=i.get(e);if(t)return t;let r=e.parentElement?o(e.parentElement):n,s=Number.parseFloat(a(e).opacity),c=Number.isFinite(s)?Math.max(0,Math.min(1,s)):1,l=r;return c<1&&(l={opacity:c,layers:[]},r.layers.push(l)),i.set(e,l),l};for(let t of document.elementsFromPoint(e.x,e.y)){if(!(t instanceof HTMLElement)||t.closest(`[data-jr-overlay],[data-jr-embed],[data-jr-touch-controls]`))continue;let e=ce(a(t).backgroundColor);if(!e||e.alpha<=0)continue;let n=e.color.match(/[\d.]+/g).slice(0,3).map(Number);o(t).layers.push({color:n,alpha:e.alpha})}let[s,c,l,u]=Ks(n);if(u<=0)return null;let d=t?0:255;return Gs(`rgb(${s+d*(1-u)} ${c+d*(1-u)} ${l+d*(1-u)})`)}var Js=class{resolve;samples=new WeakMap;constructor(e=qs){this.resolve=e}at(e,t,n,r=performance.now()){let i=this.samples.get(e);if(i&&i.fallback===n&&r-i.at<80&&Math.hypot(t.x-i.x,t.y-i.y)<48)return i.dark;let a=this.resolve(t,n)??n;return this.samples.set(e,{x:t.x,y:t.y,at:r,dark:a,fallback:n}),a}},Ys=64,Xs=e=>e.width>0&&e.height>0&&e.width<=64&&e.height<=64&&e.pixelWidth<=128&&e.pixelHeight<=128&&e.fixedRadius===void 0&&e.blastAge===void 0&&!e.smokeOnly,Zs=class{groups=new Map;combine(e,t,n){let r=e.filter(Xs);if(r.length<Ys)return[...e];let i=Math.ceil(t/2),a=Math.ceil(n/2),o=e.filter(e=>!Xs(e)),s=new Map;for(let e of r){let t=Math.max(0,Math.min(.999,e.age/Math.max(.01,e.burnSeconds))),n=Math.floor(t*4),r=s.get(n)??[];r.push(e),s.set(n,r)}for(let[e,r]of s){let s=this.groups.get(e);s&&s.alpha.length===i*a||(s={key:{},alpha:new Uint8Array(i*a),revision:0},this.groups.set(e,s)),s.alpha.fill(0);let c=!1;for(let e of r)c=this.rasterize(s.alpha,i,a,e,t,n)||c;if(!c)continue;s.revision++;let l=r.reduce((e,t)=>e+t.age/Math.max(.01,t.burnSeconds),0)/r.length;o.push({key:s.key,alpha:s.alpha,pixelWidth:i,pixelHeight:a,x:0,y:0,width:t,height:n,origin:{x:t/2,y:n/2},age:l,farthest:Math.max(t,n),spreadSeconds:0,burnSeconds:1,smokeRate:r.reduce((e,t)=>e+(t.smokeRate??13),0)/r.length,revision:s.revision})}return o}rasterize(e,t,n,r,i,a){let o=t/i,s=n/a,c=r.x+r.width/2,l=r.y+r.height/2,u=Math.cos(r.angle??0),d=Math.sin(r.angle??0),f=Math.hypot(r.width,r.height)/2,p=Math.max(0,Math.floor((c-f)*o)),m=Math.min(t-1,Math.ceil((c+f)*o)),h=Math.max(0,Math.floor((l-f)*s)),g=Math.min(n-1,Math.ceil((l+f)*s)),_=!1;for(let n=h;n<=g;n++){let i=(n+.5)/s-l;for(let a=p;a<=m;a++){let s=(a+.5)/o-c,l=s*u+i*d+r.width/2,f=-s*d+i*u+r.height/2;if(l<0||l>=r.width||f<0||f>=r.height)continue;let p=Math.floor(l/r.width*r.pixelWidth),m=Math.floor(f/r.height*r.pixelHeight),h=Math.round((r.alpha[m*r.pixelWidth+p]??0)*(r.intensity??1)),g=n*t+a;h>e[g]&&(e[g]=h),_||=h>0}}return _}},Qs=class{points=[];get count(){return this.points.length}get managedBytes(){return this.points.length*40}captureState(){return{points:this.points.map(({point:e,...t})=>({point:{...e},...t})),dispose:()=>void 0}}restoreState(e){this.points=e?.points.map(({point:e,...t})=>({point:{...e},...t}))??[]}reset(){this.points=[]}dispose(){this.reset()}ignite(e,t,n,r,i){let a=b(t,e),o=Math.max(1,Math.ceil(p(a)/Math.max(1,i)));for(let t=1;t<=o;t++)this.points.push({point:x(e,_(a,t/o)),width:n,age:0,lifetime:r});this.points.length>1200&&this.points.splice(0,this.points.length-1200)}step(e){let t=0;for(let n of this.points)n.age+=e,n.age<n.lifetime&&(this.points[t++]=n);this.points.length=t}stamps(){return this.points.map(({point:e,width:t,age:n,lifetime:r})=>({point:e,radius:Math.max(5,t*.8),progress:.42,flow:S(0,-25),strength:Math.max(0,1-(n/r)**2)*1.85,stir:!1}))}emberSource(){if(!this.points.length)return null;let e=this.points[Math.floor(Math.random()*this.points.length)];return{point:e.point,radius:e.width*.42,heat:Math.max(0,1-(e.age/e.lifetime)**2)}}},$s=3.2;function ec(e,t,n){let r=Math.max(0,Math.min(1,(n-e)/(t-e)));return r*r*(3-2*r)}function tc(e){return{dissipation:.55+2.3*ec(1.35,2.65,e),opacity:1-ec(2.25,$s,e)}}var nc=class{gl;width;height;texture;framebuffer;disposed=!1;constructor(e,t,n,r,i,a){this.gl=e,this.width=n,this.height=r;let o=e.createTexture(),s=e.createFramebuffer();if(!o||!s)throw o&&e.deleteTexture(o),s&&e.deleteFramebuffer(s),Error(`Unable to allocate GPU checkpoint`);this.texture=o,this.framebuffer=s;let c=e.getParameter(e.READ_FRAMEBUFFER_BINDING),l=e.getParameter(e.DRAW_FRAMEBUFFER_BINDING),u=e.getParameter(e.TEXTURE_BINDING_2D);try{if(e.bindTexture(e.TEXTURE_2D,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),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.texImage2D(e.TEXTURE_2D,0,i,n,r,0,e.RGBA,a,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,s),e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),e.checkFramebufferStatus(e.DRAW_FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)throw Error(`GPU checkpoint target is incomplete`);if(e.bindFramebuffer(e.READ_FRAMEBUFFER,t),e.blitFramebuffer(0,0,n,r,0,0,n,r,e.COLOR_BUFFER_BIT,e.NEAREST),e.getError()!==e.NO_ERROR)throw Error(`GPU checkpoint copy failed`)}catch(t){throw e.deleteFramebuffer(s),e.deleteTexture(o),t}finally{e.bindFramebuffer(e.READ_FRAMEBUFFER,c),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,l),e.bindTexture(e.TEXTURE_2D,u)}}restore(e,t=this.width,n=this.height){if(this.disposed)throw Error(`GPU checkpoint has been disposed`);let r=this.gl,i=r.getParameter(r.READ_FRAMEBUFFER_BINDING),a=r.getParameter(r.DRAW_FRAMEBUFFER_BINDING);try{if(r.bindFramebuffer(r.READ_FRAMEBUFFER,this.framebuffer),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.blitFramebuffer(0,0,this.width,this.height,0,0,t,n,r.COLOR_BUFFER_BIT,r.NEAREST),r.getError()!==r.NO_ERROR)throw Error(`GPU checkpoint restore failed`)}finally{r.bindFramebuffer(r.READ_FRAMEBUFFER,i),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,a)}}dispose(){this.disposed||(this.disposed=!0,this.gl.deleteFramebuffer(this.framebuffer),this.gl.deleteTexture(this.texture))}},rc=`
|
|
97
|
+
}`,fs=class{canvas=document.createElement(`canvas`);capture=document.createElement(`canvas`);bloomCapture=document.createElement(`canvas`);materials=new Map;gl=null;program=null;initialized=!1;disposed=!1;failedSources=new WeakSet;size=new Float32Array(4);directions=new Float32Array(12);colors=new Float32Array(12);contacts=new Float32Array(12);padding=64;onLost=e=>{e.preventDefault(),this.materials.clear(),this.program=null};onRestored=()=>{!this.disposed&&this.gl&&(this.program=ns(this.gl,us,ds,`Pickup refraction`))};initialize(){if(this.initialized=!0,this.gl=this.canvas.getContext(`webgl2`,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1}),this.gl){try{this.program=ns(this.gl,us,ds,`Pickup refraction`)}catch{this.gl=null;return}this.canvas.addEventListener(`webglcontextlost`,this.onLost),this.canvas.addEventListener(`webglcontextrestored`,this.onRestored)}}destroyMaterial(e){this.gl?.deleteTexture(e.texture),this.gl?.deleteTexture(e.bloomTexture)}clearMaterials(){for(let e of this.materials.values())this.destroyMaterial(e);this.materials.clear()}draw(e,t,n,r,i,a,o,s,c=4.5){if(!s.length||this.disposed||this.failedSources.has(n)||(this.initialized||this.initialize(),!this.gl||!this.program))return!1;let l=Math.max(16,Math.round(272*a/Math.max(a,o))),u=Math.max(16,Math.round(272*o/Math.max(a,o))),f=this.materials.get(t);if(f&&(f.source!==n||f.revision!==i||f.width!==l||f.height!==u)&&(this.destroyMaterial(f),this.materials.delete(t),f=void 0),!f){if(this.materials.size>=8){let e=this.materials.keys().next().value;this.destroyMaterial(this.materials.get(e)),this.materials.delete(e)}this.capture.width=l+this.padding*2,this.capture.height=u+this.padding*2;let e=this.capture.getContext(`2d`);if(!e)return!1;e.drawImage(n,r.x,r.y,r.width,r.height,this.padding,this.padding,l,u),this.bloomCapture.width=this.capture.width,this.bloomCapture.height=this.capture.height;let a=this.bloomCapture.getContext(`2d`);if(!a)return!1;if(typeof a.filter==`string`)a.filter=`blur(8px)`,a.drawImage(this.capture,0,0);else{let e=this.bloomCapture.width*2;a.shadowColor=`#ffffff`,a.shadowBlur=16,a.shadowOffsetX=e,a.drawImage(this.capture,-e,0)}try{f=this.upload(n,i,l,u)}catch{return this.failedSources.add(n),!1}this.materials.set(t,f),d(`pickup sprite uploads`)}let p=l+this.padding*2,m=u+this.padding*2;(this.canvas.width!==p||this.canvas.height!==m)&&(this.canvas.width=p,this.canvas.height=m),this.size.set([l,u,this.padding,Math.min(3,s.length)]);for(let e=0;e<Math.min(3,s.length);e++){let t=s[e];this.directions.set([Math.cos(t.angle),-Math.sin(t.angle),t.age/t.duration,t.strength],e*4),this.colors.set([...t.color,t.variation],e*4),this.contacts.set([t.origin?.x??0,-(t.origin?.y??0),+!!t.origin,t.velocity*t.duration/c],e*4)}let h=this.gl;h.viewport(0,0,p,m),h.useProgram(this.program),as(this.program,{sprite:f.texture,bloom:f.bloomTexture,size:this.size,directionTime:this.directions,tint:this.colors,contact:this.contacts}),h.drawArrays(h.TRIANGLES,0,3);let g=this.padding*a/l,_=this.padding*o/u;return e.drawImage(this.canvas,-a/2-g,-o/2-_,a+g*2,o+_*2),d(`pickup shader passes`),d(`composited megapixels`,p*m/1e6),!0}upload(e,t,n,r){let i=this.gl,a=[];try{for(let e of[this.capture,this.bloomCapture]){let t=i.createTexture();if(!t)throw Error(`Unable to allocate pickup material`);a.push(t),i.bindTexture(i.TEXTURE_2D,t),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!1),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,e)}let[o,s]=a;return{source:e,revision:t,width:n,height:r,texture:o,bloomTexture:s}}catch(e){for(let e of a)i.deleteTexture(e);throw e}}reset(){this.clearMaterials()}dispose(){this.disposed=!0,this.clearMaterials(),this.canvas.removeEventListener(`webglcontextlost`,this.onLost),this.canvas.removeEventListener(`webglcontextrestored`,this.onRestored),this.gl&&this.program&&G(this.gl,this.program),this.gl=null,this.program=null}},ps=8;function ms(e,t,n){let r=n*.45,i=0;for(let n=0;n<8;n++){let n=i+1;if(n>=r)break;let a=new Set,o=i;for(let i of e.elementsFromPoint(t,n))for(let e=i;e;e=e.parentElement){if(a.has(e))continue;a.add(e);let t=getComputedStyle(e);if(t.position!==`fixed`&&t.position!==`sticky`||t.visibility===`hidden`||t.opacity===`0`)continue;let i=e.getBoundingClientRect();i.top<=n&&i.bottom>n&&i.bottom<r&&(o=Math.max(o,i.bottom))}if(o<=i)break;i=o}return i+ps}var hs=class{camera;constructor(e){this.camera=e}pickupLayer=null;dispose(){this.pickupLayer?.dispose()}captureState(){return l({previousCarVelocity:this.previousCarVelocity,poseOffset:this.poseOffset,poseVelocity:this.poseVelocity,poseForce:this.poseForce,wheelPhase:this.wheelPhase})}restoreState(e){let t=l(e);this.previousCarVelocity=t.previousCarVelocity,this.poseOffset=t.poseOffset,this.poseVelocity=t.poseVelocity,this.poseForce=t.poseForce,this.wheelPhase=t.wheelPhase,this.clearMaterials()}clearMaterials(){this.pickupLayer?.reset(),this.carImages.clear(),this.pristineShadows=new WeakMap,this.deformedShadows=new WeakMap}reset(){this.pickupLayer?.reset(),this.markers=[],this.previousCarVelocity=null,this.poseOffset=S(),this.poseVelocity=S(),this.poseForce=S(),this.wheelPhase=[0,0,0,0]}carImages=new Map;pristineShadows=new WeakMap;deformedShadows=new WeakMap;previousCarVelocity=null;poseOffset=S();poseVelocity=S();poseForce=S();wheelPhase=[0,0,0,0];carVisualOffset(e){return _(m(S(this.poseOffset.x,-this.poseOffset.y),-e.body.angle),this.camera.zoom)}updateCarPose(e,t){if(e.mode!==`car`){this.previousCarVelocity=null,this.poseOffset=S(),this.poseVelocity=S(),this.poseForce=S();return}let n=e.body.velocity,r=this.previousCarVelocity?_(b(n,this.previousCarVelocity),1/Math.max(t,1e-4)):S();this.previousCarVelocity={...n};let i=m(r,-e.body.angle),a=1-Math.exp(-t/.11);this.poseForce=x(this.poseForce,_(b(S(y(i.x,-15,15),y(i.y,-15,15)),this.poseForce),a));let o=S(y(-this.poseForce.x*.006,-.055,.055),0);this.poseVelocity=x(this.poseVelocity,_(b(_(b(o,this.poseOffset),65),_(this.poseVelocity,15)),t)),this.poseOffset=x(this.poseOffset,_(this.poseVelocity,t)),e.car.tires.forEach((n,r)=>{this.wheelPhase[r]=(this.wheelPhase[r]+t*Math.abs(n.wheelSurfaceSpeedMps)/Math.max(.18,e.car.preset.geometry.tireLengthM*.45))%1})}line(e,t,n,r,i=1){let a=this.camera.screen(t),o=this.camera.screen(n);e.strokeStyle=r,e.lineWidth=i,e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(o.x,o.y),e.stroke()}outline(e,t,n){e.beginPath(),t.forEach((t,n)=>{let r=this.camera.screen(t);n?e.lineTo(r.x,r.y):e.moveTo(r.x,r.y)}),e.closePath(),e.fillStyle=`${n}15`,e.fill(),e.strokeStyle=n,e.lineWidth=2,e.stroke()}imageFor(e){let t=e.image?.src;if(!t)return null;let n=this.carImages.get(t);return n||(n=new Image,n.crossOrigin=`anonymous`,n.src=t,this.carImages.set(t,n)),n.complete&&n.naturalWidth?n:null}imageLoadState(e){let t=e.image?.src;return t?this.imageFor(e)?`ready`:this.carImages.get(t)?.complete?`failed`:`loading`:`failed`}async loadImage(e,t){t.throwIfAborted();let n=e.image?.src;if(!n)throw Error(`Vehicle ${e.id} has no image`);this.imageFor(e);let r=this.carImages.get(n);if(r.complete||await new Promise((e,i)=>{let a=n=>{r.removeEventListener(`load`,o),r.removeEventListener(`error`,s),t.removeEventListener(`abort`,c),n?i(n):e()},o=()=>a(),s=()=>a(Error(`Could not load vehicle image: ${n}`)),c=()=>a(t.reason);r.addEventListener(`load`,o,{once:!0}),r.addEventListener(`error`,s,{once:!0}),t.addEventListener(`abort`,c,{once:!0})}),!r.naturalWidth)throw Error(`Could not load vehicle image: ${n}`);await r.decode?.(),t.throwIfAborted()}markers=[];markerInset={x:NaN,scrollX:NaN,scrollY:NaN,width:NaN,height:NaN,at:0,value:8};topMarkerInset(e){if(!this.camera.overlay||e.y>=this.camera.height/2)return 8;let t=this.camera.regionScale,n=y(Je(e,this.camera).center.x*t,1,window.innerWidth-1),r=performance.now(),i=this.markerInset;return(r-i.at>200||Math.abs(n-i.x)>24||i.scrollX!==window.scrollX||i.scrollY!==window.scrollY||i.width!==window.innerWidth||i.height!==window.innerHeight)&&(this.markerInset={x:n,scrollX:window.scrollX,scrollY:window.scrollY,width:window.innerWidth,height:window.innerHeight,at:r,value:ms(document,n,window.innerHeight)}),this.markerInset.value/t}markerAt(e){return[...this.markers].reverse().find(t=>Math.hypot(e.x-t.x,e.y-t.y)<=t.width/2+3)?.vehicle??null}drawVehicleMarkers(e,t,n){if(this.markers=[],n)for(let n of t){let{sim:r}=n;if(r.mode!==`car`||r.car.explodedAt!==null)continue;let i=x(this.camera.screen(r.body.position),n===t[0]?this.carVisualOffset(r):S()),a=Math.max(r.car.preset.geometry.lengthM,r.car.preset.geometry.widthM)*this.camera.zoom*.5;if(i.x+a>=0&&i.x-a<=this.camera.width&&i.y+a>=0&&i.y-a<=this.camera.height)continue;let o=Je(i,this.camera,this.topMarkerInset(i)),{width:s,height:c}=o,{x:l,y:u}=o.center;this.markers.push({vehicle:n,x:l,y:u,width:s,height:c}),e.save(),e.translate(l,u),e.shadowColor=`#00000030`,e.shadowBlur=10,e.shadowOffsetY=2,e.fillStyle=`#ffffff`,e.beginPath(),e.arc(0,0,s/2,0,Math.PI*2),e.fill(),e.shadowColor=`transparent`,e.strokeStyle=`#19212640`,e.lineWidth=1,e.stroke();let d=this.imageFor(r.car.preset);if(e.save(),e.rotate(-r.body.angle),d){let t=D(r.car.preset,d.naturalWidth,d.naturalHeight),n=35*t.widthM/t.lengthM;e.drawImage(d,t.source.x,t.source.y,t.source.width,t.source.height,-35/2,-n/2,35,n)}else e.fillStyle=`#192126`,e.beginPath(),e.roundRect(-13,-5,26,10,5),e.fill();e.restore();let{left:f,right:p,tip:m}=o;e.fillStyle=`#ffffff`,e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(m.x,m.y),e.lineTo(p.x,p.y),e.closePath(),e.fill(),e.strokeStyle=`#19212640`,e.lineWidth=1,e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(m.x,m.y),e.lineTo(p.x,p.y),e.stroke(),e.restore()}}shadowFor(e,t,n){let r=this.imageFor(e);if(!r)return null;let i=D(e,r.naturalWidth,r.naturalHeight),a=t?.spriteFor(r,i)??null,o=Math.max(1,Math.round(this.camera.zoom/2)*2),s=`${JSON.stringify(e.image?.crop)}|${e.image?.scale}|${e.geometry.lengthM}:${e.geometry.widthM}|${o}:${n}`;if(t&&a){let i=`${s}|${t.geometryRevision}`,c=this.deformedShadows.get(t);if(c?.image===r&&c.key===i)return c.shadow;d(`shadow rebuilds`);let l=Ue(r,e,a,o,n);return this.deformedShadows.set(t,{image:r,key:i,shadow:l}),l}let c=this.pristineShadows.get(r);c||(c=new Map,this.pristineShadows.set(r,c));let l=c.get(s);return l||(d(`shadow rebuilds`),l=Ue(r,e,a,o,n),c.set(s,l),c.size>12&&c.delete(c.keys().next().value)),l}carGround(e,t,n,r,i){if(!this.imageFor(t.car.preset))return;performance.now();let a=t.body,o=this.camera.screen(a.position),s=y(p(this.poseForce)/13,0,1),c=e.globalAlpha;e.save(),e.translate(o.x,o.y),e.rotate(-a.angle),e.save(),e.translate(-this.poseOffset.x*this.camera.zoom*.2+2,this.poseOffset.y*this.camera.zoom*.2+4);let l=i?this.shadowFor(t.car.preset,n,r):null;if(l){let t=l.lengthM*this.camera.zoom,n=l.widthM*this.camera.zoom,r=this.camera.zoom/l.pixelsPerMeter,i=(i,a)=>{let o=i.padding*r;d(`shadow composites`),e.drawImage(i.canvas,-t/2-o,-n/2+a-o,t+o*2,n+o*2)};e.globalAlpha=c*(.43+s*.05),l.soft&&i(l.soft,3),e.globalAlpha=c*.14,l.close&&i(l.close,2)}e.restore(),t.car.tires.forEach((n,r)=>{let i=He(t.car.preset),o=i.length*this.camera.zoom,s=i.width*this.camera.zoom;e.save(),e.translate(n.local.x*this.camera.zoom,-n.local.y*this.camera.zoom),e.rotate(-n.angle),e.fillStyle=`#121719`,e.beginPath(),e.roundRect(-o/2,-s/2,o,s,Math.min(3.5,s*.33)),e.fill(),e.save(),e.beginPath(),e.roundRect(-o/2+1,-s/2+1,o-2,s-2,Math.min(3,s*.3)),e.clip();let c=this.wheelPhase[r]??0,l=n.spinning?1:y(p(a.velocity)/24,0,.65),u=Math.max(4.2,o/4);e.strokeStyle=n.spinning?`rgba(170, 181, 178, 0.38)`:`rgba(125, 139, 137, 0.34)`,e.lineWidth=n.spinning?2:1.25;for(let t=-3;t<=4;t++){let n=t*u+c*u;e.beginPath(),e.moveTo(n-l*2,-s*.31),e.lineTo(n+l*2,s*.31),e.stroke()}l>.2&&(e.fillStyle=`rgba(137, 150, 147, ${.08+l*.1})`,e.fillRect(-o*.4,-s*.09,o*.8,s*.18)),e.restore(),e.strokeStyle=`rgba(6, 10, 11, 0.8)`,e.lineWidth=1.2,e.beginPath(),e.roundRect(-o/2,-s/2,o,s,Math.min(3.5,s*.33)),e.stroke(),e.restore()}),e.restore()}car(e,t,n,r,i,a){let o=n.car.preset,s=this.imageFor(o);if(!s)return;a&&!this.pickupLayer&&(this.pickupLayer=new fs);let c=this.camera.screen(t.position),l=D(o,s.naturalWidth,s.naturalHeight),u=r?.spriteFor(s,l);e.save(),e.translate(c.x,c.y),e.rotate(-t.angle),oe(e,o,this.camera.zoom,l.lengthM,l.widthM,i,a?.pickupEffect.active.length?l.lengthM*.25:0),a?.pickupEffect.active.length&&this.pickupLayer?.draw(e,a,u??s,u?{x:0,y:0,width:u.width,height:u.height}:l.source,`${r?.geometryRevision??0}:${JSON.stringify(l.source)}`,l.lengthM*this.camera.zoom,l.widthM*this.camera.zoom,a.pickupEffect.active,l.lengthM)||(u?e.drawImage(u,-l.lengthM*this.camera.zoom/2,-l.widthM*this.camera.zoom/2,l.lengthM*this.camera.zoom,l.widthM*this.camera.zoom):e.drawImage(s,l.source.x,l.source.y,l.source.width,l.source.height,-l.lengthM*this.camera.zoom/2,-l.widthM*this.camera.zoom/2,l.lengthM*this.camera.zoom,l.widthM*this.camera.zoom),d(`vehicle sprites`)),e.restore()}exhaustOutlets(e){return Ve(e.car.preset).map(({xM:e,yM:t})=>S(e,t))}exhaust(e,t){let n=this.camera.screen(t.body.position);e.save(),e.translate(n.x,n.y),e.rotate(-t.body.angle);let r=this.exhaustOutlets(t);for(let t of r)e.fillStyle=`rgba(25, 31, 33, 0.62)`,e.beginPath(),e.ellipse(t.x*this.camera.zoom,-t.y*this.camera.zoom,Math.max(1.3,this.camera.zoom*.065),Math.max(1.2,this.camera.zoom*.055),0,0,Math.PI*2),e.fill();e.restore()}ship(e,t,n){let r=n.ship,i=r.craft,a=t.world(r.counterweight);this.line(e,t.world(x(r.counterweight,S(r.radius))),t.world(x(i,S(-.6))),`#ff6262`,2);let o=this.camera.screen(a);e.beginPath(),e.arc(o.x,o.y,r.radius*this.camera.zoom,0,Math.PI*2),e.fillStyle=`#ff626215`,e.fill(),e.strokeStyle=`#ff6262`,e.lineWidth=2,e.stroke();let s=[S(1.2),S(-.6,-.8),S(-.6,.8)].map(e=>t.world(x(i,m(e,r.headAngle))));this.outline(e,s,`#ff6262`),this.center(e,t,`#ff6262`)}brick(e,t){this.outline(e,[S(-2,-1),S(2,-1),S(2,1),S(-2,1)].map(e=>t.world(e)),`#f6bd79`),this.center(e,t,`#f6bd79`)}center(e,t,n){let r=this.camera.screen(t.position);e.fillStyle=n,e.beginPath(),e.arc(r.x,r.y,3,0,Math.PI*2),e.fill(),!this.camera.overlay&&p(t.velocity)>.1&&this.line(e,t.position,x(t.position,_(t.velocity,.35)),`#658da0`)}},gs=.055,_s=e=>{let t=Math.sin(e*127.1+311.7)*43758.5453;return t-Math.floor(t)};function vs(e,t,n){if(!Number.isFinite(n)||n<=0)return[];let r=Math.min(e.age,e.duration*.8),i=e.age-n,a=i<=1e-7?0:Math.floor((i+1e-7)/gs)+1,o=Math.floor((r+1e-7)/gs);if(a>o)return[];let s={x:Math.cos(e.angle),y:Math.sin(e.angle)},c=Math.min(t.lengthM/(2*Math.max(1e-4,Math.abs(s.x))),t.widthM/(2*Math.max(1e-4,Math.abs(s.y)))),l=e.origin?{x:e.origin.x*t.lengthM,y:e.origin.y*t.widthM}:{x:-s.x*c,y:-s.y*c},u=Math.max(1.8,Math.min(5,e.velocity*e.duration/t.lengthM*2.2)),d=Math.hypot(t.lengthM*.5+Math.abs(l.x),t.widthM*.5+Math.abs(l.y)),f=[];for(let n=a;n<=o;n++){let r=n*gs/e.duration*u*t.lengthM;for(let i=0;i<2;i++){let a=e.variation*1999+n*83+i*257,o,s=1/0,c=Math.min(r,d)*Math.sqrt(_s(a+9));for(let e=0;e<32;e++){let n=_s(a+e*2+1),i=_s(a+e*2+2),u=t.alpha;if(u&&!u.solid[Math.floor(i*u.rows)*u.columns+Math.floor(n*u.columns)])continue;let d={x:(n-.5)*t.lengthM,y:(.5-i)*t.widthM},f=Math.hypot(d.x-l.x,d.y-l.y);if(f>r+t.lengthM*.17)continue;let p=Math.abs(f-c);p<s&&(s=p,o=d)}o&&f.push(o)}}return f}function ys(e,t,n){return n?S(n.x+n.width/2,n.y+n.height/2):S(e/2,t/2)}function bs(e,t,n){let r=ys(e,t,n);return Math.ceil(2*Math.hypot(Math.max(r.x,e-r.x),Math.max(r.y,t-r.y)))}function xs(e,t,n,r){return x(n,m(b(e,t),r))}function Ss(e,t,n,r){return x(t,m(b(e,n),-r))}function Cs(e,t,n){return _(S(e,t),n/2)}function ws(e,t,n,r){return e+Math.atan2(Math.sin(t-e),Math.cos(t-e))*(r<=0?1:1-Math.exp(-Math.max(0,n)/r))}function Ts(e,t,n){return{x:e.x<n?e.x-n:e.x>t.width-n?e.x-(t.width-n):0,y:e.y<n?e.y-n:e.y>t.height-n?e.y-(t.height-n):0}}function Es(e,t,n){let r=Math.min(Math.max(1,t.width-32)/Math.max(1,e.width+160),Math.max(1,t.height-32)/Math.max(1,e.height+160));return Math.max(.1,Math.min(3,n??r))}function Ds(e,t){let n=null;for(let r of e){let e=r.bounds;t.x<e.x||t.y<e.y||t.x>=e.x+e.width||t.y>=e.y+e.height||(!n||n.element.contains(r.element)||!r.element.contains(n.element)&&e.width*e.height<n.bounds.width*n.bounds.height)&&(n=r)}return n}var Os=class{projection;regions=[];measuredAt=-1/0;constructor(e=ae){this.projection=e}at(e,t,n){return n-this.measuredAt>120&&(this.measuredAt=n,this.regions=Array.from(document.querySelectorAll(`[data-jr-camera],[data-jr-camera-zoom]`)).filter(e=>!e.closest(`[data-jr-ui],[data-jr-overlay]`)).flatMap(e=>{let n=e.getAttribute(`data-jr-camera`);if(n!==null&&n!==`fixed`&&n!==`follow`)return[];let r=this.projection.viewportRectToDocument(e.getBoundingClientRect(),t);if(r.width<=0||r.height<=0)return[];let i=e.getAttribute(`data-jr-camera-zoom`),a=i?.trim()?Number(i):NaN;return n===null&&(!Number.isFinite(a)||a<=0)?[]:[{element:e,bounds:r,fixed:n===`fixed`,zoom:Number.isFinite(a)&&a>0?a:void 0}]})),Ds(this.regions.filter(e=>e.element.isConnected),e)}reset(){this.regions=[],this.measuredAt=-1/0}},ks=class{overlay;canvasWorld;requestResize;constructor(e,t,n){this.overlay=e,this.canvasWorld=t,this.requestResize=n,e&&(this.originScroll=S(window.scrollX,window.scrollY),this.observedScroll={...this.originScroll},this.pageSize={width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight})}resize(){this.requestResize()}get pixelSpace(){return this.overlay||this.canvasWorld}get timeSeconds(){return this.lastFrame/1e3}rebaseTime(e){this.lastFrame=e}captureState(){return l({outputWidth:this.outputWidth,outputHeight:this.outputHeight,cameraRotation:this.cameraRotation,cameraLock:this.cameraLock,cameraSmoothing:this.cameraSmoothing,cameraLockInitialized:this.cameraLockInitialized,width:this.width,height:this.height,dpr:this.dpr,smokeMargin:this.smokeMargin,regionScale:this.regionScale,canvasWorldScale:this.canvasWorldScale,cameraFrame:this.cameraFrame,camera:this.camera,zoom:this.zoom,baseZoom:this.baseZoom,slowMoScale:this.slowMoScale,zoomAnchor:this.zoomAnchor,pageSize:this.pageSize,lastFrame:this.lastFrame,originScroll:this.originScroll,observedScroll:this.observedScroll,virtualScroll:this.virtualScroll,followInterrupted:this.followInterrupted,deadZone:this.deadZone})}restoreState(e){let t=l(e);this.vehicleReveal=null,this.outputWidth=t.outputWidth,this.outputHeight=t.outputHeight,this.cameraRotation=t.cameraRotation,this.cameraLock=t.cameraLock,this.cameraSmoothing=t.cameraSmoothing,this.cameraLockInitialized=t.cameraLockInitialized,this.width=t.width,this.height=t.height,this.dpr=t.dpr,this.smokeMargin=t.smokeMargin,this.regionScale=t.regionScale,this.canvasWorldScale=t.canvasWorldScale,this.cameraFrame=t.cameraFrame,this.camera=t.camera,this.zoom=t.zoom,this.baseZoom=t.baseZoom,this.slowMoScale=t.slowMoScale,this.zoomAnchor=t.zoomAnchor,this.pageSize=t.pageSize,this.lastFrame=t.lastFrame,this.originScroll=t.originScroll,this.observedScroll=t.observedScroll,this.virtualScroll=t.virtualScroll,this.followInterrupted=t.followInterrupted,this.deadZone=t.deadZone}restorePresentation(){this.setVirtualScroll({...this.virtualScroll}),this.overlay&&(window.scrollTo(this.observedScroll.x,this.observedScroll.y),de(),this.resize(),this.cameraRegions.reset(),this.activeCameraRegion||this.regionScale!==1?this.pageScene.apply(this.regionScale,this.sceneScroll()):this.pageScene.clear())}reset(){this.vehicleReveal=null,this.camera=S(),this.cameraLockInitialized=!1,this.slowMoZoom=1,this.zoomAnchor=S(),this.overlay&&(this.pageSize={width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight}),this.pageScene.clear(),this.activeCameraRegion=null,this.cameraRegions.reset(),this.regionScale=this.canvasWorld?this.canvasWorldScale:1,this.resize(),this.setVirtualScroll(S())}vehicleReveal=null;revealVehicle(e,t=550){this.overlay&&(this.syncScroll(),this.followInterrupted=!0,this.vehicleReveal={sim:e,start:this.sceneScroll(),started:null,duration:t})}advanceVehicleReveal(e,t){let n=this.vehicleReveal;if(!n)return;n.started??=e;let r=n.duration<=0?1:y((e-n.started)/n.duration,0,1),i=r*r*(3-2*r),a=b(this.documentPoint(n.sim.body.position),S(this.width/2,this.height/2));!this.virtualScroll.x&&a.x>=-this.width/2&&a.x<=this.pageSize.width-this.width/2&&(a.x=y(a.x,0,Math.max(0,this.pageSize.width-this.width))),!this.virtualScroll.y&&a.y>=-this.height/2&&a.y<=this.pageSize.height-this.height/2&&(a.y=y(a.y,0,Math.max(0,this.pageSize.height-this.height))),this.moveSceneTo(x(n.start,_(b(a,n.start),i))),r===1&&(this.vehicleReveal=null,n.sim===t&&(this.followInterrupted=!1))}resetFollow(){this.vehicleReveal=null,this.overlay&&(this.originScroll=S(window.scrollX,window.scrollY),this.observedScroll={...this.originScroll},this.followInterrupted=!1)}dispose(){this.vehicleReveal=null,this.pageScene.clear(),this.setVirtualScroll(S()),de()}resizeLayout(e,t,n){this.outputWidth=e,this.outputHeight=t;let r=this.canvasWorld&&this.cameraLock,i=r?bs(e,t,this.cameraFrame):0,a=(r?i:e)/this.regionScale,o=(r?i:t)/this.regionScale;this.overlay&&this.width>1&&(a!==this.width||o!==this.height)&&(this.originScroll.x+=(this.width-a)/2,this.originScroll.y+=(this.height-o)/2),this.width=a,this.height=o;let s=Math.min(e,t);this.baseZoom=this.canvasWorld?28:this.overlay?Math.max(14,Math.min(28,s/11)):Math.max(1,Math.min(s<600?32:28,(s-32)/10,s/25)),this.zoom=this.baseZoom*(this.canvasWorld||this.overlay?1:this.slowMoZoom),this.overlay&&this.regionScale===1&&!this.virtualScroll.x&&!this.virtualScroll.y&&(this.pageSize={width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight}),this.smokeMargin=this.canvasWorld?96/this.regionScale:this.pixelSpace?Math.min(112,Math.max(72,Math.min(this.width,this.height)*.1)):0;let c=this.width*this.height;this.dpr=Math.min(2*(this.canvasWorld?this.regionScale:1),n*this.regionScale,Math.sqrt(24e6/c),16384/Math.max(this.width,this.height))}outputWidth=1;outputHeight=1;cameraRotation=0;cameraLock=!1;cameraSmoothing=.25;cameraLockInitialized=!1;width=1;height=1;dpr=1;smokeMargin=0;pageScene=new ie;cameraRegions=new Os(this.pageScene);get documentProjection(){return this.pageScene}activeCameraRegion=null;regionScale=1;canvasWorldScale=1;cameraFrame=null;camera=S();zoom=28;baseZoom=28;slowMoScale=1;get slowMoZoom(){return this.slowMoScale??1}set slowMoZoom(e){this.slowMoScale=e}zoomAnchor=S();pageSize={width:1,height:1};lastFrame=0;originScroll=S();observedScroll=S();virtualScroll=S();followInterrupted=!1;deadZone=!0;screen(e){return S(this.width/2+(e.x-this.camera.x)*this.zoom,this.height/2-(e.y-this.camera.y)*this.zoom)}world(e){return S(this.camera.x+(e.x-this.width/2)/this.zoom,this.camera.y-(e.y-this.height/2)/this.zoom)}vehicleViewportPosition(e){return this.overlay&&this.syncScroll(),this.screen(e)}sceneScroll(){return this.canvasWorld?S(this.camera.x*28-this.width/2,-this.camera.y*28-this.height/2):x(O(),this.virtualScroll)}virtualOffset(){return{...this.virtualScroll}}documentPoint(e){return this.canvasWorld?re(e):(this.overlay&&this.syncScroll(),x(this.screen(e),this.sceneScroll()))}worldFromDocument(e){return this.canvasWorld?me(e):(this.overlay&&this.syncScroll(),this.world(b(e,this.sceneScroll())))}documentScale(){return this.canvasWorld?28:this.zoom}particlePoint(e){return this.pixelSpace?this.documentPoint(e):{...e}}particleScale(){return this.pixelSpace?this.documentScale():1}viewportSize(){return{width:this.width,height:this.height}}presentationScale(){return this.regionScale}setCanvasWorldScale(e,t=1.5){if(!this.canvasWorld)return;this.canvasWorldScale=Math.max(.2,Math.min(Math.max(.2,Math.min(4,Number.isFinite(t)?t:1.5)),Number.isFinite(e)?e:1));let n=this.canvasWorldScale*this.slowMoZoom;this.regionScale!==n&&(this.regionScale=n,this.resize())}setCameraFrame(e){this.cameraFrame=e,this.canvasWorld&&this.cameraLock&&this.resize()}setCameraLock(e){this.canvasWorld&&this.cameraLock!==e&&(this.cameraLock=e,this.cameraLockInitialized=!1,e||(this.cameraRotation=0),this.resize())}viewportFromDocument(e){let t=_(b(e,this.sceneScroll()),this.regionScale);return this.canvasWorld&&this.cameraLock?xs(t,Cs(this.width,this.height,this.regionScale),ys(this.outputWidth,this.outputHeight,this.cameraFrame),this.cameraRotation):t}documentFromViewport(e){let t=this.canvasWorld&&this.cameraLock?Ss(e,Cs(this.width,this.height,this.regionScale),ys(this.outputWidth,this.outputHeight,this.cameraFrame),this.cameraRotation):e;return x(_(t,1/this.regionScale),this.sceneScroll())}bounds(){this.overlay&&this.syncScroll();let e=this.width/(2*this.zoom)-3/this.zoom,t=this.height/(2*this.zoom)-3/this.zoom;return{left:this.camera.x-e,right:this.camera.x+e,bottom:this.camera.y-t,top:this.camera.y+t}}setVirtualScroll(e){if(!this.overlay)return;this.virtualScroll=S(Math.abs(e.x)<.01?0:e.x,Math.abs(e.y)<.01?0:e.y);let t=document.body;this.virtualScroll.x||this.virtualScroll.y?(t.dataset.jrVirtualCamera===void 0&&(t.dataset.jrVirtualCamera=``),t.style.setProperty(`--joy-ride-scene-x`,`${-this.virtualScroll.x}px`),t.style.setProperty(`--joy-ride-scene-y`,`${-this.virtualScroll.y}px`)):(t.dataset.jrVirtualCamera!==void 0&&delete t.dataset.jrVirtualCamera,t.style.removeProperty(`--joy-ride-scene-x`),t.style.removeProperty(`--joy-ride-scene-y`))}syncScroll(e=!1){let t=S(O().x,O().y);if(!e){let e=b(t,this.observedScroll);p(e)>.5&&(this.followInterrupted=!0)}this.observedScroll=t,(this.activeCameraRegion||this.regionScale!==1)&&this.pageScene?.apply(this.regionScale,this.sceneScroll());let n=x(t,this.virtualScroll);this.camera=S((n.x-this.originScroll.x-this.zoomAnchor.x*(this.baseZoom-this.zoom))/this.zoom,-(n.y-this.originScroll.y+this.zoomAnchor.y*(this.baseZoom-this.zoom))/this.zoom)}resumeFollow(){this.vehicleReveal=null,this.overlay&&(this.syncScroll(),this.followInterrupted=!1)}interruptFollow(){this.vehicleReveal=null,this.overlay&&(this.followInterrupted=!0)}restorePage(e){if(!this.overlay||!this.virtualScroll.x&&!this.virtualScroll.y&&!this.activeCameraRegion&&this.regionScale===1)return!1;this.syncScroll(!0);let t=_(this.screen(e.body.position),this.regionScale??1);return(this.activeCameraRegion||this.regionScale!==1)&&(this.slowMoZoom=1,this.pageScene.clear(),this.activeCameraRegion=null,this.regionScale=1,this.resize()),this.setVirtualScroll(S()),this.syncScroll(!0),e.body.position=this.world(t),!0}followDocument(e){if(!this.overlay)return!1;if(this.vehicleReveal||this.activeCameraRegion?.fixed)return!0;if(this.zoomAnchor={...e.body.position},this.syncScroll(),this.followInterrupted)return!1;let t=this.screen(e.body.position),n=Math.max(e.car.preset.geometry.lengthM*this.zoom/2+12,Math.min(this.width,this.height)*.25),r=Ts(t,{width:this.width,height:this.height},n);if(r.x||r.y){if(e.barrier)window.scrollBy({left:r.x,top:r.y,behavior:`instant`}),de();else{let e=S(r.x*this.virtualScroll.x<0?Math.sign(r.x)*Math.min(Math.abs(r.x),Math.abs(this.virtualScroll.x)):0,r.y*this.virtualScroll.y<0?Math.sign(r.y)*Math.min(Math.abs(r.y),Math.abs(this.virtualScroll.y)):0);this.setVirtualScroll(x(this.virtualScroll,e));let t=b(r,e),n=O();(t.x||t.y)&&(window.scrollBy({left:t.x,top:t.y,behavior:`instant`}),de());let i=b(O(),n);this.setVirtualScroll(x(this.virtualScroll,b(t,i)))}}return this.syncScroll(!0),!0}moveSceneTo(e){window.scrollBy({left:e.x-O().x,top:e.y-O().y,behavior:`instant`}),de(),this.setVirtualScroll(S(e.x-O().x,e.y-O().y)),this.syncScroll(!0)}updateCameraRegion(e,t){let n=this.cameraFrame??{x:0,y:0,width:window.innerWidth,height:window.innerHeight},r=this.activeCameraRegion!==null&&!e,i=e!==null&&this.activeCameraRegion?.element!==e.element,a=(e?e.fixed?Es(e.bounds,n,e.zoom):Math.max(.1,Math.min(3,e.zoom??1)):1)*this.slowMoZoom,o=this.regionScale,s=_(b(t,this.sceneScroll()),o);if(this.activeCameraRegion=e,r&&this.pageScene.clear(),Math.abs(a-this.regionScale)>1e-4&&(this.regionScale=a,this.resize()),e?.fixed){this.zoom=this.baseZoom;let t=e.bounds;this.moveSceneTo(S(t.x+t.width/2-(n.x+n.width/2)/this.regionScale,t.y+t.height/2-(n.y+n.height/2)/this.regionScale))}else(r||i)&&(this.followInterrupted=!1,this.moveSceneTo(S(t.x-this.width/2,t.y-this.height/2)));!e?.fixed&&!r&&!i&&Math.abs(a-o)>1e-4&&this.moveSceneTo(b(t,_(s,1/a))),e||a!==1?this.pageScene.apply(this.regionScale,this.sceneScroll()):this.pageScene.clear()}cameraStep(e,t){let n=this.lastFrame?y((t-this.lastFrame)/1e3,0,.1):1/60;this.lastFrame=t;let r=e.body;if(this.canvasWorld){if(this.cameraLock){let e=r.angle-Math.PI/2,t=!this.cameraLockInitialized||p(b(r.position,this.camera))>40;this.cameraRotation=t?e:ws(this.cameraRotation,e,n,this.cameraSmoothing),t&&(this.camera={...r.position}),this.cameraLockInitialized=!0}else this.cameraRotation=0}let i=S(this.width/2+r.position.x*this.baseZoom+this.originScroll.x,this.height/2-r.position.y*this.baseZoom+this.originScroll.y),a=this.overlay?this.cameraRegions.at(i,this.virtualScroll,t):null;this.overlay&&this.updateCameraRegion(a,i);let o=this.zoom;if(this.canvasWorld){let e=this.canvasWorldScale*this.slowMoZoom;Math.abs(this.regionScale-e)>1e-4&&(this.regionScale=e,this.resize()),this.zoom=this.baseZoom}else this.zoom=this.baseZoom*(this.overlay?1:this.slowMoZoom);if(this.overlay){this.zoomAnchor={...r.position},this.syncScroll(),this.advanceVehicleReveal(t,e);return}if(e.barrier)return;let s=o/this.zoom;if(this.camera=S(r.position.x-(r.position.x-this.camera.x)*s,r.position.y-(r.position.y-this.camera.y)*s),this.canvasWorld&&this.cameraLock){let e=this.cameraSmoothing<=0?1:1-Math.exp(-n/this.cameraSmoothing);this.camera=x(this.camera,_(b(r.position,this.camera),e));return}if(!this.deadZone){let e=this.canvasWorld&&!this.cameraLock?this.cameraFrame:null;this.camera=e?S(r.position.x-((e.x+e.width/2)/this.regionScale-this.width/2)/this.zoom,r.position.y+((e.y+e.height/2)/this.regionScale-this.height/2)/this.zoom):{...r.position};return}let c=this.width*.18/this.zoom,l=this.height*.18/this.zoom,u=S(r.position.x-y(r.position.x-this.camera.x,-c,c),r.position.y-y(r.position.y-this.camera.y,-l,l));this.camera=x(this.camera,_(b(u,this.camera),1-Math.exp(-16*n)))}},As=class{canvas;camera;overlay;canvasWorld;sceneCanvas=null;sceneContext;documentOrigin={x:0,y:0};originalPosition;constructor(e,t,n,r){this.canvas=e,this.camera=t,this.overlay=n,this.canvasWorld=r;let i=e.getContext(`2d`);if(!i)throw Error(`Joy Ride requires a 2D canvas context.`);this.sceneContext=i,this.originalPosition={position:e.style.position,left:e.style.left,top:e.style.top,translate:e.style.translate}}setAbsoluteViewport(){this.overlay&&(this.canvas.style.position=`absolute`,this.measureDocumentOrigin(),this.place())}measureDocumentOrigin(){if(!this.overlay)return;if(!this.canvas.offsetParent){this.documentOrigin={x:0,y:0};return}let e=this.canvas.offsetParent,t=e.getBoundingClientRect(),n=O();this.documentOrigin={x:t.left+n.x+e.clientLeft,y:t.top+n.y+e.clientTop}}place(){if(!this.overlay)return;let e=O();this.canvas.style.left!==`0px`&&(this.canvas.style.left=`0px`),this.canvas.style.top!==`0px`&&(this.canvas.style.top=`0px`);let t=`${e.x-this.documentOrigin.x}px ${e.y-this.documentOrigin.y}px`;this.canvas.style.translate!==t&&(this.canvas.style.translate=t)}get context(){return this.sceneContext}resize(){let e=Math.max(1,this.overlay?window.innerWidth:this.canvas.clientWidth),t=Math.max(1,this.overlay?window.innerHeight:this.canvas.clientHeight),n=e/this.camera.regionScale!==this.camera.width||t/this.camera.regionScale!==this.camera.height;this.camera.resizeLayout(e,t,window.devicePixelRatio||1);let r=this.canvasWorld&&this.camera.cameraLock;r?(this.sceneCanvas??=document.createElement(`canvas`),this.sceneContext=this.sceneCanvas.getContext(`2d`)):this.sceneCanvas&&(this.sceneContext=this.canvas.getContext(`2d`)),this.overlay&&(n||this.canvas.style.width!==`${this.camera.width}px`)&&(this.canvas.style.width=`${this.camera.width}px`,this.canvas.style.height=`${this.camera.height}px`,this.canvas.style.transformOrigin=`0 0`,this.canvas.style.scale=String(this.camera.regionScale));let i=Math.round(this.camera.width*this.camera.dpr),a=Math.round(this.camera.height*this.camera.dpr),o=r?this.sceneCanvas:this.canvas;if((o.width!==i||o.height!==a)&&(o.width=i,o.height=a),r){let n=this.camera.dpr/this.camera.regionScale,r=Math.round(e*n),i=Math.round(t*n);this.canvas.width!==r&&(this.canvas.width=r),this.canvas.height!==i&&(this.canvas.height=i)}return this.sceneContext.setTransform(this.camera.dpr,0,0,this.camera.dpr,0,0),this.measureDocumentOrigin(),this.canvasWorld?this.camera.dpr:void 0}clear(){this.place(),this.sceneContext.setTransform(this.camera.dpr,0,0,this.camera.dpr,0,0),this.sceneContext.clearRect(0,0,this.camera.width,this.camera.height)}presentLockedCamera(){if(!this.canvasWorld||!this.camera.cameraLock||!this.sceneCanvas)return;let e=this.canvas.getContext(`2d`),t=this.camera.dpr/this.camera.regionScale,n=ys(this.camera.outputWidth,this.camera.outputHeight,this.camera.cameraFrame);e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,this.canvas.width,this.canvas.height),e.save(),e.translate(n.x*t,n.y*t),e.rotate(this.camera.cameraRotation),e.drawImage(this.sceneCanvas,-this.sceneCanvas.width/2,-this.sceneCanvas.height/2),e.restore()}dispose(){this.sceneCanvas&&=(this.sceneCanvas.width=1,this.sceneCanvas.height=1,null),this.canvas.style.scale=``,this.canvas.style.transformOrigin=``,this.overlay&&(this.canvas.style.position=this.originalPosition.position,this.canvas.style.left=this.originalPosition.left,this.canvas.style.top=this.originalPosition.top,this.canvas.style.translate=this.originalPosition.translate)}},js=class{frameRate=new pe;captureState(){return this.frameRate.captureState()}restoreState(e){this.frameRate.restoreState(e)}draw(e,t,n,r,i){let a=e,o=t.body,s=this.frameRate.sample(n);a.save();let c=He(t.car.preset);for(let e of t.car.tires){let t=r(o.world(e.local));a.strokeStyle=e.front?`#00dcff`:`#ffae31`,a.lineWidth=2;let n=[S(-c.length/2,-c.width/2),S(c.length/2,-c.width/2),S(c.length/2,c.width/2),S(-c.length/2,c.width/2)].map(t=>r(o.world(x(e.local,m(t,e.angle)))));a.beginPath(),n.forEach((e,t)=>t?a.lineTo(e.x,e.y):a.moveTo(e.x,e.y)),a.closePath(),a.stroke(),a.beginPath(),a.arc(t.x,t.y,4,0,Math.PI*2),a.stroke(),a.beginPath(),a.moveTo(t.x-7,t.y),a.lineTo(t.x+7,t.y),a.moveTo(t.x,t.y-7),a.lineTo(t.x,t.y+7),a.stroke(),a.font=`bold 10px ui-monospace, SFMono-Regular, monospace`,a.fillStyle=e.front?`#007e91`:`#895000`,a.fillText(`${e.front?`F`:`R`}${e.local.y>0?`L`:`R`}${e.skidding?` SKID`:``}`,t.x+8,t.y-8)}let l=r(o.position),u=(e,t,n)=>{let r=x(l,_(e,n));a.strokeStyle=t,a.fillStyle=t,a.lineWidth=2.5,a.beginPath(),a.moveTo(l.x,l.y),a.lineTo(r.x,r.y),a.stroke();let i=Math.atan2(e.y,e.x);a.beginPath(),a.moveTo(r.x,r.y),a.lineTo(r.x-Math.cos(i-.5)*9,r.y-Math.sin(i-.5)*9),a.lineTo(r.x-Math.cos(i+.5)*9,r.y-Math.sin(i+.5)*9),a.closePath(),a.fill()};u(S(Math.cos(o.angle),-Math.sin(o.angle)),`#00c4df`,67);let d=p(o.velocity);d>.2&&u(S(o.velocity.x/d,-o.velocity.y/d),`#f05bd6`,48+Math.min(32,d));let f=Math.atan2(o.velocity.y,o.velocity.x),h=Math.atan2(Math.sin(o.angle-f),Math.cos(o.angle-f)),g=Math.max(...t.car.tires.filter(e=>e.front).map(e=>e.gripUtilization)),v=Math.max(...t.car.tires.filter(e=>!e.front).map(e=>e.gripUtilization)),y=t.car.tires.map(e=>`${e.front?`F`:`R`}${e.local.y>0?`L`:`R`} ${e.slipSpeedMps.toFixed(1)}${e.skidding?`*`:``}`).join(` `),b=[`${t.car.preset.name} · ${(d*3.6).toFixed(0)} km/h · ${Math.round(s)} FPS`,`input T ${t.lastInput.throttle} S ${t.lastInput.steer} brake ${Number(t.lastInput.action)}`,`body ${Math.round(o.angle*180/Math.PI)}° travel ${Math.round(f*180/Math.PI)}° slip ${Math.round(h*180/Math.PI)}°`,`front load ${(t.car.frontLoadFraction*100).toFixed(0)}% burnout ${Number(t.car.burnout)} charge ${t.car.boostCharge.toFixed(2)}`,`grip use F ${g.toFixed(2)} R ${v.toFixed(2)} drift ${Number(t.car.drifting)} donut ${Number(t.car.donuting)}`,`drift ${Number(t.car.fastDrifting)} countersteer ${Number(t.car.countersteering)}`,`roof rocket ${i.rocketState}`,`side guns ${i.gunState} · ${i.bulletCount} bullets`,`tire slip m/s ${y}`,`fluid ${i.fluidEngine} ${i.quality} ${i.fluidCols}×${i.fluidRows}`,`shared fire ${i.fireCols}×${i.fireRows} · ${i.groundedFireCount} grounded sources`,`cyan = nose/shape pink = travel amber = walls`,`wheel cyan = front wheel amber = rear violet = letters`];a.fillStyle=`rgba(10, 21, 24, 0.87)`,a.fillRect(12,88,Math.min(430,i.width-24),b.length*18+18),a.font=`12px ui-monospace, SFMono-Regular, monospace`,a.fillStyle=`#f1f5f3`,b.forEach((e,t)=>a.fillText(e,22,110+t*18)),a.restore()}},K=1024,Ms=Math.PI*2,Ns=Array.from({length:K},(e,t)=>({x:Math.cos(t/K*Ms),y:Math.sin(t/K*Ms)}));function Ps(e,t,n){return n.filter(n=>{let r=Math.max(n.x-e.x,0,e.x-n.x-n.width),i=Math.max(n.y-e.y,0,e.y-n.y-n.height);return n.width>0&&n.height>0&&r*r+i*i<=t*t})}function Fs(e,t,n){let r=Math.abs(t.x)<1e-8,i=Math.abs(t.y)<1e-8;if(r&&(e.x<n.x||e.x>n.x+n.width)||i&&(e.y<n.y||e.y>n.y+n.height))return 1/0;let a=r?-1/0:(n.x-e.x)/t.x,o=r?1/0:(n.x+n.width-e.x)/t.x,s=i?-1/0:(n.y-e.y)/t.y,c=i?1/0:(n.y+n.height-e.y)/t.y,l=Math.max(0,Math.min(a,o),Math.min(s,c));return l<=Math.min(Math.max(a,o),Math.max(s,c))?l:1/0}function Is(e,t,n){let r=Ps(e,t,n);if(!r.length)return;let i=new Float32Array(K);for(let n=0;n<i.length;n++){let a=t;for(let t of r)a=Math.min(a,Fs(e,Ns[n],t));i[n]=a/t}return{range:t,distances:i}}function Ls(e,t,n,r){for(let i of Ps(t,n,r)){if(t.x>=i.x&&t.x<=i.x+i.width&&t.y>=i.y&&t.y<=i.y+i.height){e.beginPath(),e.clip();return}let r=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],a=e=>{let r=1+n*4/Math.max(.001,Math.hypot(e.x-t.x,e.y-t.y));return{x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r}};for(let i=0;i<r.length;i++){let o=r[i],s=r[(i+1)%r.length];if((s.x-o.x)*(t.y-o.y)-(s.y-o.y)*(t.x-o.x)>=0)continue;let c=a(o),l=a(s);e.beginPath(),e.rect(t.x-n,t.y-n,n*2,n*2),e.moveTo(o.x,o.y),e.lineTo(s.x,s.y),e.lineTo(l.x,l.y),e.lineTo(c.x,c.y),e.closePath(),e.clip(`evenodd`)}}}var Rs=[.82,.91,1],zs=[1,.045,.018],Bs=e=>Math.max(0,Math.min(1,e));function Vs(e){let t=/^#([\da-f]{6})$/i.exec(e);if(!t)return[.4,.9,1];let n=parseInt(t[1],16);return[(n>>16)/255,(n>>8&255)/255,(n&255)/255]}function Hs(e,t,n){let r=Math.cos(e.angle),i=Math.sin(e.angle);return{x:e.center.x+r*t-i*n,y:e.center.y+i*t+r*n}}var Us=class{sprites=new WeakMap;halos=new WeakMap;beam=null;sprite(e){let t=e.image;if(!t||!t.complete||!t.naturalWidth)return null;let n=e.source??{x:0,y:0,width:t.naturalWidth,height:t.naturalHeight},r=e.mounts.taillights.map(t=>`${Math.round(t.x/e.width*1e4)},${Math.round(t.y/e.height*1e4)}`).join(`;`),i=`${n.x},${n.y},${n.width},${n.height}|${r}`,a=this.sprites.get(t);if(a||(a=new Map,this.sprites.set(t,a)),a.has(i))return a.get(i)??null;let o=document.createElement(`canvas`);o.width=192,o.height=Math.max(24,Math.round(192*n.height/n.width));let s=o.getContext(`2d`,{willReadFrequently:!0});if(!s)return a.set(i,null),null;s.drawImage(t,n.x,n.y,n.width,n.height,0,0,o.width,o.height);let c;try{c=s.getImageData(0,0,o.width,o.height)}catch{return a.set(i,null),null}let l=s.createImageData(o.width,o.height),u=0;for(let t=0;t<o.height;t++)for(let n=0;n<o.width;n++){let r=(t*o.width+n)*4,i=c.data[r],a=c.data[r+1],s=c.data[r+2],d=c.data[r+3];n<o.width*.27&&i>100&&i>a*1.6&&i>s*1.5&&d>100&&e.mounts.taillights.some(r=>{let i=n-(.5+r.x/e.width)*o.width,a=t-(.5+r.y/e.height)*o.height;return i*i+a*a<(o.height*.18)**2})&&(l.data[r]=255,l.data[r+1]=22,l.data[r+2]=5,l.data[r+3]=Math.min(235,d),u++),c.data[r]=255,c.data[r+1]=255,c.data[r+2]=255,c.data[r+3]=d>90?255:0}s.putImageData(c,0,0);let d=null;u>1&&u<o.width*o.height*.055&&(d=document.createElement(`canvas`),d.width=o.width,d.height=o.height,d.getContext(`2d`)?.putImageData(l,0,0));let f={silhouette:o,brakes:d};return a.size>=8&&a.clear(),a.set(i,f),f}halo(e,t){let n=this.halos.get(e);n||(n=new Map,this.halos.set(e,n));let r=n.get(t);if(r)return r;let i=document.createElement(`canvas`);i.width=e.width+64,i.height=e.height+64;let a=i.getContext(`2d`);a.drawImage(e,32,32),a.globalCompositeOperation=`source-in`,a.fillStyle=t,a.fillRect(0,0,i.width,i.height),a.globalCompositeOperation=`source-over`;let o=document.createElement(`canvas`);o.width=i.width,o.height=i.height,o.getContext(`2d`).drawImage(i,0,0),a.clearRect(0,0,i.width,i.height),a.filter=`blur(14px)`,a.globalAlpha=.92,a.drawImage(o,-2,-5,o.width+4,o.height+10),a.filter=`blur(7px)`,a.globalAlpha=.9,a.drawImage(o,0,0),a.filter=`blur(3px)`,a.globalAlpha=.8,a.strokeStyle=t,a.lineWidth=3,a.lineCap=`round`;for(let t of[-1,1])a.beginPath(),a.moveTo(32+e.width*.18,32+e.height*(.5+t*.34)),a.lineTo(32+e.width*.82,32+e.height*(.5+t*.34)),a.stroke();return a.filter=`none`,a.globalAlpha=1,n.size>8&&n.clear(),n.set(t,i),i}beamImage(){if(this.beam)return this.beam;let e=document.createElement(`canvas`);e.width=256,e.height=128;let t=e.getContext(`2d`),n=t.createImageData(e.width,e.height);for(let t=0;t<e.height;t++)for(let r=0;r<e.width;r++){let i=r/e.width,a=(t/e.height-.5)*2,o=.035+i*.94,s=Bs((1-i)/.4),c=Math.exp(-a*a/(o*o))*s*s*(3-2*s),l=(t*e.width+r)*4;n.data[l]=210,n.data[l+1]=230,n.data[l+2]=255,n.data[l+3]=Math.round(c*255)}return t.putImageData(n,0,0),this.beam=e,e}clip(e,t,n,r){t.walls?.length&&(e.rotate(-t.angle),e.translate(-t.center.x,-t.center.y),Ls(e,Hs(t,n.x,n.y),r,t.walls),e.translate(t.center.x,t.center.y),e.rotate(t.angle))}ground(e,t){let n=t.opacity??1,r=t.options.brakeLights?Bs(t.braking):0;if(!(n<=0||t.width<=0)){if(e.save(),e.translate(t.center.x,t.center.y),e.rotate(t.angle),e.globalCompositeOperation=`screen`,t.dark&&t.options.underglow&&t.options.underglowOpacity>0){e.save(),this.clip(e,t,{x:0,y:0},t.width*1.5);let r=this.sprite(t);if(e.globalAlpha=Bs(t.options.underglowOpacity)*n,r){let n=this.halo(r.silhouette,t.options.underglow),i=32/r.silhouette.width*t.width,a=32/r.silhouette.height*t.height;e.drawImage(n,-t.width/2-i,-t.height/2-a,t.width+i*2,t.height+a*2)}else e.shadowColor=t.options.underglow,e.shadowBlur=t.height*.5,e.fillStyle=t.options.underglow,e.beginPath(),e.roundRect(-t.width*.43,-t.height*.38,t.width*.86,t.height*.76,t.height*.22),e.fill(),e.shadowBlur=0;e.restore()}if(t.dark&&t.options.headlights)for(let r of t.mounts.headlights)e.save(),this.clip(e,t,r,t.width*6.2),e.globalAlpha=.085*n,e.drawImage(this.beamImage(),r.x,r.y-t.width*.68,t.width*5.7,t.width*1.36),e.restore();if(t.dark&&t.options.taillights||r>0){let i=r;for(let{x:r,y:a}of t.mounts.taillights){let o=t.height*(.48+i*.38);e.save(),this.clip(e,t,{x:r,y:a},o),e.globalAlpha=.1;let s=e.createRadialGradient(r,a,0,r,a,o),c=(t.dark?.12+i*.19:i*.13)*n;s.addColorStop(0,`rgba(255,30,8,${c})`),s.addColorStop(1,`rgba(255,20,4,0)`),e.fillStyle=s,e.fillRect(r-o,a-o,o*2,o*2),e.restore()}}e.restore()}}glints(e,t){e.save(),e.translate(t.center.x,t.center.y),e.rotate(t.angle),e.globalCompositeOperation=`screen`;let n=t.opacity??1,r=t.options.brakeLights?Bs(t.braking):0;if(r>0){let i=this.sprite(t)?.brakes;i&&(e.globalAlpha=r*n*(t.dark?.9:.52),e.shadowColor=`#ff250d`,e.shadowBlur=t.height*(t.dark?.16:.055),e.drawImage(i,-t.width/2,-t.height/2,t.width,t.height))}for(let i of[!0,!1])if(!(i?!(t.dark&&t.options.headlights):!(t.dark&&t.options.taillights||r>0)))for(let a of t.mounts[i?`headlights`:`taillights`]){e.save(),e.globalAlpha=n*(i?.75:t.dark?.34+r*.6:r*.45);let o=t.height*(i?.15:.12);this.clip(e,t,a,o);let s=e.createRadialGradient(a.x,a.y,0,a.x,a.y,o);s.addColorStop(0,i?`#e6f1ffd9`:`#ff3518c0`),s.addColorStop(.28,i?`#c1dcff70`:`#ff230760`),s.addColorStop(1,i?`#c1dcff00`:`#ff230700`),e.fillStyle=s,e.beginPath(),e.arc(a.x,a.y,o,0,Math.PI*2),e.fill(),e.restore()}e.restore()}smokeLights(e){let t=[],n={x:Math.cos(e.angle),y:Math.sin(e.angle)},r=e.opacity??1,i=e.options.brakeLights?Bs(e.braking):0;if(e.dark&&e.options.headlights)for(let i of e.mounts.headlights)t.push({point:Hs(e,i.x,i.y),direction:n,color:Rs,range:e.width*6.2,radius:e.height*.075,spread:.14,intensity:1.7*r});if(e.dark&&e.options.taillights||i>0)for(let a of e.mounts.taillights)t.push({point:Hs(e,a.x,a.y),direction:{x:-n.x,y:-n.y},color:zs,range:e.width*(i>0?1.6:.9),radius:e.height*.15,spread:.46,intensity:r*(e.dark?.24+i*.85:i*.42)});if(e.dark&&e.options.underglow&&e.options.underglowOpacity>0)for(let n of[-.27,0,.27])t.push({point:Hs(e,e.width*n,0),direction:{x:0,y:0},color:Vs(e.options.underglow),range:e.height,radius:e.height*.8,spread:0,intensity:r*e.options.underglowOpacity*.8});return t.map(t=>{let n=Is(t.point,Math.max(t.range,t.radius*4),e.walls??[]);return n?{...t,shadow:n}:t})}},Ws={light:{ink:`#161c17`,alphaScale:1},dark:{ink:`#a9adb0`,alphaScale:1.7}};function Gs(e){let t=e.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);if(!t)return!1;let[,n,r,i]=t.map(Number);return n*.2126+r*.7152+i*.0722<112}function Ks(e){let t=0,n=0,r=0,i=0;for(let a of e.layers){let e=`layers`in a?Ks(a):[a.color[0]*a.alpha,a.color[1]*a.alpha,a.color[2]*a.alpha,a.alpha];if(t+=(1-i)*e[0],n+=(1-i)*e[1],r+=(1-i)*e[2],i+=(1-i)*e[3],i>=.9999)break}return[t*e.opacity,n*e.opacity,r*e.opacity,i*e.opacity]}function qs(e,t=!1){let n={opacity:1,layers:[]},r=new Map,i=new Map,a=e=>{let t=r.get(e);return t||(t=getComputedStyle(e),r.set(e,t)),t},o=e=>{let t=i.get(e);if(t)return t;let r=e.parentElement?o(e.parentElement):n,s=Number.parseFloat(a(e).opacity),c=Number.isFinite(s)?Math.max(0,Math.min(1,s)):1,l=r;return c<1&&(l={opacity:c,layers:[]},r.layers.push(l)),i.set(e,l),l};for(let t of document.elementsFromPoint(e.x,e.y)){if(!(t instanceof HTMLElement)||t.closest(`[data-jr-overlay],[data-jr-embed],[data-jr-touch-controls]`))continue;let e=ce(a(t).backgroundColor);if(!e||e.alpha<=0)continue;let n=e.color.match(/[\d.]+/g).slice(0,3).map(Number);o(t).layers.push({color:n,alpha:e.alpha})}let[s,c,l,u]=Ks(n);if(u<=0)return null;let d=t?0:255;return Gs(`rgb(${s+d*(1-u)} ${c+d*(1-u)} ${l+d*(1-u)})`)}var Js=class{resolve;samples=new WeakMap;constructor(e=qs){this.resolve=e}at(e,t,n,r=performance.now()){let i=this.samples.get(e);if(i&&i.fallback===n&&r-i.at<80&&Math.hypot(t.x-i.x,t.y-i.y)<48)return i.dark;let a=this.resolve(t,n)??n;return this.samples.set(e,{x:t.x,y:t.y,at:r,dark:a,fallback:n}),a}},Ys=64,Xs=e=>e.width>0&&e.height>0&&e.width<=64&&e.height<=64&&e.pixelWidth<=128&&e.pixelHeight<=128&&e.fixedRadius===void 0&&e.blastAge===void 0&&!e.smokeOnly,Zs=class{groups=new Map;combine(e,t,n){let r=e.filter(Xs);if(r.length<Ys)return[...e];let i=Math.ceil(t/2),a=Math.ceil(n/2),o=e.filter(e=>!Xs(e)),s=new Map;for(let e of r){let t=Math.max(0,Math.min(.999,e.age/Math.max(.01,e.burnSeconds))),n=Math.floor(t*4),r=s.get(n)??[];r.push(e),s.set(n,r)}for(let[e,r]of s){let s=this.groups.get(e);s&&s.alpha.length===i*a||(s={key:{},alpha:new Uint8Array(i*a),revision:0},this.groups.set(e,s)),s.alpha.fill(0);let c=!1;for(let e of r)c=this.rasterize(s.alpha,i,a,e,t,n)||c;if(!c)continue;s.revision++;let l=r.reduce((e,t)=>e+t.age/Math.max(.01,t.burnSeconds),0)/r.length;o.push({key:s.key,alpha:s.alpha,pixelWidth:i,pixelHeight:a,x:0,y:0,width:t,height:n,origin:{x:t/2,y:n/2},age:l,farthest:Math.max(t,n),spreadSeconds:0,burnSeconds:1,smokeRate:r.reduce((e,t)=>e+(t.smokeRate??13),0)/r.length,revision:s.revision})}return o}rasterize(e,t,n,r,i,a){let o=t/i,s=n/a,c=r.x+r.width/2,l=r.y+r.height/2,u=Math.cos(r.angle??0),d=Math.sin(r.angle??0),f=Math.hypot(r.width,r.height)/2,p=Math.max(0,Math.floor((c-f)*o)),m=Math.min(t-1,Math.ceil((c+f)*o)),h=Math.max(0,Math.floor((l-f)*s)),g=Math.min(n-1,Math.ceil((l+f)*s)),_=!1;for(let n=h;n<=g;n++){let i=(n+.5)/s-l;for(let a=p;a<=m;a++){let s=(a+.5)/o-c,l=s*u+i*d+r.width/2,f=-s*d+i*u+r.height/2;if(l<0||l>=r.width||f<0||f>=r.height)continue;let p=Math.floor(l/r.width*r.pixelWidth),m=Math.floor(f/r.height*r.pixelHeight),h=Math.round((r.alpha[m*r.pixelWidth+p]??0)*(r.intensity??1)),g=n*t+a;h>e[g]&&(e[g]=h),_||=h>0}}return _}},Qs=class{points=[];get count(){return this.points.length}get managedBytes(){return this.points.length*40}captureState(){return{points:this.points.map(({point:e,...t})=>({point:{...e},...t})),dispose:()=>void 0}}restoreState(e){this.points=e?.points.map(({point:e,...t})=>({point:{...e},...t}))??[]}reset(){this.points=[]}dispose(){this.reset()}ignite(e,t,n,r,i){let a=b(t,e),o=Math.max(1,Math.ceil(p(a)/Math.max(1,i)));for(let t=1;t<=o;t++)this.points.push({point:x(e,_(a,t/o)),width:n,age:0,lifetime:r});this.points.length>1200&&this.points.splice(0,this.points.length-1200)}step(e){let t=0;for(let n of this.points)n.age+=e,n.age<n.lifetime&&(this.points[t++]=n);this.points.length=t}stamps(){return this.points.map(({point:e,width:t,age:n,lifetime:r})=>({point:e,radius:Math.max(5,t*.8),progress:.42,flow:S(0,-25),strength:Math.max(0,1-(n/r)**2)*1.85,stir:!1}))}emberSource(){if(!this.points.length)return null;let e=this.points[Math.floor(Math.random()*this.points.length)];return{point:e.point,radius:e.width*.42,heat:Math.max(0,1-(e.age/e.lifetime)**2)}}},$s=3.2;function ec(e,t,n){let r=Math.max(0,Math.min(1,(n-e)/(t-e)));return r*r*(3-2*r)}function tc(e){return{dissipation:.55+2.3*ec(1.35,2.65,e),opacity:1-ec(2.25,$s,e)}}var nc=class{gl;width;height;texture;framebuffer;disposed=!1;constructor(e,t,n,r,i,a){this.gl=e,this.width=n,this.height=r;let o=e.createTexture(),s=e.createFramebuffer();if(!o||!s)throw o&&e.deleteTexture(o),s&&e.deleteFramebuffer(s),Error(`Unable to allocate GPU checkpoint`);this.texture=o,this.framebuffer=s;let c=e.getParameter(e.READ_FRAMEBUFFER_BINDING),l=e.getParameter(e.DRAW_FRAMEBUFFER_BINDING),u=e.getParameter(e.TEXTURE_BINDING_2D);try{if(e.bindTexture(e.TEXTURE_2D,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),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.texImage2D(e.TEXTURE_2D,0,i,n,r,0,e.RGBA,a,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,s),e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),e.checkFramebufferStatus(e.DRAW_FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)throw Error(`GPU checkpoint target is incomplete`);if(e.bindFramebuffer(e.READ_FRAMEBUFFER,t),e.blitFramebuffer(0,0,n,r,0,0,n,r,e.COLOR_BUFFER_BIT,e.NEAREST),e.getError()!==e.NO_ERROR)throw Error(`GPU checkpoint copy failed`)}catch(t){throw e.deleteFramebuffer(s),e.deleteTexture(o),t}finally{e.bindFramebuffer(e.READ_FRAMEBUFFER,c),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,l),e.bindTexture(e.TEXTURE_2D,u)}}restore(e,t=this.width,n=this.height){if(this.disposed)throw Error(`GPU checkpoint has been disposed`);let r=this.gl,i=r.getParameter(r.READ_FRAMEBUFFER_BINDING),a=r.getParameter(r.DRAW_FRAMEBUFFER_BINDING);try{if(r.bindFramebuffer(r.READ_FRAMEBUFFER,this.framebuffer),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.blitFramebuffer(0,0,this.width,this.height,0,0,t,n,r.COLOR_BUFFER_BIT,r.NEAREST),r.getError()!==r.NO_ERROR)throw Error(`GPU checkpoint restore failed`)}finally{r.bindFramebuffer(r.READ_FRAMEBUFFER,i),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,a)}}dispose(){this.disposed||(this.disposed=!0,this.gl.deleteFramebuffer(this.framebuffer),this.gl.deleteTexture(this.texture))}},rc=`
|
|
98
98
|
uniform int vehicleLightCount;
|
|
99
99
|
uniform vec4 vehicleLightPosition[12];
|
|
100
100
|
uniform vec4 vehicleLightShape[12];
|
|
@@ -846,4 +846,4 @@ void main() {
|
|
|
846
846
|
float alpha = clamp((shape * (0.15 + sweep * 0.6) + rim * 0.75) * pulse, 0.0, 0.78);
|
|
847
847
|
vec3 tint = dark ? vec3(1.0, 0.86, 0.55) : vec3(0.72, 0.38, 0.08);
|
|
848
848
|
color = vec4(tint, alpha);
|
|
849
|
-
}`,`Object glint`),this.texture=e.createTexture(),this.texture||(G(e,this.program),this.program=null))}trigger(e,t,n,r){let i=this.gl;if(!i||!this.program||!this.texture)return;this.canvas.width=this.mask.width=Math.ceil(e*n),this.canvas.height=this.mask.height=Math.ceil(t*n);let a=this.mask.getContext(`2d`);a&&(a.setTransform(n,0,0,n,0,0),a.clearRect(0,0,e,t),r(a),i.bindTexture(i.TEXTURE_2D,this.texture),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,this.mask),this.startedAt=performance.now())}draw(e,t,n,r){let i=this.gl,a=(performance.now()-this.startedAt)/this.duration;!i||!this.program||!this.texture||a<0||a>=1||(i.viewport(0,0,this.canvas.width,this.canvas.height),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.useProgram(this.program),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.texture),i.uniform1i(W(this.program,`mask`),0),as(this.program,{pixel:[1/this.canvas.width,1/this.canvas.height],progress:a,dark:Number(r)}),i.drawArrays(i.TRIANGLES,0,3),d(`composited megapixels`,this.canvas.width*this.canvas.height/1e6),e.drawImage(this.canvas,0,0,t,n))}dispose(){this.gl&&(this.texture&&this.gl.deleteTexture(this.texture),this.program&&G(this.gl,this.program),this.texture=null,this.program=null)}},Fl=e({Renderer:()=>Il}),Il=class{overlay;canvasWorld;vehicleImageLoadState(e){return this.vehicles.imageLoadState(e)}carVisualOffset(e){return this.vehicles.carVisualOffset(e)}get cameraLock(){return this.view.cameraLock}set cameraLock(e){this.view.cameraLock=e}get cameraSmoothing(){return this.view.cameraSmoothing}set cameraSmoothing(e){this.view.cameraSmoothing=e}get deadZone(){return this.view.deadZone}set deadZone(e){this.view.deadZone=e}screen(e){return this.view.screen(e)}world(e){return this.view.world(e)}vehicleViewportPosition(e){return this.view.vehicleViewportPosition(e)}sceneScroll(){return this.view.sceneScroll()}get documentProjection(){return this.view.documentProjection}virtualOffset(){return this.view.virtualOffset()}documentPoint(e){return this.view.documentPoint(e)}worldFromDocument(e){return this.view.worldFromDocument(e)}documentScale(){return this.view.documentScale()}viewportSize(){return this.view.viewportSize()}presentationScale(){return this.view.presentationScale()}setSlowMoZoom(e){this.view.slowMoZoom=e}setCanvasWorldScale(e,t=1.5){this.view.setCanvasWorldScale(e,t)}setCameraFrame(e){this.view.setCameraFrame(e)}setCameraLock(e){this.view.setCameraLock(e)}viewportFromDocument(e){return this.view.viewportFromDocument(e)}documentFromViewport(e){return this.view.documentFromViewport(e)}bounds(){return this.view.bounds()}vehicleMarkerAt(e){if(!this.showVehicleMarkers)return null;let t=this.view.documentFromViewport(e);return this.vehicles.markerAt(this.view.screen(this.view.worldFromDocument(t)))}revealVehicle(e){this.view.revealVehicle(e)}resumeFollow(){this.view.resumeFollow()}interruptFollow(){this.view.interruptFollow()}restorePage(e){this.view.restorePage(e)&&(this.lastFlowCenter=null,this.flowVelocity=S())}followDocument(e){return this.view.followDocument(e)}primaryVehicleVisible=!0;primaryVehicleOpacity=1;beginVehicleArrivalFade(){this.skidTracks.beginReveal(this.skidView(),this.darkSurface()),this.primaryVehicleOpacity=0}setVehicleArrivalOpacity(e){this.primaryVehicleOpacity=y(e,0,1),this.skidTracks.setRevealAlpha(this.primaryVehicleOpacity,this.skidView(),this.darkSurface())}view;surface;vehicles;debris=new u;get ctx(){return this.surface.context}nextHistoryPrune=0;trailClock=0;quality=w.game.quality;fluidGovernor=new Ce;vehicleLights=new Us;surfaceTones=new Js;vehicleLighting={...te};setVehicleLighting(e){this.vehicleLighting=ee({...this.vehicleLighting,...e})}getVehicleLighting(){return{...this.vehicleLighting}}toggleVehicleLight(e){return this.setVehicleLighting({[e]:e===`underglow`?this.vehicleLighting.underglow?void 0:`#66e6ff`:!this.vehicleLighting[e]}),this.getVehicleLighting()}surfaceTone=w.game.surfaceTone;trail=[];skidTracks=new Ol;volumetrics;pointPuffs=[];objectGlint=null;showVehicleMarkers=w.game.showVehicleMarkers;tireSmokeEnabled=w.game.tireSmoke;vehicleShadowsEnabled=w.game.vehicleShadows;effectsFadeStartedAt=null;wallRects=[];combustion;sparks=new jc;liquidLayer;tireMarks=new xl;seedGroundMarks(e){this.overlay&&this.tireMarks.seed(e,this.particleScale())}focusVehicle=null;activeVehicles=[];bindVehicle(e){this.focusVehicle=e}forgetVehicle(e){this.tireMarks.forgetVehicle(e),this.activeVehicles=this.activeVehicles.filter(t=>t.id!==e),this.focusVehicle?.id===e&&(this.focusVehicle=null)}get rocketFlightPosition(){let e=this.focusVehicle?.sim.body.position??S(),t=null,n=1/0;for(let r of this.activeVehicles){let i=r.weapons.rocket.projectile?.position;if(!i)continue;let a=p(b(i,e));a<n&&(t=i,n=a)}return t}screenShake=new jl;exhaustBursts=[];queueExhaustPops(e){for(let t of e)t<.12||this.exhaustBursts.push({age:0,lifetime:.08+t*.11,intensity:.4+t*.6});this.exhaustBursts.length>6&&this.exhaustBursts.splice(0,this.exhaustBursts.length-6)}lastFlowCenter=null;flowVelocity=S();captureState(){let e=[],t=t=>(t&&e.push(()=>t.dispose()),t);try{let n=t(this.volumetrics.captureState()),r=t(this.combustion.captureState()),i=t(this.liquidLayer.captureState());return{at:performance.now(),data:l({primaryVehicleVisible:this.primaryVehicleVisible,primaryVehicleOpacity:this.primaryVehicleOpacity,nextHistoryPrune:this.nextHistoryPrune,trailClock:this.trailClock,quality:this.quality,fluidQualityLimit:this.fluidGovernor.limit,vehicleLighting:this.vehicleLighting,surfaceTone:this.surfaceTone,trail:this.trail,pointPuffs:this.pointPuffs,showVehicleMarkers:this.showVehicleMarkers,tireSmokeEnabled:this.tireSmokeEnabled,vehicleShadowsEnabled:this.vehicleShadowsEnabled,effectsFadeStartedAt:this.effectsFadeStartedAt,wallRects:this.wallRects,exhaustBursts:this.exhaustBursts,lastFlowCenter:this.lastFlowCenter,flowVelocity:this.flowVelocity,debugDrive:this.debugDrive,previewGroundFire:this.previewGroundFire,previewWallSmoke:this.previewWallSmoke,previewSparks:this.previewSparks,previewDamage:this.previewDamage,previewOil:this.previewOil,previewOilSplatter:this.previewOilSplatter,oilSplatterPreviewSeconds:this.oilSplatterPreviewSeconds,sparkPreviewClock:this.sparkPreviewClock,damagePreviewApplied:this.damagePreviewApplied,groundFirePreviewLit:this.groundFirePreviewLit,trailLifetime:this.trailLifetime,fallbackSurfaceTone:this.fallbackSurfaceTone}),camera:this.view.captureState(),diagnostics:this.diagnostics.captureState(),vehicles:this.vehicles.captureState(),volumetrics:n,combustion:r,liquids:i,debris:this.debris.captureState(),skidTracks:this.skidTracks.captureState(),tireMarks:this.tireMarks.captureState(),sparks:this.sparks.captureState(),screenShake:this.screenShake.captureState(),dispose:()=>e.forEach(e=>e())}}catch(t){throw e.forEach(e=>e()),t}}restoreState(e){let t=this.captureState();try{this.applyState(e)}catch(e){try{this.applyState(t)}catch(t){throw AggregateError([e,t],`Renderer checkpoint rollback failed`,{cause:t})}throw e}finally{t.dispose()}}applyState(e){this.clearEffects();let t=l(e.data);this.primaryVehicleVisible=t.primaryVehicleVisible,this.primaryVehicleOpacity=t.primaryVehicleOpacity,this.nextHistoryPrune=t.nextHistoryPrune,this.trailClock=t.trailClock,this.quality=t.quality,this.fluidGovernor.restoreLimit(t.fluidQualityLimit),this.vehicleLighting=t.vehicleLighting,this.surfaceTone=t.surfaceTone,this.trail=t.trail,this.pointPuffs=t.pointPuffs,this.showVehicleMarkers=t.showVehicleMarkers,this.tireSmokeEnabled=t.tireSmokeEnabled,this.vehicleShadowsEnabled=t.vehicleShadowsEnabled,this.effectsFadeStartedAt=t.effectsFadeStartedAt,this.wallRects=t.wallRects,this.exhaustBursts=t.exhaustBursts,this.lastFlowCenter=t.lastFlowCenter,this.flowVelocity=t.flowVelocity,this.debugDrive=t.debugDrive,this.previewGroundFire=t.previewGroundFire,this.previewWallSmoke=t.previewWallSmoke,this.previewSparks=t.previewSparks,this.previewDamage=t.previewDamage,this.previewOil=t.previewOil,this.previewOilSplatter=t.previewOilSplatter,this.oilSplatterPreviewSeconds=t.oilSplatterPreviewSeconds,this.sparkPreviewClock=t.sparkPreviewClock,this.damagePreviewApplied=t.damagePreviewApplied,this.groundFirePreviewLit=t.groundFirePreviewLit,this.trailLifetime=t.trailLifetime,this.fallbackSurfaceTone=t.fallbackSurfaceTone,this.view.restoreState(e.camera),this.diagnostics.restoreState(e.diagnostics),this.vehicles.restoreState(e.vehicles),this.volumetrics.setQuality(this.fluidGovernor.apply(this.quality)),this.volumetrics.restoreState(e.volumetrics),this.combustion.setQuality(this.fluidGovernor.apply(this.quality)),this.combustion.restoreState(e.combustion),this.liquidLayer.restoreState(e.liquids),e.debris&&this.debris.restoreState(e.debris),this.skidTracks.restoreState(e.skidTracks,this.skidView(),this.darkSurface()),this.tireMarks.restoreState(e.tireMarks),this.sparks.restoreState(e.sparks),this.screenShake.restoreState(e.screenShake),this.effectsFadeStartedAt!==null&&(this.effectsFadeStartedAt+=performance.now()-e.at),this.view.rebaseTime(performance.now()),this.view.restorePresentation()}get flamethrowerFiring(){return this.activeVehicles.some(e=>e.weapons.flamethrower.firing)}get managedMemoryGroups(){return[{label:`Tire marks`,bytes:this.skidTracks.managedBytes+this.activeVehicles.reduce((e,t)=>e+t.tirePaint.managedBytes,0)+this.tireMarks.managedBytes},{label:`Smoke`,bytes:this.volumetrics.smokeBytes},{label:`Ghost`,bytes:this.volumetrics.ghostBytes},{label:`Fire`,bytes:this.combustion.managedBytes},{label:`Liquids`,bytes:this.liquidLayer.managedBytes},{label:`Debris`,bytes:this.debris.managedBytes+Ie().bytes},{label:`Tools`,bytes:this.activeVehicles.reduce((e,t)=>e+t.weapons.managedBytes,0)},{label:`Sparks`,bytes:this.sparks.count*112},{label:`Points`,bytes:this.pointPuffs.length*32},{label:`Vehicle trail`,bytes:this.trail.length*48}]}get managedBytes(){return this.managedMemoryGroups.reduce((e,t)=>e+t.bytes,0)}debugDrive=!1;previewGroundFire=!1;previewWallSmoke=!1;previewSparks=!1;previewDamage=!1;previewOil=!1;previewOilSplatter=!1;oilSplatterPreviewSeconds=0;sparkPreviewClock=0;damagePreviewApplied=!1;groundFirePreviewLit=!1;diagnostics=new js;trailLifetime=12;constructor(e,t=!1,n=w.game.quality,r=!1){this.overlay=t,this.canvasWorld=r,this.view=new ks(t,r,()=>this.resize()),this.surface=new As(e,this.view,t,r),this.combustion=new pc(this.view,n),this.volumetrics=new vc(this.view,n),this.liquidLayer=new gl(this.view,n),this.vehicles=new hs(this.view),this.quality=n,this.resize()}get pixelSpace(){return this.overlay||this.canvasWorld}prepareFire(){return this.sparks.prepare()?this.combustion.ensure():!1}setQuality(e){if(e===this.quality)return;this.quality=e;let t=this.fluidGovernor.apply(e);this.volumetrics.setQuality(t),this.liquidLayer.setQuality(e),this.combustion.setQuality(t)}applyFluidQuality(){let e=this.fluidGovernor.apply(this.quality);this.volumetrics.setQuality(e),this.combustion.setQuality(e)}setTireSmokeEnabled(e){this.tireSmokeEnabled=e}setVehicleShadowsEnabled(e){this.vehicleShadowsEnabled=e}setAbsoluteViewport(){this.surface.setAbsoluteViewport()}setSparksEnabled(e){this.sparks.setEnabled(e)}setScreenShakeEnabled(e){this.screenShake.setEnabled(e)}setScreenShakeProfiles(e){this.screenShake.setProfiles(e)}emitCrashShake(e){if(this.effectsFadeStartedAt!==null)return;let t=Al(e);t&&this.screenShake.trigger(t)}emitRocketExplosionShake(e=1){this.effectsFadeStartedAt===null&&this.screenShake.trigger(`rocketExplosion`,Math.sqrt(Math.max(0,e)))}emitCombustibleExplosion(e,t){if(this.effectsFadeStartedAt!==null)return;this.screenShake.trigger(`combustibleExplosion`);let n=this.particlePoint(this.worldFromDocument(e));this.sparks.emitExplosion(n,S(),this.particleScale(),1.2),this.combustion.queueBlast(n,t*this.particleScale()/Math.max(1,this.documentScale())),this.emitCombustibleBlast(e,t,0)}emitCombustibleBlast(e,t,n){if(this.effectsFadeStartedAt!==null||!this.combustion.activateBuoyancy())return;let r=this.particlePoint(this.worldFromDocument(e)),i=t*this.particleScale()/Math.max(1,this.documentScale()),a=Math.min(1,n/.34);for(let e=0;e<24;e++){let t=e*Math.PI*(3-Math.sqrt(5)),n=S(Math.cos(t),Math.sin(t));this.combustion.queueStamp({point:x(r,_(n,i*a*1.05)),radius:Math.max(4,i*(.29-a*.12)),flow:x(_(n,i*(2.6-a)),S(0,-i*.4)),progress:.28+a*.53,blast:!0})}}emitRocketExplosion(e,t,n=1){if(this.effectsFadeStartedAt!==null)return;let r=this.particlePoint(this.worldFromDocument(e)),i=this.particleVelocity(S(t.x/this.view.zoom,-t.y/this.view.zoom)),a=this.particleScale(),o=Math.sqrt(y(n,.5,2));this.combustion.ensure()&&(this.combustion.queueBlast(r,a*2.2*o),this.combustion.queueStamp({point:r,radius:a*.95*o,flow:S(0,-a*.7),progress:.24,strength:2.6,blast:!0}));for(let t=0;t<64;t++){let n=t*Math.PI*(3-Math.sqrt(5))+Math.atan2(i.y,i.x),s=a*Math.sqrt((t+.5)/64)*1.75*(.83+.17*Math.sin(t*11.8+e.x*.03))*o,c=S(Math.cos(n),Math.sin(n));this.combustion.available&&this.combustion.queueStamp({point:x(r,_(c,s)),radius:a*(.38+t%4*.065)*o,flow:x(_(c,a*2.5),S(0,-a*.5)),progress:.3+t%5*.06,strength:1.7+t%3*.28,blast:!0})}this.sparks.emitExplosion(r,i,a,n),this.sparks.emitFireAt(r,a*.5,.25,14)}setDeformEnabled(e){this.focusVehicle?.damage.setEnabled(e),e||(this.damagePreviewApplied=!1)}resetVehicleDamage(){this.focusVehicle?.damage.reset()}emitSparks(e){this.effectsFadeStartedAt===null&&this.sparks.emit(e)}emitVehicleBurn(e,t,n,r){let i=e.sim,a=this.documentScale(),o=x(this.documentPoint(i.body.position),this.carVisualOffset(i)),s=n.lengthM*a,c=n.widthM*a,l=S(Math.cos(i.body.angle),-Math.sin(i.body.angle)),u=S(-l.y,l.x),d=x(o,x(_(l,t.burnOriginLocal.x*a),_(u,t.burnOriginLocal.y*a))),p=this.combustion.alphaFor(n.alpha.solid);if(t.stage===`exploded`)return t.explosionStarted&&this.emitCombustibleExplosion(o,Math.max(78,s*.7)),t.blastAge<v.fireballSeconds&&this.emitSceneFire({key:t.key,alpha:p,pixelWidth:n.alpha.columns,pixelHeight:n.alpha.rows,x:o.x-s/2,y:o.y-c/2,width:s,height:c,angle:-i.body.angle,origin:o,farthest:Math.hypot(s,c),...f(t.blastAge)},r),t.blastPulse&&this.emitCombustibleBlast(o,Math.max(78,s*.7),t.blastAge),t.explosionStarted?o:null;let m=h(t.health,t.maxHealth,s,c);return m&&this.emitSceneFire({key:t.key,alpha:p,pixelWidth:n.alpha.columns,pixelHeight:n.alpha.rows,x:o.x-s/2,y:o.y-c/2,width:s,height:c,angle:-i.body.angle,origin:d,farthest:Math.hypot(s,c),...m},r),null}sceneFireDue(e){return this.effectsFadeStartedAt===null&&this.combustion.sceneMasksDue(e)}emitSceneFire(e,t=1/60){this.effectsFadeStartedAt===null&&this.combustion.queueMask(e)}pourWorldLiquid(e,t,n,r,i){this.liquidLayer.pourWorldLiquid(e,t,n,r,i)}emitPaint(e,t,n,r,i){this.liquidLayer.emitPaint(e,t,n,r,i)}igniteLiquidAt(e,t){this.liquidLayer.igniteAt(e,t)}igniteLiquidsFromFire(e){this.liquidLayer.igniteFromFire(e)}burningLiquidSources(){return this.liquidLayer.burningSources()}hasLiquidContact(e,t){return this.liquidLayer.hasContact(e,t)}addLiquid(e,t){this.liquidLayer.add(e,t)}syncElementLiquids(e){return this.liquidLayer.syncElements(e)}ejectLiquid(e,t=`oil`,n){this.liquidLayer.pourVehicle(e,t,.65,n)}setInitialPuddles(e){this.liquidLayer.setInitialPuddles(e)}setSurfaceTone(e){this.surfaceTone=e}fallbackSurfaceTone={at:-1/0,dark:!1};darkSurface(){if(this.surfaceTone!==`auto`)return this.surfaceTone===`dark`;let e=document.documentElement.dataset.jrTheme;if(e===`light`||e===`dark`)return e===`dark`;let t=performance.now();if(t-this.fallbackSurfaceTone.at<80)return this.fallbackSurfaceTone.dark;let n=getComputedStyle(document.body).backgroundColor,r=Gs(/rgba\([^)]*,\s*0(?:\.0+)?\s*\)/.test(n)||n===`transparent`?getComputedStyle(document.documentElement).backgroundColor:n);return this.fallbackSurfaceTone={at:t,dark:r},r}setDebugEnabled(e){this.debugDrive=e||!1}fadeEffects(){if(this.effectsFadeStartedAt!==null)return;this.effectsFadeStartedAt=performance.now(),this.liquidLayer.clearEffects(),this.liquidLayer.restoreInitialPuddles(),this.volumetrics.clearSmokeSources();let e=this.activeVehicles.length?this.activeVehicles:this.focusVehicle?[this.focusVehicle]:[];for(let t of e)t.weapons.reset(),t.tirePaint.reset(),t.pickupEffect.reset(),t.damage.reset();this.screenShake.reset(),this.skidTracks.fade(),this.combustion.clearTireHistory(),this.exhaustBursts=[]}clearEffects(e=!0){this.debris.reset(),this.objectGlint?.dispose(),this.objectGlint=null,this.trail=[],this.skidTracks.clear(),this.volumetrics.reset(),this.pointPuffs=[];for(let e of this.activeVehicles.length?this.activeVehicles:this.focusVehicle?[this.focusVehicle]:[])e.pickupEffect.reset(),e.weapons.rocket.reset(),e.weapons.machineGuns.reset(),e.weapons.flamethrower.reset();this.screenShake.reset(),this.combustion.reset(),this.exhaustBursts=[],this.sparks.reset(),e&&this.liquidLayer.clearEffects(),this.tireMarks.clear(),this.lastFlowCenter=null,this.flowVelocity=S(),this.trailClock=0,this.effectsFadeStartedAt=null}reset(){this.view.reset(),this.clearEffects(),this.liquidLayer.restoreInitialPuddles(),this.wallRects=[],this.groundFirePreviewLit=!1,this.sparkPreviewClock=0,this.damagePreviewApplied=!1,this.vehicles.reset(),this.surface.clear(),this.view.resetFollow()}dispose(){this.liquidLayer.dispose(),this.debris.clear(),this.vehicles.dispose(),this.objectGlint?.dispose(),this.surface.dispose(),this.view.dispose(),this.skidTracks.clear(),this.tireMarks.clear(),this.volumetrics.dispose(),this.combustion.dispose(),this.sparks.dispose()}resize(){let e=this.surface.resize();this.liquidLayer.resize(),this.volumetrics.resize(e),this.combustion.resize(e)}rasterPixelRatio(){return this.canvasWorld?Math.min(2,Math.round(this.view.dpr/this.view.regionScale*100)/100):this.view.dpr}setShowVehicleMarkers(e){this.showVehicleMarkers=e}flashTargets(e){this.resize(),this.objectGlint??=new Pl;let t=this.sceneScroll();this.objectGlint.trigger(this.view.width,this.view.height,this.view.dpr,n=>e(n,t))}particlePoint(e){return this.view.particlePoint(e)}particleScreen(e){return this.pixelSpace?b(e,this.sceneScroll()):this.screen(e)}particleVelocity(e){return this.pixelSpace?S(e.x*this.view.zoom,-e.y*this.view.zoom):{...e}}particleScale(){return this.view.particleScale()}emitPoints(e,t){t<=0||this.pointPuffs.push({point:this.particlePoint(this.worldFromDocument(e)),amount:t,age:0})}fluidView(){let e=this.sceneScroll();return this.pixelSpace?{origin:S(this.view.smokeMargin-e.x,this.view.smokeMargin-e.y),scaleX:1,scaleY:1}:{origin:S(this.view.width/2-this.view.camera.x*this.view.zoom,this.view.height/2+this.view.camera.y*this.view.zoom),scaleX:this.view.zoom,scaleY:-this.view.zoom}}flameView(){let e=this.fluidView();return this.pixelSpace?{...e,origin:S(e.origin.x-this.view.smokeMargin,e.origin.y-this.view.smokeMargin)}:e}clipFluidWalls(e){if(!this.overlay)return;let t=this.sceneScroll();for(let n of this.wallRects){let r=n.x-t.x,i=n.y-t.y;n.width<=0||n.height<=0||r>=this.view.width||i>=this.view.height||r+n.width<=0||i+n.height<=0||(e.beginPath(),e.rect(0,0,this.view.width,this.view.height),e.rect(r,i,n.width,n.height),e.clip(`evenodd`))}}stepVehicleWeapons(e,t,n,r,i,a,o,s,c){let l=e.sim;performance.now(),e.weapons.rocket.step(t,l,e=>{this.effectsFadeStartedAt===null&&this.volumetrics.emitSmoke({point:this.particlePoint(e.point),amount:e.amount,flow:this.particleVelocity(e.flow),radiusPx:e.radiusM*this.view.zoom,swirlPx:10})},n?(t,r,i)=>{let a=n(e,this.documentPoint(t),this.documentPoint(r),i*this.documentScale());return a?this.worldFromDocument(a):null}:void 0,e=>{this.effectsFadeStartedAt===null&&this.combustion.emitJet(e.from,e.to,e.flow,e.widthM,e.intensity,`rocket`)},o,s,void 0),e.weapons.machineGuns.step(t,l,r?(t,n,i)=>{let a=r(e,this.documentPoint(t),this.documentPoint(n),i*this.documentScale());return a?this.worldFromDocument(a):null}:void 0,i,(e,t)=>{this.effectsFadeStartedAt===null&&this.sparks.emitBulletImpact(this.particlePoint(e),this.particleVelocity(t)),c?.(e)}),e.weapons.flamethrower.step(t,l,e=>{this.effectsFadeStartedAt===null&&this.volumetrics.emitSmoke({point:this.particlePoint(e.point),amount:e.amount,flow:this.particleVelocity(e.flow),radiusPx:e.radiusM*this.view.zoom,swirlPx:10})},a?(t,n,r,i)=>{let o=a(e,this.documentPoint(t),this.documentPoint(n),r*this.documentScale(),i);return o?this.worldFromDocument(o):null}:void 0,(e,n,r,i,a)=>{if(this.effectsFadeStartedAt!==null)return;let o=this.particleScale();this.liquidLayer.igniteAlong(this.particlePoint(e),this.particlePoint(n),r*o*.5),a>.3&&this.sparks.emitFireAt(this.particlePoint(n),r*o*.4,t,3),this.combustion.queueStamp({point:this.particlePoint(n),radius:r*o,progress:a,flow:this.particleVelocity(i)})})}sprayTirePaint(e,t,n,r,i,a,o,s){return this.liquidLayer.splatter(e,t,n,r,i,a,o,s)}advanceEffects(e,t,{walls:r=[],carMask:i,tirePaintSources:a=[],driven:o=!0,rocketCollision:s,bulletCollision:c,onGunshot:l,flameContact:u,onRocketLaunch:d,onRocketImpact:f,onBulletImpact:h,maskFor:g,companions:v=[]}={}){for(let e of this.pointPuffs)e.age+=t;this.pointPuffs=this.pointPuffs.filter(e=>e.age<.9),this.activeVehicles=[e,...v];let y=this.sceneScroll();this.debris.count&&this.debris.step(t,this.activeVehicles.filter(e=>e.sim.mode===`car`&&!e.isGhost&&e.sim.car.explodedAt===null).map(e=>{let t=this.particlePoint(e.sim.body.position),n=this.particleVelocity(e.sim.body.velocity),r=this.particleScale();return{x:t.x,y:t.y,vx:n.x,vy:n.y,angle:-e.sim.body.angle,length:e.sim.car.preset.geometry.lengthM*r,width:e.sim.car.preset.geometry.widthM*r}}),{x:y.x,y:y.y,width:this.view.width,height:this.view.height},r),this.volumetrics.stepGhost(t,this.activeVehicles,r,g,this.flameView(),e=>this.carVisualOffset(e.sim),e=>{let t=this.vehicles.imageFor(e.sim.car.preset);if(!t)return;let n=D(e.sim.car.preset,t.naturalWidth,t.naturalHeight),r=e.damage.spriteFor(t,n);return{image:r??t,source:r?{x:0,y:0,width:r.width,height:r.height}:n.source}});let C=e.sim;if(this.wallRects=r,this.vehicles.updateCarPose(C,t),this.effectsFadeStartedAt===null){for(let e of this.activeVehicles)for(let r of e.liquidEmissions(t))this.liquidLayer.pourVehicle(e.sim,n(r.liquid),r.amount,void 0,e.id);this.previewOil&&!this.previewOilSplatter&&this.liquidLayer.pourVehicle(C,`oil`,t*6)}for(let n of[e,...v])this.stepVehicleWeapons(n,t,s,c,l,u,d,f,h);let{tires:w,companionTires:ee}=this.liquidLayer.stepVehicles(e,v,t,o,a,this.effectsFadeStartedAt!==null,(e,t)=>this.emitSceneFire(e,t)),te=this.documentScale(),T=S(Math.cos(C.body.angle),-Math.sin(C.body.angle)),E=C.mode===`car`&&i&&!e.isGhost?{mask:i.alpha,shape:{center:x(this.documentPoint(C.body.position),this.carVisualOffset(C)),forward:T,side:S(-T.y,T.x),halfLength:i.lengthM*te/2,halfWidth:i.widthM*te/2}}:void 0;this.previewDamage&&!this.damagePreviewApplied&&E&&(this.damagePreviewApplied=e.damage.hit(x(E.shape.center,_(E.shape.forward,E.shape.halfLength)),_(E.shape.forward,-1),E.shape,20,te));for(let e of this.activeVehicles){if(e.sim.mode!==`car`||this.effectsFadeStartedAt!==null)continue;let n=g?.(e)??e.sim.car.preset.geometry;for(let r of e.pickupEffect.active){let i=S(Math.cos(r.angle),Math.sin(r.angle)),a=this.particleVelocity(m(i,e.sim.body.angle));for(let i of vs(r,n,t)){let t=e.sim.body.world(i);this.sparks.pickup(this.particlePoint(t),_(a,r.velocity),a,r.color,this.particleScale(),Math.max(.2,r.strength),1)}}}if(performance.now(),C.mode===`car`&&p(C.body.velocity)>.15&&this.sparks.disturb(this.particlePoint(C.body.position),this.particleVelocity(C.body.velocity),this.particleScale()*2.8),this.sparks.step(t,{walls:r,car:E}),this.previewSparks&&C.mode===`car`&&(this.sparkPreviewClock+=t,this.sparkPreviewClock>.12)){this.sparkPreviewClock=0;let e=this.particlePoint(C.body.position),t=this.particleScale();this.emitSparks({point:x(e,S(t*1.9,0)),velocity:S(t*4,t*10),normal:S(-1,0),pixelsPerMeter:t})}let ne=this.particleScale(),re=this.particlePoint(C.body.position),ie=this.lastFlowCenter?_(b(re,this.lastFlowCenter),1/Math.max(t,1e-4)):this.particleVelocity(C.body.velocity),ae=p(ie),oe=ae>40*ne?_(ie,40*ne/ae):ie;this.flowVelocity=x(this.flowVelocity,_(b(oe,this.flowVelocity),1-Math.exp(-12*t))),this.lastFlowCenter=re;let se=this.pixelSpace?this.flowVelocity:S(this.flowVelocity.x*this.view.zoom,-this.flowVelocity.y*this.view.zoom),ce=S(Math.cos(C.body.angle),-Math.sin(C.body.angle)),O=C.mode===`car`?{center:x(this.screen(C.body.position),S(this.view.smokeMargin,this.view.smokeMargin)),velocity:se,forward:ce,halfLength:C.car.preset.geometry.lengthM*this.view.zoom*.46,halfWidth:C.car.preset.geometry.widthM*this.view.zoom*.39,spin:-C.body.spin}:null;if(this.effectsFadeStartedAt!==null){this.volumetrics.clearSmokeSources(),this.combustion.stepTire(t),this.combustion.step(t,this.view.timeSeconds,e.isGhost?null:O,this.wallRects,!0,this.flameView(),this.sparks),this.volumetrics.stepSmoke(t,O,this.wallRects,this.fluidView());return}if(this.previewWallSmoke&&this.overlay){let e=this.sceneScroll(),n=this.wallRects.filter(t=>t.x-e.x>48&&t.x-e.x<this.view.width-48&&t.y+t.height/2-e.y>30&&t.y+t.height/2-e.y<this.view.height-30),r=n.find(t=>t.x-e.x>this.view.width*.5)??n[0];r&&this.volumetrics.emitSmoke({point:S(r.x-25,r.y+r.height/2),amount:t*15,flow:S(210,0),radiusPx:17,swirlPx:25})}if(performance.now(),this.combustion.stepTire(t),this.combustion.step(t,this.view.timeSeconds,e.isGhost?null:O,this.wallRects,!1,this.flameView(),this.sparks),!this.pixelSpace){for(let e of this.trail)e.age+=t;if(this.trail=this.trail.filter(e=>e.age<this.trailLifetime),this.trailClock+=t,this.trailLifetime>0&&this.trailClock>=1/30){this.trailClock%=1/30;let e=this.trail.at(-1);(!e||p(b(e.point,C.body.position))>.04)&&this.trail.push({point:{...C.body.position},age:0,color:C.mode===`ship`?`#9bbcff`:C.mode===`brick`?`#f6bd79`:`#8ce6c5`}),this.trail.length>800&&this.trail.shift()}}if(C.mode!==`car`){this.volumetrics.stepSmoke(t,null,this.wallRects,this.fluidView()),this.skidTracks.stop(this.skidView(),this.darkSurface(),!0),this.combustion.clearTireHistory();return}if(e.isGhost){this.volumetrics.stepSmoke(t,null,this.wallRects,this.fluidView()),this.skidTracks.stop(this.skidView(),this.darkSurface()),this.combustion.clearTireHistory();return}let le=this.advanceVehicleTireEffects(e,t,w,ee,se),ue=this.combustion.emberSource();ue&&this.sparks.emitFireAt(ue.point,ue.radius,t,20*ue.heat),performance.now(),this.volumetrics.stepSmoke(t,O,this.wallRects,this.fluidView());let de=this.darkSurface();this.skidTracks.step(t,C,le,t=>!!e.tirePaint.coating(t),{pixelSpace:this.pixelSpace,scale:this.particleScale(),dark:de,project:e=>this.particlePoint(e),roadAt:(e,t)=>!!this.overlay&&this.surfaceTones.at(e,this.viewportFromDocument(t),de),view:this.skidView()})}advanceVehicleTireEffects(e,t,n,r,i){let a=e.sim,o=this.particleScale();if(this.previewGroundFire&&!this.groundFirePreviewLit){for(let e of a.car.tires.filter(e=>!e.front)){let t=a.body.world(e.local);this.combustion.igniteTire(this.particlePoint(a.body.world(x(e.local,S(-2.4)))),this.particlePoint(t),a.car.preset.geometry.tireWidthM*o,18,.2*o)}this.groundFirePreviewLit=!0}let s=p(a.body.velocity),c=s>.1?_(a.body.velocity,-1/s):m(S(-1),a.body.angle);this.previewOilSplatter&&(s>.5?this.oilSplatterPreviewSeconds=0:s<.2&&(this.oilSplatterPreviewSeconds+=t),this.oilSplatterPreviewSeconds<2.25&&this.liquidLayer.pourOilPreview(n[0].point,t));let l={zoom:this.view.zoom,particlePoint:e=>this.particlePoint(e),particleVelocity:e=>this.particleVelocity(e),spray:(...e)=>this.sprayTirePaint(...e),smoke:this.tireSmokeEnabled?e=>this.volumetrics.emitSmoke(e):void 0};Nl(e,n,0,t,c,i,l,this.previewOilSplatter&&s<.2&&this.oilSplatterPreviewSeconds>1&&this.oilSplatterPreviewSeconds<2.25);let u=n.length;for(let{vehicle:e,tires:n}of r){if(!e.isGhost){let r=e.sim,i=p(r.body.velocity),a=i>.1?_(r.body.velocity,-1/i):m(S(-1),r.body.angle);Nl(e,n,u,t,a,this.particleVelocity(r.body.velocity),l)}u+=n.length}e.isGhost&&(this.exhaustBursts=[]);for(let e of this.exhaustBursts){e.age+=t;let n=e.intensity*Math.max(0,1-e.age/e.lifetime);if(n<=0)continue;let r=m(S(-1,0),a.body.angle),i=x(_(r,4+5*n),_(a.body.velocity,.12));for(let e of this.vehicles.exhaustOutlets(a)){let o=a.body.world(e);if(this.combustion.emitJet(o,o,i,.13,n*.8,`exhaust`),n>.55){let e=x(o,_(r,1.45));this.volumetrics.emitSmoke({point:this.particlePoint(e),amount:t*n*.2,flow:this.particleVelocity(_(i,.48)),radiusPx:.13*this.particleScale(),swirlPx:7})}}}this.exhaustBursts=this.exhaustBursts.filter(e=>e.age<e.lifetime);let d=a.car.boostActive&&!e.isGhost;return d?this.combustion.stepBoostFire(a,t,e=>this.liquidLayer.igniteAtLocal(e)):this.combustion.clearTireHistory(),d}skidView(){return{pixelSpace:this.pixelSpace,zoom:this.view.zoom,width:this.view.width,height:this.view.height,screen:e=>this.particleScreen(e)}}vehicleLightInput(e,t,n){let r=T(e.sim.car.preset),i=e=>[-1,1].map(t=>S(e.xM*this.view.zoom,t*e.yM*this.view.zoom)),a=e.sim,o=this.vehicles.imageFor(a.car.preset)??void 0,s=o?D(a.car.preset,o.naturalWidth,o.naturalHeight):null,c=a.body.velocity.x*Math.cos(a.body.angle)+a.body.velocity.y*Math.sin(a.body.angle),l=a.lastInput,u=this.sceneScroll(),d=Math.max(l.brake??0,+!!l.action,+(l.throttle<0&&c>.5||l.throttle>0&&c<-.5));return{center:x(this.screen(a.body.position),this.carVisualOffset(a)),angle:-a.body.angle,width:(s?.lengthM??a.car.preset.geometry.lengthM)*this.view.zoom,height:(s?.widthM??a.car.preset.geometry.widthM)*this.view.zoom,mounts:{headlights:i(r.headlights),taillights:i(r.taillights)},image:o,source:s?.source,dark:e.appearance===`auto`?this.overlay?this.surfaceTones.at(e,this.viewportFromDocument(this.documentPoint(a.body.position)),t):t:e.appearance===`dark`,braking:d,options:this.vehicleLighting,opacity:n,walls:this.pixelSpace?this.wallRects.map(e=>({...e,x:e.x-u.x,y:e.y-u.y})):[]}}drawVehicleAndWeapons(e,t,n){performance.now(),d(`vehicle render passes`);let r=e.sim,{rocket:i,machineGuns:a,flamethrower:o}=e.weapons,s=this.ctx;if(e.isGhost){i.drawFlight(s,e=>this.screen(e),r.car.preset,this.view.zoom,t),a.drawProjectiles(s,e=>this.screen(e),this.view.zoom,t);return}let c=this.carVisualOffset(r);if(s.save(),s.translate(c.x,c.y),r.car.explodedAt===null){this.vehicles.car(this.ctx,r.body,r,e.damage,Math.max(o.openAmount,a.openAmount),e);let i=n??this.vehicleLightInput(e,this.darkSurface(),t);this.vehicleLights.glints(s,{...i,center:this.screen(r.body.position)})}let l;if(i.state!==`idle`||o.state!==`closed`||a.state!==`closed`){let t=this.vehicles.imageFor(r.car.preset);if(t){let n=D(r.car.preset,t.naturalWidth,t.naturalHeight),i=e.damage.spriteFor(t,n);l={image:i??t,source:i?{x:0,y:0,width:i.width,height:i.height}:n.source,lengthM:n.lengthM,widthM:n.widthM}}}r.car.explodedAt===null&&i.drawMount(s,this.screen(r.body.position),r.body.angle,r.car.preset,this.view.zoom,t,l),r.car.explodedAt===null&&o.state!==`closed`?o.drawMount(s,this.screen(r.body.position),r.body.angle,r.car.preset,this.view.zoom,t,l):r.car.explodedAt===null&&a.drawMount(s,this.screen(r.body.position),r.body.angle,r.car.preset,this.view.zoom,t,l),s.restore(),s.save(),this.clipFluidWalls(s),s.translate(c.x,c.y),r.car.explodedAt===null&&this.vehicles.exhaust(this.ctx,r),s.restore(),i.drawFlight(s,e=>this.screen(e),r.car.preset,this.view.zoom,t),a.drawProjectiles(s,e=>this.screen(e),this.view.zoom,t)}drawGroundLayers(e,t,n,r){let i=t.sim;if(!this.pixelSpace){let{left:e,right:t,bottom:n,top:r}=this.bounds();for(let i=Math.floor(e/5)*5;i<=t;i+=5)this.vehicles.line(this.ctx,S(i,n),S(i,r),`#293c46`);for(let i=Math.floor(n/5)*5;i<=r;i+=5)this.vehicles.line(this.ctx,S(e,i),S(t,i),`#293c46`)}for(let t of this.trail){let n=this.screen(t.point),i=1-t.age/this.trailLifetime;e.globalAlpha=.6*i*i*r,e.fillStyle=t.color,e.beginPath(),e.arc(n.x,n.y,.8+1.4*i,0,Math.PI*2),e.fill()}e.globalAlpha=1,e.save(),e.lineCap=`round`,e.lineJoin=`round`;let a=this.sceneScroll(),o=this.pixelSpace?{left:a.x,right:a.x+this.view.width,bottom:a.y,top:a.y+this.view.height}:{left:this.world(S(0,0)).x,right:this.world(S(this.view.width,0)).x,bottom:this.world(S(0,this.view.height)).y,top:this.world(S(0,0)).y},s=this.darkSurface();performance.now(),this.skidTracks.draw(e,{pixelSpace:this.pixelSpace,scroll:a,width:this.view.width,height:this.view.height,ratio:this.rasterPixelRatio(),dark:s,alpha:r,visible:o,view:this.skidView()}),performance.now();let c={pixelSpace:this.pixelSpace,scroll:a,width:this.view.width,height:this.view.height,particleScale:this.particleScale(),rasterRatio:this.rasterPixelRatio(),zoom:this.view.zoom,effectsAlpha:r,screen:e=>this.particleScreen(e)};return this.tireMarks.draw(e,[t,...n],!1,c),e.restore(),this.liquidLayer.draw(e,1),performance.now(),this.tireMarks.draw(e,[t,...n],!0,c),i.barrier&&!this.overlay&&(e.strokeStyle=`#d4ab71`,e.lineWidth=2,e.strokeRect(3,3,this.view.width-6,this.view.height-6)),{scroll:a,darkSurface:s}}render(e,t,n,r,i=[]){let a=e.sim;performance.now(),this.resize();let o=fe(this.effectsFadeStartedAt,t);if(this.effectsFadeStartedAt!==null&&o===0&&(this.clearEffects(!1),o=0),this.view.cameraStep(a,t),this.canvasWorld&&t>=this.nextHistoryPrune){this.nextHistoryPrune=t+2e3;let e=this.documentPoint(a.body.position),n=2800,r={x:e.x-n,y:e.y-n,width:n*2,height:n*2};this.skidTracks.pruneOutside(r),this.tireMarks.pruneOutside(r),this.liquidLayer.pruneOutside(r)}let s=this.ctx;this.surface.clear();let c=this.screenShake.sample(t);s.save(),(c.x||c.y)&&s.translate(c.x,c.y),r?.drawGround?.(s,this.sceneScroll(),{width:this.view.width,height:this.view.height});let{scroll:l,darkSurface:u}=this.drawGroundLayers(s,e,i,o),d=new Map((this.primaryVehicleVisible?[e,...i]:i).filter(e=>e.sim.mode===`car`&&e.sim.car.explodedAt===null&&!e.isGhost).map(t=>[t,this.vehicleLightInput(t,u,o*(t===e?this.primaryVehicleOpacity:1))])),f=[...d.values()].flatMap(e=>this.vehicleLights.smokeLights(e));this.pixelSpace&&(s.save(),s.translate(-l.x,-l.y),Be(s,this.debris.particles,{x:l.x,y:l.y,width:this.view.width,height:this.view.height},u,`ground`),s.restore());for(let t of this.primaryVehicleVisible?[e,...i]:i)t.sim.mode!==`car`||t.sim.car.explodedAt!==null||t.isGhost||t===e&&this.primaryVehicleOpacity<=0||(s.save(),t===e&&(s.globalAlpha*=this.primaryVehicleOpacity),this.vehicles.carGround(this.ctx,t.sim,t.damage,this.rasterPixelRatio(),this.vehicleShadowsEnabled),s.restore());for(let e of d.values())this.vehicleLights.ground(s,e);s.save(),performance.now(),this.clipFluidWalls(s),s.globalAlpha=o,s.save(),s.translate(-this.view.smokeMargin,-this.view.smokeMargin),this.volumetrics.drawSmoke(s,this.fluidView(),f.map(e=>({...e,point:x(e.point,S(this.view.smokeMargin,this.view.smokeMargin))})),u),s.restore(),s.restore(),s.globalAlpha=1,r?.draw(s,l,{width:this.view.width,height:this.view.height}),this.volumetrics.ghostAvailable&&(s.save(),s.globalAlpha=o,this.volumetrics.drawGhost(s,this.flameView(),u,f),s.restore()),this.primaryVehicleVisible&&a.mode===`car`&&(s.save(),s.globalAlpha*=this.primaryVehicleOpacity,this.drawVehicleAndWeapons(e,o,d.get(e)),s.restore(),this.debugDrive&&(r?.drawDebug?.(s,a,this,e.damage),this.diagnostics.draw(s,a,t,e=>this.screen(e),{width:this.view.width,rocketState:e.weapons.rocket.state,gunState:e.weapons.machineGuns.state,bulletCount:e.weapons.machineGuns.projectileCount,fluidEngine:this.volumetrics.smokeResolution.engine,quality:this.quality,fluidCols:this.volumetrics.smokeResolution.cols,fluidRows:this.volumetrics.smokeResolution.rows,fireCols:this.combustion.resolution?.cols??0,fireRows:this.combustion.resolution?.rows??0,groundedFireCount:this.combustion.count}))),this.primaryVehicleVisible&&a.mode===`ship`&&this.vehicles.ship(this.ctx,a.body,a),this.primaryVehicleVisible&&a.mode===`brick`&&this.vehicles.brick(this.ctx,a.body);for(let e of i){let t=e.sim;if(t.mode!==`car`||(this.drawVehicleAndWeapons(e,o,d.get(e)),t.car.explodedAt!==null))continue;let n=this.screen(t.body.position);s.save(),s.font=`600 10px ui-monospace, monospace`,s.textAlign=`center`;let r=e.label;if(!r)continue;let i=Math.max(30,Math.ceil(s.measureText(r).width)+14);s.fillStyle=`rgba(24, 27, 30, 0.88)`,s.fillRect(n.x-i/2,n.y-37,i,16),s.fillStyle=`#f5f2ec`,s.fillText(r,n.x,n.y-25),s.restore()}if(this.pixelSpace&&(s.save(),s.translate(-l.x,-l.y),Be(s,this.debris.particles,{x:l.x,y:l.y,width:this.view.width,height:this.view.height},u,`air`),s.restore()),s.save(),this.clipFluidWalls(s),performance.now(),this.combustion.draw(s,this.flameView(),u,f),s.restore(),performance.now(),this.sparks.draw(s,e=>this.particleScreen(e),o,{width:this.view.width,height:this.view.height},this.view.dpr,this.canvasWorld?void 0:this.surface.canvas),this.pointPuffs.length){s.save(),s.font=`700 13px ui-monospace, monospace`,s.textAlign=`center`,s.textBaseline=`middle`;for(let e of this.pointPuffs){let t=this.particleScreen(e.point),n=e.age/.9;s.globalAlpha=(1-n)*o,s.fillStyle=`#f8f4e9`,s.strokeStyle=`rgba(22, 24, 26, 0.85)`,s.lineWidth=3;let r=`+${e.amount}`,i=t.y-16-n*26;s.strokeText(r,t.x,i),s.fillText(r,t.x,i)}s.restore()}if(r?.drawForeground?.(s,l,{width:this.view.width,height:this.view.height}),performance.now(),r?.drawHealthBars?.(s,l,{width:this.view.width,height:this.view.height},e,this,i),n){let e=this.screen(n.from),t=this.screen(n.to);s.strokeStyle=`#ffdf93`,s.lineWidth=2,s.beginPath(),s.moveTo(e.x,e.y),s.lineTo(t.x,t.y),s.stroke()}s.restore(),this.objectGlint?.draw(s,this.view.width,this.view.height,this.darkSurface()),this.vehicles.drawVehicleMarkers(this.ctx,this.primaryVehicleVisible?[e,...i]:i,this.showVehicleMarkers),this.surface.presentLockedCamera(),this.liquidLayer.drawTextVehicles([e,...i].filter(t=>(t!==e||this.primaryVehicleVisible)&&t.sim.mode===`car`&&!t.isGhost&&t.sim.car.explodedAt===null).map(e=>({point:this.screen(e.sim.body.position),radius:Math.hypot(e.sim.car.preset.geometry.lengthM,e.sim.car.preset.geometry.widthM)*this.view.zoom/2+12})),c,t=>{for(let n of[e,...i]){if(n===e&&!this.primaryVehicleVisible||n.sim.mode!==`car`||n.isGhost||n.sim.car.explodedAt!==null)continue;let r=this.carVisualOffset(n.sim);t.save(),t.translate(r.x,r.y),this.vehicles.car(t,n.sim.body,n.sim,n.damage,Math.max(n.weapons.flamethrower.openAmount,n.weapons.machineGuns.openAmount)),t.restore()}}),this.governFluidQuality(t)}governFluidQuality(e){let t=performance.now()-e;if(!(t>=0&&t<1e3))return;let n=this.volumetrics.running||this.combustion.running;this.fluidGovernor.sample(e,t,n,this.quality)&&(d(`fluid quality limit ${this.fluidGovernor.limit}`),this.applyFluidQuality())}};export{Fl as n,Ve as r,Il as t};
|
|
849
|
+
}`,`Object glint`),this.texture=e.createTexture(),this.texture||(G(e,this.program),this.program=null))}trigger(e,t,n,r){let i=this.gl;if(!i||!this.program||!this.texture)return;this.canvas.width=this.mask.width=Math.ceil(e*n),this.canvas.height=this.mask.height=Math.ceil(t*n);let a=this.mask.getContext(`2d`);a&&(a.setTransform(n,0,0,n,0,0),a.clearRect(0,0,e,t),r(a),i.bindTexture(i.TEXTURE_2D,this.texture),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,this.mask),this.startedAt=performance.now())}draw(e,t,n,r){let i=this.gl,a=(performance.now()-this.startedAt)/this.duration;!i||!this.program||!this.texture||a<0||a>=1||(i.viewport(0,0,this.canvas.width,this.canvas.height),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.useProgram(this.program),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.texture),i.uniform1i(W(this.program,`mask`),0),as(this.program,{pixel:[1/this.canvas.width,1/this.canvas.height],progress:a,dark:Number(r)}),i.drawArrays(i.TRIANGLES,0,3),d(`composited megapixels`,this.canvas.width*this.canvas.height/1e6),e.drawImage(this.canvas,0,0,t,n))}dispose(){this.gl&&(this.texture&&this.gl.deleteTexture(this.texture),this.program&&G(this.gl,this.program),this.texture=null,this.program=null)}},Fl=e({Renderer:()=>Il}),Il=class{overlay;canvasWorld;vehicleImageLoadState(e){return this.vehicles.imageLoadState(e)}loadVehicleImage(e,t){return this.vehicles.loadImage(e,t)}carVisualOffset(e){return this.vehicles.carVisualOffset(e)}get cameraLock(){return this.view.cameraLock}set cameraLock(e){this.view.cameraLock=e}get cameraSmoothing(){return this.view.cameraSmoothing}set cameraSmoothing(e){this.view.cameraSmoothing=e}get deadZone(){return this.view.deadZone}set deadZone(e){this.view.deadZone=e}screen(e){return this.view.screen(e)}world(e){return this.view.world(e)}vehicleViewportPosition(e){return this.view.vehicleViewportPosition(e)}sceneScroll(){return this.view.sceneScroll()}get documentProjection(){return this.view.documentProjection}virtualOffset(){return this.view.virtualOffset()}documentPoint(e){return this.view.documentPoint(e)}worldFromDocument(e){return this.view.worldFromDocument(e)}documentScale(){return this.view.documentScale()}viewportSize(){return this.view.viewportSize()}presentationScale(){return this.view.presentationScale()}setSlowMoZoom(e){this.view.slowMoZoom=e}setCanvasWorldScale(e,t=1.5){this.view.setCanvasWorldScale(e,t)}setCameraFrame(e){this.view.setCameraFrame(e)}setCameraLock(e){this.view.setCameraLock(e)}viewportFromDocument(e){return this.view.viewportFromDocument(e)}documentFromViewport(e){return this.view.documentFromViewport(e)}bounds(){return this.view.bounds()}vehicleMarkerAt(e){if(!this.showVehicleMarkers)return null;let t=this.view.documentFromViewport(e);return this.vehicles.markerAt(this.view.screen(this.view.worldFromDocument(t)))}revealVehicle(e){this.view.revealVehicle(e)}resumeFollow(){this.view.resumeFollow()}interruptFollow(){this.view.interruptFollow()}restorePage(e){this.view.restorePage(e)&&(this.lastFlowCenter=null,this.flowVelocity=S())}followDocument(e){return this.view.followDocument(e)}primaryVehicleVisible=!0;primaryVehicleOpacity=1;beginVehicleArrivalFade(){this.skidTracks.beginReveal(this.skidView(),this.darkSurface()),this.primaryVehicleOpacity=0}setVehicleArrivalOpacity(e){this.primaryVehicleOpacity=y(e,0,1),this.skidTracks.setRevealAlpha(this.primaryVehicleOpacity,this.skidView(),this.darkSurface())}view;surface;vehicles;debris=new u;get ctx(){return this.surface.context}nextHistoryPrune=0;trailClock=0;quality=w.game.quality;fluidGovernor=new Ce;vehicleLights=new Us;surfaceTones=new Js;vehicleLighting={...te};setVehicleLighting(e){this.vehicleLighting=ee({...this.vehicleLighting,...e})}getVehicleLighting(){return{...this.vehicleLighting}}toggleVehicleLight(e){return this.setVehicleLighting({[e]:e===`underglow`?this.vehicleLighting.underglow?void 0:`#66e6ff`:!this.vehicleLighting[e]}),this.getVehicleLighting()}surfaceTone=w.game.surfaceTone;trail=[];skidTracks=new Ol;volumetrics;pointPuffs=[];objectGlint=null;showVehicleMarkers=w.game.showVehicleMarkers;tireSmokeEnabled=w.game.tireSmoke;vehicleShadowsEnabled=w.game.vehicleShadows;effectsFadeStartedAt=null;wallRects=[];combustion;sparks=new jc;liquidLayer;tireMarks=new xl;seedGroundMarks(e){this.overlay&&this.tireMarks.seed(e,this.particleScale())}focusVehicle=null;activeVehicles=[];bindVehicle(e){this.focusVehicle=e}forgetVehicle(e){this.tireMarks.forgetVehicle(e),this.activeVehicles=this.activeVehicles.filter(t=>t.id!==e),this.focusVehicle?.id===e&&(this.focusVehicle=null)}get rocketFlightPosition(){let e=this.focusVehicle?.sim.body.position??S(),t=null,n=1/0;for(let r of this.activeVehicles){let i=r.weapons.rocket.projectile?.position;if(!i)continue;let a=p(b(i,e));a<n&&(t=i,n=a)}return t}screenShake=new jl;exhaustBursts=[];queueExhaustPops(e){for(let t of e)t<.12||this.exhaustBursts.push({age:0,lifetime:.08+t*.11,intensity:.4+t*.6});this.exhaustBursts.length>6&&this.exhaustBursts.splice(0,this.exhaustBursts.length-6)}lastFlowCenter=null;flowVelocity=S();captureState(){let e=[],t=t=>(t&&e.push(()=>t.dispose()),t);try{let n=t(this.volumetrics.captureState()),r=t(this.combustion.captureState()),i=t(this.liquidLayer.captureState());return{at:performance.now(),data:l({primaryVehicleVisible:this.primaryVehicleVisible,primaryVehicleOpacity:this.primaryVehicleOpacity,nextHistoryPrune:this.nextHistoryPrune,trailClock:this.trailClock,quality:this.quality,fluidQualityLimit:this.fluidGovernor.limit,vehicleLighting:this.vehicleLighting,surfaceTone:this.surfaceTone,trail:this.trail,pointPuffs:this.pointPuffs,showVehicleMarkers:this.showVehicleMarkers,tireSmokeEnabled:this.tireSmokeEnabled,vehicleShadowsEnabled:this.vehicleShadowsEnabled,effectsFadeStartedAt:this.effectsFadeStartedAt,wallRects:this.wallRects,exhaustBursts:this.exhaustBursts,lastFlowCenter:this.lastFlowCenter,flowVelocity:this.flowVelocity,debugDrive:this.debugDrive,previewGroundFire:this.previewGroundFire,previewWallSmoke:this.previewWallSmoke,previewSparks:this.previewSparks,previewDamage:this.previewDamage,previewOil:this.previewOil,previewOilSplatter:this.previewOilSplatter,oilSplatterPreviewSeconds:this.oilSplatterPreviewSeconds,sparkPreviewClock:this.sparkPreviewClock,damagePreviewApplied:this.damagePreviewApplied,groundFirePreviewLit:this.groundFirePreviewLit,trailLifetime:this.trailLifetime,fallbackSurfaceTone:this.fallbackSurfaceTone}),camera:this.view.captureState(),diagnostics:this.diagnostics.captureState(),vehicles:this.vehicles.captureState(),volumetrics:n,combustion:r,liquids:i,debris:this.debris.captureState(),skidTracks:this.skidTracks.captureState(),tireMarks:this.tireMarks.captureState(),sparks:this.sparks.captureState(),screenShake:this.screenShake.captureState(),dispose:()=>e.forEach(e=>e())}}catch(t){throw e.forEach(e=>e()),t}}restoreState(e){let t=this.captureState();try{this.applyState(e)}catch(e){try{this.applyState(t)}catch(t){throw AggregateError([e,t],`Renderer checkpoint rollback failed`,{cause:t})}throw e}finally{t.dispose()}}applyState(e){this.clearEffects();let t=l(e.data);this.primaryVehicleVisible=t.primaryVehicleVisible,this.primaryVehicleOpacity=t.primaryVehicleOpacity,this.nextHistoryPrune=t.nextHistoryPrune,this.trailClock=t.trailClock,this.quality=t.quality,this.fluidGovernor.restoreLimit(t.fluidQualityLimit),this.vehicleLighting=t.vehicleLighting,this.surfaceTone=t.surfaceTone,this.trail=t.trail,this.pointPuffs=t.pointPuffs,this.showVehicleMarkers=t.showVehicleMarkers,this.tireSmokeEnabled=t.tireSmokeEnabled,this.vehicleShadowsEnabled=t.vehicleShadowsEnabled,this.effectsFadeStartedAt=t.effectsFadeStartedAt,this.wallRects=t.wallRects,this.exhaustBursts=t.exhaustBursts,this.lastFlowCenter=t.lastFlowCenter,this.flowVelocity=t.flowVelocity,this.debugDrive=t.debugDrive,this.previewGroundFire=t.previewGroundFire,this.previewWallSmoke=t.previewWallSmoke,this.previewSparks=t.previewSparks,this.previewDamage=t.previewDamage,this.previewOil=t.previewOil,this.previewOilSplatter=t.previewOilSplatter,this.oilSplatterPreviewSeconds=t.oilSplatterPreviewSeconds,this.sparkPreviewClock=t.sparkPreviewClock,this.damagePreviewApplied=t.damagePreviewApplied,this.groundFirePreviewLit=t.groundFirePreviewLit,this.trailLifetime=t.trailLifetime,this.fallbackSurfaceTone=t.fallbackSurfaceTone,this.view.restoreState(e.camera),this.diagnostics.restoreState(e.diagnostics),this.vehicles.restoreState(e.vehicles),this.volumetrics.setQuality(this.fluidGovernor.apply(this.quality)),this.volumetrics.restoreState(e.volumetrics),this.combustion.setQuality(this.fluidGovernor.apply(this.quality)),this.combustion.restoreState(e.combustion),this.liquidLayer.restoreState(e.liquids),e.debris&&this.debris.restoreState(e.debris),this.skidTracks.restoreState(e.skidTracks,this.skidView(),this.darkSurface()),this.tireMarks.restoreState(e.tireMarks),this.sparks.restoreState(e.sparks),this.screenShake.restoreState(e.screenShake),this.effectsFadeStartedAt!==null&&(this.effectsFadeStartedAt+=performance.now()-e.at),this.view.rebaseTime(performance.now()),this.view.restorePresentation()}get flamethrowerFiring(){return this.activeVehicles.some(e=>e.weapons.flamethrower.firing)}get managedMemoryGroups(){return[{label:`Tire marks`,bytes:this.skidTracks.managedBytes+this.activeVehicles.reduce((e,t)=>e+t.tirePaint.managedBytes,0)+this.tireMarks.managedBytes},{label:`Smoke`,bytes:this.volumetrics.smokeBytes},{label:`Ghost`,bytes:this.volumetrics.ghostBytes},{label:`Fire`,bytes:this.combustion.managedBytes},{label:`Liquids`,bytes:this.liquidLayer.managedBytes},{label:`Debris`,bytes:this.debris.managedBytes+Ie().bytes},{label:`Tools`,bytes:this.activeVehicles.reduce((e,t)=>e+t.weapons.managedBytes,0)},{label:`Sparks`,bytes:this.sparks.count*112},{label:`Points`,bytes:this.pointPuffs.length*32},{label:`Vehicle trail`,bytes:this.trail.length*48}]}get managedBytes(){return this.managedMemoryGroups.reduce((e,t)=>e+t.bytes,0)}debugDrive=!1;previewGroundFire=!1;previewWallSmoke=!1;previewSparks=!1;previewDamage=!1;previewOil=!1;previewOilSplatter=!1;oilSplatterPreviewSeconds=0;sparkPreviewClock=0;damagePreviewApplied=!1;groundFirePreviewLit=!1;diagnostics=new js;trailLifetime=12;constructor(e,t=!1,n=w.game.quality,r=!1){this.overlay=t,this.canvasWorld=r,this.view=new ks(t,r,()=>this.resize()),this.surface=new As(e,this.view,t,r),this.combustion=new pc(this.view,n),this.volumetrics=new vc(this.view,n),this.liquidLayer=new gl(this.view,n),this.vehicles=new hs(this.view),this.quality=n,this.resize()}get pixelSpace(){return this.overlay||this.canvasWorld}prepareFire(){return this.sparks.prepare()?this.combustion.ensure():!1}setQuality(e){if(e===this.quality)return;this.quality=e;let t=this.fluidGovernor.apply(e);this.volumetrics.setQuality(t),this.liquidLayer.setQuality(e),this.combustion.setQuality(t)}applyFluidQuality(){let e=this.fluidGovernor.apply(this.quality);this.volumetrics.setQuality(e),this.combustion.setQuality(e)}setTireSmokeEnabled(e){this.tireSmokeEnabled=e}setVehicleShadowsEnabled(e){this.vehicleShadowsEnabled=e}setAbsoluteViewport(){this.surface.setAbsoluteViewport()}setSparksEnabled(e){this.sparks.setEnabled(e)}setScreenShakeEnabled(e){this.screenShake.setEnabled(e)}setScreenShakeProfiles(e){this.screenShake.setProfiles(e)}emitCrashShake(e){if(this.effectsFadeStartedAt!==null)return;let t=Al(e);t&&this.screenShake.trigger(t)}emitRocketExplosionShake(e=1){this.effectsFadeStartedAt===null&&this.screenShake.trigger(`rocketExplosion`,Math.sqrt(Math.max(0,e)))}emitCombustibleExplosion(e,t){if(this.effectsFadeStartedAt!==null)return;this.screenShake.trigger(`combustibleExplosion`);let n=this.particlePoint(this.worldFromDocument(e));this.sparks.emitExplosion(n,S(),this.particleScale(),1.2),this.combustion.queueBlast(n,t*this.particleScale()/Math.max(1,this.documentScale())),this.emitCombustibleBlast(e,t,0)}emitCombustibleBlast(e,t,n){if(this.effectsFadeStartedAt!==null||!this.combustion.activateBuoyancy())return;let r=this.particlePoint(this.worldFromDocument(e)),i=t*this.particleScale()/Math.max(1,this.documentScale()),a=Math.min(1,n/.34);for(let e=0;e<24;e++){let t=e*Math.PI*(3-Math.sqrt(5)),n=S(Math.cos(t),Math.sin(t));this.combustion.queueStamp({point:x(r,_(n,i*a*1.05)),radius:Math.max(4,i*(.29-a*.12)),flow:x(_(n,i*(2.6-a)),S(0,-i*.4)),progress:.28+a*.53,blast:!0})}}emitRocketExplosion(e,t,n=1){if(this.effectsFadeStartedAt!==null)return;let r=this.particlePoint(this.worldFromDocument(e)),i=this.particleVelocity(S(t.x/this.view.zoom,-t.y/this.view.zoom)),a=this.particleScale(),o=Math.sqrt(y(n,.5,2));this.combustion.ensure()&&(this.combustion.queueBlast(r,a*2.2*o),this.combustion.queueStamp({point:r,radius:a*.95*o,flow:S(0,-a*.7),progress:.24,strength:2.6,blast:!0}));for(let t=0;t<64;t++){let n=t*Math.PI*(3-Math.sqrt(5))+Math.atan2(i.y,i.x),s=a*Math.sqrt((t+.5)/64)*1.75*(.83+.17*Math.sin(t*11.8+e.x*.03))*o,c=S(Math.cos(n),Math.sin(n));this.combustion.available&&this.combustion.queueStamp({point:x(r,_(c,s)),radius:a*(.38+t%4*.065)*o,flow:x(_(c,a*2.5),S(0,-a*.5)),progress:.3+t%5*.06,strength:1.7+t%3*.28,blast:!0})}this.sparks.emitExplosion(r,i,a,n),this.sparks.emitFireAt(r,a*.5,.25,14)}setDeformEnabled(e){this.focusVehicle?.damage.setEnabled(e),e||(this.damagePreviewApplied=!1)}resetVehicleDamage(){this.focusVehicle?.damage.reset()}emitSparks(e){this.effectsFadeStartedAt===null&&this.sparks.emit(e)}emitVehicleBurn(e,t,n,r){let i=e.sim,a=this.documentScale(),o=x(this.documentPoint(i.body.position),this.carVisualOffset(i)),s=n.lengthM*a,c=n.widthM*a,l=S(Math.cos(i.body.angle),-Math.sin(i.body.angle)),u=S(-l.y,l.x),d=x(o,x(_(l,t.burnOriginLocal.x*a),_(u,t.burnOriginLocal.y*a))),p=this.combustion.alphaFor(n.alpha.solid);if(t.stage===`exploded`)return t.explosionStarted&&this.emitCombustibleExplosion(o,Math.max(78,s*.7)),t.blastAge<v.fireballSeconds&&this.emitSceneFire({key:t.key,alpha:p,pixelWidth:n.alpha.columns,pixelHeight:n.alpha.rows,x:o.x-s/2,y:o.y-c/2,width:s,height:c,angle:-i.body.angle,origin:o,farthest:Math.hypot(s,c),...f(t.blastAge)},r),t.blastPulse&&this.emitCombustibleBlast(o,Math.max(78,s*.7),t.blastAge),t.explosionStarted?o:null;let m=h(t.health,t.maxHealth,s,c);return m&&this.emitSceneFire({key:t.key,alpha:p,pixelWidth:n.alpha.columns,pixelHeight:n.alpha.rows,x:o.x-s/2,y:o.y-c/2,width:s,height:c,angle:-i.body.angle,origin:d,farthest:Math.hypot(s,c),...m},r),null}sceneFireDue(e){return this.effectsFadeStartedAt===null&&this.combustion.sceneMasksDue(e)}emitSceneFire(e,t=1/60){this.effectsFadeStartedAt===null&&this.combustion.queueMask(e)}pourWorldLiquid(e,t,n,r,i){this.liquidLayer.pourWorldLiquid(e,t,n,r,i)}emitPaint(e,t,n,r,i){this.liquidLayer.emitPaint(e,t,n,r,i)}igniteLiquidAt(e,t){this.liquidLayer.igniteAt(e,t)}igniteLiquidsFromFire(e){this.liquidLayer.igniteFromFire(e)}burningLiquidSources(){return this.liquidLayer.burningSources()}hasLiquidContact(e,t){return this.liquidLayer.hasContact(e,t)}addLiquid(e,t){this.liquidLayer.add(e,t)}syncElementLiquids(e){return this.liquidLayer.syncElements(e)}ejectLiquid(e,t=`oil`,n){this.liquidLayer.pourVehicle(e,t,.65,n)}setInitialPuddles(e){this.liquidLayer.setInitialPuddles(e)}setSurfaceTone(e){this.surfaceTone=e}fallbackSurfaceTone={at:-1/0,dark:!1};darkSurface(){if(this.surfaceTone!==`auto`)return this.surfaceTone===`dark`;let e=document.documentElement.dataset.jrTheme;if(e===`light`||e===`dark`)return e===`dark`;let t=performance.now();if(t-this.fallbackSurfaceTone.at<80)return this.fallbackSurfaceTone.dark;let n=getComputedStyle(document.body).backgroundColor,r=Gs(/rgba\([^)]*,\s*0(?:\.0+)?\s*\)/.test(n)||n===`transparent`?getComputedStyle(document.documentElement).backgroundColor:n);return this.fallbackSurfaceTone={at:t,dark:r},r}setDebugEnabled(e){this.debugDrive=e||!1}fadeEffects(){if(this.effectsFadeStartedAt!==null)return;this.effectsFadeStartedAt=performance.now(),this.liquidLayer.clearEffects(),this.liquidLayer.restoreInitialPuddles(),this.volumetrics.clearSmokeSources();let e=this.activeVehicles.length?this.activeVehicles:this.focusVehicle?[this.focusVehicle]:[];for(let t of e)t.weapons.reset(),t.tirePaint.reset(),t.pickupEffect.reset(),t.damage.reset();this.screenShake.reset(),this.skidTracks.fade(),this.combustion.clearTireHistory(),this.exhaustBursts=[]}clearEffects(e=!0){this.debris.reset(),this.objectGlint?.dispose(),this.objectGlint=null,this.trail=[],this.skidTracks.clear(),this.volumetrics.reset(),this.pointPuffs=[];for(let e of this.activeVehicles.length?this.activeVehicles:this.focusVehicle?[this.focusVehicle]:[])e.pickupEffect.reset(),e.weapons.rocket.reset(),e.weapons.machineGuns.reset(),e.weapons.flamethrower.reset();this.screenShake.reset(),this.combustion.reset(),this.exhaustBursts=[],this.sparks.reset(),e&&this.liquidLayer.clearEffects(),this.tireMarks.clear(),this.lastFlowCenter=null,this.flowVelocity=S(),this.trailClock=0,this.effectsFadeStartedAt=null}reset(){this.view.reset(),this.clearEffects(),this.liquidLayer.restoreInitialPuddles(),this.wallRects=[],this.groundFirePreviewLit=!1,this.sparkPreviewClock=0,this.damagePreviewApplied=!1,this.vehicles.reset(),this.surface.clear(),this.view.resetFollow()}dispose(){this.liquidLayer.dispose(),this.debris.clear(),this.vehicles.dispose(),this.objectGlint?.dispose(),this.surface.dispose(),this.view.dispose(),this.skidTracks.clear(),this.tireMarks.clear(),this.volumetrics.dispose(),this.combustion.dispose(),this.sparks.dispose()}resize(){let e=this.surface.resize();this.liquidLayer.resize(),this.volumetrics.resize(e),this.combustion.resize(e)}rasterPixelRatio(){return this.canvasWorld?Math.min(2,Math.round(this.view.dpr/this.view.regionScale*100)/100):this.view.dpr}setShowVehicleMarkers(e){this.showVehicleMarkers=e}flashTargets(e){this.resize(),this.objectGlint??=new Pl;let t=this.sceneScroll();this.objectGlint.trigger(this.view.width,this.view.height,this.view.dpr,n=>e(n,t))}particlePoint(e){return this.view.particlePoint(e)}particleScreen(e){return this.pixelSpace?b(e,this.sceneScroll()):this.screen(e)}particleVelocity(e){return this.pixelSpace?S(e.x*this.view.zoom,-e.y*this.view.zoom):{...e}}particleScale(){return this.view.particleScale()}emitPoints(e,t){t<=0||this.pointPuffs.push({point:this.particlePoint(this.worldFromDocument(e)),amount:t,age:0})}fluidView(){let e=this.sceneScroll();return this.pixelSpace?{origin:S(this.view.smokeMargin-e.x,this.view.smokeMargin-e.y),scaleX:1,scaleY:1}:{origin:S(this.view.width/2-this.view.camera.x*this.view.zoom,this.view.height/2+this.view.camera.y*this.view.zoom),scaleX:this.view.zoom,scaleY:-this.view.zoom}}flameView(){let e=this.fluidView();return this.pixelSpace?{...e,origin:S(e.origin.x-this.view.smokeMargin,e.origin.y-this.view.smokeMargin)}:e}clipFluidWalls(e){if(!this.overlay)return;let t=this.sceneScroll();for(let n of this.wallRects){let r=n.x-t.x,i=n.y-t.y;n.width<=0||n.height<=0||r>=this.view.width||i>=this.view.height||r+n.width<=0||i+n.height<=0||(e.beginPath(),e.rect(0,0,this.view.width,this.view.height),e.rect(r,i,n.width,n.height),e.clip(`evenodd`))}}stepVehicleWeapons(e,t,n,r,i,a,o,s,c){let l=e.sim;performance.now(),e.weapons.rocket.step(t,l,e=>{this.effectsFadeStartedAt===null&&this.volumetrics.emitSmoke({point:this.particlePoint(e.point),amount:e.amount,flow:this.particleVelocity(e.flow),radiusPx:e.radiusM*this.view.zoom,swirlPx:10})},n?(t,r,i)=>{let a=n(e,this.documentPoint(t),this.documentPoint(r),i*this.documentScale());return a?this.worldFromDocument(a):null}:void 0,e=>{this.effectsFadeStartedAt===null&&this.combustion.emitJet(e.from,e.to,e.flow,e.widthM,e.intensity,`rocket`)},o,s,void 0),e.weapons.machineGuns.step(t,l,r?(t,n,i)=>{let a=r(e,this.documentPoint(t),this.documentPoint(n),i*this.documentScale());return a?this.worldFromDocument(a):null}:void 0,i,(e,t)=>{this.effectsFadeStartedAt===null&&this.sparks.emitBulletImpact(this.particlePoint(e),this.particleVelocity(t)),c?.(e)}),e.weapons.flamethrower.step(t,l,e=>{this.effectsFadeStartedAt===null&&this.volumetrics.emitSmoke({point:this.particlePoint(e.point),amount:e.amount,flow:this.particleVelocity(e.flow),radiusPx:e.radiusM*this.view.zoom,swirlPx:10})},a?(t,n,r,i)=>{let o=a(e,this.documentPoint(t),this.documentPoint(n),r*this.documentScale(),i);return o?this.worldFromDocument(o):null}:void 0,(e,n,r,i,a)=>{if(this.effectsFadeStartedAt!==null)return;let o=this.particleScale();this.liquidLayer.igniteAlong(this.particlePoint(e),this.particlePoint(n),r*o*.5),a>.3&&this.sparks.emitFireAt(this.particlePoint(n),r*o*.4,t,3),this.combustion.queueStamp({point:this.particlePoint(n),radius:r*o,progress:a,flow:this.particleVelocity(i)})})}sprayTirePaint(e,t,n,r,i,a,o,s){return this.liquidLayer.splatter(e,t,n,r,i,a,o,s)}advanceEffects(e,t,{walls:r=[],carMask:i,tirePaintSources:a=[],driven:o=!0,rocketCollision:s,bulletCollision:c,onGunshot:l,flameContact:u,onRocketLaunch:d,onRocketImpact:f,onBulletImpact:h,maskFor:g,companions:v=[]}={}){for(let e of this.pointPuffs)e.age+=t;this.pointPuffs=this.pointPuffs.filter(e=>e.age<.9),this.activeVehicles=[e,...v];let y=this.sceneScroll();this.debris.count&&this.debris.step(t,this.activeVehicles.filter(e=>e.sim.mode===`car`&&!e.isGhost&&e.sim.car.explodedAt===null).map(e=>{let t=this.particlePoint(e.sim.body.position),n=this.particleVelocity(e.sim.body.velocity),r=this.particleScale();return{x:t.x,y:t.y,vx:n.x,vy:n.y,angle:-e.sim.body.angle,length:e.sim.car.preset.geometry.lengthM*r,width:e.sim.car.preset.geometry.widthM*r}}),{x:y.x,y:y.y,width:this.view.width,height:this.view.height},r),this.volumetrics.stepGhost(t,this.activeVehicles,r,g,this.flameView(),e=>this.carVisualOffset(e.sim),e=>{let t=this.vehicles.imageFor(e.sim.car.preset);if(!t)return;let n=D(e.sim.car.preset,t.naturalWidth,t.naturalHeight),r=e.damage.spriteFor(t,n);return{image:r??t,source:r?{x:0,y:0,width:r.width,height:r.height}:n.source}});let C=e.sim;if(this.wallRects=r,this.vehicles.updateCarPose(C,t),this.effectsFadeStartedAt===null){for(let e of this.activeVehicles)for(let r of e.liquidEmissions(t))this.liquidLayer.pourVehicle(e.sim,n(r.liquid),r.amount,void 0,e.id);this.previewOil&&!this.previewOilSplatter&&this.liquidLayer.pourVehicle(C,`oil`,t*6)}for(let n of[e,...v])this.stepVehicleWeapons(n,t,s,c,l,u,d,f,h);let{tires:w,companionTires:ee}=this.liquidLayer.stepVehicles(e,v,t,o,a,this.effectsFadeStartedAt!==null,(e,t)=>this.emitSceneFire(e,t)),te=this.documentScale(),T=S(Math.cos(C.body.angle),-Math.sin(C.body.angle)),E=C.mode===`car`&&i&&!e.isGhost?{mask:i.alpha,shape:{center:x(this.documentPoint(C.body.position),this.carVisualOffset(C)),forward:T,side:S(-T.y,T.x),halfLength:i.lengthM*te/2,halfWidth:i.widthM*te/2}}:void 0;this.previewDamage&&!this.damagePreviewApplied&&E&&(this.damagePreviewApplied=e.damage.hit(x(E.shape.center,_(E.shape.forward,E.shape.halfLength)),_(E.shape.forward,-1),E.shape,20,te));for(let e of this.activeVehicles){if(e.sim.mode!==`car`||this.effectsFadeStartedAt!==null)continue;let n=g?.(e)??e.sim.car.preset.geometry;for(let r of e.pickupEffect.active){let i=S(Math.cos(r.angle),Math.sin(r.angle)),a=this.particleVelocity(m(i,e.sim.body.angle));for(let i of vs(r,n,t)){let t=e.sim.body.world(i);this.sparks.pickup(this.particlePoint(t),_(a,r.velocity),a,r.color,this.particleScale(),Math.max(.2,r.strength),1)}}}if(performance.now(),C.mode===`car`&&p(C.body.velocity)>.15&&this.sparks.disturb(this.particlePoint(C.body.position),this.particleVelocity(C.body.velocity),this.particleScale()*2.8),this.sparks.step(t,{walls:r,car:E}),this.previewSparks&&C.mode===`car`&&(this.sparkPreviewClock+=t,this.sparkPreviewClock>.12)){this.sparkPreviewClock=0;let e=this.particlePoint(C.body.position),t=this.particleScale();this.emitSparks({point:x(e,S(t*1.9,0)),velocity:S(t*4,t*10),normal:S(-1,0),pixelsPerMeter:t})}let ne=this.particleScale(),re=this.particlePoint(C.body.position),ie=this.lastFlowCenter?_(b(re,this.lastFlowCenter),1/Math.max(t,1e-4)):this.particleVelocity(C.body.velocity),ae=p(ie),oe=ae>40*ne?_(ie,40*ne/ae):ie;this.flowVelocity=x(this.flowVelocity,_(b(oe,this.flowVelocity),1-Math.exp(-12*t))),this.lastFlowCenter=re;let se=this.pixelSpace?this.flowVelocity:S(this.flowVelocity.x*this.view.zoom,-this.flowVelocity.y*this.view.zoom),ce=S(Math.cos(C.body.angle),-Math.sin(C.body.angle)),O=C.mode===`car`?{center:x(this.screen(C.body.position),S(this.view.smokeMargin,this.view.smokeMargin)),velocity:se,forward:ce,halfLength:C.car.preset.geometry.lengthM*this.view.zoom*.46,halfWidth:C.car.preset.geometry.widthM*this.view.zoom*.39,spin:-C.body.spin}:null;if(this.effectsFadeStartedAt!==null){this.volumetrics.clearSmokeSources(),this.combustion.stepTire(t),this.combustion.step(t,this.view.timeSeconds,e.isGhost?null:O,this.wallRects,!0,this.flameView(),this.sparks),this.volumetrics.stepSmoke(t,O,this.wallRects,this.fluidView());return}if(this.previewWallSmoke&&this.overlay){let e=this.sceneScroll(),n=this.wallRects.filter(t=>t.x-e.x>48&&t.x-e.x<this.view.width-48&&t.y+t.height/2-e.y>30&&t.y+t.height/2-e.y<this.view.height-30),r=n.find(t=>t.x-e.x>this.view.width*.5)??n[0];r&&this.volumetrics.emitSmoke({point:S(r.x-25,r.y+r.height/2),amount:t*15,flow:S(210,0),radiusPx:17,swirlPx:25})}if(performance.now(),this.combustion.stepTire(t),this.combustion.step(t,this.view.timeSeconds,e.isGhost?null:O,this.wallRects,!1,this.flameView(),this.sparks),!this.pixelSpace){for(let e of this.trail)e.age+=t;if(this.trail=this.trail.filter(e=>e.age<this.trailLifetime),this.trailClock+=t,this.trailLifetime>0&&this.trailClock>=1/30){this.trailClock%=1/30;let e=this.trail.at(-1);(!e||p(b(e.point,C.body.position))>.04)&&this.trail.push({point:{...C.body.position},age:0,color:C.mode===`ship`?`#9bbcff`:C.mode===`brick`?`#f6bd79`:`#8ce6c5`}),this.trail.length>800&&this.trail.shift()}}if(C.mode!==`car`){this.volumetrics.stepSmoke(t,null,this.wallRects,this.fluidView()),this.skidTracks.stop(this.skidView(),this.darkSurface(),!0),this.combustion.clearTireHistory();return}if(e.isGhost){this.volumetrics.stepSmoke(t,null,this.wallRects,this.fluidView()),this.skidTracks.stop(this.skidView(),this.darkSurface()),this.combustion.clearTireHistory();return}let le=this.advanceVehicleTireEffects(e,t,w,ee,se),ue=this.combustion.emberSource();ue&&this.sparks.emitFireAt(ue.point,ue.radius,t,20*ue.heat),performance.now(),this.volumetrics.stepSmoke(t,O,this.wallRects,this.fluidView());let de=this.darkSurface();this.skidTracks.step(t,C,le,t=>!!e.tirePaint.coating(t),{pixelSpace:this.pixelSpace,scale:this.particleScale(),dark:de,project:e=>this.particlePoint(e),roadAt:(e,t)=>!!this.overlay&&this.surfaceTones.at(e,this.viewportFromDocument(t),de),view:this.skidView()})}advanceVehicleTireEffects(e,t,n,r,i){let a=e.sim,o=this.particleScale();if(this.previewGroundFire&&!this.groundFirePreviewLit){for(let e of a.car.tires.filter(e=>!e.front)){let t=a.body.world(e.local);this.combustion.igniteTire(this.particlePoint(a.body.world(x(e.local,S(-2.4)))),this.particlePoint(t),a.car.preset.geometry.tireWidthM*o,18,.2*o)}this.groundFirePreviewLit=!0}let s=p(a.body.velocity),c=s>.1?_(a.body.velocity,-1/s):m(S(-1),a.body.angle);this.previewOilSplatter&&(s>.5?this.oilSplatterPreviewSeconds=0:s<.2&&(this.oilSplatterPreviewSeconds+=t),this.oilSplatterPreviewSeconds<2.25&&this.liquidLayer.pourOilPreview(n[0].point,t));let l={zoom:this.view.zoom,particlePoint:e=>this.particlePoint(e),particleVelocity:e=>this.particleVelocity(e),spray:(...e)=>this.sprayTirePaint(...e),smoke:this.tireSmokeEnabled?e=>this.volumetrics.emitSmoke(e):void 0};Nl(e,n,0,t,c,i,l,this.previewOilSplatter&&s<.2&&this.oilSplatterPreviewSeconds>1&&this.oilSplatterPreviewSeconds<2.25);let u=n.length;for(let{vehicle:e,tires:n}of r){if(!e.isGhost){let r=e.sim,i=p(r.body.velocity),a=i>.1?_(r.body.velocity,-1/i):m(S(-1),r.body.angle);Nl(e,n,u,t,a,this.particleVelocity(r.body.velocity),l)}u+=n.length}e.isGhost&&(this.exhaustBursts=[]);for(let e of this.exhaustBursts){e.age+=t;let n=e.intensity*Math.max(0,1-e.age/e.lifetime);if(n<=0)continue;let r=m(S(-1,0),a.body.angle),i=x(_(r,4+5*n),_(a.body.velocity,.12));for(let e of this.vehicles.exhaustOutlets(a)){let o=a.body.world(e);if(this.combustion.emitJet(o,o,i,.13,n*.8,`exhaust`),n>.55){let e=x(o,_(r,1.45));this.volumetrics.emitSmoke({point:this.particlePoint(e),amount:t*n*.2,flow:this.particleVelocity(_(i,.48)),radiusPx:.13*this.particleScale(),swirlPx:7})}}}this.exhaustBursts=this.exhaustBursts.filter(e=>e.age<e.lifetime);let d=a.car.boostActive&&!e.isGhost;return d?this.combustion.stepBoostFire(a,t,e=>this.liquidLayer.igniteAtLocal(e)):this.combustion.clearTireHistory(),d}skidView(){return{pixelSpace:this.pixelSpace,zoom:this.view.zoom,width:this.view.width,height:this.view.height,screen:e=>this.particleScreen(e)}}vehicleLightInput(e,t,n){let r=T(e.sim.car.preset),i=e=>[-1,1].map(t=>S(e.xM*this.view.zoom,t*e.yM*this.view.zoom)),a=e.sim,o=this.vehicles.imageFor(a.car.preset)??void 0,s=o?D(a.car.preset,o.naturalWidth,o.naturalHeight):null,c=a.body.velocity.x*Math.cos(a.body.angle)+a.body.velocity.y*Math.sin(a.body.angle),l=a.lastInput,u=this.sceneScroll(),d=Math.max(l.brake??0,+!!l.action,+(l.throttle<0&&c>.5||l.throttle>0&&c<-.5));return{center:x(this.screen(a.body.position),this.carVisualOffset(a)),angle:-a.body.angle,width:(s?.lengthM??a.car.preset.geometry.lengthM)*this.view.zoom,height:(s?.widthM??a.car.preset.geometry.widthM)*this.view.zoom,mounts:{headlights:i(r.headlights),taillights:i(r.taillights)},image:o,source:s?.source,dark:e.appearance===`auto`?this.overlay?this.surfaceTones.at(e,this.viewportFromDocument(this.documentPoint(a.body.position)),t):t:e.appearance===`dark`,braking:d,options:this.vehicleLighting,opacity:n,walls:this.pixelSpace?this.wallRects.map(e=>({...e,x:e.x-u.x,y:e.y-u.y})):[]}}drawVehicleAndWeapons(e,t,n){performance.now(),d(`vehicle render passes`);let r=e.sim,{rocket:i,machineGuns:a,flamethrower:o}=e.weapons,s=this.ctx;if(e.isGhost){i.drawFlight(s,e=>this.screen(e),r.car.preset,this.view.zoom,t),a.drawProjectiles(s,e=>this.screen(e),this.view.zoom,t);return}let c=this.carVisualOffset(r);if(s.save(),s.translate(c.x,c.y),r.car.explodedAt===null){this.vehicles.car(this.ctx,r.body,r,e.damage,Math.max(o.openAmount,a.openAmount),e);let i=n??this.vehicleLightInput(e,this.darkSurface(),t);this.vehicleLights.glints(s,{...i,center:this.screen(r.body.position)})}let l;if(i.state!==`idle`||o.state!==`closed`||a.state!==`closed`){let t=this.vehicles.imageFor(r.car.preset);if(t){let n=D(r.car.preset,t.naturalWidth,t.naturalHeight),i=e.damage.spriteFor(t,n);l={image:i??t,source:i?{x:0,y:0,width:i.width,height:i.height}:n.source,lengthM:n.lengthM,widthM:n.widthM}}}r.car.explodedAt===null&&i.drawMount(s,this.screen(r.body.position),r.body.angle,r.car.preset,this.view.zoom,t,l),r.car.explodedAt===null&&o.state!==`closed`?o.drawMount(s,this.screen(r.body.position),r.body.angle,r.car.preset,this.view.zoom,t,l):r.car.explodedAt===null&&a.drawMount(s,this.screen(r.body.position),r.body.angle,r.car.preset,this.view.zoom,t,l),s.restore(),s.save(),this.clipFluidWalls(s),s.translate(c.x,c.y),r.car.explodedAt===null&&this.vehicles.exhaust(this.ctx,r),s.restore(),i.drawFlight(s,e=>this.screen(e),r.car.preset,this.view.zoom,t),a.drawProjectiles(s,e=>this.screen(e),this.view.zoom,t)}drawGroundLayers(e,t,n,r){let i=t.sim;if(!this.pixelSpace){let{left:e,right:t,bottom:n,top:r}=this.bounds();for(let i=Math.floor(e/5)*5;i<=t;i+=5)this.vehicles.line(this.ctx,S(i,n),S(i,r),`#293c46`);for(let i=Math.floor(n/5)*5;i<=r;i+=5)this.vehicles.line(this.ctx,S(e,i),S(t,i),`#293c46`)}for(let t of this.trail){let n=this.screen(t.point),i=1-t.age/this.trailLifetime;e.globalAlpha=.6*i*i*r,e.fillStyle=t.color,e.beginPath(),e.arc(n.x,n.y,.8+1.4*i,0,Math.PI*2),e.fill()}e.globalAlpha=1,e.save(),e.lineCap=`round`,e.lineJoin=`round`;let a=this.sceneScroll(),o=this.pixelSpace?{left:a.x,right:a.x+this.view.width,bottom:a.y,top:a.y+this.view.height}:{left:this.world(S(0,0)).x,right:this.world(S(this.view.width,0)).x,bottom:this.world(S(0,this.view.height)).y,top:this.world(S(0,0)).y},s=this.darkSurface();performance.now(),this.skidTracks.draw(e,{pixelSpace:this.pixelSpace,scroll:a,width:this.view.width,height:this.view.height,ratio:this.rasterPixelRatio(),dark:s,alpha:r,visible:o,view:this.skidView()}),performance.now();let c={pixelSpace:this.pixelSpace,scroll:a,width:this.view.width,height:this.view.height,particleScale:this.particleScale(),rasterRatio:this.rasterPixelRatio(),zoom:this.view.zoom,effectsAlpha:r,screen:e=>this.particleScreen(e)};return this.tireMarks.draw(e,[t,...n],!1,c),e.restore(),this.liquidLayer.draw(e,1),performance.now(),this.tireMarks.draw(e,[t,...n],!0,c),i.barrier&&!this.overlay&&(e.strokeStyle=`#d4ab71`,e.lineWidth=2,e.strokeRect(3,3,this.view.width-6,this.view.height-6)),{scroll:a,darkSurface:s}}render(e,t,n,r,i=[]){let a=e.sim,o=this.primaryVehicleVisible&&(a.mode!==`car`||this.vehicleImageLoadState(a.car.preset)===`ready`);i=i.filter(e=>e.sim.mode!==`car`||this.vehicleImageLoadState(e.sim.car.preset)===`ready`),performance.now(),this.resize();let s=fe(this.effectsFadeStartedAt,t);if(this.effectsFadeStartedAt!==null&&s===0&&(this.clearEffects(!1),s=0),this.view.cameraStep(a,t),this.canvasWorld&&t>=this.nextHistoryPrune){this.nextHistoryPrune=t+2e3;let e=this.documentPoint(a.body.position),n=2800,r={x:e.x-n,y:e.y-n,width:n*2,height:n*2};this.skidTracks.pruneOutside(r),this.tireMarks.pruneOutside(r),this.liquidLayer.pruneOutside(r)}let c=this.ctx;this.surface.clear();let l=this.screenShake.sample(t);c.save(),(l.x||l.y)&&c.translate(l.x,l.y),r?.drawGround?.(c,this.sceneScroll(),{width:this.view.width,height:this.view.height});let{scroll:u,darkSurface:d}=this.drawGroundLayers(c,e,i,s),f=new Map((o?[e,...i]:i).filter(e=>e.sim.mode===`car`&&e.sim.car.explodedAt===null&&!e.isGhost).map(t=>[t,this.vehicleLightInput(t,d,s*(t===e?this.primaryVehicleOpacity:1))])),p=[...f.values()].flatMap(e=>this.vehicleLights.smokeLights(e));this.pixelSpace&&(c.save(),c.translate(-u.x,-u.y),Be(c,this.debris.particles,{x:u.x,y:u.y,width:this.view.width,height:this.view.height},d,`ground`),c.restore());for(let t of o?[e,...i]:i)t.sim.mode!==`car`||t.sim.car.explodedAt!==null||t.isGhost||t===e&&this.primaryVehicleOpacity<=0||(c.save(),t===e&&(c.globalAlpha*=this.primaryVehicleOpacity),this.vehicles.carGround(this.ctx,t.sim,t.damage,this.rasterPixelRatio(),this.vehicleShadowsEnabled),c.restore());for(let e of f.values())this.vehicleLights.ground(c,e);c.save(),performance.now(),this.clipFluidWalls(c),c.globalAlpha=s,c.save(),c.translate(-this.view.smokeMargin,-this.view.smokeMargin),this.volumetrics.drawSmoke(c,this.fluidView(),p.map(e=>({...e,point:x(e.point,S(this.view.smokeMargin,this.view.smokeMargin))})),d),c.restore(),c.restore(),c.globalAlpha=1,r?.draw(c,u,{width:this.view.width,height:this.view.height}),this.volumetrics.ghostAvailable&&(c.save(),c.globalAlpha=s,this.volumetrics.drawGhost(c,this.flameView(),d,p),c.restore()),o&&a.mode===`car`&&(c.save(),c.globalAlpha*=this.primaryVehicleOpacity,this.drawVehicleAndWeapons(e,s,f.get(e)),c.restore(),this.debugDrive&&(r?.drawDebug?.(c,a,this,e.damage),this.diagnostics.draw(c,a,t,e=>this.screen(e),{width:this.view.width,rocketState:e.weapons.rocket.state,gunState:e.weapons.machineGuns.state,bulletCount:e.weapons.machineGuns.projectileCount,fluidEngine:this.volumetrics.smokeResolution.engine,quality:this.quality,fluidCols:this.volumetrics.smokeResolution.cols,fluidRows:this.volumetrics.smokeResolution.rows,fireCols:this.combustion.resolution?.cols??0,fireRows:this.combustion.resolution?.rows??0,groundedFireCount:this.combustion.count}))),o&&a.mode===`ship`&&this.vehicles.ship(this.ctx,a.body,a),o&&a.mode===`brick`&&this.vehicles.brick(this.ctx,a.body);for(let e of i){let t=e.sim;if(t.mode!==`car`||(this.drawVehicleAndWeapons(e,s,f.get(e)),t.car.explodedAt!==null))continue;let n=this.screen(t.body.position);c.save(),c.font=`600 10px ui-monospace, monospace`,c.textAlign=`center`;let r=e.label;if(!r)continue;let i=Math.max(30,Math.ceil(c.measureText(r).width)+14);c.fillStyle=`rgba(24, 27, 30, 0.88)`,c.fillRect(n.x-i/2,n.y-37,i,16),c.fillStyle=`#f5f2ec`,c.fillText(r,n.x,n.y-25),c.restore()}if(this.pixelSpace&&(c.save(),c.translate(-u.x,-u.y),Be(c,this.debris.particles,{x:u.x,y:u.y,width:this.view.width,height:this.view.height},d,`air`),c.restore()),c.save(),this.clipFluidWalls(c),performance.now(),this.combustion.draw(c,this.flameView(),d,p),c.restore(),performance.now(),this.sparks.draw(c,e=>this.particleScreen(e),s,{width:this.view.width,height:this.view.height},this.view.dpr,this.canvasWorld?void 0:this.surface.canvas),this.pointPuffs.length){c.save(),c.font=`700 13px ui-monospace, monospace`,c.textAlign=`center`,c.textBaseline=`middle`;for(let e of this.pointPuffs){let t=this.particleScreen(e.point),n=e.age/.9;c.globalAlpha=(1-n)*s,c.fillStyle=`#f8f4e9`,c.strokeStyle=`rgba(22, 24, 26, 0.85)`,c.lineWidth=3;let r=`+${e.amount}`,i=t.y-16-n*26;c.strokeText(r,t.x,i),c.fillText(r,t.x,i)}c.restore()}if(r?.drawForeground?.(c,u,{width:this.view.width,height:this.view.height}),performance.now(),r?.drawHealthBars?.(c,u,{width:this.view.width,height:this.view.height},e,this,i),n){let e=this.screen(n.from),t=this.screen(n.to);c.strokeStyle=`#ffdf93`,c.lineWidth=2,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(t.x,t.y),c.stroke()}c.restore(),this.objectGlint?.draw(c,this.view.width,this.view.height,this.darkSurface()),this.vehicles.drawVehicleMarkers(this.ctx,o?[e,...i]:i,this.showVehicleMarkers),this.surface.presentLockedCamera(),this.liquidLayer.drawTextVehicles([e,...i].filter(t=>(t!==e||o)&&t.sim.mode===`car`&&!t.isGhost&&t.sim.car.explodedAt===null).map(e=>({point:this.screen(e.sim.body.position),radius:Math.hypot(e.sim.car.preset.geometry.lengthM,e.sim.car.preset.geometry.widthM)*this.view.zoom/2+12})),l,t=>{for(let n of[e,...i]){if(n===e&&!o||n.sim.mode!==`car`||n.isGhost||n.sim.car.explodedAt!==null)continue;let r=this.carVisualOffset(n.sim);t.save(),t.translate(r.x,r.y),this.vehicles.car(t,n.sim.body,n.sim,n.damage,Math.max(n.weapons.flamethrower.openAmount,n.weapons.machineGuns.openAmount)),t.restore()}}),this.governFluidQuality(t)}governFluidQuality(e){let t=performance.now()-e;if(!(t>=0&&t<1e3))return;let n=this.volumetrics.running||this.combustion.running;this.fluidGovernor.sample(e,t,n,this.quality)&&(d(`fluid quality limit ${this.fluidGovernor.limit}`),this.applyFluidQuality())}};export{Fl as n,Ve as r,Il as t};
|