@yorab/react-paint 0.16.3 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/canvas/components/Canvas.d.ts +2 -0
  2. package/dist/canvas/constants/app.d.ts +1 -0
  3. package/dist/canvas/constants/keyboard.d.ts +3 -0
  4. package/dist/canvas/hooks/useDrawableCanvas.d.ts +3 -1
  5. package/dist/canvas/hooks/useKeyboard.d.ts +4 -1
  6. package/dist/canvas/hooks/useReactPaint.d.ts +18 -2
  7. package/dist/canvas/hooks/useShapes.d.ts +6 -2
  8. package/dist/canvas/utils/shapes/brush.d.ts +0 -6
  9. package/dist/canvas/utils/shapes/circle.d.ts +1 -7
  10. package/dist/canvas/utils/shapes/curve.d.ts +2 -7
  11. package/dist/canvas/utils/shapes/ellipse.d.ts +1 -7
  12. package/dist/canvas/utils/shapes/index.d.ts +1 -6
  13. package/dist/canvas/utils/shapes/line.d.ts +1 -7
  14. package/dist/canvas/utils/shapes/picture.d.ts +0 -6
  15. package/dist/canvas/utils/shapes/polygon.d.ts +1 -6
  16. package/dist/canvas/utils/shapes/rectangle.d.ts +0 -6
  17. package/dist/common/types/Mode.d.ts +7 -1
  18. package/dist/editor/components/common/Menu.d.ts +10 -0
  19. package/dist/editor/components/common/Panel.d.ts +3 -3
  20. package/dist/editor/components/settings/Layouts.d.ts +2 -2
  21. package/dist/editor/components/toolbox/ContextMenu.d.ts +23 -0
  22. package/dist/editor/components/toolbox/MenuGroup.d.ts +1 -8
  23. package/dist/editor/components/toolbox/ToolbarGroup.d.ts +1 -4
  24. package/dist/editor/constants/icons.d.ts +1 -0
  25. package/dist/editor/hooks/useDrag.d.ts +2 -2
  26. package/dist/editor/hooks/useMenu.d.ts +10 -0
  27. package/dist/react-paint.css +1 -1
  28. package/dist/react-paint.js +1421 -1229
  29. package/dist/react-paint.umd.cjs +1 -1
  30. package/package.json +1 -1
  31. package/dist/canvas/utils/string.d.ts +0 -2
  32. package/dist/editor/components/settings/PointsNumberField.d.ts +0 -13
@@ -1,467 +1,500 @@
1
- import hi, { useState as $, useEffect as ee, useRef as ne, useCallback as X, useMemo as kn, useImperativeHandle as Ln, useTransition as Vn } from "react";
2
- import { jsx as m, jsxs as q, Fragment as Ae } from "react/jsx-runtime";
3
- const Zn = '<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>', ui = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', pi = '<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>', gi = '<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>', Hn = '<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>', zi = '<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>', vi = '<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>', zn = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', Tn = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', An = '<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>', Ti = '<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>', Ai = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', Di = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Ei = '<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>', Ii = '<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>', Dn = '<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>', Ce = ["transparent", "black", "white", "red", "green", "blue", "yellow"], Ue = [0, 1, 2], Wi = [[1, 0], [1, 2], [4, 6]], mt = "serif", Aa = 2, En = 3, Da = 4, he = "react-paint-", In = { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } }, fi = { type: "picture", id: `${he}picture`, icon: vi, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, Wn = { type: "brush", id: `${he}brush`, icon: Zn, label: "Brosse", settings: { strokeColor: { values: Ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: Ue, default: 0 } } }, Rn = { type: "line", id: `${he}line`, icon: Tn, label: "Ligne", settings: { strokeColor: { values: Ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, Nn = { type: "polygon", id: `${he}polygon`, icon: gi, label: "Polygone", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 }, closedPoints: { default: 0 } } }, Bn = { type: "curve", id: `${he}curve`, icon: An, label: "Courbe", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 }, closedPoints: { default: 0 } } }, On = { type: "rect", id: `${he}rect`, icon: ui, label: "Rectangle", settings: In }, Fn = { type: "square", id: `${he}square`, icon: ui, label: "Carré", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } } }, Yn = { type: "circle", id: `${he}circle`, icon: pi, label: "Cercle", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } } }, Xn = { type: "ellipse", id: `${he}ellipse`, icon: pi, label: "Ellipse", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } } }, $n = { type: "text", id: `${he}text`, icon: zn, label: "Texte", settings: { strokeColor: { values: Ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: mt }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Oe = { id: `${he}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" }, dt = { id: `${he}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" }, ct = { id: `${he}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" }, ht = { id: `${he}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" }, _t = { id: `${he}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" }, Ri = { id: `${he}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" }, jt = { id: `${he}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" }, Kt = { id: `${he}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" }, Ni = { id: `${he}upload-picture`, type: "uploadpicture", icon: vi, label: "Upload picture" }, Un = 2, qn = "blue", Je = 14, Gn = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], _n = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], Ea = ["rect", "square", "circle", "ellipse", "picture", "text", "triangle", "brush", "group"], Ia = ["square", "circle", "picture", "text"], jn = "react-paint-canvas-drawcanvas", Kn = "react-paint-canvas-selectioncanvas", Bi = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [Wn, Rn, Nn, Bn, On, Fn, Yn, Xn, fi, $n], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, Wa = { canvasBackgroundColor: "white", canvasSelectionColor: qn, canvasSelectionWidth: Un }, Oi = 300, ai = (e, t) => {
1
+ import Pi, { useState as J, useEffect as de, useRef as ce, useCallback as G, useMemo as Yn, useImperativeHandle as Xn, useTransition as $n } from "react";
2
+ import { jsx as v, jsxs as K, Fragment as Oe } from "react/jsx-runtime";
3
+ const Un = '<svg><path d="M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z"/></svg>', Li = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', Vi = '<svg><path d="M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z"/></svg>', Zi = '<svg><path d="M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z"/></svg>', qn = '<svg><path d="M4.125 5.083V3.333H7.062L7.896 2.5H12.104L12.938 3.333H15.875V5.083ZM6.75 17.5Q6.021 17.5 5.51 16.99Q5 16.479 5 15.75V5.958H15V15.75Q15 16.479 14.49 16.99Q13.979 17.5 13.25 17.5Z"/></svg>', qi = '<svg><path d="M10 17.5Q7.208 17.5 5.271 15.594Q3.333 13.688 3.333 10.958Q3.333 9.583 3.854 8.396Q4.375 7.208 5.292 6.292L10 1.667L14.688 6.292Q15.604 7.208 16.135 8.396Q16.667 9.583 16.667 10.958Q16.667 13.688 14.719 15.594Q12.771 17.5 10 17.5ZM5.146 11.667H14.854Q15.083 10.188 14.552 9.146Q14.021 8.104 13.479 7.562L10 4.125L6.521 7.562Q5.979 8.104 5.448 9.146Q4.917 10.188 5.146 11.667Z"/></svg>', Hi = '<svg><path d="M4.792 15.083 8.333 11.542 9.833 13.021 11.667 10.708 15.167 15.083ZM6.667 8.417Q5.938 8.417 5.427 7.906Q4.917 7.396 4.917 6.667Q4.917 5.938 5.427 5.427Q5.938 4.917 6.667 4.917Q7.396 4.917 7.906 5.427Q8.417 5.938 8.417 6.667Q8.417 7.396 7.906 7.906Q7.396 8.417 6.667 8.417ZM4.167 18.333Q3.125 18.333 2.396 17.604Q1.667 16.875 1.667 15.833V4.167Q1.667 3.125 2.396 2.396Q3.125 1.667 4.167 1.667H15.833Q16.875 1.667 17.604 2.396Q18.333 3.125 18.333 4.167V15.833Q18.333 16.875 17.604 17.604Q16.875 18.333 15.833 18.333ZM4.167 16.583H15.833Q16.146 16.583 16.365 16.365Q16.583 16.146 16.583 15.833V4.167Q16.583 3.854 16.365 3.635Q16.146 3.417 15.833 3.417H4.167Q3.854 3.417 3.635 3.635Q3.417 3.854 3.417 4.167V15.833Q3.417 16.146 3.635 16.365Q3.854 16.583 4.167 16.583Z"/></svg>', Gn = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', _n = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', Gi = '<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>', jn = '<svg><path d="M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z"/></svg>', _i = '<svg><path d="M5.833 15V3.333H10.375Q11.812 3.333 12.885 4.156Q13.958 4.979 13.958 6.375Q13.958 7.375 13.49 7.969Q13.021 8.562 12.396 8.875V9.042Q13.312 9.354 13.844 10.021Q14.375 10.688 14.375 11.75Q14.375 13.312 13.229 14.156Q12.083 15 10.5 15ZM8.125 8.042H10.188Q10.854 8.042 11.302 7.656Q11.75 7.271 11.75 6.708Q11.75 6.167 11.302 5.771Q10.854 5.375 10.188 5.375H8.125ZM8.125 12.917H10.354Q11.167 12.917 11.625 12.51Q12.083 12.104 12.083 11.458Q12.083 10.812 11.625 10.406Q11.167 10 10.354 10H8.125Z"/></svg>', ji = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', Ki = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Ji = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM10 16.583Q10.896 16.583 11.708 16.365Q12.521 16.146 13.25 15.729L4.292 6.75Q3.875 7.479 3.646 8.292Q3.417 9.104 3.417 10Q3.417 12.729 5.344 14.656Q7.271 16.583 10 16.583ZM17 14.562 15.708 13.271Q16.125 12.542 16.354 11.719Q16.583 10.896 16.583 10Q16.583 7.271 14.656 5.344Q12.729 3.417 10 3.417Q9.104 3.417 8.292 3.646Q7.479 3.875 6.75 4.292L5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562ZM11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771ZM8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Z"/></svg>', en = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM17 14.562 5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562Z"/></svg>', Kn = '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Zm-40-60v-80h-80v-80h80v-80h80v80h80v80h-80v80h-80Z"/></svg>', Ee = ["transparent", "black", "white", "red", "green", "blue", "yellow"], lt = [0, 1, 2], tn = [[1, 0], [1, 2], [4, 6]], It = "serif", ao = 2, Jn = 3, oo = 4, Me = "react-paint-", ea = { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } }, zi = { type: "picture", id: `${Me}picture`, icon: Hi, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, ta = { type: "brush", id: `${Me}brush`, icon: Un, label: "Brosse", settings: { strokeColor: { values: Ee, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: lt, default: 0 } } }, ia = { type: "line", id: `${Me}line`, icon: _n, label: "Ligne", settings: { strokeColor: { values: Ee, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, na = { type: "polygon", id: `${Me}polygon`, icon: Zi, label: "Polygone", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, closedPoints: { default: 0 } } }, aa = { type: "curve", id: `${Me}curve`, icon: jn, label: "Courbe", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, closedPoints: { default: 0 } } }, oa = { type: "rect", id: `${Me}rect`, icon: Li, label: "Rectangle", settings: ea }, sa = { type: "square", id: `${Me}square`, icon: Li, label: "Carré", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, ra = { type: "circle", id: `${Me}circle`, icon: Vi, label: "Cercle", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, la = { type: "ellipse", id: `${Me}ellipse`, icon: Vi, label: "Ellipse", settings: { strokeColor: { values: Ee, default: "black" }, fillColor: { values: Ee, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, ca = { type: "text", id: `${Me}text`, icon: Gn, label: "Texte", settings: { strokeColor: { values: Ee, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: It }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Je = { id: `${Me}selection`, type: "selection", icon: '<svg><path d="M8.0145 11.1707C8.38484 10.9914 8.82183 11.1558 8.99959 11.5295L10.7031 15.2591L12.0363 14.6238L10.3254 10.9017C10.1476 10.528 10.3106 10.0795 10.6809 9.90761L10.8883 9.84782L12.5918 9.51148L6.48133 4.33192V12.389L7.82934 11.2903L8.0145 11.1707ZM10.6587 16.9258C10.2883 17.1052 9.84395 16.9482 9.67359 16.5745L8.05894 13.0318L6.19988 14.5416C6.07396 14.6462 5.91842 14.706 5.74066 14.706C5.54423 14.706 5.35584 14.6272 5.21694 14.4871C5.07803 14.3469 5 14.1568 5 13.9586V2.74741C5 2.54919 5.07803 2.35908 5.21694 2.21891C5.35584 2.07874 5.54423 2 5.74066 2C5.91842 2 6.08878 2.06727 6.21469 2.1719L6.2221 2.16443L14.7323 9.36947C15.0508 9.63854 15.0879 10.1094 14.8286 10.4233C14.7175 10.5579 14.562 10.6475 14.4064 10.6774L12.0659 11.1408L13.6954 14.6761C13.888 15.0498 13.7102 15.4908 13.3399 15.6627L10.6587 16.9258Z"/></svg>', label: "Sélection" }, Pt = { id: `${Me}undo`, type: "undo", icon: '<svg><path d="M11.708 15.833H5.854V14.083H11.708Q13 14.083 13.958 13.292Q14.917 12.5 14.917 11.271Q14.917 10.042 13.958 9.24Q13 8.438 11.708 8.438H6.667L8.792 10.562L7.562 11.792L3.333 7.562L7.562 3.333L8.792 4.562L6.667 6.688H11.708Q13.729 6.688 15.198 7.99Q16.667 9.292 16.667 11.25Q16.667 13.208 15.198 14.521Q13.729 15.833 11.708 15.833Z"/></svg>', label: "Undo" }, Lt = { id: `${Me}redo`, type: "redo", icon: '<svg><path d="M8.292 15.833Q6.271 15.833 4.802 14.521Q3.333 13.208 3.333 11.25Q3.333 9.292 4.802 7.99Q6.271 6.688 8.292 6.688H13.333L11.208 4.562L12.438 3.333L16.667 7.562L12.438 11.792L11.208 10.562L13.333 8.438H8.292Q7 8.438 6.042 9.229Q5.083 10.021 5.083 11.25Q5.083 12.5 6.042 13.292Q7 14.083 8.292 14.083H14.146V15.833Z"/></svg>', label: "Redo" }, Vt = { id: `${Me}clear`, type: "clear", icon: '<svg><path d="M7.854 13.812 10 11.688 12.125 13.812 13.354 12.604 11.208 10.458 13.354 8.312 12.125 7.104 10 9.229 7.854 7.104 6.625 8.312 8.771 10.458 6.625 12.604ZM5.896 17.5Q5.167 17.5 4.656 16.99Q4.146 16.479 4.146 15.75V5.125H3.333V3.375H7.542V2.5H12.458V3.375H16.667V5.125H15.833V15.75Q15.833 16.479 15.323 16.99Q14.812 17.5 14.083 17.5Z"/></svg>', label: "Clear" }, di = { id: `${Me}export`, type: "export", icon: '<svg><path d="M10 13.271 5.708 8.979 6.958 7.729 9.125 9.896V3.333H10.875V9.896L13.042 7.729L14.292 8.979ZM5.083 16.667Q4.354 16.667 3.844 16.156Q3.333 15.646 3.333 14.917V12.5H5.083V14.917Q5.083 14.917 5.083 14.917Q5.083 14.917 5.083 14.917H14.917Q14.917 14.917 14.917 14.917Q14.917 14.917 14.917 14.917V12.5H16.667V14.917Q16.667 15.646 16.156 16.156Q15.646 16.667 14.917 16.667Z"/></svg>', label: "Export PNG" }, nn = { id: `${Me}load`, type: "loadfile", icon: '<svg><path d="M3.417 16.667Q2.729 16.667 2.198 16.135Q1.667 15.604 1.667 14.917V5.083Q1.667 4.396 2.198 3.865Q2.729 3.333 3.417 3.333H8.25L9.917 5H16.667Q17.354 5 17.844 5.531Q18.333 6.062 18.333 6.75H3.417V14.917Q3.417 14.917 3.417 14.917Q3.417 14.917 3.417 14.917L5.438 8.5H19.583L17.396 15.479Q17.229 16.021 16.802 16.344Q16.375 16.667 15.833 16.667Z"/></svg>', label: "Load project" }, hi = { id: `${Me}save`, type: "savefile", icon: '<svg><path d="M17.5 5.833V15.75Q17.5 16.479 16.99 16.99Q16.479 17.5 15.75 17.5H4.25Q3.521 17.5 3.01 16.99Q2.5 16.479 2.5 15.75V4.25Q2.5 3.521 3.01 3.01Q3.521 2.5 4.25 2.5H14.167ZM10 14.917Q11.062 14.917 11.823 14.156Q12.583 13.396 12.583 12.333Q12.583 11.271 11.823 10.51Q11.062 9.75 10 9.75Q8.938 9.75 8.177 10.51Q7.417 11.271 7.417 12.333Q7.417 13.396 8.177 14.156Q8.938 14.917 10 14.917ZM5.021 8.396H12.521V5.021H5.021Z"/></svg>', label: "Save project" }, ui = { id: `${Me}move`, type: "move", icon: '<svg viewBox="0 -960 960 960"><path d="M412-48q-21.95 0-40.98-9Q352-66 338-83L48-434l27-28q17-17 41.5-20.5T162-473l126 74v-381q0-15.3 10.29-25.65Q308.58-816 323.79-816t25.71 10.35Q360-795.3 360-780v300h80v-396q0-15.3 10.29-25.65Q460.58-912 475.79-912t25.71 10.35Q512-891.3 512-876v396h80v-348q0-15.3 10.29-25.65Q612.58-864 627.79-864t25.71 10.35Q664-843.3 664-828v348h80v-252q0-15.3 10.29-25.65Q764.58-768 779.79-768t25.71 10.35Q816-747.3 816-732v540q0 60-42 102T672-48H412Z"/></svg>', label: "Move" }, an = { id: `${Me}upload-picture`, type: "uploadpicture", icon: Hi, label: "Upload picture" }, da = 2, ha = "blue", gt = 14, ua = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], pa = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], so = ["rect", "square", "circle", "ellipse", "picture", "text", "triangle", "brush", "group"], ro = ["square", "circle", "picture", "text"], ga = "react-paint-canvas-drawcanvas", fa = "react-paint-canvas-selectioncanvas", on = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, withContextMenu: !0, availableTools: [ta, ia, na, aa, oa, sa, ra, la, zi, ca], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, lo = { canvasBackgroundColor: "white", canvasSelectionColor: ha, canvasSelectionWidth: da }, sn = 300, Si = (e, t) => {
4
4
  const i = { ...t };
5
5
  for (const n of e) Array.isArray(n) ? n[1].includes(i[n[0]]) && delete i[n[0]] : delete i[n];
6
6
  return i;
7
- }, Le = (e, t, i) => {
7
+ }, Xe = (e, t, i) => {
8
8
  const n = Array.isArray(i) ? [...i] : { ...i }, a = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
- return a.reduce((o, d, r) => (o[d] = oi(o[d]) ? { ...o[d] } : Array.isArray(o[d]) ? [...o[d]] : o[d] === void 0 || o[d] === null ? {} : o[d], r === a.length - 1 && (o[d] = t), o[d]), n), n;
10
- }, oi = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, Ie = (e, t, i) => {
11
- if (!oi(t) || !oi(i)) return i;
9
+ return a.reduce((o, r, l) => (o[r] = bi(o[r]) ? { ...o[r] } : Array.isArray(o[r]) ? [...o[r]] : o[r] === void 0 || o[r] === null ? {} : o[r], l === a.length - 1 && (o[r] = t), o[r]), n), n;
10
+ }, bi = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, Ke = (e, t, i) => {
11
+ if (!bi(t) || !bi(i)) return i;
12
12
  const n = { ...t };
13
- for (const a in i) i.hasOwnProperty(a) && (n.hasOwnProperty(a) ? n[a] = e(n[a], i[a], a) ?? Ie(e, n[a], i[a]) : n[a] = i[a]);
13
+ for (const a in i) i.hasOwnProperty(a) && (n.hasOwnProperty(a) ? n[a] = e(n[a], i[a], a) ?? Ke(e, n[a], i[a]) : n[a] = i[a]);
14
14
  return n;
15
- }, Jn = (e, t) => {
15
+ }, va = (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), n = Object.keys(t);
19
19
  if (i.length !== n.length) return !1;
20
- for (const a of i) if (!n.includes(a) || !Jn(e[a], t[a])) return !1;
20
+ for (const a of i) if (!n.includes(a) || !va(e[a], t[a])) return !1;
21
21
  return !0;
22
- }, Jt = {}, ue = (e = "") => (Jt[e] || (Jt[e] = 0), `${e}${++Jt[e]}`), We = (e, t, i) => Math.max(t, Math.min(e, i)), ea = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), ta = (e) => {
22
+ }, pi = {}, Le = (e = "") => (pi[e] || (pi[e] = 0), `${e}${++pi[e]}`), et = (e, t, i) => Math.max(t, Math.min(e, i)), ma = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), ya = (e) => {
23
23
  e.reset(), e.lineCap = "round", e.lineJoin = "round";
24
- }, xe = (e, t = {}) => {
25
- const { lineCap: i = "round", fillColor: n = "transparent", opacity: a = 100, strokeColor: o = qn, lineWidth: d = Un, lineDash: r = 0, shadowColor: s = "transparent", shadowBlur: l = 0 } = t;
26
- e.lineCap = i, e.globalAlpha = a / 100, e.fillStyle = n, e.strokeStyle = o, e.lineWidth = d, e.setLineDash(r === 0 ? [] : [Wi[r][0] * d, Wi[r][1] * d]), e.shadowColor = s, e.shadowBlur = l;
27
- }, lt = (e, t, i, n) => {
24
+ }, De = (e, t = {}) => {
25
+ const { lineCap: i = "round", fillColor: n = "transparent", opacity: a = 100, strokeColor: o = ha, lineWidth: r = da, lineDash: l = 0, shadowColor: s = "transparent", shadowBlur: c = 0 } = t;
26
+ e.lineCap = i, e.globalAlpha = a / 100, e.fillStyle = n, e.strokeStyle = o, e.lineWidth = r, e.setLineDash(l === 0 ? [] : [tn[l][0] * r, tn[l][1] * r]), e.shadowColor = s, e.shadowBlur = c;
27
+ }, kt = (e, t, i, n) => {
28
28
  e.save(), e.scale(t.canvasSize.scaleRatio, t.canvasSize.scaleRatio), e.translate(t.canvasOffset[0], t.canvasOffset[1]), i && n && (e.translate(n[0], n[1]), e.rotate(i), e.translate(-n[0], -n[1]));
29
- }, si = (e) => 180 * e / Math.PI, ia = (e, t) => {
29
+ }, Qi = (e) => 180 * e / Math.PI, Sa = (e, t) => {
30
30
  const i = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), n = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
31
31
  return Math.sqrt(i * i + n * n) <= t.radius;
32
- }, le = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
32
+ }, Qe = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
33
33
  if (i === 0) return t;
34
34
  const n = [t[0] - e[0], t[1] - e[1]], a = n[1] * Math.cos(i) - n[0] * Math.sin(i);
35
35
  return [n[1] * Math.sin(i) + n[0] * Math.cos(i) + e[0], a + e[1]];
36
- }, Fi = (e) => (e + 2 * Math.PI) % (2 * Math.PI), Yi = ({ targetVector: [e, t], radian: i = !0, originVector: n }) => {
37
- const a = Fi(Math.atan2(t[1] - e[1], t[0] - e[0]));
36
+ }, rn = (e) => (e + 2 * Math.PI) % (2 * Math.PI), ln = ({ targetVector: [e, t], radian: i = !0, originVector: n }) => {
37
+ const a = rn(Math.atan2(t[1] - e[1], t[0] - e[0]));
38
38
  if (n) {
39
- const [o, d] = n, r = Math.atan2(d[1] - o[1], d[0] - o[0]), s = Fi(a - r);
40
- return i ? s : si(s);
39
+ const [o, r] = n, l = Math.atan2(r[1] - o[1], r[0] - o[0]), s = rn(a - l);
40
+ return i ? s : Qi(s);
41
41
  }
42
- return i ? a : si(a);
43
- }, na = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), et = (e, t, i) => {
44
- const n = le({ origin: t.computed.center, point: e.computed.center, rotation: t.rotation ?? 0 }), a = (n[0] - (e.computed.borders.width / 2 - i.settings.selectionPadding) - (i.originalBorders.x + i.settings.selectionPadding)) * i.widthMultiplier, o = (n[1] - (e.computed.borders.height / 2 - i.settings.selectionPadding) - (i.originalBorders.y + i.settings.selectionPadding)) * i.heightMultiplier;
42
+ return i ? a : Qi(a);
43
+ }, ba = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), mt = (e, t, i) => {
44
+ const n = Qe({ origin: t.computed.center, point: e.computed.center, rotation: t.rotation ?? 0 }), a = (n[0] - (e.computed.borders.width / 2 - i.settings.selectionPadding) - (i.originalBorders.x + i.settings.selectionPadding)) * i.widthMultiplier, o = (n[1] - (e.computed.borders.height / 2 - i.settings.selectionPadding) - (i.originalBorders.y + i.settings.selectionPadding)) * i.heightMultiplier;
45
45
  return { x: i.newBorderX + i.settings.selectionPadding + (i.isXinverted ? i.newBorderWidth - 2 * i.settings.selectionPadding - (e.computed.borders.width - 2 * i.settings.selectionPadding || 1) * i.widthMultiplier - a : a), y: i.newBorderY + i.settings.selectionPadding + (i.isYinverted ? i.newBorderHeight - 2 * i.settings.selectionPadding - (e.computed.borders.height - 2 * i.settings.selectionPadding || 1) * i.heightMultiplier - o : o) };
46
- }, tt = (e, t, i, n, a) => le({ origin: e.groupCenter, point: [t + n / 2, i + a / 2], rotation: -e.rotation }), mi = (e, { selectionPadding: t }) => {
47
- const i = e.points.flat(), n = Math.min(...i.map((s) => s[0])), a = Math.min(...i.map((s) => s[1])), o = i.map((s) => Ee(s, n, a, e.scaleX, e.scaleY)), d = Math.max(...o.map((s) => s[0])) + t, r = Math.max(...o.map((s) => s[1])) + t;
48
- return { x: n - t, width: d - n + t, y: a - t, height: r - a + t };
49
- }, ut = (e, t) => {
50
- const i = Ba(e, t), n = ((a, o) => Be(a, mi, o))(e, t);
51
- return { ...e, path: i, selection: pt(i, n, t), computed: n };
52
- }, Ra = ut, Ve = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Ee = (e, t, i, n = 1, a = 1) => [t + (e[0] - t) * n, i + (e[1] - i) * a], we = (e, t, i = 0) => {
53
- if (!t.gridGap) return Ve(e);
46
+ }, yt = (e, t, i, n, a) => Qe({ origin: e.groupCenter, point: [t + n / 2, i + a / 2], rotation: -e.rotation }), Ai = (e, { selectionPadding: t }) => {
47
+ const i = e.points.flat(), n = Math.min(...i.map((s) => s[0])), a = Math.min(...i.map((s) => s[1])), o = i.map((s) => Ge(s, n, a, e.scaleX, e.scaleY)), r = Math.max(...o.map((s) => s[0])) + t, l = Math.max(...o.map((s) => s[1])) + t;
48
+ return { x: n - t, width: r - n + t, y: a - t, height: l - a + t };
49
+ }, Zt = (e, t) => {
50
+ const i = uo(e, t), n = it(e, Ai, t);
51
+ return { ...e, path: i, selection: Ht(i, n, t), computed: n };
52
+ }, co = Zt, Qa = (e, t, i) => {
53
+ const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = Ai({ ...e, scaleX: 1, scaleY: 1 }, o), c = s.width - 2 * o.selectionPadding, h = s.height - 2 * o.selectionPadding, d = e.scaleX ?? 1 ? (e.scaleX ?? 1) * r : r / c, u = e.scaleY ?? 1 ? (e.scaleY ?? 1) * l : l / h, p = c * d, f = h * u, m = mt(e, t, i), b = yt(i, m.x, m.y, p, f), x = Be(b[0] - p / 2 - e.computed.borders.x - o.selectionPadding) + (n ? 2 * e.computed.borders.x + s.width : 0), k = Be(b[1] - f / 2 - e.computed.borders.y - o.selectionPadding) + (a ? 2 * e.computed.borders.y + s.height : 0), M = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation;
54
+ return Zt({ ...e, points: e.points.map((S) => S.map(([g, P]) => [n ? -g + x : g + x, a ? -P + k : P + k])), scaleX: d, scaleY: u, rotation: M ? -(e.rotation ?? 0) : e.rotation ?? 0 }, i.settings);
55
+ }, Be = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Ge = (e, t, i, n = 1, a = 1) => [t + (e[0] - t) * n, i + (e[1] - i) * a], ze = (e, t, i = 0) => {
56
+ if (!t.gridGap) return Be(e);
54
57
  const n = e + i, a = n >= 0 ? t.gridGap : -t.gridGap;
55
58
  return n + a / 2 - (n + a / 2) % a - i;
56
- }, Na = (e, t, i, n, a, o, d) => {
57
- if (n.mode === "translate") return pe(ma(i, n.originalShape, n.cursorStartPosition, a, o), a);
59
+ }, ho = (e, t, i, n, a, o, r) => {
60
+ if (n.mode === "translate") return pe(Oa(i, n.originalShape, n.cursorStartPosition, a, o), a);
58
61
  if (n.mode === "rotate") {
59
- const r = n.originalShape.computed.center[0] - n.cursorStartPosition[0], s = n.originalShape.computed.center[1] - n.cursorStartPosition[1], l = n.originalShape.computed.center[0] - i[0], h = n.originalShape.computed.center[1] - i[1], c = ((f, v, p) => v.gridGap || p ? f + Math.PI / 18 / 2 - (f + Math.PI / 18 / 2) % (Math.PI / 18) : Ve(f, 3))(Math.atan2(h, l) - Math.atan2(s, r), a, o), u = Y(n.originalShape).map((f) => Ne(go(f, c, n.originalShape.computed.center), a));
62
+ const l = n.originalShape.computed.center[0] - n.cursorStartPosition[0], s = n.originalShape.computed.center[1] - n.cursorStartPosition[1], c = n.originalShape.computed.center[0] - i[0], h = n.originalShape.computed.center[1] - i[1], d = ((p, f, m) => f.gridGap || m ? p + Math.PI / 18 / 2 - (p + Math.PI / 18 / 2) % (Math.PI / 18) : Be(p, 3))(Math.atan2(h, c) - Math.atan2(s, l), a, o), u = _(n.originalShape).map((p) => _e(Na(p, d, n.originalShape.computed.center), a));
60
63
  return pe(u, a);
61
64
  }
62
- return n.mode === "resize" ? pe(vo(e, i, n.originalShape, n, a, o, d), a) : n.mode === "brush" ? pe(Y(t).map((r) => ((s, l, h) => {
63
- const c = { ...s, points: Le(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(l[0]), Math.round(l[1])]], s.points) };
64
- return ut(c, h);
65
- })(r, i, a)), a) : t;
66
- }, yt = (e) => {
65
+ return n.mode === "resize" ? pe(Do(e, i, n.originalShape, n, a, o, r), a) : n.mode === "brush" ? pe(_(t).map((l) => ((s, c, h) => {
66
+ const d = { ...s, points: Xe(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(c[0]), Math.round(c[1])]], s.points) };
67
+ return Zt(d, h);
68
+ })(l, i, a)), a) : t;
69
+ }, Wt = (e) => {
67
70
  const t = new Path2D();
68
71
  return t.rect(e.x, e.y, e.width, e.height), t;
69
- }, Vt = (e) => {
72
+ }, Gt = (e) => {
70
73
  const t = new Path2D();
71
74
  return t.arc(e.x, e.y, e.radius, 0, 2 * Math.PI), t;
72
- }, Zt = (e) => {
75
+ }, _t = (e) => {
73
76
  const t = new Path2D();
74
77
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t;
75
- }, Ba = (e, { brushAlgo: t }) => {
78
+ }, uo = (e, { brushAlgo: t }) => {
76
79
  const i = new Path2D();
77
80
  if (e.points.length < 1) return i;
78
- const n = e.points.flat(), a = n.map((s) => s[0]), o = n.map((s) => s[1]), d = Math.min(...a), r = Math.min(...o);
79
- for (const s of e.points) if (s.length) if (s.length === 1) i.rect(...Ee(s[0], d, r, e.scaleX, e.scaleY), 1, 1);
80
- else if (i.moveTo(...Ee(s[0], d, r, e.scaleX, e.scaleY)), t === "quadratic") {
81
- for (let l = 0; l < s.slice(1).length - 2; l++) {
82
- const h = Ee(s[l], d, r, e.scaleX, e.scaleY), c = Ee(s[l + 1], d, r, e.scaleX, e.scaleY), u = (h[0] + c[0]) / 2, f = (h[1] + c[1]) / 2;
83
- i.quadraticCurveTo(...h, u, f);
81
+ const n = e.points.flat(), a = n.map((s) => s[0]), o = n.map((s) => s[1]), r = Math.min(...a), l = Math.min(...o);
82
+ for (const s of e.points) if (s.length) if (s.length === 1) i.rect(...Ge(s[0], r, l, e.scaleX, e.scaleY), 1, 1);
83
+ else if (i.moveTo(...Ge(s[0], r, l, e.scaleX, e.scaleY)), t === "quadratic") {
84
+ for (let c = 0; c < s.slice(1).length - 2; c++) {
85
+ const h = Ge(s[c], r, l, e.scaleX, e.scaleY), d = Ge(s[c + 1], r, l, e.scaleX, e.scaleY), u = (h[0] + d[0]) / 2, p = (h[1] + d[1]) / 2;
86
+ i.quadraticCurveTo(...h, u, p);
84
87
  }
85
- i.quadraticCurveTo(...Ee(s[s.length - 2], d, r, e.scaleX, e.scaleY), ...Ee(s[s.length - 1], d, r, e.scaleX, e.scaleY));
86
- } else for (const l of s.slice(1)) i.lineTo(...Ee(l, d, r, e.scaleX, e.scaleY));
88
+ i.quadraticCurveTo(...Ge(s[s.length - 2], r, l, e.scaleX, e.scaleY), ...Ge(s[s.length - 1], r, l, e.scaleX, e.scaleY));
89
+ } else for (const c of s.slice(1)) i.lineTo(...Ge(c, r, l, e.scaleX, e.scaleY));
87
90
  return i;
88
- }, Oa = (e, t, i, n) => {
89
- const a = (w) => (1 - w) ** 3 * e[0] + 3 * (1 - w) ** 2 * w * t[0] + 3 * (1 - w) * w ** 2 * i[0] + w ** 3 * n[0], o = (w) => (1 - w) ** 3 * e[1] + 3 * (1 - w) ** 2 * w * t[1] + 3 * (1 - w) * w ** 2 * i[1] + w ** 3 * n[1], d = (w, L, D) => {
90
- const V = w - 2 * L + D, x = -2 * w + 2 * L, Z = w;
91
- if (Math.abs(V) < 1e-10) {
92
- if (Math.abs(x) < 1e-10) return [];
93
- const G = -Z / x;
94
- return G > 0 && G < 1 ? [G] : [];
91
+ }, po = (e, t, i, n) => {
92
+ const a = (g) => (1 - g) ** 3 * e[0] + 3 * (1 - g) ** 2 * g * t[0] + 3 * (1 - g) * g ** 2 * i[0] + g ** 3 * n[0], o = (g) => (1 - g) ** 3 * e[1] + 3 * (1 - g) ** 2 * g * t[1] + 3 * (1 - g) * g ** 2 * i[1] + g ** 3 * n[1], r = (g, P, z) => {
93
+ const N = g - 2 * P + z, D = -2 * g + 2 * P, E = g;
94
+ if (Math.abs(N) < 1e-10) {
95
+ if (Math.abs(D) < 1e-10) return [];
96
+ const Z = -E / D;
97
+ return Z > 0 && Z < 1 ? [Z] : [];
95
98
  }
96
- const A = x * x - 4 * V * Z;
99
+ const A = D * D - 4 * N * E;
97
100
  if (A < 0) return [];
98
- const H = Math.sqrt(A), F = (-x - H) / (2 * V), E = (-x + H) / (2 * V), W = [];
99
- return F > 0 && F < 1 && W.push(F), E > 0 && E < 1 && E !== F && W.push(E), W;
100
- }, r = e[0], s = t[0], l = i[0], h = n[0], c = e[1], u = t[1], f = i[1], v = n[1], p = d(s - r, l - s, h - l), S = d(u - c, f - u, v - f);
101
- let C = Math.min(e[0], n[0]), b = Math.max(e[0], n[0]), Q = Math.min(e[1], n[1]), g = Math.max(e[1], n[1]);
102
- for (const w of p) {
103
- const L = a(w);
104
- C = Math.min(C, L), b = Math.max(b, L);
101
+ const T = Math.sqrt(A), B = (-D - T) / (2 * N), F = (-D + T) / (2 * N), X = [];
102
+ return B > 0 && B < 1 && X.push(B), F > 0 && F < 1 && F !== B && X.push(F), X;
103
+ }, l = e[0], s = t[0], c = i[0], h = n[0], d = e[1], u = t[1], p = i[1], f = n[1], m = r(s - l, c - s, h - c), b = r(u - d, p - u, f - p);
104
+ let x = Math.min(e[0], n[0]), k = Math.max(e[0], n[0]), M = Math.min(e[1], n[1]), S = Math.max(e[1], n[1]);
105
+ for (const g of m) {
106
+ const P = a(g);
107
+ x = Math.min(x, P), k = Math.max(k, P);
105
108
  }
106
- for (const w of S) {
107
- const L = o(w);
108
- Q = Math.min(Q, L), g = Math.max(g, L);
109
+ for (const g of b) {
110
+ const P = o(g);
111
+ M = Math.min(M, P), S = Math.max(S, P);
109
112
  }
110
- return { minX: C, maxX: b, minY: Q, maxY: g };
111
- }, yi = (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]], Si = (e, t, i, n) => ({ cp1: [t[0] + (i[0] - e[0]) / 6, t[1] + (i[1] - e[1]) / 6], cp2: [i[0] - (n[0] - t[0]) / 6, i[1] - (n[1] - t[1]) / 6] }), aa = (e) => {
113
+ return { minX: x, maxX: k, minY: M, maxY: S };
114
+ }, Ti = (e, t) => e.style?.closedPoints === 1 && t.length > 2 ? [t[t.length - 2], ...t, t[0], t[1]] : [t[0], ...t, t[t.length - 1]], Di = (e, t, i, n) => ({ cp1: [t[0] + (i[0] - e[0]) / 6, t[1] + (i[1] - e[1]) / 6], cp2: [i[0] - (n[0] - t[0]) / 6, i[1] - (n[1] - t[1]) / 6] }), wa = (e) => {
112
115
  const t = new Path2D(), i = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
113
116
  if (i.length < 2) return t;
114
117
  t.moveTo(...i[0]);
115
118
  for (const n of i.slice(1)) t.lineTo(...n);
116
119
  return i.length > 2 && e.style?.closedPoints === 1 && t.lineTo(...i[0]), t;
117
- }, Fa = (e) => {
120
+ }, go = (e) => {
118
121
  const t = new Path2D();
119
122
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t.lineTo(...e.points[2]), t.lineTo(...e.points[0]), t;
120
- }, Ya = (e, t) => ({ x: t.x - (e.style?.lineWidth ?? 0) / 2, y: t.y - (e.style?.lineWidth ?? 0) / 2, width: t.width + (e.style?.lineWidth ?? 0), height: t.height + (e.style?.lineWidth ?? 0) }), Be = (e, t, i, n = Ya) => {
121
- const a = t(e, i), o = n(e, a, i), d = [a.x + a.width / 2, a.y + a.height / 2], r = ((s, l, h = 0) => {
123
+ }, fo = (e, t) => ({ x: t.x - (e.style?.lineWidth ?? 0) / 2, y: t.y - (e.style?.lineWidth ?? 0) / 2, width: t.width + (e.style?.lineWidth ?? 0), height: t.height + (e.style?.lineWidth ?? 0) }), it = (e, t, i, n = fo) => {
124
+ const a = t(e, i), o = n(e, a, i), r = [a.x + a.width / 2, a.y + a.height / 2], l = ((s, c, h = 0) => {
122
125
  if (h === 0) return s;
123
- const c = [[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((v) => le({ point: v, origin: l, rotation: h })), u = Math.min(...c.map((v) => v[0])), f = Math.min(...c.map((v) => v[1]));
124
- return { x: u, y: f, width: Math.max(...c.map((v) => v[0])) - u, height: Math.max(...c.map((v) => v[1])) - f };
125
- })(o, d, e.rotation);
126
- return { borders: a, outerBorders: o, center: d, boundingBox: r };
127
- }, pt = (e, t, i) => {
126
+ const d = [[s.x, s.y], [s.x + s.width, s.y], [s.x + s.width, s.y + s.height], [s.x, s.y + s.height]].map((f) => Qe({ point: f, origin: c, rotation: h })), u = Math.min(...d.map((f) => f[0])), p = Math.min(...d.map((f) => f[1]));
127
+ return { x: u, y: p, width: Math.max(...d.map((f) => f[0])) - u, height: Math.max(...d.map((f) => f[1])) - p };
128
+ })(o, r, e.rotation);
129
+ return { borders: a, outerBorders: o, center: r, boundingBox: l };
130
+ }, Ht = (e, t, i) => {
128
131
  const { borders: n } = t;
129
- return { type: "rect", border: yt(n), shapePath: e, line: Zt({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: [Vt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...Gn.map((a) => Vt({ x: n.x + n.width * a[0], y: n.y + n.height * a[1], radius: 7 / i.canvasSize.scaleRatio }))] };
130
- }, Xi = ({ borderStart: e, borderSize: t, vector: i, settings: n, invertedAxe: a, anchor: o }) => {
132
+ return { type: "rect", border: Wt(n), shapePath: e, line: _t({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: [Gt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...ua.map((a) => Gt({ x: n.x + n.width * a[0], y: n.y + n.height * a[1], radius: 7 / i.canvasSize.scaleRatio }))] };
133
+ }, cn = ({ borderStart: e, borderSize: t, vector: i, settings: n, invertedAxe: a, anchor: o }) => {
131
134
  switch (o) {
132
135
  case 0: {
133
136
  if (a) {
134
- const r = Math.max(0, i - t) + 2 * n.selectionPadding;
135
- return [e + t - 2 * n.selectionPadding, r];
137
+ const l = Math.max(0, i - t) + 2 * n.selectionPadding;
138
+ return [e + t - 2 * n.selectionPadding, l];
136
139
  }
137
- const d = Math.max(2 * n.selectionPadding, t - i);
138
- return [e + t - d, d];
140
+ const r = Math.max(2 * n.selectionPadding, t - i);
141
+ return [e + t - r, r];
139
142
  }
140
143
  case 0.5:
141
144
  return [e, t];
142
145
  case 1:
143
146
  if (a) {
144
- const d = Math.min(e, e + t + i);
145
- return [d, e - d + 2 * n.selectionPadding];
147
+ const r = Math.min(e, e + t + i);
148
+ return [r, e - r + 2 * n.selectionPadding];
146
149
  }
147
150
  return [e, Math.max(2 * n.selectionPadding, t + i)];
148
151
  default:
149
152
  return [0, 0];
150
153
  }
151
- }, Xa = ({ borderX: e, borderWidth: t, borderY: i, borderHeight: n, center: a, originalShape: o }) => {
152
- const d = [e + t / 2 - a[0], i + n / 2 - a[1]], [r, s] = le({ point: d, rotation: -(o.rotation ?? 0) });
153
- return { borderX: Ve(e + r - d[0]), borderWidth: Ve(t), borderY: Ve(i + s - d[1]), borderHeight: Ve(n) };
154
- }, $a = (e, t, i, n) => {
155
- const a = t.x + t.width / 2, o = t.y + t.height / 2, d = i ? 2 * e.borderWidth + t.width : Math.abs(t.width + 2 * (e.borderWidth - t.width)), r = n ? 2 * e.borderHeight + t.height : Math.abs(t.height + 2 * (e.borderHeight - t.height));
156
- return { ...e, borderHeight: r, borderWidth: d, borderX: a - d / 2, borderY: o - r / 2 };
157
- }, it = (e, t, i, n, a = !1, o = !1) => {
158
- const { center: d, borders: r } = t.computed, s = le({ origin: d, point: e, rotation: t.rotation }), l = i.anchor[0] === 0 && s[0] >= r.x + r.width - n.selectionPadding || i.anchor[0] === 1 && s[0] <= r.x + n.selectionPadding, h = i.anchor[1] === 0 && s[1] >= r.y + r.height - n.selectionPadding || i.anchor[1] === 1 && s[1] <= r.y + n.selectionPadding, c = [we(s[0], n, i.anchor[0] === 0 && !l || i.anchor[0] === 1 && l ? n.selectionPadding : -n.selectionPadding), we(s[1], n, i.anchor[1] === 0 && !h || i.anchor[1] === 1 && h ? n.selectionPadding : -n.selectionPadding)], u = n.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] : le({ origin: d, point: i.cursorStartPosition, rotation: t.rotation }), f = [c[0] - u[0], c[1] - u[1]], [v, p] = Xi({ borderStart: r.x, borderSize: r.width, vector: f[0], settings: n, invertedAxe: l, anchor: i.anchor[0] }), [S, C] = Xi({ borderStart: r.y, borderSize: r.height, vector: f[1], settings: n, invertedAxe: h, anchor: i.anchor[1] }), b = a ? ((Q, g, w, L, D, V, x, Z, A, H, F) => {
159
- const { selectionPadding: E } = F, W = "ratio" in A && A.ratio ? A.ratio : (Q.width - 2 * E || 1) / (Q.height - 2 * E || 1), G = (L - 2 * E) / (V - 2 * E);
160
- let _, z, y, M;
161
- return H.anchor[0] !== 0.5 && H.anchor[1] !== 0.5 ? G < W ? (z = D, M = V, y = (V - 2 * E) * W + 2 * E, _ = H.anchor[0] === 0 ? x ? Q.x + Q.width - 2 * E : Q.x + (Q.width - y) : x ? Q.x - y + 2 * E : Q.x) : (_ = w, y = L, M = (L - 2 * E) / W + 2 * E, z = H.anchor[1] === 0 ? Z ? Q.y + Q.height - 2 * E : Q.y + (Q.height - M) : Z ? Q.y - M + 2 * E : Q.y) : H.anchor[0] !== 0.5 ? (_ = w, y = L, M = (L - 2 * E) / W + 2 * E, z = Q.y + (Q.height - M) / 2) : (z = D, M = V, y = (V - 2 * E) * W + 2 * E, _ = Q.x + (Q.width - y) / 2), { borderX: _, borderWidth: y, borderY: z, borderHeight: M, center: g, originalShape: A };
162
- })(r, d, v, p, S, C, l, h, t, i, n) : { borderX: v, borderWidth: p, borderY: S, borderHeight: C, center: d, originalShape: t };
163
- return { ...Xa(o ? $a(b, r, l, h) : b), isXinverted: l, isYinverted: h };
164
- }, zt = (e, t) => {
165
- const i = yt(e), n = ((a, o) => Be(a, Qi, o))(e, t);
166
- return { ...e, path: i, computed: n, selection: pt(i, n, t) };
167
- }, Ua = zt, oa = (e, t, i, n = 0, a = 0) => {
168
- const o = { toolId: e.id, type: e.type, id: ue(`${e.type}_`), x: t[0], y: t[1], width: n, height: a, style: { opacity: e.settings.opacity.default, fillColor: e.settings.fillColor.default, strokeColor: e.settings.strokeColor.default, lineWidth: e.settings.lineWidth.default, lineDash: e.settings.lineDash.default } };
169
- return zt(o, i);
170
- }, qa = (e, t) => {
154
+ }, dn = ({ borderX: e, borderWidth: t, borderY: i, borderHeight: n, center: a, originalShape: o }) => {
155
+ const r = [e + t / 2 - a[0], i + n / 2 - a[1]], [l, s] = Qe({ point: r, rotation: -(o.rotation ?? 0) });
156
+ return { borderX: Be(e + l - r[0]), borderWidth: Be(t), borderY: Be(i + s - r[1]), borderHeight: Be(n) };
157
+ }, vo = (e, t, i, n) => {
158
+ const a = t.x + t.width / 2, o = t.y + t.height / 2, r = i ? 2 * e.borderWidth + t.width : Math.abs(t.width + 2 * (e.borderWidth - t.width)), l = n ? 2 * e.borderHeight + t.height : Math.abs(t.height + 2 * (e.borderHeight - t.height));
159
+ return { ...e, borderHeight: l, borderWidth: r, borderX: a - r / 2, borderY: o - l / 2 };
160
+ }, vt = (e, t, i, n, a = !1, o = !1) => {
161
+ const { center: r, borders: l } = t.computed, s = Qe({ origin: r, point: e, rotation: t.rotation }), c = o && a ? [l.x + l.width / 2, l.x + l.width / 2] : [l.x + l.width - n.selectionPadding, l.x + n.selectionPadding], h = o && a ? [l.y + l.height / 2, l.y + l.height / 2] : [l.y + l.height - n.selectionPadding, l.y + n.selectionPadding], d = i.anchor[0] === 0 && s[0] >= c[0] || i.anchor[0] === 1 && s[0] <= c[1], u = i.anchor[1] === 0 && s[1] >= h[0] || i.anchor[1] === 1 && s[1] <= h[1], p = [ze(s[0], n, i.anchor[0] === 0 && !d || i.anchor[0] === 1 && d ? n.selectionPadding : -n.selectionPadding), ze(s[1], n, i.anchor[1] === 0 && !u || i.anchor[1] === 1 && u ? n.selectionPadding : -n.selectionPadding)];
162
+ if (a && o) {
163
+ const g = (({ roundCursorPosition: P, borders: z, center: N, selectionMode: D, originalShape: E, settings: A }) => {
164
+ const { selectionPadding: T } = A, B = Math.max(1, z.width - 2 * T), F = Math.max(1, z.height - 2 * T), X = "ratio" in E && E.ratio ? E.ratio : B / F, Z = z.x + z.width / 2, ne = z.y + z.height / 2;
165
+ let I = 1;
166
+ if (D.anchor[0] !== 0.5 && D.anchor[1] !== 0.5) {
167
+ const C = [(D.anchor[0] - 0.5) * B, (D.anchor[1] - 0.5) * F], $ = [P[0] - Z, P[1] - ne], Q = Math.hypot(C[0], C[1]) || 1;
168
+ I = Math.hypot($[0], $[1]) / Q;
169
+ } else if (D.anchor[0] === 0.5) {
170
+ const C = (D.anchor[1] - 0.5) * F, $ = P[1] - ne, Q = Math.abs(C) || 1;
171
+ I = Math.abs($) / Q;
172
+ } else {
173
+ const C = (D.anchor[0] - 0.5) * B, $ = P[0] - Z, Q = Math.abs(C) || 1;
174
+ I = Math.abs($) / Q;
175
+ }
176
+ const j = 2 * T / (B + 2 * T), ee = B * Math.max(I, j), se = ee + 2 * T, he = ee / X + 2 * T;
177
+ return { borderX: Z - se / 2, borderY: ne - he / 2, borderWidth: se, borderHeight: he, center: N, originalShape: E };
178
+ })({ roundCursorPosition: p, borders: l, center: r, selectionMode: i, originalShape: t, settings: n });
179
+ return { ...dn(g), isXinverted: d, isYinverted: u };
180
+ }
181
+ const f = n.gridGap ? [i.anchor[0] === 0 ? l.x : i.anchor[0] === 0.5 ? l.x + l.width / 2 : l.x + l.width, i.anchor[1] === 0 ? l.y : i.anchor[1] === 0.5 ? l.y + l.height / 2 : l.y + l.height] : Qe({ origin: r, point: i.cursorStartPosition, rotation: t.rotation }), m = [p[0] - f[0], p[1] - f[1]], [b, x] = cn({ borderStart: l.x, borderSize: l.width, vector: m[0], settings: n, invertedAxe: d, anchor: i.anchor[0] }), [k, M] = cn({ borderStart: l.y, borderSize: l.height, vector: m[1], settings: n, invertedAxe: u, anchor: i.anchor[1] }), S = a ? ((g, P, z, N, D, E, A, T, B, F, X) => {
182
+ const { selectionPadding: Z } = X, ne = "ratio" in B && B.ratio ? B.ratio : (g.width - 2 * Z || 1) / (g.height - 2 * Z || 1), I = (N - 2 * Z) / (E - 2 * Z);
183
+ let j, ee, se, he;
184
+ return F.anchor[0] !== 0.5 && F.anchor[1] !== 0.5 ? I < ne ? (ee = D, he = E, se = (E - 2 * Z) * ne + 2 * Z, j = F.anchor[0] === 0 ? A ? g.x + g.width - 2 * Z : g.x + (g.width - se) : A ? g.x - se + 2 * Z : g.x) : (j = z, se = N, he = (N - 2 * Z) / ne + 2 * Z, ee = F.anchor[1] === 0 ? T ? g.y + g.height - 2 * Z : g.y + (g.height - he) : T ? g.y - he + 2 * Z : g.y) : F.anchor[0] !== 0.5 ? (j = z, se = N, he = (N - 2 * Z) / ne + 2 * Z, ee = g.y + (g.height - he) / 2) : (ee = D, he = E, se = (E - 2 * Z) * ne + 2 * Z, j = g.x + (g.width - se) / 2), { borderX: j, borderWidth: se, borderY: ee, borderHeight: he, center: P, originalShape: B };
185
+ })(l, r, b, x, k, M, d, u, t, i, n) : { borderX: b, borderWidth: x, borderY: k, borderHeight: M, center: r, originalShape: t };
186
+ return { ...dn(o ? vo(S, l, d, u) : S), isXinverted: d, isYinverted: u };
187
+ }, Kt = (e, t) => {
188
+ const i = Wt(e), n = it(e, Ei, t);
189
+ return { ...e, path: i, computed: n, selection: Ht(i, n, t) };
190
+ }, mo = Kt, xa = (e, t, i, n = 0, a = 0) => {
191
+ const o = { toolId: e.id, type: e.type, id: Le(`${e.type}_`), x: t[0], y: t[1], width: n, height: a, style: { opacity: e.settings.opacity.default, fillColor: e.settings.fillColor.default, strokeColor: e.settings.strokeColor.default, lineWidth: e.settings.lineWidth.default, lineDash: e.settings.lineDash.default } };
192
+ return Kt(o, i);
193
+ }, yo = (e, t) => {
171
194
  e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
172
- }, Qi = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), $i = (e, t, i, [n, a] = [!1, !1]) => {
173
- const o = e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (n ? 0 : i.width) : i.x + (n ? i.width : 0), d = e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (a ? 0 : i.height) : i.y + (a ? i.height : 0);
174
- return ri([o, d], i.rotation ?? 0, t);
175
- }, Ui = (e, t, i, n, a, o, d, r = "replace") => {
195
+ }, Ei = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), hn = (e, t, i, [n, a] = [!1, !1]) => {
196
+ const o = e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (n ? 0 : i.width) : i.x + (n ? i.width : 0), r = e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (a ? 0 : i.height) : i.y + (a ? i.height : 0);
197
+ return wi([o, r], i.rotation ?? 0, t);
198
+ }, Ma = (e, t, i) => {
199
+ const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation, c = mt(e, t, i), h = (e.width || 1) * r, d = (e.height || 1) * l, u = yt(i, c.x, c.y, h, d);
200
+ return Kt({ ...e, width: h, height: d, x: u[0] - h / 2, y: u[1] - d / 2, rotation: s ? -(e.rotation ?? 0) : e.rotation ?? 0 }, o);
201
+ }, Ot = (e, t, i, n, a, o, r, l = "replace") => {
176
202
  let s = !1;
177
203
  if (a) {
178
- s = ft(e, a, i, n, !0, o ? 20 : void 0);
179
- const h = ((c, u, f) => {
180
- if (c.mode === "translate") return { mode: "translate", cursorStartPosition: f, originalShape: u, hasBeenDuplicated: !1, dateStart: Date.now(), selectedShapesLengthAtMouseDown: Y(u).length };
181
- if (c.mode === "rotate") {
182
- const { center: v } = u.computed;
183
- return { mode: "rotate", cursorStartPosition: f, originalShape: u, center: [v[0], v[1]], selectedShapesLengthAtMouseDown: Y(u).length };
204
+ s = Et(e, a, i, n, !0, o ? 20 : void 0);
205
+ const h = ((d, u, p) => {
206
+ if (d.mode === "translate") return { mode: "translate", cursorStartPosition: p, originalShape: u, hasBeenDuplicated: !1, dateStart: Date.now(), selectedShapesLengthAtMouseDown: _(u).length };
207
+ if (d.mode === "rotate") {
208
+ const { center: f } = u.computed;
209
+ return { mode: "rotate", cursorStartPosition: p, originalShape: u, center: [f[0], f[1]], selectedShapesLengthAtMouseDown: _(u).length };
184
210
  }
185
- return c.mode === "resize" ? { mode: "resize", cursorStartPosition: f, originalShape: u, anchor: c.anchor, selectedShapesLengthAtMouseDown: Y(u).length } : void 0;
211
+ return d.mode === "resize" ? { mode: "resize", cursorStartPosition: p, originalShape: u, anchor: d.anchor, selectedShapesLengthAtMouseDown: _(u).length } : void 0;
186
212
  })(s || { mode: "default" }, a, i);
187
213
  if (h?.mode === "resize" || h?.mode === "rotate") return { shape: a, mode: h };
188
214
  }
189
- const l = t.find((h) => Y(a).find((c) => h.id === c?.id) ? s && ft(e, h, i, n, !0, o ? 20 : void 0) : !!da(e, h, i, n)) ?? (s ? a : void 0);
190
- if (a && a?.id === l?.id) return { shape: a, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: a, selectedShapesLengthAtMouseDown: Y(a).length } };
191
- if (l) {
192
- if (r === "add") {
193
- const c = pe(sa(a, [l]), n);
194
- return { shape: c, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: c, selectedShapesLengthAtMouseDown: Y(a).length } };
215
+ const c = t.find((h) => _(a).find((d) => h.id === d?.id) ? s && Et(e, h, i, n, !0, o ? 20 : void 0) : !!La(e, h, i, n)) ?? (s ? a : void 0);
216
+ if (a && a?.id === c?.id) return { shape: a, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: a, selectedShapesLengthAtMouseDown: _(a).length } };
217
+ if (c) {
218
+ if (l === "add") {
219
+ const d = pe(Ca(a, [c]), n);
220
+ return { shape: d, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: d, selectedShapesLengthAtMouseDown: _(a).length } };
195
221
  }
196
- if (r === "remove") {
197
- const c = pe(Ga(a, l), n);
198
- return { shape: c, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: c, selectedShapesLengthAtMouseDown: Y(a).length } };
222
+ if (l === "remove") {
223
+ const d = pe(So(a, c), n);
224
+ return { shape: d, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: d, selectedShapesLengthAtMouseDown: _(a).length } };
199
225
  }
200
- const h = Y(a).find((c) => c.id === l?.id) ? a : pe([l], n);
201
- return { shape: h, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: h, selectedShapesLengthAtMouseDown: Y(a).length } };
226
+ const h = _(a).find((d) => d.id === c?.id) ? a : pe([c], n);
227
+ return { shape: h, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: h, selectedShapesLengthAtMouseDown: _(a).length } };
202
228
  }
203
- return { shape: r !== "replace" ? a : void 0, mode: { mode: d ? "selectionFrame" : "default" } };
229
+ return { shape: l !== "replace" ? a : void 0, mode: { mode: r ? "selectionFrame" : "default" } };
204
230
  }, pe = (e, t) => {
205
231
  if (!e.length) return;
206
232
  if (e.length === 1) return e[0];
207
- const i = e.some((d) => d.rotation !== e[0].rotation) ? 0 : e[0]?.rotation ?? 0, n = ((d, r, s) => {
208
- const l = d.map((g) => [[g.computed.borders.x + s.selectionPadding, g.computed.borders.y + s.selectionPadding], [g.computed.borders.x - s.selectionPadding + g.computed.borders.width, g.computed.borders.y + s.selectionPadding], [g.computed.borders.x - s.selectionPadding + g.computed.borders.width, g.computed.borders.y - s.selectionPadding + g.computed.borders.height], [g.computed.borders.x + s.selectionPadding, g.computed.borders.y - s.selectionPadding + g.computed.borders.height]].map((w) => {
209
- const L = le({ point: [w[0], w[1]], origin: g.computed.center, rotation: -(g.rotation ?? 0) });
210
- return le({ point: [L[0], L[1]], origin: [0, 0], rotation: r });
211
- })), h = Math.min(...l.flatMap((g) => [g[0][0], g[1][0], g[2][0], g[3][0]])), c = Math.min(...l.flatMap((g) => [g[0][1], g[1][1], g[2][1], g[3][1]])), u = Math.max(...l.flatMap((g) => [g[0][0], g[1][0], g[2][0], g[3][0]])), f = Math.max(...l.flatMap((g) => [g[0][1], g[1][1], g[2][1], g[3][1]])), v = [(h + u) / 2, (c + f) / 2], p = le({ point: v, origin: [0, 0], rotation: -r }), S = [v[0] - p[0], v[1] - p[1]], C = Ve(h - S[0]), b = Ve(u - S[0]), Q = Ve(c - S[1]);
212
- return { width: b - C, height: Ve(f - S[1]) - Q, x: C, y: Q };
213
- })(e, i, t), a = oa({ id: "group_selection", type: "rect", settings: In }, [n.x, n.y], t, n.width, n.height), o = e.slice(1).reduce((d, r) => {
214
- const s = r.style ?? {}, l = {};
215
- for (const h in s) d[h] !== void 0 && s[h] !== void 0 && d[h] === s[h] && (l[h] = d[h]);
216
- return l;
233
+ const i = e.some((r) => r.rotation !== e[0].rotation) ? 0 : e[0]?.rotation ?? 0, n = ((r, l, s) => {
234
+ const c = r.map((S) => [[S.computed.borders.x + s.selectionPadding, S.computed.borders.y + s.selectionPadding], [S.computed.borders.x - s.selectionPadding + S.computed.borders.width, S.computed.borders.y + s.selectionPadding], [S.computed.borders.x - s.selectionPadding + S.computed.borders.width, S.computed.borders.y - s.selectionPadding + S.computed.borders.height], [S.computed.borders.x + s.selectionPadding, S.computed.borders.y - s.selectionPadding + S.computed.borders.height]].map((g) => {
235
+ const P = Qe({ point: [g[0], g[1]], origin: S.computed.center, rotation: -(S.rotation ?? 0) });
236
+ return Qe({ point: [P[0], P[1]], origin: [0, 0], rotation: l });
237
+ })), h = Math.min(...c.flatMap((S) => [S[0][0], S[1][0], S[2][0], S[3][0]])), d = Math.min(...c.flatMap((S) => [S[0][1], S[1][1], S[2][1], S[3][1]])), u = Math.max(...c.flatMap((S) => [S[0][0], S[1][0], S[2][0], S[3][0]])), p = Math.max(...c.flatMap((S) => [S[0][1], S[1][1], S[2][1], S[3][1]])), f = [(h + u) / 2, (d + p) / 2], m = Qe({ point: f, origin: [0, 0], rotation: -l }), b = [f[0] - m[0], f[1] - m[1]], x = Be(h - b[0]), k = Be(u - b[0]), M = Be(d - b[1]);
238
+ return { width: k - x, height: Be(p - b[1]) - M, x, y: M };
239
+ })(e, i, t), a = xa({ id: "group_selection", type: "rect", settings: ea }, [n.x, n.y], t, n.width, n.height), o = e.slice(1).reduce((r, l) => {
240
+ const s = l.style ?? {}, c = {};
241
+ for (const h in s) r[h] !== void 0 && s[h] !== void 0 && r[h] === s[h] && (c[h] = r[h]);
242
+ return c;
217
243
  }, e[0].style ?? {});
218
- return { id: e.map((d) => d.id).join("-"), type: "group", shapes: e, rotation: i, visible: !0, locked: !1, selection: a.selection, x: a.x, y: a.y, width: a.width, height: a.height, style: o, computed: a.computed, path: a.path };
219
- }, qi = (e, t) => (i) => {
220
- if (!i) return;
221
- const n = i.type === "group" ? i.shapes.map((a) => e(a, t)) : [e(i, t)];
222
- return pe(n, t);
223
- }, Y = (e) => e ? e.type === "group" ? e.shapes : [e] : [], sa = (e, t) => {
224
- const i = Y(e);
244
+ return { id: e.map((r) => r.id).join("-"), type: "group", shapes: e, rotation: i, visible: !0, locked: !1, selection: a.selection, x: a.x, y: a.y, width: a.width, height: a.height, style: o, computed: a.computed, path: a.path };
245
+ }, _ = (e) => e ? e.type === "group" ? e.shapes : [e] : [], Ca = (e, t) => {
246
+ const i = _(e);
225
247
  return [.../* @__PURE__ */ new Set([...i, ...t])];
226
- }, Ga = (e, t) => Y(e).filter((i) => i.id !== t.id), ra = (e) => {
248
+ }, So = (e, t) => _(e).filter((i) => i.id !== t.id), ka = (e) => {
227
249
  const { clientX: t = 0, clientY: i = 0 } = "touches" in e && e.touches[0] ? e.touches[0] : "changedTouches" in e && e.changedTouches[0] ? e.changedTouches[0] : "clientX" in e ? e : {};
228
250
  return { clientX: t, clientY: i };
229
- }, la = (e, t, i) => {
230
- const { clientX: n, clientY: a } = ra(e), o = t.getBoundingClientRect();
251
+ }, Pa = (e, t, i) => {
252
+ const { clientX: n, clientY: a } = ka(e), o = t.getBoundingClientRect();
231
253
  return [(n - o.left) / i.scaleRatio, (a - o.top) / i.scaleRatio];
232
- }, st = (e, t, i) => {
233
- const { clientX: n, clientY: a } = ra(e), o = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
254
+ }, ft = (e, t, i) => {
255
+ const { clientX: n, clientY: a } = ka(e), o = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
234
256
  return [(n - o.left) * (i.canvasSize.width / o.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (a - o.top) * (i.canvasSize.height / o.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
235
- }, rt = (e) => "touches" in e, Re = (e, t, [i, n]) => le({ origin: [i, n], point: e, rotation: t }), ri = (e, t, [i, n]) => le({ origin: [i, n], point: e, rotation: -t }), Ct = (e, t, i) => i ? ia(e, { x: t[0], y: t[1], radius: i }) : ((n, a) => a[0] >= n.x && a[0] <= n.x + n.width && a[1] >= n.y && a[1] <= n.y + n.height)(e, t), ft = (e, t, i, n, a = !1, o = 0) => {
236
- const d = Y(t).length > 1 ? t : Y(t)[0];
237
- if (!d || d.locked) return !1;
238
- const { borders: r, center: s } = d.computed, l = Re(i, d.rotation ?? 0, s);
257
+ }, at = (e) => "touches" in e, tt = (e, t, [i, n]) => Qe({ origin: [i, n], point: e, rotation: t }), wi = (e, t, [i, n]) => Qe({ origin: [i, n], point: e, rotation: -t }), Ft = (e, t, i) => i ? Sa(e, { x: t[0], y: t[1], radius: i }) : ((n, a) => a[0] >= n.x && a[0] <= n.x + n.width && a[1] >= n.y && a[1] <= n.y + n.height)(e, t), Et = (e, t, i, n, a = !1, o = 0) => {
258
+ const r = _(t).length > 1 ? t : _(t)[0];
259
+ if (!r) return !1;
260
+ const { borders: l, center: s } = r.computed, c = tt(i, r.rotation ?? 0, s);
239
261
  if (a) {
240
- const h = ((c, u, f, v = 0) => {
241
- const { canvasSize: { scaleRatio: p } } = f, { borders: S } = c.computed;
242
- if (c.type === "line" || c.type === "polygon" || c.type === "curve") {
243
- for (let C = 0; C < c.points.length; C++) if (Ct({ x: c.points[C][0] - 7 / p, y: c.points[C][1] - 7 / p, width: Je / p, height: Je / p }, u, v)) return { mode: "resize", anchor: C };
262
+ const h = ((d, u, p, f = 0) => {
263
+ const { canvasSize: { scaleRatio: m } } = p, { borders: b } = d.computed;
264
+ if (d.type === "line" || d.type === "polygon" || d.type === "curve") {
265
+ for (let x = 0; x < d.points.length; x++) if (Ft({ x: d.points[x][0] - 7 / m, y: d.points[x][1] - 7 / m, width: gt / m, height: gt / m }, u, f)) return { mode: "resize", anchor: x };
244
266
  } else {
245
- if (Ct({ x: S.x + S.width / 2 - 7 / p, y: S.y - Je / p - 16 / p, width: Je / p, height: Je / p }, u, v)) return { mode: "rotate" };
246
- for (const C of Gn) if (Ct({ x: S.x + S.width * C[0] - 7 / p, y: S.y + S.height * C[1] - 7 / p, width: Je / p, height: Je / p }, u, v)) return { mode: "resize", anchor: C };
267
+ if (Ft({ x: b.x + b.width / 2 - 7 / m, y: b.y - gt / m - 16 / m, width: gt / m, height: gt / m }, u, f)) return { mode: "rotate" };
268
+ for (const x of ua) if (Ft({ x: b.x + b.width * x[0] - 7 / m, y: b.y + b.height * x[1] - 7 / m, width: gt / m, height: gt / m }, u, f)) return { mode: "resize", anchor: x };
247
269
  }
248
270
  return !1;
249
- })(d, l, n, o);
271
+ })(r, c, n, o);
250
272
  if (h) return h;
251
273
  }
252
- return d.selection?.type === "line" ? (e.lineWidth = (d.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(bi(d, !0) ? e.isPointInPath(d.path, l[0], l[1]) : e.isPointInStroke(d.path, l[0], l[1])) && { mode: "translate" }) : !!Ct(r, l, 15 + o) && { mode: "translate" };
253
- }, Gi = (e, t, i, n, a = 50) => {
274
+ return r.selection?.type === "line" ? (e.lineWidth = (r.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(Ii(r, !0) ? e.isPointInPath(r.path, c[0], c[1]) : e.isPointInStroke(r.path, c[0], c[1])) && { mode: "translate" }) : !!Ft(l, c, 15 + o) && { mode: "translate" };
275
+ }, un = (e, t, i, n, a = 50) => {
254
276
  if (t.locked || t.points.length < 2) return !1;
255
- const { center: o } = t.computed, d = Re(i, t.rotation ?? 0, o);
277
+ const { center: o } = t.computed, r = tt(i, t.rotation ?? 0, o);
256
278
  e.lineWidth = (t.style?.lineWidth ?? 0) + a / n.canvasZoom;
257
- const r = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
258
- for (let s = 0; s < r.length - 1; s++) {
259
- const l = Zt({ points: [r[s], r[s + 1]] });
260
- if (e.isPointInStroke(l, d[0], d[1])) return { lineIndex: s };
279
+ const l = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
280
+ for (let s = 0; s < l.length - 1; s++) {
281
+ const c = _t({ points: [l[s], l[s + 1]] });
282
+ if (e.isPointInStroke(c, r[0], r[1])) return { lineIndex: s };
261
283
  }
262
284
  return !1;
263
- }, bi = (e, t = !1) => !(!t || !["curve", "polygon"].includes(e.type)) || e.style?.fillColor && e.style?.fillColor !== "transparent" || ["picture", "text"].includes(e.type), da = (e, t, i, n) => {
264
- if (t.locked) return !1;
265
- const { center: a } = t.computed, o = Re(i, t.rotation ?? 0, a);
266
- return e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(bi(t) ? e.isPointInPath(t.path, o[0], o[1]) : e.isPointInStroke(t.path, o[0], o[1])) && { mode: "translate" };
285
+ }, Ii = (e, t = !1) => !(!t || !["curve", "polygon"].includes(e.type)) || e.style?.fillColor && e.style?.fillColor !== "transparent" || ["picture", "text"].includes(e.type), La = (e, t, i, n) => {
286
+ const { center: a } = t.computed, o = tt(i, t.rotation ?? 0, a);
287
+ return e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(Ii(t) ? e.isPointInPath(t.path, o[0], o[1]) : e.isPointInStroke(t.path, o[0], o[1])) && { mode: "translate" };
267
288
  };
268
- function li(e, t) {
289
+ function xi(e, t) {
269
290
  const i = Math.max(e.x, t.x), n = Math.max(e.y, t.y), a = Math.min(e.x + (e.width || 1), t.x + (t.width || 1)), o = Math.min(e.y + (e.height || 1), t.y + (t.height || 1));
270
291
  if (i < a && n < o) return { x: i, y: n, width: a - i, height: o - n };
271
292
  }
272
- const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, checkFill: d }) => {
273
- for (let r = 0; r < n; r += n / 2) for (let s = 0; s < n; s += n / 2) for (let l = r + i.x; l < i.x + i.width; l += n) for (let h = s + i.y; h < i.y + i.height; h += n) {
274
- const c = Re([l, h], o, a);
275
- if (d ? e.isPointInPath(t, c[0], c[1]) : e.isPointInStroke(t, c[0], c[1])) return !0;
293
+ const pn = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, checkFill: r }) => {
294
+ for (let l = 0; l < n; l += n / 2) for (let s = 0; s < n; s += n / 2) for (let c = l + i.x; c < i.x + i.width; c += n) for (let h = s + i.y; h < i.y + i.height; h += n) {
295
+ const d = tt([c, h], o, a);
296
+ if (r ? e.isPointInPath(t, d[0], d[1]) : e.isPointInStroke(t, d[0], d[1])) return !0;
276
297
  }
277
298
  return !1;
278
- }, wi = (e, t, i, n) => ({ type: "line", border: yt(i.borders), shapePath: e, anchors: [...t.points.map((a) => Vt({ x: a[0], y: a[1], radius: 7 / n.canvasSize.scaleRatio }))] }), Pe = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], di = ({ size: e, zoom: t, newOffset: [i, n], canvasSize: a }) => e === "infinite" ? { zoom: t, offset: [i, n] } : t < 1 ? { zoom: t, offset: [-(a.realWidth - a.realWidth / t) / 2, -(a.realHeight - a.realHeight / t) / 2] } : { zoom: t, offset: [We(i, a.realWidth / t - a.realWidth, 0), We(n, a.realHeight / t - a.realHeight, 0)] }, ci = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: n, zoom: a, centerPoint: o }) => {
279
- const d = e === "fixed" && a < 1 ? [t.realWidth / 2, t.realHeight / 2] : o, r = i[0] - (d[0] / n - d[0] / a), s = i[1] - (d[1] / n - d[1] / a);
280
- return { offset: e === "infinite" ? [r, s] : a < 1 ? [-(t.realWidth - t.realWidth / a) / 2, -(t.realHeight - t.realHeight / a) / 2] : [We(r, t.realWidth / a - t.realWidth, 0), We(s, t.realHeight / a - t.realHeight, 0)], zoom: a };
281
- }, ca = (e) => {
299
+ }, Wi = (e, t, i, n) => ({ type: "line", border: Wt(i.borders), shapePath: e, anchors: [...t.points.map((a) => Gt({ x: a[0], y: a[1], radius: 7 / n.canvasSize.scaleRatio }))] }), Re = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], Mi = ({ size: e, zoom: t, newOffset: [i, n], canvasSize: a }) => e === "infinite" ? { zoom: t, offset: [i, n] } : t < 1 ? { zoom: t, offset: [-(a.realWidth - a.realWidth / t) / 2, -(a.realHeight - a.realHeight / t) / 2] } : { zoom: t, offset: [et(i, a.realWidth / t - a.realWidth, 0), et(n, a.realHeight / t - a.realHeight, 0)] }, Ci = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: n, zoom: a, centerPoint: o }) => {
300
+ const r = e === "fixed" && a < 1 ? [t.realWidth / 2, t.realHeight / 2] : o, l = i[0] - (r[0] / n - r[0] / a), s = i[1] - (r[1] / n - r[1] / a);
301
+ return { offset: e === "infinite" ? [l, s] : a < 1 ? [-(t.realWidth - t.realWidth / a) / 2, -(t.realHeight - t.realHeight / a) / 2] : [et(l, t.realWidth / a - t.realWidth, 0), et(s, t.realHeight / a - t.realHeight, 0)], zoom: a };
302
+ }, Va = (e) => {
282
303
  const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: n }, canvasZoom: a, canvasOffset: o } = e;
283
304
  return { x: o[0] * a * n, y: o[1] * a * n, width: t * a, height: i * a };
284
- }, ha = (e, t) => {
305
+ }, Za = (e, t) => {
285
306
  const { canvasZoom: i, size: n } = t;
286
307
  if (n !== "fixed" || i >= 1) return;
287
- const a = ca(t);
308
+ const a = Va(t);
288
309
  e.beginPath(), e.rect(a.x, a.y, a.width, a.height), e.closePath(), e.clip();
289
- }, vt = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, _a = (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) }), Tt = (e, t) => {
290
- const i = Vt(e), n = ((a, o) => Be(a, _a, o))(e, t);
291
- return { ...e, path: i, selection: pt(i, n, t), computed: n };
292
- }, ja = Tt, St = (e, t) => {
293
- const i = aa(e), n = ((a, o) => Be(a, At, o))(e, t);
294
- return { ...e, path: i, selection: wi(i, e, n, t), computed: n };
295
- }, ua = St, At = (e, t) => {
310
+ }, Dt = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, bo = (e, t) => ({ x: e.x - e.radius - t.selectionPadding, width: 2 * (e.radius + t.selectionPadding), y: e.y - e.radius - t.selectionPadding, height: 2 * (e.radius + t.selectionPadding) }), Jt = (e, t) => {
311
+ const i = Gt(e), n = it(e, bo, t);
312
+ return { ...e, path: i, selection: Ht(i, n, t), computed: n };
313
+ }, Qo = Jt, Ha = (e, t, i) => {
314
+ const n = mt(e, t, i), a = (e.radius || 0.5) * i.widthMultiplier, o = yt(i, n.x, n.y, 2 * a, 2 * a);
315
+ return Jt({ ...e, radius: a, x: o[0], y: o[1] }, i.settings);
316
+ }, zt = (e, t) => {
317
+ const i = wa(e), n = it(e, ei, t);
318
+ return { ...e, path: i, selection: Wi(i, e, n, t), computed: n };
319
+ }, za = zt, ei = (e, t) => {
296
320
  const i = Math.min(...e.points.map((o) => o[0])) - t.selectionPadding, n = Math.max(...e.points.map((o) => o[0])) + t.selectionPadding, a = Math.min(...e.points.map((o) => o[1])) - t.selectionPadding;
297
321
  return { x: i, width: n - i, y: a, height: Math.max(...e.points.map((o) => o[1])) + t.selectionPadding - a };
298
- }, Ka = (e, t, i, n) => {
322
+ }, wo = (e, t, i, n) => {
299
323
  if (t < 0 || t > e.points.length - 1) return e;
300
324
  const a = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
301
- return St({ ...e, points: a }, n);
302
- }, ji = (e, t, i, n = !1) => {
303
- const a = [we(t[0], i), we(t[1], i)], o = Re(a, e.rotation ?? 0, e.computed.center), d = { ...e, points: n ? e.points : [...e.points, o], tempPoint: n ? o : void 0 };
304
- return St(d, i);
305
- }, Ja = (e, t, i) => {
325
+ return zt({ ...e, points: a }, n);
326
+ }, gn = (e, t, i, n = !1) => {
327
+ const a = [ze(t[0], i), ze(t[1], i)], o = tt(a, e.rotation ?? 0, e.computed.center), r = { ...e, points: n ? e.points : [...e.points, o], tempPoint: n ? o : void 0 };
328
+ return zt(r, i);
329
+ }, xo = (e, t, i) => {
306
330
  const n = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
307
331
  if (n.length < 2) {
308
- const l = n[0] ?? [0, 0], h = i.selectionPadding;
309
- return { x: l[0] - h, y: l[1] - h, width: 2 * h, height: 2 * h };
332
+ const c = n[0] ?? [0, 0], h = i.selectionPadding;
333
+ return { x: c[0] - h, y: c[1] - h, width: 2 * h, height: 2 * h };
310
334
  }
311
- if (n.length < 3) return At({ ...e, points: n }, i);
312
- const a = yi(e, n);
313
- let o = Number.POSITIVE_INFINITY, d = Number.NEGATIVE_INFINITY, r = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
314
- for (let l = 1; l < a.length - 2; l++) {
315
- const h = a[l - 1], c = a[l], u = a[l + 1], f = a[l + 2], { cp1: v, cp2: p } = Si(h, c, u, f), S = Oa(c, v, p, u);
316
- o = Math.min(o, S.minX), d = Math.max(d, S.maxX), r = Math.min(r, S.minY), s = Math.max(s, S.maxY);
335
+ if (n.length < 3) return ei({ ...e, points: n }, i);
336
+ const a = Ti(e, n);
337
+ let o = Number.POSITIVE_INFINITY, r = Number.NEGATIVE_INFINITY, l = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
338
+ for (let c = 1; c < a.length - 2; c++) {
339
+ const h = a[c - 1], d = a[c], u = a[c + 1], p = a[c + 2], { cp1: f, cp2: m } = Di(h, d, u, p), b = po(d, f, m, u);
340
+ o = Math.min(o, b.minX), r = Math.max(r, b.maxX), l = Math.min(l, b.minY), s = Math.max(s, b.maxY);
317
341
  }
318
- return Qi({ x: o, y: r, width: d - o, height: s - r }, i);
319
- }, Qt = (e, t) => {
342
+ return Ei({ x: o, y: l, width: r - o, height: s - l }, i);
343
+ }, At = (e, t) => {
320
344
  const i = ((a) => {
321
- const o = new Path2D(), d = a.tempPoint ? [...a.points, a.tempPoint] : a.points;
322
- if (d.length < 2) return o;
323
- if (d.length < 3) return aa(a);
324
- const r = a.style?.closedPoints === 1 && d.length > 2;
325
- o.moveTo(...d[0]);
326
- const s = yi(a, d);
327
- for (let l = 1; l < s.length - 2; l++) {
328
- const h = s[l - 1], c = s[l], u = s[l + 1], f = s[l + 2], { cp1: v, cp2: p } = Si(h, c, u, f);
329
- o.bezierCurveTo(v[0], v[1], p[0], p[1], u[0], u[1]);
345
+ const o = new Path2D(), r = a.tempPoint ? [...a.points, a.tempPoint] : a.points;
346
+ if (r.length < 2) return o;
347
+ if (r.length < 3) return wa(a);
348
+ const l = a.style?.closedPoints === 1 && r.length > 2;
349
+ o.moveTo(...r[0]);
350
+ const s = Ti(a, r);
351
+ for (let c = 1; c < s.length - 2; c++) {
352
+ const h = s[c - 1], d = s[c], u = s[c + 1], p = s[c + 2], { cp1: f, cp2: m } = Di(h, d, u, p);
353
+ o.bezierCurveTo(f[0], f[1], m[0], m[1], u[0], u[1]);
330
354
  }
331
- return r && o.closePath(), o;
332
- })(e), n = ((a, o) => Be(a, At, o, Ja))(e, t);
333
- return { ...e, path: i, selection: wi(i, e, n, t), computed: n };
334
- }, pa = Qt, eo = (e, t, i, n) => {
355
+ return l && o.closePath(), o;
356
+ })(e), n = it(e, ei, t, xo);
357
+ return { ...e, path: i, selection: Wi(i, e, n, t), computed: n };
358
+ }, Aa = At, Mo = (e, t, i, n) => {
335
359
  if (t < 0 || t > e.points.length - 1) return e;
336
360
  const a = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
337
- return Qt({ ...e, points: a }, n);
338
- }, Ki = (e, t, i, n = !1) => {
339
- const a = [we(t[0], i), we(t[1], i)], o = e.computed.center, d = Re(a, e.rotation ?? 0, o), r = { ...e, points: n ? e.points : [...e.points, d], tempPoint: n ? d : void 0 };
340
- return Qt(r, i);
341
- }, to = (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) }), Dt = (e, t) => {
361
+ return At({ ...e, points: a }, n);
362
+ }, fn = (e, t, i, n = !1) => {
363
+ const a = [ze(t[0], i), ze(t[1], i)], o = e.computed.center, r = tt(a, e.rotation ?? 0, o), l = { ...e, points: n ? e.points : [...e.points, r], tempPoint: n ? r : void 0 };
364
+ return At(l, i);
365
+ }, Co = (e, t) => ({ x: e.x - e.radiusX - t.selectionPadding, width: 2 * (e.radiusX + t.selectionPadding), y: e.y - e.radiusY - t.selectionPadding, height: 2 * (e.radiusY + t.selectionPadding) }), ti = (e, t) => {
342
366
  const i = ((a) => {
343
367
  const o = new Path2D();
344
368
  return o.ellipse(a.x, a.y, a.radiusX, a.radiusY, 0, 0, 2 * Math.PI), o;
345
- })(e), n = ((a, o) => Be(a, to, o))(e, t);
346
- return { ...e, path: i, selection: pt(i, n, t), computed: n };
347
- }, io = Dt, no = (e, t) => Be(e, At, t), Ji = (e, t) => ((i, n) => ({ ...i, path: Fa(i), computed: no(i, n) }))({ ...e, id: ue("triangle_"), type: "triangle" }, t), ao = (e, t) => {
369
+ })(e), n = it(e, Co, t);
370
+ return { ...e, path: i, selection: Ht(i, n, t), computed: n };
371
+ }, ko = ti, Ta = (e, t, i) => {
372
+ const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation, c = mt(e, t, i), h = (e.radiusX || 0.5) * r, d = (e.radiusY || 0.5) * l, u = yt(i, c.x, c.y, 2 * h, 2 * d);
373
+ return ti({ ...e, radiusX: h, radiusY: d, x: u[0], y: u[1], rotation: s ? -(e.rotation ?? 0) : e.rotation ?? 0 }, o);
374
+ }, vn = (e, t) => ((i, n) => ({ ...i, path: go(i), computed: it(i, ei, n) }))({ ...e, id: Le("triangle_"), type: "triangle" }, t), Po = (e, t) => {
348
375
  e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
349
- }, oo = (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 }), Et = (e, t) => {
376
+ }, Lo = (e, t) => ({ x: Math.min(e.points[0][0], e.points[1][0]) - t.selectionPadding, width: Math.abs(e.points[0][0] - e.points[1][0]) + 2 * t.selectionPadding, y: Math.min(e.points[0][1], e.points[1][1]) - t.selectionPadding, height: Math.abs(e.points[0][1] - e.points[1][1]) + 2 * t.selectionPadding }), ii = (e, t) => {
350
377
  const i = [];
351
378
  let n;
352
379
  if (e.style?.lineArrow === 1 || e.style?.lineArrow === 2 || e.style?.lineArrow === 3) {
353
- const o = Math.PI / 2 - Yi({ targetVector: [e.points[0], e.points[1]] });
354
- e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(Ji(en(e.points[0], o, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(Ji(en(e.points[1], o + Math.PI, e.style), t));
355
- const d = (({ line: r, size: s, direction: l }) => {
356
- const h = Math.PI / 2 - Yi({ targetVector: [r.points[0], r.points[1]] }), c = [r.points[0][0] + (r.points[1][0] - r.points[0][0]) / 2, r.points[0][1] + (r.points[1][1] - r.points[0][1]) / 2];
357
- let u, f;
358
- if (["start", "both"].includes(l)) {
359
- const v = le({ point: r.points[0], origin: c, rotation: -h });
360
- u = le({ point: [v[0], v[1] + s], origin: c, rotation: h });
361
- } else u = [...r.points[0]];
362
- if (["end", "both"].includes(l)) {
363
- const v = le({ point: r.points[1], origin: c, rotation: -h });
364
- f = le({ point: [v[0], v[1] - s], origin: c, rotation: h });
365
- } else f = [...r.points[1]];
366
- return { points: [u, f] };
380
+ const o = Math.PI / 2 - ln({ targetVector: [e.points[0], e.points[1]] });
381
+ e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(vn(mn(e.points[0], o, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(vn(mn(e.points[1], o + Math.PI, e.style), t));
382
+ const r = (({ line: l, size: s, direction: c }) => {
383
+ const h = Math.PI / 2 - ln({ targetVector: [l.points[0], l.points[1]] }), d = [l.points[0][0] + (l.points[1][0] - l.points[0][0]) / 2, l.points[0][1] + (l.points[1][1] - l.points[0][1]) / 2];
384
+ let u, p;
385
+ if (["start", "both"].includes(c)) {
386
+ const f = Qe({ point: l.points[0], origin: d, rotation: -h });
387
+ u = Qe({ point: [f[0], f[1] + s], origin: d, rotation: h });
388
+ } else u = [...l.points[0]];
389
+ if (["end", "both"].includes(c)) {
390
+ const f = Qe({ point: l.points[1], origin: d, rotation: -h });
391
+ p = Qe({ point: [f[0], f[1] - s], origin: d, rotation: h });
392
+ } else p = [...l.points[1]];
393
+ return { points: [u, p] };
367
394
  })({ line: e, size: 10 + 2 * (e.style?.lineWidth ?? 0), direction: e.style?.lineArrow === 1 ? "start" : e.style?.lineArrow === 2 ? "end" : "both" });
368
- n = Zt(d);
369
- } else n = Zt(e);
370
- const a = ((o, d) => Be(o, oo, d))(e, t);
371
- return { ...e, path: n, selection: wi(n, e, a, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: a };
372
- }, so = Et, en = (e, t, i) => {
373
- const n = [le({ point: [0, 0], rotation: t }), le({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), le({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
395
+ n = _t(r);
396
+ } else n = _t(e);
397
+ const a = it(e, Lo, t);
398
+ return { ...e, path: n, selection: Wi(n, e, a, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: a };
399
+ }, Vo = ii, mn = (e, t, i) => {
400
+ const n = [Qe({ point: [0, 0], rotation: t }), Qe({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), Qe({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
374
401
  return { points: [[e[0] + n[0][0], e[1] + n[0][1]], [e[0] + n[1][0], e[1] + n[1][1]], [e[0] + n[2][0], e[1] + n[2][1]]], style: { ...i, fillColor: i.strokeColor, strokeColor: "transparent" } };
375
- }, ro = (e, t, i) => {
376
- const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: d, heightMultiplier: r } = i, s = e.computed.borders.width - 2 * o.selectionPadding, l = e.computed.borders.height - 2 * o.selectionPadding, h = s * d, c = l * r, u = et(e, t, i), f = tt(i, u.x, u.y, h, c), v = e.computed.center[0] - s / 2, p = e.computed.center[1] - l / 2, S = f[0] - h / 2, C = f[1] - c / 2;
377
- return ((b, Q) => b.type === "line" ? Et(b, Q) : b.type === "polygon" ? ua(b, Q) : pa(b, Q))({ ...e, points: e.points.map(([b, Q]) => [S + (n ? h - (b - v) * d : (b - v) * d), C + (a ? c - (Q - p) * r : (Q - p) * r)]) }, i.settings);
378
- }, It = (e, t) => {
379
- const i = ((a, o) => Be(a, Qi, o))(e, t), n = yt(e);
380
- return { ...e, path: n, selection: pt(void 0, i, t), computed: i };
381
- }, lo = It, ei = (e, t, i, n, a) => {
382
- const [o, d] = ((r, s, l, h, c = !1) => {
383
- if (!(r && s && h && l)) return [Oi, Oi];
384
- const u = r / s;
385
- if (u > l / h) {
386
- const v = c ? l : Math.min(r, l);
387
- return [v, v / u];
402
+ }, Da = (e, t, i) => {
403
+ const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = e.computed.borders.width - 2 * o.selectionPadding, c = e.computed.borders.height - 2 * o.selectionPadding, h = s * r, d = c * l, u = mt(e, t, i), p = yt(i, u.x, u.y, h, d), f = e.computed.center[0] - s / 2, m = e.computed.center[1] - c / 2, b = p[0] - h / 2, x = p[1] - d / 2;
404
+ return ((k, M) => k.type === "line" ? ii(k, M) : k.type === "polygon" ? za(k, M) : Aa(k, M))({ ...e, points: e.points.map(([k, M]) => [b + (n ? h - (k - f) * r : (k - f) * r), x + (a ? d - (M - m) * l : (M - m) * l)]) }, i.settings);
405
+ }, ni = (e, t) => {
406
+ const i = it(e, Ei, t), n = Wt(e);
407
+ return { ...e, path: n, selection: Ht(void 0, i, t), computed: i };
408
+ }, Zo = ni, gi = (e, t, i, n, a) => {
409
+ const [o, r] = ((l, s, c, h, d = !1) => {
410
+ if (!(l && s && h && c)) return [sn, sn];
411
+ const u = l / s;
412
+ if (u > c / h) {
413
+ const f = d ? c : Math.min(l, c);
414
+ return [f, f / u];
388
415
  }
389
- const f = c ? h : Math.min(s, h);
390
- return [f * u, f];
416
+ const p = d ? h : Math.min(s, h);
417
+ return [p * u, p];
391
418
  })(e.width, e.height, i, n, !0);
392
- return It({ toolId: fi.id, type: "picture", id: ue("picture_"), x: -a.canvasOffset[0] + a.canvasSize.realWidth / a.canvasZoom / 2 - o / 2, y: -a.canvasOffset[1] + a.canvasSize.realHeight / a.canvasZoom / 2 - d / 2, width: o, height: d, ratio: o / d, src: t, img: e }, a);
393
- }, co = (e, t, i, n) => new Promise((a, o) => {
394
- const d = new Image();
395
- d.onerror = () => {
419
+ return ni({ toolId: zi.id, type: "picture", id: Le("picture_"), x: -a.canvasOffset[0] + a.canvasSize.realWidth / a.canvasZoom / 2 - o / 2, y: -a.canvasOffset[1] + a.canvasSize.realHeight / a.canvasZoom / 2 - r / 2, width: o, height: r, ratio: o / r, src: t, img: e }, a);
420
+ }, Ho = (e, t, i, n) => new Promise((a, o) => {
421
+ const r = new Image();
422
+ r.onerror = () => {
396
423
  o(new Error("Some images could not be loaded"));
397
424
  }, setTimeout(() => {
398
425
  o(new Error("Timeout while loading images"));
399
- }, 4e3), e instanceof File ? ((r, s, l, h, c, u) => {
400
- Sa(l) ? l.text().then((f) => {
401
- const v = ya(f);
402
- r.onload = async () => {
403
- URL.revokeObjectURL(r.src);
404
- const p = ei(r, f, h, c, u);
405
- s(p);
406
- }, r.src = v;
407
- }) : (r.onload = async () => {
408
- URL.revokeObjectURL(r.src);
409
- const f = ei(r, r.src, h, c, u);
410
- s(f);
411
- }, r.src = URL.createObjectURL(l));
412
- })(d, a, e, t, i, n) : ((r, s, l, h, c, u) => {
413
- r.onload = () => {
414
- URL.revokeObjectURL(r.src);
415
- const f = ei(r, l, h, c, u);
416
- s(f);
417
- }, Qa(l).then((f) => {
418
- r.src = f;
426
+ }, 4e3), e instanceof File ? ((l, s, c, h, d, u) => {
427
+ Ya(c) ? c.text().then((p) => {
428
+ const f = Fa(p);
429
+ l.onload = async () => {
430
+ URL.revokeObjectURL(l.src);
431
+ const m = gi(l, p, h, d, u);
432
+ s(m);
433
+ }, l.src = f;
434
+ }) : (l.onload = async () => {
435
+ URL.revokeObjectURL(l.src);
436
+ const p = gi(l, l.src, h, d, u);
437
+ s(p);
438
+ }, l.src = URL.createObjectURL(c));
439
+ })(r, a, e, t, i, n) : ((l, s, c, h, d, u) => {
440
+ l.onload = () => {
441
+ URL.revokeObjectURL(l.src);
442
+ const p = gi(l, c, h, d, u);
443
+ s(p);
444
+ }, Xa(c).then((p) => {
445
+ l.src = p;
419
446
  }).catch(() => {
420
- r.src = "";
447
+ l.src = "";
421
448
  });
422
- })(d, a, e, t, i, n);
423
- }), ti = ["Texte"], ga = (e, t) => Be(e, uo, t), Wt = (e, t) => {
424
- const i = ga(e, t), n = yt(e);
425
- return { ...e, path: n, selection: pt(void 0, i, t), computed: i };
426
- }, ho = Wt, Rt = (e, t, i, n, a, o = mt) => {
449
+ })(r, a, e, t, i, n);
450
+ }), Ea = (e, t, i) => {
451
+ const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: r, heightMultiplier: l } = i, s = mt(e, t, i), c = (e.width === 0 || e.height === 0 ? e.ratio ?? 1 : e.width) * r, h = (e.width === 0 || e.height === 0 ? e.ratio ?? 1 : e.height) * l, d = yt(i, s.x, s.y, c, h), u = (n || a) && !(n && a) && (e.rotation ?? 0) !== 0 && i.rotation !== e.rotation;
452
+ return ni({ ...e, width: c, height: h, x: d[0] - c / 2, y: d[1] - h / 2, flipX: n ? !e.flipX : !!e.flipX, flipY: a ? !e.flipY : !!e.flipY, rotation: u ? -(e.rotation ?? 0) : e.rotation ?? 0 }, o);
453
+ }, fi = ["Texte"], Ia = (e, t) => it(e, Ao, t), ai = (e, t) => {
454
+ const i = Ia(e, t), n = Wt(e);
455
+ return { ...e, path: n, selection: Ht(void 0, i, t), computed: i };
456
+ }, zo = ai, oi = (e, t, i, n, a, o = It) => {
427
457
  e.font = `${a ? "italic" : ""} ${n ? "bold" : ""} 1px ${o}`;
428
- const d = t.map((r) => i / e.measureText(r).width);
429
- return Math.min(...d) || 36;
430
- }, 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, n) => {
431
- const a = { ...t, value: i }, o = ((v, p, S, C, b, Q = mt) => {
432
- v.font = `${b ? "italic" : ""} ${C ? "bold" : ""} ${S}px ${Q}`;
433
- const g = p.map((w) => v.measureText(w).width);
434
- return Math.max(...g) || 20;
435
- })(e, a.value, a.fontSize, a.style?.fontBold ?? !1, a.style?.fontItalic ?? !1, a.style?.fontFamily), d = a.fontSize * a.value.length, r = o / d, s = { ...a, width: o, height: d, ratio: r }, { center: l } = ga(s, n), [h, c] = $i([1, 1], t.computed.center, t), [u, f] = $i([1, 1], l, s, [!1, !1]);
436
- return { ...s, x: s.x - (u - h), y: s.y - (f - c) };
437
- }, tn = (e, t, i, n) => {
438
- const a = [we(i[0], n), we(i[1], n)];
458
+ const r = t.map((l) => i / e.measureText(l).width);
459
+ return Math.min(...r) || 36;
460
+ }, Ao = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), Wa = (e, t, i, n) => {
461
+ const { isXinverted: a, isYinverted: o, settings: r, widthMultiplier: l, heightMultiplier: s } = n, c = (a || o) && !(a && o) && (t.rotation ?? 0) !== 0 && n.rotation !== t.rotation, h = mt(t, i, n), d = (t.width === 0 || t.height === 0 ? t.ratio ?? 1 : t.width) * l, u = (t.width === 0 || t.height === 0 ? t.ratio ?? 1 : t.height) * s, p = yt(n, h.x, h.y, d, u), f = ai({ ...t, width: d, height: u, x: p[0] - d / 2, y: p[1] - u / 2, flipX: a ? !t.flipX : !!t.flipX, flipY: o ? !t.flipY : !!t.flipY, rotation: c ? -(t.rotation ?? 0) : t.rotation ?? 0 }, r);
462
+ return { ...f, fontSize: oi(e, f.value, f.width, f.style?.fontBold ?? !1, f.style?.fontItalic ?? !1, f.style?.fontFamily) };
463
+ }, To = (e, t, i, n) => {
464
+ const a = { ...t, value: i }, o = ((f, m, b, x, k, M = It) => {
465
+ f.font = `${k ? "italic" : ""} ${x ? "bold" : ""} ${b}px ${M}`;
466
+ const S = m.map((g) => f.measureText(g).width);
467
+ return Math.max(...S) || 20;
468
+ })(e, a.value, a.fontSize, a.style?.fontBold ?? !1, a.style?.fontItalic ?? !1, a.style?.fontFamily), r = a.fontSize * a.value.length, l = o / r, s = { ...a, width: o, height: r, ratio: l }, { center: c } = Ia(s, n), [h, d] = hn([1, 1], t.computed.center, t), [u, p] = hn([1, 1], c, s, [!1, !1]);
469
+ return { ...s, x: s.x - (u - h), y: s.y - (p - d) };
470
+ }, yn = (e, t, i, n) => {
471
+ const a = [ze(i[0], n), ze(i[1], n)];
439
472
  switch (t.type) {
440
473
  case "brush":
441
- return ((o, d, r) => ut({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [[d]], 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 } }, r))(t, a, n);
474
+ return ((o, r, l) => Zt({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [[r]], scaleX: 1, scaleY: 1, style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, a, n);
442
475
  case "line":
443
- return ((o, d, r) => {
444
- const s = { toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [d, d], 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 } };
445
- return Et(s, r);
476
+ return ((o, r, l) => {
477
+ const s = { toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [r, r], style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, lineArrow: o.settings.lineArrow.default } };
478
+ return ii(s, l);
446
479
  })(t, a, n);
447
480
  case "polygon":
448
- return ((o, d, r) => St({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [d], 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 } }, r))(t, a, n);
481
+ return ((o, r, l) => zt({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [r], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, l))(t, a, n);
449
482
  case "curve":
450
- return ((o, d, r) => Qt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [d], 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 } }, r))(t, a, n);
483
+ return ((o, r, l) => At({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), points: [r], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, l))(t, a, n);
451
484
  case "rect":
452
485
  case "square":
453
- return oa(t, a, n);
486
+ return xa(t, a, n);
454
487
  case "text":
455
- return ((o, d, r, s) => {
456
- const l = Rt(o, ti, 150, d.settings?.fontBold.default ?? !1, d.settings?.fontItalic.default ?? !1, d.settings.fontFamily.default), h = l * (ti.length || 1);
457
- return Wt({ toolId: d.id, type: d.type, id: ue(`${d.type}_`), x: r[0] - 150, y: r[1] - h, value: ti, fontSize: l, width: 150, height: h, ratio: 150 / h, style: { opacity: d.settings.opacity.default, strokeColor: d.settings.strokeColor.default, fontFamily: d.settings.fontFamily.default, fontItalic: d.settings.fontItalic.default, fontBold: d.settings.fontBold.default } }, s);
488
+ return ((o, r, l, s) => {
489
+ const c = oi(o, fi, 150, r.settings?.fontBold.default ?? !1, r.settings?.fontItalic.default ?? !1, r.settings.fontFamily.default), h = c * (fi.length || 1);
490
+ return ai({ toolId: r.id, type: r.type, id: Le(`${r.type}_`), x: l[0] - 150, y: l[1] - h, value: fi, fontSize: c, width: 150, height: h, ratio: 150 / h, style: { opacity: r.settings.opacity.default, strokeColor: r.settings.strokeColor.default, fontFamily: r.settings.fontFamily.default, fontItalic: r.settings.fontItalic.default, fontBold: r.settings.fontBold.default } }, s);
458
491
  })(e, t, a, n);
459
492
  case "ellipse":
460
- return ((o, d, r) => Dt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), x: d[0], y: d[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 } }, r))(t, a, n);
493
+ return ((o, r, l) => ti({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), x: r[0], y: r[1], radiusX: 0, radiusY: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, a, n);
461
494
  case "circle":
462
- return ((o, d, r) => Tt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), x: d[0], y: d[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 } }, r))(t, a, n);
495
+ return ((o, r, l) => Jt({ toolId: o.id, type: o.type, id: Le(`${o.type}_`), x: r[0], y: r[1], radius: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, a, n);
463
496
  }
464
- }, nn = (e, t) => {
497
+ }, Sn = (e, t) => {
465
498
  switch (t.type) {
466
499
  case "brush":
467
500
  ((i, n) => {
@@ -471,7 +504,7 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
471
504
  case "text":
472
505
  ((i, n) => {
473
506
  if (i.globalAlpha !== 0 && n.style?.strokeColor && n.style.strokeColor !== "transparent") {
474
- i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.font = `${n.style?.fontItalic ? "italic" : ""} ${n.style?.fontBold ? "bold" : ""} ${n.fontSize}px ${n.style?.fontFamily ?? mt}`, i.textBaseline = "top", i.fillStyle = n.style.strokeColor;
507
+ i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.font = `${n.style?.fontItalic ? "italic" : ""} ${n.style?.fontBold ? "bold" : ""} ${n.fontSize}px ${n.style?.fontFamily ?? It}`, i.textBaseline = "top", i.fillStyle = n.style.strokeColor;
475
508
  for (let a = 0; a < n.value.length; a++) i.fillText(n.value[a], n.flipX ? -n.x - n.width : n.x, (n.flipY ? -n.y - n.height : n.y) + a * n.fontSize, n.width);
476
509
  }
477
510
  })(e, t);
@@ -480,7 +513,7 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
480
513
  ((i, n) => {
481
514
  if (i.globalAlpha !== 0) {
482
515
  n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path);
483
- for (const a of n.arrows ?? []) xe(i, a.style), ao(i, a);
516
+ for (const a of n.arrows ?? []) De(i, a.style), Po(i, a);
484
517
  }
485
518
  })(e, t);
486
519
  break;
@@ -506,143 +539,129 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
506
539
  break;
507
540
  case "rect":
508
541
  case "square":
509
- qa(e, t);
542
+ yo(e, t);
510
543
  break;
511
544
  case "picture":
512
545
  ((i, n) => {
513
546
  i.globalAlpha !== 0 && (i.beginPath(), i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.drawImage(n.img, n.flipX ? -n.x - n.width : n.x, n.flipY ? -n.y - n.height : n.y, n.width, n.height));
514
547
  })(e, t);
515
548
  }
516
- }, va = (e, t, i) => {
549
+ }, Ra = (e, t, i) => {
517
550
  if (t.visible === !1) return;
518
551
  if (((a, o) => {
519
- const d = ((r) => {
520
- const { canvasSize: { width: s, height: l, scaleRatioWithNoZoom: h }, canvasZoom: c, canvasOffset: u } = r;
521
- return { x: -u[0], y: -u[1], width: s / c / h, height: l / c / h };
552
+ const r = ((l) => {
553
+ const { canvasSize: { width: s, height: c, scaleRatioWithNoZoom: h }, canvasZoom: d, canvasOffset: u } = l;
554
+ return { x: -u[0], y: -u[1], width: s / d / h, height: c / d / h };
522
555
  })(o);
523
- return !!li(a.computed.boundingBox, d);
556
+ return !!xi(a.computed.boundingBox, r);
524
557
  })(t, i)) {
525
- if (lt(e, i, t.rotation, t.computed.center), xe(e, t.style), e.globalAlpha !== 1) return ((a, o) => {
526
- const { outerBorders: d } = o.computed, r = { width: 2 * d.width, height: 2 * d.height };
527
- if (r.width === 0 || r.height === 0) return;
528
- const s = document.createElement("canvas"), l = s.getContext("2d");
529
- if (!l) throw new Error("No context found for canvas");
530
- s.width = r.width, s.height = r.height, l.translate(r.width / 4 - d.x, r.height / 4 - d.y), xe(l, { ...o.style, opacity: 100 }), nn(l, o), a.drawImage(s, d.x - r.width / 4, d.y - r.height / 4);
558
+ if (kt(e, i, t.rotation, t.computed.center), De(e, t.style), e.globalAlpha !== 1) return ((a, o) => {
559
+ const { outerBorders: r } = o.computed, l = { width: 2 * r.width, height: 2 * r.height };
560
+ if (l.width === 0 || l.height === 0) return;
561
+ const s = document.createElement("canvas"), c = s.getContext("2d");
562
+ if (!c) throw new Error("No context found for canvas");
563
+ s.width = l.width, s.height = l.height, c.translate(l.width / 4 - r.x, l.height / 4 - r.y), De(c, { ...o.style, opacity: 100 }), Sn(c, o), a.drawImage(s, r.x - l.width / 4, r.y - l.height / 4);
531
564
  })(e, t), void e.restore();
532
- nn(e, t), e.restore();
565
+ Sn(e, t), e.restore();
533
566
  }
534
- }, go = (e, t, i) => {
535
- const n = le({ origin: i, point: e.computed.center, rotation: -t });
567
+ }, Na = (e, t, i) => {
568
+ if (e.locked) return e;
569
+ const n = Qe({ origin: i, point: e.computed.center, rotation: -t });
536
570
  if ("points" in e) {
537
571
  if (e.type === "brush") {
538
- const o = e.points.map((d) => d.map((r) => [r[0] + n[0] - e.computed.center[0], r[1] + n[1] - e.computed.center[1]]));
572
+ const o = e.points.map((r) => r.map((l) => [l[0] + n[0] - e.computed.center[0], l[1] + n[1] - e.computed.center[1]]));
539
573
  return { ...e, points: o, rotation: (e.rotation ?? 0) + t };
540
574
  }
541
- const a = e.points.map((o) => le({ origin: i, point: o, rotation: -t }));
575
+ const a = e.points.map((o) => Qe({ origin: i, point: o, rotation: -t }));
542
576
  return { ...e, points: a };
543
577
  }
544
578
  return { ...e, x: e.x + n[0] - e.computed.center[0], y: e.y + n[1] - e.computed.center[1], rotation: (e.rotation ?? 0) + t };
545
- }, an = (e, t, i, n, a, o, d) => {
579
+ }, bn = (e, t, i, n, a, o, r) => {
580
+ if (i.locked) return i;
546
581
  switch (i.type) {
547
582
  case "line":
548
- return ((r, s, l, h) => {
549
- const c = [we(r[0], h), we(r[1], h)], u = Re(c, s.rotation ?? 0, s.computed.center), f = Le(["points", l.anchor], u, s);
550
- return Et(f, h);
583
+ return ((l, s, c, h) => {
584
+ const d = [ze(l[0], h), ze(l[1], h)], u = tt(d, s.rotation ?? 0, s.computed.center), p = Xe(["points", c.anchor], u, s);
585
+ return ii(p, h);
551
586
  })(t, i, n, a);
552
587
  case "polygon":
553
- return ((r, s, l, h) => {
554
- const c = [we(r[0], h), we(r[1], h)], u = Re(c, s.rotation ?? 0, s.computed.center), f = Le(["points", l.anchor], u, s);
555
- return St(f, h);
588
+ return ((l, s, c, h) => {
589
+ const d = [ze(l[0], h), ze(l[1], h)], u = tt(d, s.rotation ?? 0, s.computed.center), p = Xe(["points", c.anchor], u, s);
590
+ return zt(p, h);
556
591
  })(t, i, n, a);
557
592
  case "curve":
558
- return ((r, s, l, h) => {
559
- const c = [we(r[0], h), we(r[1], h)], u = s.computed.center, f = Re(c, s.rotation ?? 0, u), v = Le(["points", l.anchor], f, s);
560
- return Qt(v, h);
593
+ return ((l, s, c, h) => {
594
+ const d = [ze(l[0], h), ze(l[1], h)], u = s.computed.center, p = tt(d, s.rotation ?? 0, u), f = Xe(["points", c.anchor], p, s);
595
+ return At(f, h);
561
596
  })(t, i, n, a);
562
597
  case "brush":
563
- return ((r, s, l, h, c, u) => {
564
- const f = mi({ ...s, scaleX: 1, scaleY: 1 }, h), v = s.computed.borders, { borderX: p, borderHeight: S, borderY: C, borderWidth: b, isXinverted: Q, isYinverted: g } = it(r, s, l, h, c, u), w = Math.max(0, f.width - 2 * h.selectionPadding), L = Math.max(0, f.height - 2 * h.selectionPadding), D = Math.max(0, b - 2 * h.selectionPadding), V = Math.max(0, S - 2 * h.selectionPadding), x = w ? D / w : 1, Z = L ? V / L : 1;
565
- if (!w || !L) return s;
566
- const A = Ve(p - v.x) + (Q ? 2 * v.x + f.width : 0), H = Ve(C - v.y) + (g ? 2 * v.y + f.height : 0);
567
- return ut({ ...s, points: s.points.map((F) => F.map(([E, W]) => [Q ? -E + A : E + A, g ? -W + H : W + H])), scaleX: x, scaleY: Z }, h);
568
- })(t, i, n, a, o, d);
598
+ return ((l, s, c, h, d, u) => {
599
+ const p = Ai({ ...s, scaleX: 1, scaleY: 1 }, h), f = s.computed.borders, { borderX: m, borderHeight: b, borderY: x, borderWidth: k, isXinverted: M, isYinverted: S } = vt(l, s, c, h, d, u), g = Math.max(0, p.width - 2 * h.selectionPadding), P = Math.max(0, p.height - 2 * h.selectionPadding), z = Math.max(0, k - 2 * h.selectionPadding), N = Math.max(0, b - 2 * h.selectionPadding), D = g ? z / g : 1, E = P ? N / P : 1;
600
+ if (!g || !P) return s;
601
+ const A = Be(m - f.x) + (M ? 2 * f.x + p.width : 0), T = Be(x - f.y) + (S ? 2 * f.y + p.height : 0);
602
+ return Zt({ ...s, points: s.points.map((B) => B.map(([F, X]) => [M ? -F + A : F + A, S ? -X + T : X + T])), scaleX: D, scaleY: E }, h);
603
+ })(t, i, n, a, o, r);
569
604
  case "circle":
570
- return ((r, s, l, h, c) => {
571
- const { borderX: u, borderHeight: f, borderY: v, borderWidth: p } = it(r, s, l, h, !0, c);
572
- return Tt({ ...s, radius: Math.max(0, p / 2 - h.selectionPadding), x: u + p / 2, y: v + f / 2 }, h);
573
- })(t, i, n, a, d);
605
+ return ((l, s, c, h, d) => {
606
+ const { borderX: u, borderHeight: p, borderY: f, borderWidth: m } = vt(l, s, c, h, !0, d);
607
+ return Jt({ ...s, radius: Math.max(0, m / 2 - h.selectionPadding), x: u + m / 2, y: f + p / 2 }, h);
608
+ })(t, i, n, a, r);
574
609
  case "ellipse":
575
- return ((r, s, l, h, c = !1, u = !1) => {
576
- const { borderX: f, borderHeight: v, borderY: p, borderWidth: S } = it(r, s, l, h, c, u);
577
- return Dt({ ...s, radiusX: Math.max(0, S / 2 - h.selectionPadding), radiusY: Math.max(0, v / 2 - h.selectionPadding), x: f + S / 2, y: p + v / 2 }, h);
578
- })(t, i, n, a, o, d);
610
+ return ((l, s, c, h, d = !1, u = !1) => {
611
+ const { borderX: p, borderHeight: f, borderY: m, borderWidth: b } = vt(l, s, c, h, d, u);
612
+ return ti({ ...s, radiusX: Math.max(0, b / 2 - h.selectionPadding), radiusY: Math.max(0, f / 2 - h.selectionPadding), x: p + b / 2, y: m + f / 2 }, h);
613
+ })(t, i, n, a, o, r);
579
614
  case "rect":
580
615
  case "square":
581
- return ((r, s, l, h, c = !1, u = !1) => {
582
- const { borderX: f, borderHeight: v, borderY: p, borderWidth: S } = it(r, s, l, h, c, u);
583
- return zt({ ...s, width: Math.max(0, S - 2 * h.selectionPadding), height: Math.max(0, v - 2 * h.selectionPadding), x: f + h.selectionPadding, y: p + h.selectionPadding }, h);
584
- })(t, i, n, a, i.type === "square" || o, d);
616
+ return ((l, s, c, h, d = !1, u = !1) => {
617
+ const { borderX: p, borderHeight: f, borderY: m, borderWidth: b } = vt(l, s, c, h, d, u);
618
+ return Kt({ ...s, width: Math.max(0, b - 2 * h.selectionPadding), height: Math.max(0, f - 2 * h.selectionPadding), x: p + h.selectionPadding, y: m + h.selectionPadding }, h);
619
+ })(t, i, n, a, i.type === "square" || o, r);
585
620
  case "text":
586
- return ((r, s, l, h, c, u) => {
587
- const { borderX: f, borderHeight: v, borderY: p, borderWidth: S, isXinverted: C, isYinverted: b } = it(s, l, h, c, !0, u), Q = Math.max(0, S - 2 * c.selectionPadding), g = Math.max(0, v - 2 * c.selectionPadding), w = Wt({ ...l, width: Q, height: g, x: f + c.selectionPadding, y: p + c.selectionPadding, flipX: C ? !l.flipX : !!l.flipX, flipY: b ? !l.flipY : !!l.flipY }, c);
588
- return { ...w, fontSize: Rt(r, w.value, w.width, w.style?.fontBold ?? !1, w.style?.fontItalic ?? !1, w.style?.fontFamily) };
589
- })(e, t, i, n, a, d);
621
+ return ((l, s, c, h, d, u) => {
622
+ const { borderX: p, borderHeight: f, borderY: m, borderWidth: b, isXinverted: x, isYinverted: k } = vt(s, c, h, d, !0, u), M = Math.max(0, b - 2 * d.selectionPadding), S = Math.max(0, f - 2 * d.selectionPadding), g = ai({ ...c, width: M, height: S, x: p + d.selectionPadding, y: m + d.selectionPadding, flipX: x ? !c.flipX : !!c.flipX, flipY: k ? !c.flipY : !!c.flipY }, d);
623
+ return { ...g, fontSize: oi(l, g.value, g.width, g.style?.fontBold ?? !1, g.style?.fontItalic ?? !1, g.style?.fontFamily) };
624
+ })(e, t, i, n, a, r);
590
625
  case "picture":
591
- return ((r, s, l, h, c) => {
592
- const { borderX: u, borderHeight: f, borderY: v, borderWidth: p, isXinverted: S, isYinverted: C } = it(r, s, l, h, !0, c), b = Math.max(0, p - 2 * h.selectionPadding), Q = Math.max(0, f - 2 * h.selectionPadding);
593
- return It({ ...s, width: b, height: Q, x: u + h.selectionPadding, y: v + h.selectionPadding, flipX: S ? !s.flipX : !!s.flipX, flipY: C ? !s.flipY : !!s.flipY }, h);
594
- })(t, i, n, a, d);
626
+ return ((l, s, c, h, d) => {
627
+ const { borderX: u, borderHeight: p, borderY: f, borderWidth: m, isXinverted: b, isYinverted: x } = vt(l, s, c, h, !0, d), k = Math.max(0, m - 2 * h.selectionPadding), M = Math.max(0, p - 2 * h.selectionPadding);
628
+ return ni({ ...s, width: k, height: M, x: u + h.selectionPadding, y: f + h.selectionPadding, flipX: b ? !s.flipX : !!s.flipX, flipY: x ? !s.flipY : !!s.flipY }, h);
629
+ })(t, i, n, a, r);
595
630
  default:
596
631
  return i;
597
632
  }
598
- }, vo = (e, t, i, n, a, o, d) => {
599
- if (i.type !== "group") return Y(i).map((v) => an(e, t, v, n, a, o, d));
600
- const r = i, s = Y(r), l = s.filter((v) => Ea.includes(v.type)), h = !l.some((v) => (v.rotation ?? 0) !== (l[0]?.rotation ?? 0)), c = (l[0]?.rotation ?? 0) !== 0 && l.length !== s.length, u = s.some((v) => Ia.includes(v.type)), f = ((v, p, S, C, b, Q) => {
601
- const { borders: g } = p.computed, { borderX: w, borderHeight: L, borderY: D, borderWidth: V, isXinverted: x, isYinverted: Z } = it(v, p, S, C, b, Q);
602
- return { newBorderX: w, newBorderY: D, newBorderWidth: V, newBorderHeight: L, widthMultiplier: (V - 2 * C.selectionPadding) / (g.width - 2 * C.selectionPadding || 1), heightMultiplier: (L - 2 * C.selectionPadding) / (g.height - 2 * C.selectionPadding || 1), isXinverted: x, isYinverted: Z, groupCenter: [w + V / 2, D + L / 2], rotation: p.rotation ?? 0, settings: C, originalBorders: g };
603
- })(t, r, n, a, o || !h || u || c, d);
604
- return s.map((v) => {
605
- switch (v.type) {
633
+ }, Do = (e, t, i, n, a, o, r) => {
634
+ if (i.type !== "group") return _(i).map((f) => bn(e, t, f, n, a, o, r));
635
+ const l = i, s = _(l), c = s.filter((f) => so.includes(f.type)), h = !c.some((f) => (f.rotation ?? 0) !== (c[0]?.rotation ?? 0)), d = (c[0]?.rotation ?? 0) !== 0 && c.length !== s.length, u = s.some((f) => ro.includes(f.type)), p = ((f, m, b, x, k, M) => {
636
+ const { borders: S } = m.computed, { borderX: g, borderHeight: P, borderY: z, borderWidth: N, isXinverted: D, isYinverted: E } = vt(f, m, b, x, k, M);
637
+ return { newBorderX: g, newBorderY: z, newBorderWidth: N, newBorderHeight: P, widthMultiplier: (N - 2 * x.selectionPadding) / (S.width - 2 * x.selectionPadding || 1), heightMultiplier: (P - 2 * x.selectionPadding) / (S.height - 2 * x.selectionPadding || 1), isXinverted: D, isYinverted: E, groupCenter: [g + N / 2, z + P / 2], rotation: m.rotation ?? 0, settings: x, originalBorders: S };
638
+ })(t, l, n, a, o || !h || u || d, r);
639
+ return s.map((f) => {
640
+ if (f.locked) return f;
641
+ switch (f.type) {
606
642
  case "rect":
607
643
  case "square":
608
- return ((p, S, C) => {
609
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation, V = et(p, S, C), x = (p.width || 1) * w, Z = (p.height || 1) * L, A = tt(C, V.x, V.y, x, Z);
610
- return zt({ ...p, width: x, height: Z, x: A[0] - x / 2, y: A[1] - Z / 2, rotation: D ? -(p.rotation ?? 0) : p.rotation ?? 0 }, g);
611
- })(v, r, f);
644
+ return Ma(f, l, p);
612
645
  case "picture":
613
- return ((p, S, C) => {
614
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = et(p, S, C), V = (p.width === 0 || p.height === 0 ? p.ratio ?? 1 : p.width) * w, x = (p.width === 0 || p.height === 0 ? p.ratio ?? 1 : p.height) * L, Z = tt(C, D.x, D.y, V, x), A = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation;
615
- return It({ ...p, width: V, height: x, x: Z[0] - V / 2, y: Z[1] - x / 2, flipX: b ? !p.flipX : !!p.flipX, flipY: Q ? !p.flipY : !!p.flipY, rotation: A ? -(p.rotation ?? 0) : p.rotation ?? 0 }, g);
616
- })(v, r, f);
646
+ return Ea(f, l, p);
617
647
  case "text":
618
- return ((p, S, C, b) => {
619
- const { isXinverted: Q, isYinverted: g, settings: w, widthMultiplier: L, heightMultiplier: D } = b, V = (Q || g) && !(Q && g) && (S.rotation ?? 0) !== 0 && C.rotation !== S.rotation, x = et(S, C, b), Z = (S.width === 0 || S.height === 0 ? S.ratio ?? 1 : S.width) * L, A = (S.width === 0 || S.height === 0 ? S.ratio ?? 1 : S.height) * D, H = tt(b, x.x, x.y, Z, A), F = Wt({ ...S, width: Z, height: A, x: H[0] - Z / 2, y: H[1] - A / 2, flipX: Q ? !S.flipX : !!S.flipX, flipY: g ? !S.flipY : !!S.flipY, rotation: V ? -(S.rotation ?? 0) : S.rotation ?? 0 }, w);
620
- return { ...F, fontSize: Rt(p, F.value, F.width, F.style?.fontBold ?? !1, F.style?.fontItalic ?? !1, F.style?.fontFamily) };
621
- })(e, v, r, f);
648
+ return Wa(e, f, l, p);
622
649
  case "ellipse":
623
- return ((p, S, C) => {
624
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation, V = et(p, S, C), x = (p.radiusX || 0.5) * w, Z = (p.radiusY || 0.5) * L, A = tt(C, V.x, V.y, 2 * x, 2 * Z);
625
- return Dt({ ...p, radiusX: x, radiusY: Z, x: A[0], y: A[1], rotation: D ? -(p.rotation ?? 0) : p.rotation ?? 0 }, g);
626
- })(v, r, f);
650
+ return Ta(f, l, p);
627
651
  case "circle":
628
- return ((p, S, C) => {
629
- const b = et(p, S, C), Q = (p.radius || 0.5) * C.widthMultiplier, g = tt(C, b.x, b.y, 2 * Q, 2 * Q);
630
- return Tt({ ...p, radius: Q, x: g[0], y: g[1] }, C.settings);
631
- })(v, r, f);
652
+ return Ha(f, l, p);
632
653
  case "brush":
633
- return ((p, S, C) => {
634
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = mi({ ...p, scaleX: 1, scaleY: 1 }, g), V = D.width - 2 * g.selectionPadding, x = D.height - 2 * g.selectionPadding, Z = p.scaleX ?? 1 ? (p.scaleX ?? 1) * w : w / V, A = p.scaleY ?? 1 ? (p.scaleY ?? 1) * L : L / x, H = V * Z, F = x * A, E = et(p, S, C), W = tt(C, E.x, E.y, H, F), G = Ve(W[0] - H / 2 - p.computed.borders.x - g.selectionPadding) + (b ? 2 * p.computed.borders.x + D.width : 0), _ = Ve(W[1] - F / 2 - p.computed.borders.y - g.selectionPadding) + (Q ? 2 * p.computed.borders.y + D.height : 0), z = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation;
635
- return ut({ ...p, points: p.points.map((y) => y.map(([M, P]) => [b ? -M + G : M + G, Q ? -P + _ : P + _])), scaleX: Z, scaleY: A, rotation: z ? -(p.rotation ?? 0) : p.rotation ?? 0 }, C.settings);
636
- })(v, r, f);
654
+ return Qa(f, l, p);
637
655
  case "line":
638
656
  case "polygon":
639
657
  case "curve":
640
- return ro(v, r, f);
658
+ return Da(f, l, p);
641
659
  default:
642
- return an(e, t, v, n, a, o, d);
660
+ return bn(e, t, f, n, a, o, r);
643
661
  }
644
662
  });
645
- }, fa = (e, t, i, n) => {
663
+ }, Ba = (e, t, i, n) => {
664
+ if (e.locked) return e;
646
665
  switch (e.type) {
647
666
  case "rect":
648
667
  case "square":
@@ -650,46 +669,46 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
650
669
  case "circle":
651
670
  case "picture":
652
671
  case "text":
653
- return Ne({ ...e, x: e.x + t, y: e.y + i }, n);
672
+ return _e({ ...e, x: e.x + t, y: e.y + i }, n);
654
673
  case "line":
655
674
  case "polygon":
656
675
  case "curve":
657
- return Ne({ ...e, points: e.points.map(([a, o]) => [a + t, o + i]) }, n);
676
+ return _e({ ...e, points: e.points.map(([a, o]) => [a + t, o + i]) }, n);
658
677
  case "brush":
659
- return Ne({ ...e, points: e.points.map((a) => a.map(([o, d]) => [o + t, d + i])) }, n);
678
+ return _e({ ...e, points: e.points.map((a) => a.map(([o, r]) => [o + t, r + i])) }, n);
660
679
  default:
661
680
  return e;
662
681
  }
663
- }, ma = (e, t, i, n, a) => {
664
- const o = t.computed.borders, d = ((l, h) => h ? [Math.abs(l[0]) > Math.abs(l[1]) ? l[0] : 0, Math.abs(l[1]) > Math.abs(l[0]) ? l[1] : 0] : l)([e[0] - i[0], e[1] - i[1]], a), r = d[0] === 0 ? 0 : we(o.x + n.selectionPadding + d[0], n) - (o.x + n.selectionPadding), s = d[1] === 0 ? 0 : we(o.y + n.selectionPadding + d[1], n) - (o.y + n.selectionPadding);
665
- return Y(t).map((l) => fa(l, r, s, n));
666
- }, Ne = (e, t) => {
682
+ }, Oa = (e, t, i, n, a) => {
683
+ const o = t.computed.borders, r = ((c, h) => h ? [Math.abs(c[0]) > Math.abs(c[1]) ? c[0] : 0, Math.abs(c[1]) > Math.abs(c[0]) ? c[1] : 0] : c)([e[0] - i[0], e[1] - i[1]], a), l = r[0] === 0 ? 0 : ze(o.x + n.selectionPadding + r[0], n) - (o.x + n.selectionPadding), s = r[1] === 0 ? 0 : ze(o.y + n.selectionPadding + r[1], n) - (o.y + n.selectionPadding);
684
+ return _(t).map((c) => Ba(c, l, s, n));
685
+ }, _e = (e, t) => {
667
686
  switch (e.type) {
668
687
  case "rect":
669
688
  case "square":
670
- return Ua(e, t);
689
+ return mo(e, t);
671
690
  case "ellipse":
672
- return io(e, t);
691
+ return ko(e, t);
673
692
  case "circle":
674
- return ja(e, t);
693
+ return Qo(e, t);
675
694
  case "picture":
676
- return lo(e, t);
695
+ return Zo(e, t);
677
696
  case "text":
678
- return ho(e, t);
697
+ return zo(e, t);
679
698
  case "line":
680
- return so(e, t);
699
+ return Vo(e, t);
681
700
  case "polygon":
682
- return ua(e, t);
701
+ return za(e, t);
683
702
  case "curve":
684
- return pa(e, t);
703
+ return Aa(e, t);
685
704
  case "brush":
686
- return Ra(e, t);
705
+ return co(e, t);
687
706
  default:
688
707
  return e;
689
708
  }
690
- }, on = ({ ctx: e, shape: t, settings: i, selectionWidth: n, selectionColor: a, hoverMode: o, selectionMode: d, withAnchors: r = !0 }) => {
691
- switch (i.debug && ((s, l, h, c) => {
692
- l.selection && c.debug && (s.save(), s.scale(c.canvasSize.scaleRatio, c.canvasSize.scaleRatio), s.translate(c.canvasOffset[0], c.canvasOffset[1]), xe(s, { fillColor: "transparent", strokeColor: "green", lineWidth: h / c.canvasSize.scaleRatio }), s.strokeRect(l.computed.boundingBox.x, l.computed.boundingBox.y, l.computed.boundingBox.width, l.computed.boundingBox.height), s.restore());
709
+ }, Qn = ({ ctx: e, shape: t, settings: i, selectionWidth: n, selectionColor: a, hoverMode: o, selectionMode: r, withAnchors: l = !0 }) => {
710
+ switch (i.debug && ((s, c, h, d) => {
711
+ c.selection && d.debug && (s.save(), s.scale(d.canvasSize.scaleRatio, d.canvasSize.scaleRatio), s.translate(d.canvasOffset[0], d.canvasOffset[1]), De(s, { fillColor: "transparent", strokeColor: "green", lineWidth: h / d.canvasSize.scaleRatio }), s.strokeRect(c.computed.boundingBox.x, c.computed.boundingBox.y, c.computed.boundingBox.width, c.computed.boundingBox.height), s.restore());
693
712
  })(e, t, n, i), t.type) {
694
713
  case "rect":
695
714
  case "square":
@@ -698,712 +717,814 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
698
717
  case "picture":
699
718
  case "text":
700
719
  case "brush":
701
- ((s, l, h, c, u, f) => {
702
- if (l.selection && (lt(s, u, l.rotation, l.computed.center), u.debug && (xe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / u.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), xe(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / u.canvasSize.scaleRatio }), l.selection.shapePath ? s.stroke(l.selection.shapePath) : s.stroke(l.selection.border), f && !l.locked)) {
703
- l.selection.shapePath && s.stroke(l.selection.border), l.selection.line && s.stroke(l.selection.line), xe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / u.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
704
- for (const v of l.selection.anchors) s.fill(v), s.stroke(v);
720
+ ((s, c, h, d, u, p) => {
721
+ if (c.selection && (kt(s, u, c.rotation, c.computed.center), u.debug && (De(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / u.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), De(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / u.canvasSize.scaleRatio }), c.selection.shapePath ? s.stroke(c.selection.shapePath) : s.stroke(c.selection.border), p && !c.locked)) {
722
+ c.selection.shapePath && s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), De(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / u.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
723
+ for (const f of c.selection.anchors) s.fill(f), s.stroke(f);
705
724
  }
706
- })(e, t, a, n, i, r);
725
+ })(e, t, a, n, i, l);
707
726
  break;
708
727
  case "group":
709
- ((s, l, h, c, u, f, v) => {
710
- if (l.selection && (l.shapes.forEach((p) => {
711
- xe(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / f.canvasSize.scaleRatio }), lt(s, f, p.rotation, p.computed.center), p.selection?.shapePath && s.stroke(p.selection.shapePath), s.restore();
712
- }), u.mode !== "rotate" && (lt(s, f, l.rotation, l.computed.center), f.debug && (xe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / f.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), xe(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / f.canvasSize.scaleRatio }), v && !l.locked))) {
713
- s.stroke(l.selection.border), l.selection.line && s.stroke(l.selection.line), xe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / f.canvasSize.scaleRatio });
714
- for (const p of l.selection.anchors) s.fill(p), s.stroke(p);
728
+ ((s, c, h, d, u, p, f) => {
729
+ if (c.selection && (c.shapes.forEach((m) => {
730
+ De(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / p.canvasSize.scaleRatio }), kt(s, p, m.rotation, m.computed.center), m.selection?.shapePath && s.stroke(m.selection.shapePath), s.restore();
731
+ }), u.mode !== "rotate" && (kt(s, p, c.rotation, c.computed.center), p.debug && (De(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / p.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), De(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / p.canvasSize.scaleRatio }), f && !c.locked))) {
732
+ s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), De(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / p.canvasSize.scaleRatio });
733
+ for (const m of c.selection.anchors) s.fill(m), s.stroke(m);
715
734
  }
716
- })(e, t, a, n, d, i, r);
735
+ })(e, t, a, n, r, i, l);
717
736
  break;
718
737
  case "polygon":
719
738
  case "line":
720
739
  case "curve":
721
- (({ ctx: s, shape: l, withAnchors: h, selectionWidth: c, selectionColor: u, hoverMode: f, settings: v }) => {
722
- if (l.selection && (lt(s, v, l.rotation, l.computed.center), v.debug && (xe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / v.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), xe(s, { fillColor: "transparent", strokeColor: u, lineWidth: c / v.canvasSize.scaleRatio }), l.selection.shapePath && s.stroke(l.selection.shapePath), h && !l.locked)) {
723
- xe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / v.canvasSize.scaleRatio, shadowColor: u, shadowBlur: 0 });
724
- for (let p = 0; p < l.selection.anchors.length; p++) {
725
- const S = l.selection.anchors[p];
726
- f.mode === "resize" && f.anchor === p ? (s.shadowBlur = 10, s.fill(S), s.shadowBlur = 0) : s.fill(S), s.stroke(S);
740
+ (({ ctx: s, shape: c, withAnchors: h, selectionWidth: d, selectionColor: u, hoverMode: p, settings: f }) => {
741
+ if (c.selection && (kt(s, f, c.rotation, c.computed.center), f.debug && (De(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / f.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), De(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / f.canvasSize.scaleRatio }), c.selection.shapePath && s.stroke(c.selection.shapePath), h && !c.locked)) {
742
+ De(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / f.canvasSize.scaleRatio, shadowColor: u, shadowBlur: 0 });
743
+ for (let m = 0; m < c.selection.anchors.length; m++) {
744
+ const b = c.selection.anchors[m];
745
+ p.mode === "resize" && p.anchor === m ? (s.shadowBlur = 10, s.fill(b), s.shadowBlur = 0) : s.fill(b), s.stroke(b);
727
746
  }
728
747
  }
729
- })({ ctx: e, shape: t, withAnchors: r, selectionWidth: n, selectionColor: a, hoverMode: o, settings: i });
748
+ })({ ctx: e, shape: t, withAnchors: l, selectionWidth: n, selectionColor: a, hoverMode: o, settings: i });
730
749
  }
731
750
  e.restore();
732
- }, fo = ({ ctx: e, selectionFrame: t, settings: i }) => {
733
- lt(e, i), ((n, a, o) => {
734
- xe(n, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / o.canvasSize.scaleRatio }), n.fillRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]), n.strokeRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]);
751
+ }, Eo = ({ ctx: e, selectionFrame: t, settings: i }) => {
752
+ kt(e, i), ((n, a, o) => {
753
+ De(n, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / o.canvasSize.scaleRatio }), n.fillRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]), n.strokeRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]);
735
754
  })(e, t.frame, i), e.restore();
736
- }, xi = (e) => e.filter((t) => t != null), ya = (e) => {
755
+ }, Ri = (e, t) => _(e).map((i) => ({ ...Ba(i, 20, 20, t), id: Le(`${i.type}_`) })), Ni = (e) => e.filter((t) => t != null), vi = (e, t, i) => t < 0 || i < 0 || t > e.length - 1 || i > e.length - 1 ? e : t < i ? [...e.slice(0, t), ...e.slice(t + 1, i + 1), e[t], ...e.slice(i + 1, e.length)] : [...e.slice(0, i), e[t], ...e.slice(i, t), ...e.slice(t + 1, e.length)], Fa = (e) => {
737
756
  const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0];
738
757
  if (!t) return "";
739
758
  const i = t.getAttribute("width"), n = t.getAttribute("height");
740
759
  let a;
741
760
  if (i || n) a = e;
742
761
  else {
743
- const d = t.getAttribute("viewBox") ?? "0 0 300 300", [, , r, s] = d.split(" ");
744
- t.setAttribute("width", r ?? "300"), t.setAttribute("height", s ?? "300"), a = new XMLSerializer().serializeToString(t);
762
+ const r = t.getAttribute("viewBox") ?? "0 0 300 300", [, , l, s] = r.split(" ");
763
+ t.setAttribute("width", l ?? "300"), t.setAttribute("height", s ?? "300"), a = new XMLSerializer().serializeToString(t);
745
764
  }
746
765
  const o = new Blob([a], { type: "image/svg+xml" });
747
766
  return URL.createObjectURL(o);
748
- }, Sa = (e) => (e instanceof File ? e.name : e).includes(".svg"), Qa = (e) => Sa(e) ? fetch(e).then((t) => t.text()).then((t) => ya(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), sn = (e, t) => {
767
+ }, Ya = (e) => (e instanceof File ? e.name : e).includes(".svg"), Xa = (e) => Ya(e) ? fetch(e).then((t) => t.text()).then((t) => Fa(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), wn = (e, t) => {
749
768
  const i = document.createElement("a");
750
769
  i.href = e, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
751
- }, mo = (e) => e.src.includes("<svg") ? e.src : ((t) => {
770
+ }, Io = (e) => e.src.includes("<svg") ? e.src : ((t) => {
752
771
  const i = document.createElement("canvas");
753
772
  i.width = t.width, i.height = t.height;
754
773
  const n = i.getContext("2d");
755
774
  return n ? (n.drawImage(t, 0, 0), i.toDataURL("image/png")) : "";
756
- })(e.img), ii = ({ shapes: e, settings: t }) => {
775
+ })(e.img), mi = ({ shapes: e, settings: t }) => {
757
776
  const i = document.createElement("canvas"), n = i.getContext("2d");
758
777
  if (!n) throw new Error("No context found for canvas");
759
778
  const { realHeight: a, realWidth: o } = t.canvasSize;
760
- i.width = o, i.height = a, n.clearRect(0, 0, o, a), ta(n);
761
- for (let d = e.length - 1; d >= 0; d--) va(n, e[d], t);
779
+ i.width = o, i.height = a, n.clearRect(0, 0, o, a), ya(n);
780
+ for (let r = e.length - 1; r >= 0; r--) Ra(n, e[r], t);
762
781
  return i.toDataURL("image/png");
763
- }, rn = ({ shapes: e, settings: t, view: i }) => {
782
+ }, xn = ({ shapes: e, settings: t, view: i }) => {
764
783
  if (i === "fitToShapes" && !e.length) throw new Error("No image found to export");
765
784
  if (i === "fitToShapes") {
766
- const a = Math.min(...e.map((l) => l.computed.boundingBox.x)), o = Math.max(...e.map((l) => l.computed.boundingBox.x + l.computed.boundingBox.width)), d = Math.min(...e.map((l) => l.computed.boundingBox.y)), r = Math.max(...e.map((l) => l.computed.boundingBox.y + l.computed.boundingBox.height)), s = { ...t, canvasOffset: [-a, -d], canvasZoom: 1, canvasSize: { realWidth: o - a, realHeight: r - d, width: o - a, height: r - d, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
767
- return ii({ shapes: e, settings: s });
785
+ const a = Math.min(...e.map((c) => c.computed.boundingBox.x)), o = Math.max(...e.map((c) => c.computed.boundingBox.x + c.computed.boundingBox.width)), r = Math.min(...e.map((c) => c.computed.boundingBox.y)), l = Math.max(...e.map((c) => c.computed.boundingBox.y + c.computed.boundingBox.height)), s = { ...t, canvasOffset: [-a, -r], canvasZoom: 1, canvasSize: { realWidth: o - a, realHeight: l - r, width: o - a, height: l - r, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
786
+ return mi({ shapes: e, settings: s });
768
787
  }
769
788
  if (i === "defaultView") {
770
789
  const a = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
771
- return ii({ shapes: e, settings: a });
790
+ return mi({ shapes: e, settings: a });
772
791
  }
773
792
  const n = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
774
- return ii({ shapes: e, settings: n });
775
- }, yo = (e, t, i) => {
776
- return a = Ci(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(a))}`;
793
+ return mi({ shapes: e, settings: n });
794
+ }, Wo = (e, t, i) => {
795
+ return a = Bi(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(a))}`;
777
796
  var a;
778
- }, So = (e) => {
797
+ }, Ro = (e) => {
779
798
  const t = ["img", "id", "selection", "path", "arrows", "tempPoint", "computed", ["flipX", [void 0, !1]], ["flipY", [void 0, !1]]];
780
- return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? ai(t, i) : ai(t, { ...i, src: mo(i) }));
781
- }, Ci = (e, t, i) => ({ shapes: So(e), config: { width: t, height: i } }), ln = (e, t) => Ne({ ...e, id: ue(`${e.type}_`) }, t), Qo = (e, t, i, n) => {
782
- const a = ne([]), o = ne({ dataChanged: [] }), [d, r] = $(void 0), [s, l] = $(void 0), [h, c] = $(void 0), [u, f] = $({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), v = u.cursor > 0, p = u.cursor < u.states.length - 1, S = a.current.length > 0, C = X(() => {
783
- f((y) => Jn(y.states[y.cursor]?.shapes, a.current) ? y : { states: [...y.states.slice(0, y.cursor + 1), { shapes: a.current, selectedShape: s, source: "user" }], cursor: y.cursor + 1 });
784
- }, [s]), b = X((y) => {
785
- a.current = [...y, ...a.current];
786
- }, []), Q = X((y) => {
787
- a.current = a.current.flatMap((M) => {
788
- const P = y.find((T) => T.id === M.id);
789
- return P ? [{ ...P, id: ue(`${M.type}_`) }, M] : M;
790
- });
791
- }, []), g = X((y, M, P, T) => {
792
- if (y.target && "className" in y.target && ![jn, Kn].includes(y.target.className) || !T) return void c(void 0);
793
- const k = a.current.find((O) => Y(s)?.map((R) => R.id).includes(O.id) ? !!ft(M, O, P, e) : !!da(M, O, P, e));
794
- c(k);
795
- }, [e, s]), w = X(async (y, M = 300, P = 300) => {
796
- const T = await co(y, M, P, e);
797
- return b([T]), C(), T;
798
- }, [b, C, e]), L = X((y, M = !1) => {
799
- a.current = a.current.map((P) => y.find((T) => T.id === P.id) ?? P), l((P) => P && pe(Y(P).map((T) => y.find((k) => k.id === T.id) ?? T), e)), M && C();
800
- }, [C, e]), D = X((y) => {
801
- const M = y.map((P) => ai(["chosen"], P));
802
- a.current = M, C();
803
- }, [C]), V = X((y) => {
804
- const M = new Set(y.map((P) => P.id));
805
- l((P) => {
806
- const T = Y(P).map((k) => k.id);
807
- return T && M.size && T.find((k) => M.has(k)) ? void 0 : P;
808
- }), a.current = a.current.filter((P) => !M?.has(P.id)), C();
809
- }, [C]), x = X((y) => {
810
- f((M) => {
811
- const P = y(M);
812
- return a.current = M.states[P]?.shapes ?? [], l(M.states[P]?.selectedShape), Le("cursor", P, M);
799
+ return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? Si(t, i) : Si(t, { ...i, src: Io(i) }));
800
+ }, Bi = (e, t, i) => ({ shapes: Ro(e), config: { width: t, height: i } }), Mn = (e, t) => _e({ ...e, id: Le(`${e.type}_`) }, t), No = (e, t, i, n) => {
801
+ const a = ce([]), o = ce(void 0), r = ce({ dataChanged: [] }), [l, s] = J(void 0), [c, h] = J(void 0), [d, u] = J(void 0), [p, f] = J(void 0), [m, b] = J({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), x = G((Q) => {
802
+ o.current = typeof Q == "function" ? Q(o.current) : Q, h(o.current);
803
+ }, []), k = m.cursor > 0, M = m.cursor < m.states.length - 1, S = a.current.length > 0, g = G(() => {
804
+ b((Q) => va(Q.states[Q.cursor]?.shapes, a.current) ? Q : { states: [...Q.states.slice(0, Q.cursor + 1), { shapes: a.current, selectedShape: o.current, source: "user" }], cursor: Q.cursor + 1 });
805
+ }, []), P = G((Q) => {
806
+ a.current = [...Q, ...a.current];
807
+ }, []), z = G((Q, w = !1, y = !1) => {
808
+ const L = [];
809
+ a.current = a.current.flatMap((W) => {
810
+ const V = Q.find((U) => U.id === W.id);
811
+ if (V) {
812
+ const U = w ? Ri(pe([V], e), e)[0] : { ...V, id: Le(`${W.type}_`) };
813
+ return L.push(U), [U, W];
814
+ }
815
+ return W;
816
+ }), y && x(pe(L, e));
817
+ }, [e, x]), N = G((Q, w, y, L) => {
818
+ if (Q.target && "className" in Q.target && ![ga, fa].includes(Q.target.className) || !L) return void u(void 0);
819
+ const W = a.current.find((V) => !V.locked && (_(c)?.map((U) => U.id).includes(V.id) ? !!Et(w, V, y, e) : !!La(w, V, y, e)));
820
+ u(W);
821
+ }, [e, c]), D = G(async (Q, w = 300, y = 300) => {
822
+ const L = await Ho(Q, w, y, e);
823
+ return P([L]), g(), L;
824
+ }, [P, g, e]), E = G((Q, w = !1) => {
825
+ a.current = a.current.map((y) => Q.find((L) => L.id === y.id) ?? y), x((y) => y && pe(_(y).map((L) => Q.find((W) => W.id === L.id) ?? L), e)), w && g();
826
+ }, [g, x, e]), A = G((Q) => {
827
+ const w = Q.map((y) => Si(["chosen"], y));
828
+ a.current = w, g();
829
+ }, [g]), T = G((Q) => {
830
+ const w = new Set(Q.map((y) => y.id));
831
+ x((y) => {
832
+ const L = _(y).map((W) => W.id);
833
+ return L && w.size && L.find((W) => w.has(W)) ? void 0 : y;
834
+ }), a.current = a.current.filter((y) => !w?.has(y.id)), g();
835
+ }, [g, x]), B = G((Q) => {
836
+ b((w) => {
837
+ const y = Q(w);
838
+ return a.current = w.states[y]?.shapes ?? [], x(w.states[y]?.selectedShape), Xe("cursor", y, w);
813
839
  });
814
- }, []), Z = X(() => {
815
- x((y) => Math.max(0, y.cursor - 1));
816
- }, [x]), A = X(() => {
817
- x((y) => Math.min(y.states.length - 1, y.cursor + 1));
818
- }, [x]), H = X((y, M) => {
819
- l(void 0), a.current = y, f((P) => M.clearHistory ? { states: [{ shapes: y, selectedShape: void 0, source: M.source }], cursor: 0 } : { states: [...P.states.slice(0, P.cursor + 1), { shapes: y, selectedShape: void 0, source: M.source }], cursor: P.cursor + 1 });
820
- }, []), F = X((y, M) => {
821
- const P = a.current, T = P.findIndex((I) => I.id === y), k = P.findIndex((I) => I.id === M);
822
- var O, R, B;
823
- D((O = P, B = k, (R = T) < 0 || B < 0 || R > O.length - 1 || B > O.length - 1 ? O : R < B ? [...O.slice(0, R), ...O.slice(R + 1, B + 1), O[R], ...O.slice(B + 1, O.length)] : [...O.slice(0, B), O[R], ...O.slice(B, R), ...O.slice(R + 1, O.length)]));
824
- }, [D]), E = X((y) => {
825
- const M = a.current, P = new Set(y.map((k) => k.id)), T = M.map((k) => P.has(k.id) ? Le("visible", k.visible === !1, k) : k);
826
- l(qi((k) => Le("visible", k.visible === !1, k), e)), D(T);
827
- }, [D, e]), W = X((y) => {
828
- const M = a.current, P = new Set(y.map((k) => k.id)), T = M.map((k) => P.has(k.id) ? Le("locked", !k.locked, k) : k);
829
- l(qi((k) => Le("locked", !k.locked, k), e)), D(T);
830
- }, [D, e]), G = X((y, M) => {
831
- o.current.hasOwnProperty(y) && (o.current[y] = [...o.current[y], M]);
832
- }, []), _ = X((y, M) => {
833
- if (o.current.hasOwnProperty(y)) if (M) {
834
- const P = o.current[y].indexOf(M);
835
- o.current[y] = [...o.current[y].slice(0, P), ...o.current[y].slice(P + 1)];
836
- } else o.current[y] = [];
840
+ }, [x]), F = G(() => {
841
+ B((Q) => Math.max(0, Q.cursor - 1));
842
+ }, [B]), X = G(() => {
843
+ B((Q) => Math.min(Q.states.length - 1, Q.cursor + 1));
844
+ }, [B]), Z = G((Q, w) => {
845
+ x(void 0), a.current = Q, b((y) => w.clearHistory ? { states: [{ shapes: Q, selectedShape: void 0, source: w.source }], cursor: 0 } : { states: [...y.states.slice(0, y.cursor + 1), { shapes: Q, selectedShape: void 0, source: w.source }], cursor: y.cursor + 1 });
846
+ }, [x]), ne = G((Q, w) => {
847
+ const y = a.current, L = y.findIndex((V) => V.id === Q), W = y.findIndex((V) => V.id === w);
848
+ A(vi(y, L, W));
849
+ }, [A]), I = G((Q, w) => {
850
+ const y = [...a.current], L = new Set(Q.map((V) => V.id)), W = y.map((V, U) => L.has(V.id) ? U : -1).filter((V) => V >= 0);
851
+ if (W.length !== 0) switch (w) {
852
+ case "first":
853
+ case "last": {
854
+ const V = W.map((R) => y[R]).filter(Boolean), U = y.filter((R, H) => !W.includes(H));
855
+ A(w === "first" ? [...V, ...U] : [...U, ...V]);
856
+ break;
857
+ }
858
+ case "backward": {
859
+ let V = [...y];
860
+ const U = W.sort((R, H) => H - R).map((R) => y[R].id);
861
+ for (const R of U) {
862
+ const H = V.findIndex((ae) => ae.id === R);
863
+ if (H < V.length - 1) {
864
+ const ae = H + 1;
865
+ L.has(V[ae].id) || (V = vi(V, H, ae));
866
+ }
867
+ }
868
+ A(V);
869
+ break;
870
+ }
871
+ case "forward": {
872
+ let V = [...y];
873
+ const U = W.sort((R, H) => R - H).map((R) => y[R].id);
874
+ for (const R of U) {
875
+ const H = V.findIndex((ae) => ae.id === R);
876
+ if (H > 0) {
877
+ const ae = H - 1;
878
+ L.has(V[ae].id) || (V = vi(V, H, ae));
879
+ }
880
+ }
881
+ A(V);
882
+ break;
883
+ }
884
+ }
885
+ }, [A]), j = G((Q, w, y, L) => {
886
+ const W = new Set(w.map((U) => U.id)), V = L === "rotateClockwise" || L === "rotateCounterclockwise" ? a.current.map((U) => W.has(U.id) ? _e(Na(U, L === "rotateClockwise" ? Math.PI / 2 : -Math.PI / 2, y), e) : U) : ((U, R, H, ae, me, O) => {
887
+ if (H.length === 0) return R;
888
+ const ge = pe(H, O), ue = ge.computed.borders, Se = { newBorderX: ue.x, newBorderY: ue.y, newBorderWidth: ue.width, newBorderHeight: ue.height, widthMultiplier: 1, heightMultiplier: 1, isXinverted: me === "flipHorizontally", isYinverted: me === "flipVertically", groupCenter: ae, rotation: 0, settings: O, originalBorders: ue }, Ie = new Set(H.map((te) => te.id));
889
+ return R.map((te) => {
890
+ if (te.locked || !Ie.has(te.id)) return te;
891
+ switch (te.type) {
892
+ case "rect":
893
+ case "square":
894
+ return Ma(te, ge, Se);
895
+ case "picture":
896
+ return Ea(te, ge, Se);
897
+ case "text":
898
+ return Wa(U, te, ge, Se);
899
+ case "ellipse":
900
+ return Ta(te, ge, Se);
901
+ case "circle":
902
+ return Ha(te, ge, Se);
903
+ case "brush":
904
+ return Qa(te, ge, Se);
905
+ case "line":
906
+ case "polygon":
907
+ case "curve":
908
+ return Da(te, ge, Se);
909
+ default:
910
+ return te;
911
+ }
912
+ });
913
+ })(Q, a.current, w, y, L, e);
914
+ x(pe(V.filter((U) => W.has(U.id)), e)), A(V);
915
+ }, [e, A, x]), ee = G((Q) => {
916
+ const w = new Set(Q.map((L) => L.id)), y = a.current.map((L) => w.has(L.id) ? Xe("visible", L.visible === !1, L) : L);
917
+ x((L) => pe(y.filter((W) => _(L)?.map((V) => V.id).includes(W.id)), e)), A(y);
918
+ }, [A, e, x]), se = G((Q) => {
919
+ const w = new Set(Q.map((L) => L.id)), y = a.current.map((L) => w.has(L.id) ? Xe("locked", !L.locked, L) : L);
920
+ x((L) => pe(y.filter((W) => _(L)?.map((V) => V.id).includes(W.id)), e)), A(y);
921
+ }, [A, e, x]), he = G((Q, w) => {
922
+ r.current.hasOwnProperty(Q) && (r.current[Q] = [...r.current[Q], w]);
923
+ }, []), C = G((Q, w) => {
924
+ if (r.current.hasOwnProperty(Q)) if (w) {
925
+ const y = r.current[Q].indexOf(w);
926
+ r.current[Q] = [...r.current[Q].slice(0, y), ...r.current[Q].slice(y + 1)];
927
+ } else r.current[Q] = [];
837
928
  }, []);
838
- ee(() => {
839
- const y = u.states[u.cursor], M = Ci(y.shapes, t, i);
840
- for (const P of o.current.dataChanged) P(M, y.source);
841
- }, [t, i, u]), ee(() => {
842
- a.current = a.current.map((y) => Ne(y, e)), l((y) => y === void 0 ? void 0 : pe(Y(y).map((M) => Ne(M, e)), e));
843
- }, [e]);
844
- const z = X((y, M) => {
845
- r((P) => {
846
- const T = [P?.frame[0] ?? [M[0], M[1]], [M[0], M[1]]], k = a.current.filter((R) => ((B, I, j) => {
847
- const { borders: de, center: se, boundingBox: K } = I.computed, N = Math.min(j[0][0], j[1][0]), ge = Math.max(j[0][0], j[1][0]), oe = Math.min(j[0][1], j[1][1]), ye = { x: N, y: oe, width: ge - N, height: Math.max(j[0][1], j[1][1]) - oe }, Se = li(K, ye);
848
- if (!Se) return !1;
849
- if (de.width <= 1 || de.height <= 1) return !0;
850
- if (B.lineWidth = (I.style?.lineWidth ?? 0) + 10, I.type === "brush") {
851
- const te = I.points.flat(), ve = Math.min(...te.map((ae) => ae[0])), U = Math.min(...te.map((ae) => ae[1]));
852
- for (const ae of I.points) {
853
- if (ae.length < 1) break;
854
- if (ae.length < 2) {
855
- const Me = Ee(ae[0], ve, U, I.scaleX, I.scaleY);
856
- if (ia(Se, { x: Me[0], y: Me[1], radius: (I.style?.lineWidth ?? 1) / 2 })) return !0;
929
+ de(() => {
930
+ const Q = m.states[m.cursor], w = Bi(Q.shapes, t, i);
931
+ for (const y of r.current.dataChanged) y(w, Q.source);
932
+ }, [t, i, m]), de(() => {
933
+ a.current = a.current.map((Q) => _e(Q, e)), x((Q) => Q === void 0 ? void 0 : pe(_(Q).map((w) => _e(w, e)), e));
934
+ }, [e, x]);
935
+ const $ = G((Q, w) => {
936
+ s((y) => {
937
+ const L = [y?.frame[0] ?? [w[0], w[1]], [w[0], w[1]]], W = a.current.filter((U) => !U.locked && ((R, H, ae) => {
938
+ const { borders: me, center: O, boundingBox: ge } = H.computed, ue = Math.min(ae[0][0], ae[1][0]), Se = Math.max(ae[0][0], ae[1][0]), Ie = Math.min(ae[0][1], ae[1][1]), te = { x: ue, y: Ie, width: Se - ue, height: Math.max(ae[0][1], ae[1][1]) - Ie }, we = xi(ge, te);
939
+ if (!we) return !1;
940
+ if (me.width <= 1 || me.height <= 1) return !0;
941
+ if (R.lineWidth = (H.style?.lineWidth ?? 0) + 10, H.type === "brush") {
942
+ const ye = H.points.flat(), ie = Math.min(...ye.map((fe) => fe[0])), le = Math.min(...ye.map((fe) => fe[1]));
943
+ for (const fe of H.points) {
944
+ if (fe.length < 1) break;
945
+ if (fe.length < 2) {
946
+ const Ve = Ge(fe[0], ie, le, H.scaleX, H.scaleY);
947
+ if (Sa(we, { x: Ve[0], y: Ve[1], radius: (H.style?.lineWidth ?? 1) / 2 })) return !0;
857
948
  }
858
- for (let Me = 0; Me < ae.length - 1; Me++) {
859
- const Ze = ri(Ee(ae[Me], ve, U, I.scaleX, I.scaleY), I.rotation ?? 0, se), re = ri(Ee(ae[Me + 1], ve, U, I.scaleX, I.scaleY), I.rotation ?? 0, se), Te = li({ x: Math.min(Ze[0], re[0]), y: Math.min(Ze[1], re[1]), width: Math.abs(Ze[0] - re[0]), height: Math.abs(Ze[1] - re[1]) }, ye);
860
- if (Te) {
861
- const qe = new Path2D();
862
- if (qe.moveTo(...Ze), qe.lineTo(...re), _i({ ctx: B, path: qe, rect: Te, offset: 10, center: se, checkFill: !1 })) return !0;
949
+ for (let Ve = 0; Ve < fe.length - 1; Ve++) {
950
+ const Fe = wi(Ge(fe[Ve], ie, le, H.scaleX, H.scaleY), H.rotation ?? 0, O), We = wi(Ge(fe[Ve + 1], ie, le, H.scaleX, H.scaleY), H.rotation ?? 0, O), Ce = xi({ x: Math.min(Fe[0], We[0]), y: Math.min(Fe[1], We[1]), width: Math.abs(Fe[0] - We[0]), height: Math.abs(Fe[1] - We[1]) }, te);
951
+ if (Ce) {
952
+ const Ye = new Path2D();
953
+ if (Ye.moveTo(...Fe), Ye.lineTo(...We), pn({ ctx: R, path: Ye, rect: Ce, offset: 10, center: O, checkFill: !1 })) return !0;
863
954
  }
864
955
  }
865
956
  }
866
957
  return !1;
867
958
  }
868
- const Qe = bi(I);
869
- return _i({ ctx: B, path: I.path, rect: Se, offset: 10, center: se, rotation: I.rotation ?? 0, checkFill: Qe });
870
- })(y, R, T)), O = pe(k, e);
871
- return l(n ? pe(sa(P?.oldSelection, k), e) : O), { oldSelection: P?.oldSelection, frame: T };
959
+ const re = Ii(H);
960
+ return pn({ ctx: R, path: H.path, rect: we, offset: 10, center: O, rotation: H.rotation ?? 0, checkFill: re });
961
+ })(Q, U, L)), V = pe(W, e);
962
+ return x(n ? pe(Ca(y?.oldSelection, W), e) : V), { oldSelection: y?.oldSelection, frame: L };
872
963
  });
873
- }, [e, n]);
874
- return { registerEvent: G, unregisterEvent: _, shapesRef: a, selectedShape: s, hoveredShape: h, selectionFrame: d, setSelectionFrame: r, refreshSelectedShapes: z, addShapes: b, duplicateShapes: Q, addPictureShape: w, moveShapes: F, saveShapes: C, setSelectedShape: l, refreshHoveredShape: g, toggleShapeVisibility: E, toggleShapeLock: W, removeShape: V, updateShape: L, backwardShape: Z, forwardShape: A, clearShapes: H, canGoBackward: v, canGoForward: p, canClear: S };
875
- }, dn = (e) => {
964
+ }, [e, n, x]);
965
+ return { registerEvent: he, unregisterEvent: C, shapesRef: a, selectedShape: c, hoveredShape: d, selectionFrame: l, setSelectionFrame: s, copiedShape: p, setCopiedShape: f, refreshSelectedShapes: $, addShapes: P, duplicateShapes: z, addPictureShape: D, moveShapes: I, swapShapes: ne, saveShapes: g, setSelectedShape: x, refreshHoveredShape: N, toggleShapeVisibility: ee, toggleShapeLock: se, removeShape: T, updateShape: E, transformShape: j, backwardShape: F, forwardShape: X, clearShapes: Z, canGoBackward: k, canGoForward: M, canClear: S };
966
+ }, Cn = (e) => {
876
967
  const t = [e[0].clientX, e[0].clientY], i = [e[1].clientX, e[1].clientY];
877
968
  var n, a;
878
- return { diff: na(t, i), center: (a = i, [((n = t)[0] + a[0]) / 2, (n[1] + a[1]) / 2]) };
879
- }, bo = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: n, setCanvasTransformation: a }) => {
880
- const o = ne([]), [d, r] = $(o.current.length > 0), s = ne(null), l = ne(t);
881
- l.current = t;
882
- const h = X(({ startDiff: c, startZoom: u, startCenter: f, startOffset: v, currentDiff: p, currentCenter: S, isMoving: C, isZooming: b }) => {
883
- if (!e || !p || !c) return;
884
- const Q = (({ canvasBoundingRect: g, canvasSize: w, size: L, startDiff: D, startZoom: V, startCenter: x, startOffset: Z, currentDiff: A, currentCenter: H, isMoving: F, isZooming: E }) => {
885
- const W = E ? We(A / D * V, Pe[0], Pe[Pe.length - 1]) : V, G = F ? [Z[0] + (H[0] - x[0]) * (w.width / g.width) / w.scaleRatio / V, Z[1] + (H[1] - x[1]) * (w.height / g.height) / w.scaleRatio / V] : [Z[0], Z[1]], _ = [(H[0] - g.left) / w.scaleRatio, (H[1] - g.top) / w.scaleRatio];
886
- return ci({ size: L, canvasSize: w, currentOffset: G, currentZoom: V, zoom: W, centerPoint: _ });
887
- })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: n, startDiff: c, startZoom: u, startCenter: f, startOffset: v, currentDiff: p, currentCenter: S, isMoving: C, isZooming: b });
888
- a(Q);
969
+ return { diff: ba(t, i), center: (a = i, [((n = t)[0] + a[0]) / 2, (n[1] + a[1]) / 2]) };
970
+ }, Bo = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: n, setCanvasTransformation: a }) => {
971
+ const o = ce([]), [r, l] = J(o.current.length > 0), s = ce(null), c = ce(t);
972
+ c.current = t;
973
+ const h = G(({ startDiff: d, startZoom: u, startCenter: p, startOffset: f, currentDiff: m, currentCenter: b, isMoving: x, isZooming: k }) => {
974
+ if (!e || !m || !d) return;
975
+ const M = (({ canvasBoundingRect: S, canvasSize: g, size: P, startDiff: z, startZoom: N, startCenter: D, startOffset: E, currentDiff: A, currentCenter: T, isMoving: B, isZooming: F }) => {
976
+ const X = F ? et(A / z * N, Re[0], Re[Re.length - 1]) : N, Z = B ? [E[0] + (T[0] - D[0]) * (g.width / S.width) / g.scaleRatio / N, E[1] + (T[1] - D[1]) * (g.height / S.height) / g.scaleRatio / N] : [E[0], E[1]], ne = [(T[0] - S.left) / g.scaleRatio, (T[1] - S.top) / g.scaleRatio];
977
+ return Ci({ size: P, canvasSize: g, currentOffset: Z, currentZoom: N, zoom: X, centerPoint: ne });
978
+ })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: n, startDiff: d, startZoom: u, startCenter: p, startOffset: f, currentDiff: m, currentCenter: b, isMoving: x, isZooming: k });
979
+ a(M);
889
980
  }, [e, i, n, a]);
890
- ee(() => {
981
+ de(() => {
891
982
  if (!e) return;
892
- const c = (u) => {
893
- if (o.current = [...o.current, u], r(o.current.length > 0), o.current.length === 2) {
983
+ const d = (u) => {
984
+ if (o.current = [...o.current, u], l(o.current.length > 0), o.current.length === 2) {
894
985
  u.stopPropagation();
895
- const { diff: f, center: v } = dn(o.current);
896
- s.current = { startDiff: f, startCenter: v, startZoom: l.current.zoom, startOffset: l.current.offset, isMoving: !1, isZooming: !1 };
986
+ const { diff: p, center: f } = Cn(o.current);
987
+ s.current = { startDiff: p, startCenter: f, startZoom: c.current.zoom, startOffset: c.current.offset, isMoving: !1, isZooming: !1 };
897
988
  }
898
989
  };
899
- return e.addEventListener("pointerdown", c), () => {
900
- e.removeEventListener("pointerdown", c);
990
+ return e.addEventListener("pointerdown", d), () => {
991
+ e.removeEventListener("pointerdown", d);
901
992
  };
902
- }, [e]), ee(() => {
903
- if (!d) return;
904
- const c = (f) => {
905
- const v = o.current.findIndex((p) => p.pointerId === f.pointerId);
906
- if (v > -1 && (o.current[v] = f), o.current.length === 2 && s.current) {
907
- const { diff: p, center: S } = dn(o.current), C = s.current.isZooming || ((Q, g) => Math.abs(Q - g.startDiff) > 30)(p, s.current), b = s.current.isMoving || C || ((Q, g) => Math.abs(na(Q, g.startCenter)) > 10)(S, s.current);
908
- s.current = { ...s.current, isMoving: b, isZooming: C }, h({ ...s.current, currentDiff: p, currentCenter: S });
993
+ }, [e]), de(() => {
994
+ if (!r) return;
995
+ const d = (p) => {
996
+ const f = o.current.findIndex((m) => m.pointerId === p.pointerId);
997
+ if (f > -1 && (o.current[f] = p), o.current.length === 2 && s.current) {
998
+ const { diff: m, center: b } = Cn(o.current), x = s.current.isZooming || ((M, S) => Math.abs(M - S.startDiff) > 30)(m, s.current), k = s.current.isMoving || x || ((M, S) => Math.abs(ba(M, S.startCenter)) > 10)(b, s.current);
999
+ s.current = { ...s.current, isMoving: k, isZooming: x }, h({ ...s.current, currentDiff: m, currentCenter: b });
909
1000
  }
910
- }, u = (f) => {
911
- o.current = o.current.filter((v) => v.pointerId !== f.pointerId), r(o.current.length > 0);
1001
+ }, u = (p) => {
1002
+ o.current = o.current.filter((f) => f.pointerId !== p.pointerId), l(o.current.length > 0);
912
1003
  };
913
- return document.addEventListener("pointermove", c), document.addEventListener("pointerup", u), document.addEventListener("pointerout", u), document.addEventListener("pointercancel", u), document.addEventListener("pointerleave", u), () => {
914
- document.removeEventListener("pointermove", c), document.removeEventListener("pointerup", u), document.removeEventListener("pointerout", u), document.removeEventListener("pointercancel", u), document.removeEventListener("pointerleave", u);
1004
+ return document.addEventListener("pointermove", d), document.addEventListener("pointerup", u), document.addEventListener("pointerout", u), document.addEventListener("pointercancel", u), document.addEventListener("pointerleave", u), () => {
1005
+ document.removeEventListener("pointermove", d), document.removeEventListener("pointerup", u), document.removeEventListener("pointerout", u), document.removeEventListener("pointercancel", u), document.removeEventListener("pointerleave", u);
915
1006
  };
916
- }, [d, h]);
917
- }, cn = { offset: [0, 0], zoom: 1 }, wo = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: n }) => {
918
- const [a, o] = $(cn), d = ne(0), r = X((h) => {
919
- o(({ zoom: c }) => di({ zoom: c, size: t, canvasSize: e, newOffset: h }));
920
- }, [e, t]), s = X((h) => {
921
- o(({ offset: c, zoom: u }) => (({ size: f, canvasSize: v, currentOffset: p, currentZoom: S, action: C }) => {
922
- const b = C === "default" ? Pe[4] : C === "zoom" ? Pe[We(Pe.length - 1 - Pe.slice(0).reverse().findIndex((g) => g <= S) + 1, 0, Pe.length - 1)] : Pe[We(Pe.findIndex((g) => g >= S) - 1, 0, Pe.length - 1)], Q = [v.realWidth / 2, v.realHeight / 2];
923
- return ci({ size: f, canvasSize: v, currentOffset: p, currentZoom: S, zoom: b, centerPoint: Q });
924
- })({ size: t, canvasSize: e, currentOffset: c, currentZoom: u, action: h }));
1007
+ }, [r, h]);
1008
+ }, kn = { offset: [0, 0], zoom: 1 }, Oo = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: n }) => {
1009
+ const [a, o] = J(kn), r = ce(0), l = G((h) => {
1010
+ o(({ zoom: d }) => Mi({ zoom: d, size: t, canvasSize: e, newOffset: h }));
1011
+ }, [e, t]), s = G((h) => {
1012
+ o(({ offset: d, zoom: u }) => (({ size: p, canvasSize: f, currentOffset: m, currentZoom: b, action: x }) => {
1013
+ const k = x === "default" ? Re[4] : x === "zoom" ? Re[et(Re.length - 1 - Re.slice(0).reverse().findIndex((S) => S <= b) + 1, 0, Re.length - 1)] : Re[et(Re.findIndex((S) => S >= b) - 1, 0, Re.length - 1)], M = [f.realWidth / 2, f.realHeight / 2];
1014
+ return Ci({ size: p, canvasSize: f, currentOffset: m, currentZoom: b, zoom: k, centerPoint: M });
1015
+ })({ size: t, canvasSize: e, currentOffset: d, currentZoom: u, action: h }));
925
1016
  }, [e, t]);
926
- bo({ canvasElt: n, canvasTransformation: a, canvasSize: e, size: t, setCanvasTransformation: o });
927
- const l = X(() => {
928
- o(cn);
1017
+ Bo({ canvasElt: n, canvasTransformation: a, canvasSize: e, size: t, setCanvasTransformation: o });
1018
+ const c = G(() => {
1019
+ o(kn);
929
1020
  }, []);
930
- return ee(() => {
1021
+ return de(() => {
931
1022
  if (!i || !n) return;
932
- const h = (c) => {
933
- const u = c.ctrlKey, { deltaX: f, deltaY: v } = ((b, Q) => {
934
- const g = Math.abs(b.deltaY) < 50 && Q < 50, w = b.ctrlKey, L = ea() && g && w;
935
- switch (b.deltaMode) {
1023
+ const h = (d) => {
1024
+ const u = d.ctrlKey, { deltaX: p, deltaY: f } = ((k, M) => {
1025
+ const S = Math.abs(k.deltaY) < 50 && M < 50, g = k.ctrlKey, P = ma() && S && g;
1026
+ switch (k.deltaMode) {
936
1027
  case WheelEvent.DOM_DELTA_LINE:
937
- return { deltaX: 16 * b.deltaX, deltaY: 16 * b.deltaY };
1028
+ return { deltaX: 16 * k.deltaX, deltaY: 16 * k.deltaY };
938
1029
  case WheelEvent.DOM_DELTA_PAGE:
939
- return { deltaX: b.deltaX * window.innerHeight, deltaY: b.deltaY * window.innerHeight };
1030
+ return { deltaX: k.deltaX * window.innerHeight, deltaY: k.deltaY * window.innerHeight };
940
1031
  default:
941
- return L ? { deltaX: 5 * b.deltaX, deltaY: 5 * b.deltaY } : { deltaX: b.deltaX, deltaY: b.deltaY };
1032
+ return P ? { deltaX: 5 * k.deltaX, deltaY: 5 * k.deltaY } : { deltaX: k.deltaX, deltaY: k.deltaY };
942
1033
  }
943
- })(c, c.timeStamp - d.current);
944
- if (d.current = c.timeStamp, u) {
945
- c.preventDefault();
946
- const b = la(c, n, e);
947
- return void o(({ offset: Q, zoom: g }) => (({ size: w, canvasSize: L, currentOffset: D, currentZoom: V, delta: x, centerPoint: Z }) => {
948
- const A = We(V * (1 - x / 1e3), Pe[0], Pe[Pe.length - 1]);
949
- return ci({ size: w, canvasSize: L, currentOffset: D, currentZoom: V, zoom: A, centerPoint: Z });
950
- })({ size: t, canvasSize: e, currentOffset: Q, currentZoom: g, delta: v, centerPoint: b }));
1034
+ })(d, d.timeStamp - r.current);
1035
+ if (r.current = d.timeStamp, u) {
1036
+ d.preventDefault();
1037
+ const k = Pa(d, n, e);
1038
+ return void o(({ offset: M, zoom: S }) => (({ size: g, canvasSize: P, currentOffset: z, currentZoom: N, delta: D, centerPoint: E }) => {
1039
+ const A = et(N * (1 - D / 1e3), Re[0], Re[Re.length - 1]);
1040
+ return Ci({ size: g, canvasSize: P, currentOffset: z, currentZoom: N, zoom: A, centerPoint: E });
1041
+ })({ size: t, canvasSize: e, currentOffset: M, currentZoom: S, delta: f, centerPoint: k }));
951
1042
  }
952
- const p = c.shiftKey, [S, C] = p ? [v, f] : [f, v];
953
- o(({ offset: b, zoom: Q }) => {
954
- const g = [b[0] - S / Q, b[1] - C / Q], w = di({ zoom: Q, size: t, canvasSize: e, newOffset: g });
955
- return w.offset[0] === b[0] && w.offset[1] === b[1] || c.preventDefault(), w;
1043
+ const m = d.shiftKey, [b, x] = m ? [f, p] : [p, f];
1044
+ o(({ offset: k, zoom: M }) => {
1045
+ const S = [k[0] - b / M, k[1] - x / M], g = Mi({ zoom: M, size: t, canvasSize: e, newOffset: S });
1046
+ return g.offset[0] === k[0] && g.offset[1] === k[1] || d.preventDefault(), g;
956
1047
  });
957
1048
  };
958
1049
  return n.addEventListener("wheel", h, { passive: !1 }), () => {
959
1050
  n.removeEventListener("wheel", h);
960
1051
  };
961
- }, [n, t, e, i]), { setCanvasTransformation: o, setCanvasOffset: r, setCanvasZoom: s, resetZoom: l, canvasTransformation: a };
962
- }, hn = (e, t = !1) => {
1052
+ }, [n, t, e, i]), { setCanvasTransformation: o, setCanvasOffset: l, setCanvasZoom: s, resetZoom: c, canvasTransformation: a };
1053
+ }, Pn = (e, t = !1) => {
963
1054
  const i = (a, o) => {
964
1055
  if (Array.isArray(a)) return o;
965
1056
  }, n = e.map((a) => {
966
1057
  if (typeof a != "object") return null;
967
1058
  switch (a.type) {
968
1059
  case "brush":
969
- return Ie(i, Wn, a);
1060
+ return Ke(i, ta, a);
970
1061
  case "circle":
971
- return Ie(i, Yn, a);
1062
+ return Ke(i, ra, a);
972
1063
  case "curve":
973
- return Ie(i, Bn, a);
1064
+ return Ke(i, aa, a);
974
1065
  case "ellipse":
975
- return Ie(i, Xn, a);
1066
+ return Ke(i, la, a);
976
1067
  case "line":
977
- return Ie(i, Rn, a);
1068
+ return Ke(i, ia, a);
978
1069
  case "polygon":
979
- return Ie(i, Nn, a);
1070
+ return Ke(i, na, a);
980
1071
  case "rect":
981
- return Ie(i, On, a);
1072
+ return Ke(i, oa, a);
982
1073
  case "square":
983
- return Ie(i, Fn, a);
1074
+ return Ke(i, sa, a);
984
1075
  case "text":
985
- return Ie(i, $n, a);
1076
+ return Ke(i, ca, a);
986
1077
  }
987
1078
  return null;
988
1079
  });
989
- return xi(t ? [...n, fi] : n);
990
- }, us = ({ width: e = 1e3, height: t = 600, shapes: i, mode: n = "editor", disabled: a = !1, options: o = Bi } = {}) => {
991
- const { layersManipulation: d, brushAlgo: r, isBrushShapeDoneOnMouseUp: s, debug: l, grid: h, canGrow: c, canShrink: u, withExport: f, withLoadAndSave: v, withUploadPicture: p, withUrlPicture: S, withSkeleton: C, withFrameSelection: b, clearCallback: Q, availableTools: g, canvasSelectionPadding: w, size: L, canZoom: D } = { ...Bi, ...o }, V = n !== "viewer", x = ne(null), Z = ne(null), A = ne(!1), H = X((ie) => {
992
- x.current = ie;
993
- }, []), [F, E] = $(void 0), [W, G] = $(Oe), [_, z] = $({ mode: "default" }), [y, M] = $(h), [P, T] = $({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), k = D === "always" && !a, { canvasTransformation: O, setCanvasTransformation: R, setCanvasOffset: B, setCanvasZoom: I, resetZoom: j } = wo({ canvasSize: P, size: L, canvasElt: Z.current, zoomEnabled: k }), { offset: de, zoom: se } = O, K = kn(() => ({ brushAlgo: r, isBrushShapeDoneOnMouseUp: s, debug: l, canvasSize: { realWidth: P.realWidth, realHeight: P.realHeight, width: P.width, height: P.height, scaleRatioWithNoZoom: P.scaleRatio, scaleRatio: P.scaleRatio * se }, size: L, canvasOffset: de, canvasZoom: se, gridGap: y, selectionPadding: w, features: { edition: V && !a, zoom: k } }), [w, y, r, s, l, se, de, P, L, a, k, V]), [N, ge] = $(hn(g, p || S)), { isInsideComponent: oe, isInsideCanvas: ye } = (({ settings: ie, componentRef: ce, canvasRef: He }) => {
994
- const [Ye, Xe] = $(!1), [je, Ke] = $(!1), be = !ie.features.edition && !ie.features.zoom;
995
- return ee(() => {
996
- if (!be) {
997
- const ze = () => Xe(!0), wt = () => Xe(!1), $e = () => Ke(!0), xt = () => Ke(!1);
998
- return ce.current?.addEventListener("focusin", ze), ce.current?.addEventListener("focusout", wt), He.current?.addEventListener("focusin", $e), He.current?.addEventListener("focusout", xt), () => {
999
- ce.current?.removeEventListener("focusin", ze), ce.current?.removeEventListener("focusout", wt), He.current?.removeEventListener("focusin", $e), He.current?.removeEventListener("focusout", xt);
1080
+ return Ni(t ? [...n, zi] : n);
1081
+ }, Ts = ({ width: e = 1e3, height: t = 600, shapes: i, mode: n = "editor", disabled: a = !1, options: o = on } = {}) => {
1082
+ const { layersManipulation: r, brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, grid: h, canGrow: d, canShrink: u, withExport: p, withLoadAndSave: f, withUploadPicture: m, withUrlPicture: b, withSkeleton: x, withFrameSelection: k, withContextMenu: M, clearCallback: S, availableTools: g, canvasSelectionPadding: P, size: z, canZoom: N } = { ...on, ...o }, D = n !== "viewer", E = M && D && !a, A = ce(null), T = ce(null), B = ce(!1), F = G((oe) => {
1083
+ A.current = oe;
1084
+ }, []), [X, Z] = J(void 0), [ne, I] = J(Je), [j, ee] = J({ mode: "default" }), [se, he] = J(h), [C, $] = J({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), Q = N === "always" && !a, { canvasTransformation: w, setCanvasTransformation: y, setCanvasOffset: L, setCanvasZoom: W, resetZoom: V } = Oo({ canvasSize: C, size: z, canvasElt: T.current, zoomEnabled: Q }), { offset: U, zoom: R } = w, H = Yn(() => ({ brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, canvasSize: { realWidth: C.realWidth, realHeight: C.realHeight, width: C.width, height: C.height, scaleRatioWithNoZoom: C.scaleRatio, scaleRatio: C.scaleRatio * R }, size: z, canvasOffset: U, canvasZoom: R, gridGap: se, selectionPadding: P, features: { edition: D && !a, zoom: Q } }), [P, se, l, s, c, R, U, C, z, a, Q, D]), [ae, me] = J(Pn(g, m || b)), { isInsideComponent: O, isInsideCanvas: ge } = (({ settings: oe, componentRef: ve, canvasRef: Te }) => {
1085
+ const [ke, He] = J(!1), [Ue, qe] = J(!1), Pe = !oe.features.edition && !oe.features.zoom;
1086
+ return de(() => {
1087
+ if (!Pe) {
1088
+ const Ze = () => He(!0), Nt = () => He(!1), rt = () => qe(!0), Bt = () => qe(!1);
1089
+ return ve.current?.addEventListener("focusin", Ze), ve.current?.addEventListener("focusout", Nt), Te.current?.addEventListener("focusin", rt), Te.current?.addEventListener("focusout", Bt), () => {
1090
+ ve.current?.removeEventListener("focusin", Ze), ve.current?.removeEventListener("focusout", Nt), Te.current?.removeEventListener("focusin", rt), Te.current?.removeEventListener("focusout", Bt);
1000
1091
  };
1001
1092
  }
1002
- Xe(!1), Ke(!1);
1003
- }, [be, ce, He]), { isInsideComponent: Ye, isInsideCanvas: je };
1004
- })({ settings: K, componentRef: x, canvasRef: Z }), [Se, Qe] = $(!1), [te, ve] = $(!1), [U, ae] = $(!1), { registerEvent: Me, unregisterEvent: Ze, shapesRef: re, selectedShape: Te, selectionFrame: qe, hoveredShape: Ot, addShapes: De, addPictureShape: Ft, moveShapes: Yt, setSelectedShape: Ge, setSelectionFrame: Xt, refreshSelectedShapes: $t, refreshHoveredShape: Ut, duplicateShapes: fe, removeShape: me, updateShape: gt, backwardShape: Fe, forwardShape: at, clearShapes: Mi, saveShapes: Pi, toggleShapeVisibility: wa, toggleShapeLock: xa, canGoBackward: Ca, canGoForward: Ma, canClear: Pa } = Qo(K, e, t, Se), qt = X((ie) => {
1005
- Ge(void 0), G(ie);
1006
- }, [Ge]), [ot, ki] = $([0, 0]), Li = _.mode === "preview";
1007
- ee(() => {
1008
- if (Li) return () => z((ie) => ie.mode === "preview" ? { mode: "default" } : ie);
1009
- }, [Te?.id, Li]);
1010
- const Vi = _.mode === "selectionFrame";
1011
- ee(() => {
1012
- if (Vi) return () => ki([0, 0]);
1013
- }, [Vi]), ee(() => {
1014
- if (ot[0] !== 0 || ot[1] !== 0) {
1015
- const ie = setInterval(() => {
1016
- R(({ offset: ce, zoom: He }) => {
1017
- const Ye = [ce[0] - ot[0], ce[1] - ot[1]];
1018
- return di({ zoom: He, size: L, canvasSize: P, newOffset: Ye });
1093
+ He(!1), qe(!1);
1094
+ }, [Pe, ve, Te]), { isInsideComponent: ke, isInsideCanvas: Ue };
1095
+ })({ settings: H, componentRef: A, canvasRef: T }), [ue, Se] = J(!1), [Ie, te] = J(!1), [we, re] = J(!1), { registerEvent: ye, unregisterEvent: ie, shapesRef: le, selectedShape: fe, selectionFrame: Ve, hoveredShape: Fe, copiedShape: We, setCopiedShape: Ce, addShapes: Ye, addPictureShape: bt, moveShapes: Qt, swapShapes: ct, setSelectedShape: $e, setSelectionFrame: wt, refreshSelectedShapes: xt, refreshHoveredShape: Ae, duplicateShapes: ot, removeShape: st, updateShape: je, backwardShape: dt, forwardShape: ht, clearShapes: ut, saveShapes: be, toggleShapeVisibility: xe, toggleShapeLock: Y, transformShape: nt, canGoBackward: Tt, canGoForward: qa, canClear: Ga } = No(H, e, t, ue), li = G((oe) => {
1096
+ $e(void 0), I(oe);
1097
+ }, [$e]), [Mt, Oi] = J([0, 0]), Fi = j.mode === "preview";
1098
+ de(() => {
1099
+ if (Fi) return () => ee((oe) => oe.mode === "preview" ? { mode: "default" } : oe);
1100
+ }, [fe?.id, Fi]);
1101
+ const Yi = j.mode === "selectionFrame";
1102
+ de(() => {
1103
+ if (Yi) return () => Oi([0, 0]);
1104
+ }, [Yi]), de(() => {
1105
+ if (Mt[0] !== 0 || Mt[1] !== 0) {
1106
+ const oe = setInterval(() => {
1107
+ y(({ offset: ve, zoom: Te }) => {
1108
+ const ke = [ve[0] - Mt[0], ve[1] - Mt[1]];
1109
+ return Mi({ zoom: Te, size: z, canvasSize: C, newOffset: ke });
1019
1110
  });
1020
1111
  }, 20);
1021
- return () => clearInterval(ie);
1112
+ return () => clearInterval(oe);
1022
1113
  }
1023
- }, [ot[0], ot[1], R, L, P]);
1024
- const bt = X((ie, ce) => {
1025
- Mi(ie, ce), qt(Oe), R({ offset: [0, 0], zoom: 1 });
1026
- }, [qt, Mi, R]), Zi = X((ie) => {
1027
- Ge((ce) => (ce?.id !== ie.map((He) => He.id).join("-") && G(Oe), pe(ie, K)));
1028
- }, [Ge, K]), ka = X(() => {
1029
- const ie = yo(re.current, e, t);
1030
- if (!ie) throw new Error("L'encodage a échoué");
1031
- sn(ie, "drawing.json");
1032
- }, [re, e, t]), La = X((ie) => {
1033
- const ce = rn({ shapes: re.current, settings: K, view: ie });
1034
- sn(ce, "drawing.png");
1035
- }, [re, K]), Va = X((ie) => rn({ shapes: re.current, settings: K, view: ie }), [re, K]), Za = X(() => Ci(re.current, e, t), [re, e, t]), _e = X(async (ie, ce) => {
1036
- const He = await (async (Ye, Xe) => {
1037
- if (!Ye) return [];
1038
- const je = [], Ke = xi(Ye.map((be) => {
1039
- if (!be || !_n.includes(be.type)) return null;
1040
- if (be.type === "picture") {
1041
- const ze = new Image(), wt = new Promise(($e, xt) => {
1042
- ze.onload = () => {
1043
- URL.revokeObjectURL(ze.src), $e();
1044
- }, ze.onerror = () => {
1045
- xt(new Error("Some images could not be loaded"));
1114
+ }, [Mt[0], Mt[1], y, z, C]);
1115
+ const Rt = G((oe, ve) => {
1116
+ ut(oe, ve), li(Je), y({ offset: [0, 0], zoom: 1 });
1117
+ }, [li, ut, y]), Ct = G((oe) => {
1118
+ $e((ve) => (ve?.id !== oe.map((Te) => Te.id).join("-") && I(Je), pe(oe, H)));
1119
+ }, [$e, H]), Xi = G((oe) => {
1120
+ Ye(oe), Ct(oe);
1121
+ }, [Ye, Ct]), $i = G(() => {
1122
+ Ct(le.current);
1123
+ }, [Ct, le]), _a = G(() => {
1124
+ const oe = Wo(le.current, e, t);
1125
+ if (!oe) throw new Error("L'encodage a échoué");
1126
+ wn(oe, "drawing.json");
1127
+ }, [le, e, t]), ja = G((oe) => {
1128
+ const ve = xn({ shapes: le.current, settings: H, view: oe });
1129
+ wn(ve, "drawing.png");
1130
+ }, [le, H]), Ka = G((oe) => xn({ shapes: le.current, settings: H, view: oe }), [le, H]), Ja = G(() => Bi(le.current, e, t), [le, e, t]), pt = G(async (oe, ve) => {
1131
+ const Te = await (async (ke, He) => {
1132
+ if (!ke) return [];
1133
+ const Ue = [], qe = Ni(ke.map((Pe) => {
1134
+ if (!Pe || !pa.includes(Pe.type)) return null;
1135
+ if (Pe.type === "picture") {
1136
+ const Ze = new Image(), Nt = new Promise((rt, Bt) => {
1137
+ Ze.onload = () => {
1138
+ URL.revokeObjectURL(Ze.src), rt();
1139
+ }, Ze.onerror = () => {
1140
+ Bt(new Error("Some images could not be loaded"));
1046
1141
  };
1047
1142
  });
1048
- if (je.push(wt), be.src.startsWith("http")) Qa(be.src).then(($e) => {
1049
- ze.src = $e;
1143
+ if (Ue.push(Nt), Pe.src.startsWith("http")) Xa(Pe.src).then((rt) => {
1144
+ Ze.src = rt;
1050
1145
  }).catch(() => {
1051
- ze.src = "";
1146
+ Ze.src = "";
1052
1147
  });
1053
- else if (be.src.includes("<svg")) {
1054
- const $e = new Blob([be.src], { type: "image/svg+xml" });
1055
- ze.src = URL.createObjectURL($e);
1056
- } else ze.src = be.src;
1057
- return ln({ ...be, img: ze }, Xe);
1148
+ else if (Pe.src.includes("<svg")) {
1149
+ const rt = new Blob([Pe.src], { type: "image/svg+xml" });
1150
+ Ze.src = URL.createObjectURL(rt);
1151
+ } else Ze.src = Pe.src;
1152
+ return Mn({ ...Pe, img: Ze }, He);
1058
1153
  }
1059
- return ln(be, Xe);
1154
+ return Mn(Pe, He);
1060
1155
  }));
1061
- return await Promise.all(je), Ke;
1062
- })(ie, K);
1063
- bt(He, ce);
1064
- }, [bt, K]), Gt = ne(_e);
1065
- Gt.current = _e;
1066
- const Ha = X((ie = [], ce = !0) => {
1067
- Gt.current?.(ie, { clearHistory: ce, source: "remote" });
1156
+ return await Promise.all(Ue), qe;
1157
+ })(oe, H);
1158
+ Rt(Te, ve);
1159
+ }, [Rt, H]), ci = ce(pt);
1160
+ ci.current = pt;
1161
+ const eo = G((oe = [], ve = !0) => {
1162
+ ci.current?.(oe, { clearHistory: ve, source: "remote" });
1068
1163
  }, []);
1069
- ee(() => {
1070
- A.current || (A.current = !0, i && Gt.current?.(i, { clearHistory: !0, source: "remote" }));
1164
+ de(() => {
1165
+ B.current || (B.current = !0, i && ci.current?.(i, { clearHistory: !0, source: "remote" }));
1071
1166
  }, [i]);
1072
- const za = X(async (ie) => {
1073
- const ce = await (async (He) => new Promise((Ye, Xe) => {
1074
- const je = new FileReader();
1075
- je.onload = (Ke) => {
1076
- const be = Ke.target?.result;
1077
- if (!be) return Xe("Impossible de récupérer les données du fichier");
1078
- const ze = JSON.parse(be);
1079
- Ye(ze);
1080
- }, je.readAsText(He);
1081
- }))(ie);
1082
- await _e(ce.shapes ?? [], { clearHistory: !0, source: "remote" });
1083
- }, [_e]), Ta = X(() => {
1084
- typeof Q != "string" ? _e(Q(), { clearHistory: !1, source: "user" }) : Q === "defaultShapes" && i !== void 0 ? _e(i, { clearHistory: !1, source: "user" }) : bt([], { clearHistory: !1, source: "user" });
1085
- }, [bt, _e, i, Q]);
1086
- ee(() => {
1087
- ge(hn(g, p || S));
1088
- }, [g, p, S]);
1089
- const Hi = { canvas: Z, editor: x, setEditor: H };
1090
- 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": K.canvasZoom, "--react-paint-canvas-offset-x": K.canvasOffset[0], "--react-paint-canvas-offset-y": K.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: re, addPictureShape: Ft, moveShapes: Yt, toggleShapeVisibility: wa, toggleShapeLock: xa, canGoBackward: Ca, canGoForward: Ma, canClear: Pa, selectedShape: Te, saveShapes: Pi, removeShape: me, updateShape: gt, backwardShape: Fe, forwardShape: at, refs: Hi, width: e, height: t, selectTool: qt, selectShapes: Zi, activeTool: W, setActiveTool: G, setAvailableTools: ge, isEditMode: V, availableTools: N, gridGap: y, setGridGap: M, loadFile: za, exportPicture: La, exportData: ka, clearCanvas: Ta, settings: K, setCanvasZoom: I, resetZoom: j, canvas: { canGrow: c, canShrink: u, layersManipulation: d, withExport: f, withLoadAndSave: v, withUploadPicture: p, withUrlPicture: S } }, canvasProps: { shapesRef: re, selectedShape: Te, selectionFrame: qe, hoveredShape: Ot, addShape: De, setSelectedShape: Ge, setSelectionFrame: Xt, refreshSelectedShapes: $t, refreshHoveredShape: Ut, removeShape: me, updateShape: gt, duplicateShapes: fe, backwardShape: Fe, forwardShape: at, saveShapes: Pi, refs: Hi, width: e, height: t, settings: K, setCanvasSize: T, setCanvasOffset: B, setCanvasZoom: I, resetZoom: j, selectShapes: Zi, activeTool: W, setActiveTool: G, isInsideComponent: oe, isInsideCanvas: ye, isEditMode: V, canvas: { withSkeleton: C, withFrameSelection: b, canGrow: c, canShrink: u }, canvasOffsetStartData: F, setCanvasOffsetStartData: E, selectionMode: _, setSelectionMode: z, setCanvasMoveAcceleration: ki, isShiftPressed: Se, isAltPressed: te, isSpacePressed: U, setShiftPressed: Qe, setAltPressed: ve, setIsSpacePressed: ae }, registerEvent: Me, unregisterEvent: Ze, resetCanvas: Ha, resetZoom: j, getCurrentImage: Va, getCurrentData: Za, setCanvasOffset: B, setCanvasZoom: I };
1091
- }, xo = ({ addShapes: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: n, shapes: a, selectionMode: o, activeTool: d, isInsideComponent: r, setCanvasOffset: s, selectedShape: l, canvasOffsetStartData: h, refreshSelectedShapes: c, setSelectedShape: u, setSelectionFrame: f, setCanvasOffsetStartData: v, updateSingleShape: p, duplicateShapes: S, saveShapes: C, setSelectionMode: b, setCanvasMoveAcceleration: Q, settings: g, isShiftPressed: w, isAltPressed: L, withFrameSelection: D, isSpacePressed: V }) => {
1092
- const [x, Z] = $({ mode: "default" }), { registerDoubleClickEvent: A, unRegisterDoubleClickEvent: H } = (() => {
1093
- const y = ne(void 0), M = ne(void 0), P = (T) => {
1094
- const k = Date.now();
1095
- y.current && k < y.current + 300 && M.current?.(T), y.current = Date.now();
1167
+ const to = G(async (oe) => {
1168
+ const ve = await (async (Te) => new Promise((ke, He) => {
1169
+ const Ue = new FileReader();
1170
+ Ue.onload = (qe) => {
1171
+ const Pe = qe.target?.result;
1172
+ if (!Pe) return He("Impossible de récupérer les données du fichier");
1173
+ const Ze = JSON.parse(Pe);
1174
+ ke(Ze);
1175
+ }, Ue.readAsText(Te);
1176
+ }))(oe);
1177
+ await pt(ve.shapes ?? [], { clearHistory: !0, source: "remote" });
1178
+ }, [pt]), io = G(() => {
1179
+ typeof S != "string" ? pt(S(), { clearHistory: !1, source: "user" }) : S === "defaultShapes" && i !== void 0 ? pt(i, { clearHistory: !1, source: "user" }) : Rt([], { clearHistory: !1, source: "user" });
1180
+ }, [Rt, pt, i, S]), no = G((oe, ve) => {
1181
+ const Te = oe.type === "curve" ? ((ke, He, Ue) => {
1182
+ if (He < 0 || He > ke.points.length - 1) return ke;
1183
+ const qe = { ...ke, points: ke.points.filter((Pe, Ze) => Ze !== He) };
1184
+ return At(qe, Ue);
1185
+ })(oe, ve, H) : ((ke, He, Ue) => {
1186
+ if (He < 0 || He > ke.points.length - 1) return ke;
1187
+ const qe = { ...ke, points: ke.points.filter((Pe, Ze) => Ze !== He) };
1188
+ return zt(qe, Ue);
1189
+ })(oe, ve, H);
1190
+ je([Te], !0);
1191
+ }, [H, je]);
1192
+ de(() => {
1193
+ me(Pn(g, m || b));
1194
+ }, [g, m, b]);
1195
+ const Ui = { canvas: T, editor: A, setEditor: F };
1196
+ return { annotationsProps: { style: { userSelect: "none", touchAction: "none", transformOrigin: "left top", transform: "scale(var(--react-paint-canvas-zoom)) translate(calc(var(--react-paint-canvas-offset-x) * 100% / var(--react-paint-app-canvaswidth)), calc(var(--react-paint-canvas-offset-y) * 100% / var(--react-paint-app-canvasheight)))", "--react-paint-canvas-zoom": H.canvasZoom, "--react-paint-canvas-offset-x": H.canvasOffset[0], "--react-paint-canvas-offset-y": H.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: le, addPictureShape: bt, moveShapes: Qt, swapShapes: ct, toggleShapeVisibility: xe, toggleShapeLock: Y, duplicateShapes: ot, canGoBackward: Tt, canGoForward: qa, canClear: Ga, selectedShape: fe, copiedShape: We, setCopiedShape: Ce, pasteShapes: Xi, saveShapes: be, removeShape: st, updateShape: je, backwardShape: dt, forwardShape: ht, removeShapePoint: no, transformShape: nt, refs: Ui, width: e, height: t, selectTool: li, selectShapes: Ct, selectAllShapes: $i, activeTool: ne, setActiveTool: I, setAvailableTools: me, isEditMode: D, availableTools: ae, gridGap: se, setGridGap: he, loadFile: to, exportPicture: ja, exportData: _a, clearCanvas: io, selectionMode: j, setSelectionMode: ee, settings: H, setCanvasZoom: W, resetZoom: V, canvas: { canGrow: d, canShrink: u, layersManipulation: r, withExport: p, withLoadAndSave: f, withUploadPicture: m, withUrlPicture: b, withContextMenu: E } }, canvasProps: { shapesRef: le, selectedShape: fe, selectionFrame: Ve, hoveredShape: Fe, copiedShape: We, pasteShapes: Xi, setCopiedShape: Ce, addShape: Ye, setSelectedShape: $e, setSelectionFrame: wt, refreshSelectedShapes: xt, refreshHoveredShape: Ae, removeShape: st, updateShape: je, duplicateShapes: ot, backwardShape: dt, forwardShape: ht, saveShapes: be, refs: Ui, width: e, height: t, settings: H, setCanvasSize: $, setCanvasOffset: L, setCanvasZoom: W, resetZoom: V, selectShapes: Ct, selectAllShapes: $i, activeTool: ne, setActiveTool: I, isInsideComponent: O, isInsideCanvas: ge, isEditMode: D, canvas: { withSkeleton: x, withFrameSelection: k, withContextMenu: E, canGrow: d, canShrink: u }, canvasOffsetStartData: X, setCanvasOffsetStartData: Z, selectionMode: j, setSelectionMode: ee, setCanvasMoveAcceleration: Oi, isShiftPressed: ue, isAltPressed: Ie, isSpacePressed: we, setShiftPressed: Se, setAltPressed: te, setIsSpacePressed: re }, registerEvent: ye, unregisterEvent: ie, resetCanvas: eo, resetZoom: V, getCurrentImage: Ka, getCurrentData: Ja, setCanvasOffset: L, setCanvasZoom: W };
1197
+ }, Fo = ({ addShapes: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: n, shapes: a, selectionMode: o, activeTool: r, isInsideComponent: l, isInsideCanvas: s, setCanvasOffset: c, selectedShape: h, canvasOffsetStartData: d, refreshSelectedShapes: u, setSelectedShape: p, setSelectionFrame: f, setCanvasOffsetStartData: m, updateSingleShape: b, duplicateShapes: x, saveShapes: k, setSelectionMode: M, setCanvasMoveAcceleration: S, settings: g, isShiftPressed: P, isAltPressed: z, withFrameSelection: N, withContextMenu: D, isSpacePressed: E }) => {
1198
+ const A = ce(null), [T, B] = J({ mode: "default" }), { registerDoubleClickEvent: F, unRegisterDoubleClickEvent: X } = (() => {
1199
+ const C = ce(void 0), $ = ce(void 0), Q = (w) => {
1200
+ const y = Date.now();
1201
+ C.current && y < C.current + 300 && $.current?.(w), C.current = Date.now();
1096
1202
  };
1097
- return { registerDoubleClickEvent: (T, k) => {
1098
- M.current = k, T.addEventListener("click", P), T.addEventListener("touchend", P);
1099
- }, unRegisterDoubleClickEvent: (T) => {
1100
- T.removeEventListener("click", P), T.removeEventListener("touchend", P);
1203
+ return { registerDoubleClickEvent: (w, y) => {
1204
+ $.current = y, w.addEventListener("click", Q), w.addEventListener("touchend", Q);
1205
+ }, unRegisterDoubleClickEvent: (w) => {
1206
+ w.removeEventListener("click", Q), w.removeEventListener("touchend", Q);
1101
1207
  } };
1102
- })(), F = ne(null);
1103
- F.current = (y) => ((M, P, T, k, O, R, B, I, j, de, se, K, N, ge, oe, ye, Se) => {
1104
- if (rt(M) && M.touches.length > 1) return;
1105
- const Qe = P.current?.getContext("2d");
1106
- if (!Qe) return;
1107
- const te = st(M, P.current, N);
1108
- if (k.mode === "selectionFrame") {
1109
- K(Qe, te, N);
1110
- const U = la(M, P.current, N.canvasSize);
1111
- return void Se([Math.ceil(We(U[0] * N.canvasZoom < 50 ? U[0] * N.canvasZoom - 50 : U[0] * N.canvasZoom > N.canvasSize.width / N.canvasSize.scaleRatioWithNoZoom - 50 ? U[0] * N.canvasZoom - (N.canvasSize.width / N.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / N.canvasZoom), Math.ceil(We(U[1] * N.canvasZoom < 50 ? U[1] * N.canvasZoom - 50 : U[1] * N.canvasZoom > N.canvasSize.height / N.canvasSize.scaleRatioWithNoZoom - 50 ? U[1] * N.canvasZoom - (N.canvasSize.height / N.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / N.canvasZoom)]);
1208
+ })(), Z = (C, $) => {
1209
+ const Q = $?.getContext("2d");
1210
+ if (Q) {
1211
+ if (r === Je && D) {
1212
+ const w = ft(C, t.current, g), { shape: y, mode: L } = Ot(Q, a, w, g, h, at(C), !1);
1213
+ p(y), M({ mode: "contextMenu", cursorStartPosition: w, originalShape: y, anchor: "anchor" in L ? L.anchor : void 0 });
1214
+ } else p(void 0), M({ mode: "default" });
1215
+ i(Je), f(void 0);
1112
1216
  }
1113
- if (R !== void 0) return void se([te[0] + N.canvasOffset[0] - R.start[0], te[1] + N.canvasOffset[1] - R.start[1]]);
1114
- if (k.mode === "preview") {
1115
- const U = Y(T)[0];
1116
- if (U?.type === "curve") {
1117
- const ae = Ki(U, te, N, !0);
1118
- return void ye(pe([ae], N));
1217
+ }, ne = ce(null);
1218
+ ne.current = (C) => (($, Q, w, y, L, W, V, U, R, H, ae, me, O, ge, ue, Se, Ie, te) => {
1219
+ if (te && clearTimeout(te), at($) && $.touches.length > 1) return;
1220
+ const we = Q.current?.getContext("2d");
1221
+ if (!we) return;
1222
+ const re = ft($, Q.current, O);
1223
+ if (y.mode === "selectionFrame") {
1224
+ me(we, re, O);
1225
+ const ie = Pa($, Q.current, O.canvasSize);
1226
+ return void Ie([Math.ceil(et(ie[0] * O.canvasZoom < 50 ? ie[0] * O.canvasZoom - 50 : ie[0] * O.canvasZoom > O.canvasSize.width / O.canvasSize.scaleRatioWithNoZoom - 50 ? ie[0] * O.canvasZoom - (O.canvasSize.width / O.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / O.canvasZoom), Math.ceil(et(ie[1] * O.canvasZoom < 50 ? ie[1] * O.canvasZoom - 50 : ie[1] * O.canvasZoom > O.canvasSize.height / O.canvasSize.scaleRatioWithNoZoom - 50 ? ie[1] * O.canvasZoom - (O.canvasSize.height / O.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / O.canvasZoom)]);
1227
+ }
1228
+ if (W !== void 0) return void ae([re[0] + O.canvasOffset[0] - W.start[0], re[1] + O.canvasOffset[1] - W.start[1]]);
1229
+ if (y.mode === "preview") {
1230
+ const ie = _(w)[0];
1231
+ if (ie?.type === "curve") {
1232
+ const le = fn(ie, re, O, !0);
1233
+ return void Se(pe([le], O));
1119
1234
  }
1120
- if (U?.type === "polygon") {
1121
- const ae = ji(U, te, N, !0);
1122
- return void ye(pe([ae], N));
1235
+ if (ie?.type === "polygon") {
1236
+ const le = gn(ie, re, O, !0);
1237
+ return void Se(pe([le], O));
1123
1238
  }
1124
1239
  }
1125
- const ve = vt(te, N);
1126
- if (rt(M) || I(M, Qe, te, ve), T === void 0 || T.locked) B({ mode: "default", outOfView: !ve });
1240
+ const ye = Dt(re, O);
1241
+ if (at($) || U($, we, re, ye), w === void 0 || w.locked) V({ mode: "default", outOfView: !ye });
1127
1242
  else {
1128
- if (k.mode === "default" || k.mode === "textedition") {
1129
- if (!ve) return void B({ mode: "default" });
1130
- B(ft(Qe, T, te, N, !0) || { mode: "default" });
1243
+ if (y.mode === "default" || y.mode === "textedition" || y.mode === "contextMenu") {
1244
+ if (!ye) return void V({ mode: "default" });
1245
+ V(Et(we, w, re, O, !0) || { mode: "default" });
1131
1246
  } else {
1132
- const U = P.current?.getContext("2d");
1133
- if (!U) return;
1134
- const ae = Na(U, T, te, k, N, ge, oe);
1135
- j(Y(ae));
1247
+ const ie = Q.current?.getContext("2d");
1248
+ if (!ie) return;
1249
+ const le = ho(ie, w, re, y, O, ge, ue);
1250
+ R(_(le));
1136
1251
  }
1137
- k.mode === "translate" && oe && !k.hasBeenDuplicated && (O({ ...k, hasBeenDuplicated: !0 }), de(Y(k.originalShape)));
1252
+ y.mode === "translate" && ue && !y.hasBeenDuplicated && (L({ ...y, hasBeenDuplicated: !0 }), H(_(y.originalShape)));
1138
1253
  }
1139
- })(y, t, l, o, b, h, Z, n, p, S, s, c, g, w, L, u, Q), ee(() => {
1140
- if (r) {
1141
- const y = (M) => F.current?.(M);
1142
- return document.addEventListener("mousemove", y), document.addEventListener("touchmove", y), () => {
1143
- document.removeEventListener("mousemove", y), document.removeEventListener("touchmove", y);
1254
+ })(C, t, h, o, M, d, B, n, b, x, c, u, g, P, z, p, S, A.current), de(() => {
1255
+ if (l) {
1256
+ const C = ($) => ne.current?.($);
1257
+ return document.addEventListener("mousemove", C), document.addEventListener("touchmove", C), () => {
1258
+ document.removeEventListener("mousemove", C), document.removeEventListener("touchmove", C);
1144
1259
  };
1145
1260
  }
1146
- }, [r]);
1147
- const { isBrushShapeDoneOnMouseUp: E } = g, W = ne(null);
1148
- W.current = (y) => {
1149
- if (rt(y) && y.touches.length > 1) return;
1150
- const M = t.current?.getContext("2d");
1151
- if (!M) return;
1152
- if ("button" in y && y.button === 2) return u(void 0), i(Oe), b({ mode: "default" }), void f(void 0);
1153
- if (h) return void v(void 0);
1154
- if (o.mode === "textedition" || o.mode === "preview") return;
1155
- const P = st(y, t.current, g);
1156
- if (o.mode === "translate" && Date.now() - o.dateStart <= 500 && P[0] === o.cursorStartPosition[0] && P[1] === o.cursorStartPosition[1]) {
1157
- if (y.ctrlKey || y.shiftKey || y.metaKey) {
1158
- const { shape: T } = Ui(M, a, P, g, l, rt(y), D, "remove");
1159
- Y(T).length !== o.selectedShapesLengthAtMouseDown && u(T);
1261
+ }, [l]);
1262
+ const { isBrushShapeDoneOnMouseUp: I } = g, j = ce(null);
1263
+ j.current = (C) => {
1264
+ if (A.current && clearTimeout(A.current), at(C) && C.touches.length > 1) return;
1265
+ const $ = t.current?.getContext("2d");
1266
+ if (!$) return;
1267
+ if ("button" in C && C.button === 2) return void Z(C, t.current);
1268
+ if (d) return void m(void 0);
1269
+ if (o.mode === "contextMenu" || o.mode === "textedition" || o.mode === "preview") return;
1270
+ const Q = ft(C, t.current, g);
1271
+ if (o.mode === "translate" && Date.now() - o.dateStart <= 500 && Q[0] === o.cursorStartPosition[0] && Q[1] === o.cursorStartPosition[1]) {
1272
+ if (C.ctrlKey || C.shiftKey || C.metaKey) {
1273
+ const { shape: w } = Ot($, a, Q, g, h, at(C), N, "remove");
1274
+ _(w).length !== o.selectedShapesLengthAtMouseDown && p(w);
1160
1275
  }
1161
- return b({ mode: "default" }), f(void 0), void C();
1276
+ return M({ mode: "default" }), f(void 0), void k();
1162
1277
  }
1163
- o.mode !== "default" && (o.mode === "brush" && E && u(void 0), b({ mode: "default" }), f(void 0), C());
1164
- }, ee(() => {
1165
- if (r) {
1166
- const y = (M) => W.current?.(M);
1167
- return document.addEventListener("mouseup", y), document.addEventListener("touchend", y), () => {
1168
- document.removeEventListener("mouseup", y), document.removeEventListener("touchend", y);
1278
+ o.mode !== "default" && (o.mode === "brush" && I && p(void 0), M({ mode: "default" }), f(void 0), k());
1279
+ }, de(() => {
1280
+ if (s) {
1281
+ const C = ($) => j.current?.($);
1282
+ return document.addEventListener("mouseup", C), document.addEventListener("touchend", C), () => {
1283
+ document.removeEventListener("mouseup", C), document.removeEventListener("touchend", C);
1169
1284
  };
1170
1285
  }
1171
- }, [r]);
1172
- const G = !g.features.edition && g.features.zoom, _ = !g.features.edition && !g.features.zoom, z = ne(null);
1173
- return z.current = (y, M, P) => {
1174
- if (y.preventDefault(), rt(y) && y.touches.length > 1) return;
1175
- const T = M?.getContext("2d");
1176
- if (!T) return;
1177
- M.focus();
1178
- const k = st(y, t.current, g), O = "button" in y && y.button === 1;
1179
- if (!("button" in y && y.button === 2)) {
1180
- if (O || P || d.type === "move") v({ start: k, originalOffset: g.canvasOffset });
1181
- else if (!G) {
1182
- if (!vt(k, g)) return u(void 0), void b({ mode: "default" });
1183
- if (d.type === "selection") {
1184
- const R = y.ctrlKey || y.shiftKey || y.metaKey ? "add" : "replace", { shape: B, mode: I } = Ui(T, a, k, g, l, rt(y), D, R);
1185
- u(B), b(I), I.mode === "selectionFrame" && f({ oldSelection: B, frame: [[k[0], k[1]], [k[0], k[1]]] });
1186
- } else if (_n.some((R) => R === d.type)) {
1187
- const R = Y(l)[0], B = t.current?.getContext("2d");
1188
- if (!B) return;
1189
- if (d.type === "brush") {
1190
- if (R?.type === "brush") {
1191
- const I = ((j, de, se) => {
1192
- const K = { ...j, points: Le(j.points.length, [[Math.round(de[0]), Math.round(de[1])]], j.points) };
1193
- return ut(K, se);
1194
- })(R, k, g);
1195
- p([I]);
1196
- } else {
1197
- const I = tn(B, d, k, g);
1198
- if (!I) return;
1199
- e([I]), u(pe([I], g));
1200
- }
1201
- b({ mode: "brush" });
1202
- } else if (o.mode !== "preview" || R?.type !== "polygon" && R?.type !== "curve") {
1203
- if (d.type !== "picture") {
1204
- const I = tn(B, d, k, g);
1205
- if (!I) return;
1206
- e([I]);
1207
- const j = pe([I], g);
1208
- u(j), I.type === "polygon" || I.type === "curve" ? b({ mode: "preview" }) : (i(Oe), b({ mode: "resize", cursorStartPosition: [k[0] + g.selectionPadding, k[1] + g.selectionPadding], originalShape: j, anchor: I.type === "line" ? 0 : [1, 1], selectedShapesLengthAtMouseDown: Y(j).length }));
1209
- }
1286
+ }, [s]);
1287
+ const ee = !g.features.edition && g.features.zoom, se = !g.features.edition && !g.features.zoom, he = ce(null);
1288
+ return he.current = (C, $, Q) => {
1289
+ if (C.preventDefault(), at(C) && C.touches.length > 1) return;
1290
+ const w = $?.getContext("2d");
1291
+ if (!w) return;
1292
+ $.focus();
1293
+ const y = ft(C, t.current, g), L = "button" in C && C.button === 1, W = "button" in C && C.button === 2;
1294
+ if (L || Q || r.type === "move" && !W) m({ start: y, originalOffset: g.canvasOffset });
1295
+ else if (!ee) {
1296
+ if (!Dt(y, g)) return p(void 0), void M({ mode: "default" });
1297
+ if (W) {
1298
+ if (r.type === "selection") {
1299
+ const { shape: V } = Ot(w, a, y, g, h, at(C), !1);
1300
+ p(V), M({ mode: "default" });
1301
+ }
1302
+ } else if (at(C) && (A.current && clearTimeout(A.current), A.current = setTimeout(() => {
1303
+ Z(C, t.current);
1304
+ }, 500)), r.type === "selection") {
1305
+ const V = C.ctrlKey || C.shiftKey || C.metaKey ? "add" : "replace", { shape: U, mode: R } = Ot(w, a, y, g, h, at(C), N, V);
1306
+ p(U), M(R), R.mode === "selectionFrame" && f({ oldSelection: U, frame: [[y[0], y[1]], [y[0], y[1]]] });
1307
+ } else if (pa.some((V) => V === r.type)) {
1308
+ const V = _(h)[0], U = t.current?.getContext("2d");
1309
+ if (!U) return;
1310
+ if (r.type === "brush") {
1311
+ if (V?.type === "brush") {
1312
+ const R = ((H, ae, me) => {
1313
+ const O = { ...H, points: Xe(H.points.length, [[Math.round(ae[0]), Math.round(ae[1])]], H.points) };
1314
+ return Zt(O, me);
1315
+ })(V, y, g);
1316
+ b([R]);
1210
1317
  } else {
1211
- const I = R.type === "polygon" ? ji(R, k, g) : Ki(R, k, g);
1212
- u(pe([I], g)), p([I], !0);
1318
+ const R = yn(U, r, y, g);
1319
+ if (!R) return;
1320
+ e([R]), p(pe([R], g));
1321
+ }
1322
+ M({ mode: "brush" });
1323
+ } else if (o.mode !== "preview" || V?.type !== "polygon" && V?.type !== "curve") {
1324
+ if (r.type !== "picture") {
1325
+ const R = yn(U, r, y, g);
1326
+ if (!R) return;
1327
+ e([R]);
1328
+ const H = pe([R], g);
1329
+ p(H), R.type === "polygon" || R.type === "curve" ? M({ mode: "preview" }) : (i(Je), M({ mode: "resize", cursorStartPosition: [y[0] + g.selectionPadding, y[1] + g.selectionPadding], originalShape: H, anchor: R.type === "line" ? 0 : [1, 1], selectedShapesLengthAtMouseDown: _(H).length }));
1213
1330
  }
1331
+ } else {
1332
+ const R = V.type === "polygon" ? gn(V, y, g) : fn(V, y, g);
1333
+ p(pe([R], g)), b([R], !0);
1214
1334
  }
1215
1335
  }
1216
1336
  }
1217
- }, ee(() => {
1218
- if (_) return;
1219
- const y = t.current;
1220
- if (!y) return;
1221
- const M = (P) => z.current?.(P, y, V);
1222
- return y.addEventListener("mousedown", M, { passive: !1 }), y.addEventListener("touchstart", M, { passive: !1 }), () => {
1223
- y.removeEventListener("mousedown", M), y.removeEventListener("touchstart", M);
1337
+ }, de(() => {
1338
+ if (se) return;
1339
+ const C = t.current;
1340
+ if (!C) return;
1341
+ const $ = (Q) => he.current?.(Q, C, E);
1342
+ return C.addEventListener("mousedown", $, { passive: !1 }), C.addEventListener("touchstart", $, { passive: !1 }), () => {
1343
+ C.removeEventListener("mousedown", $), C.removeEventListener("touchstart", $);
1224
1344
  };
1225
- }, [_, t, V]), ee(() => {
1226
- const y = t.current, M = t.current?.getContext("2d");
1227
- if (!(!y || !M))
1228
- return r ? (A(y, (P) => {
1229
- if (d.type === "selection") {
1230
- if (Y(l).length !== 1) return;
1231
- const T = Y(l)[0];
1232
- if (T?.type === "text") {
1233
- const k = st(P, t.current, g);
1234
- return vt(k, g) ? void (ft(M, l, k, g) && b({ mode: "textedition", defaultValue: T.value })) : void 0;
1345
+ }, [se, t, E]), de(() => {
1346
+ const C = t.current, $ = t.current?.getContext("2d");
1347
+ if (!(!C || !$))
1348
+ return s ? (F(C, (Q) => {
1349
+ if (r.type === "selection") {
1350
+ if (_(h).length !== 1) return;
1351
+ const w = _(h)[0];
1352
+ if (w?.locked) return;
1353
+ if (w?.type === "text") {
1354
+ const y = ft(Q, t.current, g);
1355
+ return Dt(y, g) ? void (Et($, h, y, g) && M({ mode: "textedition", defaultValue: w.value })) : void 0;
1235
1356
  }
1236
- if (T?.type === "polygon") {
1237
- const k = st(P, t.current, g);
1238
- if (!vt(k, g)) return;
1239
- const O = Gi(M, T, k, g);
1240
- return void (O && p([Ka(T, O.lineIndex, k, g)]));
1357
+ if (w?.type === "polygon") {
1358
+ const y = ft(Q, t.current, g);
1359
+ if (!Dt(y, g)) return;
1360
+ const L = un($, w, y, g);
1361
+ return void (L && b([wo(w, L.lineIndex, y, g)]));
1241
1362
  }
1242
- if (T?.type === "curve") {
1243
- const k = st(P, t.current, g);
1244
- if (!vt(k, g)) return;
1245
- const O = ((R, B, I, j, de = 50) => {
1246
- if (B.locked || B.points.length < 2) return !1;
1247
- if (B.points.length < 3) return Gi(R, B, I, j, de);
1248
- const { center: se } = B.computed, K = Re(I, B.rotation ?? 0, se);
1249
- R.lineWidth = (B.style?.lineWidth ?? 0) + de / j.canvasZoom;
1250
- const N = yi(B, B.points), ge = new Path2D();
1251
- ge.moveTo(...N[0]);
1252
- for (let oe = 1; oe < N.length - 2; oe++) {
1253
- const ye = N[oe - 1], Se = N[oe], Qe = N[oe + 1], te = N[oe + 2], { cp1: ve, cp2: U } = Si(ye, Se, Qe, te);
1254
- if (ge.bezierCurveTo(ve[0], ve[1], U[0], U[1], Qe[0], Qe[1]), R.isPointInStroke(ge, K[0], K[1])) return { lineIndex: oe - 1 };
1363
+ if (w?.type === "curve") {
1364
+ const y = ft(Q, t.current, g);
1365
+ if (!Dt(y, g)) return;
1366
+ const L = ((W, V, U, R, H = 50) => {
1367
+ if (V.locked || V.points.length < 2) return !1;
1368
+ if (V.points.length < 3) return un(W, V, U, R, H);
1369
+ const { center: ae } = V.computed, me = tt(U, V.rotation ?? 0, ae);
1370
+ W.lineWidth = (V.style?.lineWidth ?? 0) + H / R.canvasZoom;
1371
+ const O = Ti(V, V.points), ge = new Path2D();
1372
+ ge.moveTo(...O[0]);
1373
+ for (let ue = 1; ue < O.length - 2; ue++) {
1374
+ const Se = O[ue - 1], Ie = O[ue], te = O[ue + 1], we = O[ue + 2], { cp1: re, cp2: ye } = Di(Se, Ie, te, we);
1375
+ if (ge.bezierCurveTo(re[0], re[1], ye[0], ye[1], te[0], te[1]), W.isPointInStroke(ge, me[0], me[1])) return { lineIndex: ue - 1 };
1255
1376
  }
1256
1377
  return !1;
1257
- })(M, T, k, g);
1258
- return void (O && p([eo(T, O.lineIndex, k, g)]));
1378
+ })($, w, y, g);
1379
+ return void (L && b([Mo(w, L.lineIndex, y, g)]));
1259
1380
  }
1260
1381
  }
1261
1382
  }), () => {
1262
- H(y);
1383
+ X(C);
1263
1384
  }) : void 0;
1264
- }, [p, A, H, r, t, d, l, b, g]), { hoverMode: x };
1265
- }, ba = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => ba(t)).join("") : e.nodeValue ?? "", Co = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: n, saveShapes: a, settings: o }) => {
1266
- const d = ne(null), r = ne(a);
1267
- ee(() => {
1268
- if (!d.current) return;
1269
- const h = d.current, c = (u) => {
1270
- u.preventDefault();
1271
- const f = u.clipboardData?.getData("text/plain");
1385
+ }, [b, F, X, s, t, r, h, M, g]), { hoverMode: T };
1386
+ }, $a = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => $a(t)).join("") : e.nodeValue ?? "", Yo = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: n, saveShapes: a, settings: o }) => {
1387
+ const r = ce(null), l = ce(a);
1388
+ de(() => {
1389
+ if (!r.current) return;
1390
+ const d = r.current, u = (p) => {
1391
+ p.preventDefault();
1392
+ const f = p.clipboardData?.getData("text/plain");
1272
1393
  document.execCommand("insertText", !1, f);
1273
1394
  };
1274
- h.addEventListener("paste", c), h.innerText = "";
1275
- for (const u of i) {
1395
+ d.addEventListener("paste", u), d.innerText = "";
1396
+ for (const p of i) {
1276
1397
  const f = document.createElement("div");
1277
- u === "" ? f.innerHTML = "<br/>" : f.innerText = u, h.appendChild(f);
1398
+ p === "" ? f.innerHTML = "<br/>" : f.innerText = p, d.appendChild(f);
1278
1399
  }
1279
- return h.focus(), () => {
1280
- h.removeEventListener("paste", c);
1400
+ return d.focus(), () => {
1401
+ d.removeEventListener("paste", u);
1281
1402
  };
1282
- }, [i]), ee(() => {
1283
- const h = r.current;
1403
+ }, [i]), de(() => {
1404
+ const d = l.current;
1284
1405
  return () => {
1285
- h();
1406
+ d();
1286
1407
  };
1287
1408
  }, []);
1288
- const s = kn(() => {
1289
- const { borders: h, center: c } = t.computed;
1290
- return le({ point: [h.x, h.y], rotation: -(t.rotation ?? 0), origin: c });
1291
- }, [t]), l = [`translate3D(${(s[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio}px, ${(s[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio}px, 0)`, `rotate(${si(t.rotation ?? 0)}deg)`, t.flipX || t.flipY ? `scale(${t.flipX ? -1 : 1}, ${t.flipY ? -1 : 1})` : void 0, t.flipX || t.flipY ? `translate3D(${t.flipX ? -100 : 0}%,${t.flipY ? -100 : 0}%,0)` : void 0].filter(Boolean).join(" ");
1292
- return m("div", { className: "react-paint-editor-toolbox-edittextbox", ref: d, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: !e, onInput: (h) => {
1293
- const c = Array.from(h.target.childNodes).map((u) => ba(u));
1294
- n(c);
1295
- }, style: { "--react-paint-editor-toolbox-edittextbox-transform": l, "--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 ?? mt } });
1296
- }, Mo = (e, t, i, n, a) => {
1297
- ta(e), ((o, d) => {
1298
- const { canvasZoom: r, size: s, canvasSize: { width: l, height: h } } = d;
1299
- if (s !== "fixed" || r >= 1) return;
1300
- o.fillStyle = "#f5f5f5", o.fillRect(0, 0, l, h);
1301
- const c = ca(d);
1302
- o.clearRect(c.x, c.y, c.width, c.height), ha(o, d);
1303
- })(e, i), ((o, d) => {
1304
- const { canvasSize: { width: r, height: s }, gridGap: l, canvasOffset: h, canvasSize: { scaleRatio: c } } = d;
1305
- if (!l) return;
1306
- o.strokeStyle = "rgb(220,220,220)", o.lineWidth = 1, o.save(), o.scale(c, c), o.beginPath();
1307
- const u = h[0] % l, f = h[1] % l, v = Math.ceil(r / c / l) + 2, p = Math.ceil(s / c / l) + 2;
1308
- for (let S = -5; S < v; S++) o.moveTo(u + (S + 1) * l, f - l), o.lineTo(u + (S + 1) * l, f + s / c + l);
1309
- for (let S = -5; S < p; S++) o.moveTo(u - l, f + (S + 1) * l), o.lineTo(u + r / c + l, f + (S + 1) * l);
1409
+ const s = Yn(() => {
1410
+ const { borders: d, center: u } = t.computed;
1411
+ return Qe({ point: [d.x, d.y], rotation: -(t.rotation ?? 0), origin: u });
1412
+ }, [t]), c = [`translate3D(${(s[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio}px, ${(s[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio}px, 0)`, `rotate(${Qi(t.rotation ?? 0)}deg)`, t.flipX || t.flipY ? `scale(${t.flipX ? -1 : 1}, ${t.flipY ? -1 : 1})` : void 0, t.flipX || t.flipY ? `translate3D(${t.flipX ? -100 : 0}%,${t.flipY ? -100 : 0}%,0)` : void 0].filter(Boolean).join(" "), h = !e;
1413
+ return v("div", { className: "react-paint-editor-toolbox-edittextbox", ref: r, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: h, role: "textbox", tabIndex: h ? 0 : void 0, onInput: (d) => {
1414
+ const u = Array.from(d.target.childNodes).map((p) => $a(p));
1415
+ n(u);
1416
+ }, style: { "--react-paint-editor-toolbox-edittextbox-transform": c, "--react-paint-editor-toolbox-edittextbox-fontsize": t.fontSize * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-padding": o.selectionPadding * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-color": t.style?.strokeColor ?? "inherit", "--react-paint-editor-toolbox-edittextbox-opacity": (t.style?.opacity ?? 100) / 100, "--react-paint-editor-toolbox-edittextbox-fontfamily": t.style?.fontFamily ?? It } });
1417
+ }, Xo = (e, t, i, n, a) => {
1418
+ ya(e), ((o, r) => {
1419
+ const { canvasZoom: l, size: s, canvasSize: { width: c, height: h } } = r;
1420
+ if (s !== "fixed" || l >= 1) return;
1421
+ o.fillStyle = "#f5f5f5", o.fillRect(0, 0, c, h);
1422
+ const d = Va(r);
1423
+ o.clearRect(d.x, d.y, d.width, d.height), Za(o, r);
1424
+ })(e, i), ((o, r) => {
1425
+ const { canvasSize: { width: l, height: s }, gridGap: c, canvasOffset: h, canvasSize: { scaleRatio: d } } = r;
1426
+ if (!c) return;
1427
+ o.strokeStyle = "rgb(220,220,220)", o.lineWidth = 1, o.save(), o.scale(d, d), o.beginPath();
1428
+ const u = h[0] % c, p = h[1] % c, f = Math.ceil(l / d / c) + 2, m = Math.ceil(s / d / c) + 2;
1429
+ for (let b = -5; b < f; b++) o.moveTo(u + (b + 1) * c, p - c), o.lineTo(u + (b + 1) * c, p + s / d + c);
1430
+ for (let b = -5; b < m; b++) o.moveTo(u - c, p + (b + 1) * c), o.lineTo(u + l / d + c, p + (b + 1) * c);
1310
1431
  o.stroke(), o.restore();
1311
1432
  })(e, i);
1312
- for (let o = n.length - 1; o >= 0; o--) t.mode === "textedition" && n[o] === a || va(e, Y(a).find((d) => d.id === n[o].id) ?? n[o], i);
1313
- }, Po = hi.forwardRef(({ canGrow: e, shapes: t, duplicateShapes: i, addShapes: n, updateSingleShape: a, selectedShape: o, setSelectedShape: d, setSelectionFrame: r, hoveredShape: s, selectionFrame: l, refreshHoveredShape: h, refreshSelectedShapes: c, saveShapes: u, activeTool: f, setActiveTool: v, canvasOffsetStartData: p, setCanvasOffsetStartData: S, setCanvasOffset: C, setCanvasMoveAcceleration: b, isInsideComponent: Q, selectionMode: g, setSelectionMode: w, selectionWidth: L, selectionColor: D, settings: V, isEditMode: x, isShiftPressed: Z, isAltPressed: A, isSpacePressed: H, withFrameSelection: F, withSkeleton: E }, W) => {
1314
- const G = ne(null), _ = ne(null), z = V.canvasSize, y = x, M = x ? 0 : -1;
1315
- Ln(W, () => G.current);
1316
- const { hoverMode: P } = xo({ addShapes: n, drawCanvasRef: G, setActiveTool: v, shapes: t, selectionMode: g, activeTool: f, isInsideComponent: Q, setCanvasOffset: C, selectedShape: o, canvasOffsetStartData: p, setCanvasOffsetStartData: S, setSelectedShape: d, setSelectionFrame: r, refreshHoveredShape: h, refreshSelectedShapes: c, updateSingleShape: a, duplicateShapes: i, saveShapes: u, setSelectionMode: w, setCanvasMoveAcceleration: b, isShiftPressed: Z, isAltPressed: A, withFrameSelection: F, settings: V, isSpacePressed: H }), T = X((O) => {
1317
- const R = Y(o)[0];
1318
- if (R?.type !== "text") return;
1319
- const B = G.current?.getContext("2d");
1320
- if (!B) return;
1321
- const I = Ne(po(B, R, O, V), V);
1322
- a([I]);
1323
- }, [a, o, V]), k = (O) => {
1324
- if (x) return O.preventDefault(), O.stopPropagation(), !1;
1433
+ for (let o = n.length - 1; o >= 0; o--) t.mode === "textedition" && n[o] === a || Ra(e, _(a).find((r) => r.id === n[o].id) ?? n[o], i);
1434
+ }, $o = Pi.forwardRef(({ canGrow: e, shapes: t, duplicateShapes: i, addShapes: n, updateSingleShape: a, selectedShape: o, setSelectedShape: r, setSelectionFrame: l, hoveredShape: s, selectionFrame: c, refreshHoveredShape: h, refreshSelectedShapes: d, saveShapes: u, activeTool: p, setActiveTool: f, canvasOffsetStartData: m, setCanvasOffsetStartData: b, setCanvasOffset: x, setCanvasMoveAcceleration: k, isInsideComponent: M, isInsideCanvas: S, selectionMode: g, setSelectionMode: P, selectionWidth: z, selectionColor: N, settings: D, isEditMode: E, isShiftPressed: A, isAltPressed: T, isSpacePressed: B, withFrameSelection: F, withSkeleton: X, withContextMenu: Z }, ne) => {
1435
+ const I = ce(null), j = ce(null), ee = D.canvasSize, se = E, he = E ? 0 : -1;
1436
+ Xn(ne, () => I.current);
1437
+ const { hoverMode: C } = Fo({ addShapes: n, drawCanvasRef: I, setActiveTool: f, shapes: t, selectionMode: g, activeTool: p, isInsideComponent: M, isInsideCanvas: S, setCanvasOffset: x, selectedShape: o, canvasOffsetStartData: m, setCanvasOffsetStartData: b, setSelectedShape: r, setSelectionFrame: l, refreshHoveredShape: h, refreshSelectedShapes: d, updateSingleShape: a, duplicateShapes: i, saveShapes: u, setSelectionMode: P, setCanvasMoveAcceleration: k, isShiftPressed: A, isAltPressed: T, withFrameSelection: F, settings: D, isSpacePressed: B, withContextMenu: Z }), $ = G((w) => {
1438
+ const y = _(o)[0];
1439
+ if (y?.type !== "text") return;
1440
+ const L = I.current?.getContext("2d");
1441
+ if (!L) return;
1442
+ const W = _e(To(L, y, w, D), D);
1443
+ a([W]);
1444
+ }, [a, o, D]), Q = (w) => {
1445
+ if (E) return w.preventDefault(), w.stopPropagation(), !1;
1325
1446
  };
1326
- return ee(() => {
1327
- const O = G.current?.getContext("2d");
1328
- O && window.requestAnimationFrame(() => Mo(O, g, V, t, o));
1329
- }, [t, g, o, V]), ee(() => {
1330
- const O = _.current?.getContext("2d");
1331
- O && window.requestAnimationFrame(() => ((R, B, I, j, de, se, K, N, ge, oe, ye) => {
1332
- R.reset(), ha(R, I), ye && N && !Y(K).find((Se) => Se.id === N.id) && j.type === "selection" && B.mode === "default" && on({ ctx: R, shape: N, settings: I, selectionWidth: de, selectionColor: se, hoverMode: ge, selectionMode: B, withAnchors: !1 }), K && j.type !== "brush" && on({ ctx: R, shape: K, settings: I, selectionWidth: de, selectionColor: se, hoverMode: ge, selectionMode: B, withAnchors: B.mode !== "textedition" }), oe && fo({ ctx: R, selectionFrame: oe, settings: I });
1333
- })(O, g, V, f, L, D, o, s, P, l, E));
1334
- }, [s, P, l, g, o, f, V, L, D, E]), m("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": p ? "grabbing" : P.outOfView ? "default" : P.mode === "resize" ? "pointer" : f.type !== "selection" && f.type !== "move" ? "crosshair" : P.mode === "translate" ? "move" : P.mode === "rotate" || f.type === "move" || H ? "grab" : "default" }, children: q("div", { className: "react-paint-canvas-container", "data-grow": e, children: [m("canvas", { className: jn, ref: G, "data-grow": e, width: z.width, height: z.height, onContextMenu: k, tabIndex: M }), y && m("canvas", { className: Kn, ref: _, width: z.width, height: z.height, "data-grow": e, onContextMenu: k }), x && g.mode === "textedition" && Y(o)[0]?.type === "text" && m(Co, { disabled: !V.features.edition, shape: Y(o)[0], defaultValue: g.defaultValue, updateValue: T, saveShapes: u, settings: V })] }) });
1335
- }), un = "ArrowUp", pn = "ArrowDown", gn = "ArrowLeft", vn = "ArrowRight", ko = "Delete", Lo = "Backspace", Vo = "Escape", fn = "Shift", mn = "Alt", yn = "Option", Ht = " ", Zo = "z", Ho = "Z", zo = "y", To = "Y", Ao = "+", Do = "-", Eo = "0", Sn = "copy", Qn = "paste", Io = ({ isInsideComponent: e, isInsideCanvas: t, selectedShape: i, isEditingText: n, settings: a, setSelectedShape: o, setActiveTool: d, setCanvasZoom: r, resetZoom: s, setSelectionMode: l, setSelectionFrame: h, removeShape: c, pasteShapes: u, updateShapes: f, backwardShape: v, forwardShape: p, setShiftPressed: S, setAltPressed: C, setIsSpacePressed: b }) => {
1336
- const [Q, g] = $(void 0);
1337
- return ee(() => {
1338
- const w = (x) => {
1339
- i && (n || (x.preventDefault(), g({ ...i })));
1340
- }, L = (x) => {
1341
- Q && (n || (x.preventDefault(), u(((Z, A) => Y(Z).map((H) => ({ ...fa(H, 20, 20, A), id: ue(`${H.type}_`) })))(Q, a))));
1342
- }, D = (x) => {
1343
- switch (x.key) {
1344
- case fn:
1345
- S(!1);
1346
- break;
1347
- case mn:
1348
- case yn:
1349
- C(!1);
1350
- break;
1351
- case Ht:
1352
- b(!1);
1353
- }
1354
- }, V = (x) => {
1355
- if (x.metaKey || x.ctrlKey) {
1356
- if (x.key === Ho || x.key === Zo) return x.preventDefault(), x.stopPropagation(), void (x.shiftKey ? p() : v());
1357
- if (!ea() && (x.key === To || x.key === zo)) return x.preventDefault(), x.stopPropagation(), void p();
1358
- if (x.key === Ao) return x.preventDefault(), x.stopPropagation(), void r("zoom");
1359
- if (x.key === Do) return x.preventDefault(), x.stopPropagation(), void r("unzoom");
1360
- if (x.key === Eo) return x.preventDefault(), x.stopPropagation(), void s();
1361
- }
1362
- if (x.key === fn) return x.preventDefault(), x.stopPropagation(), void S(!0);
1363
- if (x.key === Ht && t) return x.preventDefault(), x.stopPropagation(), void b(!0);
1364
- if (x.key === mn || x.key === yn) return x.preventDefault(), x.stopPropagation(), void C(!0);
1365
- if (!i) return;
1366
- if (x.key === Vo) return o(void 0), d(Oe), l({ mode: "default" }), void h(void 0);
1367
- if (n) return;
1368
- const Z = { [gn]: [a.gridGap ? -a.gridGap : -1, 0], [vn]: [a.gridGap ? a.gridGap : 1, 0], [pn]: [0, a.gridGap ? a.gridGap : 1], [un]: [0, a.gridGap ? -a.gridGap : -1] };
1369
- switch (x.key) {
1370
- case gn:
1371
- case vn:
1372
- case pn:
1373
- case un:
1374
- x.preventDefault(), x.stopPropagation(), f(ma(Z[x.key], i, [0, 0], a, !0));
1375
- break;
1376
- case ko:
1377
- case Lo:
1378
- x.preventDefault(), x.stopPropagation(), c(Y(i));
1379
- }
1380
- };
1381
- if (e) return document.addEventListener("keydown", V), document.addEventListener("keyup", D), document.addEventListener(Sn, w), document.addEventListener(Qn, L), () => {
1382
- document.removeEventListener("keydown", V), document.removeEventListener("keyup", D), document.removeEventListener(Sn, w), document.removeEventListener(Qn, L);
1383
- };
1384
- }, [e, t, Q, n, i, a, f, c, o, u, v, p, S, C, d, l, h, r, s, b]), {};
1385
- }, ps = ({ options: e, className: t, style: i, canvasProps: n }) => {
1386
- const { shapesRef: a, selectedShape: o, selectionFrame: d, hoveredShape: r, addShape: s, setSelectedShape: l, setSelectionFrame: h, refreshSelectedShapes: c, refreshHoveredShape: u, duplicateShapes: f, removeShape: v, updateShape: p, backwardShape: S, forwardShape: C, saveShapes: b, refs: Q, width: g, height: w, settings: L, setCanvasSize: D, setCanvasOffset: V, selectShapes: x, activeTool: Z, setActiveTool: A, isInsideComponent: H, isInsideCanvas: F, isEditMode: E, canvas: { withSkeleton: W, withFrameSelection: G, canGrow: _, canShrink: z }, canvasOffsetStartData: y, setCanvasOffsetStartData: M, selectionMode: P, setSelectionMode: T, setCanvasMoveAcceleration: k, isShiftPressed: O, isAltPressed: R, isSpacePressed: B, setShiftPressed: I, setAltPressed: j, setCanvasZoom: de, resetZoom: se, setIsSpacePressed: K } = n, { canvasBackgroundColor: N, canvasSelectionColor: ge, canvasSelectionWidth: oe } = { ...Wa, ...e }, ye = ne(null), Se = X((te) => {
1387
- s(te), x(te);
1388
- }, [s, x]), Qe = X((te) => {
1389
- D({ realWidth: g, realHeight: w, width: te, height: w * te / g, scaleRatio: te / g });
1390
- }, [g, w, D]);
1391
- return Io({ isInsideComponent: H, isInsideCanvas: F, isEditingText: P.mode === "textedition", settings: L, selectedShape: o, setSelectedShape: l, removeShape: v, pasteShapes: Se, updateShapes: p, backwardShape: S, forwardShape: C, setShiftPressed: I, setAltPressed: j, setActiveTool: A, setSelectionMode: T, setSelectionFrame: h, setCanvasZoom: de, resetZoom: se, setIsSpacePressed: K }), (({ onResized: te, element: ve }) => {
1392
- ee(() => {
1393
- const U = ve.current;
1394
- if (!U) return;
1395
- const ae = new ResizeObserver((Me) => {
1396
- const Ze = Me?.[0]?.borderBoxSize?.[0], { width: re, height: Te } = Ze ? { width: Ze.inlineSize, height: Ze.blockSize } : Me?.[0]?.contentRect ?? {};
1397
- re !== void 0 && Te !== void 0 && te(re, Te);
1447
+ return de(() => {
1448
+ const w = I.current?.getContext("2d");
1449
+ w && window.requestAnimationFrame(() => Xo(w, g, D, t, o));
1450
+ }, [t, g, o, D]), de(() => {
1451
+ const w = j.current?.getContext("2d");
1452
+ w && window.requestAnimationFrame(() => ((y, L, W, V, U, R, H, ae, me, O, ge) => {
1453
+ y.reset(), Za(y, W), ge && ae && !_(H).find((ue) => ue.id === ae.id) && V.type === "selection" && (L.mode === "default" || L.mode === "contextMenu" || L.mode === "textedition") && Qn({ ctx: y, shape: ae, settings: W, selectionWidth: U, selectionColor: R, hoverMode: me, selectionMode: L, withAnchors: !1 }), H && V.type !== "brush" && Qn({ ctx: y, shape: H, settings: W, selectionWidth: U, selectionColor: R, hoverMode: me, selectionMode: L, withAnchors: L.mode !== "textedition" }), O && Eo({ ctx: y, selectionFrame: O, settings: W });
1454
+ })(w, g, D, p, z, N, o, s, C, c, X));
1455
+ }, [s, C, c, g, o, p, D, z, N, X]), v("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": m ? "grabbing" : C.outOfView ? "default" : C.mode === "resize" ? "pointer" : p.type !== "selection" && p.type !== "move" ? "crosshair" : C.mode === "translate" ? "move" : C.mode === "rotate" || p.type === "move" || B ? "grab" : "default" }, children: K("div", { className: "react-paint-canvas-container", "data-grow": e, children: [v("canvas", { className: ga, ref: I, "data-grow": e, width: ee.width, height: ee.height, onContextMenu: Q, tabIndex: he }), se && v("canvas", { className: fa, ref: j, width: ee.width, height: ee.height, "data-grow": e, onContextMenu: Q }), E && g.mode === "textedition" && _(o)[0]?.type === "text" && v(Yo, { disabled: !D.features.edition, shape: _(o)[0], defaultValue: g.defaultValue, updateValue: $, saveShapes: u, settings: D })] }) });
1456
+ }), Ln = "ArrowUp", Vn = "ArrowDown", Zn = "ArrowLeft", Hn = "ArrowRight", Uo = "Delete", qo = "Backspace", Go = "Escape", zn = "Shift", An = "Alt", Tn = "Option", jt = " ", _o = "A", jo = "a", Ko = "z", Jo = "Z", es = "y", ts = "Y", is = "+", ns = "-", as = "0", Dn = "cut", En = "copy", In = "paste", Ds = ({ options: e, className: t, style: i, canvasProps: n }) => {
1457
+ const { shapesRef: a, selectedShape: o, selectionFrame: r, hoveredShape: l, addShape: s, setSelectedShape: c, selectAllShapes: h, setSelectionFrame: d, refreshSelectedShapes: u, refreshHoveredShape: p, duplicateShapes: f, removeShape: m, updateShape: b, backwardShape: x, forwardShape: k, saveShapes: M, refs: S, width: g, height: P, settings: z, setCanvasSize: N, setCanvasOffset: D, pasteShapes: E, activeTool: A, setActiveTool: T, isInsideComponent: B, isInsideCanvas: F, isEditMode: X, canvas: { withSkeleton: Z, withFrameSelection: ne, withContextMenu: I, canGrow: j, canShrink: ee }, canvasOffsetStartData: se, setCanvasOffsetStartData: he, selectionMode: C, setSelectionMode: $, setCanvasMoveAcceleration: Q, isShiftPressed: w, isAltPressed: y, isSpacePressed: L, copiedShape: W, setCopiedShape: V, setShiftPressed: U, setAltPressed: R, setCanvasZoom: H, resetZoom: ae, setIsSpacePressed: me } = n, { canvasBackgroundColor: O, canvasSelectionColor: ge, canvasSelectionWidth: ue } = { ...lo, ...e }, Se = ce(null), Ie = G((te) => {
1458
+ N({ realWidth: g, realHeight: P, width: te, height: P * te / g, scaleRatio: te / g });
1459
+ }, [g, P, N]);
1460
+ return (({ isInsideComponent: te, isInsideCanvas: we, selectedShape: re, isEditingText: ye, settings: ie, copiedShape: le, setCopiedShape: fe, setSelectedShape: Ve, setActiveTool: Fe, setCanvasZoom: We, resetZoom: Ce, setSelectionMode: Ye, setSelectionFrame: bt, selectAllShapes: Qt, removeShape: ct, pasteShapes: $e, updateShapes: wt, backwardShape: xt, forwardShape: Ae, setShiftPressed: ot, setAltPressed: st, setIsSpacePressed: je }) => {
1461
+ de(() => {
1462
+ const dt = (Y) => {
1463
+ re && (ye || (Y.preventDefault(), fe({ ...re })));
1464
+ }, ht = (Y) => {
1465
+ re && (ye || (Y.preventDefault(), fe({ ...re }), ct(_(re))));
1466
+ }, ut = (Y) => {
1467
+ le && (ye || (Y.preventDefault(), $e(Ri(le, ie))));
1468
+ }, be = (Y) => {
1469
+ switch (Y.key) {
1470
+ case zn:
1471
+ ot(!1);
1472
+ break;
1473
+ case An:
1474
+ case Tn:
1475
+ st(!1);
1476
+ break;
1477
+ case jt:
1478
+ je(!1);
1479
+ }
1480
+ }, xe = (Y) => {
1481
+ if (Y.metaKey || Y.ctrlKey) {
1482
+ if (Y.key === Jo || Y.key === Ko) return Y.preventDefault(), Y.stopPropagation(), void (Y.shiftKey ? Ae() : xt());
1483
+ if (!ma() && (Y.key === ts || Y.key === es)) return Y.preventDefault(), Y.stopPropagation(), void Ae();
1484
+ if (Y.key === _o || Y.key === jo) return Y.preventDefault(), Y.stopPropagation(), void Qt();
1485
+ if (Y.key === is) return Y.preventDefault(), Y.stopPropagation(), void We("zoom");
1486
+ if (Y.key === ns) return Y.preventDefault(), Y.stopPropagation(), void We("unzoom");
1487
+ if (Y.key === as) return Y.preventDefault(), Y.stopPropagation(), void Ce();
1488
+ }
1489
+ if (Y.key === zn) return Y.preventDefault(), Y.stopPropagation(), void ot(!0);
1490
+ if (Y.key === jt && we) return Y.preventDefault(), Y.stopPropagation(), void je(!0);
1491
+ if (Y.key === An || Y.key === Tn) return Y.preventDefault(), Y.stopPropagation(), void st(!0);
1492
+ if (!re) return;
1493
+ if (Y.key === Go) return Ve(void 0), Fe(Je), Ye({ mode: "default" }), void bt(void 0);
1494
+ if (ye) return;
1495
+ const nt = { [Zn]: [ie.gridGap ? -ie.gridGap : -1, 0], [Hn]: [ie.gridGap ? ie.gridGap : 1, 0], [Vn]: [0, ie.gridGap ? ie.gridGap : 1], [Ln]: [0, ie.gridGap ? -ie.gridGap : -1] };
1496
+ switch (Y.key) {
1497
+ case Zn:
1498
+ case Hn:
1499
+ case Vn:
1500
+ case Ln:
1501
+ Y.preventDefault(), Y.stopPropagation(), wt(Oa(nt[Y.key], re, [0, 0], ie, !0));
1502
+ break;
1503
+ case Uo:
1504
+ case qo:
1505
+ Y.preventDefault(), Y.stopPropagation(), ct(_(re));
1506
+ }
1507
+ };
1508
+ if (te) return document.addEventListener("keydown", xe), document.addEventListener("keyup", be), document.addEventListener(En, dt), document.addEventListener(In, ut), document.addEventListener(Dn, ht), () => {
1509
+ document.removeEventListener("keydown", xe), document.removeEventListener("keyup", be), document.removeEventListener(En, dt), document.removeEventListener(In, ut), document.removeEventListener(Dn, ht);
1510
+ };
1511
+ }, [te, we, le, ye, re, ie, wt, ct, Ve, $e, xt, Ae, ot, st, Fe, Ye, bt, fe, We, Ce, je, Qt]);
1512
+ })({ isInsideComponent: B, isInsideCanvas: F, isEditingText: C.mode === "textedition", settings: z, selectedShape: o, copiedShape: W, setCopiedShape: V, selectAllShapes: h, setSelectedShape: c, removeShape: m, pasteShapes: E, updateShapes: b, backwardShape: x, forwardShape: k, setShiftPressed: U, setAltPressed: R, setActiveTool: T, setSelectionMode: $, setSelectionFrame: d, setCanvasZoom: H, resetZoom: ae, setIsSpacePressed: me }), (({ onResized: te, element: we }) => {
1513
+ de(() => {
1514
+ const re = we.current;
1515
+ if (!re) return;
1516
+ const ye = new ResizeObserver((ie) => {
1517
+ const le = ie?.[0]?.borderBoxSize?.[0], { width: fe, height: Ve } = le ? { width: le.inlineSize, height: le.blockSize } : ie?.[0]?.contentRect ?? {};
1518
+ fe !== void 0 && Ve !== void 0 && te(fe, Ve);
1398
1519
  });
1399
- return ae.observe(U), () => {
1400
- ae.unobserve(U);
1520
+ return ye.observe(re), () => {
1521
+ ye.unobserve(re);
1401
1522
  };
1402
- }, [ve, te]);
1403
- })({ element: ye, onResized: Qe }), m("div", { ref: ye, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": _, "data-shrink": z, style: { "--react-paint-app-row-width": L.canvasSize.width, "--react-paint-app-canvaswidth": g, "--react-paint-app-canvasheight": w, "--react-paint-app-row-aspectratio": `calc(${L.canvasSize.width} / ${L.canvasSize.height})`, "--react-paint-app-canvas-bg": N, ...i }, children: m(Po, { duplicateShapes: f, isSpacePressed: B, ref: Q.canvas, canGrow: _, isInsideComponent: H, activeTool: Z, setActiveTool: A, canvasOffsetStartData: y, setCanvasOffsetStartData: M, shapes: a.current, addShapes: s, updateSingleShape: p, selectedShape: o, selectionFrame: d, setSelectedShape: l, setSelectionFrame: h, hoveredShape: r, refreshHoveredShape: u, refreshSelectedShapes: c, settings: L, setCanvasOffset: V, saveShapes: b, selectionMode: P, setSelectionMode: T, setCanvasMoveAcceleration: k, selectionColor: ge, selectionWidth: oe, isEditMode: E, isShiftPressed: O, isAltPressed: R, withFrameSelection: G, withSkeleton: W }) });
1404
- }, Wo = ({ isLoading: e = !1 }) => {
1405
- const [t, i] = $("hidden");
1406
- return ee(() => {
1523
+ }, [we, te]);
1524
+ })({ element: Se, onResized: Ie }), v("div", { ref: Se, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": j, "data-shrink": ee, style: { "--react-paint-app-row-width": z.canvasSize.width, "--react-paint-app-canvaswidth": g, "--react-paint-app-canvasheight": P, "--react-paint-app-row-aspectratio": `calc(${z.canvasSize.width} / ${z.canvasSize.height})`, "--react-paint-app-canvas-bg": O, ...i }, children: v($o, { duplicateShapes: f, isSpacePressed: L, withContextMenu: I, ref: S.canvas, canGrow: j, isInsideComponent: B, isInsideCanvas: F, activeTool: A, setActiveTool: T, canvasOffsetStartData: se, setCanvasOffsetStartData: he, shapes: a.current, addShapes: s, updateSingleShape: b, selectedShape: o, selectionFrame: r, setSelectedShape: c, setSelectionFrame: d, hoveredShape: l, refreshHoveredShape: p, refreshSelectedShapes: u, settings: z, setCanvasOffset: D, saveShapes: M, selectionMode: C, setSelectionMode: $, setCanvasMoveAcceleration: Q, selectionColor: ge, selectionWidth: ue, isEditMode: X, isShiftPressed: w, isAltPressed: y, withFrameSelection: ne, withSkeleton: Z }) });
1525
+ }, os = ({ isLoading: e = !1 }) => {
1526
+ const [t, i] = J("hidden");
1527
+ return de(() => {
1407
1528
  if (!e) {
1408
1529
  i("fadeOut");
1409
1530
  const n = setTimeout(() => i("hidden"), 300);
@@ -1412,311 +1533,382 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
1412
1533
  };
1413
1534
  }
1414
1535
  i("visible");
1415
- }, [e]), t === "hidden" ? null : m("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": Aa, "--react-paint-editor-loading-transition-duration": "300ms" }, children: q("div", { className: "react-paint-editor-loader", children: [m("div", {}), m("div", {}), m("div", {}), m("div", {})] }) });
1416
- }, Ro = "infos", No = 4e3, Bo = ({ type: e, text: t, duration: i }) => {
1417
- const [n, a] = $(!1);
1418
- return ee(() => {
1536
+ }, [e]), t === "hidden" ? null : v("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": ao, "--react-paint-editor-loading-transition-duration": "300ms" }, children: K("div", { className: "react-paint-editor-loader", children: [v("div", {}), v("div", {}), v("div", {}), v("div", {})] }) });
1537
+ }, ss = "infos", rs = 4e3, ls = ({ type: e, text: t, duration: i }) => {
1538
+ const [n, a] = J(!1);
1539
+ return de(() => {
1419
1540
  const o = setTimeout(() => {
1420
1541
  a(!0);
1421
- }, 100), d = setTimeout(() => {
1542
+ }, 100), r = setTimeout(() => {
1422
1543
  a(!1);
1423
1544
  }, i - 500 - 100);
1424
1545
  return () => {
1425
- clearTimeout(o), clearTimeout(d);
1546
+ clearTimeout(o), clearTimeout(r);
1426
1547
  };
1427
- }, [i]), m("div", { className: "react-paint-editor-snackbar", "data-is-shown": +n, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1428
- }, Oo = ({ snackbarList: e }) => m("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": Da }, children: e.map((t) => m(Bo, { ...t }, t.id)) }), Fo = hi.forwardRef((e, t) => {
1429
- const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: d, className: r = "", title: s, onClick: l, ...h } = e, c = n ? -1 : 0, u = ne(null);
1430
- return Ln(t, () => u.current), q("label", { className: `react-paint-editor-button ${r}`, title: s, onClick: l, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, tabIndex: c, onKeyDown: (f) => {
1431
- f.key === Ht && (f.preventDefault(), f.stopPropagation());
1432
- }, onKeyUp: (f) => {
1433
- f.preventDefault(), f.stopPropagation(), f.key === Ht && u.current?.click();
1434
- }, children: [m("input", { ref: u, disabled: n, ...h }), q("span", { className: "react-paint-editor-button-content", children: [d && m("span", { className: "react-paint-editor-button-children", children: d }), o && m("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] })] });
1435
- }), J = hi.forwardRef((e, t) => {
1436
- if (e.type === "file" || e.type === "color") return m(Fo, { ...e, ref: t });
1437
- const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: d, type: r = "button", className: s = "", ...l } = e;
1438
- return m("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: n, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, type: r, ...l, children: q("span", { className: "react-paint-editor-button-content", children: [d && m("span", { className: "react-paint-editor-button-children", children: d }), o && m("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] }) });
1439
- }), nt = ({ children: e, title: t = "", className: i = "", position: n = "bottom", fitContainer: a = !1, alignment: o = "center", style: d, ...r }) => q("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": a, "data-position": n, "data-alignment": o, style: { ...d, "--react-paint-editor-panel-zindex": En }, ...r, children: [t && m("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), Yo = (e) => {
1548
+ }, [i]), v("div", { className: "react-paint-editor-snackbar", "data-is-shown": +n, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1549
+ }, cs = ({ snackbarList: e }) => v("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": oo }, children: e.map((t) => v(ls, { ...t }, t.id)) }), ds = Pi.forwardRef((e, t) => {
1550
+ const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: r, className: l = "", title: s, onClick: c, ...h } = e, d = n ? -1 : 0, u = ce(null);
1551
+ return Xn(t, () => u.current), K("label", { className: `react-paint-editor-button ${l}`, title: s, onClick: c, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, tabIndex: d, onKeyDown: (p) => {
1552
+ p.key === jt && (p.preventDefault(), p.stopPropagation());
1553
+ }, onKeyUp: (p) => {
1554
+ p.preventDefault(), p.stopPropagation(), p.key === jt && u.current?.click();
1555
+ }, children: [v("input", { ref: u, disabled: n, ...h }), K("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), o && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] })] });
1556
+ }), q = Pi.forwardRef((e, t) => {
1557
+ if (e.type === "file" || e.type === "color") return v(ds, { ...e, ref: t });
1558
+ const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: r, type: l = "button", className: s = "", ...c } = e;
1559
+ return v("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: n, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, type: l, ...c, children: K("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), o && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] }) });
1560
+ }), St = ({ children: e, title: t = "", className: i = "", position: n, fitContainer: a = !1, alignment: o, style: r, ...l }) => K("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": a, "data-position": n ?? "unset", "data-alignment": o ?? "unset", style: { ...r, "--react-paint-editor-panel-zindex": Jn }, ...l, children: [t && v("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), hs = (e) => {
1440
1561
  switch (e) {
1441
1562
  case "brush":
1442
- return Zn;
1563
+ return Un;
1443
1564
  case "line":
1444
- return Tn;
1565
+ return _n;
1445
1566
  case "polygon":
1446
- return gi;
1567
+ return Zi;
1447
1568
  case "curve":
1448
- return An;
1569
+ return jn;
1449
1570
  case "rect":
1450
1571
  case "square":
1451
- return ui;
1572
+ return Li;
1452
1573
  case "circle":
1453
1574
  case "ellipse":
1454
- return pi;
1575
+ return Vi;
1455
1576
  case "text":
1456
- return zn;
1577
+ return Gn;
1457
1578
  case "picture":
1458
- return vi;
1579
+ return Hi;
1459
1580
  case "group":
1460
1581
  return '<svg><path d="M3.333 17.5V16.667H7.5V17.5ZM3.333 14.167V13.333H9.167V14.167ZM3.333 10.833V10H10.833V10.833ZM3.333 7.5V6.667H12.5V7.5ZM3.333 4.167V3.333H13.333V4.167ZM3.333 0.833V0H16.667V0.833Z"/></svg>';
1461
1582
  case "triangle":
1462
1583
  return "";
1463
1584
  }
1464
- }, Xo = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: n, toggleShapeVisibility: a, toggleShapeLock: o, setLayoutDragging: d, handleRemove: r, handleSelect: s, onMoveShapes: l }) => {
1465
- const h = ne(null), { isOver: c } = (({ disabled: u = !1, ref: f, shape: v, layoutDragging: p, setLayoutDragging: S, handleSelect: C, onMoveShapes: b }) => {
1466
- const [Q, g] = $(!1);
1467
- return ee(() => {
1468
- p || g(!1);
1469
- }, [p]), ee(() => {
1470
- const w = f.current;
1471
- if (!w) return;
1472
- const L = () => {
1473
- S(void 0);
1474
- }, D = (H) => (H.preventDefault && H.preventDefault(), !1), V = (H) => {
1475
- C([v]), H.dataTransfer && (H.dataTransfer.effectAllowed = "move", H.dataTransfer.setData("draggableShapeId", v.id), S(v.id));
1476
- }, x = () => {
1477
- p !== v.id && g(!0);
1478
- }, Z = () => {
1479
- g(!1);
1480
- }, A = (H) => (H.stopPropagation(), H.dataTransfer && b(H.dataTransfer.getData("draggableShapeId"), v.id), !1);
1481
- return u || (w.addEventListener("dragstart", V), w.addEventListener("dragend", L), w.addEventListener("dragover", D), w.addEventListener("dragenter", x), w.addEventListener("dragleave", Z), w.addEventListener("drop", A)), () => {
1482
- u || (w.removeEventListener("dragstart", V), w.removeEventListener("dragend", L), w.removeEventListener("dragover", D), w.removeEventListener("dragenter", x), w.removeEventListener("dragleave", Z), w.removeEventListener("drop", A));
1585
+ }, us = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: n, toggleShapeVisibility: a, toggleShapeLock: o, setLayoutDragging: r, handleRemove: l, handleSelect: s, onSwapShapes: c }) => {
1586
+ const h = ce(null), { isOver: d } = (({ disabled: u = !1, ref: p, shape: f, layoutDragging: m, setLayoutDragging: b, handleSelect: x, onSwapShapes: k }) => {
1587
+ const [M, S] = J(!1);
1588
+ return de(() => {
1589
+ m || S(!1);
1590
+ }, [m]), de(() => {
1591
+ const g = p.current;
1592
+ if (!g) return;
1593
+ const P = () => {
1594
+ b(void 0);
1595
+ }, z = (T) => (T.preventDefault && T.preventDefault(), !1), N = (T) => {
1596
+ x([f]), T.dataTransfer && (T.dataTransfer.effectAllowed = "move", T.dataTransfer.setData("draggableShapeId", f.id), b(f.id));
1597
+ }, D = () => {
1598
+ m !== f.id && S(!0);
1599
+ }, E = () => {
1600
+ S(!1);
1601
+ }, A = (T) => (T.stopPropagation(), T.dataTransfer && k(T.dataTransfer.getData("draggableShapeId"), f.id), !1);
1602
+ return u || (g.addEventListener("dragstart", N), g.addEventListener("dragend", P), g.addEventListener("dragover", z), g.addEventListener("dragenter", D), g.addEventListener("dragleave", E), g.addEventListener("drop", A)), () => {
1603
+ u || (g.removeEventListener("dragstart", N), g.removeEventListener("dragend", P), g.removeEventListener("dragover", z), g.removeEventListener("dragenter", D), g.removeEventListener("dragleave", E), g.removeEventListener("drop", A));
1483
1604
  };
1484
- }, [u, f, v, S, C, b, p]), { isOver: Q };
1485
- })({ disabled: e, ref: h, shape: t, layoutDragging: n, setLayoutDragging: d, handleSelect: s, onMoveShapes: l });
1486
- return q("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(n === t.id), "data-is-over": +c, onClick: (u) => {
1487
- e || (u.preventDefault(), u.stopPropagation(), s([t]));
1488
- }, "data-selected": +i, ref: h, tabIndex: -1, children: [m("span", { dangerouslySetInnerHTML: { __html: Yo(t.type) } }), m("span", { children: t.id }), m("div", { className: "react-paint-editor-layouts-separator" }), m(J, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (u) => {
1605
+ }, [u, p, f, b, x, k, m]), { isOver: M };
1606
+ })({ disabled: e, ref: h, shape: t, layoutDragging: n, setLayoutDragging: r, handleSelect: s, onSwapShapes: c });
1607
+ return K("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(n === t.id), "data-is-over": +d, onClick: (u) => {
1608
+ e || (u.preventDefault(), s([t]));
1609
+ }, "data-selected": +i, ref: h, tabIndex: -1, children: [v("span", { dangerouslySetInnerHTML: { __html: hs(t.type) } }), v("span", { children: t.id }), v("div", { className: "react-paint-editor-layouts-separator" }), v(q, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (u) => {
1489
1610
  e || (u.preventDefault(), u.stopPropagation(), a([t]));
1490
- }, 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>' }), m(J, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (u) => {
1611
+ }, icon: t.visible === !1 ? '<svg><path d="M13.521 11.021 12.25 9.75Q12.333 8.75 11.604 7.979Q10.875 7.208 9.812 7.312L8.542 6.042Q8.896 5.896 9.26 5.833Q9.625 5.771 10 5.771Q11.583 5.771 12.688 6.875Q13.792 7.979 13.792 9.562Q13.792 9.979 13.719 10.354Q13.646 10.729 13.521 11.021ZM16.167 13.646 14.917 12.417Q15.667 11.833 16.25 11.146Q16.833 10.458 17.25 9.562Q16.229 7.479 14.292 6.281Q12.354 5.083 10 5.083Q9.396 5.083 8.885 5.156Q8.375 5.229 7.875 5.375L6.5 4Q7.354 3.646 8.208 3.49Q9.062 3.333 10 3.333Q13.146 3.333 15.615 5.052Q18.083 6.771 19.167 9.562Q18.688 10.792 17.917 11.823Q17.146 12.854 16.167 13.646ZM16.396 18.854 12.938 15.396Q12.208 15.625 11.479 15.729Q10.75 15.833 10 15.833Q6.833 15.833 4.375 14.094Q1.917 12.354 0.833 9.562Q1.25 8.479 1.917 7.552Q2.583 6.625 3.417 5.875L1.125 3.562L2.375 2.354L17.625 17.625ZM4.604 7.062Q4.021 7.604 3.542 8.219Q3.062 8.833 2.729 9.562Q3.75 11.646 5.688 12.865Q7.625 14.083 10 14.083Q10.354 14.083 10.74 14.052Q11.125 14.021 11.479 13.938L10.812 13.271Q10.625 13.312 10.417 13.333Q10.208 13.354 10 13.354Q8.417 13.354 7.312 12.25Q6.208 11.146 6.208 9.562Q6.208 9.354 6.24 9.167Q6.271 8.979 6.312 8.771ZM11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875ZM8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Z"/></svg>' : '<svg><path d="M10 13.354Q11.583 13.354 12.688 12.25Q13.792 11.146 13.792 9.562Q13.792 7.979 12.688 6.875Q11.583 5.771 10 5.771Q8.417 5.771 7.312 6.875Q6.208 7.979 6.208 9.562Q6.208 11.146 7.312 12.25Q8.417 13.354 10 13.354ZM10 11.812Q9.062 11.812 8.406 11.156Q7.75 10.5 7.75 9.562Q7.75 8.625 8.406 7.969Q9.062 7.312 10 7.312Q10.938 7.312 11.594 7.969Q12.25 8.625 12.25 9.562Q12.25 10.5 11.594 11.156Q10.938 11.812 10 11.812ZM10 15.833Q6.938 15.833 4.448 14.125Q1.958 12.417 0.833 9.562Q1.958 6.708 4.458 5.021Q6.958 3.333 10 3.333Q13.042 3.333 15.542 5.021Q18.042 6.708 19.167 9.562Q18.042 12.417 15.552 14.125Q13.062 15.833 10 15.833ZM10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562ZM10 14.083Q12.333 14.083 14.281 12.865Q16.229 11.646 17.25 9.562Q16.229 7.479 14.281 6.281Q12.333 5.083 10 5.083Q7.667 5.083 5.708 6.281Q3.75 7.479 2.729 9.562Q3.75 11.646 5.708 12.865Q7.667 14.083 10 14.083Z"/></svg>' }), v(q, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (u) => {
1491
1612
  e || (u.preventDefault(), u.stopPropagation(), o([t]));
1492
- }, 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>' }), m(J, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (u) => {
1493
- e || (u.preventDefault(), u.stopPropagation(), r([t]));
1494
- }, icon: Hn })] });
1495
- }, $o = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: n, removeShape: a, toggleShapeVisibility: o, toggleShapeLock: d, selectedShapes: r, moveShapes: s, selectShapes: l, isLayoutPanelShown: h }) => {
1496
- const [c, u] = $(void 0), f = !i.features.edition;
1497
- return h ? m(nt, { alignment: "right", className: "react-paint-editor-layouts-panel", children: m("div", { className: "react-paint-editor-layouts-panel-content", children: q("div", { className: "react-paint-editor-layouts-scrolling-content", children: [q("div", { className: "react-paint-editor-layouts-row", children: [m("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), m(J, { 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((v) => m(J, { className: "react-paint-editor-layouts-grid-button", selected: e === v, disabled: f, onClick: () => t(v), children: v.charAt(0).toUpperCase() }, v))] }), m("hr", {}), m("div", { className: "react-paint-editor-layouts", children: n.length === 0 ? m("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : n.map((v) => m(Xo, { shape: v, disabled: f, layoutDragging: c, setLayoutDragging: u, selected: Y(r).some((p) => p.id === v.id) ?? !1, handleSelect: l, handleRemove: a, onMoveShapes: s, toggleShapeVisibility: o, toggleShapeLock: d }, v.id)) })] }) }) }) : null;
1498
- }, Nt = ({ children: e, onClose: t, position: i = "center", title: n, className: a = "" }) => q("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": En }, role: "dialog", "aria-modal": "true", "aria-labelledby": n, children: [m("div", { className: "react-paint-editor-modal-mask", onClick: t }), m("div", { className: `react-paint-editor-modal-panel ${a}`, children: e })] }), Mt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: n = "fill", disabled: a = !1, values: o, field: d, value: r = "", valueChanged: s }) => {
1499
- const [l] = $(ue("settings_")), h = e === l;
1500
- return o.length ? q(Ae, { children: [m(J, { selected: h, title: i, disabled: a, onClick: () => {
1501
- t((c) => c === l ? void 0 : l);
1502
- }, icon: r === "transparent" ? n === "fill" ? Ii : Ei : void 0, children: r !== "transparent" && m("div", { className: "react-paint-editor-colorfield-color", "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": r } }) }), h && m(nt, { title: i, alignment: "left", children: q("div", { className: "react-paint-editor-colorfield-wrapper", children: [o.map((c) => m(J, { title: c, selected: c === r, color: c, icon: c === "transparent" ? n === "fill" ? Ii : Ei : void 0, onClick: () => {
1503
- s(d, c);
1504
- }, children: c !== "transparent" && m("div", { className: "react-paint-editor-colorfield-color", color: c, "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": c } }) }, c)), m(J, { type: "color", title: "Custom color", selected: r !== "" && !o.includes(r), value: r, onChange: (c) => {
1505
- const u = +c.target.value;
1506
- s(d, Number.isNaN(u) ? c.target.value : u);
1507
- }, children: m("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": o.includes(r) ? "var(--react-paint-editor-app-font-color)" : r }, children: m("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;
1508
- }, Uo = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => m(J, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1509
- i(Y(t));
1510
- }, icon: Hn }), Bt = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: n = "Choisissez l'option", disabled: a = !1, field: o, icon: d, values: r, defaultValue: s, valueChanged: l }) => {
1511
- const [h] = $(ue("settings_")), c = t === h;
1512
- return r.length ? q(Ae, { children: [m(J, { selected: c, title: n, icon: d, disabled: a, onClick: () => {
1613
+ }, icon: t.locked ? '<svg><path d="M10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H5.792V5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833ZM10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042V6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' : '<svg><path d="M5.792 5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' }), v(q, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (u) => {
1614
+ e || (u.preventDefault(), u.stopPropagation(), l([t]));
1615
+ }, icon: qn })] });
1616
+ }, ps = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: n, removeShape: a, toggleShapeVisibility: o, toggleShapeLock: r, selectedShapes: l, swapShapes: s, selectShapes: c, isLayoutPanelShown: h }) => {
1617
+ const [d, u] = J(void 0), p = !i.features.edition;
1618
+ return h ? v(St, { alignment: "right", className: "react-paint-editor-layouts-panel", position: "bottom", children: v("div", { className: "react-paint-editor-layouts-panel-content", children: K("div", { className: "react-paint-editor-layouts-scrolling-content", children: [K("div", { className: "react-paint-editor-layouts-row", children: [v("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), v(q, { icon: '<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>', className: "react-paint-editor-layouts-grid-button", selected: e === "none", disabled: p, onClick: () => t("none") }), ["small", "medium", "large"].map((f) => v(q, { className: "react-paint-editor-layouts-grid-button", selected: e === f, disabled: p, onClick: () => t(f), children: f.charAt(0).toUpperCase() }, f))] }), v("hr", {}), v("div", { className: "react-paint-editor-layouts", children: n.length === 0 ? v("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : n.map((f) => v(us, { shape: f, disabled: p, layoutDragging: d, setLayoutDragging: u, selected: _(l).some((m) => m.id === f.id) ?? !1, handleSelect: c, handleRemove: a, onSwapShapes: s, toggleShapeVisibility: o, toggleShapeLock: r }, f.id)) })] }) }) }) : null;
1619
+ }, si = ({ children: e, onClose: t, position: i = "center", title: n, className: a = "" }) => K("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": Jn }, role: "dialog", "aria-modal": "true", "aria-labelledby": n, children: [v("div", { className: "react-paint-editor-modal-mask", onClick: t }), v("div", { className: `react-paint-editor-modal-panel ${a}`, children: e })] }), Yt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: n = "fill", disabled: a = !1, values: o, field: r, value: l = "", valueChanged: s }) => {
1620
+ const [c] = J(Le("settings_")), h = e === c;
1621
+ return o.length ? K(Oe, { children: [v(q, { selected: h, title: i, disabled: a, onClick: () => {
1622
+ t((d) => d === c ? void 0 : c);
1623
+ }, icon: l === "transparent" ? n === "fill" ? en : Ji : void 0, children: l !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": l } }) }), h && v(St, { title: i, alignment: "left", position: "bottom", children: K("div", { className: "react-paint-editor-colorfield-wrapper", children: [o.map((d) => v(q, { title: d, selected: d === l, color: d, icon: d === "transparent" ? n === "fill" ? en : Ji : void 0, onClick: () => {
1624
+ s(r, d);
1625
+ }, children: d !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", color: d, "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": d } }) }, d)), v(q, { type: "color", title: "Custom color", selected: l !== "" && !o.includes(l), value: l, onChange: (d) => {
1626
+ const u = +d.target.value;
1627
+ s(r, Number.isNaN(u) ? d.target.value : u);
1628
+ }, children: v("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": o.includes(l) ? "var(--react-paint-editor-app-font-color)" : l }, children: v("span", { dangerouslySetInnerHTML: { __html: '<svg><path d="M9.958 18.333Q8.25 18.333 6.74 17.677Q5.229 17.021 4.104 15.885Q2.979 14.75 2.323 13.229Q1.667 11.708 1.667 10Q1.667 8.271 2.333 6.75Q3 5.229 4.156 4.104Q5.312 2.979 6.854 2.323Q8.396 1.667 10.125 1.667Q11.771 1.667 13.26 2.25Q14.75 2.833 15.875 3.854Q17 4.875 17.667 6.26Q18.333 7.646 18.333 9.25Q18.333 11.688 16.792 12.948Q15.25 14.208 13.188 14.208H11.75Q11.625 14.208 11.562 14.281Q11.5 14.354 11.5 14.458Q11.5 14.688 11.812 15.219Q12.125 15.75 12.125 16.458Q12.125 17.458 11.51 17.896Q10.896 18.333 9.958 18.333ZM5.458 10.875Q6 10.875 6.375 10.5Q6.75 10.125 6.75 9.583Q6.75 9.042 6.375 8.667Q6 8.292 5.458 8.292Q4.917 8.292 4.542 8.667Q4.167 9.042 4.167 9.583Q4.167 10.125 4.542 10.5Q4.917 10.875 5.458 10.875ZM7.917 7.583Q8.458 7.583 8.833 7.208Q9.208 6.833 9.208 6.292Q9.208 5.75 8.833 5.375Q8.458 5 7.917 5Q7.375 5 7 5.375Q6.625 5.75 6.625 6.292Q6.625 6.833 7 7.208Q7.375 7.583 7.917 7.583ZM12.021 7.583Q12.562 7.583 12.938 7.208Q13.312 6.833 13.312 6.292Q13.312 5.75 12.938 5.375Q12.562 5 12.021 5Q11.479 5 11.104 5.375Q10.729 5.75 10.729 6.292Q10.729 6.833 11.104 7.208Q11.479 7.583 12.021 7.583ZM14.479 10.875Q15.021 10.875 15.396 10.5Q15.771 10.125 15.771 9.583Q15.771 9.042 15.396 8.667Q15.021 8.292 14.479 8.292Q13.938 8.292 13.562 8.667Q13.188 9.042 13.188 9.583Q13.188 10.125 13.562 10.5Q13.938 10.875 14.479 10.875Z"/></svg>' } }) }) })] }) })] }) : null;
1629
+ }, gs = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => v(q, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1630
+ i(_(t));
1631
+ }, icon: qn }), ri = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: n = "Choisissez l'option", disabled: a = !1, field: o, icon: r, values: l, defaultValue: s, valueChanged: c }) => {
1632
+ const [h] = J(Le("settings_")), d = t === h;
1633
+ return l.length ? K(Oe, { children: [v(q, { selected: d, title: n, icon: r, disabled: a, onClick: () => {
1513
1634
  i((u) => u === h ? void 0 : h);
1514
- } }), c && m(nt, { title: n, alignment: "left", fitContainer: !0, children: m("div", { className: "react-paint-editor-selectfield-wrapper", children: r.map((u) => m(J, { title: `${u}`, onClick: () => ((f) => {
1515
- l(o, f);
1516
- })(u), selected: s === u, style: { "--react-paint-editor-button-padding": "16px" }, children: m(e, { children: u }) }, u)) }) })] }) : null;
1517
- }, qo = ({ children: e }) => m("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), bn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? m(Bt, { 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: n, defaultValue: a, valueChanged: o }) : null, Go = ({ disabled: e, toggleLayoutPanel: t }) => m(J, { 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" }), _o = ({ children: e }) => q("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [m("span", { className: "react-paint-editor-linearrow-left" }), m("span", { className: "react-paint-editor-linearrow-right" })] }), wn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? m(Bt, { selectedSettings: e, setSelectedSettings: t, CustomOption: _o, title: "Flèches", icon: '<svg><path d="M6 17 2 13 6 9 7.062 10.062 4.875 12.25H17V13.75H4.875L7.062 15.938ZM14 11 12.938 9.938 15.125 7.75H3V6.25H15.125L12.938 4.062L14 3L18 7Z"/></svg>', disabled: i, field: "lineArrow", values: n, defaultValue: a, valueChanged: o }) : null, jo = ({ children: e }) => q("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [m("span", {}), m("span", {}), m("span", {}), m("span", {}), m("span", {}), m("span", {}), m("span", {})] }), xn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? m(Bt, { selectedSettings: e, setSelectedSettings: t, CustomOption: jo, icon: '<svg><path d="M3 16V14.5H4.5V16ZM6.125 16V14.5H7.625V16ZM9.25 16V14.5H10.75V16ZM12.375 16V14.5H13.875V16ZM15.5 16V14.5H17V16ZM3 13V11.5H6.5V13ZM8.25 13V11.5H11.75V13ZM13.5 13V11.5H17V13ZM3 10V8.5H9.25V10ZM10.75 10V8.5H17V10ZM3 7V4H17V7Z"/></svg>', title: "Type de traits", disabled: i, field: "lineDash", values: n, defaultValue: a, valueChanged: o }) : null, Pt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: n, disabled: a = !1, field: o, value: d, min: r = 1, max: s = 20, step: l = 1, unity: h = "", valueChanged: c, saveShapes: u }) => {
1518
- const f = d === void 0, v = f ? "N/A" : `${Math.round(d)}${h}`, [p] = $(ue("settings_")), S = ((b, Q = 500) => {
1519
- const g = ne(null), w = X((...L) => {
1520
- g.current && clearTimeout(g.current), g.current = setTimeout(() => b(...L), Q);
1521
- }, [b, Q]);
1522
- return ee(() => () => {
1523
- g.current && clearTimeout(g.current);
1524
- }, []), w;
1525
- })(u), C = e === p;
1526
- return r === s ? null : q(Ae, { children: [m(J, { selected: C, title: i, disabled: a, icon: n, onClick: () => {
1527
- t((b) => b === p ? void 0 : p);
1528
- } }), C && m(nt, { title: i, alignment: "left", fitContainer: !0, children: m("div", { children: q("label", { className: "react-paint-editor-rangefield", children: [m("input", { type: "range", min: r, max: s, step: l, value: d ?? (s + r) / 2, "data-indeterminate": +f, onChange: (b) => {
1529
- const Q = +b.target.value, g = Number.isNaN(Q) ? b.target.value : Q;
1530
- c(o, g, !1), S();
1531
- } }), m("span", { children: v })] }) }) })] });
1532
- }, Ko = ({ children: e }) => m("span", { children: e === 0 ? "Non" : "Oui" }), Jo = [0, 1], Cn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: n, valueChanged: a }) => m(Bt, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ko, title: "Fermer les points", icon: gi, disabled: i, field: "closedPoints", values: Jo, defaultValue: n, valueChanged: a }), es = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => m(J, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: Dn, className: t ? ` ${t}` : "" }), kt = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: n, values: a, value: o = !1, valueChanged: d }) => {
1533
- const [r] = $(ue("settings_"));
1534
- return a.length !== 2 ? null : m(J, { onClick: () => {
1535
- e((s) => s === r ? void 0 : r), d(i, !o);
1635
+ } }), d && v(St, { title: n, alignment: "left", fitContainer: !0, position: "bottom", children: v("div", { className: "react-paint-editor-selectfield-wrapper", children: l.map((u) => v(q, { title: `${u}`, onClick: () => ((p) => {
1636
+ c(o, p);
1637
+ })(u), selected: s === u, style: { "--react-paint-editor-button-padding": "16px" }, children: v(e, { children: u }) }, u)) }) })] }) : null;
1638
+ }, fs = ({ children: e }) => v("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), Wn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: fs, title: "Police", icon: '<svg><path d="M5.312 14.979H7.125L8.042 12.479H11.979L12.896 14.979H14.708L10.917 5H9.083ZM8.542 10.958 9.958 6.958H10.042L11.458 10.958ZM3.417 18.333Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V3.417Q1.667 2.688 2.177 2.177Q2.688 1.667 3.417 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417V16.583Q18.333 17.312 17.823 17.823Q17.312 18.333 16.583 18.333ZM3.417 16.583H16.583Q16.583 16.583 16.583 16.583Q16.583 16.583 16.583 16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583ZM3.417 3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583V3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417Z"/></svg>', disabled: i, field: "fontFamily", values: n, defaultValue: a, valueChanged: o }) : null, vs = ({ disabled: e, toggleLayoutPanel: t }) => v(q, { title: "Toggle layers panel", disabled: e, onClick: t, icon: '<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>', className: "react-paint-editor-layout-button" }), ms = ({ children: e }) => K("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [v("span", { className: "react-paint-editor-linearrow-left" }), v("span", { className: "react-paint-editor-linearrow-right" })] }), Rn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: ms, title: "Flèches", icon: '<svg><path d="M6 17 2 13 6 9 7.062 10.062 4.875 12.25H17V13.75H4.875L7.062 15.938ZM14 11 12.938 9.938 15.125 7.75H3V6.25H15.125L12.938 4.062L14 3L18 7Z"/></svg>', disabled: i, field: "lineArrow", values: n, defaultValue: a, valueChanged: o }) : null, ys = ({ children: e }) => K("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {})] }), Nn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: ys, icon: '<svg><path d="M3 16V14.5H4.5V16ZM6.125 16V14.5H7.625V16ZM9.25 16V14.5H10.75V16ZM12.375 16V14.5H13.875V16ZM15.5 16V14.5H17V16ZM3 13V11.5H6.5V13ZM8.25 13V11.5H11.75V13ZM13.5 13V11.5H17V13ZM3 10V8.5H9.25V10ZM10.75 10V8.5H17V10ZM3 7V4H17V7Z"/></svg>', title: "Type de traits", disabled: i, field: "lineDash", values: n, defaultValue: a, valueChanged: o }) : null, Xt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: n, disabled: a = !1, field: o, value: r, min: l = 1, max: s = 20, step: c = 1, unity: h = "", valueChanged: d, saveShapes: u }) => {
1639
+ const p = r === void 0, f = p ? "N/A" : `${Math.round(r)}${h}`, [m] = J(Le("settings_")), b = ((k, M = 500) => {
1640
+ const S = ce(null), g = G((...P) => {
1641
+ S.current && clearTimeout(S.current), S.current = setTimeout(() => k(...P), M);
1642
+ }, [k, M]);
1643
+ return de(() => () => {
1644
+ S.current && clearTimeout(S.current);
1645
+ }, []), g;
1646
+ })(u), x = e === m;
1647
+ return l === s ? null : K(Oe, { children: [v(q, { selected: x, title: i, disabled: a, icon: n, onClick: () => {
1648
+ t((k) => k === m ? void 0 : m);
1649
+ } }), x && v(St, { title: i, alignment: "left", fitContainer: !0, position: "bottom", children: v("div", { children: K("label", { className: "react-paint-editor-rangefield", children: [v("input", { type: "range", min: l, max: s, step: c, value: r ?? (s + l) / 2, "data-indeterminate": +p, onChange: (k) => {
1650
+ const M = +k.target.value, S = Number.isNaN(M) ? k.target.value : M;
1651
+ d(o, S, !1), b();
1652
+ } }), v("span", { children: f })] }) }) })] });
1653
+ }, Ss = ({ children: e }) => v("span", { children: e === 0 ? "Non" : "Oui" }), bs = [0, 1], Bn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: n, valueChanged: a }) => v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ss, title: "Fermer les points", icon: Zi, disabled: i, field: "closedPoints", values: bs, defaultValue: n, valueChanged: a }), Qs = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => v(q, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: Kn, className: t ? ` ${t}` : "" }), $t = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: n, values: a, value: o = !1, valueChanged: r }) => {
1654
+ const [l] = J(Le("settings_"));
1655
+ return a.length !== 2 ? null : v(q, { onClick: () => {
1656
+ e((s) => s === l ? void 0 : l), r(i, !o);
1536
1657
  }, selected: o, disabled: t, icon: n });
1537
- }, ni = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: n, selectedSettings: a, setSelectedSettings: o, saveShapes: d, handleShapeStyleChange: r, handleShapeFontFamilyChange: s }) => t ? i && q(Ae, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: t.style?.strokeColor, valueChanged: r, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: t.style?.fillColor, valueChanged: r, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", icon: Di, disabled: n, 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 && m(xn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineDash, valueChanged: r, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && m(wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineArrow, valueChanged: r, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && m(Cn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: r, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && m(bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: Ti, valueChanged: s, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: Ai, valueChanged: s, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: zi, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: t.style?.opacity, valueChanged: r })] }) : "settings" in e ? q(Ae, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: r, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: e.settings.fillColor.default, valueChanged: r, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", disabled: n, field: "lineWidth", icon: Di, 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 && m(xn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineDash.default, valueChanged: r, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && m(wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineArrow.default, valueChanged: r, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && m(Cn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: r, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && m(bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: Ti, valueChanged: s, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: Ai, valueChanged: s, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: zi, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: e.settings.opacity.default, valueChanged: r })] }) : null, ts = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: n = !1, toggleLayoutPanel: a, activeTool: o, saveShapes: d, selectedShape: r, canvas: s, settings: l, updateShape: h, removeShape: c, isZoomPanelShown: u, setIsZoomPanelShown: f }) => {
1538
- const [v, p] = $(void 0), [S, C] = $(!1), b = l.size === "infinite" || l.features.zoom, Q = !l.features.edition, g = () => {
1539
- C((Z) => !Z);
1540
- }, w = ((Z, A) => {
1541
- const H = Y(Z).map((E) => A.find((W) => W.id === E?.toolId) || A.find((W) => W.type === E?.type)).filter((E) => E !== void 0);
1542
- if (!H.length) return;
1543
- if (H.length === 1) return H[0];
1544
- const F = H.slice(1).reduce((E, W) => {
1545
- const G = {};
1546
- for (const _ in W.settings) {
1547
- if (E[_] === void 0 || W.settings[_]?.hidden || E[_]?.hidden) continue;
1548
- const z = E[_], y = W.settings[_], M = {};
1549
- "min" in y && "min" in z && y.min === z.min && "max" in y && "max" in z && y.max === z.max && "step" in y && "step" in z && y.step === z.step && (M.min = y.min, M.max = y.max, M.step = y.step), "values" in y && "values" in z && y.values?.join(",") === z.values?.join(",") && (M.values = y.values), (Object.keys(M).length > 0 || _ === "closedPoints") && (G[_] = M);
1658
+ }, yi = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: n, selectedSettings: a, setSelectedSettings: o, saveShapes: r, handleShapeStyleChange: l, handleShapeFontFamilyChange: s }) => t ? i && K(Oe, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: t.style?.strokeColor, valueChanged: l, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: t.style?.fillColor, valueChanged: l, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", icon: Ki, disabled: n, field: "lineWidth", value: t.style?.lineWidth, valueChanged: l, unity: "px", min: i.settings.lineWidth.min, max: i.settings.lineWidth.max, step: i.settings.lineWidth.step }), "lineDash" in i.settings && !i.settings.lineDash.hidden && v(Nn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineDash, valueChanged: l, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && v(Rn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineArrow, valueChanged: l, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && v(Bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: l, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && v(Wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: _i, valueChanged: s, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: ji, valueChanged: s, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: qi, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: t.style?.opacity, valueChanged: l })] }) : "settings" in e ? K(Oe, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: l, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && v(Yt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: e.settings.fillColor.default, valueChanged: l, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", disabled: n, field: "lineWidth", icon: Ki, value: e.settings.lineWidth.default, valueChanged: l, unity: "px", min: e.settings.lineWidth.min, max: e.settings.lineWidth.max, step: e.settings.lineWidth.step }), "lineDash" in e.settings && !e.settings.lineDash.hidden && v(Nn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineDash.default, valueChanged: l, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && v(Rn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineArrow.default, valueChanged: l, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && v(Bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: l, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && v(Wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: _i, valueChanged: s, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && v($t, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: ji, valueChanged: s, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && v(Xt, { saveShapes: r, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: qi, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: e.settings.opacity.default, valueChanged: l })] }) : null, ws = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: n = !1, toggleLayoutPanel: a, activeTool: o, saveShapes: r, selectedShape: l, canvas: s, settings: c, updateShape: h, removeShape: d, isZoomPanelShown: u, setIsZoomPanelShown: p }) => {
1659
+ const [f, m] = J(void 0), [b, x] = J(!1), k = c.size === "infinite" || c.features.zoom, M = !c.features.edition, S = () => {
1660
+ x((E) => !E);
1661
+ }, g = ((E, A) => {
1662
+ const T = _(E).map((F) => A.find((X) => X.id === F?.toolId) || A.find((X) => X.type === F?.type)).filter((F) => F !== void 0);
1663
+ if (!T.length) return;
1664
+ if (T.length === 1) return T[0];
1665
+ const B = T.slice(1).reduce((F, X) => {
1666
+ const Z = {};
1667
+ for (const ne in X.settings) {
1668
+ if (F[ne] === void 0 || X.settings[ne]?.hidden || F[ne]?.hidden) continue;
1669
+ const I = F[ne], j = X.settings[ne], ee = {};
1670
+ "min" in j && "min" in I && j.min === I.min && "max" in j && "max" in I && j.max === I.max && "step" in j && "step" in I && j.step === I.step && (ee.min = j.min, ee.max = j.max, ee.step = j.step), "values" in j && "values" in I && j.values?.join(",") === I.values?.join(",") && (ee.values = j.values), (Object.keys(ee).length > 0 || ne === "closedPoints") && (Z[ne] = ee);
1550
1671
  }
1551
- return G;
1552
- }, H[0].settings);
1553
- return { id: H.map((E) => E.id).join("-"), icon: "", label: "group", type: "group", settings: F };
1554
- })(r, t), L = (w ? Object.keys(w.settings).length + 1 : "settings" in o ? Object.keys(o.settings).length : 0) + +n + +b, D = e < 40 * L, V = (Z, A, H = !0) => {
1555
- if (Y(r).length) {
1556
- const F = Y(r).map((E) => Ne(Le(["style", Z], A, E), l));
1557
- h(F, H), w && i(w.id, Z, A);
1558
- } else i(o.id, Z, A);
1559
- }, x = (Z, A) => {
1560
- if (Y(r).length) {
1561
- const H = Y(r).map((F) => {
1562
- if (F.type !== "text") return F;
1563
- const E = s?.getContext("2d");
1564
- if (!E) return F;
1565
- const W = Le(["style", Z], A, F), G = Rt(E, W.value, W.width, W.style?.fontBold ?? !1, W.style?.fontItalic ?? !1, W.style?.fontFamily);
1566
- return Ne({ ...W, fontSize: G, height: G * W.value.length }, l);
1672
+ return Z;
1673
+ }, T[0].settings);
1674
+ return { id: T.map((F) => F.id).join("-"), icon: "", label: "group", type: "group", settings: B };
1675
+ })(l, t), P = (g ? Object.keys(g.settings).length + 1 : "settings" in o ? Object.keys(o.settings).length : 0) + +n + +k, z = e < 40 * P, N = (E, A, T = !0) => {
1676
+ if (_(l).length) {
1677
+ const B = _(l).map((F) => _e(Xe(["style", E], A, F), c));
1678
+ h(B, T), g && i(g.id, E, A);
1679
+ } else i(o.id, E, A);
1680
+ }, D = (E, A) => {
1681
+ if (_(l).length) {
1682
+ const T = _(l).map((B) => {
1683
+ if (B.type !== "text") return B;
1684
+ const F = s?.getContext("2d");
1685
+ if (!F) return B;
1686
+ const X = Xe(["style", E], A, B), Z = oi(F, X.value, X.width, X.style?.fontBold ?? !1, X.style?.fontItalic ?? !1, X.style?.fontFamily);
1687
+ return _e({ ...X, fontSize: Z, height: Z * X.value.length }, c);
1567
1688
  });
1568
- h(H, !0), w && i(w.id, Z, A);
1569
- } else i(o.id, Z, A);
1689
+ h(T, !0), g && i(g.id, E, A);
1690
+ } else i(o.id, E, A);
1570
1691
  };
1571
- return q(Ae, { children: [q("div", { className: "react-paint-editor-settings-bar", children: [q("div", { className: "react-paint-editor-settings-shrinkable", children: [b && m(es, { className: u ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1572
- f((Z) => !Z);
1573
- } }), D && L > 2 && m(J, { disabled: Q, onClick: g, 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 ? w && q(Ae, { children: [!D && m(ni, { saveShapes: d, activeTool: o, selectedShape: r, selectedShapeTool: w, disabled: Q, selectedSettings: v, setSelectedSettings: p, handleShapeStyleChange: V, handleShapeFontFamilyChange: x }), o.type === "selection" && m(Uo, { disabled: Q, selectedShape: r, removeShape: c })] }) : !D && m(ni, { saveShapes: d, activeTool: o, selectedShape: r, selectedShapeTool: w, disabled: Q, selectedSettings: v, setSelectedSettings: p, handleShapeStyleChange: V, handleShapeFontFamilyChange: x })] }), m("div", { className: "react-paint-editor-settings-separator" }), n && m(Go, { disabled: Q, toggleLayoutPanel: a })] }), S && m(Nt, { className: "react-paint-editor-settings-modal", onClose: g, position: "bottom", title: "Settings", children: m(ni, { saveShapes: d, activeTool: o, selectedShape: r, selectedShapeTool: w, disabled: Q, selectedSettings: v, setSelectedSettings: p, handleShapeStyleChange: V, handleShapeFontFamilyChange: x }) })] });
1574
- }, Mn = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: n, img: a, accept: o }) => {
1575
- const d = ne(null);
1576
- return m(J, { ref: d, type: "file", onClick: (r) => {
1577
- r.stopPropagation(), d.current && (d.current.value = "");
1578
- }, onChange: (r) => {
1579
- const s = r.target.files?.item(0);
1692
+ return K(Oe, { children: [K("div", { className: "react-paint-editor-settings-bar", children: [K("div", { className: "react-paint-editor-settings-shrinkable", children: [k && v(Qs, { className: u ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1693
+ p((E) => !E);
1694
+ } }), z && P > 2 && v(q, { disabled: M, onClick: S, title: "Toggle settings", icon: '<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>' }), l ? g && K(Oe, { children: [!z && v(yi, { saveShapes: r, activeTool: o, selectedShape: l, selectedShapeTool: g, disabled: M, selectedSettings: f, setSelectedSettings: m, handleShapeStyleChange: N, handleShapeFontFamilyChange: D }), o.type === "selection" && v(gs, { disabled: M, selectedShape: l, removeShape: d })] }) : !z && v(yi, { saveShapes: r, activeTool: o, selectedShape: l, selectedShapeTool: g, disabled: M, selectedSettings: f, setSelectedSettings: m, handleShapeStyleChange: N, handleShapeFontFamilyChange: D })] }), v("div", { className: "react-paint-editor-settings-separator" }), n && v(vs, { disabled: M, toggleLayoutPanel: a })] }), b && v(si, { className: "react-paint-editor-settings-modal", onClose: S, position: "bottom", title: "Settings", children: v(yi, { saveShapes: r, activeTool: o, selectedShape: l, selectedShapeTool: g, disabled: M, selectedSettings: f, setSelectedSettings: m, handleShapeStyleChange: N, handleShapeFontFamilyChange: D }) })] });
1695
+ }, qt = ({ alignment: e, children: t, className: i, style: n, position: a }) => v(St, { alignment: e, position: a, className: i, style: n, children: v("div", { className: "react-paint-editor-menu", role: "menu", children: t }) }), On = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: n, img: a, accept: o }) => {
1696
+ const r = ce(null);
1697
+ return v(q, { ref: r, type: "file", onClick: () => {
1698
+ r.current && (r.current.value = "");
1699
+ }, onChange: (l) => {
1700
+ const s = l.target.files?.item(0);
1580
1701
  s && i(s);
1581
1702
  }, accept: o, title: n.label ?? n.type, icon: a, disabled: e, children: t ? n.label : void 0 });
1582
- }, ke = ({ type: e, img: t, isActive: i, withText: n = !1, disabled: a = !1, setActive: o }) => m(J, { disabled: a, selected: i, onClick: () => {
1703
+ }, Ne = ({ type: e, img: t, isActive: i, withText: n = !1, disabled: a = !1, setActive: o }) => v(q, { disabled: a, selected: i, onClick: () => {
1583
1704
  o(e);
1584
- }, title: e.label ?? e.type, icon: t, children: n ? e.label : void 0 }), is = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: n = !1, hasActionToClear: a = !1, undoAction: o, redoAction: d, clearCanvas: r, alignment: s, group: l, vertical: h = !1, disabled: c = !1, withLoadAndSave: u, withExport: f, addPicture: v, loadFile: p, togglePictureUrlModal: S, saveFile: C, toggleExportModal: b, withUploadPicture: Q, withUrlPicture: g }) => {
1585
- const [w, L] = $(!1), [, D] = Vn(), V = l?.tools?.some((Z) => Z === e.type), x = (V ? e.icon : l.img) ?? l.title;
1586
- return ee(() => {
1587
- if (!w) return;
1588
- const Z = () => {
1589
- L(!1);
1590
- };
1591
- return document.addEventListener("click", Z), () => {
1592
- document.removeEventListener("click", Z);
1705
+ }, title: e.label ?? e.type, icon: t, children: n ? e.label : void 0 }), Ua = (e, t) => !!(e.target instanceof Node && t) && t.contains(e.target), ki = ({ trigger: e = "click", buttonElt: t }) => {
1706
+ const [i, n] = J(!1), [, a] = $n(), o = G(() => {
1707
+ a(() => {
1708
+ n(!1);
1709
+ });
1710
+ }, []);
1711
+ return de(() => {
1712
+ if (!t) return;
1713
+ if (i) {
1714
+ const l = (c) => {
1715
+ Ua(c, t) || a(() => {
1716
+ n(!1);
1717
+ });
1718
+ }, s = () => {
1719
+ a(() => {
1720
+ n(!1);
1721
+ });
1722
+ };
1723
+ return e === "hover" ? (t.addEventListener("mouseleave", s), () => {
1724
+ t.removeEventListener("mouseleave", s);
1725
+ }) : (document.addEventListener("click", l), () => {
1726
+ document.removeEventListener("click", l);
1727
+ });
1728
+ }
1729
+ const r = () => {
1730
+ a(() => {
1731
+ n(!0);
1732
+ });
1593
1733
  };
1594
- }, [w]), t || Q || g || u || f ? q("div", { className: "react-paint-editor-toolbox-relative", children: [m(J, { selected: V, title: l.title, disabled: c, onClick: () => {
1595
- D(() => {
1596
- L(!0);
1734
+ return e === "hover" ? (t.addEventListener("mouseenter", r), () => {
1735
+ t.removeEventListener("mouseenter", r);
1736
+ }) : (t.addEventListener("click", r), () => {
1737
+ t.removeEventListener("click", r);
1597
1738
  });
1598
- }, icon: x }), w && m(nt, { alignment: s, position: "top", children: q("div", { className: "react-paint-editor-toolbox-panel-content", "data-vertical": +h, children: [t && q(Ae, { children: [m(ke, { withText: !0, type: dt, disabled: c || !i, img: dt.icon, isActive: e.id === dt.id, setActive: o }), m(ke, { withText: !0, type: ct, disabled: c || !n, img: ct.icon, isActive: e.id === ct.id, setActive: d }), m(ke, { withText: !0, type: ht, disabled: c || !a, img: ht.icon, isActive: e.id === ht.id, setActive: r }), (Q || g || u) && m("hr", {})] }), Q && m(Mn, { withText: !0, type: Ni, disabled: c, loadFile: async (Z) => {
1599
- L(!1), await v(Z);
1600
- }, img: Ni.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), g && m(J, { disabled: c, selected: !1, onClick: S, 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" }), (Q || g) && u && m("hr", {}), u && q(Ae, { children: [m(Mn, { withText: !0, type: Ri, disabled: c, loadFile: (Z) => {
1601
- L(!1), p(Z);
1602
- }, img: Ri.icon, accept: "application/JSON" }), m(ke, { withText: !0, disabled: c, type: jt, img: jt.icon, isActive: e.id === jt.id, setActive: C })] }), f && m(ke, { withText: !0, disabled: c, type: _t, img: _t.icon, isActive: e.id === _t.id, setActive: b })] }) })] }) : null;
1603
- }, ns = ({ togglePictureUrlModal: e, addPicture: t }) => {
1604
- const i = ne(null);
1605
- return ee(() => {
1739
+ }, [t, i, e]), { isOpen: i, trigger: e, closeMenu: o };
1740
+ }, xs = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: n = !1, hasActionToClear: a = !1, undoAction: o, redoAction: r, clearCanvas: l, disabled: s = !1, withLoadAndSave: c, withExport: h, addPicture: d, loadFile: u, togglePictureUrlModal: p, saveFile: f, toggleExportModal: m, withUploadPicture: b, withUrlPicture: x }) => {
1741
+ const k = ce(null), { isOpen: M, closeMenu: S } = ki({ buttonElt: k.current }), g = (P) => async (...z) => {
1742
+ await P(...z), S();
1743
+ };
1744
+ return t || b || x || c || h ? v("div", { className: "react-paint-editor-toolbox-relative", children: K("div", { ref: k, children: [v(q, { title: "Menu", disabled: s, icon: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }), M && K(qt, { alignment: "right", position: "top", children: [t && K(Oe, { children: [v(Ne, { withText: !0, type: Pt, disabled: s || !i, img: Pt.icon, isActive: e.id === Pt.id, setActive: g(o) }), v(Ne, { withText: !0, type: Lt, disabled: s || !n, img: Lt.icon, isActive: e.id === Lt.id, setActive: g(r) }), v(Ne, { withText: !0, type: Vt, disabled: s || !a, img: Vt.icon, isActive: e.id === Vt.id, setActive: g(l) }), (b || x || c) && v("hr", {})] }), b && v(On, { withText: !0, type: an, disabled: s, loadFile: g(d), img: an.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), x && v(q, { disabled: s, selected: !1, onClick: g(p), title: "Add picture from URL", icon: '<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>', children: "Add picture from URL" }), (b || x) && c && v("hr", {}), c && K(Oe, { children: [v(On, { withText: !0, type: nn, disabled: s, loadFile: g(u), img: nn.icon, accept: "application/JSON" }), v(Ne, { withText: !0, disabled: s, type: hi, img: hi.icon, isActive: e.id === hi.id, setActive: g(f) })] }), h && v(Ne, { withText: !0, disabled: s, type: di, img: di.icon, isActive: e.id === di.id, setActive: g(m) })] })] }) }) : null;
1745
+ }, Ms = ({ togglePictureUrlModal: e, addPicture: t }) => {
1746
+ const i = ce(null);
1747
+ return de(() => {
1606
1748
  i.current && i.current.focus();
1607
- }, []), m(Nt, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: q("form", { onSubmit: async (n) => {
1749
+ }, []), v(si, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: K("form", { onSubmit: async (n) => {
1608
1750
  n.preventDefault();
1609
1751
  const a = i.current?.value;
1610
1752
  a && (await t(a), e());
1611
- }, children: [q("label", { children: ["URL ", m("input", { type: "text", ref: i })] }), m(J, { onClick: e, children: "Annuler" }), m(J, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1612
- }, Pn = "Choose export settings", as = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1753
+ }, children: [K("label", { children: ["URL ", v("input", { type: "text", ref: i })] }), v(q, { onClick: e, children: "Annuler" }), v(q, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1754
+ }, Fn = "Choose export settings", Cs = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1613
1755
  const i = async (n) => {
1614
1756
  t(n), e();
1615
1757
  };
1616
- return q(Nt, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Pn, children: [m("h3", { children: Pn }), m("hr", {}), m(J, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), m(J, { onClick: () => i("defaultView"), children: "Exporter le canevas par défaut" }), m(J, { onClick: () => i("fitToShapes"), children: "Exporter le dessin entier" }), m(J, { selected: !0, onClick: e, children: "Annuler" })] });
1617
- }, os = ({ activeTool: e, alignment: t, group: i, disabled: n = !1, setActiveToolFromId: a }) => {
1618
- const o = ne(null), [d, r] = $(!1), [, s] = Vn(), [l, h] = $(void 0), c = (v) => {
1619
- h(v), a(v.id);
1758
+ return K(si, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Fn, children: [v("h3", { children: Fn }), v("hr", {}), v(q, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), v(q, { onClick: () => i("defaultView"), children: "Exporter le canevas par défaut" }), v(q, { onClick: () => i("fitToShapes"), children: "Exporter le dessin entier" }), v(q, { selected: !0, onClick: e, children: "Annuler" })] });
1759
+ }, ks = ({ activeTool: e, group: t, disabled: i = !1, setActiveToolFromId: n }) => {
1760
+ const a = ce(null), [o, r] = J(!1), [, l] = $n(), [s, c] = J(void 0), h = (p) => {
1761
+ c(p), n(p.id);
1620
1762
  };
1621
- if (ee(() => {
1622
- if (!d) return;
1623
- const v = (p) => {
1624
- !((C, b) => !!(C.target instanceof Node && b) && b.contains(C.target))(p, o.current) && r(!1);
1763
+ if (de(() => {
1764
+ if (!o) return;
1765
+ const p = (f) => {
1766
+ !Ua(f, a.current) && r(!1);
1625
1767
  };
1626
- return document.addEventListener("mousedown", v, { passive: !1 }), document.addEventListener("touchstart", v, { passive: !1 }), () => {
1627
- document.removeEventListener("mousedown", v), document.removeEventListener("touchstart", v);
1768
+ return document.addEventListener("mousedown", p, { passive: !1 }), document.addEventListener("touchstart", p, { passive: !1 }), () => {
1769
+ document.removeEventListener("mousedown", p), document.removeEventListener("touchstart", p);
1628
1770
  };
1629
- }, [d]), "type" in i) return m(ke, { disabled: n, type: i, img: i.icon, isActive: e.id === i.id, setActive: c });
1630
- if (!i.toolsType.length) return null;
1631
- if (i.toolsType?.length === 1) return m(ke, { disabled: n, type: i.toolsType[0], img: i.toolsType[0].icon, isActive: e.id === i.toolsType[0].id, setActive: c });
1632
- const u = i?.toolsType.find((v) => v.type === e.type) !== void 0, f = (l ? l.icon : i.toolsType?.[0]?.icon) ?? i.title;
1633
- return q("div", { className: "react-paint-editor-toolbargroup-relative", children: [m(J, { selected: u, title: i.title, disabled: n, onClick: () => {
1634
- l ? a(l.id) : i.toolsType?.[0] && c(i.toolsType[0]), s(() => {
1771
+ }, [o]), "type" in t) return v(Ne, { disabled: i, type: t, img: t.icon, isActive: e.id === t.id, setActive: h });
1772
+ if (!t.toolsType.length) return null;
1773
+ if (t.toolsType?.length === 1) return v(Ne, { disabled: i, type: t.toolsType[0], img: t.toolsType[0].icon, isActive: e.id === t.toolsType[0].id, setActive: h });
1774
+ const d = t?.toolsType.find((p) => p.type === e.type) !== void 0, u = (s ? s.icon : t.toolsType?.[0]?.icon) ?? t.title;
1775
+ return K("div", { className: "react-paint-editor-toolbargroup-relative", children: [v(q, { selected: d, title: t.title, disabled: i, onClick: () => {
1776
+ s ? n(s.id) : t.toolsType?.[0] && h(t.toolsType[0]), l(() => {
1635
1777
  r(!0);
1636
1778
  });
1637
- }, icon: f }), d && m(nt, { alignment: t, position: "top", children: m("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +i.vertical, ref: o, children: i.toolsType.map((v) => m(ke, { disabled: n, type: v, img: v.icon, isActive: e.id === v.id, setActive: c }, v.id)) }) })] });
1638
- }, ss = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], rs = ({ settings: e, width: t, activeTool: i, hasActionToUndo: n = !1, hasActionToRedo: a = !1, hasActionToClear: o = !1, withLoadAndSave: d, withExport: r, clearCanvas: s, setActiveTool: l, undoAction: h, redoAction: c, addPicture: u, loadFile: f, saveFile: v, exportCanvasInFile: p, availableTools: S, withUrlPicture: C, withUploadPicture: b }) => {
1639
- const Q = ((z, y) => {
1640
- const M = y.flatMap((P) => {
1641
- if (typeof P != "object") return z.filter((k) => k.type === P);
1642
- const T = z.filter((k) => P.toolsType.includes(k.type));
1643
- return T ? { ...P, toolsType: T } : null;
1779
+ }, icon: u }), o && v(St, { alignment: "center", position: "top", children: v("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +t.vertical, ref: a, children: t.toolsType.map((p) => v(Ne, { disabled: i, type: p, img: p.icon, isActive: e.id === p.id, setActive: h }, p.id)) }) })] });
1780
+ }, Ps = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], Ls = ({ settings: e, width: t, activeTool: i, hasActionToUndo: n = !1, hasActionToRedo: a = !1, hasActionToClear: o = !1, withLoadAndSave: r, withExport: l, clearCanvas: s, setActiveTool: c, undoAction: h, redoAction: d, addPicture: u, loadFile: p, saveFile: f, exportCanvasInFile: m, availableTools: b, withUrlPicture: x, withUploadPicture: k }) => {
1781
+ const M = ((I, j) => {
1782
+ const ee = j.flatMap((se) => {
1783
+ if (typeof se != "object") return I.filter((C) => C.type === se);
1784
+ const he = I.filter((C) => se.toolsType.includes(C.type));
1785
+ return he ? { ...se, toolsType: he } : null;
1644
1786
  });
1645
- return xi(M);
1646
- })(S, ss), g = !e.features.edition, w = t < 40 * (6 + Q.length), L = t < 40 * (3 + Q.length), [D, V] = $(!1), [x, Z] = $(!1), [A, H] = $(!1), F = () => {
1647
- V((z) => !z);
1648
- }, E = () => {
1649
- H((z) => !z);
1650
- }, W = (z) => {
1651
- l(z), V(!1);
1652
- }, G = (z) => {
1653
- W(S.find((y) => y.id === z) ?? i);
1654
- }, _ = S.find((z) => z.type === i.type) !== void 0;
1655
- return q(Ae, { children: [q("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [q("div", { className: "react-paint-editor-toolbar-shrinkable", children: [m(ke, { type: Oe, disabled: g, img: Oe.icon, isActive: i.id === Oe.id, setActive: W }), (e.size === "infinite" || e.features.zoom) && m(ke, { type: Kt, disabled: g, img: Kt.icon, isActive: i.id === Kt.id, setActive: W }), L ? m(J, { disabled: g, onClick: F, 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: _ }) : Q.map((z) => m(os, { disabled: g, activeTool: i, group: z, setActiveToolFromId: G }, "id" in z ? z.id : z.title))] }), !w && q(Ae, { children: [m(ke, { type: dt, disabled: g || !n, img: dt.icon, isActive: i.id === dt.id, setActive: h }), m(ke, { type: ct, disabled: g || !a, img: ct.icon, isActive: i.id === ct.id, setActive: c }), m(ke, { type: ht, disabled: g || !o, img: ht.icon, isActive: i.id === ht.id, setActive: s })] }), m(is, { withActionsInMenu: w, disabled: g, 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: f, saveFile: v, togglePictureUrlModal: () => {
1656
- Z(!0);
1657
- }, toggleExportModal: E, withUploadPicture: b, withUrlPicture: C, withLoadAndSave: d, withExport: r, hasActionToUndo: n, hasActionToRedo: a, hasActionToClear: o, undoAction: h, redoAction: c, clearCanvas: s })] }), D && m(Nt, { className: "react-paint-editor-toolbar-modal", onClose: F, title: "Outils", children: S.map((z) => z.type === "picture" ? null : m(ke, { disabled: g, type: z, img: z.icon, withText: !1, isActive: i.id === z.id, setActive: W }, z.id)) }), x && m(ns, { togglePictureUrlModal: () => {
1658
- Z((z) => !z);
1659
- }, addPicture: u }), A && m(as, { toggleExportModal: E, exportCanvasInFile: p })] });
1660
- }, Lt = { none: 0, small: 10, medium: 20, large: 40 }, ls = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, ds = () => {
1661
- const e = ne([]), [t, i] = $([]);
1662
- return ee(() => () => {
1787
+ return Ni(ee);
1788
+ })(b, Ps), S = !e.features.edition, g = t < 40 * (6 + M.length), P = t < 40 * (3 + M.length), [z, N] = J(!1), [D, E] = J(!1), [A, T] = J(!1), B = () => {
1789
+ N((I) => !I);
1790
+ }, F = () => {
1791
+ T((I) => !I);
1792
+ }, X = (I) => {
1793
+ c(I), N(!1);
1794
+ }, Z = (I) => {
1795
+ X(b.find((j) => j.id === I) ?? i);
1796
+ }, ne = b.find((I) => I.type === i.type) !== void 0;
1797
+ return K(Oe, { children: [K("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [K("div", { className: "react-paint-editor-toolbar-shrinkable", children: [v(Ne, { type: Je, disabled: S, img: Je.icon, isActive: i.id === Je.id, setActive: X }), (e.size === "infinite" || e.features.zoom) && v(Ne, { type: ui, disabled: S, img: ui.icon, isActive: i.id === ui.id, setActive: X }), P ? v(q, { disabled: S, onClick: B, title: "Toggle tools", icon: '<svg><path d="M5.333 9.292 10.021 1.646 14.708 9.292ZM14.562 18.333Q13 18.333 11.896 17.229Q10.792 16.125 10.792 14.562Q10.792 13 11.896 11.896Q13 10.792 14.562 10.792Q16.125 10.792 17.229 11.896Q18.333 13 18.333 14.562Q18.333 16.125 17.229 17.229Q16.125 18.333 14.562 18.333ZM2.5 17.917V11.188H9.229V17.917ZM14.562 16.583Q15.438 16.583 16.01 16.01Q16.583 15.438 16.583 14.562Q16.583 13.688 16.01 13.115Q15.438 12.542 14.562 12.542Q13.688 12.542 13.115 13.115Q12.542 13.688 12.542 14.562Q12.542 15.438 13.115 16.01Q13.688 16.583 14.562 16.583ZM4.25 16.167H7.479V12.938H4.25ZM8.458 7.542H11.583L10.021 5ZM10.021 7.542ZM7.479 12.938ZM14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Z"/></svg>', selected: ne }) : M.map((I) => v(ks, { disabled: S, activeTool: i, group: I, setActiveToolFromId: Z }, "id" in I ? I.id : I.title))] }), !g && K(Oe, { children: [v(Ne, { type: Pt, disabled: S || !n, img: Pt.icon, isActive: i.id === Pt.id, setActive: h }), v(Ne, { type: Lt, disabled: S || !a, img: Lt.icon, isActive: i.id === Lt.id, setActive: d }), v(Ne, { type: Vt, disabled: S || !o, img: Vt.icon, isActive: i.id === Vt.id, setActive: s })] }), v(xs, { withActionsInMenu: g, disabled: S, activeTool: i, addPicture: u, loadFile: p, saveFile: f, togglePictureUrlModal: () => {
1798
+ E(!0);
1799
+ }, toggleExportModal: F, withUploadPicture: k, withUrlPicture: x, withLoadAndSave: r, withExport: l, hasActionToUndo: n, hasActionToRedo: a, hasActionToClear: o, undoAction: h, redoAction: d, clearCanvas: s })] }), z && v(si, { className: "react-paint-editor-toolbar-modal", onClose: B, title: "Outils", children: b.map((I) => I.type === "picture" ? null : v(Ne, { disabled: S, type: I, img: I.icon, withText: !1, isActive: i.id === I.id, setActive: X }, I.id)) }), D && v(Ms, { togglePictureUrlModal: () => {
1800
+ E((I) => !I);
1801
+ }, addPicture: u }), A && v(Cs, { toggleExportModal: F, exportCanvasInFile: m })] });
1802
+ }, Ut = { none: 0, small: 10, medium: 20, large: 40 }, Vs = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, Zs = () => {
1803
+ const e = ce([]), [t, i] = J([]);
1804
+ return de(() => () => {
1663
1805
  for (const n of e.current) clearTimeout(n);
1664
- }, []), { snackbarList: t, addSnackbar: ({ type: n = Ro, duration: a = No, text: o }) => {
1665
- const d = { id: ue("snackbar_"), duration: a, type: n, text: o };
1666
- i((r) => [...r, d]), e.current = [...e.current, setTimeout(() => {
1667
- return r = d.id, void i((s) => s.filter((l) => l.id !== r));
1668
- var r;
1806
+ }, []), { snackbarList: t, addSnackbar: ({ type: n = ss, duration: a = rs, text: o }) => {
1807
+ const r = { id: Le("snackbar_"), duration: a, type: n, text: o };
1808
+ i((l) => [...l, r]), e.current = [...e.current, setTimeout(() => {
1809
+ return l = r.id, void i((s) => s.filter((c) => c.id !== l));
1810
+ var l;
1669
1811
  }, a)];
1670
1812
  } };
1671
- }, gs = ({ editorProps: e, className: t, style: i, options: n, children: a }) => {
1672
- const { shapesRef: o, addPictureShape: d, moveShapes: r, toggleShapeVisibility: s, toggleShapeLock: l, canGoBackward: h, canGoForward: c, canClear: u, selectedShape: f, removeShape: v, updateShape: p, backwardShape: S, forwardShape: C, refs: b, width: Q, height: g, selectTool: w, selectShapes: L, activeTool: D, setActiveTool: V, setAvailableTools: x, isEditMode: Z, availableTools: A, gridGap: H, setGridGap: F, loadFile: E, exportPicture: W, exportData: G, clearCanvas: _, settings: z, setCanvasZoom: y, saveShapes: M, canvas: { canGrow: P, layersManipulation: T, withExport: k, withLoadAndSave: O, withUploadPicture: R, withUrlPicture: B } } = e, { toolbarBackgroundColor: I, dividerColor: j, fontRadius: de, fontDisabledColor: se, fontDisabledBackgroundColor: K, fontColor: N, fontBackgroundColor: ge, fontSelectedColor: oe, fontSelectedBackgroundColor: ye, fontHoverColor: Se, fontHoverBackgroundColor: Qe } = { ...ls, ...n }, te = z.size === "infinite" || z.features.zoom, [ve, U] = $(!1), [ae, Me] = $(!1), [Ze, re] = $(te), Te = te && Ze, qe = H >= Lt.large ? "large" : H >= Lt.medium ? "medium" : H >= Lt.small ? "small" : "none", { snackbarList: Ot, addSnackbar: De } = ds(), Ft = X((fe, me, gt) => {
1673
- x((Fe) => Fe.map((at) => at.id === fe ? Le(["settings", me, "default"], gt, at) : at)), V((Fe) => Fe.id === fe ? Le(["settings", me, "default"], gt, Fe) : Fe);
1674
- }, [V, x]), Yt = X((fe) => {
1675
- U(!0);
1813
+ }, Hs = ({ moveShapes: e, selectAllShapes: t, selectionMode: i, transformShape: n, settings: a, canvasRef: o, closeContextMenu: r, toggleShapeVisibility: l, toggleShapeLock: s, removeShape: c, duplicateShapes: h, copiedShape: d, setCopiedShape: u, pasteShapes: p, removeShapePoint: f }) => {
1814
+ const m = ce(null), b = ce(null), { isOpen: x } = ki({ trigger: "hover", buttonElt: m.current }), { isOpen: k } = ki({ trigger: "hover", buttonElt: b.current }), { originalShape: M, cursorStartPosition: S, anchor: g } = i, P = _(M), z = P.length > 0, N = P.length === 1 && (P[0]?.type === "polygon" || P[0]?.type === "curve") && g !== void 0 && P[0]?.points?.length > 2, D = !P.some((Z) => Z.visible === !1), E = P.some((Z) => Z.locked), A = 16 + 36 * (2 + (z ? 8 : 0) + (N ? 1 : 0)) + 16 * (z ? 3 : 1), [T] = J(() => [(S[0] + a.canvasOffset[0]) * a.canvasSize.scaleRatio, 36 + (S[1] + a.canvasOffset[1]) * a.canvasSize.scaleRatio]), [B, F] = J();
1815
+ de(() => {
1816
+ const Z = o?.current?.getBoundingClientRect();
1817
+ if (!Z) return;
1818
+ const ne = Z.left + T[0], I = Z.top + T[1], j = Math.max(0, Math.min(ne, window.innerWidth - 176)) - Z.left, ee = Math.max(0, Math.min(I, window.innerHeight - A)) - Z.top, se = j > window.innerWidth - 176 - Math.min(j, 200) ? "left" : "right";
1819
+ F({ x: j, y: ee, subMenuPosition: se });
1820
+ }, [o, T, A]);
1821
+ const X = B ? { "--react-paint-editor-toolbox-contextmenu-transform": `translate3D(${B.x}px, ${B.y}px, 0)` } : { display: "none" };
1822
+ return K(qt, { className: "react-paint-editor-toolbox-contextmenu", style: X, children: [z && K(Oe, { children: [N && v(q, { onClick: () => {
1823
+ N && f(P[0], g), r();
1824
+ }, children: "Delete point" }), K("div", { className: "react-paint-editor-toolbox-contextmenu-group", ref: m, children: [v(q, { icon: Gi, children: "Organize" }), x && K(qt, { position: B?.subMenuPosition, children: [v(q, { onClick: () => {
1825
+ z && e(P, "forward"), r();
1826
+ }, children: "Move forward" }), v(q, { onClick: () => {
1827
+ z && e(P, "first"), r();
1828
+ }, children: "Put on first" }), v(q, { onClick: () => {
1829
+ z && e(P, "backward"), r();
1830
+ }, children: "Move backward" }), v(q, { onClick: () => {
1831
+ z && e(P, "last"), r();
1832
+ }, children: "Put on last" })] })] }), K("div", { className: "react-paint-editor-toolbox-contextmenu-group", ref: b, children: [v(q, { icon: Gi, children: "Transform" }), k && K(qt, { position: B?.subMenuPosition, children: [v(q, { onClick: () => {
1833
+ const Z = o?.current?.getContext("2d");
1834
+ Z && z && n(Z, P, M.computed.center, "flipHorizontally"), r();
1835
+ }, children: "Flip horizontally" }), v(q, { onClick: () => {
1836
+ const Z = o?.current?.getContext("2d");
1837
+ Z && z && n(Z, P, M.computed.center, "flipVertically"), r();
1838
+ }, children: "Flip vertically" }), v(q, { onClick: () => {
1839
+ const Z = o?.current?.getContext("2d");
1840
+ Z && z && n(Z, P, M.computed.center, "rotateClockwise"), r();
1841
+ }, children: "Rotate clockwise" }), v(q, { onClick: () => {
1842
+ const Z = o?.current?.getContext("2d");
1843
+ Z && z && n(Z, P, M.computed.center, "rotateCounterclockwise"), r();
1844
+ }, children: "Rotate counterclockwise" })] })] }), v("hr", {}), v(q, { onClick: () => {
1845
+ z && (u(pe(P, a)), c(P)), r();
1846
+ }, children: "Cut" }), v(q, { onClick: () => {
1847
+ z && u(pe(P, a)), r();
1848
+ }, children: "Copy" })] }), v(q, { onClick: () => {
1849
+ d && p(Ri(d, a)), r();
1850
+ }, disabled: !d, children: "Paste" }), v("hr", {}), z && K(Oe, { children: [v(q, { onClick: () => {
1851
+ z && h(P, !0, !0), r();
1852
+ }, children: "Duplicate" }), v(q, { onClick: () => {
1853
+ z && l(P.filter((Z) => D ? Z.visible !== !1 : Z.visible === !1)), r();
1854
+ }, children: D ? "Hide" : "Show" }), v(q, { onClick: () => {
1855
+ z && s(P.filter((Z) => E ? Z.locked : !Z.locked)), r();
1856
+ }, children: E ? "Unlock" : "Lock" }), v(q, { onClick: () => {
1857
+ z && c(P), r();
1858
+ }, children: "Delete" }), v("hr", {})] }), v(q, { onClick: () => {
1859
+ t(), r();
1860
+ }, children: "Select all" })] });
1861
+ }, Es = ({ editorProps: e, className: t, style: i, options: n, children: a }) => {
1862
+ const { selectionMode: o, setSelectionMode: r, shapesRef: l, addPictureShape: s, moveShapes: c, swapShapes: h, toggleShapeVisibility: d, toggleShapeLock: u, canGoBackward: p, canGoForward: f, canClear: m, selectedShape: b, copiedShape: x, setCopiedShape: k, pasteShapes: M, removeShape: S, duplicateShapes: g, updateShape: P, backwardShape: z, forwardShape: N, removeShapePoint: D, transformShape: E, refs: A, width: T, height: B, selectTool: F, selectShapes: X, selectAllShapes: Z, activeTool: ne, setActiveTool: I, setAvailableTools: j, isEditMode: ee, availableTools: se, gridGap: he, setGridGap: C, loadFile: $, exportPicture: Q, exportData: w, clearCanvas: y, settings: L, setCanvasZoom: W, saveShapes: V, canvas: { canGrow: U, layersManipulation: R, withExport: H, withLoadAndSave: ae, withUploadPicture: me, withUrlPicture: O, withContextMenu: ge } } = e, { toolbarBackgroundColor: ue, dividerColor: Se, fontRadius: Ie, fontDisabledColor: te, fontDisabledBackgroundColor: we, fontColor: re, fontBackgroundColor: ye, fontSelectedColor: ie, fontSelectedBackgroundColor: le, fontHoverColor: fe, fontHoverBackgroundColor: Ve } = { ...Vs, ...n }, Fe = L.size === "infinite" || L.features.zoom, [We, Ce] = J(!1), [Ye, bt] = J(!1), [Qt, ct] = J(Fe), $e = Fe && Qt, wt = he >= Ut.large ? "large" : he >= Ut.medium ? "medium" : he >= Ut.small ? "small" : "none", { snackbarList: xt, addSnackbar: Ae } = Zs(), ot = G((be, xe, Y) => {
1863
+ j((nt) => nt.map((Tt) => Tt.id === be ? Xe(["settings", xe, "default"], Y, Tt) : Tt)), I((nt) => nt.id === be ? Xe(["settings", xe, "default"], Y, nt) : nt);
1864
+ }, [I, j]), st = G((be) => {
1865
+ Ce(!0);
1676
1866
  try {
1677
- W(fe);
1678
- } catch (me) {
1679
- me instanceof Error && De({ type: "error", text: `L'export a échoué : ${me.message}` }), console.warn(me);
1867
+ Q(be);
1868
+ } catch (xe) {
1869
+ xe instanceof Error && Ae({ type: "error", text: `L'export a échoué : ${xe.message}` }), console.warn(xe);
1680
1870
  } finally {
1681
- U(!1);
1871
+ Ce(!1);
1682
1872
  }
1683
- }, [W, De]), Ge = X(() => {
1684
- U(!0);
1873
+ }, [Q, Ae]), je = G(() => {
1874
+ Ce(!0);
1685
1875
  try {
1686
- G(), U(!1);
1687
- } catch (fe) {
1688
- fe instanceof Error && De({ type: "error", text: "L'enregistrement a échoué" }), console.warn(fe);
1876
+ w(), Ce(!1);
1877
+ } catch (be) {
1878
+ be instanceof Error && Ae({ type: "error", text: "L'enregistrement a échoué" }), console.warn(be);
1689
1879
  } finally {
1690
- U(!1);
1880
+ Ce(!1);
1691
1881
  }
1692
- }, [G, De]), Xt = X(async (fe) => {
1693
- U(!0);
1882
+ }, [w, Ae]), dt = G(async (be) => {
1883
+ Ce(!0);
1694
1884
  try {
1695
- await E(fe), De({ type: "success", text: "Fichier chargé !" });
1696
- } catch (me) {
1697
- me instanceof Error && De({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1885
+ await $(be), Ae({ type: "success", text: "Fichier chargé !" });
1886
+ } catch (xe) {
1887
+ xe instanceof Error && Ae({ type: "error", text: "Le chargement a échoué" }), console.warn(xe);
1698
1888
  } finally {
1699
- U(!1);
1889
+ Ce(!1);
1700
1890
  }
1701
- }, [E, De]), $t = X(async (fe) => {
1702
- U(!0);
1891
+ }, [$, Ae]), ht = G(async (be) => {
1892
+ Ce(!0);
1703
1893
  try {
1704
- const me = await d(fe, Q, g);
1705
- L([me]);
1706
- } catch (me) {
1707
- me instanceof Error && De({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1894
+ const xe = await s(be, T, B);
1895
+ X([xe]);
1896
+ } catch (xe) {
1897
+ xe instanceof Error && Ae({ type: "error", text: "Le chargement a échoué" }), console.warn(xe);
1708
1898
  } finally {
1709
- U(!1);
1899
+ Ce(!1);
1710
1900
  }
1711
- }, [d, L, De, Q, g]), Ut = `${t ? `${t} ` : ""}${ae ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1712
- return q("div", { ref: b.setEditor, className: Ut, style: { "--react-paint-editor-app-maxWidth": P ? "100%" : `${Q}px`, "--react-paint-editor-app-toolbar-bg": I, "--react-paint-editor-app-divider-color": j, "--react-paint-editor-app-font-radius": de, "--react-paint-editor-app-font-disabled-color": se, "--react-paint-editor-app-font-disabled-bg": K, "--react-paint-editor-app-font-color": N, "--react-paint-editor-app-font-bg": ge, "--react-paint-editor-app-font-selected-color": oe, "--react-paint-editor-app-font-selected-bg": ye, "--react-paint-editor-app-font-hover-color": Se, "--react-paint-editor-app-font-hover-bg": Qe, ...i }, children: [Z && m(rs, { settings: z, width: z.canvasSize.width, activeTool: D, clearCanvas: _, setActiveTool: w, exportCanvasInFile: Yt, saveFile: Ge, loadFile: Xt, addPicture: $t, hasActionToUndo: h, hasActionToRedo: c, hasActionToClear: u, undoAction: S, redoAction: C, availableTools: A, withExport: k, withLoadAndSave: O, withUploadPicture: R, withUrlPicture: B }), a, Z && T && m($o, { gridFormat: qe, setGridFormat: (fe) => {
1713
- F(Lt[fe]);
1714
- }, shapes: o.current, moveShapes: r, selectedShapes: f, removeShape: v, selectShapes: L, toggleShapeVisibility: s, toggleShapeLock: l, isLayoutPanelShown: ae, settings: z }), Te && q(nt, { alignment: "left", className: "react-paint-editor-layouts-panel", "data-edit": +Z, children: [m(J, { 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: () => y("unzoom") }), q(J, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => y("default"), children: [Math.round(100 * z.canvasZoom), "%"] }), m(J, { className: "react-paint-editor-zoom-button", icon: Dn, onClick: () => y("zoom") })] }), Z && q(Ae, { children: [m(ts, { saveShapes: M, setCanvasZoom: y, width: z.canvasSize.width, activeTool: D, availableTools: A, selectedShape: f, settings: z, removeShape: v, updateShape: p, canvas: b.canvas.current, layersManipulation: T, toggleLayoutPanel: () => {
1715
- Me((fe) => !fe);
1716
- }, isZoomPanelShown: Te, setIsZoomPanelShown: re, updateToolSettings: Ft }), m(Wo, { isLoading: ve }), m(Oo, { snackbarList: Ot })] })] });
1901
+ }, [s, X, Ae, T, B]), ut = `${t ? `${t} ` : ""}${Ye ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1902
+ return K("div", { ref: A.setEditor, className: ut, style: { "--react-paint-editor-app-maxWidth": U ? "100%" : `${T}px`, "--react-paint-editor-app-toolbar-bg": ue, "--react-paint-editor-app-divider-color": Se, "--react-paint-editor-app-font-radius": `${Ie}px`, "--react-paint-editor-app-font-disabled-color": te, "--react-paint-editor-app-font-disabled-bg": we, "--react-paint-editor-app-font-color": re, "--react-paint-editor-app-font-bg": ye, "--react-paint-editor-app-font-selected-color": ie, "--react-paint-editor-app-font-selected-bg": le, "--react-paint-editor-app-font-hover-color": fe, "--react-paint-editor-app-font-hover-bg": Ve, ...i }, children: [ee && v(Ls, { settings: L, width: L.canvasSize.width, activeTool: ne, clearCanvas: y, setActiveTool: F, exportCanvasInFile: st, saveFile: je, loadFile: dt, addPicture: ht, hasActionToUndo: p, hasActionToRedo: f, hasActionToClear: m, undoAction: z, redoAction: N, availableTools: se, withExport: H, withLoadAndSave: ae, withUploadPicture: me, withUrlPicture: O }), a, ee && R && v(ps, { gridFormat: wt, setGridFormat: (be) => {
1903
+ C(Ut[be]);
1904
+ }, shapes: l.current, swapShapes: h, selectedShapes: b, removeShape: S, selectShapes: X, toggleShapeVisibility: d, toggleShapeLock: u, isLayoutPanelShown: Ye, settings: L }), $e && K(St, { alignment: "left", position: "bottom", className: "react-paint-editor-layouts-panel", "data-edit": +ee, children: [v(q, { className: "react-paint-editor-zoom-button", icon: '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>', onClick: () => W("unzoom") }), K(q, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => W("default"), children: [Math.round(100 * L.canvasZoom), "%"] }), v(q, { className: "react-paint-editor-zoom-button", icon: Kn, onClick: () => W("zoom") })] }), ee && K(Oe, { children: [v(ws, { saveShapes: V, setCanvasZoom: W, width: L.canvasSize.width, activeTool: ne, availableTools: se, selectedShape: b, settings: L, removeShape: S, updateShape: P, canvas: A.canvas.current, layersManipulation: R, toggleLayoutPanel: () => {
1905
+ bt((be) => !be);
1906
+ }, isZoomPanelShown: $e, setIsZoomPanelShown: ct, updateToolSettings: ot }), v(os, { isLoading: We }), v(cs, { snackbarList: xt })] }), o.mode === "contextMenu" && ge && v(Hs, { selectionMode: o, settings: L, canvasRef: A.canvas, closeContextMenu: () => {
1907
+ r({ mode: "default" }), A.canvas.current?.focus();
1908
+ }, selectAllShapes: Z, removeShape: S, moveShapes: c, duplicateShapes: g, toggleShapeLock: u, toggleShapeVisibility: d, setCopiedShape: k, copiedShape: x, pasteShapes: M, removeShapePoint: D, transformShape: E })] });
1717
1909
  };
1718
1910
  export {
1719
- ps as Canvas,
1720
- gs as Editor,
1721
- us as useReactPaint
1911
+ Ds as Canvas,
1912
+ Es as Editor,
1913
+ Ts as useReactPaint
1722
1914
  };