shapes.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React from "react";
  2. import oc from "open-color";
  3. // We inline font-awesome icons in order to save on js size rather than including the font awesome react library
  4. export const SHAPES = [
  5. {
  6. icon: (
  7. // fa-mouse-pointer
  8. <svg viewBox="0 0 320 512" className="">
  9. <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" />
  10. </svg>
  11. ),
  12. value: "selection",
  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. },
  23. {
  24. icon: (
  25. // custom
  26. <svg viewBox="0 0 223.646 223.646">
  27. <path d="M111.823 0L16.622 111.823 111.823 223.646 207.025 111.823z" />
  28. </svg>
  29. ),
  30. value: "diamond",
  31. },
  32. {
  33. icon: (
  34. // fa-circle
  35. <svg viewBox="0 0 512 512">
  36. <path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z" />
  37. </svg>
  38. ),
  39. value: "ellipse",
  40. },
  41. {
  42. icon: (
  43. // fa-long-arrow-alt-right
  44. <svg viewBox="0 0 448 512" className="rtl-mirror">
  45. <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" />
  46. </svg>
  47. ),
  48. value: "arrow",
  49. },
  50. {
  51. icon: (
  52. // custom
  53. <svg viewBox="0 0 6 6">
  54. <line
  55. x1="0"
  56. y1="3"
  57. x2="6"
  58. y2="3"
  59. stroke={oc.black}
  60. strokeLinecap="round"
  61. />
  62. </svg>
  63. ),
  64. value: "line",
  65. },
  66. {
  67. icon: (
  68. // fa-font
  69. <svg viewBox="0 0 448 512">
  70. <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" />
  71. </svg>
  72. ),
  73. value: "text",
  74. },
  75. ] as const;
  76. export const shapesShortcutKeys = SHAPES.map((shape, index) => [
  77. shape.value[0],
  78. (index + 1).toString(),
  79. ]).flat(1);
  80. export function findShapeByKey(key: string) {
  81. return (
  82. SHAPES.find((shape, index) => {
  83. return shape.value[0] === key || key === (index + 1).toString();
  84. })?.value || "selection"
  85. );
  86. }