mirror of
https://github.com/luxfi/quest.git
synced 2026-11-03 10:07:11 +00:00
Built with BASE_PATH=/quest for a GitHub project page. Served from this branch
rather than an Actions workflow: the repo's deploy.yml targets lux-build-amd64,
which has zero registered runners, and GitHub-hosted runners are refused on this
account ('recent account payments have failed'). A branch source needs neither.
Co-authored-by: Hanzo Dev <[email protected]>
1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[833],{8816:(e,t,n)=>{Promise.resolve().then(n.bind(n,9344))},9344:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>f});var l=n(909),r=n(9641),s=n(491),a=n.n(s),o=n(5030),i=n(5420);let c=e=>e*Math.PI/180;function u(e,t){let n=c(t.lat-e.lat),l=c(t.lng-e.lng);return 12742017.6*Math.asin(Math.min(1,Math.sqrt(Math.sin(n/2)**2+Math.cos(c(e.lat))*Math.cos(c(t.lat))*Math.sin(l/2)**2)))}function d(e){return Number.isFinite(e)?e<1e3?"".concat(Math.round(e)," m"):"".concat((e/1e3).toFixed(e<1e4?1:0)," km"):"—"}function m(e){let t=0x811c9dc5;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,0x1000193);return"lux.quest."+(t>>>0).toString(36)}let h={found:[],startedAt:null};var p=n(653);function f(){let[e,t]=(0,r.useState)(null),[n,s]=(0,r.useState)(null),[c,f]=(0,r.useState)({found:[],startedAt:null}),[x,g]=(0,r.useState)(null),[w,y]=(0,r.useState)(!1),[b,N]=(0,r.useState)("");(0,r.useEffect)(()=>{let e=window.location.hash.slice(1);t(e);let n=(0,i.Zx)(e);s(n),n&&e&&f(function(e){try{let t=window.localStorage.getItem(m(e));if(!t)return h;let n=JSON.parse(t);return{found:Array.isArray(null==n?void 0:n.found)?[...new Set(n.found.filter(e=>Number.isInteger(e)&&e>=0))]:[],startedAt:Number.isFinite(null==n?void 0:n.startedAt)?n.startedAt:null}}catch(e){return h}}(e))},[]);let v=(0,r.useMemo)(()=>new Set(c.found),[c]),j=(0,r.useMemo)(()=>n?n.stops.map((e,t)=>({...e,found:v.has(t),index:t})).filter(e=>!n.hidden||e.found):[],[n,v]),k=(0,r.useMemo)(()=>n?n.stops.reduce((e,t,n)=>e+(v.has(n)?t.points:0),0):0,[n,v]),S=null!=n&&v.size===n.stops.length;return null===n?(0,l.jsxs)("main",{className:"mx-auto w-full max-w-2xl flex-1 px-6 py-16",children:[(0,l.jsx)(a(),{href:"/",className:"text-sm text-white/40 transition hover:text-white",children:"← Lux Quest"}),(0,l.jsx)("h1",{className:"mt-6 text-2xl font-semibold",children:null===e?"Loading…":"This link is not a quest"}),null!==e&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"mt-3 text-white/60",children:"It may have been cut short when it was shared — links break when they wrap in a message. Ask for the whole thing again."}),(0,l.jsx)(a(),{href:"/create",className:"mt-6 inline-block rounded-lg bg-white px-5 py-2.5 font-medium text-black transition hover:bg-white/90",children:"Make your own"})]})]}):(0,l.jsxs)("main",{className:"mx-auto w-full max-w-2xl flex-1 px-6 py-10",children:[(0,l.jsx)(a(),{href:"/",className:"text-sm text-white/40 transition hover:text-white",children:"← Lux Quest"}),(0,l.jsxs)("header",{className:"mt-6",children:[(0,l.jsx)("h1",{className:"text-3xl font-semibold",children:n.name||"Untitled quest"}),n.place&&(0,l.jsx)("p",{className:"mt-1 text-white/50",children:n.place}),(0,l.jsxs)("p",{className:"mt-3 tabular-nums text-white/60",children:[v.size," of ",n.stops.length," found \xb7 ",k,"/",(0,i.cK)(n)," pts"]})]}),S&&(0,l.jsxs)("section",{className:"mt-6 rounded-xl border border-green-500/30 bg-green-500/10 p-5",children:[(0,l.jsx)("h2",{className:"text-lg font-semibold",children:"Quest complete"}),(0,l.jsxs)("p",{className:"mt-1 text-white/70",children:["You found every stop — ",k," points."]}),n.prize&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"mt-4 text-sm uppercase tracking-widest text-white/40",children:"The prize"}),(0,l.jsx)("p",{className:"mt-1 whitespace-pre-wrap",children:n.prize}),(0,l.jsx)("p",{className:"mt-3 text-xs text-white/40",children:"Claim it with whoever sent you this. Lux Quest doesn’t hold or hand out prizes."})]})]}),(0,l.jsx)(o.A,{pins:j,className:"mt-6"}),(0,l.jsxs)("div",{className:"sticky bottom-4 z-10 mt-6",children:[(0,l.jsx)("button",{onClick:()=>{if(n&&e){if(!("geolocation"in navigator)){N("This browser cannot share your location.");return}y(!0),N(""),navigator.geolocation.getCurrentPosition(t=>{var l;y(!1);let r={lat:t.coords.latitude,lng:t.coords.longitude,accuracy:t.coords.accuracy};g(r);let s=n.stops.findIndex((e,t)=>!v.has(t)&&function(e,t){let n=Number.isFinite(e.accuracy)&&e.accuracy>0?Math.min(e.accuracy,200):0;return u(e,t)<=t.radius+n}(r,e));if(-1===s){let e=n.stops.map((e,t)=>({i:t,d:u(r,e)})).filter(e=>{let{i:t}=e;return!v.has(t)}).sort((e,t)=>e.d-t.d)[0];N(e?"Not there yet — closest stop is ".concat(d(e.d)," away."):"Every stop is already found.");return}let a=c.found.includes(s)?c:{found:[...c.found,s],startedAt:null!==(l=c.startedAt)&&void 0!==l?l:Date.now()};f(a),function(e,t){try{window.localStorage.setItem(m(e),JSON.stringify(t))}catch(e){}}(e,a),N("Found it — ".concat(n.stops[s].name||"stop ".concat(s+1),"."))},e=>{y(!1),N(e.code===e.PERMISSION_DENIED?"Location is blocked. Allow it in your browser settings to check in.":"Could not get a location fix. Try again in the open.")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:0})}},disabled:w||S,className:"w-full rounded-lg bg-white px-6 py-4 text-lg font-medium text-black shadow-lg transition hover:bg-white/90 disabled:opacity-50",children:S?"All found":w?"Getting your location…":"I'm here"}),b&&(0,l.jsx)("p",{"aria-live":"polite",className:"mt-2 text-center text-sm text-white/70",children:b})]}),(0,l.jsx)("ol",{className:"mt-8 space-y-3",children:n.stops.map((e,t)=>{let r=v.has(t),s=x?u(x,e):null;return(0,l.jsxs)("li",{className:"rounded-xl border p-4 ".concat(r?"border-green-500/30 bg-green-500/[0.06]":"border-white/10"),children:[(0,l.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,l.jsx)("span",{className:"text-sm tabular-nums text-white/40",children:String(t+1).padStart(2,"0")}),(0,l.jsxs)("span",{className:"text-sm tabular-nums text-white/40",children:[e.points," pts"]})]}),(0,l.jsx)("p",{className:"mt-1.5 font-medium",children:r?e.name||"Found":e.clue||"No clue given"}),r&&e.clue&&(0,l.jsx)("p",{className:"mt-1 text-sm text-white/50",children:e.clue}),(0,l.jsxs)("div",{className:"mt-2 flex items-center gap-4 text-sm",children:[null!==s&&!r&&(0,l.jsxs)("span",{className:"tabular-nums text-white/40",children:[d(s)," away"]}),(r||!n.hidden)&&(0,l.jsx)("a",{href:(0,p.oP)(e.lat,e.lng),target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-2 text-white/60 hover:text-white",children:"Directions"})]})]},t)})}),v.size>0&&(0,l.jsx)("button",{onClick:()=>{e&&(!function(e){try{window.localStorage.removeItem(m(e))}catch(e){}}(e),f({found:[],startedAt:null}),N(""))},className:"mt-8 text-sm text-white/30 transition hover:text-white/60",children:"Start over"})]})}},5030:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var l=n(909),r=n(9641),s=n(653);let a={lat:37.7749,lng:-122.4194};function o(e){let{pins:t,center:n,onPick:o,className:c="",height:u="h-72"}=e,d=(0,r.useRef)(null),m=(0,r.useRef)(null),h=(0,r.useRef)([]),[p,f]=(0,r.useState)(s.c_?"loading":"no-key");return((0,r.useEffect)(()=>{if(!s.c_)return;let e=!0;return(0,s.Ak)().then(()=>e&&f("ready")).catch(t=>e&&f("no-key"===t.message?"no-key":"failed")),()=>{e=!1}},[]),(0,r.useEffect)(()=>{var e;if("ready"!==p||!d.current||m.current)return;let l=window.google;m.current=new l.maps.Map(d.current,{center:null!==(e=null!=n?n:t[0])&&void 0!==e?e:a,zoom:t.length?14:12,mapTypeControl:!1,streetViewControl:!1,fullscreenControl:!1,styles:i})},[p,n,t]),(0,r.useEffect)(()=>{if("ready"!==p||!m.current||!o)return;let e=m.current.addListener("click",e=>{o(e.latLng.lat(),e.latLng.lng())});return()=>{var t;return null==e?void 0:null===(t=e.remove)||void 0===t?void 0:t.call(e)}},[p,o]),(0,r.useEffect)(()=>{if("ready"!==p||!m.current)return;let e=window.google;if(h.current.forEach(e=>e.setMap(null)),h.current=t.map((t,n)=>new e.maps.Marker({position:{lat:t.lat,lng:t.lng},map:m.current,label:{text:String(n+1),color:"#000",fontWeight:"700"},title:t.found?t.name:t.clue,icon:{path:e.maps.SymbolPath.CIRCLE,scale:14,fillColor:t.found?"#4ade80":"#ffffff",fillOpacity:1,strokeWeight:0}})),t.length>1){let n=new e.maps.LatLngBounds;t.forEach(e=>n.extend({lat:e.lat,lng:e.lng})),m.current.fitBounds(n,64)}else 1===t.length&&(m.current.setCenter(t[0]),m.current.setZoom(15))},[t,p]),"ready"===p)?(0,l.jsx)("div",{ref:d,className:"w-full rounded-xl overflow-hidden ".concat(u," ").concat(c)}):(0,l.jsxs)("div",{className:"w-full rounded-xl border border-white/15 bg-white/[0.03] p-4 ".concat(c),role:"region","aria-label":"Stops",children:[(0,l.jsxs)("p",{className:"text-sm text-white/60",children:["loading"===p&&"Loading the map…","no-key"===p&&"No map key configured — the stops and links below all work.","failed"===p&&"The map failed to load. The stops and links below all work."]}),t.length>0&&(0,l.jsx)("ol",{className:"mt-3 space-y-2",children:t.map((e,t)=>(0,l.jsxs)("li",{className:"flex items-baseline gap-2 text-sm",children:[(0,l.jsxs)("span",{className:"text-white/40 tabular-nums",children:[t+1,"."]}),(0,l.jsx)("a",{href:(0,s.dy)(e.lat,e.lng),target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-2 hover:text-white",children:e.found?e.name:e.clue||"Open in Google Maps"})]},t))}),o&&(0,l.jsx)("p",{className:"mt-3 text-xs text-white/40",children:"Without a map key you can still add stops by pasting coordinates below."})]})}let i=[{elementType:"geometry",stylers:[{color:"#212121"}]},{elementType:"labels.icon",stylers:[{visibility:"off"}]},{elementType:"labels.text.fill",stylers:[{color:"#9e9e9e"}]},{elementType:"labels.text.stroke",stylers:[{color:"#212121"}]},{featureType:"road",elementType:"geometry.fill",stylers:[{color:"#2c2c2c"}]},{featureType:"water",elementType:"geometry",stylers:[{color:"#000000"}]},{featureType:"poi",elementType:"labels.text.fill",stylers:[{color:"#757575"}]}]},653:(e,t,n)=>{"use strict";var l;n.d(t,{Ak:()=>a,c_:()=>r,dy:()=>i,oP:()=>o});let r=null!==(l=n(2280).env.NEXT_PUBLIC_GOOGLE_MAPS_KEY)&&void 0!==l?l:"",s=null;function a(){var e;return r?(null===(e=window.google)||void 0===e?void 0:e.maps)?Promise.resolve():s||(s=new Promise((e,t)=>{let n=document.createElement("script");n.src="https://maps.googleapis.com/maps/api/js?key=".concat(encodeURIComponent(r))+"&libraries=places&loading=async&v=weekly",n.async=!0,n.onload=()=>e(),n.onerror=()=>{s=null,t(Error("failed"))},document.head.appendChild(n)})):Promise.reject(Error("no-key"))}function o(e,t){return"https://www.google.com/maps/dir/?api=1&destination=".concat(e,",").concat(t)}function i(e,t){return"https://www.google.com/maps/search/?api=1&query=".concat(e,",").concat(t)}},5420:(e,t,n)=>{"use strict";n.d(t,{Px:()=>o,Qn:()=>r,Zx:()=>c,cK:()=>s,f:()=>i,nM:()=>l});let l=20;function r(){return{name:"",place:"",prize:"",stops:[],hidden:!1}}function s(e){return e.stops.reduce((e,t)=>e+t.points,0)}let a=e=>Math.round(1e5*e)/1e5,o=60;function i(e){return function(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}(new TextEncoder().encode(JSON.stringify(function(e){let t={n:e.name,l:e.place,z:e.prize,s:e.stops.map(e=>({n:e.name,a:a(e.lat),o:a(e.lng),c:e.clue,p:e.points,r:e.radius}))};return e.hidden&&(t.h=1),t}(e))))}function c(e){let t=e.trim().replace(/^#/,"");if(!t)return null;try{var n,l,r;let e=JSON.parse(new TextDecoder().decode(function(e){let t=e.replace(/-/g,"+").replace(/_/g,"/"),n=atob(t+"=".repeat((4-t.length%4)%4)),l=new Uint8Array(n.length);for(let e=0;e<n.length;e++)l[e]=n.charCodeAt(e);return l}(t)));if(!e||"object"!=typeof e)return null;let s={name:String(null!==(n=e.n)&&void 0!==n?n:""),place:String(null!==(l=e.l)&&void 0!==l?l:""),prize:String(null!==(r=e.z)&&void 0!==r?r:""),hidden:1===e.h,stops:(Array.isArray(e.s)?e.s:[]).map(e=>{var t,n;return{name:String(null!==(t=null==e?void 0:e.n)&&void 0!==t?t:""),lat:Number(null==e?void 0:e.a),lng:Number(null==e?void 0:e.o),clue:String(null!==(n=null==e?void 0:e.c)&&void 0!==n?n:""),points:Number(null==e?void 0:e.p)||0,radius:Number(null==e?void 0:e.r)||o}})},a=s.stops.filter(e=>Number.isFinite(e.lat)&&Number.isFinite(e.lng)&&90>=Math.abs(e.lat)&&180>=Math.abs(e.lng));if(0===a.length)return null;return{...s,stops:a}}catch(e){return null}}}},e=>{var t=t=>e(e.s=t);e.O(0,[491,294,41,358],()=>t(8816)),_N_E=e.O()}]); |