mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 00:56:26 +08:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import type { StyleInfo } from 'lit/directives/style-map.js';
|
|
|
|
import type { AffineTextAttributes } from '../types';
|
|
|
|
export function affineTextStyles(
|
|
props: AffineTextAttributes,
|
|
override?: Readonly<StyleInfo>
|
|
): StyleInfo {
|
|
let textDecorations = '';
|
|
if (props.underline) {
|
|
textDecorations += 'underline';
|
|
}
|
|
if (props.strike) {
|
|
textDecorations += ' line-through';
|
|
}
|
|
|
|
let inlineCodeStyle = {};
|
|
if (props.code) {
|
|
inlineCodeStyle = {
|
|
'font-family': 'var(--affine-font-code-family)',
|
|
background: 'var(--affine-background-code-block)',
|
|
border: '1px solid var(--affine-border-color)',
|
|
'border-radius': '4px',
|
|
color: 'var(--affine-text-primary-color)',
|
|
'font-variant-ligatures': 'none',
|
|
'line-height': 'auto',
|
|
};
|
|
}
|
|
|
|
return {
|
|
'font-weight': props.bold ? 'bolder' : 'inherit',
|
|
'font-style': props.italic ? 'italic' : 'normal',
|
|
'background-color': props.background ? props.background : undefined,
|
|
color: props.color ? props.color : undefined,
|
|
'text-decoration': textDecorations.length > 0 ? textDecorations : 'none',
|
|
...inlineCodeStyle,
|
|
...override,
|
|
};
|
|
}
|