feat(ui): redesigned book card and menu (#2396)

This commit is contained in:
Alex
2026-09-21 13:01:58 +01:00
committed by GitHub
parent b7cfd20ecd
commit 5572fc2dbd
38 changed files with 2408 additions and 23 deletions
@@ -20,15 +20,25 @@
/>
} @else {
<div
class="placeholder group flex aspect-[5/7] h-full w-full flex-col items-center justify-center gap-1 overflow-hidden rounded-[inherit] p-1 text-center data-[size=md]:p-2 data-[size=lg]:gap-2 data-[size=lg]:p-4"
class="placeholder group flex aspect-[5/7] h-full w-full flex-col justify-end overflow-hidden rounded-[inherit] p-2 text-left data-[size=md]:p-3 data-[size=lg]:p-3 bg-[linear-gradient(135deg,oklch(0.58_0.075_var(--cover-h))_25%,oklch(0.46_0.09_var(--cover-h))_95%)] dark:bg-[linear-gradient(135deg,oklch(0.40_0.065_var(--cover-h))_25%,oklch(0.30_0.06_var(--cover-h))_95%)]"
[attr.data-size]="size()"
[style.background]="color()"
[style.--cover-h]="hue()"
>
<div class="placeholder-title line-clamp-3 max-w-full overflow-hidden break-words text-xs font-semibold leading-snug text-white/90 group-data-[size=md]:text-sm group-data-[size=lg]:text-base">
{{ title() }}
</div>
<div class="placeholder-author line-clamp-1 max-w-full overflow-hidden break-words text-xs text-white/55 group-data-[size=lg]:text-sm">
{{ authorsLabel() }}
<div
class="@max-[80px]:hidden transition-transform duration-300 ease-glide group-hover/lift:-translate-y-7 group-has-[:focus-visible]/lift:-translate-y-7 group-[.cover-lifted]/lift:-translate-y-7 motion-reduce:transition-none text-[oklch(0.95_0.025_var(--cover-h))] dark:text-[oklch(0.94_0.03_var(--cover-h))]"
>
@if (titleOnly()) {
<div class="placeholder-title line-clamp-3 max-w-full overflow-hidden break-words font-normal leading-[1.25] font-cover-serif text-[14px] group-data-[size=md]:text-[17px] group-data-[size=lg]:text-[19px]">
{{ title() }}
</div>
} @else {
<div class="placeholder-title line-clamp-3 max-w-full overflow-hidden break-words font-normal leading-[1.25] font-cover-serif text-[12px] group-data-[size=md]:text-[15px] group-data-[size=lg]:text-[17px]">
{{ title() }}
</div>
<div class="placeholder-author mt-1 line-clamp-1 max-w-full overflow-hidden break-words uppercase tracking-[0.08em] opacity-70 font-cover-serif text-[8.5px] group-data-[size=md]:mt-1.5 group-data-[size=md]:text-[9.5px] group-data-[size=lg]:text-[11px]">
{{ authorsLabel() }}
</div>
}
</div>
</div>
}
@@ -1,10 +1,7 @@
import {ChangeDetectionStrategy, Component, computed, DestroyRef, inject, input, signal, viewChild} from '@angular/core';
import {Image} from '@openng/optimus-ui/image';
const COVER_COLORS = [
'#1a1a2e', '#2d3436', '#0c3547', '#1e3d59', '#2c2c54', '#1b262c',
'#2B2D42', '#3D405B', '#463F3A', '#1B2838', '#2E4057', '#4A3728',
];
const COVER_HUES = [20, 155, 185, 205, 235, 265, 290, 320, 350];
function hashString(str: string): number {
let hash = 0;
@@ -15,8 +12,8 @@ function hashString(str: string): number {
return hash;
}
function coverColorFor(title: string, author: string): string {
return COVER_COLORS[Math.abs(hashString(title + author) % COVER_COLORS.length)];
function coverHueFor(title: string, author: string): number {
return COVER_HUES[Math.abs(hashString(title + author)) % COVER_HUES.length];
}
type CoverSize = 'sm' | 'md' | 'lg';
@@ -30,7 +27,7 @@ type CoverAuthors = string | string[];
imports: [Image],
templateUrl: './cover.component.html',
host: {
class: 'block w-full',
class: '@container block w-full',
'[class.h-full]': '!natural()',
'[class.h-auto]': 'natural()',
'(window:popstate)': 'closePreview()',
@@ -54,7 +51,10 @@ export class CoverComponent {
const authors = this.authors();
return Array.isArray(authors) ? authors.join(', ') : authors ?? '';
});
protected readonly color = computed(() => coverColorFor(this.title() ?? '', this.authorsLabel()));
protected readonly hue = computed(() => coverHueFor(this.title() ?? '', this.authorsLabel()));
protected readonly titleOnly = computed(
() => !this.authorsLabel() || (hashString((this.title() ?? '') + this.authorsLabel()) & 1) === 0,
);
protected readonly imageClass = computed(() => [
'cover-img block w-full rounded-[inherit]',
this.natural() ? 'h-auto' : 'h-full',
@@ -0,0 +1,13 @@
import {describe, expect, it} from 'vitest';
import {fileSizeDisplayUnit, formatFileSizeKb} from './file-size';
describe('file-size util', () => {
it('picks display units and formats with adaptive precision', () => {
expect(fileSizeDisplayUnit(358).label).toBe('KB');
expect(fileSizeDisplayUnit(1468006).label).toBe('GB');
expect(formatFileSizeKb(700)).toBe('700 KB');
expect(formatFileSizeKb(15360)).toBe('15.0 MB');
expect(formatFileSizeKb(1468006)).toBe('1.40 GB');
});
});
+19
View File
@@ -0,0 +1,19 @@
export const FILE_SIZE_UNITS = [
{label: 'KB', kb: 1},
{label: 'MB', kb: 1024},
{label: 'GB', kb: 1024 ** 2},
{label: 'TB', kb: 1024 ** 3},
] as const;
export type FileSizeUnit = (typeof FILE_SIZE_UNITS)[number];
export function fileSizeDisplayUnit(fileSizeKb: number): FileSizeUnit {
return [...FILE_SIZE_UNITS].reverse().find(unit => fileSizeKb >= unit.kb) ?? FILE_SIZE_UNITS[0];
}
export function formatFileSizeKb(fileSizeKb: number): string {
const unit = fileSizeDisplayUnit(fileSizeKb);
const size = fileSizeKb / unit.kb;
const decimals = size >= 100 ? 0 : size >= 10 ? 1 : 2;
return `${size.toFixed(decimals)} ${unit.label}`;
}
@@ -0,0 +1,13 @@
const applePlatform = /Mac/i.test(navigator.userAgent);
export function isContextMenuGesture(event: MouseEvent): boolean {
return applePlatform && event.ctrlKey;
}
export function isPlainLeftClick(event: MouseEvent): boolean {
return event.button === 0
&& !event.ctrlKey
&& !event.metaKey
&& !event.shiftKey
&& !event.altKey;
}