Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | /** * Safe Zone Debug Overlay * * Shows debug visualization for the safe zone fitting system: * - Green dashed rectangle: "leftover" area (viewport minus margins) * - Red/orange rectangle: crop region mapped to pixels * - Info panel with dimensions and viewBox info * * Only rendered when visual debug mode is enabled and fillContainer is true. */ 'use client' import { parseViewBox } from '../../maps' import type { MapData } from '../../types' import type { SafeZoneMargins } from '../../maps' // ============================================================================ // Types // ============================================================================ export interface SafeZoneDebugOverlayProps { /** Current SVG dimensions */ svgDimensions: { width: number; height: number } /** Safe zone margins */ safeZoneMargins: SafeZoneMargins /** Display viewBox string */ displayViewBox: string /** Current map data */ mapData: MapData } // ============================================================================ // Component // ============================================================================ /** * Debug overlay showing safe zone rectangles. */ export function SafeZoneDebugOverlay({ svgDimensions, safeZoneMargins, displayViewBox, mapData, }: SafeZoneDebugOverlayProps) { // Calculate the leftover rectangle (viewport minus margins) const leftoverRect = { left: safeZoneMargins.left, top: safeZoneMargins.top, width: svgDimensions.width - safeZoneMargins.left - safeZoneMargins.right, height: svgDimensions.height - safeZoneMargins.top - safeZoneMargins.bottom, } // Calculate where the crop region appears in viewport pixels // Using the display viewBox to map SVG coords to pixels const viewBox = parseViewBox(displayViewBox) // Use custom crop if defined, otherwise use the full original map bounds (same as displayViewBox logic) const originalBounds = parseViewBox(mapData.originalViewBox) const cropRegion = mapData.customCrop ? parseViewBox(mapData.customCrop) : originalBounds const isCustomCrop = !!mapData.customCrop // With preserveAspectRatio="xMidYMid meet", the SVG is letterboxed // Calculate the actual scale and offset const scaleX = svgDimensions.width / viewBox.width const scaleY = svgDimensions.height / viewBox.height const actualScale = Math.min(scaleX, scaleY) // "meet" uses the smaller scale // Calculate letterbox offsets (the SVG content is centered) const renderedWidth = viewBox.width * actualScale const renderedHeight = viewBox.height * actualScale const offsetX = (svgDimensions.width - renderedWidth) / 2 const offsetY = (svgDimensions.height - renderedHeight) / 2 // SVG point (x, y) -> pixel, accounting for letterboxing const svgToPixelX = (x: number) => offsetX + (x - viewBox.x) * actualScale const svgToPixelY = (y: number) => offsetY + (y - viewBox.y) * actualScale const cropPixelRect = { left: svgToPixelX(cropRegion.x), top: svgToPixelY(cropRegion.y), width: cropRegion.width * actualScale, height: cropRegion.height * actualScale, } return ( <> {/* Leftover rectangle (safe zone where crop should fit) - GREEN */} <div data-element="debug-leftover-rect" style={{ position: 'absolute', left: leftoverRect.left, top: leftoverRect.top, width: leftoverRect.width, height: leftoverRect.height, border: '3px dashed rgba(0, 255, 0, 0.8)', backgroundColor: 'rgba(0, 255, 0, 0.05)', pointerEvents: 'none', zIndex: 9999, }} > <span style={{ position: 'absolute', top: 4, left: 4, background: 'rgba(0, 255, 0, 0.9)', color: 'black', padding: '2px 6px', fontSize: '11px', fontWeight: 'bold', borderRadius: '3px', }} > LEFTOVER ({Math.round(leftoverRect.width)}×{Math.round(leftoverRect.height)}) </span> </div> {/* Crop region mapped to pixels - RED for custom, ORANGE for full map */} <div data-element="debug-crop-rect" style={{ position: 'absolute', left: cropPixelRect.left, top: cropPixelRect.top, width: cropPixelRect.width, height: cropPixelRect.height, border: `3px ${isCustomCrop ? 'solid' : 'dashed'} ${isCustomCrop ? 'rgba(255, 0, 0, 0.8)' : 'rgba(255, 165, 0, 0.8)'}`, backgroundColor: isCustomCrop ? 'rgba(255, 0, 0, 0.05)' : 'rgba(255, 165, 0, 0.05)', pointerEvents: 'none', zIndex: 9998, }} > <span style={{ position: 'absolute', bottom: 4, right: 4, background: isCustomCrop ? 'rgba(255, 0, 0, 0.9)' : 'rgba(255, 165, 0, 0.9)', color: isCustomCrop ? 'white' : 'black', padding: '2px 6px', fontSize: '11px', fontWeight: 'bold', borderRadius: '3px', }} > {isCustomCrop ? 'CROP' : 'FULL MAP'} ({Math.round(cropPixelRect.width)}× {Math.round(cropPixelRect.height)}) </span> </div> {/* Info panel showing calculations */} <div data-element="debug-safe-zone-info" style={{ position: 'absolute', bottom: 10, left: 10, background: 'rgba(0, 0, 0, 0.85)', color: 'white', padding: '8px 12px', fontSize: '11px', fontFamily: 'monospace', borderRadius: '6px', pointerEvents: 'none', zIndex: 9999, lineHeight: 1.4, }} > <div> <strong>Safe Zone Debug</strong> </div> <div> Viewport: {Math.round(svgDimensions.width)}×{Math.round(svgDimensions.height)} </div> <div> Margins: T={safeZoneMargins.top} R={safeZoneMargins.right} B= {safeZoneMargins.bottom} L= {safeZoneMargins.left} </div> <div style={{ color: '#0f0' }}> Leftover: {Math.round(leftoverRect.width)}×{Math.round(leftoverRect.height)} </div> <div style={{ color: isCustomCrop ? '#f00' : '#ffa500' }}> {isCustomCrop ? 'Crop' : 'Full Map'} (px): {Math.round(cropPixelRect.width)}× {Math.round(cropPixelRect.height)} </div> <div>ViewBox: {displayViewBox}</div> </div> </> ) } |