@yorab/react-paint 0.13.1 → 0.15.0

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 (63) hide show
  1. package/README.md +46 -283
  2. package/dist/canvas/components/Canvas.d.ts +15 -7
  3. package/dist/canvas/components/EditTextBox.d.ts +2 -2
  4. package/dist/canvas/constants/app.d.ts +2 -0
  5. package/dist/canvas/constants/keyboard.d.ts +24 -0
  6. package/dist/canvas/constants/shapes.d.ts +1 -1
  7. package/dist/canvas/hooks/useComponent.d.ts +3 -1
  8. package/dist/canvas/hooks/useDebounce.d.ts +2 -0
  9. package/dist/canvas/hooks/useDrawableCanvas.d.ts +12 -7
  10. package/dist/canvas/hooks/useKeyboard.d.ts +15 -8
  11. package/dist/canvas/hooks/useReactPaint.d.ts +1874 -25
  12. package/dist/canvas/hooks/useShapes.d.ts +1393 -13
  13. package/dist/canvas/hooks/useZoom.d.ts +1 -0
  14. package/dist/canvas/index.d.ts +3 -3
  15. package/dist/canvas/utils/canvas.d.ts +2 -0
  16. package/dist/canvas/utils/data.d.ts +2 -2
  17. package/dist/canvas/utils/file.d.ts +233 -4
  18. package/dist/canvas/utils/intersect.d.ts +6 -6
  19. package/dist/canvas/utils/selection/groupSelection.d.ts +3 -0
  20. package/dist/canvas/utils/selection/lineSelection.d.ts +9 -3
  21. package/dist/canvas/utils/selection/rectSelection.d.ts +10 -5
  22. package/dist/canvas/utils/selection.d.ts +11 -4
  23. package/dist/canvas/utils/shapes/brush.d.ts +14 -11
  24. package/dist/canvas/utils/shapes/circle.d.ts +13 -9
  25. package/dist/canvas/utils/shapes/curve.d.ts +15 -10
  26. package/dist/canvas/utils/shapes/ellipse.d.ts +13 -9
  27. package/dist/canvas/utils/shapes/index.d.ts +30 -16
  28. package/dist/canvas/utils/shapes/line.d.ts +13 -8
  29. package/dist/canvas/utils/shapes/path.d.ts +19 -3
  30. package/dist/canvas/utils/shapes/picture.d.ts +13 -9
  31. package/dist/canvas/utils/shapes/polygon.d.ts +15 -9
  32. package/dist/canvas/utils/shapes/rectangle.d.ts +56 -11
  33. package/dist/canvas/utils/shapes/text.d.ts +13 -8
  34. package/dist/canvas/utils/shapes/triangle.d.ts +4 -3
  35. package/dist/canvas/utils/transform.d.ts +4 -4
  36. package/dist/canvas/utils/trigo.d.ts +1 -1
  37. package/dist/common/types/Mode.d.ts +5 -4
  38. package/dist/common/types/Shapes.d.ts +70 -28
  39. package/dist/common/types/tools.d.ts +5 -1
  40. package/dist/common/types/utils.d.ts +1 -1
  41. package/dist/editor/components/common/Button.d.ts +6 -6
  42. package/dist/editor/components/common/FileInput.d.ts +13 -0
  43. package/dist/editor/components/common/Panel.d.ts +1 -1
  44. package/dist/editor/components/settings/ClosedPointsField.d.ts +1 -1
  45. package/dist/editor/components/settings/ColorField.d.ts +1 -1
  46. package/dist/editor/components/settings/DeleteButton.d.ts +3 -3
  47. package/dist/editor/components/settings/FontFamilyField.d.ts +1 -1
  48. package/dist/editor/components/settings/Layouts.d.ts +7 -7
  49. package/dist/editor/components/settings/LineArrowField.d.ts +1 -1
  50. package/dist/editor/components/settings/LineTypeField.d.ts +1 -1
  51. package/dist/editor/components/settings/RangeField.d.ts +1 -1
  52. package/dist/editor/components/settings/SettingsBar.d.ts +4 -4
  53. package/dist/editor/components/settings/ToggleField.d.ts +2 -2
  54. package/dist/editor/components/settings/ZoomButton.d.ts +2 -2
  55. package/dist/editor/constants/icons.d.ts +1 -0
  56. package/dist/editor/constants/tools.d.ts +2 -2
  57. package/dist/editor/hooks/useDrag.d.ts +1 -1
  58. package/dist/editor/index.d.ts +11 -11
  59. package/dist/editor/utils/style.d.ts +1 -1
  60. package/dist/react-paint.css +1 -1
  61. package/dist/react-paint.js +1361 -1188
  62. package/dist/react-paint.umd.cjs +1 -1
  63. package/package.json +19 -15
@@ -1,348 +1,460 @@
1
- import ta, { useState as O, useEffect as G, useRef as J, useCallback as R, useMemo as ia, useImperativeHandle as en, useTransition as aa } from "react";
2
- import { jsx as p, jsxs as I, Fragment as Ce } from "react/jsx-runtime";
3
- const na = '<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>', jt = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', Kt = '<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>', Jt = '<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>', sa = '<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>', di = '<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>', ei = '<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>', oa = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', ra = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', la = '<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>', hi = '<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>', ui = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', pi = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', gi = '<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>', fi = '<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>', ca = '<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>', pe = ["transparent", "black", "white", "red", "green", "blue", "yellow"], $e = [0, 1, 2], vi = [[1, 0], [1, 2], [4, 6]], ut = "serif", tn = 2, da = 3, an = 4, oe = "react-paint-", ti = { type: "picture", id: `${oe}picture`, icon: ei, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, ha = { type: "brush", id: `${oe}brush`, icon: na, label: "Brosse", settings: { strokeColor: { values: pe, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: $e, default: 0 } } }, ua = { type: "line", id: `${oe}line`, icon: ra, label: "Ligne", settings: { strokeColor: { values: pe, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: $e, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, pa = { type: "polygon", id: `${oe}polygon`, icon: Jt, label: "Polygone", settings: { strokeColor: { values: pe, default: "black" }, fillColor: { values: pe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: $e, default: 0 }, closedPoints: { default: 0 } } }, ga = { type: "curve", id: `${oe}curve`, icon: la, label: "Courbe", settings: { strokeColor: { values: pe, default: "black" }, fillColor: { values: pe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: $e, default: 0 }, closedPoints: { default: 0 } } }, fa = { type: "rect", id: `${oe}rect`, icon: jt, label: "Rectangle", settings: { strokeColor: { values: pe, default: "black" }, fillColor: { values: pe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: $e, default: 0 } } }, va = { type: "square", id: `${oe}square`, icon: jt, label: "Carré", settings: { strokeColor: { values: pe, default: "black" }, fillColor: { values: pe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: $e, default: 0 } } }, ma = { type: "circle", id: `${oe}circle`, icon: Kt, label: "Cercle", settings: { strokeColor: { values: pe, default: "black" }, fillColor: { values: pe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: $e, default: 0 } } }, ya = { type: "ellipse", id: `${oe}ellipse`, icon: Kt, label: "Ellipse", settings: { strokeColor: { values: pe, default: "black" }, fillColor: { values: pe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: $e, default: 0 } } }, Qa = { type: "text", id: `${oe}text`, icon: oa, label: "Texte", settings: { strokeColor: { values: pe, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: ut }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Ae = { id: `${oe}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" }, je = { id: `${oe}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" }, Ke = { id: `${oe}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" }, Je = { id: `${oe}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" }, Wt = { id: `${oe}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" }, mi = { id: `${oe}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" }, Nt = { id: `${oe}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" }, Rt = { id: `${oe}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" }, yi = { id: `${oe}upload-picture`, type: "uploadpicture", icon: ei, label: "Upload picture" }, Sa = 2, ba = "blue", Ye = 14, wa = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], xa = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle"], Ca = "react-paint-canvas-drawcanvas", Ma = "react-paint-canvas-selectioncanvas", Qi = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [ha, ua, pa, ga, fa, va, ma, ya, ti, Qa], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !1, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never" }, nn = { canvasBackgroundColor: "white", canvasSelectionColor: ba, canvasSelectionWidth: Sa }, ka = (e, t) => !!(e.target instanceof Node && t) && t.contains(e.target), wt = 300, Ut = (e, t) => {
1
+ import si, { useState as $, useEffect as J, useRef as te, useCallback as B, useMemo as ba, useImperativeHandle as xa, useTransition as wa } from "react";
2
+ import { jsx as v, jsxs as Y, Fragment as Ve } from "react/jsx-runtime";
3
+ const Ca = '<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>', ri = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', li = '<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>', ci = '<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>', Ma = '<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>', Li = '<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>', di = '<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>', ka = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', Pa = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', La = '<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>', Zi = '<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>', Vi = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', Hi = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Ti = '<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>', zi = '<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>', Za = '<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>', we = ["transparent", "black", "white", "red", "green", "blue", "yellow"], Ge = [0, 1, 2], Ai = [[1, 0], [1, 2], [4, 6]], yt = "serif", An = 2, Va = 3, En = 4, ue = "react-paint-", Ha = { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } }, hi = { type: "picture", id: `${ue}picture`, icon: di, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, Ta = { type: "brush", id: `${ue}brush`, icon: Ca, label: "Brosse", settings: { strokeColor: { values: we, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: Ge, default: 0 } } }, za = { type: "line", id: `${ue}line`, icon: Pa, label: "Ligne", settings: { strokeColor: { values: we, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, Aa = { type: "polygon", id: `${ue}polygon`, icon: ci, label: "Polygone", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 }, closedPoints: { default: 0 } } }, Ea = { type: "curve", id: `${ue}curve`, icon: La, label: "Courbe", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 }, closedPoints: { default: 0 } } }, Ia = { type: "rect", id: `${ue}rect`, icon: ri, label: "Rectangle", settings: Ha }, Na = { type: "square", id: `${ue}square`, icon: ri, label: "Carré", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } } }, Da = { type: "circle", id: `${ue}circle`, icon: li, label: "Cercle", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } } }, Ra = { type: "ellipse", id: `${ue}ellipse`, icon: li, label: "Ellipse", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } } }, Wa = { type: "text", id: `${ue}text`, icon: ka, label: "Texte", settings: { strokeColor: { values: we, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: yt }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Fe = { id: `${ue}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" }, rt = { id: `${ue}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: `${ue}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" }, ct = { id: `${ue}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" }, Yt = { id: `${ue}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" }, Ei = { id: `${ue}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" }, Ut = { id: `${ue}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" }, Xt = { id: `${ue}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" }, Ii = { id: `${ue}upload-picture`, type: "uploadpicture", icon: di, label: "Upload picture" }, Oa = 2, Fa = "blue", et = 14, Ba = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], $a = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], Ya = "react-paint-canvas-drawcanvas", Ua = "react-paint-canvas-selectioncanvas", Ni = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [Ta, za, Aa, Ea, Ia, Na, Da, Ra, hi, Wa], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, In = { canvasBackgroundColor: "white", canvasSelectionColor: Fa, canvasSelectionWidth: Oa }, Di = 300, Jt = (e, t) => {
4
4
  const i = { ...t };
5
5
  for (const a of e) delete i[a];
6
6
  return i;
7
- }, Qe = (e, t, i) => {
8
- const a = Array.isArray(i) ? [...i] : { ...i }, s = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
- return s.reduce((n, o, r) => (n[o] = Xt(n[o]) ? { ...n[o] } : Array.isArray(n[o]) ? [...n[o]] : n[o] === void 0 || n[o] === null ? {} : n[o], r === s.length - 1 && (n[o] = t), n[o]), a), a;
10
- }, Xt = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, He = (e, t, i) => {
11
- if (!Xt(t) || !Xt(i)) return i;
7
+ }, Pe = (e, t, i) => {
8
+ const a = Array.isArray(i) ? [...i] : { ...i }, n = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
+ return n.reduce((o, r, l) => (o[r] = ei(o[r]) ? { ...o[r] } : Array.isArray(o[r]) ? [...o[r]] : o[r] === void 0 || o[r] === null ? {} : o[r], l === n.length - 1 && (o[r] = t), o[r]), a), a;
10
+ }, ei = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, Ne = (e, t, i) => {
11
+ if (!ei(t) || !ei(i)) return i;
12
12
  const a = { ...t };
13
- for (const s in i) i.hasOwnProperty(s) && (a.hasOwnProperty(s) ? a[s] = e(a[s], i[s], s) ?? He(e, a[s], i[s]) : a[s] = i[s]);
13
+ for (const n in i) i.hasOwnProperty(n) && (a.hasOwnProperty(n) ? a[n] = e(a[n], i[n], n) ?? Ne(e, a[n], i[n]) : a[n] = i[n]);
14
14
  return a;
15
- }, Pa = (e, t) => {
15
+ }, Xa = (e, t) => {
16
16
  if (e === t) return !0;
17
17
  if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
18
18
  const i = Object.keys(e), a = Object.keys(t);
19
19
  if (i.length !== a.length) return !1;
20
- for (const s of i) if (!a.includes(s) || !Pa(e[s], t[s])) return !1;
20
+ for (const n of i) if (!a.includes(n) || !Xa(e[n], t[n])) return !1;
21
21
  return !0;
22
- }, It = {}, de = (e = "") => (It[e] || (It[e] = 0), `${e}${++It[e]}`), Fe = (e, t, i) => Math.max(t, Math.min(e, i)), La = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), Va = (e) => {
22
+ }, Gt = {}, ye = (e = "") => (Gt[e] || (Gt[e] = 0), `${e}${++Gt[e]}`), De = (e, t, i) => Math.max(t, Math.min(e, i)), Ga = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), qa = (e) => {
23
23
  e.reset(), e.lineCap = "round", e.lineJoin = "round";
24
- }, Ie = (e, t = {}) => {
25
- const { lineCap: i = "round", fillColor: a = "transparent", opacity: s = 100, strokeColor: n = ba, lineWidth: o = Sa, lineDash: r = 0 } = t;
26
- e.lineCap = i, e.globalAlpha = s / 100, e.fillStyle = a, e.strokeStyle = n, e.lineWidth = o, e.setLineDash(r === 0 ? [] : [vi[r][0] * o, vi[r][1] * o]);
27
- }, ii = (e, t, i, a) => {
24
+ }, Qe = (e, t = {}) => {
25
+ const { lineCap: i = "round", fillColor: a = "transparent", opacity: n = 100, strokeColor: o = Fa, lineWidth: r = Oa, lineDash: l = 0, shadowColor: s = "transparent", shadowBlur: c = 0 } = t;
26
+ e.lineCap = i, e.globalAlpha = n / 100, e.fillStyle = a, e.strokeStyle = o, e.lineWidth = r, e.setLineDash(l === 0 ? [] : [Ai[l][0] * r, Ai[l][1] * r]), e.shadowColor = s, e.shadowBlur = c;
27
+ }, Pt = (e, t, i, a) => {
28
28
  e.save(), e.scale(t.canvasSize.scaleRatio, t.canvasSize.scaleRatio), e.translate(t.canvasOffset[0], t.canvasOffset[1]), i && a && (e.translate(a[0], a[1]), e.rotate(i), e.translate(-a[0], -a[1]));
29
- }, ai = (e) => {
29
+ }, _a = (e, { selectionPadding: t }) => {
30
+ const i = e.points.flat(), a = Math.min(...i.map((s) => s[0])), n = Math.min(...i.map((s) => s[1])), o = i.map((s) => ze(s, a, n, e.scaleX, e.scaleY)), r = Math.max(...o.map((s) => s[0])) + t, l = Math.max(...o.map((s) => s[1])) + t;
31
+ return { x: a - t, width: r - a + t, y: n - t, height: l - n + t };
32
+ }, ja = (e, t) => Re(e, _a, t), ht = (e, t) => {
33
+ const i = Wn(e, t), a = ja(e, t);
34
+ return { ...e, path: i, selection: ut(i, a, t), computed: a };
35
+ }, Nn = ht, ti = (e) => 180 * e / Math.PI, Ka = (e, t) => {
36
+ const i = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), a = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
37
+ return Math.sqrt(i * i + a * a) <= t.radius;
38
+ }, xe = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
39
+ const a = [t[0] - e[0], t[1] - e[1]], n = a[1] * Math.cos(i) - a[0] * Math.sin(i);
40
+ return [a[1] * Math.sin(i) + a[0] * Math.cos(i) + e[0], n + e[1]];
41
+ }, Ri = (e) => (e + 2 * Math.PI) % (2 * Math.PI), Wi = ({ targetVector: [e, t], radian: i = !0, originVector: a }) => {
42
+ const n = Ri(Math.atan2(t[1] - e[1], t[0] - e[0]));
43
+ if (a) {
44
+ const [o, r] = a, l = Math.atan2(r[1] - o[1], r[0] - o[0]), s = Ri(n - l);
45
+ return i ? s : ti(s);
46
+ }
47
+ return i ? n : ti(n);
48
+ }, Ja = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), Xe = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, ze = (e, t, i, a = 1, n = 1) => [t + (e[0] - t) * a, i + (e[1] - i) * n], _ = (e, t, i = 0) => {
49
+ if (!t.gridGap) return Xe(e);
50
+ const a = e + i, n = a >= 0 ? t.gridGap : -t.gridGap;
51
+ return a + n / 2 - (a + n / 2) % n - i;
52
+ }, Dn = (e, t, i) => t.gridGap || i ? e + Math.PI / 18 / 2 - (e + Math.PI / 18 / 2) % (Math.PI / 18) : Xe(e, 3), Oe = (e, t) => t ? [Math.abs(e[0]) > Math.abs(e[1]) ? e[0] : 0, Math.abs(e[1]) > Math.abs(e[0]) ? e[1] : 0] : e, Rn = (e, t, i, a, n, o, r) => be(j(t).map((l) => {
53
+ switch (a.mode) {
54
+ case "brush":
55
+ return ((s, c, u) => {
56
+ const d = { ...s, points: Pe(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(c[0]), Math.round(c[1])]], s.points) };
57
+ return ht(d, u);
58
+ })(l, i, n);
59
+ case "translate":
60
+ return oi(i, j(a.originalShape).find((s) => s.id === l.id), a.cursorStartPosition, n, o);
61
+ case "rotate":
62
+ return go(l, i, j(a.originalShape).find((s) => s.id === l.id), a.cursorStartPosition, a.center, n, o);
63
+ case "resize":
64
+ return vo(e, l, i, j(a.originalShape).find((s) => s.id === l.id), a, n, o, r);
65
+ default:
66
+ return l;
67
+ }
68
+ }), n), ui = (e) => {
30
69
  const t = new Path2D();
31
70
  return t.rect(e.x, e.y, e.width, e.height), t;
32
- }, xt = (e) => {
71
+ }, Lt = (e) => {
33
72
  const t = new Path2D();
34
73
  return t.arc(e.x, e.y, e.radius, 0, 2 * Math.PI), t;
35
- }, Ct = (e) => {
74
+ }, Zt = (e) => {
36
75
  const t = new Path2D();
37
76
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t;
38
- }, Ha = (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]], Za = (e, t, i, a, s) => {
39
- const n = i[0] + (a[0] - t[0]) / 6, o = i[1] + (a[1] - t[1]) / 6, r = a[0] - (s[0] - i[0]) / 6, l = a[1] - (s[1] - i[1]) / 6;
40
- e.bezierCurveTo(n, o, r, l, a[0], a[1]);
41
- }, Ta = (e) => {
77
+ }, Wn = (e, { brushAlgo: t }) => {
78
+ if (e.points.length < 1 || e.style?.strokeColor === "transparent") return;
79
+ const i = e.points.flat(), a = i.map((s) => s[0]), n = i.map((s) => s[1]), o = Math.min(...a), r = Math.min(...n), l = new Path2D();
80
+ for (const s of e.points) {
81
+ if (!s.length) return;
82
+ if (s.length === 1) l.rect(...ze(s[0], o, r, e.scaleX, e.scaleY), 1, 1);
83
+ else if (l.moveTo(...ze(s[0], o, r, e.scaleX, e.scaleY)), t === "quadratic") {
84
+ for (let c = 0; c < s.slice(1).length - 2; c++) {
85
+ const u = ze(s[c], o, r, e.scaleX, e.scaleY), d = ze(s[c + 1], o, r, e.scaleX, e.scaleY), h = (u[0] + d[0]) / 2, f = (u[1] + d[1]) / 2;
86
+ l.quadraticCurveTo(...u, h, f);
87
+ }
88
+ l.quadraticCurveTo(...ze(s[s.length - 2], o, r, e.scaleX, e.scaleY), ...ze(s[s.length - 1], o, r, e.scaleX, e.scaleY));
89
+ } else for (const c of s.slice(1)) l.lineTo(...ze(c, o, r, e.scaleX, e.scaleY));
90
+ }
91
+ return l;
92
+ }, On = (e, t, i, a) => {
93
+ const n = (b) => (1 - b) ** 3 * e[0] + 3 * (1 - b) ** 2 * b * t[0] + 3 * (1 - b) * b ** 2 * i[0] + b ** 3 * a[0], o = (b) => (1 - b) ** 3 * e[1] + 3 * (1 - b) ** 2 * b * t[1] + 3 * (1 - b) * b ** 2 * i[1] + b ** 3 * a[1], r = (b, Z, A) => {
94
+ const T = b - 2 * Z + A, S = -2 * b + 2 * Z, V = b;
95
+ if (Math.abs(T) < 1e-10) {
96
+ if (Math.abs(S) < 1e-10) return [];
97
+ const F = -V / S;
98
+ return F > 0 && F < 1 ? [F] : [];
99
+ }
100
+ const I = S * S - 4 * T * V;
101
+ if (I < 0) return [];
102
+ const N = Math.sqrt(I), H = (-S - N) / (2 * T), D = (-S + N) / (2 * T), U = [];
103
+ return H > 0 && H < 1 && U.push(H), D > 0 && D < 1 && D !== H && U.push(D), U;
104
+ }, l = e[0], s = t[0], c = i[0], u = a[0], d = e[1], h = t[1], f = i[1], g = a[1], x = r(s - l, c - s, u - c), C = r(h - d, f - h, g - f);
105
+ let k = Math.min(e[0], a[0]), w = Math.max(e[0], a[0]), m = Math.min(e[1], a[1]), y = Math.max(e[1], a[1]);
106
+ for (const b of x) {
107
+ const Z = n(b);
108
+ k = Math.min(k, Z), w = Math.max(w, Z);
109
+ }
110
+ for (const b of C) {
111
+ const Z = o(b);
112
+ m = Math.min(m, Z), y = Math.max(y, Z);
113
+ }
114
+ return { minX: k, maxX: w, minY: m, maxY: y };
115
+ }, pi = (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]], gi = (e, t, i, a) => ({ cp1: [t[0] + (i[0] - e[0]) / 6, t[1] + (i[1] - e[1]) / 6], cp2: [i[0] - (a[0] - t[0]) / 6, i[1] - (a[1] - t[1]) / 6] }), en = (e) => {
42
116
  const t = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
43
117
  if (t.length < 2) return;
44
118
  const i = new Path2D();
45
119
  i.moveTo(...t[0]);
46
120
  for (const a of t.slice(1)) i.lineTo(...a);
47
121
  return t.length > 2 && e.style?.closedPoints === 1 && i.lineTo(...t[0]), i;
48
- }, sn = (e) => {
122
+ }, Fn = (e) => {
49
123
  const t = new Path2D();
50
124
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t.lineTo(...e.points[2]), t.lineTo(...e.points[0]), t;
51
- }, Yt = (e) => 180 * e / Math.PI, za = (e, t) => {
52
- const i = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), a = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
53
- return Math.sqrt(i * i + a * a) <= t.radius;
54
- }, we = ({ origin: e = [0, 0], point: t, rotation: i }) => {
55
- const a = [t[0] - e[0], t[1] - e[1]], s = a[1] * Math.cos(i) - a[0] * Math.sin(i);
56
- return [a[1] * Math.sin(i) + a[0] * Math.cos(i) + e[0], s + e[1]];
57
- }, Si = (e) => (e + 2 * Math.PI) % (2 * Math.PI), bi = ({ targetVector: [e, t], radian: i = !0, originVector: a }) => {
58
- const s = Si(Math.atan2(t[1] - e[1], t[0] - e[0]));
59
- if (a) {
60
- const [n, o] = a, r = Math.atan2(o[1] - n[1], o[0] - n[0]), l = Si(s - r);
61
- return i ? l : Yt(l);
62
- }
63
- return i ? s : Yt(s);
64
- }, Aa = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), tt = (e, t, i) => {
65
- const { borders: a } = ee(t, i);
66
- return { border: ai(a), shapePath: e, line: Ct({ points: [[a.x + a.width / 2, a.y], [a.x + a.width / 2, a.y - 23 / i.canvasSize.scaleRatio]] }), anchors: [xt({ x: a.x + a.width / 2, y: a.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...wa.map((s) => xt({ x: a.x + a.width * s[0], y: a.y + a.height * s[1], radius: 7 / i.canvasSize.scaleRatio }))] };
67
- }, wi = ({ borderStart: e, borderSize: t, vector: i, settings: a, invertedAxe: s, anchor: n }) => {
68
- switch (n) {
125
+ }, Bn = (e, t) => ({ x: e.x - (t?.lineWidth ?? 0) / 2, y: e.y - (t?.lineWidth ?? 0) / 2, width: e.width + (t?.lineWidth ?? 0), height: e.height + (t?.lineWidth ?? 0) }), Re = (e, t, i, a = Bn) => {
126
+ const n = t(e, i), o = a(n, e.style), r = [n.x + n.width / 2, n.y + n.height / 2], l = ((s, c, u = 0) => {
127
+ if (u === 0) return s;
128
+ 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((g) => xe({ point: g, origin: c, rotation: u })), h = Math.min(...d.map((g) => g[0])), f = Math.min(...d.map((g) => g[1]));
129
+ return { x: h, y: f, width: Math.max(...d.map((g) => g[0])) - h, height: Math.max(...d.map((g) => g[1])) - f };
130
+ })(o, r, e.rotation);
131
+ return { borders: n, outerBorders: o, center: r, boundingBox: l };
132
+ }, ut = (e, t, i, a = !1) => {
133
+ const { borders: n } = t;
134
+ return { border: ui(n), shapePath: e, line: a ? void 0 : Zt({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: a ? [] : [Lt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...Ba.map((o) => Lt({ x: n.x + n.width * o[0], y: n.y + n.height * o[1], radius: 7 / i.canvasSize.scaleRatio }))] };
135
+ }, Oi = ({ borderStart: e, borderSize: t, vector: i, settings: a, invertedAxe: n, anchor: o }) => {
136
+ switch (o) {
69
137
  case 0: {
70
- if (s) {
71
- const r = t - 2 * a.selectionPadding;
72
- return [e + r, i - r];
138
+ if (n) {
139
+ const l = t - 2 * a.selectionPadding;
140
+ return [e + l, i - l];
73
141
  }
74
- const o = Math.max(2 * a.selectionPadding, t - i);
75
- return [e + t - o, o];
142
+ const r = Math.max(2 * a.selectionPadding, t - i);
143
+ return [e + t - r, r];
76
144
  }
77
145
  case 0.5:
78
146
  return [e, t];
79
147
  case 1:
80
- if (s) {
81
- const o = t + i;
82
- return [e + o, 2 * a.selectionPadding - o];
148
+ if (n) {
149
+ const r = t + i;
150
+ return [e + r, 2 * a.selectionPadding - r];
83
151
  }
84
152
  return [e, Math.max(2 * a.selectionPadding, t + i)];
85
153
  default:
86
154
  return [0, 0];
87
155
  }
88
- }, _e = (e, t, i, a, s = !1, n = !1) => {
89
- const { center: o, borders: r } = ee(t, a), l = we({ origin: o, point: e, rotation: t.rotation }), d = i.anchor[0] === 0 && l[0] >= r.x + r.width || i.anchor[0] === 1 && l[0] <= r.x, h = i.anchor[1] === 0 && l[1] >= r.y + r.height || i.anchor[1] === 1 && l[1] <= r.y, c = [$(l[0], a, i.anchor[0] === 0 && !d || i.anchor[0] === 1 && d ? a.selectionPadding : -a.selectionPadding), $(l[1], a, i.anchor[1] === 0 && !h || i.anchor[1] === 1 && h ? a.selectionPadding : -a.selectionPadding)], u = a.gridGap ? [i.anchor[0] === 0 ? r.x : i.anchor[0] === 0.5 ? r.x + r.width / 2 : r.x + r.width, i.anchor[1] === 0 ? r.y : i.anchor[1] === 0.5 ? r.y + r.height / 2 : r.y + r.height] : we({ origin: o, point: i.cursorStartPosition, rotation: t.rotation }), g = [c[0] - u[0], c[1] - u[1]], [f, w] = wi({ borderStart: r.x, borderSize: r.width, vector: g[0], settings: a, invertedAxe: d, anchor: i.anchor[0] }), [x, C] = wi({ borderStart: r.y, borderSize: r.height, vector: g[1], settings: a, invertedAxe: h, anchor: i.anchor[1] }), b = s ? ((k, v, Q, V, T, D, H, Z, F, N) => {
90
- const { selectionPadding: W } = N, Y = (v.width - 2 * W || 1) / (v.height - 2 * W || 1), q = (T - 2 * W) / (H - 2 * W);
91
- let L, m, y, S;
92
- return F.anchor[0] !== 0.5 && F.anchor[1] !== 0.5 ? q < Y ? (m = D, S = H, y = (H - 2 * W) * Y + 2 * W, L = F.anchor[0] === 0 ? v.width - k[0] > W ? v.x + (v.width - y) : v.x + v.width - 2 * W : v.width + k[0] > W ? v.x : v.x - y + 2 * W) : (L = V, y = T, S = (T - 2 * W) / Y + 2 * W, m = F.anchor[1] === 0 ? v.height - k[1] > W ? v.y + (v.height - S) : v.y + v.height - 2 * W : v.height + k[1] > W ? v.y : v.y - S + 2 * W) : F.anchor[0] !== 0.5 ? (L = V, y = T, S = (T - 2 * W) / Y + 2 * W, m = v.y + (v.height - S) / 2) : (m = D, S = H, y = (H - 2 * W) * Y + 2 * W, L = v.x + (v.width - y) / 2), { borderX: L, borderWidth: y, borderY: m, borderHeight: S, center: Q, originalShape: Z };
93
- })(g, r, o, f, w, x, C, t, i, a) : { borderX: f, borderWidth: w, borderY: x, borderHeight: C, center: o, originalShape: t };
94
- return (({ borderX: k, borderWidth: v, borderY: Q, borderHeight: V, center: T, originalShape: D }) => {
95
- const H = [k + v / 2 - T[0], Q + V / 2 - T[1]], [Z, F] = we({ point: H, rotation: -D.rotation });
96
- return { borderX: Oe(k + Z - H[0]), borderWidth: Oe(v), borderY: Oe(Q + F - H[1]), borderHeight: Oe(V) };
97
- })(n ? ((k, v, Q, V) => {
98
- const T = v.x + v.width / 2, D = v.y + v.height / 2, H = Q ? 2 * k.borderWidth + v.width : Math.abs(v.width + 2 * (k.borderWidth - v.width)), Z = V ? 2 * k.borderHeight + v.height : Math.abs(v.height + 2 * (k.borderHeight - v.height));
99
- return { ...k, borderHeight: Z, borderWidth: H, borderX: T - H / 2, borderY: D - Z / 2 };
100
- })(b, r, d, h) : b);
101
- }, it = (e, t) => {
102
- const i = ((a, { brushAlgo: s }) => {
103
- if (a.points.length < 1 || a.style?.strokeColor === "transparent") return;
104
- const n = a.points.flat(), o = n.map((c) => c[0]), r = n.map((c) => c[1]), l = Math.min(...o), d = Math.min(...r), h = new Path2D();
105
- for (const c of a.points) {
106
- if (!c.length) return;
107
- if (c.length === 1) h.rect(...Me(c[0], l, d, a.scaleX, a.scaleY), 1, 1);
108
- else if (h.moveTo(...Me(c[0], l, d, a.scaleX, a.scaleY)), s === "quadratic") {
109
- for (let u = 0; u < c.slice(1).length - 2; u++) {
110
- const g = Me(c[u], l, d, a.scaleX, a.scaleY), f = Me(c[u + 1], l, d, a.scaleX, a.scaleY), w = (g[0] + f[0]) / 2, x = (g[1] + f[1]) / 2;
111
- h.quadraticCurveTo(...g, w, x);
112
- }
113
- h.quadraticCurveTo(...Me(c[c.length - 2], l, d, a.scaleX, a.scaleY), ...Me(c[c.length - 1], l, d, a.scaleX, a.scaleY));
114
- } else for (const u of c.slice(1)) h.lineTo(...Me(u, l, d, a.scaleX, a.scaleY));
156
+ }, nt = (e, t, i, a, n = !1, o = !1) => {
157
+ const { center: r, borders: l } = t.computed, s = xe({ origin: r, point: e, rotation: t.rotation }), c = i.anchor[0] === 0 && s[0] >= l.x + l.width || i.anchor[0] === 1 && s[0] <= l.x, u = i.anchor[1] === 0 && s[1] >= l.y + l.height || i.anchor[1] === 1 && s[1] <= l.y, d = [_(s[0], a, i.anchor[0] === 0 && !c || i.anchor[0] === 1 && c ? a.selectionPadding : -a.selectionPadding), _(s[1], a, i.anchor[1] === 0 && !u || i.anchor[1] === 1 && u ? a.selectionPadding : -a.selectionPadding)], h = a.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] : xe({ origin: r, point: i.cursorStartPosition, rotation: t.rotation }), f = [d[0] - h[0], d[1] - h[1]], [g, x] = Oi({ borderStart: l.x, borderSize: l.width, vector: f[0], settings: a, invertedAxe: c, anchor: i.anchor[0] }), [C, k] = Oi({ borderStart: l.y, borderSize: l.height, vector: f[1], settings: a, invertedAxe: u, anchor: i.anchor[1] }), w = n ? ((m, y, b, Z, A, T, S, V, I, N) => {
158
+ const { selectionPadding: H } = N, D = (y.width - 2 * H || 1) / (y.height - 2 * H || 1), U = (A - 2 * H) / (S - 2 * H);
159
+ let F, X, p, Q;
160
+ return I.anchor[0] !== 0.5 && I.anchor[1] !== 0.5 ? U < D ? (X = T, Q = S, p = (S - 2 * H) * D + 2 * H, F = I.anchor[0] === 0 ? y.width - m[0] > H ? y.x + (y.width - p) : y.x + y.width - 2 * H : y.width + m[0] > H ? y.x : y.x - p + 2 * H) : (F = Z, p = A, Q = (A - 2 * H) / D + 2 * H, X = I.anchor[1] === 0 ? y.height - m[1] > H ? y.y + (y.height - Q) : y.y + y.height - 2 * H : y.height + m[1] > H ? y.y : y.y - Q + 2 * H) : I.anchor[0] !== 0.5 ? (F = Z, p = A, Q = (A - 2 * H) / D + 2 * H, X = y.y + (y.height - Q) / 2) : (X = T, Q = S, p = (S - 2 * H) * D + 2 * H, F = y.x + (y.width - p) / 2), { borderX: F, borderWidth: p, borderY: X, borderHeight: Q, center: b, originalShape: V };
161
+ })(f, l, r, g, x, C, k, t, i, a) : { borderX: g, borderWidth: x, borderY: C, borderHeight: k, center: r, originalShape: t };
162
+ return (({ borderX: m, borderWidth: y, borderY: b, borderHeight: Z, center: A, originalShape: T }) => {
163
+ const S = [m + y / 2 - A[0], b + Z / 2 - A[1]], [V, I] = xe({ point: S, rotation: -(T.rotation ?? 0) });
164
+ return { borderX: Xe(m + V - S[0]), borderWidth: Xe(y), borderY: Xe(b + I - S[1]), borderHeight: Xe(Z) };
165
+ })(o ? ((m, y, b, Z) => {
166
+ const A = y.x + y.width / 2, T = y.y + y.height / 2, S = b ? 2 * m.borderWidth + y.width : Math.abs(y.width + 2 * (m.borderWidth - y.width)), V = Z ? 2 * m.borderHeight + y.height : Math.abs(y.height + 2 * (m.borderHeight - y.height));
167
+ return { ...m, borderHeight: V, borderWidth: S, borderX: A - S / 2, borderY: T - V / 2 };
168
+ })(w, l, c, u) : w);
169
+ }, tn = (e, t) => Re(e, vi, t), Ht = (e, t, i = !1) => {
170
+ const a = ui(e), n = tn(e, t);
171
+ return { ...e, path: a, computed: n, selection: ut(a, n, t, i) };
172
+ }, $n = Ht, an = (e, t, i, a = !1, n = 0, o = 0) => {
173
+ const r = { toolId: e.id, type: e.type, id: ye(`${e.type}_`), x: t[0], y: t[1], width: n, height: o, 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 } };
174
+ return Ht(r, i, a);
175
+ }, Yn = (e, t) => {
176
+ e.globalAlpha !== 0 && t.path && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
177
+ }, vi = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), Fi = (e, t, i, [a, n] = [!1, !1]) => {
178
+ const o = e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (a ? 0 : i.width) : i.x + (a ? i.width : 0), r = e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (n ? 0 : i.height) : i.y + (n ? i.height : 0);
179
+ return Gn([o, r], i.rotation ?? 0, t);
180
+ }, Bi = (e, t, i, a, n, o, r, l) => {
181
+ let s = !1;
182
+ if (n) {
183
+ s = mt(e, n, i, a, !0, o ? 20 : void 0);
184
+ const u = ((d, h, f) => {
185
+ if (d.mode === "translate") return { mode: "translate", cursorStartPosition: f, originalShape: h, dateStart: Date.now() };
186
+ if (d.mode === "rotate") {
187
+ const { center: g } = h.computed;
188
+ return { mode: "rotate", cursorStartPosition: f, originalShape: h, center: [g[0], g[1]] };
189
+ }
190
+ return d.mode === "resize" ? { mode: "resize", cursorStartPosition: f, originalShape: h, anchor: d.anchor } : void 0;
191
+ })(s || { mode: "default" }, n, i);
192
+ if (u?.mode === "resize" || u?.mode === "rotate") return { shape: n, mode: u };
193
+ }
194
+ const c = t.find((u) => j(n).find((d) => u.id === d?.id) ? s && l ? mt(e, u, i, a, !0, o ? 20 : void 0) : !!s : !!rn(e, u, i, a));
195
+ if (c) {
196
+ if (l) {
197
+ const d = j(n).find((h) => h.id === c?.id) ? be(Xn(n, c), a) : be(nn(n, [c]), a);
198
+ return { shape: d, mode: { mode: "translate", cursorStartPosition: i, dateStart: Date.now(), originalShape: d } };
115
199
  }
116
- return h;
117
- })(e, t);
118
- return { ...e, path: i, selection: tt(i, e, t) };
119
- }, on = it, Oe = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Me = (e, t, i, a = 1, s = 1) => [t + (e[0] - t) * a, i + (e[1] - i) * s], $ = (e, t, i = 0) => {
120
- if (!t.gridGap) return Oe(e);
121
- const a = e + i, s = a >= 0 ? t.gridGap : -t.gridGap;
122
- return a + s / 2 - (a + s / 2) % s - i;
123
- }, rn = (e, t, i) => t.gridGap || i ? e + Math.PI / 18 / 2 - (e + Math.PI / 18 / 2) % (Math.PI / 18) : Oe(e, 3), ze = (e, t) => t ? [Math.abs(e[0]) > Math.abs(e[1]) ? e[0] : 0, Math.abs(e[1]) > Math.abs(e[0]) ? e[1] : 0] : e, ln = (e, t, i, a, s, n, o) => {
124
- switch (a.mode) {
125
- case "brush":
126
- return ((r, l, d) => {
127
- const h = { ...r, points: Qe(r.points.length - 1, [...r.points[r.points.length - 1], [Math.round(l[0]), Math.round(l[1])]], r.points) };
128
- return it(h, d);
129
- })(t, i, s);
130
- case "translate":
131
- return _t(i, a.originalShape, a.cursorStartPosition, s, n);
132
- case "rotate":
133
- return xn(t, i, a.originalShape, a.cursorStartPosition, a.center, s, n);
134
- case "resize":
135
- return Cn(e, t, i, a.originalShape, a, s, n, o);
136
- default:
137
- return t;
200
+ const u = j(n).find((d) => d.id === c?.id) ? n : be([c], a);
201
+ return { shape: u, mode: { mode: "translate", cursorStartPosition: i, dateStart: Date.now(), originalShape: u } };
138
202
  }
139
- }, Ea = (e) => {
203
+ return l ? { shape: n, mode: { mode: r ? "selectionFrame" : "default" } } : { shape: void 0, mode: { mode: r ? "selectionFrame" : "default" } };
204
+ }, Un = (e, t, i = !0) => {
205
+ const a = [[e.x, e.y], [e.x + e.width, e.y], [e.x + e.width, e.y + e.height], [e.x, e.y + e.height]];
206
+ if (!i) return a;
207
+ const n = [e.x + e.width / 2, e.y + e.height / 2];
208
+ return a.map((o) => xe({ point: [o[0], o[1]], origin: n, rotation: t }));
209
+ }, be = (e, t) => {
210
+ if (!e.length) return;
211
+ if (e.length === 1) return e[0];
212
+ let i = Number.POSITIVE_INFINITY, a = Number.POSITIVE_INFINITY, n = Number.NEGATIVE_INFINITY, o = Number.NEGATIVE_INFINITY;
213
+ const r = e.some((u) => u.rotation !== e[0].rotation), l = r ? 0 : e[0]?.rotation ?? 0;
214
+ for (const u of e) {
215
+ const { borders: d } = u.computed, h = Un(d, u.rotation ?? 0, r);
216
+ i = Math.min(h[0][0], h[1][0], h[2][0], h[3][0], i), n = Math.max(h[0][0], h[1][0], h[2][0], h[3][0], n), a = Math.min(h[0][1], h[1][1], h[2][1], h[3][1], a), o = Math.max(h[0][1], h[1][1], h[2][1], h[3][1], o);
217
+ }
218
+ const s = an({ id: "test", type: "rect", settings: Ha }, [i, a], t, !0, n - i, o - a), c = e.slice(1).reduce((u, d) => {
219
+ const h = d.style ?? {}, f = {};
220
+ for (const g in h) u[g] !== void 0 && h[g] !== void 0 && u[g] === h[g] && (f[g] = u[g]);
221
+ return f;
222
+ }, e[0].style ?? {});
223
+ return { id: e.map((u) => u.id).join("-"), type: "group", shapes: e, rotation: l, visible: !0, locked: !1, selection: s.selection, x: s.x, y: s.y, width: s.width, height: s.height, style: c, computed: s.computed };
224
+ }, $i = (e, t) => (i) => {
225
+ if (!i) return;
226
+ const a = i.type === "group" ? i.shapes.map((n) => e(n, t)) : [e(i, t)];
227
+ return be(a, t);
228
+ }, j = (e) => e ? e.type === "group" ? e.shapes : [e] : [], nn = (e, t) => {
229
+ const i = j(e);
230
+ return [.../* @__PURE__ */ new Set([...i, ...t])];
231
+ }, Xn = (e, t) => j(e).filter((i) => i.id !== t.id), on = (e) => {
140
232
  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 : {};
141
233
  return { clientX: t, clientY: i };
142
- }, lt = (e, t, i) => {
143
- const { clientX: a, clientY: s } = Ea(e), n = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
144
- return [(a - n.left) * (i.canvasSize.width / n.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (s - n.top) * (i.canvasSize.height / n.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
145
- }, ct = (e) => "touches" in e, ke = (e, t, [i, a]) => we({ origin: [i, a], point: e, rotation: t }), mt = (e, t, i) => i ? za(e, { x: t[0], y: t[1], radius: i }) : ((a, s) => s[0] >= a.x && s[0] <= a.x + a.width && s[1] >= a.y && s[1] <= a.y + a.height)(e, t), ht = (e, t, i, a, s = !1, n = 0) => {
234
+ }, sn = (e, t, i) => {
235
+ const { clientX: a, clientY: n } = on(e), o = t.getBoundingClientRect();
236
+ return [(a - o.left) / i.scaleRatio, (n - o.top) / i.scaleRatio];
237
+ }, ot = (e, t, i) => {
238
+ const { clientX: a, clientY: n } = on(e), o = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
239
+ return [(a - o.left) * (i.canvasSize.width / o.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (n - o.top) * (i.canvasSize.height / o.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
240
+ }, st = (e) => "touches" in e, Ae = (e, t, [i, a]) => xe({ origin: [i, a], point: e, rotation: t }), Gn = (e, t, [i, a]) => xe({ origin: [i, a], point: e, rotation: -t }), xt = (e, t, i) => i ? Ka(e, { x: t[0], y: t[1], radius: i }) : ((a, n) => n[0] >= a.x && n[0] <= a.x + a.width && n[1] >= a.y && n[1] <= a.y + a.height)(e, t), mt = (e, t, i, a, n = !1, o = 0) => {
146
241
  if (t.locked) return !1;
147
- const { canvasSize: { scaleRatio: o } } = a, { borders: r, center: l } = ee(t, a), d = ke(i, t.rotation, l);
148
- if (s) if (t.type === "line" || t.type === "polygon" || t.type === "curve") {
149
- for (let h = 0; h < t.points.length; h++) if (mt({ x: t.points[h][0] - 7 / o, y: t.points[h][1] - 7 / o, width: Ye / o, height: Ye / o }, d, n)) return { mode: "resize", anchor: h };
150
- } else {
151
- if (mt({ x: r.x + r.width / 2 - 7 / o, y: r.y - Ye / o - 16 / o, width: Ye / o, height: Ye / o }, d, n)) return { mode: "rotate" };
152
- for (const h of wa) if (mt({ x: r.x + r.width * h[0] - 7 / o, y: r.y + r.height * h[1] - 7 / o, width: Ye / o, height: Ye / o }, d, n)) return { mode: "resize", anchor: h };
242
+ const { canvasSize: { scaleRatio: r } } = a, { borders: l, center: s } = t.computed, c = Ae(i, t.rotation ?? 0, s), u = j(t);
243
+ if (n) {
244
+ if (u.length !== 1 || u[0]?.type !== "line" && u[0]?.type !== "polygon" && u[0]?.type !== "curve") {
245
+ if (u.length === 1) {
246
+ if (xt({ x: l.x + l.width / 2 - 7 / r, y: l.y - et / r - 16 / r, width: et / r, height: et / r }, c, o)) return { mode: "rotate" };
247
+ for (const d of Ba) if (xt({ x: l.x + l.width * d[0] - 7 / r, y: l.y + l.height * d[1] - 7 / r, width: et / r, height: et / r }, c, o)) return { mode: "resize", anchor: d };
248
+ }
249
+ } else for (let d = 0; d < u[0].points.length; d++) if (xt({ x: u[0].points[d][0] - 7 / r, y: u[0].points[d][1] - 7 / r, width: et / r, height: et / r }, c, o)) return { mode: "resize", anchor: d };
153
250
  }
154
- return (mt(r, d, n) || !!(t.type === "curve" && "path" in t && t.path && e.isPointInPath(t.path, d[0], d[1]))) && { mode: "translate" };
155
- }, xi = (e, t, i, a, s = 50) => {
251
+ return (xt(l, c, o) || !!(t.type === "curve" && "path" in t && t.path && e.isPointInPath(t.path, c[0], c[1]))) && { mode: "translate" };
252
+ }, Yi = (e, t, i, a, n = 50) => {
156
253
  if (t.locked || t.points.length < 2) return !1;
157
- const { center: n } = ee(t, a), o = ke(i, t.rotation, n);
158
- e.lineWidth = (t.style?.lineWidth ?? 0) + s / a.canvasZoom;
159
- const r = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
160
- for (let l = 0; l < r.length - 1; l++) {
161
- const d = Ct({ points: [r[l], r[l + 1]] });
162
- if (e.isPointInStroke(d, o[0], o[1])) return { lineIndex: l };
254
+ const { center: o } = t.computed, r = Ae(i, t.rotation ?? 0, o);
255
+ e.lineWidth = (t.style?.lineWidth ?? 0) + n / a.canvasZoom;
256
+ const l = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
257
+ for (let s = 0; s < l.length - 1; s++) {
258
+ const c = Zt({ points: [l[s], l[s + 1]] });
259
+ if (e.isPointInStroke(c, r[0], r[1])) return { lineIndex: s };
163
260
  }
164
261
  return !1;
165
- }, Da = (e, t, i, a) => {
262
+ }, rn = (e, t, i, a) => {
166
263
  if (t.locked) return !1;
167
- const { center: s } = ee(t, a), n = ke(i, t.rotation, s);
168
- return "path" in t && t.path ? t.style?.fillColor && t.style?.fillColor !== "transparent" ? !!e.isPointInPath(t.path, n[0], n[1]) && { mode: "translate" } : (e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / a.canvasZoom, !!e.isPointInStroke(t.path, n[0], n[1]) && { mode: "translate" }) : ht(e, t, i, a, !1);
264
+ const { center: n } = t.computed, o = Ae(i, t.rotation ?? 0, n);
265
+ return "path" in t && t.path ? t.style?.fillColor && t.style?.fillColor !== "transparent" ? !!e.isPointInPath(t.path, o[0], o[1]) && { mode: "translate" } : (e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / a.canvasZoom, !!e.isPointInStroke(t.path, o[0], o[1]) && { mode: "translate" }) : mt(e, t, i, a, !1);
169
266
  };
170
- function qt(e, t) {
171
- const i = Math.max(e.x, t.x), a = Math.max(e.y, t.y), s = Math.min(e.x + (e.width || 1), t.x + (t.width || 1)), n = Math.min(e.y + (e.height || 1), t.y + (t.height || 1));
172
- if (i < s && a < n) return { x: i, y: a, width: s - i, height: n - a };
267
+ function ii(e, t) {
268
+ const i = Math.max(e.x, t.x), a = Math.max(e.y, t.y), n = 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));
269
+ if (i < n && a < o) return { x: i, y: a, width: n - i, height: o - a };
173
270
  }
174
- const Ci = ({ ctx: e, path: t, rect: i, offset: a, checkFill: s }) => {
175
- for (let n = 0; n < a; n += a / 2) for (let o = 0; o < a; o += a / 2) for (let r = n + i.x; r < i.x + i.width; r += a) for (let l = o + i.y; l < i.y + i.height; l += a) if (s ? e.isPointInPath(t, r, l) : e.isPointInStroke(t, r, l)) return !0;
271
+ const Ui = ({ ctx: e, path: t, rect: i, offset: a, checkFill: n }) => {
272
+ for (let o = 0; o < a; o += a / 2) for (let r = 0; r < a; r += a / 2) for (let l = o + i.x; l < i.x + i.width; l += a) for (let s = r + i.y; s < i.y + i.height; s += a) if (n ? e.isPointInPath(t, l, s) : e.isPointInStroke(t, l, s)) return !0;
176
273
  return !1;
177
- }, ni = (e, t, i) => {
178
- const { borders: a } = ee(t, i);
179
- return { border: ai(a), shapePath: e, anchors: [...t.points.map((s) => xt({ x: s[0], y: s[1], radius: 7 / i.canvasSize.scaleRatio }))] };
180
- }, me = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], Mi = ({ size: e, zoom: t, newOffset: [i, a], canvasSize: s }) => e === "infinite" ? { zoom: t, offset: [i, a] } : t < 1 ? { zoom: t, offset: [-(s.realWidth - s.realWidth / t) / 2, -(s.realHeight - s.realHeight / t) / 2] } : { zoom: t, offset: [Fe(i, s.realWidth / t - s.realWidth, 0), Fe(a, s.realHeight / t - s.realHeight, 0)] }, Gt = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: a, zoom: s, centerPoint: n }) => {
181
- const o = e === "fixed" && s < 1 ? [t.realWidth / 2, t.realHeight / 2] : n, r = i[0] - (o[0] / a - o[0] / s), l = i[1] - (o[1] / a - o[1] / s);
182
- return { offset: e === "infinite" ? [r, l] : s < 1 ? [-(t.realWidth - t.realWidth / s) / 2, -(t.realHeight - t.realHeight / s) / 2] : [Fe(r, t.realWidth / s - t.realWidth, 0), Fe(l, t.realHeight / s - t.realHeight, 0)], zoom: s };
183
- }, Wa = (e) => {
184
- const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: a }, canvasZoom: s, canvasOffset: n } = e;
185
- return { x: n[0] * s * a, y: n[1] * s * a, width: t * s, height: i * s };
186
- }, Na = (e, t) => {
274
+ }, fi = (e, t, i, a) => ({ border: ui(i.borders), shapePath: e, anchors: [...t.points.map((n) => Lt({ x: n[0], y: n[1], radius: 7 / a.canvasSize.scaleRatio }))] }), Me = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], ai = ({ size: e, zoom: t, newOffset: [i, a], canvasSize: n }) => e === "infinite" ? { zoom: t, offset: [i, a] } : t < 1 ? { zoom: t, offset: [-(n.realWidth - n.realWidth / t) / 2, -(n.realHeight - n.realHeight / t) / 2] } : { zoom: t, offset: [De(i, n.realWidth / t - n.realWidth, 0), De(a, n.realHeight / t - n.realHeight, 0)] }, ni = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: a, zoom: n, centerPoint: o }) => {
275
+ const r = e === "fixed" && n < 1 ? [t.realWidth / 2, t.realHeight / 2] : o, l = i[0] - (r[0] / a - r[0] / n), s = i[1] - (r[1] / a - r[1] / n);
276
+ return { offset: e === "infinite" ? [l, s] : n < 1 ? [-(t.realWidth - t.realWidth / n) / 2, -(t.realHeight - t.realHeight / n) / 2] : [De(l, t.realWidth / n - t.realWidth, 0), De(s, t.realHeight / n - t.realHeight, 0)], zoom: n };
277
+ }, ln = (e) => {
278
+ const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: a }, canvasZoom: n, canvasOffset: o } = e;
279
+ return { x: o[0] * n * a, y: o[1] * n * a, width: t * n, height: i * n };
280
+ }, cn = (e, t) => {
187
281
  const { canvasZoom: i, size: a } = t;
188
282
  if (a !== "fixed" || i >= 1) return;
189
- const s = Wa(t);
190
- e.beginPath(), e.rect(s.x, s.y, s.width, s.height), e.closePath(), e.clip();
191
- }, dt = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, Mt = (e, t) => {
192
- const i = xt(e);
193
- return { ...e, path: i, selection: tt(i, e, t) };
194
- }, cn = Mt, at = (e, t) => {
195
- const i = Ta(e);
196
- return { ...e, path: i, selection: ni(i, e, t) };
197
- }, dn = at, Ra = (e, t) => {
198
- const i = Math.min(...e.points.map((n) => n[0])) - t.selectionPadding, a = Math.max(...e.points.map((n) => n[0])) + t.selectionPadding, s = Math.min(...e.points.map((n) => n[1])) - t.selectionPadding;
199
- return { x: i, width: a - i, y: s, height: Math.max(...e.points.map((n) => n[1])) + t.selectionPadding - s };
200
- }, ki = (e, t, i, a = !1) => {
201
- const s = [$(t[0], i), $(t[1], i)], { center: n } = ee(e, i), o = ke(s, e.rotation, n), r = { ...e, points: a ? e.points : [...e.points, o], tempPoint: a ? o : void 0 };
202
- return at(r, i);
203
- }, nt = (e, t) => {
204
- const i = ((a) => {
205
- const s = a.tempPoint ? [...a.points, a.tempPoint] : a.points;
206
- if (s.length < 2) return;
207
- if (s.length < 3) return Ta(a);
208
- const n = a.style?.closedPoints === 1 && s.length > 2, o = new Path2D();
209
- o.moveTo(...s[0]);
210
- const r = Ha(a, s);
211
- for (let l = 1; l < r.length - 2; l++) {
212
- const d = r[l - 1], h = r[l], c = r[l + 1], u = r[l + 2];
213
- Za(o, d, h, c, u);
283
+ const n = ln(t);
284
+ e.beginPath(), e.rect(n.x, n.y, n.width, n.height), e.closePath(), e.clip();
285
+ }, ft = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, qn = (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) }), dn = (e, t) => Re(e, qn, t), Tt = (e, t) => {
286
+ const i = Lt(e), a = dn(e, t);
287
+ return { ...e, path: i, selection: ut(i, a, t), computed: a };
288
+ }, _n = Tt, hn = (e, t) => Re(e, mi, t), pt = (e, t) => {
289
+ const i = en(e), a = hn(e, t);
290
+ return { ...e, path: i, selection: fi(i, e, a, t), computed: a };
291
+ }, jn = pt, mi = (e, t) => {
292
+ const i = Math.min(...e.points.map((o) => o[0])) - t.selectionPadding, a = Math.max(...e.points.map((o) => o[0])) + t.selectionPadding, n = Math.min(...e.points.map((o) => o[1])) - t.selectionPadding;
293
+ return { x: i, width: a - i, y: n, height: Math.max(...e.points.map((o) => o[1])) + t.selectionPadding - n };
294
+ }, Kn = (e, t, i, a) => {
295
+ if (t < 0 || t > e.points.length - 1) return e;
296
+ const n = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
297
+ return pt({ ...e, points: n }, a);
298
+ }, Xi = (e, t, i, a = !1) => {
299
+ const n = [_(t[0], i), _(t[1], i)], o = Ae(n, e.rotation ?? 0, e.computed.center), r = { ...e, points: a ? e.points : [...e.points, o], tempPoint: a ? o : void 0 };
300
+ return pt(r, i);
301
+ }, Jn = (e, t) => {
302
+ const i = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
303
+ if (i.length < 2) {
304
+ const s = i[0] ?? [0, 0], c = t.selectionPadding;
305
+ return { x: s[0] - c, y: s[1] - c, width: 2 * c, height: 2 * c };
306
+ }
307
+ if (i.length < 3) return mi({ ...e, points: i }, t);
308
+ const a = pi(e, i);
309
+ let n = Number.POSITIVE_INFINITY, o = Number.NEGATIVE_INFINITY, r = Number.POSITIVE_INFINITY, l = Number.NEGATIVE_INFINITY;
310
+ for (let s = 1; s < a.length - 2; s++) {
311
+ const c = a[s - 1], u = a[s], d = a[s + 1], h = a[s + 2], { cp1: f, cp2: g } = gi(c, u, d, h), x = On(u, f, g, d);
312
+ n = Math.min(n, x.minX), o = Math.max(o, x.maxX), r = Math.min(r, x.minY), l = Math.max(l, x.maxY);
313
+ }
314
+ return vi({ x: n, y: r, width: o - n, height: l - r }, t);
315
+ }, un = (e, t) => Re(e, Jn, t), gt = (e, t) => {
316
+ const i = ((n) => {
317
+ const o = n.tempPoint ? [...n.points, n.tempPoint] : n.points;
318
+ if (o.length < 2) return;
319
+ if (o.length < 3) return en(n);
320
+ const r = n.style?.closedPoints === 1 && o.length > 2, l = new Path2D();
321
+ l.moveTo(...o[0]);
322
+ const s = pi(n, o);
323
+ for (let c = 1; c < s.length - 2; c++) {
324
+ const u = s[c - 1], d = s[c], h = s[c + 1], f = s[c + 2], { cp1: g, cp2: x } = gi(u, d, h, f);
325
+ l.bezierCurveTo(g[0], g[1], x[0], x[1], h[0], h[1]);
214
326
  }
215
- return n && o.closePath(), o;
216
- })(e);
217
- return { ...e, path: i, selection: ni(i, e, t) };
218
- }, hn = nt, un = Ra, Pi = (e, t, i, a = !1) => {
219
- const s = [$(t[0], i), $(t[1], i)], { center: n } = ee(e, i), o = ke(s, e.rotation, n), r = { ...e, points: a ? e.points : [...e.points, o], tempPoint: a ? o : void 0 };
220
- return nt(r, i);
221
- }, kt = (e, t) => {
222
- const i = ((a) => {
223
- const s = new Path2D();
224
- return s.ellipse(a.x, a.y, a.radiusX, a.radiusY, 0, 0, 2 * Math.PI), s;
225
- })(e);
226
- return { ...e, path: i, selection: tt(i, e, t) };
227
- }, pn = kt, Li = (e) => {
228
- return i = { ...e, type: "triangle" }, { ...i, path: sn(i) };
229
- var i;
230
- }, gn = (e, t) => {
327
+ return r && l.closePath(), l;
328
+ })(e), a = un(e, t);
329
+ return { ...e, path: i, selection: fi(i, e, a, t), computed: a };
330
+ }, eo = gt, to = (e, t, i, a) => {
331
+ if (t < 0 || t > e.points.length - 1) return e;
332
+ const n = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
333
+ return gt({ ...e, points: n }, a);
334
+ }, Gi = (e, t, i, a = !1) => {
335
+ const n = [_(t[0], i), _(t[1], i)], o = e.computed.center, r = Ae(n, e.rotation ?? 0, o), l = { ...e, points: a ? e.points : [...e.points, r], tempPoint: a ? r : void 0 };
336
+ return gt(l, i);
337
+ }, io = (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) }), pn = (e, t) => Re(e, io, t), zt = (e, t) => {
338
+ const i = ((n) => {
339
+ const o = new Path2D();
340
+ return o.ellipse(n.x, n.y, n.radiusX, n.radiusY, 0, 0, 2 * Math.PI), o;
341
+ })(e), a = pn(e, t);
342
+ return { ...e, path: i, selection: ut(i, a, t), computed: a };
343
+ }, ao = zt, no = (e, t) => Re(e, mi, t), qi = (e, t) => ((i, a) => ({ ...i, path: Fn(i), computed: no(i, a) }))({ ...e, id: ye("triangle_"), type: "triangle" }, t), oo = (e, t) => {
231
344
  e.globalAlpha !== 0 && t.path && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
232
- }, Pt = (e, t) => {
345
+ }, so = (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 }), gn = (e, t) => Re(e, so, t), At = (e, t) => {
233
346
  const i = [];
234
347
  let a;
235
348
  if (e.style?.lineArrow === 1 || e.style?.lineArrow === 2 || e.style?.lineArrow === 3) {
236
- const s = Math.PI / 2 - bi({ targetVector: [e.points[0], e.points[1]] });
237
- e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(Li(Vi(e.points[0], s, e.style))), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(Li(Vi(e.points[1], s + Math.PI, e.style)));
238
- const n = (({ line: o, size: r, direction: l }) => {
239
- const d = Math.PI / 2 - bi({ targetVector: [o.points[0], o.points[1]] }), h = [o.points[0][0] + (o.points[1][0] - o.points[0][0]) / 2, o.points[0][1] + (o.points[1][1] - o.points[0][1]) / 2];
240
- let c, u;
241
- if (["start", "both"].includes(l)) {
242
- const g = we({ point: o.points[0], origin: h, rotation: -d });
243
- c = we({ point: [g[0], g[1] + r], origin: h, rotation: d });
244
- } else c = [...o.points[0]];
245
- if (["end", "both"].includes(l)) {
246
- const g = we({ point: o.points[1], origin: h, rotation: -d });
247
- u = we({ point: [g[0], g[1] - r], origin: h, rotation: d });
248
- } else u = [...o.points[1]];
249
- return { points: [c, u] };
349
+ const o = Math.PI / 2 - Wi({ targetVector: [e.points[0], e.points[1]] });
350
+ e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(qi(_i(e.points[0], o, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(qi(_i(e.points[1], o + Math.PI, e.style), t));
351
+ const r = (({ line: l, size: s, direction: c }) => {
352
+ const u = Math.PI / 2 - Wi({ 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];
353
+ let h, f;
354
+ if (["start", "both"].includes(c)) {
355
+ const g = xe({ point: l.points[0], origin: d, rotation: -u });
356
+ h = xe({ point: [g[0], g[1] + s], origin: d, rotation: u });
357
+ } else h = [...l.points[0]];
358
+ if (["end", "both"].includes(c)) {
359
+ const g = xe({ point: l.points[1], origin: d, rotation: -u });
360
+ f = xe({ point: [g[0], g[1] - s], origin: d, rotation: u });
361
+ } else f = [...l.points[1]];
362
+ return { points: [h, f] };
250
363
  })({ line: e, size: 10 + 2 * (e.style?.lineWidth ?? 0), direction: e.style?.lineArrow === 1 ? "start" : e.style?.lineArrow === 2 ? "end" : "both" });
251
- a = Ct(n);
252
- } else a = Ct(e);
253
- return { ...e, path: a, selection: ni(a, e, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" } };
254
- }, fn = Pt, Vi = (e, t, i) => {
255
- const a = [we({ point: [0, 0], rotation: t }), we({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), we({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
364
+ a = Zt(r);
365
+ } else a = Zt(e);
366
+ const n = gn(e, t);
367
+ return { ...e, path: a, selection: fi(a, e, n, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: n };
368
+ }, ro = At, _i = (e, t, i) => {
369
+ const a = [xe({ point: [0, 0], rotation: t }), xe({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), xe({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
256
370
  return { points: [[e[0] + a[0][0], e[1] + a[0][1]], [e[0] + a[1][0], e[1] + a[1][1]], [e[0] + a[2][0], e[1] + a[2][1]]], style: { ...i, fillColor: i.strokeColor, strokeColor: "transparent" } };
257
- }, Lt = (e, t) => {
258
- const i = ai(e);
259
- return { ...e, path: i, selection: tt(i, e, t) };
260
- }, vn = Lt, mn = (e, t) => {
261
- e.globalAlpha !== 0 && t.path && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
262
- }, Hi = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), Zi = (e, t, i, [a, s] = [!1, !1]) => ((n, o, [r, l]) => we({ origin: [r, l], point: n, rotation: -o }))([e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (a ? 0 : i.width) : i.x + (a ? i.width : 0), e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (s ? 0 : i.height) : i.y + (s ? i.height : 0)], i.rotation, t), Vt = (e, t) => ({ ...e, selection: tt(void 0, e, t) }), yn = Vt, Ot = (e, t, i, a, s) => {
263
- const [n, o] = ((r, l, d, h, c = !1) => {
264
- if (!(r && l && h && d)) return [wt, wt];
265
- const u = r / l;
266
- if (u > d / h) {
267
- const f = c ? d : Math.min(r, d);
268
- return [f, f / u];
371
+ }, vn = (e, t) => Re(e, vi, t), Et = (e, t) => {
372
+ const i = vn(e, t);
373
+ return { ...e, selection: ut(void 0, i, t), computed: i };
374
+ }, lo = Et, qt = (e, t, i, a, n) => {
375
+ const [o, r] = ((l, s, c, u, d = !1) => {
376
+ if (!(l && s && u && c)) return [Di, Di];
377
+ const h = l / s;
378
+ if (h > c / u) {
379
+ const g = d ? c : Math.min(l, c);
380
+ return [g, g / h];
269
381
  }
270
- const g = c ? h : Math.min(l, h);
271
- return [g * u, g];
382
+ const f = d ? u : Math.min(s, u);
383
+ return [f * h, f];
272
384
  })(e.width, e.height, i, a, !0);
273
- return Vt({ toolId: ti.id, type: "picture", id: de("picture_"), x: -s.canvasOffset[0] + s.canvasSize.realWidth / s.canvasZoom / 2 - n / 2, y: -s.canvasOffset[1] + s.canvasSize.realHeight / s.canvasZoom / 2 - o / 2, width: n, height: o, src: t, img: e, rotation: 0 }, s);
274
- }, Qn = (e, t, i, a) => new Promise((s, n) => {
275
- const o = new Image();
276
- o.onerror = () => {
277
- n(new Error("Some images could not be loaded"));
385
+ return Et({ toolId: hi.id, type: "picture", id: ye("picture_"), x: -n.canvasOffset[0] + n.canvasSize.realWidth / n.canvasZoom / 2 - o / 2, y: -n.canvasOffset[1] + n.canvasSize.realHeight / n.canvasZoom / 2 - r / 2, width: o, height: r, src: t, img: e }, n);
386
+ }, co = (e, t, i, a) => new Promise((n, o) => {
387
+ const r = new Image();
388
+ r.onerror = () => {
389
+ o(new Error("Some images could not be loaded"));
278
390
  }, setTimeout(() => {
279
- n(new Error("Timeout while loading images"));
280
- }, 4e3), e instanceof File ? ((r, l, d, h, c, u) => {
281
- Fa(d) ? d.text().then((g) => {
282
- const f = Oa(g);
283
- r.onload = async () => {
284
- URL.revokeObjectURL(r.src);
285
- const w = Ot(r, g, h, c, u);
286
- l(w);
287
- }, r.src = f;
288
- }) : (r.onload = async () => {
289
- URL.revokeObjectURL(r.src);
290
- const g = Ot(r, r.src, h, c, u);
291
- l(g);
292
- }, r.src = URL.createObjectURL(d));
293
- })(o, s, e, t, i, a) : ((r, l, d, h, c, u) => {
294
- r.onload = () => {
295
- URL.revokeObjectURL(r.src);
296
- const g = Ot(r, d, h, c, u);
297
- l(g);
298
- }, $a(d).then((g) => {
299
- r.src = g;
391
+ o(new Error("Timeout while loading images"));
392
+ }, 4e3), e instanceof File ? ((l, s, c, u, d, h) => {
393
+ yn(c) ? c.text().then((f) => {
394
+ const g = mn(f);
395
+ l.onload = async () => {
396
+ URL.revokeObjectURL(l.src);
397
+ const x = qt(l, f, u, d, h);
398
+ s(x);
399
+ }, l.src = g;
400
+ }) : (l.onload = async () => {
401
+ URL.revokeObjectURL(l.src);
402
+ const f = qt(l, l.src, u, d, h);
403
+ s(f);
404
+ }, l.src = URL.createObjectURL(c));
405
+ })(r, n, e, t, i, a) : ((l, s, c, u, d, h) => {
406
+ l.onload = () => {
407
+ URL.revokeObjectURL(l.src);
408
+ const f = qt(l, c, u, d, h);
409
+ s(f);
410
+ }, Sn(c).then((f) => {
411
+ l.src = f;
300
412
  }).catch(() => {
301
- r.src = "";
413
+ l.src = "";
302
414
  });
303
- })(o, s, e, t, i, a);
304
- }), Ft = ["Texte"], Ht = (e, t) => ({ ...e, selection: tt(void 0, e, t) }), Sn = Ht, si = (e, t, i, a, s, n = ut) => {
305
- e.font = `${s ? "italic" : ""} ${a ? "bold" : ""} 1px ${n}`;
306
- const o = t.map((r) => i / e.measureText(r).width);
307
- return Math.min(...o) || 36;
308
- }, bn = (e, t, i, a) => {
309
- const s = { ...t, value: i }, n = ((f, w, x, C, b, k = ut) => {
310
- f.font = `${b ? "italic" : ""} ${C ? "bold" : ""} ${x}px ${k}`;
311
- const v = w.map((Q) => f.measureText(Q).width);
312
- return Math.max(...v) || 20;
313
- })(e, s.value, s.fontSize, s.style?.fontBold ?? !1, s.style?.fontItalic ?? !1, s.style?.fontFamily), o = s.fontSize * s.value.length, r = { ...s, width: n, height: o }, { center: l } = ee(t, a), { center: d } = ee(r, a), [h, c] = Zi([1, 1], l, t), [u, g] = Zi([1, 1], d, r, [!1, !1]);
314
- return { ...r, x: r.x - (u - h), y: r.y - (g - c) };
315
- }, Ti = (e, t, i, a) => {
316
- const s = [$(i[0], a), $(i[1], a)];
415
+ })(r, n, e, t, i, a);
416
+ }), _t = ["Texte"], yi = (e, t) => Re(e, uo, t), It = (e, t) => {
417
+ const i = yi(e, t);
418
+ return { ...e, selection: ut(void 0, i, t), computed: i };
419
+ }, ho = It, Si = (e, t, i, a, n, o = yt) => {
420
+ e.font = `${n ? "italic" : ""} ${a ? "bold" : ""} 1px ${o}`;
421
+ const r = t.map((l) => i / e.measureText(l).width);
422
+ return Math.min(...r) || 36;
423
+ }, uo = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), po = (e, t, i, a) => {
424
+ const n = { ...t, value: i }, o = ((f, g, x, C, k, w = yt) => {
425
+ f.font = `${k ? "italic" : ""} ${C ? "bold" : ""} ${x}px ${w}`;
426
+ const m = g.map((y) => f.measureText(y).width);
427
+ return Math.max(...m) || 20;
428
+ })(e, n.value, n.fontSize, n.style?.fontBold ?? !1, n.style?.fontItalic ?? !1, n.style?.fontFamily), r = n.fontSize * n.value.length, l = { ...n, width: o, height: r }, { center: s } = yi(l, a), [c, u] = Fi([1, 1], t.computed.center, t), [d, h] = Fi([1, 1], s, l, [!1, !1]);
429
+ return { ...l, x: l.x - (d - c), y: l.y - (h - u) };
430
+ }, ji = (e, t, i, a) => {
431
+ const n = [_(i[0], a), _(i[1], a)];
317
432
  switch (t.type) {
318
433
  case "brush":
319
- return ((n, o, r) => it({ toolId: n.id, type: n.type, id: de(`${n.type}_`), points: [[o]], rotation: 0, scaleX: 1, scaleY: 1, style: { opacity: n.settings.opacity.default, strokeColor: n.settings.strokeColor.default, lineWidth: n.settings.lineWidth.default, lineDash: n.settings.lineDash.default } }, r))(t, s, a);
434
+ return ((o, r, l) => ht({ toolId: o.id, type: o.type, id: ye(`${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, n, a);
320
435
  case "line":
321
- return ((n, o, r) => {
322
- const l = { toolId: n.id, type: n.type, id: de(`${n.type}_`), points: [o, o], rotation: 0, style: { opacity: n.settings.opacity.default, strokeColor: n.settings.strokeColor.default, lineWidth: n.settings.lineWidth.default, lineDash: n.settings.lineDash.default, lineArrow: n.settings.lineArrow.default } };
323
- return Pt(l, r);
324
- })(t, s, a);
436
+ return ((o, r, l) => {
437
+ const s = { toolId: o.id, type: o.type, id: ye(`${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 } };
438
+ return At(s, l);
439
+ })(t, n, a);
325
440
  case "polygon":
326
- return ((n, o, r) => at({ toolId: n.id, type: n.type, id: de(`${n.type}_`), points: [o], rotation: 0, style: { opacity: n.settings.opacity.default, fillColor: n.settings.fillColor.default, strokeColor: n.settings.strokeColor.default, lineWidth: n.settings.lineWidth.default, lineDash: n.settings.lineDash.default, closedPoints: n.settings.closedPoints.default } }, r))(t, s, a);
441
+ return ((o, r, l) => pt({ toolId: o.id, type: o.type, id: ye(`${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, n, a);
327
442
  case "curve":
328
- return ((n, o, r) => nt({ toolId: n.id, type: n.type, id: de(`${n.type}_`), points: [o], rotation: 0, style: { opacity: n.settings.opacity.default, fillColor: n.settings.fillColor.default, strokeColor: n.settings.strokeColor.default, lineWidth: n.settings.lineWidth.default, lineDash: n.settings.lineDash.default, closedPoints: n.settings.closedPoints.default } }, r))(t, s, a);
443
+ return ((o, r, l) => gt({ toolId: o.id, type: o.type, id: ye(`${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, n, a);
329
444
  case "rect":
330
445
  case "square":
331
- return ((n, o, r, l = 0, d = 0) => {
332
- const h = { toolId: n.id, type: n.type, id: de(`${n.type}_`), x: o[0], y: o[1], width: l, height: d, rotation: 0, style: { opacity: n.settings.opacity.default, fillColor: n.settings.fillColor.default, strokeColor: n.settings.strokeColor.default, lineWidth: n.settings.lineWidth.default, lineDash: n.settings.lineDash.default } };
333
- return Lt(h, r);
334
- })(t, s, a);
446
+ return an(t, n, a);
335
447
  case "text":
336
- return ((n, o, r, l) => {
337
- const d = si(n, Ft, 150, o.settings?.fontBold.default ?? !1, o.settings?.fontItalic.default ?? !1, o.settings.fontFamily.default), h = d * (Ft.length || 1);
338
- return Ht({ toolId: o.id, type: o.type, id: de(`${o.type}_`), x: r[0] - 150, y: r[1] - h, value: Ft, fontSize: d, width: 150, height: h, rotation: 0, style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, fontFamily: o.settings.fontFamily.default, fontItalic: o.settings.fontItalic.default, fontBold: o.settings.fontBold.default } }, l);
339
- })(e, t, s, a);
448
+ return ((o, r, l, s) => {
449
+ const c = Si(o, _t, 150, r.settings?.fontBold.default ?? !1, r.settings?.fontItalic.default ?? !1, r.settings.fontFamily.default), u = c * (_t.length || 1);
450
+ return It({ toolId: r.id, type: r.type, id: ye(`${r.type}_`), x: l[0] - 150, y: l[1] - u, value: _t, fontSize: c, width: 150, height: u, 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);
451
+ })(e, t, n, a);
340
452
  case "ellipse":
341
- return ((n, o, r) => kt({ toolId: n.id, type: n.type, id: de(`${n.type}_`), x: o[0], y: o[1], radiusX: 0, radiusY: 0, rotation: 0, style: { opacity: n.settings.opacity.default, fillColor: n.settings.fillColor.default, strokeColor: n.settings.strokeColor.default, lineWidth: n.settings.lineWidth.default, lineDash: n.settings.lineDash.default } }, r))(t, s, a);
453
+ return ((o, r, l) => zt({ toolId: o.id, type: o.type, id: ye(`${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, n, a);
342
454
  case "circle":
343
- return ((n, o, r) => Mt({ toolId: n.id, type: n.type, id: de(`${n.type}_`), x: o[0], y: o[1], radius: 0, rotation: 0, style: { opacity: n.settings.opacity.default, fillColor: n.settings.fillColor.default, strokeColor: n.settings.strokeColor.default, lineWidth: n.settings.lineWidth.default, lineDash: n.settings.lineDash.default } }, r))(t, s, a);
455
+ return ((o, r, l) => Tt({ toolId: o.id, type: o.type, id: ye(`${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, n, a);
344
456
  }
345
- }, zi = (e, t) => {
457
+ }, Ki = (e, t) => {
346
458
  switch (t.type) {
347
459
  case "brush":
348
460
  ((i, a) => {
@@ -352,8 +464,8 @@ const Ci = ({ ctx: e, path: t, rect: i, offset: a, checkFill: s }) => {
352
464
  case "text":
353
465
  ((i, a) => {
354
466
  if (i.globalAlpha !== 0 && a.style?.strokeColor && a.style.strokeColor !== "transparent") {
355
- i.font = `${a.style?.fontItalic ? "italic" : ""} ${a.style?.fontBold ? "bold" : ""} ${a.fontSize}px ${a.style?.fontFamily ?? ut}`, i.textBaseline = "top", i.fillStyle = a.style.strokeColor;
356
- for (let s = 0; s < a.value.length; s++) i.fillText(a.value[s], a.x, a.y + s * a.fontSize, a.width);
467
+ i.font = `${a.style?.fontItalic ? "italic" : ""} ${a.style?.fontBold ? "bold" : ""} ${a.fontSize}px ${a.style?.fontFamily ?? yt}`, i.textBaseline = "top", i.fillStyle = a.style.strokeColor;
468
+ for (let n = 0; n < a.value.length; n++) i.fillText(a.value[n], a.x, a.y + n * a.fontSize, a.width);
357
469
  }
358
470
  })(e, t);
359
471
  break;
@@ -361,7 +473,7 @@ const Ci = ({ ctx: e, path: t, rect: i, offset: a, checkFill: s }) => {
361
473
  ((i, a) => {
362
474
  if (i.globalAlpha !== 0 && a.path) {
363
475
  a.style?.fillColor !== "transparent" && i.fill(a.path), a.style?.strokeColor !== "transparent" && i.stroke(a.path);
364
- for (const s of a.arrows ?? []) Ie(i, s.style), gn(i, s);
476
+ for (const n of a.arrows ?? []) Qe(i, n.style), oo(i, n);
365
477
  }
366
478
  })(e, t);
367
479
  break;
@@ -387,192 +499,188 @@ const Ci = ({ ctx: e, path: t, rect: i, offset: a, checkFill: s }) => {
387
499
  break;
388
500
  case "rect":
389
501
  case "square":
390
- mn(e, t);
502
+ Yn(e, t);
391
503
  break;
392
504
  case "picture":
393
505
  ((i, a) => {
394
506
  i.globalAlpha !== 0 && (i.beginPath(), i.drawImage(a.img, a.x, a.y, a.width, a.height));
395
507
  })(e, t);
396
508
  }
397
- }, Ia = (e, t, i) => {
509
+ }, fn = (e, t, i) => {
398
510
  if (t.visible === !1) return;
399
- const { center: a, outerBorders: s } = ee(t, i), n = ((o) => {
400
- const { canvasSize: { width: r, height: l, scaleRatioWithNoZoom: d }, canvasZoom: h, canvasOffset: c } = o;
401
- return { x: -c[0], y: -c[1], width: r / h / d, height: l / h / d };
402
- })(i);
403
- if (qt(s, n)) {
404
- if (ii(e, i, t.rotation, a), Ie(e, t.style), e.globalAlpha !== 1) return ((o, r, l) => {
405
- const d = document.createElement("canvas"), h = d.getContext("2d");
406
- if (!h) throw new Error("No context found for canvas");
407
- const c = { width: 2 * l.width, height: 2 * l.height };
408
- d.width = c.width, d.height = c.height, h.translate(c.width / 4 - l.x, c.height / 4 - l.y), Ie(h, { ...r.style, opacity: 100 }), zi(h, r), o.drawImage(d, l.x - c.width / 4, l.y - c.height / 4);
409
- })(e, t, s), void e.restore();
410
- zi(e, t), e.restore();
411
- }
412
- }, wn = (e, t) => {
413
- switch (e.type) {
414
- case "brush":
415
- return ((i, { selectionPadding: a }) => {
416
- const s = i.points.flat(), n = Math.min(...s.map((h) => h[0])), o = Math.min(...s.map((h) => h[1])), r = s.map((h) => Me(h, n, o, i.scaleX, i.scaleY)), l = Math.max(...r.map((h) => h[0])) + a, d = Math.max(...r.map((h) => h[1])) + a;
417
- return { x: n - a, width: l - n + a, y: o - a, height: d - o + a };
418
- })(e, t);
419
- case "line":
420
- return ((i, a) => ({ x: Math.min(i.points[0][0], i.points[1][0]) - a.selectionPadding, width: Math.abs(i.points[0][0] - i.points[1][0]) + 2 * a.selectionPadding, y: Math.min(i.points[0][1], i.points[1][1]) - a.selectionPadding, height: Math.abs(i.points[0][1] - i.points[1][1]) + 2 * a.selectionPadding }))(e, t);
421
- case "polygon":
422
- return Ra(e, t);
423
- case "curve":
424
- return un(e, t);
425
- case "circle":
426
- return ((i, a) => ({ x: i.x - i.radius - a.selectionPadding, width: 2 * (i.radius + a.selectionPadding), y: i.y - i.radius - a.selectionPadding, height: 2 * (i.radius + a.selectionPadding) }))(e, t);
427
- case "ellipse":
428
- return ((i, a) => ({ x: i.x - i.radiusX - a.selectionPadding, width: 2 * (i.radiusX + a.selectionPadding), y: i.y - i.radiusY - a.selectionPadding, height: 2 * (i.radiusY + a.selectionPadding) }))(e, t);
429
- case "rect":
430
- case "square":
431
- return Hi(e, t);
432
- case "text":
433
- return ((i, a) => ({ x: i.x - a.selectionPadding, width: i.width + 2 * a.selectionPadding, y: i.y - a.selectionPadding, height: i.height + 2 * a.selectionPadding }))(e, t);
434
- case "picture":
435
- return ((i, a) => Hi(i, a))(e, t);
436
- default:
437
- return { x: 0, y: 0, width: 100, height: 100 };
511
+ if (((n, o) => {
512
+ const r = ((l) => {
513
+ const { canvasSize: { width: s, height: c, scaleRatioWithNoZoom: u }, canvasZoom: d, canvasOffset: h } = l;
514
+ return { x: -h[0], y: -h[1], width: s / d / u, height: c / d / u };
515
+ })(o);
516
+ return !!ii(n.computed.boundingBox, r);
517
+ })(t, i)) {
518
+ if (Pt(e, i, t.rotation, t.computed.center), Qe(e, t.style), e.globalAlpha !== 1) return ((n, o) => {
519
+ const r = document.createElement("canvas"), l = r.getContext("2d");
520
+ if (!l) throw new Error("No context found for canvas");
521
+ const { outerBorders: s } = o.computed, c = { width: 2 * s.width, height: 2 * s.height };
522
+ r.width = c.width, r.height = c.height, l.translate(c.width / 4 - s.x, c.height / 4 - s.y), Qe(l, { ...o.style, opacity: 100 }), Ki(l, o), n.drawImage(r, s.x - c.width / 4, s.y - c.height / 4);
523
+ })(e, t), void e.restore();
524
+ Ki(e, t), e.restore();
438
525
  }
439
- }, ee = (e, t) => {
440
- const i = wn(e, t), a = { x: i.x - (e.style?.lineWidth ?? 0), y: i.y - (e.style?.lineWidth ?? 0), width: i.width + 2 * (e.style?.lineWidth ?? 0), height: i.height + 2 * (e.style?.lineWidth ?? 0) }, s = ((n) => [n.x + n.width / 2, n.y + n.height / 2])(i);
441
- return { borders: i, outerBorders: a, center: s };
442
- }, xn = (e, t, i, a, s, n, o) => {
443
- const r = s[0] - a[0], l = s[1] - a[1], d = s[0] - t[0], h = s[1] - t[1], c = i.rotation + Math.atan2(h, d) - Math.atan2(l, r);
444
- return { ...e, rotation: rn(c, n, o) };
445
- }, Cn = (e, t, i, a, s, n, o, r) => {
526
+ }, go = (e, t, i, a, n, o, r) => {
527
+ const l = n[0] - a[0], s = n[1] - a[1], c = n[0] - t[0], u = n[1] - t[1], d = { ...e, rotation: Dn((i.rotation ?? 0) + Math.atan2(u, c) - Math.atan2(s, l), o, r) };
528
+ return { ...d, computed: fo(d, o) };
529
+ }, vo = (e, t, i, a, n, o, r, l) => {
446
530
  switch (a.type) {
447
531
  case "line":
448
- return ((l, d, h, c) => {
449
- const u = [$(l[0], c), $(l[1], c)], { center: g } = ee(d, c), f = ke(u, d.rotation, g), w = Qe(["points", h.anchor], f, d);
450
- return Pt(w, c);
451
- })(i, a, s, n);
532
+ return ((s, c, u, d) => {
533
+ const h = [_(s[0], d), _(s[1], d)], f = Ae(h, c.rotation ?? 0, c.computed.center), g = Pe(["points", u.anchor], f, c);
534
+ return At(g, d);
535
+ })(i, a, n, o);
452
536
  case "polygon":
453
- return ((l, d, h, c) => {
454
- const u = [$(l[0], c), $(l[1], c)], { center: g } = ee(d, c), f = ke(u, d.rotation, g), w = Qe(["points", h.anchor], f, d);
455
- return at(w, c);
456
- })(i, a, s, n);
537
+ return ((s, c, u, d) => {
538
+ const h = [_(s[0], d), _(s[1], d)], f = Ae(h, c.rotation ?? 0, c.computed.center), g = Pe(["points", u.anchor], f, c);
539
+ return pt(g, d);
540
+ })(i, a, n, o);
457
541
  case "curve":
458
- return ((l, d, h, c) => {
459
- const u = [$(l[0], c), $(l[1], c)], { center: g } = ee(d, c), f = ke(u, d.rotation, g), w = Qe(["points", h.anchor], f, d);
460
- return nt(w, c);
461
- })(i, a, s, n);
542
+ return ((s, c, u, d) => {
543
+ const h = [_(s[0], d), _(s[1], d)], f = c.computed.center, g = Ae(h, c.rotation ?? 0, f), x = Pe(["points", u.anchor], g, c);
544
+ return gt(x, d);
545
+ })(i, a, n, o);
462
546
  case "brush":
463
- return ((l, d, h, c, u, g) => {
464
- const { borders: f } = ee({ ...d, scaleX: 1, scaleY: 1 }, c), { borders: w } = ee(d, c), { borderX: x, borderHeight: C, borderY: b, borderWidth: k } = _e(l, d, h, c, u, g), v = Math.max(0, f.width - 2 * c.selectionPadding), Q = Math.max(0, f.height - 2 * c.selectionPadding), V = Math.max(0, k - 2 * c.selectionPadding), T = Math.max(0, C - 2 * c.selectionPadding), D = v ? V / v : 1, H = Q ? T / Q : 1;
465
- if (!v || !Q) return d;
466
- const Z = Oe(x - w.x), F = Oe(b - w.y);
467
- return it({ ...d, points: d.points.map((N) => N.map(([W, Y]) => [W + Z, Y + F])), scaleX: D, scaleY: H }, c);
468
- })(i, a, s, n, o, r);
547
+ return ((s, c, u, d, h, f) => {
548
+ const g = _a({ ...c, scaleX: 1, scaleY: 1 }, d), x = c.computed.borders, { borderX: C, borderHeight: k, borderY: w, borderWidth: m } = nt(s, c, u, d, h, f), y = Math.max(0, g.width - 2 * d.selectionPadding), b = Math.max(0, g.height - 2 * d.selectionPadding), Z = Math.max(0, m - 2 * d.selectionPadding), A = Math.max(0, k - 2 * d.selectionPadding), T = y ? Z / y : 1, S = b ? A / b : 1;
549
+ if (!y || !b) return c;
550
+ const V = Xe(C - x.x), I = Xe(w - x.y);
551
+ return ht({ ...c, points: c.points.map((N) => N.map(([H, D]) => [H + V, D + I])), scaleX: T, scaleY: S }, d);
552
+ })(i, a, n, o, r, l);
469
553
  case "circle":
470
- return ((l, d, h, c, u) => {
471
- const { borderX: g, borderHeight: f, borderY: w, borderWidth: x } = _e(l, d, h, c, !0, u);
472
- return Mt({ ...d, radius: Math.max(0, x / 2 - c.selectionPadding), x: g + x / 2, y: w + f / 2 }, c);
473
- })(i, a, s, n, r);
554
+ return ((s, c, u, d, h) => {
555
+ const { borderX: f, borderHeight: g, borderY: x, borderWidth: C } = nt(s, c, u, d, !0, h);
556
+ return Tt({ ...c, radius: Math.max(0, C / 2 - d.selectionPadding), x: f + C / 2, y: x + g / 2 }, d);
557
+ })(i, a, n, o, l);
474
558
  case "ellipse":
475
- return ((l, d, h, c, u = !1, g = !1) => {
476
- const { borderX: f, borderHeight: w, borderY: x, borderWidth: C } = _e(l, d, h, c, u, g);
477
- return kt({ ...d, radiusX: Math.max(0, C / 2 - c.selectionPadding), radiusY: Math.max(0, w / 2 - c.selectionPadding), x: f + C / 2, y: x + w / 2 }, c);
478
- })(i, a, s, n, o, r);
559
+ return ((s, c, u, d, h = !1, f = !1) => {
560
+ const { borderX: g, borderHeight: x, borderY: C, borderWidth: k } = nt(s, c, u, d, h, f);
561
+ return zt({ ...c, radiusX: Math.max(0, k / 2 - d.selectionPadding), radiusY: Math.max(0, x / 2 - d.selectionPadding), x: g + k / 2, y: C + x / 2 }, d);
562
+ })(i, a, n, o, r, l);
479
563
  case "rect":
480
564
  case "square":
481
- return ((l, d, h, c, u = !1, g = !1) => {
482
- const { borderX: f, borderHeight: w, borderY: x, borderWidth: C } = _e(l, d, h, c, u, g);
483
- return Lt({ ...d, width: Math.max(0, C - 2 * c.selectionPadding), height: Math.max(0, w - 2 * c.selectionPadding), x: f + c.selectionPadding, y: x + c.selectionPadding }, c);
484
- })(i, a, s, n, t.type === "square" || o, r);
565
+ return ((s, c, u, d, h = !1, f = !1) => {
566
+ const { borderX: g, borderHeight: x, borderY: C, borderWidth: k } = nt(s, c, u, d, h, f);
567
+ return Ht({ ...c, width: Math.max(0, k - 2 * d.selectionPadding), height: Math.max(0, x - 2 * d.selectionPadding), x: g + d.selectionPadding, y: C + d.selectionPadding }, d);
568
+ })(i, a, n, o, t.type === "square" || r, l);
485
569
  case "text":
486
- return ((l, d, h, c, u, g) => {
487
- const { borderX: f, borderHeight: w, borderY: x, borderWidth: C } = _e(d, h, c, u, !0, g), b = Ht({ ...h, width: Math.max(0, C - 2 * u.selectionPadding), height: Math.max(0, w - 2 * u.selectionPadding), x: f + u.selectionPadding, y: x + u.selectionPadding }, u);
488
- return { ...b, fontSize: si(l, b.value, b.width, b.style?.fontBold ?? !1, b.style?.fontItalic ?? !1, b.style?.fontFamily) };
489
- })(e, i, a, s, n, r);
570
+ return ((s, c, u, d, h, f) => {
571
+ const { borderX: g, borderHeight: x, borderY: C, borderWidth: k } = nt(c, u, d, h, !0, f), w = It({ ...u, width: Math.max(0, k - 2 * h.selectionPadding), height: Math.max(0, x - 2 * h.selectionPadding), x: g + h.selectionPadding, y: C + h.selectionPadding }, h);
572
+ return { ...w, fontSize: Si(s, w.value, w.width, w.style?.fontBold ?? !1, w.style?.fontItalic ?? !1, w.style?.fontFamily) };
573
+ })(e, i, a, n, o, l);
490
574
  case "picture":
491
- return ((l, d, h, c, u) => {
492
- const { borderX: g, borderHeight: f, borderY: w, borderWidth: x } = _e(l, d, h, c, !0, u);
493
- return Vt({ ...d, width: Math.max(0, x - 2 * c.selectionPadding), height: Math.max(0, f - 2 * c.selectionPadding), x: g + c.selectionPadding, y: w + c.selectionPadding }, c);
494
- })(i, a, s, n, r);
575
+ return ((s, c, u, d, h) => {
576
+ const { borderX: f, borderHeight: g, borderY: x, borderWidth: C } = nt(s, c, u, d, !0, h);
577
+ return Et({ ...c, width: Math.max(0, C - 2 * d.selectionPadding), height: Math.max(0, g - 2 * d.selectionPadding), x: f + d.selectionPadding, y: x + d.selectionPadding }, d);
578
+ })(i, a, n, o, l);
495
579
  default:
496
580
  return a;
497
581
  }
498
- }, _t = (e, t, i, a, s) => {
582
+ }, oi = (e, t, i, a, n) => {
499
583
  switch (t.type) {
500
584
  case "rect":
501
585
  case "square":
502
- return ((n, o, r, l, d) => {
503
- const h = ze([n[0] - r[0], n[1] - r[1]], d);
504
- return Lt({ ...o, x: $(o.x + h[0], l), y: $(o.y + h[1], l) }, l);
505
- })(e, t, i, a, s);
586
+ return ((o, r, l, s, c) => {
587
+ const u = Oe([o[0] - l[0], o[1] - l[1]], c);
588
+ return Ht({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
589
+ })(e, t, i, a, n);
506
590
  case "ellipse":
507
- return ((n, o, r, l, d) => {
508
- const h = ze([n[0] - r[0], n[1] - r[1]], d);
509
- return kt({ ...o, x: $(o.x + h[0], l), y: $(o.y + h[1], l) }, l);
510
- })(e, t, i, a, s);
591
+ return ((o, r, l, s, c) => {
592
+ const u = Oe([o[0] - l[0], o[1] - l[1]], c);
593
+ return zt({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
594
+ })(e, t, i, a, n);
511
595
  case "circle":
512
- return ((n, o, r, l, d) => {
513
- const h = ze([n[0] - r[0], n[1] - r[1]], d);
514
- return Mt({ ...o, x: $(o.x + h[0], l), y: $(o.y + h[1], l) }, l);
515
- })(e, t, i, a, s);
596
+ return ((o, r, l, s, c) => {
597
+ const u = Oe([o[0] - l[0], o[1] - l[1]], c);
598
+ return Tt({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
599
+ })(e, t, i, a, n);
516
600
  case "picture":
517
- return ((n, o, r, l, d) => {
518
- const h = ze([n[0] - r[0], n[1] - r[1]], d);
519
- return Vt({ ...o, x: $(o.x + h[0], l), y: $(o.y + h[1], l) }, l);
520
- })(e, t, i, a, s);
601
+ return ((o, r, l, s, c) => {
602
+ const u = Oe([o[0] - l[0], o[1] - l[1]], c);
603
+ return Et({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
604
+ })(e, t, i, a, n);
521
605
  case "text":
522
- return ((n, o, r, l, d) => {
523
- const h = ze([n[0] - r[0], n[1] - r[1]], d);
524
- return Ht({ ...o, x: $(o.x + h[0], l), y: $(o.y + h[1], l) }, l);
525
- })(e, t, i, a, s);
606
+ return ((o, r, l, s, c) => {
607
+ const u = Oe([o[0] - l[0], o[1] - l[1]], c);
608
+ return It({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
609
+ })(e, t, i, a, n);
526
610
  case "line":
527
- return ((n, o, r, l, d) => {
528
- const h = ze([n[0] - r[0], n[1] - r[1]], d);
529
- return Pt({ ...o, points: o.points.map(([c, u]) => [$(c + h[0], l), $(u + h[1], l)]) }, l);
530
- })(e, t, i, a, s);
611
+ return ((o, r, l, s, c) => {
612
+ const u = Oe([o[0] - l[0], o[1] - l[1]], c);
613
+ return At({ ...r, points: r.points.map(([d, h]) => [_(d + u[0], s), _(h + u[1], s)]) }, s);
614
+ })(e, t, i, a, n);
531
615
  case "polygon":
532
- return ((n, o, r, l, d) => {
533
- const h = ze([n[0] - r[0], n[1] - r[1]], d), { borders: c } = ee(o, l);
534
- return at({ ...o, points: o.points.map(([u, g]) => l.gridGap ? [u + $(c.x + h[0], l) - c.x, g + $(c.y + h[1], l) - c.y] : [$(u + n[0] - r[0], l), $(g + n[1] - r[1], l)]) }, l);
535
- })(e, t, i, a, s);
616
+ return ((o, r, l, s, c) => {
617
+ const u = Oe([o[0] - l[0], o[1] - l[1]], c), d = r.computed.borders;
618
+ return pt({ ...r, points: r.points.map(([h, f]) => s.gridGap ? [h + _(d.x + u[0], s) - d.x, f + _(d.y + u[1], s) - d.y] : [_(h + o[0] - l[0], s), _(f + o[1] - l[1], s)]) }, s);
619
+ })(e, t, i, a, n);
536
620
  case "curve":
537
- return ((n, o, r, l, d) => {
538
- const { borders: h } = ee(o, l), c = ze([n[0] - r[0], n[1] - r[1]], d);
539
- return nt({ ...o, points: o.points.map(([u, g]) => l.gridGap ? [u + $(h.x + c[0], l) - h.x, g + $(h.y + c[1], l) - h.y] : [$(u + c[0], l), $(g + c[1], l)]) }, l);
540
- })(e, t, i, a, s);
621
+ return ((o, r, l, s, c) => {
622
+ const u = r.computed.borders, d = Oe([o[0] - l[0], o[1] - l[1]], c);
623
+ return gt({ ...r, points: r.points.map(([h, f]) => s.gridGap ? [h + _(u.x + d[0], s) - u.x, f + _(u.y + d[1], s) - u.y] : [_(h + d[0], s), _(f + d[1], s)]) }, s);
624
+ })(e, t, i, a, n);
541
625
  case "brush":
542
- return ((n, o, r, l, d) => {
543
- const { borders: h } = ee(o, l), c = ze([n[0] - r[0], n[1] - r[1]], d), u = l.gridGap ? $(h.x + c[0], l) - h.x : c[0], g = l.gridGap ? $(h.y + c[1], l) - h.y : c[1];
544
- return it({ ...o, points: o.points.map((f) => f.map(([w, x]) => [w + u, x + g])) }, l);
545
- })(e, t, i, a, s);
626
+ return ((o, r, l, s, c) => {
627
+ const u = r.computed.borders, d = Oe([o[0] - l[0], o[1] - l[1]], c), h = s.gridGap ? _(u.x + d[0], s) - u.x : d[0], f = s.gridGap ? _(u.y + d[1], s) - u.y : d[1];
628
+ return ht({ ...r, points: r.points.map((g) => g.map(([x, C]) => [x + h, C + f])) }, s);
629
+ })(e, t, i, a, n);
546
630
  default:
547
631
  return t;
548
632
  }
549
- }, et = (e, t) => {
633
+ }, dt = (e, t) => {
550
634
  switch (e.type) {
551
635
  case "rect":
552
636
  case "square":
553
- return vn(e, t);
637
+ return $n(e, t);
554
638
  case "ellipse":
555
- return pn(e, t);
639
+ return ao(e, t);
556
640
  case "circle":
557
- return cn(e, t);
641
+ return _n(e, t);
558
642
  case "picture":
559
- return yn(e, t);
643
+ return lo(e, t);
560
644
  case "text":
561
- return Sn(e, t);
645
+ return ho(e, t);
562
646
  case "line":
563
- return fn(e, t);
647
+ return ro(e, t);
564
648
  case "polygon":
565
- return dn(e, t);
649
+ return jn(e, t);
566
650
  case "curve":
567
- return hn(e, t);
651
+ return eo(e, t);
568
652
  case "brush":
569
- return on(e, t);
653
+ return Nn(e, t);
570
654
  default:
571
655
  return e;
572
656
  }
573
- }, Ai = ({ ctx: e, shape: t, settings: i, selectionWidth: a, selectionColor: s, withAnchors: n = !0 }) => {
574
- const { center: o } = ee(t, i);
575
- switch (ii(e, i, t.rotation, o), t.type) {
657
+ }, fo = (e, t) => {
658
+ switch (e.type) {
659
+ case "rect":
660
+ case "square":
661
+ return tn(e, t);
662
+ case "ellipse":
663
+ return pn(e, t);
664
+ case "circle":
665
+ return dn(e, t);
666
+ case "picture":
667
+ return vn(e, t);
668
+ case "text":
669
+ return yi(e, t);
670
+ case "line":
671
+ return gn(e, t);
672
+ case "polygon":
673
+ return hn(e, t);
674
+ case "curve":
675
+ return un(e, t);
676
+ case "brush":
677
+ return ja(e, t);
678
+ }
679
+ }, Ji = ({ ctx: e, shape: t, settings: i, selectionWidth: a, selectionColor: n, hoverMode: o, withAnchors: r = !0 }) => {
680
+ const { center: l } = t.computed;
681
+ switch (i.debug && ((s, c, u, d) => {
682
+ c.selection && d.debug && (s.save(), s.scale(d.canvasSize.scaleRatio, d.canvasSize.scaleRatio), s.translate(d.canvasOffset[0], d.canvasOffset[1]), Qe(s, { fillColor: "transparent", strokeColor: "green", lineWidth: u / d.canvasSize.scaleRatio }), s.strokeRect(c.computed.boundingBox.x, c.computed.boundingBox.y, c.computed.boundingBox.width, c.computed.boundingBox.height), s.restore());
683
+ })(e, t, a, i), Pt(e, i, t.rotation, l), t.type) {
576
684
  case "rect":
577
685
  case "square":
578
686
  case "circle":
@@ -580,669 +688,707 @@ const Ci = ({ ctx: e, path: t, rect: i, offset: a, checkFill: s }) => {
580
688
  case "picture":
581
689
  case "text":
582
690
  case "brush":
583
- ((r, l, d, h, c, u) => {
584
- if (l.selection && (Ie(r, { fillColor: "transparent", strokeColor: d, lineWidth: h / c.canvasSize.scaleRatio }), l.selection.shapePath ? r.stroke(l.selection.shapePath) : r.stroke(l.selection.border), u && !l.locked)) {
585
- l.selection.shapePath && r.stroke(l.selection.border), r.stroke(l.selection.line), Ie(r, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / c.canvasSize.scaleRatio });
586
- for (const g of l.selection.anchors) r.fill(g), r.stroke(g);
691
+ ((s, c, u, d, h, f) => {
692
+ if (c.selection && (h.debug && (Qe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / h.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), Qe(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), c.selection.shapePath ? s.stroke(c.selection.shapePath) : s.stroke(c.selection.border), f && !c.locked)) {
693
+ c.selection.shapePath && s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), Qe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / h.canvasSize.scaleRatio, shadowColor: u, shadowBlur: 0 });
694
+ for (const g of c.selection.anchors) s.fill(g), s.stroke(g);
587
695
  }
588
- })(e, t, s, a, i, n);
696
+ })(e, t, n, a, i, r);
697
+ break;
698
+ case "group":
699
+ ((s, c, u, d, h, f) => {
700
+ if (c.selection) {
701
+ if (h.debug && (Qe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / h.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), Qe(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), f && !c.locked) {
702
+ s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), Qe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / h.canvasSize.scaleRatio });
703
+ for (const g of c.selection.anchors) s.fill(g), s.stroke(g);
704
+ }
705
+ c.shapes.forEach((g) => {
706
+ s.restore(), Qe(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), Pt(s, h, g.rotation, g.computed.center), g.selection?.shapePath && s.stroke(g.selection.shapePath);
707
+ });
708
+ }
709
+ })(e, t, n, a, i, r);
589
710
  break;
590
711
  case "polygon":
591
712
  case "line":
592
713
  case "curve":
593
- (({ ctx: r, shape: l, withAnchors: d, selectionWidth: h, selectionColor: c, settings: u }) => {
594
- if (l.selection && (Ie(r, { fillColor: "transparent", strokeColor: c, lineWidth: h / u.canvasSize.scaleRatio }), l.selection.shapePath && r.stroke(l.selection.shapePath), d && !l.locked)) {
595
- Ie(r, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / u.canvasSize.scaleRatio });
596
- for (const g of l.selection.anchors) r.fill(g), r.stroke(g);
714
+ (({ ctx: s, shape: c, withAnchors: u, selectionWidth: d, selectionColor: h, hoverMode: f, settings: g }) => {
715
+ if (c.selection && (g.debug && (Qe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / g.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), Qe(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / g.canvasSize.scaleRatio }), c.selection.shapePath && s.stroke(c.selection.shapePath), u && !c.locked)) {
716
+ Qe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / g.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
717
+ for (let x = 0; x < c.selection.anchors.length; x++) {
718
+ const C = c.selection.anchors[x];
719
+ f.mode === "resize" && f.anchor === x ? (s.shadowBlur = 10, s.fill(C), s.shadowBlur = 0) : s.fill(C), s.stroke(C);
720
+ }
597
721
  }
598
- })({ ctx: e, shape: t, withAnchors: n, selectionWidth: a, selectionColor: s, settings: i });
722
+ })({ ctx: e, shape: t, withAnchors: r, selectionWidth: a, selectionColor: n, hoverMode: o, settings: i });
599
723
  }
600
724
  e.restore();
601
- }, Mn = ({ ctx: e, selectionFrame: t, settings: i }) => {
602
- ii(e, i), ((a, s, n) => {
603
- Ie(a, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / n.canvasSize.scaleRatio }), a.fillRect(s[0][0], s[0][1], s[1][0] - s[0][0], s[1][1] - s[0][1]), a.strokeRect(s[0][0], s[0][1], s[1][0] - s[0][0], s[1][1] - s[0][1]);
604
- })(e, t, i), e.restore();
605
- }, oi = (e) => e.filter((t) => t != null), Oa = (e) => {
606
- const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0], i = t.getAttribute("width"), a = t.getAttribute("height");
607
- let s;
608
- if (i || a) s = e;
725
+ }, mo = ({ ctx: e, selectionFrame: t, settings: i }) => {
726
+ Pt(e, i), ((a, n, o) => {
727
+ Qe(a, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / o.canvasSize.scaleRatio }), a.fillRect(n[0][0], n[0][1], n[1][0] - n[0][0], n[1][1] - n[0][1]), a.strokeRect(n[0][0], n[0][1], n[1][0] - n[0][0], n[1][1] - n[0][1]);
728
+ })(e, t.frame, i), e.restore();
729
+ }, Qi = (e) => e.filter((t) => t != null), mn = (e) => {
730
+ const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0];
731
+ if (!t) return "";
732
+ const i = t.getAttribute("width"), a = t.getAttribute("height");
733
+ let n;
734
+ if (i || a) n = e;
609
735
  else {
610
- const o = t.getAttribute("viewBox") ?? "0 0 300 300", [, , r, l] = o.split(" ");
611
- t.setAttribute("width", r ?? wt), t.setAttribute("height", l ?? wt), s = new XMLSerializer().serializeToString(t);
736
+ const r = t.getAttribute("viewBox") ?? "0 0 300 300", [, , l, s] = r.split(" ");
737
+ t.setAttribute("width", l ?? "300"), t.setAttribute("height", s ?? "300"), n = new XMLSerializer().serializeToString(t);
612
738
  }
613
- const n = new Blob([s], { type: "image/svg+xml" });
614
- return URL.createObjectURL(n);
615
- }, Fa = (e) => (e instanceof File ? e.name : e).includes(".svg"), $a = (e) => Fa(e) ? fetch(e).then((t) => t.text()).then((t) => Oa(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), Ei = (e, t) => {
739
+ const o = new Blob([n], { type: "image/svg+xml" });
740
+ return URL.createObjectURL(o);
741
+ }, yn = (e) => (e instanceof File ? e.name : e).includes(".svg"), Sn = (e) => yn(e) ? fetch(e).then((t) => t.text()).then((t) => mn(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), ea = (e, t) => {
616
742
  const i = document.createElement("a");
617
743
  i.href = e, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
618
- }, kn = (e) => e.src.includes("<svg") ? e.src : ((t) => {
744
+ }, yo = (e) => e.src.includes("<svg") ? e.src : ((t) => {
619
745
  const i = document.createElement("canvas");
620
746
  i.width = t.width, i.height = t.height;
621
747
  const a = i.getContext("2d");
622
748
  return a ? (a.drawImage(t, 0, 0), i.toDataURL("image/png")) : "";
623
- })(e.img), $t = ({ shapes: e, settings: t }) => {
749
+ })(e.img), jt = ({ shapes: e, settings: t }) => {
624
750
  const i = document.createElement("canvas"), a = i.getContext("2d");
625
751
  if (!a) throw new Error("No context found for canvas");
626
- const { realHeight: s, realWidth: n } = t.canvasSize;
627
- i.width = n, i.height = s, a.clearRect(0, 0, n, s), Va(a);
628
- for (let o = e.length - 1; o >= 0; o--) Ia(a, e[o], t);
752
+ const { realHeight: n, realWidth: o } = t.canvasSize;
753
+ i.width = o, i.height = n, a.clearRect(0, 0, o, n), qa(a);
754
+ for (let r = e.length - 1; r >= 0; r--) fn(a, e[r], t);
629
755
  return i.toDataURL("image/png");
630
- }, Di = ({ shapes: e, settings: t, view: i }) => {
756
+ }, ta = ({ shapes: e, settings: t, view: i }) => {
631
757
  if (i === "fitToShapes" && !e.length) throw new Error("No image found to export");
632
758
  if (i === "fitToShapes") {
633
- const s = e.map((h) => {
634
- const c = ee(h, t).borders, u = (h.style?.lineWidth ?? 0) / 2;
635
- return { minX: c.x - u, minY: c.y - u, maxX: c.x + c.width + u, maxY: c.y + c.height + u };
636
- }), n = Math.min(...s.map((h) => h.minX)), o = Math.max(...s.map((h) => h.maxX)), r = Math.min(...s.map((h) => h.minY)), l = Math.max(...s.map((h) => h.maxY)), d = { ...t, canvasOffset: [-n, -r], canvasZoom: 1, canvasSize: { realWidth: o - n, realHeight: l - r, width: o - n, height: l - r, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
637
- return $t({ shapes: e, settings: d });
759
+ const n = 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: [-n, -r], canvasZoom: 1, canvasSize: { realWidth: o - n, realHeight: l - r, width: o - n, height: l - r, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
760
+ return jt({ shapes: e, settings: s });
638
761
  }
639
762
  if (i === "defaultView") {
640
- const s = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
641
- return $t({ shapes: e, settings: s });
763
+ const n = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
764
+ return jt({ shapes: e, settings: n });
642
765
  }
643
766
  const a = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
644
- return $t({ shapes: e, settings: a });
645
- }, Pn = (e, t, i) => {
646
- return s = ri(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(s))}`;
647
- var s;
648
- }, Ln = (e) => {
649
- const t = ["img", "id", "selection", "path", "arrows", "tempPoint"];
650
- return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? Ut(t, i) : Ut(t, { ...i, src: kn(i) }));
651
- }, ri = (e, t, i) => ({ shapes: Ln(e), config: { width: t, height: i } }), Wi = (e, t) => et({ ...e, id: de(`${e.type}_`) }, t), Vn = (e, t, i) => {
652
- const a = J([]), s = J({ dataChanged: [] }), [n, o] = O(void 0), [r, l] = O(void 0), [d, h] = O(void 0), [c, u] = O({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), g = c.cursor > 0, f = c.cursor < c.states.length - 1, w = a.current.length > 0, x = R(() => {
653
- u((m) => Pa(m.states[m.cursor].shapes, a.current) ? m : { states: [...m.states.slice(0, m.cursor + 1), { shapes: a.current, selectedShape: r, source: "user" }], cursor: m.cursor + 1 });
654
- }, [r]), C = R((m) => {
655
- a.current = [m, ...a.current];
656
- }, []), b = R((m, y, S, P) => {
657
- if (m.target && "className" in m.target && ![Ca, Ma].includes(m.target.className) || !P) return void h(void 0);
658
- const z = a.current.find((M) => M.id === r?.id ? !!ht(y, r, S, e) : !!Da(y, M, S, e));
659
- h(z);
660
- }, [e, r]), k = R(async (m, y = 300, S = 300) => {
661
- const P = await Qn(m, y, S, e);
662
- return C(P), x(), P;
663
- }, [C, x, e]), v = R((m, y = !1) => {
664
- a.current = a.current.map((S) => S.id === r?.id ? m : S), l((S) => S?.id === m.id ? m : S), y && x();
665
- }, [r, x]), Q = R((m) => {
666
- const y = m.map((S) => Ut(["chosen"], S));
667
- a.current = y, x();
668
- }, [x]), V = R((m) => {
669
- l((y) => y?.id === m.id ? void 0 : y), a.current = a.current.filter((y) => y.id !== m.id), x();
670
- }, [x]), T = R((m) => {
671
- u((y) => {
672
- const S = m(y);
673
- return a.current = y.states[S].shapes, l(y.states[S].selectedShape), Qe("cursor", S, y);
767
+ return jt({ shapes: e, settings: a });
768
+ }, So = (e, t, i) => {
769
+ return n = bi(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(n))}`;
770
+ var n;
771
+ }, Qo = (e) => {
772
+ const t = ["img", "id", "selection", "path", "arrows", "tempPoint", "computed"];
773
+ return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? Jt(t, i) : Jt(t, { ...i, src: yo(i) }));
774
+ }, bi = (e, t, i) => ({ shapes: Qo(e), config: { width: t, height: i } }), ia = (e, t) => dt({ ...e, id: ye(`${e.type}_`) }, t), bo = (e, t, i, a) => {
775
+ const n = te([]), o = te({ dataChanged: [] }), [r, l] = $(void 0), [s, c] = $(void 0), [u, d] = $(void 0), [h, f] = $({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), g = h.cursor > 0, x = h.cursor < h.states.length - 1, C = n.current.length > 0, k = B(() => {
776
+ f((p) => Xa(p.states[p.cursor]?.shapes, n.current) ? p : { states: [...p.states.slice(0, p.cursor + 1), { shapes: n.current, selectedShape: s, source: "user" }], cursor: p.cursor + 1 });
777
+ }, [s]), w = B((p) => {
778
+ n.current = [...p, ...n.current];
779
+ }, []), m = B((p, Q, M, L) => {
780
+ if (p.target && "className" in p.target && ![Ya, Ua].includes(p.target.className) || !L) return void d(void 0);
781
+ const P = n.current.find((E) => !j(s)?.map((W) => W.id).includes(E.id) && !!rn(Q, E, M, e));
782
+ d(P);
783
+ }, [e, s]), y = B(async (p, Q = 300, M = 300) => {
784
+ const L = await co(p, Q, M, e);
785
+ return w([L]), k(), L;
786
+ }, [w, k, e]), b = B((p, Q = !1) => {
787
+ n.current = n.current.map((M) => p.find((L) => L.id === M.id) ?? M), c((M) => M && be(j(M).map((L) => p.find((P) => P.id === L.id) ?? L), e)), Q && k();
788
+ }, [k, e]), Z = B((p) => {
789
+ const Q = p.map((M) => Jt(["chosen"], M));
790
+ n.current = Q, k();
791
+ }, [k]), A = B((p) => {
792
+ const Q = new Set(p.map((M) => M.id));
793
+ c((M) => {
794
+ const L = j(M).map((P) => P.id);
795
+ return L && Q.size && L.find((P) => Q.has(P)) ? void 0 : M;
796
+ }), n.current = n.current.filter((M) => !Q?.has(M.id)), k();
797
+ }, [k]), T = B((p) => {
798
+ f((Q) => {
799
+ const M = p(Q);
800
+ return n.current = Q.states[M]?.shapes ?? [], c(Q.states[M]?.selectedShape), Pe("cursor", M, Q);
674
801
  });
675
- }, []), D = R(() => {
676
- T((m) => Math.max(0, m.cursor - 1));
677
- }, [T]), H = R(() => {
678
- T((m) => Math.min(m.states.length - 1, m.cursor + 1));
679
- }, [T]), Z = R((m, y) => {
680
- l(void 0), a.current = m, u((S) => y.clearHistory ? { states: [{ shapes: m, selectedShape: void 0, source: y.source }], cursor: 0 } : { states: [...S.states.slice(0, S.cursor + 1), { shapes: m, selectedShape: void 0, source: y.source }], cursor: S.cursor + 1 });
681
- }, []), F = R((m, y) => {
682
- const S = a.current, P = S.findIndex((_) => _.id === m), z = S.findIndex((_) => _.id === y);
683
- var M, A, E;
684
- Q((M = S, E = z, (A = P) < 0 || E < 0 || A > M.length - 1 || E > M.length - 1 ? M : A < E ? [...M.slice(0, A), ...M.slice(A + 1, E + 1), M[A], ...M.slice(E + 1, M.length)] : [...M.slice(0, E), M[A], ...M.slice(E, A), ...M.slice(A + 1, M.length)]));
685
- }, [Q]), N = R((m) => {
686
- const y = a.current, S = y.findIndex((z) => z.id === m.id);
687
- if (S < 0) return;
688
- const P = Qe("visible", m.visible === !1, m);
689
- l((z) => z?.id === P.id ? P : z), Q(Qe(S, P, y));
690
- }, [Q]), W = R((m) => {
691
- const y = a.current, S = y.findIndex((z) => z.id === m.id);
692
- if (S < 0) return;
693
- const P = Qe("locked", !m.locked, m);
694
- l((z) => z?.id === P.id ? P : z), Q(Qe(S, P, y));
695
- }, [Q]), Y = R((m, y) => {
696
- s.current.hasOwnProperty(m) && (s.current[m] = [...s.current[m], y]);
697
- }, []), q = R((m, y) => {
698
- if (s.current.hasOwnProperty(m)) if (y) {
699
- const S = s.current[m].indexOf(y);
700
- s.current[m] = [...s.current[m].slice(0, S), ...s.current[m].slice(S + 1)];
701
- } else s.current[m] = [];
802
+ }, []), S = B(() => {
803
+ T((p) => Math.max(0, p.cursor - 1));
804
+ }, [T]), V = B(() => {
805
+ T((p) => Math.min(p.states.length - 1, p.cursor + 1));
806
+ }, [T]), I = B((p, Q) => {
807
+ c(void 0), n.current = p, f((M) => Q.clearHistory ? { states: [{ shapes: p, selectedShape: void 0, source: Q.source }], cursor: 0 } : { states: [...M.states.slice(0, M.cursor + 1), { shapes: p, selectedShape: void 0, source: Q.source }], cursor: M.cursor + 1 });
808
+ }, []), N = B((p, Q) => {
809
+ const M = n.current, L = M.findIndex((z) => z.id === p), P = M.findIndex((z) => z.id === Q);
810
+ var E, W, O;
811
+ Z((E = M, O = P, (W = L) < 0 || O < 0 || W > E.length - 1 || O > E.length - 1 ? E : W < O ? [...E.slice(0, W), ...E.slice(W + 1, O + 1), E[W], ...E.slice(O + 1, E.length)] : [...E.slice(0, O), E[W], ...E.slice(O, W), ...E.slice(W + 1, E.length)]));
812
+ }, [Z]), H = B((p) => {
813
+ const Q = n.current, M = new Set(p.map((P) => P.id)), L = Q.map((P) => M.has(P.id) ? Pe("visible", P.visible === !1, P) : P);
814
+ c($i((P) => Pe("visible", P.visible === !1, P), e)), Z(L);
815
+ }, [Z, e]), D = B((p) => {
816
+ const Q = n.current, M = new Set(p.map((P) => P.id)), L = Q.map((P) => M.has(P.id) ? Pe("locked", !P.locked, P) : P);
817
+ c($i((P) => Pe("locked", !P.locked, P), e)), Z(L);
818
+ }, [Z, e]), U = B((p, Q) => {
819
+ o.current.hasOwnProperty(p) && (o.current[p] = [...o.current[p], Q]);
820
+ }, []), F = B((p, Q) => {
821
+ if (o.current.hasOwnProperty(p)) if (Q) {
822
+ const M = o.current[p].indexOf(Q);
823
+ o.current[p] = [...o.current[p].slice(0, M), ...o.current[p].slice(M + 1)];
824
+ } else o.current[p] = [];
702
825
  }, []);
703
- G(() => {
704
- const m = c.states[c.cursor], y = ri(m.shapes, t, i);
705
- for (const S of s.current.dataChanged) S(y, m.source);
706
- }, [t, i, c]), G(() => {
707
- a.current = a.current.map((m) => et(m, e)), l((m) => m === void 0 ? void 0 : et(m, e));
826
+ J(() => {
827
+ const p = h.states[h.cursor], Q = bi(p.shapes, t, i);
828
+ for (const M of o.current.dataChanged) M(Q, p.source);
829
+ }, [t, i, h]), J(() => {
830
+ n.current = n.current.map((p) => dt(p, e)), c((p) => p === void 0 ? void 0 : be(j(p).map((Q) => dt(Q, e)), e));
708
831
  }, [e]);
709
- const L = R((m, y) => {
710
- o((S) => {
711
- const P = [S?.[0] ?? [y[0], y[1]], [y[0], y[1]]], z = a.current.filter((M) => ((A, E, _, te) => {
712
- const { selectionPadding: j } = te, { center: ne, borders: B } = ee(E, te), se = ke(_[0], E.rotation, ne), U = ke(_[1], E.rotation, ne), ie = Math.round(Math.min(se[0], U[0]) - j / 2), he = Math.round(Math.max(se[0], U[0]) + j), ge = Math.round(Math.min(se[1], U[1]) - j / 2), ae = { x: ie, y: ge, width: he - ie, height: Math.round(Math.max(se[1], U[1]) + j) - ge }, Se = qt(B, ae);
713
- if (!Se) return !1;
714
- if (B.width <= 1 || B.height <= 1 || !("path" in E) || !E.path) return !0;
715
- if (A.lineWidth = (E.style?.lineWidth ?? 0) + 10, E.type === "brush") {
716
- const De = E.points.flat(), ue = Math.min(...De.map((fe) => fe[0])), We = Math.min(...De.map((fe) => fe[1]));
717
- for (const fe of E.points) {
718
- if (fe.length < 1) break;
719
- if (fe.length < 2) {
720
- const re = Me(fe[0], ue, We, E.scaleX, E.scaleY);
721
- if (za(Se, { x: re[0], y: re[1], radius: (E.style?.lineWidth ?? 1) / 2 })) return !0;
832
+ const X = B((p, Q) => {
833
+ l((M) => {
834
+ const L = [M?.frame[0] ?? [Q[0], Q[1]], [Q[0], Q[1]]], P = n.current.filter((W) => ((O, z, ie, re) => {
835
+ const { selectionPadding: R } = re, { center: oe, borders: G } = z.computed, le = Ae(ie[0], z.rotation ?? 0, oe), ae = Ae(ie[1], z.rotation ?? 0, oe), pe = Math.round(Math.min(le[0], ae[0]) - R / 2), se = Math.round(Math.max(le[0], ae[0]) + R), ge = Math.round(Math.min(le[1], ae[1]) - R / 2), q = { x: pe, y: ge, width: se - pe, height: Math.round(Math.max(le[1], ae[1]) + R) - ge }, he = ii(G, q);
836
+ if (!he) return !1;
837
+ if (G.width <= 1 || G.height <= 1 || !("path" in z) || !z.path) return !0;
838
+ if (O.lineWidth = (z.style?.lineWidth ?? 0) + 10, z.type === "brush") {
839
+ const Ee = z.points.flat(), Ie = Math.min(...Ee.map((ve) => ve[0])), He = Math.min(...Ee.map((ve) => ve[1]));
840
+ for (const ve of z.points) {
841
+ if (ve.length < 1) break;
842
+ if (ve.length < 2) {
843
+ const ne = ze(ve[0], Ie, He, z.scaleX, z.scaleY);
844
+ if (Ka(he, { x: ne[0], y: ne[1], radius: (z.style?.lineWidth ?? 1) / 2 })) return !0;
722
845
  }
723
- for (let re = 0; re < fe.length - 1; re++) {
724
- const Ze = Me(fe[re], ue, We, E.scaleX, E.scaleY), Pe = Me(fe[re + 1], ue, We, E.scaleX, E.scaleY), Ge = qt({ x: Math.min(Ze[0], Pe[0]), y: Math.min(Ze[1], Pe[1]), width: Math.abs(Ze[0] - Pe[0]), height: Math.abs(Ze[1] - Pe[1]) }, ae);
725
- if (Ge) {
726
- const Ne = new Path2D();
727
- if (Ne.moveTo(...Ze), Ne.lineTo(...Pe), Ci({ ctx: A, path: Ne, rect: Ge, offset: 10, checkFill: !1 })) return !0;
846
+ for (let ne = 0; ne < ve.length - 1; ne++) {
847
+ const Te = ze(ve[ne], Ie, He, z.scaleX, z.scaleY), We = ze(ve[ne + 1], Ie, He, z.scaleX, z.scaleY), Ce = ii({ x: Math.min(Te[0], We[0]), y: Math.min(Te[1], We[1]), width: Math.abs(Te[0] - We[0]), height: Math.abs(Te[1] - We[1]) }, q);
848
+ if (Ce) {
849
+ const qe = new Path2D();
850
+ if (qe.moveTo(...Te), qe.lineTo(...We), Ui({ ctx: O, path: qe, rect: Ce, offset: 10, checkFill: !1 })) return !0;
728
851
  }
729
852
  }
730
853
  }
731
854
  return !1;
732
855
  }
733
- const Ee = !(!E.style?.fillColor || E.style?.fillColor === "transparent");
734
- return Ci({ ctx: A, path: E.path, rect: Se, offset: 10, checkFill: Ee });
735
- })(m, M, P, e));
736
- return l(z?.[0]), P;
856
+ const ce = !(!z.style?.fillColor || z.style?.fillColor === "transparent");
857
+ return Ui({ ctx: O, path: z.path, rect: he, offset: 10, checkFill: ce });
858
+ })(p, W, L, e)), E = be(P, e);
859
+ return c(a ? be(nn(M?.oldSelection, P), e) : E), { oldSelection: M?.oldSelection, frame: L };
737
860
  });
738
- }, [e]);
739
- return { registerEvent: Y, unregisterEvent: q, shapesRef: a, selectedShape: r, hoveredShape: d, selectionFrame: n, setSelectionFrame: o, refreshSelectedShapes: L, addShape: C, addPictureShape: k, moveShapes: F, saveShapes: x, setSelectedShape: l, refreshHoveredShape: b, toggleShapeVisibility: N, toggleShapeLock: W, removeShape: V, updateShape: v, backwardShape: D, forwardShape: H, clearShapes: Z, canGoBackward: g, canGoForward: f, canClear: w };
740
- }, Ni = (e) => {
861
+ }, [e, a]);
862
+ return { registerEvent: U, unregisterEvent: F, shapesRef: n, selectedShape: s, hoveredShape: u, selectionFrame: r, setSelectionFrame: l, refreshSelectedShapes: X, addShapes: w, addPictureShape: y, moveShapes: N, saveShapes: k, setSelectedShape: c, refreshHoveredShape: m, toggleShapeVisibility: H, toggleShapeLock: D, removeShape: A, updateShape: b, backwardShape: S, forwardShape: V, clearShapes: I, canGoBackward: g, canGoForward: x, canClear: C };
863
+ }, aa = (e) => {
741
864
  const t = [e[0].clientX, e[0].clientY], i = [e[1].clientX, e[1].clientY];
742
- var a, s;
743
- return { diff: Aa(t, i), center: (s = i, [((a = t)[0] + s[0]) / 2, (a[1] + s[1]) / 2]) };
744
- }, Hn = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: a, setCanvasTransformation: s }) => {
745
- const n = J([]), [o, r] = O(n.current.length > 0), l = J(null), d = J(t);
746
- d.current = t;
747
- const h = R(({ startDiff: c, startZoom: u, startCenter: g, startOffset: f, currentDiff: w, currentCenter: x, isMoving: C, isZooming: b }) => {
748
- if (!e || !w || !c) return;
749
- const k = (({ canvasBoundingRect: v, canvasSize: Q, size: V, startDiff: T, startZoom: D, startCenter: H, startOffset: Z, currentDiff: F, currentCenter: N, isMoving: W, isZooming: Y }) => {
750
- const q = Y ? Fe(F / T * D, me[0], me[me.length - 1]) : D, L = W ? [Z[0] + (N[0] - H[0]) * (Q.width / v.width) / Q.scaleRatio / D, Z[1] + (N[1] - H[1]) * (Q.height / v.height) / Q.scaleRatio / D] : [Z[0], Z[1]], m = [(N[0] - v.left) / Q.scaleRatio, (N[1] - v.top) / Q.scaleRatio];
751
- return Gt({ size: V, canvasSize: Q, currentOffset: L, currentZoom: D, zoom: q, centerPoint: m });
752
- })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: a, startDiff: c, startZoom: u, startCenter: g, startOffset: f, currentDiff: w, currentCenter: x, isMoving: C, isZooming: b });
753
- s(k);
754
- }, [e, i, a, s]);
755
- G(() => {
865
+ var a, n;
866
+ return { diff: Ja(t, i), center: (n = i, [((a = t)[0] + n[0]) / 2, (a[1] + n[1]) / 2]) };
867
+ }, xo = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: a, setCanvasTransformation: n }) => {
868
+ const o = te([]), [r, l] = $(o.current.length > 0), s = te(null), c = te(t);
869
+ c.current = t;
870
+ const u = B(({ startDiff: d, startZoom: h, startCenter: f, startOffset: g, currentDiff: x, currentCenter: C, isMoving: k, isZooming: w }) => {
871
+ if (!e || !x || !d) return;
872
+ const m = (({ canvasBoundingRect: y, canvasSize: b, size: Z, startDiff: A, startZoom: T, startCenter: S, startOffset: V, currentDiff: I, currentCenter: N, isMoving: H, isZooming: D }) => {
873
+ const U = D ? De(I / A * T, Me[0], Me[Me.length - 1]) : T, F = H ? [V[0] + (N[0] - S[0]) * (b.width / y.width) / b.scaleRatio / T, V[1] + (N[1] - S[1]) * (b.height / y.height) / b.scaleRatio / T] : [V[0], V[1]], X = [(N[0] - y.left) / b.scaleRatio, (N[1] - y.top) / b.scaleRatio];
874
+ return ni({ size: Z, canvasSize: b, currentOffset: F, currentZoom: T, zoom: U, centerPoint: X });
875
+ })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: a, startDiff: d, startZoom: h, startCenter: f, startOffset: g, currentDiff: x, currentCenter: C, isMoving: k, isZooming: w });
876
+ n(m);
877
+ }, [e, i, a, n]);
878
+ J(() => {
756
879
  if (!e) return;
757
- const c = (u) => {
758
- if (n.current = [...n.current, u], r(n.current.length > 0), n.current.length === 2) {
759
- u.stopPropagation();
760
- const { diff: g, center: f } = Ni(n.current);
761
- l.current = { startDiff: g, startCenter: f, startZoom: d.current.zoom, startOffset: d.current.offset, isMoving: !1, isZooming: !1 };
880
+ const d = (h) => {
881
+ if (o.current = [...o.current, h], l(o.current.length > 0), o.current.length === 2) {
882
+ h.stopPropagation();
883
+ const { diff: f, center: g } = aa(o.current);
884
+ s.current = { startDiff: f, startCenter: g, startZoom: c.current.zoom, startOffset: c.current.offset, isMoving: !1, isZooming: !1 };
762
885
  }
763
886
  };
764
- return e.addEventListener("pointerdown", c), () => {
765
- e.removeEventListener("pointerdown", c);
887
+ return e.addEventListener("pointerdown", d), () => {
888
+ e.removeEventListener("pointerdown", d);
766
889
  };
767
- }, [e]), G(() => {
768
- if (!o) return;
769
- const c = (g) => {
770
- const f = n.current.findIndex((w) => w.pointerId === g.pointerId);
771
- if (f > -1 && (n.current[f] = g), n.current.length === 2 && l.current) {
772
- const { diff: w, center: x } = Ni(n.current), C = l.current.isZooming || ((k, v) => Math.abs(k - v.startDiff) > 30)(w, l.current), b = l.current.isMoving || C || ((k, v) => Math.abs(Aa(k, v.startCenter)) > 10)(x, l.current);
773
- l.current = { ...l.current, isMoving: b, isZooming: C }, h({ ...l.current, currentDiff: w, currentCenter: x });
890
+ }, [e]), J(() => {
891
+ if (!r) return;
892
+ const d = (f) => {
893
+ const g = o.current.findIndex((x) => x.pointerId === f.pointerId);
894
+ if (g > -1 && (o.current[g] = f), o.current.length === 2 && s.current) {
895
+ const { diff: x, center: C } = aa(o.current), k = s.current.isZooming || ((m, y) => Math.abs(m - y.startDiff) > 30)(x, s.current), w = s.current.isMoving || k || ((m, y) => Math.abs(Ja(m, y.startCenter)) > 10)(C, s.current);
896
+ s.current = { ...s.current, isMoving: w, isZooming: k }, u({ ...s.current, currentDiff: x, currentCenter: C });
774
897
  }
775
- }, u = (g) => {
776
- n.current = n.current.filter((f) => f.pointerId !== g.pointerId), r(n.current.length > 0);
898
+ }, h = (f) => {
899
+ o.current = o.current.filter((g) => g.pointerId !== f.pointerId), l(o.current.length > 0);
777
900
  };
778
- return document.addEventListener("pointermove", c), document.addEventListener("pointerup", u), document.addEventListener("pointerout", u), document.addEventListener("pointercancel", u), document.addEventListener("pointerleave", u), () => {
779
- document.removeEventListener("pointermove", c), document.removeEventListener("pointerup", u), document.removeEventListener("pointerout", u), document.removeEventListener("pointercancel", u), document.removeEventListener("pointerleave", u);
901
+ return document.addEventListener("pointermove", d), document.addEventListener("pointerup", h), document.addEventListener("pointerout", h), document.addEventListener("pointercancel", h), document.addEventListener("pointerleave", h), () => {
902
+ document.removeEventListener("pointermove", d), document.removeEventListener("pointerup", h), document.removeEventListener("pointerout", h), document.removeEventListener("pointercancel", h), document.removeEventListener("pointerleave", h);
780
903
  };
781
- }, [o, h]);
782
- }, Zn = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: a }) => {
783
- const [s, n] = O({ offset: [0, 0], zoom: 1 }), o = J(0), r = R((d) => {
784
- n(({ zoom: h }) => Mi({ zoom: h, size: t, canvasSize: e, newOffset: d }));
785
- }, [e, t]), l = R((d) => {
786
- n(({ offset: h, zoom: c }) => (({ size: u, canvasSize: g, currentOffset: f, currentZoom: w, action: x }) => {
787
- const C = x === "default" ? me[4] : x === "zoom" ? me[Fe(me.length - 1 - me.slice(0).reverse().findIndex((k) => k <= w) + 1, 0, me.length - 1)] : me[Fe(me.findIndex((k) => k >= w) - 1, 0, me.length - 1)], b = [g.realWidth / 2, g.realHeight / 2];
788
- return Gt({ size: u, canvasSize: g, currentOffset: f, currentZoom: w, zoom: C, centerPoint: b });
789
- })({ size: t, canvasSize: e, currentOffset: h, currentZoom: c, action: d }));
904
+ }, [r, u]);
905
+ }, na = { offset: [0, 0], zoom: 1 }, wo = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: a }) => {
906
+ const [n, o] = $(na), r = te(0), l = B((u) => {
907
+ o(({ zoom: d }) => ai({ zoom: d, size: t, canvasSize: e, newOffset: u }));
908
+ }, [e, t]), s = B((u) => {
909
+ o(({ offset: d, zoom: h }) => (({ size: f, canvasSize: g, currentOffset: x, currentZoom: C, action: k }) => {
910
+ const w = k === "default" ? Me[4] : k === "zoom" ? Me[De(Me.length - 1 - Me.slice(0).reverse().findIndex((y) => y <= C) + 1, 0, Me.length - 1)] : Me[De(Me.findIndex((y) => y >= C) - 1, 0, Me.length - 1)], m = [g.realWidth / 2, g.realHeight / 2];
911
+ return ni({ size: f, canvasSize: g, currentOffset: x, currentZoom: C, zoom: w, centerPoint: m });
912
+ })({ size: t, canvasSize: e, currentOffset: d, currentZoom: h, action: u }));
790
913
  }, [e, t]);
791
- return Hn({ canvasElt: a, canvasTransformation: s, canvasSize: e, size: t, setCanvasTransformation: n }), G(() => {
914
+ xo({ canvasElt: a, canvasTransformation: n, canvasSize: e, size: t, setCanvasTransformation: o });
915
+ const c = B(() => {
916
+ o(na);
917
+ }, []);
918
+ return J(() => {
792
919
  if (!i || !a) return;
793
- const d = (h) => {
794
- const c = h.ctrlKey, { deltaX: u, deltaY: g } = ((C, b) => {
795
- const k = Math.abs(C.deltaY) < 50 && b < 50, v = C.ctrlKey, Q = La() && k && v;
796
- switch (C.deltaMode) {
920
+ const u = (d) => {
921
+ const h = d.ctrlKey, { deltaX: f, deltaY: g } = ((w, m) => {
922
+ const y = Math.abs(w.deltaY) < 50 && m < 50, b = w.ctrlKey, Z = Ga() && y && b;
923
+ switch (w.deltaMode) {
797
924
  case WheelEvent.DOM_DELTA_LINE:
798
- return { deltaX: 16 * C.deltaX, deltaY: 16 * C.deltaY };
925
+ return { deltaX: 16 * w.deltaX, deltaY: 16 * w.deltaY };
799
926
  case WheelEvent.DOM_DELTA_PAGE:
800
- return { deltaX: C.deltaX * window.innerHeight, deltaY: C.deltaY * window.innerHeight };
927
+ return { deltaX: w.deltaX * window.innerHeight, deltaY: w.deltaY * window.innerHeight };
801
928
  default:
802
- return Q ? { deltaX: 5 * C.deltaX, deltaY: 5 * C.deltaY } : { deltaX: C.deltaX, deltaY: C.deltaY };
929
+ return Z ? { deltaX: 5 * w.deltaX, deltaY: 5 * w.deltaY } : { deltaX: w.deltaX, deltaY: w.deltaY };
803
930
  }
804
- })(h, h.timeStamp - o.current);
805
- if (o.current = h.timeStamp, c) {
806
- h.preventDefault();
807
- const C = ((b, k, v) => {
808
- const { clientX: Q, clientY: V } = Ea(b), T = k.getBoundingClientRect();
809
- return [(Q - T.left) / v.scaleRatio, (V - T.top) / v.scaleRatio];
810
- })(h, a, e);
811
- return void n(({ offset: b, zoom: k }) => (({ size: v, canvasSize: Q, currentOffset: V, currentZoom: T, delta: D, centerPoint: H }) => {
812
- const Z = Fe(T * (1 - D / 1e3), me[0], me[me.length - 1]);
813
- return Gt({ size: v, canvasSize: Q, currentOffset: V, currentZoom: T, zoom: Z, centerPoint: H });
814
- })({ size: t, canvasSize: e, currentOffset: b, currentZoom: k, delta: g, centerPoint: C }));
931
+ })(d, d.timeStamp - r.current);
932
+ if (r.current = d.timeStamp, h) {
933
+ d.preventDefault();
934
+ const w = sn(d, a, e);
935
+ return void o(({ offset: m, zoom: y }) => (({ size: b, canvasSize: Z, currentOffset: A, currentZoom: T, delta: S, centerPoint: V }) => {
936
+ const I = De(T * (1 - S / 1e3), Me[0], Me[Me.length - 1]);
937
+ return ni({ size: b, canvasSize: Z, currentOffset: A, currentZoom: T, zoom: I, centerPoint: V });
938
+ })({ size: t, canvasSize: e, currentOffset: m, currentZoom: y, delta: g, centerPoint: w }));
815
939
  }
816
- const f = h.shiftKey, [w, x] = f ? [g, u] : [u, g];
817
- n(({ offset: C, zoom: b }) => {
818
- const k = [C[0] - w / b, C[1] - x / b], v = Mi({ zoom: b, size: t, canvasSize: e, newOffset: k });
819
- return v.offset[0] === C[0] && v.offset[1] === C[1] || h.preventDefault(), v;
940
+ const x = d.shiftKey, [C, k] = x ? [g, f] : [f, g];
941
+ o(({ offset: w, zoom: m }) => {
942
+ const y = [w[0] - C / m, w[1] - k / m], b = ai({ zoom: m, size: t, canvasSize: e, newOffset: y });
943
+ return b.offset[0] === w[0] && b.offset[1] === w[1] || d.preventDefault(), b;
820
944
  });
821
945
  };
822
- return a.addEventListener("wheel", d, { passive: !1 }), () => {
823
- a.removeEventListener("wheel", d);
946
+ return a.addEventListener("wheel", u, { passive: !1 }), () => {
947
+ a.removeEventListener("wheel", u);
824
948
  };
825
- }, [a, t, e, i]), { setCanvasTransformation: n, setCanvasOffset: r, setCanvasZoom: l, canvasTransformation: s };
826
- }, Ri = (e, t = !1) => {
827
- const i = (s, n) => {
828
- if (Array.isArray(s)) return n;
829
- }, a = e.map((s) => {
830
- if (typeof s != "object") return null;
831
- switch (s.type) {
949
+ }, [a, t, e, i]), { setCanvasTransformation: o, setCanvasOffset: l, setCanvasZoom: s, resetZoom: c, canvasTransformation: n };
950
+ }, oa = (e, t = !1) => {
951
+ const i = (n, o) => {
952
+ if (Array.isArray(n)) return o;
953
+ }, a = e.map((n) => {
954
+ if (typeof n != "object") return null;
955
+ switch (n.type) {
832
956
  case "brush":
833
- return He(i, ha, s);
957
+ return Ne(i, Ta, n);
834
958
  case "circle":
835
- return He(i, ma, s);
959
+ return Ne(i, Da, n);
836
960
  case "curve":
837
- return He(i, ga, s);
961
+ return Ne(i, Ea, n);
838
962
  case "ellipse":
839
- return He(i, ya, s);
963
+ return Ne(i, Ra, n);
840
964
  case "line":
841
- return He(i, ua, s);
965
+ return Ne(i, za, n);
842
966
  case "polygon":
843
- return He(i, pa, s);
967
+ return Ne(i, Aa, n);
844
968
  case "rect":
845
- return He(i, fa, s);
969
+ return Ne(i, Ia, n);
846
970
  case "square":
847
- return He(i, va, s);
971
+ return Ne(i, Na, n);
848
972
  case "text":
849
- return He(i, Qa, s);
973
+ return Ne(i, Wa, n);
850
974
  }
851
975
  return null;
852
976
  });
853
- return oi(t ? [...a, ti] : a);
854
- }, ys = ({ width: e = 1e3, height: t = 600, shapes: i, mode: a = "editor", disabled: s = !1, options: n = Qi } = {}) => {
855
- const { layersManipulation: o, brushAlgo: r, isBrushShapeDoneOnMouseUp: l, grid: d, canGrow: h, canShrink: c, withExport: u, withLoadAndSave: g, withUploadPicture: f, withUrlPicture: w, withSkeleton: x, withFrameSelection: C, clearCallback: b, availableTools: k, canvasSelectionPadding: v, size: Q, canZoom: V } = { ...Qi, ...n }, T = a !== "viewer", D = J(null), H = J(null), Z = J(!1), F = R((K) => {
856
- D.current = K;
857
- }, []), [N, W] = O(void 0), [Y, q] = O(Ae), [L, m] = O({ mode: "default" }), [y, S] = O(d), [P, z] = O({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), M = V === "always" && !s, { canvasTransformation: A, setCanvasTransformation: E, setCanvasOffset: _, setCanvasZoom: te } = Zn({ canvasSize: P, size: Q, canvasElt: H.current, zoomEnabled: M }), { offset: j, zoom: ne } = A, B = ia(() => ({ brushAlgo: r, isBrushShapeDoneOnMouseUp: l, canvasSize: { realWidth: P.realWidth, realHeight: P.realHeight, width: P.width, height: P.height, scaleRatioWithNoZoom: P.scaleRatio, scaleRatio: P.scaleRatio * ne }, size: Q, canvasOffset: j, canvasZoom: ne, gridGap: y, selectionPadding: v, features: { edition: T && !s, zoom: M } }), [v, y, r, l, ne, j, P, Q, s, M, T]), [se, U] = O(Ri(k, f || w)), { isInsideComponent: ie } = (({ settings: K, componentRef: ve }) => {
858
- const [st, Ue] = O(!1), Xe = !K.features.edition && !K.features.zoom;
859
- return G(() => {
860
- if (!Xe) {
861
- const Le = (ot) => {
862
- Ue(ka(ot, ve.current));
863
- };
864
- return document.addEventListener("mousedown", Le, { passive: !0 }), document.addEventListener("touchstart", Le, { passive: !0 }), () => {
865
- document.removeEventListener("mousedown", Le), document.removeEventListener("touchstart", Le);
977
+ return Qi(t ? [...a, hi] : a);
978
+ }, ps = ({ width: e = 1e3, height: t = 600, shapes: i, mode: a = "editor", disabled: n = !1, options: o = Ni } = {}) => {
979
+ const { layersManipulation: r, brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, grid: u, canGrow: d, canShrink: h, withExport: f, withLoadAndSave: g, withUploadPicture: x, withUrlPicture: C, withSkeleton: k, withFrameSelection: w, clearCallback: m, availableTools: y, canvasSelectionPadding: b, size: Z, canZoom: A } = { ...Ni, ...o }, T = a !== "viewer", S = te(null), V = te(null), I = te(!1), N = B((ee) => {
980
+ S.current = ee;
981
+ }, []), [H, D] = $(void 0), [U, F] = $(Fe), [X, p] = $({ mode: "default" }), [Q, M] = $(u), [L, P] = $({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), E = A === "always" && !n, { canvasTransformation: W, setCanvasTransformation: O, setCanvasOffset: z, setCanvasZoom: ie, resetZoom: re } = wo({ canvasSize: L, size: Z, canvasElt: V.current, zoomEnabled: E }), { offset: R, zoom: oe } = W, G = ba(() => ({ brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, canvasSize: { realWidth: L.realWidth, realHeight: L.realHeight, width: L.width, height: L.height, scaleRatioWithNoZoom: L.scaleRatio, scaleRatio: L.scaleRatio * oe }, size: Z, canvasOffset: R, canvasZoom: oe, gridGap: Q, selectionPadding: b, features: { edition: T && !n, zoom: E } }), [b, Q, l, s, c, oe, R, L, Z, n, E, T]), [le, ae] = $(oa(y, x || C)), { isInsideComponent: pe, isInsideCanvas: se } = (({ settings: ee, componentRef: de, canvasRef: Le }) => {
982
+ const [$e, Ye] = $(!1), [Ke, Je] = $(!1), Se = !ee.features.edition && !ee.features.zoom;
983
+ return J(() => {
984
+ if (!Se) {
985
+ const Ze = () => Ye(!0), Qt = () => Ye(!1), Ue = () => Je(!0), bt = () => Je(!1);
986
+ return de.current?.addEventListener("focusin", Ze), de.current?.addEventListener("focusout", Qt), Le.current?.addEventListener("focusin", Ue), Le.current?.addEventListener("focusout", bt), () => {
987
+ de.current?.removeEventListener("focusin", Ze), de.current?.removeEventListener("focusout", Qt), Le.current?.removeEventListener("focusin", Ue), Le.current?.removeEventListener("focusout", bt);
866
988
  };
867
989
  }
868
- Ue(!1);
869
- }, [Xe, ve]), { isInsideComponent: st };
870
- })({ settings: B, componentRef: D }), { registerEvent: he, unregisterEvent: ge, shapesRef: ae, selectedShape: Se, selectionFrame: Ee, hoveredShape: De, addShape: ue, addPictureShape: We, moveShapes: fe, setSelectedShape: re, setSelectionFrame: Ze, refreshSelectedShapes: Pe, refreshHoveredShape: Ge, removeShape: Ne, updateShape: xe, backwardShape: pt, forwardShape: gt, clearShapes: ft, saveShapes: zt, toggleShapeVisibility: At, toggleShapeLock: Et, canGoBackward: le, canGoForward: ce, canClear: vt } = Vn(B, e, t), Te = R((K) => {
871
- re(void 0), q(K);
872
- }, [re]);
873
- G(() => {
874
- if (L.mode === "preview") return () => m((K) => K.mode === "preview" ? { mode: "default" } : K);
875
- }, [Se?.id, L.mode === "preview"]);
876
- const Re = R((K, ve) => {
877
- ft(K, ve), Te(Ae), E({ offset: [0, 0], zoom: 1 });
878
- }, [Te, ft, E]), li = R((K) => {
879
- re((ve) => (ve?.id !== K.id && q(Ae), K));
880
- }, [re]), Ua = R(() => {
881
- const K = Pn(ae.current, e, t);
882
- if (!K) throw new Error("L'encodage a échoué");
883
- Ei(K, "drawing.json");
884
- }, [ae, e, t]), Xa = R((K) => {
885
- const ve = Di({ shapes: ae.current, settings: B, view: K });
886
- Ei(ve, "drawing.png");
887
- }, [ae, B]), Ya = R((K) => Di({ shapes: ae.current, settings: B, view: K }), [ae, B]), qa = R(() => ri(ae.current, e, t), [ae, e, t]);
888
- G(() => {
889
- ie || re(void 0);
890
- }, [ie, re]);
891
- const Be = R(async (K, ve) => {
892
- const st = await (async (Ue, Xe) => {
893
- if (!Ue) return [];
894
- const Le = [], ot = oi(Ue.map((be) => {
895
- if (!be || !xa.includes(be.type)) return null;
896
- if (be.type === "picture") {
897
- const Ve = new Image(), Ka = new Promise((rt, Ja) => {
898
- Ve.onload = () => {
899
- URL.revokeObjectURL(Ve.src), rt();
900
- }, Ve.onerror = () => {
901
- Ja(new Error("Some images could not be loaded"));
990
+ Ye(!1), Je(!1);
991
+ }, [Se, de, Le]), { isInsideComponent: $e, isInsideCanvas: Ke };
992
+ })({ settings: G, componentRef: S, canvasRef: V }), [ge, q] = $(!1), [he, ce] = $(!1), [Ee, Ie] = $(!1), { registerEvent: He, unregisterEvent: ve, shapesRef: ne, selectedShape: Te, selectionFrame: We, hoveredShape: Ce, addShapes: qe, addPictureShape: Rt, moveShapes: Wt, setSelectedShape: _e, setSelectionFrame: Ot, refreshSelectedShapes: Ft, refreshHoveredShape: fe, removeShape: me, updateShape: vt, backwardShape: Be, forwardShape: it, clearShapes: xi, saveShapes: bn, toggleShapeVisibility: xn, toggleShapeLock: wn, canGoBackward: Cn, canGoForward: Mn, canClear: kn } = bo(G, e, t, ge), Bt = B((ee) => {
993
+ _e(void 0), F(ee);
994
+ }, [_e]), [at, wi] = $([0, 0]), Ci = X.mode === "preview";
995
+ J(() => {
996
+ if (Ci) return () => p((ee) => ee.mode === "preview" ? { mode: "default" } : ee);
997
+ }, [Te?.id, Ci]);
998
+ const Mi = X.mode === "selectionFrame";
999
+ J(() => {
1000
+ if (Mi) return () => wi([0, 0]);
1001
+ }, [Mi]), J(() => {
1002
+ if (at[0] !== 0 || at[1] !== 0) {
1003
+ const ee = setInterval(() => {
1004
+ O(({ offset: de, zoom: Le }) => {
1005
+ const $e = [de[0] - at[0], de[1] - at[1]];
1006
+ return ai({ zoom: Le, size: Z, canvasSize: L, newOffset: $e });
1007
+ });
1008
+ }, 20);
1009
+ return () => clearInterval(ee);
1010
+ }
1011
+ }, [at[0], at[1], O, Z, L]);
1012
+ const St = B((ee, de) => {
1013
+ xi(ee, de), Bt(Fe), O({ offset: [0, 0], zoom: 1 });
1014
+ }, [Bt, xi, O]), ki = B((ee) => {
1015
+ _e((de) => (de?.id !== ee.map((Le) => Le.id).join("-") && F(Fe), be(ee, G)));
1016
+ }, [_e, G]), Pn = B(() => {
1017
+ const ee = So(ne.current, e, t);
1018
+ if (!ee) throw new Error("L'encodage a échoué");
1019
+ ea(ee, "drawing.json");
1020
+ }, [ne, e, t]), Ln = B((ee) => {
1021
+ const de = ta({ shapes: ne.current, settings: G, view: ee });
1022
+ ea(de, "drawing.png");
1023
+ }, [ne, G]), Zn = B((ee) => ta({ shapes: ne.current, settings: G, view: ee }), [ne, G]), Vn = B(() => bi(ne.current, e, t), [ne, e, t]), je = B(async (ee, de) => {
1024
+ const Le = await (async ($e, Ye) => {
1025
+ if (!$e) return [];
1026
+ const Ke = [], Je = Qi($e.map((Se) => {
1027
+ if (!Se || !$a.includes(Se.type)) return null;
1028
+ if (Se.type === "picture") {
1029
+ const Ze = new Image(), Qt = new Promise((Ue, bt) => {
1030
+ Ze.onload = () => {
1031
+ URL.revokeObjectURL(Ze.src), Ue();
1032
+ }, Ze.onerror = () => {
1033
+ bt(new Error("Some images could not be loaded"));
902
1034
  };
903
1035
  });
904
- if (Le.push(Ka), be.src.startsWith("http")) $a(be.src).then((rt) => {
905
- Ve.src = rt;
1036
+ if (Ke.push(Qt), Se.src.startsWith("http")) Sn(Se.src).then((Ue) => {
1037
+ Ze.src = Ue;
906
1038
  }).catch(() => {
907
- Ve.src = "";
1039
+ Ze.src = "";
908
1040
  });
909
- else if (be.src.includes("<svg")) {
910
- const rt = new Blob([be.src], { type: "image/svg+xml" });
911
- Ve.src = URL.createObjectURL(rt);
912
- } else Ve.src = be.src;
913
- return Wi({ ...be, img: Ve }, Xe);
1041
+ else if (Se.src.includes("<svg")) {
1042
+ const Ue = new Blob([Se.src], { type: "image/svg+xml" });
1043
+ Ze.src = URL.createObjectURL(Ue);
1044
+ } else Ze.src = Se.src;
1045
+ return ia({ ...Se, img: Ze }, Ye);
914
1046
  }
915
- return Wi(be, Xe);
1047
+ return ia(Se, Ye);
916
1048
  }));
917
- return await Promise.all(Le), ot;
918
- })(K, B);
919
- Re(st, ve);
920
- }, [Re, B]), Dt = J(Be);
921
- Dt.current = Be;
922
- const Ga = R((K = [], ve = !0) => {
923
- Dt.current?.(K, { clearHistory: ve, source: "remote" });
1049
+ return await Promise.all(Ke), Je;
1050
+ })(ee, G);
1051
+ St(Le, de);
1052
+ }, [St, G]), $t = te(je);
1053
+ $t.current = je;
1054
+ const Hn = B((ee = [], de = !0) => {
1055
+ $t.current?.(ee, { clearHistory: de, source: "remote" });
924
1056
  }, []);
925
- G(() => {
926
- Z.current || (Z.current = !0, i && Dt.current?.(i, { clearHistory: !0, source: "remote" }));
1057
+ J(() => {
1058
+ I.current || (I.current = !0, i && $t.current?.(i, { clearHistory: !0, source: "remote" }));
927
1059
  }, [i]);
928
- const _a = R(async (K) => {
929
- const ve = await (async (st) => new Promise((Ue, Xe) => {
930
- const Le = new FileReader();
931
- Le.onload = (ot) => {
932
- const be = ot.target?.result;
933
- if (!be) return Xe("Impossible de récupérer les données du fichier");
934
- const Ve = JSON.parse(be);
935
- Ue(Ve);
936
- }, Le.readAsText(st);
937
- }))(K);
938
- await Be(ve.shapes ?? [], { clearHistory: !0, source: "remote" });
939
- }, [Be]), ja = R(() => {
940
- typeof b != "string" ? Be(b(), { clearHistory: !1, source: "user" }) : b === "defaultShapes" && i !== void 0 ? Be(i, { clearHistory: !1, source: "user" }) : Re([], { clearHistory: !1, source: "user" });
941
- }, [Re, Be, i, b]);
942
- G(() => {
943
- U(Ri(k, f || w));
944
- }, [k, f, w]);
945
- const ci = { canvas: H, editor: D, setEditor: F };
946
- return { annotationsProps: { style: { "user-select": "none", "touch-action": "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": B.canvasZoom, "--react-paint-canvas-offset-x": B.canvasOffset[0], "--react-paint-canvas-offset-y": B.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: ae, addPictureShape: We, moveShapes: fe, toggleShapeVisibility: At, toggleShapeLock: Et, canGoBackward: le, canGoForward: ce, canClear: vt, selectedShape: Se, removeShape: Ne, updateShape: xe, backwardShape: pt, forwardShape: gt, refs: ci, width: e, height: t, selectTool: Te, selectShape: li, activeTool: Y, setActiveTool: q, setAvailableTools: U, isEditMode: T, availableTools: se, gridGap: y, setGridGap: S, loadFile: _a, exportPicture: Xa, exportData: Ua, clearCanvas: ja, settings: B, setCanvasZoom: te, canvas: { canGrow: h, canShrink: c, layersManipulation: o, withExport: u, withLoadAndSave: g, withUploadPicture: f, withUrlPicture: w } }, canvasProps: { shapesRef: ae, selectedShape: Se, selectionFrame: Ee, hoveredShape: De, addShape: ue, setSelectedShape: re, setSelectionFrame: Ze, refreshSelectedShapes: Pe, refreshHoveredShape: Ge, removeShape: Ne, updateShape: xe, backwardShape: pt, forwardShape: gt, saveShapes: zt, refs: ci, width: e, height: t, settings: B, setCanvasSize: z, setCanvasOffset: _, setCanvasZoom: te, selectShape: li, activeTool: Y, setActiveTool: q, isInsideComponent: ie, isEditMode: T, canvas: { withSkeleton: x, withFrameSelection: C, canGrow: h, canShrink: c }, canvasOffsetStartData: N, setCanvasOffsetStartData: W, selectionMode: L, setSelectionMode: m }, registerEvent: he, unregisterEvent: ge, resetCanvas: Ga, getCurrentImage: Ya, getCurrentData: qa, setCanvasOffset: _, setCanvasZoom: te };
947
- }, Tn = (e, t, i, a, s, n, o) => {
948
- let r = !1;
949
- if (s) {
950
- r = ht(e, s, i, a, !0, n ? 20 : void 0);
951
- const d = ((h, c, u, g) => {
952
- if (h.mode === "translate") return { mode: "translate", cursorStartPosition: u, originalShape: c };
953
- if (h.mode === "rotate") {
954
- const { center: f } = ee(c, g);
955
- return { mode: "rotate", cursorStartPosition: u, originalShape: c, center: [f[0], f[1]] };
956
- }
957
- return h.mode === "resize" ? { mode: "resize", cursorStartPosition: u, originalShape: c, anchor: h.anchor } : void 0;
958
- })(r || { mode: "default" }, s, i, a);
959
- if (d?.mode === "resize" || d?.mode === "rotate") return { shape: s, mode: d };
960
- }
961
- const l = t.find((d) => d.id === s?.id ? !!r : !!Da(e, d, i, a));
962
- return l ? { shape: l, mode: { mode: "translate", cursorStartPosition: i, originalShape: l } } : { shape: void 0, mode: { mode: o ? "selectionFrame" : "default" } };
963
- }, zn = ({ addShape: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: a, shapes: s, selectionMode: n, activeTool: o, isInsideComponent: r, setCanvasOffset: l, selectedShape: d, canvasOffsetStartData: h, refreshSelectedShapes: c, setSelectedShape: u, setSelectionFrame: g, setCanvasOffsetStartData: f, updateSingleShape: w, saveShapes: x, setSelectionMode: C, settings: b, isShiftPressed: k, isAltPressed: v, withFrameSelection: Q }) => {
964
- const [V, T] = O({ mode: "default" }), { registerDoubleClickEvent: D, unRegisterDoubleClickEvent: H } = (() => {
965
- const L = J(void 0), m = J(void 0), y = (S) => {
1060
+ const Tn = B(async (ee) => {
1061
+ const de = await (async (Le) => new Promise(($e, Ye) => {
1062
+ const Ke = new FileReader();
1063
+ Ke.onload = (Je) => {
1064
+ const Se = Je.target?.result;
1065
+ if (!Se) return Ye("Impossible de récupérer les données du fichier");
1066
+ const Ze = JSON.parse(Se);
1067
+ $e(Ze);
1068
+ }, Ke.readAsText(Le);
1069
+ }))(ee);
1070
+ await je(de.shapes ?? [], { clearHistory: !0, source: "remote" });
1071
+ }, [je]), zn = B(() => {
1072
+ typeof m != "string" ? je(m(), { clearHistory: !1, source: "user" }) : m === "defaultShapes" && i !== void 0 ? je(i, { clearHistory: !1, source: "user" }) : St([], { clearHistory: !1, source: "user" });
1073
+ }, [St, je, i, m]);
1074
+ J(() => {
1075
+ ae(oa(y, x || C));
1076
+ }, [y, x, C]);
1077
+ const Pi = { canvas: V, editor: S, setEditor: N };
1078
+ 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": G.canvasZoom, "--react-paint-canvas-offset-x": G.canvasOffset[0], "--react-paint-canvas-offset-y": G.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: ne, addPictureShape: Rt, moveShapes: Wt, toggleShapeVisibility: xn, toggleShapeLock: wn, canGoBackward: Cn, canGoForward: Mn, canClear: kn, selectedShape: Te, removeShape: me, updateShape: vt, backwardShape: Be, forwardShape: it, refs: Pi, width: e, height: t, selectTool: Bt, selectShapes: ki, activeTool: U, setActiveTool: F, setAvailableTools: ae, isEditMode: T, availableTools: le, gridGap: Q, setGridGap: M, loadFile: Tn, exportPicture: Ln, exportData: Pn, clearCanvas: zn, settings: G, setCanvasZoom: ie, resetZoom: re, canvas: { canGrow: d, canShrink: h, layersManipulation: r, withExport: f, withLoadAndSave: g, withUploadPicture: x, withUrlPicture: C } }, canvasProps: { shapesRef: ne, selectedShape: Te, selectionFrame: We, hoveredShape: Ce, addShape: qe, setSelectedShape: _e, setSelectionFrame: Ot, refreshSelectedShapes: Ft, refreshHoveredShape: fe, removeShape: me, updateShape: vt, backwardShape: Be, forwardShape: it, saveShapes: bn, refs: Pi, width: e, height: t, settings: G, setCanvasSize: P, setCanvasOffset: z, setCanvasZoom: ie, resetZoom: re, selectShapes: ki, activeTool: U, setActiveTool: F, isInsideComponent: pe, isInsideCanvas: se, isEditMode: T, canvas: { withSkeleton: k, withFrameSelection: w, canGrow: d, canShrink: h }, canvasOffsetStartData: H, setCanvasOffsetStartData: D, selectionMode: X, setSelectionMode: p, setCanvasMoveAcceleration: wi, isShiftPressed: ge, isAltPressed: he, isSpacePressed: Ee, setShiftPressed: q, setAltPressed: ce, setIsSpacePressed: Ie }, registerEvent: He, unregisterEvent: ve, resetCanvas: Hn, resetZoom: re, getCurrentImage: Zn, getCurrentData: Vn, setCanvasOffset: z, setCanvasZoom: ie };
1079
+ }, Co = ({ addShapes: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: a, shapes: n, selectionMode: o, activeTool: r, isInsideComponent: l, setCanvasOffset: s, selectedShape: c, canvasOffsetStartData: u, refreshSelectedShapes: d, setSelectedShape: h, setSelectionFrame: f, setCanvasOffsetStartData: g, updateSingleShape: x, saveShapes: C, setSelectionMode: k, setCanvasMoveAcceleration: w, settings: m, isShiftPressed: y, isAltPressed: b, withFrameSelection: Z, isSpacePressed: A }) => {
1080
+ const [T, S] = $({ mode: "default" }), { registerDoubleClickEvent: V, unRegisterDoubleClickEvent: I } = (() => {
1081
+ const p = te(void 0), Q = te(void 0), M = (L) => {
966
1082
  const P = Date.now();
967
- L.current && P < L.current + 300 && m.current?.(S), L.current = Date.now();
1083
+ p.current && P < p.current + 300 && Q.current?.(L), p.current = Date.now();
968
1084
  };
969
- return { registerDoubleClickEvent: (S, P) => {
970
- m.current = P, S.addEventListener("click", y), S.addEventListener("touchend", y);
971
- }, unRegisterDoubleClickEvent: (S) => {
972
- S.removeEventListener("click", y), S.removeEventListener("touchend", y);
1085
+ return { registerDoubleClickEvent: (L, P) => {
1086
+ Q.current = P, L.addEventListener("click", M), L.addEventListener("touchend", M);
1087
+ }, unRegisterDoubleClickEvent: (L) => {
1088
+ L.removeEventListener("click", M), L.removeEventListener("touchend", M);
973
1089
  } };
974
- })(), Z = J(null);
975
- Z.current = (L) => ((m, y, S, P, z, M, A, E, _, te, j, ne, B, se) => {
976
- if (ct(m) && m.touches.length > 1) return;
977
- const U = y.current?.getContext("2d");
978
- if (!U) return;
979
- const ie = lt(m, y.current, j);
980
- if (z !== void 0) return void _([ie[0] + j.canvasOffset[0] - z.start[0], ie[1] + j.canvasOffset[1] - z.start[1]]);
981
- if (P.mode === "selectionFrame") return void te(U, ie, j);
1090
+ })(), N = te(null);
1091
+ N.current = (p) => ((Q, M, L, P, E, W, O, z, ie, re, R, oe, G, le, ae) => {
1092
+ if (st(Q) && Q.touches.length > 1) return;
1093
+ const pe = M.current?.getContext("2d");
1094
+ if (!pe) return;
1095
+ const se = ot(Q, M.current, R);
1096
+ if (P.mode === "selectionFrame") {
1097
+ re(pe, se, R);
1098
+ const q = sn(Q, M.current, R.canvasSize);
1099
+ return void ae([Math.ceil(De(q[0] * R.canvasZoom < 50 ? q[0] * R.canvasZoom - 50 : q[0] * R.canvasZoom > R.canvasSize.width / R.canvasSize.scaleRatioWithNoZoom - 50 ? q[0] * R.canvasZoom - (R.canvasSize.width / R.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / R.canvasZoom), Math.ceil(De(q[1] * R.canvasZoom < 50 ? q[1] * R.canvasZoom - 50 : q[1] * R.canvasZoom > R.canvasSize.height / R.canvasSize.scaleRatioWithNoZoom - 50 ? q[1] * R.canvasZoom - (R.canvasSize.height / R.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / R.canvasZoom)]);
1100
+ }
1101
+ if (E !== void 0) return void ie([se[0] + R.canvasOffset[0] - E.start[0], se[1] + R.canvasOffset[1] - E.start[1]]);
982
1102
  if (P.mode === "preview") {
983
- if (S?.type === "curve") return void se(Pi(S, ie, j, !0));
984
- if (S?.type === "polygon") return void se(ki(S, ie, j, !0));
1103
+ const q = j(L)[0];
1104
+ if (q?.type === "curve") {
1105
+ const he = Gi(q, se, R, !0);
1106
+ return void le(be([he], R));
1107
+ }
1108
+ if (q?.type === "polygon") {
1109
+ const he = Xi(q, se, R, !0);
1110
+ return void le(be([he], R));
1111
+ }
985
1112
  }
986
- const he = dt(ie, j);
987
- if (ct(m) || A(m, U, ie, he), S === void 0 || S.locked) M({ mode: "default", outOfView: !he });
1113
+ const ge = ft(se, R);
1114
+ if (st(Q) || O(Q, pe, se, ge), L === void 0 || L.locked) W({ mode: "default", outOfView: !ge });
988
1115
  else if (P.mode === "default" || P.mode === "textedition") {
989
- if (!he) return void M({ mode: "default" });
990
- M(ht(U, S, ie, j, !0) || { mode: "default" });
1116
+ if (!ge) return void W({ mode: "default" });
1117
+ W(mt(pe, L, se, R, !0) || { mode: "default" });
991
1118
  } else {
992
- const ge = y.current?.getContext("2d");
993
- if (!ge) return;
994
- E(ln(ge, S, ie, P, j, ne, B));
1119
+ const q = M.current?.getContext("2d");
1120
+ if (!q) return;
1121
+ const he = Rn(q, L, se, P, R, oe, G);
1122
+ z(j(he));
995
1123
  }
996
- })(L, t, d, n, h, T, a, w, l, c, b, k, v, u), G(() => {
997
- if (r) {
998
- const L = (m) => Z.current?.(m);
999
- return document.addEventListener("mousemove", L), document.addEventListener("touchmove", L), () => {
1000
- document.removeEventListener("mousemove", L), document.removeEventListener("touchmove", L);
1124
+ })(p, t, c, o, u, S, a, x, s, d, m, y, b, h, w), J(() => {
1125
+ if (l) {
1126
+ const p = (Q) => N.current?.(Q);
1127
+ return document.addEventListener("mousemove", p), document.addEventListener("touchmove", p), () => {
1128
+ document.removeEventListener("mousemove", p), document.removeEventListener("touchmove", p);
1001
1129
  };
1002
1130
  }
1003
- }, [r]);
1004
- const { isBrushShapeDoneOnMouseUp: F } = b, N = J(null);
1005
- N.current = (L) => {
1006
- if (!(ct(L) && L.touches.length > 1)) {
1007
- if ("button" in L && L.button === 2) return u(void 0), i(Ae), C({ mode: "default" }), void g(void 0);
1008
- h ? f(void 0) : n.mode !== "textedition" && n.mode !== "preview" && n.mode !== "default" && (n.mode === "brush" && F && u(void 0), C({ mode: "default" }), g(void 0), x());
1131
+ }, [l]);
1132
+ const { isBrushShapeDoneOnMouseUp: H } = m, D = te(null);
1133
+ D.current = (p) => {
1134
+ if (st(p) && p.touches.length > 1) return;
1135
+ const Q = t.current?.getContext("2d");
1136
+ if (!Q) return;
1137
+ if ("button" in p && p.button === 2) return h(void 0), i(Fe), k({ mode: "default" }), void f(void 0);
1138
+ if (u) return void g(void 0);
1139
+ if (o.mode === "textedition" || o.mode === "preview") return;
1140
+ const M = ot(p, t.current, m);
1141
+ if (o.mode === "translate" && Date.now() - o.dateStart <= 500 && M[0] === o.cursorStartPosition[0] && M[1] === o.cursorStartPosition[1]) {
1142
+ if (!(p.ctrlKey || p.shiftKey || p.metaKey)) {
1143
+ const { shape: L } = Bi(Q, n, M, m, void 0, st(p), Z, !1);
1144
+ h(L);
1145
+ }
1146
+ return k({ mode: "default" }), f(void 0), void C();
1009
1147
  }
1010
- }, G(() => {
1011
- if (r) {
1012
- const L = (m) => N.current?.(m);
1013
- return document.addEventListener("mouseup", L), document.addEventListener("touchend", L), () => {
1014
- document.removeEventListener("mouseup", L), document.removeEventListener("touchend", L);
1148
+ o.mode !== "default" && (o.mode === "brush" && H && h(void 0), k({ mode: "default" }), f(void 0), C());
1149
+ }, J(() => {
1150
+ if (l) {
1151
+ const p = (Q) => D.current?.(Q);
1152
+ return document.addEventListener("mouseup", p), document.addEventListener("touchend", p), () => {
1153
+ document.removeEventListener("mouseup", p), document.removeEventListener("touchend", p);
1015
1154
  };
1016
1155
  }
1017
- }, [r]);
1018
- const W = !b.features.edition && b.features.zoom, Y = !b.features.edition && !b.features.zoom, q = J(null);
1019
- return q.current = (L, m) => {
1020
- if (L.preventDefault(), ct(L) && L.touches.length > 1) return;
1021
- const y = m?.getContext("2d");
1022
- if (!y) return;
1023
- const S = lt(L, t.current, b), P = "button" in L && L.button === 1;
1024
- if (!("button" in L && L.button === 2)) {
1025
- if (P || o.type === "move") f({ start: S, originalOffset: b.canvasOffset });
1026
- else if (!W) {
1027
- if (!dt(S, b)) return u(void 0), void C({ mode: "default" });
1028
- if (o.type === "selection") {
1029
- const { shape: z, mode: M } = Tn(y, s, S, b, d, ct(L), Q);
1030
- u(z), C(M), M.mode === "selectionFrame" && g([[S[0], S[1]], [S[0], S[1]]]);
1031
- } else if (xa.some((z) => z === o.type)) {
1032
- const z = t.current?.getContext("2d");
1033
- if (!z) return;
1034
- if (o.type === "brush") {
1035
- if (d?.type === "brush") {
1036
- const M = ((A, E, _) => {
1037
- const te = { ...A, points: Qe(A.points.length, [[Math.round(E[0]), Math.round(E[1])]], A.points) };
1038
- return it(te, _);
1039
- })(d, S, b);
1040
- w(M);
1156
+ }, [l]);
1157
+ const U = !m.features.edition && m.features.zoom, F = !m.features.edition && !m.features.zoom, X = te(null);
1158
+ return X.current = (p, Q, M) => {
1159
+ if (p.preventDefault(), st(p) && p.touches.length > 1) return;
1160
+ const L = Q?.getContext("2d");
1161
+ if (!L) return;
1162
+ Q.focus();
1163
+ const P = ot(p, t.current, m), E = "button" in p && p.button === 1;
1164
+ if (!("button" in p && p.button === 2)) {
1165
+ if (E || M || r.type === "move") g({ start: P, originalOffset: m.canvasOffset });
1166
+ else if (!U) {
1167
+ if (!ft(P, m)) return h(void 0), void k({ mode: "default" });
1168
+ if (r.type === "selection") {
1169
+ const W = p.ctrlKey || p.shiftKey || p.metaKey, { shape: O, mode: z } = Bi(L, n, P, m, c, st(p), Z, W);
1170
+ h(O), k(z), z.mode === "selectionFrame" && f({ oldSelection: O, frame: [[P[0], P[1]], [P[0], P[1]]] });
1171
+ } else if ($a.some((W) => W === r.type)) {
1172
+ const W = j(c)[0], O = t.current?.getContext("2d");
1173
+ if (!O) return;
1174
+ if (r.type === "brush") {
1175
+ if (W?.type === "brush") {
1176
+ const z = ((ie, re, R) => {
1177
+ const oe = { ...ie, points: Pe(ie.points.length, [[Math.round(re[0]), Math.round(re[1])]], ie.points) };
1178
+ return ht(oe, R);
1179
+ })(W, P, m);
1180
+ x([z]);
1041
1181
  } else {
1042
- const M = Ti(z, o, S, b);
1043
- if (!M) return;
1044
- e(M), u(M);
1182
+ const z = ji(O, r, P, m);
1183
+ if (!z) return;
1184
+ e([z]), h(be([z], m));
1045
1185
  }
1046
- C({ mode: "brush" });
1047
- } else if (n.mode !== "preview" || d?.type !== "polygon" && d?.type !== "curve") {
1048
- if (o.type !== "picture") {
1049
- const M = Ti(z, o, S, b);
1050
- e(M), u(M), M.type === "polygon" || M.type === "curve" ? C({ mode: "preview" }) : (i(Ae), C({ mode: "resize", cursorStartPosition: [S[0] + b.selectionPadding, S[1] + b.selectionPadding], originalShape: M, anchor: M.type === "line" ? 0 : [1, 1] }));
1186
+ k({ mode: "brush" });
1187
+ } else if (o.mode !== "preview" || W?.type !== "polygon" && W?.type !== "curve") {
1188
+ if (r.type !== "picture") {
1189
+ const z = ji(O, r, P, m);
1190
+ if (!z) return;
1191
+ e([z]);
1192
+ const ie = be([z], m);
1193
+ h(ie), z.type === "polygon" || z.type === "curve" ? k({ mode: "preview" }) : (i(Fe), k({ mode: "resize", cursorStartPosition: [P[0] + m.selectionPadding, P[1] + m.selectionPadding], originalShape: ie, anchor: z.type === "line" ? 0 : [1, 1] }));
1051
1194
  }
1052
1195
  } else {
1053
- const M = d?.type === "polygon" ? ki(d, S, b) : Pi(d, S, b);
1054
- u(M), w(M, !0);
1196
+ const z = W.type === "polygon" ? Xi(W, P, m) : Gi(W, P, m);
1197
+ h(be([z], m)), x([z], !0);
1055
1198
  }
1056
1199
  }
1057
1200
  }
1058
1201
  }
1059
- }, G(() => {
1060
- if (Y) return;
1061
- const L = t.current;
1062
- if (!L) return;
1063
- const m = (y) => q.current?.(y, L);
1064
- return L.addEventListener("mousedown", m, { passive: !1 }), L.addEventListener("touchstart", m, { passive: !1 }), () => {
1065
- L.removeEventListener("mousedown", m), L.removeEventListener("touchstart", m);
1202
+ }, J(() => {
1203
+ if (F) return;
1204
+ const p = t.current;
1205
+ if (!p) return;
1206
+ const Q = (M) => X.current?.(M, p, A);
1207
+ return p.addEventListener("mousedown", Q, { passive: !1 }), p.addEventListener("touchstart", Q, { passive: !1 }), () => {
1208
+ p.removeEventListener("mousedown", Q), p.removeEventListener("touchstart", Q);
1066
1209
  };
1067
- }, [Y, t]), G(() => {
1068
- const L = t.current, m = t.current?.getContext("2d");
1069
- return !L || !m ? void 0 : r ? (D(L, (S) => {
1070
- if (o.type === "selection") {
1071
- if (d?.type === "text") {
1072
- const P = lt(S, t.current, b);
1073
- return dt(P, b) ? void (ht(m, d, P, b) && C({ mode: "textedition", defaultValue: d.value })) : void 0;
1074
- }
1075
- if (d?.type === "polygon") {
1076
- const P = lt(S, t.current, b);
1077
- if (!dt(P, b)) return;
1078
- const z = xi(m, d, P, b);
1079
- return void (z && w(((M, A, E, _) => {
1080
- if (A < 0 || A > M.points.length - 1) return M;
1081
- const te = [...M.points.slice(0, A + 1), E, ...M.points.slice(A + 1)];
1082
- return at({ ...M, points: te }, _);
1083
- })(d, z.lineIndex, P, b)));
1084
- }
1085
- if (d?.type === "curve") {
1086
- const P = lt(S, t.current, b);
1087
- if (!dt(P, b)) return;
1088
- const z = ((M, A, E, _, te = 50) => {
1089
- if (A.locked || A.points.length < 2) return !1;
1090
- if (A.points.length < 3) return xi(M, A, E, _, te);
1091
- const { center: j } = ee(A, _), ne = ke(E, A.rotation, j);
1092
- M.lineWidth = (A.style?.lineWidth ?? 0) + te / _.canvasZoom;
1093
- const B = Ha(A, A.points), se = new Path2D();
1094
- se.moveTo(...B[0]);
1095
- for (let U = 1; U < B.length - 2; U++) {
1096
- const ie = B[U - 1], he = B[U], ge = B[U + 1], ae = B[U + 2];
1097
- if (Za(se, ie, he, ge, ae), M.isPointInStroke(se, ne[0], ne[1])) return { lineIndex: U - 1 };
1098
- }
1099
- return !1;
1100
- })(m, d, P, b);
1101
- return void (z && w(((M, A, E, _) => {
1102
- if (A < 0 || A > M.points.length - 1) return M;
1103
- const te = [...M.points.slice(0, A + 1), E, ...M.points.slice(A + 1)];
1104
- return nt({ ...M, points: te }, _);
1105
- })(d, z.lineIndex, P, b)));
1210
+ }, [F, t, A]), J(() => {
1211
+ const p = t.current, Q = t.current?.getContext("2d");
1212
+ if (!(!p || !Q))
1213
+ return l ? (V(p, (M) => {
1214
+ if (r.type === "selection") {
1215
+ if (j(c).length !== 1) return;
1216
+ const L = j(c)[0];
1217
+ if (L?.type === "text") {
1218
+ const P = ot(M, t.current, m);
1219
+ return ft(P, m) ? void (mt(Q, c, P, m) && k({ mode: "textedition", defaultValue: L.value })) : void 0;
1220
+ }
1221
+ if (L?.type === "polygon") {
1222
+ const P = ot(M, t.current, m);
1223
+ if (!ft(P, m)) return;
1224
+ const E = Yi(Q, L, P, m);
1225
+ return void (E && x([Kn(L, E.lineIndex, P, m)]));
1226
+ }
1227
+ if (L?.type === "curve") {
1228
+ const P = ot(M, t.current, m);
1229
+ if (!ft(P, m)) return;
1230
+ const E = ((W, O, z, ie, re = 50) => {
1231
+ if (O.locked || O.points.length < 2) return !1;
1232
+ if (O.points.length < 3) return Yi(W, O, z, ie, re);
1233
+ const { center: R } = O.computed, oe = Ae(z, O.rotation ?? 0, R);
1234
+ W.lineWidth = (O.style?.lineWidth ?? 0) + re / ie.canvasZoom;
1235
+ const G = pi(O, O.points), le = new Path2D();
1236
+ le.moveTo(...G[0]);
1237
+ for (let ae = 1; ae < G.length - 2; ae++) {
1238
+ const pe = G[ae - 1], se = G[ae], ge = G[ae + 1], q = G[ae + 2], { cp1: he, cp2: ce } = gi(pe, se, ge, q);
1239
+ if (le.bezierCurveTo(he[0], he[1], ce[0], ce[1], ge[0], ge[1]), W.isPointInStroke(le, oe[0], oe[1])) return { lineIndex: ae - 1 };
1240
+ }
1241
+ return !1;
1242
+ })(Q, L, P, m);
1243
+ return void (E && x([to(L, E.lineIndex, P, m)]));
1244
+ }
1106
1245
  }
1107
- }
1108
- }), () => {
1109
- H(L);
1110
- }) : void 0;
1111
- }, [w, D, H, r, t, o, d, C, b]), { hoverMode: V };
1112
- }, Ba = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => Ba(t)).join("") : e.nodeValue ?? "", An = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: a, saveShapes: s, settings: n }) => {
1113
- const o = J(null), r = J(s);
1114
- G(() => {
1115
- if (!o.current) return;
1116
- const d = o.current, h = (c) => {
1117
- c.preventDefault();
1118
- const u = c.clipboardData?.getData("text/plain");
1119
- document.execCommand("insertText", !1, u);
1246
+ }), () => {
1247
+ I(p);
1248
+ }) : void 0;
1249
+ }, [x, V, I, l, t, r, c, k, m]), { hoverMode: T };
1250
+ }, Qn = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => Qn(t)).join("") : e.nodeValue ?? "", Mo = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: a, saveShapes: n, settings: o }) => {
1251
+ const r = te(null), l = te(n);
1252
+ J(() => {
1253
+ if (!r.current) return;
1254
+ const c = r.current, u = (d) => {
1255
+ d.preventDefault();
1256
+ const h = d.clipboardData?.getData("text/plain");
1257
+ document.execCommand("insertText", !1, h);
1120
1258
  };
1121
- d.addEventListener("paste", h), d.innerText = "";
1122
- for (const c of i) {
1123
- const u = document.createElement("div");
1124
- c === "" ? u.innerHTML = "<br/>" : u.innerText = c, d.appendChild(u);
1259
+ c.addEventListener("paste", u), c.innerText = "";
1260
+ for (const d of i) {
1261
+ const h = document.createElement("div");
1262
+ d === "" ? h.innerHTML = "<br/>" : h.innerText = d, c.appendChild(h);
1125
1263
  }
1126
- return d.focus(), () => {
1127
- d.removeEventListener("paste", h);
1264
+ return c.focus(), () => {
1265
+ c.removeEventListener("paste", u);
1128
1266
  };
1129
- }, [i]), G(() => {
1130
- const d = r.current;
1267
+ }, [i]), J(() => {
1268
+ const c = l.current;
1131
1269
  return () => {
1132
- d();
1270
+ c();
1133
1271
  };
1134
1272
  }, []);
1135
- const l = ia(() => {
1136
- const { borders: d, center: h } = ee(t, n);
1137
- return we({ point: [d.x, d.y], rotation: -t.rotation, origin: h });
1138
- }, [t, n]);
1139
- return p("div", { className: "react-paint-editor-toolbox-edittextbox", ref: o, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: !e, onInput: (d) => {
1140
- const h = Array.from(d.target.childNodes).map((c) => Ba(c));
1141
- a(h);
1142
- }, style: { "--react-paint-editor-toolbox-edittextbox-transform": `translate3D(${(l[0] + n.canvasOffset[0]) * n.canvasSize.scaleRatio}px, ${(l[1] + n.canvasOffset[1]) * n.canvasSize.scaleRatio}px, 0) rotate(${Yt(t.rotation)}deg)`, "--react-paint-editor-toolbox-edittextbox-fontsize": t.fontSize * n.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-padding": n.selectionPadding * n.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 ?? ut } });
1143
- }, En = (e, t, i, a, s) => {
1144
- Va(e), ((n, o) => {
1145
- const { canvasZoom: r, size: l, canvasSize: { width: d, height: h } } = o;
1146
- if (l !== "fixed" || r >= 1) return;
1147
- n.fillStyle = "#f5f5f5", n.fillRect(0, 0, d, h);
1148
- const c = Wa(o);
1149
- n.clearRect(c.x, c.y, c.width, c.height), Na(n, o);
1150
- })(e, i), ((n, o) => {
1151
- const { canvasSize: { width: r, height: l }, gridGap: d, canvasOffset: h, canvasSize: { scaleRatio: c } } = o;
1152
- if (!d) return;
1153
- n.strokeStyle = "rgb(220,220,220)", n.lineWidth = 1, n.save(), n.scale(c, c), n.beginPath();
1154
- const u = h[0] % d, g = h[1] % d, f = Math.ceil(r / c / d) + 2, w = Math.ceil(l / c / d) + 2;
1155
- for (let x = -5; x < f; x++) n.moveTo(u + (x + 1) * d, g - d), n.lineTo(u + (x + 1) * d, g + l / c + d);
1156
- for (let x = -5; x < w; x++) n.moveTo(u - d, g + (x + 1) * d), n.lineTo(u + r / c + d, g + (x + 1) * d);
1157
- n.stroke(), n.restore();
1273
+ const s = ba(() => {
1274
+ const { borders: c, center: u } = t.computed;
1275
+ return xe({ point: [c.x, c.y], rotation: -(t.rotation ?? 0), origin: u });
1276
+ }, [t]);
1277
+ return v("div", { className: "react-paint-editor-toolbox-edittextbox", ref: r, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: !e, onInput: (c) => {
1278
+ const u = Array.from(c.target.childNodes).map((d) => Qn(d));
1279
+ a(u);
1280
+ }, style: { "--react-paint-editor-toolbox-edittextbox-transform": `translate3D(${(s[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio}px, ${(s[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio}px, 0) rotate(${ti(t.rotation ?? 0)}deg)`, "--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 ?? yt } });
1281
+ }, ko = (e, t, i, a, n) => {
1282
+ qa(e), ((o, r) => {
1283
+ const { canvasZoom: l, size: s, canvasSize: { width: c, height: u } } = r;
1284
+ if (s !== "fixed" || l >= 1) return;
1285
+ o.fillStyle = "#f5f5f5", o.fillRect(0, 0, c, u);
1286
+ const d = ln(r);
1287
+ o.clearRect(d.x, d.y, d.width, d.height), cn(o, r);
1288
+ })(e, i), ((o, r) => {
1289
+ const { canvasSize: { width: l, height: s }, gridGap: c, canvasOffset: u, canvasSize: { scaleRatio: d } } = r;
1290
+ if (!c) return;
1291
+ o.strokeStyle = "rgb(220,220,220)", o.lineWidth = 1, o.save(), o.scale(d, d), o.beginPath();
1292
+ const h = u[0] % c, f = u[1] % c, g = Math.ceil(l / d / c) + 2, x = Math.ceil(s / d / c) + 2;
1293
+ for (let C = -5; C < g; C++) o.moveTo(h + (C + 1) * c, f - c), o.lineTo(h + (C + 1) * c, f + s / d + c);
1294
+ for (let C = -5; C < x; C++) o.moveTo(h - c, f + (C + 1) * c), o.lineTo(h + l / d + c, f + (C + 1) * c);
1295
+ o.stroke(), o.restore();
1158
1296
  })(e, i);
1159
- for (let n = a.length - 1; n >= 0; n--) t.mode === "textedition" && a[n] === s || Ia(e, a[n].id === s?.id ? s : a[n], i);
1160
- }, Dn = ta.forwardRef(({ canGrow: e, shapes: t, addShape: i, updateSingleShape: a, selectedShape: s, setSelectedShape: n, setSelectionFrame: o, hoveredShape: r, selectionFrame: l, refreshHoveredShape: d, refreshSelectedShapes: h, saveShapes: c, activeTool: u, setActiveTool: g, canvasOffsetStartData: f, setCanvasOffsetStartData: w, setCanvasOffset: x, isInsideComponent: C, selectionMode: b, setSelectionMode: k, selectionWidth: v, selectionColor: Q, settings: V, isEditMode: T, isShiftPressed: D, isAltPressed: H, withFrameSelection: Z, withSkeleton: F }, N) => {
1161
- const W = J(null), Y = J(null), q = V.canvasSize, L = T;
1162
- en(N, () => W.current);
1163
- const { hoverMode: m } = zn({ addShape: i, drawCanvasRef: W, setActiveTool: g, shapes: t, selectionMode: b, activeTool: u, isInsideComponent: C, setCanvasOffset: x, selectedShape: s, canvasOffsetStartData: f, setCanvasOffsetStartData: w, setSelectedShape: n, setSelectionFrame: o, refreshHoveredShape: d, refreshSelectedShapes: h, updateSingleShape: a, saveShapes: c, setSelectionMode: k, isShiftPressed: D, isAltPressed: H, withFrameSelection: Z, settings: V }), y = R((P) => {
1164
- if (s?.type !== "text") return;
1165
- const z = W.current?.getContext("2d");
1166
- if (!z) return;
1167
- const M = et(bn(z, s, P, V), V);
1168
- a(M);
1169
- }, [a, s, V]), S = (P) => {
1170
- if (T) return P.preventDefault(), P.stopPropagation(), !1;
1297
+ for (let o = a.length - 1; o >= 0; o--) t.mode === "textedition" && a[o] === n || fn(e, j(n).find((r) => r.id === a[o].id) ?? a[o], i);
1298
+ }, Po = si.forwardRef(({ canGrow: e, shapes: t, addShapes: i, updateSingleShape: a, selectedShape: n, setSelectedShape: o, setSelectionFrame: r, hoveredShape: l, selectionFrame: s, refreshHoveredShape: c, refreshSelectedShapes: u, saveShapes: d, activeTool: h, setActiveTool: f, canvasOffsetStartData: g, setCanvasOffsetStartData: x, setCanvasOffset: C, setCanvasMoveAcceleration: k, isInsideComponent: w, selectionMode: m, setSelectionMode: y, selectionWidth: b, selectionColor: Z, settings: A, isEditMode: T, isShiftPressed: S, isAltPressed: V, isSpacePressed: I, withFrameSelection: N, withSkeleton: H }, D) => {
1299
+ const U = te(null), F = te(null), X = A.canvasSize, p = T, Q = T ? 0 : -1;
1300
+ xa(D, () => U.current);
1301
+ const { hoverMode: M } = Co({ addShapes: i, drawCanvasRef: U, setActiveTool: f, shapes: t, selectionMode: m, activeTool: h, isInsideComponent: w, setCanvasOffset: C, selectedShape: n, canvasOffsetStartData: g, setCanvasOffsetStartData: x, setSelectedShape: o, setSelectionFrame: r, refreshHoveredShape: c, refreshSelectedShapes: u, updateSingleShape: a, saveShapes: d, setSelectionMode: y, setCanvasMoveAcceleration: k, isShiftPressed: S, isAltPressed: V, withFrameSelection: N, settings: A, isSpacePressed: I }), L = B((E) => {
1302
+ const W = j(n)[0];
1303
+ if (W?.type !== "text") return;
1304
+ const O = U.current?.getContext("2d");
1305
+ if (!O) return;
1306
+ const z = dt(po(O, W, E, A), A);
1307
+ a([z]);
1308
+ }, [a, n, A]), P = (E) => {
1309
+ if (T) return E.preventDefault(), E.stopPropagation(), !1;
1171
1310
  };
1172
- return G(() => {
1173
- const P = W.current?.getContext("2d");
1174
- P && window.requestAnimationFrame(() => En(P, b, V, t, s));
1175
- }, [t, b, s, V]), G(() => {
1176
- const P = Y.current?.getContext("2d");
1177
- P && window.requestAnimationFrame(() => ((z, M, A, E, _, te, j, ne, B, se) => {
1178
- z.reset(), Na(z, A), se && ne && ne.id !== j?.id && E.type === "selection" && M.mode === "default" && Ai({ ctx: z, shape: ne, settings: A, selectionWidth: _, selectionColor: te, withAnchors: !1 }), j && E.type !== "brush" && Ai({ ctx: z, shape: j, settings: A, selectionWidth: _, selectionColor: te, withAnchors: M.mode !== "textedition" }), B && Mn({ ctx: z, selectionFrame: B, settings: A });
1179
- })(P, b, V, u, v, Q, s, r, l, F));
1180
- }, [r, l, b, s, u, V, v, Q, F]), p("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": f ? "grabbing" : m.outOfView ? "default" : u.type !== "selection" && u.type !== "move" || m.mode === "resize" ? "crosshair" : m.mode === "translate" ? "move" : m.mode === "rotate" || u.type === "move" ? "grab" : "default" }, children: I("div", { className: "react-paint-canvas-container", "data-grow": e, children: [p("canvas", { className: Ca, ref: W, "data-grow": e, width: q.width, height: q.height, onContextMenu: S }), L && p("canvas", { className: Ma, ref: Y, width: q.width, height: q.height, "data-grow": e, onContextMenu: S }), T && b.mode === "textedition" && s?.type === "text" && p(An, { disabled: !V.features.edition, shape: s, defaultValue: b.defaultValue, updateValue: y, saveShapes: c, settings: V })] }) });
1181
- }), Ii = "ArrowUp", Oi = "ArrowDown", Fi = "ArrowLeft", $i = "ArrowRight", Wn = "Delete", Nn = "Backspace", Rn = "Escape", Bi = "Shift", Ui = "Alt", Xi = "Option", In = "z", On = "Z", Fn = "y", $n = "Y", Yi = "copy", qi = "paste", Bn = ({ isInsideComponent: e, selectedShape: t, isEditingText: i, settings: a, setSelectedShape: s, setActiveTool: n, setSelectionMode: o, setSelectionFrame: r, removeShape: l, pasteShape: d, updateShape: h, backwardShape: c, forwardShape: u, setShiftPressed: g, setAltPressed: f }) => {
1182
- const [w, x] = O(void 0);
1183
- return G(() => {
1184
- const C = (Q) => {
1185
- t && (i || (Q.preventDefault(), x({ ...t })));
1186
- }, b = (Q) => {
1187
- w && (i || (Q.preventDefault(), d(((V, T) => ({ ..._t([20, 20], V, [0, 0], T, !1), id: de(`${V.type}_`) }))(w, a))));
1188
- }, k = (Q) => {
1189
- switch (Q.key) {
1190
- case Bi:
1191
- g(!1);
1311
+ return J(() => {
1312
+ const E = U.current?.getContext("2d");
1313
+ E && window.requestAnimationFrame(() => ko(E, m, A, t, n));
1314
+ }, [t, m, n, A]), J(() => {
1315
+ const E = F.current?.getContext("2d");
1316
+ E && window.requestAnimationFrame(() => ((W, O, z, ie, re, R, oe, G, le, ae, pe) => {
1317
+ W.reset(), cn(W, z), pe && G && !j(oe).find((se) => se.id === G.id) && ie.type === "selection" && O.mode === "default" && Ji({ ctx: W, shape: G, settings: z, selectionWidth: re, selectionColor: R, hoverMode: le, withAnchors: !1 }), oe && ie.type !== "brush" && Ji({ ctx: W, shape: oe, settings: z, selectionWidth: re, selectionColor: R, hoverMode: le, withAnchors: O.mode !== "textedition" }), ae && mo({ ctx: W, selectionFrame: ae, settings: z });
1318
+ })(E, m, A, h, b, Z, n, l, M, s, H));
1319
+ }, [l, M, s, m, n, h, A, b, Z, H]), v("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": g ? "grabbing" : M.outOfView ? "default" : M.mode === "resize" ? "pointer" : h.type !== "selection" && h.type !== "move" ? "crosshair" : M.mode === "translate" ? "move" : M.mode === "rotate" || h.type === "move" || I ? "grab" : "default" }, children: Y("div", { className: "react-paint-canvas-container", "data-grow": e, children: [v("canvas", { className: Ya, ref: U, "data-grow": e, width: X.width, height: X.height, onContextMenu: P, tabIndex: Q }), p && v("canvas", { className: Ua, ref: F, width: X.width, height: X.height, "data-grow": e, onContextMenu: P }), T && m.mode === "textedition" && j(n)[0]?.type === "text" && v(Mo, { disabled: !A.features.edition, shape: j(n)[0], defaultValue: m.defaultValue, updateValue: L, saveShapes: d, settings: A })] }) });
1320
+ }), sa = "ArrowUp", ra = "ArrowDown", la = "ArrowLeft", ca = "ArrowRight", Lo = "Delete", Zo = "Backspace", Vo = "Escape", da = "Shift", ha = "Alt", ua = "Option", Vt = " ", Ho = "z", To = "Z", zo = "y", Ao = "Y", Eo = "+", Io = "-", No = "0", pa = "copy", ga = "paste", Do = ({ isInsideComponent: e, isInsideCanvas: t, selectedShape: i, isEditingText: a, settings: n, setSelectedShape: o, setActiveTool: r, setCanvasZoom: l, resetZoom: s, setSelectionMode: c, setSelectionFrame: u, removeShape: d, pasteShapes: h, updateShapes: f, backwardShape: g, forwardShape: x, setShiftPressed: C, setAltPressed: k, setIsSpacePressed: w }) => {
1321
+ const [m, y] = $(void 0);
1322
+ return J(() => {
1323
+ const b = (S) => {
1324
+ i && (a || (S.preventDefault(), y({ ...i })));
1325
+ }, Z = (S) => {
1326
+ m && (a || (S.preventDefault(), h(((V, I) => j(V).map((N) => ({ ...oi([20, 20], N, [0, 0], I, !1), id: ye(`${N.type}_`) })))(m, n))));
1327
+ }, A = (S) => {
1328
+ switch (S.key) {
1329
+ case da:
1330
+ C(!1);
1192
1331
  break;
1193
- case Ui:
1194
- case Xi:
1195
- f(!1);
1332
+ case ha:
1333
+ case ua:
1334
+ k(!1);
1335
+ break;
1336
+ case Vt:
1337
+ w(!1);
1196
1338
  }
1197
- }, v = (Q) => {
1198
- if (Q.metaKey || Q.ctrlKey) {
1199
- if (Q.key === On || Q.key === In) return Q.preventDefault(), Q.stopPropagation(), void (Q.shiftKey ? u() : c());
1200
- if (!La() && (Q.key === $n || Q.key === Fn)) return Q.preventDefault(), Q.stopPropagation(), void u();
1339
+ }, T = (S) => {
1340
+ if (S.metaKey || S.ctrlKey) {
1341
+ if (S.key === To || S.key === Ho) return S.preventDefault(), S.stopPropagation(), void (S.shiftKey ? x() : g());
1342
+ if (!Ga() && (S.key === Ao || S.key === zo)) return S.preventDefault(), S.stopPropagation(), void x();
1343
+ if (S.key === Eo) return S.preventDefault(), S.stopPropagation(), void l("zoom");
1344
+ if (S.key === Io) return S.preventDefault(), S.stopPropagation(), void l("unzoom");
1345
+ if (S.key === No) return S.preventDefault(), S.stopPropagation(), void s();
1201
1346
  }
1202
- if (Q.key === Bi) return Q.preventDefault(), Q.stopPropagation(), void g(!0);
1203
- if (Q.key === Ui || Q.key === Xi) return Q.preventDefault(), Q.stopPropagation(), void f(!0);
1204
- if (!t) return;
1205
- if (Q.key === Rn) return s(void 0), n(Ae), o({ mode: "default" }), void r(void 0);
1206
- if (i) return;
1207
- const V = { [Fi]: [a.gridGap ? -a.gridGap : -1, 0], [$i]: [a.gridGap ? a.gridGap : 1, 0], [Oi]: [0, a.gridGap ? a.gridGap : 1], [Ii]: [0, a.gridGap ? -a.gridGap : -1] };
1208
- switch (Q.key) {
1209
- case Fi:
1210
- case $i:
1211
- case Oi:
1212
- case Ii:
1213
- Q.preventDefault(), Q.stopPropagation(), h(_t(V[Q.key], t, [0, 0], a, !1));
1347
+ if (S.key === da) return S.preventDefault(), S.stopPropagation(), void C(!0);
1348
+ if (S.key === Vt && t) return S.preventDefault(), S.stopPropagation(), void w(!0);
1349
+ if (S.key === ha || S.key === ua) return S.preventDefault(), S.stopPropagation(), void k(!0);
1350
+ if (!i) return;
1351
+ if (S.key === Vo) return o(void 0), r(Fe), c({ mode: "default" }), void u(void 0);
1352
+ if (a) return;
1353
+ const V = { [la]: [n.gridGap ? -n.gridGap : -1, 0], [ca]: [n.gridGap ? n.gridGap : 1, 0], [ra]: [0, n.gridGap ? n.gridGap : 1], [sa]: [0, n.gridGap ? -n.gridGap : -1] };
1354
+ switch (S.key) {
1355
+ case la:
1356
+ case ca:
1357
+ case ra:
1358
+ case sa:
1359
+ S.preventDefault(), S.stopPropagation(), f(((I, N, H, D, U) => j(N).map((F) => oi(I, F, H, D, U)))(V[S.key], i, [0, 0], n, !1));
1214
1360
  break;
1215
- case Wn:
1216
- case Nn:
1217
- Q.preventDefault(), Q.stopPropagation(), l(t);
1361
+ case Lo:
1362
+ case Zo:
1363
+ S.preventDefault(), S.stopPropagation(), d(j(i));
1218
1364
  }
1219
1365
  };
1220
- if (e) return document.addEventListener("keydown", v), document.addEventListener("keyup", k), document.addEventListener(Yi, C), document.addEventListener(qi, b), () => {
1221
- document.removeEventListener("keydown", v), document.removeEventListener("keyup", k), document.removeEventListener(Yi, C), document.removeEventListener(qi, b);
1366
+ if (e) return document.addEventListener("keydown", T), document.addEventListener("keyup", A), document.addEventListener(pa, b), document.addEventListener(ga, Z), () => {
1367
+ document.removeEventListener("keydown", T), document.removeEventListener("keyup", A), document.removeEventListener(pa, b), document.removeEventListener(ga, Z);
1222
1368
  };
1223
- }, [e, w, i, t, a, h, l, s, d, c, u, g, f, n, o, r]), {};
1224
- }, Qs = ({ options: e, className: t, style: i, canvasProps: a }) => {
1225
- const { shapesRef: s, selectedShape: n, selectionFrame: o, hoveredShape: r, addShape: l, setSelectedShape: d, setSelectionFrame: h, refreshSelectedShapes: c, refreshHoveredShape: u, removeShape: g, updateShape: f, backwardShape: w, forwardShape: x, saveShapes: C, refs: b, width: k, height: v, settings: Q, setCanvasSize: V, setCanvasOffset: T, selectShape: D, activeTool: H, setActiveTool: Z, isInsideComponent: F, isEditMode: N, canvas: { withSkeleton: W, withFrameSelection: Y, canGrow: q, canShrink: L }, canvasOffsetStartData: m, setCanvasOffsetStartData: y, selectionMode: S, setSelectionMode: P } = a, { canvasBackgroundColor: z, canvasSelectionColor: M, canvasSelectionWidth: A } = { ...nn, ...e }, E = J(null), [_, te] = O(!1), [j, ne] = O(!1), B = R((U) => {
1226
- l(U), D(U);
1227
- }, [l, D]), se = R((U) => {
1228
- V({ realWidth: k, realHeight: v, width: U, height: v * U / k, scaleRatio: U / k });
1229
- }, [k, v, V]);
1230
- return Bn({ isInsideComponent: F, isEditingText: S.mode === "textedition", settings: Q, selectedShape: n, setSelectedShape: d, removeShape: g, pasteShape: B, updateShape: f, backwardShape: w, forwardShape: x, setShiftPressed: te, setAltPressed: ne, setActiveTool: Z, setSelectionMode: P, setSelectionFrame: h }), (({ onResized: U, element: ie }) => {
1231
- G(() => {
1232
- const he = ie.current;
1233
- if (!he) return;
1234
- const ge = new ResizeObserver((ae) => {
1235
- const Se = ae?.[0]?.borderBoxSize?.[0], { width: Ee, height: De } = Se ? { width: Se.inlineSize, height: Se.blockSize } : ae?.[0].contentRect ?? {};
1236
- U(Ee, De);
1369
+ }, [e, t, m, a, i, n, f, d, o, h, g, x, C, k, r, c, u, l, s, w]), {};
1370
+ }, gs = ({ options: e, className: t, style: i, canvasProps: a }) => {
1371
+ const { shapesRef: n, selectedShape: o, selectionFrame: r, hoveredShape: l, addShape: s, setSelectedShape: c, setSelectionFrame: u, refreshSelectedShapes: d, refreshHoveredShape: h, removeShape: f, updateShape: g, backwardShape: x, forwardShape: C, saveShapes: k, refs: w, width: m, height: y, settings: b, setCanvasSize: Z, setCanvasOffset: A, selectShapes: T, activeTool: S, setActiveTool: V, isInsideComponent: I, isInsideCanvas: N, isEditMode: H, canvas: { withSkeleton: D, withFrameSelection: U, canGrow: F, canShrink: X }, canvasOffsetStartData: p, setCanvasOffsetStartData: Q, selectionMode: M, setSelectionMode: L, setCanvasMoveAcceleration: P, isShiftPressed: E, isAltPressed: W, isSpacePressed: O, setShiftPressed: z, setAltPressed: ie, setCanvasZoom: re, resetZoom: R, setIsSpacePressed: oe } = a, { canvasBackgroundColor: G, canvasSelectionColor: le, canvasSelectionWidth: ae } = { ...In, ...e }, pe = te(null), se = B((q) => {
1372
+ s(q), T(q);
1373
+ }, [s, T]), ge = B((q) => {
1374
+ Z({ realWidth: m, realHeight: y, width: q, height: y * q / m, scaleRatio: q / m });
1375
+ }, [m, y, Z]);
1376
+ return Do({ isInsideComponent: I, isInsideCanvas: N, isEditingText: M.mode === "textedition", settings: b, selectedShape: o, setSelectedShape: c, removeShape: f, pasteShapes: se, updateShapes: g, backwardShape: x, forwardShape: C, setShiftPressed: z, setAltPressed: ie, setActiveTool: V, setSelectionMode: L, setSelectionFrame: u, setCanvasZoom: re, resetZoom: R, setIsSpacePressed: oe }), (({ onResized: q, element: he }) => {
1377
+ J(() => {
1378
+ const ce = he.current;
1379
+ if (!ce) return;
1380
+ const Ee = new ResizeObserver((Ie) => {
1381
+ const He = Ie?.[0]?.borderBoxSize?.[0], { width: ve, height: ne } = He ? { width: He.inlineSize, height: He.blockSize } : Ie?.[0]?.contentRect ?? {};
1382
+ ve !== void 0 && ne !== void 0 && q(ve, ne);
1237
1383
  });
1238
- return ge.observe(he), () => {
1239
- ge.unobserve(he);
1384
+ return Ee.observe(ce), () => {
1385
+ Ee.unobserve(ce);
1240
1386
  };
1241
- }, [ie, U]);
1242
- })({ element: E, onResized: se }), p("div", { ref: E, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": q, "data-shrink": L, style: { "--react-paint-app-row-width": Q.canvasSize.width, "--react-paint-app-canvaswidth": k, "--react-paint-app-canvasheight": v, "--react-paint-app-row-aspectratio": `calc(${Q.canvasSize.width} / ${Q.canvasSize.height})`, "--react-paint-app-canvas-bg": z, ...i }, children: p(Dn, { ref: b.canvas, canGrow: q, isInsideComponent: F, activeTool: H, setActiveTool: Z, canvasOffsetStartData: m, setCanvasOffsetStartData: y, shapes: s.current, addShape: l, updateSingleShape: f, selectedShape: n, selectionFrame: o, setSelectedShape: d, setSelectionFrame: h, hoveredShape: r, refreshHoveredShape: u, refreshSelectedShapes: c, settings: Q, setCanvasOffset: T, saveShapes: C, selectionMode: S, setSelectionMode: P, selectionColor: M, selectionWidth: A, isEditMode: N, isShiftPressed: _, isAltPressed: j, withFrameSelection: Y, withSkeleton: W }) });
1243
- }, Un = ({ isLoading: e = !1 }) => {
1244
- const [t, i] = O("hidden");
1245
- return G(() => {
1387
+ }, [he, q]);
1388
+ })({ element: pe, onResized: ge }), v("div", { ref: pe, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": F, "data-shrink": X, style: { "--react-paint-app-row-width": b.canvasSize.width, "--react-paint-app-canvaswidth": m, "--react-paint-app-canvasheight": y, "--react-paint-app-row-aspectratio": `calc(${b.canvasSize.width} / ${b.canvasSize.height})`, "--react-paint-app-canvas-bg": G, ...i }, children: v(Po, { isSpacePressed: O, ref: w.canvas, canGrow: F, isInsideComponent: I, activeTool: S, setActiveTool: V, canvasOffsetStartData: p, setCanvasOffsetStartData: Q, shapes: n.current, addShapes: s, updateSingleShape: g, selectedShape: o, selectionFrame: r, setSelectedShape: c, setSelectionFrame: u, hoveredShape: l, refreshHoveredShape: h, refreshSelectedShapes: d, settings: b, setCanvasOffset: A, saveShapes: k, selectionMode: M, setSelectionMode: L, setCanvasMoveAcceleration: P, selectionColor: le, selectionWidth: ae, isEditMode: H, isShiftPressed: E, isAltPressed: W, withFrameSelection: U, withSkeleton: D }) });
1389
+ }, Ro = ({ isLoading: e = !1 }) => {
1390
+ const [t, i] = $("hidden");
1391
+ return J(() => {
1246
1392
  if (!e) {
1247
1393
  i("fadeOut");
1248
1394
  const a = setTimeout(() => i("hidden"), 300);
@@ -1251,284 +1397,311 @@ const Ci = ({ ctx: e, path: t, rect: i, offset: a, checkFill: s }) => {
1251
1397
  };
1252
1398
  }
1253
1399
  i("visible");
1254
- }, [e]), t === "hidden" ? null : p("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": tn, "--react-paint-editor-loading-transition-duration": "300ms" }, children: I("div", { className: "react-paint-editor-loader", children: [p("div", {}), p("div", {}), p("div", {}), p("div", {})] }) });
1255
- }, Xn = "infos", Yn = 4e3, qn = ({ type: e, text: t, duration: i }) => {
1256
- const [a, s] = O(!1);
1257
- return G(() => {
1258
- const n = setTimeout(() => {
1259
- s(!0);
1260
- }, 100), o = setTimeout(() => {
1261
- s(!1);
1400
+ }, [e]), t === "hidden" ? null : v("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": An, "--react-paint-editor-loading-transition-duration": "300ms" }, children: Y("div", { className: "react-paint-editor-loader", children: [v("div", {}), v("div", {}), v("div", {}), v("div", {})] }) });
1401
+ }, Wo = "infos", Oo = 4e3, Fo = ({ type: e, text: t, duration: i }) => {
1402
+ const [a, n] = $(!1);
1403
+ return J(() => {
1404
+ const o = setTimeout(() => {
1405
+ n(!0);
1406
+ }, 100), r = setTimeout(() => {
1407
+ n(!1);
1262
1408
  }, i - 500 - 100);
1263
1409
  return () => {
1264
- clearTimeout(n), clearTimeout(o);
1410
+ clearTimeout(o), clearTimeout(r);
1265
1411
  };
1266
- }, [i]), p("div", { className: "react-paint-editor-snackbar", "data-is-shown": +a, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1267
- }, Gn = ({ snackbarList: e }) => p("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": an }, children: e.map((t) => p(qn, { ...t }, t.id)) }), X = ta.forwardRef((e, t) => {
1268
- if (e.type === "file" || e.type === "color") {
1269
- const { hidden: h = !1, disabled: c = !1, selected: u = !1, icon: g, children: f, className: w = "", title: x, onClick: C, ...b } = e;
1270
- return I("label", { className: `react-paint-editor-button ${w}`, title: x, onClick: C, "data-disabled": +c, "data-selected": +u, "data-hidden": +h, children: [p("input", { ref: t, disabled: c, ...b }), I("span", { className: "react-paint-editor-button-content", children: [f && p("span", { className: "react-paint-editor-button-children", children: f }), g && p("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: g } })] })] });
1271
- }
1272
- const { hidden: i = !1, disabled: a = !1, selected: s = !1, icon: n, children: o, type: r = "button", className: l = "", ...d } = e;
1273
- return p("button", { className: `react-paint-editor-button ${l}`, ref: t, disabled: a, "data-disabled": +a, "data-selected": +s, "data-hidden": +i, type: r, ...d, children: I("span", { className: "react-paint-editor-button-content", children: [o && p("span", { className: "react-paint-editor-button-children", children: o }), n && p("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: n } })] }) });
1274
- }), qe = ({ children: e, title: t = "", className: i = "", position: a = "bottom", fitContainer: s = !1, alignment: n = "center", style: o, ...r }) => I("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": s, "data-position": a, "data-alignment": n, style: { ...o, "--react-paint-editor-panel-zindex": da }, ...r, children: [t && p("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), _n = (e) => {
1412
+ }, [i]), v("div", { className: "react-paint-editor-snackbar", "data-is-shown": +a, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1413
+ }, Bo = ({ snackbarList: e }) => v("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": En }, children: e.map((t) => v(Fo, { ...t }, t.id)) }), $o = si.forwardRef((e, t) => {
1414
+ const { hidden: i = !1, disabled: a = !1, selected: n = !1, icon: o, children: r, className: l = "", title: s, onClick: c, ...u } = e, d = a ? -1 : 0, h = te(null);
1415
+ return xa(t, () => h.current), Y("label", { className: `react-paint-editor-button ${l}`, title: s, onClick: c, "data-disabled": +a, "data-selected": +n, "data-hidden": +i, tabIndex: d, onKeyDown: (f) => {
1416
+ f.key === Vt && (f.preventDefault(), f.stopPropagation());
1417
+ }, onKeyUp: (f) => {
1418
+ f.preventDefault(), f.stopPropagation(), f.key === Vt && h.current?.click();
1419
+ }, children: [v("input", { ref: h, disabled: a, ...u }), Y("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 } })] })] });
1420
+ }), K = si.forwardRef((e, t) => {
1421
+ if (e.type === "file" || e.type === "color") return v($o, { ...e, ref: t });
1422
+ const { hidden: i = !1, disabled: a = !1, selected: n = !1, icon: o, children: r, type: l = "button", className: s = "", ...c } = e;
1423
+ return v("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: a, "data-disabled": +a, "data-selected": +n, "data-hidden": +i, type: l, ...c, children: Y("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 } })] }) });
1424
+ }), tt = ({ children: e, title: t = "", className: i = "", position: a = "bottom", fitContainer: n = !1, alignment: o = "center", style: r, ...l }) => Y("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": n, "data-position": a, "data-alignment": o, style: { ...r, "--react-paint-editor-panel-zindex": Va }, ...l, children: [t && v("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), Yo = (e) => {
1275
1425
  switch (e) {
1276
1426
  case "brush":
1277
- return na;
1427
+ return Ca;
1278
1428
  case "line":
1279
- return ra;
1429
+ return Pa;
1280
1430
  case "polygon":
1281
- return Jt;
1431
+ return ci;
1282
1432
  case "curve":
1283
- return la;
1433
+ return La;
1284
1434
  case "rect":
1285
1435
  case "square":
1286
- return jt;
1436
+ return ri;
1287
1437
  case "circle":
1288
1438
  case "ellipse":
1289
- return Kt;
1439
+ return li;
1290
1440
  case "text":
1291
- return oa;
1441
+ return ka;
1292
1442
  case "picture":
1293
- return ei;
1443
+ return di;
1444
+ case "group":
1445
+ 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>';
1294
1446
  case "triangle":
1295
1447
  return "";
1296
1448
  }
1297
- }, jn = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: a, toggleShapeVisibility: s, toggleShapeLock: n, setLayoutDragging: o, handleRemove: r, handleSelect: l, onMoveShapes: d }) => {
1298
- const h = J(null), { isOver: c } = (({ disabled: u = !1, ref: g, shape: f, layoutDragging: w, setLayoutDragging: x, handleSelect: C, onMoveShapes: b }) => {
1299
- const [k, v] = O(!1);
1300
- return G(() => {
1301
- w || v(!1);
1302
- }, [w]), G(() => {
1303
- const Q = g.current;
1304
- if (!Q) return;
1305
- const V = () => {
1306
- x(void 0);
1307
- }, T = (N) => (N.preventDefault && N.preventDefault(), !1), D = (N) => {
1308
- C(f), N.dataTransfer && (N.dataTransfer.effectAllowed = "move", N.dataTransfer.setData("draggableShapeId", f.id), x(f.id));
1309
- }, H = () => {
1310
- w !== f.id && v(!0);
1311
- }, Z = () => {
1312
- v(!1);
1313
- }, F = (N) => (N.stopPropagation(), N.dataTransfer && b(N.dataTransfer.getData("draggableShapeId"), f.id), !1);
1314
- return u || (Q.addEventListener("dragstart", D), Q.addEventListener("dragend", V), Q.addEventListener("dragover", T), Q.addEventListener("dragenter", H), Q.addEventListener("dragleave", Z), Q.addEventListener("drop", F)), () => {
1315
- u || (Q.removeEventListener("dragstart", D), Q.removeEventListener("dragend", V), Q.removeEventListener("dragover", T), Q.removeEventListener("dragenter", H), Q.removeEventListener("dragleave", Z), Q.removeEventListener("drop", F));
1449
+ }, Uo = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: a, toggleShapeVisibility: n, toggleShapeLock: o, setLayoutDragging: r, handleRemove: l, handleSelect: s, onMoveShapes: c }) => {
1450
+ const u = te(null), { isOver: d } = (({ disabled: h = !1, ref: f, shape: g, layoutDragging: x, setLayoutDragging: C, handleSelect: k, onMoveShapes: w }) => {
1451
+ const [m, y] = $(!1);
1452
+ return J(() => {
1453
+ x || y(!1);
1454
+ }, [x]), J(() => {
1455
+ const b = f.current;
1456
+ if (!b) return;
1457
+ const Z = () => {
1458
+ C(void 0);
1459
+ }, A = (N) => (N.preventDefault && N.preventDefault(), !1), T = (N) => {
1460
+ k([g]), N.dataTransfer && (N.dataTransfer.effectAllowed = "move", N.dataTransfer.setData("draggableShapeId", g.id), C(g.id));
1461
+ }, S = () => {
1462
+ x !== g.id && y(!0);
1463
+ }, V = () => {
1464
+ y(!1);
1465
+ }, I = (N) => (N.stopPropagation(), N.dataTransfer && w(N.dataTransfer.getData("draggableShapeId"), g.id), !1);
1466
+ return h || (b.addEventListener("dragstart", T), b.addEventListener("dragend", Z), b.addEventListener("dragover", A), b.addEventListener("dragenter", S), b.addEventListener("dragleave", V), b.addEventListener("drop", I)), () => {
1467
+ h || (b.removeEventListener("dragstart", T), b.removeEventListener("dragend", Z), b.removeEventListener("dragover", A), b.removeEventListener("dragenter", S), b.removeEventListener("dragleave", V), b.removeEventListener("drop", I));
1316
1468
  };
1317
- }, [u, g, f, x, C, b, w]), { isOver: k };
1318
- })({ disabled: e, ref: h, shape: t, layoutDragging: a, setLayoutDragging: o, handleSelect: l, onMoveShapes: d });
1319
- return I("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(a === t.id), "data-is-over": +c, onClick: (u) => {
1320
- e || (u.preventDefault(), u.stopPropagation(), l(t));
1321
- }, "data-selected": +i, ref: h, tabIndex: -1, children: [p("span", { dangerouslySetInnerHTML: { __html: _n(t.type) } }), p("span", { children: t.id }), p("div", { className: "react-paint-editor-layouts-separator" }), p(X, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (u) => {
1322
- e || (u.preventDefault(), u.stopPropagation(), s(t));
1323
- }, 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>' }), p(X, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (u) => {
1324
- e || (u.preventDefault(), u.stopPropagation(), n(t));
1325
- }, 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>' }), p(X, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (u) => {
1326
- e || (u.preventDefault(), u.stopPropagation(), r(t));
1327
- }, icon: sa })] });
1328
- }, Kn = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: a, removeShape: s, toggleShapeVisibility: n, toggleShapeLock: o, selectedShape: r, moveShapes: l, selectShape: d, isLayoutPanelShown: h }) => {
1329
- const [c, u] = O(void 0), g = !i.features.edition;
1330
- return h ? p(qe, { alignment: "right", className: "react-paint-editor-layouts-panel", children: p("div", { className: "react-paint-editor-layouts-panel-content", children: I("div", { className: "react-paint-editor-layouts-scrolling-content", children: [I("div", { className: "react-paint-editor-layouts-row", children: [p("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), p(X, { 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: g, onClick: () => t("none") }), ["small", "medium", "large"].map((f) => p(X, { className: "react-paint-editor-layouts-grid-button", selected: e === f, disabled: g, onClick: () => t(f), children: f.charAt(0).toUpperCase() }, f))] }), p("hr", {}), p("div", { className: "react-paint-editor-layouts", children: a.length === 0 ? p("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : a.map((f) => p(jn, { shape: f, disabled: g, layoutDragging: c, setLayoutDragging: u, selected: r?.id === f.id, handleSelect: d, handleRemove: s, onMoveShapes: l, toggleShapeVisibility: n, toggleShapeLock: o }, f.id)) })] }) }) }) : null;
1331
- }, Zt = ({ children: e, onClose: t, position: i = "center", title: a, className: s = "" }) => I("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": da }, role: "dialog", "aria-modal": "true", "aria-labelledby": a, children: [p("div", { className: "react-paint-editor-modal-mask", onClick: t }), p("div", { className: `react-paint-editor-modal-panel ${s}`, children: e })] }), yt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: a = "fill", disabled: s = !1, values: n, field: o, value: r = "", valueChanged: l }) => {
1332
- const [d] = O(de("settings_")), h = e === d;
1333
- return n.length ? I(Ce, { children: [p(X, { selected: h, title: i, disabled: s, onClick: () => {
1334
- t((c) => c === d ? void 0 : d);
1335
- }, icon: r === "transparent" ? a === "fill" ? fi : gi : void 0, children: r !== "transparent" && p("div", { className: "react-paint-editor-colorfield-color", "data-mode": a, style: { "--react-paint-editor-colorfield-color-value": r } }) }), h && p(qe, { title: i, alignment: "left", children: I("div", { className: "react-paint-editor-colorfield-wrapper", children: [n.map((c) => p(X, { title: c, selected: c === r, color: c, icon: c === "transparent" ? a === "fill" ? fi : gi : void 0, onClick: () => {
1336
- l(o, c);
1337
- }, children: c !== "transparent" && p("div", { className: "react-paint-editor-colorfield-color", color: c, "data-mode": a, style: { "--react-paint-editor-colorfield-color-value": c } }) }, c)), p(X, { type: "color", title: "Custom color", selected: !n.includes(r), value: r, onChange: (c) => {
1338
- const u = +c.target.value;
1339
- l(o, Number.isNaN(u) ? c.target.value : u);
1340
- }, children: p("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": n.includes(r) ? "var(--react-paint-editor-app-font-color)" : r }, children: p("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;
1341
- }, Jn = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => p(X, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1342
- i(t);
1343
- }, icon: sa }), Tt = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: a = "Choisissez l'option", disabled: s = !1, field: n, icon: o, values: r, defaultValue: l, valueChanged: d }) => {
1344
- const [h] = O(de("settings_")), c = t === h;
1345
- return r.length ? I(Ce, { children: [p(X, { selected: c, title: a, icon: o, disabled: s, onClick: () => {
1346
- i((u) => u === h ? void 0 : h);
1347
- } }), c && p(qe, { title: a, alignment: "left", fitContainer: !0, children: p("div", { className: "react-paint-editor-selectfield-wrapper", children: r.map((u) => p(X, { title: `${u}`, onClick: () => ((g) => {
1348
- d(n, g);
1349
- })(u), selected: l === u, style: { "--react-paint-editor-button-padding": "16px" }, children: p(e, { children: u }) }, u)) }) })] }) : null;
1350
- }, es = ({ children: e }) => p("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), Gi = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: s, valueChanged: n }) => a.length ? p(Tt, { selectedSettings: e, setSelectedSettings: t, CustomOption: es, 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: a, defaultValue: s, valueChanged: n }) : null, ts = ({ disabled: e, toggleLayoutPanel: t }) => p(X, { 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" }), is = ({ children: e }) => I("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [p("span", { className: "react-paint-editor-linearrow-left" }), p("span", { className: "react-paint-editor-linearrow-right" })] }), _i = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: s, valueChanged: n }) => a.length ? p(Tt, { selectedSettings: e, setSelectedSettings: t, CustomOption: is, 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: a, defaultValue: s, valueChanged: n }) : null, as = ({ children: e }) => I("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [p("span", {}), p("span", {}), p("span", {}), p("span", {}), p("span", {}), p("span", {}), p("span", {})] }), ji = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: s, valueChanged: n }) => a.length ? p(Tt, { selectedSettings: e, setSelectedSettings: t, CustomOption: as, 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: a, defaultValue: s, valueChanged: n }) : null, Qt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: a, disabled: s = !1, field: n, value: o = 1, min: r = 1, max: l = 20, step: d = 1, unity: h = "", valueChanged: c }) => {
1351
- const u = Math.round(o), [g] = O(de("settings_")), f = J(null);
1352
- G(() => () => {
1353
- f.current && clearTimeout(f.current);
1354
- }, []);
1355
- const w = e === g;
1356
- return r === l ? null : I(Ce, { children: [p(X, { selected: w, title: i, disabled: s, icon: a, onClick: () => {
1357
- t((x) => x === g ? void 0 : g);
1358
- } }), w && p(qe, { title: i, alignment: "left", fitContainer: !0, children: p("div", { children: I("label", { className: "react-paint-editor-rangefield", children: [p("input", { type: "range", min: r, max: l, step: d, value: o, onChange: (x) => {
1359
- const C = +x.target.value;
1360
- c(n, Number.isNaN(C) ? x.target.value : C, !1), f.current && clearTimeout(f.current), f.current = setTimeout(() => {
1361
- c(n, Number.isNaN(C) ? x.target.value : C, !0);
1362
- }, 1e3);
1363
- } }), I("span", { children: [u, h] })] }) }) })] });
1364
- }, ns = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => p(X, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: ca, className: t ? ` ${t}` : "" }), St = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: a, values: s, value: n = !1, valueChanged: o }) => {
1365
- const [r] = O(de("settings_"));
1366
- return s.length !== 2 ? null : p(X, { onClick: () => {
1367
- e((l) => l === r ? void 0 : r), o(i, !n);
1368
- }, selected: n, disabled: t, icon: a });
1369
- }, ss = ({ children: e }) => p("span", { children: e === 0 ? "Non" : "Oui" }), os = [0, 1], Ki = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: a, valueChanged: s }) => p(Tt, { selectedSettings: e, setSelectedSettings: t, CustomOption: ss, title: "Fermer les points", icon: Jt, disabled: i, field: "closedPoints", values: os, defaultValue: a, valueChanged: s }), Bt = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: a, selectedSettings: s, setSelectedSettings: n, handleShapeStyleChange: o, handleShapeFontFamilyChange: r }) => t ? i && I(Ce, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && p(yt, { selectedSettings: s, setSelectedSettings: n, title: "Couleur du trait", mode: "stroke", disabled: a, field: "strokeColor", value: t.style?.strokeColor, valueChanged: o, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && p(yt, { selectedSettings: s, setSelectedSettings: n, title: "Couleur de fond", disabled: a, field: "fillColor", value: t.style?.fillColor, valueChanged: o, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && p(Qt, { selectedSettings: s, setSelectedSettings: n, title: "Epaisseur du trait", icon: pi, disabled: a, field: "lineWidth", value: t.style?.lineWidth, valueChanged: o, 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 && p(ji, { selectedSettings: s, setSelectedSettings: n, disabled: a, defaultValue: t.style?.lineDash, valueChanged: o, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && p(_i, { selectedSettings: s, setSelectedSettings: n, disabled: a, defaultValue: t.style?.lineArrow, valueChanged: o, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && p(Ki, { selectedSettings: s, setSelectedSettings: n, disabled: a, valueChanged: o, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && p(Gi, { selectedSettings: s, setSelectedSettings: n, disabled: a, valueChanged: r, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && p(St, { setSelectedSettings: n, disabled: a, field: "fontBold", icon: hi, valueChanged: r, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && p(St, { setSelectedSettings: n, disabled: a, field: "fontItalic", icon: ui, valueChanged: r, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && p(Qt, { selectedSettings: s, setSelectedSettings: n, title: "Opacité", icon: di, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: a, field: "opacity", value: t.style?.opacity ?? 100, valueChanged: o })] }) : "settings" in e ? I(Ce, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && p(yt, { selectedSettings: s, setSelectedSettings: n, title: "Couleur du trait", mode: "stroke", disabled: a, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: o, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && p(yt, { selectedSettings: s, setSelectedSettings: n, title: "Couleur de fond", disabled: a, field: "fillColor", value: e.settings.fillColor.default, valueChanged: o, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && p(Qt, { selectedSettings: s, setSelectedSettings: n, title: "Epaisseur du trait", disabled: a, field: "lineWidth", icon: pi, value: e.settings.lineWidth.default, valueChanged: o, 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 && p(ji, { selectedSettings: s, setSelectedSettings: n, disabled: a, defaultValue: e.settings.lineDash.default, valueChanged: o, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && p(_i, { selectedSettings: s, setSelectedSettings: n, disabled: a, defaultValue: e.settings.lineArrow.default, valueChanged: o, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && p(Ki, { selectedSettings: s, setSelectedSettings: n, disabled: a, valueChanged: o, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && p(Gi, { selectedSettings: s, setSelectedSettings: n, disabled: a, valueChanged: r, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && p(St, { setSelectedSettings: n, disabled: a, field: "fontBold", icon: hi, valueChanged: r, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && p(St, { setSelectedSettings: n, disabled: a, field: "fontItalic", icon: ui, valueChanged: r, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && p(Qt, { selectedSettings: s, setSelectedSettings: n, title: "Opacité", icon: di, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: a, field: "opacity", value: e.settings.opacity.default, valueChanged: o })] }) : null, rs = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: a = !1, toggleLayoutPanel: s, activeTool: n, selectedShape: o, canvas: r, settings: l, updateShape: d, removeShape: h, isZoomPanelShown: c, setIsZoomPanelShown: u }) => {
1370
- const [g, f] = O(void 0), [w, x] = O(!1), C = l.size === "infinite" || l.features.zoom, b = !l.features.edition, k = () => {
1371
- x((H) => !H);
1372
- }, v = o ? t.find((H) => H.id === o.toolId) || t.find((H) => H.type === o.type) : void 0, Q = (v ? Object.keys(v.settings).length + 1 : "settings" in n ? Object.keys(n.settings).length : 0) + +a + +C, V = e < 40 * Q, T = (H, Z, F = !0) => {
1373
- o ? (d(et(Qe(["style", H], Z, o), l), F), v && i(v.id, H, Z)) : i(n.id, H, Z);
1374
- }, D = (H, Z) => {
1375
- if (o) {
1376
- if (o.type !== "text") return;
1377
- const F = r?.getContext("2d");
1378
- if (!F) return;
1379
- const N = Qe(["style", H], Z, o), W = si(F, N.value, N.width, N.style?.fontBold ?? !1, N.style?.fontItalic ?? !1, N.style?.fontFamily), Y = et({ ...N, fontSize: W, height: W * N.value.length }, l);
1380
- d(Y, !0), v && i(v.id, H, Z);
1381
- } else i(n.id, H, Z);
1469
+ }, [h, f, g, C, k, w, x]), { isOver: m };
1470
+ })({ disabled: e, ref: u, shape: t, layoutDragging: a, setLayoutDragging: r, handleSelect: s, onMoveShapes: c });
1471
+ return Y("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(a === t.id), "data-is-over": +d, onClick: (h) => {
1472
+ e || (h.preventDefault(), h.stopPropagation(), s([t]));
1473
+ }, "data-selected": +i, ref: u, tabIndex: -1, children: [v("span", { dangerouslySetInnerHTML: { __html: Yo(t.type) } }), v("span", { children: t.id }), v("div", { className: "react-paint-editor-layouts-separator" }), v(K, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (h) => {
1474
+ e || (h.preventDefault(), h.stopPropagation(), n([t]));
1475
+ }, 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(K, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (h) => {
1476
+ e || (h.preventDefault(), h.stopPropagation(), o([t]));
1477
+ }, 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(K, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (h) => {
1478
+ e || (h.preventDefault(), h.stopPropagation(), l([t]));
1479
+ }, icon: Ma })] });
1480
+ }, Xo = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: a, removeShape: n, toggleShapeVisibility: o, toggleShapeLock: r, selectedShapes: l, moveShapes: s, selectShapes: c, isLayoutPanelShown: u }) => {
1481
+ const [d, h] = $(void 0), f = !i.features.edition;
1482
+ return u ? v(tt, { alignment: "right", className: "react-paint-editor-layouts-panel", children: v("div", { className: "react-paint-editor-layouts-panel-content", children: Y("div", { className: "react-paint-editor-layouts-scrolling-content", children: [Y("div", { className: "react-paint-editor-layouts-row", children: [v("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), v(K, { 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: f, onClick: () => t("none") }), ["small", "medium", "large"].map((g) => v(K, { className: "react-paint-editor-layouts-grid-button", selected: e === g, disabled: f, onClick: () => t(g), children: g.charAt(0).toUpperCase() }, g))] }), v("hr", {}), v("div", { className: "react-paint-editor-layouts", children: a.length === 0 ? v("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : a.map((g) => v(Uo, { shape: g, disabled: f, layoutDragging: d, setLayoutDragging: h, selected: j(l).some((x) => x.id === g.id) ?? !1, handleSelect: c, handleRemove: n, onMoveShapes: s, toggleShapeVisibility: o, toggleShapeLock: r }, g.id)) })] }) }) }) : null;
1483
+ }, Nt = ({ children: e, onClose: t, position: i = "center", title: a, className: n = "" }) => Y("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": Va }, role: "dialog", "aria-modal": "true", "aria-labelledby": a, children: [v("div", { className: "react-paint-editor-modal-mask", onClick: t }), v("div", { className: `react-paint-editor-modal-panel ${n}`, children: e })] }), wt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: a = "fill", disabled: n = !1, values: o, field: r, value: l = "", valueChanged: s }) => {
1484
+ const [c] = $(ye("settings_")), u = e === c;
1485
+ return o.length ? Y(Ve, { children: [v(K, { selected: u, title: i, disabled: n, onClick: () => {
1486
+ t((d) => d === c ? void 0 : c);
1487
+ }, icon: l === "transparent" ? a === "fill" ? zi : Ti : void 0, children: l !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", "data-mode": a, style: { "--react-paint-editor-colorfield-color-value": l } }) }), u && v(tt, { title: i, alignment: "left", children: Y("div", { className: "react-paint-editor-colorfield-wrapper", children: [o.map((d) => v(K, { title: d, selected: d === l, color: d, icon: d === "transparent" ? a === "fill" ? zi : Ti : void 0, onClick: () => {
1488
+ s(r, d);
1489
+ }, children: d !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", color: d, "data-mode": a, style: { "--react-paint-editor-colorfield-color-value": d } }) }, d)), v(K, { type: "color", title: "Custom color", selected: l !== "" && !o.includes(l), value: l, onChange: (d) => {
1490
+ const h = +d.target.value;
1491
+ s(r, Number.isNaN(h) ? d.target.value : h);
1492
+ }, 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;
1493
+ }, Go = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => v(K, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1494
+ i(j(t));
1495
+ }, icon: Ma }), Dt = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: a = "Choisissez l'option", disabled: n = !1, field: o, icon: r, values: l, defaultValue: s, valueChanged: c }) => {
1496
+ const [u] = $(ye("settings_")), d = t === u;
1497
+ return l.length ? Y(Ve, { children: [v(K, { selected: d, title: a, icon: r, disabled: n, onClick: () => {
1498
+ i((h) => h === u ? void 0 : u);
1499
+ } }), d && v(tt, { title: a, alignment: "left", fitContainer: !0, children: v("div", { className: "react-paint-editor-selectfield-wrapper", children: l.map((h) => v(K, { title: `${h}`, onClick: () => ((f) => {
1500
+ c(o, f);
1501
+ })(h), selected: s === h, style: { "--react-paint-editor-button-padding": "16px" }, children: v(e, { children: h }) }, h)) }) })] }) : null;
1502
+ }, qo = ({ children: e }) => v("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), va = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: n, valueChanged: o }) => a.length ? v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: qo, 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: a, defaultValue: n, valueChanged: o }) : null, _o = ({ disabled: e, toggleLayoutPanel: t }) => v(K, { 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" }), jo = ({ children: e }) => Y("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" })] }), fa = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: n, valueChanged: o }) => a.length ? v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: jo, 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: a, defaultValue: n, valueChanged: o }) : null, Ko = ({ children: e }) => Y("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", {})] }), ma = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: n, valueChanged: o }) => a.length ? v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ko, 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: a, defaultValue: n, valueChanged: o }) : null, Ct = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: a, disabled: n = !1, field: o, value: r, min: l = 1, max: s = 20, step: c = 1, unity: u = "", valueChanged: d }) => {
1503
+ const h = r === void 0, f = h ? "N/A" : `${Math.round(r)}${u}`, [g] = $(ye("settings_")), x = ((k, w = 500) => {
1504
+ const m = te(null), y = B((...b) => {
1505
+ m.current && clearTimeout(m.current), m.current = setTimeout(() => k(...b), w);
1506
+ }, [k, w]);
1507
+ return J(() => () => {
1508
+ m.current && clearTimeout(m.current);
1509
+ }, []), y;
1510
+ })(d), C = e === g;
1511
+ return l === s ? null : Y(Ve, { children: [v(K, { selected: C, title: i, disabled: n, icon: a, onClick: () => {
1512
+ t((k) => k === g ? void 0 : g);
1513
+ } }), C && v(tt, { title: i, alignment: "left", fitContainer: !0, children: v("div", { children: Y("label", { className: "react-paint-editor-rangefield", children: [v("input", { type: "range", min: l, max: s, step: c, value: r ?? (s + l) / 2, "data-indeterminate": +h, onChange: (k) => {
1514
+ const w = +k.target.value, m = Number.isNaN(w) ? k.target.value : w;
1515
+ d(o, m, !1), x(o, m, !0);
1516
+ } }), v("span", { children: f })] }) }) })] });
1517
+ }, Jo = ({ children: e }) => v("span", { children: e === 0 ? "Non" : "Oui" }), es = [0, 1], ya = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: a, valueChanged: n }) => v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: Jo, title: "Fermer les points", icon: ci, disabled: i, field: "closedPoints", values: es, defaultValue: a, valueChanged: n }), ts = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => v(K, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: Za, className: t ? ` ${t}` : "" }), Mt = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: a, values: n, value: o = !1, valueChanged: r }) => {
1518
+ const [l] = $(ye("settings_"));
1519
+ return n.length !== 2 ? null : v(K, { onClick: () => {
1520
+ e((s) => s === l ? void 0 : l), r(i, !o);
1521
+ }, selected: o, disabled: t, icon: a });
1522
+ }, Kt = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: a, selectedSettings: n, setSelectedSettings: o, handleShapeStyleChange: r, handleShapeFontFamilyChange: l }) => t ? i && Y(Ve, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: a, field: "strokeColor", value: t.style?.strokeColor, valueChanged: r, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur de fond", disabled: a, field: "fillColor", value: t.style?.fillColor, valueChanged: r, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Epaisseur du trait", icon: Hi, disabled: a, field: "lineWidth", value: t.style?.lineWidth, valueChanged: r, 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(ma, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: t.style?.lineDash, valueChanged: r, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && v(fa, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: t.style?.lineArrow, valueChanged: r, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && v(ya, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: r, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && v(va, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: l, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontBold", icon: Zi, valueChanged: l, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontItalic", icon: Vi, valueChanged: l, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Opacité", icon: Li, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: a, field: "opacity", value: t.style?.opacity, valueChanged: r })] }) : "settings" in e ? Y(Ve, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: a, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: r, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur de fond", disabled: a, field: "fillColor", value: e.settings.fillColor.default, valueChanged: r, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Epaisseur du trait", disabled: a, field: "lineWidth", icon: Hi, value: e.settings.lineWidth.default, valueChanged: r, 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(ma, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: e.settings.lineDash.default, valueChanged: r, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && v(fa, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: e.settings.lineArrow.default, valueChanged: r, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && v(ya, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: r, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && v(va, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: l, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontBold", icon: Zi, valueChanged: l, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontItalic", icon: Vi, valueChanged: l, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Opacité", icon: Li, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: a, field: "opacity", value: e.settings.opacity.default, valueChanged: r })] }) : null, is = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: a = !1, toggleLayoutPanel: n, activeTool: o, selectedShape: r, canvas: l, settings: s, updateShape: c, removeShape: u, isZoomPanelShown: d, setIsZoomPanelShown: h }) => {
1523
+ const [f, g] = $(void 0), [x, C] = $(!1), k = s.size === "infinite" || s.features.zoom, w = !s.features.edition, m = () => {
1524
+ C((S) => !S);
1525
+ }, y = ((S, V) => {
1526
+ const I = j(S).map((H) => V.find((D) => D.id === H?.toolId) || V.find((D) => D.type === H?.type)).filter((H) => H !== void 0);
1527
+ if (!I.length) return;
1528
+ if (I.length === 1) return I[0];
1529
+ const N = I.slice(1).reduce((H, D) => {
1530
+ const U = {};
1531
+ for (const F in D.settings) {
1532
+ if (H[F] === void 0 || D.settings[F]?.hidden || H[F]?.hidden) continue;
1533
+ const X = H[F], p = D.settings[F], Q = {};
1534
+ "min" in p && "min" in X && p.min === X.min && "max" in p && "max" in X && p.max === X.max && "step" in p && "step" in X && p.step === X.step && (Q.min = p.min, Q.max = p.max, Q.step = p.step), "values" in p && "values" in X && p.values?.join(",") === X.values?.join(",") && (Q.values = p.values), (Object.keys(Q).length > 0 || F === "closedPoints") && (U[F] = Q);
1535
+ }
1536
+ return U;
1537
+ }, I[0].settings);
1538
+ return { id: I.map((H) => H.id).join("-"), icon: "", label: "group", type: "group", settings: N };
1539
+ })(r, t), b = (y ? Object.keys(y.settings).length + 1 : "settings" in o ? Object.keys(o.settings).length : 0) + +a + +k, Z = e < 40 * b, A = (S, V, I = !0) => {
1540
+ if (j(r).length) {
1541
+ const N = j(r).map((H) => dt(Pe(["style", S], V, H), s));
1542
+ c(N, I), y && i(y.id, S, V);
1543
+ } else i(o.id, S, V);
1544
+ }, T = (S, V) => {
1545
+ if (j(r).length) {
1546
+ const I = j(r).map((N) => {
1547
+ if (N.type !== "text") return N;
1548
+ const H = l?.getContext("2d");
1549
+ if (!H) return N;
1550
+ const D = Pe(["style", S], V, N), U = Si(H, D.value, D.width, D.style?.fontBold ?? !1, D.style?.fontItalic ?? !1, D.style?.fontFamily);
1551
+ return dt({ ...D, fontSize: U, height: U * D.value.length }, s);
1552
+ });
1553
+ c(I, !0), y && i(y.id, S, V);
1554
+ } else i(o.id, S, V);
1382
1555
  };
1383
- return I(Ce, { children: [I("div", { className: "react-paint-editor-settings-bar", children: [I("div", { className: "react-paint-editor-settings-shrinkable", children: [C && p(ns, { className: c ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1384
- u((H) => !H);
1385
- } }), V && Q > 2 && p(X, { disabled: b, onClick: k, 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>' }), o ? v && I(Ce, { children: [!V && p(Bt, { activeTool: n, selectedShape: o, selectedShapeTool: v, disabled: b, selectedSettings: g, setSelectedSettings: f, handleShapeStyleChange: T, handleShapeFontFamilyChange: D }), n.type === "selection" && p(Jn, { disabled: b, selectedShape: o, removeShape: h })] }) : !V && p(Bt, { activeTool: n, selectedShape: o, selectedShapeTool: v, disabled: b, selectedSettings: g, setSelectedSettings: f, handleShapeStyleChange: T, handleShapeFontFamilyChange: D })] }), p("div", { className: "react-paint-editor-settings-separator" }), a && p(ts, { disabled: b, toggleLayoutPanel: s })] }), w && p(Zt, { className: "react-paint-editor-settings-modal", onClose: k, position: "bottom", title: "Settings", children: p(Bt, { activeTool: n, selectedShape: o, selectedShapeTool: v, disabled: b, selectedSettings: g, setSelectedSettings: f, handleShapeStyleChange: T, handleShapeFontFamilyChange: D }) })] });
1386
- }, Ji = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: a, img: s, accept: n }) => {
1387
- const o = J(null);
1388
- return p(X, { ref: o, type: "file", onClick: (r) => {
1389
- r.stopPropagation(), o.current && (o.current.value = "");
1390
- }, onChange: (r) => {
1391
- const l = r.target.files?.item(0);
1392
- l && i(l);
1393
- }, accept: n, title: a.label ?? a.type, icon: s, disabled: e, children: t ? a.label : void 0 });
1394
- }, ye = ({ type: e, img: t, isActive: i, withText: a = !1, disabled: s = !1, setActive: n }) => p(X, { disabled: s, selected: i, onClick: () => {
1395
- n(e);
1396
- }, title: e.label ?? e.type, icon: t, children: a ? e.label : void 0 }), ls = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: a = !1, hasActionToClear: s = !1, undoAction: n, redoAction: o, clearCanvas: r, alignment: l, group: d, vertical: h = !1, disabled: c = !1, withLoadAndSave: u, withExport: g, addPicture: f, loadFile: w, togglePictureUrlModal: x, saveFile: C, toggleExportModal: b, withUploadPicture: k, withUrlPicture: v }) => {
1397
- const [Q, V] = O(!1), [, T] = aa(), D = d?.tools?.some((Z) => Z === e.type), H = (D ? e.icon : d.img) ?? d.title;
1398
- return G(() => {
1399
- if (!Q) return;
1400
- const Z = () => {
1401
- V(!1);
1556
+ return Y(Ve, { children: [Y("div", { className: "react-paint-editor-settings-bar", children: [Y("div", { className: "react-paint-editor-settings-shrinkable", children: [k && v(ts, { className: d ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1557
+ h((S) => !S);
1558
+ } }), Z && b > 2 && v(K, { disabled: w, onClick: m, 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>' }), r ? y && Y(Ve, { children: [!Z && v(Kt, { activeTool: o, selectedShape: r, selectedShapeTool: y, disabled: w, selectedSettings: f, setSelectedSettings: g, handleShapeStyleChange: A, handleShapeFontFamilyChange: T }), o.type === "selection" && v(Go, { disabled: w, selectedShape: r, removeShape: u })] }) : !Z && v(Kt, { activeTool: o, selectedShape: r, selectedShapeTool: y, disabled: w, selectedSettings: f, setSelectedSettings: g, handleShapeStyleChange: A, handleShapeFontFamilyChange: T })] }), v("div", { className: "react-paint-editor-settings-separator" }), a && v(_o, { disabled: w, toggleLayoutPanel: n })] }), x && v(Nt, { className: "react-paint-editor-settings-modal", onClose: m, position: "bottom", title: "Settings", children: v(Kt, { activeTool: o, selectedShape: r, selectedShapeTool: y, disabled: w, selectedSettings: f, setSelectedSettings: g, handleShapeStyleChange: A, handleShapeFontFamilyChange: T }) })] });
1559
+ }, Sa = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: a, img: n, accept: o }) => {
1560
+ const r = te(null);
1561
+ return v(K, { ref: r, type: "file", onClick: (l) => {
1562
+ l.stopPropagation(), r.current && (r.current.value = "");
1563
+ }, onChange: (l) => {
1564
+ const s = l.target.files?.item(0);
1565
+ s && i(s);
1566
+ }, accept: o, title: a.label ?? a.type, icon: n, disabled: e, children: t ? a.label : void 0 });
1567
+ }, ke = ({ type: e, img: t, isActive: i, withText: a = !1, disabled: n = !1, setActive: o }) => v(K, { disabled: n, selected: i, onClick: () => {
1568
+ o(e);
1569
+ }, title: e.label ?? e.type, icon: t, children: a ? e.label : void 0 }), as = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: a = !1, hasActionToClear: n = !1, undoAction: o, redoAction: r, clearCanvas: l, alignment: s, group: c, vertical: u = !1, disabled: d = !1, withLoadAndSave: h, withExport: f, addPicture: g, loadFile: x, togglePictureUrlModal: C, saveFile: k, toggleExportModal: w, withUploadPicture: m, withUrlPicture: y }) => {
1570
+ const [b, Z] = $(!1), [, A] = wa(), T = c?.tools?.some((V) => V === e.type), S = (T ? e.icon : c.img) ?? c.title;
1571
+ return J(() => {
1572
+ if (!b) return;
1573
+ const V = () => {
1574
+ Z(!1);
1402
1575
  };
1403
- return document.addEventListener("click", Z), () => {
1404
- document.removeEventListener("click", Z);
1576
+ return document.addEventListener("click", V), () => {
1577
+ document.removeEventListener("click", V);
1405
1578
  };
1406
- }, [Q]), t || k || v || u || g ? I("div", { className: "react-paint-editor-toolbox-relative", children: [p(X, { selected: D, title: d.title, disabled: c, onClick: () => {
1407
- T(() => {
1408
- V(!0);
1579
+ }, [b]), t || m || y || h || f ? Y("div", { className: "react-paint-editor-toolbox-relative", children: [v(K, { selected: T, title: c.title, disabled: d, onClick: () => {
1580
+ A(() => {
1581
+ Z(!0);
1409
1582
  });
1410
- }, icon: H }), Q && p(qe, { alignment: l, position: "top", children: I("div", { className: "react-paint-editor-toolbox-panel-content", "data-vertical": +h, children: [t && I(Ce, { children: [p(ye, { withText: !0, type: je, disabled: c || !i, img: je.icon, isActive: e.id === je.id, setActive: n }), p(ye, { withText: !0, type: Ke, disabled: c || !a, img: Ke.icon, isActive: e.id === Ke.id, setActive: o }), p(ye, { withText: !0, type: Je, disabled: c || !s, img: Je.icon, isActive: e.id === Je.id, setActive: r }), (k || v || u) && p("hr", {})] }), k && p(Ji, { withText: !0, type: yi, disabled: c, loadFile: async (Z) => {
1411
- V(!1), await f(Z);
1412
- }, img: yi.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), v && p(X, { disabled: c, selected: !1, onClick: x, 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" }), (k || v) && u && p("hr", {}), u && I(Ce, { children: [p(Ji, { withText: !0, type: mi, disabled: c, loadFile: (Z) => {
1413
- V(!1), w(Z);
1414
- }, img: mi.icon, accept: "application/JSON" }), p(ye, { withText: !0, disabled: c, type: Nt, img: Nt.icon, isActive: e.id === Nt.id, setActive: C })] }), g && p(ye, { withText: !0, disabled: c, type: Wt, img: Wt.icon, isActive: e.id === Wt.id, setActive: b })] }) })] }) : null;
1415
- }, cs = ({ togglePictureUrlModal: e, addPicture: t }) => {
1416
- const i = J(null);
1417
- return G(() => {
1583
+ }, icon: S }), b && v(tt, { alignment: s, position: "top", children: Y("div", { className: "react-paint-editor-toolbox-panel-content", "data-vertical": +u, children: [t && Y(Ve, { children: [v(ke, { withText: !0, type: rt, disabled: d || !i, img: rt.icon, isActive: e.id === rt.id, setActive: o }), v(ke, { withText: !0, type: lt, disabled: d || !a, img: lt.icon, isActive: e.id === lt.id, setActive: r }), v(ke, { withText: !0, type: ct, disabled: d || !n, img: ct.icon, isActive: e.id === ct.id, setActive: l }), (m || y || h) && v("hr", {})] }), m && v(Sa, { withText: !0, type: Ii, disabled: d, loadFile: async (V) => {
1584
+ Z(!1), await g(V);
1585
+ }, img: Ii.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), y && v(K, { disabled: d, selected: !1, onClick: C, 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" }), (m || y) && h && v("hr", {}), h && Y(Ve, { children: [v(Sa, { withText: !0, type: Ei, disabled: d, loadFile: (V) => {
1586
+ Z(!1), x(V);
1587
+ }, img: Ei.icon, accept: "application/JSON" }), v(ke, { withText: !0, disabled: d, type: Ut, img: Ut.icon, isActive: e.id === Ut.id, setActive: k })] }), f && v(ke, { withText: !0, disabled: d, type: Yt, img: Yt.icon, isActive: e.id === Yt.id, setActive: w })] }) })] }) : null;
1588
+ }, ns = ({ togglePictureUrlModal: e, addPicture: t }) => {
1589
+ const i = te(null);
1590
+ return J(() => {
1418
1591
  i.current && i.current.focus();
1419
- }, []), p(Zt, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: I("form", { onSubmit: async (a) => {
1592
+ }, []), v(Nt, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: Y("form", { onSubmit: async (a) => {
1420
1593
  a.preventDefault();
1421
- const s = i.current?.value;
1422
- s && (await t(s), e());
1423
- }, children: [I("label", { children: ["URL ", p("input", { type: "text", ref: i })] }), p(X, { onClick: e, children: "Annuler" }), p(X, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1424
- }, ea = "Choose export settings", ds = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1594
+ const n = i.current?.value;
1595
+ n && (await t(n), e());
1596
+ }, children: [Y("label", { children: ["URL ", v("input", { type: "text", ref: i })] }), v(K, { onClick: e, children: "Annuler" }), v(K, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1597
+ }, Qa = "Choose export settings", os = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1425
1598
  const i = async (a) => {
1426
1599
  t(a), e();
1427
1600
  };
1428
- return I(Zt, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: ea, children: [p("h3", { children: ea }), p("hr", {}), p(X, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), p(X, { onClick: () => i("defaultView"), children: "Exporter le canvas entier" }), p(X, { onClick: () => i("fitToShapes"), children: "Exporter dans les limites du dessin" }), p(X, { selected: !0, onClick: e, children: "Annuler" })] });
1429
- }, hs = ({ activeTool: e, alignment: t, group: i, disabled: a = !1, setActiveToolFromId: s }) => {
1430
- const n = J(null), [o, r] = O(!1), [, l] = aa(), [d, h] = O(void 0), c = (f) => {
1431
- h(f), s(f.id);
1601
+ return Y(Nt, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Qa, children: [v("h3", { children: Qa }), v("hr", {}), v(K, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), v(K, { onClick: () => i("defaultView"), children: "Exporter le canevas par défaut" }), v(K, { onClick: () => i("fitToShapes"), children: "Exporter le dessin entier" }), v(K, { selected: !0, onClick: e, children: "Annuler" })] });
1602
+ }, ss = ({ activeTool: e, alignment: t, group: i, disabled: a = !1, setActiveToolFromId: n }) => {
1603
+ const o = te(null), [r, l] = $(!1), [, s] = wa(), [c, u] = $(void 0), d = (g) => {
1604
+ u(g), n(g.id);
1432
1605
  };
1433
- if (G(() => {
1434
- if (!o) return;
1435
- const f = (w) => {
1436
- !ka(w, n.current) && r(!1);
1606
+ if (J(() => {
1607
+ if (!r) return;
1608
+ const g = (x) => {
1609
+ !((k, w) => !!(k.target instanceof Node && w) && w.contains(k.target))(x, o.current) && l(!1);
1437
1610
  };
1438
- return document.addEventListener("mousedown", f, { passive: !1 }), document.addEventListener("touchstart", f, { passive: !1 }), () => {
1439
- document.removeEventListener("mousedown", f), document.removeEventListener("touchstart", f);
1611
+ return document.addEventListener("mousedown", g, { passive: !1 }), document.addEventListener("touchstart", g, { passive: !1 }), () => {
1612
+ document.removeEventListener("mousedown", g), document.removeEventListener("touchstart", g);
1440
1613
  };
1441
- }, [o]), "type" in i) return p(ye, { disabled: a, type: i, img: i.icon, isActive: e.id === i.id, setActive: c });
1614
+ }, [r]), "type" in i) return v(ke, { disabled: a, type: i, img: i.icon, isActive: e.id === i.id, setActive: d });
1442
1615
  if (!i.toolsType.length) return null;
1443
- if (i.toolsType?.length === 1) return p(ye, { disabled: a, type: i.toolsType[0], img: i.toolsType[0].icon, isActive: e.id === i.toolsType[0].id, setActive: c });
1444
- const u = i?.toolsType.find((f) => f.type === e.type) !== void 0, g = (d ? d.icon : i.toolsType?.[0]?.icon) ?? i.title;
1445
- return I("div", { className: "react-paint-editor-toolbargroup-relative", children: [p(X, { selected: u, title: i.title, disabled: a, onClick: () => {
1446
- d ? s(d.id) : i.toolsType?.[0] && c(i.toolsType[0]), l(() => {
1447
- r(!0);
1616
+ if (i.toolsType?.length === 1) return v(ke, { disabled: a, type: i.toolsType[0], img: i.toolsType[0].icon, isActive: e.id === i.toolsType[0].id, setActive: d });
1617
+ const h = i?.toolsType.find((g) => g.type === e.type) !== void 0, f = (c ? c.icon : i.toolsType?.[0]?.icon) ?? i.title;
1618
+ return Y("div", { className: "react-paint-editor-toolbargroup-relative", children: [v(K, { selected: h, title: i.title, disabled: a, onClick: () => {
1619
+ c ? n(c.id) : i.toolsType?.[0] && d(i.toolsType[0]), s(() => {
1620
+ l(!0);
1448
1621
  });
1449
- }, icon: g }), o && p(qe, { alignment: t, position: "top", children: p("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +i.vertical, ref: n, children: i.toolsType.map((f) => p(ye, { disabled: a, type: f, img: f.icon, isActive: e.id === f.id, setActive: c }, f.id)) }) })] });
1450
- }, us = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], ps = ({ settings: e, width: t, activeTool: i, hasActionToUndo: a = !1, hasActionToRedo: s = !1, hasActionToClear: n = !1, withLoadAndSave: o, withExport: r, clearCanvas: l, setActiveTool: d, undoAction: h, redoAction: c, addPicture: u, loadFile: g, saveFile: f, exportCanvasInFile: w, availableTools: x, withUrlPicture: C, withUploadPicture: b }) => {
1451
- const k = ((y, S) => {
1452
- const P = S.flatMap((z) => {
1453
- if (typeof z != "object") return y.filter((A) => A.type === z);
1454
- const M = y.filter((A) => z.toolsType.includes(A.type));
1455
- return M ? { ...z, toolsType: M } : null;
1622
+ }, icon: f }), r && v(tt, { alignment: t, position: "top", children: v("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +i.vertical, ref: o, children: i.toolsType.map((g) => v(ke, { disabled: a, type: g, img: g.icon, isActive: e.id === g.id, setActive: d }, g.id)) }) })] });
1623
+ }, rs = [{ 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: a = !1, hasActionToRedo: n = !1, hasActionToClear: o = !1, withLoadAndSave: r, withExport: l, clearCanvas: s, setActiveTool: c, undoAction: u, redoAction: d, addPicture: h, loadFile: f, saveFile: g, exportCanvasInFile: x, availableTools: C, withUrlPicture: k, withUploadPicture: w }) => {
1624
+ const m = ((p, Q) => {
1625
+ const M = Q.flatMap((L) => {
1626
+ if (typeof L != "object") return p.filter((E) => E.type === L);
1627
+ const P = p.filter((E) => L.toolsType.includes(E.type));
1628
+ return P ? { ...L, toolsType: P } : null;
1456
1629
  });
1457
- return oi(P);
1458
- })(x, us), v = !e.features.edition, Q = t < 40 * (6 + k.length), V = t < 40 * (3 + k.length), [T, D] = O(!1), [H, Z] = O(!1), [F, N] = O(!1), W = () => {
1459
- D((y) => !y);
1460
- }, Y = () => {
1461
- N((y) => !y);
1462
- }, q = (y) => {
1463
- d(y), D(!1);
1464
- }, L = (y) => {
1465
- q(x.find((S) => S.id === y) ?? i);
1466
- }, m = x.find((y) => y.type === i.type) !== void 0;
1467
- return I(Ce, { children: [I("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [I("div", { className: "react-paint-editor-toolbar-shrinkable", children: [p(ye, { type: Ae, disabled: v, img: Ae.icon, isActive: i.id === Ae.id, setActive: q }), (e.size === "infinite" || e.features.zoom) && p(ye, { type: Rt, disabled: v, img: Rt.icon, isActive: i.id === Rt.id, setActive: q }), V ? p(X, { disabled: v, onClick: W, 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: m }) : k.map((y) => p(hs, { disabled: v, activeTool: i, group: y, setActiveToolFromId: L }, "id" in y ? y.id : y.title))] }), !Q && I(Ce, { children: [p(ye, { type: je, disabled: v || !a, img: je.icon, isActive: i.id === je.id, setActive: h }), p(ye, { type: Ke, disabled: v || !s, img: Ke.icon, isActive: i.id === Ke.id, setActive: c }), p(ye, { type: Je, disabled: v || !n, img: Je.icon, isActive: i.id === Je.id, setActive: l })] }), p(ls, { withActionsInMenu: Q, disabled: v, vertical: !0, alignment: "right", group: { title: "Menu", img: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }, activeTool: i, addPicture: u, loadFile: g, saveFile: f, togglePictureUrlModal: () => {
1468
- Z(!0);
1469
- }, toggleExportModal: Y, withUploadPicture: b, withUrlPicture: C, withLoadAndSave: o, withExport: r, hasActionToUndo: a, hasActionToRedo: s, hasActionToClear: n, undoAction: h, redoAction: c, clearCanvas: l })] }), T && p(Zt, { className: "react-paint-editor-toolbar-modal", onClose: W, title: "Outils", children: x.map((y) => y.type === "picture" ? null : p(ye, { disabled: v, type: y, img: y.icon, withText: !1, isActive: i.id === y.id, setActive: q }, y.id)) }), H && p(cs, { togglePictureUrlModal: () => {
1470
- Z((y) => !y);
1471
- }, addPicture: u }), F && p(ds, { toggleExportModal: Y, exportCanvasInFile: w })] });
1472
- }, bt = { none: 0, small: 10, medium: 20, large: 40 }, gs = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, fs = () => {
1473
- const e = J([]), [t, i] = O([]);
1474
- return G(() => () => {
1630
+ return Qi(M);
1631
+ })(C, rs), y = !e.features.edition, b = t < 40 * (6 + m.length), Z = t < 40 * (3 + m.length), [A, T] = $(!1), [S, V] = $(!1), [I, N] = $(!1), H = () => {
1632
+ T((p) => !p);
1633
+ }, D = () => {
1634
+ N((p) => !p);
1635
+ }, U = (p) => {
1636
+ c(p), T(!1);
1637
+ }, F = (p) => {
1638
+ U(C.find((Q) => Q.id === p) ?? i);
1639
+ }, X = C.find((p) => p.type === i.type) !== void 0;
1640
+ return Y(Ve, { children: [Y("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [Y("div", { className: "react-paint-editor-toolbar-shrinkable", children: [v(ke, { type: Fe, disabled: y, img: Fe.icon, isActive: i.id === Fe.id, setActive: U }), (e.size === "infinite" || e.features.zoom) && v(ke, { type: Xt, disabled: y, img: Xt.icon, isActive: i.id === Xt.id, setActive: U }), Z ? v(K, { disabled: y, onClick: H, 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: X }) : m.map((p) => v(ss, { disabled: y, activeTool: i, group: p, setActiveToolFromId: F }, "id" in p ? p.id : p.title))] }), !b && Y(Ve, { children: [v(ke, { type: rt, disabled: y || !a, img: rt.icon, isActive: i.id === rt.id, setActive: u }), v(ke, { type: lt, disabled: y || !n, img: lt.icon, isActive: i.id === lt.id, setActive: d }), v(ke, { type: ct, disabled: y || !o, img: ct.icon, isActive: i.id === ct.id, setActive: s })] }), v(as, { withActionsInMenu: b, disabled: y, vertical: !0, alignment: "right", group: { title: "Menu", img: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }, activeTool: i, addPicture: h, loadFile: f, saveFile: g, togglePictureUrlModal: () => {
1641
+ V(!0);
1642
+ }, toggleExportModal: D, withUploadPicture: w, withUrlPicture: k, withLoadAndSave: r, withExport: l, hasActionToUndo: a, hasActionToRedo: n, hasActionToClear: o, undoAction: u, redoAction: d, clearCanvas: s })] }), A && v(Nt, { className: "react-paint-editor-toolbar-modal", onClose: H, title: "Outils", children: C.map((p) => p.type === "picture" ? null : v(ke, { disabled: y, type: p, img: p.icon, withText: !1, isActive: i.id === p.id, setActive: U }, p.id)) }), S && v(ns, { togglePictureUrlModal: () => {
1643
+ V((p) => !p);
1644
+ }, addPicture: h }), I && v(os, { toggleExportModal: D, exportCanvasInFile: x })] });
1645
+ }, kt = { none: 0, small: 10, medium: 20, large: 40 }, cs = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, ds = () => {
1646
+ const e = te([]), [t, i] = $([]);
1647
+ return J(() => () => {
1475
1648
  for (const a of e.current) clearTimeout(a);
1476
- }, []), { snackbarList: t, addSnackbar: ({ type: a = Xn, duration: s = Yn, text: n }) => {
1477
- const o = { id: de("snackbar_"), duration: s, type: a, text: n };
1478
- i((r) => [...r, o]), e.current = [...e.current, setTimeout(() => {
1479
- return r = o.id, void i((l) => l.filter((d) => d.id !== r));
1480
- var r;
1481
- }, s)];
1649
+ }, []), { snackbarList: t, addSnackbar: ({ type: a = Wo, duration: n = Oo, text: o }) => {
1650
+ const r = { id: ye("snackbar_"), duration: n, type: a, text: o };
1651
+ i((l) => [...l, r]), e.current = [...e.current, setTimeout(() => {
1652
+ return l = r.id, void i((s) => s.filter((c) => c.id !== l));
1653
+ var l;
1654
+ }, n)];
1482
1655
  } };
1483
- }, Ss = ({ editorProps: e, className: t, style: i, options: a, children: s }) => {
1484
- const { shapesRef: n, addPictureShape: o, moveShapes: r, toggleShapeVisibility: l, toggleShapeLock: d, canGoBackward: h, canGoForward: c, canClear: u, selectedShape: g, removeShape: f, updateShape: w, backwardShape: x, forwardShape: C, refs: b, width: k, height: v, selectTool: Q, selectShape: V, activeTool: T, setActiveTool: D, setAvailableTools: H, isEditMode: Z, availableTools: F, gridGap: N, setGridGap: W, loadFile: Y, exportPicture: q, exportData: L, clearCanvas: m, settings: y, setCanvasZoom: S, canvas: { canGrow: P, layersManipulation: z, withExport: M, withLoadAndSave: A, withUploadPicture: E, withUrlPicture: _ } } = e, { toolbarBackgroundColor: te, dividerColor: j, fontRadius: ne, fontDisabledColor: B, fontDisabledBackgroundColor: se, fontColor: U, fontBackgroundColor: ie, fontSelectedColor: he, fontSelectedBackgroundColor: ge, fontHoverColor: ae, fontHoverBackgroundColor: Se } = { ...gs, ...a }, Ee = y.size === "infinite" || y.features.zoom, [De, ue] = O(!1), [We, fe] = O(!1), [re, Ze] = O(Ee), Pe = Ee && re, Ge = N >= bt.large ? "large" : N >= bt.medium ? "medium" : N >= bt.small ? "small" : "none", { snackbarList: Ne, addSnackbar: xe } = fs(), pt = R((le, ce, vt) => {
1485
- H((Te) => Te.map((Re) => Re.id === le ? Qe(["settings", ce, "default"], vt, Re) : Re)), D((Te) => Te.id === le ? Qe(["settings", ce, "default"], vt, Te) : Te);
1486
- }, [D, H]), gt = R((le) => {
1487
- ue(!0);
1656
+ }, vs = ({ editorProps: e, className: t, style: i, options: a, children: n }) => {
1657
+ const { shapesRef: o, addPictureShape: r, moveShapes: l, toggleShapeVisibility: s, toggleShapeLock: c, canGoBackward: u, canGoForward: d, canClear: h, selectedShape: f, removeShape: g, updateShape: x, backwardShape: C, forwardShape: k, refs: w, width: m, height: y, selectTool: b, selectShapes: Z, activeTool: A, setActiveTool: T, setAvailableTools: S, isEditMode: V, availableTools: I, gridGap: N, setGridGap: H, loadFile: D, exportPicture: U, exportData: F, clearCanvas: X, settings: p, setCanvasZoom: Q, canvas: { canGrow: M, layersManipulation: L, withExport: P, withLoadAndSave: E, withUploadPicture: W, withUrlPicture: O } } = e, { toolbarBackgroundColor: z, dividerColor: ie, fontRadius: re, fontDisabledColor: R, fontDisabledBackgroundColor: oe, fontColor: G, fontBackgroundColor: le, fontSelectedColor: ae, fontSelectedBackgroundColor: pe, fontHoverColor: se, fontHoverBackgroundColor: ge } = { ...cs, ...a }, q = p.size === "infinite" || p.features.zoom, [he, ce] = $(!1), [Ee, Ie] = $(!1), [He, ve] = $(q), ne = q && He, Te = N >= kt.large ? "large" : N >= kt.medium ? "medium" : N >= kt.small ? "small" : "none", { snackbarList: We, addSnackbar: Ce } = ds(), qe = B((fe, me, vt) => {
1658
+ S((Be) => Be.map((it) => it.id === fe ? Pe(["settings", me, "default"], vt, it) : it)), T((Be) => Be.id === fe ? Pe(["settings", me, "default"], vt, Be) : Be);
1659
+ }, [T, S]), Rt = B((fe) => {
1660
+ ce(!0);
1488
1661
  try {
1489
- q(le);
1490
- } catch (ce) {
1491
- ce instanceof Error && xe({ type: "error", text: `L'export a échoué : ${ce.message}` }), console.warn(ce);
1662
+ U(fe);
1663
+ } catch (me) {
1664
+ me instanceof Error && Ce({ type: "error", text: `L'export a échoué : ${me.message}` }), console.warn(me);
1492
1665
  } finally {
1493
- ue(!1);
1666
+ ce(!1);
1494
1667
  }
1495
- }, [q, xe]), ft = R(() => {
1496
- ue(!0);
1668
+ }, [U, Ce]), Wt = B(() => {
1669
+ ce(!0);
1497
1670
  try {
1498
- L(), ue(!1);
1499
- } catch (le) {
1500
- le instanceof Error && xe({ type: "error", text: "L'enregistrement a échoué" }), console.warn(le);
1671
+ F(), ce(!1);
1672
+ } catch (fe) {
1673
+ fe instanceof Error && Ce({ type: "error", text: "L'enregistrement a échoué" }), console.warn(fe);
1501
1674
  } finally {
1502
- ue(!1);
1675
+ ce(!1);
1503
1676
  }
1504
- }, [L, xe]), zt = R(async (le) => {
1505
- ue(!0);
1677
+ }, [F, Ce]), _e = B(async (fe) => {
1678
+ ce(!0);
1506
1679
  try {
1507
- await Y(le), xe({ type: "success", text: "Fichier chargé !" });
1508
- } catch (ce) {
1509
- ce instanceof Error && xe({ type: "error", text: "Le chargement a échoué" }), console.warn(ce);
1680
+ await D(fe), Ce({ type: "success", text: "Fichier chargé !" });
1681
+ } catch (me) {
1682
+ me instanceof Error && Ce({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1510
1683
  } finally {
1511
- ue(!1);
1684
+ ce(!1);
1512
1685
  }
1513
- }, [Y, xe]), At = R(async (le) => {
1514
- ue(!0);
1686
+ }, [D, Ce]), Ot = B(async (fe) => {
1687
+ ce(!0);
1515
1688
  try {
1516
- const ce = await o(le, k, v);
1517
- V(ce);
1518
- } catch (ce) {
1519
- ce instanceof Error && xe({ type: "error", text: "Le chargement a échoué" }), console.warn(ce);
1689
+ const me = await r(fe, m, y);
1690
+ Z([me]);
1691
+ } catch (me) {
1692
+ me instanceof Error && Ce({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1520
1693
  } finally {
1521
- ue(!1);
1694
+ ce(!1);
1522
1695
  }
1523
- }, [o, V, xe, k, v]), Et = `${t ? `${t} ` : ""}${We ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1524
- return I("div", { ref: b.setEditor, className: Et, style: { "--react-paint-editor-app-maxWidth": P ? "100%" : `${k}px`, "--react-paint-editor-app-toolbar-bg": te, "--react-paint-editor-app-divider-color": j, "--react-paint-editor-app-font-radius": ne, "--react-paint-editor-app-font-disabled-color": B, "--react-paint-editor-app-font-disabled-bg": se, "--react-paint-editor-app-font-color": U, "--react-paint-editor-app-font-bg": ie, "--react-paint-editor-app-font-selected-color": he, "--react-paint-editor-app-font-selected-bg": ge, "--react-paint-editor-app-font-hover-color": ae, "--react-paint-editor-app-font-hover-bg": Se, ...i }, children: [Z && p(ps, { settings: y, width: y.canvasSize.width, activeTool: T, clearCanvas: m, setActiveTool: Q, exportCanvasInFile: gt, saveFile: ft, loadFile: zt, addPicture: At, hasActionToUndo: h, hasActionToRedo: c, hasActionToClear: u, undoAction: x, redoAction: C, availableTools: F, withExport: M, withLoadAndSave: A, withUploadPicture: E, withUrlPicture: _ }), s, Z && z && p(Kn, { gridFormat: Ge, setGridFormat: (le) => {
1525
- W(bt[le]);
1526
- }, shapes: n.current, moveShapes: r, selectedShape: g, removeShape: f, selectShape: V, toggleShapeVisibility: l, toggleShapeLock: d, isLayoutPanelShown: We, settings: y }), Pe && I(qe, { alignment: "left", className: "react-paint-editor-layouts-panel", "data-edit": +Z, children: [p(X, { 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: () => S("unzoom") }), I(X, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => S("default"), children: [Math.round(100 * y.canvasZoom), "%"] }), p(X, { className: "react-paint-editor-zoom-button", icon: ca, onClick: () => S("zoom") })] }), Z && I(Ce, { children: [p(rs, { setCanvasZoom: S, width: y.canvasSize.width, activeTool: T, availableTools: F, selectedShape: g, settings: y, removeShape: f, updateShape: w, canvas: b.canvas.current, layersManipulation: z, toggleLayoutPanel: () => {
1527
- fe((le) => !le);
1528
- }, isZoomPanelShown: Pe, setIsZoomPanelShown: Ze, updateToolSettings: pt }), p(Un, { isLoading: De }), p(Gn, { snackbarList: Ne })] })] });
1696
+ }, [r, Z, Ce, m, y]), Ft = `${t ? `${t} ` : ""}${Ee ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1697
+ return Y("div", { ref: w.setEditor, className: Ft, style: { "--react-paint-editor-app-maxWidth": M ? "100%" : `${m}px`, "--react-paint-editor-app-toolbar-bg": z, "--react-paint-editor-app-divider-color": ie, "--react-paint-editor-app-font-radius": re, "--react-paint-editor-app-font-disabled-color": R, "--react-paint-editor-app-font-disabled-bg": oe, "--react-paint-editor-app-font-color": G, "--react-paint-editor-app-font-bg": le, "--react-paint-editor-app-font-selected-color": ae, "--react-paint-editor-app-font-selected-bg": pe, "--react-paint-editor-app-font-hover-color": se, "--react-paint-editor-app-font-hover-bg": ge, ...i }, children: [V && v(ls, { settings: p, width: p.canvasSize.width, activeTool: A, clearCanvas: X, setActiveTool: b, exportCanvasInFile: Rt, saveFile: Wt, loadFile: _e, addPicture: Ot, hasActionToUndo: u, hasActionToRedo: d, hasActionToClear: h, undoAction: C, redoAction: k, availableTools: I, withExport: P, withLoadAndSave: E, withUploadPicture: W, withUrlPicture: O }), n, V && L && v(Xo, { gridFormat: Te, setGridFormat: (fe) => {
1698
+ H(kt[fe]);
1699
+ }, shapes: o.current, moveShapes: l, selectedShapes: f, removeShape: g, selectShapes: Z, toggleShapeVisibility: s, toggleShapeLock: c, isLayoutPanelShown: Ee, settings: p }), ne && Y(tt, { alignment: "left", className: "react-paint-editor-layouts-panel", "data-edit": +V, children: [v(K, { 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: () => Q("unzoom") }), Y(K, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => Q("default"), children: [Math.round(100 * p.canvasZoom), "%"] }), v(K, { className: "react-paint-editor-zoom-button", icon: Za, onClick: () => Q("zoom") })] }), V && Y(Ve, { children: [v(is, { setCanvasZoom: Q, width: p.canvasSize.width, activeTool: A, availableTools: I, selectedShape: f, settings: p, removeShape: g, updateShape: x, canvas: w.canvas.current, layersManipulation: L, toggleLayoutPanel: () => {
1700
+ Ie((fe) => !fe);
1701
+ }, isZoomPanelShown: ne, setIsZoomPanelShown: ve, updateToolSettings: qe }), v(Ro, { isLoading: he }), v(Bo, { snackbarList: We })] })] });
1529
1702
  };
1530
1703
  export {
1531
- Qs as Canvas,
1532
- Ss as Editor,
1533
- ys as useReactPaint
1704
+ gs as Canvas,
1705
+ vs as Editor,
1706
+ ps as useReactPaint
1534
1707
  };