frontend(plumbing): shared theme tokens, cross-cutting stores, gestures, sheets

The plumbing layer the v0.16 UI features (and dark mode) build on.

Shared design tokens (Tailwind v4):
- tailwind-theme.css (new): @custom-variant dark (class-driven, beats OS
  default) + @theme color/font/radius tokens + baseline html/html.dark
  rules so any page that hasn't been re-themed still renders the right
  body bg + color-scheme.
- src/app.css + export-viewer/src/app.css now import the shared theme.
- src/app.html: 6-line FOUC guard sets <html class="dark"> before paint
  (mirrored from theme-store.ts) so dark reloads no longer flash white.
  Adds <meta name="theme-color"> kept in sync by initTheme().

Cross-cutting stores (one per concern, per docs/FEATURES §2.9):
- data-mode-store.ts: 'saver' | 'original' per-device, plus pickMediaUrl
  helper so feed cards / lightbox / diashow all resolve URLs the same way.
- privacy-note-store.ts: hydrated from /me/context, refreshed on SSE
  event-updated.
- quota-store.ts: { enabled, used, limit, active_uploaders, free_disk },
  refreshed after each upload completes.
- theme-store.ts: 'system' | 'light' | 'dark' preference + derived
  appliedTheme + initTheme() that syncs <html class>, localStorage,
  and the theme-color meta. Listens to prefers-color-scheme.
- auth.ts: currentPin writable mirror + clearPin() helper called from
  the global pin-reset SSE handler — fixes the stale-PIN bug where the
  localStorage copy survived a reset.

DTO mirror:
- types.ts: QuotaDto, MeContextDto, PinResetResponse, DeltaResponse each
  carry a `// mirrors backend/...` comment per the lib README convention.

SSE client:
- sse.ts: KNOWN_EVENTS registry (one entry per server-emitted type),
  synthetic feed-delta dispatched after foreground reconnect via the
  /feed/delta?since= endpoint, exponential backoff (1 → 60 s + jitter)
  on errors, attempt counter reset on user-initiated visibility resume.

Upload queue:
- upload-queue.ts: IDB schema bumped to v2 — entries tagged with userId;
  loadQueue filters by current user (no cross-user leak on shared
  devices); uploadItem refuses to upload an entry whose userId differs
  from getUserId() (defense-in-depth); new clearQueue() called on
  explicit logout. v2 upgrade wipes pre-v2 entries (no userId, can't
  attribute safely).

Mobile primitives:
- actions/longpress.ts: 500 ms hold with 10 px move tolerance, swallows
  the next click + the right-click contextmenu so the gesture doesn't
  double-fire the inner button's onclick.
- actions/doubletap.ts: tap-pair detector that preventDefaults the
  second tap so iOS Safari doesn't also zoom on double-tap.
- components/ContextSheet.svelte: generic bottom sheet driven by a
  ContextAction[] prop. Reused by feed posts, comments, host user rows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-05-16 14:32:37 +02:00
parent 2e98f5ddf5
commit 251f9f1469
15 changed files with 733 additions and 34 deletions

View File

@@ -0,0 +1,95 @@
<script lang="ts" module>
// Action shape used by every long-press / kebab menu in the app. Defined in `module`
// so importers don't pay for instance state.
export interface ContextAction {
label: string;
icon?: string; // optional emoji or unicode glyph
tone?: 'default' | 'danger';
disabled?: boolean;
onClick: () => void | Promise<void>;
}
</script>
<script lang="ts">
// Reusable bottom-sheet for context menus. Consumers pass `open`, an array of
// `actions`, and a close callback. Mobile: long-press → open. Desktop: kebab
// icon → open. The sheet itself is platform-agnostic.
interface Props {
open: boolean;
actions: ContextAction[];
onClose: () => void;
title?: string;
}
let { open, actions, onClose, title }: Props = $props();
async function handle(action: ContextAction) {
if (action.disabled) return;
try {
await action.onClick();
} finally {
onClose();
}
}
</script>
<!-- Backdrop -->
<div
class="fixed inset-0 z-40 bg-black/50 transition-opacity duration-200"
class:opacity-0={!open}
class:pointer-events-none={!open}
class:opacity-100={open}
onclick={onClose}
aria-hidden="true"
></div>
<!-- Sheet -->
<div
class="fixed inset-x-0 bottom-0 z-50 rounded-t-2xl bg-white transition-transform duration-200 dark:bg-gray-900"
class:translate-y-full={!open}
class:translate-y-0={open}
style="padding-bottom: env(safe-area-inset-bottom)"
role="dialog"
aria-modal="true"
>
<div class="flex justify-center pt-3 pb-1">
<div class="h-1 w-10 rounded-full bg-gray-300 dark:bg-gray-600"></div>
</div>
{#if title}
<p class="px-5 pt-1 pb-2 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
{title}
</p>
{/if}
<div class="space-y-1 px-3 pb-3 pt-1">
{#each actions as action (action.label)}
<button
type="button"
disabled={action.disabled}
onclick={() => handle(action)}
class="flex w-full items-center gap-3 rounded-xl px-4 py-3 text-left text-base transition active:bg-gray-100 disabled:opacity-50 dark:active:bg-gray-700"
class:text-gray-900={action.tone !== 'danger'}
class:dark:text-gray-100={action.tone !== 'danger'}
class:text-red-600={action.tone === 'danger'}
class:dark:text-red-400={action.tone === 'danger'}
class:hover:bg-gray-50={!action.disabled}
class:dark:hover:bg-gray-800={!action.disabled}
>
{#if action.icon}
<span class="text-xl leading-none">{action.icon}</span>
{/if}
<span class="font-medium">{action.label}</span>
</button>
{/each}
<button
type="button"
onclick={onClose}
class="mt-2 w-full rounded-xl border border-gray-200 py-3 text-sm font-medium text-gray-600 transition hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800"
>
Abbrechen
</button>
</div>
</div>