shapes.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { KEYS } from "./keys";
  2. // We inline font-awesome icons in order to save on js size rather than including the font awesome react library
  3. export const SHAPES = [
  4. {
  5. icon: (
  6. // fa-mouse-pointer
  7. <svg viewBox="0 0 320 512" className="">
  8. <path d="M302.189 329.126H196.105l55.831 135.993c3.889 9.428-.555 19.999-9.444 23.999l-49.165 21.427c-9.165 4-19.443-.571-23.332-9.714l-53.053-129.136-86.664 89.138C18.729 472.71 0 463.554 0 447.977V18.299C0 1.899 19.921-6.096 30.277 5.443l284.412 292.542c11.472 11.179 3.007 31.141-12.5 31.141z" />
  9. </svg>
  10. ),
  11. value: "selection",
  12. key: KEYS.V,
  13. },
  14. {
  15. icon: (
  16. // fa-square
  17. <svg viewBox="0 0 448 512">
  18. <path d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48z" />
  19. </svg>
  20. ),
  21. value: "rectangle",
  22. key: KEYS.R,
  23. },
  24. {
  25. icon: (
  26. // custom
  27. <svg viewBox="0 0 223.646 223.646">
  28. <path d="M111.823 0L16.622 111.823 111.823 223.646 207.025 111.823z" />
  29. </svg>
  30. ),
  31. value: "diamond",
  32. key: KEYS.D,
  33. },
  34. {
  35. icon: (
  36. // fa-circle
  37. <svg viewBox="0 0 512 512">
  38. <path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z" />
  39. </svg>
  40. ),
  41. value: "ellipse",
  42. key: KEYS.O,
  43. },
  44. {
  45. icon: (
  46. // fa-long-arrow-alt-right
  47. <svg viewBox="0 0 448 512" className="rtl-mirror">
  48. <path d="M313.941 216H12c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12h301.941v46.059c0 21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.569 0-33.941l-86.059-86.059c-15.119-15.119-40.971-4.411-40.971 16.971V216z" />
  49. </svg>
  50. ),
  51. value: "arrow",
  52. key: KEYS.A,
  53. },
  54. {
  55. icon: (
  56. // custom
  57. <svg viewBox="0 0 6 6">
  58. <line
  59. x1="0"
  60. y1="3"
  61. x2="6"
  62. y2="3"
  63. stroke="currentColor"
  64. strokeLinecap="round"
  65. />
  66. </svg>
  67. ),
  68. value: "line",
  69. key: [KEYS.P, KEYS.L],
  70. },
  71. {
  72. icon: (
  73. // fa-pencil
  74. <svg viewBox="0 0 512 512">
  75. <path
  76. fill="currentColor"
  77. d="M290.74 93.24l128.02 128.02-277.99 277.99-114.14 12.6C11.35 513.54-1.56 500.62.14 485.34l12.7-114.22 277.9-277.88zm207.2-19.06l-60.11-60.11c-18.75-18.75-49.16-18.75-67.91 0l-56.55 56.55 128.02 128.02 56.55-56.55c18.75-18.76 18.75-49.16 0-67.91z"
  78. ></path>
  79. </svg>
  80. ),
  81. value: "freedraw",
  82. key: [KEYS.X, KEYS.P.toUpperCase()],
  83. },
  84. {
  85. icon: (
  86. // fa-font
  87. <svg viewBox="0 0 448 512">
  88. <path d="M432 416h-23.41L277.88 53.69A32 32 0 0 0 247.58 32h-47.16a32 32 0 0 0-30.3 21.69L39.41 416H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h128a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16h-19.58l23.3-64h152.56l23.3 64H304a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h128a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM176.85 272L224 142.51 271.15 272z" />
  89. </svg>
  90. ),
  91. value: "text",
  92. key: KEYS.T,
  93. },
  94. {
  95. icon: (
  96. // fa-image
  97. <svg viewBox="0 0 512 512">
  98. <path
  99. fill="currentColor"
  100. d="M464 64H48C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V112c0-26.51-21.49-48-48-48zm-6 336H54a6 6 0 0 1-6-6V118a6 6 0 0 1 6-6h404a6 6 0 0 1 6 6v276a6 6 0 0 1-6 6zM128 152c-22.091 0-40 17.909-40 40s17.909 40 40 40 40-17.909 40-40-17.909-40-40-40zM96 352h320v-80l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L192 304l-39.515-39.515c-4.686-4.686-12.284-4.686-16.971 0L96 304v48z"
  101. ></path>
  102. </svg>
  103. ),
  104. value: "image",
  105. key: null,
  106. },
  107. ] as const;
  108. export const findShapeByKey = (key: string) => {
  109. const shape = SHAPES.find((shape, index) => {
  110. return (
  111. key === (index + 1).toString() ||
  112. (shape.key &&
  113. (typeof shape.key === "string"
  114. ? shape.key === key
  115. : (shape.key as readonly string[]).includes(key)))
  116. );
  117. });
  118. return shape?.value || null;
  119. };