@yorab/react-paint 0.17.1 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +4 -0
  2. package/dist/_chunks/array-DuJem3vg.js +1 -0
  3. package/dist/_chunks/canvas-DF1RWuxW.js +1 -0
  4. package/dist/_chunks/editor-DuVskl0R.js +1 -0
  5. package/dist/canvas/components/Canvas.d.ts +1 -52
  6. package/dist/canvas/constants/app.d.ts +3 -25
  7. package/dist/canvas/constants/rendering.d.ts +3 -0
  8. package/dist/canvas/constants/tools.d.ts +4 -0
  9. package/dist/canvas/context/CanvasContext.d.ts +55 -0
  10. package/dist/canvas/hooks/useDrawableCanvas.d.ts +2 -43
  11. package/dist/canvas/hooks/useEventListener.d.ts +2 -0
  12. package/dist/canvas/hooks/useReactPaint.d.ts +8 -3
  13. package/dist/canvas/hooks/useShapes.d.ts +1 -0
  14. package/dist/canvas/index.d.ts +4 -0
  15. package/dist/canvas/index.js +1 -0
  16. package/dist/canvas/utils/canvas.d.ts +2 -1
  17. package/dist/canvas/utils/intersect.d.ts +4 -0
  18. package/dist/canvas/utils/selection.d.ts +0 -3
  19. package/dist/canvas/utils/shapes/index.d.ts +2 -3
  20. package/dist/canvas/utils/shapes/line.d.ts +2 -2
  21. package/dist/canvas/utils/shapes/path.d.ts +1 -0
  22. package/dist/canvas/utils/tools.d.ts +1 -1
  23. package/dist/canvas/utils/transform.d.ts +0 -1
  24. package/dist/common/hooks/useDebounce.d.ts +2 -0
  25. package/dist/common/types/Settings.d.ts +24 -0
  26. package/dist/common/utils/selection.d.ts +4 -0
  27. package/dist/editor/components/settings/Layouts.d.ts +1 -1
  28. package/dist/editor/components/settings/SettingsBar.d.ts +4 -2
  29. package/dist/editor/components/toolbox/ContextMenu.d.ts +4 -2
  30. package/dist/editor/components/toolbox/Toolbar.d.ts +1 -1
  31. package/dist/editor/hooks/useMenu.d.ts +2 -1
  32. package/dist/editor/index.d.ts +3 -2
  33. package/dist/editor/index.js +1 -0
  34. package/dist/editor/utils/style.d.ts +1 -1
  35. package/dist/index.d.ts +4 -6
  36. package/dist/react-paint.css +2 -1
  37. package/dist/react-paint.js +1 -1914
  38. package/dist/react-paint.umd.cjs +1 -1
  39. package/dist/src/canvas/components/Canvas.d.ts +4 -0
  40. package/dist/src/canvas/components/EditTextBox.d.ts +13 -0
  41. package/dist/src/canvas/constants/app.d.ts +37 -0
  42. package/dist/src/canvas/constants/grid.d.ts +1 -0
  43. package/dist/src/canvas/constants/keyboard.d.ts +27 -0
  44. package/dist/src/canvas/constants/picture.d.ts +1 -0
  45. package/dist/src/canvas/constants/rendering.d.ts +3 -0
  46. package/dist/src/canvas/constants/shapes.d.ts +10 -0
  47. package/dist/src/canvas/constants/tools.d.ts +4 -0
  48. package/dist/src/canvas/constants/zoom.d.ts +5 -0
  49. package/dist/src/canvas/context/CanvasContext.d.ts +55 -0
  50. package/dist/src/canvas/hooks/useComponent.d.ts +12 -0
  51. package/dist/src/canvas/hooks/useDoubleClick.d.ts +5 -0
  52. package/dist/src/canvas/hooks/useDrawableCanvas.d.ts +6 -0
  53. package/dist/src/canvas/hooks/useEventListener.d.ts +2 -0
  54. package/dist/src/canvas/hooks/useKeyboard.d.ts +33 -0
  55. package/dist/src/canvas/hooks/usePinchZoomAndMove.d.ts +17 -0
  56. package/dist/src/canvas/hooks/useReactPaint.d.ts +164 -0
  57. package/dist/src/canvas/hooks/useResizeObserver.d.ts +6 -0
  58. package/dist/src/canvas/hooks/useShapes.d.ts +44 -0
  59. package/dist/src/canvas/hooks/useZoom.d.ts +22 -0
  60. package/dist/src/canvas/index.d.ts +19 -0
  61. package/dist/src/canvas/utils/canvas.d.ts +15 -0
  62. package/dist/src/canvas/utils/data.d.ts +5 -0
  63. package/dist/src/canvas/utils/file.d.ts +274 -0
  64. package/dist/src/canvas/utils/grid.d.ts +2 -0
  65. package/dist/src/canvas/utils/intersect.d.ts +27 -0
  66. package/dist/src/canvas/utils/selection/groupSelection.d.ts +4 -0
  67. package/dist/src/canvas/utils/selection/lineSelection.d.ts +19 -0
  68. package/dist/src/canvas/utils/selection/rectSelection.d.ts +20 -0
  69. package/dist/src/canvas/utils/selection/selectionFrame.d.ts +3 -0
  70. package/dist/src/canvas/utils/selection.d.ts +12 -0
  71. package/dist/src/canvas/utils/shapes/brush.d.ts +21 -0
  72. package/dist/src/canvas/utils/shapes/circle.d.ts +18 -0
  73. package/dist/src/canvas/utils/shapes/curve.d.ts +17 -0
  74. package/dist/src/canvas/utils/shapes/ellipse.d.ts +18 -0
  75. package/dist/src/canvas/utils/shapes/group.d.ts +33 -0
  76. package/dist/src/canvas/utils/shapes/index.d.ts +35 -0
  77. package/dist/src/canvas/utils/shapes/line.d.ts +19 -0
  78. package/dist/src/canvas/utils/shapes/path.d.ts +29 -0
  79. package/dist/src/canvas/utils/shapes/picture.d.ts +13 -0
  80. package/dist/src/canvas/utils/shapes/polygon.d.ts +18 -0
  81. package/dist/src/canvas/utils/shapes/rectangle.d.ts +22 -0
  82. package/dist/src/canvas/utils/shapes/text.d.ts +27 -0
  83. package/dist/src/canvas/utils/shapes/triangle.d.ts +4 -0
  84. package/dist/src/canvas/utils/transform.d.ts +15 -0
  85. package/dist/src/canvas/utils/trigo.d.ts +19 -0
  86. package/dist/src/canvas/utils/zoom.d.ts +58 -0
  87. package/dist/src/common/hooks/useDebounce.d.ts +2 -0
  88. package/dist/src/common/types/Canvas.d.ts +8 -0
  89. package/dist/src/common/types/Mode.d.ts +64 -0
  90. package/dist/src/common/types/Settings.d.ts +24 -0
  91. package/dist/src/common/types/Shapes.d.ts +153 -0
  92. package/dist/src/common/types/react.d.ts +6 -0
  93. package/dist/src/common/types/tools.d.ts +164 -0
  94. package/dist/src/common/types/utils.d.ts +4 -0
  95. package/dist/src/common/utils/array.d.ts +2 -0
  96. package/dist/src/common/utils/dom.d.ts +1 -0
  97. package/dist/src/common/utils/object.d.ts +4 -0
  98. package/dist/src/common/utils/selection.d.ts +4 -0
  99. package/dist/src/common/utils/util.d.ts +3 -0
  100. package/dist/src/editor/components/common/Button.d.ts +16 -0
  101. package/dist/src/editor/components/common/FileInput.d.ts +13 -0
  102. package/dist/src/editor/components/common/Loading.d.ts +6 -0
  103. package/dist/src/editor/components/common/Menu.d.ts +10 -0
  104. package/dist/src/editor/components/common/Modal.d.ts +11 -0
  105. package/dist/src/editor/components/common/Panel.d.ts +15 -0
  106. package/dist/src/editor/components/common/Snackbar.d.ts +7 -0
  107. package/dist/src/editor/components/settings/ClosedPointsField.d.ts +10 -0
  108. package/dist/src/editor/components/settings/ColorField.d.ts +15 -0
  109. package/dist/src/editor/components/settings/DeleteButton.d.ts +8 -0
  110. package/dist/src/editor/components/settings/FontFamilyField.d.ts +12 -0
  111. package/dist/src/editor/components/settings/LayoutButton.d.ts +7 -0
  112. package/dist/src/editor/components/settings/Layouts.d.ts +19 -0
  113. package/dist/src/editor/components/settings/LineArrowField.d.ts +12 -0
  114. package/dist/src/editor/components/settings/LineTypeField.d.ts +16 -0
  115. package/dist/src/editor/components/settings/RangeField.d.ts +19 -0
  116. package/dist/src/editor/components/settings/SelectField.d.ts +18 -0
  117. package/dist/src/editor/components/settings/SettingsBar.d.ts +26 -0
  118. package/dist/src/editor/components/settings/ToggleField.d.ts +13 -0
  119. package/dist/src/editor/components/settings/ZoomButton.d.ts +8 -0
  120. package/dist/src/editor/components/toolbox/ContextMenu.d.ts +25 -0
  121. package/dist/src/editor/components/toolbox/ExportModal.d.ts +7 -0
  122. package/dist/src/editor/components/toolbox/LoadFileTool.d.ts +11 -0
  123. package/dist/src/editor/components/toolbox/MenuGroup.d.ts +27 -0
  124. package/dist/src/editor/components/toolbox/PictureUrlInput.d.ts +7 -0
  125. package/dist/src/editor/components/toolbox/Tool.d.ts +11 -0
  126. package/dist/src/editor/components/toolbox/Toolbar.d.ts +26 -0
  127. package/dist/src/editor/components/toolbox/ToolbarGroup.d.ts +14 -0
  128. package/dist/src/editor/constants/grid.d.ts +7 -0
  129. package/dist/src/editor/constants/icons.d.ts +43 -0
  130. package/dist/src/editor/constants/loading.d.ts +1 -0
  131. package/dist/src/editor/constants/options.d.ts +13 -0
  132. package/dist/src/editor/constants/snackbar.d.ts +7 -0
  133. package/dist/src/editor/constants/style.d.ts +14 -0
  134. package/dist/src/editor/constants/tools.d.ts +32 -0
  135. package/dist/src/editor/hooks/useDrag.d.ts +15 -0
  136. package/dist/src/editor/hooks/useMenu.d.ts +11 -0
  137. package/dist/src/editor/hooks/useSnackbar.d.ts +10 -0
  138. package/dist/src/editor/index.d.ts +25 -0
  139. package/dist/src/editor/types/snackbar.d.ts +7 -0
  140. package/dist/src/editor/utils/style.d.ts +2 -0
  141. package/dist/src/editor/utils/toolbar.d.ts +11 -0
  142. package/dist/src/index.d.ts +5 -0
  143. package/package.json +42 -24
@@ -1,1914 +1 @@
1
- import Pi, { useState as J, useEffect as de, useRef as ce, useCallback as G, useMemo as Yn, useImperativeHandle as Xn, useTransition as $n } from "react";
2
- import { jsx as v, jsxs as K, Fragment as Oe } from "react/jsx-runtime";
3
- const Un = '<svg><path d="M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z"/></svg>', Li = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', Vi = '<svg><path d="M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z"/></svg>', Zi = '<svg><path d="M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z"/></svg>', qn = '<svg><path d="M4.125 5.083V3.333H7.062L7.896 2.5H12.104L12.938 3.333H15.875V5.083ZM6.75 17.5Q6.021 17.5 5.51 16.99Q5 16.479 5 15.75V5.958H15V15.75Q15 16.479 14.49 16.99Q13.979 17.5 13.25 17.5Z"/></svg>', qi = '<svg><path d="M10 17.5Q7.208 17.5 5.271 15.594Q3.333 13.688 3.333 10.958Q3.333 9.583 3.854 8.396Q4.375 7.208 5.292 6.292L10 1.667L14.688 6.292Q15.604 7.208 16.135 8.396Q16.667 9.583 16.667 10.958Q16.667 13.688 14.719 15.594Q12.771 17.5 10 17.5ZM5.146 11.667H14.854Q15.083 10.188 14.552 9.146Q14.021 8.104 13.479 7.562L10 4.125L6.521 7.562Q5.979 8.104 5.448 9.146Q4.917 10.188 5.146 11.667Z"/></svg>', Hi = '<svg><path d="M4.792 15.083 8.333 11.542 9.833 13.021 11.667 10.708 15.167 15.083ZM6.667 8.417Q5.938 8.417 5.427 7.906Q4.917 7.396 4.917 6.667Q4.917 5.938 5.427 5.427Q5.938 4.917 6.667 4.917Q7.396 4.917 7.906 5.427Q8.417 5.938 8.417 6.667Q8.417 7.396 7.906 7.906Q7.396 8.417 6.667 8.417ZM4.167 18.333Q3.125 18.333 2.396 17.604Q1.667 16.875 1.667 15.833V4.167Q1.667 3.125 2.396 2.396Q3.125 1.667 4.167 1.667H15.833Q16.875 1.667 17.604 2.396Q18.333 3.125 18.333 4.167V15.833Q18.333 16.875 17.604 17.604Q16.875 18.333 15.833 18.333ZM4.167 16.583H15.833Q16.146 16.583 16.365 16.365Q16.583 16.146 16.583 15.833V4.167Q16.583 3.854 16.365 3.635Q16.146 3.417 15.833 3.417H4.167Q3.854 3.417 3.635 3.635Q3.417 3.854 3.417 4.167V15.833Q3.417 16.146 3.635 16.365Q3.854 16.583 4.167 16.583Z"/></svg>', Gn = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', _n = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', Gi = '<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>', jn = '<svg><path d="M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z"/></svg>', _i = '<svg><path d="M5.833 15V3.333H10.375Q11.812 3.333 12.885 4.156Q13.958 4.979 13.958 6.375Q13.958 7.375 13.49 7.969Q13.021 8.562 12.396 8.875V9.042Q13.312 9.354 13.844 10.021Q14.375 10.688 14.375 11.75Q14.375 13.312 13.229 14.156Q12.083 15 10.5 15ZM8.125 8.042H10.188Q10.854 8.042 11.302 7.656Q11.75 7.271 11.75 6.708Q11.75 6.167 11.302 5.771Q10.854 5.375 10.188 5.375H8.125ZM8.125 12.917H10.354Q11.167 12.917 11.625 12.51Q12.083 12.104 12.083 11.458Q12.083 10.812 11.625 10.406Q11.167 10 10.354 10H8.125Z"/></svg>', ji = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', Ki = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Ji = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM10 16.583Q10.896 16.583 11.708 16.365Q12.521 16.146 13.25 15.729L4.292 6.75Q3.875 7.479 3.646 8.292Q3.417 9.104 3.417 10Q3.417 12.729 5.344 14.656Q7.271 16.583 10 16.583ZM17 14.562 15.708 13.271Q16.125 12.542 16.354 11.719Q16.583 10.896 16.583 10Q16.583 7.271 14.656 5.344Q12.729 3.417 10 3.417Q9.104 3.417 8.292 3.646Q7.479 3.875 6.75 4.292L5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562ZM11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771ZM8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Z"/></svg>', en = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM17 14.562 5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562Z"/></svg>', Kn = '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Zm-40-60v-80h-80v-80h80v-80h80v80h80v80h-80v80h-80Z"/></svg>', Ee = ["transparent", "black", "white", "red", "green", "blue", "yellow"], lt = [0, 1, 2], tn = [[1, 0], [1, 2], [4, 6]], It = "serif", ao = 2, Jn = 3, oo = 4, Me = "react-paint-", ea = { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } }, zi = { type: "picture", id: `${Me}picture`, icon: Hi, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, ta = { type: "brush", id: `${Me}brush`, icon: Un, label: "Brosse", settings: { strokeColor: { values: Ee, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: lt, default: 0 } } }, ia = { type: "line", id: `${Me}line`, icon: _n, label: "Ligne", settings: { strokeColor: { values: Ee, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, na = { type: "polygon", id: `${Me}polygon`, icon: Zi, label: "Polygone", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, closedPoints: { default: 0 } } }, aa = { type: "curve", id: `${Me}curve`, icon: jn, label: "Courbe", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, closedPoints: { default: 0 } } }, oa = { type: "rect", id: `${Me}rect`, icon: Li, label: "Rectangle", settings: ea }, sa = { type: "square", id: `${Me}square`, icon: Li, label: "Carré", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, ra = { type: "circle", id: `${Me}circle`, icon: Vi, label: "Cercle", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, la = { type: "ellipse", id: `${Me}ellipse`, icon: Vi, label: "Ellipse", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, ca = { type: "text", id: `${Me}text`, icon: Gn, label: "Texte", settings: { strokeColor: { values: Ee, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: It }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Je = { id: `${Me}selection`, type: "selection", icon: '<svg><path d="M8.0145 11.1707C8.38484 10.9914 8.82183 11.1558 8.99959 11.5295L10.7031 15.2591L12.0363 14.6238L10.3254 10.9017C10.1476 10.528 10.3106 10.0795 10.6809 9.90761L10.8883 9.84782L12.5918 9.51148L6.48133 4.33192V12.389L7.82934 11.2903L8.0145 11.1707ZM10.6587 16.9258C10.2883 17.1052 9.84395 16.9482 9.67359 16.5745L8.05894 13.0318L6.19988 14.5416C6.07396 14.6462 5.91842 14.706 5.74066 14.706C5.54423 14.706 5.35584 14.6272 5.21694 14.4871C5.07803 14.3469 5 14.1568 5 13.9586V2.74741C5 2.54919 5.07803 2.35908 5.21694 2.21891C5.35584 2.07874 5.54423 2 5.74066 2C5.91842 2 6.08878 2.06727 6.21469 2.1719L6.2221 2.16443L14.7323 9.36947C15.0508 9.63854 15.0879 10.1094 14.8286 10.4233C14.7175 10.5579 14.562 10.6475 14.4064 10.6774L12.0659 11.1408L13.6954 14.6761C13.888 15.0498 13.7102 15.4908 13.3399 15.6627L10.6587 16.9258Z"/></svg>', label: "Sélection" }, Pt = { id: `${Me}undo`, type: "undo", icon: '<svg><path d="M11.708 15.833H5.854V14.083H11.708Q13 14.083 13.958 13.292Q14.917 12.5 14.917 11.271Q14.917 10.042 13.958 9.24Q13 8.438 11.708 8.438H6.667L8.792 10.562L7.562 11.792L3.333 7.562L7.562 3.333L8.792 4.562L6.667 6.688H11.708Q13.729 6.688 15.198 7.99Q16.667 9.292 16.667 11.25Q16.667 13.208 15.198 14.521Q13.729 15.833 11.708 15.833Z"/></svg>', label: "Undo" }, Lt = { id: `${Me}redo`, type: "redo", icon: '<svg><path d="M8.292 15.833Q6.271 15.833 4.802 14.521Q3.333 13.208 3.333 11.25Q3.333 9.292 4.802 7.99Q6.271 6.688 8.292 6.688H13.333L11.208 4.562L12.438 3.333L16.667 7.562L12.438 11.792L11.208 10.562L13.333 8.438H8.292Q7 8.438 6.042 9.229Q5.083 10.021 5.083 11.25Q5.083 12.5 6.042 13.292Q7 14.083 8.292 14.083H14.146V15.833Z"/></svg>', label: "Redo" }, Vt = { id: `${Me}clear`, type: "clear", icon: '<svg><path d="M7.854 13.812 10 11.688 12.125 13.812 13.354 12.604 11.208 10.458 13.354 8.312 12.125 7.104 10 9.229 7.854 7.104 6.625 8.312 8.771 10.458 6.625 12.604ZM5.896 17.5Q5.167 17.5 4.656 16.99Q4.146 16.479 4.146 15.75V5.125H3.333V3.375H7.542V2.5H12.458V3.375H16.667V5.125H15.833V15.75Q15.833 16.479 15.323 16.99Q14.812 17.5 14.083 17.5Z"/></svg>', label: "Clear" }, di = { id: `${Me}export`, type: "export", icon: '<svg><path d="M10 13.271 5.708 8.979 6.958 7.729 9.125 9.896V3.333H10.875V9.896L13.042 7.729L14.292 8.979ZM5.083 16.667Q4.354 16.667 3.844 16.156Q3.333 15.646 3.333 14.917V12.5H5.083V14.917Q5.083 14.917 5.083 14.917Q5.083 14.917 5.083 14.917H14.917Q14.917 14.917 14.917 14.917Q14.917 14.917 14.917 14.917V12.5H16.667V14.917Q16.667 15.646 16.156 16.156Q15.646 16.667 14.917 16.667Z"/></svg>', label: "Export PNG" }, nn = { id: `${Me}load`, type: "loadfile", icon: '<svg><path d="M3.417 16.667Q2.729 16.667 2.198 16.135Q1.667 15.604 1.667 14.917V5.083Q1.667 4.396 2.198 3.865Q2.729 3.333 3.417 3.333H8.25L9.917 5H16.667Q17.354 5 17.844 5.531Q18.333 6.062 18.333 6.75H3.417V14.917Q3.417 14.917 3.417 14.917Q3.417 14.917 3.417 14.917L5.438 8.5H19.583L17.396 15.479Q17.229 16.021 16.802 16.344Q16.375 16.667 15.833 16.667Z"/></svg>', label: "Load project" }, hi = { id: `${Me}save`, type: "savefile", icon: '<svg><path d="M17.5 5.833V15.75Q17.5 16.479 16.99 16.99Q16.479 17.5 15.75 17.5H4.25Q3.521 17.5 3.01 16.99Q2.5 16.479 2.5 15.75V4.25Q2.5 3.521 3.01 3.01Q3.521 2.5 4.25 2.5H14.167ZM10 14.917Q11.062 14.917 11.823 14.156Q12.583 13.396 12.583 12.333Q12.583 11.271 11.823 10.51Q11.062 9.75 10 9.75Q8.938 9.75 8.177 10.51Q7.417 11.271 7.417 12.333Q7.417 13.396 8.177 14.156Q8.938 14.917 10 14.917ZM5.021 8.396H12.521V5.021H5.021Z"/></svg>', label: "Save project" }, ui = { id: `${Me}move`, type: "move", icon: '<svg viewBox="0 -960 960 960"><path d="M412-48q-21.95 0-40.98-9Q352-66 338-83L48-434l27-28q17-17 41.5-20.5T162-473l126 74v-381q0-15.3 10.29-25.65Q308.58-816 323.79-816t25.71 10.35Q360-795.3 360-780v300h80v-396q0-15.3 10.29-25.65Q460.58-912 475.79-912t25.71 10.35Q512-891.3 512-876v396h80v-348q0-15.3 10.29-25.65Q612.58-864 627.79-864t25.71 10.35Q664-843.3 664-828v348h80v-252q0-15.3 10.29-25.65Q764.58-768 779.79-768t25.71 10.35Q816-747.3 816-732v540q0 60-42 102T672-48H412Z"/></svg>', label: "Move" }, an = { id: `${Me}upload-picture`, type: "uploadpicture", icon: Hi, label: "Upload picture" }, da = 2, ha = "blue", gt = 14, ua = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], pa = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], so = ["rect", "square", "circle", "ellipse", "picture", "text", "triangle", "brush", "group"], ro = ["square", "circle", "picture", "text"], ga = "react-paint-canvas-drawcanvas", fa = "react-paint-canvas-selectioncanvas", on = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, withContextMenu: !0, availableTools: [ta, ia, na, aa, oa, sa, ra, la, zi, ca], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, lo = { canvasBackgroundColor: "white", canvasSelectionColor: ha, canvasSelectionWidth: da }, sn = 300, Si = (e, t) => {
4
- const i = { ...t };
5
- for (const n of e) Array.isArray(n) ? n[1].includes(i[n[0]]) && delete i[n[0]] : delete i[n];
6
- return i;
7
- }, Xe = (e, t, i) => {
8
- const n = Array.isArray(i) ? [...i] : { ...i }, a = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
- return a.reduce((o, r, l) => (o[r] = bi(o[r]) ? { ...o[r] } : Array.isArray(o[r]) ? [...o[r]] : o[r] === void 0 || o[r] === null ? {} : o[r], l === a.length - 1 && (o[r] = t), o[r]), n), n;
10
- }, bi = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, Ke = (e, t, i) => {
11
- if (!bi(t) || !bi(i)) return i;
12
- const n = { ...t };
13
- for (const a in i) i.hasOwnProperty(a) && (n.hasOwnProperty(a) ? n[a] = e(n[a], i[a], a) ?? Ke(e, n[a], i[a]) : n[a] = i[a]);
14
- return n;
15
- }, va = (e, t) => {
16
- if (e === t) return !0;
17
- if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
18
- const i = Object.keys(e), n = Object.keys(t);
19
- if (i.length !== n.length) return !1;
20
- for (const a of i) if (!n.includes(a) || !va(e[a], t[a])) return !1;
21
- return !0;
22
- }, pi = {}, Le = (e = "") => (pi[e] || (pi[e] = 0), `${e}${++pi[e]}`), et = (e, t, i) => Math.max(t, Math.min(e, i)), ma = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), ya = (e) => {
23
- e.reset(), e.lineCap = "round", e.lineJoin = "round";
24
- }, De = (e, t = {}) => {
25
- const { lineCap: i = "round", fillColor: n = "transparent", opacity: a = 100, strokeColor: o = ha, lineWidth: r = da, lineDash: l = 0, shadowColor: s = "transparent", shadowBlur: c = 0 } = t;
26
- e.lineCap = i, e.globalAlpha = a / 100, e.fillStyle = n, e.strokeStyle = o, e.lineWidth = r, e.setLineDash(l === 0 ? [] : [tn[l][0] * r, tn[l][1] * r]), e.shadowColor = s, e.shadowBlur = c;
27
- }, kt = (e, t, i, n) => {
28
- e.save(), e.scale(t.canvasSize.scaleRatio, t.canvasSize.scaleRatio), e.translate(t.canvasOffset[0], t.canvasOffset[1]), i && n && (e.translate(n[0], n[1]), e.rotate(i), e.translate(-n[0], -n[1]));
29
- }, Qi = (e) => 180 * e / Math.PI, Sa = (e, t) => {
30
- const i = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), n = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
31
- return Math.sqrt(i * i + n * n) <= t.radius;
32
- }, Qe = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
33
- if (i === 0) return t;
34
- const n = [t[0] - e[0], t[1] - e[1]], a = n[1] * Math.cos(i) - n[0] * Math.sin(i);
35
- return [n[1] * Math.sin(i) + n[0] * Math.cos(i) + e[0], a + e[1]];
36
- }, rn = (e) => (e + 2 * Math.PI) % (2 * Math.PI), ln = ({ targetVector: [e, t], radian: i = !0, originVector: n }) => {
37
- const a = rn(Math.atan2(t[1] - e[1], t[0] - e[0]));
38
- if (n) {
39
- const [o, r] = n, l = Math.atan2(r[1] - o[1], r[0] - o[0]), s = rn(a - l);
40
- return i ? s : Qi(s);
41
- }
42
- return i ? a : Qi(a);
43
- }, ba = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), mt = (e, t, i) => {
44
- const n = Qe({ origin: t.computed.center, point: e.computed.center, rotation: t.rotation ?? 0 }), a = (n[0] - (e.computed.borders.width / 2 - i.settings.selectionPadding) - (i.originalBorders.x + i.settings.selectionPadding)) * i.widthMultiplier, o = (n[1] - (e.computed.borders.height / 2 - i.settings.selectionPadding) - (i.originalBorders.y + i.settings.selectionPadding)) * i.heightMultiplier;
45
- return { x: i.newBorderX + i.settings.selectionPadding + (i.isXinverted ? i.newBorderWidth - 2 * i.settings.selectionPadding - (e.computed.borders.width - 2 * i.settings.selectionPadding || 1) * i.widthMultiplier - a : a), y: i.newBorderY + i.settings.selectionPadding + (i.isYinverted ? i.newBorderHeight - 2 * i.settings.selectionPadding - (e.computed.borders.height - 2 * i.settings.selectionPadding || 1) * i.heightMultiplier - o : o) };
46
- }, yt = (e, t, i, n, a) => Qe({ origin: e.groupCenter, point: [t + n / 2, i + a / 2], rotation: -e.rotation }), Ai = (e, { selectionPadding: t }) => {
47
- const i = e.points.flat(), n = Math.min(...i.map((s) => s[0])), a = Math.min(...i.map((s) => s[1])), o = i.map((s) => Ge(s, n, a, e.scaleX, e.scaleY)), r = Math.max(...o.map((s) => s[0])) + t, l = Math.max(...o.map((s) => s[1])) + t;
48
- return { x: n - t, width: r - n + t, y: a - t, height: l - a + t };
49
- }, Zt = (e, t) => {
50
- const i = uo(e, t), n = it(e, Ai, t);
51
- return { ...e, path: i, selection: Ht(i, n, t), computed: n };
52
- }, co = Zt, Qa = (e, t, i) => {
53
- const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = Ai({ ...e, scaleX: 1, scaleY: 1 }, o), c = s.width - 2 * o.selectionPadding, h = s.height - 2 * o.selectionPadding, d = e.scaleX ?? 1 ? (e.scaleX ?? 1) * r : r / c, u = e.scaleY ?? 1 ? (e.scaleY ?? 1) * l : l / h, p = c * d, f = h * u, m = mt(e, t, i), b = yt(i, m.x, m.y, p, f), x = Be(b[0] - p / 2 - e.computed.borders.x - o.selectionPadding) + (n ? 2 * e.computed.borders.x + s.width : 0), k = Be(b[1] - f / 2 - e.computed.borders.y - o.selectionPadding) + (a ? 2 * e.computed.borders.y + s.height : 0), M = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation;
54
- return Zt({ ...e, points: e.points.map((S) => S.map(([g, P]) => [n ? -g + x : g + x, a ? -P + k : P + k])), scaleX: d, scaleY: u, rotation: M ? -(e.rotation ?? 0) : e.rotation ?? 0 }, i.settings);
55
- }, Be = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Ge = (e, t, i, n = 1, a = 1) => [t + (e[0] - t) * n, i + (e[1] - i) * a], ze = (e, t, i = 0) => {
56
- if (!t.gridGap) return Be(e);
57
- const n = e + i, a = n >= 0 ? t.gridGap : -t.gridGap;
58
- return n + a / 2 - (n + a / 2) % a - i;
59
- }, ho = (e, t, i, n, a, o, r) => {
60
- if (n.mode === "translate") return pe(Oa(i, n.originalShape, n.cursorStartPosition, a, o), a);
61
- if (n.mode === "rotate") {
62
- const l = n.originalShape.computed.center[0] - n.cursorStartPosition[0], s = n.originalShape.computed.center[1] - n.cursorStartPosition[1], c = n.originalShape.computed.center[0] - i[0], h = n.originalShape.computed.center[1] - i[1], d = ((p, f, m) => f.gridGap || m ? p + Math.PI / 18 / 2 - (p + Math.PI / 18 / 2) % (Math.PI / 18) : Be(p, 3))(Math.atan2(h, c) - Math.atan2(s, l), a, o), u = _(n.originalShape).map((p) => _e(Na(p, d, n.originalShape.computed.center), a));
63
- return pe(u, a);
64
- }
65
- return n.mode === "resize" ? pe(Do(e, i, n.originalShape, n, a, o, r), a) : n.mode === "brush" ? pe(_(t).map((l) => ((s, c, h) => {
66
- const d = { ...s, points: Xe(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(c[0]), Math.round(c[1])]], s.points) };
67
- return Zt(d, h);
68
- })(l, i, a)), a) : t;
69
- }, Wt = (e) => {
70
- const t = new Path2D();
71
- return t.rect(e.x, e.y, e.width, e.height), t;
72
- }, Gt = (e) => {
73
- const t = new Path2D();
74
- return t.arc(e.x, e.y, e.radius, 0, 2 * Math.PI), t;
75
- }, _t = (e) => {
76
- const t = new Path2D();
77
- return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t;
78
- }, uo = (e, { brushAlgo: t }) => {
79
- const i = new Path2D();
80
- if (e.points.length < 1) return i;
81
- const n = e.points.flat(), a = n.map((s) => s[0]), o = n.map((s) => s[1]), r = Math.min(...a), l = Math.min(...o);
82
- for (const s of e.points) if (s.length) if (s.length === 1) i.rect(...Ge(s[0], r, l, e.scaleX, e.scaleY), 1, 1);
83
- else if (i.moveTo(...Ge(s[0], r, l, e.scaleX, e.scaleY)), t === "quadratic") {
84
- for (let c = 0; c < s.slice(1).length - 2; c++) {
85
- const h = Ge(s[c], r, l, e.scaleX, e.scaleY), d = Ge(s[c + 1], r, l, e.scaleX, e.scaleY), u = (h[0] + d[0]) / 2, p = (h[1] + d[1]) / 2;
86
- i.quadraticCurveTo(...h, u, p);
87
- }
88
- i.quadraticCurveTo(...Ge(s[s.length - 2], r, l, e.scaleX, e.scaleY), ...Ge(s[s.length - 1], r, l, e.scaleX, e.scaleY));
89
- } else for (const c of s.slice(1)) i.lineTo(...Ge(c, r, l, e.scaleX, e.scaleY));
90
- return i;
91
- }, po = (e, t, i, n) => {
92
- const a = (g) => (1 - g) ** 3 * e[0] + 3 * (1 - g) ** 2 * g * t[0] + 3 * (1 - g) * g ** 2 * i[0] + g ** 3 * n[0], o = (g) => (1 - g) ** 3 * e[1] + 3 * (1 - g) ** 2 * g * t[1] + 3 * (1 - g) * g ** 2 * i[1] + g ** 3 * n[1], r = (g, P, z) => {
93
- const N = g - 2 * P + z, D = -2 * g + 2 * P, E = g;
94
- if (Math.abs(N) < 1e-10) {
95
- if (Math.abs(D) < 1e-10) return [];
96
- const Z = -E / D;
97
- return Z > 0 && Z < 1 ? [Z] : [];
98
- }
99
- const A = D * D - 4 * N * E;
100
- if (A < 0) return [];
101
- const T = Math.sqrt(A), B = (-D - T) / (2 * N), F = (-D + T) / (2 * N), X = [];
102
- return B > 0 && B < 1 && X.push(B), F > 0 && F < 1 && F !== B && X.push(F), X;
103
- }, l = e[0], s = t[0], c = i[0], h = n[0], d = e[1], u = t[1], p = i[1], f = n[1], m = r(s - l, c - s, h - c), b = r(u - d, p - u, f - p);
104
- let x = Math.min(e[0], n[0]), k = Math.max(e[0], n[0]), M = Math.min(e[1], n[1]), S = Math.max(e[1], n[1]);
105
- for (const g of m) {
106
- const P = a(g);
107
- x = Math.min(x, P), k = Math.max(k, P);
108
- }
109
- for (const g of b) {
110
- const P = o(g);
111
- M = Math.min(M, P), S = Math.max(S, P);
112
- }
113
- return { minX: x, maxX: k, minY: M, maxY: S };
114
- }, Ti = (e, t) => e.style?.closedPoints === 1 && t.length > 2 ? [t[t.length - 2], ...t, t[0], t[1]] : [t[0], ...t, t[t.length - 1]], Di = (e, t, i, n) => ({ cp1: [t[0] + (i[0] - e[0]) / 6, t[1] + (i[1] - e[1]) / 6], cp2: [i[0] - (n[0] - t[0]) / 6, i[1] - (n[1] - t[1]) / 6] }), wa = (e) => {
115
- const t = new Path2D(), i = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
116
- if (i.length < 2) return t;
117
- t.moveTo(...i[0]);
118
- for (const n of i.slice(1)) t.lineTo(...n);
119
- return i.length > 2 && e.style?.closedPoints === 1 && t.lineTo(...i[0]), t;
120
- }, go = (e) => {
121
- const t = new Path2D();
122
- return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t.lineTo(...e.points[2]), t.lineTo(...e.points[0]), t;
123
- }, fo = (e, t) => ({ x: t.x - (e.style?.lineWidth ?? 0) / 2, y: t.y - (e.style?.lineWidth ?? 0) / 2, width: t.width + (e.style?.lineWidth ?? 0), height: t.height + (e.style?.lineWidth ?? 0) }), it = (e, t, i, n = fo) => {
124
- const a = t(e, i), o = n(e, a, i), r = [a.x + a.width / 2, a.y + a.height / 2], l = ((s, c, h = 0) => {
125
- if (h === 0) return s;
126
- const d = [[s.x, s.y], [s.x + s.width, s.y], [s.x + s.width, s.y + s.height], [s.x, s.y + s.height]].map((f) => Qe({ point: f, origin: c, rotation: h })), u = Math.min(...d.map((f) => f[0])), p = Math.min(...d.map((f) => f[1]));
127
- return { x: u, y: p, width: Math.max(...d.map((f) => f[0])) - u, height: Math.max(...d.map((f) => f[1])) - p };
128
- })(o, r, e.rotation);
129
- return { borders: a, outerBorders: o, center: r, boundingBox: l };
130
- }, Ht = (e, t, i) => {
131
- const { borders: n } = t;
132
- return { type: "rect", border: Wt(n), shapePath: e, line: _t({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: [Gt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...ua.map((a) => Gt({ x: n.x + n.width * a[0], y: n.y + n.height * a[1], radius: 7 / i.canvasSize.scaleRatio }))] };
133
- }, cn = ({ borderStart: e, borderSize: t, vector: i, settings: n, invertedAxe: a, anchor: o }) => {
134
- switch (o) {
135
- case 0: {
136
- if (a) {
137
- const l = Math.max(0, i - t) + 2 * n.selectionPadding;
138
- return [e + t - 2 * n.selectionPadding, l];
139
- }
140
- const r = Math.max(2 * n.selectionPadding, t - i);
141
- return [e + t - r, r];
142
- }
143
- case 0.5:
144
- return [e, t];
145
- case 1:
146
- if (a) {
147
- const r = Math.min(e, e + t + i);
148
- return [r, e - r + 2 * n.selectionPadding];
149
- }
150
- return [e, Math.max(2 * n.selectionPadding, t + i)];
151
- default:
152
- return [0, 0];
153
- }
154
- }, dn = ({ borderX: e, borderWidth: t, borderY: i, borderHeight: n, center: a, originalShape: o }) => {
155
- const r = [e + t / 2 - a[0], i + n / 2 - a[1]], [l, s] = Qe({ point: r, rotation: -(o.rotation ?? 0) });
156
- return { borderX: Be(e + l - r[0]), borderWidth: Be(t), borderY: Be(i + s - r[1]), borderHeight: Be(n) };
157
- }, vo = (e, t, i, n) => {
158
- const a = t.x + t.width / 2, o = t.y + t.height / 2, r = i ? 2 * e.borderWidth + t.width : Math.abs(t.width + 2 * (e.borderWidth - t.width)), l = n ? 2 * e.borderHeight + t.height : Math.abs(t.height + 2 * (e.borderHeight - t.height));
159
- return { ...e, borderHeight: l, borderWidth: r, borderX: a - r / 2, borderY: o - l / 2 };
160
- }, vt = (e, t, i, n, a = !1, o = !1) => {
161
- const { center: r, borders: l } = t.computed, s = Qe({ origin: r, point: e, rotation: t.rotation }), c = o && a ? [l.x + l.width / 2, l.x + l.width / 2] : [l.x + l.width - n.selectionPadding, l.x + n.selectionPadding], h = o && a ? [l.y + l.height / 2, l.y + l.height / 2] : [l.y + l.height - n.selectionPadding, l.y + n.selectionPadding], d = i.anchor[0] === 0 && s[0] >= c[0] || i.anchor[0] === 1 && s[0] <= c[1], u = i.anchor[1] === 0 && s[1] >= h[0] || i.anchor[1] === 1 && s[1] <= h[1], p = [ze(s[0], n, i.anchor[0] === 0 && !d || i.anchor[0] === 1 && d ? n.selectionPadding : -n.selectionPadding), ze(s[1], n, i.anchor[1] === 0 && !u || i.anchor[1] === 1 && u ? n.selectionPadding : -n.selectionPadding)];
162
- if (a && o) {
163
- const g = (({ roundCursorPosition: P, borders: z, center: N, selectionMode: D, originalShape: E, settings: A }) => {
164
- const { selectionPadding: T } = A, B = Math.max(1, z.width - 2 * T), F = Math.max(1, z.height - 2 * T), X = "ratio" in E && E.ratio ? E.ratio : B / F, Z = z.x + z.width / 2, ne = z.y + z.height / 2;
165
- let I = 1;
166
- if (D.anchor[0] !== 0.5 && D.anchor[1] !== 0.5) {
167
- const C = [(D.anchor[0] - 0.5) * B, (D.anchor[1] - 0.5) * F], $ = [P[0] - Z, P[1] - ne], Q = Math.hypot(C[0], C[1]) || 1;
168
- I = Math.hypot($[0], $[1]) / Q;
169
- } else if (D.anchor[0] === 0.5) {
170
- const C = (D.anchor[1] - 0.5) * F, $ = P[1] - ne, Q = Math.abs(C) || 1;
171
- I = Math.abs($) / Q;
172
- } else {
173
- const C = (D.anchor[0] - 0.5) * B, $ = P[0] - Z, Q = Math.abs(C) || 1;
174
- I = Math.abs($) / Q;
175
- }
176
- const j = 2 * T / (B + 2 * T), ee = B * Math.max(I, j), se = ee + 2 * T, he = ee / X + 2 * T;
177
- return { borderX: Z - se / 2, borderY: ne - he / 2, borderWidth: se, borderHeight: he, center: N, originalShape: E };
178
- })({ roundCursorPosition: p, borders: l, center: r, selectionMode: i, originalShape: t, settings: n });
179
- return { ...dn(g), isXinverted: d, isYinverted: u };
180
- }
181
- const f = n.gridGap ? [i.anchor[0] === 0 ? l.x : i.anchor[0] === 0.5 ? l.x + l.width / 2 : l.x + l.width, i.anchor[1] === 0 ? l.y : i.anchor[1] === 0.5 ? l.y + l.height / 2 : l.y + l.height] : Qe({ origin: r, point: i.cursorStartPosition, rotation: t.rotation }), m = [p[0] - f[0], p[1] - f[1]], [b, x] = cn({ borderStart: l.x, borderSize: l.width, vector: m[0], settings: n, invertedAxe: d, anchor: i.anchor[0] }), [k, M] = cn({ borderStart: l.y, borderSize: l.height, vector: m[1], settings: n, invertedAxe: u, anchor: i.anchor[1] }), S = a ? ((g, P, z, N, D, E, A, T, B, F, X) => {
182
- const { selectionPadding: Z } = X, ne = "ratio" in B && B.ratio ? B.ratio : (g.width - 2 * Z || 1) / (g.height - 2 * Z || 1), I = (N - 2 * Z) / (E - 2 * Z);
183
- let j, ee, se, he;
184
- return F.anchor[0] !== 0.5 && F.anchor[1] !== 0.5 ? I < ne ? (ee = D, he = E, se = (E - 2 * Z) * ne + 2 * Z, j = F.anchor[0] === 0 ? A ? g.x + g.width - 2 * Z : g.x + (g.width - se) : A ? g.x - se + 2 * Z : g.x) : (j = z, se = N, he = (N - 2 * Z) / ne + 2 * Z, ee = F.anchor[1] === 0 ? T ? g.y + g.height - 2 * Z : g.y + (g.height - he) : T ? g.y - he + 2 * Z : g.y) : F.anchor[0] !== 0.5 ? (j = z, se = N, he = (N - 2 * Z) / ne + 2 * Z, ee = g.y + (g.height - he) / 2) : (ee = D, he = E, se = (E - 2 * Z) * ne + 2 * Z, j = g.x + (g.width - se) / 2), { borderX: j, borderWidth: se, borderY: ee, borderHeight: he, center: P, originalShape: B };
185
- })(l, r, b, x, k, M, d, u, t, i, n) : { borderX: b, borderWidth: x, borderY: k, borderHeight: M, center: r, originalShape: t };
186
- return { ...dn(o ? vo(S, l, d, u) : S), isXinverted: d, isYinverted: u };
187
- }, Kt = (e, t) => {
188
- const i = Wt(e), n = it(e, Ei, t);
189
- return { ...e, path: i, computed: n, selection: Ht(i, n, t) };
190
- }, mo = Kt, xa = (e, t, i, n = 0, a = 0) => {
191
- const o = { toolId: e.id, type: e.type, id: Le(`${e.type}_`), x: t[0], y: t[1], width: n, height: a, style: { opacity: e.settings.opacity.default, fillColor: e.settings.fillColor.default, strokeColor: e.settings.strokeColor.default, lineWidth: e.settings.lineWidth.default, lineDash: e.settings.lineDash.default } };
192
- return Kt(o, i);
193
- }, yo = (e, t) => {
194
- e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
195
- }, Ei = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), hn = (e, t, i, [n, a] = [!1, !1]) => {
196
- const o = e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (n ? 0 : i.width) : i.x + (n ? i.width : 0), r = e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (a ? 0 : i.height) : i.y + (a ? i.height : 0);
197
- return wi([o, r], i.rotation ?? 0, t);
198
- }, Ma = (e, t, i) => {
199
- const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation, c = mt(e, t, i), h = (e.width || 1) * r, d = (e.height || 1) * l, u = yt(i, c.x, c.y, h, d);
200
- return Kt({ ...e, width: h, height: d, x: u[0] - h / 2, y: u[1] - d / 2, rotation: s ? -(e.rotation ?? 0) : e.rotation ?? 0 }, o);
201
- }, Ot = (e, t, i, n, a, o, r, l = "replace") => {
202
- let s = !1;
203
- if (a) {
204
- s = Et(e, a, i, n, !0, o ? 20 : void 0);
205
- const h = ((d, u, p) => {
206
- if (d.mode === "translate") return { mode: "translate", cursorStartPosition: p, originalShape: u, hasBeenDuplicated: !1, dateStart: Date.now(), selectedShapesLengthAtMouseDown: _(u).length };
207
- if (d.mode === "rotate") {
208
- const { center: f } = u.computed;
209
- return { mode: "rotate", cursorStartPosition: p, originalShape: u, center: [f[0], f[1]], selectedShapesLengthAtMouseDown: _(u).length };
210
- }
211
- return d.mode === "resize" ? { mode: "resize", cursorStartPosition: p, originalShape: u, anchor: d.anchor, selectedShapesLengthAtMouseDown: _(u).length } : void 0;
212
- })(s || { mode: "default" }, a, i);
213
- if (h?.mode === "resize" || h?.mode === "rotate") return { shape: a, mode: h };
214
- }
215
- const c = t.find((h) => _(a).find((d) => h.id === d?.id) ? s && Et(e, h, i, n, !0, o ? 20 : void 0) : !!La(e, h, i, n)) ?? (s ? a : void 0);
216
- if (a && a?.id === c?.id) return { shape: a, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: a, selectedShapesLengthAtMouseDown: _(a).length } };
217
- if (c) {
218
- if (l === "add") {
219
- const d = pe(Ca(a, [c]), n);
220
- return { shape: d, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: d, selectedShapesLengthAtMouseDown: _(a).length } };
221
- }
222
- if (l === "remove") {
223
- const d = pe(So(a, c), n);
224
- return { shape: d, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: d, selectedShapesLengthAtMouseDown: _(a).length } };
225
- }
226
- const h = _(a).find((d) => d.id === c?.id) ? a : pe([c], n);
227
- return { shape: h, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: h, selectedShapesLengthAtMouseDown: _(a).length } };
228
- }
229
- return { shape: l !== "replace" ? a : void 0, mode: { mode: r ? "selectionFrame" : "default" } };
230
- }, pe = (e, t) => {
231
- if (!e.length) return;
232
- if (e.length === 1) return e[0];
233
- const i = e.some((r) => r.rotation !== e[0].rotation) ? 0 : e[0]?.rotation ?? 0, n = ((r, l, s) => {
234
- const c = r.map((S) => [[S.computed.borders.x + s.selectionPadding, S.computed.borders.y + s.selectionPadding], [S.computed.borders.x - s.selectionPadding + S.computed.borders.width, S.computed.borders.y + s.selectionPadding], [S.computed.borders.x - s.selectionPadding + S.computed.borders.width, S.computed.borders.y - s.selectionPadding + S.computed.borders.height], [S.computed.borders.x + s.selectionPadding, S.computed.borders.y - s.selectionPadding + S.computed.borders.height]].map((g) => {
235
- const P = Qe({ point: [g[0], g[1]], origin: S.computed.center, rotation: -(S.rotation ?? 0) });
236
- return Qe({ point: [P[0], P[1]], origin: [0, 0], rotation: l });
237
- })), h = Math.min(...c.flatMap((S) => [S[0][0], S[1][0], S[2][0], S[3][0]])), d = Math.min(...c.flatMap((S) => [S[0][1], S[1][1], S[2][1], S[3][1]])), u = Math.max(...c.flatMap((S) => [S[0][0], S[1][0], S[2][0], S[3][0]])), p = Math.max(...c.flatMap((S) => [S[0][1], S[1][1], S[2][1], S[3][1]])), f = [(h + u) / 2, (d + p) / 2], m = Qe({ point: f, origin: [0, 0], rotation: -l }), b = [f[0] - m[0], f[1] - m[1]], x = Be(h - b[0]), k = Be(u - b[0]), M = Be(d - b[1]);
238
- return { width: k - x, height: Be(p - b[1]) - M, x, y: M };
239
- })(e, i, t), a = xa({ id: "group_selection", type: "rect", settings: ea }, [n.x, n.y], t, n.width, n.height), o = e.slice(1).reduce((r, l) => {
240
- const s = l.style ?? {}, c = {};
241
- for (const h in s) r[h] !== void 0 && s[h] !== void 0 && r[h] === s[h] && (c[h] = r[h]);
242
- return c;
243
- }, e[0].style ?? {});
244
- return { id: e.map((r) => r.id).join("-"), type: "group", shapes: e, rotation: i, visible: !0, locked: !1, selection: a.selection, x: a.x, y: a.y, width: a.width, height: a.height, style: o, computed: a.computed, path: a.path };
245
- }, _ = (e) => e ? e.type === "group" ? e.shapes : [e] : [], Ca = (e, t) => {
246
- const i = _(e);
247
- return [.../* @__PURE__ */ new Set([...i, ...t])];
248
- }, So = (e, t) => _(e).filter((i) => i.id !== t.id), ka = (e) => {
249
- const { clientX: t = 0, clientY: i = 0 } = "touches" in e && e.touches[0] ? e.touches[0] : "changedTouches" in e && e.changedTouches[0] ? e.changedTouches[0] : "clientX" in e ? e : {};
250
- return { clientX: t, clientY: i };
251
- }, Pa = (e, t, i) => {
252
- const { clientX: n, clientY: a } = ka(e), o = t.getBoundingClientRect();
253
- return [(n - o.left) / i.scaleRatio, (a - o.top) / i.scaleRatio];
254
- }, ft = (e, t, i) => {
255
- const { clientX: n, clientY: a } = ka(e), o = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
256
- return [(n - o.left) * (i.canvasSize.width / o.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (a - o.top) * (i.canvasSize.height / o.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
257
- }, at = (e) => "touches" in e, tt = (e, t, [i, n]) => Qe({ origin: [i, n], point: e, rotation: t }), wi = (e, t, [i, n]) => Qe({ origin: [i, n], point: e, rotation: -t }), Ft = (e, t, i) => i ? Sa(e, { x: t[0], y: t[1], radius: i }) : ((n, a) => a[0] >= n.x && a[0] <= n.x + n.width && a[1] >= n.y && a[1] <= n.y + n.height)(e, t), Et = (e, t, i, n, a = !1, o = 0) => {
258
- const r = _(t).length > 1 ? t : _(t)[0];
259
- if (!r) return !1;
260
- const { borders: l, center: s } = r.computed, c = tt(i, r.rotation ?? 0, s);
261
- if (a) {
262
- const h = ((d, u, p, f = 0) => {
263
- const { canvasSize: { scaleRatio: m } } = p, { borders: b } = d.computed;
264
- if (d.type === "line" || d.type === "polygon" || d.type === "curve") {
265
- for (let x = 0; x < d.points.length; x++) if (Ft({ x: d.points[x][0] - 7 / m, y: d.points[x][1] - 7 / m, width: gt / m, height: gt / m }, u, f)) return { mode: "resize", anchor: x };
266
- } else {
267
- if (Ft({ x: b.x + b.width / 2 - 7 / m, y: b.y - gt / m - 16 / m, width: gt / m, height: gt / m }, u, f)) return { mode: "rotate" };
268
- for (const x of ua) if (Ft({ x: b.x + b.width * x[0] - 7 / m, y: b.y + b.height * x[1] - 7 / m, width: gt / m, height: gt / m }, u, f)) return { mode: "resize", anchor: x };
269
- }
270
- return !1;
271
- })(r, c, n, o);
272
- if (h) return h;
273
- }
274
- return r.selection?.type === "line" ? (e.lineWidth = (r.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(Ii(r, !0) ? e.isPointInPath(r.path, c[0], c[1]) : e.isPointInStroke(r.path, c[0], c[1])) && { mode: "translate" }) : !!Ft(l, c, 15 + o) && { mode: "translate" };
275
- }, un = (e, t, i, n, a = 50) => {
276
- if (t.locked || t.points.length < 2) return !1;
277
- const { center: o } = t.computed, r = tt(i, t.rotation ?? 0, o);
278
- e.lineWidth = (t.style?.lineWidth ?? 0) + a / n.canvasZoom;
279
- const l = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
280
- for (let s = 0; s < l.length - 1; s++) {
281
- const c = _t({ points: [l[s], l[s + 1]] });
282
- if (e.isPointInStroke(c, r[0], r[1])) return { lineIndex: s };
283
- }
284
- return !1;
285
- }, Ii = (e, t = !1) => !(!t || !["curve", "polygon"].includes(e.type)) || e.style?.fillColor && e.style?.fillColor !== "transparent" || ["picture", "text"].includes(e.type), La = (e, t, i, n) => {
286
- const { center: a } = t.computed, o = tt(i, t.rotation ?? 0, a);
287
- return e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(Ii(t) ? e.isPointInPath(t.path, o[0], o[1]) : e.isPointInStroke(t.path, o[0], o[1])) && { mode: "translate" };
288
- };
289
- function xi(e, t) {
290
- const i = Math.max(e.x, t.x), n = Math.max(e.y, t.y), a = Math.min(e.x + (e.width || 1), t.x + (t.width || 1)), o = Math.min(e.y + (e.height || 1), t.y + (t.height || 1));
291
- if (i < a && n < o) return { x: i, y: n, width: a - i, height: o - n };
292
- }
293
- const pn = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, checkFill: r }) => {
294
- for (let l = 0; l < n; l += n / 2) for (let s = 0; s < n; s += n / 2) for (let c = l + i.x; c < i.x + i.width; c += n) for (let h = s + i.y; h < i.y + i.height; h += n) {
295
- const d = tt([c, h], o, a);
296
- if (r ? e.isPointInPath(t, d[0], d[1]) : e.isPointInStroke(t, d[0], d[1])) return !0;
297
- }
298
- return !1;
299
- }, Wi = (e, t, i, n) => ({ type: "line", border: Wt(i.borders), shapePath: e, anchors: [...t.points.map((a) => Gt({ x: a[0], y: a[1], radius: 7 / n.canvasSize.scaleRatio }))] }), Re = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], Mi = ({ size: e, zoom: t, newOffset: [i, n], canvasSize: a }) => e === "infinite" ? { zoom: t, offset: [i, n] } : t < 1 ? { zoom: t, offset: [-(a.realWidth - a.realWidth / t) / 2, -(a.realHeight - a.realHeight / t) / 2] } : { zoom: t, offset: [et(i, a.realWidth / t - a.realWidth, 0), et(n, a.realHeight / t - a.realHeight, 0)] }, Ci = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: n, zoom: a, centerPoint: o }) => {
300
- const r = e === "fixed" && a < 1 ? [t.realWidth / 2, t.realHeight / 2] : o, l = i[0] - (r[0] / n - r[0] / a), s = i[1] - (r[1] / n - r[1] / a);
301
- return { offset: e === "infinite" ? [l, s] : a < 1 ? [-(t.realWidth - t.realWidth / a) / 2, -(t.realHeight - t.realHeight / a) / 2] : [et(l, t.realWidth / a - t.realWidth, 0), et(s, t.realHeight / a - t.realHeight, 0)], zoom: a };
302
- }, Va = (e) => {
303
- const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: n }, canvasZoom: a, canvasOffset: o } = e;
304
- return { x: o[0] * a * n, y: o[1] * a * n, width: t * a, height: i * a };
305
- }, Za = (e, t) => {
306
- const { canvasZoom: i, size: n } = t;
307
- if (n !== "fixed" || i >= 1) return;
308
- const a = Va(t);
309
- e.beginPath(), e.rect(a.x, a.y, a.width, a.height), e.closePath(), e.clip();
310
- }, Dt = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, bo = (e, t) => ({ x: e.x - e.radius - t.selectionPadding, width: 2 * (e.radius + t.selectionPadding), y: e.y - e.radius - t.selectionPadding, height: 2 * (e.radius + t.selectionPadding) }), Jt = (e, t) => {
311
- const i = Gt(e), n = it(e, bo, t);
312
- return { ...e, path: i, selection: Ht(i, n, t), computed: n };
313
- }, Qo = Jt, Ha = (e, t, i) => {
314
- const n = mt(e, t, i), a = (e.radius || 0.5) * i.widthMultiplier, o = yt(i, n.x, n.y, 2 * a, 2 * a);
315
- return Jt({ ...e, radius: a, x: o[0], y: o[1] }, i.settings);
316
- }, zt = (e, t) => {
317
- const i = wa(e), n = it(e, ei, t);
318
- return { ...e, path: i, selection: Wi(i, e, n, t), computed: n };
319
- }, za = zt, ei = (e, t) => {
320
- const i = Math.min(...e.points.map((o) => o[0])) - t.selectionPadding, n = Math.max(...e.points.map((o) => o[0])) + t.selectionPadding, a = Math.min(...e.points.map((o) => o[1])) - t.selectionPadding;
321
- return { x: i, width: n - i, y: a, height: Math.max(...e.points.map((o) => o[1])) + t.selectionPadding - a };
322
- }, wo = (e, t, i, n) => {
323
- if (t < 0 || t > e.points.length - 1) return e;
324
- const a = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
325
- return zt({ ...e, points: a }, n);
326
- }, gn = (e, t, i, n = !1) => {
327
- const a = [ze(t[0], i), ze(t[1], i)], o = tt(a, e.rotation ?? 0, e.computed.center), r = { ...e, points: n ? e.points : [...e.points, o], tempPoint: n ? o : void 0 };
328
- return zt(r, i);
329
- }, xo = (e, t, i) => {
330
- const n = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
331
- if (n.length < 2) {
332
- const c = n[0] ?? [0, 0], h = i.selectionPadding;
333
- return { x: c[0] - h, y: c[1] - h, width: 2 * h, height: 2 * h };
334
- }
335
- if (n.length < 3) return ei({ ...e, points: n }, i);
336
- const a = Ti(e, n);
337
- let o = Number.POSITIVE_INFINITY, r = Number.NEGATIVE_INFINITY, l = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
338
- for (let c = 1; c < a.length - 2; c++) {
339
- const h = a[c - 1], d = a[c], u = a[c + 1], p = a[c + 2], { cp1: f, cp2: m } = Di(h, d, u, p), b = po(d, f, m, u);
340
- o = Math.min(o, b.minX), r = Math.max(r, b.maxX), l = Math.min(l, b.minY), s = Math.max(s, b.maxY);
341
- }
342
- return Ei({ x: o, y: l, width: r - o, height: s - l }, i);
343
- }, At = (e, t) => {
344
- const i = ((a) => {
345
- const o = new Path2D(), r = a.tempPoint ? [...a.points, a.tempPoint] : a.points;
346
- if (r.length < 2) return o;
347
- if (r.length < 3) return wa(a);
348
- const l = a.style?.closedPoints === 1 && r.length > 2;
349
- o.moveTo(...r[0]);
350
- const s = Ti(a, r);
351
- for (let c = 1; c < s.length - 2; c++) {
352
- const h = s[c - 1], d = s[c], u = s[c + 1], p = s[c + 2], { cp1: f, cp2: m } = Di(h, d, u, p);
353
- o.bezierCurveTo(f[0], f[1], m[0], m[1], u[0], u[1]);
354
- }
355
- return l && o.closePath(), o;
356
- })(e), n = it(e, ei, t, xo);
357
- return { ...e, path: i, selection: Wi(i, e, n, t), computed: n };
358
- }, Aa = At, Mo = (e, t, i, n) => {
359
- if (t < 0 || t > e.points.length - 1) return e;
360
- const a = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
361
- return At({ ...e, points: a }, n);
362
- }, fn = (e, t, i, n = !1) => {
363
- const a = [ze(t[0], i), ze(t[1], i)], o = e.computed.center, r = tt(a, e.rotation ?? 0, o), l = { ...e, points: n ? e.points : [...e.points, r], tempPoint: n ? r : void 0 };
364
- return At(l, i);
365
- }, Co = (e, t) => ({ x: e.x - e.radiusX - t.selectionPadding, width: 2 * (e.radiusX + t.selectionPadding), y: e.y - e.radiusY - t.selectionPadding, height: 2 * (e.radiusY + t.selectionPadding) }), ti = (e, t) => {
366
- const i = ((a) => {
367
- const o = new Path2D();
368
- return o.ellipse(a.x, a.y, a.radiusX, a.radiusY, 0, 0, 2 * Math.PI), o;
369
- })(e), n = it(e, Co, t);
370
- return { ...e, path: i, selection: Ht(i, n, t), computed: n };
371
- }, ko = ti, Ta = (e, t, i) => {
372
- const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation, c = mt(e, t, i), h = (e.radiusX || 0.5) * r, d = (e.radiusY || 0.5) * l, u = yt(i, c.x, c.y, 2 * h, 2 * d);
373
- return ti({ ...e, radiusX: h, radiusY: d, x: u[0], y: u[1], rotation: s ? -(e.rotation ?? 0) : e.rotation ?? 0 }, o);
374
- }, vn = (e, t) => ((i, n) => ({ ...i, path: go(i), computed: it(i, ei, n) }))({ ...e, id: Le("triangle_"), type: "triangle" }, t), Po = (e, t) => {
375
- e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
376
- }, Lo = (e, t) => ({ x: Math.min(e.points[0][0], e.points[1][0]) - t.selectionPadding, width: Math.abs(e.points[0][0] - e.points[1][0]) + 2 * t.selectionPadding, y: Math.min(e.points[0][1], e.points[1][1]) - t.selectionPadding, height: Math.abs(e.points[0][1] - e.points[1][1]) + 2 * t.selectionPadding }), ii = (e, t) => {
377
- const i = [];
378
- let n;
379
- if (e.style?.lineArrow === 1 || e.style?.lineArrow === 2 || e.style?.lineArrow === 3) {
380
- const o = Math.PI / 2 - ln({ targetVector: [e.points[0], e.points[1]] });
381
- e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(vn(mn(e.points[0], o, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(vn(mn(e.points[1], o + Math.PI, e.style), t));
382
- const r = (({ line: l, size: s, direction: c }) => {
383
- const h = Math.PI / 2 - ln({ targetVector: [l.points[0], l.points[1]] }), d = [l.points[0][0] + (l.points[1][0] - l.points[0][0]) / 2, l.points[0][1] + (l.points[1][1] - l.points[0][1]) / 2];
384
- let u, p;
385
- if (["start", "both"].includes(c)) {
386
- const f = Qe({ point: l.points[0], origin: d, rotation: -h });
387
- u = Qe({ point: [f[0], f[1] + s], origin: d, rotation: h });
388
- } else u = [...l.points[0]];
389
- if (["end", "both"].includes(c)) {
390
- const f = Qe({ point: l.points[1], origin: d, rotation: -h });
391
- p = Qe({ point: [f[0], f[1] - s], origin: d, rotation: h });
392
- } else p = [...l.points[1]];
393
- return { points: [u, p] };
394
- })({ line: e, size: 10 + 2 * (e.style?.lineWidth ?? 0), direction: e.style?.lineArrow === 1 ? "start" : e.style?.lineArrow === 2 ? "end" : "both" });
395
- n = _t(r);
396
- } else n = _t(e);
397
- const a = it(e, Lo, t);
398
- return { ...e, path: n, selection: Wi(n, e, a, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: a };
399
- }, Vo = ii, mn = (e, t, i) => {
400
- const n = [Qe({ point: [0, 0], rotation: t }), Qe({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), Qe({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
401
- return { points: [[e[0] + n[0][0], e[1] + n[0][1]], [e[0] + n[1][0], e[1] + n[1][1]], [e[0] + n[2][0], e[1] + n[2][1]]], style: { ...i, fillColor: i.strokeColor, strokeColor: "transparent" } };
402
- }, Da = (e, t, i) => {
403
- const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = e.computed.borders.width - 2 * o.selectionPadding, c = e.computed.borders.height - 2 * o.selectionPadding, h = s * r, d = c * l, u = mt(e, t, i), p = yt(i, u.x, u.y, h, d), f = e.computed.center[0] - s / 2, m = e.computed.center[1] - c / 2, b = p[0] - h / 2, x = p[1] - d / 2;
404
- return ((k, M) => k.type === "line" ? ii(k, M) : k.type === "polygon" ? za(k, M) : Aa(k, M))({ ...e, points: e.points.map(([k, M]) => [b + (n ? h - (k - f) * r : (k - f) * r), x + (a ? d - (M - m) * l : (M - m) * l)]) }, i.settings);
405
- }, ni = (e, t) => {
406
- const i = it(e, Ei, t), n = Wt(e);
407
- return { ...e, path: n, selection: Ht(void 0, i, t), computed: i };
408
- }, Zo = ni, gi = (e, t, i, n, a) => {
409
- const [o, r] = ((l, s, c, h, d = !1) => {
410
- if (!(l && s && h && c)) return [sn, sn];
411
- const u = l / s;
412
- if (u > c / h) {
413
- const f = d ? c : Math.min(l, c);
414
- return [f, f / u];
415
- }
416
- const p = d ? h : Math.min(s, h);
417
- return [p * u, p];
418
- })(e.width, e.height, i, n, !0);
419
- return ni({ toolId: zi.id, type: "picture", id: Le("picture_"), x: -a.canvasOffset[0] + a.canvasSize.realWidth / a.canvasZoom / 2 - o / 2, y: -a.canvasOffset[1] + a.canvasSize.realHeight / a.canvasZoom / 2 - r / 2, width: o, height: r, ratio: o / r, src: t, img: e }, a);
420
- }, Ho = (e, t, i, n) => new Promise((a, o) => {
421
- const r = new Image();
422
- r.onerror = () => {
423
- o(new Error("Some images could not be loaded"));
424
- }, setTimeout(() => {
425
- o(new Error("Timeout while loading images"));
426
- }, 4e3), e instanceof File ? ((l, s, c, h, d, u) => {
427
- Ya(c) ? c.text().then((p) => {
428
- const f = Fa(p);
429
- l.onload = async () => {
430
- URL.revokeObjectURL(l.src);
431
- const m = gi(l, p, h, d, u);
432
- s(m);
433
- }, l.src = f;
434
- }) : (l.onload = async () => {
435
- URL.revokeObjectURL(l.src);
436
- const p = gi(l, l.src, h, d, u);
437
- s(p);
438
- }, l.src = URL.createObjectURL(c));
439
- })(r, a, e, t, i, n) : ((l, s, c, h, d, u) => {
440
- l.onload = () => {
441
- URL.revokeObjectURL(l.src);
442
- const p = gi(l, c, h, d, u);
443
- s(p);
444
- }, Xa(c).then((p) => {
445
- l.src = p;
446
- }).catch(() => {
447
- l.src = "";
448
- });
449
- })(r, a, e, t, i, n);
450
- }), Ea = (e, t, i) => {
451
- const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = mt(e, t, i), c = (e.width === 0 || e.height === 0 ? e.ratio ?? 1 : e.width) * r, h = (e.width === 0 || e.height === 0 ? e.ratio ?? 1 : e.height) * l, d = yt(i, s.x, s.y, c, h), u = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation;
452
- return ni({ ...e, width: c, height: h, x: d[0] - c / 2, y: d[1] - h / 2, flipX: n ? !e.flipX : !!e.flipX, flipY: a ? !e.flipY : !!e.flipY, rotation: u ? -(e.rotation ?? 0) : e.rotation ?? 0 }, o);
453
- }, fi = ["Texte"], Ia = (e, t) => it(e, Ao, t), ai = (e, t) => {
454
- const i = Ia(e, t), n = Wt(e);
455
- return { ...e, path: n, selection: Ht(void 0, i, t), computed: i };
456
- }, zo = ai, oi = (e, t, i, n, a, o = It) => {
457
- e.font = `${a ? "italic" : ""} ${n ? "bold" : ""} 1px ${o}`;
458
- const r = t.map((l) => i / e.measureText(l).width);
459
- return Math.min(...r) || 36;
460
- }, Ao = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), Wa = (e, t, i, n) => {
461
- const { isXinverted: a, isYinverted: o, settings: r, widthMultiplier: l, heightMultiplier: s } = n, c = (a || o) && !(a && o) && (t.rotation ?? 0) !== 0 && n.rotation !== t.rotation, h = mt(t, i, n), d = (t.width === 0 || t.height === 0 ? t.ratio ?? 1 : t.width) * l, u = (t.width === 0 || t.height === 0 ? t.ratio ?? 1 : t.height) * s, p = yt(n, h.x, h.y, d, u), f = ai({ ...t, width: d, height: u, x: p[0] - d / 2, y: p[1] - u / 2, flipX: a ? !t.flipX : !!t.flipX, flipY: o ? !t.flipY : !!t.flipY, rotation: c ? -(t.rotation ?? 0) : t.rotation ?? 0 }, r);
462
- return { ...f, fontSize: oi(e, f.value, f.width, f.style?.fontBold ?? !1, f.style?.fontItalic ?? !1, f.style?.fontFamily) };
463
- }, To = (e, t, i, n) => {
464
- const a = { ...t, value: i }, o = ((f, m, b, x, k, M = It) => {
465
- f.font = `${k ? "italic" : ""} ${x ? "bold" : ""} ${b}px ${M}`;
466
- const S = m.map((g) => f.measureText(g).width);
467
- return Math.max(...S) || 20;
468
- })(e, a.value, a.fontSize, a.style?.fontBold ?? !1, a.style?.fontItalic ?? !1, a.style?.fontFamily), r = a.fontSize * a.value.length, l = o / r, s = { ...a, width: o, height: r, ratio: l }, { center: c } = Ia(s, n), [h, d] = hn([1, 1], t.computed.center, t), [u, p] = hn([1, 1], c, s, [!1, !1]);
469
- return { ...s, x: s.x - (u - h), y: s.y - (p - d) };
470
- }, yn = (e, t, i, n) => {
471
- const a = [ze(i[0], n), ze(i[1], n)];
472
- switch (t.type) {
473
- case "brush":
474
- return ((o, r, l) => Zt({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [[r]], scaleX: 1, scaleY: 1, style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, a, n);
475
- case "line":
476
- return ((o, r, l) => {
477
- const s = { toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [r, r], style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, lineArrow: o.settings.lineArrow.default } };
478
- return ii(s, l);
479
- })(t, a, n);
480
- case "polygon":
481
- return ((o, r, l) => zt({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [r], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, l))(t, a, n);
482
- case "curve":
483
- return ((o, r, l) => At({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [r], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, l))(t, a, n);
484
- case "rect":
485
- case "square":
486
- return xa(t, a, n);
487
- case "text":
488
- return ((o, r, l, s) => {
489
- const c = oi(o, fi, 150, r.settings?.fontBold.default ?? !1, r.settings?.fontItalic.default ?? !1, r.settings.fontFamily.default), h = c * (fi.length || 1);
490
- return ai({ toolId: r.id, type: r.type, id: Le(`${r.type}_`), x: l[0] - 150, y: l[1] - h, value: fi, fontSize: c, width: 150, height: h, ratio: 150 / h, style: { opacity: r.settings.opacity.default, strokeColor: r.settings.strokeColor.default, fontFamily: r.settings.fontFamily.default, fontItalic: r.settings.fontItalic.default, fontBold: r.settings.fontBold.default } }, s);
491
- })(e, t, a, n);
492
- case "ellipse":
493
- return ((o, r, l) => ti({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), x: r[0], y: r[1], radiusX: 0, radiusY: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, a, n);
494
- case "circle":
495
- return ((o, r, l) => Jt({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), x: r[0], y: r[1], radius: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, a, n);
496
- }
497
- }, Sn = (e, t) => {
498
- switch (t.type) {
499
- case "brush":
500
- ((i, n) => {
501
- n.points.length < 1 || i.globalAlpha !== 0 && n.style?.strokeColor !== "transparent" && i.globalAlpha !== 0 && i.stroke(n.path);
502
- })(e, t);
503
- break;
504
- case "text":
505
- ((i, n) => {
506
- if (i.globalAlpha !== 0 && n.style?.strokeColor && n.style.strokeColor !== "transparent") {
507
- i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.font = `${n.style?.fontItalic ? "italic" : ""} ${n.style?.fontBold ? "bold" : ""} ${n.fontSize}px ${n.style?.fontFamily ?? It}`, i.textBaseline = "top", i.fillStyle = n.style.strokeColor;
508
- for (let a = 0; a < n.value.length; a++) i.fillText(n.value[a], n.flipX ? -n.x - n.width : n.x, (n.flipY ? -n.y - n.height : n.y) + a * n.fontSize, n.width);
509
- }
510
- })(e, t);
511
- break;
512
- case "line":
513
- ((i, n) => {
514
- if (i.globalAlpha !== 0) {
515
- n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path);
516
- for (const a of n.arrows ?? []) De(i, a.style), Po(i, a);
517
- }
518
- })(e, t);
519
- break;
520
- case "polygon":
521
- ((i, n) => {
522
- i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
523
- })(e, t);
524
- break;
525
- case "curve":
526
- ((i, n) => {
527
- i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
528
- })(e, t);
529
- break;
530
- case "circle":
531
- ((i, n) => {
532
- i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
533
- })(e, t);
534
- break;
535
- case "ellipse":
536
- ((i, n) => {
537
- i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
538
- })(e, t);
539
- break;
540
- case "rect":
541
- case "square":
542
- yo(e, t);
543
- break;
544
- case "picture":
545
- ((i, n) => {
546
- i.globalAlpha !== 0 && (i.beginPath(), i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.drawImage(n.img, n.flipX ? -n.x - n.width : n.x, n.flipY ? -n.y - n.height : n.y, n.width, n.height));
547
- })(e, t);
548
- }
549
- }, Ra = (e, t, i) => {
550
- if (t.visible === !1) return;
551
- if (((a, o) => {
552
- const r = ((l) => {
553
- const { canvasSize: { width: s, height: c, scaleRatioWithNoZoom: h }, canvasZoom: d, canvasOffset: u } = l;
554
- return { x: -u[0], y: -u[1], width: s / d / h, height: c / d / h };
555
- })(o);
556
- return !!xi(a.computed.boundingBox, r);
557
- })(t, i)) {
558
- if (kt(e, i, t.rotation, t.computed.center), De(e, t.style), e.globalAlpha !== 1) return ((a, o) => {
559
- const { outerBorders: r } = o.computed, l = { width: 2 * r.width, height: 2 * r.height };
560
- if (l.width === 0 || l.height === 0) return;
561
- const s = document.createElement("canvas"), c = s.getContext("2d");
562
- if (!c) throw new Error("No context found for canvas");
563
- s.width = l.width, s.height = l.height, c.translate(l.width / 4 - r.x, l.height / 4 - r.y), De(c, { ...o.style, opacity: 100 }), Sn(c, o), a.drawImage(s, r.x - l.width / 4, r.y - l.height / 4);
564
- })(e, t), void e.restore();
565
- Sn(e, t), e.restore();
566
- }
567
- }, Na = (e, t, i) => {
568
- if (e.locked) return e;
569
- const n = Qe({ origin: i, point: e.computed.center, rotation: -t });
570
- if ("points" in e) {
571
- if (e.type === "brush") {
572
- const o = e.points.map((r) => r.map((l) => [l[0] + n[0] - e.computed.center[0], l[1] + n[1] - e.computed.center[1]]));
573
- return { ...e, points: o, rotation: (e.rotation ?? 0) + t };
574
- }
575
- const a = e.points.map((o) => Qe({ origin: i, point: o, rotation: -t }));
576
- return { ...e, points: a };
577
- }
578
- return { ...e, x: e.x + n[0] - e.computed.center[0], y: e.y + n[1] - e.computed.center[1], rotation: (e.rotation ?? 0) + t };
579
- }, bn = (e, t, i, n, a, o, r) => {
580
- if (i.locked) return i;
581
- switch (i.type) {
582
- case "line":
583
- return ((l, s, c, h) => {
584
- const d = [ze(l[0], h), ze(l[1], h)], u = tt(d, s.rotation ?? 0, s.computed.center), p = Xe(["points", c.anchor], u, s);
585
- return ii(p, h);
586
- })(t, i, n, a);
587
- case "polygon":
588
- return ((l, s, c, h) => {
589
- const d = [ze(l[0], h), ze(l[1], h)], u = tt(d, s.rotation ?? 0, s.computed.center), p = Xe(["points", c.anchor], u, s);
590
- return zt(p, h);
591
- })(t, i, n, a);
592
- case "curve":
593
- return ((l, s, c, h) => {
594
- const d = [ze(l[0], h), ze(l[1], h)], u = s.computed.center, p = tt(d, s.rotation ?? 0, u), f = Xe(["points", c.anchor], p, s);
595
- return At(f, h);
596
- })(t, i, n, a);
597
- case "brush":
598
- return ((l, s, c, h, d, u) => {
599
- const p = Ai({ ...s, scaleX: 1, scaleY: 1 }, h), f = s.computed.borders, { borderX: m, borderHeight: b, borderY: x, borderWidth: k, isXinverted: M, isYinverted: S } = vt(l, s, c, h, d, u), g = Math.max(0, p.width - 2 * h.selectionPadding), P = Math.max(0, p.height - 2 * h.selectionPadding), z = Math.max(0, k - 2 * h.selectionPadding), N = Math.max(0, b - 2 * h.selectionPadding), D = g ? z / g : 1, E = P ? N / P : 1;
600
- if (!g || !P) return s;
601
- const A = Be(m - f.x) + (M ? 2 * f.x + p.width : 0), T = Be(x - f.y) + (S ? 2 * f.y + p.height : 0);
602
- return Zt({ ...s, points: s.points.map((B) => B.map(([F, X]) => [M ? -F + A : F + A, S ? -X + T : X + T])), scaleX: D, scaleY: E }, h);
603
- })(t, i, n, a, o, r);
604
- case "circle":
605
- return ((l, s, c, h, d) => {
606
- const { borderX: u, borderHeight: p, borderY: f, borderWidth: m } = vt(l, s, c, h, !0, d);
607
- return Jt({ ...s, radius: Math.max(0, m / 2 - h.selectionPadding), x: u + m / 2, y: f + p / 2 }, h);
608
- })(t, i, n, a, r);
609
- case "ellipse":
610
- return ((l, s, c, h, d = !1, u = !1) => {
611
- const { borderX: p, borderHeight: f, borderY: m, borderWidth: b } = vt(l, s, c, h, d, u);
612
- return ti({ ...s, radiusX: Math.max(0, b / 2 - h.selectionPadding), radiusY: Math.max(0, f / 2 - h.selectionPadding), x: p + b / 2, y: m + f / 2 }, h);
613
- })(t, i, n, a, o, r);
614
- case "rect":
615
- case "square":
616
- return ((l, s, c, h, d = !1, u = !1) => {
617
- const { borderX: p, borderHeight: f, borderY: m, borderWidth: b } = vt(l, s, c, h, d, u);
618
- return Kt({ ...s, width: Math.max(0, b - 2 * h.selectionPadding), height: Math.max(0, f - 2 * h.selectionPadding), x: p + h.selectionPadding, y: m + h.selectionPadding }, h);
619
- })(t, i, n, a, i.type === "square" || o, r);
620
- case "text":
621
- return ((l, s, c, h, d, u) => {
622
- const { borderX: p, borderHeight: f, borderY: m, borderWidth: b, isXinverted: x, isYinverted: k } = vt(s, c, h, d, !0, u), M = Math.max(0, b - 2 * d.selectionPadding), S = Math.max(0, f - 2 * d.selectionPadding), g = ai({ ...c, width: M, height: S, x: p + d.selectionPadding, y: m + d.selectionPadding, flipX: x ? !c.flipX : !!c.flipX, flipY: k ? !c.flipY : !!c.flipY }, d);
623
- return { ...g, fontSize: oi(l, g.value, g.width, g.style?.fontBold ?? !1, g.style?.fontItalic ?? !1, g.style?.fontFamily) };
624
- })(e, t, i, n, a, r);
625
- case "picture":
626
- return ((l, s, c, h, d) => {
627
- const { borderX: u, borderHeight: p, borderY: f, borderWidth: m, isXinverted: b, isYinverted: x } = vt(l, s, c, h, !0, d), k = Math.max(0, m - 2 * h.selectionPadding), M = Math.max(0, p - 2 * h.selectionPadding);
628
- return ni({ ...s, width: k, height: M, x: u + h.selectionPadding, y: f + h.selectionPadding, flipX: b ? !s.flipX : !!s.flipX, flipY: x ? !s.flipY : !!s.flipY }, h);
629
- })(t, i, n, a, r);
630
- default:
631
- return i;
632
- }
633
- }, Do = (e, t, i, n, a, o, r) => {
634
- if (i.type !== "group") return _(i).map((f) => bn(e, t, f, n, a, o, r));
635
- const l = i, s = _(l), c = s.filter((f) => so.includes(f.type)), h = !c.some((f) => (f.rotation ?? 0) !== (c[0]?.rotation ?? 0)), d = (c[0]?.rotation ?? 0) !== 0 && c.length !== s.length, u = s.some((f) => ro.includes(f.type)), p = ((f, m, b, x, k, M) => {
636
- const { borders: S } = m.computed, { borderX: g, borderHeight: P, borderY: z, borderWidth: N, isXinverted: D, isYinverted: E } = vt(f, m, b, x, k, M);
637
- return { newBorderX: g, newBorderY: z, newBorderWidth: N, newBorderHeight: P, widthMultiplier: (N - 2 * x.selectionPadding) / (S.width - 2 * x.selectionPadding || 1), heightMultiplier: (P - 2 * x.selectionPadding) / (S.height - 2 * x.selectionPadding || 1), isXinverted: D, isYinverted: E, groupCenter: [g + N / 2, z + P / 2], rotation: m.rotation ?? 0, settings: x, originalBorders: S };
638
- })(t, l, n, a, o || !h || u || d, r);
639
- return s.map((f) => {
640
- if (f.locked) return f;
641
- switch (f.type) {
642
- case "rect":
643
- case "square":
644
- return Ma(f, l, p);
645
- case "picture":
646
- return Ea(f, l, p);
647
- case "text":
648
- return Wa(e, f, l, p);
649
- case "ellipse":
650
- return Ta(f, l, p);
651
- case "circle":
652
- return Ha(f, l, p);
653
- case "brush":
654
- return Qa(f, l, p);
655
- case "line":
656
- case "polygon":
657
- case "curve":
658
- return Da(f, l, p);
659
- default:
660
- return bn(e, t, f, n, a, o, r);
661
- }
662
- });
663
- }, Ba = (e, t, i, n) => {
664
- if (e.locked) return e;
665
- switch (e.type) {
666
- case "rect":
667
- case "square":
668
- case "ellipse":
669
- case "circle":
670
- case "picture":
671
- case "text":
672
- return _e({ ...e, x: e.x + t, y: e.y + i }, n);
673
- case "line":
674
- case "polygon":
675
- case "curve":
676
- return _e({ ...e, points: e.points.map(([a, o]) => [a + t, o + i]) }, n);
677
- case "brush":
678
- return _e({ ...e, points: e.points.map((a) => a.map(([o, r]) => [o + t, r + i])) }, n);
679
- default:
680
- return e;
681
- }
682
- }, Oa = (e, t, i, n, a) => {
683
- const o = t.computed.borders, r = ((c, h) => h ? [Math.abs(c[0]) > Math.abs(c[1]) ? c[0] : 0, Math.abs(c[1]) > Math.abs(c[0]) ? c[1] : 0] : c)([e[0] - i[0], e[1] - i[1]], a), l = r[0] === 0 ? 0 : ze(o.x + n.selectionPadding + r[0], n) - (o.x + n.selectionPadding), s = r[1] === 0 ? 0 : ze(o.y + n.selectionPadding + r[1], n) - (o.y + n.selectionPadding);
684
- return _(t).map((c) => Ba(c, l, s, n));
685
- }, _e = (e, t) => {
686
- switch (e.type) {
687
- case "rect":
688
- case "square":
689
- return mo(e, t);
690
- case "ellipse":
691
- return ko(e, t);
692
- case "circle":
693
- return Qo(e, t);
694
- case "picture":
695
- return Zo(e, t);
696
- case "text":
697
- return zo(e, t);
698
- case "line":
699
- return Vo(e, t);
700
- case "polygon":
701
- return za(e, t);
702
- case "curve":
703
- return Aa(e, t);
704
- case "brush":
705
- return co(e, t);
706
- default:
707
- return e;
708
- }
709
- }, Qn = ({ ctx: e, shape: t, settings: i, selectionWidth: n, selectionColor: a, hoverMode: o, selectionMode: r, withAnchors: l = !0 }) => {
710
- switch (i.debug && ((s, c, h, d) => {
711
- c.selection && d.debug && (s.save(), s.scale(d.canvasSize.scaleRatio, d.canvasSize.scaleRatio), s.translate(d.canvasOffset[0], d.canvasOffset[1]), De(s, { fillColor: "transparent", strokeColor: "green", lineWidth: h / d.canvasSize.scaleRatio }), s.strokeRect(c.computed.boundingBox.x, c.computed.boundingBox.y, c.computed.boundingBox.width, c.computed.boundingBox.height), s.restore());
712
- })(e, t, n, i), t.type) {
713
- case "rect":
714
- case "square":
715
- case "circle":
716
- case "ellipse":
717
- case "picture":
718
- case "text":
719
- case "brush":
720
- ((s, c, h, d, u, p) => {
721
- if (c.selection && (kt(s, u, c.rotation, c.computed.center), u.debug && (De(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / u.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), De(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / u.canvasSize.scaleRatio }), c.selection.shapePath ? s.stroke(c.selection.shapePath) : s.stroke(c.selection.border), p && !c.locked)) {
722
- c.selection.shapePath && s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), De(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / u.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
723
- for (const f of c.selection.anchors) s.fill(f), s.stroke(f);
724
- }
725
- })(e, t, a, n, i, l);
726
- break;
727
- case "group":
728
- ((s, c, h, d, u, p, f) => {
729
- if (c.selection && (c.shapes.forEach((m) => {
730
- De(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / p.canvasSize.scaleRatio }), kt(s, p, m.rotation, m.computed.center), m.selection?.shapePath && s.stroke(m.selection.shapePath), s.restore();
731
- }), u.mode !== "rotate" && (kt(s, p, c.rotation, c.computed.center), p.debug && (De(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / p.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), De(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / p.canvasSize.scaleRatio }), f && !c.locked))) {
732
- s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), De(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / p.canvasSize.scaleRatio });
733
- for (const m of c.selection.anchors) s.fill(m), s.stroke(m);
734
- }
735
- })(e, t, a, n, r, i, l);
736
- break;
737
- case "polygon":
738
- case "line":
739
- case "curve":
740
- (({ ctx: s, shape: c, withAnchors: h, selectionWidth: d, selectionColor: u, hoverMode: p, settings: f }) => {
741
- if (c.selection && (kt(s, f, c.rotation, c.computed.center), f.debug && (De(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / f.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), De(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / f.canvasSize.scaleRatio }), c.selection.shapePath && s.stroke(c.selection.shapePath), h && !c.locked)) {
742
- De(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / f.canvasSize.scaleRatio, shadowColor: u, shadowBlur: 0 });
743
- for (let m = 0; m < c.selection.anchors.length; m++) {
744
- const b = c.selection.anchors[m];
745
- p.mode === "resize" && p.anchor === m ? (s.shadowBlur = 10, s.fill(b), s.shadowBlur = 0) : s.fill(b), s.stroke(b);
746
- }
747
- }
748
- })({ ctx: e, shape: t, withAnchors: l, selectionWidth: n, selectionColor: a, hoverMode: o, settings: i });
749
- }
750
- e.restore();
751
- }, Eo = ({ ctx: e, selectionFrame: t, settings: i }) => {
752
- kt(e, i), ((n, a, o) => {
753
- De(n, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / o.canvasSize.scaleRatio }), n.fillRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]), n.strokeRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]);
754
- })(e, t.frame, i), e.restore();
755
- }, Ri = (e, t) => _(e).map((i) => ({ ...Ba(i, 20, 20, t), id: Le(`${i.type}_`) })), Ni = (e) => e.filter((t) => t != null), vi = (e, t, i) => t < 0 || i < 0 || t > e.length - 1 || i > e.length - 1 ? e : t < i ? [...e.slice(0, t), ...e.slice(t + 1, i + 1), e[t], ...e.slice(i + 1, e.length)] : [...e.slice(0, i), e[t], ...e.slice(i, t), ...e.slice(t + 1, e.length)], Fa = (e) => {
756
- const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0];
757
- if (!t) return "";
758
- const i = t.getAttribute("width"), n = t.getAttribute("height");
759
- let a;
760
- if (i || n) a = e;
761
- else {
762
- const r = t.getAttribute("viewBox") ?? "0 0 300 300", [, , l, s] = r.split(" ");
763
- t.setAttribute("width", l ?? "300"), t.setAttribute("height", s ?? "300"), a = new XMLSerializer().serializeToString(t);
764
- }
765
- const o = new Blob([a], { type: "image/svg+xml" });
766
- return URL.createObjectURL(o);
767
- }, Ya = (e) => (e instanceof File ? e.name : e).includes(".svg"), Xa = (e) => Ya(e) ? fetch(e).then((t) => t.text()).then((t) => Fa(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), wn = (e, t) => {
768
- const i = document.createElement("a");
769
- i.href = e, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
770
- }, Io = (e) => e.src.includes("<svg") ? e.src : ((t) => {
771
- const i = document.createElement("canvas");
772
- i.width = t.width, i.height = t.height;
773
- const n = i.getContext("2d");
774
- return n ? (n.drawImage(t, 0, 0), i.toDataURL("image/png")) : "";
775
- })(e.img), mi = ({ shapes: e, settings: t }) => {
776
- const i = document.createElement("canvas"), n = i.getContext("2d");
777
- if (!n) throw new Error("No context found for canvas");
778
- const { realHeight: a, realWidth: o } = t.canvasSize;
779
- i.width = o, i.height = a, n.clearRect(0, 0, o, a), ya(n);
780
- for (let r = e.length - 1; r >= 0; r--) Ra(n, e[r], t);
781
- return i.toDataURL("image/png");
782
- }, xn = ({ shapes: e, settings: t, view: i }) => {
783
- if (i === "fitToShapes" && !e.length) throw new Error("No image found to export");
784
- if (i === "fitToShapes") {
785
- const a = Math.min(...e.map((c) => c.computed.boundingBox.x)), o = Math.max(...e.map((c) => c.computed.boundingBox.x + c.computed.boundingBox.width)), r = Math.min(...e.map((c) => c.computed.boundingBox.y)), l = Math.max(...e.map((c) => c.computed.boundingBox.y + c.computed.boundingBox.height)), s = { ...t, canvasOffset: [-a, -r], canvasZoom: 1, canvasSize: { realWidth: o - a, realHeight: l - r, width: o - a, height: l - r, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
786
- return mi({ shapes: e, settings: s });
787
- }
788
- if (i === "defaultView") {
789
- const a = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
790
- return mi({ shapes: e, settings: a });
791
- }
792
- const n = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
793
- return mi({ shapes: e, settings: n });
794
- }, Wo = (e, t, i) => {
795
- return a = Bi(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(a))}`;
796
- var a;
797
- }, Ro = (e) => {
798
- const t = ["img", "id", "selection", "path", "arrows", "tempPoint", "computed", ["flipX", [void 0, !1]], ["flipY", [void 0, !1]]];
799
- return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? Si(t, i) : Si(t, { ...i, src: Io(i) }));
800
- }, Bi = (e, t, i) => ({ shapes: Ro(e), config: { width: t, height: i } }), Mn = (e, t) => _e({ ...e, id: Le(`${e.type}_`) }, t), No = (e, t, i, n) => {
801
- const a = ce([]), o = ce(void 0), r = ce({ dataChanged: [] }), [l, s] = J(void 0), [c, h] = J(void 0), [d, u] = J(void 0), [p, f] = J(void 0), [m, b] = J({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), x = G((Q) => {
802
- o.current = typeof Q == "function" ? Q(o.current) : Q, h(o.current);
803
- }, []), k = m.cursor > 0, M = m.cursor < m.states.length - 1, S = a.current.length > 0, g = G(() => {
804
- b((Q) => va(Q.states[Q.cursor]?.shapes, a.current) ? Q : { states: [...Q.states.slice(0, Q.cursor + 1), { shapes: a.current, selectedShape: o.current, source: "user" }], cursor: Q.cursor + 1 });
805
- }, []), P = G((Q) => {
806
- a.current = [...Q, ...a.current];
807
- }, []), z = G((Q, w = !1, y = !1) => {
808
- const L = [];
809
- a.current = a.current.flatMap((W) => {
810
- const V = Q.find((U) => U.id === W.id);
811
- if (V) {
812
- const U = w ? Ri(pe([V], e), e)[0] : { ...V, id: Le(`${W.type}_`) };
813
- return L.push(U), [U, W];
814
- }
815
- return W;
816
- }), y && x(pe(L, e));
817
- }, [e, x]), N = G((Q, w, y, L) => {
818
- if (Q.target && "className" in Q.target && ![ga, fa].includes(Q.target.className) || !L) return void u(void 0);
819
- const W = a.current.find((V) => !V.locked && (_(c)?.map((U) => U.id).includes(V.id) ? !!Et(w, V, y, e) : !!La(w, V, y, e)));
820
- u(W);
821
- }, [e, c]), D = G(async (Q, w = 300, y = 300) => {
822
- const L = await Ho(Q, w, y, e);
823
- return P([L]), g(), L;
824
- }, [P, g, e]), E = G((Q, w = !1) => {
825
- a.current = a.current.map((y) => Q.find((L) => L.id === y.id) ?? y), x((y) => y && pe(_(y).map((L) => Q.find((W) => W.id === L.id) ?? L), e)), w && g();
826
- }, [g, x, e]), A = G((Q) => {
827
- const w = Q.map((y) => Si(["chosen"], y));
828
- a.current = w, g();
829
- }, [g]), T = G((Q) => {
830
- const w = new Set(Q.map((y) => y.id));
831
- x((y) => {
832
- const L = _(y).map((W) => W.id);
833
- return L && w.size && L.find((W) => w.has(W)) ? void 0 : y;
834
- }), a.current = a.current.filter((y) => !w?.has(y.id)), g();
835
- }, [g, x]), B = G((Q) => {
836
- b((w) => {
837
- const y = Q(w);
838
- return a.current = w.states[y]?.shapes ?? [], x(w.states[y]?.selectedShape), Xe("cursor", y, w);
839
- });
840
- }, [x]), F = G(() => {
841
- B((Q) => Math.max(0, Q.cursor - 1));
842
- }, [B]), X = G(() => {
843
- B((Q) => Math.min(Q.states.length - 1, Q.cursor + 1));
844
- }, [B]), Z = G((Q, w) => {
845
- x(void 0), a.current = Q, b((y) => w.clearHistory ? { states: [{ shapes: Q, selectedShape: void 0, source: w.source }], cursor: 0 } : { states: [...y.states.slice(0, y.cursor + 1), { shapes: Q, selectedShape: void 0, source: w.source }], cursor: y.cursor + 1 });
846
- }, [x]), ne = G((Q, w) => {
847
- const y = a.current, L = y.findIndex((V) => V.id === Q), W = y.findIndex((V) => V.id === w);
848
- A(vi(y, L, W));
849
- }, [A]), I = G((Q, w) => {
850
- const y = [...a.current], L = new Set(Q.map((V) => V.id)), W = y.map((V, U) => L.has(V.id) ? U : -1).filter((V) => V >= 0);
851
- if (W.length !== 0) switch (w) {
852
- case "first":
853
- case "last": {
854
- const V = W.map((R) => y[R]).filter(Boolean), U = y.filter((R, H) => !W.includes(H));
855
- A(w === "first" ? [...V, ...U] : [...U, ...V]);
856
- break;
857
- }
858
- case "backward": {
859
- let V = [...y];
860
- const U = W.sort((R, H) => H - R).map((R) => y[R].id);
861
- for (const R of U) {
862
- const H = V.findIndex((ae) => ae.id === R);
863
- if (H < V.length - 1) {
864
- const ae = H + 1;
865
- L.has(V[ae].id) || (V = vi(V, H, ae));
866
- }
867
- }
868
- A(V);
869
- break;
870
- }
871
- case "forward": {
872
- let V = [...y];
873
- const U = W.sort((R, H) => R - H).map((R) => y[R].id);
874
- for (const R of U) {
875
- const H = V.findIndex((ae) => ae.id === R);
876
- if (H > 0) {
877
- const ae = H - 1;
878
- L.has(V[ae].id) || (V = vi(V, H, ae));
879
- }
880
- }
881
- A(V);
882
- break;
883
- }
884
- }
885
- }, [A]), j = G((Q, w, y, L) => {
886
- const W = new Set(w.map((U) => U.id)), V = L === "rotateClockwise" || L === "rotateCounterclockwise" ? a.current.map((U) => W.has(U.id) ? _e(Na(U, L === "rotateClockwise" ? Math.PI / 2 : -Math.PI / 2, y), e) : U) : ((U, R, H, ae, me, O) => {
887
- if (H.length === 0) return R;
888
- const ge = pe(H, O), ue = ge.computed.borders, Se = { newBorderX: ue.x, newBorderY: ue.y, newBorderWidth: ue.width, newBorderHeight: ue.height, widthMultiplier: 1, heightMultiplier: 1, isXinverted: me === "flipHorizontally", isYinverted: me === "flipVertically", groupCenter: ae, rotation: 0, settings: O, originalBorders: ue }, Ie = new Set(H.map((te) => te.id));
889
- return R.map((te) => {
890
- if (te.locked || !Ie.has(te.id)) return te;
891
- switch (te.type) {
892
- case "rect":
893
- case "square":
894
- return Ma(te, ge, Se);
895
- case "picture":
896
- return Ea(te, ge, Se);
897
- case "text":
898
- return Wa(U, te, ge, Se);
899
- case "ellipse":
900
- return Ta(te, ge, Se);
901
- case "circle":
902
- return Ha(te, ge, Se);
903
- case "brush":
904
- return Qa(te, ge, Se);
905
- case "line":
906
- case "polygon":
907
- case "curve":
908
- return Da(te, ge, Se);
909
- default:
910
- return te;
911
- }
912
- });
913
- })(Q, a.current, w, y, L, e);
914
- x(pe(V.filter((U) => W.has(U.id)), e)), A(V);
915
- }, [e, A, x]), ee = G((Q) => {
916
- const w = new Set(Q.map((L) => L.id)), y = a.current.map((L) => w.has(L.id) ? Xe("visible", L.visible === !1, L) : L);
917
- x((L) => pe(y.filter((W) => _(L)?.map((V) => V.id).includes(W.id)), e)), A(y);
918
- }, [A, e, x]), se = G((Q) => {
919
- const w = new Set(Q.map((L) => L.id)), y = a.current.map((L) => w.has(L.id) ? Xe("locked", !L.locked, L) : L);
920
- x((L) => pe(y.filter((W) => _(L)?.map((V) => V.id).includes(W.id)), e)), A(y);
921
- }, [A, e, x]), he = G((Q, w) => {
922
- r.current.hasOwnProperty(Q) && (r.current[Q] = [...r.current[Q], w]);
923
- }, []), C = G((Q, w) => {
924
- if (r.current.hasOwnProperty(Q)) if (w) {
925
- const y = r.current[Q].indexOf(w);
926
- r.current[Q] = [...r.current[Q].slice(0, y), ...r.current[Q].slice(y + 1)];
927
- } else r.current[Q] = [];
928
- }, []);
929
- de(() => {
930
- const Q = m.states[m.cursor], w = Bi(Q.shapes, t, i);
931
- for (const y of r.current.dataChanged) y(w, Q.source);
932
- }, [t, i, m]), de(() => {
933
- a.current = a.current.map((Q) => _e(Q, e)), x((Q) => Q === void 0 ? void 0 : pe(_(Q).map((w) => _e(w, e)), e));
934
- }, [e, x]);
935
- const $ = G((Q, w) => {
936
- s((y) => {
937
- const L = [y?.frame[0] ?? [w[0], w[1]], [w[0], w[1]]], W = a.current.filter((U) => !U.locked && ((R, H, ae) => {
938
- const { borders: me, center: O, boundingBox: ge } = H.computed, ue = Math.min(ae[0][0], ae[1][0]), Se = Math.max(ae[0][0], ae[1][0]), Ie = Math.min(ae[0][1], ae[1][1]), te = { x: ue, y: Ie, width: Se - ue, height: Math.max(ae[0][1], ae[1][1]) - Ie }, we = xi(ge, te);
939
- if (!we) return !1;
940
- if (me.width <= 1 || me.height <= 1) return !0;
941
- if (R.lineWidth = (H.style?.lineWidth ?? 0) + 10, H.type === "brush") {
942
- const ye = H.points.flat(), ie = Math.min(...ye.map((fe) => fe[0])), le = Math.min(...ye.map((fe) => fe[1]));
943
- for (const fe of H.points) {
944
- if (fe.length < 1) break;
945
- if (fe.length < 2) {
946
- const Ve = Ge(fe[0], ie, le, H.scaleX, H.scaleY);
947
- if (Sa(we, { x: Ve[0], y: Ve[1], radius: (H.style?.lineWidth ?? 1) / 2 })) return !0;
948
- }
949
- for (let Ve = 0; Ve < fe.length - 1; Ve++) {
950
- const Fe = wi(Ge(fe[Ve], ie, le, H.scaleX, H.scaleY), H.rotation ?? 0, O), We = wi(Ge(fe[Ve + 1], ie, le, H.scaleX, H.scaleY), H.rotation ?? 0, O), Ce = xi({ x: Math.min(Fe[0], We[0]), y: Math.min(Fe[1], We[1]), width: Math.abs(Fe[0] - We[0]), height: Math.abs(Fe[1] - We[1]) }, te);
951
- if (Ce) {
952
- const Ye = new Path2D();
953
- if (Ye.moveTo(...Fe), Ye.lineTo(...We), pn({ ctx: R, path: Ye, rect: Ce, offset: 10, center: O, checkFill: !1 })) return !0;
954
- }
955
- }
956
- }
957
- return !1;
958
- }
959
- const re = Ii(H);
960
- return pn({ ctx: R, path: H.path, rect: we, offset: 10, center: O, rotation: H.rotation ?? 0, checkFill: re });
961
- })(Q, U, L)), V = pe(W, e);
962
- return x(n ? pe(Ca(y?.oldSelection, W), e) : V), { oldSelection: y?.oldSelection, frame: L };
963
- });
964
- }, [e, n, x]);
965
- return { registerEvent: he, unregisterEvent: C, shapesRef: a, selectedShape: c, hoveredShape: d, selectionFrame: l, setSelectionFrame: s, copiedShape: p, setCopiedShape: f, refreshSelectedShapes: $, addShapes: P, duplicateShapes: z, addPictureShape: D, moveShapes: I, swapShapes: ne, saveShapes: g, setSelectedShape: x, refreshHoveredShape: N, toggleShapeVisibility: ee, toggleShapeLock: se, removeShape: T, updateShape: E, transformShape: j, backwardShape: F, forwardShape: X, clearShapes: Z, canGoBackward: k, canGoForward: M, canClear: S };
966
- }, Cn = (e) => {
967
- const t = [e[0].clientX, e[0].clientY], i = [e[1].clientX, e[1].clientY];
968
- var n, a;
969
- return { diff: ba(t, i), center: (a = i, [((n = t)[0] + a[0]) / 2, (n[1] + a[1]) / 2]) };
970
- }, Bo = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: n, setCanvasTransformation: a }) => {
971
- const o = ce([]), [r, l] = J(o.current.length > 0), s = ce(null), c = ce(t);
972
- c.current = t;
973
- const h = G(({ startDiff: d, startZoom: u, startCenter: p, startOffset: f, currentDiff: m, currentCenter: b, isMoving: x, isZooming: k }) => {
974
- if (!e || !m || !d) return;
975
- const M = (({ canvasBoundingRect: S, canvasSize: g, size: P, startDiff: z, startZoom: N, startCenter: D, startOffset: E, currentDiff: A, currentCenter: T, isMoving: B, isZooming: F }) => {
976
- const X = F ? et(A / z * N, Re[0], Re[Re.length - 1]) : N, Z = B ? [E[0] + (T[0] - D[0]) * (g.width / S.width) / g.scaleRatio / N, E[1] + (T[1] - D[1]) * (g.height / S.height) / g.scaleRatio / N] : [E[0], E[1]], ne = [(T[0] - S.left) / g.scaleRatio, (T[1] - S.top) / g.scaleRatio];
977
- return Ci({ size: P, canvasSize: g, currentOffset: Z, currentZoom: N, zoom: X, centerPoint: ne });
978
- })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: n, startDiff: d, startZoom: u, startCenter: p, startOffset: f, currentDiff: m, currentCenter: b, isMoving: x, isZooming: k });
979
- a(M);
980
- }, [e, i, n, a]);
981
- de(() => {
982
- if (!e) return;
983
- const d = (u) => {
984
- if (o.current = [...o.current, u], l(o.current.length > 0), o.current.length === 2) {
985
- u.stopPropagation();
986
- const { diff: p, center: f } = Cn(o.current);
987
- s.current = { startDiff: p, startCenter: f, startZoom: c.current.zoom, startOffset: c.current.offset, isMoving: !1, isZooming: !1 };
988
- }
989
- };
990
- return e.addEventListener("pointerdown", d), () => {
991
- e.removeEventListener("pointerdown", d);
992
- };
993
- }, [e]), de(() => {
994
- if (!r) return;
995
- const d = (p) => {
996
- const f = o.current.findIndex((m) => m.pointerId === p.pointerId);
997
- if (f > -1 && (o.current[f] = p), o.current.length === 2 && s.current) {
998
- const { diff: m, center: b } = Cn(o.current), x = s.current.isZooming || ((M, S) => Math.abs(M - S.startDiff) > 30)(m, s.current), k = s.current.isMoving || x || ((M, S) => Math.abs(ba(M, S.startCenter)) > 10)(b, s.current);
999
- s.current = { ...s.current, isMoving: k, isZooming: x }, h({ ...s.current, currentDiff: m, currentCenter: b });
1000
- }
1001
- }, u = (p) => {
1002
- o.current = o.current.filter((f) => f.pointerId !== p.pointerId), l(o.current.length > 0);
1003
- };
1004
- return document.addEventListener("pointermove", d), document.addEventListener("pointerup", u), document.addEventListener("pointerout", u), document.addEventListener("pointercancel", u), document.addEventListener("pointerleave", u), () => {
1005
- document.removeEventListener("pointermove", d), document.removeEventListener("pointerup", u), document.removeEventListener("pointerout", u), document.removeEventListener("pointercancel", u), document.removeEventListener("pointerleave", u);
1006
- };
1007
- }, [r, h]);
1008
- }, kn = { offset: [0, 0], zoom: 1 }, Oo = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: n }) => {
1009
- const [a, o] = J(kn), r = ce(0), l = G((h) => {
1010
- o(({ zoom: d }) => Mi({ zoom: d, size: t, canvasSize: e, newOffset: h }));
1011
- }, [e, t]), s = G((h) => {
1012
- o(({ offset: d, zoom: u }) => (({ size: p, canvasSize: f, currentOffset: m, currentZoom: b, action: x }) => {
1013
- const k = x === "default" ? Re[4] : x === "zoom" ? Re[et(Re.length - 1 - Re.slice(0).reverse().findIndex((S) => S <= b) + 1, 0, Re.length - 1)] : Re[et(Re.findIndex((S) => S >= b) - 1, 0, Re.length - 1)], M = [f.realWidth / 2, f.realHeight / 2];
1014
- return Ci({ size: p, canvasSize: f, currentOffset: m, currentZoom: b, zoom: k, centerPoint: M });
1015
- })({ size: t, canvasSize: e, currentOffset: d, currentZoom: u, action: h }));
1016
- }, [e, t]);
1017
- Bo({ canvasElt: n, canvasTransformation: a, canvasSize: e, size: t, setCanvasTransformation: o });
1018
- const c = G(() => {
1019
- o(kn);
1020
- }, []);
1021
- return de(() => {
1022
- if (!i || !n) return;
1023
- const h = (d) => {
1024
- const u = d.ctrlKey, { deltaX: p, deltaY: f } = ((k, M) => {
1025
- const S = Math.abs(k.deltaY) < 50 && M < 50, g = k.ctrlKey, P = ma() && S && g;
1026
- switch (k.deltaMode) {
1027
- case WheelEvent.DOM_DELTA_LINE:
1028
- return { deltaX: 16 * k.deltaX, deltaY: 16 * k.deltaY };
1029
- case WheelEvent.DOM_DELTA_PAGE:
1030
- return { deltaX: k.deltaX * window.innerHeight, deltaY: k.deltaY * window.innerHeight };
1031
- default:
1032
- return P ? { deltaX: 5 * k.deltaX, deltaY: 5 * k.deltaY } : { deltaX: k.deltaX, deltaY: k.deltaY };
1033
- }
1034
- })(d, d.timeStamp - r.current);
1035
- if (r.current = d.timeStamp, u) {
1036
- d.preventDefault();
1037
- const k = Pa(d, n, e);
1038
- return void o(({ offset: M, zoom: S }) => (({ size: g, canvasSize: P, currentOffset: z, currentZoom: N, delta: D, centerPoint: E }) => {
1039
- const A = et(N * (1 - D / 1e3), Re[0], Re[Re.length - 1]);
1040
- return Ci({ size: g, canvasSize: P, currentOffset: z, currentZoom: N, zoom: A, centerPoint: E });
1041
- })({ size: t, canvasSize: e, currentOffset: M, currentZoom: S, delta: f, centerPoint: k }));
1042
- }
1043
- const m = d.shiftKey, [b, x] = m ? [f, p] : [p, f];
1044
- o(({ offset: k, zoom: M }) => {
1045
- const S = [k[0] - b / M, k[1] - x / M], g = Mi({ zoom: M, size: t, canvasSize: e, newOffset: S });
1046
- return g.offset[0] === k[0] && g.offset[1] === k[1] || d.preventDefault(), g;
1047
- });
1048
- };
1049
- return n.addEventListener("wheel", h, { passive: !1 }), () => {
1050
- n.removeEventListener("wheel", h);
1051
- };
1052
- }, [n, t, e, i]), { setCanvasTransformation: o, setCanvasOffset: l, setCanvasZoom: s, resetZoom: c, canvasTransformation: a };
1053
- }, Pn = (e, t = !1) => {
1054
- const i = (a, o) => {
1055
- if (Array.isArray(a)) return o;
1056
- }, n = e.map((a) => {
1057
- if (typeof a != "object") return null;
1058
- switch (a.type) {
1059
- case "brush":
1060
- return Ke(i, ta, a);
1061
- case "circle":
1062
- return Ke(i, ra, a);
1063
- case "curve":
1064
- return Ke(i, aa, a);
1065
- case "ellipse":
1066
- return Ke(i, la, a);
1067
- case "line":
1068
- return Ke(i, ia, a);
1069
- case "polygon":
1070
- return Ke(i, na, a);
1071
- case "rect":
1072
- return Ke(i, oa, a);
1073
- case "square":
1074
- return Ke(i, sa, a);
1075
- case "text":
1076
- return Ke(i, ca, a);
1077
- }
1078
- return null;
1079
- });
1080
- return Ni(t ? [...n, zi] : n);
1081
- }, Ts = ({ width: e = 1e3, height: t = 600, shapes: i, mode: n = "editor", disabled: a = !1, options: o = on } = {}) => {
1082
- const { layersManipulation: r, brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, grid: h, canGrow: d, canShrink: u, withExport: p, withLoadAndSave: f, withUploadPicture: m, withUrlPicture: b, withSkeleton: x, withFrameSelection: k, withContextMenu: M, clearCallback: S, availableTools: g, canvasSelectionPadding: P, size: z, canZoom: N } = { ...on, ...o }, D = n !== "viewer", E = M && D && !a, A = ce(null), T = ce(null), B = ce(!1), F = G((oe) => {
1083
- A.current = oe;
1084
- }, []), [X, Z] = J(void 0), [ne, I] = J(Je), [j, ee] = J({ mode: "default" }), [se, he] = J(h), [C, $] = J({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), Q = N === "always" && !a, { canvasTransformation: w, setCanvasTransformation: y, setCanvasOffset: L, setCanvasZoom: W, resetZoom: V } = Oo({ canvasSize: C, size: z, canvasElt: T.current, zoomEnabled: Q }), { offset: U, zoom: R } = w, H = Yn(() => ({ brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, canvasSize: { realWidth: C.realWidth, realHeight: C.realHeight, width: C.width, height: C.height, scaleRatioWithNoZoom: C.scaleRatio, scaleRatio: C.scaleRatio * R }, size: z, canvasOffset: U, canvasZoom: R, gridGap: se, selectionPadding: P, features: { edition: D && !a, zoom: Q } }), [P, se, l, s, c, R, U, C, z, a, Q, D]), [ae, me] = J(Pn(g, m || b)), { isInsideComponent: O, isInsideCanvas: ge } = (({ settings: oe, componentRef: ve, canvasRef: Te }) => {
1085
- const [ke, He] = J(!1), [Ue, qe] = J(!1), Pe = !oe.features.edition && !oe.features.zoom;
1086
- return de(() => {
1087
- if (!Pe) {
1088
- const Ze = () => He(!0), Nt = () => He(!1), rt = () => qe(!0), Bt = () => qe(!1);
1089
- return ve.current?.addEventListener("focusin", Ze), ve.current?.addEventListener("focusout", Nt), Te.current?.addEventListener("focusin", rt), Te.current?.addEventListener("focusout", Bt), () => {
1090
- ve.current?.removeEventListener("focusin", Ze), ve.current?.removeEventListener("focusout", Nt), Te.current?.removeEventListener("focusin", rt), Te.current?.removeEventListener("focusout", Bt);
1091
- };
1092
- }
1093
- He(!1), qe(!1);
1094
- }, [Pe, ve, Te]), { isInsideComponent: ke, isInsideCanvas: Ue };
1095
- })({ settings: H, componentRef: A, canvasRef: T }), [ue, Se] = J(!1), [Ie, te] = J(!1), [we, re] = J(!1), { registerEvent: ye, unregisterEvent: ie, shapesRef: le, selectedShape: fe, selectionFrame: Ve, hoveredShape: Fe, copiedShape: We, setCopiedShape: Ce, addShapes: Ye, addPictureShape: bt, moveShapes: Qt, swapShapes: ct, setSelectedShape: $e, setSelectionFrame: wt, refreshSelectedShapes: xt, refreshHoveredShape: Ae, duplicateShapes: ot, removeShape: st, updateShape: je, backwardShape: dt, forwardShape: ht, clearShapes: ut, saveShapes: be, toggleShapeVisibility: xe, toggleShapeLock: Y, transformShape: nt, canGoBackward: Tt, canGoForward: qa, canClear: Ga } = No(H, e, t, ue), li = G((oe) => {
1096
- $e(void 0), I(oe);
1097
- }, [$e]), [Mt, Oi] = J([0, 0]), Fi = j.mode === "preview";
1098
- de(() => {
1099
- if (Fi) return () => ee((oe) => oe.mode === "preview" ? { mode: "default" } : oe);
1100
- }, [fe?.id, Fi]);
1101
- const Yi = j.mode === "selectionFrame";
1102
- de(() => {
1103
- if (Yi) return () => Oi([0, 0]);
1104
- }, [Yi]), de(() => {
1105
- if (Mt[0] !== 0 || Mt[1] !== 0) {
1106
- const oe = setInterval(() => {
1107
- y(({ offset: ve, zoom: Te }) => {
1108
- const ke = [ve[0] - Mt[0], ve[1] - Mt[1]];
1109
- return Mi({ zoom: Te, size: z, canvasSize: C, newOffset: ke });
1110
- });
1111
- }, 20);
1112
- return () => clearInterval(oe);
1113
- }
1114
- }, [Mt[0], Mt[1], y, z, C]);
1115
- const Rt = G((oe, ve) => {
1116
- ut(oe, ve), li(Je), y({ offset: [0, 0], zoom: 1 });
1117
- }, [li, ut, y]), Ct = G((oe) => {
1118
- $e((ve) => (ve?.id !== oe.map((Te) => Te.id).join("-") && I(Je), pe(oe, H)));
1119
- }, [$e, H]), Xi = G((oe) => {
1120
- Ye(oe), Ct(oe);
1121
- }, [Ye, Ct]), $i = G(() => {
1122
- Ct(le.current);
1123
- }, [Ct, le]), _a = G(() => {
1124
- const oe = Wo(le.current, e, t);
1125
- if (!oe) throw new Error("L'encodage a échoué");
1126
- wn(oe, "drawing.json");
1127
- }, [le, e, t]), ja = G((oe) => {
1128
- const ve = xn({ shapes: le.current, settings: H, view: oe });
1129
- wn(ve, "drawing.png");
1130
- }, [le, H]), Ka = G((oe) => xn({ shapes: le.current, settings: H, view: oe }), [le, H]), Ja = G(() => Bi(le.current, e, t), [le, e, t]), pt = G(async (oe, ve) => {
1131
- const Te = await (async (ke, He) => {
1132
- if (!ke) return [];
1133
- const Ue = [], qe = Ni(ke.map((Pe) => {
1134
- if (!Pe || !pa.includes(Pe.type)) return null;
1135
- if (Pe.type === "picture") {
1136
- const Ze = new Image(), Nt = new Promise((rt, Bt) => {
1137
- Ze.onload = () => {
1138
- URL.revokeObjectURL(Ze.src), rt();
1139
- }, Ze.onerror = () => {
1140
- Bt(new Error("Some images could not be loaded"));
1141
- };
1142
- });
1143
- if (Ue.push(Nt), Pe.src.startsWith("http")) Xa(Pe.src).then((rt) => {
1144
- Ze.src = rt;
1145
- }).catch(() => {
1146
- Ze.src = "";
1147
- });
1148
- else if (Pe.src.includes("<svg")) {
1149
- const rt = new Blob([Pe.src], { type: "image/svg+xml" });
1150
- Ze.src = URL.createObjectURL(rt);
1151
- } else Ze.src = Pe.src;
1152
- return Mn({ ...Pe, img: Ze }, He);
1153
- }
1154
- return Mn(Pe, He);
1155
- }));
1156
- return await Promise.all(Ue), qe;
1157
- })(oe, H);
1158
- Rt(Te, ve);
1159
- }, [Rt, H]), ci = ce(pt);
1160
- ci.current = pt;
1161
- const eo = G((oe = [], ve = !0) => {
1162
- ci.current?.(oe, { clearHistory: ve, source: "remote" });
1163
- }, []);
1164
- de(() => {
1165
- B.current || (B.current = !0, i && ci.current?.(i, { clearHistory: !0, source: "remote" }));
1166
- }, [i]);
1167
- const to = G(async (oe) => {
1168
- const ve = await (async (Te) => new Promise((ke, He) => {
1169
- const Ue = new FileReader();
1170
- Ue.onload = (qe) => {
1171
- const Pe = qe.target?.result;
1172
- if (!Pe) return He("Impossible de récupérer les données du fichier");
1173
- const Ze = JSON.parse(Pe);
1174
- ke(Ze);
1175
- }, Ue.readAsText(Te);
1176
- }))(oe);
1177
- await pt(ve.shapes ?? [], { clearHistory: !0, source: "remote" });
1178
- }, [pt]), io = G(() => {
1179
- typeof S != "string" ? pt(S(), { clearHistory: !1, source: "user" }) : S === "defaultShapes" && i !== void 0 ? pt(i, { clearHistory: !1, source: "user" }) : Rt([], { clearHistory: !1, source: "user" });
1180
- }, [Rt, pt, i, S]), no = G((oe, ve) => {
1181
- const Te = oe.type === "curve" ? ((ke, He, Ue) => {
1182
- if (He < 0 || He > ke.points.length - 1) return ke;
1183
- const qe = { ...ke, points: ke.points.filter((Pe, Ze) => Ze !== He) };
1184
- return At(qe, Ue);
1185
- })(oe, ve, H) : ((ke, He, Ue) => {
1186
- if (He < 0 || He > ke.points.length - 1) return ke;
1187
- const qe = { ...ke, points: ke.points.filter((Pe, Ze) => Ze !== He) };
1188
- return zt(qe, Ue);
1189
- })(oe, ve, H);
1190
- je([Te], !0);
1191
- }, [H, je]);
1192
- de(() => {
1193
- me(Pn(g, m || b));
1194
- }, [g, m, b]);
1195
- const Ui = { canvas: T, editor: A, setEditor: F };
1196
- return { annotationsProps: { style: { userSelect: "none", touchAction: "none", transformOrigin: "left top", transform: "scale(var(--react-paint-canvas-zoom)) translate(calc(var(--react-paint-canvas-offset-x) * 100% / var(--react-paint-app-canvaswidth)), calc(var(--react-paint-canvas-offset-y) * 100% / var(--react-paint-app-canvasheight)))", "--react-paint-canvas-zoom": H.canvasZoom, "--react-paint-canvas-offset-x": H.canvasOffset[0], "--react-paint-canvas-offset-y": H.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: le, addPictureShape: bt, moveShapes: Qt, swapShapes: ct, toggleShapeVisibility: xe, toggleShapeLock: Y, duplicateShapes: ot, canGoBackward: Tt, canGoForward: qa, canClear: Ga, selectedShape: fe, copiedShape: We, setCopiedShape: Ce, pasteShapes: Xi, saveShapes: be, removeShape: st, updateShape: je, backwardShape: dt, forwardShape: ht, removeShapePoint: no, transformShape: nt, refs: Ui, width: e, height: t, selectTool: li, selectShapes: Ct, selectAllShapes: $i, activeTool: ne, setActiveTool: I, setAvailableTools: me, isEditMode: D, availableTools: ae, gridGap: se, setGridGap: he, loadFile: to, exportPicture: ja, exportData: _a, clearCanvas: io, selectionMode: j, setSelectionMode: ee, settings: H, setCanvasZoom: W, resetZoom: V, canvas: { canGrow: d, canShrink: u, layersManipulation: r, withExport: p, withLoadAndSave: f, withUploadPicture: m, withUrlPicture: b, withContextMenu: E } }, canvasProps: { shapesRef: le, selectedShape: fe, selectionFrame: Ve, hoveredShape: Fe, copiedShape: We, pasteShapes: Xi, setCopiedShape: Ce, addShape: Ye, setSelectedShape: $e, setSelectionFrame: wt, refreshSelectedShapes: xt, refreshHoveredShape: Ae, removeShape: st, updateShape: je, duplicateShapes: ot, backwardShape: dt, forwardShape: ht, saveShapes: be, refs: Ui, width: e, height: t, settings: H, setCanvasSize: $, setCanvasOffset: L, setCanvasZoom: W, resetZoom: V, selectShapes: Ct, selectAllShapes: $i, activeTool: ne, setActiveTool: I, isInsideComponent: O, isInsideCanvas: ge, isEditMode: D, canvas: { withSkeleton: x, withFrameSelection: k, withContextMenu: E, canGrow: d, canShrink: u }, canvasOffsetStartData: X, setCanvasOffsetStartData: Z, selectionMode: j, setSelectionMode: ee, setCanvasMoveAcceleration: Oi, isShiftPressed: ue, isAltPressed: Ie, isSpacePressed: we, setShiftPressed: Se, setAltPressed: te, setIsSpacePressed: re }, registerEvent: ye, unregisterEvent: ie, resetCanvas: eo, resetZoom: V, getCurrentImage: Ka, getCurrentData: Ja, setCanvasOffset: L, setCanvasZoom: W };
1197
- }, Fo = ({ addShapes: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: n, shapes: a, selectionMode: o, activeTool: r, isInsideComponent: l, isInsideCanvas: s, setCanvasOffset: c, selectedShape: h, canvasOffsetStartData: d, refreshSelectedShapes: u, setSelectedShape: p, setSelectionFrame: f, setCanvasOffsetStartData: m, updateSingleShape: b, duplicateShapes: x, saveShapes: k, setSelectionMode: M, setCanvasMoveAcceleration: S, settings: g, isShiftPressed: P, isAltPressed: z, withFrameSelection: N, withContextMenu: D, isSpacePressed: E }) => {
1198
- const A = ce(null), [T, B] = J({ mode: "default" }), { registerDoubleClickEvent: F, unRegisterDoubleClickEvent: X } = (() => {
1199
- const C = ce(void 0), $ = ce(void 0), Q = (w) => {
1200
- const y = Date.now();
1201
- C.current && y < C.current + 300 && $.current?.(w), C.current = Date.now();
1202
- };
1203
- return { registerDoubleClickEvent: (w, y) => {
1204
- $.current = y, w.addEventListener("click", Q), w.addEventListener("touchend", Q);
1205
- }, unRegisterDoubleClickEvent: (w) => {
1206
- w.removeEventListener("click", Q), w.removeEventListener("touchend", Q);
1207
- } };
1208
- })(), Z = (C, $) => {
1209
- const Q = $?.getContext("2d");
1210
- if (Q) {
1211
- if (r === Je && D) {
1212
- const w = ft(C, t.current, g), { shape: y, mode: L } = Ot(Q, a, w, g, h, at(C), !1);
1213
- p(y), M({ mode: "contextMenu", cursorStartPosition: w, originalShape: y, anchor: "anchor" in L ? L.anchor : void 0 });
1214
- } else p(void 0), M({ mode: "default" });
1215
- i(Je), f(void 0);
1216
- }
1217
- }, ne = ce(null);
1218
- ne.current = (C) => (($, Q, w, y, L, W, V, U, R, H, ae, me, O, ge, ue, Se, Ie, te) => {
1219
- if (te && clearTimeout(te), at($) && $.touches.length > 1) return;
1220
- const we = Q.current?.getContext("2d");
1221
- if (!we) return;
1222
- const re = ft($, Q.current, O);
1223
- if (y.mode === "selectionFrame") {
1224
- me(we, re, O);
1225
- const ie = Pa($, Q.current, O.canvasSize);
1226
- return void Ie([Math.ceil(et(ie[0] * O.canvasZoom < 50 ? ie[0] * O.canvasZoom - 50 : ie[0] * O.canvasZoom > O.canvasSize.width / O.canvasSize.scaleRatioWithNoZoom - 50 ? ie[0] * O.canvasZoom - (O.canvasSize.width / O.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / O.canvasZoom), Math.ceil(et(ie[1] * O.canvasZoom < 50 ? ie[1] * O.canvasZoom - 50 : ie[1] * O.canvasZoom > O.canvasSize.height / O.canvasSize.scaleRatioWithNoZoom - 50 ? ie[1] * O.canvasZoom - (O.canvasSize.height / O.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / O.canvasZoom)]);
1227
- }
1228
- if (W !== void 0) return void ae([re[0] + O.canvasOffset[0] - W.start[0], re[1] + O.canvasOffset[1] - W.start[1]]);
1229
- if (y.mode === "preview") {
1230
- const ie = _(w)[0];
1231
- if (ie?.type === "curve") {
1232
- const le = fn(ie, re, O, !0);
1233
- return void Se(pe([le], O));
1234
- }
1235
- if (ie?.type === "polygon") {
1236
- const le = gn(ie, re, O, !0);
1237
- return void Se(pe([le], O));
1238
- }
1239
- }
1240
- const ye = Dt(re, O);
1241
- if (at($) || U($, we, re, ye), w === void 0 || w.locked) V({ mode: "default", outOfView: !ye });
1242
- else {
1243
- if (y.mode === "default" || y.mode === "textedition" || y.mode === "contextMenu") {
1244
- if (!ye) return void V({ mode: "default" });
1245
- V(Et(we, w, re, O, !0) || { mode: "default" });
1246
- } else {
1247
- const ie = Q.current?.getContext("2d");
1248
- if (!ie) return;
1249
- const le = ho(ie, w, re, y, O, ge, ue);
1250
- R(_(le));
1251
- }
1252
- y.mode === "translate" && ue && !y.hasBeenDuplicated && (L({ ...y, hasBeenDuplicated: !0 }), H(_(y.originalShape)));
1253
- }
1254
- })(C, t, h, o, M, d, B, n, b, x, c, u, g, P, z, p, S, A.current), de(() => {
1255
- if (l) {
1256
- const C = ($) => ne.current?.($);
1257
- return document.addEventListener("mousemove", C), document.addEventListener("touchmove", C), () => {
1258
- document.removeEventListener("mousemove", C), document.removeEventListener("touchmove", C);
1259
- };
1260
- }
1261
- }, [l]);
1262
- const { isBrushShapeDoneOnMouseUp: I } = g, j = ce(null);
1263
- j.current = (C) => {
1264
- if (A.current && clearTimeout(A.current), at(C) && C.touches.length > 1) return;
1265
- const $ = t.current?.getContext("2d");
1266
- if (!$) return;
1267
- if ("button" in C && C.button === 2) return void Z(C, t.current);
1268
- if (d) return void m(void 0);
1269
- if (o.mode === "contextMenu" || o.mode === "textedition" || o.mode === "preview") return;
1270
- const Q = ft(C, t.current, g);
1271
- if (o.mode === "translate" && Date.now() - o.dateStart <= 500 && Q[0] === o.cursorStartPosition[0] && Q[1] === o.cursorStartPosition[1]) {
1272
- if (C.ctrlKey || C.shiftKey || C.metaKey) {
1273
- const { shape: w } = Ot($, a, Q, g, h, at(C), N, "remove");
1274
- _(w).length !== o.selectedShapesLengthAtMouseDown && p(w);
1275
- }
1276
- return M({ mode: "default" }), f(void 0), void k();
1277
- }
1278
- o.mode !== "default" && (o.mode === "brush" && I && p(void 0), M({ mode: "default" }), f(void 0), k());
1279
- }, de(() => {
1280
- if (s) {
1281
- const C = ($) => j.current?.($);
1282
- return document.addEventListener("mouseup", C), document.addEventListener("touchend", C), () => {
1283
- document.removeEventListener("mouseup", C), document.removeEventListener("touchend", C);
1284
- };
1285
- }
1286
- }, [s]);
1287
- const ee = !g.features.edition && g.features.zoom, se = !g.features.edition && !g.features.zoom, he = ce(null);
1288
- return he.current = (C, $, Q) => {
1289
- if (C.preventDefault(), at(C) && C.touches.length > 1) return;
1290
- const w = $?.getContext("2d");
1291
- if (!w) return;
1292
- $.focus();
1293
- const y = ft(C, t.current, g), L = "button" in C && C.button === 1, W = "button" in C && C.button === 2;
1294
- if (L || Q || r.type === "move" && !W) m({ start: y, originalOffset: g.canvasOffset });
1295
- else if (!ee) {
1296
- if (!Dt(y, g)) return p(void 0), void M({ mode: "default" });
1297
- if (W) {
1298
- if (r.type === "selection") {
1299
- const { shape: V } = Ot(w, a, y, g, h, at(C), !1);
1300
- p(V), M({ mode: "default" });
1301
- }
1302
- } else if (at(C) && (A.current && clearTimeout(A.current), A.current = setTimeout(() => {
1303
- Z(C, t.current);
1304
- }, 500)), r.type === "selection") {
1305
- const V = C.ctrlKey || C.shiftKey || C.metaKey ? "add" : "replace", { shape: U, mode: R } = Ot(w, a, y, g, h, at(C), N, V);
1306
- p(U), M(R), R.mode === "selectionFrame" && f({ oldSelection: U, frame: [[y[0], y[1]], [y[0], y[1]]] });
1307
- } else if (pa.some((V) => V === r.type)) {
1308
- const V = _(h)[0], U = t.current?.getContext("2d");
1309
- if (!U) return;
1310
- if (r.type === "brush") {
1311
- if (V?.type === "brush") {
1312
- const R = ((H, ae, me) => {
1313
- const O = { ...H, points: Xe(H.points.length, [[Math.round(ae[0]), Math.round(ae[1])]], H.points) };
1314
- return Zt(O, me);
1315
- })(V, y, g);
1316
- b([R]);
1317
- } else {
1318
- const R = yn(U, r, y, g);
1319
- if (!R) return;
1320
- e([R]), p(pe([R], g));
1321
- }
1322
- M({ mode: "brush" });
1323
- } else if (o.mode !== "preview" || V?.type !== "polygon" && V?.type !== "curve") {
1324
- if (r.type !== "picture") {
1325
- const R = yn(U, r, y, g);
1326
- if (!R) return;
1327
- e([R]);
1328
- const H = pe([R], g);
1329
- p(H), R.type === "polygon" || R.type === "curve" ? M({ mode: "preview" }) : (i(Je), M({ mode: "resize", cursorStartPosition: [y[0] + g.selectionPadding, y[1] + g.selectionPadding], originalShape: H, anchor: R.type === "line" ? 0 : [1, 1], selectedShapesLengthAtMouseDown: _(H).length }));
1330
- }
1331
- } else {
1332
- const R = V.type === "polygon" ? gn(V, y, g) : fn(V, y, g);
1333
- p(pe([R], g)), b([R], !0);
1334
- }
1335
- }
1336
- }
1337
- }, de(() => {
1338
- if (se) return;
1339
- const C = t.current;
1340
- if (!C) return;
1341
- const $ = (Q) => he.current?.(Q, C, E);
1342
- return C.addEventListener("mousedown", $, { passive: !1 }), C.addEventListener("touchstart", $, { passive: !1 }), () => {
1343
- C.removeEventListener("mousedown", $), C.removeEventListener("touchstart", $);
1344
- };
1345
- }, [se, t, E]), de(() => {
1346
- const C = t.current, $ = t.current?.getContext("2d");
1347
- if (!(!C || !$))
1348
- return s ? (F(C, (Q) => {
1349
- if (r.type === "selection") {
1350
- if (_(h).length !== 1) return;
1351
- const w = _(h)[0];
1352
- if (w?.locked) return;
1353
- if (w?.type === "text") {
1354
- const y = ft(Q, t.current, g);
1355
- return Dt(y, g) ? void (Et($, h, y, g) && M({ mode: "textedition", defaultValue: w.value })) : void 0;
1356
- }
1357
- if (w?.type === "polygon") {
1358
- const y = ft(Q, t.current, g);
1359
- if (!Dt(y, g)) return;
1360
- const L = un($, w, y, g);
1361
- return void (L && b([wo(w, L.lineIndex, y, g)]));
1362
- }
1363
- if (w?.type === "curve") {
1364
- const y = ft(Q, t.current, g);
1365
- if (!Dt(y, g)) return;
1366
- const L = ((W, V, U, R, H = 50) => {
1367
- if (V.locked || V.points.length < 2) return !1;
1368
- if (V.points.length < 3) return un(W, V, U, R, H);
1369
- const { center: ae } = V.computed, me = tt(U, V.rotation ?? 0, ae);
1370
- W.lineWidth = (V.style?.lineWidth ?? 0) + H / R.canvasZoom;
1371
- const O = Ti(V, V.points), ge = new Path2D();
1372
- ge.moveTo(...O[0]);
1373
- for (let ue = 1; ue < O.length - 2; ue++) {
1374
- const Se = O[ue - 1], Ie = O[ue], te = O[ue + 1], we = O[ue + 2], { cp1: re, cp2: ye } = Di(Se, Ie, te, we);
1375
- if (ge.bezierCurveTo(re[0], re[1], ye[0], ye[1], te[0], te[1]), W.isPointInStroke(ge, me[0], me[1])) return { lineIndex: ue - 1 };
1376
- }
1377
- return !1;
1378
- })($, w, y, g);
1379
- return void (L && b([Mo(w, L.lineIndex, y, g)]));
1380
- }
1381
- }
1382
- }), () => {
1383
- X(C);
1384
- }) : void 0;
1385
- }, [b, F, X, s, t, r, h, M, g]), { hoverMode: T };
1386
- }, $a = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => $a(t)).join("") : e.nodeValue ?? "", Yo = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: n, saveShapes: a, settings: o }) => {
1387
- const r = ce(null), l = ce(a);
1388
- de(() => {
1389
- if (!r.current) return;
1390
- const d = r.current, u = (p) => {
1391
- p.preventDefault();
1392
- const f = p.clipboardData?.getData("text/plain");
1393
- document.execCommand("insertText", !1, f);
1394
- };
1395
- d.addEventListener("paste", u), d.innerText = "";
1396
- for (const p of i) {
1397
- const f = document.createElement("div");
1398
- p === "" ? f.innerHTML = "<br/>" : f.innerText = p, d.appendChild(f);
1399
- }
1400
- return d.focus(), () => {
1401
- d.removeEventListener("paste", u);
1402
- };
1403
- }, [i]), de(() => {
1404
- const d = l.current;
1405
- return () => {
1406
- d();
1407
- };
1408
- }, []);
1409
- const s = Yn(() => {
1410
- const { borders: d, center: u } = t.computed;
1411
- return Qe({ point: [d.x, d.y], rotation: -(t.rotation ?? 0), origin: u });
1412
- }, [t]), c = [`translate3D(${(s[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio}px, ${(s[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio}px, 0)`, `rotate(${Qi(t.rotation ?? 0)}deg)`, t.flipX || t.flipY ? `scale(${t.flipX ? -1 : 1}, ${t.flipY ? -1 : 1})` : void 0, t.flipX || t.flipY ? `translate3D(${t.flipX ? -100 : 0}%,${t.flipY ? -100 : 0}%,0)` : void 0].filter(Boolean).join(" "), h = !e;
1413
- return v("div", { className: "react-paint-editor-toolbox-edittextbox", ref: r, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: h, role: "textbox", tabIndex: h ? 0 : void 0, onInput: (d) => {
1414
- const u = Array.from(d.target.childNodes).map((p) => $a(p));
1415
- n(u);
1416
- }, style: { "--react-paint-editor-toolbox-edittextbox-transform": c, "--react-paint-editor-toolbox-edittextbox-fontsize": t.fontSize * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-padding": o.selectionPadding * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-color": t.style?.strokeColor ?? "inherit", "--react-paint-editor-toolbox-edittextbox-opacity": (t.style?.opacity ?? 100) / 100, "--react-paint-editor-toolbox-edittextbox-fontfamily": t.style?.fontFamily ?? It } });
1417
- }, Xo = (e, t, i, n, a) => {
1418
- ya(e), ((o, r) => {
1419
- const { canvasZoom: l, size: s, canvasSize: { width: c, height: h } } = r;
1420
- if (s !== "fixed" || l >= 1) return;
1421
- o.fillStyle = "#f5f5f5", o.fillRect(0, 0, c, h);
1422
- const d = Va(r);
1423
- o.clearRect(d.x, d.y, d.width, d.height), Za(o, r);
1424
- })(e, i), ((o, r) => {
1425
- const { canvasSize: { width: l, height: s }, gridGap: c, canvasOffset: h, canvasSize: { scaleRatio: d } } = r;
1426
- if (!c) return;
1427
- o.strokeStyle = "rgb(220,220,220)", o.lineWidth = 1, o.save(), o.scale(d, d), o.beginPath();
1428
- const u = h[0] % c, p = h[1] % c, f = Math.ceil(l / d / c) + 2, m = Math.ceil(s / d / c) + 2;
1429
- for (let b = -5; b < f; b++) o.moveTo(u + (b + 1) * c, p - c), o.lineTo(u + (b + 1) * c, p + s / d + c);
1430
- for (let b = -5; b < m; b++) o.moveTo(u - c, p + (b + 1) * c), o.lineTo(u + l / d + c, p + (b + 1) * c);
1431
- o.stroke(), o.restore();
1432
- })(e, i);
1433
- for (let o = n.length - 1; o >= 0; o--) t.mode === "textedition" && n[o] === a || Ra(e, _(a).find((r) => r.id === n[o].id) ?? n[o], i);
1434
- }, $o = Pi.forwardRef(({ canGrow: e, shapes: t, duplicateShapes: i, addShapes: n, updateSingleShape: a, selectedShape: o, setSelectedShape: r, setSelectionFrame: l, hoveredShape: s, selectionFrame: c, refreshHoveredShape: h, refreshSelectedShapes: d, saveShapes: u, activeTool: p, setActiveTool: f, canvasOffsetStartData: m, setCanvasOffsetStartData: b, setCanvasOffset: x, setCanvasMoveAcceleration: k, isInsideComponent: M, isInsideCanvas: S, selectionMode: g, setSelectionMode: P, selectionWidth: z, selectionColor: N, settings: D, isEditMode: E, isShiftPressed: A, isAltPressed: T, isSpacePressed: B, withFrameSelection: F, withSkeleton: X, withContextMenu: Z }, ne) => {
1435
- const I = ce(null), j = ce(null), ee = D.canvasSize, se = E, he = E ? 0 : -1;
1436
- Xn(ne, () => I.current);
1437
- const { hoverMode: C } = Fo({ addShapes: n, drawCanvasRef: I, setActiveTool: f, shapes: t, selectionMode: g, activeTool: p, isInsideComponent: M, isInsideCanvas: S, setCanvasOffset: x, selectedShape: o, canvasOffsetStartData: m, setCanvasOffsetStartData: b, setSelectedShape: r, setSelectionFrame: l, refreshHoveredShape: h, refreshSelectedShapes: d, updateSingleShape: a, duplicateShapes: i, saveShapes: u, setSelectionMode: P, setCanvasMoveAcceleration: k, isShiftPressed: A, isAltPressed: T, withFrameSelection: F, settings: D, isSpacePressed: B, withContextMenu: Z }), $ = G((w) => {
1438
- const y = _(o)[0];
1439
- if (y?.type !== "text") return;
1440
- const L = I.current?.getContext("2d");
1441
- if (!L) return;
1442
- const W = _e(To(L, y, w, D), D);
1443
- a([W]);
1444
- }, [a, o, D]), Q = (w) => {
1445
- if (E) return w.preventDefault(), w.stopPropagation(), !1;
1446
- };
1447
- return de(() => {
1448
- const w = I.current?.getContext("2d");
1449
- w && window.requestAnimationFrame(() => Xo(w, g, D, t, o));
1450
- }, [t, g, o, D]), de(() => {
1451
- const w = j.current?.getContext("2d");
1452
- w && window.requestAnimationFrame(() => ((y, L, W, V, U, R, H, ae, me, O, ge) => {
1453
- y.reset(), Za(y, W), ge && ae && !_(H).find((ue) => ue.id === ae.id) && V.type === "selection" && (L.mode === "default" || L.mode === "contextMenu" || L.mode === "textedition") && Qn({ ctx: y, shape: ae, settings: W, selectionWidth: U, selectionColor: R, hoverMode: me, selectionMode: L, withAnchors: !1 }), H && V.type !== "brush" && Qn({ ctx: y, shape: H, settings: W, selectionWidth: U, selectionColor: R, hoverMode: me, selectionMode: L, withAnchors: L.mode !== "textedition" }), O && Eo({ ctx: y, selectionFrame: O, settings: W });
1454
- })(w, g, D, p, z, N, o, s, C, c, X));
1455
- }, [s, C, c, g, o, p, D, z, N, X]), v("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": m ? "grabbing" : C.outOfView ? "default" : C.mode === "resize" ? "pointer" : p.type !== "selection" && p.type !== "move" ? "crosshair" : C.mode === "translate" ? "move" : C.mode === "rotate" || p.type === "move" || B ? "grab" : "default" }, children: K("div", { className: "react-paint-canvas-container", "data-grow": e, children: [v("canvas", { className: ga, ref: I, "data-grow": e, width: ee.width, height: ee.height, onContextMenu: Q, tabIndex: he }), se && v("canvas", { className: fa, ref: j, width: ee.width, height: ee.height, "data-grow": e, onContextMenu: Q }), E && g.mode === "textedition" && _(o)[0]?.type === "text" && v(Yo, { disabled: !D.features.edition, shape: _(o)[0], defaultValue: g.defaultValue, updateValue: $, saveShapes: u, settings: D })] }) });
1456
- }), Ln = "ArrowUp", Vn = "ArrowDown", Zn = "ArrowLeft", Hn = "ArrowRight", Uo = "Delete", qo = "Backspace", Go = "Escape", zn = "Shift", An = "Alt", Tn = "Option", jt = " ", _o = "A", jo = "a", Ko = "z", Jo = "Z", es = "y", ts = "Y", is = "+", ns = "-", as = "0", Dn = "cut", En = "copy", In = "paste", Ds = ({ options: e, className: t, style: i, canvasProps: n }) => {
1457
- const { shapesRef: a, selectedShape: o, selectionFrame: r, hoveredShape: l, addShape: s, setSelectedShape: c, selectAllShapes: h, setSelectionFrame: d, refreshSelectedShapes: u, refreshHoveredShape: p, duplicateShapes: f, removeShape: m, updateShape: b, backwardShape: x, forwardShape: k, saveShapes: M, refs: S, width: g, height: P, settings: z, setCanvasSize: N, setCanvasOffset: D, pasteShapes: E, activeTool: A, setActiveTool: T, isInsideComponent: B, isInsideCanvas: F, isEditMode: X, canvas: { withSkeleton: Z, withFrameSelection: ne, withContextMenu: I, canGrow: j, canShrink: ee }, canvasOffsetStartData: se, setCanvasOffsetStartData: he, selectionMode: C, setSelectionMode: $, setCanvasMoveAcceleration: Q, isShiftPressed: w, isAltPressed: y, isSpacePressed: L, copiedShape: W, setCopiedShape: V, setShiftPressed: U, setAltPressed: R, setCanvasZoom: H, resetZoom: ae, setIsSpacePressed: me } = n, { canvasBackgroundColor: O, canvasSelectionColor: ge, canvasSelectionWidth: ue } = { ...lo, ...e }, Se = ce(null), Ie = G((te) => {
1458
- N({ realWidth: g, realHeight: P, width: te, height: P * te / g, scaleRatio: te / g });
1459
- }, [g, P, N]);
1460
- return (({ isInsideComponent: te, isInsideCanvas: we, selectedShape: re, isEditingText: ye, settings: ie, copiedShape: le, setCopiedShape: fe, setSelectedShape: Ve, setActiveTool: Fe, setCanvasZoom: We, resetZoom: Ce, setSelectionMode: Ye, setSelectionFrame: bt, selectAllShapes: Qt, removeShape: ct, pasteShapes: $e, updateShapes: wt, backwardShape: xt, forwardShape: Ae, setShiftPressed: ot, setAltPressed: st, setIsSpacePressed: je }) => {
1461
- de(() => {
1462
- const dt = (Y) => {
1463
- re && (ye || (Y.preventDefault(), fe({ ...re })));
1464
- }, ht = (Y) => {
1465
- re && (ye || (Y.preventDefault(), fe({ ...re }), ct(_(re))));
1466
- }, ut = (Y) => {
1467
- le && (ye || (Y.preventDefault(), $e(Ri(le, ie))));
1468
- }, be = (Y) => {
1469
- switch (Y.key) {
1470
- case zn:
1471
- ot(!1);
1472
- break;
1473
- case An:
1474
- case Tn:
1475
- st(!1);
1476
- break;
1477
- case jt:
1478
- je(!1);
1479
- }
1480
- }, xe = (Y) => {
1481
- if (Y.metaKey || Y.ctrlKey) {
1482
- if (Y.key === Jo || Y.key === Ko) return Y.preventDefault(), Y.stopPropagation(), void (Y.shiftKey ? Ae() : xt());
1483
- if (!ma() && (Y.key === ts || Y.key === es)) return Y.preventDefault(), Y.stopPropagation(), void Ae();
1484
- if (Y.key === _o || Y.key === jo) return Y.preventDefault(), Y.stopPropagation(), void Qt();
1485
- if (Y.key === is) return Y.preventDefault(), Y.stopPropagation(), void We("zoom");
1486
- if (Y.key === ns) return Y.preventDefault(), Y.stopPropagation(), void We("unzoom");
1487
- if (Y.key === as) return Y.preventDefault(), Y.stopPropagation(), void Ce();
1488
- }
1489
- if (Y.key === zn) return Y.preventDefault(), Y.stopPropagation(), void ot(!0);
1490
- if (Y.key === jt && we) return Y.preventDefault(), Y.stopPropagation(), void je(!0);
1491
- if (Y.key === An || Y.key === Tn) return Y.preventDefault(), Y.stopPropagation(), void st(!0);
1492
- if (!re) return;
1493
- if (Y.key === Go) return Ve(void 0), Fe(Je), Ye({ mode: "default" }), void bt(void 0);
1494
- if (ye) return;
1495
- const nt = { [Zn]: [ie.gridGap ? -ie.gridGap : -1, 0], [Hn]: [ie.gridGap ? ie.gridGap : 1, 0], [Vn]: [0, ie.gridGap ? ie.gridGap : 1], [Ln]: [0, ie.gridGap ? -ie.gridGap : -1] };
1496
- switch (Y.key) {
1497
- case Zn:
1498
- case Hn:
1499
- case Vn:
1500
- case Ln:
1501
- Y.preventDefault(), Y.stopPropagation(), wt(Oa(nt[Y.key], re, [0, 0], ie, !0));
1502
- break;
1503
- case Uo:
1504
- case qo:
1505
- Y.preventDefault(), Y.stopPropagation(), ct(_(re));
1506
- }
1507
- };
1508
- if (te) return document.addEventListener("keydown", xe), document.addEventListener("keyup", be), document.addEventListener(En, dt), document.addEventListener(In, ut), document.addEventListener(Dn, ht), () => {
1509
- document.removeEventListener("keydown", xe), document.removeEventListener("keyup", be), document.removeEventListener(En, dt), document.removeEventListener(In, ut), document.removeEventListener(Dn, ht);
1510
- };
1511
- }, [te, we, le, ye, re, ie, wt, ct, Ve, $e, xt, Ae, ot, st, Fe, Ye, bt, fe, We, Ce, je, Qt]);
1512
- })({ isInsideComponent: B, isInsideCanvas: F, isEditingText: C.mode === "textedition", settings: z, selectedShape: o, copiedShape: W, setCopiedShape: V, selectAllShapes: h, setSelectedShape: c, removeShape: m, pasteShapes: E, updateShapes: b, backwardShape: x, forwardShape: k, setShiftPressed: U, setAltPressed: R, setActiveTool: T, setSelectionMode: $, setSelectionFrame: d, setCanvasZoom: H, resetZoom: ae, setIsSpacePressed: me }), (({ onResized: te, element: we }) => {
1513
- de(() => {
1514
- const re = we.current;
1515
- if (!re) return;
1516
- const ye = new ResizeObserver((ie) => {
1517
- const le = ie?.[0]?.borderBoxSize?.[0], { width: fe, height: Ve } = le ? { width: le.inlineSize, height: le.blockSize } : ie?.[0]?.contentRect ?? {};
1518
- fe !== void 0 && Ve !== void 0 && te(fe, Ve);
1519
- });
1520
- return ye.observe(re), () => {
1521
- ye.unobserve(re);
1522
- };
1523
- }, [we, te]);
1524
- })({ element: Se, onResized: Ie }), v("div", { ref: Se, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": j, "data-shrink": ee, style: { "--react-paint-app-row-width": z.canvasSize.width, "--react-paint-app-canvaswidth": g, "--react-paint-app-canvasheight": P, "--react-paint-app-row-aspectratio": `calc(${z.canvasSize.width} / ${z.canvasSize.height})`, "--react-paint-app-canvas-bg": O, ...i }, children: v($o, { duplicateShapes: f, isSpacePressed: L, withContextMenu: I, ref: S.canvas, canGrow: j, isInsideComponent: B, isInsideCanvas: F, activeTool: A, setActiveTool: T, canvasOffsetStartData: se, setCanvasOffsetStartData: he, shapes: a.current, addShapes: s, updateSingleShape: b, selectedShape: o, selectionFrame: r, setSelectedShape: c, setSelectionFrame: d, hoveredShape: l, refreshHoveredShape: p, refreshSelectedShapes: u, settings: z, setCanvasOffset: D, saveShapes: M, selectionMode: C, setSelectionMode: $, setCanvasMoveAcceleration: Q, selectionColor: ge, selectionWidth: ue, isEditMode: X, isShiftPressed: w, isAltPressed: y, withFrameSelection: ne, withSkeleton: Z }) });
1525
- }, os = ({ isLoading: e = !1 }) => {
1526
- const [t, i] = J("hidden");
1527
- return de(() => {
1528
- if (!e) {
1529
- i("fadeOut");
1530
- const n = setTimeout(() => i("hidden"), 300);
1531
- return () => {
1532
- clearTimeout(n);
1533
- };
1534
- }
1535
- i("visible");
1536
- }, [e]), t === "hidden" ? null : v("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": ao, "--react-paint-editor-loading-transition-duration": "300ms" }, children: K("div", { className: "react-paint-editor-loader", children: [v("div", {}), v("div", {}), v("div", {}), v("div", {})] }) });
1537
- }, ss = "infos", rs = 4e3, ls = ({ type: e, text: t, duration: i }) => {
1538
- const [n, a] = J(!1);
1539
- return de(() => {
1540
- const o = setTimeout(() => {
1541
- a(!0);
1542
- }, 100), r = setTimeout(() => {
1543
- a(!1);
1544
- }, i - 500 - 100);
1545
- return () => {
1546
- clearTimeout(o), clearTimeout(r);
1547
- };
1548
- }, [i]), v("div", { className: "react-paint-editor-snackbar", "data-is-shown": +n, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1549
- }, cs = ({ snackbarList: e }) => v("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": oo }, children: e.map((t) => v(ls, { ...t }, t.id)) }), ds = Pi.forwardRef((e, t) => {
1550
- const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: r, className: l = "", title: s, onClick: c, ...h } = e, d = n ? -1 : 0, u = ce(null);
1551
- return Xn(t, () => u.current), K("label", { className: `react-paint-editor-button ${l}`, title: s, onClick: c, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, tabIndex: d, onKeyDown: (p) => {
1552
- p.key === jt && (p.preventDefault(), p.stopPropagation());
1553
- }, onKeyUp: (p) => {
1554
- p.preventDefault(), p.stopPropagation(), p.key === jt && u.current?.click();
1555
- }, children: [v("input", { ref: u, disabled: n, ...h }), K("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), o && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] })] });
1556
- }), q = Pi.forwardRef((e, t) => {
1557
- if (e.type === "file" || e.type === "color") return v(ds, { ...e, ref: t });
1558
- const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: r, type: l = "button", className: s = "", ...c } = e;
1559
- return v("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: n, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, type: l, ...c, children: K("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), o && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] }) });
1560
- }), St = ({ children: e, title: t = "", className: i = "", position: n, fitContainer: a = !1, alignment: o, style: r, ...l }) => K("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": a, "data-position": n ?? "unset", "data-alignment": o ?? "unset", style: { ...r, "--react-paint-editor-panel-zindex": Jn }, ...l, children: [t && v("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), hs = (e) => {
1561
- switch (e) {
1562
- case "brush":
1563
- return Un;
1564
- case "line":
1565
- return _n;
1566
- case "polygon":
1567
- return Zi;
1568
- case "curve":
1569
- return jn;
1570
- case "rect":
1571
- case "square":
1572
- return Li;
1573
- case "circle":
1574
- case "ellipse":
1575
- return Vi;
1576
- case "text":
1577
- return Gn;
1578
- case "picture":
1579
- return Hi;
1580
- case "group":
1581
- return '<svg><path d="M3.333 17.5V16.667H7.5V17.5ZM3.333 14.167V13.333H9.167V14.167ZM3.333 10.833V10H10.833V10.833ZM3.333 7.5V6.667H12.5V7.5ZM3.333 4.167V3.333H13.333V4.167ZM3.333 0.833V0H16.667V0.833Z"/></svg>';
1582
- case "triangle":
1583
- return "";
1584
- }
1585
- }, us = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: n, toggleShapeVisibility: a, toggleShapeLock: o, setLayoutDragging: r, handleRemove: l, handleSelect: s, onSwapShapes: c }) => {
1586
- const h = ce(null), { isOver: d } = (({ disabled: u = !1, ref: p, shape: f, layoutDragging: m, setLayoutDragging: b, handleSelect: x, onSwapShapes: k }) => {
1587
- const [M, S] = J(!1);
1588
- return de(() => {
1589
- m || S(!1);
1590
- }, [m]), de(() => {
1591
- const g = p.current;
1592
- if (!g) return;
1593
- const P = () => {
1594
- b(void 0);
1595
- }, z = (T) => (T.preventDefault && T.preventDefault(), !1), N = (T) => {
1596
- x([f]), T.dataTransfer && (T.dataTransfer.effectAllowed = "move", T.dataTransfer.setData("draggableShapeId", f.id), b(f.id));
1597
- }, D = () => {
1598
- m !== f.id && S(!0);
1599
- }, E = () => {
1600
- S(!1);
1601
- }, A = (T) => (T.stopPropagation(), T.dataTransfer && k(T.dataTransfer.getData("draggableShapeId"), f.id), !1);
1602
- return u || (g.addEventListener("dragstart", N), g.addEventListener("dragend", P), g.addEventListener("dragover", z), g.addEventListener("dragenter", D), g.addEventListener("dragleave", E), g.addEventListener("drop", A)), () => {
1603
- u || (g.removeEventListener("dragstart", N), g.removeEventListener("dragend", P), g.removeEventListener("dragover", z), g.removeEventListener("dragenter", D), g.removeEventListener("dragleave", E), g.removeEventListener("drop", A));
1604
- };
1605
- }, [u, p, f, b, x, k, m]), { isOver: M };
1606
- })({ disabled: e, ref: h, shape: t, layoutDragging: n, setLayoutDragging: r, handleSelect: s, onSwapShapes: c });
1607
- return K("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(n === t.id), "data-is-over": +d, onClick: (u) => {
1608
- e || (u.preventDefault(), s([t]));
1609
- }, "data-selected": +i, ref: h, tabIndex: -1, children: [v("span", { dangerouslySetInnerHTML: { __html: hs(t.type) } }), v("span", { children: t.id }), v("div", { className: "react-paint-editor-layouts-separator" }), v(q, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (u) => {
1610
- e || (u.preventDefault(), u.stopPropagation(), a([t]));
1611
- }, icon: t.visible === !1 ? '<svg><path d="M13.521 11.021 12.25 9.75Q12.333 8.75 11.604 7.979Q10.875 7.208 9.812 7.312L8.542 6.042Q8.896 5.896 9.26 5.833Q9.625 5.771 10 5.771Q11.583 5.771 12.688 6.875Q13.792 7.979 13.792 9.562Q13.792 9.979 13.719 10.354Q13.646 10.729 13.521 11.021ZM16.167 13.646 14.917 12.417Q15.667 11.833 16.25 11.146Q16.833 10.458 17.25 9.562Q16.229 7.479 14.292 6.281Q12.354 5.083 10 5.083Q9.396 5.083 8.885 5.156Q8.375 5.229 7.875 5.375L6.5 4Q7.354 3.646 8.208 3.49Q9.062 3.333 10 3.333Q13.146 3.333 15.615 5.052Q18.083 6.771 19.167 9.562Q18.688 10.792 17.917 11.823Q17.146 12.854 16.167 13.646ZM16.396 18.854 12.938 15.396Q12.208 15.625 11.479 15.729Q10.75 15.833 10 15.833Q6.833 15.833 4.375 14.094Q1.917 12.354 0.833 9.562Q1.25 8.479 1.917 7.552Q2.583 6.625 3.417 5.875L1.125 3.562L2.375 2.354L17.625 17.625ZM4.604 7.062Q4.021 7.604 3.542 8.219Q3.062 8.833 2.729 9.562Q3.75 11.646 5.688 12.865Q7.625 14.083 10 14.083Q10.354 14.083 10.74 14.052Q11.125 14.021 11.479 13.938L10.812 13.271Q10.625 13.312 10.417 13.333Q10.208 13.354 10 13.354Q8.417 13.354 7.312 12.25Q6.208 11.146 6.208 9.562Q6.208 9.354 6.24 9.167Q6.271 8.979 6.312 8.771ZM11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875ZM8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Z"/></svg>' : '<svg><path d="M10 13.354Q11.583 13.354 12.688 12.25Q13.792 11.146 13.792 9.562Q13.792 7.979 12.688 6.875Q11.583 5.771 10 5.771Q8.417 5.771 7.312 6.875Q6.208 7.979 6.208 9.562Q6.208 11.146 7.312 12.25Q8.417 13.354 10 13.354ZM10 11.812Q9.062 11.812 8.406 11.156Q7.75 10.5 7.75 9.562Q7.75 8.625 8.406 7.969Q9.062 7.312 10 7.312Q10.938 7.312 11.594 7.969Q12.25 8.625 12.25 9.562Q12.25 10.5 11.594 11.156Q10.938 11.812 10 11.812ZM10 15.833Q6.938 15.833 4.448 14.125Q1.958 12.417 0.833 9.562Q1.958 6.708 4.458 5.021Q6.958 3.333 10 3.333Q13.042 3.333 15.542 5.021Q18.042 6.708 19.167 9.562Q18.042 12.417 15.552 14.125Q13.062 15.833 10 15.833ZM10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562ZM10 14.083Q12.333 14.083 14.281 12.865Q16.229 11.646 17.25 9.562Q16.229 7.479 14.281 6.281Q12.333 5.083 10 5.083Q7.667 5.083 5.708 6.281Q3.75 7.479 2.729 9.562Q3.75 11.646 5.708 12.865Q7.667 14.083 10 14.083Z"/></svg>' }), v(q, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (u) => {
1612
- e || (u.preventDefault(), u.stopPropagation(), o([t]));
1613
- }, icon: t.locked ? '<svg><path d="M10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H5.792V5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833ZM10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042V6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' : '<svg><path d="M5.792 5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' }), v(q, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (u) => {
1614
- e || (u.preventDefault(), u.stopPropagation(), l([t]));
1615
- }, icon: qn })] });
1616
- }, ps = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: n, removeShape: a, toggleShapeVisibility: o, toggleShapeLock: r, selectedShapes: l, swapShapes: s, selectShapes: c, isLayoutPanelShown: h }) => {
1617
- const [d, u] = J(void 0), p = !i.features.edition;
1618
- return h ? v(St, { alignment: "right", className: "react-paint-editor-layouts-panel", position: "bottom", children: v("div", { className: "react-paint-editor-layouts-panel-content", children: K("div", { className: "react-paint-editor-layouts-scrolling-content", children: [K("div", { className: "react-paint-editor-layouts-row", children: [v("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), v(q, { icon: '<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>', className: "react-paint-editor-layouts-grid-button", selected: e === "none", disabled: p, onClick: () => t("none") }), ["small", "medium", "large"].map((f) => v(q, { className: "react-paint-editor-layouts-grid-button", selected: e === f, disabled: p, onClick: () => t(f), children: f.charAt(0).toUpperCase() }, f))] }), v("hr", {}), v("div", { className: "react-paint-editor-layouts", children: n.length === 0 ? v("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : n.map((f) => v(us, { shape: f, disabled: p, layoutDragging: d, setLayoutDragging: u, selected: _(l).some((m) => m.id === f.id) ?? !1, handleSelect: c, handleRemove: a, onSwapShapes: s, toggleShapeVisibility: o, toggleShapeLock: r }, f.id)) })] }) }) }) : null;
1619
- }, si = ({ children: e, onClose: t, position: i = "center", title: n, className: a = "" }) => K("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": Jn }, role: "dialog", "aria-modal": "true", "aria-labelledby": n, children: [v("div", { className: "react-paint-editor-modal-mask", onClick: t }), v("div", { className: `react-paint-editor-modal-panel ${a}`, children: e })] }), Yt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: n = "fill", disabled: a = !1, values: o, field: r, value: l = "", valueChanged: s }) => {
1620
- const [c] = J(Le("settings_")), h = e === c;
1621
- return o.length ? K(Oe, { children: [v(q, { selected: h, title: i, disabled: a, onClick: () => {
1622
- t((d) => d === c ? void 0 : c);
1623
- }, icon: l === "transparent" ? n === "fill" ? en : Ji : void 0, children: l !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": l } }) }), h && v(St, { title: i, alignment: "left", position: "bottom", children: K("div", { className: "react-paint-editor-colorfield-wrapper", children: [o.map((d) => v(q, { title: d, selected: d === l, color: d, icon: d === "transparent" ? n === "fill" ? en : Ji : void 0, onClick: () => {
1624
- s(r, d);
1625
- }, children: d !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", color: d, "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": d } }) }, d)), v(q, { type: "color", title: "Custom color", selected: l !== "" && !o.includes(l), value: l, onChange: (d) => {
1626
- const u = +d.target.value;
1627
- s(r, Number.isNaN(u) ? d.target.value : u);
1628
- }, children: v("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": o.includes(l) ? "var(--react-paint-editor-app-font-color)" : l }, children: v("span", { dangerouslySetInnerHTML: { __html: '<svg><path d="M9.958 18.333Q8.25 18.333 6.74 17.677Q5.229 17.021 4.104 15.885Q2.979 14.75 2.323 13.229Q1.667 11.708 1.667 10Q1.667 8.271 2.333 6.75Q3 5.229 4.156 4.104Q5.312 2.979 6.854 2.323Q8.396 1.667 10.125 1.667Q11.771 1.667 13.26 2.25Q14.75 2.833 15.875 3.854Q17 4.875 17.667 6.26Q18.333 7.646 18.333 9.25Q18.333 11.688 16.792 12.948Q15.25 14.208 13.188 14.208H11.75Q11.625 14.208 11.562 14.281Q11.5 14.354 11.5 14.458Q11.5 14.688 11.812 15.219Q12.125 15.75 12.125 16.458Q12.125 17.458 11.51 17.896Q10.896 18.333 9.958 18.333ZM5.458 10.875Q6 10.875 6.375 10.5Q6.75 10.125 6.75 9.583Q6.75 9.042 6.375 8.667Q6 8.292 5.458 8.292Q4.917 8.292 4.542 8.667Q4.167 9.042 4.167 9.583Q4.167 10.125 4.542 10.5Q4.917 10.875 5.458 10.875ZM7.917 7.583Q8.458 7.583 8.833 7.208Q9.208 6.833 9.208 6.292Q9.208 5.75 8.833 5.375Q8.458 5 7.917 5Q7.375 5 7 5.375Q6.625 5.75 6.625 6.292Q6.625 6.833 7 7.208Q7.375 7.583 7.917 7.583ZM12.021 7.583Q12.562 7.583 12.938 7.208Q13.312 6.833 13.312 6.292Q13.312 5.75 12.938 5.375Q12.562 5 12.021 5Q11.479 5 11.104 5.375Q10.729 5.75 10.729 6.292Q10.729 6.833 11.104 7.208Q11.479 7.583 12.021 7.583ZM14.479 10.875Q15.021 10.875 15.396 10.5Q15.771 10.125 15.771 9.583Q15.771 9.042 15.396 8.667Q15.021 8.292 14.479 8.292Q13.938 8.292 13.562 8.667Q13.188 9.042 13.188 9.583Q13.188 10.125 13.562 10.5Q13.938 10.875 14.479 10.875Z"/></svg>' } }) }) })] }) })] }) : null;
1629
- }, gs = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => v(q, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1630
- i(_(t));
1631
- }, icon: qn }), ri = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: n = "Choisissez l'option", disabled: a = !1, field: o, icon: r, values: l, defaultValue: s, valueChanged: c }) => {
1632
- const [h] = J(Le("settings_")), d = t === h;
1633
- return l.length ? K(Oe, { children: [v(q, { selected: d, title: n, icon: r, disabled: a, onClick: () => {
1634
- i((u) => u === h ? void 0 : h);
1635
- } }), d && v(St, { title: n, alignment: "left", fitContainer: !0, position: "bottom", children: v("div", { className: "react-paint-editor-selectfield-wrapper", children: l.map((u) => v(q, { title: `${u}`, onClick: () => ((p) => {
1636
- c(o, p);
1637
- })(u), selected: s === u, style: { "--react-paint-editor-button-padding": "16px" }, children: v(e, { children: u }) }, u)) }) })] }) : null;
1638
- }, fs = ({ children: e }) => v("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), Wn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: fs, title: "Police", icon: '<svg><path d="M5.312 14.979H7.125L8.042 12.479H11.979L12.896 14.979H14.708L10.917 5H9.083ZM8.542 10.958 9.958 6.958H10.042L11.458 10.958ZM3.417 18.333Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V3.417Q1.667 2.688 2.177 2.177Q2.688 1.667 3.417 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417V16.583Q18.333 17.312 17.823 17.823Q17.312 18.333 16.583 18.333ZM3.417 16.583H16.583Q16.583 16.583 16.583 16.583Q16.583 16.583 16.583 16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583ZM3.417 3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583V3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417Z"/></svg>', disabled: i, field: "fontFamily", values: n, defaultValue: a, valueChanged: o }) : null, vs = ({ disabled: e, toggleLayoutPanel: t }) => v(q, { title: "Toggle layers panel", disabled: e, onClick: t, icon: '<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>', className: "react-paint-editor-layout-button" }), ms = ({ children: e }) => K("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [v("span", { className: "react-paint-editor-linearrow-left" }), v("span", { className: "react-paint-editor-linearrow-right" })] }), Rn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: ms, title: "Flèches", icon: '<svg><path d="M6 17 2 13 6 9 7.062 10.062 4.875 12.25H17V13.75H4.875L7.062 15.938ZM14 11 12.938 9.938 15.125 7.75H3V6.25H15.125L12.938 4.062L14 3L18 7Z"/></svg>', disabled: i, field: "lineArrow", values: n, defaultValue: a, valueChanged: o }) : null, ys = ({ children: e }) => K("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {})] }), Nn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: ys, icon: '<svg><path d="M3 16V14.5H4.5V16ZM6.125 16V14.5H7.625V16ZM9.25 16V14.5H10.75V16ZM12.375 16V14.5H13.875V16ZM15.5 16V14.5H17V16ZM3 13V11.5H6.5V13ZM8.25 13V11.5H11.75V13ZM13.5 13V11.5H17V13ZM3 10V8.5H9.25V10ZM10.75 10V8.5H17V10ZM3 7V4H17V7Z"/></svg>', title: "Type de traits", disabled: i, field: "lineDash", values: n, defaultValue: a, valueChanged: o }) : null, Xt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: n, disabled: a = !1, field: o, value: r, min: l = 1, max: s = 20, step: c = 1, unity: h = "", valueChanged: d, saveShapes: u }) => {
1639
- const p = r === void 0, f = p ? "N/A" : `${Math.round(r)}${h}`, [m] = J(Le("settings_")), b = ((k, M = 500) => {
1640
- const S = ce(null), g = G((...P) => {
1641
- S.current && clearTimeout(S.current), S.current = setTimeout(() => k(...P), M);
1642
- }, [k, M]);
1643
- return de(() => () => {
1644
- S.current && clearTimeout(S.current);
1645
- }, []), g;
1646
- })(u), x = e === m;
1647
- return l === s ? null : K(Oe, { children: [v(q, { selected: x, title: i, disabled: a, icon: n, onClick: () => {
1648
- t((k) => k === m ? void 0 : m);
1649
- } }), x && v(St, { title: i, alignment: "left", fitContainer: !0, position: "bottom", children: v("div", { children: K("label", { className: "react-paint-editor-rangefield", children: [v("input", { type: "range", min: l, max: s, step: c, value: r ?? (s + l) / 2, "data-indeterminate": +p, onChange: (k) => {
1650
- const M = +k.target.value, S = Number.isNaN(M) ? k.target.value : M;
1651
- d(o, S, !1), b();
1652
- } }), v("span", { children: f })] }) }) })] });
1653
- }, Ss = ({ children: e }) => v("span", { children: e === 0 ? "Non" : "Oui" }), bs = [0, 1], Bn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: n, valueChanged: a }) => v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ss, title: "Fermer les points", icon: Zi, disabled: i, field: "closedPoints", values: bs, defaultValue: n, valueChanged: a }), Qs = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => v(q, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: Kn, className: t ? ` ${t}` : "" }), $t = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: n, values: a, value: o = !1, valueChanged: r }) => {
1654
- const [l] = J(Le("settings_"));
1655
- return a.length !== 2 ? null : v(q, { onClick: () => {
1656
- e((s) => s === l ? void 0 : l), r(i, !o);
1657
- }, selected: o, disabled: t, icon: n });
1658
- }, yi = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: n, selectedSettings: a, setSelectedSettings: o, saveShapes: r, handleShapeStyleChange: l, handleShapeFontFamilyChange: s }) => t ? i && K(Oe, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: t.style?.strokeColor, valueChanged: l, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: t.style?.fillColor, valueChanged: l, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", icon: Ki, disabled: n, field: "lineWidth", value: t.style?.lineWidth, valueChanged: l, unity: "px", min: i.settings.lineWidth.min, max: i.settings.lineWidth.max, step: i.settings.lineWidth.step }), "lineDash" in i.settings && !i.settings.lineDash.hidden && v(Nn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineDash, valueChanged: l, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && v(Rn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineArrow, valueChanged: l, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && v(Bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: l, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && v(Wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: _i, valueChanged: s, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: ji, valueChanged: s, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: qi, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: t.style?.opacity, valueChanged: l })] }) : "settings" in e ? K(Oe, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: l, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: e.settings.fillColor.default, valueChanged: l, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", disabled: n, field: "lineWidth", icon: Ki, value: e.settings.lineWidth.default, valueChanged: l, unity: "px", min: e.settings.lineWidth.min, max: e.settings.lineWidth.max, step: e.settings.lineWidth.step }), "lineDash" in e.settings && !e.settings.lineDash.hidden && v(Nn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineDash.default, valueChanged: l, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && v(Rn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineArrow.default, valueChanged: l, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && v(Bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: l, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && v(Wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: _i, valueChanged: s, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: ji, valueChanged: s, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: qi, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: e.settings.opacity.default, valueChanged: l })] }) : null, ws = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: n = !1, toggleLayoutPanel: a, activeTool: o, saveShapes: r, selectedShape: l, canvas: s, settings: c, updateShape: h, removeShape: d, isZoomPanelShown: u, setIsZoomPanelShown: p }) => {
1659
- const [f, m] = J(void 0), [b, x] = J(!1), k = c.size === "infinite" || c.features.zoom, M = !c.features.edition, S = () => {
1660
- x((E) => !E);
1661
- }, g = ((E, A) => {
1662
- const T = _(E).map((F) => A.find((X) => X.id === F?.toolId) || A.find((X) => X.type === F?.type)).filter((F) => F !== void 0);
1663
- if (!T.length) return;
1664
- if (T.length === 1) return T[0];
1665
- const B = T.slice(1).reduce((F, X) => {
1666
- const Z = {};
1667
- for (const ne in X.settings) {
1668
- if (F[ne] === void 0 || X.settings[ne]?.hidden || F[ne]?.hidden) continue;
1669
- const I = F[ne], j = X.settings[ne], ee = {};
1670
- "min" in j && "min" in I && j.min === I.min && "max" in j && "max" in I && j.max === I.max && "step" in j && "step" in I && j.step === I.step && (ee.min = j.min, ee.max = j.max, ee.step = j.step), "values" in j && "values" in I && j.values?.join(",") === I.values?.join(",") && (ee.values = j.values), (Object.keys(ee).length > 0 || ne === "closedPoints") && (Z[ne] = ee);
1671
- }
1672
- return Z;
1673
- }, T[0].settings);
1674
- return { id: T.map((F) => F.id).join("-"), icon: "", label: "group", type: "group", settings: B };
1675
- })(l, t), P = (g ? Object.keys(g.settings).length + 1 : "settings" in o ? Object.keys(o.settings).length : 0) + +n + +k, z = e < 40 * P, N = (E, A, T = !0) => {
1676
- if (_(l).length) {
1677
- const B = _(l).map((F) => _e(Xe(["style", E], A, F), c));
1678
- h(B, T), g && i(g.id, E, A);
1679
- } else i(o.id, E, A);
1680
- }, D = (E, A) => {
1681
- if (_(l).length) {
1682
- const T = _(l).map((B) => {
1683
- if (B.type !== "text") return B;
1684
- const F = s?.getContext("2d");
1685
- if (!F) return B;
1686
- const X = Xe(["style", E], A, B), Z = oi(F, X.value, X.width, X.style?.fontBold ?? !1, X.style?.fontItalic ?? !1, X.style?.fontFamily);
1687
- return _e({ ...X, fontSize: Z, height: Z * X.value.length }, c);
1688
- });
1689
- h(T, !0), g && i(g.id, E, A);
1690
- } else i(o.id, E, A);
1691
- };
1692
- return K(Oe, { children: [K("div", { className: "react-paint-editor-settings-bar", children: [K("div", { className: "react-paint-editor-settings-shrinkable", children: [k && v(Qs, { className: u ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1693
- p((E) => !E);
1694
- } }), z && P > 2 && v(q, { disabled: M, onClick: S, title: "Toggle settings", icon: '<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>' }), l ? g && K(Oe, { children: [!z && v(yi, { saveShapes: r, activeTool: o, selectedShape: l, selectedShapeTool: g, disabled: M, selectedSettings: f, setSelectedSettings: m, handleShapeStyleChange: N, handleShapeFontFamilyChange: D }), o.type === "selection" && v(gs, { disabled: M, selectedShape: l, removeShape: d })] }) : !z && v(yi, { saveShapes: r, activeTool: o, selectedShape: l, selectedShapeTool: g, disabled: M, selectedSettings: f, setSelectedSettings: m, handleShapeStyleChange: N, handleShapeFontFamilyChange: D })] }), v("div", { className: "react-paint-editor-settings-separator" }), n && v(vs, { disabled: M, toggleLayoutPanel: a })] }), b && v(si, { className: "react-paint-editor-settings-modal", onClose: S, position: "bottom", title: "Settings", children: v(yi, { saveShapes: r, activeTool: o, selectedShape: l, selectedShapeTool: g, disabled: M, selectedSettings: f, setSelectedSettings: m, handleShapeStyleChange: N, handleShapeFontFamilyChange: D }) })] });
1695
- }, qt = ({ alignment: e, children: t, className: i, style: n, position: a }) => v(St, { alignment: e, position: a, className: i, style: n, children: v("div", { className: "react-paint-editor-menu", role: "menu", children: t }) }), On = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: n, img: a, accept: o }) => {
1696
- const r = ce(null);
1697
- return v(q, { ref: r, type: "file", onClick: () => {
1698
- r.current && (r.current.value = "");
1699
- }, onChange: (l) => {
1700
- const s = l.target.files?.item(0);
1701
- s && i(s);
1702
- }, accept: o, title: n.label ?? n.type, icon: a, disabled: e, children: t ? n.label : void 0 });
1703
- }, Ne = ({ type: e, img: t, isActive: i, withText: n = !1, disabled: a = !1, setActive: o }) => v(q, { disabled: a, selected: i, onClick: () => {
1704
- o(e);
1705
- }, title: e.label ?? e.type, icon: t, children: n ? e.label : void 0 }), Ua = (e, t) => !!(e.target instanceof Node && t) && t.contains(e.target), ki = ({ trigger: e = "click", buttonElt: t }) => {
1706
- const [i, n] = J(!1), [, a] = $n(), o = G(() => {
1707
- a(() => {
1708
- n(!1);
1709
- });
1710
- }, []);
1711
- return de(() => {
1712
- if (!t) return;
1713
- if (i) {
1714
- const l = (c) => {
1715
- Ua(c, t) || a(() => {
1716
- n(!1);
1717
- });
1718
- }, s = () => {
1719
- a(() => {
1720
- n(!1);
1721
- });
1722
- };
1723
- return e === "hover" ? (t.addEventListener("mouseleave", s), () => {
1724
- t.removeEventListener("mouseleave", s);
1725
- }) : (document.addEventListener("click", l), () => {
1726
- document.removeEventListener("click", l);
1727
- });
1728
- }
1729
- const r = () => {
1730
- a(() => {
1731
- n(!0);
1732
- });
1733
- };
1734
- return e === "hover" ? (t.addEventListener("mouseenter", r), () => {
1735
- t.removeEventListener("mouseenter", r);
1736
- }) : (t.addEventListener("click", r), () => {
1737
- t.removeEventListener("click", r);
1738
- });
1739
- }, [t, i, e]), { isOpen: i, trigger: e, closeMenu: o };
1740
- }, xs = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: n = !1, hasActionToClear: a = !1, undoAction: o, redoAction: r, clearCanvas: l, disabled: s = !1, withLoadAndSave: c, withExport: h, addPicture: d, loadFile: u, togglePictureUrlModal: p, saveFile: f, toggleExportModal: m, withUploadPicture: b, withUrlPicture: x }) => {
1741
- const k = ce(null), { isOpen: M, closeMenu: S } = ki({ buttonElt: k.current }), g = (P) => async (...z) => {
1742
- await P(...z), S();
1743
- };
1744
- return t || b || x || c || h ? v("div", { className: "react-paint-editor-toolbox-relative", children: K("div", { ref: k, children: [v(q, { title: "Menu", disabled: s, icon: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }), M && K(qt, { alignment: "right", position: "top", children: [t && K(Oe, { children: [v(Ne, { withText: !0, type: Pt, disabled: s || !i, img: Pt.icon, isActive: e.id === Pt.id, setActive: g(o) }), v(Ne, { withText: !0, type: Lt, disabled: s || !n, img: Lt.icon, isActive: e.id === Lt.id, setActive: g(r) }), v(Ne, { withText: !0, type: Vt, disabled: s || !a, img: Vt.icon, isActive: e.id === Vt.id, setActive: g(l) }), (b || x || c) && v("hr", {})] }), b && v(On, { withText: !0, type: an, disabled: s, loadFile: g(d), img: an.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), x && v(q, { disabled: s, selected: !1, onClick: g(p), title: "Add picture from URL", icon: '<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>', children: "Add picture from URL" }), (b || x) && c && v("hr", {}), c && K(Oe, { children: [v(On, { withText: !0, type: nn, disabled: s, loadFile: g(u), img: nn.icon, accept: "application/JSON" }), v(Ne, { withText: !0, disabled: s, type: hi, img: hi.icon, isActive: e.id === hi.id, setActive: g(f) })] }), h && v(Ne, { withText: !0, disabled: s, type: di, img: di.icon, isActive: e.id === di.id, setActive: g(m) })] })] }) }) : null;
1745
- }, Ms = ({ togglePictureUrlModal: e, addPicture: t }) => {
1746
- const i = ce(null);
1747
- return de(() => {
1748
- i.current && i.current.focus();
1749
- }, []), v(si, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: K("form", { onSubmit: async (n) => {
1750
- n.preventDefault();
1751
- const a = i.current?.value;
1752
- a && (await t(a), e());
1753
- }, children: [K("label", { children: ["URL ", v("input", { type: "text", ref: i })] }), v(q, { onClick: e, children: "Annuler" }), v(q, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1754
- }, Fn = "Choose export settings", Cs = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1755
- const i = async (n) => {
1756
- t(n), e();
1757
- };
1758
- return K(si, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Fn, children: [v("h3", { children: Fn }), v("hr", {}), v(q, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), v(q, { onClick: () => i("defaultView"), children: "Exporter le canevas par défaut" }), v(q, { onClick: () => i("fitToShapes"), children: "Exporter le dessin entier" }), v(q, { selected: !0, onClick: e, children: "Annuler" })] });
1759
- }, ks = ({ activeTool: e, group: t, disabled: i = !1, setActiveToolFromId: n }) => {
1760
- const a = ce(null), [o, r] = J(!1), [, l] = $n(), [s, c] = J(void 0), h = (p) => {
1761
- c(p), n(p.id);
1762
- };
1763
- if (de(() => {
1764
- if (!o) return;
1765
- const p = (f) => {
1766
- !Ua(f, a.current) && r(!1);
1767
- };
1768
- return document.addEventListener("mousedown", p, { passive: !1 }), document.addEventListener("touchstart", p, { passive: !1 }), () => {
1769
- document.removeEventListener("mousedown", p), document.removeEventListener("touchstart", p);
1770
- };
1771
- }, [o]), "type" in t) return v(Ne, { disabled: i, type: t, img: t.icon, isActive: e.id === t.id, setActive: h });
1772
- if (!t.toolsType.length) return null;
1773
- if (t.toolsType?.length === 1) return v(Ne, { disabled: i, type: t.toolsType[0], img: t.toolsType[0].icon, isActive: e.id === t.toolsType[0].id, setActive: h });
1774
- const d = t?.toolsType.find((p) => p.type === e.type) !== void 0, u = (s ? s.icon : t.toolsType?.[0]?.icon) ?? t.title;
1775
- return K("div", { className: "react-paint-editor-toolbargroup-relative", children: [v(q, { selected: d, title: t.title, disabled: i, onClick: () => {
1776
- s ? n(s.id) : t.toolsType?.[0] && h(t.toolsType[0]), l(() => {
1777
- r(!0);
1778
- });
1779
- }, icon: u }), o && v(St, { alignment: "center", position: "top", children: v("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +t.vertical, ref: a, children: t.toolsType.map((p) => v(Ne, { disabled: i, type: p, img: p.icon, isActive: e.id === p.id, setActive: h }, p.id)) }) })] });
1780
- }, Ps = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], Ls = ({ settings: e, width: t, activeTool: i, hasActionToUndo: n = !1, hasActionToRedo: a = !1, hasActionToClear: o = !1, withLoadAndSave: r, withExport: l, clearCanvas: s, setActiveTool: c, undoAction: h, redoAction: d, addPicture: u, loadFile: p, saveFile: f, exportCanvasInFile: m, availableTools: b, withUrlPicture: x, withUploadPicture: k }) => {
1781
- const M = ((I, j) => {
1782
- const ee = j.flatMap((se) => {
1783
- if (typeof se != "object") return I.filter((C) => C.type === se);
1784
- const he = I.filter((C) => se.toolsType.includes(C.type));
1785
- return he ? { ...se, toolsType: he } : null;
1786
- });
1787
- return Ni(ee);
1788
- })(b, Ps), S = !e.features.edition, g = t < 40 * (6 + M.length), P = t < 40 * (3 + M.length), [z, N] = J(!1), [D, E] = J(!1), [A, T] = J(!1), B = () => {
1789
- N((I) => !I);
1790
- }, F = () => {
1791
- T((I) => !I);
1792
- }, X = (I) => {
1793
- c(I), N(!1);
1794
- }, Z = (I) => {
1795
- X(b.find((j) => j.id === I) ?? i);
1796
- }, ne = b.find((I) => I.type === i.type) !== void 0;
1797
- return K(Oe, { children: [K("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [K("div", { className: "react-paint-editor-toolbar-shrinkable", children: [v(Ne, { type: Je, disabled: S, img: Je.icon, isActive: i.id === Je.id, setActive: X }), (e.size === "infinite" || e.features.zoom) && v(Ne, { type: ui, disabled: S, img: ui.icon, isActive: i.id === ui.id, setActive: X }), P ? v(q, { disabled: S, onClick: B, title: "Toggle tools", icon: '<svg><path d="M5.333 9.292 10.021 1.646 14.708 9.292ZM14.562 18.333Q13 18.333 11.896 17.229Q10.792 16.125 10.792 14.562Q10.792 13 11.896 11.896Q13 10.792 14.562 10.792Q16.125 10.792 17.229 11.896Q18.333 13 18.333 14.562Q18.333 16.125 17.229 17.229Q16.125 18.333 14.562 18.333ZM2.5 17.917V11.188H9.229V17.917ZM14.562 16.583Q15.438 16.583 16.01 16.01Q16.583 15.438 16.583 14.562Q16.583 13.688 16.01 13.115Q15.438 12.542 14.562 12.542Q13.688 12.542 13.115 13.115Q12.542 13.688 12.542 14.562Q12.542 15.438 13.115 16.01Q13.688 16.583 14.562 16.583ZM4.25 16.167H7.479V12.938H4.25ZM8.458 7.542H11.583L10.021 5ZM10.021 7.542ZM7.479 12.938ZM14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Z"/></svg>', selected: ne }) : M.map((I) => v(ks, { disabled: S, activeTool: i, group: I, setActiveToolFromId: Z }, "id" in I ? I.id : I.title))] }), !g && K(Oe, { children: [v(Ne, { type: Pt, disabled: S || !n, img: Pt.icon, isActive: i.id === Pt.id, setActive: h }), v(Ne, { type: Lt, disabled: S || !a, img: Lt.icon, isActive: i.id === Lt.id, setActive: d }), v(Ne, { type: Vt, disabled: S || !o, img: Vt.icon, isActive: i.id === Vt.id, setActive: s })] }), v(xs, { withActionsInMenu: g, disabled: S, activeTool: i, addPicture: u, loadFile: p, saveFile: f, togglePictureUrlModal: () => {
1798
- E(!0);
1799
- }, toggleExportModal: F, withUploadPicture: k, withUrlPicture: x, withLoadAndSave: r, withExport: l, hasActionToUndo: n, hasActionToRedo: a, hasActionToClear: o, undoAction: h, redoAction: d, clearCanvas: s })] }), z && v(si, { className: "react-paint-editor-toolbar-modal", onClose: B, title: "Outils", children: b.map((I) => I.type === "picture" ? null : v(Ne, { disabled: S, type: I, img: I.icon, withText: !1, isActive: i.id === I.id, setActive: X }, I.id)) }), D && v(Ms, { togglePictureUrlModal: () => {
1800
- E((I) => !I);
1801
- }, addPicture: u }), A && v(Cs, { toggleExportModal: F, exportCanvasInFile: m })] });
1802
- }, Ut = { none: 0, small: 10, medium: 20, large: 40 }, Vs = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, Zs = () => {
1803
- const e = ce([]), [t, i] = J([]);
1804
- return de(() => () => {
1805
- for (const n of e.current) clearTimeout(n);
1806
- }, []), { snackbarList: t, addSnackbar: ({ type: n = ss, duration: a = rs, text: o }) => {
1807
- const r = { id: Le("snackbar_"), duration: a, type: n, text: o };
1808
- i((l) => [...l, r]), e.current = [...e.current, setTimeout(() => {
1809
- return l = r.id, void i((s) => s.filter((c) => c.id !== l));
1810
- var l;
1811
- }, a)];
1812
- } };
1813
- }, Hs = ({ moveShapes: e, selectAllShapes: t, selectionMode: i, transformShape: n, settings: a, canvasRef: o, closeContextMenu: r, toggleShapeVisibility: l, toggleShapeLock: s, removeShape: c, duplicateShapes: h, copiedShape: d, setCopiedShape: u, pasteShapes: p, removeShapePoint: f }) => {
1814
- const m = ce(null), b = ce(null), { isOpen: x } = ki({ trigger: "hover", buttonElt: m.current }), { isOpen: k } = ki({ trigger: "hover", buttonElt: b.current }), { originalShape: M, cursorStartPosition: S, anchor: g } = i, P = _(M), z = P.length > 0, N = P.length === 1 && (P[0]?.type === "polygon" || P[0]?.type === "curve") && g !== void 0 && P[0]?.points?.length > 2, D = !P.some((Z) => Z.visible === !1), E = P.some((Z) => Z.locked), A = 16 + 36 * (2 + (z ? 8 : 0) + (N ? 1 : 0)) + 16 * (z ? 3 : 1), [T] = J(() => [(S[0] + a.canvasOffset[0]) * a.canvasSize.scaleRatio, 36 + (S[1] + a.canvasOffset[1]) * a.canvasSize.scaleRatio]), [B, F] = J();
1815
- de(() => {
1816
- const Z = o?.current?.getBoundingClientRect();
1817
- if (!Z) return;
1818
- const ne = Z.left + T[0], I = Z.top + T[1], j = Math.max(0, Math.min(ne, window.innerWidth - 176)) - Z.left, ee = Math.max(0, Math.min(I, window.innerHeight - A)) - Z.top, se = j > window.innerWidth - 176 - Math.min(j, 200) ? "left" : "right";
1819
- F({ x: j, y: ee, subMenuPosition: se });
1820
- }, [o, T, A]);
1821
- const X = B ? { "--react-paint-editor-toolbox-contextmenu-transform": `translate3D(${B.x}px, ${B.y}px, 0)` } : { display: "none" };
1822
- return K(qt, { className: "react-paint-editor-toolbox-contextmenu", style: X, children: [z && K(Oe, { children: [N && v(q, { onClick: () => {
1823
- N && f(P[0], g), r();
1824
- }, children: "Delete point" }), K("div", { className: "react-paint-editor-toolbox-contextmenu-group", ref: m, children: [v(q, { icon: Gi, children: "Organize" }), x && K(qt, { position: B?.subMenuPosition, children: [v(q, { onClick: () => {
1825
- z && e(P, "forward"), r();
1826
- }, children: "Move forward" }), v(q, { onClick: () => {
1827
- z && e(P, "first"), r();
1828
- }, children: "Put on first" }), v(q, { onClick: () => {
1829
- z && e(P, "backward"), r();
1830
- }, children: "Move backward" }), v(q, { onClick: () => {
1831
- z && e(P, "last"), r();
1832
- }, children: "Put on last" })] })] }), K("div", { className: "react-paint-editor-toolbox-contextmenu-group", ref: b, children: [v(q, { icon: Gi, children: "Transform" }), k && K(qt, { position: B?.subMenuPosition, children: [v(q, { onClick: () => {
1833
- const Z = o?.current?.getContext("2d");
1834
- Z && z && n(Z, P, M.computed.center, "flipHorizontally"), r();
1835
- }, children: "Flip horizontally" }), v(q, { onClick: () => {
1836
- const Z = o?.current?.getContext("2d");
1837
- Z && z && n(Z, P, M.computed.center, "flipVertically"), r();
1838
- }, children: "Flip vertically" }), v(q, { onClick: () => {
1839
- const Z = o?.current?.getContext("2d");
1840
- Z && z && n(Z, P, M.computed.center, "rotateClockwise"), r();
1841
- }, children: "Rotate clockwise" }), v(q, { onClick: () => {
1842
- const Z = o?.current?.getContext("2d");
1843
- Z && z && n(Z, P, M.computed.center, "rotateCounterclockwise"), r();
1844
- }, children: "Rotate counterclockwise" })] })] }), v("hr", {}), v(q, { onClick: () => {
1845
- z && (u(pe(P, a)), c(P)), r();
1846
- }, children: "Cut" }), v(q, { onClick: () => {
1847
- z && u(pe(P, a)), r();
1848
- }, children: "Copy" })] }), v(q, { onClick: () => {
1849
- d && p(Ri(d, a)), r();
1850
- }, disabled: !d, children: "Paste" }), v("hr", {}), z && K(Oe, { children: [v(q, { onClick: () => {
1851
- z && h(P, !0, !0), r();
1852
- }, children: "Duplicate" }), v(q, { onClick: () => {
1853
- z && l(P.filter((Z) => D ? Z.visible !== !1 : Z.visible === !1)), r();
1854
- }, children: D ? "Hide" : "Show" }), v(q, { onClick: () => {
1855
- z && s(P.filter((Z) => E ? Z.locked : !Z.locked)), r();
1856
- }, children: E ? "Unlock" : "Lock" }), v(q, { onClick: () => {
1857
- z && c(P), r();
1858
- }, children: "Delete" }), v("hr", {})] }), v(q, { onClick: () => {
1859
- t(), r();
1860
- }, children: "Select all" })] });
1861
- }, Es = ({ editorProps: e, className: t, style: i, options: n, children: a }) => {
1862
- const { selectionMode: o, setSelectionMode: r, shapesRef: l, addPictureShape: s, moveShapes: c, swapShapes: h, toggleShapeVisibility: d, toggleShapeLock: u, canGoBackward: p, canGoForward: f, canClear: m, selectedShape: b, copiedShape: x, setCopiedShape: k, pasteShapes: M, removeShape: S, duplicateShapes: g, updateShape: P, backwardShape: z, forwardShape: N, removeShapePoint: D, transformShape: E, refs: A, width: T, height: B, selectTool: F, selectShapes: X, selectAllShapes: Z, activeTool: ne, setActiveTool: I, setAvailableTools: j, isEditMode: ee, availableTools: se, gridGap: he, setGridGap: C, loadFile: $, exportPicture: Q, exportData: w, clearCanvas: y, settings: L, setCanvasZoom: W, saveShapes: V, canvas: { canGrow: U, layersManipulation: R, withExport: H, withLoadAndSave: ae, withUploadPicture: me, withUrlPicture: O, withContextMenu: ge } } = e, { toolbarBackgroundColor: ue, dividerColor: Se, fontRadius: Ie, fontDisabledColor: te, fontDisabledBackgroundColor: we, fontColor: re, fontBackgroundColor: ye, fontSelectedColor: ie, fontSelectedBackgroundColor: le, fontHoverColor: fe, fontHoverBackgroundColor: Ve } = { ...Vs, ...n }, Fe = L.size === "infinite" || L.features.zoom, [We, Ce] = J(!1), [Ye, bt] = J(!1), [Qt, ct] = J(Fe), $e = Fe && Qt, wt = he >= Ut.large ? "large" : he >= Ut.medium ? "medium" : he >= Ut.small ? "small" : "none", { snackbarList: xt, addSnackbar: Ae } = Zs(), ot = G((be, xe, Y) => {
1863
- j((nt) => nt.map((Tt) => Tt.id === be ? Xe(["settings", xe, "default"], Y, Tt) : Tt)), I((nt) => nt.id === be ? Xe(["settings", xe, "default"], Y, nt) : nt);
1864
- }, [I, j]), st = G((be) => {
1865
- Ce(!0);
1866
- try {
1867
- Q(be);
1868
- } catch (xe) {
1869
- xe instanceof Error && Ae({ type: "error", text: `L'export a échoué : ${xe.message}` }), console.warn(xe);
1870
- } finally {
1871
- Ce(!1);
1872
- }
1873
- }, [Q, Ae]), je = G(() => {
1874
- Ce(!0);
1875
- try {
1876
- w(), Ce(!1);
1877
- } catch (be) {
1878
- be instanceof Error && Ae({ type: "error", text: "L'enregistrement a échoué" }), console.warn(be);
1879
- } finally {
1880
- Ce(!1);
1881
- }
1882
- }, [w, Ae]), dt = G(async (be) => {
1883
- Ce(!0);
1884
- try {
1885
- await $(be), Ae({ type: "success", text: "Fichier chargé !" });
1886
- } catch (xe) {
1887
- xe instanceof Error && Ae({ type: "error", text: "Le chargement a échoué" }), console.warn(xe);
1888
- } finally {
1889
- Ce(!1);
1890
- }
1891
- }, [$, Ae]), ht = G(async (be) => {
1892
- Ce(!0);
1893
- try {
1894
- const xe = await s(be, T, B);
1895
- X([xe]);
1896
- } catch (xe) {
1897
- xe instanceof Error && Ae({ type: "error", text: "Le chargement a échoué" }), console.warn(xe);
1898
- } finally {
1899
- Ce(!1);
1900
- }
1901
- }, [s, X, Ae, T, B]), ut = `${t ? `${t} ` : ""}${Ye ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1902
- return K("div", { ref: A.setEditor, className: ut, style: { "--react-paint-editor-app-maxWidth": U ? "100%" : `${T}px`, "--react-paint-editor-app-toolbar-bg": ue, "--react-paint-editor-app-divider-color": Se, "--react-paint-editor-app-font-radius": `${Ie}px`, "--react-paint-editor-app-font-disabled-color": te, "--react-paint-editor-app-font-disabled-bg": we, "--react-paint-editor-app-font-color": re, "--react-paint-editor-app-font-bg": ye, "--react-paint-editor-app-font-selected-color": ie, "--react-paint-editor-app-font-selected-bg": le, "--react-paint-editor-app-font-hover-color": fe, "--react-paint-editor-app-font-hover-bg": Ve, ...i }, children: [ee && v(Ls, { settings: L, width: L.canvasSize.width, activeTool: ne, clearCanvas: y, setActiveTool: F, exportCanvasInFile: st, saveFile: je, loadFile: dt, addPicture: ht, hasActionToUndo: p, hasActionToRedo: f, hasActionToClear: m, undoAction: z, redoAction: N, availableTools: se, withExport: H, withLoadAndSave: ae, withUploadPicture: me, withUrlPicture: O }), a, ee && R && v(ps, { gridFormat: wt, setGridFormat: (be) => {
1903
- C(Ut[be]);
1904
- }, shapes: l.current, swapShapes: h, selectedShapes: b, removeShape: S, selectShapes: X, toggleShapeVisibility: d, toggleShapeLock: u, isLayoutPanelShown: Ye, settings: L }), $e && K(St, { alignment: "left", position: "bottom", className: "react-paint-editor-layouts-panel", "data-edit": +ee, children: [v(q, { className: "react-paint-editor-zoom-button", icon: '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>', onClick: () => W("unzoom") }), K(q, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => W("default"), children: [Math.round(100 * L.canvasZoom), "%"] }), v(q, { className: "react-paint-editor-zoom-button", icon: Kn, onClick: () => W("zoom") })] }), ee && K(Oe, { children: [v(ws, { saveShapes: V, setCanvasZoom: W, width: L.canvasSize.width, activeTool: ne, availableTools: se, selectedShape: b, settings: L, removeShape: S, updateShape: P, canvas: A.canvas.current, layersManipulation: R, toggleLayoutPanel: () => {
1905
- bt((be) => !be);
1906
- }, isZoomPanelShown: $e, setIsZoomPanelShown: ct, updateToolSettings: ot }), v(os, { isLoading: We }), v(cs, { snackbarList: xt })] }), o.mode === "contextMenu" && ge && v(Hs, { selectionMode: o, settings: L, canvasRef: A.canvas, closeContextMenu: () => {
1907
- r({ mode: "default" }), A.canvas.current?.focus();
1908
- }, selectAllShapes: Z, removeShape: S, moveShapes: c, duplicateShapes: g, toggleShapeLock: u, toggleShapeVisibility: d, setCopiedShape: k, copiedShape: x, pasteShapes: M, removeShapePoint: D, transformShape: E })] });
1909
- };
1910
- export {
1911
- Ds as Canvas,
1912
- Es as Editor,
1913
- Ts as useReactPaint
1914
- };
1
+ import{n as e,r as t,t as n}from"./_chunks/canvas-DF1RWuxW.js";import{i as r,t as i}from"./_chunks/array-DuJem3vg.js";import{n as a,t as o}from"./_chunks/editor-DuVskl0R.js";import{useMemo as s}from"react";var c=(e,t)=>{if(Array.isArray(e))return t},l=e=>i(e.map(e=>{if(typeof e!=`object`||!e.type)return null;let t=a.find(t=>t.type===e.type);return t?r(c,t,e):e})),u=({options:n,...r}={})=>{let i=n?.availableTools,o=(n?.withUploadPicture??t.withUploadPicture)||(n?.withUrlPicture??t.withUrlPicture),c=s(()=>{let e=i?l(i):a;return o?e:e.filter(e=>e.type!==`picture`)},[i,o]);return e({...r,options:{...n,availableTools:c}})};export{n as Canvas,o as Editor,u as useReactPaint};