1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/lib/services/style/themeToCss.ts
2023-07-16 17:42:42 +01:00

30 lines
888 B
TypeScript

import { Theme } from '../../themes/type';
const { camelCaseToDash, formatCssSize } = require('../../string-utils');
const isColor = (v: any) => {
return v && typeof v === 'object' && ('color' in v) && ('model' in v) && ('valpha' in v);
};
export default function(theme: Theme) {
const lines = [];
lines.push(':root {');
const names = Object.keys(theme).sort();
for (const name of names) {
const value = (theme as any)[name];
if (typeof value === 'object' && !isColor(value)) continue;
if (value === undefined || value === null) continue;
if (typeof value === 'number' && isNaN(value)) continue;
const newName = `--joplin-${camelCaseToDash(name)}`;
const formattedValue = typeof value === 'number' && newName.indexOf('opacity') < 0 ? formatCssSize(value) : value;
lines.push(`\t${newName}: ${formattedValue};`);
}
lines.push('}');
return lines.join('\n');
}