Skip to content

feat(demo): persist the custom theme and let people copy it as code - #5

Merged
saifulapm merged 1 commit into
mainfrom
feat/theme-editor-persist-and-export
Sep 6, 2026
Merged

saifulapm merged 1 commit into
mainfrom
feat/theme-editor-persist-and-export

Conversation

@saifulapm

Copy link
Copy Markdown
Contributor

Follow-ups to the theme editor added in #4.

Settings survive a preset round-trip. The editor's state lived inside initCustomTheme, so every visit rebuilt the grid from a fresh random theme — switch to a preset, come back, and whatever you'd dialed in was gone. The theme and its input registry now sit at module scope, randomized once per page load, with the DOM built on first open only.

The theme can be copied out as code. A live defineTheme() snippet renders under the controls with a Copy button matching the install block. Snippet segments are [text, class] pairs, so the highlighted markup and the copied text come from one source rather than two that can drift.

Also widened the number boxes to 115px: 0.00402 is the longest value the sliders can produce and it clipped behind the number spinner at 100px.

Verified in Chromium

  • Settings preserved across preset round-trip, including manual edits
  • Repeated opens don't duplicate DOM (6 sliders / 8 labels / 2 groups after 4 opens)
  • Copied text is byte-identical to what's displayed
  • Emitted snippet parses (node --check), satisfies TiksTheme under tsc --strict, and round-trips through the real published defineTheme and plays
  • Earlier Added a custom theme editor to the demo page #4 fixes still hold: 0/20 loads with a desynced slider, no throws on empty/invalid input, all sounds clean

Two follow-ups to the theme editor from #4.

The editor's state lived inside initCustomTheme, so every visit rebuilt
the grid from a fresh random theme — switch to a preset, come back, and
whatever you had dialed in was gone. The theme and its input registry now
sit at module scope, randomized once per page load, and the DOM is built
on first open only. Reopening shows the theme you left.

The editor also had no way to get a theme back out, which is the main
reason to have one in a library demo. It now renders a live
defineTheme() snippet under the controls, with a Copy button matching the
install block. The snippet is generated as [text, class] segments, so the
highlighted markup and the copied text come from one source instead of
two that can drift.

Widened the number boxes to 115px — 0.00402 is the longest value the
sliders can produce and it clipped behind the spinner at 100px.
@saifulapm
saifulapm merged commit 806cab3 into main Sep 6, 2026
1 check passed
@saifulapm
saifulapm deleted the feat/theme-editor-persist-and-export branch September 6, 2026 06:27
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