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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { SVGProps } from 'react'
  2. import { ColorStyle, DashStyle, 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): number {
  48. return strokeWidths[size]
  49. }
  50. export function getStrokeDashArray(
  51. dash: DashStyle,
  52. strokeWidth: number
  53. ): number[] {
  54. return dashArrays[dash](strokeWidth)
  55. }
  56. export function getFontSize(size: SizeStyle): number {
  57. return fontSizes[size]
  58. }
  59. export function getFontStyle(scale: number, style: ShapeStyles): string {
  60. const fontSize = getFontSize(style.size)
  61. return `${fontSize * scale}px/1.4 Verveine Regular`
  62. }
  63. export function getShapeStyle(
  64. style: ShapeStyles
  65. ): Partial<SVGProps<SVGUseElement>> {
  66. const { color, size, isFilled } = style
  67. const strokeWidth = getStrokeWidth(size)
  68. return {
  69. stroke: strokes[color],
  70. fill: isFilled ? fills[color] : 'none',
  71. strokeWidth,
  72. }
  73. }
  74. export const defaultStyle = {
  75. color: ColorStyle.Black,
  76. size: SizeStyle.Medium,
  77. isFilled: false,
  78. dash: DashStyle.Solid,
  79. }