feat: add runtime theme tweaks

Draft
KI
2mo ago
+3996-19

Status

Draft and stacked on #476. This restores the work from the original PR #241 so it can continue being developed independently before merging.

Scope

  • Runtime theme tweak configuration and UI.
  • Framework bundle and adapter integration.
  • Related exports, styles, examples, and tests from the original change.

History

The original PR was reverted by #474 because it was not ready to ship. This branch reproduces the original PR tree exactly when combined with #476, without unrelated changes.

Merge order

Merge #476 first. Then retarget this PR to main, update it, and complete its review.


Summary by cubic

Adds an opt‑in runtime “Tweaks” dialog to docs so readers can adjust preset, accent, density, radius, and font, and authors can adjust all tokens and export a createTheme({...}) snippet. Selections persist in localStorage and reapply pre‑paint to avoid FOUC; nothing changes unless enabled.

  • Opt in via defineDocs as tweaks: { reader: true, author: process.env.NODE_ENV !== 'production', position?: 'sidebar' | 'floating' | 'both' }. Defaults off.
  • Integrates in layout by mounting TweaksControl/TweaksAutoPortalTrigger and injecting a pre‑paint script from buildFoucScript(); adds tweaks.css to base styles.
  • Exposes types and components: TweaksConfig in @farming-labs/docs; TweaksAutoPortalTrigger, TweaksControl, and triggers in @farming-labs/fumadocs; new subpath export @farming-labs/fumadocs/tweaks.
  • Main review focus: packages/fumadocs/src/tweaks-runtime.ts (persistence, FOUC prevention) and packages/fumadocs/src/tweaks-dialog.tsx (UI, token application). Examples enable tweaks for local dev.