@yorab/react-paint 0.15.0 → 0.16.0

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