PageSourceSearch

https://aetherscope-app.web.app/assets/controller-DDYzpmIg.js

js aetherscope-app.web.app collected 2026-10-03 12:15:40 UTC 74,278 bytes, 1 lines download raw bytes

1import{c as Be,d as re,a as je,L as ht,J as mt,b as z,e as ft,f as ce,g as pt,h as xt,i as gt,k as Q,l as bt,m as ve,n as Xe,P as yt,W as vt,o as wt,p as Re,q as Me,r as le,s as We,t as jt,u as St,v as Nt,w as Ct,x as ue,y as de,z as kt,A as Te,B as Pt,C as Lt,D as Rt,E as Mt,F as Wt,G as Tt,H as It,I as zt,K as Ge,M as ie,j as n,N as Z,O as At,Q as Ie,R as Vt,S as Et,T as v,U as ee,V as Ft,X as Qe,Y as D,Z as Ot,_ as ze,$ as Ae,a0 as Ze,a1 as Ve}from"./index-BWQ_003N.js";import{D as et,a as tt,b as nt,c as st,u as $,S as $t}from"./useSyncRef-BR4RkdWI.js";import{G as _t,L as Dt,V as Jt,S as he,a as me,b as fe,c as pe,d as xe,P as rt,e as Ht,p as Ee,r as Yt,f as ge,g as Fe,h as Kt,t as F,i as qt,s as Se,m as Ut,R as te,M as Bt,U as Oe,j as Xt}from"./controllerRange-6-XsImRn.js";import{M as it,X as Gt}from"./x-BG4rm9CX.js";import"./owner-CkyA1xtG.js";import"./input-CcP4PNSI.js";const Qt=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],we=Be("settings-2",Qt);const Zt=[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]],en=Be("shapes",Zt),tn="wireProbe",nn=.37;function $e(s,e){return e?{re:Math.cos(s),im:Math.sin(s)}:{re:Math.sin(s),im:0}}function sn(s,e){if(s.type==="float"){const i=$e(e,s.complex);return s.complex?{re:i.re,im:i.im}:i.re}const{re:t}=re(s.value,s.type),r=[],a=[];for(let i=0;i<t.length;i++){const c=e+i*nn,o=$e(c,s.complex);r.push(o.re),a.push(o.im)}return je(s.type,s.complex,r,a)}function rn(s,e,t){const r={};for(const a of s)r[a]=sn(e[a],t);return r}function J(){if(typeof window>"u")return!1;const s=window;if(s.__jamWireProbe===!0)return!0;if(s.__jamWireProbe===!1)return!1;const e=new URLSearchParams(window.location.search).get(tn);return e==="1"||e==="true"}function at(){const s=window;return s.DeviceOrientationEvent??s.DeviceMotionEvent}function _(){return typeof at()?.requestPermission=="function"}function Ne(s){return window.isSecureContext?s()?"ready":"unsupported":"needs-https"}function an(){if(!window.isSecureContext||!("ondevicemotion"in window||"ondeviceorientation"in window||"LinearAccelerationSensor"in window||"RelativeOrientationSensor"in window||"AbsoluteOrientationSensor"in window))return!1;const e=navigator.userAgent;return!!(/Android|iPhone|iPad|iPod|Mobile/i.test(e)||navigator.maxTouchPoints>1&&/Macintosh/i.test(e))}async function Ce(){const s=at();return s?.requestPermission?await s.requestPermission()==="granted":!0}function on(s,{attack:e,release:t=e}){let r=null;return a=>{const i=Math.max(0,Math.min(1,a));if(r===null)r=i;else{const c=i>r?e:t;r=c*i+(1-c)*r}s(r)}}function cn(s,{attack:e,release:t=e}){let r=null;return a=>{const i=[Math.max(0,Math.min(1,a[0])),Math.max(0,Math.min(1,a[1])),Math.max(0,Math.min(1,a[2]))];if(r===null)r=i;else{const c=[0,0,0];for(let o=0;o<3;o++){const u=i[o]>r[o]?e:t;c[o]=u*i[o]+(1-u)*r[o]}r=c}s(r)}}async function ln(s,e){const t=e.replace(/\/$/,""),r=await fetch(`${t}/attest/player?room=${encodeURIComponent(s)}`);if(!r.ok)throw new Error("Session attestation failed");const a=await r.json();if(!a.attestation)throw new Error("Session attestation failed");return a.attestation}const un=["aetherscope-app.web.app","aetherscope-app.firebaseapp.com","localhost"];function _e(){if(window.location.port===String(ht))return window.location.origin;const s=window.location.hostname;return un.some(t=>s===t||s.endsWith(`.${t}`))?"https://aetherscope-party.paramountliquor.workers.dev":window.location.origin}class dn{sentinel=null;wanted=!1;visibilityHandler=null;async acquire(){this.wanted=!0,this.ensureVisibilityHook(),await this.request()}async release(){this.wanted=!1,this.clearVisibilityHook(),await this.drop()}ensureVisibilityHook(){this.visibilityHandler||typeof document>"u"||(this.visibilityHandler=()=>{this.wanted&&document.visibilityState==="visible"&&this.request()},document.addEventListener("visibilitychange",this.visibilityHandler))}clearVisibilityHook(){!this.visibilityHandler||typeof document>"u"||(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)}async request(){if(this.wanted&&!(typeof navigator>"u"||!navigator.wakeLock?.request)&&!(typeof document<"u"&&document.visibilityState!=="visible"))try{await this.drop();const e=await navigator.wakeLock.request("screen");this.sentinel=e,e.addEventListener("release",()=>{this.sentinel===e&&(this.sentinel=null)})}catch{}}async drop(){const e=this.sentinel;if(this.sentinel=null,!!e)try{await e.release()}catch{}}}class hn{pc=null;dc=null;iceQueue=new mt;handlers;sendCount=0;sendFailCount=0;constructor(e){this.handlers=e}get open(){return this.dc!==null&&this.dc.readyState==="open"}get bufferedAmount(){return this.dc?.bufferedAmount??0}close(){if(this.iceQueue.reset(),this.dc){this.dc.onopen=null,this.dc.onclose
1=null,this.dc.onerror=null,this.dc.onbufferedamountlow=null;try{this.dc.close()}catch{}this.dc=null}if(this.pc){this.pc.onicecandidate=null,this.pc.onconnectionstatechange=null,this.pc.oniceconnectionstatechange=null;try{this.pc.close()}catch{}this.pc=null}}async start(){this.close(),this.sendCount=0,this.sendFailCount=0,z("phone","start");const e=new RTCPeerConnection(ft());this.pc=e,e.onicecandidate=r=>{const a=r.candidate?{candidate:r.candidate.candidate,sdpMid:r.candidate.sdpMid,sdpMLineIndex:r.candidate.sdpMLineIndex,usernameFragment:r.candidate.usernameFragment}:null;z("phone","local-ice",{kind:ce(a)}),this.handlers.onLocalIce(a)},e.onconnectionstatechange=()=>{z("phone","pc-state",{connectionState:e.connectionState}),(e.connectionState==="failed"||e.connectionState==="closed")&&this.dc&&(this.dc=null,this.handlers.onClosed())},e.oniceconnectionstatechange=()=>{z("phone","ice-state",{iceConnectionState:e.iceConnectionState})};const t=e.createDataChannel(pt,{...gt(),negotiated:!0,id:xt});this.dc=t,t.binaryType="arraybuffer",t.bufferedAmountLowThreshold=16384,t.onopen=()=>{z("phone","dc-open",{readyState:t.readyState,id:t.id}),this.handlers.onOpen()},t.onclose=()=>{z("phone","dc-close"),this.dc===t&&(this.dc=null),this.handlers.onClosed()},t.onerror=()=>{z("phone","dc-error")};try{const r=await e.createOffer();await e.setLocalDescription(r);const a=e.localDescription?.sdp;if(!a){z("phone","offer-empty");return}z("phone","local-offer",{sdpBytes:a.length}),this.handlers.onLocalOffer(a)}catch(r){z("phone","offer-failed",{err:r instanceof Error?r.message:String(r)}),this.close(),this.handlers.onClosed()}}async applyRemoteAnswer(e){if(!this.pc){z("phone","answer-no-pc");return}try{z("phone","remote-answer",{sdpBytes:e.length}),await this.pc.setRemoteDescription({type:"answer",sdp:e}),await this.iceQueue.flush(this.pc),z("phone","remote-answer-applied",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,dc:this.dc?.readyState})}catch(t){z("phone","answer-failed",{err:t instanceof Error?t.message:String(t)}),this.close(),this.handlers.onClosed()}}async applyRemoteIce(e){this.pc&&(Q("phone","remote-ice",ce(e),{kind:ce(e)}),await this.iceQueue.push(this.pc,e))}send(e){if(!this.open||!this.dc)return this.sendFailCount+=1,Q("phone","send-not-open","x",{fails:this.sendFailCount,dc:this.dc?.readyState??null}),!1;try{return this.dc.send(e),this.sendCount+=1,Q("phone","send-ok","x",{n:this.sendCount,bytes:e.byteLength,buf:this.dc.bufferedAmount}),!0}catch(t){return this.sendFailCount+=1,Q("phone","send-throw","x",{fails:this.sendFailCount,err:t instanceof Error?t.message:String(t)}),!1}}}function mn(s,e){return ve(s)?new WebSocket(Xe(s,e)):new yt({host:s,party:"room",room:e,query:{[vt.role]:"player"},maxRetries:0,connectionTimeout:8e3})}function fn(s,e,t,r,a){if(!s||s.readyState!==WebSocket.OPEN||e.length===0)return{ok:!1,sent:!1,bufferedAmount:0};const i=bt(e,t,r,a);return!i.ok||!i.sent?{ok:i.ok,sent:!1,bufferedAmount:s.bufferedAmount??0}:(s.send(i.frame),{ok:!0,sent:!0,bufferedAmount:s.bufferedAmount??0})}function pn(s){return new Worker("/assets/jamPlayerWire.worker-DgIi2gJE.js",{type:"module",name:s?.name})}function be(s){return new Worker("/assets/jamStreamClock.worker-B0BrOy7j.js",{type:"module",name:s?.name})}function De(s){return`jamroom:deviceToken:${s}`}const xn=15e3,gn=1e4;function ne(s){return!(s.boolean||s.type==="float")}class bn{constructor(e,t){this.room=e,this.state={phase:"name",name:t,assignments:{},values:{},componentValues:{},componentValuesIm:{},roster:[]}}socket=null;wireWorker=null;lanRtc=null;wakeLock=new dn;lanWirePath=!1;assignmentKeys=[];streamActive=!1;streamWorker=null;wireClockWorker=null;lastLanWireSent={};lanWireJumping=new Set;lanWireJumpArmed=new Set;lastStreamTickSnapshot={};lanNetGap=new wt;paramTurn=new Map;listener=null;state;joinTimeout=null;rtcReadyTimeout=null;lanRtcOpen=!1;uiFlushScheduled=!1;editing=new Set;subscribe(e){return this.listener=e,e(this.state),()=>{this.listener===e&&(this.listener=null)}}set(e,t=!0){this.state={...this.state,...e},t&&(e.phase!==void 0||e.assignments!==void 0?this.flushUiNow():this.scheduleUiFlush())}syncAssignmentKeys(){const e=this.assignmentKeys;if(this.assignmentKeys=Object.keys(this.state.assignments).sort(),this.lanWirePath&&this.wireWorker&&this.lanRtcOpen&&J()){for(const t of e)this.state.assignments[t]||this.socketSend(JSON.stringify({t:"touch",lhs:t,active:!1}));for(const t of this.assignmentKeys)e.includes(t)||this.socketSend(JSON.stringify({t:"touch",lhs:t,active:!0}))}}claimLanProbeTouches(){for(const e of this.assignmentKeys)this.socketSend(JSON.stringify({t:"touch",lhs:e,active:!0}))}releaseLanProbeTouches(){for(const e of this.assignmentKeys)this.socketSend(JSON.stringify({t:"touch",lhs:e,active:!1}))}ensureLanWireStream(){if(!(!this.lanWirePath||!this.wireWorker||!this.lanRtcOpen)&&this.assignmentKeys.length!==0){if(J()){this.stopLanWireStream(),this.lanNetGap.reset(),this.startLanProbeStream(),this.claimLanProbeTouches();return}this.stopStreamLoop(),this.stopLanWireClock(),this.syncComposedValues(),this.startLanWireClock()}}tickLanWirePump(){!this.lanWirePath||!this.lanRtcOpen||this.assignmentKeys.length===0||this.sendLanWireFromState(!1)}startLanWireClock(){if(!this.lanWirePath||this.wireClockWorker)return;this.lastLanWireSent=this.snapshotAssignedMemory();const e=new be;e.onmessage=()=>this.tickLanWirePump(),this.wireClockWorker=e,e.postMessage({t:"start",hz:Re}),this.sendLanWireFromState(!0)}stopLanWireClock(){this.wireClockWorker&&(this.wireClockWorker.postMessage({t:"stop"}),this.wireClockWorker.terminate(),this.wireClockWorker=null,this.lastLanWireSent={},this.lanWireJumping.clear(),this.lanWireJumpArmed.clear())}lanWireGestureFlags(){return{touching:new Set(this.editing),jumping:new Set(this.lanWireJumping)}}armLanWireJump(e){this.lanWireJumpArmed.add(e)}consumeLanWireJump(e){const t=this.lanWireJumpArmed.has(e)||!this.editing.has(e);return this.lanWireJumpArmed.delete(e),t&&this.lanWireJumping.add(e),t}shouldForceLanWireSend(e){return this.lanWireJumping.has(e)?!0:!this.editing.has(e)}sendLanWireFromState(e=!1){if(!this.lanWirePath||!this.lanRtcOpen||J()||this.assignmentKeys.length===0)return;this.syncComposedValues();const t=this.snapshotAssignedMemory(),r=this.lanWireGestureFlags();if(!e){let h=r.jumping.size>0;
1if(!h){for(const f of this.assignmentKeys)if(!Me(this.lastLanWireSent[f],t[f])){h=!0;break}}if(!h)return}const a=le(this.assignmentKeys,this.state.assignments,t,r);if(!a.ok||!this.sendLanWireFrame(a.frame))return;for(const h of this.assignmentKeys)this.lastLanWireSent[h]=t[h];const o=r.jumping.size>0&&r.touching.size===0;if(this.lanWireJumping.clear(),o){for(const f of r.jumping)this.lanWireJumping.add(f);const h=le(this.assignmentKeys,this.state.assignments,t,this.lanWireGestureFlags());h.ok&&this.sendLanWireFrame(h.frame)&&this.lanWireJumping.clear()}const u=this.assignmentKeys[0];u&&We("phone:wire-send",u,{bytes:a.frame.byteLength,force:e,touching:[...r.touching],jumping:[...r.jumping],discreteRetry:o})}startLanProbeStream(){if(this.streamActive)return;this.streamActive=!0,this.lanNetGap.reset();const e=new be;e.onmessage=()=>this.tickLanProbeStream(),this.streamWorker=e,e.postMessage({t:"start",hz:Re})}tickLanProbeStream(){if(!this.lanRtcOpen||this.assignmentKeys.length===0)return;const e=performance.now(),t=rn(this.assignmentKeys,this.state.assignments,e/1e3),r=le(this.assignmentKeys,this.state.assignments,t);r.ok&&this.sendLanWireFrame(r.frame)}stopLanWireStream(){this.stopLanWireClock(),this.lanWirePath&&this.streamActive&&J()&&this.releaseLanProbeTouches()}sendLanWireFrame(e){if(!this.lanWirePath||!this.lanRtcOpen||!this.lanRtc?.open||this.lanRtc.bufferedAmount>jt)return!1;const t=performance.now(),r=St(e,Wt),a=this.lanNetGap.stamp(r,this.lanRtc.bufferedAmount,t);return this.lanRtc.send(a)}flushLanWireFinal(){this.sendLanWireFromState(!0)}clearRtcReadyTimeout(){this.rtcReadyTimeout!==null&&(clearTimeout(this.rtcReadyTimeout),this.rtcReadyTimeout=null)}onLanRtcOpen(){z("phone","session-dc-open",{phase:this.state.phase,keys:this.assignmentKeys}),this.clearRtcReadyTimeout(),this.lanRtcOpen=!0,this.state.phase==="connecting"&&this.set({phase:"live",error:void 0}),this.wakeLock.acquire(),this.ensureLanWireStream(),this.ensureStreamLoop()}onLanRtcClosed(){z("phone","session-dc-closed",{phase:this.state.phase}),this.lanRtcOpen=!1,this.state.phase==="live"?(this.stopLanWireStream(),this.stopStreamLoop(),this.set({phase:"error",error:"LAN wire channel closed"})):this.state.phase==="connecting"&&this.failConnect("Could not open the LAN wire channel")}startLanRtc(){!this.lanWirePath||!this.wireWorker||(z("phone","session-start"),this.lanRtcOpen=!1,this.clearRtcReadyTimeout(),this.rtcReadyTimeout=setTimeout(()=>{this.rtcReadyTimeout=null,!this.lanRtcOpen&&(z("phone","session-timeout"),this.failConnect("Timed out opening the LAN wire channel"))},gn),this.lanRtc?.close(),this.lanRtc=new hn({onLocalOffer:e=>{z("phone","signal-offer-out",{sdpBytes:e.length}),this.socketSend(JSON.stringify({t:"rtcOffer",sdp:e}))},onLocalIce:e=>this.socketSend(JSON.stringify({t:"rtcIce",candidate:e})),onOpen:()=>this.onLanRtcOpen(),onClosed:()=>this.onLanRtcClosed()}),this.lanRtc.start())}onWireWorkerMessage(e){switch(e.t){case"open":this.sendHello();break;case"message":this.onMessage(e.raw);break;case"error":this.failConnect("Could not connect to the session server");break;case"close":if(this.state.phase==="connecting"){this.failConnect("Disconnected before joining the session");return}this.state.phase==="live"&&(this.stopStreamLoop(),this.set({phase:"error",error:"Disconnected from the session"}),this.wireWorker=null);break}}attachWireWorkerHandlers(e){e.onmessage=t=>{this.onWireWorkerMessage(t.data)},e.onerror=()=>{this.failConnect("Could not connect to the session server")}}snapshotAssignedMemory(){const e={};for(const t of this.assignmentKeys)e[t]=this.state.values[t]??this.state.assignments[t].value;return e}flushUiNow(){this.uiFlushScheduled=!1,this.state={...this.state,values:{...this.state.values},componentValues:{...this.state.componentValues},componentValuesIm:{...this.state.componentValuesIm}},this.listener?.(this.state)}scheduleUiFlush(){this.uiFlushScheduled||(this.uiFlushScheduled=!0,requestAnimationFrame(()=>{this.uiFlushScheduled=!1,this.state={...this.state,values:{...this.state.values},componentValues:{...this.state.componentValues},componentValuesIm:{...this.state.componentValuesIm}},this.listener?.(this.state)}))}syncComposedValues(){for(const e of this.assignmentKeys){const t=this.state.assignments[e];if(!t||!ne(t))continue;const r=this.state.componentValues[e];if(!r)continue;const a=this.state.componentValuesIm[e]??[];this.state.values[e]=je(t.type,t.complex??!1,r,a)}}turnState(e,t){let r=this.paramTurn.get(e);return r||(r=Nt(t??this.state.values[e]),this.paramTurn.set(e,r)),r}setTurnState(e,t){this.paramTurn.set(e,t)}applyValueToPhoneMemory(e,t){const r=this.state.assignments[e];if(this.state.values[e]=t,r&&ne(r)){const a=re(t,r.type);this.state.componentValues[e]=a.re,this.state.componentValuesIm[e]=a.im}this.lastStreamTickSnapshot[e]=t,this.lastLanWireSent[e]=t,this.scheduleUiFlush()}socketSend(e){if(this.lanWirePath){this.wireWorker?.postMessage({t:"send",raw:e});return}this.socket?.readyState===WebSocket.OPEN&&this.socket.send(e)}failConnect(e){this.state.phase==="connecting"&&(this.clearJoinTimeout(),this.set({phase:"error",error:e}),this.close())}async sendHello(){const e=localStorage.getItem(De(this.room))??void 0;let t;try{t=_e()}catch(r){const a=r instanceof Error?r.message:"Session server is not configured";this.failConnect(a);return}try{const r=await ln(this.room,t),a=JSON.stringify({t:"hello",role:"player",name:this.state.name,deviceToken:e,attestation:r,hasMotionSensors:an()});this.socketSend(a)}catch(r){const a=r instanceof Error?r.message:"Session attestation failed";this.failConnect(a)}}tickMemoryStream(){if(this.state.phase!=="live"||this.socket?.readyState!==WebSocket.OPEN)return;this.syncComposedValues();const e=fn(this.socket,this.assignmentKeys,this.state.assignments,this.state.values,this.lastStreamTickSnapshot);if(!(!e.ok||!e.sent))for(const t of this.assignmentKeys)this.lastStreamTickSnapshot[t]=this.state.values[t]??this.state.assignments[t].value}ensureStreamLoop(){if(!this.lanWirePath&&this.state.phase==="live"){if(this.assignmentKeys.length===0){this.streamActive&&this.stopStreamLoop();return}this.streamActive||this.startStreamLoop()}}stopStreamClockWorker(){this.streamWorker&&(this.streamWorker.postMessage({t:"stop"}),this.streamWorker.terminate(),this.streamWorker=null)}onStreamClockTick(){!this.streamActive||this.assignmentKeys.length===0||(this.syncComposedValues(),this.tickMemoryStream())}startStreamLoop(){this.lastStreamTickSnapshot={},this.streamActive=!0;const e=new be;e.onmessage=()=>this.onStreamClockTick(),this.streamWorker=e,e.postMessage({t:"start",hz:Ct})}stopStreamLoop(){this.streamActive=!1,this.lastStreamTickSnapshot={},this.stopStreamClockWorker()}writeMemory(e,t,r){const a=this.state.assignments[e];if(this.state.values[e]=t,a&&ne(a)){const o=r??re(t,a.type);this.state.componentValues[e]=o.re,this.state.componentValuesIm[e]=o.im}else r&&(this.state.componentValues[e]=r.re,this.state.componentValuesIm[e]=r.im);this.editing.has(e)||this.scheduleUiFlush();const i=this.consumeLanWireJump(e);ue(e,t,this.editing.has(e),i),this.shouldForceLanWireSend(e)&&this.sendLanWireFromState(!0);let c=this.turnState(e,t);c=de(c,t),this.setTurnState(e,c)}get snapshot(){return this.state}connect(e){this.clearJoinTimeout(),this.close(),this.set({phase:"connecting",name:e,error:void 0});let t;try{t=_e()}catch(a){const i=a instanceof Error?a.message:"Session server is not configured";this.set({phase:"error",error:i});return}this.lanWirePath=ve(t);const r=Xe(t,this.room);if(!this.lanWirePath&&ve(r)&&(this.lanWirePath=!0),this.lanWirePath){const a=new pn;this.wireWorker=a,this.attachWireWorkerHandlers(a),a.postMessage({t:"connect",url:r})}else this.socket=mn(t,this.room),this.socket.addEventListener("open",()=>{this.sendHello()}),this.socket.addEventListener("message",a=>this.onMessage(a.data)),this.socket.addEventListener("error",()=>{this.failConnect("Could not connect to the session server")}),this.socket.addEventListener("close",()=>{if(this.state.phase==="connecting"){this.failConnect("Disconnected before joining the session");return}this.state.phase==="live"&&(this.stopStreamLoop(),this.set({phase:"error",error:"Disconnected from the session"}),this.socket=null)});this.joinTimeout=setTimeout(()=>this.failConnect("Timed out joining the session"),xn)}clearJoinTimeout(){this.joinTimeout!==null&&(clearTimeout(this.joinTimeout),this.joinTimeout=null)}close(){this.clearJoinTimeout(),this.clearRtcReadyTimeout(),this.stopLanWireStream(),this.stopStreamLoop(),this.assignmentKeys=[],this.lanRtcOpen=!1,this.wakeLock.release(),this.lanRtc?.close(),this.lanRtc=null,this.lanWirePath&&(this.wireWorker?.postMessage({t:"disconnect"}),this.wireWorker?.terminate(),this.wireWorker=null),this.socket?.close(),this.socket=null,this.lanWirePath=!1,this.paramTurn.clear()}onMessage(e){let t;try{t=JSON.parse(e)}catch{return}switch(t.t){case"welcome":{this.clearJoinTimeout(),localStorage.setItem(De(this.room),t.deviceToken);const r={},a={},i={};for(const[c,o]of Object.entries(t.assignments))r[c]=o.value,o.componentValues&&(a[c]=[...o.componentValues]),o.componentValuesIm&&(i[c]=[...o.componentValuesIm]);this.set({phase:this.lanWirePath?"connecting":"live",playerId:t.playerId,assignments:{...t.assignments},values:r,componentValues:a,componentValuesIm:i,roster:t.roster,error:void 0}),this.syncAssignmentKeys(),this.lanWirePath?this.startLanRtc():(this.wakeLock.acquire(),this.ensureStreamLoop());break}case"rtcAnswer":{if(!this.lanWirePath)break;z("phone","signal-answer-in",{sdpBytes:t.sdp.length,hasRtc:!!this.lanRtc}),this.lanRtc?.applyRemoteAnswer(t.sdp);break}case"rtcIce":{if(!this.lanWirePath)break;this.lanRtc?.applyRemoteIce(t.candidate);break}case"assigned":{this.set({assignments:{...this.state.assignments,[t.schema.lhs]:t.schema},values:{...this.state.values,[t.schema.lhs]:t.schema.value},componentValues:t.schema.componentValues?{...this.state.componentValues,[t.schema.lhs]:[...t.schema.componentValues]}:this.state.componentValues,componentValuesIm:t.schema.componentValuesIm?{...this.state.componentValuesIm,[t.schema.lhs]:[...t.schema.componentValuesIm]}:this.state.componentValuesIm}),this.syncAssignmentKeys(),this.ensureLanWireStream(),this.ensureStreamLoop();break}case"unassigned":{const r={...this.state.assignments},a={...this.state.values},i={...this.state.componentValues},c={...this.state.componentValuesIm};delete r[t.lhs],delete a[t.lhs],delete i[t.lhs],delete c[t.lhs],this.editing.delete(t.lhs),this.paramTurn.delete(t.lhs),this.set({assignments:r,values:a,componentValues:i,componentValuesIm:c}),this.syncAssignmentKeys(),this.ensureLanWireStream(),this.ensureStreamLoop();break}
1case"value":{if(this.editing.has(t.lhs))break;const r=this.turnState(t.lhs,t.value);if(!Pt(r))break;const a=Lt(r,t.value);if(this.setTurnState(t.lhs,a),Me(this.state.values[t.lhs],t.value))break;this.applyValueToPhoneMemory(t.lhs,t.value);break}case"hostTouch":{let r=this.turnState(t.lhs);r=t.active?kt(r):Te(r),this.setTurnState(t.lhs,r);break}case"schema":{if(!this.state.assignments[t.lhs])return;const r={assignments:{...this.state.assignments,[t.lhs]:t.schema}};this.editing.has(t.lhs)||(r.values={...this.state.values,[t.lhs]:t.schema.value},r.componentValues=t.schema.componentValues?{...this.state.componentValues,[t.lhs]:[...t.schema.componentValues]}:this.state.componentValues,r.componentValuesIm=t.schema.componentValuesIm?{...this.state.componentValuesIm,[t.lhs]:[...t.schema.componentValuesIm]}:this.state.componentValuesIm),this.set(r),this.syncAssignmentKeys();break}case"roster":this.set({roster:t.players});break;case"kicked":this.set({phase:"kicked",error:t.reason}),this.close();break;case"error":this.state.phase!=="live"&&(this.clearJoinTimeout(),this.set({phase:"error",error:t.msg}),this.close());break}}setValue(e,t){const r=this.state.assignments[e];if(!r){this.writeMemory(e,t);return}if(ne(r)){const a=re(t,r.type);this.writeMemory(e,t,a);return}this.writeMemory(e,t)}setComponent(e,t,r){if(!this.state.assignments[e])return;let i=this.state.componentValues[e];i||(i=[],this.state.componentValues[e]=i),i[t]=r,this.state.componentValuesIm[e]||(this.state.componentValuesIm[e]=[]),this.syncComposedValues();const c=this.state.values[e];if(c===void 0)return;this.editing.has(e)||this.scheduleUiFlush();const o=this.consumeLanWireJump(e);ue(e,c,this.editing.has(e),o),this.shouldForceLanWireSend(e)&&this.sendLanWireFromState(!0);let u=this.turnState(e,c);u=de(u,c),this.setTurnState(e,u)}setComponentComplex(e,t,r){if(!this.state.assignments[e])return;let i=this.state.componentValues[e];i||(i=[],this.state.componentValues[e]=i);let c=this.state.componentValuesIm[e];c||(c=[],this.state.componentValuesIm[e]=c),i[t]=r.re,c[t]=r.im,this.syncComposedValues();const o=this.state.values[e];if(o===void 0)return;this.editing.has(e)||this.scheduleUiFlush();const u=this.consumeLanWireJump(e);ue(e,o,this.editing.has(e),u),this.shouldForceLanWireSend(e)&&this.sendLanWireFromState(!0);let h=this.turnState(e,o);h=de(h,o),this.setTurnState(e,h)}setEditing(e,t){if(t){this.editing.add(e),this.lanWireJumpArmed.add(e);let r=this.turnState(e);r=Rt(r),this.setTurnState(e,r)}else{this.editing.delete(e),this.lanWireJumpArmed.delete(e);let r=this.turnState(e);r=Te(r),this.setTurnState(e,r),this.scheduleUiFlush()}if(!(this.lanWirePath&&J())){if(this.lanWirePath){t||(this.flushLanWireFinal(),We("phone:release",e,{},{force:!0}));return}this.socket?.readyState===WebSocket.OPEN&&this.socket.send(JSON.stringify({t:"touch",lhs:e,active:t}))}}patchSchema(e,t){const r=this.state.assignments[e];if(!r)return;const a=Mt(r,t);this.set({assignments:{...this.state.assignments,[e]:a}}),this.syncAssignmentKeys();const i=JSON.stringify({t:"patchSchema",lhs:e,patch:t});this.lanWirePath?this.socketSend(i):this.socket?.readyState===WebSocket.OPEN&&this.socket.send(i)}}const se=[{value:"0",label:"Global",icon:_t},{value:"1",label:"Layer",icon:Dt},{value:"2",label:"System",icon:en},{value:"3",label:"Variant",icon:Jt}],Je=[{value:"full",label:"Full"},{value:"positive",label:"Pos"},{value:"unit",label:"Unit"},{value:"parameter",label:"Range"}],yn=[{value:"real",label:"Real"},{value:"complex",label:"Complex"},{value:"boolean",label:"Boolean"}];function He({schema:s,open:e,onOpenChange:t,onPatch:r}){const a=String(s.scope??0),i=s.rangeMode??Tt,c=It(s),o=se.find(m=>m.value===a)??se[0],u=o.icon,h=zt(s),f=Ge(s,s.widgetType),l=f&&h.includes(f)?f:null,d=ie(s.padCount),x=l==="pads",w=l==="plane"||l==="dualPlane",S=s.planePolar??!1;return n.jsx(et,{open:e,onOpenChange:t,children:n.jsxs(tt,{className:"max-w-sm gap-0 p-0 overflow-hidden",children:[n.jsx(nt,{className:"px-4 pt-4 pb-2",children:n.jsxs(st,{className:"flex items-center gap-2 text-base",children:[n.jsx(we,{className:"h-4 w-4"}),s.label||s.lhs]})}),n.jsxs("div",{className:"border-t",children:[n.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium px-4 py-2 bg-muted/30",children:"Scope"}),n.jsxs(he,{items:se.map(m=>({value:m.value,label:m.label})),value:a,onValueChange:m=>{m!=null&&r({scope:Number(m)}
1)},children:[n.jsx(me,{className:"border-0 rounded-none h-11",children:n.jsx(fe,{children:n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(u,{className:"h-4 w-4"}),o.label]})})}),n.jsx(pe,{children:se.map(m=>n.jsx(xe,{value:m.value,children:n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(m.icon,{className:"h-4 w-4"}),m.label]})},m.value))})]})]}),n.jsxs("div",{className:"border-t",children:[n.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium px-4 py-2 bg-muted/30",children:"Number type"}),n.jsx("div",{className:"grid grid-cols-3 gap-2 p-3",children:yn.map(m=>n.jsx(Z,{variant:c===m.value?"default":"outline",size:"sm",onClick:()=>r(At(m.value)),children:m.label},m.value))})]}),h.length>0&&n.jsxs("div",{className:"border-t",children:[n.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium px-4 py-2 bg-muted/30",children:"Widget"}),n.jsxs(he,{items:h.map(m=>({value:m,label:Ie(m,s)})),value:l??void 0,onValueChange:m=>{m!=null&&r({widgetType:m,colorPicker:m==="color"})},children:[n.jsx(me,{className:"border-0 rounded-none h-11",children:n.jsx(fe,{placeholder:"Choose widget"})}),n.jsx(pe,{children:h.map(m=>n.jsx(xe,{value:m,children:Ie(m,s)},m))})]})]}),x&&n.jsxs("div",{className:"border-t",children:[n.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium px-4 py-2 bg-muted/30",children:"Pad count"}),n.jsxs("div",{className:"flex items-center justify-center gap-4 p-4",children:[n.jsx(Z,{type:"button",variant:"outline",size:"icon",disabled:d<=Vt,onClick:()=>r({padCount:d-1}),"aria-label":"Fewer pads",children:n.jsx(it,{className:"h-4 w-4"})}),n.jsx("span",{className:"tabular-nums text-lg font-medium w-8 text-center",children:d}),n.jsx(Z,{type:"button",variant:"outline",size:"icon",disabled:d>=Et,onClick:()=>r({padCount:d+1}),"aria-label":"More pads",children:n.jsx(rt,{className:"h-4 w-4"})})]})]}),w&&n.jsxs("div",{className:"border-t",children:[n.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium px-4 py-2 bg-muted/30",children:"Pad display"}),n.jsx("div",{className:"p-3",children:n.jsx(Z,{variant:S?"default":"outline",size:"sm",className:"w-full",onClick:()=>r({planePolar:!S}),children:"R/θ"})})]}),n.jsxs("div",{className:"border-t",children:[n.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium px-4 py-2 bg-muted/30",children:"Control range"}),n.jsxs(he,{items:Je,value:i,onValueChange:m=>{m!=null&&r({rangeMode:m})},children:[n.jsx(me,{className:"border-0 rounded-none h-11",children:n.jsx(fe,{})}),n.jsx(pe,{children:Je.map(m=>n.jsx(xe,{value:m.value,children:m.label},m.value))})]})]}),n.jsxs("div",{className:"border-t",children:[n.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium px-4 py-2 bg-muted/30",children:"Value range"}),n.jsx(Ht,{min:s.range[0],max:s.range[1],onCommit:(m,b)=>r({range:[m,b]})})]})]})})}function q(s,e){const t=v.useRef(null),r=v.useRef(new Map),a=$(s),i=$(e);return{begin:l=>(r.current.set(l.pointerId,{clientX:l.clientX,clientY:l.clientY}),l.currentTarget.setPointerCapture(l.pointerId),t.current===null?(t.current=l.pointerId,a.current(!0),"primary"):"secondary"),end:l=>{if(!r.current.has(l.pointerId))return{kind:"ignored"};if(r.current.delete(l.pointerId),l.currentTarget.hasPointerCapture(l.pointerId)&&l.currentTarget.releasePointerCapture(l.pointerId),t.current!==l.pointerId)return{kind:"ignored"};const d=r.current.entries().next();if(d.done)return t.current=null,a.current(!1),{kind:"ended"};const[x,w]=d.value;return t.current=x,i.current?.(),{kind:"retargeted",pointerId:x,clientX:w.clientX,clientY:w.clientY}},noteMove:l=>{r.current.has(l.pointerId)&&r.current.set(l.pointerId,{clientX:l.clientX,clientY:l.clientY})},isDragging:()=>t.current!==null,isActive:l=>t.current===l.pointerId,activePointerIdRef:t}}function vn(s,e){const t=s.nativeEvent;if(typeof t.getCoalescedEvents=="function")for(const r of t.getCoalescedEvents())e(r.clientX,r.clientY);else e(s.clientX,s.clientY)}function ot({x:s,y:e,range:t,rangeMode:r,planePolar:a=!1,onChange:i,onEditing:c,onArmJump:o,immersive:u=!1,framed:h=!0,className:f,children:l}){const d=v.useRef(null),x=v.useRef(null),w=v.useRef(null),S=q(c,o),m=Yt(r),b=t[0],k=t[1],g=v.useCallback(()=>
1{if(!w.current||!d.current||!x.current)return;const j=d.current.getBoundingClientRect(),C=x.current.getBoundingClientRect(),M=j.left+j.width/2,W=j.top+j.height/2,R=C.left+C.width/2-M,T=C.top+C.height/2-W,A=Math.sqrt(R*R+T*T),p=Math.atan2(T,R)*(180/Math.PI);w.current.style.width=`${A}px`,w.current.style.transform=`translateY(-50%) rotate(${p}deg)`},[]),y=v.useCallback(()=>{const j=[b,k],{left:C,top:M}=Ee(s,e,m,j);x.current&&(x.current.style.left=`${C*100}%`,x.current.style.top=`${M*100}%`),a&&g()},[s,e,m,b,k,a,g]),P=(j,C)=>{const M=d.current;if(!M||!x.current)return;const W=M.getBoundingClientRect(),R=ge(j,C,W,m,t),{left:T,top:A}=Ee(R.x,R.y,m,t);x.current.style.left=`${T*100}%`,x.current.style.top=`${A*100}%`,a&&g()};v.useEffect(()=>{S.isDragging()||y()},[y,S]);const L=(j,C)=>{const M=d.current;if(!M)return;const W=M.getBoundingClientRect();P(j,C);const R=ge(j,C,W,m,t);i(R.x,R.y)},N=j=>{const C=S.end(j);C.kind==="retargeted"&&L(C.clientX,C.clientY)};return n.jsxs("div",{ref:d,className:ee("relative select-none touch-none overflow-hidden cursor-crosshair",u?ee("h-full w-full bg-black/20",h&&"border border-white/25"):"aspect-square w-full rounded-lg border border-white/25 bg-black/20 backdrop-blur-md",f),style:{touchAction:"none"},onPointerDown:j=>{j.preventDefault(),j.stopPropagation(),S.begin(j)==="primary"&&L(j.clientX,j.clientY)},onPointerMove:j=>{if(S.noteMove(j),!S.isActive(j))return;const C=d.current;if(!C)return;const M=C.getBoundingClientRect();vn(j,(W,R)=>{P(W,R);const T=ge(W,R,M,m,t);i(T.x,T.y)})},onPointerUp:N,onPointerCancel:N,onLostPointerCapture:N,children:[n.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:n.jsx("div",{className:"h-full w-full rounded-full border-2 border-dashed border-white/40"})}),n.jsxs("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:[n.jsx("div",{className:"absolute w-full h-px bg-white/30"}),n.jsx("div",{className:"absolute h-full w-px bg-white/30"})]}),n.jsx("div",{ref:w,className:ee("absolute top-1/2 left-1/2 h-[2px] bg-white origin-left pointer-events-none",!a&&"opacity-0")}),n.jsx("div",{ref:x,className:ee("absolute rounded-full bg-white shadow-lg pointer-events-none -translate-x-1/2 -translate-y-1/2",u?"h-6 w-6":"h-2 w-2")}),l]})}function wn(){return"ondevicemotion"in window||"LinearAccelerationSensor"in window}function jn(){return Ne(wn)}function Ye(s,e,t){return Math.sqrt(s*s+e*e+t*t)}function Sn(s){const e=on(s,{attack:.4,release:.1}),t=[];let r=!1;if("ondevicemotion"in window){const i=c=>{if(r)return;const o=c.acceleration;!o||o.x==null||o.y==null||o.z==null||[o.x,o.y,o.z].every(Number.isFinite)&&e(Fe(Ye(o.x,o.y,o.z)))};window.addEventListener("devicemotion",i),t.push(()=>window.removeEventListener("devicemotion",i))}const a=window.LinearAccelerationSensor;if(a){let i=null;try{i=new a({frequency:60});const c=()=>{r=!0;const o=i?.x,u=i?.y,h=i?.z;o==null||u==null||h==null||[o,u,h].every(Number.isFinite)&&e(Fe(Ye(o,u,h)))};i.addEventListener("reading",c),i.start(),t.push(()=>{i?.removeEventListener("reading",c),i?.stop(),i=null,r=!1})}catch{i?.stop(),r=!1}}return()=>{for(const i of t)i()}}function Nn(){return"ondevicemotion"in window}function Cn(){return Ne(Nn)}function kn(s){const e=cn(s,{attack:.35,release:.12}),t=r=>{const a=r.rotationRate;a&&(a.gamma==null||a.beta==null||a.alpha==null||[a.gamma,a.beta,a.alpha].every(Number.isFinite)&&e(Kt(a.gamma,a.beta,a.alpha)))};return window.addEventListener("devicemotion",t),()=>window.removeEventListener("devicemotion",t)}function ae(s){return window[s]}function Pn(){return!!ae("RelativeOrientationSensor")||!!ae("AbsoluteOrientationSensor")||"ondeviceorientation"in window}function Ln(){return Ne(Pn)}function Rn(s){let e=null,t=null,r=null;return a=>{let i=Qe(a);if(t&&(i=ze(t,i)),t=D(i),e===null){e=D(i),r=D(Ae),s(D(Ae));return}let c=Ot(e,i);r&&(c=ze(r,c)),r=D(c),s(c)}}function Mn(s,e=[0,0,0,1]){const t=s.quaternion;if(!t||t.length<4)return null;const r=t[0],a=t[1],i=t[2],c=t[3];return typeof r!="number"||typeof a!="number"||typeof i!="number"||typeof c!="number"||![r,a,i,c].every(Number.isFinite)?null:Qe([r,a,i,c],e)}function Ke(s,e){let t;try{t=new s({frequency:60,referenceFrame:"screen"})}catch{return null}const r=()=>{const i=Mn(t);i&&e(i)},a=()=>{};t.addEventListener("reading",r),t.addEventListener("error",a);try{t.start()}catch{return t.removeEventListener("reading",r),t.removeEventListener("error",a),null}return()=>{t.removeEventListener("reading",r),t.removeEventListener("error",a);try{t.stop()}catch{}}}
1function Wn(s){const e=Rn(s),t=ae("RelativeOrientationSensor");if(t){const i=Ke(t,e);if(i)return i}const r=ae("AbsoluteOrientationSensor");if(r){const i=Ke(r,e);if(i)return i}const a=i=>{i.gamma==null||i.beta==null||i.alpha==null||[i.gamma,i.beta,i.alpha].every(Number.isFinite)&&e(Ft(i.alpha,i.beta,i.gamma))};return window.addEventListener("deviceorientation",a),()=>window.removeEventListener("deviceorientation",a)}function Tn(s){switch(U(s)){case"xypad":case"xypadVec2":case"dualPad":return!0;default:return!1}}function qe(s){switch(U(s)){case"slider":case"knob":case"pads":case"multislider":case"dualSlider":case"quadSliderComplex":case"xypad":case"xypadVec2":case"dualPad":case"sphere":case"color":return!0;default:return!1}}function U(s){if(s.boolean)return"toggle";switch(Ge(s,s.widgetType)){case"slider":return s.type==="vec2"&&!s.complex?"slider":"multislider";case"knob":return"knob";case"pads":return"pads";case"accelerometer":return"accelerometer";case"rotation":return"rotation";case"gyroscope":return"gyroscope";case"sphere":return s.type==="cvec4"&&!s.complex?"rotation":"sphere";case"color":return"color";case"plane":return s.complex?"xypad":"xypadVec2";case"dualSlider":return s.type==="vec2"?"dualSlider":"multislider";case"dualPlane":return"dualPad";case"quadSlider":return s.complex?"quadSliderComplex":"multislider"}return s.type!=="vec2"?"multislider":"unsupported"}function In(s){return Tn(s)}const zn=["Roll","Pitch","Yaw"],E=(s,e,t)=>Math.max(e,Math.min(t,s));function O(s){return s.toFixed(3)}function oe({children:s,className:e}){return n.jsx("span",{className:`pointer-events-none font-mono text-sm font-semibold tabular-nums text-white mix-blend-difference ${e??""}`,children:s})}function ct(s,e){const t=typeof s.nativeEvent.getCoalescedEvents=="function"?s.nativeEvent.getCoalescedEvents():[s.nativeEvent];for(const r of t)e(r.clientX,r.clientY)}function An(s){switch(U(s.schema)){case"toggle":return n.jsx(Qn,{...s});case"color":return n.jsx(ls,{...s});case"xypad":return n.jsx(On,{...s});case"xypadVec2":return n.jsx(Bn,{...s});case"slider":return n.jsx(Vn,{...s});case"knob":return n.jsx(En,{...s});case"pads":return n.jsx($n,{...s});case"accelerometer":return n.jsx(Dn,{...s});case"rotation":return n.jsx(Hn,{...s});case"gyroscope":return n.jsx(Yn,{...s});case"sphere":return n.jsx(qn,{...s});case"dualSlider":return n.jsx(Un,{...s});case"dualPad":return n.jsx(Xn,{...s});case"quadSliderComplex":return n.jsx(Gn,{...s});case"multislider":return n.jsx(Fn,{...s});default:return n.jsx("p",{className:"text-xs text-zinc-400 py-4 text-center",children:"This parameter type isn't supported on phone yet — control it on the desktop."})}}function B({value:s,min:e,max:t,onChange:r,onEditing:a,onArmJump:i}){const c=v.useRef(null),o=v.useRef(null),u=v.useRef(null),{begin:h,end:f,noteMove:l,isActive:d,activePointerIdRef:x}=q(a,i),w=g=>E((g-e)/(t-e||1),0,1)*100,S=g=>{const y=w(g);o.current&&(o.current.style.width=`${y}%`),u.current&&(u.current.style.left=`${y}%`)};v.useLayoutEffect(()=>{if(x.current!==null)return;const g=E((s-e)/(t-e||1),0,1)*100;o.current&&(o.current.style.width=`${g}%`),u.current&&(u.current.style.left=`${g}%`)},[s,e,t,x]);const m=g=>{const y=c.current;if(!y)return s;const P=y.getBoundingClientRect();return e+E((g-P.left)/P.width,0,1)*(t-e)},b=g=>{S(g),r(g)},k=g=>{const y=f(g);y.kind==="retargeted"&&b(m(y.clientX))};return n.jsxs("div",{ref:c,className:"relative h-14 rounded-xl bg-zinc-800 overflow-hidden cursor-pointer select-none touch-none",onPointerDown:g=>{h(g)==="primary"&&b(m(g.clientX))},onPointerMove:g=>{l(g),d(g)&&ct(g,y=>{b(m(y))})},onPointerUp:k,onPointerCancel:k,onLostPointerCapture:k,children:[n.jsx("div",{ref:o,className:"absolute inset-y-0 left-0 bg-white/70",style:{width:`${w(s)}%`}}),n.jsx("div",{ref:u,className:"absolute inset-y-0 w-1.5 bg-white -translate-x-1/2",style:{left:`${w(s)}%`}})]})}function Vn({schema:s,value:e,onChange:t,onEditing:r,onArmJump:a}){const[i,c]=F(s.range),o=typeof e=="number"?e:i;return n.jsxs("div",{children:[n.jsxs("div",{className:"flex justify-between text-xs text-zinc-400 mb-1",children:[n.jsx("span",{children:i}),n.jsx("span",{className:"text-zinc-200 font-mono",children:o.toFixed(3)}),n.jsx("span",{children:c})]}),n.jsx(B,{value:o,min:i,max:c,onChange:t,onEditing:r,onArmJump:a})]})}function Ue({value:s,min:e,max:t,label:r,onChange:a,onEditing:i,onArmJump:c}){const o=t-e||1,h=225+E((s-e)/o,0,1)*270,f=v.useRef(0),l=v.useRef(0),d=S=>{S.currentTarget.setPointerCapture(S.pointerId),f.current=S.clientY,l.current=s,c(),i(!0)},x=S=>
1{if(!S.currentTarget.hasPointerCapture(S.pointerId))return;const m=f.current-S.clientY,b=E(l.current+m/140*o,e,t);a(b)},w=S=>{S.currentTarget.hasPointerCapture(S.pointerId)&&S.currentTarget.releasePointerCapture(S.pointerId),i(!1)};return n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r?n.jsx("span",{className:"text-xs text-zinc-400",children:r}):null,n.jsx("div",{className:"relative h-28 w-28 touch-none select-none rounded-full border border-white/20 bg-white/10",style:{touchAction:"none"},onPointerDown:d,onPointerMove:x,onPointerUp:w,onPointerCancel:w,children:n.jsx("div",{className:"absolute left-1/2 top-3 h-5 w-1.5 -translate-x-1/2 rounded-full bg-white/80",style:{transformOrigin:"center 44px",transform:`translateX(-50%) rotate(${h}deg)`}})}),n.jsx("span",{className:"font-mono text-sm tabular-nums text-zinc-200",children:s.toFixed(3)})]})}function En({schema:s,value:e,componentValues:t,onChange:r,onComponentChange:a,onEditing:i,onArmJump:c}){const[o,u]=F(s.range),h=s.componentLabels??[],f=Math.max(t.length,h.length,s.type==="vec2"?1:0);if(s.type==="vec2"&&!s.complex){const l=typeof e=="number"?e:o;return n.jsx("div",{className:"flex justify-center py-2",children:n.jsx(Ue,{value:l,min:o,max:u,onChange:r,onEditing:i,onArmJump:c})})}return n.jsx("div",{className:`grid gap-4 ${f>2?"grid-cols-2":"grid-cols-1"}`,children:Array.from({length:f},(l,d)=>n.jsx(Ue,{label:h[d]??`#${d}`,value:t[d]??o,min:o,max:u,onChange:x=>a(d,x),onEditing:i,onArmJump:c},d))})}function Fn({schema:s,componentValues:e,onComponentChange:t,onEditing:r,onArmJump:a}){const[i,c]=F(s.range),o=e.length||s.componentLabels?.length||0,u=s.componentLabels??[];return n.jsx("div",{className:"flex flex-col gap-3",children:Array.from({length:o},(h,f)=>{const l=e[f]??i;return n.jsxs("div",{children:[n.jsxs("div",{className:"flex justify-between text-xs text-zinc-400 mb-1",children:[n.jsx("span",{children:u[f]??`#${f}`}),n.jsx("span",{className:"text-zinc-200 font-mono",children:l.toFixed(3)})]}),n.jsx(B,{value:l,min:i,max:c,onChange:d=>t(f,d),onEditing:r,onArmJump:a})]},f)})})}function On({schema:s,value:e,onChange:t,onEditing:r,onArmJump:a}){const i=e&&typeof e=="object"&&"re"in e?e:{re:0,im:0};return n.jsx(ke,{x:i.re,y:i.im,rangeMode:s.rangeMode,range:s.range,planePolar:s.planePolar,onChange:(c,o)=>t({re:c,im:o}),onEditing:r,onArmJump:a,formatLabel:(c,o)=>`re ${c.toFixed(2)} · im ${o.toFixed(2)}`})}function Y({label:s,value:e,min:t,max:r,onChange:a,onEditing:i,onArmJump:c}){const o=v.useRef(null);return v.useEffect(()=>{o.current&&(o.current.textContent=e.toFixed(3))},[e]),n.jsxs("div",{children:[n.jsxs("div",{className:"flex justify-between text-xs text-zinc-400 mb-1",children:[n.jsx("span",{children:s}),n.jsx("span",{ref:o,className:"text-zinc-200 font-mono",children:e.toFixed(3)})]}),n.jsx(B,{value:e,min:t,max:r,onChange:u=>{o.current&&(o.current.textContent=u.toFixed(3)),a(u)},onEditing:i,onArmJump:c})]})}function $n({schema:s,value:e,componentValues:t,onChange:r,onArmJump:a,onPatchSchema:i}){const[c,o]=F(s.range),u=o-c||1,h=ie(s.padCount),f=s.type==="cvec2"&&!s.complex,l=f?t[0]??c:typeof e=="number"?e:c,[d,x]=v.useState(null),w=N=>{N&&a()},{begin:S,end:m}=q(w,a),k=E(Math.round(((d!==null&&d!==l?d:l)-c)/u*(h-1)),0,h-1),g=N=>{x(N),r(f?[N,t[1]??0]:N)},y=v.useRef(new Map),P=N=>{y.current.delete(N.pointerId);const j=m(N);if(j.kind==="retargeted"){const C=y.current.get(j.pointerId);C!==void 0&&g(C)}},L=N=>{i({padCount:ie(N)})};return n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"flex items-stretch gap-1",children:Array.from({length:h},(N,j)=>{const C=c+j/(h-1)*u,M=j===k;return n.jsx("button",{type:"button","aria-label":`Set to ${C.toFixed(2)}`,className:`h-16 min-w-0 flex-1 rounded-lg border transition-all ${M?"border-white ring-2 ring-white brightness-125":"border-white/15"}`,style:{backgroundColor:`hsl(${Ze(C,c,o)} 85% 55%)`},onPointerDown:W=>{const R=S(W);y.current.set(W.pointerId,C),R==="primary"&&g(C)},onPointerUp:P,onPointerCancel:P,onLostPointerCapture:P},j)})}),n.jsxs("div",{className:"flex items-center justify-center gap-3 text-sm text-zinc-300",children:[n.jsx("button",{type:"button",className:"rounded-lg bg-zinc-800 p-2 active:bg-zinc-700",onClick:()=>L(h-1),"aria-label":"Fewer pads",children:n.jsx(it,{className:"h-4 w-4"})}),n.jsx("span",{className:"tabular-nums w-8 text-center",children:h}),n.jsx("button",{type:"button",className:"rounded-lg bg-zinc-800 p-2 active:bg-zinc-700",onClick:()=>L(h+1),"aria-label":"More pads",children:n.jsx(rt,{className:"h-4 w-4"})})]})]})}
1function _n({schema:s,value:e,onChange:t,onEditing:r,capability:a,subscribe:i,normToScalar:c,startLabel:o,activeHint:u,unsupportedHint:h,httpsHint:f}){const[l,d]=Se(s.rangeMode,s.range),x=typeof e=="number"?e:l,[w,S]=v.useState(!1),[m,b]=v.useState(!1),[k,g]=v.useState(x),y=$(t),P=$({min:l,max:d}),L=w?k:x,N=v.useCallback(async()=>{if(_()&&!await Ce()){b(!0);return}b(!1),S(!0)},[]);return v.useEffect(()=>{if(!w)return;r(!0);const j=i(C=>{const{min:M,max:W}=P.current,R=c(C,M,W);g(R),y.current(R)});return()=>{j(),r(!1)}},[w,c,r,i,P,y]),n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex justify-between text-xs text-zinc-400 mb-1",children:[n.jsx("span",{children:l}),n.jsx("span",{className:"text-zinc-200 font-mono",children:L.toFixed(3)}),n.jsx("span",{children:d})]}),n.jsx("div",{className:"pointer-events-none",children:n.jsx(B,{value:L,min:l,max:d,onChange:()=>{},onEditing:()=>{},onArmJump:()=>{}})}),a==="ready"&&!w&&!m&&n.jsx("button",{type:"button",className:"w-full rounded-xl bg-white text-zinc-900 py-3 font-semibold active:bg-zinc-200",onClick:()=>{N()},children:o}),a==="needs-https"&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:f}),m&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:"Motion access was denied. Allow it in browser settings to use this control."}),a==="unsupported"&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:h}),w&&n.jsx("p",{className:"text-xs text-zinc-500 text-center",children:u})]})}function Dn(s){return n.jsx(_n,{...s,capability:jn(),subscribe:Sn,normToScalar:qt,startLabel:_()?"Enable motion":"Start accelerometer",activeHint:"Shake or move the phone to adjust",unsupportedHint:"Accelerometer control isn't available on this device.",httpsHint:"Accelerometer control needs a secure connection. Open the controller link over HTTPS."})}function Jn({schema:s,componentValues:e,onChange:t,onEditing:r,capability:a,subscribe:i,startLabel:c,activeHint:o,unsupportedHint:u,httpsHint:h}){const[f,l]=Se(s.rangeMode,s.range),d=[e[0]??f,e[1]??f,e[2]??f],[x,w]=v.useState(!1),[S,m]=v.useState(!1),[b,k]=v.useState(d),g=$(t),y=$(s),P=d[0],L=d[1],N=d[2],j=x?b:[P,L,N],C=v.useCallback(async()=>{if(_()&&!await Ce()){m(!0);return}m(!1),k([P,L,N]),w(!0)},[P,L,N]);return v.useEffect(()=>{if(!x)return;r(!0);const M=i(W=>{const R=Ut(W,y.current.rangeMode,y.current.range);k(R),g.current(R)});return()=>{M(),r(!1)}},[x,r,i,g,y]),n.jsxs("div",{className:"flex flex-col gap-3",children:[zn.map((M,W)=>n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("div",{className:"flex justify-between text-xs text-zinc-400",children:[n.jsx("span",{children:M}),n.jsx("span",{className:"text-zinc-200 font-mono",children:j[W].toFixed(3)})]}),n.jsx("div",{className:"pointer-events-none",children:n.jsx(B,{value:j[W],min:f,max:l,onChange:()=>{},onEditing:()=>{},onArmJump:()=>{}})})]},M)),a==="ready"&&!x&&!S&&n.jsx("button",{type:"button",className:"w-full rounded-xl bg-white text-zinc-900 py-3 font-semibold active:bg-zinc-200",onClick:()=>{C()},children:c}),a==="needs-https"&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:h}),S&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:"Motion access was denied. Allow it in browser settings to use this control."}),a==="unsupported"&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:u}),x&&n.jsx("p",{className:"text-xs text-zinc-500 text-center",children:o})]})}function Hn({componentValues:s,onChange:e,onEditing:t}){const r=Ln(),[a,i]=v.useState(!1),[c,o]=v.useState(!1),u=$(e),h=s[0]??0,f=s[1]??0,l=s[2]??0,d=s[3]??1,[x,w]=v.useState(()=>[h,f,l,d]),S=a?x:[h,f,l,d],m=v.useCallback(async()=>{if(_()&&!await Ce()){o(!0);return}o(!1),w([h,f,l,d]),i(!0)},[h,f,l,d]);return v.useEffect(()=>{if(!a)return;t(!0);const b=Wn(k=>{w(k),u.current([k[0],k[1],k[2],k[3]])});return()=>{b(),t(!1)}},[a,t,u]),n.jsxs("div",{className:"flex flex-col gap-3",children:[["X","Y","Z","W"].map((b,k)=>n.jsxs("div",{className:"flex justify-between text-xs text-zinc-400",children:[n.jsx("span",{children:b}),n.jsx("span",{className:"text-zinc-200 font-mono",children:S[k].toFixed(3)})]},b)),r==="ready"&&!a&&!c&&n.jsx("button",{type:"button",className:"w-full rounded-xl bg-white text-zinc-900 py-3 font-semibold active:bg-zinc-200",onClick:()=>{m()},children:_()?"Enable motion":"Start rotation"}),r==="needs-https"&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:"Rotation control needs a secure connection. Open the controller link over HTTPS."}),c&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:"Motion access was denied. Allow it in browser settings to use this control."}),r==="unsupported"&&n.jsx("p",{className:"text-xs text-zinc-400 text-center",children:"Rotation control isn't available on this device."}),a&&n.jsx("p",{className:"text-xs text-zinc-500 text-center",children:"Tilt and turn the phone to drive orientation"})]})}function Yn(s){return n.jsx(Jn,{...s,capability:Cn(),subscribe:kn,startLabel:_()?"Enable motion":"Start gyroscope",activeHint:"Spin the phone to drive roll, pitch, and yaw rates",unsupportedHint:"G
1yroscope control isn't available on this device.",httpsHint:"Gyroscope control needs a secure connection. Open the controller link over HTTPS."})}function Kn(s,e,t,r,a){const i=Math.sqrt(s*s+e*e+t*t)||1,c=s/i,o=e/i,u=t/i,h=r??"unit";if(h==="unit")return[c,o,u];if(h==="full")return[c,o,u];const[f,l]=Se(h,a),d=(f+l)/2,x=(l-f)/2||1;return[d+c*x,d+o*x,d+u*x]}function qn({schema:s,componentValues:e,onChange:t,onEditing:r,onArmJump:a}){const i=v.useRef(null),c=v.useRef(.6),o=v.useRef(.4),u=v.useRef(!1),h=v.useRef({x:0,y:0}),f=v.useRef(!1),l=e[0]??0,d=e[1]??0,x=e[2]??1,w=v.useCallback(()=>{const m=i.current;if(!m)return;const b=m.getContext("2d");if(!b)return;const k=window.devicePixelRatio||1,g=m.clientWidth;if(g<=0)return;(m.width!==Math.round(g*k)||m.height!==Math.round(g*k))&&(m.width=Math.round(g*k),m.height=Math.round(g*k)),b.setTransform(k,0,0,k,0,0);const y=g,P=y/2,L=y/2,N=y*.38;b.clearRect(0,0,y,y),b.beginPath(),b.arc(P,L,N,0,Math.PI*2),b.fillStyle="rgba(255,255,255,0.06)",b.fill(),b.strokeStyle="rgba(255,255,255,0.25)",b.lineWidth=1.5,b.stroke();const j=c.current,C=o.current,M=(T,A,p)=>{const I=Math.cos(j),V=Math.sin(j),X=Math.cos(C),G=Math.sin(C),lt=T*I-p*V,Le=T*V+p*I,ut=A*X-Le*G,dt=A*G+Le*X;return{x:P+lt*N,y:L-ut*N,depth:dt}};b.strokeStyle="rgba(255,255,255,0.12)",b.lineWidth=1;for(let T=0;T<6;T++){const A=T/6*Math.PI;b.beginPath();for(let p=0;p<=64;p++){const I=p/64*Math.PI*2,V=M(Math.cos(I)*Math.sin(A),Math.sin(I)*Math.sin(A),Math.cos(A));p===0?b.moveTo(V.x,V.y):b.lineTo(V.x,V.y)}b.stroke()}const W=Math.sqrt(l*l+d*d+x*x)||1,R=M(l/W,d/W,x/W);b.beginPath(),b.moveTo(P,L),b.lineTo(R.x,R.y),b.strokeStyle="rgba(255,255,255,0.55)",b.lineWidth=2,b.stroke(),b.beginPath(),b.arc(R.x,R.y,7,0,Math.PI*2),b.fillStyle=R.depth>=0?"rgb(96, 165, 250)":"rgba(96, 165, 250, 0.45)",b.fill()},[l,d,x]);v.useEffect(()=>{w()},[w]);const S=(m,b)=>{const k=i.current;if(!k)return;const g=k.getBoundingClientRect(),y=g.width,P=(m-g.left-y/2)/(y*.38),L=-(b-g.top-y/2)/(y*.38);if(P*P+L*L>1)return;const N=Math.sqrt(Math.max(0,1-P*P-L*L)),j=c.current,C=o.current,M=Math.cos(-j),W=Math.sin(-j),R=Math.cos(-C),T=Math.sin(-C),A=L*R+N*T;let p=-L*T+N*R;const I=P*M+p*W;p=-P*W+p*M;const[V,X,G]=Kn(I,A,p,s.rangeMode,s.range);t(je(s.type,s.complex,[V,X,G],[0,0,0]))};return n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("div",{className:"flex justify-between font-mono text-xs text-zinc-400",children:[n.jsxs("span",{children:["X ",l.toFixed(2)]}),n.jsxs("span",{children:["Y ",d.toFixed(2)]}),n.jsxs("span",{children:["Z ",x.toFixed(2)]})]}),n.jsx("canvas",{ref:i,className:"aspect-square w-full touch-none rounded-2xl bg-zinc-900/60",style:{touchAction:"none"},onPointerDown:m=>{m.currentTarget.setPointerCapture(m.pointerId),u.current=!0,f.current=!1,h.current={x:m.clientX,y:m.clientY},a(),r(!0)},onPointerMove:m=>{if(!u.current)return;const b=m.clientX-h.current.x,k=m.clientY-h.current.y;Math.abs(b)+Math.abs(k)>3&&(f.current=!0),h.current={x:m.clientX,y:m.clientY},c.current+=b*.01,o.current=E(o.current+k*.01,-1.2,1.2),w()},onPointerUp:m=>{m.currentTarget.hasPointerCapture(m.pointerId)&&m.currentTarget.releasePointerCapture(m.pointerId),u.current&&!f.current&&S(m.clientX,m.clientY),u.current=!1,r(!1)},onPointerCancel:m=>{u.current=!1,r(!1),m.currentTarget.hasPointerCapture(m.pointerId)&&m.currentTarget.releasePointerCapture(m.pointerId)}}),n.jsx("p",{className:"text-center text-xs text-zinc-500",children:"Drag to orbit · tap to set direction"})]})}function Un({schema:s,value:e,onChange:t,onEditing:r,onArmJump:a}){const[i,c]=F(s.range),o=e&&typeof e=="object"&&"re"in e?e:{re:0,im:0};return n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx(Y,{label:"Re",value:o.re,min:i,max:c,onChange:u=>t({re:u,im:o.im}),onEditing:r,onArmJump:a}),n.jsx(Y,{label:"Im",value:o.im,min:i,max:c,onChange:u=>t({re:o.re,im:u}),onEditing:r,onArmJump:a})]})}function ke({x:s,y:e,rangeMode:t,range:r,planePolar:a,onChange:i,onEditing:c,onArmJump:o,formatLabel:u}){const h=v.useRef(null);return v.useEffect(()=>{h.current&&(h.current.textContent=u(s,e))},[s,e,u]),n.jsxs("div",{className:"select-none touch-none",children:[n.jsx("div",{ref:h,className:"text-xs text-zinc-400 mb-1 font-mono text-center",children:u(s,e)}),n.jsx(ot,{x:s,y:e,range:r,rangeMode:t,planePolar:a,onChange:(f,l)=>{h.current&&(h.current.textContent=u(f,l)),i(f,l)},onEditing:c,onArmJump:o})]})}function Bn({schema:s,componentValues:e,onChange:t,onEditing:r,onArmJump:a}){const i=e[0]??0,c=e[1]??0;return n.jsx(ke,{x:i,y:c,rangeMode:s.rangeMode,range:s.range,planePolar:s.planePolar,onChange:(o,u)=>t([o,u]),onEditing:r,onArmJump:a,formatLabel:(o,u)=>`x ${o.toFixed(2)} · y ${u.toFixed(2)}`})}function Xn({schema:s,componentValues:e,componentValuesIm:t,onComponentChange:r,onComponentComplexChange:a,onEditing:i,onArmJump:c}){const o=s.type==="cvec2"&&s.complex,u=s.componentLabels??[],h=o?[0,1].map(f=>({key:f,x:e[f]??0,y:t[f]??0,label:u[f]??(f===0?"X":"Y"),onChange:(l,d)=>a(f,{re:l,im:d})})):[0,1].map(f=>{const l=f*2;return{key:f,x:e[l]??0,y:e[l+1]??0,label:`${u[l]??"?"}/${u[l+1]??"?"}`,onChange:(d,x)=>{r(l,d),r(l+1,x)}}});return n.jsx("div",{className:"grid grid-cols-2 gap-3",children:h.map(f=>n.jsx(ke,{x:f.x,y:f.y,rangeMode:s.rangeMode,range:s.range,planePolar:s.planePolar,onChange:f.onChange,onEditing:i,onArmJump:c,formatLabel:(l,d)=>`${f.label}: ${l.toFixed(2)}, ${d.toFixed(2)}`},f.key))})}function Gn({schema:s,componentValues:e,componentValuesIm:t,onComponentChange:r,onComponentComplexChange:a,onEditing:i,onArmJump:c}){const[o,u]=F(s.range),h=s.componentLabels??[];return n.jsx("div",{className:"flex flex-col gap-3",children:[0,1].map(f=>{const l=e[f]??0,d=t[f]??0,x=h[f]??`#${f}`;return n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx(Y,{label:`${x} Re`,value:l,min:o,max:u,onChange:w=>r(f,w),onEditing:i,onArmJump:c}),n.jsx(Y,{label:`${x} Im`,value:d,min:o,max:u,onChange:w=>a(f,{re:e[f]??0,im:w}),onEditing:i,onArmJump:c})]},f)})})}function Qn({value:s,onChange:e}){const t=typeof s=="number"&&s>=.5;return n.jsx("button",{className:`w-full h-16 rounded-xl font-semibold text-lg transition-colors ${t?"bg-white text-zinc-900":"bg-zinc-800 text-zinc-400"}`,onClick:()=>e(t?0:1),children:t?"ON":"OFF"})}function K({value:s,min:e,max:t,landscape:r,onChange:a,onEditing:i,onArmJump:c}){const o=v.useRef(null),u=v.useRef(null),h=v.useRef(null),{begin:f,end:l,noteMove:d,isActive:x,activePointerIdRef:w}
1=q(i,c),S=y=>E((y-e)/(t-e||1),0,1)*100,m=y=>{const P=S(y);u.current&&(r?(u.current.style.width=`${P}%`,u.current.style.height="100%"):(u.current.style.height=`${P}%`,u.current.style.width="100%")),h.current&&(h.current.textContent=O(y))};v.useLayoutEffect(()=>{if(w.current!==null)return;const y=E((s-e)/(t-e||1),0,1)*100;u.current&&(r?(u.current.style.width=`${y}%`,u.current.style.height="100%"):(u.current.style.height=`${y}%`,u.current.style.width="100%")),h.current&&(h.current.textContent=O(s))},[s,e,t,r,w]);const b=(y,P)=>{const L=o.current;if(!L)return s;const N=L.getBoundingClientRect();if(r)return e+E((y-N.left)/N.width,0,1)*(t-e);const j=1-E((P-N.top)/N.height,0,1);return e+j*(t-e)},k=y=>{m(y),a(y)},g=y=>{const P=l(y);P.kind==="retargeted"&&k(b(P.clientX,P.clientY))};return n.jsxs("div",{ref:o,className:"relative h-full w-full bg-zinc-950 overflow-hidden cursor-pointer select-none touch-none",onPointerDown:y=>{f(y)==="primary"&&k(b(y.clientX,y.clientY))},onPointerMove:y=>{d(y),x(y)&&ct(y,(P,L)=>{k(b(P,L))})},onPointerUp:g,onPointerCancel:g,onLostPointerCapture:g,children:[n.jsx("div",{ref:u,className:`absolute bg-white ${r?"left-0 bottom-0 top-0":"left-0 right-0 bottom-0"}`,style:r?{width:`${S(s)}%`}:{height:`${S(s)}%`}}),n.jsx(oe,{className:"absolute bottom-3 left-3 z-10",children:n.jsx("span",{ref:h,children:O(s)})})]})}function Zn({schema:s,value:e,landscape:t,onChange:r,onEditing:a,onArmJump:i}){const[c,o]=F(s.range),u=typeof e=="number"?e:c;return n.jsx(K,{value:u,min:c,max:o,landscape:t,onChange:r,onEditing:a,onArmJump:i})}function es({schema:s,componentValues:e,landscape:t,onComponentChange:r,onEditing:a,onArmJump:i}){const[c,o]=F(s.range),u=e.length||s.componentLabels?.length||0;return n.jsx("div",{className:`h-full w-full flex ${t?"flex-row":"flex-col"}`,children:Array.from({length:u},(h,f)=>{const l=e[f]??c;return n.jsx("div",{className:"flex-1 min-h-0 min-w-0",children:n.jsx(K,{value:l,min:c,max:o,landscape:t,onChange:d=>r(f,d),onEditing:a,onArmJump:i})},f)})})}function ts({schema:s,value:e,landscape:t,onChange:r,onEditing:a,onArmJump:i}){const[c,o]=F(s.range),u=e&&typeof e=="object"&&"re"in e?e:{re:0,im:0};return n.jsxs("div",{className:`h-full w-full flex ${t?"flex-row":"flex-col"}`,children:[n.jsx("div",{className:"flex-1 min-h-0 min-w-0",children:n.jsx(K,{value:u.re,min:c,max:o,landscape:t,onChange:h=>r({re:h,im:u.im}),onEditing:a,onArmJump:i})}),n.jsx("div",{className:"flex-1 min-h-0 min-w-0",children:n.jsx(K,{value:u.im,min:c,max:o,landscape:t,onChange:h=>r({re:u.re,im:h}),onEditing:a,onArmJump:i})})]})}function ns({schema:s,componentValues:e,componentValuesIm:t,landscape:r,onComponentChange:a,onComponentComplexChange:i,onEditing:c,onArmJump:o}){const[u,h]=F(s.range),f=[0,1].flatMap(l=>[{key:`${l}-re`,value:e[l]??0,onChange:d=>a(l,d)},{key:`${l}-im`,value:t[l]??0,onChange:d=>i(l,{re:e[l]??0,im:d})}]);return n.jsx("div",{className:`h-full w-full flex ${r?"flex-row":"flex-col"}`,children:f.map(l=>n.jsx("div",{className:"flex-1 min-h-0 min-w-0",children:n.jsx(K,{value:l.value,min:u,max:h,landscape:r,onChange:l.onChange,onEditing:c,onArmJump:o})},l.key))})}function ss({schema:s,value:e,componentValues:t,landscape:r,onChange:a,onArmJump:i}){const[c,o]=F(s.range),u=o-c||1,h=ie(s.padCount),f=s.type==="cvec2"&&!s.complex,l=f?t[0]??c:typeof e=="number"?e:c,[d,x]=v.useState(null),w=r?"border-r border-white/25 last:border-r-0":"border-b border-white/25 last:border-b-0",S=N=>{N&&i()},{begin:m,end:b}=q(S,i),k=d!==null&&d!==l?d:l,g=E(Math.round((k-c)/u*(h-1)),0,h-1),y=v.useRef(new Map),P=N=>{x(N),a(f?[N,t[1]??0]:N)},L=N=>{y.current.delete(N.pointerId);const j=b(N);if(j.kind==="retargeted"){const C=y.current.get(j.pointerId);C!==void 0&&P(C)}};return n.jsxs("div",{className:`relative h-full w-full flex ${r?"flex-row":"flex-col"}`,children:[Array.from({length:h},(N,j)=>{const C=c+j/(h-1)*u,M=j===g;return n.jsx("button",{type:"button","aria-label":`Set to ${C.toFixed(2)}`,className:`relative min-h-0 min-w-0 flex-1 p-0 transition-all ${w} ${M?"ring-2 ring-inset ring-white z-10":""}`,style:{backgroundColor:`hsl(${Ze(C,c,o)} 85% 55%)`},onPointerDown:W=>{const R=m(W);y.current.set(W.pointerId,C),R==="primary"&&P(C)},onPointerUp:L,onPointerCancel:L,onLostPointerCapture:L},j)}),n.jsx(oe,{className:"absolute bottom-3 left-3 z-20",children:O(k)})]})}function rs({landscape:s,children:e}){return n.jsx("div",{className:`flex h-full w-full ${s?"flex-row":"flex-col"}`,children:e})}function is({landscape:s,index:e,children:t}){return n.jsx("div",{className:`min-h-0 min-w-0 flex-1 ${e===0?s?"border-r border-white/25":"border-b border-white/25":""}`,children:t})}function Pe({x:s,y:e,rangeMode:t,range:r,planePolar:a,onChange:i,onEditing:c,onArmJump:o,xLabel:u,yLabel:h,framed:f=!0}){const l=v.useRef(null),d=v.useRef(null);return v.useEffect(()=>{l.current&&(l.current.textContent=O(s)),d.current&&(d.current.textContent=O(e))},[s,e]),n.jsx("div",{className:"relative h-full w-full",children:n.jsxs(ot,{immersive:!0,framed:f,x:s,y:e,range:r,rangeMode:t,planePolar:a,onChange:(x,w)=>{l.current&&(l.current.textContent=O(x)),d.current&&(d.current.textContent=O(w)),i(x,w)},onEditing:c,onArmJump:o,className:"h-full w-full",children:[n.jsxs(oe,{className:"absolute bottom-3 left-3 z-10",children:[u," ",n.jsx("span",{ref:l,children:O(s)})]}),n.jsxs(oe,{className:"absolute bottom-3 right-3 z-10",children:[h," ",n.jsx("span",{ref:d,children:O(e)})]})]})})}
1function as({schema:s,value:e,onChange:t,onEditing:r,onArmJump:a}){const i=e&&typeof e=="object"&&"re"in e?e:{re:0,im:0};return n.jsx(Pe,{x:i.re,y:i.im,rangeMode:s.rangeMode,range:s.range,planePolar:s.planePolar,onChange:(c,o)=>t({re:c,im:o}),onEditing:r,onArmJump:a,xLabel:"re",yLabel:"im"})}function os({schema:s,componentValues:e,onChange:t,onEditing:r,onArmJump:a}){const i=e[0]??0,c=e[1]??0;return n.jsx(Pe,{x:i,y:c,rangeMode:s.rangeMode,range:s.range,planePolar:s.planePolar,onChange:(o,u)=>t([o,u]),onEditing:r,onArmJump:a,xLabel:"x",yLabel:"y"})}function cs({schema:s,componentValues:e,componentValuesIm:t,onComponentChange:r,onComponentComplexChange:a,onEditing:i,onArmJump:c,landscape:o}){const u=s.type==="cvec2"&&s.complex,h=s.componentLabels??[],f=u?[0,1].map(l=>({key:l,x:e[l]??0,y:t[l]??0,xLabel:"re",yLabel:"im",onChange:(d,x)=>a(l,{re:d,im:x})})):[0,1].map(l=>{const d=l*2;return{key:l,x:e[d]??0,y:e[d+1]??0,xLabel:h[d]??`c${d}`,yLabel:h[d+1]??`c${d+1}`,onChange:(x,w)=>{r(d,x),r(d+1,w)}}});return n.jsx(rs,{landscape:o,children:f.map((l,d)=>n.jsx(is,{landscape:o,index:d,children:n.jsx(Pe,{x:l.x,y:l.y,rangeMode:s.rangeMode,range:s.range,planePolar:s.planePolar,onChange:l.onChange,onEditing:i,onArmJump:c,xLabel:l.xLabel,yLabel:l.yLabel,framed:!1})},l.key))})}function ye(s){switch(U(s.schema)){case"slider":return n.jsx(Zn,{...s});case"pads":return n.jsx(ss,{...s});case"multislider":return n.jsx(es,{...s});case"dualSlider":return n.jsx(ts,{...s});case"quadSliderComplex":return n.jsx(ns,{...s});case"xypad":return n.jsx(as,{...s});case"xypadVec2":return n.jsx(os,{...s});case"dualPad":return n.jsx(cs,{...s});default:return null}}function ls({schema:s,value:e,onChange:t,onEditing:r,onArmJump:a}){const[i,c]=s.range,o=c-i||1,u=Array.isArray(e)?e:[i,i,i],h=d=>E(Math.round((d-i)/o*255),0,255).toString(16).padStart(2,"0"),f=`#${h(u[0]??i)}${h(u[1]??i)}${h(u[2]??i)}`,l=d=>{const x=parseInt(d.slice(1),16),w=[i+(x>>16&255)/255*o,i+(x>>8&255)/255*o,i+(x&255)/255*o];return s.type==="cvec4"?[...w,u[3]??c]:w};return n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("input",{type:"color",value:f,onChange:d=>t(l(d.target.value)),className:"w-full h-16 rounded-xl bg-zinc-800 cursor-pointer"}),s.type==="cvec4"&&n.jsx(Y,{label:"Alpha",value:u[3]??c,min:i,max:c,onChange:d=>t([u[0]??i,u[1]??i,u[2]??i,d]),onEditing:r,onArmJump:a})]})}function H({children:s}){return n.jsx("div",{className:"fixed inset-0 bg-zinc-950 text-zinc-100 flex flex-col items-center justify-center p-6 text-center",children:s})}function us(){const[s,e]=v.useState(()=>typeof window>"u"?!1:window.matchMedia("(orientation: landscape)").matches);return v.useEffect(()=>{const t=window.matchMedia("(orientation: landscape)"),r=()=>e(t.matches);return r(),t.addEventListener("change",r),window.addEventListener("resize",r),window.addEventListener("orientationchange",r),()=>{t.removeEventListener("change",r),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r)}},[]),s}function ds({open:s,onOpenChange:e,schemas:t,onSelect:r}){return n.jsx(et,{open:s,onOpenChange:e,children:n.jsxs(tt,{className:"max-w-sm gap-0 p-0 overflow-hidden",children:[n.jsx(nt,{className:"px-4 pt-4 pb-2",children:n.jsx(st,{className:"text-base",children:"Parameter settings"})}),n.jsx("div",{className:"border-t max-h-[60vh] overflow-y-auto",children:t.map(a=>n.jsx("button",{type:"button",className:"w-full text-left px-4 py-3 border-b border-border last:border-b-0 active:bg-muted",onClick:()=>{r(a),e(!1)},children:n.jsx("span",{className:"font-medium",children:a.label||a.lhs})},a.lhs))})]})})}function hs(){const s=v.useMemo(()=>new URLSearchParams(window.location.search).get("room")??"",[]),e=v.useMemo(()=>localStorage.getItem("jamroom:name")??"",[]),[t]=v.useState(()=>s?new bn(s,e):null),[r,a]=v.useState(()=>t?.snapshot??null),[i,c]=v.useState(e),[o,u]=v.useState(!1),[h,f]=v.useState(!1),[l,d]=v.useState(null),[x,w]=v.useState(!1),S=us();if(v.useEffect(()=>{const p=t;if(!p)return;const I=p.subscribe(a);return()=>{I(),p.close()}},[t]),!s)return n.jsxs(H,{children:[n.jsx(te,{className:"h-8 w-8 mb-3 text-zinc-500"}),n.jsx("p",{className:"text-lg font-medium",children:"No room code"}),n.jsx("p",{className:"text-sm text-zinc-400 mt-1",children:"Open the link or scan the QR the host is showing."})]});if(!r||!t)return null;const b=i.trim().length>0,k=()=>{const p=i.trim();p&&(localStorage.setItem("jamroom:name",p),t.connect(p))};
1if(r.phase==="name")return n.jsxs(H,{children:[n.jsx(te,{className:"h-10 w-10 mb-4 text-white"}),n.jsx("h1",{className:"text-2xl font-semibold mb-1",children:"Jam Session"}),n.jsxs("p",{className:"text-sm text-zinc-400 mb-6",children:["Room ",s]}),n.jsx("input",{value:i,onChange:p=>c(p.target.value),onKeyDown:p=>p.key==="Enter"&&b&&k(),placeholder:"Your name",maxLength:24,className:"w-full max-w-xs rounded-xl bg-zinc-800 px-4 py-3 text-center text-lg outline-none focus:ring-2 ring-white/50"}),n.jsx("button",{type:"button",onClick:k,disabled:!b,className:`mt-4 w-full max-w-xs rounded-xl py-3 font-semibold ${b?"cursor-pointer bg-white text-zinc-900 active:bg-zinc-200":"cursor-not-allowed bg-white/30 text-zinc-500"}`,children:"Join"})]});if(r.phase==="connecting")return n.jsxs(H,{children:[n.jsx($t,{className:"size-10 text-white"}),n.jsxs("p",{className:"mt-4 text-sm text-zinc-400",children:["Joining ",s,"…"]})]});if(r.phase==="kicked")return n.jsxs(H,{children:[n.jsx("p",{className:"text-lg font-medium",children:"You were removed from the session"}),r.error&&n.jsxs("div",{className:"mt-1 flex items-start justify-center gap-2",children:[n.jsx("p",{className:"text-sm text-zinc-400 select-text cursor-text",role:"alert",children:r.error}),n.jsx(Ve,{text:r.error,className:"text-zinc-400 hover:bg-white/10"})]})]});if(r.phase==="error"){const p=r.error??"Unknown error";return n.jsxs(H,{children:[n.jsx("p",{className:"text-lg font-medium text-red-400",children:"Can't join"}),n.jsxs("div",{className:"mt-1 flex items-start justify-center gap-2",children:[n.jsx("p",{className:"text-sm text-zinc-400 select-text cursor-text",role:"alert",children:p}),n.jsx(Ve,{text:p,className:"text-zinc-400 hover:bg-white/10"})]}),n.jsx("button",{onClick:()=>t.connect(r.name),className:"mt-5 rounded-xl bg-zinc-800 px-5 py-2.5 font-medium active:bg-zinc-700",children:"Try again"})]})}const g=Object.values(r.assignments),y=g.length>0&&g.every(qe)&&!x,P=g.length===1&&In(g[0]),L=g.length===1&&U(g[0])==="dualPad",N=p=>({schema:p,value:r.values[p.lhs],componentValues:r.componentValues[p.lhs]??[],componentValuesIm:r.componentValuesIm[p.lhs]??[],onChange:I=>t.setValue(p.lhs,I),onComponentChange:(I,V)=>t.setComponent(p.lhs,I,V),onComponentComplexChange:(I,V)=>t.setComponentComplex(p.lhs,I,V),onEditing:I=>t.setEditing(p.lhs,I),onArmJump:()=>t.armLanWireJump(p.lhs),onPatchSchema:I=>t.patchSchema(p.lhs,I)}),j=()=>{g.length===1?d(g[0]):f(!0)},C=r.roster.filter(p=>p.connected).length,M=o&&n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-end sm:items-center justify-center z-50",onClick:()=>u(!1),children:n.jsxs("div",{className:"bg-zinc-900 w-full sm:max-w-sm rounded-t-2xl sm:rounded-2xl p-4",onClick:p=>p.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsx("span",{className:"font-semibold",children:"In the room"}),n.jsx("button",{type:"button",onClick:()=>u(!1),children:n.jsx(Gt,{className:"h-5 w-5 text-zinc-400"})})]}),n.jsx("div",{className:"flex flex-col gap-2",children:r.roster.map(p=>n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`h-2 w-2 rounded-full ${p.connected?"bg-green-400":"bg-zinc-600"}`}),n.jsx("span",{className:p.playerId===r.playerId?"font-semibold":"",children:p.name}),p.playerId===r.playerId&&n.jsx("span",{className:"text-xs text-zinc-500",children:"(you)"})]},p.playerId))})]})}),W=n.jsxs(n.Fragment,{children:[h&&n.jsx(ds,{open:!0,schemas:g,onOpenChange:p=>{p||f(!1)},onSelect:d}),l&&n.jsx(He,{schema:r.assignments[l.lhs]??l,open:!0,onOpenChange:p=>{p||d(null)},onPatch:p=>t.patchSchema(l.lhs,p)}),M]}),R=n.jsxs("div",{className:"flex flex-col items-center gap-1 text-center min-w-0 px-4",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx(te,{className:"h-4 w-4 text-white shrink-0"}),n.jsx("span",{className:"font-semibold truncate",children:r.name})]}),n.jsx("span",{className:"text-xs text-zinc-500",children:s})]}),T="rounded-xl p-2.5 text-zinc-300 active:bg-zinc-800/80 touch-manipulation transition-colors",A=n.jsx("header",{className:`shrink-0 flex items-center justify-center gap-1 ${S?"
1w-14 flex-col py-3 border-r border-zinc-800/80 bg-zinc-950":"h-14 flex-row px-3 border-b border-zinc-800/80 bg-zinc-950"}`,children:n.jsxs("div",{className:`flex items-center gap-0.5 rounded-2xl bg-zinc-900/90 ring-1 ring-white/5 ${S?"flex-col p-1":"flex-row p-1"}`,children:[n.jsx("button",{type:"button",onClick:j,className:T,"aria-label":"Parameter settings",children:n.jsx(we,{className:"h-5 w-5"})}),n.jsx("button",{type:"button",onClick:()=>w(!0),className:T,"aria-label":"Classic layout",children:n.jsx(Xt,{className:"h-5 w-5"})}),n.jsx("div",{className:`bg-zinc-800/80 ${S?"h-px w-6 my-0.5":"w-px h-6 mx-0.5"}`,"aria-hidden":!0}),n.jsxs("button",{type:"button",onClick:()=>u(!0),className:`${T} relative`,"aria-label":"People in the room",children:[n.jsx(Oe,{className:"h-5 w-5"}),n.jsx("span",{className:"absolute -top-0.5 -right-0.5 min-w-[1.05rem] h-[1.05rem] px-1 rounded-full bg-zinc-100 text-[10px] font-semibold leading-[1.05rem] text-zinc-900 text-center tabular-nums",children:C})]})]})});if(y){const p=P&&!L;return n.jsxs("div",{className:`fixed inset-0 bg-zinc-950 text-zinc-100 flex ${S?"flex-row":"flex-col"}`,children:[A,L?n.jsx("div",{className:"flex-1 min-h-0 min-w-0",children:n.jsx(ye,{...N(g[0]),landscape:S})}):p?n.jsxs("div",{className:`flex-1 min-h-0 min-w-0 flex ${S?"flex-row":"flex-col"}`,children:[n.jsx("div",{className:"flex-1 min-h-0 min-w-0 flex items-center justify-center",children:R}),n.jsx("div",{className:S?"h-full w-1/2 shrink-0":"h-1/2 w-full shrink-0",children:n.jsx(ye,{...N(g[0]),landscape:S})})]}):n.jsx("main",{className:"flex-1 min-h-0 min-w-0 flex flex-col",children:g.length===0?n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center text-zinc-400",children:[n.jsx("div",{className:"animate-pulse text-4xl mb-3",children:"🎛️"}),n.jsx("p",{children:"Waiting for the host to give you something to control…"})]}):g.map(I=>n.jsx("div",{className:"flex-1 min-h-0 min-w-0",children:n.jsx(ye,{...N(I),landscape:S})},I.lhs))}),W]})}return n.jsxs("div",{className:"fixed inset-0 bg-zinc-950 text-zinc-100 flex flex-col",children:[n.jsxs("header",{className:"flex items-center justify-between px-4 py-3 border-b border-zinc-800",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx(te,{className:"h-4 w-4 text-white shrink-0"}),n.jsx("span",{className:"font-semibold truncate",children:r.name}),n.jsxs("span",{className:"text-xs text-zinc-500 shrink-0",children:["· ",s]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[g.length>0&&g.every(qe)&&n.jsx("button",{type:"button",onClick:()=>w(!1),className:"rounded-lg p-2 text-zinc-300 bg-zinc-800 active:bg-zinc-700","aria-label":"Immersive layout",children:n.jsx(Bt,{className:"h-4 w-4"})}),n.jsxs("button",{onClick:()=>u(!0),className:"flex items-center gap-1.5 text-sm text-zinc-300 rounded-lg px-2.5 py-1.5 bg-zinc-800 active:bg-zinc-700",children:[n.jsx(Oe,{className:"h-4 w-4"}),r.roster.filter(p=>p.connected).length]})]})]}),n.jsx("main",{className:"flex-1 overflow-y-auto p-4 flex flex-col gap-4",children:g.length===0?n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center text-zinc-400",children:[n.jsx("div",{className:"animate-pulse text-4xl mb-3",children:"🎛️"}),n.jsx("p",{children:"Waiting for the host to give you something to control…"})]}):g.map(p=>n.jsxs("div",{className:"rounded-2xl bg-zinc-900 border border-zinc-800 p-4",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3",children:[n.jsx("div",{className:"text-sm font-medium truncate",children:p.label||p.lhs}),n.jsx("button",{type:"button",onClick:()=>d(p),className:"shrink-0 rounded-lg p-2 text-zinc-400 bg-zinc-800 active:bg-zinc-700","aria-label":"Parameter settings",children:n.jsx(we,{className:"h-4 w-4"})})]}),n.jsx(An,{...N(p)})]},p.lhs))}),l&&n.jsx(He,{schema:r.assignments[l.lhs]??l,open:!0,onOpenChange:p=>{p||d(null)},onPatch:p=>t.patchSchema(l.lhs,p)}),M]})}const ys=hs;export{ys as component};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.