Add Reference route, clean up gitignore, update mock firmware version, and refactor gallery frames into reusable component
Add Reference route with modal overlay accessible from Overview. Update .gitignore to consolidate reference/ and .claude/ exclusions. Change mock firmware version to 0.1.0-alpha. Remove unused scrubber_ts from UI state and store methods. Extract gallery frame rendering into GalleryFrame component with FrameSpec interface. Add chamber label cards above twin visualization showing
This commit is contained in:
1 parent
ccea0bf25a
commit
edf696f3ce
19 files changed
+2301
-724
No files matched your search
@@ -0,0 +1,225 @@
|
||||
// ── Briefing derivations ────────────────────────────────────────
|
||||
// Pure functions that turn Cultivar state into the copy + categorisations
|
||||
// rendered on the Overview page. Kept side-effect free so the component
|
||||
// stays thin and the logic stays testable.
|
||||
|
||||
import type { BagWithChamber } from './bag-label';
|
||||
import { bagLabel, bagList } from './bag-label';
|
||||
import type { Chamber, CultivarState, EnvironmentReading } from './types';
|
||||
|
||||
// ── Health score ───────────────────────────────────────
|
||||
export function healthScore(
|
||||
r: EnvironmentReading,
|
||||
targets: { temp_c: number; rh_pct: number; co2_ppm: number },
|
||||
): 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));
|
||||
}
|
||||
|
||||
// ── Bag buckets ────────────────────────────────────────
|
||||
export type BagBuckets = {
|
||||
harvestReady: BagWithChamber[];
|
||||
fruitingSoon: BagWithChamber[];
|
||||
pinning: BagWithChamber[];
|
||||
readyToMove: BagWithChamber[];
|
||||
highContam: BagWithChamber[];
|
||||
lowContam: BagWithChamber[];
|
||||
};
|
||||
|
||||
export function daysTo(ts: number): number {
|
||||
return Math.ceil((ts - Date.now() / 1000) / 86400);
|
||||
}
|
||||
|
||||
export function bucketBags(allBags: BagWithChamber[]): BagBuckets {
|
||||
return {
|
||||
harvestReady: allBags.filter(({ bag }) =>
|
||||
bag.vision.stage === 'harvest' ||
|
||||
daysTo(bag.vision.projection.estimated_ready_ts) <= 0
|
||||
),
|
||||
fruitingSoon: allBags.filter(({ bag }) => {
|
||||
const d = daysTo(bag.vision.projection.estimated_ready_ts);
|
||||
return bag.vision.stage === 'fruiting' && d > 0 && d <= 4;
|
||||
}),
|
||||
pinning: allBags.filter(({ bag }) => bag.vision.stage === 'pinning'),
|
||||
readyToMove: allBags.filter(({ bag, chamber }) =>
|
||||
chamber.type === 'colonization' && bag.vision.colonization_pct >= 90
|
||||
),
|
||||
highContam: allBags.filter(({ bag }) => bag.vision.contamination_risk === 'high'),
|
||||
lowContam: allBags.filter(({ bag }) =>
|
||||
bag.vision.contamination_risk === 'low' || bag.vision.contamination_risk === 'medium'
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
// ── Climate flags ──────────────────────────────────────
|
||||
export type ClimateFlags = {
|
||||
co2RecentAvg: number;
|
||||
co2Persistent: boolean;
|
||||
reservoirLow: boolean;
|
||||
colTempCool: boolean;
|
||||
colTempWarm: boolean;
|
||||
fruitTempCool: boolean;
|
||||
fruitTempWarm: boolean;
|
||||
};
|
||||
|
||||
export function climateFlags(
|
||||
history: EnvironmentReading[],
|
||||
hw: CultivarState['hardware'],
|
||||
colChamber: Pick<Chamber, 'environment'>,
|
||||
fruitChamber: Pick<Chamber, 'environment'>,
|
||||
): ClimateFlags {
|
||||
const slice = history.slice(-180);
|
||||
const co2RecentAvg = slice.length === 0
|
||||
? 0
|
||||
: slice.reduce((a, r) => a + (r.co2e_ppm ?? r.co2_ppm ?? 0), 0) / slice.length;
|
||||
const colFanSpeed = hw.fans.find(f => f.chamber_id === 'main')?.speed_pct ?? 0;
|
||||
const colT = colChamber.environment.temp_c;
|
||||
const fruitT = fruitChamber.environment.temp_c;
|
||||
return {
|
||||
co2RecentAvg,
|
||||
co2Persistent: co2RecentAvg > 1600 && colFanSpeed >= 50,
|
||||
reservoirLow: hw.humidifier.reservoir_pct < 20,
|
||||
colTempCool: colT < 20,
|
||||
colTempWarm: colT > 25,
|
||||
fruitTempCool: fruitT < 15,
|
||||
fruitTempWarm: fruitT > 21,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Headline ───────────────────────────────────────────
|
||||
export type Headline = { big: string; italic: string; tone: 'warn' | 'good' };
|
||||
|
||||
export function pickHeadline(b: BagBuckets, currentScore: number): Headline {
|
||||
if (b.highContam.length > 0) return { big: 'One thing', italic: 'worth a look.', tone: 'warn' };
|
||||
if (currentScore < 55) return { big: 'The climate', italic: 'wants a nudge.', tone: 'warn' };
|
||||
if (b.harvestReady.length > 0) return { big: 'Harvest', italic: 'day.', tone: 'good' };
|
||||
if (b.readyToMove.length > 0) return { big: 'Time', italic: 'for the next step.', tone: 'good' };
|
||||
if (b.fruitingSoon.length > 0) return { big: 'Harvest', italic: 'around the corner.', tone: 'good' };
|
||||
if (b.lowContam.length > 0) return { big: 'One small', italic: 'thing.', tone: 'warn' };
|
||||
return { big: 'All', italic: 'growing nicely.', tone: 'good' };
|
||||
}
|
||||
|
||||
// ── Copy helpers ───────────────────────────────────────
|
||||
function capFirst(s: string): string {
|
||||
return s.length ? s[0].toUpperCase() + s.slice(1) : s;
|
||||
}
|
||||
|
||||
function joinHuman(items: string[], last = 'and'): string {
|
||||
if (items.length <= 1) return items[0] ?? '';
|
||||
if (items.length === 2) return `${items[0]} ${last} ${items[1]}`;
|
||||
return `${items.slice(0, -1).join(', ')}, ${last} ${items[items.length - 1]}`;
|
||||
}
|
||||
|
||||
// ── Grow-side briefing paragraphs ───────────────────────
|
||||
export function growParagraphs(b: BagBuckets, allBags: BagWithChamber[]): string[] {
|
||||
const paragraphs: string[] = [];
|
||||
|
||||
if (b.harvestReady.length > 0) {
|
||||
const list = bagList(b.harvestReady, allBags);
|
||||
const verb = b.harvestReady.length === 1 ? 'is' : 'are';
|
||||
paragraphs.push(`${capFirst(list)} ${verb} ready to pick today, caps full right on schedule.`);
|
||||
}
|
||||
|
||||
if (b.fruitingSoon.length > 0) {
|
||||
const items = b.fruitingSoon.map(({ bag, chamber }) => {
|
||||
const d = daysTo(bag.vision.projection.estimated_ready_ts);
|
||||
const label = bagLabel(bag, chamber, allBags);
|
||||
return `${label} (about ${d} day${d === 1 ? '' : 's'} out)`;
|
||||
});
|
||||
paragraphs.push(
|
||||
`${capFirst(joinHuman(items))} ${b.fruitingSoon.length === 1 ? 'is' : 'are'} fruiting and on track.`
|
||||
);
|
||||
}
|
||||
|
||||
if (b.pinning.length > 0 && paragraphs.length < 2) {
|
||||
const list = bagList(b.pinning, allBags);
|
||||
paragraphs.push(
|
||||
`${capFirst(list)} started pinning, so little primordia should be popping through the cuts.`
|
||||
);
|
||||
}
|
||||
|
||||
if (b.readyToMove.length > 0) {
|
||||
const list = bagList(b.readyToMove, allBags);
|
||||
const pct = b.readyToMove[0].bag.vision.colonization_pct;
|
||||
paragraphs.push(
|
||||
`On to colonization. ${capFirst(list)} is showing a strong mycelium network at ${pct}% coverage and can move to fruiting when you have a minute.`
|
||||
);
|
||||
}
|
||||
|
||||
if (b.highContam.length > 0) {
|
||||
const list = bagList(b.highContam, allBags);
|
||||
paragraphs.push(
|
||||
`The camera picked up a contamination signal on ${list}. Worth opening the door today and having a quick look.`
|
||||
);
|
||||
} else if (b.lowContam.length > 0) {
|
||||
const list = bagList(b.lowContam, allBags);
|
||||
paragraphs.push(
|
||||
`${capFirst(list)} shows a faint potential contamination signal. Nothing serious, just one to glance at next time you're nearby.`
|
||||
);
|
||||
}
|
||||
|
||||
if (paragraphs.length === 0) {
|
||||
const total = allBags.length;
|
||||
paragraphs.push(
|
||||
total > 0
|
||||
? `All ${total} bags are tracking along today. Nothing needs you.`
|
||||
: `Your Cultivar is empty, resting until the next batch.`
|
||||
);
|
||||
}
|
||||
|
||||
return paragraphs;
|
||||
}
|
||||
|
||||
// ── Climate-side briefing paragraph ─────────────────────
|
||||
export function climateParagraph(
|
||||
flags: ClimateFlags,
|
||||
hw: CultivarState['hardware'],
|
||||
): string {
|
||||
const sentences: string[] = [];
|
||||
|
||||
if (flags.co2Persistent) {
|
||||
sentences.push(
|
||||
`CO₂ has been running high on the colonization side. The fan has been keeping pace, but if your home stays closed up, cracking a window for a minute gives us both some fresh air.`
|
||||
);
|
||||
}
|
||||
|
||||
if (flags.colTempCool || flags.fruitTempCool) {
|
||||
sentences.push(
|
||||
`It is on the cool side inside. Cultivar has no heater, so if you're chilly, the grow probably is too. A spot away from exterior walls or drafty windows helps. Shiitake and Lion's Mane genuinely prefer this range, if you're picking for the next batch.`
|
||||
);
|
||||
} else if (flags.colTempWarm || flags.fruitTempWarm) {
|
||||
sentences.push(
|
||||
`It is running a touch warm. Cultivar has no cooler, so moving it away from sunny windows or appliance vents will help. Warm-season species like Pink Oyster do well at this temperature.`
|
||||
);
|
||||
}
|
||||
|
||||
if (flags.reservoirLow) {
|
||||
sentences.push(
|
||||
`The humidifier reservoir is down to ${hw.humidifier.reservoir_pct}%. A top-up next time you're in the kitchen keeps the mist going.`
|
||||
);
|
||||
}
|
||||
|
||||
if (sentences.length === 0) {
|
||||
sentences.push(
|
||||
`Climate is comfortable in both compartments. Humidity, CO₂, and airflow are all sitting nicely in range.`
|
||||
);
|
||||
}
|
||||
|
||||
return sentences.join(' ');
|
||||
}
|
||||
|
||||
// ── Maintenance cadences ───────────────────────────────
|
||||
export const MAINTENANCE = {
|
||||
/** Chamber walls + racks wiped with 70% iso */
|
||||
wipeIntervalDays: 14,
|
||||
wipeOverdueGraceDays: 7,
|
||||
/** Humidifier reservoir hand- or dishwasher-washed */
|
||||
reservoirIntervalDays: 28,
|
||||
reservoirOverdueGraceDays: 7,
|
||||
} as const;
|
||||
|
||||
export function daysSinceTs(ts: number): number {
|
||||
return Math.floor((Date.now() / 1000 - ts) / 86400);
|
||||
}
|
||||
+1
-3
@@ -75,7 +75,7 @@ const inoculatedF_C1 = NOW - 22 * HOUR * 24;
|
||||
const fullMockState: CultivarState = {
|
||||
meta: {
|
||||
device_id: 'CVR-0042',
|
||||
firmware_version: '0.9.4',
|
||||
firmware_version: '0.1.0-alpha',
|
||||
uptime_s: 432000,
|
||||
wifi_rssi: -58,
|
||||
timestamp_utc: NOW,
|
||||
@@ -408,7 +408,6 @@ const fullMockState: CultivarState = {
|
||||
last_reservoir_clean_ts: NOW - 16 * HOUR * 24,
|
||||
},
|
||||
ui: {
|
||||
scrubber_ts: null,
|
||||
selected_bag_id: null,
|
||||
onboarding_complete: localStorage.getItem('onboarding_complete') === 'true',
|
||||
},
|
||||
@@ -451,7 +450,6 @@ const minimalState: CultivarState = {
|
||||
last_reservoir_clean_ts: 0,
|
||||
},
|
||||
ui: {
|
||||
scrubber_ts: null,
|
||||
selected_bag_id: null,
|
||||
onboarding_complete: false,
|
||||
},
|
||||
|
||||
@@ -75,10 +75,6 @@ function createStore() {
|
||||
}
|
||||
}
|
||||
|
||||
function setScrubberTs(ts: number | null) {
|
||||
state.ui.scrubber_ts = ts;
|
||||
}
|
||||
|
||||
function selectBag(bagId: string | null) {
|
||||
state.ui.selected_bag_id = bagId;
|
||||
}
|
||||
@@ -103,10 +99,8 @@ function createStore() {
|
||||
|
||||
return {
|
||||
get state() { return state; },
|
||||
applyDiff,
|
||||
startMockWs,
|
||||
stopMockWs,
|
||||
setScrubberTs,
|
||||
selectBag,
|
||||
completeOnboarding,
|
||||
dismissAlert,
|
||||
|
||||
+202
-248
@@ -2,6 +2,7 @@
|
||||
import { cultivar } from '../store.svelte';
|
||||
import type { Chamber, BagState } from '../types';
|
||||
import FruitCluster from './FruitCluster.svelte';
|
||||
import GalleryFrame, { type FrameSpec } from './GalleryFrame.svelte';
|
||||
import { profileFor, imageFor } from './species';
|
||||
|
||||
interface Props {
|
||||
@@ -46,12 +47,11 @@
|
||||
|
||||
// Fill remaining slots with the beloved generic illustrations
|
||||
const generics = [
|
||||
{ strain: 'Family portrait', src: '/img/illustration.webp', slotId: 'est. the Proterozoic', isGeneric: true },
|
||||
{ strain: 'The boys', src: '/img/illustration_oysters.webp', slotId: 'oil on canvas · 2024', isGeneric: true },
|
||||
{ strain: 'Mycelial dreams', src: '/img/illustration_mycelium.webp', slotId: 'acrylic on canvas · 2025', isGeneric: true },
|
||||
{ strain: 'Fungi friends', src: '/img/illustration_mycelium.webp', slotId: 'watercolor · 2025', isGeneric: true },
|
||||
{ strain: 'Spore sisters', src: '/img/illustration_mycelium.webp', slotId: 'mixed media · 2025', isGeneric: true },
|
||||
{ strain: 'Hyphal harmony', src: '/img/illustration_mycelium.webp', slotId: 'digital art · 2025', isGeneric: true },
|
||||
{ strain: 'Family Portrait', src: '/img/illustration.webp', slotId: 'est. the Proterozoic', isGeneric: true },
|
||||
{ strain: 'The Boys', src: '/img/illustration_oysters.webp', slotId: 'oil on canvas · 2024', isGeneric: true },
|
||||
{ strain: 'Mycelial Dreams', src: '/img/illustration_mycelium.webp', slotId: 'acrylic on canvas · 2025', isGeneric: true },
|
||||
{ strain: 'Fungi Friends', src: '/img/illustration_mycelium.webp', slotId: 'watercolor · 2025', isGeneric: true },
|
||||
{ strain: 'Spore Sisters', src: '/img/illustration_mycelium.webp', slotId: 'mixed media · 2025', isGeneric: true },
|
||||
];
|
||||
|
||||
for (const gen of generics) {
|
||||
@@ -62,6 +62,87 @@
|
||||
return images;
|
||||
});
|
||||
|
||||
// ── Wall-gallery frames ─────────────────────────────────────────
|
||||
// One factory per physical frame on the wall. Each receives the
|
||||
// gallery entry in its slot (if any) and produces a FrameSpec for
|
||||
// <GalleryFrame>. Leaving the geometry hand-tuned — the frames are
|
||||
// meant to feel placed, not generated.
|
||||
type GalleryEntry = { strain: string; src: string; slotId: string; isGeneric?: boolean };
|
||||
|
||||
function placard(s: GalleryEntry): string {
|
||||
return s.isGeneric ? s.slotId : `Slot ${s.slotId}`;
|
||||
}
|
||||
|
||||
// Frame factories — indexed by position on the wall. `null` slots
|
||||
// belong to hand-authored frames (e.g. the "Welcome home" tapestry at
|
||||
// index 2) that stay inline in the template.
|
||||
const frameFactories: Array<((s: GalleryEntry) => FrameSpec) | null> = [
|
||||
// 1 · left wall, lower — dark walnut
|
||||
(s) => ({
|
||||
tx: -12, ty: 168, rotate: -3.5,
|
||||
frame: { x: -21, y: -34, w: 42, h: 60, fill: '#4a3a24' },
|
||||
liner: { stroke: '#7a5f3d', opacity: 0.8 },
|
||||
mat: { fill: '#f3e9ce' },
|
||||
image: { href: s.src, x: -16, y: -29, w: 32, h: 44 },
|
||||
placard: { x: -16, y: 30, w: 32, h: 11 },
|
||||
title: { text: s.strain, y: 35, size: 4.2 },
|
||||
subtitle: { text: placard(s), y: 39.2, size: 3 },
|
||||
}),
|
||||
// 2 · right wall, upper — gold
|
||||
(s) => ({
|
||||
tx: 490, ty: 65, rotate: 2.5,
|
||||
frame: { x: -18, y: -26, w: 36, h: 46, fill: '#8a6f3a', stroke: '#5a461e' },
|
||||
liner: { stroke: '#c2a55a', opacity: 0.75 },
|
||||
mat: { fill: '#fef7e4' },
|
||||
image: { href: s.src, x: -13.5, y: -21.5, w: 27, h: 32 },
|
||||
placard: { x: -14, y: 24, w: 28, h: 10.5, fill: '#f3ead0', stroke: '#a89466' },
|
||||
title: { text: s.strain, y: 28.8, size: 4.2 },
|
||||
subtitle: { text: placard(s), y: 32.8, size: 2.9 },
|
||||
}),
|
||||
// (frame 3 is hand-authored — the "Welcome home" tapestry — see template)
|
||||
null,
|
||||
// 4 · left wall, upper — mid-brown
|
||||
(s) => ({
|
||||
tx: -8, ty: 68, rotate: 0,
|
||||
frame: { x: -19, y: -30, w: 38, h: 52, fill: '#5a4632' },
|
||||
liner: { stroke: '#8a6f4a', opacity: 0.75 },
|
||||
mat: { fill: '#f4ebd1' },
|
||||
image: { href: s.src, x: -14, y: -25, w: 28, h: 38 },
|
||||
placard: { x: -14, y: 26, w: 28, h: 10, fill: '#f0e5c8' },
|
||||
title: { text: s.strain, y: 30, size: 4 },
|
||||
subtitle: { text: placard(s), y: 34, size: 2.8 },
|
||||
}),
|
||||
// 5 · left wall, bottom — warm brown
|
||||
(s) => ({
|
||||
tx: -12, ty: 260, rotate: 0.2,
|
||||
frame: { x: -20, y: -28, w: 40, h: 50, fill: '#6b5438' },
|
||||
liner: { stroke: '#9a7f58', opacity: 0.7 },
|
||||
mat: { fill: '#f8f0da' },
|
||||
image: { href: s.src, x: -15, y: -23, w: 30, h: 36 },
|
||||
placard: { x: -15, y: 27, w: 30, h: 10.5, fill: '#f3e8cc' },
|
||||
title: { text: s.strain, y: 31.2, size: 4.1 },
|
||||
subtitle: { text: placard(s), y: 35.2, size: 2.9 },
|
||||
}),
|
||||
// 6 · right wall, middle — large gold
|
||||
(s) => ({
|
||||
tx: 490, ty: 142, rotate: -2,
|
||||
frame: { x: -22.5, y: -22, w: 45, h: 57, fill: '#7a5f3d' },
|
||||
liner: { stroke: '#b09870', opacity: 0.7 },
|
||||
mat: { fill: '#fef9e8' },
|
||||
image: { href: s.src, x: -18, y: -17.5, w: 36, h: 47 },
|
||||
placard: { x: -20, y: 38, w: 40, h: 10, fill: '#f4ebd1', stroke: '#a89466' },
|
||||
title: { text: s.strain, y: 42.5, size: 5 },
|
||||
subtitle: { text: placard(s), y: 46.5, size: 3.5 },
|
||||
}),
|
||||
];
|
||||
|
||||
const galleryFrames = $derived(
|
||||
frameFactories.map((make, i) => {
|
||||
const entry = gallerySpecies[i];
|
||||
return make && entry ? make(entry) : null;
|
||||
})
|
||||
);
|
||||
|
||||
// Two fans — one per compartment, used for fresh-air exchange
|
||||
const colFan = $derived(hw.fans.find(f => f.chamber_id === 'main') ?? hw.fans[0] ?? { speed_pct: 0 });
|
||||
const fruitFan = $derived(hw.fans.find(f => f.chamber_id === 'second') ?? hw.fans[1] ?? { speed_pct: 0 });
|
||||
@@ -207,6 +288,27 @@
|
||||
</script>
|
||||
|
||||
<div class="twin-wrap">
|
||||
<div class="labels">
|
||||
<div class="label-card">
|
||||
<div class="lc-kicker">Colonization</div>
|
||||
<div class="lc-meta">
|
||||
<span class="lc-count">{occupiedCol}<span class="lc-total">/{totalCol}</span></span>
|
||||
<span class="lc-sep">·</span>
|
||||
<span class="lc-desc">{occupiedCol === 1 ? 'bag' : 'bags'} colonizing</span>
|
||||
</div>
|
||||
<div class="lc-poem font-serif italic">An underground forest floor.</div>
|
||||
</div>
|
||||
|
||||
<div class="label-card right">
|
||||
<div class="lc-kicker">Fruiting</div>
|
||||
<div class="lc-meta">
|
||||
<span class="lc-count">{occupiedFruit}<span class="lc-total">/{totalFruit}</span></span>
|
||||
<span class="lc-sep">·</span>
|
||||
<span class="lc-desc">{occupiedFruit === 1 ? 'bag' : 'bags'} fruiting</span>
|
||||
</div>
|
||||
<div class="lc-poem font-serif italic">A shaded grove after rain.</div>
|
||||
</div>
|
||||
</div>
|
||||
<svg
|
||||
class="appliance"
|
||||
viewBox="-48 -30 576 475"
|
||||
@@ -214,14 +316,6 @@
|
||||
aria-label="Your Cultivar — {occupiedCol + occupiedFruit} of {totalCol + totalFruit} bags growing"
|
||||
>
|
||||
<defs>
|
||||
<!-- ── Room atmosphere: a warm wall gradient behind the appliance ── -->
|
||||
<linearGradient id="room-wall" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#f3ede0"/>
|
||||
<stop offset="45%" stop-color="#f6f1e5"/>
|
||||
<stop offset="85%" stop-color="#ece4d2"/>
|
||||
<stop offset="100%" stop-color="#e2d8c1"/>
|
||||
</linearGradient>
|
||||
|
||||
<!-- Ambient ceiling spotlight overhead of the appliance -->
|
||||
<radialGradient id="room-spot" cx="50%" cy="0%" r="75%">
|
||||
<stop offset="0%" stop-color="#fff7e2" stop-opacity="0.75"/>
|
||||
@@ -254,12 +348,6 @@
|
||||
<stop offset="0%" stop-color="#fff"/>
|
||||
<stop offset="100%" stop-color="#fff"/>
|
||||
</linearGradient>
|
||||
|
||||
<linearGradient id="glass-shine" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#ffffff" stop-opacity="0.16"/>
|
||||
<stop offset="22%" stop-color="#ffffff" stop-opacity="0.04"/>
|
||||
<stop offset="100%" stop-color="#ffffff" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
|
||||
<radialGradient id="col-led" cx="50%" cy="0%" r="120%" fy="0%">
|
||||
<stop offset="0%" stop-color={colLedColor} stop-opacity={colLedOpacity * 0.9}/>
|
||||
@@ -306,7 +394,7 @@
|
||||
</feMerge>
|
||||
</filter>
|
||||
|
||||
<!-- Mercedes-style bloom for the door-ajar light spill -->
|
||||
<!-- Bloom for the door-ajar light spill -->
|
||||
<filter id="ajar-bloom" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur in="SourceGraphic" stdDeviation="2.4"/>
|
||||
</filter>
|
||||
@@ -391,8 +479,8 @@
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
<!-- ─── Room backdrop: gives the appliance a sense of place ─── -->
|
||||
<rect x="-960" y="10" width="1920px" height="415" fill="url(#room-wall)"/>
|
||||
<!-- Room backdrop is now rendered as a full-width CSS layer in the
|
||||
HTML above; no SVG rect needed here. -->
|
||||
|
||||
<!-- ─── Back-wall gallery: tilted frames + museum placards ───
|
||||
Sits behind the appliance so the frames feel hung on the
|
||||
@@ -400,161 +488,39 @@
|
||||
Displays up to 3 unique species currently growing. -->
|
||||
<g class="wall-gallery" aria-hidden="true" pointer-events="none">
|
||||
|
||||
{#if gallerySpecies[0]}
|
||||
<!-- Frame 1 · LEFT wall — species portrait #1 -->
|
||||
{@const s1 = gallerySpecies[0]}
|
||||
<g transform="translate(-12, 188) rotate(-3.5)">
|
||||
<rect x="-21" y="-34" width="42" height="60" rx="0.6"
|
||||
fill="#000" opacity="0.25" transform="translate(1.8, 2.2)"/>
|
||||
<rect x="-21" y="-34" width="42" height="60" rx="0.8"
|
||||
fill="#4a3a24" stroke="#2a1f12" stroke-width="0.3"/>
|
||||
<rect x="-19.5" y="-32.5" width="39" height="57" rx="0.5"
|
||||
fill="none" stroke="#7a5f3d" stroke-width="0.35" opacity="0.8"/>
|
||||
<rect x="-18" y="-31" width="36" height="54" fill="#f3e9ce"/>
|
||||
<image href={s1.src}
|
||||
x="-16" y="-29" width="32" height="44"
|
||||
preserveAspectRatio="xMidYMid slice"/>
|
||||
<rect x="-16" y="-29" width="32" height="44"
|
||||
fill="none" stroke="#2a1f12" stroke-width="0.3" opacity="0.3"/>
|
||||
<rect x="-16" y="30" width="32" height="11" rx="0.5"
|
||||
fill="#ebe0c2" stroke="#9d8b61" stroke-width="0.2"/>
|
||||
<text x="0" y="35" text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: 4.2px; font-family: 'DM Serif Display', Georgia, serif;">{s1.strain}</text>
|
||||
<text x="0" y="39.2" text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: 3px; font-style: italic; font-family: 'DM Sans', sans-serif;">{s1.isGeneric ? s1.slotId : `Slot ${s1.slotId}`}</text>
|
||||
</g>
|
||||
{/if}
|
||||
<!-- Species-portrait frames (geometry in frameFactories above) -->
|
||||
{#each galleryFrames as frame, i (i)}
|
||||
{#if frame}
|
||||
<GalleryFrame spec={frame} />
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
{#if gallerySpecies[1]}
|
||||
<!-- Frame 2 · RIGHT wall top — species portrait #2 -->
|
||||
{@const s2 = gallerySpecies[1]}
|
||||
<g transform="translate(493, 108) rotate(4.5)">
|
||||
<rect x="-18" y="-26" width="36" height="46" rx="0.6"
|
||||
fill="#000" opacity="0.22" transform="translate(1.5, 2)"/>
|
||||
<rect x="-18" y="-26" width="36" height="46" rx="0.8"
|
||||
fill="#8a6f3a" stroke="#5a461e" stroke-width="0.3"/>
|
||||
<rect x="-16.5" y="-24.5" width="33" height="43" rx="0.5"
|
||||
fill="none" stroke="#c2a55a" stroke-width="0.35" opacity="0.75"/>
|
||||
<rect x="-15" y="-23" width="30" height="40" fill="#fef7e4"/>
|
||||
<image href={s2.src}
|
||||
x="-13.5" y="-21.5" width="27" height="32"
|
||||
preserveAspectRatio="xMidYMid slice"/>
|
||||
<rect x="-13.5" y="-21.5" width="27" height="32"
|
||||
fill="none" stroke="#5a461e" stroke-width="0.25" opacity="0.3"/>
|
||||
<rect x="-14" y="24" width="28" height="10.5" rx="0.5"
|
||||
fill="#f3ead0" stroke="#a89466" stroke-width="0.2"/>
|
||||
<text x="0" y="28.8" text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: 4.2px; font-family: 'DM Serif Display', Georgia, serif;">{s2.strain}</text>
|
||||
<text x="0" y="32.8" text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: 2.9px; font-style: italic; font-family: 'DM Sans', sans-serif;">{s2.isGeneric ? s2.slotId : `Slot ${s2.slotId}`}</text>
|
||||
</g>
|
||||
{/if}
|
||||
|
||||
<!-- Fallback when fewer than 3 species: show the classic "Live, Laugh, Lignify" -->
|
||||
<g transform="translate(492, 278) rotate(-2.5)">
|
||||
<rect x="-22" y="-30" width="44" height="50" rx="0.8"
|
||||
fill="#000" opacity="0.22" transform="translate(1.8, 2.4)"/>
|
||||
<rect x="-22" y="-30" width="44" height="50" rx="1"
|
||||
fill="#cbb592" stroke="#85714b" stroke-width="0.4"/>
|
||||
<rect x="-19" y="-27" width="38" height="44" fill="#fff8e7"/>
|
||||
<image href="/img/illustration_mycelium.webp"
|
||||
x="-19" y="-27" width="38" height="44"
|
||||
preserveAspectRatio="xMidYMid slice" opacity="0.85"/>
|
||||
<text x="0" y="-14" text-anchor="middle" fill="#fff"
|
||||
style="font-size: 6.5px; font-family: 'DM Serif Display', Georgia, serif;">Live</text>
|
||||
<text x="0" y="-6" text-anchor="middle" fill="#fff"
|
||||
style="font-size: 6.5px; font-family: 'DM Serif Display', Georgia, serif;">Laugh</text>
|
||||
<text x="0" y="3" text-anchor="middle" fill="#fff"
|
||||
style="font-size: 6.5px; font-family: 'DM Serif Display', Georgia, serif;">Lignify</text>
|
||||
<line x1="-7" y1="12" x2="7" y2="12" stroke="#b09870" stroke-width="0.4" opacity="0.7"/>
|
||||
<rect x="-19" y="22" width="40" height="12" rx="0.6"
|
||||
fill="#ece2c3" stroke="#a89466" stroke-width="0.25"/>
|
||||
<text x="1" y="27.5" text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: 4.5px; font-family: 'DM Serif Display', Georgia, serif;">Welcome home</text>
|
||||
<text x="1" y="32" text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: 3.4px; font-style: italic; font-family: 'DM Sans', sans-serif;">hand-stitched, probably</text>
|
||||
</g>
|
||||
|
||||
{#if gallerySpecies[3]}
|
||||
<!-- Frame 4 · LEFT wall top — species portrait #4 -->
|
||||
{@const s4 = gallerySpecies[3]}
|
||||
<g transform="translate(-8, 88) rotate(2.8)">
|
||||
<rect x="-19" y="-30" width="38" height="52" rx="0.6"
|
||||
fill="#000" opacity="0.23" transform="translate(1.6, 2)"/>
|
||||
<rect x="-19" y="-30" width="38" height="52" rx="0.8"
|
||||
fill="#5a4632" stroke="#2a1f12" stroke-width="0.3"/>
|
||||
<rect x="-17.5" y="-28.5" width="35" height="49" rx="0.5"
|
||||
fill="none" stroke="#8a6f4a" stroke-width="0.35" opacity="0.75"/>
|
||||
<rect x="-16" y="-27" width="32" height="46" fill="#f4ebd1"/>
|
||||
<image href={s4.src}
|
||||
x="-14" y="-25" width="28" height="38"
|
||||
preserveAspectRatio="xMidYMid slice"/>
|
||||
<rect x="-14" y="-25" width="28" height="38"
|
||||
fill="none" stroke="#2a1f12" stroke-width="0.3" opacity="0.3"/>
|
||||
<rect x="-14" y="26" width="28" height="10" rx="0.5"
|
||||
fill="#f0e5c8" stroke="#9d8b61" stroke-width="0.2"/>
|
||||
<text x="0" y="30" text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: 4px; font-family: 'DM Serif Display', Georgia, serif;">{s4.strain}</text>
|
||||
<text x="0" y="34" text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: 2.8px; font-style: italic; font-family: 'DM Sans', sans-serif;">{s4.isGeneric ? s4.slotId : `Slot ${s4.slotId}`}</text>
|
||||
</g>
|
||||
{/if}
|
||||
|
||||
{#if gallerySpecies[4]}
|
||||
<!-- Frame 5 · LEFT wall bottom — species portrait #5 -->
|
||||
{@const s5 = gallerySpecies[4]}
|
||||
<g transform="translate(-16, 300) rotate(4.2)">
|
||||
<rect x="-20" y="-28" width="40" height="50" rx="0.6"
|
||||
fill="#000" opacity="0.24" transform="translate(1.7, 2.1)"/>
|
||||
<rect x="-20" y="-28" width="40" height="50" rx="0.8"
|
||||
fill="#6b5438" stroke="#2a1f12" stroke-width="0.3"/>
|
||||
<rect x="-18.5" y="-26.5" width="37" height="47" rx="0.5"
|
||||
fill="none" stroke="#9a7f58" stroke-width="0.35" opacity="0.7"/>
|
||||
<rect x="-17" y="-25" width="34" height="44" fill="#f8f0da"/>
|
||||
<image href={s5.src}
|
||||
x="-15" y="-23" width="30" height="36"
|
||||
preserveAspectRatio="xMidYMid slice"/>
|
||||
<rect x="-15" y="-23" width="30" height="36"
|
||||
fill="none" stroke="#2a1f12" stroke-width="0.3" opacity="0.3"/>
|
||||
<rect x="-15" y="27" width="30" height="10.5" rx="0.5"
|
||||
fill="#f3e8cc" stroke="#9d8b61" stroke-width="0.2"/>
|
||||
<text x="0" y="31.2" text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: 4.1px; font-family: 'DM Serif Display', Georgia, serif;">{s5.strain}</text>
|
||||
<text x="0" y="35.2" text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: 2.9px; font-style: italic; font-family: 'DM Sans', sans-serif;">{s5.isGeneric ? s5.slotId : `Slot ${s5.slotId}`}</text>
|
||||
</g>
|
||||
{/if}
|
||||
|
||||
{#if gallerySpecies[5]}
|
||||
<!-- Frame 6 · RIGHT wall middle — species portrait #6 -->
|
||||
{@const s6 = gallerySpecies[5]}
|
||||
<g transform="translate(485, 198) rotate(3.8)">
|
||||
<rect x="-15" y="-22" width="30" height="38" rx="0.6"
|
||||
fill="#000" opacity="0.21" transform="translate(1.3, 1.8)"/>
|
||||
<rect x="-15" y="-22" width="30" height="38" rx="0.8"
|
||||
fill="#7a5f3d" stroke="#2a1f12" stroke-width="0.3"/>
|
||||
<rect x="-13.5" y="-20.5" width="27" height="35" rx="0.5"
|
||||
fill="none" stroke="#b09870" stroke-width="0.35" opacity="0.7"/>
|
||||
<rect x="-12" y="-19" width="24" height="32" fill="#fef9e8"/>
|
||||
<image href={s6.src}
|
||||
x="-10.5" y="-17.5" width="21" height="25"
|
||||
preserveAspectRatio="xMidYMid slice"/>
|
||||
<rect x="-10.5" y="-17.5" width="21" height="25"
|
||||
fill="none" stroke="#5a461e" stroke-width="0.25" opacity="0.3"/>
|
||||
<rect x="-15" y="18" width="30" height="9.5" rx="0.5"
|
||||
fill="#f4ebd1" stroke="#a89466" stroke-width="0.2"/>
|
||||
<text x="0" y="21.8" text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: 3.6px; font-family: 'DM Serif Display', Georgia, serif;">{s6.strain}</text>
|
||||
<text x="0" y="25.3" text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: 2.5px; font-style: italic; font-family: 'DM Sans', sans-serif;">{s6.isGeneric ? s6.slotId : `Slot ${s6.slotId}`}</text>
|
||||
</g>
|
||||
{/if}
|
||||
<!-- Frame 3 · "Welcome home" tapestry — unique layout, stays inline -->
|
||||
<g transform="translate(492, 252) rotate(3.4)">
|
||||
<rect x="-22" y="-30" width="44" height="50" rx="0.8"
|
||||
fill="#000" opacity="0.22" transform="translate(1.8, 2.4)"/>
|
||||
<rect x="-22" y="-30" width="44" height="50" rx="1"
|
||||
fill="#cbb592" stroke="#85714b" stroke-width="0.4"/>
|
||||
<rect x="-19" y="-27" width="38" height="44" fill="#fff8e7"/>
|
||||
<image href="/img/illustration_mycelium.webp"
|
||||
x="-19" y="-27" width="38" height="44"
|
||||
preserveAspectRatio="xMidYMid slice" opacity="0.85"/>
|
||||
<text x="0" y="-14" text-anchor="middle" fill="#fff"
|
||||
style="font-size: 6.5px; font-family: 'DM Serif Display', Georgia, serif;">Live</text>
|
||||
<text x="0" y="-6" text-anchor="middle" fill="#fff"
|
||||
style="font-size: 6.5px; font-family: 'DM Serif Display', Georgia, serif;">Laugh</text>
|
||||
<text x="0" y="3" text-anchor="middle" fill="#fff"
|
||||
style="font-size: 6.5px; font-family: 'DM Serif Display', Georgia, serif;">Lignify</text>
|
||||
<line x1="-7" y1="12" x2="7" y2="12" stroke="#b09870" stroke-width="0.4" opacity="0.7"/>
|
||||
<rect x="-19" y="22" width="40" height="12" rx="0.6"
|
||||
fill="#ece2c3" stroke="#a89466" stroke-width="0.25"/>
|
||||
<text x="1" y="27.5" text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: 4.5px; font-family: 'DM Serif Display', Georgia, serif;">Welcome home</text>
|
||||
<text x="1" y="32" text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: 3.4px; font-style: italic; font-family: 'DM Sans', sans-serif;">hand-stitched, probably</text>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- Floor line (soft horizon where wall meets counter) -->
|
||||
<line x1="-48" y1="398" x2="528" y2="398"
|
||||
stroke="#cbbfa3" stroke-width="0.6" opacity="0.55"/>
|
||||
|
||||
<!-- Floor reflection band beneath the appliance -->
|
||||
<rect x="20" y="398" width="440" height="30" rx="2" fill="url(#floor-reflection)" opacity="0.6"/>
|
||||
|
||||
@@ -580,18 +546,7 @@
|
||||
<text x="34" y="388"
|
||||
font-family="DM Serif Display, Georgia, serif" font-size="8" font-weight="400"
|
||||
fill="#8b8269" letter-spacing="0.04em">Cultivar</text>
|
||||
<circle cx="70" cy="385" r="1" fill="#7bb27b" class="status-led"/>
|
||||
|
||||
<!-- Seam between doors (also where both doors hinge, French-door style) -->
|
||||
<line x1="240" y1="52" x2="240" y2="349"
|
||||
stroke="#cdc3aa" stroke-width="0.8" opacity="0.6"/>
|
||||
<!-- Hinge pins at top + bottom of the seam -->
|
||||
<g aria-hidden="true">
|
||||
<circle cx="237" cy="54" r="1.1" fill="#9d9377" opacity="0.7"/>
|
||||
<circle cx="243" cy="54" r="1.1" fill="#9d9377" opacity="0.7"/>
|
||||
<circle cx="237" cy="347" r="1.1" fill="#9d9377" opacity="0.7"/>
|
||||
<circle cx="243" cy="347" r="1.1" fill="#9d9377" opacity="0.7"/>
|
||||
</g>
|
||||
<circle cx="70" cy="385" r="1" fill="#7bb27b" class="status-led"/>
|
||||
|
||||
<!-- ═══ LEFT COMPARTMENT · colonization ═══ -->
|
||||
<g aria-label="Colonization compartment">
|
||||
@@ -717,17 +672,8 @@
|
||||
{/each}
|
||||
{/each}
|
||||
|
||||
<!-- Glass shine + handle on the colonization door.
|
||||
Door opens to the outer LEFT (hinges at center seam). -->
|
||||
<rect x={LEFT.x + LEFT.w * 0.45} y={LEFT.y} width={LEFT.w * 0.55} height={LEFT.h}
|
||||
fill="url(#glass-shine)" pointer-events="none"/>
|
||||
<!-- Metallic handle (outer left edge, inside the body bezel) -->
|
||||
<rect x={LEFT.x - 7} y={LEFT.y + 12} width="3" height={LEFT.h - 24} rx="1.5"
|
||||
fill="#b0a788" opacity="0.8"/>
|
||||
<rect x={LEFT.x - 7} y={LEFT.y + 12} width="1.2" height={LEFT.h - 24} rx="0.6"
|
||||
fill="#f3ecd8" opacity="0.7"/>
|
||||
|
||||
<!-- Door-ajar visual (Mercedes-style light leak) — colonization opens OUTER LEFT -->
|
||||
|
||||
<!-- Door-ajar visual (light leak) — colonization opens OUTER LEFT -->
|
||||
{#if colDoorOpen}
|
||||
<rect x={LEFT.x} y={LEFT.y} width={LEFT.w} height={LEFT.h} rx="4"
|
||||
fill="url(#ajar-bloom-col)" pointer-events="none" class="ajar-bloom"/>
|
||||
@@ -890,17 +836,7 @@
|
||||
{/each}
|
||||
{/each}
|
||||
|
||||
<!-- Glass door shine -->
|
||||
<rect x={RIGHT.x} y={RIGHT.y} width={RIGHT.w * 0.55} height={RIGHT.h}
|
||||
fill="url(#glass-shine)" pointer-events="none"/>
|
||||
|
||||
<!-- Glass door handle (outer right, metallic two-tone) -->
|
||||
<rect x={RIGHT.x + RIGHT.w + 4} y={RIGHT.y + 12} width="3" height={RIGHT.h - 24} rx="1.5"
|
||||
fill="#b0a788" opacity="0.8"/>
|
||||
<rect x={RIGHT.x + RIGHT.w + 4 + 1.8} y={RIGHT.y + 12} width="1.2" height={RIGHT.h - 24} rx="0.6"
|
||||
fill="#f3ecd8" opacity="0.7"/>
|
||||
|
||||
<!-- Door-ajar visual (Mercedes-style) — fruiting hinges on the RIGHT -->
|
||||
<!-- Door-ajar visual — fruiting hinges on the RIGHT -->
|
||||
{#if fruitDoorOpen}
|
||||
<rect x={RIGHT.x} y={RIGHT.y} width={RIGHT.w} height={RIGHT.h} rx="4"
|
||||
fill="url(#ajar-bloom-fruit)" pointer-events="none" class="ajar-bloom"/>
|
||||
@@ -1060,29 +996,6 @@
|
||||
</g>
|
||||
{/if}
|
||||
</svg>
|
||||
|
||||
<!-- Compartment labels below the appliance -->
|
||||
<div class="labels">
|
||||
<div class="label-card">
|
||||
<div class="lc-kicker">Left side · Colonization</div>
|
||||
<div class="lc-meta">
|
||||
<span class="lc-count">{occupiedCol}<span class="lc-total">/{totalCol}</span></span>
|
||||
<span class="lc-sep">·</span>
|
||||
<span class="lc-desc">{occupiedCol === 1 ? 'bag' : 'bags'} colonizing</span>
|
||||
</div>
|
||||
<div class="lc-poem font-serif italic">Like a forest floor, underground.</div>
|
||||
</div>
|
||||
|
||||
<div class="label-card right">
|
||||
<div class="lc-kicker">Right side · Fruiting</div>
|
||||
<div class="lc-meta">
|
||||
<span class="lc-count">{occupiedFruit}<span class="lc-total">/{totalFruit}</span></span>
|
||||
<span class="lc-sep">·</span>
|
||||
<span class="lc-desc">{occupiedFruit === 1 ? 'bag' : 'bags'} fruiting</span>
|
||||
</div>
|
||||
<div class="lc-poem font-serif italic">Like a shaded grove after rain.</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@@ -1092,10 +1005,29 @@
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
/* Skip painting the whole twin while it's scrolled offscreen */
|
||||
content-visibility: auto;
|
||||
contain-intrinsic-size: 680px 500px;
|
||||
}
|
||||
.twin-wrap::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 1;
|
||||
pointer-events: none;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
var(--paper-1) 0%,
|
||||
var(--paper-2) 40%,
|
||||
var(--paper-3) 78%,
|
||||
var(--paper) 78%,
|
||||
var(--paper) 82%,
|
||||
var(--ink-muted) 82%,
|
||||
var(--ink-muted) 94%
|
||||
);
|
||||
}
|
||||
|
||||
.appliance {
|
||||
width: 100%;
|
||||
@@ -1104,6 +1036,7 @@
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
overflow: visible;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* ── Humidifier mist rings (replacement for SMIL <animate>) ── */
|
||||
@@ -1289,15 +1222,19 @@
|
||||
.labels {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 24px;
|
||||
max-width: 680px;
|
||||
gap: 4px;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
padding: 0 8px;
|
||||
margin: 10px auto -80px;
|
||||
padding: 0 28px;
|
||||
}
|
||||
|
||||
.label-card { display: flex; flex-direction: column; gap: 4px; }
|
||||
.label-card.right { text-align: right; }
|
||||
.label-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: 1.25;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.lc-kicker {
|
||||
font-family: var(--font-sans);
|
||||
@@ -1305,21 +1242,23 @@
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-2);
|
||||
color: var(--ink);
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.lc-meta {
|
||||
font-size: 12.5px;
|
||||
color: var(--ink-muted);
|
||||
color: var(--ink);
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.label-card.right .lc-meta { justify-content: flex-end; }
|
||||
|
||||
.lc-poem {
|
||||
font-size: 12.5px;
|
||||
font-size: 11.5px;
|
||||
color: var(--ink-muted);
|
||||
opacity: 0.45;
|
||||
letter-spacing: 0.005em;
|
||||
margin-top: 2px;
|
||||
}
|
||||
@@ -1327,15 +1266,30 @@
|
||||
.lc-count {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 15px;
|
||||
color: var(--forest);
|
||||
z-index: 10;
|
||||
color: var(--ink);
|
||||
font-weight: var(--fw-display);
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
.lc-total { color: var(--ink-muted); font-size: 12px; }
|
||||
.lc-sep { opacity: 0.4; }
|
||||
.lc-desc { font-style: italic; font-family: var(--font-serif); color: var(--ink-2); }
|
||||
.lc-total {
|
||||
font-family: var(--font-serif);
|
||||
color: var(--ink);
|
||||
opacity: 1;
|
||||
font-size: 15px;
|
||||
}
|
||||
.lc-sep { opacity: 0.3; color: var(--ink); }
|
||||
.lc-desc {
|
||||
font-style: italic;
|
||||
font-family: var(--font-serif);
|
||||
color: var(--ink-muted);
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.labels { gap: 14px; }
|
||||
@media (max-width: 640px) {
|
||||
.labels { gap: 2px; margin-bottom: -62px; }
|
||||
}
|
||||
|
||||
@media (max-width: 440px) {
|
||||
.labels { gap: 2px; margin-bottom: -50px; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,80 @@
|
||||
<script lang="ts">
|
||||
// A single "framed painting" hung on the room's back wall behind the
|
||||
// Cultivar appliance. All geometry is authored per-frame so each one
|
||||
// can feel hand-placed — the component just handles the repeated SVG
|
||||
// structure (drop shadow, frame, optional liner, mat, image, placard).
|
||||
|
||||
export type FrameSpec = {
|
||||
/** Group translation + rotation (origin = placard-hang point) */
|
||||
tx: number;
|
||||
ty: number;
|
||||
rotate: number;
|
||||
/** Outer frame rect (coordinates relative to the group origin) */
|
||||
frame: { x: number; y: number; w: number; h: number; fill: string; stroke?: string };
|
||||
/** Optional thin inner "gold leaf" liner */
|
||||
liner?: { stroke: string; opacity?: number };
|
||||
/** Mat inset inside the frame (usually 3 on all sides) */
|
||||
mat: { fill: string; inset?: number };
|
||||
/** Painting image */
|
||||
image: { href: string; x: number; y: number; w: number; h: number };
|
||||
/** Placard that hangs below the frame */
|
||||
placard: { x: number; y: number; w: number; h: number; fill?: string; stroke?: string };
|
||||
/** Title + subtitle text baselines (y relative to group origin) */
|
||||
title: { text: string; y: number; size: number };
|
||||
subtitle: { text: string; y: number; size: number };
|
||||
};
|
||||
|
||||
interface Props { spec: FrameSpec }
|
||||
const { spec }: Props = $props();
|
||||
|
||||
const matInset = $derived(spec.mat.inset ?? 3);
|
||||
// Drop shadow offset derives from frame size so it always looks proportional
|
||||
const shadowDx = $derived(spec.frame.w * 0.043);
|
||||
const shadowDy = $derived(spec.frame.h * 0.037);
|
||||
const frameStroke = $derived(spec.frame.stroke ?? '#2a1f12');
|
||||
const placardFill = $derived(spec.placard.fill ?? '#ebe0c2');
|
||||
const placardStroke = $derived(spec.placard.stroke ?? '#9d8b61');
|
||||
</script>
|
||||
|
||||
<g transform="translate({spec.tx}, {spec.ty}) rotate({spec.rotate})">
|
||||
<!-- Drop shadow -->
|
||||
<rect x={spec.frame.x} y={spec.frame.y} width={spec.frame.w} height={spec.frame.h}
|
||||
rx="0.6" fill="#000" opacity="0.23"
|
||||
transform="translate({shadowDx}, {shadowDy})"/>
|
||||
|
||||
<!-- Frame -->
|
||||
<rect x={spec.frame.x} y={spec.frame.y} width={spec.frame.w} height={spec.frame.h}
|
||||
rx="0.8" fill={spec.frame.fill} stroke={frameStroke} stroke-width="0.3"/>
|
||||
|
||||
<!-- Optional inner gold liner -->
|
||||
{#if spec.liner}
|
||||
<rect
|
||||
x={spec.frame.x + 1.5} y={spec.frame.y + 1.5}
|
||||
width={spec.frame.w - 3} height={spec.frame.h - 3} rx="0.5"
|
||||
fill="none" stroke={spec.liner.stroke} stroke-width="0.35"
|
||||
opacity={spec.liner.opacity ?? 0.78}/>
|
||||
{/if}
|
||||
|
||||
<!-- Mat -->
|
||||
<rect
|
||||
x={spec.frame.x + matInset} y={spec.frame.y + matInset}
|
||||
width={spec.frame.w - matInset * 2} height={spec.frame.h - matInset * 2}
|
||||
fill={spec.mat.fill}/>
|
||||
|
||||
<!-- Image -->
|
||||
<image href={spec.image.href}
|
||||
x={spec.image.x} y={spec.image.y} width={spec.image.w} height={spec.image.h}
|
||||
preserveAspectRatio="xMidYMid slice"/>
|
||||
<rect x={spec.image.x} y={spec.image.y} width={spec.image.w} height={spec.image.h}
|
||||
fill="none" stroke={frameStroke} stroke-width="0.3" opacity="0.3"/>
|
||||
|
||||
<!-- Placard -->
|
||||
<rect x={spec.placard.x} y={spec.placard.y} width={spec.placard.w} height={spec.placard.h}
|
||||
rx="0.5" fill={placardFill} stroke={placardStroke} stroke-width="0.2"/>
|
||||
<text x="0" y={spec.title.y} text-anchor="middle" fill="#2f2615"
|
||||
style="font-size: {spec.title.size}px; font-family: 'DM Serif Display', Georgia, serif;"
|
||||
>{spec.title.text}</text>
|
||||
<text x="0" y={spec.subtitle.y} text-anchor="middle" fill="#8a7650"
|
||||
style="font-size: {spec.subtitle.size}px; font-style: italic; font-family: 'DM Sans', sans-serif;"
|
||||
>{spec.subtitle.text}</text>
|
||||
</g>
|
||||
@@ -137,7 +137,6 @@ export type CultivarState = {
|
||||
last_reservoir_clean_ts: number;
|
||||
};
|
||||
ui: {
|
||||
scrubber_ts: number | null;
|
||||
selected_bag_id: string | null;
|
||||
onboarding_complete: boolean;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { cultivar } from '../store.svelte';
|
||||
import LineChart from '../charts/LineChart.svelte';
|
||||
import InfoHint from './InfoHint.svelte';
|
||||
import type { TimeSeriesPoint, EnvironmentReading, Chamber } from '../types';
|
||||
import type { TimeSeriesPoint, EnvironmentReading, Chamber, ChamberEnvironment } from '../types';
|
||||
|
||||
type Win = '1h' | '6h' | '24h';
|
||||
let activeWin = $state<Win>('24h');
|
||||
@@ -37,38 +37,32 @@
|
||||
const pts = $derived(winPts[activeWin]);
|
||||
const step = $derived(winStep[activeWin]);
|
||||
|
||||
// Per-chamber virtual history (single global history offset by the gap
|
||||
// between each chamber's live reading and the history's latest)
|
||||
function sliceCh(ch: Chamber, key: 'temp_c' | 'rh_pct' | 'co2_ppm' | 'co2e_ppm' | 'voc_ppb'): TimeSeriesPoint[] {
|
||||
// Per-chamber virtual history: the global history, shifted by the gap
|
||||
// between each chamber's live reading and the history's latest.
|
||||
type MetricKey = 'temp_c' | 'rh_pct' | 'co2_ppm' | 'co2e_ppm' | 'voc_ppb';
|
||||
const readCh: Record<MetricKey, (e: ChamberEnvironment | undefined) => number> = {
|
||||
temp_c: e => e?.temp_c ?? 0,
|
||||
rh_pct: e => e?.rh_pct ?? 0,
|
||||
co2_ppm: e => e?.co2_ppm ?? e?.co2e_ppm ?? 0,
|
||||
co2e_ppm: e => e?.co2e_ppm ?? e?.co2_ppm ?? 0,
|
||||
voc_ppb: e => e?.voc_ppb ?? 0,
|
||||
};
|
||||
const readHist: Record<MetricKey, (r: EnvironmentReading) => number> = {
|
||||
temp_c: r => r.temp_c,
|
||||
rh_pct: r => r.rh_pct,
|
||||
co2_ppm: r => r.co2_ppm,
|
||||
co2e_ppm: r => r.co2e_ppm ?? r.co2_ppm,
|
||||
voc_ppb: r => r.voc_ppb,
|
||||
};
|
||||
|
||||
function sliceCh(ch: Chamber, key: MetricKey): TimeSeriesPoint[] {
|
||||
const last = history[history.length - 1];
|
||||
if (!last) return [];
|
||||
|
||||
const live = (() => {
|
||||
switch (key) {
|
||||
case 'temp_c': return ch.environment?.temp_c ?? 0;
|
||||
case 'rh_pct': return ch.environment?.rh_pct ?? 0;
|
||||
case 'co2_ppm': return ch.environment?.co2_ppm ?? ch.environment?.co2e_ppm ?? 0;
|
||||
case 'co2e_ppm': return ch.environment?.co2e_ppm ?? ch.environment?.co2_ppm ?? 0;
|
||||
case 'voc_ppb': return ch.environment?.voc_ppb ?? 0;
|
||||
}
|
||||
})();
|
||||
const baseline = (() => {
|
||||
switch (key) {
|
||||
case 'temp_c': return last.temp_c;
|
||||
case 'rh_pct': return last.rh_pct;
|
||||
case 'co2_ppm': return last.co2_ppm;
|
||||
case 'co2e_ppm': return last.co2e_ppm ?? last.co2_ppm;
|
||||
case 'voc_ppb': return last.voc_ppb;
|
||||
}
|
||||
})();
|
||||
const offset = live - (baseline ?? 0);
|
||||
|
||||
return chartSnap.slice(-pts)
|
||||
const offset = readCh[key](ch.environment) - readHist[key](last);
|
||||
return chartSnap
|
||||
.slice(-pts)
|
||||
.filter((_, i) => i % step === 0)
|
||||
.map(r => {
|
||||
const raw = (r[key] as number | undefined) ?? (r.co2_ppm as number);
|
||||
return { ts: r.ts, value: raw + offset };
|
||||
});
|
||||
.map(r => ({ ts: r.ts, value: readHist[key](r) + offset }));
|
||||
}
|
||||
|
||||
// Metric definitions (label, unit, target-ranges per chamber, sparkline color)
|
||||
@@ -135,7 +129,7 @@
|
||||
},
|
||||
{
|
||||
key: 'co2',
|
||||
label: (() => 'CO₂')(),
|
||||
label: 'CO₂',
|
||||
unit: 'ppm',
|
||||
color: '#8a6a3d',
|
||||
valueFor: (ch) => (ch.type === 'colonization'
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
<script lang="ts">
|
||||
export type RhythmDetailData = {
|
||||
id: string;
|
||||
urgency: 'urgent' | 'action';
|
||||
title: string;
|
||||
lede: string;
|
||||
why?: string;
|
||||
time_estimate?: string;
|
||||
materials?: string[];
|
||||
steps: string[];
|
||||
tips?: string[];
|
||||
/** Primary action button label (e.g., "Mark wiped down") */
|
||||
primary_cta?: string;
|
||||
/** Callback when the primary CTA is clicked */
|
||||
onPrimary?: () => void;
|
||||
};
|
||||
import type { RhythmDetailData } from './rhythm';
|
||||
|
||||
interface Props {
|
||||
detail: RhythmDetailData;
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<script lang="ts">
|
||||
// A small decorative SVG that stands in for a specimen photo. Tinted
|
||||
// per named tone so cards have visual identity even with no imagery.
|
||||
// When a real photo lands, swap this for an <img> bound to imageSrc.
|
||||
|
||||
export type JarTone = 'sage' | 'amber' | 'sienna' | 'rust' | 'slate';
|
||||
|
||||
interface Props {
|
||||
tone: JarTone;
|
||||
/** Specimen's common name — rendered as a small tag on the jar */
|
||||
name: string;
|
||||
/** Short scientific or caption text for the jar tag */
|
||||
caption?: string;
|
||||
/** Single-letter accent (defaults to first letter of name) */
|
||||
initial?: string;
|
||||
/** Optional unique id to disambiguate SVG gradients across instances */
|
||||
uid?: string;
|
||||
}
|
||||
const { tone, name, caption, initial, uid }: Props = $props();
|
||||
|
||||
// Paper-toned palettes so cards sit comfortably on the cream surface.
|
||||
const palettes: Record<JarTone, { bg: string; contents: string; accent: string; ink: string }> = {
|
||||
sage: { bg: '#EEF0E3', contents: '#B5BE93', accent: '#6E7F47', ink: '#3C4A26' },
|
||||
amber: { bg: '#F3E8D4', contents: '#D1B582', accent: '#B8621E', ink: '#5E3A18' },
|
||||
sienna: { bg: '#EDD9C9', contents: '#C99A7A', accent: '#A24B26', ink: '#5C2810' },
|
||||
rust: { bg: '#E7CFC4', contents: '#9D6A56', accent: '#A83838', ink: '#4A1A1A' },
|
||||
slate: { bg: '#E4E6E3', contents: '#9DA49E', accent: '#4F5A52', ink: '#2A302C' },
|
||||
};
|
||||
const p = $derived(palettes[tone]);
|
||||
const letter = $derived((initial ?? name[0] ?? '?').toUpperCase());
|
||||
const gid = $derived(uid ?? tone);
|
||||
</script>
|
||||
|
||||
<svg class="jar" viewBox="0 0 160 200" role="img" aria-label="{name} specimen jar illustration">
|
||||
<defs>
|
||||
<!-- Vertical highlight on the glass -->
|
||||
<linearGradient id="glass-shine-{gid}" x1="0" y1="0" x2="1" y2="0">
|
||||
<stop offset="0%" stop-color="#ffffff" stop-opacity="0.45"/>
|
||||
<stop offset="30%" stop-color="#ffffff" stop-opacity="0.08"/>
|
||||
<stop offset="70%" stop-color="#ffffff" stop-opacity="0"/>
|
||||
<stop offset="100%" stop-color="#000000" stop-opacity="0.08"/>
|
||||
</linearGradient>
|
||||
|
||||
<!-- Textured "contents" fill — subtle paper grain feel -->
|
||||
<radialGradient id="contents-{gid}" cx="0.5" cy="0.35" r="0.8">
|
||||
<stop offset="0%" stop-color={p.contents} stop-opacity="0.95"/>
|
||||
<stop offset="70%" stop-color={p.contents} stop-opacity="0.75"/>
|
||||
<stop offset="100%" stop-color={p.accent} stop-opacity="0.5"/>
|
||||
</radialGradient>
|
||||
|
||||
<clipPath id="jar-clip-{gid}">
|
||||
<rect x="24" y="58" width="112" height="118" rx="4"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
<!-- Soft ground shadow under the jar -->
|
||||
<ellipse cx="80" cy="186" rx="58" ry="4" fill="#000" opacity="0.08"/>
|
||||
|
||||
<!-- Lid -->
|
||||
<rect x="26" y="32" width="108" height="14" rx="2" fill={p.accent} opacity="0.85"/>
|
||||
<rect x="26" y="42" width="108" height="4" fill="#000" opacity="0.12"/>
|
||||
<rect x="26" y="46" width="108" height="6" rx="1" fill={p.accent}/>
|
||||
<rect x="26" y="52" width="108" height="3" fill="#000" opacity="0.15"/>
|
||||
|
||||
<!-- Jar body -->
|
||||
<rect x="24" y="55" width="112" height="125" rx="6" fill="#F2EFE6" stroke={p.ink} stroke-width="0.8" opacity="0.9"/>
|
||||
|
||||
<!-- Contents (clipped inside the body) -->
|
||||
<g clip-path="url(#jar-clip-{gid})">
|
||||
<rect x="24" y="58" width="112" height="122" fill={p.bg}/>
|
||||
<!-- Organic blob of contents -->
|
||||
<path
|
||||
d="M 30 110 C 45 90, 60 105, 75 95 S 110 98, 130 110 L 130 180 L 30 180 Z"
|
||||
fill="url(#contents-{gid})"/>
|
||||
<!-- Scattered texture dots — gives the specimen character -->
|
||||
<circle cx="48" cy="118" r="3" fill={p.accent} opacity="0.55"/>
|
||||
<circle cx="92" cy="128" r="2.2" fill={p.accent} opacity="0.7"/>
|
||||
<circle cx="68" cy="140" r="1.8" fill={p.ink} opacity="0.4"/>
|
||||
<circle cx="110" cy="146" r="2.8" fill={p.accent} opacity="0.55"/>
|
||||
<circle cx="58" cy="156" r="1.4" fill={p.ink} opacity="0.35"/>
|
||||
<circle cx="100" cy="168" r="2.2" fill={p.accent} opacity="0.5"/>
|
||||
<circle cx="76" cy="172" r="1.6" fill={p.ink} opacity="0.45"/>
|
||||
</g>
|
||||
|
||||
<!-- Glass shine overlay -->
|
||||
<rect x="24" y="55" width="112" height="125" rx="6"
|
||||
fill="url(#glass-shine-{gid})" pointer-events="none"/>
|
||||
|
||||
<!-- Paper label on the jar -->
|
||||
<g>
|
||||
<rect x="40" y="100" width="80" height="34" rx="1"
|
||||
fill="#FBF7EC" stroke={p.ink} stroke-opacity="0.25" stroke-width="0.5"/>
|
||||
<!-- Label letter -->
|
||||
<text x="80" y="124" text-anchor="middle" fill={p.ink}
|
||||
style="font-family: 'DM Serif Display', Georgia, serif; font-size: 22px;"
|
||||
>{letter}</text>
|
||||
{#if caption}
|
||||
<text x="80" y="132" text-anchor="middle" fill={p.ink} opacity="0.55"
|
||||
style="font-family: 'DM Sans', sans-serif; font-size: 4.5px; letter-spacing: 0.06em; text-transform: uppercase;"
|
||||
>{caption}</text>
|
||||
{/if}
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
<style>
|
||||
.jar {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -1,106 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
|
||||
const active = $derived(
|
||||
(cultivar.state.environment?.alerts ?? []).filter(a => !a.dismissed)
|
||||
);
|
||||
|
||||
const icons: Record<string, string> = {
|
||||
info: '🍄🟫',
|
||||
warn: '🚩',
|
||||
critical: '⚠️',
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if active.length > 0}
|
||||
<div class="notes">
|
||||
{#each active as alert (alert.id)}
|
||||
<div class="note note-{alert.severity}">
|
||||
<span class="note-mark" aria-hidden="true">{icons[alert.severity] ?? '•'}</span>
|
||||
<span class="note-body">{alert.message}</span>
|
||||
<button
|
||||
class="note-close"
|
||||
onclick={() => cultivar.dismissAlert(alert.id)}
|
||||
aria-label="Dismiss"
|
||||
>
|
||||
<svg width="11" height="11" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
||||
<path d="M2 2L10 10M10 2L2 10" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.notes {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 10px 20px 0;
|
||||
}
|
||||
|
||||
.note {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 10px 12px 10px 14px;
|
||||
border-radius: var(--radius-md);
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
border: 1px solid var(--line);
|
||||
background: #fbf7ec;
|
||||
color: var(--ink);
|
||||
position: relative;
|
||||
animation: rise-in 0.22s ease-out;
|
||||
}
|
||||
|
||||
/* Vertical accent bar on the left edge */
|
||||
.note::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 10px;
|
||||
bottom: 10px;
|
||||
width: 3px;
|
||||
border-radius: 2px;
|
||||
background: var(--forest);
|
||||
}
|
||||
|
||||
.note-info::before { background: var(--forest); }
|
||||
.note-warn::before { background: var(--attention); }
|
||||
.note-critical::before { background: var(--urgent); }
|
||||
|
||||
.note-info { color: var(--ink); }
|
||||
.note-warn { color: var(--ink); background: #fbf3e7; border-color: #e9d7b9; }
|
||||
.note-critical { color: var(--ink); background: #fbefec; border-color: #e9c7c1; }
|
||||
|
||||
.note-mark {
|
||||
font-size: 14px;
|
||||
line-height: 1.3;
|
||||
flex-shrink: 0;
|
||||
font-family: var(--font-serif);
|
||||
}
|
||||
.note-info .note-mark { color: var(--forest); }
|
||||
.note-warn .note-mark { color: var(--attention); }
|
||||
.note-critical .note-mark { color: var(--urgent); }
|
||||
|
||||
.note-body {
|
||||
flex: 1;
|
||||
font-family: var(--font-sans);
|
||||
}
|
||||
|
||||
.note-close {
|
||||
flex-shrink: 0;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
color: var(--ink-muted);
|
||||
transition: background 0.15s, color 0.15s;
|
||||
}
|
||||
.note-close:hover { background: var(--paper-3); color: var(--ink); }
|
||||
</style>
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { cultivar } from '../store.svelte';
|
||||
|
||||
interface Props {
|
||||
onOpenReference?: () => void;
|
||||
}
|
||||
const { onOpenReference }: Props = $props();
|
||||
|
||||
// Format a friendly greeting based on local time of day and weekday
|
||||
const now = new Date();
|
||||
const hour = now.getHours();
|
||||
@@ -26,7 +31,8 @@
|
||||
const nightGreetings = [
|
||||
'Good evening',
|
||||
'Late night',
|
||||
'Still up?', ];
|
||||
'Still up?',
|
||||
];
|
||||
|
||||
// Weekend-specific greetings
|
||||
const weekendGreetings = [
|
||||
@@ -100,6 +106,17 @@
|
||||
|
||||
<!-- Right: live status + menu -->
|
||||
<div class="actions">
|
||||
{#if onOpenReference}
|
||||
<button class="nav-link" onclick={onOpenReference} type="button" aria-label="Open field guide">
|
||||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
||||
<path d="M2.5 2.5 L2.5 11.5 L7 11.5 L11.5 11.5 L11.5 2.5 L7 2.5 Z"
|
||||
stroke="currentColor" stroke-width="1" stroke-linejoin="round" fill="none"/>
|
||||
<path d="M7 2.5 L7 11.5" stroke="currentColor" stroke-width="1"/>
|
||||
</svg>
|
||||
<span class="nav-label">Field Guide</span>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<span class="live" aria-label="Connected">
|
||||
<span class="dot"></span>
|
||||
<span class="live-label">Live</span>
|
||||
@@ -192,6 +209,25 @@
|
||||
animation: dot-live 2.6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 5px 11px 5px 9px;
|
||||
border-radius: 999px;
|
||||
color: var(--ink-2);
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.01em;
|
||||
border: 1px solid var(--line);
|
||||
background: transparent;
|
||||
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
}
|
||||
.nav-link:hover {
|
||||
color: var(--forest);
|
||||
border-color: color-mix(in srgb, var(--forest) 35%, var(--line));
|
||||
background: var(--forest-tint);
|
||||
}
|
||||
|
||||
.menu-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -230,5 +266,7 @@
|
||||
.meta-sep { display: none; }
|
||||
.live-label { display: none; }
|
||||
.live { padding: 4px 8px; }
|
||||
.nav-label { display: none; }
|
||||
.nav-link { padding: 5px 8px; }
|
||||
}
|
||||
</style>
|
||||
@@ -1,74 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user