ocearo-ui
Version:
Ocean Robot UI: 3D visualization dashboard for signalk
1 lines • 4.18 kB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,9229,e=>{"use strict";var t=e.i(43476),i=e.i(67561),n=e.i(71645),l=e.i(85709);e.i(85269);var s=e.i(22831);let a={BACKGROUND:"bg-oGreen",TEXT:"text-oGreen"},r={BACKGROUND:"bg-oYellow",TEXT:"text-oYellow"};e.s(["default",0,()=>{let{t:e}=(0,s.useTranslation)(),{nightMode:o}=(0,i.useOcearoContext)(),[u,c]=(0,n.useState)(240),m=(0,n.useMemo)(()=>["environment.tide.heightNow","environment.tide.heightHigh","environment.tide.heightLow","environment.tide.timeLow","environment.tide.timeHigh","environment.tide.coeffNow"],[]),d=(0,l.useSignalKPaths)(m),h=(0,n.useCallback)(e=>{if(!e)return null;if("string"==typeof e&&(e.includes("T")||e.includes("-"))){let t=new Date(e);return isNaN(t.getTime())?null:t}if("string"==typeof e){let t=e.split(":").map(Number);if(t.length<2)return null;let i=new Date;return i.setHours(t[0],t[1],0,0),i}return null},[]),x=(0,n.useCallback)(e=>{if(!e)return null;if("string"==typeof e&&(e.includes("T")||e.includes("-"))){let t=new Date(e);if(!isNaN(t.getTime()))return t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1})}return e},[]),g=(0,n.useCallback)((e,t)=>{let i=h(t),n=h(e);return!!i&&!!n&&i.getTime()<n.getTime()},[h]),f=(0,n.useCallback)((e,t,i)=>i<=t||!e?0:Math.min(100,Math.max(0,(e-t)/(i-t)*100)),[]);(0,n.useEffect)(()=>{let e=()=>{let e=window.innerHeight;c(e<640?Math.min(.25*e,240):Math.min(.35*e,240))};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let p=(0,n.useMemo)(()=>{let e=d["environment.tide.heightNow"],t=d["environment.tide.heightHigh"],i=d["environment.tide.heightLow"],n=d["environment.tide.timeLow"],l=d["environment.tide.timeHigh"],s=d["environment.tide.coeffNow"];return[e,t,i,n,l].every(e=>null!=e)?{level:e,high:t,low:i,timeLow:n,timeHigh:l,coefficient:s,isRising:g(n,l)}:{level:null,high:null,low:null,timeLow:null,timeHigh:null,coefficient:null,isRising:null}},[d,g]),{level:v,high:b,low:N,timeLow:w,timeHigh:T,coefficient:j,isRising:y}=p,k=o?"text-oNight":"text-hud-main",$=y?a:r,C=(0,n.useMemo)(()=>f(v,N,b),[v,N,b,f]);return Object.values(p).some(e=>null===e)?null:(0,t.jsxs)("div",{className:"flex flex-col items-center group p-3 transition-all duration-300",children:[(0,t.jsx)("div",{className:`text-xs font-black uppercase tracking-[0.2em] mb-1 opacity-40 group-hover:opacity-100 transition-opacity ${k}`,children:e("indicators.tide")}),(0,t.jsxs)("div",{className:`text-xs font-black uppercase tracking-widest mb-4 ${k} flex items-center gap-1.5 opacity-60`,children:[(0,t.jsx)("span",{className:"text-oBlue",children:x(T)}),(0,t.jsx)("span",{className:`inline-block transform ${!y&&"rotate-180"} ${$.TEXT} text-xs`,children:"▲"}),(0,t.jsxs)("span",{className:"text-hud-muted",children:["C",j]})]}),(0,t.jsxs)("div",{className:"relative flex flex-col w-12",style:{height:u},children:[(0,t.jsx)("div",{className:"absolute left-0 top-0 w-1.5 h-full bg-hud-elevated rounded-full overflow-hidden",children:(0,t.jsx)("div",{role:"progressbar",className:`${$.BACKGROUND} w-full rounded-full transition-all duration-1000 ease-in-out absolute bottom-0 left-0`,"aria-valuenow":C,"aria-valuemin":"0","aria-valuemax":"100","aria-label":`Tide level: ${v.toFixed(2)} meters`,style:{height:`${C}%`}})}),(0,t.jsxs)("div",{className:"ml-4 h-full relative",children:[(0,t.jsxs)("span",{className:`absolute ${k} text-xs font-black uppercase tracking-tighter opacity-30`,style:{top:"0%"},children:[b,"m"]}),C>10&&C<90&&(0,t.jsxs)("div",{className:"absolute transition-all duration-500 flex items-center space-x-1",style:{bottom:`${C}%`,transform:"translateY(50%)"},children:[(0,t.jsx)("div",{className:`w-2 h-[1px] ${$.BACKGROUND} opacity-50`}),(0,t.jsxs)("span",{className:`${k} text-xs font-black tracking-tight`,children:[v.toFixed(2),"m"]})]}),(0,t.jsxs)("span",{className:`absolute ${k} text-xs font-black uppercase tracking-tighter opacity-30`,style:{bottom:"0%"},children:[N,"m"]})]})]}),(0,t.jsx)("div",{className:`text-xs font-black uppercase tracking-widest mt-4 opacity-40 ${k}`,children:x(w)})]})}])},58166,e=>{e.n(e.i(9229))}]);