--- import mapsVector from '@data/maps-vector.json'; import CaptureScript from '../CaptureScript.astro'; interface MapData { title?: string; map: string; color?: string; filled?: boolean; zoom?: boolean; values?: Record; markers?: { name: string; coords: string }[]; lines?: { from: string; to: string }[]; } interface Props { mapId: string; color?: string; ratio?: string; } const { mapId, color: colorProp, ratio = '4x3' } = Astro.props; const data = (mapsVector as Record)[mapId]; const color = colorProp ?? data?.color ?? 'primary'; // scale1..scale10 — a 10-step color-mix ramp against var(--tblr-primary). const scale = Object.fromEntries( Array.from({ length: 10 }, (_, n) => [ `scale${n + 1}`, `color-mix(in srgb, transparent, var(--tblr-primary) ${(n + 1) * 10}%)`, ]), ); const markers = data?.markers?.map((marker) => ({ coords: marker.coords.split(',').map((n) => Number(n.trim())), name: marker.name, })); const mapKey = `map-${mapId}`; const mapSelector = `#map-${mapId}`; const mapLabel = data?.title ?? 'Map'; // jsVectorMap renders its own zoom +/- buttons inside this container when // zoom is enabled. `role="img"` flattens all descendants for assistive // tech, which would swallow those buttons — so only apply it when there's // no interactive chrome to hide. const hasZoomControls = Boolean(data?.zoom); const mapOptions = data ? { backgroundColor: 'transparent', regionStyle: { initial: { fill: 'var(--tblr-bg-surface-secondary)', stroke: data.filled ? '#fff' : 'var(--tblr-border-color)', strokeWidth: data.filled ? 1 : 2, }, }, zoomOnScroll: Boolean(data.zoom), zoomButtons: Boolean(data.zoom), ...(data.values ? { series: { regions: [{ attribute: 'fill', scale, values: data.values }] } } : {}), ...(markers ? { markers, markerStyle: { initial: { r: 4, stroke: '#fff', opacity: 1, strokeWidth: 3, strokeOpacity: 0.5, fill: `var(--tblr-${color})`, }, hover: { fill: `var(--tblr-${color})`, stroke: `var(--tblr-${color})` }, }, markerLabelStyle: { initial: { fontSize: 10 } }, } : {}), ...(data.lines ? { lines: data.lines, lineStyle: { strokeDasharray: '4 4', animation: true, stroke: 'rgba(98, 105, 118, .75)', strokeWidth: 0.5, }, } : {}), } : undefined; --- { data && (
) }