ocearo-ui
Version:
Ocean Robot UI: Sailing made smarter
1 lines • 8.98 kB
JavaScript
;(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[412],{6412:function(e,t,a){a.r(t),a.d(t,{default:function(){return A}});var l=a(57437),s=a(21276),o=a(36496),n=a(30166),r=a(53082),c=a(72079),i=a(2265),d=a(51268),u=a(35217),h=()=>{let{nightMode:e,setNightMode:t,states:a,toggleState:s}=(0,r.yC)(),o=(0,i.useRef)(a.autopilot),n=e?"text-oNight":"text-oGray",c=e=>{let t={autopilot:"autopilot"===e,anchorWatch:"anchorWatch"===e,parkingMode:"parkingMode"===e};Object.keys(t).forEach(e=>{s(e,t[e])})};return(0,i.useEffect)(()=>{a.autopilot&&!o.current&&s("showPolar",!0),o.current=a.autopilot},[a.autopilot,s]),(0,l.jsxs)("div",{className:"text-lg",children:[(0,l.jsx)("button",{onClick:()=>c("autopilot"),className:"p-1",children:(0,l.jsx)(d.G,{icon:u.lnS,className:a.autopilot?"text-oBlue":n})}),(0,l.jsx)("button",{onClick:()=>c("anchorWatch"),className:"p-1",children:(0,l.jsx)(d.G,{icon:u.SJR,className:a.anchorWatch?"text-oYellow":n})}),(0,l.jsx)("button",{onClick:()=>c("parkingMode"),className:"p-1",children:(0,l.jsx)(d.G,{icon:u.BQ9,className:a.parkingMode?"text-oGreen":n})}),(0,l.jsx)("button",{onClick:()=>t(!e),className:"p-1",children:(0,l.jsx)(d.G,{icon:u.DBF,className:e?"text-oNight":n})}),(0,l.jsx)("button",{onClick:()=>s("showOcean"),className:"p-1",children:(0,l.jsx)(d.G,{icon:u.L02,className:a.showOcean?"text-oBlue":n})}),a.autopilot&&!a.showOcean&&(0,l.jsx)("button",{onClick:()=>s("showPolar"),className:"p-1",children:(0,l.jsx)(d.G,{icon:u.GTN,className:a.showPolar?"text-oBlue":n})}),a.autopilot&&(0,l.jsx)("button",{onClick:()=>s("ais"),className:"p-1",children:(0,l.jsx)(d.G,{icon:u.mDh,className:a.ais?"text-oGreen":n})})]})},x=a(15008);let b={BATTERIES:"batteries",TANKS:"tanks"},p={FRESH_WATER:{id:"freshWater",label:"Fresh Water",path:"tanks.freshWater.0.currentLevel",icon:u.Zkk,color:"bg-oBlue"},FUEL:{id:"fuel",label:"Fuel",path:"tanks.fuel.0.currentLevel",icon:u.q16,color:"bg-oYellow"},BLACK_WATER:{id:"blackWater",label:"Black Water",path:"tanks.blackWater.0.currentLevel",icon:u.NId,color:"bg-oGray"}},m=e=>{let{level:t,type:a}=e,[s,o]=(0,i.useState)(!1),n=Math.max(0,Math.min(100,t)),{label:r,icon:c,color:u}=p[a];return(0,l.jsxs)("div",{className:"flex items-center space-x-3 relative",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsx)("span",{className:"text-sm",children:(0,l.jsx)(d.G,{icon:c})}),(0,l.jsxs)("div",{className:"relative w-8 h-4 bg-oGray rounded-sm border border-oGray flex items-center justify-center",children:[(0,l.jsx)("div",{className:"absolute -right-1 w-1 h-3 bg-oGray rounded-sm"}),(0,l.jsx)("div",{className:"absolute left-0 top-0 h-full ".concat(u," transition-all duration-300 rounded-sm"),style:{width:"".concat(n,"%")}}),(0,l.jsxs)("span",{className:"relative z-10 text-xs text-white font-bold ".concat(n<=20?"text-oRed animate-pulse":""),children:[n,"%"]})]})]}),s&&(0,l.jsxs)("div",{className:"absolute -left-20 top-6 bg-gray-800 text-white px-2 py-1 rounded text-xs whitespace-nowrap z-20",children:[r,": ",n,"%"]})]})},f=e=>{let{batteryLevel:t,batteryNumber:a,voltage:s}=e,[o,n]=(0,i.useState)(!1),r=Math.max(0,Math.min(100,t)),c=(0,x.d3)(s),h=(0,i.useMemo)(()=>(0,x.z)(r),[r]);return(0,l.jsx)("div",{className:"flex items-center space-x-3 relative",onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),children:(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsx)("span",{className:"text-sm",children:(0,l.jsx)(d.G,{icon:u.BDt})}),(0,l.jsxs)("div",{className:"relative w-8 h-4 bg-oGray rounded-sm border border-oGray flex items-center justify-center",children:[(0,l.jsx)("div",{className:"absolute -right-1 w-1 h-3 bg-oGray rounded-sm"}),(0,l.jsx)("div",{className:"absolute left-0 top-0 h-full ".concat(h," transition-all duration-300 rounded-sm"),style:{width:"".concat(r,"%")}}),c?(0,l.jsx)("span",{className:"relative z-10 text-xs text-white font-bold",children:"⚡︎"}):(0,l.jsxs)("span",{className:"relative z-10 text-xs text-white font-bold ".concat(r<=x.vp.DANGER_THRESHOLD?"text-oRed animate-pulse":""),children:[r,"%"]})]}),o&&(0,l.jsxs)("div",{className:"absolute -left-20 top-6 bg-gray-800 text-white px-2 py-1 rounded text-xs whitespace-nowrap z-20",children:["Voltage: ",null==s?void 0:s.toFixed(1),"V ",c&&"(Charging)"]})]})})};var v=()=>{let{nightMode:e,getSignalKValue:t}=(0,r.yC)(),[a,s]=(0,i.useState)(b.BATTERIES),o=(0,i.useMemo)(()=>{let e=t("electrical.batteries.1.capacity.stateOfCharge"),a=t("electrical.batteries.1.voltage");return[{level:null===e?(0,x.Si)(a):e,number:1,voltage:a}].filter(e=>null!==e.level)},[t]),n=(0,i.useMemo)(()=>({FRESH_WATER:t(p.FRESH_WATER.path)||40,FUEL:t(p.FUEL.path)||75,BLACK_WATER:t(p.BLACK_WATER.path)||20}),[t]),c=()=>{s(e=>e===b.BATTERIES?b.TANKS:b.BATTERIES)},d=a===b.BATTERIES;return(0,l.jsx)("div",{className:"".concat(e?"text-oNight":"text-oGray"," rounded-lg transition-all duration-300 hover:bg-gray-800/10 cursor-pointer"),onClick:c,role:"button",tabIndex:0,"aria-label":"Toggle between ".concat(d?"tanks":"batteries"," display"),onKeyDown:e=>"Enter"===e.key&&c(),children:d?(0,l.jsx)("div",{className:"space-y-2",children:o.map(e=>(0,l.jsx)(f,{batteryLevel:e.level,batteryNumber:e.number,voltage:e.voltage},e.number))}):(0,l.jsx)("div",{className:"space-y-2",children:Object.keys(p).map(e=>(0,l.jsx)(m,{type:e,level:n[e]},e))})})};let N=(0,n.default)(()=>Promise.all([a.e(918),a.e(226),a.e(687),a.e(250),a.e(909),a.e(890)]).then(a.bind(a,10890)),{loadableGenerated:{webpack:()=>[10890]},ssr:!1}),j=(0,n.default)(()=>Promise.all([a.e(918),a.e(226),a.e(687),a.e(909),a.e(188)]).then(a.bind(a,97188)),{loadableGenerated:{webpack:()=>[97188]},ssr:!1}),g=(0,n.default)(()=>Promise.all([a.e(226),a.e(909),a.e(197)]).then(a.bind(a,62197)),{loadableGenerated:{webpack:()=>[62197]},ssr:!1}),w=(0,n.default)(()=>a.e(751).then(a.bind(a,95751)),{loadableGenerated:{webpack:()=>[95751]}}),E=(0,n.default)(()=>a.e(353).then(a.bind(a,22353)),{loadableGenerated:{webpack:()=>[22353]}}),R=(0,n.default)(()=>a.e(610).then(a.bind(a,48610)),{loadableGenerated:{webpack:()=>[48610]}}),G=(0,n.default)(()=>a.e(59).then(a.bind(a,53059)),{loadableGenerated:{webpack:()=>[53059]}}),k=(0,n.default)(()=>a.e(728).then(a.bind(a,66728)),{loadableGenerated:{webpack:()=>[66728]}}),y=(0,n.default)(()=>a.e(949).then(a.bind(a,76949)),{loadableGenerated:{webpack:()=>[76949]}}),_=()=>{let{gl:e,scene:t}=(0,s.D)();return(0,i.useEffect)(()=>{if(window&&e){window.__OCEARO_RENDERER=e;let t=setInterval(()=>{e&&e.info&&(window.__OCEARO_RENDER_INFO=e.info)},1e3);return()=>{delete window.__OCEARO_RENDERER,delete window.__OCEARO_RENDER_INFO,clearInterval(t)}}},[e,t]),null};var A=()=>{let{states:e}=(0,r.yC)(),[t,a]=(0,i.useState)(null);return(0,l.jsxs)("div",{className:"w-full h-full relative ",children:[(0,l.jsxs)("div",{className:"absolute top-2 left-2 z-10 space-y-0",children:[(0,l.jsx)(h,{}),!e.anchorWatch&&(0,l.jsx)(w,{}),e.anchorWatch&&(0,l.jsx)(G,{})]}),(0,l.jsxs)("div",{className:"absolute top-2 right-2 z-20 flex flex-col items-end",children:[(0,l.jsx)("div",{className:"mb-2",children:(0,l.jsx)(y,{content:t})}),(0,l.jsx)(v,{})]}),(0,l.jsx)("div",{className:"absolute left-2 bottom-2 z-20 flex flex-col items-center",children:(0,l.jsx)(k,{})}),(0,l.jsx)("div",{className:"absolute right-2 bottom-2 z-20 flex flex-col items-center",children:(0,l.jsx)(R,{})}),!e.anchorWatch&&(0,l.jsx)("div",{className:"absolute bottom-2 left-1/2 transform -translate-x-1/2 z-10",children:(0,l.jsx)(E,{})}),(0,l.jsx)("div",{className:"absolute left-1/2 transform -translate-x-1/2 w-full h-full",children:(0,l.jsxs)(o.Xz,{style:{width:"100%",height:"100%"},shadows:!1,dpr:Math.min(window.devicePixelRatio,1.5),performance:{min:.5},gl:{antialias:!0,powerPreference:"low-power",physicallyCorrectLights:!1,toneMapping:c.uL9,toneMappingExposure:1,shadowMap:{enabled:!1},precision:"lowp"},children:[(0,l.jsx)(_,{}),e.parkingMode?(0,l.jsx)(j,{onUpdateInfoPanel:a}):e.anchorWatch?(0,l.jsx)(g,{onUpdateInfoPanel:a}):(0,l.jsx)(N,{onUpdateInfoPanel:a})]})})]})}},15008:function(e,t,a){a.d(t,{Si:function(){return s},d3:function(){return o},vp:function(){return l},z:function(){return n}});let l={WARNING_THRESHOLD:50,DANGER_THRESHOLD:20,CHARGING_THRESHOLD:13.2,MIN_VOLTAGE:10.5,MAX_VOLTAGE:14.4},s=e=>{if(!e||"number"!=typeof e)return 0;if(e>=13)return 100;if(e<=l.MIN_VOLTAGE)return 0;let t=[{voltage:12.85,soc:100},{voltage:12.75,soc:90},{voltage:12.65,soc:80},{voltage:12.55,soc:70},{voltage:12.45,soc:60},{voltage:12.35,soc:50},{voltage:12.25,soc:40},{voltage:12.15,soc:30},{voltage:12.05,soc:20},{voltage:11.95,soc:15},{voltage:11.8,soc:10},{voltage:11.6,soc:5},{voltage:10.5,soc:0}];for(let a=0;a<t.length-1;a++)if(e>=t[a+1].voltage){let l=t[a].voltage,s=t[a+1].voltage,o=t[a].soc,n=t[a+1].soc;return Math.round(n+(e-s)/(l-s)*(o-n))}return 0},o=e=>e>l.CHARGING_THRESHOLD,n=e=>e>l.WARNING_THRESHOLD?"bg-oGreen":e>l.DANGER_THRESHOLD?"bg-oYellow":"bg-oRed"}}]);