forked from fahrPool/fahrPool
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { STANDARD_FARBE_PRIMAER } from "@/lib/firma/farben";
|
|
import { iconUrl, type IconBranding } from "./icon-url";
|
|
|
|
const STANDARD_NAME = "Aushilfsfahrer";
|
|
const MAX_KURZNAME = 12;
|
|
|
|
// Kurzname fuers Homescreen-Label: an der Wortgrenze kuerzen, sonst hart.
|
|
export function kurzname(name: string): string {
|
|
const n = name.trim();
|
|
if (n.length <= MAX_KURZNAME) return n;
|
|
if (n[MAX_KURZNAME] === " ") return n.slice(0, MAX_KURZNAME);
|
|
const kopf = n.slice(0, MAX_KURZNAME);
|
|
const grenze = kopf.lastIndexOf(" ");
|
|
return grenze > 0 ? kopf.slice(0, grenze).trim() : kopf;
|
|
}
|
|
|
|
export function themeFarbe(f: { farbe_primaer: string | null } | null): string {
|
|
return f?.farbe_primaer ?? STANDARD_FARBE_PRIMAER;
|
|
}
|
|
|
|
export function baueManifest(f: IconBranding | null): Record<string, unknown> {
|
|
return {
|
|
name: f ? f.name : STANDARD_NAME,
|
|
short_name: f ? kurzname(f.name) : STANDARD_NAME,
|
|
theme_color: themeFarbe(f),
|
|
background_color: "#ffffff",
|
|
display: "standalone",
|
|
start_url: "/",
|
|
scope: "/",
|
|
lang: "de",
|
|
icons: [
|
|
{ src: iconUrl(f, "192"), sizes: "192x192", type: "image/png", purpose: "any" },
|
|
{ src: iconUrl(f, "512"), sizes: "512x512", type: "image/png", purpose: "any" },
|
|
{ src: iconUrl(f, "512-maskable"), sizes: "512x512", type: "image/png", purpose: "maskable" },
|
|
],
|
|
};
|
|
}
|