From a723e56b4ce392d2b11d28f2745279aa825a2ee1 Mon Sep 17 00:00:00 2001 From: memdmp Date: Mon, 21 Jul 2025 22:53:11 +0200 Subject: feat: initial commit --- src/app.css | 24 + src/app.d.ts | 13 + src/app.html | 13 + src/hooks.server.ts | 12 + src/hooks.ts | 3 + src/lib/Page.svelte | 32 ++ src/lib/Timetable.svelte | 424 +++++++++++++++++ src/lib/Titlebar.svelte | 55 +++ src/lib/aliases.ts | 36 ++ src/lib/assets/LineGlyph.svelte | 193 ++++++++ src/lib/assets/LineGlyphSrc.svg | 233 +++++++++ src/lib/assets/Pictogram.svelte | 11 + src/lib/index.ts | 51 ++ src/lib/motis-api.ts | 57 +++ src/lib/motis-types.ts | 496 +++++++++++++++++++ src/routes/(app)/+layout.svelte | 10 + src/routes/(app)/+server.ts | 5 + src/routes/(app)/fahrplan/+page.svelte | 524 +++++++++++++++++++++ src/routes/+layout.svelte | 7 + src/routes/_lang/+page.svelte | 17 + src/routes/train-ico/[type]/[[line]]/+page.svelte | 13 + src/routes/train-ico/[type]/[[line]]/+page.ts | 1 + .../train-ico/[type]/[[line]]/.svg/+server.ts | 23 + 23 files changed, 2253 insertions(+) create mode 100644 src/app.css create mode 100644 src/app.d.ts create mode 100644 src/app.html create mode 100644 src/hooks.server.ts create mode 100644 src/hooks.ts create mode 100644 src/lib/Page.svelte create mode 100644 src/lib/Timetable.svelte create mode 100644 src/lib/Titlebar.svelte create mode 100644 src/lib/aliases.ts create mode 100644 src/lib/assets/LineGlyph.svelte create mode 100644 src/lib/assets/LineGlyphSrc.svg create mode 100644 src/lib/assets/Pictogram.svelte create mode 100644 src/lib/index.ts create mode 100644 src/lib/motis-api.ts create mode 100644 src/lib/motis-types.ts create mode 100644 src/routes/(app)/+layout.svelte create mode 100644 src/routes/(app)/+server.ts create mode 100644 src/routes/(app)/fahrplan/+page.svelte create mode 100644 src/routes/+layout.svelte create mode 100644 src/routes/_lang/+page.svelte create mode 100644 src/routes/train-ico/[type]/[[line]]/+page.svelte create mode 100644 src/routes/train-ico/[type]/[[line]]/+page.ts create mode 100644 src/routes/train-ico/[type]/[[line]]/.svg/+server.ts (limited to 'src') diff --git a/src/app.css b/src/app.css new file mode 100644 index 0000000..2d40759 --- /dev/null +++ b/src/app.css @@ -0,0 +1,24 @@ +@import 'tailwindcss'; + +@theme { + --font-sans: 'Adwaita Sans', Inter, system-ui, -apple-system, + BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, + 'Open Sans', 'Helvetica Neue', sans-serif; + --font-sbb-typo: SBB, 'Helvetica_Neue', Helvetica, Inter, var(--font-sans), + system-ui, sans-serif; +} + +@keyframes loadingbar { + 0% { + width: 0; + left: 0; + } + 50% { + width: 100%; + left: 0; + } + 100% { + width: 0; + left: 100%; + } +} diff --git a/src/app.d.ts b/src/app.d.ts new file mode 100644 index 0000000..da08e6d --- /dev/null +++ b/src/app.d.ts @@ -0,0 +1,13 @@ +// See https://svelte.dev/docs/kit/types#app.d.ts +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } +} + +export {}; diff --git a/src/app.html b/src/app.html new file mode 100644 index 0000000..48ea59c --- /dev/null +++ b/src/app.html @@ -0,0 +1,13 @@ + + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/src/hooks.server.ts b/src/hooks.server.ts new file mode 100644 index 0000000..5182210 --- /dev/null +++ b/src/hooks.server.ts @@ -0,0 +1,12 @@ +import type { Handle } from '@sveltejs/kit'; +import { paraglideMiddleware } from '$lib/paraglide/server'; + +const handleParaglide: Handle = ({ event, resolve }) => paraglideMiddleware(event.request, ({ request, locale }) => { + event.request = request; + + return resolve(event, { + transformPageChunk: ({ html }) => html.replace('%paraglide.lang%', locale) + }); +}); + +export const handle: Handle = handleParaglide; diff --git a/src/hooks.ts b/src/hooks.ts new file mode 100644 index 0000000..e75600b --- /dev/null +++ b/src/hooks.ts @@ -0,0 +1,3 @@ +import { deLocalizeUrl } from '$lib/paraglide/runtime'; + +export const reroute = (request) => deLocalizeUrl(request.url).pathname; diff --git a/src/lib/Page.svelte b/src/lib/Page.svelte new file mode 100644 index 0000000..92cd92a --- /dev/null +++ b/src/lib/Page.svelte @@ -0,0 +1,32 @@ + + + + {title} + + + +
+ {#if sidepanel} +
+ {@render sidepanel()} +
+ {/if} + {@render children()} +
diff --git a/src/lib/Timetable.svelte b/src/lib/Timetable.svelte new file mode 100644 index 0000000..4a17ca7 --- /dev/null +++ b/src/lib/Timetable.svelte @@ -0,0 +1,424 @@ + + +{#snippet renderLocalTime( + time: Date, + forceAbsolute = false +)}{#await localTime(time, forceAbsolute, now)}{isRelativeTime && !forceAbsolute + ? timeRelative(time.getTime(), now) + : time.getUTCHours() + + ':' + + time.getUTCMinutes() + + (time.getUTCSeconds() !== 0 ? `:${time.getUTCSeconds()}` : '') + + ' UTC'}{:then t}{t}{/await}{/snippet} + +{#if stopTimes} + {#each stopTimes.stopTimes + // garbage data + .filter((v) => v.agencyUrl !== 'http://www.rta.ae') as departure} + {@const expectedTime = + new Date( + (isArrivals + ? departure.place.scheduledArrival + : departure.place.scheduledDeparture) ?? '0' + ).getTime() / + 1000 / + 60} + {@const receivedTime = + new Date( + (isArrivals ? departure.place.arrival : departure.place.departure) ?? + '0' + ).getTime() / + 1000 / + 60} + {@const delayMinutes = receivedTime - expectedTime} + {@const avoidGlyph = departure.routeShortName.startsWith('FlixTrain')} + {@const routeShortName = (() => { + let n = departure.routeShortName; + if (n.startsWith('EC ')) n = n.replace('EC ', 'EC'); + if (departure.mode === 'TRAM' && !isNaN(parseInt(n))) n = 'T ' + n; + if (departure.mode === 'BUS' && !isNaN(parseInt(n))) n = 'B ' + n; + if ( + departure.routeShortName === 'European Sleeper' && + departure.agencyName === 'Eu Sleeper' + ) + n = 'EN'; // TODO: validate these are real euronights + if (n === '?') n = ''; + if (n.startsWith('FlixTrain ')) n = n.substring(10); + // Note: may also catch ECs/ICs/EXTs operated by DB + if ( + departure.agencyId === '12681' && + departure.agencyName === 'DB Fernverkehr AG' && + departure.mode === 'HIGHSPEED_RAIL' && + departure.source.startsWith('de_DELFI.gtfs.zip/') && + !isNaN(parseInt(n)) + ) + n = `ICE ${n}`; + return n; + })()} + {@const pictogram = (() => { + switch (true) { + case departure.mode === Mode.Bike: + return 'Velo_l'; + case departure.mode === Mode.ODM: + case departure.mode === Mode.Rental: + return 'Taxi_l'; + case departure.mode === Mode.Car: + case departure.mode === Mode.CarDropoff: + case departure.mode === Mode.CarParking: + return 'Auto_l'; + + // Transit // + case departure.mode === Mode.Airplane: + return 'Abflug_l'; + case departure.mode === Mode.LongDistanceRail: + case departure.mode === Mode.RegionalFastRail: + case departure.mode === Mode.RegionalRail: + case departure.mode === Mode.Metro: + case departure.mode === Mode.HighspeedRail: + return 'Zug_l'; + case departure.mode === Mode.NightRail: + return 'Schlafwagen'; + case departure.mode === Mode.Subway: + return 'Metro_l_' + (m.lang_short() === 'en' ? 'de' : m.lang_short()); + case departure.mode === Mode.Bus: + return 'Bus_l'; + case departure.mode === Mode.Coach: + return 'Fernbus_l'; + case departure.mode === Mode.Tram: + case departure.mode === Mode.CableTram: + return 'Tram_l'; + case departure.mode === Mode.Funicular: + return 'Zahnradbahn_l'; + case departure.mode === Mode.AerialLift: + // return 'Gondelbahn_l'; + return 'Luftseilbahn_l'; + case departure.mode === Mode.Ferry: + return 'Schiff_l'; + case departure.mode === Mode.Other: + default: + return 'Licht'; + } + })()} + {@const notices = (() => { + let notices = [] as [pictogram: string[], content: string][]; + if (departure.cancelled) + notices.push([ + ['Cancellation', 'Attention'], + m.brief_north_otter_cherish(), + ]); + if (delayMinutes < -0.5) { + notices.push([ + ['Hint'], + m.vehicle_is_early({ + minutes: -delayMinutes, + arrival: isArrivals.toString(), + }), + ]); + } else if (delayMinutes >= 1) { + notices.push([ + delayMinutes >= 5 + ? ['Delay', 'Attention'] + : delayMinutes >= 3 + ? ['Delay', 'Hint'] + : ['Hint'], + m.next_long_lark_bask({ + minutes: delayMinutes.toFixed(0), + }), + ]); + } + return notices; + })()} + {@const situationIsBad = notices.find((v) => v[0].includes('Attention'))} +
+
+
+ {#if pictogram} + + {/if} + {#if ([Mode.NightRail || Mode.HighspeedRail || Mode.LongDistanceRail || Mode.RegionalFastRail || Mode.RegionalRail].includes(departure.mode) || (departure.mode === 'BUS' && routeShortName.startsWith('EV')) || (departure.mode === 'METRO' && departure.routeShortName.startsWith('S'))) && !avoidGlyph} + + {:else} + + {routeShortName} + + {/if} + + + {m.to()} + {departure.headsign} + +
+
+ {#if departure.place.scheduledTrack && departure.place.track} + + {#if departure.place.name !== placeName}{`${ + departure.place.name === placeName + ', Bahnhof' + ? placeName + ', Busbahnhof' + : departure.place.name + }, `} + {/if}{m.station_location({ + track: departure.place.track, + mode: departure.mode, + })} + + {:else if departure.place.name !== placeName}{departure.place.name === + placeName + ', Bahnhof' + ? placeName + ', Busbahnhof' + : departure.place.name} + {/if} +
+
+ {departure.cancelled + ? m.antsy_weird_cowfish_wish() + ' ' + : ''}{isRelativeTime && Math.abs(expectedTime - receivedTime) < 1 + ? isArrivals + ? m.hour_tidy_hawk_explore() + : m.free_knotty_ray_soar() + : isArrivals + ? m.polite_lucky_angelfish_amaze() + : m.home_flaky_jurgen_ascend()} + {#if Math.abs(expectedTime - receivedTime) < 1} + + {@render renderLocalTime(new Date(receivedTime * 60 * 1000))} + + {:else} + + {@render renderLocalTime(new Date(expectedTime * 60 * 1000), true)} + + + {@render renderLocalTime(new Date(receivedTime * 60 * 1000), true)} + + {#if isRelativeTime} + + ({@render renderLocalTime(new Date(receivedTime * 60 * 1000))}) + + {/if} + {/if} +
+ {#if notices.length !== 0} +
+ {#each notices as notice} +
+ {#each notice[0] as pictogram}{/each} + + {notice[1]} + +
+ {/each} +
+ {/if} + + {#if departure.agencyName} + {m.operated_by({ + operator: operators.has(departure.agencyName) + ? operators.get(departure.agencyName)! + : departure.agencyName, + })}{#if departure.agencyName === 'DB Fernverkehr AG'} + {' '} + · + {m.line_number_accuracy()}{/if} + {/if} +
+ {/each} +{:else} +
+
+ {#if (placeName || placeId) && isResultsPage} +

No results

+

+ No results have been found for the station {placeName ?? placeId}.
+ Please try again. +

+ {:else if placeId} +

No results

+

+ No results have been found for the station {placeName ?? placeId}.
+ Please try again. +

+ {:else} +

No Station

+

+ Please input a station in the search field above and select a search + result. +

+

+ Examples: + + + + + + +

+ {/if} +
+
+{/if} diff --git a/src/lib/Titlebar.svelte b/src/lib/Titlebar.svelte new file mode 100644 index 0000000..35cfd0d --- /dev/null +++ b/src/lib/Titlebar.svelte @@ -0,0 +1,55 @@ + + +
+ +
+ {@render children?.()} +
+
diff --git a/src/lib/aliases.ts b/src/lib/aliases.ts new file mode 100644 index 0000000..4fc08ec --- /dev/null +++ b/src/lib/aliases.ts @@ -0,0 +1,36 @@ +import { m } from './paraglide/messages'; + +export const placeNameMap = new Map(); +for (const [v1, v2] of [ + ['Freiburg(Brsg)', 'Freiburg(Breisgau) Hbf'], + ['Freiburg(Breisgau)', 'Freiburg(Breisgau) Hbf'], + ['Freiburg(Breisgau) Hbf', 'Freiburg(Breisgau) Hbf'], + ['Freiburg (Breisgau)', 'Freiburg(Breisgau) Hbf'], + ['Freiburg (Breisgau) Hbf', 'Freiburg(Breisgau) Hbf'], + ['Freiburg im Breisgau', 'Freiburg(Breisgau) Hbf'], + ['Freiburg im Breisgau Hbf', 'Freiburg(Breisgau) Hbf'], + ['Freiburg im Breisgau Hauptbahnhof', 'Freiburg(Breisgau) Hbf'], + ['Freiburg (D)', 'Freiburg(Breisgau) Hbf'], + ['Freiburg (D), Busbahnhof', 'Freiburg(Breisgau) Hbf'], + ['Freiburg Hauptbahnhof', 'Freiburg(Breisgau) Hbf'], + ['S+U Berlin Hauptbahnhof', 'Berlin Hbf'], + ['Berlin Hauptbahnhof', 'Berlin Hbf'], +]) + placeNameMap.set(v1.toLowerCase(), v2); +export const operators = new Map(); +operators.set('Schweizerische Bundesbahnen SBB', m.operator_sbb()); +operators.set('SBB', m.operator_sbb()); + +operators.set('SZU', m.operator_szu()); +operators.set('Sihltal-Zürich-Uetliberg-Bahn', m.operator_szu()); + +operators.set('Verkehrsbetriebe Zürich', m.operator_vbz()); // buses +operators.set('Verkehrsbetriebe Zürich INFO+', m.operator_vbz()); // trams + +operators.set('BLS AG (bls)', m.operator_bls()); + +operators.set('Städtische Verkehrsbetriebe Bern', m.operator_bernmobil()); + +operators.set('Regionalverkehr Bern-Solothurn', m.operator_rbs()); + +operators.set('Verkehrsbetriebe Glattal', m.operator_vbg()); diff --git a/src/lib/assets/LineGlyph.svelte b/src/lib/assets/LineGlyph.svelte new file mode 100644 index 0000000..f5df523 --- /dev/null +++ b/src/lib/assets/LineGlyph.svelte @@ -0,0 +1,193 @@ + + + + + + + + + + {#if isFernverkehr} + + + + {#if lineType && lineType.toUpperCase() in fernverkehrIconMap} + + {/if} + + {#if line !== undefined && line !== ''} + {line} + {/if} + + {:else} + + A + + {routeShortName} + + {/if} + diff --git a/src/lib/assets/LineGlyphSrc.svg b/src/lib/assets/LineGlyphSrc.svg new file mode 100644 index 0000000..8d7bc59 --- /dev/null +++ b/src/lib/assets/LineGlyphSrc.svg @@ -0,0 +1,233 @@ + + + + diff --git a/src/lib/assets/Pictogram.svelte b/src/lib/assets/Pictogram.svelte new file mode 100644 index 0000000..fe97de6 --- /dev/null +++ b/src/lib/assets/Pictogram.svelte @@ -0,0 +1,11 @@ + + +{which} diff --git a/src/lib/index.ts b/src/lib/index.ts new file mode 100644 index 0000000..a961354 --- /dev/null +++ b/src/lib/index.ts @@ -0,0 +1,51 @@ +// place files you want to import through the `$lib` alias in this folder. +export type ButtonColours = { + fg: string; + fgDisabled: string; + bg: string; + bgActive: string; + bgHover: string; +}; +export const S = { + card_bg: 'bg-[#ffffff]/20' as const, + shadow_large: 'shadow-[0_5px_25px_-3px_#00000077]' as const, + window: + 'outline-[1.5px] outline-[#313135] rounded-xl flex flex-row items-stretch justify-stretch max-h-full' as const, + window_sidepanel: 'bg-[#28282C] rounded-l-xl p-2 pt-0 min-w-48' as const, + window_content: 'bg-[#1D1D20] rounded-r-xl p-2 pt-0 flex-1' as const, + window_content_fullscreen: + 'bg-[#1D1D20] rounded-xl p-2 pt-0 flex-1 max-w-[100%]' as const, + window_topbar: + 'box-border min-h-[3.5rem] px-1 py-2 font-bold flex items-center justify-center gap-2 sticky top-0 bg-inherit z-50' as const, + button(colours: 'primary' | 'secondary' | ButtonColours) { + switch (colours) { + case 'primary': + colours = { + fg: '#dedede', + fgDisabled: '#2e3436', + bg: '#3584E4', + bgActiv