From 8ce5366e80176e94f636e569eca726fafc7024fc Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 29 Mar 2020 16:09:44 +0900 Subject: テーマ関係 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/theme.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/client') diff --git a/src/client/theme.ts b/src/client/theme.ts index cc69ee4060..2f4920e3af 100644 --- a/src/client/theme.ts +++ b/src/client/theme.ts @@ -27,7 +27,7 @@ export const builtinThemes = [ require('./themes/danboard.json5'), require('./themes/olive.json5'), require('./themes/tweetdeck.json5'), -]; +] as Theme[]; let timeout = null; @@ -66,16 +66,21 @@ export function applyTheme(theme: Theme, persist = true) { } } -function compile(theme: Theme): { [key: string]: string } { - function getColor(code: string): tinycolor.Instance { - // ref - if (code[0] == '@') { - return getColor(theme.props[code.substr(1)]); +function compile(theme: Theme): Record { + function getColor(val: string): tinycolor.Instance { + // ref (prop) + if (val[0] === '@') { + return getColor(theme.props[val.substr(1)]); + } + + // ref (const) + else if (val[0] === '$') { + return getColor(theme.props[val]); } // func - if (code[0] == ':') { - const parts = code.split('<'); + else if (val[0] === ':') { + const parts = val.split('<'); const func = parts.shift().substr(1); const arg = parseFloat(parts.shift()); const color = getColor(parts.join('<')); @@ -87,12 +92,15 @@ function compile(theme: Theme): { [key: string]: string } { } } - return tinycolor(code); + // other case + return tinycolor(val); } const props = {}; for (const [k, v] of Object.entries(theme.props)) { + if (k.startsWith('$')) continue; // ignore const + props[k] = genValue(getColor(v)); } -- cgit v1.2.3-freya