commit dbea2d6c48769c857a49ef356a556620264c9e7a
parent 3325cf11f01583ffd494a07ae748053d27bb850f
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 17 Apr 2025 09:40:42 +0200
parent 3325cf11f01583ffd494a07ae748053d27bb850f
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 17 Apr 2025 09:40:42 +0200
cleanup
18 files changed, 83 insertions(+), 94 deletions(-)
diff --git a/src/coach-sequence/DB/TrainNames.js b/src/coach-sequence/DB/TrainNames.js @@ -1,5 +1,6 @@ // List from https://de.wikipedia.org/wiki/Liste_nach_Gemeinden_und_Regionen_benannter_IC/ICE-Fahrzeuge#Namensgebung_ICE-Triebz%C3%BCge_nach_Gemeinden const naming = { + // ICE 1 - BR 401 101: 'Gießen', 102: 'Jever', @@ -52,7 +53,7 @@ const naming = { 187: 'Mühldorf a. Inn', 188: 'Hildesheim', 190: 'Ludwigshafen am Rhein', - // + // ICE 2 - BR 402 201: 'Rheinsberg', 202: 'Wuppertal', @@ -98,7 +99,7 @@ const naming = { 242: 'Quedlinburg', 243: 'Bautzen/Budyšin', 244: 'Koblenz', - // + // ICE 3 - BR 403 301: 'Freiburg im Breisgau', 302: 'Hansestadt Lübeck', @@ -148,7 +149,7 @@ const naming = { 361: 'Celle', 362: 'Schwerte (Ruhr)', 363: 'Weilheim i. OB', - // + // ICE T - BR 411 1101: 'Neustadt an der Weinstraße', 1102: 'Neubrandenburg', @@ -209,7 +210,7 @@ const naming = { 1190: 'Wien', 1191: 'Salzburg', 1192: 'Linz', - // + // ICE T - BR 415 1501: 'Eisenach', 1502: 'Karlsruhe', @@ -222,7 +223,7 @@ const naming = { 1522: 'Torgau', 1523: 'Hansestadt Greifswald', 1524: 'Hansestadt Rostock', - // + // Intercity2 2853: 'Nationalpark Sächsische Schweiz', 2865: 'Remstal', @@ -230,12 +231,12 @@ const naming = { 2871: 'Leipziger Neuseenland', 2874: 'Oberer Neckar', 2875: 'Magdeburger Börde', - // + // Intercity2 KISS - BR 4110 4111: 'Gäu', 4114: 'Dresden Elbland', 4117: 'Mecklenburgische Ostseeküste', - // + // ICE 3 - BR 406 4601: 'Europa/Europe', 4602: 'Euregio Maas-Rhein', @@ -251,11 +252,11 @@ const naming = { 4683: 'Limburg an der Lahn', 4684: 'Forbach-Lorraine', 4685: 'Schwäbisch Hall', - // + // ICE 3 - BR 407 4712: 'Dillingen a.d. Donau', 4717: 'Paris', - // + // ICE 4 - BR 412 9006: 'Martin Luther', 9018: 'Freistaat Bayern', @@ -268,6 +269,7 @@ const naming = { 9202: 'Schleswig-Holstein', 9457: 'Bundesrepublik Deutschland' }; + export default (tzn => { // @ts-expect-error ??? if (tzn) return naming[Number.parseInt(tzn, 10)];
diff --git a/src/coach-sequence/DB/baureihe.js b/src/coach-sequence/DB/baureihe.js @@ -5,31 +5,31 @@ // export const nameMap = { - '401': 'ICE 1 (BR401)', - '401.9': 'ICE 1 Kurz (BR401)', + '401': 'ICE 1 (BR401)', + '401.9': 'ICE 1 Kurz (BR401)', '401.LDV': 'ICE 1 Modernisiert (BR401)', - '402': 'ICE 2 (BR402)', - '403': 'ICE 3 (BR403)', - '403.S1': 'ICE 3 (BR403 1. Serie)', - '403.S2': 'ICE 3 (BR403 2. Serie)', - '403.R': 'ICE 3 (BR403)', - '406': 'ICE 3 (BR406)', - '406.R': 'ICE 3 (BR406 Redesign)', - '407': 'ICE 3 Velaro (BR407)', - '408': 'ICE 3neo (BR408)', - '410.1': 'ICE S (BR410.1)', - '411': 'ICE T (BR411)', - '411.S1': 'ICE T (BR411 1. Serie)', - '411.S2': 'ICE T (BR411 2. Serie)', - '412': 'ICE 4 (BR412)', - '412.7': 'ICE 4 Kurz (BR412)', - '412.13': 'ICE 4 Lang (BR412)', - '415': 'ICE T Kurz (BR415)', + '402': 'ICE 2 (BR402)', + '403': 'ICE 3 (BR403)', + '403.S1': 'ICE 3 (BR403 1. Serie)', + '403.S2': 'ICE 3 (BR403 2. Serie)', + '403.R': 'ICE 3 (BR403)', + '406': 'ICE 3 (BR406)', + '406.R': 'ICE 3 (BR406 Redesign)', + '407': 'ICE 3 Velaro (BR407)', + '408': 'ICE 3neo (BR408)', + '410.1': 'ICE S (BR410.1)', + '411': 'ICE T (BR411)', + '411.S1': 'ICE T (BR411 1. Serie)', + '411.S2': 'ICE T (BR411 2. Serie)', + '412': 'ICE 4 (BR412)', + '412.7': 'ICE 4 Kurz (BR412)', + '412.13': 'ICE 4 Lang (BR412)', + '415': 'ICE T Kurz (BR415)', 'IC2.TRE': 'IC 2 (TRE)', - '4110': 'IC 2 KISS (BR4110)', - '4010': 'IC 2 KISS (BR4010)', - MET: 'MET', - TGV: 'TGV', + '4110': 'IC 2 KISS (BR4110)', + '4010': 'IC 2 KISS (BR4010)', + 'MET': 'MET', + 'TGV': 'TGV', }; const getATBR = (code, _serial, _coaches) => {
diff --git a/src/coach-sequence/DB/specialSeats.js b/src/coach-sequence/DB/specialSeats.js @@ -51,6 +51,7 @@ export function getComfortSeats(identifier, klasse) { return klasse === 3 ? '144, 145' : '55-68'; } } + export function getDisabledSeats(identifier, klasse, wagenordnungsnummer) { switch (identifier) { case '401': @@ -122,6 +123,7 @@ export function getDisabledSeats(identifier, klasse, wagenordnungsnummer) { return klasse === 3 ? '143' : '21-26'; } } + export function getFamilySeats(identifier) { switch (identifier) { case '401':
diff --git a/src/departuresView.js b/src/departuresView.js @@ -1,4 +1,4 @@ -import { LitElement, html, nothing } from 'lit'; +import { html, nothing } from 'lit'; import { LitOverlay } from './LitOverlay.js'; import { sleep, queryBackgroundColor, setThemeColor } from './helpers.js';
diff --git a/src/hafasClient.js b/src/hafasClient.js @@ -1,11 +1,12 @@ import { createClient as createVendoClient } from 'db-vendo-client'; +import { createClient as createHafasClient } from 'hafas-client'; + import { profile as dbNavProfile } from 'db-vendo-client/p/dbnav/index.js'; import { profile as bvgProfile } from 'hafas-client/p/bvg/index.js'; import { profile as nahshProfile } from 'hafas-client/p/nahsh/index.js'; import { profile as rmvProfile } from 'hafas-client/p/rmv/index.js'; import { profile as oebbProfile } from 'hafas-client/p/oebb/index.js'; -let createHafasClient = null; const clients = {}; export let client; @@ -28,7 +29,6 @@ export const getHafasClient = async profileName => { } if (profiles[profileName].backend === 'hafas') { - if ( createHafasClient === null) createHafasClient = (await import('hafas-client')).createClient; clients[profileName] = createHafasClient(profiles[profileName].profile, APP_NAME); if (isDevServer) console.info('initialized hafas client with profile ' + profileName); }
diff --git a/src/helpers.js b/src/helpers.js @@ -1,6 +1,6 @@ -export const sleep = delay => new Promise((resolve) => setTimeout(resolve, delay)); -export const isEmptyObject = obj => Object.keys(obj).length === 0; -export const padZeros = str => (('00' + str).slice(-2)); +export const sleep = delay => new Promise((resolve) => setTimeout(resolve, delay)); +export const isEmptyObject = obj => Object.keys(obj).length === 0; +export const padZeros = str => (('00' + str).slice(-2)); export const setThemeColor = color => document.querySelector('meta[name="theme-color"]').setAttribute('content', color); export const queryBackgroundColor = (target, query) => window.getComputedStyle(target.querySelector(query)).getPropertyValue('background-color');
diff --git a/src/index.html b/src/index.html @@ -2,7 +2,8 @@ <html> <head> <title>{{APP_NAME}}</title> - <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> + + <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta name="theme-color" content="#333"> <meta name="description" content="Plan your public transport journeys"> @@ -22,6 +23,7 @@ <noscript style="margin: auto;">JavaScript is required to use <%= htmlWebpackPlugin.options.title %></noscript> <svg style="margin: auto; width: 50vmin; height: 50vmin;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><rect rx="4" height="28" width="28" fill="green"/><path d="M14 5.5c-4 0-8 .5-8 4V19c0 1.93 1.57 3.5 3.5 3.5L8 24v.5h2.23l2-2H16l2 2h2V24l-1.5-1.5c1.93 0 3.5-1.57 3.5-3.5V9.5c0-3.5-3.58-4-8-4m-4.5 15c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5m3.5-7H8v-4h5zm2 0v-4h5v4zm3.5 7c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5" fill="white"/></svg> </div> + <script type="module" src="./main.js"></script> </body> </html>
diff --git a/src/journeyView.js b/src/journeyView.js @@ -1,4 +1,4 @@ -import { LitElement, html, css, nothing } from 'lit'; +import { html, css, nothing } from 'lit'; import { LitOverlay } from './LitOverlay.js'; import { createEvents } from 'ics'; @@ -38,7 +38,7 @@ class JourneyView extends LitOverlay { this.viewState = null; this.settingsState = settings.getState(); - this.isUpdating = false; + this.isUpdating = false; } async connectedCallback () { @@ -49,7 +49,7 @@ class JourneyView extends LitOverlay { if (this.viewState === null) await this.updateViewState(); - this._unsubscribeSettingsState = settings.subscribe((state) => { + this._unsubscribeSettingsState = settings.subscribe(state => { this.settingsState = state; this.performUpdate(); }); @@ -277,7 +277,7 @@ class JourneyView extends LitOverlay { await this.refreshJourney(); if (this.viewState.tickets === undefined) { - await showAlertOverlay('No ticket data available'); + await this.showAlertOverlay('No ticket data available'); return false; }
diff --git a/src/journeysCanvas.js b/src/journeysCanvas.js @@ -1,7 +1,7 @@ -import { LitElement, html, css } from 'lit'; +import { html } from 'lit'; import { LitOverlay } from './LitOverlay.js'; -import { CustomDate, sleep } from './helpers.js'; +import { CustomDate } from './helpers.js'; import { formatTrainTypes, formatLineDisplayName } from './formatters.js' import { cachedCoachSequence, coachSequenceCache, coachSequenceCacheKey } from './coach-sequence/index.js'; @@ -68,7 +68,7 @@ export class JourneysCanvas extends LitOverlay { }; this.canvasState.offsetX = (window.innerWidth / this.canvasState.dpr) > 600 ? 140 : 80; - }; + } updated (previous) { super.updated(previous); @@ -101,7 +101,7 @@ export class JourneysCanvas extends LitOverlay { this.resizeHandler(); } } - } + }; disconnectCanvas = () => { window.removeEventListener('mouseup', this.mouseUpHandler); @@ -113,7 +113,7 @@ export class JourneysCanvas extends LitOverlay { this.canvasState.handlersConnected = false; this.canvasElement = null; this.canvasContext = null; - } + }; resizeHandler = () => { if (this.canvasContext === null) return true; @@ -158,7 +158,7 @@ export class JourneysCanvas extends LitOverlay { this.canvasState.dragging = false; this.canvasState.isClick = false; - } + }; mouseDownHandler = event => { const x = event.x || event.changedTouches[0].pageX; @@ -166,7 +166,7 @@ export class JourneysCanvas extends LitOverlay { this.canvasState.dragStartOffset = this.canvasState.offsetX; this.canvasState.dragging = true; this.canvasState.isClick = true; - } + }; mouseMoveHandler = event => { if (this.canvasState.dragging) { @@ -177,7 +177,7 @@ export class JourneysCanvas extends LitOverlay { this.renderCanvas(); return true; } - } + }; makeTextCache = (text, color, fixedHeight) => { const cacheCanvas = document.createElement('canvas'); @@ -223,7 +223,7 @@ export class JourneysCanvas extends LitOverlay { } else { return JourneysCanvas.colors[type][leg][num]; } - } + }; getCoachSequences = async () => { if (this.viewState.profile !== 'db') return; @@ -238,7 +238,7 @@ export class JourneysCanvas extends LitOverlay { } } this.isUpdating = false; - } + }; getTrainTypeTexts = leg => { if (!leg.line || !leg.line.name) return []; @@ -446,5 +446,5 @@ export class JourneysCanvas extends LitOverlay { }); if (this.viewState.laterRef) drawButton('later'); - } + }; }
diff --git a/src/journeysView.js b/src/journeysView.js @@ -1,4 +1,4 @@ -import { html, css, nothing } from 'lit'; +import { html, nothing } from 'lit'; import { sleep, queryBackgroundColor, setThemeColor } from './helpers.js'; import { getJourneys, getMoreJourneys, refreshJourneys, getFromPoint, getToPoint } from './app_functions.js'; @@ -49,7 +49,7 @@ export class JourneysView extends JourneysCanvas { if (this.viewState === null) await this.updateViewState(); if (this.mode === 'canvas') this.connectCanvas(); - this._unsubscribeSettingsState = settings.subscribe((state) => { + this._unsubscribeSettingsState = settings.subscribe(state => { this.settingsState = state; this.performUpdate(); });
diff --git a/src/main.js b/src/main.js @@ -1,4 +1,4 @@ -import { LitElement, html, render } from 'lit'; +import { LitElement, html } from 'lit'; import { cache } from 'lit/directives/cache.js'; import { initDataStorage } from './dataStorage.js'; @@ -49,14 +49,6 @@ class Oeffisearch extends LitElement { if (!window.location.hash.length) window.location = '#/'; } - routeHandler = () => { - const dest = window.location.hash.slice(1); - this.routes.forEach(route => { - const match = route.pattern.exec(dest); - if (match !== null) this.outlet = route.render(match.slice(1)); - }); - } - connectedCallback () { super.connectedCallback(); window.addEventListener('hashchange', this.routeHandler); @@ -69,6 +61,14 @@ class Oeffisearch extends LitElement { } render = () => cache(this.outlet); + + routeHandler = () => { + const dest = window.location.hash.slice(1); + this.routes.forEach(route => { + const match = route.pattern.exec(dest); + if (match !== null) this.outlet = route.render(match.slice(1)); + }); + } } customElements.define('oeffi-search', Oeffisearch); @@ -80,10 +80,7 @@ customElements.define('oeffi-search', Oeffisearch); const style = document.createElement('style'); style.type = 'text/css'; - style.appendChild(document.createTextNode([ - baseStyles, - helperStyles - ].join(''))); + style.appendChild(document.createTextNode(baseStyles)); document.head.appendChild(style); document.body.innerHTML = '<oeffi-search></oeffi-search>';
diff --git a/src/searchView.js b/src/searchView.js @@ -7,7 +7,7 @@ import { client } from './hafasClient.js'; import { getIBNRbyDS100 } from './ds100.js'; import { formatPoint } from './formatters.js'; import { newJourneys } from './app_functions.js'; -import { CustomDate, padZeros, sleep, queryBackgroundColor, setThemeColor } from './helpers.js'; +import { CustomDate, sleep, queryBackgroundColor, setThemeColor } from './helpers.js'; import { baseStyles, helperStyles, flexboxStyles, buttonInputStyles, iconStyles, searchViewStyles } from './styles.js'; import { settings } from './settings.js'; @@ -77,7 +77,7 @@ class SearchView extends LitOverlay { await this.updateHistoryState(); - this._unsubscribeSettingsState = settings.subscribe((state) => { + this._unsubscribeSettingsState = settings.subscribe(state => { this.settingsState = state; this.performUpdate(); }); @@ -141,8 +141,8 @@ class SearchView extends LitOverlay { ${this.location[name].suggestions.map((suggestion, index) => html` <p class="${index !== this.location[name].suggestion ? nothing : 'selected'}" @click=${(event) => this.setSuggestion(name, index, event.pointerType)} - @mouseover=${(event) => this.mouseOverHandler(event, name)} - @mouseout=${(event) => this.mouseOutHandler(event, name)}>${formatPoint(suggestion)}</p> + @mouseover=${() => this.mouseOverHandler(name)} + @mouseout=${() => this.mouseOutHandler(name)}>${formatPoint(suggestion)}</p> `)} </div> `)} @@ -393,8 +393,8 @@ class SearchView extends LitOverlay { window.location = `#/${responseData.slug}/${this.settingsState.journeysViewMode}`; } - mouseOverHandler (event, name) { this.location[name].suggestionsFocused = true; } - mouseOutHandler (event, name) { this.location[name].suggestionsFocused = false; } + mouseOverHandler (name) { this.location[name].suggestionsFocused = true; } + mouseOutHandler (name) { this.location[name].suggestionsFocused = false; } focusHandler = event => { const name = event.target.name;
diff --git a/src/settings.js b/src/settings.js @@ -53,7 +53,7 @@ export const settings = createStore()( export const initSettingsState = async () => { settingsState = settings.getState(); - settings.subscribe((state) => { + settings.subscribe(state => { settingsState = state; }); };
diff --git a/src/settingsView.js b/src/settingsView.js @@ -29,7 +29,7 @@ class SettingsView extends LitElement { connectedCallback () { super.connectedCallback(); - this._unsubscribeViewState = settings.subscribe((state, prev) => { + this._unsubscribeViewState = settings.subscribe(state => { this.viewState = state; this.performUpdate(); });
diff --git a/src/shim/cross-fetch.js b/src/shim/cross-fetch.js @@ -1,9 +1,7 @@ export const Request = globalThis.Request; export const fetch = (resource, options) => { - if (!(resource instanceof Request)) { - resource = new Request(resource); - } + if (!(resource instanceof Request)) resource = new Request(resource); if (isDevServer) console.log('fetch(): ', resource, options);
diff --git a/src/shim/https-proxy-agent.js b/src/shim/https-proxy-agent.js @@ -1,19 +1,8 @@ import {Agent} from "https"; export default class HttpsProxyAgent extends Agent { - constructor(proxy, opts) { super(opts); this.proxy = proxy; } - - /** - * Called when the node-core HTTP client library is creating a - * new HTTP request. - */ - /*async connect( - req: http.ClientRequest, - opts: AgentConnectOpts - ): Promise<net.Socket> { - }*/ }
diff --git a/src/shim/https.js b/src/shim/https.js @@ -1,4 +1,3 @@ export class Agent { - Agent() { - } + Agent() {} }
diff --git a/src/tripView.js b/src/tripView.js @@ -1,4 +1,4 @@ -import { LitElement, html, nothing } from 'lit'; +import { html, nothing } from 'lit'; import { LitOverlay } from './LitOverlay.js'; import { sleep, queryBackgroundColor, setThemeColor } from './helpers.js';