diff --git a/src/components/awards/ribbonDesign/RibbonArt.tsx b/src/components/awards/ribbonDesign/RibbonArt.tsx index 1cb45ecf..abe0ebc9 100644 --- a/src/components/awards/ribbonDesign/RibbonArt.tsx +++ b/src/components/awards/ribbonDesign/RibbonArt.tsx @@ -13,6 +13,9 @@ * ribbons keep the device set authored in the designer. * - `computeDeviceSlots(...)` lays the devices out as one centered cluster on * the ribbon face, evenly spaced and shrunk to fit narrow ribbons. + * + * Stripes run either direction (`stripeOrientation`) and optional horizontal + * accent lines (`lines`) draw over the bands but under the overlay and devices. */ import type { ReactNode } from "react"; import { RIBBON_CONSTANTS, DEFAULT_RIBBON } from "./constants"; @@ -165,6 +168,50 @@ export function DeviceGlyph({ ); } +// ─── Accent lines ─────────────────────────────────────────────────── + +export interface LineRect { + x: number; + y: number; + width: number; + height: number; + color: string; +} + +/** + * Convert authored accent lines (percentages of ribbon height, `positionY` + * at the line's center) into full-width SVG rects, clamped to the canvas. + * Malformed entries are skipped so stored junk can never crash the renderer. + */ +export function computeLineRects( + lines: RibbonDesign["lines"], + width: number, + height: number, +): LineRect[] { + if (!Array.isArray(lines)) return []; + const rects: LineRect[] = []; + for (const line of lines) { + if (!line || typeof line !== "object") continue; + const { positionY, thickness, color } = line; + if ( + typeof positionY !== "number" || + !Number.isFinite(positionY) || + typeof thickness !== "number" || + !Number.isFinite(thickness) || + thickness <= 0 || + typeof color !== "string" + ) { + continue; + } + const clampPct = (v: number) => Math.max(0, Math.min(1, v / 100)); + const top = clampPct(positionY - thickness / 2) * height; + const bottom = clampPct(positionY + thickness / 2) * height; + if (bottom <= top) continue; + rects.push({ x: 0, y: top, width, height: bottom - top, color }); + } + return rects; +} + // ─── Shared renderer ──────────────────────────────────────────────── export interface RibbonArtProps { @@ -179,9 +226,9 @@ export interface RibbonArtProps { } /** - * Render a ribbon (stripes + overlay + vector devices) at the canonical - * `RIBBON_WIDTH x PREVIEW_HEIGHT` viewBox, scaled responsively by CSS. The - * devices shown come from `resolveDisplayedDeviceTypes(design, tier)` and are + * Render a ribbon (stripes + accent lines + overlay + vector devices) at the + * canonical `RIBBON_WIDTH x PREVIEW_HEIGHT` viewBox, scaled responsively by CSS. + * The devices shown come from `resolveDisplayedDeviceTypes(design, tier)` and are * auto-laid-out by `computeDeviceSlots`, so this component owns all layout. */ export function RibbonArt({ @@ -195,7 +242,11 @@ export function RibbonArt({ design && typeof design === "object" && Array.isArray(design.stripes) ? design : DEFAULT_RIBBON; const { stripes, mirrored } = resolved; if (stripes.length === 0) return null; + const orientation = resolved.stripeOrientation === "horizontal" ? "horizontal" : "vertical"; + // Mirroring reflects the band sequence. For vertical bands that is a + // left-right mirror; for horizontal bands it stacks symmetrically + // top-to-bottom, keeping the pattern balanced in either orientation. const displayStripes = mirrored ? [...stripes, ...stripes.slice(0, -1).reverse()] : stripes; const totalWeight = displayStripes.reduce((sum, s) => sum + s.width, 0); const viewWidth = RIBBON_CONSTANTS.RIBBON_WIDTH; @@ -203,12 +254,19 @@ export function RibbonArt({ const deviceTypes = resolveDisplayedDeviceTypes(resolved, tier); const slots = computeDeviceSlots(deviceTypes.length, viewWidth, viewHeight); + const lineRects = computeLineRects(resolved.lines, viewWidth, viewHeight); - let stripeX = 0; + let stripeOffset = 0; const stripeRects = displayStripes.map((stripe, i) => { - const w = (stripe.width / totalWeight) * viewWidth; - const el = ; - stripeX += w; + const span = + (stripe.width / totalWeight) * (orientation === "horizontal" ? viewHeight : viewWidth); + const el = + orientation === "horizontal" ? ( + + ) : ( + + ); + stripeOffset += span; return el; }); @@ -220,6 +278,17 @@ export function RibbonArt({ > {stripeRects} + {lineRects.map((rect, i) => ( + + ))} {showOverlay && ( )} diff --git a/src/components/awards/ribbonDesign/constants.ts b/src/components/awards/ribbonDesign/constants.ts index c4785286..257d9ae5 100644 --- a/src/components/awards/ribbonDesign/constants.ts +++ b/src/components/awards/ribbonDesign/constants.ts @@ -12,6 +12,7 @@ export const DEFAULT_RIBBON: RibbonDesign = { ], devices: [], mirrored: false, + lines: [], }; export const MILITARY_COLORS: { name: string; hex: string }[] = [ diff --git a/src/components/awards/ribbonDesign/types.ts b/src/components/awards/ribbonDesign/types.ts index f1d03ef2..4f01660e 100644 --- a/src/components/awards/ribbonDesign/types.ts +++ b/src/components/awards/ribbonDesign/types.ts @@ -14,8 +14,29 @@ export type Stripe = { width: number; }; +/** Direction the stripe bands run across the ribbon face. */ +export type StripeOrientation = "vertical" | "horizontal"; + +/** + * A horizontal accent line drawn across the stripe pattern, independent of + * stripe orientation. `positionY` marks the line's center as a percentage of + * ribbon height (0 = top edge, 100 = bottom edge) and `thickness` is also a + * percentage of ribbon height, so hairline pinstripes and bold bars share + * one representation. + */ +export type RibbonLine = { + id: string; + color: string; + positionY: number; + thickness: number; +}; + export type RibbonDesign = { stripes: Stripe[]; devices: Device[]; mirrored: boolean; + /** Band layout direction. Legacy designs without this key render vertical. */ + stripeOrientation?: StripeOrientation; + /** Accent lines over the stripes, under the overlay and devices. Absent means none. */ + lines?: RibbonLine[]; };