Initial commit
This commit is contained in:
1 parent
b359d852fe
commit
92be365e0c
39 files changed
+7072
No files matched your search
@@ -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>
|
||||
Reference in new issue
Block a user