From 6da5d48fbf32e49e1e184703421fcffc8b98349c Mon Sep 17 00:00:00 2001 From: Amir Husayn Panahifar Date: Tue, 25 Aug 2026 21:06:45 +0330 Subject: [PATCH] feat: add runtime dynamic theming from config --- src/styles.ts | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/styles.ts diff --git a/src/styles.ts b/src/styles.ts new file mode 100644 index 0000000..1d31d5c --- /dev/null +++ b/src/styles.ts @@ -0,0 +1,68 @@ +import command from "../config.json" assert { type: "json" }; + +(() => { + const style = document.createElement("style"); + const head = document.head; + const background = `body {background: ${command.colors.background}}`; + const foreground = `body {color: ${command.colors.foreground}}`; + const inputBackground = `input {background: ${command.colors.background}}`; + const inputForeground = `input {color: ${command.colors.prompt.input}}`; + const outputColor = `.output {color: ${command.colors.prompt.input}}`; + const preHost = `#pre-host {color: ${command.colors.prompt.host}}`; + const host = `#host {color: ${command.colors.prompt.host}}`; + const preUser = `#pre-user {color: ${command.colors.prompt.user}}`; + const user = `#user {color: ${command.colors.prompt.user}}`; + const prompt = `#prompt {color: ${command.colors.prompt.default}}`; + const banner = `pre {color: ${command.colors.banner}}`; + const link = `a {color: ${command.colors.link.text}}`; + const linkHighlight = `a:hover {background: ${command.colors.link.highlightColor}}`; + const linkTextHighlight = `a:hover {color: ${command.colors.link.highlightText}}`; + const commandHighlight = `.command {color: ${command.colors.commands.textColor}}`; + const keys = `.keys {color: ${command.colors.banner}}`; + + head.appendChild(style); + + if (!style.sheet) return; + + if (!command.colors.border.visible) { + style.sheet.insertRule("#bars {display: none}"); + style.sheet.insertRule("main {border: none}"); + } else { + style.sheet.insertRule(`#bars {background: ${command.colors.background}}`); + style.sheet.insertRule( + `main {border-color: ${command.colors.border.color}}` + ); + style.sheet.insertRule( + `#bar-1 {background: ${command.colors.border.color}; color: ${command.colors.background}}` + ); + style.sheet.insertRule( + `#bar-2 {background: ${command.colors.border.color}}` + ); + style.sheet.insertRule( + `#bar-3 {background: ${command.colors.border.color}}` + ); + style.sheet.insertRule( + `#bar-4 {background: ${command.colors.border.color}}` + ); + style.sheet.insertRule( + `#bar-5 {background: ${command.colors.border.color}}` + ); + } + + style.sheet.insertRule(background); + style.sheet.insertRule(foreground); + style.sheet.insertRule(inputBackground); + style.sheet.insertRule(inputForeground); + style.sheet.insertRule(outputColor); + style.sheet.insertRule(preHost); + style.sheet.insertRule(host); + style.sheet.insertRule(preUser); + style.sheet.insertRule(user); + style.sheet.insertRule(prompt); + style.sheet.insertRule(banner); + style.sheet.insertRule(link); + style.sheet.insertRule(linkHighlight); + style.sheet.insertRule(linkTextHighlight); + style.sheet.insertRule(commandHighlight); + style.sheet.insertRule(keys); +})();