hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | /** |
| 2 | * unDraw illustrations (https://undraw.co — free for commercial use, no |
| 3 | * attribution required; see src/assets/illustrations/README.md). The SVG files |
| 4 | * stay exactly as downloaded; their fixed palette is mapped onto theme tokens |
| 5 | * here, so they follow the picked brand color and the dark theme. |
| 6 | */ |
| 7 | export type IllustrationName = |
| 8 | | "calendar-empty" |
| 9 | | "charts" |
| 10 | | "coming-soon" |
| 11 | | "courses" |
| 12 | | "empty" |
| 13 | | "events" |
| 14 | | "exams" |
| 15 | | "homework" |
| 16 | | "meals" |
| 17 | | "modules" |
| 18 | | "messages" |
| 19 | | "no-results" |
| 20 | | "notes" |
| 21 | | "payments" |
| 22 | | "people" |
| 23 | | "schedule" |
| 24 | | "server-down" |
| 25 | | "whiteboard" |
| 26 | | "work"; |
| 27 | |
| 28 | const loaders = import.meta.glob<string>("../assets/illustrations/*.svg", { |
| 29 | query: "?raw", |
| 30 | import: "default", |
| 31 | }); |
| 32 | |
| 33 | // unDraw's stock colors → the --illu-* tokens declared in index.css. Skin |
| 34 | // tones and the few food colors are left alone. |
| 35 | const PALETTE: Record<string, string> = { |
| 36 | "#6c63ff": "var(--illu-accent)", |
| 37 | "#ff6584": "var(--illu-accent-2)", |
| 38 | "#fd6584": "var(--illu-accent-2)", |
| 39 | "#3f3d56": "var(--illu-ink)", |
| 40 | "#2f2e41": "var(--illu-ink)", |
| 41 | "#090814": "var(--illu-ink)", |
| 42 | "#ccc": "var(--illu-line)", |
| 43 | "#cacaca": "var(--illu-line)", |
| 44 | "#cbcbcb": "var(--illu-line)", |
| 45 | "#d6d6e3": "var(--illu-line)", |
| 46 | "#e6e6e6": "var(--illu-soft)", |
| 47 | "#e4e4e4": "var(--illu-soft)", |
| 48 | "#e2e2e2": "var(--illu-soft)", |
| 49 | "#e6e7e8": "var(--illu-soft)", |
| 50 | "#f0f0f0": "var(--illu-soft)", |
| 51 | "#f2f2f2": "var(--illu-soft)", |
| 52 | "#fff": "var(--illu-paper)", |
| 53 | "#ffffff": "var(--illu-paper)", |
| 54 | }; |
| 55 | |
| 56 | export function recolorIllustration(svg: string): string { |
| 57 | return svg |
| 58 | .replace(/#[0-9a-f]{3,6}\b/gi, (hex) => PALETTE[hex.toLowerCase()] ?? hex) |
| 59 | // Size comes from the wrapper's CSS, not the file's pixel dimensions. |
| 60 | .replace(/<svg([^>]*?)\s(?:width|height)="[^"]*"/g, "<svg$1") |
| 61 | .replace(/<svg([^>]*?)\s(?:width|height)="[^"]*"/g, "<svg$1") |
| 62 | .replace(/<svg/, '<svg aria-hidden="true" focusable="false" preserveAspectRatio="xMidYMid meet"'); |
| 63 | } |
| 64 | |
| 65 | const cache = new Map<IllustrationName, Promise<string>>(); |
| 66 | |
| 67 | export function loadIllustration(name: IllustrationName): Promise<string> { |
| 68 | let pending = cache.get(name); |
| 69 | if (!pending) { |
| 70 | const load = loaders[`../assets/illustrations/${name}.svg`]; |
| 71 | pending = load ? load().then(recolorIllustration) : Promise.resolve(""); |
| 72 | cache.set(name, pending); |
| 73 | } |
| 74 | return pending; |
| 75 | } |