Skip to content

refactor: dedupe alias resolution, quote-stripping, error messages, and attribution drawing - #77

Merged
otnc merged 5 commits into
mainfrom
refactor/dedupe-alias-resolution-and-drawing
Aug 29, 2026
Merged

refactor: dedupe alias resolution, quote-stripping, error messages, and attribution drawing#77
otnc merged 5 commits into
mainfrom
refactor/dedupe-alias-resolution-and-drawing

Conversation

@otnc

@otnc otnc commented Aug 29, 2026

Copy link
Copy Markdown
Owner

What does this change?

Four independent dedup/cleanup passes found during a codebase review, each its own commit. Pure extractions — no behavior change, confirmed by the existing (including pixel-comparing) test suite passing unchanged throughout.

  1. errorMessage(cause): cause instanceof Error ? cause.message : String(cause) was repeated verbatim at 10 call sites across 4 files.
  2. normalizeFontFamily() / unquoteFontFamily(): resolveFontAlias(x) ?? x (7 sites) and the quote-stripping regex for a CSS font-family token (3 sites, including one in pipeline.ts the original review missed) were each duplicated identically.
  3. util/aliasCatalogue.ts: font/catalogue.ts's FONT_ALIASES/CATALOGUE_BY_LOWERCASE and theme/colorThemes.ts's COLOR_THEME_ALIASES/KEYS_BY_NORMALIZED built the same two maps from the same {key, alias} row shape — one inline, one as its own function. Shared via accessor functions so each caller's row shape and normalization (they differ subtly) stay exactly as they were; resolveFontAlias()/resolveColorTheme() themselves are untouched.
  4. drawAttributionLine(): pipeline.ts's drawAttribution() did the same five-step draw (resolve size, set font/fill style, draw prefixed text, advance y) for both displayName and username — they share the exact same LabelTheme type.

Checklist

  • npm run ci passes (Biome lint and format)
  • npm run typecheck passes
  • npm run test passes
  • npm run build && npm run check:build passes
  • Tests cover the change
  • README updated, if the public API changed

otnc added 5 commits August 29, 2026 20:52
cause instanceof Error ? cause.message : String(cause) was repeated
verbatim across 10 call sites in 4 files. Pulled into a single
util/errorMessage.ts, with a small test of its own.
…tripping idioms

resolveFontAlias(x) ?? x was repeated at 7 call sites across autoload.ts,
catalogue.ts, googleFonts.ts and install.ts; pulled into
normalizeFontFamily(). part.trim().replace(/^["']|["']$/g, '') for a single
CSS font-family token was duplicated identically in catalogue.ts,
registry.ts and pipeline.ts; pulled into unquoteFontFamily(), both now
exported from font/catalogue.ts alongside resolveFontAlias itself.

Pure extraction, no behavior change.
…themes

font/catalogue.ts's FONT_ALIASES and theme/colorThemes.ts's
COLOR_THEME_ALIASES/CUSTOM_COLOR_THEME_ALIASES built the same alias -> key
record from a list of {key, alias} rows — one as an inline IIFE, the other
as its own aliasMap() function. Likewise CATALOGUE_BY_LOWERCASE and
KEYS_BY_NORMALIZED both built a Map<normalize(key), key> from the same kind
of rows, just with different normalize functions.

Pulled both into util/aliasCatalogue.ts as buildAliasMap/buildNormalizedKeyMap,
taking accessor functions so each caller's row shape and normalization stay
exactly as they were. resolveFontAlias() and resolveColorTheme() themselves
are untouched — colorThemes.ts's resolveColorTheme() normalizes an alias
lookup differently than a key lookup (stripping underscores only for the
latter), a real difference this doesn't collapse, just the identical
map-building boilerplate around it.
Both branches of drawAttribution did the same five steps on a LabelTheme
(displayName and username share that exact type) — resolve the pixel size,
set font and fill style, draw the prefixed text centred, advance y by the
size — differing only in which theme field and which text. Pulled into
drawAttributionLine(), which returns the y its own baseline landed on so
displayName's caller can still add the extra gap before username.

Pixel-comparing pipeline tests (draws something in the text area, etc.) all
still pass, confirming identical rendered output.
…-resolution-and-drawing

# Conflicts:
#	src/cli/commands.ts
@otnc
otnc merged commit b1754a3 into main Aug 29, 2026
7 checks passed
@otnc
otnc deleted the refactor/dedupe-alias-resolution-and-drawing branch August 29, 2026 12:25
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.

1 participant