2021-07-10 20:39:29 +00:00
|
|
|
import { Theme, ColorStyle, DashStyle, ShapeStyles, SizeStyle } from 'types'
|
|
|
|
import { lerpColor } from 'utils'
|
|
|
|
|
|
|
|
const canvasLight = '#fafafa'
|
|
|
|
|
|
|
|
const canvasDark = '#343d45'
|
|
|
|
|
|
|
|
const colors = {
|
2021-07-13 20:52:20 +00:00
|
|
|
[ColorStyle.Black]: '#212528',
|
2021-07-10 20:39:29 +00:00
|
|
|
[ColorStyle.White]: '#f0f1f3',
|
|
|
|
[ColorStyle.LightGray]: '#c6cbd1',
|
|
|
|
[ColorStyle.Gray]: '#788492',
|
|
|
|
[ColorStyle.Green]: '#36b24d',
|
|
|
|
[ColorStyle.Cyan]: '#0e98ad',
|
|
|
|
[ColorStyle.Blue]: '#1c7ed6',
|
|
|
|
[ColorStyle.Indigo]: '#4263eb',
|
|
|
|
[ColorStyle.Violet]: '#7746f1',
|
|
|
|
[ColorStyle.Red]: '#ff2133',
|
|
|
|
[ColorStyle.Orange]: '#ff9433',
|
|
|
|
[ColorStyle.Yellow]: '#ffc936',
|
2021-06-02 11:50:34 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 20:39:29 +00:00
|
|
|
export const strokes: Record<Theme, Record<ColorStyle, string>> = {
|
|
|
|
light: colors,
|
|
|
|
dark: {
|
|
|
|
...(Object.fromEntries(
|
|
|
|
Object.entries(colors).map(([k, v]) => [k, lerpColor(v, canvasDark, 0.1)])
|
|
|
|
) as Record<ColorStyle, string>),
|
|
|
|
[ColorStyle.White]: '#ffffff',
|
|
|
|
[ColorStyle.Black]: '#000',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fills: Record<Theme, Record<ColorStyle, string>> = {
|
|
|
|
light: {
|
|
|
|
...(Object.fromEntries(
|
|
|
|
Object.entries(colors).map(([k, v]) => [
|
|
|
|
k,
|
|
|
|
lerpColor(v, canvasLight, 0.82),
|
|
|
|
])
|
|
|
|
) as Record<ColorStyle, string>),
|
|
|
|
[ColorStyle.White]: '#ffffff',
|
|
|
|
[ColorStyle.Black]: '#ffffff',
|
|
|
|
},
|
|
|
|
dark: Object.fromEntries(
|
|
|
|
Object.entries(colors).map(([k, v]) => [k, lerpColor(v, canvasDark, 0.618)])
|
|
|
|
) as Record<ColorStyle, string>,
|
2021-06-02 11:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const strokeWidths = {
|
|
|
|
[SizeStyle.Small]: 2,
|
|
|
|
[SizeStyle.Medium]: 4,
|
|
|
|
[SizeStyle.Large]: 8,
|
|
|
|
}
|
|
|
|
|
2021-06-15 11:58:51 +00:00
|
|
|
const fontSizes = {
|
2021-06-18 09:32:07 +00:00
|
|
|
[SizeStyle.Small]: 24,
|
|
|
|
[SizeStyle.Medium]: 48,
|
|
|
|
[SizeStyle.Large]: 72,
|
2021-06-15 11:58:51 +00:00
|
|
|
auto: 'auto',
|
|
|
|
}
|
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export function getStrokeWidth(size: SizeStyle): number {
|
2021-06-02 11:50:34 +00:00
|
|
|
return strokeWidths[size]
|
|
|
|
}
|
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export function getFontSize(size: SizeStyle): number {
|
2021-06-15 11:58:51 +00:00
|
|
|
return fontSizes[size]
|
|
|
|
}
|
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export function getFontStyle(scale: number, style: ShapeStyles): string {
|
2021-06-18 09:32:07 +00:00
|
|
|
const fontSize = getFontSize(style.size)
|
2021-06-15 11:58:51 +00:00
|
|
|
|
2021-06-17 21:50:04 +00:00
|
|
|
return `${fontSize * scale}px/1.4 Verveine Regular`
|
2021-06-15 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 20:39:29 +00:00
|
|
|
export function getShapeStyle(
|
|
|
|
style: ShapeStyles,
|
|
|
|
isDarkMode = false
|
|
|
|
): {
|
2021-07-08 12:26:55 +00:00
|
|
|
stroke: string
|
|
|
|
fill: string
|
|
|
|
strokeWidth: number
|
|
|
|
} {
|
2021-06-22 18:13:16 +00:00
|
|
|
const { color, size, isFilled } = style
|
2021-06-02 11:50:34 +00:00
|
|
|
|
|
|
|
const strokeWidth = getStrokeWidth(size)
|
|
|
|
|
2021-07-10 20:39:29 +00:00
|
|
|
const theme: Theme = isDarkMode ? 'dark' : 'light'
|
|
|
|
|
2021-06-02 11:50:34 +00:00
|
|
|
return {
|
2021-07-10 20:39:29 +00:00
|
|
|
stroke: strokes[theme][color],
|
|
|
|
fill: isFilled ? fills[theme][color] : 'none',
|
2021-06-02 11:50:34 +00:00
|
|
|
strokeWidth,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 12:09:53 +00:00
|
|
|
export const defaultStyle: ShapeStyles = {
|
2021-06-02 11:50:34 +00:00
|
|
|
color: ColorStyle.Black,
|
|
|
|
size: SizeStyle.Medium,
|
|
|
|
isFilled: false,
|
2021-07-09 18:42:43 +00:00
|
|
|
dash: DashStyle.Draw,
|
2021-06-02 11:50:34 +00:00
|
|
|
}
|