Initial commit
This commit is contained in:
1 parent
b359d852fe
commit
92be365e0c
39 files changed
+7072
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from './lib/store.svelte';
|
||||
import Overview from './routes/Overview.svelte';
|
||||
import BagDetail from './routes/BagDetail.svelte';
|
||||
import Onboarding from './routes/Onboarding.svelte';
|
||||
import './app.css';
|
||||
|
||||
let selectedBagId = $state<string | null>(null);
|
||||
let showDetail = $state(false);
|
||||
|
||||
function handleBagSelect(bagId: string) {
|
||||
selectedBagId = bagId;
|
||||
cultivar.selectBag(bagId);
|
||||
showDetail = true;
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
showDetail = false;
|
||||
cultivar.selectBag(null);
|
||||
}
|
||||
|
||||
function handleOnboardingComplete() {
|
||||
// state updates reactively via cultivar.completeOnboarding()
|
||||
}
|
||||
|
||||
// Start mock WebSocket on mount
|
||||
$effect(() => {
|
||||
cultivar.startMockWs();
|
||||
return () => cultivar.stopMockWs();
|
||||
});
|
||||
|
||||
const showOnboarding = $derived(!cultivar.state.ui.onboarding_complete);
|
||||
</script>
|
||||
|
||||
<div id="app-root">
|
||||
<Overview onBagSelect={handleBagSelect} />
|
||||
|
||||
{#if showDetail && selectedBagId}
|
||||
<BagDetail bagId={selectedBagId} onBack={handleBack} />
|
||||
{/if}
|
||||
|
||||
{#if showOnboarding}
|
||||
<Onboarding onComplete={handleOnboardingComplete} />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#app-root {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
@font-face {
|
||||
font-family: 'Baskervville';
|
||||
src: url('/fonts/Baskervville-VariableFont_wght.ttf') format('truetype');
|
||||
font-weight: 100 900;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Baskervville';
|
||||
src: url('/fonts/Baskervville-Italic-VariableFont_wght.ttf') format('truetype');
|
||||
font-weight: 100 900;
|
||||
font-style: italic;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'DM Sans';
|
||||
src: url('/fonts/DMSans-VariableFont_opsz,wght.ttf') format('truetype');
|
||||
font-weight: 100 900;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'DM Sans';
|
||||
src: url('/fonts/DMSans-Italic-VariableFont_opsz,wght.ttf') format('truetype');
|
||||
font-weight: 100 900;
|
||||
font-style: italic;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
:root {
|
||||
--color-bg: #070c08;
|
||||
--color-surface: #0e1410;
|
||||
--color-surface-2: #171d18;
|
||||
--color-border: #232922;
|
||||
--color-text: #e2ece0;
|
||||
--color-text-muted: #596056;
|
||||
--color-charcoal: #1e2520;
|
||||
|
||||
/* Brand — signature Cultivar green */
|
||||
--color-sage: #52cb78;
|
||||
--color-sage-dim: #1a4a2c;
|
||||
|
||||
/* Stage / biome */
|
||||
--color-mycelium: #c0c9b4; /* off-white — colonization */
|
||||
--color-fruiting: #18c8b2; /* vivid teal — clearly distinct from sage */
|
||||
--color-pinning: #7c9cf0; /* periwinkle blue */
|
||||
|
||||
/* Contamination — unmissable signals */
|
||||
--color-contam-low: #f09038; /* amber orange */
|
||||
--color-contam-high: #e43a4c; /* hot red */
|
||||
|
||||
--font-serif: 'Baskervville', Georgia, serif;
|
||||
--font-sans: 'DM Sans', system-ui, sans-serif;
|
||||
|
||||
--radius-sm: 4px;
|
||||
--radius-md: 8px;
|
||||
--radius-lg: 12px;
|
||||
|
||||
--transition-view: 320ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
font-family: var(--font-sans);
|
||||
font-size: 14px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
#app {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Grain overlay */
|
||||
#app::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
z-index: 9999;
|
||||
opacity: 0.03;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
|
||||
background-repeat: repeat;
|
||||
}
|
||||
|
||||
/* ---- Keyframe animations ---- */
|
||||
|
||||
@keyframes pulse-mycelium {
|
||||
0%, 100% { opacity: 0.7; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
|
||||
@keyframes pulse-contam-low {
|
||||
0%, 100% { opacity: 0.65; }
|
||||
50% { opacity: 0.95; }
|
||||
}
|
||||
|
||||
@keyframes pulse-contam-high {
|
||||
0%, 100% { opacity: 0.6; filter: brightness(0.9); }
|
||||
50% { opacity: 1; filter: brightness(1.15); }
|
||||
}
|
||||
|
||||
@keyframes shimmer-fruiting {
|
||||
0%, 100% { opacity: 0.7; transform: scale(1); }
|
||||
33% { opacity: 0.9; transform: scale(1.01); }
|
||||
66% { opacity: 0.8; transform: scale(0.99); }
|
||||
}
|
||||
|
||||
@keyframes pulse-pinning {
|
||||
0%, 100% { opacity: 0.65; }
|
||||
50% { opacity: 0.9; }
|
||||
}
|
||||
|
||||
@keyframes dot-live {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.3; }
|
||||
}
|
||||
|
||||
@keyframes flare {
|
||||
0% { opacity: 1; transform: scale(1); }
|
||||
50% { opacity: 1; transform: scale(1.08); filter: brightness(1.4); }
|
||||
100% { opacity: 1; transform: scale(1); filter: brightness(1); }
|
||||
}
|
||||
|
||||
@keyframes slide-in-right {
|
||||
from { transform: translateX(100%); }
|
||||
to { transform: translateX(0); }
|
||||
}
|
||||
|
||||
@keyframes slide-out-right {
|
||||
from { transform: translateX(0); }
|
||||
to { transform: translateX(100%); }
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
/* ---- Utility classes ---- */
|
||||
|
||||
.font-serif { font-family: var(--font-serif); }
|
||||
.font-sans { font-family: var(--font-sans); }
|
||||
.text-muted { color: var(--color-text-muted); }
|
||||
.text-sage { color: var(--color-sage); }
|
||||
|
||||
.pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 100px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.pill-inoculation { background: color-mix(in srgb, var(--color-text-muted) 20%, transparent); color: var(--color-text-muted); }
|
||||
.pill-colonization { background: color-mix(in srgb, var(--color-sage) 20%, transparent); color: var(--color-sage); }
|
||||
.pill-pinning { background: color-mix(in srgb, var(--color-pinning) 20%, transparent); color: var(--color-pinning); }
|
||||
.pill-fruiting { background: color-mix(in srgb, var(--color-fruiting) 20%, transparent); color: var(--color-fruiting); }
|
||||
.pill-harvest { background: color-mix(in srgb, var(--color-contam-low) 20%, transparent); color: var(--color-contam-low); }
|
||||
|
||||
.pill-contam-none { background: transparent; color: var(--color-text-muted); border: 1px solid var(--color-border); }
|
||||
.pill-contam-low { background: color-mix(in srgb, var(--color-contam-low) 15%, transparent); color: var(--color-contam-low); }
|
||||
.pill-contam-high { background: color-mix(in srgb, var(--color-contam-high) 15%, transparent); color: var(--color-contam-high); }
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
font-family: var(--font-sans);
|
||||
border: none;
|
||||
background: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
button:focus-visible {
|
||||
outline: 2px solid var(--color-sage);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<script lang="ts">
|
||||
import type { TimeSeriesPoint } from '../types';
|
||||
|
||||
interface Props {
|
||||
curve: TimeSeriesPoint[];
|
||||
inoculatedTs: number;
|
||||
estimatedReadyTs: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
}
|
||||
|
||||
const {
|
||||
curve,
|
||||
inoculatedTs,
|
||||
estimatedReadyTs,
|
||||
width = 300,
|
||||
height = 120,
|
||||
}: Props = $props();
|
||||
|
||||
const PAD = { top: 16, right: 16, bottom: 28, left: 32 };
|
||||
const NOW = $derived(Math.floor(Date.now() / 1000));
|
||||
|
||||
const plotW = $derived(width - PAD.left - PAD.right);
|
||||
const plotH = $derived(height - PAD.top - PAD.bottom);
|
||||
|
||||
// Split curve into past actuals vs projection
|
||||
const pastPoints = $derived(curve.filter(p => p.ts <= NOW));
|
||||
const projPoints = $derived(curve.filter(p => p.ts >= NOW));
|
||||
|
||||
const allTs = $derived(curve.map(p => p.ts));
|
||||
const minTs = $derived(allTs.length > 0 ? Math.min(...allTs, inoculatedTs) : inoculatedTs);
|
||||
const maxTs = $derived(allTs.length > 0 ? Math.max(...allTs, estimatedReadyTs) : estimatedReadyTs);
|
||||
const rangeTs = $derived(maxTs - minTs || 1);
|
||||
|
||||
const px = $derived((ts: number) =>
|
||||
PAD.left + ((ts - minTs) / rangeTs) * plotW
|
||||
);
|
||||
const py = $derived((v: number) =>
|
||||
PAD.top + (1 - v / 100) * plotH
|
||||
);
|
||||
|
||||
function toPath(pts: TimeSeriesPoint[]): string {
|
||||
if (pts.length < 2) return '';
|
||||
return pts.map((p, i) => `${i === 0 ? 'M' : 'L'}${px(p.ts).toFixed(1)},${py(p.value).toFixed(1)}`).join(' ');
|
||||
}
|
||||
|
||||
const pastPath = $derived(toPath(pastPoints));
|
||||
const projPath = $derived(toPath(projPoints));
|
||||
|
||||
// Confidence band for projection (±5%)
|
||||
const projBand = $derived.by(() => {
|
||||
if (projPoints.length < 2) return '';
|
||||
const upper = projPoints.map(p => ({ ts: p.ts, value: Math.min(100, p.value + 5) }));
|
||||
const lower = [...projPoints].reverse().map(p => ({ ts: p.ts, value: Math.max(0, p.value - 5) }));
|
||||
const up = upper.map((p, i) => `${i === 0 ? 'M' : 'L'}${px(p.ts).toFixed(1)},${py(p.value).toFixed(1)}`).join(' ');
|
||||
const dn = lower.map(p => `L${px(p.ts).toFixed(1)},${py(p.value).toFixed(1)}`).join(' ');
|
||||
return `${up} ${dn} Z`;
|
||||
});
|
||||
|
||||
const nowX = $derived(px(NOW));
|
||||
|
||||
// X axis ticks
|
||||
const xTicks = $derived.by(() => {
|
||||
const ticks: { x: number; label: string }[] = [];
|
||||
const step = rangeTs / 4;
|
||||
for (let i = 0; i <= 4; i++) {
|
||||
const ts = minTs + i * step;
|
||||
const d = new Date(ts * 1000);
|
||||
ticks.push({
|
||||
x: px(ts),
|
||||
label: `${d.getMonth() + 1}/${d.getDate()}`,
|
||||
});
|
||||
}
|
||||
return ticks;
|
||||
});
|
||||
</script>
|
||||
|
||||
<svg {width} {height} viewBox="0 0 {width} {height}" class="curve-svg" aria-label="Colonization curve">
|
||||
<!-- Y axis labels -->
|
||||
{#each [0, 25, 50, 75, 100] as pct}
|
||||
<text
|
||||
x={PAD.left - 6}
|
||||
y={py(pct) + 4}
|
||||
text-anchor="end"
|
||||
font-family="var(--font-sans)"
|
||||
font-size="9"
|
||||
fill="var(--color-text-muted)"
|
||||
>{pct}%</text>
|
||||
<line
|
||||
x1={PAD.left}
|
||||
y1={py(pct)}
|
||||
x2={PAD.left + plotW}
|
||||
y2={py(pct)}
|
||||
stroke="var(--color-border)"
|
||||
stroke-width="0.5"
|
||||
opacity="0.6"
|
||||
/>
|
||||
{/each}
|
||||
|
||||
<!-- X axis ticks -->
|
||||
{#each xTicks as tick}
|
||||
<text
|
||||
x={tick.x}
|
||||
y={height - 8}
|
||||
text-anchor="middle"
|
||||
font-family="var(--font-sans)"
|
||||
font-size="8"
|
||||
fill="var(--color-text-muted)"
|
||||
>{tick.label}</text>
|
||||
{/each}
|
||||
|
||||
<!-- Projection confidence band -->
|
||||
{#if projBand}
|
||||
<path
|
||||
d={projBand}
|
||||
fill="var(--color-sage)"
|
||||
opacity="0.08"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Projection dashed line -->
|
||||
{#if projPath}
|
||||
<path
|
||||
d={projPath}
|
||||
fill="none"
|
||||
stroke="var(--color-sage)"
|
||||
stroke-width="1.5"
|
||||
stroke-dasharray="5 3"
|
||||
opacity="0.6"
|
||||
stroke-linecap="round"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Past actuals solid line -->
|
||||
{#if pastPath}
|
||||
<path
|
||||
d={pastPath}
|
||||
fill="none"
|
||||
stroke="var(--color-sage)"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- "Now" vertical marker -->
|
||||
{#if nowX >= PAD.left && nowX <= PAD.left + plotW}
|
||||
<line
|
||||
x1={nowX}
|
||||
y1={PAD.top}
|
||||
x2={nowX}
|
||||
y2={PAD.top + plotH}
|
||||
stroke="var(--color-text-muted)"
|
||||
stroke-width="1"
|
||||
stroke-dasharray="2 2"
|
||||
opacity="0.5"
|
||||
/>
|
||||
<text
|
||||
x={nowX + 3}
|
||||
y={PAD.top + 9}
|
||||
font-family="var(--font-sans)"
|
||||
font-size="8"
|
||||
fill="var(--color-text-muted)"
|
||||
letter-spacing="0.05em"
|
||||
>NOW</text>
|
||||
{/if}
|
||||
|
||||
<!-- Estimated ready marker -->
|
||||
{#if estimatedReadyTs > NOW}
|
||||
{@const ex = px(estimatedReadyTs)}
|
||||
<line
|
||||
x1={ex}
|
||||
y1={PAD.top}
|
||||
x2={ex}
|
||||
y2={PAD.top + plotH}
|
||||
stroke="var(--color-sage)"
|
||||
stroke-width="0.8"
|
||||
stroke-dasharray="3 2"
|
||||
opacity="0.4"
|
||||
/>
|
||||
{/if}
|
||||
</svg>
|
||||
|
||||
<style>
|
||||
.curve-svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,127 @@
|
||||
<script lang="ts">
|
||||
import type { EnvironmentReading } from '../types';
|
||||
|
||||
interface Props {
|
||||
history: EnvironmentReading[];
|
||||
targets: { temp_c: number; rh_pct: number; co2_ppm: number };
|
||||
windowPts: number;
|
||||
}
|
||||
|
||||
const { history, targets, windowPts }: Props = $props();
|
||||
|
||||
function scoreReading(r: EnvironmentReading): number {
|
||||
const tempP = Math.min(Math.abs(r.temp_c - targets.temp_c) / 3, 1) * 33;
|
||||
const rhP = Math.min(Math.abs(r.rh_pct - targets.rh_pct) / 10, 1) * 34;
|
||||
const co2P = Math.min(Math.abs((r.co2_ppm ?? r.co2e_ppm ?? 0) - targets.co2_ppm) / 500, 1) * 33;
|
||||
return Math.max(0, Math.round(100 - tempP - rhP - co2P));
|
||||
}
|
||||
|
||||
const pts = $derived(
|
||||
history.slice(-windowPts).map(r => ({ ts: r.ts, v: scoreReading(r) }))
|
||||
);
|
||||
|
||||
const current = $derived(pts.length > 0 ? pts[pts.length - 1].v : 100);
|
||||
|
||||
const lineColor = $derived(
|
||||
current >= 80 ? 'var(--color-sage)'
|
||||
: current >= 50 ? 'var(--color-contam-low)'
|
||||
: 'var(--color-contam-high)'
|
||||
);
|
||||
|
||||
// Normalized 0–100 coordinate space; SVG scales via CSS
|
||||
const linePath = $derived.by(() => {
|
||||
if (pts.length < 2) return '';
|
||||
const minTs = pts[0].ts;
|
||||
const span = (pts[pts.length - 1].ts - minTs) || 1;
|
||||
return pts.map((p, i) => {
|
||||
const x = ((p.ts - minTs) / span) * 100;
|
||||
const y = 100 - p.v;
|
||||
return `${i === 0 ? 'M' : 'L'}${x.toFixed(2)},${y.toFixed(2)}`;
|
||||
}).join(' ');
|
||||
});
|
||||
|
||||
const areaPath = $derived.by(() => {
|
||||
if (pts.length < 2 || !linePath) return '';
|
||||
const minTs = pts[0].ts;
|
||||
const span = (pts[pts.length - 1].ts - minTs) || 1;
|
||||
const lastX = (((pts[pts.length - 1].ts - minTs) / span) * 100).toFixed(2);
|
||||
return `${linePath} L${lastX},100 L0,100 Z`;
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="hs-root">
|
||||
<div class="hs-header">
|
||||
<span class="hs-label">Health</span>
|
||||
<span class="hs-score" style="color: {lineColor}">{current}</span>
|
||||
<span class="hs-max">/100</span>
|
||||
</div>
|
||||
|
||||
<div class="hs-chart">
|
||||
<svg viewBox="0 0 100 100" preserveAspectRatio="none">
|
||||
<defs>
|
||||
<linearGradient id="hs-fill" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color={lineColor} stop-opacity="0.3"/>
|
||||
<stop offset="100%" stop-color={lineColor} stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<line x1="0" y1="50" x2="100" y2="50"
|
||||
stroke="var(--color-border)" stroke-width="0.5"
|
||||
vector-effect="non-scaling-stroke"/>
|
||||
{#if areaPath}
|
||||
<path d={areaPath} fill="url(#hs-fill)"/>
|
||||
{/if}
|
||||
{#if linePath}
|
||||
<path d={linePath} fill="none" stroke={lineColor}
|
||||
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
|
||||
vector-effect="non-scaling-stroke"/>
|
||||
{/if}
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.hs-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.hs-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 5px;
|
||||
flex-shrink: 0;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
.hs-label {
|
||||
font-size: 9px;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-muted);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.hs-score {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.hs-max {
|
||||
font-size: 10px;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.hs-chart {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,135 @@
|
||||
<script lang="ts">
|
||||
import type { TimeSeriesPoint } from '../types';
|
||||
|
||||
interface Props {
|
||||
data: TimeSeriesPoint[];
|
||||
label: string;
|
||||
value: string;
|
||||
color?: string;
|
||||
targetValue?: number | null;
|
||||
yMin?: number | null;
|
||||
yMax?: number | null;
|
||||
}
|
||||
|
||||
const {
|
||||
data,
|
||||
label,
|
||||
value,
|
||||
color = 'var(--color-sage)',
|
||||
targetValue = null,
|
||||
yMin = null,
|
||||
yMax = null,
|
||||
}: Props = $props();
|
||||
|
||||
const uid = $derived(label.replace(/[^a-z0-9]/gi, '').toLowerCase());
|
||||
|
||||
const paths = $derived.by(() => {
|
||||
if (data.length < 2) return { line: '', area: '', targetY: null as number | null };
|
||||
const minTs = data[0].ts;
|
||||
const span = (data[data.length - 1].ts - minTs) || 1;
|
||||
const vals = data.map(d => d.value);
|
||||
const lo = yMin ?? Math.min(...vals);
|
||||
const hi = yMax ?? Math.max(...vals);
|
||||
const range = hi - lo || 1;
|
||||
|
||||
const px = (ts: number) => ((ts - minTs) / span) * 100;
|
||||
const py = (v: number) => 100 - ((v - lo) / range) * 100;
|
||||
|
||||
const line = data.map((p, i) =>
|
||||
`${i === 0 ? 'M' : 'L'}${px(p.ts).toFixed(2)},${py(p.value).toFixed(2)}`
|
||||
).join(' ');
|
||||
|
||||
const lastX = px(data[data.length - 1].ts).toFixed(2);
|
||||
const area = `${line} L${lastX},100 L0,100 Z`;
|
||||
|
||||
const targetY = targetValue !== null ? py(targetValue) : null;
|
||||
|
||||
return { line, area, targetY };
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="lc">
|
||||
<div class="lc-overlay">
|
||||
<span class="lc-label">{label}</span>
|
||||
<span class="lc-value">{value}</span>
|
||||
</div>
|
||||
|
||||
<svg viewBox="0 0 100 100" preserveAspectRatio="none">
|
||||
<defs>
|
||||
<linearGradient id="lc-{uid}" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color={color} stop-opacity="0.28"/>
|
||||
<stop offset="100%" stop-color={color} stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<!-- Midline when scale is fixed (health score) -->
|
||||
{#if yMin !== null && yMax !== null}
|
||||
<line x1="0" y1="50" x2="100" y2="50"
|
||||
stroke="var(--color-border)" stroke-width="0.8"
|
||||
vector-effect="non-scaling-stroke"/>
|
||||
{/if}
|
||||
|
||||
<!-- Target line -->
|
||||
{#if paths.targetY !== null}
|
||||
<line x1="0" y1={paths.targetY} x2="100" y2={paths.targetY}
|
||||
stroke={color} stroke-width="0.6" stroke-dasharray="2 2" opacity="0.5"
|
||||
vector-effect="non-scaling-stroke"/>
|
||||
{/if}
|
||||
|
||||
<!-- Area fill -->
|
||||
{#if paths.area}
|
||||
<path d={paths.area} fill="url(#lc-{uid})"/>
|
||||
{/if}
|
||||
|
||||
<!-- Line -->
|
||||
{#if paths.line}
|
||||
<path d={paths.line} fill="none" stroke={color}
|
||||
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
|
||||
vector-effect="non-scaling-stroke"/>
|
||||
{/if}
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.lc {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.lc-overlay {
|
||||
position: absolute;
|
||||
padding: 2px 4px;
|
||||
background-color: var(--color-bg);
|
||||
opacity: 0.9;
|
||||
border-radius: 4px;
|
||||
top: 5px;
|
||||
left: 8px;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.lc-label {
|
||||
font-size: 9px;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-muted);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.lc-value {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
color: var(--color-text);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,139 @@
|
||||
<script lang="ts">
|
||||
import type { TimeSeriesPoint } from '../types';
|
||||
|
||||
interface Props {
|
||||
data: TimeSeriesPoint[];
|
||||
width?: number;
|
||||
height?: number;
|
||||
color?: string;
|
||||
targetValue?: number | null;
|
||||
scrubberTs?: number | null;
|
||||
}
|
||||
|
||||
const {
|
||||
data,
|
||||
width = 120,
|
||||
height = 32,
|
||||
color = 'var(--color-sage)',
|
||||
targetValue = null,
|
||||
scrubberTs = null,
|
||||
}: Props = $props();
|
||||
|
||||
const PAD_X = 2;
|
||||
const PAD_Y = 3;
|
||||
|
||||
const path = $derived.by(() => {
|
||||
if (data.length < 2) return '';
|
||||
const minTs = data[0].ts;
|
||||
const maxTs = data[data.length - 1].ts;
|
||||
const vals = data.map(p => p.value);
|
||||
const minV = Math.min(...vals);
|
||||
const maxV = Math.max(...vals);
|
||||
const rangeV = maxV - minV || 1;
|
||||
const rangeTs = maxTs - minTs || 1;
|
||||
|
||||
const px = (ts: number) => PAD_X + ((ts - minTs) / rangeTs) * (width - PAD_X * 2);
|
||||
const py = (v: number) => PAD_Y + (1 - (v - minV) / rangeV) * (height - PAD_Y * 2);
|
||||
|
||||
return data
|
||||
.map((p, i) => `${i === 0 ? 'M' : 'L'}${px(p.ts).toFixed(1)},${py(p.value).toFixed(1)}`)
|
||||
.join(' ');
|
||||
});
|
||||
|
||||
const targetY = $derived.by(() => {
|
||||
if (targetValue === null || data.length < 2) return null;
|
||||
const vals = data.map(p => p.value);
|
||||
const minV = Math.min(...vals);
|
||||
const maxV = Math.max(...vals);
|
||||
const rangeV = maxV - minV || 1;
|
||||
return PAD_Y + (1 - (targetValue - minV) / rangeV) * (height - PAD_Y * 2);
|
||||
});
|
||||
|
||||
const scrubberX = $derived.by(() => {
|
||||
if (scrubberTs === null || data.length < 2) return null;
|
||||
const minTs = data[0].ts;
|
||||
const maxTs = data[data.length - 1].ts;
|
||||
const rangeTs = maxTs - minTs || 1;
|
||||
const x = PAD_X + ((scrubberTs - minTs) / rangeTs) * (width - PAD_X * 2);
|
||||
return Math.max(PAD_X, Math.min(width - PAD_X, x));
|
||||
});
|
||||
|
||||
const areaPath = $derived.by(() => {
|
||||
if (!path || data.length < 2) return '';
|
||||
const minTs = data[0].ts;
|
||||
const maxTs = data[data.length - 1].ts;
|
||||
const rangeTs = maxTs - minTs || 1;
|
||||
const vals = data.map(p => p.value);
|
||||
const minV = Math.min(...vals);
|
||||
const maxV = Math.max(...vals);
|
||||
const rangeV = maxV - minV || 1;
|
||||
const px = (ts: number) => PAD_X + ((ts - minTs) / rangeTs) * (width - PAD_X * 2);
|
||||
const bottom = height - PAD_Y;
|
||||
const firstX = px(data[0].ts).toFixed(1);
|
||||
const lastX = px(data[data.length - 1].ts).toFixed(1);
|
||||
return `${path} L${lastX},${bottom} L${firstX},${bottom} Z`;
|
||||
});
|
||||
</script>
|
||||
|
||||
<svg {width} {height} viewBox="0 0 {width} {height}" aria-hidden="true">
|
||||
<defs>
|
||||
<linearGradient id="spark-fill-{color.replace(/[^a-z0-9]/gi, '')}" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color={color} stop-opacity="0.18"/>
|
||||
<stop offset="100%" stop-color={color} stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<!-- Area fill -->
|
||||
{#if areaPath}
|
||||
<path
|
||||
d={areaPath}
|
||||
fill="url(#spark-fill-{color.replace(/[^a-z0-9]/gi, '')})"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Target line -->
|
||||
{#if targetY !== null}
|
||||
<line
|
||||
x1={PAD_X}
|
||||
y1={targetY}
|
||||
x2={width - PAD_X}
|
||||
y2={targetY}
|
||||
stroke={color}
|
||||
stroke-width="0.5"
|
||||
stroke-dasharray="3 3"
|
||||
opacity="0.4"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Main line -->
|
||||
{#if path}
|
||||
<path
|
||||
d={path}
|
||||
fill="none"
|
||||
stroke={color}
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Scrubber marker -->
|
||||
{#if scrubberX !== null}
|
||||
<line
|
||||
x1={scrubberX}
|
||||
y1={PAD_Y}
|
||||
x2={scrubberX}
|
||||
y2={height - PAD_Y}
|
||||
stroke={color}
|
||||
stroke-width="1"
|
||||
opacity="0.8"
|
||||
/>
|
||||
{/if}
|
||||
</svg>
|
||||
|
||||
<style>
|
||||
svg {
|
||||
display: block;
|
||||
overflow: visible;
|
||||
}
|
||||
</style>
|
||||
+352
@@ -0,0 +1,352 @@
|
||||
import type { CultivarState, EnvironmentReading, TimeSeriesPoint, BagSnapshot } from './types';
|
||||
|
||||
const NOW = Math.floor(Date.now() / 1000);
|
||||
const HOUR = 3600;
|
||||
|
||||
function genEnvHistory(): EnvironmentReading[] {
|
||||
const pts: EnvironmentReading[] = [];
|
||||
for (let i = 1440; i >= 0; i--) {
|
||||
const t = NOW - i * 60;
|
||||
const phase = (i / 1440) * Math.PI * 4;
|
||||
pts.push({
|
||||
ts: t,
|
||||
temp_c: 22.5 + Math.sin(phase) * 0.8 + (Math.random() - 0.5) * 0.2,
|
||||
rh_pct: 87 + Math.sin(phase * 1.3) * 3 + (Math.random() - 0.5) * 0.5,
|
||||
co2_ppm: 1200 + Math.sin(phase * 0.7) * 150 + (Math.random() - 0.5) * 30,
|
||||
co2e_ppm: 1350 + Math.sin(phase * 0.6) * 120 + (Math.random() - 0.5) * 25,
|
||||
voc_ppb: 42 + Math.sin(phase * 1.2) * 8 + (Math.random() - 0.5) * 2,
|
||||
vpd: 0.41 + Math.sin(phase * 1.1) * 0.05 + (Math.random() - 0.5) * 0.01,
|
||||
});
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
function genColonizationCurve(inoculatedTs: number, pctNow: number): TimeSeriesPoint[] {
|
||||
const pts: TimeSeriesPoint[] = [];
|
||||
const daysSinceInoculation = (NOW - inoculatedTs) / (HOUR * 24);
|
||||
const totalDays = 21;
|
||||
|
||||
for (let d = 0; d <= daysSinceInoculation; d += 0.5) {
|
||||
const pct = Math.min(100, (d / totalDays) * 100 * (1 + Math.sin(d * 0.3) * 0.05));
|
||||
pts.push({ ts: inoculatedTs + d * HOUR * 24, value: Math.round(pct * 10) / 10 });
|
||||
}
|
||||
|
||||
const projDays = totalDays - daysSinceInoculation;
|
||||
for (let d = 0; d <= projDays; d += 0.5) {
|
||||
const base = pctNow + (d / projDays) * (100 - pctNow);
|
||||
pts.push({ ts: NOW + d * HOUR * 24, value: Math.min(100, Math.round(base * 10) / 10) });
|
||||
}
|
||||
|
||||
return pts;
|
||||
}
|
||||
|
||||
function genSnapshots(inoculatedTs: number, count: number): BagSnapshot[] {
|
||||
const snaps: BagSnapshot[] = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const age = count - 1 - i;
|
||||
const ts = NOW - age * HOUR * 48;
|
||||
const pct = Math.min(95, ((NOW - inoculatedTs - age * HOUR * 48) / (HOUR * 24 * 21)) * 100);
|
||||
snaps.push({
|
||||
ts,
|
||||
image_url: `/mock/snapshot_${i}.jpg`,
|
||||
colonization_pct: Math.max(0, Math.round(pct * 10) / 10),
|
||||
contamination_risk: i === 0 ? 'low' : 'none',
|
||||
annotations: [
|
||||
{ type: 'mycelium', x: 0.5, y: 0.4, radius: 0.38, confidence: 0.92 },
|
||||
{ type: 'mycelium', x: 0.3, y: 0.6, radius: 0.18, confidence: 0.85 },
|
||||
...(i === 0
|
||||
? [{ type: 'contamination' as const, x: 0.75, y: 0.2, radius: 0.06, confidence: 0.71 }]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
}
|
||||
return snaps;
|
||||
}
|
||||
|
||||
const inoculatedA1 = NOW - 12 * HOUR * 24;
|
||||
const inoculatedA2 = NOW - 8 * HOUR * 24;
|
||||
const inoculatedB1 = NOW - 18 * HOUR * 24;
|
||||
const inoculatedB2 = NOW - 5 * HOUR * 24;
|
||||
const inoculatedBx1 = NOW - 3 * HOUR * 24;
|
||||
const inoculatedBx2 = NOW - 15 * HOUR * 24;
|
||||
|
||||
export const mockState: CultivarState = {
|
||||
meta: {
|
||||
device_id: 'CVR-0042',
|
||||
firmware_version: '0.9.4',
|
||||
uptime_s: 432000,
|
||||
wifi_rssi: -58,
|
||||
timestamp_utc: NOW,
|
||||
},
|
||||
environment: {
|
||||
history: genEnvHistory(),
|
||||
live: { temp_c: 22.4, rh_pct: 87.2, co2_ppm: 1240, co2e_ppm: 1380, voc_ppb: 44, vpd: 0.41 },
|
||||
targets: { temp_c: 22.5, rh_pct: 88, co2_ppm: 1200 },
|
||||
alerts: [
|
||||
{
|
||||
id: 'a1',
|
||||
type: 'bag_ready',
|
||||
severity: 'info',
|
||||
message: 'Bag B1 (Golden Oyster, 94%) is ready to move to the fruiting chamber.',
|
||||
ts: NOW - 3600,
|
||||
dismissed: false,
|
||||
},
|
||||
{
|
||||
id: 'a2',
|
||||
type: 'co2_elevated',
|
||||
severity: 'warn',
|
||||
message: 'CO₂e is elevated in Colonization (1380 ppm). Check that the FAE port is clear.',
|
||||
ts: NOW - 1800,
|
||||
dismissed: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
chambers: [
|
||||
{
|
||||
id: 'main',
|
||||
label: 'Colonization',
|
||||
type: 'colonization',
|
||||
environment: {
|
||||
temp_c: 22.4,
|
||||
rh_pct: 87.2,
|
||||
co2e_ppm: 1380,
|
||||
voc_ppb: 44,
|
||||
},
|
||||
slots: [
|
||||
{
|
||||
slot_id: 'A1',
|
||||
position: { x: 0, y: 0, z: 2 },
|
||||
bag: {
|
||||
bag_id: 'bag-001',
|
||||
slot_id: 'A1',
|
||||
tag: {
|
||||
strain_code: 'MSS-PLEOS-GRV-2024-001',
|
||||
strain_name: 'Blue Oyster',
|
||||
substrate: 'Hardwood + Wheat Bran',
|
||||
inoculated_ts: inoculatedA1,
|
||||
batch_id: 'BTC-2024-03',
|
||||
},
|
||||
vision: {
|
||||
colonization_pct: 68,
|
||||
colonization_confidence: 0.91,
|
||||
contamination_risk: 'low',
|
||||
stage: 'colonization',
|
||||
snapshots: genSnapshots(inoculatedA1, 4),
|
||||
projection: {
|
||||
estimated_ready_ts: NOW + 9 * HOUR * 24,
|
||||
colonization_curve: genColonizationCurve(inoculatedA1, 68),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
slot_id: 'A2',
|
||||
position: { x: 1, y: 0, z: 2 },
|
||||
bag: {
|
||||
bag_id: 'bag-002',
|
||||
slot_id: 'A2',
|
||||
tag: {
|
||||
strain_code: 'MSS-PLEOS-GRV-2024-002',
|
||||
strain_name: 'Blue Oyster',
|
||||
substrate: 'Hardwood Sawdust',
|
||||
inoculated_ts: inoculatedA2,
|
||||
batch_id: 'BTC-2024-03',
|
||||
},
|
||||
vision: {
|
||||
colonization_pct: 42,
|
||||
colonization_confidence: 0.87,
|
||||
contamination_risk: 'none',
|
||||
stage: 'colonization',
|
||||
snapshots: genSnapshots(inoculatedA2, 3),
|
||||
projection: {
|
||||
estimated_ready_ts: NOW + 13 * HOUR * 24,
|
||||
colonization_curve: genColonizationCurve(inoculatedA2, 42),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
slot_id: 'B1',
|
||||
position: { x: 0, y: 0, z: 1 },
|
||||
bag: {
|
||||
bag_id: 'bag-003',
|
||||
slot_id: 'B1',
|
||||
tag: {
|
||||
strain_code: 'MSS-GFROND-GRV-2024-001',
|
||||
strain_name: 'Golden Oyster',
|
||||
substrate: 'Supplemented Sawdust',
|
||||
inoculated_ts: inoculatedB1,
|
||||
batch_id: 'BTC-2024-02',
|
||||
},
|
||||
vision: {
|
||||
colonization_pct: 94,
|
||||
colonization_confidence: 0.96,
|
||||
contamination_risk: 'none',
|
||||
stage: 'fruiting',
|
||||
snapshots: genSnapshots(inoculatedB1, 6),
|
||||
projection: {
|
||||
estimated_ready_ts: NOW + 3 * HOUR * 24,
|
||||
colonization_curve: genColonizationCurve(inoculatedB1, 94),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
slot_id: 'B2',
|
||||
position: { x: 1, y: 0, z: 1 },
|
||||
bag: {
|
||||
bag_id: 'bag-004',
|
||||
slot_id: 'B2',
|
||||
tag: {
|
||||
strain_code: 'MSS-LELED-GRV-2024-001',
|
||||
strain_name: "Lion's Mane",
|
||||
substrate: 'Master Mix',
|
||||
inoculated_ts: inoculatedB2,
|
||||
batch_id: 'BTC-2024-04',
|
||||
},
|
||||
vision: {
|
||||
colonization_pct: 18,
|
||||
colonization_confidence: 0.79,
|
||||
contamination_risk: 'none',
|
||||
stage: 'inoculation',
|
||||
snapshots: genSnapshots(inoculatedB2, 2),
|
||||
projection: {
|
||||
estimated_ready_ts: NOW + 16 * HOUR * 24,
|
||||
colonization_curve: genColonizationCurve(inoculatedB2, 18),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
slot_id: 'C1',
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
bag: null,
|
||||
},
|
||||
{
|
||||
slot_id: 'C2',
|
||||
position: { x: 1, y: 0, z: 0 },
|
||||
bag: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'second',
|
||||
label: 'Fruiting',
|
||||
type: 'fruiting',
|
||||
environment: {
|
||||
temp_c: 18.8,
|
||||
rh_pct: 92.4,
|
||||
co2_ppm: 820,
|
||||
voc_ppb: 61,
|
||||
},
|
||||
slots: [
|
||||
{
|
||||
slot_id: 'A1',
|
||||
position: { x: 0, y: 0, z: 2 },
|
||||
bag: {
|
||||
bag_id: 'bag-005',
|
||||
slot_id: 'A1',
|
||||
tag: {
|
||||
strain_code: 'MSS-PLEOS-GRV-2024-005',
|
||||
strain_name: 'Blue Oyster',
|
||||
substrate: 'Master Mix',
|
||||
inoculated_ts: inoculatedBx1,
|
||||
batch_id: 'BTC-2024-05',
|
||||
},
|
||||
vision: {
|
||||
colonization_pct: 12,
|
||||
colonization_confidence: 0.74,
|
||||
contamination_risk: 'none',
|
||||
stage: 'inoculation',
|
||||
snapshots: genSnapshots(inoculatedBx1, 1),
|
||||
projection: {
|
||||
estimated_ready_ts: NOW + 18 * HOUR * 24,
|
||||
colonization_curve: genColonizationCurve(inoculatedBx1, 12),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
slot_id: 'A2',
|
||||
position: { x: 1, y: 0, z: 2 },
|
||||
bag: null,
|
||||
},
|
||||
{
|
||||
slot_id: 'B1',
|
||||
position: { x: 0, y: 0, z: 1 },
|
||||
bag: null,
|
||||
},
|
||||
{
|
||||
slot_id: 'B2',
|
||||
position: { x: 1, y: 0, z: 1 },
|
||||
bag: {
|
||||
bag_id: 'bag-006',
|
||||
slot_id: 'B2',
|
||||
tag: {
|
||||
strain_code: 'MSS-HERER-GRV-2024-001',
|
||||
strain_name: 'Shiitake',
|
||||
substrate: 'Supplemented Sawdust',
|
||||
inoculated_ts: inoculatedBx2,
|
||||
batch_id: 'BTC-2024-02',
|
||||
},
|
||||
vision: {
|
||||
colonization_pct: 82,
|
||||
colonization_confidence: 0.93,
|
||||
contamination_risk: 'none',
|
||||
stage: 'pinning',
|
||||
snapshots: genSnapshots(inoculatedBx2, 5),
|
||||
projection: {
|
||||
estimated_ready_ts: NOW + 5 * HOUR * 24,
|
||||
colonization_curve: genColonizationCurve(inoculatedBx2, 82),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
slot_id: 'C1',
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
bag: null,
|
||||
},
|
||||
{
|
||||
slot_id: 'C2',
|
||||
position: { x: 1, y: 0, z: 0 },
|
||||
bag: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
hardware: {
|
||||
fans: [
|
||||
{ id: 'fan-1', speed_pct: 60, mode: 'auto' },
|
||||
{ id: 'fan-2', speed_pct: 0, mode: 'auto' },
|
||||
],
|
||||
heater: { active: false, duty_cycle: 0 },
|
||||
humidifier: { active: true, mode: 'auto' },
|
||||
leds: { mode: 'fruiting', color_hex: '#4a9e8a', brightness: 0.4 },
|
||||
cameras: [
|
||||
{ id: 'cam-1', position: 'top', last_capture_ts: NOW - 180 },
|
||||
{ id: 'cam-2', position: 'side', last_capture_ts: NOW - 180 },
|
||||
],
|
||||
},
|
||||
recipe: {
|
||||
id: 'recipe-pleos-01',
|
||||
name: 'Blue Oyster Standard',
|
||||
species: 'Pleurotus ostreatus',
|
||||
stage: 'colonization',
|
||||
stage_started_ts: NOW - 8 * HOUR * 24,
|
||||
stage_target_duration_h: 336,
|
||||
stage_history: [
|
||||
{ stage: 'inoculation', started_ts: NOW - 18 * HOUR * 24, ended_ts: NOW - 8 * HOUR * 24 },
|
||||
{ stage: 'colonization', started_ts: NOW - 8 * HOUR * 24, ended_ts: null },
|
||||
],
|
||||
next_actions: [
|
||||
{ type: 'mist', due_ts: NOW + 3600, description: 'Mist chamber walls' },
|
||||
{ type: 'fae', due_ts: NOW + 7200, description: 'Fresh air exchange' },
|
||||
],
|
||||
},
|
||||
ui: {
|
||||
scrubber_ts: null,
|
||||
selected_bag_id: null,
|
||||
onboarding_complete: localStorage.getItem('onboarding_complete') === 'true',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
import { mockState } from './mock';
|
||||
import type { CultivarState, EnvironmentReading, WsDiff } from './types';
|
||||
|
||||
function deepClone<T>(v: T): T {
|
||||
return JSON.parse(JSON.stringify(v));
|
||||
}
|
||||
|
||||
function createStore() {
|
||||
let state = $state<CultivarState>(deepClone(mockState));
|
||||
|
||||
// Mock WS diff interval
|
||||
let mockInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function applyDiff(diff: WsDiff) {
|
||||
state.meta.timestamp_utc = diff.t;
|
||||
|
||||
if (diff.e) {
|
||||
if (diff.e.temp !== undefined) state.environment.live.temp_c = diff.e.temp;
|
||||
if (diff.e.rh !== undefined) state.environment.live.rh_pct = diff.e.rh;
|
||||
if (diff.e.co2 !== undefined) state.environment.live.co2_ppm = diff.e.co2;
|
||||
if (diff.e.vpd !== undefined) state.environment.live.vpd = diff.e.vpd;
|
||||
|
||||
// Push to history ring buffer
|
||||
const reading: EnvironmentReading = {
|
||||
ts: diff.t,
|
||||
temp_c: state.environment.live.temp_c,
|
||||
rh_pct: state.environment.live.rh_pct,
|
||||
co2_ppm: state.environment.live.co2_ppm,
|
||||
voc_ppb: state.environment.live.voc_ppb,
|
||||
vpd: state.environment.live.vpd,
|
||||
};
|
||||
state.environment.history.push(reading);
|
||||
if (state.environment.history.length > 1441) {
|
||||
state.environment.history.shift();
|
||||
}
|
||||
}
|
||||
|
||||
if (diff.hw) {
|
||||
if (diff.hw.fans) {
|
||||
diff.hw.fans.forEach((spd, i) => {
|
||||
if (state.hardware.fans[i]) state.hardware.fans[i].speed_pct = spd;
|
||||
});
|
||||
}
|
||||
if (diff.hw.heater !== undefined) state.hardware.heater.active = diff.hw.heater;
|
||||
if (diff.hw.humidifier !== undefined) state.hardware.humidifier.active = diff.hw.humidifier;
|
||||
}
|
||||
}
|
||||
|
||||
function startMockWs() {
|
||||
mockInterval = setInterval(() => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const jitter = (x: number, amt: number) => x + (Math.random() - 0.5) * amt;
|
||||
applyDiff({
|
||||
t: now,
|
||||
e: {
|
||||
temp: jitter(state.environment.live.temp_c, 0.3),
|
||||
rh: jitter(state.environment.live.rh_pct, 1),
|
||||
co2: jitter(state.environment.live.co2_ppm, 40),
|
||||
vpd: jitter(state.environment.live.vpd, 0.02),
|
||||
},
|
||||
hw: {
|
||||
fans: state.hardware.fans.map(f => f.speed_pct),
|
||||
heater: state.hardware.heater.active,
|
||||
humidifier: state.hardware.humidifier.active,
|
||||
},
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function stopMockWs() {
|
||||
if (mockInterval) {
|
||||
clearInterval(mockInterval);
|
||||
mockInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
function setScrubberTs(ts: number | null) {
|
||||
state.ui.scrubber_ts = ts;
|
||||
}
|
||||
|
||||
function selectBag(bagId: string | null) {
|
||||
state.ui.selected_bag_id = bagId;
|
||||
}
|
||||
|
||||
function completeOnboarding() {
|
||||
state.ui.onboarding_complete = true;
|
||||
localStorage.setItem('onboarding_complete', 'true');
|
||||
}
|
||||
|
||||
function dismissAlert(alertId: string) {
|
||||
const alert = state.environment.alerts.find(a => a.id === alertId);
|
||||
if (alert) alert.dismissed = true;
|
||||
}
|
||||
|
||||
return {
|
||||
get state() { return state; },
|
||||
applyDiff,
|
||||
startMockWs,
|
||||
stopMockWs,
|
||||
setScrubberTs,
|
||||
selectBag,
|
||||
completeOnboarding,
|
||||
dismissAlert,
|
||||
};
|
||||
}
|
||||
|
||||
export const cultivar = createStore();
|
||||
@@ -0,0 +1,181 @@
|
||||
<script lang="ts">
|
||||
import type { BagState } from '../types';
|
||||
import { STAGE_LABELS } from '../types';
|
||||
|
||||
interface Props {
|
||||
bag: BagState | null;
|
||||
slotId: string;
|
||||
chamberId: string;
|
||||
theme: 'colonization' | 'fruiting';
|
||||
onBagClick: (bagId: string, el: HTMLElement) => void;
|
||||
}
|
||||
|
||||
const { bag, slotId, chamberId, theme, onBagClick }: Props = $props();
|
||||
|
||||
const stageColor = $derived.by(() => {
|
||||
if (!bag) return '#4a4a40';
|
||||
const risk = bag.vision.contamination_risk;
|
||||
const stage = bag.vision.stage;
|
||||
if (risk === 'high') return '#c94040';
|
||||
if (risk === 'low') return '#c9832a';
|
||||
if (stage === 'fruiting') return '#4a9e8a';
|
||||
if (stage === 'pinning') return '#3a7a8e';
|
||||
return '#c8caaa';
|
||||
});
|
||||
|
||||
const stageAnim = $derived.by(() => {
|
||||
if (!bag) return '';
|
||||
if (bag.vision.contamination_risk === 'high') return 'pulse-contam-high 2.2s ease-in-out infinite';
|
||||
if (bag.vision.contamination_risk === 'low') return 'pulse-contam-low 3s ease-in-out infinite';
|
||||
if (bag.vision.stage === 'fruiting') return 'shimmer-fruiting 5s ease-in-out infinite';
|
||||
if (bag.vision.stage === 'pinning') return 'pulse-pinning 4s ease-in-out infinite';
|
||||
return 'pulse-mycelium 4s ease-in-out infinite';
|
||||
});
|
||||
|
||||
const coveragePct = $derived(bag ? bag.vision.colonization_pct : 0);
|
||||
|
||||
let btnEl: HTMLButtonElement | null = $state(null);
|
||||
|
||||
function handleClick() {
|
||||
if (bag && btnEl) onBagClick(bag.bag_id, btnEl);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button
|
||||
bind:this={btnEl}
|
||||
class="bag-slot"
|
||||
class:empty={!bag}
|
||||
aria-label={bag
|
||||
? `${bag.tag.strain_name}, ${STAGE_LABELS[bag.vision.stage]}, ${bag.vision.colonization_pct}% colonized`
|
||||
: `Slot ${slotId}: empty`}
|
||||
onclick={handleClick}
|
||||
disabled={!bag}
|
||||
>
|
||||
{#if bag}
|
||||
<!--
|
||||
viewBox 80×100: squarer ratio fills compact grid cells cleanly.
|
||||
Colonization gradient rises from bottom (substrate) to top (mycelium).
|
||||
-->
|
||||
<svg class="bag-svg" viewBox="0 0 80 100" preserveAspectRatio="xMidYMid meet" aria-hidden="true">
|
||||
<defs>
|
||||
<linearGradient id="bg-{chamberId}-{slotId}" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color={stageColor} stop-opacity="0.9"/>
|
||||
<stop offset="{Math.max(4, 100 - coveragePct)}%" stop-color={stageColor} stop-opacity="0.55"/>
|
||||
<stop offset="{Math.max(6, 104 - coveragePct)}%" stop-color="#2e1e0e" stop-opacity="0.98"/>
|
||||
<stop offset="100%" stop-color="#18100a" stop-opacity="1"/>
|
||||
</linearGradient>
|
||||
<radialGradient id="halo-{chamberId}-{slotId}" cx="50%" cy="35%" r="60%">
|
||||
<stop offset="0%" stop-color={stageColor} stop-opacity="0.15"/>
|
||||
<stop offset="100%" stop-color={stageColor} stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
|
||||
<!-- Glow -->
|
||||
<ellipse cx="40" cy="48" rx="36" ry="44"
|
||||
fill="url(#halo-{chamberId}-{slotId})"
|
||||
style="animation: {stageAnim}"
|
||||
/>
|
||||
|
||||
<!-- Bag body -->
|
||||
<rect x="3" y="3" width="74" height="94" rx="6"
|
||||
fill="url(#bg-{chamberId}-{slotId})"
|
||||
style="animation: {stageAnim}"
|
||||
/>
|
||||
|
||||
<!-- Bag outline -->
|
||||
<rect x="3" y="3" width="74" height="94" rx="6"
|
||||
fill="none" stroke={stageColor} stroke-width="0.6" stroke-opacity="0.28"
|
||||
/>
|
||||
|
||||
<!-- Filter patch: square -->
|
||||
<rect x="24" y="8" width="32" height="32" rx="2"
|
||||
fill="#dedad0" fill-opacity="0.82"
|
||||
/>
|
||||
{#each [0,1,2,3] as row}{#each [0,1,2,3] as col}
|
||||
<circle cx={28 + col * 8} cy={12 + row * 8} r="0.7" fill="#9a9888" opacity="0.38"/>
|
||||
{/each}{/each}
|
||||
|
||||
<!-- Tag placeholder: faint outline only -->
|
||||
<rect x="14" y="48" width="52" height="34" rx="3"
|
||||
fill={stageColor} fill-opacity="0.04"
|
||||
stroke={stageColor} stroke-width="0.5" stroke-opacity="0.16"
|
||||
/>
|
||||
|
||||
<!-- Injection port -->
|
||||
<circle cx="40" cy="89" r="5"
|
||||
fill="none" stroke={stageColor} stroke-width="0.5" stroke-opacity="0.25"
|
||||
/>
|
||||
<circle cx="40" cy="89" r="2"
|
||||
fill={stageColor} fill-opacity="0.16"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
<!-- Colonization % -->
|
||||
<div class="bag-pct" style="color: {stageColor}">
|
||||
{bag.vision.colonization_pct}%
|
||||
</div>
|
||||
|
||||
<!-- Contamination badge -->
|
||||
{#if bag.vision.contamination_risk !== 'none'}
|
||||
<div class="contam-badge">⚠</div>
|
||||
{/if}
|
||||
|
||||
{:else}
|
||||
<!-- Empty slot: dashed outline matching new bag aspect ratio -->
|
||||
<svg class="bag-svg" viewBox="0 0 80 100" aria-hidden="true">
|
||||
<rect x="3" y="3" width="74" height="94" rx="6"
|
||||
fill="none"
|
||||
stroke="var(--color-border)"
|
||||
stroke-width="0.8"
|
||||
stroke-dasharray="3 4"
|
||||
opacity="0.4"
|
||||
/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<style>
|
||||
.bag-slot {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 2px;
|
||||
cursor: pointer;
|
||||
transition: filter 0.18s;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bag-slot:hover:not(:disabled) { filter: brightness(1.15); }
|
||||
.bag-slot:focus-visible { outline: 2px solid var(--color-sage); outline-offset: 2px; }
|
||||
.bag-slot:disabled { cursor: default; }
|
||||
|
||||
.bag-svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.bag-pct {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 5px;
|
||||
font-family: var(--font-serif);
|
||||
font-size: 10px;
|
||||
line-height: 1;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.contam-badge {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
left: 5px;
|
||||
font-size: 9px;
|
||||
color: var(--color-contam-low);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,306 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
import type { BagState } from '../types';
|
||||
import { STAGE_LABELS } from '../types';
|
||||
|
||||
interface Props {
|
||||
bagId: string;
|
||||
anchor: { x: number; y: number };
|
||||
onClose: () => void;
|
||||
onOpenDetails: () => void;
|
||||
}
|
||||
|
||||
const { bagId, anchor, onClose, onOpenDetails }: Props = $props();
|
||||
|
||||
const bag = $derived.by<BagState | null>(() => {
|
||||
for (const ch of cultivar.state.chambers) {
|
||||
for (const sl of ch.slots) if (sl.bag?.bag_id === bagId) return sl.bag;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
const daysSinceInoc = $derived(
|
||||
bag ? Math.max(0, Math.floor((Date.now() / 1000 - bag.tag.inoculated_ts) / 86400)) : 0
|
||||
);
|
||||
const daysToReady = $derived(
|
||||
bag ? Math.max(0, Math.ceil((bag.vision.projection.estimated_ready_ts - Date.now() / 1000) / 86400)) : 0
|
||||
);
|
||||
|
||||
const stageColor: Record<string, string> = {
|
||||
inoculation: 'var(--color-text-muted)',
|
||||
colonization: 'var(--color-mycelium)',
|
||||
pinning: 'var(--color-pinning)',
|
||||
fruiting: 'var(--color-fruiting)',
|
||||
harvest: 'var(--color-sage)',
|
||||
};
|
||||
|
||||
const contamColor: Record<string, string> = {
|
||||
none: 'var(--color-text-muted)',
|
||||
low: 'var(--color-contam-low)',
|
||||
medium: 'var(--color-contam-low)',
|
||||
high: 'var(--color-contam-high)',
|
||||
};
|
||||
|
||||
const POP_W = 288;
|
||||
const POP_H_EST = 268;
|
||||
const MARGIN = 12;
|
||||
|
||||
let winW = $state(typeof window === 'undefined' ? 800 : window.innerWidth);
|
||||
let winH = $state(typeof window === 'undefined' ? 600 : window.innerHeight);
|
||||
|
||||
const pos = $derived.by(() => {
|
||||
let x = anchor.x + 18;
|
||||
let y = anchor.y - POP_H_EST / 2;
|
||||
if (x + POP_W > winW - MARGIN) x = anchor.x - POP_W - 18;
|
||||
if (x < MARGIN) x = MARGIN;
|
||||
if (y < MARGIN) y = MARGIN;
|
||||
if (y + POP_H_EST > winH - MARGIN) y = winH - POP_H_EST - MARGIN;
|
||||
return { x, y };
|
||||
});
|
||||
|
||||
function handleKey(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape') onClose();
|
||||
}
|
||||
|
||||
function handleResize() {
|
||||
winW = window.innerWidth;
|
||||
winH = window.innerHeight;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
window.addEventListener('keydown', handleKey);
|
||||
window.addEventListener('resize', handleResize);
|
||||
return () => {
|
||||
window.removeEventListener('keydown', handleKey);
|
||||
window.removeEventListener('resize', handleResize);
|
||||
};
|
||||
});
|
||||
|
||||
function formatDate(ts: number): string {
|
||||
return new Date(ts * 1000).toLocaleDateString([], { month: 'short', day: 'numeric' });
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="popover-backdrop"
|
||||
onclick={onClose}
|
||||
onkeydown={(e) => e.key === 'Escape' && onClose()}
|
||||
role="presentation"
|
||||
></div>
|
||||
|
||||
{#if bag}
|
||||
<div
|
||||
class="popover-card"
|
||||
style="left: {pos.x}px; top: {pos.y}px; width: {POP_W}px;"
|
||||
role="dialog"
|
||||
aria-label="Bag {bag.slot_id} info"
|
||||
>
|
||||
<div class="pop-head">
|
||||
<div class="pop-slot">{bag.slot_id}</div>
|
||||
<div class="pop-pct">
|
||||
<span class="pct-num">{bag.vision.colonization_pct}%</span>
|
||||
<span class="pct-label">COLONIZED</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pop-strain">{bag.tag.strain_name}</div>
|
||||
<div class="pop-sub">{bag.tag.substrate}</div>
|
||||
|
||||
<div class="pop-stats">
|
||||
<div class="stat">
|
||||
<div class="stat-label">STAGE</div>
|
||||
<div class="stat-value" style="color: {stageColor[bag.vision.stage]}">
|
||||
{STAGE_LABELS[bag.vision.stage]}
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">DAY</div>
|
||||
<div class="stat-value">{daysSinceInoc}</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">READY IN</div>
|
||||
<div class="stat-value">
|
||||
{#if daysToReady > 0}{daysToReady}d{:else}Soon{/if}
|
||||
</div>
|
||||
</div>
|
||||
{#if bag.vision.contamination_risk !== 'none'}
|
||||
<div class="stat">
|
||||
<div class="stat-label">HEALTH</div>
|
||||
<div class="stat-value" style="color: {contamColor[bag.vision.contamination_risk]}">
|
||||
Monitor
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="stat">
|
||||
<div class="stat-label">HEALTH</div>
|
||||
<div class="stat-value" style="color: var(--color-sage)">Good</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="pop-meta">
|
||||
<span>Started {formatDate(bag.tag.inoculated_ts)}</span>
|
||||
</div>
|
||||
|
||||
<button class="pop-details-btn" onclick={onOpenDetails}>
|
||||
View Details
|
||||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
|
||||
<path d="M5 3L9 7L5 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.popover-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.25);
|
||||
backdrop-filter: blur(2px);
|
||||
-webkit-backdrop-filter: blur(2px);
|
||||
z-index: 40;
|
||||
animation: fade-in 0.15s ease-out;
|
||||
}
|
||||
|
||||
.popover-card {
|
||||
position: fixed;
|
||||
z-index: 41;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 14px 16px 12px;
|
||||
box-shadow: 0 12px 32px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.03) inset;
|
||||
animation: pop-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.1);
|
||||
}
|
||||
|
||||
@keyframes pop-in {
|
||||
from { opacity: 0; transform: translateY(-4px) scale(0.98); }
|
||||
to { opacity: 1; transform: translateY(0) scale(1); }
|
||||
}
|
||||
|
||||
.pop-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.pop-slot {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 22px;
|
||||
color: var(--color-text);
|
||||
line-height: 1;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.pop-pct {
|
||||
text-align: right;
|
||||
line-height: 1;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid color-mix(in srgb, var(--color-sage) 40%, var(--color-border));
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.pct-num {
|
||||
display: block;
|
||||
font-family: var(--font-serif);
|
||||
font-size: 16px;
|
||||
color: var(--color-sage);
|
||||
}
|
||||
|
||||
.pct-label {
|
||||
display: block;
|
||||
font-family: var(--font-sans);
|
||||
font-size: 7px;
|
||||
letter-spacing: 0.18em;
|
||||
color: var(--color-text-muted);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.pop-strain {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 11px;
|
||||
color: var(--color-text);
|
||||
letter-spacing: 0.02em;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.pop-sub {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 11px;
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.pop-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
padding: 8px 0;
|
||||
border-top: 1px solid var(--color-border);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.stat {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 8px;
|
||||
letter-spacing: 0.16em;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 13px;
|
||||
color: var(--color-text);
|
||||
text-transform: capitalize;
|
||||
line-height: 1.1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pop-meta {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 10px;
|
||||
color: var(--color-text-muted);
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
|
||||
.pop-details-btn {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 9px 14px;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid color-mix(in srgb, var(--color-sage) 40%, var(--color-border));
|
||||
background: color-mix(in srgb, var(--color-sage) 10%, var(--color-surface-2));
|
||||
color: var(--color-sage);
|
||||
font-family: var(--font-sans);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.02em;
|
||||
transition: background 0.15s, border-color 0.15s;
|
||||
}
|
||||
|
||||
.pop-details-btn:hover {
|
||||
background: color-mix(in srgb, var(--color-sage) 18%, var(--color-surface-2));
|
||||
border-color: var(--color-sage);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,216 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
import BagGlyph from './BagGlyph.svelte';
|
||||
import type { ChamberSlot } from '../types';
|
||||
import { STAGE_LABELS } from '../types';
|
||||
|
||||
interface Props {
|
||||
onBagClick: (bagId: string, el: HTMLElement) => void;
|
||||
}
|
||||
const { onBagClick }: Props = $props();
|
||||
|
||||
const chambers = $derived(cultivar.state.chambers);
|
||||
|
||||
function sortedSlots(slots: ChamberSlot[]): ChamberSlot[] {
|
||||
return [...slots].sort((a, b) => {
|
||||
const zDiff = b.position.z - a.position.z; // top shelf first (z=2)
|
||||
if (zDiff !== 0) return zDiff;
|
||||
return a.position.x - b.position.x;
|
||||
});
|
||||
}
|
||||
|
||||
function fmtTemp(v: number) { return v.toFixed(1); }
|
||||
function fmtRh(v: number) { return v.toFixed(0); }
|
||||
function fmtCo2(v: number) { return v.toFixed(0); }
|
||||
function fmtVoc(v: number) { return v.toFixed(0); }
|
||||
|
||||
// Count bags with issues in a chamber
|
||||
function chamberAlert(slots: ChamberSlot[]): boolean {
|
||||
return slots.some(s => s.bag && s.bag.vision.contamination_risk !== 'none');
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="chambers-wrap">
|
||||
{#each chambers as chamber (chamber.id)}
|
||||
{@const isFruiting = chamber.type === 'fruiting'}
|
||||
{@const hasAlert = chamberAlert(chamber.slots)}
|
||||
|
||||
<div class="chamber-card" class:fruiting={isFruiting}>
|
||||
<!-- Chamber header -->
|
||||
<div class="ch-header">
|
||||
<div class="ch-title-row">
|
||||
<span class="ch-name">{chamber.label}</span>
|
||||
{#if hasAlert}
|
||||
<span class="ch-alert-badge">⚠</span>
|
||||
{:else}
|
||||
<span class="ch-status-dot"></span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Environment readings (compact, 4 sensors) -->
|
||||
<div class="ch-env">
|
||||
<div class="env-pill">
|
||||
<span class="env-val">{fmtTemp(chamber.environment.temp_c)}°</span>
|
||||
<span class="env-unit">Temp</span>
|
||||
</div>
|
||||
<div class="env-pill">
|
||||
<span class="env-val">{fmtRh(chamber.environment.rh_pct)}%</span>
|
||||
<span class="env-unit">RH</span>
|
||||
</div>
|
||||
<div class="env-pill">
|
||||
{#if chamber.type === 'colonization'}
|
||||
<span class="env-val">{fmtCo2(chamber.environment.co2e_ppm ?? 0)}</span>
|
||||
<span class="env-unit">CO₂e</span>
|
||||
{:else}
|
||||
<span class="env-val">{fmtCo2(chamber.environment.co2_ppm ?? 0)}</span>
|
||||
<span class="env-unit">CO₂</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="env-pill">
|
||||
<span class="env-val">{fmtVoc(chamber.environment.voc_ppb)}</span>
|
||||
<span class="env-unit">VOC</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bag grid: 3 rows × 2 cols (top shelf first) -->
|
||||
<div class="bag-grid">
|
||||
{#each sortedSlots(chamber.slots) as slot (slot.slot_id)}
|
||||
<BagGlyph
|
||||
bag={slot.bag}
|
||||
slotId={slot.slot_id}
|
||||
chamberId={chamber.id}
|
||||
theme={isFruiting ? 'fruiting' : 'colonization'}
|
||||
onBagClick={onBagClick}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.chambers-wrap {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* ---- Chamber card ---- */
|
||||
.chamber-card {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
padding: 10px;
|
||||
background: var(--color-surface);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Fruiting chamber: warm off-white */
|
||||
.chamber-card.fruiting {
|
||||
background: #f5f0e6;
|
||||
border-color: #d8ceba;
|
||||
color: #2a2416;
|
||||
}
|
||||
|
||||
/* ---- Header ---- */
|
||||
.ch-header {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ch-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ch-name {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 15px;
|
||||
letter-spacing: 0.01em;
|
||||
line-height: 1;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.chamber-card.fruiting .ch-name {
|
||||
color: #2a2416;
|
||||
}
|
||||
|
||||
.ch-status-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-sage);
|
||||
animation: dot-live 2.5s ease-in-out infinite;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ch-alert-badge {
|
||||
font-size: 11px;
|
||||
color: var(--color-contam-low);
|
||||
}
|
||||
|
||||
/* ---- Env row ---- */
|
||||
.ch-env {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.env-pill {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1px;
|
||||
padding: 4px 2px;
|
||||
border-radius: 5px;
|
||||
background: rgba(0,0,0,0.12);
|
||||
}
|
||||
|
||||
.chamber-card.fruiting .env-pill {
|
||||
background: rgba(0,0,0,0.07);
|
||||
}
|
||||
|
||||
.env-val {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.env-unit {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 8px;
|
||||
letter-spacing: 0.08em;
|
||||
opacity: 0.6;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ---- Bag grid ---- */
|
||||
.bag-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
grid-template-rows: repeat(3, 1fr);
|
||||
gap: 6px;
|
||||
/* Height chosen so bags render near-square with the 80×100 viewBox */
|
||||
height: 240px;
|
||||
}
|
||||
|
||||
/* ---- Responsive ---- */
|
||||
@media (max-width: 900px) {
|
||||
.chambers-wrap {
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,353 @@
|
||||
<script lang="ts">
|
||||
import type { Chamber, BagState } from '../types';
|
||||
import { cultivar } from '../store.svelte';
|
||||
|
||||
interface Props {
|
||||
chamber: Chamber;
|
||||
}
|
||||
|
||||
const { chamber }: Props = $props();
|
||||
|
||||
const hw = $derived(cultivar.state.hardware);
|
||||
const fan = $derived(hw.fans[0]);
|
||||
const humidOn = $derived(hw.humidifier.active);
|
||||
const heaterOn = $derived(hw.heater.active);
|
||||
const leds = $derived(hw.leds);
|
||||
|
||||
const fanSpinning = $derived(fan.speed_pct > 0);
|
||||
const fanDur = $derived(
|
||||
fanSpinning ? `${(0.5 + (1 - fan.speed_pct / 100) * 2.4).toFixed(2)}s` : '4s'
|
||||
);
|
||||
|
||||
const ledColor = $derived(leds.brightness > 0 ? leds.color_hex : '#1a1d16');
|
||||
const ledOpacity = $derived(leds.brightness * 0.45);
|
||||
|
||||
// Uniform bag color by chamber type — only contamination changes appearance
|
||||
const BAG_BASE = $derived(chamber.type === 'colonization' ? '#bcc5b0' : '#18c8b2');
|
||||
|
||||
function contamColor(bag: BagState): string | null {
|
||||
if (bag.vision.contamination_risk === 'high') return '#e43a4c';
|
||||
if (bag.vision.contamination_risk === 'low') return '#f09038';
|
||||
return null;
|
||||
}
|
||||
|
||||
// Colonization: show %, Fruiting: show days to harvest
|
||||
function bagLabel(bag: BagState): string {
|
||||
if (chamber.type === 'fruiting') {
|
||||
const days = Math.max(0, Math.ceil(
|
||||
(bag.vision.projection.estimated_ready_ts - Date.now() / 1000) / 86400
|
||||
));
|
||||
return days === 0 ? 'Today' : `${days}d`;
|
||||
}
|
||||
return `${bag.vision.colonization_pct}%`;
|
||||
}
|
||||
|
||||
// rows[0]=top shelf (z=2), rows[1]=mid (z=1), rows[2]=bot (z=0)
|
||||
const grid = $derived.by(() => {
|
||||
const rows: (BagState | null)[][] = [[null, null], [null, null], [null, null]];
|
||||
for (const slot of chamber.slots) {
|
||||
const row = 2 - slot.position.z;
|
||||
const col = slot.position.x;
|
||||
if (row >= 0 && row < 3 && col >= 0 && col < 2)
|
||||
rows[row][col] = slot.bag;
|
||||
}
|
||||
return rows;
|
||||
});
|
||||
|
||||
// Bag rect geometry — front face: x=28..152, y=82..250 (124×168)
|
||||
// 3 shelf rows; dividers at y=138, y=194 (56px per row)
|
||||
const BAG_X = [33, 96];
|
||||
const BAG_W = 51;
|
||||
const BAG_TOPS = [87, 143, 199];
|
||||
const BAG_H = 48;
|
||||
|
||||
// Env reading shortcuts
|
||||
const temp = $derived(chamber.environment.temp_c.toFixed(1));
|
||||
const rh = $derived(chamber.environment.rh_pct.toFixed(0));
|
||||
const co2 = $derived(
|
||||
chamber.type === 'colonization'
|
||||
? (chamber.environment.co2e_ppm ?? 0).toFixed(0)
|
||||
: (chamber.environment.co2_ppm ?? 0).toFixed(0)
|
||||
);
|
||||
const co2Label = chamber.type === 'colonization' ? 'CO₂e' : 'CO₂';
|
||||
const voc = $derived(chamber.environment.voc_ppb.toFixed(0));
|
||||
</script>
|
||||
|
||||
<div class="wrap">
|
||||
<div class="ch-name">{chamber.label}</div>
|
||||
|
||||
<!--
|
||||
Cabinet geometry:
|
||||
Front face : x=28..152, y=82..250 (124×168)
|
||||
Depth : 20h / 12v
|
||||
Top face : 28,82 → 48,70 → 172,70 → 152,82
|
||||
Side face : 152,82 → 172,70 → 172,238 → 152,250
|
||||
Shelf lines: y=138, y=194
|
||||
-->
|
||||
<svg viewBox="20 60 155 200" class="iso" aria-hidden="true">
|
||||
<defs>
|
||||
<radialGradient id="led-{chamber.id}" cx="50%" cy="0%" r="110%" fy="0%">
|
||||
<stop offset="0%" stop-color={ledColor} stop-opacity={ledOpacity}/>
|
||||
<stop offset="80%" stop-color={ledColor} stop-opacity={ledOpacity * 0.15}/>
|
||||
<stop offset="100%" stop-color={ledColor} stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<radialGradient id="heat-{chamber.id}" cx="50%" cy="100%" r="75%">
|
||||
<stop offset="0%" stop-color="#ff5020" stop-opacity={heaterOn ? 0.13 : 0}/>
|
||||
<stop offset="100%" stop-color="#ff5020" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
|
||||
<!-- TOP FACE -->
|
||||
<polygon points="28,82 48,70 172,70 152,82"
|
||||
fill="#0d1210" stroke="#222a20" stroke-width="0.8"/>
|
||||
<!-- LED strip -->
|
||||
<line x1="28" y1="82" x2="152" y2="82"
|
||||
stroke={ledColor}
|
||||
stroke-width={leds.brightness > 0 ? 3 : 0.6}
|
||||
stroke-opacity={leds.brightness > 0 ? 0.9 : 0.18}/>
|
||||
|
||||
<!-- RIGHT SIDE FACE -->
|
||||
<polygon points="152,82 172,70 172,238 152,250"
|
||||
fill="#0b0f0c" stroke="#222a20" stroke-width="0.8"/>
|
||||
|
||||
<!-- FRONT FACE -->
|
||||
<rect x="28" y="82" width="124" height="168"
|
||||
fill="#111810" fill-opacity="0.88"
|
||||
stroke="#222a20" stroke-width="0.8"/>
|
||||
<rect x="28" y="82" width="124" height="168" fill="url(#led-{chamber.id})"/>
|
||||
<rect x="28" y="82" width="124" height="168" fill="url(#heat-{chamber.id})"/>
|
||||
|
||||
<!-- SHELF DIVIDERS -->
|
||||
<line x1="28" y1="138" x2="152" y2="138" stroke="#1c2419" stroke-width="1"/>
|
||||
<line x1="28" y1="194" x2="152" y2="194" stroke="#1c2419" stroke-width="1"/>
|
||||
<line x1="90" y1="82" x2="90" y2="250" stroke="#181e15" stroke-width="0.6" stroke-opacity="0.7"/>
|
||||
|
||||
<!-- BAGS -->
|
||||
{#each grid as row, ri}
|
||||
{#each row as bag, ci}
|
||||
{@const bx = BAG_X[ci]}
|
||||
{@const by = BAG_TOPS[ri]}
|
||||
{#if bag}
|
||||
{@const cc = contamColor(bag)}
|
||||
<!-- Bag body (dim fill) -->
|
||||
<rect x={bx} y={by} width={BAG_W} height={BAG_H} rx="2.5"
|
||||
fill={BAG_BASE} fill-opacity="0.10"
|
||||
stroke={BAG_BASE} stroke-width="0.5" stroke-opacity="0.20"/>
|
||||
<!-- Colonization fill rising from bottom -->
|
||||
{@const fh = Math.max(3, BAG_H * bag.vision.colonization_pct / 100)}
|
||||
<rect x={bx} y={by + BAG_H - fh} width={BAG_W} height={fh} rx="2"
|
||||
fill={BAG_BASE} fill-opacity="0.52"/>
|
||||
<!-- Label -->
|
||||
<text
|
||||
x={bx + BAG_W / 2} y={by + BAG_H / 2 + 3.5}
|
||||
text-anchor="middle"
|
||||
fill={BAG_BASE} fill-opacity="0.9"
|
||||
style="font-size:8px; font-family: Georgia, serif;"
|
||||
>{bagLabel(bag)}</text>
|
||||
<!-- Contamination glow outline (pulsing) -->
|
||||
{#if cc}
|
||||
<!-- Outer halo -->
|
||||
<rect x={bx - 2} y={by - 2} width={BAG_W + 4} height={BAG_H + 4} rx="4"
|
||||
fill="none" stroke={cc} stroke-width="1" stroke-opacity="0.22"/>
|
||||
<!-- Inner border (animated) -->
|
||||
<rect x={bx} y={by} width={BAG_W} height={BAG_H} rx="2.5"
|
||||
fill="none" stroke={cc} stroke-width="1.8"
|
||||
class={bag.vision.contamination_risk === 'high' ? 'contam-high' : 'contam-low'}/>
|
||||
{/if}
|
||||
{:else}
|
||||
<!-- Empty slot -->
|
||||
<rect x={bx} y={by} width={BAG_W} height={BAG_H} rx="2.5"
|
||||
fill="#181e16" fill-opacity="0.55"
|
||||
stroke="#3a4236" stroke-width="1"
|
||||
stroke-dasharray="3 3" stroke-opacity="0.65"/>
|
||||
<line x1={bx + BAG_W/2 - 6} y1={by + BAG_H/2}
|
||||
x2={bx + BAG_W/2 + 6} y2={by + BAG_H/2}
|
||||
stroke="#4a5244" stroke-width="1" stroke-opacity="0.5"/>
|
||||
<line x1={bx + BAG_W/2} y1={by + BAG_H/2 - 6}
|
||||
x2={bx + BAG_W/2} y2={by + BAG_H/2 + 6}
|
||||
stroke="#4a5244" stroke-width="1" stroke-opacity="0.5"/>
|
||||
{/if}
|
||||
{/each}
|
||||
{/each}
|
||||
|
||||
<!-- HARDWARE: Fan -->
|
||||
<g transform="translate(162, 122)">
|
||||
<circle r="9" fill="#090e0a" stroke="#1e2820" stroke-width="0.7"/>
|
||||
<g class="fan-blades" class:spinning={fanSpinning}
|
||||
style="--fan-dur: {fanDur}">
|
||||
{#each [0, 90, 180, 270] as a}
|
||||
<path transform="rotate({a})"
|
||||
d="M0,-1 Q2,-4.5 0,-8 Q-2,-4.5 0,-1 Z"
|
||||
fill={fanSpinning ? '#52cb78' : '#323a2e'}
|
||||
fill-opacity={fanSpinning ? 0.8 : 0.4}/>
|
||||
{/each}
|
||||
</g>
|
||||
<circle r="1.8" fill="#1a2018"/>
|
||||
<circle r="9" fill="none"
|
||||
stroke={fanSpinning ? '#52cb78' : '#2a3428'}
|
||||
stroke-width="0.6" stroke-opacity={fanSpinning ? 0.55 : 0.2}/>
|
||||
</g>
|
||||
|
||||
<!-- HARDWARE: Humidifier -->
|
||||
<g transform="translate(162, 160)">
|
||||
<circle r="5"
|
||||
fill={humidOn ? '#0e2e2c' : '#0a0e0b'}
|
||||
fill-opacity="0.9"
|
||||
stroke={humidOn ? '#18c8b2' : '#1e2820'}
|
||||
stroke-width="0.6" stroke-opacity={humidOn ? 0.7 : 0.3}/>
|
||||
{#each [-1.5, 0, 1.5] as dx}
|
||||
<path d="M{dx},-2 Q{dx + 1},0 {dx},2"
|
||||
fill="none"
|
||||
stroke={humidOn ? '#18c8b2' : '#2a3428'}
|
||||
stroke-width="0.6" stroke-opacity={humidOn ? 0.8 : 0.25}/>
|
||||
{/each}
|
||||
</g>
|
||||
|
||||
<!-- HARDWARE: Heater -->
|
||||
<g transform="translate(162, 185)">
|
||||
<circle r="4"
|
||||
fill={heaterOn ? '#2e0e10' : '#0a0e0b'}
|
||||
fill-opacity="0.9"
|
||||
stroke={heaterOn ? '#e43a4c' : '#1e2820'}
|
||||
stroke-width="0.6" stroke-opacity={heaterOn ? 0.65 : 0.25}/>
|
||||
{#if heaterOn}
|
||||
{#each [0, 2, 4] as dy}
|
||||
<line x1="-2.5" y1={dy - 2} x2="2.5" y2={dy - 2}
|
||||
stroke="#e43a4c" stroke-width="0.6" stroke-opacity="0.7"/>
|
||||
{/each}
|
||||
{/if}
|
||||
</g>
|
||||
|
||||
<!-- MIST PARTICLES -->
|
||||
{#if humidOn}
|
||||
{#each [42, 78, 114] as mx, i}
|
||||
<circle cx={mx} cy="0" r="0" fill="#18c8b2">
|
||||
<animate attributeName="cy" values="248;82" dur="4.5s" begin="{i * 1.5}s" repeatCount="indefinite"/>
|
||||
<animate attributeName="r" values="1.5;4" dur="4.5s" begin="{i * 1.5}s" repeatCount="indefinite"/>
|
||||
<animate attributeName="opacity" values="0;0.3;0.22;0" keyTimes="0;0.08;0.75;1"
|
||||
dur="4.5s" begin="{i * 1.5}s" repeatCount="indefinite"/>
|
||||
</circle>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<!-- BOTTOM EDGES -->
|
||||
<line x1="28" y1="250" x2="152" y2="250" stroke="#222a20" stroke-width="0.8"/>
|
||||
<line x1="152" y1="250" x2="172" y2="238" stroke="#222a20" stroke-width="0.8"/>
|
||||
</svg>
|
||||
|
||||
<!-- Env stats pills -->
|
||||
<div class="env-pills">
|
||||
<div class="env-pill temp-pill">
|
||||
<span class="pv">{temp}°</span>
|
||||
<span class="pk">Temp</span>
|
||||
</div>
|
||||
<div class="env-pill rh-pill">
|
||||
<span class="pv">{rh}%</span>
|
||||
<span class="pk">RH</span>
|
||||
</div>
|
||||
<div class="env-pill co2-pill">
|
||||
<span class="pv">{co2}</span>
|
||||
<span class="pk">{co2Label}</span>
|
||||
</div>
|
||||
<div class="env-pill voc-pill">
|
||||
<span class="pv">{voc}</span>
|
||||
<span class="pk">VOC</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ch-name {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 14px;
|
||||
letter-spacing: 0.02em;
|
||||
color: var(--color-text);
|
||||
padding: 0 2px;
|
||||
}
|
||||
|
||||
.iso {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* ── Env pills ── */
|
||||
.env-pills {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 0 2px;
|
||||
}
|
||||
|
||||
.env-pill {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 5px 3px 4px;
|
||||
background: rgba(255, 255, 255, 0.025);
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-top-width: 2px;
|
||||
}
|
||||
|
||||
.temp-pill { border-top-color: var(--color-sage); }
|
||||
.rh-pill { border-top-color: var(--color-pinning); }
|
||||
.co2-pill { border-top-color: var(--color-fruiting); }
|
||||
.voc-pill { border-top-color: var(--color-text-muted); }
|
||||
|
||||
.pv {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
color: var(--color-text);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pk {
|
||||
font-size: 7px;
|
||||
letter-spacing: 0.09em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-muted);
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ── Fan animation ── */
|
||||
.fan-blades {
|
||||
transform-box: fill-box;
|
||||
transform-origin: 50% 50%;
|
||||
}
|
||||
.fan-blades.spinning {
|
||||
animation: fan-spin var(--fan-dur) linear infinite;
|
||||
}
|
||||
|
||||
@keyframes fan-spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* ── Contamination outline pulse ── */
|
||||
.contam-high {
|
||||
animation: contam-pulse-high 2s ease-in-out infinite;
|
||||
}
|
||||
.contam-low {
|
||||
animation: contam-pulse-low 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes contam-pulse-high {
|
||||
0%, 100% { stroke-opacity: 0.9; }
|
||||
50% { stroke-opacity: 0.3; }
|
||||
}
|
||||
@keyframes contam-pulse-low {
|
||||
0%, 100% { stroke-opacity: 0.75; }
|
||||
50% { stroke-opacity: 0.25; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
import IsoChamber from './IsoChamber.svelte';
|
||||
|
||||
const chambers = $derived(cultivar.state.chambers);
|
||||
</script>
|
||||
|
||||
<div class="twin">
|
||||
{#each chambers as chamber (chamber.id)}
|
||||
<div class="twin-col">
|
||||
<IsoChamber {chamber} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.twin {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 12px 14px;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.twin-col {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 639px) {
|
||||
.twin {
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,542 @@
|
||||
<script lang="ts">
|
||||
import type { BagAnnotation } from '../types';
|
||||
|
||||
interface Props {
|
||||
colonizationPct: number;
|
||||
contaminationRisk: 'none' | 'low' | 'medium' | 'high';
|
||||
stage: 'inoculation' | 'colonization' | 'pinning' | 'fruiting' | 'harvest';
|
||||
annotations?: BagAnnotation[];
|
||||
strainCode?: string;
|
||||
inoculatedTs?: number;
|
||||
}
|
||||
|
||||
const {
|
||||
colonizationPct,
|
||||
contaminationRisk,
|
||||
stage,
|
||||
annotations = [],
|
||||
strainCode = '',
|
||||
inoculatedTs,
|
||||
}: Props = $props();
|
||||
|
||||
const W = 300;
|
||||
const H = 460;
|
||||
|
||||
// Bag body (clear plastic, grain fills it entirely)
|
||||
const BX = 48;
|
||||
const BY = 28;
|
||||
const BW = 204;
|
||||
const BH = 404;
|
||||
|
||||
// Gas exchange filter patch (top, opaque white fabric)
|
||||
const FILTER_W = 76;
|
||||
const FILTER_H = 58;
|
||||
const FILTER_X = W / 2 - FILTER_W / 2;
|
||||
const FILTER_Y = BY + 28;
|
||||
|
||||
// BagTag (center, semi-transparent carrier, QR + QuroCode stacked)
|
||||
const TAG_W = 116;
|
||||
const TAG_H = 200;
|
||||
const TAG_X = W / 2 - TAG_W / 2;
|
||||
const TAG_Y = BY + 130;
|
||||
const CODE_W = TAG_W - 10; // 106
|
||||
const CODE_H = (TAG_H - 22) / 2; // 89
|
||||
|
||||
// Injection port (bottom, gray rounded square)
|
||||
const PORT_W = 28;
|
||||
const PORT_H = 28;
|
||||
const PORT_X = W / 2 - PORT_W / 2;
|
||||
const PORT_Y = BY + BH - 56;
|
||||
|
||||
const coverage = $derived(Math.max(0, Math.min(100, colonizationPct)) / 100);
|
||||
|
||||
const myceliumTint = $derived.by(() => {
|
||||
if (contaminationRisk === 'high') return '#d46868';
|
||||
if (contaminationRisk === 'low') return '#d4a368';
|
||||
if (stage === 'fruiting') return '#d6ebe1';
|
||||
if (stage === 'pinning') return '#d4e3ea';
|
||||
return '#f4f2e0';
|
||||
});
|
||||
|
||||
const substrateZone = { x: BX + 6, y: BY + 6, w: BW - 12, h: BH - 12 };
|
||||
|
||||
// QuroCode Y position (computed once here to avoid {@const} at template level)
|
||||
const QURO_Y = TAG_Y + 6 + CODE_H + 11;
|
||||
|
||||
// Mycelium bubbles spread across the grain substrate
|
||||
const bubbles = [
|
||||
{ cx: 0.22, cy: 0.12, r: 0.22 },
|
||||
{ cx: 0.72, cy: 0.10, r: 0.24 },
|
||||
{ cx: 0.48, cy: 0.28, r: 0.27 },
|
||||
{ cx: 0.18, cy: 0.42, r: 0.20 },
|
||||
{ cx: 0.80, cy: 0.45, r: 0.22 },
|
||||
{ cx: 0.42, cy: 0.60, r: 0.23 },
|
||||
{ cx: 0.74, cy: 0.74, r: 0.20 },
|
||||
{ cx: 0.24, cy: 0.76, r: 0.19 },
|
||||
{ cx: 0.55, cy: 0.88, r: 0.18 },
|
||||
];
|
||||
|
||||
// Grain particles (deterministic, stable)
|
||||
const grains = Array.from({ length: 88 }).map((_, i) => ({
|
||||
cx: BX + 8 + ((i * 37 + 11) % 97) / 97 * (BW - 16),
|
||||
cy: BY + 8 + ((i * 53 + 7) % 100) / 100 * (BH - 16),
|
||||
rx: 2.8 + ((i * 7) % 5) * 0.5,
|
||||
ry: 1.2 + ((i * 3) % 3) * 0.3,
|
||||
rot: ((i * 41) % 180) - 90,
|
||||
op: 0.45 + ((i * 13) % 4) * 0.06,
|
||||
}));
|
||||
|
||||
// Hyphae particles (deterministic)
|
||||
const hyphae = Array.from({ length: 28 }).map((_, i) => ({
|
||||
px: ((i * 37) % 100) / 100,
|
||||
py: ((i * 53) % 100) / 100,
|
||||
len: 2.5 + ((i * 11) % 5),
|
||||
angle: (i * 29) % 360,
|
||||
}));
|
||||
|
||||
// QR module pattern (deterministic)
|
||||
function qrOn(r: number, c: number, grid: number): boolean {
|
||||
const inTL = r < 4 && c < 4;
|
||||
const inTR = r < 4 && c > grid - 5;
|
||||
const inBL = r > grid - 5 && c < 4;
|
||||
if (inTL || inTR || inBL) return false;
|
||||
return ((r * 17 + c * 13 + 5) % 11) < 5;
|
||||
}
|
||||
|
||||
// QuroCode module pattern (dark bg, large white modules)
|
||||
function quroOn(r: number, c: number, grid: number): boolean {
|
||||
const inTL = r < 3 && c < 3;
|
||||
const inTR = r < 3 && c > grid - 4;
|
||||
const inBL = r > grid - 4 && c < 3;
|
||||
if (inTL || inTR || inBL) return false;
|
||||
return ((r * 11 + c * 7 + 3) % 9) < 4;
|
||||
}
|
||||
|
||||
const annotColor: Record<string, string> = {
|
||||
mycelium: '#f4f2e0',
|
||||
contamination: '#c94040',
|
||||
fruiting: '#4a9e8a',
|
||||
pinning: '#3a7a8e',
|
||||
};
|
||||
|
||||
function formatDate(ts: number | undefined): string {
|
||||
if (!ts) return '';
|
||||
return new Date(ts * 1000).toLocaleDateString([], { month: 'short', day: 'numeric' });
|
||||
}
|
||||
|
||||
const showContam = $derived(contaminationRisk !== 'none');
|
||||
const showFruits = $derived(stage === 'fruiting' || stage === 'harvest');
|
||||
const showPins = $derived(stage === 'pinning');
|
||||
</script>
|
||||
|
||||
<svg
|
||||
class="mushroom-bag-svg"
|
||||
viewBox="0 0 {W} {H}"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
aria-label="Mushroom cultivation bag"
|
||||
>
|
||||
<defs>
|
||||
<!-- Clear plastic: very subtle silvery tint at edges -->
|
||||
<linearGradient id="plastic" x1="0" y1="0" x2="1" y2="0">
|
||||
<stop offset="0%" stop-color="#b0b2a8" stop-opacity="0.28"/>
|
||||
<stop offset="12%" stop-color="#d8d9cf" stop-opacity="0.14"/>
|
||||
<stop offset="88%" stop-color="#d0d2c8" stop-opacity="0.12"/>
|
||||
<stop offset="100%" stop-color="#9fa198" stop-opacity="0.32"/>
|
||||
</linearGradient>
|
||||
|
||||
<!-- Grain substrate gradient -->
|
||||
<linearGradient id="grain-bg" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#3e3020"/>
|
||||
<stop offset="50%" stop-color="#4a3a24"/>
|
||||
<stop offset="100%" stop-color="#2e2416"/>
|
||||
</linearGradient>
|
||||
|
||||
<!-- Mycelium bubble (soft glow sphere) -->
|
||||
<radialGradient id="bubble" cx="42%" cy="35%">
|
||||
<stop offset="0%" stop-color={myceliumTint} stop-opacity="0.96"/>
|
||||
<stop offset="40%" stop-color={myceliumTint} stop-opacity="0.78"/>
|
||||
<stop offset="80%" stop-color={myceliumTint} stop-opacity="0.25"/>
|
||||
<stop offset="100%" stop-color={myceliumTint} stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
|
||||
<!-- Pearl highlight on bubble -->
|
||||
<radialGradient id="pearl" cx="50%" cy="50%">
|
||||
<stop offset="0%" stop-color="white" stop-opacity="0.9"/>
|
||||
<stop offset="70%" stop-color="white" stop-opacity="0.2"/>
|
||||
<stop offset="100%" stop-color="white" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
|
||||
<!-- Filter patch fabric -->
|
||||
<pattern id="filter-fabric" x="0" y="0" width="3.5" height="3.5" patternUnits="userSpaceOnUse">
|
||||
<rect width="3.5" height="3.5" fill="#e8e4d4"/>
|
||||
<circle cx="1" cy="1" r="0.32" fill="#b0ad9a" opacity="0.55"/>
|
||||
<circle cx="2.5" cy="2.5" r="0.32" fill="#b0ad9a" opacity="0.55"/>
|
||||
</pattern>
|
||||
|
||||
<!-- Bag bg glow -->
|
||||
<radialGradient id="bag-glow" cx="50%" cy="48%" r="52%">
|
||||
<stop offset="0%" stop-color={myceliumTint} stop-opacity="0.055"/>
|
||||
<stop offset="100%" stop-color={myceliumTint} stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
|
||||
<!-- Bag body clip -->
|
||||
<clipPath id="bag-clip">
|
||||
<path d={`M ${BX + 10} ${BY}
|
||||
Q ${BX} ${BY} ${BX} ${BY + 10}
|
||||
L ${BX} ${BY + BH - 14}
|
||||
Q ${BX} ${BY + BH} ${BX + 14} ${BY + BH}
|
||||
L ${BX + BW - 14} ${BY + BH}
|
||||
Q ${BX + BW} ${BY + BH} ${BX + BW} ${BY + BH - 14}
|
||||
L ${BX + BW} ${BY + 10}
|
||||
Q ${BX + BW} ${BY} ${BX + BW - 10} ${BY}
|
||||
Z`}/>
|
||||
</clipPath>
|
||||
|
||||
<!-- Plastic edge highlight -->
|
||||
<linearGradient id="edge-shine" x1="0" y1="0" x2="1" y2="0">
|
||||
<stop offset="0%" stop-color="white" stop-opacity="0"/>
|
||||
<stop offset="8%" stop-color="white" stop-opacity="0.1"/>
|
||||
<stop offset="16%" stop-color="white" stop-opacity="0"/>
|
||||
<stop offset="84%" stop-color="white" stop-opacity="0"/>
|
||||
<stop offset="92%" stop-color="white" stop-opacity="0.08"/>
|
||||
<stop offset="100%" stop-color="white" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
|
||||
<!-- Heat seal at top -->
|
||||
<linearGradient id="heat-seal" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#9fa198" stop-opacity="0.6"/>
|
||||
<stop offset="100%" stop-color="#9fa198" stop-opacity="0.1"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<!-- Background glow -->
|
||||
<rect width={W} height={H} fill="url(#bag-glow)"/>
|
||||
|
||||
<!-- Drop shadow -->
|
||||
<ellipse cx={W/2} cy={BY+BH+10} rx={BW*0.46} ry="7" fill="#000" opacity="0.4"/>
|
||||
|
||||
<!-- ===== BAG BODY ===== -->
|
||||
<g clip-path="url(#bag-clip)">
|
||||
<!-- Grain substrate (fills bag) -->
|
||||
<rect x={BX} y={BY} width={BW} height={BH} fill="url(#grain-bg)"/>
|
||||
|
||||
<!-- Grain particles -->
|
||||
<g>
|
||||
{#each grains as g, i (i)}
|
||||
<ellipse
|
||||
cx={g.cx} cy={g.cy}
|
||||
rx={g.rx} ry={g.ry}
|
||||
fill="#6a5228"
|
||||
opacity={g.op}
|
||||
transform={`rotate(${g.rot}, ${g.cx}, ${g.cy})`}
|
||||
/>
|
||||
{/each}
|
||||
</g>
|
||||
|
||||
<!-- Lighter grain highlights -->
|
||||
<g opacity="0.35">
|
||||
{#each grains as g, i (`gh-${i}`)}
|
||||
{#if i % 3 === 0}
|
||||
<ellipse
|
||||
cx={g.cx - 0.6} cy={g.cy - 0.5}
|
||||
rx={g.rx * 0.6} ry={g.ry * 0.6}
|
||||
fill="#a08040"
|
||||
opacity="0.7"
|
||||
transform={`rotate(${g.rot}, ${g.cx}, ${g.cy})`}
|
||||
/>
|
||||
{/if}
|
||||
{/each}
|
||||
</g>
|
||||
|
||||
<!-- ===== MYCELIUM COVERAGE ===== -->
|
||||
<!-- Grow bubbles across the grain substrate -->
|
||||
{#each bubbles as b, i (i)}
|
||||
{@const visible = coverage > i / bubbles.length * 0.85}
|
||||
{#if visible}
|
||||
{@const scale = 0.45 + coverage * 0.95}
|
||||
{@const ax = substrateZone.x + b.cx * substrateZone.w}
|
||||
{@const ay = substrateZone.y + b.cy * substrateZone.h}
|
||||
{@const r = b.r * Math.min(substrateZone.w, substrateZone.h * 0.7) * scale}
|
||||
<ellipse cx={ax} cy={ay} rx={r} ry={r * 0.95} fill="url(#bubble)"/>
|
||||
<!-- Pearl highlight -->
|
||||
<ellipse
|
||||
cx={ax - r * 0.26} cy={ay - r * 0.34}
|
||||
rx={r * 0.18} ry={r * 0.12}
|
||||
fill="url(#pearl)"
|
||||
/>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
<!-- Hyphae strands -->
|
||||
{#if coverage > 0.1}
|
||||
<g opacity={Math.min(0.55, coverage * 0.75)}>
|
||||
{#each hyphae as h, i (`h-${i}`)}
|
||||
{@const px = substrateZone.x + h.px * substrateZone.w}
|
||||
{@const py = substrateZone.y + h.py * substrateZone.h}
|
||||
{@const rad = h.angle * Math.PI / 180}
|
||||
<line
|
||||
x1={px} y1={py}
|
||||
x2={px + Math.cos(rad) * h.len} y2={py + Math.sin(rad) * h.len}
|
||||
stroke={myceliumTint}
|
||||
stroke-width="0.45"
|
||||
opacity="0.65"
|
||||
/>
|
||||
{/each}
|
||||
</g>
|
||||
{/if}
|
||||
|
||||
<!-- Contamination zone -->
|
||||
{#if showContam}
|
||||
<ellipse
|
||||
cx={substrateZone.x + substrateZone.w * 0.74}
|
||||
cy={substrateZone.y + substrateZone.h * 0.22}
|
||||
rx="22" ry="16"
|
||||
fill={contaminationRisk === 'high' ? '#c94040' : '#c9832a'}
|
||||
opacity="0.5"
|
||||
/>
|
||||
<ellipse
|
||||
cx={substrateZone.x + substrateZone.w * 0.76}
|
||||
cy={substrateZone.y + substrateZone.h * 0.23}
|
||||
rx="12" ry="9"
|
||||
fill={contaminationRisk === 'high' ? '#8c2020' : '#8c5a18'}
|
||||
opacity="0.65"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Pinning primordia -->
|
||||
{#if showPins}
|
||||
{#each [0.22, 0.40, 0.60, 0.78] as fx, fi (fi)}
|
||||
<circle cx={substrateZone.x + fx*substrateZone.w} cy={substrateZone.y + 8} r="3.5" fill="#cfe2ea" opacity="0.9"/>
|
||||
<circle cx={substrateZone.x + fx*substrateZone.w} cy={substrateZone.y + 7} r="1.4" fill="white" opacity="0.65"/>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<!-- Fruiting bodies -->
|
||||
{#if showFruits}
|
||||
{#each [{fx:0.22,sz:1},{fx:0.40,sz:1.3},{fx:0.60,sz:0.9},{fx:0.78,sz:1.1}] as f, fi (fi)}
|
||||
{@const cx = substrateZone.x + f.fx * substrateZone.w}
|
||||
{@const cy = substrateZone.y + 6}
|
||||
<rect x={cx - 2*f.sz} y={cy} width={4*f.sz} height={10*f.sz} fill="#e8e4d0" opacity="0.9"/>
|
||||
<ellipse cx={cx} cy={cy} rx={8*f.sz} ry={5*f.sz} fill="var(--color-fruiting)"/>
|
||||
<ellipse cx={cx} cy={cy+2} rx={6*f.sz} ry={2*f.sz} fill="#3d2a18" opacity="0.6"/>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<!-- Clear plastic overlay -->
|
||||
<rect x={BX} y={BY} width={BW} height={BH} fill="url(#plastic)"/>
|
||||
<rect x={BX} y={BY} width={BW} height={BH} fill="url(#edge-shine)"/>
|
||||
</g>
|
||||
|
||||
<!-- Bag outline -->
|
||||
<path
|
||||
d={`M ${BX + 10} ${BY}
|
||||
Q ${BX} ${BY} ${BX} ${BY + 10}
|
||||
L ${BX} ${BY + BH - 14}
|
||||
Q ${BX} ${BY + BH} ${BX + 14} ${BY + BH}
|
||||
L ${BX + BW - 14} ${BY + BH}
|
||||
Q ${BX + BW} ${BY + BH} ${BX + BW} ${BY + BH - 14}
|
||||
L ${BX + BW} ${BY + 10}
|
||||
Q ${BX + BW} ${BY} ${BX + BW - 10} ${BY}
|
||||
Z`}
|
||||
fill="none"
|
||||
stroke="#8e907e"
|
||||
stroke-width="0.9"
|
||||
stroke-opacity="0.7"
|
||||
/>
|
||||
|
||||
<!-- Top heat seal crimp -->
|
||||
<rect x={BX} y={BY} width={BW} height="8" rx="1" fill="url(#heat-seal)"/>
|
||||
<line x1={BX+4} y1={BY+3} x2={BX+BW-4} y2={BY+3} stroke="#b0b2a8" stroke-width="0.5" stroke-opacity="0.5"/>
|
||||
<line x1={BX+4} y1={BY+5.5} x2={BX+BW-4} y2={BY+5.5} stroke="#b0b2a8" stroke-width="0.4" stroke-opacity="0.3"/>
|
||||
|
||||
<!-- Gusset fold lines (side creases of flat bag) -->
|
||||
<line x1={BX+8} y1={BY+14} x2={BX+8} y2={BY+BH-12}
|
||||
stroke="#9fa198" stroke-width="0.5" stroke-opacity="0.3"/>
|
||||
<line x1={BX+BW-8} y1={BY+14} x2={BX+BW-8} y2={BY+BH-12}
|
||||
stroke="#9fa198" stroke-width="0.5" stroke-opacity="0.3"/>
|
||||
|
||||
<!-- ===== FILTER PATCH (top, opaque white fabric) ===== -->
|
||||
<rect
|
||||
x={FILTER_X} y={FILTER_Y}
|
||||
width={FILTER_W} height={FILTER_H}
|
||||
rx="2"
|
||||
fill="url(#filter-fabric)"
|
||||
stroke="#9a9888"
|
||||
stroke-width="0.7"
|
||||
/>
|
||||
<!-- Stitching border -->
|
||||
<rect
|
||||
x={FILTER_X} y={FILTER_Y}
|
||||
width={FILTER_W} height={FILTER_H}
|
||||
rx="2"
|
||||
fill="none"
|
||||
stroke="#6a6858"
|
||||
stroke-width="0.45"
|
||||
stroke-dasharray="1.8 1.4"
|
||||
opacity="0.65"
|
||||
/>
|
||||
|
||||
<!-- ===== BAGTAG (center, semi-transparent, QR + QuroCode stacked) ===== -->
|
||||
<g>
|
||||
<!-- Tag carrier (nearly transparent plastic strip — just a border hint) -->
|
||||
<rect
|
||||
x={TAG_X} y={TAG_Y}
|
||||
width={TAG_W} height={TAG_H}
|
||||
rx="2"
|
||||
fill="#888880"
|
||||
fill-opacity="0.08"
|
||||
stroke="#8a8880"
|
||||
stroke-width="0.6"
|
||||
stroke-opacity="0.4"
|
||||
/>
|
||||
|
||||
<!-- QR code (top code, white bg) -->
|
||||
<g transform={`translate(${TAG_X + 5}, ${TAG_Y + 6})`}>
|
||||
<rect width={CODE_W} height={CODE_H} rx="1" fill="#f4f2e2"/>
|
||||
|
||||
<!-- Corner locators -->
|
||||
<rect x="4" y="4" width="14" height="14" fill="#0a0b09"/>
|
||||
<rect x="6" y="6" width="10" height="10" fill="#f4f2e2"/>
|
||||
<rect x="8" y="8" width="6" height="6" fill="#0a0b09"/>
|
||||
|
||||
<rect x={CODE_W - 18} y="4" width="14" height="14" fill="#0a0b09"/>
|
||||
<rect x={CODE_W - 16} y="6" width="10" height="10" fill="#f4f2e2"/>
|
||||
<rect x={CODE_W - 14} y="8" width="6" height="6" fill="#0a0b09"/>
|
||||
|
||||
<rect x="4" y={CODE_H - 18} width="14" height="14" fill="#0a0b09"/>
|
||||
<rect x="6" y={CODE_H - 16} width="10" height="10" fill="#f4f2e2"/>
|
||||
<rect x="8" y={CODE_H - 14} width="6" height="6" fill="#0a0b09"/>
|
||||
|
||||
<!-- Timing + data modules -->
|
||||
{#each Array.from({length: 16*14}) as _, idx (idx)}
|
||||
{@const r = Math.floor(idx / 16)}
|
||||
{@const c = idx % 16}
|
||||
{@const mx = 4 + c * 6}
|
||||
{@const my = 4 + r * 5.4}
|
||||
{@const inTL = r < 3 && c < 3}
|
||||
{@const inTR = r < 3 && c > 12}
|
||||
{@const inBL = r > 10 && c < 3}
|
||||
{@const on = ((r * 23 + c * 17 + 7) % 13) < 6}
|
||||
{#if !inTL && !inTR && !inBL && on}
|
||||
<rect x={mx} y={my} width="5" height="4.4" fill="#0a0b09"/>
|
||||
{/if}
|
||||
{/each}
|
||||
</g>
|
||||
|
||||
<!-- Divider line between codes -->
|
||||
<line
|
||||
x1={TAG_X + 6} y1={TAG_Y + 6 + CODE_H + 5}
|
||||
x2={TAG_X + TAG_W - 6} y2={TAG_Y + 6 + CODE_H + 5}
|
||||
stroke="#6a6a60"
|
||||
stroke-width="0.5"
|
||||
opacity="0.5"
|
||||
/>
|
||||
|
||||
<!-- QuroCode (bottom code, dark bg + white modules) -->
|
||||
<g transform={`translate(${TAG_X + 5}, ${QURO_Y})`}>
|
||||
<rect width={CODE_W} height={CODE_H} rx="1" fill="#0a0b09"/>
|
||||
|
||||
<!-- Circular corner marks -->
|
||||
<circle cx="9" cy="9" r="6.5" fill="#0a0b09" stroke="#f0f0e0" stroke-width="1.5"/>
|
||||
<circle cx="9" cy="9" r="3.2" fill="#f0f0e0"/>
|
||||
|
||||
<circle cx={CODE_W - 9} cy="9" r="6.5" fill="#0a0b09" stroke="#f0f0e0" stroke-width="1.5"/>
|
||||
<circle cx={CODE_W - 9} cy="9" r="3.2" fill="#f0f0e0"/>
|
||||
|
||||
<circle cx="9" cy={CODE_H - 9} r="6.5" fill="#0a0b09" stroke="#f0f0e0" stroke-width="1.5"/>
|
||||
<circle cx="9" cy={CODE_H - 9} r="3.2" fill="#f0f0e0"/>
|
||||
|
||||
<!-- White data modules (large) -->
|
||||
{#each Array.from({length: 10*9}) as _, idx (idx)}
|
||||
{@const r = Math.floor(idx / 10)}
|
||||
{@const c = idx % 10}
|
||||
{@const mx = 6 + c * 9.5}
|
||||
{@const my = 6 + r * 8.4}
|
||||
{@const inTL = r < 2 && c < 2}
|
||||
{@const inTR = r < 2 && c > 7}
|
||||
{@const inBL = r > 6 && c < 2}
|
||||
{@const on = ((r * 13 + c * 11 + 5) % 9) < 4}
|
||||
{#if !inTL && !inTR && !inBL && on}
|
||||
<rect x={mx} y={my} width="7.5" height="6.5" rx="0.5" fill="#f0f0e0"/>
|
||||
{/if}
|
||||
{/each}
|
||||
</g>
|
||||
|
||||
<!-- Strain code text at bottom of tag -->
|
||||
{#if strainCode}
|
||||
<text
|
||||
x={W / 2}
|
||||
y={TAG_Y + TAG_H - 4}
|
||||
text-anchor="middle"
|
||||
font-family="var(--font-sans)"
|
||||
font-size="4"
|
||||
fill="#e0ddd0"
|
||||
letter-spacing="0.03em"
|
||||
opacity="0.85"
|
||||
>{strainCode}</text>
|
||||
{/if}
|
||||
{#if inoculatedTs}
|
||||
<text
|
||||
x={W / 2}
|
||||
y={TAG_Y + TAG_H + 6}
|
||||
text-anchor="middle"
|
||||
font-family="var(--font-sans)"
|
||||
font-size="3.5"
|
||||
fill="#8e907e"
|
||||
letter-spacing="0.06em"
|
||||
>INOC {formatDate(inoculatedTs)}</text>
|
||||
{/if}
|
||||
</g>
|
||||
|
||||
<!-- ===== INJECTION PORT (bottom, opaque gray rounded square) ===== -->
|
||||
<g>
|
||||
<rect
|
||||
x={PORT_X} y={PORT_Y}
|
||||
width={PORT_W} height={PORT_H}
|
||||
rx="4"
|
||||
fill="#7a7868"
|
||||
stroke="#5a5848"
|
||||
stroke-width="0.8"
|
||||
/>
|
||||
<!-- Port rim highlight -->
|
||||
<rect
|
||||
x={PORT_X + 2} y={PORT_Y + 2}
|
||||
width={PORT_W - 4} height={PORT_H - 4}
|
||||
rx="2"
|
||||
fill="none"
|
||||
stroke="#9a9888"
|
||||
stroke-width="0.5"
|
||||
opacity="0.6"
|
||||
/>
|
||||
<!-- Self-healing center dot -->
|
||||
<circle cx={W / 2} cy={PORT_Y + PORT_H / 2} r="3.5" fill="#4a4840"/>
|
||||
<circle cx={W / 2 - 0.8} cy={PORT_Y + PORT_H / 2 - 1} r="1.2" fill="#9a9888" opacity="0.45"/>
|
||||
</g>
|
||||
|
||||
<!-- ===== ANNOTATION OVERLAYS ===== -->
|
||||
{#if annotations.length > 0}
|
||||
{#each annotations as ann, i (i)}
|
||||
{@const ax = BX + ann.x * BW}
|
||||
{@const ay = BY + ann.y * BH}
|
||||
{@const ar = ann.radius * Math.min(BW, BH)}
|
||||
<circle
|
||||
cx={ax} cy={ay} r={ar}
|
||||
fill={annotColor[ann.type]}
|
||||
fill-opacity={ann.type === 'contamination' ? 0.18 : 0.04}
|
||||
stroke={annotColor[ann.type]}
|
||||
stroke-width={ann.type === 'contamination' ? 1.2 : 0.8}
|
||||
stroke-dasharray={ann.type === 'contamination' ? '3 2' : 'none'}
|
||||
stroke-opacity={0.35 + ann.confidence * 0.55}
|
||||
/>
|
||||
{/each}
|
||||
{/if}
|
||||
</svg>
|
||||
|
||||
<style>
|
||||
.mushroom-bag-svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,186 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
|
||||
// no props needed — opacity/sizing controlled by parent CSS
|
||||
let canvas = $state<HTMLCanvasElement | null>(null);
|
||||
let stop: (() => void) | null = null;
|
||||
|
||||
onMount(() => {
|
||||
if (canvas) stop = run(canvas);
|
||||
});
|
||||
|
||||
onDestroy(() => { stop?.(); });
|
||||
|
||||
function run(el: HTMLCanvasElement): () => void {
|
||||
const ctx = el.getContext('2d')!;
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
||||
const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
let W = 0, H = 0;
|
||||
let hyphae: Hypha[] = [];
|
||||
let lastSpawn = 0;
|
||||
let active = true;
|
||||
|
||||
function resize() {
|
||||
const r = el.getBoundingClientRect();
|
||||
W = Math.max(1, r.width);
|
||||
H = Math.max(1, r.height);
|
||||
el.width = W * dpr;
|
||||
el.height = H * dpr;
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
}
|
||||
|
||||
class Hypha {
|
||||
x: number; y: number; angle: number; gen: number;
|
||||
width: number;
|
||||
points: { x: number; y: number }[];
|
||||
maxPoints: number;
|
||||
growing = true;
|
||||
fade = 1;
|
||||
deathTimer = 0;
|
||||
lifespan: number;
|
||||
wander: number;
|
||||
speed: number;
|
||||
branchProb: number;
|
||||
stepsSinceBranch = 0;
|
||||
|
||||
constructor(x: number, y: number, angle: number, gen: number) {
|
||||
this.x = x; this.y = y; this.angle = angle; this.gen = gen;
|
||||
this.width = Math.max(0.28, 1.05 - gen * 0.22);
|
||||
this.points = [{ x, y }];
|
||||
this.maxPoints = gen === 0 ? 320 + Math.random() * 240
|
||||
: gen === 1 ? 180 + Math.random() * 120
|
||||
: 90 + Math.random() * 80;
|
||||
this.lifespan = 500 + Math.random() * 300;
|
||||
this.wander = 0.12 + Math.random() * 0.14;
|
||||
this.speed = 0.40 + Math.random() * 0.35 + (gen === 0 ? 0.10 : 0);
|
||||
this.branchProb = gen < 2 ? 0.020 : gen < 4 ? 0.010 : 0.003;
|
||||
}
|
||||
|
||||
step(spawned: Hypha[]): boolean {
|
||||
if (this.growing) {
|
||||
this.angle += (Math.random() - 0.5) * this.wander;
|
||||
this.x += Math.cos(this.angle) * this.speed;
|
||||
this.y += Math.sin(this.angle) * this.speed;
|
||||
this.points.push({ x: this.x, y: this.y });
|
||||
this.stepsSinceBranch++;
|
||||
|
||||
if (this.x < -20 || this.x > W + 20 || this.y < -20 || this.y > H + 20)
|
||||
this.growing = false;
|
||||
if (this.points.length >= this.maxPoints)
|
||||
this.growing = false;
|
||||
|
||||
if (this.gen < 5 && this.stepsSinceBranch > 12 && Math.random() < this.branchProb) {
|
||||
const dir = Math.random() < 0.5 ? -1 : 1;
|
||||
spawned.push(new Hypha(this.x, this.y, this.angle + dir * (0.5 + Math.random() * 0.55), this.gen + 1));
|
||||
this.stepsSinceBranch = 0;
|
||||
}
|
||||
} else {
|
||||
this.deathTimer++;
|
||||
this.fade = Math.max(0, 1 - this.deathTimer / this.lifespan);
|
||||
}
|
||||
return this.fade > 0;
|
||||
}
|
||||
|
||||
draw() {
|
||||
if (this.points.length < 2) return;
|
||||
const a = this.fade;
|
||||
ctx.lineCap = 'round';
|
||||
ctx.lineJoin = 'round';
|
||||
|
||||
// Main filament — brighter than original for overlay use
|
||||
ctx.strokeStyle = `rgba(215, 228, 210, ${0.18 * a})`;
|
||||
ctx.lineWidth = this.width;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.points[0].x, this.points[0].y);
|
||||
for (let i = 1; i < this.points.length; i++)
|
||||
ctx.lineTo(this.points[i].x, this.points[i].y);
|
||||
ctx.stroke();
|
||||
|
||||
if (this.growing && this.points.length > 4) {
|
||||
const tipLen = Math.min(10, this.points.length - 1);
|
||||
const start = this.points.length - 1 - tipLen;
|
||||
|
||||
// Growing tip — sage-tinted
|
||||
ctx.strokeStyle = `rgba(150, 210, 155, ${0.45 * a})`;
|
||||
ctx.lineWidth = this.width * 1.15;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.points[start].x, this.points[start].y);
|
||||
for (let i = start + 1; i < this.points.length; i++)
|
||||
ctx.lineTo(this.points[i].x, this.points[i].y);
|
||||
ctx.stroke();
|
||||
|
||||
// Tip node
|
||||
const tip = this.points[this.points.length - 1];
|
||||
ctx.fillStyle = `rgba(170, 220, 170, ${0.55 * a})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(tip.x, tip.y, this.width * 1.4, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function spawn() {
|
||||
const fromSide = Math.random() < 0.6;
|
||||
let x: number, y: number, angle: number;
|
||||
if (fromSide) {
|
||||
if (Math.random() < 0.5) { x = -2; angle = (Math.random() - 0.5) * 0.9; }
|
||||
else { x = W + 2; angle = Math.PI + (Math.random() - 0.5) * 0.9; }
|
||||
y = Math.random() * H;
|
||||
} else {
|
||||
x = Math.random() * W;
|
||||
if (Math.random() < 0.5) { y = -2; angle = Math.PI / 2 + (Math.random() - 0.5) * 0.9; }
|
||||
else { y = H + 2; angle = -Math.PI / 2 + (Math.random() - 0.5) * 0.9; }
|
||||
}
|
||||
hyphae.push(new Hypha(x, y, angle, 0));
|
||||
}
|
||||
|
||||
function frame(t: number) {
|
||||
if (!active) return;
|
||||
if (!W || !H) { requestAnimationFrame(frame); return; }
|
||||
ctx.clearRect(0, 0, W, H);
|
||||
|
||||
const target = Math.max(2, Math.floor(W / 150));
|
||||
const liveTrunks = hyphae.reduce((n, h) => n + (h.gen === 0 && h.growing ? 1 : 0), 0);
|
||||
if (liveTrunks < target && t - lastSpawn > 400) { spawn(); lastSpawn = t; }
|
||||
|
||||
const next: Hypha[] = [];
|
||||
for (const h of hyphae) {
|
||||
const alive = h.step(next);
|
||||
h.draw();
|
||||
if (alive) next.push(h);
|
||||
}
|
||||
hyphae = next;
|
||||
requestAnimationFrame(frame);
|
||||
}
|
||||
|
||||
const ro = new ResizeObserver(resize);
|
||||
ro.observe(el);
|
||||
resize();
|
||||
|
||||
if (reduced) {
|
||||
for (let i = 0; i < 10; i++) spawn();
|
||||
for (let s = 0; s < 200; s++) {
|
||||
const next: Hypha[] = [];
|
||||
for (const h of hyphae) { if (h.step(next)) next.push(h); }
|
||||
hyphae = next;
|
||||
}
|
||||
for (const h of hyphae) { h.growing = false; h.draw(); }
|
||||
} else {
|
||||
for (let i = 0; i < 2; i++) spawn();
|
||||
requestAnimationFrame(frame);
|
||||
}
|
||||
|
||||
return () => { active = false; ro.disconnect(); };
|
||||
}
|
||||
</script>
|
||||
|
||||
<canvas bind:this={canvas}></canvas>
|
||||
|
||||
<style>
|
||||
canvas {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,139 @@
|
||||
export type TimeSeriesPoint = { ts: number; value: number };
|
||||
|
||||
export type BagAnnotation = {
|
||||
type: 'mycelium' | 'contamination' | 'fruiting' | 'pinning';
|
||||
x: number;
|
||||
y: number;
|
||||
radius: number;
|
||||
confidence: number;
|
||||
};
|
||||
|
||||
export type BagSnapshot = {
|
||||
ts: number;
|
||||
image_url: string;
|
||||
colonization_pct: number;
|
||||
contamination_risk: 'none' | 'low' | 'medium' | 'high';
|
||||
annotations: BagAnnotation[];
|
||||
};
|
||||
|
||||
export type BagVision = {
|
||||
colonization_pct: number;
|
||||
colonization_confidence: number;
|
||||
contamination_risk: 'none' | 'low' | 'medium' | 'high';
|
||||
stage: 'inoculation' | 'colonization' | 'pinning' | 'fruiting' | 'harvest';
|
||||
snapshots: BagSnapshot[];
|
||||
projection: {
|
||||
estimated_ready_ts: number;
|
||||
colonization_curve: TimeSeriesPoint[];
|
||||
};
|
||||
};
|
||||
|
||||
export type BagTag = {
|
||||
strain_code: string;
|
||||
strain_name: string; // human-friendly name: "Blue Oyster", "Lion's Mane"
|
||||
substrate: string;
|
||||
inoculated_ts: number;
|
||||
batch_id: string;
|
||||
};
|
||||
|
||||
export type BagState = {
|
||||
bag_id: string;
|
||||
slot_id: string;
|
||||
tag: BagTag;
|
||||
vision: BagVision;
|
||||
};
|
||||
|
||||
export type ChamberSlot = {
|
||||
slot_id: string;
|
||||
position: { x: number; y: number; z: number };
|
||||
bag: BagState | null;
|
||||
};
|
||||
|
||||
export type ChamberEnvironment = {
|
||||
temp_c: number;
|
||||
rh_pct: number;
|
||||
co2_ppm?: number; // fruiting chamber
|
||||
co2e_ppm?: number; // colonization chamber
|
||||
voc_ppb: number;
|
||||
};
|
||||
|
||||
export type Chamber = {
|
||||
id: string;
|
||||
label: string;
|
||||
type: 'colonization' | 'fruiting';
|
||||
environment: ChamberEnvironment;
|
||||
slots: ChamberSlot[];
|
||||
};
|
||||
|
||||
export type EnvironmentReading = {
|
||||
ts: number;
|
||||
temp_c: number;
|
||||
rh_pct: number;
|
||||
co2_ppm: number;
|
||||
co2e_ppm?: number;
|
||||
voc_ppb: number;
|
||||
vpd: number;
|
||||
};
|
||||
|
||||
export type RecipeStage = 'inoculation' | 'colonization' | 'pinning' | 'fruiting' | 'harvest';
|
||||
|
||||
export type CultivarState = {
|
||||
meta: {
|
||||
device_id: string;
|
||||
firmware_version: string;
|
||||
uptime_s: number;
|
||||
wifi_rssi: number;
|
||||
timestamp_utc: number;
|
||||
};
|
||||
environment: {
|
||||
history: EnvironmentReading[];
|
||||
live: Omit<EnvironmentReading, 'ts'>;
|
||||
targets: { temp_c: number; rh_pct: number; co2_ppm: number };
|
||||
alerts: Array<{
|
||||
id: string;
|
||||
type: string;
|
||||
severity: 'info' | 'warn' | 'critical';
|
||||
message: string;
|
||||
ts: number;
|
||||
dismissed: boolean;
|
||||
}>;
|
||||
};
|
||||
chambers: Chamber[];
|
||||
hardware: {
|
||||
fans: Array<{ id: string; speed_pct: number; mode: 'auto' | 'manual' }>;
|
||||
heater: { active: boolean; duty_cycle: number };
|
||||
humidifier: { active: boolean; mode: 'auto' | 'manual' };
|
||||
leds: { mode: string; color_hex: string; brightness: number };
|
||||
cameras: Array<{ id: string; position: string; last_capture_ts: number }>;
|
||||
};
|
||||
recipe: {
|
||||
id: string;
|
||||
name: string;
|
||||
species: string;
|
||||
stage: RecipeStage;
|
||||
stage_started_ts: number;
|
||||
stage_target_duration_h: number;
|
||||
stage_history: Array<{ stage: RecipeStage; started_ts: number; ended_ts: number | null }>;
|
||||
next_actions: Array<{ type: string; due_ts: number; description: string }>;
|
||||
};
|
||||
ui: {
|
||||
scrubber_ts: number | null;
|
||||
selected_bag_id: string | null;
|
||||
onboarding_complete: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
export type WsDiff = {
|
||||
t: number;
|
||||
e?: { temp?: number; rh?: number; co2?: number; voc?: number; vpd?: number };
|
||||
hw?: { fans?: number[]; heater?: boolean; humidifier?: boolean };
|
||||
};
|
||||
|
||||
// Friendly stage names for display
|
||||
export const STAGE_LABELS: Record<BagVision['stage'], string> = {
|
||||
inoculation: 'Inoculated',
|
||||
colonization: 'Growing',
|
||||
pinning: 'Pinning',
|
||||
fruiting: 'Fruiting',
|
||||
harvest: 'Ready',
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
|
||||
const activeAlerts = $derived(
|
||||
cultivar.state.environment.alerts.filter((a: { dismissed: boolean }) => !a.dismissed)
|
||||
);
|
||||
|
||||
const severityIcon: Record<string, string> = {
|
||||
info: '○',
|
||||
warn: '△',
|
||||
critical: '✕',
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if activeAlerts.length > 0}
|
||||
<div class="alert-bar">
|
||||
{#each activeAlerts as alert (alert.id)}
|
||||
<div class="alert alert-{alert.severity}">
|
||||
<span class="alert-icon">{severityIcon[alert.severity]}</span>
|
||||
<span class="alert-type">{alert.type.replace(/_/g, ' ')}</span>
|
||||
<button class="dismiss" onclick={() => cultivar.dismissAlert(alert.id)} aria-label="Dismiss">×</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.alert-bar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 7px 16px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.alert-info { background: color-mix(in srgb, var(--color-sage) 12%, transparent); color: var(--color-sage); }
|
||||
.alert-warn { background: color-mix(in srgb, var(--color-contam-low) 12%, transparent); color: var(--color-contam-low); }
|
||||
.alert-critical { background: color-mix(in srgb, var(--color-contam-high) 12%, transparent); color: var(--color-contam-high); }
|
||||
|
||||
.alert-icon { font-size: 10px; }
|
||||
.alert-type { flex: 1; text-transform: capitalize; letter-spacing: 0.03em; }
|
||||
|
||||
.dismiss {
|
||||
font-size: 14px;
|
||||
opacity: 0.6;
|
||||
line-height: 1;
|
||||
padding: 2px 4px;
|
||||
border-radius: var(--radius-sm);
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
.dismiss:hover { opacity: 1; }
|
||||
</style>
|
||||
@@ -0,0 +1,174 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
import LineChart from '../charts/LineChart.svelte';
|
||||
import type { TimeSeriesPoint, EnvironmentReading } from '../types';
|
||||
|
||||
type Win = '1h' | '6h' | '24h';
|
||||
let activeWin = $state<Win>('24h');
|
||||
const winPts: Record<Win, number> = { '1h': 60, '6h': 360, '24h': 1441 };
|
||||
const winStep: Record<Win, number> = { '1h': 1, '6h': 4, '24h': 12 };
|
||||
// Minimum ms between chart redraws per window (1h = every tick, 6h = 30s, 24h = 2min)
|
||||
const winMs: Record<Win, number> = { '1h': 0, '6h': 30_000, '24h': 120_000 };
|
||||
|
||||
const history = $derived(cultivar.state.environment.history);
|
||||
const targets = $derived(cultivar.state.environment.targets);
|
||||
// live values always track the latest point regardless of chart throttle
|
||||
const live = $derived(history[history.length - 1]);
|
||||
|
||||
// Throttled snapshot: chart data only re-renders when window demands it.
|
||||
// The effect subscribes to history (runs every 3s) but commits a new snapshot
|
||||
// only when enough time has elapsed — or immediately when the user switches windows.
|
||||
let chartSnap = $state(cultivar.state.environment.history.slice());
|
||||
let snapMs = 0;
|
||||
let snapWin: Win = '24h';
|
||||
|
||||
$effect(() => {
|
||||
const h = cultivar.state.environment.history; // reactive — runs on each tick
|
||||
const win = activeWin; // reactive — runs on window change
|
||||
const now = Date.now();
|
||||
if (win !== snapWin || now - snapMs >= winMs[win]) {
|
||||
chartSnap = h.slice();
|
||||
snapMs = now;
|
||||
snapWin = win;
|
||||
}
|
||||
});
|
||||
|
||||
const pts = $derived(winPts[activeWin]);
|
||||
const step = $derived(winStep[activeWin]);
|
||||
|
||||
function scoreReading(r: EnvironmentReading): number {
|
||||
const tP = Math.min(Math.abs(r.temp_c - targets.temp_c) / 3, 1) * 33;
|
||||
const rP = Math.min(Math.abs(r.rh_pct - targets.rh_pct) / 10, 1) * 34;
|
||||
const cP = Math.min(Math.abs((r.co2_ppm ?? r.co2e_ppm ?? 0) - targets.co2_ppm) / 500, 1) * 33;
|
||||
return Math.max(0, Math.round(100 - tP - rP - cP));
|
||||
}
|
||||
|
||||
function slice(key: keyof EnvironmentReading): TimeSeriesPoint[] {
|
||||
return chartSnap.slice(-pts)
|
||||
.filter((_, i) => i % step === 0)
|
||||
.map(r => ({ ts: r.ts, value: r[key] as number }));
|
||||
}
|
||||
|
||||
const healthSeries = $derived(
|
||||
chartSnap.slice(-pts)
|
||||
.filter((_, i) => i % step === 0)
|
||||
.map(r => ({ ts: r.ts, value: scoreReading(r) }))
|
||||
);
|
||||
|
||||
const currentScore = $derived(
|
||||
healthSeries.length > 0 ? healthSeries[healthSeries.length - 1].value : 100
|
||||
);
|
||||
|
||||
const scoreColor = $derived(
|
||||
currentScore >= 80 ? 'var(--color-sage)'
|
||||
: currentScore >= 50 ? 'var(--color-contam-low)'
|
||||
: 'var(--color-contam-high)'
|
||||
);
|
||||
|
||||
const sensors = $derived([
|
||||
{ label: 'Temp', value: live ? `${live.temp_c.toFixed(1)}°` : '—', data: slice('temp_c'), color: 'var(--color-sage)', target: targets.temp_c },
|
||||
{ label: 'Humidity', value: live ? `${live.rh_pct.toFixed(0)}%` : '—', data: slice('rh_pct'), color: 'var(--color-pinning)', target: targets.rh_pct },
|
||||
{ label: 'CO₂e', value: live ? `${(live.co2e_ppm ?? 0).toFixed(0)} ppm` : '—', data: chartSnap.slice(-pts).filter((_, i) => i % step === 0).map(r => ({ ts: r.ts, value: r.co2e_ppm ?? 0 })), color: 'var(--color-fruiting)', target: targets.co2_ppm },
|
||||
{ label: 'CO₂', value: live ? `${live.co2_ppm.toFixed(0)} ppm` : '—', data: slice('co2_ppm'), color: 'var(--color-fruiting)', target: null },
|
||||
{ label: 'VOC', value: live ? `${live.voc_ppb.toFixed(0)} ppb` : '—', data: slice('voc_ppb'), color: 'var(--color-text-muted)', target: null },
|
||||
]);
|
||||
</script>
|
||||
|
||||
<div class="panel">
|
||||
<!-- Time window tabs -->
|
||||
<div class="tabs">
|
||||
{#each (['1h', '6h', '24h'] as Win[]) as w}
|
||||
<button class="tab" class:active={activeWin === w} onclick={() => activeWin = w}>{w}</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<!-- Scrollable chart list -->
|
||||
<div class="charts">
|
||||
<!-- Health score trend -->
|
||||
<div class="chart-row health-row">
|
||||
<LineChart
|
||||
data={healthSeries}
|
||||
label="Health"
|
||||
value={String(currentScore)}
|
||||
color={scoreColor}
|
||||
yMin={0}
|
||||
yMax={100}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Sensor charts -->
|
||||
{#each sensors as s}
|
||||
<div class="chart-row">
|
||||
<LineChart
|
||||
data={s.data}
|
||||
label={s.label}
|
||||
value={s.value}
|
||||
color={s.color}
|
||||
targetValue={s.target}
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* ── Tabs ── */
|
||||
.tabs {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
padding: 8px 12px 6px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
padding: 3px 10px;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--color-text-muted);
|
||||
transition: background 0.12s, color 0.12s;
|
||||
}
|
||||
.tab:hover { color: var(--color-text); background: var(--color-surface-2); }
|
||||
.tab.active { background: var(--color-surface-2); color: var(--color-sage); }
|
||||
|
||||
/* ── Chart scroll container ── */
|
||||
.charts {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 0 8px 8px;
|
||||
/* Thin scrollbar */
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--color-border) transparent;
|
||||
}
|
||||
.charts::-webkit-scrollbar { width: 4px; }
|
||||
.charts::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }
|
||||
|
||||
/* ── Chart rows — fixed heights ── */
|
||||
.chart-row {
|
||||
flex-shrink: 0;
|
||||
height: calc(100% / 7.5);
|
||||
border-radius: 8px;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Health row taller */
|
||||
.chart-row.health-row {
|
||||
height: calc(100% / 6);
|
||||
margin-bottom: min(20px, calc(100% / 8));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,163 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
import Sparkline from '../charts/Sparkline.svelte';
|
||||
import type { TimeSeriesPoint } from '../types';
|
||||
|
||||
// Last 2h of history = 120 points at 1-min resolution
|
||||
const historyWindow = $derived(cultivar.state.environment.history.slice(-120));
|
||||
|
||||
const tempHistory = $derived<TimeSeriesPoint[]>(
|
||||
historyWindow.map(r => ({ ts: r.ts, value: r.temp_c }))
|
||||
);
|
||||
const rhHistory = $derived<TimeSeriesPoint[]>(
|
||||
historyWindow.map(r => ({ ts: r.ts, value: r.rh_pct }))
|
||||
);
|
||||
const co2History = $derived<TimeSeriesPoint[]>(
|
||||
historyWindow.map(r => ({ ts: r.ts, value: r.co2_ppm }))
|
||||
);
|
||||
const vpdHistory = $derived<TimeSeriesPoint[]>(
|
||||
historyWindow.map(r => ({ ts: r.ts, value: r.vpd }))
|
||||
);
|
||||
|
||||
const scrubTs = $derived(cultivar.state.ui.scrubber_ts);
|
||||
|
||||
function fmt(v: number, decimals = 1) {
|
||||
return v.toFixed(decimals);
|
||||
}
|
||||
|
||||
// Show scrubber-time value when in historical mode
|
||||
function scrubValue(history: TimeSeriesPoint[], live: number): number {
|
||||
if (scrubTs === null) return live;
|
||||
const closest = history.reduce((best, pt) =>
|
||||
Math.abs(pt.ts - scrubTs!) < Math.abs(best.ts - scrubTs!) ? pt : best
|
||||
, history[0]);
|
||||
return closest?.value ?? live;
|
||||
}
|
||||
|
||||
const displayTemp = $derived(scrubValue(tempHistory, cultivar.state.environment.live.temp_c));
|
||||
const displayRh = $derived(scrubValue(rhHistory, cultivar.state.environment.live.rh_pct));
|
||||
const displayCo2 = $derived(scrubValue(co2History, cultivar.state.environment.live.co2_ppm));
|
||||
const displayVpd = $derived(scrubValue(vpdHistory, cultivar.state.environment.live.vpd));
|
||||
</script>
|
||||
|
||||
<div class="env-strip">
|
||||
<div class="metric">
|
||||
<div class="metric-value">
|
||||
<span class="num">{fmt(displayTemp)}</span>
|
||||
<span class="unit text-muted">°C</span>
|
||||
</div>
|
||||
<div class="metric-label text-muted">Temp</div>
|
||||
<Sparkline
|
||||
data={tempHistory}
|
||||
width={100}
|
||||
height={28}
|
||||
targetValue={cultivar.state.environment.targets.temp_c}
|
||||
scrubberTs={scrubTs}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="metric">
|
||||
<div class="metric-value">
|
||||
<span class="num">{fmt(displayRh)}</span>
|
||||
<span class="unit text-muted">%</span>
|
||||
</div>
|
||||
<div class="metric-label text-muted">RH</div>
|
||||
<Sparkline
|
||||
data={rhHistory}
|
||||
width={100}
|
||||
height={28}
|
||||
targetValue={cultivar.state.environment.targets.rh_pct}
|
||||
scrubberTs={scrubTs}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="metric">
|
||||
<div class="metric-value">
|
||||
<span class="num">{fmt(displayCo2, 0)}</span>
|
||||
<span class="unit text-muted">ppm</span>
|
||||
</div>
|
||||
<div class="metric-label text-muted">CO₂</div>
|
||||
<Sparkline
|
||||
data={co2History}
|
||||
width={100}
|
||||
height={28}
|
||||
scrubberTs={scrubTs}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="metric">
|
||||
<div class="metric-value">
|
||||
<span class="num">{fmt(displayVpd, 2)}</span>
|
||||
<span class="unit text-muted">kPa</span>
|
||||
</div>
|
||||
<div class="metric-label text-muted">VPD</div>
|
||||
<Sparkline
|
||||
data={vpdHistory}
|
||||
width={100}
|
||||
height={28}
|
||||
scrubberTs={scrubTs}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.env-strip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0;
|
||||
padding: 10px 0;
|
||||
background: var(--color-surface);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.env-strip::-webkit-scrollbar { display: none; }
|
||||
|
||||
.metric {
|
||||
flex: 1;
|
||||
min-width: 90px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
.metric-value {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.num {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.unit {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.metric-label {
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 1px;
|
||||
height: 48px;
|
||||
background: var(--color-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,220 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
|
||||
const history = $derived(cultivar.state.environment.history);
|
||||
const minTs = $derived(history.length > 0 ? history[0].ts : 0);
|
||||
const maxTs = $derived(history.length > 0 ? history[history.length - 1].ts : 0);
|
||||
const isLive = $derived(cultivar.state.ui.scrubber_ts === null);
|
||||
|
||||
let trackEl = $state<HTMLDivElement | null>(null);
|
||||
let isDragging = $state(false);
|
||||
|
||||
const thumbPct = $derived.by(() => {
|
||||
if (isLive || maxTs === minTs) return 100;
|
||||
const ts = cultivar.state.ui.scrubber_ts!;
|
||||
return Math.max(0, Math.min(100, ((ts - minTs) / (maxTs - minTs)) * 100));
|
||||
});
|
||||
|
||||
function tsFromPct(pct: number): number {
|
||||
return minTs + (pct / 100) * (maxTs - minTs);
|
||||
}
|
||||
|
||||
function pctFromEvent(e: MouseEvent | TouchEvent): number {
|
||||
if (!trackEl) return 100;
|
||||
const rect = trackEl.getBoundingClientRect();
|
||||
const clientX = 'touches' in e ? e.touches[0].clientX : e.clientX;
|
||||
return Math.max(0, Math.min(100, ((clientX - rect.left) / rect.width) * 100));
|
||||
}
|
||||
|
||||
function onTrackClick(e: MouseEvent) {
|
||||
const pct = pctFromEvent(e);
|
||||
if (pct >= 99) {
|
||||
cultivar.setScrubberTs(null);
|
||||
} else {
|
||||
cultivar.setScrubberTs(tsFromPct(pct));
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseDown(e: MouseEvent) {
|
||||
isDragging = true;
|
||||
const pct = pctFromEvent(e);
|
||||
cultivar.setScrubberTs(pct >= 99 ? null : tsFromPct(pct));
|
||||
|
||||
const onMove = (ev: MouseEvent) => {
|
||||
const p = pctFromEvent(ev);
|
||||
cultivar.setScrubberTs(p >= 99 ? null : tsFromPct(p));
|
||||
};
|
||||
const onUp = () => {
|
||||
isDragging = false;
|
||||
window.removeEventListener('mousemove', onMove);
|
||||
window.removeEventListener('mouseup', onUp);
|
||||
};
|
||||
window.addEventListener('mousemove', onMove);
|
||||
window.addEventListener('mouseup', onUp);
|
||||
}
|
||||
|
||||
function onTouchStart(e: TouchEvent) {
|
||||
const onMove = (ev: TouchEvent) => {
|
||||
const p = pctFromEvent(ev);
|
||||
cultivar.setScrubberTs(p >= 99 ? null : tsFromPct(p));
|
||||
};
|
||||
const onEnd = () => {
|
||||
window.removeEventListener('touchmove', onMove);
|
||||
window.removeEventListener('touchend', onEnd);
|
||||
};
|
||||
window.addEventListener('touchmove', onMove);
|
||||
window.addEventListener('touchend', onEnd);
|
||||
const p = pctFromEvent(e);
|
||||
cultivar.setScrubberTs(p >= 99 ? null : tsFromPct(p));
|
||||
}
|
||||
|
||||
function formatTs(ts: number): string {
|
||||
const d = new Date(ts * 1000);
|
||||
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
const displayTime = $derived(
|
||||
isLive
|
||||
? 'Live'
|
||||
: formatTs(cultivar.state.ui.scrubber_ts!)
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="scrubber">
|
||||
<span class="time-label text-muted">{formatTs(minTs)}</span>
|
||||
|
||||
<div
|
||||
class="track"
|
||||
bind:this={trackEl}
|
||||
onclick={onTrackClick}
|
||||
onmousedown={onMouseDown}
|
||||
ontouchstart={onTouchStart}
|
||||
role="slider"
|
||||
aria-label="Timeline scrubber"
|
||||
aria-valuenow={thumbPct}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
tabindex="0"
|
||||
onkeydown={(e) => {
|
||||
const step = 1;
|
||||
if (e.key === 'ArrowRight') {
|
||||
const next = Math.min(100, thumbPct + step);
|
||||
cultivar.setScrubberTs(next >= 99 ? null : tsFromPct(next));
|
||||
} else if (e.key === 'ArrowLeft') {
|
||||
const next = Math.max(0, thumbPct - step);
|
||||
cultivar.setScrubberTs(tsFromPct(next));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div class="track-fill" style="width: {thumbPct}%"></div>
|
||||
<div class="thumb" style="left: {thumbPct}%" class:live={isLive}></div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="live-pill"
|
||||
class:active={isLive}
|
||||
onclick={() => cultivar.setScrubberTs(null)}
|
||||
aria-pressed={isLive}
|
||||
>
|
||||
{#if isLive}
|
||||
<span class="live-dot"></span>
|
||||
{/if}
|
||||
{isLive ? 'LIVE' : displayTime}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.scrubber {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 16px;
|
||||
background: var(--color-surface);
|
||||
border-top: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.time-label {
|
||||
font-size: 10px;
|
||||
white-space: nowrap;
|
||||
letter-spacing: 0.04em;
|
||||
min-width: 36px;
|
||||
}
|
||||
|
||||
.track {
|
||||
flex: 1;
|
||||
height: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.track::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 8px 0;
|
||||
background: var(--color-border);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.track-fill {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 8px;
|
||||
bottom: 8px;
|
||||
background: var(--color-sage-dim);
|
||||
border-radius: 2px;
|
||||
pointer-events: none;
|
||||
transition: width 0.1s;
|
||||
}
|
||||
|
||||
.thumb {
|
||||
position: absolute;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-text-muted);
|
||||
border: 2px solid var(--color-surface);
|
||||
transform: translateX(-50%);
|
||||
transition: background 0.2s;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.thumb.live {
|
||||
background: var(--color-sage);
|
||||
box-shadow: 0 0 6px color-mix(in srgb, var(--color-sage) 60%, transparent);
|
||||
}
|
||||
|
||||
.live-pill {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 3px 10px;
|
||||
border-radius: 100px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.06em;
|
||||
white-space: nowrap;
|
||||
background: var(--color-surface-2);
|
||||
color: var(--color-text-muted);
|
||||
border: 1px solid var(--color-border);
|
||||
transition: background 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
.live-pill.active {
|
||||
background: color-mix(in srgb, var(--color-sage) 15%, transparent);
|
||||
color: var(--color-sage);
|
||||
border-color: var(--color-sage-dim);
|
||||
}
|
||||
|
||||
.live-dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-sage);
|
||||
animation: dot-live 2s ease-in-out infinite;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,180 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
|
||||
interface Props {
|
||||
onBagClick: (bagId: string) => void;
|
||||
}
|
||||
|
||||
const { onBagClick }: Props = $props();
|
||||
|
||||
type RecentSnap = {
|
||||
bagId: string;
|
||||
slotId: string;
|
||||
ts: number;
|
||||
image_url: string;
|
||||
colonization_pct: number;
|
||||
contamination_risk: 'none' | 'low' | 'medium' | 'high';
|
||||
};
|
||||
|
||||
const recentSnapshots = $derived.by<RecentSnap[]>(() => {
|
||||
const snaps: RecentSnap[] = [];
|
||||
const chamber = cultivar.state.chambers[0];
|
||||
if (!chamber) return [];
|
||||
for (const slot of chamber.slots) {
|
||||
if (!slot.bag) continue;
|
||||
const { snapshots } = slot.bag.vision;
|
||||
if (snapshots.length === 0) continue;
|
||||
const latest = snapshots[snapshots.length - 1];
|
||||
snaps.push({
|
||||
bagId: slot.bag.bag_id,
|
||||
slotId: slot.slot_id,
|
||||
ts: latest.ts,
|
||||
image_url: latest.image_url,
|
||||
colonization_pct: latest.colonization_pct,
|
||||
contamination_risk: latest.contamination_risk,
|
||||
});
|
||||
}
|
||||
return snaps
|
||||
.sort((a, b) => b.ts - a.ts)
|
||||
.slice(0, 2);
|
||||
});
|
||||
|
||||
function formatAge(ts: number): string {
|
||||
const diff = Math.floor(Date.now() / 1000) - ts;
|
||||
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
|
||||
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
|
||||
return `${Math.floor(diff / 86400)}d ago`;
|
||||
}
|
||||
|
||||
const contamColor: Record<string, string> = {
|
||||
none: 'var(--color-text-muted)',
|
||||
low: 'var(--color-contam-low)',
|
||||
medium: 'var(--color-contam-low)',
|
||||
high: 'var(--color-contam-high)',
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if recentSnapshots.length > 0}
|
||||
<div class="snapshot-strip">
|
||||
<div class="strip-label text-muted">Recent</div>
|
||||
<div class="snaps">
|
||||
{#each recentSnapshots as snap (snap.bagId)}
|
||||
<button class="snap-card" onclick={() => onBagClick(snap.bagId)}>
|
||||
<div class="snap-thumb">
|
||||
<div class="thumb-placeholder" style="--slot-color: {contamColor[snap.contamination_risk]}">
|
||||
<span class="slot-label">{snap.slotId}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="snap-meta">
|
||||
<span class="snap-slot">{snap.slotId}</span>
|
||||
<span class="snap-pct">{snap.colonization_pct}%</span>
|
||||
{#if snap.contamination_risk !== 'none'}
|
||||
<span class="snap-contam" style="color: {contamColor[snap.contamination_risk]}">
|
||||
⚠ {snap.contamination_risk}
|
||||
</span>
|
||||
{/if}
|
||||
<span class="snap-age text-muted">{formatAge(snap.ts)}</span>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.snapshot-strip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 16px;
|
||||
background: var(--color-surface);
|
||||
border-top: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.strip-label {
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.snaps {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.snaps::-webkit-scrollbar { display: none; }
|
||||
|
||||
.snap-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 10px;
|
||||
background: var(--color-surface-2);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
text-align: left;
|
||||
transition: border-color 0.2s, background 0.2s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.snap-card:hover {
|
||||
border-color: var(--color-sage-dim);
|
||||
background: color-mix(in srgb, var(--color-sage) 6%, var(--color-surface-2));
|
||||
}
|
||||
|
||||
.snap-thumb {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.thumb-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: color-mix(in srgb, var(--slot-color, var(--color-sage)) 10%, var(--color-bg));
|
||||
border: 1px solid color-mix(in srgb, var(--slot-color, var(--color-sage)) 30%, transparent);
|
||||
border-radius: var(--radius-sm);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.slot-label {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 13px;
|
||||
color: color-mix(in srgb, var(--slot-color, var(--color-sage)) 70%, transparent);
|
||||
}
|
||||
|
||||
.snap-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.snap-slot {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 13px;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.snap-pct {
|
||||
font-size: 11px;
|
||||
color: var(--color-sage);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.snap-contam {
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.snap-age {
|
||||
font-size: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,92 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
|
||||
const active = $derived(
|
||||
cultivar.state.environment.alerts.filter(a => !a.dismissed)
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if active.length > 0}
|
||||
<div class="action-list">
|
||||
{#each active as alert (alert.id)}
|
||||
{@const level = alert.severity}
|
||||
<div class="action-item action-{level}">
|
||||
<span class="action-dot"></span>
|
||||
<span class="action-msg">{alert.message}</span>
|
||||
<button
|
||||
class="action-dismiss"
|
||||
onclick={() => cultivar.dismissAlert(alert.id)}
|
||||
aria-label="Ignore this action"
|
||||
>Ignore</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.action-list {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
padding: 0 12px 6px;
|
||||
}
|
||||
|
||||
.action-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.35;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.action-info {
|
||||
background: color-mix(in srgb, var(--color-sage) 10%, transparent);
|
||||
border-color: color-mix(in srgb, var(--color-sage) 18%, transparent);
|
||||
color: color-mix(in srgb, var(--color-sage) 90%, var(--color-text));
|
||||
}
|
||||
|
||||
.action-warn {
|
||||
background: color-mix(in srgb, var(--color-contam-low) 10%, transparent);
|
||||
border-color: color-mix(in srgb, var(--color-contam-low) 20%, transparent);
|
||||
color: color-mix(in srgb, var(--color-contam-low) 85%, var(--color-text));
|
||||
}
|
||||
|
||||
.action-critical {
|
||||
background: color-mix(in srgb, var(--color-contam-high) 12%, transparent);
|
||||
border-color: color-mix(in srgb, var(--color-contam-high) 22%, transparent);
|
||||
color: color-mix(in srgb, var(--color-contam-high) 85%, var(--color-text));
|
||||
}
|
||||
|
||||
.action-dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
flex-shrink: 0;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.action-msg {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.action-dismiss {
|
||||
flex-shrink: 0;
|
||||
font-size: 10.5px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: currentColor;
|
||||
opacity: 0.5;
|
||||
padding: 2px 6px;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid currentColor;
|
||||
transition: opacity 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.action-dismiss:hover { opacity: 0.85; }
|
||||
</style>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
</script>
|
||||
|
||||
<header class="topbar">
|
||||
<!-- Grove5 monogram -->
|
||||
<div class="monogram" aria-label="Grove5">
|
||||
<svg width="28" height="28" viewBox="0 0 32 32" fill="none">
|
||||
<circle cx="16" cy="16" r="16" fill="var(--color-surface-2)"/>
|
||||
<text x="8" y="21" font-family="var(--font-serif)" font-size="13" fill="var(--color-text)" font-weight="400">g</text>
|
||||
<text x="17" y="21" font-family="var(--font-serif)" font-size="13" fill="var(--color-sage)" font-weight="700">5</text>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<span class="brand">Cultivar</span>
|
||||
|
||||
<div class="spacer"></div>
|
||||
|
||||
<!-- Connection indicator -->
|
||||
<span class="status-dot live" aria-label="Connected"></span>
|
||||
|
||||
<!-- Menu button -->
|
||||
<button class="menu-btn" aria-label="Menu">
|
||||
<svg width="18" height="14" viewBox="0 0 18 14" fill="none">
|
||||
<line x1="0" y1="1" x2="18" y2="1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
||||
<line x1="0" y1="7" x2="18" y2="7" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
||||
<line x1="0" y1="13" x2="18" y2="13" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<style>
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.monogram {
|
||||
flex-shrink: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.brand {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 17px;
|
||||
letter-spacing: 0.01em;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-sage);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.status-dot.live {
|
||||
animation: dot-live 2.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.menu-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: var(--radius-md);
|
||||
color: var(--color-text-muted);
|
||||
transition: background 0.12s, color 0.12s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.menu-btn:hover {
|
||||
background: var(--color-surface-2);
|
||||
color: var(--color-text);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,74 @@
|
||||
import type { WsDiff } from './types';
|
||||
|
||||
type DiffHandler = (diff: WsDiff) => void;
|
||||
|
||||
export class WsClient {
|
||||
private ws: WebSocket | null = null;
|
||||
private url: string;
|
||||
private handlers: DiffHandler[] = [];
|
||||
private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private reconnectDelay = 2000;
|
||||
private _connected = $state(false);
|
||||
|
||||
get connected() { return this._connected; }
|
||||
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
connect() {
|
||||
try {
|
||||
this.ws = new WebSocket(this.url);
|
||||
|
||||
this.ws.onopen = () => {
|
||||
this._connected = true;
|
||||
this.reconnectDelay = 2000;
|
||||
};
|
||||
|
||||
this.ws.onmessage = (ev) => {
|
||||
try {
|
||||
const diff: WsDiff = JSON.parse(ev.data);
|
||||
this.handlers.forEach(h => h(diff));
|
||||
} catch {
|
||||
// ignore malformed frames
|
||||
}
|
||||
};
|
||||
|
||||
this.ws.onclose = () => {
|
||||
this._connected = false;
|
||||
this.scheduleReconnect();
|
||||
};
|
||||
|
||||
this.ws.onerror = () => {
|
||||
this._connected = false;
|
||||
this.ws?.close();
|
||||
};
|
||||
} catch {
|
||||
this._connected = false;
|
||||
this.scheduleReconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private scheduleReconnect() {
|
||||
if (this.reconnectTimer) return;
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
this.reconnectTimer = null;
|
||||
this.reconnectDelay = Math.min(this.reconnectDelay * 1.5, 30000);
|
||||
this.connect();
|
||||
}, this.reconnectDelay);
|
||||
}
|
||||
|
||||
onDiff(handler: DiffHandler) {
|
||||
this.handlers.push(handler);
|
||||
return () => { this.handlers = this.handlers.filter(h => h !== handler); };
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
this.ws?.close();
|
||||
this.ws = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { mount } from 'svelte';
|
||||
import App from './App.svelte';
|
||||
|
||||
mount(App, { target: document.getElementById('app')! });
|
||||
@@ -0,0 +1,503 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../lib/store.svelte';
|
||||
import ColonizationCurve from '../lib/charts/ColonizationCurve.svelte';
|
||||
import MushroomBag from '../lib/twin/MushroomBag.svelte';
|
||||
import type { BagSnapshot, BagState } from '../lib/types';
|
||||
import { STAGE_LABELS } from '../lib/types';
|
||||
|
||||
interface Props {
|
||||
bagId: string;
|
||||
onBack: () => void;
|
||||
}
|
||||
|
||||
const { bagId, onBack }: Props = $props();
|
||||
|
||||
const bag = $derived.by<BagState | null>(() => {
|
||||
for (const chamber of cultivar.state.chambers) {
|
||||
for (const slot of chamber.slots) {
|
||||
if (slot.bag?.bag_id === bagId) return slot.bag;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
let selectedSnapshotIdx = $state<number | null>(null);
|
||||
|
||||
const activeSnapshot = $derived.by<BagSnapshot | null>(() => {
|
||||
if (!bag) return null;
|
||||
const snaps = bag.vision.snapshots;
|
||||
if (snaps.length === 0) return null;
|
||||
if (selectedSnapshotIdx !== null) return snaps[selectedSnapshotIdx] ?? snaps[snaps.length - 1];
|
||||
return snaps[snaps.length - 1];
|
||||
});
|
||||
|
||||
function formatDate(ts: number): string {
|
||||
return new Date(ts * 1000).toLocaleDateString([], {
|
||||
month: 'short', day: 'numeric', year: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
function formatDaysAgo(ts: number): string {
|
||||
const d = Math.floor((Date.now() / 1000 - ts) / 86400);
|
||||
return d === 0 ? 'today' : `${d}d ago`;
|
||||
}
|
||||
|
||||
const contamColor: Record<string, string> = {
|
||||
none: 'var(--color-text-muted)',
|
||||
low: 'var(--color-contam-low)',
|
||||
medium: 'var(--color-contam-low)',
|
||||
high: 'var(--color-contam-high)',
|
||||
};
|
||||
|
||||
const annotColor: Record<string, string> = {
|
||||
mycelium: 'var(--color-mycelium)',
|
||||
contamination: 'var(--color-contam-high)',
|
||||
fruiting: 'var(--color-fruiting)',
|
||||
pinning: 'var(--color-pinning)',
|
||||
};
|
||||
|
||||
// Quick actions
|
||||
let actionPending = $state<string | null>(null);
|
||||
|
||||
async function postAction(endpoint: string, label: string) {
|
||||
actionPending = label;
|
||||
try {
|
||||
await fetch(endpoint, { method: 'POST' });
|
||||
} catch {
|
||||
// mock: ignore errors
|
||||
} finally {
|
||||
actionPending = null;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="bag-detail">
|
||||
<!-- Header -->
|
||||
<div class="detail-header">
|
||||
<button class="back-btn" onclick={onBack} aria-label="Back">
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
|
||||
<path d="M12 4L6 10L12 16" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{#if bag}
|
||||
<div class="header-info">
|
||||
<h1 class="slot-strain">
|
||||
<span class="slot-id">{bag.tag.strain_name}</span>
|
||||
<span class="stage-pill">{STAGE_LABELS[bag.vision.stage]}</span>
|
||||
</h1>
|
||||
<div class="header-meta text-muted">
|
||||
<span>Started {formatDate(bag.tag.inoculated_ts)}</span>
|
||||
<span class="sep">·</span>
|
||||
<span>{bag.tag.substrate}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if bag}
|
||||
<div class="detail-scroll">
|
||||
|
||||
<!-- Snapshot viewer — mushroom bag digital twin -->
|
||||
<section class="snapshot-viewer">
|
||||
<div class="snapshot-image-wrap">
|
||||
<div class="bag-twin-container">
|
||||
<MushroomBag
|
||||
colonizationPct={activeSnapshot?.colonization_pct ?? bag.vision.colonization_pct}
|
||||
contaminationRisk={activeSnapshot?.contamination_risk ?? bag.vision.contamination_risk}
|
||||
stage={bag.vision.stage}
|
||||
annotations={activeSnapshot?.annotations ?? []}
|
||||
strainCode={bag.tag.strain_code}
|
||||
inoculatedTs={bag.tag.inoculated_ts}
|
||||
/>
|
||||
|
||||
<!-- Overlay: stage + % readout -->
|
||||
<div class="bag-readout">
|
||||
<div class="readout-pct">{activeSnapshot?.colonization_pct ?? bag.vision.colonization_pct}%</div>
|
||||
<div class="readout-label">colonized</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if activeSnapshot && activeSnapshot.contamination_risk !== 'none'}
|
||||
<div class="contam-badge" style="color: {contamColor[activeSnapshot.contamination_risk]}">
|
||||
⚠ {activeSnapshot.contamination_risk} contamination risk
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Colonization curve -->
|
||||
<section class="section">
|
||||
<h2 class="section-title">Colonization Progress</h2>
|
||||
<div class="curve-wrap">
|
||||
<ColonizationCurve
|
||||
curve={bag.vision.projection.colonization_curve}
|
||||
inoculatedTs={bag.tag.inoculated_ts}
|
||||
estimatedReadyTs={bag.vision.projection.estimated_ready_ts}
|
||||
/>
|
||||
</div>
|
||||
<div class="curve-meta text-muted">
|
||||
<span>Est. ready: {formatDate(bag.vision.projection.estimated_ready_ts)}</span>
|
||||
<span class="sep">·</span>
|
||||
<span>{bag.vision.colonization_pct}% colonized</span>
|
||||
<span class="sep">·</span>
|
||||
<span>Confidence: {Math.round(bag.vision.colonization_confidence * 100)}%</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Snapshot history -->
|
||||
<section class="section">
|
||||
<h2 class="section-title">Snapshot History</h2>
|
||||
<div class="history-scroll">
|
||||
{#each [...bag.vision.snapshots].reverse() as snap, i (snap.ts)}
|
||||
{@const isActive = selectedSnapshotIdx === bag.vision.snapshots.length - 1 - i ||
|
||||
(selectedSnapshotIdx === null && i === 0)}
|
||||
<button
|
||||
class="history-thumb"
|
||||
class:active={isActive}
|
||||
onclick={() => {
|
||||
selectedSnapshotIdx = bag.vision.snapshots.length - 1 - i;
|
||||
}}
|
||||
>
|
||||
<div
|
||||
class="history-img"
|
||||
style="background: color-mix(in srgb, {snap.contamination_risk !== 'none' ? contamColor[snap.contamination_risk] : 'var(--color-sage)'} 10%, var(--color-bg))"
|
||||
>
|
||||
<span class="history-pct">{snap.colonization_pct}%</span>
|
||||
</div>
|
||||
<div class="history-info">
|
||||
<span class="history-date text-muted">{formatDaysAgo(snap.ts)}</span>
|
||||
{#if snap.contamination_risk !== 'none'}
|
||||
<span class="history-contam" style="color: {contamColor[snap.contamination_risk]}">⚠</span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Quick actions -->
|
||||
<section class="section quick-actions">
|
||||
<h2 class="section-title">Actions</h2>
|
||||
<div class="action-row">
|
||||
<button
|
||||
class="action-btn action-flag"
|
||||
disabled={actionPending !== null}
|
||||
onclick={() => postAction(`/api/bags/${bagId}/flag`, 'flag')}
|
||||
>
|
||||
{actionPending === 'flag' ? 'Flagging…' : 'Flag Contamination'}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="action-btn action-harvest"
|
||||
disabled={actionPending !== null}
|
||||
onclick={() => postAction(`/api/bags/${bagId}/harvest`, 'harvest')}
|
||||
>
|
||||
{actionPending === 'harvest' ? 'Marking…' : 'Mark Harvested'}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="action-btn action-retag"
|
||||
disabled={actionPending !== null}
|
||||
onclick={() => {
|
||||
// V1: manual entry fallback
|
||||
const code = prompt('Enter strain code (MSS format):');
|
||||
if (code) {
|
||||
// In production: POST to /api/bags/{id}/retag
|
||||
console.log('Retag:', code);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Retag
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
{:else}
|
||||
<div class="not-found text-muted">Bag not found.</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.bag-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background: var(--color-bg);
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
animation: slide-in-right var(--transition-view) both;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 10px 16px;
|
||||
background: var(--color-surface);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--color-text-muted);
|
||||
flex-shrink: 0;
|
||||
transition: color 0.2s, background 0.2s;
|
||||
}
|
||||
.back-btn:hover {
|
||||
color: var(--color-text);
|
||||
background: var(--color-surface-2);
|
||||
}
|
||||
|
||||
.header-info {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.slot-strain {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
font-family: var(--font-serif);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.slot-id {
|
||||
font-size: 20px;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.stage-pill {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-sage);
|
||||
border: 1px solid color-mix(in srgb, var(--color-sage) 40%, transparent);
|
||||
padding: 2px 7px;
|
||||
border-radius: 20px;
|
||||
white-space: nowrap;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.header-meta {
|
||||
font-size: 11px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.sep { opacity: 0.4; }
|
||||
|
||||
.detail-scroll {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--color-border) transparent;
|
||||
}
|
||||
|
||||
/* Snapshot viewer */
|
||||
.snapshot-viewer {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.snapshot-image-wrap {
|
||||
position: relative;
|
||||
border-radius: var(--radius-lg);
|
||||
overflow: hidden;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.bag-twin-container {
|
||||
position: relative;
|
||||
aspect-ratio: 3/4;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: radial-gradient(ellipse at 50% 45%, var(--color-surface-2) 0%, var(--color-bg) 100%);
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.bag-readout {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 14px;
|
||||
text-align: right;
|
||||
font-family: var(--font-serif);
|
||||
z-index: 2;
|
||||
padding: 6px 10px;
|
||||
background: color-mix(in srgb, var(--color-bg) 70%, transparent);
|
||||
backdrop-filter: blur(4px);
|
||||
-webkit-backdrop-filter: blur(4px);
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.readout-pct {
|
||||
font-size: 28px;
|
||||
color: var(--color-sage);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.readout-label {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 9px;
|
||||
color: var(--color-text-muted);
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.contam-badge {
|
||||
padding: 6px 12px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.04em;
|
||||
background: color-mix(in srgb, currentColor 8%, var(--color-surface));
|
||||
}
|
||||
|
||||
/* Sections */
|
||||
.section {
|
||||
padding: 0 16px 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-family: var(--font-sans);
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.curve-wrap {
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.curve-meta {
|
||||
font-size: 11px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/* History strip */
|
||||
.history-scroll {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
.history-scroll::-webkit-scrollbar { display: none; }
|
||||
|
||||
.history-thumb {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--color-border);
|
||||
padding: 4px;
|
||||
background: var(--color-surface);
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.history-thumb.active {
|
||||
border-color: var(--color-sage);
|
||||
}
|
||||
|
||||
.history-img {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 3px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.history-pct {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 14px;
|
||||
color: var(--color-sage);
|
||||
}
|
||||
|
||||
.history-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 4px;
|
||||
padding: 0 2px;
|
||||
}
|
||||
|
||||
.history-date {
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
.history-contam {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
/* Quick actions */
|
||||
.action-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
padding: 10px 16px;
|
||||
border-radius: var(--radius-md);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-surface-2);
|
||||
color: var(--color-text);
|
||||
transition: background 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.action-btn:hover:not(:disabled) {
|
||||
background: var(--color-surface);
|
||||
border-color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.action-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.action-flag {
|
||||
border-color: color-mix(in srgb, var(--color-contam-low) 40%, transparent);
|
||||
color: var(--color-contam-low);
|
||||
}
|
||||
|
||||
.action-harvest {
|
||||
border-color: color-mix(in srgb, var(--color-sage) 40%, transparent);
|
||||
color: var(--color-sage);
|
||||
}
|
||||
|
||||
.not-found {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,522 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../lib/store.svelte';
|
||||
|
||||
interface Props {
|
||||
onComplete: () => void;
|
||||
}
|
||||
|
||||
const { onComplete }: Props = $props();
|
||||
|
||||
type Step = 'welcome' | 'connect' | 'confirm';
|
||||
|
||||
let step = $state<Step>('welcome');
|
||||
let btAvailable = $state(typeof navigator !== 'undefined' && 'bluetooth' in navigator);
|
||||
let iosBtStep = $state(0);
|
||||
let ssid = $state('');
|
||||
let password = $state('');
|
||||
let btStatus = $state<'idle' | 'scanning' | 'connecting' | 'success' | 'error'>('idle');
|
||||
let btError = $state('');
|
||||
|
||||
async function startBtScan() {
|
||||
btStatus = 'scanning';
|
||||
try {
|
||||
const device = await (navigator as any).bluetooth.requestDevice({
|
||||
filters: [{ services: ['12345678-1234-1234-1234-123456789abc'] }],
|
||||
});
|
||||
btStatus = 'connecting';
|
||||
const server = await device.gatt.connect();
|
||||
const service = await server.getPrimaryService('12345678-1234-1234-1234-123456789abc');
|
||||
const cred = await service.getCharacteristic('wifi-credentials');
|
||||
const payload = JSON.stringify({ ssid, password });
|
||||
const encoded = new TextEncoder().encode(payload);
|
||||
await cred.writeValue(encoded);
|
||||
btStatus = 'success';
|
||||
setTimeout(() => { step = 'confirm'; }, 1500);
|
||||
} catch (err: any) {
|
||||
btError = err.message ?? 'Bluetooth error';
|
||||
btStatus = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// iOS/manual path: poll for connectivity
|
||||
let apPolling = $state(false);
|
||||
let apConnected = $state(false);
|
||||
|
||||
async function pollCaptivePortal() {
|
||||
apPolling = true;
|
||||
const check = async () => {
|
||||
try {
|
||||
const res = await fetch('http://192.168.4.1/api/status', { signal: AbortSignal.timeout(2000) });
|
||||
if (res.ok) {
|
||||
apConnected = true;
|
||||
apPolling = false;
|
||||
return;
|
||||
}
|
||||
} catch { /* not connected yet */ }
|
||||
if (apPolling) setTimeout(check, 2000);
|
||||
};
|
||||
check();
|
||||
}
|
||||
|
||||
async function submitWifi() {
|
||||
try {
|
||||
await fetch('http://192.168.4.1/api/wifi', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ssid, password }),
|
||||
});
|
||||
} catch { /* expected if device reboots */ }
|
||||
iosBtStep = 3;
|
||||
}
|
||||
|
||||
function finish() {
|
||||
cultivar.completeOnboarding();
|
||||
onComplete();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="onboarding-overlay">
|
||||
<!-- Blurred twin background -->
|
||||
<div class="onboarding-bg" aria-hidden="true"></div>
|
||||
|
||||
<div class="onboarding-card">
|
||||
<!-- Step: Welcome -->
|
||||
{#if step === 'welcome'}
|
||||
<div class="ob-step" style="animation: fade-in 0.4s both">
|
||||
<div class="ob-monogram">
|
||||
<svg width="56" height="56" viewBox="0 0 56 56" fill="none">
|
||||
<circle cx="28" cy="28" r="28" fill="var(--color-charcoal)"/>
|
||||
<text x="14" y="38" font-family="var(--font-serif)" font-size="24" fill="var(--color-charcoal)" font-weight="700">g</text>
|
||||
<text x="31" y="38" font-family="var(--font-serif)" font-size="24" fill="var(--color-sage)" font-weight="700">5</text>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="ob-headline">Welcome to your Cultivar.</h1>
|
||||
<p class="ob-body text-muted">Let's connect your chamber.</p>
|
||||
<button class="ob-cta" onclick={() => { step = 'connect'; }}>Begin Setup</button>
|
||||
</div>
|
||||
|
||||
<!-- Step: Connect -->
|
||||
{:else if step === 'connect'}
|
||||
<div class="ob-step" style="animation: fade-in 0.3s both">
|
||||
{#if btAvailable}
|
||||
<!-- Android / Chrome BT path -->
|
||||
<h2 class="ob-headline-sm">Connect via Bluetooth</h2>
|
||||
<p class="ob-body text-muted">We found Bluetooth support. This will only take a moment.</p>
|
||||
|
||||
{#if btStatus === 'idle' || btStatus === 'error'}
|
||||
<div class="ob-form">
|
||||
<label class="ob-label">
|
||||
WiFi Network
|
||||
<input class="ob-input" type="text" bind:value={ssid} placeholder="Home network name" autocomplete="off"/>
|
||||
</label>
|
||||
<label class="ob-label">
|
||||
Password
|
||||
<input class="ob-input" type="password" bind:value={password} placeholder="••••••••"/>
|
||||
</label>
|
||||
</div>
|
||||
{#if btStatus === 'error'}
|
||||
<p class="ob-error">⚠ {btError}</p>
|
||||
{/if}
|
||||
<button class="ob-cta" onclick={startBtScan} disabled={!ssid}>
|
||||
Scan for Cultivar
|
||||
</button>
|
||||
<button class="ob-link text-muted" onclick={() => { btAvailable = false; }}>
|
||||
Switch to manual setup
|
||||
</button>
|
||||
{:else if btStatus === 'scanning'}
|
||||
<div class="ob-status">
|
||||
<div class="ob-spinner"></div>
|
||||
<span>Scanning for Cultivar…</span>
|
||||
</div>
|
||||
{:else if btStatus === 'connecting'}
|
||||
<div class="ob-status">
|
||||
<div class="ob-spinner"></div>
|
||||
<span>Connecting to your network…</span>
|
||||
</div>
|
||||
{:else if btStatus === 'success'}
|
||||
<div class="ob-status success">
|
||||
<span class="ob-check">✓</span>
|
||||
<span>Cultivar is online</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{:else}
|
||||
<!-- iOS / Safari manual AP path -->
|
||||
<h2 class="ob-headline-sm">WiFi Setup</h2>
|
||||
<p class="ob-body text-muted">Bluetooth isn't available in this browser. We'll use WiFi setup instead.</p>
|
||||
|
||||
<div class="ob-steps-list">
|
||||
<div class="ob-manual-step" class:active={iosBtStep === 0} class:done={iosBtStep > 0}>
|
||||
<span class="step-num">1</span>
|
||||
<div>
|
||||
<strong>Connect to Cultivar hotspot</strong>
|
||||
<p class="text-muted">Open WiFi settings and connect to <code>Cultivar-XXXX</code></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ob-manual-step" class:active={iosBtStep === 1} class:done={iosBtStep > 1}>
|
||||
<span class="step-num">2</span>
|
||||
<div>
|
||||
<strong>Return here</strong>
|
||||
<p class="text-muted">We'll detect when you're connected.</p>
|
||||
{#if iosBtStep === 1}
|
||||
{#if !apConnected}
|
||||
<button class="ob-link-sm text-muted" onclick={pollCaptivePortal}>
|
||||
{apPolling ? 'Checking…' : 'Check connection'}
|
||||
</button>
|
||||
{:else}
|
||||
<span class="ob-check-sm">✓ Connected</span>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ob-manual-step" class:active={iosBtStep === 2} class:done={iosBtStep > 2}>
|
||||
<span class="step-num">3</span>
|
||||
<div>
|
||||
<strong>Enter your home WiFi</strong>
|
||||
{#if iosBtStep === 2}
|
||||
<div class="ob-form-sm">
|
||||
<input class="ob-input" type="text" bind:value={ssid} placeholder="Network name" autocomplete="off"/>
|
||||
<input class="ob-input" type="password" bind:value={password} placeholder="Password"/>
|
||||
<button class="ob-cta-sm" onclick={submitWifi} disabled={!ssid}>Send</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ob-manual-step" class:active={iosBtStep === 3} class:done={iosBtStep > 3}>
|
||||
<span class="step-num">4</span>
|
||||
<div>
|
||||
<strong>Reconnect to your home WiFi</strong>
|
||||
<p class="text-muted">Then tap Continue below.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if iosBtStep < 3}
|
||||
<button class="ob-cta" onclick={() => { iosBtStep = Math.min(3, iosBtStep + 1); }}>
|
||||
Next
|
||||
</button>
|
||||
{:else}
|
||||
<button class="ob-cta" onclick={() => { step = 'confirm'; }}>
|
||||
Continue
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Step: Confirmation -->
|
||||
{:else if step === 'confirm'}
|
||||
<div class="ob-step" style="animation: fade-in 0.4s both">
|
||||
<div class="ob-check-circle">✓</div>
|
||||
<h2 class="ob-headline">Your Cultivar is connected.</h2>
|
||||
<div class="ob-device-info">
|
||||
<div class="di-row">
|
||||
<span class="text-muted">Device</span>
|
||||
<span>{cultivar.state.meta.device_id}</span>
|
||||
</div>
|
||||
<div class="di-row">
|
||||
<span class="text-muted">Firmware</span>
|
||||
<span>{cultivar.state.meta.firmware_version}</span>
|
||||
</div>
|
||||
<div class="di-row">
|
||||
<span class="text-muted">Signal</span>
|
||||
<span>{cultivar.state.meta.wifi_rssi} dBm</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ob-cta ob-cta-sage" onclick={finish}>Start Growing</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.onboarding-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
background: color-mix(in srgb, var(--color-bg) 85%, transparent);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.onboarding-bg {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: radial-gradient(ellipse at center, transparent 30%, var(--color-bg) 80%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.onboarding-card {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 32px 28px;
|
||||
width: 100%;
|
||||
max-width: 360px;
|
||||
box-shadow: 0 32px 64px rgba(0,0,0,0.6);
|
||||
}
|
||||
|
||||
.ob-step {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ob-monogram {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.ob-headline {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 22px;
|
||||
font-weight: 400;
|
||||
color: var(--color-text);
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.ob-headline-sm {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 18px;
|
||||
font-weight: 400;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.ob-body {
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
max-width: 280px;
|
||||
}
|
||||
|
||||
.ob-cta {
|
||||
padding: 12px 28px;
|
||||
background: var(--color-surface-2);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
width: 100%;
|
||||
transition: background 0.2s, border-color 0.2s;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.ob-cta:hover:not(:disabled) {
|
||||
background: var(--color-charcoal);
|
||||
border-color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.ob-cta:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
|
||||
.ob-cta-sage {
|
||||
background: color-mix(in srgb, var(--color-sage) 20%, var(--color-surface-2));
|
||||
border-color: var(--color-sage-dim);
|
||||
color: var(--color-sage);
|
||||
}
|
||||
|
||||
.ob-cta-sage:hover {
|
||||
background: color-mix(in srgb, var(--color-sage) 30%, var(--color-surface-2));
|
||||
}
|
||||
|
||||
.ob-link {
|
||||
font-size: 12px;
|
||||
padding: 4px;
|
||||
background: none;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
|
||||
.ob-form {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.ob-label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.ob-input {
|
||||
padding: 9px 12px;
|
||||
background: var(--color-bg);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--color-text);
|
||||
font-family: var(--font-sans);
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
.ob-input:focus { border-color: var(--color-sage-dim); }
|
||||
|
||||
.ob-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-muted);
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.ob-status.success { color: var(--color-sage); }
|
||||
|
||||
.ob-spinner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid var(--color-border);
|
||||
border-top-color: var(--color-sage);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.ob-check {
|
||||
font-size: 20px;
|
||||
color: var(--color-sage);
|
||||
}
|
||||
|
||||
.ob-error {
|
||||
font-size: 12px;
|
||||
color: var(--color-contam-low);
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Manual steps list */
|
||||
.ob-steps-list {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.ob-manual-step {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
opacity: 0.4;
|
||||
transition: opacity 0.3s;
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.ob-manual-step.active { opacity: 1; }
|
||||
.ob-manual-step.done { opacity: 0.6; }
|
||||
|
||||
.step-num {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid var(--color-border);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 11px;
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.ob-manual-step.active .step-num {
|
||||
border-color: var(--color-sage);
|
||||
color: var(--color-sage);
|
||||
}
|
||||
|
||||
.ob-form-sm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.ob-cta-sm {
|
||||
padding: 7px 14px;
|
||||
background: var(--color-surface-2);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
align-self: flex-start;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.ob-cta-sm:hover:not(:disabled) { background: var(--color-charcoal); }
|
||||
.ob-cta-sm:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
|
||||
.ob-link-sm {
|
||||
font-size: 11px;
|
||||
padding: 2px 0;
|
||||
background: none;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
display: inline;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.ob-check-sm {
|
||||
font-size: 11px;
|
||||
color: var(--color-sage);
|
||||
margin-top: 4px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* Confirmation step */
|
||||
.ob-check-circle {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 50%;
|
||||
background: color-mix(in srgb, var(--color-sage) 15%, var(--color-surface));
|
||||
border: 1px solid var(--color-sage-dim);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 24px;
|
||||
color: var(--color-sage);
|
||||
}
|
||||
|
||||
.ob-device-info {
|
||||
width: 100%;
|
||||
background: var(--color-surface-2);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 12px 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.di-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: monospace;
|
||||
background: var(--color-surface-2);
|
||||
padding: 1px 5px;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,203 @@
|
||||
<script lang="ts">
|
||||
import TopBar from '../lib/ui/TopBar.svelte';
|
||||
import StatusBar from '../lib/ui/StatusBar.svelte';
|
||||
import IsoTwin from '../lib/twin/IsoTwin.svelte';
|
||||
import BagPopover from '../lib/twin/BagPopover.svelte';
|
||||
import ChartPanel from '../lib/ui/ChartPanel.svelte';
|
||||
import { cultivar } from '../lib/store.svelte';
|
||||
import type { EnvironmentReading } from '../lib/types';
|
||||
|
||||
interface Props {
|
||||
onBagSelect: (bagId: string) => void;
|
||||
}
|
||||
|
||||
const { onBagSelect }: Props = $props();
|
||||
|
||||
let popoverBagId = $state<string | null>(null);
|
||||
let popoverAnchor = $state<{ x: number; y: number } | null>(null);
|
||||
|
||||
function handleBagClick(bagId: string, el: HTMLElement) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
popoverBagId = bagId;
|
||||
popoverAnchor = { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
|
||||
}
|
||||
|
||||
function closePopover() { popoverBagId = null; popoverAnchor = null; }
|
||||
|
||||
function openDetails() {
|
||||
if (popoverBagId) {
|
||||
const id = popoverBagId;
|
||||
closePopover();
|
||||
onBagSelect(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Health score
|
||||
const targets = $derived(cultivar.state.environment.targets);
|
||||
const history = $derived(cultivar.state.environment.history);
|
||||
|
||||
function score(r: EnvironmentReading): number {
|
||||
const tP = Math.min(Math.abs(r.temp_c - targets.temp_c) / 3, 1) * 33;
|
||||
const rP = Math.min(Math.abs(r.rh_pct - targets.rh_pct) / 10, 1) * 34;
|
||||
const cP = Math.min(Math.abs((r.co2_ppm ?? r.co2e_ppm ?? 0) - targets.co2_ppm) / 500, 1) * 33;
|
||||
return Math.max(0, Math.round(100 - tP - rP - cP));
|
||||
}
|
||||
|
||||
const currentScore = $derived(history.length > 0 ? score(history[history.length - 1]) : 100);
|
||||
const score1hAgo = $derived(history.length > 60 ? score(history[history.length - 61]) : currentScore);
|
||||
const scoreDelta = $derived(currentScore - score1hAgo);
|
||||
|
||||
const scoreColor = $derived(
|
||||
currentScore >= 80 ? 'var(--color-sage)'
|
||||
: currentScore >= 50 ? 'var(--color-contam-low)'
|
||||
: 'var(--color-contam-high)'
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="overview">
|
||||
<TopBar />
|
||||
|
||||
<!-- Action items (only visible when there are alerts) -->
|
||||
<StatusBar />
|
||||
|
||||
<!-- Full-width health banner -->
|
||||
<div class="health-banner">
|
||||
<div class="hb-score" style="color: {scoreColor}">{currentScore}</div>
|
||||
<div class="hb-meta">
|
||||
<span class="hb-label">System Health</span>
|
||||
{#if scoreDelta !== 0}
|
||||
<span class="hb-delta" class:pos={scoreDelta > 0} class:neg={scoreDelta < 0}>
|
||||
{scoreDelta > 0 ? '▲' : '▼'} {Math.abs(scoreDelta)} pts
|
||||
</span>
|
||||
{:else}
|
||||
<span class="hb-delta muted">— flat</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="main">
|
||||
<!-- Left: isometric digital twin -->
|
||||
<div class="twin-area">
|
||||
<IsoTwin />
|
||||
{#if popoverBagId && popoverAnchor}
|
||||
<BagPopover
|
||||
bagId={popoverBagId}
|
||||
anchor={popoverAnchor}
|
||||
onClose={closePopover}
|
||||
onOpenDetails={openDetails}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Right: sensor charts -->
|
||||
<div class="chart-area">
|
||||
<ChartPanel />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.overview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Health banner (full-width strip) ── */
|
||||
.health-banner {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 16px 10px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.hb-score {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 38px;
|
||||
line-height: 1;
|
||||
letter-spacing: -0.02em;
|
||||
transition: color 0.4s;
|
||||
}
|
||||
|
||||
.hb-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.hb-label {
|
||||
font-size: 9px;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-muted);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.hb-delta {
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.02em;
|
||||
color: var(--color-text-muted);
|
||||
line-height: 1;
|
||||
}
|
||||
.hb-delta.pos { color: var(--color-sage); }
|
||||
.hb-delta.neg { color: var(--color-contam-high); }
|
||||
.hb-delta.muted { color: var(--color-text-muted); }
|
||||
|
||||
/* ── Main content ── */
|
||||
.main {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.twin-area {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
align-self: flex-start;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chart-area {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
border-left: 1px solid var(--color-border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Mobile ── */
|
||||
@media (max-width: 599px) {
|
||||
.main {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.twin-area {
|
||||
height: 75vw;
|
||||
flex-shrink: 0;
|
||||
width: 100%;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chart-area {
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
.hb-score {
|
||||
font-size: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Desktop widths ── */
|
||||
@media (min-width: 600px) {
|
||||
.twin-area { width: 62vw; }
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
Reference in new issue
Block a user