Skip to content

feat(feed): Phase 0 — foundations (types, NIP-92 imeta parser, blurhash decoder)#396

Merged
spe1020 merged 1 commit into
zapcooking:mainfrom
dmnyc:feat/feed-foundations
May 15, 2026
Merged

feat(feed): Phase 0 — foundations (types, NIP-92 imeta parser, blurhash decoder)#396
spe1020 merged 1 commit into
zapcooking:mainfrom
dmnyc:feat/feed-foundations

Conversation

@dmnyc
Copy link
Copy Markdown
Collaborator

@dmnyc dmnyc commented May 14, 2026

Summary

Phase 0 of the planned feed overhaul. Lays down the type and parsing primitives that subsequent phases depend on, with no production wiring and no runtime side-effects. Nothing is visible to users in this PR.

See `/Users/daniel/.claude/plans/cached-waddling-treasure.md` for the full overhaul plan (8 phases). This is the smallest, safest first slice.

What's new

  • `src/lib/feed/types.ts` — view-model types (`FeedNoteVM`, `MediaItem`, `RepostVM`, `EmbedVM`, `FeedTab`, `FeedCursor`, `FeedSourceState`). Framework-free. Always recomputed from cached `NDKEvent`s on read — no IndexedDB schema changes, so warm caches in production aren't invalidated.
  • `src/lib/feed/imeta.ts` — NIP-92 `imeta` tag parser (`parseImeta`, `isImageUrl`, `isVideoUrl`). Reads `url`, `m`, `dim`, `blurhash`, `alt`, `x`, `fallback` slots. When no `imeta` tags are present, falls back to scanning `event.content` for raw image/video URLs using the same hostname + extension heuristics `NoteContent.svelte` uses today — so fallback-path media lists exactly match the current feed.
  • `src/lib/feed/blurhash.ts` — hand-ported canonical blurhash decoder (~200 LOC) instead of the `blurhash` npm dep. Exports `isValidBlurhash`, `decodeBlurhash` (pixel buffer), and `blurhashToDataUrl` (PNG data URL via canvas). SSR-safe: returns `null` when no canvas is available, so callers paint a solid `--color-bg-secondary` tile.
  • `src/lib/feed/imeta.test.ts` (20 tests) + `src/lib/feed/blurhash.test.ts` (11 tests).

Test plan

  • `pnpm test src/lib/feed/` — 31/31 tests pass.
  • `pnpm check` / `tsc --noEmit` — clean.
  • `pnpm build` on Vercel preview — should succeed identically to main (no production paths touched).

What's NOT in this PR

  • No component changes.
  • No `/community` or `/[nip19]` route changes.
  • No new IndexedDB tables or schema bumps.
  • No new bundle-size contribution to production routes (the new module is unimported by anything user-facing yet).

The Phase 1 PR (`feat/feed-media-gallery`) will be the first user-visible step — adding the gallery grid + Lightbox components behind a dev-only demo route.

…hash decoder

Phase 0 of the feed overhaul. New `src/lib/feed/` module with no
runtime side-effects, no production wiring; everything downstream
phases need is in place.

- types.ts: FeedNoteVM, MediaItem, RepostVM, EmbedVM, FeedTab,
  FeedCursor, FeedSourceState. Framework-free; will be recomputed
  from cached NDK events on read (no IndexedDB schema impact).
- imeta.ts: parseImeta(event) reads NIP-92 imeta tags (url, m, dim,
  blurhash, alt, x, fallback) and falls back to URL extraction from
  event.content when no imeta tags are present. Mirrors the
  hostname + extension heuristics used by NoteContent.svelte so the
  fallback path produces the same media list the current feed does.
- blurhash.ts: hand-ported canonical blurhash decoder (~200 LOC) so
  we don't pull the npm dep. Exports isValidBlurhash, decodeBlurhash
  (pixel buffer), and blurhashToDataUrl (PNG data URL via canvas).
  SSR-safe — returns null when no canvas is available so callers
  paint a solid bg-secondary tile instead.
- imeta.test.ts (20 tests) + blurhash.test.ts (11 tests): covers
  empty events, single/multiple imeta tags, mime inference, fallback
  splitting, dim parsing edge cases, URL extraction dedupe, and
  decoder validity / range guarantees.

All 31 tests pass; `pnpm check` and `tsc --noEmit` are clean.
@dmnyc dmnyc marked this pull request as draft May 14, 2026 16:12
@spe1020 spe1020 marked this pull request as ready for review May 15, 2026 11:02
@spe1020 spe1020 merged commit 3874555 into zapcooking:main May 15, 2026
1 check passed
@dmnyc dmnyc deleted the feat/feed-foundations branch May 16, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants