2021-09-06 17:57:07 +02:00
|
|
|
import { Theme } from '../../themes/type';
|
|
|
|
const { camelCaseToDash, formatCssSize } = require('../../string-utils');
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-07-16 18:42:42 +02:00
|
|
|
const isColor = (v: any) => {
|
|
|
|
return v && typeof v === 'object' && ('color' in v) && ('model' in v) && ('valpha' in v);
|
|
|
|
};
|
2021-09-06 17:57:07 +02:00
|
|
|
|
|
|
|
export default function(theme: Theme) {
|
|
|
|
const lines = [];
|
|
|
|
lines.push(':root {');
|
|
|
|
|
2023-07-16 18:42:42 +02:00
|
|
|
const names = Object.keys(theme).sort();
|
|
|
|
|
|
|
|
for (const name of names) {
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2021-09-06 17:57:07 +02:00
|
|
|
const value = (theme as any)[name];
|
2023-07-16 18:42:42 +02:00
|
|
|
|
|
|
|
if (typeof value === 'object' && !isColor(value)) continue;
|
|
|
|
if (value === undefined || value === null) continue;
|
|
|
|
if (typeof value === 'number' && isNaN(value)) continue;
|
|
|
|
|
2021-09-06 17:57:07 +02:00
|
|
|
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');
|
|
|
|
}
|