Run npm format

This commit is contained in:
2026-02-05 20:01:54 +00:00
parent 221159433c
commit 4220cdfa5e
18 changed files with 751 additions and 723 deletions

View File

@@ -1,116 +1,116 @@
<script lang="ts">
import RouteRow from '$lib/components/RouteRow.svelte';
import RouteRow from '$lib/components/RouteRow.svelte';
const dummyFeatures = [
{
type: 'station',
miles: 0,
chains: 0,
name: 'Testington',
description: 'Terminus',
terminus: true,
elec: '25kvac',
},
{
type: 'station',
miles: 0,
chains: 76,
name: 'Closeby',
description: 'Temporarily closed',
elec: '25kvac',
},
{
type: 'junction',
name: 'Test Junction',
diverges: 'right',
direction: 'down',
elec: '25kvac',
elecBranch: 'none',
miles: 1,
chains: 13,
},
{
type: 'bridge',
position: 'over',
category: 'pipeline',
name: 'Waterway Bridge',
roadName: "TfL (LU)",
elec: '25kvac',
miles: 1,
chains: 41,
},
{
type: 'crossover',
name: 'Dolphin junction',
elec: '25kvac',
miles: 1,
chains: 42,
},
{
type: 'junction',
name: 'Test Junction South',
description: "To: Banbury West Junction & Birmingham",
diverges: 'left',
direction: 'down',
elec: '25kvac',
elecBranch: '650vdc',
miles: 1,
chains: 42,
},
{
type: 'electrificationChange',
from: {
elec: '25kvac',
eco: 'Didcot',
},
to: {
elec: 'none',
},
},
{
type: 'crossing',
kind: 'ahb',
elec: '25kvac',
name: 'Swindon Lane',
description: 'Controlled by TVSC (Level Crossing WS)'
},
{
type: 'loop',
side: 'both',
elec: '25kvac',
elecLoop: 'none',
},
{
type: 'signallerChange',
from: 'TVSC - Didcot WS (SB)',
to: 'TVSC - Swindon WS (SN)',
elec: '25kvac',
},
{
type: 'station',
miles: 4,
chains: 13,
name: 'Powerless',
description: "Doesn't exist",
elec: '750vdc',
}
]
const dummyFeatures = [
{
type: 'station',
miles: 0,
chains: 0,
name: 'Testington',
description: 'Terminus',
terminus: true,
elec: '25kvac'
},
{
type: 'station',
miles: 0,
chains: 76,
name: 'Closeby',
description: 'Temporarily closed',
elec: '25kvac'
},
{
type: 'junction',
name: 'Test Junction',
diverges: 'right',
direction: 'down',
elec: '25kvac',
elecBranch: 'none',
miles: 1,
chains: 13
},
{
type: 'bridge',
position: 'over',
category: 'pipeline',
name: 'Waterway Bridge',
roadName: 'TfL (LU)',
elec: '25kvac',
miles: 1,
chains: 41
},
{
type: 'crossover',
name: 'Dolphin junction',
elec: '25kvac',
miles: 1,
chains: 42
},
{
type: 'junction',
name: 'Test Junction South',
description: 'To: Banbury West Junction & Birmingham',
diverges: 'left',
direction: 'down',
elec: '25kvac',
elecBranch: '650vdc',
miles: 1,
chains: 42
},
{
type: 'electrificationChange',
from: {
elec: '25kvac',
eco: 'Didcot'
},
to: {
elec: 'none'
}
},
{
type: 'crossing',
kind: 'ahb',
elec: '25kvac',
name: 'Swindon Lane',
description: 'Controlled by TVSC (Level Crossing WS)'
},
{
type: 'loop',
side: 'both',
elec: '25kvac',
elecLoop: 'none'
},
{
type: 'signallerChange',
from: 'TVSC - Didcot WS (SB)',
to: 'TVSC - Swindon WS (SN)',
elec: '25kvac'
},
{
type: 'station',
miles: 4,
chains: 13,
name: 'Powerless',
description: "Doesn't exist",
elec: '750vdc'
}
];
</script>
<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p>
<div class="map-container">
{#each dummyFeatures as feature}
<RouteRow {feature} activeElec={feature.elec} />
{/each}
{#each dummyFeatures as feature}
<RouteRow {feature} activeElec={feature.elec} />
{/each}
</div>
<style>
.map-container {
width: 100%;
max-width: 600px;
margin: 0 auto;
font-family: sans-serif;
}
</style>
.map-container {
width: 100%;
max-width: 600px;
margin: 0 auto;
font-family: sans-serif;
}
</style>

View File

@@ -1,238 +1,240 @@
<script lang="ts">
import RouteRow from '$lib/components/RouteRow.svelte';
import { slide } from 'svelte/transition';
// data.route contains: routeName, routeId, elecStart, elecEnd, routeDetail[]
export let data;
import RouteRow from '$lib/components/RouteRow.svelte';
import { slide } from 'svelte/transition';
let reversed = false; // Reverses Array, and passes value down to children
// data.route contains: routeName, routeId, elecStart, elecEnd, routeDetail[]
export let data;
let visibleTypes = {
station: true,
bridge: true,
crossovers: true,
loop: true,
signallerChange: true,
electrificationChange: true,
siteof: true,
junction: true,
}
let reversed = false; // Reverses Array, and passes value down to children
let showFilters = false;
let visibleTypes = {
station: true,
bridge: true,
crossovers: true,
loop: true,
signallerChange: true,
electrificationChange: true,
siteof: true,
junction: true
};
// Toggle feature types
const toggleFilter = (type: string) => {
visibleTypes[type] = !visibleTypes[type];
visibleTypes = visibleTypes;
};
let showFilters = false;
// Helper to prettify 'types'
const formatLabel = (str: string) => str.replace(/([A-Z])/g, ' $1').replace(/^./, (s) => s.toUpperCase());
// Toggle feature types
const toggleFilter = (type: string) => {
visibleTypes[type] = !visibleTypes[type];
visibleTypes = visibleTypes;
};
$: processedFeatures = (() => {
const list = reversed
? [...data.route.routeDetail].reverse()
: [...data.route.routeDetail];
// Helper to prettify 'types'
const formatLabel = (str: string) =>
str.replace(/([A-Z])/g, ' $1').replace(/^./, (s) => s.toUpperCase());
// Seed currentElec from the YAML header boundary
let currentElec = reversed
? data.route.elecEnd.elec
: data.route.elecStart.elec;
$: processedFeatures = (() => {
const list = reversed ? [...data.route.routeDetail].reverse() : [...data.route.routeDetail];
return list.map(f => {
if (f.type === 'electrificationChange') {
// Transition state: this tile and everything after it
// adopts the new electrification.
currentElec = reversed ? f.from.elec : f.to.elec;
}
return {
...f,
activeElec: currentElec
};
});
})();
// Seed currentElec from the YAML header boundary
let currentElec = reversed ? data.route.elecEnd.elec : data.route.elecStart.elec;
$: filteredFeatures = processedFeatures.filter(f => {
return visibleTypes[f.type] ?? true;
})
return list.map((f) => {
if (f.type === 'electrificationChange') {
// Transition state: this tile and everything after it
// adopts the new electrification.
currentElec = reversed ? f.from.elec : f.to.elec;
}
return {
...f,
activeElec: currentElec
};
});
})();
$: filteredFeatures = processedFeatures.filter((f) => {
return visibleTypes[f.type] ?? true;
});
</script>
<div class="map-layout">
<header class="top-nav">
<h1>{data.route.routeName}</h1>
<span class="route-code">{data.route.routeId}</span>
<div class="quick-actions">
<button class="icon-btn" on:click={() => reversed = !reversed}>
{reversed ? 'UP' : 'DN'}
</button>
<button class="icon-btn" on:click={() => showFilters = !showFilters}>
Settings
</button>
</div>
</header>
<header class="top-nav">
<h1>{data.route.routeName}</h1>
<span class="route-code">{data.route.routeId}</span>
<div class="quick-actions">
<button class="icon-btn" on:click={() => (reversed = !reversed)}>
{reversed ? 'UP' : 'DN'}
</button>
<button class="icon-btn" on:click={() => (showFilters = !showFilters)}> Settings </button>
</div>
</header>
{#if showFilters}
<div class="backdrop" on:click={() => showFilters = false}></div>
{#if showFilters}
<div class="backdrop" on:click={() => (showFilters = false)}></div>
<div class="filter-drawer" transition:slide>
<div class="drawer-header">
<h3>Visibility Filters</h3>
<button class="close-icon" on:click={() => showFilters = false} aria-label="Close">
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.5">
<path d="M18 6L6 18M6 6l12 12" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
<div class="filter-drawer" transition:slide>
<div class="drawer-header">
<h3>Visibility Filters</h3>
<button class="close-icon" on:click={() => (showFilters = false)} aria-label="Close">
<svg
viewBox="0 0 24 24"
width="20"
height="20"
fill="none"
stroke="currentColor"
stroke-width="2.5"
>
<path d="M18 6L6 18M6 6l12 12" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</button>
</div>
<div class="drawer-content">
<div class="filter-flex">
{#each Object.keys(visibleTypes) as type}
<button
class="filter-chip"
class:active={visibleTypes[type]}
on:click={() => toggleFilter(type)}
>
{formatLabel(type)}
</button>
{/each}
</div>
</div>
</div>
{/if}
<div class="drawer-content">
<div class="filter-flex">
{#each Object.keys(visibleTypes) as type}
<button
class="filter-chip"
class:active={visibleTypes[type]}
on:click={() => toggleFilter(type)}
>
{formatLabel(type)}
</button>
{/each}
</div>
</div>
</div>
{/if}
<main class="map-spine">
<div class="container">
{#each filteredFeatures as f, i (`${f.type}-${f.miles}-${f.chains}-${i}`)}
<RouteRow feature={f} activeElec={f.activeElec} {reversed} />
{/each}
</div>
</main>
<main class="map-spine">
<div class="container">
{#each filteredFeatures as f, i (`${f.type}-${f.miles}-${f.chains}-${i}`)}
<RouteRow feature={f} activeElec={f.activeElec} {reversed} />
{/each}
</div>
</main>
</div>
<style>
.map-layout {
display: flex;
flex-direction: column;
background: #ffffff;
min-height: 100vh;
}
.map-layout {
display: flex;
flex-direction: column;
background: #ffffff;
min-height: 100vh;
}
.top-nav {
position: sticky;
top: 0;
z-index: 100;
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-bottom: 1px solid #e2e8f0;
padding: 0.75rem 1rem;
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.top-nav {
position: sticky;
top: 0;
z-index: 100;
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-bottom: 1px solid #e2e8f0;
padding: 0.75rem 1rem;
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
h1 {
flex: 1;
min-width: 0;
margin: 0;
font-size: 1.1rem;
font-weight: 800;
line-height: 1.2;
color: #0f172a;
letter-spacing: -0.02em;
white-space: normal;
overflow-wrap: break-word;
}
h1 {
flex: 1;
min-width: 0;
margin: 0;
font-size: 1.1rem;
font-weight: 800;
line-height: 1.2;
color: #0f172a;
letter-spacing: -0.02em;
white-space: normal;
overflow-wrap: break-word;
}
@media (min-width: 768px) {
.top-nav {
padding: 1rem 2rem;
}
@media (min-width: 768px) {
.top-nav {
padding: 1rem 2rem;
}
h1 {
font-size: 1.5rem;
letter-spacing: -0.03em;
}
}
h1 {
font-size: 1.5rem;
letter-spacing: -0.03em;
}
}
.container {
width: 100%;
max-width: 500px;
margin: 0 auto;
padding-top: 1rem;
}
.container {
width: 100%;
max-width: 500px;
margin: 0 auto;
padding-top: 1rem;
}
.backdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.4);
z-index: 150;
}
.backdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.4);
z-index: 150;
}
.filter-drawer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: white;
z-index: 200;
border-radius: 20px 20px 0 0;
box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.15);
/* Ensure it handles iOS home bar spacing */
padding-bottom: env(safe-area-inset-bottom, 1rem);
}
.filter-drawer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: white;
z-index: 200;
border-radius: 20px 20px 0 0;
box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.15);
/* Ensure it handles iOS home bar spacing */
padding-bottom: env(safe-area-inset-bottom, 1rem);
}
.drawer-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1.25rem 1.5rem 0.75rem;
border-bottom: 1px solid #f1f5f9;
}
.drawer-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1.25rem 1.5rem 0.75rem;
border-bottom: 1px solid #f1f5f9;
}
.drawer-header h3 {
margin: 0;
font-size: 1rem;
color: #1e293b;
}
.drawer-header h3 {
margin: 0;
font-size: 1rem;
color: #1e293b;
}
.close-icon {
background: #f1f5f9;
border: none;
border-radius: 50%;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: #64748b;
}
.close-icon {
background: #f1f5f9;
border: none;
border-radius: 50%;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: #64748b;
}
.drawer-content {
padding: 1.25rem 1.5rem;
}
.drawer-content {
padding: 1.25rem 1.5rem;
}
.filter-flex {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
}
.filter-flex {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
}
.filter-chip {
padding: 0.5rem 1rem;
border-radius: 999px;
border: 1px solid #e2e8f0;
background: #f8fafc;
font-size: 0.875rem;
cursor: pointer;
transition: all 0.2s;
}
.filter-chip {
padding: 0.5rem 1rem;
border-radius: 999px;
border: 1px solid #e2e8f0;
background: #f8fafc;
font-size: 0.875rem;
cursor: pointer;
transition: all 0.2s;
}
.filter-chip.active {
background: #1e293b;
color: white;
border-color: #1e293b;
}
</style>
.filter-chip.active {
background: #1e293b;
color: white;
border-color: #1e293b;
}
</style>

View File

@@ -2,28 +2,28 @@ import type { PageLoad } from '/$types';
import { error } from '@sveltejs/kit';
export const load: PageLoad = async ({ params, fetch }) => {
const { slug } = params;
const { slug } = params;
try {
const res = await fetch(`/mapFiles/json/${slug}.json`);
try {
const res = await fetch(`/mapFiles/json/${slug}.json`);
if (!res.ok) {
throw error(404, {
message: `Route ${slug} not found`
});
}
if (!res.ok) {
throw error(404, {
message: `Route ${slug} not found`
});
}
const rawData = await res.json();
const rawData = await res.json();
return {
route: rawData,
slug: slug,
};
} catch (err) {
console.error(`Error loading map ${slug}: `, err);
return {
route: rawData,
slug: slug
};
} catch (err) {
console.error(`Error loading map ${slug}: `, err);
throw error(500, {
message: `Failed to parse map data for ${slug}`
});
}
};
throw error(500, {
message: `Failed to parse map data for ${slug}`
});
}
};