You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shape-styles.ts 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { SVGProps } from 'react'
  2. import { ColorStyle, DashStyle, FontSize, ShapeStyles, SizeStyle } from 'types'
  3. export const strokes: Record<ColorStyle, string> = {
  4. [ColorStyle.White]: 'rgba(248, 249, 250, 1.000)',
  5. [ColorStyle.LightGray]: 'rgba(224, 226, 230, 1.000)',
  6. [ColorStyle.Gray]: 'rgba(172, 181, 189, 1.000)',
  7. [ColorStyle.Black]: 'rgba(0,0,0, 1.000)',
  8. [ColorStyle.Green]: 'rgba(54, 178, 77, 1.000)',
  9. [ColorStyle.Cyan]: 'rgba(14, 152, 173, 1.000)',
  10. [ColorStyle.Blue]: 'rgba(28, 126, 214, 1.000)',
  11. [ColorStyle.Indigo]: 'rgba(66, 99, 235, 1.000)',
  12. [ColorStyle.Violet]: 'rgba(112, 72, 232, 1.000)',
  13. [ColorStyle.Red]: 'rgba(240, 63, 63, 1.000)',
  14. [ColorStyle.Orange]: 'rgba(247, 103, 6, 1.000)',
  15. [ColorStyle.Yellow]: 'rgba(245, 159, 0, 1.000)',
  16. }
  17. export const fills = {
  18. [ColorStyle.White]: 'rgba(224, 226, 230, 1.000)',
  19. [ColorStyle.LightGray]: 'rgba(255, 255, 255, 1.000)',
  20. [ColorStyle.Gray]: 'rgba(224, 226, 230, 1.000)',
  21. [ColorStyle.Black]: 'rgba(255, 255, 255, 1.000)',
  22. [ColorStyle.Green]: 'rgba(235, 251, 238, 1.000)',
  23. [ColorStyle.Cyan]: 'rgba(227, 250, 251, 1.000)',
  24. [ColorStyle.Blue]: 'rgba(231, 245, 255, 1.000)',
  25. [ColorStyle.Indigo]: 'rgba(237, 242, 255, 1.000)',
  26. [ColorStyle.Violet]: 'rgba(242, 240, 255, 1.000)',
  27. [ColorStyle.Red]: 'rgba(255, 245, 245, 1.000)',
  28. [ColorStyle.Orange]: 'rgba(255, 244, 229, 1.000)',
  29. [ColorStyle.Yellow]: 'rgba(255, 249, 219, 1.000)',
  30. }
  31. const strokeWidths = {
  32. [SizeStyle.Small]: 2,
  33. [SizeStyle.Medium]: 4,
  34. [SizeStyle.Large]: 8,
  35. }
  36. const dashArrays = {
  37. [DashStyle.Solid]: () => [1],
  38. [DashStyle.Dashed]: (sw: number) => [sw * 2, sw * 4],
  39. [DashStyle.Dotted]: (sw: number) => [0, sw * 3],
  40. }
  41. const fontSizes = {
  42. [SizeStyle.Small]: 24,
  43. [SizeStyle.Medium]: 48,
  44. [SizeStyle.Large]: 72,
  45. auto: 'auto',
  46. }
  47. export function getStrokeWidth(size: SizeStyle) {
  48. return strokeWidths[size]
  49. }
  50. export function getStrokeDashArray(dash: DashStyle, strokeWidth: number) {
  51. return dashArrays[dash](strokeWidth)
  52. }
  53. export function getFontSize(size: SizeStyle) {
  54. return fontSizes[size]
  55. }
  56. export function getFontStyle(scale: number, style: ShapeStyles) {
  57. const fontSize = getFontSize(style.size)
  58. return `${fontSize * scale}px/1.4 Verveine Regular`
  59. }
  60. export function getShapeStyle(
  61. style: ShapeStyles
  62. ): Partial<SVGProps<SVGUseElement>> {
  63. const { color, size, dash, isFilled } = style
  64. const strokeWidth = getStrokeWidth(size)
  65. const strokeDasharray = getStrokeDashArray(dash, strokeWidth).join()
  66. return {
  67. stroke: strokes[color],
  68. fill: isFilled ? fills[color] : 'none',
  69. strokeWidth,
  70. strokeDasharray,
  71. }
  72. }
  73. export const defaultStyle = {
  74. color: ColorStyle.Black,
  75. size: SizeStyle.Medium,
  76. isFilled: false,
  77. dash: DashStyle.Solid,
  78. }