@yorab/react-paint 0.16.3 → 0.17.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,467 +1,463 @@
1
- import hi, { useState as $, useEffect as ee, useRef as ne, useCallback as X, useMemo as kn, useImperativeHandle as Ln, useTransition as Vn } from "react";
2
- import { jsx as m, jsxs as q, Fragment as Ae } from "react/jsx-runtime";
3
- const Zn = '<svg><path d="M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z"/></svg>', ui = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', pi = '<svg><path d="M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z"/></svg>', gi = '<svg><path d="M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z"/></svg>', Hn = '<svg><path d="M4.125 5.083V3.333H7.062L7.896 2.5H12.104L12.938 3.333H15.875V5.083ZM6.75 17.5Q6.021 17.5 5.51 16.99Q5 16.479 5 15.75V5.958H15V15.75Q15 16.479 14.49 16.99Q13.979 17.5 13.25 17.5Z"/></svg>', zi = '<svg><path d="M10 17.5Q7.208 17.5 5.271 15.594Q3.333 13.688 3.333 10.958Q3.333 9.583 3.854 8.396Q4.375 7.208 5.292 6.292L10 1.667L14.688 6.292Q15.604 7.208 16.135 8.396Q16.667 9.583 16.667 10.958Q16.667 13.688 14.719 15.594Q12.771 17.5 10 17.5ZM5.146 11.667H14.854Q15.083 10.188 14.552 9.146Q14.021 8.104 13.479 7.562L10 4.125L6.521 7.562Q5.979 8.104 5.448 9.146Q4.917 10.188 5.146 11.667Z"/></svg>', vi = '<svg><path d="M4.792 15.083 8.333 11.542 9.833 13.021 11.667 10.708 15.167 15.083ZM6.667 8.417Q5.938 8.417 5.427 7.906Q4.917 7.396 4.917 6.667Q4.917 5.938 5.427 5.427Q5.938 4.917 6.667 4.917Q7.396 4.917 7.906 5.427Q8.417 5.938 8.417 6.667Q8.417 7.396 7.906 7.906Q7.396 8.417 6.667 8.417ZM4.167 18.333Q3.125 18.333 2.396 17.604Q1.667 16.875 1.667 15.833V4.167Q1.667 3.125 2.396 2.396Q3.125 1.667 4.167 1.667H15.833Q16.875 1.667 17.604 2.396Q18.333 3.125 18.333 4.167V15.833Q18.333 16.875 17.604 17.604Q16.875 18.333 15.833 18.333ZM4.167 16.583H15.833Q16.146 16.583 16.365 16.365Q16.583 16.146 16.583 15.833V4.167Q16.583 3.854 16.365 3.635Q16.146 3.417 15.833 3.417H4.167Q3.854 3.417 3.635 3.635Q3.417 3.854 3.417 4.167V15.833Q3.417 16.146 3.635 16.365Q3.854 16.583 4.167 16.583Z"/></svg>', zn = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', Tn = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', An = '<svg><path d="M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z"/></svg>', Ti = '<svg><path d="M5.833 15V3.333H10.375Q11.812 3.333 12.885 4.156Q13.958 4.979 13.958 6.375Q13.958 7.375 13.49 7.969Q13.021 8.562 12.396 8.875V9.042Q13.312 9.354 13.844 10.021Q14.375 10.688 14.375 11.75Q14.375 13.312 13.229 14.156Q12.083 15 10.5 15ZM8.125 8.042H10.188Q10.854 8.042 11.302 7.656Q11.75 7.271 11.75 6.708Q11.75 6.167 11.302 5.771Q10.854 5.375 10.188 5.375H8.125ZM8.125 12.917H10.354Q11.167 12.917 11.625 12.51Q12.083 12.104 12.083 11.458Q12.083 10.812 11.625 10.406Q11.167 10 10.354 10H8.125Z"/></svg>', Ai = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', Di = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Ei = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM10 16.583Q10.896 16.583 11.708 16.365Q12.521 16.146 13.25 15.729L4.292 6.75Q3.875 7.479 3.646 8.292Q3.417 9.104 3.417 10Q3.417 12.729 5.344 14.656Q7.271 16.583 10 16.583ZM17 14.562 15.708 13.271Q16.125 12.542 16.354 11.719Q16.583 10.896 16.583 10Q16.583 7.271 14.656 5.344Q12.729 3.417 10 3.417Q9.104 3.417 8.292 3.646Q7.479 3.875 6.75 4.292L5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562ZM11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771ZM8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Z"/></svg>', Ii = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM17 14.562 5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562Z"/></svg>', Dn = '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Zm-40-60v-80h-80v-80h80v-80h80v80h80v80h-80v80h-80Z"/></svg>', Ce = ["transparent", "black", "white", "red", "green", "blue", "yellow"], Ue = [0, 1, 2], Wi = [[1, 0], [1, 2], [4, 6]], mt = "serif", Aa = 2, En = 3, Da = 4, he = "react-paint-", In = { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } }, fi = { type: "picture", id: `${he}picture`, icon: vi, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, Wn = { type: "brush", id: `${he}brush`, icon: Zn, label: "Brosse", settings: { strokeColor: { values: Ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: Ue, default: 0 } } }, Rn = { type: "line", id: `${he}line`, icon: Tn, label: "Ligne", settings: { strokeColor: { values: Ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, Nn = { type: "polygon", id: `${he}polygon`, icon: gi, label: "Polygone", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 }, closedPoints: { default: 0 } } }, Bn = { type: "curve", id: `${he}curve`, icon: An, label: "Courbe", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 }, closedPoints: { default: 0 } } }, On = { type: "rect", id: `${he}rect`, icon: ui, label: "Rectangle", settings: In }, Fn = { type: "square", id: `${he}square`, icon: ui, label: "Carré", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } } }, Yn = { type: "circle", id: `${he}circle`, icon: pi, label: "Cercle", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } } }, Xn = { type: "ellipse", id: `${he}ellipse`, icon: pi, label: "Ellipse", settings: { strokeColor: { values: Ce, default: "black" }, fillColor: { values: Ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Ue, default: 0 } } }, $n = { type: "text", id: `${he}text`, icon: zn, label: "Texte", settings: { strokeColor: { values: Ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: mt }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Oe = { id: `${he}selection`, type: "selection", icon: '<svg><path d="M8.0145 11.1707C8.38484 10.9914 8.82183 11.1558 8.99959 11.5295L10.7031 15.2591L12.0363 14.6238L10.3254 10.9017C10.1476 10.528 10.3106 10.0795 10.6809 9.90761L10.8883 9.84782L12.5918 9.51148L6.48133 4.33192V12.389L7.82934 11.2903L8.0145 11.1707ZM10.6587 16.9258C10.2883 17.1052 9.84395 16.9482 9.67359 16.5745L8.05894 13.0318L6.19988 14.5416C6.07396 14.6462 5.91842 14.706 5.74066 14.706C5.54423 14.706 5.35584 14.6272 5.21694 14.4871C5.07803 14.3469 5 14.1568 5 13.9586V2.74741C5 2.54919 5.07803 2.35908 5.21694 2.21891C5.35584 2.07874 5.54423 2 5.74066 2C5.91842 2 6.08878 2.06727 6.21469 2.1719L6.2221 2.16443L14.7323 9.36947C15.0508 9.63854 15.0879 10.1094 14.8286 10.4233C14.7175 10.5579 14.562 10.6475 14.4064 10.6774L12.0659 11.1408L13.6954 14.6761C13.888 15.0498 13.7102 15.4908 13.3399 15.6627L10.6587 16.9258Z"/></svg>', label: "Sélection" }, dt = { id: `${he}undo`, type: "undo", icon: '<svg><path d="M11.708 15.833H5.854V14.083H11.708Q13 14.083 13.958 13.292Q14.917 12.5 14.917 11.271Q14.917 10.042 13.958 9.24Q13 8.438 11.708 8.438H6.667L8.792 10.562L7.562 11.792L3.333 7.562L7.562 3.333L8.792 4.562L6.667 6.688H11.708Q13.729 6.688 15.198 7.99Q16.667 9.292 16.667 11.25Q16.667 13.208 15.198 14.521Q13.729 15.833 11.708 15.833Z"/></svg>', label: "Undo" }, ct = { id: `${he}redo`, type: "redo", icon: '<svg><path d="M8.292 15.833Q6.271 15.833 4.802 14.521Q3.333 13.208 3.333 11.25Q3.333 9.292 4.802 7.99Q6.271 6.688 8.292 6.688H13.333L11.208 4.562L12.438 3.333L16.667 7.562L12.438 11.792L11.208 10.562L13.333 8.438H8.292Q7 8.438 6.042 9.229Q5.083 10.021 5.083 11.25Q5.083 12.5 6.042 13.292Q7 14.083 8.292 14.083H14.146V15.833Z"/></svg>', label: "Redo" }, ht = { id: `${he}clear`, type: "clear", icon: '<svg><path d="M7.854 13.812 10 11.688 12.125 13.812 13.354 12.604 11.208 10.458 13.354 8.312 12.125 7.104 10 9.229 7.854 7.104 6.625 8.312 8.771 10.458 6.625 12.604ZM5.896 17.5Q5.167 17.5 4.656 16.99Q4.146 16.479 4.146 15.75V5.125H3.333V3.375H7.542V2.5H12.458V3.375H16.667V5.125H15.833V15.75Q15.833 16.479 15.323 16.99Q14.812 17.5 14.083 17.5Z"/></svg>', label: "Clear" }, _t = { id: `${he}export`, type: "export", icon: '<svg><path d="M10 13.271 5.708 8.979 6.958 7.729 9.125 9.896V3.333H10.875V9.896L13.042 7.729L14.292 8.979ZM5.083 16.667Q4.354 16.667 3.844 16.156Q3.333 15.646 3.333 14.917V12.5H5.083V14.917Q5.083 14.917 5.083 14.917Q5.083 14.917 5.083 14.917H14.917Q14.917 14.917 14.917 14.917Q14.917 14.917 14.917 14.917V12.5H16.667V14.917Q16.667 15.646 16.156 16.156Q15.646 16.667 14.917 16.667Z"/></svg>', label: "Export PNG" }, Ri = { id: `${he}load`, type: "loadfile", icon: '<svg><path d="M3.417 16.667Q2.729 16.667 2.198 16.135Q1.667 15.604 1.667 14.917V5.083Q1.667 4.396 2.198 3.865Q2.729 3.333 3.417 3.333H8.25L9.917 5H16.667Q17.354 5 17.844 5.531Q18.333 6.062 18.333 6.75H3.417V14.917Q3.417 14.917 3.417 14.917Q3.417 14.917 3.417 14.917L5.438 8.5H19.583L17.396 15.479Q17.229 16.021 16.802 16.344Q16.375 16.667 15.833 16.667Z"/></svg>', label: "Load project" }, jt = { id: `${he}save`, type: "savefile", icon: '<svg><path d="M17.5 5.833V15.75Q17.5 16.479 16.99 16.99Q16.479 17.5 15.75 17.5H4.25Q3.521 17.5 3.01 16.99Q2.5 16.479 2.5 15.75V4.25Q2.5 3.521 3.01 3.01Q3.521 2.5 4.25 2.5H14.167ZM10 14.917Q11.062 14.917 11.823 14.156Q12.583 13.396 12.583 12.333Q12.583 11.271 11.823 10.51Q11.062 9.75 10 9.75Q8.938 9.75 8.177 10.51Q7.417 11.271 7.417 12.333Q7.417 13.396 8.177 14.156Q8.938 14.917 10 14.917ZM5.021 8.396H12.521V5.021H5.021Z"/></svg>', label: "Save project" }, Kt = { id: `${he}move`, type: "move", icon: '<svg viewBox="0 -960 960 960"><path d="M412-48q-21.95 0-40.98-9Q352-66 338-83L48-434l27-28q17-17 41.5-20.5T162-473l126 74v-381q0-15.3 10.29-25.65Q308.58-816 323.79-816t25.71 10.35Q360-795.3 360-780v300h80v-396q0-15.3 10.29-25.65Q460.58-912 475.79-912t25.71 10.35Q512-891.3 512-876v396h80v-348q0-15.3 10.29-25.65Q612.58-864 627.79-864t25.71 10.35Q664-843.3 664-828v348h80v-252q0-15.3 10.29-25.65Q764.58-768 779.79-768t25.71 10.35Q816-747.3 816-732v540q0 60-42 102T672-48H412Z"/></svg>', label: "Move" }, Ni = { id: `${he}upload-picture`, type: "uploadpicture", icon: vi, label: "Upload picture" }, Un = 2, qn = "blue", Je = 14, Gn = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], _n = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], Ea = ["rect", "square", "circle", "ellipse", "picture", "text", "triangle", "brush", "group"], Ia = ["square", "circle", "picture", "text"], jn = "react-paint-canvas-drawcanvas", Kn = "react-paint-canvas-selectioncanvas", Bi = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [Wn, Rn, Nn, Bn, On, Fn, Yn, Xn, fi, $n], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, Wa = { canvasBackgroundColor: "white", canvasSelectionColor: qn, canvasSelectionWidth: Un }, Oi = 300, ai = (e, t) => {
1
+ import ki, { useState as K, useEffect as le, useRef as re, useCallback as X, useMemo as Fn, useImperativeHandle as Yn, useTransition as Xn } from "react";
2
+ import { jsx as v, jsxs as G, Fragment as Ne } from "react/jsx-runtime";
3
+ const $n = '<svg><path d="M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z"/></svg>', Li = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', Vi = '<svg><path d="M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z"/></svg>', Zi = '<svg><path d="M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z"/></svg>', Un = '<svg><path d="M4.125 5.083V3.333H7.062L7.896 2.5H12.104L12.938 3.333H15.875V5.083ZM6.75 17.5Q6.021 17.5 5.51 16.99Q5 16.479 5 15.75V5.958H15V15.75Q15 16.479 14.49 16.99Q13.979 17.5 13.25 17.5Z"/></svg>', qi = '<svg><path d="M10 17.5Q7.208 17.5 5.271 15.594Q3.333 13.688 3.333 10.958Q3.333 9.583 3.854 8.396Q4.375 7.208 5.292 6.292L10 1.667L14.688 6.292Q15.604 7.208 16.135 8.396Q16.667 9.583 16.667 10.958Q16.667 13.688 14.719 15.594Q12.771 17.5 10 17.5ZM5.146 11.667H14.854Q15.083 10.188 14.552 9.146Q14.021 8.104 13.479 7.562L10 4.125L6.521 7.562Q5.979 8.104 5.448 9.146Q4.917 10.188 5.146 11.667Z"/></svg>', zi = '<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>', qn = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', Gn = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', Gi = '<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>', _n = '<svg><path d="M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z"/></svg>', _i = '<svg><path d="M5.833 15V3.333H10.375Q11.812 3.333 12.885 4.156Q13.958 4.979 13.958 6.375Q13.958 7.375 13.49 7.969Q13.021 8.562 12.396 8.875V9.042Q13.312 9.354 13.844 10.021Q14.375 10.688 14.375 11.75Q14.375 13.312 13.229 14.156Q12.083 15 10.5 15ZM8.125 8.042H10.188Q10.854 8.042 11.302 7.656Q11.75 7.271 11.75 6.708Q11.75 6.167 11.302 5.771Q10.854 5.375 10.188 5.375H8.125ZM8.125 12.917H10.354Q11.167 12.917 11.625 12.51Q12.083 12.104 12.083 11.458Q12.083 10.812 11.625 10.406Q11.167 10 10.354 10H8.125Z"/></svg>', ji = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', Ki = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', Ji = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM10 16.583Q10.896 16.583 11.708 16.365Q12.521 16.146 13.25 15.729L4.292 6.75Q3.875 7.479 3.646 8.292Q3.417 9.104 3.417 10Q3.417 12.729 5.344 14.656Q7.271 16.583 10 16.583ZM17 14.562 15.708 13.271Q16.125 12.542 16.354 11.719Q16.583 10.896 16.583 10Q16.583 7.271 14.656 5.344Q12.729 3.417 10 3.417Q9.104 3.417 8.292 3.646Q7.479 3.875 6.75 4.292L5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562ZM11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771ZM8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Z"/></svg>', en = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM17 14.562 5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562Z"/></svg>', jn = '<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>', De = ["transparent", "black", "white", "red", "green", "blue", "yellow"], lt = [0, 1, 2], tn = [[1, 0], [1, 2], [4, 6]], It = "serif", jo = 2, Kn = 3, Ko = 4, Qe = "react-paint-", Jn = { strokeColor: { values: De, default: "black" }, fillColor: { values: De, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } }, Ai = { type: "picture", id: `${Qe}picture`, icon: zi, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, eo = { type: "brush", id: `${Qe}brush`, icon: $n, label: "Brosse", settings: { strokeColor: { values: De, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: lt, default: 0 } } }, to = { type: "line", id: `${Qe}line`, icon: Gn, label: "Ligne", settings: { strokeColor: { values: De, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, io = { type: "polygon", id: `${Qe}polygon`, icon: Zi, label: "Polygone", settings: { strokeColor: { values: De, default: "black" }, fillColor: { values: De, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, closedPoints: { default: 0 } } }, no = { type: "curve", id: `${Qe}curve`, icon: _n, label: "Courbe", settings: { strokeColor: { values: De, default: "black" }, fillColor: { values: De, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 }, closedPoints: { default: 0 } } }, oo = { type: "rect", id: `${Qe}rect`, icon: Li, label: "Rectangle", settings: Jn }, ao = { type: "square", id: `${Qe}square`, icon: Li, label: "Carré", settings: { strokeColor: { values: De, default: "black" }, fillColor: { values: De, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, so = { type: "circle", id: `${Qe}circle`, icon: Vi, label: "Cercle", settings: { strokeColor: { values: De, default: "black" }, fillColor: { values: De, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, ro = { type: "ellipse", id: `${Qe}ellipse`, icon: Vi, label: "Ellipse", settings: { strokeColor: { values: De, default: "black" }, fillColor: { values: De, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: lt, default: 0 } } }, lo = { type: "text", id: `${Qe}text`, icon: qn, label: "Texte", settings: { strokeColor: { values: De, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: It }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Je = { id: `${Qe}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" }, kt = { id: `${Qe}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: `${Qe}redo`, type: "redo", icon: '<svg><path d="M8.292 15.833Q6.271 15.833 4.802 14.521Q3.333 13.208 3.333 11.25Q3.333 9.292 4.802 7.99Q6.271 6.688 8.292 6.688H13.333L11.208 4.562L12.438 3.333L16.667 7.562L12.438 11.792L11.208 10.562L13.333 8.438H8.292Q7 8.438 6.042 9.229Q5.083 10.021 5.083 11.25Q5.083 12.5 6.042 13.292Q7 14.083 8.292 14.083H14.146V15.833Z"/></svg>', label: "Redo" }, Vt = { id: `${Qe}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" }, ci = { id: `${Qe}export`, type: "export", icon: '<svg><path d="M10 13.271 5.708 8.979 6.958 7.729 9.125 9.896V3.333H10.875V9.896L13.042 7.729L14.292 8.979ZM5.083 16.667Q4.354 16.667 3.844 16.156Q3.333 15.646 3.333 14.917V12.5H5.083V14.917Q5.083 14.917 5.083 14.917Q5.083 14.917 5.083 14.917H14.917Q14.917 14.917 14.917 14.917Q14.917 14.917 14.917 14.917V12.5H16.667V14.917Q16.667 15.646 16.156 16.156Q15.646 16.667 14.917 16.667Z"/></svg>', label: "Export PNG" }, nn = { id: `${Qe}load`, type: "loadfile", icon: '<svg><path d="M3.417 16.667Q2.729 16.667 2.198 16.135Q1.667 15.604 1.667 14.917V5.083Q1.667 4.396 2.198 3.865Q2.729 3.333 3.417 3.333H8.25L9.917 5H16.667Q17.354 5 17.844 5.531Q18.333 6.062 18.333 6.75H3.417V14.917Q3.417 14.917 3.417 14.917Q3.417 14.917 3.417 14.917L5.438 8.5H19.583L17.396 15.479Q17.229 16.021 16.802 16.344Q16.375 16.667 15.833 16.667Z"/></svg>', label: "Load project" }, hi = { id: `${Qe}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" }, pi = { id: `${Qe}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" }, on = { id: `${Qe}upload-picture`, type: "uploadpicture", icon: zi, label: "Upload picture" }, co = 2, ho = "blue", gt = 14, po = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], uo = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"], Jo = ["rect", "square", "circle", "ellipse", "picture", "text", "triangle", "brush", "group"], ea = ["square", "circle", "picture", "text"], go = "react-paint-canvas-drawcanvas", fo = "react-paint-canvas-selectioncanvas", an = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, withContextMenu: !0, availableTools: [eo, to, io, no, oo, ao, so, ro, Ai, lo], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !0, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never", debug: !1 }, ta = { canvasBackgroundColor: "white", canvasSelectionColor: ho, canvasSelectionWidth: co }, sn = 300, yi = (e, t) => {
4
4
  const i = { ...t };
5
5
  for (const n of e) Array.isArray(n) ? n[1].includes(i[n[0]]) && delete i[n[0]] : delete i[n];
6
6
  return i;
7
- }, Le = (e, t, i) => {
8
- const n = Array.isArray(i) ? [...i] : { ...i }, a = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
- return a.reduce((o, d, r) => (o[d] = oi(o[d]) ? { ...o[d] } : Array.isArray(o[d]) ? [...o[d]] : o[d] === void 0 || o[d] === null ? {} : o[d], r === a.length - 1 && (o[d] = t), o[d]), n), n;
10
- }, oi = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, Ie = (e, t, i) => {
11
- if (!oi(t) || !oi(i)) return i;
7
+ }, Xe = (e, t, i) => {
8
+ const n = Array.isArray(i) ? [...i] : { ...i }, o = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
9
+ return o.reduce((a, r, l) => (a[r] = bi(a[r]) ? { ...a[r] } : Array.isArray(a[r]) ? [...a[r]] : a[r] === void 0 || a[r] === null ? {} : a[r], l === o.length - 1 && (a[r] = t), a[r]), n), n;
10
+ }, bi = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, Ke = (e, t, i) => {
11
+ if (!bi(t) || !bi(i)) return i;
12
12
  const n = { ...t };
13
- for (const a in i) i.hasOwnProperty(a) && (n.hasOwnProperty(a) ? n[a] = e(n[a], i[a], a) ?? Ie(e, n[a], i[a]) : n[a] = i[a]);
13
+ for (const o in i) i.hasOwnProperty(o) && (n.hasOwnProperty(o) ? n[o] = e(n[o], i[o], o) ?? Ke(e, n[o], i[o]) : n[o] = i[o]);
14
14
  return n;
15
- }, Jn = (e, t) => {
15
+ }, vo = (e, t) => {
16
16
  if (e === t) return !0;
17
17
  if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
18
18
  const i = Object.keys(e), n = Object.keys(t);
19
19
  if (i.length !== n.length) return !1;
20
- for (const a of i) if (!n.includes(a) || !Jn(e[a], t[a])) return !1;
20
+ for (const o of i) if (!n.includes(o) || !vo(e[o], t[o])) return !1;
21
21
  return !0;
22
- }, Jt = {}, ue = (e = "") => (Jt[e] || (Jt[e] = 0), `${e}${++Jt[e]}`), We = (e, t, i) => Math.max(t, Math.min(e, i)), ea = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), ta = (e) => {
22
+ }, ui = {}, Ce = (e = "") => (ui[e] || (ui[e] = 0), `${e}${++ui[e]}`), et = (e, t, i) => Math.max(t, Math.min(e, i)), mo = () => typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), So = (e) => {
23
23
  e.reset(), e.lineCap = "round", e.lineJoin = "round";
24
- }, xe = (e, t = {}) => {
25
- const { lineCap: i = "round", fillColor: n = "transparent", opacity: a = 100, strokeColor: o = qn, lineWidth: d = Un, lineDash: r = 0, shadowColor: s = "transparent", shadowBlur: l = 0 } = t;
26
- e.lineCap = i, e.globalAlpha = a / 100, e.fillStyle = n, e.strokeStyle = o, e.lineWidth = d, e.setLineDash(r === 0 ? [] : [Wi[r][0] * d, Wi[r][1] * d]), e.shadowColor = s, e.shadowBlur = l;
27
- }, lt = (e, t, i, n) => {
24
+ }, Te = (e, t = {}) => {
25
+ const { lineCap: i = "round", fillColor: n = "transparent", opacity: o = 100, strokeColor: a = ho, lineWidth: r = co, lineDash: l = 0, shadowColor: s = "transparent", shadowBlur: d = 0 } = t;
26
+ e.lineCap = i, e.globalAlpha = o / 100, e.fillStyle = n, e.strokeStyle = a, e.lineWidth = r, e.setLineDash(l === 0 ? [] : [tn[l][0] * r, tn[l][1] * r]), e.shadowColor = s, e.shadowBlur = d;
27
+ }, Pt = (e, t, i, n) => {
28
28
  e.save(), e.scale(t.canvasSize.scaleRatio, t.canvasSize.scaleRatio), e.translate(t.canvasOffset[0], t.canvasOffset[1]), i && n && (e.translate(n[0], n[1]), e.rotate(i), e.translate(-n[0], -n[1]));
29
- }, si = (e) => 180 * e / Math.PI, ia = (e, t) => {
29
+ }, Qi = (e) => 180 * e / Math.PI, yo = (e, t) => {
30
30
  const i = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), n = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
31
31
  return Math.sqrt(i * i + n * n) <= t.radius;
32
- }, le = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
32
+ }, me = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
33
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
- }, Fi = (e) => (e + 2 * Math.PI) % (2 * Math.PI), Yi = ({ targetVector: [e, t], radian: i = !0, originVector: n }) => {
37
- const a = Fi(Math.atan2(t[1] - e[1], t[0] - e[0]));
34
+ const n = [t[0] - e[0], t[1] - e[1]], o = n[1] * Math.cos(i) - n[0] * Math.sin(i);
35
+ return [n[1] * Math.sin(i) + n[0] * Math.cos(i) + e[0], o + e[1]];
36
+ }, rn = (e) => (e + 2 * Math.PI) % (2 * Math.PI), ln = ({ targetVector: [e, t], radian: i = !0, originVector: n }) => {
37
+ const o = rn(Math.atan2(t[1] - e[1], t[0] - e[0]));
38
38
  if (n) {
39
- const [o, d] = n, r = Math.atan2(d[1] - o[1], d[0] - o[0]), s = Fi(a - r);
40
- return i ? s : si(s);
39
+ const [a, r] = n, l = Math.atan2(r[1] - a[1], r[0] - a[0]), s = rn(o - l);
40
+ return i ? s : Qi(s);
41
41
  }
42
- return i ? a : si(a);
43
- }, na = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), et = (e, t, i) => {
44
- const n = le({ origin: t.computed.center, point: e.computed.center, rotation: t.rotation ?? 0 }), a = (n[0] - (e.computed.borders.width / 2 - i.settings.selectionPadding) - (i.originalBorders.x + i.settings.selectionPadding)) * i.widthMultiplier, o = (n[1] - (e.computed.borders.height / 2 - i.settings.selectionPadding) - (i.originalBorders.y + i.settings.selectionPadding)) * i.heightMultiplier;
45
- return { x: i.newBorderX + i.settings.selectionPadding + (i.isXinverted ? i.newBorderWidth - 2 * i.settings.selectionPadding - (e.computed.borders.width - 2 * i.settings.selectionPadding || 1) * i.widthMultiplier - a : a), y: i.newBorderY + i.settings.selectionPadding + (i.isYinverted ? i.newBorderHeight - 2 * i.settings.selectionPadding - (e.computed.borders.height - 2 * i.settings.selectionPadding || 1) * i.heightMultiplier - o : o) };
46
- }, tt = (e, t, i, n, a) => le({ origin: e.groupCenter, point: [t + n / 2, i + a / 2], rotation: -e.rotation }), mi = (e, { selectionPadding: t }) => {
47
- const i = e.points.flat(), n = Math.min(...i.map((s) => s[0])), a = Math.min(...i.map((s) => s[1])), o = i.map((s) => Ee(s, n, a, e.scaleX, e.scaleY)), d = Math.max(...o.map((s) => s[0])) + t, r = Math.max(...o.map((s) => s[1])) + t;
48
- return { x: n - t, width: d - n + t, y: a - t, height: r - a + t };
49
- }, ut = (e, t) => {
50
- const i = Ba(e, t), n = ((a, o) => Be(a, mi, o))(e, t);
51
- return { ...e, path: i, selection: pt(i, n, t), computed: n };
52
- }, Ra = ut, Ve = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Ee = (e, t, i, n = 1, a = 1) => [t + (e[0] - t) * n, i + (e[1] - i) * a], we = (e, t, i = 0) => {
53
- if (!t.gridGap) return Ve(e);
54
- const n = e + i, a = n >= 0 ? t.gridGap : -t.gridGap;
55
- return n + a / 2 - (n + a / 2) % a - i;
56
- }, Na = (e, t, i, n, a, o, d) => {
57
- if (n.mode === "translate") return pe(ma(i, n.originalShape, n.cursorStartPosition, a, o), a);
42
+ return i ? o : Qi(o);
43
+ }, bo = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), vt = (e, t, i) => {
44
+ const n = me({ origin: t.computed.center, point: e.computed.center, rotation: t.rotation ?? 0 }), o = (n[0] - (e.computed.borders.width / 2 - i.settings.selectionPadding) - (i.originalBorders.x + i.settings.selectionPadding)) * i.widthMultiplier, a = (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 - o : o), 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 - a : a) };
46
+ }, mt = (e, t, i, n, o) => me({ origin: e.groupCenter, point: [t + n / 2, i + o / 2], rotation: -e.rotation }), Hi = (e, { selectionPadding: t }) => {
47
+ const i = e.points.flat(), n = Math.min(...i.map((s) => s[0])), o = Math.min(...i.map((s) => s[1])), a = i.map((s) => Ge(s, n, o, e.scaleX, e.scaleY)), r = Math.max(...a.map((s) => s[0])) + t, l = Math.max(...a.map((s) => s[1])) + t;
48
+ return { x: n - t, width: r - n + t, y: o - t, height: l - o + t };
49
+ }, Zt = (e, t) => {
50
+ const i = oa(e, t), n = ((o, a) => it(o, Hi, a))(e, t);
51
+ return { ...e, path: i, selection: zt(i, n, t), computed: n };
52
+ }, ia = Zt, We = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Ge = (e, t, i, n = 1, o = 1) => [t + (e[0] - t) * n, i + (e[1] - i) * o], Ze = (e, t, i = 0) => {
53
+ if (!t.gridGap) return We(e);
54
+ const n = e + i, o = n >= 0 ? t.gridGap : -t.gridGap;
55
+ return n + o / 2 - (n + o / 2) % o - i;
56
+ }, na = (e, t, i, n, o, a, r) => {
57
+ if (n.mode === "translate") return de(Do(i, n.originalShape, n.cursorStartPosition, o, a), o);
58
58
  if (n.mode === "rotate") {
59
- const r = n.originalShape.computed.center[0] - n.cursorStartPosition[0], s = n.originalShape.computed.center[1] - n.cursorStartPosition[1], l = n.originalShape.computed.center[0] - i[0], h = n.originalShape.computed.center[1] - i[1], c = ((f, v, p) => v.gridGap || p ? f + Math.PI / 18 / 2 - (f + Math.PI / 18 / 2) % (Math.PI / 18) : Ve(f, 3))(Math.atan2(h, l) - Math.atan2(s, r), a, o), u = Y(n.originalShape).map((f) => Ne(go(f, c, n.originalShape.computed.center), a));
60
- return pe(u, a);
59
+ const l = n.originalShape.computed.center[0] - n.cursorStartPosition[0], s = n.originalShape.computed.center[1] - n.cursorStartPosition[1], d = n.originalShape.computed.center[0] - i[0], h = n.originalShape.computed.center[1] - i[1], c = ((p, m, u) => m.gridGap || u ? p + Math.PI / 18 / 2 - (p + Math.PI / 18 / 2) % (Math.PI / 18) : We(p, 3))(Math.atan2(h, d) - Math.atan2(s, l), o, a), f = U(n.originalShape).map((p) => _e(Ho(p, c, n.originalShape.computed.center), o));
60
+ return de(f, o);
61
61
  }
62
- return n.mode === "resize" ? pe(vo(e, i, n.originalShape, n, a, o, d), a) : n.mode === "brush" ? pe(Y(t).map((r) => ((s, l, h) => {
63
- const c = { ...s, points: Le(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(l[0]), Math.round(l[1])]], s.points) };
64
- return ut(c, h);
65
- })(r, i, a)), a) : t;
66
- }, yt = (e) => {
62
+ return n.mode === "resize" ? de(Za(e, i, n.originalShape, n, o, a, r), o) : n.mode === "brush" ? de(U(t).map((l) => ((s, d, h) => {
63
+ const c = { ...s, points: Xe(s.points.length - 1, [...s.points[s.points.length - 1], [Math.round(d[0]), Math.round(d[1])]], s.points) };
64
+ return Zt(c, h);
65
+ })(l, i, o)), o) : t;
66
+ }, Rt = (e) => {
67
67
  const t = new Path2D();
68
68
  return t.rect(e.x, e.y, e.width, e.height), t;
69
- }, Vt = (e) => {
69
+ }, Gt = (e) => {
70
70
  const t = new Path2D();
71
71
  return t.arc(e.x, e.y, e.radius, 0, 2 * Math.PI), t;
72
- }, Zt = (e) => {
72
+ }, _t = (e) => {
73
73
  const t = new Path2D();
74
74
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t;
75
- }, Ba = (e, { brushAlgo: t }) => {
75
+ }, oa = (e, { brushAlgo: t }) => {
76
76
  const i = new Path2D();
77
77
  if (e.points.length < 1) return i;
78
- const n = e.points.flat(), a = n.map((s) => s[0]), o = n.map((s) => s[1]), d = Math.min(...a), r = Math.min(...o);
79
- for (const s of e.points) if (s.length) if (s.length === 1) i.rect(...Ee(s[0], d, r, e.scaleX, e.scaleY), 1, 1);
80
- else if (i.moveTo(...Ee(s[0], d, r, e.scaleX, e.scaleY)), t === "quadratic") {
81
- for (let l = 0; l < s.slice(1).length - 2; l++) {
82
- const h = Ee(s[l], d, r, e.scaleX, e.scaleY), c = Ee(s[l + 1], d, r, e.scaleX, e.scaleY), u = (h[0] + c[0]) / 2, f = (h[1] + c[1]) / 2;
83
- i.quadraticCurveTo(...h, u, f);
78
+ const n = e.points.flat(), o = n.map((s) => s[0]), a = n.map((s) => s[1]), r = Math.min(...o), l = Math.min(...a);
79
+ for (const s of e.points) if (s.length) if (s.length === 1) i.rect(...Ge(s[0], r, l, e.scaleX, e.scaleY), 1, 1);
80
+ else if (i.moveTo(...Ge(s[0], r, l, e.scaleX, e.scaleY)), t === "quadratic") {
81
+ for (let d = 0; d < s.slice(1).length - 2; d++) {
82
+ const h = Ge(s[d], r, l, e.scaleX, e.scaleY), c = Ge(s[d + 1], r, l, e.scaleX, e.scaleY), f = (h[0] + c[0]) / 2, p = (h[1] + c[1]) / 2;
83
+ i.quadraticCurveTo(...h, f, p);
84
84
  }
85
- i.quadraticCurveTo(...Ee(s[s.length - 2], d, r, e.scaleX, e.scaleY), ...Ee(s[s.length - 1], d, r, e.scaleX, e.scaleY));
86
- } else for (const l of s.slice(1)) i.lineTo(...Ee(l, d, r, e.scaleX, e.scaleY));
85
+ i.quadraticCurveTo(...Ge(s[s.length - 2], r, l, e.scaleX, e.scaleY), ...Ge(s[s.length - 1], r, l, e.scaleX, e.scaleY));
86
+ } else for (const d of s.slice(1)) i.lineTo(...Ge(d, r, l, e.scaleX, e.scaleY));
87
87
  return i;
88
- }, Oa = (e, t, i, n) => {
89
- const a = (w) => (1 - w) ** 3 * e[0] + 3 * (1 - w) ** 2 * w * t[0] + 3 * (1 - w) * w ** 2 * i[0] + w ** 3 * n[0], o = (w) => (1 - w) ** 3 * e[1] + 3 * (1 - w) ** 2 * w * t[1] + 3 * (1 - w) * w ** 2 * i[1] + w ** 3 * n[1], d = (w, L, D) => {
90
- const V = w - 2 * L + D, x = -2 * w + 2 * L, Z = w;
91
- if (Math.abs(V) < 1e-10) {
92
- if (Math.abs(x) < 1e-10) return [];
93
- const G = -Z / x;
94
- return G > 0 && G < 1 ? [G] : [];
88
+ }, aa = (e, t, i, n) => {
89
+ const o = (g) => (1 - g) ** 3 * e[0] + 3 * (1 - g) ** 2 * g * t[0] + 3 * (1 - g) * g ** 2 * i[0] + g ** 3 * n[0], a = (g) => (1 - g) ** 3 * e[1] + 3 * (1 - g) ** 2 * g * t[1] + 3 * (1 - g) * g ** 2 * i[1] + g ** 3 * n[1], r = (g, P, z) => {
90
+ const D = g - 2 * P + z, A = -2 * g + 2 * P, H = g;
91
+ if (Math.abs(D) < 1e-10) {
92
+ if (Math.abs(A) < 1e-10) return [];
93
+ const oe = -H / A;
94
+ return oe > 0 && oe < 1 ? [oe] : [];
95
95
  }
96
- const A = x * x - 4 * V * Z;
97
- if (A < 0) return [];
98
- const H = Math.sqrt(A), F = (-x - H) / (2 * V), E = (-x + H) / (2 * V), W = [];
99
- return F > 0 && F < 1 && W.push(F), E > 0 && E < 1 && E !== F && W.push(E), W;
100
- }, r = e[0], s = t[0], l = i[0], h = n[0], c = e[1], u = t[1], f = i[1], v = n[1], p = d(s - r, l - s, h - l), S = d(u - c, f - u, v - f);
101
- let C = Math.min(e[0], n[0]), b = Math.max(e[0], n[0]), Q = Math.min(e[1], n[1]), g = Math.max(e[1], n[1]);
102
- for (const w of p) {
103
- const L = a(w);
104
- C = Math.min(C, L), b = Math.max(b, L);
96
+ const Z = A * A - 4 * D * H;
97
+ if (Z < 0) return [];
98
+ const E = Math.sqrt(Z), F = (-A - E) / (2 * D), W = (-A + E) / (2 * D), I = [];
99
+ return F > 0 && F < 1 && I.push(F), W > 0 && W < 1 && W !== F && I.push(W), I;
100
+ }, l = e[0], s = t[0], d = i[0], h = n[0], c = e[1], f = t[1], p = i[1], m = n[1], u = r(s - l, d - s, h - d), S = r(f - c, p - f, m - p);
101
+ let w = Math.min(e[0], n[0]), x = Math.max(e[0], n[0]), b = Math.min(e[1], n[1]), y = Math.max(e[1], n[1]);
102
+ for (const g of u) {
103
+ const P = o(g);
104
+ w = Math.min(w, P), x = Math.max(x, P);
105
105
  }
106
- for (const w of S) {
107
- const L = o(w);
108
- Q = Math.min(Q, L), g = Math.max(g, L);
106
+ for (const g of S) {
107
+ const P = a(g);
108
+ b = Math.min(b, P), y = Math.max(y, P);
109
109
  }
110
- return { minX: C, maxX: b, minY: Q, maxY: g };
111
- }, yi = (e, t) => e.style?.closedPoints === 1 && t.length > 2 ? [t[t.length - 2], ...t, t[0], t[1]] : [t[0], ...t, t[t.length - 1]], Si = (e, t, i, n) => ({ cp1: [t[0] + (i[0] - e[0]) / 6, t[1] + (i[1] - e[1]) / 6], cp2: [i[0] - (n[0] - t[0]) / 6, i[1] - (n[1] - t[1]) / 6] }), aa = (e) => {
110
+ return { minX: w, maxX: x, minY: b, maxY: y };
111
+ }, Ti = (e, t) => e.style?.closedPoints === 1 && t.length > 2 ? [t[t.length - 2], ...t, t[0], t[1]] : [t[0], ...t, t[t.length - 1]], Di = (e, t, i, n) => ({ cp1: [t[0] + (i[0] - e[0]) / 6, t[1] + (i[1] - e[1]) / 6], cp2: [i[0] - (n[0] - t[0]) / 6, i[1] - (n[1] - t[1]) / 6] }), Qo = (e) => {
112
112
  const t = new Path2D(), i = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
113
113
  if (i.length < 2) return t;
114
114
  t.moveTo(...i[0]);
115
115
  for (const n of i.slice(1)) t.lineTo(...n);
116
116
  return i.length > 2 && e.style?.closedPoints === 1 && t.lineTo(...i[0]), t;
117
- }, Fa = (e) => {
117
+ }, sa = (e) => {
118
118
  const t = new Path2D();
119
119
  return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t.lineTo(...e.points[2]), t.lineTo(...e.points[0]), t;
120
- }, Ya = (e, t) => ({ x: t.x - (e.style?.lineWidth ?? 0) / 2, y: t.y - (e.style?.lineWidth ?? 0) / 2, width: t.width + (e.style?.lineWidth ?? 0), height: t.height + (e.style?.lineWidth ?? 0) }), Be = (e, t, i, n = Ya) => {
121
- const a = t(e, i), o = n(e, a, i), d = [a.x + a.width / 2, a.y + a.height / 2], r = ((s, l, h = 0) => {
120
+ }, ra = (e, t) => ({ x: t.x - (e.style?.lineWidth ?? 0) / 2, y: t.y - (e.style?.lineWidth ?? 0) / 2, width: t.width + (e.style?.lineWidth ?? 0), height: t.height + (e.style?.lineWidth ?? 0) }), it = (e, t, i, n = ra) => {
121
+ const o = t(e, i), a = n(e, o, i), r = [o.x + o.width / 2, o.y + o.height / 2], l = ((s, d, h = 0) => {
122
122
  if (h === 0) return s;
123
- const c = [[s.x, s.y], [s.x + s.width, s.y], [s.x + s.width, s.y + s.height], [s.x, s.y + s.height]].map((v) => le({ point: v, origin: l, rotation: h })), u = Math.min(...c.map((v) => v[0])), f = Math.min(...c.map((v) => v[1]));
124
- return { x: u, y: f, width: Math.max(...c.map((v) => v[0])) - u, height: Math.max(...c.map((v) => v[1])) - f };
125
- })(o, d, e.rotation);
126
- return { borders: a, outerBorders: o, center: d, boundingBox: r };
127
- }, pt = (e, t, i) => {
123
+ const c = [[s.x, s.y], [s.x + s.width, s.y], [s.x + s.width, s.y + s.height], [s.x, s.y + s.height]].map((m) => me({ point: m, origin: d, rotation: h })), f = Math.min(...c.map((m) => m[0])), p = Math.min(...c.map((m) => m[1]));
124
+ return { x: f, y: p, width: Math.max(...c.map((m) => m[0])) - f, height: Math.max(...c.map((m) => m[1])) - p };
125
+ })(a, r, e.rotation);
126
+ return { borders: o, outerBorders: a, center: r, boundingBox: l };
127
+ }, zt = (e, t, i) => {
128
128
  const { borders: n } = t;
129
- return { type: "rect", border: yt(n), shapePath: e, line: Zt({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: [Vt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...Gn.map((a) => Vt({ x: n.x + n.width * a[0], y: n.y + n.height * a[1], radius: 7 / i.canvasSize.scaleRatio }))] };
130
- }, Xi = ({ borderStart: e, borderSize: t, vector: i, settings: n, invertedAxe: a, anchor: o }) => {
131
- switch (o) {
129
+ return { type: "rect", border: Rt(n), shapePath: e, line: _t({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: [Gt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...po.map((o) => Gt({ x: n.x + n.width * o[0], y: n.y + n.height * o[1], radius: 7 / i.canvasSize.scaleRatio }))] };
130
+ }, dn = ({ borderStart: e, borderSize: t, vector: i, settings: n, invertedAxe: o, anchor: a }) => {
131
+ switch (a) {
132
132
  case 0: {
133
- if (a) {
134
- const r = Math.max(0, i - t) + 2 * n.selectionPadding;
135
- return [e + t - 2 * n.selectionPadding, r];
133
+ if (o) {
134
+ const l = Math.max(0, i - t) + 2 * n.selectionPadding;
135
+ return [e + t - 2 * n.selectionPadding, l];
136
136
  }
137
- const d = Math.max(2 * n.selectionPadding, t - i);
138
- return [e + t - d, d];
137
+ const r = Math.max(2 * n.selectionPadding, t - i);
138
+ return [e + t - r, r];
139
139
  }
140
140
  case 0.5:
141
141
  return [e, t];
142
142
  case 1:
143
- if (a) {
144
- const d = Math.min(e, e + t + i);
145
- return [d, e - d + 2 * n.selectionPadding];
143
+ if (o) {
144
+ const r = Math.min(e, e + t + i);
145
+ return [r, e - r + 2 * n.selectionPadding];
146
146
  }
147
147
  return [e, Math.max(2 * n.selectionPadding, t + i)];
148
148
  default:
149
149
  return [0, 0];
150
150
  }
151
- }, Xa = ({ borderX: e, borderWidth: t, borderY: i, borderHeight: n, center: a, originalShape: o }) => {
152
- const d = [e + t / 2 - a[0], i + n / 2 - a[1]], [r, s] = le({ point: d, rotation: -(o.rotation ?? 0) });
153
- return { borderX: Ve(e + r - d[0]), borderWidth: Ve(t), borderY: Ve(i + s - d[1]), borderHeight: Ve(n) };
154
- }, $a = (e, t, i, n) => {
155
- const a = t.x + t.width / 2, o = t.y + t.height / 2, d = i ? 2 * e.borderWidth + t.width : Math.abs(t.width + 2 * (e.borderWidth - t.width)), r = n ? 2 * e.borderHeight + t.height : Math.abs(t.height + 2 * (e.borderHeight - t.height));
156
- return { ...e, borderHeight: r, borderWidth: d, borderX: a - d / 2, borderY: o - r / 2 };
157
- }, it = (e, t, i, n, a = !1, o = !1) => {
158
- const { center: d, borders: r } = t.computed, s = le({ origin: d, point: e, rotation: t.rotation }), l = i.anchor[0] === 0 && s[0] >= r.x + r.width - n.selectionPadding || i.anchor[0] === 1 && s[0] <= r.x + n.selectionPadding, h = i.anchor[1] === 0 && s[1] >= r.y + r.height - n.selectionPadding || i.anchor[1] === 1 && s[1] <= r.y + n.selectionPadding, c = [we(s[0], n, i.anchor[0] === 0 && !l || i.anchor[0] === 1 && l ? n.selectionPadding : -n.selectionPadding), we(s[1], n, i.anchor[1] === 0 && !h || i.anchor[1] === 1 && h ? n.selectionPadding : -n.selectionPadding)], u = n.gridGap ? [i.anchor[0] === 0 ? r.x : i.anchor[0] === 0.5 ? r.x + r.width / 2 : r.x + r.width, i.anchor[1] === 0 ? r.y : i.anchor[1] === 0.5 ? r.y + r.height / 2 : r.y + r.height] : le({ origin: d, point: i.cursorStartPosition, rotation: t.rotation }), f = [c[0] - u[0], c[1] - u[1]], [v, p] = Xi({ borderStart: r.x, borderSize: r.width, vector: f[0], settings: n, invertedAxe: l, anchor: i.anchor[0] }), [S, C] = Xi({ borderStart: r.y, borderSize: r.height, vector: f[1], settings: n, invertedAxe: h, anchor: i.anchor[1] }), b = a ? ((Q, g, w, L, D, V, x, Z, A, H, F) => {
159
- const { selectionPadding: E } = F, W = "ratio" in A && A.ratio ? A.ratio : (Q.width - 2 * E || 1) / (Q.height - 2 * E || 1), G = (L - 2 * E) / (V - 2 * E);
160
- let _, z, y, M;
161
- return H.anchor[0] !== 0.5 && H.anchor[1] !== 0.5 ? G < W ? (z = D, M = V, y = (V - 2 * E) * W + 2 * E, _ = H.anchor[0] === 0 ? x ? Q.x + Q.width - 2 * E : Q.x + (Q.width - y) : x ? Q.x - y + 2 * E : Q.x) : (_ = w, y = L, M = (L - 2 * E) / W + 2 * E, z = H.anchor[1] === 0 ? Z ? Q.y + Q.height - 2 * E : Q.y + (Q.height - M) : Z ? Q.y - M + 2 * E : Q.y) : H.anchor[0] !== 0.5 ? (_ = w, y = L, M = (L - 2 * E) / W + 2 * E, z = Q.y + (Q.height - M) / 2) : (z = D, M = V, y = (V - 2 * E) * W + 2 * E, _ = Q.x + (Q.width - y) / 2), { borderX: _, borderWidth: y, borderY: z, borderHeight: M, center: g, originalShape: A };
162
- })(r, d, v, p, S, C, l, h, t, i, n) : { borderX: v, borderWidth: p, borderY: S, borderHeight: C, center: d, originalShape: t };
163
- return { ...Xa(o ? $a(b, r, l, h) : b), isXinverted: l, isYinverted: h };
164
- }, zt = (e, t) => {
165
- const i = yt(e), n = ((a, o) => Be(a, Qi, o))(e, t);
166
- return { ...e, path: i, computed: n, selection: pt(i, n, t) };
167
- }, Ua = zt, oa = (e, t, i, n = 0, a = 0) => {
168
- const o = { toolId: e.id, type: e.type, id: ue(`${e.type}_`), x: t[0], y: t[1], width: n, height: a, style: { opacity: e.settings.opacity.default, fillColor: e.settings.fillColor.default, strokeColor: e.settings.strokeColor.default, lineWidth: e.settings.lineWidth.default, lineDash: e.settings.lineDash.default } };
169
- return zt(o, i);
170
- }, qa = (e, t) => {
151
+ }, la = ({ borderX: e, borderWidth: t, borderY: i, borderHeight: n, center: o, originalShape: a }) => {
152
+ const r = [e + t / 2 - o[0], i + n / 2 - o[1]], [l, s] = me({ point: r, rotation: -(a.rotation ?? 0) });
153
+ return { borderX: We(e + l - r[0]), borderWidth: We(t), borderY: We(i + s - r[1]), borderHeight: We(n) };
154
+ }, da = (e, t, i, n) => {
155
+ const o = t.x + t.width / 2, a = t.y + t.height / 2, r = i ? 2 * e.borderWidth + t.width : Math.abs(t.width + 2 * (e.borderWidth - t.width)), l = n ? 2 * e.borderHeight + t.height : Math.abs(t.height + 2 * (e.borderHeight - t.height));
156
+ return { ...e, borderHeight: l, borderWidth: r, borderX: o - r / 2, borderY: a - l / 2 };
157
+ }, St = (e, t, i, n, o = !1, a = !1) => {
158
+ const { center: r, borders: l } = t.computed, s = me({ origin: r, point: e, rotation: t.rotation }), d = i.anchor[0] === 0 && s[0] >= l.x + l.width - n.selectionPadding || i.anchor[0] === 1 && s[0] <= l.x + n.selectionPadding, h = i.anchor[1] === 0 && s[1] >= l.y + l.height - n.selectionPadding || i.anchor[1] === 1 && s[1] <= l.y + n.selectionPadding, c = [Ze(s[0], n, i.anchor[0] === 0 && !d || i.anchor[0] === 1 && d ? n.selectionPadding : -n.selectionPadding), Ze(s[1], n, i.anchor[1] === 0 && !h || i.anchor[1] === 1 && h ? n.selectionPadding : -n.selectionPadding)], f = n.gridGap ? [i.anchor[0] === 0 ? l.x : i.anchor[0] === 0.5 ? l.x + l.width / 2 : l.x + l.width, i.anchor[1] === 0 ? l.y : i.anchor[1] === 0.5 ? l.y + l.height / 2 : l.y + l.height] : me({ origin: r, point: i.cursorStartPosition, rotation: t.rotation }), p = [c[0] - f[0], c[1] - f[1]], [m, u] = dn({ borderStart: l.x, borderSize: l.width, vector: p[0], settings: n, invertedAxe: d, anchor: i.anchor[0] }), [S, w] = dn({ borderStart: l.y, borderSize: l.height, vector: p[1], settings: n, invertedAxe: h, anchor: i.anchor[1] }), x = o ? ((b, y, g, P, z, D, A, H, Z, E, F) => {
159
+ const { selectionPadding: W } = F, I = "ratio" in Z && Z.ratio ? Z.ratio : (b.width - 2 * W || 1) / (b.height - 2 * W || 1), oe = (P - 2 * W) / (D - 2 * W);
160
+ let te, R, $, j;
161
+ return E.anchor[0] !== 0.5 && E.anchor[1] !== 0.5 ? oe < I ? (R = z, j = D, $ = (D - 2 * W) * I + 2 * W, te = E.anchor[0] === 0 ? A ? b.x + b.width - 2 * W : b.x + (b.width - $) : A ? b.x - $ + 2 * W : b.x) : (te = g, $ = P, j = (P - 2 * W) / I + 2 * W, R = E.anchor[1] === 0 ? H ? b.y + b.height - 2 * W : b.y + (b.height - j) : H ? b.y - j + 2 * W : b.y) : E.anchor[0] !== 0.5 ? (te = g, $ = P, j = (P - 2 * W) / I + 2 * W, R = b.y + (b.height - j) / 2) : (R = z, j = D, $ = (D - 2 * W) * I + 2 * W, te = b.x + (b.width - $) / 2), { borderX: te, borderWidth: $, borderY: R, borderHeight: j, center: y, originalShape: Z };
162
+ })(l, r, m, u, S, w, d, h, t, i, n) : { borderX: m, borderWidth: u, borderY: S, borderHeight: w, center: r, originalShape: t };
163
+ return { ...la(a ? da(x, l, d, h) : x), isXinverted: d, isYinverted: h };
164
+ }, Kt = (e, t) => {
165
+ const i = Rt(e), n = ((o, a) => it(o, Ei, a))(e, t);
166
+ return { ...e, path: i, computed: n, selection: zt(i, n, t) };
167
+ }, ca = Kt, wo = (e, t, i, n = 0, o = 0) => {
168
+ const a = { toolId: e.id, type: e.type, id: Ce(`${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 } };
169
+ return Kt(a, i);
170
+ }, ha = (e, t) => {
171
171
  e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
172
- }, Qi = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), $i = (e, t, i, [n, a] = [!1, !1]) => {
173
- const o = e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (n ? 0 : i.width) : i.x + (n ? i.width : 0), d = e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (a ? 0 : i.height) : i.y + (a ? i.height : 0);
174
- return ri([o, d], i.rotation ?? 0, t);
175
- }, Ui = (e, t, i, n, a, o, d, r = "replace") => {
172
+ }, Ei = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), cn = (e, t, i, [n, o] = [!1, !1]) => {
173
+ const a = e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (n ? 0 : i.width) : i.x + (n ? i.width : 0), r = e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (o ? 0 : i.height) : i.y + (o ? i.height : 0);
174
+ return wi([a, r], i.rotation ?? 0, t);
175
+ }, Bt = (e, t, i, n, o, a, r, l = "replace") => {
176
176
  let s = !1;
177
- if (a) {
178
- s = ft(e, a, i, n, !0, o ? 20 : void 0);
179
- const h = ((c, u, f) => {
180
- if (c.mode === "translate") return { mode: "translate", cursorStartPosition: f, originalShape: u, hasBeenDuplicated: !1, dateStart: Date.now(), selectedShapesLengthAtMouseDown: Y(u).length };
177
+ if (o) {
178
+ s = Et(e, o, i, n, !0, a ? 20 : void 0);
179
+ const h = ((c, f, p) => {
180
+ if (c.mode === "translate") return { mode: "translate", cursorStartPosition: p, originalShape: f, hasBeenDuplicated: !1, dateStart: Date.now(), selectedShapesLengthAtMouseDown: U(f).length };
181
181
  if (c.mode === "rotate") {
182
- const { center: v } = u.computed;
183
- return { mode: "rotate", cursorStartPosition: f, originalShape: u, center: [v[0], v[1]], selectedShapesLengthAtMouseDown: Y(u).length };
182
+ const { center: m } = f.computed;
183
+ return { mode: "rotate", cursorStartPosition: p, originalShape: f, center: [m[0], m[1]], selectedShapesLengthAtMouseDown: U(f).length };
184
184
  }
185
- return c.mode === "resize" ? { mode: "resize", cursorStartPosition: f, originalShape: u, anchor: c.anchor, selectedShapesLengthAtMouseDown: Y(u).length } : void 0;
186
- })(s || { mode: "default" }, a, i);
187
- if (h?.mode === "resize" || h?.mode === "rotate") return { shape: a, mode: h };
185
+ return c.mode === "resize" ? { mode: "resize", cursorStartPosition: p, originalShape: f, anchor: c.anchor, selectedShapesLengthAtMouseDown: U(f).length } : void 0;
186
+ })(s || { mode: "default" }, o, i);
187
+ if (h?.mode === "resize" || h?.mode === "rotate") return { shape: o, mode: h };
188
188
  }
189
- const l = t.find((h) => Y(a).find((c) => h.id === c?.id) ? s && ft(e, h, i, n, !0, o ? 20 : void 0) : !!da(e, h, i, n)) ?? (s ? a : void 0);
190
- if (a && a?.id === l?.id) return { shape: a, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: a, selectedShapesLengthAtMouseDown: Y(a).length } };
191
- if (l) {
192
- if (r === "add") {
193
- const c = pe(sa(a, [l]), n);
194
- return { shape: c, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: c, selectedShapesLengthAtMouseDown: Y(a).length } };
189
+ const d = t.find((h) => U(o).find((c) => h.id === c?.id) ? s && Et(e, h, i, n, !0, a ? 20 : void 0) : !!Po(e, h, i, n)) ?? (s ? o : void 0);
190
+ if (o && o?.id === d?.id) return { shape: o, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: o, selectedShapesLengthAtMouseDown: U(o).length } };
191
+ if (d) {
192
+ if (l === "add") {
193
+ const c = de(xo(o, [d]), n);
194
+ return { shape: c, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: c, selectedShapesLengthAtMouseDown: U(o).length } };
195
195
  }
196
- if (r === "remove") {
197
- const c = pe(Ga(a, l), n);
198
- return { shape: c, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: c, selectedShapesLengthAtMouseDown: Y(a).length } };
196
+ if (l === "remove") {
197
+ const c = de(pa(o, d), n);
198
+ return { shape: c, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: c, selectedShapesLengthAtMouseDown: U(o).length } };
199
199
  }
200
- const h = Y(a).find((c) => c.id === l?.id) ? a : pe([l], n);
201
- return { shape: h, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: h, selectedShapesLengthAtMouseDown: Y(a).length } };
200
+ const h = U(o).find((c) => c.id === d?.id) ? o : de([d], n);
201
+ return { shape: h, mode: { mode: "translate", cursorStartPosition: i, hasBeenDuplicated: !1, dateStart: Date.now(), originalShape: h, selectedShapesLengthAtMouseDown: U(o).length } };
202
202
  }
203
- return { shape: r !== "replace" ? a : void 0, mode: { mode: d ? "selectionFrame" : "default" } };
204
- }, pe = (e, t) => {
203
+ return { shape: l !== "replace" ? o : void 0, mode: { mode: r ? "selectionFrame" : "default" } };
204
+ }, de = (e, t) => {
205
205
  if (!e.length) return;
206
206
  if (e.length === 1) return e[0];
207
- const i = e.some((d) => d.rotation !== e[0].rotation) ? 0 : e[0]?.rotation ?? 0, n = ((d, r, s) => {
208
- const l = d.map((g) => [[g.computed.borders.x + s.selectionPadding, g.computed.borders.y + s.selectionPadding], [g.computed.borders.x - s.selectionPadding + g.computed.borders.width, g.computed.borders.y + s.selectionPadding], [g.computed.borders.x - s.selectionPadding + g.computed.borders.width, g.computed.borders.y - s.selectionPadding + g.computed.borders.height], [g.computed.borders.x + s.selectionPadding, g.computed.borders.y - s.selectionPadding + g.computed.borders.height]].map((w) => {
209
- const L = le({ point: [w[0], w[1]], origin: g.computed.center, rotation: -(g.rotation ?? 0) });
210
- return le({ point: [L[0], L[1]], origin: [0, 0], rotation: r });
211
- })), h = Math.min(...l.flatMap((g) => [g[0][0], g[1][0], g[2][0], g[3][0]])), c = Math.min(...l.flatMap((g) => [g[0][1], g[1][1], g[2][1], g[3][1]])), u = Math.max(...l.flatMap((g) => [g[0][0], g[1][0], g[2][0], g[3][0]])), f = Math.max(...l.flatMap((g) => [g[0][1], g[1][1], g[2][1], g[3][1]])), v = [(h + u) / 2, (c + f) / 2], p = le({ point: v, origin: [0, 0], rotation: -r }), S = [v[0] - p[0], v[1] - p[1]], C = Ve(h - S[0]), b = Ve(u - S[0]), Q = Ve(c - S[1]);
212
- return { width: b - C, height: Ve(f - S[1]) - Q, x: C, y: Q };
213
- })(e, i, t), a = oa({ id: "group_selection", type: "rect", settings: In }, [n.x, n.y], t, n.width, n.height), o = e.slice(1).reduce((d, r) => {
214
- const s = r.style ?? {}, l = {};
215
- for (const h in s) d[h] !== void 0 && s[h] !== void 0 && d[h] === s[h] && (l[h] = d[h]);
216
- return l;
207
+ const i = e.some((r) => r.rotation !== e[0].rotation) ? 0 : e[0]?.rotation ?? 0, n = ((r, l, s) => {
208
+ const d = r.map((y) => [[y.computed.borders.x + s.selectionPadding, y.computed.borders.y + s.selectionPadding], [y.computed.borders.x - s.selectionPadding + y.computed.borders.width, y.computed.borders.y + s.selectionPadding], [y.computed.borders.x - s.selectionPadding + y.computed.borders.width, y.computed.borders.y - s.selectionPadding + y.computed.borders.height], [y.computed.borders.x + s.selectionPadding, y.computed.borders.y - s.selectionPadding + y.computed.borders.height]].map((g) => {
209
+ const P = me({ point: [g[0], g[1]], origin: y.computed.center, rotation: -(y.rotation ?? 0) });
210
+ return me({ point: [P[0], P[1]], origin: [0, 0], rotation: l });
211
+ })), h = Math.min(...d.flatMap((y) => [y[0][0], y[1][0], y[2][0], y[3][0]])), c = Math.min(...d.flatMap((y) => [y[0][1], y[1][1], y[2][1], y[3][1]])), f = Math.max(...d.flatMap((y) => [y[0][0], y[1][0], y[2][0], y[3][0]])), p = Math.max(...d.flatMap((y) => [y[0][1], y[1][1], y[2][1], y[3][1]])), m = [(h + f) / 2, (c + p) / 2], u = me({ point: m, origin: [0, 0], rotation: -l }), S = [m[0] - u[0], m[1] - u[1]], w = We(h - S[0]), x = We(f - S[0]), b = We(c - S[1]);
212
+ return { width: x - w, height: We(p - S[1]) - b, x: w, y: b };
213
+ })(e, i, t), o = wo({ id: "group_selection", type: "rect", settings: Jn }, [n.x, n.y], t, n.width, n.height), a = e.slice(1).reduce((r, l) => {
214
+ const s = l.style ?? {}, d = {};
215
+ for (const h in s) r[h] !== void 0 && s[h] !== void 0 && r[h] === s[h] && (d[h] = r[h]);
216
+ return d;
217
217
  }, e[0].style ?? {});
218
- return { id: e.map((d) => d.id).join("-"), type: "group", shapes: e, rotation: i, visible: !0, locked: !1, selection: a.selection, x: a.x, y: a.y, width: a.width, height: a.height, style: o, computed: a.computed, path: a.path };
219
- }, qi = (e, t) => (i) => {
220
- if (!i) return;
221
- const n = i.type === "group" ? i.shapes.map((a) => e(a, t)) : [e(i, t)];
222
- return pe(n, t);
223
- }, Y = (e) => e ? e.type === "group" ? e.shapes : [e] : [], sa = (e, t) => {
224
- const i = Y(e);
218
+ return { id: e.map((r) => r.id).join("-"), type: "group", shapes: e, rotation: i, visible: !0, locked: !1, selection: o.selection, x: o.x, y: o.y, width: o.width, height: o.height, style: a, computed: o.computed, path: o.path };
219
+ }, U = (e) => e ? e.type === "group" ? e.shapes : [e] : [], xo = (e, t) => {
220
+ const i = U(e);
225
221
  return [.../* @__PURE__ */ new Set([...i, ...t])];
226
- }, Ga = (e, t) => Y(e).filter((i) => i.id !== t.id), ra = (e) => {
222
+ }, pa = (e, t) => U(e).filter((i) => i.id !== t.id), Mo = (e) => {
227
223
  const { clientX: t = 0, clientY: i = 0 } = "touches" in e && e.touches[0] ? e.touches[0] : "changedTouches" in e && e.changedTouches[0] ? e.changedTouches[0] : "clientX" in e ? e : {};
228
224
  return { clientX: t, clientY: i };
229
- }, la = (e, t, i) => {
230
- const { clientX: n, clientY: a } = ra(e), o = t.getBoundingClientRect();
231
- return [(n - o.left) / i.scaleRatio, (a - o.top) / i.scaleRatio];
232
- }, st = (e, t, i) => {
233
- const { clientX: n, clientY: a } = ra(e), o = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
234
- return [(n - o.left) * (i.canvasSize.width / o.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (a - o.top) * (i.canvasSize.height / o.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
235
- }, rt = (e) => "touches" in e, Re = (e, t, [i, n]) => le({ origin: [i, n], point: e, rotation: t }), ri = (e, t, [i, n]) => le({ origin: [i, n], point: e, rotation: -t }), Ct = (e, t, i) => i ? ia(e, { x: t[0], y: t[1], radius: i }) : ((n, a) => a[0] >= n.x && a[0] <= n.x + n.width && a[1] >= n.y && a[1] <= n.y + n.height)(e, t), ft = (e, t, i, n, a = !1, o = 0) => {
236
- const d = Y(t).length > 1 ? t : Y(t)[0];
237
- if (!d || d.locked) return !1;
238
- const { borders: r, center: s } = d.computed, l = Re(i, d.rotation ?? 0, s);
239
- if (a) {
240
- const h = ((c, u, f, v = 0) => {
241
- const { canvasSize: { scaleRatio: p } } = f, { borders: S } = c.computed;
225
+ }, Co = (e, t, i) => {
226
+ const { clientX: n, clientY: o } = Mo(e), a = t.getBoundingClientRect();
227
+ return [(n - a.left) / i.scaleRatio, (o - a.top) / i.scaleRatio];
228
+ }, ft = (e, t, i) => {
229
+ const { clientX: n, clientY: o } = Mo(e), a = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
230
+ return [(n - a.left) * (i.canvasSize.width / a.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (o - a.top) * (i.canvasSize.height / a.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
231
+ }, ot = (e) => "touches" in e, tt = (e, t, [i, n]) => me({ origin: [i, n], point: e, rotation: t }), wi = (e, t, [i, n]) => me({ origin: [i, n], point: e, rotation: -t }), Ft = (e, t, i) => i ? yo(e, { x: t[0], y: t[1], radius: i }) : ((n, o) => o[0] >= n.x && o[0] <= n.x + n.width && o[1] >= n.y && o[1] <= n.y + n.height)(e, t), Et = (e, t, i, n, o = !1, a = 0) => {
232
+ const r = U(t).length > 1 ? t : U(t)[0];
233
+ if (!r || r.locked) return !1;
234
+ const { borders: l, center: s } = r.computed, d = tt(i, r.rotation ?? 0, s);
235
+ if (o) {
236
+ const h = ((c, f, p, m = 0) => {
237
+ const { canvasSize: { scaleRatio: u } } = p, { borders: S } = c.computed;
242
238
  if (c.type === "line" || c.type === "polygon" || c.type === "curve") {
243
- for (let C = 0; C < c.points.length; C++) if (Ct({ x: c.points[C][0] - 7 / p, y: c.points[C][1] - 7 / p, width: Je / p, height: Je / p }, u, v)) return { mode: "resize", anchor: C };
239
+ for (let w = 0; w < c.points.length; w++) if (Ft({ x: c.points[w][0] - 7 / u, y: c.points[w][1] - 7 / u, width: gt / u, height: gt / u }, f, m)) return { mode: "resize", anchor: w };
244
240
  } else {
245
- if (Ct({ x: S.x + S.width / 2 - 7 / p, y: S.y - Je / p - 16 / p, width: Je / p, height: Je / p }, u, v)) return { mode: "rotate" };
246
- for (const C of Gn) if (Ct({ x: S.x + S.width * C[0] - 7 / p, y: S.y + S.height * C[1] - 7 / p, width: Je / p, height: Je / p }, u, v)) return { mode: "resize", anchor: C };
241
+ if (Ft({ x: S.x + S.width / 2 - 7 / u, y: S.y - gt / u - 16 / u, width: gt / u, height: gt / u }, f, m)) return { mode: "rotate" };
242
+ for (const w of po) if (Ft({ x: S.x + S.width * w[0] - 7 / u, y: S.y + S.height * w[1] - 7 / u, width: gt / u, height: gt / u }, f, m)) return { mode: "resize", anchor: w };
247
243
  }
248
244
  return !1;
249
- })(d, l, n, o);
245
+ })(r, d, n, a);
250
246
  if (h) return h;
251
247
  }
252
- return d.selection?.type === "line" ? (e.lineWidth = (d.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(bi(d, !0) ? e.isPointInPath(d.path, l[0], l[1]) : e.isPointInStroke(d.path, l[0], l[1])) && { mode: "translate" }) : !!Ct(r, l, 15 + o) && { mode: "translate" };
253
- }, Gi = (e, t, i, n, a = 50) => {
248
+ return r.selection?.type === "line" ? (e.lineWidth = (r.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(Ii(r, !0) ? e.isPointInPath(r.path, d[0], d[1]) : e.isPointInStroke(r.path, d[0], d[1])) && { mode: "translate" }) : !!Ft(l, d, 15 + a) && { mode: "translate" };
249
+ }, hn = (e, t, i, n, o = 50) => {
254
250
  if (t.locked || t.points.length < 2) return !1;
255
- const { center: o } = t.computed, d = Re(i, t.rotation ?? 0, o);
256
- e.lineWidth = (t.style?.lineWidth ?? 0) + a / n.canvasZoom;
257
- const r = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
258
- for (let s = 0; s < r.length - 1; s++) {
259
- const l = Zt({ points: [r[s], r[s + 1]] });
260
- if (e.isPointInStroke(l, d[0], d[1])) return { lineIndex: s };
251
+ const { center: a } = t.computed, r = tt(i, t.rotation ?? 0, a);
252
+ e.lineWidth = (t.style?.lineWidth ?? 0) + o / n.canvasZoom;
253
+ const l = t.style?.closedPoints ? [...t.points, t.points[0]] : t.points;
254
+ for (let s = 0; s < l.length - 1; s++) {
255
+ const d = _t({ points: [l[s], l[s + 1]] });
256
+ if (e.isPointInStroke(d, r[0], r[1])) return { lineIndex: s };
261
257
  }
262
258
  return !1;
263
- }, bi = (e, t = !1) => !(!t || !["curve", "polygon"].includes(e.type)) || e.style?.fillColor && e.style?.fillColor !== "transparent" || ["picture", "text"].includes(e.type), da = (e, t, i, n) => {
259
+ }, Ii = (e, t = !1) => !(!t || !["curve", "polygon"].includes(e.type)) || e.style?.fillColor && e.style?.fillColor !== "transparent" || ["picture", "text"].includes(e.type), Po = (e, t, i, n) => {
264
260
  if (t.locked) return !1;
265
- const { center: a } = t.computed, o = Re(i, t.rotation ?? 0, a);
266
- return e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(bi(t) ? e.isPointInPath(t.path, o[0], o[1]) : e.isPointInStroke(t.path, o[0], o[1])) && { mode: "translate" };
261
+ const { center: o } = t.computed, a = tt(i, t.rotation ?? 0, o);
262
+ return e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!(Ii(t) ? e.isPointInPath(t.path, a[0], a[1]) : e.isPointInStroke(t.path, a[0], a[1])) && { mode: "translate" };
267
263
  };
268
- function li(e, t) {
269
- const i = Math.max(e.x, t.x), n = Math.max(e.y, t.y), a = Math.min(e.x + (e.width || 1), t.x + (t.width || 1)), o = Math.min(e.y + (e.height || 1), t.y + (t.height || 1));
270
- if (i < a && n < o) return { x: i, y: n, width: a - i, height: o - n };
264
+ function xi(e, t) {
265
+ const i = Math.max(e.x, t.x), n = Math.max(e.y, t.y), o = Math.min(e.x + (e.width || 1), t.x + (t.width || 1)), a = Math.min(e.y + (e.height || 1), t.y + (t.height || 1));
266
+ if (i < o && n < a) return { x: i, y: n, width: o - i, height: a - n };
271
267
  }
272
- const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, checkFill: d }) => {
273
- for (let r = 0; r < n; r += n / 2) for (let s = 0; s < n; s += n / 2) for (let l = r + i.x; l < i.x + i.width; l += n) for (let h = s + i.y; h < i.y + i.height; h += n) {
274
- const c = Re([l, h], o, a);
275
- if (d ? e.isPointInPath(t, c[0], c[1]) : e.isPointInStroke(t, c[0], c[1])) return !0;
268
+ const pn = ({ ctx: e, path: t, rect: i, offset: n, center: o, rotation: a = 0, checkFill: r }) => {
269
+ for (let l = 0; l < n; l += n / 2) for (let s = 0; s < n; s += n / 2) for (let d = l + i.x; d < i.x + i.width; d += n) for (let h = s + i.y; h < i.y + i.height; h += n) {
270
+ const c = tt([d, h], a, o);
271
+ if (r ? e.isPointInPath(t, c[0], c[1]) : e.isPointInStroke(t, c[0], c[1])) return !0;
276
272
  }
277
273
  return !1;
278
- }, wi = (e, t, i, n) => ({ type: "line", border: yt(i.borders), shapePath: e, anchors: [...t.points.map((a) => Vt({ x: a[0], y: a[1], radius: 7 / n.canvasSize.scaleRatio }))] }), Pe = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], di = ({ size: e, zoom: t, newOffset: [i, n], canvasSize: a }) => e === "infinite" ? { zoom: t, offset: [i, n] } : t < 1 ? { zoom: t, offset: [-(a.realWidth - a.realWidth / t) / 2, -(a.realHeight - a.realHeight / t) / 2] } : { zoom: t, offset: [We(i, a.realWidth / t - a.realWidth, 0), We(n, a.realHeight / t - a.realHeight, 0)] }, ci = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: n, zoom: a, centerPoint: o }) => {
279
- const d = e === "fixed" && a < 1 ? [t.realWidth / 2, t.realHeight / 2] : o, r = i[0] - (d[0] / n - d[0] / a), s = i[1] - (d[1] / n - d[1] / a);
280
- return { offset: e === "infinite" ? [r, s] : a < 1 ? [-(t.realWidth - t.realWidth / a) / 2, -(t.realHeight - t.realHeight / a) / 2] : [We(r, t.realWidth / a - t.realWidth, 0), We(s, t.realHeight / a - t.realHeight, 0)], zoom: a };
281
- }, ca = (e) => {
282
- const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: n }, canvasZoom: a, canvasOffset: o } = e;
283
- return { x: o[0] * a * n, y: o[1] * a * n, width: t * a, height: i * a };
284
- }, ha = (e, t) => {
274
+ }, Ri = (e, t, i, n) => ({ type: "line", border: Rt(i.borders), shapePath: e, anchors: [...t.points.map((o) => Gt({ x: o[0], y: o[1], radius: 7 / n.canvasSize.scaleRatio }))] }), Ie = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], Mi = ({ size: e, zoom: t, newOffset: [i, n], canvasSize: o }) => e === "infinite" ? { zoom: t, offset: [i, n] } : t < 1 ? { zoom: t, offset: [-(o.realWidth - o.realWidth / t) / 2, -(o.realHeight - o.realHeight / t) / 2] } : { zoom: t, offset: [et(i, o.realWidth / t - o.realWidth, 0), et(n, o.realHeight / t - o.realHeight, 0)] }, Ci = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: n, zoom: o, centerPoint: a }) => {
275
+ const r = e === "fixed" && o < 1 ? [t.realWidth / 2, t.realHeight / 2] : a, l = i[0] - (r[0] / n - r[0] / o), s = i[1] - (r[1] / n - r[1] / o);
276
+ return { offset: e === "infinite" ? [l, s] : o < 1 ? [-(t.realWidth - t.realWidth / o) / 2, -(t.realHeight - t.realHeight / o) / 2] : [et(l, t.realWidth / o - t.realWidth, 0), et(s, t.realHeight / o - t.realHeight, 0)], zoom: o };
277
+ }, ko = (e) => {
278
+ const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: n }, canvasZoom: o, canvasOffset: a } = e;
279
+ return { x: a[0] * o * n, y: a[1] * o * n, width: t * o, height: i * o };
280
+ }, Lo = (e, t) => {
285
281
  const { canvasZoom: i, size: n } = t;
286
282
  if (n !== "fixed" || i >= 1) return;
287
- const a = ca(t);
288
- e.beginPath(), e.rect(a.x, a.y, a.width, a.height), e.closePath(), e.clip();
289
- }, vt = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, _a = (e, t) => ({ x: e.x - e.radius - t.selectionPadding, width: 2 * (e.radius + t.selectionPadding), y: e.y - e.radius - t.selectionPadding, height: 2 * (e.radius + t.selectionPadding) }), Tt = (e, t) => {
290
- const i = Vt(e), n = ((a, o) => Be(a, _a, o))(e, t);
291
- return { ...e, path: i, selection: pt(i, n, t), computed: n };
292
- }, ja = Tt, St = (e, t) => {
293
- const i = aa(e), n = ((a, o) => Be(a, At, o))(e, t);
294
- return { ...e, path: i, selection: wi(i, e, n, t), computed: n };
295
- }, ua = St, At = (e, t) => {
296
- const i = Math.min(...e.points.map((o) => o[0])) - t.selectionPadding, n = Math.max(...e.points.map((o) => o[0])) + t.selectionPadding, a = Math.min(...e.points.map((o) => o[1])) - t.selectionPadding;
297
- return { x: i, width: n - i, y: a, height: Math.max(...e.points.map((o) => o[1])) + t.selectionPadding - a };
298
- }, Ka = (e, t, i, n) => {
283
+ const o = ko(t);
284
+ e.beginPath(), e.rect(o.x, o.y, o.width, o.height), e.closePath(), e.clip();
285
+ }, Dt = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, ua = (e, t) => ({ x: e.x - e.radius - t.selectionPadding, width: 2 * (e.radius + t.selectionPadding), y: e.y - e.radius - t.selectionPadding, height: 2 * (e.radius + t.selectionPadding) }), Jt = (e, t) => {
286
+ const i = Gt(e), n = ((o, a) => it(o, ua, a))(e, t);
287
+ return { ...e, path: i, selection: zt(i, n, t), computed: n };
288
+ }, ga = Jt, At = (e, t) => {
289
+ const i = Qo(e), n = ((o, a) => it(o, ei, a))(e, t);
290
+ return { ...e, path: i, selection: Ri(i, e, n, t), computed: n };
291
+ }, Vo = At, ei = (e, t) => {
292
+ const i = Math.min(...e.points.map((a) => a[0])) - t.selectionPadding, n = Math.max(...e.points.map((a) => a[0])) + t.selectionPadding, o = Math.min(...e.points.map((a) => a[1])) - t.selectionPadding;
293
+ return { x: i, width: n - i, y: o, height: Math.max(...e.points.map((a) => a[1])) + t.selectionPadding - o };
294
+ }, fa = (e, t, i, n) => {
299
295
  if (t < 0 || t > e.points.length - 1) return e;
300
- const a = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
301
- return St({ ...e, points: a }, n);
302
- }, ji = (e, t, i, n = !1) => {
303
- const a = [we(t[0], i), we(t[1], i)], o = Re(a, e.rotation ?? 0, e.computed.center), d = { ...e, points: n ? e.points : [...e.points, o], tempPoint: n ? o : void 0 };
304
- return St(d, i);
305
- }, Ja = (e, t, i) => {
296
+ const o = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
297
+ return At({ ...e, points: o }, n);
298
+ }, un = (e, t, i, n = !1) => {
299
+ const o = [Ze(t[0], i), Ze(t[1], i)], a = tt(o, e.rotation ?? 0, e.computed.center), r = { ...e, points: n ? e.points : [...e.points, a], tempPoint: n ? a : void 0 };
300
+ return At(r, i);
301
+ }, va = (e, t, i) => {
306
302
  const n = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
307
303
  if (n.length < 2) {
308
- const l = n[0] ?? [0, 0], h = i.selectionPadding;
309
- return { x: l[0] - h, y: l[1] - h, width: 2 * h, height: 2 * h };
304
+ const d = n[0] ?? [0, 0], h = i.selectionPadding;
305
+ return { x: d[0] - h, y: d[1] - h, width: 2 * h, height: 2 * h };
310
306
  }
311
- if (n.length < 3) return At({ ...e, points: n }, i);
312
- const a = yi(e, n);
313
- let o = Number.POSITIVE_INFINITY, d = Number.NEGATIVE_INFINITY, r = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
314
- for (let l = 1; l < a.length - 2; l++) {
315
- const h = a[l - 1], c = a[l], u = a[l + 1], f = a[l + 2], { cp1: v, cp2: p } = Si(h, c, u, f), S = Oa(c, v, p, u);
316
- o = Math.min(o, S.minX), d = Math.max(d, S.maxX), r = Math.min(r, S.minY), s = Math.max(s, S.maxY);
307
+ if (n.length < 3) return ei({ ...e, points: n }, i);
308
+ const o = Ti(e, n);
309
+ let a = Number.POSITIVE_INFINITY, r = Number.NEGATIVE_INFINITY, l = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
310
+ for (let d = 1; d < o.length - 2; d++) {
311
+ const h = o[d - 1], c = o[d], f = o[d + 1], p = o[d + 2], { cp1: m, cp2: u } = Di(h, c, f, p), S = aa(c, m, u, f);
312
+ a = Math.min(a, S.minX), r = Math.max(r, S.maxX), l = Math.min(l, S.minY), s = Math.max(s, S.maxY);
317
313
  }
318
- return Qi({ x: o, y: r, width: d - o, height: s - r }, i);
319
- }, Qt = (e, t) => {
320
- const i = ((a) => {
321
- const o = new Path2D(), d = a.tempPoint ? [...a.points, a.tempPoint] : a.points;
322
- if (d.length < 2) return o;
323
- if (d.length < 3) return aa(a);
324
- const r = a.style?.closedPoints === 1 && d.length > 2;
325
- o.moveTo(...d[0]);
326
- const s = yi(a, d);
327
- for (let l = 1; l < s.length - 2; l++) {
328
- const h = s[l - 1], c = s[l], u = s[l + 1], f = s[l + 2], { cp1: v, cp2: p } = Si(h, c, u, f);
329
- o.bezierCurveTo(v[0], v[1], p[0], p[1], u[0], u[1]);
314
+ return Ei({ x: a, y: l, width: r - a, height: s - l }, i);
315
+ }, Ht = (e, t) => {
316
+ const i = ((o) => {
317
+ const a = new Path2D(), r = o.tempPoint ? [...o.points, o.tempPoint] : o.points;
318
+ if (r.length < 2) return a;
319
+ if (r.length < 3) return Qo(o);
320
+ const l = o.style?.closedPoints === 1 && r.length > 2;
321
+ a.moveTo(...r[0]);
322
+ const s = Ti(o, r);
323
+ for (let d = 1; d < s.length - 2; d++) {
324
+ const h = s[d - 1], c = s[d], f = s[d + 1], p = s[d + 2], { cp1: m, cp2: u } = Di(h, c, f, p);
325
+ a.bezierCurveTo(m[0], m[1], u[0], u[1], f[0], f[1]);
330
326
  }
331
- return r && o.closePath(), o;
332
- })(e), n = ((a, o) => Be(a, At, o, Ja))(e, t);
333
- return { ...e, path: i, selection: wi(i, e, n, t), computed: n };
334
- }, pa = Qt, eo = (e, t, i, n) => {
327
+ return l && a.closePath(), a;
328
+ })(e), n = ((o, a) => it(o, ei, a, va))(e, t);
329
+ return { ...e, path: i, selection: Ri(i, e, n, t), computed: n };
330
+ }, Zo = Ht, ma = (e, t, i, n) => {
335
331
  if (t < 0 || t > e.points.length - 1) return e;
336
- const a = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
337
- return Qt({ ...e, points: a }, n);
338
- }, Ki = (e, t, i, n = !1) => {
339
- const a = [we(t[0], i), we(t[1], i)], o = e.computed.center, d = Re(a, e.rotation ?? 0, o), r = { ...e, points: n ? e.points : [...e.points, d], tempPoint: n ? d : void 0 };
340
- return Qt(r, i);
341
- }, to = (e, t) => ({ x: e.x - e.radiusX - t.selectionPadding, width: 2 * (e.radiusX + t.selectionPadding), y: e.y - e.radiusY - t.selectionPadding, height: 2 * (e.radiusY + t.selectionPadding) }), Dt = (e, t) => {
342
- const i = ((a) => {
343
- const o = new Path2D();
344
- return o.ellipse(a.x, a.y, a.radiusX, a.radiusY, 0, 0, 2 * Math.PI), o;
345
- })(e), n = ((a, o) => Be(a, to, o))(e, t);
346
- return { ...e, path: i, selection: pt(i, n, t), computed: n };
347
- }, io = Dt, no = (e, t) => Be(e, At, t), Ji = (e, t) => ((i, n) => ({ ...i, path: Fa(i), computed: no(i, n) }))({ ...e, id: ue("triangle_"), type: "triangle" }, t), ao = (e, t) => {
332
+ const o = [...e.points.slice(0, t + 1), i, ...e.points.slice(t + 1)];
333
+ return Ht({ ...e, points: o }, n);
334
+ }, gn = (e, t, i, n = !1) => {
335
+ const o = [Ze(t[0], i), Ze(t[1], i)], a = e.computed.center, r = tt(o, e.rotation ?? 0, a), l = { ...e, points: n ? e.points : [...e.points, r], tempPoint: n ? r : void 0 };
336
+ return Ht(l, i);
337
+ }, Sa = (e, t) => ({ x: e.x - e.radiusX - t.selectionPadding, width: 2 * (e.radiusX + t.selectionPadding), y: e.y - e.radiusY - t.selectionPadding, height: 2 * (e.radiusY + t.selectionPadding) }), ti = (e, t) => {
338
+ const i = ((o) => {
339
+ const a = new Path2D();
340
+ return a.ellipse(o.x, o.y, o.radiusX, o.radiusY, 0, 0, 2 * Math.PI), a;
341
+ })(e), n = ((o, a) => it(o, Sa, a))(e, t);
342
+ return { ...e, path: i, selection: zt(i, n, t), computed: n };
343
+ }, ya = ti, ba = (e, t) => it(e, ei, t), fn = (e, t) => ((i, n) => ({ ...i, path: sa(i), computed: ba(i, n) }))({ ...e, id: Ce("triangle_"), type: "triangle" }, t), Qa = (e, t) => {
348
344
  e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
349
- }, oo = (e, t) => ({ x: Math.min(e.points[0][0], e.points[1][0]) - t.selectionPadding, width: Math.abs(e.points[0][0] - e.points[1][0]) + 2 * t.selectionPadding, y: Math.min(e.points[0][1], e.points[1][1]) - t.selectionPadding, height: Math.abs(e.points[0][1] - e.points[1][1]) + 2 * t.selectionPadding }), Et = (e, t) => {
345
+ }, wa = (e, t) => ({ x: Math.min(e.points[0][0], e.points[1][0]) - t.selectionPadding, width: Math.abs(e.points[0][0] - e.points[1][0]) + 2 * t.selectionPadding, y: Math.min(e.points[0][1], e.points[1][1]) - t.selectionPadding, height: Math.abs(e.points[0][1] - e.points[1][1]) + 2 * t.selectionPadding }), ii = (e, t) => {
350
346
  const i = [];
351
347
  let n;
352
348
  if (e.style?.lineArrow === 1 || e.style?.lineArrow === 2 || e.style?.lineArrow === 3) {
353
- const o = Math.PI / 2 - Yi({ targetVector: [e.points[0], e.points[1]] });
354
- e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(Ji(en(e.points[0], o, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(Ji(en(e.points[1], o + Math.PI, e.style), t));
355
- const d = (({ line: r, size: s, direction: l }) => {
356
- const h = Math.PI / 2 - Yi({ targetVector: [r.points[0], r.points[1]] }), c = [r.points[0][0] + (r.points[1][0] - r.points[0][0]) / 2, r.points[0][1] + (r.points[1][1] - r.points[0][1]) / 2];
357
- let u, f;
358
- if (["start", "both"].includes(l)) {
359
- const v = le({ point: r.points[0], origin: c, rotation: -h });
360
- u = le({ point: [v[0], v[1] + s], origin: c, rotation: h });
361
- } else u = [...r.points[0]];
362
- if (["end", "both"].includes(l)) {
363
- const v = le({ point: r.points[1], origin: c, rotation: -h });
364
- f = le({ point: [v[0], v[1] - s], origin: c, rotation: h });
365
- } else f = [...r.points[1]];
366
- return { points: [u, f] };
349
+ const a = Math.PI / 2 - ln({ targetVector: [e.points[0], e.points[1]] });
350
+ e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(fn(vn(e.points[0], a, e.style), t)), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(fn(vn(e.points[1], a + Math.PI, e.style), t));
351
+ const r = (({ line: l, size: s, direction: d }) => {
352
+ const h = Math.PI / 2 - ln({ targetVector: [l.points[0], l.points[1]] }), c = [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 f, p;
354
+ if (["start", "both"].includes(d)) {
355
+ const m = me({ point: l.points[0], origin: c, rotation: -h });
356
+ f = me({ point: [m[0], m[1] + s], origin: c, rotation: h });
357
+ } else f = [...l.points[0]];
358
+ if (["end", "both"].includes(d)) {
359
+ const m = me({ point: l.points[1], origin: c, rotation: -h });
360
+ p = me({ point: [m[0], m[1] - s], origin: c, rotation: h });
361
+ } else p = [...l.points[1]];
362
+ return { points: [f, p] };
367
363
  })({ line: e, size: 10 + 2 * (e.style?.lineWidth ?? 0), direction: e.style?.lineArrow === 1 ? "start" : e.style?.lineArrow === 2 ? "end" : "both" });
368
- n = Zt(d);
369
- } else n = Zt(e);
370
- const a = ((o, d) => Be(o, oo, d))(e, t);
371
- return { ...e, path: n, selection: wi(n, e, a, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: a };
372
- }, so = Et, en = (e, t, i) => {
373
- const n = [le({ point: [0, 0], rotation: t }), le({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), le({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
364
+ n = _t(r);
365
+ } else n = _t(e);
366
+ const o = ((a, r) => it(a, wa, r))(e, t);
367
+ return { ...e, path: n, selection: Ri(n, e, o, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" }, computed: o };
368
+ }, xa = ii, vn = (e, t, i) => {
369
+ const n = [me({ point: [0, 0], rotation: t }), me({ point: [-(5 + (i.lineWidth ?? 0)), 10 + 2 * (i.lineWidth ?? 0)], rotation: t }), me({ point: [5 + (i.lineWidth ?? 0), 10 + 2 * (i.lineWidth ?? 0)], rotation: t })];
374
370
  return { points: [[e[0] + n[0][0], e[1] + n[0][1]], [e[0] + n[1][0], e[1] + n[1][1]], [e[0] + n[2][0], e[1] + n[2][1]]], style: { ...i, fillColor: i.strokeColor, strokeColor: "transparent" } };
375
- }, ro = (e, t, i) => {
376
- const { isXinverted: n, isYinverted: a, settings: o, widthMultiplier: d, heightMultiplier: r } = i, s = e.computed.borders.width - 2 * o.selectionPadding, l = e.computed.borders.height - 2 * o.selectionPadding, h = s * d, c = l * r, u = et(e, t, i), f = tt(i, u.x, u.y, h, c), v = e.computed.center[0] - s / 2, p = e.computed.center[1] - l / 2, S = f[0] - h / 2, C = f[1] - c / 2;
377
- return ((b, Q) => b.type === "line" ? Et(b, Q) : b.type === "polygon" ? ua(b, Q) : pa(b, Q))({ ...e, points: e.points.map(([b, Q]) => [S + (n ? h - (b - v) * d : (b - v) * d), C + (a ? c - (Q - p) * r : (Q - p) * r)]) }, i.settings);
378
- }, It = (e, t) => {
379
- const i = ((a, o) => Be(a, Qi, o))(e, t), n = yt(e);
380
- return { ...e, path: n, selection: pt(void 0, i, t), computed: i };
381
- }, lo = It, ei = (e, t, i, n, a) => {
382
- const [o, d] = ((r, s, l, h, c = !1) => {
383
- if (!(r && s && h && l)) return [Oi, Oi];
384
- const u = r / s;
385
- if (u > l / h) {
386
- const v = c ? l : Math.min(r, l);
387
- return [v, v / u];
371
+ }, Ma = (e, t, i) => {
372
+ const { isXinverted: n, isYinverted: o, settings: a, widthMultiplier: r, heightMultiplier: l } = i, s = e.computed.borders.width - 2 * a.selectionPadding, d = e.computed.borders.height - 2 * a.selectionPadding, h = s * r, c = d * l, f = vt(e, t, i), p = mt(i, f.x, f.y, h, c), m = e.computed.center[0] - s / 2, u = e.computed.center[1] - d / 2, S = p[0] - h / 2, w = p[1] - c / 2;
373
+ return ((x, b) => x.type === "line" ? ii(x, b) : x.type === "polygon" ? Vo(x, b) : Zo(x, b))({ ...e, points: e.points.map(([x, b]) => [S + (n ? h - (x - m) * r : (x - m) * r), w + (o ? c - (b - u) * l : (b - u) * l)]) }, i.settings);
374
+ }, ni = (e, t) => {
375
+ const i = ((o, a) => it(o, Ei, a))(e, t), n = Rt(e);
376
+ return { ...e, path: n, selection: zt(void 0, i, t), computed: i };
377
+ }, Ca = ni, gi = (e, t, i, n, o) => {
378
+ const [a, r] = ((l, s, d, h, c = !1) => {
379
+ if (!(l && s && h && d)) return [sn, sn];
380
+ const f = l / s;
381
+ if (f > d / h) {
382
+ const m = c ? d : Math.min(l, d);
383
+ return [m, m / f];
388
384
  }
389
- const f = c ? h : Math.min(s, h);
390
- return [f * u, f];
385
+ const p = c ? h : Math.min(s, h);
386
+ return [p * f, p];
391
387
  })(e.width, e.height, i, n, !0);
392
- return It({ toolId: fi.id, type: "picture", id: ue("picture_"), x: -a.canvasOffset[0] + a.canvasSize.realWidth / a.canvasZoom / 2 - o / 2, y: -a.canvasOffset[1] + a.canvasSize.realHeight / a.canvasZoom / 2 - d / 2, width: o, height: d, ratio: o / d, src: t, img: e }, a);
393
- }, co = (e, t, i, n) => new Promise((a, o) => {
394
- const d = new Image();
395
- d.onerror = () => {
396
- o(new Error("Some images could not be loaded"));
388
+ return ni({ toolId: Ai.id, type: "picture", id: Ce("picture_"), x: -o.canvasOffset[0] + o.canvasSize.realWidth / o.canvasZoom / 2 - a / 2, y: -o.canvasOffset[1] + o.canvasSize.realHeight / o.canvasZoom / 2 - r / 2, width: a, height: r, ratio: a / r, src: t, img: e }, o);
389
+ }, Pa = (e, t, i, n) => new Promise((o, a) => {
390
+ const r = new Image();
391
+ r.onerror = () => {
392
+ a(new Error("Some images could not be loaded"));
397
393
  }, setTimeout(() => {
398
- o(new Error("Timeout while loading images"));
399
- }, 4e3), e instanceof File ? ((r, s, l, h, c, u) => {
400
- Sa(l) ? l.text().then((f) => {
401
- const v = ya(f);
402
- r.onload = async () => {
403
- URL.revokeObjectURL(r.src);
404
- const p = ei(r, f, h, c, u);
405
- s(p);
406
- }, r.src = v;
407
- }) : (r.onload = async () => {
408
- URL.revokeObjectURL(r.src);
409
- const f = ei(r, r.src, h, c, u);
410
- s(f);
411
- }, r.src = URL.createObjectURL(l));
412
- })(d, a, e, t, i, n) : ((r, s, l, h, c, u) => {
413
- r.onload = () => {
414
- URL.revokeObjectURL(r.src);
415
- const f = ei(r, l, h, c, u);
416
- s(f);
417
- }, Qa(l).then((f) => {
418
- r.src = f;
394
+ a(new Error("Timeout while loading images"));
395
+ }, 4e3), e instanceof File ? ((l, s, d, h, c, f) => {
396
+ Io(d) ? d.text().then((p) => {
397
+ const m = Eo(p);
398
+ l.onload = async () => {
399
+ URL.revokeObjectURL(l.src);
400
+ const u = gi(l, p, h, c, f);
401
+ s(u);
402
+ }, l.src = m;
403
+ }) : (l.onload = async () => {
404
+ URL.revokeObjectURL(l.src);
405
+ const p = gi(l, l.src, h, c, f);
406
+ s(p);
407
+ }, l.src = URL.createObjectURL(d));
408
+ })(r, o, e, t, i, n) : ((l, s, d, h, c, f) => {
409
+ l.onload = () => {
410
+ URL.revokeObjectURL(l.src);
411
+ const p = gi(l, d, h, c, f);
412
+ s(p);
413
+ }, Ro(d).then((p) => {
414
+ l.src = p;
419
415
  }).catch(() => {
420
- r.src = "";
416
+ l.src = "";
421
417
  });
422
- })(d, a, e, t, i, n);
423
- }), ti = ["Texte"], ga = (e, t) => Be(e, uo, t), Wt = (e, t) => {
424
- const i = ga(e, t), n = yt(e);
425
- return { ...e, path: n, selection: pt(void 0, i, t), computed: i };
426
- }, ho = Wt, Rt = (e, t, i, n, a, o = mt) => {
427
- e.font = `${a ? "italic" : ""} ${n ? "bold" : ""} 1px ${o}`;
428
- const d = t.map((r) => i / e.measureText(r).width);
429
- return Math.min(...d) || 36;
430
- }, uo = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), po = (e, t, i, n) => {
431
- const a = { ...t, value: i }, o = ((v, p, S, C, b, Q = mt) => {
432
- v.font = `${b ? "italic" : ""} ${C ? "bold" : ""} ${S}px ${Q}`;
433
- const g = p.map((w) => v.measureText(w).width);
434
- return Math.max(...g) || 20;
435
- })(e, a.value, a.fontSize, a.style?.fontBold ?? !1, a.style?.fontItalic ?? !1, a.style?.fontFamily), d = a.fontSize * a.value.length, r = o / d, s = { ...a, width: o, height: d, ratio: r }, { center: l } = ga(s, n), [h, c] = $i([1, 1], t.computed.center, t), [u, f] = $i([1, 1], l, s, [!1, !1]);
436
- return { ...s, x: s.x - (u - h), y: s.y - (f - c) };
437
- }, tn = (e, t, i, n) => {
438
- const a = [we(i[0], n), we(i[1], n)];
418
+ })(r, o, e, t, i, n);
419
+ }), fi = ["Texte"], zo = (e, t) => it(e, La, t), oi = (e, t) => {
420
+ const i = zo(e, t), n = Rt(e);
421
+ return { ...e, path: n, selection: zt(void 0, i, t), computed: i };
422
+ }, ka = oi, ai = (e, t, i, n, o, a = It) => {
423
+ e.font = `${o ? "italic" : ""} ${n ? "bold" : ""} 1px ${a}`;
424
+ const r = t.map((l) => i / e.measureText(l).width);
425
+ return Math.min(...r) || 36;
426
+ }, La = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), Va = (e, t, i, n) => {
427
+ const o = { ...t, value: i }, a = ((m, u, S, w, x, b = It) => {
428
+ m.font = `${x ? "italic" : ""} ${w ? "bold" : ""} ${S}px ${b}`;
429
+ const y = u.map((g) => m.measureText(g).width);
430
+ return Math.max(...y) || 20;
431
+ })(e, o.value, o.fontSize, o.style?.fontBold ?? !1, o.style?.fontItalic ?? !1, o.style?.fontFamily), r = o.fontSize * o.value.length, l = a / r, s = { ...o, width: a, height: r, ratio: l }, { center: d } = zo(s, n), [h, c] = cn([1, 1], t.computed.center, t), [f, p] = cn([1, 1], d, s, [!1, !1]);
432
+ return { ...s, x: s.x - (f - h), y: s.y - (p - c) };
433
+ }, mn = (e, t, i, n) => {
434
+ const o = [Ze(i[0], n), Ze(i[1], n)];
439
435
  switch (t.type) {
440
436
  case "brush":
441
- return ((o, d, r) => ut({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [[d]], scaleX: 1, scaleY: 1, style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, r))(t, a, n);
437
+ return ((a, r, l) => Zt({ toolId: a.id, type: a.type, id: Ce(`${a.type}_`), points: [[r]], scaleX: 1, scaleY: 1, style: { opacity: a.settings.opacity.default, strokeColor: a.settings.strokeColor.default, lineWidth: a.settings.lineWidth.default, lineDash: a.settings.lineDash.default } }, l))(t, o, n);
442
438
  case "line":
443
- return ((o, d, r) => {
444
- const s = { toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [d, d], style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, lineArrow: o.settings.lineArrow.default } };
445
- return Et(s, r);
446
- })(t, a, n);
439
+ return ((a, r, l) => {
440
+ const s = { toolId: a.id, type: a.type, id: Ce(`${a.type}_`), points: [r, r], style: { opacity: a.settings.opacity.default, strokeColor: a.settings.strokeColor.default, lineWidth: a.settings.lineWidth.default, lineDash: a.settings.lineDash.default, lineArrow: a.settings.lineArrow.default } };
441
+ return ii(s, l);
442
+ })(t, o, n);
447
443
  case "polygon":
448
- return ((o, d, r) => St({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [d], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, r))(t, a, n);
444
+ return ((a, r, l) => At({ toolId: a.id, type: a.type, id: Ce(`${a.type}_`), points: [r], style: { opacity: a.settings.opacity.default, fillColor: a.settings.fillColor.default, strokeColor: a.settings.strokeColor.default, lineWidth: a.settings.lineWidth.default, lineDash: a.settings.lineDash.default, closedPoints: a.settings.closedPoints.default } }, l))(t, o, n);
449
445
  case "curve":
450
- return ((o, d, r) => Qt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), points: [d], style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default, closedPoints: o.settings.closedPoints.default } }, r))(t, a, n);
446
+ return ((a, r, l) => Ht({ toolId: a.id, type: a.type, id: Ce(`${a.type}_`), points: [r], style: { opacity: a.settings.opacity.default, fillColor: a.settings.fillColor.default, strokeColor: a.settings.strokeColor.default, lineWidth: a.settings.lineWidth.default, lineDash: a.settings.lineDash.default, closedPoints: a.settings.closedPoints.default } }, l))(t, o, n);
451
447
  case "rect":
452
448
  case "square":
453
- return oa(t, a, n);
449
+ return wo(t, o, n);
454
450
  case "text":
455
- return ((o, d, r, s) => {
456
- const l = Rt(o, ti, 150, d.settings?.fontBold.default ?? !1, d.settings?.fontItalic.default ?? !1, d.settings.fontFamily.default), h = l * (ti.length || 1);
457
- return Wt({ toolId: d.id, type: d.type, id: ue(`${d.type}_`), x: r[0] - 150, y: r[1] - h, value: ti, fontSize: l, width: 150, height: h, ratio: 150 / h, style: { opacity: d.settings.opacity.default, strokeColor: d.settings.strokeColor.default, fontFamily: d.settings.fontFamily.default, fontItalic: d.settings.fontItalic.default, fontBold: d.settings.fontBold.default } }, s);
458
- })(e, t, a, n);
451
+ return ((a, r, l, s) => {
452
+ const d = ai(a, fi, 150, r.settings?.fontBold.default ?? !1, r.settings?.fontItalic.default ?? !1, r.settings.fontFamily.default), h = d * (fi.length || 1);
453
+ return oi({ toolId: r.id, type: r.type, id: Ce(`${r.type}_`), x: l[0] - 150, y: l[1] - h, value: fi, fontSize: d, width: 150, height: h, ratio: 150 / h, style: { opacity: r.settings.opacity.default, strokeColor: r.settings.strokeColor.default, fontFamily: r.settings.fontFamily.default, fontItalic: r.settings.fontItalic.default, fontBold: r.settings.fontBold.default } }, s);
454
+ })(e, t, o, n);
459
455
  case "ellipse":
460
- return ((o, d, r) => Dt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), x: d[0], y: d[1], radiusX: 0, radiusY: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, r))(t, a, n);
456
+ return ((a, r, l) => ti({ toolId: a.id, type: a.type, id: Ce(`${a.type}_`), x: r[0], y: r[1], radiusX: 0, radiusY: 0, style: { opacity: a.settings.opacity.default, fillColor: a.settings.fillColor.default, strokeColor: a.settings.strokeColor.default, lineWidth: a.settings.lineWidth.default, lineDash: a.settings.lineDash.default } }, l))(t, o, n);
461
457
  case "circle":
462
- return ((o, d, r) => Tt({ toolId: o.id, type: o.type, id: ue(`${o.type}_`), x: d[0], y: d[1], radius: 0, style: { opacity: o.settings.opacity.default, fillColor: o.settings.fillColor.default, strokeColor: o.settings.strokeColor.default, lineWidth: o.settings.lineWidth.default, lineDash: o.settings.lineDash.default } }, r))(t, a, n);
458
+ return ((a, r, l) => Jt({ toolId: a.id, type: a.type, id: Ce(`${a.type}_`), x: r[0], y: r[1], radius: 0, style: { opacity: a.settings.opacity.default, fillColor: a.settings.fillColor.default, strokeColor: a.settings.strokeColor.default, lineWidth: a.settings.lineWidth.default, lineDash: a.settings.lineDash.default } }, l))(t, o, n);
463
459
  }
464
- }, nn = (e, t) => {
460
+ }, Sn = (e, t) => {
465
461
  switch (t.type) {
466
462
  case "brush":
467
463
  ((i, n) => {
@@ -471,8 +467,8 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
471
467
  case "text":
472
468
  ((i, n) => {
473
469
  if (i.globalAlpha !== 0 && n.style?.strokeColor && n.style.strokeColor !== "transparent") {
474
- i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.font = `${n.style?.fontItalic ? "italic" : ""} ${n.style?.fontBold ? "bold" : ""} ${n.fontSize}px ${n.style?.fontFamily ?? mt}`, i.textBaseline = "top", i.fillStyle = n.style.strokeColor;
475
- 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);
470
+ i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.font = `${n.style?.fontItalic ? "italic" : ""} ${n.style?.fontBold ? "bold" : ""} ${n.fontSize}px ${n.style?.fontFamily ?? It}`, i.textBaseline = "top", i.fillStyle = n.style.strokeColor;
471
+ for (let o = 0; o < n.value.length; o++) i.fillText(n.value[o], n.flipX ? -n.x - n.width : n.x, (n.flipY ? -n.y - n.height : n.y) + o * n.fontSize, n.width);
476
472
  }
477
473
  })(e, t);
478
474
  break;
@@ -480,7 +476,7 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
480
476
  ((i, n) => {
481
477
  if (i.globalAlpha !== 0) {
482
478
  n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path);
483
- for (const a of n.arrows ?? []) xe(i, a.style), ao(i, a);
479
+ for (const o of n.arrows ?? []) Te(i, o.style), Qa(i, o);
484
480
  }
485
481
  })(e, t);
486
482
  break;
@@ -506,143 +502,143 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
506
502
  break;
507
503
  case "rect":
508
504
  case "square":
509
- qa(e, t);
505
+ ha(e, t);
510
506
  break;
511
507
  case "picture":
512
508
  ((i, n) => {
513
509
  i.globalAlpha !== 0 && (i.beginPath(), i.scale(n.flipX ? -1 : 1, n.flipY ? -1 : 1), i.drawImage(n.img, n.flipX ? -n.x - n.width : n.x, n.flipY ? -n.y - n.height : n.y, n.width, n.height));
514
510
  })(e, t);
515
511
  }
516
- }, va = (e, t, i) => {
512
+ }, Ao = (e, t, i) => {
517
513
  if (t.visible === !1) return;
518
- if (((a, o) => {
519
- const d = ((r) => {
520
- const { canvasSize: { width: s, height: l, scaleRatioWithNoZoom: h }, canvasZoom: c, canvasOffset: u } = r;
521
- return { x: -u[0], y: -u[1], width: s / c / h, height: l / c / h };
522
- })(o);
523
- return !!li(a.computed.boundingBox, d);
514
+ if (((o, a) => {
515
+ const r = ((l) => {
516
+ const { canvasSize: { width: s, height: d, scaleRatioWithNoZoom: h }, canvasZoom: c, canvasOffset: f } = l;
517
+ return { x: -f[0], y: -f[1], width: s / c / h, height: d / c / h };
518
+ })(a);
519
+ return !!xi(o.computed.boundingBox, r);
524
520
  })(t, i)) {
525
- if (lt(e, i, t.rotation, t.computed.center), xe(e, t.style), e.globalAlpha !== 1) return ((a, o) => {
526
- const { outerBorders: d } = o.computed, r = { width: 2 * d.width, height: 2 * d.height };
527
- if (r.width === 0 || r.height === 0) return;
528
- const s = document.createElement("canvas"), l = s.getContext("2d");
529
- if (!l) throw new Error("No context found for canvas");
530
- s.width = r.width, s.height = r.height, l.translate(r.width / 4 - d.x, r.height / 4 - d.y), xe(l, { ...o.style, opacity: 100 }), nn(l, o), a.drawImage(s, d.x - r.width / 4, d.y - r.height / 4);
521
+ if (Pt(e, i, t.rotation, t.computed.center), Te(e, t.style), e.globalAlpha !== 1) return ((o, a) => {
522
+ const { outerBorders: r } = a.computed, l = { width: 2 * r.width, height: 2 * r.height };
523
+ if (l.width === 0 || l.height === 0) return;
524
+ const s = document.createElement("canvas"), d = s.getContext("2d");
525
+ if (!d) throw new Error("No context found for canvas");
526
+ s.width = l.width, s.height = l.height, d.translate(l.width / 4 - r.x, l.height / 4 - r.y), Te(d, { ...a.style, opacity: 100 }), Sn(d, a), o.drawImage(s, r.x - l.width / 4, r.y - l.height / 4);
531
527
  })(e, t), void e.restore();
532
- nn(e, t), e.restore();
528
+ Sn(e, t), e.restore();
533
529
  }
534
- }, go = (e, t, i) => {
535
- const n = le({ origin: i, point: e.computed.center, rotation: -t });
530
+ }, Ho = (e, t, i) => {
531
+ const n = me({ origin: i, point: e.computed.center, rotation: -t });
536
532
  if ("points" in e) {
537
533
  if (e.type === "brush") {
538
- const o = e.points.map((d) => d.map((r) => [r[0] + n[0] - e.computed.center[0], r[1] + n[1] - e.computed.center[1]]));
539
- return { ...e, points: o, rotation: (e.rotation ?? 0) + t };
534
+ const a = e.points.map((r) => r.map((l) => [l[0] + n[0] - e.computed.center[0], l[1] + n[1] - e.computed.center[1]]));
535
+ return { ...e, points: a, rotation: (e.rotation ?? 0) + t };
540
536
  }
541
- const a = e.points.map((o) => le({ origin: i, point: o, rotation: -t }));
542
- return { ...e, points: a };
537
+ const o = e.points.map((a) => me({ origin: i, point: a, rotation: -t }));
538
+ return { ...e, points: o };
543
539
  }
544
540
  return { ...e, x: e.x + n[0] - e.computed.center[0], y: e.y + n[1] - e.computed.center[1], rotation: (e.rotation ?? 0) + t };
545
- }, an = (e, t, i, n, a, o, d) => {
541
+ }, yn = (e, t, i, n, o, a, r) => {
546
542
  switch (i.type) {
547
543
  case "line":
548
- return ((r, s, l, h) => {
549
- const c = [we(r[0], h), we(r[1], h)], u = Re(c, s.rotation ?? 0, s.computed.center), f = Le(["points", l.anchor], u, s);
550
- return Et(f, h);
551
- })(t, i, n, a);
544
+ return ((l, s, d, h) => {
545
+ const c = [Ze(l[0], h), Ze(l[1], h)], f = tt(c, s.rotation ?? 0, s.computed.center), p = Xe(["points", d.anchor], f, s);
546
+ return ii(p, h);
547
+ })(t, i, n, o);
552
548
  case "polygon":
553
- return ((r, s, l, h) => {
554
- const c = [we(r[0], h), we(r[1], h)], u = Re(c, s.rotation ?? 0, s.computed.center), f = Le(["points", l.anchor], u, s);
555
- return St(f, h);
556
- })(t, i, n, a);
549
+ return ((l, s, d, h) => {
550
+ const c = [Ze(l[0], h), Ze(l[1], h)], f = tt(c, s.rotation ?? 0, s.computed.center), p = Xe(["points", d.anchor], f, s);
551
+ return At(p, h);
552
+ })(t, i, n, o);
557
553
  case "curve":
558
- return ((r, s, l, h) => {
559
- const c = [we(r[0], h), we(r[1], h)], u = s.computed.center, f = Re(c, s.rotation ?? 0, u), v = Le(["points", l.anchor], f, s);
560
- return Qt(v, h);
561
- })(t, i, n, a);
554
+ return ((l, s, d, h) => {
555
+ const c = [Ze(l[0], h), Ze(l[1], h)], f = s.computed.center, p = tt(c, s.rotation ?? 0, f), m = Xe(["points", d.anchor], p, s);
556
+ return Ht(m, h);
557
+ })(t, i, n, o);
562
558
  case "brush":
563
- return ((r, s, l, h, c, u) => {
564
- const f = mi({ ...s, scaleX: 1, scaleY: 1 }, h), v = s.computed.borders, { borderX: p, borderHeight: S, borderY: C, borderWidth: b, isXinverted: Q, isYinverted: g } = it(r, s, l, h, c, u), w = Math.max(0, f.width - 2 * h.selectionPadding), L = Math.max(0, f.height - 2 * h.selectionPadding), D = Math.max(0, b - 2 * h.selectionPadding), V = Math.max(0, S - 2 * h.selectionPadding), x = w ? D / w : 1, Z = L ? V / L : 1;
565
- if (!w || !L) return s;
566
- const A = Ve(p - v.x) + (Q ? 2 * v.x + f.width : 0), H = Ve(C - v.y) + (g ? 2 * v.y + f.height : 0);
567
- return ut({ ...s, points: s.points.map((F) => F.map(([E, W]) => [Q ? -E + A : E + A, g ? -W + H : W + H])), scaleX: x, scaleY: Z }, h);
568
- })(t, i, n, a, o, d);
559
+ return ((l, s, d, h, c, f) => {
560
+ const p = Hi({ ...s, scaleX: 1, scaleY: 1 }, h), m = s.computed.borders, { borderX: u, borderHeight: S, borderY: w, borderWidth: x, isXinverted: b, isYinverted: y } = St(l, s, d, h, c, f), g = Math.max(0, p.width - 2 * h.selectionPadding), P = Math.max(0, p.height - 2 * h.selectionPadding), z = Math.max(0, x - 2 * h.selectionPadding), D = Math.max(0, S - 2 * h.selectionPadding), A = g ? z / g : 1, H = P ? D / P : 1;
561
+ if (!g || !P) return s;
562
+ const Z = We(u - m.x) + (b ? 2 * m.x + p.width : 0), E = We(w - m.y) + (y ? 2 * m.y + p.height : 0);
563
+ return Zt({ ...s, points: s.points.map((F) => F.map(([W, I]) => [b ? -W + Z : W + Z, y ? -I + E : I + E])), scaleX: A, scaleY: H }, h);
564
+ })(t, i, n, o, a, r);
569
565
  case "circle":
570
- return ((r, s, l, h, c) => {
571
- const { borderX: u, borderHeight: f, borderY: v, borderWidth: p } = it(r, s, l, h, !0, c);
572
- return Tt({ ...s, radius: Math.max(0, p / 2 - h.selectionPadding), x: u + p / 2, y: v + f / 2 }, h);
573
- })(t, i, n, a, d);
566
+ return ((l, s, d, h, c) => {
567
+ const { borderX: f, borderHeight: p, borderY: m, borderWidth: u } = St(l, s, d, h, !0, c);
568
+ return Jt({ ...s, radius: Math.max(0, u / 2 - h.selectionPadding), x: f + u / 2, y: m + p / 2 }, h);
569
+ })(t, i, n, o, r);
574
570
  case "ellipse":
575
- return ((r, s, l, h, c = !1, u = !1) => {
576
- const { borderX: f, borderHeight: v, borderY: p, borderWidth: S } = it(r, s, l, h, c, u);
577
- return Dt({ ...s, radiusX: Math.max(0, S / 2 - h.selectionPadding), radiusY: Math.max(0, v / 2 - h.selectionPadding), x: f + S / 2, y: p + v / 2 }, h);
578
- })(t, i, n, a, o, d);
571
+ return ((l, s, d, h, c = !1, f = !1) => {
572
+ const { borderX: p, borderHeight: m, borderY: u, borderWidth: S } = St(l, s, d, h, c, f);
573
+ return ti({ ...s, radiusX: Math.max(0, S / 2 - h.selectionPadding), radiusY: Math.max(0, m / 2 - h.selectionPadding), x: p + S / 2, y: u + m / 2 }, h);
574
+ })(t, i, n, o, a, r);
579
575
  case "rect":
580
576
  case "square":
581
- return ((r, s, l, h, c = !1, u = !1) => {
582
- const { borderX: f, borderHeight: v, borderY: p, borderWidth: S } = it(r, s, l, h, c, u);
583
- return zt({ ...s, width: Math.max(0, S - 2 * h.selectionPadding), height: Math.max(0, v - 2 * h.selectionPadding), x: f + h.selectionPadding, y: p + h.selectionPadding }, h);
584
- })(t, i, n, a, i.type === "square" || o, d);
577
+ return ((l, s, d, h, c = !1, f = !1) => {
578
+ const { borderX: p, borderHeight: m, borderY: u, borderWidth: S } = St(l, s, d, h, c, f);
579
+ return Kt({ ...s, width: Math.max(0, S - 2 * h.selectionPadding), height: Math.max(0, m - 2 * h.selectionPadding), x: p + h.selectionPadding, y: u + h.selectionPadding }, h);
580
+ })(t, i, n, o, i.type === "square" || a, r);
585
581
  case "text":
586
- return ((r, s, l, h, c, u) => {
587
- const { borderX: f, borderHeight: v, borderY: p, borderWidth: S, isXinverted: C, isYinverted: b } = it(s, l, h, c, !0, u), Q = Math.max(0, S - 2 * c.selectionPadding), g = Math.max(0, v - 2 * c.selectionPadding), w = Wt({ ...l, width: Q, height: g, x: f + c.selectionPadding, y: p + c.selectionPadding, flipX: C ? !l.flipX : !!l.flipX, flipY: b ? !l.flipY : !!l.flipY }, c);
588
- return { ...w, fontSize: Rt(r, w.value, w.width, w.style?.fontBold ?? !1, w.style?.fontItalic ?? !1, w.style?.fontFamily) };
589
- })(e, t, i, n, a, d);
582
+ return ((l, s, d, h, c, f) => {
583
+ const { borderX: p, borderHeight: m, borderY: u, borderWidth: S, isXinverted: w, isYinverted: x } = St(s, d, h, c, !0, f), b = Math.max(0, S - 2 * c.selectionPadding), y = Math.max(0, m - 2 * c.selectionPadding), g = oi({ ...d, width: b, height: y, x: p + c.selectionPadding, y: u + c.selectionPadding, flipX: w ? !d.flipX : !!d.flipX, flipY: x ? !d.flipY : !!d.flipY }, c);
584
+ return { ...g, fontSize: ai(l, g.value, g.width, g.style?.fontBold ?? !1, g.style?.fontItalic ?? !1, g.style?.fontFamily) };
585
+ })(e, t, i, n, o, r);
590
586
  case "picture":
591
- return ((r, s, l, h, c) => {
592
- const { borderX: u, borderHeight: f, borderY: v, borderWidth: p, isXinverted: S, isYinverted: C } = it(r, s, l, h, !0, c), b = Math.max(0, p - 2 * h.selectionPadding), Q = Math.max(0, f - 2 * h.selectionPadding);
593
- return It({ ...s, width: b, height: Q, x: u + h.selectionPadding, y: v + h.selectionPadding, flipX: S ? !s.flipX : !!s.flipX, flipY: C ? !s.flipY : !!s.flipY }, h);
594
- })(t, i, n, a, d);
587
+ return ((l, s, d, h, c) => {
588
+ const { borderX: f, borderHeight: p, borderY: m, borderWidth: u, isXinverted: S, isYinverted: w } = St(l, s, d, h, !0, c), x = Math.max(0, u - 2 * h.selectionPadding), b = Math.max(0, p - 2 * h.selectionPadding);
589
+ return ni({ ...s, width: x, height: b, x: f + h.selectionPadding, y: m + h.selectionPadding, flipX: S ? !s.flipX : !!s.flipX, flipY: w ? !s.flipY : !!s.flipY }, h);
590
+ })(t, i, n, o, r);
595
591
  default:
596
592
  return i;
597
593
  }
598
- }, vo = (e, t, i, n, a, o, d) => {
599
- if (i.type !== "group") return Y(i).map((v) => an(e, t, v, n, a, o, d));
600
- const r = i, s = Y(r), l = s.filter((v) => Ea.includes(v.type)), h = !l.some((v) => (v.rotation ?? 0) !== (l[0]?.rotation ?? 0)), c = (l[0]?.rotation ?? 0) !== 0 && l.length !== s.length, u = s.some((v) => Ia.includes(v.type)), f = ((v, p, S, C, b, Q) => {
601
- const { borders: g } = p.computed, { borderX: w, borderHeight: L, borderY: D, borderWidth: V, isXinverted: x, isYinverted: Z } = it(v, p, S, C, b, Q);
602
- return { newBorderX: w, newBorderY: D, newBorderWidth: V, newBorderHeight: L, widthMultiplier: (V - 2 * C.selectionPadding) / (g.width - 2 * C.selectionPadding || 1), heightMultiplier: (L - 2 * C.selectionPadding) / (g.height - 2 * C.selectionPadding || 1), isXinverted: x, isYinverted: Z, groupCenter: [w + V / 2, D + L / 2], rotation: p.rotation ?? 0, settings: C, originalBorders: g };
603
- })(t, r, n, a, o || !h || u || c, d);
604
- return s.map((v) => {
605
- switch (v.type) {
594
+ }, Za = (e, t, i, n, o, a, r) => {
595
+ if (i.type !== "group") return U(i).map((m) => yn(e, t, m, n, o, a, r));
596
+ const l = i, s = U(l), d = s.filter((m) => Jo.includes(m.type)), h = !d.some((m) => (m.rotation ?? 0) !== (d[0]?.rotation ?? 0)), c = (d[0]?.rotation ?? 0) !== 0 && d.length !== s.length, f = s.some((m) => ea.includes(m.type)), p = ((m, u, S, w, x, b) => {
597
+ const { borders: y } = u.computed, { borderX: g, borderHeight: P, borderY: z, borderWidth: D, isXinverted: A, isYinverted: H } = St(m, u, S, w, x, b);
598
+ return { newBorderX: g, newBorderY: z, newBorderWidth: D, newBorderHeight: P, widthMultiplier: (D - 2 * w.selectionPadding) / (y.width - 2 * w.selectionPadding || 1), heightMultiplier: (P - 2 * w.selectionPadding) / (y.height - 2 * w.selectionPadding || 1), isXinverted: A, isYinverted: H, groupCenter: [g + D / 2, z + P / 2], rotation: u.rotation ?? 0, settings: w, originalBorders: y };
599
+ })(t, l, n, o, a || !h || f || c, r);
600
+ return s.map((m) => {
601
+ switch (m.type) {
606
602
  case "rect":
607
603
  case "square":
608
- return ((p, S, C) => {
609
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation, V = et(p, S, C), x = (p.width || 1) * w, Z = (p.height || 1) * L, A = tt(C, V.x, V.y, x, Z);
610
- return zt({ ...p, width: x, height: Z, x: A[0] - x / 2, y: A[1] - Z / 2, rotation: D ? -(p.rotation ?? 0) : p.rotation ?? 0 }, g);
611
- })(v, r, f);
604
+ return ((u, S, w) => {
605
+ const { isXinverted: x, isYinverted: b, settings: y, widthMultiplier: g, heightMultiplier: P } = w, z = (x || b) && !(x && b) && (u.rotation ?? 0) !== 0 && S.rotation !== u.rotation, D = vt(u, S, w), A = (u.width || 1) * g, H = (u.height || 1) * P, Z = mt(w, D.x, D.y, A, H);
606
+ return Kt({ ...u, width: A, height: H, x: Z[0] - A / 2, y: Z[1] - H / 2, rotation: z ? -(u.rotation ?? 0) : u.rotation ?? 0 }, y);
607
+ })(m, l, p);
612
608
  case "picture":
613
- return ((p, S, C) => {
614
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = et(p, S, C), V = (p.width === 0 || p.height === 0 ? p.ratio ?? 1 : p.width) * w, x = (p.width === 0 || p.height === 0 ? p.ratio ?? 1 : p.height) * L, Z = tt(C, D.x, D.y, V, x), A = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation;
615
- return It({ ...p, width: V, height: x, x: Z[0] - V / 2, y: Z[1] - x / 2, flipX: b ? !p.flipX : !!p.flipX, flipY: Q ? !p.flipY : !!p.flipY, rotation: A ? -(p.rotation ?? 0) : p.rotation ?? 0 }, g);
616
- })(v, r, f);
609
+ return ((u, S, w) => {
610
+ const { isXinverted: x, isYinverted: b, settings: y, widthMultiplier: g, heightMultiplier: P } = w, z = vt(u, S, w), D = (u.width === 0 || u.height === 0 ? u.ratio ?? 1 : u.width) * g, A = (u.width === 0 || u.height === 0 ? u.ratio ?? 1 : u.height) * P, H = mt(w, z.x, z.y, D, A), Z = (x || b) && !(x && b) && (u.rotation ?? 0) !== 0 && S.rotation !== u.rotation;
611
+ return ni({ ...u, width: D, height: A, x: H[0] - D / 2, y: H[1] - A / 2, flipX: x ? !u.flipX : !!u.flipX, flipY: b ? !u.flipY : !!u.flipY, rotation: Z ? -(u.rotation ?? 0) : u.rotation ?? 0 }, y);
612
+ })(m, l, p);
617
613
  case "text":
618
- return ((p, S, C, b) => {
619
- const { isXinverted: Q, isYinverted: g, settings: w, widthMultiplier: L, heightMultiplier: D } = b, V = (Q || g) && !(Q && g) && (S.rotation ?? 0) !== 0 && C.rotation !== S.rotation, x = et(S, C, b), Z = (S.width === 0 || S.height === 0 ? S.ratio ?? 1 : S.width) * L, A = (S.width === 0 || S.height === 0 ? S.ratio ?? 1 : S.height) * D, H = tt(b, x.x, x.y, Z, A), F = Wt({ ...S, width: Z, height: A, x: H[0] - Z / 2, y: H[1] - A / 2, flipX: Q ? !S.flipX : !!S.flipX, flipY: g ? !S.flipY : !!S.flipY, rotation: V ? -(S.rotation ?? 0) : S.rotation ?? 0 }, w);
620
- return { ...F, fontSize: Rt(p, F.value, F.width, F.style?.fontBold ?? !1, F.style?.fontItalic ?? !1, F.style?.fontFamily) };
621
- })(e, v, r, f);
614
+ return ((u, S, w, x) => {
615
+ const { isXinverted: b, isYinverted: y, settings: g, widthMultiplier: P, heightMultiplier: z } = x, D = (b || y) && !(b && y) && (S.rotation ?? 0) !== 0 && w.rotation !== S.rotation, A = vt(S, w, x), H = (S.width === 0 || S.height === 0 ? S.ratio ?? 1 : S.width) * P, Z = (S.width === 0 || S.height === 0 ? S.ratio ?? 1 : S.height) * z, E = mt(x, A.x, A.y, H, Z), F = oi({ ...S, width: H, height: Z, x: E[0] - H / 2, y: E[1] - Z / 2, flipX: b ? !S.flipX : !!S.flipX, flipY: y ? !S.flipY : !!S.flipY, rotation: D ? -(S.rotation ?? 0) : S.rotation ?? 0 }, g);
616
+ return { ...F, fontSize: ai(u, F.value, F.width, F.style?.fontBold ?? !1, F.style?.fontItalic ?? !1, F.style?.fontFamily) };
617
+ })(e, m, l, p);
622
618
  case "ellipse":
623
- return ((p, S, C) => {
624
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation, V = et(p, S, C), x = (p.radiusX || 0.5) * w, Z = (p.radiusY || 0.5) * L, A = tt(C, V.x, V.y, 2 * x, 2 * Z);
625
- return Dt({ ...p, radiusX: x, radiusY: Z, x: A[0], y: A[1], rotation: D ? -(p.rotation ?? 0) : p.rotation ?? 0 }, g);
626
- })(v, r, f);
619
+ return ((u, S, w) => {
620
+ const { isXinverted: x, isYinverted: b, settings: y, widthMultiplier: g, heightMultiplier: P } = w, z = (x || b) && !(x && b) && (u.rotation ?? 0) !== 0 && S.rotation !== u.rotation, D = vt(u, S, w), A = (u.radiusX || 0.5) * g, H = (u.radiusY || 0.5) * P, Z = mt(w, D.x, D.y, 2 * A, 2 * H);
621
+ return ti({ ...u, radiusX: A, radiusY: H, x: Z[0], y: Z[1], rotation: z ? -(u.rotation ?? 0) : u.rotation ?? 0 }, y);
622
+ })(m, l, p);
627
623
  case "circle":
628
- return ((p, S, C) => {
629
- const b = et(p, S, C), Q = (p.radius || 0.5) * C.widthMultiplier, g = tt(C, b.x, b.y, 2 * Q, 2 * Q);
630
- return Tt({ ...p, radius: Q, x: g[0], y: g[1] }, C.settings);
631
- })(v, r, f);
624
+ return ((u, S, w) => {
625
+ const x = vt(u, S, w), b = (u.radius || 0.5) * w.widthMultiplier, y = mt(w, x.x, x.y, 2 * b, 2 * b);
626
+ return Jt({ ...u, radius: b, x: y[0], y: y[1] }, w.settings);
627
+ })(m, l, p);
632
628
  case "brush":
633
- return ((p, S, C) => {
634
- const { isXinverted: b, isYinverted: Q, settings: g, widthMultiplier: w, heightMultiplier: L } = C, D = mi({ ...p, scaleX: 1, scaleY: 1 }, g), V = D.width - 2 * g.selectionPadding, x = D.height - 2 * g.selectionPadding, Z = p.scaleX ?? 1 ? (p.scaleX ?? 1) * w : w / V, A = p.scaleY ?? 1 ? (p.scaleY ?? 1) * L : L / x, H = V * Z, F = x * A, E = et(p, S, C), W = tt(C, E.x, E.y, H, F), G = Ve(W[0] - H / 2 - p.computed.borders.x - g.selectionPadding) + (b ? 2 * p.computed.borders.x + D.width : 0), _ = Ve(W[1] - F / 2 - p.computed.borders.y - g.selectionPadding) + (Q ? 2 * p.computed.borders.y + D.height : 0), z = (b || Q) && !(b && Q) && (p.rotation ?? 0) !== 0 && S.rotation !== p.rotation;
635
- return ut({ ...p, points: p.points.map((y) => y.map(([M, P]) => [b ? -M + G : M + G, Q ? -P + _ : P + _])), scaleX: Z, scaleY: A, rotation: z ? -(p.rotation ?? 0) : p.rotation ?? 0 }, C.settings);
636
- })(v, r, f);
629
+ return ((u, S, w) => {
630
+ const { isXinverted: x, isYinverted: b, settings: y, widthMultiplier: g, heightMultiplier: P } = w, z = Hi({ ...u, scaleX: 1, scaleY: 1 }, y), D = z.width - 2 * y.selectionPadding, A = z.height - 2 * y.selectionPadding, H = u.scaleX ?? 1 ? (u.scaleX ?? 1) * g : g / D, Z = u.scaleY ?? 1 ? (u.scaleY ?? 1) * P : P / A, E = D * H, F = A * Z, W = vt(u, S, w), I = mt(w, W.x, W.y, E, F), oe = We(I[0] - E / 2 - u.computed.borders.x - y.selectionPadding) + (x ? 2 * u.computed.borders.x + z.width : 0), te = We(I[1] - F / 2 - u.computed.borders.y - y.selectionPadding) + (b ? 2 * u.computed.borders.y + z.height : 0), R = (x || b) && !(x && b) && (u.rotation ?? 0) !== 0 && S.rotation !== u.rotation;
631
+ return Zt({ ...u, points: u.points.map(($) => $.map(([j, ce]) => [x ? -j + oe : j + oe, b ? -ce + te : ce + te])), scaleX: H, scaleY: Z, rotation: R ? -(u.rotation ?? 0) : u.rotation ?? 0 }, w.settings);
632
+ })(m, l, p);
637
633
  case "line":
638
634
  case "polygon":
639
635
  case "curve":
640
- return ro(v, r, f);
636
+ return Ma(m, l, p);
641
637
  default:
642
- return an(e, t, v, n, a, o, d);
638
+ return yn(e, t, m, n, o, a, r);
643
639
  }
644
640
  });
645
- }, fa = (e, t, i, n) => {
641
+ }, To = (e, t, i, n) => {
646
642
  switch (e.type) {
647
643
  case "rect":
648
644
  case "square":
@@ -650,46 +646,46 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
650
646
  case "circle":
651
647
  case "picture":
652
648
  case "text":
653
- return Ne({ ...e, x: e.x + t, y: e.y + i }, n);
649
+ return _e({ ...e, x: e.x + t, y: e.y + i }, n);
654
650
  case "line":
655
651
  case "polygon":
656
652
  case "curve":
657
- return Ne({ ...e, points: e.points.map(([a, o]) => [a + t, o + i]) }, n);
653
+ return _e({ ...e, points: e.points.map(([o, a]) => [o + t, a + i]) }, n);
658
654
  case "brush":
659
- return Ne({ ...e, points: e.points.map((a) => a.map(([o, d]) => [o + t, d + i])) }, n);
655
+ return _e({ ...e, points: e.points.map((o) => o.map(([a, r]) => [a + t, r + i])) }, n);
660
656
  default:
661
657
  return e;
662
658
  }
663
- }, ma = (e, t, i, n, a) => {
664
- const o = t.computed.borders, d = ((l, h) => h ? [Math.abs(l[0]) > Math.abs(l[1]) ? l[0] : 0, Math.abs(l[1]) > Math.abs(l[0]) ? l[1] : 0] : l)([e[0] - i[0], e[1] - i[1]], a), r = d[0] === 0 ? 0 : we(o.x + n.selectionPadding + d[0], n) - (o.x + n.selectionPadding), s = d[1] === 0 ? 0 : we(o.y + n.selectionPadding + d[1], n) - (o.y + n.selectionPadding);
665
- return Y(t).map((l) => fa(l, r, s, n));
666
- }, Ne = (e, t) => {
659
+ }, Do = (e, t, i, n, o) => {
660
+ const a = t.computed.borders, r = ((d, h) => h ? [Math.abs(d[0]) > Math.abs(d[1]) ? d[0] : 0, Math.abs(d[1]) > Math.abs(d[0]) ? d[1] : 0] : d)([e[0] - i[0], e[1] - i[1]], o), l = r[0] === 0 ? 0 : Ze(a.x + n.selectionPadding + r[0], n) - (a.x + n.selectionPadding), s = r[1] === 0 ? 0 : Ze(a.y + n.selectionPadding + r[1], n) - (a.y + n.selectionPadding);
661
+ return U(t).map((d) => To(d, l, s, n));
662
+ }, _e = (e, t) => {
667
663
  switch (e.type) {
668
664
  case "rect":
669
665
  case "square":
670
- return Ua(e, t);
666
+ return ca(e, t);
671
667
  case "ellipse":
672
- return io(e, t);
668
+ return ya(e, t);
673
669
  case "circle":
674
- return ja(e, t);
670
+ return ga(e, t);
675
671
  case "picture":
676
- return lo(e, t);
672
+ return Ca(e, t);
677
673
  case "text":
678
- return ho(e, t);
674
+ return ka(e, t);
679
675
  case "line":
680
- return so(e, t);
676
+ return xa(e, t);
681
677
  case "polygon":
682
- return ua(e, t);
678
+ return Vo(e, t);
683
679
  case "curve":
684
- return pa(e, t);
680
+ return Zo(e, t);
685
681
  case "brush":
686
- return Ra(e, t);
682
+ return ia(e, t);
687
683
  default:
688
684
  return e;
689
685
  }
690
- }, on = ({ ctx: e, shape: t, settings: i, selectionWidth: n, selectionColor: a, hoverMode: o, selectionMode: d, withAnchors: r = !0 }) => {
691
- switch (i.debug && ((s, l, h, c) => {
692
- l.selection && c.debug && (s.save(), s.scale(c.canvasSize.scaleRatio, c.canvasSize.scaleRatio), s.translate(c.canvasOffset[0], c.canvasOffset[1]), xe(s, { fillColor: "transparent", strokeColor: "green", lineWidth: h / c.canvasSize.scaleRatio }), s.strokeRect(l.computed.boundingBox.x, l.computed.boundingBox.y, l.computed.boundingBox.width, l.computed.boundingBox.height), s.restore());
686
+ }, bn = ({ ctx: e, shape: t, settings: i, selectionWidth: n, selectionColor: o, hoverMode: a, selectionMode: r, withAnchors: l = !0 }) => {
687
+ switch (i.debug && ((s, d, h, c) => {
688
+ d.selection && c.debug && (s.save(), s.scale(c.canvasSize.scaleRatio, c.canvasSize.scaleRatio), s.translate(c.canvasOffset[0], c.canvasOffset[1]), Te(s, { fillColor: "transparent", strokeColor: "green", lineWidth: h / c.canvasSize.scaleRatio }), s.strokeRect(d.computed.boundingBox.x, d.computed.boundingBox.y, d.computed.boundingBox.width, d.computed.boundingBox.height), s.restore());
693
689
  })(e, t, n, i), t.type) {
694
690
  case "rect":
695
691
  case "square":
@@ -698,712 +694,786 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
698
694
  case "picture":
699
695
  case "text":
700
696
  case "brush":
701
- ((s, l, h, c, u, f) => {
702
- if (l.selection && (lt(s, u, l.rotation, l.computed.center), u.debug && (xe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / u.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), xe(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / u.canvasSize.scaleRatio }), l.selection.shapePath ? s.stroke(l.selection.shapePath) : s.stroke(l.selection.border), f && !l.locked)) {
703
- l.selection.shapePath && s.stroke(l.selection.border), l.selection.line && s.stroke(l.selection.line), xe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / u.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
704
- for (const v of l.selection.anchors) s.fill(v), s.stroke(v);
697
+ ((s, d, h, c, f, p) => {
698
+ if (d.selection && (Pt(s, f, d.rotation, d.computed.center), f.debug && (Te(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / f.canvasSize.scaleRatio }), s.strokeRect(d.computed.outerBorders.x, d.computed.outerBorders.y, d.computed.outerBorders.width, d.computed.outerBorders.height)), Te(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / f.canvasSize.scaleRatio }), d.selection.shapePath ? s.stroke(d.selection.shapePath) : s.stroke(d.selection.border), p && !d.locked)) {
699
+ d.selection.shapePath && s.stroke(d.selection.border), d.selection.line && s.stroke(d.selection.line), Te(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / f.canvasSize.scaleRatio, shadowColor: h, shadowBlur: 0 });
700
+ for (const m of d.selection.anchors) s.fill(m), s.stroke(m);
705
701
  }
706
- })(e, t, a, n, i, r);
702
+ })(e, t, o, n, i, l);
707
703
  break;
708
704
  case "group":
709
- ((s, l, h, c, u, f, v) => {
710
- if (l.selection && (l.shapes.forEach((p) => {
711
- xe(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / f.canvasSize.scaleRatio }), lt(s, f, p.rotation, p.computed.center), p.selection?.shapePath && s.stroke(p.selection.shapePath), s.restore();
712
- }), u.mode !== "rotate" && (lt(s, f, l.rotation, l.computed.center), f.debug && (xe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / f.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), xe(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / f.canvasSize.scaleRatio }), v && !l.locked))) {
713
- s.stroke(l.selection.border), l.selection.line && s.stroke(l.selection.line), xe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / f.canvasSize.scaleRatio });
714
- for (const p of l.selection.anchors) s.fill(p), s.stroke(p);
705
+ ((s, d, h, c, f, p, m) => {
706
+ if (d.selection && (d.shapes.forEach((u) => {
707
+ Te(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / p.canvasSize.scaleRatio }), Pt(s, p, u.rotation, u.computed.center), u.selection?.shapePath && s.stroke(u.selection.shapePath), s.restore();
708
+ }), f.mode !== "rotate" && (Pt(s, p, d.rotation, d.computed.center), p.debug && (Te(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / p.canvasSize.scaleRatio }), s.strokeRect(d.computed.outerBorders.x, d.computed.outerBorders.y, d.computed.outerBorders.width, d.computed.outerBorders.height)), Te(s, { fillColor: "transparent", strokeColor: h, lineWidth: c / p.canvasSize.scaleRatio }), m && !d.locked))) {
709
+ s.stroke(d.selection.border), d.selection.line && s.stroke(d.selection.line), Te(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / p.canvasSize.scaleRatio });
710
+ for (const u of d.selection.anchors) s.fill(u), s.stroke(u);
715
711
  }
716
- })(e, t, a, n, d, i, r);
712
+ })(e, t, o, n, r, i, l);
717
713
  break;
718
714
  case "polygon":
719
715
  case "line":
720
716
  case "curve":
721
- (({ ctx: s, shape: l, withAnchors: h, selectionWidth: c, selectionColor: u, hoverMode: f, settings: v }) => {
722
- if (l.selection && (lt(s, v, l.rotation, l.computed.center), v.debug && (xe(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / v.canvasSize.scaleRatio }), s.strokeRect(l.computed.outerBorders.x, l.computed.outerBorders.y, l.computed.outerBorders.width, l.computed.outerBorders.height)), xe(s, { fillColor: "transparent", strokeColor: u, lineWidth: c / v.canvasSize.scaleRatio }), l.selection.shapePath && s.stroke(l.selection.shapePath), h && !l.locked)) {
723
- xe(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / v.canvasSize.scaleRatio, shadowColor: u, shadowBlur: 0 });
724
- for (let p = 0; p < l.selection.anchors.length; p++) {
725
- const S = l.selection.anchors[p];
726
- f.mode === "resize" && f.anchor === p ? (s.shadowBlur = 10, s.fill(S), s.shadowBlur = 0) : s.fill(S), s.stroke(S);
717
+ (({ ctx: s, shape: d, withAnchors: h, selectionWidth: c, selectionColor: f, hoverMode: p, settings: m }) => {
718
+ if (d.selection && (Pt(s, m, d.rotation, d.computed.center), m.debug && (Te(s, { fillColor: "transparent", strokeColor: "red", lineWidth: c / m.canvasSize.scaleRatio }), s.strokeRect(d.computed.outerBorders.x, d.computed.outerBorders.y, d.computed.outerBorders.width, d.computed.outerBorders.height)), Te(s, { fillColor: "transparent", strokeColor: f, lineWidth: c / m.canvasSize.scaleRatio }), d.selection.shapePath && s.stroke(d.selection.shapePath), h && !d.locked)) {
719
+ Te(s, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / m.canvasSize.scaleRatio, shadowColor: f, shadowBlur: 0 });
720
+ for (let u = 0; u < d.selection.anchors.length; u++) {
721
+ const S = d.selection.anchors[u];
722
+ p.mode === "resize" && p.anchor === u ? (s.shadowBlur = 10, s.fill(S), s.shadowBlur = 0) : s.fill(S), s.stroke(S);
727
723
  }
728
724
  }
729
- })({ ctx: e, shape: t, withAnchors: r, selectionWidth: n, selectionColor: a, hoverMode: o, settings: i });
725
+ })({ ctx: e, shape: t, withAnchors: l, selectionWidth: n, selectionColor: o, hoverMode: a, settings: i });
730
726
  }
731
727
  e.restore();
732
- }, fo = ({ ctx: e, selectionFrame: t, settings: i }) => {
733
- lt(e, i), ((n, a, o) => {
734
- xe(n, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / o.canvasSize.scaleRatio }), n.fillRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]), n.strokeRect(a[0][0], a[0][1], a[1][0] - a[0][0], a[1][1] - a[0][1]);
728
+ }, za = ({ ctx: e, selectionFrame: t, settings: i }) => {
729
+ Pt(e, i), ((n, o, a) => {
730
+ Te(n, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / a.canvasSize.scaleRatio }), n.fillRect(o[0][0], o[0][1], o[1][0] - o[0][0], o[1][1] - o[0][1]), n.strokeRect(o[0][0], o[0][1], o[1][0] - o[0][0], o[1][1] - o[0][1]);
735
731
  })(e, t.frame, i), e.restore();
736
- }, xi = (e) => e.filter((t) => t != null), ya = (e) => {
732
+ }, Wi = (e, t) => U(e).map((i) => ({ ...To(i, 20, 20, t), id: Ce(`${i.type}_`) })), Ni = (e) => e.filter((t) => t != null), vi = (e, t, i) => t < 0 || i < 0 || t > e.length - 1 || i > e.length - 1 ? e : t < i ? [...e.slice(0, t), ...e.slice(t + 1, i + 1), e[t], ...e.slice(i + 1, e.length)] : [...e.slice(0, i), e[t], ...e.slice(i, t), ...e.slice(t + 1, e.length)], Eo = (e) => {
737
733
  const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0];
738
734
  if (!t) return "";
739
735
  const i = t.getAttribute("width"), n = t.getAttribute("height");
740
- let a;
741
- if (i || n) a = e;
736
+ let o;
737
+ if (i || n) o = e;
742
738
  else {
743
- const d = t.getAttribute("viewBox") ?? "0 0 300 300", [, , r, s] = d.split(" ");
744
- t.setAttribute("width", r ?? "300"), t.setAttribute("height", s ?? "300"), a = new XMLSerializer().serializeToString(t);
739
+ const r = t.getAttribute("viewBox") ?? "0 0 300 300", [, , l, s] = r.split(" ");
740
+ t.setAttribute("width", l ?? "300"), t.setAttribute("height", s ?? "300"), o = new XMLSerializer().serializeToString(t);
745
741
  }
746
- const o = new Blob([a], { type: "image/svg+xml" });
747
- return URL.createObjectURL(o);
748
- }, Sa = (e) => (e instanceof File ? e.name : e).includes(".svg"), Qa = (e) => Sa(e) ? fetch(e).then((t) => t.text()).then((t) => ya(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), sn = (e, t) => {
742
+ const a = new Blob([o], { type: "image/svg+xml" });
743
+ return URL.createObjectURL(a);
744
+ }, Io = (e) => (e instanceof File ? e.name : e).includes(".svg"), Ro = (e) => Io(e) ? fetch(e).then((t) => t.text()).then((t) => Eo(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), Qn = (e, t) => {
749
745
  const i = document.createElement("a");
750
746
  i.href = e, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
751
- }, mo = (e) => e.src.includes("<svg") ? e.src : ((t) => {
747
+ }, Aa = (e) => e.src.includes("<svg") ? e.src : ((t) => {
752
748
  const i = document.createElement("canvas");
753
749
  i.width = t.width, i.height = t.height;
754
750
  const n = i.getContext("2d");
755
751
  return n ? (n.drawImage(t, 0, 0), i.toDataURL("image/png")) : "";
756
- })(e.img), ii = ({ shapes: e, settings: t }) => {
752
+ })(e.img), mi = ({ shapes: e, settings: t }) => {
757
753
  const i = document.createElement("canvas"), n = i.getContext("2d");
758
754
  if (!n) throw new Error("No context found for canvas");
759
- const { realHeight: a, realWidth: o } = t.canvasSize;
760
- i.width = o, i.height = a, n.clearRect(0, 0, o, a), ta(n);
761
- for (let d = e.length - 1; d >= 0; d--) va(n, e[d], t);
755
+ const { realHeight: o, realWidth: a } = t.canvasSize;
756
+ i.width = a, i.height = o, n.clearRect(0, 0, a, o), So(n);
757
+ for (let r = e.length - 1; r >= 0; r--) Ao(n, e[r], t);
762
758
  return i.toDataURL("image/png");
763
- }, rn = ({ shapes: e, settings: t, view: i }) => {
759
+ }, wn = ({ shapes: e, settings: t, view: i }) => {
764
760
  if (i === "fitToShapes" && !e.length) throw new Error("No image found to export");
765
761
  if (i === "fitToShapes") {
766
- const a = Math.min(...e.map((l) => l.computed.boundingBox.x)), o = Math.max(...e.map((l) => l.computed.boundingBox.x + l.computed.boundingBox.width)), d = Math.min(...e.map((l) => l.computed.boundingBox.y)), r = Math.max(...e.map((l) => l.computed.boundingBox.y + l.computed.boundingBox.height)), s = { ...t, canvasOffset: [-a, -d], canvasZoom: 1, canvasSize: { realWidth: o - a, realHeight: r - d, width: o - a, height: r - d, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
767
- return ii({ shapes: e, settings: s });
762
+ const o = Math.min(...e.map((d) => d.computed.boundingBox.x)), a = Math.max(...e.map((d) => d.computed.boundingBox.x + d.computed.boundingBox.width)), r = Math.min(...e.map((d) => d.computed.boundingBox.y)), l = Math.max(...e.map((d) => d.computed.boundingBox.y + d.computed.boundingBox.height)), s = { ...t, canvasOffset: [-o, -r], canvasZoom: 1, canvasSize: { realWidth: a - o, realHeight: l - r, width: a - o, height: l - r, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
763
+ return mi({ shapes: e, settings: s });
768
764
  }
769
765
  if (i === "defaultView") {
770
- const a = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
771
- return ii({ shapes: e, settings: a });
766
+ const o = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
767
+ return mi({ shapes: e, settings: o });
772
768
  }
773
769
  const n = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
774
- return ii({ shapes: e, settings: n });
775
- }, yo = (e, t, i) => {
776
- return a = Ci(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(a))}`;
777
- var a;
778
- }, So = (e) => {
770
+ return mi({ shapes: e, settings: n });
771
+ }, Ha = (e, t, i) => {
772
+ return o = Oi(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(o))}`;
773
+ var o;
774
+ }, Ta = (e) => {
779
775
  const t = ["img", "id", "selection", "path", "arrows", "tempPoint", "computed", ["flipX", [void 0, !1]], ["flipY", [void 0, !1]]];
780
- return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? ai(t, i) : ai(t, { ...i, src: mo(i) }));
781
- }, Ci = (e, t, i) => ({ shapes: So(e), config: { width: t, height: i } }), ln = (e, t) => Ne({ ...e, id: ue(`${e.type}_`) }, t), Qo = (e, t, i, n) => {
782
- const a = ne([]), o = ne({ dataChanged: [] }), [d, r] = $(void 0), [s, l] = $(void 0), [h, c] = $(void 0), [u, f] = $({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), v = u.cursor > 0, p = u.cursor < u.states.length - 1, S = a.current.length > 0, C = X(() => {
783
- f((y) => Jn(y.states[y.cursor]?.shapes, a.current) ? y : { states: [...y.states.slice(0, y.cursor + 1), { shapes: a.current, selectedShape: s, source: "user" }], cursor: y.cursor + 1 });
784
- }, [s]), b = X((y) => {
785
- a.current = [...y, ...a.current];
786
- }, []), Q = X((y) => {
787
- a.current = a.current.flatMap((M) => {
788
- const P = y.find((T) => T.id === M.id);
789
- return P ? [{ ...P, id: ue(`${M.type}_`) }, M] : M;
790
- });
791
- }, []), g = X((y, M, P, T) => {
792
- if (y.target && "className" in y.target && ![jn, Kn].includes(y.target.className) || !T) return void c(void 0);
793
- const k = a.current.find((O) => Y(s)?.map((R) => R.id).includes(O.id) ? !!ft(M, O, P, e) : !!da(M, O, P, e));
794
- c(k);
795
- }, [e, s]), w = X(async (y, M = 300, P = 300) => {
796
- const T = await co(y, M, P, e);
797
- return b([T]), C(), T;
798
- }, [b, C, e]), L = X((y, M = !1) => {
799
- a.current = a.current.map((P) => y.find((T) => T.id === P.id) ?? P), l((P) => P && pe(Y(P).map((T) => y.find((k) => k.id === T.id) ?? T), e)), M && C();
800
- }, [C, e]), D = X((y) => {
801
- const M = y.map((P) => ai(["chosen"], P));
802
- a.current = M, C();
803
- }, [C]), V = X((y) => {
804
- const M = new Set(y.map((P) => P.id));
805
- l((P) => {
806
- const T = Y(P).map((k) => k.id);
807
- return T && M.size && T.find((k) => M.has(k)) ? void 0 : P;
808
- }), a.current = a.current.filter((P) => !M?.has(P.id)), C();
809
- }, [C]), x = X((y) => {
810
- f((M) => {
811
- const P = y(M);
812
- return a.current = M.states[P]?.shapes ?? [], l(M.states[P]?.selectedShape), Le("cursor", P, M);
776
+ return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? yi(t, i) : yi(t, { ...i, src: Aa(i) }));
777
+ }, Oi = (e, t, i) => ({ shapes: Ta(e), config: { width: t, height: i } }), xn = (e, t) => _e({ ...e, id: Ce(`${e.type}_`) }, t), Da = (e, t, i, n) => {
778
+ const o = re([]), a = re(void 0), r = re({ dataChanged: [] }), [l, s] = K(void 0), [d, h] = K(void 0), [c, f] = K(void 0), [p, m] = K(void 0), [u, S] = K({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), w = X((M) => {
779
+ a.current = typeof M == "function" ? M(a.current) : M, h(a.current);
780
+ }, []), x = u.cursor > 0, b = u.cursor < u.states.length - 1, y = o.current.length > 0, g = X(() => {
781
+ S((M) => vo(M.states[M.cursor]?.shapes, o.current) ? M : { states: [...M.states.slice(0, M.cursor + 1), { shapes: o.current, selectedShape: a.current, source: "user" }], cursor: M.cursor + 1 });
782
+ }, []), P = X((M) => {
783
+ o.current = [...M, ...o.current];
784
+ }, []), z = X((M, C = !1, Q = !1) => {
785
+ const V = [];
786
+ o.current = o.current.flatMap((N) => {
787
+ const k = M.find((J) => J.id === N.id);
788
+ if (k) {
789
+ const J = C ? Wi(de([k], e), e)[0] : { ...k, id: Ce(`${N.type}_`) };
790
+ return V.push(J), [J, N];
791
+ }
792
+ return N;
793
+ }), Q && w(de(V, e));
794
+ }, [e, w]), D = X((M, C, Q, V) => {
795
+ if (M.target && "className" in M.target && ![go, fo].includes(M.target.className) || !V) return void f(void 0);
796
+ const N = o.current.find((k) => U(d)?.map((J) => J.id).includes(k.id) ? !!Et(C, k, Q, e) : !!Po(C, k, Q, e));
797
+ f(N);
798
+ }, [e, d]), A = X(async (M, C = 300, Q = 300) => {
799
+ const V = await Pa(M, C, Q, e);
800
+ return P([V]), g(), V;
801
+ }, [P, g, e]), H = X((M, C = !1) => {
802
+ o.current = o.current.map((Q) => M.find((V) => V.id === Q.id) ?? Q), w((Q) => Q && de(U(Q).map((V) => M.find((N) => N.id === V.id) ?? V), e)), C && g();
803
+ }, [g, w, e]), Z = X((M) => {
804
+ const C = M.map((Q) => yi(["chosen"], Q));
805
+ o.current = C, g();
806
+ }, [g]), E = X((M) => {
807
+ const C = new Set(M.map((Q) => Q.id));
808
+ w((Q) => {
809
+ const V = U(Q).map((N) => N.id);
810
+ return V && C.size && V.find((N) => C.has(N)) ? void 0 : Q;
811
+ }), o.current = o.current.filter((Q) => !C?.has(Q.id)), g();
812
+ }, [g, w]), F = X((M) => {
813
+ S((C) => {
814
+ const Q = M(C);
815
+ return o.current = C.states[Q]?.shapes ?? [], w(C.states[Q]?.selectedShape), Xe("cursor", Q, C);
813
816
  });
814
- }, []), Z = X(() => {
815
- x((y) => Math.max(0, y.cursor - 1));
816
- }, [x]), A = X(() => {
817
- x((y) => Math.min(y.states.length - 1, y.cursor + 1));
818
- }, [x]), H = X((y, M) => {
819
- l(void 0), a.current = y, f((P) => M.clearHistory ? { states: [{ shapes: y, selectedShape: void 0, source: M.source }], cursor: 0 } : { states: [...P.states.slice(0, P.cursor + 1), { shapes: y, selectedShape: void 0, source: M.source }], cursor: P.cursor + 1 });
820
- }, []), F = X((y, M) => {
821
- const P = a.current, T = P.findIndex((I) => I.id === y), k = P.findIndex((I) => I.id === M);
822
- var O, R, B;
823
- D((O = P, B = k, (R = T) < 0 || B < 0 || R > O.length - 1 || B > O.length - 1 ? O : R < B ? [...O.slice(0, R), ...O.slice(R + 1, B + 1), O[R], ...O.slice(B + 1, O.length)] : [...O.slice(0, B), O[R], ...O.slice(B, R), ...O.slice(R + 1, O.length)]));
824
- }, [D]), E = X((y) => {
825
- const M = a.current, P = new Set(y.map((k) => k.id)), T = M.map((k) => P.has(k.id) ? Le("visible", k.visible === !1, k) : k);
826
- l(qi((k) => Le("visible", k.visible === !1, k), e)), D(T);
827
- }, [D, e]), W = X((y) => {
828
- const M = a.current, P = new Set(y.map((k) => k.id)), T = M.map((k) => P.has(k.id) ? Le("locked", !k.locked, k) : k);
829
- l(qi((k) => Le("locked", !k.locked, k), e)), D(T);
830
- }, [D, e]), G = X((y, M) => {
831
- o.current.hasOwnProperty(y) && (o.current[y] = [...o.current[y], M]);
832
- }, []), _ = X((y, M) => {
833
- if (o.current.hasOwnProperty(y)) if (M) {
834
- const P = o.current[y].indexOf(M);
835
- o.current[y] = [...o.current[y].slice(0, P), ...o.current[y].slice(P + 1)];
836
- } else o.current[y] = [];
817
+ }, [w]), W = X(() => {
818
+ F((M) => Math.max(0, M.cursor - 1));
819
+ }, [F]), I = X(() => {
820
+ F((M) => Math.min(M.states.length - 1, M.cursor + 1));
821
+ }, [F]), oe = X((M, C) => {
822
+ w(void 0), o.current = M, S((Q) => C.clearHistory ? { states: [{ shapes: M, selectedShape: void 0, source: C.source }], cursor: 0 } : { states: [...Q.states.slice(0, Q.cursor + 1), { shapes: M, selectedShape: void 0, source: C.source }], cursor: Q.cursor + 1 });
823
+ }, [w]), te = X((M, C) => {
824
+ const Q = o.current, V = Q.findIndex((k) => k.id === M), N = Q.findIndex((k) => k.id === C);
825
+ Z(vi(Q, V, N));
826
+ }, [Z]), R = X((M, C) => {
827
+ const Q = [...o.current], V = new Set(M.map((k) => k.id)), N = Q.map((k, J) => V.has(k.id) ? J : -1).filter((k) => k >= 0);
828
+ if (N.length !== 0) switch (C) {
829
+ case "first":
830
+ case "last": {
831
+ const k = N.map((O) => Q[O]).filter(Boolean), J = Q.filter((O, T) => !N.includes(T));
832
+ Z(C === "first" ? [...k, ...J] : [...J, ...k]);
833
+ break;
834
+ }
835
+ case "backward": {
836
+ let k = [...Q];
837
+ const J = N.sort((O, T) => T - O).map((O) => Q[O].id);
838
+ for (const O of J) {
839
+ const T = k.findIndex((ne) => ne.id === O);
840
+ if (T < k.length - 1) {
841
+ const ne = T + 1;
842
+ V.has(k[ne].id) || (k = vi(k, T, ne));
843
+ }
844
+ }
845
+ Z(k);
846
+ break;
847
+ }
848
+ case "forward": {
849
+ let k = [...Q];
850
+ const J = N.sort((O, T) => O - T).map((O) => Q[O].id);
851
+ for (const O of J) {
852
+ const T = k.findIndex((ne) => ne.id === O);
853
+ if (T > 0) {
854
+ const ne = T - 1;
855
+ V.has(k[ne].id) || (k = vi(k, T, ne));
856
+ }
857
+ }
858
+ Z(k);
859
+ break;
860
+ }
861
+ }
862
+ }, [Z]), $ = X((M, C, Q) => {
863
+ const V = new Set(M.map((k) => k.id)), N = o.current.map((k) => V.has(k.id) ? _e(Ho(k, Q === "rotateClockwise" ? Math.PI / 2 : -Math.PI / 2, C), e) : k);
864
+ w(de(N.filter((k) => V.has(k.id)), e)), Z(N);
865
+ }, [e, Z, w]), j = X((M) => {
866
+ const C = new Set(M.map((V) => V.id)), Q = o.current.map((V) => C.has(V.id) ? Xe("visible", V.visible === !1, V) : V);
867
+ w((V) => de(Q.filter((N) => U(V)?.map((k) => k.id).includes(N.id)), e)), Z(Q);
868
+ }, [Z, e, w]), ce = X((M) => {
869
+ const C = new Set(M.map((V) => V.id)), Q = o.current.map((V) => C.has(V.id) ? Xe("locked", !V.locked, V) : V);
870
+ w((V) => de(Q.filter((N) => U(V)?.map((k) => k.id).includes(N.id)), e)), Z(Q);
871
+ }, [Z, e, w]), Pe = X((M, C) => {
872
+ r.current.hasOwnProperty(M) && (r.current[M] = [...r.current[M], C]);
873
+ }, []), L = X((M, C) => {
874
+ if (r.current.hasOwnProperty(M)) if (C) {
875
+ const Q = r.current[M].indexOf(C);
876
+ r.current[M] = [...r.current[M].slice(0, Q), ...r.current[M].slice(Q + 1)];
877
+ } else r.current[M] = [];
837
878
  }, []);
838
- ee(() => {
839
- const y = u.states[u.cursor], M = Ci(y.shapes, t, i);
840
- for (const P of o.current.dataChanged) P(M, y.source);
841
- }, [t, i, u]), ee(() => {
842
- a.current = a.current.map((y) => Ne(y, e)), l((y) => y === void 0 ? void 0 : pe(Y(y).map((M) => Ne(M, e)), e));
843
- }, [e]);
844
- const z = X((y, M) => {
845
- r((P) => {
846
- const T = [P?.frame[0] ?? [M[0], M[1]], [M[0], M[1]]], k = a.current.filter((R) => ((B, I, j) => {
847
- const { borders: de, center: se, boundingBox: K } = I.computed, N = Math.min(j[0][0], j[1][0]), ge = Math.max(j[0][0], j[1][0]), oe = Math.min(j[0][1], j[1][1]), ye = { x: N, y: oe, width: ge - N, height: Math.max(j[0][1], j[1][1]) - oe }, Se = li(K, ye);
879
+ le(() => {
880
+ const M = u.states[u.cursor], C = Oi(M.shapes, t, i);
881
+ for (const Q of r.current.dataChanged) Q(C, M.source);
882
+ }, [t, i, u]), le(() => {
883
+ o.current = o.current.map((M) => _e(M, e)), w((M) => M === void 0 ? void 0 : de(U(M).map((C) => _e(C, e)), e));
884
+ }, [e, w]);
885
+ const _ = X((M, C) => {
886
+ s((Q) => {
887
+ const V = [Q?.frame[0] ?? [C[0], C[1]], [C[0], C[1]]], N = o.current.filter((J) => ((O, T, ne) => {
888
+ const { borders: ye, center: Y, boundingBox: ze } = T.computed, ge = Math.min(ne[0][0], ne[1][0]), Oe = Math.max(ne[0][0], ne[1][0]), Ye = Math.min(ne[0][1], ne[1][1]), he = { x: ge, y: Ye, width: Oe - ge, height: Math.max(ne[0][1], ne[1][1]) - Ye }, Se = xi(ze, he);
848
889
  if (!Se) return !1;
849
- if (de.width <= 1 || de.height <= 1) return !0;
850
- if (B.lineWidth = (I.style?.lineWidth ?? 0) + 10, I.type === "brush") {
851
- const te = I.points.flat(), ve = Math.min(...te.map((ae) => ae[0])), U = Math.min(...te.map((ae) => ae[1]));
852
- for (const ae of I.points) {
853
- if (ae.length < 1) break;
854
- if (ae.length < 2) {
855
- const Me = Ee(ae[0], ve, U, I.scaleX, I.scaleY);
856
- if (ia(Se, { x: Me[0], y: Me[1], radius: (I.style?.lineWidth ?? 1) / 2 })) return !0;
890
+ if (ye.width <= 1 || ye.height <= 1) return !0;
891
+ if (O.lineWidth = (T.style?.lineWidth ?? 0) + 10, T.type === "brush") {
892
+ const fe = T.points.flat(), ee = Math.min(...fe.map((pe) => pe[0])), se = Math.min(...fe.map((pe) => pe[1]));
893
+ for (const pe of T.points) {
894
+ if (pe.length < 1) break;
895
+ if (pe.length < 2) {
896
+ const ke = Ge(pe[0], ee, se, T.scaleX, T.scaleY);
897
+ if (yo(Se, { x: ke[0], y: ke[1], radius: (T.style?.lineWidth ?? 1) / 2 })) return !0;
857
898
  }
858
- for (let Me = 0; Me < ae.length - 1; Me++) {
859
- const Ze = ri(Ee(ae[Me], ve, U, I.scaleX, I.scaleY), I.rotation ?? 0, se), re = ri(Ee(ae[Me + 1], ve, U, I.scaleX, I.scaleY), I.rotation ?? 0, se), Te = li({ x: Math.min(Ze[0], re[0]), y: Math.min(Ze[1], re[1]), width: Math.abs(Ze[0] - re[0]), height: Math.abs(Ze[1] - re[1]) }, ye);
860
- if (Te) {
861
- const qe = new Path2D();
862
- if (qe.moveTo(...Ze), qe.lineTo(...re), _i({ ctx: B, path: qe, rect: Te, offset: 10, center: se, checkFill: !1 })) return !0;
899
+ for (let ke = 0; ke < pe.length - 1; ke++) {
900
+ const Be = wi(Ge(pe[ke], ee, se, T.scaleX, T.scaleY), T.rotation ?? 0, Y), Ee = wi(Ge(pe[ke + 1], ee, se, T.scaleX, T.scaleY), T.rotation ?? 0, Y), we = xi({ x: Math.min(Be[0], Ee[0]), y: Math.min(Be[1], Ee[1]), width: Math.abs(Be[0] - Ee[0]), height: Math.abs(Be[1] - Ee[1]) }, he);
901
+ if (we) {
902
+ const Fe = new Path2D();
903
+ if (Fe.moveTo(...Be), Fe.lineTo(...Ee), pn({ ctx: O, path: Fe, rect: we, offset: 10, center: Y, checkFill: !1 })) return !0;
863
904
  }
864
905
  }
865
906
  }
866
907
  return !1;
867
908
  }
868
- const Qe = bi(I);
869
- return _i({ ctx: B, path: I.path, rect: Se, offset: 10, center: se, rotation: I.rotation ?? 0, checkFill: Qe });
870
- })(y, R, T)), O = pe(k, e);
871
- return l(n ? pe(sa(P?.oldSelection, k), e) : O), { oldSelection: P?.oldSelection, frame: T };
909
+ const ae = Ii(T);
910
+ return pn({ ctx: O, path: T.path, rect: Se, offset: 10, center: Y, rotation: T.rotation ?? 0, checkFill: ae });
911
+ })(M, J, V)), k = de(N, e);
912
+ return w(n ? de(xo(Q?.oldSelection, N), e) : k), { oldSelection: Q?.oldSelection, frame: V };
872
913
  });
873
- }, [e, n]);
874
- return { registerEvent: G, unregisterEvent: _, shapesRef: a, selectedShape: s, hoveredShape: h, selectionFrame: d, setSelectionFrame: r, refreshSelectedShapes: z, addShapes: b, duplicateShapes: Q, addPictureShape: w, moveShapes: F, saveShapes: C, setSelectedShape: l, refreshHoveredShape: g, toggleShapeVisibility: E, toggleShapeLock: W, removeShape: V, updateShape: L, backwardShape: Z, forwardShape: A, clearShapes: H, canGoBackward: v, canGoForward: p, canClear: S };
875
- }, dn = (e) => {
914
+ }, [e, n, w]);
915
+ return { registerEvent: Pe, unregisterEvent: L, shapesRef: o, selectedShape: d, hoveredShape: c, selectionFrame: l, setSelectionFrame: s, copiedShape: p, setCopiedShape: m, refreshSelectedShapes: _, addShapes: P, duplicateShapes: z, addPictureShape: A, moveShapes: R, swapShapes: te, saveShapes: g, setSelectedShape: w, refreshHoveredShape: D, toggleShapeVisibility: j, toggleShapeLock: ce, removeShape: E, updateShape: H, transformShape: $, backwardShape: W, forwardShape: I, clearShapes: oe, canGoBackward: x, canGoForward: b, canClear: y };
916
+ }, Mn = (e) => {
876
917
  const t = [e[0].clientX, e[0].clientY], i = [e[1].clientX, e[1].clientY];
877
- var n, a;
878
- return { diff: na(t, i), center: (a = i, [((n = t)[0] + a[0]) / 2, (n[1] + a[1]) / 2]) };
879
- }, bo = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: n, setCanvasTransformation: a }) => {
880
- const o = ne([]), [d, r] = $(o.current.length > 0), s = ne(null), l = ne(t);
881
- l.current = t;
882
- const h = X(({ startDiff: c, startZoom: u, startCenter: f, startOffset: v, currentDiff: p, currentCenter: S, isMoving: C, isZooming: b }) => {
883
- if (!e || !p || !c) return;
884
- const Q = (({ canvasBoundingRect: g, canvasSize: w, size: L, startDiff: D, startZoom: V, startCenter: x, startOffset: Z, currentDiff: A, currentCenter: H, isMoving: F, isZooming: E }) => {
885
- const W = E ? We(A / D * V, Pe[0], Pe[Pe.length - 1]) : V, G = F ? [Z[0] + (H[0] - x[0]) * (w.width / g.width) / w.scaleRatio / V, Z[1] + (H[1] - x[1]) * (w.height / g.height) / w.scaleRatio / V] : [Z[0], Z[1]], _ = [(H[0] - g.left) / w.scaleRatio, (H[1] - g.top) / w.scaleRatio];
886
- return ci({ size: L, canvasSize: w, currentOffset: G, currentZoom: V, zoom: W, centerPoint: _ });
887
- })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: n, startDiff: c, startZoom: u, startCenter: f, startOffset: v, currentDiff: p, currentCenter: S, isMoving: C, isZooming: b });
888
- a(Q);
889
- }, [e, i, n, a]);
890
- ee(() => {
918
+ var n, o;
919
+ return { diff: bo(t, i), center: (o = i, [((n = t)[0] + o[0]) / 2, (n[1] + o[1]) / 2]) };
920
+ }, Ea = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: n, setCanvasTransformation: o }) => {
921
+ const a = re([]), [r, l] = K(a.current.length > 0), s = re(null), d = re(t);
922
+ d.current = t;
923
+ const h = X(({ startDiff: c, startZoom: f, startCenter: p, startOffset: m, currentDiff: u, currentCenter: S, isMoving: w, isZooming: x }) => {
924
+ if (!e || !u || !c) return;
925
+ const b = (({ canvasBoundingRect: y, canvasSize: g, size: P, startDiff: z, startZoom: D, startCenter: A, startOffset: H, currentDiff: Z, currentCenter: E, isMoving: F, isZooming: W }) => {
926
+ const I = W ? et(Z / z * D, Ie[0], Ie[Ie.length - 1]) : D, oe = F ? [H[0] + (E[0] - A[0]) * (g.width / y.width) / g.scaleRatio / D, H[1] + (E[1] - A[1]) * (g.height / y.height) / g.scaleRatio / D] : [H[0], H[1]], te = [(E[0] - y.left) / g.scaleRatio, (E[1] - y.top) / g.scaleRatio];
927
+ return Ci({ size: P, canvasSize: g, currentOffset: oe, currentZoom: D, zoom: I, centerPoint: te });
928
+ })({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: n, startDiff: c, startZoom: f, startCenter: p, startOffset: m, currentDiff: u, currentCenter: S, isMoving: w, isZooming: x });
929
+ o(b);
930
+ }, [e, i, n, o]);
931
+ le(() => {
891
932
  if (!e) return;
892
- const c = (u) => {
893
- if (o.current = [...o.current, u], r(o.current.length > 0), o.current.length === 2) {
894
- u.stopPropagation();
895
- const { diff: f, center: v } = dn(o.current);
896
- s.current = { startDiff: f, startCenter: v, startZoom: l.current.zoom, startOffset: l.current.offset, isMoving: !1, isZooming: !1 };
933
+ const c = (f) => {
934
+ if (a.current = [...a.current, f], l(a.current.length > 0), a.current.length === 2) {
935
+ f.stopPropagation();
936
+ const { diff: p, center: m } = Mn(a.current);
937
+ s.current = { startDiff: p, startCenter: m, startZoom: d.current.zoom, startOffset: d.current.offset, isMoving: !1, isZooming: !1 };
897
938
  }
898
939
  };
899
940
  return e.addEventListener("pointerdown", c), () => {
900
941
  e.removeEventListener("pointerdown", c);
901
942
  };
902
- }, [e]), ee(() => {
903
- if (!d) return;
904
- const c = (f) => {
905
- const v = o.current.findIndex((p) => p.pointerId === f.pointerId);
906
- if (v > -1 && (o.current[v] = f), o.current.length === 2 && s.current) {
907
- const { diff: p, center: S } = dn(o.current), C = s.current.isZooming || ((Q, g) => Math.abs(Q - g.startDiff) > 30)(p, s.current), b = s.current.isMoving || C || ((Q, g) => Math.abs(na(Q, g.startCenter)) > 10)(S, s.current);
908
- s.current = { ...s.current, isMoving: b, isZooming: C }, h({ ...s.current, currentDiff: p, currentCenter: S });
943
+ }, [e]), le(() => {
944
+ if (!r) return;
945
+ const c = (p) => {
946
+ const m = a.current.findIndex((u) => u.pointerId === p.pointerId);
947
+ if (m > -1 && (a.current[m] = p), a.current.length === 2 && s.current) {
948
+ const { diff: u, center: S } = Mn(a.current), w = s.current.isZooming || ((b, y) => Math.abs(b - y.startDiff) > 30)(u, s.current), x = s.current.isMoving || w || ((b, y) => Math.abs(bo(b, y.startCenter)) > 10)(S, s.current);
949
+ s.current = { ...s.current, isMoving: x, isZooming: w }, h({ ...s.current, currentDiff: u, currentCenter: S });
909
950
  }
910
- }, u = (f) => {
911
- o.current = o.current.filter((v) => v.pointerId !== f.pointerId), r(o.current.length > 0);
951
+ }, f = (p) => {
952
+ a.current = a.current.filter((m) => m.pointerId !== p.pointerId), l(a.current.length > 0);
912
953
  };
913
- return document.addEventListener("pointermove", c), document.addEventListener("pointerup", u), document.addEventListener("pointerout", u), document.addEventListener("pointercancel", u), document.addEventListener("pointerleave", u), () => {
914
- document.removeEventListener("pointermove", c), document.removeEventListener("pointerup", u), document.removeEventListener("pointerout", u), document.removeEventListener("pointercancel", u), document.removeEventListener("pointerleave", u);
954
+ return document.addEventListener("pointermove", c), document.addEventListener("pointerup", f), document.addEventListener("pointerout", f), document.addEventListener("pointercancel", f), document.addEventListener("pointerleave", f), () => {
955
+ document.removeEventListener("pointermove", c), document.removeEventListener("pointerup", f), document.removeEventListener("pointerout", f), document.removeEventListener("pointercancel", f), document.removeEventListener("pointerleave", f);
915
956
  };
916
- }, [d, h]);
917
- }, cn = { offset: [0, 0], zoom: 1 }, wo = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: n }) => {
918
- const [a, o] = $(cn), d = ne(0), r = X((h) => {
919
- o(({ zoom: c }) => di({ zoom: c, size: t, canvasSize: e, newOffset: h }));
957
+ }, [r, h]);
958
+ }, Cn = { offset: [0, 0], zoom: 1 }, Ia = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: n }) => {
959
+ const [o, a] = K(Cn), r = re(0), l = X((h) => {
960
+ a(({ zoom: c }) => Mi({ zoom: c, size: t, canvasSize: e, newOffset: h }));
920
961
  }, [e, t]), s = X((h) => {
921
- o(({ offset: c, zoom: u }) => (({ size: f, canvasSize: v, currentOffset: p, currentZoom: S, action: C }) => {
922
- const b = C === "default" ? Pe[4] : C === "zoom" ? Pe[We(Pe.length - 1 - Pe.slice(0).reverse().findIndex((g) => g <= S) + 1, 0, Pe.length - 1)] : Pe[We(Pe.findIndex((g) => g >= S) - 1, 0, Pe.length - 1)], Q = [v.realWidth / 2, v.realHeight / 2];
923
- return ci({ size: f, canvasSize: v, currentOffset: p, currentZoom: S, zoom: b, centerPoint: Q });
924
- })({ size: t, canvasSize: e, currentOffset: c, currentZoom: u, action: h }));
962
+ a(({ offset: c, zoom: f }) => (({ size: p, canvasSize: m, currentOffset: u, currentZoom: S, action: w }) => {
963
+ const x = w === "default" ? Ie[4] : w === "zoom" ? Ie[et(Ie.length - 1 - Ie.slice(0).reverse().findIndex((y) => y <= S) + 1, 0, Ie.length - 1)] : Ie[et(Ie.findIndex((y) => y >= S) - 1, 0, Ie.length - 1)], b = [m.realWidth / 2, m.realHeight / 2];
964
+ return Ci({ size: p, canvasSize: m, currentOffset: u, currentZoom: S, zoom: x, centerPoint: b });
965
+ })({ size: t, canvasSize: e, currentOffset: c, currentZoom: f, action: h }));
925
966
  }, [e, t]);
926
- bo({ canvasElt: n, canvasTransformation: a, canvasSize: e, size: t, setCanvasTransformation: o });
927
- const l = X(() => {
928
- o(cn);
967
+ Ea({ canvasElt: n, canvasTransformation: o, canvasSize: e, size: t, setCanvasTransformation: a });
968
+ const d = X(() => {
969
+ a(Cn);
929
970
  }, []);
930
- return ee(() => {
971
+ return le(() => {
931
972
  if (!i || !n) return;
932
973
  const h = (c) => {
933
- const u = c.ctrlKey, { deltaX: f, deltaY: v } = ((b, Q) => {
934
- const g = Math.abs(b.deltaY) < 50 && Q < 50, w = b.ctrlKey, L = ea() && g && w;
935
- switch (b.deltaMode) {
974
+ const f = c.ctrlKey, { deltaX: p, deltaY: m } = ((x, b) => {
975
+ const y = Math.abs(x.deltaY) < 50 && b < 50, g = x.ctrlKey, P = mo() && y && g;
976
+ switch (x.deltaMode) {
936
977
  case WheelEvent.DOM_DELTA_LINE:
937
- return { deltaX: 16 * b.deltaX, deltaY: 16 * b.deltaY };
978
+ return { deltaX: 16 * x.deltaX, deltaY: 16 * x.deltaY };
938
979
  case WheelEvent.DOM_DELTA_PAGE:
939
- return { deltaX: b.deltaX * window.innerHeight, deltaY: b.deltaY * window.innerHeight };
980
+ return { deltaX: x.deltaX * window.innerHeight, deltaY: x.deltaY * window.innerHeight };
940
981
  default:
941
- return L ? { deltaX: 5 * b.deltaX, deltaY: 5 * b.deltaY } : { deltaX: b.deltaX, deltaY: b.deltaY };
982
+ return P ? { deltaX: 5 * x.deltaX, deltaY: 5 * x.deltaY } : { deltaX: x.deltaX, deltaY: x.deltaY };
942
983
  }
943
- })(c, c.timeStamp - d.current);
944
- if (d.current = c.timeStamp, u) {
984
+ })(c, c.timeStamp - r.current);
985
+ if (r.current = c.timeStamp, f) {
945
986
  c.preventDefault();
946
- const b = la(c, n, e);
947
- return void o(({ offset: Q, zoom: g }) => (({ size: w, canvasSize: L, currentOffset: D, currentZoom: V, delta: x, centerPoint: Z }) => {
948
- const A = We(V * (1 - x / 1e3), Pe[0], Pe[Pe.length - 1]);
949
- return ci({ size: w, canvasSize: L, currentOffset: D, currentZoom: V, zoom: A, centerPoint: Z });
950
- })({ size: t, canvasSize: e, currentOffset: Q, currentZoom: g, delta: v, centerPoint: b }));
987
+ const x = Co(c, n, e);
988
+ return void a(({ offset: b, zoom: y }) => (({ size: g, canvasSize: P, currentOffset: z, currentZoom: D, delta: A, centerPoint: H }) => {
989
+ const Z = et(D * (1 - A / 1e3), Ie[0], Ie[Ie.length - 1]);
990
+ return Ci({ size: g, canvasSize: P, currentOffset: z, currentZoom: D, zoom: Z, centerPoint: H });
991
+ })({ size: t, canvasSize: e, currentOffset: b, currentZoom: y, delta: m, centerPoint: x }));
951
992
  }
952
- const p = c.shiftKey, [S, C] = p ? [v, f] : [f, v];
953
- o(({ offset: b, zoom: Q }) => {
954
- const g = [b[0] - S / Q, b[1] - C / Q], w = di({ zoom: Q, size: t, canvasSize: e, newOffset: g });
955
- return w.offset[0] === b[0] && w.offset[1] === b[1] || c.preventDefault(), w;
993
+ const u = c.shiftKey, [S, w] = u ? [m, p] : [p, m];
994
+ a(({ offset: x, zoom: b }) => {
995
+ const y = [x[0] - S / b, x[1] - w / b], g = Mi({ zoom: b, size: t, canvasSize: e, newOffset: y });
996
+ return g.offset[0] === x[0] && g.offset[1] === x[1] || c.preventDefault(), g;
956
997
  });
957
998
  };
958
999
  return n.addEventListener("wheel", h, { passive: !1 }), () => {
959
1000
  n.removeEventListener("wheel", h);
960
1001
  };
961
- }, [n, t, e, i]), { setCanvasTransformation: o, setCanvasOffset: r, setCanvasZoom: s, resetZoom: l, canvasTransformation: a };
962
- }, hn = (e, t = !1) => {
963
- const i = (a, o) => {
964
- if (Array.isArray(a)) return o;
965
- }, n = e.map((a) => {
966
- if (typeof a != "object") return null;
967
- switch (a.type) {
1002
+ }, [n, t, e, i]), { setCanvasTransformation: a, setCanvasOffset: l, setCanvasZoom: s, resetZoom: d, canvasTransformation: o };
1003
+ }, Pn = (e, t = !1) => {
1004
+ const i = (o, a) => {
1005
+ if (Array.isArray(o)) return a;
1006
+ }, n = e.map((o) => {
1007
+ if (typeof o != "object") return null;
1008
+ switch (o.type) {
968
1009
  case "brush":
969
- return Ie(i, Wn, a);
1010
+ return Ke(i, eo, o);
970
1011
  case "circle":
971
- return Ie(i, Yn, a);
1012
+ return Ke(i, so, o);
972
1013
  case "curve":
973
- return Ie(i, Bn, a);
1014
+ return Ke(i, no, o);
974
1015
  case "ellipse":
975
- return Ie(i, Xn, a);
1016
+ return Ke(i, ro, o);
976
1017
  case "line":
977
- return Ie(i, Rn, a);
1018
+ return Ke(i, to, o);
978
1019
  case "polygon":
979
- return Ie(i, Nn, a);
1020
+ return Ke(i, io, o);
980
1021
  case "rect":
981
- return Ie(i, On, a);
1022
+ return Ke(i, oo, o);
982
1023
  case "square":
983
- return Ie(i, Fn, a);
1024
+ return Ke(i, ao, o);
984
1025
  case "text":
985
- return Ie(i, $n, a);
1026
+ return Ke(i, lo, o);
986
1027
  }
987
1028
  return null;
988
1029
  });
989
- return xi(t ? [...n, fi] : n);
990
- }, us = ({ width: e = 1e3, height: t = 600, shapes: i, mode: n = "editor", disabled: a = !1, options: o = Bi } = {}) => {
991
- const { layersManipulation: d, brushAlgo: r, isBrushShapeDoneOnMouseUp: s, debug: l, grid: h, canGrow: c, canShrink: u, withExport: f, withLoadAndSave: v, withUploadPicture: p, withUrlPicture: S, withSkeleton: C, withFrameSelection: b, clearCallback: Q, availableTools: g, canvasSelectionPadding: w, size: L, canZoom: D } = { ...Bi, ...o }, V = n !== "viewer", x = ne(null), Z = ne(null), A = ne(!1), H = X((ie) => {
992
- x.current = ie;
993
- }, []), [F, E] = $(void 0), [W, G] = $(Oe), [_, z] = $({ mode: "default" }), [y, M] = $(h), [P, T] = $({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), k = D === "always" && !a, { canvasTransformation: O, setCanvasTransformation: R, setCanvasOffset: B, setCanvasZoom: I, resetZoom: j } = wo({ canvasSize: P, size: L, canvasElt: Z.current, zoomEnabled: k }), { offset: de, zoom: se } = O, K = kn(() => ({ brushAlgo: r, isBrushShapeDoneOnMouseUp: s, debug: l, canvasSize: { realWidth: P.realWidth, realHeight: P.realHeight, width: P.width, height: P.height, scaleRatioWithNoZoom: P.scaleRatio, scaleRatio: P.scaleRatio * se }, size: L, canvasOffset: de, canvasZoom: se, gridGap: y, selectionPadding: w, features: { edition: V && !a, zoom: k } }), [w, y, r, s, l, se, de, P, L, a, k, V]), [N, ge] = $(hn(g, p || S)), { isInsideComponent: oe, isInsideCanvas: ye } = (({ settings: ie, componentRef: ce, canvasRef: He }) => {
994
- const [Ye, Xe] = $(!1), [je, Ke] = $(!1), be = !ie.features.edition && !ie.features.zoom;
995
- return ee(() => {
996
- if (!be) {
997
- const ze = () => Xe(!0), wt = () => Xe(!1), $e = () => Ke(!0), xt = () => Ke(!1);
998
- return ce.current?.addEventListener("focusin", ze), ce.current?.addEventListener("focusout", wt), He.current?.addEventListener("focusin", $e), He.current?.addEventListener("focusout", xt), () => {
999
- ce.current?.removeEventListener("focusin", ze), ce.current?.removeEventListener("focusout", wt), He.current?.removeEventListener("focusin", $e), He.current?.removeEventListener("focusout", xt);
1030
+ return Ni(t ? [...n, Ai] : n);
1031
+ }, Vs = ({ width: e = 1e3, height: t = 600, shapes: i, mode: n = "editor", disabled: o = !1, options: a = an } = {}) => {
1032
+ const { layersManipulation: r, brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: d, grid: h, canGrow: c, canShrink: f, withExport: p, withLoadAndSave: m, withUploadPicture: u, withUrlPicture: S, withSkeleton: w, withFrameSelection: x, withContextMenu: b, clearCallback: y, availableTools: g, canvasSelectionPadding: P, size: z, canZoom: D } = { ...an, ...a }, A = n !== "viewer", H = b && A && !o, Z = re(null), E = re(null), F = re(!1), W = X((ie) => {
1033
+ Z.current = ie;
1034
+ }, []), [I, oe] = K(void 0), [te, R] = K(Je), [$, j] = K({ mode: "default" }), [ce, Pe] = K(h), [L, _] = K({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), M = D === "always" && !o, { canvasTransformation: C, setCanvasTransformation: Q, setCanvasOffset: V, setCanvasZoom: N, resetZoom: k } = Ia({ canvasSize: L, size: z, canvasElt: E.current, zoomEnabled: M }), { offset: J, zoom: O } = C, T = Fn(() => ({ brushAlgo: l, isBrushShapeDoneOnMouseUp: s, debug: d, canvasSize: { realWidth: L.realWidth, realHeight: L.realHeight, width: L.width, height: L.height, scaleRatioWithNoZoom: L.scaleRatio, scaleRatio: L.scaleRatio * O }, size: z, canvasOffset: J, canvasZoom: O, gridGap: ce, selectionPadding: P, features: { edition: A && !o, zoom: M } }), [P, ce, l, s, d, O, J, L, z, o, M, A]), [ne, ye] = K(Pn(g, u || S)), { isInsideComponent: Y, isInsideCanvas: ze } = (({ settings: ie, componentRef: ue, canvasRef: He }) => {
1035
+ const [xe, Ve] = K(!1), [Ue, qe] = K(!1), Me = !ie.features.edition && !ie.features.zoom;
1036
+ return le(() => {
1037
+ if (!Me) {
1038
+ const Le = () => Ve(!0), Nt = () => Ve(!1), rt = () => qe(!0), Ot = () => qe(!1);
1039
+ return ue.current?.addEventListener("focusin", Le), ue.current?.addEventListener("focusout", Nt), He.current?.addEventListener("focusin", rt), He.current?.addEventListener("focusout", Ot), () => {
1040
+ ue.current?.removeEventListener("focusin", Le), ue.current?.removeEventListener("focusout", Nt), He.current?.removeEventListener("focusin", rt), He.current?.removeEventListener("focusout", Ot);
1000
1041
  };
1001
1042
  }
1002
- Xe(!1), Ke(!1);
1003
- }, [be, ce, He]), { isInsideComponent: Ye, isInsideCanvas: je };
1004
- })({ settings: K, componentRef: x, canvasRef: Z }), [Se, Qe] = $(!1), [te, ve] = $(!1), [U, ae] = $(!1), { registerEvent: Me, unregisterEvent: Ze, shapesRef: re, selectedShape: Te, selectionFrame: qe, hoveredShape: Ot, addShapes: De, addPictureShape: Ft, moveShapes: Yt, setSelectedShape: Ge, setSelectionFrame: Xt, refreshSelectedShapes: $t, refreshHoveredShape: Ut, duplicateShapes: fe, removeShape: me, updateShape: gt, backwardShape: Fe, forwardShape: at, clearShapes: Mi, saveShapes: Pi, toggleShapeVisibility: wa, toggleShapeLock: xa, canGoBackward: Ca, canGoForward: Ma, canClear: Pa } = Qo(K, e, t, Se), qt = X((ie) => {
1005
- Ge(void 0), G(ie);
1006
- }, [Ge]), [ot, ki] = $([0, 0]), Li = _.mode === "preview";
1007
- ee(() => {
1008
- if (Li) return () => z((ie) => ie.mode === "preview" ? { mode: "default" } : ie);
1009
- }, [Te?.id, Li]);
1010
- const Vi = _.mode === "selectionFrame";
1011
- ee(() => {
1012
- if (Vi) return () => ki([0, 0]);
1013
- }, [Vi]), ee(() => {
1014
- if (ot[0] !== 0 || ot[1] !== 0) {
1043
+ Ve(!1), qe(!1);
1044
+ }, [Me, ue, He]), { isInsideComponent: xe, isInsideCanvas: Ue };
1045
+ })({ settings: T, componentRef: Z, canvasRef: E }), [ge, Oe] = K(!1), [Ye, he] = K(!1), [Se, ae] = K(!1), { registerEvent: fe, unregisterEvent: ee, shapesRef: se, selectedShape: pe, selectionFrame: ke, hoveredShape: Be, copiedShape: Ee, setCopiedShape: we, addShapes: Fe, addPictureShape: bt, moveShapes: Qt, swapShapes: dt, setSelectedShape: $e, setSelectionFrame: wt, refreshSelectedShapes: xt, refreshHoveredShape: Ae, duplicateShapes: at, removeShape: st, updateShape: je, backwardShape: ct, forwardShape: ht, clearShapes: pt, saveShapes: ve, toggleShapeVisibility: be, toggleShapeLock: B, transformShape: nt, canGoBackward: Tt, canGoForward: Oo, canClear: Bo } = Da(T, e, t, ge), li = X((ie) => {
1046
+ $e(void 0), R(ie);
1047
+ }, [$e]), [Mt, Bi] = K([0, 0]), Fi = $.mode === "preview";
1048
+ le(() => {
1049
+ if (Fi) return () => j((ie) => ie.mode === "preview" ? { mode: "default" } : ie);
1050
+ }, [pe?.id, Fi]);
1051
+ const Yi = $.mode === "selectionFrame";
1052
+ le(() => {
1053
+ if (Yi) return () => Bi([0, 0]);
1054
+ }, [Yi]), le(() => {
1055
+ if (Mt[0] !== 0 || Mt[1] !== 0) {
1015
1056
  const ie = setInterval(() => {
1016
- R(({ offset: ce, zoom: He }) => {
1017
- const Ye = [ce[0] - ot[0], ce[1] - ot[1]];
1018
- return di({ zoom: He, size: L, canvasSize: P, newOffset: Ye });
1057
+ Q(({ offset: ue, zoom: He }) => {
1058
+ const xe = [ue[0] - Mt[0], ue[1] - Mt[1]];
1059
+ return Mi({ zoom: He, size: z, canvasSize: L, newOffset: xe });
1019
1060
  });
1020
1061
  }, 20);
1021
1062
  return () => clearInterval(ie);
1022
1063
  }
1023
- }, [ot[0], ot[1], R, L, P]);
1024
- const bt = X((ie, ce) => {
1025
- Mi(ie, ce), qt(Oe), R({ offset: [0, 0], zoom: 1 });
1026
- }, [qt, Mi, R]), Zi = X((ie) => {
1027
- Ge((ce) => (ce?.id !== ie.map((He) => He.id).join("-") && G(Oe), pe(ie, K)));
1028
- }, [Ge, K]), ka = X(() => {
1029
- const ie = yo(re.current, e, t);
1064
+ }, [Mt[0], Mt[1], Q, z, L]);
1065
+ const Wt = X((ie, ue) => {
1066
+ pt(ie, ue), li(Je), Q({ offset: [0, 0], zoom: 1 });
1067
+ }, [li, pt, Q]), Ct = X((ie) => {
1068
+ $e((ue) => (ue?.id !== ie.map((He) => He.id).join("-") && R(Je), de(ie, T)));
1069
+ }, [$e, T]), Xi = X((ie) => {
1070
+ Fe(ie), Ct(ie);
1071
+ }, [Fe, Ct]), $i = X(() => {
1072
+ Ct(se.current);
1073
+ }, [Ct, se]), Fo = X(() => {
1074
+ const ie = Ha(se.current, e, t);
1030
1075
  if (!ie) throw new Error("L'encodage a échoué");
1031
- sn(ie, "drawing.json");
1032
- }, [re, e, t]), La = X((ie) => {
1033
- const ce = rn({ shapes: re.current, settings: K, view: ie });
1034
- sn(ce, "drawing.png");
1035
- }, [re, K]), Va = X((ie) => rn({ shapes: re.current, settings: K, view: ie }), [re, K]), Za = X(() => Ci(re.current, e, t), [re, e, t]), _e = X(async (ie, ce) => {
1036
- const He = await (async (Ye, Xe) => {
1037
- if (!Ye) return [];
1038
- const je = [], Ke = xi(Ye.map((be) => {
1039
- if (!be || !_n.includes(be.type)) return null;
1040
- if (be.type === "picture") {
1041
- const ze = new Image(), wt = new Promise(($e, xt) => {
1042
- ze.onload = () => {
1043
- URL.revokeObjectURL(ze.src), $e();
1044
- }, ze.onerror = () => {
1045
- xt(new Error("Some images could not be loaded"));
1076
+ Qn(ie, "drawing.json");
1077
+ }, [se, e, t]), Yo = X((ie) => {
1078
+ const ue = wn({ shapes: se.current, settings: T, view: ie });
1079
+ Qn(ue, "drawing.png");
1080
+ }, [se, T]), Xo = X((ie) => wn({ shapes: se.current, settings: T, view: ie }), [se, T]), $o = X(() => Oi(se.current, e, t), [se, e, t]), ut = X(async (ie, ue) => {
1081
+ const He = await (async (xe, Ve) => {
1082
+ if (!xe) return [];
1083
+ const Ue = [], qe = Ni(xe.map((Me) => {
1084
+ if (!Me || !uo.includes(Me.type)) return null;
1085
+ if (Me.type === "picture") {
1086
+ const Le = new Image(), Nt = new Promise((rt, Ot) => {
1087
+ Le.onload = () => {
1088
+ URL.revokeObjectURL(Le.src), rt();
1089
+ }, Le.onerror = () => {
1090
+ Ot(new Error("Some images could not be loaded"));
1046
1091
  };
1047
1092
  });
1048
- if (je.push(wt), be.src.startsWith("http")) Qa(be.src).then(($e) => {
1049
- ze.src = $e;
1093
+ if (Ue.push(Nt), Me.src.startsWith("http")) Ro(Me.src).then((rt) => {
1094
+ Le.src = rt;
1050
1095
  }).catch(() => {
1051
- ze.src = "";
1096
+ Le.src = "";
1052
1097
  });
1053
- else if (be.src.includes("<svg")) {
1054
- const $e = new Blob([be.src], { type: "image/svg+xml" });
1055
- ze.src = URL.createObjectURL($e);
1056
- } else ze.src = be.src;
1057
- return ln({ ...be, img: ze }, Xe);
1098
+ else if (Me.src.includes("<svg")) {
1099
+ const rt = new Blob([Me.src], { type: "image/svg+xml" });
1100
+ Le.src = URL.createObjectURL(rt);
1101
+ } else Le.src = Me.src;
1102
+ return xn({ ...Me, img: Le }, Ve);
1058
1103
  }
1059
- return ln(be, Xe);
1104
+ return xn(Me, Ve);
1060
1105
  }));
1061
- return await Promise.all(je), Ke;
1062
- })(ie, K);
1063
- bt(He, ce);
1064
- }, [bt, K]), Gt = ne(_e);
1065
- Gt.current = _e;
1066
- const Ha = X((ie = [], ce = !0) => {
1067
- Gt.current?.(ie, { clearHistory: ce, source: "remote" });
1106
+ return await Promise.all(Ue), qe;
1107
+ })(ie, T);
1108
+ Wt(He, ue);
1109
+ }, [Wt, T]), di = re(ut);
1110
+ di.current = ut;
1111
+ const Uo = X((ie = [], ue = !0) => {
1112
+ di.current?.(ie, { clearHistory: ue, source: "remote" });
1068
1113
  }, []);
1069
- ee(() => {
1070
- A.current || (A.current = !0, i && Gt.current?.(i, { clearHistory: !0, source: "remote" }));
1114
+ le(() => {
1115
+ F.current || (F.current = !0, i && di.current?.(i, { clearHistory: !0, source: "remote" }));
1071
1116
  }, [i]);
1072
- const za = X(async (ie) => {
1073
- const ce = await (async (He) => new Promise((Ye, Xe) => {
1074
- const je = new FileReader();
1075
- je.onload = (Ke) => {
1076
- const be = Ke.target?.result;
1077
- if (!be) return Xe("Impossible de récupérer les données du fichier");
1078
- const ze = JSON.parse(be);
1079
- Ye(ze);
1080
- }, je.readAsText(He);
1117
+ const qo = X(async (ie) => {
1118
+ const ue = await (async (He) => new Promise((xe, Ve) => {
1119
+ const Ue = new FileReader();
1120
+ Ue.onload = (qe) => {
1121
+ const Me = qe.target?.result;
1122
+ if (!Me) return Ve("Impossible de récupérer les données du fichier");
1123
+ const Le = JSON.parse(Me);
1124
+ xe(Le);
1125
+ }, Ue.readAsText(He);
1081
1126
  }))(ie);
1082
- await _e(ce.shapes ?? [], { clearHistory: !0, source: "remote" });
1083
- }, [_e]), Ta = X(() => {
1084
- typeof Q != "string" ? _e(Q(), { clearHistory: !1, source: "user" }) : Q === "defaultShapes" && i !== void 0 ? _e(i, { clearHistory: !1, source: "user" }) : bt([], { clearHistory: !1, source: "user" });
1085
- }, [bt, _e, i, Q]);
1086
- ee(() => {
1087
- ge(hn(g, p || S));
1088
- }, [g, p, S]);
1089
- const Hi = { canvas: Z, editor: x, setEditor: H };
1090
- return { annotationsProps: { style: { userSelect: "none", touchAction: "none", transformOrigin: "left top", transform: "scale(var(--react-paint-canvas-zoom)) translate(calc(var(--react-paint-canvas-offset-x) * 100% / var(--react-paint-app-canvaswidth)), calc(var(--react-paint-canvas-offset-y) * 100% / var(--react-paint-app-canvasheight)))", "--react-paint-canvas-zoom": K.canvasZoom, "--react-paint-canvas-offset-x": K.canvasOffset[0], "--react-paint-canvas-offset-y": K.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: re, addPictureShape: Ft, moveShapes: Yt, toggleShapeVisibility: wa, toggleShapeLock: xa, canGoBackward: Ca, canGoForward: Ma, canClear: Pa, selectedShape: Te, saveShapes: Pi, removeShape: me, updateShape: gt, backwardShape: Fe, forwardShape: at, refs: Hi, width: e, height: t, selectTool: qt, selectShapes: Zi, activeTool: W, setActiveTool: G, setAvailableTools: ge, isEditMode: V, availableTools: N, gridGap: y, setGridGap: M, loadFile: za, exportPicture: La, exportData: ka, clearCanvas: Ta, settings: K, setCanvasZoom: I, resetZoom: j, canvas: { canGrow: c, canShrink: u, layersManipulation: d, withExport: f, withLoadAndSave: v, withUploadPicture: p, withUrlPicture: S } }, canvasProps: { shapesRef: re, selectedShape: Te, selectionFrame: qe, hoveredShape: Ot, addShape: De, setSelectedShape: Ge, setSelectionFrame: Xt, refreshSelectedShapes: $t, refreshHoveredShape: Ut, removeShape: me, updateShape: gt, duplicateShapes: fe, backwardShape: Fe, forwardShape: at, saveShapes: Pi, refs: Hi, width: e, height: t, settings: K, setCanvasSize: T, setCanvasOffset: B, setCanvasZoom: I, resetZoom: j, selectShapes: Zi, activeTool: W, setActiveTool: G, isInsideComponent: oe, isInsideCanvas: ye, isEditMode: V, canvas: { withSkeleton: C, withFrameSelection: b, canGrow: c, canShrink: u }, canvasOffsetStartData: F, setCanvasOffsetStartData: E, selectionMode: _, setSelectionMode: z, setCanvasMoveAcceleration: ki, isShiftPressed: Se, isAltPressed: te, isSpacePressed: U, setShiftPressed: Qe, setAltPressed: ve, setIsSpacePressed: ae }, registerEvent: Me, unregisterEvent: Ze, resetCanvas: Ha, resetZoom: j, getCurrentImage: Va, getCurrentData: Za, setCanvasOffset: B, setCanvasZoom: I };
1091
- }, xo = ({ addShapes: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: n, shapes: a, selectionMode: o, activeTool: d, isInsideComponent: r, setCanvasOffset: s, selectedShape: l, canvasOffsetStartData: h, refreshSelectedShapes: c, setSelectedShape: u, setSelectionFrame: f, setCanvasOffsetStartData: v, updateSingleShape: p, duplicateShapes: S, saveShapes: C, setSelectionMode: b, setCanvasMoveAcceleration: Q, settings: g, isShiftPressed: w, isAltPressed: L, withFrameSelection: D, isSpacePressed: V }) => {
1092
- const [x, Z] = $({ mode: "default" }), { registerDoubleClickEvent: A, unRegisterDoubleClickEvent: H } = (() => {
1093
- const y = ne(void 0), M = ne(void 0), P = (T) => {
1094
- const k = Date.now();
1095
- y.current && k < y.current + 300 && M.current?.(T), y.current = Date.now();
1127
+ await ut(ue.shapes ?? [], { clearHistory: !0, source: "remote" });
1128
+ }, [ut]), Go = X(() => {
1129
+ typeof y != "string" ? ut(y(), { clearHistory: !1, source: "user" }) : y === "defaultShapes" && i !== void 0 ? ut(i, { clearHistory: !1, source: "user" }) : Wt([], { clearHistory: !1, source: "user" });
1130
+ }, [Wt, ut, i, y]), _o = X((ie, ue) => {
1131
+ const He = ie.type === "curve" ? ((xe, Ve, Ue) => {
1132
+ if (Ve < 0 || Ve > xe.points.length - 1) return xe;
1133
+ const qe = { ...xe, points: xe.points.filter((Me, Le) => Le !== Ve) };
1134
+ return Ht(qe, Ue);
1135
+ })(ie, ue, T) : ((xe, Ve, Ue) => {
1136
+ if (Ve < 0 || Ve > xe.points.length - 1) return xe;
1137
+ const qe = { ...xe, points: xe.points.filter((Me, Le) => Le !== Ve) };
1138
+ return At(qe, Ue);
1139
+ })(ie, ue, T);
1140
+ je([He], !0);
1141
+ }, [T, je]);
1142
+ le(() => {
1143
+ ye(Pn(g, u || S));
1144
+ }, [g, u, S]);
1145
+ const Ui = { canvas: E, editor: Z, setEditor: W };
1146
+ 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": T.canvasZoom, "--react-paint-canvas-offset-x": T.canvasOffset[0], "--react-paint-canvas-offset-y": T.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: se, addPictureShape: bt, moveShapes: Qt, swapShapes: dt, toggleShapeVisibility: be, toggleShapeLock: B, duplicateShapes: at, canGoBackward: Tt, canGoForward: Oo, canClear: Bo, selectedShape: pe, copiedShape: Ee, setCopiedShape: we, pasteShapes: Xi, saveShapes: ve, removeShape: st, updateShape: je, backwardShape: ct, forwardShape: ht, removeShapePoint: _o, transformShape: nt, refs: Ui, width: e, height: t, selectTool: li, selectShapes: Ct, selectAllShapes: $i, activeTool: te, setActiveTool: R, setAvailableTools: ye, isEditMode: A, availableTools: ne, gridGap: ce, setGridGap: Pe, loadFile: qo, exportPicture: Yo, exportData: Fo, clearCanvas: Go, selectionMode: $, setSelectionMode: j, settings: T, setCanvasZoom: N, resetZoom: k, canvas: { canGrow: c, canShrink: f, layersManipulation: r, withExport: p, withLoadAndSave: m, withUploadPicture: u, withUrlPicture: S, withContextMenu: H } }, canvasProps: { shapesRef: se, selectedShape: pe, selectionFrame: ke, hoveredShape: Be, copiedShape: Ee, pasteShapes: Xi, setCopiedShape: we, addShape: Fe, setSelectedShape: $e, setSelectionFrame: wt, refreshSelectedShapes: xt, refreshHoveredShape: Ae, removeShape: st, updateShape: je, duplicateShapes: at, backwardShape: ct, forwardShape: ht, saveShapes: ve, refs: Ui, width: e, height: t, settings: T, setCanvasSize: _, setCanvasOffset: V, setCanvasZoom: N, resetZoom: k, selectShapes: Ct, selectAllShapes: $i, activeTool: te, setActiveTool: R, isInsideComponent: Y, isInsideCanvas: ze, isEditMode: A, canvas: { withSkeleton: w, withFrameSelection: x, withContextMenu: H, canGrow: c, canShrink: f }, canvasOffsetStartData: I, setCanvasOffsetStartData: oe, selectionMode: $, setSelectionMode: j, setCanvasMoveAcceleration: Bi, isShiftPressed: ge, isAltPressed: Ye, isSpacePressed: Se, setShiftPressed: Oe, setAltPressed: he, setIsSpacePressed: ae }, registerEvent: fe, unregisterEvent: ee, resetCanvas: Uo, resetZoom: k, getCurrentImage: Xo, getCurrentData: $o, setCanvasOffset: V, setCanvasZoom: N };
1147
+ }, Ra = ({ addShapes: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: n, shapes: o, selectionMode: a, activeTool: r, isInsideComponent: l, isInsideCanvas: s, setCanvasOffset: d, selectedShape: h, canvasOffsetStartData: c, refreshSelectedShapes: f, setSelectedShape: p, setSelectionFrame: m, setCanvasOffsetStartData: u, updateSingleShape: S, duplicateShapes: w, saveShapes: x, setSelectionMode: b, setCanvasMoveAcceleration: y, settings: g, isShiftPressed: P, isAltPressed: z, withFrameSelection: D, withContextMenu: A, isSpacePressed: H }) => {
1148
+ const Z = re(null), [E, F] = K({ mode: "default" }), { registerDoubleClickEvent: W, unRegisterDoubleClickEvent: I } = (() => {
1149
+ const L = re(void 0), _ = re(void 0), M = (C) => {
1150
+ const Q = Date.now();
1151
+ L.current && Q < L.current + 300 && _.current?.(C), L.current = Date.now();
1096
1152
  };
1097
- return { registerDoubleClickEvent: (T, k) => {
1098
- M.current = k, T.addEventListener("click", P), T.addEventListener("touchend", P);
1099
- }, unRegisterDoubleClickEvent: (T) => {
1100
- T.removeEventListener("click", P), T.removeEventListener("touchend", P);
1153
+ return { registerDoubleClickEvent: (C, Q) => {
1154
+ _.current = Q, C.addEventListener("click", M), C.addEventListener("touchend", M);
1155
+ }, unRegisterDoubleClickEvent: (C) => {
1156
+ C.removeEventListener("click", M), C.removeEventListener("touchend", M);
1101
1157
  } };
1102
- })(), F = ne(null);
1103
- F.current = (y) => ((M, P, T, k, O, R, B, I, j, de, se, K, N, ge, oe, ye, Se) => {
1104
- if (rt(M) && M.touches.length > 1) return;
1105
- const Qe = P.current?.getContext("2d");
1106
- if (!Qe) return;
1107
- const te = st(M, P.current, N);
1108
- if (k.mode === "selectionFrame") {
1109
- K(Qe, te, N);
1110
- const U = la(M, P.current, N.canvasSize);
1111
- return void Se([Math.ceil(We(U[0] * N.canvasZoom < 50 ? U[0] * N.canvasZoom - 50 : U[0] * N.canvasZoom > N.canvasSize.width / N.canvasSize.scaleRatioWithNoZoom - 50 ? U[0] * N.canvasZoom - (N.canvasSize.width / N.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / N.canvasZoom), Math.ceil(We(U[1] * N.canvasZoom < 50 ? U[1] * N.canvasZoom - 50 : U[1] * N.canvasZoom > N.canvasSize.height / N.canvasSize.scaleRatioWithNoZoom - 50 ? U[1] * N.canvasZoom - (N.canvasSize.height / N.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / N.canvasZoom)]);
1158
+ })(), oe = (L, _) => {
1159
+ const M = _?.getContext("2d");
1160
+ if (M) {
1161
+ if (r === Je && A) {
1162
+ const C = ft(L, t.current, g), { shape: Q, mode: V } = Bt(M, o, C, g, h, ot(L), !1);
1163
+ p(Q), b({ mode: "contextMenu", cursorStartPosition: C, originalShape: Q, anchor: "anchor" in V ? V.anchor : void 0 });
1164
+ } else p(void 0), b({ mode: "default" });
1165
+ i(Je), m(void 0);
1166
+ }
1167
+ }, te = re(null);
1168
+ te.current = (L) => ((_, M, C, Q, V, N, k, J, O, T, ne, ye, Y, ze, ge, Oe, Ye, he) => {
1169
+ if (he && clearTimeout(he), ot(_) && _.touches.length > 1) return;
1170
+ const Se = M.current?.getContext("2d");
1171
+ if (!Se) return;
1172
+ const ae = ft(_, M.current, Y);
1173
+ if (Q.mode === "selectionFrame") {
1174
+ ye(Se, ae, Y);
1175
+ const ee = Co(_, M.current, Y.canvasSize);
1176
+ return void Ye([Math.ceil(et(ee[0] * Y.canvasZoom < 50 ? ee[0] * Y.canvasZoom - 50 : ee[0] * Y.canvasZoom > Y.canvasSize.width / Y.canvasSize.scaleRatioWithNoZoom - 50 ? ee[0] * Y.canvasZoom - (Y.canvasSize.width / Y.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / Y.canvasZoom), Math.ceil(et(ee[1] * Y.canvasZoom < 50 ? ee[1] * Y.canvasZoom - 50 : ee[1] * Y.canvasZoom > Y.canvasSize.height / Y.canvasSize.scaleRatioWithNoZoom - 50 ? ee[1] * Y.canvasZoom - (Y.canvasSize.height / Y.canvasSize.scaleRatioWithNoZoom - 50) : 0, -100, 100) / 5 / Y.canvasZoom)]);
1112
1177
  }
1113
- if (R !== void 0) return void se([te[0] + N.canvasOffset[0] - R.start[0], te[1] + N.canvasOffset[1] - R.start[1]]);
1114
- if (k.mode === "preview") {
1115
- const U = Y(T)[0];
1116
- if (U?.type === "curve") {
1117
- const ae = Ki(U, te, N, !0);
1118
- return void ye(pe([ae], N));
1178
+ if (N !== void 0) return void ne([ae[0] + Y.canvasOffset[0] - N.start[0], ae[1] + Y.canvasOffset[1] - N.start[1]]);
1179
+ if (Q.mode === "preview") {
1180
+ const ee = U(C)[0];
1181
+ if (ee?.type === "curve") {
1182
+ const se = gn(ee, ae, Y, !0);
1183
+ return void Oe(de([se], Y));
1119
1184
  }
1120
- if (U?.type === "polygon") {
1121
- const ae = ji(U, te, N, !0);
1122
- return void ye(pe([ae], N));
1185
+ if (ee?.type === "polygon") {
1186
+ const se = un(ee, ae, Y, !0);
1187
+ return void Oe(de([se], Y));
1123
1188
  }
1124
1189
  }
1125
- const ve = vt(te, N);
1126
- if (rt(M) || I(M, Qe, te, ve), T === void 0 || T.locked) B({ mode: "default", outOfView: !ve });
1190
+ const fe = Dt(ae, Y);
1191
+ if (ot(_) || J(_, Se, ae, fe), C === void 0 || C.locked) k({ mode: "default", outOfView: !fe });
1127
1192
  else {
1128
- if (k.mode === "default" || k.mode === "textedition") {
1129
- if (!ve) return void B({ mode: "default" });
1130
- B(ft(Qe, T, te, N, !0) || { mode: "default" });
1193
+ if (Q.mode === "default" || Q.mode === "textedition" || Q.mode === "contextMenu") {
1194
+ if (!fe) return void k({ mode: "default" });
1195
+ k(Et(Se, C, ae, Y, !0) || { mode: "default" });
1131
1196
  } else {
1132
- const U = P.current?.getContext("2d");
1133
- if (!U) return;
1134
- const ae = Na(U, T, te, k, N, ge, oe);
1135
- j(Y(ae));
1197
+ const ee = M.current?.getContext("2d");
1198
+ if (!ee) return;
1199
+ const se = na(ee, C, ae, Q, Y, ze, ge);
1200
+ O(U(se));
1136
1201
  }
1137
- k.mode === "translate" && oe && !k.hasBeenDuplicated && (O({ ...k, hasBeenDuplicated: !0 }), de(Y(k.originalShape)));
1202
+ Q.mode === "translate" && ge && !Q.hasBeenDuplicated && (V({ ...Q, hasBeenDuplicated: !0 }), T(U(Q.originalShape)));
1138
1203
  }
1139
- })(y, t, l, o, b, h, Z, n, p, S, s, c, g, w, L, u, Q), ee(() => {
1140
- if (r) {
1141
- const y = (M) => F.current?.(M);
1142
- return document.addEventListener("mousemove", y), document.addEventListener("touchmove", y), () => {
1143
- document.removeEventListener("mousemove", y), document.removeEventListener("touchmove", y);
1204
+ })(L, t, h, a, b, c, F, n, S, w, d, f, g, P, z, p, y, Z.current), le(() => {
1205
+ if (l) {
1206
+ const L = (_) => te.current?.(_);
1207
+ return document.addEventListener("mousemove", L), document.addEventListener("touchmove", L), () => {
1208
+ document.removeEventListener("mousemove", L), document.removeEventListener("touchmove", L);
1144
1209
  };
1145
1210
  }
1146
- }, [r]);
1147
- const { isBrushShapeDoneOnMouseUp: E } = g, W = ne(null);
1148
- W.current = (y) => {
1149
- if (rt(y) && y.touches.length > 1) return;
1150
- const M = t.current?.getContext("2d");
1151
- if (!M) return;
1152
- if ("button" in y && y.button === 2) return u(void 0), i(Oe), b({ mode: "default" }), void f(void 0);
1153
- if (h) return void v(void 0);
1154
- if (o.mode === "textedition" || o.mode === "preview") return;
1155
- const P = st(y, t.current, g);
1156
- if (o.mode === "translate" && Date.now() - o.dateStart <= 500 && P[0] === o.cursorStartPosition[0] && P[1] === o.cursorStartPosition[1]) {
1157
- if (y.ctrlKey || y.shiftKey || y.metaKey) {
1158
- const { shape: T } = Ui(M, a, P, g, l, rt(y), D, "remove");
1159
- Y(T).length !== o.selectedShapesLengthAtMouseDown && u(T);
1211
+ }, [l]);
1212
+ const { isBrushShapeDoneOnMouseUp: R } = g, $ = re(null);
1213
+ $.current = (L) => {
1214
+ if (Z.current && clearTimeout(Z.current), ot(L) && L.touches.length > 1) return;
1215
+ const _ = t.current?.getContext("2d");
1216
+ if (!_) return;
1217
+ if ("button" in L && L.button === 2) return void oe(L, t.current);
1218
+ if (c) return void u(void 0);
1219
+ if (a.mode === "contextMenu" || a.mode === "textedition" || a.mode === "preview") return;
1220
+ const M = ft(L, t.current, g);
1221
+ if (a.mode === "translate" && Date.now() - a.dateStart <= 500 && M[0] === a.cursorStartPosition[0] && M[1] === a.cursorStartPosition[1]) {
1222
+ if (L.ctrlKey || L.shiftKey || L.metaKey) {
1223
+ const { shape: C } = Bt(_, o, M, g, h, ot(L), D, "remove");
1224
+ U(C).length !== a.selectedShapesLengthAtMouseDown && p(C);
1160
1225
  }
1161
- return b({ mode: "default" }), f(void 0), void C();
1226
+ return b({ mode: "default" }), m(void 0), void x();
1162
1227
  }
1163
- o.mode !== "default" && (o.mode === "brush" && E && u(void 0), b({ mode: "default" }), f(void 0), C());
1164
- }, ee(() => {
1165
- if (r) {
1166
- const y = (M) => W.current?.(M);
1167
- return document.addEventListener("mouseup", y), document.addEventListener("touchend", y), () => {
1168
- document.removeEventListener("mouseup", y), document.removeEventListener("touchend", y);
1228
+ a.mode !== "default" && (a.mode === "brush" && R && p(void 0), b({ mode: "default" }), m(void 0), x());
1229
+ }, le(() => {
1230
+ if (s) {
1231
+ const L = (_) => $.current?.(_);
1232
+ return document.addEventListener("mouseup", L), document.addEventListener("touchend", L), () => {
1233
+ document.removeEventListener("mouseup", L), document.removeEventListener("touchend", L);
1169
1234
  };
1170
1235
  }
1171
- }, [r]);
1172
- const G = !g.features.edition && g.features.zoom, _ = !g.features.edition && !g.features.zoom, z = ne(null);
1173
- return z.current = (y, M, P) => {
1174
- if (y.preventDefault(), rt(y) && y.touches.length > 1) return;
1175
- const T = M?.getContext("2d");
1176
- if (!T) return;
1177
- M.focus();
1178
- const k = st(y, t.current, g), O = "button" in y && y.button === 1;
1179
- if (!("button" in y && y.button === 2)) {
1180
- if (O || P || d.type === "move") v({ start: k, originalOffset: g.canvasOffset });
1181
- else if (!G) {
1182
- if (!vt(k, g)) return u(void 0), void b({ mode: "default" });
1183
- if (d.type === "selection") {
1184
- const R = y.ctrlKey || y.shiftKey || y.metaKey ? "add" : "replace", { shape: B, mode: I } = Ui(T, a, k, g, l, rt(y), D, R);
1185
- u(B), b(I), I.mode === "selectionFrame" && f({ oldSelection: B, frame: [[k[0], k[1]], [k[0], k[1]]] });
1186
- } else if (_n.some((R) => R === d.type)) {
1187
- const R = Y(l)[0], B = t.current?.getContext("2d");
1188
- if (!B) return;
1189
- if (d.type === "brush") {
1190
- if (R?.type === "brush") {
1191
- const I = ((j, de, se) => {
1192
- const K = { ...j, points: Le(j.points.length, [[Math.round(de[0]), Math.round(de[1])]], j.points) };
1193
- return ut(K, se);
1194
- })(R, k, g);
1195
- p([I]);
1196
- } else {
1197
- const I = tn(B, d, k, g);
1198
- if (!I) return;
1199
- e([I]), u(pe([I], g));
1200
- }
1201
- b({ mode: "brush" });
1202
- } else if (o.mode !== "preview" || R?.type !== "polygon" && R?.type !== "curve") {
1203
- if (d.type !== "picture") {
1204
- const I = tn(B, d, k, g);
1205
- if (!I) return;
1206
- e([I]);
1207
- const j = pe([I], g);
1208
- u(j), I.type === "polygon" || I.type === "curve" ? b({ mode: "preview" }) : (i(Oe), b({ mode: "resize", cursorStartPosition: [k[0] + g.selectionPadding, k[1] + g.selectionPadding], originalShape: j, anchor: I.type === "line" ? 0 : [1, 1], selectedShapesLengthAtMouseDown: Y(j).length }));
1209
- }
1236
+ }, [s]);
1237
+ const j = !g.features.edition && g.features.zoom, ce = !g.features.edition && !g.features.zoom, Pe = re(null);
1238
+ return Pe.current = (L, _, M) => {
1239
+ if (L.preventDefault(), ot(L) && L.touches.length > 1) return;
1240
+ const C = _?.getContext("2d");
1241
+ if (!C) return;
1242
+ _.focus();
1243
+ const Q = ft(L, t.current, g), V = "button" in L && L.button === 1, N = "button" in L && L.button === 2;
1244
+ if (V || M || r.type === "move" && !N) u({ start: Q, originalOffset: g.canvasOffset });
1245
+ else if (!j) {
1246
+ if (!Dt(Q, g)) return p(void 0), void b({ mode: "default" });
1247
+ if (N) {
1248
+ if (r.type === "selection") {
1249
+ const { shape: k } = Bt(C, o, Q, g, h, ot(L), !1);
1250
+ p(k), b({ mode: "default" });
1251
+ }
1252
+ } else if (ot(L) && (Z.current && clearTimeout(Z.current), Z.current = setTimeout(() => {
1253
+ oe(L, t.current);
1254
+ }, 500)), r.type === "selection") {
1255
+ const k = L.ctrlKey || L.shiftKey || L.metaKey ? "add" : "replace", { shape: J, mode: O } = Bt(C, o, Q, g, h, ot(L), D, k);
1256
+ p(J), b(O), O.mode === "selectionFrame" && m({ oldSelection: J, frame: [[Q[0], Q[1]], [Q[0], Q[1]]] });
1257
+ } else if (uo.some((k) => k === r.type)) {
1258
+ const k = U(h)[0], J = t.current?.getContext("2d");
1259
+ if (!J) return;
1260
+ if (r.type === "brush") {
1261
+ if (k?.type === "brush") {
1262
+ const O = ((T, ne, ye) => {
1263
+ const Y = { ...T, points: Xe(T.points.length, [[Math.round(ne[0]), Math.round(ne[1])]], T.points) };
1264
+ return Zt(Y, ye);
1265
+ })(k, Q, g);
1266
+ S([O]);
1210
1267
  } else {
1211
- const I = R.type === "polygon" ? ji(R, k, g) : Ki(R, k, g);
1212
- u(pe([I], g)), p([I], !0);
1268
+ const O = mn(J, r, Q, g);
1269
+ if (!O) return;
1270
+ e([O]), p(de([O], g));
1213
1271
  }
1272
+ b({ mode: "brush" });
1273
+ } else if (a.mode !== "preview" || k?.type !== "polygon" && k?.type !== "curve") {
1274
+ if (r.type !== "picture") {
1275
+ const O = mn(J, r, Q, g);
1276
+ if (!O) return;
1277
+ e([O]);
1278
+ const T = de([O], g);
1279
+ p(T), O.type === "polygon" || O.type === "curve" ? b({ mode: "preview" }) : (i(Je), b({ mode: "resize", cursorStartPosition: [Q[0] + g.selectionPadding, Q[1] + g.selectionPadding], originalShape: T, anchor: O.type === "line" ? 0 : [1, 1], selectedShapesLengthAtMouseDown: U(T).length }));
1280
+ }
1281
+ } else {
1282
+ const O = k.type === "polygon" ? un(k, Q, g) : gn(k, Q, g);
1283
+ p(de([O], g)), S([O], !0);
1214
1284
  }
1215
1285
  }
1216
1286
  }
1217
- }, ee(() => {
1218
- if (_) return;
1219
- const y = t.current;
1220
- if (!y) return;
1221
- const M = (P) => z.current?.(P, y, V);
1222
- return y.addEventListener("mousedown", M, { passive: !1 }), y.addEventListener("touchstart", M, { passive: !1 }), () => {
1223
- y.removeEventListener("mousedown", M), y.removeEventListener("touchstart", M);
1287
+ }, le(() => {
1288
+ if (ce) return;
1289
+ const L = t.current;
1290
+ if (!L) return;
1291
+ const _ = (M) => Pe.current?.(M, L, H);
1292
+ return L.addEventListener("mousedown", _, { passive: !1 }), L.addEventListener("touchstart", _, { passive: !1 }), () => {
1293
+ L.removeEventListener("mousedown", _), L.removeEventListener("touchstart", _);
1224
1294
  };
1225
- }, [_, t, V]), ee(() => {
1226
- const y = t.current, M = t.current?.getContext("2d");
1227
- if (!(!y || !M))
1228
- return r ? (A(y, (P) => {
1229
- if (d.type === "selection") {
1230
- if (Y(l).length !== 1) return;
1231
- const T = Y(l)[0];
1232
- if (T?.type === "text") {
1233
- const k = st(P, t.current, g);
1234
- return vt(k, g) ? void (ft(M, l, k, g) && b({ mode: "textedition", defaultValue: T.value })) : void 0;
1295
+ }, [ce, t, H]), le(() => {
1296
+ const L = t.current, _ = t.current?.getContext("2d");
1297
+ if (!(!L || !_))
1298
+ return s ? (W(L, (M) => {
1299
+ if (r.type === "selection") {
1300
+ if (U(h).length !== 1) return;
1301
+ const C = U(h)[0];
1302
+ if (C?.type === "text") {
1303
+ const Q = ft(M, t.current, g);
1304
+ return Dt(Q, g) ? void (Et(_, h, Q, g) && b({ mode: "textedition", defaultValue: C.value })) : void 0;
1235
1305
  }
1236
- if (T?.type === "polygon") {
1237
- const k = st(P, t.current, g);
1238
- if (!vt(k, g)) return;
1239
- const O = Gi(M, T, k, g);
1240
- return void (O && p([Ka(T, O.lineIndex, k, g)]));
1306
+ if (C?.type === "polygon") {
1307
+ const Q = ft(M, t.current, g);
1308
+ if (!Dt(Q, g)) return;
1309
+ const V = hn(_, C, Q, g);
1310
+ return void (V && S([fa(C, V.lineIndex, Q, g)]));
1241
1311
  }
1242
- if (T?.type === "curve") {
1243
- const k = st(P, t.current, g);
1244
- if (!vt(k, g)) return;
1245
- const O = ((R, B, I, j, de = 50) => {
1246
- if (B.locked || B.points.length < 2) return !1;
1247
- if (B.points.length < 3) return Gi(R, B, I, j, de);
1248
- const { center: se } = B.computed, K = Re(I, B.rotation ?? 0, se);
1249
- R.lineWidth = (B.style?.lineWidth ?? 0) + de / j.canvasZoom;
1250
- const N = yi(B, B.points), ge = new Path2D();
1251
- ge.moveTo(...N[0]);
1252
- for (let oe = 1; oe < N.length - 2; oe++) {
1253
- const ye = N[oe - 1], Se = N[oe], Qe = N[oe + 1], te = N[oe + 2], { cp1: ve, cp2: U } = Si(ye, Se, Qe, te);
1254
- if (ge.bezierCurveTo(ve[0], ve[1], U[0], U[1], Qe[0], Qe[1]), R.isPointInStroke(ge, K[0], K[1])) return { lineIndex: oe - 1 };
1312
+ if (C?.type === "curve") {
1313
+ const Q = ft(M, t.current, g);
1314
+ if (!Dt(Q, g)) return;
1315
+ const V = ((N, k, J, O, T = 50) => {
1316
+ if (k.locked || k.points.length < 2) return !1;
1317
+ if (k.points.length < 3) return hn(N, k, J, O, T);
1318
+ const { center: ne } = k.computed, ye = tt(J, k.rotation ?? 0, ne);
1319
+ N.lineWidth = (k.style?.lineWidth ?? 0) + T / O.canvasZoom;
1320
+ const Y = Ti(k, k.points), ze = new Path2D();
1321
+ ze.moveTo(...Y[0]);
1322
+ for (let ge = 1; ge < Y.length - 2; ge++) {
1323
+ const Oe = Y[ge - 1], Ye = Y[ge], he = Y[ge + 1], Se = Y[ge + 2], { cp1: ae, cp2: fe } = Di(Oe, Ye, he, Se);
1324
+ if (ze.bezierCurveTo(ae[0], ae[1], fe[0], fe[1], he[0], he[1]), N.isPointInStroke(ze, ye[0], ye[1])) return { lineIndex: ge - 1 };
1255
1325
  }
1256
1326
  return !1;
1257
- })(M, T, k, g);
1258
- return void (O && p([eo(T, O.lineIndex, k, g)]));
1327
+ })(_, C, Q, g);
1328
+ return void (V && S([ma(C, V.lineIndex, Q, g)]));
1259
1329
  }
1260
1330
  }
1261
1331
  }), () => {
1262
- H(y);
1332
+ I(L);
1263
1333
  }) : void 0;
1264
- }, [p, A, H, r, t, d, l, b, g]), { hoverMode: x };
1265
- }, ba = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => ba(t)).join("") : e.nodeValue ?? "", Co = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: n, saveShapes: a, settings: o }) => {
1266
- const d = ne(null), r = ne(a);
1267
- ee(() => {
1268
- if (!d.current) return;
1269
- const h = d.current, c = (u) => {
1270
- u.preventDefault();
1271
- const f = u.clipboardData?.getData("text/plain");
1272
- document.execCommand("insertText", !1, f);
1334
+ }, [S, W, I, s, t, r, h, b, g]), { hoverMode: E };
1335
+ }, Wo = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => Wo(t)).join("") : e.nodeValue ?? "", Wa = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: n, saveShapes: o, settings: a }) => {
1336
+ const r = re(null), l = re(o);
1337
+ le(() => {
1338
+ if (!r.current) return;
1339
+ const c = r.current, f = (p) => {
1340
+ p.preventDefault();
1341
+ const m = p.clipboardData?.getData("text/plain");
1342
+ document.execCommand("insertText", !1, m);
1273
1343
  };
1274
- h.addEventListener("paste", c), h.innerText = "";
1275
- for (const u of i) {
1276
- const f = document.createElement("div");
1277
- u === "" ? f.innerHTML = "<br/>" : f.innerText = u, h.appendChild(f);
1344
+ c.addEventListener("paste", f), c.innerText = "";
1345
+ for (const p of i) {
1346
+ const m = document.createElement("div");
1347
+ p === "" ? m.innerHTML = "<br/>" : m.innerText = p, c.appendChild(m);
1278
1348
  }
1279
- return h.focus(), () => {
1280
- h.removeEventListener("paste", c);
1349
+ return c.focus(), () => {
1350
+ c.removeEventListener("paste", f);
1281
1351
  };
1282
- }, [i]), ee(() => {
1283
- const h = r.current;
1352
+ }, [i]), le(() => {
1353
+ const c = l.current;
1284
1354
  return () => {
1285
- h();
1355
+ c();
1286
1356
  };
1287
1357
  }, []);
1288
- const s = kn(() => {
1289
- const { borders: h, center: c } = t.computed;
1290
- return le({ point: [h.x, h.y], rotation: -(t.rotation ?? 0), origin: c });
1291
- }, [t]), l = [`translate3D(${(s[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio}px, ${(s[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio}px, 0)`, `rotate(${si(t.rotation ?? 0)}deg)`, t.flipX || t.flipY ? `scale(${t.flipX ? -1 : 1}, ${t.flipY ? -1 : 1})` : void 0, t.flipX || t.flipY ? `translate3D(${t.flipX ? -100 : 0}%,${t.flipY ? -100 : 0}%,0)` : void 0].filter(Boolean).join(" ");
1292
- return m("div", { className: "react-paint-editor-toolbox-edittextbox", ref: d, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: !e, onInput: (h) => {
1293
- const c = Array.from(h.target.childNodes).map((u) => ba(u));
1294
- n(c);
1295
- }, style: { "--react-paint-editor-toolbox-edittextbox-transform": l, "--react-paint-editor-toolbox-edittextbox-fontsize": t.fontSize * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-padding": o.selectionPadding * o.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-color": t.style?.strokeColor ?? "inherit", "--react-paint-editor-toolbox-edittextbox-opacity": (t.style?.opacity ?? 100) / 100, "--react-paint-editor-toolbox-edittextbox-fontfamily": t.style?.fontFamily ?? mt } });
1296
- }, Mo = (e, t, i, n, a) => {
1297
- ta(e), ((o, d) => {
1298
- const { canvasZoom: r, size: s, canvasSize: { width: l, height: h } } = d;
1299
- if (s !== "fixed" || r >= 1) return;
1300
- o.fillStyle = "#f5f5f5", o.fillRect(0, 0, l, h);
1301
- const c = ca(d);
1302
- o.clearRect(c.x, c.y, c.width, c.height), ha(o, d);
1303
- })(e, i), ((o, d) => {
1304
- const { canvasSize: { width: r, height: s }, gridGap: l, canvasOffset: h, canvasSize: { scaleRatio: c } } = d;
1305
- if (!l) return;
1306
- o.strokeStyle = "rgb(220,220,220)", o.lineWidth = 1, o.save(), o.scale(c, c), o.beginPath();
1307
- const u = h[0] % l, f = h[1] % l, v = Math.ceil(r / c / l) + 2, p = Math.ceil(s / c / l) + 2;
1308
- for (let S = -5; S < v; S++) o.moveTo(u + (S + 1) * l, f - l), o.lineTo(u + (S + 1) * l, f + s / c + l);
1309
- for (let S = -5; S < p; S++) o.moveTo(u - l, f + (S + 1) * l), o.lineTo(u + r / c + l, f + (S + 1) * l);
1310
- o.stroke(), o.restore();
1358
+ const s = Fn(() => {
1359
+ const { borders: c, center: f } = t.computed;
1360
+ return me({ point: [c.x, c.y], rotation: -(t.rotation ?? 0), origin: f });
1361
+ }, [t]), d = [`translate3D(${(s[0] + a.canvasOffset[0]) * a.canvasSize.scaleRatio}px, ${(s[1] + a.canvasOffset[1]) * a.canvasSize.scaleRatio}px, 0)`, `rotate(${Qi(t.rotation ?? 0)}deg)`, t.flipX || t.flipY ? `scale(${t.flipX ? -1 : 1}, ${t.flipY ? -1 : 1})` : void 0, t.flipX || t.flipY ? `translate3D(${t.flipX ? -100 : 0}%,${t.flipY ? -100 : 0}%,0)` : void 0].filter(Boolean).join(" "), h = !e;
1362
+ return v("div", { className: "react-paint-editor-toolbox-edittextbox", ref: r, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: h, role: "textbox", tabIndex: h ? 0 : void 0, onInput: (c) => {
1363
+ const f = Array.from(c.target.childNodes).map((p) => Wo(p));
1364
+ n(f);
1365
+ }, style: { "--react-paint-editor-toolbox-edittextbox-transform": d, "--react-paint-editor-toolbox-edittextbox-fontsize": t.fontSize * a.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-padding": a.selectionPadding * a.canvasSize.scaleRatio + "px", "--react-paint-editor-toolbox-edittextbox-color": t.style?.strokeColor ?? "inherit", "--react-paint-editor-toolbox-edittextbox-opacity": (t.style?.opacity ?? 100) / 100, "--react-paint-editor-toolbox-edittextbox-fontfamily": t.style?.fontFamily ?? It } });
1366
+ }, Na = (e, t, i, n, o) => {
1367
+ So(e), ((a, r) => {
1368
+ const { canvasZoom: l, size: s, canvasSize: { width: d, height: h } } = r;
1369
+ if (s !== "fixed" || l >= 1) return;
1370
+ a.fillStyle = "#f5f5f5", a.fillRect(0, 0, d, h);
1371
+ const c = ko(r);
1372
+ a.clearRect(c.x, c.y, c.width, c.height), Lo(a, r);
1373
+ })(e, i), ((a, r) => {
1374
+ const { canvasSize: { width: l, height: s }, gridGap: d, canvasOffset: h, canvasSize: { scaleRatio: c } } = r;
1375
+ if (!d) return;
1376
+ a.strokeStyle = "rgb(220,220,220)", a.lineWidth = 1, a.save(), a.scale(c, c), a.beginPath();
1377
+ const f = h[0] % d, p = h[1] % d, m = Math.ceil(l / c / d) + 2, u = Math.ceil(s / c / d) + 2;
1378
+ for (let S = -5; S < m; S++) a.moveTo(f + (S + 1) * d, p - d), a.lineTo(f + (S + 1) * d, p + s / c + d);
1379
+ for (let S = -5; S < u; S++) a.moveTo(f - d, p + (S + 1) * d), a.lineTo(f + l / c + d, p + (S + 1) * d);
1380
+ a.stroke(), a.restore();
1311
1381
  })(e, i);
1312
- for (let o = n.length - 1; o >= 0; o--) t.mode === "textedition" && n[o] === a || va(e, Y(a).find((d) => d.id === n[o].id) ?? n[o], i);
1313
- }, Po = hi.forwardRef(({ canGrow: e, shapes: t, duplicateShapes: i, addShapes: n, updateSingleShape: a, selectedShape: o, setSelectedShape: d, setSelectionFrame: r, hoveredShape: s, selectionFrame: l, refreshHoveredShape: h, refreshSelectedShapes: c, saveShapes: u, activeTool: f, setActiveTool: v, canvasOffsetStartData: p, setCanvasOffsetStartData: S, setCanvasOffset: C, setCanvasMoveAcceleration: b, isInsideComponent: Q, selectionMode: g, setSelectionMode: w, selectionWidth: L, selectionColor: D, settings: V, isEditMode: x, isShiftPressed: Z, isAltPressed: A, isSpacePressed: H, withFrameSelection: F, withSkeleton: E }, W) => {
1314
- const G = ne(null), _ = ne(null), z = V.canvasSize, y = x, M = x ? 0 : -1;
1315
- Ln(W, () => G.current);
1316
- const { hoverMode: P } = xo({ addShapes: n, drawCanvasRef: G, setActiveTool: v, shapes: t, selectionMode: g, activeTool: f, isInsideComponent: Q, setCanvasOffset: C, selectedShape: o, canvasOffsetStartData: p, setCanvasOffsetStartData: S, setSelectedShape: d, setSelectionFrame: r, refreshHoveredShape: h, refreshSelectedShapes: c, updateSingleShape: a, duplicateShapes: i, saveShapes: u, setSelectionMode: w, setCanvasMoveAcceleration: b, isShiftPressed: Z, isAltPressed: A, withFrameSelection: F, settings: V, isSpacePressed: H }), T = X((O) => {
1317
- const R = Y(o)[0];
1318
- if (R?.type !== "text") return;
1319
- const B = G.current?.getContext("2d");
1320
- if (!B) return;
1321
- const I = Ne(po(B, R, O, V), V);
1322
- a([I]);
1323
- }, [a, o, V]), k = (O) => {
1324
- if (x) return O.preventDefault(), O.stopPropagation(), !1;
1382
+ for (let a = n.length - 1; a >= 0; a--) t.mode === "textedition" && n[a] === o || Ao(e, U(o).find((r) => r.id === n[a].id) ?? n[a], i);
1383
+ }, Oa = ki.forwardRef(({ canGrow: e, shapes: t, duplicateShapes: i, addShapes: n, updateSingleShape: o, selectedShape: a, setSelectedShape: r, setSelectionFrame: l, hoveredShape: s, selectionFrame: d, refreshHoveredShape: h, refreshSelectedShapes: c, saveShapes: f, activeTool: p, setActiveTool: m, canvasOffsetStartData: u, setCanvasOffsetStartData: S, setCanvasOffset: w, setCanvasMoveAcceleration: x, isInsideComponent: b, isInsideCanvas: y, selectionMode: g, setSelectionMode: P, selectionWidth: z, selectionColor: D, settings: A, isEditMode: H, isShiftPressed: Z, isAltPressed: E, isSpacePressed: F, withFrameSelection: W, withSkeleton: I, withContextMenu: oe }, te) => {
1384
+ const R = re(null), $ = re(null), j = A.canvasSize, ce = H, Pe = H ? 0 : -1;
1385
+ Yn(te, () => R.current);
1386
+ const { hoverMode: L } = Ra({ addShapes: n, drawCanvasRef: R, setActiveTool: m, shapes: t, selectionMode: g, activeTool: p, isInsideComponent: b, isInsideCanvas: y, setCanvasOffset: w, selectedShape: a, canvasOffsetStartData: u, setCanvasOffsetStartData: S, setSelectedShape: r, setSelectionFrame: l, refreshHoveredShape: h, refreshSelectedShapes: c, updateSingleShape: o, duplicateShapes: i, saveShapes: f, setSelectionMode: P, setCanvasMoveAcceleration: x, isShiftPressed: Z, isAltPressed: E, withFrameSelection: W, settings: A, isSpacePressed: F, withContextMenu: oe }), _ = X((C) => {
1387
+ const Q = U(a)[0];
1388
+ if (Q?.type !== "text") return;
1389
+ const V = R.current?.getContext("2d");
1390
+ if (!V) return;
1391
+ const N = _e(Va(V, Q, C, A), A);
1392
+ o([N]);
1393
+ }, [o, a, A]), M = (C) => {
1394
+ if (H) return C.preventDefault(), C.stopPropagation(), !1;
1325
1395
  };
1326
- return ee(() => {
1327
- const O = G.current?.getContext("2d");
1328
- O && window.requestAnimationFrame(() => Mo(O, g, V, t, o));
1329
- }, [t, g, o, V]), ee(() => {
1330
- const O = _.current?.getContext("2d");
1331
- O && window.requestAnimationFrame(() => ((R, B, I, j, de, se, K, N, ge, oe, ye) => {
1332
- R.reset(), ha(R, I), ye && N && !Y(K).find((Se) => Se.id === N.id) && j.type === "selection" && B.mode === "default" && on({ ctx: R, shape: N, settings: I, selectionWidth: de, selectionColor: se, hoverMode: ge, selectionMode: B, withAnchors: !1 }), K && j.type !== "brush" && on({ ctx: R, shape: K, settings: I, selectionWidth: de, selectionColor: se, hoverMode: ge, selectionMode: B, withAnchors: B.mode !== "textedition" }), oe && fo({ ctx: R, selectionFrame: oe, settings: I });
1333
- })(O, g, V, f, L, D, o, s, P, l, E));
1334
- }, [s, P, l, g, o, f, V, L, D, E]), m("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": p ? "grabbing" : P.outOfView ? "default" : P.mode === "resize" ? "pointer" : f.type !== "selection" && f.type !== "move" ? "crosshair" : P.mode === "translate" ? "move" : P.mode === "rotate" || f.type === "move" || H ? "grab" : "default" }, children: q("div", { className: "react-paint-canvas-container", "data-grow": e, children: [m("canvas", { className: jn, ref: G, "data-grow": e, width: z.width, height: z.height, onContextMenu: k, tabIndex: M }), y && m("canvas", { className: Kn, ref: _, width: z.width, height: z.height, "data-grow": e, onContextMenu: k }), x && g.mode === "textedition" && Y(o)[0]?.type === "text" && m(Co, { disabled: !V.features.edition, shape: Y(o)[0], defaultValue: g.defaultValue, updateValue: T, saveShapes: u, settings: V })] }) });
1335
- }), un = "ArrowUp", pn = "ArrowDown", gn = "ArrowLeft", vn = "ArrowRight", ko = "Delete", Lo = "Backspace", Vo = "Escape", fn = "Shift", mn = "Alt", yn = "Option", Ht = " ", Zo = "z", Ho = "Z", zo = "y", To = "Y", Ao = "+", Do = "-", Eo = "0", Sn = "copy", Qn = "paste", Io = ({ isInsideComponent: e, isInsideCanvas: t, selectedShape: i, isEditingText: n, settings: a, setSelectedShape: o, setActiveTool: d, setCanvasZoom: r, resetZoom: s, setSelectionMode: l, setSelectionFrame: h, removeShape: c, pasteShapes: u, updateShapes: f, backwardShape: v, forwardShape: p, setShiftPressed: S, setAltPressed: C, setIsSpacePressed: b }) => {
1336
- const [Q, g] = $(void 0);
1337
- return ee(() => {
1338
- const w = (x) => {
1339
- i && (n || (x.preventDefault(), g({ ...i })));
1340
- }, L = (x) => {
1341
- Q && (n || (x.preventDefault(), u(((Z, A) => Y(Z).map((H) => ({ ...fa(H, 20, 20, A), id: ue(`${H.type}_`) })))(Q, a))));
1342
- }, D = (x) => {
1343
- switch (x.key) {
1344
- case fn:
1345
- S(!1);
1346
- break;
1347
- case mn:
1348
- case yn:
1349
- C(!1);
1350
- break;
1351
- case Ht:
1352
- b(!1);
1353
- }
1354
- }, V = (x) => {
1355
- if (x.metaKey || x.ctrlKey) {
1356
- if (x.key === Ho || x.key === Zo) return x.preventDefault(), x.stopPropagation(), void (x.shiftKey ? p() : v());
1357
- if (!ea() && (x.key === To || x.key === zo)) return x.preventDefault(), x.stopPropagation(), void p();
1358
- if (x.key === Ao) return x.preventDefault(), x.stopPropagation(), void r("zoom");
1359
- if (x.key === Do) return x.preventDefault(), x.stopPropagation(), void r("unzoom");
1360
- if (x.key === Eo) return x.preventDefault(), x.stopPropagation(), void s();
1361
- }
1362
- if (x.key === fn) return x.preventDefault(), x.stopPropagation(), void S(!0);
1363
- if (x.key === Ht && t) return x.preventDefault(), x.stopPropagation(), void b(!0);
1364
- if (x.key === mn || x.key === yn) return x.preventDefault(), x.stopPropagation(), void C(!0);
1365
- if (!i) return;
1366
- if (x.key === Vo) return o(void 0), d(Oe), l({ mode: "default" }), void h(void 0);
1367
- if (n) return;
1368
- const Z = { [gn]: [a.gridGap ? -a.gridGap : -1, 0], [vn]: [a.gridGap ? a.gridGap : 1, 0], [pn]: [0, a.gridGap ? a.gridGap : 1], [un]: [0, a.gridGap ? -a.gridGap : -1] };
1369
- switch (x.key) {
1370
- case gn:
1371
- case vn:
1372
- case pn:
1373
- case un:
1374
- x.preventDefault(), x.stopPropagation(), f(ma(Z[x.key], i, [0, 0], a, !0));
1375
- break;
1376
- case ko:
1377
- case Lo:
1378
- x.preventDefault(), x.stopPropagation(), c(Y(i));
1379
- }
1380
- };
1381
- if (e) return document.addEventListener("keydown", V), document.addEventListener("keyup", D), document.addEventListener(Sn, w), document.addEventListener(Qn, L), () => {
1382
- document.removeEventListener("keydown", V), document.removeEventListener("keyup", D), document.removeEventListener(Sn, w), document.removeEventListener(Qn, L);
1383
- };
1384
- }, [e, t, Q, n, i, a, f, c, o, u, v, p, S, C, d, l, h, r, s, b]), {};
1385
- }, ps = ({ options: e, className: t, style: i, canvasProps: n }) => {
1386
- const { shapesRef: a, selectedShape: o, selectionFrame: d, hoveredShape: r, addShape: s, setSelectedShape: l, setSelectionFrame: h, refreshSelectedShapes: c, refreshHoveredShape: u, duplicateShapes: f, removeShape: v, updateShape: p, backwardShape: S, forwardShape: C, saveShapes: b, refs: Q, width: g, height: w, settings: L, setCanvasSize: D, setCanvasOffset: V, selectShapes: x, activeTool: Z, setActiveTool: A, isInsideComponent: H, isInsideCanvas: F, isEditMode: E, canvas: { withSkeleton: W, withFrameSelection: G, canGrow: _, canShrink: z }, canvasOffsetStartData: y, setCanvasOffsetStartData: M, selectionMode: P, setSelectionMode: T, setCanvasMoveAcceleration: k, isShiftPressed: O, isAltPressed: R, isSpacePressed: B, setShiftPressed: I, setAltPressed: j, setCanvasZoom: de, resetZoom: se, setIsSpacePressed: K } = n, { canvasBackgroundColor: N, canvasSelectionColor: ge, canvasSelectionWidth: oe } = { ...Wa, ...e }, ye = ne(null), Se = X((te) => {
1387
- s(te), x(te);
1388
- }, [s, x]), Qe = X((te) => {
1389
- D({ realWidth: g, realHeight: w, width: te, height: w * te / g, scaleRatio: te / g });
1390
- }, [g, w, D]);
1391
- return Io({ isInsideComponent: H, isInsideCanvas: F, isEditingText: P.mode === "textedition", settings: L, selectedShape: o, setSelectedShape: l, removeShape: v, pasteShapes: Se, updateShapes: p, backwardShape: S, forwardShape: C, setShiftPressed: I, setAltPressed: j, setActiveTool: A, setSelectionMode: T, setSelectionFrame: h, setCanvasZoom: de, resetZoom: se, setIsSpacePressed: K }), (({ onResized: te, element: ve }) => {
1392
- ee(() => {
1393
- const U = ve.current;
1394
- if (!U) return;
1395
- const ae = new ResizeObserver((Me) => {
1396
- const Ze = Me?.[0]?.borderBoxSize?.[0], { width: re, height: Te } = Ze ? { width: Ze.inlineSize, height: Ze.blockSize } : Me?.[0]?.contentRect ?? {};
1397
- re !== void 0 && Te !== void 0 && te(re, Te);
1396
+ return le(() => {
1397
+ const C = R.current?.getContext("2d");
1398
+ C && window.requestAnimationFrame(() => Na(C, g, A, t, a));
1399
+ }, [t, g, a, A]), le(() => {
1400
+ const C = $.current?.getContext("2d");
1401
+ C && window.requestAnimationFrame(() => ((Q, V, N, k, J, O, T, ne, ye, Y, ze) => {
1402
+ Q.reset(), Lo(Q, N), ze && ne && !U(T).find((ge) => ge.id === ne.id) && k.type === "selection" && (V.mode === "default" || V.mode === "contextMenu" || V.mode === "textedition") && bn({ ctx: Q, shape: ne, settings: N, selectionWidth: J, selectionColor: O, hoverMode: ye, selectionMode: V, withAnchors: !1 }), T && k.type !== "brush" && bn({ ctx: Q, shape: T, settings: N, selectionWidth: J, selectionColor: O, hoverMode: ye, selectionMode: V, withAnchors: V.mode !== "textedition" }), Y && za({ ctx: Q, selectionFrame: Y, settings: N });
1403
+ })(C, g, A, p, z, D, a, s, L, d, I));
1404
+ }, [s, L, d, g, a, p, A, z, D, I]), v("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": u ? "grabbing" : L.outOfView ? "default" : L.mode === "resize" ? "pointer" : p.type !== "selection" && p.type !== "move" ? "crosshair" : L.mode === "translate" ? "move" : L.mode === "rotate" || p.type === "move" || F ? "grab" : "default" }, children: G("div", { className: "react-paint-canvas-container", "data-grow": e, children: [v("canvas", { className: go, ref: R, "data-grow": e, width: j.width, height: j.height, onContextMenu: M, tabIndex: Pe }), ce && v("canvas", { className: fo, ref: $, width: j.width, height: j.height, "data-grow": e, onContextMenu: M }), H && g.mode === "textedition" && U(a)[0]?.type === "text" && v(Wa, { disabled: !A.features.edition, shape: U(a)[0], defaultValue: g.defaultValue, updateValue: _, saveShapes: f, settings: A })] }) });
1405
+ }), kn = "ArrowUp", Ln = "ArrowDown", Vn = "ArrowLeft", Zn = "ArrowRight", Ba = "Delete", Fa = "Backspace", Ya = "Escape", zn = "Shift", An = "Alt", Hn = "Option", jt = " ", Xa = "A", $a = "a", Ua = "z", qa = "Z", Ga = "y", _a = "Y", ja = "+", Ka = "-", Ja = "0", Tn = "cut", Dn = "copy", En = "paste", Zs = ({ options: e, className: t, style: i, canvasProps: n }) => {
1406
+ const { shapesRef: o, selectedShape: a, selectionFrame: r, hoveredShape: l, addShape: s, setSelectedShape: d, selectAllShapes: h, setSelectionFrame: c, refreshSelectedShapes: f, refreshHoveredShape: p, duplicateShapes: m, removeShape: u, updateShape: S, backwardShape: w, forwardShape: x, saveShapes: b, refs: y, width: g, height: P, settings: z, setCanvasSize: D, setCanvasOffset: A, pasteShapes: H, activeTool: Z, setActiveTool: E, isInsideComponent: F, isInsideCanvas: W, isEditMode: I, canvas: { withSkeleton: oe, withFrameSelection: te, withContextMenu: R, canGrow: $, canShrink: j }, canvasOffsetStartData: ce, setCanvasOffsetStartData: Pe, selectionMode: L, setSelectionMode: _, setCanvasMoveAcceleration: M, isShiftPressed: C, isAltPressed: Q, isSpacePressed: V, copiedShape: N, setCopiedShape: k, setShiftPressed: J, setAltPressed: O, setCanvasZoom: T, resetZoom: ne, setIsSpacePressed: ye } = n, { canvasBackgroundColor: Y, canvasSelectionColor: ze, canvasSelectionWidth: ge } = { ...ta, ...e }, Oe = re(null), Ye = X((he) => {
1407
+ D({ realWidth: g, realHeight: P, width: he, height: P * he / g, scaleRatio: he / g });
1408
+ }, [g, P, D]);
1409
+ return (({ isInsideComponent: he, isInsideCanvas: Se, selectedShape: ae, isEditingText: fe, settings: ee, copiedShape: se, setCopiedShape: pe, setSelectedShape: ke, setActiveTool: Be, setCanvasZoom: Ee, resetZoom: we, setSelectionMode: Fe, setSelectionFrame: bt, selectAllShapes: Qt, removeShape: dt, pasteShapes: $e, updateShapes: wt, backwardShape: xt, forwardShape: Ae, setShiftPressed: at, setAltPressed: st, setIsSpacePressed: je }) => {
1410
+ le(() => {
1411
+ const ct = (B) => {
1412
+ ae && (fe || (B.preventDefault(), pe({ ...ae })));
1413
+ }, ht = (B) => {
1414
+ ae && (fe || (B.preventDefault(), pe({ ...ae }), dt(U(ae))));
1415
+ }, pt = (B) => {
1416
+ se && (fe || (B.preventDefault(), $e(Wi(se, ee))));
1417
+ }, ve = (B) => {
1418
+ switch (B.key) {
1419
+ case zn:
1420
+ at(!1);
1421
+ break;
1422
+ case An:
1423
+ case Hn:
1424
+ st(!1);
1425
+ break;
1426
+ case jt:
1427
+ je(!1);
1428
+ }
1429
+ }, be = (B) => {
1430
+ if (B.metaKey || B.ctrlKey) {
1431
+ if (B.key === qa || B.key === Ua) return B.preventDefault(), B.stopPropagation(), void (B.shiftKey ? Ae() : xt());
1432
+ if (!mo() && (B.key === _a || B.key === Ga)) return B.preventDefault(), B.stopPropagation(), void Ae();
1433
+ if (B.key === Xa || B.key === $a) return B.preventDefault(), B.stopPropagation(), void Qt();
1434
+ if (B.key === ja) return B.preventDefault(), B.stopPropagation(), void Ee("zoom");
1435
+ if (B.key === Ka) return B.preventDefault(), B.stopPropagation(), void Ee("unzoom");
1436
+ if (B.key === Ja) return B.preventDefault(), B.stopPropagation(), void we();
1437
+ }
1438
+ if (B.key === zn) return B.preventDefault(), B.stopPropagation(), void at(!0);
1439
+ if (B.key === jt && Se) return B.preventDefault(), B.stopPropagation(), void je(!0);
1440
+ if (B.key === An || B.key === Hn) return B.preventDefault(), B.stopPropagation(), void st(!0);
1441
+ if (!ae) return;
1442
+ if (B.key === Ya) return ke(void 0), Be(Je), Fe({ mode: "default" }), void bt(void 0);
1443
+ if (fe) return;
1444
+ const nt = { [Vn]: [ee.gridGap ? -ee.gridGap : -1, 0], [Zn]: [ee.gridGap ? ee.gridGap : 1, 0], [Ln]: [0, ee.gridGap ? ee.gridGap : 1], [kn]: [0, ee.gridGap ? -ee.gridGap : -1] };
1445
+ switch (B.key) {
1446
+ case Vn:
1447
+ case Zn:
1448
+ case Ln:
1449
+ case kn:
1450
+ B.preventDefault(), B.stopPropagation(), wt(Do(nt[B.key], ae, [0, 0], ee, !0));
1451
+ break;
1452
+ case Ba:
1453
+ case Fa:
1454
+ B.preventDefault(), B.stopPropagation(), dt(U(ae));
1455
+ }
1456
+ };
1457
+ if (he) return document.addEventListener("keydown", be), document.addEventListener("keyup", ve), document.addEventListener(Dn, ct), document.addEventListener(En, pt), document.addEventListener(Tn, ht), () => {
1458
+ document.removeEventListener("keydown", be), document.removeEventListener("keyup", ve), document.removeEventListener(Dn, ct), document.removeEventListener(En, pt), document.removeEventListener(Tn, ht);
1459
+ };
1460
+ }, [he, Se, se, fe, ae, ee, wt, dt, ke, $e, xt, Ae, at, st, Be, Fe, bt, pe, Ee, we, je, Qt]);
1461
+ })({ isInsideComponent: F, isInsideCanvas: W, isEditingText: L.mode === "textedition", settings: z, selectedShape: a, copiedShape: N, setCopiedShape: k, selectAllShapes: h, setSelectedShape: d, removeShape: u, pasteShapes: H, updateShapes: S, backwardShape: w, forwardShape: x, setShiftPressed: J, setAltPressed: O, setActiveTool: E, setSelectionMode: _, setSelectionFrame: c, setCanvasZoom: T, resetZoom: ne, setIsSpacePressed: ye }), (({ onResized: he, element: Se }) => {
1462
+ le(() => {
1463
+ const ae = Se.current;
1464
+ if (!ae) return;
1465
+ const fe = new ResizeObserver((ee) => {
1466
+ const se = ee?.[0]?.borderBoxSize?.[0], { width: pe, height: ke } = se ? { width: se.inlineSize, height: se.blockSize } : ee?.[0]?.contentRect ?? {};
1467
+ pe !== void 0 && ke !== void 0 && he(pe, ke);
1398
1468
  });
1399
- return ae.observe(U), () => {
1400
- ae.unobserve(U);
1469
+ return fe.observe(ae), () => {
1470
+ fe.unobserve(ae);
1401
1471
  };
1402
- }, [ve, te]);
1403
- })({ element: ye, onResized: Qe }), m("div", { ref: ye, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": _, "data-shrink": z, style: { "--react-paint-app-row-width": L.canvasSize.width, "--react-paint-app-canvaswidth": g, "--react-paint-app-canvasheight": w, "--react-paint-app-row-aspectratio": `calc(${L.canvasSize.width} / ${L.canvasSize.height})`, "--react-paint-app-canvas-bg": N, ...i }, children: m(Po, { duplicateShapes: f, isSpacePressed: B, ref: Q.canvas, canGrow: _, isInsideComponent: H, activeTool: Z, setActiveTool: A, canvasOffsetStartData: y, setCanvasOffsetStartData: M, shapes: a.current, addShapes: s, updateSingleShape: p, selectedShape: o, selectionFrame: d, setSelectedShape: l, setSelectionFrame: h, hoveredShape: r, refreshHoveredShape: u, refreshSelectedShapes: c, settings: L, setCanvasOffset: V, saveShapes: b, selectionMode: P, setSelectionMode: T, setCanvasMoveAcceleration: k, selectionColor: ge, selectionWidth: oe, isEditMode: E, isShiftPressed: O, isAltPressed: R, withFrameSelection: G, withSkeleton: W }) });
1404
- }, Wo = ({ isLoading: e = !1 }) => {
1405
- const [t, i] = $("hidden");
1406
- return ee(() => {
1472
+ }, [Se, he]);
1473
+ })({ element: Oe, onResized: Ye }), v("div", { ref: Oe, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": $, "data-shrink": j, style: { "--react-paint-app-row-width": z.canvasSize.width, "--react-paint-app-canvaswidth": g, "--react-paint-app-canvasheight": P, "--react-paint-app-row-aspectratio": `calc(${z.canvasSize.width} / ${z.canvasSize.height})`, "--react-paint-app-canvas-bg": Y, ...i }, children: v(Oa, { duplicateShapes: m, isSpacePressed: V, withContextMenu: R, ref: y.canvas, canGrow: $, isInsideComponent: F, isInsideCanvas: W, activeTool: Z, setActiveTool: E, canvasOffsetStartData: ce, setCanvasOffsetStartData: Pe, shapes: o.current, addShapes: s, updateSingleShape: S, selectedShape: a, selectionFrame: r, setSelectedShape: d, setSelectionFrame: c, hoveredShape: l, refreshHoveredShape: p, refreshSelectedShapes: f, settings: z, setCanvasOffset: A, saveShapes: b, selectionMode: L, setSelectionMode: _, setCanvasMoveAcceleration: M, selectionColor: ze, selectionWidth: ge, isEditMode: I, isShiftPressed: C, isAltPressed: Q, withFrameSelection: te, withSkeleton: oe }) });
1474
+ }, es = ({ isLoading: e = !1 }) => {
1475
+ const [t, i] = K("hidden");
1476
+ return le(() => {
1407
1477
  if (!e) {
1408
1478
  i("fadeOut");
1409
1479
  const n = setTimeout(() => i("hidden"), 300);
@@ -1412,311 +1482,374 @@ const _i = ({ ctx: e, path: t, rect: i, offset: n, center: a, rotation: o = 0, c
1412
1482
  };
1413
1483
  }
1414
1484
  i("visible");
1415
- }, [e]), t === "hidden" ? null : m("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": Aa, "--react-paint-editor-loading-transition-duration": "300ms" }, children: q("div", { className: "react-paint-editor-loader", children: [m("div", {}), m("div", {}), m("div", {}), m("div", {})] }) });
1416
- }, Ro = "infos", No = 4e3, Bo = ({ type: e, text: t, duration: i }) => {
1417
- const [n, a] = $(!1);
1418
- return ee(() => {
1419
- const o = setTimeout(() => {
1420
- a(!0);
1421
- }, 100), d = setTimeout(() => {
1422
- a(!1);
1485
+ }, [e]), t === "hidden" ? null : v("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": jo, "--react-paint-editor-loading-transition-duration": "300ms" }, children: G("div", { className: "react-paint-editor-loader", children: [v("div", {}), v("div", {}), v("div", {}), v("div", {})] }) });
1486
+ }, ts = "infos", is = 4e3, ns = ({ type: e, text: t, duration: i }) => {
1487
+ const [n, o] = K(!1);
1488
+ return le(() => {
1489
+ const a = setTimeout(() => {
1490
+ o(!0);
1491
+ }, 100), r = setTimeout(() => {
1492
+ o(!1);
1423
1493
  }, i - 500 - 100);
1424
1494
  return () => {
1425
- clearTimeout(o), clearTimeout(d);
1495
+ clearTimeout(a), clearTimeout(r);
1426
1496
  };
1427
- }, [i]), m("div", { className: "react-paint-editor-snackbar", "data-is-shown": +n, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1428
- }, Oo = ({ snackbarList: e }) => m("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": Da }, children: e.map((t) => m(Bo, { ...t }, t.id)) }), Fo = hi.forwardRef((e, t) => {
1429
- const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: d, className: r = "", title: s, onClick: l, ...h } = e, c = n ? -1 : 0, u = ne(null);
1430
- return Ln(t, () => u.current), q("label", { className: `react-paint-editor-button ${r}`, title: s, onClick: l, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, tabIndex: c, onKeyDown: (f) => {
1431
- f.key === Ht && (f.preventDefault(), f.stopPropagation());
1432
- }, onKeyUp: (f) => {
1433
- f.preventDefault(), f.stopPropagation(), f.key === Ht && u.current?.click();
1434
- }, children: [m("input", { ref: u, disabled: n, ...h }), q("span", { className: "react-paint-editor-button-content", children: [d && m("span", { className: "react-paint-editor-button-children", children: d }), o && m("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] })] });
1435
- }), J = hi.forwardRef((e, t) => {
1436
- if (e.type === "file" || e.type === "color") return m(Fo, { ...e, ref: t });
1437
- const { hidden: i = !1, disabled: n = !1, selected: a = !1, icon: o, children: d, type: r = "button", className: s = "", ...l } = e;
1438
- return m("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: n, "data-disabled": +n, "data-selected": +a, "data-hidden": +i, type: r, ...l, children: q("span", { className: "react-paint-editor-button-content", children: [d && m("span", { className: "react-paint-editor-button-children", children: d }), o && m("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: o } })] }) });
1439
- }), nt = ({ children: e, title: t = "", className: i = "", position: n = "bottom", fitContainer: a = !1, alignment: o = "center", style: d, ...r }) => q("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": a, "data-position": n, "data-alignment": o, style: { ...d, "--react-paint-editor-panel-zindex": En }, ...r, children: [t && m("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), Yo = (e) => {
1497
+ }, [i]), v("div", { className: "react-paint-editor-snackbar", "data-is-shown": +n, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
1498
+ }, os = ({ snackbarList: e }) => v("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": Ko }, children: e.map((t) => v(ns, { ...t }, t.id)) }), as = ki.forwardRef((e, t) => {
1499
+ const { hidden: i = !1, disabled: n = !1, selected: o = !1, icon: a, children: r, className: l = "", title: s, onClick: d, ...h } = e, c = n ? -1 : 0, f = re(null);
1500
+ return Yn(t, () => f.current), G("label", { className: `react-paint-editor-button ${l}`, title: s, onClick: d, "data-disabled": +n, "data-selected": +o, "data-hidden": +i, tabIndex: c, onKeyDown: (p) => {
1501
+ p.key === jt && (p.preventDefault(), p.stopPropagation());
1502
+ }, onKeyUp: (p) => {
1503
+ p.preventDefault(), p.stopPropagation(), p.key === jt && f.current?.click();
1504
+ }, children: [v("input", { ref: f, disabled: n, ...h }), G("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), a && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: a } })] })] });
1505
+ }), q = ki.forwardRef((e, t) => {
1506
+ if (e.type === "file" || e.type === "color") return v(as, { ...e, ref: t });
1507
+ const { hidden: i = !1, disabled: n = !1, selected: o = !1, icon: a, children: r, type: l = "button", className: s = "", ...d } = e;
1508
+ return v("button", { className: `react-paint-editor-button ${s}`, ref: t, disabled: n, "data-disabled": +n, "data-selected": +o, "data-hidden": +i, type: l, ...d, children: G("span", { className: "react-paint-editor-button-content", children: [r && v("span", { className: "react-paint-editor-button-children", children: r }), a && v("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: a } })] }) });
1509
+ }), yt = ({ children: e, title: t = "", className: i = "", position: n, fitContainer: o = !1, alignment: a, style: r, ...l }) => G("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": o, "data-position": n ?? "unset", "data-alignment": a ?? "unset", style: { ...r, "--react-paint-editor-panel-zindex": Kn }, ...l, children: [t && v("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), ss = (e) => {
1440
1510
  switch (e) {
1441
1511
  case "brush":
1442
- return Zn;
1512
+ return $n;
1443
1513
  case "line":
1444
- return Tn;
1514
+ return Gn;
1445
1515
  case "polygon":
1446
- return gi;
1516
+ return Zi;
1447
1517
  case "curve":
1448
- return An;
1518
+ return _n;
1449
1519
  case "rect":
1450
1520
  case "square":
1451
- return ui;
1521
+ return Li;
1452
1522
  case "circle":
1453
1523
  case "ellipse":
1454
- return pi;
1524
+ return Vi;
1455
1525
  case "text":
1456
- return zn;
1526
+ return qn;
1457
1527
  case "picture":
1458
- return vi;
1528
+ return zi;
1459
1529
  case "group":
1460
1530
  return '<svg><path d="M3.333 17.5V16.667H7.5V17.5ZM3.333 14.167V13.333H9.167V14.167ZM3.333 10.833V10H10.833V10.833ZM3.333 7.5V6.667H12.5V7.5ZM3.333 4.167V3.333H13.333V4.167ZM3.333 0.833V0H16.667V0.833Z"/></svg>';
1461
1531
  case "triangle":
1462
1532
  return "";
1463
1533
  }
1464
- }, Xo = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: n, toggleShapeVisibility: a, toggleShapeLock: o, setLayoutDragging: d, handleRemove: r, handleSelect: s, onMoveShapes: l }) => {
1465
- const h = ne(null), { isOver: c } = (({ disabled: u = !1, ref: f, shape: v, layoutDragging: p, setLayoutDragging: S, handleSelect: C, onMoveShapes: b }) => {
1466
- const [Q, g] = $(!1);
1467
- return ee(() => {
1468
- p || g(!1);
1469
- }, [p]), ee(() => {
1470
- const w = f.current;
1471
- if (!w) return;
1472
- const L = () => {
1534
+ }, rs = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: n, toggleShapeVisibility: o, toggleShapeLock: a, setLayoutDragging: r, handleRemove: l, handleSelect: s, onSwapShapes: d }) => {
1535
+ const h = re(null), { isOver: c } = (({ disabled: f = !1, ref: p, shape: m, layoutDragging: u, setLayoutDragging: S, handleSelect: w, onSwapShapes: x }) => {
1536
+ const [b, y] = K(!1);
1537
+ return le(() => {
1538
+ u || y(!1);
1539
+ }, [u]), le(() => {
1540
+ const g = p.current;
1541
+ if (!g) return;
1542
+ const P = () => {
1473
1543
  S(void 0);
1474
- }, D = (H) => (H.preventDefault && H.preventDefault(), !1), V = (H) => {
1475
- C([v]), H.dataTransfer && (H.dataTransfer.effectAllowed = "move", H.dataTransfer.setData("draggableShapeId", v.id), S(v.id));
1476
- }, x = () => {
1477
- p !== v.id && g(!0);
1478
- }, Z = () => {
1479
- g(!1);
1480
- }, A = (H) => (H.stopPropagation(), H.dataTransfer && b(H.dataTransfer.getData("draggableShapeId"), v.id), !1);
1481
- return u || (w.addEventListener("dragstart", V), w.addEventListener("dragend", L), w.addEventListener("dragover", D), w.addEventListener("dragenter", x), w.addEventListener("dragleave", Z), w.addEventListener("drop", A)), () => {
1482
- u || (w.removeEventListener("dragstart", V), w.removeEventListener("dragend", L), w.removeEventListener("dragover", D), w.removeEventListener("dragenter", x), w.removeEventListener("dragleave", Z), w.removeEventListener("drop", A));
1544
+ }, z = (E) => (E.preventDefault && E.preventDefault(), !1), D = (E) => {
1545
+ w([m]), E.dataTransfer && (E.dataTransfer.effectAllowed = "move", E.dataTransfer.setData("draggableShapeId", m.id), S(m.id));
1546
+ }, A = () => {
1547
+ u !== m.id && y(!0);
1548
+ }, H = () => {
1549
+ y(!1);
1550
+ }, Z = (E) => (E.stopPropagation(), E.dataTransfer && x(E.dataTransfer.getData("draggableShapeId"), m.id), !1);
1551
+ return f || (g.addEventListener("dragstart", D), g.addEventListener("dragend", P), g.addEventListener("dragover", z), g.addEventListener("dragenter", A), g.addEventListener("dragleave", H), g.addEventListener("drop", Z)), () => {
1552
+ f || (g.removeEventListener("dragstart", D), g.removeEventListener("dragend", P), g.removeEventListener("dragover", z), g.removeEventListener("dragenter", A), g.removeEventListener("dragleave", H), g.removeEventListener("drop", Z));
1483
1553
  };
1484
- }, [u, f, v, S, C, b, p]), { isOver: Q };
1485
- })({ disabled: e, ref: h, shape: t, layoutDragging: n, setLayoutDragging: d, handleSelect: s, onMoveShapes: l });
1486
- return q("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(n === t.id), "data-is-over": +c, onClick: (u) => {
1487
- e || (u.preventDefault(), u.stopPropagation(), s([t]));
1488
- }, "data-selected": +i, ref: h, tabIndex: -1, children: [m("span", { dangerouslySetInnerHTML: { __html: Yo(t.type) } }), m("span", { children: t.id }), m("div", { className: "react-paint-editor-layouts-separator" }), m(J, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (u) => {
1489
- e || (u.preventDefault(), u.stopPropagation(), a([t]));
1490
- }, icon: t.visible === !1 ? '<svg><path d="M13.521 11.021 12.25 9.75Q12.333 8.75 11.604 7.979Q10.875 7.208 9.812 7.312L8.542 6.042Q8.896 5.896 9.26 5.833Q9.625 5.771 10 5.771Q11.583 5.771 12.688 6.875Q13.792 7.979 13.792 9.562Q13.792 9.979 13.719 10.354Q13.646 10.729 13.521 11.021ZM16.167 13.646 14.917 12.417Q15.667 11.833 16.25 11.146Q16.833 10.458 17.25 9.562Q16.229 7.479 14.292 6.281Q12.354 5.083 10 5.083Q9.396 5.083 8.885 5.156Q8.375 5.229 7.875 5.375L6.5 4Q7.354 3.646 8.208 3.49Q9.062 3.333 10 3.333Q13.146 3.333 15.615 5.052Q18.083 6.771 19.167 9.562Q18.688 10.792 17.917 11.823Q17.146 12.854 16.167 13.646ZM16.396 18.854 12.938 15.396Q12.208 15.625 11.479 15.729Q10.75 15.833 10 15.833Q6.833 15.833 4.375 14.094Q1.917 12.354 0.833 9.562Q1.25 8.479 1.917 7.552Q2.583 6.625 3.417 5.875L1.125 3.562L2.375 2.354L17.625 17.625ZM4.604 7.062Q4.021 7.604 3.542 8.219Q3.062 8.833 2.729 9.562Q3.75 11.646 5.688 12.865Q7.625 14.083 10 14.083Q10.354 14.083 10.74 14.052Q11.125 14.021 11.479 13.938L10.812 13.271Q10.625 13.312 10.417 13.333Q10.208 13.354 10 13.354Q8.417 13.354 7.312 12.25Q6.208 11.146 6.208 9.562Q6.208 9.354 6.24 9.167Q6.271 8.979 6.312 8.771ZM11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875ZM8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Z"/></svg>' : '<svg><path d="M10 13.354Q11.583 13.354 12.688 12.25Q13.792 11.146 13.792 9.562Q13.792 7.979 12.688 6.875Q11.583 5.771 10 5.771Q8.417 5.771 7.312 6.875Q6.208 7.979 6.208 9.562Q6.208 11.146 7.312 12.25Q8.417 13.354 10 13.354ZM10 11.812Q9.062 11.812 8.406 11.156Q7.75 10.5 7.75 9.562Q7.75 8.625 8.406 7.969Q9.062 7.312 10 7.312Q10.938 7.312 11.594 7.969Q12.25 8.625 12.25 9.562Q12.25 10.5 11.594 11.156Q10.938 11.812 10 11.812ZM10 15.833Q6.938 15.833 4.448 14.125Q1.958 12.417 0.833 9.562Q1.958 6.708 4.458 5.021Q6.958 3.333 10 3.333Q13.042 3.333 15.542 5.021Q18.042 6.708 19.167 9.562Q18.042 12.417 15.552 14.125Q13.062 15.833 10 15.833ZM10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562ZM10 14.083Q12.333 14.083 14.281 12.865Q16.229 11.646 17.25 9.562Q16.229 7.479 14.281 6.281Q12.333 5.083 10 5.083Q7.667 5.083 5.708 6.281Q3.75 7.479 2.729 9.562Q3.75 11.646 5.708 12.865Q7.667 14.083 10 14.083Z"/></svg>' }), m(J, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (u) => {
1491
- e || (u.preventDefault(), u.stopPropagation(), o([t]));
1492
- }, icon: t.locked ? '<svg><path d="M10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H5.792V5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833ZM10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042V6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' : '<svg><path d="M5.792 5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' }), m(J, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (u) => {
1493
- e || (u.preventDefault(), u.stopPropagation(), r([t]));
1494
- }, icon: Hn })] });
1495
- }, $o = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: n, removeShape: a, toggleShapeVisibility: o, toggleShapeLock: d, selectedShapes: r, moveShapes: s, selectShapes: l, isLayoutPanelShown: h }) => {
1496
- const [c, u] = $(void 0), f = !i.features.edition;
1497
- return h ? m(nt, { alignment: "right", className: "react-paint-editor-layouts-panel", children: m("div", { className: "react-paint-editor-layouts-panel-content", children: q("div", { className: "react-paint-editor-layouts-scrolling-content", children: [q("div", { className: "react-paint-editor-layouts-row", children: [m("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), m(J, { icon: '<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>', className: "react-paint-editor-layouts-grid-button", selected: e === "none", disabled: f, onClick: () => t("none") }), ["small", "medium", "large"].map((v) => m(J, { className: "react-paint-editor-layouts-grid-button", selected: e === v, disabled: f, onClick: () => t(v), children: v.charAt(0).toUpperCase() }, v))] }), m("hr", {}), m("div", { className: "react-paint-editor-layouts", children: n.length === 0 ? m("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : n.map((v) => m(Xo, { shape: v, disabled: f, layoutDragging: c, setLayoutDragging: u, selected: Y(r).some((p) => p.id === v.id) ?? !1, handleSelect: l, handleRemove: a, onMoveShapes: s, toggleShapeVisibility: o, toggleShapeLock: d }, v.id)) })] }) }) }) : null;
1498
- }, Nt = ({ children: e, onClose: t, position: i = "center", title: n, className: a = "" }) => q("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": En }, role: "dialog", "aria-modal": "true", "aria-labelledby": n, children: [m("div", { className: "react-paint-editor-modal-mask", onClick: t }), m("div", { className: `react-paint-editor-modal-panel ${a}`, children: e })] }), Mt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: n = "fill", disabled: a = !1, values: o, field: d, value: r = "", valueChanged: s }) => {
1499
- const [l] = $(ue("settings_")), h = e === l;
1500
- return o.length ? q(Ae, { children: [m(J, { selected: h, title: i, disabled: a, onClick: () => {
1501
- t((c) => c === l ? void 0 : l);
1502
- }, icon: r === "transparent" ? n === "fill" ? Ii : Ei : void 0, children: r !== "transparent" && m("div", { className: "react-paint-editor-colorfield-color", "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": r } }) }), h && m(nt, { title: i, alignment: "left", children: q("div", { className: "react-paint-editor-colorfield-wrapper", children: [o.map((c) => m(J, { title: c, selected: c === r, color: c, icon: c === "transparent" ? n === "fill" ? Ii : Ei : void 0, onClick: () => {
1503
- s(d, c);
1504
- }, children: c !== "transparent" && m("div", { className: "react-paint-editor-colorfield-color", color: c, "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": c } }) }, c)), m(J, { type: "color", title: "Custom color", selected: r !== "" && !o.includes(r), value: r, onChange: (c) => {
1505
- const u = +c.target.value;
1506
- s(d, Number.isNaN(u) ? c.target.value : u);
1507
- }, children: m("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": o.includes(r) ? "var(--react-paint-editor-app-font-color)" : r }, children: m("span", { dangerouslySetInnerHTML: { __html: '<svg><path d="M9.958 18.333Q8.25 18.333 6.74 17.677Q5.229 17.021 4.104 15.885Q2.979 14.75 2.323 13.229Q1.667 11.708 1.667 10Q1.667 8.271 2.333 6.75Q3 5.229 4.156 4.104Q5.312 2.979 6.854 2.323Q8.396 1.667 10.125 1.667Q11.771 1.667 13.26 2.25Q14.75 2.833 15.875 3.854Q17 4.875 17.667 6.26Q18.333 7.646 18.333 9.25Q18.333 11.688 16.792 12.948Q15.25 14.208 13.188 14.208H11.75Q11.625 14.208 11.562 14.281Q11.5 14.354 11.5 14.458Q11.5 14.688 11.812 15.219Q12.125 15.75 12.125 16.458Q12.125 17.458 11.51 17.896Q10.896 18.333 9.958 18.333ZM5.458 10.875Q6 10.875 6.375 10.5Q6.75 10.125 6.75 9.583Q6.75 9.042 6.375 8.667Q6 8.292 5.458 8.292Q4.917 8.292 4.542 8.667Q4.167 9.042 4.167 9.583Q4.167 10.125 4.542 10.5Q4.917 10.875 5.458 10.875ZM7.917 7.583Q8.458 7.583 8.833 7.208Q9.208 6.833 9.208 6.292Q9.208 5.75 8.833 5.375Q8.458 5 7.917 5Q7.375 5 7 5.375Q6.625 5.75 6.625 6.292Q6.625 6.833 7 7.208Q7.375 7.583 7.917 7.583ZM12.021 7.583Q12.562 7.583 12.938 7.208Q13.312 6.833 13.312 6.292Q13.312 5.75 12.938 5.375Q12.562 5 12.021 5Q11.479 5 11.104 5.375Q10.729 5.75 10.729 6.292Q10.729 6.833 11.104 7.208Q11.479 7.583 12.021 7.583ZM14.479 10.875Q15.021 10.875 15.396 10.5Q15.771 10.125 15.771 9.583Q15.771 9.042 15.396 8.667Q15.021 8.292 14.479 8.292Q13.938 8.292 13.562 8.667Q13.188 9.042 13.188 9.583Q13.188 10.125 13.562 10.5Q13.938 10.875 14.479 10.875Z"/></svg>' } }) }) })] }) })] }) : null;
1508
- }, Uo = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => m(J, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1509
- i(Y(t));
1510
- }, icon: Hn }), Bt = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: n = "Choisissez l'option", disabled: a = !1, field: o, icon: d, values: r, defaultValue: s, valueChanged: l }) => {
1511
- const [h] = $(ue("settings_")), c = t === h;
1512
- return r.length ? q(Ae, { children: [m(J, { selected: c, title: n, icon: d, disabled: a, onClick: () => {
1513
- i((u) => u === h ? void 0 : h);
1514
- } }), c && m(nt, { title: n, alignment: "left", fitContainer: !0, children: m("div", { className: "react-paint-editor-selectfield-wrapper", children: r.map((u) => m(J, { title: `${u}`, onClick: () => ((f) => {
1515
- l(o, f);
1516
- })(u), selected: s === u, style: { "--react-paint-editor-button-padding": "16px" }, children: m(e, { children: u }) }, u)) }) })] }) : null;
1517
- }, qo = ({ children: e }) => m("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), bn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? m(Bt, { selectedSettings: e, setSelectedSettings: t, CustomOption: qo, title: "Police", icon: '<svg><path d="M5.312 14.979H7.125L8.042 12.479H11.979L12.896 14.979H14.708L10.917 5H9.083ZM8.542 10.958 9.958 6.958H10.042L11.458 10.958ZM3.417 18.333Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V3.417Q1.667 2.688 2.177 2.177Q2.688 1.667 3.417 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417V16.583Q18.333 17.312 17.823 17.823Q17.312 18.333 16.583 18.333ZM3.417 16.583H16.583Q16.583 16.583 16.583 16.583Q16.583 16.583 16.583 16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583ZM3.417 3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583V3.417Q3.417 3.417 3.417 3.417Q3.417 3.417 3.417 3.417Z"/></svg>', disabled: i, field: "fontFamily", values: n, defaultValue: a, valueChanged: o }) : null, Go = ({ disabled: e, toggleLayoutPanel: t }) => m(J, { title: "Toggle layers panel", disabled: e, onClick: t, icon: '<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>', className: "react-paint-editor-layout-button" }), _o = ({ children: e }) => q("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [m("span", { className: "react-paint-editor-linearrow-left" }), m("span", { className: "react-paint-editor-linearrow-right" })] }), wn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? m(Bt, { selectedSettings: e, setSelectedSettings: t, CustomOption: _o, title: "Flèches", icon: '<svg><path d="M6 17 2 13 6 9 7.062 10.062 4.875 12.25H17V13.75H4.875L7.062 15.938ZM14 11 12.938 9.938 15.125 7.75H3V6.25H15.125L12.938 4.062L14 3L18 7Z"/></svg>', disabled: i, field: "lineArrow", values: n, defaultValue: a, valueChanged: o }) : null, jo = ({ children: e }) => q("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [m("span", {}), m("span", {}), m("span", {}), m("span", {}), m("span", {}), m("span", {}), m("span", {})] }), xn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: a, valueChanged: o }) => n.length ? m(Bt, { selectedSettings: e, setSelectedSettings: t, CustomOption: jo, icon: '<svg><path d="M3 16V14.5H4.5V16ZM6.125 16V14.5H7.625V16ZM9.25 16V14.5H10.75V16ZM12.375 16V14.5H13.875V16ZM15.5 16V14.5H17V16ZM3 13V11.5H6.5V13ZM8.25 13V11.5H11.75V13ZM13.5 13V11.5H17V13ZM3 10V8.5H9.25V10ZM10.75 10V8.5H17V10ZM3 7V4H17V7Z"/></svg>', title: "Type de traits", disabled: i, field: "lineDash", values: n, defaultValue: a, valueChanged: o }) : null, Pt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: n, disabled: a = !1, field: o, value: d, min: r = 1, max: s = 20, step: l = 1, unity: h = "", valueChanged: c, saveShapes: u }) => {
1518
- const f = d === void 0, v = f ? "N/A" : `${Math.round(d)}${h}`, [p] = $(ue("settings_")), S = ((b, Q = 500) => {
1519
- const g = ne(null), w = X((...L) => {
1520
- g.current && clearTimeout(g.current), g.current = setTimeout(() => b(...L), Q);
1521
- }, [b, Q]);
1522
- return ee(() => () => {
1523
- g.current && clearTimeout(g.current);
1524
- }, []), w;
1525
- })(u), C = e === p;
1526
- return r === s ? null : q(Ae, { children: [m(J, { selected: C, title: i, disabled: a, icon: n, onClick: () => {
1527
- t((b) => b === p ? void 0 : p);
1528
- } }), C && m(nt, { title: i, alignment: "left", fitContainer: !0, children: m("div", { children: q("label", { className: "react-paint-editor-rangefield", children: [m("input", { type: "range", min: r, max: s, step: l, value: d ?? (s + r) / 2, "data-indeterminate": +f, onChange: (b) => {
1529
- const Q = +b.target.value, g = Number.isNaN(Q) ? b.target.value : Q;
1530
- c(o, g, !1), S();
1531
- } }), m("span", { children: v })] }) }) })] });
1532
- }, Ko = ({ children: e }) => m("span", { children: e === 0 ? "Non" : "Oui" }), Jo = [0, 1], Cn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: n, valueChanged: a }) => m(Bt, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ko, title: "Fermer les points", icon: gi, disabled: i, field: "closedPoints", values: Jo, defaultValue: n, valueChanged: a }), es = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => m(J, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: Dn, className: t ? ` ${t}` : "" }), kt = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: n, values: a, value: o = !1, valueChanged: d }) => {
1533
- const [r] = $(ue("settings_"));
1534
- return a.length !== 2 ? null : m(J, { onClick: () => {
1535
- e((s) => s === r ? void 0 : r), d(i, !o);
1536
- }, selected: o, disabled: t, icon: n });
1537
- }, ni = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: n, selectedSettings: a, setSelectedSettings: o, saveShapes: d, handleShapeStyleChange: r, handleShapeFontFamilyChange: s }) => t ? i && q(Ae, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: t.style?.strokeColor, valueChanged: r, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: t.style?.fillColor, valueChanged: r, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", icon: Di, disabled: n, field: "lineWidth", value: t.style?.lineWidth, valueChanged: r, unity: "px", min: i.settings.lineWidth.min, max: i.settings.lineWidth.max, step: i.settings.lineWidth.step }), "lineDash" in i.settings && !i.settings.lineDash.hidden && m(xn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineDash, valueChanged: r, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && m(wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: t.style?.lineArrow, valueChanged: r, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && m(Cn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: r, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && m(bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: Ti, valueChanged: s, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: Ai, valueChanged: s, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: zi, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: t.style?.opacity, valueChanged: r })] }) : "settings" in e ? q(Ae, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: r, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && m(Mt, { selectedSettings: a, setSelectedSettings: o, title: "Couleur de fond", disabled: n, field: "fillColor", value: e.settings.fillColor.default, valueChanged: r, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Epaisseur du trait", disabled: n, field: "lineWidth", icon: Di, value: e.settings.lineWidth.default, valueChanged: r, unity: "px", min: e.settings.lineWidth.min, max: e.settings.lineWidth.max, step: e.settings.lineWidth.step }), "lineDash" in e.settings && !e.settings.lineDash.hidden && m(xn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineDash.default, valueChanged: r, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && m(wn, { selectedSettings: a, setSelectedSettings: o, disabled: n, defaultValue: e.settings.lineArrow.default, valueChanged: r, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && m(Cn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: r, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && m(bn, { selectedSettings: a, setSelectedSettings: o, disabled: n, valueChanged: s, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontBold", icon: Ti, valueChanged: s, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && m(kt, { setSelectedSettings: o, disabled: n, field: "fontItalic", icon: Ai, valueChanged: s, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && m(Pt, { saveShapes: d, selectedSettings: a, setSelectedSettings: o, title: "Opacité", icon: zi, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: e.settings.opacity.default, valueChanged: r })] }) : null, ts = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: n = !1, toggleLayoutPanel: a, activeTool: o, saveShapes: d, selectedShape: r, canvas: s, settings: l, updateShape: h, removeShape: c, isZoomPanelShown: u, setIsZoomPanelShown: f }) => {
1538
- const [v, p] = $(void 0), [S, C] = $(!1), b = l.size === "infinite" || l.features.zoom, Q = !l.features.edition, g = () => {
1539
- C((Z) => !Z);
1540
- }, w = ((Z, A) => {
1541
- const H = Y(Z).map((E) => A.find((W) => W.id === E?.toolId) || A.find((W) => W.type === E?.type)).filter((E) => E !== void 0);
1542
- if (!H.length) return;
1543
- if (H.length === 1) return H[0];
1544
- const F = H.slice(1).reduce((E, W) => {
1545
- const G = {};
1546
- for (const _ in W.settings) {
1547
- if (E[_] === void 0 || W.settings[_]?.hidden || E[_]?.hidden) continue;
1548
- const z = E[_], y = W.settings[_], M = {};
1549
- "min" in y && "min" in z && y.min === z.min && "max" in y && "max" in z && y.max === z.max && "step" in y && "step" in z && y.step === z.step && (M.min = y.min, M.max = y.max, M.step = y.step), "values" in y && "values" in z && y.values?.join(",") === z.values?.join(",") && (M.values = y.values), (Object.keys(M).length > 0 || _ === "closedPoints") && (G[_] = M);
1554
+ }, [f, p, m, S, w, x, u]), { isOver: b };
1555
+ })({ disabled: e, ref: h, shape: t, layoutDragging: n, setLayoutDragging: r, handleSelect: s, onSwapShapes: d });
1556
+ return G("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(n === t.id), "data-is-over": +c, onClick: (f) => {
1557
+ e || (f.preventDefault(), s([t]));
1558
+ }, "data-selected": +i, ref: h, tabIndex: -1, children: [v("span", { dangerouslySetInnerHTML: { __html: ss(t.type) } }), v("span", { children: t.id }), v("div", { className: "react-paint-editor-layouts-separator" }), v(q, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (f) => {
1559
+ e || (f.preventDefault(), f.stopPropagation(), o([t]));
1560
+ }, icon: t.visible === !1 ? '<svg><path d="M13.521 11.021 12.25 9.75Q12.333 8.75 11.604 7.979Q10.875 7.208 9.812 7.312L8.542 6.042Q8.896 5.896 9.26 5.833Q9.625 5.771 10 5.771Q11.583 5.771 12.688 6.875Q13.792 7.979 13.792 9.562Q13.792 9.979 13.719 10.354Q13.646 10.729 13.521 11.021ZM16.167 13.646 14.917 12.417Q15.667 11.833 16.25 11.146Q16.833 10.458 17.25 9.562Q16.229 7.479 14.292 6.281Q12.354 5.083 10 5.083Q9.396 5.083 8.885 5.156Q8.375 5.229 7.875 5.375L6.5 4Q7.354 3.646 8.208 3.49Q9.062 3.333 10 3.333Q13.146 3.333 15.615 5.052Q18.083 6.771 19.167 9.562Q18.688 10.792 17.917 11.823Q17.146 12.854 16.167 13.646ZM16.396 18.854 12.938 15.396Q12.208 15.625 11.479 15.729Q10.75 15.833 10 15.833Q6.833 15.833 4.375 14.094Q1.917 12.354 0.833 9.562Q1.25 8.479 1.917 7.552Q2.583 6.625 3.417 5.875L1.125 3.562L2.375 2.354L17.625 17.625ZM4.604 7.062Q4.021 7.604 3.542 8.219Q3.062 8.833 2.729 9.562Q3.75 11.646 5.688 12.865Q7.625 14.083 10 14.083Q10.354 14.083 10.74 14.052Q11.125 14.021 11.479 13.938L10.812 13.271Q10.625 13.312 10.417 13.333Q10.208 13.354 10 13.354Q8.417 13.354 7.312 12.25Q6.208 11.146 6.208 9.562Q6.208 9.354 6.24 9.167Q6.271 8.979 6.312 8.771ZM11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875Q11.375 8.875 11.375 8.875ZM8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Q8.042 10.5 8.042 10.5Z"/></svg>' : '<svg><path d="M10 13.354Q11.583 13.354 12.688 12.25Q13.792 11.146 13.792 9.562Q13.792 7.979 12.688 6.875Q11.583 5.771 10 5.771Q8.417 5.771 7.312 6.875Q6.208 7.979 6.208 9.562Q6.208 11.146 7.312 12.25Q8.417 13.354 10 13.354ZM10 11.812Q9.062 11.812 8.406 11.156Q7.75 10.5 7.75 9.562Q7.75 8.625 8.406 7.969Q9.062 7.312 10 7.312Q10.938 7.312 11.594 7.969Q12.25 8.625 12.25 9.562Q12.25 10.5 11.594 11.156Q10.938 11.812 10 11.812ZM10 15.833Q6.938 15.833 4.448 14.125Q1.958 12.417 0.833 9.562Q1.958 6.708 4.458 5.021Q6.958 3.333 10 3.333Q13.042 3.333 15.542 5.021Q18.042 6.708 19.167 9.562Q18.042 12.417 15.552 14.125Q13.062 15.833 10 15.833ZM10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562Q10 9.562 10 9.562ZM10 14.083Q12.333 14.083 14.281 12.865Q16.229 11.646 17.25 9.562Q16.229 7.479 14.281 6.281Q12.333 5.083 10 5.083Q7.667 5.083 5.708 6.281Q3.75 7.479 2.729 9.562Q3.75 11.646 5.708 12.865Q7.667 14.083 10 14.083Z"/></svg>' }), v(q, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (f) => {
1561
+ e || (f.preventDefault(), f.stopPropagation(), a([t]));
1562
+ }, icon: t.locked ? '<svg><path d="M10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H5.792V5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833ZM10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042V6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' : '<svg><path d="M5.792 5.042Q5.792 3.271 7.01 2.052Q8.229 0.833 10 0.833Q11.771 0.833 12.99 2.052Q14.208 3.271 14.208 5.042V6.667H14.917Q15.646 6.667 16.156 7.177Q16.667 7.688 16.667 8.417V16.562Q16.667 17.292 16.156 17.812Q15.646 18.333 14.917 18.333H5.083Q4.354 18.333 3.844 17.812Q3.333 17.292 3.333 16.562V8.417Q3.333 7.688 3.844 7.177Q4.354 6.667 5.083 6.667H12.458V5.042Q12.458 4.021 11.74 3.302Q11.021 2.583 10 2.583Q8.979 2.583 8.26 3.302Q7.542 4.021 7.542 5.042ZM5.083 16.583H14.917Q14.917 16.583 14.917 16.583Q14.917 16.583 14.917 16.583V8.417Q14.917 8.417 14.917 8.417Q14.917 8.417 14.917 8.417H5.083Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583ZM10 10.812Q9.292 10.812 8.802 11.302Q8.312 11.792 8.312 12.5Q8.312 13.208 8.802 13.698Q9.292 14.188 10 14.188Q10.708 14.188 11.198 13.698Q11.688 13.208 11.688 12.5Q11.688 11.792 11.198 11.302Q10.708 10.812 10 10.812ZM5.083 8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417V16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583Q5.083 16.583 5.083 16.583V8.417Q5.083 8.417 5.083 8.417Q5.083 8.417 5.083 8.417Z"/></svg>' }), v(q, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (f) => {
1563
+ e || (f.preventDefault(), f.stopPropagation(), l([t]));
1564
+ }, icon: Un })] });
1565
+ }, ls = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: n, removeShape: o, toggleShapeVisibility: a, toggleShapeLock: r, selectedShapes: l, swapShapes: s, selectShapes: d, isLayoutPanelShown: h }) => {
1566
+ const [c, f] = K(void 0), p = !i.features.edition;
1567
+ return h ? v(yt, { alignment: "right", className: "react-paint-editor-layouts-panel", position: "bottom", children: v("div", { className: "react-paint-editor-layouts-panel-content", children: G("div", { className: "react-paint-editor-layouts-scrolling-content", children: [G("div", { className: "react-paint-editor-layouts-row", children: [v("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), v(q, { icon: '<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>', className: "react-paint-editor-layouts-grid-button", selected: e === "none", disabled: p, onClick: () => t("none") }), ["small", "medium", "large"].map((m) => v(q, { className: "react-paint-editor-layouts-grid-button", selected: e === m, disabled: p, onClick: () => t(m), children: m.charAt(0).toUpperCase() }, m))] }), v("hr", {}), v("div", { className: "react-paint-editor-layouts", children: n.length === 0 ? v("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : n.map((m) => v(rs, { shape: m, disabled: p, layoutDragging: c, setLayoutDragging: f, selected: U(l).some((u) => u.id === m.id) ?? !1, handleSelect: d, handleRemove: o, onSwapShapes: s, toggleShapeVisibility: a, toggleShapeLock: r }, m.id)) })] }) }) }) : null;
1568
+ }, si = ({ children: e, onClose: t, position: i = "center", title: n, className: o = "" }) => G("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": Kn }, role: "dialog", "aria-modal": "true", "aria-labelledby": n, children: [v("div", { className: "react-paint-editor-modal-mask", onClick: t }), v("div", { className: `react-paint-editor-modal-panel ${o}`, children: e })] }), Yt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: n = "fill", disabled: o = !1, values: a, field: r, value: l = "", valueChanged: s }) => {
1569
+ const [d] = K(Ce("settings_")), h = e === d;
1570
+ return a.length ? G(Ne, { children: [v(q, { selected: h, title: i, disabled: o, onClick: () => {
1571
+ t((c) => c === d ? void 0 : d);
1572
+ }, icon: l === "transparent" ? n === "fill" ? en : Ji : void 0, children: l !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": l } }) }), h && v(yt, { title: i, alignment: "left", position: "bottom", children: G("div", { className: "react-paint-editor-colorfield-wrapper", children: [a.map((c) => v(q, { title: c, selected: c === l, color: c, icon: c === "transparent" ? n === "fill" ? en : Ji : void 0, onClick: () => {
1573
+ s(r, c);
1574
+ }, children: c !== "transparent" && v("div", { className: "react-paint-editor-colorfield-color", color: c, "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": c } }) }, c)), v(q, { type: "color", title: "Custom color", selected: l !== "" && !a.includes(l), value: l, onChange: (c) => {
1575
+ const f = +c.target.value;
1576
+ s(r, Number.isNaN(f) ? c.target.value : f);
1577
+ }, children: v("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": a.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;
1578
+ }, ds = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => v(q, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
1579
+ i(U(t));
1580
+ }, icon: Un }), ri = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: n = "Choisissez l'option", disabled: o = !1, field: a, icon: r, values: l, defaultValue: s, valueChanged: d }) => {
1581
+ const [h] = K(Ce("settings_")), c = t === h;
1582
+ return l.length ? G(Ne, { children: [v(q, { selected: c, title: n, icon: r, disabled: o, onClick: () => {
1583
+ i((f) => f === h ? void 0 : h);
1584
+ } }), c && v(yt, { title: n, alignment: "left", fitContainer: !0, position: "bottom", children: v("div", { className: "react-paint-editor-selectfield-wrapper", children: l.map((f) => v(q, { title: `${f}`, onClick: () => ((p) => {
1585
+ d(a, p);
1586
+ })(f), selected: s === f, style: { "--react-paint-editor-button-padding": "16px" }, children: v(e, { children: f }) }, f)) }) })] }) : null;
1587
+ }, cs = ({ children: e }) => v("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), In = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: o, valueChanged: a }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: cs, 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: o, valueChanged: a }) : null, hs = ({ disabled: e, toggleLayoutPanel: t }) => v(q, { title: "Toggle layers panel", disabled: e, onClick: t, icon: '<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>', className: "react-paint-editor-layout-button" }), ps = ({ children: e }) => G("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [v("span", { className: "react-paint-editor-linearrow-left" }), v("span", { className: "react-paint-editor-linearrow-right" })] }), Rn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: o, valueChanged: a }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: ps, 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: o, valueChanged: a }) : null, us = ({ children: e }) => G("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", {})] }), Wn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: o, valueChanged: a }) => n.length ? v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: us, 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: o, valueChanged: a }) : null, Xt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: n, disabled: o = !1, field: a, value: r, min: l = 1, max: s = 20, step: d = 1, unity: h = "", valueChanged: c, saveShapes: f }) => {
1588
+ const p = r === void 0, m = p ? "N/A" : `${Math.round(r)}${h}`, [u] = K(Ce("settings_")), S = ((x, b = 500) => {
1589
+ const y = re(null), g = X((...P) => {
1590
+ y.current && clearTimeout(y.current), y.current = setTimeout(() => x(...P), b);
1591
+ }, [x, b]);
1592
+ return le(() => () => {
1593
+ y.current && clearTimeout(y.current);
1594
+ }, []), g;
1595
+ })(f), w = e === u;
1596
+ return l === s ? null : G(Ne, { children: [v(q, { selected: w, title: i, disabled: o, icon: n, onClick: () => {
1597
+ t((x) => x === u ? void 0 : u);
1598
+ } }), w && v(yt, { title: i, alignment: "left", fitContainer: !0, position: "bottom", children: v("div", { children: G("label", { className: "react-paint-editor-rangefield", children: [v("input", { type: "range", min: l, max: s, step: d, value: r ?? (s + l) / 2, "data-indeterminate": +p, onChange: (x) => {
1599
+ const b = +x.target.value, y = Number.isNaN(b) ? x.target.value : b;
1600
+ c(a, y, !1), S();
1601
+ } }), v("span", { children: m })] }) }) })] });
1602
+ }, gs = ({ children: e }) => v("span", { children: e === 0 ? "Non" : "Oui" }), fs = [0, 1], Nn = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, defaultValue: n, valueChanged: o }) => v(ri, { selectedSettings: e, setSelectedSettings: t, CustomOption: gs, title: "Fermer les points", icon: Zi, disabled: i, field: "closedPoints", values: fs, defaultValue: n, valueChanged: o }), vs = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => v(q, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: jn, className: t ? ` ${t}` : "" }), $t = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: n, values: o, value: a = !1, valueChanged: r }) => {
1603
+ const [l] = K(Ce("settings_"));
1604
+ return o.length !== 2 ? null : v(q, { onClick: () => {
1605
+ e((s) => s === l ? void 0 : l), r(i, !a);
1606
+ }, selected: a, disabled: t, icon: n });
1607
+ }, Si = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: n, selectedSettings: o, setSelectedSettings: a, saveShapes: r, handleShapeStyleChange: l, handleShapeFontFamilyChange: s }) => t ? i && G(Ne, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && v(Yt, { selectedSettings: o, setSelectedSettings: a, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: t.style?.strokeColor, valueChanged: l, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && v(Yt, { selectedSettings: o, setSelectedSettings: a, title: "Couleur de fond", disabled: n, field: "fillColor", value: t.style?.fillColor, valueChanged: l, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && v(Xt, { saveShapes: r, selectedSettings: o, setSelectedSettings: a, title: "Epaisseur du trait", icon: Ki, disabled: n, field: "lineWidth", value: t.style?.lineWidth, valueChanged: l, unity: "px", min: i.settings.lineWidth.min, max: i.settings.lineWidth.max, step: i.settings.lineWidth.step }), "lineDash" in i.settings && !i.settings.lineDash.hidden && v(Wn, { selectedSettings: o, setSelectedSettings: a, disabled: n, defaultValue: t.style?.lineDash, valueChanged: l, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && v(Rn, { selectedSettings: o, setSelectedSettings: a, disabled: n, defaultValue: t.style?.lineArrow, valueChanged: l, values: i.settings.lineArrow.values }), "closedPoints" in i.settings && !i.settings.closedPoints.hidden && v(Nn, { selectedSettings: o, setSelectedSettings: a, disabled: n, valueChanged: l, defaultValue: t.style?.closedPoints }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && v(In, { selectedSettings: o, setSelectedSettings: a, disabled: n, valueChanged: s, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && v($t, { setSelectedSettings: a, disabled: n, field: "fontBold", icon: _i, valueChanged: s, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && v($t, { setSelectedSettings: a, disabled: n, field: "fontItalic", icon: ji, valueChanged: s, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && v(Xt, { saveShapes: r, selectedSettings: o, setSelectedSettings: a, title: "Opacité", icon: qi, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: t.style?.opacity, valueChanged: l })] }) : "settings" in e ? G(Ne, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && v(Yt, { selectedSettings: o, setSelectedSettings: a, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: l, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && v(Yt, { selectedSettings: o, setSelectedSettings: a, title: "Couleur de fond", disabled: n, field: "fillColor", value: e.settings.fillColor.default, valueChanged: l, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && v(Xt, { saveShapes: r, selectedSettings: o, setSelectedSettings: a, title: "Epaisseur du trait", disabled: n, field: "lineWidth", icon: Ki, value: e.settings.lineWidth.default, valueChanged: l, unity: "px", min: e.settings.lineWidth.min, max: e.settings.lineWidth.max, step: e.settings.lineWidth.step }), "lineDash" in e.settings && !e.settings.lineDash.hidden && v(Wn, { selectedSettings: o, setSelectedSettings: a, disabled: n, defaultValue: e.settings.lineDash.default, valueChanged: l, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && v(Rn, { selectedSettings: o, setSelectedSettings: a, disabled: n, defaultValue: e.settings.lineArrow.default, valueChanged: l, values: e.settings.lineArrow.values }), "closedPoints" in e.settings && !e.settings.closedPoints.hidden && v(Nn, { selectedSettings: o, setSelectedSettings: a, disabled: n, valueChanged: l, defaultValue: e.settings?.closedPoints.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && v(In, { selectedSettings: o, setSelectedSettings: a, disabled: n, valueChanged: s, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && v($t, { setSelectedSettings: a, disabled: n, field: "fontBold", icon: _i, valueChanged: s, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && v($t, { setSelectedSettings: a, disabled: n, field: "fontItalic", icon: ji, valueChanged: s, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && v(Xt, { saveShapes: r, selectedSettings: o, setSelectedSettings: a, title: "Opacité", icon: qi, min: e.settings.opacity.min, max: e.settings.opacity.max, step: e.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: e.settings.opacity.default, valueChanged: l })] }) : null, ms = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: n = !1, toggleLayoutPanel: o, activeTool: a, saveShapes: r, selectedShape: l, canvas: s, settings: d, updateShape: h, removeShape: c, isZoomPanelShown: f, setIsZoomPanelShown: p }) => {
1608
+ const [m, u] = K(void 0), [S, w] = K(!1), x = d.size === "infinite" || d.features.zoom, b = !d.features.edition, y = () => {
1609
+ w((H) => !H);
1610
+ }, g = ((H, Z) => {
1611
+ const E = U(H).map((W) => Z.find((I) => I.id === W?.toolId) || Z.find((I) => I.type === W?.type)).filter((W) => W !== void 0);
1612
+ if (!E.length) return;
1613
+ if (E.length === 1) return E[0];
1614
+ const F = E.slice(1).reduce((W, I) => {
1615
+ const oe = {};
1616
+ for (const te in I.settings) {
1617
+ if (W[te] === void 0 || I.settings[te]?.hidden || W[te]?.hidden) continue;
1618
+ const R = W[te], $ = I.settings[te], j = {};
1619
+ "min" in $ && "min" in R && $.min === R.min && "max" in $ && "max" in R && $.max === R.max && "step" in $ && "step" in R && $.step === R.step && (j.min = $.min, j.max = $.max, j.step = $.step), "values" in $ && "values" in R && $.values?.join(",") === R.values?.join(",") && (j.values = $.values), (Object.keys(j).length > 0 || te === "closedPoints") && (oe[te] = j);
1550
1620
  }
1551
- return G;
1552
- }, H[0].settings);
1553
- return { id: H.map((E) => E.id).join("-"), icon: "", label: "group", type: "group", settings: F };
1554
- })(r, t), L = (w ? Object.keys(w.settings).length + 1 : "settings" in o ? Object.keys(o.settings).length : 0) + +n + +b, D = e < 40 * L, V = (Z, A, H = !0) => {
1555
- if (Y(r).length) {
1556
- const F = Y(r).map((E) => Ne(Le(["style", Z], A, E), l));
1557
- h(F, H), w && i(w.id, Z, A);
1558
- } else i(o.id, Z, A);
1559
- }, x = (Z, A) => {
1560
- if (Y(r).length) {
1561
- const H = Y(r).map((F) => {
1621
+ return oe;
1622
+ }, E[0].settings);
1623
+ return { id: E.map((W) => W.id).join("-"), icon: "", label: "group", type: "group", settings: F };
1624
+ })(l, t), P = (g ? Object.keys(g.settings).length + 1 : "settings" in a ? Object.keys(a.settings).length : 0) + +n + +x, z = e < 40 * P, D = (H, Z, E = !0) => {
1625
+ if (U(l).length) {
1626
+ const F = U(l).map((W) => _e(Xe(["style", H], Z, W), d));
1627
+ h(F, E), g && i(g.id, H, Z);
1628
+ } else i(a.id, H, Z);
1629
+ }, A = (H, Z) => {
1630
+ if (U(l).length) {
1631
+ const E = U(l).map((F) => {
1562
1632
  if (F.type !== "text") return F;
1563
- const E = s?.getContext("2d");
1564
- if (!E) return F;
1565
- const W = Le(["style", Z], A, F), G = Rt(E, W.value, W.width, W.style?.fontBold ?? !1, W.style?.fontItalic ?? !1, W.style?.fontFamily);
1566
- return Ne({ ...W, fontSize: G, height: G * W.value.length }, l);
1633
+ const W = s?.getContext("2d");
1634
+ if (!W) return F;
1635
+ const I = Xe(["style", H], Z, F), oe = ai(W, I.value, I.width, I.style?.fontBold ?? !1, I.style?.fontItalic ?? !1, I.style?.fontFamily);
1636
+ return _e({ ...I, fontSize: oe, height: oe * I.value.length }, d);
1567
1637
  });
1568
- h(H, !0), w && i(w.id, Z, A);
1569
- } else i(o.id, Z, A);
1638
+ h(E, !0), g && i(g.id, H, Z);
1639
+ } else i(a.id, H, Z);
1570
1640
  };
1571
- return q(Ae, { children: [q("div", { className: "react-paint-editor-settings-bar", children: [q("div", { className: "react-paint-editor-settings-shrinkable", children: [b && m(es, { className: u ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1572
- f((Z) => !Z);
1573
- } }), D && L > 2 && m(J, { disabled: Q, onClick: g, title: "Toggle settings", icon: '<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>' }), r ? w && q(Ae, { children: [!D && m(ni, { saveShapes: d, activeTool: o, selectedShape: r, selectedShapeTool: w, disabled: Q, selectedSettings: v, setSelectedSettings: p, handleShapeStyleChange: V, handleShapeFontFamilyChange: x }), o.type === "selection" && m(Uo, { disabled: Q, selectedShape: r, removeShape: c })] }) : !D && m(ni, { saveShapes: d, activeTool: o, selectedShape: r, selectedShapeTool: w, disabled: Q, selectedSettings: v, setSelectedSettings: p, handleShapeStyleChange: V, handleShapeFontFamilyChange: x })] }), m("div", { className: "react-paint-editor-settings-separator" }), n && m(Go, { disabled: Q, toggleLayoutPanel: a })] }), S && m(Nt, { className: "react-paint-editor-settings-modal", onClose: g, position: "bottom", title: "Settings", children: m(ni, { saveShapes: d, activeTool: o, selectedShape: r, selectedShapeTool: w, disabled: Q, selectedSettings: v, setSelectedSettings: p, handleShapeStyleChange: V, handleShapeFontFamilyChange: x }) })] });
1574
- }, Mn = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: n, img: a, accept: o }) => {
1575
- const d = ne(null);
1576
- return m(J, { ref: d, type: "file", onClick: (r) => {
1577
- r.stopPropagation(), d.current && (d.current.value = "");
1578
- }, onChange: (r) => {
1579
- const s = r.target.files?.item(0);
1641
+ return G(Ne, { children: [G("div", { className: "react-paint-editor-settings-bar", children: [G("div", { className: "react-paint-editor-settings-shrinkable", children: [x && v(vs, { className: f ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
1642
+ p((H) => !H);
1643
+ } }), z && P > 2 && v(q, { disabled: b, onClick: y, title: "Toggle settings", icon: '<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>' }), l ? g && G(Ne, { children: [!z && v(Si, { saveShapes: r, activeTool: a, selectedShape: l, selectedShapeTool: g, disabled: b, selectedSettings: m, setSelectedSettings: u, handleShapeStyleChange: D, handleShapeFontFamilyChange: A }), a.type === "selection" && v(ds, { disabled: b, selectedShape: l, removeShape: c })] }) : !z && v(Si, { saveShapes: r, activeTool: a, selectedShape: l, selectedShapeTool: g, disabled: b, selectedSettings: m, setSelectedSettings: u, handleShapeStyleChange: D, handleShapeFontFamilyChange: A })] }), v("div", { className: "react-paint-editor-settings-separator" }), n && v(hs, { disabled: b, toggleLayoutPanel: o })] }), S && v(si, { className: "react-paint-editor-settings-modal", onClose: y, position: "bottom", title: "Settings", children: v(Si, { saveShapes: r, activeTool: a, selectedShape: l, selectedShapeTool: g, disabled: b, selectedSettings: m, setSelectedSettings: u, handleShapeStyleChange: D, handleShapeFontFamilyChange: A }) })] });
1644
+ }, qt = ({ alignment: e, children: t, className: i, style: n, position: o }) => v(yt, { alignment: e, position: o, className: i, style: n, children: v("div", { className: "react-paint-editor-menu", role: "menu", children: t }) }), On = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: n, img: o, accept: a }) => {
1645
+ const r = re(null);
1646
+ return v(q, { ref: r, type: "file", onClick: () => {
1647
+ r.current && (r.current.value = "");
1648
+ }, onChange: (l) => {
1649
+ const s = l.target.files?.item(0);
1580
1650
  s && i(s);
1581
- }, accept: o, title: n.label ?? n.type, icon: a, disabled: e, children: t ? n.label : void 0 });
1582
- }, ke = ({ type: e, img: t, isActive: i, withText: n = !1, disabled: a = !1, setActive: o }) => m(J, { disabled: a, selected: i, onClick: () => {
1583
- o(e);
1584
- }, title: e.label ?? e.type, icon: t, children: n ? e.label : void 0 }), is = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: n = !1, hasActionToClear: a = !1, undoAction: o, redoAction: d, clearCanvas: r, alignment: s, group: l, vertical: h = !1, disabled: c = !1, withLoadAndSave: u, withExport: f, addPicture: v, loadFile: p, togglePictureUrlModal: S, saveFile: C, toggleExportModal: b, withUploadPicture: Q, withUrlPicture: g }) => {
1585
- const [w, L] = $(!1), [, D] = Vn(), V = l?.tools?.some((Z) => Z === e.type), x = (V ? e.icon : l.img) ?? l.title;
1586
- return ee(() => {
1587
- if (!w) return;
1588
- const Z = () => {
1589
- L(!1);
1590
- };
1591
- return document.addEventListener("click", Z), () => {
1592
- document.removeEventListener("click", Z);
1651
+ }, accept: a, title: n.label ?? n.type, icon: o, disabled: e, children: t ? n.label : void 0 });
1652
+ }, Re = ({ type: e, img: t, isActive: i, withText: n = !1, disabled: o = !1, setActive: a }) => v(q, { disabled: o, selected: i, onClick: () => {
1653
+ a(e);
1654
+ }, title: e.label ?? e.type, icon: t, children: n ? e.label : void 0 }), No = (e, t) => !!(e.target instanceof Node && t) && t.contains(e.target), Pi = ({ trigger: e = "click", buttonElt: t }) => {
1655
+ const [i, n] = K(!1), [, o] = Xn(), a = X(() => {
1656
+ o(() => {
1657
+ n(!1);
1658
+ });
1659
+ }, []);
1660
+ return le(() => {
1661
+ if (!t) return;
1662
+ if (i) {
1663
+ const l = (d) => {
1664
+ No(d, t) || o(() => {
1665
+ n(!1);
1666
+ });
1667
+ }, s = () => {
1668
+ o(() => {
1669
+ n(!1);
1670
+ });
1671
+ };
1672
+ return e === "hover" ? (t.addEventListener("mouseleave", s), () => {
1673
+ t.removeEventListener("mouseleave", s);
1674
+ }) : (document.addEventListener("click", l), () => {
1675
+ document.removeEventListener("click", l);
1676
+ });
1677
+ }
1678
+ const r = () => {
1679
+ o(() => {
1680
+ n(!0);
1681
+ });
1593
1682
  };
1594
- }, [w]), t || Q || g || u || f ? q("div", { className: "react-paint-editor-toolbox-relative", children: [m(J, { selected: V, title: l.title, disabled: c, onClick: () => {
1595
- D(() => {
1596
- L(!0);
1683
+ return e === "hover" ? (t.addEventListener("mouseenter", r), () => {
1684
+ t.removeEventListener("mouseenter", r);
1685
+ }) : (t.addEventListener("click", r), () => {
1686
+ t.removeEventListener("click", r);
1597
1687
  });
1598
- }, icon: x }), w && m(nt, { alignment: s, position: "top", children: q("div", { className: "react-paint-editor-toolbox-panel-content", "data-vertical": +h, children: [t && q(Ae, { children: [m(ke, { withText: !0, type: dt, disabled: c || !i, img: dt.icon, isActive: e.id === dt.id, setActive: o }), m(ke, { withText: !0, type: ct, disabled: c || !n, img: ct.icon, isActive: e.id === ct.id, setActive: d }), m(ke, { withText: !0, type: ht, disabled: c || !a, img: ht.icon, isActive: e.id === ht.id, setActive: r }), (Q || g || u) && m("hr", {})] }), Q && m(Mn, { withText: !0, type: Ni, disabled: c, loadFile: async (Z) => {
1599
- L(!1), await v(Z);
1600
- }, img: Ni.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), g && m(J, { disabled: c, selected: !1, onClick: S, title: "Add picture from URL", icon: '<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>', children: "Add picture from URL" }), (Q || g) && u && m("hr", {}), u && q(Ae, { children: [m(Mn, { withText: !0, type: Ri, disabled: c, loadFile: (Z) => {
1601
- L(!1), p(Z);
1602
- }, img: Ri.icon, accept: "application/JSON" }), m(ke, { withText: !0, disabled: c, type: jt, img: jt.icon, isActive: e.id === jt.id, setActive: C })] }), f && m(ke, { withText: !0, disabled: c, type: _t, img: _t.icon, isActive: e.id === _t.id, setActive: b })] }) })] }) : null;
1603
- }, ns = ({ togglePictureUrlModal: e, addPicture: t }) => {
1604
- const i = ne(null);
1605
- return ee(() => {
1688
+ }, [t, i, e]), { isOpen: i, trigger: e, closeMenu: a };
1689
+ }, Ss = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: n = !1, hasActionToClear: o = !1, undoAction: a, redoAction: r, clearCanvas: l, disabled: s = !1, withLoadAndSave: d, withExport: h, addPicture: c, loadFile: f, togglePictureUrlModal: p, saveFile: m, toggleExportModal: u, withUploadPicture: S, withUrlPicture: w }) => {
1690
+ const x = re(null), { isOpen: b, closeMenu: y } = Pi({ buttonElt: x.current }), g = (P) => async (...z) => {
1691
+ await P(...z), y();
1692
+ };
1693
+ return t || S || w || d || h ? v("div", { className: "react-paint-editor-toolbox-relative", children: G("div", { ref: x, children: [v(q, { title: "Menu", disabled: s, icon: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }), b && G(qt, { alignment: "right", position: "top", children: [t && G(Ne, { children: [v(Re, { withText: !0, type: kt, disabled: s || !i, img: kt.icon, isActive: e.id === kt.id, setActive: g(a) }), v(Re, { withText: !0, type: Lt, disabled: s || !n, img: Lt.icon, isActive: e.id === Lt.id, setActive: g(r) }), v(Re, { withText: !0, type: Vt, disabled: s || !o, img: Vt.icon, isActive: e.id === Vt.id, setActive: g(l) }), (S || w || d) && v("hr", {})] }), S && v(On, { withText: !0, type: on, disabled: s, loadFile: g(c), img: on.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml, image/webp" }), w && v(q, { disabled: s, selected: !1, onClick: g(p), title: "Add picture from URL", icon: '<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>', children: "Add picture from URL" }), (S || w) && d && v("hr", {}), d && G(Ne, { children: [v(On, { withText: !0, type: nn, disabled: s, loadFile: g(f), img: nn.icon, accept: "application/JSON" }), v(Re, { withText: !0, disabled: s, type: hi, img: hi.icon, isActive: e.id === hi.id, setActive: g(m) })] }), h && v(Re, { withText: !0, disabled: s, type: ci, img: ci.icon, isActive: e.id === ci.id, setActive: g(u) })] })] }) }) : null;
1694
+ }, ys = ({ togglePictureUrlModal: e, addPicture: t }) => {
1695
+ const i = re(null);
1696
+ return le(() => {
1606
1697
  i.current && i.current.focus();
1607
- }, []), m(Nt, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: q("form", { onSubmit: async (n) => {
1698
+ }, []), v(si, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: G("form", { onSubmit: async (n) => {
1608
1699
  n.preventDefault();
1609
- const a = i.current?.value;
1610
- a && (await t(a), e());
1611
- }, children: [q("label", { children: ["URL ", m("input", { type: "text", ref: i })] }), m(J, { onClick: e, children: "Annuler" }), m(J, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1612
- }, Pn = "Choose export settings", as = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1700
+ const o = i.current?.value;
1701
+ o && (await t(o), e());
1702
+ }, children: [G("label", { children: ["URL ", v("input", { type: "text", ref: i })] }), v(q, { onClick: e, children: "Annuler" }), v(q, { type: "submit", selected: !0, children: "Ajouter" })] }) });
1703
+ }, Bn = "Choose export settings", bs = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
1613
1704
  const i = async (n) => {
1614
1705
  t(n), e();
1615
1706
  };
1616
- return q(Nt, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Pn, children: [m("h3", { children: Pn }), m("hr", {}), m(J, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), m(J, { onClick: () => i("defaultView"), children: "Exporter le canevas par défaut" }), m(J, { onClick: () => i("fitToShapes"), children: "Exporter le dessin entier" }), m(J, { selected: !0, onClick: e, children: "Annuler" })] });
1617
- }, os = ({ activeTool: e, alignment: t, group: i, disabled: n = !1, setActiveToolFromId: a }) => {
1618
- const o = ne(null), [d, r] = $(!1), [, s] = Vn(), [l, h] = $(void 0), c = (v) => {
1619
- h(v), a(v.id);
1707
+ return G(si, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Bn, children: [v("h3", { children: Bn }), v("hr", {}), v(q, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), v(q, { onClick: () => i("defaultView"), children: "Exporter le canevas par défaut" }), v(q, { onClick: () => i("fitToShapes"), children: "Exporter le dessin entier" }), v(q, { selected: !0, onClick: e, children: "Annuler" })] });
1708
+ }, Qs = ({ activeTool: e, group: t, disabled: i = !1, setActiveToolFromId: n }) => {
1709
+ const o = re(null), [a, r] = K(!1), [, l] = Xn(), [s, d] = K(void 0), h = (p) => {
1710
+ d(p), n(p.id);
1620
1711
  };
1621
- if (ee(() => {
1622
- if (!d) return;
1623
- const v = (p) => {
1624
- !((C, b) => !!(C.target instanceof Node && b) && b.contains(C.target))(p, o.current) && r(!1);
1712
+ if (le(() => {
1713
+ if (!a) return;
1714
+ const p = (m) => {
1715
+ !No(m, o.current) && r(!1);
1625
1716
  };
1626
- return document.addEventListener("mousedown", v, { passive: !1 }), document.addEventListener("touchstart", v, { passive: !1 }), () => {
1627
- document.removeEventListener("mousedown", v), document.removeEventListener("touchstart", v);
1717
+ return document.addEventListener("mousedown", p, { passive: !1 }), document.addEventListener("touchstart", p, { passive: !1 }), () => {
1718
+ document.removeEventListener("mousedown", p), document.removeEventListener("touchstart", p);
1628
1719
  };
1629
- }, [d]), "type" in i) return m(ke, { disabled: n, type: i, img: i.icon, isActive: e.id === i.id, setActive: c });
1630
- if (!i.toolsType.length) return null;
1631
- if (i.toolsType?.length === 1) return m(ke, { disabled: n, type: i.toolsType[0], img: i.toolsType[0].icon, isActive: e.id === i.toolsType[0].id, setActive: c });
1632
- const u = i?.toolsType.find((v) => v.type === e.type) !== void 0, f = (l ? l.icon : i.toolsType?.[0]?.icon) ?? i.title;
1633
- return q("div", { className: "react-paint-editor-toolbargroup-relative", children: [m(J, { selected: u, title: i.title, disabled: n, onClick: () => {
1634
- l ? a(l.id) : i.toolsType?.[0] && c(i.toolsType[0]), s(() => {
1720
+ }, [a]), "type" in t) return v(Re, { disabled: i, type: t, img: t.icon, isActive: e.id === t.id, setActive: h });
1721
+ if (!t.toolsType.length) return null;
1722
+ if (t.toolsType?.length === 1) return v(Re, { disabled: i, type: t.toolsType[0], img: t.toolsType[0].icon, isActive: e.id === t.toolsType[0].id, setActive: h });
1723
+ const c = t?.toolsType.find((p) => p.type === e.type) !== void 0, f = (s ? s.icon : t.toolsType?.[0]?.icon) ?? t.title;
1724
+ return G("div", { className: "react-paint-editor-toolbargroup-relative", children: [v(q, { selected: c, title: t.title, disabled: i, onClick: () => {
1725
+ s ? n(s.id) : t.toolsType?.[0] && h(t.toolsType[0]), l(() => {
1635
1726
  r(!0);
1636
1727
  });
1637
- }, icon: f }), d && m(nt, { alignment: t, position: "top", children: m("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +i.vertical, ref: o, children: i.toolsType.map((v) => m(ke, { disabled: n, type: v, img: v.icon, isActive: e.id === v.id, setActive: c }, v.id)) }) })] });
1638
- }, ss = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], rs = ({ settings: e, width: t, activeTool: i, hasActionToUndo: n = !1, hasActionToRedo: a = !1, hasActionToClear: o = !1, withLoadAndSave: d, withExport: r, clearCanvas: s, setActiveTool: l, undoAction: h, redoAction: c, addPicture: u, loadFile: f, saveFile: v, exportCanvasInFile: p, availableTools: S, withUrlPicture: C, withUploadPicture: b }) => {
1639
- const Q = ((z, y) => {
1640
- const M = y.flatMap((P) => {
1641
- if (typeof P != "object") return z.filter((k) => k.type === P);
1642
- const T = z.filter((k) => P.toolsType.includes(k.type));
1643
- return T ? { ...P, toolsType: T } : null;
1728
+ }, icon: f }), a && v(yt, { alignment: "center", position: "top", children: v("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +t.vertical, ref: o, children: t.toolsType.map((p) => v(Re, { disabled: i, type: p, img: p.icon, isActive: e.id === p.id, setActive: h }, p.id)) }) })] });
1729
+ }, ws = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], xs = ({ settings: e, width: t, activeTool: i, hasActionToUndo: n = !1, hasActionToRedo: o = !1, hasActionToClear: a = !1, withLoadAndSave: r, withExport: l, clearCanvas: s, setActiveTool: d, undoAction: h, redoAction: c, addPicture: f, loadFile: p, saveFile: m, exportCanvasInFile: u, availableTools: S, withUrlPicture: w, withUploadPicture: x }) => {
1730
+ const b = ((R, $) => {
1731
+ const j = $.flatMap((ce) => {
1732
+ if (typeof ce != "object") return R.filter((L) => L.type === ce);
1733
+ const Pe = R.filter((L) => ce.toolsType.includes(L.type));
1734
+ return Pe ? { ...ce, toolsType: Pe } : null;
1644
1735
  });
1645
- return xi(M);
1646
- })(S, ss), g = !e.features.edition, w = t < 40 * (6 + Q.length), L = t < 40 * (3 + Q.length), [D, V] = $(!1), [x, Z] = $(!1), [A, H] = $(!1), F = () => {
1647
- V((z) => !z);
1648
- }, E = () => {
1649
- H((z) => !z);
1650
- }, W = (z) => {
1651
- l(z), V(!1);
1652
- }, G = (z) => {
1653
- W(S.find((y) => y.id === z) ?? i);
1654
- }, _ = S.find((z) => z.type === i.type) !== void 0;
1655
- return q(Ae, { children: [q("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [q("div", { className: "react-paint-editor-toolbar-shrinkable", children: [m(ke, { type: Oe, disabled: g, img: Oe.icon, isActive: i.id === Oe.id, setActive: W }), (e.size === "infinite" || e.features.zoom) && m(ke, { type: Kt, disabled: g, img: Kt.icon, isActive: i.id === Kt.id, setActive: W }), L ? m(J, { disabled: g, onClick: F, title: "Toggle tools", icon: '<svg><path d="M5.333 9.292 10.021 1.646 14.708 9.292ZM14.562 18.333Q13 18.333 11.896 17.229Q10.792 16.125 10.792 14.562Q10.792 13 11.896 11.896Q13 10.792 14.562 10.792Q16.125 10.792 17.229 11.896Q18.333 13 18.333 14.562Q18.333 16.125 17.229 17.229Q16.125 18.333 14.562 18.333ZM2.5 17.917V11.188H9.229V17.917ZM14.562 16.583Q15.438 16.583 16.01 16.01Q16.583 15.438 16.583 14.562Q16.583 13.688 16.01 13.115Q15.438 12.542 14.562 12.542Q13.688 12.542 13.115 13.115Q12.542 13.688 12.542 14.562Q12.542 15.438 13.115 16.01Q13.688 16.583 14.562 16.583ZM4.25 16.167H7.479V12.938H4.25ZM8.458 7.542H11.583L10.021 5ZM10.021 7.542ZM7.479 12.938ZM14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Z"/></svg>', selected: _ }) : Q.map((z) => m(os, { disabled: g, activeTool: i, group: z, setActiveToolFromId: G }, "id" in z ? z.id : z.title))] }), !w && q(Ae, { children: [m(ke, { type: dt, disabled: g || !n, img: dt.icon, isActive: i.id === dt.id, setActive: h }), m(ke, { type: ct, disabled: g || !a, img: ct.icon, isActive: i.id === ct.id, setActive: c }), m(ke, { type: ht, disabled: g || !o, img: ht.icon, isActive: i.id === ht.id, setActive: s })] }), m(is, { withActionsInMenu: w, disabled: g, vertical: !0, alignment: "right", group: { title: "Menu", img: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }, activeTool: i, addPicture: u, loadFile: f, saveFile: v, togglePictureUrlModal: () => {
1656
- Z(!0);
1657
- }, toggleExportModal: E, withUploadPicture: b, withUrlPicture: C, withLoadAndSave: d, withExport: r, hasActionToUndo: n, hasActionToRedo: a, hasActionToClear: o, undoAction: h, redoAction: c, clearCanvas: s })] }), D && m(Nt, { className: "react-paint-editor-toolbar-modal", onClose: F, title: "Outils", children: S.map((z) => z.type === "picture" ? null : m(ke, { disabled: g, type: z, img: z.icon, withText: !1, isActive: i.id === z.id, setActive: W }, z.id)) }), x && m(ns, { togglePictureUrlModal: () => {
1658
- Z((z) => !z);
1659
- }, addPicture: u }), A && m(as, { toggleExportModal: E, exportCanvasInFile: p })] });
1660
- }, Lt = { none: 0, small: 10, medium: 20, large: 40 }, ls = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, ds = () => {
1661
- const e = ne([]), [t, i] = $([]);
1662
- return ee(() => () => {
1736
+ return Ni(j);
1737
+ })(S, ws), y = !e.features.edition, g = t < 40 * (6 + b.length), P = t < 40 * (3 + b.length), [z, D] = K(!1), [A, H] = K(!1), [Z, E] = K(!1), F = () => {
1738
+ D((R) => !R);
1739
+ }, W = () => {
1740
+ E((R) => !R);
1741
+ }, I = (R) => {
1742
+ d(R), D(!1);
1743
+ }, oe = (R) => {
1744
+ I(S.find(($) => $.id === R) ?? i);
1745
+ }, te = S.find((R) => R.type === i.type) !== void 0;
1746
+ return G(Ne, { children: [G("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [G("div", { className: "react-paint-editor-toolbar-shrinkable", children: [v(Re, { type: Je, disabled: y, img: Je.icon, isActive: i.id === Je.id, setActive: I }), (e.size === "infinite" || e.features.zoom) && v(Re, { type: pi, disabled: y, img: pi.icon, isActive: i.id === pi.id, setActive: I }), P ? v(q, { disabled: y, 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: te }) : b.map((R) => v(Qs, { disabled: y, activeTool: i, group: R, setActiveToolFromId: oe }, "id" in R ? R.id : R.title))] }), !g && G(Ne, { children: [v(Re, { type: kt, disabled: y || !n, img: kt.icon, isActive: i.id === kt.id, setActive: h }), v(Re, { type: Lt, disabled: y || !o, img: Lt.icon, isActive: i.id === Lt.id, setActive: c }), v(Re, { type: Vt, disabled: y || !a, img: Vt.icon, isActive: i.id === Vt.id, setActive: s })] }), v(Ss, { withActionsInMenu: g, disabled: y, activeTool: i, addPicture: f, loadFile: p, saveFile: m, togglePictureUrlModal: () => {
1747
+ H(!0);
1748
+ }, toggleExportModal: W, withUploadPicture: x, withUrlPicture: w, withLoadAndSave: r, withExport: l, hasActionToUndo: n, hasActionToRedo: o, hasActionToClear: a, undoAction: h, redoAction: c, clearCanvas: s })] }), z && v(si, { className: "react-paint-editor-toolbar-modal", onClose: F, title: "Outils", children: S.map((R) => R.type === "picture" ? null : v(Re, { disabled: y, type: R, img: R.icon, withText: !1, isActive: i.id === R.id, setActive: I }, R.id)) }), A && v(ys, { togglePictureUrlModal: () => {
1749
+ H((R) => !R);
1750
+ }, addPicture: f }), Z && v(bs, { toggleExportModal: W, exportCanvasInFile: u })] });
1751
+ }, Ut = { none: 0, small: 10, medium: 20, large: 40 }, Ms = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, Cs = () => {
1752
+ const e = re([]), [t, i] = K([]);
1753
+ return le(() => () => {
1663
1754
  for (const n of e.current) clearTimeout(n);
1664
- }, []), { snackbarList: t, addSnackbar: ({ type: n = Ro, duration: a = No, text: o }) => {
1665
- const d = { id: ue("snackbar_"), duration: a, type: n, text: o };
1666
- i((r) => [...r, d]), e.current = [...e.current, setTimeout(() => {
1667
- return r = d.id, void i((s) => s.filter((l) => l.id !== r));
1668
- var r;
1669
- }, a)];
1755
+ }, []), { snackbarList: t, addSnackbar: ({ type: n = ts, duration: o = is, text: a }) => {
1756
+ const r = { id: Ce("snackbar_"), duration: o, type: n, text: a };
1757
+ i((l) => [...l, r]), e.current = [...e.current, setTimeout(() => {
1758
+ return l = r.id, void i((s) => s.filter((d) => d.id !== l));
1759
+ var l;
1760
+ }, o)];
1670
1761
  } };
1671
- }, gs = ({ editorProps: e, className: t, style: i, options: n, children: a }) => {
1672
- const { shapesRef: o, addPictureShape: d, moveShapes: r, toggleShapeVisibility: s, toggleShapeLock: l, canGoBackward: h, canGoForward: c, canClear: u, selectedShape: f, removeShape: v, updateShape: p, backwardShape: S, forwardShape: C, refs: b, width: Q, height: g, selectTool: w, selectShapes: L, activeTool: D, setActiveTool: V, setAvailableTools: x, isEditMode: Z, availableTools: A, gridGap: H, setGridGap: F, loadFile: E, exportPicture: W, exportData: G, clearCanvas: _, settings: z, setCanvasZoom: y, saveShapes: M, canvas: { canGrow: P, layersManipulation: T, withExport: k, withLoadAndSave: O, withUploadPicture: R, withUrlPicture: B } } = e, { toolbarBackgroundColor: I, dividerColor: j, fontRadius: de, fontDisabledColor: se, fontDisabledBackgroundColor: K, fontColor: N, fontBackgroundColor: ge, fontSelectedColor: oe, fontSelectedBackgroundColor: ye, fontHoverColor: Se, fontHoverBackgroundColor: Qe } = { ...ls, ...n }, te = z.size === "infinite" || z.features.zoom, [ve, U] = $(!1), [ae, Me] = $(!1), [Ze, re] = $(te), Te = te && Ze, qe = H >= Lt.large ? "large" : H >= Lt.medium ? "medium" : H >= Lt.small ? "small" : "none", { snackbarList: Ot, addSnackbar: De } = ds(), Ft = X((fe, me, gt) => {
1673
- x((Fe) => Fe.map((at) => at.id === fe ? Le(["settings", me, "default"], gt, at) : at)), V((Fe) => Fe.id === fe ? Le(["settings", me, "default"], gt, Fe) : Fe);
1674
- }, [V, x]), Yt = X((fe) => {
1675
- U(!0);
1762
+ }, Ps = ({ moveShapes: e, selectAllShapes: t, selectionMode: i, transformShape: n, settings: o, canvasRef: a, closeContextMenu: r, toggleShapeVisibility: l, toggleShapeLock: s, removeShape: d, duplicateShapes: h, copiedShape: c, setCopiedShape: f, pasteShapes: p, removeShapePoint: m }) => {
1763
+ const u = re(null), S = re(null), { isOpen: w } = Pi({ trigger: "hover", buttonElt: u.current }), { isOpen: x } = Pi({ trigger: "hover", buttonElt: S.current }), { originalShape: b, cursorStartPosition: y, anchor: g } = i, P = U(b), z = P.length > 0, D = P.length === 1 && (P[0]?.type === "polygon" || P[0]?.type === "curve") && g !== void 0 && P[0]?.points?.length > 2, A = !P.some((I) => I.visible === !1);
1764
+ P.some((I) => I.locked);
1765
+ const H = 16 + 36 * (2 + (z ? 8 : 0) + (D ? 1 : 0)) + 16 * (z ? 3 : 1), [Z] = K(() => [(y[0] + o.canvasOffset[0]) * o.canvasSize.scaleRatio, 36 + (y[1] + o.canvasOffset[1]) * o.canvasSize.scaleRatio]), [E, F] = K();
1766
+ le(() => {
1767
+ const I = a?.current?.getBoundingClientRect();
1768
+ if (!I) return;
1769
+ const oe = I.left + Z[0], te = I.top + Z[1], R = Math.max(0, Math.min(oe, window.innerWidth - 176)) - I.left, $ = Math.max(0, Math.min(te, window.innerHeight - H)) - I.top, j = R > window.innerWidth - 176 - Math.min(R, 200) ? "left" : "right";
1770
+ F({ x: R, y: $, subMenuPosition: j });
1771
+ }, [a, Z, H]);
1772
+ const W = E ? { "--react-paint-editor-toolbox-contextmenu-transform": `translate3D(${E.x}px, ${E.y}px, 0)` } : { display: "none" };
1773
+ return G(qt, { className: "react-paint-editor-toolbox-contextmenu", style: W, children: [z && G(Ne, { children: [D && v(q, { onClick: () => {
1774
+ D && m(P[0], g), r();
1775
+ }, children: "Delete point" }), G("div", { className: "react-paint-editor-toolbox-contextmenu-group", ref: u, children: [v(q, { icon: Gi, children: "Organize" }), w && G(qt, { position: E?.subMenuPosition, children: [v(q, { onClick: () => {
1776
+ z && e(P, "forward"), r();
1777
+ }, children: "Move forward" }), v(q, { onClick: () => {
1778
+ z && e(P, "first"), r();
1779
+ }, children: "Put on first" }), v(q, { onClick: () => {
1780
+ z && e(P, "backward"), r();
1781
+ }, children: "Move backward" }), v(q, { onClick: () => {
1782
+ z && e(P, "last"), r();
1783
+ }, children: "Put on last" })] })] }), G("div", { className: "react-paint-editor-toolbox-contextmenu-group", ref: S, children: [v(q, { icon: Gi, children: "Transform" }), x && G(qt, { position: E?.subMenuPosition, children: [v(q, { onClick: () => {
1784
+ z && n(P, b.computed.center, "rotateClockwise"), r();
1785
+ }, children: "Rotate clockwise" }), v(q, { onClick: () => {
1786
+ z && n(P, b.computed.center, "rotateCounterclockwise"), r();
1787
+ }, children: "Rotate counterclockwise" })] })] }), v("hr", {}), v(q, { onClick: () => {
1788
+ z && (f(de(P, o)), d(P)), r();
1789
+ }, children: "Cut" }), v(q, { onClick: () => {
1790
+ z && f(de(P, o)), r();
1791
+ }, children: "Copy" })] }), v(q, { onClick: () => {
1792
+ c && p(Wi(c, o)), r();
1793
+ }, disabled: !c, children: "Paste" }), v("hr", {}), z && G(Ne, { children: [v(q, { onClick: () => {
1794
+ z && h(P, !0, !0), r();
1795
+ }, children: "Duplicate" }), v(q, { onClick: () => {
1796
+ z && l(P.filter((I) => A ? I.visible !== !1 : I.visible === !1)), r();
1797
+ }, children: A ? "Hide" : "Show" }), v(q, { onClick: () => {
1798
+ z && d(P), r();
1799
+ }, children: "Delete" }), v("hr", {})] }), v(q, { onClick: () => {
1800
+ t(), r();
1801
+ }, children: "Select all" })] });
1802
+ }, zs = ({ editorProps: e, className: t, style: i, options: n, children: o }) => {
1803
+ const { selectionMode: a, setSelectionMode: r, shapesRef: l, addPictureShape: s, moveShapes: d, swapShapes: h, toggleShapeVisibility: c, toggleShapeLock: f, canGoBackward: p, canGoForward: m, canClear: u, selectedShape: S, copiedShape: w, setCopiedShape: x, pasteShapes: b, removeShape: y, duplicateShapes: g, updateShape: P, backwardShape: z, forwardShape: D, removeShapePoint: A, transformShape: H, refs: Z, width: E, height: F, selectTool: W, selectShapes: I, selectAllShapes: oe, activeTool: te, setActiveTool: R, setAvailableTools: $, isEditMode: j, availableTools: ce, gridGap: Pe, setGridGap: L, loadFile: _, exportPicture: M, exportData: C, clearCanvas: Q, settings: V, setCanvasZoom: N, saveShapes: k, canvas: { canGrow: J, layersManipulation: O, withExport: T, withLoadAndSave: ne, withUploadPicture: ye, withUrlPicture: Y, withContextMenu: ze } } = e, { toolbarBackgroundColor: ge, dividerColor: Oe, fontRadius: Ye, fontDisabledColor: he, fontDisabledBackgroundColor: Se, fontColor: ae, fontBackgroundColor: fe, fontSelectedColor: ee, fontSelectedBackgroundColor: se, fontHoverColor: pe, fontHoverBackgroundColor: ke } = { ...Ms, ...n }, Be = V.size === "infinite" || V.features.zoom, [Ee, we] = K(!1), [Fe, bt] = K(!1), [Qt, dt] = K(Be), $e = Be && Qt, wt = Pe >= Ut.large ? "large" : Pe >= Ut.medium ? "medium" : Pe >= Ut.small ? "small" : "none", { snackbarList: xt, addSnackbar: Ae } = Cs(), at = X((ve, be, B) => {
1804
+ $((nt) => nt.map((Tt) => Tt.id === ve ? Xe(["settings", be, "default"], B, Tt) : Tt)), R((nt) => nt.id === ve ? Xe(["settings", be, "default"], B, nt) : nt);
1805
+ }, [R, $]), st = X((ve) => {
1806
+ we(!0);
1676
1807
  try {
1677
- W(fe);
1678
- } catch (me) {
1679
- me instanceof Error && De({ type: "error", text: `L'export a échoué : ${me.message}` }), console.warn(me);
1808
+ M(ve);
1809
+ } catch (be) {
1810
+ be instanceof Error && Ae({ type: "error", text: `L'export a échoué : ${be.message}` }), console.warn(be);
1680
1811
  } finally {
1681
- U(!1);
1812
+ we(!1);
1682
1813
  }
1683
- }, [W, De]), Ge = X(() => {
1684
- U(!0);
1814
+ }, [M, Ae]), je = X(() => {
1815
+ we(!0);
1685
1816
  try {
1686
- G(), U(!1);
1687
- } catch (fe) {
1688
- fe instanceof Error && De({ type: "error", text: "L'enregistrement a échoué" }), console.warn(fe);
1817
+ C(), we(!1);
1818
+ } catch (ve) {
1819
+ ve instanceof Error && Ae({ type: "error", text: "L'enregistrement a échoué" }), console.warn(ve);
1689
1820
  } finally {
1690
- U(!1);
1821
+ we(!1);
1691
1822
  }
1692
- }, [G, De]), Xt = X(async (fe) => {
1693
- U(!0);
1823
+ }, [C, Ae]), ct = X(async (ve) => {
1824
+ we(!0);
1694
1825
  try {
1695
- await E(fe), De({ type: "success", text: "Fichier chargé !" });
1696
- } catch (me) {
1697
- me instanceof Error && De({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1826
+ await _(ve), Ae({ type: "success", text: "Fichier chargé !" });
1827
+ } catch (be) {
1828
+ be instanceof Error && Ae({ type: "error", text: "Le chargement a échoué" }), console.warn(be);
1698
1829
  } finally {
1699
- U(!1);
1830
+ we(!1);
1700
1831
  }
1701
- }, [E, De]), $t = X(async (fe) => {
1702
- U(!0);
1832
+ }, [_, Ae]), ht = X(async (ve) => {
1833
+ we(!0);
1703
1834
  try {
1704
- const me = await d(fe, Q, g);
1705
- L([me]);
1706
- } catch (me) {
1707
- me instanceof Error && De({ type: "error", text: "Le chargement a échoué" }), console.warn(me);
1835
+ const be = await s(ve, E, F);
1836
+ I([be]);
1837
+ } catch (be) {
1838
+ be instanceof Error && Ae({ type: "error", text: "Le chargement a échoué" }), console.warn(be);
1708
1839
  } finally {
1709
- U(!1);
1840
+ we(!1);
1710
1841
  }
1711
- }, [d, L, De, Q, g]), Ut = `${t ? `${t} ` : ""}${ae ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1712
- return q("div", { ref: b.setEditor, className: Ut, style: { "--react-paint-editor-app-maxWidth": P ? "100%" : `${Q}px`, "--react-paint-editor-app-toolbar-bg": I, "--react-paint-editor-app-divider-color": j, "--react-paint-editor-app-font-radius": de, "--react-paint-editor-app-font-disabled-color": se, "--react-paint-editor-app-font-disabled-bg": K, "--react-paint-editor-app-font-color": N, "--react-paint-editor-app-font-bg": ge, "--react-paint-editor-app-font-selected-color": oe, "--react-paint-editor-app-font-selected-bg": ye, "--react-paint-editor-app-font-hover-color": Se, "--react-paint-editor-app-font-hover-bg": Qe, ...i }, children: [Z && m(rs, { settings: z, width: z.canvasSize.width, activeTool: D, clearCanvas: _, setActiveTool: w, exportCanvasInFile: Yt, saveFile: Ge, loadFile: Xt, addPicture: $t, hasActionToUndo: h, hasActionToRedo: c, hasActionToClear: u, undoAction: S, redoAction: C, availableTools: A, withExport: k, withLoadAndSave: O, withUploadPicture: R, withUrlPicture: B }), a, Z && T && m($o, { gridFormat: qe, setGridFormat: (fe) => {
1713
- F(Lt[fe]);
1714
- }, shapes: o.current, moveShapes: r, selectedShapes: f, removeShape: v, selectShapes: L, toggleShapeVisibility: s, toggleShapeLock: l, isLayoutPanelShown: ae, settings: z }), Te && q(nt, { alignment: "left", className: "react-paint-editor-layouts-panel", "data-edit": +Z, children: [m(J, { className: "react-paint-editor-zoom-button", icon: '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>', onClick: () => y("unzoom") }), q(J, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => y("default"), children: [Math.round(100 * z.canvasZoom), "%"] }), m(J, { className: "react-paint-editor-zoom-button", icon: Dn, onClick: () => y("zoom") })] }), Z && q(Ae, { children: [m(ts, { saveShapes: M, setCanvasZoom: y, width: z.canvasSize.width, activeTool: D, availableTools: A, selectedShape: f, settings: z, removeShape: v, updateShape: p, canvas: b.canvas.current, layersManipulation: T, toggleLayoutPanel: () => {
1715
- Me((fe) => !fe);
1716
- }, isZoomPanelShown: Te, setIsZoomPanelShown: re, updateToolSettings: Ft }), m(Wo, { isLoading: ve }), m(Oo, { snackbarList: Ot })] })] });
1842
+ }, [s, I, Ae, E, F]), pt = `${t ? `${t} ` : ""}${Fe ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
1843
+ return G("div", { ref: Z.setEditor, className: pt, style: { "--react-paint-editor-app-maxWidth": J ? "100%" : `${E}px`, "--react-paint-editor-app-toolbar-bg": ge, "--react-paint-editor-app-divider-color": Oe, "--react-paint-editor-app-font-radius": `${Ye}px`, "--react-paint-editor-app-font-disabled-color": he, "--react-paint-editor-app-font-disabled-bg": Se, "--react-paint-editor-app-font-color": ae, "--react-paint-editor-app-font-bg": fe, "--react-paint-editor-app-font-selected-color": ee, "--react-paint-editor-app-font-selected-bg": se, "--react-paint-editor-app-font-hover-color": pe, "--react-paint-editor-app-font-hover-bg": ke, ...i }, children: [j && v(xs, { settings: V, width: V.canvasSize.width, activeTool: te, clearCanvas: Q, setActiveTool: W, exportCanvasInFile: st, saveFile: je, loadFile: ct, addPicture: ht, hasActionToUndo: p, hasActionToRedo: m, hasActionToClear: u, undoAction: z, redoAction: D, availableTools: ce, withExport: T, withLoadAndSave: ne, withUploadPicture: ye, withUrlPicture: Y }), o, j && O && v(ls, { gridFormat: wt, setGridFormat: (ve) => {
1844
+ L(Ut[ve]);
1845
+ }, shapes: l.current, swapShapes: h, selectedShapes: S, removeShape: y, selectShapes: I, toggleShapeVisibility: c, toggleShapeLock: f, isLayoutPanelShown: Fe, settings: V }), $e && G(yt, { alignment: "left", position: "bottom", className: "react-paint-editor-layouts-panel", "data-edit": +j, children: [v(q, { className: "react-paint-editor-zoom-button", icon: '<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>', onClick: () => N("unzoom") }), G(q, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => N("default"), children: [Math.round(100 * V.canvasZoom), "%"] }), v(q, { className: "react-paint-editor-zoom-button", icon: jn, onClick: () => N("zoom") })] }), j && G(Ne, { children: [v(ms, { saveShapes: k, setCanvasZoom: N, width: V.canvasSize.width, activeTool: te, availableTools: ce, selectedShape: S, settings: V, removeShape: y, updateShape: P, canvas: Z.canvas.current, layersManipulation: O, toggleLayoutPanel: () => {
1846
+ bt((ve) => !ve);
1847
+ }, isZoomPanelShown: $e, setIsZoomPanelShown: dt, updateToolSettings: at }), v(es, { isLoading: Ee }), v(os, { snackbarList: xt })] }), a.mode === "contextMenu" && ze && v(Ps, { selectionMode: a, settings: V, canvasRef: Z.canvas, closeContextMenu: () => {
1848
+ r({ mode: "default" }), Z.canvas.current?.focus();
1849
+ }, selectAllShapes: oe, removeShape: y, moveShapes: d, duplicateShapes: g, toggleShapeLock: f, toggleShapeVisibility: c, setCopiedShape: x, copiedShape: w, pasteShapes: b, removeShapePoint: A, transformShape: H })] });
1717
1850
  };
1718
1851
  export {
1719
- ps as Canvas,
1720
- gs as Editor,
1721
- us as useReactPaint
1852
+ Zs as Canvas,
1853
+ zs as Editor,
1854
+ Vs as useReactPaint
1722
1855
  };