2020-09-15 15:01:07 +02:00
|
|
|
import { Theme } from './themes/type';
|
|
|
|
|
|
|
|
import theme_light from './themes/light';
|
|
|
|
import theme_dark from './themes/dark';
|
|
|
|
import theme_dracula from './themes/dracula';
|
|
|
|
import theme_solarizedLight from './themes/solarizedLight';
|
|
|
|
import theme_solarizedDark from './themes/solarizedDark';
|
|
|
|
import theme_nord from './themes/nord';
|
|
|
|
import theme_aritimDark from './themes/aritimDark';
|
|
|
|
import theme_oledDark from './themes/oledDark';
|
2020-10-21 01:23:55 +02:00
|
|
|
import Setting from 'lib/models/Setting';
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-05-02 17:41:07 +02:00
|
|
|
const Color = require('color');
|
2020-04-07 10:19:53 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const themes:any = {
|
|
|
|
[Setting.THEME_LIGHT]: theme_light,
|
|
|
|
[Setting.THEME_DARK]: theme_dark,
|
|
|
|
[Setting.THEME_DRACULA]: theme_dracula,
|
|
|
|
[Setting.THEME_SOLARIZED_LIGHT]: theme_solarizedLight,
|
|
|
|
[Setting.THEME_SOLARIZED_DARK]: theme_solarizedDark,
|
|
|
|
[Setting.THEME_NORD]: theme_nord,
|
|
|
|
[Setting.THEME_ARITIM_DARK]: theme_aritimDark,
|
|
|
|
[Setting.THEME_OLED_DARK]: theme_oledDark,
|
2020-04-07 10:19:53 +02:00
|
|
|
};
|
2017-11-06 22:54:58 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
function themeById(themeId:string) {
|
2020-06-10 23:08:59 +02:00
|
|
|
if (!themes[themeId]) throw new Error(`Invalid theme ID: ${themeId}`);
|
|
|
|
const output = Object.assign({}, themes[themeId]);
|
|
|
|
|
|
|
|
if (!output.headerBackgroundColor) {
|
|
|
|
output.headerBackgroundColor = output.appearance === 'light' ? '#F0F0F0' : '#2D3136';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!output.textSelectionColor) {
|
|
|
|
output.textSelectionColor = output.appearance === 'light' ? '#0096FF' : '#00AEFF';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!output.colorBright2) {
|
|
|
|
output.colorBright2 = output.appearance === 'light' ? '#ffffff' : '#ffffff';
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:37:13 +02:00
|
|
|
// globalStyle should be used for properties that do not change across themes
|
|
|
|
// i.e. should not be used for colors
|
2020-09-15 15:01:07 +02:00
|
|
|
const globalStyle:any = {
|
|
|
|
fontFamily: 'Roboto',// 'sans-serif',
|
2017-11-06 22:54:58 +02:00
|
|
|
margin: 15, // No text and no interactive component should be within this margin
|
|
|
|
itemMarginTop: 10,
|
|
|
|
itemMarginBottom: 10,
|
|
|
|
disabledOpacity: 0.3,
|
2017-11-08 19:51:55 +02:00
|
|
|
buttonMinWidth: 50,
|
|
|
|
buttonMinHeight: 30,
|
2019-01-10 20:34:58 +02:00
|
|
|
editorFontSize: 12,
|
|
|
|
textAreaLineHeight: 17,
|
2020-06-10 23:08:59 +02:00
|
|
|
lineHeight: '1.6em',
|
2017-11-09 00:23:26 +02:00
|
|
|
headerButtonHPadding: 6,
|
2020-09-15 15:01:07 +02:00
|
|
|
toolbarHeight: 26,
|
|
|
|
toolbarPadding: 6,
|
2020-05-17 16:34:42 +02:00
|
|
|
appearance: 'light',
|
2020-09-15 15:01:07 +02:00
|
|
|
mainPadding: 12,
|
|
|
|
topRowHeight: 50,
|
2017-11-06 22:54:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
globalStyle.marginRight = globalStyle.margin;
|
|
|
|
globalStyle.marginLeft = globalStyle.margin;
|
|
|
|
globalStyle.marginTop = globalStyle.margin;
|
|
|
|
globalStyle.marginBottom = globalStyle.margin;
|
|
|
|
|
|
|
|
globalStyle.icon = {
|
|
|
|
fontSize: 30,
|
|
|
|
};
|
|
|
|
|
|
|
|
globalStyle.lineInput = {
|
2018-03-26 19:33:55 +02:00
|
|
|
fontFamily: globalStyle.fontFamily,
|
2019-05-06 22:35:29 +02:00
|
|
|
maxHeight: 22,
|
|
|
|
height: 22,
|
|
|
|
paddingLeft: 5,
|
2017-11-06 22:54:58 +02:00
|
|
|
};
|
|
|
|
|
2019-01-28 01:15:56 +02:00
|
|
|
globalStyle.headerStyle = {
|
|
|
|
fontFamily: globalStyle.fontFamily,
|
|
|
|
};
|
2018-11-08 00:37:13 +02:00
|
|
|
|
|
|
|
globalStyle.inputStyle = {
|
|
|
|
border: '1px solid',
|
2019-04-01 21:43:13 +02:00
|
|
|
height: 24,
|
2019-05-06 22:35:29 +02:00
|
|
|
maxHeight: 24,
|
2019-04-01 21:43:13 +02:00
|
|
|
paddingLeft: 5,
|
|
|
|
paddingRight: 5,
|
|
|
|
boxSizing: 'border-box',
|
2018-11-08 00:37:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
globalStyle.containerStyle = {
|
|
|
|
overflow: 'auto',
|
|
|
|
overflowY: 'auto',
|
|
|
|
};
|
|
|
|
|
|
|
|
globalStyle.buttonStyle = {
|
2019-05-06 22:35:29 +02:00
|
|
|
// marginRight: 10,
|
2018-11-08 00:37:13 +02:00
|
|
|
border: '1px solid',
|
2019-05-06 22:35:29 +02:00
|
|
|
minHeight: 26,
|
2019-01-28 01:44:16 +02:00
|
|
|
minWidth: 80,
|
2020-03-13 19:42:50 +02:00
|
|
|
// maxWidth: 220,
|
2019-01-29 20:02:34 +02:00
|
|
|
paddingLeft: 12,
|
|
|
|
paddingRight: 12,
|
2019-09-11 01:53:01 +02:00
|
|
|
paddingTop: 6,
|
|
|
|
paddingBottom: 6,
|
2020-09-15 15:01:07 +02:00
|
|
|
// boxShadow: '0px 1px 1px rgba(0,0,0,0.3)',
|
2019-09-11 01:53:01 +02:00
|
|
|
fontSize: globalStyle.fontSize,
|
|
|
|
borderRadius: 4,
|
2018-11-08 00:37:13 +02:00
|
|
|
};
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
function addMissingProperties(theme:Theme) {
|
|
|
|
// if (!('backgroundColor3' in theme)) theme.backgroundColor3 = theme.backgroundColor;
|
|
|
|
// if (!('color3' in theme)) theme.color3 = theme.color;
|
|
|
|
// if (!('selectionBackgroundColor3' in theme)) {
|
|
|
|
// if (theme.appearance === 'dark') {
|
|
|
|
// theme.selectionBackgroundColor3 = '#ffffff77';
|
|
|
|
// } else {
|
|
|
|
// theme.selectionBackgroundColor3 = '#00000077';
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if (!('backgroundColorHover3' in theme)) theme.backgroundColorHover3 = Color(theme.selectionBackgroundColor3).alpha(0.5).rgb();
|
|
|
|
// if (!('selectionBorderColor3' in theme)) theme.selectionBorderColor3 = theme.backgroundColor3;
|
|
|
|
|
|
|
|
// TODO: pick base theme based on appearence
|
|
|
|
|
|
|
|
// const lightTheme = themes[Setting.THEME_LIGHT];
|
|
|
|
|
|
|
|
// for (const n in lightTheme) {
|
|
|
|
// if (!(n in theme)) theme[n] = lightTheme[n];
|
|
|
|
// }
|
|
|
|
|
|
|
|
return theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addExtraStyles(style:any) {
|
2020-05-02 17:41:07 +02:00
|
|
|
style.selectedDividerColor = Color(style.dividerColor).darken(0.2).hex();
|
2020-05-17 16:34:42 +02:00
|
|
|
style.iconColor = Color(style.color).alpha(0.8);
|
2020-05-02 17:41:07 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
style.colorFaded2 = Color(style.color2).alpha(0.5).rgb();
|
|
|
|
style.colorHover2 = Color(style.color2).alpha(0.7).rgb();
|
|
|
|
style.colorActive2 = Color(style.color2).alpha(0.9).rgb();
|
|
|
|
|
|
|
|
style.backgroundColorHoverDim3 = Color(style.backgroundColorHover3).alpha(0.3).rgb();
|
|
|
|
style.backgroundColorActive3 = Color(style.backgroundColorHover3).alpha(0.5).rgb();
|
|
|
|
|
|
|
|
const bgColor4 = style.backgroundColor4;
|
|
|
|
|
|
|
|
style.backgroundColorHover2 = Color(style.selectedColor2).alpha(0.4).rgb();
|
|
|
|
|
|
|
|
style.backgroundColorHover4 = Color(style.backgroundColorHover3).alpha(0.3).rgb();
|
|
|
|
style.backgroundColorActive4 = Color(style.backgroundColorHover3).alpha(0.8).rgb();
|
|
|
|
style.borderColor4 = Color(style.color).alpha(0.3);
|
|
|
|
style.backgroundColor4 = bgColor4;
|
|
|
|
|
|
|
|
style.color5 = bgColor4;
|
|
|
|
style.backgroundColor5 = style.color4;
|
|
|
|
style.backgroundColorHover5 = Color(style.backgroundColor5).darken(0.2).hex();
|
|
|
|
style.backgroundColorActive5 = Color(style.backgroundColor5).darken(0.4).hex();
|
|
|
|
|
|
|
|
style.configScreenPadding = style.mainPadding * 2;
|
|
|
|
|
|
|
|
style.icon = Object.assign({},
|
|
|
|
style.icon,
|
|
|
|
{ color: style.color }
|
|
|
|
);
|
|
|
|
|
|
|
|
style.lineInput = Object.assign({},
|
|
|
|
style.lineInput,
|
|
|
|
{
|
|
|
|
color: style.color,
|
|
|
|
backgroundColor: style.backgroundColor,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
style.headerStyle = Object.assign({},
|
|
|
|
style.headerStyle,
|
|
|
|
{
|
|
|
|
color: style.color,
|
|
|
|
backgroundColor: style.backgroundColor,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
style.inputStyle = Object.assign({},
|
|
|
|
style.inputStyle,
|
|
|
|
{
|
|
|
|
color: style.color,
|
|
|
|
backgroundColor: style.backgroundColor,
|
|
|
|
borderColor: style.dividerColor,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
style.containerStyle = Object.assign({},
|
|
|
|
style.containerStyle,
|
|
|
|
{
|
|
|
|
color: style.color,
|
|
|
|
backgroundColor: style.backgroundColor,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
style.buttonStyle = Object.assign({},
|
|
|
|
style.buttonStyle,
|
|
|
|
{
|
|
|
|
color: style.color4,
|
|
|
|
backgroundColor: style.backgroundColor4,
|
|
|
|
borderColor: style.borderColor4,
|
|
|
|
userSelect: 'none',
|
|
|
|
cursor: 'pointer',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-11-08 00:47:34 +02:00
|
|
|
style.tagStyle = {
|
|
|
|
fontSize: style.fontSize,
|
|
|
|
fontFamily: style.fontFamily,
|
2020-09-15 15:01:07 +02:00
|
|
|
paddingTop: 4,
|
|
|
|
paddingBottom: 4,
|
|
|
|
paddingRight: 10,
|
|
|
|
paddingLeft: 10,
|
|
|
|
backgroundColor: style.backgroundColor3,
|
|
|
|
color: style.color3,
|
2020-05-02 17:41:07 +02:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2020-09-15 15:01:07 +02:00
|
|
|
marginRight: 8,
|
|
|
|
borderRadius: 100,
|
2018-11-08 00:47:34 +02:00
|
|
|
};
|
|
|
|
|
2019-01-10 20:34:58 +02:00
|
|
|
style.toolbarStyle = {
|
|
|
|
height: style.toolbarHeight,
|
2020-05-04 02:14:28 +02:00
|
|
|
minWidth: style.toolbarHeight,
|
2019-01-10 20:34:58 +02:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingLeft: style.headerButtonHPadding,
|
|
|
|
paddingRight: style.headerButtonHPadding,
|
|
|
|
textDecoration: 'none',
|
|
|
|
fontFamily: style.fontFamily,
|
|
|
|
fontSize: style.fontSize,
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
cursor: 'default',
|
|
|
|
justifyContent: 'center',
|
|
|
|
color: style.color,
|
2019-03-15 23:57:58 +02:00
|
|
|
whiteSpace: 'nowrap',
|
2019-01-10 20:34:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
style.textStyle = {
|
|
|
|
fontFamily: globalStyle.fontFamily,
|
|
|
|
fontSize: style.fontSize,
|
|
|
|
lineHeight: '1.6em',
|
2019-07-30 09:35:42 +02:00
|
|
|
color: style.color,
|
2019-01-10 20:34:58 +02:00
|
|
|
};
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
style.clickableTextStyle = Object.assign({}, style.textStyle, {
|
|
|
|
userSelect: 'none',
|
|
|
|
});
|
|
|
|
|
2019-01-10 20:34:58 +02:00
|
|
|
style.textStyle2 = Object.assign({}, style.textStyle,
|
2020-08-05 00:00:11 +02:00
|
|
|
{ color: style.color2 }
|
2019-01-10 20:34:58 +02:00
|
|
|
);
|
|
|
|
|
2020-04-02 19:16:11 +02:00
|
|
|
style.textStyleMinor = Object.assign({}, style.textStyle,
|
|
|
|
{
|
|
|
|
color: style.colorFaded,
|
|
|
|
fontSize: style.fontSize * 0.8,
|
2020-08-05 00:00:11 +02:00
|
|
|
}
|
2020-04-02 19:16:11 +02:00
|
|
|
);
|
|
|
|
|
2019-01-10 20:34:58 +02:00
|
|
|
style.urlStyle = Object.assign({}, style.textStyle,
|
|
|
|
{
|
|
|
|
textDecoration: 'underline',
|
2019-07-30 09:35:42 +02:00
|
|
|
color: style.urlColor,
|
2020-08-05 00:00:11 +02:00
|
|
|
}
|
2019-01-10 20:34:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
style.h1Style = Object.assign({},
|
|
|
|
style.textStyle,
|
|
|
|
{
|
|
|
|
color: style.color,
|
|
|
|
fontSize: style.textStyle.fontSize * 1.5,
|
2019-07-30 09:35:42 +02:00
|
|
|
fontWeight: 'bold',
|
2020-08-05 00:00:11 +02:00
|
|
|
}
|
2019-01-10 20:34:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
style.h2Style = Object.assign({},
|
|
|
|
style.textStyle,
|
|
|
|
{
|
|
|
|
color: style.color,
|
|
|
|
fontSize: style.textStyle.fontSize * 1.3,
|
2019-07-30 09:35:42 +02:00
|
|
|
fontWeight: 'bold',
|
2020-08-05 00:00:11 +02:00
|
|
|
}
|
2019-01-10 20:34:58 +02:00
|
|
|
);
|
|
|
|
|
2019-04-01 21:43:13 +02:00
|
|
|
style.dialogModalLayer = {
|
|
|
|
zIndex: 9999,
|
|
|
|
display: 'flex',
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
|
|
alignItems: 'flex-start',
|
|
|
|
justifyContent: 'center',
|
|
|
|
};
|
|
|
|
|
2020-02-25 11:43:31 +02:00
|
|
|
style.controlBox = {
|
|
|
|
marginBottom: '1em',
|
|
|
|
color: 'black', // This will apply for the calendar
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
};
|
|
|
|
|
|
|
|
style.controlBoxLabel = {
|
|
|
|
marginRight: '1em',
|
|
|
|
width: '10em',
|
|
|
|
display: 'inline-block',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
};
|
|
|
|
|
|
|
|
style.controlBoxValue = {
|
|
|
|
display: 'inline-block',
|
|
|
|
};
|
|
|
|
|
2019-04-01 21:43:13 +02:00
|
|
|
style.dialogBox = {
|
|
|
|
backgroundColor: style.backgroundColor,
|
|
|
|
padding: 16,
|
|
|
|
boxShadow: '6px 6px 20px rgba(0,0,0,0.5)',
|
|
|
|
marginTop: 20,
|
2020-04-22 00:57:04 +02:00
|
|
|
maxHeight: '80%',
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2019-04-01 21:43:13 +02:00
|
|
|
|
2019-07-21 17:49:53 +02:00
|
|
|
style.buttonIconStyle = {
|
2020-05-17 16:34:42 +02:00
|
|
|
color: style.iconColor,
|
2019-07-21 17:49:53 +02:00
|
|
|
marginRight: 6,
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2019-07-21 17:49:53 +02:00
|
|
|
|
2020-04-08 12:12:25 +02:00
|
|
|
style.notificationBox = {
|
|
|
|
backgroundColor: style.warningBackgroundColor,
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
padding: 10,
|
|
|
|
fontSize: style.fontSize,
|
|
|
|
};
|
|
|
|
|
2019-04-01 21:43:13 +02:00
|
|
|
style.dialogTitle = Object.assign({}, style.h1Style, { marginBottom: '1.2em' });
|
|
|
|
|
2019-05-06 22:35:29 +02:00
|
|
|
style.dropdownList = Object.assign({}, style.inputStyle);
|
|
|
|
|
2020-04-03 20:12:14 +02:00
|
|
|
style.colorHover = style.color;
|
|
|
|
style.backgroundHover = `${style.selectedColor2}44`;
|
|
|
|
|
2019-09-11 01:53:01 +02:00
|
|
|
// In general the highlighted color, used to highlight text or icons, should be the same as selectedColor2
|
|
|
|
// but some times, depending on the theme, it might be too dark or too light, so it can be
|
|
|
|
// specified directly by the theme too.
|
|
|
|
if (!style.highlightedColor) style.highlightedColor = style.selectedColor2;
|
|
|
|
|
2018-11-08 00:47:34 +02:00
|
|
|
return style;
|
|
|
|
}
|
2018-11-08 00:16:05 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const themeCache_:any = {};
|
2017-11-06 22:54:58 +02:00
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
function themeStyle(themeId:number) {
|
|
|
|
if (!themeId) throw new Error('Theme must be specified');
|
2019-01-10 20:34:58 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const zoomRatio = 1; // Setting.value('style.zoom') / 100;
|
|
|
|
const editorFontSize = Setting.value('style.editor.fontSize');
|
2019-01-10 20:34:58 +02:00
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
const cacheKey = [themeId, zoomRatio, editorFontSize].join('-');
|
2019-01-10 20:34:58 +02:00
|
|
|
if (themeCache_[cacheKey]) return themeCache_[cacheKey];
|
|
|
|
|
2019-06-06 00:11:18 +02:00
|
|
|
// Font size are not theme specific, but they must be referenced
|
|
|
|
// and computed here to allow them to respond to settings changes
|
|
|
|
// without the need to restart
|
2020-09-15 15:01:07 +02:00
|
|
|
const fontSizes:any = {
|
2020-06-10 23:08:59 +02:00
|
|
|
fontSize: Math.round(12 * zoomRatio),
|
2020-09-15 15:01:07 +02:00
|
|
|
toolbarIconSize: 16,
|
2019-01-10 20:34:58 +02:00
|
|
|
editorFontSize: editorFontSize,
|
2019-06-06 00:11:18 +02:00
|
|
|
textAreaLineHeight: Math.round(globalStyle.textAreaLineHeight * editorFontSize / 12),
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2017-11-06 22:54:58 +02:00
|
|
|
|
2020-06-10 23:08:59 +02:00
|
|
|
fontSizes.noteViewerFontSize = Math.round(fontSizes.fontSize * 1.25);
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
let output:any = {};
|
2019-01-10 20:34:58 +02:00
|
|
|
output.zoomRatio = zoomRatio;
|
2019-07-29 12:05:58 +02:00
|
|
|
|
|
|
|
// All theme are based on the light style, and just override the
|
|
|
|
// relevant properties
|
2020-10-21 01:23:55 +02:00
|
|
|
output = Object.assign({}, globalStyle, fontSizes, themes[themeId]);
|
2020-09-15 15:01:07 +02:00
|
|
|
output = addMissingProperties(output);
|
2018-11-08 00:47:34 +02:00
|
|
|
output = addExtraStyles(output);
|
2020-10-21 01:23:55 +02:00
|
|
|
output.cacheKey = cacheKey;
|
2018-11-08 00:47:34 +02:00
|
|
|
|
2019-01-10 20:34:58 +02:00
|
|
|
themeCache_[cacheKey] = output;
|
|
|
|
return themeCache_[cacheKey];
|
2017-11-06 22:54:58 +02:00
|
|
|
}
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const cachedStyles_:any = {
|
2020-07-14 21:17:25 +02:00
|
|
|
themeId: null,
|
|
|
|
styles: {},
|
|
|
|
};
|
2019-12-13 03:16:34 +02:00
|
|
|
|
2020-07-14 21:17:25 +02:00
|
|
|
// cacheKey must be a globally unique key, and must change whenever
|
|
|
|
// the dependencies of the style change. If the style depends only
|
|
|
|
// on the theme, a static string can be provided as a cache key.
|
2020-10-21 01:23:55 +02:00
|
|
|
function buildStyle(cacheKey:any, themeId:number, callback:Function) {
|
2020-07-23 00:26:45 +02:00
|
|
|
cacheKey = Array.isArray(cacheKey) ? cacheKey.join('_') : cacheKey;
|
|
|
|
|
2020-07-14 21:17:25 +02:00
|
|
|
// We clear the cache whenever switching themes
|
|
|
|
if (cachedStyles_.themeId !== themeId) {
|
|
|
|
cachedStyles_.themeId = themeId;
|
|
|
|
cachedStyles_.styles = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cachedStyles_.styles[cacheKey]) return cachedStyles_.styles[cacheKey].style;
|
2019-12-13 03:16:34 +02:00
|
|
|
|
|
|
|
const s = callback(themeStyle(themeId));
|
|
|
|
|
2020-07-14 21:17:25 +02:00
|
|
|
cachedStyles_.styles[cacheKey] = {
|
2019-12-13 03:16:34 +02:00
|
|
|
style: s,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
};
|
|
|
|
|
2020-07-14 21:17:25 +02:00
|
|
|
return cachedStyles_.styles[cacheKey].style;
|
2019-12-13 03:16:34 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
export { themeStyle, buildStyle, themeById };
|