Skip to content

refactor: centralize FONT_WEIGHT_MAP in shared typography#142

Open
RedWilly wants to merge 1 commit intowalterlow:developfrom
RedWilly:motion
Open

refactor: centralize FONT_WEIGHT_MAP in shared typography#142
RedWilly wants to merge 1 commit intowalterlow:developfrom
RedWilly:motion

Conversation

@RedWilly
Copy link
Copy Markdown

@RedWilly RedWilly commented Mar 23, 2026

Removed duplicated FONT_WEIGHT_MAP definitions and switched composition runtime and export code to use the shared typography source of truth.

Summary by CodeRabbit

  • Refactor
    • Centralized typography configuration by consolidating font weight mappings into a shared module, reducing code duplication across the codebase.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 23, 2026

@RedWilly is attempting to deploy a commit to the walterlow's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b27ce3a4-a5d0-4399-90d9-9da30543c231

📥 Commits

Reviewing files that changed from the base of the PR and between bb972a0 and 3b063ea.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • src/features/composition-runtime/utils/text-layout.ts
  • src/features/export/utils/canvas-item-renderer.ts

📝 Walkthrough

Walkthrough

This change refactors duplicate FONT_WEIGHT_MAP constants from two files into a centralized shared module. Both text-layout.ts and canvas-item-renderer.ts now import the constant from @/shared/typography/fonts instead of maintaining local definitions.

Changes

Cohort / File(s) Summary
Font Weight Map Centralization
src/features/composition-runtime/utils/text-layout.ts, src/features/export/utils/canvas-item-renderer.ts
Removed duplicate FONT_WEIGHT_MAP constant definitions and replaced with shared imports from @/shared/typography/fonts. Both getTextRequiredHeight and renderTextItem now reference the centralized font weight mapping.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Hop, skip, and deduplicate we go,
One map to rule them all, you know!
No more scattered across the land,
Shared typography, neatly planned.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: centralize FONT_WEIGHT_MAP in shared typography' accurately and clearly summarizes the main change: moving duplicate FONT_WEIGHT_MAP definitions to a shared location.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 23, 2026

Greptile Summary

This PR eliminates duplicate FONT_WEIGHT_MAP definitions in text-layout.ts and canvas-item-renderer.ts, replacing them with a single import from the existing shared source of truth at @/shared/typography/fonts (ultimately font-loader.ts). The weight values (normal: 400, medium: 500, semibold: 600, bold: 700) are byte-for-byte identical to the removed copies, so runtime behavior is fully preserved.

  • src/features/composition-runtime/utils/text-layout.ts — local FONT_WEIGHT_MAP removed; now imported from @/shared/typography/fonts
  • src/features/export/utils/canvas-item-renderer.ts — local FONT_WEIGHT_MAP (which already had a comment saying it matched fonts.ts) removed; now imported from @/shared/typography/fonts
  • bun.lock — a new bun lockfile is included in this PR; it appears unrelated to the stated refactoring goal and could be a separate commit/PR concern
  • Note: src/features/composition-runtime/utils/fonts.ts still provides an intermediate re-export of FONT_WEIGHT_MAP for the composition-runtime feature, which could be a candidate for a follow-up cleanup

Confidence Score: 5/5

  • Safe to merge — the refactoring is a pure deduplication with no behavioral changes.
  • The removed local maps are identical to the shared source. Both consuming call sites (FONT_WEIGHT_MAP[item.fontWeight ?? 'normal'] ?? 400) remain unchanged. The only non-refactoring artifact is the addition of bun.lock, which is benign.
  • No files require special attention.

Important Files Changed

Filename Overview
src/features/composition-runtime/utils/text-layout.ts Removes the local FONT_WEIGHT_MAP definition and imports the shared version from @/shared/typography/fonts. Behavior is identical — values are unchanged.
src/features/export/utils/canvas-item-renderer.ts Removes the local FONT_WEIGHT_MAP definition (which had a comment noting it matched fonts.ts) and imports the canonical shared version. Usage at line 752 is unchanged.
bun.lock New bun lockfile added to the repository. This is unrelated to the FONT_WEIGHT_MAP refactoring described in the PR title and description.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["@/shared/typography/font-loader.ts\nFONT_WEIGHT_MAP (source of truth)"]
    B["@/shared/typography/fonts.ts\nre-exports FONT_WEIGHT_MAP"]
    C["composition-runtime/utils/fonts.ts\nre-exports as FONT_WEIGHT_MAP"]
    D["text-layout.ts\n(now imports from shared)"]
    E["canvas-item-renderer.ts\n(now imports from shared)"]
    F["text-content.tsx\n(imports via feature utils)"]
    G["text-section.tsx\n(imports from shared)"]

    A --> B
    B --> D
    B --> E
    B --> C
    B --> G
    C --> F
Loading

Reviews (1): Last reviewed commit: "refactor: centralize FONT_WEIGHT_MAP in ..." | Re-trigger Greptile

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