@yorab/react-paint 0.17.0 → 0.18.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.
- package/dist/_chunks/array-DuJem3vg.js +1 -0
- package/dist/_chunks/canvas-OCtokhMt.js +1 -0
- package/dist/_chunks/editor-CNTO8aYs.js +1 -0
- package/dist/canvas/components/Canvas.d.ts +1 -52
- package/dist/canvas/constants/app.d.ts +3 -25
- package/dist/canvas/constants/rendering.d.ts +3 -0
- package/dist/canvas/constants/tools.d.ts +4 -0
- package/dist/canvas/context/CanvasContext.d.ts +55 -0
- package/dist/canvas/hooks/useDrawableCanvas.d.ts +2 -43
- package/dist/canvas/hooks/useEventListener.d.ts +2 -0
- package/dist/canvas/hooks/useReactPaint.d.ts +9 -4
- package/dist/canvas/hooks/useShapes.d.ts +2 -1
- package/dist/canvas/index.d.ts +4 -0
- package/dist/canvas/index.js +1 -0
- package/dist/canvas/utils/canvas.d.ts +2 -1
- package/dist/canvas/utils/intersect.d.ts +4 -0
- package/dist/canvas/utils/selection.d.ts +0 -3
- package/dist/canvas/utils/shapes/brush.d.ts +0 -6
- package/dist/canvas/utils/shapes/circle.d.ts +1 -7
- package/dist/canvas/utils/shapes/curve.d.ts +1 -7
- package/dist/canvas/utils/shapes/ellipse.d.ts +1 -7
- package/dist/canvas/utils/shapes/index.d.ts +3 -9
- package/dist/canvas/utils/shapes/line.d.ts +3 -9
- package/dist/canvas/utils/shapes/path.d.ts +1 -0
- package/dist/canvas/utils/shapes/picture.d.ts +0 -6
- package/dist/canvas/utils/shapes/polygon.d.ts +0 -6
- package/dist/canvas/utils/shapes/rectangle.d.ts +0 -6
- package/dist/canvas/utils/tools.d.ts +1 -1
- package/dist/canvas/utils/transform.d.ts +0 -1
- package/dist/common/hooks/useDebounce.d.ts +2 -0
- package/dist/common/types/Settings.d.ts +24 -0
- package/dist/common/utils/selection.d.ts +4 -0
- package/dist/editor/components/settings/Layouts.d.ts +1 -1
- package/dist/editor/components/settings/SettingsBar.d.ts +4 -2
- package/dist/editor/components/toolbox/ContextMenu.d.ts +5 -3
- package/dist/editor/components/toolbox/Toolbar.d.ts +1 -1
- package/dist/editor/hooks/useMenu.d.ts +2 -1
- package/dist/editor/index.d.ts +3 -2
- package/dist/editor/index.js +1 -0
- package/dist/editor/utils/style.d.ts +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/react-paint.css +1 -0
- package/dist/react-paint.js +1 -1855
- package/dist/react-paint.umd.cjs +1 -1
- package/package.json +34 -18
package/dist/react-paint.js
CHANGED
|
@@ -1,1855 +1 @@
|
|
|
1
|
-
import
|
|
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
|
-
const i = { ...t };
|
|
5
|
-
for (const n of e) Array.isArray(n) ? n[1].includes(i[n[0]]) && delete i[n[0]] : delete i[n];
|
|
6
|
-
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
|
-
const n = { ...t };
|
|
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
|
-
return n;
|
|
15
|
-
}, vo = (e, t) => {
|
|
16
|
-
if (e === t) return !0;
|
|
17
|
-
if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
|
|
18
|
-
const i = Object.keys(e), n = Object.keys(t);
|
|
19
|
-
if (i.length !== n.length) return !1;
|
|
20
|
-
for (const o of i) if (!n.includes(o) || !vo(e[o], t[o])) return !1;
|
|
21
|
-
return !0;
|
|
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
|
-
e.reset(), e.lineCap = "round", e.lineJoin = "round";
|
|
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
|
-
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
|
-
}, Qi = (e) => 180 * e / Math.PI, yo = (e, t) => {
|
|
30
|
-
const i = t.x - Math.min(Math.max(t.x, e.x), e.x + e.width), n = t.y - Math.min(Math.max(t.y, e.y), e.y + e.height);
|
|
31
|
-
return Math.sqrt(i * i + n * n) <= t.radius;
|
|
32
|
-
}, me = ({ origin: e = [0, 0], point: t, rotation: i = 0 }) => {
|
|
33
|
-
if (i === 0) return t;
|
|
34
|
-
const n = [t[0] - e[0], t[1] - e[1]], 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
|
-
if (n) {
|
|
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
|
-
}
|
|
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
|
-
if (n.mode === "rotate") {
|
|
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
|
-
}
|
|
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
|
-
const t = new Path2D();
|
|
68
|
-
return t.rect(e.x, e.y, e.width, e.height), t;
|
|
69
|
-
}, Gt = (e) => {
|
|
70
|
-
const t = new Path2D();
|
|
71
|
-
return t.arc(e.x, e.y, e.radius, 0, 2 * Math.PI), t;
|
|
72
|
-
}, _t = (e) => {
|
|
73
|
-
const t = new Path2D();
|
|
74
|
-
return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t;
|
|
75
|
-
}, oa = (e, { brushAlgo: t }) => {
|
|
76
|
-
const i = new Path2D();
|
|
77
|
-
if (e.points.length < 1) return i;
|
|
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
|
-
}
|
|
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
|
-
return i;
|
|
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
|
-
}
|
|
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
|
-
}
|
|
106
|
-
for (const g of S) {
|
|
107
|
-
const P = a(g);
|
|
108
|
-
b = Math.min(b, P), y = Math.max(y, P);
|
|
109
|
-
}
|
|
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
|
-
const t = new Path2D(), i = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
|
|
113
|
-
if (i.length < 2) return t;
|
|
114
|
-
t.moveTo(...i[0]);
|
|
115
|
-
for (const n of i.slice(1)) t.lineTo(...n);
|
|
116
|
-
return i.length > 2 && e.style?.closedPoints === 1 && t.lineTo(...i[0]), t;
|
|
117
|
-
}, sa = (e) => {
|
|
118
|
-
const t = new Path2D();
|
|
119
|
-
return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t.lineTo(...e.points[2]), t.lineTo(...e.points[0]), t;
|
|
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
|
-
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((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
|
-
const { borders: n } = t;
|
|
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
|
-
case 0: {
|
|
133
|
-
if (o) {
|
|
134
|
-
const l = Math.max(0, i - t) + 2 * n.selectionPadding;
|
|
135
|
-
return [e + t - 2 * n.selectionPadding, l];
|
|
136
|
-
}
|
|
137
|
-
const r = Math.max(2 * n.selectionPadding, t - i);
|
|
138
|
-
return [e + t - r, r];
|
|
139
|
-
}
|
|
140
|
-
case 0.5:
|
|
141
|
-
return [e, t];
|
|
142
|
-
case 1:
|
|
143
|
-
if (o) {
|
|
144
|
-
const r = Math.min(e, e + t + i);
|
|
145
|
-
return [r, e - r + 2 * n.selectionPadding];
|
|
146
|
-
}
|
|
147
|
-
return [e, Math.max(2 * n.selectionPadding, t + i)];
|
|
148
|
-
default:
|
|
149
|
-
return [0, 0];
|
|
150
|
-
}
|
|
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
|
-
e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
|
|
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
|
-
let s = !1;
|
|
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
|
-
if (c.mode === "rotate") {
|
|
182
|
-
const { center: m } = f.computed;
|
|
183
|
-
return { mode: "rotate", cursorStartPosition: p, originalShape: f, center: [m[0], m[1]], selectedShapesLengthAtMouseDown: U(f).length };
|
|
184
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
203
|
-
return { shape: l !== "replace" ? o : void 0, mode: { mode: r ? "selectionFrame" : "default" } };
|
|
204
|
-
}, de = (e, t) => {
|
|
205
|
-
if (!e.length) return;
|
|
206
|
-
if (e.length === 1) return e[0];
|
|
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
|
-
}, e[0].style ?? {});
|
|
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);
|
|
221
|
-
return [.../* @__PURE__ */ new Set([...i, ...t])];
|
|
222
|
-
}, pa = (e, t) => U(e).filter((i) => i.id !== t.id), Mo = (e) => {
|
|
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 : {};
|
|
224
|
-
return { clientX: t, clientY: i };
|
|
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;
|
|
238
|
-
if (c.type === "line" || c.type === "polygon" || c.type === "curve") {
|
|
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 };
|
|
240
|
-
} else {
|
|
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 };
|
|
243
|
-
}
|
|
244
|
-
return !1;
|
|
245
|
-
})(r, d, n, a);
|
|
246
|
-
if (h) return h;
|
|
247
|
-
}
|
|
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) => {
|
|
250
|
-
if (t.locked || t.points.length < 2) return !1;
|
|
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 };
|
|
257
|
-
}
|
|
258
|
-
return !1;
|
|
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) => {
|
|
260
|
-
if (t.locked) return !1;
|
|
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" };
|
|
263
|
-
};
|
|
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 };
|
|
267
|
-
}
|
|
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;
|
|
272
|
-
}
|
|
273
|
-
return !1;
|
|
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) => {
|
|
281
|
-
const { canvasZoom: i, size: n } = t;
|
|
282
|
-
if (n !== "fixed" || i >= 1) return;
|
|
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) => {
|
|
295
|
-
if (t < 0 || t > e.points.length - 1) return e;
|
|
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) => {
|
|
302
|
-
const n = e.tempPoint ? [...e.points, e.tempPoint] : e.points;
|
|
303
|
-
if (n.length < 2) {
|
|
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 };
|
|
306
|
-
}
|
|
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);
|
|
313
|
-
}
|
|
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]);
|
|
326
|
-
}
|
|
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) => {
|
|
331
|
-
if (t < 0 || t > e.points.length - 1) return e;
|
|
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) => {
|
|
344
|
-
e.globalAlpha !== 0 && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
|
|
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) => {
|
|
346
|
-
const i = [];
|
|
347
|
-
let n;
|
|
348
|
-
if (e.style?.lineArrow === 1 || e.style?.lineArrow === 2 || e.style?.lineArrow === 3) {
|
|
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] };
|
|
363
|
-
})({ line: e, size: 10 + 2 * (e.style?.lineWidth ?? 0), direction: e.style?.lineArrow === 1 ? "start" : e.style?.lineArrow === 2 ? "end" : "both" });
|
|
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 })];
|
|
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" } };
|
|
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];
|
|
384
|
-
}
|
|
385
|
-
const p = c ? h : Math.min(s, h);
|
|
386
|
-
return [p * f, p];
|
|
387
|
-
})(e.width, e.height, i, n, !0);
|
|
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"));
|
|
393
|
-
}, setTimeout(() => {
|
|
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;
|
|
415
|
-
}).catch(() => {
|
|
416
|
-
l.src = "";
|
|
417
|
-
});
|
|
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)];
|
|
435
|
-
switch (t.type) {
|
|
436
|
-
case "brush":
|
|
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);
|
|
438
|
-
case "line":
|
|
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);
|
|
443
|
-
case "polygon":
|
|
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);
|
|
445
|
-
case "curve":
|
|
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);
|
|
447
|
-
case "rect":
|
|
448
|
-
case "square":
|
|
449
|
-
return wo(t, o, n);
|
|
450
|
-
case "text":
|
|
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);
|
|
455
|
-
case "ellipse":
|
|
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);
|
|
457
|
-
case "circle":
|
|
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);
|
|
459
|
-
}
|
|
460
|
-
}, Sn = (e, t) => {
|
|
461
|
-
switch (t.type) {
|
|
462
|
-
case "brush":
|
|
463
|
-
((i, n) => {
|
|
464
|
-
n.points.length < 1 || i.globalAlpha !== 0 && n.style?.strokeColor !== "transparent" && i.globalAlpha !== 0 && i.stroke(n.path);
|
|
465
|
-
})(e, t);
|
|
466
|
-
break;
|
|
467
|
-
case "text":
|
|
468
|
-
((i, n) => {
|
|
469
|
-
if (i.globalAlpha !== 0 && n.style?.strokeColor && n.style.strokeColor !== "transparent") {
|
|
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);
|
|
472
|
-
}
|
|
473
|
-
})(e, t);
|
|
474
|
-
break;
|
|
475
|
-
case "line":
|
|
476
|
-
((i, n) => {
|
|
477
|
-
if (i.globalAlpha !== 0) {
|
|
478
|
-
n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path);
|
|
479
|
-
for (const o of n.arrows ?? []) Te(i, o.style), Qa(i, o);
|
|
480
|
-
}
|
|
481
|
-
})(e, t);
|
|
482
|
-
break;
|
|
483
|
-
case "polygon":
|
|
484
|
-
((i, n) => {
|
|
485
|
-
i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
|
|
486
|
-
})(e, t);
|
|
487
|
-
break;
|
|
488
|
-
case "curve":
|
|
489
|
-
((i, n) => {
|
|
490
|
-
i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
|
|
491
|
-
})(e, t);
|
|
492
|
-
break;
|
|
493
|
-
case "circle":
|
|
494
|
-
((i, n) => {
|
|
495
|
-
i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
|
|
496
|
-
})(e, t);
|
|
497
|
-
break;
|
|
498
|
-
case "ellipse":
|
|
499
|
-
((i, n) => {
|
|
500
|
-
i.globalAlpha !== 0 && (n.style?.fillColor !== "transparent" && i.fill(n.path), n.style?.strokeColor !== "transparent" && i.stroke(n.path));
|
|
501
|
-
})(e, t);
|
|
502
|
-
break;
|
|
503
|
-
case "rect":
|
|
504
|
-
case "square":
|
|
505
|
-
ha(e, t);
|
|
506
|
-
break;
|
|
507
|
-
case "picture":
|
|
508
|
-
((i, n) => {
|
|
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));
|
|
510
|
-
})(e, t);
|
|
511
|
-
}
|
|
512
|
-
}, Ao = (e, t, i) => {
|
|
513
|
-
if (t.visible === !1) return;
|
|
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);
|
|
520
|
-
})(t, i)) {
|
|
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);
|
|
527
|
-
})(e, t), void e.restore();
|
|
528
|
-
Sn(e, t), e.restore();
|
|
529
|
-
}
|
|
530
|
-
}, Ho = (e, t, i) => {
|
|
531
|
-
const n = me({ origin: i, point: e.computed.center, rotation: -t });
|
|
532
|
-
if ("points" in e) {
|
|
533
|
-
if (e.type === "brush") {
|
|
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 };
|
|
536
|
-
}
|
|
537
|
-
const o = e.points.map((a) => me({ origin: i, point: a, rotation: -t }));
|
|
538
|
-
return { ...e, points: o };
|
|
539
|
-
}
|
|
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 };
|
|
541
|
-
}, yn = (e, t, i, n, o, a, r) => {
|
|
542
|
-
switch (i.type) {
|
|
543
|
-
case "line":
|
|
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);
|
|
548
|
-
case "polygon":
|
|
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);
|
|
553
|
-
case "curve":
|
|
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);
|
|
558
|
-
case "brush":
|
|
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);
|
|
565
|
-
case "circle":
|
|
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);
|
|
570
|
-
case "ellipse":
|
|
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);
|
|
575
|
-
case "rect":
|
|
576
|
-
case "square":
|
|
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);
|
|
581
|
-
case "text":
|
|
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);
|
|
586
|
-
case "picture":
|
|
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);
|
|
591
|
-
default:
|
|
592
|
-
return i;
|
|
593
|
-
}
|
|
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) {
|
|
602
|
-
case "rect":
|
|
603
|
-
case "square":
|
|
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);
|
|
608
|
-
case "picture":
|
|
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);
|
|
613
|
-
case "text":
|
|
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);
|
|
618
|
-
case "ellipse":
|
|
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);
|
|
623
|
-
case "circle":
|
|
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);
|
|
628
|
-
case "brush":
|
|
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);
|
|
633
|
-
case "line":
|
|
634
|
-
case "polygon":
|
|
635
|
-
case "curve":
|
|
636
|
-
return Ma(m, l, p);
|
|
637
|
-
default:
|
|
638
|
-
return yn(e, t, m, n, o, a, r);
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
}, To = (e, t, i, n) => {
|
|
642
|
-
switch (e.type) {
|
|
643
|
-
case "rect":
|
|
644
|
-
case "square":
|
|
645
|
-
case "ellipse":
|
|
646
|
-
case "circle":
|
|
647
|
-
case "picture":
|
|
648
|
-
case "text":
|
|
649
|
-
return _e({ ...e, x: e.x + t, y: e.y + i }, n);
|
|
650
|
-
case "line":
|
|
651
|
-
case "polygon":
|
|
652
|
-
case "curve":
|
|
653
|
-
return _e({ ...e, points: e.points.map(([o, a]) => [o + t, a + i]) }, n);
|
|
654
|
-
case "brush":
|
|
655
|
-
return _e({ ...e, points: e.points.map((o) => o.map(([a, r]) => [a + t, r + i])) }, n);
|
|
656
|
-
default:
|
|
657
|
-
return e;
|
|
658
|
-
}
|
|
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) => {
|
|
663
|
-
switch (e.type) {
|
|
664
|
-
case "rect":
|
|
665
|
-
case "square":
|
|
666
|
-
return ca(e, t);
|
|
667
|
-
case "ellipse":
|
|
668
|
-
return ya(e, t);
|
|
669
|
-
case "circle":
|
|
670
|
-
return ga(e, t);
|
|
671
|
-
case "picture":
|
|
672
|
-
return Ca(e, t);
|
|
673
|
-
case "text":
|
|
674
|
-
return ka(e, t);
|
|
675
|
-
case "line":
|
|
676
|
-
return xa(e, t);
|
|
677
|
-
case "polygon":
|
|
678
|
-
return Vo(e, t);
|
|
679
|
-
case "curve":
|
|
680
|
-
return Zo(e, t);
|
|
681
|
-
case "brush":
|
|
682
|
-
return ia(e, t);
|
|
683
|
-
default:
|
|
684
|
-
return e;
|
|
685
|
-
}
|
|
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());
|
|
689
|
-
})(e, t, n, i), t.type) {
|
|
690
|
-
case "rect":
|
|
691
|
-
case "square":
|
|
692
|
-
case "circle":
|
|
693
|
-
case "ellipse":
|
|
694
|
-
case "picture":
|
|
695
|
-
case "text":
|
|
696
|
-
case "brush":
|
|
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);
|
|
701
|
-
}
|
|
702
|
-
})(e, t, o, n, i, l);
|
|
703
|
-
break;
|
|
704
|
-
case "group":
|
|
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);
|
|
711
|
-
}
|
|
712
|
-
})(e, t, o, n, r, i, l);
|
|
713
|
-
break;
|
|
714
|
-
case "polygon":
|
|
715
|
-
case "line":
|
|
716
|
-
case "curve":
|
|
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);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
})({ ctx: e, shape: t, withAnchors: l, selectionWidth: n, selectionColor: o, hoverMode: a, settings: i });
|
|
726
|
-
}
|
|
727
|
-
e.restore();
|
|
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]);
|
|
731
|
-
})(e, t.frame, i), e.restore();
|
|
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) => {
|
|
733
|
-
const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0];
|
|
734
|
-
if (!t) return "";
|
|
735
|
-
const i = t.getAttribute("width"), n = t.getAttribute("height");
|
|
736
|
-
let o;
|
|
737
|
-
if (i || n) o = e;
|
|
738
|
-
else {
|
|
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);
|
|
741
|
-
}
|
|
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) => {
|
|
745
|
-
const i = document.createElement("a");
|
|
746
|
-
i.href = e, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
|
|
747
|
-
}, Aa = (e) => e.src.includes("<svg") ? e.src : ((t) => {
|
|
748
|
-
const i = document.createElement("canvas");
|
|
749
|
-
i.width = t.width, i.height = t.height;
|
|
750
|
-
const n = i.getContext("2d");
|
|
751
|
-
return n ? (n.drawImage(t, 0, 0), i.toDataURL("image/png")) : "";
|
|
752
|
-
})(e.img), mi = ({ shapes: e, settings: t }) => {
|
|
753
|
-
const i = document.createElement("canvas"), n = i.getContext("2d");
|
|
754
|
-
if (!n) throw new Error("No context found for canvas");
|
|
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);
|
|
758
|
-
return i.toDataURL("image/png");
|
|
759
|
-
}, wn = ({ shapes: e, settings: t, view: i }) => {
|
|
760
|
-
if (i === "fitToShapes" && !e.length) throw new Error("No image found to export");
|
|
761
|
-
if (i === "fitToShapes") {
|
|
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 });
|
|
764
|
-
}
|
|
765
|
-
if (i === "defaultView") {
|
|
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 });
|
|
768
|
-
}
|
|
769
|
-
const n = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
|
|
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) => {
|
|
775
|
-
const t = ["img", "id", "selection", "path", "arrows", "tempPoint", "computed", ["flipX", [void 0, !1]], ["flipY", [void 0, !1]]];
|
|
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);
|
|
816
|
-
});
|
|
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] = [];
|
|
878
|
-
}, []);
|
|
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);
|
|
889
|
-
if (!Se) return !1;
|
|
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;
|
|
898
|
-
}
|
|
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;
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
return !1;
|
|
908
|
-
}
|
|
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 };
|
|
913
|
-
});
|
|
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) => {
|
|
917
|
-
const t = [e[0].clientX, e[0].clientY], i = [e[1].clientX, e[1].clientY];
|
|
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(() => {
|
|
932
|
-
if (!e) return;
|
|
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 };
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
return e.addEventListener("pointerdown", c), () => {
|
|
941
|
-
e.removeEventListener("pointerdown", c);
|
|
942
|
-
};
|
|
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 });
|
|
950
|
-
}
|
|
951
|
-
}, f = (p) => {
|
|
952
|
-
a.current = a.current.filter((m) => m.pointerId !== p.pointerId), l(a.current.length > 0);
|
|
953
|
-
};
|
|
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);
|
|
956
|
-
};
|
|
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 }));
|
|
961
|
-
}, [e, t]), s = X((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 }));
|
|
966
|
-
}, [e, t]);
|
|
967
|
-
Ea({ canvasElt: n, canvasTransformation: o, canvasSize: e, size: t, setCanvasTransformation: a });
|
|
968
|
-
const d = X(() => {
|
|
969
|
-
a(Cn);
|
|
970
|
-
}, []);
|
|
971
|
-
return le(() => {
|
|
972
|
-
if (!i || !n) return;
|
|
973
|
-
const h = (c) => {
|
|
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) {
|
|
977
|
-
case WheelEvent.DOM_DELTA_LINE:
|
|
978
|
-
return { deltaX: 16 * x.deltaX, deltaY: 16 * x.deltaY };
|
|
979
|
-
case WheelEvent.DOM_DELTA_PAGE:
|
|
980
|
-
return { deltaX: x.deltaX * window.innerHeight, deltaY: x.deltaY * window.innerHeight };
|
|
981
|
-
default:
|
|
982
|
-
return P ? { deltaX: 5 * x.deltaX, deltaY: 5 * x.deltaY } : { deltaX: x.deltaX, deltaY: x.deltaY };
|
|
983
|
-
}
|
|
984
|
-
})(c, c.timeStamp - r.current);
|
|
985
|
-
if (r.current = c.timeStamp, f) {
|
|
986
|
-
c.preventDefault();
|
|
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 }));
|
|
992
|
-
}
|
|
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;
|
|
997
|
-
});
|
|
998
|
-
};
|
|
999
|
-
return n.addEventListener("wheel", h, { passive: !1 }), () => {
|
|
1000
|
-
n.removeEventListener("wheel", h);
|
|
1001
|
-
};
|
|
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) {
|
|
1009
|
-
case "brush":
|
|
1010
|
-
return Ke(i, eo, o);
|
|
1011
|
-
case "circle":
|
|
1012
|
-
return Ke(i, so, o);
|
|
1013
|
-
case "curve":
|
|
1014
|
-
return Ke(i, no, o);
|
|
1015
|
-
case "ellipse":
|
|
1016
|
-
return Ke(i, ro, o);
|
|
1017
|
-
case "line":
|
|
1018
|
-
return Ke(i, to, o);
|
|
1019
|
-
case "polygon":
|
|
1020
|
-
return Ke(i, io, o);
|
|
1021
|
-
case "rect":
|
|
1022
|
-
return Ke(i, oo, o);
|
|
1023
|
-
case "square":
|
|
1024
|
-
return Ke(i, ao, o);
|
|
1025
|
-
case "text":
|
|
1026
|
-
return Ke(i, lo, o);
|
|
1027
|
-
}
|
|
1028
|
-
return null;
|
|
1029
|
-
});
|
|
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);
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
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) {
|
|
1056
|
-
const ie = setInterval(() => {
|
|
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 });
|
|
1060
|
-
});
|
|
1061
|
-
}, 20);
|
|
1062
|
-
return () => clearInterval(ie);
|
|
1063
|
-
}
|
|
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);
|
|
1075
|
-
if (!ie) throw new Error("L'encodage a échoué");
|
|
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"));
|
|
1091
|
-
};
|
|
1092
|
-
});
|
|
1093
|
-
if (Ue.push(Nt), Me.src.startsWith("http")) Ro(Me.src).then((rt) => {
|
|
1094
|
-
Le.src = rt;
|
|
1095
|
-
}).catch(() => {
|
|
1096
|
-
Le.src = "";
|
|
1097
|
-
});
|
|
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);
|
|
1103
|
-
}
|
|
1104
|
-
return xn(Me, Ve);
|
|
1105
|
-
}));
|
|
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" });
|
|
1113
|
-
}, []);
|
|
1114
|
-
le(() => {
|
|
1115
|
-
F.current || (F.current = !0, i && di.current?.(i, { clearHistory: !0, source: "remote" }));
|
|
1116
|
-
}, [i]);
|
|
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);
|
|
1126
|
-
}))(ie);
|
|
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();
|
|
1152
|
-
};
|
|
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);
|
|
1157
|
-
} };
|
|
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)]);
|
|
1177
|
-
}
|
|
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));
|
|
1184
|
-
}
|
|
1185
|
-
if (ee?.type === "polygon") {
|
|
1186
|
-
const se = un(ee, ae, Y, !0);
|
|
1187
|
-
return void Oe(de([se], Y));
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
const fe = Dt(ae, Y);
|
|
1191
|
-
if (ot(_) || J(_, Se, ae, fe), C === void 0 || C.locked) k({ mode: "default", outOfView: !fe });
|
|
1192
|
-
else {
|
|
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" });
|
|
1196
|
-
} else {
|
|
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));
|
|
1201
|
-
}
|
|
1202
|
-
Q.mode === "translate" && ge && !Q.hasBeenDuplicated && (V({ ...Q, hasBeenDuplicated: !0 }), T(U(Q.originalShape)));
|
|
1203
|
-
}
|
|
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);
|
|
1209
|
-
};
|
|
1210
|
-
}
|
|
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);
|
|
1225
|
-
}
|
|
1226
|
-
return b({ mode: "default" }), m(void 0), void x();
|
|
1227
|
-
}
|
|
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);
|
|
1234
|
-
};
|
|
1235
|
-
}
|
|
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]);
|
|
1267
|
-
} else {
|
|
1268
|
-
const O = mn(J, r, Q, g);
|
|
1269
|
-
if (!O) return;
|
|
1270
|
-
e([O]), p(de([O], g));
|
|
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);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
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", _);
|
|
1294
|
-
};
|
|
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;
|
|
1305
|
-
}
|
|
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)]));
|
|
1311
|
-
}
|
|
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 };
|
|
1325
|
-
}
|
|
1326
|
-
return !1;
|
|
1327
|
-
})(_, C, Q, g);
|
|
1328
|
-
return void (V && S([ma(C, V.lineIndex, Q, g)]));
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
}), () => {
|
|
1332
|
-
I(L);
|
|
1333
|
-
}) : void 0;
|
|
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);
|
|
1343
|
-
};
|
|
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);
|
|
1348
|
-
}
|
|
1349
|
-
return c.focus(), () => {
|
|
1350
|
-
c.removeEventListener("paste", f);
|
|
1351
|
-
};
|
|
1352
|
-
}, [i]), le(() => {
|
|
1353
|
-
const c = l.current;
|
|
1354
|
-
return () => {
|
|
1355
|
-
c();
|
|
1356
|
-
};
|
|
1357
|
-
}, []);
|
|
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();
|
|
1381
|
-
})(e, i);
|
|
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;
|
|
1395
|
-
};
|
|
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);
|
|
1468
|
-
});
|
|
1469
|
-
return fe.observe(ae), () => {
|
|
1470
|
-
fe.unobserve(ae);
|
|
1471
|
-
};
|
|
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(() => {
|
|
1477
|
-
if (!e) {
|
|
1478
|
-
i("fadeOut");
|
|
1479
|
-
const n = setTimeout(() => i("hidden"), 300);
|
|
1480
|
-
return () => {
|
|
1481
|
-
clearTimeout(n);
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
i("visible");
|
|
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);
|
|
1493
|
-
}, i - 500 - 100);
|
|
1494
|
-
return () => {
|
|
1495
|
-
clearTimeout(a), clearTimeout(r);
|
|
1496
|
-
};
|
|
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) => {
|
|
1510
|
-
switch (e) {
|
|
1511
|
-
case "brush":
|
|
1512
|
-
return $n;
|
|
1513
|
-
case "line":
|
|
1514
|
-
return Gn;
|
|
1515
|
-
case "polygon":
|
|
1516
|
-
return Zi;
|
|
1517
|
-
case "curve":
|
|
1518
|
-
return _n;
|
|
1519
|
-
case "rect":
|
|
1520
|
-
case "square":
|
|
1521
|
-
return Li;
|
|
1522
|
-
case "circle":
|
|
1523
|
-
case "ellipse":
|
|
1524
|
-
return Vi;
|
|
1525
|
-
case "text":
|
|
1526
|
-
return qn;
|
|
1527
|
-
case "picture":
|
|
1528
|
-
return zi;
|
|
1529
|
-
case "group":
|
|
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>';
|
|
1531
|
-
case "triangle":
|
|
1532
|
-
return "";
|
|
1533
|
-
}
|
|
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 = () => {
|
|
1543
|
-
S(void 0);
|
|
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));
|
|
1553
|
-
};
|
|
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);
|
|
1620
|
-
}
|
|
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) => {
|
|
1632
|
-
if (F.type !== "text") return F;
|
|
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);
|
|
1637
|
-
});
|
|
1638
|
-
h(E, !0), g && i(g.id, H, Z);
|
|
1639
|
-
} else i(a.id, H, Z);
|
|
1640
|
-
};
|
|
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);
|
|
1650
|
-
s && i(s);
|
|
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
|
-
});
|
|
1682
|
-
};
|
|
1683
|
-
return e === "hover" ? (t.addEventListener("mouseenter", r), () => {
|
|
1684
|
-
t.removeEventListener("mouseenter", r);
|
|
1685
|
-
}) : (t.addEventListener("click", r), () => {
|
|
1686
|
-
t.removeEventListener("click", r);
|
|
1687
|
-
});
|
|
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(() => {
|
|
1697
|
-
i.current && i.current.focus();
|
|
1698
|
-
}, []), v(si, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: G("form", { onSubmit: async (n) => {
|
|
1699
|
-
n.preventDefault();
|
|
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 }) => {
|
|
1704
|
-
const i = async (n) => {
|
|
1705
|
-
t(n), e();
|
|
1706
|
-
};
|
|
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);
|
|
1711
|
-
};
|
|
1712
|
-
if (le(() => {
|
|
1713
|
-
if (!a) return;
|
|
1714
|
-
const p = (m) => {
|
|
1715
|
-
!No(m, o.current) && r(!1);
|
|
1716
|
-
};
|
|
1717
|
-
return document.addEventListener("mousedown", p, { passive: !1 }), document.addEventListener("touchstart", p, { passive: !1 }), () => {
|
|
1718
|
-
document.removeEventListener("mousedown", p), document.removeEventListener("touchstart", p);
|
|
1719
|
-
};
|
|
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(() => {
|
|
1726
|
-
r(!0);
|
|
1727
|
-
});
|
|
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;
|
|
1735
|
-
});
|
|
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(() => () => {
|
|
1754
|
-
for (const n of e.current) clearTimeout(n);
|
|
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)];
|
|
1761
|
-
} };
|
|
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);
|
|
1807
|
-
try {
|
|
1808
|
-
M(ve);
|
|
1809
|
-
} catch (be) {
|
|
1810
|
-
be instanceof Error && Ae({ type: "error", text: `L'export a échoué : ${be.message}` }), console.warn(be);
|
|
1811
|
-
} finally {
|
|
1812
|
-
we(!1);
|
|
1813
|
-
}
|
|
1814
|
-
}, [M, Ae]), je = X(() => {
|
|
1815
|
-
we(!0);
|
|
1816
|
-
try {
|
|
1817
|
-
C(), we(!1);
|
|
1818
|
-
} catch (ve) {
|
|
1819
|
-
ve instanceof Error && Ae({ type: "error", text: "L'enregistrement a échoué" }), console.warn(ve);
|
|
1820
|
-
} finally {
|
|
1821
|
-
we(!1);
|
|
1822
|
-
}
|
|
1823
|
-
}, [C, Ae]), ct = X(async (ve) => {
|
|
1824
|
-
we(!0);
|
|
1825
|
-
try {
|
|
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);
|
|
1829
|
-
} finally {
|
|
1830
|
-
we(!1);
|
|
1831
|
-
}
|
|
1832
|
-
}, [_, Ae]), ht = X(async (ve) => {
|
|
1833
|
-
we(!0);
|
|
1834
|
-
try {
|
|
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);
|
|
1839
|
-
} finally {
|
|
1840
|
-
we(!1);
|
|
1841
|
-
}
|
|
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 })] });
|
|
1850
|
-
};
|
|
1851
|
-
export {
|
|
1852
|
-
Zs as Canvas,
|
|
1853
|
-
zs as Editor,
|
|
1854
|
-
Vs as useReactPaint
|
|
1855
|
-
};
|
|
1
|
+
import{n as e,r as t,t as n}from"./_chunks/canvas-OCtokhMt.js";import{i as r,t as i}from"./_chunks/array-DuJem3vg.js";import{n as a,t as o}from"./_chunks/editor-CNTO8aYs.js";import{useMemo as s}from"react";var c=(e,t)=>{if(Array.isArray(e))return t},l=e=>i(e.map(e=>{if(typeof e!=`object`||!e.type)return null;let t=a.find(t=>t.type===e.type);return t?r(c,t,e):e})),u=({options:n,...r}={})=>{let i=n?.availableTools,o=(n?.withUploadPicture??t.withUploadPicture)||(n?.withUrlPicture??t.withUrlPicture),c=s(()=>{let e=i?l(i):a;return o?e:e.filter(e=>e.type!==`picture`)},[i,o]);return e({...r,options:{...n,availableTools:c}})};export{n as Canvas,o as Editor,u as useReactPaint};
|