@yorab/react-paint 0.15.0 → 0.15.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.
@@ -1,686 +1,686 @@
1
- import si, { useState as $, useEffect as J, useRef as te, useCallback as B, useMemo as ba, useImperativeHandle as xa, useTransition as wa } from "react";
2
- import { jsx as v, jsxs as Y, Fragment as Ve } from "react/jsx-runtime";
3
- const Ca = '<svg><path d="M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z"/></svg>', ri = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', li = '<svg><path d="M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z"/></svg>', ci = '<svg><path d="M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z"/></svg>', Ma = '<svg><path d="M4.125 5.083V3.333H7.062L7.896 2.5H12.104L12.938 3.333H15.875V5.083ZM6.75 17.5Q6.021 17.5 5.51 16.99Q5 16.479 5 15.75V5.958H15V15.75Q15 16.479 14.49 16.99Q13.979 17.5 13.25 17.5Z"/></svg>', Li = '<svg><path d="M10 17.5Q7.208 17.5 5.271 15.594Q3.333 13.688 3.333 10.958Q3.333 9.583 3.854 8.396Q4.375 7.208 5.292 6.292L10 1.667L14.688 6.292Q15.604 7.208 16.135 8.396Q16.667 9.583 16.667 10.958Q16.667 13.688 14.719 15.594Q12.771 17.5 10 17.5ZM5.146 11.667H14.854Q15.083 10.188 14.552 9.146Q14.021 8.104 13.479 7.562L10 4.125L6.521 7.562Q5.979 8.104 5.448 9.146Q4.917 10.188 5.146 11.667Z"/></svg>', di = '<svg><path d="M4.792 15.083 8.333 11.542 9.833 13.021 11.667 10.708 15.167 15.083ZM6.667 8.417Q5.938 8.417 5.427 7.906Q4.917 7.396 4.917 6.667Q4.917 5.938 5.427 5.427Q5.938 4.917 6.667 4.917Q7.396 4.917 7.906 5.427Q8.417 5.938 8.417 6.667Q8.417 7.396 7.906 7.906Q7.396 8.417 6.667 8.417ZM4.167 18.333Q3.125 18.333 2.396 17.604Q1.667 16.875 1.667 15.833V4.167Q1.667 3.125 2.396 2.396Q3.125 1.667 4.167 1.667H15.833Q16.875 1.667 17.604 2.396Q18.333 3.125 18.333 4.167V15.833Q18.333 16.875 17.604 17.604Q16.875 18.333 15.833 18.333ZM4.167 16.583H15.833Q16.146 16.583 16.365 16.365Q16.583 16.146 16.583 15.833V4.167Q16.583 3.854 16.365 3.635Q16.146 3.417 15.833 3.417H4.167Q3.854 3.417 3.635 3.635Q3.417 3.854 3.417 4.167V15.833Q3.417 16.146 3.635 16.365Q3.854 16.583 4.167 16.583Z"/></svg>', ka = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', Pa = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', La = '<svg><path d="M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z"/></svg>', Zi = '<svg><path d="M5.833 15V3.333H10.375Q11.812 3.333 12.885 4.156Q13.958 4.979 13.958 6.375Q13.958 7.375 13.49 7.969Q13.021 8.562 12.396 8.875V9.042Q13.312 9.354 13.844 10.021Q14.375 10.688 14.375 11.75Q14.375 13.312 13.229 14.156Q12.083 15 10.5 15ZM8.125 8.042H10.188Q10.854 8.042 11.302 7.656Q11.75 7.271 11.75 6.708Q11.75 6.167 11.302 5.771Q10.854 5.375 10.188 5.375H8.125ZM8.125 12.917H10.354Q11.167 12.917 11.625 12.51Q12.083 12.104 12.083 11.458Q12.083 10.812 11.625 10.406Q11.167 10 10.354 10H8.125Z"/></svg>', Vi = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', Hi = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Ti = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM10 16.583Q10.896 16.583 11.708 16.365Q12.521 16.146 13.25 15.729L4.292 6.75Q3.875 7.479 3.646 8.292Q3.417 9.104 3.417 10Q3.417 12.729 5.344 14.656Q7.271 16.583 10 16.583ZM17 14.562 15.708 13.271Q16.125 12.542 16.354 11.719Q16.583 10.896 16.583 10Q16.583 7.271 14.656 5.344Q12.729 3.417 10 3.417Q9.104 3.417 8.292 3.646Q7.479 3.875 6.75 4.292L5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562ZM11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771ZM8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Z"/></svg>', zi = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM17 14.562 5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562Z"/></svg>', Za = '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Zm-40-60v-80h-80v-80h80v-80h80v80h80v80h-80v80h-80Z"/></svg>', we = ["transparent", "black", "white", "red", "green", "blue", "yellow"], Ge = [0, 1, 2], Ai = [[1, 0], [1, 2], [4, 6]], yt = "serif", An = 2, Va = 3, En = 4, ue = "react-paint-", Ha = { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } }, hi = { type: "picture", id: `${ue}picture`, icon: di, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, Ta = { type: "brush", id: `${ue}brush`, icon: Ca, label: "Brosse", settings: { strokeColor: { values: we, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: Ge, default: 0 } } }, za = { type: "line", id: `${ue}line`, icon: Pa, label: "Ligne", settings: { strokeColor: { values: we, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, Aa = { type: "polygon", id: `${ue}polygon`, icon: ci, label: "Polygone", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 }, closedPoints: { default: 0 } } }, Ea = { type: "curve", id: `${ue}curve`, icon: La, label: "Courbe", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 }, closedPoints: { default: 0 } } }, Ia = { type: "rect", id: `${ue}rect`, icon: ri, label: "Rectangle", settings: Ha }, Na = { type: "square", id: `${ue}square`, icon: ri, label: "Carré", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } } }, Da = { type: "circle", id: `${ue}circle`, icon: li, label: "Cercle", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } } }, Ra = { type: "ellipse", id: `${ue}ellipse`, icon: li, label: "Ellipse", settings: { strokeColor: { values: we, default: "black" }, fillColor: { values: we, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ge, default: 0 } } }, Wa = { type: "text", id: `${ue}text`, icon: ka, label: "Texte", settings: { strokeColor: { values: we, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: yt }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Fe = { id: `${ue}selection`, type: "selection", icon: '<svg><path d="M8.0145 11.1707C8.38484 10.9914 8.82183 11.1558 8.99959 11.5295L10.7031 15.2591L12.0363 14.6238L10.3254 10.9017C10.1476 10.528 10.3106 10.0795 10.6809 9.90761L10.8883 9.84782L12.5918 9.51148L6.48133 4.33192V12.389L7.82934 11.2903L8.0145 11.1707ZM10.6587 16.9258C10.2883 17.1052 9.84395 16.9482 9.67359 16.5745L8.05894 13.0318L6.19988 14.5416C6.07396 14.6462 5.91842 14.706 5.74066 14.706C5.54423 14.706 5.35584 14.6272 5.21694 14.4871C5.07803 14.3469 5 14.1568 5 13.9586V2.74741C5 2.54919 5.07803 2.35908 5.21694 2.21891C5.35584 2.07874 5.54423 2 5.74066 2C5.91842 2 6.08878 2.06727 6.21469 2.1719L6.2221 2.16443L14.7323 9.36947C15.0508 9.63854 15.0879 10.1094 14.8286 10.4233C14.7175 10.5579 14.562 10.6475 14.4064 10.6774L12.0659 11.1408L13.6954 14.6761C13.888 15.0498 13.7102 15.4908 13.3399 15.6627L10.6587 16.9258Z"/></svg>', label: "Sélection" }, rt = { id: `${ue}undo`, type: "undo", icon: '<svg><path d="M11.708 15.833H5.854V14.083H11.708Q13 14.083 13.958 13.292Q14.917 12.5 14.917 11.271Q14.917 10.042 13.958 9.24Q13 8.438 11.708 8.438H6.667L8.792 10.562L7.562 11.792L3.333 7.562L7.562 3.333L8.792 4.562L6.667 6.688H11.708Q13.729 6.688 15.198 7.99Q16.667 9.292 16.667 11.25Q16.667 13.208 15.198 14.521Q13.729 15.833 11.708 15.833Z"/></svg>', label: "Undo" }, lt = { id: `${ue}redo`, type: "redo", icon: '<svg><path d="M8.292 15.833Q6.271 15.833 4.802 14.521Q3.333 13.208 3.333 11.25Q3.333 9.292 4.802 7.99Q6.271 6.688 8.292 6.688H13.333L11.208 4.562L12.438 3.333L16.667 7.562L12.438 11.792L11.208 10.562L13.333 8.438H8.292Q7 8.438 6.042 9.229Q5.083 10.021 5.083 11.25Q5.083 12.5 6.042 13.292Q7 14.083 8.292 14.083H14.146V15.833Z"/></svg>', label: "Redo" }, ct = { id: `${ue}clear`, type: "clear", icon: '<svg><path d="M7.854 13.812 10 11.688 12.125 13.812 13.354 12.604 11.208 10.458 13.354 8.312 12.125 7.104 10 9.229 7.854 7.104 6.625 8.312 8.771 10.458 6.625 12.604ZM5.896 17.5Q5.167 17.5 4.656 16.99Q4.146 16.479 4.146 15.75V5.125H3.333V3.375H7.542V2.5H12.458V3.375H16.667V5.125H15.833V15.75Q15.833 16.479 15.323 16.99Q14.812 17.5 14.083 17.5Z"/></svg>', label: "Clear" }, Yt = { id: `${ue}export`, type: "export", icon: '<svg><path d="M10 13.271 5.708 8.979 6.958 7.729 9.125 9.896V3.333H10.875V9.896L13.042 7.729L14.292 8.979ZM5.083 16.667Q4.354 16.667 3.844 16.156Q3.333 15.646 3.333 14.917V12.5H5.083V14.917Q5.083 14.917 5.083 14.917Q5.083 14.917 5.083 14.917H14.917Q14.917 14.917 14.917 14.917Q14.917 14.917 14.917 14.917V12.5H16.667V14.917Q16.667 15.646 16.156 16.156Q15.646 16.667 14.917 16.667Z"/></svg>', label: "Export PNG" }, Ei = { id: `${ue}load`, type: "loadfile", icon: '<svg><path d="M3.417 16.667Q2.729 16.667 2.198 16.135Q1.667 15.604 1.667 14.917V5.083Q1.667 4.396 2.198 3.865Q2.729 3.333 3.417 3.333H8.25L9.917 5H16.667Q17.354 5 17.844 5.531Q18.333 6.062 18.333 6.75H3.417V14.917Q3.417 14.917 3.417 14.917Q3.417 14.917 3.417 14.917L5.438 8.5H19.583L17.396 15.479Q17.229 16.021 16.802 16.344Q16.375 16.667 15.833 16.667Z"/></svg>', label: "Load project" }, Ut = { id: `${ue}save`, type: "savefile", icon: '<svg><path d="M17.5 5.833V15.75Q17.5 16.479 16.99 16.99Q16.479 17.5 15.75 17.5H4.25Q3.521 17.5 3.01 16.99Q2.5 16.479 2.5 15.75V4.25Q2.5 3.521 3.01 3.01Q3.521 2.5 4.25 2.5H14.167ZM10 14.917Q11.062 14.917 11.823 14.156Q12.583 13.396 12.583 12.333Q12.583 11.271 11.823 10.51Q11.062 9.75 10 9.75Q8.938 9.75 8.177 10.51Q7.417 11.271 7.417 12.333Q7.417 13.396 8.177 14.156Q8.938 14.917 10 14.917ZM5.021 8.396H12.521V5.021H5.021Z"/></svg>', label: "Save project" }, Xt = { id: `${ue}move`, type: "move", icon: '<svg viewBox="0 -960 960 960"><path d="M412-48q-21.95 0-40.98-9Q352-66 338-83L48-434l27-28q17-17 41.5-20.5T162-473l126 74v-381q0-15.3 10.29-25.65Q308.58-816 323.79-816t25.71 10.35Q360-795.3 360-780v300h80v-396q0-15.3 10.29-25.65Q460.58-912 475.79-912t25.71 10.35Q512-891.3 512-876v396h80v-348q0-15.3 10.29-25.65Q612.58-864 627.79-864t25.71 10.35Q664-843.3 664-828v348h80v-252q0-15.3 10.29-25.65Q764.58-768 779.79-768t25.71 10.35Q816-747.3 816-732v540q0 60-42 102T672-48H412Z"/></svg>', label: "Move" }, Ii = { id: `${ue}upload-picture`, type: "uploadpicture", icon: di, label: "Upload picture" }, Oa = 2, Fa = "blue", et = 14, Ba = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], $a = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], Ya = "react-paint-canvas-drawcanvas", Ua = "react-paint-canvas-selectioncanvas", Ni = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [Ta, za, Aa, Ea, Ia, Na, Da, Ra, hi, Wa], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, In = { canvasBackgroundColor: "white", canvasSelectionColor: Fa, canvasSelectionWidth: Oa }, Di = 300, Jt = (e, t) => {
4
- const i = { ...t };
5
- for (const a of e) delete i[a];
6
- return i;
7
- }, Pe = (e, t, i) => {
8
- const a = Array.isArray(i) ? [...i] : { ...i }, n = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
- return n.reduce((o, r, l) => (o[r] = ei(o[r]) ? { ...o[r] } : Array.isArray(o[r]) ? [...o[r]] : o[r] === void 0 || o[r] === null ? {} : o[r], l === n.length - 1 && (o[r] = t), o[r]), a), a;
10
- }, ei = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, Ne = (e, t, i) => {
11
- if (!ei(t) || !ei(i)) return i;
1
+ import ra, { useState as U, useEffect as ee, useRef as ie, useCallback as $, useMemo as Ci, useImperativeHandle as xi, useTransition as Mi } from "react";
2
+ import { jsx as f, jsxs as X, Fragment as Te } from "react/jsx-runtime";
3
+ const ki = '<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>', la = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', ca = '<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>', da = '<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>', Pi = '<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>', Za = '<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>', ha = '<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>', Li = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', Vi = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', Zi = '<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>', Ha = '<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>', Ta = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', za = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Aa = '<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>', Ea = '<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>', Hi = '<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>', xe = ["transparent", "black", "white", "red", "green", "blue", "yellow"], qe = [0, 1, 2], Ia = [[1, 0], [1, 2], [4, 6]], St = "serif", En = 2, Ti = 3, In = 4, he = "react-paint-", zi = { strokeColor: { values: xe, default: "black" }, fillColor: { values: xe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: qe, default: 0 } }, ua = { type: "picture", id: `${he}picture`, icon: ha, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, Ai = { type: "brush", id: `${he}brush`, icon: ki, label: "Brosse", settings: { strokeColor: { values: xe, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: qe, default: 0 } } }, Ei = { type: "line", id: `${he}line`, icon: Vi, label: "Ligne", settings: { strokeColor: { values: xe, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: qe, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, Ii = { type: "polygon", id: `${he}polygon`, icon: da, label: "Polygone", settings: { strokeColor: { values: xe, default: "black" }, fillColor: { values: xe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: qe, default: 0 }, closedPoints: { default: 0 } } }, Di = { type: "curve", id: `${he}curve`, icon: Zi, label: "Courbe", settings: { strokeColor: { values: xe, default: "black" }, fillColor: { values: xe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: qe, default: 0 }, closedPoints: { default: 0 } } }, Ni = { type: "rect", id: `${he}rect`, icon: la, label: "Rectangle", settings: zi }, Ri = { type: "square", id: `${he}square`, icon: la, label: "Carré", settings: { strokeColor: { values: xe, default: "black" }, fillColor: { values: xe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: qe, default: 0 } } }, Wi = { type: "circle", id: `${he}circle`, icon: ca, label: "Cercle", settings: { strokeColor: { values: xe, default: "black" }, fillColor: { values: xe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: qe, default: 0 } } }, Oi = { type: "ellipse", id: `${he}ellipse`, icon: ca, label: "Ellipse", settings: { strokeColor: { values: xe, default: "black" }, fillColor: { values: xe, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: qe, default: 0 } } }, Fi = { type: "text", id: `${he}text`, icon: Li, label: "Texte", settings: { strokeColor: { values: xe, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: St }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Be = { 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" }, lt = { 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" }, dt = { 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" }, Ut = { 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" }, Da = { 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" }, Xt = { 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" }, Gt = { 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" }, Na = { id: `${he}upload-picture`, type: "uploadpicture", icon: ha, label: "Upload picture" }, Bi = 2, $i = "blue", tt = 14, Yi = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], Ui = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], Xi = "react-paint-canvas-drawcanvas", Gi = "react-paint-canvas-selectioncanvas", Ra = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [Ai, Ei, Ii, Di, Ni, Ri, Wi, Oi, ua, Fi], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, Dn = { canvasBackgroundColor: "white", canvasSelectionColor: $i, canvasSelectionWidth: Bi }, Wa = 300, ea = (e, t) => {
12
4
  const a = { ...t };
13
- for (const n in i) i.hasOwnProperty(n) && (a.hasOwnProperty(n) ? a[n] = e(a[n], i[n], n) ?? Ne(e, a[n], i[n]) : a[n] = i[n]);
5
+ for (const i of e) delete a[i];
14
6
  return a;
15
- }, Xa = (e, t) => {
7
+ }, Ve = (e, t, a) => {
8
+ const i = Array.isArray(a) ? [...a] : { ...a }, n = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
+ return n.reduce((o, c, r) => (o[c] = ta(o[c]) ? { ...o[c] } : Array.isArray(o[c]) ? [...o[c]] : o[c] === void 0 || o[c] === null ? {} : o[c], r === n.length - 1 && (o[c] = t), o[c]), i), i;
10
+ }, ta = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, De = (e, t, a) => {
11
+ if (!ta(t) || !ta(a)) return a;
12
+ const i = { ...t };
13
+ for (const n in a) a.hasOwnProperty(n) && (i.hasOwnProperty(n) ? i[n] = e(i[n], a[n], n) ?? De(e, i[n], a[n]) : i[n] = a[n]);
14
+ return i;
15
+ }, qi = (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
- const i = Object.keys(e), a = Object.keys(t);
19
- if (i.length !== a.length) return !1;
20
- for (const n of i) if (!a.includes(n) || !Xa(e[n], t[n])) return !1;
18
+ const a = Object.keys(e), i = Object.keys(t);
19
+ if (a.length !== i.length) return !1;
20
+ for (const n of a) if (!i.includes(n) || !qi(e[n], t[n])) return !1;
21
21
  return !0;
22
- }, Gt = {}, ye = (e = "") => (Gt[e] || (Gt[e] = 0), `${e}${++Gt[e]}`), De = (e, t, i) => Math.max(t, Math.min(e, i)), Ga = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), qa = (e) => {
22
+ }, qt = {}, ue = (e = "") => (qt[e] || (qt[e] = 0), `${e}${++qt[e]}`), Ne = (e, t, a) => Math.max(t, Math.min(e, a)), _i = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), ji = (e) => {
23
23
  e.reset(), e.lineCap = "round", e.lineJoin = "round";
24
- }, Qe = (e, t = {}) => {
25
- const { lineCap: i = "round", fillColor: a = "transparent", opacity: n = 100, strokeColor: o = Fa, lineWidth: r = Oa, lineDash: l = 0, shadowColor: s = "transparent", shadowBlur: c = 0 } = t;
26
- e.lineCap = i, e.globalAlpha = n / 100, e.fillStyle = a, e.strokeStyle = o, e.lineWidth = r, e.setLineDash(l === 0 ? [] : [Ai[l][0] * r, Ai[l][1] * r]), e.shadowColor = s, e.shadowBlur = c;
27
- }, Pt = (e, t, i, a) => {
28
- e.save(), e.scale(t.canvasSize.scaleRatio, t.canvasSize.scaleRatio), e.translate(t.canvasOffset[0], t.canvasOffset[1]), i && a && (e.translate(a[0], a[1]), e.rotate(i), e.translate(-a[0], -a[1]));
29
- }, _a = (e, { selectionPadding: t }) => {
30
- const i = e.points.flat(), a = Math.min(...i.map((s) => s[0])), n = Math.min(...i.map((s) => s[1])), o = i.map((s) => ze(s, a, n, e.scaleX, e.scaleY)), r = Math.max(...o.map((s) => s[0])) + t, l = Math.max(...o.map((s) => s[1])) + t;
31
- return { x: a - t, width: r - a + t, y: n - t, height: l - n + t };
32
- }, ja = (e, t) => Re(e, _a, t), ht = (e, t) => {
33
- const i = Wn(e, t), a = ja(e, t);
34
- return { ...e, path: i, selection: ut(i, a, t), computed: a };
35
- }, Nn = ht, ti = (e) => 180 * e / Math.PI, Ka = (e, t) => {
36
- const i = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), a = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
37
- return Math.sqrt(i * i + a * a) <= t.radius;
38
- }, xe = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
39
- const a = [t[0] - e[0], t[1] - e[1]], n = a[1] * Math.cos(i) - a[0] * Math.sin(i);
40
- return [a[1] * Math.sin(i) + a[0] * Math.cos(i) + e[0], n + e[1]];
41
- }, Ri = (e) => (e + 2 * Math.PI) % (2 * Math.PI), Wi = ({ targetVector: [e, t], radian: i = !0, originVector: a }) => {
42
- const n = Ri(Math.atan2(t[1] - e[1], t[0] - e[0]));
43
- if (a) {
44
- const [o, r] = a, l = Math.atan2(r[1] - o[1], r[0] - o[0]), s = Ri(n - l);
45
- return i ? s : ti(s);
24
+ }, be = (e, t = {}) => {
25
+ const { lineCap: a = "round", fillColor: i = "transparent", opacity: n = 100, strokeColor: o = $i, lineWidth: c = Bi, lineDash: r = 0, shadowColor: s = "transparent", shadowBlur: l = 0 } = t;
26
+ e.lineCap = a, e.globalAlpha = n / 100, e.fillStyle = i, e.strokeStyle = o, e.lineWidth = c, e.setLineDash(r === 0 ? [] : [Ia[r][0] * c, Ia[r][1] * c]), e.shadowColor = s, e.shadowBlur = l;
27
+ }, Lt = (e, t, a, i) => {
28
+ e.save(), e.scale(t.canvasSize.scaleRatio, t.canvasSize.scaleRatio), e.translate(t.canvasOffset[0], t.canvasOffset[1]), a && i && (e.translate(i[0], i[1]), e.rotate(a), e.translate(-i[0], -i[1]));
29
+ }, Ki = (e, { selectionPadding: t }) => {
30
+ const a = e.points.flat(), i = Math.min(...a.map((s) => s[0])), n = Math.min(...a.map((s) => s[1])), o = a.map((s) => Ae(s, i, n, e.scaleX, e.scaleY)), c = Math.max(...o.map((s) => s[0])) + t, r = Math.max(...o.map((s) => s[1])) + t;
31
+ return { x: i - t, width: c - i + t, y: n - t, height: r - n + t };
32
+ }, Ji = (e, t) => Re(e, Ki, t), pt = (e, t) => {
33
+ const a = On(e, t), i = Ji(e, t);
34
+ return { ...e, path: a, selection: gt(a, i, t), computed: i };
35
+ }, Nn = pt, aa = (e) => 180 * e / Math.PI, en = (e, t) => {
36
+ const a = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), i = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
37
+ return Math.sqrt(a * a + i * i) <= t.radius;
38
+ }, Ce = ({ origin: e = [0, 0], point: t, rotation: a = 0 }) => {
39
+ const i = [t[0] - e[0], t[1] - e[1]], n = i[1] * Math.cos(a) - i[0] * Math.sin(a);
40
+ return [i[1] * Math.sin(a) + i[0] * Math.cos(a) + e[0], n + e[1]];
41
+ }, Oa = (e) => (e + 2 * Math.PI) % (2 * Math.PI), Fa = ({ targetVector: [e, t], radian: a = !0, originVector: i }) => {
42
+ const n = Oa(Math.atan2(t[1] - e[1], t[0] - e[0]));
43
+ if (i) {
44
+ const [o, c] = i, r = Math.atan2(c[1] - o[1], c[0] - o[0]), s = Oa(n - r);
45
+ return a ? s : aa(s);
46
46
  }
47
- return i ? n : ti(n);
48
- }, Ja = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), Xe = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, ze = (e, t, i, a = 1, n = 1) => [t + (e[0] - t) * a, i + (e[1] - i) * n], _ = (e, t, i = 0) => {
49
- if (!t.gridGap) return Xe(e);
50
- const a = e + i, n = a >= 0 ? t.gridGap : -t.gridGap;
51
- return a + n / 2 - (a + n / 2) % n - i;
52
- }, Dn = (e, t, i) => t.gridGap || i ? e + Math.PI / 18 / 2 - (e + Math.PI / 18 / 2) % (Math.PI / 18) : Xe(e, 3), Oe = (e, t) => t ? [Math.abs(e[0]) > Math.abs(e[1]) ? e[0] : 0, Math.abs(e[1]) > Math.abs(e[0]) ? e[1] : 0] : e, Rn = (e, t, i, a, n, o, r) => be(j(t).map((l) => {
53
- switch (a.mode) {
47
+ return a ? n : aa(n);
48
+ }, tn = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), Ge = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Ae = (e, t, a, i = 1, n = 1) => [t + (e[0] - t) * i, a + (e[1] - a) * n], q = (e, t, a = 0) => {
49
+ if (!t.gridGap) return Ge(e);
50
+ const i = e + a, n = i >= 0 ? t.gridGap : -t.gridGap;
51
+ return i + n / 2 - (i + n / 2) % n - a;
52
+ }, Rn = (e, t, a) => t.gridGap || a ? e + Math.PI / 18 / 2 - (e + Math.PI / 18 / 2) % (Math.PI / 18) : Ge(e, 3), Fe = (e, t) => t ? [Math.abs(e[0]) > Math.abs(e[1]) ? e[0] : 0, Math.abs(e[1]) > Math.abs(e[0]) ? e[1] : 0] : e, Wn = (e, t, a, i, n, o, c) => we(_(t).map((r) => {
53
+ switch (i.mode) {
54
54
  case "brush":
55
- return ((s, c, u) => {
56
- const d = { ...s, points: Pe(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(c[0]), Math.round(c[1])]], s.points) };
57
- return ht(d, u);
58
- })(l, i, n);
55
+ return ((s, l, u) => {
56
+ const d = { ...s, points: Ve(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(l[0]), Math.round(l[1])]], s.points) };
57
+ return pt(d, u);
58
+ })(r, a, n);
59
59
  case "translate":
60
- return oi(i, j(a.originalShape).find((s) => s.id === l.id), a.cursorStartPosition, n, o);
60
+ return sa(a, _(i.originalShape).find((s) => s.id === r.id), i.cursorStartPosition, n, o);
61
61
  case "rotate":
62
- return go(l, i, j(a.originalShape).find((s) => s.id === l.id), a.cursorStartPosition, a.center, n, o);
62
+ return fo(r, a, _(i.originalShape).find((s) => s.id === r.id), i.cursorStartPosition, i.center, n, o);
63
63
  case "resize":
64
- return vo(e, l, i, j(a.originalShape).find((s) => s.id === l.id), a, n, o, r);
64
+ return vo(e, r, a, _(i.originalShape).find((s) => s.id === r.id), i, n, o, c);
65
65
  default:
66
- return l;
66
+ return r;
67
67
  }
68
- }), n), ui = (e) => {
68
+ }), n), pa = (e) => {
69
69
  const t = new Path2D();
70
70
  return t.rect(e.x, e.y, e.width, e.height), t;
71
- }, Lt = (e) => {
71
+ }, Vt = (e) => {
72
72
  const t = new Path2D();
73
73
  return t.arc(e.x, e.y, e.radius, 0, 2 * Math.PI), t;
74
74
  }, Zt = (e) => {
75
75
  const t = new Path2D();
76
76
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t;
77
- }, Wn = (e, { brushAlgo: t }) => {
77
+ }, On = (e, { brushAlgo: t }) => {
78
78
  if (e.points.length < 1 || e.style?.strokeColor === "transparent") return;
79
- const i = e.points.flat(), a = i.map((s) => s[0]), n = i.map((s) => s[1]), o = Math.min(...a), r = Math.min(...n), l = new Path2D();
79
+ const a = e.points.flat(), i = a.map((s) => s[0]), n = a.map((s) => s[1]), o = Math.min(...i), c = Math.min(...n), r = new Path2D();
80
80
  for (const s of e.points) {
81
81
  if (!s.length) return;
82
- if (s.length === 1) l.rect(...ze(s[0], o, r, e.scaleX, e.scaleY), 1, 1);
83
- else if (l.moveTo(...ze(s[0], o, r, e.scaleX, e.scaleY)), t === "quadratic") {
84
- for (let c = 0; c < s.slice(1).length - 2; c++) {
85
- const u = ze(s[c], o, r, e.scaleX, e.scaleY), d = ze(s[c + 1], o, r, e.scaleX, e.scaleY), h = (u[0] + d[0]) / 2, f = (u[1] + d[1]) / 2;
86
- l.quadraticCurveTo(...u, h, f);
82
+ if (s.length === 1) r.rect(...Ae(s[0], o, c, e.scaleX, e.scaleY), 1, 1);
83
+ else if (r.moveTo(...Ae(s[0], o, c, e.scaleX, e.scaleY)), t === "quadratic") {
84
+ for (let l = 0; l < s.slice(1).length - 2; l++) {
85
+ const u = Ae(s[l], o, c, e.scaleX, e.scaleY), d = Ae(s[l + 1], o, c, e.scaleX, e.scaleY), h = (u[0] + d[0]) / 2, m = (u[1] + d[1]) / 2;
86
+ r.quadraticCurveTo(...u, h, m);
87
87
  }
88
- l.quadraticCurveTo(...ze(s[s.length - 2], o, r, e.scaleX, e.scaleY), ...ze(s[s.length - 1], o, r, e.scaleX, e.scaleY));
89
- } else for (const c of s.slice(1)) l.lineTo(...ze(c, o, r, e.scaleX, e.scaleY));
88
+ r.quadraticCurveTo(...Ae(s[s.length - 2], o, c, e.scaleX, e.scaleY), ...Ae(s[s.length - 1], o, c, e.scaleX, e.scaleY));
89
+ } else for (const l of s.slice(1)) r.lineTo(...Ae(l, o, c, e.scaleX, e.scaleY));
90
90
  }
91
- return l;
92
- }, On = (e, t, i, a) => {
93
- const n = (b) => (1 - b) ** 3 * e[0] + 3 * (1 - b) ** 2 * b * t[0] + 3 * (1 - b) * b ** 2 * i[0] + b ** 3 * a[0], o = (b) => (1 - b) ** 3 * e[1] + 3 * (1 - b) ** 2 * b * t[1] + 3 * (1 - b) * b ** 2 * i[1] + b ** 3 * a[1], r = (b, Z, A) => {
94
- const T = b - 2 * Z + A, S = -2 * b + 2 * Z, V = b;
95
- if (Math.abs(T) < 1e-10) {
96
- if (Math.abs(S) < 1e-10) return [];
97
- const F = -V / S;
98
- return F > 0 && F < 1 ? [F] : [];
91
+ return r;
92
+ }, Fn = (e, t, a, i) => {
93
+ const n = (S) => (1 - S) ** 3 * e[0] + 3 * (1 - S) ** 2 * S * t[0] + 3 * (1 - S) * S ** 2 * a[0] + S ** 3 * i[0], o = (S) => (1 - S) ** 3 * e[1] + 3 * (1 - S) ** 2 * S * t[1] + 3 * (1 - S) * S ** 2 * a[1] + S ** 3 * i[1], c = (S, Z, I) => {
94
+ const H = S - 2 * Z + I, y = -2 * S + 2 * Z, P = S;
95
+ if (Math.abs(H) < 1e-10) {
96
+ if (Math.abs(y) < 1e-10) return [];
97
+ const Y = -P / y;
98
+ return Y > 0 && Y < 1 ? [Y] : [];
99
99
  }
100
- const I = S * S - 4 * T * V;
101
- if (I < 0) return [];
102
- const N = Math.sqrt(I), H = (-S - N) / (2 * T), D = (-S + N) / (2 * T), U = [];
103
- return H > 0 && H < 1 && U.push(H), D > 0 && D < 1 && D !== H && U.push(D), U;
104
- }, l = e[0], s = t[0], c = i[0], u = a[0], d = e[1], h = t[1], f = i[1], g = a[1], x = r(s - l, c - s, u - c), C = r(h - d, f - h, g - f);
105
- let k = Math.min(e[0], a[0]), w = Math.max(e[0], a[0]), m = Math.min(e[1], a[1]), y = Math.max(e[1], a[1]);
106
- for (const b of x) {
107
- const Z = n(b);
108
- k = Math.min(k, Z), w = Math.max(w, Z);
100
+ const D = y * y - 4 * H * P;
101
+ if (D < 0) return [];
102
+ const A = Math.sqrt(D), E = (-y - A) / (2 * H), W = (-y + A) / (2 * H), B = [];
103
+ return E > 0 && E < 1 && B.push(E), W > 0 && W < 1 && W !== E && B.push(W), B;
104
+ }, r = e[0], s = t[0], l = a[0], u = i[0], d = e[1], h = t[1], m = a[1], p = i[1], Q = c(s - r, l - s, u - l), k = c(h - d, m - h, p - m);
105
+ let L = Math.min(e[0], i[0]), C = Math.max(e[0], i[0]), M = Math.min(e[1], i[1]), g = Math.max(e[1], i[1]);
106
+ for (const S of Q) {
107
+ const Z = n(S);
108
+ L = Math.min(L, Z), C = Math.max(C, Z);
109
109
  }
110
- for (const b of C) {
111
- const Z = o(b);
112
- m = Math.min(m, Z), y = Math.max(y, Z);
110
+ for (const S of k) {
111
+ const Z = o(S);
112
+ M = Math.min(M, Z), g = Math.max(g, Z);
113
113
  }
114
- return { minX: k, maxX: w, minY: m, maxY: y };
115
- }, pi = (e, t) => e.style?.closedPoints === 1 && t.length > 2 ? [t[t.length - 2], ...t, t[0], t[1]] : [t[0], ...t, t[t.length - 1]], gi = (e, t, i, a) => ({ cp1: [t[0] + (i[0] - e[0]) / 6, t[1] + (i[1] - e[1]) / 6], cp2: [i[0] - (a[0] - t[0]) / 6, i[1] - (a[1] - t[1]) / 6] }), en = (e) => {
114
+ return { minX: L, maxX: C, minY: M, maxY: g };
115
+ }, ga = (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]], fa = (e, t, a, i) => ({ cp1: [t[0] + (a[0] - e[0]) / 6, t[1] + (a[1] - e[1]) / 6], cp2: [a[0] - (i[0] - t[0]) / 6, a[1] - (i[1] - t[1]) / 6] }), an = (e) => {
116
116
  const t = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
117
117
  if (t.length < 2) return;
118
- const i = new Path2D();
119
- i.moveTo(...t[0]);
120
- for (const a of t.slice(1)) i.lineTo(...a);
121
- return t.length > 2 && e.style?.closedPoints === 1 && i.lineTo(...t[0]), i;
122
- }, Fn = (e) => {
118
+ const a = new Path2D();
119
+ a.moveTo(...t[0]);
120
+ for (const i of t.slice(1)) a.lineTo(...i);
121
+ return t.length > 2 && e.style?.closedPoints === 1 && a.lineTo(...t[0]), a;
122
+ }, Bn = (e) => {
123
123
  const t = new Path2D();
124
124
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t.lineTo(...e.points[2]), t.lineTo(...e.points[0]), t;
125
- }, Bn = (e, t) => ({ x: e.x - (t?.lineWidth ?? 0) / 2, y: e.y - (t?.lineWidth ?? 0) / 2, width: e.width + (t?.lineWidth ?? 0), height: e.height + (t?.lineWidth ?? 0) }), Re = (e, t, i, a = Bn) => {
126
- const n = t(e, i), o = a(n, e.style), r = [n.x + n.width / 2, n.y + n.height / 2], l = ((s, c, u = 0) => {
125
+ }, $n = (e, t) => ({ x: e.x - (t?.lineWidth ?? 0) / 2, y: e.y - (t?.lineWidth ?? 0) / 2, width: e.width + (t?.lineWidth ?? 0), height: e.height + (t?.lineWidth ?? 0) }), Re = (e, t, a, i = $n) => {
126
+ const n = t(e, a), o = i(n, e.style), c = [n.x + n.width / 2, n.y + n.height / 2], r = ((s, l, u = 0) => {
127
127
  if (u === 0) return s;
128
- const d = [[s.x, s.y], [s.x + s.width, s.y], [s.x + s.width, s.y + s.height], [s.x, s.y + s.height]].map((g) => xe({ point: g, origin: c, rotation: u })), h = Math.min(...d.map((g) => g[0])), f = Math.min(...d.map((g) => g[1]));
129
- return { x: h, y: f, width: Math.max(...d.map((g) => g[0])) - h, height: Math.max(...d.map((g) => g[1])) - f };
130
- })(o, r, e.rotation);
131
- return { borders: n, outerBorders: o, center: r, boundingBox: l };
132
- }, ut = (e, t, i, a = !1) => {
128
+ const d = [[s.x, s.y], [s.x + s.width, s.y], [s.x + s.width, s.y + s.height], [s.x, s.y + s.height]].map((p) => Ce({ point: p, origin: l, rotation: u })), h = Math.min(...d.map((p) => p[0])), m = Math.min(...d.map((p) => p[1]));
129
+ return { x: h, y: m, width: Math.max(...d.map((p) => p[0])) - h, height: Math.max(...d.map((p) => p[1])) - m };
130
+ })(o, c, e.rotation);
131
+ return { borders: n, outerBorders: o, center: c, boundingBox: r };
132
+ }, gt = (e, t, a, i = !1) => {
133
133
  const { borders: n } = t;
134
- return { border: ui(n), shapePath: e, line: a ? void 0 : Zt({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: a ? [] : [Lt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...Ba.map((o) => Lt({ x: n.x + n.width * o[0], y: n.y + n.height * o[1], radius: 7 / i.canvasSize.scaleRatio }))] };
135
- }, Oi = ({ borderStart: e, borderSize: t, vector: i, settings: a, invertedAxe: n, anchor: o }) => {
134
+ return { border: pa(n), shapePath: e, line: i ? void 0 : Zt({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / a.canvasSize.scaleRatio]] }), anchors: i ? [] : [Vt({ x: n.x + n.width / 2, y: n.y - 23 / a.canvasSize.scaleRatio, radius: 7 / a.canvasSize.scaleRatio }), ...Yi.map((o) => Vt({ x: n.x + n.width * o[0], y: n.y + n.height * o[1], radius: 7 / a.canvasSize.scaleRatio }))] };
135
+ }, Ba = ({ borderStart: e, borderSize: t, vector: a, settings: i, invertedAxe: n, anchor: o }) => {
136
136
  switch (o) {
137
137
  case 0: {
138
138
  if (n) {
139
- const l = t - 2 * a.selectionPadding;
140
- return [e + l, i - l];
139
+ const r = t - 2 * i.selectionPadding;
140
+ return [e + r, a - r];
141
141
  }
142
- const r = Math.max(2 * a.selectionPadding, t - i);
143
- return [e + t - r, r];
142
+ const c = Math.max(2 * i.selectionPadding, t - a);
143
+ return [e + t - c, c];
144
144
  }
145
145
  case 0.5:
146
146
  return [e, t];
147
147
  case 1:
148
148
  if (n) {
149
- const r = t + i;
150
- return [e + r, 2 * a.selectionPadding - r];
149
+ const c = t + a;
150
+ return [e + c, 2 * i.selectionPadding - c];
151
151
  }
152
- return [e, Math.max(2 * a.selectionPadding, t + i)];
152
+ return [e, Math.max(2 * i.selectionPadding, t + a)];
153
153
  default:
154
154
  return [0, 0];
155
155
  }
156
- }, nt = (e, t, i, a, n = !1, o = !1) => {
157
- const { center: r, borders: l } = t.computed, s = xe({ origin: r, point: e, rotation: t.rotation }), c = i.anchor[0] === 0 && s[0] >= l.x + l.width || i.anchor[0] === 1 && s[0] <= l.x, u = i.anchor[1] === 0 && s[1] >= l.y + l.height || i.anchor[1] === 1 && s[1] <= l.y, d = [_(s[0], a, i.anchor[0] === 0 && !c || i.anchor[0] === 1 && c ? a.selectionPadding : -a.selectionPadding), _(s[1], a, i.anchor[1] === 0 && !u || i.anchor[1] === 1 && u ? a.selectionPadding : -a.selectionPadding)], h = a.gridGap ? [i.anchor[0] === 0 ? l.x : i.anchor[0] === 0.5 ? l.x + l.width / 2 : l.x + l.width, i.anchor[1] === 0 ? l.y : i.anchor[1] === 0.5 ? l.y + l.height / 2 : l.y + l.height] : xe({ origin: r, point: i.cursorStartPosition, rotation: t.rotation }), f = [d[0] - h[0], d[1] - h[1]], [g, x] = Oi({ borderStart: l.x, borderSize: l.width, vector: f[0], settings: a, invertedAxe: c, anchor: i.anchor[0] }), [C, k] = Oi({ borderStart: l.y, borderSize: l.height, vector: f[1], settings: a, invertedAxe: u, anchor: i.anchor[1] }), w = n ? ((m, y, b, Z, A, T, S, V, I, N) => {
158
- const { selectionPadding: H } = N, D = (y.width - 2 * H || 1) / (y.height - 2 * H || 1), U = (A - 2 * H) / (S - 2 * H);
159
- let F, X, p, Q;
160
- return I.anchor[0] !== 0.5 && I.anchor[1] !== 0.5 ? U < D ? (X = T, Q = S, p = (S - 2 * H) * D + 2 * H, F = I.anchor[0] === 0 ? y.width - m[0] > H ? y.x + (y.width - p) : y.x + y.width - 2 * H : y.width + m[0] > H ? y.x : y.x - p + 2 * H) : (F = Z, p = A, Q = (A - 2 * H) / D + 2 * H, X = I.anchor[1] === 0 ? y.height - m[1] > H ? y.y + (y.height - Q) : y.y + y.height - 2 * H : y.height + m[1] > H ? y.y : y.y - Q + 2 * H) : I.anchor[0] !== 0.5 ? (F = Z, p = A, Q = (A - 2 * H) / D + 2 * H, X = y.y + (y.height - Q) / 2) : (X = T, Q = S, p = (S - 2 * H) * D + 2 * H, F = y.x + (y.width - p) / 2), { borderX: F, borderWidth: p, borderY: X, borderHeight: Q, center: b, originalShape: V };
161
- })(f, l, r, g, x, C, k, t, i, a) : { borderX: g, borderWidth: x, borderY: C, borderHeight: k, center: r, originalShape: t };
162
- return (({ borderX: m, borderWidth: y, borderY: b, borderHeight: Z, center: A, originalShape: T }) => {
163
- const S = [m + y / 2 - A[0], b + Z / 2 - A[1]], [V, I] = xe({ point: S, rotation: -(T.rotation ?? 0) });
164
- return { borderX: Xe(m + V - S[0]), borderWidth: Xe(y), borderY: Xe(b + I - S[1]), borderHeight: Xe(Z) };
165
- })(o ? ((m, y, b, Z) => {
166
- const A = y.x + y.width / 2, T = y.y + y.height / 2, S = b ? 2 * m.borderWidth + y.width : Math.abs(y.width + 2 * (m.borderWidth - y.width)), V = Z ? 2 * m.borderHeight + y.height : Math.abs(y.height + 2 * (m.borderHeight - y.height));
167
- return { ...m, borderHeight: V, borderWidth: S, borderX: A - S / 2, borderY: T - V / 2 };
168
- })(w, l, c, u) : w);
169
- }, tn = (e, t) => Re(e, vi, t), Ht = (e, t, i = !1) => {
170
- const a = ui(e), n = tn(e, t);
171
- return { ...e, path: a, computed: n, selection: ut(a, n, t, i) };
172
- }, $n = Ht, an = (e, t, i, a = !1, n = 0, o = 0) => {
173
- const r = { toolId: e.id, type: e.type, id: ye(`${e.type}_`), x: t[0], y: t[1], width: n, height: o, style: { opacity: e.settings.opacity.default, fillColor: e.settings.fillColor.default, strokeColor: e.settings.strokeColor.default, lineWidth: e.settings.lineWidth.default, lineDash: e.settings.lineDash.default } };
174
- return Ht(r, i, a);
175
- }, Yn = (e, t) => {
156
+ }, ot = (e, t, a, i, n = !1, o = !1) => {
157
+ const { center: c, borders: r } = t.computed, s = Ce({ origin: c, point: e, rotation: t.rotation }), l = a.anchor[0] === 0 && s[0] >= r.x + r.width || a.anchor[0] === 1 && s[0] <= r.x, u = a.anchor[1] === 0 && s[1] >= r.y + r.height || a.anchor[1] === 1 && s[1] <= r.y, d = [q(s[0], i, a.anchor[0] === 0 && !l || a.anchor[0] === 1 && l ? i.selectionPadding : -i.selectionPadding), q(s[1], i, a.anchor[1] === 0 && !u || a.anchor[1] === 1 && u ? i.selectionPadding : -i.selectionPadding)], h = i.gridGap ? [a.anchor[0] === 0 ? r.x : a.anchor[0] === 0.5 ? r.x + r.width / 2 : r.x + r.width, a.anchor[1] === 0 ? r.y : a.anchor[1] === 0.5 ? r.y + r.height / 2 : r.y + r.height] : Ce({ origin: c, point: a.cursorStartPosition, rotation: t.rotation }), m = [d[0] - h[0], d[1] - h[1]], [p, Q] = Ba({ borderStart: r.x, borderSize: r.width, vector: m[0], settings: i, invertedAxe: l, anchor: a.anchor[0] }), [k, L] = Ba({ borderStart: r.y, borderSize: r.height, vector: m[1], settings: i, invertedAxe: u, anchor: a.anchor[1] }), C = n ? ((M, g, S, Z, I, H, y, P, D, A) => {
158
+ const { selectionPadding: E } = A, W = (g.width - 2 * E || 1) / (g.height - 2 * E || 1), B = (I - 2 * E) / (y - 2 * E);
159
+ let Y, j, V, v;
160
+ return D.anchor[0] !== 0.5 && D.anchor[1] !== 0.5 ? B < W ? (j = H, v = y, V = (y - 2 * E) * W + 2 * E, Y = D.anchor[0] === 0 ? g.width - M[0] > E ? g.x + (g.width - V) : g.x + g.width - 2 * E : g.width + M[0] > E ? g.x : g.x - V + 2 * E) : (Y = Z, V = I, v = (I - 2 * E) / W + 2 * E, j = D.anchor[1] === 0 ? g.height - M[1] > E ? g.y + (g.height - v) : g.y + g.height - 2 * E : g.height + M[1] > E ? g.y : g.y - v + 2 * E) : D.anchor[0] !== 0.5 ? (Y = Z, V = I, v = (I - 2 * E) / W + 2 * E, j = g.y + (g.height - v) / 2) : (j = H, v = y, V = (y - 2 * E) * W + 2 * E, Y = g.x + (g.width - V) / 2), { borderX: Y, borderWidth: V, borderY: j, borderHeight: v, center: S, originalShape: P };
161
+ })(m, r, c, p, Q, k, L, t, a, i) : { borderX: p, borderWidth: Q, borderY: k, borderHeight: L, center: c, originalShape: t };
162
+ return (({ borderX: M, borderWidth: g, borderY: S, borderHeight: Z, center: I, originalShape: H }) => {
163
+ const y = [M + g / 2 - I[0], S + Z / 2 - I[1]], [P, D] = Ce({ point: y, rotation: -(H.rotation ?? 0) });
164
+ return { borderX: Ge(M + P - y[0]), borderWidth: Ge(g), borderY: Ge(S + D - y[1]), borderHeight: Ge(Z) };
165
+ })(o ? ((M, g, S, Z) => {
166
+ const I = g.x + g.width / 2, H = g.y + g.height / 2, y = S ? 2 * M.borderWidth + g.width : Math.abs(g.width + 2 * (M.borderWidth - g.width)), P = Z ? 2 * M.borderHeight + g.height : Math.abs(g.height + 2 * (M.borderHeight - g.height));
167
+ return { ...M, borderHeight: P, borderWidth: y, borderX: I - y / 2, borderY: H - P / 2 };
168
+ })(C, r, l, u) : C);
169
+ }, nn = (e, t) => Re(e, va, t), Tt = (e, t, a = !1) => {
170
+ const i = pa(e), n = nn(e, t);
171
+ return { ...e, path: i, computed: n, selection: gt(i, n, t, a) };
172
+ }, Yn = Tt, on = (e, t, a, i = !1, n = 0, o = 0) => {
173
+ const c = { toolId: e.id, type: e.type, id: ue(`${e.type}_`), x: t[0], y: t[1], width: n, height: o, style: { opacity: e.settings.opacity.default, fillColor: e.settings.fillColor.default, strokeColor: e.settings.strokeColor.default, lineWidth: e.settings.lineWidth.default, lineDash: e.settings.lineDash.default } };
174
+ return Tt(c, a, i);
175
+ }, Un = (e, t) => {
176
176
  e.globalAlpha !== 0 && t.path && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
177
- }, vi = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), Fi = (e, t, i, [a, n] = [!1, !1]) => {
178
- const o = e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (a ? 0 : i.width) : i.x + (a ? i.width : 0), r = e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (n ? 0 : i.height) : i.y + (n ? i.height : 0);
179
- return Gn([o, r], i.rotation ?? 0, t);
180
- }, Bi = (e, t, i, a, n, o, r, l) => {
177
+ }, va = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), $a = (e, t, a, [i, n] = [!1, !1]) => {
178
+ const o = e[0] === 0.5 ? a.x + a.width / 2 : e[0] === 0 ? a.x + (i ? 0 : a.width) : a.x + (i ? a.width : 0), c = e[1] === 0.5 ? a.y + a.height / 2 : e[1] === 0 ? a.y + (n ? 0 : a.height) : a.y + (n ? a.height : 0);
179
+ return qn([o, c], a.rotation ?? 0, t);
180
+ }, Ya = (e, t, a, i, n, o, c, r) => {
181
181
  let s = !1;
182
182
  if (n) {
183
- s = mt(e, n, i, a, !0, o ? 20 : void 0);
184
- const u = ((d, h, f) => {
185
- if (d.mode === "translate") return { mode: "translate", cursorStartPosition: f, originalShape: h, dateStart: Date.now() };
183
+ s = ht(e, n, a, i, !0, o ? 20 : void 0);
184
+ const u = ((d, h, m) => {
185
+ if (d.mode === "translate") return { mode: "translate", cursorStartPosition: m, originalShape: h, hasBeenDuplicated: !1, dateStart: Date.now() };
186
186
  if (d.mode === "rotate") {
187
- const { center: g } = h.computed;
188
- return { mode: "rotate", cursorStartPosition: f, originalShape: h, center: [g[0], g[1]] };
187
+ const { center: p } = h.computed;
188
+ return { mode: "rotate", cursorStartPosition: m, originalShape: h, center: [p[0], p[1]] };
189
189
  }
190
- return d.mode === "resize" ? { mode: "resize", cursorStartPosition: f, originalShape: h, anchor: d.anchor } : void 0;
191
- })(s || { mode: "default" }, n, i);
190
+ return d.mode === "resize" ? { mode: "resize", cursorStartPosition: m, originalShape: h, anchor: d.anchor } : void 0;
191
+ })(s || { mode: "default" }, n, a);
192
192
  if (u?.mode === "resize" || u?.mode === "rotate") return { shape: n, mode: u };
193
193
  }
194
- const c = t.find((u) => j(n).find((d) => u.id === d?.id) ? s && l ? mt(e, u, i, a, !0, o ? 20 : void 0) : !!s : !!rn(e, u, i, a));
195
- if (c) {
196
- if (l) {
197
- const d = j(n).find((h) => h.id === c?.id) ? be(Xn(n, c), a) : be(nn(n, [c]), a);
198
- return { shape: d, mode: { mode: "translate", cursorStartPosition: i, dateStart: Date.now(), originalShape: d } };
194
+ const l = t.find((u) => _(n).find((d) => u.id === d?.id) ? s && r ? ht(e, u, a, i, !0, o ? 20 : void 0) : !!s : !!cn(e, u, a, i));
195
+ if (l) {
196
+ if (r) {
197
+ const d = _(n).find((h) => h.id === l?.id) ? we(Gn(n, l), i) : we(sn(n, [l]), i);
198
+ return { shape: d, mode: { mode: "translate", cursorStartPosition: a, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: d } };
199
199
  }
200
- const u = j(n).find((d) => d.id === c?.id) ? n : be([c], a);
201
- return { shape: u, mode: { mode: "translate", cursorStartPosition: i, dateStart: Date.now(), originalShape: u } };
200
+ const u = _(n).find((d) => d.id === l?.id) ? n : we([l], i);
201
+ return { shape: u, mode: { mode: "translate", cursorStartPosition: a, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: u } };
202
202
  }
203
- return l ? { shape: n, mode: { mode: r ? "selectionFrame" : "default" } } : { shape: void 0, mode: { mode: r ? "selectionFrame" : "default" } };
204
- }, Un = (e, t, i = !0) => {
205
- const a = [[e.x, e.y], [e.x + e.width, e.y], [e.x + e.width, e.y + e.height], [e.x, e.y + e.height]];
206
- if (!i) return a;
203
+ return r ? { shape: n, mode: { mode: c ? "selectionFrame" : "default" } } : { shape: void 0, mode: { mode: c ? "selectionFrame" : "default" } };
204
+ }, Xn = (e, t, a = !0) => {
205
+ const i = [[e.x, e.y], [e.x + e.width, e.y], [e.x + e.width, e.y + e.height], [e.x, e.y + e.height]];
206
+ if (!a) return i;
207
207
  const n = [e.x + e.width / 2, e.y + e.height / 2];
208
- return a.map((o) => xe({ point: [o[0], o[1]], origin: n, rotation: t }));
209
- }, be = (e, t) => {
208
+ return i.map((o) => Ce({ point: [o[0], o[1]], origin: n, rotation: t }));
209
+ }, we = (e, t) => {
210
210
  if (!e.length) return;
211
211
  if (e.length === 1) return e[0];
212
- let i = Number.POSITIVE_INFINITY, a = Number.POSITIVE_INFINITY, n = Number.NEGATIVE_INFINITY, o = Number.NEGATIVE_INFINITY;
213
- const r = e.some((u) => u.rotation !== e[0].rotation), l = r ? 0 : e[0]?.rotation ?? 0;
212
+ let a = Number.POSITIVE_INFINITY, i = Number.POSITIVE_INFINITY, n = Number.NEGATIVE_INFINITY, o = Number.NEGATIVE_INFINITY;
213
+ const c = e.some((u) => u.rotation !== e[0].rotation), r = c ? 0 : e[0]?.rotation ?? 0;
214
214
  for (const u of e) {
215
- const { borders: d } = u.computed, h = Un(d, u.rotation ?? 0, r);
216
- i = Math.min(h[0][0], h[1][0], h[2][0], h[3][0], i), n = Math.max(h[0][0], h[1][0], h[2][0], h[3][0], n), a = Math.min(h[0][1], h[1][1], h[2][1], h[3][1], a), o = Math.max(h[0][1], h[1][1], h[2][1], h[3][1], o);
215
+ const { borders: d } = u.computed, h = Xn(d, u.rotation ?? 0, c);
216
+ a = Math.min(h[0][0], h[1][0], h[2][0], h[3][0], a), n = Math.max(h[0][0], h[1][0], h[2][0], h[3][0], n), i = Math.min(h[0][1], h[1][1], h[2][1], h[3][1], i), o = Math.max(h[0][1], h[1][1], h[2][1], h[3][1], o);
217
217
  }
218
- const s = an({ id: "test", type: "rect", settings: Ha }, [i, a], t, !0, n - i, o - a), c = e.slice(1).reduce((u, d) => {
219
- const h = d.style ?? {}, f = {};
220
- for (const g in h) u[g] !== void 0 && h[g] !== void 0 && u[g] === h[g] && (f[g] = u[g]);
221
- return f;
218
+ const s = on({ id: "test", type: "rect", settings: zi }, [a, i], t, !0, n - a, o - i), l = e.slice(1).reduce((u, d) => {
219
+ const h = d.style ?? {}, m = {};
220
+ for (const p in h) u[p] !== void 0 && h[p] !== void 0 && u[p] === h[p] && (m[p] = u[p]);
221
+ return m;
222
222
  }, e[0].style ?? {});
223
- return { id: e.map((u) => u.id).join("-"), type: "group", shapes: e, rotation: l, visible: !0, locked: !1, selection: s.selection, x: s.x, y: s.y, width: s.width, height: s.height, style: c, computed: s.computed };
224
- }, $i = (e, t) => (i) => {
225
- if (!i) return;
226
- const a = i.type === "group" ? i.shapes.map((n) => e(n, t)) : [e(i, t)];
227
- return be(a, t);
228
- }, j = (e) => e ? e.type === "group" ? e.shapes : [e] : [], nn = (e, t) => {
229
- const i = j(e);
230
- return [.../* @__PURE__ */ new Set([...i, ...t])];
231
- }, Xn = (e, t) => j(e).filter((i) => i.id !== t.id), on = (e) => {
232
- const { clientX: t = 0, clientY: i = 0 } = "touches" in e && e.touches[0] ? e.touches[0] : "changedTouches" in e && e.changedTouches[0] ? e.changedTouches[0] : "clientX" in e ? e : {};
233
- return { clientX: t, clientY: i };
234
- }, sn = (e, t, i) => {
235
- const { clientX: a, clientY: n } = on(e), o = t.getBoundingClientRect();
236
- return [(a - o.left) / i.scaleRatio, (n - o.top) / i.scaleRatio];
237
- }, ot = (e, t, i) => {
238
- const { clientX: a, clientY: n } = on(e), o = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
239
- return [(a - o.left) * (i.canvasSize.width / o.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (n - o.top) * (i.canvasSize.height / o.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
240
- }, st = (e) => "touches" in e, Ae = (e, t, [i, a]) => xe({ origin: [i, a], point: e, rotation: t }), Gn = (e, t, [i, a]) => xe({ origin: [i, a], point: e, rotation: -t }), xt = (e, t, i) => i ? Ka(e, { x: t[0], y: t[1], radius: i }) : ((a, n) => n[0] >= a.x && n[0] <= a.x + a.width && n[1] >= a.y && n[1] <= a.y + a.height)(e, t), mt = (e, t, i, a, n = !1, o = 0) => {
223
+ return { id: e.map((u) => u.id).join("-"), type: "group", shapes: e, rotation: r, visible: !0, locked: !1, selection: s.selection, x: s.x, y: s.y, width: s.width, height: s.height, style: l, computed: s.computed };
224
+ }, Ua = (e, t) => (a) => {
225
+ if (!a) return;
226
+ const i = a.type === "group" ? a.shapes.map((n) => e(n, t)) : [e(a, t)];
227
+ return we(i, t);
228
+ }, _ = (e) => e ? e.type === "group" ? e.shapes : [e] : [], sn = (e, t) => {
229
+ const a = _(e);
230
+ return [.../* @__PURE__ */ new Set([...a, ...t])];
231
+ }, Gn = (e, t) => _(e).filter((a) => a.id !== t.id), rn = (e) => {
232
+ const { clientX: t = 0, clientY: a = 0 } = "touches" in e && e.touches[0] ? e.touches[0] : "changedTouches" in e && e.changedTouches[0] ? e.changedTouches[0] : "clientX" in e ? e : {};
233
+ return { clientX: t, clientY: a };
234
+ }, ln = (e, t, a) => {
235
+ const { clientX: i, clientY: n } = rn(e), o = t.getBoundingClientRect();
236
+ return [(i - o.left) / a.scaleRatio, (n - o.top) / a.scaleRatio];
237
+ }, st = (e, t, a) => {
238
+ const { clientX: i, clientY: n } = rn(e), o = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: a.canvasSize.width, height: a.canvasSize.height };
239
+ return [(i - o.left) * (a.canvasSize.width / o.width) / a.canvasSize.scaleRatio - a.canvasOffset[0], (n - o.top) * (a.canvasSize.height / o.height) / a.canvasSize.scaleRatio - a.canvasOffset[1]];
240
+ }, rt = (e) => "touches" in e, Ee = (e, t, [a, i]) => Ce({ origin: [a, i], point: e, rotation: t }), qn = (e, t, [a, i]) => Ce({ origin: [a, i], point: e, rotation: -t }), Ct = (e, t, a) => a ? en(e, { x: t[0], y: t[1], radius: a }) : ((i, n) => n[0] >= i.x && n[0] <= i.x + i.width && n[1] >= i.y && n[1] <= i.y + i.height)(e, t), ht = (e, t, a, i, n = !1, o = 0) => {
241
241
  if (t.locked) return !1;
242
- const { canvasSize: { scaleRatio: r } } = a, { borders: l, center: s } = t.computed, c = Ae(i, t.rotation ?? 0, s), u = j(t);
242
+ const { canvasSize: { scaleRatio: c } } = i, { borders: r, center: s } = t.computed, l = Ee(a, t.rotation ?? 0, s), u = _(t);
243
243
  if (n) {
244
244
  if (u.length !== 1 || u[0]?.type !== "line" && u[0]?.type !== "polygon" && u[0]?.type !== "curve") {
245
245
  if (u.length === 1) {
246
- if (xt({ x: l.x + l.width / 2 - 7 / r, y: l.y - et / r - 16 / r, width: et / r, height: et / r }, c, o)) return { mode: "rotate" };
247
- for (const d of Ba) if (xt({ x: l.x + l.width * d[0] - 7 / r, y: l.y + l.height * d[1] - 7 / r, width: et / r, height: et / r }, c, o)) return { mode: "resize", anchor: d };
246
+ if (Ct({ x: r.x + r.width / 2 - 7 / c, y: r.y - tt / c - 16 / c, width: tt / c, height: tt / c }, l, o)) return { mode: "rotate" };
247
+ for (const d of Yi) if (Ct({ x: r.x + r.width * d[0] - 7 / c, y: r.y + r.height * d[1] - 7 / c, width: tt / c, height: tt / c }, l, o)) return { mode: "resize", anchor: d };
248
248
  }
249
- } else for (let d = 0; d < u[0].points.length; d++) if (xt({ x: u[0].points[d][0] - 7 / r, y: u[0].points[d][1] - 7 / r, width: et / r, height: et / r }, c, o)) return { mode: "resize", anchor: d };
249
+ } else for (let d = 0; d < u[0].points.length; d++) if (Ct({ x: u[0].points[d][0] - 7 / c, y: u[0].points[d][1] - 7 / c, width: tt / c, height: tt / c }, l, o)) return { mode: "resize", anchor: d };
250
250
  }
251
- return (xt(l, c, o) || !!(t.type === "curve" && "path" in t && t.path && e.isPointInPath(t.path, c[0], c[1]))) && { mode: "translate" };
252
- }, Yi = (e, t, i, a, n = 50) => {
251
+ return (Ct(r, l, o) || !!(t.type === "curve" && "path" in t && t.path && e.isPointInPath(t.path, l[0], l[1]))) && { mode: "translate" };
252
+ }, Xa = (e, t, a, i, n = 50) => {
253
253
  if (t.locked || t.points.length < 2) return !1;
254
- const { center: o } = t.computed, r = Ae(i, t.rotation ?? 0, o);
255
- e.lineWidth = (t.style?.lineWidth ?? 0) + n / a.canvasZoom;
256
- const l = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
257
- for (let s = 0; s < l.length - 1; s++) {
258
- const c = Zt({ points: [l[s], l[s + 1]] });
259
- if (e.isPointInStroke(c, r[0], r[1])) return { lineIndex: s };
254
+ const { center: o } = t.computed, c = Ee(a, t.rotation ?? 0, o);
255
+ e.lineWidth = (t.style?.lineWidth ?? 0) + n / i.canvasZoom;
256
+ const r = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
257
+ for (let s = 0; s < r.length - 1; s++) {
258
+ const l = Zt({ points: [r[s], r[s + 1]] });
259
+ if (e.isPointInStroke(l, c[0], c[1])) return { lineIndex: s };
260
260
  }
261
261
  return !1;
262
- }, rn = (e, t, i, a) => {
262
+ }, cn = (e, t, a, i) => {
263
263
  if (t.locked) return !1;
264
- const { center: n } = t.computed, o = Ae(i, t.rotation ?? 0, n);
265
- return "path" in t && t.path ? t.style?.fillColor && t.style?.fillColor !== "transparent" ? !!e.isPointInPath(t.path, o[0], o[1]) && { mode: "translate" } : (e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / a.canvasZoom, !!e.isPointInStroke(t.path, o[0], o[1]) && { mode: "translate" }) : mt(e, t, i, a, !1);
264
+ const { center: n } = t.computed, o = Ee(a, t.rotation ?? 0, n);
265
+ return "path" in t && t.path ? t.style?.fillColor && t.style?.fillColor !== "transparent" ? !!e.isPointInPath(t.path, o[0], o[1]) && { mode: "translate" } : (e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / i.canvasZoom, !!e.isPointInStroke(t.path, o[0], o[1]) && { mode: "translate" }) : ht(e, t, a, i, !1);
266
266
  };
267
- function ii(e, t) {
268
- const i = Math.max(e.x, t.x), a = Math.max(e.y, t.y), n = Math.min(e.x + (e.width || 1), t.x + (t.width || 1)), o = Math.min(e.y + (e.height || 1), t.y + (t.height || 1));
269
- if (i < n && a < o) return { x: i, y: a, width: n - i, height: o - a };
267
+ function ia(e, t) {
268
+ const a = Math.max(e.x, t.x), i = Math.max(e.y, t.y), n = Math.min(e.x + (e.width || 1), t.x + (t.width || 1)), o = Math.min(e.y + (e.height || 1), t.y + (t.height || 1));
269
+ if (a < n && i < o) return { x: a, y: i, width: n - a, height: o - i };
270
270
  }
271
- const Ui = ({ ctx: e, path: t, rect: i, offset: a, checkFill: n }) => {
272
- for (let o = 0; o < a; o += a / 2) for (let r = 0; r < a; r += a / 2) for (let l = o + i.x; l < i.x + i.width; l += a) for (let s = r + i.y; s < i.y + i.height; s += a) if (n ? e.isPointInPath(t, l, s) : e.isPointInStroke(t, l, s)) return !0;
271
+ const Ga = ({ ctx: e, path: t, rect: a, offset: i, checkFill: n }) => {
272
+ for (let o = 0; o < i; o += i / 2) for (let c = 0; c < i; c += i / 2) for (let r = o + a.x; r < a.x + a.width; r += i) for (let s = c + a.y; s < a.y + a.height; s += i) if (n ? e.isPointInPath(t, r, s) : e.isPointInStroke(t, r, s)) return !0;
273
273
  return !1;
274
- }, fi = (e, t, i, a) => ({ border: ui(i.borders), shapePath: e, anchors: [...t.points.map((n) => Lt({ x: n[0], y: n[1], radius: 7 / a.canvasSize.scaleRatio }))] }), Me = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], ai = ({ size: e, zoom: t, newOffset: [i, a], canvasSize: n }) => e === "infinite" ? { zoom: t, offset: [i, a] } : t < 1 ? { zoom: t, offset: [-(n.realWidth - n.realWidth / t) / 2, -(n.realHeight - n.realHeight / t) / 2] } : { zoom: t, offset: [De(i, n.realWidth / t - n.realWidth, 0), De(a, n.realHeight / t - n.realHeight, 0)] }, ni = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: a, zoom: n, centerPoint: o }) => {
275
- const r = e === "fixed" && n < 1 ? [t.realWidth / 2, t.realHeight / 2] : o, l = i[0] - (r[0] / a - r[0] / n), s = i[1] - (r[1] / a - r[1] / n);
276
- return { offset: e === "infinite" ? [l, s] : n < 1 ? [-(t.realWidth - t.realWidth / n) / 2, -(t.realHeight - t.realHeight / n) / 2] : [De(l, t.realWidth / n - t.realWidth, 0), De(s, t.realHeight / n - t.realHeight, 0)], zoom: n };
277
- }, ln = (e) => {
278
- const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: a }, canvasZoom: n, canvasOffset: o } = e;
279
- return { x: o[0] * n * a, y: o[1] * n * a, width: t * n, height: i * n };
280
- }, cn = (e, t) => {
281
- const { canvasZoom: i, size: a } = t;
282
- if (a !== "fixed" || i >= 1) return;
283
- const n = ln(t);
274
+ }, ma = (e, t, a, i) => ({ border: pa(a.borders), shapePath: e, anchors: [...t.points.map((n) => Vt({ x: n[0], y: n[1], radius: 7 / i.canvasSize.scaleRatio }))] }), Pe = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], na = ({ size: e, zoom: t, newOffset: [a, i], canvasSize: n }) => e === "infinite" ? { zoom: t, offset: [a, i] } : t < 1 ? { zoom: t, offset: [-(n.realWidth - n.realWidth / t) / 2, -(n.realHeight - n.realHeight / t) / 2] } : { zoom: t, offset: [Ne(a, n.realWidth / t - n.realWidth, 0), Ne(i, n.realHeight / t - n.realHeight, 0)] }, oa = ({ size: e, canvasSize: t, currentOffset: a, currentZoom: i, zoom: n, centerPoint: o }) => {
275
+ const c = e === "fixed" && n < 1 ? [t.realWidth / 2, t.realHeight / 2] : o, r = a[0] - (c[0] / i - c[0] / n), s = a[1] - (c[1] / i - c[1] / n);
276
+ return { offset: e === "infinite" ? [r, s] : n < 1 ? [-(t.realWidth - t.realWidth / n) / 2, -(t.realHeight - t.realHeight / n) / 2] : [Ne(r, t.realWidth / n - t.realWidth, 0), Ne(s, t.realHeight / n - t.realHeight, 0)], zoom: n };
277
+ }, dn = (e) => {
278
+ const { canvasSize: { width: t, height: a, scaleRatioWithNoZoom: i }, canvasZoom: n, canvasOffset: o } = e;
279
+ return { x: o[0] * n * i, y: o[1] * n * i, width: t * n, height: a * n };
280
+ }, hn = (e, t) => {
281
+ const { canvasZoom: a, size: i } = t;
282
+ if (i !== "fixed" || a >= 1) return;
283
+ const n = dn(t);
284
284
  e.beginPath(), e.rect(n.x, n.y, n.width, n.height), e.closePath(), e.clip();
285
- }, ft = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, qn = (e, t) => ({ x: e.x - e.radius - t.selectionPadding, width: 2 * (e.radius + t.selectionPadding), y: e.y - e.radius - t.selectionPadding, height: 2 * (e.radius + t.selectionPadding) }), dn = (e, t) => Re(e, qn, t), Tt = (e, t) => {
286
- const i = Lt(e), a = dn(e, t);
287
- return { ...e, path: i, selection: ut(i, a, t), computed: a };
288
- }, _n = Tt, hn = (e, t) => Re(e, mi, t), pt = (e, t) => {
289
- const i = en(e), a = hn(e, t);
290
- return { ...e, path: i, selection: fi(i, e, a, t), computed: a };
291
- }, jn = pt, mi = (e, t) => {
292
- const i = Math.min(...e.points.map((o) => o[0])) - t.selectionPadding, a = Math.max(...e.points.map((o) => o[0])) + t.selectionPadding, n = Math.min(...e.points.map((o) => o[1])) - t.selectionPadding;
293
- return { x: i, width: a - i, y: n, height: Math.max(...e.points.map((o) => o[1])) + t.selectionPadding - n };
294
- }, Kn = (e, t, i, a) => {
285
+ }, yt = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, _n = (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) }), un = (e, t) => Re(e, _n, t), zt = (e, t) => {
286
+ const a = Vt(e), i = un(e, t);
287
+ return { ...e, path: a, selection: gt(a, i, t), computed: i };
288
+ }, jn = zt, pn = (e, t) => Re(e, ya, t), ft = (e, t) => {
289
+ const a = an(e), i = pn(e, t);
290
+ return { ...e, path: a, selection: ma(a, e, i, t), computed: i };
291
+ }, Kn = ft, ya = (e, t) => {
292
+ const a = Math.min(...e.points.map((o) => o[0])) - t.selectionPadding, i = Math.max(...e.points.map((o) => o[0])) + t.selectionPadding, n = Math.min(...e.points.map((o) => o[1])) - t.selectionPadding;
293
+ return { x: a, width: i - a, y: n, height: Math.max(...e.points.map((o) => o[1])) + t.selectionPadding - n };
294
+ }, Jn = (e, t, a, i) => {
295
295
  if (t < 0 || t > e.points.length - 1) return e;
296
- const n = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
297
- return pt({ ...e, points: n }, a);
298
- }, Xi = (e, t, i, a = !1) => {
299
- const n = [_(t[0], i), _(t[1], i)], o = Ae(n, e.rotation ?? 0, e.computed.center), r = { ...e, points: a ? e.points : [...e.points, o], tempPoint: a ? o : void 0 };
300
- return pt(r, i);
301
- }, Jn = (e, t) => {
302
- const i = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
303
- if (i.length < 2) {
304
- const s = i[0] ?? [0, 0], c = t.selectionPadding;
305
- return { x: s[0] - c, y: s[1] - c, width: 2 * c, height: 2 * c };
296
+ const n = [...e.points.slice(0, t + 1), a, ...e.points.slice(t + 1)];
297
+ return ft({ ...e, points: n }, i);
298
+ }, qa = (e, t, a, i = !1) => {
299
+ const n = [q(t[0], a), q(t[1], a)], o = Ee(n, e.rotation ?? 0, e.computed.center), c = { ...e, points: i ? e.points : [...e.points, o], tempPoint: i ? o : void 0 };
300
+ return ft(c, a);
301
+ }, eo = (e, t) => {
302
+ const a = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
303
+ if (a.length < 2) {
304
+ const s = a[0] ?? [0, 0], l = t.selectionPadding;
305
+ return { x: s[0] - l, y: s[1] - l, width: 2 * l, height: 2 * l };
306
306
  }
307
- if (i.length < 3) return mi({ ...e, points: i }, t);
308
- const a = pi(e, i);
309
- let n = Number.POSITIVE_INFINITY, o = Number.NEGATIVE_INFINITY, r = Number.POSITIVE_INFINITY, l = Number.NEGATIVE_INFINITY;
310
- for (let s = 1; s < a.length - 2; s++) {
311
- const c = a[s - 1], u = a[s], d = a[s + 1], h = a[s + 2], { cp1: f, cp2: g } = gi(c, u, d, h), x = On(u, f, g, d);
312
- n = Math.min(n, x.minX), o = Math.max(o, x.maxX), r = Math.min(r, x.minY), l = Math.max(l, x.maxY);
307
+ if (a.length < 3) return ya({ ...e, points: a }, t);
308
+ const i = ga(e, a);
309
+ let n = Number.POSITIVE_INFINITY, o = Number.NEGATIVE_INFINITY, c = Number.POSITIVE_INFINITY, r = Number.NEGATIVE_INFINITY;
310
+ for (let s = 1; s < i.length - 2; s++) {
311
+ const l = i[s - 1], u = i[s], d = i[s + 1], h = i[s + 2], { cp1: m, cp2: p } = fa(l, u, d, h), Q = Fn(u, m, p, d);
312
+ n = Math.min(n, Q.minX), o = Math.max(o, Q.maxX), c = Math.min(c, Q.minY), r = Math.max(r, Q.maxY);
313
313
  }
314
- return vi({ x: n, y: r, width: o - n, height: l - r }, t);
315
- }, un = (e, t) => Re(e, Jn, t), gt = (e, t) => {
316
- const i = ((n) => {
314
+ return va({ x: n, y: c, width: o - n, height: r - c }, t);
315
+ }, gn = (e, t) => Re(e, eo, t), vt = (e, t) => {
316
+ const a = ((n) => {
317
317
  const o = n.tempPoint ? [...n.points, n.tempPoint] : n.points;
318
318
  if (o.length < 2) return;
319
- if (o.length < 3) return en(n);
320
- const r = n.style?.closedPoints === 1 && o.length > 2, l = new Path2D();
321
- l.moveTo(...o[0]);
322
- const s = pi(n, o);
323
- for (let c = 1; c < s.length - 2; c++) {
324
- const u = s[c - 1], d = s[c], h = s[c + 1], f = s[c + 2], { cp1: g, cp2: x } = gi(u, d, h, f);
325
- l.bezierCurveTo(g[0], g[1], x[0], x[1], h[0], h[1]);
319
+ if (o.length < 3) return an(n);
320
+ const c = n.style?.closedPoints === 1 && o.length > 2, r = new Path2D();
321
+ r.moveTo(...o[0]);
322
+ const s = ga(n, o);
323
+ for (let l = 1; l < s.length - 2; l++) {
324
+ const u = s[l - 1], d = s[l], h = s[l + 1], m = s[l + 2], { cp1: p, cp2: Q } = fa(u, d, h, m);
325
+ r.bezierCurveTo(p[0], p[1], Q[0], Q[1], h[0], h[1]);
326
326
  }
327
- return r && l.closePath(), l;
328
- })(e), a = un(e, t);
329
- return { ...e, path: i, selection: fi(i, e, a, t), computed: a };
330
- }, eo = gt, to = (e, t, i, a) => {
327
+ return c && r.closePath(), r;
328
+ })(e), i = gn(e, t);
329
+ return { ...e, path: a, selection: ma(a, e, i, t), computed: i };
330
+ }, to = vt, ao = (e, t, a, i) => {
331
331
  if (t < 0 || t > e.points.length - 1) return e;
332
- const n = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
333
- return gt({ ...e, points: n }, a);
334
- }, Gi = (e, t, i, a = !1) => {
335
- const n = [_(t[0], i), _(t[1], i)], o = e.computed.center, r = Ae(n, e.rotation ?? 0, o), l = { ...e, points: a ? e.points : [...e.points, r], tempPoint: a ? r : void 0 };
336
- return gt(l, i);
337
- }, io = (e, t) => ({ x: e.x - e.radiusX - t.selectionPadding, width: 2 * (e.radiusX + t.selectionPadding), y: e.y - e.radiusY - t.selectionPadding, height: 2 * (e.radiusY + t.selectionPadding) }), pn = (e, t) => Re(e, io, t), zt = (e, t) => {
338
- const i = ((n) => {
332
+ const n = [...e.points.slice(0, t + 1), a, ...e.points.slice(t + 1)];
333
+ return vt({ ...e, points: n }, i);
334
+ }, _a = (e, t, a, i = !1) => {
335
+ const n = [q(t[0], a), q(t[1], a)], o = e.computed.center, c = Ee(n, e.rotation ?? 0, o), r = { ...e, points: i ? e.points : [...e.points, c], tempPoint: i ? c : void 0 };
336
+ return vt(r, a);
337
+ }, io = (e, t) => ({ x: e.x - e.radiusX - t.selectionPadding, width: 2 * (e.radiusX + t.selectionPadding), y: e.y - e.radiusY - t.selectionPadding, height: 2 * (e.radiusY + t.selectionPadding) }), fn = (e, t) => Re(e, io, t), At = (e, t) => {
338
+ const a = ((n) => {
339
339
  const o = new Path2D();
340
340
  return o.ellipse(n.x, n.y, n.radiusX, n.radiusY, 0, 0, 2 * Math.PI), o;
341
- })(e), a = pn(e, t);
342
- return { ...e, path: i, selection: ut(i, a, t), computed: a };
343
- }, ao = zt, no = (e, t) => Re(e, mi, t), qi = (e, t) => ((i, a) => ({ ...i, path: Fn(i), computed: no(i, a) }))({ ...e, id: ye("triangle_"), type: "triangle" }, t), oo = (e, t) => {
341
+ })(e), i = fn(e, t);
342
+ return { ...e, path: a, selection: gt(a, i, t), computed: i };
343
+ }, no = At, oo = (e, t) => Re(e, ya, t), ja = (e, t) => ((a, i) => ({ ...a, path: Bn(a), computed: oo(a, i) }))({ ...e, id: ue("triangle_"), type: "triangle" }, t), so = (e, t) => {
344
344
  e.globalAlpha !== 0 && t.path && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
345
- }, so = (e, t) => ({ x: Math.min(e.points[0][0], e.points[1][0]) - t.selectionPadding, width: Math.abs(e.points[0][0] - e.points[1][0]) + 2 * t.selectionPadding, y: Math.min(e.points[0][1], e.points[1][1]) - t.selectionPadding, height: Math.abs(e.points[0][1] - e.points[1][1]) + 2 * t.selectionPadding }), gn = (e, t) => Re(e, so, t), At = (e, t) => {
346
- const i = [];
347
- let a;
345
+ }, ro = (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 }), vn = (e, t) => Re(e, ro, t), Et = (e, t) => {
346
+ const a = [];
347
+ let i;
348
348
  if (e.style?.lineArrow === 1 || e.style?.lineArrow === 2 || e.style?.lineArrow === 3) {
349
- const o = Math.PI / 2 - Wi({ targetVector: [e.points[0], e.points[1]] });
350
- e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(qi(_i(e.points[0], o, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(qi(_i(e.points[1], o + Math.PI, e.style), t));
351
- const r = (({ line: l, size: s, direction: c }) => {
352
- const u = Math.PI / 2 - Wi({ targetVector: [l.points[0], l.points[1]] }), d = [l.points[0][0] + (l.points[1][0] - l.points[0][0]) / 2, l.points[0][1] + (l.points[1][1] - l.points[0][1]) / 2];
353
- let h, f;
354
- if (["start", "both"].includes(c)) {
355
- const g = xe({ point: l.points[0], origin: d, rotation: -u });
356
- h = xe({ point: [g[0], g[1] + s], origin: d, rotation: u });
357
- } else h = [...l.points[0]];
358
- if (["end", "both"].includes(c)) {
359
- const g = xe({ point: l.points[1], origin: d, rotation: -u });
360
- f = xe({ point: [g[0], g[1] - s], origin: d, rotation: u });
361
- } else f = [...l.points[1]];
362
- return { points: [h, f] };
349
+ const o = Math.PI / 2 - Fa({ targetVector: [e.points[0], e.points[1]] });
350
+ e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || a.push(ja(Ka(e.points[0], o, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || a.push(ja(Ka(e.points[1], o + Math.PI, e.style), t));
351
+ const c = (({ line: r, size: s, direction: l }) => {
352
+ const u = Math.PI / 2 - Fa({ targetVector: [r.points[0], r.points[1]] }), d = [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];
353
+ let h, m;
354
+ if (["start", "both"].includes(l)) {
355
+ const p = Ce({ point: r.points[0], origin: d, rotation: -u });
356
+ h = Ce({ point: [p[0], p[1] + s], origin: d, rotation: u });
357
+ } else h = [...r.points[0]];
358
+ if (["end", "both"].includes(l)) {
359
+ const p = Ce({ point: r.points[1], origin: d, rotation: -u });
360
+ m = Ce({ point: [p[0], p[1] - s], origin: d, rotation: u });
361
+ } else m = [...r.points[1]];
362
+ return { points: [h, m] };
363
363
  })({ line: e, size: 10 + 2 * (e.style?.lineWidth ?? 0), direction: e.style?.lineArrow === 1 ? "start" : e.style?.lineArrow === 2 ? "end" : "both" });
364
- a = Zt(r);
365
- } else a = Zt(e);
366
- const n = gn(e, t);
367
- return { ...e, path: a, selection: fi(a, e, n, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: n };
368
- }, ro = At, _i = (e, t, i) => {
369
- const a = [xe({ point: [0, 0], rotation: t }), xe({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), xe({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
370
- return { points: [[e[0] + a[0][0], e[1] + a[0][1]], [e[0] + a[1][0], e[1] + a[1][1]], [e[0] + a[2][0], e[1] + a[2][1]]], style: { ...i, fillColor: i.strokeColor, strokeColor: "transparent" } };
371
- }, vn = (e, t) => Re(e, vi, t), Et = (e, t) => {
372
- const i = vn(e, t);
373
- return { ...e, selection: ut(void 0, i, t), computed: i };
374
- }, lo = Et, qt = (e, t, i, a, n) => {
375
- const [o, r] = ((l, s, c, u, d = !1) => {
376
- if (!(l && s && u && c)) return [Di, Di];
377
- const h = l / s;
378
- if (h > c / u) {
379
- const g = d ? c : Math.min(l, c);
380
- return [g, g / h];
364
+ i = Zt(c);
365
+ } else i = Zt(e);
366
+ const n = vn(e, t);
367
+ return { ...e, path: i, selection: ma(i, e, n, t), arrows: a, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: n };
368
+ }, lo = Et, Ka = (e, t, a) => {
369
+ const i = [Ce({ point: [0, 0], rotation: t }), Ce({ point: [-(5 + (a.lineWidth ?? 0)), 10 + 2 * (a.lineWidth ?? 0)], rotation: t }), Ce({ point: [5 + (a.lineWidth ?? 0), 10 + 2 * (a.lineWidth ?? 0)], rotation: t })];
370
+ return { points: [[e[0] + i[0][0], e[1] + i[0][1]], [e[0] + i[1][0], e[1] + i[1][1]], [e[0] + i[2][0], e[1] + i[2][1]]], style: { ...a, fillColor: a.strokeColor, strokeColor: "transparent" } };
371
+ }, mn = (e, t) => Re(e, va, t), It = (e, t) => {
372
+ const a = mn(e, t);
373
+ return { ...e, selection: gt(void 0, a, t), computed: a };
374
+ }, co = It, _t = (e, t, a, i, n) => {
375
+ const [o, c] = ((r, s, l, u, d = !1) => {
376
+ if (!(r && s && u && l)) return [Wa, Wa];
377
+ const h = r / s;
378
+ if (h > l / u) {
379
+ const p = d ? l : Math.min(r, l);
380
+ return [p, p / h];
381
381
  }
382
- const f = d ? u : Math.min(s, u);
383
- return [f * h, f];
384
- })(e.width, e.height, i, a, !0);
385
- return Et({ toolId: hi.id, type: "picture", id: ye("picture_"), x: -n.canvasOffset[0] + n.canvasSize.realWidth / n.canvasZoom / 2 - o / 2, y: -n.canvasOffset[1] + n.canvasSize.realHeight / n.canvasZoom / 2 - r / 2, width: o, height: r, src: t, img: e }, n);
386
- }, co = (e, t, i, a) => new Promise((n, o) => {
387
- const r = new Image();
388
- r.onerror = () => {
382
+ const m = d ? u : Math.min(s, u);
383
+ return [m * h, m];
384
+ })(e.width, e.height, a, i, !0);
385
+ return It({ toolId: ua.id, type: "picture", id: ue("picture_"), x: -n.canvasOffset[0] + n.canvasSize.realWidth / n.canvasZoom / 2 - o / 2, y: -n.canvasOffset[1] + n.canvasSize.realHeight / n.canvasZoom / 2 - c / 2, width: o, height: c, src: t, img: e }, n);
386
+ }, ho = (e, t, a, i) => new Promise((n, o) => {
387
+ const c = new Image();
388
+ c.onerror = () => {
389
389
  o(new Error("Some images could not be loaded"));
390
390
  }, setTimeout(() => {
391
391
  o(new Error("Timeout while loading images"));
392
- }, 4e3), e instanceof File ? ((l, s, c, u, d, h) => {
393
- yn(c) ? c.text().then((f) => {
394
- const g = mn(f);
395
- l.onload = async () => {
396
- URL.revokeObjectURL(l.src);
397
- const x = qt(l, f, u, d, h);
398
- s(x);
399
- }, l.src = g;
400
- }) : (l.onload = async () => {
401
- URL.revokeObjectURL(l.src);
402
- const f = qt(l, l.src, u, d, h);
403
- s(f);
404
- }, l.src = URL.createObjectURL(c));
405
- })(r, n, e, t, i, a) : ((l, s, c, u, d, h) => {
406
- l.onload = () => {
407
- URL.revokeObjectURL(l.src);
408
- const f = qt(l, c, u, d, h);
409
- s(f);
410
- }, Sn(c).then((f) => {
411
- l.src = f;
392
+ }, 4e3), e instanceof File ? ((r, s, l, u, d, h) => {
393
+ Qn(l) ? l.text().then((m) => {
394
+ const p = Sn(m);
395
+ r.onload = async () => {
396
+ URL.revokeObjectURL(r.src);
397
+ const Q = _t(r, m, u, d, h);
398
+ s(Q);
399
+ }, r.src = p;
400
+ }) : (r.onload = async () => {
401
+ URL.revokeObjectURL(r.src);
402
+ const m = _t(r, r.src, u, d, h);
403
+ s(m);
404
+ }, r.src = URL.createObjectURL(l));
405
+ })(c, n, e, t, a, i) : ((r, s, l, u, d, h) => {
406
+ r.onload = () => {
407
+ URL.revokeObjectURL(r.src);
408
+ const m = _t(r, l, u, d, h);
409
+ s(m);
410
+ }, bn(l).then((m) => {
411
+ r.src = m;
412
412
  }).catch(() => {
413
- l.src = "";
413
+ r.src = "";
414
414
  });
415
- })(r, n, e, t, i, a);
416
- }), _t = ["Texte"], yi = (e, t) => Re(e, uo, t), It = (e, t) => {
417
- const i = yi(e, t);
418
- return { ...e, selection: ut(void 0, i, t), computed: i };
419
- }, ho = It, Si = (e, t, i, a, n, o = yt) => {
420
- e.font = `${n ? "italic" : ""} ${a ? "bold" : ""} 1px ${o}`;
421
- const r = t.map((l) => i / e.measureText(l).width);
422
- return Math.min(...r) || 36;
423
- }, uo = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), po = (e, t, i, a) => {
424
- const n = { ...t, value: i }, o = ((f, g, x, C, k, w = yt) => {
425
- f.font = `${k ? "italic" : ""} ${C ? "bold" : ""} ${x}px ${w}`;
426
- const m = g.map((y) => f.measureText(y).width);
427
- return Math.max(...m) || 20;
428
- })(e, n.value, n.fontSize, n.style?.fontBold ?? !1, n.style?.fontItalic ?? !1, n.style?.fontFamily), r = n.fontSize * n.value.length, l = { ...n, width: o, height: r }, { center: s } = yi(l, a), [c, u] = Fi([1, 1], t.computed.center, t), [d, h] = Fi([1, 1], s, l, [!1, !1]);
429
- return { ...l, x: l.x - (d - c), y: l.y - (h - u) };
430
- }, ji = (e, t, i, a) => {
431
- const n = [_(i[0], a), _(i[1], a)];
415
+ })(c, n, e, t, a, i);
416
+ }), jt = ["Texte"], Sa = (e, t) => Re(e, po, t), Dt = (e, t) => {
417
+ const a = Sa(e, t);
418
+ return { ...e, selection: gt(void 0, a, t), computed: a };
419
+ }, uo = Dt, Qa = (e, t, a, i, n, o = St) => {
420
+ e.font = `${n ? "italic" : ""} ${i ? "bold" : ""} 1px ${o}`;
421
+ const c = t.map((r) => a / e.measureText(r).width);
422
+ return Math.min(...c) || 36;
423
+ }, po = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), go = (e, t, a, i) => {
424
+ const n = { ...t, value: a }, o = ((m, p, Q, k, L, C = St) => {
425
+ m.font = `${L ? "italic" : ""} ${k ? "bold" : ""} ${Q}px ${C}`;
426
+ const M = p.map((g) => m.measureText(g).width);
427
+ return Math.max(...M) || 20;
428
+ })(e, n.value, n.fontSize, n.style?.fontBold ?? !1, n.style?.fontItalic ?? !1, n.style?.fontFamily), c = n.fontSize * n.value.length, r = { ...n, width: o, height: c }, { center: s } = Sa(r, i), [l, u] = $a([1, 1], t.computed.center, t), [d, h] = $a([1, 1], s, r, [!1, !1]);
429
+ return { ...r, x: r.x - (d - l), y: r.y - (h - u) };
430
+ }, Ja = (e, t, a, i) => {
431
+ const n = [q(a[0], i), q(a[1], i)];
432
432
  switch (t.type) {
433
433
  case "brush":
434
- return ((o, r, l) => ht({ toolId: o.id, type: o.type, id: ye(`${o.type}_`), points: [[r]], scaleX: 1, scaleY: 1, style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, n, a);
434
+ return ((o, c, r) => pt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [[c]], 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, n, i);
435
435
  case "line":
436
- return ((o, r, l) => {
437
- const s = { toolId: o.id, type: o.type, id: ye(`${o.type}_`), points: [r, r], style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, lineArrow: o.settings.lineArrow.default } };
438
- return At(s, l);
439
- })(t, n, a);
436
+ return ((o, c, r) => {
437
+ const s = { toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [c, c], style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, lineArrow: o.settings.lineArrow.default } };
438
+ return Et(s, r);
439
+ })(t, n, i);
440
440
  case "polygon":
441
- return ((o, r, l) => pt({ toolId: o.id, type: o.type, id: ye(`${o.type}_`), points: [r], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, l))(t, n, a);
441
+ return ((o, c, r) => ft({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [c], 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, n, i);
442
442
  case "curve":
443
- return ((o, r, l) => gt({ toolId: o.id, type: o.type, id: ye(`${o.type}_`), points: [r], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, l))(t, n, a);
443
+ return ((o, c, r) => vt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [c], 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, n, i);
444
444
  case "rect":
445
445
  case "square":
446
- return an(t, n, a);
446
+ return on(t, n, i);
447
447
  case "text":
448
- return ((o, r, l, s) => {
449
- const c = Si(o, _t, 150, r.settings?.fontBold.default ?? !1, r.settings?.fontItalic.default ?? !1, r.settings.fontFamily.default), u = c * (_t.length || 1);
450
- return It({ toolId: r.id, type: r.type, id: ye(`${r.type}_`), x: l[0] - 150, y: l[1] - u, value: _t, fontSize: c, width: 150, height: u, style: { opacity: r.settings.opacity.default, strokeColor: r.settings.strokeColor.default, fontFamily: r.settings.fontFamily.default, fontItalic: r.settings.fontItalic.default, fontBold: r.settings.fontBold.default } }, s);
451
- })(e, t, n, a);
448
+ return ((o, c, r, s) => {
449
+ const l = Qa(o, jt, 150, c.settings?.fontBold.default ?? !1, c.settings?.fontItalic.default ?? !1, c.settings.fontFamily.default), u = l * (jt.length || 1);
450
+ return Dt({ toolId: c.id, type: c.type, id: ue(`${c.type}_`), x: r[0] - 150, y: r[1] - u, value: jt, fontSize: l, width: 150, height: u, style: { opacity: c.settings.opacity.default, strokeColor: c.settings.strokeColor.default, fontFamily: c.settings.fontFamily.default, fontItalic: c.settings.fontItalic.default, fontBold: c.settings.fontBold.default } }, s);
451
+ })(e, t, n, i);
452
452
  case "ellipse":
453
- return ((o, r, l) => zt({ toolId: o.id, type: o.type, id: ye(`${o.type}_`), x: r[0], y: r[1], radiusX: 0, radiusY: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, n, a);
453
+ return ((o, c, r) => At({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), x: c[0], y: c[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, n, i);
454
454
  case "circle":
455
- return ((o, r, l) => Tt({ toolId: o.id, type: o.type, id: ye(`${o.type}_`), x: r[0], y: r[1], radius: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, l))(t, n, a);
455
+ return ((o, c, r) => zt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), x: c[0], y: c[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, n, i);
456
456
  }
457
- }, Ki = (e, t) => {
457
+ }, ei = (e, t) => {
458
458
  switch (t.type) {
459
459
  case "brush":
460
- ((i, a) => {
461
- a.points.length < 1 || !a.path || i.globalAlpha !== 0 && a.style?.strokeColor !== "transparent" && i.globalAlpha !== 0 && i.stroke(a.path);
460
+ ((a, i) => {
461
+ i.points.length < 1 || !i.path || a.globalAlpha !== 0 && i.style?.strokeColor !== "transparent" && a.globalAlpha !== 0 && a.stroke(i.path);
462
462
  })(e, t);
463
463
  break;
464
464
  case "text":
465
- ((i, a) => {
466
- if (i.globalAlpha !== 0 && a.style?.strokeColor && a.style.strokeColor !== "transparent") {
467
- i.font = `${a.style?.fontItalic ? "italic" : ""} ${a.style?.fontBold ? "bold" : ""} ${a.fontSize}px ${a.style?.fontFamily ?? yt}`, i.textBaseline = "top", i.fillStyle = a.style.strokeColor;
468
- for (let n = 0; n < a.value.length; n++) i.fillText(a.value[n], a.x, a.y + n * a.fontSize, a.width);
465
+ ((a, i) => {
466
+ if (a.globalAlpha !== 0 && i.style?.strokeColor && i.style.strokeColor !== "transparent") {
467
+ a.font = `${i.style?.fontItalic ? "italic" : ""} ${i.style?.fontBold ? "bold" : ""} ${i.fontSize}px ${i.style?.fontFamily ?? St}`, a.textBaseline = "top", a.fillStyle = i.style.strokeColor;
468
+ for (let n = 0; n < i.value.length; n++) a.fillText(i.value[n], i.x, i.y + n * i.fontSize, i.width);
469
469
  }
470
470
  })(e, t);
471
471
  break;
472
472
  case "line":
473
- ((i, a) => {
474
- if (i.globalAlpha !== 0 && a.path) {
475
- a.style?.fillColor !== "transparent" && i.fill(a.path), a.style?.strokeColor !== "transparent" && i.stroke(a.path);
476
- for (const n of a.arrows ?? []) Qe(i, n.style), oo(i, n);
473
+ ((a, i) => {
474
+ if (a.globalAlpha !== 0 && i.path) {
475
+ i.style?.fillColor !== "transparent" && a.fill(i.path), i.style?.strokeColor !== "transparent" && a.stroke(i.path);
476
+ for (const n of i.arrows ?? []) be(a, n.style), so(a, n);
477
477
  }
478
478
  })(e, t);
479
479
  break;
480
480
  case "polygon":
481
- ((i, a) => {
482
- a.path && i.globalAlpha !== 0 && (a.style?.fillColor !== "transparent" && i.fill(a.path), a.style?.strokeColor !== "transparent" && i.stroke(a.path));
481
+ ((a, i) => {
482
+ i.path && a.globalAlpha !== 0 && (i.style?.fillColor !== "transparent" && a.fill(i.path), i.style?.strokeColor !== "transparent" && a.stroke(i.path));
483
483
  })(e, t);
484
484
  break;
485
485
  case "curve":
486
- ((i, a) => {
487
- a.path && i.globalAlpha !== 0 && (a.style?.fillColor !== "transparent" && i.fill(a.path), a.style?.strokeColor !== "transparent" && i.stroke(a.path));
486
+ ((a, i) => {
487
+ i.path && a.globalAlpha !== 0 && (i.style?.fillColor !== "transparent" && a.fill(i.path), i.style?.strokeColor !== "transparent" && a.stroke(i.path));
488
488
  })(e, t);
489
489
  break;
490
490
  case "circle":
491
- ((i, a) => {
492
- i.globalAlpha !== 0 && a.path && (a.style?.fillColor !== "transparent" && i.fill(a.path), a.style?.strokeColor !== "transparent" && i.stroke(a.path));
491
+ ((a, i) => {
492
+ a.globalAlpha !== 0 && i.path && (i.style?.fillColor !== "transparent" && a.fill(i.path), i.style?.strokeColor !== "transparent" && a.stroke(i.path));
493
493
  })(e, t);
494
494
  break;
495
495
  case "ellipse":
496
- ((i, a) => {
497
- i.globalAlpha !== 0 && a.path && (a.style?.fillColor !== "transparent" && i.fill(a.path), a.style?.strokeColor !== "transparent" && i.stroke(a.path));
496
+ ((a, i) => {
497
+ a.globalAlpha !== 0 && i.path && (i.style?.fillColor !== "transparent" && a.fill(i.path), i.style?.strokeColor !== "transparent" && a.stroke(i.path));
498
498
  })(e, t);
499
499
  break;
500
500
  case "rect":
501
501
  case "square":
502
- Yn(e, t);
502
+ Un(e, t);
503
503
  break;
504
504
  case "picture":
505
- ((i, a) => {
506
- i.globalAlpha !== 0 && (i.beginPath(), i.drawImage(a.img, a.x, a.y, a.width, a.height));
505
+ ((a, i) => {
506
+ a.globalAlpha !== 0 && (a.beginPath(), a.drawImage(i.img, i.x, i.y, i.width, i.height));
507
507
  })(e, t);
508
508
  }
509
- }, fn = (e, t, i) => {
509
+ }, yn = (e, t, a) => {
510
510
  if (t.visible === !1) return;
511
511
  if (((n, o) => {
512
- const r = ((l) => {
513
- const { canvasSize: { width: s, height: c, scaleRatioWithNoZoom: u }, canvasZoom: d, canvasOffset: h } = l;
514
- return { x: -h[0], y: -h[1], width: s / d / u, height: c / d / u };
512
+ const c = ((r) => {
513
+ const { canvasSize: { width: s, height: l, scaleRatioWithNoZoom: u }, canvasZoom: d, canvasOffset: h } = r;
514
+ return { x: -h[0], y: -h[1], width: s / d / u, height: l / d / u };
515
515
  })(o);
516
- return !!ii(n.computed.boundingBox, r);
517
- })(t, i)) {
518
- if (Pt(e, i, t.rotation, t.computed.center), Qe(e, t.style), e.globalAlpha !== 1) return ((n, o) => {
519
- const r = document.createElement("canvas"), l = r.getContext("2d");
520
- if (!l) throw new Error("No context found for canvas");
521
- const { outerBorders: s } = o.computed, c = { width: 2 * s.width, height: 2 * s.height };
522
- r.width = c.width, r.height = c.height, l.translate(c.width / 4 - s.x, c.height / 4 - s.y), Qe(l, { ...o.style, opacity: 100 }), Ki(l, o), n.drawImage(r, s.x - c.width / 4, s.y - c.height / 4);
516
+ return !!ia(n.computed.boundingBox, c);
517
+ })(t, a)) {
518
+ if (Lt(e, a, t.rotation, t.computed.center), be(e, t.style), e.globalAlpha !== 1) return ((n, o) => {
519
+ const c = document.createElement("canvas"), r = c.getContext("2d");
520
+ if (!r) throw new Error("No context found for canvas");
521
+ const { outerBorders: s } = o.computed, l = { width: 2 * s.width, height: 2 * s.height };
522
+ c.width = l.width, c.height = l.height, r.translate(l.width / 4 - s.x, l.height / 4 - s.y), be(r, { ...o.style, opacity: 100 }), ei(r, o), n.drawImage(c, s.x - l.width / 4, s.y - l.height / 4);
523
523
  })(e, t), void e.restore();
524
- Ki(e, t), e.restore();
524
+ ei(e, t), e.restore();
525
525
  }
526
- }, go = (e, t, i, a, n, o, r) => {
527
- const l = n[0] - a[0], s = n[1] - a[1], c = n[0] - t[0], u = n[1] - t[1], d = { ...e, rotation: Dn((i.rotation ?? 0) + Math.atan2(u, c) - Math.atan2(s, l), o, r) };
528
- return { ...d, computed: fo(d, o) };
529
- }, vo = (e, t, i, a, n, o, r, l) => {
530
- switch (a.type) {
526
+ }, fo = (e, t, a, i, n, o, c) => {
527
+ const r = n[0] - i[0], s = n[1] - i[1], l = n[0] - t[0], u = n[1] - t[1], d = { ...e, rotation: Rn((a.rotation ?? 0) + Math.atan2(u, l) - Math.atan2(s, r), o, c) };
528
+ return { ...d, computed: mo(d, o) };
529
+ }, vo = (e, t, a, i, n, o, c, r) => {
530
+ switch (i.type) {
531
531
  case "line":
532
- return ((s, c, u, d) => {
533
- const h = [_(s[0], d), _(s[1], d)], f = Ae(h, c.rotation ?? 0, c.computed.center), g = Pe(["points", u.anchor], f, c);
534
- return At(g, d);
535
- })(i, a, n, o);
532
+ return ((s, l, u, d) => {
533
+ const h = [q(s[0], d), q(s[1], d)], m = Ee(h, l.rotation ?? 0, l.computed.center), p = Ve(["points", u.anchor], m, l);
534
+ return Et(p, d);
535
+ })(a, i, n, o);
536
536
  case "polygon":
537
- return ((s, c, u, d) => {
538
- const h = [_(s[0], d), _(s[1], d)], f = Ae(h, c.rotation ?? 0, c.computed.center), g = Pe(["points", u.anchor], f, c);
539
- return pt(g, d);
540
- })(i, a, n, o);
537
+ return ((s, l, u, d) => {
538
+ const h = [q(s[0], d), q(s[1], d)], m = Ee(h, l.rotation ?? 0, l.computed.center), p = Ve(["points", u.anchor], m, l);
539
+ return ft(p, d);
540
+ })(a, i, n, o);
541
541
  case "curve":
542
- return ((s, c, u, d) => {
543
- const h = [_(s[0], d), _(s[1], d)], f = c.computed.center, g = Ae(h, c.rotation ?? 0, f), x = Pe(["points", u.anchor], g, c);
544
- return gt(x, d);
545
- })(i, a, n, o);
542
+ return ((s, l, u, d) => {
543
+ const h = [q(s[0], d), q(s[1], d)], m = l.computed.center, p = Ee(h, l.rotation ?? 0, m), Q = Ve(["points", u.anchor], p, l);
544
+ return vt(Q, d);
545
+ })(a, i, n, o);
546
546
  case "brush":
547
- return ((s, c, u, d, h, f) => {
548
- const g = _a({ ...c, scaleX: 1, scaleY: 1 }, d), x = c.computed.borders, { borderX: C, borderHeight: k, borderY: w, borderWidth: m } = nt(s, c, u, d, h, f), y = Math.max(0, g.width - 2 * d.selectionPadding), b = Math.max(0, g.height - 2 * d.selectionPadding), Z = Math.max(0, m - 2 * d.selectionPadding), A = Math.max(0, k - 2 * d.selectionPadding), T = y ? Z / y : 1, S = b ? A / b : 1;
549
- if (!y || !b) return c;
550
- const V = Xe(C - x.x), I = Xe(w - x.y);
551
- return ht({ ...c, points: c.points.map((N) => N.map(([H, D]) => [H + V, D + I])), scaleX: T, scaleY: S }, d);
552
- })(i, a, n, o, r, l);
547
+ return ((s, l, u, d, h, m) => {
548
+ const p = Ki({ ...l, scaleX: 1, scaleY: 1 }, d), Q = l.computed.borders, { borderX: k, borderHeight: L, borderY: C, borderWidth: M } = ot(s, l, u, d, h, m), g = Math.max(0, p.width - 2 * d.selectionPadding), S = Math.max(0, p.height - 2 * d.selectionPadding), Z = Math.max(0, M - 2 * d.selectionPadding), I = Math.max(0, L - 2 * d.selectionPadding), H = g ? Z / g : 1, y = S ? I / S : 1;
549
+ if (!g || !S) return l;
550
+ const P = Ge(k - Q.x), D = Ge(C - Q.y);
551
+ return pt({ ...l, points: l.points.map((A) => A.map(([E, W]) => [E + P, W + D])), scaleX: H, scaleY: y }, d);
552
+ })(a, i, n, o, c, r);
553
553
  case "circle":
554
- return ((s, c, u, d, h) => {
555
- const { borderX: f, borderHeight: g, borderY: x, borderWidth: C } = nt(s, c, u, d, !0, h);
556
- return Tt({ ...c, radius: Math.max(0, C / 2 - d.selectionPadding), x: f + C / 2, y: x + g / 2 }, d);
557
- })(i, a, n, o, l);
554
+ return ((s, l, u, d, h) => {
555
+ const { borderX: m, borderHeight: p, borderY: Q, borderWidth: k } = ot(s, l, u, d, !0, h);
556
+ return zt({ ...l, radius: Math.max(0, k / 2 - d.selectionPadding), x: m + k / 2, y: Q + p / 2 }, d);
557
+ })(a, i, n, o, r);
558
558
  case "ellipse":
559
- return ((s, c, u, d, h = !1, f = !1) => {
560
- const { borderX: g, borderHeight: x, borderY: C, borderWidth: k } = nt(s, c, u, d, h, f);
561
- return zt({ ...c, radiusX: Math.max(0, k / 2 - d.selectionPadding), radiusY: Math.max(0, x / 2 - d.selectionPadding), x: g + k / 2, y: C + x / 2 }, d);
562
- })(i, a, n, o, r, l);
559
+ return ((s, l, u, d, h = !1, m = !1) => {
560
+ const { borderX: p, borderHeight: Q, borderY: k, borderWidth: L } = ot(s, l, u, d, h, m);
561
+ return At({ ...l, radiusX: Math.max(0, L / 2 - d.selectionPadding), radiusY: Math.max(0, Q / 2 - d.selectionPadding), x: p + L / 2, y: k + Q / 2 }, d);
562
+ })(a, i, n, o, c, r);
563
563
  case "rect":
564
564
  case "square":
565
- return ((s, c, u, d, h = !1, f = !1) => {
566
- const { borderX: g, borderHeight: x, borderY: C, borderWidth: k } = nt(s, c, u, d, h, f);
567
- return Ht({ ...c, width: Math.max(0, k - 2 * d.selectionPadding), height: Math.max(0, x - 2 * d.selectionPadding), x: g + d.selectionPadding, y: C + d.selectionPadding }, d);
568
- })(i, a, n, o, t.type === "square" || r, l);
565
+ return ((s, l, u, d, h = !1, m = !1) => {
566
+ const { borderX: p, borderHeight: Q, borderY: k, borderWidth: L } = ot(s, l, u, d, h, m);
567
+ return Tt({ ...l, width: Math.max(0, L - 2 * d.selectionPadding), height: Math.max(0, Q - 2 * d.selectionPadding), x: p + d.selectionPadding, y: k + d.selectionPadding }, d);
568
+ })(a, i, n, o, t.type === "square" || c, r);
569
569
  case "text":
570
- return ((s, c, u, d, h, f) => {
571
- const { borderX: g, borderHeight: x, borderY: C, borderWidth: k } = nt(c, u, d, h, !0, f), w = It({ ...u, width: Math.max(0, k - 2 * h.selectionPadding), height: Math.max(0, x - 2 * h.selectionPadding), x: g + h.selectionPadding, y: C + h.selectionPadding }, h);
572
- return { ...w, fontSize: Si(s, w.value, w.width, w.style?.fontBold ?? !1, w.style?.fontItalic ?? !1, w.style?.fontFamily) };
573
- })(e, i, a, n, o, l);
570
+ return ((s, l, u, d, h, m) => {
571
+ const { borderX: p, borderHeight: Q, borderY: k, borderWidth: L } = ot(l, u, d, h, !0, m), C = Dt({ ...u, width: Math.max(0, L - 2 * h.selectionPadding), height: Math.max(0, Q - 2 * h.selectionPadding), x: p + h.selectionPadding, y: k + h.selectionPadding }, h);
572
+ return { ...C, fontSize: Qa(s, C.value, C.width, C.style?.fontBold ?? !1, C.style?.fontItalic ?? !1, C.style?.fontFamily) };
573
+ })(e, a, i, n, o, r);
574
574
  case "picture":
575
- return ((s, c, u, d, h) => {
576
- const { borderX: f, borderHeight: g, borderY: x, borderWidth: C } = nt(s, c, u, d, !0, h);
577
- return Et({ ...c, width: Math.max(0, C - 2 * d.selectionPadding), height: Math.max(0, g - 2 * d.selectionPadding), x: f + d.selectionPadding, y: x + d.selectionPadding }, d);
578
- })(i, a, n, o, l);
575
+ return ((s, l, u, d, h) => {
576
+ const { borderX: m, borderHeight: p, borderY: Q, borderWidth: k } = ot(s, l, u, d, !0, h);
577
+ return It({ ...l, width: Math.max(0, k - 2 * d.selectionPadding), height: Math.max(0, p - 2 * d.selectionPadding), x: m + d.selectionPadding, y: Q + d.selectionPadding }, d);
578
+ })(a, i, n, o, r);
579
579
  default:
580
- return a;
580
+ return i;
581
581
  }
582
- }, oi = (e, t, i, a, n) => {
582
+ }, sa = (e, t, a, i, n) => {
583
583
  switch (t.type) {
584
584
  case "rect":
585
585
  case "square":
586
- return ((o, r, l, s, c) => {
587
- const u = Oe([o[0] - l[0], o[1] - l[1]], c);
588
- return Ht({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
589
- })(e, t, i, a, n);
586
+ return ((o, c, r, s, l) => {
587
+ const u = Fe([o[0] - r[0], o[1] - r[1]], l);
588
+ return Tt({ ...c, x: q(c.x + u[0], s), y: q(c.y + u[1], s) }, s);
589
+ })(e, t, a, i, n);
590
590
  case "ellipse":
591
- return ((o, r, l, s, c) => {
592
- const u = Oe([o[0] - l[0], o[1] - l[1]], c);
593
- return zt({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
594
- })(e, t, i, a, n);
591
+ return ((o, c, r, s, l) => {
592
+ const u = Fe([o[0] - r[0], o[1] - r[1]], l);
593
+ return At({ ...c, x: q(c.x + u[0], s), y: q(c.y + u[1], s) }, s);
594
+ })(e, t, a, i, n);
595
595
  case "circle":
596
- return ((o, r, l, s, c) => {
597
- const u = Oe([o[0] - l[0], o[1] - l[1]], c);
598
- return Tt({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
599
- })(e, t, i, a, n);
596
+ return ((o, c, r, s, l) => {
597
+ const u = Fe([o[0] - r[0], o[1] - r[1]], l);
598
+ return zt({ ...c, x: q(c.x + u[0], s), y: q(c.y + u[1], s) }, s);
599
+ })(e, t, a, i, n);
600
600
  case "picture":
601
- return ((o, r, l, s, c) => {
602
- const u = Oe([o[0] - l[0], o[1] - l[1]], c);
603
- return Et({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
604
- })(e, t, i, a, n);
601
+ return ((o, c, r, s, l) => {
602
+ const u = Fe([o[0] - r[0], o[1] - r[1]], l);
603
+ return It({ ...c, x: q(c.x + u[0], s), y: q(c.y + u[1], s) }, s);
604
+ })(e, t, a, i, n);
605
605
  case "text":
606
- return ((o, r, l, s, c) => {
607
- const u = Oe([o[0] - l[0], o[1] - l[1]], c);
608
- return It({ ...r, x: _(r.x + u[0], s), y: _(r.y + u[1], s) }, s);
609
- })(e, t, i, a, n);
606
+ return ((o, c, r, s, l) => {
607
+ const u = Fe([o[0] - r[0], o[1] - r[1]], l);
608
+ return Dt({ ...c, x: q(c.x + u[0], s), y: q(c.y + u[1], s) }, s);
609
+ })(e, t, a, i, n);
610
610
  case "line":
611
- return ((o, r, l, s, c) => {
612
- const u = Oe([o[0] - l[0], o[1] - l[1]], c);
613
- return At({ ...r, points: r.points.map(([d, h]) => [_(d + u[0], s), _(h + u[1], s)]) }, s);
614
- })(e, t, i, a, n);
611
+ return ((o, c, r, s, l) => {
612
+ const u = Fe([o[0] - r[0], o[1] - r[1]], l);
613
+ return Et({ ...c, points: c.points.map(([d, h]) => [q(d + u[0], s), q(h + u[1], s)]) }, s);
614
+ })(e, t, a, i, n);
615
615
  case "polygon":
616
- return ((o, r, l, s, c) => {
617
- const u = Oe([o[0] - l[0], o[1] - l[1]], c), d = r.computed.borders;
618
- return pt({ ...r, points: r.points.map(([h, f]) => s.gridGap ? [h + _(d.x + u[0], s) - d.x, f + _(d.y + u[1], s) - d.y] : [_(h + o[0] - l[0], s), _(f + o[1] - l[1], s)]) }, s);
619
- })(e, t, i, a, n);
616
+ return ((o, c, r, s, l) => {
617
+ const u = Fe([o[0] - r[0], o[1] - r[1]], l), d = c.computed.borders;
618
+ return ft({ ...c, points: c.points.map(([h, m]) => s.gridGap ? [h + q(d.x + u[0], s) - d.x, m + q(d.y + u[1], s) - d.y] : [q(h + o[0] - r[0], s), q(m + o[1] - r[1], s)]) }, s);
619
+ })(e, t, a, i, n);
620
620
  case "curve":
621
- return ((o, r, l, s, c) => {
622
- const u = r.computed.borders, d = Oe([o[0] - l[0], o[1] - l[1]], c);
623
- return gt({ ...r, points: r.points.map(([h, f]) => s.gridGap ? [h + _(u.x + d[0], s) - u.x, f + _(u.y + d[1], s) - u.y] : [_(h + d[0], s), _(f + d[1], s)]) }, s);
624
- })(e, t, i, a, n);
621
+ return ((o, c, r, s, l) => {
622
+ const u = c.computed.borders, d = Fe([o[0] - r[0], o[1] - r[1]], l);
623
+ return vt({ ...c, points: c.points.map(([h, m]) => s.gridGap ? [h + q(u.x + d[0], s) - u.x, m + q(u.y + d[1], s) - u.y] : [q(h + d[0], s), q(m + d[1], s)]) }, s);
624
+ })(e, t, a, i, n);
625
625
  case "brush":
626
- return ((o, r, l, s, c) => {
627
- const u = r.computed.borders, d = Oe([o[0] - l[0], o[1] - l[1]], c), h = s.gridGap ? _(u.x + d[0], s) - u.x : d[0], f = s.gridGap ? _(u.y + d[1], s) - u.y : d[1];
628
- return ht({ ...r, points: r.points.map((g) => g.map(([x, C]) => [x + h, C + f])) }, s);
629
- })(e, t, i, a, n);
626
+ return ((o, c, r, s, l) => {
627
+ const u = c.computed.borders, d = Fe([o[0] - r[0], o[1] - r[1]], l), h = s.gridGap ? q(u.x + d[0], s) - u.x : d[0], m = s.gridGap ? q(u.y + d[1], s) - u.y : d[1];
628
+ return pt({ ...c, points: c.points.map((p) => p.map(([Q, k]) => [Q + h, k + m])) }, s);
629
+ })(e, t, a, i, n);
630
630
  default:
631
631
  return t;
632
632
  }
633
- }, dt = (e, t) => {
633
+ }, ut = (e, t) => {
634
634
  switch (e.type) {
635
635
  case "rect":
636
636
  case "square":
637
- return $n(e, t);
637
+ return Yn(e, t);
638
638
  case "ellipse":
639
- return ao(e, t);
639
+ return no(e, t);
640
640
  case "circle":
641
- return _n(e, t);
641
+ return jn(e, t);
642
642
  case "picture":
643
- return lo(e, t);
643
+ return co(e, t);
644
644
  case "text":
645
- return ho(e, t);
645
+ return uo(e, t);
646
646
  case "line":
647
- return ro(e, t);
647
+ return lo(e, t);
648
648
  case "polygon":
649
- return jn(e, t);
649
+ return Kn(e, t);
650
650
  case "curve":
651
- return eo(e, t);
651
+ return to(e, t);
652
652
  case "brush":
653
653
  return Nn(e, t);
654
654
  default:
655
655
  return e;
656
656
  }
657
- }, fo = (e, t) => {
657
+ }, mo = (e, t) => {
658
658
  switch (e.type) {
659
659
  case "rect":
660
660
  case "square":
661
- return tn(e, t);
661
+ return nn(e, t);
662
662
  case "ellipse":
663
- return pn(e, t);
663
+ return fn(e, t);
664
664
  case "circle":
665
- return dn(e, t);
665
+ return un(e, t);
666
666
  case "picture":
667
- return vn(e, t);
667
+ return mn(e, t);
668
668
  case "text":
669
- return yi(e, t);
669
+ return Sa(e, t);
670
670
  case "line":
671
- return gn(e, t);
671
+ return vn(e, t);
672
672
  case "polygon":
673
- return hn(e, t);
673
+ return pn(e, t);
674
674
  case "curve":
675
- return un(e, t);
675
+ return gn(e, t);
676
676
  case "brush":
677
- return ja(e, t);
677
+ return Ji(e, t);
678
678
  }
679
- }, Ji = ({ ctx: e, shape: t, settings: i, selectionWidth: a, selectionColor: n, hoverMode: o, withAnchors: r = !0 }) => {
680
- const { center: l } = t.computed;
681
- switch (i.debug && ((s, c, u, d) => {
682
- c.selection && d.debug && (s.save(), s.scale(d.canvasSize.scaleRatio, d.canvasSize.scaleRatio), s.translate(d.canvasOffset[0], d.canvasOffset[1]), Qe(s, { fillColor: "transparent", strokeColor: "green", lineWidth: u / d.canvasSize.scaleRatio }), s.strokeRect(c.computed.boundingBox.x, c.computed.boundingBox.y, c.computed.boundingBox.width, c.computed.boundingBox.height), s.restore());
683
- })(e, t, a, i), Pt(e, i, t.rotation, l), t.type) {
679
+ }, ti = ({ ctx: e, shape: t, settings: a, selectionWidth: i, selectionColor: n, hoverMode: o, withAnchors: c = !0 }) => {
680
+ const { center: r } = t.computed;
681
+ switch (a.debug && ((s, l, u, d) => {
682
+ l.selection && d.debug && (s.save(), s.scale(d.canvasSize.scaleRatio, d.canvasSize.scaleRatio), s.translate(d.canvasOffset[0], d.canvasOffset[1]), be(s, { fillColor: "transparent", strokeColor: "green", lineWidth: u / d.canvasSize.scaleRatio }), s.strokeRect(l.computed.boundingBox.x, l.computed.boundingBox.y, l.computed.boundingBox.width, l.computed.boundingBox.height), s.restore());
683
+ })(e, t, i, a), Lt(e, a, t.rotation, r), t.type) {
684
684
  case "rect":
685
685
  case "square":
686
686
  case "circle":
@@ -688,1020 +688,1028 @@ const Ui = ({ ctx: e, path: t, rect: i, offset: a, checkFill: n }) => {
688
688
  case "picture":
689
689
  case "text":
690
690
  case "brush":
691
- ((s, c, u, d, h, f) => {
692
- if (c.selection && (h.debug && (Qe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / h.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), Qe(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), c.selection.shapePath ? s.stroke(c.selection.shapePath) : s.stroke(c.selection.border), f && !c.locked)) {
693
- c.selection.shapePath && s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), Qe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / h.canvasSize.scaleRatio, shadowColor: u, shadowBlur: 0 });
694
- for (const g of c.selection.anchors) s.fill(g), s.stroke(g);
691
+ ((s, l, u, d, h, m) => {
692
+ if (l.selection && (h.debug && (be(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / h.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), be(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), l.selection.shapePath ? s.stroke(l.selection.shapePath) : s.stroke(l.selection.border), m && !l.locked)) {
693
+ l.selection.shapePath && s.stroke(l.selection.border), l.selection.line && s.stroke(l.selection.line), be(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / h.canvasSize.scaleRatio, shadowColor: u, shadowBlur: 0 });
694
+ for (const p of l.selection.anchors) s.fill(p), s.stroke(p);
695
695
  }
696
- })(e, t, n, a, i, r);
696
+ })(e, t, n, i, a, c);
697
697
  break;
698
698
  case "group":
699
- ((s, c, u, d, h, f) => {
700
- if (c.selection) {
701
- if (h.debug && (Qe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / h.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), Qe(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), f && !c.locked) {
702
- s.stroke(c.selection.border), c.selection.line && s.stroke(c.selection.line), Qe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / h.canvasSize.scaleRatio });
703
- for (const g of c.selection.anchors) s.fill(g), s.stroke(g);
699
+ ((s, l, u, d, h, m) => {
700
+ if (l.selection) {
701
+ if (h.debug && (be(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / h.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), be(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), m && !l.locked) {
702
+ s.stroke(l.selection.border), l.selection.line && s.stroke(l.selection.line), be(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / h.canvasSize.scaleRatio });
703
+ for (const p of l.selection.anchors) s.fill(p), s.stroke(p);
704
704
  }
705
- c.shapes.forEach((g) => {
706
- s.restore(), Qe(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), Pt(s, h, g.rotation, g.computed.center), g.selection?.shapePath && s.stroke(g.selection.shapePath);
705
+ l.shapes.forEach((p) => {
706
+ s.restore(), be(s, { fillColor: "transparent", strokeColor: u, lineWidth: d / h.canvasSize.scaleRatio }), Lt(s, h, p.rotation, p.computed.center), p.selection?.shapePath && s.stroke(p.selection.shapePath);
707
707
  });
708
708
  }
709
- })(e, t, n, a, i, r);
709
+ })(e, t, n, i, a, c);
710
710
  break;
711
711
  case "polygon":
712
712
  case "line":
713
713
  case "curve":
714
- (({ ctx: s, shape: c, withAnchors: u, selectionWidth: d, selectionColor: h, hoverMode: f, settings: g }) => {
715
- if (c.selection && (g.debug && (Qe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / g.canvasSize.scaleRatio }), s.strokeRect(c.computed.outerBorders.x, c.computed.outerBorders.y, c.computed.outerBorders.width, c.computed.outerBorders.height)), Qe(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / g.canvasSize.scaleRatio }), c.selection.shapePath && s.stroke(c.selection.shapePath), u && !c.locked)) {
716
- Qe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / g.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
717
- for (let x = 0; x < c.selection.anchors.length; x++) {
718
- const C = c.selection.anchors[x];
719
- f.mode === "resize" && f.anchor === x ? (s.shadowBlur = 10, s.fill(C), s.shadowBlur = 0) : s.fill(C), s.stroke(C);
714
+ (({ ctx: s, shape: l, withAnchors: u, selectionWidth: d, selectionColor: h, hoverMode: m, settings: p }) => {
715
+ if (l.selection && (p.debug && (be(s, { fillColor: "transparent", strokeColor: "red", lineWidth: d / p.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), be(s, { fillColor: "transparent", strokeColor: h, lineWidth: d / p.canvasSize.scaleRatio }), l.selection.shapePath && s.stroke(l.selection.shapePath), u && !l.locked)) {
716
+ be(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / p.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
717
+ for (let Q = 0; Q < l.selection.anchors.length; Q++) {
718
+ const k = l.selection.anchors[Q];
719
+ m.mode === "resize" && m.anchor === Q ? (s.shadowBlur = 10, s.fill(k), s.shadowBlur = 0) : s.fill(k), s.stroke(k);
720
720
  }
721
721
  }
722
- })({ ctx: e, shape: t, withAnchors: r, selectionWidth: a, selectionColor: n, hoverMode: o, settings: i });
722
+ })({ ctx: e, shape: t, withAnchors: c, selectionWidth: i, selectionColor: n, hoverMode: o, settings: a });
723
723
  }
724
724
  e.restore();
725
- }, mo = ({ ctx: e, selectionFrame: t, settings: i }) => {
726
- Pt(e, i), ((a, n, o) => {
727
- Qe(a, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / o.canvasSize.scaleRatio }), a.fillRect(n[0][0], n[0][1], n[1][0] - n[0][0], n[1][1] - n[0][1]), a.strokeRect(n[0][0], n[0][1], n[1][0] - n[0][0], n[1][1] - n[0][1]);
728
- })(e, t.frame, i), e.restore();
729
- }, Qi = (e) => e.filter((t) => t != null), mn = (e) => {
725
+ }, yo = ({ ctx: e, selectionFrame: t, settings: a }) => {
726
+ Lt(e, a), ((i, n, o) => {
727
+ be(i, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / o.canvasSize.scaleRatio }), i.fillRect(n[0][0], n[0][1], n[1][0] - n[0][0], n[1][1] - n[0][1]), i.strokeRect(n[0][0], n[0][1], n[1][0] - n[0][0], n[1][1] - n[0][1]);
728
+ })(e, t.frame, a), e.restore();
729
+ }, ba = (e) => e.filter((t) => t != null), Sn = (e) => {
730
730
  const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0];
731
731
  if (!t) return "";
732
- const i = t.getAttribute("width"), a = t.getAttribute("height");
732
+ const a = t.getAttribute("width"), i = t.getAttribute("height");
733
733
  let n;
734
- if (i || a) n = e;
734
+ if (a || i) n = e;
735
735
  else {
736
- const r = t.getAttribute("viewBox") ?? "0 0 300 300", [, , l, s] = r.split(" ");
737
- t.setAttribute("width", l ?? "300"), t.setAttribute("height", s ?? "300"), n = new XMLSerializer().serializeToString(t);
736
+ const c = t.getAttribute("viewBox") ?? "0 0 300 300", [, , r, s] = c.split(" ");
737
+ t.setAttribute("width", r ?? "300"), t.setAttribute("height", s ?? "300"), n = new XMLSerializer().serializeToString(t);
738
738
  }
739
739
  const o = new Blob([n], { type: "image/svg+xml" });
740
740
  return URL.createObjectURL(o);
741
- }, yn = (e) => (e instanceof File ? e.name : e).includes(".svg"), Sn = (e) => yn(e) ? fetch(e).then((t) => t.text()).then((t) => mn(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), ea = (e, t) => {
742
- const i = document.createElement("a");
743
- i.href = e, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
744
- }, yo = (e) => e.src.includes("<svg") ? e.src : ((t) => {
745
- const i = document.createElement("canvas");
746
- i.width = t.width, i.height = t.height;
747
- const a = i.getContext("2d");
748
- return a ? (a.drawImage(t, 0, 0), i.toDataURL("image/png")) : "";
749
- })(e.img), jt = ({ shapes: e, settings: t }) => {
750
- const i = document.createElement("canvas"), a = i.getContext("2d");
751
- if (!a) throw new Error("No context found for canvas");
741
+ }, Qn = (e) => (e instanceof File ? e.name : e).includes(".svg"), bn = (e) => Qn(e) ? fetch(e).then((t) => t.text()).then((t) => Sn(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), ai = (e, t) => {
742
+ const a = document.createElement("a");
743
+ a.href = e, a.download = t, document.body.appendChild(a), a.click(), document.body.removeChild(a);
744
+ }, So = (e) => e.src.includes("<svg") ? e.src : ((t) => {
745
+ const a = document.createElement("canvas");
746
+ a.width = t.width, a.height = t.height;
747
+ const i = a.getContext("2d");
748
+ return i ? (i.drawImage(t, 0, 0), a.toDataURL("image/png")) : "";
749
+ })(e.img), Kt = ({ shapes: e, settings: t }) => {
750
+ const a = document.createElement("canvas"), i = a.getContext("2d");
751
+ if (!i) throw new Error("No context found for canvas");
752
752
  const { realHeight: n, realWidth: o } = t.canvasSize;
753
- i.width = o, i.height = n, a.clearRect(0, 0, o, n), qa(a);
754
- for (let r = e.length - 1; r >= 0; r--) fn(a, e[r], t);
755
- return i.toDataURL("image/png");
756
- }, ta = ({ shapes: e, settings: t, view: i }) => {
757
- if (i === "fitToShapes" && !e.length) throw new Error("No image found to export");
758
- if (i === "fitToShapes") {
759
- const n = Math.min(...e.map((c) => c.computed.boundingBox.x)), o = Math.max(...e.map((c) => c.computed.boundingBox.x + c.computed.boundingBox.width)), r = Math.min(...e.map((c) => c.computed.boundingBox.y)), l = Math.max(...e.map((c) => c.computed.boundingBox.y + c.computed.boundingBox.height)), s = { ...t, canvasOffset: [-n, -r], canvasZoom: 1, canvasSize: { realWidth: o - n, realHeight: l - r, width: o - n, height: l - r, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
760
- return jt({ shapes: e, settings: s });
753
+ a.width = o, a.height = n, i.clearRect(0, 0, o, n), ji(i);
754
+ for (let c = e.length - 1; c >= 0; c--) yn(i, e[c], t);
755
+ return a.toDataURL("image/png");
756
+ }, ii = ({ shapes: e, settings: t, view: a }) => {
757
+ if (a === "fitToShapes" && !e.length) throw new Error("No image found to export");
758
+ if (a === "fitToShapes") {
759
+ const n = Math.min(...e.map((l) => l.computed.boundingBox.x)), o = Math.max(...e.map((l) => l.computed.boundingBox.x + l.computed.boundingBox.width)), c = 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: [-n, -c], canvasZoom: 1, canvasSize: { realWidth: o - n, realHeight: r - c, width: o - n, height: r - c, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
760
+ return Kt({ shapes: e, settings: s });
761
761
  }
762
- if (i === "defaultView") {
762
+ if (a === "defaultView") {
763
763
  const n = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
764
- return jt({ shapes: e, settings: n });
764
+ return Kt({ shapes: e, settings: n });
765
765
  }
766
- const a = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
767
- return jt({ shapes: e, settings: a });
768
- }, So = (e, t, i) => {
769
- return n = bi(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(n))}`;
766
+ const i = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
767
+ return Kt({ shapes: e, settings: i });
768
+ }, Qo = (e, t, a) => {
769
+ return n = wa(e, t, a), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(n))}`;
770
770
  var n;
771
- }, Qo = (e) => {
771
+ }, bo = (e) => {
772
772
  const t = ["img", "id", "selection", "path", "arrows", "tempPoint", "computed"];
773
- return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? Jt(t, i) : Jt(t, { ...i, src: yo(i) }));
774
- }, bi = (e, t, i) => ({ shapes: Qo(e), config: { width: t, height: i } }), ia = (e, t) => dt({ ...e, id: ye(`${e.type}_`) }, t), bo = (e, t, i, a) => {
775
- const n = te([]), o = te({ dataChanged: [] }), [r, l] = $(void 0), [s, c] = $(void 0), [u, d] = $(void 0), [h, f] = $({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), g = h.cursor > 0, x = h.cursor < h.states.length - 1, C = n.current.length > 0, k = B(() => {
776
- f((p) => Xa(p.states[p.cursor]?.shapes, n.current) ? p : { states: [...p.states.slice(0, p.cursor + 1), { shapes: n.current, selectedShape: s, source: "user" }], cursor: p.cursor + 1 });
777
- }, [s]), w = B((p) => {
778
- n.current = [...p, ...n.current];
779
- }, []), m = B((p, Q, M, L) => {
780
- if (p.target && "className" in p.target && ![Ya, Ua].includes(p.target.className) || !L) return void d(void 0);
781
- const P = n.current.find((E) => !j(s)?.map((W) => W.id).includes(E.id) && !!rn(Q, E, M, e));
782
- d(P);
783
- }, [e, s]), y = B(async (p, Q = 300, M = 300) => {
784
- const L = await co(p, Q, M, e);
785
- return w([L]), k(), L;
786
- }, [w, k, e]), b = B((p, Q = !1) => {
787
- n.current = n.current.map((M) => p.find((L) => L.id === M.id) ?? M), c((M) => M && be(j(M).map((L) => p.find((P) => P.id === L.id) ?? L), e)), Q && k();
788
- }, [k, e]), Z = B((p) => {
789
- const Q = p.map((M) => Jt(["chosen"], M));
790
- n.current = Q, k();
791
- }, [k]), A = B((p) => {
792
- const Q = new Set(p.map((M) => M.id));
793
- c((M) => {
794
- const L = j(M).map((P) => P.id);
795
- return L && Q.size && L.find((P) => Q.has(P)) ? void 0 : M;
796
- }), n.current = n.current.filter((M) => !Q?.has(M.id)), k();
797
- }, [k]), T = B((p) => {
798
- f((Q) => {
799
- const M = p(Q);
800
- return n.current = Q.states[M]?.shapes ?? [], c(Q.states[M]?.selectedShape), Pe("cursor", M, Q);
773
+ return e.map((a) => a.type !== "picture" || a.src.startsWith("http") ? ea(t, a) : ea(t, { ...a, src: So(a) }));
774
+ }, wa = (e, t, a) => ({ shapes: bo(e), config: { width: t, height: a } }), ni = (e, t) => ut({ ...e, id: ue(`${e.type}_`) }, t), wo = (e, t, a, i) => {
775
+ const n = ie([]), o = ie({ dataChanged: [] }), [c, r] = U(void 0), [s, l] = U(void 0), [u, d] = U(void 0), [h, m] = U({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), p = h.cursor > 0, Q = h.cursor < h.states.length - 1, k = n.current.length > 0, L = $(() => {
776
+ m((v) => qi(v.states[v.cursor]?.shapes, n.current) ? v : { states: [...v.states.slice(0, v.cursor + 1), { shapes: n.current, selectedShape: s, source: "user" }], cursor: v.cursor + 1 });
777
+ }, [s]), C = $((v) => {
778
+ n.current = [...v, ...n.current];
779
+ }, []), M = $((v) => {
780
+ n.current = n.current.flatMap((w) => {
781
+ const b = v.find((T) => T.id === w.id);
782
+ return b ? [{ ...b, id: ue(`${w.type}_`) }, w] : w;
801
783
  });
802
- }, []), S = B(() => {
803
- T((p) => Math.max(0, p.cursor - 1));
804
- }, [T]), V = B(() => {
805
- T((p) => Math.min(p.states.length - 1, p.cursor + 1));
806
- }, [T]), I = B((p, Q) => {
807
- c(void 0), n.current = p, f((M) => Q.clearHistory ? { states: [{ shapes: p, selectedShape: void 0, source: Q.source }], cursor: 0 } : { states: [...M.states.slice(0, M.cursor + 1), { shapes: p, selectedShape: void 0, source: Q.source }], cursor: M.cursor + 1 });
808
- }, []), N = B((p, Q) => {
809
- const M = n.current, L = M.findIndex((z) => z.id === p), P = M.findIndex((z) => z.id === Q);
810
- var E, W, O;
811
- Z((E = M, O = P, (W = L) < 0 || O < 0 || W > E.length - 1 || O > E.length - 1 ? E : W < O ? [...E.slice(0, W), ...E.slice(W + 1, O + 1), E[W], ...E.slice(O + 1, E.length)] : [...E.slice(0, O), E[W], ...E.slice(O, W), ...E.slice(W + 1, E.length)]));
812
- }, [Z]), H = B((p) => {
813
- const Q = n.current, M = new Set(p.map((P) => P.id)), L = Q.map((P) => M.has(P.id) ? Pe("visible", P.visible === !1, P) : P);
814
- c($i((P) => Pe("visible", P.visible === !1, P), e)), Z(L);
815
- }, [Z, e]), D = B((p) => {
816
- const Q = n.current, M = new Set(p.map((P) => P.id)), L = Q.map((P) => M.has(P.id) ? Pe("locked", !P.locked, P) : P);
817
- c($i((P) => Pe("locked", !P.locked, P), e)), Z(L);
818
- }, [Z, e]), U = B((p, Q) => {
819
- o.current.hasOwnProperty(p) && (o.current[p] = [...o.current[p], Q]);
820
- }, []), F = B((p, Q) => {
821
- if (o.current.hasOwnProperty(p)) if (Q) {
822
- const M = o.current[p].indexOf(Q);
823
- o.current[p] = [...o.current[p].slice(0, M), ...o.current[p].slice(M + 1)];
824
- } else o.current[p] = [];
784
+ }, []), g = $((v, w, b, T) => {
785
+ if (v.target && "className" in v.target && ![Xi, Gi].includes(v.target.className) || !T) return void d(void 0);
786
+ const x = n.current.find((O) => _(s)?.map((N) => N.id).includes(O.id) ? !!ht(w, O, b, e) : !!cn(w, O, b, e));
787
+ d(x);
788
+ }, [e, s]), S = $(async (v, w = 300, b = 300) => {
789
+ const T = await ho(v, w, b, e);
790
+ return C([T]), L(), T;
791
+ }, [C, L, e]), Z = $((v, w = !1) => {
792
+ n.current = n.current.map((b) => v.find((T) => T.id === b.id) ?? b), l((b) => b && we(_(b).map((T) => v.find((x) => x.id === T.id) ?? T), e)), w && L();
793
+ }, [L, e]), I = $((v) => {
794
+ const w = v.map((b) => ea(["chosen"], b));
795
+ n.current = w, L();
796
+ }, [L]), H = $((v) => {
797
+ const w = new Set(v.map((b) => b.id));
798
+ l((b) => {
799
+ const T = _(b).map((x) => x.id);
800
+ return T && w.size && T.find((x) => w.has(x)) ? void 0 : b;
801
+ }), n.current = n.current.filter((b) => !w?.has(b.id)), L();
802
+ }, [L]), y = $((v) => {
803
+ m((w) => {
804
+ const b = v(w);
805
+ return n.current = w.states[b]?.shapes ?? [], l(w.states[b]?.selectedShape), Ve("cursor", b, w);
806
+ });
807
+ }, []), P = $(() => {
808
+ y((v) => Math.max(0, v.cursor - 1));
809
+ }, [y]), D = $(() => {
810
+ y((v) => Math.min(v.states.length - 1, v.cursor + 1));
811
+ }, [y]), A = $((v, w) => {
812
+ l(void 0), n.current = v, m((b) => w.clearHistory ? { states: [{ shapes: v, selectedShape: void 0, source: w.source }], cursor: 0 } : { states: [...b.states.slice(0, b.cursor + 1), { shapes: v, selectedShape: void 0, source: w.source }], cursor: b.cursor + 1 });
813
+ }, []), E = $((v, w) => {
814
+ const b = n.current, T = b.findIndex((z) => z.id === v), x = b.findIndex((z) => z.id === w);
815
+ var O, N, F;
816
+ I((O = b, F = x, (N = T) < 0 || F < 0 || N > O.length - 1 || F > O.length - 1 ? O : N < F ? [...O.slice(0, N), ...O.slice(N + 1, F + 1), O[N], ...O.slice(F + 1, O.length)] : [...O.slice(0, F), O[N], ...O.slice(F, N), ...O.slice(N + 1, O.length)]));
817
+ }, [I]), W = $((v) => {
818
+ const w = n.current, b = new Set(v.map((x) => x.id)), T = w.map((x) => b.has(x.id) ? Ve("visible", x.visible === !1, x) : x);
819
+ l(Ua((x) => Ve("visible", x.visible === !1, x), e)), I(T);
820
+ }, [I, e]), B = $((v) => {
821
+ const w = n.current, b = new Set(v.map((x) => x.id)), T = w.map((x) => b.has(x.id) ? Ve("locked", !x.locked, x) : x);
822
+ l(Ua((x) => Ve("locked", !x.locked, x), e)), I(T);
823
+ }, [I, e]), Y = $((v, w) => {
824
+ o.current.hasOwnProperty(v) && (o.current[v] = [...o.current[v], w]);
825
+ }, []), j = $((v, w) => {
826
+ if (o.current.hasOwnProperty(v)) if (w) {
827
+ const b = o.current[v].indexOf(w);
828
+ o.current[v] = [...o.current[v].slice(0, b), ...o.current[v].slice(b + 1)];
829
+ } else o.current[v] = [];
825
830
  }, []);
826
- J(() => {
827
- const p = h.states[h.cursor], Q = bi(p.shapes, t, i);
828
- for (const M of o.current.dataChanged) M(Q, p.source);
829
- }, [t, i, h]), J(() => {
830
- n.current = n.current.map((p) => dt(p, e)), c((p) => p === void 0 ? void 0 : be(j(p).map((Q) => dt(Q, e)), e));
831
+ ee(() => {
832
+ const v = h.states[h.cursor], w = wa(v.shapes, t, a);
833
+ for (const b of o.current.dataChanged) b(w, v.source);
834
+ }, [t, a, h]), ee(() => {
835
+ n.current = n.current.map((v) => ut(v, e)), l((v) => v === void 0 ? void 0 : we(_(v).map((w) => ut(w, e)), e));
831
836
  }, [e]);
832
- const X = B((p, Q) => {
833
- l((M) => {
834
- const L = [M?.frame[0] ?? [Q[0], Q[1]], [Q[0], Q[1]]], P = n.current.filter((W) => ((O, z, ie, re) => {
835
- const { selectionPadding: R } = re, { center: oe, borders: G } = z.computed, le = Ae(ie[0], z.rotation ?? 0, oe), ae = Ae(ie[1], z.rotation ?? 0, oe), pe = Math.round(Math.min(le[0], ae[0]) - R / 2), se = Math.round(Math.max(le[0], ae[0]) + R), ge = Math.round(Math.min(le[1], ae[1]) - R / 2), q = { x: pe, y: ge, width: se - pe, height: Math.round(Math.max(le[1], ae[1]) + R) - ge }, he = ii(G, q);
836
- if (!he) return !1;
837
- if (G.width <= 1 || G.height <= 1 || !("path" in z) || !z.path) return !0;
838
- if (O.lineWidth = (z.style?.lineWidth ?? 0) + 10, z.type === "brush") {
839
- const Ee = z.points.flat(), Ie = Math.min(...Ee.map((ve) => ve[0])), He = Math.min(...Ee.map((ve) => ve[1]));
840
- for (const ve of z.points) {
841
- if (ve.length < 1) break;
842
- if (ve.length < 2) {
843
- const ne = ze(ve[0], Ie, He, z.scaleX, z.scaleY);
844
- if (Ka(he, { x: ne[0], y: ne[1], radius: (z.style?.lineWidth ?? 1) / 2 })) return !0;
837
+ const V = $((v, w) => {
838
+ r((b) => {
839
+ const T = [b?.frame[0] ?? [w[0], w[1]], [w[0], w[1]]], x = n.current.filter((N) => ((F, z, oe, de) => {
840
+ const { selectionPadding: re } = de, { center: K, borders: R } = z.computed, le = Ee(oe[0], z.rotation ?? 0, K), se = Ee(oe[1], z.rotation ?? 0, K), ye = Math.round(Math.min(le[0], se[0]) - re / 2), Me = Math.round(Math.max(le[0], se[0]) + re), pe = Math.round(Math.min(le[1], se[1]) - re / 2), te = { x: ye, y: pe, width: Me - ye, height: Math.round(Math.max(le[1], se[1]) + re) - pe }, ge = ia(R, te);
841
+ if (!ge) return !1;
842
+ if (R.width <= 1 || R.height <= 1 || !("path" in z) || !z.path) return !0;
843
+ if (F.lineWidth = (z.style?.lineWidth ?? 0) + 10, z.type === "brush") {
844
+ const Se = z.points.flat(), Ie = Math.min(...Se.map((ne) => ne[0])), ze = Math.min(...Se.map((ne) => ne[1]));
845
+ for (const ne of z.points) {
846
+ if (ne.length < 1) break;
847
+ if (ne.length < 2) {
848
+ const fe = Ae(ne[0], Ie, ze, z.scaleX, z.scaleY);
849
+ if (en(ge, { x: fe[0], y: fe[1], radius: (z.style?.lineWidth ?? 1) / 2 })) return !0;
845
850
  }
846
- for (let ne = 0; ne < ve.length - 1; ne++) {
847
- const Te = ze(ve[ne], Ie, He, z.scaleX, z.scaleY), We = ze(ve[ne + 1], Ie, He, z.scaleX, z.scaleY), Ce = ii({ x: Math.min(Te[0], We[0]), y: Math.min(Te[1], We[1]), width: Math.abs(Te[0] - We[0]), height: Math.abs(Te[1] - We[1]) }, q);
848
- if (Ce) {
849
- const qe = new Path2D();
850
- if (qe.moveTo(...Te), qe.lineTo(...We), Ui({ ctx: O, path: qe, rect: Ce, offset: 10, checkFill: !1 })) return !0;
851
+ for (let fe = 0; fe < ne.length - 1; fe++) {
852
+ const We = Ae(ne[fe], Ie, ze, z.scaleX, z.scaleY), Oe = Ae(ne[fe + 1], Ie, ze, z.scaleX, z.scaleY), ke = ia({ x: Math.min(We[0], Oe[0]), y: Math.min(We[1], Oe[1]), width: Math.abs(We[0] - Oe[0]), height: Math.abs(We[1] - Oe[1]) }, te);
853
+ if (ke) {
854
+ const _e = new Path2D();
855
+ if (_e.moveTo(...We), _e.lineTo(...Oe), Ga({ ctx: F, path: _e, rect: ke, offset: 10, checkFill: !1 })) return !0;
851
856
  }
852
857
  }
853
858
  }
854
859
  return !1;
855
860
  }
856
- const ce = !(!z.style?.fillColor || z.style?.fillColor === "transparent");
857
- return Ui({ ctx: O, path: z.path, rect: he, offset: 10, checkFill: ce });
858
- })(p, W, L, e)), E = be(P, e);
859
- return c(a ? be(nn(M?.oldSelection, P), e) : E), { oldSelection: M?.oldSelection, frame: L };
861
+ const G = !(!z.style?.fillColor || z.style?.fillColor === "transparent");
862
+ return Ga({ ctx: F, path: z.path, rect: ge, offset: 10, checkFill: G });
863
+ })(v, N, T, e)), O = we(x, e);
864
+ return l(i ? we(sn(b?.oldSelection, x), e) : O), { oldSelection: b?.oldSelection, frame: T };
860
865
  });
861
- }, [e, a]);
862
- return { registerEvent: U, unregisterEvent: F, shapesRef: n, selectedShape: s, hoveredShape: u, selectionFrame: r, setSelectionFrame: l, refreshSelectedShapes: X, addShapes: w, addPictureShape: y, moveShapes: N, saveShapes: k, setSelectedShape: c, refreshHoveredShape: m, toggleShapeVisibility: H, toggleShapeLock: D, removeShape: A, updateShape: b, backwardShape: S, forwardShape: V, clearShapes: I, canGoBackward: g, canGoForward: x, canClear: C };
863
- }, aa = (e) => {
864
- const t = [e[0].clientX, e[0].clientY], i = [e[1].clientX, e[1].clientY];
865
- var a, n;
866
- return { diff: Ja(t, i), center: (n = i, [((a = t)[0] + n[0]) / 2, (a[1] + n[1]) / 2]) };
867
- }, xo = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: a, setCanvasTransformation: n }) => {
868
- const o = te([]), [r, l] = $(o.current.length > 0), s = te(null), c = te(t);
869
- c.current = t;
870
- const u = B(({ startDiff: d, startZoom: h, startCenter: f, startOffset: g, currentDiff: x, currentCenter: C, isMoving: k, isZooming: w }) => {
871
- if (!e || !x || !d) return;
872
- const m = (({ canvasBoundingRect: y, canvasSize: b, size: Z, startDiff: A, startZoom: T, startCenter: S, startOffset: V, currentDiff: I, currentCenter: N, isMoving: H, isZooming: D }) => {
873
- const U = D ? De(I / A * T, Me[0], Me[Me.length - 1]) : T, F = H ? [V[0] + (N[0] - S[0]) * (b.width / y.width) / b.scaleRatio / T, V[1] + (N[1] - S[1]) * (b.height / y.height) / b.scaleRatio / T] : [V[0], V[1]], X = [(N[0] - y.left) / b.scaleRatio, (N[1] - y.top) / b.scaleRatio];
874
- return ni({ size: Z, canvasSize: b, currentOffset: F, currentZoom: T, zoom: U, centerPoint: X });
875
- })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: a, startDiff: d, startZoom: h, startCenter: f, startOffset: g, currentDiff: x, currentCenter: C, isMoving: k, isZooming: w });
876
- n(m);
877
- }, [e, i, a, n]);
878
- J(() => {
866
+ }, [e, i]);
867
+ return { registerEvent: Y, unregisterEvent: j, shapesRef: n, selectedShape: s, hoveredShape: u, selectionFrame: c, setSelectionFrame: r, refreshSelectedShapes: V, addShapes: C, duplicateShapes: M, addPictureShape: S, moveShapes: E, saveShapes: L, setSelectedShape: l, refreshHoveredShape: g, toggleShapeVisibility: W, toggleShapeLock: B, removeShape: H, updateShape: Z, backwardShape: P, forwardShape: D, clearShapes: A, canGoBackward: p, canGoForward: Q, canClear: k };
868
+ }, oi = (e) => {
869
+ const t = [e[0].clientX, e[0].clientY], a = [e[1].clientX, e[1].clientY];
870
+ var i, n;
871
+ return { diff: tn(t, a), center: (n = a, [((i = t)[0] + n[0]) / 2, (i[1] + n[1]) / 2]) };
872
+ }, Co = ({ canvasElt: e, canvasTransformation: t, canvasSize: a, size: i, setCanvasTransformation: n }) => {
873
+ const o = ie([]), [c, r] = U(o.current.length > 0), s = ie(null), l = ie(t);
874
+ l.current = t;
875
+ const u = $(({ startDiff: d, startZoom: h, startCenter: m, startOffset: p, currentDiff: Q, currentCenter: k, isMoving: L, isZooming: C }) => {
876
+ if (!e || !Q || !d) return;
877
+ const M = (({ canvasBoundingRect: g, canvasSize: S, size: Z, startDiff: I, startZoom: H, startCenter: y, startOffset: P, currentDiff: D, currentCenter: A, isMoving: E, isZooming: W }) => {
878
+ const B = W ? Ne(D / I * H, Pe[0], Pe[Pe.length - 1]) : H, Y = E ? [P[0] + (A[0] - y[0]) * (S.width / g.width) / S.scaleRatio / H, P[1] + (A[1] - y[1]) * (S.height / g.height) / S.scaleRatio / H] : [P[0], P[1]], j = [(A[0] - g.left) / S.scaleRatio, (A[1] - g.top) / S.scaleRatio];
879
+ return oa({ size: Z, canvasSize: S, currentOffset: Y, currentZoom: H, zoom: B, centerPoint: j });
880
+ })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: a, size: i, startDiff: d, startZoom: h, startCenter: m, startOffset: p, currentDiff: Q, currentCenter: k, isMoving: L, isZooming: C });
881
+ n(M);
882
+ }, [e, a, i, n]);
883
+ ee(() => {
879
884
  if (!e) return;
880
885
  const d = (h) => {
881
- if (o.current = [...o.current, h], l(o.current.length > 0), o.current.length === 2) {
886
+ if (o.current = [...o.current, h], r(o.current.length > 0), o.current.length === 2) {
882
887
  h.stopPropagation();
883
- const { diff: f, center: g } = aa(o.current);
884
- s.current = { startDiff: f, startCenter: g, startZoom: c.current.zoom, startOffset: c.current.offset, isMoving: !1, isZooming: !1 };
888
+ const { diff: m, center: p } = oi(o.current);
889
+ s.current = { startDiff: m, startCenter: p, startZoom: l.current.zoom, startOffset: l.current.offset, isMoving: !1, isZooming: !1 };
885
890
  }
886
891
  };
887
892
  return e.addEventListener("pointerdown", d), () => {
888
893
  e.removeEventListener("pointerdown", d);
889
894
  };
890
- }, [e]), J(() => {
891
- if (!r) return;
892
- const d = (f) => {
893
- const g = o.current.findIndex((x) => x.pointerId === f.pointerId);
894
- if (g > -1 && (o.current[g] = f), o.current.length === 2 && s.current) {
895
- const { diff: x, center: C } = aa(o.current), k = s.current.isZooming || ((m, y) => Math.abs(m - y.startDiff) > 30)(x, s.current), w = s.current.isMoving || k || ((m, y) => Math.abs(Ja(m, y.startCenter)) > 10)(C, s.current);
896
- s.current = { ...s.current, isMoving: w, isZooming: k }, u({ ...s.current, currentDiff: x, currentCenter: C });
895
+ }, [e]), ee(() => {
896
+ if (!c) return;
897
+ const d = (m) => {
898
+ const p = o.current.findIndex((Q) => Q.pointerId === m.pointerId);
899
+ if (p > -1 && (o.current[p] = m), o.current.length === 2 && s.current) {
900
+ const { diff: Q, center: k } = oi(o.current), L = s.current.isZooming || ((M, g) => Math.abs(M - g.startDiff) > 30)(Q, s.current), C = s.current.isMoving || L || ((M, g) => Math.abs(tn(M, g.startCenter)) > 10)(k, s.current);
901
+ s.current = { ...s.current, isMoving: C, isZooming: L }, u({ ...s.current, currentDiff: Q, currentCenter: k });
897
902
  }
898
- }, h = (f) => {
899
- o.current = o.current.filter((g) => g.pointerId !== f.pointerId), l(o.current.length > 0);
903
+ }, h = (m) => {
904
+ o.current = o.current.filter((p) => p.pointerId !== m.pointerId), r(o.current.length > 0);
900
905
  };
901
906
  return document.addEventListener("pointermove", d), document.addEventListener("pointerup", h), document.addEventListener("pointerout", h), document.addEventListener("pointercancel", h), document.addEventListener("pointerleave", h), () => {
902
907
  document.removeEventListener("pointermove", d), document.removeEventListener("pointerup", h), document.removeEventListener("pointerout", h), document.removeEventListener("pointercancel", h), document.removeEventListener("pointerleave", h);
903
908
  };
904
- }, [r, u]);
905
- }, na = { offset: [0, 0], zoom: 1 }, wo = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: a }) => {
906
- const [n, o] = $(na), r = te(0), l = B((u) => {
907
- o(({ zoom: d }) => ai({ zoom: d, size: t, canvasSize: e, newOffset: u }));
908
- }, [e, t]), s = B((u) => {
909
- o(({ offset: d, zoom: h }) => (({ size: f, canvasSize: g, currentOffset: x, currentZoom: C, action: k }) => {
910
- const w = k === "default" ? Me[4] : k === "zoom" ? Me[De(Me.length - 1 - Me.slice(0).reverse().findIndex((y) => y <= C) + 1, 0, Me.length - 1)] : Me[De(Me.findIndex((y) => y >= C) - 1, 0, Me.length - 1)], m = [g.realWidth / 2, g.realHeight / 2];
911
- return ni({ size: f, canvasSize: g, currentOffset: x, currentZoom: C, zoom: w, centerPoint: m });
909
+ }, [c, u]);
910
+ }, si = { offset: [0, 0], zoom: 1 }, xo = ({ canvasSize: e, size: t, zoomEnabled: a, canvasElt: i }) => {
911
+ const [n, o] = U(si), c = ie(0), r = $((u) => {
912
+ o(({ zoom: d }) => na({ zoom: d, size: t, canvasSize: e, newOffset: u }));
913
+ }, [e, t]), s = $((u) => {
914
+ o(({ offset: d, zoom: h }) => (({ size: m, canvasSize: p, currentOffset: Q, currentZoom: k, action: L }) => {
915
+ const C = L === "default" ? Pe[4] : L === "zoom" ? Pe[Ne(Pe.length - 1 - Pe.slice(0).reverse().findIndex((g) => g <= k) + 1, 0, Pe.length - 1)] : Pe[Ne(Pe.findIndex((g) => g >= k) - 1, 0, Pe.length - 1)], M = [p.realWidth / 2, p.realHeight / 2];
916
+ return oa({ size: m, canvasSize: p, currentOffset: Q, currentZoom: k, zoom: C, centerPoint: M });
912
917
  })({ size: t, canvasSize: e, currentOffset: d, currentZoom: h, action: u }));
913
918
  }, [e, t]);
914
- xo({ canvasElt: a, canvasTransformation: n, canvasSize: e, size: t, setCanvasTransformation: o });
915
- const c = B(() => {
916
- o(na);
919
+ Co({ canvasElt: i, canvasTransformation: n, canvasSize: e, size: t, setCanvasTransformation: o });
920
+ const l = $(() => {
921
+ o(si);
917
922
  }, []);
918
- return J(() => {
919
- if (!i || !a) return;
923
+ return ee(() => {
924
+ if (!a || !i) return;
920
925
  const u = (d) => {
921
- const h = d.ctrlKey, { deltaX: f, deltaY: g } = ((w, m) => {
922
- const y = Math.abs(w.deltaY) < 50 && m < 50, b = w.ctrlKey, Z = Ga() && y && b;
923
- switch (w.deltaMode) {
926
+ const h = d.ctrlKey, { deltaX: m, deltaY: p } = ((C, M) => {
927
+ const g = Math.abs(C.deltaY) < 50 && M < 50, S = C.ctrlKey, Z = _i() && g && S;
928
+ switch (C.deltaMode) {
924
929
  case WheelEvent.DOM_DELTA_LINE:
925
- return { deltaX: 16 * w.deltaX, deltaY: 16 * w.deltaY };
930
+ return { deltaX: 16 * C.deltaX, deltaY: 16 * C.deltaY };
926
931
  case WheelEvent.DOM_DELTA_PAGE:
927
- return { deltaX: w.deltaX * window.innerHeight, deltaY: w.deltaY * window.innerHeight };
932
+ return { deltaX: C.deltaX * window.innerHeight, deltaY: C.deltaY * window.innerHeight };
928
933
  default:
929
- return Z ? { deltaX: 5 * w.deltaX, deltaY: 5 * w.deltaY } : { deltaX: w.deltaX, deltaY: w.deltaY };
934
+ return Z ? { deltaX: 5 * C.deltaX, deltaY: 5 * C.deltaY } : { deltaX: C.deltaX, deltaY: C.deltaY };
930
935
  }
931
- })(d, d.timeStamp - r.current);
932
- if (r.current = d.timeStamp, h) {
936
+ })(d, d.timeStamp - c.current);
937
+ if (c.current = d.timeStamp, h) {
933
938
  d.preventDefault();
934
- const w = sn(d, a, e);
935
- return void o(({ offset: m, zoom: y }) => (({ size: b, canvasSize: Z, currentOffset: A, currentZoom: T, delta: S, centerPoint: V }) => {
936
- const I = De(T * (1 - S / 1e3), Me[0], Me[Me.length - 1]);
937
- return ni({ size: b, canvasSize: Z, currentOffset: A, currentZoom: T, zoom: I, centerPoint: V });
938
- })({ size: t, canvasSize: e, currentOffset: m, currentZoom: y, delta: g, centerPoint: w }));
939
+ const C = ln(d, i, e);
940
+ return void o(({ offset: M, zoom: g }) => (({ size: S, canvasSize: Z, currentOffset: I, currentZoom: H, delta: y, centerPoint: P }) => {
941
+ const D = Ne(H * (1 - y / 1e3), Pe[0], Pe[Pe.length - 1]);
942
+ return oa({ size: S, canvasSize: Z, currentOffset: I, currentZoom: H, zoom: D, centerPoint: P });
943
+ })({ size: t, canvasSize: e, currentOffset: M, currentZoom: g, delta: p, centerPoint: C }));
939
944
  }
940
- const x = d.shiftKey, [C, k] = x ? [g, f] : [f, g];
941
- o(({ offset: w, zoom: m }) => {
942
- const y = [w[0] - C / m, w[1] - k / m], b = ai({ zoom: m, size: t, canvasSize: e, newOffset: y });
943
- return b.offset[0] === w[0] && b.offset[1] === w[1] || d.preventDefault(), b;
945
+ const Q = d.shiftKey, [k, L] = Q ? [p, m] : [m, p];
946
+ o(({ offset: C, zoom: M }) => {
947
+ const g = [C[0] - k / M, C[1] - L / M], S = na({ zoom: M, size: t, canvasSize: e, newOffset: g });
948
+ return S.offset[0] === C[0] && S.offset[1] === C[1] || d.preventDefault(), S;
944
949
  });
945
950
  };
946
- return a.addEventListener("wheel", u, { passive: !1 }), () => {
947
- a.removeEventListener("wheel", u);
951
+ return i.addEventListener("wheel", u, { passive: !1 }), () => {
952
+ i.removeEventListener("wheel", u);
948
953
  };
949
- }, [a, t, e, i]), { setCanvasTransformation: o, setCanvasOffset: l, setCanvasZoom: s, resetZoom: c, canvasTransformation: n };
950
- }, oa = (e, t = !1) => {
951
- const i = (n, o) => {
954
+ }, [i, t, e, a]), { setCanvasTransformation: o, setCanvasOffset: r, setCanvasZoom: s, resetZoom: l, canvasTransformation: n };
955
+ }, ri = (e, t = !1) => {
956
+ const a = (n, o) => {
952
957
  if (Array.isArray(n)) return o;
953
- }, a = e.map((n) => {
958
+ }, i = e.map((n) => {
954
959
  if (typeof n != "object") return null;
955
960
  switch (n.type) {
956
961
  case "brush":
957
- return Ne(i, Ta, n);
962
+ return De(a, Ai, n);
958
963
  case "circle":
959
- return Ne(i, Da, n);
964
+ return De(a, Wi, n);
960
965
  case "curve":
961
- return Ne(i, Ea, n);
966
+ return De(a, Di, n);
962
967
  case "ellipse":
963
- return Ne(i, Ra, n);
968
+ return De(a, Oi, n);
964
969
  case "line":
965
- return Ne(i, za, n);
970
+ return De(a, Ei, n);
966
971
  case "polygon":
967
- return Ne(i, Aa, n);
972
+ return De(a, Ii, n);
968
973
  case "rect":
969
- return Ne(i, Ia, n);
974
+ return De(a, Ni, n);
970
975
  case "square":
971
- return Ne(i, Na, n);
976
+ return De(a, Ri, n);
972
977
  case "text":
973
- return Ne(i, Wa, n);
978
+ return De(a, Fi, n);
974
979
  }
975
980
  return null;
976
981
  });
977
- return Qi(t ? [...a, hi] : a);
978
- }, ps = ({ width: e = 1e3, height: t = 600, shapes: i, mode: a = "editor", disabled: n = !1, options: o = Ni } = {}) => {
979
- const { layersManipulation: r, brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, grid: u, canGrow: d, canShrink: h, withExport: f, withLoadAndSave: g, withUploadPicture: x, withUrlPicture: C, withSkeleton: k, withFrameSelection: w, clearCallback: m, availableTools: y, canvasSelectionPadding: b, size: Z, canZoom: A } = { ...Ni, ...o }, T = a !== "viewer", S = te(null), V = te(null), I = te(!1), N = B((ee) => {
980
- S.current = ee;
981
- }, []), [H, D] = $(void 0), [U, F] = $(Fe), [X, p] = $({ mode: "default" }), [Q, M] = $(u), [L, P] = $({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), E = A === "always" && !n, { canvasTransformation: W, setCanvasTransformation: O, setCanvasOffset: z, setCanvasZoom: ie, resetZoom: re } = wo({ canvasSize: L, size: Z, canvasElt: V.current, zoomEnabled: E }), { offset: R, zoom: oe } = W, G = ba(() => ({ brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: c, canvasSize: { realWidth: L.realWidth, realHeight: L.realHeight, width: L.width, height: L.height, scaleRatioWithNoZoom: L.scaleRatio, scaleRatio: L.scaleRatio * oe }, size: Z, canvasOffset: R, canvasZoom: oe, gridGap: Q, selectionPadding: b, features: { edition: T && !n, zoom: E } }), [b, Q, l, s, c, oe, R, L, Z, n, E, T]), [le, ae] = $(oa(y, x || C)), { isInsideComponent: pe, isInsideCanvas: se } = (({ settings: ee, componentRef: de, canvasRef: Le }) => {
982
- const [$e, Ye] = $(!1), [Ke, Je] = $(!1), Se = !ee.features.edition && !ee.features.zoom;
983
- return J(() => {
984
- if (!Se) {
985
- const Ze = () => Ye(!0), Qt = () => Ye(!1), Ue = () => Je(!0), bt = () => Je(!1);
986
- return de.current?.addEventListener("focusin", Ze), de.current?.addEventListener("focusout", Qt), Le.current?.addEventListener("focusin", Ue), Le.current?.addEventListener("focusout", bt), () => {
987
- de.current?.removeEventListener("focusin", Ze), de.current?.removeEventListener("focusout", Qt), Le.current?.removeEventListener("focusin", Ue), Le.current?.removeEventListener("focusout", bt);
982
+ return ba(t ? [...i, ua] : i);
983
+ }, gs = ({ width: e = 1e3, height: t = 600, shapes: a, mode: i = "editor", disabled: n = !1, options: o = Ra } = {}) => {
984
+ const { layersManipulation: c, brushAlgo: r, isBrushShapeDoneOnMouseUp: s, debug: l, grid: u, canGrow: d, canShrink: h, withExport: m, withLoadAndSave: p, withUploadPicture: Q, withUrlPicture: k, withSkeleton: L, withFrameSelection: C, clearCallback: M, availableTools: g, canvasSelectionPadding: S, size: Z, canZoom: I } = { ...Ra, ...o }, H = i !== "viewer", y = ie(null), P = ie(null), D = ie(!1), A = $((ae) => {
985
+ y.current = ae;
986
+ }, []), [E, W] = U(void 0), [B, Y] = U(Be), [j, V] = U({ mode: "default" }), [v, w] = U(u), [b, T] = U({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), x = I === "always" && !n, { canvasTransformation: O, setCanvasTransformation: N, setCanvasOffset: F, setCanvasZoom: z, resetZoom: oe } = xo({ canvasSize: b, size: Z, canvasElt: P.current, zoomEnabled: x }), { offset: de, zoom: re } = O, K = Ci(() => ({ brushAlgo: r, isBrushShapeDoneOnMouseUp: s, debug: l, canvasSize: { realWidth: b.realWidth, realHeight: b.realHeight, width: b.width, height: b.height, scaleRatioWithNoZoom: b.scaleRatio, scaleRatio: b.scaleRatio * re }, size: Z, canvasOffset: de, canvasZoom: re, gridGap: v, selectionPadding: S, features: { edition: H && !n, zoom: x } }), [S, v, r, s, l, re, de, b, Z, n, x, H]), [R, le] = U(ri(g, Q || k)), { isInsideComponent: se, isInsideCanvas: ye } = (({ settings: ae, componentRef: ce, canvasRef: Ze }) => {
987
+ const [Ye, Ue] = U(!1), [Je, et] = U(!1), Qe = !ae.features.edition && !ae.features.zoom;
988
+ return ee(() => {
989
+ if (!Qe) {
990
+ const He = () => Ue(!0), bt = () => Ue(!1), Xe = () => et(!0), wt = () => et(!1);
991
+ return ce.current?.addEventListener("focusin", He), ce.current?.addEventListener("focusout", bt), Ze.current?.addEventListener("focusin", Xe), Ze.current?.addEventListener("focusout", wt), () => {
992
+ ce.current?.removeEventListener("focusin", He), ce.current?.removeEventListener("focusout", bt), Ze.current?.removeEventListener("focusin", Xe), Ze.current?.removeEventListener("focusout", wt);
988
993
  };
989
994
  }
990
- Ye(!1), Je(!1);
991
- }, [Se, de, Le]), { isInsideComponent: $e, isInsideCanvas: Ke };
992
- })({ settings: G, componentRef: S, canvasRef: V }), [ge, q] = $(!1), [he, ce] = $(!1), [Ee, Ie] = $(!1), { registerEvent: He, unregisterEvent: ve, shapesRef: ne, selectedShape: Te, selectionFrame: We, hoveredShape: Ce, addShapes: qe, addPictureShape: Rt, moveShapes: Wt, setSelectedShape: _e, setSelectionFrame: Ot, refreshSelectedShapes: Ft, refreshHoveredShape: fe, removeShape: me, updateShape: vt, backwardShape: Be, forwardShape: it, clearShapes: xi, saveShapes: bn, toggleShapeVisibility: xn, toggleShapeLock: wn, canGoBackward: Cn, canGoForward: Mn, canClear: kn } = bo(G, e, t, ge), Bt = B((ee) => {
993
- _e(void 0), F(ee);
994
- }, [_e]), [at, wi] = $([0, 0]), Ci = X.mode === "preview";
995
- J(() => {
996
- if (Ci) return () => p((ee) => ee.mode === "preview" ? { mode: "default" } : ee);
997
- }, [Te?.id, Ci]);
998
- const Mi = X.mode === "selectionFrame";
999
- J(() => {
1000
- if (Mi) return () => wi([0, 0]);
1001
- }, [Mi]), J(() => {
1002
- if (at[0] !== 0 || at[1] !== 0) {
1003
- const ee = setInterval(() => {
1004
- O(({ offset: de, zoom: Le }) => {
1005
- const $e = [de[0] - at[0], de[1] - at[1]];
1006
- return ai({ zoom: Le, size: Z, canvasSize: L, newOffset: $e });
995
+ Ue(!1), et(!1);
996
+ }, [Qe, ce, Ze]), { isInsideComponent: Ye, isInsideCanvas: Je };
997
+ })({ settings: K, componentRef: y, canvasRef: P }), [Me, pe] = U(!1), [te, ge] = U(!1), [G, Se] = U(!1), { registerEvent: Ie, unregisterEvent: ze, shapesRef: ne, selectedShape: fe, selectionFrame: We, hoveredShape: Oe, addShapes: ke, addPictureShape: _e, moveShapes: Wt, setSelectedShape: je, setSelectionFrame: Ot, refreshSelectedShapes: Ft, refreshHoveredShape: Bt, duplicateShapes: ve, removeShape: me, updateShape: mt, backwardShape: $e, forwardShape: it, clearShapes: Ca, saveShapes: xa, toggleShapeVisibility: Cn, toggleShapeLock: xn, canGoBackward: Mn, canGoForward: kn, canClear: Pn } = wo(K, e, t, Me), $t = $((ae) => {
998
+ je(void 0), Y(ae);
999
+ }, [je]), [nt, Ma] = U([0, 0]), ka = j.mode === "preview";
1000
+ ee(() => {
1001
+ if (ka) return () => V((ae) => ae.mode === "preview" ? { mode: "default" } : ae);
1002
+ }, [fe?.id, ka]);
1003
+ const Pa = j.mode === "selectionFrame";
1004
+ ee(() => {
1005
+ if (Pa) return () => Ma([0, 0]);
1006
+ }, [Pa]), ee(() => {
1007
+ if (nt[0] !== 0 || nt[1] !== 0) {
1008
+ const ae = setInterval(() => {
1009
+ N(({ offset: ce, zoom: Ze }) => {
1010
+ const Ye = [ce[0] - nt[0], ce[1] - nt[1]];
1011
+ return na({ zoom: Ze, size: Z, canvasSize: b, newOffset: Ye });
1007
1012
  });
1008
1013
  }, 20);
1009
- return () => clearInterval(ee);
1014
+ return () => clearInterval(ae);
1010
1015
  }
1011
- }, [at[0], at[1], O, Z, L]);
1012
- const St = B((ee, de) => {
1013
- xi(ee, de), Bt(Fe), O({ offset: [0, 0], zoom: 1 });
1014
- }, [Bt, xi, O]), ki = B((ee) => {
1015
- _e((de) => (de?.id !== ee.map((Le) => Le.id).join("-") && F(Fe), be(ee, G)));
1016
- }, [_e, G]), Pn = B(() => {
1017
- const ee = So(ne.current, e, t);
1018
- if (!ee) throw new Error("L'encodage a échoué");
1019
- ea(ee, "drawing.json");
1020
- }, [ne, e, t]), Ln = B((ee) => {
1021
- const de = ta({ shapes: ne.current, settings: G, view: ee });
1022
- ea(de, "drawing.png");
1023
- }, [ne, G]), Zn = B((ee) => ta({ shapes: ne.current, settings: G, view: ee }), [ne, G]), Vn = B(() => bi(ne.current, e, t), [ne, e, t]), je = B(async (ee, de) => {
1024
- const Le = await (async ($e, Ye) => {
1025
- if (!$e) return [];
1026
- const Ke = [], Je = Qi($e.map((Se) => {
1027
- if (!Se || !$a.includes(Se.type)) return null;
1028
- if (Se.type === "picture") {
1029
- const Ze = new Image(), Qt = new Promise((Ue, bt) => {
1030
- Ze.onload = () => {
1031
- URL.revokeObjectURL(Ze.src), Ue();
1032
- }, Ze.onerror = () => {
1033
- bt(new Error("Some images could not be loaded"));
1016
+ }, [nt[0], nt[1], N, Z, b]);
1017
+ const Qt = $((ae, ce) => {
1018
+ Ca(ae, ce), $t(Be), N({ offset: [0, 0], zoom: 1 });
1019
+ }, [$t, Ca, N]), La = $((ae) => {
1020
+ je((ce) => (ce?.id !== ae.map((Ze) => Ze.id).join("-") && Y(Be), we(ae, K)));
1021
+ }, [je, K]), Ln = $(() => {
1022
+ const ae = Qo(ne.current, e, t);
1023
+ if (!ae) throw new Error("L'encodage a échoué");
1024
+ ai(ae, "drawing.json");
1025
+ }, [ne, e, t]), Vn = $((ae) => {
1026
+ const ce = ii({ shapes: ne.current, settings: K, view: ae });
1027
+ ai(ce, "drawing.png");
1028
+ }, [ne, K]), Zn = $((ae) => ii({ shapes: ne.current, settings: K, view: ae }), [ne, K]), Hn = $(() => wa(ne.current, e, t), [ne, e, t]), Ke = $(async (ae, ce) => {
1029
+ const Ze = await (async (Ye, Ue) => {
1030
+ if (!Ye) return [];
1031
+ const Je = [], et = ba(Ye.map((Qe) => {
1032
+ if (!Qe || !Ui.includes(Qe.type)) return null;
1033
+ if (Qe.type === "picture") {
1034
+ const He = new Image(), bt = new Promise((Xe, wt) => {
1035
+ He.onload = () => {
1036
+ URL.revokeObjectURL(He.src), Xe();
1037
+ }, He.onerror = () => {
1038
+ wt(new Error("Some images could not be loaded"));
1034
1039
  };
1035
1040
  });
1036
- if (Ke.push(Qt), Se.src.startsWith("http")) Sn(Se.src).then((Ue) => {
1037
- Ze.src = Ue;
1041
+ if (Je.push(bt), Qe.src.startsWith("http")) bn(Qe.src).then((Xe) => {
1042
+ He.src = Xe;
1038
1043
  }).catch(() => {
1039
- Ze.src = "";
1044
+ He.src = "";
1040
1045
  });
1041
- else if (Se.src.includes("<svg")) {
1042
- const Ue = new Blob([Se.src], { type: "image/svg+xml" });
1043
- Ze.src = URL.createObjectURL(Ue);
1044
- } else Ze.src = Se.src;
1045
- return ia({ ...Se, img: Ze }, Ye);
1046
+ else if (Qe.src.includes("<svg")) {
1047
+ const Xe = new Blob([Qe.src], { type: "image/svg+xml" });
1048
+ He.src = URL.createObjectURL(Xe);
1049
+ } else He.src = Qe.src;
1050
+ return ni({ ...Qe, img: He }, Ue);
1046
1051
  }
1047
- return ia(Se, Ye);
1052
+ return ni(Qe, Ue);
1048
1053
  }));
1049
- return await Promise.all(Ke), Je;
1050
- })(ee, G);
1051
- St(Le, de);
1052
- }, [St, G]), $t = te(je);
1053
- $t.current = je;
1054
- const Hn = B((ee = [], de = !0) => {
1055
- $t.current?.(ee, { clearHistory: de, source: "remote" });
1054
+ return await Promise.all(Je), et;
1055
+ })(ae, K);
1056
+ Qt(Ze, ce);
1057
+ }, [Qt, K]), Yt = ie(Ke);
1058
+ Yt.current = Ke;
1059
+ const Tn = $((ae = [], ce = !0) => {
1060
+ Yt.current?.(ae, { clearHistory: ce, source: "remote" });
1056
1061
  }, []);
1057
- J(() => {
1058
- I.current || (I.current = !0, i && $t.current?.(i, { clearHistory: !0, source: "remote" }));
1059
- }, [i]);
1060
- const Tn = B(async (ee) => {
1061
- const de = await (async (Le) => new Promise(($e, Ye) => {
1062
- const Ke = new FileReader();
1063
- Ke.onload = (Je) => {
1064
- const Se = Je.target?.result;
1065
- if (!Se) return Ye("Impossible de récupérer les données du fichier");
1066
- const Ze = JSON.parse(Se);
1067
- $e(Ze);
1068
- }, Ke.readAsText(Le);
1069
- }))(ee);
1070
- await je(de.shapes ?? [], { clearHistory: !0, source: "remote" });
1071
- }, [je]), zn = B(() => {
1072
- typeof m != "string" ? je(m(), { clearHistory: !1, source: "user" }) : m === "defaultShapes" && i !== void 0 ? je(i, { clearHistory: !1, source: "user" }) : St([], { clearHistory: !1, source: "user" });
1073
- }, [St, je, i, m]);
1074
- J(() => {
1075
- ae(oa(y, x || C));
1076
- }, [y, x, C]);
1077
- const Pi = { canvas: V, editor: S, setEditor: N };
1078
- return { annotationsProps: { style: { userSelect: "none", touchAction: "none", transformOrigin: "left top", transform: "scale(var(--react-paint-canvas-zoom)) translate(calc(var(--react-paint-canvas-offset-x) * 100% / var(--react-paint-app-canvaswidth)), calc(var(--react-paint-canvas-offset-y) * 100% / var(--react-paint-app-canvasheight)))", "--react-paint-canvas-zoom": G.canvasZoom, "--react-paint-canvas-offset-x": G.canvasOffset[0], "--react-paint-canvas-offset-y": G.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: ne, addPictureShape: Rt, moveShapes: Wt, toggleShapeVisibility: xn, toggleShapeLock: wn, canGoBackward: Cn, canGoForward: Mn, canClear: kn, selectedShape: Te, removeShape: me, updateShape: vt, backwardShape: Be, forwardShape: it, refs: Pi, width: e, height: t, selectTool: Bt, selectShapes: ki, activeTool: U, setActiveTool: F, setAvailableTools: ae, isEditMode: T, availableTools: le, gridGap: Q, setGridGap: M, loadFile: Tn, exportPicture: Ln, exportData: Pn, clearCanvas: zn, settings: G, setCanvasZoom: ie, resetZoom: re, canvas: { canGrow: d, canShrink: h, layersManipulation: r, withExport: f, withLoadAndSave: g, withUploadPicture: x, withUrlPicture: C } }, canvasProps: { shapesRef: ne, selectedShape: Te, selectionFrame: We, hoveredShape: Ce, addShape: qe, setSelectedShape: _e, setSelectionFrame: Ot, refreshSelectedShapes: Ft, refreshHoveredShape: fe, removeShape: me, updateShape: vt, backwardShape: Be, forwardShape: it, saveShapes: bn, refs: Pi, width: e, height: t, settings: G, setCanvasSize: P, setCanvasOffset: z, setCanvasZoom: ie, resetZoom: re, selectShapes: ki, activeTool: U, setActiveTool: F, isInsideComponent: pe, isInsideCanvas: se, isEditMode: T, canvas: { withSkeleton: k, withFrameSelection: w, canGrow: d, canShrink: h }, canvasOffsetStartData: H, setCanvasOffsetStartData: D, selectionMode: X, setSelectionMode: p, setCanvasMoveAcceleration: wi, isShiftPressed: ge, isAltPressed: he, isSpacePressed: Ee, setShiftPressed: q, setAltPressed: ce, setIsSpacePressed: Ie }, registerEvent: He, unregisterEvent: ve, resetCanvas: Hn, resetZoom: re, getCurrentImage: Zn, getCurrentData: Vn, setCanvasOffset: z, setCanvasZoom: ie };
1079
- }, Co = ({ addShapes: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: a, shapes: n, selectionMode: o, activeTool: r, isInsideComponent: l, setCanvasOffset: s, selectedShape: c, canvasOffsetStartData: u, refreshSelectedShapes: d, setSelectedShape: h, setSelectionFrame: f, setCanvasOffsetStartData: g, updateSingleShape: x, saveShapes: C, setSelectionMode: k, setCanvasMoveAcceleration: w, settings: m, isShiftPressed: y, isAltPressed: b, withFrameSelection: Z, isSpacePressed: A }) => {
1080
- const [T, S] = $({ mode: "default" }), { registerDoubleClickEvent: V, unRegisterDoubleClickEvent: I } = (() => {
1081
- const p = te(void 0), Q = te(void 0), M = (L) => {
1082
- const P = Date.now();
1083
- p.current && P < p.current + 300 && Q.current?.(L), p.current = Date.now();
1062
+ ee(() => {
1063
+ D.current || (D.current = !0, a && Yt.current?.(a, { clearHistory: !0, source: "remote" }));
1064
+ }, [a]);
1065
+ const zn = $(async (ae) => {
1066
+ const ce = await (async (Ze) => new Promise((Ye, Ue) => {
1067
+ const Je = new FileReader();
1068
+ Je.onload = (et) => {
1069
+ const Qe = et.target?.result;
1070
+ if (!Qe) return Ue("Impossible de récupérer les données du fichier");
1071
+ const He = JSON.parse(Qe);
1072
+ Ye(He);
1073
+ }, Je.readAsText(Ze);
1074
+ }))(ae);
1075
+ await Ke(ce.shapes ?? [], { clearHistory: !0, source: "remote" });
1076
+ }, [Ke]), An = $(() => {
1077
+ typeof M != "string" ? Ke(M(), { clearHistory: !1, source: "user" }) : M === "defaultShapes" && a !== void 0 ? Ke(a, { clearHistory: !1, source: "user" }) : Qt([], { clearHistory: !1, source: "user" });
1078
+ }, [Qt, Ke, a, M]);
1079
+ ee(() => {
1080
+ le(ri(g, Q || k));
1081
+ }, [g, Q, k]);
1082
+ const Va = { canvas: P, editor: y, setEditor: A };
1083
+ 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: ne, addPictureShape: _e, moveShapes: Wt, toggleShapeVisibility: Cn, toggleShapeLock: xn, canGoBackward: Mn, canGoForward: kn, canClear: Pn, selectedShape: fe, saveShapes: xa, removeShape: me, updateShape: mt, backwardShape: $e, forwardShape: it, refs: Va, width: e, height: t, selectTool: $t, selectShapes: La, activeTool: B, setActiveTool: Y, setAvailableTools: le, isEditMode: H, availableTools: R, gridGap: v, setGridGap: w, loadFile: zn, exportPicture: Vn, exportData: Ln, clearCanvas: An, settings: K, setCanvasZoom: z, resetZoom: oe, canvas: { canGrow: d, canShrink: h, layersManipulation: c, withExport: m, withLoadAndSave: p, withUploadPicture: Q, withUrlPicture: k } }, canvasProps: { shapesRef: ne, selectedShape: fe, selectionFrame: We, hoveredShape: Oe, addShape: ke, setSelectedShape: je, setSelectionFrame: Ot, refreshSelectedShapes: Ft, refreshHoveredShape: Bt, removeShape: me, updateShape: mt, duplicateShapes: ve, backwardShape: $e, forwardShape: it, saveShapes: xa, refs: Va, width: e, height: t, settings: K, setCanvasSize: T, setCanvasOffset: F, setCanvasZoom: z, resetZoom: oe, selectShapes: La, activeTool: B, setActiveTool: Y, isInsideComponent: se, isInsideCanvas: ye, isEditMode: H, canvas: { withSkeleton: L, withFrameSelection: C, canGrow: d, canShrink: h }, canvasOffsetStartData: E, setCanvasOffsetStartData: W, selectionMode: j, setSelectionMode: V, setCanvasMoveAcceleration: Ma, isShiftPressed: Me, isAltPressed: te, isSpacePressed: G, setShiftPressed: pe, setAltPressed: ge, setIsSpacePressed: Se }, registerEvent: Ie, unregisterEvent: ze, resetCanvas: Tn, resetZoom: oe, getCurrentImage: Zn, getCurrentData: Hn, setCanvasOffset: F, setCanvasZoom: z };
1084
+ }, Mo = ({ addShapes: e, drawCanvasRef: t, setActiveTool: a, refreshHoveredShape: i, shapes: n, selectionMode: o, activeTool: c, isInsideComponent: r, setCanvasOffset: s, selectedShape: l, canvasOffsetStartData: u, refreshSelectedShapes: d, setSelectedShape: h, setSelectionFrame: m, setCanvasOffsetStartData: p, updateSingleShape: Q, duplicateShapes: k, saveShapes: L, setSelectionMode: C, setCanvasMoveAcceleration: M, settings: g, isShiftPressed: S, isAltPressed: Z, withFrameSelection: I, isSpacePressed: H }) => {
1085
+ const [y, P] = U({ mode: "default" }), { registerDoubleClickEvent: D, unRegisterDoubleClickEvent: A } = (() => {
1086
+ const v = ie(void 0), w = ie(void 0), b = (T) => {
1087
+ const x = Date.now();
1088
+ v.current && x < v.current + 300 && w.current?.(T), v.current = Date.now();
1084
1089
  };
1085
- return { registerDoubleClickEvent: (L, P) => {
1086
- Q.current = P, L.addEventListener("click", M), L.addEventListener("touchend", M);
1087
- }, unRegisterDoubleClickEvent: (L) => {
1088
- L.removeEventListener("click", M), L.removeEventListener("touchend", M);
1090
+ return { registerDoubleClickEvent: (T, x) => {
1091
+ w.current = x, T.addEventListener("click", b), T.addEventListener("touchend", b);
1092
+ }, unRegisterDoubleClickEvent: (T) => {
1093
+ T.removeEventListener("click", b), T.removeEventListener("touchend", b);
1089
1094
  } };
1090
- })(), N = te(null);
1091
- N.current = (p) => ((Q, M, L, P, E, W, O, z, ie, re, R, oe, G, le, ae) => {
1092
- if (st(Q) && Q.touches.length > 1) return;
1093
- const pe = M.current?.getContext("2d");
1095
+ })(), E = ie(null);
1096
+ E.current = (v) => ((w, b, T, x, O, N, F, z, oe, de, re, K, R, le, se, ye, Me) => {
1097
+ if (rt(w) && w.touches.length > 1) return;
1098
+ const pe = b.current?.getContext("2d");
1094
1099
  if (!pe) return;
1095
- const se = ot(Q, M.current, R);
1096
- if (P.mode === "selectionFrame") {
1097
- re(pe, se, R);
1098
- const q = sn(Q, M.current, R.canvasSize);
1099
- return void ae([Math.ceil(De(q[0] * R.canvasZoom < 50 ? q[0] * R.canvasZoom - 50 : q[0] * R.canvasZoom > R.canvasSize.width / R.canvasSize.scaleRatioWithNoZoom - 50 ? q[0] * R.canvasZoom - (R.canvasSize.width / R.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / R.canvasZoom), Math.ceil(De(q[1] * R.canvasZoom < 50 ? q[1] * R.canvasZoom - 50 : q[1] * R.canvasZoom > R.canvasSize.height / R.canvasSize.scaleRatioWithNoZoom - 50 ? q[1] * R.canvasZoom - (R.canvasSize.height / R.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / R.canvasZoom)]);
1100
+ const te = st(w, b.current, R);
1101
+ if (x.mode === "selectionFrame") {
1102
+ K(pe, te, R);
1103
+ const G = ln(w, b.current, R.canvasSize);
1104
+ return void Me([Math.ceil(Ne(G[0] * R.canvasZoom < 50 ? G[0] * R.canvasZoom - 50 : G[0] * R.canvasZoom > R.canvasSize.width / R.canvasSize.scaleRatioWithNoZoom - 50 ? G[0] * R.canvasZoom - (R.canvasSize.width / R.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / R.canvasZoom), Math.ceil(Ne(G[1] * R.canvasZoom < 50 ? G[1] * R.canvasZoom - 50 : G[1] * R.canvasZoom > R.canvasSize.height / R.canvasSize.scaleRatioWithNoZoom - 50 ? G[1] * R.canvasZoom - (R.canvasSize.height / R.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / R.canvasZoom)]);
1100
1105
  }
1101
- if (E !== void 0) return void ie([se[0] + R.canvasOffset[0] - E.start[0], se[1] + R.canvasOffset[1] - E.start[1]]);
1102
- if (P.mode === "preview") {
1103
- const q = j(L)[0];
1104
- if (q?.type === "curve") {
1105
- const he = Gi(q, se, R, !0);
1106
- return void le(be([he], R));
1106
+ if (N !== void 0) return void re([te[0] + R.canvasOffset[0] - N.start[0], te[1] + R.canvasOffset[1] - N.start[1]]);
1107
+ if (x.mode === "preview") {
1108
+ const G = _(T)[0];
1109
+ if (G?.type === "curve") {
1110
+ const Se = _a(G, te, R, !0);
1111
+ return void ye(we([Se], R));
1107
1112
  }
1108
- if (q?.type === "polygon") {
1109
- const he = Xi(q, se, R, !0);
1110
- return void le(be([he], R));
1113
+ if (G?.type === "polygon") {
1114
+ const Se = qa(G, te, R, !0);
1115
+ return void ye(we([Se], R));
1111
1116
  }
1112
1117
  }
1113
- const ge = ft(se, R);
1114
- if (st(Q) || O(Q, pe, se, ge), L === void 0 || L.locked) W({ mode: "default", outOfView: !ge });
1115
- else if (P.mode === "default" || P.mode === "textedition") {
1116
- if (!ge) return void W({ mode: "default" });
1117
- W(mt(pe, L, se, R, !0) || { mode: "default" });
1118
- } else {
1119
- const q = M.current?.getContext("2d");
1120
- if (!q) return;
1121
- const he = Rn(q, L, se, P, R, oe, G);
1122
- z(j(he));
1118
+ const ge = yt(te, R);
1119
+ if (rt(w) || z(w, pe, te, ge), T === void 0 || T.locked) F({ mode: "default", outOfView: !ge });
1120
+ else {
1121
+ if (x.mode === "default" || x.mode === "textedition") {
1122
+ if (!ge) return void F({ mode: "default" });
1123
+ F(ht(pe, T, te, R, !0) || { mode: "default" });
1124
+ } else {
1125
+ const G = b.current?.getContext("2d");
1126
+ if (!G) return;
1127
+ const Se = Wn(G, T, te, x, R, le, se);
1128
+ oe(_(Se));
1129
+ }
1130
+ x.mode === "translate" && se && !x.hasBeenDuplicated && (O({ ...x, hasBeenDuplicated: !0 }), de(_(x.originalShape)));
1123
1131
  }
1124
- })(p, t, c, o, u, S, a, x, s, d, m, y, b, h, w), J(() => {
1125
- if (l) {
1126
- const p = (Q) => N.current?.(Q);
1127
- return document.addEventListener("mousemove", p), document.addEventListener("touchmove", p), () => {
1128
- document.removeEventListener("mousemove", p), document.removeEventListener("touchmove", p);
1132
+ })(v, t, l, o, C, u, P, i, Q, k, s, d, g, S, Z, h, M), ee(() => {
1133
+ if (r) {
1134
+ const v = (w) => E.current?.(w);
1135
+ return document.addEventListener("mousemove", v), document.addEventListener("touchmove", v), () => {
1136
+ document.removeEventListener("mousemove", v), document.removeEventListener("touchmove", v);
1129
1137
  };
1130
1138
  }
1131
- }, [l]);
1132
- const { isBrushShapeDoneOnMouseUp: H } = m, D = te(null);
1133
- D.current = (p) => {
1134
- if (st(p) && p.touches.length > 1) return;
1135
- const Q = t.current?.getContext("2d");
1136
- if (!Q) return;
1137
- if ("button" in p && p.button === 2) return h(void 0), i(Fe), k({ mode: "default" }), void f(void 0);
1138
- if (u) return void g(void 0);
1139
+ }, [r]);
1140
+ const { isBrushShapeDoneOnMouseUp: W } = g, B = ie(null);
1141
+ B.current = (v) => {
1142
+ if (rt(v) && v.touches.length > 1) return;
1143
+ const w = t.current?.getContext("2d");
1144
+ if (!w) return;
1145
+ if ("button" in v && v.button === 2) return h(void 0), a(Be), C({ mode: "default" }), void m(void 0);
1146
+ if (u) return void p(void 0);
1139
1147
  if (o.mode === "textedition" || o.mode === "preview") return;
1140
- const M = ot(p, t.current, m);
1141
- if (o.mode === "translate" && Date.now() - o.dateStart <= 500 && M[0] === o.cursorStartPosition[0] && M[1] === o.cursorStartPosition[1]) {
1142
- if (!(p.ctrlKey || p.shiftKey || p.metaKey)) {
1143
- const { shape: L } = Bi(Q, n, M, m, void 0, st(p), Z, !1);
1144
- h(L);
1148
+ const b = st(v, t.current, g);
1149
+ if (o.mode === "translate" && Date.now() - o.dateStart <= 500 && b[0] === o.cursorStartPosition[0] && b[1] === o.cursorStartPosition[1]) {
1150
+ if (!(v.ctrlKey || v.shiftKey || v.metaKey)) {
1151
+ const { shape: T } = Ya(w, n, b, g, void 0, rt(v), I, !1);
1152
+ h(T);
1145
1153
  }
1146
- return k({ mode: "default" }), f(void 0), void C();
1154
+ return C({ mode: "default" }), m(void 0), void L();
1147
1155
  }
1148
- o.mode !== "default" && (o.mode === "brush" && H && h(void 0), k({ mode: "default" }), f(void 0), C());
1149
- }, J(() => {
1150
- if (l) {
1151
- const p = (Q) => D.current?.(Q);
1152
- return document.addEventListener("mouseup", p), document.addEventListener("touchend", p), () => {
1153
- document.removeEventListener("mouseup", p), document.removeEventListener("touchend", p);
1156
+ o.mode !== "default" && (o.mode === "brush" && W && h(void 0), C({ mode: "default" }), m(void 0), L());
1157
+ }, ee(() => {
1158
+ if (r) {
1159
+ const v = (w) => B.current?.(w);
1160
+ return document.addEventListener("mouseup", v), document.addEventListener("touchend", v), () => {
1161
+ document.removeEventListener("mouseup", v), document.removeEventListener("touchend", v);
1154
1162
  };
1155
1163
  }
1156
- }, [l]);
1157
- const U = !m.features.edition && m.features.zoom, F = !m.features.edition && !m.features.zoom, X = te(null);
1158
- return X.current = (p, Q, M) => {
1159
- if (p.preventDefault(), st(p) && p.touches.length > 1) return;
1160
- const L = Q?.getContext("2d");
1161
- if (!L) return;
1162
- Q.focus();
1163
- const P = ot(p, t.current, m), E = "button" in p && p.button === 1;
1164
- if (!("button" in p && p.button === 2)) {
1165
- if (E || M || r.type === "move") g({ start: P, originalOffset: m.canvasOffset });
1166
- else if (!U) {
1167
- if (!ft(P, m)) return h(void 0), void k({ mode: "default" });
1168
- if (r.type === "selection") {
1169
- const W = p.ctrlKey || p.shiftKey || p.metaKey, { shape: O, mode: z } = Bi(L, n, P, m, c, st(p), Z, W);
1170
- h(O), k(z), z.mode === "selectionFrame" && f({ oldSelection: O, frame: [[P[0], P[1]], [P[0], P[1]]] });
1171
- } else if ($a.some((W) => W === r.type)) {
1172
- const W = j(c)[0], O = t.current?.getContext("2d");
1173
- if (!O) return;
1174
- if (r.type === "brush") {
1175
- if (W?.type === "brush") {
1176
- const z = ((ie, re, R) => {
1177
- const oe = { ...ie, points: Pe(ie.points.length, [[Math.round(re[0]), Math.round(re[1])]], ie.points) };
1178
- return ht(oe, R);
1179
- })(W, P, m);
1180
- x([z]);
1164
+ }, [r]);
1165
+ const Y = !g.features.edition && g.features.zoom, j = !g.features.edition && !g.features.zoom, V = ie(null);
1166
+ return V.current = (v, w, b) => {
1167
+ if (v.preventDefault(), rt(v) && v.touches.length > 1) return;
1168
+ const T = w?.getContext("2d");
1169
+ if (!T) return;
1170
+ w.focus();
1171
+ const x = st(v, t.current, g), O = "button" in v && v.button === 1;
1172
+ if (!("button" in v && v.button === 2)) {
1173
+ if (O || b || c.type === "move") p({ start: x, originalOffset: g.canvasOffset });
1174
+ else if (!Y) {
1175
+ if (!yt(x, g)) return h(void 0), void C({ mode: "default" });
1176
+ if (c.type === "selection") {
1177
+ const N = v.ctrlKey || v.shiftKey || v.metaKey, { shape: F, mode: z } = Ya(T, n, x, g, l, rt(v), I, N);
1178
+ h(F), C(z), z.mode === "selectionFrame" && m({ oldSelection: F, frame: [[x[0], x[1]], [x[0], x[1]]] });
1179
+ } else if (Ui.some((N) => N === c.type)) {
1180
+ const N = _(l)[0], F = t.current?.getContext("2d");
1181
+ if (!F) return;
1182
+ if (c.type === "brush") {
1183
+ if (N?.type === "brush") {
1184
+ const z = ((oe, de, re) => {
1185
+ const K = { ...oe, points: Ve(oe.points.length, [[Math.round(de[0]), Math.round(de[1])]], oe.points) };
1186
+ return pt(K, re);
1187
+ })(N, x, g);
1188
+ Q([z]);
1181
1189
  } else {
1182
- const z = ji(O, r, P, m);
1190
+ const z = Ja(F, c, x, g);
1183
1191
  if (!z) return;
1184
- e([z]), h(be([z], m));
1192
+ e([z]), h(we([z], g));
1185
1193
  }
1186
- k({ mode: "brush" });
1187
- } else if (o.mode !== "preview" || W?.type !== "polygon" && W?.type !== "curve") {
1188
- if (r.type !== "picture") {
1189
- const z = ji(O, r, P, m);
1194
+ C({ mode: "brush" });
1195
+ } else if (o.mode !== "preview" || N?.type !== "polygon" && N?.type !== "curve") {
1196
+ if (c.type !== "picture") {
1197
+ const z = Ja(F, c, x, g);
1190
1198
  if (!z) return;
1191
1199
  e([z]);
1192
- const ie = be([z], m);
1193
- h(ie), z.type === "polygon" || z.type === "curve" ? k({ mode: "preview" }) : (i(Fe), k({ mode: "resize", cursorStartPosition: [P[0] + m.selectionPadding, P[1] + m.selectionPadding], originalShape: ie, anchor: z.type === "line" ? 0 : [1, 1] }));
1200
+ const oe = we([z], g);
1201
+ h(oe), z.type === "polygon" || z.type === "curve" ? C({ mode: "preview" }) : (a(Be), C({ mode: "resize", cursorStartPosition: [x[0] + g.selectionPadding, x[1] + g.selectionPadding], originalShape: oe, anchor: z.type === "line" ? 0 : [1, 1] }));
1194
1202
  }
1195
1203
  } else {
1196
- const z = W.type === "polygon" ? Xi(W, P, m) : Gi(W, P, m);
1197
- h(be([z], m)), x([z], !0);
1204
+ const z = N.type === "polygon" ? qa(N, x, g) : _a(N, x, g);
1205
+ h(we([z], g)), Q([z], !0);
1198
1206
  }
1199
1207
  }
1200
1208
  }
1201
1209
  }
1202
- }, J(() => {
1203
- if (F) return;
1204
- const p = t.current;
1205
- if (!p) return;
1206
- const Q = (M) => X.current?.(M, p, A);
1207
- return p.addEventListener("mousedown", Q, { passive: !1 }), p.addEventListener("touchstart", Q, { passive: !1 }), () => {
1208
- p.removeEventListener("mousedown", Q), p.removeEventListener("touchstart", Q);
1210
+ }, ee(() => {
1211
+ if (j) return;
1212
+ const v = t.current;
1213
+ if (!v) return;
1214
+ const w = (b) => V.current?.(b, v, H);
1215
+ return v.addEventListener("mousedown", w, { passive: !1 }), v.addEventListener("touchstart", w, { passive: !1 }), () => {
1216
+ v.removeEventListener("mousedown", w), v.removeEventListener("touchstart", w);
1209
1217
  };
1210
- }, [F, t, A]), J(() => {
1211
- const p = t.current, Q = t.current?.getContext("2d");
1212
- if (!(!p || !Q))
1213
- return l ? (V(p, (M) => {
1214
- if (r.type === "selection") {
1215
- if (j(c).length !== 1) return;
1216
- const L = j(c)[0];
1217
- if (L?.type === "text") {
1218
- const P = ot(M, t.current, m);
1219
- return ft(P, m) ? void (mt(Q, c, P, m) && k({ mode: "textedition", defaultValue: L.value })) : void 0;
1218
+ }, [j, t, H]), ee(() => {
1219
+ const v = t.current, w = t.current?.getContext("2d");
1220
+ if (!(!v || !w))
1221
+ return r ? (D(v, (b) => {
1222
+ if (c.type === "selection") {
1223
+ if (_(l).length !== 1) return;
1224
+ const T = _(l)[0];
1225
+ if (T?.type === "text") {
1226
+ const x = st(b, t.current, g);
1227
+ return yt(x, g) ? void (ht(w, l, x, g) && C({ mode: "textedition", defaultValue: T.value })) : void 0;
1220
1228
  }
1221
- if (L?.type === "polygon") {
1222
- const P = ot(M, t.current, m);
1223
- if (!ft(P, m)) return;
1224
- const E = Yi(Q, L, P, m);
1225
- return void (E && x([Kn(L, E.lineIndex, P, m)]));
1229
+ if (T?.type === "polygon") {
1230
+ const x = st(b, t.current, g);
1231
+ if (!yt(x, g)) return;
1232
+ const O = Xa(w, T, x, g);
1233
+ return void (O && Q([Jn(T, O.lineIndex, x, g)]));
1226
1234
  }
1227
- if (L?.type === "curve") {
1228
- const P = ot(M, t.current, m);
1229
- if (!ft(P, m)) return;
1230
- const E = ((W, O, z, ie, re = 50) => {
1231
- if (O.locked || O.points.length < 2) return !1;
1232
- if (O.points.length < 3) return Yi(W, O, z, ie, re);
1233
- const { center: R } = O.computed, oe = Ae(z, O.rotation ?? 0, R);
1234
- W.lineWidth = (O.style?.lineWidth ?? 0) + re / ie.canvasZoom;
1235
- const G = pi(O, O.points), le = new Path2D();
1236
- le.moveTo(...G[0]);
1237
- for (let ae = 1; ae < G.length - 2; ae++) {
1238
- const pe = G[ae - 1], se = G[ae], ge = G[ae + 1], q = G[ae + 2], { cp1: he, cp2: ce } = gi(pe, se, ge, q);
1239
- if (le.bezierCurveTo(he[0], he[1], ce[0], ce[1], ge[0], ge[1]), W.isPointInStroke(le, oe[0], oe[1])) return { lineIndex: ae - 1 };
1235
+ if (T?.type === "curve") {
1236
+ const x = st(b, t.current, g);
1237
+ if (!yt(x, g)) return;
1238
+ const O = ((N, F, z, oe, de = 50) => {
1239
+ if (F.locked || F.points.length < 2) return !1;
1240
+ if (F.points.length < 3) return Xa(N, F, z, oe, de);
1241
+ const { center: re } = F.computed, K = Ee(z, F.rotation ?? 0, re);
1242
+ N.lineWidth = (F.style?.lineWidth ?? 0) + de / oe.canvasZoom;
1243
+ const R = ga(F, F.points), le = new Path2D();
1244
+ le.moveTo(...R[0]);
1245
+ for (let se = 1; se < R.length - 2; se++) {
1246
+ const ye = R[se - 1], Me = R[se], pe = R[se + 1], te = R[se + 2], { cp1: ge, cp2: G } = fa(ye, Me, pe, te);
1247
+ if (le.bezierCurveTo(ge[0], ge[1], G[0], G[1], pe[0], pe[1]), N.isPointInStroke(le, K[0], K[1])) return { lineIndex: se - 1 };
1240
1248
  }
1241
1249
  return !1;
1242
- })(Q, L, P, m);
1243
- return void (E && x([to(L, E.lineIndex, P, m)]));
1250
+ })(w, T, x, g);
1251
+ return void (O && Q([ao(T, O.lineIndex, x, g)]));
1244
1252
  }
1245
1253
  }
1246
1254
  }), () => {
1247
- I(p);
1255
+ A(v);
1248
1256
  }) : void 0;
1249
- }, [x, V, I, l, t, r, c, k, m]), { hoverMode: T };
1250
- }, Qn = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => Qn(t)).join("") : e.nodeValue ?? "", Mo = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: a, saveShapes: n, settings: o }) => {
1251
- const r = te(null), l = te(n);
1252
- J(() => {
1253
- if (!r.current) return;
1254
- const c = r.current, u = (d) => {
1257
+ }, [Q, D, A, r, t, c, l, C, g]), { hoverMode: y };
1258
+ }, wn = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => wn(t)).join("") : e.nodeValue ?? "", ko = ({ disabled: e = !1, shape: t, defaultValue: a, updateValue: i, saveShapes: n, settings: o }) => {
1259
+ const c = ie(null), r = ie(n);
1260
+ ee(() => {
1261
+ if (!c.current) return;
1262
+ const l = c.current, u = (d) => {
1255
1263
  d.preventDefault();
1256
1264
  const h = d.clipboardData?.getData("text/plain");
1257
1265
  document.execCommand("insertText", !1, h);
1258
1266
  };
1259
- c.addEventListener("paste", u), c.innerText = "";
1260
- for (const d of i) {
1267
+ l.addEventListener("paste", u), l.innerText = "";
1268
+ for (const d of a) {
1261
1269
  const h = document.createElement("div");
1262
- d === "" ? h.innerHTML = "<br/>" : h.innerText = d, c.appendChild(h);
1270
+ d === "" ? h.innerHTML = "<br/>" : h.innerText = d, l.appendChild(h);
1263
1271
  }
1264
- return c.focus(), () => {
1265
- c.removeEventListener("paste", u);
1272
+ return l.focus(), () => {
1273
+ l.removeEventListener("paste", u);
1266
1274
  };
1267
- }, [i]), J(() => {
1268
- const c = l.current;
1275
+ }, [a]), ee(() => {
1276
+ const l = r.current;
1269
1277
  return () => {
1270
- c();
1278
+ l();
1271
1279
  };
1272
1280
  }, []);
1273
- const s = ba(() => {
1274
- const { borders: c, center: u } = t.computed;
1275
- return xe({ point: [c.x, c.y], rotation: -(t.rotation ?? 0), origin: u });
1281
+ const s = Ci(() => {
1282
+ const { borders: l, center: u } = t.computed;
1283
+ return Ce({ point: [l.x, l.y], rotation: -(t.rotation ?? 0), origin: u });
1276
1284
  }, [t]);
1277
- return v("div", { className: "react-paint-editor-toolbox-edittextbox", ref: r, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: !e, onInput: (c) => {
1278
- const u = Array.from(c.target.childNodes).map((d) => Qn(d));
1279
- a(u);
1280
- }, style: { "--react-paint-editor-toolbox-edittextbox-transform": `translate3D(${(s[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio}px, ${(s[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio}px, 0) rotate(${ti(t.rotation ?? 0)}deg)`, "--react-paint-editor-toolbox-edittextbox-fontsize": t.fontSize * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-padding": o.selectionPadding * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-color": t.style?.strokeColor ?? "inherit", "--react-paint-editor-toolbox-edittextbox-opacity": (t.style?.opacity ?? 100) / 100, "--react-paint-editor-toolbox-edittextbox-fontfamily": t.style?.fontFamily ?? yt } });
1281
- }, ko = (e, t, i, a, n) => {
1282
- qa(e), ((o, r) => {
1283
- const { canvasZoom: l, size: s, canvasSize: { width: c, height: u } } = r;
1284
- if (s !== "fixed" || l >= 1) return;
1285
- o.fillStyle = "#f5f5f5", o.fillRect(0, 0, c, u);
1286
- const d = ln(r);
1287
- o.clearRect(d.x, d.y, d.width, d.height), cn(o, r);
1288
- })(e, i), ((o, r) => {
1289
- const { canvasSize: { width: l, height: s }, gridGap: c, canvasOffset: u, canvasSize: { scaleRatio: d } } = r;
1290
- if (!c) return;
1285
+ return f("div", { className: "react-paint-editor-toolbox-edittextbox", ref: c, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: !e, onInput: (l) => {
1286
+ const u = Array.from(l.target.childNodes).map((d) => wn(d));
1287
+ i(u);
1288
+ }, style: { "--react-paint-editor-toolbox-edittextbox-transform": `translate3D(${(s[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio}px, ${(s[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio}px, 0) rotate(${aa(t.rotation ?? 0)}deg)`, "--react-paint-editor-toolbox-edittextbox-fontsize": t.fontSize * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-padding": o.selectionPadding * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-color": t.style?.strokeColor ?? "inherit", "--react-paint-editor-toolbox-edittextbox-opacity": (t.style?.opacity ?? 100) / 100, "--react-paint-editor-toolbox-edittextbox-fontfamily": t.style?.fontFamily ?? St } });
1289
+ }, Po = (e, t, a, i, n) => {
1290
+ ji(e), ((o, c) => {
1291
+ const { canvasZoom: r, size: s, canvasSize: { width: l, height: u } } = c;
1292
+ if (s !== "fixed" || r >= 1) return;
1293
+ o.fillStyle = "#f5f5f5", o.fillRect(0, 0, l, u);
1294
+ const d = dn(c);
1295
+ o.clearRect(d.x, d.y, d.width, d.height), hn(o, c);
1296
+ })(e, a), ((o, c) => {
1297
+ const { canvasSize: { width: r, height: s }, gridGap: l, canvasOffset: u, canvasSize: { scaleRatio: d } } = c;
1298
+ if (!l) return;
1291
1299
  o.strokeStyle = "rgb(220,220,220)", o.lineWidth = 1, o.save(), o.scale(d, d), o.beginPath();
1292
- const h = u[0] % c, f = u[1] % c, g = Math.ceil(l / d / c) + 2, x = Math.ceil(s / d / c) + 2;
1293
- for (let C = -5; C < g; C++) o.moveTo(h + (C + 1) * c, f - c), o.lineTo(h + (C + 1) * c, f + s / d + c);
1294
- for (let C = -5; C < x; C++) o.moveTo(h - c, f + (C + 1) * c), o.lineTo(h + l / d + c, f + (C + 1) * c);
1300
+ const h = u[0] % l, m = u[1] % l, p = Math.ceil(r / d / l) + 2, Q = Math.ceil(s / d / l) + 2;
1301
+ for (let k = -5; k < p; k++) o.moveTo(h + (k + 1) * l, m - l), o.lineTo(h + (k + 1) * l, m + s / d + l);
1302
+ for (let k = -5; k < Q; k++) o.moveTo(h - l, m + (k + 1) * l), o.lineTo(h + r / d + l, m + (k + 1) * l);
1295
1303
  o.stroke(), o.restore();
1296
- })(e, i);
1297
- for (let o = a.length - 1; o >= 0; o--) t.mode === "textedition" && a[o] === n || fn(e, j(n).find((r) => r.id === a[o].id) ?? a[o], i);
1298
- }, Po = si.forwardRef(({ canGrow: e, shapes: t, addShapes: i, updateSingleShape: a, selectedShape: n, setSelectedShape: o, setSelectionFrame: r, hoveredShape: l, selectionFrame: s, refreshHoveredShape: c, refreshSelectedShapes: u, saveShapes: d, activeTool: h, setActiveTool: f, canvasOffsetStartData: g, setCanvasOffsetStartData: x, setCanvasOffset: C, setCanvasMoveAcceleration: k, isInsideComponent: w, selectionMode: m, setSelectionMode: y, selectionWidth: b, selectionColor: Z, settings: A, isEditMode: T, isShiftPressed: S, isAltPressed: V, isSpacePressed: I, withFrameSelection: N, withSkeleton: H }, D) => {
1299
- const U = te(null), F = te(null), X = A.canvasSize, p = T, Q = T ? 0 : -1;
1300
- xa(D, () => U.current);
1301
- const { hoverMode: M } = Co({ addShapes: i, drawCanvasRef: U, setActiveTool: f, shapes: t, selectionMode: m, activeTool: h, isInsideComponent: w, setCanvasOffset: C, selectedShape: n, canvasOffsetStartData: g, setCanvasOffsetStartData: x, setSelectedShape: o, setSelectionFrame: r, refreshHoveredShape: c, refreshSelectedShapes: u, updateSingleShape: a, saveShapes: d, setSelectionMode: y, setCanvasMoveAcceleration: k, isShiftPressed: S, isAltPressed: V, withFrameSelection: N, settings: A, isSpacePressed: I }), L = B((E) => {
1302
- const W = j(n)[0];
1303
- if (W?.type !== "text") return;
1304
- const O = U.current?.getContext("2d");
1305
- if (!O) return;
1306
- const z = dt(po(O, W, E, A), A);
1307
- a([z]);
1308
- }, [a, n, A]), P = (E) => {
1309
- if (T) return E.preventDefault(), E.stopPropagation(), !1;
1304
+ })(e, a);
1305
+ for (let o = i.length - 1; o >= 0; o--) t.mode === "textedition" && i[o] === n || yn(e, _(n).find((c) => c.id === i[o].id) ?? i[o], a);
1306
+ }, Lo = ra.forwardRef(({ canGrow: e, shapes: t, duplicateShapes: a, addShapes: i, updateSingleShape: n, selectedShape: o, setSelectedShape: c, setSelectionFrame: r, hoveredShape: s, selectionFrame: l, refreshHoveredShape: u, refreshSelectedShapes: d, saveShapes: h, activeTool: m, setActiveTool: p, canvasOffsetStartData: Q, setCanvasOffsetStartData: k, setCanvasOffset: L, setCanvasMoveAcceleration: C, isInsideComponent: M, selectionMode: g, setSelectionMode: S, selectionWidth: Z, selectionColor: I, settings: H, isEditMode: y, isShiftPressed: P, isAltPressed: D, isSpacePressed: A, withFrameSelection: E, withSkeleton: W }, B) => {
1307
+ const Y = ie(null), j = ie(null), V = H.canvasSize, v = y, w = y ? 0 : -1;
1308
+ xi(B, () => Y.current);
1309
+ const { hoverMode: b } = Mo({ addShapes: i, drawCanvasRef: Y, setActiveTool: p, shapes: t, selectionMode: g, activeTool: m, isInsideComponent: M, setCanvasOffset: L, selectedShape: o, canvasOffsetStartData: Q, setCanvasOffsetStartData: k, setSelectedShape: c, setSelectionFrame: r, refreshHoveredShape: u, refreshSelectedShapes: d, updateSingleShape: n, duplicateShapes: a, saveShapes: h, setSelectionMode: S, setCanvasMoveAcceleration: C, isShiftPressed: P, isAltPressed: D, withFrameSelection: E, settings: H, isSpacePressed: A }), T = $((O) => {
1310
+ const N = _(o)[0];
1311
+ if (N?.type !== "text") return;
1312
+ const F = Y.current?.getContext("2d");
1313
+ if (!F) return;
1314
+ const z = ut(go(F, N, O, H), H);
1315
+ n([z]);
1316
+ }, [n, o, H]), x = (O) => {
1317
+ if (y) return O.preventDefault(), O.stopPropagation(), !1;
1310
1318
  };
1311
- return J(() => {
1312
- const E = U.current?.getContext("2d");
1313
- E && window.requestAnimationFrame(() => ko(E, m, A, t, n));
1314
- }, [t, m, n, A]), J(() => {
1315
- const E = F.current?.getContext("2d");
1316
- E && window.requestAnimationFrame(() => ((W, O, z, ie, re, R, oe, G, le, ae, pe) => {
1317
- W.reset(), cn(W, z), pe && G && !j(oe).find((se) => se.id === G.id) && ie.type === "selection" && O.mode === "default" && Ji({ ctx: W, shape: G, settings: z, selectionWidth: re, selectionColor: R, hoverMode: le, withAnchors: !1 }), oe && ie.type !== "brush" && Ji({ ctx: W, shape: oe, settings: z, selectionWidth: re, selectionColor: R, hoverMode: le, withAnchors: O.mode !== "textedition" }), ae && mo({ ctx: W, selectionFrame: ae, settings: z });
1318
- })(E, m, A, h, b, Z, n, l, M, s, H));
1319
- }, [l, M, s, m, n, h, A, b, Z, H]), v("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": g ? "grabbing" : M.outOfView ? "default" : M.mode === "resize" ? "pointer" : h.type !== "selection" && h.type !== "move" ? "crosshair" : M.mode === "translate" ? "move" : M.mode === "rotate" || h.type === "move" || I ? "grab" : "default" }, children: Y("div", { className: "react-paint-canvas-container", "data-grow": e, children: [v("canvas", { className: Ya, ref: U, "data-grow": e, width: X.width, height: X.height, onContextMenu: P, tabIndex: Q }), p && v("canvas", { className: Ua, ref: F, width: X.width, height: X.height, "data-grow": e, onContextMenu: P }), T && m.mode === "textedition" && j(n)[0]?.type === "text" && v(Mo, { disabled: !A.features.edition, shape: j(n)[0], defaultValue: m.defaultValue, updateValue: L, saveShapes: d, settings: A })] }) });
1320
- }), sa = "ArrowUp", ra = "ArrowDown", la = "ArrowLeft", ca = "ArrowRight", Lo = "Delete", Zo = "Backspace", Vo = "Escape", da = "Shift", ha = "Alt", ua = "Option", Vt = " ", Ho = "z", To = "Z", zo = "y", Ao = "Y", Eo = "+", Io = "-", No = "0", pa = "copy", ga = "paste", Do = ({ isInsideComponent: e, isInsideCanvas: t, selectedShape: i, isEditingText: a, settings: n, setSelectedShape: o, setActiveTool: r, setCanvasZoom: l, resetZoom: s, setSelectionMode: c, setSelectionFrame: u, removeShape: d, pasteShapes: h, updateShapes: f, backwardShape: g, forwardShape: x, setShiftPressed: C, setAltPressed: k, setIsSpacePressed: w }) => {
1321
- const [m, y] = $(void 0);
1322
- return J(() => {
1323
- const b = (S) => {
1324
- i && (a || (S.preventDefault(), y({ ...i })));
1325
- }, Z = (S) => {
1326
- m && (a || (S.preventDefault(), h(((V, I) => j(V).map((N) => ({ ...oi([20, 20], N, [0, 0], I, !1), id: ye(`${N.type}_`) })))(m, n))));
1327
- }, A = (S) => {
1328
- switch (S.key) {
1329
- case da:
1330
- C(!1);
1331
- break;
1332
- case ha:
1333
- case ua:
1319
+ return ee(() => {
1320
+ const O = Y.current?.getContext("2d");
1321
+ O && window.requestAnimationFrame(() => Po(O, g, H, t, o));
1322
+ }, [t, g, o, H]), ee(() => {
1323
+ const O = j.current?.getContext("2d");
1324
+ O && window.requestAnimationFrame(() => ((N, F, z, oe, de, re, K, R, le, se, ye) => {
1325
+ N.reset(), hn(N, z), ye && R && !_(K).find((Me) => Me.id === R.id) && oe.type === "selection" && F.mode === "default" && ti({ ctx: N, shape: R, settings: z, selectionWidth: de, selectionColor: re, hoverMode: le, withAnchors: !1 }), K && oe.type !== "brush" && ti({ ctx: N, shape: K, settings: z, selectionWidth: de, selectionColor: re, hoverMode: le, withAnchors: F.mode !== "textedition" }), se && yo({ ctx: N, selectionFrame: se, settings: z });
1326
+ })(O, g, H, m, Z, I, o, s, b, l, W));
1327
+ }, [s, b, l, g, o, m, H, Z, I, W]), f("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": Q ? "grabbing" : b.outOfView ? "default" : b.mode === "resize" ? "pointer" : m.type !== "selection" && m.type !== "move" ? "crosshair" : b.mode === "translate" ? "move" : b.mode === "rotate" || m.type === "move" || A ? "grab" : "default" }, children: X("div", { className: "react-paint-canvas-container", "data-grow": e, children: [f("canvas", { className: Xi, ref: Y, "data-grow": e, width: V.width, height: V.height, onContextMenu: x, tabIndex: w }), v && f("canvas", { className: Gi, ref: j, width: V.width, height: V.height, "data-grow": e, onContextMenu: x }), y && g.mode === "textedition" && _(o)[0]?.type === "text" && f(ko, { disabled: !H.features.edition, shape: _(o)[0], defaultValue: g.defaultValue, updateValue: T, saveShapes: h, settings: H })] }) });
1328
+ }), li = "ArrowUp", ci = "ArrowDown", di = "ArrowLeft", hi = "ArrowRight", Vo = "Delete", Zo = "Backspace", Ho = "Escape", ui = "Shift", pi = "Alt", gi = "Option", Ht = " ", To = "z", zo = "Z", Ao = "y", Eo = "Y", Io = "+", Do = "-", No = "0", fi = "copy", vi = "paste", Ro = ({ isInsideComponent: e, isInsideCanvas: t, selectedShape: a, isEditingText: i, settings: n, setSelectedShape: o, setActiveTool: c, setCanvasZoom: r, resetZoom: s, setSelectionMode: l, setSelectionFrame: u, removeShape: d, pasteShapes: h, updateShapes: m, backwardShape: p, forwardShape: Q, setShiftPressed: k, setAltPressed: L, setIsSpacePressed: C }) => {
1329
+ const [M, g] = U(void 0);
1330
+ return ee(() => {
1331
+ const S = (y) => {
1332
+ a && (i || (y.preventDefault(), g({ ...a })));
1333
+ }, Z = (y) => {
1334
+ M && (i || (y.preventDefault(), h(((P, D) => _(P).map((A) => ({ ...sa([20, 20], A, [0, 0], D, !1), id: ue(`${A.type}_`) })))(M, n))));
1335
+ }, I = (y) => {
1336
+ switch (y.key) {
1337
+ case ui:
1334
1338
  k(!1);
1335
1339
  break;
1336
- case Vt:
1337
- w(!1);
1340
+ case pi:
1341
+ case gi:
1342
+ L(!1);
1343
+ break;
1344
+ case Ht:
1345
+ C(!1);
1338
1346
  }
1339
- }, T = (S) => {
1340
- if (S.metaKey || S.ctrlKey) {
1341
- if (S.key === To || S.key === Ho) return S.preventDefault(), S.stopPropagation(), void (S.shiftKey ? x() : g());
1342
- if (!Ga() && (S.key === Ao || S.key === zo)) return S.preventDefault(), S.stopPropagation(), void x();
1343
- if (S.key === Eo) return S.preventDefault(), S.stopPropagation(), void l("zoom");
1344
- if (S.key === Io) return S.preventDefault(), S.stopPropagation(), void l("unzoom");
1345
- if (S.key === No) return S.preventDefault(), S.stopPropagation(), void s();
1347
+ }, H = (y) => {
1348
+ if (y.metaKey || y.ctrlKey) {
1349
+ if (y.key === zo || y.key === To) return y.preventDefault(), y.stopPropagation(), void (y.shiftKey ? Q() : p());
1350
+ if (!_i() && (y.key === Eo || y.key === Ao)) return y.preventDefault(), y.stopPropagation(), void Q();
1351
+ if (y.key === Io) return y.preventDefault(), y.stopPropagation(), void r("zoom");
1352
+ if (y.key === Do) return y.preventDefault(), y.stopPropagation(), void r("unzoom");
1353
+ if (y.key === No) return y.preventDefault(), y.stopPropagation(), void s();
1346
1354
  }
1347
- if (S.key === da) return S.preventDefault(), S.stopPropagation(), void C(!0);
1348
- if (S.key === Vt && t) return S.preventDefault(), S.stopPropagation(), void w(!0);
1349
- if (S.key === ha || S.key === ua) return S.preventDefault(), S.stopPropagation(), void k(!0);
1350
- if (!i) return;
1351
- if (S.key === Vo) return o(void 0), r(Fe), c({ mode: "default" }), void u(void 0);
1352
- if (a) return;
1353
- const V = { [la]: [n.gridGap ? -n.gridGap : -1, 0], [ca]: [n.gridGap ? n.gridGap : 1, 0], [ra]: [0, n.gridGap ? n.gridGap : 1], [sa]: [0, n.gridGap ? -n.gridGap : -1] };
1354
- switch (S.key) {
1355
- case la:
1356
- case ca:
1357
- case ra:
1358
- case sa:
1359
- S.preventDefault(), S.stopPropagation(), f(((I, N, H, D, U) => j(N).map((F) => oi(I, F, H, D, U)))(V[S.key], i, [0, 0], n, !1));
1355
+ if (y.key === ui) return y.preventDefault(), y.stopPropagation(), void k(!0);
1356
+ if (y.key === Ht && t) return y.preventDefault(), y.stopPropagation(), void C(!0);
1357
+ if (y.key === pi || y.key === gi) return y.preventDefault(), y.stopPropagation(), void L(!0);
1358
+ if (!a) return;
1359
+ if (y.key === Ho) return o(void 0), c(Be), l({ mode: "default" }), void u(void 0);
1360
+ if (i) return;
1361
+ const P = { [di]: [n.gridGap ? -n.gridGap : -1, 0], [hi]: [n.gridGap ? n.gridGap : 1, 0], [ci]: [0, n.gridGap ? n.gridGap : 1], [li]: [0, n.gridGap ? -n.gridGap : -1] };
1362
+ switch (y.key) {
1363
+ case di:
1364
+ case hi:
1365
+ case ci:
1366
+ case li:
1367
+ y.preventDefault(), y.stopPropagation(), m(((D, A, E, W, B) => _(A).map((Y) => sa(D, Y, E, W, B)))(P[y.key], a, [0, 0], n, !1));
1360
1368
  break;
1361
- case Lo:
1369
+ case Vo:
1362
1370
  case Zo:
1363
- S.preventDefault(), S.stopPropagation(), d(j(i));
1371
+ y.preventDefault(), y.stopPropagation(), d(_(a));
1364
1372
  }
1365
1373
  };
1366
- if (e) return document.addEventListener("keydown", T), document.addEventListener("keyup", A), document.addEventListener(pa, b), document.addEventListener(ga, Z), () => {
1367
- document.removeEventListener("keydown", T), document.removeEventListener("keyup", A), document.removeEventListener(pa, b), document.removeEventListener(ga, Z);
1374
+ if (e) return document.addEventListener("keydown", H), document.addEventListener("keyup", I), document.addEventListener(fi, S), document.addEventListener(vi, Z), () => {
1375
+ document.removeEventListener("keydown", H), document.removeEventListener("keyup", I), document.removeEventListener(fi, S), document.removeEventListener(vi, Z);
1368
1376
  };
1369
- }, [e, t, m, a, i, n, f, d, o, h, g, x, C, k, r, c, u, l, s, w]), {};
1370
- }, gs = ({ options: e, className: t, style: i, canvasProps: a }) => {
1371
- const { shapesRef: n, selectedShape: o, selectionFrame: r, hoveredShape: l, addShape: s, setSelectedShape: c, setSelectionFrame: u, refreshSelectedShapes: d, refreshHoveredShape: h, removeShape: f, updateShape: g, backwardShape: x, forwardShape: C, saveShapes: k, refs: w, width: m, height: y, settings: b, setCanvasSize: Z, setCanvasOffset: A, selectShapes: T, activeTool: S, setActiveTool: V, isInsideComponent: I, isInsideCanvas: N, isEditMode: H, canvas: { withSkeleton: D, withFrameSelection: U, canGrow: F, canShrink: X }, canvasOffsetStartData: p, setCanvasOffsetStartData: Q, selectionMode: M, setSelectionMode: L, setCanvasMoveAcceleration: P, isShiftPressed: E, isAltPressed: W, isSpacePressed: O, setShiftPressed: z, setAltPressed: ie, setCanvasZoom: re, resetZoom: R, setIsSpacePressed: oe } = a, { canvasBackgroundColor: G, canvasSelectionColor: le, canvasSelectionWidth: ae } = { ...In, ...e }, pe = te(null), se = B((q) => {
1372
- s(q), T(q);
1373
- }, [s, T]), ge = B((q) => {
1374
- Z({ realWidth: m, realHeight: y, width: q, height: y * q / m, scaleRatio: q / m });
1375
- }, [m, y, Z]);
1376
- return Do({ isInsideComponent: I, isInsideCanvas: N, isEditingText: M.mode === "textedition", settings: b, selectedShape: o, setSelectedShape: c, removeShape: f, pasteShapes: se, updateShapes: g, backwardShape: x, forwardShape: C, setShiftPressed: z, setAltPressed: ie, setActiveTool: V, setSelectionMode: L, setSelectionFrame: u, setCanvasZoom: re, resetZoom: R, setIsSpacePressed: oe }), (({ onResized: q, element: he }) => {
1377
- J(() => {
1378
- const ce = he.current;
1379
- if (!ce) return;
1380
- const Ee = new ResizeObserver((Ie) => {
1381
- const He = Ie?.[0]?.borderBoxSize?.[0], { width: ve, height: ne } = He ? { width: He.inlineSize, height: He.blockSize } : Ie?.[0]?.contentRect ?? {};
1382
- ve !== void 0 && ne !== void 0 && q(ve, ne);
1377
+ }, [e, t, M, i, a, n, m, d, o, h, p, Q, k, L, c, l, u, r, s, C]), {};
1378
+ }, fs = ({ options: e, className: t, style: a, canvasProps: i }) => {
1379
+ const { shapesRef: n, selectedShape: o, selectionFrame: c, hoveredShape: r, addShape: s, setSelectedShape: l, setSelectionFrame: u, refreshSelectedShapes: d, refreshHoveredShape: h, duplicateShapes: m, removeShape: p, updateShape: Q, backwardShape: k, forwardShape: L, saveShapes: C, refs: M, width: g, height: S, settings: Z, setCanvasSize: I, setCanvasOffset: H, selectShapes: y, activeTool: P, setActiveTool: D, isInsideComponent: A, isInsideCanvas: E, isEditMode: W, canvas: { withSkeleton: B, withFrameSelection: Y, canGrow: j, canShrink: V }, canvasOffsetStartData: v, setCanvasOffsetStartData: w, selectionMode: b, setSelectionMode: T, setCanvasMoveAcceleration: x, isShiftPressed: O, isAltPressed: N, isSpacePressed: F, setShiftPressed: z, setAltPressed: oe, setCanvasZoom: de, resetZoom: re, setIsSpacePressed: K } = i, { canvasBackgroundColor: R, canvasSelectionColor: le, canvasSelectionWidth: se } = { ...Dn, ...e }, ye = ie(null), Me = $((te) => {
1380
+ s(te), y(te);
1381
+ }, [s, y]), pe = $((te) => {
1382
+ I({ realWidth: g, realHeight: S, width: te, height: S * te / g, scaleRatio: te / g });
1383
+ }, [g, S, I]);
1384
+ return Ro({ isInsideComponent: A, isInsideCanvas: E, isEditingText: b.mode === "textedition", settings: Z, selectedShape: o, setSelectedShape: l, removeShape: p, pasteShapes: Me, updateShapes: Q, backwardShape: k, forwardShape: L, setShiftPressed: z, setAltPressed: oe, setActiveTool: D, setSelectionMode: T, setSelectionFrame: u, setCanvasZoom: de, resetZoom: re, setIsSpacePressed: K }), (({ onResized: te, element: ge }) => {
1385
+ ee(() => {
1386
+ const G = ge.current;
1387
+ if (!G) return;
1388
+ const Se = new ResizeObserver((Ie) => {
1389
+ const ze = Ie?.[0]?.borderBoxSize?.[0], { width: ne, height: fe } = ze ? { width: ze.inlineSize, height: ze.blockSize } : Ie?.[0]?.contentRect ?? {};
1390
+ ne !== void 0 && fe !== void 0 && te(ne, fe);
1383
1391
  });
1384
- return Ee.observe(ce), () => {
1385
- Ee.unobserve(ce);
1392
+ return Se.observe(G), () => {
1393
+ Se.unobserve(G);
1386
1394
  };
1387
- }, [he, q]);
1388
- })({ element: pe, onResized: ge }), v("div", { ref: pe, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": F, "data-shrink": X, style: { "--react-paint-app-row-width": b.canvasSize.width, "--react-paint-app-canvaswidth": m, "--react-paint-app-canvasheight": y, "--react-paint-app-row-aspectratio": `calc(${b.canvasSize.width} / ${b.canvasSize.height})`, "--react-paint-app-canvas-bg": G, ...i }, children: v(Po, { isSpacePressed: O, ref: w.canvas, canGrow: F, isInsideComponent: I, activeTool: S, setActiveTool: V, canvasOffsetStartData: p, setCanvasOffsetStartData: Q, shapes: n.current, addShapes: s, updateSingleShape: g, selectedShape: o, selectionFrame: r, setSelectedShape: c, setSelectionFrame: u, hoveredShape: l, refreshHoveredShape: h, refreshSelectedShapes: d, settings: b, setCanvasOffset: A, saveShapes: k, selectionMode: M, setSelectionMode: L, setCanvasMoveAcceleration: P, selectionColor: le, selectionWidth: ae, isEditMode: H, isShiftPressed: E, isAltPressed: W, withFrameSelection: U, withSkeleton: D }) });
1389
- }, Ro = ({ isLoading: e = !1 }) => {
1390
- const [t, i] = $("hidden");
1391
- return J(() => {
1395
+ }, [ge, te]);
1396
+ })({ element: ye, onResized: pe }), f("div", { ref: ye, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": j, "data-shrink": V, style: { "--react-paint-app-row-width": Z.canvasSize.width, "--react-paint-app-canvaswidth": g, "--react-paint-app-canvasheight": S, "--react-paint-app-row-aspectratio": `calc(${Z.canvasSize.width} / ${Z.canvasSize.height})`, "--react-paint-app-canvas-bg": R, ...a }, children: f(Lo, { duplicateShapes: m, isSpacePressed: F, ref: M.canvas, canGrow: j, isInsideComponent: A, activeTool: P, setActiveTool: D, canvasOffsetStartData: v, setCanvasOffsetStartData: w, shapes: n.current, addShapes: s, updateSingleShape: Q, selectedShape: o, selectionFrame: c, setSelectedShape: l, setSelectionFrame: u, hoveredShape: r, refreshHoveredShape: h, refreshSelectedShapes: d, settings: Z, setCanvasOffset: H, saveShapes: C, selectionMode: b, setSelectionMode: T, setCanvasMoveAcceleration: x, selectionColor: le, selectionWidth: se, isEditMode: W, isShiftPressed: O, isAltPressed: N, withFrameSelection: Y, withSkeleton: B }) });
1397
+ }, Wo = ({ isLoading: e = !1 }) => {
1398
+ const [t, a] = U("hidden");
1399
+ return ee(() => {
1392
1400
  if (!e) {
1393
- i("fadeOut");
1394
- const a = setTimeout(() => i("hidden"), 300);
1401
+ a("fadeOut");
1402
+ const i = setTimeout(() => a("hidden"), 300);
1395
1403
  return () => {
1396
- clearTimeout(a);
1404
+ clearTimeout(i);
1397
1405
  };
1398
1406
  }
1399
- i("visible");
1400
- }, [e]), t === "hidden" ? null : v("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": An, "--react-paint-editor-loading-transition-duration": "300ms" }, children: Y("div", { className: "react-paint-editor-loader", children: [v("div", {}), v("div", {}), v("div", {}), v("div", {})] }) });
1401
- }, Wo = "infos", Oo = 4e3, Fo = ({ type: e, text: t, duration: i }) => {
1402
- const [a, n] = $(!1);
1403
- return J(() => {
1407
+ a("visible");
1408
+ }, [e]), t === "hidden" ? null : f("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": En, "--react-paint-editor-loading-transition-duration": "300ms" }, children: X("div", { className: "react-paint-editor-loader", children: [f("div", {}), f("div", {}), f("div", {}), f("div", {})] }) });
1409
+ }, Oo = "infos", Fo = 4e3, Bo = ({ type: e, text: t, duration: a }) => {
1410
+ const [i, n] = U(!1);
1411
+ return ee(() => {
1404
1412
  const o = setTimeout(() => {
1405
1413
  n(!0);
1406
- }, 100), r = setTimeout(() => {
1414
+ }, 100), c = setTimeout(() => {
1407
1415
  n(!1);
1408
- }, i - 500 - 100);
1416
+ }, a - 500 - 100);
1409
1417
  return () => {
1410
- clearTimeout(o), clearTimeout(r);
1418
+ clearTimeout(o), clearTimeout(c);
1411
1419
  };
1412
- }, [i]), v("div", { className: "react-paint-editor-snackbar", "data-is-shown": +a, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1413
- }, Bo = ({ snackbarList: e }) => v("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": En }, children: e.map((t) => v(Fo, { ...t }, t.id)) }), $o = si.forwardRef((e, t) => {
1414
- const { hidden: i = !1, disabled: a = !1, selected: n = !1, icon: o, children: r, className: l = "", title: s, onClick: c, ...u } = e, d = a ? -1 : 0, h = te(null);
1415
- return xa(t, () => h.current), Y("label", { className: `react-paint-editor-button ${l}`, title: s, onClick: c, "data-disabled": +a, "data-selected": +n, "data-hidden": +i, tabIndex: d, onKeyDown: (f) => {
1416
- f.key === Vt && (f.preventDefault(), f.stopPropagation());
1417
- }, onKeyUp: (f) => {
1418
- f.preventDefault(), f.stopPropagation(), f.key === Vt && h.current?.click();
1419
- }, children: [v("input", { ref: h, disabled: a, ...u }), Y("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), o && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] })] });
1420
- }), K = si.forwardRef((e, t) => {
1421
- if (e.type === "file" || e.type === "color") return v($o, { ...e, ref: t });
1422
- const { hidden: i = !1, disabled: a = !1, selected: n = !1, icon: o, children: r, type: l = "button", className: s = "", ...c } = e;
1423
- return v("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: a, "data-disabled": +a, "data-selected": +n, "data-hidden": +i, type: l, ...c, children: Y("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), o && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] }) });
1424
- }), tt = ({ children: e, title: t = "", className: i = "", position: a = "bottom", fitContainer: n = !1, alignment: o = "center", style: r, ...l }) => Y("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": n, "data-position": a, "data-alignment": o, style: { ...r, "--react-paint-editor-panel-zindex": Va }, ...l, children: [t && v("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), Yo = (e) => {
1420
+ }, [a]), f("div", { className: "react-paint-editor-snackbar", "data-is-shown": +i, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1421
+ }, $o = ({ snackbarList: e }) => f("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": In }, children: e.map((t) => f(Bo, { ...t }, t.id)) }), Yo = ra.forwardRef((e, t) => {
1422
+ const { hidden: a = !1, disabled: i = !1, selected: n = !1, icon: o, children: c, className: r = "", title: s, onClick: l, ...u } = e, d = i ? -1 : 0, h = ie(null);
1423
+ return xi(t, () => h.current), X("label", { className: `react-paint-editor-button ${r}`, title: s, onClick: l, "data-disabled": +i, "data-selected": +n, "data-hidden": +a, tabIndex: d, onKeyDown: (m) => {
1424
+ m.key === Ht && (m.preventDefault(), m.stopPropagation());
1425
+ }, onKeyUp: (m) => {
1426
+ m.preventDefault(), m.stopPropagation(), m.key === Ht && h.current?.click();
1427
+ }, children: [f("input", { ref: h, disabled: i, ...u }), X("span", { className: "react-paint-editor-button-content", children: [c && f("span", { className: "react-paint-editor-button-children", children: c }), o && f("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] })] });
1428
+ }), J = ra.forwardRef((e, t) => {
1429
+ if (e.type === "file" || e.type === "color") return f(Yo, { ...e, ref: t });
1430
+ const { hidden: a = !1, disabled: i = !1, selected: n = !1, icon: o, children: c, type: r = "button", className: s = "", ...l } = e;
1431
+ return f("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: i, "data-disabled": +i, "data-selected": +n, "data-hidden": +a, type: r, ...l, children: X("span", { className: "react-paint-editor-button-content", children: [c && f("span", { className: "react-paint-editor-button-children", children: c }), o && f("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] }) });
1432
+ }), at = ({ children: e, title: t = "", className: a = "", position: i = "bottom", fitContainer: n = !1, alignment: o = "center", style: c, ...r }) => X("div", { className: `react-paint-editor-panel ${a}`, "data-fitcontainer": n, "data-position": i, "data-alignment": o, style: { ...c, "--react-paint-editor-panel-zindex": Ti }, ...r, children: [t && f("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), Uo = (e) => {
1425
1433
  switch (e) {
1426
1434
  case "brush":
1427
- return Ca;
1435
+ return ki;
1428
1436
  case "line":
1429
- return Pa;
1437
+ return Vi;
1430
1438
  case "polygon":
1431
- return ci;
1439
+ return da;
1432
1440
  case "curve":
1433
- return La;
1441
+ return Zi;
1434
1442
  case "rect":
1435
1443
  case "square":
1436
- return ri;
1444
+ return la;
1437
1445
  case "circle":
1438
1446
  case "ellipse":
1439
- return li;
1447
+ return ca;
1440
1448
  case "text":
1441
- return ka;
1449
+ return Li;
1442
1450
  case "picture":
1443
- return di;
1451
+ return ha;
1444
1452
  case "group":
1445
1453
  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>';
1446
1454
  case "triangle":
1447
1455
  return "";
1448
1456
  }
1449
- }, Uo = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: a, toggleShapeVisibility: n, toggleShapeLock: o, setLayoutDragging: r, handleRemove: l, handleSelect: s, onMoveShapes: c }) => {
1450
- const u = te(null), { isOver: d } = (({ disabled: h = !1, ref: f, shape: g, layoutDragging: x, setLayoutDragging: C, handleSelect: k, onMoveShapes: w }) => {
1451
- const [m, y] = $(!1);
1452
- return J(() => {
1453
- x || y(!1);
1454
- }, [x]), J(() => {
1455
- const b = f.current;
1456
- if (!b) return;
1457
+ }, Xo = ({ disabled: e = !1, shape: t, selected: a, layoutDragging: i, toggleShapeVisibility: n, toggleShapeLock: o, setLayoutDragging: c, handleRemove: r, handleSelect: s, onMoveShapes: l }) => {
1458
+ const u = ie(null), { isOver: d } = (({ disabled: h = !1, ref: m, shape: p, layoutDragging: Q, setLayoutDragging: k, handleSelect: L, onMoveShapes: C }) => {
1459
+ const [M, g] = U(!1);
1460
+ return ee(() => {
1461
+ Q || g(!1);
1462
+ }, [Q]), ee(() => {
1463
+ const S = m.current;
1464
+ if (!S) return;
1457
1465
  const Z = () => {
1458
- C(void 0);
1459
- }, A = (N) => (N.preventDefault && N.preventDefault(), !1), T = (N) => {
1460
- k([g]), N.dataTransfer && (N.dataTransfer.effectAllowed = "move", N.dataTransfer.setData("draggableShapeId", g.id), C(g.id));
1461
- }, S = () => {
1462
- x !== g.id && y(!0);
1463
- }, V = () => {
1464
- y(!1);
1465
- }, I = (N) => (N.stopPropagation(), N.dataTransfer && w(N.dataTransfer.getData("draggableShapeId"), g.id), !1);
1466
- return h || (b.addEventListener("dragstart", T), b.addEventListener("dragend", Z), b.addEventListener("dragover", A), b.addEventListener("dragenter", S), b.addEventListener("dragleave", V), b.addEventListener("drop", I)), () => {
1467
- h || (b.removeEventListener("dragstart", T), b.removeEventListener("dragend", Z), b.removeEventListener("dragover", A), b.removeEventListener("dragenter", S), b.removeEventListener("dragleave", V), b.removeEventListener("drop", I));
1466
+ k(void 0);
1467
+ }, I = (A) => (A.preventDefault && A.preventDefault(), !1), H = (A) => {
1468
+ L([p]), A.dataTransfer && (A.dataTransfer.effectAllowed = "move", A.dataTransfer.setData("draggableShapeId", p.id), k(p.id));
1469
+ }, y = () => {
1470
+ Q !== p.id && g(!0);
1471
+ }, P = () => {
1472
+ g(!1);
1473
+ }, D = (A) => (A.stopPropagation(), A.dataTransfer && C(A.dataTransfer.getData("draggableShapeId"), p.id), !1);
1474
+ return h || (S.addEventListener("dragstart", H), S.addEventListener("dragend", Z), S.addEventListener("dragover", I), S.addEventListener("dragenter", y), S.addEventListener("dragleave", P), S.addEventListener("drop", D)), () => {
1475
+ h || (S.removeEventListener("dragstart", H), S.removeEventListener("dragend", Z), S.removeEventListener("dragover", I), S.removeEventListener("dragenter", y), S.removeEventListener("dragleave", P), S.removeEventListener("drop", D));
1468
1476
  };
1469
- }, [h, f, g, C, k, w, x]), { isOver: m };
1470
- })({ disabled: e, ref: u, shape: t, layoutDragging: a, setLayoutDragging: r, handleSelect: s, onMoveShapes: c });
1471
- return Y("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(a === t.id), "data-is-over": +d, onClick: (h) => {
1477
+ }, [h, m, p, k, L, C, Q]), { isOver: M };
1478
+ })({ disabled: e, ref: u, shape: t, layoutDragging: i, setLayoutDragging: c, handleSelect: s, onMoveShapes: l });
1479
+ return X("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(i === t.id), "data-is-over": +d, onClick: (h) => {
1472
1480
  e || (h.preventDefault(), h.stopPropagation(), s([t]));
1473
- }, "data-selected": +i, ref: u, tabIndex: -1, children: [v("span", { dangerouslySetInnerHTML: { __html: Yo(t.type) } }), v("span", { children: t.id }), v("div", { className: "react-paint-editor-layouts-separator" }), v(K, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (h) => {
1481
+ }, "data-selected": +a, ref: u, tabIndex: -1, children: [f("span", { dangerouslySetInnerHTML: { __html: Uo(t.type) } }), f("span", { children: t.id }), f("div", { className: "react-paint-editor-layouts-separator" }), f(J, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: a, onClick: (h) => {
1474
1482
  e || (h.preventDefault(), h.stopPropagation(), n([t]));
1475
- }, icon: t.visible === !1 ? '<svg><path d="M13.521 11.021 12.25 9.75Q12.333 8.75 11.604 7.979Q10.875 7.208 9.812 7.312L8.542 6.042Q8.896 5.896 9.26 5.833Q9.625 5.771 10 5.771Q11.583 5.771 12.688 6.875Q13.792 7.979 13.792 9.562Q13.792 9.979 13.719 10.354Q13.646 10.729 13.521 11.021ZM16.167 13.646 14.917 12.417Q15.667 11.833 16.25 11.146Q16.833 10.458 17.25 9.562Q16.229 7.479 14.292 6.281Q12.354 5.083 10 5.083Q9.396 5.083 8.885 5.156Q8.375 5.229 7.875 5.375L6.5 4Q7.354 3.646 8.208 3.49Q9.062 3.333 10 3.333Q13.146 3.333 15.615 5.052Q18.083 6.771 19.167 9.562Q18.688 10.792 17.917 11.823Q17.146 12.854 16.167 13.646ZM16.396 18.854 12.938 15.396Q12.208 15.625 11.479 15.729Q10.75 15.833 10 15.833Q6.833 15.833 4.375 14.094Q1.917 12.354 0.833 9.562Q1.25 8.479 1.917 7.552Q2.583 6.625 3.417 5.875L1.125 3.562L2.375 2.354L17.625 17.625ZM4.604 7.062Q4.021 7.604 3.542 8.219Q3.062 8.833 2.729 9.562Q3.75 11.646 5.688 12.865Q7.625 14.083 10 14.083Q10.354 14.083 10.74 14.052Q11.125 14.021 11.479 13.938L10.812 13.271Q10.625 13.312 10.417 13.333Q10.208 13.354 10 13.354Q8.417 13.354 7.312 12.25Q6.208 11.146 6.208 9.562Q6.208 9.354 6.24 9.167Q6.271 8.979 6.312 8.771ZM11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875ZM8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Z"/></svg>' : '<svg><path d="M10 13.354Q11.583 13.354 12.688 12.25Q13.792 11.146 13.792 9.562Q13.792 7.979 12.688 6.875Q11.583 5.771 10 5.771Q8.417 5.771 7.312 6.875Q6.208 7.979 6.208 9.562Q6.208 11.146 7.312 12.25Q8.417 13.354 10 13.354ZM10 11.812Q9.062 11.812 8.406 11.156Q7.75 10.5 7.75 9.562Q7.75 8.625 8.406 7.969Q9.062 7.312 10 7.312Q10.938 7.312 11.594 7.969Q12.25 8.625 12.25 9.562Q12.25 10.5 11.594 11.156Q10.938 11.812 10 11.812ZM10 15.833Q6.938 15.833 4.448 14.125Q1.958 12.417 0.833 9.562Q1.958 6.708 4.458 5.021Q6.958 3.333 10 3.333Q13.042 3.333 15.542 5.021Q18.042 6.708 19.167 9.562Q18.042 12.417 15.552 14.125Q13.062 15.833 10 15.833ZM10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562ZM10 14.083Q12.333 14.083 14.281 12.865Q16.229 11.646 17.25 9.562Q16.229 7.479 14.281 6.281Q12.333 5.083 10 5.083Q7.667 5.083 5.708 6.281Q3.75 7.479 2.729 9.562Q3.75 11.646 5.708 12.865Q7.667 14.083 10 14.083Z"/></svg>' }), v(K, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (h) => {
1483
+ }, 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>' }), f(J, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: a, onClick: (h) => {
1476
1484
  e || (h.preventDefault(), h.stopPropagation(), o([t]));
1477
- }, icon: t.locked ? '<svg><path d="M10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H5.792V5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833ZM10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042V6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' : '<svg><path d="M5.792 5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' }), v(K, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (h) => {
1478
- e || (h.preventDefault(), h.stopPropagation(), l([t]));
1479
- }, icon: Ma })] });
1480
- }, Xo = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: a, removeShape: n, toggleShapeVisibility: o, toggleShapeLock: r, selectedShapes: l, moveShapes: s, selectShapes: c, isLayoutPanelShown: u }) => {
1481
- const [d, h] = $(void 0), f = !i.features.edition;
1482
- return u ? v(tt, { alignment: "right", className: "react-paint-editor-layouts-panel", children: v("div", { className: "react-paint-editor-layouts-panel-content", children: Y("div", { className: "react-paint-editor-layouts-scrolling-content", children: [Y("div", { className: "react-paint-editor-layouts-row", children: [v("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), v(K, { icon: '<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>', className: "react-paint-editor-layouts-grid-button", selected: e === "none", disabled: f, onClick: () => t("none") }), ["small", "medium", "large"].map((g) => v(K, { className: "react-paint-editor-layouts-grid-button", selected: e === g, disabled: f, onClick: () => t(g), children: g.charAt(0).toUpperCase() }, g))] }), v("hr", {}), v("div", { className: "react-paint-editor-layouts", children: a.length === 0 ? v("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : a.map((g) => v(Uo, { shape: g, disabled: f, layoutDragging: d, setLayoutDragging: h, selected: j(l).some((x) => x.id === g.id) ?? !1, handleSelect: c, handleRemove: n, onMoveShapes: s, toggleShapeVisibility: o, toggleShapeLock: r }, g.id)) })] }) }) }) : null;
1483
- }, Nt = ({ children: e, onClose: t, position: i = "center", title: a, className: n = "" }) => Y("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": Va }, role: "dialog", "aria-modal": "true", "aria-labelledby": a, children: [v("div", { className: "react-paint-editor-modal-mask", onClick: t }), v("div", { className: `react-paint-editor-modal-panel ${n}`, children: e })] }), wt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: a = "fill", disabled: n = !1, values: o, field: r, value: l = "", valueChanged: s }) => {
1484
- const [c] = $(ye("settings_")), u = e === c;
1485
- return o.length ? Y(Ve, { children: [v(K, { selected: u, title: i, disabled: n, onClick: () => {
1486
- t((d) => d === c ? void 0 : c);
1487
- }, icon: l === "transparent" ? a === "fill" ? zi : Ti : void 0, children: l !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", "data-mode": a, style: { "--react-paint-editor-colorfield-color-value": l } }) }), u && v(tt, { title: i, alignment: "left", children: Y("div", { className: "react-paint-editor-colorfield-wrapper", children: [o.map((d) => v(K, { title: d, selected: d === l, color: d, icon: d === "transparent" ? a === "fill" ? zi : Ti : void 0, onClick: () => {
1488
- s(r, d);
1489
- }, children: d !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", color: d, "data-mode": a, style: { "--react-paint-editor-colorfield-color-value": d } }) }, d)), v(K, { type: "color", title: "Custom color", selected: l !== "" && !o.includes(l), value: l, onChange: (d) => {
1485
+ }, 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>' }), f(J, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (h) => {
1486
+ e || (h.preventDefault(), h.stopPropagation(), r([t]));
1487
+ }, icon: Pi })] });
1488
+ }, Go = ({ gridFormat: e, setGridFormat: t, settings: a, shapes: i, removeShape: n, toggleShapeVisibility: o, toggleShapeLock: c, selectedShapes: r, moveShapes: s, selectShapes: l, isLayoutPanelShown: u }) => {
1489
+ const [d, h] = U(void 0), m = !a.features.edition;
1490
+ return u ? f(at, { alignment: "right", className: "react-paint-editor-layouts-panel", children: f("div", { className: "react-paint-editor-layouts-panel-content", children: X("div", { className: "react-paint-editor-layouts-scrolling-content", children: [X("div", { className: "react-paint-editor-layouts-row", children: [f("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), f(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: m, onClick: () => t("none") }), ["small", "medium", "large"].map((p) => f(J, { className: "react-paint-editor-layouts-grid-button", selected: e === p, disabled: m, onClick: () => t(p), children: p.charAt(0).toUpperCase() }, p))] }), f("hr", {}), f("div", { className: "react-paint-editor-layouts", children: i.length === 0 ? f("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : i.map((p) => f(Xo, { shape: p, disabled: m, layoutDragging: d, setLayoutDragging: h, selected: _(r).some((Q) => Q.id === p.id) ?? !1, handleSelect: l, handleRemove: n, onMoveShapes: s, toggleShapeVisibility: o, toggleShapeLock: c }, p.id)) })] }) }) }) : null;
1491
+ }, Nt = ({ children: e, onClose: t, position: a = "center", title: i, className: n = "" }) => X("div", { className: "react-paint-editor-modal", "data-position": a, style: { "--react-paint-editor-modal-zindex": Ti }, role: "dialog", "aria-modal": "true", "aria-labelledby": i, children: [f("div", { className: "react-paint-editor-modal-mask", onClick: t }), f("div", { className: `react-paint-editor-modal-panel ${n}`, children: e })] }), xt = ({ selectedSettings: e, setSelectedSettings: t, title: a = "Choisissez une couleur", mode: i = "fill", disabled: n = !1, values: o, field: c, value: r = "", valueChanged: s }) => {
1492
+ const [l] = U(ue("settings_")), u = e === l;
1493
+ return o.length ? X(Te, { children: [f(J, { selected: u, title: a, disabled: n, onClick: () => {
1494
+ t((d) => d === l ? void 0 : l);
1495
+ }, icon: r === "transparent" ? i === "fill" ? Ea : Aa : void 0, children: r !== "transparent" && f("div", { className: "react-paint-editor-colorfield-color", "data-mode": i, style: { "--react-paint-editor-colorfield-color-value": r } }) }), u && f(at, { title: a, alignment: "left", children: X("div", { className: "react-paint-editor-colorfield-wrapper", children: [o.map((d) => f(J, { title: d, selected: d === r, color: d, icon: d === "transparent" ? i === "fill" ? Ea : Aa : void 0, onClick: () => {
1496
+ s(c, d);
1497
+ }, children: d !== "transparent" && f("div", { className: "react-paint-editor-colorfield-color", color: d, "data-mode": i, style: { "--react-paint-editor-colorfield-color-value": d } }) }, d)), f(J, { type: "color", title: "Custom color", selected: r !== "" && !o.includes(r), value: r, onChange: (d) => {
1490
1498
  const h = +d.target.value;
1491
- s(r, Number.isNaN(h) ? d.target.value : h);
1492
- }, children: v("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": o.includes(l) ? "var(--react-paint-editor-app-font-color)" : l }, children: v("span", { dangerouslySetInnerHTML: { __html: '<svg><path d="M9.958 18.333Q8.25 18.333 6.74 17.677Q5.229 17.021 4.104 15.885Q2.979 14.75 2.323 13.229Q1.667 11.708 1.667 10Q1.667 8.271 2.333 6.75Q3 5.229 4.156 4.104Q5.312 2.979 6.854 2.323Q8.396 1.667 10.125 1.667Q11.771 1.667 13.26 2.25Q14.75 2.833 15.875 3.854Q17 4.875 17.667 6.26Q18.333 7.646 18.333 9.25Q18.333 11.688 16.792 12.948Q15.25 14.208 13.188 14.208H11.75Q11.625 14.208 11.562 14.281Q11.5 14.354 11.5 14.458Q11.5 14.688 11.812 15.219Q12.125 15.75 12.125 16.458Q12.125 17.458 11.51 17.896Q10.896 18.333 9.958 18.333ZM5.458 10.875Q6 10.875 6.375 10.5Q6.75 10.125 6.75 9.583Q6.75 9.042 6.375 8.667Q6 8.292 5.458 8.292Q4.917 8.292 4.542 8.667Q4.167 9.042 4.167 9.583Q4.167 10.125 4.542 10.5Q4.917 10.875 5.458 10.875ZM7.917 7.583Q8.458 7.583 8.833 7.208Q9.208 6.833 9.208 6.292Q9.208 5.75 8.833 5.375Q8.458 5 7.917 5Q7.375 5 7 5.375Q6.625 5.75 6.625 6.292Q6.625 6.833 7 7.208Q7.375 7.583 7.917 7.583ZM12.021 7.583Q12.562 7.583 12.938 7.208Q13.312 6.833 13.312 6.292Q13.312 5.75 12.938 5.375Q12.562 5 12.021 5Q11.479 5 11.104 5.375Q10.729 5.75 10.729 6.292Q10.729 6.833 11.104 7.208Q11.479 7.583 12.021 7.583ZM14.479 10.875Q15.021 10.875 15.396 10.5Q15.771 10.125 15.771 9.583Q15.771 9.042 15.396 8.667Q15.021 8.292 14.479 8.292Q13.938 8.292 13.562 8.667Q13.188 9.042 13.188 9.583Q13.188 10.125 13.562 10.5Q13.938 10.875 14.479 10.875Z"/></svg>' } }) }) })] }) })] }) : null;
1493
- }, Go = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => v(K, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1494
- i(j(t));
1495
- }, icon: Ma }), Dt = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: a = "Choisissez l'option", disabled: n = !1, field: o, icon: r, values: l, defaultValue: s, valueChanged: c }) => {
1496
- const [u] = $(ye("settings_")), d = t === u;
1497
- return l.length ? Y(Ve, { children: [v(K, { selected: d, title: a, icon: r, disabled: n, onClick: () => {
1498
- i((h) => h === u ? void 0 : u);
1499
- } }), d && v(tt, { title: a, alignment: "left", fitContainer: !0, children: v("div", { className: "react-paint-editor-selectfield-wrapper", children: l.map((h) => v(K, { title: `${h}`, onClick: () => ((f) => {
1500
- c(o, f);
1501
- })(h), selected: s === h, style: { "--react-paint-editor-button-padding": "16px" }, children: v(e, { children: h }) }, h)) }) })] }) : null;
1502
- }, qo = ({ children: e }) => v("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), va = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: n, valueChanged: o }) => a.length ? v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: qo, title: "Police", icon: '<svg><path d="M5.312 14.979H7.125L8.042 12.479H11.979L12.896 14.979H14.708L10.917 5H9.083ZM8.542 10.958 9.958 6.958H10.042L11.458 10.958ZM3.417 18.333Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V3.417Q1.667 2.688 2.177 2.177Q2.688 1.667 3.417 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417V16.583Q18.333 17.312 17.823 17.823Q17.312 18.333 16.583 18.333ZM3.417 16.583H16.583Q16.583 16.583 16.583 16.583Q16.583 16.583 16.583 16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583ZM3.417 3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583V3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417Z"/></svg>', disabled: i, field: "fontFamily", values: a, defaultValue: n, valueChanged: o }) : null, _o = ({ disabled: e, toggleLayoutPanel: t }) => v(K, { title: "Toggle layers panel", disabled: e, onClick: t, icon: '<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>', className: "react-paint-editor-layout-button" }), jo = ({ children: e }) => Y("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [v("span", { className: "react-paint-editor-linearrow-left" }), v("span", { className: "react-paint-editor-linearrow-right" })] }), fa = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: n, valueChanged: o }) => a.length ? v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: jo, title: "Flèches", icon: '<svg><path d="M6 17 2 13 6 9 7.062 10.062 4.875 12.25H17V13.75H4.875L7.062 15.938ZM14 11 12.938 9.938 15.125 7.75H3V6.25H15.125L12.938 4.062L14 3L18 7Z"/></svg>', disabled: i, field: "lineArrow", values: a, defaultValue: n, valueChanged: o }) : null, Ko = ({ children: e }) => Y("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {}), v("span", {})] }), ma = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: a, defaultValue: n, valueChanged: o }) => a.length ? v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ko, icon: '<svg><path d="M3 16V14.5H4.5V16ZM6.125 16V14.5H7.625V16ZM9.25 16V14.5H10.75V16ZM12.375 16V14.5H13.875V16ZM15.5 16V14.5H17V16ZM3 13V11.5H6.5V13ZM8.25 13V11.5H11.75V13ZM13.5 13V11.5H17V13ZM3 10V8.5H9.25V10ZM10.75 10V8.5H17V10ZM3 7V4H17V7Z"/></svg>', title: "Type de traits", disabled: i, field: "lineDash", values: a, defaultValue: n, valueChanged: o }) : null, Ct = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: a, disabled: n = !1, field: o, value: r, min: l = 1, max: s = 20, step: c = 1, unity: u = "", valueChanged: d }) => {
1503
- const h = r === void 0, f = h ? "N/A" : `${Math.round(r)}${u}`, [g] = $(ye("settings_")), x = ((k, w = 500) => {
1504
- const m = te(null), y = B((...b) => {
1505
- m.current && clearTimeout(m.current), m.current = setTimeout(() => k(...b), w);
1506
- }, [k, w]);
1507
- return J(() => () => {
1508
- m.current && clearTimeout(m.current);
1509
- }, []), y;
1510
- })(d), C = e === g;
1511
- return l === s ? null : Y(Ve, { children: [v(K, { selected: C, title: i, disabled: n, icon: a, onClick: () => {
1512
- t((k) => k === g ? void 0 : g);
1513
- } }), C && v(tt, { title: i, alignment: "left", fitContainer: !0, children: v("div", { children: Y("label", { className: "react-paint-editor-rangefield", children: [v("input", { type: "range", min: l, max: s, step: c, value: r ?? (s + l) / 2, "data-indeterminate": +h, onChange: (k) => {
1514
- const w = +k.target.value, m = Number.isNaN(w) ? k.target.value : w;
1515
- d(o, m, !1), x(o, m, !0);
1516
- } }), v("span", { children: f })] }) }) })] });
1517
- }, Jo = ({ children: e }) => v("span", { children: e === 0 ? "Non" : "Oui" }), es = [0, 1], ya = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: a, valueChanged: n }) => v(Dt, { selectedSettings: e, setSelectedSettings: t, CustomOption: Jo, title: "Fermer les points", icon: ci, disabled: i, field: "closedPoints", values: es, defaultValue: a, valueChanged: n }), ts = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => v(K, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: Za, className: t ? ` ${t}` : "" }), Mt = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: a, values: n, value: o = !1, valueChanged: r }) => {
1518
- const [l] = $(ye("settings_"));
1519
- return n.length !== 2 ? null : v(K, { onClick: () => {
1520
- e((s) => s === l ? void 0 : l), r(i, !o);
1521
- }, selected: o, disabled: t, icon: a });
1522
- }, Kt = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: a, selectedSettings: n, setSelectedSettings: o, handleShapeStyleChange: r, handleShapeFontFamilyChange: l }) => t ? i && Y(Ve, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: a, field: "strokeColor", value: t.style?.strokeColor, valueChanged: r, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur de fond", disabled: a, field: "fillColor", value: t.style?.fillColor, valueChanged: r, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Epaisseur du trait", icon: Hi, disabled: a, field: "lineWidth", value: t.style?.lineWidth, valueChanged: r, unity: "px", min: i.settings.lineWidth.min, max: i.settings.lineWidth.max, step: i.settings.lineWidth.step }), "lineDash" in i.settings && !i.settings.lineDash.hidden && v(ma, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: t.style?.lineDash, valueChanged: r, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && v(fa, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: t.style?.lineArrow, valueChanged: r, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && v(ya, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: r, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && v(va, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: l, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontBold", icon: Zi, valueChanged: l, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontItalic", icon: Vi, valueChanged: l, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Opacité", icon: Li, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: a, field: "opacity", value: t.style?.opacity, valueChanged: r })] }) : "settings" in e ? Y(Ve, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: a, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: r, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && v(wt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur de fond", disabled: a, field: "fillColor", value: e.settings.fillColor.default, valueChanged: r, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Epaisseur du trait", disabled: a, field: "lineWidth", icon: Hi, value: e.settings.lineWidth.default, valueChanged: r, unity: "px", min: e.settings.lineWidth.min, max: e.settings.lineWidth.max, step: e.settings.lineWidth.step }), "lineDash" in e.settings && !e.settings.lineDash.hidden && v(ma, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: e.settings.lineDash.default, valueChanged: r, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && v(fa, { selectedSettings: n, setSelectedSettings: o, disabled: a, defaultValue: e.settings.lineArrow.default, valueChanged: r, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && v(ya, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: r, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && v(va, { selectedSettings: n, setSelectedSettings: o, disabled: a, valueChanged: l, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontBold", icon: Zi, valueChanged: l, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && v(Mt, { setSelectedSettings: o, disabled: a, field: "fontItalic", icon: Vi, valueChanged: l, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && v(Ct, { selectedSettings: n, setSelectedSettings: o, title: "Opacité", icon: Li, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: a, field: "opacity", value: e.settings.opacity.default, valueChanged: r })] }) : null, is = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: a = !1, toggleLayoutPanel: n, activeTool: o, selectedShape: r, canvas: l, settings: s, updateShape: c, removeShape: u, isZoomPanelShown: d, setIsZoomPanelShown: h }) => {
1523
- const [f, g] = $(void 0), [x, C] = $(!1), k = s.size === "infinite" || s.features.zoom, w = !s.features.edition, m = () => {
1524
- C((S) => !S);
1525
- }, y = ((S, V) => {
1526
- const I = j(S).map((H) => V.find((D) => D.id === H?.toolId) || V.find((D) => D.type === H?.type)).filter((H) => H !== void 0);
1527
- if (!I.length) return;
1528
- if (I.length === 1) return I[0];
1529
- const N = I.slice(1).reduce((H, D) => {
1530
- const U = {};
1531
- for (const F in D.settings) {
1532
- if (H[F] === void 0 || D.settings[F]?.hidden || H[F]?.hidden) continue;
1533
- const X = H[F], p = D.settings[F], Q = {};
1534
- "min" in p && "min" in X && p.min === X.min && "max" in p && "max" in X && p.max === X.max && "step" in p && "step" in X && p.step === X.step && (Q.min = p.min, Q.max = p.max, Q.step = p.step), "values" in p && "values" in X && p.values?.join(",") === X.values?.join(",") && (Q.values = p.values), (Object.keys(Q).length > 0 || F === "closedPoints") && (U[F] = Q);
1499
+ s(c, Number.isNaN(h) ? d.target.value : h);
1500
+ }, children: f("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: f("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;
1501
+ }, qo = ({ disabled: e = !1, selectedShape: t, removeShape: a }) => f(J, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1502
+ a(_(t));
1503
+ }, icon: Pi }), Rt = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: a, title: i = "Choisissez l'option", disabled: n = !1, field: o, icon: c, values: r, defaultValue: s, valueChanged: l }) => {
1504
+ const [u] = U(ue("settings_")), d = t === u;
1505
+ return r.length ? X(Te, { children: [f(J, { selected: d, title: i, icon: c, disabled: n, onClick: () => {
1506
+ a((h) => h === u ? void 0 : u);
1507
+ } }), d && f(at, { title: i, alignment: "left", fitContainer: !0, children: f("div", { className: "react-paint-editor-selectfield-wrapper", children: r.map((h) => f(J, { title: `${h}`, onClick: () => ((m) => {
1508
+ l(o, m);
1509
+ })(h), selected: s === h, style: { "--react-paint-editor-button-padding": "16px" }, children: f(e, { children: h }) }, h)) }) })] }) : null;
1510
+ }, _o = ({ children: e }) => f("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), mi = ({ selectedSettings: e, setSelectedSettings: t, disabled: a = !1, values: i, defaultValue: n, valueChanged: o }) => i.length ? f(Rt, { selectedSettings: e, setSelectedSettings: t, CustomOption: _o, 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: a, field: "fontFamily", values: i, defaultValue: n, valueChanged: o }) : null, jo = ({ disabled: e, toggleLayoutPanel: t }) => f(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" }), Ko = ({ children: e }) => X("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [f("span", { className: "react-paint-editor-linearrow-left" }), f("span", { className: "react-paint-editor-linearrow-right" })] }), yi = ({ selectedSettings: e, setSelectedSettings: t, disabled: a = !1, values: i, defaultValue: n, valueChanged: o }) => i.length ? f(Rt, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ko, 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: a, field: "lineArrow", values: i, defaultValue: n, valueChanged: o }) : null, Jo = ({ children: e }) => X("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [f("span", {}), f("span", {}), f("span", {}), f("span", {}), f("span", {}), f("span", {}), f("span", {})] }), Si = ({ selectedSettings: e, setSelectedSettings: t, disabled: a = !1, values: i, defaultValue: n, valueChanged: o }) => i.length ? f(Rt, { 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: a, field: "lineDash", values: i, defaultValue: n, valueChanged: o }) : null, Mt = ({ selectedSettings: e, setSelectedSettings: t, title: a = "Choisissez l'intervalle", icon: i, disabled: n = !1, field: o, value: c, min: r = 1, max: s = 20, step: l = 1, unity: u = "", valueChanged: d, saveShapes: h }) => {
1511
+ const m = c === void 0, p = m ? "N/A" : `${Math.round(c)}${u}`, [Q] = U(ue("settings_")), k = ((C, M = 500) => {
1512
+ const g = ie(null), S = $((...Z) => {
1513
+ g.current && clearTimeout(g.current), g.current = setTimeout(() => C(...Z), M);
1514
+ }, [C, M]);
1515
+ return ee(() => () => {
1516
+ g.current && clearTimeout(g.current);
1517
+ }, []), S;
1518
+ })(h), L = e === Q;
1519
+ return r === s ? null : X(Te, { children: [f(J, { selected: L, title: a, disabled: n, icon: i, onClick: () => {
1520
+ t((C) => C === Q ? void 0 : Q);
1521
+ } }), L && f(at, { title: a, alignment: "left", fitContainer: !0, children: f("div", { children: X("label", { className: "react-paint-editor-rangefield", children: [f("input", { type: "range", min: r, max: s, step: l, value: c ?? (s + r) / 2, "data-indeterminate": +m, onChange: (C) => {
1522
+ const M = +C.target.value, g = Number.isNaN(M) ? C.target.value : M;
1523
+ d(o, g, !1), k();
1524
+ } }), f("span", { children: p })] }) }) })] });
1525
+ }, es = ({ children: e }) => f("span", { children: e === 0 ? "Non" : "Oui" }), ts = [0, 1], Qi = ({ selectedSettings: e, setSelectedSettings: t, disabled: a = !1, defaultValue: i, valueChanged: n }) => f(Rt, { selectedSettings: e, setSelectedSettings: t, CustomOption: es, title: "Fermer les points", icon: da, disabled: a, field: "closedPoints", values: ts, defaultValue: i, valueChanged: n }), as = ({ disabled: e = !1, className: t, toggleZoomPanel: a }) => f(J, { title: "Toggle zoom panel", disabled: e, onClick: a, icon: Hi, className: t ? ` ${t}` : "" }), kt = ({ setSelectedSettings: e, disabled: t = !1, field: a, icon: i, values: n, value: o = !1, valueChanged: c }) => {
1526
+ const [r] = U(ue("settings_"));
1527
+ return n.length !== 2 ? null : f(J, { onClick: () => {
1528
+ e((s) => s === r ? void 0 : r), c(a, !o);
1529
+ }, selected: o, disabled: t, icon: i });
1530
+ }, Jt = ({ activeTool: e, selectedShape: t, selectedShapeTool: a, disabled: i, selectedSettings: n, setSelectedSettings: o, saveShapes: c, handleShapeStyleChange: r, handleShapeFontFamilyChange: s }) => t ? a && X(Te, { children: ["strokeColor" in a.settings && !a.settings.strokeColor.hidden && f(xt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: i, field: "strokeColor", value: t.style?.strokeColor, valueChanged: r, values: a.settings.strokeColor.values }), "fillColor" in a.settings && !a.settings.fillColor.hidden && f(xt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur de fond", disabled: i, field: "fillColor", value: t.style?.fillColor, valueChanged: r, values: a.settings.fillColor.values }), "lineWidth" in a.settings && !a.settings.lineWidth.hidden && f(Mt, { saveShapes: c, selectedSettings: n, setSelectedSettings: o, title: "Epaisseur du trait", icon: za, disabled: i, field: "lineWidth", value: t.style?.lineWidth, valueChanged: r, unity: "px", min: a.settings.lineWidth.min, max: a.settings.lineWidth.max, step: a.settings.lineWidth.step }), "lineDash" in a.settings && !a.settings.lineDash.hidden && f(Si, { selectedSettings: n, setSelectedSettings: o, disabled: i, defaultValue: t.style?.lineDash, valueChanged: r, values: a.settings.lineDash.values }), "lineArrow" in a.settings && !a.settings.lineArrow.hidden && f(yi, { selectedSettings: n, setSelectedSettings: o, disabled: i, defaultValue: t.style?.lineArrow, valueChanged: r, values: a.settings.lineArrow.values }), "closedPoints" in a.settings && !a.settings.closedPoints.hidden && f(Qi, { selectedSettings: n, setSelectedSettings: o, disabled: i, valueChanged: r, defaultValue: t.style?.closedPoints }), "fontFamily" in a.settings && !a.settings.fontFamily.hidden && f(mi, { selectedSettings: n, setSelectedSettings: o, disabled: i, valueChanged: s, values: a.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in a.settings && !a.settings.fontBold.hidden && f(kt, { setSelectedSettings: o, disabled: i, field: "fontBold", icon: Ha, valueChanged: s, values: a.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in a.settings && !a.settings.fontItalic.hidden && f(kt, { setSelectedSettings: o, disabled: i, field: "fontItalic", icon: Ta, valueChanged: s, values: a.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in a.settings && !a.settings.opacity.hidden && f(Mt, { saveShapes: c, selectedSettings: n, setSelectedSettings: o, title: "Opacité", icon: Za, min: a.settings.opacity.min, max: a.settings.opacity.max, step: a.settings.opacity.step, unity: "%", disabled: i, field: "opacity", value: t.style?.opacity, valueChanged: r })] }) : "settings" in e ? X(Te, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && f(xt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: i, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: r, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && f(xt, { selectedSettings: n, setSelectedSettings: o, title: "Couleur de fond", disabled: i, field: "fillColor", value: e.settings.fillColor.default, valueChanged: r, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && f(Mt, { saveShapes: c, selectedSettings: n, setSelectedSettings: o, title: "Epaisseur du trait", disabled: i, field: "lineWidth", icon: za, 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 && f(Si, { selectedSettings: n, setSelectedSettings: o, disabled: i, defaultValue: e.settings.lineDash.default, valueChanged: r, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && f(yi, { selectedSettings: n, setSelectedSettings: o, disabled: i, defaultValue: e.settings.lineArrow.default, valueChanged: r, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && f(Qi, { selectedSettings: n, setSelectedSettings: o, disabled: i, valueChanged: r, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && f(mi, { selectedSettings: n, setSelectedSettings: o, disabled: i, valueChanged: s, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && f(kt, { setSelectedSettings: o, disabled: i, field: "fontBold", icon: Ha, valueChanged: s, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && f(kt, { setSelectedSettings: o, disabled: i, field: "fontItalic", icon: Ta, valueChanged: s, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && f(Mt, { saveShapes: c, selectedSettings: n, setSelectedSettings: o, title: "Opacité", icon: Za, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: i, field: "opacity", value: e.settings.opacity.default, valueChanged: r })] }) : null, is = ({ width: e, availableTools: t, updateToolSettings: a, layersManipulation: i = !1, toggleLayoutPanel: n, activeTool: o, saveShapes: c, selectedShape: r, canvas: s, settings: l, updateShape: u, removeShape: d, isZoomPanelShown: h, setIsZoomPanelShown: m }) => {
1531
+ const [p, Q] = U(void 0), [k, L] = U(!1), C = l.size === "infinite" || l.features.zoom, M = !l.features.edition, g = () => {
1532
+ L((P) => !P);
1533
+ }, S = ((P, D) => {
1534
+ const A = _(P).map((W) => D.find((B) => B.id === W?.toolId) || D.find((B) => B.type === W?.type)).filter((W) => W !== void 0);
1535
+ if (!A.length) return;
1536
+ if (A.length === 1) return A[0];
1537
+ const E = A.slice(1).reduce((W, B) => {
1538
+ const Y = {};
1539
+ for (const j in B.settings) {
1540
+ if (W[j] === void 0 || B.settings[j]?.hidden || W[j]?.hidden) continue;
1541
+ const V = W[j], v = B.settings[j], w = {};
1542
+ "min" in v && "min" in V && v.min === V.min && "max" in v && "max" in V && v.max === V.max && "step" in v && "step" in V && v.step === V.step && (w.min = v.min, w.max = v.max, w.step = v.step), "values" in v && "values" in V && v.values?.join(",") === V.values?.join(",") && (w.values = v.values), (Object.keys(w).length > 0 || j === "closedPoints") && (Y[j] = w);
1535
1543
  }
1536
- return U;
1537
- }, I[0].settings);
1538
- return { id: I.map((H) => H.id).join("-"), icon: "", label: "group", type: "group", settings: N };
1539
- })(r, t), b = (y ? Object.keys(y.settings).length + 1 : "settings" in o ? Object.keys(o.settings).length : 0) + +a + +k, Z = e < 40 * b, A = (S, V, I = !0) => {
1540
- if (j(r).length) {
1541
- const N = j(r).map((H) => dt(Pe(["style", S], V, H), s));
1542
- c(N, I), y && i(y.id, S, V);
1543
- } else i(o.id, S, V);
1544
- }, T = (S, V) => {
1545
- if (j(r).length) {
1546
- const I = j(r).map((N) => {
1547
- if (N.type !== "text") return N;
1548
- const H = l?.getContext("2d");
1549
- if (!H) return N;
1550
- const D = Pe(["style", S], V, N), U = Si(H, D.value, D.width, D.style?.fontBold ?? !1, D.style?.fontItalic ?? !1, D.style?.fontFamily);
1551
- return dt({ ...D, fontSize: U, height: U * D.value.length }, s);
1544
+ return Y;
1545
+ }, A[0].settings);
1546
+ return { id: A.map((W) => W.id).join("-"), icon: "", label: "group", type: "group", settings: E };
1547
+ })(r, t), Z = (S ? Object.keys(S.settings).length + 1 : "settings" in o ? Object.keys(o.settings).length : 0) + +i + +C, I = e < 40 * Z, H = (P, D, A = !0) => {
1548
+ if (_(r).length) {
1549
+ const E = _(r).map((W) => ut(Ve(["style", P], D, W), l));
1550
+ u(E, A), S && a(S.id, P, D);
1551
+ } else a(o.id, P, D);
1552
+ }, y = (P, D) => {
1553
+ if (_(r).length) {
1554
+ const A = _(r).map((E) => {
1555
+ if (E.type !== "text") return E;
1556
+ const W = s?.getContext("2d");
1557
+ if (!W) return E;
1558
+ const B = Ve(["style", P], D, E), Y = Qa(W, B.value, B.width, B.style?.fontBold ?? !1, B.style?.fontItalic ?? !1, B.style?.fontFamily);
1559
+ return ut({ ...B, fontSize: Y, height: Y * B.value.length }, l);
1552
1560
  });
1553
- c(I, !0), y && i(y.id, S, V);
1554
- } else i(o.id, S, V);
1561
+ u(A, !0), S && a(S.id, P, D);
1562
+ } else a(o.id, P, D);
1555
1563
  };
1556
- return Y(Ve, { children: [Y("div", { className: "react-paint-editor-settings-bar", children: [Y("div", { className: "react-paint-editor-settings-shrinkable", children: [k && v(ts, { className: d ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1557
- h((S) => !S);
1558
- } }), Z && b > 2 && v(K, { disabled: w, onClick: m, title: "Toggle settings", icon: '<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>' }), r ? y && Y(Ve, { children: [!Z && v(Kt, { activeTool: o, selectedShape: r, selectedShapeTool: y, disabled: w, selectedSettings: f, setSelectedSettings: g, handleShapeStyleChange: A, handleShapeFontFamilyChange: T }), o.type === "selection" && v(Go, { disabled: w, selectedShape: r, removeShape: u })] }) : !Z && v(Kt, { activeTool: o, selectedShape: r, selectedShapeTool: y, disabled: w, selectedSettings: f, setSelectedSettings: g, handleShapeStyleChange: A, handleShapeFontFamilyChange: T })] }), v("div", { className: "react-paint-editor-settings-separator" }), a && v(_o, { disabled: w, toggleLayoutPanel: n })] }), x && v(Nt, { className: "react-paint-editor-settings-modal", onClose: m, position: "bottom", title: "Settings", children: v(Kt, { activeTool: o, selectedShape: r, selectedShapeTool: y, disabled: w, selectedSettings: f, setSelectedSettings: g, handleShapeStyleChange: A, handleShapeFontFamilyChange: T }) })] });
1559
- }, Sa = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: a, img: n, accept: o }) => {
1560
- const r = te(null);
1561
- return v(K, { ref: r, type: "file", onClick: (l) => {
1562
- l.stopPropagation(), r.current && (r.current.value = "");
1563
- }, onChange: (l) => {
1564
- const s = l.target.files?.item(0);
1565
- s && i(s);
1566
- }, accept: o, title: a.label ?? a.type, icon: n, disabled: e, children: t ? a.label : void 0 });
1567
- }, ke = ({ type: e, img: t, isActive: i, withText: a = !1, disabled: n = !1, setActive: o }) => v(K, { disabled: n, selected: i, onClick: () => {
1564
+ return X(Te, { children: [X("div", { className: "react-paint-editor-settings-bar", children: [X("div", { className: "react-paint-editor-settings-shrinkable", children: [C && f(as, { className: h ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1565
+ m((P) => !P);
1566
+ } }), I && Z > 2 && f(J, { disabled: M, 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 ? S && X(Te, { children: [!I && f(Jt, { saveShapes: c, activeTool: o, selectedShape: r, selectedShapeTool: S, disabled: M, selectedSettings: p, setSelectedSettings: Q, handleShapeStyleChange: H, handleShapeFontFamilyChange: y }), o.type === "selection" && f(qo, { disabled: M, selectedShape: r, removeShape: d })] }) : !I && f(Jt, { saveShapes: c, activeTool: o, selectedShape: r, selectedShapeTool: S, disabled: M, selectedSettings: p, setSelectedSettings: Q, handleShapeStyleChange: H, handleShapeFontFamilyChange: y })] }), f("div", { className: "react-paint-editor-settings-separator" }), i && f(jo, { disabled: M, toggleLayoutPanel: n })] }), k && f(Nt, { className: "react-paint-editor-settings-modal", onClose: g, position: "bottom", title: "Settings", children: f(Jt, { saveShapes: c, activeTool: o, selectedShape: r, selectedShapeTool: S, disabled: M, selectedSettings: p, setSelectedSettings: Q, handleShapeStyleChange: H, handleShapeFontFamilyChange: y }) })] });
1567
+ }, bi = ({ disabled: e = !1, withText: t = !1, loadFile: a, type: i, img: n, accept: o }) => {
1568
+ const c = ie(null);
1569
+ return f(J, { ref: c, type: "file", onClick: (r) => {
1570
+ r.stopPropagation(), c.current && (c.current.value = "");
1571
+ }, onChange: (r) => {
1572
+ const s = r.target.files?.item(0);
1573
+ s && a(s);
1574
+ }, accept: o, title: i.label ?? i.type, icon: n, disabled: e, children: t ? i.label : void 0 });
1575
+ }, Le = ({ type: e, img: t, isActive: a, withText: i = !1, disabled: n = !1, setActive: o }) => f(J, { disabled: n, selected: a, onClick: () => {
1568
1576
  o(e);
1569
- }, title: e.label ?? e.type, icon: t, children: a ? e.label : void 0 }), as = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: a = !1, hasActionToClear: n = !1, undoAction: o, redoAction: r, clearCanvas: l, alignment: s, group: c, vertical: u = !1, disabled: d = !1, withLoadAndSave: h, withExport: f, addPicture: g, loadFile: x, togglePictureUrlModal: C, saveFile: k, toggleExportModal: w, withUploadPicture: m, withUrlPicture: y }) => {
1570
- const [b, Z] = $(!1), [, A] = wa(), T = c?.tools?.some((V) => V === e.type), S = (T ? e.icon : c.img) ?? c.title;
1571
- return J(() => {
1572
- if (!b) return;
1573
- const V = () => {
1577
+ }, title: e.label ?? e.type, icon: t, children: i ? e.label : void 0 }), ns = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: a = !1, hasActionToRedo: i = !1, hasActionToClear: n = !1, undoAction: o, redoAction: c, clearCanvas: r, alignment: s, group: l, vertical: u = !1, disabled: d = !1, withLoadAndSave: h, withExport: m, addPicture: p, loadFile: Q, togglePictureUrlModal: k, saveFile: L, toggleExportModal: C, withUploadPicture: M, withUrlPicture: g }) => {
1578
+ const [S, Z] = U(!1), [, I] = Mi(), H = l?.tools?.some((P) => P === e.type), y = (H ? e.icon : l.img) ?? l.title;
1579
+ return ee(() => {
1580
+ if (!S) return;
1581
+ const P = () => {
1574
1582
  Z(!1);
1575
1583
  };
1576
- return document.addEventListener("click", V), () => {
1577
- document.removeEventListener("click", V);
1584
+ return document.addEventListener("click", P), () => {
1585
+ document.removeEventListener("click", P);
1578
1586
  };
1579
- }, [b]), t || m || y || h || f ? Y("div", { className: "react-paint-editor-toolbox-relative", children: [v(K, { selected: T, title: c.title, disabled: d, onClick: () => {
1580
- A(() => {
1587
+ }, [S]), t || M || g || h || m ? X("div", { className: "react-paint-editor-toolbox-relative", children: [f(J, { selected: H, title: l.title, disabled: d, onClick: () => {
1588
+ I(() => {
1581
1589
  Z(!0);
1582
1590
  });
1583
- }, icon: S }), b && v(tt, { alignment: s, position: "top", children: Y("div", { className: "react-paint-editor-toolbox-panel-content", "data-vertical": +u, children: [t && Y(Ve, { children: [v(ke, { withText: !0, type: rt, disabled: d || !i, img: rt.icon, isActive: e.id === rt.id, setActive: o }), v(ke, { withText: !0, type: lt, disabled: d || !a, img: lt.icon, isActive: e.id === lt.id, setActive: r }), v(ke, { withText: !0, type: ct, disabled: d || !n, img: ct.icon, isActive: e.id === ct.id, setActive: l }), (m || y || h) && v("hr", {})] }), m && v(Sa, { withText: !0, type: Ii, disabled: d, loadFile: async (V) => {
1584
- Z(!1), await g(V);
1585
- }, img: Ii.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), y && v(K, { disabled: d, selected: !1, onClick: C, title: "Add picture from URL", icon: '<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>', children: "Add picture from URL" }), (m || y) && h && v("hr", {}), h && Y(Ve, { children: [v(Sa, { withText: !0, type: Ei, disabled: d, loadFile: (V) => {
1586
- Z(!1), x(V);
1587
- }, img: Ei.icon, accept: "application/JSON" }), v(ke, { withText: !0, disabled: d, type: Ut, img: Ut.icon, isActive: e.id === Ut.id, setActive: k })] }), f && v(ke, { withText: !0, disabled: d, type: Yt, img: Yt.icon, isActive: e.id === Yt.id, setActive: w })] }) })] }) : null;
1588
- }, ns = ({ togglePictureUrlModal: e, addPicture: t }) => {
1589
- const i = te(null);
1590
- return J(() => {
1591
- i.current && i.current.focus();
1592
- }, []), v(Nt, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: Y("form", { onSubmit: async (a) => {
1593
- a.preventDefault();
1594
- const n = i.current?.value;
1591
+ }, icon: y }), S && f(at, { alignment: s, position: "top", children: X("div", { className: "react-paint-editor-toolbox-panel-content", "data-vertical": +u, children: [t && X(Te, { children: [f(Le, { withText: !0, type: lt, disabled: d || !a, img: lt.icon, isActive: e.id === lt.id, setActive: o }), f(Le, { withText: !0, type: ct, disabled: d || !i, img: ct.icon, isActive: e.id === ct.id, setActive: c }), f(Le, { withText: !0, type: dt, disabled: d || !n, img: dt.icon, isActive: e.id === dt.id, setActive: r }), (M || g || h) && f("hr", {})] }), M && f(bi, { withText: !0, type: Na, disabled: d, loadFile: async (P) => {
1592
+ Z(!1), await p(P);
1593
+ }, img: Na.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), g && f(J, { disabled: d, selected: !1, onClick: k, title: "Add picture from URL", icon: '<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>', children: "Add picture from URL" }), (M || g) && h && f("hr", {}), h && X(Te, { children: [f(bi, { withText: !0, type: Da, disabled: d, loadFile: (P) => {
1594
+ Z(!1), Q(P);
1595
+ }, img: Da.icon, accept: "application/JSON" }), f(Le, { withText: !0, disabled: d, type: Xt, img: Xt.icon, isActive: e.id === Xt.id, setActive: L })] }), m && f(Le, { withText: !0, disabled: d, type: Ut, img: Ut.icon, isActive: e.id === Ut.id, setActive: C })] }) })] }) : null;
1596
+ }, os = ({ togglePictureUrlModal: e, addPicture: t }) => {
1597
+ const a = ie(null);
1598
+ return ee(() => {
1599
+ a.current && a.current.focus();
1600
+ }, []), f(Nt, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: X("form", { onSubmit: async (i) => {
1601
+ i.preventDefault();
1602
+ const n = a.current?.value;
1595
1603
  n && (await t(n), e());
1596
- }, children: [Y("label", { children: ["URL ", v("input", { type: "text", ref: i })] }), v(K, { onClick: e, children: "Annuler" }), v(K, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1597
- }, Qa = "Choose export settings", os = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1598
- const i = async (a) => {
1599
- t(a), e();
1604
+ }, children: [X("label", { children: ["URL ", f("input", { type: "text", ref: a })] }), f(J, { onClick: e, children: "Annuler" }), f(J, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1605
+ }, wi = "Choose export settings", ss = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1606
+ const a = async (i) => {
1607
+ t(i), e();
1600
1608
  };
1601
- return Y(Nt, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Qa, children: [v("h3", { children: Qa }), v("hr", {}), v(K, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), v(K, { onClick: () => i("defaultView"), children: "Exporter le canevas par défaut" }), v(K, { onClick: () => i("fitToShapes"), children: "Exporter le dessin entier" }), v(K, { selected: !0, onClick: e, children: "Annuler" })] });
1602
- }, ss = ({ activeTool: e, alignment: t, group: i, disabled: a = !1, setActiveToolFromId: n }) => {
1603
- const o = te(null), [r, l] = $(!1), [, s] = wa(), [c, u] = $(void 0), d = (g) => {
1604
- u(g), n(g.id);
1609
+ return X(Nt, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: wi, children: [f("h3", { children: wi }), f("hr", {}), f(J, { onClick: () => a("currentZoom"), children: "Exporter la vue actuelle" }), f(J, { onClick: () => a("defaultView"), children: "Exporter le canevas par défaut" }), f(J, { onClick: () => a("fitToShapes"), children: "Exporter le dessin entier" }), f(J, { selected: !0, onClick: e, children: "Annuler" })] });
1610
+ }, rs = ({ activeTool: e, alignment: t, group: a, disabled: i = !1, setActiveToolFromId: n }) => {
1611
+ const o = ie(null), [c, r] = U(!1), [, s] = Mi(), [l, u] = U(void 0), d = (p) => {
1612
+ u(p), n(p.id);
1605
1613
  };
1606
- if (J(() => {
1607
- if (!r) return;
1608
- const g = (x) => {
1609
- !((k, w) => !!(k.target instanceof Node && w) && w.contains(k.target))(x, o.current) && l(!1);
1614
+ if (ee(() => {
1615
+ if (!c) return;
1616
+ const p = (Q) => {
1617
+ !((L, C) => !!(L.target instanceof Node && C) && C.contains(L.target))(Q, o.current) && r(!1);
1610
1618
  };
1611
- return document.addEventListener("mousedown", g, { passive: !1 }), document.addEventListener("touchstart", g, { passive: !1 }), () => {
1612
- document.removeEventListener("mousedown", g), document.removeEventListener("touchstart", g);
1619
+ return document.addEventListener("mousedown", p, { passive: !1 }), document.addEventListener("touchstart", p, { passive: !1 }), () => {
1620
+ document.removeEventListener("mousedown", p), document.removeEventListener("touchstart", p);
1613
1621
  };
1614
- }, [r]), "type" in i) return v(ke, { disabled: a, type: i, img: i.icon, isActive: e.id === i.id, setActive: d });
1615
- if (!i.toolsType.length) return null;
1616
- if (i.toolsType?.length === 1) return v(ke, { disabled: a, type: i.toolsType[0], img: i.toolsType[0].icon, isActive: e.id === i.toolsType[0].id, setActive: d });
1617
- const h = i?.toolsType.find((g) => g.type === e.type) !== void 0, f = (c ? c.icon : i.toolsType?.[0]?.icon) ?? i.title;
1618
- return Y("div", { className: "react-paint-editor-toolbargroup-relative", children: [v(K, { selected: h, title: i.title, disabled: a, onClick: () => {
1619
- c ? n(c.id) : i.toolsType?.[0] && d(i.toolsType[0]), s(() => {
1620
- l(!0);
1622
+ }, [c]), "type" in a) return f(Le, { disabled: i, type: a, img: a.icon, isActive: e.id === a.id, setActive: d });
1623
+ if (!a.toolsType.length) return null;
1624
+ if (a.toolsType?.length === 1) return f(Le, { disabled: i, type: a.toolsType[0], img: a.toolsType[0].icon, isActive: e.id === a.toolsType[0].id, setActive: d });
1625
+ const h = a?.toolsType.find((p) => p.type === e.type) !== void 0, m = (l ? l.icon : a.toolsType?.[0]?.icon) ?? a.title;
1626
+ return X("div", { className: "react-paint-editor-toolbargroup-relative", children: [f(J, { selected: h, title: a.title, disabled: i, onClick: () => {
1627
+ l ? n(l.id) : a.toolsType?.[0] && d(a.toolsType[0]), s(() => {
1628
+ r(!0);
1621
1629
  });
1622
- }, icon: f }), r && v(tt, { alignment: t, position: "top", children: v("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +i.vertical, ref: o, children: i.toolsType.map((g) => v(ke, { disabled: a, type: g, img: g.icon, isActive: e.id === g.id, setActive: d }, g.id)) }) })] });
1623
- }, rs = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], ls = ({ settings: e, width: t, activeTool: i, hasActionToUndo: a = !1, hasActionToRedo: n = !1, hasActionToClear: o = !1, withLoadAndSave: r, withExport: l, clearCanvas: s, setActiveTool: c, undoAction: u, redoAction: d, addPicture: h, loadFile: f, saveFile: g, exportCanvasInFile: x, availableTools: C, withUrlPicture: k, withUploadPicture: w }) => {
1624
- const m = ((p, Q) => {
1625
- const M = Q.flatMap((L) => {
1626
- if (typeof L != "object") return p.filter((E) => E.type === L);
1627
- const P = p.filter((E) => L.toolsType.includes(E.type));
1628
- return P ? { ...L, toolsType: P } : null;
1630
+ }, icon: m }), c && f(at, { alignment: t, position: "top", children: f("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +a.vertical, ref: o, children: a.toolsType.map((p) => f(Le, { disabled: i, type: p, img: p.icon, isActive: e.id === p.id, setActive: d }, p.id)) }) })] });
1631
+ }, ls = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], cs = ({ settings: e, width: t, activeTool: a, hasActionToUndo: i = !1, hasActionToRedo: n = !1, hasActionToClear: o = !1, withLoadAndSave: c, withExport: r, clearCanvas: s, setActiveTool: l, undoAction: u, redoAction: d, addPicture: h, loadFile: m, saveFile: p, exportCanvasInFile: Q, availableTools: k, withUrlPicture: L, withUploadPicture: C }) => {
1632
+ const M = ((V, v) => {
1633
+ const w = v.flatMap((b) => {
1634
+ if (typeof b != "object") return V.filter((x) => x.type === b);
1635
+ const T = V.filter((x) => b.toolsType.includes(x.type));
1636
+ return T ? { ...b, toolsType: T } : null;
1629
1637
  });
1630
- return Qi(M);
1631
- })(C, rs), y = !e.features.edition, b = t < 40 * (6 + m.length), Z = t < 40 * (3 + m.length), [A, T] = $(!1), [S, V] = $(!1), [I, N] = $(!1), H = () => {
1632
- T((p) => !p);
1633
- }, D = () => {
1634
- N((p) => !p);
1635
- }, U = (p) => {
1636
- c(p), T(!1);
1637
- }, F = (p) => {
1638
- U(C.find((Q) => Q.id === p) ?? i);
1639
- }, X = C.find((p) => p.type === i.type) !== void 0;
1640
- return Y(Ve, { children: [Y("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [Y("div", { className: "react-paint-editor-toolbar-shrinkable", children: [v(ke, { type: Fe, disabled: y, img: Fe.icon, isActive: i.id === Fe.id, setActive: U }), (e.size === "infinite" || e.features.zoom) && v(ke, { type: Xt, disabled: y, img: Xt.icon, isActive: i.id === Xt.id, setActive: U }), Z ? v(K, { disabled: y, onClick: H, title: "Toggle tools", icon: '<svg><path d="M5.333 9.292 10.021 1.646 14.708 9.292ZM14.562 18.333Q13 18.333 11.896 17.229Q10.792 16.125 10.792 14.562Q10.792 13 11.896 11.896Q13 10.792 14.562 10.792Q16.125 10.792 17.229 11.896Q18.333 13 18.333 14.562Q18.333 16.125 17.229 17.229Q16.125 18.333 14.562 18.333ZM2.5 17.917V11.188H9.229V17.917ZM14.562 16.583Q15.438 16.583 16.01 16.01Q16.583 15.438 16.583 14.562Q16.583 13.688 16.01 13.115Q15.438 12.542 14.562 12.542Q13.688 12.542 13.115 13.115Q12.542 13.688 12.542 14.562Q12.542 15.438 13.115 16.01Q13.688 16.583 14.562 16.583ZM4.25 16.167H7.479V12.938H4.25ZM8.458 7.542H11.583L10.021 5ZM10.021 7.542ZM7.479 12.938ZM14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Z"/></svg>', selected: X }) : m.map((p) => v(ss, { disabled: y, activeTool: i, group: p, setActiveToolFromId: F }, "id" in p ? p.id : p.title))] }), !b && Y(Ve, { children: [v(ke, { type: rt, disabled: y || !a, img: rt.icon, isActive: i.id === rt.id, setActive: u }), v(ke, { type: lt, disabled: y || !n, img: lt.icon, isActive: i.id === lt.id, setActive: d }), v(ke, { type: ct, disabled: y || !o, img: ct.icon, isActive: i.id === ct.id, setActive: s })] }), v(as, { withActionsInMenu: b, disabled: y, vertical: !0, alignment: "right", group: { title: "Menu", img: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }, activeTool: i, addPicture: h, loadFile: f, saveFile: g, togglePictureUrlModal: () => {
1641
- V(!0);
1642
- }, toggleExportModal: D, withUploadPicture: w, withUrlPicture: k, withLoadAndSave: r, withExport: l, hasActionToUndo: a, hasActionToRedo: n, hasActionToClear: o, undoAction: u, redoAction: d, clearCanvas: s })] }), A && v(Nt, { className: "react-paint-editor-toolbar-modal", onClose: H, title: "Outils", children: C.map((p) => p.type === "picture" ? null : v(ke, { disabled: y, type: p, img: p.icon, withText: !1, isActive: i.id === p.id, setActive: U }, p.id)) }), S && v(ns, { togglePictureUrlModal: () => {
1643
- V((p) => !p);
1644
- }, addPicture: h }), I && v(os, { toggleExportModal: D, exportCanvasInFile: x })] });
1645
- }, kt = { none: 0, small: 10, medium: 20, large: 40 }, cs = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, ds = () => {
1646
- const e = te([]), [t, i] = $([]);
1647
- return J(() => () => {
1648
- for (const a of e.current) clearTimeout(a);
1649
- }, []), { snackbarList: t, addSnackbar: ({ type: a = Wo, duration: n = Oo, text: o }) => {
1650
- const r = { id: ye("snackbar_"), duration: n, type: a, text: o };
1651
- i((l) => [...l, r]), e.current = [...e.current, setTimeout(() => {
1652
- return l = r.id, void i((s) => s.filter((c) => c.id !== l));
1653
- var l;
1638
+ return ba(w);
1639
+ })(k, ls), g = !e.features.edition, S = t < 40 * (6 + M.length), Z = t < 40 * (3 + M.length), [I, H] = U(!1), [y, P] = U(!1), [D, A] = U(!1), E = () => {
1640
+ H((V) => !V);
1641
+ }, W = () => {
1642
+ A((V) => !V);
1643
+ }, B = (V) => {
1644
+ l(V), H(!1);
1645
+ }, Y = (V) => {
1646
+ B(k.find((v) => v.id === V) ?? a);
1647
+ }, j = k.find((V) => V.type === a.type) !== void 0;
1648
+ return X(Te, { children: [X("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [X("div", { className: "react-paint-editor-toolbar-shrinkable", children: [f(Le, { type: Be, disabled: g, img: Be.icon, isActive: a.id === Be.id, setActive: B }), (e.size === "infinite" || e.features.zoom) && f(Le, { type: Gt, disabled: g, img: Gt.icon, isActive: a.id === Gt.id, setActive: B }), Z ? f(J, { disabled: g, onClick: E, 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: j }) : M.map((V) => f(rs, { disabled: g, activeTool: a, group: V, setActiveToolFromId: Y }, "id" in V ? V.id : V.title))] }), !S && X(Te, { children: [f(Le, { type: lt, disabled: g || !i, img: lt.icon, isActive: a.id === lt.id, setActive: u }), f(Le, { type: ct, disabled: g || !n, img: ct.icon, isActive: a.id === ct.id, setActive: d }), f(Le, { type: dt, disabled: g || !o, img: dt.icon, isActive: a.id === dt.id, setActive: s })] }), f(ns, { withActionsInMenu: S, 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: a, addPicture: h, loadFile: m, saveFile: p, togglePictureUrlModal: () => {
1649
+ P(!0);
1650
+ }, toggleExportModal: W, withUploadPicture: C, withUrlPicture: L, withLoadAndSave: c, withExport: r, hasActionToUndo: i, hasActionToRedo: n, hasActionToClear: o, undoAction: u, redoAction: d, clearCanvas: s })] }), I && f(Nt, { className: "react-paint-editor-toolbar-modal", onClose: E, title: "Outils", children: k.map((V) => V.type === "picture" ? null : f(Le, { disabled: g, type: V, img: V.icon, withText: !1, isActive: a.id === V.id, setActive: B }, V.id)) }), y && f(os, { togglePictureUrlModal: () => {
1651
+ P((V) => !V);
1652
+ }, addPicture: h }), D && f(ss, { toggleExportModal: W, exportCanvasInFile: Q })] });
1653
+ }, Pt = { none: 0, small: 10, medium: 20, large: 40 }, ds = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, hs = () => {
1654
+ const e = ie([]), [t, a] = U([]);
1655
+ return ee(() => () => {
1656
+ for (const i of e.current) clearTimeout(i);
1657
+ }, []), { snackbarList: t, addSnackbar: ({ type: i = Oo, duration: n = Fo, text: o }) => {
1658
+ const c = { id: ue("snackbar_"), duration: n, type: i, text: o };
1659
+ a((r) => [...r, c]), e.current = [...e.current, setTimeout(() => {
1660
+ return r = c.id, void a((s) => s.filter((l) => l.id !== r));
1661
+ var r;
1654
1662
  }, n)];
1655
1663
  } };
1656
- }, vs = ({ editorProps: e, className: t, style: i, options: a, children: n }) => {
1657
- const { shapesRef: o, addPictureShape: r, moveShapes: l, toggleShapeVisibility: s, toggleShapeLock: c, canGoBackward: u, canGoForward: d, canClear: h, selectedShape: f, removeShape: g, updateShape: x, backwardShape: C, forwardShape: k, refs: w, width: m, height: y, selectTool: b, selectShapes: Z, activeTool: A, setActiveTool: T, setAvailableTools: S, isEditMode: V, availableTools: I, gridGap: N, setGridGap: H, loadFile: D, exportPicture: U, exportData: F, clearCanvas: X, settings: p, setCanvasZoom: Q, canvas: { canGrow: M, layersManipulation: L, withExport: P, withLoadAndSave: E, withUploadPicture: W, withUrlPicture: O } } = e, { toolbarBackgroundColor: z, dividerColor: ie, fontRadius: re, fontDisabledColor: R, fontDisabledBackgroundColor: oe, fontColor: G, fontBackgroundColor: le, fontSelectedColor: ae, fontSelectedBackgroundColor: pe, fontHoverColor: se, fontHoverBackgroundColor: ge } = { ...cs, ...a }, q = p.size === "infinite" || p.features.zoom, [he, ce] = $(!1), [Ee, Ie] = $(!1), [He, ve] = $(q), ne = q && He, Te = N >= kt.large ? "large" : N >= kt.medium ? "medium" : N >= kt.small ? "small" : "none", { snackbarList: We, addSnackbar: Ce } = ds(), qe = B((fe, me, vt) => {
1658
- S((Be) => Be.map((it) => it.id === fe ? Pe(["settings", me, "default"], vt, it) : it)), T((Be) => Be.id === fe ? Pe(["settings", me, "default"], vt, Be) : Be);
1659
- }, [T, S]), Rt = B((fe) => {
1660
- ce(!0);
1664
+ }, vs = ({ editorProps: e, className: t, style: a, options: i, children: n }) => {
1665
+ const { shapesRef: o, addPictureShape: c, moveShapes: r, toggleShapeVisibility: s, toggleShapeLock: l, canGoBackward: u, canGoForward: d, canClear: h, selectedShape: m, removeShape: p, updateShape: Q, backwardShape: k, forwardShape: L, refs: C, width: M, height: g, selectTool: S, selectShapes: Z, activeTool: I, setActiveTool: H, setAvailableTools: y, isEditMode: P, availableTools: D, gridGap: A, setGridGap: E, loadFile: W, exportPicture: B, exportData: Y, clearCanvas: j, settings: V, setCanvasZoom: v, saveShapes: w, canvas: { canGrow: b, layersManipulation: T, withExport: x, withLoadAndSave: O, withUploadPicture: N, withUrlPicture: F } } = e, { toolbarBackgroundColor: z, dividerColor: oe, fontRadius: de, fontDisabledColor: re, fontDisabledBackgroundColor: K, fontColor: R, fontBackgroundColor: le, fontSelectedColor: se, fontSelectedBackgroundColor: ye, fontHoverColor: Me, fontHoverBackgroundColor: pe } = { ...ds, ...i }, te = V.size === "infinite" || V.features.zoom, [ge, G] = U(!1), [Se, Ie] = U(!1), [ze, ne] = U(te), fe = te && ze, We = A >= Pt.large ? "large" : A >= Pt.medium ? "medium" : A >= Pt.small ? "small" : "none", { snackbarList: Oe, addSnackbar: ke } = hs(), _e = $((ve, me, mt) => {
1666
+ y(($e) => $e.map((it) => it.id === ve ? Ve(["settings", me, "default"], mt, it) : it)), H(($e) => $e.id === ve ? Ve(["settings", me, "default"], mt, $e) : $e);
1667
+ }, [H, y]), Wt = $((ve) => {
1668
+ G(!0);
1661
1669
  try {
1662
- U(fe);
1670
+ B(ve);
1663
1671
  } catch (me) {
1664
- me instanceof Error && Ce({ type: "error", text: `L'export a échoué : ${me.message}` }), console.warn(me);
1672
+ me instanceof Error && ke({ type: "error", text: `L'export a échoué : ${me.message}` }), console.warn(me);
1665
1673
  } finally {
1666
- ce(!1);
1674
+ G(!1);
1667
1675
  }
1668
- }, [U, Ce]), Wt = B(() => {
1669
- ce(!0);
1676
+ }, [B, ke]), je = $(() => {
1677
+ G(!0);
1670
1678
  try {
1671
- F(), ce(!1);
1672
- } catch (fe) {
1673
- fe instanceof Error && Ce({ type: "error", text: "L'enregistrement a échoué" }), console.warn(fe);
1679
+ Y(), G(!1);
1680
+ } catch (ve) {
1681
+ ve instanceof Error && ke({ type: "error", text: "L'enregistrement a échoué" }), console.warn(ve);
1674
1682
  } finally {
1675
- ce(!1);
1683
+ G(!1);
1676
1684
  }
1677
- }, [F, Ce]), _e = B(async (fe) => {
1678
- ce(!0);
1685
+ }, [Y, ke]), Ot = $(async (ve) => {
1686
+ G(!0);
1679
1687
  try {
1680
- await D(fe), Ce({ type: "success", text: "Fichier chargé !" });
1688
+ await W(ve), ke({ type: "success", text: "Fichier chargé !" });
1681
1689
  } catch (me) {
1682
- me instanceof Error && Ce({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1690
+ me instanceof Error && ke({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1683
1691
  } finally {
1684
- ce(!1);
1692
+ G(!1);
1685
1693
  }
1686
- }, [D, Ce]), Ot = B(async (fe) => {
1687
- ce(!0);
1694
+ }, [W, ke]), Ft = $(async (ve) => {
1695
+ G(!0);
1688
1696
  try {
1689
- const me = await r(fe, m, y);
1697
+ const me = await c(ve, M, g);
1690
1698
  Z([me]);
1691
1699
  } catch (me) {
1692
- me instanceof Error && Ce({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1700
+ me instanceof Error && ke({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1693
1701
  } finally {
1694
- ce(!1);
1702
+ G(!1);
1695
1703
  }
1696
- }, [r, Z, Ce, m, y]), Ft = `${t ? `${t} ` : ""}${Ee ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1697
- return Y("div", { ref: w.setEditor, className: Ft, style: { "--react-paint-editor-app-maxWidth": M ? "100%" : `${m}px`, "--react-paint-editor-app-toolbar-bg": z, "--react-paint-editor-app-divider-color": ie, "--react-paint-editor-app-font-radius": re, "--react-paint-editor-app-font-disabled-color": R, "--react-paint-editor-app-font-disabled-bg": oe, "--react-paint-editor-app-font-color": G, "--react-paint-editor-app-font-bg": le, "--react-paint-editor-app-font-selected-color": ae, "--react-paint-editor-app-font-selected-bg": pe, "--react-paint-editor-app-font-hover-color": se, "--react-paint-editor-app-font-hover-bg": ge, ...i }, children: [V && v(ls, { settings: p, width: p.canvasSize.width, activeTool: A, clearCanvas: X, setActiveTool: b, exportCanvasInFile: Rt, saveFile: Wt, loadFile: _e, addPicture: Ot, hasActionToUndo: u, hasActionToRedo: d, hasActionToClear: h, undoAction: C, redoAction: k, availableTools: I, withExport: P, withLoadAndSave: E, withUploadPicture: W, withUrlPicture: O }), n, V && L && v(Xo, { gridFormat: Te, setGridFormat: (fe) => {
1698
- H(kt[fe]);
1699
- }, shapes: o.current, moveShapes: l, selectedShapes: f, removeShape: g, selectShapes: Z, toggleShapeVisibility: s, toggleShapeLock: c, isLayoutPanelShown: Ee, settings: p }), ne && Y(tt, { alignment: "left", className: "react-paint-editor-layouts-panel", "data-edit": +V, children: [v(K, { className: "react-paint-editor-zoom-button", icon: '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>', onClick: () => Q("unzoom") }), Y(K, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => Q("default"), children: [Math.round(100 * p.canvasZoom), "%"] }), v(K, { className: "react-paint-editor-zoom-button", icon: Za, onClick: () => Q("zoom") })] }), V && Y(Ve, { children: [v(is, { setCanvasZoom: Q, width: p.canvasSize.width, activeTool: A, availableTools: I, selectedShape: f, settings: p, removeShape: g, updateShape: x, canvas: w.canvas.current, layersManipulation: L, toggleLayoutPanel: () => {
1700
- Ie((fe) => !fe);
1701
- }, isZoomPanelShown: ne, setIsZoomPanelShown: ve, updateToolSettings: qe }), v(Ro, { isLoading: he }), v(Bo, { snackbarList: We })] })] });
1704
+ }, [c, Z, ke, M, g]), Bt = `${t ? `${t} ` : ""}${Se ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1705
+ return X("div", { ref: C.setEditor, className: Bt, style: { "--react-paint-editor-app-maxWidth": b ? "100%" : `${M}px`, "--react-paint-editor-app-toolbar-bg": z, "--react-paint-editor-app-divider-color": oe, "--react-paint-editor-app-font-radius": de, "--react-paint-editor-app-font-disabled-color": re, "--react-paint-editor-app-font-disabled-bg": K, "--react-paint-editor-app-font-color": R, "--react-paint-editor-app-font-bg": le, "--react-paint-editor-app-font-selected-color": se, "--react-paint-editor-app-font-selected-bg": ye, "--react-paint-editor-app-font-hover-color": Me, "--react-paint-editor-app-font-hover-bg": pe, ...a }, children: [P && f(cs, { settings: V, width: V.canvasSize.width, activeTool: I, clearCanvas: j, setActiveTool: S, exportCanvasInFile: Wt, saveFile: je, loadFile: Ot, addPicture: Ft, hasActionToUndo: u, hasActionToRedo: d, hasActionToClear: h, undoAction: k, redoAction: L, availableTools: D, withExport: x, withLoadAndSave: O, withUploadPicture: N, withUrlPicture: F }), n, P && T && f(Go, { gridFormat: We, setGridFormat: (ve) => {
1706
+ E(Pt[ve]);
1707
+ }, shapes: o.current, moveShapes: r, selectedShapes: m, removeShape: p, selectShapes: Z, toggleShapeVisibility: s, toggleShapeLock: l, isLayoutPanelShown: Se, settings: V }), fe && X(at, { alignment: "left", className: "react-paint-editor-layouts-panel", "data-edit": +P, children: [f(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: () => v("unzoom") }), X(J, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => v("default"), children: [Math.round(100 * V.canvasZoom), "%"] }), f(J, { className: "react-paint-editor-zoom-button", icon: Hi, onClick: () => v("zoom") })] }), P && X(Te, { children: [f(is, { saveShapes: w, setCanvasZoom: v, width: V.canvasSize.width, activeTool: I, availableTools: D, selectedShape: m, settings: V, removeShape: p, updateShape: Q, canvas: C.canvas.current, layersManipulation: T, toggleLayoutPanel: () => {
1708
+ Ie((ve) => !ve);
1709
+ }, isZoomPanelShown: fe, setIsZoomPanelShown: ne, updateToolSettings: _e }), f(Wo, { isLoading: ge }), f($o, { snackbarList: Oe })] })] });
1702
1710
  };
1703
1711
  export {
1704
- gs as Canvas,
1712
+ fs as Canvas,
1705
1713
  vs as Editor,
1706
- ps as useReactPaint
1714
+ gs as useReactPaint
1707
1715
  };