一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
30 行
978 B
TypeScript
30 行
978 B
TypeScript
import { Theme } from '../../themes/type';
|
|
import { camelCaseToDash, formatCssSize } from '../../string-utils';
|
|
|
|
const isColor = (v: unknown): v is { color: unknown; model: unknown; valpha: unknown } => {
|
|
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 unknown as Record<string, unknown>)[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');
|
|
}
|