@joy-ride/game 0.25.1 → 0.26.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.
- package/README.md +1 -5
- package/bookmarklet.js +1 -1
- package/embed-chunks/{CodeBlock-DMi-BeLY.js → CodeBlock-QLZWgPoe.js} +1 -1
- package/embed-chunks/{Documentation-CI9JoAsv.js → Documentation-BJMN2wVe.js} +2 -2
- package/embed-chunks/{EmbedPanel-CgEZTMF7.js → EmbedPanel-sqS3N8pg.js} +1 -1
- package/embed-chunks/{JoyRideView-C3AYwIPH.js → JoyRideView-DaI5oip_.js} +1 -1
- package/embed-chunks/{configuration~index~embed-CG9auZKS.js → configuration~index~embed-0luxl74s.js} +1 -1
- package/embed-chunks/{configuration~index~embed~bookmarklet-C8RUCiUX.js → configuration~index~embed~bookmarklet-BH7GyoGh.js} +1 -1
- package/embed-chunks/{configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~Documentation~JoyRideView~~n76yhyet-zf1LIsS8.js → configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~Documentation~JoyRideView~~n76yhyet-mgPW9A8j.js} +1 -1
- package/embed-chunks/{configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~JoyRideView~browser-sessio~iaaa3ndj-BBrKrH7m.js → configuration~index~embed~bookmarklet~vehicle-popover~EmbedPanel~JoyRideView~browser-sessio~iaaa3ndj-DLfKTakR.js} +1 -1
- package/embed-chunks/{runtime~JoyRideView~browser-session-core-Ya-yv4PC.js → runtime~JoyRideView~browser-session-core-Bkk9BE6P.js} +1 -1
- package/embed-chunks/{runtime~browser-session-core-DUfZaJcj.js → runtime~browser-session-core-COeP2p6D.js} +1 -1
- package/embed-chunks/{runtime~index~embed-B2Zpd22X.js → runtime~index~embed-cWNM8Fsj.js} +2 -2
- package/embed-chunks/{runtime~index~embed~vehicle-popover~browser-session-core~renderer-OqE9OpvH.js → runtime~index~embed~vehicle-popover~browser-session-core~renderer-YuWj6rHi.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover-DI44kx2W.js → runtime~vehicle-popover-vmgt62ll.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover~browser-session-core-BC-HGK32.js → runtime~vehicle-popover~browser-session-core-CjXpkmYi.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover~browser-session-core~renderer-CHG4ymHM.js → runtime~vehicle-popover~browser-session-core~renderer-CLLM7CAb.js} +1 -1
- package/embed-chunks/{runtime~vehicle-popover~renderer-DwVymD49.js → runtime~vehicle-popover~renderer-Cx3wjyMH.js} +1 -1
- package/embed-chunks/{src-v4km-Xn-.js → src-rpwqYZr-.js} +2 -2
- package/embed-chunks/{vehicle-catalog~index~embed-DcyLaPhV.js → vehicle-catalog~index~embed-CZzI6C0M.js} +1 -1
- package/embed-chunks/{vehicle-popover-CBTIiR6Q.js → vehicle-popover-C34y-W5W.js} +1 -1
- package/embed.js +1 -1
- package/index.js +1 -1
- package/npm-chunks/{Documentation-D5RIEQza.js → Documentation-Nc7GWFnR.js} +2 -2
- package/npm-chunks/{EmbedPanel-COgcEIgT.js → EmbedPanel-DRQcCEA1.js} +1 -1
- package/npm-chunks/{JoyRideView-C2nOVKZu.js → JoyRideView-B3g_Yxhd.js} +1 -1
- package/npm-chunks/{configuration~react-CKBQFWEF.js → configuration~react-CgNlw0cC.js} +1 -1
- package/npm-chunks/{configuration~react~vehicle-popover~EmbedPanel~Documentation~JoyRideView~browser-session-co~fvauaeow-zf1LIsS8.js → configuration~react~vehicle-popover~EmbedPanel~Documentation~JoyRideView~browser-session-co~fvauaeow-mgPW9A8j.js} +1 -1
- package/npm-chunks/{configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core-BQ8wO_VE.js → configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core-rFMaxKZs.js} +1 -1
- package/npm-chunks/{configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core~renderer-DJhBwBho.js → configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core~renderer-Bo9KSudc.js} +1 -1
- package/npm-chunks/{runtime~JoyRideView~browser-session-core-CuSPCh9O.js → runtime~JoyRideView~browser-session-core-CBQyAv9f.js} +1 -1
- package/npm-chunks/{runtime~browser-session-core-BenGnDZN.js → runtime~browser-session-core-CuLU4VUg.js} +1 -1
- package/npm-chunks/{runtime~react-BKEnJfDK.js → runtime~react-Jmjjtxii.js} +1 -1
- package/npm-chunks/{runtime~react~browser-session-core-Cr50FE3R.js → runtime~react~browser-session-core-n5P8q7G8.js} +1 -1
- package/npm-chunks/{runtime~vehicle-popover~browser-session-core-Ddxp7Nuh.js → runtime~vehicle-popover~browser-session-core-Ce3U7qky.js} +1 -1
- package/npm-chunks/{runtime~vehicle-popover~renderer-CYXkRwO4.js → runtime~vehicle-popover~renderer-Dmf1M43y.js} +1 -1
- package/npm-chunks/{sync-shadow-theme-Bqi_M9ro.js → sync-shadow-theme-DieEPOi7.js} +1 -1
- package/npm-chunks/{vehicle-catalog~react~vehicle-popover~browser-session-core-B1wVsjdQ.js → vehicle-catalog~react~vehicle-popover~browser-session-core-CX066OIY.js} +1 -1
- package/npm-chunks/{vehicle-popover-CbBEYEjM.js → vehicle-popover-DAESh8qQ.js} +1 -1
- package/package.json +1 -1
- package/react.js +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./controls~react~vehicle-popover~JoyRideView~browser-session-core~renderer-Cnf30Q_A.js";import{t}from"./runtime~react~vehicle-popover-khBccGFq.js";function n(e,t,n,r=()=>!0){let i=e.getAttribute(t);if(i===null)return n;let a=Number(i);if(!i.trim()||!Number.isFinite(a)||!r(a))throw TypeError(`${t} must be a valid number`);return a}function r(e){let t=n(e,`data-jr-entry-angle-rad`,0),r=n(e,`data-jr-entry-distance-px`,185,e=>e>0),i=n(e,`data-jr-entry-fade-fraction`,.5,e=>e>=0&&e<=1),a=n(e,`data-jr-entry-steer`,.04,e=>Math.abs(e)<=1),o=n(e,`data-jr-entry-delay-ms`,0,e=>e>=0),s=e.getAttribute(`data-jr-entry-speed-mps`)===null?void 0:n(e,`data-jr-entry-speed-mps`,0,e=>e>0);return{target:e,delayMs:o,approach:{angleRad:t,distancePx:r,fadeFraction:i,...s?{initialSpeedMps:s}:{}},handbrake:{steer:a}}}function i(e){let t=e.querySelector(`[data-jr-entry]`);return t?r(t):null}var a=()=>t(()=>import(`./runtime~vehicle-popover~renderer-
|
|
1
|
+
import{t as e}from"./controls~react~vehicle-popover~JoyRideView~browser-session-core~renderer-Cnf30Q_A.js";import{t}from"./runtime~react~vehicle-popover-khBccGFq.js";function n(e,t,n,r=()=>!0){let i=e.getAttribute(t);if(i===null)return n;let a=Number(i);if(!i.trim()||!Number.isFinite(a)||!r(a))throw TypeError(`${t} must be a valid number`);return a}function r(e){let t=n(e,`data-jr-entry-angle-rad`,0),r=n(e,`data-jr-entry-distance-px`,185,e=>e>0),i=n(e,`data-jr-entry-fade-fraction`,.5,e=>e>=0&&e<=1),a=n(e,`data-jr-entry-steer`,.04,e=>Math.abs(e)<=1),o=n(e,`data-jr-entry-delay-ms`,0,e=>e>=0),s=e.getAttribute(`data-jr-entry-speed-mps`)===null?void 0:n(e,`data-jr-entry-speed-mps`,0,e=>e>0);return{target:e,delayMs:o,approach:{angleRad:t,distancePx:r,fadeFraction:i,...s?{initialSpeedMps:s}:{}},handbrake:{steer:a}}}function i(e){let t=e.querySelector(`[data-jr-entry]`);return t?r(t):null}var a=()=>t(()=>import(`./runtime~vehicle-popover~renderer-Dmf1M43y.js`).then(e=>e.n),[],import.meta.url),o=async()=>{let[{BrowserSessionCore:n},{Renderer:r}]=await Promise.all([t(()=>import(`./runtime~browser-session-core-CuLU4VUg.js`).then(e=>e.t),[],import.meta.url),a()]);return(...t)=>new n(t[0],t[1]??{},t[2]??{},{Renderer:r,installPageLayers:e})},s=`joy-ride:preferences:v1`;function c(e){if(e!==void 0&&(!e||typeof e!=`object`||Array.isArray(e)))throw TypeError(`persist must be an object`);for(let[t,n]of Object.entries(e??{})){if(t!==`vehicle`&&t!==`audio`)throw TypeError(`Unknown persist field: ${t}`);if(typeof n!=`boolean`)throw TypeError(`persist.${t} must be boolean`)}return{vehicle:e?.vehicle??!0,audio:e?.audio??!0}}function l(){try{return globalThis.localStorage}catch{return}}function u(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=1}function d(e=l()){try{let t=e?.getItem(s);if(!t)return{};let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))return{};let r=n,i=r.audio;return{...typeof r.vehicle==`string`&&r.vehicle.length?{vehicle:r.vehicle}:{},...i&&typeof i==`object`&&!Array.isArray(i)&&u(i.masterVolume)&&u(i.lastAudibleVolume)&&i.lastAudibleVolume>0?{audio:{masterVolume:i.masterVolume,lastAudibleVolume:i.lastAudibleVolume}}:{}}}catch{return{}}}function f(e,t=l()){try{t?.setItem(s,JSON.stringify({...d(t),...e}))}catch{}}function p(e,t){e&&f({vehicle:e},t)}function m(e,t){u(e.masterVolume)&&u(e.lastAudibleVolume)&&e.lastAudibleVolume>0&&f({audio:e},t)}export{o as a,p as i,c as n,i as o,m as r,d as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,o as t}from"./configuration~react~vehicle-popover~JoyRideView~browser-session-core~renderer-B70Mpi9X.js";import{c as n,n as r,t as i}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core~renderer-Dt96jol6.js";import{r as a}from"./definitions~react~vehicle-popover~browser-session-core~renderer-RDNEXk_b.js";import{f as o,i as s,s as c,t as l}from"./runtime~react~vehicle-popover~browser-session-core~renderer-Be8cIaU4.js";import{t as u}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core-BZJqthWX.js";import{a as d,r as f,t as p}from"./configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core-BQ8wO_VE.js";import{a as m,g as h,i as g,n as _,o as v,r as y,s as b,t as x}from"./definitions~react~browser-session-core-acRq5AYt.js";import{n as S,r as C}from"./configuration~react~browser-session-core-CyXr42pk.js";import{o as w}from"./vehicle-catalog~react~browser-session-core-BzB5J-Lm.js";var T=class{releases=[];disposed=!1;own(e){if(this.disposed)try{e()}catch(e){console.error(`JoyRide cleanup failed`,e)}else this.releases.push(e)}disown(e){let t=this.releases.lastIndexOf(e);t>=0&&this.releases.splice(t,1)}listen(e,t,n,r){e.addEventListener(t,n,r),this.own(()=>e.removeEventListener(t,n,r))}dispose(){if(!this.disposed){this.disposed=!0;for(let e of this.releases.splice(0).reverse())try{e()}catch(e){console.error(`JoyRide cleanup failed`,e)}}}},E=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 D(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`${t} must be an object`);return e}function O(e,t,n){for(let r of Object.keys(e))if(!n.includes(r))throw TypeError(`Unknown ${t} field: ${r}`)}function k(e,t,n,r=()=>!0){if(e[t]!==void 0&&(typeof e[t]!=`number`||!Number.isFinite(e[t])||!r(e[t])))throw TypeError(`${n}.${t} must be a valid number`)}function A(e){let t=D(e,`entry`);O(t,`entry`,[`target`,`delayMs`,`stopAt`,`approach`,`handbrake`]);let n=t.target;if(typeof n==`string`){if(!n.trim())throw TypeError(`entry.target must be a nonempty CSS selector`)}else{let e=D(n,`entry.target`);if(O(e,`entry.target`,[`xPx`,`yPx`]),k(e,`xPx`,`entry.target`),k(e,`yPx`,`entry.target`),e.xPx===void 0||e.yPx===void 0)throw TypeError(`entry.target requires xPx and yPx`)}if(k(t,`delayMs`,`entry`,e=>e>=0),t.stopAt!==void 0){let e=D(t.stopAt,`entry.stopAt`);O(e,`entry.stopAt`,[`x`,`y`,`offsetXPx`,`offsetYPx`]);for(let t of[`x`,`y`,`offsetXPx`,`offsetYPx`])k(e,t,`entry.stopAt`)}if(t.approach!==void 0){let e=D(t.approach,`entry.approach`);O(e,`entry.approach`,[`angleRad`,`distancePx`,`initialSpeedMps`,`fadeFraction`]),k(e,`angleRad`,`entry.approach`),k(e,`distancePx`,`entry.approach`,e=>e>0),k(e,`initialSpeedMps`,`entry.approach`,e=>e>0),k(e,`fadeFraction`,`entry.approach`,e=>e>=0&&e<=1)}if(t.handbrake!==void 0){let e=D(t.handbrake,`entry.handbrake`);O(e,`entry.handbrake`,[`steer`]),k(e,`steer`,`entry.handbrake`,e=>Math.abs(e)<=1)}return e}function j(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))j(a,`${t}.${i}`,n,r);r.delete(e)}}function M(e){return e&&typeof e==`object`&&(Object.values(e).forEach(M),Object.freeze(e)),e}function N(e){let t=[];if(j(e,`configuration`,t),t.length)throw new E(t);for(let t of Object.keys(e))if(![`audioSet`,`persist`,`definitions`,`player`,`bindings`,`routes`,`objectives`,`game`,`dialog`,`entry`].includes(t))throw TypeError(`Unknown playground configuration field: ${t}`);if(e.audioSet!==void 0&&!/^[a-z0-9][a-z0-9_-]*$/.test(e.audioSet))throw TypeError(`Audio set must be a folder name`);if(e.persist!==void 0){if(!e.persist||typeof e.persist!=`object`||Array.isArray(e.persist))throw TypeError(`persist must be an object`);for(let[t,n]of Object.entries(e.persist)){if(t!==`vehicle`&&t!==`audio`)throw TypeError(`Unknown persist field: ${t}`);if(typeof n!=`boolean`)throw TypeError(`persist.${t} must be boolean`)}}e.entry!==void 0&&A(e.entry);let n=x(e.definitions??{}),r=e.player===void 0?void 0:v(e.player),i=e.bindings?.map((e,t)=>{if(typeof e.target!=`string`||!e.target.trim())throw new E([{path:`bindings.${t}.target`,reason:`use a selector instead of an element reference`}]);return{target:e.target,spec:g(e.spec)}}),a=e.routes&&Object.fromEntries(Object.entries(e.routes).map(([e,t])=>[e,b(t)])),o=e.objectives&&Object.fromEntries(Object.entries(e.objectives).map(([e,t])=>[e,_(t)])),s=f(d(p,{game:e.game,dialog:e.dialog}));return M(structuredClone({...e,definitions:n,player:r,bindings:i,routes:a,objectives:o,...s,format:`joy-ride-playground`,version:3}))}function P(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!==3)throw TypeError(`Unsupported playground configuration format or version`);for(let e of Object.keys(t))if(![`format`,`version`,`audioSet`,`persist`,`definitions`,`player`,`bindings`,`routes`,`objectives`,`game`,`dialog`,`entry`].includes(e))throw TypeError(`Unknown playground configuration field: ${e}`);let{format:n,version:r,...i}=t;return N(i)}function F(e,t){if(!(typeof HTMLElement<`u`&&e instanceof HTMLElement)){for(let e of[`trigger`,`crushable`,`combustible`,`pushable`])if(t[e])throw new h(`object.${e}`,`${e} requires an HTML element`);if(t.liquid&&!(typeof SVGGeometryElement<`u`&&e instanceof SVGGeometryElement))throw new h(`object.liquid`,`liquid requires HTML or an SVG shape`);if(!(typeof SVGSVGElement<`u`&&e instanceof SVGSVGElement)&&(t.breakable||t.burnable))throw new h(`object`,`breakable and burnable artwork require HTML text/artwork or an SVG root`)}}var I=0;function L(e){return e&&typeof e==`object`&&(Object.values(e).forEach(L),Object.freeze(e)),e}var R=class{root;definitions;scope=++I;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;observer;dirty=!0;disposed=!1;nextId=0;nextRegistration=0;version=0;pageStateChanged=()=>this.invalidate();constructor(e=document,t={}){this.root=e,this.definitions=x(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,l(`registry invalidations`);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(y(...r.map(e=>e.spec),S(e),...i.map(e=>e.spec),n));return F(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:g(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:g(y(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:g(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=g(y(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(C));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:L(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 E(e);return[...this.registrations].map(e=>({target:e.target,spec:structuredClone(e.spec)}))}exportDefinitions(){if(this.disposed)throw Error(`Playground is disposed`);return x({...this.definitions,liquids:{...this.definitions.liquids,...Object.fromEntries(this.importedLiquids)},vehicles:{...this.definitions.vehicles,...Object.fromEntries(this.importedVehicles)}})}registerVehiclePreset(t,n){if(this.disposed)throw Error(`Playground is disposed`);if(this.definitions.vehicles?.[t]||this.importedVehicles.has(t)||Object.values(e).some(e=>e.id===t))throw Error(`Vehicle recipe already exists: ${t}`);let{id:r,...i}=w(n),a={...i,base:e.porsche911997.id};return x({vehicles:{[t]:a}}),this.importedVehicles.set(t,a),t}vehicleName(t){for(let[e,n]of this.vehicles)if(n.id===t)return e;if(Object.values(e).some(e=>e.id===t))return t;throw new E([{path:`player.vehicle`,reason:`vehicle ${t} has no authored recipe in this catalog`}])}resolve(e,t=new Set){let n=y(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=y(this.resolve(r,t),a)}let r=n.liquid;return r&&typeof r==`object`&&typeof r.kind==`string`&&(r.kind=this.resolveLiquid(r.kind)),m(n)}resolveLiquid(e,t=new Set){let r=this.liquids.get(e);if(r)return r;let a=this.importedLiquids.get(e)??this.definitions.liquids?.[e];if(!a)return n(e);if(t.has(e))throw Error(`Circular liquid definition: ${e}`);t.add(e);let o=this.resolveLiquid(a.base,t),s=`jr-${this.scope}-${this.liquids.size}-`,c=i(`${s}${e.slice(0,64-s.length)}`,{...a,base:o});return this.liquids.set(e,c.kind),c.kind}liquidName(e){for(let[t,n]of this.liquids)if(n===e)return t;return e}resolveVehicle(t,n=new Set){let r=this.vehicles.get(t);if(r)return r;let i=this.importedVehicles.get(t)??this.definitions.vehicles?.[t];if(!i){let n=Object.values(e).find(e=>e.id===t);if(!n)throw Error(`Unknown vehicle definition: ${t}`);return n}if(n.has(t))throw Error(`Circular vehicle definition: ${t}`);n.add(t);let{base:a,appearance:o,slots:s,...c}=i,l=w(y(this.resolveVehicle(a,n),c,{id:`custom-jr-${this.scope}-${t}`}));return this.vehicles.set(t,l),l}vehicleOptions(e){let t=this.importedVehicles.get(e)??this.definitions.vehicles?.[e];return t?y(this.vehicleOptions(t.base),{appearance:t.appearance,slots:t.slots}):{appearance:`auto`,slots:u}}captureState(){return a({patches:this.patches,registrations:new Map([...this.registrations].map(e=>[e.id,e.spec]))})}restoreState(e){let t=a(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())r(e);this.liquids.clear(),this.vehicles.clear(),this.importedVehicles.clear(),this.importedLiquids.clear()}}};function z(e,t){let n=e.getBoundingClientRect(),r=n.left+window.scrollX+n.width/2,i=n.top+window.scrollY+n.height/2,a=r-(t?.xPx??r-185),o=i-(t?.yPx??i);return{target:e,approach:{angleRad:Math.hypot(a,o)>1?Math.atan2(o,a):-(t?.angleRad??0),distancePx:185,fadeFraction:.5},handbrake:{steer:.04}}}function B(e){let t=e.car;return t.rollingResistance*(4+2*t.handbrakeStrength*7)/e.body.mass}function V(e,t){let n=e.car;return n.preset.handbrakeDecelerationMps2+n.preset.coastDecelerationMps2+B(e)*t*.75}function H(e,t,n){return t*t*n/(2*V(e,t))}function U(e,t,n){let r=0,i=60;for(let a=0;a<14;a++){let a=(r+i)/2;H(e,a,n)<t?r=a:i=a}return(r+i)/2}function W(e,n,r){let{handbrake:i,stopAt:a}=e,c={angleRad:e.approach?.angleRad??0,distancePx:e.approach?.distancePx??185,initialSpeedMps:e.approach?.initialSpeedMps,fadeFraction:e.approach?.fadeFraction??.5};if(![c.angleRad,c.distancePx,c.initialSpeedMps??1,c.fadeFraction,i?.steer??0,a?.x??.5,a?.y??.5,a?.offsetXPx??0,a?.offsetYPx??0,r].every(Number.isFinite)||c.distancePx<=0||c.initialSpeedMps!==void 0&&c.initialSpeedMps<=0||c.fadeFraction<0||c.fadeFraction>1||Math.abs(i?.steer??0)>1||r<=0)return null;let l;try{l=typeof e.target==`string`?document.querySelector(e.target):e.target}catch(e){if(e instanceof DOMException&&e.name===`SyntaxError`)return null;throw e}if(!l)return null;let u=`xPx`in l?o(l.xPx,l.yPx):(()=>{if(!l.isConnected)return null;let e=l.getBoundingClientRect();return o(e.left+window.scrollX+e.width*(a?.x??.5),e.top+window.scrollY+e.height*(a?.y??.5))})();if(!u||!Number.isFinite(u.x)||!Number.isFinite(u.y))return null;u.x+=a?.offsetXPx??0,u.y+=a?.offsetYPx??0;let d=o(Math.cos(c.angleRad),Math.sin(c.angleRad)),f=c.initialSpeedMps??U(n,c.distancePx,r),p=f*f*r/(2*c.distancePx),m=s((p-V(n,f))/t(n.car.preset),0,1),h=B(n),g=Math.max(.01,n.car.preset.handbrakeDecelerationMps2+n.car.preset.coastDecelerationMps2+m*t(n.car.preset)),_=h>0?Math.log1p(h*f/g)/h:f/g;return{destination:u,start:o(u.x-d.x*c.distancePx,u.y-d.y*c.distancePx),headingRad:-c.angleRad,velocity:o(d.x*f,-d.y*f),fadeDurationSeconds:_*c.fadeFraction,steer:i?.steer??0,serviceBrake:m}}var G=class{fadeDurationSeconds;steer;serviceBrake;elapsedSeconds=0;done=!1;constructor(e,t,n=0){this.fadeDurationSeconds=e,this.steer=t,this.serviceBrake=n}get opacity(){return this.fadeDurationSeconds===0?1:s(this.elapsedSeconds/this.fadeDurationSeconds,0,1)}get complete(){return this.done}drive(e,t,n,r,i){return this.elapsedSeconds+=r,c(e.body.velocity)<.45||this.elapsedSeconds>3?(this.done=!0,{throttle:0,steer:0,action:!1,boost:!1}):{throttle:0,steer:this.steer,action:!0,brake:this.serviceBrake,boost:!1}}};export{E as a,A as c,R as i,T as l,z as n,N as o,W as r,P as s,G as t};
|
|
1
|
+
import{c as e,o as t}from"./configuration~react~vehicle-popover~JoyRideView~browser-session-core~renderer-B70Mpi9X.js";import{c as n,n as r,t as i}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core~renderer-Dt96jol6.js";import{r as a}from"./definitions~react~vehicle-popover~browser-session-core~renderer-RDNEXk_b.js";import{f as o,i as s,s as c,t as l}from"./runtime~react~vehicle-popover~browser-session-core~renderer-Be8cIaU4.js";import{t as u}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core-BZJqthWX.js";import{a as d,r as f,t as p}from"./configuration~react~vehicle-popover~EmbedPanel~JoyRideView~browser-session-core-rFMaxKZs.js";import{a as m,g as h,i as g,n as _,o as v,r as y,s as b,t as x}from"./definitions~react~browser-session-core-acRq5AYt.js";import{n as S,r as C}from"./configuration~react~browser-session-core-CyXr42pk.js";import{o as w}from"./vehicle-catalog~react~browser-session-core-BzB5J-Lm.js";var T=class{releases=[];disposed=!1;own(e){if(this.disposed)try{e()}catch(e){console.error(`JoyRide cleanup failed`,e)}else this.releases.push(e)}disown(e){let t=this.releases.lastIndexOf(e);t>=0&&this.releases.splice(t,1)}listen(e,t,n,r){e.addEventListener(t,n,r),this.own(()=>e.removeEventListener(t,n,r))}dispose(){if(!this.disposed){this.disposed=!0;for(let e of this.releases.splice(0).reverse())try{e()}catch(e){console.error(`JoyRide cleanup failed`,e)}}}},E=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 D(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`${t} must be an object`);return e}function O(e,t,n){for(let r of Object.keys(e))if(!n.includes(r))throw TypeError(`Unknown ${t} field: ${r}`)}function k(e,t,n,r=()=>!0){if(e[t]!==void 0&&(typeof e[t]!=`number`||!Number.isFinite(e[t])||!r(e[t])))throw TypeError(`${n}.${t} must be a valid number`)}function A(e){let t=D(e,`entry`);O(t,`entry`,[`target`,`delayMs`,`stopAt`,`approach`,`handbrake`]);let n=t.target;if(typeof n==`string`){if(!n.trim())throw TypeError(`entry.target must be a nonempty CSS selector`)}else{let e=D(n,`entry.target`);if(O(e,`entry.target`,[`xPx`,`yPx`]),k(e,`xPx`,`entry.target`),k(e,`yPx`,`entry.target`),e.xPx===void 0||e.yPx===void 0)throw TypeError(`entry.target requires xPx and yPx`)}if(k(t,`delayMs`,`entry`,e=>e>=0),t.stopAt!==void 0){let e=D(t.stopAt,`entry.stopAt`);O(e,`entry.stopAt`,[`x`,`y`,`offsetXPx`,`offsetYPx`]);for(let t of[`x`,`y`,`offsetXPx`,`offsetYPx`])k(e,t,`entry.stopAt`)}if(t.approach!==void 0){let e=D(t.approach,`entry.approach`);O(e,`entry.approach`,[`angleRad`,`distancePx`,`initialSpeedMps`,`fadeFraction`]),k(e,`angleRad`,`entry.approach`),k(e,`distancePx`,`entry.approach`,e=>e>0),k(e,`initialSpeedMps`,`entry.approach`,e=>e>0),k(e,`fadeFraction`,`entry.approach`,e=>e>=0&&e<=1)}if(t.handbrake!==void 0){let e=D(t.handbrake,`entry.handbrake`);O(e,`entry.handbrake`,[`steer`]),k(e,`steer`,`entry.handbrake`,e=>Math.abs(e)<=1)}return e}function j(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))j(a,`${t}.${i}`,n,r);r.delete(e)}}function M(e){return e&&typeof e==`object`&&(Object.values(e).forEach(M),Object.freeze(e)),e}function N(e){let t=[];if(j(e,`configuration`,t),t.length)throw new E(t);for(let t of Object.keys(e))if(![`audioSet`,`persist`,`definitions`,`player`,`bindings`,`routes`,`objectives`,`game`,`dialog`,`entry`].includes(t))throw TypeError(`Unknown playground configuration field: ${t}`);if(e.audioSet!==void 0&&!/^[a-z0-9][a-z0-9_-]*$/.test(e.audioSet))throw TypeError(`Audio set must be a folder name`);if(e.persist!==void 0){if(!e.persist||typeof e.persist!=`object`||Array.isArray(e.persist))throw TypeError(`persist must be an object`);for(let[t,n]of Object.entries(e.persist)){if(t!==`vehicle`&&t!==`audio`)throw TypeError(`Unknown persist field: ${t}`);if(typeof n!=`boolean`)throw TypeError(`persist.${t} must be boolean`)}}e.entry!==void 0&&A(e.entry);let n=x(e.definitions??{}),r=e.player===void 0?void 0:v(e.player),i=e.bindings?.map((e,t)=>{if(typeof e.target!=`string`||!e.target.trim())throw new E([{path:`bindings.${t}.target`,reason:`use a selector instead of an element reference`}]);return{target:e.target,spec:g(e.spec)}}),a=e.routes&&Object.fromEntries(Object.entries(e.routes).map(([e,t])=>[e,b(t)])),o=e.objectives&&Object.fromEntries(Object.entries(e.objectives).map(([e,t])=>[e,_(t)])),s=f(d(p,{game:e.game,dialog:e.dialog}));return M(structuredClone({...e,definitions:n,player:r,bindings:i,routes:a,objectives:o,...s,format:`joy-ride-playground`,version:3}))}function P(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!==3)throw TypeError(`Unsupported playground configuration format or version`);for(let e of Object.keys(t))if(![`format`,`version`,`audioSet`,`persist`,`definitions`,`player`,`bindings`,`routes`,`objectives`,`game`,`dialog`,`entry`].includes(e))throw TypeError(`Unknown playground configuration field: ${e}`);let{format:n,version:r,...i}=t;return N(i)}function F(e,t){if(!(typeof HTMLElement<`u`&&e instanceof HTMLElement)){for(let e of[`trigger`,`crushable`,`combustible`,`pushable`])if(t[e])throw new h(`object.${e}`,`${e} requires an HTML element`);if(t.liquid&&!(typeof SVGGeometryElement<`u`&&e instanceof SVGGeometryElement))throw new h(`object.liquid`,`liquid requires HTML or an SVG shape`);if(!(typeof SVGSVGElement<`u`&&e instanceof SVGSVGElement)&&(t.breakable||t.burnable))throw new h(`object`,`breakable and burnable artwork require HTML text/artwork or an SVG root`)}}var I=0;function L(e){return e&&typeof e==`object`&&(Object.values(e).forEach(L),Object.freeze(e)),e}var R=class{root;definitions;scope=++I;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;observer;dirty=!0;disposed=!1;nextId=0;nextRegistration=0;version=0;pageStateChanged=()=>this.invalidate();constructor(e=document,t={}){this.root=e,this.definitions=x(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,l(`registry invalidations`);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(y(...r.map(e=>e.spec),S(e),...i.map(e=>e.spec),n));return F(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:g(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:g(y(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:g(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=g(y(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(C));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:L(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 E(e);return[...this.registrations].map(e=>({target:e.target,spec:structuredClone(e.spec)}))}exportDefinitions(){if(this.disposed)throw Error(`Playground is disposed`);return x({...this.definitions,liquids:{...this.definitions.liquids,...Object.fromEntries(this.importedLiquids)},vehicles:{...this.definitions.vehicles,...Object.fromEntries(this.importedVehicles)}})}registerVehiclePreset(t,n){if(this.disposed)throw Error(`Playground is disposed`);if(this.definitions.vehicles?.[t]||this.importedVehicles.has(t)||Object.values(e).some(e=>e.id===t))throw Error(`Vehicle recipe already exists: ${t}`);let{id:r,...i}=w(n),a={...i,base:e.porsche911997.id};return x({vehicles:{[t]:a}}),this.importedVehicles.set(t,a),t}vehicleName(t){for(let[e,n]of this.vehicles)if(n.id===t)return e;if(Object.values(e).some(e=>e.id===t))return t;throw new E([{path:`player.vehicle`,reason:`vehicle ${t} has no authored recipe in this catalog`}])}resolve(e,t=new Set){let n=y(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=y(this.resolve(r,t),a)}let r=n.liquid;return r&&typeof r==`object`&&typeof r.kind==`string`&&(r.kind=this.resolveLiquid(r.kind)),m(n)}resolveLiquid(e,t=new Set){let r=this.liquids.get(e);if(r)return r;let a=this.importedLiquids.get(e)??this.definitions.liquids?.[e];if(!a)return n(e);if(t.has(e))throw Error(`Circular liquid definition: ${e}`);t.add(e);let o=this.resolveLiquid(a.base,t),s=`jr-${this.scope}-${this.liquids.size}-`,c=i(`${s}${e.slice(0,64-s.length)}`,{...a,base:o});return this.liquids.set(e,c.kind),c.kind}liquidName(e){for(let[t,n]of this.liquids)if(n===e)return t;return e}resolveVehicle(t,n=new Set){let r=this.vehicles.get(t);if(r)return r;let i=this.importedVehicles.get(t)??this.definitions.vehicles?.[t];if(!i){let n=Object.values(e).find(e=>e.id===t);if(!n)throw Error(`Unknown vehicle definition: ${t}`);return n}if(n.has(t))throw Error(`Circular vehicle definition: ${t}`);n.add(t);let{base:a,appearance:o,slots:s,...c}=i,l=w(y(this.resolveVehicle(a,n),c,{id:`custom-jr-${this.scope}-${t}`}));return this.vehicles.set(t,l),l}vehicleOptions(e){let t=this.importedVehicles.get(e)??this.definitions.vehicles?.[e];return t?y(this.vehicleOptions(t.base),{appearance:t.appearance,slots:t.slots}):{appearance:`auto`,slots:u}}captureState(){return a({patches:this.patches,registrations:new Map([...this.registrations].map(e=>[e.id,e.spec]))})}restoreState(e){let t=a(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())r(e);this.liquids.clear(),this.vehicles.clear(),this.importedVehicles.clear(),this.importedLiquids.clear()}}};function z(e,t){let n=e.getBoundingClientRect(),r=n.left+window.scrollX+n.width/2,i=n.top+window.scrollY+n.height/2,a=r-(t?.xPx??r-185),o=i-(t?.yPx??i);return{target:e,approach:{angleRad:Math.hypot(a,o)>1?Math.atan2(o,a):-(t?.angleRad??0),distancePx:185,fadeFraction:.5},handbrake:{steer:.04}}}function B(e){let t=e.car;return t.rollingResistance*(4+2*t.handbrakeStrength*7)/e.body.mass}function V(e,t){let n=e.car;return n.preset.handbrakeDecelerationMps2+n.preset.coastDecelerationMps2+B(e)*t*.75}function H(e,t,n){return t*t*n/(2*V(e,t))}function U(e,t,n){let r=0,i=60;for(let a=0;a<14;a++){let a=(r+i)/2;H(e,a,n)<t?r=a:i=a}return(r+i)/2}function W(e,n,r){let{handbrake:i,stopAt:a}=e,c={angleRad:e.approach?.angleRad??0,distancePx:e.approach?.distancePx??185,initialSpeedMps:e.approach?.initialSpeedMps,fadeFraction:e.approach?.fadeFraction??.5};if(![c.angleRad,c.distancePx,c.initialSpeedMps??1,c.fadeFraction,i?.steer??0,a?.x??.5,a?.y??.5,a?.offsetXPx??0,a?.offsetYPx??0,r].every(Number.isFinite)||c.distancePx<=0||c.initialSpeedMps!==void 0&&c.initialSpeedMps<=0||c.fadeFraction<0||c.fadeFraction>1||Math.abs(i?.steer??0)>1||r<=0)return null;let l;try{l=typeof e.target==`string`?document.querySelector(e.target):e.target}catch(e){if(e instanceof DOMException&&e.name===`SyntaxError`)return null;throw e}if(!l)return null;let u=`xPx`in l?o(l.xPx,l.yPx):(()=>{if(!l.isConnected)return null;let e=l.getBoundingClientRect();return o(e.left+window.scrollX+e.width*(a?.x??.5),e.top+window.scrollY+e.height*(a?.y??.5))})();if(!u||!Number.isFinite(u.x)||!Number.isFinite(u.y))return null;u.x+=a?.offsetXPx??0,u.y+=a?.offsetYPx??0;let d=o(Math.cos(c.angleRad),Math.sin(c.angleRad)),f=c.initialSpeedMps??U(n,c.distancePx,r),p=f*f*r/(2*c.distancePx),m=s((p-V(n,f))/t(n.car.preset),0,1),h=B(n),g=Math.max(.01,n.car.preset.handbrakeDecelerationMps2+n.car.preset.coastDecelerationMps2+m*t(n.car.preset)),_=h>0?Math.log1p(h*f/g)/h:f/g;return{destination:u,start:o(u.x-d.x*c.distancePx,u.y-d.y*c.distancePx),headingRad:-c.angleRad,velocity:o(d.x*f,-d.y*f),fadeDurationSeconds:_*c.fadeFraction,steer:i?.steer??0,serviceBrake:m}}var G=class{fadeDurationSeconds;steer;serviceBrake;elapsedSeconds=0;done=!1;constructor(e,t,n=0){this.fadeDurationSeconds=e,this.steer=t,this.serviceBrake=n}get opacity(){return this.fadeDurationSeconds===0?1:s(this.elapsedSeconds/this.fadeDurationSeconds,0,1)}get complete(){return this.done}drive(e,t,n,r,i){return this.elapsedSeconds+=r,c(e.body.velocity)<.45||this.elapsedSeconds>3?(this.done=!0,{throttle:0,steer:0,action:!1,boost:!1}):{throttle:0,steer:this.steer,action:!0,brake:this.serviceBrake,boost:!1}}};export{E as a,A as c,R as i,T as l,z as n,N as o,W as r,P as s,G as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,n as t,r as n}from"./configuration~react~vehicle-popover~JoyRideView~browser-session-core~renderer-B70Mpi9X.js";import{a as r,r as i}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core~renderer-Dt96jol6.js";import{r as a}from"./definitions~react~vehicle-popover~browser-session-core~renderer-RDNEXk_b.js";import{S as o,c as s,d as c,f as l,i as u,l as d,o as f,s as p,u as m}from"./runtime~react~vehicle-popover~browser-session-core~renderer-Be8cIaU4.js";import{_ as h,b as g,g as _,h as v,v as y,x as b,y as ee}from"./runtime~vehicle-popover~browser-session-core~renderer-jVG7K050.js";import{n as te,r as x,t as S}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core-BZJqthWX.js";import{n as ne,r as re}from"./vehicle-catalog~react~vehicle-popover~browser-session-core-B1wVsjdQ.js";function ie(){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 ae(){let e=ie();if(e.__xstate__)return e.__xstate__}var oe=e=>{if(typeof window>`u`)return;let t=ae();t&&t.register(e)},se=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}},ce=``,le=`#`,ue=`*`,de=`xstate.init`,fe=`xstate.stop`;function pe(e,t){return{type:`xstate.after.${e}.${t}`}}function me(e,t){return{type:`xstate.done.state.${e}`,output:t}}function he(e,t){return{type:`xstate.done.actor.${e}`,output:t,actorId:e}}function ge(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function _e(e){return{type:de,input:e}}function C(e){setTimeout(()=>{throw e})}var ve=typeof Symbol==`function`&&Symbol.observable||`@@observable`;function ye(e,t){let n=xe(e),r=xe(t);return typeof r==`string`?typeof n==`string`&&r===n:typeof n==`string`?n in r:Object.keys(n).every(e=>e in r&&ye(n[e],r[e]))}function be(e){if(Ee(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 xe(e){return Nt(e)?e.value:typeof e==`string`?Se(be(e)):e}function Se(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 Ce(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 we(e){return Ee(e)?e:[e]}function w(e){return e===void 0?[]:we(e)}function Te(e,t,n,r){return typeof e==`function`?e({context:t,event:n,self:r}):e}function Ee(e){return Array.isArray(e)}function De(e){return e.type.startsWith(`xstate.error.actor`)}function T(e){return we(e).map(e=>e===void 0||typeof e==`string`?{target:e}:e)}function Oe(e){if(e!==void 0&&e!==ce)return w(e)}function E(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 ke(e,t){return`${t}.${e}`}function D(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 Ae(e,t){if(t===e||t===ue)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 je(e,t){return`${e.sessionId}.${t}`}var Me=0;function Ne(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=je(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=je(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:${Me++}`,_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=E(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 O=!1,k=function(e){return e[e.NotStarted=0]=`NotStarted`,e[e.Running=1]=`Running`,e[e.Stopped=2]=`Stopped`,e}({}),Pe={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1},Fe=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 se(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=k.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={...Pe,...t},{clock:r,logger:i,parent:a,syncSnapshot:o,id:s,systemId:c,inspect:l}=n;this.system=a?a.system:Ne(this,{clock:r,logger:i}),l&&!a&&this.system.inspect(E(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){C(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=O;try{O=!0,e.exec(e.info,e.params)}finally{O=t}};this._processingStatus===k.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){C(e)}break;case`done`:for(let t of this.observers)try{t.next?.(e)}catch(e){C(e)}this._stopProcedure(),this._complete(),this._doneEvent=he(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=E(e,t,n);if(this._processingStatus!==k.Stopped)this.observers.add(r);else switch(this._snapshot.status){case`done`:try{r.complete?.()}catch(e){C(e)}break;case`error`:{let e=this._snapshot.error;if(!r.error)C(e);else try{r.error(e)}catch(e){C(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=E(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===k.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=k.Running;let e=_e(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===k.Stopped?this:(this.mailbox.clear(),this._processingStatus===k.NotStarted?(this._processingStatus=k.Stopped,this):(this.mailbox.enqueue({type:fe}),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){C(e)}this.observers.clear(),this.eventListeners.clear()}_reportError(e){if(!this.observers.size){this._parent||C(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){C(e)}}this.observers.clear(),this.eventListeners.clear(),t&&C(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,ge(this.id,e))}_stopProcedure(){return this._processingStatus===k.Running&&(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new se(this._process.bind(this)),this._processingStatus=k.Stopped,this.system._unregister(this)),this}_send(e){this._processingStatus!==k.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:oe)(this)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[ve](){return this}getSnapshot(){return this._snapshot}};function A(e,...[t]){return new Fe(e,t)}function Ie(e,t,n,r,{sendId:i}){return[t,{sendId:typeof i==`function`?i(n,r):i},void 0]}function Le(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t.sendId)})}function Re(e){function t(e,t){}return t.type=`xstate.cancel`,t.sendId=e,t.resolve=Ie,t.execute=Le,t}function ze(e,t,n,r,{id:i,systemId:a,src:o,input:s,syncSnapshot:c}){let l=typeof o==`string`?D(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=A(l,{id:u,src:o,parent:e.self,syncSnapshot:c,systemId:a,input:f})),[q(t,{children:{...t.children,[u]:d}}),{id:i,systemId:a,actorRef:d,src:o,input:f},void 0]}function Be(e,{actorRef:t}){t&&e.defer(()=>{t._processingStatus!==k.Stopped&&t.start()})}function Ve(...[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=ze,a.execute=Be,a}function He(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]),[q(t,{children:s}),o,void 0]}function Ue(e,t){let n=t.getSnapshot();if(n&&`children`in n)for(let t of Object.values(n.children))Ue(e,t);e.system._unregister(t)}function We(e,t){t&&(Ue(e,t),t._processingStatus===k.Running?e.defer(()=>{e.stopChild(t)}):e.stopChild(t))}function j(e){function t(e,t){}return t.type=`xstate.stopChild`,t.actorRef=e,t.resolve=He,t.execute=We,t}function Ge(e,{context:t,event:n},{guards:r}){return r.every(r=>M(r,t,n,e))}function Ke(e){function t(e,t){return!1}return t.check=Ge,t.guards=e,t}function M(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 M(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 qe(e){return e.type===`atomic`||e.type===`final`}function N(e){return Object.values(e.states).filter(e=>e.type!==`history`)}function P(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 F(e){let t=new Set(e),n=Ye(t);for(let e of t)if(e.type===`compound`&&(!n.get(e)||!n.get(e).length))at(e).forEach(e=>t.add(e));else if(e.type===`parallel`){for(let n of N(e))if(n.type!==`history`&&!t.has(n)){let e=at(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 Je(e,t){let n=t.get(e);if(!n)return{};if(e.type===`compound`){let e=n[0];if(e){if(qe(e))return e.key}else return{}}let r={};for(let e of n)r[e.key]=Je(e,t);return r}function Ye(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 Xe(e,t){return Je(e,Ye(F(t)))}function Ze(e,t){return t.type===`compound`?N(t).some(t=>t.type===`final`&&e.has(t)):t.type===`parallel`?N(t).every(t=>Ze(e,t)):t.type===`final`}var I=e=>e[0]===le;function Qe(e,t){let n=e.transitions.get(t),r=[...e.transitions.keys()].filter(e=>e!==t&&Ae(t,e)).sort((e,t)=>t.length-e.length).flatMap(t=>e.transitions.get(t));return n?[...n,...r]:r}function $e(e){let t=e.config.after;if(!t)return[];let n=t=>{let n=pe(t,e.id),r=n.type;return e.entry.push(Wt(n,{id:r,delay:t})),e.exit.push(Re(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 w(i).map(e=>({...e,event:o,delay:a}))}).map(t=>{let{delay:n}=t;return{...L(e,t.event,t),delay:n}})}function L(e,t,n){let r=Oe(n.target),i=n.reenter??!1,a=rt(e,r),o={...n,actions:w(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 et(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,T(r).map(t=>L(e,n,t)))}if(e.config.onDone){let n=`xstate.done.state.${e.id}`;t.set(n,T(e.config.onDone).map(t=>L(e,n,t)))}for(let n of e.invoke){if(n.onDone){let r=`xstate.done.actor.${n.id}`;t.set(r,T(n.onDone).map(t=>L(e,r,t)))}if(n.onError){let r=`xstate.error.actor.${n.id}`;t.set(r,T(n.onError).map(t=>L(e,r,t)))}if(n.onSnapshot){let r=`xstate.snapshot.${n.id}`;t.set(r,T(n.onSnapshot).map(t=>L(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 tt(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?Ke([a,i]):a,target:`#${n}`};t.push(L(e,`xstate.route`,o))}r.states&&n(r.states)})};n(e.states),t.length>0&&e.transitions.set(`xstate.route`,t)}function nt(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`?[]:w(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 rt(e,t){if(t!==void 0)return t.map(t=>{if(typeof t!=`string`)return t;if(I(t))return e.machine.getStateNodeById(t);let n=t[0]===`.`;if(n&&!e.parent)return B(e,t.slice(1));let r=n?e.key+t:t;if(e.parent)try{return B(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 it(e){let t=Oe(e.config.target);return t?{target:t.map(t=>typeof t==`string`?B(e.parent,t):t)}:e.parent.type===`parallel`?{target:[e.parent]}:e.parent.initial}function R(e){return e.type===`history`}function at(e){let t=ot(e);for(let n of t)for(let r of P(n,e))t.add(r);return t}function ot(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 N(e))n(t)}}return n(e),t}function z(e,t){if(I(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 B(e,t){if(typeof t==`string`&&I(t))try{return e.machine.getStateNodeById(t)}catch{}let n=be(t).slice(),r=e;for(;n.length;){let e=n.shift();if(!e.length)break;r=z(r,e)}return r}function V(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=>z(e,t)).filter(Boolean);return[e.machine.root,e].concat(r,n.reduce((n,r)=>{let i=z(e,r);if(!i)return n;let a=V(i,t[r]);return n.concat(a)},[]))}function st(e,t,n,r){let i=z(e,t).next(n,r);return!i||!i.length?e.next(n,r):i}function ct(e,t,n,r){let i=Object.keys(t),a=ut(z(e,i[0]),t[i[0]],n,r);return!a||!a.length?e.next(n,r):a}function lt(e,t,n,r){let i=[];for(let a of Object.keys(t)){let o=t[a];if(!o)continue;let s=ut(z(e,a),o,n,r);s&&i.push(...s)}return i.length?i:e.next(n,r)}function ut(e,t,n,r){return typeof t==`string`?st(e,t,n,r):Object.keys(t).length===1?ct(e,t,n,r):lt(e,t,n,r)}function dt(e){return Object.keys(e.states).map(t=>e.states[t]).filter(e=>e.type===`history`)}function H(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function ft(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 pt(e,t,n){let r=new Set;for(let i of e){let e=!1,a=new Set;for(let o of r)if(ft(_t([i],t,n),_t([o],t,n))){if(H(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 mt(e){let[t,...n]=e;for(let e of P(t,void 0))if(n.every(t=>H(t,e)))return e}function ht(e,t){if(!e.target)return[];let n=new Set;for(let r of e.target)if(R(r)){if(t[r.id])for(let e of t[r.id])n.add(e);else for(let e of ht(it(r),t))n.add(e)}else n.add(r);return[...n]}function gt(e,t){let n=ht(e,t);if(!n)return;if(!e.reenter&&n.every(t=>t===e.source||H(t,e.source)))return e.source;let r=mt(n.concat(e.source));if(r)return r;if(!e.reenter)return e.source.machine.root}function _t(e,t,n){let r=new Set;for(let i of e)if(i.target?.length){let e=gt(i,n);i.reenter&&i.source===e&&r.add(e);for(let n of t)H(n,e)&&r.add(n)}return[...r]}function vt(e,t){if(e.length!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function yt(e,t,n,r,i){return U([{target:[...ot(e)],source:e,reenter:!0,actions:[],eventType:null,toJSON:null}],t,n,r,!0,i)}function U(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=pt(e,s,c),u=t;i||([u,c]=Tt(u,r,n,l,s,c,a,n.actionExecutor)),u=G(u,r,n,l.flatMap(e=>e.actions),a,void 0),u=xt(u,r,n,l,s,a,c,i);let d=[...s];u.status===`done`&&(u=G(u,r,n,d.sort((e,t)=>t.order-e.order).flatMap(e=>e.exit),a,void 0));try{return c===t.historyValue&&vt(t._nodes,s)?[u,o]:[q(u,{_nodes:d,historyValue:c}),o]}catch(e){throw e}}finally{n.actionExecutor=s}}function bt(e,t,n,r,i){if(r.output===void 0)return;let a=me(i.id,i.output!==void 0&&i.parent?Te(i.output,e.context,t,n.self):void 0);return Te(r.output,e.context,a,n.self)}function xt(e,t,n,r,i,a,o,s){let c=e,l=new Set,u=new Set;St(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(Ve(t.src,{...t,syncSnapshot:!!t.onSnapshot}));if(u.has(e)){let t=e.initial.actions;r.push(...t)}if(c=G(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(me(r.id,e.output===void 0?void 0:Te(e.output,c.context,t,n.self)));o?.type===`parallel`&&!d.has(o)&&Ze(i,o);)d.add(o),a.push(me(o.id)),s=o,o=o.parent;if(o)continue;c=q(c,{status:`done`,output:bt(c,t,n,c.machine.root,s)})}}return c}function St(e,t,n,r){for(let i of e){let e=gt(i,t);for(let a of i.target||[])!R(a)&&(i.source!==a||i.source!==e||i.reenter)&&(r.add(a),n.add(a)),W(a,t,n,r);let a=ht(i,t);for(let o of a){let a=P(o,e);e?.type===`parallel`&&a.push(e),Ct(r,t,n,a,!i.source.parent&&i.reenter?void 0:e)}}}function W(e,t,n,r){if(R(e)){if(t[e.id]){let i=t[e.id];for(let e of i)r.add(e),W(e,t,n,r);for(let a of i)wt(a,e.parent,r,t,n)}else{let i=it(e);for(let a of i.target)r.add(a),i===e.parent?.initial&&n.add(e.parent),W(a,t,n,r);for(let a of i.target)wt(a,e.parent,r,t,n)}}else if(e.type===`compound`){let[i]=e.initial.target;R(i)||(r.add(i),n.add(i)),W(i,t,n,r),wt(i,e,r,t,n)}else if(e.type===`parallel`)for(let i of N(e).filter(e=>!R(e)))[...r].some(e=>H(e,i))||(R(i)||(r.add(i),n.add(i)),W(i,t,n,r))}function Ct(e,t,n,r,i){for(let a of r)if((!i||H(a,i))&&e.add(a),a.type===`parallel`)for(let r of N(a).filter(e=>!R(e)))[...e].some(e=>H(e,r))||(e.add(r),W(r,t,n,e))}function wt(e,t,n,r,i){Ct(n,r,i,P(e,t))}function Tt(e,t,n,r,i,a,o,s){let c=e,l=_t(r,i,a);l.sort((e,t)=>t.order-e.order);let u;for(let e of l)for(let t of dt(e)){let n;n=t.history===`deep`?t=>qe(t)&&H(t,e):t=>t.parent===e,u??={...a},u[t.id]=Array.from(i).filter(n)}for(let e of l)c=G(c,t,n,[...e.exit,...e.invoke.map(e=>j(e.id))],o,void 0),i.delete(e);return[c,u||a]}function Et(e,t){return e.implementations.actions[t]}function Dt(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:Et(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=Dt(s,t,n,m,i,a))}return s}function G(e,t,n,r,i,a){let o=a?[]:void 0,s=Dt(e,t,n,r,{internalQueue:i,deferredActorIds:a},o);return o?.forEach(([e,t])=>{e.retryResolve(n,s,t)}),s}function Ot(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=q(kt(i,t,n),{status:`stopped`}),o([i,[]],t,[]),{snapshot:i,microsteps:a};let s=t;if(s.type!==de){let t=s,c=De(t),l=At(t,i);if(c&&!l.length)return i=q(kt(i,t,n),{status:`error`,error:t.error}),o([i,[]],t,[]),{snapshot:i,microsteps:a};let u=U(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?jt(i,s):[],t=e.length?i:void 0;if(!e.length){if(!r.length)break;s=r.shift(),e=At(s,i)}let a=U(e,i,n,s,!1,r);i=a[0],c=i!==t,o(a,s,e)}return i.status!==`active`&&kt(i,s,n),{snapshot:i,microsteps:a}}function kt(e,t,n){return G(e,t,n,Object.values(e.children).map(e=>j(e)),[],void 0)}function At(e,t){return t.machine.getTransitionData(t,e)}function jt(e,t){let n=new Set,r=e._nodes.filter(qe);for(let i of r)loop:for(let r of[i].concat(P(i,void 0)))if(r.always){for(let i of r.always)if(i.guard===void 0||M(i.guard,e.context,t,e)){n.add(i);break loop}}return pt(Array.from(n),new Set(e._nodes),e.historyValue)}function Mt(e,t){return Xe(e,[...F(V(e,t))])}function Nt(e){return!!e&&typeof e==`object`&&`machine`in e&&`value`in e}var Pt=function(e){return ye(e,this.value)},Ft=function(e){return this.tags.has(e)},It=function(e){let t=this.machine.getTransitionData(this,e);return!!t?.length&&t.some(e=>e.target!==void 0||e.actions.length)},Lt=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)}},Rt=function(){return this._nodes.reduce((e,t)=>(t.meta!==void 0&&(e[t.id]=t.meta),e),{})};function K(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:Xe(t.root,e._nodes),tags:new Set(e._nodes.flatMap(e=>e.tags)),children:e.children,historyValue:e.historyValue||{},matches:Pt,hasTag:Ft,can:It,getMeta:Rt,toJSON:Lt}}function q(e,t={}){return K({...e,...t},e.machine)}function zt(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 Bt(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:Vt(o),children:p,historyValue:zt(f.historyValue)}}function Vt(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=Vt(r);i!==r&&(t??=Array.isArray(e)?e.slice():{...e},t[n]=i)}}}return t??e}function Ht(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 Ut(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 Wt(e,t){function n(e,t){}return n.type=`xstate.raise`,n.event=e,n.id=t?.id,n.delay=t?.delay,n.resolve=Ht,n.execute=Ut,n}function Gt(e,{machine:t,context:n},r,i){let a=(a,o)=>{if(typeof a==`string`){let s=D(t,a);if(!s)throw Error(`Actor logic '${a}' not implemented in machine '${t.id}'`);let c=A(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 A(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!==k.Stopped&&r.start()}),r}}function Kt(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:Gt(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[q(t,{context:Object.assign({},t.context,s),children:Object.keys(a).length?{...t.children,...a}:t.children}),void 0,void 0]}function qt(e){function t(e,t){}return t.type=`xstate.assign`,t.assignment=e,t.resolve=Kt,t}var Jt=new WeakMap;function J(e,t,n){let r=Jt.get(e);return r?t in r||(r[t]=n()):(r={[t]:n()},Jt.set(e,r)),r[t]}var Yt={},Y=e=>typeof e==`string`?{type:e}:typeof e==`function`?`resolve`in e?{type:e.type}:{type:e.name}:e,Xt=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?Ce(this.config.states,(t,n)=>new e(t,{_parent:this,_key:n,_machine:this.machine})):Yt,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=w(this.config.entry).slice(),this.exit=w(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type===`final`||!this.parent?this.config.output:void 0,this.tags=w(t.tags).slice()}_initialize(){this.transitions=et(this),this.config.always&&(this.always=T(this.config.always).map(e=>L(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(Y),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(Y),eventType:null,meta:this.initial.meta,description:this.initial.description})}:void 0,history:this.history,states:Ce(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(Y)})),entry:this.entry.map(Y),exit:this.exit.map(Y),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 J(this,`invoke`,()=>w(this.config.invoke).map((e,t)=>{let{src:n,systemId:r}=e,i=e.id??ke(this.id,t),a=typeof n==`string`?n:`xstate.invoke.${ke(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 J(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 J(this,`delayedTransitions`,()=>$e(this))}get initial(){return J(this,`initial`,()=>nt(this,this.config.initial))}next(e,t){let n=t.type,r=[],i,a=J(this,`candidates-${n}`,()=>Qe(this,n));for(let o of a){let{guard:a}=o,s=e.context,c=!1;try{c=!a||M(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 J(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)}},Zt=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 Xt(e,{_key:this.id,_machine:this}),this.root._initialize(),tt(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=Mt(this.root,e.value),n=F(V(this.root,t));return K({_nodes:[...n],context:e.context||{},children:{},status:Ze(n,this.root)?`done`:e.status||`active`,output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,t,n){return Ot(e,t,n,[]).snapshot}microstep(e,t,n){return Ot(e,t,n,[]).microsteps.map(([e])=>e)}getTransitionData(e,t){return ut(this.root,e.value,e,t)||[]}_getPreInitialState(e,t,n){let{context:r}=this.config,i=K({context:typeof r!=`function`&&r?r:{},_nodes:[this.root],children:{},status:`active`},this);return typeof r==`function`?G(i,t,e,[qt(({spawn:e,event:t,self:n})=>r({spawn:e,input:t.input,self:n}))],n,void 0):i}getInitialSnapshot(e,t){let n=_e(t),r=[],i=K({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]=yt(this.root,i,e,n,r),{snapshot:a}=Ot(t,n,e,r);return a}catch(e){return q(i,{status:`error`,error:e})}}start(e){Object.values(e.children).forEach(e=>{e.getSnapshot().status===`active`&&e.start()})}getStateNodeById(e){let t=be(e),n=t.slice(1),r=I(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 B(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,t){return Bt(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`?D(this,o):o;if(!s)return;let c=A(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 Xt)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=K({...e,children:n,_nodes:Array.from(F(V(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 Qt(e,t,n,r,{event:i}){return[t,{event:typeof i==`function`?i(n,r):i},void 0]}function $t(e,{event:t}){e.defer(()=>e.emit(t))}function en(e){function t(e,t){}return t.type=`xstate.emit`,t.event=e,t.resolve=Qt,t.execute=$t,t}var tn=function(e){return e.Parent=`#_parent`,e.Internal=`#_internal`,e}({});function nn(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===tn.Parent?e.self._parent:f===tn.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 rn(e,t,n){typeof n.to==`string`&&(n.to=t.children[n.to])}function an(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`?ge(e.self.id,r.data):r)})}function on(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=nn,r.retryResolve=rn,r.execute=an,r}function sn(e,t){return on(tn.Parent,e,t)}function cn(e,t,n,r,{collect:i}){let a=[],o=function(e){a.push(e)};return o.assign=(...e)=>{a.push(qt(...e))},o.cancel=(...e)=>{a.push(Re(...e))},o.raise=(...e)=>{a.push(Wt(...e))},o.sendTo=(...e)=>{a.push(on(...e))},o.sendParent=(...e)=>{a.push(sn(...e))},o.spawnChild=(...e)=>{a.push(Ve(...e))},o.stopChild=(...e)=>{a.push(j(...e))},o.emit=(...e)=>{a.push(en(...e))},i({context:n.context,event:n.event,enqueue:o,check:e=>M(e,t.context,n.event,t),self:e.self,system:e.system},r),[t,void 0,a]}function ln(e){function t(e,t){}return t.type=`xstate.enqueueActions`,t.collect=e,t.resolve=cn,t}function un(e,t,n,r,{value:i,label:a}){return[t,{value:typeof i==`function`?i(n,r):i,label:a},void 0]}function dn({logger:e},{value:t,label:n}){n?e(n,t):e(t)}function fn(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=un,n.execute=dn,n}function pn(e,t){return new Zt(e,t)}function mn({schemas:e,actors:t,actions:n,guards:r,delays:i}){return{assign:qt,sendTo:on,raise:Wt,log:fn,cancel:Re,stopChild:j,enqueueActions:ln,emit:en,spawnChild:Ve,createStateConfig:e=>e,createAction:e=>e,createMachine:a=>pn({...a,schemas:e},{actors:t,actions:n,guards:r,delays:i}),extend:a=>mn({schemas:e,actors:t,actions:{...n,...a.actions},guards:{...r,...a.guards},delays:{...i,...a.delays}})}}var hn=(e,t,n)=>Math.max(t,Math.min(n,e)),gn=class{dents=[];revision=0;enabled=!1;maxDepthM=0;maskCache=new WeakMap;spriteCache=null;captureState(){return a({dents:this.dents,revision:this.revision,enabled:this.enabled,maxDepthM:this.maxDepthM})}restoreState(e){let t=a(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=s(e,n.center),u=l(f(o,n.forward)/a,f(o,n.side)/a),d=l(f(t,n.forward),f(t,n.side)),m=p(d);if(m<.001)return!1;let h=hn((r-2.5)/17.5,0,1)**1.5;return this.maxDepthM=Math.min(.25,8/a),this.dents.push({center:u,inward:c(d,1/m),depthM:this.maxDepthM*h,radiusAlongM:.65+h*.5,radiusAcrossM:.55+h*.55}),this.dents.length>12&&this.dents.shift(),this.revision++,this.spriteCache=null,!0}point(e){if(!this.hasDamage)return e;let t=l();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=d(t,c(n.inward,n.depthM*o))}let n=p(t);return n>this.maxDepthM&&(t=c(t,this.maxDepthM/n)),d(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,c=e.widthM/r;for(let t=0;t<r;t++)for(let u=0;u<n;u++){let f=l((u+.5)*o-e.lengthM/2,(t+.5)*c-e.widthM/2),p=f;for(let e=0;e<5;e++)p=d(p,s(f,this.point(p)));let m=Math.floor((p.x/e.lengthM+.5)*n),h=Math.floor((p.y/e.widthM+.5)*r);m>=0&&m<n&&h>=0&&h<r&&(a[t*n+u]=i[h*n+m])}let u={...e,alpha:{columns:n,rows:r,solid:a}};return this.maskCache.set(e,{revision:this.revision,value:u}),u}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=l((e.x/r.width-.5)*t.lengthM,(e.y/r.height-.5)*t.widthM),i=this.point(n);return l((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,u=n*r.height/10,d=(n+1)*r.height/10,f=l(s,u),p=l(c,u),m=l(s,d),h=l(c,d);this.drawTriangle(i,e,t,[f,p,m],[a(f),a(p),a(m)]),this.drawTriangle(i,e,t,[h,m,p],[a(h),a(m),a(p)])}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,ee=(_*m-y*f)/h,te=(v*d-g*p)/h,x=(y*d-_*p)/h,S=c.x-b*a.x-te*a.y,ne=c.y-ee*a.x-x*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,ee,te,x,S,ne),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()}},_n=class{random;pulses=[];constructor(e=Math.random){this.random=e}get active(){return this.pulses}trigger({color:e,angle:t,velocity:n,origin:r}){if(!Number.isFinite(t)||!Number.isFinite(n))throw RangeError(`Pickup angle and velocity must be finite`);if(r&&(!Number.isFinite(r.x)||!Number.isFinite(r.y)||Math.abs(r.x)>.5||Math.abs(r.y)>.5))throw RangeError(`Pickup origin must lie within normalized body coordinates [-0.5, 0.5]`);let a=i(e),o=Math.min(1,Math.abs(n)/32);this.pulses.push({color:[a[0]/255,a[1]/255,a[2]/255],angle:Math.atan2(Math.sin(t),Math.cos(t)),strength:o,velocity:Math.abs(n),origin:r?{...r}:null,variation:this.random(),age:0,duration:.38-o*.1}),this.pulses.length>3&&this.pulses.shift()}step(e){if(!(!this.pulses.length||!Number.isFinite(e)||e<=0)){for(let t of this.pulses)t.age+=e;this.pulses=this.pulses.filter(e=>e.age<e.duration)}}reset(){this.pulses=[]}captureState(){return structuredClone(this.pulses)}restoreState(e){this.pulses=structuredClone(e)}},vn=new Map,X=null;function yn(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?[u(+n[1],0,255),u(+n[2],0,255),u(+n[3],0,255)]:null}function bn(e){let t=yn(e);if(t)return t;if(vn.has(e))return vn.get(e);let n=null;return typeof document<`u`&&(X??=document.createElement(`canvas`).getContext(`2d`),X&&(X.fillStyle=`#010203`,X.fillStyle=e,X.fillStyle!==`#010203`&&(n=yn(X.fillStyle)))),vn.set(e,n),n}var xn=[[0,0],[60,120],[120,180],[240,240],[300,300],[360,360]];function Sn(e,t=!1){let n=(e%360+360)%360;for(let e=1;e<xn.length;e++){let[r,i]=xn[e-1],[a,o]=xn[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 Cn([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 wn(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 Tn(e){let t=e.filter(e=>e.strength>0&&bn(e.color));if(!t.length)return e.at(-1)?.color??`rgb(0 0 0)`;if(t.length===1)return`rgb(${bn(t[0].color).join(` `)})`;let n=0,r=0,i=0,a=0,o=0;for(let e of t){let t=Cn(bn(e.color)),s=Sn(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 wn(Sn((Math.atan2(r,n)*180/Math.PI+360)%360,!0),Math.min(1,a/o),i/o)}var En=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 a({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=a(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,u(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,i,a,o,s){let c=this.coating(e);if(!c||a<=0||s<=0)return;let l=r.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 ee(t,n,i,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 c=this.coating(e);if(!c){this.pauseTrack(e);return}let l=this.previous.get(e),d=this.wetPaths.get(e);if(!d||!l||p(s(t,l))>=1.5*i)d={marks:[],distanceM:0},this.wetPaths.set(e,d),o&&(this.marks.push({...c,from:{...t},point:{...t},angle:n,widthM:r,phaseM:this.travelM.get(e)??0,slip:u(a,0,1),overPuddle:!0}),this.markCount++);else{let f=d.marks.at(-1),m=f&&p(s(f.point,f.from))/i<.02,h=m?f.from:l;m&&(d.distanceM-=p(s(f.point,f.from))/i);let g=p(s(t,h))/i,_={...c,from:{...h},point:{...t},angle:n,widthM:r,phaseM:(this.travelM.get(e)??0)-g,slip:u(a,0,1)};m?d.marks[d.marks.length-1]=_:d.marks.push(_),d.distanceM+=g,o&&g>=.02&&(this.marks.push({..._,overPuddle:!0}),this.markCount++,this.marks.length>3e4&&this.marks.splice(0,1e3));let v=Math.max(.5,r*6);for(;d.marks.length>1&&(d.distanceM>v||d.marks.length>128);){let e=d.marks.shift();d.distanceM-=p(s(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 c=this.coating(e);if(!c)return;let l=this.previous.get(e),d=l?p(s(t,l)):0,f=this.wetPaths.has(e)||this.exits.has(e)?.01:.05;if(l&&d<f*i)return;let m=l&&d<1.5*i,h=this.wetPaths.get(e);if(h&&m){let t=Math.max(.35,r*(2+4*(c.material?.film??.6))),n=-h.distanceM;for(let e of h.marks){let r=n+p(s(e.point,e.from))/i;this.marks.push({...e,overPuddle:!1,exit:{fromM:n,toM:r,lengthM:t,leadInM:h.distanceM}}),this.markCount++,n=r}this.exits.set(e,{distanceM:0,lengthM:t})}else m||this.exits.delete(e);this.wetPaths.delete(e);let g=this.exits.get(e),_=g&&g.distanceM<g.lengthM?{fromM:g.distanceM,toM:g.distanceM+d/i,lengthM:g.lengthM}:void 0;g&&(g.distanceM+=d/i,g.distanceM>=g.lengthM&&this.exits.delete(e)),this.marks.push({from:m?{...l}:{...t},point:{...t},angle:n,widthM:r,phaseM:(this.travelM.get(e)??0)-(m?p(s(t,l))/i:0),wetness:c.wetness,material:c.material,slip:u(o,0,1),color:c.color,opacity:c.opacity,overPuddle:a,exit:_}),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*u(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=u(r.remaining/r.distanceM,0,1);return{material:r.material,wetness:i,color:Tn(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))}}},Z={opening:.32,raising:.52,igniting:.48,closing:.36},Dn=class{previewOpen=!1;inspecting=!1;phase=`idle`;elapsed=0;held=!1;presetId=null;flights=[];launchClock=0;queuedShots=0;launches=0;ignitionDuration=Z.igniting;captureState(){return a({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=a(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=Z.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(t,n,r,i,a,o,s,p){if(n.mode!==`car`){this.reset();return}if(this.presetId&&this.presetId!==n.car.preset.id&&this.reset(),this.previewOpen){this.inspecting=!0,this.presetId=n.car.preset.id,(this.phase===`idle`||this.phase===`closing`)&&this.transition(`opening`),this.elapsed+=t,this.phase===`opening`&&this.elapsed>=Z.opening&&this.transition(`raising`),this.phase===`raising`&&(this.elapsed=Math.min(this.elapsed,Z.raising));return}this.inspecting&&(this.inspecting=!1,this.transition(`closing`));let h=!!n.lastInput.rocket;h&&!this.held&&(this.queuedShots++,(this.phase===`idle`||this.phase===`closing`)&&(this.presetId=n.car.preset.id,this.transition(`opening`))),this.held=h;let g=e(n.car.preset);if(this.phase===`idle`&&!this.flights.length)return;this.elapsed+=t,this.launchClock+=t;let _=n.car.preset.roofRocket,v=Math.max(1.05,_.sizeM*1.12);if(this.phase===`opening`&&this.elapsed>=Z.opening)this.transition(`raising`);else if(this.phase===`raising`&&this.elapsed>=Z.raising)this.ignitionDuration=Z.igniting,this.transition(`igniting`),p?.(n.body.world(l(_.xM,_.yM)));else if(this.phase===`igniting`&&this.elapsed>=this.ignitionDuration){let e=m(l(1,0),n.body.angle),t=n.body.world(l(_.xM,_.yM));this.flights.push({position:t,angle:n.body.angle,speedMps:g.launchSpeedMps+Math.max(0,f(n.body.velocity,e)),distanceM:0,age:0}),this.launches++,o?.(t),this.queuedShots=Math.max(0,this.queuedShots-1),this.launchClock=0,this.transition(`flying`)}else this.phase===`closing`&&this.elapsed>=Z.closing&&this.transition(`idle`);if(this.phase===`igniting`){let e=u(this.elapsed/Math.min(.27,this.ignitionDuration*.65),0,.9),i=m(l(-1,0),n.body.angle),o=n.body.world(l(_.xM-v*.52,_.yM));r({point:o,flow:c(i,3.5),amount:t*14*e,radiusM:.2}),a?.({from:o,to:o,flow:c(i,12),widthM:.16,intensity:e*.75})}this.phase===`flying`&&(!h&&this.queuedShots===0?this.transition(`closing`):this.launchClock>=Math.max(0,1/g.roundsPerSecond-Math.min(Z.igniting,.7/g.roundsPerSecond))&&(this.ignitionDuration=Math.min(Z.igniting,.7/g.roundsPerSecond),this.transition(`igniting`),p?.(n.body.world(l(_.xM,_.yM)))));for(let e=this.flights.length-1;e>=0;e--){let n=this.flights[e],o=m(l(1,0),n.angle);n.speedMps=Math.min(g.maxSpeedMps,n.speedMps+g.accelerationMps2*t);let u=n.speedMps*t,f=n.position,p=d(f,c(o,u)),h=i?.(f,p,_.sizeM*.18);n.position=h??p,n.distanceM+=u,n.age+=t;let y=d(n.position,c(o,-v*.53)),b=d(f,c(o,-v*.53));if(r({point:y,flow:c(o,-5),amount:t*g.smokePerSecond,radiusM:.2}),a?.({from:b,to:y,flow:c(o,-18),widthM:.13,intensity:.9}),h){s?.(h);for(let e=0;e<7;e++){let t=m(l(1,0),e*Math.PI*2/7);r({point:h,flow:c(t,5.5),amount:.18,radiusM:.22})}this.flights.splice(e,1)}else(n.age>=g.lifetimeSeconds||n.distanceM>100)&&this.flights.splice(e,1)}this.phase===`closing`&&this.elapsed>=Z.closing&&this.transition(`idle`)}get open(){return this.phase===`idle`?0:this.phase===`opening`?u(this.elapsed/Z.opening,0,1):this.phase===`closing`?1-u(this.elapsed/Z.closing,0,1):1}drawMount(e,t,n,r,i,a=1,o){let s=this.open;if(s<=0)return;y();let c=r.roofRocket,l=c.sizeM*i,d=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 f=e.createLinearGradient(0,-l/2,0,l/2);f.addColorStop(0,`#11171b`),f.addColorStop(.45,`#030609`),f.addColorStop(1,`#222a2e`),e.fillStyle=f,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-d*.78),r=t*(l*.25+d*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:u(this.elapsed/Z.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,!h(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()}},On=.22,kn=.24,An=class{phase=`closed`;phaseTime=0;shotClock=0;flashAge=1/0;presetId=null;bullets=[];captureState(){return a({phase:this.phase,phaseTime:this.phaseTime,shotClock:this.shotClock,flashAge:this.flashAge,presetId:this.presetId,bullets:this.bullets})}restoreState(e){let t=a(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,r,i,a){if(t.mode!==`car`){this.reset();return}this.presetId&&this.presetId!==t.car.preset.id&&this.reset();let o=n(t.car.preset),s=!!t.lastInput.machineGun;if(s&&(this.phase===`closed`||this.phase===`closing`)){this.presetId=t.car.preset.id;let e=this.open;this.phase=`opening`,this.phaseTime=e*On}else if(!s&&(this.phase===`opening`||this.phase===`active`)){let e=this.open;this.phase=`closing`,this.phaseTime=(1-e)*kn}if(this.phaseTime+=e,this.flashAge+=e,this.phase===`opening`&&this.phaseTime>=On&&(this.phase=`active`,this.phaseTime=0,this.shotClock=1/o.roundsPerSecond),this.phase===`active`){if(s){let n=1/Math.max(1,o.roundsPerSecond);this.shotClock+=e;for(let e=0;this.shotClock>=n&&e<4;e++)this.shotClock-=n,this.fire(t),i?.()}}else this.phase===`closing`&&this.phaseTime>=kn&&(this.phase=`closed`,this.phaseTime=0);for(let t=this.bullets.length-1;t>=0;t--){let n=this.bullets[t],i=n.position,s=d(i,c(n.velocity,e)),l=r?.(i,s,.075);n.age+=e,l||n.age>=o.bulletLifetimeSeconds?(l&&a?.(l,n.velocity),this.bullets.splice(t,1)):n.position=s}}fire(e){let t=n(e.car.preset),r=m(l(1,0),e.body.angle);for(let n of[-1,1]){let i=e.body.world(_(e.car.preset,n)),a=d(c(r,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`?u(this.phaseTime/On,0,1):this.phase===`closing`?1-u(this.phaseTime/kn,0,1):1}drawMount(e,t,n,r,i,a=1,o){v(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(d(i.position,c(i.velocity,-.75/Math.max(1,o)))),l=e.createLinearGradient(s.x,s.y,a.x,a.y);l.addColorStop(0,`rgba(224,153,63,0)`),l.addColorStop(.7,`rgba(224,153,63,.25)`),l.addColorStop(1,`rgba(255,225,157,.7)`),e.globalAlpha=r,e.strokeStyle=l,e.lineWidth=Math.max(.65,n*.025),e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(a.x,a.y),e.stroke();let u=t(d(i.position,c(i.velocity,-.09/Math.max(1,o))));e.strokeStyle=`#fff6d7`,e.lineWidth=Math.max(.55,n*.018),e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(a.x,a.y),e.stroke()}e.restore()}},jn=.22,Mn=.24,Q=1/45,Nn=class{phase=`closed`;phaseTime=0;emitting=!1;presetId=null;fireClock=0;jets=[];captureState(){return a({phase:this.phase,phaseTime:this.phaseTime,emitting:this.emitting,presetId:this.presetId,fireClock:this.fireClock,jets:this.jets})}restoreState(e){let t=a(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,n,r,i,a){if(n.mode!==`car`){(this.phase!==`closed`||this.jets.length)&&this.reset();return}this.presetId&&this.presetId!==n.car.preset.id&&this.reset();let o=!!n.lastInput.flamethrower,s=t(n.car.preset);if(o&&(this.phase===`closed`||this.phase===`closing`)){this.presetId=n.car.preset.id;let e=this.open;this.phase=`opening`,this.phaseTime=e*jn}else if(!o&&(this.phase===`opening`||this.phase===`active`)){let e=this.open;this.phase=`closing`,this.phaseTime=(1-e)*Mn}if(this.phaseTime+=e,this.phase===`opening`&&this.phaseTime>=jn&&(this.phase=`active`,this.phaseTime=0,this.fireClock=Q),this.emitting=this.phase===`active`&&o,this.phase===`closing`&&this.phaseTime>=Mn&&(this.phase=`closed`,this.phaseTime=0),this.emitting){let t=m(l(1,0),n.body.angle),i=s.rangeM/.3;for(this.fireClock+=e;this.fireClock>=Q;){this.fireClock-=Q;for(let e of[-1,1]){let r=n.body.world(_(n.car.preset,e));this.jets.push({point:r,velocity:d(c(t,i),c(n.body.velocity,.25)),traveled:0,range:s.rangeM,speed:i,width:s.jetWidthM*s.flowRate})}}for(let i of[-1,1]){let a=n.body.world(_(n.car.preset,i));r({point:d(a,c(t,.06)),flow:c(t,5.5),amount:e*s.smokePerSecond*s.flowRate*.38,radiusM:.12})}}let u=[];for(let t of this.jets){let n=Math.min(t.range-t.traveled,t.speed*e),o=t.point,l=d(o,c(t.velocity,n/t.speed)),f=(t.traveled+n)/t.range,p=t.width*(.65+1.45*f),m=i?.(o,l,Math.max(.3,p*1.25),Q*s.flowRate),h=m??l;t.point=h,t.traveled+=n,a?.(o,h,p,t.velocity,f),(f>.62||m)&&r({point:h,flow:c(t.velocity,.42),amount:e*s.smokePerSecond*s.flowRate*(m?.42:.18),radiusM:Math.max(.11,p*.48)}),m?a?.(h,h,p*1.35,t.velocity,f):t.traveled+1e-6<t.range&&u.push(t)}this.jets=u}get open(){return this.phase===`closed`?0:this.phase===`opening`?u(this.phaseTime/jn,0,1):this.phase===`closing`?1-u(this.phaseTime/Mn,0,1):1}drawMount(e,t,n,r,i,a=1,o){v(e,t,n,r,i,this.open,`flame`,this.phase===`active`?.8:0,a,o)}},Pn=class{rocket=new Dn;machineGuns=new An;flamethrower=new Nn;lightning=new g;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}},$=e=>({...e,slots:e.slots?[...e.slots]:void 0,slotPresses:e.slotPresses?[...e.slotPresses]:void 0}),Fn=mn({types:{events:{}}}).createMachine({id:`vehicleLifecycle`,initial:`drivable`,states:{drivable:{on:{DESTROYED:`destroyed`}},destroyed:{on:{RESPAWNED:`drivable`}}}}),In=class{id;sim;damage=new gn;weapons=new Pn;tirePaint=new En;pickupEffect=new _n;lifecycle=A(Fn).start();controls={throttle:0,steer:0,action:!1};controlSource=`player`;label=``;appearance=`auto`;slotConfiguration=S;toolPolicy={};numberedSlots=re(S);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=re(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})).filter(e=>e.amount>0)}useSlot(e){let t=x(e);return this.disposed||!this.numberedSlots[t-1]||this.lifecycleState!==`drivable`?!1:(this.slotPulses.add(t),!0)}startSlot(e){let t=x(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(x(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(x)),n=new Set((e.slotPresses??[]).map(x));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=$(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}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}setControls(e,t,n={}){if(n.toolsEnabled!==this.toolPolicy.toolsEnabled){let t=re(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(x(t))}this.toolPolicy=n,this.numberedSlots=t}this.controls=ne(this.resolveSlots(e),n.toolsEnabled),this.controlSource=t}step(e,t,n=!1){this.pickupEffect.step(e),n?this.sim.lastInput={throttle:0,steer:0,action:!1,boost:!1}:this.sim.tick(this.lifecycleState===`drivable`?this.controls:{throttle:0,steer:0,action:!1},e,t),this.weapons.lightning.step(e,!n&&!!this.sim.lastInput.lightning&&this.lifecycleState===`drivable`,b(this.sim.car.preset).chargeSeconds),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.tirePaint.reset(),this.pickupEffect.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.tirePaint.reset(),this.pickupEffect.reset(),this.synchronizeLifecycle()}setPreset(e){this.clearSlotInput(),this.sim.setPreset(e),this.damage.reset(),this.weapons.reset(),this.tirePaint.reset(),this.pickupEffect.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>=o.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(),tirePaint:this.tirePaint.captureState(),pickupEffect:this.pickupEffect.captureState(),controls:$(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.tirePaint.restoreState(e.tirePaint),this.pickupEffect.restoreState(e.pickupEffect),this.controls=$(e.controls),this.controlSource=e.controlSource,this.lifecycle.stop(),this.lifecycle=A(Fn,{snapshot:e.lifecycle}).start()}dispose(){this.disposed=!0,this.pickupEffect.reset(),this.clearSlotInput(),this.lifecycle.stop()}};export{gn as n,In as t};
|
|
1
|
+
import{a as e,n as t,r as n}from"./configuration~react~vehicle-popover~JoyRideView~browser-session-core~renderer-B70Mpi9X.js";import{a as r,r as i}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core~renderer-Dt96jol6.js";import{r as a}from"./definitions~react~vehicle-popover~browser-session-core~renderer-RDNEXk_b.js";import{S as o,c as s,d as c,f as l,i as u,l as d,o as f,s as p,u as m}from"./runtime~react~vehicle-popover~browser-session-core~renderer-Be8cIaU4.js";import{_ as h,b as g,g as _,h as v,v as y,x as b,y as ee}from"./runtime~vehicle-popover~browser-session-core~renderer-jVG7K050.js";import{n as te,r as x,t as S}from"./definitions~react~vehicle-popover~Documentation~JoyRideView~browser-session-core-BZJqthWX.js";import{n as ne,r as re}from"./vehicle-catalog~react~vehicle-popover~browser-session-core-CX066OIY.js";function ie(){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 ae(){let e=ie();if(e.__xstate__)return e.__xstate__}var oe=e=>{if(typeof window>`u`)return;let t=ae();t&&t.register(e)},se=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}},ce=``,le=`#`,ue=`*`,de=`xstate.init`,fe=`xstate.stop`;function pe(e,t){return{type:`xstate.after.${e}.${t}`}}function me(e,t){return{type:`xstate.done.state.${e}`,output:t}}function he(e,t){return{type:`xstate.done.actor.${e}`,output:t,actorId:e}}function ge(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function _e(e){return{type:de,input:e}}function C(e){setTimeout(()=>{throw e})}var ve=typeof Symbol==`function`&&Symbol.observable||`@@observable`;function ye(e,t){let n=xe(e),r=xe(t);return typeof r==`string`?typeof n==`string`&&r===n:typeof n==`string`?n in r:Object.keys(n).every(e=>e in r&&ye(n[e],r[e]))}function be(e){if(Ee(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 xe(e){return Nt(e)?e.value:typeof e==`string`?Se(be(e)):e}function Se(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 Ce(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 we(e){return Ee(e)?e:[e]}function w(e){return e===void 0?[]:we(e)}function Te(e,t,n,r){return typeof e==`function`?e({context:t,event:n,self:r}):e}function Ee(e){return Array.isArray(e)}function De(e){return e.type.startsWith(`xstate.error.actor`)}function T(e){return we(e).map(e=>e===void 0||typeof e==`string`?{target:e}:e)}function Oe(e){if(e!==void 0&&e!==ce)return w(e)}function E(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 ke(e,t){return`${t}.${e}`}function D(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 Ae(e,t){if(t===e||t===ue)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 je(e,t){return`${e.sessionId}.${t}`}var Me=0;function Ne(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=je(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=je(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:${Me++}`,_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=E(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 O=!1,k=function(e){return e[e.NotStarted=0]=`NotStarted`,e[e.Running=1]=`Running`,e[e.Stopped=2]=`Stopped`,e}({}),Pe={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1},Fe=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 se(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=k.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={...Pe,...t},{clock:r,logger:i,parent:a,syncSnapshot:o,id:s,systemId:c,inspect:l}=n;this.system=a?a.system:Ne(this,{clock:r,logger:i}),l&&!a&&this.system.inspect(E(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){C(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=O;try{O=!0,e.exec(e.info,e.params)}finally{O=t}};this._processingStatus===k.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){C(e)}break;case`done`:for(let t of this.observers)try{t.next?.(e)}catch(e){C(e)}this._stopProcedure(),this._complete(),this._doneEvent=he(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=E(e,t,n);if(this._processingStatus!==k.Stopped)this.observers.add(r);else switch(this._snapshot.status){case`done`:try{r.complete?.()}catch(e){C(e)}break;case`error`:{let e=this._snapshot.error;if(!r.error)C(e);else try{r.error(e)}catch(e){C(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=E(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===k.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=k.Running;let e=_e(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===k.Stopped?this:(this.mailbox.clear(),this._processingStatus===k.NotStarted?(this._processingStatus=k.Stopped,this):(this.mailbox.enqueue({type:fe}),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){C(e)}this.observers.clear(),this.eventListeners.clear()}_reportError(e){if(!this.observers.size){this._parent||C(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){C(e)}}this.observers.clear(),this.eventListeners.clear(),t&&C(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,ge(this.id,e))}_stopProcedure(){return this._processingStatus===k.Running&&(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new se(this._process.bind(this)),this._processingStatus=k.Stopped,this.system._unregister(this)),this}_send(e){this._processingStatus!==k.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:oe)(this)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[ve](){return this}getSnapshot(){return this._snapshot}};function A(e,...[t]){return new Fe(e,t)}function Ie(e,t,n,r,{sendId:i}){return[t,{sendId:typeof i==`function`?i(n,r):i},void 0]}function Le(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t.sendId)})}function Re(e){function t(e,t){}return t.type=`xstate.cancel`,t.sendId=e,t.resolve=Ie,t.execute=Le,t}function ze(e,t,n,r,{id:i,systemId:a,src:o,input:s,syncSnapshot:c}){let l=typeof o==`string`?D(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=A(l,{id:u,src:o,parent:e.self,syncSnapshot:c,systemId:a,input:f})),[q(t,{children:{...t.children,[u]:d}}),{id:i,systemId:a,actorRef:d,src:o,input:f},void 0]}function Be(e,{actorRef:t}){t&&e.defer(()=>{t._processingStatus!==k.Stopped&&t.start()})}function Ve(...[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=ze,a.execute=Be,a}function He(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]),[q(t,{children:s}),o,void 0]}function Ue(e,t){let n=t.getSnapshot();if(n&&`children`in n)for(let t of Object.values(n.children))Ue(e,t);e.system._unregister(t)}function We(e,t){t&&(Ue(e,t),t._processingStatus===k.Running?e.defer(()=>{e.stopChild(t)}):e.stopChild(t))}function j(e){function t(e,t){}return t.type=`xstate.stopChild`,t.actorRef=e,t.resolve=He,t.execute=We,t}function Ge(e,{context:t,event:n},{guards:r}){return r.every(r=>M(r,t,n,e))}function Ke(e){function t(e,t){return!1}return t.check=Ge,t.guards=e,t}function M(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 M(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 qe(e){return e.type===`atomic`||e.type===`final`}function N(e){return Object.values(e.states).filter(e=>e.type!==`history`)}function P(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 F(e){let t=new Set(e),n=Ye(t);for(let e of t)if(e.type===`compound`&&(!n.get(e)||!n.get(e).length))at(e).forEach(e=>t.add(e));else if(e.type===`parallel`){for(let n of N(e))if(n.type!==`history`&&!t.has(n)){let e=at(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 Je(e,t){let n=t.get(e);if(!n)return{};if(e.type===`compound`){let e=n[0];if(e){if(qe(e))return e.key}else return{}}let r={};for(let e of n)r[e.key]=Je(e,t);return r}function Ye(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 Xe(e,t){return Je(e,Ye(F(t)))}function Ze(e,t){return t.type===`compound`?N(t).some(t=>t.type===`final`&&e.has(t)):t.type===`parallel`?N(t).every(t=>Ze(e,t)):t.type===`final`}var I=e=>e[0]===le;function Qe(e,t){let n=e.transitions.get(t),r=[...e.transitions.keys()].filter(e=>e!==t&&Ae(t,e)).sort((e,t)=>t.length-e.length).flatMap(t=>e.transitions.get(t));return n?[...n,...r]:r}function $e(e){let t=e.config.after;if(!t)return[];let n=t=>{let n=pe(t,e.id),r=n.type;return e.entry.push(Wt(n,{id:r,delay:t})),e.exit.push(Re(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 w(i).map(e=>({...e,event:o,delay:a}))}).map(t=>{let{delay:n}=t;return{...L(e,t.event,t),delay:n}})}function L(e,t,n){let r=Oe(n.target),i=n.reenter??!1,a=rt(e,r),o={...n,actions:w(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 et(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,T(r).map(t=>L(e,n,t)))}if(e.config.onDone){let n=`xstate.done.state.${e.id}`;t.set(n,T(e.config.onDone).map(t=>L(e,n,t)))}for(let n of e.invoke){if(n.onDone){let r=`xstate.done.actor.${n.id}`;t.set(r,T(n.onDone).map(t=>L(e,r,t)))}if(n.onError){let r=`xstate.error.actor.${n.id}`;t.set(r,T(n.onError).map(t=>L(e,r,t)))}if(n.onSnapshot){let r=`xstate.snapshot.${n.id}`;t.set(r,T(n.onSnapshot).map(t=>L(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 tt(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?Ke([a,i]):a,target:`#${n}`};t.push(L(e,`xstate.route`,o))}r.states&&n(r.states)})};n(e.states),t.length>0&&e.transitions.set(`xstate.route`,t)}function nt(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`?[]:w(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 rt(e,t){if(t!==void 0)return t.map(t=>{if(typeof t!=`string`)return t;if(I(t))return e.machine.getStateNodeById(t);let n=t[0]===`.`;if(n&&!e.parent)return B(e,t.slice(1));let r=n?e.key+t:t;if(e.parent)try{return B(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 it(e){let t=Oe(e.config.target);return t?{target:t.map(t=>typeof t==`string`?B(e.parent,t):t)}:e.parent.type===`parallel`?{target:[e.parent]}:e.parent.initial}function R(e){return e.type===`history`}function at(e){let t=ot(e);for(let n of t)for(let r of P(n,e))t.add(r);return t}function ot(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 N(e))n(t)}}return n(e),t}function z(e,t){if(I(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 B(e,t){if(typeof t==`string`&&I(t))try{return e.machine.getStateNodeById(t)}catch{}let n=be(t).slice(),r=e;for(;n.length;){let e=n.shift();if(!e.length)break;r=z(r,e)}return r}function V(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=>z(e,t)).filter(Boolean);return[e.machine.root,e].concat(r,n.reduce((n,r)=>{let i=z(e,r);if(!i)return n;let a=V(i,t[r]);return n.concat(a)},[]))}function st(e,t,n,r){let i=z(e,t).next(n,r);return!i||!i.length?e.next(n,r):i}function ct(e,t,n,r){let i=Object.keys(t),a=ut(z(e,i[0]),t[i[0]],n,r);return!a||!a.length?e.next(n,r):a}function lt(e,t,n,r){let i=[];for(let a of Object.keys(t)){let o=t[a];if(!o)continue;let s=ut(z(e,a),o,n,r);s&&i.push(...s)}return i.length?i:e.next(n,r)}function ut(e,t,n,r){return typeof t==`string`?st(e,t,n,r):Object.keys(t).length===1?ct(e,t,n,r):lt(e,t,n,r)}function dt(e){return Object.keys(e.states).map(t=>e.states[t]).filter(e=>e.type===`history`)}function H(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function ft(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 pt(e,t,n){let r=new Set;for(let i of e){let e=!1,a=new Set;for(let o of r)if(ft(_t([i],t,n),_t([o],t,n))){if(H(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 mt(e){let[t,...n]=e;for(let e of P(t,void 0))if(n.every(t=>H(t,e)))return e}function ht(e,t){if(!e.target)return[];let n=new Set;for(let r of e.target)if(R(r)){if(t[r.id])for(let e of t[r.id])n.add(e);else for(let e of ht(it(r),t))n.add(e)}else n.add(r);return[...n]}function gt(e,t){let n=ht(e,t);if(!n)return;if(!e.reenter&&n.every(t=>t===e.source||H(t,e.source)))return e.source;let r=mt(n.concat(e.source));if(r)return r;if(!e.reenter)return e.source.machine.root}function _t(e,t,n){let r=new Set;for(let i of e)if(i.target?.length){let e=gt(i,n);i.reenter&&i.source===e&&r.add(e);for(let n of t)H(n,e)&&r.add(n)}return[...r]}function vt(e,t){if(e.length!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function yt(e,t,n,r,i){return U([{target:[...ot(e)],source:e,reenter:!0,actions:[],eventType:null,toJSON:null}],t,n,r,!0,i)}function U(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=pt(e,s,c),u=t;i||([u,c]=Tt(u,r,n,l,s,c,a,n.actionExecutor)),u=G(u,r,n,l.flatMap(e=>e.actions),a,void 0),u=xt(u,r,n,l,s,a,c,i);let d=[...s];u.status===`done`&&(u=G(u,r,n,d.sort((e,t)=>t.order-e.order).flatMap(e=>e.exit),a,void 0));try{return c===t.historyValue&&vt(t._nodes,s)?[u,o]:[q(u,{_nodes:d,historyValue:c}),o]}catch(e){throw e}}finally{n.actionExecutor=s}}function bt(e,t,n,r,i){if(r.output===void 0)return;let a=me(i.id,i.output!==void 0&&i.parent?Te(i.output,e.context,t,n.self):void 0);return Te(r.output,e.context,a,n.self)}function xt(e,t,n,r,i,a,o,s){let c=e,l=new Set,u=new Set;St(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(Ve(t.src,{...t,syncSnapshot:!!t.onSnapshot}));if(u.has(e)){let t=e.initial.actions;r.push(...t)}if(c=G(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(me(r.id,e.output===void 0?void 0:Te(e.output,c.context,t,n.self)));o?.type===`parallel`&&!d.has(o)&&Ze(i,o);)d.add(o),a.push(me(o.id)),s=o,o=o.parent;if(o)continue;c=q(c,{status:`done`,output:bt(c,t,n,c.machine.root,s)})}}return c}function St(e,t,n,r){for(let i of e){let e=gt(i,t);for(let a of i.target||[])!R(a)&&(i.source!==a||i.source!==e||i.reenter)&&(r.add(a),n.add(a)),W(a,t,n,r);let a=ht(i,t);for(let o of a){let a=P(o,e);e?.type===`parallel`&&a.push(e),Ct(r,t,n,a,!i.source.parent&&i.reenter?void 0:e)}}}function W(e,t,n,r){if(R(e)){if(t[e.id]){let i=t[e.id];for(let e of i)r.add(e),W(e,t,n,r);for(let a of i)wt(a,e.parent,r,t,n)}else{let i=it(e);for(let a of i.target)r.add(a),i===e.parent?.initial&&n.add(e.parent),W(a,t,n,r);for(let a of i.target)wt(a,e.parent,r,t,n)}}else if(e.type===`compound`){let[i]=e.initial.target;R(i)||(r.add(i),n.add(i)),W(i,t,n,r),wt(i,e,r,t,n)}else if(e.type===`parallel`)for(let i of N(e).filter(e=>!R(e)))[...r].some(e=>H(e,i))||(R(i)||(r.add(i),n.add(i)),W(i,t,n,r))}function Ct(e,t,n,r,i){for(let a of r)if((!i||H(a,i))&&e.add(a),a.type===`parallel`)for(let r of N(a).filter(e=>!R(e)))[...e].some(e=>H(e,r))||(e.add(r),W(r,t,n,e))}function wt(e,t,n,r,i){Ct(n,r,i,P(e,t))}function Tt(e,t,n,r,i,a,o,s){let c=e,l=_t(r,i,a);l.sort((e,t)=>t.order-e.order);let u;for(let e of l)for(let t of dt(e)){let n;n=t.history===`deep`?t=>qe(t)&&H(t,e):t=>t.parent===e,u??={...a},u[t.id]=Array.from(i).filter(n)}for(let e of l)c=G(c,t,n,[...e.exit,...e.invoke.map(e=>j(e.id))],o,void 0),i.delete(e);return[c,u||a]}function Et(e,t){return e.implementations.actions[t]}function Dt(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:Et(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=Dt(s,t,n,m,i,a))}return s}function G(e,t,n,r,i,a){let o=a?[]:void 0,s=Dt(e,t,n,r,{internalQueue:i,deferredActorIds:a},o);return o?.forEach(([e,t])=>{e.retryResolve(n,s,t)}),s}function Ot(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=q(kt(i,t,n),{status:`stopped`}),o([i,[]],t,[]),{snapshot:i,microsteps:a};let s=t;if(s.type!==de){let t=s,c=De(t),l=At(t,i);if(c&&!l.length)return i=q(kt(i,t,n),{status:`error`,error:t.error}),o([i,[]],t,[]),{snapshot:i,microsteps:a};let u=U(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?jt(i,s):[],t=e.length?i:void 0;if(!e.length){if(!r.length)break;s=r.shift(),e=At(s,i)}let a=U(e,i,n,s,!1,r);i=a[0],c=i!==t,o(a,s,e)}return i.status!==`active`&&kt(i,s,n),{snapshot:i,microsteps:a}}function kt(e,t,n){return G(e,t,n,Object.values(e.children).map(e=>j(e)),[],void 0)}function At(e,t){return t.machine.getTransitionData(t,e)}function jt(e,t){let n=new Set,r=e._nodes.filter(qe);for(let i of r)loop:for(let r of[i].concat(P(i,void 0)))if(r.always){for(let i of r.always)if(i.guard===void 0||M(i.guard,e.context,t,e)){n.add(i);break loop}}return pt(Array.from(n),new Set(e._nodes),e.historyValue)}function Mt(e,t){return Xe(e,[...F(V(e,t))])}function Nt(e){return!!e&&typeof e==`object`&&`machine`in e&&`value`in e}var Pt=function(e){return ye(e,this.value)},Ft=function(e){return this.tags.has(e)},It=function(e){let t=this.machine.getTransitionData(this,e);return!!t?.length&&t.some(e=>e.target!==void 0||e.actions.length)},Lt=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)}},Rt=function(){return this._nodes.reduce((e,t)=>(t.meta!==void 0&&(e[t.id]=t.meta),e),{})};function K(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:Xe(t.root,e._nodes),tags:new Set(e._nodes.flatMap(e=>e.tags)),children:e.children,historyValue:e.historyValue||{},matches:Pt,hasTag:Ft,can:It,getMeta:Rt,toJSON:Lt}}function q(e,t={}){return K({...e,...t},e.machine)}function zt(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 Bt(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:Vt(o),children:p,historyValue:zt(f.historyValue)}}function Vt(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=Vt(r);i!==r&&(t??=Array.isArray(e)?e.slice():{...e},t[n]=i)}}}return t??e}function Ht(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 Ut(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 Wt(e,t){function n(e,t){}return n.type=`xstate.raise`,n.event=e,n.id=t?.id,n.delay=t?.delay,n.resolve=Ht,n.execute=Ut,n}function Gt(e,{machine:t,context:n},r,i){let a=(a,o)=>{if(typeof a==`string`){let s=D(t,a);if(!s)throw Error(`Actor logic '${a}' not implemented in machine '${t.id}'`);let c=A(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 A(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!==k.Stopped&&r.start()}),r}}function Kt(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:Gt(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[q(t,{context:Object.assign({},t.context,s),children:Object.keys(a).length?{...t.children,...a}:t.children}),void 0,void 0]}function qt(e){function t(e,t){}return t.type=`xstate.assign`,t.assignment=e,t.resolve=Kt,t}var Jt=new WeakMap;function J(e,t,n){let r=Jt.get(e);return r?t in r||(r[t]=n()):(r={[t]:n()},Jt.set(e,r)),r[t]}var Yt={},Y=e=>typeof e==`string`?{type:e}:typeof e==`function`?`resolve`in e?{type:e.type}:{type:e.name}:e,Xt=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?Ce(this.config.states,(t,n)=>new e(t,{_parent:this,_key:n,_machine:this.machine})):Yt,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=w(this.config.entry).slice(),this.exit=w(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type===`final`||!this.parent?this.config.output:void 0,this.tags=w(t.tags).slice()}_initialize(){this.transitions=et(this),this.config.always&&(this.always=T(this.config.always).map(e=>L(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(Y),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(Y),eventType:null,meta:this.initial.meta,description:this.initial.description})}:void 0,history:this.history,states:Ce(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(Y)})),entry:this.entry.map(Y),exit:this.exit.map(Y),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 J(this,`invoke`,()=>w(this.config.invoke).map((e,t)=>{let{src:n,systemId:r}=e,i=e.id??ke(this.id,t),a=typeof n==`string`?n:`xstate.invoke.${ke(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 J(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 J(this,`delayedTransitions`,()=>$e(this))}get initial(){return J(this,`initial`,()=>nt(this,this.config.initial))}next(e,t){let n=t.type,r=[],i,a=J(this,`candidates-${n}`,()=>Qe(this,n));for(let o of a){let{guard:a}=o,s=e.context,c=!1;try{c=!a||M(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 J(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)}},Zt=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 Xt(e,{_key:this.id,_machine:this}),this.root._initialize(),tt(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=Mt(this.root,e.value),n=F(V(this.root,t));return K({_nodes:[...n],context:e.context||{},children:{},status:Ze(n,this.root)?`done`:e.status||`active`,output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,t,n){return Ot(e,t,n,[]).snapshot}microstep(e,t,n){return Ot(e,t,n,[]).microsteps.map(([e])=>e)}getTransitionData(e,t){return ut(this.root,e.value,e,t)||[]}_getPreInitialState(e,t,n){let{context:r}=this.config,i=K({context:typeof r!=`function`&&r?r:{},_nodes:[this.root],children:{},status:`active`},this);return typeof r==`function`?G(i,t,e,[qt(({spawn:e,event:t,self:n})=>r({spawn:e,input:t.input,self:n}))],n,void 0):i}getInitialSnapshot(e,t){let n=_e(t),r=[],i=K({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]=yt(this.root,i,e,n,r),{snapshot:a}=Ot(t,n,e,r);return a}catch(e){return q(i,{status:`error`,error:e})}}start(e){Object.values(e.children).forEach(e=>{e.getSnapshot().status===`active`&&e.start()})}getStateNodeById(e){let t=be(e),n=t.slice(1),r=I(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 B(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,t){return Bt(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`?D(this,o):o;if(!s)return;let c=A(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 Xt)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=K({...e,children:n,_nodes:Array.from(F(V(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 Qt(e,t,n,r,{event:i}){return[t,{event:typeof i==`function`?i(n,r):i},void 0]}function $t(e,{event:t}){e.defer(()=>e.emit(t))}function en(e){function t(e,t){}return t.type=`xstate.emit`,t.event=e,t.resolve=Qt,t.execute=$t,t}var tn=function(e){return e.Parent=`#_parent`,e.Internal=`#_internal`,e}({});function nn(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===tn.Parent?e.self._parent:f===tn.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 rn(e,t,n){typeof n.to==`string`&&(n.to=t.children[n.to])}function an(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`?ge(e.self.id,r.data):r)})}function on(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=nn,r.retryResolve=rn,r.execute=an,r}function sn(e,t){return on(tn.Parent,e,t)}function cn(e,t,n,r,{collect:i}){let a=[],o=function(e){a.push(e)};return o.assign=(...e)=>{a.push(qt(...e))},o.cancel=(...e)=>{a.push(Re(...e))},o.raise=(...e)=>{a.push(Wt(...e))},o.sendTo=(...e)=>{a.push(on(...e))},o.sendParent=(...e)=>{a.push(sn(...e))},o.spawnChild=(...e)=>{a.push(Ve(...e))},o.stopChild=(...e)=>{a.push(j(...e))},o.emit=(...e)=>{a.push(en(...e))},i({context:n.context,event:n.event,enqueue:o,check:e=>M(e,t.context,n.event,t),self:e.self,system:e.system},r),[t,void 0,a]}function ln(e){function t(e,t){}return t.type=`xstate.enqueueActions`,t.collect=e,t.resolve=cn,t}function un(e,t,n,r,{value:i,label:a}){return[t,{value:typeof i==`function`?i(n,r):i,label:a},void 0]}function dn({logger:e},{value:t,label:n}){n?e(n,t):e(t)}function fn(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=un,n.execute=dn,n}function pn(e,t){return new Zt(e,t)}function mn({schemas:e,actors:t,actions:n,guards:r,delays:i}){return{assign:qt,sendTo:on,raise:Wt,log:fn,cancel:Re,stopChild:j,enqueueActions:ln,emit:en,spawnChild:Ve,createStateConfig:e=>e,createAction:e=>e,createMachine:a=>pn({...a,schemas:e},{actors:t,actions:n,guards:r,delays:i}),extend:a=>mn({schemas:e,actors:t,actions:{...n,...a.actions},guards:{...r,...a.guards},delays:{...i,...a.delays}})}}var hn=(e,t,n)=>Math.max(t,Math.min(n,e)),gn=class{dents=[];revision=0;enabled=!1;maxDepthM=0;maskCache=new WeakMap;spriteCache=null;captureState(){return a({dents:this.dents,revision:this.revision,enabled:this.enabled,maxDepthM:this.maxDepthM})}restoreState(e){let t=a(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=s(e,n.center),u=l(f(o,n.forward)/a,f(o,n.side)/a),d=l(f(t,n.forward),f(t,n.side)),m=p(d);if(m<.001)return!1;let h=hn((r-2.5)/17.5,0,1)**1.5;return this.maxDepthM=Math.min(.25,8/a),this.dents.push({center:u,inward:c(d,1/m),depthM:this.maxDepthM*h,radiusAlongM:.65+h*.5,radiusAcrossM:.55+h*.55}),this.dents.length>12&&this.dents.shift(),this.revision++,this.spriteCache=null,!0}point(e){if(!this.hasDamage)return e;let t=l();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=d(t,c(n.inward,n.depthM*o))}let n=p(t);return n>this.maxDepthM&&(t=c(t,this.maxDepthM/n)),d(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,c=e.widthM/r;for(let t=0;t<r;t++)for(let u=0;u<n;u++){let f=l((u+.5)*o-e.lengthM/2,(t+.5)*c-e.widthM/2),p=f;for(let e=0;e<5;e++)p=d(p,s(f,this.point(p)));let m=Math.floor((p.x/e.lengthM+.5)*n),h=Math.floor((p.y/e.widthM+.5)*r);m>=0&&m<n&&h>=0&&h<r&&(a[t*n+u]=i[h*n+m])}let u={...e,alpha:{columns:n,rows:r,solid:a}};return this.maskCache.set(e,{revision:this.revision,value:u}),u}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=l((e.x/r.width-.5)*t.lengthM,(e.y/r.height-.5)*t.widthM),i=this.point(n);return l((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,u=n*r.height/10,d=(n+1)*r.height/10,f=l(s,u),p=l(c,u),m=l(s,d),h=l(c,d);this.drawTriangle(i,e,t,[f,p,m],[a(f),a(p),a(m)]),this.drawTriangle(i,e,t,[h,m,p],[a(h),a(m),a(p)])}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,ee=(_*m-y*f)/h,te=(v*d-g*p)/h,x=(y*d-_*p)/h,S=c.x-b*a.x-te*a.y,ne=c.y-ee*a.x-x*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,ee,te,x,S,ne),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()}},_n=class{random;pulses=[];constructor(e=Math.random){this.random=e}get active(){return this.pulses}trigger({color:e,angle:t,velocity:n,origin:r}){if(!Number.isFinite(t)||!Number.isFinite(n))throw RangeError(`Pickup angle and velocity must be finite`);if(r&&(!Number.isFinite(r.x)||!Number.isFinite(r.y)||Math.abs(r.x)>.5||Math.abs(r.y)>.5))throw RangeError(`Pickup origin must lie within normalized body coordinates [-0.5, 0.5]`);let a=i(e),o=Math.min(1,Math.abs(n)/32);this.pulses.push({color:[a[0]/255,a[1]/255,a[2]/255],angle:Math.atan2(Math.sin(t),Math.cos(t)),strength:o,velocity:Math.abs(n),origin:r?{...r}:null,variation:this.random(),age:0,duration:.38-o*.1}),this.pulses.length>3&&this.pulses.shift()}step(e){if(!(!this.pulses.length||!Number.isFinite(e)||e<=0)){for(let t of this.pulses)t.age+=e;this.pulses=this.pulses.filter(e=>e.age<e.duration)}}reset(){this.pulses=[]}captureState(){return structuredClone(this.pulses)}restoreState(e){this.pulses=structuredClone(e)}},vn=new Map,X=null;function yn(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?[u(+n[1],0,255),u(+n[2],0,255),u(+n[3],0,255)]:null}function bn(e){let t=yn(e);if(t)return t;if(vn.has(e))return vn.get(e);let n=null;return typeof document<`u`&&(X??=document.createElement(`canvas`).getContext(`2d`),X&&(X.fillStyle=`#010203`,X.fillStyle=e,X.fillStyle!==`#010203`&&(n=yn(X.fillStyle)))),vn.set(e,n),n}var xn=[[0,0],[60,120],[120,180],[240,240],[300,300],[360,360]];function Sn(e,t=!1){let n=(e%360+360)%360;for(let e=1;e<xn.length;e++){let[r,i]=xn[e-1],[a,o]=xn[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 Cn([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 wn(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 Tn(e){let t=e.filter(e=>e.strength>0&&bn(e.color));if(!t.length)return e.at(-1)?.color??`rgb(0 0 0)`;if(t.length===1)return`rgb(${bn(t[0].color).join(` `)})`;let n=0,r=0,i=0,a=0,o=0;for(let e of t){let t=Cn(bn(e.color)),s=Sn(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 wn(Sn((Math.atan2(r,n)*180/Math.PI+360)%360,!0),Math.min(1,a/o),i/o)}var En=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 a({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=a(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,u(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,i,a,o,s){let c=this.coating(e);if(!c||a<=0||s<=0)return;let l=r.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 ee(t,n,i,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 c=this.coating(e);if(!c){this.pauseTrack(e);return}let l=this.previous.get(e),d=this.wetPaths.get(e);if(!d||!l||p(s(t,l))>=1.5*i)d={marks:[],distanceM:0},this.wetPaths.set(e,d),o&&(this.marks.push({...c,from:{...t},point:{...t},angle:n,widthM:r,phaseM:this.travelM.get(e)??0,slip:u(a,0,1),overPuddle:!0}),this.markCount++);else{let f=d.marks.at(-1),m=f&&p(s(f.point,f.from))/i<.02,h=m?f.from:l;m&&(d.distanceM-=p(s(f.point,f.from))/i);let g=p(s(t,h))/i,_={...c,from:{...h},point:{...t},angle:n,widthM:r,phaseM:(this.travelM.get(e)??0)-g,slip:u(a,0,1)};m?d.marks[d.marks.length-1]=_:d.marks.push(_),d.distanceM+=g,o&&g>=.02&&(this.marks.push({..._,overPuddle:!0}),this.markCount++,this.marks.length>3e4&&this.marks.splice(0,1e3));let v=Math.max(.5,r*6);for(;d.marks.length>1&&(d.distanceM>v||d.marks.length>128);){let e=d.marks.shift();d.distanceM-=p(s(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 c=this.coating(e);if(!c)return;let l=this.previous.get(e),d=l?p(s(t,l)):0,f=this.wetPaths.has(e)||this.exits.has(e)?.01:.05;if(l&&d<f*i)return;let m=l&&d<1.5*i,h=this.wetPaths.get(e);if(h&&m){let t=Math.max(.35,r*(2+4*(c.material?.film??.6))),n=-h.distanceM;for(let e of h.marks){let r=n+p(s(e.point,e.from))/i;this.marks.push({...e,overPuddle:!1,exit:{fromM:n,toM:r,lengthM:t,leadInM:h.distanceM}}),this.markCount++,n=r}this.exits.set(e,{distanceM:0,lengthM:t})}else m||this.exits.delete(e);this.wetPaths.delete(e);let g=this.exits.get(e),_=g&&g.distanceM<g.lengthM?{fromM:g.distanceM,toM:g.distanceM+d/i,lengthM:g.lengthM}:void 0;g&&(g.distanceM+=d/i,g.distanceM>=g.lengthM&&this.exits.delete(e)),this.marks.push({from:m?{...l}:{...t},point:{...t},angle:n,widthM:r,phaseM:(this.travelM.get(e)??0)-(m?p(s(t,l))/i:0),wetness:c.wetness,material:c.material,slip:u(o,0,1),color:c.color,opacity:c.opacity,overPuddle:a,exit:_}),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*u(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=u(r.remaining/r.distanceM,0,1);return{material:r.material,wetness:i,color:Tn(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))}}},Z={opening:.32,raising:.52,igniting:.48,closing:.36},Dn=class{previewOpen=!1;inspecting=!1;phase=`idle`;elapsed=0;held=!1;presetId=null;flights=[];launchClock=0;queuedShots=0;launches=0;ignitionDuration=Z.igniting;captureState(){return a({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=a(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=Z.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(t,n,r,i,a,o,s,p){if(n.mode!==`car`){this.reset();return}if(this.presetId&&this.presetId!==n.car.preset.id&&this.reset(),this.previewOpen){this.inspecting=!0,this.presetId=n.car.preset.id,(this.phase===`idle`||this.phase===`closing`)&&this.transition(`opening`),this.elapsed+=t,this.phase===`opening`&&this.elapsed>=Z.opening&&this.transition(`raising`),this.phase===`raising`&&(this.elapsed=Math.min(this.elapsed,Z.raising));return}this.inspecting&&(this.inspecting=!1,this.transition(`closing`));let h=!!n.lastInput.rocket;h&&!this.held&&(this.queuedShots++,(this.phase===`idle`||this.phase===`closing`)&&(this.presetId=n.car.preset.id,this.transition(`opening`))),this.held=h;let g=e(n.car.preset);if(this.phase===`idle`&&!this.flights.length)return;this.elapsed+=t,this.launchClock+=t;let _=n.car.preset.roofRocket,v=Math.max(1.05,_.sizeM*1.12);if(this.phase===`opening`&&this.elapsed>=Z.opening)this.transition(`raising`);else if(this.phase===`raising`&&this.elapsed>=Z.raising)this.ignitionDuration=Z.igniting,this.transition(`igniting`),p?.(n.body.world(l(_.xM,_.yM)));else if(this.phase===`igniting`&&this.elapsed>=this.ignitionDuration){let e=m(l(1,0),n.body.angle),t=n.body.world(l(_.xM,_.yM));this.flights.push({position:t,angle:n.body.angle,speedMps:g.launchSpeedMps+Math.max(0,f(n.body.velocity,e)),distanceM:0,age:0}),this.launches++,o?.(t),this.queuedShots=Math.max(0,this.queuedShots-1),this.launchClock=0,this.transition(`flying`)}else this.phase===`closing`&&this.elapsed>=Z.closing&&this.transition(`idle`);if(this.phase===`igniting`){let e=u(this.elapsed/Math.min(.27,this.ignitionDuration*.65),0,.9),i=m(l(-1,0),n.body.angle),o=n.body.world(l(_.xM-v*.52,_.yM));r({point:o,flow:c(i,3.5),amount:t*14*e,radiusM:.2}),a?.({from:o,to:o,flow:c(i,12),widthM:.16,intensity:e*.75})}this.phase===`flying`&&(!h&&this.queuedShots===0?this.transition(`closing`):this.launchClock>=Math.max(0,1/g.roundsPerSecond-Math.min(Z.igniting,.7/g.roundsPerSecond))&&(this.ignitionDuration=Math.min(Z.igniting,.7/g.roundsPerSecond),this.transition(`igniting`),p?.(n.body.world(l(_.xM,_.yM)))));for(let e=this.flights.length-1;e>=0;e--){let n=this.flights[e],o=m(l(1,0),n.angle);n.speedMps=Math.min(g.maxSpeedMps,n.speedMps+g.accelerationMps2*t);let u=n.speedMps*t,f=n.position,p=d(f,c(o,u)),h=i?.(f,p,_.sizeM*.18);n.position=h??p,n.distanceM+=u,n.age+=t;let y=d(n.position,c(o,-v*.53)),b=d(f,c(o,-v*.53));if(r({point:y,flow:c(o,-5),amount:t*g.smokePerSecond,radiusM:.2}),a?.({from:b,to:y,flow:c(o,-18),widthM:.13,intensity:.9}),h){s?.(h);for(let e=0;e<7;e++){let t=m(l(1,0),e*Math.PI*2/7);r({point:h,flow:c(t,5.5),amount:.18,radiusM:.22})}this.flights.splice(e,1)}else(n.age>=g.lifetimeSeconds||n.distanceM>100)&&this.flights.splice(e,1)}this.phase===`closing`&&this.elapsed>=Z.closing&&this.transition(`idle`)}get open(){return this.phase===`idle`?0:this.phase===`opening`?u(this.elapsed/Z.opening,0,1):this.phase===`closing`?1-u(this.elapsed/Z.closing,0,1):1}drawMount(e,t,n,r,i,a=1,o){let s=this.open;if(s<=0)return;y();let c=r.roofRocket,l=c.sizeM*i,d=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 f=e.createLinearGradient(0,-l/2,0,l/2);f.addColorStop(0,`#11171b`),f.addColorStop(.45,`#030609`),f.addColorStop(1,`#222a2e`),e.fillStyle=f,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-d*.78),r=t*(l*.25+d*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:u(this.elapsed/Z.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,!h(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()}},On=.22,kn=.24,An=class{phase=`closed`;phaseTime=0;shotClock=0;flashAge=1/0;presetId=null;bullets=[];captureState(){return a({phase:this.phase,phaseTime:this.phaseTime,shotClock:this.shotClock,flashAge:this.flashAge,presetId:this.presetId,bullets:this.bullets})}restoreState(e){let t=a(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,r,i,a){if(t.mode!==`car`){this.reset();return}this.presetId&&this.presetId!==t.car.preset.id&&this.reset();let o=n(t.car.preset),s=!!t.lastInput.machineGun;if(s&&(this.phase===`closed`||this.phase===`closing`)){this.presetId=t.car.preset.id;let e=this.open;this.phase=`opening`,this.phaseTime=e*On}else if(!s&&(this.phase===`opening`||this.phase===`active`)){let e=this.open;this.phase=`closing`,this.phaseTime=(1-e)*kn}if(this.phaseTime+=e,this.flashAge+=e,this.phase===`opening`&&this.phaseTime>=On&&(this.phase=`active`,this.phaseTime=0,this.shotClock=1/o.roundsPerSecond),this.phase===`active`){if(s){let n=1/Math.max(1,o.roundsPerSecond);this.shotClock+=e;for(let e=0;this.shotClock>=n&&e<4;e++)this.shotClock-=n,this.fire(t),i?.()}}else this.phase===`closing`&&this.phaseTime>=kn&&(this.phase=`closed`,this.phaseTime=0);for(let t=this.bullets.length-1;t>=0;t--){let n=this.bullets[t],i=n.position,s=d(i,c(n.velocity,e)),l=r?.(i,s,.075);n.age+=e,l||n.age>=o.bulletLifetimeSeconds?(l&&a?.(l,n.velocity),this.bullets.splice(t,1)):n.position=s}}fire(e){let t=n(e.car.preset),r=m(l(1,0),e.body.angle);for(let n of[-1,1]){let i=e.body.world(_(e.car.preset,n)),a=d(c(r,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`?u(this.phaseTime/On,0,1):this.phase===`closing`?1-u(this.phaseTime/kn,0,1):1}drawMount(e,t,n,r,i,a=1,o){v(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(d(i.position,c(i.velocity,-.75/Math.max(1,o)))),l=e.createLinearGradient(s.x,s.y,a.x,a.y);l.addColorStop(0,`rgba(224,153,63,0)`),l.addColorStop(.7,`rgba(224,153,63,.25)`),l.addColorStop(1,`rgba(255,225,157,.7)`),e.globalAlpha=r,e.strokeStyle=l,e.lineWidth=Math.max(.65,n*.025),e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(a.x,a.y),e.stroke();let u=t(d(i.position,c(i.velocity,-.09/Math.max(1,o))));e.strokeStyle=`#fff6d7`,e.lineWidth=Math.max(.55,n*.018),e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(a.x,a.y),e.stroke()}e.restore()}},jn=.22,Mn=.24,Q=1/45,Nn=class{phase=`closed`;phaseTime=0;emitting=!1;presetId=null;fireClock=0;jets=[];captureState(){return a({phase:this.phase,phaseTime:this.phaseTime,emitting:this.emitting,presetId:this.presetId,fireClock:this.fireClock,jets:this.jets})}restoreState(e){let t=a(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,n,r,i,a){if(n.mode!==`car`){(this.phase!==`closed`||this.jets.length)&&this.reset();return}this.presetId&&this.presetId!==n.car.preset.id&&this.reset();let o=!!n.lastInput.flamethrower,s=t(n.car.preset);if(o&&(this.phase===`closed`||this.phase===`closing`)){this.presetId=n.car.preset.id;let e=this.open;this.phase=`opening`,this.phaseTime=e*jn}else if(!o&&(this.phase===`opening`||this.phase===`active`)){let e=this.open;this.phase=`closing`,this.phaseTime=(1-e)*Mn}if(this.phaseTime+=e,this.phase===`opening`&&this.phaseTime>=jn&&(this.phase=`active`,this.phaseTime=0,this.fireClock=Q),this.emitting=this.phase===`active`&&o,this.phase===`closing`&&this.phaseTime>=Mn&&(this.phase=`closed`,this.phaseTime=0),this.emitting){let t=m(l(1,0),n.body.angle),i=s.rangeM/.3;for(this.fireClock+=e;this.fireClock>=Q;){this.fireClock-=Q;for(let e of[-1,1]){let r=n.body.world(_(n.car.preset,e));this.jets.push({point:r,velocity:d(c(t,i),c(n.body.velocity,.25)),traveled:0,range:s.rangeM,speed:i,width:s.jetWidthM*s.flowRate})}}for(let i of[-1,1]){let a=n.body.world(_(n.car.preset,i));r({point:d(a,c(t,.06)),flow:c(t,5.5),amount:e*s.smokePerSecond*s.flowRate*.38,radiusM:.12})}}let u=[];for(let t of this.jets){let n=Math.min(t.range-t.traveled,t.speed*e),o=t.point,l=d(o,c(t.velocity,n/t.speed)),f=(t.traveled+n)/t.range,p=t.width*(.65+1.45*f),m=i?.(o,l,Math.max(.3,p*1.25),Q*s.flowRate),h=m??l;t.point=h,t.traveled+=n,a?.(o,h,p,t.velocity,f),(f>.62||m)&&r({point:h,flow:c(t.velocity,.42),amount:e*s.smokePerSecond*s.flowRate*(m?.42:.18),radiusM:Math.max(.11,p*.48)}),m?a?.(h,h,p*1.35,t.velocity,f):t.traveled+1e-6<t.range&&u.push(t)}this.jets=u}get open(){return this.phase===`closed`?0:this.phase===`opening`?u(this.phaseTime/jn,0,1):this.phase===`closing`?1-u(this.phaseTime/Mn,0,1):1}drawMount(e,t,n,r,i,a=1,o){v(e,t,n,r,i,this.open,`flame`,this.phase===`active`?.8:0,a,o)}},Pn=class{rocket=new Dn;machineGuns=new An;flamethrower=new Nn;lightning=new g;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}},$=e=>({...e,slots:e.slots?[...e.slots]:void 0,slotPresses:e.slotPresses?[...e.slotPresses]:void 0}),Fn=mn({types:{events:{}}}).createMachine({id:`vehicleLifecycle`,initial:`drivable`,states:{drivable:{on:{DESTROYED:`destroyed`}},destroyed:{on:{RESPAWNED:`drivable`}}}}),In=class{id;sim;damage=new gn;weapons=new Pn;tirePaint=new En;pickupEffect=new _n;lifecycle=A(Fn).start();controls={throttle:0,steer:0,action:!1};controlSource=`player`;label=``;appearance=`auto`;slotConfiguration=S;toolPolicy={};numberedSlots=re(S);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=re(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})).filter(e=>e.amount>0)}useSlot(e){let t=x(e);return this.disposed||!this.numberedSlots[t-1]||this.lifecycleState!==`drivable`?!1:(this.slotPulses.add(t),!0)}startSlot(e){let t=x(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(x(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(x)),n=new Set((e.slotPresses??[]).map(x));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=$(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}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}setControls(e,t,n={}){if(n.toolsEnabled!==this.toolPolicy.toolsEnabled){let t=re(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(x(t))}this.toolPolicy=n,this.numberedSlots=t}this.controls=ne(this.resolveSlots(e),n.toolsEnabled),this.controlSource=t}step(e,t,n=!1){this.pickupEffect.step(e),n?this.sim.lastInput={throttle:0,steer:0,action:!1,boost:!1}:this.sim.tick(this.lifecycleState===`drivable`?this.controls:{throttle:0,steer:0,action:!1},e,t),this.weapons.lightning.step(e,!n&&!!this.sim.lastInput.lightning&&this.lifecycleState===`drivable`,b(this.sim.car.preset).chargeSeconds),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.tirePaint.reset(),this.pickupEffect.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.tirePaint.reset(),this.pickupEffect.reset(),this.synchronizeLifecycle()}setPreset(e){this.clearSlotInput(),this.sim.setPreset(e),this.damage.reset(),this.weapons.reset(),this.tirePaint.reset(),this.pickupEffect.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>=o.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(),tirePaint:this.tirePaint.captureState(),pickupEffect:this.pickupEffect.captureState(),controls:$(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.tirePaint.restoreState(e.tirePaint),this.pickupEffect.restoreState(e.pickupEffect),this.controls=$(e.controls),this.controlSource=e.controlSource,this.lifecycle.stop(),this.lifecycle=A(Fn,{snapshot:e.lifecycle}).start()}dispose(){this.disposed=!0,this.pickupEffect.reset(),this.clearSlotInput(),this.lifecycle.stop()}};export{gn as n,In as t};
|