@joy-ride/joy-ride 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ function e(e){if(typeof e==`string`){if(!/^#[\da-f]{6}$/i.test(e))throw RangeError(`Use a six-digit hex color or an RGB tuple.`);return[1,3,5].map(t=>parseInt(e.slice(t,t+2),16))}if(!Array.isArray(e)||e.length!==3||e.some(e=>!Number.isFinite(e)||e<0||e>255))throw RangeError(`RGB channels must be finite numbers from 0 to 255.`);return[...e]}function t(e){let t=typeof e==`string`?e:e.kind;if(!Object.hasOwn(i,t))throw Error(`Unknown liquid: ${t}`);return t}var n={oil:{family:`oil`,conductive:!1,burnable:!0,deformation:1,thickness:.86,alpha:1,color:[5,8,9],effectDistanceM:30,treadDistanceM:30,minimumGrip:.28,burnSeconds:12,burnLifetime:12,fireSpreadMps:3.2},water:{family:`water`,conductive:!0,burnable:!1,deformation:1,thickness:.14,alpha:.52,color:[116,172,196],effectDistanceM:0,treadDistanceM:15,minimumGrip:1},paint:{family:`paint`,conductive:!1,burnable:!1,deformation:1,thickness:.78,alpha:1,color:[205,49,57],effectDistanceM:0,treadDistanceM:30,minimumGrip:1},mud:{family:`mud`,conductive:!1,burnable:!1,deformation:1,thickness:.98,alpha:1,color:[104,72,45],effectDistanceM:18,treadDistanceM:34,minimumGrip:.45,speedFactor:.78,driveForceFactor:.82,contactGrip:.52,contactSpeedFactor:.72,contactDriveForceFactor:.8}},r={gloss:0,relief:0,film:0,grain:0,fineSpray:1},i={...n,"iridescent-oil":{...n.oil,color:[22,29,31]},"clear-water":{...n.water,color:[115,173,187]},"wet-clay":{...n.mud,color:[133,91,59]},"concept-water":{...n.water,color:[104,151,159]},"concept-oil":{...n.oil,color:[17,22,24]},"concept-syrup":{...n.paint,color:[159,75,14]},"concept-clay":{...n.mud,color:[114,82,61]},"concept-lava":{...n.mud,color:[62,30,22]},"concept-acid":{...n.water,alpha:.82,color:[137,182,31]},"concept-paint":{...n.paint}},a={oil:r,water:r,paint:r,mud:r,"iridescent-oil":{gloss:.72,relief:.7,film:.65,grain:0,fineSpray:1},"clear-water":{gloss:.85,relief:.85,film:0,grain:0,fineSpray:1},"wet-clay":{gloss:.28,relief:.55,film:0,grain:.7,fineSpray:1},"concept-water":{...r,fineSpray:1},"concept-oil":{...r,fineSpray:1},"concept-syrup":{...r,fineSpray:1},"concept-clay":{...r,fineSpray:1},"concept-lava":{...r,fineSpray:1},"concept-acid":{...r,fineSpray:1},"concept-paint":{...r,fineSpray:1}};function o(e){return i[e].family}var s={"concept-water":{name:`Water`,description:`Fast spreading · low viscosity · clear wakes`,gravity:1800,viscosity:2.5,cohesion:20,yieldStress:0,contactDepth:.06,wetting:.3,roughness:.07,absorption:.22,iridescence:0,sediment:0,settleSeconds:12},"concept-oil":{name:`Motor oil`,description:`Slow sheets · high viscosity · persistent tire coating`,gravity:650,viscosity:12,cohesion:16,yieldStress:0,contactDepth:.16,wetting:4,roughness:.12,absorption:20,iridescence:.45,sediment:0,settleSeconds:10},"concept-syrup":{name:`Amber syrup`,description:`Slow leveling · cohesive flow · persistent coating`,gravity:220,viscosity:30,cohesion:25,yieldStress:.05,contactDepth:.32,wetting:34,roughness:.09,absorption:1.7,iridescence:0,sediment:0,settleSeconds:10},"concept-clay":{name:`Clay slurry`,description:`Yield resistance · persistent furrows · suspended sediment`,gravity:120,viscosity:22,cohesion:12,yieldStress:.8,contactDepth:.22,wetting:18,roughness:.58,absorption:5,iridescence:0,sediment:.6,settleSeconds:8},"concept-lava":{name:`Basalt lava`,description:`High yield resistance · slow transport · heavy spray`,gravity:100,viscosity:38,cohesion:30,yieldStress:1.2,contactDepth:.35,wetting:35,roughness:.65,absorption:16,iridescence:0,sediment:.85,settleSeconds:14,thermal:[1,.9,.05,0],atmosphere:{emission:.65,emissionColor:[255,112,18],pulseSeconds:7.5,vaporOpacity:.56,vaporRise:22,vaporColor:[207,104,40],embers:{density:.45,color:[255,143,35],rise:20,size:.7,brightness:.85}}},"concept-acid":{name:`Acid`,description:`Fast wetting · low viscosity · fine spray`,gravity:2100,viscosity:1.2,cohesion:14,yieldStress:0,contactDepth:.045,wetting:.1,roughness:.045,absorption:.65,iridescence:.08,sediment:0,settleSeconds:12,thermal:[.08,0,.45,.8],atmosphere:{emission:.75,emissionColor:[168,255,38],pulseSeconds:6.5,vaporOpacity:.58,vaporRise:18,vaporColor:[119,181,34]}},"concept-paint":{name:`Paint`,description:`Opaque pigment · local color mixing · marbled tire pickup`,gravity:420,viscosity:18,cohesion:18,yieldStress:.1,contactDepth:.2,wetting:9,roughness:.18,absorption:24,iridescence:0,sediment:0,settleSeconds:12,mixing:!0,surface:{microRelief:0,heightNormalScale:2.4,clearcoat:1}}};function c(e){if(e.startsWith(`custom:`))return d.get(e)??null;let t=e===`paint`?`concept-paint`:e===`iridescent-oil`?`concept-oil`:e===`clear-water`?`concept-water`:e===`wet-clay`?`concept-clay`:e;return t in s?s[t]:null}var l={water:{coverage:.5,breakup:.32,film:.08,gloss:.9,iridescence:0,grain:0,drain:2.3,pitchM:.12,spray:1.1,impact:.3,carryM:5,emission:0},oil:{coverage:.82,breakup:.18,film:.78,gloss:.85,iridescence:.55,grain:0,drain:1.5,pitchM:.12,spray:.8,impact:.6,carryM:23,emission:0},paint:{coverage:.96,breakup:.08,film:.94,gloss:.38,iridescence:0,grain:0,drain:1.15,pitchM:.12,spray:.5,impact:.8,carryM:26,emission:0},mud:{coverage:.92,breakup:.36,film:.66,gloss:.3,iridescence:0,grain:.9,drain:1.3,pitchM:.12,spray:.45,impact:1,carryM:20,emission:0}};function u(e){let t=l[o(e)],n=c(e);return n?{...t,gloss:0,iridescence:0,grain:n.sediment,spray:1/(1+n.viscosity*.06),impact:Math.min(1,n.cohesion/30),emission:0,carryM:Math.min(28,4+n.viscosity*.7),breakup:Math.min(.65,.16+n.yieldStress*.3),drain:1.2+2/(1+n.viscosity)}:{...t,gloss:0,iridescence:0,emission:0}}var d=new Map,f=new Map;function p(e){return f.get(e)}function m(t,r){if(!/^[a-z][a-z0-9-]{0,63}$/.test(t))throw Error(`Liquid names use lowercase letters, digits and hyphens.`);let o=`custom:${t}`;for(let e of[`conductive`,`burnable`])if(r[e]!==void 0&&typeof r[e]!=`boolean`)throw TypeError(`Liquid ${e} must be a boolean.`);if(Object.hasOwn(i,o))throw Error(`Liquid already defined: ${t}`);if(!Object.hasOwn(i,r.base))throw Error(`Choose a defined base liquid.`);for(let e of[r.thickness,r.opacity])if(e!==void 0&&(!Number.isFinite(e)||e<0||e>1))throw RangeError(`Thickness and opacity must be between 0 and 1.`);if(r.deformation!==void 0&&(!Number.isFinite(r.deformation)||r.deformation<0||r.deformation>4))throw RangeError(`Deformation must be between 0 and 4.`);let s=r.effect;for(let e of[r.burnLifetime,r.fireSpreadMps])if(e!==void 0&&(!Number.isFinite(e)||e<=0))throw RangeError(`Liquid burn lifetime and fire spread speed must be positive finite numbers.`);if(s&&(![`seconds`,`distanceM`].includes(s.lifetime.unit)||!Number.isFinite(s.lifetime.amount)||s.lifetime.amount<=0||Object.values(s.modifiers).some(e=>e!==void 0&&(!Number.isFinite(e)||e<0))||Object.values(s.additiveModifiers??{}).some(e=>e!==void 0&&!Number.isFinite(e))))throw RangeError(`Invalid liquid status effect.`);let l=i[r.base],u=r.burnable??l.burnable,p={...l,conductive:r.conductive??l.conductive,burnable:u,color:e(r.color??l.color),thickness:r.thickness??l.thickness,deformation:r.deformation??l.deformation,alpha:r.opacity??l.alpha,burnLifetime:r.burnLifetime??l.burnLifetime??l.burnSeconds??(u?n.oil.burnLifetime:void 0),fireSpreadMps:r.fireSpreadMps??l.fireSpreadMps??(u?n.oil.fireSpreadMps:void 0)};i[o]=Object.freeze(p),a[o]={...a[r.base]};let m=c(r.base),h=p.thickness/Math.max(.05,l.thickness);return d.set(o,m?{...m,viscosity:m.viscosity*Math.max(.05,h),yieldStress:m.yieldStress*h}:null),s&&f.set(o,{...s,lifetime:{...s.lifetime},modifiers:{...s.modifiers},additiveModifiers:s.additiveModifiers?{...s.additiveModifiers}:void 0}),Object.freeze({kind:o})}function h(e){e.startsWith(`custom:`)&&(delete i[e],delete a[e],d.delete(e),f.delete(e))}var g=[1,2,3,4,5,6,7,8,9],_=[`eject`,`machineGun`,`flamethrower`,`rocket`,`ghost`,`attractor`,`lightning`,`boost`],v=Symbol(`prepared vehicle slots`),y=Object.freeze({1:Object.freeze({action:`eject`,liquid:`oil`,activation:`hold`,rate:6,amount:.65}),2:Object.freeze({action:`machineGun`,activation:`hold`}),3:Object.freeze({action:`flamethrower`,activation:`hold`}),4:Object.freeze({action:`rocket`,activation:`hold`}),5:Object.freeze({action:`ghost`,activation:`hold`}),6:Object.freeze({action:`attractor`,activation:`hold`}),7:Object.freeze({action:`lightning`,activation:`hold`})});function b(e){if(!Number.isInteger(e)||e<1||e>9)throw RangeError(`Vehicle slots use whole numbers from 1 to 9.`);return e}var x=new Set(_),S=new Set([`action`,`activation`]),C=new Set([...S,`liquid`,`rate`,`amount`]);function ee(e,t=`slots`,n=!0,r=(e,t)=>{throw TypeError(`${e}: ${t}`)}){(!e||typeof e!=`object`||Array.isArray(e))&&r(t,`expected a slot configuration object.`);for(let[i,a]of Object.entries(e)){if(/^[1-9]$/.test(i)||r(`${t}.${i}`,`slot must be from 1 to 9.`),a===!1)continue;(!a||typeof a!=`object`||Array.isArray(a))&&r(`${t}.${i}`,`expected an action or false.`);let e=a;!n&&e.action===void 0||typeof e.action==`string`&&x.has(e.action)||r(`${t}.${i}.action`,`choose a supported vehicle action.`),e.activation!==void 0&&e.activation!==`tap`&&e.activation!==`hold`&&r(`${t}.${i}.activation`,`choose tap or hold.`);let o=e.action===`eject`||!n&&e.action===void 0?C:S;for(let n of Object.keys(e))o.has(n)||r(`${t}.${i}.${n}`,`unsupported option for this action.`);e.action===`eject`&&n&&(typeof e.liquid!=`string`||!e.liquid.trim())&&r(`${t}.${i}.liquid`,`choose a liquid definition.`),e.liquid===void 0||typeof e.liquid==`string`&&e.liquid.trim()||r(`${t}.${i}.liquid`,`choose a liquid definition.`);for(let n of[`rate`,`amount`])e[n]!==void 0&&(typeof e[n]!=`number`||!Number.isFinite(e[n])||e[n]<=0)&&r(`${t}.${i}.${n}`,`expected a positive finite amount.`)}}function te(e){if(e&&typeof e==`object`&&e[v])return e;ee(e);let n={...y};for(let t of g){let r=e[t];r!==void 0&&(n[t]=r===!1?!1:r.action===`eject`?Object.freeze({activation:`hold`,rate:6,amount:.65,...r}):Object.freeze({activation:`hold`,...r}))}for(let e of Object.values(n))e&&e.action===`eject`&&t(e.liquid);return Object.defineProperty(n,v,{value:!0}),Object.freeze(n)}var ne=class extends Error{path;code=`JR_INVALID_CONFIGURATION`;constructor(e,t){super(`${e}: ${t}`),this.path=e,this.name=`PlaygroundConfigurationError`}},w=(e,t)=>{throw new ne(e,t)},T=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return w(t,`expected an option object`);let n=Object.getPrototypeOf(e),r=n&&Object.getOwnPropertyDescriptor(n,`constructor`)?.value;return n!==null&&(Object.getPrototypeOf(n)!==null||typeof r!=`function`||Function.prototype.toString.call(r)!==Function.prototype.toString.call(Object))?w(t,`expected an option object`):e},E=(e,t)=>Object.hasOwn(e,t)&&e[t]!==void 0,re=e=>e!==void 0&&e!==!1,ie=(e,t,n)=>{for(let r of Object.keys(e))t.includes(r)||w(`${n}.${r}`,`unknown option`)},D=(e,t)=>(typeof e==`string`&&e.trim()||w(t,`expected a non-empty string`),e),O=(e,t)=>{typeof e!=`boolean`&&w(t,`expected true or false`)},k=(e,t,n=0,r=1/0,i=!1)=>{(typeof e!=`number`||!Number.isFinite(e)||(i?e<=n:e<n)||e>r)&&w(t,`expected a finite number ${i?`greater than`:`at least`} ${n}${r<1/0?` and at most ${r}`:``}`)},A=(e,t,n)=>{typeof e==`string`&&t.includes(e)||w(n,`expected ${t.join(`, `)}`)},ae=(e,t,n=!1)=>{n&&e===`auto`||typeof e==`string`&&/^#[\da-f]{6}$/i.test(e)||Array.isArray(e)&&e.length===3&&e.every(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=255)||w(t,`expected a six-digit hex color or RGB tuple`)},j=(e,t,n)=>{ie(e,Object.keys(t),n);for(let[r,i]of Object.entries(t))E(e,r)&&i(e[r],`${n}.${r}`)},M=(e,t)=>k(e,t,0,1/0,!0),oe=(e,t)=>k(e,t,0,1),N=(e,t)=>k(e,t),se=(e,t)=>A(e,[`auto`,`light`,`dark`],t),ce=(e,t,n)=>{typeof e!=`boolean`&&j(T(e,t),n,t)};function le(e,t){let n=Math.imul(e^Math.imul(t+13,374761393),668265263);return n=Math.imul(n^n>>>13,1274126177),((n^n>>>16)>>>0)/4294967296}function ue(e,t,n,r){let i=Array.from({length:9},(i,a)=>{let o=a*2.399963+le(r,3)*6.28,s=Math.sqrt(a/9)*n*.45;return{x:e+Math.cos(o)*s,y:t+Math.sin(o)*s*.8,z:0,vx:0,vy:0,vz:0,radius:n*(.29+le(r,a+20)*.13),spread:1,angle:le(r,a+40)*6.28,mass:1/9,seed:r+a*7919|0}}),a=i.reduce((t,n)=>t+n.x-e,0)/i.length,o=i.reduce((e,n)=>e+n.y-t,0)/i.length;for(let e of i)e.x-=a,e.y-=o;return{parcels:i,radius:n}}function de(e,t,n,r,i){let a=e.dust,o=!1;for(let e of a.parcels){let a=r(e.x,e.y),s=a.x,c=a.y,l=Math.hypot(s-e.vx,c-e.vy),u=e.z>.02||e.vz>0;if(!u&&l<18&&Math.hypot(e.vx,e.vy)<.02){e.vx=e.vy=0;continue}o=!0;let d=1-Math.exp(-e.z/9),f=le(31,73)*6.28,p=e.x/61+n*.35+f,m=e.y/53-n*.22+f,h=e.x/23+e.y/39+n*.8,g=d*Math.min(950,l*8+Math.hypot(e.vx,e.vy)*4);s+=(-Math.sin(p)*Math.sin(m)/53+Math.cos(h)*.3/39)*g,c-=(Math.cos(p)*Math.cos(m)/61+Math.cos(h)*.3/23)*g;let _=15+le(e.seed,5)*9,v=Math.max(0,l-20)*(.85+le(e.seed,7)*.4);(u||v>_)&&(e.vz+=(v/(1+e.z/80)-_-e.vz*1.6)*t),e.vz=Math.min(65,e.vz),e.z=Math.max(0,Math.min(80,e.z+e.vz*t)),e.z===0&&e.vz<0&&(e.vz=0),e.z===80&&(e.vz=Math.min(0,e.vz));let y=e.z>.02?1:Math.max(0,Math.min(.6,(l-18)/90)),b=1-Math.exp(-(2.2+le(e.seed,9)*2)*y*t);if(e.vx+=(s-e.vx)*b,e.vy+=(c-e.vy)*b,e.z<.02){let n=Math.exp(-9*t);e.vx*=n,e.vy*=n}let x=e.x,S=e.y;if(e.x+=e.vx*t,e.y+=e.vy*t,e.z<12)for(let t of i)e.x<t.x||e.x>t.x+t.width||e.y<t.y||e.y>t.y+t.height||((x<=t.x||x>=t.x+t.width)&&(e.x=x,e.vx=0),(S<=t.y||S>=t.y+t.height)&&(e.y=S,e.vy=0));e.spread=Math.min(2.2,e.spread+d*Math.hypot(e.vx,e.vy)*t*.0018),e.angle+=(e.vx-e.vy)*t*.006+d*Math.sin(p+m)*t*.7}if(!o)return;let s=a.parcels.length;for(let t of[`x`,`y`,`z`,`vx`,`vy`,`vz`])e[t]=a.parcels.reduce((e,n)=>e+n[t],0)/s;a.radius=Math.max(...a.parcels.map(t=>Math.hypot(t.x-e.x,t.y-e.y)+t.radius*t.spread*1.8))}function P(e,t=new WeakMap){if(typeof e==`function`)throw Error(`Functions are not checkpoint state`);if(typeof e!=`object`||!e)return e;if(t.has(e))return t.get(e);if(typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement){let n=document.createElement(`canvas`);return n.width=e.width,n.height=e.height,n.getContext(`2d`)?.drawImage(e,0,0),t.set(e,n),n}if(typeof Node<`u`&&e instanceof Node||typeof Range<`u`&&e instanceof Range)return e;if(typeof ImageData<`u`&&e instanceof ImageData)return new ImageData(new Uint8ClampedArray(e.data),e.width,e.height);if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e)){let n=[];t.set(e,n);for(let r of e)n.push(P(r,t));return n}if(ArrayBuffer.isView(e))return e instanceof DataView?new DataView(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)):new e.constructor(e);if(e instanceof Map){let n=new Map;t.set(e,n);for(let[r,i]of e)n.set(P(r,t),P(i,t));return n}if(e instanceof Set){let n=new Set;t.set(e,n);for(let r of e)n.add(P(r,t));return n}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&!Object.keys(e).length)throw Error(`Cannot checkpoint ${e.constructor?.name??`unknown engine resource`}`);let r=Object.create(n);t.set(e,r);for(let[n,i]of Object.entries(e))r[n]=P(i,t);return r}var fe=Object.freeze([`paper`,`crumpled-paper`,`trash`,`leaf`,`dust`]),pe=Object.freeze([`center`,`top`,`top-right`,`right`,`bottom-right`,`bottom`,`bottom-left`,`left`,`top-left`,`fill`]),F=(e,t)=>{let n=Math.imul(e+31,374761393)^Math.imul(t+17,668265263);return n=Math.imul(n^n>>>13,1274126177),((n^n>>>16)>>>0)/4294967296},me=(e,t,n)=>e+(t-e)*n;function he(e,t){let n=Math.floor(e),r=e-n;return me(F(n,t),F(n+1,t),r*r*(3-2*r))*2-1}var ge={paper:{size:[15,24],response:3.8,threshold:28,lift:1.6,gravity:52,friction:4,colors:[`#f2efe4`,`#e4e5dc`,`#e8dfc8`,`#d8e2e2`]},"crumpled-paper":{size:[8,13],response:1.8,threshold:82,lift:.65,gravity:170,friction:2.8,colors:[`#b9b4a4`,`#d2cbbb`,`#9eaaad`]},trash:{size:[11,18],response:3,threshold:45,lift:1.15,gravity:92,friction:4,colors:[`#9aacae`,`#b2a681`,`#ab6960`,`#697f86`]},leaf:{size:[12,21],response:3.4,threshold:32,lift:1.4,gravity:65,friction:4.5,colors:[`#91824e`,`#927146`,`#707c4e`,`#9c7552`]},dust:{size:[28,46],response:5,threshold:24,lift:1.5,gravity:20,friction:6,colors:[`#a28a62`,`#978a76`,`#b09b79`]}};function _e(e={}){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`Debris options must be an object`);for(let t of Object.keys(e))if(![`amount`,`kinds`,`anchor`,`spread`,`seed`,`wind`,`color`,`glint`].includes(t))throw RangeError(`Unknown debris option: ${t}`);let t=(t,n,r,i=!1)=>{let a=e[t];if(a!==void 0&&(!Number.isFinite(a)||a<n||a>r||i&&!Number.isInteger(a)))throw RangeError(`debris.${t} must be ${i?`an integer`:`a number`} between ${n} and ${r}`)};if(t(`amount`,0,600,!0),t(`spread`,0,2e3),t(`seed`,-2147483648,2147483647,!0),e.anchor!==void 0&&!pe.includes(e.anchor))throw RangeError(`Unknown debris anchor`);if(e.kinds!==void 0&&(!Array.isArray(e.kinds)||!e.kinds.length||e.kinds.some(e=>!fe.includes(e))))throw RangeError(`Choose at least one supported debris kind`);if(e.wind!==void 0&&(!e.wind||typeof e.wind!=`object`||!Number.isFinite(e.wind.x)||!Number.isFinite(e.wind.y)||Math.hypot(e.wind.x,e.wind.y)>500))throw RangeError(`Debris wind must be a finite vector up to 500 pixels/second`);if(e.glint!==void 0&&(!Number.isFinite(e.glint)||e.glint<0||e.glint>1))throw RangeError(`Debris glint must be between 0 and 1`);if(e.color!==void 0&&!/^#[\da-f]{3}(?:[\da-f]{3})?$/i.test(e.color))throw RangeError(`Debris color must be a 3 or 6 digit hex color`)}function ve(e,t){let n=t.anchor,r=n.includes(`left`)||n===`left`?0:n.includes(`right`)||n===`right`?1:.5,i=n.includes(`top`)||n===`top`?0:n.includes(`bottom`)||n===`bottom`?1:.5;return Array.from({length:t.amount},(a,o)=>{let s=Math.imul(t.seed,31)+o*977|0,c=t.kinds[o%t.kinds.length],l=ge[c],u=F(s,7)*Math.PI*2,d=Math.sqrt(F(s,11))*t.spread,f={kind:c,x:e.x+(n===`fill`?F(s,13)*e.width:e.width*r+Math.cos(u)*d),y:e.y+(n===`fill`?F(s,17)*e.height:e.height*i+Math.sin(u)*d),z:0,vx:0,vy:0,vz:0,angle:F(s,19)*Math.PI*2,spin:0,tilt:0,fold:.05+F(s,23)*.18,curlX:.35+F(s,41)*.4,curlY:.1+F(s,43)*.35,twist:(F(s,47)-.5)*.4,curlVelocityX:0,curlVelocityY:0,twistVelocity:0,size:me(l.size[0],l.size[1],F(s,29)),seed:s,color:t.color||l.colors[Math.floor(F(s,31)*l.colors.length)],age:0,opacity:c===`dust`?.65+F(s,37)*.2:1,glint:t.glint};return c===`dust`&&(f.dust=ue(f.x,f.y,f.size,s)),f})}var ye=class{groups=new Map;vortices=[];serial=0;time=0;wakeClock=0;collection=[];get particles(){return this.collection}get count(){return this.collection.length}get managedBytes(){return this.count*216+this.collection.reduce((e,t)=>e+(t.dust?.parcels.length??0)*104,0)+this.vortices.length*64}collect(){this.collection=[...this.groups.values()].flatMap(e=>e.particles)}scatter(e,t={}){if(_e(t),[e.x,e.y,e.width,e.height].some(e=>!Number.isFinite(e))||e.width<0||e.height<0)throw RangeError(`Debris bounds must be finite and non-negative`);let n={amount:t.amount??30,anchor:t.anchor??`center`,kinds:[...new Set(t.kinds??fe)],seed:t.seed??31,spread:t.spread??Math.max(60,Math.min(200,Math.sqrt(e.width*e.height)*.4)),wind:{...t.wind??{x:7,y:-2}},color:t.color??``,glint:t.glint??.12};if(this.count+n.amount>3e3)throw RangeError(`Scene debris budget is 3000 particles`);let r=`debris-${++this.serial}`;return this.groups.set(r,{bounds:{...e},options:n,particles:ve(e,n),gust:{x:0,y:0},gustAge:0}),this.collect(),this.handle(r)}get(e){return this.groups.has(e)?this.handle(e):null}handle(e){return{id:e,reset:()=>{let t=this.groups.get(e);t&&(t.particles=ve(t.bounds,t.options),t.gust={x:0,y:0},this.collect())},gust:t=>{if(!Number.isFinite(t.x)||!Number.isFinite(t.y)||Math.hypot(t.x,t.y)>500)throw RangeError(`Gust velocity must be finite and at most 500 pixels/second`);let n=this.groups.get(e);n&&(n.gust={...t},n.gustAge=0)},dispose:()=>{this.groups.delete(e),this.collect()}}}reset(){this.vortices=[],this.time=0,this.wakeClock=0;for(let e of this.groups.values())e.particles=ve(e.bounds,e.options),e.gust={x:0,y:0},e.gustAge=0;this.collect()}clear(){this.groups.clear(),this.vortices=[],this.collection=[]}captureState(){return P({groups:this.groups,vortices:this.vortices,serial:this.serial,time:this.time,wakeClock:this.wakeClock})}restoreState(e){let t=P(e);this.groups=t.groups,this.vortices=t.vortices,this.serial=Math.max(this.serial,t.serial),this.time=t.time,this.wakeClock=t.wakeClock,this.collect()}step(e,t=[],n,r=[]){if(!this.count||e<=0)return;let i=Math.max(1,Math.ceil(Math.min(.1,e)*120));for(let a=0;a<i;a++)this.integrate(Math.min(.1,e)/i,t,n,r)}airAt(e,t,n,r,i){let a=1+he(this.time*.27+e*7e-4,n.options.seed)*.55,o=n.options.wind.x*a+n.gust.x*r,s=n.options.wind.y*a+n.gust.y*r;o+=he(this.time*.5+t*.002,n.options.seed+19)*5,s+=he(this.time*.4+e*.002,n.options.seed+31)*5;for(let n of i){let r=e-n.x,i=t-n.y,a=Math.hypot(n.vx,n.vy);if(a<3||Math.abs(r)>n.length+100||Math.abs(i)>n.length+100)continue;let c=n.angle,l=Math.cos(c),u=Math.sin(c),d=r*l+i*u,f=-r*u+i*l,p=Math.max(0,1-Math.abs(d)/(n.length*.75+40))*Math.max(0,1-Math.abs(f)/(n.width*.7+55)),m=f>=0?1:-1;o+=(n.vx*.22-u*a*.36*m)*p,s+=(n.vy*.22+l*a*.36*m)*p}for(let n of this.vortices){let r=e-n.x,i=t-n.y,a=r*r+i*i;if(a>n.radius*n.radius)continue;let c=(1-a/(n.radius*n.radius))**2*Math.exp(-n.age*2),l=n.strength*c/Math.max(12,Math.sqrt(a));o+=-i*l+n.vx*c,s+=r*l+n.vy*c}return{x:o,y:s}}integrate(e,t,n,r=[]){this.time+=e,this.wakeClock+=e,this.vortices=this.vortices.filter(e=>e.age<1.6);for(let t of this.vortices)t.age+=e,t.x+=t.vx*e,t.y+=t.vy*e;if(this.wakeClock>=.1){this.wakeClock%=.1;for(let e of t){let t=Math.hypot(e.vx,e.vy);if(t<35)continue;let n=e.vx/t,r=e.vy/t;for(let i of[-1,1])this.vortices.push({x:e.x-n*e.length*.45-r*e.width*.6*i,y:e.y-r*e.length*.45+n*e.width*.6*i,vx:e.vx*.12,vy:e.vy*.12,strength:Math.min(200,t*.3)*i,radius:Math.min(130,e.width*1.6+t*.1),age:0})}this.vortices.length>32&&this.vortices.splice(0,this.vortices.length-32)}for(let i of this.groups.values()){i.gustAge+=e;let a=Math.exp(-i.gustAge*1.5);for(let o of i.particles){if(o.age+=e,n&&o.z<.05&&(!o.dust||o.dust.parcels.every(e=>e.z===0&&e.vz===0))&&Math.hypot(o.vx,o.vy)<2&&o.vz<=0&&(o.x<n.x-300-(o.dust?.radius??0)||o.x>n.x+n.width+300+(o.dust?.radius??0)||o.y<n.y-300-(o.dust?.radius??0)||o.y>n.y+n.height+300+(o.dust?.radius??0)))continue;let s=ge[o.kind];if(o.kind===`dust`){o.dust??=ue(o.x,o.y,o.size,o.seed),de(o,e,this.time,(e,n)=>this.airAt(e,n,i,a,t),r);continue}let{x:c,y:l}=this.airAt(o.x,o.y,i,a,t),u=Math.hypot(c-o.vx,l-o.vy),d=o.z>.1||o.vz>0,f=Math.max(0,u-s.threshold)*s.lift;(d||f>s.gravity*.8)&&(o.vz+=(f-s.gravity-o.vz*1.8)*e,o.vz=Math.min(95,o.vz)),o.z+=o.vz*e,o.z<=0&&(o.z=0,o.vz=o.vz<-18&&o.kind===`crumpled-paper`?-o.vz*.13:0),o.z>70&&(o.z=70,o.vz=Math.min(0,o.vz));let p=o.z>.1?1:Math.max(0,Math.min(.7,(u-s.threshold*.5)/70));if(o.vx+=(c-o.vx)*(1-Math.exp(-s.response*p*e)),o.vy+=(l-o.vy)*(1-Math.exp(-s.response*p*e)),o.z<.1){let t=Math.exp(-s.friction*e);o.vx*=t,o.vy*=t}let m=o.x,h=o.y;if(o.x+=o.vx*e,o.y+=o.vy*e,o.z<12){for(let e of r)if(!(o.x<e.x||o.x>e.x+e.width||o.y<e.y||o.y>e.y+e.height)){o.x=m,o.y=h,o.vx*=-.15,o.vy*=-.15;break}}let g=he(this.time*3.2+o.x*.01,o.seed),_=(c*Math.sin(o.angle)-l*Math.cos(o.angle))*.024;if(o.spin+=(_+g*u*.02-o.spin*(o.z>0?1.8:9))*e,o.angle+=o.spin*e,o.kind===`paper`){let t=Math.min(1,Math.max(0,(u-18)/100)),n=c-o.vx,r=l-o.vy,i=Math.max(1,Math.hypot(n,r)),a=(n*Math.cos(o.angle)+r*Math.sin(o.angle))/i,s=(-n*Math.sin(o.angle)+r*Math.cos(o.angle))/i,d=.35+F(o.seed,41)*.4,f=.1+F(o.seed,43)*.35,p=(F(o.seed,47)-.5)*.4,m=d+t*(1.5+Math.abs(a)*1.1+g*.7),h=f+t*(.5+Math.abs(s)*.8-g*.3),_=p+t*(s*.9+g*.8);o.curlVelocityX+=((m-o.curlX)*55-o.curlVelocityX*9)*e,o.curlVelocityY+=((h-o.curlY)*38-o.curlVelocityY*7)*e,o.twistVelocity+=((_-o.twist)*42-o.twistVelocity*7.5)*e,o.curlX+=o.curlVelocityX*e,o.curlY+=o.curlVelocityY*e,o.twist+=o.twistVelocity*e}if(o.z>.5)o.tilt+=(Math.hypot(o.vx,o.vy)*.035+g*2.5)*e,o.fold+=(.18+Math.abs(g)*.5-o.fold)*Math.min(1,e*8);else{if(o.kind===`crumpled-paper`)o.tilt+=Math.hypot(o.vx,o.vy)/Math.max(2,o.size*.42)*e;else{let t=Math.round(o.tilt/Math.PI)*Math.PI;o.tilt+=(t-o.tilt)*(1-Math.exp(-e*10))}o.fold+=(.05+F(o.seed,23)*.18-o.fold)*Math.min(1,e*4)}}}}},be={health:M},xe={burnSeconds:M,ignitionSeconds:N,spreadSeconds:N},Se={health:M,burnSeconds:M,blastRadiusPx:M},Ce={scale:oe,opacity:oe,crushedClass:D,crushedPaintColor:(e,t)=>ae(e,t)},we={kind:D,color:(e,t)=>ae(e,t,!0),distanceM:N,opacity:oe,deformation:(e,t)=>k(e,t,0,4)},Te=[`click`,`check`,`toggle`,`pickup`,`parking`],Ee=(e,t)=>{typeof e!=`string`&&w(t,`expected a space-separated class string`)},De={preset:(e,t)=>A(e,Te,t),when:(e,t)=>A(e,[`enter`,`stop`],t),dwellSeconds:N,maxSpeedMps:N,action:(e,t)=>A(e,[`event`,`click`,`check`,`uncheck`,`toggle`],t),event:D,repeat:(e,t)=>A(e,[`visit`,`vehicle`,`scene`],t),vehicles:(e,t)=>A(e,[`player`,`all`,`ai`],t),target:D,consume:O,exitMarginPx:N,containment:(e,t)=>A(e,[`overlap`,`center`,`full`],t),requireExit:O,suspended:O,reveal:(e,t)=>A(e,[`departed`],t),enteredClass:Ee,dwellingClass:Ee,successClass:Ee};function Oe(e,t){typeof e!=`boolean`&&(typeof e==`string`?A(e,Te,t):j(T(e,t),De,t))}function ke(e,t,n=!0){ee(e,t,n,w)}function Ae(e,t,n=new Set){if(e!==null&&typeof e!=`string`&&typeof e!=`boolean`){if(typeof e==`number`)k(e,t,-1/0);else{if(typeof e!=`object`)return w(t,`metadata must be JSON-compatible`);if(n.has(e)&&w(t,`metadata cannot contain cycles`),n.add(e),Array.isArray(e))e.forEach((e,r)=>Ae(e,`${t}.${r}`,n));else for(let[r,i]of Object.entries(T(e,t)))Ae(i,`${t}.${r}`,n);n.delete(e)}}}function je(e,t,n=!0){if(e===!1)return;let r=T(e,t);j(r,{field:(e,t)=>A(e,[`fps`,`speed`,`rpm`,`gear`,`health`,`points`],t),unit:(e,t)=>A(e,[`mph`,`kmh`,`mps`],t),precision:(e,t)=>{k(e,t,0,4),Number.isInteger(e)||w(t,`precision must be an integer`)}},t),n&&!E(r,`field`)&&w(`${t}.field`,`choose one HUD metric`),E(r,`unit`)&&E(r,`field`)&&r.field!==`speed`&&w(`${t}.unit`,`only speed has a unit`)}var Me={id:D,enabled:O,debris:e=>{typeof e!=`boolean`&&_e(e)},trigger:Oe,hud:je,meta:(e,t)=>{T(e,t),Ae(e,t)},object:D,solid:O,pushable:O,points:N,liquid:(e,t)=>{if(e===!1)return;let n=T(e,t);j(n,we,t),E(n,`kind`)||w(`${t}.kind`,`choose a liquid`)},breakable:(e,t)=>ce(e,t,be),burnable:(e,t)=>ce(e,t,xe),combustible:(e,t)=>ce(e,t,Se),crushable:(e,t)=>ce(e,t,Ce)},Ne={id:D,vehicle:D,driver:(e,t)=>A(e,[`player`,`idle`,`follow`,`flee`,`pursue`],t),appearance:se,slots:ke};function Pe(e){let t=T(e,`object`);return j(t,{...Me,hud:(e,t)=>je(e,t,!1)},`object`),structuredClone(t)}function Fe(e){let t=T(e,`object`);return j(t,Me,`object`),re(t.combustible)&&re(t.breakable)&&w(`object.combustible`,`combustible excludes breakable`),re(t.crushable)&&re(t.breakable)&&w(`object.crushable`,`crushable excludes breakable`),re(t.crushable)&&t.solid===!0&&w(`object.solid`,`crushable objects cannot be solid`),re(t.hud)&&(re(t.breakable)||re(t.burnable)||t.pushable===!0||re(t.liquid))&&w(`object.hud`,`HUD output cannot also own artwork or a liquid field`),structuredClone(t)}function Ie(e){let t=T(e,`vehicle`);j(t,{...Ne,slots:(e,t)=>ke(e,t,!1)},`vehicle`);let n=t.slots;if(n)for(let[e,t]of Object.entries(n))t&&t.action!==void 0&&ke({[e]:t},`vehicle.slots`);return structuredClone(t)}function Le(e){let t=T(e,`vehicle`);return j(t,Ne,`vehicle`),D(t.vehicle,`vehicle.vehicle`),structuredClone(t)}function Re(e){let t=T(e,`player`);return ie(t,[`vehicle`,`appearance`,`slots`],`player`),Le(t)}function ze(e,t){let n=T(e,t);j(n,{order:(e,t)=>A(e,[`ordered`,`any`],t),progress:(e,t)=>A(e,[`vehicle`,`scene`],t),event:D,stops:(e,t)=>{Array.isArray(e)&&e.length||w(t,`expected at least one stop`);let n=new Set;for(let[r,i]of e.entries()){let e;if(typeof i==`string`)e=D(i,`${t}.${r}`);else{let n=T(i,`${t}.${r}`);j(n,{target:D,when:De.when,dwellSeconds:N,maxSpeedMps:N},`${t}.${r}`),e=D(n.target,`${t}.${r}.target`)}n.has(e)&&w(t,`duplicate stop ${e}`),n.add(e)}}},t),E(n,`stops`)||w(`${t}.stops`,`expected at least one stop`)}function Be(e){return ze(e,`route`),structuredClone(e)}function Ve(e,t,n=[]){if(t===void 0||t===!0&&e&&typeof e==`object`&&!Array.isArray(e))return e;if(t&&typeof t==`object`&&!Array.isArray(t)){let r=T(t,`object`);n.length===2&&n[0]===`slots`&&r.action!==void 0&&e&&typeof e==`object`&&e.action!==r.action&&(e=void 0);let i={...e&&typeof e==`object`&&!Array.isArray(e)?e:{}};for(let[e,r]of Object.entries(t))[`__proto__`,`prototype`,`constructor`].includes(e)&&w(e,`reserved option name`),r!==void 0&&(i[e]=Ve(i[e],r,[...n,e]));return i}return t}function I(...e){let t={};for(let n of e){if(n==null)continue;let e={...T(n,`object`)};for(let t of[`trigger`])typeof e[t]==`string`&&(e[t]={preset:e[t]});t=Ve(t,e)}return structuredClone(t)}var He=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),Ue=e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),We=new Map,L=(e,t,n)=>We.set(`data-jr-${e}`,{path:t,kind:n});for(let e of[`solid`,`pushable`,`enabled`])L(e,[e],`boolean`);for(let e of[`id`,`object`])L(e,[e],`string`);for(let e of[`points`])L(e,[e],`number`);var Ge=new Set([M,N,oe,we.deformation]);function Ke(e,t,n){for(let[r,i]of Object.entries(n))L(`${e}-${Ue(r)}`,[...t,r],i===O?`boolean`:Ge.has(i)?`number`:`string`)}for(let[e,t]of Object.entries({breakable:be,burnable:xe,combustible:Se,crushable:Ce}))L(e,[e],`root`),Ke(e,[e],t);L(`crushed-class`,[`crushable`,`crushedClass`],`string`),L(`crushed-paint-color`,[`crushable`,`crushedPaintColor`],`string`),L(`liquid`,[`liquid`,`kind`],`string`);var{kind:qe,...Je}=we;Ke(`liquid`,[`liquid`],Je),L(`debris`,[`debris`],`root`);for(let e of[`anchor`,`color`])L(`debris-${e}`,[`debris`,e],`string`);for(let e of[`amount`,`spread`,`seed`,`glint`])L(`debris-${e}`,[`debris`,e],`number`);L(`debris-kinds`,[`debris`,`kinds`],`list`),L(`debris-wind-x`,[`debris`,`wind`,`x`],`number`),L(`debris-wind-y`,[`debris`,`wind`,`y`],`number`),L(`trigger`,[`trigger`],`root`),Ke(`trigger`,[`trigger`],De);var Ye=[...[`fps`,`speed`,`rpm`,`gear`,`health`,`points`].map(e=>`data-jr-hud-${e}`),`data-jr-hud-unit`,`data-jr-hud-precision`],Xe=Object.freeze([...We.keys(),...Ye]).map(e=>`[${e}]`).join(`,`);function Ze(e,t){return e===``||e===`true`||e!==`false`&&w(t,`use an empty marker, true, or false`)}function Qe(e,t,n,r){let i=e;for(let e=0;e<t.length-1;e++){let n=t[e],a=i[n];a===!1&&w(r,`options require an enabled capability`),a&&typeof a==`object`||(i[n]=typeof a==`string`?{preset:a}:{}),i=i[n]}i[t[t.length-1]]=n}function $e(e){let t={},n=!1,r={},i=!1,a=Array.from(e.attributes).sort((e,t)=>e.name.split(`-`).length-t.name.split(`-`).length);for(let{name:e,value:o}of a){if(Ye.includes(e)){n=!0;let t=e.slice(12);t===`unit`?r.unit=o:t===`precision`?(o.trim()&&Number.isFinite(Number(o))||w(e,`expected a finite number`),r.precision=Number(o)):Ze(o,e)?(r.field&&w(e,`one element can display only one HUD metric`),r.field=t):i=!0;continue}if(e.startsWith(`data-jr-meta-`)){let r=He(e.slice(13));(!r||[`__proto__`,`prototype`,`constructor`].includes(r))&&w(e,`invalid metadata key`),t.meta??={},t.meta[r]=o,n=!0;continue}let a=We.get(e);if(!a)continue;n=!0;let s=o;a.kind===`list`?s=o.split(/[\s,]+/).filter(Boolean):a.kind===`boolean`?s=Ze(o,e):a.kind===`number`?(o.trim()||w(e,`expected a number`),s=Number(o),Number.isFinite(s)||w(e,`expected a finite number`)):a.kind===`root`&&(s=o===``||o===`true`||o===`false`?Ze(o,e):e===`data-jr-debris`?{kinds:o.split(/[\s,]+/).filter(Boolean)}:o),Qe(t,a.path,s,e)}return Object.keys(r).length?t.hud=r:i&&(t.hud=!1),n?t:null}function et(e){return e&&typeof e==`object`&&(Object.values(e).forEach(et),Object.freeze(e)),e}function tt(e){let t=T(e,`definitions`);ie(t,[`liquids`,`vehicles`,`objects`,`routes`],`definitions`);for(let[e,n]of Object.entries(t)){if(n===void 0)continue;let t=T(n,`definitions.${e}`);for(let[n,r]of Object.entries(t)){let t=`definitions.${e}.${n}`;(!/^[a-z][a-z0-9-]{0,63}$/.test(n)||[`constructor`,`prototype`,`__proto__`].includes(n))&&w(t,`use a lowercase recipe name`);let i=T(r,t);if(e===`objects`)Fe(i);else if(e===`routes`)ze(i,t);else if(e===`liquids`)j(i,{base:D,color:ae,thickness:oe,opacity:oe,deformation:(e,t)=>k(e,t,0,4),conductive:O,burnable:O,burnLifetime:M,fireSpreadMps:M,effect:(e,t)=>{let n=T(e,t);j(n,{lifetime:(e,t)=>{let n=T(e,t);j(n,{unit:(e,t)=>A(e,[`seconds`,`distanceM`],t),amount:M},t),E(n,`unit`)&&E(n,`amount`)||w(t,`unit and amount are required`)},modifiers:(e,t)=>{for(let[n,r]of Object.entries(T(e,t)))N(r,`${t}.${n}`)},additiveModifiers:(e,t)=>{for(let[n,r]of Object.entries(T(e,t)))k(r,`${t}.${n}`,-1/0)},intensity:(e,t)=>A(e,[`linear`,`pulse`,`constant`],t)},t),E(n,`lifetime`)&&E(n,`modifiers`)||w(t,`lifetime and modifiers are required`)}},t),D(i.base,`${t}.base`);else{ie(i,`base.name.description.make.model.year.massKg.health.frontWeightFraction.geometry.exhaust.lights.roofRocket.machineGuns.flamethrower.rockets.lightning.sound.visual.engineForceN.reversePowerRatio.maxReverseSpeedMps.rollingResistance.coastDecelerationMps2.handbrakeDecelerationMps2.serviceBrakeDecelerationMps2.lateralResistance.corneringAccelerationMps2.maxSteerAngleRad.handbrakeStrength.drift.launch.driveBoost.image.appearance.slots`.split(`.`),t),D(i.base,`${t}.base`),E(i,`appearance`)&&se(i.appearance,`${t}.appearance`),E(i,`slots`)&&ke(i.slots,`${t}.slots`);for(let[e,n]of Object.entries(i))typeof n==`number`&&k(n,`${t}.${e}`,-1/0);Ae(Ve({},i),t)}}for(let n of Object.keys(t)){let r=new Set,i=n;for(;i&&Object.hasOwn(t,i);)r.has(i)&&w(`definitions.${e}.${n}.base`,`recipe inheritance contains a cycle`),r.add(i),i=t[i].base}}return et(structuredClone(e))}var nt=new URL(`../embed-assets/porsche-911-997-top-BE6uRNL4.webp`,import.meta.url).href,rt=new URL(`../embed-assets/ford-mustang-gt-top-DVzZTm7G.webp`,import.meta.url).href,it=new URL(`../embed-assets/bmw-m4-top-GKSf0h28.webp`,import.meta.url).href,at=new URL(`../embed-assets/jeep-wrangler-top-Dr43LU9c.webp`,import.meta.url).href,ot=new URL(`../embed-assets/subaru-wrx-top-dLvMFYDs.webp`,import.meta.url).href,st=new URL(`../embed-assets/audi-rs3-top-Zwm7ZQ20.webp`,import.meta.url).href,ct=new URL(`../embed-assets/lamborghini-huracan-evo-top-BCJJwrTj.webp`,import.meta.url).href,lt=new URL(`../embed-assets/electric-gt-top-DTcvEjMR.webp`,import.meta.url).href,ut={xM:-.22,revealM:.36,roundsPerSecond:11,bulletSpeedMps:72,bulletLifetimeSeconds:1.35};function dt(e){let t={...ut,...e.machineGuns},n=(e,t,n,r)=>Number.isFinite(e)?Math.max(n,Math.min(r,e)):t;return{xM:n(t.xM,ut.xM,-e.geometry.lengthM/2+.5,e.geometry.lengthM/2-.5),revealM:n(t.revealM,ut.revealM,.12,.5),roundsPerSecond:n(t.roundsPerSecond,ut.roundsPerSecond,2,20),bulletSpeedMps:n(t.bulletSpeedMps,ut.bulletSpeedMps,20,150),bulletLifetimeSeconds:n(t.bulletLifetimeSeconds,ut.bulletLifetimeSeconds,.25,3)}}var R={rangeM:6.5,ignitionSeconds:.45,spreadSeconds:2.2,spreadRadiusPx:24,burnSeconds:4,smokePerSecond:13,jetWidthM:.5,flowRate:1};function ft(e){let t={...R,...e.flamethrower},n=(e,t,n,r)=>Number.isFinite(e)?Math.max(n,Math.min(r,e)):t;return{rangeM:n(t.rangeM,R.rangeM,1,12),ignitionSeconds:n(t.ignitionSeconds,R.ignitionSeconds,.1,10),spreadSeconds:n(t.spreadSeconds,R.spreadSeconds,.5,30),spreadRadiusPx:n(t.spreadRadiusPx,R.spreadRadiusPx,0,96),burnSeconds:n(t.burnSeconds,R.burnSeconds,.5,30),smokePerSecond:n(t.smokePerSecond,R.smokePerSecond,0,50),jetWidthM:n(t.jetWidthM,R.jetWidthM,.2,.9),flowRate:n(t.flowRate,R.flowRate,.2,2)}}var pt={roundsPerSecond:1.25,launchSpeedMps:18,accelerationMps2:24,maxSpeedMps:44,lifetimeSeconds:3.1,smokePerSecond:22};function mt(e){let t={...pt,...e.rockets},n=(e,t,n,r)=>Number.isFinite(e)?Math.max(n,Math.min(r,e)):t;return{roundsPerSecond:n(t.roundsPerSecond,pt.roundsPerSecond,.25,5),launchSpeedMps:n(t.launchSpeedMps,pt.launchSpeedMps,5,60),accelerationMps2:n(t.accelerationMps2,pt.accelerationMps2,0,100),maxSpeedMps:n(t.maxSpeedMps,pt.maxSpeedMps,10,100),lifetimeSeconds:n(t.lifetimeSeconds,pt.lifetimeSeconds,.5,8),smokePerSecond:n(t.smokePerSecond,pt.smokePerSecond,0,60)}}function ht(e){return{headlights:{xM:e.geometry.lengthM*.4,yM:e.geometry.widthM*.3,...e.lights?.headlights},taillights:{xM:-e.geometry.lengthM*.43,yM:e.geometry.widthM*.3,...e.lights?.taillights}}}function gt(e){return e.serviceBrakeDecelerationMps2??12}var z={porsche911997:{id:`porsche-911-997`,name:`Porsche 911 (997)`,description:`A quick, responsive rear-engine 911 with a naturally aspirated flat-six sound profile.`,make:`Porsche`,model:`911 (997)`,year:`2004–2012`,massKg:1380,frontWeightFraction:.4,sound:{engineId:`flat6`,vehicleId:`sports`,engineLabel:`Simulated flat-six · 3.8 L`,horn:{lowHz:335,highHz:400,tone:`disc`,level:.88}},geometry:{lengthM:4.43,widthM:2.03,wheelbaseM:2.35,trackWidthM:1.68,frontTrackWidthM:1.62,rearTrackWidthM:1.74,tireLengthM:.67,tireWidthM:.29},exhaust:{layout:`left-right`},lights:{headlights:{xM:1.728,yM:.608},taillights:{xM:-1.927,yM:.649}},roofRocket:{xM:-.16,yM:0,sizeM:.76,panelColor:`#a8b0b3`},machineGuns:{xM:-.14},engineForceN:18500,reversePowerRatio:.72,rollingResistance:39,coastDecelerationMps2:4,handbrakeDecelerationMps2:10.5,lateralResistance:1750,corneringAccelerationMps2:40,maxSteerAngleRad:.67,handbrakeStrength:.68,drift:{entrySpeedMps:4.5,slipAngleRad:.3},launch:{minRpm:2200,boostMps:.6,boostedBoostMps:1.8,assistDurationSeconds:.7,burnoutRampSeconds:1.05,chargedSpinSeconds:1.35,fireLifetimeSeconds:5.3},driveBoost:{gainMps:5.2,durationSeconds:2.6,cooldownSeconds:2.2},image:{src:nt,crop:{x:90/1774,y:74/887,width:1602/1774,height:733/887},wheelEdgeHalfWidthM:{front:.885,rear:.944}}},fordMustangGt:{id:`ford-mustang-gt-2024`,name:`Ford Mustang GT`,description:`A burbling V8 muscle car with strong acceleration and a willing rear axle.`,make:`Ford`,model:`Mustang GT`,year:`2024`,massKg:1730,frontWeightFraction:.54,sound:{engineId:`v8cross`,vehicleId:`muscle`,engineLabel:`Simulated cross-plane V8 · 5.0 L`,horn:{lowHz:330,highHz:430,tone:`trumpet`,level:1}},visual:{color:`#cc6249`,shape:`coupe`},geometry:{lengthM:4.81,widthM:1.92,wheelbaseM:2.72,trackWidthM:1.59,tireLengthM:.72,tireWidthM:.3},exhaust:{layout:`left-right`},lights:{headlights:{xM:1.826,yM:.576},taillights:{xM:-1.998,yM:.538}},roofRocket:{xM:-.1,yM:0,sizeM:.82,panelColor:`#777d80`},engineForceN:19500,reversePowerRatio:.7,rollingResistance:42,coastDecelerationMps2:3.7,handbrakeDecelerationMps2:9.2,lateralResistance:1580,corneringAccelerationMps2:35,maxSteerAngleRad:.6,handbrakeStrength:.72,drift:{entrySpeedMps:4,slipAngleRad:.3},launch:{minRpm:2600,boostMps:.5,boostedBoostMps:1.6,assistDurationSeconds:.75,burnoutRampSeconds:1.2,chargedSpinSeconds:1.5,fireLifetimeSeconds:5.6},driveBoost:{gainMps:4.3,durationSeconds:2.8,cooldownSeconds:2.4},image:{src:rt,crop:{x:41/1774,y:64/887,width:1687/1774,height:754/887},wheelEdgeHalfWidthM:{front:.868,rear:.87}}},bmwM4:{id:`bmw-m4-2024`,name:`BMW M4`,description:`A quick turbo straight-six coupe that rotates cleanly and rewards precise countersteer.`,make:`BMW`,model:`M4`,year:`2024`,massKg:1750,frontWeightFraction:.52,sound:{engineId:`i6`,vehicleId:`sports`,engineLabel:`Simulated turbo inline-six · 3.0 L`,turbo:!0,horn:{lowHz:345,highHz:415,tone:`disc`,level:.86}},visual:{color:`#587d9a`,shape:`coupe`},geometry:{lengthM:4.79,widthM:1.89,wheelbaseM:2.86,trackWidthM:1.54,tireLengthM:.71,tireWidthM:.29},exhaust:{layout:`left-right`},lights:{headlights:{xM:1.876,yM:.661},taillights:{xM:-1.941,yM:.661}},roofRocket:{xM:-.12,yM:0,sizeM:.8,panelColor:`#6c7d88`},engineForceN:22500,reversePowerRatio:.72,rollingResistance:42,coastDecelerationMps2:4.2,handbrakeDecelerationMps2:10,lateralResistance:1900,corneringAccelerationMps2:39,maxSteerAngleRad:.64,handbrakeStrength:.65,drift:{entrySpeedMps:4.5,slipAngleRad:.3},launch:{minRpm:2300,boostMps:.7,boostedBoostMps:1.8,assistDurationSeconds:.7,burnoutRampSeconds:1.1,chargedSpinSeconds:1.35,fireLifetimeSeconds:5.1},driveBoost:{gainMps:4.8,durationSeconds:2.6,cooldownSeconds:2.3},image:{src:it,crop:{x:22/1774,y:47/887,width:1731/1774,height:795/887},scale:1.06,wheelEdgeHalfWidthM:{front:.842,rear:.851}}},jeepWrangler:{id:`jeep-wrangler-2026`,name:`Jeep Wrangler`,description:`A tall, heavy four-door SUV with deliberate steering and a wide, steady slide.`,make:`Jeep`,model:`Wrangler`,year:`2026`,massKg:2050,frontWeightFraction:.53,sound:{engineId:`v6`,vehicleId:`truck`,engineLabel:`Simulated V6 · 3.6 L`,horn:{lowHz:300,highHz:400,tone:`trumpet`,level:1}},visual:{color:`#7d8060`,shape:`suv`},geometry:{lengthM:4.78,widthM:1.88,wheelbaseM:3.01,trackWidthM:1.58,tireLengthM:.76,tireWidthM:.32},exhaust:{layout:`right`},lights:{headlights:{xM:1.818,yM:.645},taillights:{xM:-1.947,yM:.645}},roofRocket:{xM:0,yM:0,sizeM:.9,panelColor:`#777a65`},engineForceN:12500,reversePowerRatio:.73,rollingResistance:58,coastDecelerationMps2:4.8,handbrakeDecelerationMps2:11.5,lateralResistance:1850,corneringAccelerationMps2:28,maxSteerAngleRad:.53,handbrakeStrength:.64,drift:{entrySpeedMps:4.2,slipAngleRad:.3},launch:{minRpm:2200,boostMps:0,boostedBoostMps:.8,assistDurationSeconds:.8,burnoutRampSeconds:1.35,chargedSpinSeconds:1.65,fireLifetimeSeconds:5.8},driveBoost:{gainMps:2.8,durationSeconds:3,cooldownSeconds:2.7},image:{src:at,crop:{x:52/1774,y:47/887,width:1720/1774,height:786/887},scale:1.04,wheelEdgeHalfWidthM:{front:.869,rear:.874}}},subaruWrx:{id:`subaru-wrx-2024`,name:`Subaru WRX`,description:`A compact turbo boxer sedan with brisk turn-in and a playful handbrake slide.`,make:`Subaru`,model:`WRX`,year:`2024`,massKg:1550,frontWeightFraction:.54,sound:{engineId:`boxer4`,vehicleId:`sports`,engineLabel:`Simulated turbo flat-four · 2.4 L`,turbo:!0,horn:{lowHz:370,highHz:450,tone:`disc`,level:.88}},visual:{color:`#547aaf`,shape:`sedan`},geometry:{lengthM:4.67,widthM:1.83,wheelbaseM:2.67,trackWidthM:1.48,tireLengthM:.69,tireWidthM:.27},exhaust:{layout:`left-right`},lights:{headlights:{xM:1.665,yM:.635},taillights:{xM:-1.784,yM:.616}},roofRocket:{xM:-.1,yM:0,sizeM:.78,panelColor:`#60758d`},engineForceN:16600,reversePowerRatio:.73,rollingResistance:39,coastDecelerationMps2:4,handbrakeDecelerationMps2:10,lateralResistance:1740,corneringAccelerationMps2:38,maxSteerAngleRad:.65,handbrakeStrength:.69,drift:{entrySpeedMps:4,slipAngleRad:.3},launch:{minRpm:2400,boostMps:.4,boostedBoostMps:1.3,assistDurationSeconds:.7,burnoutRampSeconds:1.1,chargedSpinSeconds:1.25,fireLifetimeSeconds:4.8},driveBoost:{gainMps:3.8,durationSeconds:2.8,cooldownSeconds:2.4},image:{src:ot,crop:{x:45/1774,y:48/887,width:1684/1774,height:793/887},scale:1.02,wheelEdgeHalfWidthM:{front:.801,rear:.811}}},audiRs3:{id:`audi-rs3-2024`,name:`Audi RS 3`,description:`A sharp five-cylinder sport sedan with punchy acceleration and fast grip recovery.`,make:`Audi`,model:`RS 3`,year:`2024`,massKg:1580,frontWeightFraction:.57,sound:{engineId:`i5`,vehicleId:`sports`,engineLabel:`Simulated turbo inline-five · 2.5 L`,turbo:!0,horn:{lowHz:400,highHz:500,tone:`disc`,level:.91}},visual:{color:`#5e7275`,shape:`sedan`},geometry:{lengthM:4.54,widthM:1.85,wheelbaseM:2.63,trackWidthM:1.52,tireLengthM:.7,tireWidthM:.28},exhaust:{layout:`left-right`},lights:{headlights:{xM:1.64,yM:.61},taillights:{xM:-1.738,yM:.61}},roofRocket:{xM:-.12,yM:0,sizeM:.76,panelColor:`#667377`},engineForceN:21e3,reversePowerRatio:.72,rollingResistance:40,coastDecelerationMps2:4.4,handbrakeDecelerationMps2:10.4,lateralResistance:1950,corneringAccelerationMps2:40,maxSteerAngleRad:.63,handbrakeStrength:.66,drift:{entrySpeedMps:4.5,slipAngleRad:.3},launch:{minRpm:2200,boostMps:.6,boostedBoostMps:1.7,assistDurationSeconds:.7,burnoutRampSeconds:1.05,chargedSpinSeconds:1.35,fireLifetimeSeconds:5.1},driveBoost:{gainMps:4.3,durationSeconds:2.7,cooldownSeconds:2.3},image:{src:st,crop:{x:38/1774,y:34/887,width:1699/1774,height:805/887},wheelEdgeHalfWidthM:{front:.826,rear:.83}}},lamborghiniHuracanEvo:{id:`lamborghini-huracan-evo-2023`,name:`Lamborghini Huracán EVO`,description:`A low V10 supercar with fierce acceleration, quick response, and a high-revving voice.`,make:`Lamborghini`,model:`Huracán EVO`,year:`2023`,massKg:1450,frontWeightFraction:.43,sound:{engineId:`v10`,vehicleId:`supercar`,engineLabel:`Simulated V10 · 5.2 L`,horn:{lowHz:405,highHz:515,tone:`trumpet`,level:.92}},visual:{color:`#e0a84b`,shape:`supercar`},geometry:{lengthM:4.52,widthM:1.93,wheelbaseM:2.62,trackWidthM:1.49,frontTrackWidthM:1.43,rearTrackWidthM:1.54,tireLengthM:.69,tireWidthM:.3},exhaust:{layout:`center`},lights:{headlights:{xM:1.567,yM:.675},taillights:{xM:-1.72,yM:.695}},roofRocket:{xM:-.16,yM:0,sizeM:.7,panelColor:`#b79c57`},engineForceN:26500,reversePowerRatio:.68,rollingResistance:43,coastDecelerationMps2:4.7,handbrakeDecelerationMps2:11,lateralResistance:2250,corneringAccelerationMps2:44,maxSteerAngleRad:.63,handbrakeStrength:.7,drift:{entrySpeedMps:5,slipAngleRad:.3},launch:{minRpm:2800,boostMps:.9,boostedBoostMps:2.1,assistDurationSeconds:.65,burnoutRampSeconds:.95,chargedSpinSeconds:1.5,fireLifetimeSeconds:5.6},driveBoost:{gainMps:5.7,durationSeconds:2.5,cooldownSeconds:2.1},image:{src:ct,crop:{x:46/1774,y:13/887,width:1687/1774,height:852/887},wheelEdgeHalfWidthM:{front:.792,rear:.847}}},electricGt:{id:`electric-gt`,name:`Joy Ride Electric GT`,description:`An original electric fastback with instant response and a soft, choir-like low-speed warning tone.`,make:`Joy Ride`,model:`Electric GT`,year:`2026`,massKg:1850,frontWeightFraction:.5,sound:{engineId:`i4`,vehicleId:`sports`,engineLabel:`Procedural electric motor + choir-like warning tone`,electric:{fadeStartMps:20/3.6,fadeEndMps:30/3.6,motorFadeStartMps:120/3.6,motorFadeEndMps:50},horn:{lowHz:420,highHz:500,tone:`electronic`,level:.8}},visual:{color:`#dce9ed`,shape:`sedan`},geometry:{lengthM:4.75,widthM:1.9,wheelbaseM:2.88,trackWidthM:1.59,tireLengthM:.7,tireWidthM:.29},exhaust:{layout:`center`},lights:{headlights:{xM:1.964,yM:.665},taillights:{xM:-2.008,yM:.705}},roofRocket:{xM:-.12,yM:0,sizeM:.8,panelColor:`#b9cbd1`},engineForceN:23e3,reversePowerRatio:.68,rollingResistance:42,coastDecelerationMps2:4.8,handbrakeDecelerationMps2:10.5,lateralResistance:1940,corneringAccelerationMps2:37,maxSteerAngleRad:.63,handbrakeStrength:.69,drift:{entrySpeedMps:4.4,slipAngleRad:.3},launch:{minRpm:0,boostMps:0,boostedBoostMps:1.4,assistDurationSeconds:.65,burnoutRampSeconds:.95,chargedSpinSeconds:1.3,fireLifetimeSeconds:4.6},driveBoost:{gainMps:4.5,durationSeconds:2.6,cooldownSeconds:2.2},image:{src:lt,crop:{x:31/1774,y:50/887,width:1713/1774,height:773/887},scale:1.06,wheelEdgeHalfWidthM:{front:.86,rear:.858}}}};function _t(e){return e.geometry.wheelbaseM/Math.tan(e.maxSteerAngleRad)}var vt=`joy-ride:vehicles:v1`,yt=Object.values(z);function bt(){try{if(typeof localStorage>`u`)return[];let e=JSON.parse(localStorage.getItem(vt)??`[]`);return Array.isArray(e)?e.flatMap(e=>{try{return[Et(e)]}catch{return[]}}):[]}catch{return[]}}function xt(){let e=bt();return[...yt.map(t=>e.find(e=>e.id===t.id)??t),...e.filter(e=>Ct(e.id))]}function St(e){return xt().find(t=>t.id===e)}function Ct(e){return e.startsWith(`custom-`)}function wt(e){return yt.some(t=>t.id===e)&&bt().some(t=>t.id===e)}function Tt(e){let t=globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;return{...structuredClone(e),id:`custom-${t}`,name:`${e.name} Custom`}}function B(e,t,n){return typeof e==`number`&&Number.isFinite(e)&&e>=t&&e<=n}function Et(e){if(!e||typeof e!=`object`)throw Error(`Invalid vehicle file.`);let t={...e},n=t.geometry;if(typeof t.id!=`string`||!(Ct(t.id)||yt.some(e=>e.id===t.id))||t.id.length>100||typeof t.name!=`string`||!t.name.trim()||t.name.length>100||typeof t.description!=`string`||!n||!t.roofRocket||!t.sound||!t.sound.horn||!t.exhaust||!t.drift||!t.launch||!t.driveBoost||typeof t.sound.engineId!=`string`||!t.sound.engineId||typeof t.sound.vehicleId!=`string`||!t.sound.vehicleId||typeof t.sound.engineLabel!=`string`||![`left`,`right`,`center`,`left-right`].includes(t.exhaust.layout)||!B(t.massKg,50,1e4)||!B(n.lengthM,1,15)||!B(n.widthM,.5,6)||!B(n.wheelbaseM,.5,n.lengthM)||!B(n.trackWidthM,.3,n.widthM)||!B(n.tireLengthM,.1,2)||!B(n.tireWidthM,.05,1)||!B(t.engineForceN,100,1e5)||!B(t.rollingResistance,.1,1e4)||!B(t.maxSteerAngleRad,.05,1.4)||!B(t.roofRocket.xM,-n.lengthM/2,n.lengthM/2)||!B(t.roofRocket.yM,-n.widthM/2,n.widthM/2)||!B(t.roofRocket.sizeM,.1,n.widthM)||t.image&&(!/^(data:image\/(?:png|webp|jpeg);base64,|https?:\/\/|\/)/i.test(t.image.src)||t.image.src.length>3e6))throw Error(`Invalid vehicle geometry or settings.`);if([[t.reversePowerRatio,.05,2],[t.coastDecelerationMps2,0,30],[t.handbrakeDecelerationMps2,0,30],[t.lateralResistance,1,1e4],[t.corneringAccelerationMps2,1,100],[t.handbrakeStrength,0,2],[t.drift.entrySpeedMps,.2,30],[t.drift.slipAngleRad,.05,1.2],[t.launch.minRpm,0,12e3],[t.launch.boostMps,0,20],[t.launch.boostedBoostMps,0,30],[t.launch.assistDurationSeconds,.05,10],[t.launch.burnoutRampSeconds,.1,10],[t.launch.chargedSpinSeconds,0,20],[t.launch.fireLifetimeSeconds,0,30],[t.driveBoost.gainMps,0,30],[t.driveBoost.durationSeconds,.05,10],[t.driveBoost.cooldownSeconds,0,30],[t.sound.horn.lowHz,80,1200],[t.sound.horn.highHz,80,1600],[t.sound.horn.level,0,2]].some(([e,t,n])=>!B(e,t,n))||![`disc`,`trumpet`,`electronic`].includes(t.sound.horn.tone)||t.frontWeightFraction!==void 0&&!B(t.frontWeightFraction,.1,.9)||t.maxReverseSpeedMps!==void 0&&!B(t.maxReverseSpeedMps,1,30)||t.health!==void 0&&!B(t.health,1,1e4)||n.frontTrackWidthM!==void 0&&!B(n.frontTrackWidthM,.3,n.widthM)||n.rearTrackWidthM!==void 0&&!B(n.rearTrackWidthM,.3,n.widthM)||t.image?.scale!==void 0&&!B(t.image.scale,.5,1.5))throw Error(`Invalid vehicle tuning.`);let r=t.image?.crop;if(t.lightning!==void 0){if(!t.lightning||typeof t.lightning!=`object`||Array.isArray(t.lightning))throw Error(`Invalid lightning settings.`);let e={rangeM:[1,30],forwardBias:[0,4],chargeSeconds:[.1,10],statusSeconds:[.1,30],speedFactor:[.1,1],impactRadiusM:[.1,10],damage:[0,1e4],impulse:[0,4]};for(let[n,r]of Object.entries(t.lightning))if(n===`ignite`){if(typeof r!=`boolean`)throw Error(`Invalid lightning ignition.`)}else if(!e[n]||!B(r,...e[n]))throw Error(`Invalid lightning settings.`)}if(t.lights!==void 0){if(!t.lights||typeof t.lights!=`object`||Array.isArray(t.lights))throw Error(`Invalid vehicle light points.`);for(let e of[`headlights`,`taillights`]){let r=t.lights[e];if(r!==void 0&&(!r||!B(r.xM,-n.lengthM/2,n.lengthM/2)||!B(r.yM,0,n.widthM/2)))throw Error(`Invalid vehicle light points.`)}}if(r&&(!B(r.x,0,1)||!B(r.y,0,1)||!B(r.width,.01,1)||!B(r.height,.01,1)||r.x+r.width>1.001||r.y+r.height>1.001))throw Error(`Invalid vehicle image crop.`);if(n.frontAxleXM!==void 0&&!B(n.frontAxleXM,-n.lengthM/2,n.lengthM/2))throw Error(`Invalid front axle.`);if(n.rearAxleXM!==void 0&&!B(n.rearAxleXM,-n.lengthM/2,n.lengthM/2))throw Error(`Invalid rear axle.`);let i=e=>typeof e==`number`?Number.isFinite(e):e===null||typeof e==`boolean`||typeof e==`string`||typeof e==`object`&&Object.values(e).every(i);if(!i(t))throw Error(`Invalid vehicle settings.`);return t}function Dt(e){let t=Et(e);if(typeof localStorage>`u`)throw Error(`Browser storage is unavailable.`);let n=bt().filter(e=>e.id!==t.id);return n.push(t),localStorage.setItem(vt,JSON.stringify(n)),typeof window<`u`&&window.dispatchEvent(new Event(`joy-ride:vehicles-changed`)),t}function Ot(e){(Ct(e)||yt.some(t=>t.id===e))&&typeof localStorage<`u`&&(localStorage.setItem(vt,JSON.stringify(bt().filter(t=>t.id!==e))),typeof window<`u`&&window.dispatchEvent(new Event(`joy-ride:vehicles-changed`)))}function kt(){return xt().map(({id:e,name:t,make:n,model:r,year:i,image:a})=>({id:e,name:t,make:n,model:r,year:i,image:a?.src}))}var At=Object.freeze({underglow:!1,underglowColor:`#66e6ff`,underglowOpacity:.6,headlights:!0,taillights:!0,brakeLights:!0});function jt(e={}){return{underglow:typeof e.underglow==`boolean`?e.underglow:At.underglow,underglowColor:/^#[\da-f]{6}$/i.test(e.underglowColor??``)?e.underglowColor:At.underglowColor,underglowOpacity:Number.isFinite(e.underglowOpacity)?Math.max(0,Math.min(1,e.underglowOpacity)):At.underglowOpacity,headlights:typeof e.headlights==`boolean`?e.headlights:At.headlights,brakeLights:typeof e.brakeLights==`boolean`?e.brakeLights:At.brakeLights,taillights:typeof e.taillights==`boolean`?e.taillights:At.taillights}}var V=[{id:`boost`,label:`Boost`,keys:[`Shift`],description:`Burn rear tracks while held`,sfw:!0,weapon:!1},{id:`eject`,label:`Liquid`,keys:[`1`],description:`Pour while held`,sfw:!0,weapon:!1},{id:`machineGun`,label:`Machine guns`,keys:[`2`],description:`Fire while held`,sfw:!1,weapon:!0},{id:`flamethrower`,label:`Flamethrower`,keys:[`3`],description:`Burn objects while held`,sfw:!0,weapon:!0},{id:`rocket`,label:`Roof rockets`,keys:[`4`],description:`Launch, then repeat while held`,sfw:!1,weapon:!0},{id:`ghost`,label:`Ghost mode`,keys:[`5`],description:`Phase while held`,sfw:!0,weapon:!1},{id:`attractor`,label:`Attractor`,keys:[`6`],description:`Pull nearby letters and debris`,sfw:!0,weapon:!1},{id:`lightning`,label:`Lightning`,keys:[`7`],description:`Hold to charge; discharge when the reserve empties`,sfw:!0,weapon:!0}];function Mt(e=y,t={}){let n=t.enabledTools,r=[];for(let i of g){let a=e[i];!a||n&&!n.includes(a.action)||t.weaponsEnabled===!1&&V.some(e=>e.id===a.action&&e.weapon)||r.push({number:g[r.length],source:i,slot:a})}return r}function Nt(e,t=!0,n=y){let r=Mt(n,{enabledTools:e,weaponsEnabled:t});return V.filter(n=>e.includes(n.id)&&(t||!n.weapon)).map(e=>({...e,keys:[...e.id===`boost`?[`Shift`]:[],...r.filter(({slot:t})=>t.action===e.id).map(({number:e})=>String(e))]}))}var Pt=V.map(e=>e.id);function Ft(e,t=Pt,n=!0){let r=e;for(let i of V)(!t.includes(i.id)||!n&&i.weapon)&&(r===e&&(r={...e}),r[i.id]=!1);return r.ghost&&(r===e&&(r={...e}),r.boost=r.eject=r.machineGun=r.flamethrower=r.rocket=r.attractor=r.lightning=!1),r}function It(e){if(e&&typeof e==`object`&&!(typeof Node<`u`&&e instanceof Node)){for(let t of Object.values(e))It(t);Object.freeze(e)}return e}var Lt=[`vehicle`,`objects`,`weapons`,`controls`,`ai`,`settings`,`embed`,`documentation`],Rt={showHud:!1,showHealthBars:!0,showWeaponBar:!0,showLogo:!0,showGithub:!0,allowVehicleEditing:!0,vehicleTabs:Lt,vehicleDestructible:!0,weaponsEnabled:!0,enabledTools:V.map(e=>e.id)},zt={...Rt,showHud:!1,showHealthBars:!1,showWeaponBar:!1,showLogo:!1,showGithub:!1,allowVehicleEditing:!1,vehicleTabs:[`vehicle`,`weapons`,`controls`],vehicleDestructible:!1,enabledTools:V.filter(e=>e.sfw).map(e=>e.id),brandColor:`#000000`,brandName:`Vehicle settings`};function Bt(e={}){let t={...e.workMode?.sfw?zt:Rt};for(let n of[e.workMode,e])if(n)for(let e of Object.keys({...Rt,brandColor:void 0,brandName:void 0})){let r=n[e];r!==void 0&&Object.assign(t,{[e]:r})}return t.vehicleTabs=[...new Set(t.vehicleTabs)],t.enabledTools=[...new Set(t.enabledTools)],t}var Vt=It({lighting:jt(),masterVolume:1,idleSound:!0,quality:`high`,smokeTint:`natural`,surfaceTone:`auto`,debug:!1,sparks:!0,deform:!0,screenShake:!0,showHud:!1,showTotalPoints:!0,showHealthBars:!0,showVehicleMarkers:!0,showWeaponBar:!0,showLogo:!0,showGithub:!0,allowVehicleEditing:!0,vehicleTabs:Lt,weaponCooldown:!0,autoPaint:!1,rocketBlastStrength:1,viewportWalls:!0,viewportMode:`absolute`,speedZoom:`auto`,vehicleDestructible:!0,weaponsEnabled:!0,enabledTools:V.map(e=>e.id)}),Ht={policy:{vehicleDestructible:!1,enabledTools:V.filter(e=>e.sfw).map(e=>e.id)},ui:{showHealthBars:!1,showWeaponBar:!1,showLogo:!1,showGithub:!1,allowVehicleEditing:!1,vehicleTabs:[`vehicle`,`weapons`,`controls`],brandColor:`#000000`,brandName:`Vehicle settings`}},Ut={audio:[`masterVolume`,`idleSound`],rendering:[`quality`,`smokeTint`,`sparks`,`deform`,`screenShake`,`surfaceTone`,`debug`],policy:[`weaponCooldown`,`vehicleDestructible`,`weaponsEnabled`,`enabledTools`,`rocketBlastStrength`],ui:[`showHud`,`showTotalPoints`,`showHealthBars`,`showVehicleMarkers`,`showWeaponBar`,`showLogo`,`showGithub`,`allowVehicleEditing`,`vehicleTabs`,`brandColor`,`brandName`],camera:[`viewportWalls`,`viewportMode`,`speedZoom`]};function Wt(e){let t={lighting:jt(e.lighting),autoPaint:e.autoPaint??!1};for(let[n,r]of Object.entries(Ut))t[n]=Object.fromEntries(r.map(t=>[t,e[t]]));return It(structuredClone(t))}function Gt(e,t){if(!t||typeof t!=`object`||Array.isArray(t))throw TypeError(`Runtime options must be an object`);let n=structuredClone(e),r=new Set([...Object.keys(Ut),`lighting`,`autoPaint`]);for(let e of Object.keys(t))if(!r.has(e))throw TypeError(`Unknown runtime option: ${e}`);for(let[e,r]of Object.entries(Ut)){let i=t[e];if(i!==void 0){if(!i||typeof i!=`object`||Array.isArray(i))throw TypeError(`options.${e} must be an object`);for(let[t,a]of Object.entries(i)){if(!r.includes(t))throw TypeError(`Unknown option: ${e}.${t}`);a!==void 0&&(n[t]=structuredClone(a))}}}if(t.lighting!==void 0){if(!t.lighting||typeof t.lighting!=`object`)throw TypeError(`Lighting options must be an object`);for(let[e,n]of Object.entries(t.lighting)){let t=jt()[e];if(t===void 0||typeof n!=typeof t)throw TypeError(`Invalid lighting option: ${e}`);if(e===`underglowColor`&&!/^#[\da-f]{6}$/i.test(n))throw TypeError(`Underglow color must be six-digit hex`);if(e===`underglowOpacity`&&(!Number.isFinite(n)||n<0||n>1))throw RangeError(`Underglow opacity must be between 0 and 1`)}n.lighting=jt({...n.lighting,...t.lighting})}t.autoPaint!==void 0&&(n.autoPaint=t.autoPaint);for(let[e,t]of Object.entries(n))if(typeof Vt[e]==`boolean`&&typeof t!=`boolean`)throw TypeError(`${e} must be a boolean`);if(!Array.isArray(n.vehicleTabs)||n.vehicleTabs.some(e=>!Lt.includes(e)))throw TypeError(`Unknown vehicle tab`);for(let e of[`brandColor`,`brandName`])if(n[e]!==void 0&&typeof n[e]!=`string`)throw TypeError(`${e} must be a string`);for(let[e,t]of Object.entries({quality:[`low`,`medium`,`high`],smokeTint:[`natural`,`cyan`,`magenta`],surfaceTone:[`auto`,`light`,`dark`]}))if(!t.includes(n[e]))throw TypeError(`Invalid ${e}`);if(n.speedZoom!==`auto`&&typeof n.speedZoom!=`boolean`)throw TypeError(`Invalid speedZoom`);if(n.viewportMode!==`fixed`&&n.viewportMode!==`absolute`)throw TypeError(`Invalid viewportMode`);for(let[e,t,r]of[[`masterVolume`,0,1],[`rocketBlastStrength`,0,10]])if(!Number.isFinite(n[e])||n[e]<t||n[e]>r)throw RangeError(`${e} must be between ${t} and ${r}`);if(!Array.isArray(n.enabledTools)||n.enabledTools.some(e=>!V.some(t=>t.id===e)))throw TypeError(`Unknown enabled vehicle tool`);return n}var Kt=class extends Error{code=`JR_NON_SERIALIZABLE_DEPENDENCY`;dependencies;constructor(e){super(`Configuration cannot be exported: ${e.map(({path:e,reason:t})=>`${e}: ${t}`).join(`; `)}`),this.name=`NonSerializableDependencyError`,this.dependencies=Object.freeze(e.map(e=>Object.freeze({...e})))}};function qt(e,t,n,r=new Set){if(e===null||typeof e==`string`||typeof e==`boolean`||e===void 0||typeof e==`number`&&Number.isFinite(e))return;if(typeof e!=`object`){n.push({path:t,reason:`only finite JSON values can be exported`});return}if(r.has(e)){n.push({path:t,reason:`cyclic references cannot be exported`});return}let i=Object.getPrototypeOf(e);if(!Array.isArray(e)&&i!==null&&Object.getPrototypeOf(i)!==null)n.push({path:t,reason:`DOM references and strategy instances are not serializable`});else{r.add(e);for(let[i,a]of Object.entries(e))qt(a,`${t}.${i}`,n,r);r.delete(e)}}function Jt(e){return e&&typeof e==`object`&&(Object.values(e).forEach(Jt),Object.freeze(e)),e}function Yt(e){let t=[];if(qt(e,`configuration`,t),t.length)throw new Kt(t);for(let t of Object.keys(e))if(![`root`,`definitions`,`player`,`bindings`,`routes`,`options`].includes(t))throw TypeError(`Unknown playground configuration field: ${t}`);if(e.root!==void 0&&(typeof e.root!=`string`||!e.root.trim()))throw TypeError(`Configuration root must be a selector string`);let n=tt(e.definitions??{}),r=e.player===void 0?void 0:Re(e.player),i=e.bindings?.map((e,t)=>{if(typeof e.target!=`string`||!e.target.trim())throw new Kt([{path:`bindings.${t}.target`,reason:`use a selector instead of an element reference`}]);return{target:e.target,spec:Pe(e.spec)}}),a=e.routes&&Object.fromEntries(Object.entries(e.routes).map(([e,t])=>[e,Be(t)])),o=e.options===void 0?void 0:Wt(Gt(Vt,e.options));return Jt(structuredClone({...e,definitions:n,player:r,bindings:i,routes:a,options:o,format:`joy-ride-playground`,version:1}))}function Xt(e){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`Expected a playground configuration`);let t=e;if(t.format!==`joy-ride-playground`||t.version!==1)throw TypeError(`Unsupported playground configuration format or version`);for(let e of Object.keys(t))if(![`format`,`version`,`root`,`definitions`,`player`,`bindings`,`routes`,`options`].includes(e))throw TypeError(`Unknown playground configuration field: ${e}`);let{format:n,version:r,...i}=t;return Yt(i)}function Zt(e){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`Recording needs a portable vehicle configuration`);let t=e,n=[];if(qt(t,`vehicle`,n),n.length)throw new Kt(n);for(let e of Object.keys(t))if(![`preset`,`appearance`,`slots`,`liquids`].includes(e))throw TypeError(`Unknown recorded vehicle field: ${e}`);if(t.appearance===void 0||t.slots===void 0||t.liquids===void 0)throw TypeError(`Recording needs appearance, slots, and material definitions`);let r=Et(t.preset),i=Le({vehicle:r.id,appearance:t.appearance,slots:t.slots}),a=tt({liquids:t.liquids});return Jt({preset:r,appearance:i.appearance,slots:i.slots,liquids:a.liquids??{}})}function Qt(e,t){return{lifetime:{unit:`seconds`,amount:1},modifiers:{driveForce:1.08,grip:1.04},additiveModifiers:{forwardAccelerationMps2:e/Math.max(.1,t)}}}var $t={oil:{lifetime:{unit:`distanceM`,amount:i.oil.effectDistanceM},modifiers:{grip:i.oil.minimumGrip}},mud:{lifetime:{unit:`distanceM`,amount:i.mud.effectDistanceM},modifiers:{grip:i.mud.minimumGrip,speed:i.mud.speedFactor,driveForce:i.mud.driveForceFactor}}},en={mud:{grip:i.mud.contactGrip,speed:i.mud.contactSpeedFactor,driveForce:i.mud.contactDriveForceFactor}};function tn(e,t=0){let n=e.definition.lifetime.unit===`seconds`?Math.max(0,e.remaining-t):e.remaining,r=Math.min(1,n/e.definition.lifetime.amount);return e.definition.intensity===`constant`?+(n>0):e.definition.intensity===`pulse`?Math.sin(Math.PI*(1-r)):r}var nn=class{active=new Map;contacts=new Map;captureState(){return P({active:this.active,contacts:this.contacts})}restoreState(e){let t=P(e);this.active=t.active,this.contacts=t.contacts}setContacts(e,t,n){n.length?this.contacts.set(e,new Map(n.map(e=>[e,t]))):this.contacts.delete(e)}apply(e,t,n){if(t.lifetime.amount<=0)return;let r=this.active.get(e);r||(r=new Map,this.active.set(e,r)),r.set(n??`vehicle`,{remaining:t.lifetime.amount,definition:t})}remaining(e,t){let n=this.active.get(e);return t===void 0?Math.max(0,...[...n?.values()??[]].map(e=>e.remaining)):n?.get(t)?.remaining??0}remove(e){this.active.delete(e)}bonus(e,t,n=4,r=0){if(t===void 0){let t=0;for(let i=0;i<n;i++)t+=this.bonus(e,i,n,r);return t/n}let i=0;for(let n of this.active.values())for(let a of[`vehicle`,t]){let t=n.get(a);i+=(t?.definition.additiveModifiers?.[e]??0)*(t?tn(t,r):0)}return i}indicators(){return[...new Set([...this.active.keys(),...this.contacts.keys()])].map(e=>{let t=this.active.get(e),n=Math.max(0,...[...t?.values()??[]].map(e=>Math.min(1,e.remaining/e.definition.lifetime.amount)));return{label:e.charAt(0).toUpperCase()+e.slice(1),fraction:this.contacts.has(e)?1:n}})}factor(e,t,n=4){return this.factorFrom(null,e,t,n)}factorFrom(e,t,n,r=4){if(n===void 0){let n=0;for(let i=0;i<r;i++)n+=this.factorFrom(e,t,i);return n/r}let i=1;for(let[r,a]of this.active)for(let o of[`vehicle`,n]){if(e!==null&&r!==e)continue;let n=a.get(o),s=n?.definition.modifiers[t];if(n&&s!==void 0){let e=tn(n);i*=1+(s-1)*e}}for(let[r,a]of this.contacts)for(let o of[`vehicle`,n])(e===null||r===e)&&(i*=a.get(o)?.[t]??1);return i}advance(e,t){for(let[n,r]of this.active){for(let[n,i]of r){let a=i.definition.lifetime.unit===`distanceM`?e:t;i.remaining=Math.max(0,i.remaining-Math.max(0,a)),i.remaining===0&&r.delete(n)}r.size===0&&this.active.delete(n)}}clearTire(e){for(let[t,n]of this.active)n.delete(e),n.size===0&&this.active.delete(t);for(let[t,n]of this.contacts)n.delete(e),n.size===0&&this.contacts.delete(t)}clear(){this.active.clear(),this.contacts.clear()}},H={defaultHealth:100,smokeFraction:.5,smoulderFraction:.35,ignitionFraction:.25,damagePerSecond:48,burnDownSeconds:8,impactDamagePerMps:3.5,explosionSeconds:.8,fireballSeconds:.38,blastRadiusPx:78},rn={pixelsPerTenPoints:2500,minimum:10,maximum:1e3};function an(e,t,n){let r=Math.max(0,t)*Math.max(0,n);return gn(e,`data-jr-points`,Math.min(rn.maximum,Math.max(rn.minimum,Math.round(r/rn.pixelsPerTenPoints)*10)))}var on=class{maxHealth;health;explodedAt=null;blastQueued=!1;blastAge=0;lastBlastEmission=-1/0;lastDamageAt=-1/0;healthBarShownAt=-1/0;constructor(e=H.defaultHealth){this.maxHealth=e,this.maxHealth=Math.max(1,e),this.health=this.maxHealth}get stage(){return cn(this.health,this.maxHealth)}get healthFraction(){return this.health/this.maxHealth}resetBurnable(e=this.maxHealth){let t=this.health!==Math.max(1,e);this.maxHealth=Math.max(1,e),this.health=this.maxHealth,this.explodedAt=null,this.blastQueued=!1,this.blastAge=0,this.lastBlastEmission=-1/0,this.lastDamageAt=t?performance.now():-1/0,this.healthBarShownAt=this.lastDamageAt}damage(e,t=performance.now()){return this.explodedAt!==null||!Number.isFinite(e)||e<=0||(this.health=Math.max(0,this.health-e),t-this.lastDamageAt>=2900&&(this.healthBarShownAt=t),this.lastDamageAt=t,this.health>0)?!1:(this.explodedAt=t,!0)}healthBarAlpha(e=performance.now()){let t=e-this.lastDamageAt;return this.stage===`burning`&&this.health>0?Math.max(0,Math.min(1,(e-this.healthBarShownAt)/120)):t<0||t>=2900?0:Math.min(1,(e-this.healthBarShownAt)/120,(2900-t)/650)}},sn={defaultHealth:600,impactThresholdMps:3,impactDamagePerMps:5.5,maxImpactDamageFraction:.3,burningDamagePerSecond:14,respawnSeconds:2.5};function cn(e,t){if(e<=0)return`exploded`;let n=e/Math.max(t,.001);return n<=H.ignitionFraction?`burning`:n<=H.smoulderFraction?`smouldering`:n<=H.smokeFraction?`smoking`:`intact`}function ln(e,t){let n=e/Math.max(t,.001);return Math.max(0,Math.min(1,(H.smokeFraction-n)/H.smokeFraction))}function un(e,t,n){let r=Math.max(1,Math.min(e,t));return Math.max(13,r*.28)+r*.52*Math.max(0,Math.min(1,n))}function dn(e,t,n,r){let i=cn(e,t);if(i===`intact`||i===`exploded`)return null;let a=ln(e,t),o=i===`burning`?Math.max(0,1-e/Math.max(t*H.ignitionFraction,.001)):0;return{stage:i,age:.19,spreadSeconds:0,burnSeconds:.8,fixedRadius:un(n,r,a),intensity:i===`burning`?.65+o*1.4:0,smokeOnly:i!==`burning`,smokeRate:i===`burning`?10+o*4:18+a*12}}function fn(e){return{age:e,spreadSeconds:0,burnSeconds:H.fireballSeconds,blastAge:e,blastSeconds:H.fireballSeconds,smokeRate:12}}function pn(e,t){return cn(e,t)===`intact`||e<=0?0:.06+ln(e,t)*.94}function mn(e,t,n=0){let r=H.damagePerSecond;return e===`bullet`?r/(2*dt(t).roundsPerSecond):e===`rocket`?r/mt(t).roundsPerSecond:r*Math.max(0,n)}function hn(e,t,n){return e*H.ignitionFraction*t/n}function gn(e,t,n){let r=Number(e.getAttribute(t));return Number.isFinite(r)&&r>=0&&e.hasAttribute(t)?r:n}var U=(e=0,t=0)=>({x:e,y:t}),W=(e,t)=>U(e.x+t.x,e.y+t.y),G=(e,t)=>U(e.x-t.x,e.y-t.y),K=(e,t)=>U(e.x*t,e.y*t),q=(e,t)=>e.x*t.x+e.y*t.y,_n=(e,t)=>e.x*t.y-e.y*t.x,J=e=>Math.hypot(e.x,e.y),Y=(e,t)=>{let n=Math.cos(t),r=Math.sin(t);return U(e.x*n-e.y*r,e.x*r+e.y*n)},X=(e,t,n)=>Math.max(t,Math.min(n,e)),vn=e=>Math.atan2(Math.sin(e),Math.cos(e));function yn(e){let t=X(5.8+e.engineForceN/e.massKg*.12,6.5,8.5);return{speed:t,radius:t/X(t*Math.tan(e.maxSteerAngleRad)/e.geometry.wheelbaseM*.62,1.3,1.8)}}var bn=class{mass=1e3;inertia=this.mass*20/12;position=U();velocity=U();angle=0;spin=0;force=U();torque=0;captureState(){return P({mass:this.mass,inertia:this.inertia,position:this.position,velocity:this.velocity,angle:this.angle,spin:this.spin,force:this.force,torque:this.torque})}restoreState(e){let t=P(e);this.mass=t.mass,this.inertia=t.inertia,this.position=t.position,this.velocity=t.velocity,this.angle=t.angle,this.spin=t.spin,this.force=t.force,this.torque=t.torque}reset(){this.position=U(),this.velocity=U(),this.angle=0,this.spin=0,this.force=U(),this.torque=0}world(e){return W(this.position,Y(e,this.angle))}local(e){return Y(G(e,this.position),-this.angle)}velocityAt(e){let t=G(e,this.position);return W(this.velocity,U(-this.spin*t.y,this.spin*t.x))}push(e,t=this.position){this.force=W(this.force,e),this.torque+=_n(G(t,this.position),e)}impulse(e,t=this.position){this.velocity=W(this.velocity,K(e,1/this.mass)),this.spin+=_n(G(t,this.position),e)/this.inertia}tick(e){this.velocity=W(this.velocity,K(this.force,e/this.mass)),this.spin+=this.torque*e/this.inertia,this.position=W(this.position,K(this.velocity,e)),this.angle+=this.spin*e,this.force=U(),this.torque=0}},xn=class extends on{destructible=!0;get stage(){return this.destructible?super.stage:`intact`}damage(e,t=performance.now()){return this.destructible?super.damage(e,t):!1}tires=[];engineForce=0;rollingResistance=0;lateralResistance=0;handbrakeStrength=0;drifting=!1;donuting=!1;burnout=!1;launchSpinSeconds=0;boostCharge=0;boostReady=!1;get boostActive(){return this.statusEffects.remaining(`boost`)>0}burnOriginLocal=U(.7,0);statusEffects=new nn;get oilDistanceRemainingM(){return this.statusEffects.remaining(`oil`)}get oilGripFactor(){return this.statusEffects.factorFrom(`oil`,`grip`,void 0,this.tires.length||4)}oilGripFactorFor(e){return this.statusEffects.factorFrom(`oil`,`grip`,e)}coatWithOil(e){if(e===void 0)for(let e=0;e<this.tires.length;e++)this.statusEffects.apply(`oil`,$t.oil,e);else e>=0&&e<this.tires.length&&this.statusEffects.apply(`oil`,$t.oil,e)}coatWithMud(e){if(e===void 0)for(let e=0;e<this.tires.length;e++)this.statusEffects.apply(`mud`,$t.mud,e);else e>=0&&e<this.tires.length&&this.statusEffects.apply(`mud`,$t.mud,e)}washWheel(e){e>=0&&e<this.tires.length&&(this.statusEffects.clearTire(e),this.tires[e].heat=0)}advanceOil(e){this.statusEffects.advance(e,0)}frontLoadFraction=.5;slideAngleRad=0;countersteering=!1;driftDirection=0;driftStart=null;donutDirection=0;steeringAngle=0;steeringReferenceSpeed=0;previousVelocity=null;longitudinalAcceleration=0;burnoutSeconds=0;boostChargeSeconds=0;launchPeakRpm=0;launchAssistElapsed=0;launchAssistGainMps=0;preset=z.porsche911997;constructor(){super(sn.defaultHealth),this.configure(z.porsche911997)}captureState(){return P({maxHealth:this.maxHealth,health:this.health,explodedAt:this.explodedAt,blastQueued:this.blastQueued,blastAge:this.blastAge,lastBlastEmission:this.lastBlastEmission,lastDamageAt:this.lastDamageAt,healthBarShownAt:this.healthBarShownAt,destructible:this.destructible,tires:this.tires,engineForce:this.engineForce,rollingResistance:this.rollingResistance,lateralResistance:this.lateralResistance,handbrakeStrength:this.handbrakeStrength,drifting:this.drifting,donuting:this.donuting,burnout:this.burnout,launchSpinSeconds:this.launchSpinSeconds,boostCharge:this.boostCharge,boostReady:this.boostReady,burnOriginLocal:this.burnOriginLocal,frontLoadFraction:this.frontLoadFraction,slideAngleRad:this.slideAngleRad,countersteering:this.countersteering,driftDirection:this.driftDirection,driftStart:this.driftStart,donutDirection:this.donutDirection,steeringAngle:this.steeringAngle,steeringReferenceSpeed:this.steeringReferenceSpeed,previousVelocity:this.previousVelocity,longitudinalAcceleration:this.longitudinalAcceleration,burnoutSeconds:this.burnoutSeconds,boostChargeSeconds:this.boostChargeSeconds,launchPeakRpm:this.launchPeakRpm,launchAssistElapsed:this.launchAssistElapsed,launchAssistGainMps:this.launchAssistGainMps,statusEffects:this.statusEffects.captureState()})}restoreState(e){let t=P(e);this.maxHealth=t.maxHealth,this.health=t.health,this.explodedAt=t.explodedAt,this.blastQueued=t.blastQueued,this.blastAge=t.blastAge,this.lastBlastEmission=t.lastBlastEmission,this.lastDamageAt=t.lastDamageAt,this.healthBarShownAt=t.healthBarShownAt,this.destructible=t.destructible,this.tires=t.tires,this.engineForce=t.engineForce,this.rollingResistance=t.rollingResistance,this.lateralResistance=t.lateralResistance,this.handbrakeStrength=t.handbrakeStrength,this.drifting=t.drifting,this.donuting=t.donuting,this.burnout=t.burnout,this.launchSpinSeconds=t.launchSpinSeconds,this.boostCharge=t.boostCharge,this.boostReady=t.boostReady,this.burnOriginLocal=t.burnOriginLocal,this.frontLoadFraction=t.frontLoadFraction,this.slideAngleRad=t.slideAngleRad,this.countersteering=t.countersteering,this.driftDirection=t.driftDirection,this.driftStart=t.driftStart,this.donutDirection=t.donutDirection,this.steeringAngle=t.steeringAngle,this.steeringReferenceSpeed=t.steeringReferenceSpeed,this.previousVelocity=t.previousVelocity,this.longitudinalAcceleration=t.longitudinalAcceleration,this.burnoutSeconds=t.burnoutSeconds,this.boostChargeSeconds=t.boostChargeSeconds,this.launchPeakRpm=t.launchPeakRpm,this.launchAssistElapsed=t.launchAssistElapsed,this.launchAssistGainMps=t.launchAssistGainMps,this.statusEffects.restoreState(t.statusEffects)}takeImpact(e,t=U(.7,0)){let n=this.stage===`burning`,r=Math.max(0,e-sn.impactThresholdMps)*sn.impactDamagePerMps,i=this.damage(Math.min(r,this.maxHealth*sn.maxImpactDamageFraction));return!n&&this.health>0&&this.healthFraction<=H.ignitionFraction&&(this.burnOriginLocal={...t}),i}advanceBurn(e){return this.stage===`burning`&&this.damage(sn.burningDamagePerSecond*Math.max(0,e))}configure(e){this.preset=e,this.engineForce=e.engineForceN,this.rollingResistance=e.rollingResistance,this.lateralResistance=e.lateralResistance,this.handbrakeStrength=e.handbrakeStrength;let{geometry:t}=e;this.tires=[{x:t.rearAxleXM??-t.wheelbaseM/2,track:t.rearTrackWidthM??t.trackWidthM,front:!1},{x:t.frontAxleXM??t.wheelbaseM/2,track:t.frontTrackWidthM??t.trackWidthM,front:!0}].flatMap(({x:e,track:t,front:n})=>[-t/2,t/2].map(t=>({local:U(e,t),front:n,angle:0,skidding:!1,lateralSpeed:0,slipSpeedMps:0,wheelSurfaceSpeedMps:0,slip:0,heat:0,spinning:!1,lateralForceN:0,gripUtilization:0}))),this.reset()}reset(){this.resetBurnable(this.preset.health??sn.defaultHealth),this.burnOriginLocal=U(.7,0),this.drifting=!1,this.donuting=!1,this.frontLoadFraction=this.preset.frontWeightFraction??.5,this.slideAngleRad=0,this.countersteering=!1,this.driftDirection=0,this.driftStart=null,this.donutDirection=0,this.steeringAngle=0,this.steeringReferenceSpeed=0,this.previousVelocity=null,this.longitudinalAcceleration=0,this.burnout=!1,this.burnoutSeconds=0,this.launchPeakRpm=0,this.boostChargeSeconds=0,this.boostCharge=0,this.boostReady=!1,this.launchSpinSeconds=0,this.launchAssistElapsed=0,this.launchAssistGainMps=0,this.statusEffects.clear();for(let e of this.tires)e.angle=0,e.skidding=!1,e.lateralSpeed=0,e.slipSpeedMps=0,e.wheelSurfaceSpeedMps=0,e.slip=0,e.heat=0,e.spinning=!1,e.lateralForceN=0,e.gripUtilization=0}get fastDrifting(){return this.driftDirection!==0}prepareDrift(e,t){let n=J(e.velocity),r=q(e.velocity,Y(U(1,0),e.angle)),i=this.preset.drift;this.fastDrifting&&(!t.action||Math.abs(t.steer)<=.2||n<i.entrySpeedMps*.65||t.throttle<=.5)&&(this.driftDirection=0),!this.fastDrifting&&t.action&&Math.abs(t.steer)>.2&&r>i.entrySpeedMps&&t.throttle>.5&&(this.driftDirection=Math.sign(t.steer),this.statusEffects.remove(`boost`)),this.driftStart=this.fastDrifting?{position:{...e.position},velocity:{...e.velocity},angle:e.angle,spin:e.spin}:null}tick(e,t,n,r){this.prepareDrift(e,t);let i=this.fastDrifting?{...t,action:!1}:t;this.tickForces(e,i,n,r)}tickForces(e,t,n,r){let i=this.burnout,a=this.boostReady&&!!t.boost;if(t.boost&&t.throttle>.5&&!t.action&&!this.fastDrifting?this.statusEffects.apply(`boost`,Qt(this.preset.driveBoost.gainMps,this.preset.driveBoost.durationSeconds)):this.statusEffects.remove(`boost`),this.burnout=t.action&&t.throttle>.5&&J(e.velocity)<1.2,this.burnout){this.burnoutSeconds+=n,this.boostChargeSeconds=t.boost?this.boostChargeSeconds+n:0;let e=Math.max(.1,this.preset.launch.burnoutRampSeconds);this.boostCharge=X(this.boostChargeSeconds/e,0,1),this.boostReady=this.boostChargeSeconds>=e&&this.burnoutSeconds>=e;let i=Math.max(r??0,this.preset.launch.minRpm*Math.min(1,this.burnoutSeconds/.9));this.launchPeakRpm=Math.max(this.launchPeakRpm,i)}else i&&!t.action&&t.throttle>.5?(this.burnoutSeconds>=.25&&this.launchPeakRpm>=this.preset.launch.minRpm&&(this.launchAssistGainMps=a?this.preset.launch.boostedBoostMps:this.preset.launch.boostMps,this.launchAssistElapsed=0),this.launchSpinSeconds=a?this.preset.launch.chargedSpinSeconds:.4):this.launchSpinSeconds=Math.max(0,this.launchSpinSeconds-n),this.burnoutSeconds=0,this.launchPeakRpm=0,this.boostChargeSeconds=0,this.boostCharge=0,this.boostReady=!1;let o=Y(U(1,0),e.angle),s=Math.max(.1,this.preset.launch.assistDurationSeconds);if(this.launchAssistGainMps>0&&t.throttle>.5&&!t.action){let t=Math.min(s,this.launchAssistElapsed+n*.5),r=Math.sin(Math.PI*t/s);e.push(K(o,e.mass*this.launchAssistGainMps*Math.PI*r/(2*s))),this.launchAssistElapsed+=n,this.launchAssistElapsed>=s&&(this.launchAssistGainMps=0)}else this.launchAssistGainMps=0;let c=this.statusEffects.bonus(`forwardAccelerationMps2`,void 0,this.tires.length,n*.5);c>0&&t.throttle>.5&&!t.action&&e.push(K(o,e.mass*c));let l=U(-o.y,o.x),u=J(e.velocity),d=q(e.velocity,o),f=q(e.velocity,l),p=this.previousVelocity===null?0:X(q(G(e.velocity,this.previousVelocity),o)/Math.max(n,1e-4),-16,16);this.previousVelocity={...e.velocity},this.longitudinalAcceleration+=(p-this.longitudinalAcceleration)*(1-Math.exp(-n/.12));let m=this.preset.frontWeightFraction??.5;this.frontLoadFraction=X(m-this.longitudinalAcceleration*.012,.34,.68),this.slideAngleRad=Math.atan2(f,Math.max(2,Math.abs(d)));let h=Math.abs(t.steer),g=t.throttle>.5&&h>.8&&!t.action&&!this.fastDrifting;if(this.donuting?g&&Math.sign(t.steer)===this.donutDirection||(this.donuting=!1,this.donutDirection=0):g&&u<4.5&&(this.donuting=!0,this.donutDirection=Math.sign(t.steer)),this.drifting=this.fastDrifting||this.donuting,this.countersteering=this.fastDrifting&&t.steer*this.driftDirection<0,!this.drifting&&!t.action&&u>4&&d>0){let t=X(Math.abs(this.slideAngleRad)-.05,0,.8);e.spin+=Math.sign(this.slideAngleRad)*t*40*n}let _=t.throttle<0&&q(e.velocity,o)<=0,v=(t.action?.18:1)*(1-X(t.brake??0,0,1));e.push(K(o,t.throttle*v*this.engineForce*this.statusEffects.factor(`driveForce`,void 0,this.tires.length)*(_?this.preset.reversePowerRatio:1))),this.steeringReferenceSpeed=t.steer?Math.max(u,this.steeringReferenceSpeed-8*n):u;let y=Math.atan(this.preset.geometry.wheelbaseM*this.preset.corneringAccelerationMps2/(this.steeringReferenceSpeed**2+16)),b=t.steer*(this.donuting?this.preset.maxSteerAngleRad:Math.min(this.preset.maxSteerAngleRad,y));this.steeringAngle+=(b-this.steeringAngle)*(1-Math.exp(-n/(t.steer?.06:.04)));for(let[r,i]of this.tires.entries()){i.angle=i.front?this.steeringAngle:0;let a=e.world(i.local),o=e.velocityAt(a),s=e.angle+i.angle,c=U(Math.cos(s),Math.sin(s)),l=U(-c.y,c.x),d=q(o,c),f=q(o,l);i.lateralSpeed=Math.abs(f),i.spinning=!i.front&&(this.burnout||this.launchSpinSeconds>0||this.donuting);let p=!i.front&&t.action?Math.abs(d)*.65:0,h=this.burnout?5.2*(.3+.7*X(this.burnoutSeconds/Math.max(.1,this.preset.launch.burnoutRampSeconds),0,1)):5.2;i.wheelSurfaceSpeedMps=i.spinning?d+h:!i.front&&t.action?d*.35:d,i.slipSpeedMps=Math.max(i.lateralSpeed,p,Math.abs(i.wheelSurfaceSpeedMps-d)),i.slip=X((i.slipSpeedMps-.45)/4.8,0,1);let g=X((i.slipSpeedMps-.4)/5.2,0,1),_=g>i.heat?.65:2.2;i.heat+=(g-i.heat)*(1-Math.exp(-n/_));let v=i.front?this.frontLoadFraction:1-this.frontLoadFraction,y=X(v/(i.front?m:1-m),.65,1.35),b=(!i.front&&this.donuting?.5:1)*(1-i.heat*(i.front?.06:.12))*this.statusEffects.factor(`grip`,r),x=this.lateralResistance*(1+Math.min(u,40)/18)*y*b,S=e.mass*this.preset.corneringAccelerationMps2*v*.5*b,C=-x*f,ee=X(C,-S,S);i.lateralForceN=ee,i.gripUtilization=Math.abs(C)/Math.max(1,S);let te=Math.abs(C)>S*.92,ne=i.skidding?1.2:1.8;i.skidding=i.spinning||i.slipSpeedMps>ne&&(te||i.lateralSpeed>(i.front?2.8:2.1)||p>2.4);let w=this.rollingResistance*(!i.front&&t.action?1+this.handbrakeStrength*7:1);e.push(W(K(c,-w*d),K(l,ee)),a)}}slow(e,t,n){let r=(t.throttle===0?this.preset.coastDecelerationMps2:0)+(t.action?this.preset.handbrakeDecelerationMps2:0),i=J(e.velocity);if(i===0)return;r&&(e.velocity=K(e.velocity,Math.max(0,i-r*n)/i));let a=X(t.brake??0,0,1);if(!a)return;let o=U(Math.cos(e.angle),Math.sin(e.angle)),s=q(e.velocity,o),c=Math.min(Math.abs(s),a*gt(this.preset)*Math.max(.35,this.statusEffects.factor(`grip`,void 0,this.tires.length))*n);e.velocity=G(e.velocity,K(o,Math.sign(s)*c))}finishDrift(e,t,n){let r=this.driftStart;if(!this.fastDrifting||!r)return;let i=J(r.velocity),a=X(i/12,.55,1.2),o=this.driftDirection*(.92+.24*a)+X(t.steer,-1,1)*.47;e.spin=r.spin+(o-r.spin)*(1-Math.exp(-12*n)),e.angle=r.angle+e.spin*n;let s=J(e.velocity),c=Math.max(s,i-.5*n),l=Math.atan2(r.velocity.y,r.velocity.x),u=l+X(vn(e.angle-this.driftDirection*this.preset.drift.slipAngleRad-l)*(1-Math.exp(-7*n)),-3.5*n,3.5*n);e.velocity=U(Math.cos(u)*c,Math.sin(u)*c),e.position=W(r.position,K(e.velocity,n)),this.slideAngleRad=vn(u-e.angle);for(let e of this.tires)e.front||(e.skidding=!0,e.lateralSpeed=c*Math.sin(this.preset.drift.slipAngleRad),e.slipSpeedMps=Math.max(e.slipSpeedMps,e.lateralSpeed),e.slip=X(e.slipSpeedMps/4,0,1),e.heat+=(.8-e.heat)*(1-Math.exp(-2*n)),e.gripUtilization=Math.max(e.gripUtilization,1))}arcadeAssist(e,t,n){let r=J(e.velocity),{speed:i,radius:a}=yn(this.preset);if(this.donuting){let t=i*this.statusEffects.factor(`speed`,void 0,this.tires.length),o=Math.atan2(e.velocity.y,e.velocity.x),s=e.angle-this.donutDirection*.22,c=Math.atan2(Math.sin(s-o),Math.cos(s-o))*(1-Math.exp(-n/.11)),l=r+(t-r)*(1-Math.exp(-n/.28));e.velocity=K(U(Math.cos(o+c),Math.sin(o+c)),l),e.spin=this.donutDirection*l/a;return}let o=Y(U(1,0),e.angle);if(q(e.velocity,o)<-.35&&t.throttle<0&&!t.action){let i=this.preset.maxReverseSpeedMps??7;r>i&&(e.velocity=K(e.velocity,i/r)),e.spin=-t.steer*Math.min(r,i)/a;let s=K(o,-1),c=Math.atan2(_n(s,e.velocity),q(s,e.velocity));e.velocity=Y(e.velocity,-X(c,-.45,.45)*(1-Math.exp(-5*n)));return}if(r<2||this.drifting||t.action||q(e.velocity,o)<=0)return;let s=Math.atan2(_n(o,e.velocity),q(o,e.velocity)),c=X((r-2)/10,0,1)*(t.steer?4.5:6)*this.statusEffects.factor(`grip`,void 0,this.tires.length),l=-X(s,-.55,.55)*(1-Math.exp(-c*n));e.velocity=Y(e.velocity,l),t.steer||(e.spin*=Math.exp(-4.5*n))}},Sn=class{headAngle=0;appliedForce=U();craft=U(4,0);counterweight=U(-2,0);radius=.9;captureState(){return P({headAngle:this.headAngle,appliedForce:this.appliedForce,craft:this.craft,counterweight:this.counterweight,radius:this.radius})}restoreState(e){let t=P(e);this.headAngle=t.headAngle,this.appliedForce=t.appliedForce,Object.assign(this,{craft:t.craft,counterweight:t.counterweight,radius:t.radius})}reset(){this.headAngle=0,this.appliedForce=U()}tick(e,t,n){this.headAngle+=t.steer*2.5*n;let r=(t.throttle||+!!t.action)*5e3*(t.action?2:1);this.appliedForce=Y(U(r,0),this.headAngle),e.push(Y(this.appliedForce,e.angle),e.world(this.craft)),e.push(K(e.velocity,-e.mass*.12)),e.spin*=Math.exp(-.35*n)}},Cn=class{body=new bn;car=new xn;ship=new Sn;mode=`car`;gravity=!1;barrier=!1;paused=!1;lastInput={throttle:0,steer:0,action:!1};brickForce=null;captureState(){return{at:performance.now(),preset:P(this.car.preset),simulation:P({mode:this.mode,gravity:this.gravity,barrier:this.barrier,paused:this.paused,lastInput:this.lastInput,brickForce:this.brickForce}),body:this.body.captureState(),car:this.car.captureState(),ship:this.ship.captureState()}}restoreState(e){let t=P(e);this.setPreset(t.preset),this.body.restoreState(t.body),this.car.restoreState(t.car),this.ship.restoreState(t.ship),this.mode=t.simulation.mode,this.gravity=t.simulation.gravity,this.barrier=t.simulation.barrier,this.paused=t.simulation.paused,this.lastInput=t.simulation.lastInput,this.brickForce=t.simulation.brickForce;let n=performance.now()-t.at;this.car.explodedAt!==null&&(this.car.explodedAt+=n),Number.isFinite(this.car.lastBlastEmission)&&(this.car.lastBlastEmission+=n)}setPreset(e){this.car.configure(e),this.mode===`car`&&(this.body.mass=e.massKg,this.body.inertia=e.massKg*(e.geometry.lengthM**2+e.geometry.widthM**2)/12)}setMode(e){this.mode=e,this.body.mass=e===`car`?this.car.preset.massKg:1e3,this.body.inertia=e===`ship`?this.body.mass*(1/3*(1.8**2/18+.8**2/6+16)+2/3*(.9**2/2+4)):this.body.mass*(this.car.preset.geometry.lengthM**2+this.car.preset.geometry.widthM**2)/12,this.car.reset(),this.ship.reset(),this.brickForce=null}reset(){this.body.reset(),this.car.reset(),this.ship.reset(),this.brickForce=null,this.lastInput={throttle:0,steer:0,action:!1}}resetAtCurrentPose(){let e={...this.body.position},t=this.body.angle;this.reset(),this.body.position=e,this.body.angle=t}tick(e,t,n){if(this.paused)return;if(this.mode===`car`&&this.car.explodedAt!==null){this.body.velocity=U(),this.body.spin=0,this.lastInput={throttle:0,steer:0,action:!1,boost:!1};return}this.lastInput={...e};let r=this.body,i={...r.position};if(this.gravity){let e=r.mass*3/30;r.push(U(-e*r.velocity.x,-r.mass*3-e*r.velocity.y))}if(this.mode===`car`&&this.car.tick(r,e,t,n),this.mode===`ship`){let n=r.angle;this.ship.tick(r,e,t),r.tick(t),this.ship.headAngle-=r.angle-n}else if(this.mode===`brick`&&this.brickForce&&r.push(this.brickForce.force,r.world(this.brickForce.local)),r.tick(t),this.mode===`car`){let n=this.car.fastDrifting?{...e,action:!1}:e;this.car.slow(r,n,t),this.car.fastDrifting?this.car.finishDrift(r,e,t):this.car.arcadeAssist(r,n,t);let a=this.car.statusEffects.factor(`speed`,void 0,this.car.tires.length);a<1&&(r.velocity=K(r.velocity,Math.exp(-5*(1-a)*t))),this.car.statusEffects.advance(J(G(r.position,i)),t)}}contain(e){let t=this.body,n=this.mode===`car`?this.car.preset.geometry.lengthM/2:2,r=this.mode===`car`?this.car.preset.geometry.widthM/2:1,i=this.mode===`ship`?[U(1.2,0),U(-.6,-.8),U(-.6,.8)].map(e=>t.world(W(this.ship.craft,Y(e,this.ship.headAngle)))):[U(-n,-r),U(n,-r),U(n,r),U(-n,r)].map(e=>t.world(e));this.mode===`ship`&&i.push(t.world(this.ship.counterweight));let a=[[U(1),e.left],[U(-1),-e.right],[U(0,1),e.bottom],[U(0,-1),-e.top]];for(let e=0;e<4;e++)for(let[e,n]of a){let r=i.map(t=>q(t,e)-(this.mode===`ship`?this.ship.radius:0)),a=Math.min(...r),o=n-a;if(o<-1e-8)continue;let s=i[r.indexOf(a)],c=K(e,Math.max(0,o));t.position=W(t.position,c);for(let e of i)e.x+=c.x,e.y+=c.y;let l=W(s,K(e,this.mode===`ship`?-this.ship.radius:0)),u=q(t.velocityAt(l),e);if(u>=0)continue;let d=_n(G(l,t.position),e),f=1/t.mass+d*d/t.inertia;t.impulse(K(e,-(1+(u<-.5?.55:0))*u/f),l)}}};function wn(e,t){}function Tn(e,t=1){}function En(e,t){if(!(typeof HTMLElement<`u`&&e instanceof HTMLElement)){for(let e of[`trigger`,`crushable`,`combustible`,`pushable`])if(t[e])throw new ne(`object.${e}`,`${e} requires an HTML element`);if(t.liquid&&!(typeof SVGGeometryElement<`u`&&e instanceof SVGGeometryElement))throw new ne(`object.liquid`,`liquid requires HTML or an SVG shape`);if(!(typeof SVGSVGElement<`u`&&e instanceof SVGSVGElement)&&(t.breakable||t.burnable))throw new ne(`object`,`breakable and burnable artwork require HTML text/artwork or an SVG root`)}}var Dn=0;function On(e){return e&&typeof e==`object`&&(Object.values(e).forEach(On),Object.freeze(e)),e}var kn=class{root;definitions;scope=++Dn;registrations=new Set;records=new Map;snapshot=Object.freeze([]);identities=new WeakMap;patches=new Map;listeners=new Set;diagnosticListeners=new Set;liquids=new Map;vehicles=new Map;importedVehicles=new Map;importedLiquids=new Map;recordingImports=new Map;importSerial=0;observer;dirty=!0;disposed=!1;nextId=0;nextRegistration=0;version=0;pageStateChanged=()=>this.invalidate();constructor(e=document,t={}){this.root=e,this.definitions=tt(t);try{for(let e of Object.keys(this.definitions.liquids??{}))this.resolveLiquid(e);for(let e of Object.keys(this.definitions.vehicles??{}))this.resolveVehicle(e);for(let e of Object.values(this.definitions.objects??{}))this.resolve(e);this.observe()}catch(e){throw this.dispose(),e}}observe(){this.observer?.disconnect(),this.observer??=new MutationObserver(e=>{e.some(e=>{if(e.type!==`attributes`){let t=e.target instanceof Element?e.target:e.target.parentElement;return!(t&&this.records.get(t)?.spec.hud)}if((e.target instanceof Element?e.target:null)?.closest(`[data-jr-embed],[data-jr-overlay],[data-jr-text-run]`))return!1;if([...this.registrations].some(e=>typeof e.target==`string`))return!0;let t=e.attributeName??``;return t!==`style`&&![`data-jr-trigger-state`,`data-jr-trigger-departed`,`data-jr-crushed`].includes(t)})&&this.invalidate()});for(let e of[`input`,`change`,`focusin`,`focusout`])this.root.addEventListener(e,this.pageStateChanged);this.observer.observe(this.root,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}invalidate(){if(!(this.disposed||this.dirty)){this.dirty=!0;for(let e of this.listeners)e()}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onDiagnostic(e){return this.diagnosticListeners.add(e),()=>this.diagnosticListeners.delete(e)}report(e,t){let n={code:`configuration`,message:e instanceof Error?e.message:String(e),target:t};for(let e of this.diagnosticListeners)e(n);this.root.dispatchEvent(new CustomEvent(`joyride:diagnostic`,{bubbles:!0,detail:n}))}targets(e){if(typeof e==`string`){let t=[...this.root.querySelectorAll(e)];return this.root instanceof Element&&this.root.matches(e)&&t.unshift(this.root),t}if(e instanceof Element)return[e];if(!e||typeof e[Symbol.iterator]!=`function`)throw TypeError(`Expected a selector, element, or iterable of elements`);let t=[...e];if(t.some(e=>!(e instanceof Element)))throw TypeError(`Every binding target must be an Element`);return[...new Set(t)]}accepts(e){return e.isConnected&&!(this.root instanceof Element&&e!==this.root&&!this.root.contains(e))&&!e.closest(`[data-jr-embed],[data-jr-overlay]`)}compose(e,t=[...this.registrations],n=this.patches.get(e)){let r=t.filter(t=>typeof t.target==`string`&&e.matches(t.target)),i=t.filter(t=>typeof t.target!=`string`&&this.targets(t.target).includes(e)),a=this.resolve(I(...r.map(e=>e.spec),$e(e),...i.map(e=>e.spec),n));return En(e,a),a}validateChange(e,t,n,r){this.refresh();let i=new Set(e),a=new Set([...this.records.values()].filter(e=>!i.has(e.target)).map(e=>e.id));for(let i of e){if(!this.accepts(i))continue;let e=this.compose(i,t,i===n?r:this.patches.get(i)).id??this.identities.get(i);if(e&&a.has(e))throw Error(`Duplicate playground object ID: ${e}`);e&&a.add(e)}}bindAll(e){let t=[];try{for(let n of e)t.push(this.bind(n.target,n.spec));return t}catch(e){for(let e of t)e.dispose();throw e}}bind(e,t){if(this.disposed)throw Error(`Playground is disposed`);let n=this.targets(e),r={id:++this.nextRegistration,target:typeof e==`string`||e instanceof Element?e:n,spec:Pe(t),disposed:!1};this.validateChange(n,[...this.registrations,r]),this.registrations.add(r),this.dirty=!1,this.invalidate();let i=()=>r.disposed||this.disposed?[]:(this.refresh(),this.targets(r.target).flatMap(e=>this.records.get(e)??[]));return{get objects(){return i()},update:e=>{if(r.disposed||this.disposed)throw Error(`Binding is disposed`);let t={...r,spec:Pe(I(r.spec,e))};this.validateChange(this.targets(r.target),[...this.registrations].map(e=>e===r?t:e)),r.spec=t.spec,this.dirty=!1,this.invalidate()},replace:e=>{if(r.disposed||this.disposed)throw Error(`Binding is disposed`);let t={...r,spec:Pe(e)};this.validateChange(this.targets(r.target),[...this.registrations].map(e=>e===r?t:e)),r.spec=t.spec,this.dirty=!1,this.invalidate()},refresh:()=>{if(r.disposed||this.disposed)throw Error(`Binding is disposed`);this.dirty=!1,this.invalidate(),this.refresh()},dispose:()=>{r.disposed||(r.disposed=!0,this.registrations.delete(r),this.dirty=!1,this.invalidate())}}}update(e,t){if(this.disposed)throw Error(`Playground is disposed`);if(this.refresh(),!this.records.has(e))throw Error(`Element is not registered`);let n=Pe(I(this.patches.get(e),t));this.validateChange([e],[...this.registrations],e,n),this.patches.set(e,n),this.dirty=!1,this.invalidate()}get(e){return this.refresh(),this.records.get(e)}get objects(){return this.refresh(),this.snapshot}refresh(){if(!this.dirty||this.disposed)return;this.dirty=!1;let e=new Set(this.targets(Xe));for(let t of this.registrations)for(let n of this.targets(t.target))e.add(n);let t=new Set,n=new Map([...this.records].filter(([t])=>e.has(t)&&this.accepts(t)).map(([e,t])=>[t.id,e])),r=!1;for(let i of e)if(this.accepts(i))try{let e=this.compose(i),a=e.id??this.identities.get(i);a??=`jr-${this.scope}-${++this.nextId}`;let o=n.get(a);if(o&&o!==i||t.has(a))throw Error(`Duplicate playground object ID: ${a}`);t.add(a),this.identities.set(i,a);let s=this.records.get(i);s&&JSON.stringify(s.spec)===JSON.stringify(e)||(this.records.set(i,Object.freeze({id:a,target:i,spec:On(e),revision:++this.version})),r=!0)}catch(e){this.report(e,i)}for(let[t]of this.records)e.has(t)&&this.accepts(t)||(this.records.delete(t),this.patches.delete(t),r=!0);if(r){this.snapshot=Object.freeze([...this.records.values()]);for(let e of this.listeners)e()}}validateObject(e){return this.resolve(e)}exportBindings(){if(this.disposed)throw Error(`Playground is disposed`);let e=[...this.registrations].flatMap(e=>typeof e.target==`string`?[]:[{path:`bindings.${e.id}.target`,reason:`an exact element binding has no portable selector`}]);if(this.patches.size&&e.push({path:`objectOverrides`,reason:`runtime object overrides are tied to live element identities`}),e.length)throw new Kt(e);return[...this.registrations].map(e=>({target:e.target,spec:structuredClone(e.spec)}))}exportDefinitions(){if(this.disposed)throw Error(`Playground is disposed`);return tt({...this.definitions,liquids:{...this.definitions.liquids,...Object.fromEntries(this.importedLiquids)},vehicles:{...this.definitions.vehicles,...Object.fromEntries(this.importedVehicles)}})}registerVehiclePreset(e,t){if(this.disposed)throw Error(`Playground is disposed`);if(this.definitions.vehicles?.[e]||this.importedVehicles.has(e)||Object.values(z).some(t=>t.id===e))throw Error(`Vehicle recipe already exists: ${e}`);let{id:n,...r}=Et(t),i={...r,base:z.porsche911997.id};return tt({vehicles:{[e]:i}}),this.importedVehicles.set(e,i),e}vehicleName(e){for(let[t,n]of this.vehicles)if(n.id===e)return t;if(Object.values(z).some(t=>t.id===e))return e;throw new Kt([{path:`player.vehicle`,reason:`vehicle ${e} has no authored recipe in this catalog`}])}captureVehicleConfiguration(e,n,r){let i=structuredClone(r),a=this.exportDefinitions().liquids??{},o={},s=e=>{if(o[e])return;let n=a[e];if(n)o[e]=n,s(n.base);else{if(e.startsWith(`custom:`))throw new Kt([{path:`vehicle.liquids`,reason:`material ${e} has no portable authored definition`}]);t(e)}};for(let e of Object.values(i))if(e&&e.action===`eject`){if(e.liquid=this.liquidName(e.liquid),e.liquid.startsWith(`custom:`))throw new Kt([{path:`vehicle.slots`,reason:`material ${e.liquid} is not owned by this catalog`}]);s(e.liquid)}return Zt({preset:e,appearance:n,slots:i,liquids:o})}importRecordedVehicle(e){if(this.disposed)throw Error(`Playground is disposed`);let n=Zt(e),r=JSON.stringify(n),i=this.recordingImports.get(r);if(i)return structuredClone(i);let a;do a=`recorded-${++this.importSerial}`;while(this.importedVehicles.has(`${a}-vehicle`)||this.definitions.vehicles?.[`${a}-vehicle`]||Object.keys(n.liquids).some((e,t)=>this.importedLiquids.has(`${a}-liquid-${t}`)||this.definitions.liquids?.[`${a}-liquid-${t}`]));let o=new Map(Object.keys(n.liquids).map((e,t)=>[e,`${a}-liquid-${t}`]));for(let e of Object.values(n.liquids))if(!o.has(e.base)){if(e.base.startsWith(`custom:`))throw Error(`Recorded liquid bases must use portable authored names`);t(e.base)}let s=structuredClone(n.slots);for(let e of Object.values(s))if(e&&e.action===`eject`){if(o.has(e.liquid))e.liquid=o.get(e.liquid);else{if(e.liquid.startsWith(`custom:`))throw Error(`Recorded emitters must use portable authored names`);t(e.liquid)}}for(let[e,t]of Object.entries(n.liquids))this.importedLiquids.set(o.get(e),{...structuredClone(t),base:o.get(t.base)??t.base});let c={vehicle:this.registerVehiclePreset(`${a}-vehicle`,n.preset),appearance:n.appearance,slots:s};return this.recordingImports.set(r,c),structuredClone(c)}resolve(e,t=new Set){let n=I(e);if(typeof n.object==`string`){let e=n.object;if(t.has(e))throw Error(`Circular object definition: ${e}`);let r=this.definitions.objects?.[e];if(!r)throw Error(`Unknown object definition: ${e}`);t.add(e);let{object:i,...a}=n;n=I(this.resolve(r,t),a)}let r=n.liquid;return r&&typeof r==`object`&&typeof r.kind==`string`&&(r.kind=this.resolveLiquid(r.kind)),Fe(n)}resolveLiquid(e,n=new Set){let r=this.liquids.get(e);if(r)return r;let i=this.importedLiquids.get(e)??this.definitions.liquids?.[e];if(!i)return t(e);if(n.has(e))throw Error(`Circular liquid definition: ${e}`);n.add(e);let a=this.resolveLiquid(i.base,n),o=`jr-${this.scope}-${this.liquids.size}-`,s=m(`${o}${e.slice(0,64-o.length)}`,{...i,base:a});return this.liquids.set(e,s.kind),s.kind}liquidName(e){for(let[t,n]of this.liquids)if(n===e)return t;return e}resolveVehicle(e,t=new Set){let n=this.vehicles.get(e);if(n)return n;let r=this.importedVehicles.get(e)??this.definitions.vehicles?.[e];if(!r){let t=Object.values(z).find(t=>t.id===e);if(!t)throw Error(`Unknown vehicle definition: ${e}`);return t}if(t.has(e))throw Error(`Circular vehicle definition: ${e}`);t.add(e);let{base:i,appearance:a,slots:o,...s}=r,c=Et(I(this.resolveVehicle(i,t),s,{id:`custom-jr-${this.scope}-${e}`}));return this.vehicles.set(e,c),c}vehicleOptions(e){let t=this.importedVehicles.get(e)??this.definitions.vehicles?.[e];return t?I(this.vehicleOptions(t.base),{appearance:t.appearance,slots:t.slots}):{appearance:`auto`,slots:y}}captureState(){return P({patches:this.patches,registrations:new Map([...this.registrations].map(e=>[e.id,e.spec]))})}restoreState(e){let t=P(e);this.patches.clear();for(let[e,n]of t.patches)this.patches.set(e,n);for(let e of this.registrations){let n=t.registrations.get(e.id);n&&(e.spec=n)}this.dirty=!1,this.invalidate(),this.refresh()}reset(){this.patches.clear(),this.dirty=!1,this.invalidate()}dispose(){if(!this.disposed){this.disposed=!0,this.observer?.disconnect();for(let e of[`input`,`change`,`focusin`,`focusout`])this.root.removeEventListener(e,this.pageStateChanged);this.records.clear(),this.snapshot=Object.freeze([]),this.registrations.clear(),this.patches.clear(),this.listeners.clear(),this.diagnosticListeners.clear();for(let e of this.liquids.values())h(e);this.liquids.clear(),this.vehicles.clear(),this.importedVehicles.clear(),this.importedLiquids.clear(),this.recordingImports.clear()}}};function An(e,t,n=0){let{halfX:r,halfY:i}=e,a=r.x*i.y-r.y*i.x;if(Math.abs(a)<1e-4)return!1;let o=t.x-e.center.x,s=t.y-e.center.y,c=(o*i.y-s*i.x)/a,l=(s*r.x-o*r.y)/a;return Math.abs(c)<=1+n/Math.max(1,Math.hypot(r.x,r.y))&&Math.abs(l)<=1+n/Math.max(1,Math.hypot(i.x,i.y))}var jn=class{transforms=new WeakMap;transform(e){return this.transforms.has(e)||this.transforms.set(e,Mn(e)),this.transforms.get(e)}};function Mn(e){let t=getComputedStyle(e);if(t.visibility===`hidden`||t.display===`none`)return null;let n=new DOMMatrixReadOnly;if(t.rotate&&t.rotate!==`none`){let e=t.rotate.trim().split(/\s+/);if(e.length>1&&e.slice(0,-1).join(` `)!==`z`)return null;let r=e.at(-1),i=parseFloat(r),a=r.endsWith(`grad`)?i*.9:r.endsWith(`rad`)?i*180/Math.PI:r.endsWith(`turn`)?i*360:i;n=n.rotate(a)}if(t.scale&&t.scale!==`none`){let[e,r]=t.scale.split(/\s+/).map(Number);n=n.scale(e,r??e)}return t.transform&&t.transform!==`none`&&(n=n.multiply(new DOMMatrixReadOnly(t.transform))),n.is2D?n:null}function Nn(e,t){let n=e.getBoundingClientRect();if(!n.width||!n.height)return null;let r=new DOMMatrixReadOnly;for(let n=e;n;n=n.parentElement){let e=t?t.transform(n):Mn(n);if(!e)return null;r=e.multiply(r)}return{center:{x:n.left+n.width/2,y:n.top+n.height/2},halfX:{x:r.a*e.offsetWidth/2,y:r.b*e.offsetWidth/2},halfY:{x:r.c*e.offsetHeight/2,y:r.d*e.offsetHeight/2}}}function Pn(e,t){let n=1/0,r={x:1,y:0};for(let i of[e,t])for(let a=0;a<i.length;a++){let o=i[a],s=i[(a+1)%i.length],c=Math.hypot(s.x-o.x,s.y-o.y);if(c<1e-9)continue;let l={x:-(s.y-o.y)/c,y:(s.x-o.x)/c},u=e.map(e=>e.x*l.x+e.y*l.y),d=t.map(e=>e.x*l.x+e.y*l.y),f=Math.min(...u),p=Math.max(...u),m=Math.min(...d),h=Math.max(...d);if(p<=m||h<=f)return null;let g=p-m,_=h-f,v=Math.min(g,_);v<n&&(n=v,r=g<_?{x:-l.x,y:-l.y}:l)}return Number.isFinite(n)?{normal:r,depth:n}:null}function Fn(e,t,n,r){let i=r.reduce((e,t,n)=>{let i=r[(n+1)%r.length];return e+t.x*i.y-i.x*t.y},0),a=0,o=1;for(let s=0;s<r.length;s++){let c=r[s],l=r[(s+1)%r.length],u=Math.hypot(l.x-c.x,l.y-c.y);if(u<1e-9)continue;let d=(l.y-c.y)/u*Math.sign(i),f=-(l.x-c.x)/u*Math.sign(i),p=(e.x-c.x)*d+(e.y-c.y)*f-n,m=(t.x-e.x)*d+(t.y-e.y)*f;if(Math.abs(m)<1e-9){if(p>0)return null;continue}let h=-p/m;if(m<0?a=Math.max(a,h):o=Math.min(o,h),a>o)return null}return a<=1&&o>=0?a:null}var In=(e=``)=>e.split(/\s+/u).filter(Boolean),Ln=class{entries=new Map;apply(e,t,n){let r=this.entries.get(e),{enteredClass:i,dwellingClass:a,successClass:o}=t;if(!r&&!i&&!a&&!o||r?.phase===n&&r.entered===i&&r.dwelling===a&&r.success===o)return;let s=r?.tokens??new Map,c=new Set([...In(i),...In(a),...In(o)]),l=new Set(In(n===`entered`?i:n===`dwelling`?a:n===`success`?o:``));for(let[t,n]of s)c.has(t)||(this.restoreToken(e,t,n),s.delete(t));for(let t of c){let n=e.classList.contains(t),r=s.get(t)??{original:n,applied:n},i=l.has(t);n!==i&&e.classList.toggle(t,i),r.applied=i,s.set(t,r)}c.size?this.entries.set(e,{phase:n,entered:i,dwelling:a,success:o,tokens:s}):this.entries.delete(e)}restoreToken(e,t,n){let r=e.classList.contains(t);r===n.applied&&r!==n.original&&e.classList.toggle(t,n.original)}restore(e){for(let[t,n]of this.entries.get(e)?.tokens??[])this.restoreToken(e,t,n);this.entries.delete(e)}reset(){for(let e of this.entries.keys())this.restore(e)}captureState(){return P(this.entries)}restoreState(e){this.reset();for(let[t,n]of P(e)){this.entries.set(t,n);for(let[e,r]of n.tokens)t.classList.contains(e)!==r.applied&&t.classList.toggle(e,r.applied)}}},Rn=`input[type="checkbox"],[role="checkbox"],[role="switch"]`;function zn(e){return e instanceof HTMLInputElement?{checked:e.checked,indeterminate:e.indeterminate}:{aria:e.getAttribute(`aria-checked`)}}function Bn(e,t){`checked`in t&&e instanceof HTMLInputElement?(e.checked=t.checked,e.indeterminate=t.indeterminate):`aria`in t&&(t.aria===null?e.removeAttribute(`aria-checked`):e.setAttribute(`aria-checked`,t.aria))}var Vn=class{initial=new Map;sync(e){for(let[t,n]of this.initial)e.has(t)||(Bn(t,n),this.initial.delete(t));for(let t of e)this.initial.has(t)||this.initial.set(t,zn(t))}reset(){for(let[e,t]of this.initial)Bn(e,t)}resetTarget(e){let t=this.initial.get(e);t&&Bn(e,t)}captureState(){return P(new Map([...this.initial].map(([e,t])=>[e,{initial:t,current:zn(e)}])))}restoreState(e){this.reset(),this.initial.clear();for(let[t,{initial:n,current:r}]of P(e))this.initial.set(t,n),Bn(t,r)}dispose(){this.reset(),this.initial.clear()}},Hn={click:{action:`click`},check:{action:`check`},toggle:{action:`toggle`},pickup:{repeat:`scene`,consume:!0},parking:{when:`stop`,dwellSeconds:.45,maxSpeedMps:.25,containment:`center`}};function Un(e){let t=e.spec.trigger,n=typeof t==`string`?{preset:t}:typeof t==`object`?t:{};return{when:`enter`,action:`event`,repeat:`visit`,vehicles:`player`,...Hn[n.preset??``],...n}}var Wn=e=>e.spec.stops.map(e=>typeof e==`string`?e:e.target),Gn=()=>({phase:`idle`,inside:!1,departed:!1,qualified:!1,dwell:0,routeDwell:new Map}),Kn=e=>[{x:e.center.x-e.halfX.x-e.halfY.x,y:e.center.y-e.halfX.y-e.halfY.y},{x:e.center.x+e.halfX.x-e.halfY.x,y:e.center.y+e.halfX.y-e.halfY.y},{x:e.center.x+e.halfX.x+e.halfY.x,y:e.center.y+e.halfX.y+e.halfY.y},{x:e.center.x-e.halfX.x+e.halfY.x,y:e.center.y-e.halfX.y+e.halfY.y}];function qn(e){let t=Math.cos(e.angle),n=Math.sin(e.angle);return{center:e.position,halfX:{x:t*e.lengthPx/2,y:n*e.lengthPx/2},halfY:{x:-n*e.widthPx/2,y:t*e.widthPx/2}}}function Jn(e,t){let n=Math.hypot(e.halfX.x,e.halfX.y),r=Math.hypot(e.halfY.x,e.halfY.y);return{center:e.center,halfX:{x:e.halfX.x*(1+t/n),y:e.halfX.y*(1+t/n)},halfY:{x:e.halfY.x*(1+t/r),y:e.halfY.y*(1+t/r)}}}var Yn=(e,t,n,r,i)=>(!e.requireExit||r)&&(e.when===`stop`?t&&i>=(e.dwellSeconds??.45):n),Xn=(e,t,n,r,i)=>n&&Math.abs(r)<=(t.maxSpeedMps??.25)?e+i:0,Zn=class{registry;measure;publicPosition;localPosition;stateClasses=new Ln;controls=new Vn;visits=new Map;credited=new Map;consumed=new Map;visuals=new Map;routes=new Map;declarations=new Map;definitionRoutes=new Set;listeners=new Set;missing=new Set;frameGeometry=null;defaultGeometryFrame;dirty=!0;disposed=!1;unsubscribe;constructor(e,t,n=e=>({...e}),r=e=>({...e})){this.registry=e,this.measure=t,this.publicPosition=n,this.localPosition=r,this.unsubscribe=e.subscribe(()=>{this.dirty=!0});for(let[t,n]of Object.entries(e.definitions.routes??{}))this.definitionRoutes.add(t),this.route(t,n)}onEvent(e){return this.listeners.add(e),()=>this.listeners.delete(e)}beginFrame(){this.disposed||(this.frameGeometry??=new Map,this.frameGeometry.clear(),this.measure||(this.defaultGeometryFrame=new jn))}relocateVehicle(e){for(let t of this.visits.values()){let n=t.get(e);n&&t.set(e,{...n,inside:!1,qualified:!1,position:void 0,dwell:0,routeDwell:new Map})}}geometry(e){let t=()=>this.measure?this.measure(e):e instanceof HTMLElement?Nn(e,this.defaultGeometryFrame):null;return this.frameGeometry?(this.frameGeometry.has(e)||this.frameGeometry.set(e,t()),this.frameGeometry.get(e)):t()}exportRoutes(){if(this.disposed)throw Error(`Playground is disposed`);return Object.fromEntries([...this.routes].filter(([e,t])=>!t.target&&!this.definitionRoutes.has(e)).map(([e,t])=>[e,structuredClone(t.spec)]))}emit(e,t,n){let{object:r,...i}=t,a=It({...P(i),...r?{object:r}:{},...`position`in t?{position:this.publicPosition(t.position)}:{}});(n??this.registry.root).dispatchEvent(new CustomEvent(`joyride:${e}`,{bubbles:!0,detail:a}));for(let t of this.listeners)try{t(e,a)}catch(e){this.registry.report(e,n)}}route(e,t,n){if(this.disposed)throw Error(`Playground is disposed`);if(!e.trim())throw Error(`Route needs an ID`);if(this.routes.has(e))throw Error(`Route already exists: ${e}`);let r=Be(t),i={id:e,spec:r,target:n,visited:new Map,completed:new Set};this.routes.set(e,i);let a=!1;return{id:e,get state(){return[...i.visited].map(([e,t])=>Object.freeze({vehicleId:e,completed:t.size,total:r.stops.length,complete:t.size===r.stops.length}))},reset:()=>{a||this.resetRoute(i)},dispose:()=>{a||this.routes.delete(e),a=!0}}}sync(e){if(!this.dirty)return;this.dirty=!1;let t=[...this.registry.root.querySelectorAll(`[data-jr-route]`)];this.registry.root instanceof Element&&this.registry.root.matches(`[data-jr-route]`)&&t.unshift(this.registry.root);for(let[e,n]of this.declarations)t.includes(e)||(this.routes.delete(n.id),this.declarations.delete(e),this.missing.delete(n.id));for(let n of t)try{let t=n.getAttribute(`data-jr-route`)??``,r=this.declarations.get(n),i=e.filter(e=>n.contains(e.target)&&e.target.closest(`[data-jr-route]`)===n);if(!i.length)continue;let a=i.map(e=>e.id),o=n.getAttribute(`data-jr-route-order`)??`ordered`,s=n.getAttribute(`data-jr-route-progress`)??`vehicle`,c=n.getAttribute(`data-jr-route-event`)??void 0,l=r&&this.routes.get(r.id),u=Be({order:o,progress:s,event:c,stops:l&&l.visited.size?Wn(l):a}),d=JSON.stringify({id:t,spec:u});if(r?.signature===d)continue;if(this.routes.has(t)&&r?.id!==t)throw Error(`Route already exists: ${t}`);if(r){let e=this.routes.get(r.id);e&&this.resetRoute(e),this.routes.delete(r.id)}this.route(t,u,n),this.declarations.set(n,{id:t,signature:d})}catch(e){this.registry.report(e,n)}let n=new Set(e.map(e=>e.target)),r=new Set;for(let t of e){let e=Un(t);if(e.action!==`event`)try{let n=this.actionTarget(t.target,e),i=this.controlTarget(n);i&&r.add(i)}catch(e){this.registry.report(e,t.target)}}this.controls.sync(r);for(let e of this.visits.keys())n.has(e)||(this.visits.delete(e),this.credited.delete(e),this.restore(e))}eligible(e,t,n,r){let i=e.spec.progress===`scene`?`scene`:n.id,a=e.visited.get(i)??new Set,o=Wn(e);return o.includes(t.id)?o.some(e=>!r.some(t=>t.id===e))?(this.missing.has(e.id)||(this.missing.add(e.id),this.registry.report(Error(`Route ${e.id} is waiting for a missing or disabled stop`),e.target)),!1):(this.missing.delete(e.id),!a.has(t.id)&&(e.spec.order===`any`||o[a.size]===t.id)):!1}step(e,t,n=!0){if(this.disposed)return;let r=Number.isFinite(t)?Math.max(0,t):0,i=this.registry.objects.filter(e=>e.spec.trigger&&e.spec.enabled!==!1);this.sync(i);let a=new Set(e.map(e=>e.id)),o=[];for(let t of i){let r=Un(t),i=t.target;if(!(i instanceof HTMLElement))continue;let s=this.visits.get(i);s||this.visits.set(i,s=new Map);for(let e of s.keys())a.has(e)||s.delete(e);let c=this.geometry(i);for(let a of e){let e=s.get(a.id)??Gn(),l=r.vehicles===`all`||(r.vehicles===`ai`?!a.player:a.player);if(!n||!c||!l||r.suspended){let n={...e,phase:!l||r.suspended||!c?`idle`:e.phase===`dwelling`?`entered`:e.phase,inside:c?e.inside:!1,dwell:0,routeDwell:new Map,position:this.publicPosition(a.position)};s.set(a.id,n),(n.phase!==e.phase||n.inside!==e.inside)&&this.emit(`trigger:change`,{object:t,vehicle:{id:a.id},position:a.position,speedMps:a.speedMps,state:{inside:n.inside,departed:n.departed,stopped:n.qualified,phase:n.phase}},i);continue}let u=qn(a),d=Kn(c),f=r.containment===`center`?An(c,a.position):r.containment===`full`?Kn(u).every(e=>An(c,e)):!!Pn(Kn(u),d),p=r.containment===`center`?0:r.containment===`full`?-Math.hypot(a.lengthPx,a.widthPx)/2:a.widthPx/2,m=e.position&&this.localPosition(e.position),h=m&&Math.hypot(a.position.x-m.x,a.position.y-m.y)>.001?Fn(m,a.position,p,d):null,g=!f&&!e.inside&&h!==null,_=!e.inside&&(f||g),v=r.containment===`center`?!An(c,a.position,r.exitMarginPx??20):!Pn(Kn(u),Kn(Jn(c,r.exitMarginPx??20)));e.resetBlocked?v&&s.set(a.id,{...Gn(),departed:!0,position:this.publicPosition(a.position)}):o.push({object:t,config:r,target:i,vehicle:a,visits:s,previous:e,inside:f,crossed:g,entered:_,outside:v,departed:e.departed||v,arrival:e.inside?0:h??1})}}o.sort((e,t)=>e.arrival-t.arrival);for(let e of o){let{object:t,config:n,target:a,vehicle:o,visits:s,previous:c,inside:l,crossed:u,entered:d,outside:f,departed:p}=e,m=[...this.routes.values()].filter(e=>Wn(e).includes(t.id)),h=Xn(c.dwell,n,l,o.speedMps,r),g={object:t,vehicle:{id:o.id},position:{...o.position},speedMps:o.speedMps,state:{inside:l,departed:p,stopped:c.qualified,phase:d?`entered`:c.phase}};d&&this.emit(`trigger:enter`,g,a);let _=m.filter(e=>this.eligible(e,t,o,i)),v=new Map(c.routeDwell),y=_.filter(e=>{let i=e.spec.stops.find(e=>(typeof e==`string`?e:e.target)===t.id),a=typeof i==`string`?n:{...n,...i},s=Xn(c.routeDwell.get(e.id)??0,a,l,o.speedMps,r);return v.set(e.id,s),Yn(a,l,d,p,s)});for(let e of v.keys())_.some(t=>t.id===e)||v.delete(e);let b=this.credited.get(a)??new Set;this.credited.set(a,b);let x=n.repeat===`scene`?`scene`:o.id,S=n.repeat===`visit`?!c.qualified:!b.has(x),C=!f&&c.qualified,ee=!1,te=(m.length?y.length>0:Yn(n,l,d,p,h))&&S;try{let e=!0;if(te&&(e=this.action(a,n),e&&(ee=!0,b.add(x),C=!f,g.state.stopped=C,g.state.phase=`success`,this.emit(`trigger:qualify`,g,a),(m.length?y.some(e=>{let r=e.spec.stops.find(e=>(typeof e==`string`?e:e.target)===t.id);return(typeof r==`string`?n.when:r.when??n.when)===`stop`}):n.when===`stop`)&&this.emit(`trigger:stop`,g,a),n.event&&this.emit(n.event,g,a),n.consume&&!this.consumed.has(a)&&(this.consumed.set(a,{value:a.style.getPropertyValue(`visibility`),priority:a.style.getPropertyPriority(`visibility`)}),a.style.setProperty(`visibility`,`hidden`)))),e)for(let e of y)this.credit(e,t,o,g)}catch(e){this.registry.report(e,a)}let ne=m.some(e=>e.visited.get(e.spec.progress===`scene`?`scene`:o.id)?.has(t.id)),w=S&&l&&(m.length?_.some(e=>{let r=e.spec.stops.find(e=>(typeof e==`string`?e:e.target)===t.id),i=typeof r==`string`?n:{...n,...r},a=v.get(e.id)??0;return i.when===`stop`&&a>0&&a<(i.dwellSeconds??.45)&&(!i.requireExit||p)}):n.when===`stop`&&h>0&&h<(n.dwellSeconds??.45)&&(!n.requireExit||p)),T=ee||ne||n.repeat!==`visit`&&b.has(x)||c.phase===`success`&&!d?`success`:w?`dwelling`:l?`entered`:`idle`;g.state.phase=T,(!l&&c.inside||u)&&this.emit(`trigger:leave`,g,a),s.set(o.id,{phase:T,inside:l,departed:p,qualified:C,dwell:h,routeDwell:v,position:this.publicPosition(o.position)}),g.state.stopped=C,(l!==c.inside||p!==c.departed||C!==c.qualified||T!==c.phase)&&this.emit(`trigger:change`,g,a)}let s=new Set;for(let e of this.routes.values())for(let t of e.visited.values())for(let e of t)s.add(e);for(let e of i){let t=e.target;if(!(t instanceof HTMLElement))continue;let n=Un(e),r=[...this.visits.get(t)?.values()??[]],i=s.has(e.id)||n.repeat!==`visit`&&this.credited.get(t)?.size||r.some(e=>e.phase===`success`)?`success`:r.some(e=>e.phase===`dwelling`)?`dwelling`:r.some(e=>e.phase===`entered`)?`entered`:`idle`;this.visual(t,`data-jr-trigger-state`,i),this.visual(t,`data-jr-trigger-departed`,String(r.some(e=>e.departed))),this.stateClasses.apply(t,n,i)}}credit(e,t,n,r){let i=e.spec.progress===`scene`?`scene`:n.id,a=e.visited.get(i)??new Set;a.add(t.id),e.visited.set(i,a);let o=a.size===e.spec.stops.length,s={...r,route:{id:e.id,completed:a.size,total:e.spec.stops.length,complete:o}};this.emit(`route:progress`,s,e.target),o&&!e.completed.has(i)&&(e.completed.add(i),this.emit(`route:complete`,s,e.target),e.spec.event&&this.emit(e.spec.event,s,e.target))}actionTarget(e,t){let n=e;if(t.target){let e=[...this.registry.root.querySelectorAll(t.target)];if(this.registry.root instanceof Element&&this.registry.root.matches(t.target)&&e.unshift(this.registry.root),e.length!==1)throw Error(`Trigger action target must resolve to exactly one element`);n=e[0]}if(!(n instanceof HTMLElement))throw Error(`Trigger action target must support native activation`);return n}controlTarget(e){let t=e.matches(`input[type="checkbox"],[role="checkbox"],[role="switch"]`)?e:e.querySelector(Rn);return t instanceof HTMLElement?t:null}action(e,t){if(t.action===`event`)return!0;let n=this.actionTarget(e,t);if(n.matches(`:disabled,[aria-disabled="true"]`))return!1;if(t.action===`click`)return n.click(),!0;let r=this.controlTarget(n);if(!(r instanceof HTMLElement))throw Error(`Checkbox action needs a checkbox or switch target`);if(r.matches(`:disabled,[aria-disabled="true"]`))return!1;let i=r instanceof HTMLInputElement?r.checked:r.getAttribute(`aria-checked`)===`true`;return(t.action===`toggle`||i!==(t.action===`check`))&&r.click(),!0}visual(e,t,n){let r=this.visuals.get(e);r||this.visuals.set(e,r=new Map);let i=r.get(t);i?.applied!==n&&(i?i.applied=n:r.set(t,{original:e.getAttribute(t),applied:n}),e.getAttribute(t)!==n&&e.setAttribute(t,n))}captureState(){return P({visits:this.visits,credited:this.credited,routes:[...this.routes].map(([e,t])=>({id:e,visited:t.visited,completed:t.completed})),consumed:this.consumed,visuals:this.visuals,classes:this.stateClasses.captureState(),controls:this.controls.captureState()})}restoreState(e){let t=P(e);this.reset(),this.visits.clear();for(let[e,n]of t.visits)this.visits.set(e,n);for(let[e,n]of t.credited)this.credited.set(e,n);for(let e of t.routes){let t=this.routes.get(e.id);t&&(t.visited=e.visited,t.completed=e.completed)}for(let[e,n]of t.consumed)this.consumed.set(e,n),e.style.setProperty(`visibility`,`hidden`);for(let[e,n]of t.visuals){this.visuals.set(e,n);for(let[t,r]of n)e.setAttribute(t,r.applied)}this.stateClasses.restoreState(t.classes),this.controls.restoreState(t.controls)}restore(e){if(!(e instanceof HTMLElement))return;this.stateClasses.restore(e);let t=this.consumed.get(e);t&&e.style.visibility===`hidden`&&(t.value?e.style.setProperty(`visibility`,t.value,t.priority):e.style.removeProperty(`visibility`)),this.consumed.delete(e);for(let[t,n]of this.visuals.get(e)??[])e.getAttribute(t)===n.applied&&(n.original===null?e.removeAttribute(t):e.setAttribute(t,n.original));this.visuals.delete(e)}resetRoute(e){e.visited.clear(),e.completed.clear(),this.missing.delete(e.id);for(let t of this.registry.objects)Wn(e).includes(t.id)&&(this.visits.delete(t.target),this.credited.delete(t.target),this.restore(t.target))}resetObject(e){let t=this.visits.get(e);this.restore(e),this.credited.delete(e);let n=new Map;for(let[e,r]of t??[])r.inside&&n.set(e,{...Gn(),inside:!0,resetBlocked:!0});n.size?this.visits.set(e,n):this.visits.delete(e);let r=this.registry.get(e);if(r?.spec.trigger){let t=this.controlTarget(this.actionTarget(e,Un(r)));t&&this.controls.resetTarget(t)}if(r){for(let e of this.routes.values())if(Wn(e).includes(r.id)){for(let t of e.visited.values())t.delete(r.id);e.completed.clear(),this.missing.delete(e.id)}}this.frameGeometry?.clear()}reset(){let e=new Map;for(let[t,n]of this.visits){let r=new Map;for(let[e,t]of n)t.inside&&r.set(e,{...Gn(),inside:!0,resetBlocked:!0});r.size&&e.set(t,r)}this.stateClasses.reset(),this.controls.reset(),this.frameGeometry?.clear(),this.defaultGeometryFrame&&=new jn;for(let e of new Set([...this.visits.keys(),...this.consumed.keys(),...this.visuals.keys()]))this.restore(e);this.visits.clear();for(let[t,n]of e)this.visits.set(t,n);this.credited.clear(),this.missing.clear();for(let e of this.routes.values())e.visited.clear(),e.completed.clear()}dispose(){this.disposed||(this.reset(),this.controls.dispose(),this.visits.clear(),this.disposed=!0,this.unsubscribe(),this.routes.clear(),this.declarations.clear(),this.definitionRoutes.clear(),this.listeners.clear(),this.frameGeometry=null,this.defaultGeometryFrame=void 0)}},Qn={gun:new URL(`../embed-assets/side-gun-v1-BnpvZN1b.webp`,import.meta.url).href,rocket:new URL(`../embed-assets/roof-rocket-v1-Bs4IEw-s.webp`,import.meta.url).href},$n={gun:.55,rocket:.5},er=new Map;function tr(e){if(typeof Image>`u`)return null;let t=er.get(e);return t||(t=new Image,t.decoding=`async`,t.crossOrigin=`anonymous`,t.src=Qn[e],er.set(e,t)),t.complete&&t.naturalWidth>0?t:null}function nr(){tr(`gun`),tr(`rocket`)}function rr(e,t,n,r,i){let a=tr(t);if(!a)return!1;let o=i*a.naturalHeight/a.naturalWidth;return e.drawImage(a,n,r-o*$n[t],i,o),!0}var ir=-.65,ar=.35,or=1.04;function sr(e,t){let n=dt(e);return{x:n.xM+ar,y:t*(e.geometry.widthM/2+n.revealM*.45)}}function cr(e,t,n,r,i,a){if(a<=0)return;let o=a*a*(3-2*a),s=dt(t),c=t.geometry.widthM*n/2,l=n*.16*o;e.beginPath(),e.rect(-r*n/2,-i*n/2,r*n,i*n);for(let t of[-1,1])e.rect((s.xM+ir)*n,t>0?-c:c-l,n*or,l);e.clip(`evenodd`)}function lr(e,t,n,r,i,a,o,s=0,c=1,l){if(a<=0)return;nr();let u=dt(r),d=r.geometry.widthM*i/2,f=a*a*(3-2*a),p=u.revealM*f*i,m=i*.08*(1-f*.7);e.save(),e.translate(t.x,t.y),e.rotate(-n),e.globalAlpha*=c*Math.min(1,a*10);for(let t of[-1,1]){e.save(),e.translate(u.xM*i,-t*d),e.scale(1,-t);let n=e.createLinearGradient(0,-i*.16,0,i*.045);n.addColorStop(0,`#070b0e`),n.addColorStop(.75,`#252d31`),n.addColorStop(1,`rgba(12,18,22,0)`),e.fillStyle=n,e.fillRect(i*ir,-i*.16*f,i*or,i*.205*f);let a=Math.max(0,p-m);if(a>0){e.save(),e.beginPath(),e.rect(i*ir,0,i*1.34,a),e.clip();for(let t of[-.5,.16]){let n=e.createLinearGradient((t-.02)*i,0,(t+.02)*i,0);n.addColorStop(0,`#1b2227`),n.addColorStop(.45,`#b8c2c7`),n.addColorStop(.6,`#68767d`),n.addColorStop(1,`#242d32`),e.fillStyle=n,e.fillRect((t-.022)*i,0,i*.044,a)}let t=p*.45;e.translate(0,t);let n=o===`gun`?s*i*.018:0;if(e.shadowColor=`rgba(0,0,0,.6)`,e.shadowBlur=i*.045,e.shadowOffsetY=i*.025,!rr(e,`gun`,ir*i-n,0,i)){let t=e.createLinearGradient(0,-i*.07,0,i*.07);t.addColorStop(0,`#30383c`),t.addColorStop(.3,`#adb5b6`),t.addColorStop(.55,`#59646a`),t.addColorStop(1,`#141b20`),e.fillStyle=t,e.fillRect(ir*i,-i*.085,i*.43,i*.17),e.fillRect(-i*.22,-i*.035,i*.57,i*.07)}if(e.shadowBlur=0,e.shadowOffsetY=0,s>0){e.save(),e.globalAlpha*=s;let t=ar*i,n=i*(o===`flame`?.075:.14),r=e.createRadialGradient(t,0,0,t,0,n);r.addColorStop(0,o===`flame`?`#b2d8ff`:`#fffbea`),r.addColorStop(.22,o===`flame`?`#ffb14d`:`#ffcf75`),r.addColorStop(1,`rgba(255,128,24,0)`),e.fillStyle=r,e.fillRect(t-n,-n,n*2,n*2),o===`gun`&&(e.fillStyle=`#fff4c7`,e.beginPath(),e.moveTo(t,-i*.025),e.lineTo(t+i*.19,-i*.008),e.lineTo(t+i*.24,0),e.lineTo(t+i*.19,i*.008),e.lineTo(t,i*.025),e.closePath(),e.fill()),e.restore()}e.restore()}if(e.fillStyle=r.roofRocket.panelColor,e.strokeStyle=`#22292b`,e.lineWidth=Math.max(.8,i*.025),e.beginPath(),e.roundRect(i*ir,p-m,i*or,m*2,i*.025),e.fill(),e.stroke(),l){let n=or/l.lengthM*l.source.width,a=.16/l.widthM*l.source.height,o=l.source.x+(u.xM+ir+l.lengthM/2)/l.lengthM*l.source.width,s=-t*(r.geometry.widthM/2-.08),c=l.source.y+(s-.08+l.widthM/2)/l.widthM*l.source.height;e.save(),e.scale(1,-t),e.beginPath(),e.roundRect(i*ir,-t*p-m,i*or,m*2,i*.025),e.clip(),e.drawImage(l.image,o,c,n,a,i*ir,-t*p-m,i*or,m*2),e.restore()}e.restore()}e.restore()}function ur(e,t,n,r,i,a,o=Math.random){let s=Math.hypot(t.x,t.y)||1,c={x:t.x/s,y:t.y/s},l={x:-c.y,y:c.x},u=Math.max(.4,Math.min(2,i)),d=[];for(let t=0;t<r;t++){let t=o()<.985-a*.045,r=(t?1+o()**.65*(12+u*15):.8+o()*7)*(1-a*.38),i=(o()+o()-1)*r*(.1+o()*.32),s=t?.025+o()**2.8*n*.14:n*(.16+o()**2*(.2+a*.35));d.push({x:e.x+n*(c.x*r+l.x*i),y:e.y+n*(c.y*r+l.y*i),radius:s,angularity:t?u*(.25+o()*.75):u*o(),opacity:t?.28+o()*.62:.85+o()*.15})}return d}var dr={rangeM:10,forwardBias:1.5,chargeSeconds:1.1,statusSeconds:4,speedFactor:.5,impactRadiusM:1.6,damage:75,impulse:1,ignite:!0};function fr(e){let t={...dr,...e.lightning};for(let e of Object.keys(dr)){if(e===`ignite`)continue;let n=t[e];(!Number.isFinite(n)||n<0)&&(t[e]=dr[e])}return t.forwardBias=Math.max(0,Math.min(4,t.forwardBias)),t.rangeM=Math.max(1,Math.min(30,t.rangeM)),t.chargeSeconds=Math.max(.1,Math.min(10,t.chargeSeconds)),t.speedFactor=Math.max(.1,Math.min(1,t.speedFactor)),t.statusSeconds=Math.max(.1,Math.min(30,t.statusSeconds)),t.impactRadiusM=Math.max(.1,Math.min(10,t.impactRadiusM)),t.damage=Math.min(1e4,t.damage),t.impulse=Math.min(4,t.impulse),t.ignite=typeof t.ignite==`boolean`?t.ignite:dr.ignite,t}function pr(e,t,n=28){let r=fr(e);return e.lightning?.rangeM!==void 0||!Number.isFinite(t)||!t||n<=0?r.rangeM:Math.max(4,Math.min(60,t/(3*n)))}function mr(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=Math.hypot(i,a),s=o>.001?(i*Math.cos(n)-a*Math.sin(n))/o:1;return o*(1+Math.max(0,r)*(1-Math.max(-1,Math.min(1,s))))}var hr=class{charging=!1;charge=0;target=null;dischargeAge=1/0;dischargeId=0;dischargeTargets=[];dischargePaths=[];pending=!1;elapsed=0;captureState(){return P({charging:this.charging,charge:this.charge,target:this.target,dischargeAge:this.dischargeAge,dischargeId:this.dischargeId,dischargeTargets:this.dischargeTargets,dischargePaths:this.dischargePaths,pending:this.pending,elapsed:this.elapsed})}restoreState(e){let t=P(e);this.charging=t.charging,this.charge=t.charge,this.target=t.target,this.dischargeAge=t.dischargeAge,this.dischargeId=t.dischargeId,this.dischargeTargets=t.dischargeTargets,this.dischargePaths=t.dischargePaths,this.pending=t.pending,this.elapsed=t.elapsed}get visual(){let e=this.dischargeAge<.6;return{phase:e?`discharged`:this.charging?`charging`:`idle`,charge:this.charge,target:e?this.dischargeTargets[0]??this.dischargePaths[0]?.[0]??null:this.target,dischargeAge:this.dischargeAge,dischargeId:this.dischargeId,branches:this.dischargeTargets,paths:this.dischargePaths}}step(e,t,n,r){this.dischargeAge+=e,this.dischargeAge>.6&&(this.dischargeTargets=[],this.dischargePaths=[]),this.charging=t,t?(this.elapsed+=e,this.charge=Math.min(1,r===void 0?this.elapsed/n:1-r),(r===void 0?this.elapsed>=n:r<=0)&&(this.charge=1,this.pending=!0,this.elapsed=0,this.charging=!1)):(this.charge=this.elapsed=0,this.target=null)}takeDischarge(){let e=this.pending;return this.pending=!1,e}discharge(e,t=[]){this.dischargeTargets=e.map(e=>({...e})),this.dischargePaths=t.map(e=>e.map(e=>({...e}))),this.dischargeAge=0,this.dischargeId++}reset(){this.charging=this.pending=!1,this.charge=this.elapsed=this.dischargeId=0,this.target=null,this.dischargeAge=1/0,this.dischargeTargets=[],this.dischargePaths=[]}};function gr(){if(typeof globalThis<`u`)return globalThis;if(typeof self<`u`)return self;if(typeof window<`u`)return window;if(typeof global<`u`)return global}function _r(){let e=gr();if(e.__xstate__)return e.__xstate__}var vr=e=>{if(typeof window>`u`)return;let t=_r();t&&t.register(e)},yr=class{constructor(e){this._process=e,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(e){let t={value:e,next:null};this._current?(this._last.next=t,this._last=t):(this._current=t,this._last=t,this._active&&this.flush())}flush(){for(;this._current;){let e=this._current;this._process(e.value),this._current=e.next}this._last=null}},br=``,xr=`#`,Sr=`*`,Cr=`xstate.init`,wr=`xstate.stop`;function Tr(e,t){return{type:`xstate.after.${e}.${t}`}}function Er(e,t){return{type:`xstate.done.state.${e}`,output:t}}function Dr(e,t){return{type:`xstate.done.actor.${e}`,output:t,actorId:e}}function Or(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function kr(e){return{type:Cr,input:e}}function Z(e){setTimeout(()=>{throw e})}var Ar=typeof Symbol==`function`&&Symbol.observable||`@@observable`;function jr(e,t){let n=Nr(e),r=Nr(t);return typeof r==`string`?typeof n==`string`&&r===n:typeof n==`string`?n in r:Object.keys(n).every(e=>e in r&&jr(n[e],r[e]))}function Mr(e){if(zr(e))return e;let t=[],n=``;for(let r=0;r<e.length;r++){switch(e.charCodeAt(r)){case 92:n+=e[r+1],r++;continue;case 46:t.push(n),n=``;continue}n+=e[r]}return t.push(n),t}function Nr(e){return fa(e)?e.value:typeof e==`string`?Pr(Mr(e)):e}function Pr(e){if(e.length===1)return e[0];let t={},n=t;for(let t=0;t<e.length-1;t++)if(t===e.length-2)n[e[t]]=e[t+1];else{let r=n;n={},r[e[t]]=n}return t}function Fr(e,t){let n={},r=Object.keys(e);for(let i=0;i<r.length;i++){let a=r[i];n[a]=t(e[a],a,e,i)}return n}function Ir(e){return zr(e)?e:[e]}function Lr(e){return e===void 0?[]:Ir(e)}function Rr(e,t,n,r){return typeof e==`function`?e({context:t,event:n,self:r}):e}function zr(e){return Array.isArray(e)}function Br(e){return e.type.startsWith(`xstate.error.actor`)}function Vr(e){return Ir(e).map(e=>e===void 0||typeof e==`string`?{target:e}:e)}function Hr(e){if(e!==void 0&&e!==br)return Lr(e)}function Ur(e,t,n){let r=typeof e==`object`,i=r?e:void 0;return{next:(r?e.next:e)?.bind(i),error:(r?e.error:t)?.bind(i),complete:(r?e.complete:n)?.bind(i)}}function Wr(e,t){return`${t}.${e}`}function Gr(e,t){let n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];let[,r,i]=n,a=e.getStateNodeById(i).config.invoke;return(Array.isArray(a)?a[r]:a).src}function Kr(e,t){if(t===e||t===Sr)return!0;if(!t.endsWith(`.*`))return!1;let n=t.split(`.`),r=e.split(`.`);for(let e=0;e<n.length;e++){let t=n[e],i=r[e];if(t===`*`)return e===n.length-1;if(t!==i)return!1}return!0}function qr(e,t){return`${e.sessionId}.${t}`}var Jr=0;function Yr(e,t){let n=new Map,r=new Map,i=new WeakMap,a=new Set,o={},{clock:s,logger:c}=t,l={schedule:(e,t,n,r,i=Math.random().toString(36).slice(2))=>{let a={source:e,target:t,event:n,delay:r,id:i,startedAt:Date.now()},c=qr(e,i);u._snapshot._scheduledEvents[c]=a;let l=s.setTimeout(()=>{delete o[c],delete u._snapshot._scheduledEvents[c],u._relay(e,t,n)},r);o[c]=l},cancel:(e,t)=>{let n=qr(e,t),r=o[n];delete o[n],delete u._snapshot._scheduledEvents[n],r!==void 0&&s.clearTimeout(r)},cancelAll:e=>{for(let t in u._snapshot._scheduledEvents){let n=u._snapshot._scheduledEvents[t];n.source===e&&l.cancel(e,n.id)}}},u={_snapshot:{_scheduledEvents:(t?.snapshot&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${Jr++}`,_register:(e,t)=>(n.set(e,t),e),_unregister:e=>{n.delete(e.sessionId);let t=i.get(e);t!==void 0&&(r.delete(t),i.delete(e))},get:e=>r.get(e),getAll:()=>Object.fromEntries(r.entries()),_set:(e,t)=>{let n=r.get(e);if(n&&n!==t)throw Error(`Actor with system ID '${e}' already exists.`);r.set(e,t),i.set(t,e)},inspect:e=>{let t=Ur(e);return a.add(t),{unsubscribe(){a.delete(t)}}},_sendInspectionEvent:t=>{if(!a.size)return;let n={...t,rootId:e.sessionId};a.forEach(e=>e.next?.(n))},_relay:(e,t,n)=>{u._sendInspectionEvent({type:`@xstate.event`,sourceRef:e,actorRef:t,event:n}),t._send(n)},scheduler:l,getSnapshot:()=>({_scheduledEvents:{...u._snapshot._scheduledEvents}}),start:()=>{let e=u._snapshot._scheduledEvents;u._snapshot._scheduledEvents={};for(let t in e){let{source:n,target:r,event:i,delay:a,id:o}=e[t];l.schedule(n,r,i,a,o)}},_clock:s,_logger:c};return u}var Xr=!1,Q=function(e){return e[e.NotStarted=0]=`NotStarted`,e[e.Running=1]=`Running`,e[e.Stopped=2]=`Stopped`,e}({}),Zr={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1},Qr=class{constructor(e,t){this.logic=e,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new yr(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=Q.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];let n={...Zr,...t},{clock:r,logger:i,parent:a,syncSnapshot:o,id:s,systemId:c,inspect:l}=n;this.system=a?a.system:Yr(this,{clock:r,logger:i}),l&&!a&&this.system.inspect(Ur(l)),this.sessionId=this.system._bookId(),this.id=s??this.sessionId,this.logger=t?.logger??this.system._logger,this.clock=t?.clock??this.system._clock,this._parent=a,this._syncSnapshot=o,this.options=n,this.src=n.src??e,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:e=>{this._deferred.push(e)},system:this.system,stopChild:e=>{if(e._parent!==this)throw Error(`Cannot stop child actor ${e.id} of ${this.id} because it is not a child`);e._stop()},emit:e=>{let t=this.eventListeners.get(e.type),n=this.eventListeners.get(`*`);if(!t&&!n)return;let r=[...t?t.values():[],...n?n.values():[]];for(let t of r)try{t(e)}catch(e){Z(e)}},actionExecutor:e=>{let t=()=>{if(this._actorScope.system._sendInspectionEvent({type:`@xstate.action`,actorRef:this,action:{type:e.type,params:e.params}}),!e.exec)return;let t=Xr;try{Xr=!0,e.exec(e.info,e.params)}finally{Xr=t}};this._processingStatus===Q.Running?t():this._deferred.push(t)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:`@xstate.actor`,actorRef:this}),c&&(this.systemId=c,this.system._set(c,this)),this._initState(t?.snapshot??t?.state),c&&this._snapshot.status!==`active`&&this.system._unregister(this)}_initState(e){try{this._snapshot=e?this.logic.restoreSnapshot?this.logic.restoreSnapshot(e,this._actorScope):e:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(e){this._snapshot={status:`error`,output:void 0,error:e}}}update(e,t){this._snapshot=e;let n;for(;n=this._deferred.shift();)try{n()}catch(t){this._deferred.length=0,this._snapshot={...e,status:`error`,error:t}}switch(this._snapshot.status){case`active`:for(let t of this.observers)try{t.next?.(e)}catch(e){Z(e)}break;case`done`:for(let t of this.observers)try{t.next?.(e)}catch(e){Z(e)}this._stopProcedure(),this._complete(),this._doneEvent=Dr(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case`error`:this._error(this._snapshot.error)}this.system._sendInspectionEvent({type:`@xstate.snapshot`,actorRef:this,event:t,snapshot:e})}subscribe(e,t,n){let r=Ur(e,t,n);if(this._processingStatus!==Q.Stopped)this.observers.add(r);else switch(this._snapshot.status){case`done`:try{r.complete?.()}catch(e){Z(e)}break;case`error`:{let e=this._snapshot.error;if(!r.error)Z(e);else try{r.error(e)}catch(e){Z(e)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(e,t){let n=this.eventListeners.get(e);n||(n=new Set,this.eventListeners.set(e,n));let r=t.bind(void 0);return n.add(r),{unsubscribe:()=>{n.delete(r)}}}select(e,t=Object.is){return{subscribe:n=>{let r=Ur(n),i=e(this.getSnapshot());return this.subscribe(n=>{let a=e(n);t(i,a)||(i=a,r.next?.(a))})},get:()=>e(this.getSnapshot())}}start(){if(this._processingStatus===Q.Running)return this;this._syncSnapshot&&this.subscribe({next:e=>{e.status===`active`&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:e})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=Q.Running;let e=kr(this.options.input);switch(this.system._sendInspectionEvent({type:`@xstate.event`,sourceRef:this._parent,actorRef:this,event:e}),this._snapshot.status){case`done`:return this.update(this._snapshot,e),this;case`error`:return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(e){return this._snapshot={...this._snapshot,status:`error`,error:e},this._error(e),this}return this.update(this._snapshot,e),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(e){let t,n;try{t=this.logic.transition(this._snapshot,e,this._actorScope)}catch(e){n={err:e}}if(n){let{err:e}=n;this._snapshot={...this._snapshot,status:`error`,error:e},this._error(e)}else this.update(t,e),e.type===`xstate.stop`&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===Q.Stopped?this:(this.mailbox.clear(),this._processingStatus===Q.NotStarted?(this._processingStatus=Q.Stopped,this):(this.mailbox.enqueue({type:wr}),this))}stop(){if(this._parent)throw Error(`A non-root actor cannot be stopped directly.`);return this._stop()}_complete(){for(let e of this.observers)try{e.complete?.()}catch(e){Z(e)}this.observers.clear(),this.eventListeners.clear()}_reportError(e){if(!this.observers.size){this._parent||Z(e),this.eventListeners.clear();return}let t=!1;for(let n of this.observers){let r=n.error;t||=!r;try{r?.(e)}catch(e){Z(e)}}this.observers.clear(),this.eventListeners.clear(),t&&Z(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,Or(this.id,e))}_stopProcedure(){return this._processingStatus===Q.Running&&(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new yr(this._process.bind(this)),this._processingStatus=Q.Stopped,this.system._unregister(this)),this}_send(e){this._processingStatus!==Q.Stopped&&this.mailbox.enqueue(e)}send(e){this.system._relay(void 0,this,e)}attachDevTools(){let{devTools:e}=this.options;e&&(typeof e==`function`?e:vr)(this)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[Ar](){return this}getSnapshot(){return this._snapshot}};function $r(e,...[t]){return new Qr(e,t)}function ei(e,t,n,r,{sendId:i}){return[t,{sendId:typeof i==`function`?i(n,r):i},void 0]}function ti(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t.sendId)})}function ni(e){function t(e,t){}return t.type=`xstate.cancel`,t.sendId=e,t.resolve=ei,t.execute=ti,t}function ri(e,t,n,r,{id:i,systemId:a,src:o,input:s,syncSnapshot:c}){let l=typeof o==`string`?Gr(t.machine,o):o,u=typeof i==`function`?i(n):i,d,f;return l&&(f=typeof s==`function`?s({context:t.context,event:n.event,self:e.self}):s,d=$r(l,{id:u,src:o,parent:e.self,syncSnapshot:c,systemId:a,input:f})),[ya(t,{children:{...t.children,[u]:d}}),{id:i,systemId:a,actorRef:d,src:o,input:f},void 0]}function ii(e,{actorRef:t}){t&&e.defer(()=>{t._processingStatus!==Q.Stopped&&t.start()})}function ai(...[e,{id:t,systemId:n,input:r,syncSnapshot:i=!1}={}]){function a(e,t){}return a.type=`xstate.spawnChild`,a.id=t,a.systemId=n,a.src=e,a.input=r,a.syncSnapshot=i,a.resolve=ri,a.execute=ii,a}function oi(e,t,n,r,{actorRef:i}){let a=typeof i==`function`?i(n,r):i,o=typeof a==`string`?t.children[a]:a,s=t.children;return o&&(s={...s},delete s[o.id]),[ya(t,{children:s}),o,void 0]}function si(e,t){let n=t.getSnapshot();if(n&&`children`in n)for(let t of Object.values(n.children))si(e,t);e.system._unregister(t)}function ci(e,t){t&&(si(e,t),t._processingStatus===Q.Running?e.defer(()=>{e.stopChild(t)}):e.stopChild(t))}function li(e){function t(e,t){}return t.type=`xstate.stopChild`,t.actorRef=e,t.resolve=oi,t.execute=ci,t}function ui(e,{context:t,event:n},{guards:r}){return r.every(r=>fi(r,t,n,e))}function di(e){function t(e,t){return!1}return t.check=ui,t.guards=e,t}function fi(e,t,n,r){let{machine:i}=r,a=typeof e==`function`,o=a?e:i.implementations.guards[typeof e==`string`?e:e.type];if(!a&&!o)throw Error(`Guard '${typeof e==`string`?e:e.type}' is not implemented.'.`);if(typeof o!=`function`)return fi(o,t,n,r);let s={context:t,event:n},c=a||typeof e==`string`?void 0:`params`in e?typeof e.params==`function`?e.params({context:t,event:n}):e.params:void 0;return`check`in o?o.check(r,s,o):o(s,c)}function pi(e){return e.type===`atomic`||e.type===`final`}function mi(e){return Object.values(e.states).filter(e=>e.type!==`history`)}function hi(e,t){let n=[];if(t===e)return n;let r=e.parent;for(;r&&r!==t;)n.push(r),r=r.parent;return n}function gi(e){let t=new Set(e),n=vi(t);for(let e of t)if(e.type===`compound`&&(!n.get(e)||!n.get(e).length))ji(e).forEach(e=>t.add(e));else if(e.type===`parallel`){for(let n of mi(e))if(n.type!==`history`&&!t.has(n)){let e=ji(n);for(let n of e)t.add(n)}}for(let e of t){let n=e.parent;for(;n;)t.add(n),n=n.parent}return t}function _i(e,t){let n=t.get(e);if(!n)return{};if(e.type===`compound`){let e=n[0];if(e){if(pi(e))return e.key}else return{}}let r={};for(let e of n)r[e.key]=_i(e,t);return r}function vi(e){let t=new Map;for(let n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function yi(e,t){return _i(e,vi(gi(t)))}function bi(e,t){return t.type===`compound`?mi(t).some(t=>t.type===`final`&&e.has(t)):t.type===`parallel`?mi(t).every(t=>bi(e,t)):t.type===`final`}var xi=e=>e[0]===xr;function Si(e,t){let n=e.transitions.get(t),r=[...e.transitions.keys()].filter(e=>e!==t&&Kr(t,e)).sort((e,t)=>t.length-e.length).flatMap(t=>e.transitions.get(t));return n?[...n,...r]:r}function Ci(e){let t=e.config.after;if(!t)return[];let n=t=>{let n=Tr(t,e.id),r=n.type;return e.entry.push(Ta(n,{id:r,delay:t})),e.exit.push(ni(r)),r};return Object.keys(t).flatMap(e=>{let r=t[e],i=typeof r==`string`?{target:r}:r,a=Number.isNaN(+e)?e:+e,o=n(a);return Lr(i).map(e=>({...e,event:o,delay:a}))}).map(t=>{let{delay:n}=t;return{...wi(e,t.event,t),delay:n}})}function wi(e,t,n){let r=Hr(n.target),i=n.reenter??!1,a=Oi(e,r),o={...n,actions:Lr(n.actions),guard:n.guard,target:a,source:e,reenter:i,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:a?a.map(e=>`#${e.id}`):void 0})};return o}function Ti(e){let t=new Map;if(e.config.on)for(let n of Object.keys(e.config.on)){if(n===``)throw Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');let r=e.config.on[n];t.set(n,Vr(r).map(t=>wi(e,n,t)))}if(e.config.onDone){let n=`xstate.done.state.${e.id}`;t.set(n,Vr(e.config.onDone).map(t=>wi(e,n,t)))}for(let n of e.invoke){if(n.onDone){let r=`xstate.done.actor.${n.id}`;t.set(r,Vr(n.onDone).map(t=>wi(e,r,t)))}if(n.onError){let r=`xstate.error.actor.${n.id}`;t.set(r,Vr(n.onError).map(t=>wi(e,r,t)))}if(n.onSnapshot){let r=`xstate.snapshot.${n.id}`;t.set(r,Vr(n.onSnapshot).map(t=>wi(e,r,t)))}}for(let n of e.after){let e=t.get(n.eventType);e||(e=[],t.set(n.eventType,e)),e.push(n)}return t}function Ei(e){let t=[],n=r=>{Object.values(r).forEach(r=>{if(r.config.route&&r.config.id){let n=r.config.id,i=r.config.route.guard,a=({event:e})=>e.to===`#${n}`,o={...r.config.route,guard:i?di([a,i]):a,target:`#${n}`};t.push(wi(e,`xstate.route`,o))}r.states&&n(r.states)})};n(e.states),t.length>0&&e.transitions.set(`xstate.route`,t)}function Di(e,t){let n=typeof t==`string`?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw Error(`Initial state node "${t}" not found on parent state node #${e.id}`);let r={source:e,actions:!t||typeof t==`string`?[]:Lr(t.actions),eventType:null,reenter:!1,target:n?[n]:[],meta:typeof t==`object`?t.meta:void 0,description:typeof t==`object`?t.description:void 0,toJSON:()=>({...r,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return r}function Oi(e,t){if(t!==void 0)return t.map(t=>{if(typeof t!=`string`)return t;if(xi(t))return e.machine.getStateNodeById(t);let n=t[0]===`.`;if(n&&!e.parent)return Pi(e,t.slice(1));let r=n?e.key+t:t;if(e.parent)try{return Pi(e.parent,r)}catch(t){throw Error(`Invalid transition definition for state node '${e.id}':\n${t.message}`)}throw Error(`Invalid target: "${t}" is not a valid target from the root node. Did you mean ".${t}"?`)})}function ki(e){let t=Hr(e.config.target);return t?{target:t.map(t=>typeof t==`string`?Pi(e.parent,t):t)}:e.parent.type===`parallel`?{target:[e.parent]}:e.parent.initial}function Ai(e){return e.type===`history`}function ji(e){let t=Mi(e);for(let n of t)for(let r of hi(n,e))t.add(r);return t}function Mi(e){let t=new Set;function n(e){if(!t.has(e)){if(t.add(e),e.type===`compound`)n(e.initial.target[0]);else if(e.type===`parallel`)for(let t of mi(e))n(t)}}return n(e),t}function Ni(e,t){if(xi(t))return e.machine.getStateNodeById(t);if(!e.states)throw Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);let n=e.states[t];if(!n)throw Error(`Child state '${t}' does not exist on '${e.id}'`);return n}function Pi(e,t){if(typeof t==`string`&&xi(t))try{return e.machine.getStateNodeById(t)}catch{}let n=Mr(t).slice(),r=e;for(;n.length;){let e=n.shift();if(!e.length)break;r=Ni(r,e)}return r}function Fi(e,t){if(typeof t==`string`){let n=e.states[t];if(!n)throw Error(`State '${t}' does not exist on '${e.id}'`);return[e,n]}let n=Object.keys(t),r=n.map(t=>Ni(e,t)).filter(Boolean);return[e.machine.root,e].concat(r,n.reduce((n,r)=>{let i=Ni(e,r);if(!i)return n;let a=Fi(i,t[r]);return n.concat(a)},[]))}function Ii(e,t,n,r){let i=Ni(e,t).next(n,r);return!i||!i.length?e.next(n,r):i}function Li(e,t,n,r){let i=Object.keys(t),a=zi(Ni(e,i[0]),t[i[0]],n,r);return!a||!a.length?e.next(n,r):a}function Ri(e,t,n,r){let i=[];for(let a of Object.keys(t)){let o=t[a];if(!o)continue;let s=zi(Ni(e,a),o,n,r);s&&i.push(...s)}return i.length?i:e.next(n,r)}function zi(e,t,n,r){return typeof t==`string`?Ii(e,t,n,r):Object.keys(t).length===1?Li(e,t,n,r):Ri(e,t,n,r)}function Bi(e){return Object.keys(e.states).map(t=>e.states[t]).filter(e=>e.type===`history`)}function Vi(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function Hi(e,t){let n=new Set(e),r=new Set(t);for(let e of n)if(r.has(e))return!0;for(let e of r)if(n.has(e))return!0;return!1}function Ui(e,t,n){let r=new Set;for(let i of e){let e=!1,a=new Set;for(let o of r)if(Hi(qi([i],t,n),qi([o],t,n))){if(Vi(i.source,o.source))a.add(o);else{e=!0;break}}if(!e){for(let e of a)r.delete(e);r.add(i)}}return Array.from(r)}function Wi(e){let[t,...n]=e;for(let e of hi(t,void 0))if(n.every(t=>Vi(t,e)))return e}function Gi(e,t){if(!e.target)return[];let n=new Set;for(let r of e.target)if(Ai(r)){if(t[r.id])for(let e of t[r.id])n.add(e);else for(let e of Gi(ki(r),t))n.add(e)}else n.add(r);return[...n]}function Ki(e,t){let n=Gi(e,t);if(!n)return;if(!e.reenter&&n.every(t=>t===e.source||Vi(t,e.source)))return e.source;let r=Wi(n.concat(e.source));if(r)return r;if(!e.reenter)return e.source.machine.root}function qi(e,t,n){let r=new Set;for(let i of e)if(i.target?.length){let e=Ki(i,n);i.reenter&&i.source===e&&r.add(e);for(let n of t)Vi(n,e)&&r.add(n)}return[...r]}function Ji(e,t){if(e.length!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Yi(e,t,n,r,i){return Xi([{target:[...Mi(e)],source:e,reenter:!0,actions:[],eventType:null,toJSON:null}],t,n,r,!0,i)}function Xi(e,t,n,r,i,a){let o=[];if(!e.length)return[t,o];let s=n.actionExecutor;n.actionExecutor=e=>{o.push(e),s(e)};try{let s=new Set(t._nodes),c=t.historyValue,l=Ui(e,s,c),u=t;i||([u,c]=ra(u,r,n,l,s,c,a,n.actionExecutor)),u=oa(u,r,n,l.flatMap(e=>e.actions),a,void 0),u=Qi(u,r,n,l,s,a,c,i);let d=[...s];u.status===`done`&&(u=oa(u,r,n,d.sort((e,t)=>t.order-e.order).flatMap(e=>e.exit),a,void 0));try{return c===t.historyValue&&Ji(t._nodes,s)?[u,o]:[ya(u,{_nodes:d,historyValue:c}),o]}catch(e){throw e}}finally{n.actionExecutor=s}}function Zi(e,t,n,r,i){if(r.output===void 0)return;let a=Er(i.id,i.output!==void 0&&i.parent?Rr(i.output,e.context,t,n.self):void 0);return Rr(r.output,e.context,a,n.self)}function Qi(e,t,n,r,i,a,o,s){let c=e,l=new Set,u=new Set;$i(r,o,u,l),s&&u.add(e.machine.root);let d=new Set;for(let e of[...l].sort((e,t)=>e.order-t.order)){i.add(e);let r=[];r.push(...e.entry);for(let t of e.invoke)r.push(ai(t.src,{...t,syncSnapshot:!!t.onSnapshot}));if(u.has(e)){let t=e.initial.actions;r.push(...t)}if(c=oa(c,t,n,r,a,e.invoke.map(e=>e.id)),e.type===`final`){let r=e.parent,o=r?.type===`parallel`?r:r?.parent,s=o||e;for(r?.type===`compound`&&a.push(Er(r.id,e.output===void 0?void 0:Rr(e.output,c.context,t,n.self)));o?.type===`parallel`&&!d.has(o)&&bi(i,o);)d.add(o),a.push(Er(o.id)),s=o,o=o.parent;if(o)continue;c=ya(c,{status:`done`,output:Zi(c,t,n,c.machine.root,s)})}}return c}function $i(e,t,n,r){for(let i of e){let e=Ki(i,t);for(let a of i.target||[])!Ai(a)&&(i.source!==a||i.source!==e||i.reenter)&&(r.add(a),n.add(a)),ea(a,t,n,r);let a=Gi(i,t);for(let o of a){let a=hi(o,e);e?.type===`parallel`&&a.push(e),ta(r,t,n,a,!i.source.parent&&i.reenter?void 0:e)}}}function ea(e,t,n,r){if(Ai(e)){if(t[e.id]){let i=t[e.id];for(let e of i)r.add(e),ea(e,t,n,r);for(let a of i)na(a,e.parent,r,t,n)}else{let i=ki(e);for(let a of i.target)r.add(a),i===e.parent?.initial&&n.add(e.parent),ea(a,t,n,r);for(let a of i.target)na(a,e.parent,r,t,n)}}else if(e.type===`compound`){let[i]=e.initial.target;Ai(i)||(r.add(i),n.add(i)),ea(i,t,n,r),na(i,e,r,t,n)}else if(e.type===`parallel`)for(let i of mi(e).filter(e=>!Ai(e)))[...r].some(e=>Vi(e,i))||(Ai(i)||(r.add(i),n.add(i)),ea(i,t,n,r))}function ta(e,t,n,r,i){for(let a of r)if((!i||Vi(a,i))&&e.add(a),a.type===`parallel`)for(let r of mi(a).filter(e=>!Ai(e)))[...e].some(e=>Vi(e,r))||(e.add(r),ea(r,t,n,e))}function na(e,t,n,r,i){ta(n,r,i,hi(e,t))}function ra(e,t,n,r,i,a,o,s){let c=e,l=qi(r,i,a);l.sort((e,t)=>t.order-e.order);let u;for(let e of l)for(let t of Bi(e)){let n;n=t.history===`deep`?t=>pi(t)&&Vi(t,e):t=>t.parent===e,u??={...a},u[t.id]=Array.from(i).filter(n)}for(let e of l)c=oa(c,t,n,[...e.exit,...e.invoke.map(e=>li(e.id))],o,void 0),i.delete(e);return[c,u||a]}function ia(e,t){return e.implementations.actions[t]}function aa(e,t,n,r,i,a){let{machine:o}=e,s=e;for(let e of r){let r=typeof e==`function`,c=r?e:ia(o,typeof e==`string`?e:e.type),l={context:s.context,event:t,self:n.self,system:n.system},u=r||typeof e==`string`?void 0:`params`in e?typeof e.params==`function`?e.params({context:s.context,event:t}):e.params:void 0;if(!c||!(`resolve`in c)){n.actionExecutor({type:typeof e==`string`?e:typeof e==`object`?e.type:e.name||`(anonymous)`,info:l,params:u,exec:c});continue}let d=c,[f,p,m]=d.resolve(n,s,l,u,c,i);s=f,`retryResolve`in d&&a?.push([d,p]),`execute`in d&&n.actionExecutor({type:d.type,info:l,params:p,exec:d.execute.bind(null,n,p)}),m&&(s=aa(s,t,n,m,i,a))}return s}function oa(e,t,n,r,i,a){let o=a?[]:void 0,s=aa(e,t,n,r,{internalQueue:i,deferredActorIds:a},o);return o?.forEach(([e,t])=>{e.retryResolve(n,s,t)}),s}function sa(e,t,n,r){let i=e,a=[];function o(e,t,r){n.system._sendInspectionEvent({type:`@xstate.microstep`,actorRef:n.self,event:t,snapshot:e[0],_transitions:r}),a.push(e)}if(t.type===`xstate.stop`)return i=ya(ca(i,t,n),{status:`stopped`}),o([i,[]],t,[]),{snapshot:i,microsteps:a};let s=t;if(s.type!==Cr){let t=s,c=Br(t),l=la(t,i);if(c&&!l.length)return i=ya(ca(i,t,n),{status:`error`,error:t.error}),o([i,[]],t,[]),{snapshot:i,microsteps:a};let u=Xi(l,e,n,s,!1,r);i=u[0],o(u,t,l)}let c=!0,l=e.machine.options?.maxIterations??1/0,u=0;for(;i.status===`active`;){if(u++,u>l)throw Error(`Infinite loop detected: the machine has processed more than ${l} microsteps without reaching a stable state. This usually happens when there's a cycle of transitions (e.g., eventless transitions or raised events causing state A -> B -> C -> A).`);let e=c?ua(i,s):[],t=e.length?i:void 0;if(!e.length){if(!r.length)break;s=r.shift(),e=la(s,i)}let a=Xi(e,i,n,s,!1,r);i=a[0],c=i!==t,o(a,s,e)}return i.status!==`active`&&ca(i,s,n),{snapshot:i,microsteps:a}}function ca(e,t,n){return oa(e,t,n,Object.values(e.children).map(e=>li(e)),[],void 0)}function la(e,t){return t.machine.getTransitionData(t,e)}function ua(e,t){let n=new Set,r=e._nodes.filter(pi);for(let i of r)loop:for(let r of[i].concat(hi(i,void 0)))if(r.always){for(let i of r.always)if(i.guard===void 0||fi(i.guard,e.context,t,e)){n.add(i);break loop}}return Ui(Array.from(n),new Set(e._nodes),e.historyValue)}function da(e,t){return yi(e,[...gi(Fi(e,t))])}function fa(e){return!!e&&typeof e==`object`&&`machine`in e&&`value`in e}var pa=function(e){return jr(e,this.value)},ma=function(e){return this.tags.has(e)},ha=function(e){let t=this.machine.getTransitionData(this,e);return!!t?.length&&t.some(e=>e.target!==void 0||e.actions.length)},ga=function(){let{_nodes:e,tags:t,machine:n,getMeta:r,toJSON:i,can:a,hasTag:o,matches:s,...c}=this;return{...c,tags:Array.from(t)}},_a=function(){return this._nodes.reduce((e,t)=>(t.meta!==void 0&&(e[t.id]=t.meta),e),{})};function va(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:yi(t.root,e._nodes),tags:new Set(e._nodes.flatMap(e=>e.tags)),children:e.children,historyValue:e.historyValue||{},matches:pa,hasTag:ma,can:ha,getMeta:_a,toJSON:ga}}function ya(e,t={}){return va({...e,...t},e.machine)}function ba(e){if(typeof e!=`object`||!e)return{};let t={};for(let n in e){let r=e[n];Array.isArray(r)&&(t[n]=r.map(e=>({id:e.id})))}return t}function xa(e,t){let{_nodes:n,tags:r,machine:i,children:a,context:o,can:s,hasTag:c,matches:l,getMeta:u,toJSON:d,...f}=e,p={};for(let e in a){let n=a[e];p[e]={snapshot:n.getPersistedSnapshot(t),src:n.src,systemId:n.systemId,syncSnapshot:n._syncSnapshot}}return{...f,context:Sa(o),children:p,historyValue:ba(f.historyValue)}}function Sa(e){let t;for(let n in e){let r=e[n];if(r&&typeof r==`object`){if(`sessionId`in r&&`send`in r&&`ref`in r)t??=Array.isArray(e)?e.slice():{...e},t[n]={xstate$$type:1,id:r.id};else{let i=Sa(r);i!==r&&(t??=Array.isArray(e)?e.slice():{...e},t[n]=i)}}}return t??e}function Ca(e,t,n,r,{event:i,id:a,delay:o},{internalQueue:s}){let c=t.machine.implementations.delays;if(typeof i==`string`)throw Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);let l=typeof i==`function`?i(n,r):i,u;if(typeof o==`string`){let e=c&&c[o];u=typeof e==`function`?e(n,r):e}else u=typeof o==`function`?o(n,r):o;return typeof u!=`number`&&s.push(l),[t,{event:l,id:a,delay:u},void 0]}function wa(e,t){let{event:n,delay:r,id:i}=t;typeof r==`number`&&e.defer(()=>{let t=e.self;e.system.scheduler.schedule(t,t,n,r,i)})}function Ta(e,t){function n(e,t){}return n.type=`xstate.raise`,n.event=e,n.id=t?.id,n.delay=t?.delay,n.resolve=Ca,n.execute=wa,n}function Ea(e,{machine:t,context:n},r,i){let a=(a,o)=>{if(typeof a==`string`){let s=Gr(t,a);if(!s)throw Error(`Actor logic '${a}' not implemented in machine '${t.id}'`);let c=$r(s,{id:o?.id,parent:e.self,syncSnapshot:o?.syncSnapshot,input:typeof o?.input==`function`?o.input({context:n,event:r,self:e.self}):o?.input,src:a,systemId:o?.systemId});return i[c.id]=c,c}return $r(a,{id:o?.id,parent:e.self,syncSnapshot:o?.syncSnapshot,input:o?.input,src:a,systemId:o?.systemId})};return(t,n)=>{let r=a(t,n);return i[r.id]=r,e.defer(()=>{r._processingStatus!==Q.Stopped&&r.start()}),r}}function Da(e,t,n,r,{assignment:i}){if(!t.context)throw Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");let a={},o={context:t.context,event:n.event,spawn:Ea(e,t,n.event,a),self:e.self,system:e.system},s={};if(typeof i==`function`)s=i(o,r);else for(let e of Object.keys(i)){let t=i[e];s[e]=typeof t==`function`?t(o,r):t}return[ya(t,{context:Object.assign({},t.context,s),children:Object.keys(a).length?{...t.children,...a}:t.children}),void 0,void 0]}function Oa(e){function t(e,t){}return t.type=`xstate.assign`,t.assignment=e,t.resolve=Da,t}var ka=new WeakMap;function Aa(e,t,n){let r=ka.get(e);return r?t in r||(r[t]=n()):(r={[t]:n()},ka.set(e,r)),r[t]}var ja={},Ma=e=>typeof e==`string`?{type:e}:typeof e==`function`?`resolve`in e?{type:e.type}:{type:e.name}:e,Na=class e{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(`.`),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?`compound`:this.config.history?`history`:`atomic`),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?Fr(this.config.states,(t,n)=>new e(t,{_parent:this,_key:n,_machine:this.machine})):ja,this.type===`compound`&&!this.config.initial)throw Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?`shallow`:this.config.history||!1,this.entry=Lr(this.config.entry).slice(),this.exit=Lr(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type===`final`||!this.parent?this.config.output:void 0,this.tags=Lr(t.tags).slice()}_initialize(){this.transitions=Ti(this),this.config.always&&(this.always=Vr(this.config.always).map(e=>wi(this,``,e))),Object.keys(this.states).forEach(e=>{this.states[e]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(Ma),eventType:null,reenter:!1,meta:this.initial.meta,description:this.initial.description,toJSON:()=>({target:this.initial.target.map(e=>`#${e.id}`),source:`#${this.id}`,actions:this.initial.actions.map(Ma),eventType:null,meta:this.initial.meta,description:this.initial.description})}:void 0,history:this.history,states:Fr(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(Ma)})),entry:this.entry.map(Ma),exit:this.exit.map(Ma),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return Aa(this,`invoke`,()=>Lr(this.config.invoke).map((e,t)=>{let{src:n,systemId:r}=e,i=e.id??Wr(this.id,t),a=typeof n==`string`?n:`xstate.invoke.${Wr(this.id,t)}`;return{...e,src:a,id:i,systemId:r,toJSON(){let{onDone:t,onError:n,...r}=e;return{...r,type:`xstate.invoke`,src:a,id:i}}}}))}get on(){return Aa(this,`on`,()=>[...this.transitions].flatMap(([e,t])=>t.map(t=>[e,t])).reduce((e,[t,n])=>(e[t]=e[t]||[],e[t].push(n),e),{}))}get after(){return Aa(this,`delayedTransitions`,()=>Ci(this))}get initial(){return Aa(this,`initial`,()=>Di(this,this.config.initial))}next(e,t){let n=t.type,r=[],i,a=Aa(this,`candidates-${n}`,()=>Si(this,n));for(let o of a){let{guard:a}=o,s=e.context,c=!1;try{c=!a||fi(a,s,t,e)}catch(e){let t=typeof a==`string`?a:typeof a==`object`?a.type:void 0;throw Error(`Unable to evaluate guard ${t?`'${t}' `:``}in transition for event '${n}' in state node '${this.id}':\n${e.message}`)}if(c){r.push(...o.actions),i=o;break}}return i?[i]:void 0}get events(){return Aa(this,`events`,()=>{let{states:e}=this,t=new Set(this.ownEvents);if(e)for(let n of Object.keys(e)){let r=e[n];if(r.states)for(let e of r.events)t.add(`${e}`)}return Array.from(t)})}get ownEvents(){let e=Object.keys(Object.fromEntries(this.transitions)),t=new Set(e.filter(e=>this.transitions.get(e).some(e=>!(!e.target&&!e.actions.length&&!e.reenter))));return Array.from(t)}},Pa=class e{constructor(e,t){this.config=e,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.options=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=e.id||`(machine)`,this.implementations={actors:t?.actors??{},actions:t?.actions??{},delays:t?.delays??{},guards:t?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.options={maxIterations:1/0,...this.config.options},this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new Na(e,{_key:this.id,_machine:this}),this.root._initialize(),Ei(this.root),this.states=this.root.states,this.events=this.root.events}provide(t){let{actions:n,guards:r,actors:i,delays:a}=this.implementations;return new e(this.config,{actions:{...n,...t.actions},guards:{...r,...t.guards},actors:{...i,...t.actors},delays:{...a,...t.delays}})}resolveState(e){let t=da(this.root,e.value),n=gi(Fi(this.root,t));return va({_nodes:[...n],context:e.context||{},children:{},status:bi(n,this.root)?`done`:e.status||`active`,output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,t,n){return sa(e,t,n,[]).snapshot}microstep(e,t,n){return sa(e,t,n,[]).microsteps.map(([e])=>e)}getTransitionData(e,t){return zi(this.root,e.value,e,t)||[]}_getPreInitialState(e,t,n){let{context:r}=this.config,i=va({context:typeof r!=`function`&&r?r:{},_nodes:[this.root],children:{},status:`active`},this);return typeof r==`function`?oa(i,t,e,[Oa(({spawn:e,event:t,self:n})=>r({spawn:e,input:t.input,self:n}))],n,void 0):i}getInitialSnapshot(e,t){let n=kr(t),r=[],i=va({context:typeof this.config.context!=`function`&&this.config.context?this.config.context:{},_nodes:[this.root],children:{},status:`active`},this);try{i=this._getPreInitialState(e,n,r);let[t]=Yi(this.root,i,e,n,r),{snapshot:a}=sa(t,n,e,r);return a}catch(e){return ya(i,{status:`error`,error:e})}}start(e){Object.values(e.children).forEach(e=>{e.getSnapshot().status===`active`&&e.start()})}getStateNodeById(e){let t=Mr(e),n=t.slice(1),r=xi(t[0])?t[0].slice(1):t[0],i=this.idMap.get(r);if(!i)throw Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return Pi(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,t){return xa(e,t)}restoreSnapshot(e,t){let n={},r=e.children;Object.keys(r).forEach(e=>{let i=r[e],a=i.snapshot,o=i.src,s=typeof o==`string`?Gr(this,o):o;if(!s)return;let c=$r(s,{id:e,parent:t.self,syncSnapshot:i.syncSnapshot,snapshot:a,src:o,systemId:i.systemId});n[e]=c});function i(e,t){if(t instanceof Na)return t;try{return e.machine.getStateNodeById(t.id)}catch{}}function a(e,t){if(!t||typeof t!=`object`)return{};let n={};for(let r in t){let a=t[r];for(let t of a){let a=i(e,t);a&&(n[r]??=[],n[r].push(a))}}return n}let o=a(this.root,e.historyValue),s=va({...e,children:n,_nodes:Array.from(gi(Fi(this.root,e.value))),historyValue:o},this),c=new Set;function l(e,t){if(!c.has(e)){c.add(e);for(let n in e){let r=e[n];if(r&&typeof r==`object`){if(`xstate$$type`in r&&r.xstate$$type===1){e[n]=t[r.id];continue}l(r,t)}}}}return l(s.context,n),s}};function Fa(e,t,n,r,{event:i}){return[t,{event:typeof i==`function`?i(n,r):i},void 0]}function Ia(e,{event:t}){e.defer(()=>e.emit(t))}function La(e){function t(e,t){}return t.type=`xstate.emit`,t.event=e,t.resolve=Fa,t.execute=Ia,t}var Ra=function(e){return e.Parent=`#_parent`,e.Internal=`#_internal`,e}({});function za(e,t,n,r,{to:i,event:a,id:o,delay:s},c){let l=t.machine.implementations.delays;if(typeof a==`string`)throw Error(`Only event objects may be used with sendTo; use sendTo({ type: "${a}" }) instead`);let u=typeof a==`function`?a(n,r):a,d;if(typeof s==`string`){let e=l&&l[s];d=typeof e==`function`?e(n,r):e}else d=typeof s==`function`?s(n,r):s;let f=typeof i==`function`?i(n,r):i,p;if(typeof f==`string`){if(p=f===Ra.Parent?e.self._parent:f===Ra.Internal?e.self:f.startsWith(`#_`)?t.children[f.slice(2)]:c.deferredActorIds?.includes(f)?f:t.children[f],!p)throw Error(`Unable to send event to actor '${f}' from machine '${t.machine.id}'.`)}else p=f||e.self;return[t,{to:p,targetId:typeof f==`string`?f:void 0,event:u,id:o,delay:d},void 0]}function Ba(e,t,n){typeof n.to==`string`&&(n.to=t.children[n.to])}function Va(e,t){e.defer(()=>{let{to:n,event:r,delay:i,id:a}=t;typeof i==`number`?e.system.scheduler.schedule(e.self,n,r,i,a):e.system._relay(e.self,n,r.type===`xstate.error`?Or(e.self.id,r.data):r)})}function Ha(e,t,n){function r(e,t){}return r.type=`xstate.sendTo`,r.to=e,r.event=t,r.id=n?.id,r.delay=n?.delay,r.resolve=za,r.retryResolve=Ba,r.execute=Va,r}function Ua(e,t){return Ha(Ra.Parent,e,t)}function Wa(e,t,n,r,{collect:i}){let a=[],o=function(e){a.push(e)};return o.assign=(...e)=>{a.push(Oa(...e))},o.cancel=(...e)=>{a.push(ni(...e))},o.raise=(...e)=>{a.push(Ta(...e))},o.sendTo=(...e)=>{a.push(Ha(...e))},o.sendParent=(...e)=>{a.push(Ua(...e))},o.spawnChild=(...e)=>{a.push(ai(...e))},o.stopChild=(...e)=>{a.push(li(...e))},o.emit=(...e)=>{a.push(La(...e))},i({context:n.context,event:n.event,enqueue:o,check:e=>fi(e,t.context,n.event,t),self:e.self,system:e.system},r),[t,void 0,a]}function Ga(e){function t(e,t){}return t.type=`xstate.enqueueActions`,t.collect=e,t.resolve=Wa,t}function Ka(e,t,n,r,{value:i,label:a}){return[t,{value:typeof i==`function`?i(n,r):i,label:a},void 0]}function qa({logger:e},{value:t,label:n}){n?e(n,t):e(t)}function Ja(e=({context:e,event:t})=>({context:e,event:t}),t){function n(e,t){}return n.type=`xstate.log`,n.value=e,n.label=t,n.resolve=Ka,n.execute=qa,n}function Ya(e,t){return new Pa(e,t)}function Xa({schemas:e,actors:t,actions:n,guards:r,delays:i}){return{assign:Oa,sendTo:Ha,raise:Ta,log:Ja,cancel:ni,stopChild:li,enqueueActions:Ga,emit:La,spawnChild:ai,createStateConfig:e=>e,createAction:e=>e,createMachine:a=>Ya({...a,schemas:e},{actors:t,actions:n,guards:r,delays:i}),extend:a=>Xa({schemas:e,actors:t,actions:{...n,...a.actions},guards:{...r,...a.guards},delays:{...i,...a.delays}})}}var Za=(e,t,n)=>Math.max(t,Math.min(n,e)),Qa=class{dents=[];revision=0;enabled=!1;maxDepthM=0;maskCache=new WeakMap;spriteCache=null;captureState(){return P({dents:this.dents,revision:this.revision,enabled:this.enabled,maxDepthM:this.maxDepthM})}restoreState(e){let t=P(e);this.dents=t.dents,this.revision=t.revision,this.enabled=t.enabled,this.maxDepthM=t.maxDepthM,this.maskCache=new WeakMap,this.spriteCache=null}get hasDamage(){return this.enabled&&this.dents.length>0}get geometryRevision(){return this.revision}setEnabled(e){this.enabled!==e&&(this.enabled=e,e||this.reset())}reset(){this.dents=[],this.maxDepthM=0,this.revision++,this.spriteCache=null}hit(e,t,n,r,i){if(!this.enabled||r<=2.5||!Number.isFinite(r))return!1;let a=Math.max(1,i),o=G(e,n.center),s=U(q(o,n.forward)/a,q(o,n.side)/a),c=U(q(t,n.forward),q(t,n.side)),l=J(c);if(l<.001)return!1;let u=Za((r-2.5)/17.5,0,1)**1.5;return this.maxDepthM=Math.min(.25,8/a),this.dents.push({center:s,inward:K(c,1/l),depthM:this.maxDepthM*u,radiusAlongM:.65+u*.5,radiusAcrossM:.55+u*.55}),this.dents.length>12&&this.dents.shift(),this.revision++,this.spriteCache=null,!0}point(e){if(!this.hasDamage)return e;let t=U();for(let n of this.dents){let r=(e.x-n.center.x)/n.radiusAlongM,i=(e.y-n.center.y)/n.radiusAcrossM,a=Math.hypot(r,i);if(a>=1)continue;let o=(1-a*a)**2;t=W(t,K(n.inward,n.depthM*o))}let n=J(t);return n>this.maxDepthM&&(t=K(t,this.maxDepthM/n)),W(e,t)}maskFor(e){if(!this.hasDamage)return e;let t=this.maskCache.get(e);if(t?.revision===this.revision)return t.value;let{columns:n,rows:r,solid:i}=e.alpha,a=new Uint8Array(i.length),o=e.lengthM/n,s=e.widthM/r;for(let t=0;t<r;t++)for(let c=0;c<n;c++){let l=U((c+.5)*o-e.lengthM/2,(t+.5)*s-e.widthM/2),u=l;for(let e=0;e<5;e++)u=W(u,G(l,this.point(u)));let d=Math.floor((u.x/e.lengthM+.5)*n),f=Math.floor((u.y/e.widthM+.5)*r);d>=0&&d<n&&f>=0&&f<r&&(a[t*n+c]=i[f*n+d])}let c={...e,alpha:{columns:n,rows:r,solid:a}};return this.maskCache.set(e,{revision:this.revision,value:c}),c}spriteFor(e,t){if(!this.hasDamage)return null;let n=`${t.source.x}:${t.source.y}:${t.source.width}:${t.source.height}:${t.lengthM}:${t.widthM}`;if(this.spriteCache?.image===e&&this.spriteCache.key===n&&this.spriteCache.revision===this.revision)return this.spriteCache.canvas;let r=document.createElement(`canvas`);r.width=Math.max(1,Math.round(t.source.width)),r.height=Math.max(1,Math.round(t.source.height));let i=r.getContext(`2d`);if(!i)return null;let a=e=>{let n=U((e.x/r.width-.5)*t.lengthM,(e.y/r.height-.5)*t.widthM),i=this.point(n);return U((i.x/t.lengthM+.5)*r.width,(i.y/t.widthM+.5)*r.height)};for(let n=0;n<10;n++)for(let o=0;o<20;o++){let s=o*r.width/20,c=(o+1)*r.width/20,l=n*r.height/10,u=(n+1)*r.height/10,d=U(s,l),f=U(c,l),p=U(s,u),m=U(c,u);this.drawTriangle(i,e,t,[d,f,p],[a(d),a(f),a(p)]),this.drawTriangle(i,e,t,[m,p,f],[a(m),a(p),a(f)])}return this.spriteCache={image:e,key:n,revision:this.revision,canvas:r},r}drawTriangle(e,t,n,r,i){let[a,o,s]=r,[c,l,u]=i,d=o.x-a.x,f=o.y-a.y,p=s.x-a.x,m=s.y-a.y,h=d*m-p*f;if(Math.abs(h)<1e-4)return;let g=l.x-c.x,_=l.y-c.y,v=u.x-c.x,y=u.y-c.y,b=(g*m-v*f)/h,x=(_*m-y*f)/h,S=(v*d-g*p)/h,C=(y*d-_*p)/h,ee=c.x-b*a.x-S*a.y,te=c.y-x*a.x-C*a.y;e.save(),e.beginPath(),e.moveTo(c.x,c.y),e.lineTo(l.x,l.y),e.lineTo(u.x,u.y),e.closePath(),e.clip(),e.transform(b,x,S,C,ee,te),e.drawImage(t,n.source.x,n.source.y,n.source.width,n.source.height,0,0,e.canvas.width,e.canvas.height),e.restore()}},$a=new Map,eo=null;function to(e){let t=e.match(/^#([\da-f]{3}|[\da-f]{6})$/i)?.[1];if(t){let e=t.length===3?[...t].map(e=>e+e).join(``):t;return[0,2,4].map(t=>parseInt(e.slice(t,t+2),16))}let n=e.match(/^rgba?\(\s*(\d{1,3})[,\s]+(\d{1,3})[,\s]+(\d{1,3})/i);return n?[X(+n[1],0,255),X(+n[2],0,255),X(+n[3],0,255)]:null}function no(e){let t=to(e);if(t)return t;if($a.has(e))return $a.get(e);let n=null;return typeof document<`u`&&(eo??=document.createElement(`canvas`).getContext(`2d`),eo&&(eo.fillStyle=`#010203`,eo.fillStyle=e,eo.fillStyle!==`#010203`&&(n=to(eo.fillStyle)))),$a.set(e,n),n}var ro=[[0,0],[60,120],[120,180],[240,240],[300,300],[360,360]];function io(e,t=!1){let n=(e%360+360)%360;for(let e=1;e<ro.length;e++){let[r,i]=ro[e-1],[a,o]=ro[e],s=t?i:r,c=t?o:a;if(n<=c){let e=(n-s)/(c-s);return(t?r+(a-r)*e:i+(o-i)*e)%360}}return 0}function ao([e,t,n]){let r=e/255,i=t/255,a=n/255,o=Math.max(r,i,a),s=Math.min(r,i,a),c=o-s,l=(o+s)/2;if(c===0)return{hue:0,saturation:0,light:l};let u=c/(1-Math.abs(2*l-1));return{hue:((o===r?(i-a)/c%6:o===i?(a-r)/c+2:(r-i)/c+4)*60+360)%360,saturation:u,light:l}}function oo(e,t,n){let r=(1-Math.abs(2*n-1))*t,i=r*(1-Math.abs(e/60%2-1)),a=Math.floor(e/60)%6,o=[[r,i,0],[i,r,0],[0,r,i],[0,i,r],[i,0,r],[r,0,i]][a],s=n-r/2;return`rgb(${o.map(e=>Math.round((e+s)*255)).join(` `)})`}function so(e){let t=e.filter(e=>e.strength>0&&no(e.color));if(!t.length)return e.at(-1)?.color??`rgb(0 0 0)`;if(t.length===1)return`rgb(${no(t[0].color).join(` `)})`;let n=0,r=0,i=0,a=0,o=0;for(let e of t){let t=ao(no(e.color)),s=io(t.hue)*Math.PI/180,c=e.strength*t.saturation;n+=Math.cos(s)*c,r+=Math.sin(s)*c,i+=t.light*e.strength,a+=c,o+=e.strength}return oo(io((Math.atan2(r,n)*180/Math.PI+360)%360,!0),Math.min(1,a/o),i/o)}var co=class{coatings=new Map;previous=new Map;travelM=new Map;previousLayer=new Map;wetPaths=new Map;exits=new Map;sprayRemainder=new Map;marks=[];markCount=0;captureState(){return P({coatings:this.coatings,previous:this.previous,travelM:this.travelM,previousLayer:this.previousLayer,wetPaths:this.wetPaths,exits:this.exits,sprayRemainder:this.sprayRemainder,marks:this.marks,markCount:this.markCount})}restoreState(e){let t=P(e);this.coatings=t.coatings,this.previous=t.previous,this.travelM=t.travelM,this.previousLayer=t.previousLayer,this.wetPaths=t.wetPaths,this.exits=t.exits,this.sprayRemainder=t.sprayRemainder,this.marks.length=0;for(let e of t.marks)this.marks.push(e);this.markCount=t.markCount}get totalMarks(){return this.markCount}get managedBytes(){return this.marks.length*136+this.travelM.size*16+[...this.coatings.values()].reduce((e,t)=>e+t.size*72,0)+this.previous.size*24+this.previousLayer.size*8+[...this.wetPaths.values()].reduce((e,t)=>e+t.marks.length*160,0)+this.exits.size*24+this.sprayRemainder.size*16}reset(){this.travelM.clear(),this.coatings.clear(),this.previous.clear(),this.previousLayer.clear(),this.wetPaths.clear(),this.exits.clear(),this.sprayRemainder.clear(),this.marks.length=0,this.markCount=0}step(e){e.forEach((e,t)=>this.travelM.set(t,(this.travelM.get(t)??0)+Math.max(0,e)));for(let[t,n]of this.coatings){let r=Math.max(0,e[t]??0);for(let[e,t]of n)t.remaining=Math.max(0,t.remaining-r),t.remaining===0&&n.delete(e);n.size===0&&(this.coatings.delete(t),this.previous.delete(t),this.previousLayer.delete(t),this.wetPaths.delete(t),this.exits.delete(t))}}touch(e,t){if(!t||t.opacity<=0||t.distanceM<=0)return;let n=this.coatings.get(e);n||(n=new Map,this.coatings.set(e,n));let r=t.id??t.color,i=n.get(r);if(n.set(r,{...t,opacity:Math.max(i?.opacity??0,X(t.opacity,0,1)),remaining:t.distanceM}),n.size>16){let e=[...n.entries()].filter(([e])=>e!==r).sort((e,t)=>e[1].opacity*e[1].remaining/e[1].distanceM-t[1].opacity*t[1].remaining/t[1].distanceM)[0];e&&n.delete(e[0])}}wash(e,t=[]){let n=this.coatings.get(e);if(n&&t.length){let e=new Set(t.map(e=>e.id??e.color));for(let t of n.keys())e.has(t)||n.delete(t);if(n.size)return}this.coatings.delete(e),this.previous.delete(e),this.previousLayer.delete(e),this.sprayRemainder.delete(e),this.wetPaths.delete(e),this.exits.delete(e)}splatter(e,t,n,r,a,o,s){let c=this.coating(e);if(!c||a<=0||s<=0)return;let l=i.paint.thickness,u=(this.sprayRemainder.get(e)??0)+a*(9+(1-l)*7)*(c.material?.spray??.5),d=Math.min(24,Math.floor(u));this.sprayRemainder.set(e,u-Math.floor(u));for(let e of ur(t,n,r,d,o,l)){let t=1+e.angularity*1.7,r={x:e.x,y:e.y};this.marks.push({from:r,point:r,angle:Math.atan2(n.y,n.x),widthM:e.radius*2*t/(s*.76),color:c.color,opacity:c.opacity*e.opacity,droplet:{aspect:(.5+Math.random()*.45)/t}}),this.markCount++}this.marks.length>3e4&&this.marks.splice(0,1e3)}trackWet(e,t,n,r,i,a=0,o=!1){let s=this.coating(e);if(!s){this.pauseTrack(e);return}let c=this.previous.get(e),l=this.wetPaths.get(e);if(!l||!c||J(G(t,c))>=1.5*i)l={marks:[],distanceM:0},this.wetPaths.set(e,l),o&&(this.marks.push({...s,from:{...t},point:{...t},angle:n,widthM:r,phaseM:this.travelM.get(e)??0,slip:X(a,0,1),overPuddle:!0}),this.markCount++);else{let u=l.marks.at(-1),d=u&&J(G(u.point,u.from))/i<.02,f=d?u.from:c;d&&(l.distanceM-=J(G(u.point,u.from))/i);let p=J(G(t,f))/i,m={...s,from:{...f},point:{...t},angle:n,widthM:r,phaseM:(this.travelM.get(e)??0)-p,slip:X(a,0,1)};d?l.marks[l.marks.length-1]=m:l.marks.push(m),l.distanceM+=p,o&&p>=.02&&(this.marks.push({...m,overPuddle:!0}),this.markCount++,this.marks.length>3e4&&this.marks.splice(0,1e3));let h=Math.max(.5,r*6);for(;l.marks.length>1&&(l.distanceM>h||l.marks.length>128);){let e=l.marks.shift();l.distanceM-=J(G(e.point,e.from))/i}}this.exits.delete(e),this.previous.set(e,{...t}),this.previousLayer.set(e,!1)}pauseTrack(e){this.wetPaths.delete(e),this.exits.delete(e),this.previous.delete(e),this.previousLayer.delete(e)}track(e,t,n,r,i,a=!1,o=0){let s=this.coating(e);if(!s)return;let c=this.previous.get(e),l=c?J(G(t,c)):0,u=this.wetPaths.has(e)||this.exits.has(e)?.01:.05;if(c&&l<u*i)return;let d=c&&l<1.5*i,f=this.wetPaths.get(e);if(f&&d){let t=Math.max(.35,r*(2+4*(s.material?.film??.6))),n=-f.distanceM;for(let e of f.marks){let r=n+J(G(e.point,e.from))/i;this.marks.push({...e,overPuddle:!1,exit:{fromM:n,toM:r,lengthM:t,leadInM:f.distanceM}}),this.markCount++,n=r}this.exits.set(e,{distanceM:0,lengthM:t})}else d||this.exits.delete(e);this.wetPaths.delete(e);let p=this.exits.get(e),m=p&&p.distanceM<p.lengthM?{fromM:p.distanceM,toM:p.distanceM+l/i,lengthM:p.lengthM}:void 0;p&&(p.distanceM+=l/i,p.distanceM>=p.lengthM&&this.exits.delete(e)),this.marks.push({from:d?{...c}:{...t},point:{...t},angle:n,widthM:r,phaseM:(this.travelM.get(e)??0)-(d?J(G(t,c))/i:0),wetness:s.wetness,material:s.material,slip:X(o,0,1),color:s.color,opacity:s.opacity,overPuddle:a,exit:m}),this.markCount++,this.previous.set(e,{...t}),this.previousLayer.set(e,a),this.marks.length>3e4&&this.marks.splice(0,1e3)}coating(e){let t=this.coatings.get(e);if(!t?.size)return null;let n=[...t.values()].map(e=>({color:e.color,strength:e.opacity*X(e.remaining/e.distanceM,0,1)})),r=[...t.values()].sort((e,t)=>t.opacity*t.remaining/t.distanceM-e.opacity*e.remaining/e.distanceM)[0],i=X(r.remaining/r.distanceM,0,1);return{material:r.material,wetness:i,color:so(n),opacity:Math.max(...n.map(e=>e.strength))*i**+Math.max(0,(r.material?.drain??1)-1),remaining:Math.max(...[...t.values()].map(e=>e.remaining)),distanceM:Math.max(...[...t.values()].map(e=>e.distanceM))}}},$={opening:.32,raising:.52,igniting:.48,closing:.36},lo=class{previewOpen=!1;inspecting=!1;phase=`idle`;elapsed=0;held=!1;presetId=null;flights=[];launchClock=0;queuedShots=0;launches=0;ignitionDuration=$.igniting;captureState(){return P({previewOpen:this.previewOpen,inspecting:this.inspecting,phase:this.phase,elapsed:this.elapsed,held:this.held,presetId:this.presetId,flights:this.flights,launchClock:this.launchClock,queuedShots:this.queuedShots,launches:this.launches,ignitionDuration:this.ignitionDuration})}restoreState(e){let t=P(e);this.previewOpen=t.previewOpen,this.inspecting=t.inspecting,this.phase=t.phase,this.elapsed=t.elapsed,this.held=t.held,this.presetId=t.presetId,this.flights=t.flights,this.launchClock=t.launchClock,this.queuedShots=t.queuedShots,this.launches=t.launches,this.ignitionDuration=t.ignitionDuration}get state(){return this.phase}get projectile(){let e=this.flights[0];return e?{...e,position:{...e.position}}:null}get projectileCount(){return this.flights.length}get managedBytes(){return this.flights.length*64}get launchCount(){return this.launches}reset(){this.previewOpen=!1,this.inspecting=!1,this.phase=`idle`,this.elapsed=0,this.held=!1,this.flights=[],this.launchClock=0,this.queuedShots=0,this.launches=0,this.ignitionDuration=$.igniting,this.presetId=null}disarm(){this.held=!1,this.queuedShots=0,(this.phase===`opening`||this.phase===`raising`||this.phase===`igniting`)&&this.transition(`closing`)}transition(e){this.phase=e,this.elapsed=0}step(e,t,n,r,i,a,o,s){if(t.mode!==`car`){this.reset();return}if(this.presetId&&this.presetId!==t.car.preset.id&&this.reset(),this.previewOpen){this.inspecting=!0,this.presetId=t.car.preset.id,(this.phase===`idle`||this.phase===`closing`)&&this.transition(`opening`),this.elapsed+=e,this.phase===`opening`&&this.elapsed>=$.opening&&this.transition(`raising`),this.phase===`raising`&&(this.elapsed=Math.min(this.elapsed,$.raising));return}this.inspecting&&(this.inspecting=!1,this.transition(`closing`));let c=!!t.lastInput.rocket;c&&!this.held&&(this.queuedShots++,(this.phase===`idle`||this.phase===`closing`)&&(this.presetId=t.car.preset.id,this.transition(`opening`))),this.held=c;let l=mt(t.car.preset);if(this.phase===`idle`&&!this.flights.length)return;this.elapsed+=e,this.launchClock+=e;let u=t.car.preset.roofRocket,d=Math.max(1.05,u.sizeM*1.12);if(this.phase===`opening`&&this.elapsed>=$.opening)this.transition(`raising`);else if(this.phase===`raising`&&this.elapsed>=$.raising)this.ignitionDuration=$.igniting,this.transition(`igniting`),s?.(t.body.world(U(u.xM,u.yM)));else if(this.phase===`igniting`&&this.elapsed>=this.ignitionDuration){let e=Y(U(1,0),t.body.angle),n=t.body.world(U(u.xM,u.yM));this.flights.push({position:n,angle:t.body.angle,speedMps:l.launchSpeedMps+Math.max(0,q(t.body.velocity,e)),distanceM:0,age:0}),this.launches++,a?.(n),this.queuedShots=Math.max(0,this.queuedShots-1),this.launchClock=0,this.transition(`flying`)}else this.phase===`closing`&&this.elapsed>=$.closing&&this.transition(`idle`);if(this.phase===`igniting`){let r=X(this.elapsed/Math.min(.27,this.ignitionDuration*.65),0,.9),a=Y(U(-1,0),t.body.angle),o=t.body.world(U(u.xM-d*.52,u.yM));n({point:o,flow:K(a,3.5),amount:e*14*r,radiusM:.2}),i?.({from:o,to:o,flow:K(a,12),widthM:.16,intensity:r*.75})}this.phase===`flying`&&(!c&&this.queuedShots===0?this.transition(`closing`):this.launchClock>=Math.max(0,1/l.roundsPerSecond-Math.min($.igniting,.7/l.roundsPerSecond))&&(this.ignitionDuration=Math.min($.igniting,.7/l.roundsPerSecond),this.transition(`igniting`),s?.(t.body.world(U(u.xM,u.yM)))));for(let t=this.flights.length-1;t>=0;t--){let a=this.flights[t],s=Y(U(1,0),a.angle);a.speedMps=Math.min(l.maxSpeedMps,a.speedMps+l.accelerationMps2*e);let c=a.speedMps*e,f=a.position,p=W(f,K(s,c)),m=r?.(f,p,u.sizeM*.18);a.position=m??p,a.distanceM+=c,a.age+=e;let h=W(a.position,K(s,-d*.53)),g=W(f,K(s,-d*.53));if(n({point:h,flow:K(s,-5),amount:e*l.smokePerSecond,radiusM:.2}),i?.({from:g,to:h,flow:K(s,-18),widthM:.13,intensity:.9}),m){o?.(m);for(let e=0;e<7;e++)n({point:m,flow:K(Y(U(1,0),e*Math.PI*2/7),5.5),amount:.18,radiusM:.22});this.flights.splice(t,1)}else(a.age>=l.lifetimeSeconds||a.distanceM>100)&&this.flights.splice(t,1)}this.phase===`closing`&&this.elapsed>=$.closing&&this.transition(`idle`)}get open(){return this.phase===`idle`?0:this.phase===`opening`?X(this.elapsed/$.opening,0,1):this.phase===`closing`?1-X(this.elapsed/$.closing,0,1):1}drawMount(e,t,n,r,i,a=1,o){let s=this.open;if(s<=0)return;nr();let c=r.roofRocket,l=c.sizeM*i,u=s*s*(3-2*s);e.save(),e.translate(t.x,t.y),e.rotate(-n),e.translate(c.xM*i,-c.yM*i),e.globalAlpha*=a;let d=e.createLinearGradient(0,-l/2,0,l/2);d.addColorStop(0,`#11171b`),d.addColorStop(.45,`#030609`),d.addColorStop(1,`#222a2e`),e.fillStyle=d,e.beginPath(),e.roundRect(-l/2,-l/2,l,l,l*.06),e.fill(),e.strokeStyle=`#525c62`,e.lineWidth=Math.max(.45,i*.018),e.stroke();for(let t of[-1,1]){e.fillStyle=`#687279`,e.fillRect(-l*.42,t*l*.2,l*.84,l*.035),e.fillStyle=`#161d22`,e.fillRect(-l*.34,-l*.28,l*.065,l*.56);let n=l*.5*(1-u*.78),r=t*(l*.25+u*l*.22);if(e.save(),e.translate(0,r),e.shadowColor=`rgba(0,0,0,.55)`,e.shadowBlur=l*.08,e.shadowOffsetY=l*.035,e.fillStyle=c.panelColor,e.beginPath(),e.roundRect(-l/2,-n/2,l,n,l*.035),e.fill(),e.shadowBlur=0,e.shadowOffsetY=0,o){e.save(),e.clip();let r=o.source.x+(c.xM-c.sizeM/2+o.lengthM/2)/o.lengthM*o.source.width,i=o.source.y+(-c.yM+(t<0?-c.sizeM/2:0)+o.widthM/2)/o.widthM*o.source.height;e.drawImage(o.image,r,i,c.sizeM/o.lengthM*o.source.width,c.sizeM/2/o.widthM*o.source.height,-l/2,-n/2,l,n),e.restore()}e.strokeStyle=`rgba(8,13,17,.7)`,e.lineWidth=Math.max(.45,i*.018),e.stroke(),e.restore()}if(this.phase===`raising`||this.phase===`igniting`){let t=this.phase===`igniting`?1:X(this.elapsed/$.raising,0,1);e.save(),e.globalAlpha*=t,e.scale(.35+t*.65,.35+t*.65),this.drawBody(e,Math.max(1.05,c.sizeM*1.12)*i,1),e.restore()}e.restore()}drawFlight(e,t,n,r,i=1){for(let a of this.flights){let o=t(a.position);e.save(),e.translate(o.x,o.y),e.rotate(-a.angle),e.globalAlpha=i,this.drawBody(e,Math.max(1.05,n.roofRocket.sizeM*1.12)*r,1),e.restore()}}drawBody(e,t,n){if(e.save(),e.globalAlpha*=n,e.shadowColor=`rgba(0,0,0,.5)`,e.shadowBlur=t*.055,e.shadowOffsetY=t*.025,!rr(e,`rocket`,-t*.53,0,t*1.06)){let n=e.createLinearGradient(0,-t*.045,0,t*.045);n.addColorStop(0,`#3b454d`),n.addColorStop(.35,`#d8dddc`),n.addColorStop(1,`#3e484f`),e.fillStyle=n,e.beginPath(),e.moveTo(-t*.53,-t*.045),e.lineTo(t*.3,-t*.045),e.lineTo(t*.53,0),e.lineTo(t*.3,t*.045),e.lineTo(-t*.53,t*.045),e.closePath(),e.fill(),e.fillStyle=`#30383e`;for(let n of[-1,1])e.beginPath(),e.moveTo(-t*.48,n*t*.12),e.lineTo(-t*.22,n*t*.04),e.lineTo(-t*.44,n*t*.04),e.closePath(),e.fill()}e.restore()}},uo=.22,fo=.24,po=class{phase=`closed`;phaseTime=0;shotClock=0;flashAge=1/0;presetId=null;bullets=[];captureState(){return P({phase:this.phase,phaseTime:this.phaseTime,shotClock:this.shotClock,flashAge:this.flashAge,presetId:this.presetId,bullets:this.bullets})}restoreState(e){let t=P(e);this.phase=t.phase,this.phaseTime=t.phaseTime,this.shotClock=t.shotClock,this.flashAge=t.flashAge,this.presetId=t.presetId,this.bullets=t.bullets}get state(){return this.phase}get openAmount(){return this.open}get projectileCount(){return this.bullets.length}get managedBytes(){return this.bullets.length*56}reset(){this.phase=`closed`,this.phaseTime=0,this.shotClock=0,this.flashAge=1/0,this.presetId=null,this.bullets=[]}step(e,t,n,r,i){if(t.mode!==`car`){this.reset();return}this.presetId&&this.presetId!==t.car.preset.id&&this.reset();let a=dt(t.car.preset),o=!!t.lastInput.machineGun;if(o&&(this.phase===`closed`||this.phase===`closing`)){this.presetId=t.car.preset.id;let e=this.open;this.phase=`opening`,this.phaseTime=e*uo}else if(!o&&(this.phase===`opening`||this.phase===`active`)){let e=this.open;this.phase=`closing`,this.phaseTime=(1-e)*fo}if(this.phaseTime+=e,this.flashAge+=e,this.phase===`opening`&&this.phaseTime>=uo&&(this.phase=`active`,this.phaseTime=0,this.shotClock=1/a.roundsPerSecond),this.phase===`active`){if(o){let n=1/Math.max(1,a.roundsPerSecond);this.shotClock+=e;for(let e=0;this.shotClock>=n&&e<4;e++)this.shotClock-=n,this.fire(t),r?.()}}else this.phase===`closing`&&this.phaseTime>=fo&&(this.phase=`closed`,this.phaseTime=0);for(let t=this.bullets.length-1;t>=0;t--){let r=this.bullets[t],o=r.position,s=W(o,K(r.velocity,e)),c=n?.(o,s,.075);r.age+=e,c||r.age>=a.bulletLifetimeSeconds?(c&&i?.(c,r.velocity),this.bullets.splice(t,1)):r.position=s}}fire(e){let t=dt(e.car.preset),n=Y(U(1,0),e.body.angle);for(let r of[-1,1]){let i=e.body.world(sr(e.car.preset,r)),a=W(K(n,t.bulletSpeedMps),e.body.velocityAt(i));this.bullets.push({position:i,velocity:a,age:0})}this.flashAge=0}get open(){return this.phase===`closed`?0:this.phase===`opening`?X(this.phaseTime/uo,0,1):this.phase===`closing`?1-X(this.phaseTime/fo,0,1):1}drawMount(e,t,n,r,i,a=1,o){lr(e,t,n,r,i,this.open,`gun`,Math.max(0,1-this.flashAge/.075),a,o)}drawProjectiles(e,t,n,r=1){e.save(),e.lineCap=`round`;for(let i of this.bullets){let a=t(i.position),o=Math.hypot(i.velocity.x,i.velocity.y),s=t(W(i.position,K(i.velocity,-.75/Math.max(1,o)))),c=e.createLinearGradient(s.x,s.y,a.x,a.y);c.addColorStop(0,`rgba(224,153,63,0)`),c.addColorStop(.7,`rgba(224,153,63,.25)`),c.addColorStop(1,`rgba(255,225,157,.7)`),e.globalAlpha=r,e.strokeStyle=c,e.lineWidth=Math.max(.65,n*.025),e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(a.x,a.y),e.stroke();let l=t(W(i.position,K(i.velocity,-.09/Math.max(1,o))));e.strokeStyle=`#fff6d7`,e.lineWidth=Math.max(.55,n*.018),e.beginPath(),e.moveTo(l.x,l.y),e.lineTo(a.x,a.y),e.stroke()}e.restore()}},mo=.22,ho=.24,go=1/45,_o=class{phase=`closed`;phaseTime=0;emitting=!1;presetId=null;fireClock=0;jets=[];captureState(){return P({phase:this.phase,phaseTime:this.phaseTime,emitting:this.emitting,presetId:this.presetId,fireClock:this.fireClock,jets:this.jets})}restoreState(e){let t=P(e);this.phase=t.phase,this.phaseTime=t.phaseTime,this.emitting=t.emitting,this.presetId=t.presetId,this.fireClock=t.fireClock,this.jets=t.jets}get state(){return this.phase}get firing(){return this.emitting}get openAmount(){return this.open}get managedBytes(){return this.jets.length*64}reset(){this.phase=`closed`,this.phaseTime=0,this.emitting=!1,this.presetId=null,this.fireClock=0,this.jets=[]}step(e,t,n,r,i){if(t.mode!==`car`){(this.phase!==`closed`||this.jets.length)&&this.reset();return}this.presetId&&this.presetId!==t.car.preset.id&&this.reset();let a=!!t.lastInput.flamethrower,o=ft(t.car.preset);if(a&&(this.phase===`closed`||this.phase===`closing`)){this.presetId=t.car.preset.id;let e=this.open;this.phase=`opening`,this.phaseTime=e*mo}else if(!a&&(this.phase===`opening`||this.phase===`active`)){let e=this.open;this.phase=`closing`,this.phaseTime=(1-e)*ho}if(this.phaseTime+=e,this.phase===`opening`&&this.phaseTime>=mo&&(this.phase=`active`,this.phaseTime=0,this.fireClock=go),this.emitting=this.phase===`active`&&a,this.phase===`closing`&&this.phaseTime>=ho&&(this.phase=`closed`,this.phaseTime=0),this.emitting){let r=Y(U(1,0),t.body.angle),i=o.rangeM/.3;for(this.fireClock+=e;this.fireClock>=go;){this.fireClock-=go;for(let e of[-1,1]){let n=t.body.world(sr(t.car.preset,e));this.jets.push({point:n,velocity:W(K(r,i),K(t.body.velocity,.25)),traveled:0,range:o.rangeM,speed:i,width:o.jetWidthM*o.flowRate})}}for(let i of[-1,1])n({point:W(t.body.world(sr(t.car.preset,i)),K(r,.06)),flow:K(r,5.5),amount:e*o.smokePerSecond*o.flowRate*.38,radiusM:.12})}let s=[];for(let t of this.jets){let a=Math.min(t.range-t.traveled,t.speed*e),c=t.point,l=W(c,K(t.velocity,a/t.speed)),u=(t.traveled+a)/t.range,d=t.width*(.65+1.45*u),f=r?.(c,l,Math.max(.3,d*1.25),go*o.flowRate),p=f??l;t.point=p,t.traveled+=a,i?.(c,p,d,t.velocity,u),(u>.62||f)&&n({point:p,flow:K(t.velocity,.42),amount:e*o.smokePerSecond*o.flowRate*(f?.42:.18),radiusM:Math.max(.11,d*.48)}),f?i?.(p,p,d*1.35,t.velocity,u):t.traveled+1e-6<t.range&&s.push(t)}this.jets=s}get open(){return this.phase===`closed`?0:this.phase===`opening`?X(this.phaseTime/mo,0,1):this.phase===`closing`?1-X(this.phaseTime/ho,0,1):1}drawMount(e,t,n,r,i,a=1,o){lr(e,t,n,r,i,this.open,`flame`,this.phase===`active`?.8:0,a,o)}},vo=class{rocket=new lo;machineGuns=new po;flamethrower=new _o;lightning=new hr;reset(){this.rocket.reset(),this.machineGuns.reset(),this.flamethrower.reset(),this.lightning.reset()}stopFiring(){this.rocket.disarm(),this.lightning.reset()}captureState(){return{rocket:this.rocket.captureState(),machineGuns:this.machineGuns.captureState(),flamethrower:this.flamethrower.captureState(),lightning:this.lightning.captureState()}}restoreState(e){this.rocket.restoreState(e.rocket),this.machineGuns.restoreState(e.machineGuns),this.flamethrower.restoreState(e.flamethrower),e.lightning?this.lightning.restoreState(e.lightning):this.lightning.reset()}get managedBytes(){return this.rocket.managedBytes+this.machineGuns.managedBytes+this.flamethrower.managedBytes}},yo={boost:{capacity:2.6,partialRecharge:1.1,emptyRecharge:2,partialPause:.35,emptyPause:.9,label:`Boost`},eject:{capacity:4,partialRecharge:2.2,emptyRecharge:4.5,partialPause:.3,emptyPause:1.1,label:`Liquid`},machineGun:{capacity:5,partialRecharge:2.4,emptyRecharge:5,partialPause:.3,emptyPause:1.2,label:`Machine guns`},flamethrower:{capacity:3.5,partialRecharge:2.8,emptyRecharge:5.2,partialPause:.4,emptyPause:1.4,label:`Flamethrower`},rocket:{capacity:4.5,partialRecharge:3,emptyRecharge:5.5,partialPause:.4,emptyPause:1.5,label:`Rocket`},ghost:{capacity:5,partialRecharge:3,emptyRecharge:5,partialPause:.35,emptyPause:1.2,label:`Ghost`},lightning:{capacity:1.1,partialRecharge:.8,emptyRecharge:2.4,partialPause:.2,emptyPause:.6,label:`Lightning`}},bo=Object.keys(yo),xo=class{reserves=new Map;time=0;stepScales=new Map;enabled=!0;reset(){this.reserves.clear(),this.stepScales.clear(),this.time=0}captureState(){return{enabled:this.enabled,time:this.time,stepScales:[...this.stepScales],reserves:[...this.reserves].map(([e,t])=>[e,{...t}])}}restoreState(e){this.enabled=e.enabled,this.time=e.time,this.stepScales=new Map(e.stepScales),this.reserves=new Map(e.reserves.map(([e,t])=>[e,{...t}]))}consumptionScale(e){return this.enabled?this.stepScales.get(e)??1:1}fraction(e){return this.reserves.get(e)?.fill??1}step(e,t,n,r={}){if(this.stepScales.clear(),!this.enabled)return e;this.time+=Math.max(0,t);let i={...e},a=this.time;for(let o of bo){let s=yo[o],c=o===`boost`&&n?{...s,capacity:Math.max(.1,n.durationSeconds),partialRecharge:Math.max(.1,n.cooldownSeconds*.55),emptyRecharge:Math.max(.1,n.cooldownSeconds)}:s,l=this.reserves.get(o)??{fill:1,pause:0,exhausted:!1,lastUsedAt:-1/0},u=!!e[o]&&(o!==`boost`||e.throttle>.5)&&!l.exhausted&&l.fill>0;i[o]=u;let d=Math.max(0,t)*Math.max(0,r[o]??1)/c.capacity,f=u&&d>0?Math.min(1,l.fill/d):+!!u;this.stepScales.set(o,f),u?(l.fill=Math.max(0,l.fill-d*f),l.pause=c.partialPause,l.lastUsedAt=a,l.fill===0&&(l.exhausted=!0,l.pause=c.emptyPause)):l.fill<1&&(l.pause=Math.max(0,l.pause-Math.max(0,t)),l.pause===0&&(l.fill=Math.min(1,l.fill+Math.max(0,t)/(l.exhausted?c.emptyRecharge:c.partialRecharge)),l.fill===1&&(l.exhausted=!1))),l.fill<1||a-l.lastUsedAt<1.8?this.reserves.set(o,l):this.reserves.delete(o)}return i}indicator(e=this.time){if(!this.enabled)return null;let t=[...this.reserves].sort((e,t)=>t[1].lastUsedAt-e[1].lastUsedAt)[0];if(!t)return null;let[n,r]=t,i=e-r.lastUsedAt;if(r.fill>=1&&i>=1.8)return null;let a=r.fill<1?1:Math.min(1,(1.8-i)/.45);return{label:yo[n].label,fraction:r.fill,alpha:a,depleted:r.exhausted||r.fill===0,recharging:r.fill<1&&r.pause===0}}},So=e=>({...e,slots:e.slots?[...e.slots]:void 0,slotPresses:e.slotPresses?[...e.slotPresses]:void 0}),Co=Xa({types:{events:{}}}).createMachine({id:`vehicleLifecycle`,initial:`drivable`,states:{drivable:{on:{DESTROYED:`destroyed`}},destroyed:{on:{RESPAWNED:`drivable`}}}}),wo=class{id;sim;damage=new Qa;weapons=new vo;weaponReserves=new xo;tirePaint=new co;lifecycle=$r(Co).start();controls={throttle:0,steer:0,action:!1};controlSource=`player`;label=``;appearance=`auto`;slotConfiguration=y;toolPolicy={};numberedSlots=Mt(y);slotHeld=new Set;slotPulses=new Set;slotPresses=new Set;blockedSlots=new Set;disposed=!1;previousSlotInput=new Set;activeEmitters=[];get slots(){return this.slotConfiguration}set slots(e){if(this.disposed)throw Error(`Vehicle is disposed.`);let t=te(e);this.clearSlotInput(),this.slotConfiguration=t,this.numberedSlots=Mt(t,this.toolPolicy)}liquidEmissions(e){return!this.sim.lastInput.eject||this.isGhost||this.lifecycleState!==`drivable`?[]:this.activeEmitters.map(({slot:t,liquid:n,pulse:r,rate:i,amount:a})=>({slot:t,liquid:n,amount:(r?a:Math.max(0,e)*i)*this.weaponReserves.consumptionScale(`eject`)})).filter(e=>e.amount>0)}useSlot(e){let t=b(e);return this.disposed||!this.numberedSlots[t-1]||this.lifecycleState!==`drivable`?!1:(this.slotPulses.add(t),!0)}startSlot(e){let t=b(e);return this.disposed||!this.numberedSlots[t-1]||this.lifecycleState!==`drivable`?!1:(this.slotHeld.has(t)||this.slotPresses.add(t),this.slotHeld.add(t),!0)}stopSlot(e){this.slotHeld.delete(b(e))}clearSlotInput(){this.slotHeld.clear(),this.slotPulses.clear(),this.slotPresses.clear(),this.blockedSlots.clear(),this.previousSlotInput.clear(),this.activeEmitters=[]}resolveSlots(e){let t=new Set((e.slots??[]).map(b)),n=new Set((e.slotPresses??[]).map(b));for(let e of this.blockedSlots)!t.has(e)&&!n.has(e)?this.blockedSlots.delete(e):(t.delete(e),n.delete(e));let r=new Set([...this.slotHeld,...t]),i=new Set([...this.slotPresses,...n]),a=So(e);this.activeEmitters=[];for(let{number:e,slot:t}of this.numberedSlots){let n=r.has(e)&&!this.previousSlotInput.has(e),o=this.slotPulses.has(e)||(t.activation===`tap`?n||i.has(e):i.has(e)&&!r.has(e));(o||t.activation!==`tap`&&r.has(e))&&(t.action===`eject`?(a.eject=!0,this.activeEmitters.push({slot:e,liquid:t.liquid,pulse:o,rate:t.rate??6,amount:t.amount??.65})):a[t.action]=!0)}if(e.eject&&!this.activeEmitters.length){for(let{number:e,slot:t}of this.numberedSlots)if(t.action===`eject`){this.activeEmitters.push({slot:e,liquid:t.liquid,pulse:!1,rate:t.rate??6,amount:t.amount??.65});break}}return this.previousSlotInput=r,a}tourCommands;constructor(e,t){this.id=e,this.sim=t}get lifecycleState(){return this.lifecycle.getSnapshot().value}get isGhost(){return this.sim.mode===`car`&&this.lifecycleState===`drivable`&&!!this.controls.ghost}bindTourCommands(e){this.tourCommands=e}driveTo(e,t){return this.tour([e],t)}tour(e,t){return this.tourCommands?.start(e,t)??!1}stopTour(){return this.tourCommands?.stop()??!1}setControls(e,t,n={}){if(n.enabledTools!==this.toolPolicy.enabledTools||n.weaponsEnabled!==this.toolPolicy.weaponsEnabled){let t=Mt(this.slotConfiguration,n);if(t.length!==this.numberedSlots.length||t.some(({source:e},t)=>e!==this.numberedSlots[t].source)){this.clearSlotInput();for(let t of[...e.slots??[],...e.slotPresses??[]])this.blockedSlots.add(b(t))}this.toolPolicy=n,this.numberedSlots=t}this.controls=Ft(this.resolveSlots(e),n.enabledTools,n.weaponsEnabled),this.controlSource=t}step(e,t,n=!1){n?(this.weaponReserves.step({throttle:0,steer:0,action:!1},e,this.sim.car.preset.driveBoost),this.sim.lastInput={throttle:0,steer:0,action:!1,boost:!1}):this.sim.tick(this.lifecycleState===`drivable`?this.weaponReserves.step(this.controls,e,this.sim.car.preset.driveBoost,{lightning:yo.lightning.capacity/fr(this.sim.car.preset).chargeSeconds,eject:e>0?this.activeEmitters.reduce((t,n)=>t+(n.pulse?n.amount:n.rate*e),0)/(e*6):0}):this.weaponReserves.step({throttle:0,steer:0,action:!1},e,this.sim.car.preset.driveBoost),e,t),this.weapons.lightning.step(e,!n&&!!this.sim.lastInput.lightning&&this.lifecycleState===`drivable`,fr(this.sim.car.preset).chargeSeconds,this.weaponReserves.enabled?this.weaponReserves.fraction(`lightning`):void 0),this.slotPulses.clear(),this.slotPresses.clear()}synchronizeLifecycle(){let e=this.sim.car.explodedAt!==null;e&&this.lifecycleState===`drivable`?(this.lifecycle.send({type:`DESTROYED`}),this.weapons.stopFiring(),this.clearSlotInput(),this.sim.lastInput={throttle:0,steer:0,action:!1,boost:!1}):!e&&this.lifecycleState===`destroyed`&&this.lifecycle.send({type:`RESPAWNED`})}reset(){this.clearSlotInput(),this.sim.reset(),this.damage.reset(),this.weapons.reset(),this.weaponReserves.reset(),this.tirePaint.reset(),this.synchronizeLifecycle()}restoreHealth(){this.sim.car.resetBurnable(),this.synchronizeLifecycle()}setMode(e){this.clearSlotInput(),this.sim.setMode(e),this.damage.reset(),this.weapons.reset(),this.weaponReserves.reset(),this.tirePaint.reset(),this.synchronizeLifecycle()}setPreset(e){this.clearSlotInput(),this.sim.setPreset(e),this.damage.reset(),this.weapons.reset(),this.weaponReserves.reset(),this.tirePaint.reset(),this.synchronizeLifecycle()}advanceBurn(e){if(this.sim.mode!==`car`)return null;let{car:t}=this.sim;t.advanceBurn(e),this.synchronizeLifecycle();let n=t.stage;if(n===`intact`)return null;let r=!1,i=!1;this.lifecycleState===`destroyed`&&(t.blastQueued||(t.blastQueued=!0,r=!0),t.blastAge+=e,t.blastAge<.36&&t.blastAge-t.lastBlastEmission>=1/30&&(i=!0,t.lastBlastEmission=t.blastAge));let a={stage:n,health:t.health,maxHealth:t.maxHealth,key:t,burnOriginLocal:{...t.burnOriginLocal},blastAge:t.blastAge,explosionStarted:r,blastPulse:i};return this.lifecycleState===`destroyed`&&t.blastAge>=sn.respawnSeconds&&(this.sim.resetAtCurrentPose(),this.damage.reset(),this.synchronizeLifecycle()),a}captureState(){return{id:this.id,label:this.label,appearance:this.appearance,slots:structuredClone(this.slots),slotHeld:[...this.slotHeld],slotPulses:[...this.slotPulses],slotPresses:[...this.slotPresses],blockedSlots:[...this.blockedSlots],previousSlotInput:[...this.previousSlotInput],activeEmitters:this.activeEmitters.map(e=>({...e})),simulation:this.sim.captureState(),damage:this.damage.captureState(),weapons:this.weapons.captureState(),weaponReserves:this.weaponReserves.captureState(),tirePaint:this.tirePaint.captureState(),controls:So(this.controls),controlSource:this.controlSource,lifecycle:this.lifecycle.getPersistedSnapshot()}}restoreState(e){if(e.id!==this.id)throw Error(`Checkpoint vehicle does not match`);this.label=e.label,this.appearance=e.appearance,this.slots=structuredClone(e.slots),this.slotHeld=new Set(e.slotHeld),this.slotPulses=new Set(e.slotPulses),this.slotPresses=new Set(e.slotPresses),this.blockedSlots=new Set(e.blockedSlots),this.previousSlotInput=new Set(e.previousSlotInput),this.activeEmitters=e.activeEmitters.map(e=>({...e})),this.sim.restoreState(e.simulation),this.damage.restoreState(e.damage),this.weapons.restoreState(e.weapons),this.weaponReserves.restoreState(e.weaponReserves),this.tirePaint.restoreState(e.tirePaint),this.controls=So(e.controls),this.controlSource=e.controlSource,this.lifecycle.stop(),this.lifecycle=$r(Co,{snapshot:e.lifecycle}).start()}dispose(){this.disposed=!0,this.clearSlotInput(),this.lifecycle.stop()}};function To(e,t,n,r){let{sim:i,weaponReserves:a}=e,o=i.car,s=a.indicator(),c=t?.redlineRpm??8e3,l=t?.gear;return{speed:(i.paused?0:J(i.body.velocity))*2.2369362921,rpm:t?.rpm??0,gear:l==null||l===0?`N`:l,maxRpm:Math.ceil(c/1e3)*1e3,redlineRpm:c,hp:o.health,maxHp:o.maxHealth,ammo:a.enabled?s?.fraction??1:void 0,maxAmmo:1,ammoState:(s?.fraction??1)<=0?`empty`:s?.recharging||s?.depleted?`refilling`:`ready`,points:n,totalPoints:r,maxPoints:r??999999,effects:[]}}var Eo=`joy-ride-odometer-v1`,Do=`joy-ride-distance-dpi-v1`,Oo=1609.344,ko={screen:96,print:300};ko.print;var Ao=.0254;function jo(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}var Mo={pixels:0,kilometers:0,miles:0,dpi:ko.print,dpiMode:`print`};function No(e){if(!e||typeof e!=`object`)return!1;let t=e;return Number.isFinite(t.pixels)&&(t.pixels??-1)>=0}var Po=class{store;total;dirty=!1;mode=`print`;constructor(e=jo()){this.store=e;let t=null;try{t=JSON.parse(this.store?.getItem(Eo)??`null`)}catch{}this.total=No(t)?{pixels:t.pixels}:{pixels:0};try{this.store?.getItem(Do)===`screen`&&(this.mode=`screen`)}catch{}}add(e,t){!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0||(this.total.pixels+=e*t,this.dirty=!0)}reset(){this.total.pixels=0,this.dirty=!0,this.flush()}get dpiMode(){return this.mode}captureState(){return{pixels:this.total.pixels,mode:this.mode}}restoreState(e){if(!Number.isFinite(e.pixels)||e.pixels<0||!(e.mode in ko))throw Error(`Invalid odometer checkpoint`);this.total.pixels=e.pixels,this.mode=e.mode,this.dirty=!0,this.flush();try{this.store?.setItem(Do,this.mode)}catch{}}get dpi(){return ko[this.mode]}cycleDpi(){this.mode=this.mode===`print`?`screen`:`print`;try{this.store?.setItem(Do,this.mode)}catch{}return this.readout}flush(){if(this.dirty)try{this.store?.setItem(Eo,JSON.stringify(this.total)),this.dirty=!1}catch{}}get kilometers(){return this.total.pixels/this.dpi*Ao/1e3}get miles(){return this.total.pixels/this.dpi*Ao/Oo}get readout(){return{pixels:this.total.pixels,kilometers:this.kilometers,miles:this.miles,dpi:this.dpi,dpiMode:this.mode}}},Fo=e=>!!e&&typeof e==`object`&&!Array.isArray(e);function Io(e,t){if(Object.is(e,t))return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>Io(e,t[n]));if(!Fo(e)||!Fo(t))return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Io(e[n],t[n]))}var Lo=e=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==`id`&&e!==`base`));function Ro(e,t){if(Io(e,t))return;if(!Fo(e)||!Fo(t))return e;let n=Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Ro(n,t[e])]).filter(([,e])=>e!==void 0));return Object.keys(n).length?n:void 0}function zo(e){let t=Object.values(z),n=t.find(t=>t.id===e.base);if(!n)return e;let r=I(n,e),i=e;for(let e of t){let t=Object.fromEntries(Object.entries(r).filter(([t,n])=>t!==`id`&&t!==`base`&&!Io(n,e[t]))),n={base:e.id,...t};Io(Lo(I(e,n)),Lo(r))&&JSON.stringify(n).length<JSON.stringify(i).length&&(i=n)}return i}function Bo(e,t){let n=[],r=new Set,i=e;for(;t?.vehicles?.[i]&&!r.has(i);){r.add(i);let e=t.vehicles[i];n.unshift(e),i=e.base}return I({slots:y},...n.map(e=>({slots:e.slots}))).slots}function Vo(e){let t=Wt(Vt),n=e.options?Ro(e.options,t):void 0,r=e.definitions?{...Object.fromEntries(Object.entries(e.definitions).filter(([,e])=>Object.keys(e??{}).length)),...e.definitions.vehicles?{vehicles:Object.fromEntries(Object.entries(e.definitions.vehicles).map(([e,t])=>[e,zo(t)]))}:{}}:void 0,i=e.player?Bo(e.player.vehicle,r):void 0,a=e.player?{vehicle:e.player.vehicle,...e.player.appearance&&e.player.appearance!==`auto`?{appearance:e.player.appearance}:{},...e.player.slots?{slots:Object.fromEntries(Object.entries(e.player.slots).filter(([e,t])=>!Io(t,i?.[e])))}:{}}:void 0;return a?.slots&&!Object.keys(a.slots).length&&delete a.slots,{...e.root?{root:e.root}:{},...r&&Object.values(r).some(e=>Object.keys(e??{}).length)?{definitions:r}:{},...a?{player:a}:{},...e.bindings?.length?{bindings:e.bindings}:{},...e.routes&&Object.keys(e.routes).length?{routes:e.routes}:{},...n?{options:n}:{}}}var Ho=`https://unpkg.com/@joy-ride/joy-ride@latest/npm/embed.js`,Uo=`https://unpkg.com/@joy-ride/joy-ride@latest/npm/index.js`;function Wo(e){let t=Vo(e),n=t.definitions?.vehicles;if(!n)return t;let r=typeof document<`u`&&document.baseURI||Ho;return{...t,definitions:{...t.definitions,vehicles:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,{...t,...t.image?.src?{image:{...t.image,src:new URL(t.image.src,r).href}}:{}}]))}}}function Go(e){return`javascript:(()=>{const u=${JSON.stringify(Ho)},o=${JSON.stringify(Wo(e))},d=window.JoyRide;if(d){d.active?d.active.dispose():d.mount(o);return}const s=document.createElement('script');s.type='module';s.src=u;s.async=true;s.charset='utf-8';s.onload=()=>window.JoyRide.mount(o);document.head.append(s)})()`}function Ko(e){return JSON.stringify(Wo(e),null,2).replace(/</g,`\\u003c`).replace(/\n/g,`
2
+ `)}function qo(e){return`<button type="button" id="joy-ride-toggle">${(e.options?.ui.brandName??`Joy Ride`).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}</button>
3
+ <script type="module">
4
+ const joyRideOptions = ${Ko(e)};
5
+ document.querySelector('#joy-ride-toggle').addEventListener('click', async () => {
6
+ const { default: JoyRide } = await import(${JSON.stringify(Uo)});
7
+ if (JoyRide.active) JoyRide.active.dispose();
8
+ else JoyRide.mount(joyRideOptions);
9
+ });
10
+ <\/script>`}function Jo(e){return`const joyRideOptions = ${Ko(e)};
11
+ const joyRideUrl = ${JSON.stringify(Uo)};
12
+ const { default: JoyRide } = await import(
13
+ /* @vite-ignore */ /* webpackIgnore: true */ joyRideUrl
14
+ );
15
+ const ride = JoyRide.mount(joyRideOptions);
16
+ // Call ride.dispose() when the host view is removed.`}function Yo(e){return`import JoyRide from '@joy-ride/joy-ride';
17
+
18
+ const joyRideOptions = ${Ko(e)};
19
+ const ride = JoyRide.mount(joyRideOptions);
20
+ // Call ride.dispose() when the host view is removed.`}export{V as $,K as A,e as At,an as B,_n as C,ye as Ct,G as D,le as Dt,J as E,ue as Et,H as F,t as Ft,Zt as G,Kt as H,mn as I,u as It,Ht as J,Vt as K,dn as L,p as Lt,on as M,i as Mt,pn as N,o as Nt,W as O,te as Ot,hn as P,a as Pt,Nt as Q,fn as R,X as S,Ie as St,q as T,P as Tt,Yt as U,en as V,Xt as W,Bt as X,Gt as Y,Lt as Z,Nn as _,z as _t,Po as a,Ct as at,wn as b,Re as bt,wo as c,xt as ct,pr as d,R as dt,At as et,mr as f,ft,jn as g,ht as gt,Zn as h,gt as ht,Yo as i,St as it,U as j,c as jt,Y as k,g as kt,Qa as l,Et as lt,cr as m,_t as mt,Go as n,Tt as nt,Mo as o,wt as ot,ur as p,dt as pt,Wt as q,qo as r,Ot as rt,To as s,kt as st,Jo as t,jt as tt,fr as u,Dt as ut,kn as v,tt as vt,yn as w,_e as wt,Cn as x,Le as xt,Tn as y,I as yt,cn as z};