From cf617592d4ed2b8abbd06244b65ed42ca5caab79 Mon Sep 17 00:00:00 2001 From: "DESKTOP-PUHFO60\\dsx2016" Date: Fri, 23 Oct 2026 18:45:24 +0800 Subject: [PATCH] Size HTML firmware previews by board (480x320 for 3.5). EOF Co-authored-by: Cursor --- components/firmware-card.tsx | 8 +++++++- components/firmware-detail.tsx | 8 +++++++- components/firmware-preview.tsx | 13 ++++++------- lib/boards.ts | 6 ++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/components/firmware-card.tsx b/components/firmware-card.tsx index 2e70b0e..360f029 100644 --- a/components/firmware-card.tsx +++ b/components/firmware-card.tsx @@ -31,7 +31,13 @@ export function FirmwareCard({ : "border-[var(--line)] bg-[rgba(0,0,0,0.22)] hover:-translate-y-0.5 hover:border-[rgba(240,197,10,0.35)] hover:bg-[rgba(240,197,10,0.04)]" )} > -
+
{hasPreview && ( diff --git a/components/firmware-detail.tsx b/components/firmware-detail.tsx index 374cec6..8a3090c 100644 --- a/components/firmware-detail.tsx +++ b/components/firmware-detail.tsx @@ -36,7 +36,13 @@ export function FirmwareDetail({
-
+
{fw.media.preview ? ( ) : fw.media.video ? ( diff --git a/components/firmware-preview.tsx b/components/firmware-preview.tsx index 4ac2774..caba06f 100644 --- a/components/firmware-preview.tsx +++ b/components/firmware-preview.tsx @@ -3,12 +3,10 @@ import { useEffect, useRef, useState } from "react"; import { useTranslations } from "next-intl"; import type { FirmwareInfo } from "@/lib/firmware"; +import { boardPreviewSize } from "@/lib/boards"; import { sensorMediaForProject } from "@/lib/sensor-media"; import { cn } from "@/lib/utils"; -const SCREEN_W = 320; -const SCREEN_H = 240; - type Tab = "ui" | "sensor"; /** On-device HTML UI mock + optional hardware still, switchable via tabs. */ @@ -24,6 +22,7 @@ export function FirmwarePreview({ const t = useTranslations("firmware"); const hostRef = useRef(null); const [scale, setScale] = useState(1); + const { w: screenW, h: screenH } = boardPreviewSize(fw.boardId); const sensor = sensorMediaForProject(fw.project); const hasUi = Boolean(fw.media.preview); const [tab, setTab] = useState(hasUi ? "ui" : "sensor"); @@ -39,14 +38,14 @@ export function FirmwarePreview({ const update = () => { const { width, height } = el.getBoundingClientRect(); if (width <= 0 || height <= 0) return; - setScale(Math.min(width / SCREEN_W, height / SCREEN_H)); + setScale(Math.min(width / screenW, height / screenH)); }; update(); const ro = new ResizeObserver(update); ro.observe(el); return () => ro.disconnect(); - }, [fw.media.preview, tab]); + }, [fw.media.preview, tab, screenW, screenH]); const showTabs = hasUi && Boolean(sensor); @@ -113,8 +112,8 @@ export function FirmwarePreview({